]> andersk Git - moira.git/blob - clients/moira/attach.c
a3b850a448e6621fd6ee0fd9e40f8c8488296b4f
[moira.git] / clients / moira / attach.c
1 #if (!defined(lint) && !defined(SABER))
2   static char rcsid_module_c[] = "$Header$";
3 #endif
4
5 /*      This is the file attach.c for the SMS Client, which allows a nieve
6  *      user to quickly and easily maintain most parts of the SMS database.
7  *      It Contains: Functions for maintaining data used by Hesiod 
8  *                   to map courses/projects/users to their file systems, 
9  *                   and maintain filesys info. 
10  *      
11  *      Created:        5/4/88
12  *      By:             Chris D. Peterson
13  *
14  *      $Source$
15  *      $Author$
16  *      $Header$
17  *      
18  *      Copyright 1988 by the Massachusetts Institute of Technology.
19  *
20  *      For further information on copyright and distribution 
21  *      see the file mit-copyright.h
22  */
23
24 #include <stdio.h>
25 #include <strings.h>
26 #include <sms.h>
27 #include <sms_app.h>
28 #include <menu.h>
29
30 #include "mit-copyright.h"
31 #include "defs.h"
32 #include "f_defs.h"
33 #include "globals.h"
34
35 #define FS_ALIAS_TYPE "FILESYS"
36
37 #define LABEL        0
38 #define MACHINE      1
39 #define GROUP        2
40 #define ALIAS        3
41
42 #define NO_MACHINE       ("\\[NONE\\]") /* C will remove one of the /'s here,
43                                          * and the other quotes the [ for
44                                          * ingres' regexp facility. */
45
46 #define DEFAULT_TYPE     ("NFS")
47 #define DEFAULT_MACHINE  DEFAULT_NONE
48 #define DEFAULT_PACK     DEFAULT_NONE
49 #define DEFAULT_M_POINT  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     info[FS_NAME] =     Strsave(name);
69     info[FS_TYPE] =     Strsave(DEFAULT_TYPE);
70     info[FS_MACHINE] =  Strsave(DEFAULT_MACHINE);
71     info[FS_PACK] =     Strsave(DEFAULT_PACK);
72     info[FS_M_POINT] =  Strsave(DEFAULT_M_POINT);
73     info[FS_ACCESS] =   Strsave(DEFAULT_ACCESS);
74     info[FS_COMMENTS] = Strsave(DEFAULT_COMMENTS);
75     info[FS_OWNER] =    Strsave(DEFAULT_OWNER);
76     info[FS_OWNERS] =   Strsave(DEFAULT_OWNERS);
77     info[FS_CREATE] =   Strsave(DEFAULT_CREATE);
78     info[FS_L_TYPE] =   Strsave(DEFAULT_L_TYPE);
79     info[FS_MODTIME] = info[FS_MODBY] = info[FS_MODWITH] = info[FS_END] = NULL;
80     return(info);
81 }
82
83 /*      Function Name: GetFSInfo
84  *      Description: Stores the info in a queue.
85  *      Arguments: type - type of information to get.
86  *                 name - name of the item to get information on.
87  *      Returns: a pointer to the first element in the queue.
88  */
89
90 static struct qelem *
91 GetFSInfo(type, name)
92 int type;
93 char *name;
94 {
95     int stat;
96     struct qelem * elem = NULL;
97     char * args[5];
98
99     switch (type) {
100     case LABEL:
101         if ( (stat = do_sms_query("get_filesys_by_label", 1, &name,
102                                   StoreInfo, (char *)&elem)) != 0) {
103             com_err(program_name, stat, NULL);
104             return(NULL);
105         }
106         break;
107     case MACHINE:
108         if ( (stat = do_sms_query("get_filesys_by_machine", 1, &name,
109                                   StoreInfo, (char *)&elem)) != 0) {
110             com_err(program_name, stat, NULL);
111             return(NULL);
112         }
113         break;
114     case GROUP:
115         if ( (stat = do_sms_query("get_filesys_by_group", 1, &name,
116                                   StoreInfo, (char *)&elem)) != 0) {
117             com_err(program_name, stat, NULL);
118             return(NULL);
119         }
120         break;
121     case ALIAS:
122         args[ALIAS_NAME] = name;
123         args[ALIAS_TYPE] = FS_ALIAS_TYPE;
124         args[ALIAS_TRANS] = "*";
125         if ( (stat = do_sms_query("get_alias", 3, args, StoreInfo, 
126                                   (char *) &elem)) != 0) {
127             com_err(program_name, stat, " in get_alias.");
128             return(NULL);
129         }
130     }
131
132     return(QueueTop(elem));
133 }
134
135 /*      Function Name: PrintFSAlias
136  *      Description: Prints a filesystem alias
137  *      Arguments: info - an array contains the strings of info.
138  *      Returns: the name of the filesys - used be QueryLoop().
139  */
140
141 static char *
142 PrintFSAlias(info)
143 char ** info;
144 {
145     char buf[BUFSIZ];
146
147     sprintf(buf,"Alias: %-25s Filesystem: %s",info[ALIAS_NAME], 
148             info[ALIAS_TRANS]);
149     Put_message(buf);
150     return(info[ALIAS_NAME]);
151 }
152
153 static int fsgCount = 1;
154
155 static char *
156 PrintFSGMembers(info)
157 char ** info;
158 {
159     char print_buf[BUFSIZ];
160
161     sprintf(print_buf, "  %d. Filesystem: %-32s (sort key: %s)", fsgCount++, info[0], info[1]);
162     Put_message(print_buf);
163     return(info[0]);
164 }
165
166
167 /*      Function Name: PrintFSInfo
168  *      Description: Prints the filesystem information.
169  *      Arguments: info - a pointer to the filesystem information.
170  *      Returns: none.
171  */
172
173 static char *
174 PrintFSInfo(info)
175 char ** info;
176 {
177     char print_buf[BUFSIZ];
178
179     FORMFEED;
180     sprintf(print_buf,"%20s Filesystem Group: %s", 
181             " ",info[FS_NAME]);
182     Put_message(print_buf);
183
184     if (!strcmp(info[FS_TYPE], "FSGROUP")) {
185         int stat;
186         struct qelem *elem = NULL;
187
188         sprintf(print_buf,"Comments; %s",info[FS_COMMENTS]);
189         Put_message(print_buf);
190         sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME], 
191                 info[FS_MODWITH]);
192         Put_message(print_buf);
193         Put_message("Containing the filesystems (in order):");
194         if ((stat = do_sms_query("get_fsgroup_members", 1, &info[FS_NAME],
195                                  StoreInfo, (char *)&elem)) != 0) {
196             if (stat == SMS_NO_MATCH)
197               Put_message("    [no members]");
198             else
199               com_err(program_name, stat, NULL);
200         } else {
201             fsgCount = 1;
202             Loop(QueueTop(elem), (void *) PrintFSGMembers);
203             FreeQueue(elem);
204         }
205     } else {
206         sprintf(print_buf,"Type: %-40s Machine: %-15s",
207                 info[FS_TYPE], info[FS_MACHINE]);
208         Put_message(print_buf);
209         sprintf(print_buf,"Default Access: %-2s Packname: %-17s Mountpoint %s ",
210                 info[FS_ACCESS], info[FS_PACK], info[FS_M_POINT]);
211         Put_message(print_buf);
212         sprintf(print_buf,"Comments; %s",info[FS_COMMENTS]);
213         Put_message(print_buf);
214         sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s",
215                 info[FS_OWNER], info[FS_OWNERS]);
216         Put_message(print_buf);
217         sprintf(print_buf, "Auto Create: %-34s Locker Type: %s",
218                 atoi(info[FS_CREATE]) ? "ON" : "OFF", 
219                 info[FS_L_TYPE]);
220         Put_message(print_buf);
221         sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME], 
222                 info[FS_MODWITH]);
223         Put_message(print_buf);
224     }
225     return(info[FS_NAME]);
226 }
227
228 /*      Function Name: AskFSInfo.
229  *      Description: This function askes the user for information about a 
230  *                   machine and saves it into a structure.
231  *      Arguments: info - a pointer the the structure to put the
232  *                             info into.
233  *                 name - add a newname field? (T/F)
234  *      Returns: none.
235  */
236
237 static char **
238 AskFSInfo(info, name)
239 char ** info;
240 Bool name;
241 {
242     char temp_buf[BUFSIZ], *newname;
243     int fsgroup = 0;
244
245     Put_message("");
246     sprintf(temp_buf, "Changing Attributes of filesystem %s.", 
247             info[FS_NAME]);
248     Put_message(temp_buf);
249     Put_message("");
250
251     if (name) {
252         newname = Strsave(info[FS_NAME]);
253         GetValueFromUser("The new name for this filesystem",
254                          &newname);
255     }
256
257     GetTypeFromUser("Filesystem's Type", "filesys", &info[FS_TYPE]);
258     if (!strcmp(info[FS_TYPE], "FSGROUP") || !strcmp(info[FS_TYPE], "fsgroup"))
259       fsgroup++;
260     if (fsgroup) {
261         free(info[FS_MACHINE]);
262         info[FS_MACHINE] = Strsave(NO_MACHINE);
263     } else {
264         GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]);
265         strcpy(temp_buf, CanonicalizeHostname(info[FS_MACHINE]));
266         free(info[FS_MACHINE]);
267         info[FS_MACHINE] = Strsave(temp_buf);
268     }
269     if (!fsgroup) {
270         GetValueFromUser("Filesystem's Pack Name", &info[FS_PACK]);
271         GetValueFromUser("Filesystem's Mount Point", &info[FS_M_POINT]);
272         GetValueFromUser("Filesystem's Default Access", &info[FS_ACCESS]);
273     }
274     GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS]);
275     GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]);
276     GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]);
277     if (!fsgroup)
278       GetYesNoValueFromUser("Automatically create this filesystem",
279                             &info[FS_CREATE]);
280     GetTypeFromUser("Filesystem's lockertype", "lockertype", &info[FS_L_TYPE]);
281
282     FreeAndClear(&info[FS_MODTIME], TRUE);
283     FreeAndClear(&info[FS_MODBY], TRUE);
284     FreeAndClear(&info[FS_MODWITH], TRUE);
285
286     if (name)                   /* slide the newname into the #2 slot. */
287         SlipInNewName(info, newname);
288
289     return(info);
290 }
291
292 /* --------------- Filesystem Menu ------------- */
293
294 /*      Function Name: GetFS
295  *      Description: Get Filesystem information by name.
296  *      Arguments: argc, argv - name of filsys in argv[1].
297  *      Returns: DM_NORMAL.
298  */
299
300 /* ARGSUSED */
301 int
302 GetFS(argc, argv)
303 int argc;
304 char **argv;
305 {
306     struct qelem *top;
307
308     top = GetFSInfo(LABEL, argv[1]); /* get info. */
309     Loop(top, (void *) PrintFSInfo);
310     FreeQueue(top);             /* clean the queue. */
311     return (DM_NORMAL);
312 }
313
314 /*      Function Name: RealDeleteFS
315  *      Description: Does the real deletion work.
316  *      Arguments: info - array of char *'s containing all useful info.
317  *                 one_item - a Boolean that is true if only one item 
318  *                              in queue that dumped us here.
319  *      Returns: none.
320  */
321
322 void
323 RealDeleteFS(info, one_item)
324 char ** info;
325 Bool one_item;
326 {
327     int stat;
328     char temp_buf[BUFSIZ];
329
330 /* 
331  * Deletetions are  performed if the user hits 'y' on a list of multiple 
332  * filesystem, or if the user confirms on a unique alias.
333  */
334     sprintf(temp_buf, "Are you sure that you want to delete filesystem %s",
335             info[FS_NAME]);
336     if(!one_item || Confirm(temp_buf)) {
337         if ( (stat = do_sms_query("delete_filesys", 1,
338                                   &info[FS_NAME], Scream, NULL)) != 0)
339             com_err(program_name, stat, " filesystem not deleted.");
340         else
341             Put_message("Filesystem deleted.");
342     }
343     else 
344         Put_message("Filesystem not deleted.");
345 }
346
347 /*      Function Name: DeleteFS
348  *      Description: Delete a filesystem give its name.
349  *      Arguments: argc, argv - argv[1] is the name of the filesystem.
350  *      Returns: none.
351  */
352
353 /* ARGSUSED */
354  
355 int
356 DeleteFS(argc, argv)
357 int argc;
358 char **argv;
359 {
360     struct qelem *elem = GetFSInfo(LABEL, argv[1]);
361     QueryLoop(elem, PrintFSInfo, RealDeleteFS, "Delete the Filesystem");
362
363     FreeQueue(elem);
364     return (DM_NORMAL);
365 }
366
367 /*      Function Name: RealChangeFS
368  *      Description: performs the actual change to the filesys.
369  *      Arguments: info - the information 
370  *                 junk - an unused boolean.
371  *      Returns: none.
372  */
373
374 /* ARGSUSED. */
375 static void
376 RealChangeFS(info, junk)
377 char ** info;
378 Bool junk;
379 {
380     int stat;
381     char ** args = AskFSInfo(info, TRUE);
382     extern Menu nfsphys_menu;
383
384     stat = do_sms_query("update_filesys", CountArgs(args), args,
385                         NullFunc, NULL);
386     switch (stat) {
387     case SMS_NFS:
388         Put_message("That NFS filesystem is not exported.");
389         if (YesNoQuestion("Fix this now (Y/N)")) {
390             Do_menu(&nfsphys_menu, 0, NULL);
391             if (YesNoQuestion("Retry filesystem update now (Y/N)")) {
392                 if (stat = do_sms_query("update_filesys", CountArgs(args), args,
393                                         NullFunc, NULL))
394                     com_err(program_name, stat, " filesystem not updated");
395                 else
396                     Put_message("filesystem sucessfully updated.");
397             }
398         }
399         break;
400     case SMS_SUCCESS:
401         break;
402     default:
403         com_err(program_name, stat, " in UpdateFS");
404     }
405 }
406
407 /*      Function Name: ChangeFS
408  *      Description: change the information in a filesys record.
409  *      Arguments: arc, argv - value of filsys in argv[1].
410  *      Returns: DM_NORMAL.
411  */
412
413 /* ARGSUSED */
414 int
415 ChangeFS(argc, argv)
416 char **argv;
417 int argc;
418 {
419     struct qelem *elem = GetFSInfo(LABEL, argv[1]);
420     QueryLoop(elem, NullPrint, RealChangeFS, "Update the Filesystem");
421
422     FreeQueue(elem);
423     return (DM_NORMAL);
424 }
425
426 /*      Function Name: AddFS
427  *      Description: change the information in a filesys record.
428  *      Arguments: arc, argv - name of filsys in argv[1].
429  *      Returns: DM_NORMAL.
430  */
431
432 /* ARGSUSED */
433 int
434 AddFS(argc, argv)
435 char **argv;
436 int argc;
437 {
438     char *info[MAX_ARGS_SIZE], **args;
439     int stat;
440     extern Menu nfsphys_menu;
441
442     if ( !ValidName(argv[1]) )
443         return(DM_NORMAL);
444
445     if ( (stat = do_sms_query("get_filesys_by_label", 1, argv + 1,
446                               NullFunc, NULL)) == 0) {
447         Put_message ("A Filesystem by that name already exists.");
448         return(DM_NORMAL);
449     } else if (stat != SMS_NO_MATCH) {
450         com_err(program_name, stat, " in AddFS");
451         return(DM_NORMAL);
452     } 
453
454     args = AskFSInfo(SetDefaults(info, argv[1]), FALSE );
455
456     stat = do_sms_query("add_filesys", CountArgs(args), args, NullFunc, NULL);
457     switch (stat) {
458     case SMS_NFS:
459         Put_message("That NFS filesystem is not exported.");
460         if (YesNoQuestion("Fix this now (Y/N)")) {
461             Do_menu(&nfsphys_menu, 0, NULL);
462             if (YesNoQuestion("Retry filesystem creation now (Y/N)")) {
463                 if (stat = do_sms_query("add_filesys", CountArgs(args), args,
464                                         NullFunc, NULL))
465                     com_err(program_name, stat, " in AddFS");
466                 else
467                     Put_message("Created.");
468             }
469         }
470         break;
471     case SMS_SUCCESS:
472         break;
473     default:
474         com_err(program_name, stat, " in AddFS");
475     }
476
477     FreeInfo(info);
478     return (DM_NORMAL);
479 }
480
481 /*      Function Name: SortAfter
482  *      Description: choose a sortkey to cause an item to be added after 
483  *              the count element in the queue
484  *      Arguments: queue of filesys names & sortkeys, queue count pointer
485  *      Returns: sort key to use.
486  */
487
488 /* ARGSUSED */
489 char *
490 SortAfter(elem, count)
491 struct qelem *elem;
492 int count;
493 {
494     char *prev, *next, prevnext, *key, keybuf[9];
495
496     /* first find the two keys we need to insert between */
497     prev = "A";
498     for (; count > 0; count--) {
499         prev = ((char **)elem->q_data)[1];
500         if (elem->q_forw)
501           elem = elem->q_forw;
502         else
503           break;
504     }
505     if (count > 0)
506       next = "Z";
507     else
508       next = ((char **)elem->q_data)[1];
509
510     /* now copy the matching characters */
511     for (key = keybuf; *prev && *prev == *next; next++) {
512         *key++ = *prev++;
513     }
514
515     /* and set the last character */
516     if (*prev == 0)
517       *prev = prevnext = 'A';
518     else
519       prevnext = prev[1];
520     if (prevnext == 0)
521       prevnext = 'A';
522     if (*next == 0)
523       *next = 'Z';
524     if (*next - *prev > 1) {
525         *key++ = (*next + *prev)/2;
526     } else {
527         *key++ = *prev;
528         *key++ = (prevnext + 'Z')/2;
529     }
530     *key = 0;
531     return(Strsave(keybuf));
532 }
533
534 /*      Function Name: AddFSToGroup
535  *      Description: add a filesystem to an FS group
536  *      Arguments: arc, argv - name of group in argv[1], filesys in argv[2].
537  *      Returns: DM_NORMAL.
538  */
539
540 /* ARGSUSED */
541 int
542 AddFSToGroup(argc, argv)
543 char **argv;
544 int argc;
545 {
546     int stat, count;
547     struct qelem *elem = NULL;
548     char buf[BUFSIZ], *args[5], *bufp;
549
550     if ((stat = do_sms_query("get_fsgroup_members", 1, argv+1, StoreInfo,
551                              (char *)&elem)) != 0) {
552         if (stat != SMS_NO_MATCH)
553           com_err(program_name, stat, " in AddFSToGroup");
554     }
555     if (elem == NULL) {
556         args[0] = argv[1];
557         args[1] = argv[2];
558         args[2] = "M";
559         stat = do_sms_query("add_filesys_to_fsgroup", 3, args, Scream, NULL);
560         if (stat)
561           com_err(program_name, stat, " in AddFSToGroup");
562         return(DM_NORMAL);
563     }
564     elem = QueueTop(elem);
565     fsgCount = 1;
566     Loop(elem, (void *) PrintFSGMembers);
567     sprintf(buf, "%d", QueueCount(elem));
568     bufp = Strsave(buf);
569     stat = GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp);
570     count = atoi(bufp);
571     free(bufp);
572     args[2] = SortAfter(elem, count);
573
574     FreeQueue(QueueTop(elem));
575     args[0] = argv[1];
576     args[1] = argv[2];
577     stat = do_sms_query("add_filesys_to_fsgroup", 3, args, Scream, NULL);
578     if (stat == SMS_EXISTS) {
579         Put_message("That filesystem is already a member of the group.");
580         Put_message("Use the order command if you want to change the sorting order.");
581     } else if (stat)
582       com_err(program_name, stat, " in AddFSToGroup");
583     return(DM_NORMAL);
584 }
585
586
587 /*      Function Name: RemoveFSFromGroup
588  *      Description: delete a filesystem from an FS group
589  *      Arguments: arc, argv - name of group in argv[1].
590  *      Returns: DM_NORMAL.
591  */
592
593 /* ARGSUSED */
594 int
595 RemoveFSFromGroup(argc, argv)
596 char **argv;
597 int argc;
598 {
599     int stat;
600     char buf[BUFSIZ];
601
602     sprintf(buf, "Delete filesystem %s from FS group %s", argv[2], argv[1]);
603     if (!Confirm(buf))
604       return(DM_NORMAL);
605     if ((stat = do_sms_query("remove_filesys_from_fsgroup", 2, argv+1,
606                              Scream, NULL)) != 0) {
607         com_err(program_name, stat, ", not removed.");
608     }
609     return(DM_NORMAL);
610 }
611
612 /*      Function Name: ChangeFSGroupOrder
613  *      Description: change the sortkey on a filesys in an FSgroup
614  *      Arguments: arc, argv - name of group in argv[1].
615  *      Returns: DM_NORMAL.
616  */
617
618 /* ARGSUSED */
619 int
620 ChangeFSGroupOrder(argc, argv)
621 char **argv;
622 int argc;
623 {
624     int stat, src, dst;
625     struct qelem *elem = NULL, *top;
626     char buf[BUFSIZ], *bufp, *args[3];
627
628     if ((stat = do_sms_query("get_fsgroup_members", 1, argv+1, StoreInfo,
629                              (char *)&elem)) != 0) {
630         if (stat == SMS_NO_MATCH) {
631             sprintf(buf, "Ether %s is not a filesystem group or it has no members", argv[1]);
632             Put_message(buf);
633         } else
634           com_err(program_name, stat, " in ChangeFSGroupOrder");
635         return(DM_NORMAL);
636     }
637     top = QueueTop(elem);
638     fsgCount = 1;
639     Loop(top, (void *) PrintFSGMembers);
640     while (1) {
641         bufp = Strsave("1");
642         stat = GetValueFromUser("Enter number of the filesystem to move:",
643                                 &bufp);
644         src = atoi(bufp);
645         free(bufp);
646         if (src < 0) {
647             Put_message("You must enter a positive number (or 0 to abort).");
648             continue;
649         } else if (src == 0) {
650             Put_message("Aborted.");
651             return(DM_NORMAL);
652         }
653         for (elem = top; src-- > 1 && elem->q_forw; elem = elem->q_forw);
654         if (src > 1) {
655             Put_message("You entered a number that is too high");
656             continue;
657         }
658         break;
659     }
660     bufp = Strsave("0");
661     stat = GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp);
662     dst = atoi(bufp);
663     free(bufp);
664     if (src == dst || src == dst + 1) {
665         Put_message("That has no effect on the sorting order!");
666         return(DM_NORMAL);
667     }
668     args[2] = SortAfter(top, dst);
669     args[0] = argv[1];
670     args[1] = ((char **)elem->q_data)[0];
671     if ((stat = do_sms_query("remove_filesys_from_fsgroup", 2, args,
672                              Scream, NULL)) != 0) {
673         com_err(program_name, stat, " in ChangeFSGroupOrder");
674         return(DM_NORMAL);
675     }
676     if ((stat = do_sms_query("add_filesys_to_fsgroup", 3, args,
677                              Scream, NULL)) != 0) {
678         com_err(program_name, stat, " in ChangeFSGroupOrder");
679     }
680     return(DM_NORMAL);
681 }
682
683
684 /* -------------- Top Level Menu ---------------- */
685
686 /*      Function Name: GetFSAlias
687  *      Description: Gets the value for a Filesystem Alias.
688  *      Arguments: argc, argv - name of alias in argv[1].
689  *      Returns: DM_NORMAL.
690  *      NOTES: There should only be one filesystem per alias, thus
691  *             this will work correctly.
692  */
693
694 /* ARGSUSED */
695 int
696 GetFSAlias(argc, argv)
697 int argc;
698 char **argv;
699 {
700     struct qelem *top;
701
702     top = GetFSInfo(ALIAS, argv[1]);
703     Put_message(" ");           /* blank line. */
704     Loop(top, (void *) PrintFSAlias);
705     FreeQueue(top);
706     return(DM_NORMAL);
707 }
708
709 /*      Function Name: CreateFSAlias
710  *      Description: Create an alias name for a filesystem
711  *      Arguments: argc, argv - name of alias in argv[1].
712  *      Returns: DM_NORMAL.
713  *      NOTES:  This requires (name, type, transl)  I get {name, translation}
714  *              from the user.  I provide type, which is well-known. 
715  */
716
717 /* ARGSUSED */
718 int
719 CreateFSAlias(argc, argv)
720 int argc;
721 char **argv;
722 {
723     register int stat;
724     struct qelem *elem, *top;
725     char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info;
726
727     elem = NULL;
728
729     if (!ValidName(argv[1]))
730         return(DM_NORMAL);
731
732     args[ALIAS_NAME] = Strsave(argv[1]);
733     args[ALIAS_TYPE] = Strsave(FS_ALIAS_TYPE);
734     args[ALIAS_TRANS] = Strsave("*");
735
736 /*
737  * Check to see if this alias already exists in the database, if so then
738  * print out values, free memory used and then exit.
739  */
740
741     if ( (stat = do_sms_query("get_alias", 3, args, StoreInfo, 
742                               (char *)&elem)) == 0) {
743         top = elem = QueueTop(elem);
744         while (elem != NULL) {
745             info = (char **) elem->q_data;          
746             sprintf(buf,"The alias: %s currently describes the filesystem %s",
747                     info[ALIAS_NAME], info[ALIAS_TRANS]);
748             Put_message(buf);
749             elem = elem->q_forw;
750         }
751         FreeQueue(top);
752         return(DM_NORMAL);
753     }
754     else if ( stat != SMS_NO_MATCH) {
755         com_err(program_name, stat, " in CreateFSAlias.");
756         return(DM_NORMAL);
757     }
758
759     args[ALIAS_TRANS]= args[ALIAS_END] = NULL;  /* set to NULL initially. */
760     GetValueFromUser("Which filesystem will this alias point to?",
761                      &args[ALIAS_TRANS]);
762
763     if ( (stat = do_sms_query("add_alias", 3, args, NullFunc, NULL)) != 0)
764         com_err(program_name, stat, " in CreateFSAlias.");
765
766     FreeInfo(args);
767     return (DM_NORMAL);
768 }
769     
770 /*      Function Name: RealDeleteFSAlias
771  *      Description: Does the real deletion work.
772  *      Arguments: info - array of char *'s containing all useful info.
773  *                 one_item - a Boolean that is true if only one item 
774  *                              in queue that dumped us here.
775  *      Returns: none.
776  */
777
778 void
779 RealDeleteFSAlias(info, one_item)
780 char ** info;
781 Bool one_item;
782 {
783     int stat;
784     char temp_buf[BUFSIZ];
785
786 /* 
787  * Deletetions are  performed if the user hits 'y' on a list of multiple 
788  * filesystem, or if the user confirms on a unique alias.
789  */
790     sprintf(temp_buf, 
791             "Are you sure that you want to delete the filesystem alias %s",
792             info[ALIAS_NAME]);
793     if(!one_item || Confirm(temp_buf)) {
794         if ( (stat = do_sms_query("delete_alias", CountArgs(info),
795                                   info, Scream, NULL)) != 0 )
796             com_err(program_name, stat, " filesystem alias not deleted.");
797         else
798             Put_message("Filesystem alias deleted.");
799     }
800     else 
801         Put_message("Filesystem alias not deleted.");
802 }
803
804 /*      Function Name: DeleteFSAlias
805  *      Description: Delete an alias name for a filesystem
806  *      Arguments: argc, argv - name of alias in argv[1].
807  *      Returns: DM_NORMAL.
808  *      NOTES:  This requires (name, type, transl)  I get {name, translation}
809  *              from the user.  I provide type, which is well-known. 
810  */
811
812 /* ARGSUSED */
813 int
814 DeleteFSAlias(argc, argv)
815 int argc;
816 char **argv;
817 {
818     struct qelem *elem = GetFSInfo(ALIAS, argv[1]);
819     QueryLoop(elem, PrintFSAlias, RealDeleteFSAlias,
820               "Delete the Filesystem Alias");
821     FreeQueue(elem);
822     return (DM_NORMAL);
823 }
824
825 /*      Function Name: AttachHelp
826  *      Description: Print help info on attachmaint.
827  *      Arguments: none
828  *      Returns: DM_NORMAL.
829  */
830
831 int
832 AttachHelp()
833 {
834     static char *message[] = {
835       "These are the options:",
836       "",
837       "get - get information about a filesystem.",
838       "add - add a new filesystem to the data base.",
839       "update - update the information in the database on a filesystem.",
840       "delete - delete a filesystem from the database.",
841       "check - check information about association of a name and a filesys.",
842       "alias - associate a name with a filesystem.",
843       "unalias - disassociate a name with a filesystem.",
844       "verbose - toggle the request for delete confirmation.",
845         NULL,
846     };
847
848     return(PrintHelp(message));
849 }
850
851 /*      Function Name: FSGroupHelp
852  *      Description: Print help info on fsgroups.
853  *      Arguments: none
854  *      Returns: DM_NORMAL.
855  */
856
857 int
858 FSGroupHelp()
859 {
860     static char *message[] = {
861         "A filesystem group is a named sorted list of filesystems.",
862         "",
863         "To create, modify, or delete a group itself, use the menu above",
864         "  this one, and manipulate a filesystem of type FSGROUP.",
865         "Options here are:",
866         "  get - get info about a group and show its members",
867         "  add - add a new member to a group.",
868         "  remove - remove a member from a group.",
869         "  order - change the sorting order of a group.",
870         NULL
871     };
872
873     return(PrintHelp(message));
874 }
This page took 0.096244 seconds and 3 git commands to generate.