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