Apply Craig Barratt's fixes to allow multiple exlusion files and patterns.
[Samba/gebeck_regimport.git] / source3 / modules / vfs_default_quota.c
blob1294a515333cf2c3bda3c0fbbfae692b8595065c
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.
21 #include "includes.h"
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_VFS
26 #define DEFAULT_QUOTA_NAME "default_quota"
28 #define DEFAULT_QUOTA_UID_DEFAULT 0
29 #define DEFAULT_QUOTA_UID_NOLIMIT_DEFAULT True
30 #define DEFAULT_QUOTA_GID_DEFAULT 0
31 #define DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT True
33 #define DEFAULT_QUOTA_UID(handle) \
34 (uid_t)lp_parm_int(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"uid",DEFAULT_QUOTA_UID_DEFAULT)
36 #define DEFAULT_QUOTA_UID_NOLIMIT(handle) \
37 lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"uid nolimit",DEFAULT_QUOTA_UID_NOLIMIT_DEFAULT)
39 #define DEFAULT_QUOTA_GID(handle) \
40 (gid_t)lp_parm_int(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid",DEFAULT_QUOTA_GID_DEFAULT)
42 #define DEFAULT_QUOTA_GID_NOLIMIT(handle) \
43 lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid nolimit",DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT)
45 static int default_quota_get_quota(vfs_handle_struct *handle, connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq)
47 int ret = -1;
49 if ((ret=SMB_VFS_NEXT_GET_QUOTA(handle, conn, qtype, id, dq))!=0) {
50 return ret;
53 switch (qtype) {
54 case SMB_USER_QUOTA_TYPE:
55 /* we use id.uid == 0 for default quotas */
56 if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
57 DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
58 SMB_QUOTAS_SET_NO_LIMIT(dq);
60 break;
61 #ifdef HAVE_GROUP_QUOTA
62 case SMB_GROUP_QUOTA_TYPE:
63 /* we use id.gid == 0 for default quotas */
64 if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
65 DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
66 SMB_QUOTAS_SET_NO_LIMIT(dq);
68 break;
69 #endif /* HAVE_GROUP_QUOTA */
70 case SMB_USER_FS_QUOTA_TYPE:
72 unid_t qid;
73 uint32 qflags = dq->qflags;
74 qid.uid = DEFAULT_QUOTA_UID(handle);
75 SMB_VFS_NEXT_GET_QUOTA(handle, conn, SMB_USER_QUOTA_TYPE, qid, dq);
76 dq->qflags = qflags;
78 break;
79 #ifdef HAVE_GROUP_QUOTA
80 case SMB_GROUP_FS_QUOTA_TYPE:
82 unid_t qid;
83 uint32 qflags = dq->qflags;
84 qid.gid = DEFAULT_QUOTA_GID(handle);
85 SMB_VFS_NEXT_GET_QUOTA(handle, conn, SMB_GROUP_QUOTA_TYPE, qid, dq);
86 dq->qflags = qflags;
88 break;
89 #endif /* HAVE_GROUP_QUOTA */
90 default:
91 errno = ENOSYS;
92 return -1;
93 break;
96 return ret;
99 static int default_quota_set_quota(vfs_handle_struct *handle, connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq)
101 int ret = -1;
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 return -1;
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 return -1;
118 break;
119 #endif /* HAVE_GROUP_QUOTA */
120 case SMB_USER_FS_QUOTA_TYPE:
121 break;
122 #ifdef HAVE_GROUP_QUOTA
123 case SMB_GROUP_FS_QUOTA_TYPE:
124 break;
125 #endif /* HAVE_GROUP_QUOTA */
126 default:
127 errno = ENOSYS;
128 return -1;
129 break;
132 if ((ret=SMB_VFS_NEXT_SET_QUOTA(handle, conn, qtype, id, dq))!=0) {
133 return ret;
136 switch (qtype) {
137 case SMB_USER_QUOTA_TYPE:
138 break;
139 #ifdef HAVE_GROUP_QUOTA
140 case SMB_GROUP_QUOTA_TYPE:
141 break;
142 #endif /* HAVE_GROUP_QUOTA */
143 case SMB_USER_FS_QUOTA_TYPE:
145 unid_t qid;
146 qid.uid = DEFAULT_QUOTA_UID(handle);
147 ret = SMB_VFS_NEXT_SET_QUOTA(handle, conn, SMB_USER_QUOTA_TYPE, qid, dq);
149 break;
150 #ifdef HAVE_GROUP_QUOTA
151 case SMB_GROUP_FS_QUOTA_TYPE:
153 unid_t qid;
154 qid.gid = DEFAULT_QUOTA_GID(handle);
155 ret = SMB_VFS_NEXT_SET_QUOTA(handle, conn, SMB_GROUP_QUOTA_TYPE, qid, dq);
157 break;
158 #endif /* HAVE_GROUP_QUOTA */
159 default:
160 errno = ENOSYS;
161 return -1;
162 break;
165 return ret;
168 /* VFS operations structure */
170 static vfs_op_tuple default_quota_ops[] = {
171 {SMB_VFS_OP(default_quota_get_quota), SMB_VFS_OP_GET_QUOTA, SMB_VFS_LAYER_TRANSPARENT},
172 {SMB_VFS_OP(default_quota_set_quota), SMB_VFS_OP_SET_QUOTA, SMB_VFS_LAYER_TRANSPARENT},
174 {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
177 NTSTATUS vfs_default_quota_init(void)
179 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, DEFAULT_QUOTA_NAME, default_quota_ops);