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