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