| @@ -1,48 +1,48 @@ | | | @@ -1,48 +1,48 @@ |
1 | $NetBSD: patch-at,v 1.5 2011/03/26 18:45:52 bouyer Exp $ | | 1 | $NetBSD: patch-at,v 1.6 2011/08/30 15:09:23 bouyer Exp $ |
2 | | | 2 | |
3 | --- etc/afpd/quota.c.orig 2011-03-24 15:43:48.000000000 +0100 | | 3 | --- etc/afpd/quota.c.orig 2011-03-24 15:43:48.000000000 +0100 |
4 | +++ etc/afpd/quota.c 2011-03-24 17:56:34.000000000 +0100 | | 4 | +++ etc/afpd/quota.c 2011-03-24 17:56:34.000000000 +0100 |
5 | @@ -47,6 +47,96 @@ | | 5 | @@ -47,6 +47,96 @@ |
6 | #include "volume.h" | | 6 | #include "volume.h" |
7 | #include "unix.h" | | 7 | #include "unix.h" |
8 | | | 8 | |
9 | +#ifdef HAVE_LIBQUOTA | | 9 | +#ifdef HAVE_LIBQUOTA |
10 | +#include <quota/quota.h> | | 10 | +#include <quota/quota.h> |
11 | + | | 11 | + |
12 | +static int | | 12 | +static int |
13 | +getfreespace(struct vol *vol, VolSpace *bfree, VolSpace *btotal, | | 13 | +getfreespace(struct vol *vol, VolSpace *bfree, VolSpace *btotal, |
14 | + uid_t uid, const char *classq) | | 14 | + uid_t ouruid, uid_t quid, const char *classq) |
15 | +{ | | 15 | +{ |
16 | + int retq; | | 16 | + int retq; |
17 | + struct ufs_quota_entry ufsq[QUOTA_NLIMITS]; | | 17 | + struct ufs_quota_entry ufsq[QUOTA_NLIMITS]; |
18 | + time_t now; | | 18 | + time_t now; |
19 | + | | 19 | + |
20 | + if (time(&now) == -1) { | | 20 | + if (time(&now) == -1) { |
21 | + LOG(log_info, logtype_afpd, "time(): %s", | | 21 | + LOG(log_info, logtype_afpd, "time(): %s", |
22 | + strerror(errno)); | | 22 | + strerror(errno)); |
23 | + return -1; | | 23 | + return -1; |
24 | + } | | 24 | + } |
25 | + | | 25 | + |
26 | + if ( seteuid( getuid() ) != 0 ) { | | 26 | + if ( seteuid( getuid() ) != 0 ) { |
27 | + LOG(log_info, logtype_afpd, "seteuid(): %s", | | 27 | + LOG(log_info, logtype_afpd, "seteuid(): %s", |
28 | + strerror(errno)); | | 28 | + strerror(errno)); |
29 | + return -1; | | 29 | + return -1; |
30 | + } | | 30 | + } |
31 | + if ((retq = getfsquota(vol->v_path, ufsq, uid, classq)) < 0) { | | 31 | + if ((retq = getfsquota(vol->v_path, ufsq, quid, classq)) < 0) { |
32 | + LOG(log_info, logtype_afpd, "getfsquota(%s, %s): %s", | | 32 | + LOG(log_info, logtype_afpd, "getfsquota(%s, %s): %s", |
33 | + vol->v_path, classq, strerror(errno)); | | 33 | + vol->v_path, classq, strerror(errno)); |
34 | + } | | 34 | + } |
35 | + seteuid( uid ); | | 35 | + seteuid( ouruid ); |
36 | + if (retq < 1) | | 36 | + if (retq < 1) |
37 | + return retq; | | 37 | + return retq; |
38 | + | | 38 | + |
39 | + switch(QL_STATUS(quota_check_limit(ufsq[QUOTA_LIMIT_BLOCK].ufsqe_cur, 1, | | 39 | + switch(QL_STATUS(quota_check_limit(ufsq[QUOTA_LIMIT_BLOCK].ufsqe_cur, 1, |
40 | + ufsq[QUOTA_LIMIT_BLOCK].ufsqe_softlimit, | | 40 | + ufsq[QUOTA_LIMIT_BLOCK].ufsqe_softlimit, |
41 | + ufsq[QUOTA_LIMIT_BLOCK].ufsqe_hardlimit, | | 41 | + ufsq[QUOTA_LIMIT_BLOCK].ufsqe_hardlimit, |
42 | + ufsq[QUOTA_LIMIT_BLOCK].ufsqe_time, now))) { | | 42 | + ufsq[QUOTA_LIMIT_BLOCK].ufsqe_time, now))) { |
43 | + case QL_S_DENY_HARD: | | 43 | + case QL_S_DENY_HARD: |
44 | + case QL_S_DENY_GRACE: | | 44 | + case QL_S_DENY_GRACE: |
45 | + *bfree = 0; | | 45 | + *bfree = 0; |
46 | + *btotal = dbtob(ufsq[QUOTA_LIMIT_BLOCK].ufsqe_cur); | | 46 | + *btotal = dbtob(ufsq[QUOTA_LIMIT_BLOCK].ufsqe_cur); |
47 | + break; | | 47 | + break; |
48 | + default: | | 48 | + default: |
| @@ -50,32 +50,32 @@ $NetBSD: patch-at,v 1.5 2011/03/26 18:45 | | | @@ -50,32 +50,32 @@ $NetBSD: patch-at,v 1.5 2011/03/26 18:45 |
50 | + ufsq[QUOTA_LIMIT_BLOCK].ufsqe_cur); | | 50 | + ufsq[QUOTA_LIMIT_BLOCK].ufsqe_cur); |
51 | + *btotal = dbtob(ufsq[QUOTA_LIMIT_BLOCK].ufsqe_hardlimit); | | 51 | + *btotal = dbtob(ufsq[QUOTA_LIMIT_BLOCK].ufsqe_hardlimit); |
52 | + break; | | 52 | + break; |
53 | + } | | 53 | + } |
54 | + return 1; | | 54 | + return 1; |
55 | +} | | 55 | +} |
56 | + | | 56 | + |
57 | +int uquota_getvolspace( struct vol *vol, VolSpace *bfree, VolSpace *btotal, const u_int32_t bsize) | | 57 | +int uquota_getvolspace( struct vol *vol, VolSpace *bfree, VolSpace *btotal, const u_int32_t bsize) |
58 | +{ | | 58 | +{ |
59 | + int uretq, gretq; | | 59 | + int uretq, gretq; |
60 | + VolSpace ubfree, ubtotal; | | 60 | + VolSpace ubfree, ubtotal; |
61 | + VolSpace gbfree, gbtotal; | | 61 | + VolSpace gbfree, gbtotal; |
62 | + | | 62 | + |
63 | + uretq = getfreespace(vol, &ubfree, &ubtotal, | | 63 | + uretq = getfreespace(vol, &ubfree, &ubtotal, uuid, |
64 | + uuid, QUOTADICT_CLASS_USER); | | 64 | + uuid, QUOTADICT_CLASS_USER); |
65 | + LOG(log_info, logtype_afpd, "getfsquota(%s): %d %d", | | 65 | + LOG(log_info, logtype_afpd, "getfsquota(%s): %d %d", |
66 | + vol->v_path, (int)ubfree, (int)ubtotal); | | 66 | + vol->v_path, (int)ubfree, (int)ubtotal); |
67 | + if (ngroups >= 1) { | | 67 | + if (ngroups >= 1) { |
68 | + gretq = getfreespace(vol, &ubfree, &ubtotal, | | 68 | + gretq = getfreespace(vol, &ubfree, &ubtotal, uuid, |
69 | + groups[0], QUOTADICT_CLASS_GROUP); | | 69 | + groups[0], QUOTADICT_CLASS_GROUP); |
70 | + } else | | 70 | + } else |
71 | + gretq = -1; | | 71 | + gretq = -1; |
72 | + if (uretq < 1 && gretq < 1) { /* no quota for this fs */ | | 72 | + if (uretq < 1 && gretq < 1) { /* no quota for this fs */ |
73 | + return AFPERR_PARAM; | | 73 | + return AFPERR_PARAM; |
74 | + } | | 74 | + } |
75 | + if (uretq < 1) { | | 75 | + if (uretq < 1) { |
76 | + /* use group quotas */ | | 76 | + /* use group quotas */ |
77 | + *bfree = gbfree; | | 77 | + *bfree = gbfree; |
78 | + *btotal = gbtotal; | | 78 | + *btotal = gbtotal; |
79 | + } else if (gretq < 1) { | | 79 | + } else if (gretq < 1) { |
80 | + /* use user quotas */ | | 80 | + /* use user quotas */ |
81 | + *bfree = ubfree; | | 81 | + *bfree = ubfree; |