r23620: Convert set_nt_acl to return NTSTATUS. Also fix the chown
[Samba/bb.git] / source3 / modules / vfs_default_quota.c
blob772c91dc47310e203c8dadece08bf53640c90043
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 2 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, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * This module allows the default quota values,
23 * in the windows explorer GUI, to be stored on a samba server.
24 * The problem is that linux filesystems only store quotas
25 * for users and groups, but no default quotas.
27 * Samba returns NO_LIMIT as the default quotas by default
28 * and refuses to update them.
30 * With this module you can store the default quotas that are reported to
31 * a windows client, in the quota record of a user. By default the root user
32 * is taken because quota limits for root are typically not enforced.
34 * This module takes 2 parametric parameters in smb.conf:
35 * (the default prefix for them is 'default_quota',
36 * it can be overwrittem when you load the module in
37 * the 'vfs objects' parameter like this:
38 * vfs objects = default_quota:myprefix)
40 * "<myprefix>:uid" parameter takes a integer argument,
41 * it specifies the uid of the quota record, that will be taken for
42 * storing the default USER-quotas.
44 * - default value: '0' (for root user)
45 * - e.g.: default_quota:uid = 65534
47 * "<myprefix>:uid nolimit" parameter takes a boolean argument,
48 * it specifies if we should report the stored default quota values,
49 * also for the user record, or if you should just report NO_LIMIT
50 * to the windows client for the user specified by the "<prefix>:uid" parameter.
52 * - default value: yes (that means to report NO_LIMIT)
53 * - e.g.: default_quota:uid nolimit = no
55 * "<myprefix>:gid" parameter takes a integer argument,
56 * it's just like "<prefix>:uid" but for group quotas.
57 * (NOTE: group quotas are not supported from the windows explorer!)
59 * - default value: '0' (for root group)
60 * - e.g.: default_quota:gid = 65534
62 * "<myprefix>:gid nolimit" parameter takes a boolean argument,
63 * it's just like "<prefix>:uid nolimit" but for group quotas.
64 * (NOTE: group quotas are not supported from the windows explorer!)
66 * - default value: yes (that means to report NO_LIMIT)
67 * - e.g.: default_quota:uid nolimit = no
71 #include "includes.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, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq)
97 int ret = -1;
99 if ((ret=SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, dq))!=0) {
100 return ret;
103 switch (qtype) {
104 case SMB_USER_QUOTA_TYPE:
105 /* we use id.uid == 0 for default quotas */
106 if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
107 DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
108 SMB_QUOTAS_SET_NO_LIMIT(dq);
110 break;
111 #ifdef HAVE_GROUP_QUOTA
112 case SMB_GROUP_QUOTA_TYPE:
113 /* we use id.gid == 0 for default quotas */
114 if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
115 DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
116 SMB_QUOTAS_SET_NO_LIMIT(dq);
118 break;
119 #endif /* HAVE_GROUP_QUOTA */
120 case SMB_USER_FS_QUOTA_TYPE:
122 unid_t qid;
123 uint32 qflags = dq->qflags;
124 qid.uid = DEFAULT_QUOTA_UID(handle);
125 SMB_VFS_NEXT_GET_QUOTA(handle, SMB_USER_QUOTA_TYPE, qid, dq);
126 dq->qflags = qflags;
128 break;
129 #ifdef HAVE_GROUP_QUOTA
130 case SMB_GROUP_FS_QUOTA_TYPE:
132 unid_t qid;
133 uint32 qflags = dq->qflags;
134 qid.gid = DEFAULT_QUOTA_GID(handle);
135 SMB_VFS_NEXT_GET_QUOTA(handle, SMB_GROUP_QUOTA_TYPE, qid, dq);
136 dq->qflags = qflags;
138 break;
139 #endif /* HAVE_GROUP_QUOTA */
140 default:
141 errno = ENOSYS;
142 return -1;
143 break;
146 return ret;
149 static int default_quota_set_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq)
151 int ret = -1;
153 switch (qtype) {
154 case SMB_USER_QUOTA_TYPE:
155 /* we use id.uid == 0 for default quotas */
156 if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
157 DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
158 return -1;
160 break;
161 #ifdef HAVE_GROUP_QUOTA
162 case SMB_GROUP_QUOTA_TYPE:
163 /* we use id.gid == 0 for default quotas */
164 if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
165 DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
166 return -1;
168 break;
169 #endif /* HAVE_GROUP_QUOTA */
170 case SMB_USER_FS_QUOTA_TYPE:
171 break;
172 #ifdef HAVE_GROUP_QUOTA
173 case SMB_GROUP_FS_QUOTA_TYPE:
174 break;
175 #endif /* HAVE_GROUP_QUOTA */
176 default:
177 errno = ENOSYS;
178 return -1;
179 break;
182 if ((ret=SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, dq))!=0) {
183 return ret;
186 switch (qtype) {
187 case SMB_USER_QUOTA_TYPE:
188 break;
189 #ifdef HAVE_GROUP_QUOTA
190 case SMB_GROUP_QUOTA_TYPE:
191 break;
192 #endif /* HAVE_GROUP_QUOTA */
193 case SMB_USER_FS_QUOTA_TYPE:
195 unid_t qid;
196 qid.uid = DEFAULT_QUOTA_UID(handle);
197 ret = SMB_VFS_NEXT_SET_QUOTA(handle, SMB_USER_QUOTA_TYPE, qid, dq);
199 break;
200 #ifdef HAVE_GROUP_QUOTA
201 case SMB_GROUP_FS_QUOTA_TYPE:
203 unid_t qid;
204 qid.gid = DEFAULT_QUOTA_GID(handle);
205 ret = SMB_VFS_NEXT_SET_QUOTA(handle, SMB_GROUP_QUOTA_TYPE, qid, dq);
207 break;
208 #endif /* HAVE_GROUP_QUOTA */
209 default:
210 errno = ENOSYS;
211 return -1;
212 break;
215 return ret;
218 /* VFS operations structure */
220 static vfs_op_tuple default_quota_ops[] = {
221 {SMB_VFS_OP(default_quota_get_quota), SMB_VFS_OP_GET_QUOTA, SMB_VFS_LAYER_TRANSPARENT},
222 {SMB_VFS_OP(default_quota_set_quota), SMB_VFS_OP_SET_QUOTA, SMB_VFS_LAYER_TRANSPARENT},
224 {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
227 NTSTATUS vfs_default_quota_init(void);
228 NTSTATUS vfs_default_quota_init(void)
230 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, DEFAULT_QUOTA_NAME, default_quota_ops);