]> andersk Git - moira.git/blob - clients/moira/attach.c
fixed bug in array length
[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 MOIRA Client, which allows a nieve
6  *      user to quickly and easily maintain most parts of the MOIRA 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 <moira.h>
27 #include <moira_site.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_mr_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_mr_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_mr_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_mr_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_mr_query("get_fsgroup_members", 1, &info[FS_NAME],
198                                  StoreInfo, (char *)&elem)) != 0) {
199             if (stat == MR_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, access_type[32];
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         sprintf(access_type, "fs_access_%s", info[FS_TYPE]);
280         GetTypeFromUser("Filesystem's Default Access", access_type,
281                         &info[FS_ACCESS]);
282     }
283     GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS]);
284     GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]);
285     GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]);
286     if (!fsgroup)
287       GetYesNoValueFromUser("Automatically create this filesystem",
288                             &info[FS_CREATE]);
289     GetTypeFromUser("Filesystem's lockertype", "lockertype", &info[FS_L_TYPE]);
290
291     FreeAndClear(&info[FS_MODTIME], TRUE);
292     FreeAndClear(&info[FS_MODBY], TRUE);
293     FreeAndClear(&info[FS_MODWITH], TRUE);
294
295     if (name)                   /* slide the newname into the #2 slot. */
296         SlipInNewName(info, newname);
297
298     return(info);
299 }
300
301 /* --------------- Filesystem Menu ------------- */
302
303 /*      Function Name: GetFS
304  *      Description: Get Filesystem information by name.
305  *      Arguments: argc, argv - name of filsys in argv[1].
306  *      Returns: DM_NORMAL.
307  */
308
309 /* ARGSUSED */
310 int
311 GetFS(argc, argv)
312 int argc;
313 char **argv;
314 {
315     struct qelem *top;
316
317     top = GetFSInfo(LABEL, argv[1]); /* get info. */
318     Loop(top, (void *) PrintFSInfo);
319     FreeQueue(top);             /* clean the queue. */
320     return (DM_NORMAL);
321 }
322
323 /*      Function Name: RealDeleteFS
324  *      Description: Does the real deletion work.
325  *      Arguments: info - array of char *'s containing all useful info.
326  *                 one_item - a Boolean that is true if only one item 
327  *                              in queue that dumped us here.
328  *      Returns: none.
329  */
330
331 void
332 RealDeleteFS(info, one_item)
333 char ** info;
334 Bool one_item;
335 {
336     int stat;
337     char temp_buf[BUFSIZ];
338
339 /* 
340  * Deletetions are  performed if the user hits 'y' on a list of multiple 
341  * filesystem, or if the user confirms on a unique alias.
342  */
343     sprintf(temp_buf, "Are you sure that you want to delete filesystem %s",
344             info[FS_NAME]);
345     if(!one_item || Confirm(temp_buf)) {
346         if ( (stat = do_mr_query("delete_filesys", 1,
347                                   &info[FS_NAME], Scream, NULL)) != 0)
348             com_err(program_name, stat, " filesystem not deleted.");
349         else
350             Put_message("Filesystem deleted.");
351     }
352     else 
353         Put_message("Filesystem not deleted.");
354 }
355
356 /*      Function Name: DeleteFS
357  *      Description: Delete a filesystem give its name.
358  *      Arguments: argc, argv - argv[1] is the name of the filesystem.
359  *      Returns: none.
360  */
361
362 /* ARGSUSED */
363  
364 int
365 DeleteFS(argc, argv)
366 int argc;
367 char **argv;
368 {
369     struct qelem *elem = GetFSInfo(LABEL, argv[1]);
370     QueryLoop(elem, PrintFSInfo, RealDeleteFS, "Delete the Filesystem");
371
372     FreeQueue(elem);
373     return (DM_NORMAL);
374 }
375
376 /*      Function Name: RealChangeFS
377  *      Description: performs the actual change to the filesys.
378  *      Arguments: info - the information 
379  *                 junk - an unused boolean.
380  *      Returns: none.
381  */
382
383 /* ARGSUSED. */
384 static void
385 RealChangeFS(info, junk)
386 char ** info;
387 Bool junk;
388 {
389     int stat;
390     char ** args = AskFSInfo(info, TRUE);
391     extern Menu nfsphys_menu;
392
393     stat = do_mr_query("update_filesys", CountArgs(args), args,
394                         NullFunc, NULL);
395     switch (stat) {
396     case MR_NFS:
397         Put_message("That NFS filesystem is not exported.");
398         if (YesNoQuestion("Fix this now (Y/N)")) {
399             Do_menu(&nfsphys_menu, 0, NULL);
400             if (YesNoQuestion("Retry filesystem update now (Y/N)")) {
401                 if (stat = do_mr_query("update_filesys", CountArgs(args), args,
402                                         NullFunc, NULL))
403                     com_err(program_name, stat, " filesystem not updated");
404                 else
405                     Put_message("filesystem sucessfully updated.");
406             }
407         }
408         break;
409     case MR_SUCCESS:
410         break;
411     default:
412         com_err(program_name, stat, " in UpdateFS");
413     }
414 }
415
416 /*      Function Name: ChangeFS
417  *      Description: change the information in a filesys record.
418  *      Arguments: arc, argv - value of filsys in argv[1].
419  *      Returns: DM_NORMAL.
420  */
421
422 /* ARGSUSED */
423 int
424 ChangeFS(argc, argv)
425 char **argv;
426 int argc;
427 {
428     struct qelem *elem = GetFSInfo(LABEL, argv[1]);
429     QueryLoop(elem, NullPrint, RealChangeFS, "Update the Filesystem");
430
431     FreeQueue(elem);
432     return (DM_NORMAL);
433 }
434
435 /*      Function Name: AddFS
436  *      Description: change the information in a filesys record.
437  *      Arguments: arc, argv - name of filsys in argv[1].
438  *      Returns: DM_NORMAL.
439  */
440
441 /* ARGSUSED */
442 int
443 AddFS(argc, argv)
444 char **argv;
445 int argc;
446 {
447     char *info[MAX_ARGS_SIZE], **args, buf[BUFSIZ];
448     int stat;
449     extern Menu nfsphys_menu;
450
451     if ( !ValidName(argv[1]) )
452         return(DM_NORMAL);
453
454     if ( (stat = do_mr_query("get_filesys_by_label", 1, argv + 1,
455                               NullFunc, NULL)) == 0) {
456         Put_message ("A Filesystem by that name already exists.");
457         return(DM_NORMAL);
458     } else if (stat != MR_NO_MATCH) {
459         com_err(program_name, stat, " in AddFS");
460         return(DM_NORMAL);
461     } 
462
463     args = AskFSInfo(SetDefaults(info, argv[1]), FALSE );
464
465     stat = do_mr_query("add_filesys", CountArgs(args), args, NullFunc, NULL);
466     switch (stat) {
467     case MR_NFS:
468         Put_message("That NFS filesystem is not exported.");
469         if (YesNoQuestion("Fix this now (Y/N)")) {
470             Do_menu(&nfsphys_menu, 0, NULL);
471             if (YesNoQuestion("Retry filesystem creation now (Y/N)")) {
472                 if (stat = do_mr_query("add_filesys", CountArgs(args), args,
473                                         NullFunc, NULL))
474                     com_err(program_name, stat, " in AddFS");
475                 else
476                     Put_message("Created.");
477             }
478         }
479         break;
480     case MR_SUCCESS:
481         break;
482     default:
483         com_err(program_name, stat, " in AddFS");
484     }
485
486     if (stat == MR_SUCCESS && !strcasecmp(info[FS_L_TYPE], "HOMEDIR")) {
487         static char *val[] = {"def_quota", NULL};
488         static char *def_quota = NULL;
489         char *argv[Q_QUOTA + 1];
490         struct qelem *top = NULL;
491
492         if (def_quota == NULL) {
493             stat = do_mr_query("get_value", CountArgs(val), val,
494                                 StoreInfo, (char *) &top);
495             if (stat != MR_SUCCESS) {
496                 com_err(program_name, stat, " getting default quota");
497             } else {
498                 top = QueueTop(top);
499                 def_quota = Strsave(((char **)top->q_data)[0]);
500                 FreeQueue(top);
501             }
502         }
503         if (def_quota != NULL) {
504             sprintf(buf, "Give user %s a quota of %s on filesys %s (Y/N)",
505                     info[FS_NAME], def_quota, info[FS_NAME]);
506             if (YesNoQuestion(buf, 1)) {
507                 argv[Q_NAME] = argv[Q_FILESYS] = info[FS_NAME];
508                 argv[Q_TYPE] = "USER";
509                 argv[Q_QUOTA] = def_quota;
510                 if ((stat = do_mr_query("add_quota", Q_QUOTA+1, argv, Scream,
511                                          (char *) NULL)) != MR_SUCCESS) {
512                     com_err(program_name, stat, " while adding quota");
513                 }
514             }
515         }
516     }
517
518     FreeInfo(info);
519     return (DM_NORMAL);
520 }
521
522 /*      Function Name: SortAfter
523  *      Description: choose a sortkey to cause an item to be added after 
524  *              the count element in the queue
525  *      Arguments: queue of filesys names & sortkeys, queue count pointer
526  *      Returns: sort key to use.
527  */
528
529 /* ARGSUSED */
530 char *
531 SortAfter(elem, count)
532 struct qelem *elem;
533 int count;
534 {
535     char *prev, *next, prevnext, *key, keybuf[9];
536
537     /* first find the two keys we need to insert between */
538     prev = "A";
539     for (; count > 0; count--) {
540         prev = ((char **)elem->q_data)[1];
541         if (elem->q_forw)
542           elem = elem->q_forw;
543         else
544           break;
545     }
546     if (count > 0)
547       next = "Z";
548     else
549       next = ((char **)elem->q_data)[1];
550
551     /* now copy the matching characters */
552     for (key = keybuf; *prev && *prev == *next; next++) {
553         *key++ = *prev++;
554     }
555
556     /* and set the last character */
557     if (*prev == 0)
558       *prev = prevnext = 'A';
559     else
560       prevnext = prev[1];
561     if (prevnext == 0)
562       prevnext = 'A';
563     if (*next == 0)
564       *next = 'Z';
565     if (*next - *prev > 1) {
566         *key++ = (*next + *prev)/2;
567     } else {
568         *key++ = *prev;
569         *key++ = (prevnext + 'Z')/2;
570     }
571     *key = 0;
572     return(Strsave(keybuf));
573 }
574
575 /*      Function Name: AddFSToGroup
576  *      Description: add a filesystem to an FS group
577  *      Arguments: arc, argv - name of group in argv[1], filesys in argv[2].
578  *      Returns: DM_NORMAL.
579  */
580
581 /* ARGSUSED */
582 int
583 AddFSToGroup(argc, argv)
584 char **argv;
585 int argc;
586 {
587     int stat, count;
588     struct qelem *elem = NULL;
589     char buf[BUFSIZ], *args[5], *bufp;
590
591     if ((stat = do_mr_query("get_fsgroup_members", 1, argv+1, StoreInfo,
592                              (char *)&elem)) != 0) {
593         if (stat != MR_NO_MATCH)
594           com_err(program_name, stat, " in AddFSToGroup");
595     }
596     if (elem == NULL) {
597         args[0] = argv[1];
598         args[1] = argv[2];
599         args[2] = "M";
600         stat = do_mr_query("add_filesys_to_fsgroup", 3, args, Scream, NULL);
601         if (stat)
602           com_err(program_name, stat, " in AddFSToGroup");
603         return(DM_NORMAL);
604     }
605     elem = QueueTop(elem);
606     fsgCount = 1;
607     Loop(elem, (void *) PrintFSGMembers);
608     sprintf(buf, "%d", QueueCount(elem));
609     bufp = Strsave(buf);
610     stat = GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp);
611     count = atoi(bufp);
612     free(bufp);
613     args[2] = SortAfter(elem, count);
614
615     FreeQueue(QueueTop(elem));
616     args[0] = argv[1];
617     args[1] = argv[2];
618     stat = do_mr_query("add_filesys_to_fsgroup", 3, args, Scream, NULL);
619     if (stat == MR_EXISTS) {
620         Put_message("That filesystem is already a member of the group.");
621         Put_message("Use the order command if you want to change the sorting order.");
622     } else if (stat)
623       com_err(program_name, stat, " in AddFSToGroup");
624     return(DM_NORMAL);
625 }
626
627
628 /*      Function Name: RemoveFSFromGroup
629  *      Description: delete a filesystem from an FS group
630  *      Arguments: arc, argv - name of group in argv[1].
631  *      Returns: DM_NORMAL.
632  */
633
634 /* ARGSUSED */
635 int
636 RemoveFSFromGroup(argc, argv)
637 char **argv;
638 int argc;
639 {
640     int stat;
641     char buf[BUFSIZ];
642
643     sprintf(buf, "Delete filesystem %s from FS group %s", argv[2], argv[1]);
644     if (!Confirm(buf))
645       return(DM_NORMAL);
646     if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, argv+1,
647                              Scream, NULL)) != 0) {
648         com_err(program_name, stat, ", not removed.");
649     }
650     return(DM_NORMAL);
651 }
652
653 /*      Function Name: ChangeFSGroupOrder
654  *      Description: change the sortkey on a filesys in an FSgroup
655  *      Arguments: arc, argv - name of group in argv[1].
656  *      Returns: DM_NORMAL.
657  */
658
659 /* ARGSUSED */
660 int
661 ChangeFSGroupOrder(argc, argv)
662 char **argv;
663 int argc;
664 {
665     int stat, src, dst;
666     struct qelem *elem = NULL, *top;
667     char buf[BUFSIZ], *bufp, *args[3];
668
669     if ((stat = do_mr_query("get_fsgroup_members", 1, argv+1, StoreInfo,
670                              (char *)&elem)) != 0) {
671         if (stat == MR_NO_MATCH) {
672             sprintf(buf, "Ether %s is not a filesystem group or it has no members", argv[1]);
673             Put_message(buf);
674         } else
675           com_err(program_name, stat, " in ChangeFSGroupOrder");
676         return(DM_NORMAL);
677     }
678     top = QueueTop(elem);
679     fsgCount = 1;
680     Loop(top, (void *) PrintFSGMembers);
681     while (1) {
682         bufp = Strsave("1");
683         stat = GetValueFromUser("Enter number of the filesystem to move:",
684                                 &bufp);
685         src = atoi(bufp);
686         free(bufp);
687         if (src < 0) {
688             Put_message("You must enter a positive number (or 0 to abort).");
689             continue;
690         } else if (src == 0) {
691             Put_message("Aborted.");
692             return(DM_NORMAL);
693         }
694         for (elem = top; src-- > 1 && elem->q_forw; elem = elem->q_forw);
695         if (src > 1) {
696             Put_message("You entered a number that is too high");
697             continue;
698         }
699         break;
700     }
701     bufp = Strsave("0");
702     stat = GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp);
703     dst = atoi(bufp);
704     free(bufp);
705     if (src == dst || src == dst + 1) {
706         Put_message("That has no effect on the sorting order!");
707         return(DM_NORMAL);
708     }
709     args[2] = SortAfter(top, dst);
710     args[0] = argv[1];
711     args[1] = ((char **)elem->q_data)[0];
712     if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, args,
713                              Scream, NULL)) != 0) {
714         com_err(program_name, stat, " in ChangeFSGroupOrder");
715         return(DM_NORMAL);
716     }
717     if ((stat = do_mr_query("add_filesys_to_fsgroup", 3, args,
718                              Scream, NULL)) != 0) {
719         com_err(program_name, stat, " in ChangeFSGroupOrder");
720     }
721     return(DM_NORMAL);
722 }
723
724
725 /* -------------- Top Level Menu ---------------- */
726
727 /*      Function Name: GetFSAlias
728  *      Description: Gets the value for a Filesystem Alias.
729  *      Arguments: argc, argv - name of alias in argv[1].
730  *      Returns: DM_NORMAL.
731  *      NOTES: There should only be one filesystem per alias, thus
732  *             this will work correctly.
733  */
734
735 /* ARGSUSED */
736 int
737 GetFSAlias(argc, argv)
738 int argc;
739 char **argv;
740 {
741     struct qelem *top;
742
743     top = GetFSInfo(ALIAS, argv[1]);
744     Put_message(" ");           /* blank line. */
745     Loop(top, (void *) PrintFSAlias);
746     FreeQueue(top);
747     return(DM_NORMAL);
748 }
749
750 /*      Function Name: CreateFSAlias
751  *      Description: Create an alias name for a filesystem
752  *      Arguments: argc, argv - name of alias in argv[1].
753  *      Returns: DM_NORMAL.
754  *      NOTES:  This requires (name, type, transl)  I get {name, translation}
755  *              from the user.  I provide type, which is well-known. 
756  */
757
758 /* ARGSUSED */
759 int
760 CreateFSAlias(argc, argv)
761 int argc;
762 char **argv;
763 {
764     register int stat;
765     struct qelem *elem, *top;
766     char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info;
767
768     elem = NULL;
769
770     if (!ValidName(argv[1]))
771         return(DM_NORMAL);
772
773     args[ALIAS_NAME] = Strsave(argv[1]);
774     args[ALIAS_TYPE] = Strsave(FS_ALIAS_TYPE);
775     args[ALIAS_TRANS] = Strsave("*");
776
777 /*
778  * Check to see if this alias already exists in the database, if so then
779  * print out values, free memory used and then exit.
780  */
781
782     if ( (stat = do_mr_query("get_alias", 3, args, StoreInfo, 
783                               (char *)&elem)) == 0) {
784         top = elem = QueueTop(elem);
785         while (elem != NULL) {
786             info = (char **) elem->q_data;          
787             sprintf(buf,"The alias: %s currently describes the filesystem %s",
788                     info[ALIAS_NAME], info[ALIAS_TRANS]);
789             Put_message(buf);
790             elem = elem->q_forw;
791         }
792         FreeQueue(top);
793         return(DM_NORMAL);
794     }
795     else if ( stat != MR_NO_MATCH) {
796         com_err(program_name, stat, " in CreateFSAlias.");
797         return(DM_NORMAL);
798     }
799
800     args[ALIAS_TRANS]= args[ALIAS_END] = NULL;  /* set to NULL initially. */
801     GetValueFromUser("Which filesystem will this alias point to?",
802                      &args[ALIAS_TRANS]);
803
804     if ( (stat = do_mr_query("add_alias", 3, args, NullFunc, NULL)) != 0)
805         com_err(program_name, stat, " in CreateFSAlias.");
806
807     FreeInfo(args);
808     return (DM_NORMAL);
809 }
810     
811 /*      Function Name: RealDeleteFSAlias
812  *      Description: Does the real deletion work.
813  *      Arguments: info - array of char *'s containing all useful info.
814  *                 one_item - a Boolean that is true if only one item 
815  *                              in queue that dumped us here.
816  *      Returns: none.
817  */
818
819 void
820 RealDeleteFSAlias(info, one_item)
821 char ** info;
822 Bool one_item;
823 {
824     int stat;
825     char temp_buf[BUFSIZ];
826
827 /* 
828  * Deletetions are  performed if the user hits 'y' on a list of multiple 
829  * filesystem, or if the user confirms on a unique alias.
830  */
831     sprintf(temp_buf, 
832             "Are you sure that you want to delete the filesystem alias %s",
833             info[ALIAS_NAME]);
834     if(!one_item || Confirm(temp_buf)) {
835         if ( (stat = do_mr_query("delete_alias", CountArgs(info),
836                                   info, Scream, NULL)) != 0 )
837             com_err(program_name, stat, " filesystem alias not deleted.");
838         else
839             Put_message("Filesystem alias deleted.");
840     }
841     else 
842         Put_message("Filesystem alias not deleted.");
843 }
844
845 /*      Function Name: DeleteFSAlias
846  *      Description: Delete an alias name for a filesystem
847  *      Arguments: argc, argv - name of alias in argv[1].
848  *      Returns: DM_NORMAL.
849  *      NOTES:  This requires (name, type, transl)  I get {name, translation}
850  *              from the user.  I provide type, which is well-known. 
851  */
852
853 /* ARGSUSED */
854 int
855 DeleteFSAlias(argc, argv)
856 int argc;
857 char **argv;
858 {
859     struct qelem *elem = GetFSInfo(ALIAS, argv[1]);
860     QueryLoop(elem, PrintFSAlias, RealDeleteFSAlias,
861               "Delete the Filesystem Alias");
862     FreeQueue(elem);
863     return (DM_NORMAL);
864 }
865
866 /*      Function Name: AttachHelp
867  *      Description: Print help info on attachmaint.
868  *      Arguments: none
869  *      Returns: DM_NORMAL.
870  */
871
872 int
873 AttachHelp()
874 {
875     static char *message[] = {
876       "These are the options:",
877       "",
878       "get - get information about a filesystem.",
879       "add - add a new filesystem to the data base.",
880       "update - update the information in the database on a filesystem.",
881       "delete - delete a filesystem from the database.",
882       "check - check information about association of a name and a filesys.",
883       "alias - associate a name with a filesystem.",
884       "unalias - disassociate a name with a filesystem.",
885       "verbose - toggle the request for delete confirmation.",
886         NULL,
887     };
888
889     return(PrintHelp(message));
890 }
891
892 /*      Function Name: FSGroupHelp
893  *      Description: Print help info on fsgroups.
894  *      Arguments: none
895  *      Returns: DM_NORMAL.
896  */
897
898 int
899 FSGroupHelp()
900 {
901     static char *message[] = {
902         "A filesystem group is a named sorted list of filesystems.",
903         "",
904         "To create, modify, or delete a group itself, use the menu above",
905         "  this one, and manipulate a filesystem of type FSGROUP.",
906         "Options here are:",
907         "  get - get info about a group and show its members",
908         "  add - add a new member to a group.",
909         "  remove - remove a member from a group.",
910         "  order - change the sorting order of a group.",
911         NULL
912     };
913
914     return(PrintHelp(message));
915 }
This page took 0.134351 seconds and 5 git commands to generate.