]>
Commit | Line | Data |
---|---|---|
c4095074 | 1 | /* $Header$ |
2 | */ | |
3 | ||
4 | #include <stdio.h> | |
5 | #include <moira.h> | |
6 | #include <moira_site.h> | |
7 | #include <Xm/Xm.h> | |
8 | #include "mmoira.h" | |
9 | ||
10 | ||
11 | extern char *user, *program_name; | |
12 | extern EntryForm *MoiraForms[]; | |
13 | EntryForm *GetAndClearForm(); | |
14 | ||
15 | char *user_states[] = { "0 - Registerable", | |
16 | "1 - Active", | |
17 | "2 - Half Registered", | |
18 | "3 - Deleted", | |
19 | "4 - Not registerable", | |
20 | "5 - Enrolled/Registerable", | |
21 | "6 - Enrolled/Not Registerable", | |
22 | "7 - Half Enrolled", | |
23 | NULL}; | |
24 | char *nfs_states[] = { "0 - Not Allocated", | |
25 | "1 - Student", | |
26 | "2 - Faculty", | |
27 | "4 - Staff", | |
28 | "8 - Miscellaneous", | |
29 | NULL}; | |
30 | ||
31 | ||
32 | /* Called when a menu item is selected. */ | |
33 | ||
34 | MoiraMenuRequest(menu) | |
35 | MenuItem *menu; | |
36 | { | |
37 | EntryForm *f; | |
38 | ||
39 | f = GetAndClearForm(menu->form); | |
40 | if (f == NULL) { | |
41 | if (!strcmp(menu->form, "0")) | |
42 | MoiraMenuComplete(menu); | |
43 | else | |
44 | display_error("Sorry, unable to process that request (no form registered)."); | |
45 | return; | |
46 | } | |
47 | ||
48 | switch (menu->operation) { | |
49 | case MM_SHOW_USER: | |
50 | GetKeywords(f, 4, "class"); | |
51 | break; | |
52 | case MM_ADD_USER: | |
53 | StoreField(f, U_NAME, UNIQUE_LOGIN); | |
54 | StoreField(f, U_UID, UNIQUE_UID); | |
55 | StoreField(f, U_SHELL, "/bin/csh"); | |
56 | StoreField(f, U_STATE, user_states[US_NO_LOGIN_YET]); | |
57 | f->inputlines[U_STATE]->keywords = user_states; | |
58 | GetKeywords(f, U_CLASS, "class"); | |
59 | break; | |
60 | case MM_SET_POBOX: | |
61 | GetKeywords(f, 1, "pobox"); | |
62 | GetKeywords(f, 3, "poserver"); | |
63 | break; | |
64 | case MM_ADD_FILSYS: | |
65 | StoreField(f, FS_TYPE, "NFS"); | |
66 | StoreField(f, FS_M_POINT, "/mit/"); | |
67 | StoreField(f, FS_ACCESS, "w"); | |
68 | StoreField(f, FS_OWNER, user); | |
69 | StoreField(f, FS_OWNERS, user); | |
70 | boolval(f, FS_CREATE) = TRUE; | |
71 | GetKeywords(f, FS_TYPE, "filesys"); | |
72 | GetKeywords(f, FS_ACCESS, "fs_access_NFS"); | |
73 | GetKeywords(f, FS_L_TYPE, "lockertype"); | |
74 | break; | |
75 | case MM_ADD_NFS: | |
76 | StoreField(f, 1, "/u1/lockers"); | |
77 | StoreField(f, 2, "/dev/"); | |
78 | StoreField(f, 5, "0"); | |
79 | StoreField(f, 6, "0"); | |
80 | StoreField(f, 3, nfs_states[1]); | |
81 | f->inputlines[3]->keywords = nfs_states; | |
82 | break; | |
83 | case MM_ADD_QUOTA: | |
84 | case MM_DEL_QUOTA: | |
892c98b2 | 85 | case MM_MOD_QUOTA: |
86 | GetKeywords(f, 1, "quota_type"); | |
c4095074 | 87 | break; |
88 | case MM_SHOW_ACE_USE: | |
89 | StoreField(f, 0, "USER"); | |
90 | GetKeywords(f, 0, "ace_type"); | |
91 | break; | |
92 | case MM_ADD_LIST: | |
93 | boolval(f, L_ACTIVE) = TRUE; | |
94 | boolval(f, L_MAILLIST) = TRUE; | |
95 | StoreField(f, L_GID, UNIQUE_GID); | |
96 | StoreField(f, L_ACE_TYPE, "USER"); | |
97 | GetKeywords(f, L_ACE_TYPE, "ace_type"); | |
98 | break; | |
99 | case MM_SHOW_MEMBERS: | |
100 | GetKeywords(f, 1, "member"); | |
101 | break; | |
102 | case MM_ADD_MEMBER: | |
103 | case MM_DEL_MEMBER: | |
104 | GetKeywords(f, 1, "member"); | |
105 | break; | |
106 | case MM_DEL_ALL_MEMBER: | |
107 | boolval(f, 2) = TRUE; | |
108 | GetKeywords(f, 0, "member"); | |
109 | break; | |
110 | case MM_ADD_MACH: | |
111 | GetKeywords(f, 1, "mac_type"); | |
112 | break; | |
113 | case MM_ADD_PCAP: | |
114 | StoreField(f, PCAP_SPOOL_DIR, "/usr/spool/printer/"); | |
115 | boolval(f, PCAP_AUTH) = TRUE; | |
116 | StoreField(f, PCAP_PRICE, "10"); | |
117 | break; | |
118 | case MM_ADD_SERVICE: | |
119 | StoreField(f, SVC_INTERVAL, "1430"); | |
120 | StoreField(f, SVC_TARGET, "/tmp/"); | |
121 | StoreField(f, SVC_SCRIPT, "/moira/bin/"); | |
122 | StoreField(f, 4, "UNIQUE"); | |
123 | StoreField(f, 6, "NONE"); | |
124 | GetKeywords(f, 4, "service"); | |
125 | GetKeywords(f, 6, "ace_type"); | |
126 | break; | |
127 | case MM_SHOW_ALIAS: | |
128 | StoreField(f, 2, "*"); | |
129 | GetKeywords(f, 1, "alias"); | |
130 | break; | |
131 | case MM_ADD_ZEPHYR: | |
132 | GetKeywords(f, 1, "ace_type"); | |
133 | GetKeywords(f, 3, "ace_type"); | |
134 | GetKeywords(f, 5, "ace_type"); | |
135 | GetKeywords(f, 7, "ace_type"); | |
136 | break; | |
137 | } | |
138 | ||
139 | f->menu = menu; | |
140 | DisplayForm(f); | |
141 | } | |
142 | ||
143 | ||
144 | /* Find a form by name. Returns a pointer to the form or NULL on error. */ | |
145 | ||
146 | EntryForm *GetForm(name) | |
147 | char *name; | |
148 | { | |
149 | EntryForm **fp; | |
150 | ||
151 | for (fp = MoiraForms; *fp; fp++) | |
152 | if (!strcmp((*fp)->formname, name)) | |
153 | break; | |
154 | return(*fp); | |
155 | } | |
156 | ||
157 | ||
158 | /* Find a form by name and clear all of its fields. Returns a pointer | |
159 | * to the form or NULL on error. | |
160 | */ | |
161 | ||
162 | EntryForm *GetAndClearForm(name) | |
163 | char *name; | |
164 | { | |
165 | EntryForm **fp; | |
166 | UserPrompt *p, **pp; | |
167 | static BottomButton **buttons = NULL; | |
168 | int MoiraFormComplete(), button_callback(), help_form_callback(); | |
169 | ||
170 | for (fp = MoiraForms; *fp; fp++) | |
171 | if (!strcmp((*fp)->formname, name)) | |
172 | break; | |
173 | if (*fp == (EntryForm *)NULL) | |
174 | return(NULL); | |
175 | ||
176 | for (pp = (*fp)->inputlines; p = *pp; pp++) { | |
177 | switch (p->type) { | |
178 | case FT_STRING: | |
179 | case FT_KEYWORD: | |
180 | if (p->returnvalue.stringvalue) | |
181 | free(p->returnvalue.stringvalue); | |
182 | p->returnvalue.stringvalue = (char *)malloc(MAXFIELDSIZE); | |
183 | if (p->returnvalue.stringvalue == NULL) { | |
184 | fprintf(stderr, "Moira: out of memory\n"); | |
185 | return(NULL); | |
186 | } | |
187 | *(p->returnvalue.stringvalue) = '\0'; | |
188 | break; | |
189 | case FT_BOOLEAN: | |
190 | p->returnvalue.booleanvalue = False; | |
191 | break; | |
192 | case FT_NUMBER: | |
193 | p->returnvalue.integervalue = 0; | |
194 | break; | |
195 | } | |
196 | } | |
197 | if (buttons == NULL) { | |
198 | buttons = (BottomButton **)malloc(4 * sizeof(BottomButton *)); | |
199 | buttons[0] = (BottomButton *)malloc(sizeof(BottomButton)); | |
200 | buttons[0]->label = "OK"; | |
201 | buttons[0]->returnfunction = MoiraFormComplete; | |
202 | buttons[1] = (BottomButton *)malloc(sizeof(BottomButton)); | |
203 | buttons[1]->label = "Cancel"; | |
204 | buttons[1]->returnfunction = button_callback; | |
205 | buttons[2] = (BottomButton *)malloc(sizeof(BottomButton)); | |
206 | buttons[2]->label = "Help"; | |
207 | buttons[2]->returnfunction = help_form_callback; | |
208 | buttons[3] = NULL; | |
209 | } | |
210 | (*fp)->buttons = buttons; | |
211 | return(*fp); | |
212 | } | |
213 | ||
214 | ||
215 | /* Store a string into a given field in a form. */ | |
216 | ||
217 | StoreField(form, field, value) | |
218 | EntryForm *form; | |
219 | int field; | |
220 | char *value; | |
221 | { | |
222 | strncpy(form->inputlines[field]->returnvalue.stringvalue, | |
223 | value, MAXFIELDSIZE); | |
224 | } | |
225 | ||
226 | ||
892c98b2 | 227 | char *StringValue(form, field) |
228 | EntryForm *form; | |
229 | int field; | |
230 | { | |
231 | switch (form->inputlines[field]->type) { | |
232 | case FT_STRING: | |
233 | case FT_KEYWORD: | |
234 | return(stringval(form, field)); | |
235 | case FT_BOOLEAN: | |
236 | return(boolval(form, field) ? "1" : "0"); | |
237 | } | |
238 | } | |
239 | ||
240 | ||
7df88a65 | 241 | StoreHost(form, field, dest) |
242 | EntryForm *form; | |
243 | int field; | |
244 | char **dest; | |
245 | { | |
246 | char *s; | |
247 | ||
248 | s = strsave(stringval(form, 0)); | |
249 | s = canonicalize_hostname(s); | |
250 | StoreField(form, 0, s); | |
251 | free(s); | |
252 | *dest = stringval(form, 0); | |
253 | } | |
254 | ||
255 | ||
c4095074 | 256 | /* Helper routine for GetKeywords() */ |
257 | ||
258 | static get_alias(argc, argv, sq) | |
259 | int argc; | |
260 | char **argv; | |
261 | struct save_queue *sq; | |
262 | { | |
263 | sq_save_data(sq, strsave(argv[2])); | |
264 | #ifdef DEBUG | |
265 | printf("found keyword %s\n", argv[2]); | |
266 | #endif | |
267 | return(MR_CONT); | |
268 | } | |
269 | ||
270 | static get_sloc(argc, argv, sq) | |
271 | int argc; | |
272 | char **argv; | |
273 | struct save_queue *sq; | |
274 | { | |
275 | sq_save_data(sq, strsave(argv[1])); | |
276 | #ifdef DEBUG | |
277 | printf("found sloc %s\n", argv[1]); | |
278 | #endif | |
279 | return(MR_CONT); | |
280 | } | |
281 | ||
282 | ||
283 | /* Retrieve possible keyword values from Moira and store them in the specified | |
284 | * field of the form. Returns 0 if successful, -1 if not. | |
285 | */ | |
286 | ||
287 | int GetKeywords(form, field, name) | |
288 | EntryForm *form; | |
289 | int field; | |
290 | char *name; | |
291 | { | |
292 | static struct save_queue *cache = NULL; | |
293 | struct save_queue *sq, *s; | |
294 | struct cache_elem { char *name; char **values; } *ce; | |
295 | int i, size, stat; | |
296 | char *argv[4]; | |
297 | ||
298 | /* init cache */ | |
299 | if (cache == NULL) | |
300 | cache = sq_create(); | |
301 | cache->q_lastget = NULL; | |
302 | ||
303 | /* look through cache */ | |
304 | while (sq_get_data(cache, &ce)) | |
305 | if (!strcmp(ce->name, name)) { | |
306 | form->inputlines[field]->keywords = ce->values; | |
307 | return(0); | |
308 | } | |
309 | ||
310 | /* not in cache, do query */ | |
311 | sq = sq_create(); | |
312 | if (!strcmp(name, "poserver")) { | |
313 | argv[0] = "POP"; | |
314 | stat = MoiraQuery("get_server_locations", 1, argv, get_sloc, | |
315 | (char *)sq); | |
316 | if (stat) { | |
317 | com_err(program_name, stat, "retrieving service locations"); | |
318 | return(-1); | |
319 | } | |
320 | } else { | |
321 | argv[0] = name; | |
322 | argv[1] = "TYPE"; | |
323 | argv[2] = "*"; | |
324 | stat = MoiraQuery("get_alias", 3, argv, get_alias, (char *)sq); | |
325 | if (stat) { | |
326 | com_err(program_name, stat, "retrieving keyword values"); | |
327 | return(-1); | |
328 | } | |
329 | } | |
330 | ||
331 | size = 1; | |
332 | for (s = sq->q_next; s->q_next != sq; s = s->q_next) | |
333 | size++; | |
334 | #ifdef DEBUG | |
335 | printf("Found %d keywords of type %s\n", size, name); | |
336 | #endif | |
337 | ||
338 | /* transform query data into proper malloc'ed structure */ | |
339 | ce = (struct cache_elem *) malloc(sizeof(struct cache_elem)); | |
340 | if (ce == NULL) { | |
341 | display_error("Out of memory while fetching keywords"); | |
342 | return(-1); | |
343 | } | |
344 | ce->name = name; | |
345 | ce->values = (char **) malloc(sizeof(char *) * (size + 1)); | |
346 | if (ce->values == NULL) { | |
347 | display_error("Out of memory while fetching keywords"); | |
348 | return(-1); | |
349 | } | |
350 | for (i = 0; i < size; i++) | |
351 | sq_get_data(sq, &(ce->values[i])); | |
352 | ce->values[i] = NULL; | |
353 | sq_destroy(sq); | |
354 | ||
355 | /* put it in the cache */ | |
356 | sq_save_data(cache, ce); | |
357 | ||
358 | /* and return answer */ | |
359 | form->inputlines[field]->keywords = ce->values; | |
360 | return(0); | |
361 | } |