s4-libnet: Fix continue_groupinfo_opengroup to check correct state info
[Samba.git] / source3 / modules / onefs_config.c
blob8b34d7cd4548d877afb9b2a16266f5165cfbb715
1 /*
2 * Unix SMB/CIFS implementation.
3 * Support for OneFS
5 * Copyright (C) Todd Stecher, 2009
6 * Copyright (C) Tim Prouty, 2009
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "smbd/smbd.h"
24 #include "onefs_config.h"
26 #include <ifs/ifs_syscalls.h>
28 #define ONEFS_DATA_FASTBUF 10
30 struct onefs_vfs_share_config vfs_share_config[ONEFS_DATA_FASTBUF];
31 struct onefs_vfs_share_config *pvfs_share_config;
33 static void onefs_load_faketimestamp_config(struct connection_struct *conn,
34 struct onefs_vfs_share_config *cfg)
36 const char **parm;
37 int snum = SNUM(conn);
39 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_ATIME_NOW,
40 PARM_ATIME_NOW_DEFAULT);
42 if (parm) {
43 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
44 set_namearray(&cfg->atime_now_list,*parm);
47 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_CTIME_NOW,
48 PARM_CTIME_NOW_DEFAULT);
50 if (parm) {
51 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
52 set_namearray(&cfg->ctime_now_list,*parm);
55 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_MTIME_NOW,
56 PARM_MTIME_NOW_DEFAULT);
58 if (parm) {
59 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
60 set_namearray(&cfg->mtime_now_list,*parm);
63 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_ATIME_STATIC,
64 PARM_ATIME_STATIC_DEFAULT);
66 if (parm) {
67 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
68 set_namearray(&cfg->atime_static_list,*parm);
71 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_MTIME_STATIC,
72 PARM_MTIME_STATIC_DEFAULT);
74 if (parm) {
75 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
76 set_namearray(&cfg->mtime_static_list,*parm);
79 cfg->atime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_ATIME_SLOP,
80 PARM_ATIME_SLOP_DEFAULT);
81 cfg->ctime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_CTIME_SLOP,
82 PARM_CTIME_SLOP_DEFAULT);
83 cfg->mtime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_MTIME_SLOP,
84 PARM_MTIME_SLOP_DEFAULT);
87 /**
88 * Set onefs-specific vfs global config parameters.
90 * Since changes in these parameters require calling syscalls, we only want to
91 * call them when the configuration actually changes.
93 static void onefs_load_global_config(connection_struct *conn)
95 static struct onefs_vfs_global_config global_config;
96 bool dot_snap_child_accessible;
97 bool dot_snap_child_visible;
98 bool dot_snap_root_accessible;
99 bool dot_snap_root_visible;
100 bool dot_snap_tilde;
101 bool reconfig_dso = false;
102 bool reconfig_tilde = false;
104 /* Check if this is the first time setting the config options. */
105 if (!(global_config.init_flags & ONEFS_VFS_CONFIG_INITIALIZED)) {
106 global_config.init_flags |= ONEFS_VFS_CONFIG_INITIALIZED;
108 /* Set process encoding */
109 onefs_sys_config_enc();
111 reconfig_dso = true;
112 reconfig_tilde = true;
115 /* Get the dot snap options from the conf. */
116 dot_snap_child_accessible =
117 lp_parm_bool(SNUM(conn), PARM_ONEFS_TYPE,
118 PARM_DOT_SNAP_CHILD_ACCESSIBLE,
119 PARM_DOT_SNAP_CHILD_ACCESSIBLE_DEFAULT);
120 dot_snap_child_visible =
121 lp_parm_bool(SNUM(conn), PARM_ONEFS_TYPE,
122 PARM_DOT_SNAP_CHILD_VISIBLE,
123 PARM_DOT_SNAP_CHILD_VISIBLE_DEFAULT);
124 dot_snap_root_accessible =
125 lp_parm_bool(SNUM(conn), PARM_ONEFS_TYPE,
126 PARM_DOT_SNAP_ROOT_ACCESSIBLE,
127 PARM_DOT_SNAP_ROOT_ACCESSIBLE_DEFAULT);
128 dot_snap_root_visible =
129 lp_parm_bool(SNUM(conn), PARM_ONEFS_TYPE,
130 PARM_DOT_SNAP_ROOT_VISIBLE,
131 PARM_DOT_SNAP_ROOT_VISIBLE_DEFAULT);
132 dot_snap_tilde =
133 lp_parm_bool(SNUM(conn), PARM_ONEFS_TYPE,
134 PARM_DOT_SNAP_TILDE,
135 PARM_DOT_SNAP_TILDE_DEFAULT);
137 /* Check if any of the dot snap options need updating. */
138 if (dot_snap_child_accessible !=
139 global_config.dot_snap_child_accessible) {
140 global_config.dot_snap_child_accessible =
141 dot_snap_child_accessible;
142 reconfig_dso = true;
144 if (dot_snap_child_visible !=
145 global_config.dot_snap_child_visible) {
146 global_config.dot_snap_child_visible =
147 dot_snap_child_visible;
148 reconfig_dso = true;
150 if (dot_snap_root_accessible !=
151 global_config.dot_snap_root_accessible) {
152 global_config.dot_snap_root_accessible =
153 dot_snap_root_accessible;
154 reconfig_dso = true;
156 if (dot_snap_root_visible !=
157 global_config.dot_snap_root_visible) {
158 global_config.dot_snap_root_visible =
159 dot_snap_root_visible;
160 reconfig_dso = true;
162 if (dot_snap_tilde != global_config.dot_snap_tilde) {
163 global_config.dot_snap_tilde = dot_snap_tilde;
164 reconfig_tilde = true;
167 /* If a dot snap option has changed update the process. */
168 if (reconfig_dso) {
169 onefs_sys_config_snap_opt(&global_config);
172 /* If the dot snap tilde option has changed update the process. */
173 if (reconfig_tilde) {
174 onefs_sys_config_tilde(&global_config);
178 int onefs_load_config(connection_struct *conn)
180 int snum = SNUM(conn);
181 int share_count = lp_numservices();
183 /* Share config */
184 if (!pvfs_share_config) {
186 if (share_count <= ONEFS_DATA_FASTBUF)
187 pvfs_share_config = vfs_share_config;
188 else {
189 pvfs_share_config =
190 SMB_MALLOC_ARRAY(struct onefs_vfs_share_config,
191 share_count);
192 if (!pvfs_share_config) {
193 errno = ENOMEM;
194 return -1;
197 memset(pvfs_share_config, 0,
198 (sizeof(struct onefs_vfs_share_config) *
199 share_count));
203 if ((pvfs_share_config[snum].init_flags &
204 ONEFS_VFS_CONFIG_INITIALIZED) == 0) {
205 pvfs_share_config[snum].init_flags =
206 ONEFS_VFS_CONFIG_INITIALIZED;
207 onefs_load_faketimestamp_config(conn,
208 &pvfs_share_config[snum]);
211 /* Global config */
212 onefs_load_global_config(conn);
214 return 0;
217 bool onefs_get_config(int snum, int config_type,
218 struct onefs_vfs_share_config *cfg)
220 if ((pvfs_share_config != NULL) &&
221 (pvfs_share_config[snum].init_flags & config_type))
222 *cfg = pvfs_share_config[snum];
223 else
224 return false;
226 return true;
231 * Set the per-process encoding, ignoring errors.
233 void onefs_sys_config_enc(void)
235 int ret;
237 ret = enc_set_proc(ENC_UTF8);
238 if (ret) {
239 DEBUG(0, ("Setting process encoding failed: %s\n",
240 strerror(errno)));
245 * Set the per-process .snpashot directory options, ignoring errors.
247 void onefs_sys_config_snap_opt(struct onefs_vfs_global_config *global_config)
249 struct ifs_dotsnap_options dso;
250 int ret;
252 dso.per_proc = 1;
253 dso.sub_accessible = global_config->dot_snap_child_accessible;
254 dso.sub_visible = global_config->dot_snap_child_visible;
255 dso.root_accessible = global_config->dot_snap_root_accessible;
256 dso.root_visible = global_config->dot_snap_root_visible;
258 ret = ifs_set_dotsnap_options(&dso);
259 if (ret) {
260 DEBUG(0, ("Setting snapshot visibility/accessibility "
261 "failed: %s\n", strerror(errno)));
266 * Set the per-process flag saying whether or not to accept ~snapshot
267 * as an alternative name for .snapshot directories.
269 void onefs_sys_config_tilde(struct onefs_vfs_global_config *global_config)
271 int ret;
273 ret = ifs_tilde_snapshot(global_config->dot_snap_tilde);
274 if (ret) {
275 DEBUG(0, ("Setting snapshot tilde failed: %s\n",
276 strerror(errno)));