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