Print this page
Build provider 3rd arg from smb_request_t
hacking...
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/smbsrv/smb_directory.c
+++ new/usr/src/uts/common/fs/smbsrv/smb_directory.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 *
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 2010 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 *
25 25 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
26 26 */
27 27
28 28 #include <smbsrv/smb_kproto.h>
29 29 #include <smbsrv/smbinfo.h>
30 30 #include <smbsrv/smb_fsops.h>
31 31
32 32 /*
33 33 * The create directory message is sent to create a new directory. The
34 34 * appropriate Tid and additional pathname are passed. The directory must
35 35 * not exist for it to be created.
36 36 *
37 37 * Client Request Description
38 38 * ================================== =================================
39 39 * UCHAR WordCount; Count of parameter words = 0
40 40 * USHORT ByteCount; Count of data bytes; min = 2
41 41 * UCHAR BufferFormat; 0x04
42 42 * STRING DirectoryName[]; Directory name
43 43 *
44 44 * Servers require clients to have at least create permission for the
45 45 * subtree containing the directory in order to create a new directory.
46 46 * The creator's access rights to the new directory are be determined by
47 47 * local policy on the server.
48 48 *
49 49 * Server Response Description
50 50 * ================================== =================================
51 51 * UCHAR WordCount; Count of parameter words = 0
↓ open down ↓ |
51 lines elided |
↑ open up ↑ |
52 52 * USHORT ByteCount; Count of data bytes = 0
53 53 */
54 54 smb_sdrc_t
55 55 smb_pre_create_directory(smb_request_t *sr)
56 56 {
57 57 int rc;
58 58
59 59 rc = smbsr_decode_data(sr, "%S", sr,
60 60 &sr->arg.dirop.fqi.fq_path.pn_path);
61 61
62 - DTRACE_SMB_2(op__CreateDirectory__start, smb_request_t *, sr,
63 - struct dirop *, &sr->arg.dirop);
62 + DTRACE_SMB_1(op__CreateDirectory__start, smb_request_t *, sr); /* arg.dirop */
64 63
65 64 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
66 65 }
67 66
68 67 void
69 68 smb_post_create_directory(smb_request_t *sr)
70 69 {
71 70 DTRACE_SMB_1(op__CreateDirectory__done, smb_request_t *, sr);
72 71 }
73 72
74 73 smb_sdrc_t
75 74 smb_com_create_directory(smb_request_t *sr)
76 75 {
77 76 int rc = 0;
78 77 smb_pathname_t *pn = &sr->arg.dirop.fqi.fq_path;
79 78
80 79 if (!STYPE_ISDSK(sr->tid_tree->t_res_type)) {
81 80 smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
82 81 ERRDOS, ERROR_ACCESS_DENIED);
83 82 return (SDRC_ERROR);
84 83 }
85 84
86 85 smb_pathname_init(sr, pn, pn->pn_path);
87 86 if (!smb_pathname_validate(sr, pn) ||
88 87 !smb_validate_dirname(sr, pn)) {
89 88 return (SDRC_ERROR);
90 89 }
91 90
92 91 if ((rc = smb_common_create_directory(sr)) != 0) {
93 92 smbsr_errno(sr, rc);
94 93 return (SDRC_ERROR);
95 94 }
96 95
97 96 rc = smbsr_encode_empty_result(sr);
98 97 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
99 98 }
100 99
101 100 /*
102 101 * smb_common_create_directory
103 102 *
104 103 * Currently called from:
105 104 * smb_com_create_directory
106 105 * smb_com_trans2_create_directory
107 106 *
108 107 * Returns errno values.
109 108 */
110 109 int
111 110 smb_common_create_directory(smb_request_t *sr)
112 111 {
113 112 int rc;
114 113 smb_attr_t new_attr;
115 114 smb_fqi_t *fqi;
116 115 smb_node_t *tnode;
117 116
118 117 fqi = &sr->arg.dirop.fqi;
119 118 tnode = sr->tid_tree->t_snode;
120 119
121 120 rc = smb_pathname_reduce(sr, sr->user_cr, fqi->fq_path.pn_path,
122 121 tnode, tnode, &fqi->fq_dnode, fqi->fq_last_comp);
123 122 if (rc != 0)
124 123 return (rc);
125 124
126 125 if (smb_is_invalid_filename(fqi->fq_last_comp)) {
127 126 smb_node_release(fqi->fq_dnode);
128 127 return (EILSEQ); /* NT_STATUS_OBJECT_NAME_INVALID */
129 128 }
130 129
131 130 /* lookup node - to ensure that it does NOT exist */
132 131 rc = smb_fsop_lookup(sr, sr->user_cr, SMB_FOLLOW_LINKS,
133 132 tnode, fqi->fq_dnode, fqi->fq_last_comp, &fqi->fq_fnode);
134 133 if (rc == 0) {
135 134 smb_node_release(fqi->fq_dnode);
136 135 smb_node_release(fqi->fq_fnode);
137 136 return (EEXIST);
138 137 }
139 138 if (rc != ENOENT) {
140 139 smb_node_release(fqi->fq_dnode);
141 140 return (rc);
142 141 }
143 142
144 143 rc = smb_fsop_access(sr, sr->user_cr, fqi->fq_dnode,
145 144 FILE_ADD_SUBDIRECTORY);
146 145 if (rc != NT_STATUS_SUCCESS) {
147 146 smb_node_release(fqi->fq_dnode);
148 147 return (EACCES);
149 148 }
150 149
151 150 /*
152 151 * Explicitly set sa_dosattr, otherwise the file system may
153 152 * automatically apply FILE_ATTRIBUTE_ARCHIVE which, for
154 153 * compatibility with windows servers, should not be set.
155 154 */
156 155 bzero(&new_attr, sizeof (new_attr));
157 156 new_attr.sa_dosattr = FILE_ATTRIBUTE_DIRECTORY;
158 157 new_attr.sa_vattr.va_type = VDIR;
159 158 new_attr.sa_vattr.va_mode = 0777;
160 159 new_attr.sa_mask = SMB_AT_TYPE | SMB_AT_MODE | SMB_AT_DOSATTR;
161 160
162 161 rc = smb_fsop_mkdir(sr, sr->user_cr, fqi->fq_dnode, fqi->fq_last_comp,
163 162 &new_attr, &fqi->fq_fnode);
164 163 if (rc != 0) {
165 164 smb_node_release(fqi->fq_dnode);
166 165 return (rc);
167 166 }
168 167
169 168 sr->arg.open.create_options = FILE_DIRECTORY_FILE;
170 169
171 170 smb_node_release(fqi->fq_dnode);
172 171 smb_node_release(fqi->fq_fnode);
173 172 return (0);
174 173 }
175 174
176 175 /*
177 176 * The delete directory message is sent to delete an empty directory. The
178 177 * appropriate Tid and additional pathname are passed. The directory must
179 178 * be empty for it to be deleted.
180 179 *
181 180 * NT supports a hidden permission known as File Delete Child (FDC). If
182 181 * the user has FullControl access to a directory, the user is permitted
183 182 * to delete any object in the directory regardless of the permissions
184 183 * on the object.
185 184 *
186 185 * Client Request Description
187 186 * ================================== =================================
188 187 * UCHAR WordCount; Count of parameter words = 0
189 188 * USHORT ByteCount; Count of data bytes; min = 2
190 189 * UCHAR BufferFormat; 0x04
191 190 * STRING DirectoryName[]; Directory name
192 191 *
193 192 * The directory to be deleted cannot be the root of the share specified
194 193 * by Tid.
195 194 *
196 195 * Server Response Description
197 196 * ================================== =================================
198 197 * UCHAR WordCount; Count of parameter words = 0
↓ open down ↓ |
125 lines elided |
↑ open up ↑ |
199 198 * USHORT ByteCount; Count of data bytes = 0
200 199 */
201 200 smb_sdrc_t
202 201 smb_pre_delete_directory(smb_request_t *sr)
203 202 {
204 203 int rc;
205 204
206 205 rc = smbsr_decode_data(sr, "%S", sr,
207 206 &sr->arg.dirop.fqi.fq_path.pn_path);
208 207
209 - DTRACE_SMB_2(op__DeleteDirectory__start, smb_request_t *, sr,
210 - struct dirop *, &sr->arg.dirop);
208 + DTRACE_SMB_1(op__DeleteDirectory__start, smb_request_t *, sr); /* arg.dirop */
211 209
212 210 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
213 211 }
214 212
215 213 void
216 214 smb_post_delete_directory(smb_request_t *sr)
217 215 {
218 216 DTRACE_SMB_1(op__DeleteDirectory__done, smb_request_t *, sr);
219 217 }
220 218
221 219 smb_sdrc_t
222 220 smb_com_delete_directory(smb_request_t *sr)
223 221 {
224 222 int rc;
225 223 uint32_t flags = 0;
226 224 smb_fqi_t *fqi;
227 225 smb_node_t *tnode;
228 226
229 227 if (!STYPE_ISDSK(sr->tid_tree->t_res_type)) {
230 228 smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
231 229 ERRDOS, ERROR_ACCESS_DENIED);
232 230 return (SDRC_ERROR);
233 231 }
234 232
235 233 fqi = &sr->arg.dirop.fqi;
236 234 tnode = sr->tid_tree->t_snode;
237 235
238 236 smb_pathname_init(sr, &fqi->fq_path, fqi->fq_path.pn_path);
239 237 if (!smb_pathname_validate(sr, &fqi->fq_path) ||
240 238 !smb_validate_dirname(sr, &fqi->fq_path)) {
241 239 return (SDRC_ERROR);
242 240 }
243 241
244 242 rc = smb_pathname_reduce(sr, sr->user_cr, fqi->fq_path.pn_path,
245 243 tnode, tnode, &fqi->fq_dnode, fqi->fq_last_comp);
246 244
247 245 if (rc != 0) {
248 246 smbsr_errno(sr, rc);
249 247 return (SDRC_ERROR);
250 248 }
251 249
252 250 rc = smb_fsop_lookup(sr, sr->user_cr, SMB_FOLLOW_LINKS,
253 251 tnode, fqi->fq_dnode, fqi->fq_last_comp, &fqi->fq_fnode);
254 252 if (rc != 0) {
255 253 if (rc == ENOENT)
256 254 smbsr_error(sr, NT_STATUS_OBJECT_NAME_NOT_FOUND,
257 255 ERRDOS, ERROR_FILE_NOT_FOUND);
258 256 else
259 257 smbsr_errno(sr, rc);
260 258 smb_node_release(fqi->fq_dnode);
261 259 return (SDRC_ERROR);
262 260 }
263 261
264 262 /*
265 263 * Delete should fail if this is the root of a share
266 264 * or a DFS link
267 265 */
268 266 if ((fqi->fq_fnode == tnode) || smb_node_is_dfslink(fqi->fq_fnode)) {
269 267 smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
270 268 ERRDOS, ERROR_ACCESS_DENIED);
271 269 smb_node_release(fqi->fq_dnode);
272 270 smb_node_release(fqi->fq_fnode);
273 271 return (SDRC_ERROR);
274 272 }
275 273
276 274 if (!smb_node_is_dir(fqi->fq_fnode)) {
277 275 smbsr_error(sr, NT_STATUS_NOT_A_DIRECTORY,
278 276 ERRDOS, ERROR_PATH_NOT_FOUND);
279 277 smb_node_release(fqi->fq_dnode);
280 278 smb_node_release(fqi->fq_fnode);
281 279 return (SDRC_ERROR);
282 280 }
283 281
284 282 /*
285 283 * Using kcred because we just want the DOS attrs
286 284 * and don't want access errors for this.
287 285 */
288 286 fqi->fq_fattr.sa_mask = SMB_AT_DOSATTR;
289 287 rc = smb_node_getattr(sr, fqi->fq_fnode, zone_kcred(), NULL,
290 288 &fqi->fq_fattr);
291 289 if (rc != 0) {
292 290 smbsr_errno(sr, rc);
293 291 smb_node_release(fqi->fq_dnode);
294 292 smb_node_release(fqi->fq_fnode);
295 293 return (SDRC_ERROR);
296 294 }
297 295
298 296 if ((fqi->fq_fattr.sa_dosattr & FILE_ATTRIBUTE_READONLY) ||
299 297 (smb_fsop_access(sr, sr->user_cr, fqi->fq_fnode, DELETE)
300 298 != NT_STATUS_SUCCESS)) {
301 299 smbsr_error(sr, NT_STATUS_CANNOT_DELETE,
302 300 ERRDOS, ERROR_ACCESS_DENIED);
303 301 smb_node_release(fqi->fq_dnode);
304 302 smb_node_release(fqi->fq_fnode);
305 303 return (SDRC_ERROR);
306 304 }
307 305
308 306 if (SMB_TREE_SUPPORTS_CATIA(sr))
309 307 flags |= SMB_CATIA;
310 308
311 309 rc = smb_fsop_rmdir(sr, sr->user_cr, fqi->fq_dnode,
312 310 fqi->fq_fnode->od_name, flags);
313 311
314 312 smb_node_release(fqi->fq_fnode);
315 313 smb_node_release(fqi->fq_dnode);
316 314
317 315 if (rc != 0) {
318 316 if (rc == EEXIST)
319 317 smbsr_error(sr, NT_STATUS_DIRECTORY_NOT_EMPTY,
320 318 ERRDOS, ERROR_DIR_NOT_EMPTY);
321 319 else
322 320 smbsr_errno(sr, rc);
323 321 return (SDRC_ERROR);
324 322 }
325 323
326 324 rc = smbsr_encode_empty_result(sr);
327 325 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
328 326 }
329 327
330 328 /*
331 329 * This SMB is used to verify that a path exists and is a directory. No
332 330 * error is returned if the given path exists and the client has read
333 331 * access to it. Client machines which maintain a concept of a "working
334 332 * directory" will find this useful to verify the validity of a "change
335 333 * working directory" command. Note that the servers do NOT have a concept
336 334 * of working directory for a particular client. The client must always
337 335 * supply full pathnames relative to the Tid in the SMB header.
338 336 *
339 337 * Client Request Description
340 338 * ================================== =================================
341 339 *
342 340 * UCHAR WordCount; Count of parameter words = 0
343 341 * USHORT ByteCount; Count of data bytes; min = 2
344 342 * UCHAR BufferFormat; 0x04
345 343 * STRING DirectoryPath[]; Directory path
346 344 *
347 345 * Server Response Description
348 346 * ================================== =================================
349 347 *
350 348 * UCHAR WordCount; Count of parameter words = 0
351 349 * USHORT ByteCount; Count of data bytes = 0
352 350 *
353 351 * DOS clients, in particular, depend on ERRbadpath if the directory is
↓ open down ↓ |
133 lines elided |
↑ open up ↑ |
354 352 * not found.
355 353 */
356 354 smb_sdrc_t
357 355 smb_pre_check_directory(smb_request_t *sr)
358 356 {
359 357 int rc;
360 358
361 359 rc = smbsr_decode_data(sr, "%S", sr,
362 360 &sr->arg.dirop.fqi.fq_path.pn_path);
363 361
364 - DTRACE_SMB_2(op__CheckDirectory__start, smb_request_t *, sr,
365 - struct dirop *, &sr->arg.dirop);
362 + DTRACE_SMB_1(op__CheckDirectory__start, smb_request_t *, sr); /* arg.dirop */
366 363
367 364 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
368 365 }
369 366
370 367 void
371 368 smb_post_check_directory(smb_request_t *sr)
372 369 {
373 370 DTRACE_SMB_1(op__CheckDirectory__done, smb_request_t *, sr);
374 371 }
375 372
376 373 smb_sdrc_t
377 374 smb_com_check_directory(smb_request_t *sr)
378 375 {
379 376 int rc;
380 377 smb_fqi_t *fqi;
381 378 smb_node_t *tnode;
382 379 smb_node_t *node;
383 380 char *path;
384 381 smb_pathname_t *pn;
385 382
386 383 if (STYPE_ISIPC(sr->tid_tree->t_res_type)) {
387 384 smbsr_error(sr, NT_STATUS_ACCESS_DENIED, ERRDOS,
388 385 ERROR_ACCESS_DENIED);
389 386 return (SDRC_ERROR);
390 387 }
391 388
392 389 fqi = &sr->arg.dirop.fqi;
393 390 pn = &fqi->fq_path;
394 391
395 392 if (pn->pn_path[0] == '\0') {
396 393 rc = smbsr_encode_empty_result(sr);
397 394 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
398 395 }
399 396
400 397 smb_pathname_init(sr, pn, pn->pn_path);
401 398 if (!smb_pathname_validate(sr, pn) ||
402 399 !smb_validate_dirname(sr, pn)) {
403 400 return (SDRC_ERROR);
404 401 }
405 402
406 403 path = pn->pn_path;
407 404 tnode = sr->tid_tree->t_snode;
408 405
409 406 rc = smb_pathname_reduce(sr, sr->user_cr, path, tnode, tnode,
410 407 &fqi->fq_dnode, fqi->fq_last_comp);
411 408 if (rc != 0) {
412 409 smbsr_errno(sr, rc);
413 410 return (SDRC_ERROR);
414 411 }
415 412
416 413 rc = smb_fsop_lookup(sr, sr->user_cr, SMB_FOLLOW_LINKS,
417 414 tnode, fqi->fq_dnode, fqi->fq_last_comp, &fqi->fq_fnode);
418 415 smb_node_release(fqi->fq_dnode);
419 416 if (rc != 0) {
420 417 if (rc == ENOENT)
421 418 smbsr_error(sr, NT_STATUS_OBJECT_NAME_NOT_FOUND,
422 419 ERRDOS, ERROR_PATH_NOT_FOUND);
423 420 else
424 421 smbsr_errno(sr, rc);
425 422 return (SDRC_ERROR);
426 423 }
427 424
428 425 node = fqi->fq_fnode;
429 426 if (!smb_node_is_dir(node)) {
430 427 smbsr_error(sr, NT_STATUS_NOT_A_DIRECTORY,
431 428 ERRDOS, ERROR_PATH_NOT_FOUND);
432 429 smb_node_release(node);
433 430 return (SDRC_ERROR);
434 431 }
435 432
436 433 if ((sr->smb_flg2 & SMB_FLAGS2_DFS) && smb_node_is_dfslink(node)) {
437 434 smbsr_error(sr, NT_STATUS_PATH_NOT_COVERED, ERRSRV, ERRbadpath);
438 435 smb_node_release(node);
439 436 return (SDRC_ERROR);
440 437 }
441 438
442 439 rc = smb_fsop_access(sr, sr->user_cr, node, FILE_TRAVERSE);
443 440
444 441 smb_node_release(node);
445 442
446 443 if (rc != 0) {
447 444 smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
448 445 ERRDOS, ERROR_ACCESS_DENIED);
449 446 return (SDRC_ERROR);
450 447 }
451 448
452 449 rc = smbsr_encode_empty_result(sr);
453 450 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
454 451 }
↓ open down ↓ |
79 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX