libcli/smb: Allow smb2cli_validate_negotiate_info_done() to ignore NT_STATUS_INVALID_...
[Samba.git] / source3 / modules / vfs_default_quota.c
blob326eb8c8f0a79345be6d088fc17ecff3fe1a7908
1 /*
2 * Store default Quotas in a specified quota record
4 * Copyright (C) Stefan (metze) Metzmacher 2003
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.
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.
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/>.
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.
26 * Samba returns NO_LIMIT as the default quotas by default
27 * and refuses to update them.
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.
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)
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.
43 * - default value: '0' (for root user)
44 * - e.g.: default_quota:uid = 65534
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.
51 * - default value: yes (that means to report NO_LIMIT)
52 * - e.g.: default_quota:uid nolimit = no
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!)
58 * - default value: '0' (for root group)
59 * - e.g.: default_quota:gid = 65534
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!)
65 * - default value: yes (that means to report NO_LIMIT)
66 * - e.g.: default_quota:uid nolimit = no
70 #include "includes.h"
71 #include "smbd/smbd.h"
73 #undef DBGC_CLASS
74 #define DBGC_CLASS DBGC_QUOTA
76 #define DEFAULT_QUOTA_NAME "default_quota"
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
83 #define DEFAULT_QUOTA_UID(handle) \
84 (uid_t)lp_parm_int(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"uid",DEFAULT_QUOTA_UID_DEFAULT)
86 #define DEFAULT_QUOTA_UID_NOLIMIT(handle) \
87 lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"uid nolimit",DEFAULT_QUOTA_UID_NOLIMIT_DEFAULT)
89 #define DEFAULT_QUOTA_GID(handle) \
90 (gid_t)lp_parm_int(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid",DEFAULT_QUOTA_GID_DEFAULT)
92 #define DEFAULT_QUOTA_GID_NOLIMIT(handle) \
93 lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid nolimit",DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT)
95 static int default_quota_get_quota(vfs_handle_struct *handle,
96 const struct smb_filename *smb_fname,
97 enum SMB_QUOTA_TYPE qtype,
98 unid_t id,
99 SMB_DISK_QUOTA *dq)
101 int ret = -1;
103 if ((ret = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname,
104 qtype, id, dq)) != 0) {
105 return ret;
108 switch (qtype) {
109 case SMB_USER_QUOTA_TYPE:
110 /* we use id.uid == 0 for default quotas */
111 if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
112 DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
113 SMB_QUOTAS_SET_NO_LIMIT(dq);
115 break;
116 #ifdef HAVE_GROUP_QUOTA
117 case SMB_GROUP_QUOTA_TYPE:
118 /* we use id.gid == 0 for default quotas */
119 if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
120 DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
121 SMB_QUOTAS_SET_NO_LIMIT(dq);
123 break;
124 #endif /* HAVE_GROUP_QUOTA */
125 case SMB_USER_FS_QUOTA_TYPE:
127 unid_t qid;
128 uint32_t qflags = dq->qflags;
129 qid.uid = DEFAULT_QUOTA_UID(handle);
130 SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname,
131 SMB_USER_QUOTA_TYPE, qid, dq);
132 dq->qflags = qflags;
134 break;
135 #ifdef HAVE_GROUP_QUOTA
136 case SMB_GROUP_FS_QUOTA_TYPE:
138 unid_t qid;
139 uint32_t qflags = dq->qflags;
140 qid.gid = DEFAULT_QUOTA_GID(handle);
141 SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname,
142 SMB_GROUP_QUOTA_TYPE,
143 qid, dq);
144 dq->qflags = qflags;
146 break;
147 #endif /* HAVE_GROUP_QUOTA */
148 default:
149 errno = ENOSYS;
150 return -1;
151 break;
154 return ret;
157 static int default_quota_set_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq)
159 int ret = -1;
161 switch (qtype) {
162 case SMB_USER_QUOTA_TYPE:
163 /* we use id.uid == 0 for default quotas */
164 if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
165 DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
166 return -1;
168 break;
169 #ifdef HAVE_GROUP_QUOTA
170 case SMB_GROUP_QUOTA_TYPE:
171 /* we use id.gid == 0 for default quotas */
172 if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
173 DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
174 return -1;
176 break;
177 #endif /* HAVE_GROUP_QUOTA */
178 case SMB_USER_FS_QUOTA_TYPE:
179 break;
180 #ifdef HAVE_GROUP_QUOTA
181 case SMB_GROUP_FS_QUOTA_TYPE:
182 break;
183 #endif /* HAVE_GROUP_QUOTA */
184 default:
185 errno = ENOSYS;
186 return -1;
187 break;
190 if ((ret=SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, dq))!=0) {
191 return ret;
194 switch (qtype) {
195 case SMB_USER_QUOTA_TYPE:
196 break;
197 #ifdef HAVE_GROUP_QUOTA
198 case SMB_GROUP_QUOTA_TYPE:
199 break;
200 #endif /* HAVE_GROUP_QUOTA */
201 case SMB_USER_FS_QUOTA_TYPE:
203 unid_t qid;
204 qid.uid = DEFAULT_QUOTA_UID(handle);
205 ret = SMB_VFS_NEXT_SET_QUOTA(handle, SMB_USER_QUOTA_TYPE, qid, dq);
207 break;
208 #ifdef HAVE_GROUP_QUOTA
209 case SMB_GROUP_FS_QUOTA_TYPE:
211 unid_t qid;
212 qid.gid = DEFAULT_QUOTA_GID(handle);
213 ret = SMB_VFS_NEXT_SET_QUOTA(handle, SMB_GROUP_QUOTA_TYPE, qid, dq);
215 break;
216 #endif /* HAVE_GROUP_QUOTA */
217 default:
218 errno = ENOSYS;
219 return -1;
220 break;
223 return ret;
226 static struct vfs_fn_pointers vfs_default_quota_fns = {
227 .get_quota_fn = default_quota_get_quota,
228 .set_quota_fn = default_quota_set_quota
231 static_decl_vfs;
232 NTSTATUS vfs_default_quota_init(TALLOC_CTX *ctx)
234 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, DEFAULT_QUOTA_NAME,
235 &vfs_default_quota_fns);