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