Print this page
NEX-14666 Need to provide SMB 2.1 Client
NEX-17187 panic in smbfs_acl_store
NEX-17231 smbfs create xattr files finds wrong file
NEX-17224 smbfs lookup EINVAL should be ENOENT
NEX-17260 SMB1 client fails to list directory after NEX-14666
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
and: (cleanup)
NEX-2807 Restoring previous versions from snapshots doesn't work with nested folders.
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-3611 CLONE NEX-3550 Replace smb2_enable with max_protocol
Reviewed by: Yuri Pankov <Yuri.Pankov@nexenta.com>
SMB-136 Snapshots not visible in Windows previous versions
SMB-65 SMB server in non-global zones (use zone_kcred())
SMB-65 SMB server in non-global zones (data structure changes)
Many things move to the smb_server_t object, and
many functions gain an sv arg (which server).
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/smbsrv/smb_vss.c
+++ new/usr/src/uts/common/fs/smbsrv/smb_vss.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
23 - * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
23 + * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25
26 26 /*
27 27 * Volume Copy Shadow Services (VSS) provides a way for users to
28 28 * restore/recover deleted files/directories.
29 29 * For the server to support VSS for Microsoft clients, there is
30 30 * two basic functions that need to be implemented.
31 31 * The first is to intercept the NT_TRANSACT_IOCTL command with
32 32 * the function code of FSCTL_SRV_ENUMERATE_SNAPSHOTS (0x00144064).
33 33 * This is to report the count or the count and list of snapshots
34 34 * for that share.
35 35 * The second function need to trap commands with the
36 36 * SMB_FLAGS2_REPARSE_PATH bit set in the smb header. This bit
37 37 * means that there is a @GMT token in path that needs to be
38 38 * processed. The @GMT token means to process this command, but
39 39 * in the snapshot.
40 40 */
41 41
42 42 #include <smbsrv/smb_kproto.h>
43 43 #include <smbsrv/string.h>
44 -#include <smbsrv/winioctl.h>
44 +#include <smb/winioctl.h>
45 45 #include <smbsrv/smb_door.h>
46 46
47 47 /* Size of the token on the wire due to encoding */
48 48 #define SMB_VSS_GMT_NET_SIZE(sr) (smb_ascii_or_unicode_null_len(sr) * \
49 49 SMB_VSS_GMT_SIZE)
50 50
51 51 #define SMB_VSS_COUNT_SIZE 16
52 52
53 53 static boolean_t smb_vss_is_gmttoken(const char *);
54 54 static const char *smb_vss_find_gmttoken(const char *);
55 55 static uint32_t smb_vss_encode_gmttokens(smb_request_t *, smb_fsctl_t *,
56 56 int32_t, smb_gmttoken_response_t *);
57 57 static void smb_vss_remove_first_token_from_path(char *);
58 58
59 59 static uint32_t smb_vss_get_count(smb_tree_t *, char *);
60 60 static void smb_vss_map_gmttoken(smb_tree_t *, char *, char *, time_t, char *);
61 61 static void smb_vss_get_snapshots(smb_tree_t *, char *,
62 62 uint32_t, smb_gmttoken_response_t *);
63 63 static void smb_vss_get_snapshots_free(smb_gmttoken_response_t *);
64 64 static int smb_vss_lookup_node(smb_request_t *sr, smb_node_t *, vnode_t *,
65 65 char *, smb_node_t *, smb_node_t **);
66 66
67 67 /*
68 68 * This is to respond to the nt_transact_ioctl to either respond with the
69 69 * number of snapshots, or to respond with the list. It needs to be sorted
70 70 * before the reply. If the the max data bytes to return is
|
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
71 71 * SMB_VSS_COUNT_SIZE, then all that is requested is the count, otherwise
72 72 * return the count and the list of @GMT tokens (one token for each
73 73 * snapshot).
74 74 */
75 75 uint32_t
76 76 smb_vss_enum_snapshots(smb_request_t *sr, smb_fsctl_t *fsctl)
77 77 {
78 78 uint32_t count = 0;
79 79 char *root_path;
80 80 uint32_t status = NT_STATUS_SUCCESS;
81 - smb_node_t *tnode;
82 81 smb_gmttoken_response_t snaps;
83 82
84 - ASSERT(sr->tid_tree);
85 - ASSERT(sr->tid_tree->t_snode);
83 + ASSERT(sr->fid_ofile);
84 + ASSERT(sr->fid_ofile->f_node);
86 85
87 86 if (fsctl->MaxOutputResp < SMB_VSS_COUNT_SIZE)
88 87 return (NT_STATUS_INVALID_PARAMETER);
89 88
90 - tnode = sr->tid_tree->t_snode;
89 + /*
90 + * smbd will find the root of the lowest filesystem from mntpath of a
91 + * file by comparing it agaisnt mnttab, repeatedly removing components
92 + * until one matches.
93 + */
91 94 root_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
92 - if (smb_node_getmntpath(tnode, root_path, MAXPATHLEN) != 0)
95 + if (smb_node_getmntpath(sr->fid_ofile->f_node, root_path,
96 + MAXPATHLEN) != 0)
93 97 return (NT_STATUS_INVALID_PARAMETER);
94 98
95 99 if (fsctl->MaxOutputResp == SMB_VSS_COUNT_SIZE) {
96 100 count = smb_vss_get_count(sr->tid_tree, root_path);
97 101 if (smb_mbc_encodef(fsctl->out_mbc, "lllw", count, 0,
98 102 (count * SMB_VSS_GMT_NET_SIZE(sr) +
99 103 smb_ascii_or_unicode_null_len(sr)), 0) != 0) {
100 104 status = NT_STATUS_INVALID_PARAMETER;
101 105 }
102 106 } else {
103 107 count = fsctl->MaxOutputResp / SMB_VSS_GMT_NET_SIZE(sr);
104 108
105 109 smb_vss_get_snapshots(sr->tid_tree, root_path,
106 110 count, &snaps);
107 111
108 112 status = smb_vss_encode_gmttokens(sr, fsctl, count, &snaps);
109 113
110 114 smb_vss_get_snapshots_free(&snaps);
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
111 115 }
112 116
113 117 kmem_free(root_path, MAXPATHLEN);
114 118 return (status);
115 119 }
116 120
117 121 /*
118 122 * sr - the request info, used to find root of dataset,
119 123 * unicode or ascii, where the share is rooted in the
120 124 * dataset
121 - * root_node - root of the share
122 125 * cur_node - where in the share for the command
123 - * buf - is the path for the command to be processed
124 - * returned without @GMT if processed
125 126 * vss_cur_node - returned value for the snapshot version
126 127 * of the cur_node
127 - * vss_root_node - returned value for the snapshot version
128 - * of the root_node
128 + * gmttoken - if SMB1, the gmttoken to be used to find the snapshot.
129 + * Otherwise, NULL.
129 130 *
130 131 * This routine is the processing for handling the
131 132 * SMB_FLAGS2_REPARSE_PATH bit being set in the smb header.
132 133 *
133 134 * By using the cur_node passed in, a new node is found or
134 135 * created that is the same place in the directory tree, but
135 - * in the snapshot. We also use root_node to do the same for
136 - * the root.
137 - * Once the new smb node is found, the path is modified by
138 - * removing the @GMT token from the path in the buf.
136 + * in the snapshot.
139 137 */
140 138 int
141 -smb_vss_lookup_nodes(smb_request_t *sr, smb_node_t *root_node,
142 - smb_node_t *cur_node, char *buf, smb_node_t **vss_cur_node,
143 - smb_node_t **vss_root_node)
139 +smb_vss_lookup_nodes(smb_request_t *sr, smb_node_t *cur_node,
140 + smb_node_t **vss_cur_node, char *gmttoken)
144 141 {
145 142 smb_arg_open_t *op = &sr->arg.open;
146 - smb_node_t *tnode;
147 143 char *snapname, *path;
148 - char *gmttoken;
149 - char gmttok_buf[SMB_VSS_GMT_SIZE];
150 144 vnode_t *fsrootvp = NULL;
151 145 time_t toktime;
152 146 int err = 0;
153 - boolean_t smb1;
154 147
155 148 if (sr->tid_tree == NULL)
156 149 return (ESTALE);
157 150
158 - tnode = sr->tid_tree->t_snode;
159 -
160 - ASSERT(tnode);
161 - ASSERT(tnode->vp);
162 - ASSERT(tnode->vp->v_vfsp);
163 -
164 - smb1 = (sr->session->dialect < SMB_VERS_2_BASE);
165 - if (smb1) {
166 - const char *p;
167 -
168 - /* get gmttoken from buf */
169 - if ((p = smb_vss_find_gmttoken(buf)) == NULL)
170 - return (ENOENT);
171 -
172 - bcopy(p, gmttok_buf, SMB_VSS_GMT_SIZE);
173 - gmttok_buf[SMB_VSS_GMT_SIZE - 1] = '\0';
174 - gmttoken = gmttok_buf;
151 + if (gmttoken != NULL) {
175 152 toktime = 0;
176 153 } else {
177 154 /* SMB2 and later */
178 - gmttoken = NULL;
179 155 toktime = op->timewarp.tv_sec;
180 156 }
181 157
182 158 path = smb_srm_alloc(sr, MAXPATHLEN);
183 159 snapname = smb_srm_alloc(sr, MAXPATHLEN);
184 160
185 - err = smb_node_getmntpath(tnode, path, MAXPATHLEN);
161 + err = smb_node_getmntpath(cur_node, path, MAXPATHLEN);
186 162 if (err != 0)
187 163 return (err);
188 164
189 165 /*
190 166 * Find the corresponding snapshot name. If snapname is
191 167 * empty after the map call, no such snapshot was found.
192 168 */
193 169 *snapname = '\0';
194 170 smb_vss_map_gmttoken(sr->tid_tree, path, gmttoken, toktime,
195 171 snapname);
196 172 if (*snapname == '\0')
197 173 return (ENOENT);
198 174
199 175 /* find snapshot nodes */
200 - err = VFS_ROOT(tnode->vp->v_vfsp, &fsrootvp);
176 + err = VFS_ROOT(cur_node->vp->v_vfsp, &fsrootvp);
201 177 if (err != 0)
202 178 return (err);
203 179
204 - /* find snapshot node corresponding to root_node */
205 - err = smb_vss_lookup_node(sr, root_node, fsrootvp,
206 - snapname, cur_node, vss_root_node);
207 - if (err == 0) {
208 - /* find snapshot node corresponding to cur_node */
209 - err = smb_vss_lookup_node(sr, cur_node, fsrootvp,
210 - snapname, cur_node, vss_cur_node);
211 - if (err != 0)
212 - smb_node_release(*vss_root_node);
213 - }
180 + /* find snapshot node corresponding to cur_node */
181 + err = smb_vss_lookup_node(sr, cur_node, fsrootvp,
182 + snapname, cur_node, vss_cur_node);
214 183
215 184 VN_RELE(fsrootvp);
216 185
217 - if (smb1)
218 - smb_vss_remove_first_token_from_path(buf);
219 -
220 186 return (err);
221 187 }
222 188
223 189 /*
224 190 * Find snapshot node corresponding to 'node', and return it in
225 191 * 'vss_node', as follows:
226 192 * - find the path from fsrootvp to node, appending it to the
227 193 * the snapshot path
228 194 * - lookup the vnode and smb_node (vss_node).
229 195 */
230 196 static int
231 197 smb_vss_lookup_node(smb_request_t *sr, smb_node_t *node, vnode_t *fsrootvp,
232 198 char *snapname, smb_node_t *dnode, smb_node_t **vss_node)
233 199 {
234 200 char *p, *path;
235 201 int err, len;
236 202 vnode_t *vp = NULL;
237 203
238 204 *vss_node = NULL;
239 205
240 206 path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
241 207 (void) snprintf(path, MAXPATHLEN, ".zfs/snapshot/%s/", snapname);
242 208 len = strlen(path);
243 209 p = path + len;
244 210
245 211 err = smb_node_getpath(node, fsrootvp, p, MAXPATHLEN - len);
246 212 if (err == 0) {
247 213 vp = smb_lookuppathvptovp(sr, path, fsrootvp, fsrootvp);
248 214 if (vp) {
249 215 *vss_node = smb_node_lookup(sr, NULL, zone_kcred(),
250 216 vp, snapname, dnode, NULL);
251 217 VN_RELE(vp);
252 218 }
253 219 }
254 220
255 221 kmem_free(path, MAXPATHLEN);
256 222
257 223 if (*vss_node != NULL)
258 224 return (0);
259 225
260 226 return (err ? err : ENOENT);
261 227 }
262 228
263 229
264 230 static boolean_t
265 231 smb_vss_is_gmttoken(const char *s)
266 232 {
267 233 char *t = "@GMT-NNNN.NN.NN-NN.NN.NN";
268 234 const char *str;
269 235 char *template;
270 236
271 237 template = t;
272 238 str = s;
273 239
274 240 while (*template) {
275 241 if (*template == 'N') {
276 242 if (!smb_isdigit(*str))
277 243 return (B_FALSE);
278 244 } else if (*template != *str) {
279 245 return (B_FALSE);
280 246 }
281 247
282 248 template++;
283 249 str++;
284 250 }
285 251
286 252 /* Make sure it is JUST the @GMT token */
287 253 if ((*str == '\0') || (*str == '/'))
288 254 return (B_TRUE);
289 255
290 256 return (B_FALSE);
291 257 }
292 258
293 259 static const char *
294 260 smb_vss_find_gmttoken(const char *path)
295 261 {
296 262 const char *p;
297 263
298 264 p = path;
299 265
300 266 while (*p) {
301 267 if (*p == '@' && smb_vss_is_gmttoken(p))
302 268 return (p);
303 269 p++;
304 270 }
305 271 return (NULL);
306 272 }
307 273
308 274 static uint32_t
309 275 smb_vss_encode_gmttokens(smb_request_t *sr, smb_fsctl_t *fsctl,
310 276 int32_t count, smb_gmttoken_response_t *snap_data)
311 277 {
312 278 uint32_t i;
313 279 uint32_t returned_count;
314 280 uint32_t num_gmttokens;
315 281 char **gmttokens;
316 282 uint32_t status = NT_STATUS_SUCCESS;
317 283 uint32_t data_size;
318 284
319 285 returned_count = snap_data->gtr_count;
320 286 num_gmttokens = snap_data->gtr_gmttokens.gtr_gmttokens_len;
321 287 gmttokens = snap_data->gtr_gmttokens.gtr_gmttokens_val;
322 288
323 289 if (returned_count > count)
324 290 status = NT_STATUS_BUFFER_TOO_SMALL;
325 291
326 292 data_size = returned_count * SMB_VSS_GMT_NET_SIZE(sr) +
327 293 smb_ascii_or_unicode_null_len(sr);
328 294
329 295 if (smb_mbc_encodef(fsctl->out_mbc, "lll", returned_count,
330 296 num_gmttokens, data_size) != 0)
331 297 return (NT_STATUS_INVALID_PARAMETER);
332 298
333 299 if (status == NT_STATUS_SUCCESS) {
334 300 for (i = 0; i < num_gmttokens; i++) {
335 301 if (smb_mbc_encodef(fsctl->out_mbc, "%u", sr,
336 302 *gmttokens) != 0)
337 303 status = NT_STATUS_INVALID_PARAMETER;
338 304 gmttokens++;
339 305 }
340 306 }
341 307
342 308 return (status);
343 309 }
344 310
345 311 /* This removes the first @GMT from the path */
346 312 static void
347 313 smb_vss_remove_first_token_from_path(char *path)
348 314 {
349 315 boolean_t found;
350 316 char *src, *dest;
351 317
352 318 src = path;
353 319 dest = path;
354 320
355 321 found = B_FALSE;
356 322
357 323 while (*src != '\0') {
358 324 if (!found && smb_vss_is_gmttoken(src)) {
359 325 src += SMB_VSS_GMT_SIZE - 1;
360 326 if (*src == '/')
361 327 src += 1;
362 328 found = B_TRUE;
363 329 continue;
364 330 }
365 331 *dest = *src;
366 332 src++;
367 333 dest++;
368 334 }
369 335 *dest = *src;
370 336 }
371 337
372 338 /*
373 339 * This returns the number of snapshots for the dataset
374 340 * of the path provided.
375 341 */
376 342 static uint32_t
377 343 smb_vss_get_count(smb_tree_t *tree, char *resource_path)
378 344 {
379 345 uint32_t count = 0;
380 346 int rc;
381 347 smb_string_t path;
382 348
383 349 path.buf = resource_path;
384 350
385 351 rc = smb_kdoor_upcall(tree->t_server, SMB_DR_VSS_GET_COUNT,
386 352 &path, smb_string_xdr, &count, xdr_uint32_t);
387 353
388 354 if (rc != 0)
389 355 count = 0;
390 356
391 357 return (count);
392 358 }
393 359
394 360 /*
395 361 * This takes a path for the root of the dataset and gets the counts of
396 362 * snapshots for that dataset and the list of @GMT tokens (one for each
397 363 * snapshot) up to the count provided.
398 364 *
399 365 * Call smb_vss_get_snapshots_free after to free up the data.
400 366 */
401 367 static void
402 368 smb_vss_get_snapshots(smb_tree_t *tree, char *resource_path,
403 369 uint32_t count, smb_gmttoken_response_t *gmttokens)
404 370 {
405 371 smb_gmttoken_query_t request;
406 372
407 373 request.gtq_count = count;
408 374 request.gtq_path = resource_path;
409 375 bzero(gmttokens, sizeof (smb_gmttoken_response_t));
410 376
411 377 (void) smb_kdoor_upcall(tree->t_server, SMB_DR_VSS_GET_SNAPSHOTS,
412 378 &request, smb_gmttoken_query_xdr,
413 379 gmttokens, smb_gmttoken_response_xdr);
414 380 }
415 381
416 382 static void
417 383 smb_vss_get_snapshots_free(smb_gmttoken_response_t *reply)
418 384 {
|
↓ open down ↓ |
189 lines elided |
↑ open up ↑ |
419 385 xdr_free(smb_gmttoken_response_xdr, (char *)reply);
420 386 }
421 387
422 388 /*
423 389 * Returns the snapshot name for the @GMT token provided for the dataset
424 390 * of the path. If the snapshot cannot be found, a string with a NULL
425 391 * is returned.
426 392 */
427 393 static void
428 394 smb_vss_map_gmttoken(smb_tree_t *tree, char *path, char *gmttoken,
429 - time_t toktime, char *snapname)
395 + time_t toktime, char *snapname)
430 396 {
431 397 smb_gmttoken_snapname_t request;
432 398 smb_string_t result;
433 399
434 400 bzero(&result, sizeof (smb_string_t));
435 401 result.buf = snapname;
436 402
437 403 request.gts_path = path;
438 404 request.gts_gmttoken = gmttoken;
439 405 request.gts_toktime = toktime;
440 406
441 407 (void) smb_kdoor_upcall(tree->t_server, SMB_DR_VSS_MAP_GMTTOKEN,
442 408 &request, smb_gmttoken_snapname_xdr,
443 409 &result, smb_string_xdr);
410 +}
411 +
412 +int
413 +smb_vss_extract_gmttoken(char *buf, char *gmttoken)
414 +{
415 + const char *p;
416 +
417 + /* get gmttoken from buf */
418 + if ((p = smb_vss_find_gmttoken(buf)) == NULL)
419 + return (ENOENT);
420 +
421 + bcopy(p, gmttoken, SMB_VSS_GMT_SIZE);
422 + gmttoken[SMB_VSS_GMT_SIZE - 1] = '\0';
423 +
424 + smb_vss_remove_first_token_from_path(buf);
425 +
426 + return (0);
444 427 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX