]> andersk Git - moira.git/blame_incremental - clients/moira/attach.c
handle non-lower case letters in AFS redirection differently
[moira.git] / clients / moira / attach.c
... / ...
CommitLineData
1#if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
3#endif
4
5/* This is the file attach.c for the MOIRA Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the MOIRA database.
7 * It Contains: Functions for maintaining data used by Hesiod
8 * to map courses/projects/users to their file systems,
9 * and maintain filesys info.
10 *
11 * Created: 5/4/88
12 * By: Chris D. Peterson
13 *
14 * $Source$
15 * $Author$
16 * $Header$
17 *
18 * Copyright 1988 by the Massachusetts Institute of Technology.
19 *
20 * For further information on copyright and distribution
21 * see the file mit-copyright.h
22 */
23
24#include <stdio.h>
25#include <strings.h>
26#include <moira.h>
27#include <moira_site.h>
28#include <menu.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <ctype.h>
32
33#include "mit-copyright.h"
34#include "defs.h"
35#include "f_defs.h"
36#include "globals.h"
37
38#define FS_ALIAS_TYPE "FILESYS"
39
40#define LABEL 0
41#define MACHINE 1
42#define GROUP 2
43#define ALIAS 3
44
45#define NO_MACHINE ("\\[NONE\\]") /* C will remove one of the /'s here,
46 * and the other quotes the [ for
47 * ingres' regexp facility. */
48#define NO_MACHINE_BAD ("[NONE]")
49
50#define DEFAULT_TYPE ("NFS")
51#define DEFAULT_MACHINE DEFAULT_NONE
52#define DEFAULT_PACK DEFAULT_NONE
53#define DEFAULT_ACCESS ("w")
54#define DEFAULT_COMMENTS DEFAULT_COMMENT
55#define DEFAULT_OWNER (user)
56#define DEFAULT_OWNERS (user)
57#define DEFAULT_CREATE DEFAULT_YES
58#define DEFAULT_L_TYPE ("PROJECT")
59#define DEFAULT_CELL ("athena.mit.edu")
60
61/* Function Name: SetDefaults
62 * Description: sets the default values for filesystem additions.
63 * Arguments: info - an array of char pointers to recieve defaults.
64 * Returns: char ** (this array, now filled).
65 */
66
67static char **
68SetDefaults(info, name)
69char ** info;
70char * name;
71{
72 char buf[BUFSIZ];
73
74 info[FS_NAME] = Strsave(name);
75 info[FS_TYPE] = Strsave(DEFAULT_TYPE);
76 info[FS_MACHINE] = Strsave(DEFAULT_MACHINE);
77 info[FS_PACK] = Strsave(DEFAULT_PACK);
78 sprintf(buf, "/mit/%s", name);
79 info[FS_M_POINT] = Strsave(buf);
80 info[FS_ACCESS] = Strsave(DEFAULT_ACCESS);
81 info[FS_COMMENTS] = Strsave(DEFAULT_COMMENTS);
82 info[FS_OWNER] = Strsave(DEFAULT_OWNER);
83 info[FS_OWNERS] = Strsave(DEFAULT_OWNERS);
84 info[FS_CREATE] = Strsave(DEFAULT_CREATE);
85 info[FS_L_TYPE] = Strsave(DEFAULT_L_TYPE);
86 info[FS_MODTIME] = info[FS_MODBY] = info[FS_MODWITH] = info[FS_END] = NULL;
87 return(info);
88}
89
90/* Function Name: GetFSInfo
91 * Description: Stores the info in a queue.
92 * Arguments: type - type of information to get.
93 * name - name of the item to get information on.
94 * Returns: a pointer to the first element in the queue.
95 */
96
97static struct qelem *
98GetFSInfo(type, name)
99int type;
100char *name;
101{
102 int stat;
103 struct qelem * elem = NULL;
104 char * args[5];
105
106 switch (type) {
107 case LABEL:
108 if ( (stat = do_mr_query("get_filesys_by_label", 1, &name,
109 StoreInfo, (char *)&elem)) != 0) {
110 com_err(program_name, stat, " in GetFSInfo");
111 return(NULL);
112 }
113 break;
114 case MACHINE:
115 if ( (stat = do_mr_query("get_filesys_by_machine", 1, &name,
116 StoreInfo, (char *)&elem)) != 0) {
117 com_err(program_name, stat, " in GetFSInfo");
118 return(NULL);
119 }
120 break;
121 case GROUP:
122 if ( (stat = do_mr_query("get_filesys_by_group", 1, &name,
123 StoreInfo, (char *)&elem)) != 0) {
124 com_err(program_name, stat, " in GetFSInfo");
125 return(NULL);
126 }
127 break;
128 case ALIAS:
129 args[ALIAS_NAME] = name;
130 args[ALIAS_TYPE] = FS_ALIAS_TYPE;
131 args[ALIAS_TRANS] = "*";
132 if ( (stat = do_mr_query("get_alias", 3, args, StoreInfo,
133 (char *) &elem)) != 0) {
134 com_err(program_name, stat, " in get_alias.");
135 return(NULL);
136 }
137 }
138
139 return(QueueTop(elem));
140}
141
142/* Function Name: PrintFSAlias
143 * Description: Prints a filesystem alias
144 * Arguments: info - an array contains the strings of info.
145 * Returns: the name of the filesys - used be QueryLoop().
146 */
147
148static char *
149PrintFSAlias(info)
150char ** info;
151{
152 char buf[BUFSIZ];
153
154 sprintf(buf,"Alias: %-25s Filesystem: %s",info[ALIAS_NAME],
155 info[ALIAS_TRANS]);
156 Put_message(buf);
157 return(info[ALIAS_NAME]);
158}
159
160static int fsgCount = 1;
161
162static char *
163PrintFSGMembers(info)
164char ** info;
165{
166 char print_buf[BUFSIZ];
167
168 sprintf(print_buf, " %d. Filesystem: %-32s (sort key: %s)", fsgCount++, info[0], info[1]);
169 Put_message(print_buf);
170 return(info[0]);
171}
172
173
174/* Function Name: PrintFSInfo
175 * Description: Prints the filesystem information.
176 * Arguments: info - a pointer to the filesystem information.
177 * Returns: none.
178 */
179
180static char *
181PrintFSInfo(info)
182char ** info;
183{
184 char print_buf[BUFSIZ];
185
186 FORMFEED;
187
188 if (!strcmp(info[FS_TYPE], "FSGROUP") || !strcmp(info[FS_TYPE], "MUL")) {
189 int stat;
190 struct qelem *elem = NULL;
191
192 if (!strcmp(info[FS_TYPE], "MUL"))
193 sprintf(print_buf,"%20s Multiple Filesystem: %s", " ", info[FS_NAME]);
194 else
195 sprintf(print_buf,"%20s Filesystem Group: %s", " ", info[FS_NAME]);
196 Put_message(print_buf);
197
198 sprintf(print_buf,"Comments: %s",info[FS_COMMENTS]);
199 Put_message(print_buf);
200 sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME],
201 info[FS_MODWITH]);
202 Put_message(print_buf);
203 Put_message("Containing the filesystems (in order):");
204 if ((stat = do_mr_query("get_fsgroup_members", 1, &info[FS_NAME],
205 StoreInfo, (char *)&elem)) != 0) {
206 if (stat == MR_NO_MATCH)
207 Put_message(" [no members]");
208 else
209 com_err(program_name, stat, " in PrintFSInfo");
210 } else {
211 fsgCount = 1;
212 Loop(QueueTop(elem), (void *) PrintFSGMembers);
213 FreeQueue(elem);
214 }
215 } else {
216 sprintf(print_buf,"%20s Filesystem: %s", " ", info[FS_NAME]);
217 Put_message(print_buf);
218 sprintf(print_buf,"Type: %-40s Machine: %-15s",
219 info[FS_TYPE], info[FS_MACHINE]);
220 Put_message(print_buf);
221 sprintf(print_buf,"Default Access: %-2s Packname: %-17s Mountpoint %s ",
222 info[FS_ACCESS], info[FS_PACK], info[FS_M_POINT]);
223 Put_message(print_buf);
224 sprintf(print_buf,"Comments: %s",info[FS_COMMENTS]);
225 Put_message(print_buf);
226 sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s",
227 info[FS_OWNER], info[FS_OWNERS]);
228 Put_message(print_buf);
229 sprintf(print_buf, "Auto Create: %-34s Locker Type: %s",
230 atoi(info[FS_CREATE]) ? "ON" : "OFF",
231 info[FS_L_TYPE]);
232 Put_message(print_buf);
233 sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME],
234 info[FS_MODWITH]);
235 Put_message(print_buf);
236 }
237 return(info[FS_NAME]);
238}
239
240
241char *canonicalize_cell(c)
242char *c;
243{
244 struct stat stbuf;
245 char path[512];
246 int count;
247
248 sprintf(path, "/afs/%s", c);
249 if (lstat(path, &stbuf) || !stbuf.st_mode&S_IFLNK)
250 return(c);
251 count = readlink(path, path, sizeof(path));
252 if (count < 1) return(c);
253 path[count] = 0;
254 free(c);
255 return(strsave(path));
256}
257
258
259int GetAliasValue(argc, argv, retval)
260int argc;
261char **argv;
262char **retval;
263{
264 *retval = strsave(argv[2]);
265 return(MR_CONT);
266}
267
268/* Function Name: AskFSInfo.
269 * Description: This function askes the user for information about a
270 * machine and saves it into a structure.
271 * Arguments: info - a pointer the the structure to put the
272 * info into.
273 * name - add a newname field? (T/F)
274 * Returns: none.
275 */
276
277static char **
278AskFSInfo(info, name)
279char ** info;
280Bool name;
281{
282 char temp_buf[BUFSIZ], *newname, access_type[32];
283 int fsgroup = 0, newdefaults = 0;
284
285 Put_message("");
286 sprintf(temp_buf, "Changing Attributes of filesystem %s.",
287 info[FS_NAME]);
288 Put_message(temp_buf);
289 Put_message("");
290
291 if (name) {
292 newname = Strsave(info[FS_NAME]);
293 if (GetValueFromUser("The new name for this filesystem",
294 &newname) == SUB_ERROR)
295 return(NULL);
296 }
297
298 strcpy(temp_buf, info[FS_TYPE]);
299 if (GetTypeFromUser("Filesystem's Type", "filesys", &info[FS_TYPE]) ==
300 SUB_ERROR)
301 return(NULL);
302 if (!strcasecmp(info[FS_TYPE], "FSGROUP") ||
303 !strcasecmp(info[FS_TYPE], "MUL"))
304 fsgroup++;
305 if (strcasecmp(info[FS_TYPE], temp_buf))
306 newdefaults++;
307 if (fsgroup) {
308 free(info[FS_MACHINE]);
309 info[FS_MACHINE] = Strsave(NO_MACHINE);
310 } else {
311 if (!strcmp(info[FS_MACHINE], NO_MACHINE_BAD)) {
312 free(info[FS_MACHINE]);
313 info[FS_MACHINE] = Strsave(NO_MACHINE);
314 }
315 if (!strcasecmp(info[FS_TYPE], "AFS")) {
316 if (!name || newdefaults) {
317 free(info[FS_MACHINE]);
318 info[FS_MACHINE] = strsave(DEFAULT_CELL);
319 }
320 if (GetValueFromUser("Filesystem's Cell", &info[FS_MACHINE]) ==
321 SUB_ERROR)
322 return(NULL);
323 info[FS_MACHINE] = canonicalize_cell(info[FS_MACHINE]);
324 } else {
325 if (GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]) ==
326 SUB_ERROR)
327 return(NULL);
328 info[FS_MACHINE] = canonicalize_hostname(info[FS_MACHINE]);
329 }
330 }
331 if (!fsgroup) {
332 if (!strcasecmp(info[FS_TYPE], "AFS")) {
333 char *path, *args[3], *p;
334 int status, depth, i;
335 if (GetTypeFromUser("Filesystem's lockertype", "lockertype",
336 &info[FS_L_TYPE]) == SUB_ERROR)
337 return(NULL);
338 if (!name || newdefaults) {
339 free(info[FS_PACK]);
340 lowercase(info[FS_MACHINE]);
341 sprintf(temp_buf, "%s:%s", info[FS_MACHINE], info[FS_L_TYPE]);
342 args[0] = temp_buf;
343 args[1] = "AFSPATH";
344 args[2] = "*";
345 path = "???";
346 status = do_mr_query("get_alias", 3, args,
347 GetAliasValue, &path);
348 if (status == MR_SUCCESS) {
349 p = index(path, ':');
350 if (p) {
351 *p = 0;
352 depth = atoi(++p);
353 } else
354 depth = 0;
355 sprintf(temp_buf, "/afs/%s/%s", info[FS_MACHINE], path);
356 if (depth >= 0) {
357 for (p=info[FS_NAME]; *p&&(p-info[FS_NAME])<depth; p++) {
358 if (islower(*p)) {
359 strcat(temp_buf, "/x");
360 temp_buf[strlen(temp_buf)-1] = *p;
361 } else {
362 sprintf(temp_buf, "/afs/%s/%s/other", info[FS_MACHINE], path);
363 break;
364 }
365 }
366 } else if (depth = -1) {
367 if (isdigit(info[FS_NAME][0])) {
368 strcat(temp_buf, "/");
369 depth = strlen(temp_buf);
370 for (p = info[FS_NAME]; *p && isdigit(*p); p++) {
371 temp_buf[depth++] = *p;
372 temp_buf[depth] = 0;
373 }
374 } else
375 strcat(temp_buf, "/other");
376 } else {
377 /* no default */
378 }
379 strcat(temp_buf, "/");
380 strcat(temp_buf, info[FS_NAME]);
381 free(path);
382 } else {
383 sprintf(temp_buf, "/afs/%s/%s/%s", info[FS_MACHINE],
384 lowercase(info[FS_L_TYPE]), info[FS_NAME]);
385 }
386 info[FS_PACK] = strsave(temp_buf);
387 }
388 }
389 if (GetValueFromUser("Filesystem's Pack Name", &info[FS_PACK]) ==
390 SUB_ERROR)
391 return(NULL);
392 if (GetValueFromUser("Filesystem's Mount Point", &info[FS_M_POINT]) ==
393 SUB_ERROR)
394 return(NULL);
395 sprintf(access_type, "fs_access_%s", info[FS_TYPE]);
396 if (GetTypeFromUser("Filesystem's Default Access", access_type,
397 &info[FS_ACCESS]) == SUB_ERROR)
398 return(NULL);
399 }
400 if (GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS])
401 == SUB_ERROR)
402 return(NULL);
403 if (GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]) ==
404 SUB_ERROR)
405 return(NULL);
406 if (GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]) ==
407 SUB_ERROR)
408 return(NULL);
409 if (!fsgroup)
410 if (GetYesNoValueFromUser("Automatically create this filesystem",
411 &info[FS_CREATE]) == SUB_ERROR)
412 return(NULL);
413 if (strcasecmp(info[FS_TYPE], "AFS")) {
414 if (GetTypeFromUser("Filesystem's lockertype", "lockertype",
415 &info[FS_L_TYPE]) == SUB_ERROR)
416 return(NULL);
417 }
418
419 FreeAndClear(&info[FS_MODTIME], TRUE);
420 FreeAndClear(&info[FS_MODBY], TRUE);
421 FreeAndClear(&info[FS_MODWITH], TRUE);
422
423 if (name) /* slide the newname into the #2 slot. */
424 SlipInNewName(info, newname);
425
426 return(info);
427}
428
429
430/* --------------- Filesystem Menu ------------- */
431
432/* Function Name: GetFS
433 * Description: Get Filesystem information by name.
434 * Arguments: argc, argv - name of filsys in argv[1].
435 * Returns: DM_NORMAL.
436 */
437
438/* ARGSUSED */
439int
440GetFS(argc, argv)
441int argc;
442char **argv;
443{
444 struct qelem *top;
445
446 top = GetFSInfo(LABEL, argv[1]); /* get info. */
447 Loop(top, (void *) PrintFSInfo);
448 FreeQueue(top); /* clean the queue. */
449 return (DM_NORMAL);
450}
451
452/* Function Name: GetFSM
453 * Description: Get Filesystem information by machine.
454 * Arguments: argc, argv - name of server in argv[1].
455 * Returns: DM_NORMAL.
456 */
457
458/* ARGSUSED */
459int
460GetFSM(argc, argv)
461int argc;
462char **argv;
463{
464 struct qelem *top;
465
466 argv[1] = canonicalize_hostname(strsave(argv[1]));
467 top = GetFSInfo(MACHINE, argv[1]); /* get info. */
468 Loop(top, (void *) PrintFSInfo);
469 FreeQueue(top); /* clean the queue. */
470 return (DM_NORMAL);
471}
472
473/* Function Name: RealDeleteFS
474 * Description: Does the real deletion work.
475 * Arguments: info - array of char *'s containing all useful info.
476 * one_item - a Boolean that is true if only one item
477 * in queue that dumped us here.
478 * Returns: none.
479 */
480
481void
482RealDeleteFS(info, one_item)
483char ** info;
484Bool one_item;
485{
486 int stat;
487 char temp_buf[BUFSIZ];
488
489/*
490 * Deletetions are performed if the user hits 'y' on a list of multiple
491 * filesystem, or if the user confirms on a unique alias.
492 */
493 sprintf(temp_buf, "Are you sure that you want to delete filesystem %s",
494 info[FS_NAME]);
495 if(!one_item || Confirm(temp_buf)) {
496 if ( (stat = do_mr_query("delete_filesys", 1,
497 &info[FS_NAME], Scream, NULL)) != 0)
498 com_err(program_name, stat, " filesystem not deleted.");
499 else
500 Put_message("Filesystem deleted.");
501 }
502 else
503 Put_message("Filesystem not deleted.");
504}
505
506/* Function Name: DeleteFS
507 * Description: Delete a filesystem give its name.
508 * Arguments: argc, argv - argv[1] is the name of the filesystem.
509 * Returns: none.
510 */
511
512/* ARGSUSED */
513
514int
515DeleteFS(argc, argv)
516int argc;
517char **argv;
518{
519 struct qelem *elem = GetFSInfo(LABEL, argv[1]);
520 QueryLoop(elem, PrintFSInfo, RealDeleteFS, "Delete the Filesystem");
521
522 FreeQueue(elem);
523 return (DM_NORMAL);
524}
525
526/* Function Name: RealChangeFS
527 * Description: performs the actual change to the filesys.
528 * Arguments: info - the information
529 * junk - an unused boolean.
530 * Returns: none.
531 */
532
533/* ARGSUSED. */
534static void
535RealChangeFS(info, junk)
536char ** info;
537Bool junk;
538{
539 int stat;
540 char ** args;
541 extern Menu nfsphys_menu;
542
543 args = AskFSInfo(info, TRUE);
544 if (args == NULL) {
545 Put_message("Aborted.");
546 return;
547 }
548 stat = do_mr_query("update_filesys", CountArgs(args), args,
549 NullFunc, NULL);
550 switch (stat) {
551 case MR_NFS:
552 Put_message("That NFS filesystem is not exported.");
553 if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE) {
554 Do_menu(&nfsphys_menu, 0, NULL);
555 if (YesNoQuestion("Retry filesystem update now (Y/N)", TRUE)
556 == TRUE) {
557 if (stat = do_mr_query("update_filesys", CountArgs(args), args,
558 NullFunc, NULL))
559 com_err(program_name, stat, " filesystem not updated");
560 else
561 Put_message("filesystem sucessfully updated.");
562 }
563 }
564 break;
565 case MR_SUCCESS:
566 break;
567 default:
568 com_err(program_name, stat, " in UpdateFS");
569 }
570}
571
572/* Function Name: ChangeFS
573 * Description: change the information in a filesys record.
574 * Arguments: arc, argv - value of filsys in argv[1].
575 * Returns: DM_NORMAL.
576 */
577
578/* ARGSUSED */
579int
580ChangeFS(argc, argv)
581char **argv;
582int argc;
583{
584 struct qelem *elem = GetFSInfo(LABEL, argv[1]);
585 QueryLoop(elem, NullPrint, RealChangeFS, "Update the Filesystem");
586
587 FreeQueue(elem);
588 return (DM_NORMAL);
589}
590
591/* Function Name: AddFS
592 * Description: change the information in a filesys record.
593 * Arguments: arc, argv - name of filsys in argv[1].
594 * Returns: DM_NORMAL.
595 */
596
597/* ARGSUSED */
598int
599AddFS(argc, argv)
600char **argv;
601int argc;
602{
603 char *info[MAX_ARGS_SIZE], **args, buf[BUFSIZ];
604 int stat;
605 extern Menu nfsphys_menu;
606
607 if ( !ValidName(argv[1]) )
608 return(DM_NORMAL);
609
610 if ( (stat = do_mr_query("get_filesys_by_label", 1, argv + 1,
611 NullFunc, NULL)) == 0) {
612 Put_message ("A Filesystem by that name already exists.");
613 return(DM_NORMAL);
614 } else if (stat != MR_NO_MATCH) {
615 com_err(program_name, stat, " in AddFS");
616 return(DM_NORMAL);
617 }
618
619 if ((args = AskFSInfo(SetDefaults(info, argv[1]), FALSE )) == NULL) {
620 Put_message("Aborted.");
621 return(DM_NORMAL);
622 }
623
624 stat = do_mr_query("add_filesys", CountArgs(args), args, NullFunc, NULL);
625 switch (stat) {
626 case MR_NFS:
627 Put_message("That NFS filesystem is not exported.");
628 if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE) {
629 Do_menu(&nfsphys_menu, 0, NULL);
630 if (YesNoQuestion("Retry filesystem creation now (Y/N)", TRUE)
631 == TRUE) {
632 if (stat = do_mr_query("add_filesys", CountArgs(args), args,
633 NullFunc, NULL))
634 com_err(program_name, stat, " in AddFS");
635 else
636 Put_message("Created.");
637 }
638 }
639 break;
640 case MR_SUCCESS:
641 break;
642 default:
643 com_err(program_name, stat, " in AddFS");
644 }
645
646 if (stat == MR_SUCCESS && !strcasecmp(info[FS_L_TYPE], "HOMEDIR")) {
647 static char *val[] = {"def_quota", NULL};
648 static char *def_quota = NULL;
649 char *argv[Q_QUOTA + 1];
650 struct qelem *top = NULL;
651
652 if (def_quota == NULL) {
653 stat = do_mr_query("get_value", CountArgs(val), val,
654 StoreInfo, (char *) &top);
655 if (stat != MR_SUCCESS) {
656 com_err(program_name, stat, " getting default quota");
657 } else {
658 top = QueueTop(top);
659 def_quota = Strsave(((char **)top->q_data)[0]);
660 FreeQueue(top);
661 }
662 }
663 if (def_quota != NULL) {
664 sprintf(buf, "Give user %s a quota of %s on filesys %s (Y/N)",
665 info[FS_NAME], def_quota, info[FS_NAME]);
666 if (YesNoQuestion(buf, 1) == TRUE) {
667 argv[Q_NAME] = argv[Q_FILESYS] = info[FS_NAME];
668 if (!strcmp(info[FS_TYPE], "NFS"))
669 argv[Q_TYPE] = "USER";
670 else
671 argv[Q_TYPE] = "ANY";
672 argv[Q_QUOTA] = def_quota;
673 if ((stat = do_mr_query("add_quota", Q_QUOTA+1, argv, Scream,
674 (char *) NULL)) != MR_SUCCESS) {
675 com_err(program_name, stat, " while adding quota");
676 }
677 }
678 }
679 } else if (stat == MR_SUCCESS) {
680 if (YesNoQuestion("Assign a quota on this filesystem (Y/N)", 1)
681 == TRUE) {
682 parsed_argc = 1;
683 parsed_argv[0] = info[FS_NAME];
684 AddQuota();
685 }
686 }
687
688 FreeInfo(info);
689 return (DM_NORMAL);
690}
691
692/* Function Name: SortAfter
693 * Description: choose a sortkey to cause an item to be added after
694 * the count element in the queue
695 * Arguments: queue of filesys names & sortkeys, queue count pointer
696 * Returns: sort key to use.
697 */
698
699/* ARGSUSED */
700char *
701SortAfter(elem, count)
702struct qelem *elem;
703int count;
704{
705 char *prev, *next, prevnext, *key, keybuf[9];
706
707 /* first find the two keys we need to insert between */
708 prev = "A";
709 for (; count > 0; count--) {
710 prev = ((char **)elem->q_data)[1];
711 if (elem->q_forw)
712 elem = elem->q_forw;
713 else
714 break;
715 }
716 if (count > 0)
717 next = "Z";
718 else
719 next = ((char **)elem->q_data)[1];
720
721 /* now copy the matching characters */
722 for (key = keybuf; *prev && *prev == *next; next++) {
723 *key++ = *prev++;
724 }
725
726 /* and set the last character */
727 if (*prev == 0)
728 *prev = prevnext = 'A';
729 else
730 prevnext = prev[1];
731 if (prevnext == 0)
732 prevnext = 'A';
733 if (*next == 0)
734 *next = 'Z';
735 if (*next - *prev > 1) {
736 *key++ = (*next + *prev)/2;
737 } else {
738 *key++ = *prev;
739 *key++ = (prevnext + 'Z')/2;
740 }
741 *key = 0;
742 return(Strsave(keybuf));
743}
744
745/* Function Name: AddFSToGroup
746 * Description: add a filesystem to an FS group
747 * Arguments: arc, argv - name of group in argv[1], filesys in argv[2].
748 * Returns: DM_NORMAL.
749 */
750
751/* ARGSUSED */
752int
753AddFSToGroup(argc, argv)
754char **argv;
755int argc;
756{
757 int stat, count;
758 struct qelem *elem = NULL;
759 char buf[BUFSIZ], *args[5], *bufp;
760
761 if ((stat = do_mr_query("get_fsgroup_members", 1, argv+1, StoreInfo,
762 (char *)&elem)) != 0) {
763 if (stat != MR_NO_MATCH)
764 com_err(program_name, stat, " in AddFSToGroup");
765 }
766 if (elem == NULL) {
767 args[0] = argv[1];
768 args[1] = argv[2];
769 args[2] = "M";
770 stat = do_mr_query("add_filesys_to_fsgroup", 3, args, Scream, NULL);
771 if (stat)
772 com_err(program_name, stat, " in AddFSToGroup");
773 return(DM_NORMAL);
774 }
775 elem = QueueTop(elem);
776 fsgCount = 1;
777 Loop(elem, (void *) PrintFSGMembers);
778 sprintf(buf, "%d", QueueCount(elem));
779 bufp = Strsave(buf);
780 if (GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp) == SUB_ERROR)
781 return(DM_NORMAL);
782 count = atoi(bufp);
783 free(bufp);
784 args[2] = SortAfter(elem, count);
785
786 FreeQueue(QueueTop(elem));
787 args[0] = argv[1];
788 args[1] = argv[2];
789 stat = do_mr_query("add_filesys_to_fsgroup", 3, args, Scream, NULL);
790 if (stat == MR_EXISTS) {
791 Put_message("That filesystem is already a member of the group.");
792 Put_message("Use the order command if you want to change the sorting order.");
793 } else if (stat)
794 com_err(program_name, stat, " in AddFSToGroup");
795 return(DM_NORMAL);
796}
797
798
799/* Function Name: RemoveFSFromGroup
800 * Description: delete a filesystem from an FS group
801 * Arguments: arc, argv - name of group in argv[1].
802 * Returns: DM_NORMAL.
803 */
804
805/* ARGSUSED */
806int
807RemoveFSFromGroup(argc, argv)
808char **argv;
809int argc;
810{
811 int stat;
812 char buf[BUFSIZ];
813
814 sprintf(buf, "Delete filesystem %s from FS group %s", argv[2], argv[1]);
815 if (!Confirm(buf))
816 return(DM_NORMAL);
817 if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, argv+1,
818 Scream, NULL)) != 0) {
819 com_err(program_name, stat, ", not removed.");
820 }
821 return(DM_NORMAL);
822}
823
824/* Function Name: ChangeFSGroupOrder
825 * Description: change the sortkey on a filesys in an FSgroup
826 * Arguments: arc, argv - name of group in argv[1].
827 * Returns: DM_NORMAL.
828 */
829
830/* ARGSUSED */
831int
832ChangeFSGroupOrder(argc, argv)
833char **argv;
834int argc;
835{
836 int stat, src, dst, i;
837 struct qelem *elem = NULL, *top, *tmpelem;
838 char buf[BUFSIZ], *bufp, *args[3];
839
840 if ((stat = do_mr_query("get_fsgroup_members", 1, argv+1, StoreInfo,
841 (char *)&elem)) != 0) {
842 if (stat == MR_NO_MATCH) {
843 sprintf(buf,
844 "Ether %s is not a filesystem group or it has no members",
845 argv[1]);
846 Put_message(buf);
847 } else
848 com_err(program_name, stat, " in ChangeFSGroupOrder");
849 return(DM_NORMAL);
850 }
851 top = QueueTop(elem);
852 fsgCount = 1;
853 Loop(top, (void *) PrintFSGMembers);
854 while (1) {
855 bufp = Strsave("1");
856 if (GetValueFromUser("Enter number of the filesystem to move:",
857 &bufp) == SUB_ERROR)
858 return(DM_NORMAL);
859 src = atoi(bufp);
860 free(bufp);
861 if (src < 0) {
862 Put_message("You must enter a positive number (or 0 to abort).");
863 continue;
864 } else if (src == 0) {
865 Put_message("Aborted.");
866 return(DM_NORMAL);
867 }
868 for (elem = top, i = src; i-- > 1 && elem->q_forw; elem = elem->q_forw);
869 if (i > 0) {
870 Put_message("You entered a number that is too high");
871 continue;
872 }
873 break;
874 }
875 while (1) {
876 bufp = Strsave("0");
877 if (GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp) == SUB_ERROR)
878 return(DM_NORMAL);
879 dst = atoi(bufp);
880 free(bufp);
881 if (src == dst || src == dst + 1) {
882 Put_message("That has no effect on the sorting order!");
883 return(DM_NORMAL);
884 }
885 if (dst < 0) {
886 Put_message("You must enter a non-negative number.");
887 continue;
888 }
889 for (tmpelem = top, i = dst;
890 i-- > 1 && tmpelem->q_forw;
891 tmpelem = tmpelem->q_forw);
892 if (i > 0) {
893 Put_message("You entered a number that is too high");
894 continue;
895 }
896 break;
897 }
898 args[2] = SortAfter(top, dst);
899 args[0] = argv[1];
900 args[1] = ((char **)elem->q_data)[0];
901 if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, args,
902 Scream, NULL)) != 0) {
903 com_err(program_name, stat, " in ChangeFSGroupOrder");
904 return(DM_NORMAL);
905 }
906 if ((stat = do_mr_query("add_filesys_to_fsgroup", 3, args,
907 Scream, NULL)) != 0) {
908 com_err(program_name, stat, " in ChangeFSGroupOrder");
909 }
910 return(DM_NORMAL);
911}
912
913
914/* -------------- Top Level Menu ---------------- */
915
916/* Function Name: GetFSAlias
917 * Description: Gets the value for a Filesystem Alias.
918 * Arguments: argc, argv - name of alias in argv[1].
919 * Returns: DM_NORMAL.
920 * NOTES: There should only be one filesystem per alias, thus
921 * this will work correctly.
922 */
923
924/* ARGSUSED */
925int
926GetFSAlias(argc, argv)
927int argc;
928char **argv;
929{
930 struct qelem *top;
931
932 top = GetFSInfo(ALIAS, argv[1]);
933 Put_message(" "); /* blank line. */
934 Loop(top, (void *) PrintFSAlias);
935 FreeQueue(top);
936 return(DM_NORMAL);
937}
938
939/* Function Name: CreateFSAlias
940 * Description: Create an alias name for a filesystem
941 * Arguments: argc, argv - name of alias in argv[1].
942 * Returns: DM_NORMAL.
943 * NOTES: This requires (name, type, transl) I get {name, translation}
944 * from the user. I provide type, which is well-known.
945 */
946
947/* ARGSUSED */
948int
949CreateFSAlias(argc, argv)
950int argc;
951char **argv;
952{
953 register int stat;
954 struct qelem *elem, *top;
955 char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info;
956
957 elem = NULL;
958
959 if (!ValidName(argv[1]))
960 return(DM_NORMAL);
961
962 args[ALIAS_NAME] = Strsave(argv[1]);
963 args[ALIAS_TYPE] = Strsave(FS_ALIAS_TYPE);
964 args[ALIAS_TRANS] = Strsave("*");
965
966/*
967 * Check to see if this alias already exists in the database, if so then
968 * print out values, free memory used and then exit.
969 */
970
971 if ( (stat = do_mr_query("get_alias", 3, args, StoreInfo,
972 (char *)&elem)) == 0) {
973 top = elem = QueueTop(elem);
974 while (elem != NULL) {
975 info = (char **) elem->q_data;
976 sprintf(buf,"The alias: %s currently describes the filesystem %s",
977 info[ALIAS_NAME], info[ALIAS_TRANS]);
978 Put_message(buf);
979 elem = elem->q_forw;
980 }
981 FreeQueue(top);
982 return(DM_NORMAL);
983 }
984 else if ( stat != MR_NO_MATCH) {
985 com_err(program_name, stat, " in CreateFSAlias.");
986 return(DM_NORMAL);
987 }
988
989 args[ALIAS_TRANS]= Strsave("");
990 args[ALIAS_END] = NULL;
991 if (GetValueFromUser("Which filesystem will this alias point to?",
992 &args[ALIAS_TRANS]) == SUB_ERROR)
993 return(DM_NORMAL);
994
995 if ( (stat = do_mr_query("add_alias", 3, args, NullFunc, NULL)) != 0)
996 com_err(program_name, stat, " in CreateFSAlias.");
997
998 FreeInfo(args);
999 return (DM_NORMAL);
1000}
1001
1002/* Function Name: RealDeleteFSAlias
1003 * Description: Does the real deletion work.
1004 * Arguments: info - array of char *'s containing all useful info.
1005 * one_item - a Boolean that is true if only one item
1006 * in queue that dumped us here.
1007 * Returns: none.
1008 */
1009
1010void
1011RealDeleteFSAlias(info, one_item)
1012char ** info;
1013Bool one_item;
1014{
1015 int stat;
1016 char temp_buf[BUFSIZ];
1017
1018/*
1019 * Deletetions are performed if the user hits 'y' on a list of multiple
1020 * filesystem, or if the user confirms on a unique alias.
1021 */
1022 sprintf(temp_buf,
1023 "Are you sure that you want to delete the filesystem alias %s",
1024 info[ALIAS_NAME]);
1025 if(!one_item || Confirm(temp_buf)) {
1026 if ( (stat = do_mr_query("delete_alias", CountArgs(info),
1027 info, Scream, NULL)) != 0 )
1028 com_err(program_name, stat, " filesystem alias not deleted.");
1029 else
1030 Put_message("Filesystem alias deleted.");
1031 }
1032 else
1033 Put_message("Filesystem alias not deleted.");
1034}
1035
1036/* Function Name: DeleteFSAlias
1037 * Description: Delete an alias name for a filesystem
1038 * Arguments: argc, argv - name of alias in argv[1].
1039 * Returns: DM_NORMAL.
1040 * NOTES: This requires (name, type, transl) I get {name, translation}
1041 * from the user. I provide type, which is well-known.
1042 */
1043
1044/* ARGSUSED */
1045int
1046DeleteFSAlias(argc, argv)
1047int argc;
1048char **argv;
1049{
1050 struct qelem *elem = GetFSInfo(ALIAS, argv[1]);
1051 QueryLoop(elem, PrintFSAlias, RealDeleteFSAlias,
1052 "Delete the Filesystem Alias");
1053 FreeQueue(elem);
1054 return (DM_NORMAL);
1055}
1056
1057/* Function Name: AttachHelp
1058 * Description: Print help info on attachmaint.
1059 * Arguments: none
1060 * Returns: DM_NORMAL.
1061 */
1062
1063int
1064AttachHelp()
1065{
1066 static char *message[] = {
1067 "These are the options:",
1068 "",
1069 "get - get information about a filesystem.",
1070 "add - add a new filesystem to the data base.",
1071 "update - update the information in the database on a filesystem.",
1072 "delete - delete a filesystem from the database.",
1073 "check - check information about association of a name and a filesys.",
1074 "alias - associate a name with a filesystem.",
1075 "unalias - disassociate a name with a filesystem.",
1076 "verbose - toggle the request for delete confirmation.",
1077 NULL,
1078 };
1079
1080 return(PrintHelp(message));
1081}
1082
1083/* Function Name: FSGroupHelp
1084 * Description: Print help info on fsgroups.
1085 * Arguments: none
1086 * Returns: DM_NORMAL.
1087 */
1088
1089int
1090FSGroupHelp()
1091{
1092 static char *message[] = {
1093 "A filesystem group is a named sorted list of filesystems.",
1094 "",
1095 "To create, modify, or delete a group itself, use the menu above",
1096 " this one, and manipulate a filesystem of type FSGROUP.",
1097 "Options here are:",
1098 " get - get info about a group and show its members",
1099 " add - add a new member to a group.",
1100 " remove - remove a member from a group.",
1101 " order - change the sorting order of a group.",
1102 NULL
1103 };
1104
1105 return(PrintHelp(message));
1106}
This page took 0.045022 seconds and 5 git commands to generate.