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