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 ("r")
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 ("HOMEDIR")
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, &elem)) != 0) {
99 com_err(program_name, stat, NULL);
104 if ( (stat = sms_query("get_filesys_by_machine", 1, &name,
105 StoreInfo, &elem)) != 0) {
106 com_err(program_name, stat, NULL);
111 if ( (stat = sms_query("get_filesys_by_group", 1, &name,
112 StoreInfo, &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, &elem)) != 0) {
122 com_err(program_name, stat, " in get_alias.");
127 return(QueueTop(elem));
130 /* Function Name: PrintFSAlias
131 * Description: Prints a filesystem alias
132 * Arguments: info - an array contains the strings of info.
133 * Returns: the name of the filesys - used be QueryLoop().
142 sprintf(buf,"Alias: %-25s Filesystem: %s",info[ALIAS_NAME],
145 return(info[ALIAS_NAME]);
148 /* Function Name: PrintFSInfo
149 * Description: Prints the filesystem information.
150 * Arguments: info - a pointer to the filesystem information.
158 char print_buf[BUFSIZ];
160 sprintf(print_buf,"%20s Filesystem: %s",
162 Put_message(print_buf);
163 sprintf(print_buf,"Type: %-40s Machine: %-15s",
164 info[FS_TYPE], info[FS_MACHINE]);
165 Put_message(print_buf);
166 sprintf(print_buf,"Default Access: %-2s Packname: %-17s Mountpoint %s ",
167 info[FS_ACCESS], info[FS_PACK], info[FS_M_POINT]);
168 Put_message(print_buf);
169 sprintf(print_buf,"Comments; %s",info[FS_COMMENTS]);
170 Put_message(print_buf);
171 sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s",
172 info[FS_OWNER], info[FS_OWNERS]);
173 Put_message(print_buf);
174 sprintf(print_buf, "Auto Create: %-34s Locker Type: %s",
175 atoi(info[FS_CREATE]) ? "ON" : "OFF",
177 Put_message(print_buf);
178 sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME],
180 Put_message(print_buf);
181 return(info[FS_NAME]);
184 /* Function Name: AskFSInfo.
185 * Description: This function askes the user for information about a
186 * machine and saves it into a structure.
187 * Arguments: info - a pointer the the structure to put the
189 * name - add a newname field? (T/F)
194 AskFSInfo(info, name)
198 char temp_buf[BUFSIZ], *newname;
201 sprintf(temp_buf, "Changing Attributes of filesystem %s.",
203 Put_message(temp_buf);
207 newname = Strsave(info[FS_NAME]);
208 GetValueFromUser("The new name for this filesystem",
212 GetValueFromUser("Filesystem's Type", &info[FS_TYPE]);
213 GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]);
214 strcpy(temp_buf, CanonicalizeHostname(info[FS_MACHINE]));
215 free(info[FS_MACHINE]);
216 info[FS_MACHINE] = Strsave(temp_buf);
217 GetValueFromUser("Filesystem's Pack Name", &info[FS_PACK]);
218 GetValueFromUser("Filesystem's Mount Point", &info[FS_M_POINT]);
219 GetValueFromUser("Filesystem's Default Access", &info[FS_ACCESS]);
220 GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS]);
221 GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]);
222 GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]);
223 GetYesNoValueFromUser("Automatically create this filsystem",
225 GetValueFromUser("Filesystem's lockertype", &info[FS_L_TYPE]);
227 FreeAndClear(&info[FS_MODTIME], TRUE);
228 FreeAndClear(&info[FS_MODBY], TRUE);
229 FreeAndClear(&info[FS_MODWITH], TRUE);
231 if (name) /* slide the newname into the #2 slot. */
232 SlipInNewName(info, newname);
237 /* --------------- Filesystem Menu ------------- */
239 /* Function Name: GetFS
240 * Description: Get Filesystem information by name.
241 * Arguments: argc, argv - name of filsys in argv[1].
242 * Returns: DM_NORMAL.
253 top = GetFSInfo(LABEL, argv[1]); /* get info. */
254 Loop(top, (void *) PrintFSInfo);
255 FreeQueue(top); /* clean the queue. */
259 /* Function Name: RealDeleteFS
260 * Description: Does the real deletion work.
261 * Arguments: info - array of char *'s containing all useful info.
262 * one_item - a Boolean that is true if only one item
263 * in queue that dumped us here.
268 RealDeleteFS(info, one_item)
273 char temp_buf[BUFSIZ];
276 * Deletetions are performed if the user hits 'y' on a list of multiple
277 * filesystem, or if the user confirms on a unique alias.
279 sprintf(temp_buf, "Are you sure that you want to delete filesystem %s",
281 if(!one_item || Confirm(temp_buf)) {
282 if ( (stat = sms_query("delete_filesys", 1,
283 &info[FS_NAME], Scream, NULL)) != 0)
284 com_err(program_name, stat, " filesystem not deleted.");
286 Put_message("Filesystem deleted.");
289 Put_message("Filesystem not deleted.");
292 /* Function Name: DeleteFS
293 * Description: Delete a filesystem give its name.
294 * Arguments: argc, argv - argv[1] is the name of the filesystem.
305 struct qelem *elem = GetFSInfo(LABEL, argv[1]);
306 QueryLoop(elem, PrintFSInfo, RealDeleteFS, "Delete the Filesystem");
312 /* Function Name: RealChangeFS
313 * Description: performs the actual change to the filesys.
314 * Arguments: info - the information
315 * junk - an unused boolean.
321 RealChangeFS(info, junk)
326 char ** args = AskFSInfo(info, TRUE);
328 if ( (stat = sms_query("update_filesys", CountArgs(args),
329 args, NullFunc, NULL)) != 0)
330 com_err(program_name, stat, ", filesystem not updated");
332 Put_message("filesystem sucessfully updated.");
335 /* Function Name: ChangeFS
336 * Description: change the information in a filesys record.
337 * Arguments: arc, argv - value of filsys in argv[1].
338 * Returns: DM_NORMAL.
347 struct qelem *elem = GetFSInfo(LABEL, argv[1]);
348 QueryLoop(elem, NullPrint, RealChangeFS, "Update the Filesystem");
354 /* Function Name: AddFS
355 * Description: change the information in a filesys record.
356 * Arguments: arc, argv - name of filsys in argv[1].
357 * Returns: DM_NORMAL.
366 char *info[MAX_ARGS_SIZE], **args;
369 if ( !ValidName(argv[1]) )
372 if ( (stat = sms_query("get_filesys_by_label", 1, argv + 1,
373 NullFunc, NULL)) == 0) {
374 Put_message ("A Filesystem by that name already exists.");
376 } else if (stat != SMS_NO_MATCH) {
377 com_err(program_name, stat, " in AddFS");
381 args = AskFSInfo(SetDefaults(info, argv[1]), FALSE );
383 if ( (stat = sms_query("add_filesys", CountArgs(args), args,
384 NullFunc, NULL)) != 0)
385 com_err(program_name, stat, " in AddFS");
391 /* -------------- Top Level Menu ---------------- */
393 /* Function Name: GetFSAlias
394 * Description: Gets the value for a Filesystem Alias.
395 * Arguments: argc, argv - name of alias in argv[1].
396 * Returns: DM_NORMAL.
397 * NOTES: There should only be one filesystem per alias, thus
398 * this will work correctly.
403 GetFSAlias(argc, argv)
409 top = GetFSInfo(ALIAS, argv[1]);
410 Put_message(" "); /* blank line. */
411 Loop(top, (void *) PrintFSAlias);
416 /* Function Name: CreateFSAlias
417 * Description: Create an alias name for a filsystem
418 * Arguments: argc, argv - name of alias in argv[1].
419 * Returns: DM_NORMAL.
420 * NOTES: This requires (name, type, transl) I get {name, translation}
421 * from the user. I provide type, which is well-known.
426 CreateFSAlias(argc, argv)
431 struct qelem *elem, *top;
432 char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info;
436 if (!ValidName(argv[1]))
439 args[ALIAS_NAME] = Strsave(argv[1]);
440 args[ALIAS_TYPE] = Strsave(FS_ALIAS_TYPE);
441 args[ALIAS_TRANS] = Strsave("*");
444 * Check to see if this alias already exists in the database, if so then
445 * print out values, free memory used and then exit.
448 if ( (stat = sms_query("get_alias", 3, args, StoreInfo, &elem)) == 0) {
449 top = elem = QueueTop(elem);
450 while (elem != NULL) {
451 info = (char **) elem->q_data;
452 sprintf(buf,"The alias: %s currently describes the filesystem %s",
453 info[ALIAS_NAME], info[ALIAS_TRANS]);
460 else if ( stat != SMS_NO_MATCH) {
461 com_err(program_name, stat, " in CreateFSAlias.");
465 args[ALIAS_TRANS]= args[ALIAS_END] = NULL; /* set to NULL initially. */
466 GetValueFromUser("Which filesystem will this alias point to?",
469 if ( (stat = sms_query("add_alias", 3, args, NullFunc, NULL)) != 0)
470 com_err(program_name, stat, " in CreateFSAlias.");
476 /* Function Name: RealDeleteFSAlias
477 * Description: Does the real deletion work.
478 * Arguments: info - array of char *'s containing all useful info.
479 * one_item - a Boolean that is true if only one item
480 * in queue that dumped us here.
485 RealDeleteFSAlias(info, one_item)
490 char temp_buf[BUFSIZ];
493 * Deletetions are performed if the user hits 'y' on a list of multiple
494 * filesystem, or if the user confirms on a unique alias.
497 "Are you sure that you want to delete the filesystem alias %s",
499 if(!one_item || Confirm(temp_buf)) {
500 if ( (stat = sms_query("delete_alias", CountArgs(info),
501 info, Scream, NULL)) != 0 )
502 com_err(program_name, stat, " filesystem alias not deleted.");
504 Put_message("Filesystem alias deleted.");
507 Put_message("Filesystem alias not deleted.");
510 /* Function Name: DeleteFSAlias
511 * Description: Delete an alias name for a filsystem
512 * Arguments: argc, argv - name of alias in argv[1].
513 * Returns: DM_NORMAL.
514 * NOTES: This requires (name, type, transl) I get {name, translation}
515 * from the user. I provide type, which is well-known.
520 DeleteFSAlias(argc, argv)
524 struct qelem *elem = GetFSInfo(ALIAS, argv[1]);
525 QueryLoop(elem, PrintFSAlias, RealDeleteFSAlias,
526 "Delete the Filesystem Alias");
531 /* Function Name: AttachHelp
532 * Description: Print help info on attachmaint.
534 * Returns: DM_NORMAL.
540 static char *message[] = {
541 "These are the options:\n\n",
542 "get - get information about a filesystem.\n",
543 "add - add a new filesystem to the data base.\n",
544 "update - update the information in the database on a filesystem.\n",
545 "delete - delete a filesystem from the database.\n",
546 "check - check information about association of a name and a filesys.\n",
547 "alias - associate a name with a filsystem.\n",
548 "unalias - disassociate a name with a filesystem.\n",
549 "verbose - toggle the request for delete confirmation.\n",
553 return(PrintHelp(message));
560 * c-continued-statement-offset: 4
562 * c-argdecl-indent: 4