summaryrefslogtreecommitdiff
path: root/source3/modules/vfs_default_quota.c
blob: 1294a515333cf2c3bda3c0fbbfae692b8595065c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* 
 * Store default Quotas in a specified quota record
 *
 * Copyright (C) Stefan (metze) Metzmacher 2003
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "includes.h"

#undef DBGC_CLASS
#define DBGC_CLASS DBGC_VFS

#define DEFAULT_QUOTA_NAME "default_quota"

#define DEFAULT_QUOTA_UID_DEFAULT		0
#define DEFAULT_QUOTA_UID_NOLIMIT_DEFAULT	True
#define DEFAULT_QUOTA_GID_DEFAULT		0
#define DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT	True

#define DEFAULT_QUOTA_UID(handle) \
	(uid_t)lp_parm_int(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"uid",DEFAULT_QUOTA_UID_DEFAULT)

#define DEFAULT_QUOTA_UID_NOLIMIT(handle) \
	lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"uid nolimit",DEFAULT_QUOTA_UID_NOLIMIT_DEFAULT)

#define DEFAULT_QUOTA_GID(handle) \
	(gid_t)lp_parm_int(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid",DEFAULT_QUOTA_GID_DEFAULT)

#define DEFAULT_QUOTA_GID_NOLIMIT(handle) \
	lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid nolimit",DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT)

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)
{
	int ret = -1;

	if ((ret=SMB_VFS_NEXT_GET_QUOTA(handle, conn, qtype, id, dq))!=0) {
		return ret;
	}

	switch (qtype) {
		case SMB_USER_QUOTA_TYPE:
			/* we use id.uid == 0 for default quotas */
			if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
				DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
				SMB_QUOTAS_SET_NO_LIMIT(dq);
			}
			break;
#ifdef HAVE_GROUP_QUOTA
		case SMB_GROUP_QUOTA_TYPE:
			/* we use id.gid == 0 for default quotas */
			if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
				DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
				SMB_QUOTAS_SET_NO_LIMIT(dq);
			}
			break;
#endif /* HAVE_GROUP_QUOTA */
		case SMB_USER_FS_QUOTA_TYPE:
			{
				unid_t qid;
				uint32 qflags = dq->qflags;
				qid.uid = DEFAULT_QUOTA_UID(handle);
				SMB_VFS_NEXT_GET_QUOTA(handle, conn, SMB_USER_QUOTA_TYPE, qid, dq);
				dq->qflags = qflags;
			}
			break;
#ifdef HAVE_GROUP_QUOTA
		case SMB_GROUP_FS_QUOTA_TYPE:
			{
				unid_t qid;
				uint32 qflags = dq->qflags;
				qid.gid = DEFAULT_QUOTA_GID(handle);
				SMB_VFS_NEXT_GET_QUOTA(handle, conn, SMB_GROUP_QUOTA_TYPE, qid, dq);
				dq->qflags = qflags;
			}
			break;
#endif /* HAVE_GROUP_QUOTA */
		default:
			errno = ENOSYS;
			return -1;
			break;
	}

	return ret;
}

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)
{
	int ret = -1;

	switch (qtype) {
		case SMB_USER_QUOTA_TYPE:
			/* we use id.uid == 0 for default quotas */
			if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
				DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
				return -1;
			}
			break;
#ifdef HAVE_GROUP_QUOTA
		case SMB_GROUP_QUOTA_TYPE:
			/* we use id.gid == 0 for default quotas */
			if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
				DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
				return -1;
			}
			break;
#endif /* HAVE_GROUP_QUOTA */
		case SMB_USER_FS_QUOTA_TYPE:
			break;
#ifdef HAVE_GROUP_QUOTA
		case SMB_GROUP_FS_QUOTA_TYPE:
			break;
#endif /* HAVE_GROUP_QUOTA */
		default:
			errno = ENOSYS;
			return -1;
			break;
	}

	if ((ret=SMB_VFS_NEXT_SET_QUOTA(handle, conn, qtype, id, dq))!=0) {
		return ret;
	}

	switch (qtype) {
		case SMB_USER_QUOTA_TYPE:
			break;
#ifdef HAVE_GROUP_QUOTA
		case SMB_GROUP_QUOTA_TYPE:
			break;
#endif /* HAVE_GROUP_QUOTA */
		case SMB_USER_FS_QUOTA_TYPE:
			{
				unid_t qid;
				qid.uid = DEFAULT_QUOTA_UID(handle);
				ret = SMB_VFS_NEXT_SET_QUOTA(handle, conn, SMB_USER_QUOTA_TYPE, qid, dq);
			}
			break;
#ifdef HAVE_GROUP_QUOTA
		case SMB_GROUP_FS_QUOTA_TYPE:
			{
				unid_t qid;
				qid.gid = DEFAULT_QUOTA_GID(handle);
				ret = SMB_VFS_NEXT_SET_QUOTA(handle, conn, SMB_GROUP_QUOTA_TYPE, qid, dq);
			}
			break;
#endif /* HAVE_GROUP_QUOTA */
		default:
			errno = ENOSYS;
			return -1;
			break;
	}

	return ret;
}

/* VFS operations structure */

static vfs_op_tuple default_quota_ops[] = {	
	{SMB_VFS_OP(default_quota_get_quota),	SMB_VFS_OP_GET_QUOTA,	SMB_VFS_LAYER_TRANSPARENT},
	{SMB_VFS_OP(default_quota_set_quota),	SMB_VFS_OP_SET_QUOTA,	SMB_VFS_LAYER_TRANSPARENT},

	{SMB_VFS_OP(NULL),			SMB_VFS_OP_NOOP,	SMB_VFS_LAYER_NOOP}
};

NTSTATUS vfs_default_quota_init(void)
{
	return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, DEFAULT_QUOTA_NAME, default_quota_ops);
}