| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: edquota.c,v 1.44 2012/01/30 19:16:36 dholland Exp $ */ | | 1 | /* $NetBSD: edquota.c,v 1.45 2012/01/30 19:18:36 dholland Exp $ */ |
2 | /* | | 2 | /* |
3 | * Copyright (c) 1980, 1990, 1993 | | 3 | * Copyright (c) 1980, 1990, 1993 |
4 | * The Regents of the University of California. All rights reserved. | | 4 | * The Regents of the University of California. All rights reserved. |
5 | * | | 5 | * |
6 | * This code is derived from software contributed to Berkeley by | | 6 | * This code is derived from software contributed to Berkeley by |
7 | * Robert Elz at The University of Melbourne. | | 7 | * Robert Elz at The University of Melbourne. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -31,27 +31,27 @@ | | | @@ -31,27 +31,27 @@ |
31 | * SUCH DAMAGE. | | 31 | * SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #include <sys/cdefs.h> | | 34 | #include <sys/cdefs.h> |
35 | #ifndef lint | | 35 | #ifndef lint |
36 | __COPYRIGHT("@(#) Copyright (c) 1980, 1990, 1993\ | | 36 | __COPYRIGHT("@(#) Copyright (c) 1980, 1990, 1993\ |
37 | The Regents of the University of California. All rights reserved."); | | 37 | The Regents of the University of California. All rights reserved."); |
38 | #endif /* not lint */ | | 38 | #endif /* not lint */ |
39 | | | 39 | |
40 | #ifndef lint | | 40 | #ifndef lint |
41 | #if 0 | | 41 | #if 0 |
42 | static char sccsid[] = "from: @(#)edquota.c 8.3 (Berkeley) 4/27/95"; | | 42 | static char sccsid[] = "from: @(#)edquota.c 8.3 (Berkeley) 4/27/95"; |
43 | #else | | 43 | #else |
44 | __RCSID("$NetBSD: edquota.c,v 1.44 2012/01/30 19:16:36 dholland Exp $"); | | 44 | __RCSID("$NetBSD: edquota.c,v 1.45 2012/01/30 19:18:36 dholland Exp $"); |
45 | #endif | | 45 | #endif |
46 | #endif /* not lint */ | | 46 | #endif /* not lint */ |
47 | | | 47 | |
48 | /* | | 48 | /* |
49 | * Disk quota editor. | | 49 | * Disk quota editor. |
50 | */ | | 50 | */ |
51 | #include <sys/param.h> | | 51 | #include <sys/param.h> |
52 | #include <sys/stat.h> | | 52 | #include <sys/stat.h> |
53 | #include <sys/file.h> | | 53 | #include <sys/file.h> |
54 | #include <sys/wait.h> | | 54 | #include <sys/wait.h> |
55 | #include <sys/queue.h> | | 55 | #include <sys/queue.h> |
56 | #include <sys/types.h> | | 56 | #include <sys/types.h> |
57 | #include <sys/statvfs.h> | | 57 | #include <sys/statvfs.h> |
| @@ -70,27 +70,29 @@ __RCSID("$NetBSD: edquota.c,v 1.44 2012/ | | | @@ -70,27 +70,29 @@ __RCSID("$NetBSD: edquota.c,v 1.44 2012/ |
70 | #include <ctype.h> | | 70 | #include <ctype.h> |
71 | #include <signal.h> | | 71 | #include <signal.h> |
72 | #include <stdbool.h> | | 72 | #include <stdbool.h> |
73 | #include <stdio.h> | | 73 | #include <stdio.h> |
74 | #include <stdlib.h> | | 74 | #include <stdlib.h> |
75 | #include <string.h> | | 75 | #include <string.h> |
76 | #include <unistd.h> | | 76 | #include <unistd.h> |
77 | | | 77 | |
78 | #include "printquota.h" | | 78 | #include "printquota.h" |
79 | #include "quotautil.h" | | 79 | #include "quotautil.h" |
80 | | | 80 | |
81 | #include "pathnames.h" | | 81 | #include "pathnames.h" |
82 | | | 82 | |
| | | 83 | #if 0 |
83 | static const char *quotagroup = QUOTAGROUP; | | 84 | static const char *quotagroup = QUOTAGROUP; |
| | | 85 | #endif |
84 | | | 86 | |
85 | #define MAX_TMPSTR (100+MAXPATHLEN) | | 87 | #define MAX_TMPSTR (100+MAXPATHLEN) |
86 | | | 88 | |
87 | /* flags for quotause */ | | 89 | /* flags for quotause */ |
88 | #define FOUND 0x01 | | 90 | #define FOUND 0x01 |
89 | #define XGRACE 0x02 /* extended grace periods (per-id) */ | | 91 | #define XGRACE 0x02 /* extended grace periods (per-id) */ |
90 | #define DEFAULT 0x04 | | 92 | #define DEFAULT 0x04 |
91 | | | 93 | |
92 | struct quotause { | | 94 | struct quotause { |
93 | struct quotause *next; | | 95 | struct quotause *next; |
94 | long flags; | | 96 | long flags; |
95 | struct quotaval qv[QUOTA_NLIMITS]; | | 97 | struct quotaval qv[QUOTA_NLIMITS]; |
96 | char fsname[MAXPATHLEN + 1]; | | 98 | char fsname[MAXPATHLEN + 1]; |
| @@ -208,49 +210,52 @@ quotalist_create(void) | | | @@ -208,49 +210,52 @@ quotalist_create(void) |
208 | */ | | 210 | */ |
209 | static void | | 211 | static void |
210 | quotalist_destroy(struct quotalist *qlist) | | 212 | quotalist_destroy(struct quotalist *qlist) |
211 | { | | 213 | { |
212 | struct quotause *qup, *nextqup; | | 214 | struct quotause *qup, *nextqup; |
213 | | | 215 | |
214 | for (qup = qlist->head; qup; qup = nextqup) { | | 216 | for (qup = qlist->head; qup; qup = nextqup) { |
215 | nextqup = qup->next; | | 217 | nextqup = qup->next; |
216 | quotause_destroy(qup); | | 218 | quotause_destroy(qup); |
217 | } | | 219 | } |
218 | free(qlist); | | 220 | free(qlist); |
219 | } | | 221 | } |
220 | | | 222 | |
| | | 223 | #if 0 |
221 | static bool | | 224 | static bool |
222 | quotalist_empty(struct quotalist *qlist) | | 225 | quotalist_empty(struct quotalist *qlist) |
223 | { | | 226 | { |
224 | return qlist->head == NULL; | | 227 | return qlist->head == NULL; |
225 | } | | 228 | } |
| | | 229 | #endif |
226 | | | 230 | |
227 | static void | | 231 | static void |
228 | quotalist_append(struct quotalist *qlist, struct quotause *qup) | | 232 | quotalist_append(struct quotalist *qlist, struct quotause *qup) |
229 | { | | 233 | { |
230 | /* should not already be on a list */ | | 234 | /* should not already be on a list */ |
231 | assert(qup->next == NULL); | | 235 | assert(qup->next == NULL); |
232 | | | 236 | |
233 | if (qlist->head == NULL) { | | 237 | if (qlist->head == NULL) { |
234 | qlist->head = qup; | | 238 | qlist->head = qup; |
235 | } else { | | 239 | } else { |
236 | qlist->tail->next = qup; | | 240 | qlist->tail->next = qup; |
237 | } | | 241 | } |
238 | qlist->tail = qup; | | 242 | qlist->tail = qup; |
239 | } | | 243 | } |
240 | | | 244 | |
241 | //////////////////////////////////////////////////////////// | | 245 | //////////////////////////////////////////////////////////// |
242 | // ffs quota v1 | | 246 | // ffs quota v1 |
243 | | | 247 | |
| | | 248 | #if 0 |
244 | static void | | 249 | static void |
245 | putprivs1(uint32_t id, int idtype, struct quotause *qup) | | 250 | putprivs1(uint32_t id, int idtype, struct quotause *qup) |
246 | { | | 251 | { |
247 | struct dqblk dqblk; | | 252 | struct dqblk dqblk; |
248 | int fd; | | 253 | int fd; |
249 | | | 254 | |
250 | quotavals_to_dqblk(&qup->qv[QUOTA_LIMIT_BLOCK], | | 255 | quotavals_to_dqblk(&qup->qv[QUOTA_LIMIT_BLOCK], |
251 | &qup->qv[QUOTA_LIMIT_FILE], | | 256 | &qup->qv[QUOTA_LIMIT_FILE], |
252 | &dqblk); | | 257 | &dqblk); |
253 | assert((qup->flags & DEFAULT) == 0); | | 258 | assert((qup->flags & DEFAULT) == 0); |
254 | | | 259 | |
255 | if ((fd = open(qup->qfname, O_WRONLY)) < 0) { | | 260 | if ((fd = open(qup->qfname, O_WRONLY)) < 0) { |
256 | warnx("open `%s'", qup->qfname); | | 261 | warnx("open `%s'", qup->qfname); |
| @@ -322,26 +327,27 @@ getprivs1(long id, int idtype, const cha | | | @@ -322,26 +327,27 @@ getprivs1(long id, int idtype, const cha |
322 | warn("read error in `%s'", qfpathname); | | 327 | warn("read error in `%s'", qfpathname); |
323 | close(fd); | | 328 | close(fd); |
324 | quotause_destroy(qup); | | 329 | quotause_destroy(qup); |
325 | return NULL; | | 330 | return NULL; |
326 | } | | 331 | } |
327 | close(fd); | | 332 | close(fd); |
328 | qup->qfname = qfpathname; | | 333 | qup->qfname = qfpathname; |
329 | endfsent(); | | 334 | endfsent(); |
330 | dqblk_to_quotavals(&dqblk, | | 335 | dqblk_to_quotavals(&dqblk, |
331 | &qup->qv[QUOTA_LIMIT_BLOCK], | | 336 | &qup->qv[QUOTA_LIMIT_BLOCK], |
332 | &qup->qv[QUOTA_LIMIT_FILE]); | | 337 | &qup->qv[QUOTA_LIMIT_FILE]); |
333 | return qup; | | 338 | return qup; |
334 | } | | 339 | } |
| | | 340 | #endif |
335 | | | 341 | |
336 | //////////////////////////////////////////////////////////// | | 342 | //////////////////////////////////////////////////////////// |
337 | // ffs quota v2 | | 343 | // ffs quota v2 |
338 | | | 344 | |
339 | static int | | 345 | static int |
340 | dogetprivs2(struct quotahandle *qh, int idtype, id_t id, int defaultq, | | 346 | dogetprivs2(struct quotahandle *qh, int idtype, id_t id, int defaultq, |
341 | int objtype, struct quotause *qup) | | 347 | int objtype, struct quotause *qup) |
342 | { | | 348 | { |
343 | struct quotakey qk; | | 349 | struct quotakey qk; |
344 | | | 350 | |
345 | qk.qk_idtype = idtype; | | 351 | qk.qk_idtype = idtype; |
346 | qk.qk_id = defaultq ? QUOTA_DEFAULTID : id; | | 352 | qk.qk_id = defaultq ? QUOTA_DEFAULTID : id; |
347 | qk.qk_objtype = objtype; | | 353 | qk.qk_objtype = objtype; |
| @@ -477,55 +483,59 @@ getprivs(long id, int defaultq, int idty | | | @@ -477,55 +483,59 @@ getprivs(long id, int defaultq, int idty |
477 | * Note: we cannot warn unconditionally here | | 483 | * Note: we cannot warn unconditionally here |
478 | * because this case apparently includes "no | | 484 | * because this case apparently includes "no |
479 | * quota entry on this volume" and that causes | | 485 | * quota entry on this volume" and that causes |
480 | * the atf tests to fail. Bletch. | | 486 | * the atf tests to fail. Bletch. |
481 | */ | | 487 | */ |
482 | /*return NULL;*/ | | 488 | /*return NULL;*/ |
483 | /*warnx("getprivs2 failed");*/ | | 489 | /*warnx("getprivs2 failed");*/ |
484 | continue; | | 490 | continue; |
485 | } | | 491 | } |
486 | | | 492 | |
487 | quotalist_append(qlist, qup); | | 493 | quotalist_append(qlist, qup); |
488 | } | | 494 | } |
489 | | | 495 | |
| | | 496 | #if 0 |
490 | if (filesys && quotalist_empty(qlist)) { | | 497 | if (filesys && quotalist_empty(qlist)) { |
491 | if (defaultq) | | 498 | if (defaultq) |
492 | errx(1, "no default quota for version 1"); | | 499 | errx(1, "no default quota for version 1"); |
493 | /* if we get there, filesys is not mounted. try the old way */ | | 500 | /* if we get there, filesys is not mounted. try the old way */ |
494 | qup = getprivs1(id, idtype, filesys); | | 501 | qup = getprivs1(id, idtype, filesys); |
495 | if (qup == NULL) { | | 502 | if (qup == NULL) { |
496 | /* XXX. see above */ | | 503 | /* XXX. see above */ |
497 | /*return NULL;*/ | | 504 | /*return NULL;*/ |
498 | /*warnx("getprivs1 failed");*/ | | 505 | /*warnx("getprivs1 failed");*/ |
499 | return qlist; | | 506 | return qlist; |
500 | } | | 507 | } |
501 | quotalist_append(qlist, qup); | | 508 | quotalist_append(qlist, qup); |
502 | } | | 509 | } |
| | | 510 | #endif |
503 | return qlist; | | 511 | return qlist; |
504 | } | | 512 | } |
505 | | | 513 | |
506 | /* | | 514 | /* |
507 | * Store the requested quota information. | | 515 | * Store the requested quota information. |
508 | */ | | 516 | */ |
509 | static void | | 517 | static void |
510 | putprivs(uint32_t id, int idtype, struct quotalist *qlist) | | 518 | putprivs(uint32_t id, int idtype, struct quotalist *qlist) |
511 | { | | 519 | { |
512 | struct quotause *qup; | | 520 | struct quotause *qup; |
513 | | | 521 | |
514 | for (qup = qlist->head; qup; qup = qup->next) { | | 522 | for (qup = qlist->head; qup; qup = qup->next) { |
515 | if (qup->qfname == NULL) | | 523 | if (qup->qfname == NULL) |
516 | putprivs2(id, idtype, qup); | | 524 | putprivs2(id, idtype, qup); |
| | | 525 | #if 0 |
517 | else | | 526 | else |
518 | putprivs1(id, idtype, qup); | | 527 | putprivs1(id, idtype, qup); |
| | | 528 | #endif |
519 | } | | 529 | } |
520 | } | | 530 | } |
521 | | | 531 | |
522 | static void | | 532 | static void |
523 | clearpriv(int argc, char **argv, const char *filesys, int idtype) | | 533 | clearpriv(int argc, char **argv, const char *filesys, int idtype) |
524 | { | | 534 | { |
525 | struct statvfs *fst; | | 535 | struct statvfs *fst; |
526 | int nfst, i; | | 536 | int nfst, i; |
527 | int id; | | 537 | int id; |
528 | id_t *ids; | | 538 | id_t *ids; |
529 | unsigned nids, maxids, j; | | 539 | unsigned nids, maxids, j; |
530 | struct quotahandle *qh; | | 540 | struct quotahandle *qh; |
531 | struct quotakey qk; | | 541 | struct quotakey qk; |