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