]> andersk Git - moira.git/blob - clients/moira/attach.c
a345be302685b2aace400bee2bc564c8477156c0
[moira.git] / clients / moira / attach.c
1 #if (!defined(lint) && !defined(SABER))
2   static char rcsid_module_c[] = "$Header$";
3 #endif
4
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. 
10  *      
11  *      Created:        5/4/88
12  *      By:             Chris D. Peterson
13  *
14  *      $Source$
15  *      $Author$
16  *      $Header$
17  *      
18  *      Copyright 1988 by the Massachusetts Institute of Technology.
19  *
20  *      For further information on copyright and distribution 
21  *      see the file mit-copyright.h
22  */
23
24 #include <stdio.h>
25 #include <strings.h>
26 #include <sms.h>
27 #include <sms_app.h>
28 #include <menu.h>
29
30 #include "mit-copyright.h"
31 #include "defs.h"
32 #include "f_defs.h"
33 #include "globals.h"
34
35 #define FS_ALIAS_TYPE "FILESYS"
36
37 #define LABEL        0
38 #define MACHINE      1
39 #define GROUP        2
40 #define ALIAS        3
41
42 #define NO_MACHINE       ("\\[NONE\\]") /* C will remove one of the /'s here,
43                                          * and the other quotes the [ for
44                                          * ingres' regexp facility. */
45 #define NO_MACHINE_BAD   ("[NONE]")
46
47 #define DEFAULT_TYPE     ("NFS")
48 #define DEFAULT_MACHINE  DEFAULT_NONE
49 #define DEFAULT_PACK     DEFAULT_NONE
50 #define DEFAULT_ACCESS   ("w")
51 #define DEFAULT_COMMENTS DEFAULT_COMMENT
52 #define DEFAULT_OWNER    (user)
53 #define DEFAULT_OWNERS   (user)
54 #define DEFAULT_CREATE   DEFAULT_YES
55 #define DEFAULT_L_TYPE   ("PROJECT")
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 {
68     char buf[BUFSIZ];
69
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);
74     sprintf(buf, "/mit/%s", name);
75     info[FS_M_POINT] =  Strsave(buf);
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
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
93 static struct qelem *
94 GetFSInfo(type, name)
95 int type;
96 char *name;
97 {
98     int stat;
99     struct qelem * elem = NULL;
100     char * args[5];
101
102     switch (type) {
103     case LABEL:
104         if ( (stat = do_sms_query("get_filesys_by_label", 1, &name,
105                                   StoreInfo, (char *)&elem)) != 0) {
106             com_err(program_name, stat, NULL);
107             return(NULL);
108         }
109         break;
110     case MACHINE:
111         if ( (stat = do_sms_query("get_filesys_by_machine", 1, &name,
112                                   StoreInfo, (char *)&elem)) != 0) {
113             com_err(program_name, stat, NULL);
114             return(NULL);
115         }
116         break;
117     case GROUP:
118         if ( (stat = do_sms_query("get_filesys_by_group", 1, &name,
119                                   StoreInfo, (char *)&elem)) != 0) {
120             com_err(program_name, stat, NULL);
121             return(NULL);
122         }
123         break;
124     case ALIAS:
125         args[ALIAS_NAME] = name;
126         args[ALIAS_TYPE] = FS_ALIAS_TYPE;
127         args[ALIAS_TRANS] = "*";
128         if ( (stat = do_sms_query("get_alias", 3, args, StoreInfo, 
129                                   (char *) &elem)) != 0) {
130             com_err(program_name, stat, " in get_alias.");
131             return(NULL);
132         }
133     }
134
135     return(QueueTop(elem));
136 }
137
138 /*      Function Name: PrintFSAlias
139  *      Description: Prints a filesystem alias
140  *      Arguments: info - an array contains the strings of info.
141  *      Returns: the name of the filesys - used be QueryLoop().
142  */
143
144 static char *
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);
153     return(info[ALIAS_NAME]);
154 }
155
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
170 /*      Function Name: PrintFSInfo
171  *      Description: Prints the filesystem information.
172  *      Arguments: info - a pointer to the filesystem information.
173  *      Returns: none.
174  */
175
176 static char *
177 PrintFSInfo(info)
178 char ** info;
179 {
180     char print_buf[BUFSIZ];
181
182     FORMFEED;
183
184     if (!strcmp(info[FS_TYPE], "FSGROUP")) {
185         int stat;
186         struct qelem *elem = NULL;
187
188         sprintf(print_buf,"%20s Filesystem Group: %s", " ", info[FS_NAME]);
189         Put_message(print_buf);
190
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):");
197         if ((stat = do_sms_query("get_fsgroup_members", 1, &info[FS_NAME],
198                                  StoreInfo, (char *)&elem)) != 0) {
199             if (stat == SMS_NO_MATCH)
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 {
209         sprintf(print_buf,"%20s Filesystem: %s", " ", info[FS_NAME]);
210         Put_message(print_buf);
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     }
230     return(info[FS_NAME]);
231 }
232
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
242 static char **
243 AskFSInfo(info, name)
244 char ** info;
245 Bool name;
246 {
247     char temp_buf[BUFSIZ], *newname;
248     int fsgroup = 0;
249
250     Put_message("");
251     sprintf(temp_buf, "Changing Attributes of filesystem %s.", 
252             info[FS_NAME]);
253     Put_message(temp_buf);
254     Put_message("");
255
256     if (name) {
257         newname = Strsave(info[FS_NAME]);
258         GetValueFromUser("The new name for this filesystem",
259                          &newname);
260     }
261
262     GetTypeFromUser("Filesystem's Type", "filesys", &info[FS_TYPE]);
263     if (!strcasecmp(info[FS_TYPE], "FSGROUP"))
264       fsgroup++;
265     if (fsgroup || !strcasecmp(info[FS_TYPE], "AFS")) {
266         free(info[FS_MACHINE]);
267         info[FS_MACHINE] = Strsave(NO_MACHINE);
268     } else {
269         if (!strcmp(info[FS_MACHINE], NO_MACHINE_BAD)) {
270             free(info[FS_MACHINE]);
271             info[FS_MACHINE] = Strsave(NO_MACHINE);
272         }
273         GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]);
274         info[FS_MACHINE] = canonicalize_hostname(info[FS_MACHINE]);
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     }
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]);
284     if (!fsgroup)
285       GetYesNoValueFromUser("Automatically create this filesystem",
286                             &info[FS_CREATE]);
287     GetTypeFromUser("Filesystem's lockertype", "lockertype", &info[FS_L_TYPE]);
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 {
313     struct qelem *top;
314
315     top = GetFSInfo(LABEL, argv[1]); /* get info. */
316     Loop(top, (void *) PrintFSInfo);
317     FreeQueue(top);             /* clean the queue. */
318     return (DM_NORMAL);
319 }
320
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)) {
344         if ( (stat = do_sms_query("delete_filesys", 1,
345                                   &info[FS_NAME], Scream, NULL)) != 0)
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
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 {
367     struct qelem *elem = GetFSInfo(LABEL, argv[1]);
368     QueryLoop(elem, PrintFSInfo, RealDeleteFS, "Delete the Filesystem");
369
370     FreeQueue(elem);
371     return (DM_NORMAL);
372 }
373
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);
389     extern Menu nfsphys_menu;
390
391     stat = do_sms_query("update_filesys", CountArgs(args), args,
392                         NullFunc, NULL);
393     switch (stat) {
394     case SMS_NFS:
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)")) {
399                 if (stat = do_sms_query("update_filesys", CountArgs(args), args,
400                                         NullFunc, NULL))
401                     com_err(program_name, stat, " filesystem not updated");
402                 else
403                     Put_message("filesystem sucessfully updated.");
404             }
405         }
406         break;
407     case SMS_SUCCESS:
408         break;
409     default:
410         com_err(program_name, stat, " in UpdateFS");
411     }
412 }
413
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 {
426     struct qelem *elem = GetFSInfo(LABEL, argv[1]);
427     QueryLoop(elem, NullPrint, RealChangeFS, "Update the Filesystem");
428
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 {
445     char *info[MAX_ARGS_SIZE], **args, buf[BUFSIZ];
446     int stat;
447     extern Menu nfsphys_menu;
448
449     if ( !ValidName(argv[1]) )
450         return(DM_NORMAL);
451
452     if ( (stat = do_sms_query("get_filesys_by_label", 1, argv + 1,
453                               NullFunc, NULL)) == 0) {
454         Put_message ("A Filesystem by that name already exists.");
455         return(DM_NORMAL);
456     } else if (stat != SMS_NO_MATCH) {
457         com_err(program_name, stat, " in AddFS");
458         return(DM_NORMAL);
459     } 
460
461     args = AskFSInfo(SetDefaults(info, argv[1]), FALSE );
462
463     stat = do_sms_query("add_filesys", CountArgs(args), args, NullFunc, NULL);
464     switch (stat) {
465     case SMS_NFS:
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)")) {
470                 if (stat = do_sms_query("add_filesys", CountArgs(args), args,
471                                         NullFunc, NULL))
472                     com_err(program_name, stat, " in AddFS");
473                 else
474                     Put_message("Created.");
475             }
476         }
477         break;
478     case SMS_SUCCESS:
479         break;
480     default:
481         com_err(program_name, stat, " in AddFS");
482     }
483
484     if (stat == SMS_SUCCESS && !strcasecmp(info[FS_L_TYPE], "HOMEDIR")) {
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) {
491             stat = do_sms_query("get_value", CountArgs(val), val,
492                                 StoreInfo, (char *) &top);
493             if (stat != SMS_SUCCESS) {
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;
507                 if ((stat = do_sms_query("add_nfs_quota", 3, argv, Scream,
508                                          (char *) NULL)) != SMS_SUCCESS) {
509                     com_err(program_name, stat, " while adding quota");
510                 }
511             }
512         }
513     }
514
515     FreeInfo(info);
516     return (DM_NORMAL);
517 }
518
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
588     if ((stat = do_sms_query("get_fsgroup_members", 1, argv+1, StoreInfo,
589                              (char *)&elem)) != 0) {
590         if (stat != SMS_NO_MATCH)
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";
597         stat = do_sms_query("add_filesys_to_fsgroup", 3, args, Scream, NULL);
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];
615     stat = do_sms_query("add_filesys_to_fsgroup", 3, args, Scream, NULL);
616     if (stat == SMS_EXISTS) {
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);
643     if ((stat = do_sms_query("remove_filesys_from_fsgroup", 2, argv+1,
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
666     if ((stat = do_sms_query("get_fsgroup_members", 1, argv+1, StoreInfo,
667                              (char *)&elem)) != 0) {
668         if (stat == SMS_NO_MATCH) {
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];
709     if ((stat = do_sms_query("remove_filesys_from_fsgroup", 2, args,
710                              Scream, NULL)) != 0) {
711         com_err(program_name, stat, " in ChangeFSGroupOrder");
712         return(DM_NORMAL);
713     }
714     if ((stat = do_sms_query("add_filesys_to_fsgroup", 3, args,
715                              Scream, NULL)) != 0) {
716         com_err(program_name, stat, " in ChangeFSGroupOrder");
717     }
718     return(DM_NORMAL);
719 }
720
721
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 {
738     struct qelem *top;
739
740     top = GetFSInfo(ALIAS, argv[1]);
741     Put_message(" ");           /* blank line. */
742     Loop(top, (void *) PrintFSAlias);
743     FreeQueue(top);
744     return(DM_NORMAL);
745 }
746
747 /*      Function Name: CreateFSAlias
748  *      Description: Create an alias name for a filesystem
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 {
761     register int stat;
762     struct qelem *elem, *top;
763     char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info;
764
765     elem = NULL;
766
767     if (!ValidName(argv[1]))
768         return(DM_NORMAL);
769
770     args[ALIAS_NAME] = Strsave(argv[1]);
771     args[ALIAS_TYPE] = Strsave(FS_ALIAS_TYPE);
772     args[ALIAS_TRANS] = Strsave("*");
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
779     if ( (stat = do_sms_query("get_alias", 3, args, StoreInfo, 
780                               (char *)&elem)) == 0) {
781         top = elem = QueueTop(elem);
782         while (elem != NULL) {
783             info = (char **) elem->q_data;          
784             sprintf(buf,"The alias: %s currently describes the filesystem %s",
785                     info[ALIAS_NAME], info[ALIAS_TRANS]);
786             Put_message(buf);
787             elem = elem->q_forw;
788         }
789         FreeQueue(top);
790         return(DM_NORMAL);
791     }
792     else if ( stat != SMS_NO_MATCH) {
793         com_err(program_name, stat, " in CreateFSAlias.");
794         return(DM_NORMAL);
795     }
796
797     args[ALIAS_TRANS]= args[ALIAS_END] = NULL;  /* set to NULL initially. */
798     GetValueFromUser("Which filesystem will this alias point to?",
799                      &args[ALIAS_TRANS]);
800
801     if ( (stat = do_sms_query("add_alias", 3, args, NullFunc, NULL)) != 0)
802         com_err(program_name, stat, " in CreateFSAlias.");
803
804     FreeInfo(args);
805     return (DM_NORMAL);
806 }
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)) {
832         if ( (stat = do_sms_query("delete_alias", CountArgs(info),
833                                   info, Scream, NULL)) != 0 )
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 }
841
842 /*      Function Name: DeleteFSAlias
843  *      Description: Delete an alias name for a filesystem
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 {
856     struct qelem *elem = GetFSInfo(ALIAS, argv[1]);
857     QueryLoop(elem, PrintFSAlias, RealDeleteFSAlias,
858               "Delete the Filesystem Alias");
859     FreeQueue(elem);
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[] = {
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.",
883         NULL,
884     };
885
886     return(PrintHelp(message));
887 }
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 }
This page took 0.094895 seconds and 3 git commands to generate.