2
* Copyright 2007 Massachusetts Institute of Technology.
5
* Export of this software from the United States of America may
6
* require a specific license from the United States Government.
7
* It is the responsibility of any person or organization contemplating
8
* export to obtain such a license before exporting.
10
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
11
* distribute this software and its documentation for any purpose and
12
* without fee is hereby granted, provided that the above copyright
13
* notice appear in all copies and that both that copyright notice and
14
* this permission notice appear in supporting documentation, and that
15
* the name of M.I.T. not be used in advertising or publicity pertaining
16
* to distribution of the software without specific, written prior
17
* permission. Furthermore if you modify this software you must label
18
* your software as modified software and not distribute it in such a
19
* fashion that it might be confused with the original M.I.T. software.
20
* M.I.T. makes no representations about the suitability of
21
* this software for any purpose. It is provided "as is" without express
22
* or implied warranty.
2
25
* Copyright 1987, 1988 by MIT Student Information Processing Board
4
27
* For copyright information, see copyright.h.
7
30
#include "copyright.h"
8
31
#define size sizeof(ss_data *)
33
/* XXX The memory in _ss_table never gets freed up until program exit!
34
If you change the code to free it and stick a null pointer into
35
_ss_table[sci_idx], make sure you change the allocation routine to
36
not assume there are no null pointers in the middle of the
11
38
int ss_create_invocation(subsystem_name, version_string, info_ptr,
12
39
request_table_ptr, code_ptr)
13
40
char *subsystem_name, *version_string;
18
45
register int sci_idx;
19
46
register ss_data *new_table;
20
register ss_data **table;
47
register ss_data **table, **tmp;
24
51
new_table = (ss_data *) malloc(sizeof(ss_data));
52
if (new_table == NULL) {
26
57
if (table == (ss_data **) NULL) {
27
58
table = (ss_data **) malloc(2 * size);
28
63
table[0] = table[1] = (ss_data *)NULL;
30
66
initialize_ss_error_table ();
32
68
for (sci_idx = 1; table[sci_idx] != (ss_data *)NULL; sci_idx++)
34
table = (ss_data **) realloc((char *)table,
35
((unsigned)sci_idx+2)*size);
70
tmp = (ss_data **) realloc((char *)table,
71
((unsigned)sci_idx+2)*size);
76
_ss_table = table = tmp;
36
77
table[sci_idx+1] = (ss_data *) NULL;
37
table[sci_idx] = new_table;
78
table[sci_idx] = NULL;
39
80
new_table->subsystem_name = subsystem_name;
40
81
new_table->subsystem_version = version_string;
41
82
new_table->argv = (char **)NULL;
42
83
new_table->current_request = (char *)NULL;
43
84
new_table->info_dirs = (char **)malloc(sizeof(char *));
85
if (new_table->info_dirs == NULL) {
44
90
*new_table->info_dirs = (char *)NULL;
45
91
new_table->info_ptr = info_ptr;
46
new_table->prompt = malloc((unsigned)strlen(subsystem_name)+4);
47
strcpy(new_table->prompt, subsystem_name);
48
strcat(new_table->prompt, ": ");
50
new_table->abbrev_info = ss_abbrev_initialize("/etc/passwd", code_ptr);
92
if (asprintf(&new_table->prompt, "%s: ", subsystem_name) < 0) {
94
free(new_table->info_dirs);
52
98
new_table->abbrev_info = NULL;
54
99
new_table->flags.escape_disabled = 0;
55
100
new_table->flags.abbrevs_disabled = 0;
56
101
new_table->rqt_tables =
57
102
(ss_request_table **) calloc(2, sizeof(ss_request_table *));
103
if (new_table->rqt_tables == NULL) {
105
free(new_table->prompt);
106
free(new_table->info_dirs);
58
110
*(new_table->rqt_tables) = request_table_ptr;
59
111
*(new_table->rqt_tables+1) = (ss_request_table *) NULL;
112
table[sci_idx] = new_table;