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