]> andersk Git - moira.git/blame - clients/moira/attach.c
Fixed comment about usernames being allowed to contain periods so that
[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>
27#include <menu.h>
28
461c03b6 29#include "mit-copyright.h"
0a2c64cb 30#include "defs.h"
31#include "f_defs.h"
461c03b6 32#include "globals.h"
33#include "infodefs.h"
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
85ca828a 42#define DEFAULT_TYPE ("NFS")
43#define DEFAULT_MACHINE DEFAULT_NONE
44#define DEFAULT_PACK DEFAULT_NONE
45#define DEFAULT_M_POINT DEFAULT_NONE
7f6743f7 46#define DEFAULT_ACCESS ("w")
85ca828a 47#define DEFAULT_COMMENTS DEFAULT_COMMENT
48#define DEFAULT_OWNER (user)
49#define DEFAULT_OWNERS (user)
50#define DEFAULT_CREATE DEFAULT_YES
7f6743f7 51#define DEFAULT_L_TYPE ("PROJECT")
85ca828a 52
53/* Function Name: SetDefaults
54 * Description: sets the default values for filesystem additions.
55 * Arguments: info - an array of char pointers to recieve defaults.
56 * Returns: char ** (this array, now filled).
57 */
58
59static char **
60SetDefaults(info, name)
61char ** info;
62char * name;
63{
64 info[FS_NAME] = Strsave(name);
65 info[FS_TYPE] = Strsave(DEFAULT_TYPE);
66 info[FS_MACHINE] = Strsave(DEFAULT_MACHINE);
67 info[FS_PACK] = Strsave(DEFAULT_PACK);
68 info[FS_M_POINT] = Strsave(DEFAULT_M_POINT);
69 info[FS_ACCESS] = Strsave(DEFAULT_ACCESS);
70 info[FS_COMMENTS] = Strsave(DEFAULT_COMMENTS);
71 info[FS_OWNER] = Strsave(DEFAULT_OWNER);
72 info[FS_OWNERS] = Strsave(DEFAULT_OWNERS);
73 info[FS_CREATE] = Strsave(DEFAULT_CREATE);
74 info[FS_L_TYPE] = Strsave(DEFAULT_L_TYPE);
75 info[FS_MODTIME] = info[FS_MODBY] = info[FS_MODWITH] = info[FS_END] = NULL;
76 return(info);
77}
78
08345b74 79/* Function Name: GetFSInfo
80 * Description: Stores the info in a queue.
81 * Arguments: type - type of information to get.
82 * name - name of the item to get information on.
83 * Returns: a pointer to the first element in the queue.
84 */
85
402461ad 86static struct qelem *
08345b74 87GetFSInfo(type, name)
88int type;
89char *name;
90{
91 int stat;
92 struct qelem * elem = NULL;
85ca828a 93 char * args[5];
08345b74 94
95 switch (type) {
461c03b6 96 case LABEL:
08345b74 97 if ( (stat = sms_query("get_filesys_by_label", 1, &name,
770464be 98 StoreInfo, (char *)&elem)) != 0) {
461c03b6 99 com_err(program_name, stat, NULL);
08345b74 100 return(NULL);
101 }
102 break;
461c03b6 103 case MACHINE:
104 if ( (stat = sms_query("get_filesys_by_machine", 1, &name,
770464be 105 StoreInfo, (char *)&elem)) != 0) {
461c03b6 106 com_err(program_name, stat, NULL);
08345b74 107 return(NULL);
108 }
109 break;
461c03b6 110 case GROUP:
111 if ( (stat = sms_query("get_filesys_by_group", 1, &name,
770464be 112 StoreInfo, (char *)&elem)) != 0) {
461c03b6 113 com_err(program_name, stat, NULL);
08345b74 114 return(NULL);
115 }
116 break;
461c03b6 117 case ALIAS:
85ca828a 118 args[ALIAS_NAME] = name;
119 args[ALIAS_TYPE] = FS_ALIAS_TYPE;
120 args[ALIAS_TRANS] = "*";
770464be 121 if ( (stat = sms_query("get_alias", 3, args, StoreInfo,
122 (char *) &elem)) != 0) {
461c03b6 123 com_err(program_name, stat, " in get_alias.");
08345b74 124 return(NULL);
125 }
126 }
127
128 return(QueueTop(elem));
129}
130
85ca828a 131/* Function Name: PrintFSAlias
132 * Description: Prints a filesystem alias
133 * Arguments: info - an array contains the strings of info.
402461ad 134 * Returns: the name of the filesys - used be QueryLoop().
85ca828a 135 */
136
402461ad 137static char *
85ca828a 138PrintFSAlias(info)
139char ** info;
140{
141 char buf[BUFSIZ];
142
143 sprintf(buf,"Alias: %-25s Filesystem: %s",info[ALIAS_NAME],
144 info[ALIAS_TRANS]);
145 Put_message(buf);
402461ad 146 return(info[ALIAS_NAME]);
85ca828a 147}
148
08345b74 149/* Function Name: PrintFSInfo
150 * Description: Prints the filesystem information.
151 * Arguments: info - a pointer to the filesystem information.
152 * Returns: none.
153 */
154
402461ad 155static char *
461c03b6 156PrintFSInfo(info)
08345b74 157char ** info;
158{
159 char print_buf[BUFSIZ];
85ca828a 160 FORMFEED;
161 sprintf(print_buf,"%20s Filesystem: %s",
162 " ",info[FS_NAME]);
08345b74 163 Put_message(print_buf);
85ca828a 164 sprintf(print_buf,"Type: %-40s Machine: %-15s",
165 info[FS_TYPE], info[FS_MACHINE]);
08345b74 166 Put_message(print_buf);
85ca828a 167 sprintf(print_buf,"Default Access: %-2s Packname: %-17s Mountpoint %s ",
168 info[FS_ACCESS], info[FS_PACK], info[FS_M_POINT]);
08345b74 169 Put_message(print_buf);
170 sprintf(print_buf,"Comments; %s",info[FS_COMMENTS]);
171 Put_message(print_buf);
85ca828a 172 sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s",
08345b74 173 info[FS_OWNER], info[FS_OWNERS]);
174 Put_message(print_buf);
075fe5bb 175 sprintf(print_buf, "Auto Create: %-34s Locker Type: %s",
176 atoi(info[FS_CREATE]) ? "ON" : "OFF",
08345b74 177 info[FS_L_TYPE]);
178 Put_message(print_buf);
075fe5bb 179 sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME],
180 info[FS_MODWITH]);
08345b74 181 Put_message(print_buf);
402461ad 182 return(info[FS_NAME]);
08345b74 183}
184
08345b74 185/* Function Name: AskFSInfo.
186 * Description: This function askes the user for information about a
187 * machine and saves it into a structure.
188 * Arguments: info - a pointer the the structure to put the
189 * info into.
190 * name - add a newname field? (T/F)
191 * Returns: none.
192 */
193
402461ad 194static char **
461c03b6 195AskFSInfo(info, name)
08345b74 196char ** info;
197Bool name;
198{
461c03b6 199 char temp_buf[BUFSIZ], *newname;
08345b74 200
402461ad 201 Put_message("");
202 sprintf(temp_buf, "Changing Attributes of filesystem %s.",
85ca828a 203 info[FS_NAME]);
08345b74 204 Put_message(temp_buf);
402461ad 205 Put_message("");
08345b74 206
207 if (name) {
208 newname = Strsave(info[FS_NAME]);
402461ad 209 GetValueFromUser("The new name for this filesystem",
08345b74 210 &newname);
211 }
212
84d7e36d 213 GetTypeFromUser("Filesystem's Type", "filesys", &info[FS_TYPE]);
402461ad 214 GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]);
85ca828a 215 strcpy(temp_buf, CanonicalizeHostname(info[FS_MACHINE]));
216 free(info[FS_MACHINE]);
217 info[FS_MACHINE] = Strsave(temp_buf);
402461ad 218 GetValueFromUser("Filesystem's Pack Name", &info[FS_PACK]);
219 GetValueFromUser("Filesystem's Mount Point", &info[FS_M_POINT]);
220 GetValueFromUser("Filesystem's Default Access", &info[FS_ACCESS]);
221 GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS]);
222 GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]);
223 GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]);
6c7a2fcf 224 GetYesNoValueFromUser("Automatically create this filesystem",
85ca828a 225 &info[FS_CREATE]);
84d7e36d 226 GetTypeFromUser("Filesystem's lockertype", "lockertype", &info[FS_L_TYPE]);
08345b74 227
228 FreeAndClear(&info[FS_MODTIME], TRUE);
229 FreeAndClear(&info[FS_MODBY], TRUE);
230 FreeAndClear(&info[FS_MODWITH], TRUE);
231
232 if (name) /* slide the newname into the #2 slot. */
233 SlipInNewName(info, newname);
234
235 return(info);
236}
237
238/* --------------- Filesystem Menu ------------- */
239
240/* Function Name: GetFS
241 * Description: Get Filesystem information by name.
242 * Arguments: argc, argv - name of filsys in argv[1].
243 * Returns: DM_NORMAL.
244 */
245
246/* ARGSUSED */
247int
248GetFS(argc, argv)
249int argc;
250char **argv;
251{
0a2c64cb 252 struct qelem *top;
08345b74 253
0a2c64cb 254 top = GetFSInfo(LABEL, argv[1]); /* get info. */
255 Loop(top, (void *) PrintFSInfo);
85ca828a 256 FreeQueue(top); /* clean the queue. */
08345b74 257 return (DM_NORMAL);
258}
259
402461ad 260/* Function Name: RealDeleteFS
261 * Description: Does the real deletion work.
262 * Arguments: info - array of char *'s containing all useful info.
263 * one_item - a Boolean that is true if only one item
264 * in queue that dumped us here.
265 * Returns: none.
266 */
267
268void
269RealDeleteFS(info, one_item)
270char ** info;
271Bool one_item;
272{
273 int stat;
274 char temp_buf[BUFSIZ];
275
276/*
277 * Deletetions are performed if the user hits 'y' on a list of multiple
278 * filesystem, or if the user confirms on a unique alias.
279 */
280 sprintf(temp_buf, "Are you sure that you want to delete filesystem %s",
281 info[FS_NAME]);
282 if(!one_item || Confirm(temp_buf)) {
283 if ( (stat = sms_query("delete_filesys", 1,
284 &info[FS_NAME], Scream, NULL)) != 0)
285 com_err(program_name, stat, " filesystem not deleted.");
286 else
287 Put_message("Filesystem deleted.");
288 }
289 else
290 Put_message("Filesystem not deleted.");
291}
292
08345b74 293/* Function Name: DeleteFS
294 * Description: Delete a filesystem give its name.
295 * Arguments: argc, argv - argv[1] is the name of the filesystem.
296 * Returns: none.
297 */
298
299/* ARGSUSED */
300
301int
302DeleteFS(argc, argv)
303int argc;
304char **argv;
305{
402461ad 306 struct qelem *elem = GetFSInfo(LABEL, argv[1]);
307 QueryLoop(elem, PrintFSInfo, RealDeleteFS, "Delete the Filesystem");
08345b74 308
402461ad 309 FreeQueue(elem);
08345b74 310 return (DM_NORMAL);
311}
312
402461ad 313/* Function Name: RealChangeFS
314 * Description: performs the actual change to the filesys.
315 * Arguments: info - the information
316 * junk - an unused boolean.
317 * Returns: none.
318 */
319
320/* ARGSUSED. */
321static void
322RealChangeFS(info, junk)
323char ** info;
324Bool junk;
325{
326 int stat;
327 char ** args = AskFSInfo(info, TRUE);
bff71786 328 extern Menu nfsphys_menu;
329
330 stat = sms_query("update_filesys", CountArgs(args), args, NullFunc, NULL);
331 switch (stat) {
332 case SMS_NFS:
333 Put_message("That NFS filesystem is not exported.");
334 if (YesNoQuestion("Fix this now (Y/N)")) {
335 Do_menu(&nfsphys_menu, 0, NULL);
336 if (YesNoQuestion("Retry filesystem update now (Y/N)")) {
337 if (stat = sms_query("update_filesys", CountArgs(args), args,
338 NullFunc, NULL))
339 com_err(program_name, stat, " filesystem not updated");
340 else
341 Put_message("filesystem sucessfully updated.");
342 }
343 }
344 break;
98cce88c 345 case SMS_SUCCESS:
346 break;
bff71786 347 default:
98cce88c 348 com_err(program_name, stat, " in UpdateFS");
bff71786 349 }
402461ad 350}
351
08345b74 352/* Function Name: ChangeFS
353 * Description: change the information in a filesys record.
354 * Arguments: arc, argv - value of filsys in argv[1].
355 * Returns: DM_NORMAL.
356 */
357
358/* ARGSUSED */
359int
360ChangeFS(argc, argv)
361char **argv;
362int argc;
363{
402461ad 364 struct qelem *elem = GetFSInfo(LABEL, argv[1]);
365 QueryLoop(elem, NullPrint, RealChangeFS, "Update the Filesystem");
08345b74 366
08345b74 367 FreeQueue(elem);
368 return (DM_NORMAL);
369}
370
371/* Function Name: AddFS
372 * Description: change the information in a filesys record.
373 * Arguments: arc, argv - name of filsys in argv[1].
374 * Returns: DM_NORMAL.
375 */
376
377/* ARGSUSED */
378int
379AddFS(argc, argv)
380char **argv;
381int argc;
382{
383 char *info[MAX_ARGS_SIZE], **args;
85ca828a 384 int stat;
bff71786 385 extern Menu nfsphys_menu;
08345b74 386
387 if ( !ValidName(argv[1]) )
388 return(DM_NORMAL);
389
390 if ( (stat = sms_query("get_filesys_by_label", 1, argv + 1,
391 NullFunc, NULL)) == 0) {
392 Put_message ("A Filesystem by that name already exists.");
393 return(DM_NORMAL);
461c03b6 394 } else if (stat != SMS_NO_MATCH) {
395 com_err(program_name, stat, " in AddFS");
08345b74 396 return(DM_NORMAL);
397 }
398
85ca828a 399 args = AskFSInfo(SetDefaults(info, argv[1]), FALSE );
461c03b6 400
bff71786 401 stat = sms_query("add_filesys", CountArgs(args), args, NullFunc, NULL);
402 switch (stat) {
403 case SMS_NFS:
404 Put_message("That NFS filesystem is not exported.");
405 if (YesNoQuestion("Fix this now (Y/N)")) {
406 Do_menu(&nfsphys_menu, 0, NULL);
407 if (YesNoQuestion("Retry filesystem creation now (Y/N)")) {
408 if (stat = sms_query("add_filesys", CountArgs(args), args,
409 NullFunc, NULL))
410 com_err(program_name, stat, " in AddFS");
411 else
412 Put_message("Created.");
413 }
414 }
415 break;
98cce88c 416 case SMS_SUCCESS:
417 break;
bff71786 418 default:
461c03b6 419 com_err(program_name, stat, " in AddFS");
bff71786 420 }
08345b74 421
422 FreeInfo(info);
423 return (DM_NORMAL);
424}
425
426/* -------------- Top Level Menu ---------------- */
427
428/* Function Name: GetFSAlias
429 * Description: Gets the value for a Filesystem Alias.
430 * Arguments: argc, argv - name of alias in argv[1].
431 * Returns: DM_NORMAL.
432 * NOTES: There should only be one filesystem per alias, thus
433 * this will work correctly.
434 */
435
436/* ARGSUSED */
437int
438GetFSAlias(argc, argv)
439int argc;
440char **argv;
441{
0a2c64cb 442 struct qelem *top;
08345b74 443
0a2c64cb 444 top = GetFSInfo(ALIAS, argv[1]);
85ca828a 445 Put_message(" "); /* blank line. */
0a2c64cb 446 Loop(top, (void *) PrintFSAlias);
08345b74 447 FreeQueue(top);
448 return(DM_NORMAL);
449}
450
451/* Function Name: CreateFSAlias
6c7a2fcf 452 * Description: Create an alias name for a filesystem
08345b74 453 * Arguments: argc, argv - name of alias in argv[1].
454 * Returns: DM_NORMAL.
455 * NOTES: This requires (name, type, transl) I get {name, translation}
456 * from the user. I provide type, which is well-known.
457 */
458
459/* ARGSUSED */
460int
461CreateFSAlias(argc, argv)
462int argc;
463char **argv;
464{
461c03b6 465 register int stat;
08345b74 466 struct qelem *elem, *top;
461c03b6 467 char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info;
08345b74 468
469 elem = NULL;
470
471 if (!ValidName(argv[1]))
472 return(DM_NORMAL);
473
461c03b6 474 args[ALIAS_NAME] = Strsave(argv[1]);
475 args[ALIAS_TYPE] = Strsave(FS_ALIAS_TYPE);
85ca828a 476 args[ALIAS_TRANS] = Strsave("*");
08345b74 477
478/*
479 * Check to see if this alias already exists in the database, if so then
480 * print out values, free memory used and then exit.
481 */
482
770464be 483 if ( (stat = sms_query("get_alias", 3, args, StoreInfo,
484 (char *)&elem)) == 0) {
85ca828a 485 top = elem = QueueTop(elem);
08345b74 486 while (elem != NULL) {
487 info = (char **) elem->q_data;
85ca828a 488 sprintf(buf,"The alias: %s currently describes the filesystem %s",
461c03b6 489 info[ALIAS_NAME], info[ALIAS_TRANS]);
08345b74 490 Put_message(buf);
491 elem = elem->q_forw;
492 }
493 FreeQueue(top);
494 return(DM_NORMAL);
495 }
496 else if ( stat != SMS_NO_MATCH) {
461c03b6 497 com_err(program_name, stat, " in CreateFSAlias.");
08345b74 498 return(DM_NORMAL);
499 }
500
461c03b6 501 args[ALIAS_TRANS]= args[ALIAS_END] = NULL; /* set to NULL initially. */
08345b74 502 GetValueFromUser("Which filesystem will this alias point to?",
461c03b6 503 &args[ALIAS_TRANS]);
08345b74 504
505 if ( (stat = sms_query("add_alias", 3, args, NullFunc, NULL)) != 0)
461c03b6 506 com_err(program_name, stat, " in CreateFSAlias.");
08345b74 507
461c03b6 508 FreeInfo(args);
08345b74 509 return (DM_NORMAL);
510}
402461ad 511
512/* Function Name: RealDeleteFSAlias
513 * Description: Does the real deletion work.
514 * Arguments: info - array of char *'s containing all useful info.
515 * one_item - a Boolean that is true if only one item
516 * in queue that dumped us here.
517 * Returns: none.
518 */
519
520void
521RealDeleteFSAlias(info, one_item)
522char ** info;
523Bool one_item;
524{
525 int stat;
526 char temp_buf[BUFSIZ];
527
528/*
529 * Deletetions are performed if the user hits 'y' on a list of multiple
530 * filesystem, or if the user confirms on a unique alias.
531 */
532 sprintf(temp_buf,
533 "Are you sure that you want to delete the filesystem alias %s",
534 info[ALIAS_NAME]);
535 if(!one_item || Confirm(temp_buf)) {
536 if ( (stat = sms_query("delete_alias", CountArgs(info),
537 info, Scream, NULL)) != 0 )
538 com_err(program_name, stat, " filesystem alias not deleted.");
539 else
540 Put_message("Filesystem alias deleted.");
541 }
542 else
543 Put_message("Filesystem alias not deleted.");
544}
08345b74 545
546/* Function Name: DeleteFSAlias
6c7a2fcf 547 * Description: Delete an alias name for a filesystem
08345b74 548 * Arguments: argc, argv - name of alias in argv[1].
549 * Returns: DM_NORMAL.
550 * NOTES: This requires (name, type, transl) I get {name, translation}
551 * from the user. I provide type, which is well-known.
552 */
553
554/* ARGSUSED */
555int
556DeleteFSAlias(argc, argv)
557int argc;
558char **argv;
559{
402461ad 560 struct qelem *elem = GetFSInfo(ALIAS, argv[1]);
561 QueryLoop(elem, PrintFSAlias, RealDeleteFSAlias,
562 "Delete the Filesystem Alias");
563 FreeQueue(elem);
08345b74 564 return (DM_NORMAL);
565}
566
567/* Function Name: AttachHelp
568 * Description: Print help info on attachmaint.
569 * Arguments: none
570 * Returns: DM_NORMAL.
571 */
572
573int
574AttachHelp()
575{
576 static char *message[] = {
85ca828a 577 "These are the options:\n\n",
578 "get - get information about a filesystem.\n",
579 "add - add a new filesystem to the data base.\n",
580 "update - update the information in the database on a filesystem.\n",
581 "delete - delete a filesystem from the database.\n",
582 "check - check information about association of a name and a filesys.\n",
6c7a2fcf 583 "alias - associate a name with a filesystem.\n",
85ca828a 584 "unalias - disassociate a name with a filesystem.\n",
585 "verbose - toggle the request for delete confirmation.\n",
08345b74 586 NULL,
587 };
588
589 return(PrintHelp(message));
590}
591
592/*
593 * Local Variables:
594 * mode: c
595 * c-indent-level: 4
596 * c-continued-statement-offset: 4
597 * c-brace-offset: -4
598 * c-argdecl-indent: 4
599 * c-label-offset: -4
600 * End:
601 */
This page took 0.146152 seconds and 5 git commands to generate.