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_nt_transact_create.c
+++ new/usr/src/uts/common/fs/smbsrv/smb_nt_transact_create.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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25
26 26 /*
27 27 * This command is used to create or open a file or directory, when EAs
28 28 * or an SD must be applied to the file. The functionality is similar
29 29 * to SmbNtCreateAndx with the option to supply extended attributes or
30 30 * a security descriptor.
31 31 *
32 32 * Note: we don't decode the extended attributes because we don't
33 33 * support them at this time.
34 34 */
35 35
36 36 #include <smbsrv/smb_kproto.h>
37 37 #include <smbsrv/smb_fsops.h>
38 38
39 39 extern int smb_nt_create_enable_extended_response;
40 40
41 41 /*
42 42 * smb_nt_transact_create
43 43 *
44 44 * This command is used to create or open a file or directory, when EAs
45 45 * or an SD must be applied to the file. The request parameter block
46 46 * encoding, data block encoding and output parameter block encoding are
47 47 * described in CIFS section 4.2.2.
48 48 *
49 49 * The format of the command is SmbNtTransact but it is basically the same
50 50 * as SmbNtCreateAndx with the option to supply extended attributes or a
51 51 * security descriptor. For information not defined in CIFS section 4.2.2
52 52 * see section 4.2.1 (NT_CREATE_ANDX).
53 53 */
54 54 smb_sdrc_t
55 55 smb_pre_nt_transact_create(smb_request_t *sr, smb_xa_t *xa)
56 56 {
57 57 struct open_param *op = &sr->arg.open;
58 58 uint8_t SecurityFlags;
59 59 uint32_t EaLength;
60 60 uint32_t ImpersonationLevel;
61 61 uint32_t NameLength;
62 62 uint32_t sd_len;
63 63 uint32_t status;
64 64 smb_sd_t sd;
65 65 int rc;
66 66
67 67 bzero(op, sizeof (sr->arg.open));
68 68
69 69 rc = smb_mbc_decodef(&xa->req_param_mb, "%lllqllllllllb",
70 70 sr,
71 71 &op->nt_flags,
72 72 &op->rootdirfid,
73 73 &op->desired_access,
74 74 &op->dsize,
75 75 &op->dattr,
76 76 &op->share_access,
77 77 &op->create_disposition,
78 78 &op->create_options,
79 79 &sd_len,
80 80 &EaLength,
81 81 &NameLength,
82 82 &ImpersonationLevel,
83 83 &SecurityFlags);
84 84
85 85 if (rc == 0) {
86 86 if (NameLength == 0) {
87 87 op->fqi.fq_path.pn_path = "\\";
88 88 } else if (NameLength >= SMB_MAXPATHLEN) {
89 89 smbsr_error(sr, NT_STATUS_OBJECT_NAME_INVALID,
90 90 ERRDOS, ERROR_INVALID_NAME);
91 91 rc = -1;
92 92 } else {
93 93 rc = smb_mbc_decodef(&xa->req_param_mb, "%#u",
94 94 sr, NameLength, &op->fqi.fq_path.pn_path);
95 95 }
96 96 }
97 97
98 98 op->op_oplock_level = SMB_OPLOCK_NONE;
99 99 if (op->nt_flags & NT_CREATE_FLAG_REQUEST_OPLOCK) {
100 100 if (op->nt_flags & NT_CREATE_FLAG_REQUEST_OPBATCH)
101 101 op->op_oplock_level = SMB_OPLOCK_BATCH;
102 102 else
103 103 op->op_oplock_level = SMB_OPLOCK_EXCLUSIVE;
104 104 }
105 105
106 106 if (sd_len) {
107 107 status = smb_decode_sd(&xa->req_data_mb, &sd);
↓ open down ↓ |
107 lines elided |
↑ open up ↑ |
108 108 if (status != NT_STATUS_SUCCESS) {
109 109 smbsr_error(sr, status, 0, 0);
110 110 return (SDRC_ERROR);
111 111 }
112 112 op->sd = kmem_alloc(sizeof (smb_sd_t), KM_SLEEP);
113 113 *op->sd = sd;
114 114 } else {
115 115 op->sd = NULL;
116 116 }
117 117
118 - DTRACE_SMB_2(op__NtTransactCreate__start, smb_request_t *, sr,
119 - struct open_param *, op);
118 + DTRACE_SMB_1(op__NtTransactCreate__start, smb_request_t *, sr); /* arg.open */
120 119
121 120 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
122 121 }
123 122
124 123 void
125 124 smb_post_nt_transact_create(smb_request_t *sr, smb_xa_t *xa)
126 125 {
127 126 smb_sd_t *sd = sr->arg.open.sd;
127 + _NOTE(ARGUNUSED(xa))
128 128
129 - DTRACE_SMB_2(op__NtTransactCreate__done, smb_request_t *, sr,
130 - smb_xa_t *, xa);
129 + DTRACE_SMB_1(op__NtTransactCreate__done, smb_request_t *, sr);
131 130
132 131 if (sd) {
133 132 smb_sd_term(sd);
134 133 kmem_free(sd, sizeof (smb_sd_t));
135 134 }
136 135
137 136 if (sr->arg.open.dir != NULL) {
138 137 smb_ofile_release(sr->arg.open.dir);
139 138 sr->arg.open.dir = NULL;
140 139 }
141 140 }
142 141
143 142 /*
144 143 * A lot like smb_com_nt_create_andx
145 144 */
146 145 smb_sdrc_t
147 146 smb_nt_transact_create(smb_request_t *sr, smb_xa_t *xa)
148 147 {
149 148 struct open_param *op = &sr->arg.open;
150 149 smb_attr_t *ap = &op->fqi.fq_fattr;
151 150 smb_ofile_t *of;
152 151 int rc;
153 152 uint8_t DirFlag;
154 153 uint32_t status;
155 154
156 155 if (op->create_options & ~SMB_NTCREATE_VALID_OPTIONS) {
157 156 smbsr_error(sr, NT_STATUS_INVALID_PARAMETER,
158 157 ERRDOS, ERROR_INVALID_PARAMETER);
159 158 return (SDRC_ERROR);
160 159 }
161 160
162 161 if (op->create_options & FILE_OPEN_BY_FILE_ID) {
163 162 smbsr_error(sr, NT_STATUS_NOT_SUPPORTED,
164 163 ERRDOS, ERROR_NOT_SUPPORTED);
165 164 return (SDRC_ERROR);
166 165 }
167 166
168 167 if ((op->create_options & FILE_DELETE_ON_CLOSE) &&
169 168 !(op->desired_access & DELETE)) {
170 169 smbsr_error(sr, NT_STATUS_INVALID_PARAMETER,
171 170 ERRDOS, ERRbadaccess);
172 171 return (SDRC_ERROR);
173 172 }
174 173
175 174 if (op->create_disposition > FILE_MAXIMUM_DISPOSITION) {
176 175 smbsr_error(sr, NT_STATUS_INVALID_PARAMETER,
177 176 ERRDOS, ERRbadaccess);
178 177 return (SDRC_ERROR);
179 178 }
180 179
181 180 if (op->dattr & FILE_FLAG_WRITE_THROUGH)
182 181 op->create_options |= FILE_WRITE_THROUGH;
183 182
184 183 if (op->dattr & FILE_FLAG_DELETE_ON_CLOSE)
185 184 op->create_options |= FILE_DELETE_ON_CLOSE;
186 185
187 186 if (op->dattr & FILE_FLAG_BACKUP_SEMANTICS)
188 187 op->create_options |= FILE_OPEN_FOR_BACKUP_INTENT;
189 188
190 189 if (op->create_options & FILE_OPEN_FOR_BACKUP_INTENT)
191 190 sr->user_cr = smb_user_getprivcred(sr->uid_user);
192 191
193 192 if (op->rootdirfid == 0) {
194 193 op->fqi.fq_dnode = sr->tid_tree->t_snode;
195 194 } else {
196 195 op->dir = smb_ofile_lookup_by_fid(sr, (uint16_t)op->rootdirfid);
197 196 if (op->dir == NULL) {
198 197 smbsr_error(sr, NT_STATUS_INVALID_HANDLE,
199 198 ERRDOS, ERRbadfid);
200 199 return (SDRC_ERROR);
201 200 }
202 201 op->fqi.fq_dnode = op->dir->f_node;
203 202 }
204 203
205 204 op->op_oplock_levelII = B_TRUE;
206 205
207 206 status = smb_common_open(sr);
208 207 if (status != NT_STATUS_SUCCESS) {
209 208 smbsr_status(sr, status, 0, 0);
210 209 return (SDRC_ERROR);
211 210 }
212 211
213 212 /*
214 213 * NB: after the above smb_common_open() success,
215 214 * we have a handle allocated (sr->fid_ofile).
216 215 * If we don't return success, we must close it.
217 216 */
218 217 of = sr->fid_ofile;
219 218
220 219 switch (sr->tid_tree->t_res_type & STYPE_MASK) {
221 220 case STYPE_DISKTREE:
222 221 case STYPE_PRINTQ:
223 222 if (op->create_options & FILE_DELETE_ON_CLOSE)
224 223 smb_ofile_set_delete_on_close(of);
225 224 DirFlag = smb_node_is_dir(of->f_node) ? 1 : 0;
226 225 break;
227 226
228 227 case STYPE_IPC:
229 228 DirFlag = 0;
230 229 break;
231 230
232 231 default:
233 232 smbsr_error(sr, NT_STATUS_INVALID_DEVICE_REQUEST,
234 233 ERRDOS, ERROR_INVALID_FUNCTION);
235 234 goto errout;
236 235 }
237 236
238 237 if ((op->nt_flags & NT_CREATE_FLAG_EXTENDED_RESPONSE) != 0 &&
239 238 smb_nt_create_enable_extended_response != 0) {
240 239 uint32_t MaxAccess = 0;
241 240 if (of->f_node != NULL) {
242 241 smb_fsop_eaccess(sr, of->f_cr, of->f_node, &MaxAccess);
243 242 }
244 243 MaxAccess |= of->f_granted_access;
245 244
246 245 rc = smb_mbc_encodef(
247 246 &xa->rep_param_mb, "bbwllTTTTlqqwwb16.qll",
248 247 op->op_oplock_level, /* (b) */
249 248 1, /* ResponseType (b) */
250 249 sr->smb_fid, /* (w) */
251 250 op->action_taken, /* (l) */
252 251 0, /* EaErrorOffset (l) */
253 252 &ap->sa_crtime, /* (T) */
254 253 &ap->sa_vattr.va_atime, /* (T) */
255 254 &ap->sa_vattr.va_mtime, /* (T) */
256 255 &ap->sa_vattr.va_ctime, /* (T) */
257 256 op->dattr & FILE_ATTRIBUTE_MASK, /* (l) */
258 257 ap->sa_allocsz, /* (q) */
259 258 ap->sa_vattr.va_size, /* (q) */
260 259 op->ftype, /* (w) */
261 260 op->devstate, /* (w) */
262 261 DirFlag, /* (b) */
263 262 /* volume guid (16.) */
264 263 op->fileid, /* (q) */
265 264 MaxAccess, /* (l) */
266 265 0); /* guest access (l) */
267 266 } else {
268 267 rc = smb_mbc_encodef(
269 268 &xa->rep_param_mb, "bbwllTTTTlqqwwb",
270 269 op->op_oplock_level, /* (b) */
271 270 0, /* ResponseType (b) */
272 271 sr->smb_fid, /* (w) */
273 272 op->action_taken, /* (l) */
274 273 0, /* EaErrorOffset (l) */
275 274 &ap->sa_crtime, /* (T) */
276 275 &ap->sa_vattr.va_atime, /* (T) */
277 276 &ap->sa_vattr.va_mtime, /* (T) */
278 277 &ap->sa_vattr.va_ctime, /* (T) */
279 278 op->dattr & FILE_ATTRIBUTE_MASK, /* (l) */
280 279 ap->sa_allocsz, /* (q) */
281 280 ap->sa_vattr.va_size, /* (q) */
282 281 op->ftype, /* (w) */
283 282 op->devstate, /* (w) */
284 283 DirFlag); /* (b) */
285 284 }
286 285
287 286 if (rc == 0)
288 287 return (SDRC_SUCCESS);
289 288
290 289 errout:
291 290 smb_ofile_close(of, 0);
292 291 return (SDRC_ERROR);
293 292 }
↓ open down ↓ |
153 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX