6 #include <moira_site.h>
11 extern char *user, *program_name;
12 extern EntryForm *MoiraForms[];
13 EntryForm *GetAndClearForm();
15 char *user_states[] = { "0 - Registerable",
17 "2 - Half Registered",
19 "4 - Not registerable",
20 "5 - Enrolled/Registerable",
21 "6 - Enrolled/Not Registerable",
24 char *nfs_states[] = { "0 - Not Allocated",
32 /* Called when a menu item is selected. */
34 MoiraMenuRequest(menu)
39 f = GetAndClearForm(menu->form);
41 if (!strcmp(menu->form, "0"))
42 MoiraMenuComplete(menu);
44 display_error("Sorry, unable to process that request (no form registered).");
48 switch (menu->operation) {
50 GetKeywords(f, 4, "class");
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");
61 GetKeywords(f, 1, "pobox");
62 GetKeywords(f, 3, "poserver");
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");
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;
85 GetKeywords(f, 0, "quota_type");
88 StoreField(f, 0, "USER");
89 GetKeywords(f, 0, "ace_type");
92 boolval(f, L_ACTIVE) = TRUE;
93 boolval(f, L_MAILLIST) = TRUE;
94 StoreField(f, L_GID, UNIQUE_GID);
95 StoreField(f, L_ACE_TYPE, "USER");
96 GetKeywords(f, L_ACE_TYPE, "ace_type");
99 GetKeywords(f, 1, "member");
103 GetKeywords(f, 1, "member");
105 case MM_DEL_ALL_MEMBER:
106 boolval(f, 2) = TRUE;
107 GetKeywords(f, 0, "member");
110 GetKeywords(f, 1, "mac_type");
113 StoreField(f, PCAP_SPOOL_DIR, "/usr/spool/printer/");
114 boolval(f, PCAP_AUTH) = TRUE;
115 StoreField(f, PCAP_PRICE, "10");
118 StoreField(f, SVC_INTERVAL, "1430");
119 StoreField(f, SVC_TARGET, "/tmp/");
120 StoreField(f, SVC_SCRIPT, "/moira/bin/");
121 StoreField(f, 4, "UNIQUE");
122 StoreField(f, 6, "NONE");
123 GetKeywords(f, 4, "service");
124 GetKeywords(f, 6, "ace_type");
127 StoreField(f, 2, "*");
128 GetKeywords(f, 1, "alias");
131 GetKeywords(f, 1, "ace_type");
132 GetKeywords(f, 3, "ace_type");
133 GetKeywords(f, 5, "ace_type");
134 GetKeywords(f, 7, "ace_type");
143 /* Find a form by name. Returns a pointer to the form or NULL on error. */
145 EntryForm *GetForm(name)
150 for (fp = MoiraForms; *fp; fp++)
151 if (!strcmp((*fp)->formname, name))
157 /* Find a form by name and clear all of its fields. Returns a pointer
158 * to the form or NULL on error.
161 EntryForm *GetAndClearForm(name)
166 static BottomButton **buttons = NULL;
167 int MoiraFormComplete(), button_callback(), help_form_callback();
169 for (fp = MoiraForms; *fp; fp++)
170 if (!strcmp((*fp)->formname, name))
172 if (*fp == (EntryForm *)NULL)
175 for (pp = (*fp)->inputlines; p = *pp; pp++) {
179 if (p->returnvalue.stringvalue)
180 free(p->returnvalue.stringvalue);
181 p->returnvalue.stringvalue = (char *)malloc(MAXFIELDSIZE);
182 if (p->returnvalue.stringvalue == NULL) {
183 fprintf(stderr, "Moira: out of memory\n");
186 *(p->returnvalue.stringvalue) = '\0';
189 p->returnvalue.booleanvalue = False;
192 p->returnvalue.integervalue = 0;
196 if (buttons == NULL) {
197 buttons = (BottomButton **)malloc(4 * sizeof(BottomButton *));
198 buttons[0] = (BottomButton *)malloc(sizeof(BottomButton));
199 buttons[0]->label = "OK";
200 buttons[0]->returnfunction = MoiraFormComplete;
201 buttons[1] = (BottomButton *)malloc(sizeof(BottomButton));
202 buttons[1]->label = "Cancel";
203 buttons[1]->returnfunction = button_callback;
204 buttons[2] = (BottomButton *)malloc(sizeof(BottomButton));
205 buttons[2]->label = "Help";
206 buttons[2]->returnfunction = help_form_callback;
209 (*fp)->buttons = buttons;
214 /* Store a string into a given field in a form. */
216 StoreField(form, field, value)
221 strncpy(form->inputlines[field]->returnvalue.stringvalue,
222 value, MAXFIELDSIZE);
226 /* Helper routine for GetKeywords() */
228 static get_alias(argc, argv, sq)
231 struct save_queue *sq;
233 sq_save_data(sq, strsave(argv[2]));
235 printf("found keyword %s\n", argv[2]);
240 static get_sloc(argc, argv, sq)
243 struct save_queue *sq;
245 sq_save_data(sq, strsave(argv[1]));
247 printf("found sloc %s\n", argv[1]);
253 /* Retrieve possible keyword values from Moira and store them in the specified
254 * field of the form. Returns 0 if successful, -1 if not.
257 int GetKeywords(form, field, name)
262 static struct save_queue *cache = NULL;
263 struct save_queue *sq, *s;
264 struct cache_elem { char *name; char **values; } *ce;
271 cache->q_lastget = NULL;
273 /* look through cache */
274 while (sq_get_data(cache, &ce))
275 if (!strcmp(ce->name, name)) {
276 form->inputlines[field]->keywords = ce->values;
280 /* not in cache, do query */
282 if (!strcmp(name, "poserver")) {
284 stat = MoiraQuery("get_server_locations", 1, argv, get_sloc,
287 com_err(program_name, stat, "retrieving service locations");
294 stat = MoiraQuery("get_alias", 3, argv, get_alias, (char *)sq);
296 com_err(program_name, stat, "retrieving keyword values");
302 for (s = sq->q_next; s->q_next != sq; s = s->q_next)
305 printf("Found %d keywords of type %s\n", size, name);
308 /* transform query data into proper malloc'ed structure */
309 ce = (struct cache_elem *) malloc(sizeof(struct cache_elem));
311 display_error("Out of memory while fetching keywords");
315 ce->values = (char **) malloc(sizeof(char *) * (size + 1));
316 if (ce->values == NULL) {
317 display_error("Out of memory while fetching keywords");
320 for (i = 0; i < size; i++)
321 sq_get_data(sq, &(ce->values[i]));
322 ce->values[i] = NULL;
325 /* put it in the cache */
326 sq_save_data(cache, ce);
328 /* and return answer */
329 form->inputlines[field]->keywords = ce->values;
334 /********** temporary *8********/
338 { fprintf(stderr, "%s\n", s); }