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