]> andersk Git - moira.git/blame - clients/moira/nfs.c
fix duplicated accelerators
[moira.git] / clients / moira / nfs.c
CommitLineData
402461ad 1#if (!defined(lint) && !defined(SABER))
08345b74 2 static char rcsid_module_c[] = "$Header$";
3#endif lint
4
8defc06b 5/* This is the file nfs.c for the MOIRA Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the MOIRA database.
0a2c64cb 7 * It Contains: All functions for manipulating NFS Physical directories.
08345b74 8 *
9 * Created: 5/6/88
10 * By: Chris D. Peterson
11 *
12 * $Source$
13 * $Author$
14 * $Header$
15 *
0a2c64cb 16 * Copyright 1988 by the Massachusetts Institute of Technology.
08345b74 17 *
18 * For further information on copyright and distribution
19 * see the file mit-copyright.h
20 */
21
08345b74 22#include <stdio.h>
23#include <strings.h>
8defc06b 24#include <moira.h>
25#include <moira_site.h>
08345b74 26#include <menu.h>
27
461c03b6 28#include "mit-copyright.h"
0a2c64cb 29#include "defs.h"
30#include "f_defs.h"
461c03b6 31#include "globals.h"
461c03b6 32
08345b74 33
34#define TYPE_NFS "NFS"
35
2851eeaf 36#define DEFAULT_DIR "/u1/lockers"
ca45701c 37#define DEFAULT_DEVICE "/dev/ra1c"
075fe5bb 38#define DEFAULT_STATUS DEFAULT_YES /* active. */
08345b74 39#define DEFAULT_ALLOC "0"
075fe5bb 40#define DEFAULT_SIZE "0"
41
42/* Function Name: UpdatePrint
43 * Description: store a useful string for updates to print.
44 * Arguments: info - info about NFS service stored in array of strings.
45 * Returns: useful string.
46 */
47
48static char *
49UpdatePrint(info)
50char ** info;
51{
52 char temp_buf[BUFSIZ];
53 sprintf(temp_buf, "Machine %s Directory %s",
54 info[NFS_NAME], info[NFS_DIR]);
55 return(Strsave(temp_buf)); /* Small memory leak here, but no good way
56 to avoid it that I see. */
57}
08345b74 58
59/* Function Name: PrintNFSInfo
60 * Description: Prints NFS Physical service information.
61 * Arguments: info - the information.
075fe5bb 62 * Returns: directory of this nfs server, for DeleteNFSService().
08345b74 63 */
64
075fe5bb 65static char *
08345b74 66PrintNFSInfo(info)
67char ** info;
68{
075fe5bb 69 char buf[BUFSIZ], status_buf[BUFSIZ];
08345b74 70 int status = atoi(info[NFS_STATUS]);
075fe5bb 71 Bool is_one = FALSE;
08345b74 72
075fe5bb 73 status_buf[0] = '\0'; /* clear string. */
74
8defc06b 75 if (status & MR_FS_STUDENT) {
075fe5bb 76 strcat(status_buf, "Student");
77 is_one = TRUE;
78 }
8defc06b 79 if (status & MR_FS_FACULTY) {
075fe5bb 80 if (is_one)
81 strcat(status_buf, " and ");
82 strcat(status_buf, "Faculty");
83 is_one = TRUE;
84 }
8defc06b 85 if (status & MR_FS_STAFF) {
075fe5bb 86 if (is_one)
87 strcat(status_buf, " and ");
88 strcat(status_buf, "Staff");
89 is_one = TRUE;
90 }
8defc06b 91 if (status & MR_FS_MISC) {
075fe5bb 92 if (is_one)
93 strcat(status_buf, " and ");
94 strcat(status_buf, "Miscellaneous");
95 }
96 /* Add another type here. */
9d5593c1 97 if (status & MR_FS_GROUPQUOTA) {
98 if (is_one)
99 strcat(status_buf, " / ");
100 strcat(status_buf, "Group Quotas Enabled");
101 }
075fe5bb 102
103 if (status_buf[0] == '\0')
104 strcat(status_buf, "-- None --");
105
106 Put_message("");
107 sprintf(buf,"Machine: %-20s Directory: %-15s Device: %s",
08345b74 108 info[NFS_NAME], info[NFS_DIR], info[NFS_DEVICE]);
075fe5bb 109 Put_message(buf);
110 sprintf(buf, "Status: %s", status_buf);
111 Put_message(buf);
112 sprintf(buf, "Quota Allocated: %-17s Size: %s",
113 info[NFS_ALLOC], info[NFS_SIZE]);
114 Put_message(buf);
115 sprintf(buf, MOD_FORMAT, info[NFS_MODBY], info[NFS_MODTIME],
116 info[NFS_MODWITH]);
117 Put_message(buf);
118 return(info[NFS_DIR]);
08345b74 119}
075fe5bb 120
08345b74 121/* Function Name: AskNFSInfo.
122 * Description: This function askes the user for information about a
123 * machine and saves it into a structure.
124 * Arguments: info - a pointer the the structure to put the
125 * info into.
126 * Returns: the arglist to make the update call with.
127 */
128
129char **
461c03b6 130AskNFSInfo(info)
08345b74 131char ** info;
132{
133 /* Also need name of the machine in this structure. */
134
2851eeaf 135 if (GetValueFromUser("Device for this filsystem", &info[NFS_DEVICE]) ==
136 SUB_ERROR)
137 return(NULL);
138 if (GetFSTypes(&info[NFS_STATUS], TRUE) == SUB_ERROR)
139 return(NULL);
140 if (GetValueFromUser("Allocated Space for this filsystem:",
141 &info[NFS_ALLOC]) == SUB_ERROR)
142 return(NULL);
143 if (GetValueFromUser("Size of this Filsystem:", &info[NFS_SIZE]) ==
144 SUB_ERROR)
145 return(NULL);
08345b74 146
147 FreeAndClear(&info[NFS_MODTIME], TRUE);
148 FreeAndClear(&info[NFS_MODBY], TRUE);
149 FreeAndClear(&info[NFS_MODWITH], TRUE);
150
461c03b6 151 return(info);
08345b74 152}
153
075fe5bb 154
08345b74 155/* Function Name: ShowNFSService
156 * Description: This function prints all exported partitions.
461c03b6 157 * Arguments: argc, argv - argv[1] - name of machine.
08345b74 158 * Returns: DM_NORMAL.
159 */
160
85ca828a 161/* ARGSUSED */
08345b74 162int
163ShowNFSService(argc, argv)
164int argc;
165char **argv;
166{
167 register int stat;
075fe5bb 168 struct qelem *elem = NULL;
169 char *args[10];
170
171 if (!ValidName(argv[1]))
172 return(DM_NORMAL);
08345b74 173
2aaf43e0 174 args[0] = canonicalize_hostname(strsave(argv[1]));
2851eeaf 175 args[1] = strsave(DEFAULT_DIR);
176 if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR)
177 return(DM_NORMAL);
075fe5bb 178
8defc06b 179 if ( (stat = do_mr_query("get_nfsphys", 2, args,
180 StoreInfo, (char *) &elem)) != MR_SUCCESS)
461c03b6 181 com_err(program_name, stat, " in ShowNFSServices.");
2aaf43e0 182 free(args[0]);
075fe5bb 183 free(args[1]); /* prevents memory leaks. */
08345b74 184
075fe5bb 185 elem = QueueTop(elem);
186 Loop(elem, (void *) PrintNFSInfo);
187
188 FreeQueue(elem);
08345b74 189 return (DM_NORMAL);
190}
191
192/* Function Name: AddNFSService
193 * Description: Adds a new partition to the nfsphys relation
075fe5bb 194 * Arguments: arc, argv - argv[1] - machine name.
08345b74 195 * Returns: DM_NORMAL.
196 */
197
85ca828a 198/* ARGSUSED */
08345b74 199int
200AddNFSService(argc, argv)
201char **argv;
202int argc;
203{
075fe5bb 204 char **add_args, *args[10];
205 char *info[MAX_ARGS_SIZE];
08345b74 206 int stat;
075fe5bb 207
2aaf43e0 208 args[0] = canonicalize_hostname(strsave(argv[1]));
2851eeaf 209 args[1] = strsave(DEFAULT_DIR);
210 if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR)
211 return(DM_NORMAL);
075fe5bb 212
213 if (!ValidName(args[0]) || !ValidName(args[1]))
214 return(DM_NORMAL);
08345b74 215
8defc06b 216 if ( (stat = do_mr_query("get_nfsphys", 2, args,
217 NullFunc, (char *) NULL)) == MR_SUCCESS)
2851eeaf 218 stat = MR_EXISTS;
219 if (stat != MR_NO_MATCH) {
075fe5bb 220 com_err(program_name, stat, " in get_nfsphys.");
2851eeaf 221 return(DM_NORMAL);
222 }
08345b74 223
075fe5bb 224 info[NFS_NAME] = Strsave(args[0]);
225 info[NFS_DIR] = args[1]; /* already saved. */
226 info[NFS_DEVICE] = Strsave(DEFAULT_DEVICE);
08345b74 227 info[NFS_STATUS] = Strsave(DEFAULT_STATUS);
228 info[NFS_ALLOC] = Strsave(DEFAULT_ALLOC);
229 info[NFS_SIZE] = Strsave(DEFAULT_SIZE);
075fe5bb 230 info[NFS_MODBY] = info[NFS_MODWITH] = info[NFS_MODTIME] = NULL;
231 info[NFS_END] = NULL;
08345b74 232
2851eeaf 233 if ((add_args = AskNFSInfo(info)) == NULL) {
234 Put_message("Aborted.");
235 return(DM_NORMAL);
236 }
08345b74 237
8defc06b 238 if ((stat = do_mr_query("add_nfsphys", CountArgs(add_args), add_args,
14f99d7d 239 Scream, (char *) NULL)) != 0)
461c03b6 240 com_err(program_name, stat, " in AdsNFSService");
08345b74 241
242 FreeInfo(info);
2aaf43e0 243 free(args[0]);
08345b74 244 return (DM_NORMAL);
245}
246
075fe5bb 247/* Function Name: RealUpdateNFSService
248 * Description: performs the actual update of the nfs service.
249 * Arguments: info - info about NFS service stored in array of strings.
250 * junk - an unused boolean.
251 * Returns: none.
252 */
253
254/* ARGSUSED */
255static void
256RealUpdateNFSService(info, junk)
257char ** info;
258Bool junk;
259{
260 char ** args;
261 register int stat;
262
2851eeaf 263 if ((args = AskNFSInfo(info)) == NULL) {
264 Put_message("Aborted.");
265 return;
266 }
267
8defc06b 268 if ((stat = do_mr_query("update_nfsphys", CountArgs(args), args,
269 Scream, (char *)NULL)) != MR_SUCCESS)
b98304a9 270 com_err(program_name, stat, " in RealUpdateNFSService");
075fe5bb 271}
272
08345b74 273/* Function Name: UpdateNFSService
274 * Description: Update the values for an nfsphys entry.
075fe5bb 275 * Arguments: argc, argv - argv[1] - machine name.
08345b74 276 * Returns: DM_NORMAL.
277 */
278
279/* ARGSUSED. */
280int
281UpdateNFSService(argc, argv)
282char **argv;
283int argc;
284{
285 register int stat;
075fe5bb 286 struct qelem *elem = NULL;
287 char * args[10];
08345b74 288
075fe5bb 289 if (!ValidName(argv[1]))
08345b74 290 return(DM_NORMAL);
08345b74 291
2aaf43e0 292 args[0] = canonicalize_hostname(strsave(argv[1]));
2851eeaf 293 args[1] = strsave(DEFAULT_DIR);
294 if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR)
295 return(DM_NORMAL);
075fe5bb 296
8defc06b 297 if ( (stat = do_mr_query("get_nfsphys", 2, args,
298 StoreInfo, (char *) &elem)) != MR_SUCCESS) {
461c03b6 299 com_err(program_name, stat, " in UpdateNFSService.");
08345b74 300 return (DM_NORMAL);
301 }
2aaf43e0 302 free(args[0]);
075fe5bb 303 free(args[1]); /* stop memory leaks. */
08345b74 304
075fe5bb 305 elem = QueueTop(elem);
306 QueryLoop(elem, UpdatePrint, RealUpdateNFSService,
307 "Update NFS Service for");
08345b74 308
075fe5bb 309 FreeQueue(elem);
08345b74 310 return (DM_NORMAL);
311}
312
075fe5bb 313/* Function Name: FSPartPrint
314 * Description: print filesystem partition usage.
315 * Arguments: info - the filesystem information.
316 * Returns: none.
317 */
318
319static void
320FSPartPrint(info)
321char ** info;
322{
323 char buf[BUFSIZ];
324 sprintf(buf, "NFS Filesystem %s uses that partition.", info[FS_NAME]);
325 Put_message(buf);
326}
327
328/* Function Name: RealDeleteNFSService
329 * Description: Actually Deletes the filesystem (some checks are made).
330 * Arguments: info - info about NFS service stored in array of strings.
331 * one_item - if TRUE then only one item on the queue, and
332 * we should confirm.
333 * Returns: none.
334 */
335
336static void
337RealDeleteNFSService(info, one_item)
338char ** info;
339Bool one_item;
340{
341 char temp_buf[BUFSIZ], *args[10];
342 struct qelem *elem= NULL;
343 register int stat;
344
345 sprintf(temp_buf,
346 "Are you sure that you want to delete the %s directory on %s",
347 info[NFS_DIR],info[NFS_NAME]);
348
349/*
350 * Check to be sure that it is not used by any of the nfs packs.
351 */
352
353 if (!one_item || Confirm(temp_buf)) {
354 args[0] = info[NFS_NAME];
355 args[1] = info[NFS_DIR];
356 args[2] = NULL;
8defc06b 357 switch(stat = do_mr_query("get_filesys_by_nfsphys", CountArgs(args),
14f99d7d 358 args, StoreInfo, (char *)&elem)) {
8defc06b 359 case MR_NO_MATCH: /* it is unused, delete it. */
360 if ( (stat = do_mr_query("delete_nfsphys", 2, info, Scream,
361 (char *) NULL )) != MR_SUCCESS)
075fe5bb 362 com_err(program_name, stat, " in DeleteNFSService");
363 else
364 Put_message("Physical Filesystem Deleted.");
365 break;
8defc06b 366 case MR_SUCCESS: /* it is used, print filesys's that use it. */
075fe5bb 367 elem = QueueTop(elem);
368 Put_message("The following fileystems are using this partition,");
369 Put_message("and must be removed before it can be deleted.");
370 Put_message("");
371 Loop(elem, FSPartPrint);
372
373 FreeQueue(elem);
374 Put_message("");
375 break;
376 default:
377 com_err(program_name, stat, " while checking usage of partition");
378 }
379 }
380 else
381 Put_message("Physical filesystem not deleted.");
382}
383
08345b74 384/* Function Name: DeleteNFSService
385 * Description: Delete an nfsphys entry.
075fe5bb 386 * Arguments: argc, argv - name of the machine in argv[1].
08345b74 387 * Returns: DM_NORMAL.
388 */
389
390/* ARGSUSED */
391int
392DeleteNFSService(argc, argv)
393int argc;
394char **argv;
395{
396 register int stat;
075fe5bb 397 struct qelem *elem = NULL;
398 char * args[10];
08345b74 399
075fe5bb 400 if (!ValidName(argv[1]))
401 return(DM_NORMAL);
402
2aaf43e0 403 args[0] = canonicalize_hostname(strsave(argv[1]));
2851eeaf 404 args[1] = strsave(DEFAULT_DIR);
405 if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR)
406 return(DM_NORMAL);
08345b74 407
8defc06b 408 switch(stat = do_mr_query("get_nfsphys", 2, args,
14f99d7d 409 StoreInfo, (char *) &elem)) {
8defc06b 410 case MR_NO_MATCH:
08345b74 411 Put_message("This filsystem does not exist!");
412 return(DM_NORMAL);
8defc06b 413 case MR_SUCCESS:
075fe5bb 414 break;
415 default:
461c03b6 416 com_err(program_name, stat, " in DeleteNFSService");
08345b74 417 return(DM_NORMAL);
418 }
2aaf43e0 419 free(args[0]);
075fe5bb 420 free(args[1]); /* stop memory leaks, in your neighborhood. */
08345b74 421
075fe5bb 422 QueryLoop(elem, PrintNFSInfo, RealDeleteNFSService,
423 "Delete the Physical Filesystem on Directory");
08345b74 424
075fe5bb 425 FreeQueue(elem);
08345b74 426 return(DM_NORMAL);
075fe5bb 427}
This page took 0.159138 seconds and 5 git commands to generate.