| [988] | 1 | /*
|
|---|
| 2 | * shadow_copy2: a shadow copy module (second implementation)
|
|---|
| [917] | 3 | *
|
|---|
| [988] | 4 | * Copyright (C) Andrew Tridgell 2007 (portions taken from shadow_copy2)
|
|---|
| 5 | * Copyright (C) Ed Plese 2009
|
|---|
| 6 | * Copyright (C) Volker Lendecke 2011
|
|---|
| 7 | * Copyright (C) Christian Ambach 2011
|
|---|
| 8 | * Copyright (C) Michael Adam 2013
|
|---|
| [917] | 9 | *
|
|---|
| 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 2 of the License, or
|
|---|
| 13 | * (at your option) any later version.
|
|---|
| [988] | 14 | *
|
|---|
| [917] | 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.
|
|---|
| [988] | 19 | *
|
|---|
| [917] | 20 | * You should have received a copy of the GNU General Public License
|
|---|
| 21 | * along with this program; if not, write to the Free Software
|
|---|
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 23 | */
|
|---|
| 24 |
|
|---|
| [988] | 25 | /*
|
|---|
| 26 | * This is a second implemetation of a shadow copy module for exposing
|
|---|
| 27 | * file system snapshots to windows clients as shadow copies.
|
|---|
| 28 | *
|
|---|
| 29 | * See the manual page for documentation.
|
|---|
| 30 | */
|
|---|
| 31 |
|
|---|
| [917] | 32 | #include "includes.h"
|
|---|
| 33 | #include "smbd/smbd.h"
|
|---|
| 34 | #include "system/filesys.h"
|
|---|
| [988] | 35 | #include "include/ntioctl.h"
|
|---|
| 36 | #include "util_tdb.h"
|
|---|
| [917] | 37 |
|
|---|
| [988] | 38 | struct shadow_copy2_config {
|
|---|
| 39 | char *gmt_format;
|
|---|
| 40 | bool use_sscanf;
|
|---|
| 41 | bool use_localtime;
|
|---|
| 42 | char *snapdir;
|
|---|
| 43 | bool snapdirseverywhere;
|
|---|
| 44 | bool crossmountpoints;
|
|---|
| 45 | bool fixinodes;
|
|---|
| 46 | char *sort_order;
|
|---|
| 47 | bool snapdir_absolute;
|
|---|
| 48 | char *mount_point;
|
|---|
| 49 | char *rel_connectpath; /* share root, relative to a snapshot root */
|
|---|
| 50 | char *snapshot_basepath; /* the absolute version of snapdir */
|
|---|
| 51 | };
|
|---|
| [917] | 52 |
|
|---|
| [988] | 53 | static bool shadow_copy2_find_slashes(TALLOC_CTX *mem_ctx, const char *str,
|
|---|
| 54 | size_t **poffsets,
|
|---|
| 55 | unsigned *pnum_offsets)
|
|---|
| 56 | {
|
|---|
| 57 | unsigned num_offsets;
|
|---|
| 58 | size_t *offsets;
|
|---|
| 59 | const char *p;
|
|---|
| [917] | 60 |
|
|---|
| [988] | 61 | num_offsets = 0;
|
|---|
| [917] | 62 |
|
|---|
| [988] | 63 | p = str;
|
|---|
| 64 | while ((p = strchr(p, '/')) != NULL) {
|
|---|
| 65 | num_offsets += 1;
|
|---|
| 66 | p += 1;
|
|---|
| 67 | }
|
|---|
| [917] | 68 |
|
|---|
| [988] | 69 | offsets = talloc_array(mem_ctx, size_t, num_offsets);
|
|---|
| 70 | if (offsets == NULL) {
|
|---|
| 71 | return false;
|
|---|
| 72 | }
|
|---|
| [917] | 73 |
|
|---|
| [988] | 74 | p = str;
|
|---|
| 75 | num_offsets = 0;
|
|---|
| 76 | while ((p = strchr(p, '/')) != NULL) {
|
|---|
| 77 | offsets[num_offsets] = p-str;
|
|---|
| 78 | num_offsets += 1;
|
|---|
| 79 | p += 1;
|
|---|
| 80 | }
|
|---|
| [917] | 81 |
|
|---|
| [988] | 82 | *poffsets = offsets;
|
|---|
| 83 | *pnum_offsets = num_offsets;
|
|---|
| 84 | return true;
|
|---|
| 85 | }
|
|---|
| [917] | 86 |
|
|---|
| [988] | 87 | /**
|
|---|
| 88 | * Given a timestamp, build the posix level GMT-tag string
|
|---|
| 89 | * based on the configurable format.
|
|---|
| 90 | */
|
|---|
| 91 | static size_t shadow_copy2_posix_gmt_string(struct vfs_handle_struct *handle,
|
|---|
| 92 | time_t snapshot,
|
|---|
| 93 | char *snaptime_string,
|
|---|
| 94 | size_t len)
|
|---|
| 95 | {
|
|---|
| 96 | struct tm snap_tm;
|
|---|
| 97 | size_t snaptime_len;
|
|---|
| 98 | struct shadow_copy2_config *config;
|
|---|
| [917] | 99 |
|
|---|
| [988] | 100 | SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
|
|---|
| 101 | return 0);
|
|---|
| [917] | 102 |
|
|---|
| [988] | 103 | if (config->use_sscanf) {
|
|---|
| 104 | snaptime_len = snprintf(snaptime_string,
|
|---|
| 105 | len,
|
|---|
| 106 | config->gmt_format,
|
|---|
| 107 | (unsigned long)snapshot);
|
|---|
| 108 | if (snaptime_len <= 0) {
|
|---|
| 109 | DEBUG(10, ("snprintf failed\n"));
|
|---|
| 110 | return snaptime_len;
|
|---|
| 111 | }
|
|---|
| 112 | } else {
|
|---|
| 113 | if (config->use_localtime) {
|
|---|
| 114 | if (localtime_r(&snapshot, &snap_tm) == 0) {
|
|---|
| 115 | DEBUG(10, ("gmtime_r failed\n"));
|
|---|
| 116 | return -1;
|
|---|
| 117 | }
|
|---|
| 118 | } else {
|
|---|
| 119 | if (gmtime_r(&snapshot, &snap_tm) == 0) {
|
|---|
| 120 | DEBUG(10, ("gmtime_r failed\n"));
|
|---|
| 121 | return -1;
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 | snaptime_len = strftime(snaptime_string,
|
|---|
| 125 | len,
|
|---|
| 126 | config->gmt_format,
|
|---|
| 127 | &snap_tm);
|
|---|
| 128 | if (snaptime_len == 0) {
|
|---|
| 129 | DEBUG(10, ("strftime failed\n"));
|
|---|
| 130 | return 0;
|
|---|
| 131 | }
|
|---|
| 132 | }
|
|---|
| [917] | 133 |
|
|---|
| [988] | 134 | return snaptime_len;
|
|---|
| 135 | }
|
|---|
| [917] | 136 |
|
|---|
| [988] | 137 | /**
|
|---|
| 138 | * Given a timestamp, build the string to insert into a path
|
|---|
| 139 | * as a path component for creating the local path to the
|
|---|
| 140 | * snapshot at the given timestamp of the input path.
|
|---|
| 141 | *
|
|---|
| 142 | * In the case of a parallel snapdir (specified with an
|
|---|
| 143 | * absolute path), this is the inital portion of the
|
|---|
| 144 | * local path of any snapshot file. The complete path is
|
|---|
| 145 | * obtained by appending the portion of the file's path
|
|---|
| 146 | * below the share root's mountpoint.
|
|---|
| [917] | 147 | */
|
|---|
| [988] | 148 | static char *shadow_copy2_insert_string(TALLOC_CTX *mem_ctx,
|
|---|
| 149 | struct vfs_handle_struct *handle,
|
|---|
| 150 | time_t snapshot)
|
|---|
| 151 | {
|
|---|
| 152 | fstring snaptime_string;
|
|---|
| 153 | size_t snaptime_len = 0;
|
|---|
| 154 | char *result = NULL;
|
|---|
| 155 | struct shadow_copy2_config *config;
|
|---|
| [917] | 156 |
|
|---|
| [988] | 157 | SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
|
|---|
| 158 | return NULL);
|
|---|
| [917] | 159 |
|
|---|
| [988] | 160 | snaptime_len = shadow_copy2_posix_gmt_string(handle,
|
|---|
| 161 | snapshot,
|
|---|
| 162 | snaptime_string,
|
|---|
| 163 | sizeof(snaptime_string));
|
|---|
| 164 | if (snaptime_len <= 0) {
|
|---|
| 165 | return NULL;
|
|---|
| 166 | }
|
|---|
| [917] | 167 |
|
|---|
| [988] | 168 | if (config->snapdir_absolute) {
|
|---|
| 169 | result = talloc_asprintf(mem_ctx, "%s/%s",
|
|---|
| 170 | config->snapdir, snaptime_string);
|
|---|
| 171 | } else {
|
|---|
| 172 | result = talloc_asprintf(mem_ctx, "/%s/%s",
|
|---|
| 173 | config->snapdir, snaptime_string);
|
|---|
| [917] | 174 | }
|
|---|
| [988] | 175 | if (result == NULL) {
|
|---|
| 176 | DEBUG(1, (__location__ " talloc_asprintf failed\n"));
|
|---|
| [917] | 177 | }
|
|---|
| [988] | 178 |
|
|---|
| 179 | return result;
|
|---|
| [917] | 180 | }
|
|---|
| 181 |
|
|---|
| [988] | 182 | /**
|
|---|
| 183 | * Build the posix snapshot path for the connection
|
|---|
| 184 | * at the given timestamp, i.e. the absolute posix path
|
|---|
| 185 | * that contains the snapshot for this file system.
|
|---|
| 186 | *
|
|---|
| 187 | * This only applies to classical case, i.e. not
|
|---|
| 188 | * to the "snapdirseverywhere" mode.
|
|---|
| 189 | */
|
|---|
| 190 | static char *shadow_copy2_snapshot_path(TALLOC_CTX *mem_ctx,
|
|---|
| 191 | struct vfs_handle_struct *handle,
|
|---|
| 192 | time_t snapshot)
|
|---|
| [917] | 193 | {
|
|---|
| [988] | 194 | fstring snaptime_string;
|
|---|
| 195 | size_t snaptime_len = 0;
|
|---|
| 196 | char *result = NULL;
|
|---|
| 197 | struct shadow_copy2_config *config;
|
|---|
| [917] | 198 |
|
|---|
| [988] | 199 | SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
|
|---|
| 200 | return NULL);
|
|---|
| [917] | 201 |
|
|---|
| [988] | 202 | snaptime_len = shadow_copy2_posix_gmt_string(handle,
|
|---|
| 203 | snapshot,
|
|---|
| 204 | snaptime_string,
|
|---|
| 205 | sizeof(snaptime_string));
|
|---|
| 206 | if (snaptime_len <= 0) {
|
|---|
| [917] | 207 | return NULL;
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| [988] | 210 | result = talloc_asprintf(mem_ctx, "%s/%s",
|
|---|
| 211 | config->snapshot_basepath, snaptime_string);
|
|---|
| 212 | if (result == NULL) {
|
|---|
| 213 | DEBUG(1, (__location__ " talloc_asprintf failed\n"));
|
|---|
| [917] | 214 | }
|
|---|
| 215 |
|
|---|
| [988] | 216 | return result;
|
|---|
| [917] | 217 | }
|
|---|
| 218 |
|
|---|
| [988] | 219 | /**
|
|---|
| 220 | * Strip a snapshot component from a filename as
|
|---|
| 221 | * handed in via the smb layer.
|
|---|
| 222 | * Returns the parsed timestamp and the stripped filename.
|
|---|
| [917] | 223 | */
|
|---|
| [988] | 224 | static bool shadow_copy2_strip_snapshot(TALLOC_CTX *mem_ctx,
|
|---|
| 225 | struct vfs_handle_struct *handle,
|
|---|
| 226 | const char *name,
|
|---|
| 227 | time_t *ptimestamp,
|
|---|
| 228 | char **pstripped)
|
|---|
| [917] | 229 | {
|
|---|
| [988] | 230 | struct tm tm;
|
|---|
| 231 | time_t timestamp;
|
|---|
| 232 | const char *p;
|
|---|
| 233 | char *q;
|
|---|
| 234 | char *stripped;
|
|---|
| 235 | size_t rest_len, dst_len;
|
|---|
| 236 | struct shadow_copy2_config *config;
|
|---|
| 237 | const char *snapdir;
|
|---|
| 238 | ssize_t snapdirlen;
|
|---|
| 239 | ptrdiff_t len_before_gmt;
|
|---|
| [917] | 240 |
|
|---|
| [988] | 241 | SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
|
|---|
| 242 | return false);
|
|---|
| [917] | 243 |
|
|---|
| [988] | 244 | DEBUG(10, (__location__ ": enter path '%s'\n", name));
|
|---|
| [917] | 245 |
|
|---|
| [988] | 246 | p = strstr_m(name, "@GMT-");
|
|---|
| 247 | if (p == NULL) {
|
|---|
| 248 | DEBUG(11, ("@GMT not found\n"));
|
|---|
| 249 | goto no_snapshot;
|
|---|
| [917] | 250 | }
|
|---|
| [988] | 251 | if ((p > name) && (p[-1] != '/')) {
|
|---|
| 252 | /* the GMT-token does not start a path-component */
|
|---|
| 253 | DEBUG(10, ("not at start, p=%p, name=%p, p[-1]=%d\n",
|
|---|
| 254 | p, name, (int)p[-1]));
|
|---|
| 255 | goto no_snapshot;
|
|---|
| 256 | }
|
|---|
| [917] | 257 |
|
|---|
| 258 | /*
|
|---|
| [988] | 259 | * Figure out whether we got an already converted string. One
|
|---|
| 260 | * case where this happens is in a smb2 create call with the
|
|---|
| 261 | * mxac create blob set. We do the get_acl call on
|
|---|
| 262 | * fsp->fsp_name, which is already converted. We are converted
|
|---|
| 263 | * if we got a file name of the form ".snapshots/@GMT-",
|
|---|
| 264 | * i.e. ".snapshots/" precedes "p".
|
|---|
| [917] | 265 | */
|
|---|
| 266 |
|
|---|
| [988] | 267 | snapdir = lp_parm_const_string(SNUM(handle->conn), "shadow", "snapdir",
|
|---|
| 268 | ".snapshots");
|
|---|
| 269 | snapdirlen = strlen(snapdir);
|
|---|
| 270 | len_before_gmt = p - name;
|
|---|
| [917] | 271 |
|
|---|
| [988] | 272 | if ((len_before_gmt >= (snapdirlen + 1)) && (p[-1] == '/')) {
|
|---|
| 273 | const char *parent_snapdir = p - (snapdirlen+1);
|
|---|
| [917] | 274 |
|
|---|
| [988] | 275 | DEBUG(10, ("parent_snapdir = %s\n", parent_snapdir));
|
|---|
| [917] | 276 |
|
|---|
| [988] | 277 | if (strncmp(parent_snapdir, snapdir, snapdirlen) == 0) {
|
|---|
| 278 | DEBUG(10, ("name=%s is already converted\n", name));
|
|---|
| 279 | goto no_snapshot;
|
|---|
| 280 | }
|
|---|
| 281 | }
|
|---|
| 282 | q = strptime(p, GMT_FORMAT, &tm);
|
|---|
| 283 | if (q == NULL) {
|
|---|
| 284 | DEBUG(10, ("strptime failed\n"));
|
|---|
| 285 | goto no_snapshot;
|
|---|
| 286 | }
|
|---|
| 287 | tm.tm_isdst = -1;
|
|---|
| 288 | timestamp = timegm(&tm);
|
|---|
| 289 | if (timestamp == (time_t)-1) {
|
|---|
| 290 | DEBUG(10, ("timestamp==-1\n"));
|
|---|
| 291 | goto no_snapshot;
|
|---|
| 292 | }
|
|---|
| 293 | if (q[0] == '\0') {
|
|---|
| 294 | /*
|
|---|
| 295 | * The name consists of only the GMT token or the GMT
|
|---|
| 296 | * token is at the end of the path. XP seems to send
|
|---|
| 297 | * @GMT- at the end under certain circumstances even
|
|---|
| 298 | * with a path prefix.
|
|---|
| 299 | */
|
|---|
| 300 | if (pstripped != NULL) {
|
|---|
| 301 | stripped = talloc_strndup(mem_ctx, name, p - name);
|
|---|
| 302 | if (stripped == NULL) {
|
|---|
| 303 | return false;
|
|---|
| 304 | }
|
|---|
| 305 | *pstripped = stripped;
|
|---|
| 306 | }
|
|---|
| 307 | *ptimestamp = timestamp;
|
|---|
| 308 | return true;
|
|---|
| 309 | }
|
|---|
| 310 | if (q[0] != '/') {
|
|---|
| 311 | /*
|
|---|
| 312 | * It is not a complete path component, i.e. the path
|
|---|
| 313 | * component continues after the gmt-token.
|
|---|
| 314 | */
|
|---|
| 315 | DEBUG(10, ("q[0] = %d\n", (int)q[0]));
|
|---|
| 316 | goto no_snapshot;
|
|---|
| 317 | }
|
|---|
| 318 | q += 1;
|
|---|
| [917] | 319 |
|
|---|
| [988] | 320 | rest_len = strlen(q);
|
|---|
| 321 | dst_len = (p-name) + rest_len;
|
|---|
| [917] | 322 |
|
|---|
| [988] | 323 | if (config->snapdirseverywhere) {
|
|---|
| 324 | char *insert;
|
|---|
| 325 | bool have_insert;
|
|---|
| 326 | insert = shadow_copy2_insert_string(talloc_tos(), handle,
|
|---|
| 327 | timestamp);
|
|---|
| 328 | if (insert == NULL) {
|
|---|
| 329 | errno = ENOMEM;
|
|---|
| 330 | return false;
|
|---|
| 331 | }
|
|---|
| [917] | 332 |
|
|---|
| [988] | 333 | DEBUG(10, (__location__ ": snapdirseverywhere mode.\n"
|
|---|
| 334 | "path '%s'.\n"
|
|---|
| 335 | "insert string '%s'\n", name, insert));
|
|---|
| [917] | 336 |
|
|---|
| [988] | 337 | have_insert = (strstr(name, insert+1) != NULL);
|
|---|
| 338 | DEBUG(10, ("have_insert=%d, name=%s, insert+1=%s\n",
|
|---|
| 339 | (int)have_insert, name, insert+1));
|
|---|
| 340 | if (have_insert) {
|
|---|
| 341 | DEBUG(10, (__location__ ": insert string '%s' found in "
|
|---|
| 342 | "path '%s' found in snapdirseverywhere mode "
|
|---|
| 343 | "==> already converted\n", insert, name));
|
|---|
| 344 | TALLOC_FREE(insert);
|
|---|
| 345 | goto no_snapshot;
|
|---|
| 346 | }
|
|---|
| 347 | TALLOC_FREE(insert);
|
|---|
| 348 | } else {
|
|---|
| 349 | char *snapshot_path;
|
|---|
| 350 | char *s;
|
|---|
| [917] | 351 |
|
|---|
| [988] | 352 | snapshot_path = shadow_copy2_snapshot_path(talloc_tos(),
|
|---|
| 353 | handle,
|
|---|
| 354 | timestamp);
|
|---|
| 355 | if (snapshot_path == NULL) {
|
|---|
| 356 | errno = ENOMEM;
|
|---|
| 357 | return false;
|
|---|
| 358 | }
|
|---|
| [917] | 359 |
|
|---|
| [988] | 360 | DEBUG(10, (__location__ " path: '%s'.\n"
|
|---|
| 361 | "snapshot path: '%s'\n", name, snapshot_path));
|
|---|
| [917] | 362 |
|
|---|
| [988] | 363 | s = strstr(name, snapshot_path);
|
|---|
| 364 | if (s == name) {
|
|---|
| 365 | /*
|
|---|
| 366 | * this starts with "snapshot_basepath/GMT-Token"
|
|---|
| 367 | * so it is already a converted absolute
|
|---|
| 368 | * path. Don't process further.
|
|---|
| 369 | */
|
|---|
| 370 | DEBUG(10, (__location__ ": path '%s' starts with "
|
|---|
| 371 | "snapshot path '%s' (not in "
|
|---|
| 372 | "snapdirseverywhere mode) ==> "
|
|---|
| 373 | "already converted\n", name, snapshot_path));
|
|---|
| 374 | talloc_free(snapshot_path);
|
|---|
| 375 | goto no_snapshot;
|
|---|
| 376 | }
|
|---|
| 377 | talloc_free(snapshot_path);
|
|---|
| 378 | }
|
|---|
| [917] | 379 |
|
|---|
| [988] | 380 | if (pstripped != NULL) {
|
|---|
| 381 | stripped = talloc_array(mem_ctx, char, dst_len+1);
|
|---|
| 382 | if (stripped == NULL) {
|
|---|
| 383 | errno = ENOMEM;
|
|---|
| 384 | return false;
|
|---|
| 385 | }
|
|---|
| 386 | if (p > name) {
|
|---|
| 387 | memcpy(stripped, name, p-name);
|
|---|
| 388 | }
|
|---|
| 389 | if (rest_len > 0) {
|
|---|
| 390 | memcpy(stripped + (p-name), q, rest_len);
|
|---|
| 391 | }
|
|---|
| 392 | stripped[dst_len] = '\0';
|
|---|
| 393 | *pstripped = stripped;
|
|---|
| 394 | }
|
|---|
| 395 | *ptimestamp = timestamp;
|
|---|
| 396 | return true;
|
|---|
| 397 | no_snapshot:
|
|---|
| 398 | *ptimestamp = 0;
|
|---|
| 399 | return true;
|
|---|
| 400 | }
|
|---|
| [917] | 401 |
|
|---|
| [988] | 402 | static char *shadow_copy2_find_mount_point(TALLOC_CTX *mem_ctx,
|
|---|
| 403 | vfs_handle_struct *handle)
|
|---|
| [917] | 404 | {
|
|---|
| 405 | char *path = talloc_strdup(mem_ctx, handle->conn->connectpath);
|
|---|
| 406 | dev_t dev;
|
|---|
| 407 | struct stat st;
|
|---|
| 408 | char *p;
|
|---|
| 409 |
|
|---|
| 410 | if (stat(path, &st) != 0) {
|
|---|
| 411 | talloc_free(path);
|
|---|
| 412 | return NULL;
|
|---|
| 413 | }
|
|---|
| 414 |
|
|---|
| 415 | dev = st.st_dev;
|
|---|
| 416 |
|
|---|
| 417 | while ((p = strrchr(path, '/')) && p > path) {
|
|---|
| 418 | *p = 0;
|
|---|
| 419 | if (stat(path, &st) != 0) {
|
|---|
| 420 | talloc_free(path);
|
|---|
| 421 | return NULL;
|
|---|
| 422 | }
|
|---|
| 423 | if (st.st_dev != dev) {
|
|---|
| 424 | *p = '/';
|
|---|
| 425 | break;
|
|---|
| 426 | }
|
|---|
| 427 | }
|
|---|
| 428 |
|
|---|
| [988] | 429 | return path;
|
|---|
| [917] | 430 | }
|
|---|
| 431 |
|
|---|
| [988] | 432 | /**
|
|---|
| 433 | * Convert from a name as handed in via the SMB layer
|
|---|
| 434 | * and a timestamp into the local path of the snapshot
|
|---|
| 435 | * of the provided file at the provided time.
|
|---|
| 436 | * Also return the path in the snapshot corresponding
|
|---|
| 437 | * to the file's share root.
|
|---|
| [917] | 438 | */
|
|---|
| [988] | 439 | static char *shadow_copy2_do_convert(TALLOC_CTX *mem_ctx,
|
|---|
| 440 | struct vfs_handle_struct *handle,
|
|---|
| 441 | const char *name, time_t timestamp,
|
|---|
| 442 | size_t *snaproot_len)
|
|---|
| [917] | 443 | {
|
|---|
| [988] | 444 | struct smb_filename converted_fname;
|
|---|
| 445 | char *result = NULL;
|
|---|
| 446 | size_t *slashes = NULL;
|
|---|
| 447 | unsigned num_slashes;
|
|---|
| 448 | char *path = NULL;
|
|---|
| 449 | size_t pathlen;
|
|---|
| 450 | char *insert = NULL;
|
|---|
| 451 | char *converted = NULL;
|
|---|
| 452 | size_t insertlen, connectlen = 0;
|
|---|
| 453 | int i, saved_errno;
|
|---|
| 454 | size_t min_offset;
|
|---|
| 455 | struct shadow_copy2_config *config;
|
|---|
| 456 | size_t in_share_offset = 0;
|
|---|
| [917] | 457 |
|
|---|
| [988] | 458 | SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
|
|---|
| 459 | return NULL);
|
|---|
| [917] | 460 |
|
|---|
| [988] | 461 | DEBUG(10, ("converting '%s'\n", name));
|
|---|
| [917] | 462 |
|
|---|
| [988] | 463 | if (!config->snapdirseverywhere) {
|
|---|
| 464 | int ret;
|
|---|
| 465 | char *snapshot_path;
|
|---|
| [917] | 466 |
|
|---|
| [988] | 467 | snapshot_path = shadow_copy2_snapshot_path(talloc_tos(),
|
|---|
| 468 | handle,
|
|---|
| 469 | timestamp);
|
|---|
| 470 | if (snapshot_path == NULL) {
|
|---|
| 471 | goto fail;
|
|---|
| 472 | }
|
|---|
| [917] | 473 |
|
|---|
| [988] | 474 | if (config->rel_connectpath == NULL) {
|
|---|
| 475 | converted = talloc_asprintf(mem_ctx, "%s/%s",
|
|---|
| 476 | snapshot_path, name);
|
|---|
| 477 | } else {
|
|---|
| 478 | converted = talloc_asprintf(mem_ctx, "%s/%s/%s",
|
|---|
| 479 | snapshot_path,
|
|---|
| 480 | config->rel_connectpath,
|
|---|
| 481 | name);
|
|---|
| 482 | }
|
|---|
| 483 | if (converted == NULL) {
|
|---|
| 484 | goto fail;
|
|---|
| 485 | }
|
|---|
| [917] | 486 |
|
|---|
| [988] | 487 | ZERO_STRUCT(converted_fname);
|
|---|
| 488 | converted_fname.base_name = converted;
|
|---|
| [917] | 489 |
|
|---|
| [988] | 490 | ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
|
|---|
| 491 | DEBUG(10, ("Trying[not snapdirseverywhere] %s: %d (%s)\n",
|
|---|
| 492 | converted,
|
|---|
| 493 | ret, ret == 0 ? "ok" : strerror(errno)));
|
|---|
| 494 | if (ret == 0) {
|
|---|
| 495 | DEBUG(10, ("Found %s\n", converted));
|
|---|
| 496 | result = converted;
|
|---|
| 497 | converted = NULL;
|
|---|
| 498 | if (snaproot_len != NULL) {
|
|---|
| 499 | *snaproot_len = strlen(snapshot_path);
|
|---|
| 500 | if (config->rel_connectpath != NULL) {
|
|---|
| 501 | *snaproot_len +=
|
|---|
| 502 | strlen(config->rel_connectpath) + 1;
|
|---|
| 503 | }
|
|---|
| 504 | }
|
|---|
| 505 | goto fail;
|
|---|
| 506 | } else {
|
|---|
| 507 | errno = ENOENT;
|
|---|
| 508 | goto fail;
|
|---|
| 509 | }
|
|---|
| 510 | /* never reached ... */
|
|---|
| 511 | }
|
|---|
| [917] | 512 |
|
|---|
| [988] | 513 | connectlen = strlen(handle->conn->connectpath);
|
|---|
| 514 | if (name[0] == 0) {
|
|---|
| 515 | path = talloc_strdup(mem_ctx, handle->conn->connectpath);
|
|---|
| 516 | } else {
|
|---|
| 517 | path = talloc_asprintf(
|
|---|
| 518 | mem_ctx, "%s/%s", handle->conn->connectpath, name);
|
|---|
| 519 | }
|
|---|
| 520 | if (path == NULL) {
|
|---|
| 521 | errno = ENOMEM;
|
|---|
| 522 | goto fail;
|
|---|
| 523 | }
|
|---|
| 524 | pathlen = talloc_get_size(path)-1;
|
|---|
| [917] | 525 |
|
|---|
| [988] | 526 | if (!shadow_copy2_find_slashes(talloc_tos(), path,
|
|---|
| 527 | &slashes, &num_slashes)) {
|
|---|
| 528 | goto fail;
|
|---|
| [917] | 529 | }
|
|---|
| 530 |
|
|---|
| [988] | 531 | insert = shadow_copy2_insert_string(talloc_tos(), handle, timestamp);
|
|---|
| 532 | if (insert == NULL) {
|
|---|
| 533 | goto fail;
|
|---|
| [917] | 534 | }
|
|---|
| [988] | 535 | insertlen = talloc_get_size(insert)-1;
|
|---|
| [917] | 536 |
|
|---|
| [988] | 537 | /*
|
|---|
| 538 | * Note: We deliberatly don't expensively initialize the
|
|---|
| 539 | * array with talloc_zero here: Putting zero into
|
|---|
| 540 | * converted[pathlen+insertlen] below is sufficient, because
|
|---|
| 541 | * in the following for loop, the insert string is inserted
|
|---|
| 542 | * at various slash places. So the memory up to position
|
|---|
| 543 | * pathlen+insertlen will always be initialized when the
|
|---|
| 544 | * converted string is used.
|
|---|
| 545 | */
|
|---|
| 546 | converted = talloc_array(mem_ctx, char, pathlen + insertlen + 1);
|
|---|
| 547 | if (converted == NULL) {
|
|---|
| 548 | goto fail;
|
|---|
| [917] | 549 | }
|
|---|
| 550 |
|
|---|
| [988] | 551 | if (path[pathlen-1] != '/') {
|
|---|
| 552 | /*
|
|---|
| 553 | * Append a fake slash to find the snapshot root
|
|---|
| 554 | */
|
|---|
| 555 | size_t *tmp;
|
|---|
| 556 | tmp = talloc_realloc(talloc_tos(), slashes,
|
|---|
| 557 | size_t, num_slashes+1);
|
|---|
| 558 | if (tmp == NULL) {
|
|---|
| 559 | goto fail;
|
|---|
| [917] | 560 | }
|
|---|
| [988] | 561 | slashes = tmp;
|
|---|
| 562 | slashes[num_slashes] = pathlen;
|
|---|
| 563 | num_slashes += 1;
|
|---|
| [917] | 564 | }
|
|---|
| 565 |
|
|---|
| [988] | 566 | min_offset = 0;
|
|---|
| 567 |
|
|---|
| 568 | if (!config->crossmountpoints) {
|
|---|
| 569 | min_offset = strlen(config->mount_point);
|
|---|
| [917] | 570 | }
|
|---|
| 571 |
|
|---|
| [988] | 572 | memcpy(converted, path, pathlen+1);
|
|---|
| 573 | converted[pathlen+insertlen] = '\0';
|
|---|
| [917] | 574 |
|
|---|
| [988] | 575 | ZERO_STRUCT(converted_fname);
|
|---|
| 576 | converted_fname.base_name = converted;
|
|---|
| [917] | 577 |
|
|---|
| [988] | 578 | for (i = num_slashes-1; i>=0; i--) {
|
|---|
| 579 | int ret;
|
|---|
| 580 | size_t offset;
|
|---|
| [917] | 581 |
|
|---|
| [988] | 582 | offset = slashes[i];
|
|---|
| [917] | 583 |
|
|---|
| [988] | 584 | if (offset < min_offset) {
|
|---|
| 585 | errno = ENOENT;
|
|---|
| 586 | goto fail;
|
|---|
| 587 | }
|
|---|
| 588 |
|
|---|
| 589 | if (offset >= connectlen) {
|
|---|
| 590 | in_share_offset = offset;
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | memcpy(converted+offset, insert, insertlen);
|
|---|
| 594 |
|
|---|
| 595 | offset += insertlen;
|
|---|
| 596 | memcpy(converted+offset, path + slashes[i],
|
|---|
| 597 | pathlen - slashes[i]);
|
|---|
| 598 |
|
|---|
| 599 | ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
|
|---|
| 600 |
|
|---|
| 601 | DEBUG(10, ("Trying[snapdirseverywhere] %s: %d (%s)\n",
|
|---|
| 602 | converted,
|
|---|
| 603 | ret, ret == 0 ? "ok" : strerror(errno)));
|
|---|
| 604 | if (ret == 0) {
|
|---|
| 605 | /* success */
|
|---|
| 606 | if (snaproot_len != NULL) {
|
|---|
| 607 | *snaproot_len = in_share_offset + insertlen;
|
|---|
| 608 | }
|
|---|
| 609 | break;
|
|---|
| 610 | }
|
|---|
| 611 | if (errno == ENOTDIR) {
|
|---|
| 612 | /*
|
|---|
| 613 | * This is a valid condition: We appended the
|
|---|
| 614 | * .snaphots/@GMT.. to a file name. Just try
|
|---|
| 615 | * with the upper levels.
|
|---|
| 616 | */
|
|---|
| 617 | continue;
|
|---|
| 618 | }
|
|---|
| 619 | if (errno != ENOENT) {
|
|---|
| 620 | /* Other problem than "not found" */
|
|---|
| 621 | goto fail;
|
|---|
| 622 | }
|
|---|
| [917] | 623 | }
|
|---|
| 624 |
|
|---|
| [988] | 625 | if (i >= 0) {
|
|---|
| 626 | /*
|
|---|
| 627 | * Found something
|
|---|
| 628 | */
|
|---|
| 629 | DEBUG(10, ("Found %s\n", converted));
|
|---|
| 630 | result = converted;
|
|---|
| 631 | converted = NULL;
|
|---|
| 632 | } else {
|
|---|
| 633 | errno = ENOENT;
|
|---|
| 634 | }
|
|---|
| 635 | fail:
|
|---|
| 636 | saved_errno = errno;
|
|---|
| 637 | TALLOC_FREE(converted);
|
|---|
| 638 | TALLOC_FREE(insert);
|
|---|
| 639 | TALLOC_FREE(slashes);
|
|---|
| 640 | TALLOC_FREE(path);
|
|---|
| 641 | errno = saved_errno;
|
|---|
| 642 | return result;
|
|---|
| [917] | 643 | }
|
|---|
| 644 |
|
|---|
| [988] | 645 | /**
|
|---|
| 646 | * Convert from a name as handed in via the SMB layer
|
|---|
| 647 | * and a timestamp into the local path of the snapshot
|
|---|
| 648 | * of the provided file at the provided time.
|
|---|
| [917] | 649 | */
|
|---|
| [988] | 650 | static char *shadow_copy2_convert(TALLOC_CTX *mem_ctx,
|
|---|
| 651 | struct vfs_handle_struct *handle,
|
|---|
| 652 | const char *name, time_t timestamp)
|
|---|
| [917] | 653 | {
|
|---|
| [988] | 654 | return shadow_copy2_do_convert(mem_ctx, handle, name, timestamp, NULL);
|
|---|
| [917] | 655 | }
|
|---|
| 656 |
|
|---|
| 657 | /*
|
|---|
| 658 | modify a sbuf return to ensure that inodes in the shadow directory
|
|---|
| 659 | are different from those in the main directory
|
|---|
| 660 | */
|
|---|
| [988] | 661 | static void convert_sbuf(vfs_handle_struct *handle, const char *fname,
|
|---|
| 662 | SMB_STRUCT_STAT *sbuf)
|
|---|
| [917] | 663 | {
|
|---|
| [988] | 664 | struct shadow_copy2_config *config;
|
|---|
| 665 |
|
|---|
| 666 | SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
|
|---|
| 667 | return);
|
|---|
| 668 |
|
|---|
| 669 | if (config->fixinodes) {
|
|---|
| [917] | 670 | /* some snapshot systems, like GPFS, return the name
|
|---|
| 671 | device:inode for the snapshot files as the current
|
|---|
| 672 | files. That breaks the 'restore' button in the shadow copy
|
|---|
| 673 | GUI, as the client gets a sharing violation.
|
|---|
| 674 |
|
|---|
| 675 | This is a crude way of allowing both files to be
|
|---|
| 676 | open at once. It has a slight chance of inode
|
|---|
| 677 | number collision, but I can't see a better approach
|
|---|
| 678 | without significant VFS changes
|
|---|
| 679 | */
|
|---|
| [988] | 680 | TDB_DATA key = { .dptr = discard_const_p(uint8_t, fname),
|
|---|
| 681 | .dsize = strlen(fname) };
|
|---|
| 682 | uint32_t shash;
|
|---|
| 683 |
|
|---|
| 684 | shash = tdb_jenkins_hash(&key) & 0xFF000000;
|
|---|
| [917] | 685 | if (shash == 0) {
|
|---|
| 686 | shash = 1;
|
|---|
| 687 | }
|
|---|
| 688 | sbuf->st_ex_ino ^= shash;
|
|---|
| 689 | }
|
|---|
| 690 | }
|
|---|
| 691 |
|
|---|
| [988] | 692 | static DIR *shadow_copy2_opendir(vfs_handle_struct *handle,
|
|---|
| 693 | const char *fname,
|
|---|
| 694 | const char *mask,
|
|---|
| 695 | uint32_t attr)
|
|---|
| 696 | {
|
|---|
| 697 | time_t timestamp;
|
|---|
| 698 | char *stripped;
|
|---|
| 699 | DIR *ret;
|
|---|
| 700 | int saved_errno;
|
|---|
| 701 | char *conv;
|
|---|
| 702 |
|
|---|
| 703 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 704 | ×tamp, &stripped)) {
|
|---|
| 705 | return NULL;
|
|---|
| 706 | }
|
|---|
| 707 | if (timestamp == 0) {
|
|---|
| 708 | return SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
|
|---|
| 709 | }
|
|---|
| 710 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 711 | TALLOC_FREE(stripped);
|
|---|
| 712 | if (conv == NULL) {
|
|---|
| 713 | return NULL;
|
|---|
| 714 | }
|
|---|
| 715 | ret = SMB_VFS_NEXT_OPENDIR(handle, conv, mask, attr);
|
|---|
| 716 | saved_errno = errno;
|
|---|
| 717 | TALLOC_FREE(conv);
|
|---|
| 718 | errno = saved_errno;
|
|---|
| 719 | return ret;
|
|---|
| 720 | }
|
|---|
| 721 |
|
|---|
| [917] | 722 | static int shadow_copy2_rename(vfs_handle_struct *handle,
|
|---|
| 723 | const struct smb_filename *smb_fname_src,
|
|---|
| 724 | const struct smb_filename *smb_fname_dst)
|
|---|
| 725 | {
|
|---|
| [988] | 726 | time_t timestamp_src, timestamp_dst;
|
|---|
| 727 |
|
|---|
| 728 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
|
|---|
| 729 | smb_fname_src->base_name,
|
|---|
| 730 | ×tamp_src, NULL)) {
|
|---|
| 731 | return -1;
|
|---|
| 732 | }
|
|---|
| 733 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
|
|---|
| 734 | smb_fname_dst->base_name,
|
|---|
| 735 | ×tamp_dst, NULL)) {
|
|---|
| 736 | return -1;
|
|---|
| 737 | }
|
|---|
| 738 | if (timestamp_src != 0) {
|
|---|
| [917] | 739 | errno = EXDEV;
|
|---|
| 740 | return -1;
|
|---|
| 741 | }
|
|---|
| [988] | 742 | if (timestamp_dst != 0) {
|
|---|
| 743 | errno = EROFS;
|
|---|
| 744 | return -1;
|
|---|
| 745 | }
|
|---|
| 746 | return SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
|
|---|
| [917] | 747 | }
|
|---|
| 748 |
|
|---|
| 749 | static int shadow_copy2_symlink(vfs_handle_struct *handle,
|
|---|
| 750 | const char *oldname, const char *newname)
|
|---|
| 751 | {
|
|---|
| [988] | 752 | time_t timestamp_old, timestamp_new;
|
|---|
| 753 |
|
|---|
| 754 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, oldname,
|
|---|
| 755 | ×tamp_old, NULL)) {
|
|---|
| 756 | return -1;
|
|---|
| 757 | }
|
|---|
| 758 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, newname,
|
|---|
| 759 | ×tamp_new, NULL)) {
|
|---|
| 760 | return -1;
|
|---|
| 761 | }
|
|---|
| 762 | if ((timestamp_old != 0) || (timestamp_new != 0)) {
|
|---|
| 763 | errno = EROFS;
|
|---|
| 764 | return -1;
|
|---|
| 765 | }
|
|---|
| 766 | return SMB_VFS_NEXT_SYMLINK(handle, oldname, newname);
|
|---|
| [917] | 767 | }
|
|---|
| 768 |
|
|---|
| 769 | static int shadow_copy2_link(vfs_handle_struct *handle,
|
|---|
| [988] | 770 | const char *oldname, const char *newname)
|
|---|
| [917] | 771 | {
|
|---|
| [988] | 772 | time_t timestamp_old, timestamp_new;
|
|---|
| [917] | 773 |
|
|---|
| [988] | 774 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, oldname,
|
|---|
| 775 | ×tamp_old, NULL)) {
|
|---|
| 776 | return -1;
|
|---|
| 777 | }
|
|---|
| 778 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, newname,
|
|---|
| 779 | ×tamp_new, NULL)) {
|
|---|
| 780 | return -1;
|
|---|
| 781 | }
|
|---|
| 782 | if ((timestamp_old != 0) || (timestamp_new != 0)) {
|
|---|
| 783 | errno = EROFS;
|
|---|
| 784 | return -1;
|
|---|
| 785 | }
|
|---|
| 786 | return SMB_VFS_NEXT_LINK(handle, oldname, newname);
|
|---|
| [917] | 787 | }
|
|---|
| 788 |
|
|---|
| 789 | static int shadow_copy2_stat(vfs_handle_struct *handle,
|
|---|
| 790 | struct smb_filename *smb_fname)
|
|---|
| 791 | {
|
|---|
| [988] | 792 | time_t timestamp;
|
|---|
| 793 | char *stripped, *tmp;
|
|---|
| 794 | int ret, saved_errno;
|
|---|
| 795 |
|
|---|
| 796 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
|
|---|
| 797 | smb_fname->base_name,
|
|---|
| 798 | ×tamp, &stripped)) {
|
|---|
| 799 | return -1;
|
|---|
| 800 | }
|
|---|
| 801 | if (timestamp == 0) {
|
|---|
| 802 | return SMB_VFS_NEXT_STAT(handle, smb_fname);
|
|---|
| 803 | }
|
|---|
| 804 |
|
|---|
| 805 | tmp = smb_fname->base_name;
|
|---|
| 806 | smb_fname->base_name = shadow_copy2_convert(
|
|---|
| 807 | talloc_tos(), handle, stripped, timestamp);
|
|---|
| 808 | TALLOC_FREE(stripped);
|
|---|
| 809 |
|
|---|
| 810 | if (smb_fname->base_name == NULL) {
|
|---|
| 811 | smb_fname->base_name = tmp;
|
|---|
| 812 | return -1;
|
|---|
| 813 | }
|
|---|
| 814 |
|
|---|
| 815 | ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
|
|---|
| 816 | saved_errno = errno;
|
|---|
| 817 |
|
|---|
| 818 | TALLOC_FREE(smb_fname->base_name);
|
|---|
| 819 | smb_fname->base_name = tmp;
|
|---|
| 820 |
|
|---|
| 821 | if (ret == 0) {
|
|---|
| 822 | convert_sbuf(handle, smb_fname->base_name, &smb_fname->st);
|
|---|
| 823 | }
|
|---|
| 824 | errno = saved_errno;
|
|---|
| 825 | return ret;
|
|---|
| [917] | 826 | }
|
|---|
| 827 |
|
|---|
| 828 | static int shadow_copy2_lstat(vfs_handle_struct *handle,
|
|---|
| 829 | struct smb_filename *smb_fname)
|
|---|
| 830 | {
|
|---|
| [988] | 831 | time_t timestamp;
|
|---|
| 832 | char *stripped, *tmp;
|
|---|
| 833 | int ret, saved_errno;
|
|---|
| 834 |
|
|---|
| 835 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
|
|---|
| 836 | smb_fname->base_name,
|
|---|
| 837 | ×tamp, &stripped)) {
|
|---|
| 838 | return -1;
|
|---|
| 839 | }
|
|---|
| 840 | if (timestamp == 0) {
|
|---|
| 841 | return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
|
|---|
| 842 | }
|
|---|
| 843 |
|
|---|
| 844 | tmp = smb_fname->base_name;
|
|---|
| 845 | smb_fname->base_name = shadow_copy2_convert(
|
|---|
| 846 | talloc_tos(), handle, stripped, timestamp);
|
|---|
| 847 | TALLOC_FREE(stripped);
|
|---|
| 848 |
|
|---|
| 849 | if (smb_fname->base_name == NULL) {
|
|---|
| 850 | smb_fname->base_name = tmp;
|
|---|
| 851 | return -1;
|
|---|
| 852 | }
|
|---|
| 853 |
|
|---|
| 854 | ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
|
|---|
| 855 | saved_errno = errno;
|
|---|
| 856 |
|
|---|
| 857 | TALLOC_FREE(smb_fname->base_name);
|
|---|
| 858 | smb_fname->base_name = tmp;
|
|---|
| 859 |
|
|---|
| 860 | if (ret == 0) {
|
|---|
| 861 | convert_sbuf(handle, smb_fname->base_name, &smb_fname->st);
|
|---|
| 862 | }
|
|---|
| 863 | errno = saved_errno;
|
|---|
| 864 | return ret;
|
|---|
| [917] | 865 | }
|
|---|
| 866 |
|
|---|
| [988] | 867 | static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp,
|
|---|
| 868 | SMB_STRUCT_STAT *sbuf)
|
|---|
| [917] | 869 | {
|
|---|
| [988] | 870 | time_t timestamp;
|
|---|
| 871 | int ret;
|
|---|
| 872 |
|
|---|
| 873 | ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
|
|---|
| 874 | if (ret == -1) {
|
|---|
| 875 | return ret;
|
|---|
| 876 | }
|
|---|
| 877 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
|
|---|
| 878 | fsp->fsp_name->base_name,
|
|---|
| 879 | ×tamp, NULL)) {
|
|---|
| 880 | return 0;
|
|---|
| 881 | }
|
|---|
| 882 | if (timestamp != 0) {
|
|---|
| [917] | 883 | convert_sbuf(handle, fsp->fsp_name->base_name, sbuf);
|
|---|
| 884 | }
|
|---|
| [988] | 885 | return 0;
|
|---|
| 886 | }
|
|---|
| 887 |
|
|---|
| 888 | static int shadow_copy2_open(vfs_handle_struct *handle,
|
|---|
| 889 | struct smb_filename *smb_fname, files_struct *fsp,
|
|---|
| 890 | int flags, mode_t mode)
|
|---|
| 891 | {
|
|---|
| 892 | time_t timestamp;
|
|---|
| 893 | char *stripped, *tmp;
|
|---|
| 894 | int ret, saved_errno;
|
|---|
| 895 |
|
|---|
| 896 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
|
|---|
| 897 | smb_fname->base_name,
|
|---|
| 898 | ×tamp, &stripped)) {
|
|---|
| 899 | return -1;
|
|---|
| 900 | }
|
|---|
| 901 | if (timestamp == 0) {
|
|---|
| 902 | return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
|
|---|
| 903 | }
|
|---|
| 904 |
|
|---|
| 905 | tmp = smb_fname->base_name;
|
|---|
| 906 | smb_fname->base_name = shadow_copy2_convert(
|
|---|
| 907 | talloc_tos(), handle, stripped, timestamp);
|
|---|
| 908 | TALLOC_FREE(stripped);
|
|---|
| 909 |
|
|---|
| 910 | if (smb_fname->base_name == NULL) {
|
|---|
| 911 | smb_fname->base_name = tmp;
|
|---|
| 912 | return -1;
|
|---|
| 913 | }
|
|---|
| 914 |
|
|---|
| 915 | ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
|
|---|
| 916 | saved_errno = errno;
|
|---|
| 917 |
|
|---|
| 918 | TALLOC_FREE(smb_fname->base_name);
|
|---|
| 919 | smb_fname->base_name = tmp;
|
|---|
| 920 |
|
|---|
| 921 | errno = saved_errno;
|
|---|
| [917] | 922 | return ret;
|
|---|
| 923 | }
|
|---|
| 924 |
|
|---|
| 925 | static int shadow_copy2_unlink(vfs_handle_struct *handle,
|
|---|
| [988] | 926 | const struct smb_filename *smb_fname)
|
|---|
| [917] | 927 | {
|
|---|
| [988] | 928 | time_t timestamp;
|
|---|
| 929 | char *stripped;
|
|---|
| 930 | int ret, saved_errno;
|
|---|
| 931 | struct smb_filename *conv;
|
|---|
| [917] | 932 |
|
|---|
| [988] | 933 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
|
|---|
| 934 | smb_fname->base_name,
|
|---|
| 935 | ×tamp, &stripped)) {
|
|---|
| [917] | 936 | return -1;
|
|---|
| 937 | }
|
|---|
| [988] | 938 | if (timestamp == 0) {
|
|---|
| 939 | return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
|
|---|
| 940 | }
|
|---|
| 941 | conv = cp_smb_filename(talloc_tos(), smb_fname);
|
|---|
| 942 | if (conv == NULL) {
|
|---|
| 943 | errno = ENOMEM;
|
|---|
| 944 | return -1;
|
|---|
| 945 | }
|
|---|
| 946 | conv->base_name = shadow_copy2_convert(
|
|---|
| 947 | conv, handle, stripped, timestamp);
|
|---|
| 948 | TALLOC_FREE(stripped);
|
|---|
| 949 | if (conv->base_name == NULL) {
|
|---|
| 950 | return -1;
|
|---|
| 951 | }
|
|---|
| 952 | ret = SMB_VFS_NEXT_UNLINK(handle, conv);
|
|---|
| 953 | saved_errno = errno;
|
|---|
| 954 | TALLOC_FREE(conv);
|
|---|
| 955 | errno = saved_errno;
|
|---|
| 956 | return ret;
|
|---|
| [917] | 957 | }
|
|---|
| 958 |
|
|---|
| [988] | 959 | static int shadow_copy2_chmod(vfs_handle_struct *handle, const char *fname,
|
|---|
| 960 | mode_t mode)
|
|---|
| [917] | 961 | {
|
|---|
| [988] | 962 | time_t timestamp;
|
|---|
| 963 | char *stripped;
|
|---|
| 964 | int ret, saved_errno;
|
|---|
| 965 | char *conv;
|
|---|
| 966 |
|
|---|
| 967 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 968 | ×tamp, &stripped)) {
|
|---|
| 969 | return -1;
|
|---|
| 970 | }
|
|---|
| 971 | if (timestamp == 0) {
|
|---|
| 972 | return SMB_VFS_NEXT_CHMOD(handle, fname, mode);
|
|---|
| 973 | }
|
|---|
| 974 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 975 | TALLOC_FREE(stripped);
|
|---|
| 976 | if (conv == NULL) {
|
|---|
| 977 | return -1;
|
|---|
| 978 | }
|
|---|
| 979 | ret = SMB_VFS_NEXT_CHMOD(handle, conv, mode);
|
|---|
| 980 | saved_errno = errno;
|
|---|
| 981 | TALLOC_FREE(conv);
|
|---|
| 982 | errno = saved_errno;
|
|---|
| 983 | return ret;
|
|---|
| [917] | 984 | }
|
|---|
| 985 |
|
|---|
| [988] | 986 | static int shadow_copy2_chown(vfs_handle_struct *handle, const char *fname,
|
|---|
| 987 | uid_t uid, gid_t gid)
|
|---|
| [917] | 988 | {
|
|---|
| [988] | 989 | time_t timestamp;
|
|---|
| 990 | char *stripped;
|
|---|
| 991 | int ret, saved_errno;
|
|---|
| 992 | char *conv;
|
|---|
| 993 |
|
|---|
| 994 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 995 | ×tamp, &stripped)) {
|
|---|
| 996 | return -1;
|
|---|
| 997 | }
|
|---|
| 998 | if (timestamp == 0) {
|
|---|
| 999 | return SMB_VFS_NEXT_CHOWN(handle, fname, uid, gid);
|
|---|
| 1000 | }
|
|---|
| 1001 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1002 | TALLOC_FREE(stripped);
|
|---|
| 1003 | if (conv == NULL) {
|
|---|
| 1004 | return -1;
|
|---|
| 1005 | }
|
|---|
| 1006 | ret = SMB_VFS_NEXT_CHOWN(handle, conv, uid, gid);
|
|---|
| 1007 | saved_errno = errno;
|
|---|
| 1008 | TALLOC_FREE(conv);
|
|---|
| 1009 | errno = saved_errno;
|
|---|
| 1010 | return ret;
|
|---|
| [917] | 1011 | }
|
|---|
| 1012 |
|
|---|
| 1013 | static int shadow_copy2_chdir(vfs_handle_struct *handle,
|
|---|
| [988] | 1014 | const char *fname)
|
|---|
| [917] | 1015 | {
|
|---|
| [988] | 1016 | time_t timestamp;
|
|---|
| 1017 | char *stripped;
|
|---|
| 1018 | int ret, saved_errno;
|
|---|
| 1019 | char *conv;
|
|---|
| 1020 |
|
|---|
| 1021 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1022 | ×tamp, &stripped)) {
|
|---|
| 1023 | return -1;
|
|---|
| 1024 | }
|
|---|
| 1025 | if (timestamp == 0) {
|
|---|
| 1026 | return SMB_VFS_NEXT_CHDIR(handle, fname);
|
|---|
| 1027 | }
|
|---|
| 1028 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1029 | TALLOC_FREE(stripped);
|
|---|
| 1030 | if (conv == NULL) {
|
|---|
| 1031 | return -1;
|
|---|
| 1032 | }
|
|---|
| 1033 | ret = SMB_VFS_NEXT_CHDIR(handle, conv);
|
|---|
| 1034 | saved_errno = errno;
|
|---|
| 1035 | TALLOC_FREE(conv);
|
|---|
| 1036 | errno = saved_errno;
|
|---|
| 1037 | return ret;
|
|---|
| [917] | 1038 | }
|
|---|
| 1039 |
|
|---|
| 1040 | static int shadow_copy2_ntimes(vfs_handle_struct *handle,
|
|---|
| [988] | 1041 | const struct smb_filename *smb_fname,
|
|---|
| [917] | 1042 | struct smb_file_time *ft)
|
|---|
| 1043 | {
|
|---|
| [988] | 1044 | time_t timestamp;
|
|---|
| 1045 | char *stripped;
|
|---|
| 1046 | int ret, saved_errno;
|
|---|
| 1047 | struct smb_filename *conv;
|
|---|
| [917] | 1048 |
|
|---|
| [988] | 1049 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
|
|---|
| 1050 | smb_fname->base_name,
|
|---|
| 1051 | ×tamp, &stripped)) {
|
|---|
| [917] | 1052 | return -1;
|
|---|
| 1053 | }
|
|---|
| [988] | 1054 | if (timestamp == 0) {
|
|---|
| 1055 | return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
|
|---|
| 1056 | }
|
|---|
| 1057 | conv = cp_smb_filename(talloc_tos(), smb_fname);
|
|---|
| 1058 | if (conv == NULL) {
|
|---|
| 1059 | errno = ENOMEM;
|
|---|
| 1060 | return -1;
|
|---|
| 1061 | }
|
|---|
| 1062 | conv->base_name = shadow_copy2_convert(
|
|---|
| 1063 | conv, handle, stripped, timestamp);
|
|---|
| 1064 | TALLOC_FREE(stripped);
|
|---|
| 1065 | if (conv->base_name == NULL) {
|
|---|
| 1066 | return -1;
|
|---|
| 1067 | }
|
|---|
| 1068 | ret = SMB_VFS_NEXT_NTIMES(handle, conv, ft);
|
|---|
| 1069 | saved_errno = errno;
|
|---|
| 1070 | TALLOC_FREE(conv);
|
|---|
| 1071 | errno = saved_errno;
|
|---|
| 1072 | return ret;
|
|---|
| [917] | 1073 | }
|
|---|
| 1074 |
|
|---|
| 1075 | static int shadow_copy2_readlink(vfs_handle_struct *handle,
|
|---|
| 1076 | const char *fname, char *buf, size_t bufsiz)
|
|---|
| 1077 | {
|
|---|
| [988] | 1078 | time_t timestamp;
|
|---|
| 1079 | char *stripped;
|
|---|
| 1080 | int ret, saved_errno;
|
|---|
| 1081 | char *conv;
|
|---|
| 1082 |
|
|---|
| 1083 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1084 | ×tamp, &stripped)) {
|
|---|
| 1085 | return -1;
|
|---|
| 1086 | }
|
|---|
| 1087 | if (timestamp == 0) {
|
|---|
| 1088 | return SMB_VFS_NEXT_READLINK(handle, fname, buf, bufsiz);
|
|---|
| 1089 | }
|
|---|
| 1090 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1091 | TALLOC_FREE(stripped);
|
|---|
| 1092 | if (conv == NULL) {
|
|---|
| 1093 | return -1;
|
|---|
| 1094 | }
|
|---|
| 1095 | ret = SMB_VFS_NEXT_READLINK(handle, conv, buf, bufsiz);
|
|---|
| 1096 | saved_errno = errno;
|
|---|
| 1097 | TALLOC_FREE(conv);
|
|---|
| 1098 | errno = saved_errno;
|
|---|
| 1099 | return ret;
|
|---|
| [917] | 1100 | }
|
|---|
| 1101 |
|
|---|
| 1102 | static int shadow_copy2_mknod(vfs_handle_struct *handle,
|
|---|
| [988] | 1103 | const char *fname, mode_t mode, SMB_DEV_T dev)
|
|---|
| [917] | 1104 | {
|
|---|
| [988] | 1105 | time_t timestamp;
|
|---|
| 1106 | char *stripped;
|
|---|
| 1107 | int ret, saved_errno;
|
|---|
| 1108 | char *conv;
|
|---|
| 1109 |
|
|---|
| 1110 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1111 | ×tamp, &stripped)) {
|
|---|
| 1112 | return -1;
|
|---|
| 1113 | }
|
|---|
| 1114 | if (timestamp == 0) {
|
|---|
| 1115 | return SMB_VFS_NEXT_MKNOD(handle, fname, mode, dev);
|
|---|
| 1116 | }
|
|---|
| 1117 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1118 | TALLOC_FREE(stripped);
|
|---|
| 1119 | if (conv == NULL) {
|
|---|
| 1120 | return -1;
|
|---|
| 1121 | }
|
|---|
| 1122 | ret = SMB_VFS_NEXT_MKNOD(handle, conv, mode, dev);
|
|---|
| 1123 | saved_errno = errno;
|
|---|
| 1124 | TALLOC_FREE(conv);
|
|---|
| 1125 | errno = saved_errno;
|
|---|
| 1126 | return ret;
|
|---|
| [917] | 1127 | }
|
|---|
| 1128 |
|
|---|
| 1129 | static char *shadow_copy2_realpath(vfs_handle_struct *handle,
|
|---|
| [988] | 1130 | const char *fname)
|
|---|
| [917] | 1131 | {
|
|---|
| [988] | 1132 | time_t timestamp;
|
|---|
| 1133 | char *stripped = NULL;
|
|---|
| 1134 | char *tmp = NULL;
|
|---|
| 1135 | char *result = NULL;
|
|---|
| 1136 | int saved_errno;
|
|---|
| [917] | 1137 |
|
|---|
| [988] | 1138 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1139 | ×tamp, &stripped)) {
|
|---|
| 1140 | goto done;
|
|---|
| 1141 | }
|
|---|
| 1142 | if (timestamp == 0) {
|
|---|
| 1143 | return SMB_VFS_NEXT_REALPATH(handle, fname);
|
|---|
| 1144 | }
|
|---|
| [917] | 1145 |
|
|---|
| [988] | 1146 | tmp = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1147 | if (tmp == NULL) {
|
|---|
| 1148 | goto done;
|
|---|
| 1149 | }
|
|---|
| [917] | 1150 |
|
|---|
| [988] | 1151 | result = SMB_VFS_NEXT_REALPATH(handle, tmp);
|
|---|
| [917] | 1152 |
|
|---|
| [988] | 1153 | done:
|
|---|
| 1154 | saved_errno = errno;
|
|---|
| 1155 | TALLOC_FREE(tmp);
|
|---|
| 1156 | TALLOC_FREE(stripped);
|
|---|
| 1157 | errno = saved_errno;
|
|---|
| 1158 | return result;
|
|---|
| [917] | 1159 | }
|
|---|
| 1160 |
|
|---|
| [988] | 1161 | /**
|
|---|
| 1162 | * Check whether a given directory contains a
|
|---|
| 1163 | * snapshot directory as direct subdirectory.
|
|---|
| 1164 | * If yes, return the path of the snapshot-subdir,
|
|---|
| 1165 | * otherwise return NULL.
|
|---|
| 1166 | */
|
|---|
| 1167 | static char *have_snapdir(struct vfs_handle_struct *handle,
|
|---|
| 1168 | const char *path)
|
|---|
| [917] | 1169 | {
|
|---|
| [988] | 1170 | struct smb_filename smb_fname;
|
|---|
| 1171 | int ret;
|
|---|
| 1172 | struct shadow_copy2_config *config;
|
|---|
| [917] | 1173 |
|
|---|
| [988] | 1174 | SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
|
|---|
| 1175 | return NULL);
|
|---|
| [917] | 1176 |
|
|---|
| [988] | 1177 | ZERO_STRUCT(smb_fname);
|
|---|
| 1178 | smb_fname.base_name = talloc_asprintf(talloc_tos(), "%s/%s",
|
|---|
| 1179 | path, config->snapdir);
|
|---|
| 1180 | if (smb_fname.base_name == NULL) {
|
|---|
| [917] | 1181 | return NULL;
|
|---|
| 1182 | }
|
|---|
| 1183 |
|
|---|
| [988] | 1184 | ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
|
|---|
| 1185 | if ((ret == 0) && (S_ISDIR(smb_fname.st.st_ex_mode))) {
|
|---|
| 1186 | return smb_fname.base_name;
|
|---|
| [917] | 1187 | }
|
|---|
| [988] | 1188 | TALLOC_FREE(smb_fname.base_name);
|
|---|
| 1189 | return NULL;
|
|---|
| [917] | 1190 | }
|
|---|
| 1191 |
|
|---|
| [919] | 1192 | static bool check_access_snapdir(struct vfs_handle_struct *handle,
|
|---|
| 1193 | const char *path)
|
|---|
| 1194 | {
|
|---|
| 1195 | struct smb_filename smb_fname;
|
|---|
| 1196 | int ret;
|
|---|
| 1197 | NTSTATUS status;
|
|---|
| 1198 |
|
|---|
| 1199 | ZERO_STRUCT(smb_fname);
|
|---|
| 1200 | smb_fname.base_name = talloc_asprintf(talloc_tos(),
|
|---|
| 1201 | "%s",
|
|---|
| 1202 | path);
|
|---|
| 1203 | if (smb_fname.base_name == NULL) {
|
|---|
| 1204 | return false;
|
|---|
| 1205 | }
|
|---|
| 1206 |
|
|---|
| 1207 | ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
|
|---|
| 1208 | if (ret != 0 || !S_ISDIR(smb_fname.st.st_ex_mode)) {
|
|---|
| 1209 | TALLOC_FREE(smb_fname.base_name);
|
|---|
| 1210 | return false;
|
|---|
| 1211 | }
|
|---|
| 1212 |
|
|---|
| [988] | 1213 | status = smbd_check_access_rights(handle->conn,
|
|---|
| [919] | 1214 | &smb_fname,
|
|---|
| [988] | 1215 | false,
|
|---|
| 1216 | SEC_DIR_LIST);
|
|---|
| [919] | 1217 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 1218 | DEBUG(0,("user does not have list permission "
|
|---|
| 1219 | "on snapdir %s\n",
|
|---|
| 1220 | smb_fname.base_name));
|
|---|
| 1221 | TALLOC_FREE(smb_fname.base_name);
|
|---|
| 1222 | return false;
|
|---|
| 1223 | }
|
|---|
| 1224 | TALLOC_FREE(smb_fname.base_name);
|
|---|
| 1225 | return true;
|
|---|
| 1226 | }
|
|---|
| 1227 |
|
|---|
| [988] | 1228 | /**
|
|---|
| 1229 | * Find the snapshot directory (if any) for the given
|
|---|
| 1230 | * filename (which is relative to the share).
|
|---|
| 1231 | */
|
|---|
| 1232 | static const char *shadow_copy2_find_snapdir(TALLOC_CTX *mem_ctx,
|
|---|
| 1233 | struct vfs_handle_struct *handle,
|
|---|
| 1234 | struct smb_filename *smb_fname)
|
|---|
| [917] | 1235 | {
|
|---|
| [988] | 1236 | char *path, *p;
|
|---|
| 1237 | const char *snapdir;
|
|---|
| 1238 | struct shadow_copy2_config *config;
|
|---|
| [917] | 1239 |
|
|---|
| [988] | 1240 | SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
|
|---|
| 1241 | return NULL);
|
|---|
| [917] | 1242 |
|
|---|
| [988] | 1243 | /*
|
|---|
| 1244 | * If the non-snapdisrseverywhere mode, we should not search!
|
|---|
| 1245 | */
|
|---|
| 1246 | if (!config->snapdirseverywhere) {
|
|---|
| 1247 | return config->snapshot_basepath;
|
|---|
| 1248 | }
|
|---|
| [917] | 1249 |
|
|---|
| [988] | 1250 | path = talloc_asprintf(mem_ctx, "%s/%s",
|
|---|
| 1251 | handle->conn->connectpath,
|
|---|
| 1252 | smb_fname->base_name);
|
|---|
| 1253 | if (path == NULL) {
|
|---|
| 1254 | return NULL;
|
|---|
| 1255 | }
|
|---|
| [917] | 1256 |
|
|---|
| [988] | 1257 | snapdir = have_snapdir(handle, path);
|
|---|
| 1258 | if (snapdir != NULL) {
|
|---|
| 1259 | TALLOC_FREE(path);
|
|---|
| 1260 | return snapdir;
|
|---|
| 1261 | }
|
|---|
| [917] | 1262 |
|
|---|
| [988] | 1263 | while ((p = strrchr(path, '/')) && (p > path)) {
|
|---|
| [917] | 1264 |
|
|---|
| [988] | 1265 | p[0] = '\0';
|
|---|
| [917] | 1266 |
|
|---|
| [988] | 1267 | snapdir = have_snapdir(handle, path);
|
|---|
| 1268 | if (snapdir != NULL) {
|
|---|
| 1269 | TALLOC_FREE(path);
|
|---|
| 1270 | return snapdir;
|
|---|
| 1271 | }
|
|---|
| 1272 | }
|
|---|
| 1273 | TALLOC_FREE(path);
|
|---|
| 1274 | return NULL;
|
|---|
| [917] | 1275 | }
|
|---|
| 1276 |
|
|---|
| [988] | 1277 | static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct *handle,
|
|---|
| 1278 | const char *name,
|
|---|
| 1279 | char *gmt, size_t gmt_len)
|
|---|
| [917] | 1280 | {
|
|---|
| [988] | 1281 | struct tm timestamp;
|
|---|
| 1282 | time_t timestamp_t;
|
|---|
| 1283 | unsigned long int timestamp_long;
|
|---|
| 1284 | const char *fmt;
|
|---|
| 1285 | struct shadow_copy2_config *config;
|
|---|
| [917] | 1286 |
|
|---|
| [988] | 1287 | SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
|
|---|
| 1288 | return NULL);
|
|---|
| 1289 |
|
|---|
| 1290 | fmt = config->gmt_format;
|
|---|
| 1291 |
|
|---|
| 1292 | ZERO_STRUCT(timestamp);
|
|---|
| 1293 | if (config->use_sscanf) {
|
|---|
| 1294 | if (sscanf(name, fmt, ×tamp_long) != 1) {
|
|---|
| 1295 | DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
|
|---|
| 1296 | "no sscanf match %s: %s\n",
|
|---|
| 1297 | fmt, name));
|
|---|
| 1298 | return false;
|
|---|
| 1299 | }
|
|---|
| 1300 | timestamp_t = timestamp_long;
|
|---|
| 1301 | gmtime_r(×tamp_t, ×tamp);
|
|---|
| 1302 | } else {
|
|---|
| 1303 | if (strptime(name, fmt, ×tamp) == NULL) {
|
|---|
| 1304 | DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
|
|---|
| 1305 | "no match %s: %s\n",
|
|---|
| 1306 | fmt, name));
|
|---|
| 1307 | return false;
|
|---|
| 1308 | }
|
|---|
| 1309 | DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n",
|
|---|
| 1310 | fmt, name));
|
|---|
| 1311 |
|
|---|
| 1312 | if (config->use_localtime) {
|
|---|
| 1313 | timestamp.tm_isdst = -1;
|
|---|
| 1314 | timestamp_t = mktime(×tamp);
|
|---|
| 1315 | gmtime_r(×tamp_t, ×tamp);
|
|---|
| 1316 | }
|
|---|
| 1317 | }
|
|---|
| 1318 |
|
|---|
| 1319 | strftime(gmt, gmt_len, GMT_FORMAT, ×tamp);
|
|---|
| 1320 | return true;
|
|---|
| [917] | 1321 | }
|
|---|
| 1322 |
|
|---|
| 1323 | static int shadow_copy2_label_cmp_asc(const void *x, const void *y)
|
|---|
| 1324 | {
|
|---|
| [988] | 1325 | return strncmp((const char *)x, (const char *)y, sizeof(SHADOW_COPY_LABEL));
|
|---|
| [917] | 1326 | }
|
|---|
| 1327 |
|
|---|
| 1328 | static int shadow_copy2_label_cmp_desc(const void *x, const void *y)
|
|---|
| 1329 | {
|
|---|
| [988] | 1330 | return -strncmp((const char *)x, (const char *)y, sizeof(SHADOW_COPY_LABEL));
|
|---|
| [917] | 1331 | }
|
|---|
| 1332 |
|
|---|
| 1333 | /*
|
|---|
| 1334 | sort the shadow copy data in ascending or descending order
|
|---|
| 1335 | */
|
|---|
| 1336 | static void shadow_copy2_sort_data(vfs_handle_struct *handle,
|
|---|
| 1337 | struct shadow_copy_data *shadow_copy2_data)
|
|---|
| 1338 | {
|
|---|
| 1339 | int (*cmpfunc)(const void *, const void *);
|
|---|
| 1340 | const char *sort;
|
|---|
| [988] | 1341 | struct shadow_copy2_config *config;
|
|---|
| [917] | 1342 |
|
|---|
| [988] | 1343 | SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
|
|---|
| 1344 | return);
|
|---|
| 1345 |
|
|---|
| 1346 | sort = config->sort_order;
|
|---|
| [917] | 1347 | if (sort == NULL) {
|
|---|
| 1348 | return;
|
|---|
| 1349 | }
|
|---|
| 1350 |
|
|---|
| 1351 | if (strcmp(sort, "asc") == 0) {
|
|---|
| 1352 | cmpfunc = shadow_copy2_label_cmp_asc;
|
|---|
| 1353 | } else if (strcmp(sort, "desc") == 0) {
|
|---|
| 1354 | cmpfunc = shadow_copy2_label_cmp_desc;
|
|---|
| 1355 | } else {
|
|---|
| 1356 | return;
|
|---|
| 1357 | }
|
|---|
| 1358 |
|
|---|
| 1359 | if (shadow_copy2_data && shadow_copy2_data->num_volumes > 0 &&
|
|---|
| 1360 | shadow_copy2_data->labels)
|
|---|
| 1361 | {
|
|---|
| 1362 | TYPESAFE_QSORT(shadow_copy2_data->labels,
|
|---|
| 1363 | shadow_copy2_data->num_volumes,
|
|---|
| 1364 | cmpfunc);
|
|---|
| 1365 | }
|
|---|
| 1366 | }
|
|---|
| 1367 |
|
|---|
| [988] | 1368 | static int shadow_copy2_get_shadow_copy_data(
|
|---|
| 1369 | vfs_handle_struct *handle, files_struct *fsp,
|
|---|
| 1370 | struct shadow_copy_data *shadow_copy2_data,
|
|---|
| 1371 | bool labels)
|
|---|
| [917] | 1372 | {
|
|---|
| [988] | 1373 | DIR *p;
|
|---|
| [917] | 1374 | const char *snapdir;
|
|---|
| [988] | 1375 | struct dirent *d;
|
|---|
| 1376 | TALLOC_CTX *tmp_ctx = talloc_stackframe();
|
|---|
| [919] | 1377 | bool ret;
|
|---|
| [917] | 1378 |
|
|---|
| [988] | 1379 | snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle, fsp->fsp_name);
|
|---|
| [917] | 1380 | if (snapdir == NULL) {
|
|---|
| 1381 | DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
|
|---|
| 1382 | handle->conn->connectpath));
|
|---|
| 1383 | errno = EINVAL;
|
|---|
| 1384 | talloc_free(tmp_ctx);
|
|---|
| 1385 | return -1;
|
|---|
| 1386 | }
|
|---|
| [919] | 1387 | ret = check_access_snapdir(handle, snapdir);
|
|---|
| 1388 | if (!ret) {
|
|---|
| 1389 | DEBUG(0,("access denied on listing snapdir %s\n", snapdir));
|
|---|
| 1390 | errno = EACCES;
|
|---|
| 1391 | talloc_free(tmp_ctx);
|
|---|
| 1392 | return -1;
|
|---|
| 1393 | }
|
|---|
| [917] | 1394 |
|
|---|
| 1395 | p = SMB_VFS_NEXT_OPENDIR(handle, snapdir, NULL, 0);
|
|---|
| 1396 |
|
|---|
| 1397 | if (!p) {
|
|---|
| 1398 | DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
|
|---|
| 1399 | " - %s\n", snapdir, strerror(errno)));
|
|---|
| 1400 | talloc_free(tmp_ctx);
|
|---|
| 1401 | errno = ENOSYS;
|
|---|
| 1402 | return -1;
|
|---|
| 1403 | }
|
|---|
| 1404 |
|
|---|
| 1405 | shadow_copy2_data->num_volumes = 0;
|
|---|
| 1406 | shadow_copy2_data->labels = NULL;
|
|---|
| 1407 |
|
|---|
| 1408 | while ((d = SMB_VFS_NEXT_READDIR(handle, p, NULL))) {
|
|---|
| [988] | 1409 | char snapshot[GMT_NAME_LEN+1];
|
|---|
| [917] | 1410 | SHADOW_COPY_LABEL *tlabels;
|
|---|
| 1411 |
|
|---|
| [988] | 1412 | /*
|
|---|
| 1413 | * ignore names not of the right form in the snapshot
|
|---|
| 1414 | * directory
|
|---|
| 1415 | */
|
|---|
| 1416 | if (!shadow_copy2_snapshot_to_gmt(
|
|---|
| 1417 | handle, d->d_name,
|
|---|
| 1418 | snapshot, sizeof(snapshot))) {
|
|---|
| 1419 |
|
|---|
| 1420 | DEBUG(6, ("shadow_copy2_get_shadow_copy_data: "
|
|---|
| 1421 | "ignoring %s\n", d->d_name));
|
|---|
| [917] | 1422 | continue;
|
|---|
| 1423 | }
|
|---|
| [988] | 1424 | DEBUG(6,("shadow_copy2_get_shadow_copy_data: %s -> %s\n",
|
|---|
| 1425 | d->d_name, snapshot));
|
|---|
| [917] | 1426 |
|
|---|
| 1427 | if (!labels) {
|
|---|
| 1428 | /* the caller doesn't want the labels */
|
|---|
| 1429 | shadow_copy2_data->num_volumes++;
|
|---|
| 1430 | continue;
|
|---|
| 1431 | }
|
|---|
| 1432 |
|
|---|
| 1433 | tlabels = talloc_realloc(shadow_copy2_data,
|
|---|
| 1434 | shadow_copy2_data->labels,
|
|---|
| [988] | 1435 | SHADOW_COPY_LABEL,
|
|---|
| 1436 | shadow_copy2_data->num_volumes+1);
|
|---|
| [917] | 1437 | if (tlabels == NULL) {
|
|---|
| 1438 | DEBUG(0,("shadow_copy2: out of memory\n"));
|
|---|
| 1439 | SMB_VFS_NEXT_CLOSEDIR(handle, p);
|
|---|
| 1440 | talloc_free(tmp_ctx);
|
|---|
| 1441 | return -1;
|
|---|
| 1442 | }
|
|---|
| 1443 |
|
|---|
| 1444 | strlcpy(tlabels[shadow_copy2_data->num_volumes], snapshot,
|
|---|
| 1445 | sizeof(*tlabels));
|
|---|
| 1446 |
|
|---|
| 1447 | shadow_copy2_data->num_volumes++;
|
|---|
| 1448 | shadow_copy2_data->labels = tlabels;
|
|---|
| 1449 | }
|
|---|
| 1450 |
|
|---|
| 1451 | SMB_VFS_NEXT_CLOSEDIR(handle,p);
|
|---|
| 1452 |
|
|---|
| 1453 | shadow_copy2_sort_data(handle, shadow_copy2_data);
|
|---|
| 1454 |
|
|---|
| 1455 | talloc_free(tmp_ctx);
|
|---|
| 1456 | return 0;
|
|---|
| 1457 | }
|
|---|
| 1458 |
|
|---|
| [988] | 1459 | static NTSTATUS shadow_copy2_fget_nt_acl(vfs_handle_struct *handle,
|
|---|
| 1460 | struct files_struct *fsp,
|
|---|
| 1461 | uint32_t security_info,
|
|---|
| 1462 | TALLOC_CTX *mem_ctx,
|
|---|
| 1463 | struct security_descriptor **ppdesc)
|
|---|
| 1464 | {
|
|---|
| 1465 | time_t timestamp;
|
|---|
| 1466 | char *stripped;
|
|---|
| 1467 | NTSTATUS status;
|
|---|
| 1468 | char *conv;
|
|---|
| [917] | 1469 |
|
|---|
| [988] | 1470 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
|
|---|
| 1471 | fsp->fsp_name->base_name,
|
|---|
| 1472 | ×tamp, &stripped)) {
|
|---|
| 1473 | return map_nt_error_from_unix(errno);
|
|---|
| 1474 | }
|
|---|
| 1475 | if (timestamp == 0) {
|
|---|
| 1476 | return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
|
|---|
| 1477 | mem_ctx,
|
|---|
| 1478 | ppdesc);
|
|---|
| 1479 | }
|
|---|
| 1480 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1481 | TALLOC_FREE(stripped);
|
|---|
| 1482 | if (conv == NULL) {
|
|---|
| 1483 | return map_nt_error_from_unix(errno);
|
|---|
| 1484 | }
|
|---|
| 1485 | status = SMB_VFS_NEXT_GET_NT_ACL(handle, conv, security_info,
|
|---|
| 1486 | mem_ctx, ppdesc);
|
|---|
| 1487 | TALLOC_FREE(conv);
|
|---|
| 1488 | return status;
|
|---|
| 1489 | }
|
|---|
| 1490 |
|
|---|
| 1491 | static NTSTATUS shadow_copy2_get_nt_acl(vfs_handle_struct *handle,
|
|---|
| 1492 | const char *fname,
|
|---|
| 1493 | uint32_t security_info,
|
|---|
| 1494 | TALLOC_CTX *mem_ctx,
|
|---|
| 1495 | struct security_descriptor **ppdesc)
|
|---|
| [917] | 1496 | {
|
|---|
| [988] | 1497 | time_t timestamp;
|
|---|
| 1498 | char *stripped;
|
|---|
| 1499 | NTSTATUS status;
|
|---|
| 1500 | char *conv;
|
|---|
| [917] | 1501 |
|
|---|
| [988] | 1502 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1503 | ×tamp, &stripped)) {
|
|---|
| 1504 | return map_nt_error_from_unix(errno);
|
|---|
| 1505 | }
|
|---|
| 1506 | if (timestamp == 0) {
|
|---|
| 1507 | return SMB_VFS_NEXT_GET_NT_ACL(handle, fname, security_info,
|
|---|
| 1508 | mem_ctx, ppdesc);
|
|---|
| 1509 | }
|
|---|
| 1510 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1511 | TALLOC_FREE(stripped);
|
|---|
| 1512 | if (conv == NULL) {
|
|---|
| 1513 | return map_nt_error_from_unix(errno);
|
|---|
| 1514 | }
|
|---|
| 1515 | status = SMB_VFS_NEXT_GET_NT_ACL(handle, conv, security_info,
|
|---|
| 1516 | mem_ctx, ppdesc);
|
|---|
| 1517 | TALLOC_FREE(conv);
|
|---|
| 1518 | return status;
|
|---|
| 1519 | }
|
|---|
| [917] | 1520 |
|
|---|
| [988] | 1521 | static int shadow_copy2_mkdir(vfs_handle_struct *handle,
|
|---|
| 1522 | const char *fname, mode_t mode)
|
|---|
| 1523 | {
|
|---|
| 1524 | time_t timestamp;
|
|---|
| 1525 | char *stripped;
|
|---|
| 1526 | int ret, saved_errno;
|
|---|
| 1527 | char *conv;
|
|---|
| 1528 |
|
|---|
| 1529 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1530 | ×tamp, &stripped)) {
|
|---|
| 1531 | return -1;
|
|---|
| 1532 | }
|
|---|
| 1533 | if (timestamp == 0) {
|
|---|
| 1534 | return SMB_VFS_NEXT_MKDIR(handle, fname, mode);
|
|---|
| 1535 | }
|
|---|
| 1536 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1537 | TALLOC_FREE(stripped);
|
|---|
| 1538 | if (conv == NULL) {
|
|---|
| 1539 | return -1;
|
|---|
| 1540 | }
|
|---|
| 1541 | ret = SMB_VFS_NEXT_MKDIR(handle, conv, mode);
|
|---|
| 1542 | saved_errno = errno;
|
|---|
| 1543 | TALLOC_FREE(conv);
|
|---|
| 1544 | errno = saved_errno;
|
|---|
| 1545 | return ret;
|
|---|
| 1546 | }
|
|---|
| 1547 |
|
|---|
| 1548 | static int shadow_copy2_rmdir(vfs_handle_struct *handle, const char *fname)
|
|---|
| 1549 | {
|
|---|
| 1550 | time_t timestamp;
|
|---|
| 1551 | char *stripped;
|
|---|
| 1552 | int ret, saved_errno;
|
|---|
| 1553 | char *conv;
|
|---|
| 1554 |
|
|---|
| 1555 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1556 | ×tamp, &stripped)) {
|
|---|
| 1557 | return -1;
|
|---|
| 1558 | }
|
|---|
| 1559 | if (timestamp == 0) {
|
|---|
| 1560 | return SMB_VFS_NEXT_RMDIR(handle, fname);
|
|---|
| 1561 | }
|
|---|
| 1562 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1563 | TALLOC_FREE(stripped);
|
|---|
| 1564 | if (conv == NULL) {
|
|---|
| 1565 | return -1;
|
|---|
| 1566 | }
|
|---|
| 1567 | ret = SMB_VFS_NEXT_RMDIR(handle, conv);
|
|---|
| 1568 | saved_errno = errno;
|
|---|
| 1569 | TALLOC_FREE(conv);
|
|---|
| 1570 | errno = saved_errno;
|
|---|
| 1571 | return ret;
|
|---|
| 1572 | }
|
|---|
| 1573 |
|
|---|
| 1574 | static int shadow_copy2_chflags(vfs_handle_struct *handle, const char *fname,
|
|---|
| 1575 | unsigned int flags)
|
|---|
| 1576 | {
|
|---|
| 1577 | time_t timestamp;
|
|---|
| 1578 | char *stripped;
|
|---|
| 1579 | int ret, saved_errno;
|
|---|
| 1580 | char *conv;
|
|---|
| 1581 |
|
|---|
| 1582 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1583 | ×tamp, &stripped)) {
|
|---|
| 1584 | return -1;
|
|---|
| 1585 | }
|
|---|
| 1586 | if (timestamp == 0) {
|
|---|
| 1587 | return SMB_VFS_NEXT_CHFLAGS(handle, fname, flags);
|
|---|
| 1588 | }
|
|---|
| 1589 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1590 | TALLOC_FREE(stripped);
|
|---|
| 1591 | if (conv == NULL) {
|
|---|
| 1592 | return -1;
|
|---|
| 1593 | }
|
|---|
| 1594 | ret = SMB_VFS_NEXT_CHFLAGS(handle, conv, flags);
|
|---|
| 1595 | saved_errno = errno;
|
|---|
| 1596 | TALLOC_FREE(conv);
|
|---|
| 1597 | errno = saved_errno;
|
|---|
| 1598 | return ret;
|
|---|
| 1599 | }
|
|---|
| 1600 |
|
|---|
| 1601 | static ssize_t shadow_copy2_getxattr(vfs_handle_struct *handle,
|
|---|
| 1602 | const char *fname, const char *aname,
|
|---|
| 1603 | void *value, size_t size)
|
|---|
| 1604 | {
|
|---|
| 1605 | time_t timestamp;
|
|---|
| 1606 | char *stripped;
|
|---|
| 1607 | ssize_t ret;
|
|---|
| 1608 | int saved_errno;
|
|---|
| 1609 | char *conv;
|
|---|
| 1610 |
|
|---|
| 1611 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1612 | ×tamp, &stripped)) {
|
|---|
| 1613 | return -1;
|
|---|
| 1614 | }
|
|---|
| 1615 | if (timestamp == 0) {
|
|---|
| 1616 | return SMB_VFS_NEXT_GETXATTR(handle, fname, aname, value,
|
|---|
| 1617 | size);
|
|---|
| 1618 | }
|
|---|
| 1619 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1620 | TALLOC_FREE(stripped);
|
|---|
| 1621 | if (conv == NULL) {
|
|---|
| 1622 | return -1;
|
|---|
| 1623 | }
|
|---|
| 1624 | ret = SMB_VFS_NEXT_GETXATTR(handle, conv, aname, value, size);
|
|---|
| 1625 | saved_errno = errno;
|
|---|
| 1626 | TALLOC_FREE(conv);
|
|---|
| 1627 | errno = saved_errno;
|
|---|
| 1628 | return ret;
|
|---|
| 1629 | }
|
|---|
| 1630 |
|
|---|
| 1631 | static ssize_t shadow_copy2_listxattr(struct vfs_handle_struct *handle,
|
|---|
| 1632 | const char *fname,
|
|---|
| 1633 | char *list, size_t size)
|
|---|
| 1634 | {
|
|---|
| 1635 | time_t timestamp;
|
|---|
| 1636 | char *stripped;
|
|---|
| 1637 | ssize_t ret;
|
|---|
| 1638 | int saved_errno;
|
|---|
| 1639 | char *conv;
|
|---|
| 1640 |
|
|---|
| 1641 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1642 | ×tamp, &stripped)) {
|
|---|
| 1643 | return -1;
|
|---|
| 1644 | }
|
|---|
| 1645 | if (timestamp == 0) {
|
|---|
| 1646 | return SMB_VFS_NEXT_LISTXATTR(handle, fname, list, size);
|
|---|
| 1647 | }
|
|---|
| 1648 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1649 | TALLOC_FREE(stripped);
|
|---|
| 1650 | if (conv == NULL) {
|
|---|
| 1651 | return -1;
|
|---|
| 1652 | }
|
|---|
| 1653 | ret = SMB_VFS_NEXT_LISTXATTR(handle, conv, list, size);
|
|---|
| 1654 | saved_errno = errno;
|
|---|
| 1655 | TALLOC_FREE(conv);
|
|---|
| 1656 | errno = saved_errno;
|
|---|
| 1657 | return ret;
|
|---|
| 1658 | }
|
|---|
| 1659 |
|
|---|
| 1660 | static int shadow_copy2_removexattr(vfs_handle_struct *handle,
|
|---|
| 1661 | const char *fname, const char *aname)
|
|---|
| 1662 | {
|
|---|
| 1663 | time_t timestamp;
|
|---|
| 1664 | char *stripped;
|
|---|
| 1665 | int ret, saved_errno;
|
|---|
| 1666 | char *conv;
|
|---|
| 1667 |
|
|---|
| 1668 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1669 | ×tamp, &stripped)) {
|
|---|
| 1670 | return -1;
|
|---|
| 1671 | }
|
|---|
| 1672 | if (timestamp == 0) {
|
|---|
| 1673 | return SMB_VFS_NEXT_REMOVEXATTR(handle, fname, aname);
|
|---|
| 1674 | }
|
|---|
| 1675 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1676 | TALLOC_FREE(stripped);
|
|---|
| 1677 | if (conv == NULL) {
|
|---|
| 1678 | return -1;
|
|---|
| 1679 | }
|
|---|
| 1680 | ret = SMB_VFS_NEXT_REMOVEXATTR(handle, conv, aname);
|
|---|
| 1681 | saved_errno = errno;
|
|---|
| 1682 | TALLOC_FREE(conv);
|
|---|
| 1683 | errno = saved_errno;
|
|---|
| 1684 | return ret;
|
|---|
| 1685 | }
|
|---|
| 1686 |
|
|---|
| 1687 | static int shadow_copy2_setxattr(struct vfs_handle_struct *handle,
|
|---|
| 1688 | const char *fname,
|
|---|
| 1689 | const char *aname, const void *value,
|
|---|
| 1690 | size_t size, int flags)
|
|---|
| 1691 | {
|
|---|
| 1692 | time_t timestamp;
|
|---|
| 1693 | char *stripped;
|
|---|
| 1694 | ssize_t ret;
|
|---|
| 1695 | int saved_errno;
|
|---|
| 1696 | char *conv;
|
|---|
| 1697 |
|
|---|
| 1698 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1699 | ×tamp, &stripped)) {
|
|---|
| 1700 | return -1;
|
|---|
| 1701 | }
|
|---|
| 1702 | if (timestamp == 0) {
|
|---|
| 1703 | return SMB_VFS_NEXT_SETXATTR(handle, fname, aname, value, size,
|
|---|
| 1704 | flags);
|
|---|
| 1705 | }
|
|---|
| 1706 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1707 | TALLOC_FREE(stripped);
|
|---|
| 1708 | if (conv == NULL) {
|
|---|
| 1709 | return -1;
|
|---|
| 1710 | }
|
|---|
| 1711 | ret = SMB_VFS_NEXT_SETXATTR(handle, conv, aname, value, size, flags);
|
|---|
| 1712 | saved_errno = errno;
|
|---|
| 1713 | TALLOC_FREE(conv);
|
|---|
| 1714 | errno = saved_errno;
|
|---|
| 1715 | return ret;
|
|---|
| 1716 | }
|
|---|
| 1717 |
|
|---|
| 1718 | static int shadow_copy2_chmod_acl(vfs_handle_struct *handle,
|
|---|
| 1719 | const char *fname, mode_t mode)
|
|---|
| 1720 | {
|
|---|
| 1721 | time_t timestamp;
|
|---|
| 1722 | char *stripped;
|
|---|
| 1723 | ssize_t ret;
|
|---|
| 1724 | int saved_errno;
|
|---|
| 1725 | char *conv;
|
|---|
| 1726 |
|
|---|
| 1727 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1728 | ×tamp, &stripped)) {
|
|---|
| 1729 | return -1;
|
|---|
| 1730 | }
|
|---|
| 1731 | if (timestamp == 0) {
|
|---|
| 1732 | return SMB_VFS_NEXT_CHMOD_ACL(handle, fname, mode);
|
|---|
| 1733 | }
|
|---|
| 1734 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1735 | TALLOC_FREE(stripped);
|
|---|
| 1736 | if (conv == NULL) {
|
|---|
| 1737 | return -1;
|
|---|
| 1738 | }
|
|---|
| 1739 | ret = SMB_VFS_NEXT_CHMOD_ACL(handle, conv, mode);
|
|---|
| 1740 | saved_errno = errno;
|
|---|
| 1741 | TALLOC_FREE(conv);
|
|---|
| 1742 | errno = saved_errno;
|
|---|
| 1743 | return ret;
|
|---|
| 1744 | }
|
|---|
| 1745 |
|
|---|
| 1746 | static int shadow_copy2_get_real_filename(struct vfs_handle_struct *handle,
|
|---|
| 1747 | const char *path,
|
|---|
| 1748 | const char *name,
|
|---|
| 1749 | TALLOC_CTX *mem_ctx,
|
|---|
| 1750 | char **found_name)
|
|---|
| 1751 | {
|
|---|
| 1752 | time_t timestamp;
|
|---|
| 1753 | char *stripped;
|
|---|
| 1754 | ssize_t ret;
|
|---|
| 1755 | int saved_errno;
|
|---|
| 1756 | char *conv;
|
|---|
| 1757 |
|
|---|
| 1758 | DEBUG(10, ("shadow_copy2_get_real_filename called for path=[%s], "
|
|---|
| 1759 | "name=[%s]\n", path, name));
|
|---|
| 1760 |
|
|---|
| 1761 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
|
|---|
| 1762 | ×tamp, &stripped)) {
|
|---|
| 1763 | DEBUG(10, ("shadow_copy2_strip_snapshot failed\n"));
|
|---|
| 1764 | return -1;
|
|---|
| 1765 | }
|
|---|
| 1766 | if (timestamp == 0) {
|
|---|
| 1767 | DEBUG(10, ("timestamp == 0\n"));
|
|---|
| 1768 | return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
|
|---|
| 1769 | mem_ctx, found_name);
|
|---|
| 1770 | }
|
|---|
| 1771 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1772 | TALLOC_FREE(stripped);
|
|---|
| 1773 | if (conv == NULL) {
|
|---|
| 1774 | DEBUG(10, ("shadow_copy2_convert failed\n"));
|
|---|
| 1775 | return -1;
|
|---|
| 1776 | }
|
|---|
| 1777 | DEBUG(10, ("Calling NEXT_GET_REAL_FILE_NAME for conv=[%s], "
|
|---|
| 1778 | "name=[%s]\n", conv, name));
|
|---|
| 1779 | ret = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, conv, name,
|
|---|
| 1780 | mem_ctx, found_name);
|
|---|
| 1781 | DEBUG(10, ("NEXT_REAL_FILE_NAME returned %d\n", (int)ret));
|
|---|
| 1782 | saved_errno = errno;
|
|---|
| 1783 | TALLOC_FREE(conv);
|
|---|
| 1784 | errno = saved_errno;
|
|---|
| 1785 | return ret;
|
|---|
| 1786 | }
|
|---|
| 1787 |
|
|---|
| 1788 | static const char *shadow_copy2_connectpath(struct vfs_handle_struct *handle,
|
|---|
| 1789 | const char *fname)
|
|---|
| 1790 | {
|
|---|
| 1791 | time_t timestamp;
|
|---|
| 1792 | char *stripped = NULL;
|
|---|
| 1793 | char *tmp = NULL;
|
|---|
| 1794 | char *result = NULL;
|
|---|
| [989] | 1795 | char *parent_dir = NULL;
|
|---|
| [988] | 1796 | int saved_errno;
|
|---|
| 1797 | size_t rootpath_len = 0;
|
|---|
| 1798 |
|
|---|
| 1799 | DBG_DEBUG("Calc connect path for [%s]\n", fname);
|
|---|
| 1800 |
|
|---|
| 1801 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
|
|---|
| 1802 | ×tamp, &stripped)) {
|
|---|
| 1803 | goto done;
|
|---|
| 1804 | }
|
|---|
| 1805 | if (timestamp == 0) {
|
|---|
| 1806 | return SMB_VFS_NEXT_CONNECTPATH(handle, fname);
|
|---|
| 1807 | }
|
|---|
| 1808 |
|
|---|
| 1809 | tmp = shadow_copy2_do_convert(talloc_tos(), handle, stripped, timestamp,
|
|---|
| 1810 | &rootpath_len);
|
|---|
| 1811 | if (tmp == NULL) {
|
|---|
| [989] | 1812 | if (errno != ENOENT) {
|
|---|
| 1813 | goto done;
|
|---|
| 1814 | }
|
|---|
| 1815 |
|
|---|
| 1816 | /*
|
|---|
| 1817 | * If the converted path does not exist, and converting
|
|---|
| 1818 | * the parent yields something that does exist, then
|
|---|
| 1819 | * this path refers to something that has not been
|
|---|
| 1820 | * created yet, relative to the parent path.
|
|---|
| 1821 | * The snapshot finding is relative to the parent.
|
|---|
| 1822 | * (usually snapshots are read/only but this is not
|
|---|
| 1823 | * necessarily true).
|
|---|
| 1824 | * This code also covers getting a wildcard in the
|
|---|
| 1825 | * last component, because this function is called
|
|---|
| 1826 | * prior to sanitizing the path, and in SMB1 we may
|
|---|
| 1827 | * get wildcards in path names.
|
|---|
| 1828 | */
|
|---|
| 1829 | if (!parent_dirname(talloc_tos(), stripped, &parent_dir,
|
|---|
| 1830 | NULL)) {
|
|---|
| 1831 | errno = ENOMEM;
|
|---|
| 1832 | goto done;
|
|---|
| 1833 | }
|
|---|
| 1834 |
|
|---|
| 1835 | tmp = shadow_copy2_do_convert(talloc_tos(), handle, parent_dir,
|
|---|
| 1836 | timestamp, &rootpath_len);
|
|---|
| 1837 | if (tmp == NULL) {
|
|---|
| 1838 | goto done;
|
|---|
| 1839 | }
|
|---|
| [988] | 1840 | }
|
|---|
| 1841 |
|
|---|
| 1842 | DBG_DEBUG("converted path is [%s] root path is [%.*s]\n", tmp,
|
|---|
| 1843 | (int)rootpath_len, tmp);
|
|---|
| 1844 |
|
|---|
| 1845 | tmp[rootpath_len] = '\0';
|
|---|
| 1846 | result = SMB_VFS_NEXT_REALPATH(handle, tmp);
|
|---|
| 1847 | if (result == NULL) {
|
|---|
| 1848 | goto done;
|
|---|
| 1849 | }
|
|---|
| 1850 |
|
|---|
| 1851 | DBG_DEBUG("connect path is [%s]\n", result);
|
|---|
| 1852 |
|
|---|
| 1853 | done:
|
|---|
| 1854 | saved_errno = errno;
|
|---|
| 1855 | TALLOC_FREE(tmp);
|
|---|
| 1856 | TALLOC_FREE(stripped);
|
|---|
| [989] | 1857 | TALLOC_FREE(parent_dir);
|
|---|
| [988] | 1858 | errno = saved_errno;
|
|---|
| 1859 | return result;
|
|---|
| 1860 | }
|
|---|
| 1861 |
|
|---|
| 1862 | static uint64_t shadow_copy2_disk_free(vfs_handle_struct *handle,
|
|---|
| 1863 | const char *path, uint64_t *bsize,
|
|---|
| 1864 | uint64_t *dfree, uint64_t *dsize)
|
|---|
| 1865 | {
|
|---|
| 1866 | time_t timestamp;
|
|---|
| 1867 | char *stripped;
|
|---|
| 1868 | ssize_t ret;
|
|---|
| 1869 | int saved_errno;
|
|---|
| 1870 | char *conv;
|
|---|
| 1871 |
|
|---|
| 1872 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
|
|---|
| 1873 | ×tamp, &stripped)) {
|
|---|
| 1874 | return -1;
|
|---|
| 1875 | }
|
|---|
| 1876 | if (timestamp == 0) {
|
|---|
| 1877 | return SMB_VFS_NEXT_DISK_FREE(handle, path,
|
|---|
| 1878 | bsize, dfree, dsize);
|
|---|
| 1879 | }
|
|---|
| 1880 |
|
|---|
| 1881 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1882 | TALLOC_FREE(stripped);
|
|---|
| 1883 | if (conv == NULL) {
|
|---|
| 1884 | return -1;
|
|---|
| 1885 | }
|
|---|
| 1886 |
|
|---|
| 1887 | ret = SMB_VFS_NEXT_DISK_FREE(handle, conv, bsize, dfree, dsize);
|
|---|
| 1888 |
|
|---|
| 1889 | saved_errno = errno;
|
|---|
| 1890 | TALLOC_FREE(conv);
|
|---|
| 1891 | errno = saved_errno;
|
|---|
| 1892 |
|
|---|
| 1893 | return ret;
|
|---|
| 1894 | }
|
|---|
| 1895 |
|
|---|
| 1896 | static int shadow_copy2_get_quota(vfs_handle_struct *handle, const char *path,
|
|---|
| 1897 | enum SMB_QUOTA_TYPE qtype, unid_t id,
|
|---|
| 1898 | SMB_DISK_QUOTA *dq)
|
|---|
| 1899 | {
|
|---|
| 1900 | time_t timestamp;
|
|---|
| 1901 | char *stripped;
|
|---|
| 1902 | int ret;
|
|---|
| 1903 | int saved_errno;
|
|---|
| 1904 | char *conv;
|
|---|
| 1905 |
|
|---|
| 1906 | if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path, ×tamp,
|
|---|
| 1907 | &stripped)) {
|
|---|
| 1908 | return -1;
|
|---|
| 1909 | }
|
|---|
| 1910 | if (timestamp == 0) {
|
|---|
| 1911 | return SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, dq);
|
|---|
| 1912 | }
|
|---|
| 1913 |
|
|---|
| 1914 | conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
|
|---|
| 1915 | TALLOC_FREE(stripped);
|
|---|
| 1916 | if (conv == NULL) {
|
|---|
| 1917 | return -1;
|
|---|
| 1918 | }
|
|---|
| 1919 |
|
|---|
| 1920 | ret = SMB_VFS_NEXT_GET_QUOTA(handle, conv, qtype, id, dq);
|
|---|
| 1921 |
|
|---|
| 1922 | saved_errno = errno;
|
|---|
| 1923 | TALLOC_FREE(conv);
|
|---|
| 1924 | errno = saved_errno;
|
|---|
| 1925 |
|
|---|
| 1926 | return ret;
|
|---|
| 1927 | }
|
|---|
| 1928 |
|
|---|
| 1929 | static int shadow_copy2_connect(struct vfs_handle_struct *handle,
|
|---|
| 1930 | const char *service, const char *user)
|
|---|
| 1931 | {
|
|---|
| 1932 | struct shadow_copy2_config *config;
|
|---|
| 1933 | int ret;
|
|---|
| 1934 | const char *snapdir;
|
|---|
| 1935 | const char *gmt_format;
|
|---|
| 1936 | const char *sort_order;
|
|---|
| 1937 | const char *basedir = NULL;
|
|---|
| 1938 | const char *snapsharepath = NULL;
|
|---|
| 1939 | const char *mount_point;
|
|---|
| 1940 |
|
|---|
| 1941 | DEBUG(10, (__location__ ": cnum[%u], connectpath[%s]\n",
|
|---|
| 1942 | (unsigned)handle->conn->cnum,
|
|---|
| 1943 | handle->conn->connectpath));
|
|---|
| 1944 |
|
|---|
| 1945 | ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
|
|---|
| 1946 | if (ret < 0) {
|
|---|
| [917] | 1947 | return ret;
|
|---|
| [988] | 1948 | }
|
|---|
| [917] | 1949 |
|
|---|
| [988] | 1950 | config = talloc_zero(handle->conn, struct shadow_copy2_config);
|
|---|
| 1951 | if (config == NULL) {
|
|---|
| 1952 | DEBUG(0, ("talloc_zero() failed\n"));
|
|---|
| 1953 | errno = ENOMEM;
|
|---|
| 1954 | return -1;
|
|---|
| 1955 | }
|
|---|
| 1956 |
|
|---|
| 1957 | gmt_format = lp_parm_const_string(SNUM(handle->conn),
|
|---|
| 1958 | "shadow", "format",
|
|---|
| 1959 | GMT_FORMAT);
|
|---|
| 1960 | config->gmt_format = talloc_strdup(config, gmt_format);
|
|---|
| 1961 | if (config->gmt_format == NULL) {
|
|---|
| 1962 | DEBUG(0, ("talloc_strdup() failed\n"));
|
|---|
| 1963 | errno = ENOMEM;
|
|---|
| 1964 | return -1;
|
|---|
| 1965 | }
|
|---|
| 1966 |
|
|---|
| 1967 | config->use_sscanf = lp_parm_bool(SNUM(handle->conn),
|
|---|
| 1968 | "shadow", "sscanf", false);
|
|---|
| 1969 |
|
|---|
| 1970 | config->use_localtime = lp_parm_bool(SNUM(handle->conn),
|
|---|
| 1971 | "shadow", "localtime",
|
|---|
| 1972 | false);
|
|---|
| 1973 |
|
|---|
| 1974 | snapdir = lp_parm_const_string(SNUM(handle->conn),
|
|---|
| 1975 | "shadow", "snapdir",
|
|---|
| 1976 | ".snapshots");
|
|---|
| 1977 | config->snapdir = talloc_strdup(config, snapdir);
|
|---|
| 1978 | if (config->snapdir == NULL) {
|
|---|
| 1979 | DEBUG(0, ("talloc_strdup() failed\n"));
|
|---|
| 1980 | errno = ENOMEM;
|
|---|
| 1981 | return -1;
|
|---|
| 1982 | }
|
|---|
| 1983 |
|
|---|
| 1984 | config->snapdirseverywhere = lp_parm_bool(SNUM(handle->conn),
|
|---|
| 1985 | "shadow",
|
|---|
| 1986 | "snapdirseverywhere",
|
|---|
| 1987 | false);
|
|---|
| 1988 |
|
|---|
| 1989 | config->crossmountpoints = lp_parm_bool(SNUM(handle->conn),
|
|---|
| 1990 | "shadow", "crossmountpoints",
|
|---|
| 1991 | false);
|
|---|
| 1992 |
|
|---|
| 1993 | if (config->crossmountpoints && !config->snapdirseverywhere) {
|
|---|
| 1994 | DBG_WARNING("Warning: 'crossmountpoints' depends on "
|
|---|
| 1995 | "'snapdirseverywhere'. Disabling crossmountpoints.\n");
|
|---|
| 1996 | }
|
|---|
| 1997 |
|
|---|
| 1998 | config->fixinodes = lp_parm_bool(SNUM(handle->conn),
|
|---|
| 1999 | "shadow", "fixinodes",
|
|---|
| 2000 | false);
|
|---|
| 2001 |
|
|---|
| 2002 | sort_order = lp_parm_const_string(SNUM(handle->conn),
|
|---|
| 2003 | "shadow", "sort", "desc");
|
|---|
| 2004 | config->sort_order = talloc_strdup(config, sort_order);
|
|---|
| 2005 | if (config->sort_order == NULL) {
|
|---|
| 2006 | DEBUG(0, ("talloc_strdup() failed\n"));
|
|---|
| 2007 | errno = ENOMEM;
|
|---|
| 2008 | return -1;
|
|---|
| 2009 | }
|
|---|
| 2010 |
|
|---|
| 2011 | mount_point = lp_parm_const_string(SNUM(handle->conn),
|
|---|
| 2012 | "shadow", "mountpoint", NULL);
|
|---|
| 2013 | if (mount_point != NULL) {
|
|---|
| 2014 | if (mount_point[0] != '/') {
|
|---|
| 2015 | DEBUG(1, (__location__ " Warning: 'mountpoint' is "
|
|---|
| 2016 | "relative ('%s'), but it has to be an "
|
|---|
| 2017 | "absolute path. Ignoring provided value.\n",
|
|---|
| 2018 | mount_point));
|
|---|
| 2019 | mount_point = NULL;
|
|---|
| 2020 | } else {
|
|---|
| 2021 | char *p;
|
|---|
| 2022 | p = strstr(handle->conn->connectpath, mount_point);
|
|---|
| 2023 | if (p != handle->conn->connectpath) {
|
|---|
| 2024 | DBG_WARNING("Warning: the share root (%s) is "
|
|---|
| 2025 | "not a subdirectory of the "
|
|---|
| 2026 | "specified mountpoint (%s). "
|
|---|
| 2027 | "Ignoring provided value.\n",
|
|---|
| 2028 | handle->conn->connectpath,
|
|---|
| 2029 | mount_point);
|
|---|
| 2030 | mount_point = NULL;
|
|---|
| 2031 | }
|
|---|
| 2032 | }
|
|---|
| 2033 | }
|
|---|
| 2034 |
|
|---|
| 2035 | if (mount_point != NULL) {
|
|---|
| 2036 | config->mount_point = talloc_strdup(config, mount_point);
|
|---|
| 2037 | if (config->mount_point == NULL) {
|
|---|
| 2038 | DEBUG(0, (__location__ " talloc_strdup() failed\n"));
|
|---|
| 2039 | return -1;
|
|---|
| 2040 | }
|
|---|
| [917] | 2041 | } else {
|
|---|
| [988] | 2042 | config->mount_point = shadow_copy2_find_mount_point(config,
|
|---|
| 2043 | handle);
|
|---|
| 2044 | if (config->mount_point == NULL) {
|
|---|
| 2045 | DBG_WARNING("shadow_copy2_find_mount_point "
|
|---|
| 2046 | "of the share root '%s' failed: %s\n",
|
|---|
| 2047 | handle->conn->connectpath, strerror(errno));
|
|---|
| 2048 | return -1;
|
|---|
| 2049 | }
|
|---|
| [917] | 2050 | }
|
|---|
| 2051 |
|
|---|
| [988] | 2052 | basedir = lp_parm_const_string(SNUM(handle->conn),
|
|---|
| 2053 | "shadow", "basedir", NULL);
|
|---|
| 2054 |
|
|---|
| 2055 | if (basedir != NULL) {
|
|---|
| 2056 | if (basedir[0] != '/') {
|
|---|
| 2057 | DEBUG(1, (__location__ " Warning: 'basedir' is "
|
|---|
| 2058 | "relative ('%s'), but it has to be an "
|
|---|
| 2059 | "absolute path. Disabling basedir.\n",
|
|---|
| 2060 | basedir));
|
|---|
| 2061 | basedir = NULL;
|
|---|
| 2062 | } else {
|
|---|
| 2063 | char *p;
|
|---|
| 2064 | p = strstr(basedir, config->mount_point);
|
|---|
| 2065 | if (p != basedir) {
|
|---|
| 2066 | DEBUG(1, ("Warning: basedir (%s) is not a "
|
|---|
| 2067 | "subdirectory of the share root's "
|
|---|
| 2068 | "mount point (%s). "
|
|---|
| 2069 | "Disabling basedir\n",
|
|---|
| 2070 | basedir, config->mount_point));
|
|---|
| 2071 | basedir = NULL;
|
|---|
| 2072 | }
|
|---|
| 2073 | }
|
|---|
| 2074 | }
|
|---|
| 2075 |
|
|---|
| 2076 | if (config->snapdirseverywhere && basedir != NULL) {
|
|---|
| 2077 | DEBUG(1, (__location__ " Warning: 'basedir' is incompatible "
|
|---|
| 2078 | "with 'snapdirseverywhere'. Disabling basedir.\n"));
|
|---|
| 2079 | basedir = NULL;
|
|---|
| 2080 | }
|
|---|
| 2081 |
|
|---|
| 2082 | snapsharepath = lp_parm_const_string(SNUM(handle->conn), "shadow",
|
|---|
| 2083 | "snapsharepath", NULL);
|
|---|
| 2084 | if (snapsharepath != NULL) {
|
|---|
| 2085 | if (snapsharepath[0] == '/') {
|
|---|
| 2086 | DBG_WARNING("Warning: 'snapsharepath' is "
|
|---|
| 2087 | "absolute ('%s'), but it has to be a "
|
|---|
| 2088 | "relative path. Disabling snapsharepath.\n",
|
|---|
| 2089 | snapsharepath);
|
|---|
| 2090 | snapsharepath = NULL;
|
|---|
| 2091 | }
|
|---|
| 2092 | if (config->snapdirseverywhere && snapsharepath != NULL) {
|
|---|
| 2093 | DBG_WARNING("Warning: 'snapsharepath' is incompatible "
|
|---|
| 2094 | "with 'snapdirseverywhere'. Disabling "
|
|---|
| 2095 | "snapsharepath.\n");
|
|---|
| 2096 | snapsharepath = NULL;
|
|---|
| 2097 | }
|
|---|
| 2098 | }
|
|---|
| 2099 |
|
|---|
| 2100 | if (basedir != NULL && snapsharepath != NULL) {
|
|---|
| 2101 | DBG_WARNING("Warning: 'snapsharepath' is incompatible with "
|
|---|
| 2102 | "'basedir'. Disabling snapsharepath\n");
|
|---|
| 2103 | snapsharepath = NULL;
|
|---|
| 2104 | }
|
|---|
| 2105 |
|
|---|
| 2106 | if (snapsharepath != NULL) {
|
|---|
| 2107 | config->rel_connectpath = talloc_strdup(config, snapsharepath);
|
|---|
| 2108 | if (config->rel_connectpath == NULL) {
|
|---|
| 2109 | DBG_ERR("talloc_strdup() failed\n");
|
|---|
| 2110 | errno = ENOMEM;
|
|---|
| 2111 | return -1;
|
|---|
| 2112 | }
|
|---|
| 2113 | }
|
|---|
| 2114 |
|
|---|
| 2115 | if (basedir == NULL) {
|
|---|
| 2116 | basedir = config->mount_point;
|
|---|
| 2117 | }
|
|---|
| 2118 |
|
|---|
| 2119 | if (config->rel_connectpath == NULL &&
|
|---|
| 2120 | strlen(basedir) != strlen(handle->conn->connectpath)) {
|
|---|
| 2121 | config->rel_connectpath = talloc_strdup(config,
|
|---|
| 2122 | handle->conn->connectpath + strlen(basedir));
|
|---|
| 2123 | if (config->rel_connectpath == NULL) {
|
|---|
| 2124 | DEBUG(0, ("talloc_strdup() failed\n"));
|
|---|
| 2125 | errno = ENOMEM;
|
|---|
| 2126 | return -1;
|
|---|
| 2127 | }
|
|---|
| 2128 | }
|
|---|
| 2129 |
|
|---|
| 2130 | if (config->snapdir[0] == '/') {
|
|---|
| 2131 | config->snapdir_absolute = true;
|
|---|
| 2132 |
|
|---|
| 2133 | if (config->snapdirseverywhere == true) {
|
|---|
| 2134 | DEBUG(1, (__location__ " Warning: An absolute snapdir "
|
|---|
| 2135 | "is incompatible with 'snapdirseverywhere', "
|
|---|
| 2136 | "setting 'snapdirseverywhere' to false.\n"));
|
|---|
| 2137 | config->snapdirseverywhere = false;
|
|---|
| 2138 | }
|
|---|
| 2139 |
|
|---|
| 2140 | if (config->crossmountpoints == true) {
|
|---|
| 2141 | DEBUG(1, (__location__ " Warning: 'crossmountpoints' "
|
|---|
| 2142 | "is not supported with an absolute snapdir. "
|
|---|
| 2143 | "Disabling it.\n"));
|
|---|
| 2144 | config->crossmountpoints = false;
|
|---|
| 2145 | }
|
|---|
| 2146 |
|
|---|
| 2147 | config->snapshot_basepath = config->snapdir;
|
|---|
| 2148 | } else {
|
|---|
| 2149 | config->snapshot_basepath = talloc_asprintf(config, "%s/%s",
|
|---|
| 2150 | config->mount_point, config->snapdir);
|
|---|
| 2151 | if (config->snapshot_basepath == NULL) {
|
|---|
| 2152 | DEBUG(0, ("talloc_asprintf() failed\n"));
|
|---|
| 2153 | errno = ENOMEM;
|
|---|
| 2154 | return -1;
|
|---|
| 2155 | }
|
|---|
| 2156 | }
|
|---|
| 2157 |
|
|---|
| 2158 | DEBUG(10, ("shadow_copy2_connect: configuration:\n"
|
|---|
| 2159 | " share root: '%s'\n"
|
|---|
| 2160 | " mountpoint: '%s'\n"
|
|---|
| 2161 | " rel share root: '%s'\n"
|
|---|
| 2162 | " snapdir: '%s'\n"
|
|---|
| 2163 | " snapshot base path: '%s'\n"
|
|---|
| 2164 | " format: '%s'\n"
|
|---|
| 2165 | " use sscanf: %s\n"
|
|---|
| 2166 | " snapdirs everywhere: %s\n"
|
|---|
| 2167 | " cross mountpoints: %s\n"
|
|---|
| 2168 | " fix inodes: %s\n"
|
|---|
| 2169 | " sort order: %s\n"
|
|---|
| 2170 | "",
|
|---|
| 2171 | handle->conn->connectpath,
|
|---|
| 2172 | config->mount_point,
|
|---|
| 2173 | config->rel_connectpath,
|
|---|
| 2174 | config->snapdir,
|
|---|
| 2175 | config->snapshot_basepath,
|
|---|
| 2176 | config->gmt_format,
|
|---|
| 2177 | config->use_sscanf ? "yes" : "no",
|
|---|
| 2178 | config->snapdirseverywhere ? "yes" : "no",
|
|---|
| 2179 | config->crossmountpoints ? "yes" : "no",
|
|---|
| 2180 | config->fixinodes ? "yes" : "no",
|
|---|
| 2181 | config->sort_order
|
|---|
| 2182 | ));
|
|---|
| 2183 |
|
|---|
| 2184 |
|
|---|
| 2185 | SMB_VFS_HANDLE_SET_DATA(handle, config,
|
|---|
| 2186 | NULL, struct shadow_copy2_config,
|
|---|
| 2187 | return -1);
|
|---|
| 2188 |
|
|---|
| 2189 | return 0;
|
|---|
| [917] | 2190 | }
|
|---|
| [988] | 2191 |
|
|---|
| 2192 | static struct vfs_fn_pointers vfs_shadow_copy2_fns = {
|
|---|
| 2193 | .connect_fn = shadow_copy2_connect,
|
|---|
| 2194 | .opendir_fn = shadow_copy2_opendir,
|
|---|
| 2195 | .disk_free_fn = shadow_copy2_disk_free,
|
|---|
| 2196 | .get_quota_fn = shadow_copy2_get_quota,
|
|---|
| 2197 | .rename_fn = shadow_copy2_rename,
|
|---|
| 2198 | .link_fn = shadow_copy2_link,
|
|---|
| 2199 | .symlink_fn = shadow_copy2_symlink,
|
|---|
| 2200 | .stat_fn = shadow_copy2_stat,
|
|---|
| 2201 | .lstat_fn = shadow_copy2_lstat,
|
|---|
| 2202 | .fstat_fn = shadow_copy2_fstat,
|
|---|
| 2203 | .open_fn = shadow_copy2_open,
|
|---|
| 2204 | .unlink_fn = shadow_copy2_unlink,
|
|---|
| 2205 | .chmod_fn = shadow_copy2_chmod,
|
|---|
| 2206 | .chown_fn = shadow_copy2_chown,
|
|---|
| 2207 | .chdir_fn = shadow_copy2_chdir,
|
|---|
| 2208 | .ntimes_fn = shadow_copy2_ntimes,
|
|---|
| 2209 | .readlink_fn = shadow_copy2_readlink,
|
|---|
| 2210 | .mknod_fn = shadow_copy2_mknod,
|
|---|
| 2211 | .realpath_fn = shadow_copy2_realpath,
|
|---|
| 2212 | .get_nt_acl_fn = shadow_copy2_get_nt_acl,
|
|---|
| 2213 | .fget_nt_acl_fn = shadow_copy2_fget_nt_acl,
|
|---|
| 2214 | .get_shadow_copy_data_fn = shadow_copy2_get_shadow_copy_data,
|
|---|
| 2215 | .mkdir_fn = shadow_copy2_mkdir,
|
|---|
| 2216 | .rmdir_fn = shadow_copy2_rmdir,
|
|---|
| 2217 | .getxattr_fn = shadow_copy2_getxattr,
|
|---|
| 2218 | .listxattr_fn = shadow_copy2_listxattr,
|
|---|
| 2219 | .removexattr_fn = shadow_copy2_removexattr,
|
|---|
| 2220 | .setxattr_fn = shadow_copy2_setxattr,
|
|---|
| 2221 | .chmod_acl_fn = shadow_copy2_chmod_acl,
|
|---|
| 2222 | .chflags_fn = shadow_copy2_chflags,
|
|---|
| 2223 | .get_real_filename_fn = shadow_copy2_get_real_filename,
|
|---|
| 2224 | .connectpath_fn = shadow_copy2_connectpath,
|
|---|
| 2225 | };
|
|---|
| 2226 |
|
|---|
| 2227 | NTSTATUS vfs_shadow_copy2_init(void);
|
|---|
| 2228 | NTSTATUS vfs_shadow_copy2_init(void)
|
|---|
| 2229 | {
|
|---|
| 2230 | return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
|
|---|
| 2231 | "shadow_copy2", &vfs_shadow_copy2_fns);
|
|---|
| 2232 | }
|
|---|