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