]> andersk Git - moira.git/blame - clients/moira/quota.c
fixed include files
[moira.git] / clients / moira / quota.c
CommitLineData
73c83e3d 1#if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
3#endif lint
4
0a2c64cb 5/* This is the file quota.c for the SMS Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the SMS database.
7 * It Contains: Functions for manipulating the quota information.
73c83e3d 8 *
0a2c64cb 9 * Created: 7/10/88
10 * By: Chris D. Peterson
73c83e3d 11 *
12 * $Source$
13 * $Author$
14 * $Header$
15 *
0a2c64cb 16 * Copyright 1988 by the Massachusetts Institute of Technology.
73c83e3d 17 *
18 * For further information on copyright and distribution
19 * see the file mit-copyright.h
20 */
21
73c83e3d 22#include <stdio.h>
23#include <strings.h>
24#include <sms.h>
cc3056a6 25#include <sms_app.h>
73c83e3d 26#include <menu.h>
27
28#include "mit-copyright.h"
0a2c64cb 29#include "defs.h"
30#include "f_defs.h"
73c83e3d 31#include "globals.h"
73c83e3d 32
33static char * def_quota = NULL;
34
35#define DEFAULT_FILESYS DEFAULT_NONE
36#define DEFAULT_USER user /* this is the user who started sms. */
37
38/* Function Name: GetDefaultUserQuota
39 * Description: gets the user quota from sms, and caches the value.
40 * Arguments: override - if true, go to sms and override the cache.
41 * Returns: none.
42 * NOTE: Using a queue here is pretty useless, but StoreInfo expects
43 * one, and it works, so why fuck with it.
44 */
45
46static char *
47GetDefaultUserQuota(override)
48Bool override;
49{
50 register int status;
51 char ** info;
52 struct qelem * top = NULL;
53 static char *val[] = {"def_quota", NULL};
54
55 if (override || (def_quota == NULL)) {
14f99d7d 56 if ( (status = do_sms_query("get_value", CountArgs(val), val,
57 StoreInfo, (char *) &top)) != SMS_SUCCESS) {
73c83e3d 58 com_err(program_name, status, " in ShowDefaultQuota");
59 if (def_quota == NULL) {
60 Put_message("No default Quota Found, setting default to 0.");
61 def_quota = Strsave("0");
62 }
63 else
64 Put_message("No default Quota Found, retaining old value.");
65 }
66 else {
67 top = QueueTop(top);
68 info = (char **) top->q_data;
69 FreeAndClear(&def_quota, TRUE);
70 def_quota = Strsave(info[0]);
71 FreeQueue(top);
72 }
73 }
74 return(def_quota);
75}
76
77/* Function Name: PrintDefaultQuota
78 * Description: Prints default quota info in a meaningful way.
79 * Arguments: value of the default quota.
80 * Returns: none.
81 */
82
83static void
84PrintDefaultQuota(quota)
85char * quota;
86{
87 char temp_buf[BUFSIZ];
88 Put_message("");
89 sprintf(temp_buf,"The default quota is %s Kb.", quota);
90 Put_message(temp_buf);
91}
92
93/* Function Name: PrintQuota
94 * Description: Prints a users quota information.
95 * Arguments: info - a pointer to the quota information:
96 * Returns: none.
97 */
98
99static char *
100PrintQuota(info)
101char ** info;
102{
103 char buf[BUFSIZ];
104 Put_message("");
105 sprintf(buf, "Filsystem: %-45s User: %s",info[Q_FILESYS], info[Q_LOGIN]);
106 Put_message(buf);
107 sprintf(buf, "Machine: %-20s Directory: %-15s Quota: %s",
108 info[Q_MACHINE], info[Q_DIRECTORY], info[Q_QUOTA]);
109 Put_message(buf);
110 return(info[Q_FILESYS]);
111}
112
113/* Function Name: GetQuotaArgs
114 * Description: gets quota args from the user
115 * Arguments: quota - if TRUE the get quota too.
116 * Returns: the arguments.
117 */
118
119static char **
120GetQuotaArgs(quota)
121Bool quota;
122{
123 char ** args = (char **) malloc( MAX_ARGS_SIZE * sizeof(char *) );
124
125 if (args == NULL) {
126 Put_message("Could not allocate memory in GetQuotaArgs.");
127 return(NULL);
128 }
129
130 args[Q_FILESYS] = Strsave(DEFAULT_FILESYS);
131 args[Q_LOGIN] = Strsave(DEFAULT_USER);
132 if (quota) {
133 args[Q_QUOTA] = Strsave(GetDefaultUserQuota(FALSE));
134 args[3] = NULL; /* NULL terminate. */
135 }
136 else
137 args[2] = NULL; /* NULL terminate. */
138
139 /* Get filesystem. */
140
141 GetValueFromUser("Filesystem", &args[Q_FILESYS]);
142 if (quota) /* We need an exact entry. */
143 if (!ValidName(args[Q_FILESYS]))
144 return(NULL);
145
146 /* Get and check username. */
147
148 GetValueFromUser("Username", &args[Q_LOGIN]);
149 if (!ValidName(args[Q_LOGIN])) return(NULL);
150
151 if (quota) { /* Get and check quota. */
152 GetValueFromUser("Quota", &args[Q_QUOTA]);
153 if (!ValidName(args[Q_QUOTA])) return(NULL);
154 }
155 return(args);
156}
157
158/* ------------------------- Show Quota Info ------------------------- */
159
160/* Function Name: ShowDefaultQuota
161 * Description: This prints out a default quota for the system.
162 * Arguments: none
163 * Returns: DM_NORMAL.
164 */
165
166int
167ShowDefaultQuota()
168{
169 PrintDefaultQuota(GetDefaultUserQuota(TRUE));
170 return (DM_NORMAL);
171}
172
173/* Function Name: ChangeDefaultQuota
174 * Description: Changes the System Wide default quota.
175 * Arguments: argc, argv - New quota in argv[1].
176 * Returns: DM_NORMAL.
177 */
178
179/*ARGSUSED*/
180int
181ChangeDefaultQuota(argc, argv)
182int argc;
183char *argv[];
184{
185 register int status;
186 char temp_buf[BUFSIZ];
187 static char *newval[] = {
188 "def_quota", NULL, NULL
189 };
190
191 if (!ValidName(argv[1]))
192 return(DM_NORMAL);
193
194 sprintf(temp_buf,"%s %s","Are you sure that you want to",
195 "change the default quota for all new users");
196 if(Confirm(temp_buf)) {
197 newval[1] = argv[1];
14f99d7d 198 if ( (status = do_sms_query("update_value", CountArgs(newval),
199 newval, Scream, NULL)) == SMS_SUCCESS ) {
73c83e3d 200 FreeAndClear(&def_quota, TRUE);
201 def_quota = Strsave(argv[1]);
202 }
203 else
204 com_err(program_name, status, " in update_value");
205 }
206 else
207 Put_message("Quota not changed.");
208
209 return (DM_NORMAL);
210}
211
212/* ------------------------- User Quotas ------------------------- */
213
214/* Function Name: ShowUserQuota
215 * Description: Shows the quota of a user.
216 * Arguments: none
217 * Returns: DM_NORMAL
218 */
219
220int
221ShowUserQuota()
222{
223 struct qelem *top = NULL;
224 register int status;
225 char ** args;
226
227 if ( (args = GetQuotaArgs(FALSE) ) == NULL)
228 return(DM_NORMAL);
229
14f99d7d 230 if ( (status = do_sms_query("get_nfs_quota", CountArgs(args), args,
231 StoreInfo, (char *) &top)) != SMS_SUCCESS)
73c83e3d 232 com_err(program_name, status, " in get_nfs_quota");
233
234 FreeInfo(args); /* done with args free them. */
235 free(args);
236
237 top = QueueTop(top);
238 Loop(top, (void *) PrintQuota);
239
240 FreeQueue(top);
241 return (DM_NORMAL);
242}
243
244/* Function Name: AddUserQuota
245 * Description: Adds a new quota entry to the database.
246 * Arguments: argc, argv - name of the filesystem in argv[1].
247 * Returns: DM_NORMAL
248 */
249
250int
251AddUserQuota()
252{
253 char ** args;
254 register int status;
255
256 if ( (args = GetQuotaArgs(TRUE) ) == NULL)
257 return(DM_NORMAL);
258
14f99d7d 259 if ( (status = do_sms_query("add_nfs_quota", CountArgs(args), args,
260 Scream, (char *) NULL)) != SMS_SUCCESS)
73c83e3d 261 com_err(program_name, status, " in get_nfs_quota");
262
263 FreeInfo(args);
264 free(args);
265 return(DM_NORMAL);
266}
267
268/* Function Name: RealUpdateUser
269 * Description: Performs the actual update of the user information.
270 * Arguments: info - the information nesc. to update the user.
271 * Returns: none.
272 */
273
274static void
275RealUpdateUser(info)
276char ** info;
277{
278 register int status;
279 char temp_buf[BUFSIZ];
280
281 sprintf(temp_buf, "New quota for filesystem %s (in KB)", info[Q_FILESYS]);
282 GetValueFromUser(temp_buf, &info[Q_QUOTA]);
283
14f99d7d 284 if (status = do_sms_query("update_nfs_quota", 3, info,
285 Scream, (char *) NULL) != SMS_SUCCESS) {
73c83e3d 286 com_err(program_name, status, " in update_nfs_quota");
287 sprintf(temp_buf,"Could not perform quota change on %s",
288 info[Q_FILESYS]);
289 Put_message(temp_buf);
290 }
291}
292
293/* Function Name: ChangeUserQuota
294 * Description: This function allows quotas to be updated.
295 * Arguments: none.
296 * Returns: DM_NORMAL.
297 */
298
299int
300ChangeUserQuota()
301{
302 int status;
303 char **args;
304 struct qelem *top = NULL;
305
306 if ( (args = GetQuotaArgs(FALSE) ) == NULL)
307 return(DM_NORMAL);
308
14f99d7d 309 if ( (status = do_sms_query("get_nfs_quota", 2, args,
310 StoreInfo, (char *) &top)) != SMS_SUCCESS)
73c83e3d 311 com_err(program_name, status, " in get_nfs_quota");
312
313 FreeInfo(args); /* done with args, free them. */
314 free(args);
315 top = QueueTop(top);
316 Loop(top, RealUpdateUser);
317
318 FreeQueue(top);
319 return (DM_NORMAL);
320}
321
322/* Function Name: RealRemoveUserQuota
323 * Description: Actually removes the user quota.
324 * Arguments: info - all information about this user quota.
325 * one_item - true if there is only one item in the queue, and
326 * we should confirm.
327 * Returns: none.
328 */
329
330static void
331RealRemoveUserQuota(info, one_item)
332char ** info;
333Bool one_item;
334{
335 register int status;
336 char temp_buf[BUFSIZ];
337
338 sprintf(temp_buf,
339 "Do you really want to delete the user %s's quota on filesystem %s",
340 info[Q_LOGIN], info[Q_FILESYS]);
341
342 if (!one_item || Confirm(temp_buf)) {
14f99d7d 343 if ( (status = do_sms_query("delete_nfs_quota", 2, info,
344 Scream, (char *) NULL)) != SMS_SUCCESS)
73c83e3d 345 com_err(program_name, status, " in delete_nfs_quota");
346 else
347 Put_message("Quota sucessfully removed.");
348 }
349 else
350 Put_message("Aborted.");
351}
352
353/* Function Name: RemoveUserQuota
354 * Description: Removes a users quota on a given filsystem
355 * Arguments: none.
356 * Returns: DM_NORMAL.
357 */
358
359int
360RemoveUserQuota()
361{
362 register int status;
363 char **args;
364 struct qelem *top = NULL;
365
366 if ( (args = GetQuotaArgs(FALSE) ) == NULL)
367 return(DM_NORMAL);
368
14f99d7d 369 if ( (status = do_sms_query("get_nfs_quota", 2, args,
370 StoreInfo, (char *) &top)) != SMS_SUCCESS)
73c83e3d 371 com_err(program_name, status, " in get_nfs_quota");
372
373 FreeInfo(args);
374 free(args);
375 top = QueueTop(top);
376 QueryLoop(top, PrintQuota, RealRemoveUserQuota,
377 "Delete This users quota on filesystem");
378
379 FreeQueue(top);
380 return(DM_NORMAL);
381}
This page took 0.271712 seconds and 5 git commands to generate.