]>
Commit | Line | Data |
---|---|---|
402461ad | 1 | #if (!defined(lint) && !defined(SABER)) |
08345b74 | 2 | static char rcsid_module_c[] = "$Header$"; |
3 | #endif lint | |
4 | ||
5 | /* This is the file nfs.c for allmaint, the SMS client that allows | |
6 | * a user to maintaint most important parts of the SMS database. | |
7 | * It Contains: The nfs maintanance code. | |
8 | * | |
9 | * Created: 5/6/88 | |
10 | * By: Chris D. Peterson | |
11 | * | |
12 | * $Source$ | |
13 | * $Author$ | |
14 | * $Header$ | |
15 | * | |
16 | * Copyright 1987, 1988 by the Massachusetts Institute of Technology. | |
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> | |
24 | #include <sms.h> | |
25 | #include <menu.h> | |
26 | ||
461c03b6 | 27 | #include "mit-copyright.h" |
28 | #include "allmaint.h" | |
29 | #include "allmaint_funcs.h" | |
30 | #include "globals.h" | |
31 | #include "infodefs.h" | |
32 | ||
08345b74 | 33 | /* #include <sys/types.h> */ |
34 | ||
35 | #define TYPE_NFS "NFS" | |
36 | ||
37 | #define DEFAULT_DIR "/mit" | |
075fe5bb | 38 | #define DEFAULT_DEVICE "ra0a" |
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 | ||
49 | static char * | |
50 | UpdatePrint(info) | |
51 | char ** 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 | 66 | static char * |
08345b74 | 67 | PrintNFSInfo(info) |
68 | char ** 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 | ||
76 | if (status & SMS_FS_STUDENT) { | |
77 | strcat(status_buf, "Student"); | |
78 | is_one = TRUE; | |
79 | } | |
80 | if (status & SMS_FS_FACULTY) { | |
81 | if (is_one) | |
82 | strcat(status_buf, " and "); | |
83 | strcat(status_buf, "Faculty"); | |
84 | is_one = TRUE; | |
85 | } | |
86 | if (status & SMS_FS_STAFF) { | |
87 | if (is_one) | |
88 | strcat(status_buf, " and "); | |
89 | strcat(status_buf, "Staff"); | |
90 | is_one = TRUE; | |
91 | } | |
92 | if (status & SMS_FS_MISC) { | |
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 | ||
125 | char ** | |
461c03b6 | 126 | AskNFSInfo(info) |
08345b74 | 127 | char ** 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 | ||
149 | static char * | |
150 | GetDirName() | |
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 | 165 | int |
166 | ShowNFSService(argc, argv) | |
167 | int argc; | |
168 | char **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 | |
075fe5bb | 177 | args[0] = CanonicalizeHostname(argv[1]); |
178 | if ( (args[1] = GetDirName()) == NULL) | |
179 | return(DM_NORMAL); | |
180 | ||
181 | if ( (stat = sms_query("get_nfsphys", 2, args, | |
182 | StoreInfo, (char *) &elem)) != SMS_SUCCESS) | |
461c03b6 | 183 | com_err(program_name, stat, " in ShowNFSServices."); |
075fe5bb | 184 | free(args[1]); /* prevents memory leaks. */ |
08345b74 | 185 | |
075fe5bb | 186 | elem = QueueTop(elem); |
187 | Loop(elem, (void *) PrintNFSInfo); | |
188 | ||
189 | FreeQueue(elem); | |
08345b74 | 190 | return (DM_NORMAL); |
191 | } | |
192 | ||
193 | /* Function Name: AddNFSService | |
194 | * Description: Adds a new partition to the nfsphys relation | |
075fe5bb | 195 | * Arguments: arc, argv - argv[1] - machine name. |
08345b74 | 196 | * Returns: DM_NORMAL. |
197 | */ | |
198 | ||
85ca828a | 199 | /* ARGSUSED */ |
08345b74 | 200 | int |
201 | AddNFSService(argc, argv) | |
202 | char **argv; | |
203 | int argc; | |
204 | { | |
075fe5bb | 205 | char **add_args, *args[10]; |
206 | char *info[MAX_ARGS_SIZE]; | |
08345b74 | 207 | int stat; |
075fe5bb | 208 | |
209 | args[0] = CanonicalizeHostname(argv[1]); | |
210 | if ( (args[1] = GetDirName()) == NULL) | |
211 | return(DM_NORMAL); | |
212 | ||
213 | if (!ValidName(args[0]) || !ValidName(args[1])) | |
214 | return(DM_NORMAL); | |
08345b74 | 215 | |
075fe5bb | 216 | if ( (stat = sms_query("get_nfsphys", 2, args, |
217 | NullFunc, (char *) NULL)) == SMS_SUCCESS) | |
08345b74 | 218 | Put_message("This service already exists."); |
075fe5bb | 219 | if (stat != SMS_NO_MATCH) |
220 | com_err(program_name, stat, " in get_nfsphys."); | |
08345b74 | 221 | |
075fe5bb | 222 | info[NFS_NAME] = Strsave(args[0]); |
223 | info[NFS_DIR] = args[1]; /* already saved. */ | |
224 | info[NFS_DEVICE] = Strsave(DEFAULT_DEVICE); | |
08345b74 | 225 | info[NFS_STATUS] = Strsave(DEFAULT_STATUS); |
226 | info[NFS_ALLOC] = Strsave(DEFAULT_ALLOC); | |
227 | info[NFS_SIZE] = Strsave(DEFAULT_SIZE); | |
075fe5bb | 228 | info[NFS_MODBY] = info[NFS_MODWITH] = info[NFS_MODTIME] = NULL; |
229 | info[NFS_END] = NULL; | |
08345b74 | 230 | |
075fe5bb | 231 | add_args = AskNFSInfo(info); |
08345b74 | 232 | |
075fe5bb | 233 | if ((stat = sms_query("add_nfsphys", CountArgs(add_args), add_args, |
08345b74 | 234 | Scream, (char *) NULL)) != 0) |
461c03b6 | 235 | com_err(program_name, stat, " in AdsNFSService"); |
08345b74 | 236 | |
237 | FreeInfo(info); | |
238 | return (DM_NORMAL); | |
239 | } | |
240 | ||
075fe5bb | 241 | /* Function Name: RealUpdateNFSService |
242 | * Description: performs the actual update of the nfs service. | |
243 | * Arguments: info - info about NFS service stored in array of strings. | |
244 | * junk - an unused boolean. | |
245 | * Returns: none. | |
246 | */ | |
247 | ||
248 | /* ARGSUSED */ | |
249 | static void | |
250 | RealUpdateNFSService(info, junk) | |
251 | char ** info; | |
252 | Bool junk; | |
253 | { | |
254 | char ** args; | |
255 | register int stat; | |
256 | ||
257 | args = AskNFSInfo(info); | |
258 | if ((stat = sms_query("update_nfsphys", CountArgs(args), args, | |
259 | Scream, (char *)NULL)) != SMS_SUCCESS) | |
260 | com_err(program_name, stat, (char *) NULL); | |
261 | } | |
262 | ||
08345b74 | 263 | /* Function Name: UpdateNFSService |
264 | * Description: Update the values for an nfsphys entry. | |
075fe5bb | 265 | * Arguments: argc, argv - argv[1] - machine name. |
08345b74 | 266 | * Returns: DM_NORMAL. |
267 | */ | |
268 | ||
269 | /* ARGSUSED. */ | |
270 | int | |
271 | UpdateNFSService(argc, argv) | |
272 | char **argv; | |
273 | int argc; | |
274 | { | |
275 | register int stat; | |
075fe5bb | 276 | struct qelem *elem = NULL; |
277 | char * args[10]; | |
08345b74 | 278 | |
075fe5bb | 279 | if (!ValidName(argv[1])) |
08345b74 | 280 | return(DM_NORMAL); |
08345b74 | 281 | |
075fe5bb | 282 | args[0] = CanonicalizeHostname(argv[1]); |
283 | if ( (args[1] = GetDirName()) == NULL) | |
284 | return(DM_NORMAL); | |
285 | ||
286 | if ( (stat = sms_query("get_nfsphys", 2, args, | |
287 | StoreInfo, (char *) &elem)) != SMS_SUCCESS) { | |
461c03b6 | 288 | com_err(program_name, stat, " in UpdateNFSService."); |
08345b74 | 289 | return (DM_NORMAL); |
290 | } | |
075fe5bb | 291 | free(args[1]); /* stop memory leaks. */ |
08345b74 | 292 | |
075fe5bb | 293 | elem = QueueTop(elem); |
294 | QueryLoop(elem, UpdatePrint, RealUpdateNFSService, | |
295 | "Update NFS Service for"); | |
08345b74 | 296 | |
075fe5bb | 297 | FreeQueue(elem); |
08345b74 | 298 | return (DM_NORMAL); |
299 | } | |
300 | ||
075fe5bb | 301 | /* Function Name: FSPartPrint |
302 | * Description: print filesystem partition usage. | |
303 | * Arguments: info - the filesystem information. | |
304 | * Returns: none. | |
305 | */ | |
306 | ||
307 | static void | |
308 | FSPartPrint(info) | |
309 | char ** info; | |
310 | { | |
311 | char buf[BUFSIZ]; | |
312 | sprintf(buf, "NFS Filesystem %s uses that partition.", info[FS_NAME]); | |
313 | Put_message(buf); | |
314 | } | |
315 | ||
316 | /* Function Name: RealDeleteNFSService | |
317 | * Description: Actually Deletes the filesystem (some checks are made). | |
318 | * Arguments: info - info about NFS service stored in array of strings. | |
319 | * one_item - if TRUE then only one item on the queue, and | |
320 | * we should confirm. | |
321 | * Returns: none. | |
322 | */ | |
323 | ||
324 | static void | |
325 | RealDeleteNFSService(info, one_item) | |
326 | char ** info; | |
327 | Bool one_item; | |
328 | { | |
329 | char temp_buf[BUFSIZ], *args[10]; | |
330 | struct qelem *elem= NULL; | |
331 | register int stat; | |
332 | ||
333 | sprintf(temp_buf, | |
334 | "Are you sure that you want to delete the %s directory on %s", | |
335 | info[NFS_DIR],info[NFS_NAME]); | |
336 | ||
337 | /* | |
338 | * Check to be sure that it is not used by any of the nfs packs. | |
339 | */ | |
340 | ||
341 | if (!one_item || Confirm(temp_buf)) { | |
342 | args[0] = info[NFS_NAME]; | |
343 | args[1] = info[NFS_DIR]; | |
344 | args[2] = NULL; | |
345 | switch(stat = sms_query("get_filesys_by_nfsphys", CountArgs(args), | |
346 | args, StoreInfo, &elem)) { | |
347 | case SMS_NO_MATCH: /* it is unused, delete it. */ | |
348 | if ( (stat = sms_query("delete_nfsphys", 2, info, Scream, | |
349 | (char *) NULL )) != SMS_SUCCESS) | |
350 | com_err(program_name, stat, " in DeleteNFSService"); | |
351 | else | |
352 | Put_message("Physical Filesystem Deleted."); | |
353 | break; | |
354 | case SMS_SUCCESS: /* it is used, print filesys's that use it. */ | |
355 | elem = QueueTop(elem); | |
356 | Put_message("The following fileystems are using this partition,"); | |
357 | Put_message("and must be removed before it can be deleted."); | |
358 | Put_message(""); | |
359 | Loop(elem, FSPartPrint); | |
360 | ||
361 | FreeQueue(elem); | |
362 | Put_message(""); | |
363 | break; | |
364 | default: | |
365 | com_err(program_name, stat, " while checking usage of partition"); | |
366 | } | |
367 | } | |
368 | else | |
369 | Put_message("Physical filesystem not deleted."); | |
370 | } | |
371 | ||
08345b74 | 372 | /* Function Name: DeleteNFSService |
373 | * Description: Delete an nfsphys entry. | |
075fe5bb | 374 | * Arguments: argc, argv - name of the machine in argv[1]. |
08345b74 | 375 | * Returns: DM_NORMAL. |
376 | */ | |
377 | ||
378 | /* ARGSUSED */ | |
379 | int | |
380 | DeleteNFSService(argc, argv) | |
381 | int argc; | |
382 | char **argv; | |
383 | { | |
384 | register int stat; | |
075fe5bb | 385 | struct qelem *elem = NULL; |
386 | char * args[10]; | |
08345b74 | 387 | |
075fe5bb | 388 | if (!ValidName(argv[1])) |
389 | return(DM_NORMAL); | |
390 | ||
391 | args[0] = CanonicalizeHostname(argv[1]); | |
392 | if ( (args[1] = GetDirName()) == NULL) | |
393 | return(DM_NORMAL); | |
08345b74 | 394 | |
075fe5bb | 395 | switch(stat = sms_query("get_nfsphys", 2, args, |
396 | StoreInfo, (char *) &elem)) { | |
397 | case SMS_NO_MATCH: | |
08345b74 | 398 | Put_message("This filsystem does not exist!"); |
399 | return(DM_NORMAL); | |
075fe5bb | 400 | case SMS_SUCCESS: |
401 | break; | |
402 | default: | |
461c03b6 | 403 | com_err(program_name, stat, " in DeleteNFSService"); |
08345b74 | 404 | return(DM_NORMAL); |
405 | } | |
075fe5bb | 406 | free(args[1]); /* stop memory leaks, in your neighborhood. */ |
08345b74 | 407 | |
075fe5bb | 408 | QueryLoop(elem, PrintNFSInfo, RealDeleteNFSService, |
409 | "Delete the Physical Filesystem on Directory"); | |
08345b74 | 410 | |
075fe5bb | 411 | FreeQueue(elem); |
08345b74 | 412 | return(DM_NORMAL); |
075fe5bb | 413 | } |
08345b74 | 414 | |
415 | /* | |
416 | * Local Variables: | |
417 | * mode: c | |
418 | * c-indent-level: 4 | |
419 | * c-continued-statement-offset: 4 | |
420 | * c-brace-offset: -4 | |
421 | * c-argdecl-indent: 4 | |
422 | * c-label-offset: -4 | |
423 | * End: | |
424 | */ |