1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2019 Nexenta by DDN, Inc. All rights reserved.
*/
/*
* Trans2 Set File/Path Information Levels:
*
* SMB_INFO_STANDARD
* SMB_INFO_SET_EAS
* SMB_SET_FILE_BASIC_INFO
* SMB_SET_FILE_DISPOSITION_INFO
* SMB_SET_FILE_END_OF_FILE_INFO
* SMB_SET_FILE_ALLOCATION_INFO
*
* Handled Passthrough levels:
* SMB_FILE_BASIC_INFORMATION
* SMB_FILE_RENAME_INFORMATION
* SMB_FILE_LINK_INFORMATION
* SMB_FILE_DISPOSITION_INFORMATION
* SMB_FILE_END_OF_FILE_INFORMATION
* SMB_FILE_ALLOCATION_INFORMATION
*
* Internal levels representing non trans2 requests
* SMB_SET_INFORMATION
* SMB_SET_INFORMATION2
*/
/*
* Setting timestamps:
* The behaviour when the time field is set to -1 is not documented
* but is generally treated like 0, meaning that that server file
* system assigned value need not be changed.
*
* Setting attributes - FILE_ATTRIBUTE_NORMAL:
* SMB_SET_INFORMATION -
* - if the specified attributes have ONLY FILE_ATTRIBUTE_NORMAL set
* do NOT change the file's attributes.
* SMB_SET_BASIC_INFO -
* - if the specified attributes have ONLY FILE_ATTRIBUTE_NORMAL set
* clear (0) the file's attributes.
* - if the specified attributes are 0 do NOT change the file's
* attributes.
*/
#include <smbsrv/smb_kproto.h>
#include <smbsrv/smb_fsops.h>
static int smb_set_by_fid(smb_request_t *, smb_xa_t *, uint16_t);
static int smb_set_by_path(smb_request_t *, smb_xa_t *, uint16_t);
/*
* These functions all return and NT status code.
*/
static uint32_t smb_set_fileinfo(smb_request_t *, smb_setinfo_t *, int);
static uint32_t smb_set_information(smb_request_t *, smb_setinfo_t *);
static uint32_t smb_set_information2(smb_request_t *, smb_setinfo_t *);
static uint32_t smb_set_standard_info(smb_request_t *, smb_setinfo_t *);
static uint32_t smb_set_rename_info(smb_request_t *sr, smb_setinfo_t *);
/*
* smb_com_trans2_set_file_information
*/
smb_sdrc_t
smb_com_trans2_set_file_information(smb_request_t *sr, smb_xa_t *xa)
{
uint16_t infolev;
if (smb_mbc_decodef(&xa->req_param_mb, "ww",
&sr->smb_fid, &infolev) != 0)
return (SDRC_ERROR);
if (smb_set_by_fid(sr, xa, infolev) != 0)
return (SDRC_ERROR);
return (SDRC_SUCCESS);
}
/*
* smb_com_trans2_set_path_information
*/
smb_sdrc_t
smb_com_trans2_set_path_information(smb_request_t *sr, smb_xa_t *xa)
{
uint16_t infolev;
smb_fqi_t *fqi = &sr->arg.dirop.fqi;
if (STYPE_ISIPC(sr->tid_tree->t_res_type)) {
smbsr_error(sr, NT_STATUS_INVALID_DEVICE_REQUEST,
ERRDOS, ERROR_INVALID_FUNCTION);
return (SDRC_ERROR);
}
if (smb_mbc_decodef(&xa->req_param_mb, "%w4.u",
sr, &infolev, &fqi->fq_path.pn_path) != 0)
return (SDRC_ERROR);
if (smb_set_by_path(sr, xa, infolev) != 0)
return (SDRC_ERROR);
return (SDRC_SUCCESS);
}
/*
* smb_com_set_information (aka setattr)
*/
smb_sdrc_t
smb_pre_set_information(smb_request_t *sr)
{
DTRACE_SMB_START(op__SetInformation, smb_request_t *, sr);
return (SDRC_SUCCESS);
}
void
smb_post_set_information(smb_request_t *sr)
{
DTRACE_SMB_DONE(op__SetInformation, smb_request_t *, sr);
}
smb_sdrc_t
smb_com_set_information(smb_request_t *sr)
{
uint16_t infolev = SMB_SET_INFORMATION;
smb_fqi_t *fqi = &sr->arg.dirop.fqi;
if (STYPE_ISIPC(sr->tid_tree->t_res_type)) {
smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
ERRDOS, ERROR_ACCESS_DENIED);
return (SDRC_ERROR);
}
if (smbsr_decode_data(sr, "%S", sr, &fqi->fq_path.pn_path) != 0)
return (SDRC_ERROR);
if (smb_set_by_path(sr, NULL, infolev) != 0)
return (SDRC_ERROR);
if (smbsr_encode_empty_result(sr) != 0)
return (SDRC_ERROR);
return (SDRC_SUCCESS);
}
/*
* smb_com_set_information2 (aka setattre)
*/
smb_sdrc_t
smb_pre_set_information2(smb_request_t *sr)
{
DTRACE_SMB_START(op__SetInformation2, smb_request_t *, sr);
return (SDRC_SUCCESS);
}
void
smb_post_set_information2(smb_request_t *sr)
{
DTRACE_SMB_DONE(op__SetInformation2, smb_request_t *, sr);
}
smb_sdrc_t
smb_com_set_information2(smb_request_t *sr)
{
uint16_t infolev = SMB_SET_INFORMATION2;
if (smbsr_decode_vwv(sr, "w", &sr->smb_fid) != 0)
return (SDRC_ERROR);
if (smb_set_by_fid(sr, NULL, infolev) != 0)
return (SDRC_ERROR);
if (smbsr_encode_empty_result(sr) != 0)
return (SDRC_ERROR);
return (SDRC_SUCCESS);
}
/*
* smb_set_by_fid
*
* Common code for setting file information by open file id.
* Use the id to identify the node object and invoke smb_set_fileinfo
* for that node.
*
* Setting attributes on a named pipe by id is handled by simply
* returning success.
*/
static int
smb_set_by_fid(smb_request_t *sr, smb_xa_t *xa, uint16_t infolev)
{
smb_setinfo_t sinfo;
uint32_t status;
int rc = 0;
if (SMB_TREE_IS_READONLY(sr)) {
smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
ERRDOS, ERROR_ACCESS_DENIED);
return (-1);
}
if (STYPE_ISIPC(sr->tid_tree->t_res_type))
return (0);
smbsr_lookup_file(sr);
if (sr->fid_ofile == NULL) {
smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
return (-1);
}
if (!SMB_FTYPE_IS_DISK(sr->fid_ofile->f_ftype)) {
smbsr_release_file(sr);
return (0);
}
sr->user_cr = smb_ofile_getcred(sr->fid_ofile);
bzero(&sinfo, sizeof (sinfo));
sinfo.si_node = sr->fid_ofile->f_node;
if (xa != NULL)
sinfo.si_data = xa->req_data_mb;
status = smb_set_fileinfo(sr, &sinfo, infolev);
if (status != 0) {
smbsr_error(sr, status, 0, 0);
rc = -1;
}
smbsr_release_file(sr);
return (rc);
}
/*
* smb_set_by_path
*
* Common code for setting file information by file name.
* Use the file name to identify the node object and invoke
* smb_set_fileinfo for that node.
*
* Path should be set in sr->arg.dirop.fqi.fq_path prior to
* calling smb_set_by_path.
*
* Setting attributes on a named pipe by name is an error and
* is handled in the calling functions so that they can return
* the appropriate error status code (which differs by caller).
*/
static int
smb_set_by_path(smb_request_t *sr, smb_xa_t *xa, uint16_t infolev)
{
int rc;
uint32_t status;
smb_setinfo_t sinfo;
smb_node_t *node, *dnode;
char *name;
smb_pathname_t *pn;
if (SMB_TREE_IS_READONLY(sr)) {
smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
ERRDOS, ERROR_ACCESS_DENIED);
return (-1);
}
if (STYPE_ISIPC(sr->tid_tree->t_res_type))
return (0);
pn = &sr->arg.dirop.fqi.fq_path;
smb_pathname_init(sr, pn, pn->pn_path);
if (!smb_pathname_validate(sr, pn))
return (-1);
name = kmem_alloc(MAXNAMELEN, KM_SLEEP);
rc = smb_pathname_reduce(sr, sr->user_cr, pn->pn_path,
sr->tid_tree->t_snode, sr->tid_tree->t_snode, &dnode, name);
if (rc == 0) {
rc = smb_fsop_lookup_name(sr, sr->user_cr, SMB_FOLLOW_LINKS,
sr->tid_tree->t_snode, dnode, name, &node);
smb_node_release(dnode);
}
kmem_free(name, MAXNAMELEN);
if (rc != 0) {
smbsr_errno(sr, rc);
return (-1);
}
bzero(&sinfo, sizeof (sinfo));
sinfo.si_node = node;
if (xa != NULL)
sinfo.si_data = xa->req_data_mb;
status = smb_set_fileinfo(sr, &sinfo, infolev);
if (status != 0) {
smbsr_error(sr, status, 0, 0);
rc = -1;
}
smb_node_release(node);
return (rc);
}
/*
* smb_set_fileinfo
*
* For compatibility with windows servers, SMB_FILE_LINK_INFORMATION
* is handled by returning NT_STATUS_NOT_SUPPORTED.
*/
static uint32_t
smb_set_fileinfo(smb_request_t *sr, smb_setinfo_t *sinfo, int infolev)
{
uint32_t status;
switch (infolev) {
case SMB_SET_INFORMATION:
status = smb_set_information(sr, sinfo);
break;
case SMB_SET_INFORMATION2:
status = smb_set_information2(sr, sinfo);
break;
case SMB_INFO_STANDARD:
status = smb_set_standard_info(sr, sinfo);
break;
case SMB_INFO_SET_EAS:
status = NT_STATUS_EAS_NOT_SUPPORTED;
break;
case SMB_SET_FILE_BASIC_INFO:
case SMB_FILE_BASIC_INFORMATION:
status = smb_set_basic_info(sr, sinfo);
break;
case SMB_SET_FILE_DISPOSITION_INFO:
case SMB_FILE_DISPOSITION_INFORMATION:
status = smb_set_disposition_info(sr, sinfo);
break;
case SMB_SET_FILE_END_OF_FILE_INFO:
case SMB_FILE_END_OF_FILE_INFORMATION:
status = smb_set_eof_info(sr, sinfo);
break;
case SMB_SET_FILE_ALLOCATION_INFO:
case SMB_FILE_ALLOCATION_INFORMATION:
status = smb_set_alloc_info(sr, sinfo);
break;
case SMB_FILE_RENAME_INFORMATION:
status = smb_set_rename_info(sr, sinfo);
break;
case SMB_FILE_LINK_INFORMATION:
status = NT_STATUS_NOT_SUPPORTED;
break;
default:
status = NT_STATUS_INVALID_INFO_CLASS;
break;
}
return (status);
}
/*
* smb_set_information
*
* It is not valid to set FILE_ATTRIBUTE_DIRECTORY if the
* target is not a directory.
*
* For compatibility with Windows Servers, if the specified
* attributes have ONLY FILE_ATTRIBUTE_NORMAL set do NOT change
* the file's attributes.
*/
static uint32_t
smb_set_information(smb_request_t *sr, smb_setinfo_t *sinfo)
{
smb_attr_t attr;
smb_node_t *node = sinfo->si_node;
uint32_t status = 0;
uint32_t mtime;
uint16_t attributes;
int rc;
if (smbsr_decode_vwv(sr, "wl10.", &attributes, &mtime) != 0)
return (NT_STATUS_INFO_LENGTH_MISMATCH);
if ((attributes & FILE_ATTRIBUTE_DIRECTORY) &&
(!smb_node_is_dir(node))) {
return (NT_STATUS_INVALID_PARAMETER);
}
bzero(&attr, sizeof (smb_attr_t));
if (attributes != FILE_ATTRIBUTE_NORMAL) {
attr.sa_dosattr = attributes;
attr.sa_mask |= SMB_AT_DOSATTR;
}
if (mtime != 0 && mtime != UINT_MAX) {
attr.sa_vattr.va_mtime.tv_sec =
smb_time_local_to_gmt(sr, mtime);
attr.sa_mask |= SMB_AT_MTIME;
}
rc = smb_node_setattr(sr, node, sr->user_cr, NULL, &attr);
if (rc != 0)
status = smb_errno2status(rc);
return (status);
}
/*
* smb_set_information2
*/
static uint32_t
smb_set_information2(smb_request_t *sr, smb_setinfo_t *sinfo)
{
smb_attr_t attr;
uint32_t crtime, atime, mtime;
uint32_t status = 0;
int rc;
if (smbsr_decode_vwv(sr, "yyy", &crtime, &atime, &mtime) != 0)
return (NT_STATUS_INFO_LENGTH_MISMATCH);
bzero(&attr, sizeof (smb_attr_t));
if (mtime != 0 && mtime != UINT_MAX) {
attr.sa_vattr.va_mtime.tv_sec =
smb_time_local_to_gmt(sr, mtime);
attr.sa_mask |= SMB_AT_MTIME;
}
if (crtime != 0 && crtime != UINT_MAX) {
attr.sa_crtime.tv_sec = smb_time_local_to_gmt(sr, crtime);
attr.sa_mask |= SMB_AT_CRTIME;
}
if (atime != 0 && atime != UINT_MAX) {
attr.sa_vattr.va_atime.tv_sec =
smb_time_local_to_gmt(sr, atime);
attr.sa_mask |= SMB_AT_ATIME;
}
rc = smb_node_setattr(sr, sinfo->si_node, sr->user_cr,
sr->fid_ofile, &attr);
if (rc != 0)
status = smb_errno2status(rc);
return (status);
}
/*
* smb_set_standard_info
*
* Sets standard file/path information.
*/
static uint32_t
smb_set_standard_info(smb_request_t *sr, smb_setinfo_t *sinfo)
{
smb_attr_t attr;
smb_node_t *node = sinfo->si_node;
uint32_t crtime, atime, mtime;
uint32_t status = 0;
int rc;
if (smb_mbc_decodef(&sinfo->si_data, "yyy",
&crtime, &atime, &mtime) != 0)
return (NT_STATUS_INFO_LENGTH_MISMATCH);
bzero(&attr, sizeof (smb_attr_t));
if (mtime != 0 && mtime != (uint32_t)-1) {
attr.sa_vattr.va_mtime.tv_sec =
smb_time_local_to_gmt(sr, mtime);
attr.sa_mask |= SMB_AT_MTIME;
}
if (crtime != 0 && crtime != (uint32_t)-1) {
attr.sa_crtime.tv_sec = smb_time_local_to_gmt(sr, crtime);
attr.sa_mask |= SMB_AT_CRTIME;
}
if (atime != 0 && atime != (uint32_t)-1) {
attr.sa_vattr.va_atime.tv_sec =
smb_time_local_to_gmt(sr, atime);
attr.sa_mask |= SMB_AT_ATIME;
}
rc = smb_node_setattr(sr, node, sr->user_cr, sr->fid_ofile, &attr);
if (rc != 0)
status = smb_errno2status(rc);
return (status);
}
/*
* smb_set_rename_info
*
* This call only allows a rename in the same directory, and the
* directory name is not part of the new name provided.
*
* Explicitly specified parameter validation rules:
* - If rootdir is not NULL respond with NT_STATUS_INVALID_PARAMETER.
* - If the filename contains a separator character respond with
* NT_STATUS_INVALID_PARAMETER.
*
* Oplock break:
* Some Windows servers break BATCH oplocks prior to the rename.
* W2K3 does not. We behave as W2K3; we do not send an oplock break.
*/
static uint32_t
smb_set_rename_info(smb_request_t *sr, smb_setinfo_t *sinfo)
{
smb_fqi_t *src_fqi = &sr->arg.dirop.fqi;
smb_fqi_t *dst_fqi = &sr->arg.dirop.dst_fqi;
char *fname;
char *path;
uint8_t flags;
uint32_t rootdir, namelen;
uint32_t status = 0;
int rc;
rc = smb_mbc_decodef(&sinfo->si_data, "b...ll",
&flags, &rootdir, &namelen);
if (rc == 0) {
rc = smb_mbc_decodef(&sinfo->si_data, "%#U",
sr, namelen, &fname);
}
if (rc != 0)
return (NT_STATUS_INFO_LENGTH_MISMATCH);
if ((rootdir != 0) || (namelen == 0) || (namelen >= MAXNAMELEN)) {
return (NT_STATUS_INVALID_PARAMETER);
}
if (strchr(fname, '\\') != NULL) {
return (NT_STATUS_NOT_SUPPORTED);
}
/*
* Construct the full dst. path relative to the share root.
* Allocated path is free'd in smb_request_free.
*/
path = smb_srm_zalloc(sr, SMB_MAXPATHLEN);
if (src_fqi->fq_path.pn_pname) {
/* Got here via: smb_set_by_path */
(void) snprintf(path, SMB_MAXPATHLEN, "%s\\%s",
src_fqi->fq_path.pn_pname, fname);
} else {
/* Got here via: smb_set_by_fid */
rc = smb_node_getshrpath(sinfo->si_node->n_dnode,
sr->tid_tree, path, SMB_MAXPATHLEN);
if (rc != 0) {
status = smb_errno2status(rc);
return (status);
}
(void) strlcat(path, "\\", SMB_MAXPATHLEN);
(void) strlcat(path, fname, SMB_MAXPATHLEN);
}
/*
* The common rename code can slightly optimize a
* rename in the same directory when we set the
* dst_fqi->fq_dnode, dst_fqi->fq_last_comp
*/
dst_fqi->fq_dnode = sinfo->si_node->n_dnode;
(void) strlcpy(dst_fqi->fq_last_comp, fname, MAXNAMELEN);
status = smb_setinfo_rename(sr, sinfo->si_node, path, flags);
return (status);
}
|