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.
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
)
49 if ((ret
=SMB_VFS_NEXT_GET_QUOTA(handle
, conn
, qtype
, id
, dq
))!=0) {
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
);
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
);
69 #endif /* HAVE_GROUP_QUOTA */
70 case SMB_USER_FS_QUOTA_TYPE
:
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
);
79 #ifdef HAVE_GROUP_QUOTA
80 case SMB_GROUP_FS_QUOTA_TYPE
:
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
);
89 #endif /* HAVE_GROUP_QUOTA */
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
)
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
)) {
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
)) {
119 #endif /* HAVE_GROUP_QUOTA */
120 case SMB_USER_FS_QUOTA_TYPE
:
122 #ifdef HAVE_GROUP_QUOTA
123 case SMB_GROUP_FS_QUOTA_TYPE
:
125 #endif /* HAVE_GROUP_QUOTA */
132 if ((ret
=SMB_VFS_NEXT_SET_QUOTA(handle
, conn
, qtype
, id
, dq
))!=0) {
137 case SMB_USER_QUOTA_TYPE
:
139 #ifdef HAVE_GROUP_QUOTA
140 case SMB_GROUP_QUOTA_TYPE
:
142 #endif /* HAVE_GROUP_QUOTA */
143 case SMB_USER_FS_QUOTA_TYPE
:
146 qid
.uid
= DEFAULT_QUOTA_UID(handle
);
147 ret
= SMB_VFS_NEXT_SET_QUOTA(handle
, conn
, SMB_USER_QUOTA_TYPE
, qid
, dq
);
150 #ifdef HAVE_GROUP_QUOTA
151 case SMB_GROUP_FS_QUOTA_TYPE
:
154 qid
.gid
= DEFAULT_QUOTA_GID(handle
);
155 ret
= SMB_VFS_NEXT_SET_QUOTA(handle
, conn
, SMB_GROUP_QUOTA_TYPE
, qid
, dq
);
158 #endif /* HAVE_GROUP_QUOTA */
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
);