]>
Commit | Line | Data |
---|---|---|
402461ad | 1 | #if (!defined(lint) && !defined(SABER)) |
08345b74 | 2 | static char rcsid_module_c[] = "$Header$"; |
402461ad | 3 | #endif |
08345b74 | 4 | |
8defc06b | 5 | /* This is the file attach.c for the MOIRA Client, which allows a nieve |
6 | * user to quickly and easily maintain most parts of the MOIRA database. | |
08345b74 | 7 | * It Contains: Functions for maintaining data used by Hesiod |
8 | * to map courses/projects/users to their file systems, | |
9 | * and maintain filesys info. | |
10 | * | |
11 | * Created: 5/4/88 | |
12 | * By: Chris D. Peterson | |
08345b74 | 13 | * |
14 | * $Source$ | |
15 | * $Author$ | |
16 | * $Header$ | |
17 | * | |
0a2c64cb | 18 | * Copyright 1988 by the Massachusetts Institute of Technology. |
08345b74 | 19 | * |
20 | * For further information on copyright and distribution | |
21 | * see the file mit-copyright.h | |
22 | */ | |
23 | ||
08345b74 | 24 | #include <stdio.h> |
25 | #include <strings.h> | |
8defc06b | 26 | #include <moira.h> |
27 | #include <moira_site.h> | |
08345b74 | 28 | #include <menu.h> |
29 | ||
461c03b6 | 30 | #include "mit-copyright.h" |
0a2c64cb | 31 | #include "defs.h" |
32 | #include "f_defs.h" | |
461c03b6 | 33 | #include "globals.h" |
461c03b6 | 34 | |
08345b74 | 35 | #define FS_ALIAS_TYPE "FILESYS" |
36 | ||
461c03b6 | 37 | #define LABEL 0 |
38 | #define MACHINE 1 | |
39 | #define GROUP 2 | |
40 | #define ALIAS 3 | |
08345b74 | 41 | |
9e2516d6 | 42 | #define NO_MACHINE ("\\[NONE\\]") /* C will remove one of the /'s here, |
43 | * and the other quotes the [ for | |
44 | * ingres' regexp facility. */ | |
b3197763 | 45 | #define NO_MACHINE_BAD ("[NONE]") |
9e2516d6 | 46 | |
85ca828a | 47 | #define DEFAULT_TYPE ("NFS") |
48 | #define DEFAULT_MACHINE DEFAULT_NONE | |
49 | #define DEFAULT_PACK DEFAULT_NONE | |
7f6743f7 | 50 | #define DEFAULT_ACCESS ("w") |
85ca828a | 51 | #define DEFAULT_COMMENTS DEFAULT_COMMENT |
52 | #define DEFAULT_OWNER (user) | |
53 | #define DEFAULT_OWNERS (user) | |
54 | #define DEFAULT_CREATE DEFAULT_YES | |
7f6743f7 | 55 | #define DEFAULT_L_TYPE ("PROJECT") |
85ca828a | 56 | |
57 | /* Function Name: SetDefaults | |
58 | * Description: sets the default values for filesystem additions. | |
59 | * Arguments: info - an array of char pointers to recieve defaults. | |
60 | * Returns: char ** (this array, now filled). | |
61 | */ | |
62 | ||
63 | static char ** | |
64 | SetDefaults(info, name) | |
65 | char ** info; | |
66 | char * name; | |
67 | { | |
7cce48da | 68 | char buf[BUFSIZ]; |
69 | ||
85ca828a | 70 | info[FS_NAME] = Strsave(name); |
71 | info[FS_TYPE] = Strsave(DEFAULT_TYPE); | |
72 | info[FS_MACHINE] = Strsave(DEFAULT_MACHINE); | |
73 | info[FS_PACK] = Strsave(DEFAULT_PACK); | |
7cce48da | 74 | sprintf(buf, "/mit/%s", name); |
75 | info[FS_M_POINT] = Strsave(buf); | |
85ca828a | 76 | info[FS_ACCESS] = Strsave(DEFAULT_ACCESS); |
77 | info[FS_COMMENTS] = Strsave(DEFAULT_COMMENTS); | |
78 | info[FS_OWNER] = Strsave(DEFAULT_OWNER); | |
79 | info[FS_OWNERS] = Strsave(DEFAULT_OWNERS); | |
80 | info[FS_CREATE] = Strsave(DEFAULT_CREATE); | |
81 | info[FS_L_TYPE] = Strsave(DEFAULT_L_TYPE); | |
82 | info[FS_MODTIME] = info[FS_MODBY] = info[FS_MODWITH] = info[FS_END] = NULL; | |
83 | return(info); | |
84 | } | |
85 | ||
08345b74 | 86 | /* Function Name: GetFSInfo |
87 | * Description: Stores the info in a queue. | |
88 | * Arguments: type - type of information to get. | |
89 | * name - name of the item to get information on. | |
90 | * Returns: a pointer to the first element in the queue. | |
91 | */ | |
92 | ||
402461ad | 93 | static struct qelem * |
08345b74 | 94 | GetFSInfo(type, name) |
95 | int type; | |
96 | char *name; | |
97 | { | |
98 | int stat; | |
99 | struct qelem * elem = NULL; | |
85ca828a | 100 | char * args[5]; |
08345b74 | 101 | |
102 | switch (type) { | |
461c03b6 | 103 | case LABEL: |
8defc06b | 104 | if ( (stat = do_mr_query("get_filesys_by_label", 1, &name, |
14f99d7d | 105 | StoreInfo, (char *)&elem)) != 0) { |
461c03b6 | 106 | com_err(program_name, stat, NULL); |
08345b74 | 107 | return(NULL); |
108 | } | |
109 | break; | |
461c03b6 | 110 | case MACHINE: |
8defc06b | 111 | if ( (stat = do_mr_query("get_filesys_by_machine", 1, &name, |
14f99d7d | 112 | StoreInfo, (char *)&elem)) != 0) { |
461c03b6 | 113 | com_err(program_name, stat, NULL); |
08345b74 | 114 | return(NULL); |
115 | } | |
116 | break; | |
461c03b6 | 117 | case GROUP: |
8defc06b | 118 | if ( (stat = do_mr_query("get_filesys_by_group", 1, &name, |
14f99d7d | 119 | StoreInfo, (char *)&elem)) != 0) { |
461c03b6 | 120 | com_err(program_name, stat, NULL); |
08345b74 | 121 | return(NULL); |
122 | } | |
123 | break; | |
461c03b6 | 124 | case ALIAS: |
85ca828a | 125 | args[ALIAS_NAME] = name; |
126 | args[ALIAS_TYPE] = FS_ALIAS_TYPE; | |
127 | args[ALIAS_TRANS] = "*"; | |
8defc06b | 128 | if ( (stat = do_mr_query("get_alias", 3, args, StoreInfo, |
14f99d7d | 129 | (char *) &elem)) != 0) { |
461c03b6 | 130 | com_err(program_name, stat, " in get_alias."); |
08345b74 | 131 | return(NULL); |
132 | } | |
133 | } | |
134 | ||
135 | return(QueueTop(elem)); | |
136 | } | |
137 | ||
85ca828a | 138 | /* Function Name: PrintFSAlias |
139 | * Description: Prints a filesystem alias | |
140 | * Arguments: info - an array contains the strings of info. | |
402461ad | 141 | * Returns: the name of the filesys - used be QueryLoop(). |
85ca828a | 142 | */ |
143 | ||
402461ad | 144 | static char * |
85ca828a | 145 | PrintFSAlias(info) |
146 | char ** info; | |
147 | { | |
148 | char buf[BUFSIZ]; | |
149 | ||
150 | sprintf(buf,"Alias: %-25s Filesystem: %s",info[ALIAS_NAME], | |
151 | info[ALIAS_TRANS]); | |
152 | Put_message(buf); | |
402461ad | 153 | return(info[ALIAS_NAME]); |
85ca828a | 154 | } |
155 | ||
9e2516d6 | 156 | static int fsgCount = 1; |
157 | ||
158 | static char * | |
159 | PrintFSGMembers(info) | |
160 | char ** info; | |
161 | { | |
162 | char print_buf[BUFSIZ]; | |
163 | ||
164 | sprintf(print_buf, " %d. Filesystem: %-32s (sort key: %s)", fsgCount++, info[0], info[1]); | |
165 | Put_message(print_buf); | |
166 | return(info[0]); | |
167 | } | |
168 | ||
169 | ||
08345b74 | 170 | /* Function Name: PrintFSInfo |
171 | * Description: Prints the filesystem information. | |
172 | * Arguments: info - a pointer to the filesystem information. | |
173 | * Returns: none. | |
174 | */ | |
175 | ||
402461ad | 176 | static char * |
461c03b6 | 177 | PrintFSInfo(info) |
08345b74 | 178 | char ** info; |
179 | { | |
180 | char print_buf[BUFSIZ]; | |
9e2516d6 | 181 | |
85ca828a | 182 | FORMFEED; |
9e2516d6 | 183 | |
184 | if (!strcmp(info[FS_TYPE], "FSGROUP")) { | |
185 | int stat; | |
186 | struct qelem *elem = NULL; | |
187 | ||
b3197763 | 188 | sprintf(print_buf,"%20s Filesystem Group: %s", " ", info[FS_NAME]); |
189 | Put_message(print_buf); | |
190 | ||
9e2516d6 | 191 | sprintf(print_buf,"Comments; %s",info[FS_COMMENTS]); |
192 | Put_message(print_buf); | |
193 | sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME], | |
194 | info[FS_MODWITH]); | |
195 | Put_message(print_buf); | |
196 | Put_message("Containing the filesystems (in order):"); | |
8defc06b | 197 | if ((stat = do_mr_query("get_fsgroup_members", 1, &info[FS_NAME], |
9e2516d6 | 198 | StoreInfo, (char *)&elem)) != 0) { |
8defc06b | 199 | if (stat == MR_NO_MATCH) |
9e2516d6 | 200 | Put_message(" [no members]"); |
201 | else | |
202 | com_err(program_name, stat, NULL); | |
203 | } else { | |
204 | fsgCount = 1; | |
205 | Loop(QueueTop(elem), (void *) PrintFSGMembers); | |
206 | FreeQueue(elem); | |
207 | } | |
208 | } else { | |
b3197763 | 209 | sprintf(print_buf,"%20s Filesystem: %s", " ", info[FS_NAME]); |
210 | Put_message(print_buf); | |
9e2516d6 | 211 | sprintf(print_buf,"Type: %-40s Machine: %-15s", |
212 | info[FS_TYPE], info[FS_MACHINE]); | |
213 | Put_message(print_buf); | |
214 | sprintf(print_buf,"Default Access: %-2s Packname: %-17s Mountpoint %s ", | |
215 | info[FS_ACCESS], info[FS_PACK], info[FS_M_POINT]); | |
216 | Put_message(print_buf); | |
217 | sprintf(print_buf,"Comments; %s",info[FS_COMMENTS]); | |
218 | Put_message(print_buf); | |
219 | sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s", | |
220 | info[FS_OWNER], info[FS_OWNERS]); | |
221 | Put_message(print_buf); | |
222 | sprintf(print_buf, "Auto Create: %-34s Locker Type: %s", | |
223 | atoi(info[FS_CREATE]) ? "ON" : "OFF", | |
224 | info[FS_L_TYPE]); | |
225 | Put_message(print_buf); | |
226 | sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME], | |
227 | info[FS_MODWITH]); | |
228 | Put_message(print_buf); | |
229 | } | |
402461ad | 230 | return(info[FS_NAME]); |
08345b74 | 231 | } |
232 | ||
08345b74 | 233 | /* Function Name: AskFSInfo. |
234 | * Description: This function askes the user for information about a | |
235 | * machine and saves it into a structure. | |
236 | * Arguments: info - a pointer the the structure to put the | |
237 | * info into. | |
238 | * name - add a newname field? (T/F) | |
239 | * Returns: none. | |
240 | */ | |
241 | ||
402461ad | 242 | static char ** |
461c03b6 | 243 | AskFSInfo(info, name) |
08345b74 | 244 | char ** info; |
245 | Bool name; | |
246 | { | |
461c03b6 | 247 | char temp_buf[BUFSIZ], *newname; |
9e2516d6 | 248 | int fsgroup = 0; |
08345b74 | 249 | |
402461ad | 250 | Put_message(""); |
251 | sprintf(temp_buf, "Changing Attributes of filesystem %s.", | |
85ca828a | 252 | info[FS_NAME]); |
08345b74 | 253 | Put_message(temp_buf); |
402461ad | 254 | Put_message(""); |
08345b74 | 255 | |
256 | if (name) { | |
257 | newname = Strsave(info[FS_NAME]); | |
402461ad | 258 | GetValueFromUser("The new name for this filesystem", |
08345b74 | 259 | &newname); |
260 | } | |
261 | ||
84d7e36d | 262 | GetTypeFromUser("Filesystem's Type", "filesys", &info[FS_TYPE]); |
f48d1a68 | 263 | if (!strcasecmp(info[FS_TYPE], "FSGROUP")) |
9e2516d6 | 264 | fsgroup++; |
f48d1a68 | 265 | if (fsgroup || !strcasecmp(info[FS_TYPE], "AFS")) { |
9e2516d6 | 266 | free(info[FS_MACHINE]); |
267 | info[FS_MACHINE] = Strsave(NO_MACHINE); | |
268 | } else { | |
b3197763 | 269 | if (!strcmp(info[FS_MACHINE], NO_MACHINE_BAD)) { |
270 | free(info[FS_MACHINE]); | |
271 | info[FS_MACHINE] = Strsave(NO_MACHINE); | |
272 | } | |
9e2516d6 | 273 | GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]); |
1c3831ea | 274 | info[FS_MACHINE] = canonicalize_hostname(info[FS_MACHINE]); |
9e2516d6 | 275 | } |
276 | if (!fsgroup) { | |
277 | GetValueFromUser("Filesystem's Pack Name", &info[FS_PACK]); | |
278 | GetValueFromUser("Filesystem's Mount Point", &info[FS_M_POINT]); | |
279 | GetValueFromUser("Filesystem's Default Access", &info[FS_ACCESS]); | |
280 | } | |
402461ad | 281 | GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS]); |
282 | GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]); | |
283 | GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]); | |
9e2516d6 | 284 | if (!fsgroup) |
285 | GetYesNoValueFromUser("Automatically create this filesystem", | |
286 | &info[FS_CREATE]); | |
84d7e36d | 287 | GetTypeFromUser("Filesystem's lockertype", "lockertype", &info[FS_L_TYPE]); |
08345b74 | 288 | |
289 | FreeAndClear(&info[FS_MODTIME], TRUE); | |
290 | FreeAndClear(&info[FS_MODBY], TRUE); | |
291 | FreeAndClear(&info[FS_MODWITH], TRUE); | |
292 | ||
293 | if (name) /* slide the newname into the #2 slot. */ | |
294 | SlipInNewName(info, newname); | |
295 | ||
296 | return(info); | |
297 | } | |
298 | ||
299 | /* --------------- Filesystem Menu ------------- */ | |
300 | ||
301 | /* Function Name: GetFS | |
302 | * Description: Get Filesystem information by name. | |
303 | * Arguments: argc, argv - name of filsys in argv[1]. | |
304 | * Returns: DM_NORMAL. | |
305 | */ | |
306 | ||
307 | /* ARGSUSED */ | |
308 | int | |
309 | GetFS(argc, argv) | |
310 | int argc; | |
311 | char **argv; | |
312 | { | |
0a2c64cb | 313 | struct qelem *top; |
08345b74 | 314 | |
0a2c64cb | 315 | top = GetFSInfo(LABEL, argv[1]); /* get info. */ |
316 | Loop(top, (void *) PrintFSInfo); | |
85ca828a | 317 | FreeQueue(top); /* clean the queue. */ |
08345b74 | 318 | return (DM_NORMAL); |
319 | } | |
320 | ||
402461ad | 321 | /* Function Name: RealDeleteFS |
322 | * Description: Does the real deletion work. | |
323 | * Arguments: info - array of char *'s containing all useful info. | |
324 | * one_item - a Boolean that is true if only one item | |
325 | * in queue that dumped us here. | |
326 | * Returns: none. | |
327 | */ | |
328 | ||
329 | void | |
330 | RealDeleteFS(info, one_item) | |
331 | char ** info; | |
332 | Bool one_item; | |
333 | { | |
334 | int stat; | |
335 | char temp_buf[BUFSIZ]; | |
336 | ||
337 | /* | |
338 | * Deletetions are performed if the user hits 'y' on a list of multiple | |
339 | * filesystem, or if the user confirms on a unique alias. | |
340 | */ | |
341 | sprintf(temp_buf, "Are you sure that you want to delete filesystem %s", | |
342 | info[FS_NAME]); | |
343 | if(!one_item || Confirm(temp_buf)) { | |
8defc06b | 344 | if ( (stat = do_mr_query("delete_filesys", 1, |
14f99d7d | 345 | &info[FS_NAME], Scream, NULL)) != 0) |
402461ad | 346 | com_err(program_name, stat, " filesystem not deleted."); |
347 | else | |
348 | Put_message("Filesystem deleted."); | |
349 | } | |
350 | else | |
351 | Put_message("Filesystem not deleted."); | |
352 | } | |
353 | ||
08345b74 | 354 | /* Function Name: DeleteFS |
355 | * Description: Delete a filesystem give its name. | |
356 | * Arguments: argc, argv - argv[1] is the name of the filesystem. | |
357 | * Returns: none. | |
358 | */ | |
359 | ||
360 | /* ARGSUSED */ | |
361 | ||
362 | int | |
363 | DeleteFS(argc, argv) | |
364 | int argc; | |
365 | char **argv; | |
366 | { | |
402461ad | 367 | struct qelem *elem = GetFSInfo(LABEL, argv[1]); |
368 | QueryLoop(elem, PrintFSInfo, RealDeleteFS, "Delete the Filesystem"); | |
08345b74 | 369 | |
402461ad | 370 | FreeQueue(elem); |
08345b74 | 371 | return (DM_NORMAL); |
372 | } | |
373 | ||
402461ad | 374 | /* Function Name: RealChangeFS |
375 | * Description: performs the actual change to the filesys. | |
376 | * Arguments: info - the information | |
377 | * junk - an unused boolean. | |
378 | * Returns: none. | |
379 | */ | |
380 | ||
381 | /* ARGSUSED. */ | |
382 | static void | |
383 | RealChangeFS(info, junk) | |
384 | char ** info; | |
385 | Bool junk; | |
386 | { | |
387 | int stat; | |
388 | char ** args = AskFSInfo(info, TRUE); | |
bff71786 | 389 | extern Menu nfsphys_menu; |
390 | ||
8defc06b | 391 | stat = do_mr_query("update_filesys", CountArgs(args), args, |
14f99d7d | 392 | NullFunc, NULL); |
bff71786 | 393 | switch (stat) { |
8defc06b | 394 | case MR_NFS: |
bff71786 | 395 | Put_message("That NFS filesystem is not exported."); |
396 | if (YesNoQuestion("Fix this now (Y/N)")) { | |
397 | Do_menu(&nfsphys_menu, 0, NULL); | |
398 | if (YesNoQuestion("Retry filesystem update now (Y/N)")) { | |
8defc06b | 399 | if (stat = do_mr_query("update_filesys", CountArgs(args), args, |
14f99d7d | 400 | NullFunc, NULL)) |
bff71786 | 401 | com_err(program_name, stat, " filesystem not updated"); |
402 | else | |
403 | Put_message("filesystem sucessfully updated."); | |
404 | } | |
405 | } | |
406 | break; | |
8defc06b | 407 | case MR_SUCCESS: |
98cce88c | 408 | break; |
bff71786 | 409 | default: |
98cce88c | 410 | com_err(program_name, stat, " in UpdateFS"); |
bff71786 | 411 | } |
402461ad | 412 | } |
413 | ||
08345b74 | 414 | /* Function Name: ChangeFS |
415 | * Description: change the information in a filesys record. | |
416 | * Arguments: arc, argv - value of filsys in argv[1]. | |
417 | * Returns: DM_NORMAL. | |
418 | */ | |
419 | ||
420 | /* ARGSUSED */ | |
421 | int | |
422 | ChangeFS(argc, argv) | |
423 | char **argv; | |
424 | int argc; | |
425 | { | |
402461ad | 426 | struct qelem *elem = GetFSInfo(LABEL, argv[1]); |
427 | QueryLoop(elem, NullPrint, RealChangeFS, "Update the Filesystem"); | |
08345b74 | 428 | |
08345b74 | 429 | FreeQueue(elem); |
430 | return (DM_NORMAL); | |
431 | } | |
432 | ||
433 | /* Function Name: AddFS | |
434 | * Description: change the information in a filesys record. | |
435 | * Arguments: arc, argv - name of filsys in argv[1]. | |
436 | * Returns: DM_NORMAL. | |
437 | */ | |
438 | ||
439 | /* ARGSUSED */ | |
440 | int | |
441 | AddFS(argc, argv) | |
442 | char **argv; | |
443 | int argc; | |
444 | { | |
7cce48da | 445 | char *info[MAX_ARGS_SIZE], **args, buf[BUFSIZ]; |
85ca828a | 446 | int stat; |
bff71786 | 447 | extern Menu nfsphys_menu; |
08345b74 | 448 | |
449 | if ( !ValidName(argv[1]) ) | |
450 | return(DM_NORMAL); | |
451 | ||
8defc06b | 452 | if ( (stat = do_mr_query("get_filesys_by_label", 1, argv + 1, |
14f99d7d | 453 | NullFunc, NULL)) == 0) { |
08345b74 | 454 | Put_message ("A Filesystem by that name already exists."); |
455 | return(DM_NORMAL); | |
8defc06b | 456 | } else if (stat != MR_NO_MATCH) { |
461c03b6 | 457 | com_err(program_name, stat, " in AddFS"); |
08345b74 | 458 | return(DM_NORMAL); |
459 | } | |
460 | ||
85ca828a | 461 | args = AskFSInfo(SetDefaults(info, argv[1]), FALSE ); |
461c03b6 | 462 | |
8defc06b | 463 | stat = do_mr_query("add_filesys", CountArgs(args), args, NullFunc, NULL); |
bff71786 | 464 | switch (stat) { |
8defc06b | 465 | case MR_NFS: |
bff71786 | 466 | Put_message("That NFS filesystem is not exported."); |
467 | if (YesNoQuestion("Fix this now (Y/N)")) { | |
468 | Do_menu(&nfsphys_menu, 0, NULL); | |
469 | if (YesNoQuestion("Retry filesystem creation now (Y/N)")) { | |
8defc06b | 470 | if (stat = do_mr_query("add_filesys", CountArgs(args), args, |
14f99d7d | 471 | NullFunc, NULL)) |
bff71786 | 472 | com_err(program_name, stat, " in AddFS"); |
473 | else | |
474 | Put_message("Created."); | |
475 | } | |
476 | } | |
477 | break; | |
8defc06b | 478 | case MR_SUCCESS: |
98cce88c | 479 | break; |
bff71786 | 480 | default: |
461c03b6 | 481 | com_err(program_name, stat, " in AddFS"); |
bff71786 | 482 | } |
08345b74 | 483 | |
8defc06b | 484 | if (stat == MR_SUCCESS && !strcasecmp(info[FS_L_TYPE], "HOMEDIR")) { |
7cce48da | 485 | static char *val[] = {"def_quota", NULL}; |
486 | static char *def_quota = NULL; | |
487 | char *argv[3]; | |
488 | struct qelem *top = NULL; | |
489 | ||
490 | if (def_quota == NULL) { | |
8defc06b | 491 | stat = do_mr_query("get_value", CountArgs(val), val, |
7cce48da | 492 | StoreInfo, (char *) &top); |
8defc06b | 493 | if (stat != MR_SUCCESS) { |
7cce48da | 494 | com_err(program_name, stat, " getting default quota"); |
495 | } else { | |
496 | top = QueueTop(top); | |
497 | def_quota = Strsave(((char **)top->q_data)[0]); | |
498 | FreeQueue(top); | |
499 | } | |
500 | } | |
501 | if (def_quota != NULL) { | |
502 | sprintf(buf, "Give user %s a quota of %s on filesys %s (Y/N)", | |
503 | info[FS_NAME], def_quota, info[FS_NAME]); | |
504 | if (YesNoQuestion(buf, 1)) { | |
505 | argv[Q_LOGIN] = argv[Q_FILESYS] = info[FS_NAME]; | |
506 | argv[Q_QUOTA] = def_quota; | |
8defc06b | 507 | if ((stat = do_mr_query("add_nfs_quota", 3, argv, Scream, |
508 | (char *) NULL)) != MR_SUCCESS) { | |
7cce48da | 509 | com_err(program_name, stat, " while adding quota"); |
510 | } | |
511 | } | |
512 | } | |
513 | } | |
514 | ||
08345b74 | 515 | FreeInfo(info); |
516 | return (DM_NORMAL); | |
517 | } | |
518 | ||
9e2516d6 | 519 | /* Function Name: SortAfter |
520 | * Description: choose a sortkey to cause an item to be added after | |
521 | * the count element in the queue | |
522 | * Arguments: queue of filesys names & sortkeys, queue count pointer | |
523 | * Returns: sort key to use. | |
524 | */ | |
525 | ||
526 | /* ARGSUSED */ | |
527 | char * | |
528 | SortAfter(elem, count) | |
529 | struct qelem *elem; | |
530 | int count; | |
531 | { | |
532 | char *prev, *next, prevnext, *key, keybuf[9]; | |
533 | ||
534 | /* first find the two keys we need to insert between */ | |
535 | prev = "A"; | |
536 | for (; count > 0; count--) { | |
537 | prev = ((char **)elem->q_data)[1]; | |
538 | if (elem->q_forw) | |
539 | elem = elem->q_forw; | |
540 | else | |
541 | break; | |
542 | } | |
543 | if (count > 0) | |
544 | next = "Z"; | |
545 | else | |
546 | next = ((char **)elem->q_data)[1]; | |
547 | ||
548 | /* now copy the matching characters */ | |
549 | for (key = keybuf; *prev && *prev == *next; next++) { | |
550 | *key++ = *prev++; | |
551 | } | |
552 | ||
553 | /* and set the last character */ | |
554 | if (*prev == 0) | |
555 | *prev = prevnext = 'A'; | |
556 | else | |
557 | prevnext = prev[1]; | |
558 | if (prevnext == 0) | |
559 | prevnext = 'A'; | |
560 | if (*next == 0) | |
561 | *next = 'Z'; | |
562 | if (*next - *prev > 1) { | |
563 | *key++ = (*next + *prev)/2; | |
564 | } else { | |
565 | *key++ = *prev; | |
566 | *key++ = (prevnext + 'Z')/2; | |
567 | } | |
568 | *key = 0; | |
569 | return(Strsave(keybuf)); | |
570 | } | |
571 | ||
572 | /* Function Name: AddFSToGroup | |
573 | * Description: add a filesystem to an FS group | |
574 | * Arguments: arc, argv - name of group in argv[1], filesys in argv[2]. | |
575 | * Returns: DM_NORMAL. | |
576 | */ | |
577 | ||
578 | /* ARGSUSED */ | |
579 | int | |
580 | AddFSToGroup(argc, argv) | |
581 | char **argv; | |
582 | int argc; | |
583 | { | |
584 | int stat, count; | |
585 | struct qelem *elem = NULL; | |
586 | char buf[BUFSIZ], *args[5], *bufp; | |
587 | ||
8defc06b | 588 | if ((stat = do_mr_query("get_fsgroup_members", 1, argv+1, StoreInfo, |
9e2516d6 | 589 | (char *)&elem)) != 0) { |
8defc06b | 590 | if (stat != MR_NO_MATCH) |
9e2516d6 | 591 | com_err(program_name, stat, " in AddFSToGroup"); |
592 | } | |
593 | if (elem == NULL) { | |
594 | args[0] = argv[1]; | |
595 | args[1] = argv[2]; | |
596 | args[2] = "M"; | |
8defc06b | 597 | stat = do_mr_query("add_filesys_to_fsgroup", 3, args, Scream, NULL); |
9e2516d6 | 598 | if (stat) |
599 | com_err(program_name, stat, " in AddFSToGroup"); | |
600 | return(DM_NORMAL); | |
601 | } | |
602 | elem = QueueTop(elem); | |
603 | fsgCount = 1; | |
604 | Loop(elem, (void *) PrintFSGMembers); | |
605 | sprintf(buf, "%d", QueueCount(elem)); | |
606 | bufp = Strsave(buf); | |
607 | stat = GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp); | |
608 | count = atoi(bufp); | |
609 | free(bufp); | |
610 | args[2] = SortAfter(elem, count); | |
611 | ||
612 | FreeQueue(QueueTop(elem)); | |
613 | args[0] = argv[1]; | |
614 | args[1] = argv[2]; | |
8defc06b | 615 | stat = do_mr_query("add_filesys_to_fsgroup", 3, args, Scream, NULL); |
616 | if (stat == MR_EXISTS) { | |
9e2516d6 | 617 | Put_message("That filesystem is already a member of the group."); |
618 | Put_message("Use the order command if you want to change the sorting order."); | |
619 | } else if (stat) | |
620 | com_err(program_name, stat, " in AddFSToGroup"); | |
621 | return(DM_NORMAL); | |
622 | } | |
623 | ||
624 | ||
625 | /* Function Name: RemoveFSFromGroup | |
626 | * Description: delete a filesystem from an FS group | |
627 | * Arguments: arc, argv - name of group in argv[1]. | |
628 | * Returns: DM_NORMAL. | |
629 | */ | |
630 | ||
631 | /* ARGSUSED */ | |
632 | int | |
633 | RemoveFSFromGroup(argc, argv) | |
634 | char **argv; | |
635 | int argc; | |
636 | { | |
637 | int stat; | |
638 | char buf[BUFSIZ]; | |
639 | ||
640 | sprintf(buf, "Delete filesystem %s from FS group %s", argv[2], argv[1]); | |
641 | if (!Confirm(buf)) | |
642 | return(DM_NORMAL); | |
8defc06b | 643 | if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, argv+1, |
9e2516d6 | 644 | Scream, NULL)) != 0) { |
645 | com_err(program_name, stat, ", not removed."); | |
646 | } | |
647 | return(DM_NORMAL); | |
648 | } | |
649 | ||
650 | /* Function Name: ChangeFSGroupOrder | |
651 | * Description: change the sortkey on a filesys in an FSgroup | |
652 | * Arguments: arc, argv - name of group in argv[1]. | |
653 | * Returns: DM_NORMAL. | |
654 | */ | |
655 | ||
656 | /* ARGSUSED */ | |
657 | int | |
658 | ChangeFSGroupOrder(argc, argv) | |
659 | char **argv; | |
660 | int argc; | |
661 | { | |
662 | int stat, src, dst; | |
663 | struct qelem *elem = NULL, *top; | |
664 | char buf[BUFSIZ], *bufp, *args[3]; | |
665 | ||
8defc06b | 666 | if ((stat = do_mr_query("get_fsgroup_members", 1, argv+1, StoreInfo, |
9e2516d6 | 667 | (char *)&elem)) != 0) { |
8defc06b | 668 | if (stat == MR_NO_MATCH) { |
9e2516d6 | 669 | sprintf(buf, "Ether %s is not a filesystem group or it has no members", argv[1]); |
670 | Put_message(buf); | |
671 | } else | |
672 | com_err(program_name, stat, " in ChangeFSGroupOrder"); | |
673 | return(DM_NORMAL); | |
674 | } | |
675 | top = QueueTop(elem); | |
676 | fsgCount = 1; | |
677 | Loop(top, (void *) PrintFSGMembers); | |
678 | while (1) { | |
679 | bufp = Strsave("1"); | |
680 | stat = GetValueFromUser("Enter number of the filesystem to move:", | |
681 | &bufp); | |
682 | src = atoi(bufp); | |
683 | free(bufp); | |
684 | if (src < 0) { | |
685 | Put_message("You must enter a positive number (or 0 to abort)."); | |
686 | continue; | |
687 | } else if (src == 0) { | |
688 | Put_message("Aborted."); | |
689 | return(DM_NORMAL); | |
690 | } | |
691 | for (elem = top; src-- > 1 && elem->q_forw; elem = elem->q_forw); | |
692 | if (src > 1) { | |
693 | Put_message("You entered a number that is too high"); | |
694 | continue; | |
695 | } | |
696 | break; | |
697 | } | |
698 | bufp = Strsave("0"); | |
699 | stat = GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp); | |
700 | dst = atoi(bufp); | |
701 | free(bufp); | |
702 | if (src == dst || src == dst + 1) { | |
703 | Put_message("That has no effect on the sorting order!"); | |
704 | return(DM_NORMAL); | |
705 | } | |
706 | args[2] = SortAfter(top, dst); | |
707 | args[0] = argv[1]; | |
708 | args[1] = ((char **)elem->q_data)[0]; | |
8defc06b | 709 | if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, args, |
9e2516d6 | 710 | Scream, NULL)) != 0) { |
711 | com_err(program_name, stat, " in ChangeFSGroupOrder"); | |
712 | return(DM_NORMAL); | |
713 | } | |
8defc06b | 714 | if ((stat = do_mr_query("add_filesys_to_fsgroup", 3, args, |
9e2516d6 | 715 | Scream, NULL)) != 0) { |
716 | com_err(program_name, stat, " in ChangeFSGroupOrder"); | |
717 | } | |
718 | return(DM_NORMAL); | |
719 | } | |
720 | ||
721 | ||
08345b74 | 722 | /* -------------- Top Level Menu ---------------- */ |
723 | ||
724 | /* Function Name: GetFSAlias | |
725 | * Description: Gets the value for a Filesystem Alias. | |
726 | * Arguments: argc, argv - name of alias in argv[1]. | |
727 | * Returns: DM_NORMAL. | |
728 | * NOTES: There should only be one filesystem per alias, thus | |
729 | * this will work correctly. | |
730 | */ | |
731 | ||
732 | /* ARGSUSED */ | |
733 | int | |
734 | GetFSAlias(argc, argv) | |
735 | int argc; | |
736 | char **argv; | |
737 | { | |
0a2c64cb | 738 | struct qelem *top; |
08345b74 | 739 | |
0a2c64cb | 740 | top = GetFSInfo(ALIAS, argv[1]); |
85ca828a | 741 | Put_message(" "); /* blank line. */ |
0a2c64cb | 742 | Loop(top, (void *) PrintFSAlias); |
08345b74 | 743 | FreeQueue(top); |
744 | return(DM_NORMAL); | |
745 | } | |
746 | ||
747 | /* Function Name: CreateFSAlias | |
6c7a2fcf | 748 | * Description: Create an alias name for a filesystem |
08345b74 | 749 | * Arguments: argc, argv - name of alias in argv[1]. |
750 | * Returns: DM_NORMAL. | |
751 | * NOTES: This requires (name, type, transl) I get {name, translation} | |
752 | * from the user. I provide type, which is well-known. | |
753 | */ | |
754 | ||
755 | /* ARGSUSED */ | |
756 | int | |
757 | CreateFSAlias(argc, argv) | |
758 | int argc; | |
759 | char **argv; | |
760 | { | |
461c03b6 | 761 | register int stat; |
08345b74 | 762 | struct qelem *elem, *top; |
461c03b6 | 763 | char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info; |
08345b74 | 764 | |
765 | elem = NULL; | |
766 | ||
767 | if (!ValidName(argv[1])) | |
768 | return(DM_NORMAL); | |
769 | ||
461c03b6 | 770 | args[ALIAS_NAME] = Strsave(argv[1]); |
771 | args[ALIAS_TYPE] = Strsave(FS_ALIAS_TYPE); | |
85ca828a | 772 | args[ALIAS_TRANS] = Strsave("*"); |
08345b74 | 773 | |
774 | /* | |
775 | * Check to see if this alias already exists in the database, if so then | |
776 | * print out values, free memory used and then exit. | |
777 | */ | |
778 | ||
8defc06b | 779 | if ( (stat = do_mr_query("get_alias", 3, args, StoreInfo, |
14f99d7d | 780 | (char *)&elem)) == 0) { |
85ca828a | 781 | top = elem = QueueTop(elem); |
08345b74 | 782 | while (elem != NULL) { |
783 | info = (char **) elem->q_data; | |
85ca828a | 784 | sprintf(buf,"The alias: %s currently describes the filesystem %s", |
461c03b6 | 785 | info[ALIAS_NAME], info[ALIAS_TRANS]); |
08345b74 | 786 | Put_message(buf); |
787 | elem = elem->q_forw; | |
788 | } | |
789 | FreeQueue(top); | |
790 | return(DM_NORMAL); | |
791 | } | |
8defc06b | 792 | else if ( stat != MR_NO_MATCH) { |
461c03b6 | 793 | com_err(program_name, stat, " in CreateFSAlias."); |
08345b74 | 794 | return(DM_NORMAL); |
795 | } | |
796 | ||
461c03b6 | 797 | args[ALIAS_TRANS]= args[ALIAS_END] = NULL; /* set to NULL initially. */ |
08345b74 | 798 | GetValueFromUser("Which filesystem will this alias point to?", |
461c03b6 | 799 | &args[ALIAS_TRANS]); |
08345b74 | 800 | |
8defc06b | 801 | if ( (stat = do_mr_query("add_alias", 3, args, NullFunc, NULL)) != 0) |
461c03b6 | 802 | com_err(program_name, stat, " in CreateFSAlias."); |
08345b74 | 803 | |
461c03b6 | 804 | FreeInfo(args); |
08345b74 | 805 | return (DM_NORMAL); |
806 | } | |
402461ad | 807 | |
808 | /* Function Name: RealDeleteFSAlias | |
809 | * Description: Does the real deletion work. | |
810 | * Arguments: info - array of char *'s containing all useful info. | |
811 | * one_item - a Boolean that is true if only one item | |
812 | * in queue that dumped us here. | |
813 | * Returns: none. | |
814 | */ | |
815 | ||
816 | void | |
817 | RealDeleteFSAlias(info, one_item) | |
818 | char ** info; | |
819 | Bool one_item; | |
820 | { | |
821 | int stat; | |
822 | char temp_buf[BUFSIZ]; | |
823 | ||
824 | /* | |
825 | * Deletetions are performed if the user hits 'y' on a list of multiple | |
826 | * filesystem, or if the user confirms on a unique alias. | |
827 | */ | |
828 | sprintf(temp_buf, | |
829 | "Are you sure that you want to delete the filesystem alias %s", | |
830 | info[ALIAS_NAME]); | |
831 | if(!one_item || Confirm(temp_buf)) { | |
8defc06b | 832 | if ( (stat = do_mr_query("delete_alias", CountArgs(info), |
14f99d7d | 833 | info, Scream, NULL)) != 0 ) |
402461ad | 834 | com_err(program_name, stat, " filesystem alias not deleted."); |
835 | else | |
836 | Put_message("Filesystem alias deleted."); | |
837 | } | |
838 | else | |
839 | Put_message("Filesystem alias not deleted."); | |
840 | } | |
08345b74 | 841 | |
842 | /* Function Name: DeleteFSAlias | |
6c7a2fcf | 843 | * Description: Delete an alias name for a filesystem |
08345b74 | 844 | * Arguments: argc, argv - name of alias in argv[1]. |
845 | * Returns: DM_NORMAL. | |
846 | * NOTES: This requires (name, type, transl) I get {name, translation} | |
847 | * from the user. I provide type, which is well-known. | |
848 | */ | |
849 | ||
850 | /* ARGSUSED */ | |
851 | int | |
852 | DeleteFSAlias(argc, argv) | |
853 | int argc; | |
854 | char **argv; | |
855 | { | |
402461ad | 856 | struct qelem *elem = GetFSInfo(ALIAS, argv[1]); |
857 | QueryLoop(elem, PrintFSAlias, RealDeleteFSAlias, | |
858 | "Delete the Filesystem Alias"); | |
859 | FreeQueue(elem); | |
08345b74 | 860 | return (DM_NORMAL); |
861 | } | |
862 | ||
863 | /* Function Name: AttachHelp | |
864 | * Description: Print help info on attachmaint. | |
865 | * Arguments: none | |
866 | * Returns: DM_NORMAL. | |
867 | */ | |
868 | ||
869 | int | |
870 | AttachHelp() | |
871 | { | |
872 | static char *message[] = { | |
9e2516d6 | 873 | "These are the options:", |
874 | "", | |
875 | "get - get information about a filesystem.", | |
876 | "add - add a new filesystem to the data base.", | |
877 | "update - update the information in the database on a filesystem.", | |
878 | "delete - delete a filesystem from the database.", | |
879 | "check - check information about association of a name and a filesys.", | |
880 | "alias - associate a name with a filesystem.", | |
881 | "unalias - disassociate a name with a filesystem.", | |
882 | "verbose - toggle the request for delete confirmation.", | |
08345b74 | 883 | NULL, |
884 | }; | |
885 | ||
886 | return(PrintHelp(message)); | |
887 | } | |
9e2516d6 | 888 | |
889 | /* Function Name: FSGroupHelp | |
890 | * Description: Print help info on fsgroups. | |
891 | * Arguments: none | |
892 | * Returns: DM_NORMAL. | |
893 | */ | |
894 | ||
895 | int | |
896 | FSGroupHelp() | |
897 | { | |
898 | static char *message[] = { | |
899 | "A filesystem group is a named sorted list of filesystems.", | |
900 | "", | |
901 | "To create, modify, or delete a group itself, use the menu above", | |
902 | " this one, and manipulate a filesystem of type FSGROUP.", | |
903 | "Options here are:", | |
904 | " get - get info about a group and show its members", | |
905 | " add - add a new member to a group.", | |
906 | " remove - remove a member from a group.", | |
907 | " order - change the sorting order of a group.", | |
908 | NULL | |
909 | }; | |
910 | ||
911 | return(PrintHelp(message)); | |
912 | } |