1 #if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
5 /* This is the file attach.c for the SMS Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the SMS database.
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.
12 * By: Chris D. Peterson
18 * Copyright 1988 by the Massachusetts Institute of Technology.
20 * For further information on copyright and distribution
21 * see the file mit-copyright.h
29 #include "mit-copyright.h"
35 #define FS_ALIAS_TYPE "FILESYS"
42 #define DEFAULT_TYPE ("NFS")
43 #define DEFAULT_MACHINE DEFAULT_NONE
44 #define DEFAULT_PACK DEFAULT_NONE
45 #define DEFAULT_M_POINT DEFAULT_NONE
46 #define DEFAULT_ACCESS ("w")
47 #define DEFAULT_COMMENTS DEFAULT_COMMENT
48 #define DEFAULT_OWNER (user)
49 #define DEFAULT_OWNERS (user)
50 #define DEFAULT_CREATE DEFAULT_YES
51 #define DEFAULT_L_TYPE ("PROJECT")
53 /* Function Name: SetDefaults
54 * Description: sets the default values for filesystem additions.
55 * Arguments: info - an array of char pointers to recieve defaults.
56 * Returns: char ** (this array, now filled).
60 SetDefaults(info, name)
64 info[FS_NAME] = Strsave(name);
65 info[FS_TYPE] = Strsave(DEFAULT_TYPE);
66 info[FS_MACHINE] = Strsave(DEFAULT_MACHINE);
67 info[FS_PACK] = Strsave(DEFAULT_PACK);
68 info[FS_M_POINT] = Strsave(DEFAULT_M_POINT);
69 info[FS_ACCESS] = Strsave(DEFAULT_ACCESS);
70 info[FS_COMMENTS] = Strsave(DEFAULT_COMMENTS);
71 info[FS_OWNER] = Strsave(DEFAULT_OWNER);
72 info[FS_OWNERS] = Strsave(DEFAULT_OWNERS);
73 info[FS_CREATE] = Strsave(DEFAULT_CREATE);
74 info[FS_L_TYPE] = Strsave(DEFAULT_L_TYPE);
75 info[FS_MODTIME] = info[FS_MODBY] = info[FS_MODWITH] = info[FS_END] = NULL;
79 /* Function Name: GetFSInfo
80 * Description: Stores the info in a queue.
81 * Arguments: type - type of information to get.
82 * name - name of the item to get information on.
83 * Returns: a pointer to the first element in the queue.
92 struct qelem * elem = NULL;
97 if ( (stat = sms_query("get_filesys_by_label", 1, &name,
98 StoreInfo, (char *)&elem)) != 0) {
99 com_err(program_name, stat, NULL);
104 if ( (stat = sms_query("get_filesys_by_machine", 1, &name,
105 StoreInfo, (char *)&elem)) != 0) {
106 com_err(program_name, stat, NULL);
111 if ( (stat = sms_query("get_filesys_by_group", 1, &name,
112 StoreInfo, (char *)&elem)) != 0) {
113 com_err(program_name, stat, NULL);
118 args[ALIAS_NAME] = name;
119 args[ALIAS_TYPE] = FS_ALIAS_TYPE;
120 args[ALIAS_TRANS] = "*";
121 if ( (stat = sms_query("get_alias", 3, args, StoreInfo,
122 (char *) &elem)) != 0) {
123 com_err(program_name, stat, " in get_alias.");
128 return(QueueTop(elem));
131 /* Function Name: PrintFSAlias
132 * Description: Prints a filesystem alias
133 * Arguments: info - an array contains the strings of info.
134 * Returns: the name of the filesys - used be QueryLoop().
143 sprintf(buf,"Alias: %-25s Filesystem: %s",info[ALIAS_NAME],
146 return(info[ALIAS_NAME]);
149 /* Function Name: PrintFSInfo
150 * Description: Prints the filesystem information.
151 * Arguments: info - a pointer to the filesystem information.
159 char print_buf[BUFSIZ];
161 sprintf(print_buf,"%20s Filesystem: %s",
163 Put_message(print_buf);
164 sprintf(print_buf,"Type: %-40s Machine: %-15s",
165 info[FS_TYPE], info[FS_MACHINE]);
166 Put_message(print_buf);
167 sprintf(print_buf,"Default Access: %-2s Packname: %-17s Mountpoint %s ",
168 info[FS_ACCESS], info[FS_PACK], info[FS_M_POINT]);
169 Put_message(print_buf);
170 sprintf(print_buf,"Comments; %s",info[FS_COMMENTS]);
171 Put_message(print_buf);
172 sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s",
173 info[FS_OWNER], info[FS_OWNERS]);
174 Put_message(print_buf);
175 sprintf(print_buf, "Auto Create: %-34s Locker Type: %s",
176 atoi(info[FS_CREATE]) ? "ON" : "OFF",
178 Put_message(print_buf);
179 sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME],
181 Put_message(print_buf);
182 return(info[FS_NAME]);
185 /* Function Name: AskFSInfo.
186 * Description: This function askes the user for information about a
187 * machine and saves it into a structure.
188 * Arguments: info - a pointer the the structure to put the
190 * name - add a newname field? (T/F)
195 AskFSInfo(info, name)
199 char temp_buf[BUFSIZ], *newname;
202 sprintf(temp_buf, "Changing Attributes of filesystem %s.",
204 Put_message(temp_buf);
208 newname = Strsave(info[FS_NAME]);
209 GetValueFromUser("The new name for this filesystem",
213 GetValueFromUser("Filesystem's Type", &info[FS_TYPE]);
214 GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]);
215 strcpy(temp_buf, CanonicalizeHostname(info[FS_MACHINE]));
216 free(info[FS_MACHINE]);
217 info[FS_MACHINE] = Strsave(temp_buf);
218 GetValueFromUser("Filesystem's Pack Name", &info[FS_PACK]);
219 GetValueFromUser("Filesystem's Mount Point", &info[FS_M_POINT]);
220 GetValueFromUser("Filesystem's Default Access", &info[FS_ACCESS]);
221 GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS]);
222 GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]);
223 GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]);
224 GetYesNoValueFromUser("Automatically create this filesystem",
226 GetValueFromUser("Filesystem's lockertype", &info[FS_L_TYPE]);
228 FreeAndClear(&info[FS_MODTIME], TRUE);
229 FreeAndClear(&info[FS_MODBY], TRUE);
230 FreeAndClear(&info[FS_MODWITH], TRUE);
232 if (name) /* slide the newname into the #2 slot. */
233 SlipInNewName(info, newname);
238 /* --------------- Filesystem Menu ------------- */
240 /* Function Name: GetFS
241 * Description: Get Filesystem information by name.
242 * Arguments: argc, argv - name of filsys in argv[1].
243 * Returns: DM_NORMAL.
254 top = GetFSInfo(LABEL, argv[1]); /* get info. */
255 Loop(top, (void *) PrintFSInfo);
256 FreeQueue(top); /* clean the queue. */
260 /* Function Name: RealDeleteFS
261 * Description: Does the real deletion work.
262 * Arguments: info - array of char *'s containing all useful info.
263 * one_item - a Boolean that is true if only one item
264 * in queue that dumped us here.
269 RealDeleteFS(info, one_item)
274 char temp_buf[BUFSIZ];
277 * Deletetions are performed if the user hits 'y' on a list of multiple
278 * filesystem, or if the user confirms on a unique alias.
280 sprintf(temp_buf, "Are you sure that you want to delete filesystem %s",
282 if(!one_item || Confirm(temp_buf)) {
283 if ( (stat = sms_query("delete_filesys", 1,
284 &info[FS_NAME], Scream, NULL)) != 0)
285 com_err(program_name, stat, " filesystem not deleted.");
287 Put_message("Filesystem deleted.");
290 Put_message("Filesystem not deleted.");
293 /* Function Name: DeleteFS
294 * Description: Delete a filesystem give its name.
295 * Arguments: argc, argv - argv[1] is the name of the filesystem.
306 struct qelem *elem = GetFSInfo(LABEL, argv[1]);
307 QueryLoop(elem, PrintFSInfo, RealDeleteFS, "Delete the Filesystem");
313 /* Function Name: RealChangeFS
314 * Description: performs the actual change to the filesys.
315 * Arguments: info - the information
316 * junk - an unused boolean.
322 RealChangeFS(info, junk)
327 char ** args = AskFSInfo(info, TRUE);
329 if ( (stat = sms_query("update_filesys", CountArgs(args),
330 args, NullFunc, NULL)) != 0)
331 com_err(program_name, stat, ", filesystem not updated");
333 Put_message("filesystem sucessfully updated.");
336 /* Function Name: ChangeFS
337 * Description: change the information in a filesys record.
338 * Arguments: arc, argv - value of filsys in argv[1].
339 * Returns: DM_NORMAL.
348 struct qelem *elem = GetFSInfo(LABEL, argv[1]);
349 QueryLoop(elem, NullPrint, RealChangeFS, "Update the Filesystem");
355 /* Function Name: AddFS
356 * Description: change the information in a filesys record.
357 * Arguments: arc, argv - name of filsys in argv[1].
358 * Returns: DM_NORMAL.
367 char *info[MAX_ARGS_SIZE], **args;
370 if ( !ValidName(argv[1]) )
373 if ( (stat = sms_query("get_filesys_by_label", 1, argv + 1,
374 NullFunc, NULL)) == 0) {
375 Put_message ("A Filesystem by that name already exists.");
377 } else if (stat != SMS_NO_MATCH) {
378 com_err(program_name, stat, " in AddFS");
382 args = AskFSInfo(SetDefaults(info, argv[1]), FALSE );
384 if ( (stat = sms_query("add_filesys", CountArgs(args), args,
385 NullFunc, NULL)) != 0)
386 com_err(program_name, stat, " in AddFS");
392 /* -------------- Top Level Menu ---------------- */
394 /* Function Name: GetFSAlias
395 * Description: Gets the value for a Filesystem Alias.
396 * Arguments: argc, argv - name of alias in argv[1].
397 * Returns: DM_NORMAL.
398 * NOTES: There should only be one filesystem per alias, thus
399 * this will work correctly.
404 GetFSAlias(argc, argv)
410 top = GetFSInfo(ALIAS, argv[1]);
411 Put_message(" "); /* blank line. */
412 Loop(top, (void *) PrintFSAlias);
417 /* Function Name: CreateFSAlias
418 * Description: Create an alias name for a filesystem
419 * Arguments: argc, argv - name of alias in argv[1].
420 * Returns: DM_NORMAL.
421 * NOTES: This requires (name, type, transl) I get {name, translation}
422 * from the user. I provide type, which is well-known.
427 CreateFSAlias(argc, argv)
432 struct qelem *elem, *top;
433 char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info;
437 if (!ValidName(argv[1]))
440 args[ALIAS_NAME] = Strsave(argv[1]);
441 args[ALIAS_TYPE] = Strsave(FS_ALIAS_TYPE);
442 args[ALIAS_TRANS] = Strsave("*");
445 * Check to see if this alias already exists in the database, if so then
446 * print out values, free memory used and then exit.
449 if ( (stat = sms_query("get_alias", 3, args, StoreInfo,
450 (char *)&elem)) == 0) {
451 top = elem = QueueTop(elem);
452 while (elem != NULL) {
453 info = (char **) elem->q_data;
454 sprintf(buf,"The alias: %s currently describes the filesystem %s",
455 info[ALIAS_NAME], info[ALIAS_TRANS]);
462 else if ( stat != SMS_NO_MATCH) {
463 com_err(program_name, stat, " in CreateFSAlias.");
467 args[ALIAS_TRANS]= args[ALIAS_END] = NULL; /* set to NULL initially. */
468 GetValueFromUser("Which filesystem will this alias point to?",
471 if ( (stat = sms_query("add_alias", 3, args, NullFunc, NULL)) != 0)
472 com_err(program_name, stat, " in CreateFSAlias.");
478 /* Function Name: RealDeleteFSAlias
479 * Description: Does the real deletion work.
480 * Arguments: info - array of char *'s containing all useful info.
481 * one_item - a Boolean that is true if only one item
482 * in queue that dumped us here.
487 RealDeleteFSAlias(info, one_item)
492 char temp_buf[BUFSIZ];
495 * Deletetions are performed if the user hits 'y' on a list of multiple
496 * filesystem, or if the user confirms on a unique alias.
499 "Are you sure that you want to delete the filesystem alias %s",
501 if(!one_item || Confirm(temp_buf)) {
502 if ( (stat = sms_query("delete_alias", CountArgs(info),
503 info, Scream, NULL)) != 0 )
504 com_err(program_name, stat, " filesystem alias not deleted.");
506 Put_message("Filesystem alias deleted.");
509 Put_message("Filesystem alias not deleted.");
512 /* Function Name: DeleteFSAlias
513 * Description: Delete an alias name for a filesystem
514 * Arguments: argc, argv - name of alias in argv[1].
515 * Returns: DM_NORMAL.
516 * NOTES: This requires (name, type, transl) I get {name, translation}
517 * from the user. I provide type, which is well-known.
522 DeleteFSAlias(argc, argv)
526 struct qelem *elem = GetFSInfo(ALIAS, argv[1]);
527 QueryLoop(elem, PrintFSAlias, RealDeleteFSAlias,
528 "Delete the Filesystem Alias");
533 /* Function Name: AttachHelp
534 * Description: Print help info on attachmaint.
536 * Returns: DM_NORMAL.
542 static char *message[] = {
543 "These are the options:\n\n",
544 "get - get information about a filesystem.\n",
545 "add - add a new filesystem to the data base.\n",
546 "update - update the information in the database on a filesystem.\n",
547 "delete - delete a filesystem from the database.\n",
548 "check - check information about association of a name and a filesys.\n",
549 "alias - associate a name with a filesystem.\n",
550 "unalias - disassociate a name with a filesystem.\n",
551 "verbose - toggle the request for delete confirmation.\n",
555 return(PrintHelp(message));
562 * c-continued-statement-offset: 4
564 * c-argdecl-indent: 4