getncchanges: Add a comment regarding sIDHistory for allow/deny in repl_secret
[Samba.git] / source3 / modules / vfs_fake_dfq.c
blob51ab7bb46d99723d622f8f1f0e3c04d5016870b3
1 /*
2 * Fake Disk-Free and Quota VFS module. Implements passthrough operation
3 * of all VFS calls, except for "disk free" and "get quota" which
4 * are handled by reading a text file named ".dfq" in the current directory.
6 * This module is intended for testing purposes.
8 * Copyright (C) Uri Simchoni, 2016
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "smbd/smbd.h"
27 #undef DBGC_CLASS
28 #define DBGC_CLASS DBGC_VFS
30 static int dfq_get_quota(struct vfs_handle_struct *handle, const char *path,
31 enum SMB_QUOTA_TYPE qtype, unid_t id,
32 SMB_DISK_QUOTA *qt);
34 static uint64_t dfq_load_param(int snum, const char *path, const char *section,
35 const char *param, uint64_t def_val)
37 uint64_t ret;
39 char *option =
40 talloc_asprintf(talloc_tos(), "%s/%s/%s", section, param, path);
41 if (option == NULL) {
42 return def_val;
45 ret = (uint64_t)lp_parm_ulonglong(snum, "fake_dfq", option,
46 (unsigned long long)def_val);
48 TALLOC_FREE(option);
50 return ret;
53 static uint64_t dfq_disk_free(vfs_handle_struct *handle, const char *path,
54 uint64_t *bsize, uint64_t *dfree, uint64_t *dsize)
56 uint64_t free_1k;
57 int snum = SNUM(handle->conn);
58 uint64_t dfq_bsize = 0;
59 char *rpath = NULL;
61 /* look up the params based on real path to be resilient
62 * to refactoring of path<->realpath
64 rpath = SMB_VFS_NEXT_REALPATH(handle, path);
65 if (rpath != NULL) {
66 dfq_bsize = dfq_load_param(snum, rpath, "df", "block size", 0);
68 if (dfq_bsize == 0) {
69 SAFE_FREE(rpath);
70 return SMB_VFS_NEXT_DISK_FREE(handle, path, bsize, dfree,
71 dsize);
74 *bsize = dfq_bsize;
75 *dfree = dfq_load_param(snum, rpath, "df", "disk free", 0);
76 *dsize = dfq_load_param(snum, rpath, "df", "disk size", 0);
78 if ((*bsize) < 1024) {
79 free_1k = (*dfree) / (1024 / (*bsize));
80 } else {
81 free_1k = ((*bsize) / 1024) * (*dfree);
84 SAFE_FREE(rpath);
85 return free_1k;
88 static int dfq_get_quota(struct vfs_handle_struct *handle, const char *path,
89 enum SMB_QUOTA_TYPE qtype, unid_t id,
90 SMB_DISK_QUOTA *qt)
92 int rc = 0;
93 int save_errno;
94 char *section = NULL;
95 int snum = SNUM(handle->conn);
96 uint64_t bsize = 0;
97 char *rpath = NULL;
99 rpath = SMB_VFS_NEXT_REALPATH(handle, path);
100 if (rpath == NULL) {
101 goto dflt;
104 switch (qtype) {
105 case SMB_USER_QUOTA_TYPE:
106 section = talloc_asprintf(talloc_tos(), "u%llu",
107 (unsigned long long)id.uid);
108 break;
109 case SMB_GROUP_QUOTA_TYPE:
110 section = talloc_asprintf(talloc_tos(), "g%llu",
111 (unsigned long long)id.gid);
112 break;
113 case SMB_USER_FS_QUOTA_TYPE:
114 section = talloc_strdup(talloc_tos(), "udflt");
115 break;
116 case SMB_GROUP_FS_QUOTA_TYPE:
117 section = talloc_strdup(talloc_tos(), "gdflt");
118 break;
119 default:
120 break;
123 if (section == NULL) {
124 goto dflt;
127 bsize = dfq_load_param(snum, rpath, section, "block size", 4096);
128 if (bsize == 0) {
129 goto dflt;
132 if (dfq_load_param(snum, rpath, section, "err", 0) != 0) {
133 errno = ENOTSUP;
134 rc = -1;
135 goto out;
138 if (dfq_load_param(snum, rpath, section, "nosys", 0) != 0) {
139 errno = ENOSYS;
140 rc = -1;
141 goto out;
144 ZERO_STRUCTP(qt);
146 qt->bsize = bsize;
147 qt->hardlimit = dfq_load_param(snum, rpath, section, "hard limit", 0);
148 qt->softlimit = dfq_load_param(snum, rpath, section, "soft limit", 0);
149 qt->curblocks = dfq_load_param(snum, rpath, section, "cur blocks", 0);
150 qt->ihardlimit =
151 dfq_load_param(snum, rpath, section, "inode hard limit", 0);
152 qt->isoftlimit =
153 dfq_load_param(snum, rpath, section, "inode soft limit", 0);
154 qt->curinodes = dfq_load_param(snum, rpath, section, "cur inodes", 0);
155 qt->qflags = dfq_load_param(snum, rpath, section, "qflags", QUOTAS_DENY_DISK);
157 goto out;
159 dflt:
160 rc = SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, qt);
162 out:
163 save_errno = errno;
164 TALLOC_FREE(section);
165 SAFE_FREE(rpath);
166 errno = save_errno;
167 return rc;
170 struct vfs_fn_pointers vfs_fake_dfq_fns = {
171 /* Disk operations */
173 .disk_free_fn = dfq_disk_free,
174 .get_quota_fn = dfq_get_quota,
177 static_decl_vfs;
178 NTSTATUS vfs_fake_dfq_init(void)
180 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "fake_dfq",
181 &vfs_fake_dfq_fns);