| 1 | /*
|
|---|
| 2 | * Store default Quotas in a specified quota record
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright (C) Stefan (metze) Metzmacher 2003
|
|---|
| 5 | *
|
|---|
| 6 | * This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | * it under the terms of the GNU General Public License as published by
|
|---|
| 8 | * the Free Software Foundation; either version 3 of the License, or
|
|---|
| 9 | * (at your option) any later version.
|
|---|
| 10 | *
|
|---|
| 11 | * This program is distributed in the hope that it will be useful,
|
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | * GNU General Public License for more details.
|
|---|
| 15 | *
|
|---|
| 16 | * You should have received a copy of the GNU General Public License
|
|---|
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | /*
|
|---|
| 21 | * This module allows the default quota values,
|
|---|
| 22 | * in the windows explorer GUI, to be stored on a samba server.
|
|---|
| 23 | * The problem is that linux filesystems only store quotas
|
|---|
| 24 | * for users and groups, but no default quotas.
|
|---|
| 25 | *
|
|---|
| 26 | * Samba returns NO_LIMIT as the default quotas by default
|
|---|
| 27 | * and refuses to update them.
|
|---|
| 28 | *
|
|---|
| 29 | * With this module you can store the default quotas that are reported to
|
|---|
| 30 | * a windows client, in the quota record of a user. By default the root user
|
|---|
| 31 | * is taken because quota limits for root are typically not enforced.
|
|---|
| 32 | *
|
|---|
| 33 | * This module takes 2 parametric parameters in smb.conf:
|
|---|
| 34 | * (the default prefix for them is 'default_quota',
|
|---|
| 35 | * it can be overwrittem when you load the module in
|
|---|
| 36 | * the 'vfs objects' parameter like this:
|
|---|
| 37 | * vfs objects = default_quota:myprefix)
|
|---|
| 38 | *
|
|---|
| 39 | * "<myprefix>:uid" parameter takes a integer argument,
|
|---|
| 40 | * it specifies the uid of the quota record, that will be taken for
|
|---|
| 41 | * storing the default USER-quotas.
|
|---|
| 42 | *
|
|---|
| 43 | * - default value: '0' (for root user)
|
|---|
| 44 | * - e.g.: default_quota:uid = 65534
|
|---|
| 45 | *
|
|---|
| 46 | * "<myprefix>:uid nolimit" parameter takes a boolean argument,
|
|---|
| 47 | * it specifies if we should report the stored default quota values,
|
|---|
| 48 | * also for the user record, or if you should just report NO_LIMIT
|
|---|
| 49 | * to the windows client for the user specified by the "<prefix>:uid" parameter.
|
|---|
| 50 | *
|
|---|
| 51 | * - default value: yes (that means to report NO_LIMIT)
|
|---|
| 52 | * - e.g.: default_quota:uid nolimit = no
|
|---|
| 53 | *
|
|---|
| 54 | * "<myprefix>:gid" parameter takes a integer argument,
|
|---|
| 55 | * it's just like "<prefix>:uid" but for group quotas.
|
|---|
| 56 | * (NOTE: group quotas are not supported from the windows explorer!)
|
|---|
| 57 | *
|
|---|
| 58 | * - default value: '0' (for root group)
|
|---|
| 59 | * - e.g.: default_quota:gid = 65534
|
|---|
| 60 | *
|
|---|
| 61 | * "<myprefix>:gid nolimit" parameter takes a boolean argument,
|
|---|
| 62 | * it's just like "<prefix>:uid nolimit" but for group quotas.
|
|---|
| 63 | * (NOTE: group quotas are not supported from the windows explorer!)
|
|---|
| 64 | *
|
|---|
| 65 | * - default value: yes (that means to report NO_LIMIT)
|
|---|
| 66 | * - e.g.: default_quota:uid nolimit = no
|
|---|
| 67 | *
|
|---|
| 68 | */
|
|---|
| 69 |
|
|---|
| 70 | #include "includes.h"
|
|---|
| 71 | #include "smbd/smbd.h"
|
|---|
| 72 |
|
|---|
| 73 | #undef DBGC_CLASS
|
|---|
| 74 | #define DBGC_CLASS DBGC_QUOTA
|
|---|
| 75 |
|
|---|
| 76 | #define DEFAULT_QUOTA_NAME "default_quota"
|
|---|
| 77 |
|
|---|
| 78 | #define DEFAULT_QUOTA_UID_DEFAULT 0
|
|---|
| 79 | #define DEFAULT_QUOTA_UID_NOLIMIT_DEFAULT True
|
|---|
| 80 | #define DEFAULT_QUOTA_GID_DEFAULT 0
|
|---|
| 81 | #define DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT True
|
|---|
| 82 |
|
|---|
| 83 | #define DEFAULT_QUOTA_UID(handle) \
|
|---|
| 84 | (uid_t)lp_parm_int(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"uid",DEFAULT_QUOTA_UID_DEFAULT)
|
|---|
| 85 |
|
|---|
| 86 | #define DEFAULT_QUOTA_UID_NOLIMIT(handle) \
|
|---|
| 87 | lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"uid nolimit",DEFAULT_QUOTA_UID_NOLIMIT_DEFAULT)
|
|---|
| 88 |
|
|---|
| 89 | #define DEFAULT_QUOTA_GID(handle) \
|
|---|
| 90 | (gid_t)lp_parm_int(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid",DEFAULT_QUOTA_GID_DEFAULT)
|
|---|
| 91 |
|
|---|
| 92 | #define DEFAULT_QUOTA_GID_NOLIMIT(handle) \
|
|---|
| 93 | lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid nolimit",DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT)
|
|---|
| 94 |
|
|---|
| 95 | static int default_quota_get_quota(vfs_handle_struct *handle, const char *path,
|
|---|
| 96 | enum SMB_QUOTA_TYPE qtype, unid_t id,
|
|---|
| 97 | SMB_DISK_QUOTA *dq)
|
|---|
| 98 | {
|
|---|
| 99 | int ret = -1;
|
|---|
| 100 |
|
|---|
| 101 | if ((ret = SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, dq)) != 0) {
|
|---|
| 102 | return ret;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | switch (qtype) {
|
|---|
| 106 | case SMB_USER_QUOTA_TYPE:
|
|---|
| 107 | /* we use id.uid == 0 for default quotas */
|
|---|
| 108 | if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
|
|---|
| 109 | DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
|
|---|
| 110 | SMB_QUOTAS_SET_NO_LIMIT(dq);
|
|---|
| 111 | }
|
|---|
| 112 | break;
|
|---|
| 113 | #ifdef HAVE_GROUP_QUOTA
|
|---|
| 114 | case SMB_GROUP_QUOTA_TYPE:
|
|---|
| 115 | /* we use id.gid == 0 for default quotas */
|
|---|
| 116 | if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
|
|---|
| 117 | DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
|
|---|
| 118 | SMB_QUOTAS_SET_NO_LIMIT(dq);
|
|---|
| 119 | }
|
|---|
| 120 | break;
|
|---|
| 121 | #endif /* HAVE_GROUP_QUOTA */
|
|---|
| 122 | case SMB_USER_FS_QUOTA_TYPE:
|
|---|
| 123 | {
|
|---|
| 124 | unid_t qid;
|
|---|
| 125 | uint32_t qflags = dq->qflags;
|
|---|
| 126 | qid.uid = DEFAULT_QUOTA_UID(handle);
|
|---|
| 127 | SMB_VFS_NEXT_GET_QUOTA(
|
|---|
| 128 | handle, path, SMB_USER_QUOTA_TYPE, qid, dq);
|
|---|
| 129 | dq->qflags = qflags;
|
|---|
| 130 | }
|
|---|
| 131 | break;
|
|---|
| 132 | #ifdef HAVE_GROUP_QUOTA
|
|---|
| 133 | case SMB_GROUP_FS_QUOTA_TYPE:
|
|---|
| 134 | {
|
|---|
| 135 | unid_t qid;
|
|---|
| 136 | uint32_t qflags = dq->qflags;
|
|---|
| 137 | qid.gid = DEFAULT_QUOTA_GID(handle);
|
|---|
| 138 | SMB_VFS_NEXT_GET_QUOTA(handle, path,
|
|---|
| 139 | SMB_GROUP_QUOTA_TYPE,
|
|---|
| 140 | qid, dq);
|
|---|
| 141 | dq->qflags = qflags;
|
|---|
| 142 | }
|
|---|
| 143 | break;
|
|---|
| 144 | #endif /* HAVE_GROUP_QUOTA */
|
|---|
| 145 | default:
|
|---|
| 146 | errno = ENOSYS;
|
|---|
| 147 | return -1;
|
|---|
| 148 | break;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | return ret;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | static int default_quota_set_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq)
|
|---|
| 155 | {
|
|---|
| 156 | int ret = -1;
|
|---|
| 157 |
|
|---|
| 158 | switch (qtype) {
|
|---|
| 159 | case SMB_USER_QUOTA_TYPE:
|
|---|
| 160 | /* we use id.uid == 0 for default quotas */
|
|---|
| 161 | if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
|
|---|
| 162 | DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
|
|---|
| 163 | return -1;
|
|---|
| 164 | }
|
|---|
| 165 | break;
|
|---|
| 166 | #ifdef HAVE_GROUP_QUOTA
|
|---|
| 167 | case SMB_GROUP_QUOTA_TYPE:
|
|---|
| 168 | /* we use id.gid == 0 for default quotas */
|
|---|
| 169 | if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
|
|---|
| 170 | DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
|
|---|
| 171 | return -1;
|
|---|
| 172 | }
|
|---|
| 173 | break;
|
|---|
| 174 | #endif /* HAVE_GROUP_QUOTA */
|
|---|
| 175 | case SMB_USER_FS_QUOTA_TYPE:
|
|---|
| 176 | break;
|
|---|
| 177 | #ifdef HAVE_GROUP_QUOTA
|
|---|
| 178 | case SMB_GROUP_FS_QUOTA_TYPE:
|
|---|
| 179 | break;
|
|---|
| 180 | #endif /* HAVE_GROUP_QUOTA */
|
|---|
| 181 | default:
|
|---|
| 182 | errno = ENOSYS;
|
|---|
| 183 | return -1;
|
|---|
| 184 | break;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | if ((ret=SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, dq))!=0) {
|
|---|
| 188 | return ret;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | switch (qtype) {
|
|---|
| 192 | case SMB_USER_QUOTA_TYPE:
|
|---|
| 193 | break;
|
|---|
| 194 | #ifdef HAVE_GROUP_QUOTA
|
|---|
| 195 | case SMB_GROUP_QUOTA_TYPE:
|
|---|
| 196 | break;
|
|---|
| 197 | #endif /* HAVE_GROUP_QUOTA */
|
|---|
| 198 | case SMB_USER_FS_QUOTA_TYPE:
|
|---|
| 199 | {
|
|---|
| 200 | unid_t qid;
|
|---|
| 201 | qid.uid = DEFAULT_QUOTA_UID(handle);
|
|---|
| 202 | ret = SMB_VFS_NEXT_SET_QUOTA(handle, SMB_USER_QUOTA_TYPE, qid, dq);
|
|---|
| 203 | }
|
|---|
| 204 | break;
|
|---|
| 205 | #ifdef HAVE_GROUP_QUOTA
|
|---|
| 206 | case SMB_GROUP_FS_QUOTA_TYPE:
|
|---|
| 207 | {
|
|---|
| 208 | unid_t qid;
|
|---|
| 209 | qid.gid = DEFAULT_QUOTA_GID(handle);
|
|---|
| 210 | ret = SMB_VFS_NEXT_SET_QUOTA(handle, SMB_GROUP_QUOTA_TYPE, qid, dq);
|
|---|
| 211 | }
|
|---|
| 212 | break;
|
|---|
| 213 | #endif /* HAVE_GROUP_QUOTA */
|
|---|
| 214 | default:
|
|---|
| 215 | errno = ENOSYS;
|
|---|
| 216 | return -1;
|
|---|
| 217 | break;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | return ret;
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | static struct vfs_fn_pointers vfs_default_quota_fns = {
|
|---|
| 224 | .get_quota_fn = default_quota_get_quota,
|
|---|
| 225 | .set_quota_fn = default_quota_set_quota
|
|---|
| 226 | };
|
|---|
| 227 |
|
|---|
| 228 | NTSTATUS vfs_default_quota_init(void);
|
|---|
| 229 | NTSTATUS vfs_default_quota_init(void)
|
|---|
| 230 | {
|
|---|
| 231 | return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, DEFAULT_QUOTA_NAME,
|
|---|
| 232 | &vfs_default_quota_fns);
|
|---|
| 233 | }
|
|---|