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