Print this page
Build provider 3rd arg from smb_request_t
hacking...
NEX-1643 dtrace provider for smbsrv
Also illumos 1841:
DTrace smb provider was mis-implemented, doesn't exist.
Add back handlers for read/write raw, so that
legacy dtrace consumers can find the probes.
Kill extra arg in smb_negotiate
Fix missing "done" probe with smb_notify
Add example consumer: smb-trace.d
fix soi_pid
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/smbsrv/smb_query_fileinfo.c
+++ new/usr/src/uts/common/fs/smbsrv/smb_query_fileinfo.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 /*
23 23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
25 25 */
26 26
27 27 #include <smbsrv/smb_kproto.h>
28 28 #include <smbsrv/smb_vops.h>
29 29 #include <smbsrv/smb_fsops.h>
30 30
31 31 /*
32 32 * Trans2 Query File/Path Information Levels:
33 33 *
34 34 * SMB_INFO_STANDARD
35 35 * SMB_INFO_QUERY_EA_SIZE
36 36 * SMB_INFO_QUERY_EAS_FROM_LIST
37 37 * SMB_INFO_QUERY_ALL_EAS - not valid for pipes
38 38 * SMB_INFO_IS_NAME_VALID - only valid when query is by path
39 39 *
40 40 * SMB_QUERY_FILE_BASIC_INFO
41 41 * SMB_QUERY_FILE_STANDARD_INFO
42 42 * SMB_QUERY_FILE_EA_INFO
43 43 * SMB_QUERY_FILE_NAME_INFO
44 44 * SMB_QUERY_FILE_ALL_INFO
45 45 * SMB_QUERY_FILE_ALT_NAME_INFO - not valid for pipes
46 46 * SMB_QUERY_FILE_STREAM_INFO - not valid for pipes
47 47 * SMB_QUERY_FILE_COMPRESSION_INFO - not valid for pipes
48 48 *
49 49 * Supported Passthrough levels:
50 50 * SMB_FILE_BASIC_INFORMATION
51 51 * SMB_FILE_STANDARD_INFORMATION
52 52 * SMB_FILE_INTERNAL_INFORMATION
53 53 * SMB_FILE_EA_INFORMATION
54 54 * SMB_FILE_ACCESS_INFORMATION - not yet supported when query by path
55 55 * SMB_FILE_NAME_INFORMATION
56 56 * SMB_FILE_ALL_INFORMATION
57 57 * SMB_FILE_ALT_NAME_INFORMATION - not valid for pipes
58 58 * SMB_FILE_STREAM_INFORMATION - not valid for pipes
59 59 * SMB_FILE_COMPRESSION_INFORMATION - not valid for pipes
60 60 * SMB_FILE_NETWORK_OPEN_INFORMATION - not valid for pipes
61 61 * SMB_FILE_ATTR_TAG_INFORMATION - not valid for pipes
62 62 *
63 63 * Internal levels representing non trans2 requests
64 64 * SMB_QUERY_INFORMATION
65 65 * SMB_QUERY_INFORMATION2
66 66 */
67 67
68 68 /*
69 69 * SMB_STREAM_ENCODE_FIXED_SIZE:
70 70 * 2 dwords + 2 quadwords => 4 + 4 + 8 + 8 => 24
71 71 */
72 72 #define SMB_STREAM_ENCODE_FIXED_SZ 24
73 73
74 74 /* See smb_queryinfo_t in smb_ktypes.h */
75 75 #define qi_mtime qi_attr.sa_vattr.va_mtime
76 76 #define qi_ctime qi_attr.sa_vattr.va_ctime
77 77 #define qi_atime qi_attr.sa_vattr.va_atime
78 78 #define qi_crtime qi_attr.sa_crtime
79 79
80 80 static int smb_query_by_fid(smb_request_t *, smb_xa_t *, uint16_t);
81 81 static int smb_query_by_path(smb_request_t *, smb_xa_t *, uint16_t);
82 82
83 83 static int smb_query_fileinfo(smb_request_t *, smb_node_t *,
84 84 uint16_t, smb_queryinfo_t *);
85 85 static int smb_query_pipeinfo(smb_request_t *, smb_opipe_t *,
86 86 uint16_t, smb_queryinfo_t *);
87 87 static boolean_t smb_query_pipe_valid_infolev(smb_request_t *, uint16_t);
88 88
89 89 static int smb_query_encode_response(smb_request_t *, smb_xa_t *,
90 90 uint16_t, smb_queryinfo_t *);
91 91 static boolean_t smb_stream_fits(smb_request_t *, mbuf_chain_t *,
92 92 char *, uint32_t);
93 93 static int smb_query_pathname(smb_request_t *, smb_node_t *, boolean_t,
94 94 smb_queryinfo_t *);
95 95
96 96 int smb_query_passthru;
97 97
98 98 /*
99 99 * smb_com_trans2_query_file_information
100 100 */
101 101 smb_sdrc_t
102 102 smb_com_trans2_query_file_information(struct smb_request *sr, struct smb_xa *xa)
103 103 {
104 104 uint16_t infolev;
105 105
106 106 if (smb_mbc_decodef(&xa->req_param_mb, "ww",
107 107 &sr->smb_fid, &infolev) != 0)
108 108 return (SDRC_ERROR);
109 109
110 110 if (smb_query_by_fid(sr, xa, infolev) != 0)
111 111 return (SDRC_ERROR);
112 112
113 113 return (SDRC_SUCCESS);
114 114 }
115 115
116 116 /*
117 117 * smb_com_trans2_query_path_information
118 118 */
119 119 smb_sdrc_t
120 120 smb_com_trans2_query_path_information(smb_request_t *sr, smb_xa_t *xa)
121 121 {
122 122 uint16_t infolev;
123 123 smb_fqi_t *fqi = &sr->arg.dirop.fqi;
124 124
125 125 if (STYPE_ISIPC(sr->tid_tree->t_res_type)) {
126 126 smbsr_error(sr, NT_STATUS_INVALID_DEVICE_REQUEST,
127 127 ERRDOS, ERROR_INVALID_FUNCTION);
128 128 return (SDRC_ERROR);
129 129 }
130 130
131 131 if (smb_mbc_decodef(&xa->req_param_mb, "%w4.u",
132 132 sr, &infolev, &fqi->fq_path.pn_path) != 0)
133 133 return (SDRC_ERROR);
134 134
135 135 if (smb_query_by_path(sr, xa, infolev) != 0)
136 136 return (SDRC_ERROR);
137 137
138 138 return (SDRC_SUCCESS);
139 139 }
140 140
141 141 /*
↓ open down ↓ |
141 lines elided |
↑ open up ↑ |
142 142 * smb_com_query_information (aka getattr)
143 143 */
144 144 smb_sdrc_t
145 145 smb_pre_query_information(smb_request_t *sr)
146 146 {
147 147 int rc;
148 148 smb_fqi_t *fqi = &sr->arg.dirop.fqi;
149 149
150 150 rc = smbsr_decode_data(sr, "%S", sr, &fqi->fq_path.pn_path);
151 151
152 - DTRACE_SMB_2(op__QueryInformation__start, smb_request_t *, sr,
153 - smb_fqi_t *, fqi);
152 + DTRACE_SMB_1(op__QueryInformation__start, smb_request_t *, sr); /* arg.dirop */
154 153
155 154 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
156 155 }
157 156
158 157 void
159 158 smb_post_query_information(smb_request_t *sr)
160 159 {
161 160 DTRACE_SMB_1(op__QueryInformation__done, smb_request_t *, sr);
162 161 }
163 162
164 163 smb_sdrc_t
165 164 smb_com_query_information(smb_request_t *sr)
166 165 {
167 166 uint16_t infolev = SMB_QUERY_INFORMATION;
168 167
169 168 if (STYPE_ISIPC(sr->tid_tree->t_res_type)) {
170 169 smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
171 170 ERRDOS, ERROR_ACCESS_DENIED);
172 171 return (SDRC_ERROR);
173 172 }
174 173
175 174 if (smb_query_by_path(sr, NULL, infolev) != 0)
176 175 return (SDRC_ERROR);
177 176
178 177 return (SDRC_SUCCESS);
179 178 }
180 179
181 180 /*
182 181 * smb_com_query_information2 (aka getattre)
183 182 */
184 183 smb_sdrc_t
185 184 smb_pre_query_information2(smb_request_t *sr)
186 185 {
187 186 int rc;
188 187 rc = smbsr_decode_vwv(sr, "w", &sr->smb_fid);
189 188
190 189 DTRACE_SMB_1(op__QueryInformation2__start, smb_request_t *, sr);
191 190
192 191 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
193 192 }
194 193
195 194 void
196 195 smb_post_query_information2(smb_request_t *sr)
197 196 {
198 197 DTRACE_SMB_1(op__QueryInformation2__done, smb_request_t *, sr);
199 198 }
200 199
201 200 smb_sdrc_t
202 201 smb_com_query_information2(smb_request_t *sr)
203 202 {
204 203 uint16_t infolev = SMB_QUERY_INFORMATION2;
205 204
206 205 if (smb_query_by_fid(sr, NULL, infolev) != 0)
207 206 return (SDRC_ERROR);
208 207
209 208 return (SDRC_SUCCESS);
210 209 }
211 210
212 211 /*
213 212 * smb_query_by_fid
214 213 *
215 214 * Common code for querying file information by open file (or pipe) id.
216 215 * Use the id to identify the node / pipe object and request the
217 216 * smb_queryinfo_t data for that object.
218 217 */
219 218 static int
220 219 smb_query_by_fid(smb_request_t *sr, smb_xa_t *xa, uint16_t infolev)
221 220 {
222 221 int rc;
223 222 smb_queryinfo_t *qinfo;
224 223 smb_node_t *node;
225 224 smb_opipe_t *opipe;
226 225
227 226 smbsr_lookup_file(sr);
228 227
229 228 if (sr->fid_ofile == NULL) {
230 229 smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
231 230 return (-1);
232 231 }
233 232
234 233 if (infolev == SMB_INFO_IS_NAME_VALID) {
235 234 smbsr_error(sr, 0, ERRDOS, ERROR_INVALID_LEVEL);
236 235 smbsr_release_file(sr);
237 236 return (-1);
238 237 }
239 238
240 239 if ((sr->fid_ofile->f_ftype == SMB_FTYPE_MESG_PIPE) &&
241 240 (!smb_query_pipe_valid_infolev(sr, infolev))) {
242 241 smbsr_release_file(sr);
243 242 return (-1);
244 243 }
245 244
246 245 sr->user_cr = smb_ofile_getcred(sr->fid_ofile);
247 246 qinfo = kmem_alloc(sizeof (smb_queryinfo_t), KM_SLEEP);
248 247
249 248 switch (sr->fid_ofile->f_ftype) {
250 249 case SMB_FTYPE_DISK:
251 250 node = sr->fid_ofile->f_node;
252 251 rc = smb_query_fileinfo(sr, node, infolev, qinfo);
253 252 break;
254 253 case SMB_FTYPE_MESG_PIPE:
255 254 opipe = sr->fid_ofile->f_pipe;
256 255 rc = smb_query_pipeinfo(sr, opipe, infolev, qinfo);
257 256 break;
258 257 default:
259 258 smbsr_error(sr, 0, ERRDOS, ERRbadfile);
260 259 rc = -1;
261 260 break;
262 261 }
263 262
264 263 if (rc == 0)
265 264 rc = smb_query_encode_response(sr, xa, infolev, qinfo);
266 265
267 266 kmem_free(qinfo, sizeof (smb_queryinfo_t));
268 267 smbsr_release_file(sr);
269 268 return (rc);
270 269 }
271 270
272 271 /*
273 272 * smb_query_by_path
274 273 *
275 274 * Common code for querying file information by file name.
276 275 * Use the file name to identify the node object and request the
277 276 * smb_queryinfo_t data for that node.
278 277 *
279 278 * Path should be set in sr->arg.dirop.fqi.fq_path prior to
280 279 * calling smb_query_by_path.
281 280 *
282 281 * Querying attributes on a named pipe by name is an error and
283 282 * is handled in the calling functions so that they can return
284 283 * the appropriate error status code (which differs by caller).
285 284 */
286 285 static int
287 286 smb_query_by_path(smb_request_t *sr, smb_xa_t *xa, uint16_t infolev)
288 287 {
289 288 smb_queryinfo_t *qinfo;
290 289 smb_node_t *node, *dnode;
291 290 smb_pathname_t *pn;
292 291 int rc;
293 292
294 293 /*
295 294 * The function smb_query_fileinfo is used here and in
296 295 * smb_query_by_fid. That common function needs this
297 296 * one to call it with a NULL fid_ofile, so check here.
298 297 * Note: smb_query_by_fid enforces the opposite.
299 298 *
300 299 * In theory we could ASSERT this, but whether we have
301 300 * fid_ofile set here depends on what sequence of SMB
302 301 * commands the client has sent in this message, so
303 302 * let's be cautious and handle it as an error.
304 303 */
305 304 if (sr->fid_ofile != NULL)
306 305 return (-1);
307 306
308 307
309 308 /* VALID, but not yet supported */
310 309 if (infolev == SMB_FILE_ACCESS_INFORMATION) {
311 310 smbsr_error(sr, 0, ERRDOS, ERROR_INVALID_LEVEL);
312 311 return (-1);
313 312 }
314 313
315 314 pn = &sr->arg.dirop.fqi.fq_path;
316 315 smb_pathname_init(sr, pn, pn->pn_path);
317 316 if (!smb_pathname_validate(sr, pn))
318 317 return (-1);
319 318
320 319 qinfo = kmem_alloc(sizeof (smb_queryinfo_t), KM_SLEEP);
321 320
322 321 rc = smb_pathname_reduce(sr, sr->user_cr, pn->pn_path,
323 322 sr->tid_tree->t_snode, sr->tid_tree->t_snode, &dnode,
324 323 qinfo->qi_name);
325 324
326 325 if (rc == 0) {
327 326 rc = smb_fsop_lookup_name(sr, sr->user_cr, SMB_FOLLOW_LINKS,
328 327 sr->tid_tree->t_snode, dnode, qinfo->qi_name, &node);
329 328 smb_node_release(dnode);
330 329 }
331 330
332 331 if (rc != 0) {
333 332 if (rc == ENOENT)
334 333 smbsr_error(sr, NT_STATUS_OBJECT_NAME_NOT_FOUND,
335 334 ERRDOS, ERROR_FILE_NOT_FOUND);
336 335 else
337 336 smbsr_errno(sr, rc);
338 337
339 338 kmem_free(qinfo, sizeof (smb_queryinfo_t));
340 339 return (-1);
341 340 }
342 341
343 342 if ((sr->smb_flg2 & SMB_FLAGS2_DFS) && smb_node_is_dfslink(node)) {
344 343 smbsr_error(sr, NT_STATUS_PATH_NOT_COVERED, ERRSRV, ERRbadpath);
345 344 kmem_free(qinfo, sizeof (smb_queryinfo_t));
346 345 smb_node_release(node);
347 346 return (-1);
348 347 }
349 348
350 349 rc = smb_query_fileinfo(sr, node, infolev, qinfo);
351 350 if (rc != 0) {
352 351 kmem_free(qinfo, sizeof (smb_queryinfo_t));
353 352 smb_node_release(node);
354 353 return (rc);
355 354 }
356 355
357 356 /* If delete_on_close - NT_STATUS_DELETE_PENDING */
358 357 if (qinfo->qi_delete_on_close) {
359 358 smbsr_error(sr, NT_STATUS_DELETE_PENDING,
360 359 ERRDOS, ERROR_ACCESS_DENIED);
361 360 kmem_free(qinfo, sizeof (smb_queryinfo_t));
362 361 smb_node_release(node);
363 362 return (-1);
364 363 }
365 364
366 365 rc = smb_query_encode_response(sr, xa, infolev, qinfo);
367 366 kmem_free(qinfo, sizeof (smb_queryinfo_t));
368 367 smb_node_release(node);
369 368 return (rc);
370 369 }
371 370
372 371 /*
373 372 * smb_size32
374 373 * Some responses only support 32 bit file sizes. If the file size
375 374 * exceeds UINT_MAX (32 bit) we return UINT_MAX in the response.
376 375 */
377 376 static uint32_t
378 377 smb_size32(u_offset_t size)
379 378 {
380 379 return ((size > UINT_MAX) ? UINT_MAX : (uint32_t)size);
381 380 }
382 381
383 382 /*
384 383 * smb_query_encode_response
385 384 *
386 385 * Encode the data from smb_queryinfo_t into client response
387 386 */
388 387 int
389 388 smb_query_encode_response(smb_request_t *sr, smb_xa_t *xa,
390 389 uint16_t infolev, smb_queryinfo_t *qinfo)
391 390 {
392 391 uint16_t dattr;
393 392 u_offset_t datasz, allocsz;
394 393 uint32_t status;
395 394
396 395 dattr = qinfo->qi_attr.sa_dosattr & FILE_ATTRIBUTE_MASK;
397 396 datasz = qinfo->qi_attr.sa_vattr.va_size;
398 397 allocsz = qinfo->qi_attr.sa_allocsz;
399 398
400 399 switch (infolev) {
401 400 case SMB_QUERY_INFORMATION:
402 401 (void) smbsr_encode_result(sr, 10, 0, "bwll10.w",
403 402 10,
404 403 dattr,
405 404 smb_time_gmt_to_local(sr, qinfo->qi_mtime.tv_sec),
406 405 smb_size32(datasz),
407 406 0);
408 407 break;
409 408
410 409 case SMB_QUERY_INFORMATION2:
411 410 (void) smbsr_encode_result(sr, 11, 0, "byyyllww",
412 411 11,
413 412 smb_time_gmt_to_local(sr, qinfo->qi_crtime.tv_sec),
414 413 smb_time_gmt_to_local(sr, qinfo->qi_atime.tv_sec),
415 414 smb_time_gmt_to_local(sr, qinfo->qi_mtime.tv_sec),
416 415 smb_size32(datasz), smb_size32(allocsz), dattr, 0);
417 416 break;
418 417
419 418 case SMB_FILE_ACCESS_INFORMATION:
420 419 ASSERT(sr->fid_ofile);
421 420 (void) smb_mbc_encodef(&xa->rep_data_mb, "l",
422 421 sr->fid_ofile->f_granted_access);
423 422 break;
424 423
425 424 case SMB_INFO_STANDARD:
426 425 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
427 426 (void) smb_mbc_encodef(&xa->rep_data_mb,
428 427 ((sr->session->native_os == NATIVE_OS_WIN95) ?
429 428 "YYYllw" : "yyyllw"),
430 429 smb_time_gmt_to_local(sr, qinfo->qi_crtime.tv_sec),
431 430 smb_time_gmt_to_local(sr, qinfo->qi_atime.tv_sec),
432 431 smb_time_gmt_to_local(sr, qinfo->qi_mtime.tv_sec),
433 432 smb_size32(datasz), smb_size32(allocsz), dattr);
434 433 break;
435 434
436 435 case SMB_INFO_QUERY_EA_SIZE:
437 436 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
438 437 (void) smb_mbc_encodef(&xa->rep_data_mb,
439 438 ((sr->session->native_os == NATIVE_OS_WIN95) ?
440 439 "YYYllwl" : "yyyllwl"),
441 440 smb_time_gmt_to_local(sr, qinfo->qi_crtime.tv_sec),
442 441 smb_time_gmt_to_local(sr, qinfo->qi_atime.tv_sec),
443 442 smb_time_gmt_to_local(sr, qinfo->qi_mtime.tv_sec),
444 443 smb_size32(datasz), smb_size32(allocsz), dattr, 0);
445 444 break;
446 445
447 446 case SMB_INFO_QUERY_ALL_EAS:
448 447 case SMB_INFO_QUERY_EAS_FROM_LIST:
449 448 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
450 449 (void) smb_mbc_encodef(&xa->rep_data_mb, "l", 0);
451 450 break;
452 451
453 452 case SMB_INFO_IS_NAME_VALID:
454 453 break;
455 454
456 455 case SMB_QUERY_FILE_BASIC_INFO:
457 456 case SMB_FILE_BASIC_INFORMATION:
458 457 /*
459 458 * NT includes 6 bytes (spec says 4) at the end of this
460 459 * response, which are required by NetBench 5.01.
461 460 */
462 461 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
463 462 (void) smb_mbc_encodef(&xa->rep_data_mb, "TTTTw6.",
464 463 &qinfo->qi_crtime,
465 464 &qinfo->qi_atime,
466 465 &qinfo->qi_mtime,
467 466 &qinfo->qi_ctime,
468 467 dattr);
469 468 break;
470 469
471 470 case SMB_QUERY_FILE_STANDARD_INFO:
472 471 case SMB_FILE_STANDARD_INFORMATION:
473 472 /* 2-byte pad at end */
474 473 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
475 474 (void) smb_mbc_encodef(&xa->rep_data_mb, "qqlbb2.",
476 475 (uint64_t)allocsz,
477 476 (uint64_t)datasz,
478 477 qinfo->qi_attr.sa_vattr.va_nlink,
479 478 qinfo->qi_delete_on_close,
480 479 qinfo->qi_isdir);
481 480 break;
482 481
483 482 case SMB_QUERY_FILE_EA_INFO:
484 483 case SMB_FILE_EA_INFORMATION:
485 484 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
486 485 (void) smb_mbc_encodef(&xa->rep_data_mb, "l", 0);
487 486 break;
488 487
489 488 case SMB_QUERY_FILE_NAME_INFO:
490 489 case SMB_FILE_NAME_INFORMATION:
491 490 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
492 491 (void) smb_mbc_encodef(&xa->rep_data_mb, "%lu", sr,
493 492 qinfo->qi_namelen, qinfo->qi_name);
494 493 break;
495 494
496 495 case SMB_QUERY_FILE_ALL_INFO:
497 496 case SMB_FILE_ALL_INFORMATION:
498 497 /*
499 498 * There is a 6-byte pad between Attributes and AllocationSize,
500 499 * and a 2-byte pad after the Directory field.
501 500 */
502 501 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
503 502 (void) smb_mbc_encodef(&xa->rep_data_mb, "TTTTw6.qqlbb2.l",
504 503 &qinfo->qi_crtime,
505 504 &qinfo->qi_atime,
506 505 &qinfo->qi_mtime,
507 506 &qinfo->qi_ctime,
508 507 dattr,
509 508 (uint64_t)allocsz,
510 509 (uint64_t)datasz,
511 510 qinfo->qi_attr.sa_vattr.va_nlink,
512 511 qinfo->qi_delete_on_close,
513 512 qinfo->qi_isdir,
514 513 0);
515 514
516 515 (void) smb_mbc_encodef(&xa->rep_data_mb, "%lu",
517 516 sr, qinfo->qi_namelen, qinfo->qi_name);
518 517 break;
519 518
520 519 case SMB_QUERY_FILE_ALT_NAME_INFO:
521 520 case SMB_FILE_ALT_NAME_INFORMATION:
522 521 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
523 522 (void) smb_mbc_encodef(&xa->rep_data_mb, "%lU", sr,
524 523 smb_wcequiv_strlen(qinfo->qi_shortname),
525 524 qinfo->qi_shortname);
526 525 break;
527 526
528 527 case SMB_QUERY_FILE_STREAM_INFO:
529 528 case SMB_FILE_STREAM_INFORMATION:
530 529 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
531 530 status = smb_query_stream_info(sr, &xa->rep_data_mb, qinfo);
532 531 if (status)
533 532 smbsr_status(sr, status, 0, 0);
534 533 break;
535 534
536 535 case SMB_QUERY_FILE_COMPRESSION_INFO:
537 536 case SMB_FILE_COMPRESSION_INFORMATION:
538 537 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
539 538 (void) smb_mbc_encodef(&xa->rep_data_mb, "qwbbb3.",
540 539 datasz, 0, 0, 0, 0);
541 540 break;
542 541
543 542 case SMB_FILE_INTERNAL_INFORMATION:
544 543 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
545 544 (void) smb_mbc_encodef(&xa->rep_data_mb, "q",
546 545 qinfo->qi_attr.sa_vattr.va_nodeid);
547 546 break;
548 547
549 548 case SMB_FILE_NETWORK_OPEN_INFORMATION:
550 549 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
551 550 (void) smb_mbc_encodef(&xa->rep_data_mb, "TTTTqql4.",
552 551 &qinfo->qi_crtime,
553 552 &qinfo->qi_atime,
554 553 &qinfo->qi_mtime,
555 554 &qinfo->qi_ctime,
556 555 (uint64_t)allocsz,
557 556 (uint64_t)datasz,
558 557 (uint32_t)dattr);
559 558 break;
560 559
561 560 case SMB_FILE_ATTR_TAG_INFORMATION:
562 561 /*
563 562 * If dattr includes FILE_ATTRIBUTE_REPARSE_POINT, the
564 563 * second dword should be the reparse tag. Otherwise
565 564 * the tag value should be set to zero.
566 565 * We don't support reparse points, so we set the tag
567 566 * to zero.
568 567 */
569 568 (void) smb_mbc_encodef(&xa->rep_param_mb, "w", 0);
570 569 (void) smb_mbc_encodef(&xa->rep_data_mb, "ll",
571 570 (uint32_t)dattr, 0);
572 571 break;
573 572
574 573 default:
575 574 if ((infolev > 1000) && smb_query_passthru)
576 575 smbsr_error(sr, NT_STATUS_NOT_SUPPORTED,
577 576 ERRDOS, ERROR_NOT_SUPPORTED);
578 577 else
579 578 smbsr_error(sr, 0, ERRDOS, ERROR_INVALID_LEVEL);
580 579 return (-1);
581 580 }
582 581
583 582 return (0);
584 583 }
585 584
586 585 /*
587 586 * smb_encode_stream_info
588 587 *
589 588 * This function encodes the streams information.
590 589 * The following rules about how have been derived from observed NT
591 590 * behaviour.
592 591 *
593 592 * If the target is a file:
594 593 * 1. If there are no named streams, the response should still contain
595 594 * an entry for the unnamed stream.
596 595 * 2. If there are named streams, the response should contain an entry
597 596 * for the unnamed stream followed by the entries for the named
598 597 * streams.
599 598 *
600 599 * If the target is a directory:
601 600 * 1. If there are no streams, the response is complete. Directories
602 601 * do not report the unnamed stream.
603 602 * 2. If there are streams, the response should contain entries for
604 603 * those streams but there should not be an entry for the unnamed
605 604 * stream.
606 605 *
607 606 * Note that the stream name lengths exclude the null terminator but
608 607 * the field lengths (i.e. next offset calculations) need to include
609 608 * the null terminator and be padded to a multiple of 8 bytes. The
610 609 * last entry does not seem to need any padding.
611 610 *
612 611 * If an error is encountered when trying to read the stream entries
613 612 * (smb_odir_read_streaminfo) it is treated as if there are no [more]
614 613 * entries. The entries that have been read so far are returned and
615 614 * no error is reported.
616 615 *
617 616 * If the response buffer is not large enough to return all of the
618 617 * named stream entries, the entries that do fit are returned and
619 618 * a warning code is set (NT_STATUS_BUFFER_OVERFLOW). The next_offset
620 619 * value in the last returned entry must be 0.
621 620 */
622 621 uint32_t
623 622 smb_query_stream_info(smb_request_t *sr, mbuf_chain_t *mbc,
624 623 smb_queryinfo_t *qinfo)
625 624 {
626 625 char *stream_name;
627 626 uint32_t next_offset;
628 627 uint32_t stream_nlen;
629 628 uint32_t pad;
630 629 u_offset_t datasz, allocsz;
631 630 smb_streaminfo_t *sinfo, *sinfo_next;
632 631 int rc = 0;
633 632 boolean_t done = B_FALSE;
634 633 boolean_t eos = B_FALSE;
635 634 smb_odir_t *od = NULL;
636 635 uint32_t status = 0;
637 636
638 637 smb_node_t *fnode = qinfo->qi_node;
639 638 smb_attr_t *attr = &qinfo->qi_attr;
640 639
641 640 ASSERT(fnode);
642 641 if (SMB_IS_STREAM(fnode)) {
643 642 fnode = fnode->n_unode;
644 643 ASSERT(fnode);
645 644 }
646 645 ASSERT(fnode->n_magic == SMB_NODE_MAGIC);
647 646 ASSERT(fnode->n_state != SMB_NODE_STATE_DESTROYING);
648 647
649 648 sinfo = kmem_alloc(sizeof (smb_streaminfo_t), KM_SLEEP);
650 649 sinfo_next = kmem_alloc(sizeof (smb_streaminfo_t), KM_SLEEP);
651 650 datasz = attr->sa_vattr.va_size;
652 651 allocsz = attr->sa_allocsz;
653 652
654 653 status = smb_odir_openat(sr, fnode, &od);
655 654 switch (status) {
656 655 case 0:
657 656 break;
658 657 case NT_STATUS_NO_SUCH_FILE:
659 658 case NT_STATUS_NOT_SUPPORTED:
660 659 /* No streams. */
661 660 done = B_TRUE;
662 661 break;
663 662 default:
664 663 return (status);
665 664 }
666 665
667 666 if (!done) {
668 667 rc = smb_odir_read_streaminfo(sr, od, sinfo, &eos);
669 668 if ((rc != 0) || (eos))
670 669 done = B_TRUE;
671 670 }
672 671
673 672 /* If not a directory, encode an entry for the unnamed stream. */
674 673 if (qinfo->qi_isdir == 0) {
675 674 stream_name = "::$DATA";
676 675 stream_nlen = smb_ascii_or_unicode_strlen(sr, stream_name);
677 676 next_offset = SMB_STREAM_ENCODE_FIXED_SZ + stream_nlen +
678 677 smb_ascii_or_unicode_null_len(sr);
679 678
680 679 /* Can unnamed stream fit in response buffer? */
681 680 if (MBC_ROOM_FOR(mbc, next_offset) == 0) {
682 681 done = B_TRUE;
683 682 status = NT_STATUS_BUFFER_OVERFLOW;
684 683 } else {
685 684 /* Can first named stream fit in rsp buffer? */
686 685 if (!done && !smb_stream_fits(sr, mbc, sinfo->si_name,
687 686 next_offset)) {
688 687 done = B_TRUE;
689 688 status = NT_STATUS_BUFFER_OVERFLOW;
690 689 }
691 690
692 691 if (done)
693 692 next_offset = 0;
694 693
695 694 (void) smb_mbc_encodef(mbc, "%llqqu", sr,
696 695 next_offset, stream_nlen, datasz, allocsz,
697 696 stream_name);
698 697 }
699 698 }
700 699
701 700 /*
702 701 * If there is no next entry, or there is not enough space in
703 702 * the response buffer for the next entry, the next_offset and
704 703 * padding are 0.
705 704 */
706 705 while (!done) {
707 706 stream_nlen = smb_ascii_or_unicode_strlen(sr, sinfo->si_name);
708 707 sinfo_next->si_name[0] = 0;
709 708
710 709 rc = smb_odir_read_streaminfo(sr, od, sinfo_next, &eos);
711 710 if ((rc != 0) || (eos)) {
712 711 done = B_TRUE;
713 712 } else {
714 713 next_offset = SMB_STREAM_ENCODE_FIXED_SZ +
715 714 stream_nlen +
716 715 smb_ascii_or_unicode_null_len(sr);
717 716 pad = smb_pad_align(next_offset, 8);
718 717 next_offset += pad;
719 718
720 719 /* Can next named stream fit in response buffer? */
721 720 if (!smb_stream_fits(sr, mbc, sinfo_next->si_name,
722 721 next_offset)) {
723 722 done = B_TRUE;
724 723 status = NT_STATUS_BUFFER_OVERFLOW;
725 724 }
726 725 }
727 726
728 727 if (done) {
729 728 next_offset = 0;
730 729 pad = 0;
731 730 }
732 731
733 732 (void) smb_mbc_encodef(mbc, "%llqqu#.",
734 733 sr, next_offset, stream_nlen,
735 734 sinfo->si_size, sinfo->si_alloc_size,
736 735 sinfo->si_name, pad);
737 736
738 737 (void) memcpy(sinfo, sinfo_next, sizeof (smb_streaminfo_t));
739 738 }
740 739
741 740 kmem_free(sinfo, sizeof (smb_streaminfo_t));
742 741 kmem_free(sinfo_next, sizeof (smb_streaminfo_t));
743 742 if (od) {
744 743 smb_odir_close(od);
745 744 smb_odir_release(od);
746 745 }
747 746
748 747 return (status);
749 748 }
750 749
751 750 /*
752 751 * smb_stream_fits
753 752 *
754 753 * Check if the named stream entry can fit in the response buffer.
755 754 *
756 755 * Required space =
757 756 * offset (size of current entry)
758 757 * + SMB_STREAM_ENCODE_FIXED_SIZE
759 758 * + length of encoded stream name
760 759 * + length of null terminator
761 760 * + alignment padding
762 761 */
763 762 static boolean_t
764 763 smb_stream_fits(smb_request_t *sr, mbuf_chain_t *mbc,
765 764 char *name, uint32_t offset)
766 765 {
767 766 uint32_t len, pad;
768 767
769 768 len = SMB_STREAM_ENCODE_FIXED_SZ +
770 769 smb_ascii_or_unicode_strlen(sr, name) +
771 770 smb_ascii_or_unicode_null_len(sr);
772 771 pad = smb_pad_align(len, 8);
773 772 len += pad;
774 773
775 774 return (MBC_ROOM_FOR(mbc, offset + len) != 0);
776 775 }
777 776
778 777 /*
779 778 * smb_query_fileinfo
780 779 *
781 780 * Populate smb_queryinfo_t structure for SMB_FTYPE_DISK
782 781 * (This should become an smb_ofile / smb_node function.)
783 782 */
784 783 int
785 784 smb_query_fileinfo(smb_request_t *sr, smb_node_t *node, uint16_t infolev,
786 785 smb_queryinfo_t *qinfo)
787 786 {
788 787 int rc = 0;
789 788
790 789 /* If shortname required but not supported -> OBJECT_NAME_NOT_FOUND */
791 790 if ((infolev == SMB_QUERY_FILE_ALT_NAME_INFO) ||
792 791 (infolev == SMB_FILE_ALT_NAME_INFORMATION)) {
793 792 if (!smb_tree_has_feature(sr->tid_tree, SMB_TREE_SHORTNAMES)) {
794 793 smbsr_error(sr, NT_STATUS_OBJECT_NAME_NOT_FOUND,
795 794 ERRDOS, ERROR_FILE_NOT_FOUND);
796 795 return (-1);
797 796 }
798 797 }
799 798
800 799 (void) bzero(qinfo, sizeof (smb_queryinfo_t));
801 800
802 801 /* See: smb_query_encode_response */
803 802 qinfo->qi_attr.sa_mask = SMB_AT_ALL;
804 803 rc = smb_node_getattr(sr, node, sr->user_cr, sr->fid_ofile,
805 804 &qinfo->qi_attr);
806 805 if (rc != 0) {
807 806 smbsr_error(sr, NT_STATUS_INTERNAL_ERROR,
808 807 ERRDOS, ERROR_INTERNAL_ERROR);
809 808 return (-1);
810 809 }
811 810
812 811 qinfo->qi_node = node;
813 812 qinfo->qi_delete_on_close =
814 813 (node->flags & NODE_FLAGS_DELETE_ON_CLOSE) != 0;
815 814 qinfo->qi_isdir = smb_node_is_dir(node);
816 815
817 816 /*
818 817 * The number of links reported should be the number of
819 818 * non-deleted links. Thus if delete_on_close is set,
820 819 * decrement the link count.
821 820 */
822 821 if (qinfo->qi_delete_on_close &&
823 822 qinfo->qi_attr.sa_vattr.va_nlink > 0) {
824 823 --(qinfo->qi_attr.sa_vattr.va_nlink);
825 824 }
826 825
827 826 /*
828 827 * populate name, namelen and shortname ONLY for the information
829 828 * levels that require these fields
830 829 */
831 830 switch (infolev) {
832 831 case SMB_QUERY_FILE_ALL_INFO:
833 832 case SMB_FILE_ALL_INFORMATION:
834 833 rc = smb_query_pathname(sr, node, B_TRUE, qinfo);
835 834 break;
836 835 case SMB_QUERY_FILE_NAME_INFO:
837 836 case SMB_FILE_NAME_INFORMATION:
838 837 rc = smb_query_pathname(sr, node, B_FALSE, qinfo);
839 838 break;
840 839 case SMB_QUERY_FILE_ALT_NAME_INFO:
841 840 case SMB_FILE_ALT_NAME_INFORMATION:
842 841 smb_query_shortname(node, qinfo);
843 842 break;
844 843 default:
845 844 break;
846 845 }
847 846
848 847 if (rc != 0) {
849 848 smbsr_errno(sr, rc);
850 849 return (-1);
851 850 }
852 851 return (0);
853 852 }
854 853
855 854 /*
856 855 * smb_query_pathname
857 856 *
858 857 * Determine the absolute pathname of 'node' within the share.
859 858 * For some levels (e.g. ALL_INFO) the pathname should include the
860 859 * sharename for others (e.g. NAME_INFO) the pathname should be
861 860 * relative to the share.
862 861 * For example if the node represents file "test1.txt" in directory
863 862 * "dir1" on share "share1"
864 863 * - if include_share is TRUE the pathname would be: \share1\dir1\test1.txt
865 864 * - if include_share is FALSE the pathname would be: \dir1\test1.txt
866 865 *
867 866 * For some reason NT will not show the security tab in the root
868 867 * directory of a mapped drive unless the filename length is greater
869 868 * than one. So if the length is 1 we set it to 2 to persuade NT to
870 869 * show the tab. It should be safe because of the null terminator.
871 870 */
872 871 static int
873 872 smb_query_pathname(smb_request_t *sr, smb_node_t *node, boolean_t include_share,
874 873 smb_queryinfo_t *qinfo)
875 874 {
876 875 smb_tree_t *tree = sr->tid_tree;
877 876 char *buf = qinfo->qi_name;
878 877 size_t buflen = MAXPATHLEN;
879 878 size_t len;
880 879 int rc;
881 880
882 881 if (include_share) {
883 882 len = snprintf(buf, buflen, "\\%s", tree->t_sharename);
884 883 if (len == (buflen - 1))
885 884 return (ENAMETOOLONG);
886 885
887 886 buf += len;
888 887 buflen -= len;
889 888 }
890 889
891 890 if (node == tree->t_snode) {
892 891 if (!include_share)
893 892 (void) strlcpy(buf, "\\", buflen);
894 893 return (0);
895 894 }
896 895
897 896 rc = smb_node_getshrpath(node, tree, buf, buflen);
898 897 if (rc == 0) {
899 898 qinfo->qi_namelen =
900 899 smb_ascii_or_unicode_strlen(sr, qinfo->qi_name);
901 900 if (qinfo->qi_namelen == 1)
902 901 qinfo->qi_namelen = 2;
903 902 }
904 903 return (rc);
905 904 }
906 905
907 906 /*
908 907 * smb_query_shortname
909 908 *
910 909 * If the node is a named stream, use its associated
911 910 * unnamed stream name to determine the shortname.
912 911 * If a shortname is required (smb_needs_mangle()), generate it
913 912 * using smb_mangle(), otherwise, convert the original name to
914 913 * upper-case and return it as the alternative name.
915 914 */
916 915 void
917 916 smb_query_shortname(smb_node_t *node, smb_queryinfo_t *qinfo)
918 917 {
919 918 char *namep;
920 919
921 920 if (SMB_IS_STREAM(node))
922 921 namep = node->n_unode->od_name;
923 922 else
924 923 namep = node->od_name;
925 924
926 925 if (smb_needs_mangled(namep)) {
927 926 smb_mangle(namep, qinfo->qi_attr.sa_vattr.va_nodeid,
928 927 qinfo->qi_shortname, SMB_SHORTNAMELEN);
929 928 } else {
930 929 (void) strlcpy(qinfo->qi_shortname, namep, SMB_SHORTNAMELEN);
931 930 (void) smb_strupr(qinfo->qi_shortname);
932 931 }
933 932 }
934 933
935 934 /*
936 935 * smb_query_pipeinfo
937 936 *
938 937 * Populate smb_queryinfo_t structure for SMB_FTYPE_MESG_PIPE
939 938 * (This should become an smb_opipe function.)
940 939 */
941 940 static int
942 941 smb_query_pipeinfo(smb_request_t *sr, smb_opipe_t *opipe, uint16_t infolev,
943 942 smb_queryinfo_t *qinfo)
944 943 {
945 944 char *namep = opipe->p_name;
946 945
947 946 (void) bzero(qinfo, sizeof (smb_queryinfo_t));
948 947 qinfo->qi_node = NULL;
949 948 qinfo->qi_attr.sa_vattr.va_nlink = 1;
950 949 qinfo->qi_delete_on_close = 1;
951 950 qinfo->qi_isdir = 0;
952 951
953 952 if ((infolev == SMB_INFO_STANDARD) ||
954 953 (infolev == SMB_INFO_QUERY_EA_SIZE) ||
955 954 (infolev == SMB_QUERY_INFORMATION2)) {
956 955 qinfo->qi_attr.sa_dosattr = 0;
957 956 } else {
958 957 qinfo->qi_attr.sa_dosattr = FILE_ATTRIBUTE_NORMAL;
959 958 }
960 959
961 960 /* If the leading \ is missing from the pipe name, add it. */
962 961 if (*namep != '\\')
963 962 (void) snprintf(qinfo->qi_name, MAXNAMELEN, "\\%s", namep);
964 963 else
965 964 (void) strlcpy(qinfo->qi_name, namep, MAXNAMELEN);
966 965
967 966 qinfo->qi_namelen=
968 967 smb_ascii_or_unicode_strlen(sr, qinfo->qi_name);
969 968
970 969 return (0);
971 970 }
972 971
973 972 /*
974 973 * smb_query_pipe_valid_infolev
975 974 *
976 975 * If the infolev is not valid for a message pipe, the error
977 976 * information is set in sr and B_FALSE is returned.
978 977 * Otherwise, returns B_TRUE.
979 978 */
980 979 static boolean_t
981 980 smb_query_pipe_valid_infolev(smb_request_t *sr, uint16_t infolev)
982 981 {
983 982 switch (infolev) {
984 983 case SMB_INFO_QUERY_ALL_EAS:
985 984 smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
986 985 ERRDOS, ERROR_ACCESS_DENIED);
987 986 return (B_FALSE);
988 987
989 988 case SMB_QUERY_FILE_ALT_NAME_INFO:
990 989 case SMB_FILE_ALT_NAME_INFORMATION:
991 990 case SMB_QUERY_FILE_STREAM_INFO:
992 991 case SMB_FILE_STREAM_INFORMATION:
993 992 case SMB_QUERY_FILE_COMPRESSION_INFO:
994 993 case SMB_FILE_COMPRESSION_INFORMATION:
995 994 case SMB_FILE_NETWORK_OPEN_INFORMATION:
996 995 case SMB_FILE_ATTR_TAG_INFORMATION:
997 996 smbsr_error(sr, NT_STATUS_INVALID_PARAMETER,
998 997 ERRDOS, ERROR_INVALID_PARAMETER);
999 998 return (B_FALSE);
1000 999 }
1001 1000
1002 1001 return (B_TRUE);
1003 1002 }
↓ open down ↓ |
840 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX