Print this page
12513 SMB 3.1.1 support for server
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/smbsrv/libsmb/common/smb_kmod.c
+++ new/usr/src/lib/smbsrv/libsmb/common/smb_kmod.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.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
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 23 * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
24 24 * Copyright 2017 Joyent, Inc.
25 + * Copyright 2020 RackTop Systems, Inc.
25 26 */
26 27
27 28 #include <sys/types.h>
28 29 #include <sys/stat.h>
29 30 #include <sys/ioccom.h>
30 31 #include <sys/param.h>
31 32 #include <stddef.h>
32 33 #include <stdio.h>
33 34 #include <string.h>
34 35 #include <strings.h>
35 36 #include <stdlib.h>
36 37 #include <unistd.h>
37 38 #include <fcntl.h>
38 39 #include <errno.h>
39 40
40 41 #include <smbsrv/smb_xdr.h>
41 42 #include <smbsrv/smbinfo.h>
42 43 #include <smbsrv/smb_ioctl.h>
43 44 #include <smbsrv/libsmb.h>
44 45
45 46 #define SMBDRV_DEVICE_PATH "/dev/smbsrv"
46 47
47 48 int smb_kmod_ioctl(int, smb_ioc_header_t *, uint32_t);
48 49
49 50
50 51 int smbdrv_fd = -1;
51 52
52 53 int
53 54 smb_kmod_bind(void)
54 55 {
55 56 if (smbdrv_fd != -1)
56 57 (void) close(smbdrv_fd);
57 58
58 59 if ((smbdrv_fd = open(SMBDRV_DEVICE_PATH, 0)) < 0) {
59 60 smbdrv_fd = -1;
60 61 return (errno);
61 62 }
62 63
63 64 return (0);
64 65 }
65 66
66 67 boolean_t
67 68 smb_kmod_isbound(void)
68 69 {
69 70 return ((smbdrv_fd == -1) ? B_FALSE : B_TRUE);
70 71 }
71 72
72 73 /* See also: smbsrv smb_server_store_cfg */
73 74 int
74 75 smb_kmod_setcfg(smb_kmod_cfg_t *cfg)
75 76 {
76 77 smb_ioc_cfg_t ioc;
77 78
78 79 ioc.maxworkers = cfg->skc_maxworkers;
79 80 ioc.maxconnections = cfg->skc_maxconnections;
80 81 ioc.keepalive = cfg->skc_keepalive;
81 82 ioc.restrict_anon = cfg->skc_restrict_anon;
82 83 ioc.signing_enable = cfg->skc_signing_enable;
83 84 ioc.signing_required = cfg->skc_signing_required;
84 85 ioc.oplock_enable = cfg->skc_oplock_enable;
85 86 ioc.sync_enable = cfg->skc_sync_enable;
86 87 ioc.secmode = cfg->skc_secmode;
87 88 ioc.netbios_enable = cfg->skc_netbios_enable;
88 89 ioc.ipv6_enable = cfg->skc_ipv6_enable;
↓ open down ↓ |
54 lines elided |
↑ open up ↑ |
89 90 ioc.print_enable = cfg->skc_print_enable;
90 91 ioc.traverse_mounts = cfg->skc_traverse_mounts;
91 92 ioc.max_protocol = cfg->skc_max_protocol;
92 93 ioc.min_protocol = cfg->skc_min_protocol;
93 94 ioc.exec_flags = cfg->skc_execflags;
94 95 ioc.negtok_len = cfg->skc_negtok_len;
95 96 ioc.version = cfg->skc_version;
96 97 ioc.initial_credits = cfg->skc_initial_credits;
97 98 ioc.maximum_credits = cfg->skc_maximum_credits;
98 99 ioc.encrypt = cfg->skc_encrypt;
100 + ioc.encrypt_cipher = cfg->skc_encrypt_cipher;
99 101
100 102 (void) memcpy(ioc.machine_uuid, cfg->skc_machine_uuid, sizeof (uuid_t));
101 103 (void) memcpy(ioc.negtok, cfg->skc_negtok, sizeof (ioc.negtok));
102 104 (void) memcpy(ioc.native_os, cfg->skc_native_os,
103 105 sizeof (ioc.native_os));
104 106 (void) memcpy(ioc.native_lm, cfg->skc_native_lm,
105 107 sizeof (ioc.native_lm));
106 108
107 109 (void) strlcpy(ioc.nbdomain, cfg->skc_nbdomain, sizeof (ioc.nbdomain));
108 110 (void) strlcpy(ioc.fqdn, cfg->skc_fqdn, sizeof (ioc.fqdn));
109 111 (void) strlcpy(ioc.hostname, cfg->skc_hostname, sizeof (ioc.hostname));
110 112 (void) strlcpy(ioc.system_comment, cfg->skc_system_comment,
111 113 sizeof (ioc.system_comment));
112 114
113 115 return (smb_kmod_ioctl(SMB_IOC_CONFIG, &ioc.hdr, sizeof (ioc)));
114 116 }
115 117
116 118 int
117 119 smb_kmod_setgmtoff(int32_t gmtoff)
118 120 {
119 121 smb_ioc_gmt_t ioc;
120 122
121 123 ioc.offset = gmtoff;
122 124 return (smb_kmod_ioctl(SMB_IOC_GMTOFF, &ioc.hdr,
123 125 sizeof (ioc)));
124 126 }
125 127
126 128 int
127 129 smb_kmod_start(int opipe, int lmshr, int udoor)
128 130 {
129 131 smb_ioc_start_t ioc;
130 132
131 133 ioc.opipe = opipe;
132 134 ioc.lmshrd = lmshr;
133 135 ioc.udoor = udoor;
134 136 return (smb_kmod_ioctl(SMB_IOC_START, &ioc.hdr, sizeof (ioc)));
135 137 }
136 138
137 139 void
138 140 smb_kmod_stop(void)
139 141 {
140 142 smb_ioc_header_t ioc;
141 143
142 144 (void) smb_kmod_ioctl(SMB_IOC_STOP, &ioc, sizeof (ioc));
143 145 }
144 146
145 147 int
146 148 smb_kmod_event_notify(uint32_t txid)
147 149 {
148 150 smb_ioc_event_t ioc;
149 151
150 152 ioc.txid = txid;
151 153 return (smb_kmod_ioctl(SMB_IOC_EVENT, &ioc.hdr, sizeof (ioc)));
152 154 }
153 155
154 156 int
155 157 smb_kmod_share(nvlist_t *shrlist)
156 158 {
157 159 smb_ioc_share_t *ioc;
158 160 uint32_t ioclen;
159 161 char *shrbuf = NULL;
160 162 size_t bufsz;
161 163 int rc = ENOMEM;
162 164
163 165 if ((rc = nvlist_pack(shrlist, &shrbuf, &bufsz, NV_ENCODE_XDR, 0)) != 0)
164 166 return (rc);
165 167
166 168 ioclen = sizeof (smb_ioc_share_t) + bufsz;
167 169
168 170 if ((ioc = malloc(ioclen)) != NULL) {
169 171 ioc->shrlen = bufsz;
170 172 bcopy(shrbuf, ioc->shr, bufsz);
171 173 rc = smb_kmod_ioctl(SMB_IOC_SHARE, &ioc->hdr, ioclen);
172 174 free(ioc);
173 175 }
174 176
175 177 free(shrbuf);
176 178 return (rc);
177 179 }
178 180
179 181 int
180 182 smb_kmod_unshare(nvlist_t *shrlist)
181 183 {
182 184 smb_ioc_share_t *ioc;
183 185 uint32_t ioclen;
184 186 char *shrbuf = NULL;
185 187 size_t bufsz;
186 188 int rc = ENOMEM;
187 189
188 190 if ((rc = nvlist_pack(shrlist, &shrbuf, &bufsz, NV_ENCODE_XDR, 0)) != 0)
189 191 return (rc);
190 192
191 193 ioclen = sizeof (smb_ioc_share_t) + bufsz;
192 194
193 195 if ((ioc = malloc(ioclen)) != NULL) {
194 196 ioc->shrlen = bufsz;
195 197 bcopy(shrbuf, ioc->shr, bufsz);
196 198 rc = smb_kmod_ioctl(SMB_IOC_UNSHARE, &ioc->hdr, ioclen);
197 199 free(ioc);
198 200 }
199 201
200 202 free(shrbuf);
201 203 return (rc);
202 204 }
203 205
204 206 int
205 207 smb_kmod_shareinfo(char *shrname, boolean_t *shortnames)
206 208 {
207 209 smb_ioc_shareinfo_t ioc;
208 210 int rc;
209 211
210 212 bzero(&ioc, sizeof (ioc));
211 213 (void) strlcpy(ioc.shrname, shrname, MAXNAMELEN);
212 214
213 215 rc = smb_kmod_ioctl(SMB_IOC_SHAREINFO, &ioc.hdr, sizeof (ioc));
214 216 if (rc == 0)
215 217 *shortnames = ioc.shortnames;
216 218 else
217 219 *shortnames = B_TRUE;
218 220
219 221 return (rc);
220 222 }
221 223
222 224 int
223 225 smb_kmod_get_open_num(smb_opennum_t *opennum)
224 226 {
225 227 smb_ioc_opennum_t ioc;
226 228 int rc;
227 229
228 230 bzero(&ioc, sizeof (ioc));
229 231 ioc.qualtype = opennum->qualtype;
230 232 (void) strlcpy(ioc.qualifier, opennum->qualifier, MAXNAMELEN);
231 233
232 234 rc = smb_kmod_ioctl(SMB_IOC_NUMOPEN, &ioc.hdr, sizeof (ioc));
233 235 if (rc == 0) {
234 236 opennum->open_users = ioc.open_users;
235 237 opennum->open_trees = ioc.open_trees;
236 238 opennum->open_files = ioc.open_files;
237 239 }
238 240
239 241 return (rc);
240 242 }
241 243
242 244 int
243 245 smb_kmod_get_spool_doc(uint32_t *spool_num, char *username,
244 246 char *path, smb_inaddr_t *ipaddr)
245 247 {
246 248 smb_ioc_spooldoc_t ioc;
247 249 int rc;
248 250
249 251 bzero(&ioc, sizeof (ioc));
250 252 rc = smb_kmod_ioctl(SMB_IOC_SPOOLDOC, &ioc.hdr, sizeof (ioc));
251 253 if (rc == 0) {
252 254 *spool_num = ioc.spool_num;
253 255 (void) strlcpy(username, ioc.username, MAXNAMELEN);
254 256 (void) strlcpy(path, ioc.path, MAXPATHLEN);
255 257 *ipaddr = ioc.ipaddr;
256 258 }
257 259 return (rc);
258 260 }
259 261
260 262 /*
261 263 * Initialization for an smb_kmod_enum request. If this call succeeds,
262 264 * smb_kmod_enum_fini() must be called later to deallocate resources.
263 265 */
264 266 smb_netsvc_t *
265 267 smb_kmod_enum_init(smb_svcenum_t *request)
266 268 {
267 269 smb_netsvc_t *ns;
268 270 smb_svcenum_t *svcenum;
269 271 smb_ioc_svcenum_t *ioc;
270 272 uint32_t ioclen;
271 273
272 274 if ((ns = calloc(1, sizeof (smb_netsvc_t))) == NULL)
273 275 return (NULL);
274 276
275 277 ioclen = sizeof (smb_ioc_svcenum_t) + SMB_IOC_DATA_SIZE;
276 278 if ((ioc = malloc(ioclen)) == NULL) {
277 279 free(ns);
278 280 return (NULL);
279 281 }
280 282
281 283 bzero(ioc, ioclen);
282 284 svcenum = &ioc->svcenum;
283 285 svcenum->se_type = request->se_type;
284 286 svcenum->se_level = request->se_level;
285 287 svcenum->se_bavail = SMB_IOC_DATA_SIZE;
286 288 svcenum->se_nlimit = request->se_nlimit;
287 289 svcenum->se_nskip = request->se_nskip;
288 290 svcenum->se_buflen = SMB_IOC_DATA_SIZE;
289 291
290 292 list_create(&ns->ns_list, sizeof (smb_netsvcitem_t),
291 293 offsetof(smb_netsvcitem_t, nsi_lnd));
292 294
293 295 ns->ns_ioc = ioc;
294 296 ns->ns_ioclen = ioclen;
295 297 return (ns);
296 298 }
297 299
298 300 /*
299 301 * Cleanup resources allocated via smb_kmod_enum_init and smb_kmod_enum.
300 302 */
301 303 void
302 304 smb_kmod_enum_fini(smb_netsvc_t *ns)
303 305 {
304 306 list_t *lst;
305 307 smb_netsvcitem_t *item;
306 308 smb_netuserinfo_t *user;
307 309 smb_netconnectinfo_t *tree;
308 310 smb_netfileinfo_t *ofile;
309 311 uint32_t se_type;
310 312
311 313 if (ns == NULL)
312 314 return;
313 315
314 316 lst = &ns->ns_list;
315 317 se_type = ns->ns_ioc->svcenum.se_type;
316 318
317 319 while ((item = list_head(lst)) != NULL) {
318 320 list_remove(lst, item);
319 321
320 322 switch (se_type) {
321 323 case SMB_SVCENUM_TYPE_USER:
322 324 user = &item->nsi_un.nsi_user;
323 325 free(user->ui_domain);
324 326 free(user->ui_account);
325 327 free(user->ui_workstation);
326 328 break;
327 329 case SMB_SVCENUM_TYPE_TREE:
328 330 tree = &item->nsi_un.nsi_tree;
329 331 free(tree->ci_username);
330 332 free(tree->ci_share);
331 333 break;
332 334 case SMB_SVCENUM_TYPE_FILE:
333 335 ofile = &item->nsi_un.nsi_ofile;
334 336 free(ofile->fi_path);
335 337 free(ofile->fi_username);
336 338 break;
337 339 default:
338 340 break;
339 341 }
340 342 }
341 343
342 344 list_destroy(&ns->ns_list);
343 345 free(ns->ns_items);
344 346 free(ns->ns_ioc);
345 347 free(ns);
346 348 }
347 349
348 350 /*
349 351 * Enumerate users, connections or files.
350 352 */
351 353 int
352 354 smb_kmod_enum(smb_netsvc_t *ns)
353 355 {
354 356 smb_ioc_svcenum_t *ioc;
355 357 uint32_t ioclen;
356 358 smb_svcenum_t *svcenum;
357 359 smb_netsvcitem_t *items;
358 360 smb_netuserinfo_t *user;
359 361 smb_netconnectinfo_t *tree;
360 362 smb_netfileinfo_t *ofile;
361 363 uint8_t *data;
362 364 uint32_t len;
363 365 uint32_t se_type;
364 366 uint_t nbytes;
365 367 int i;
366 368 int rc;
367 369
368 370 ioc = ns->ns_ioc;
369 371 ioclen = ns->ns_ioclen;
370 372 rc = smb_kmod_ioctl(SMB_IOC_SVCENUM, &ioc->hdr, ioclen);
371 373 if (rc != 0)
372 374 return (rc);
373 375
374 376 svcenum = &ioc->svcenum;
375 377 items = calloc(svcenum->se_nitems, sizeof (smb_netsvcitem_t));
376 378 if (items == NULL)
377 379 return (ENOMEM);
378 380
379 381 ns->ns_items = items;
380 382 se_type = ns->ns_ioc->svcenum.se_type;
381 383 data = svcenum->se_buf;
382 384 len = svcenum->se_bused;
383 385
384 386 for (i = 0; i < svcenum->se_nitems; ++i) {
385 387 switch (se_type) {
386 388 case SMB_SVCENUM_TYPE_USER:
387 389 user = &items->nsi_un.nsi_user;
388 390 rc = smb_netuserinfo_decode(user, data, len, &nbytes);
389 391 break;
390 392 case SMB_SVCENUM_TYPE_TREE:
391 393 tree = &items->nsi_un.nsi_tree;
392 394 rc = smb_netconnectinfo_decode(tree, data, len,
393 395 &nbytes);
394 396 break;
395 397 case SMB_SVCENUM_TYPE_FILE:
396 398 ofile = &items->nsi_un.nsi_ofile;
397 399 rc = smb_netfileinfo_decode(ofile, data, len, &nbytes);
398 400 break;
399 401 default:
400 402 rc = -1;
401 403 break;
402 404 }
403 405
404 406 if (rc != 0)
405 407 return (EINVAL);
406 408
407 409 list_insert_tail(&ns->ns_list, items);
408 410
409 411 ++items;
410 412 data += nbytes;
411 413 len -= nbytes;
412 414 }
413 415
414 416 return (0);
415 417 }
416 418
417 419 /*
418 420 * A NULL pointer is a wildcard indicator, which we pass on
419 421 * as an empty string (by virtue of the bzero).
420 422 */
421 423 int
422 424 smb_kmod_session_close(const char *client, const char *username)
423 425 {
424 426 smb_ioc_session_t ioc;
425 427 int rc;
426 428
427 429 bzero(&ioc, sizeof (ioc));
428 430
429 431 if (client != NULL)
430 432 (void) strlcpy(ioc.client, client, MAXNAMELEN);
431 433 if (username != NULL)
432 434 (void) strlcpy(ioc.username, username, MAXNAMELEN);
433 435
434 436 rc = smb_kmod_ioctl(SMB_IOC_SESSION_CLOSE, &ioc.hdr, sizeof (ioc));
435 437 return (rc);
436 438 }
437 439
438 440 int
439 441 smb_kmod_file_close(uint32_t uniqid)
440 442 {
441 443 smb_ioc_fileid_t ioc;
442 444 int rc;
443 445
444 446 bzero(&ioc, sizeof (ioc));
445 447 ioc.uniqid = uniqid;
446 448
447 449 rc = smb_kmod_ioctl(SMB_IOC_FILE_CLOSE, &ioc.hdr, sizeof (ioc));
448 450 return (rc);
449 451 }
450 452
451 453 void
452 454 smb_kmod_unbind(void)
453 455 {
454 456 if (smbdrv_fd != -1) {
455 457 (void) close(smbdrv_fd);
456 458 smbdrv_fd = -1;
457 459 }
458 460 }
459 461
460 462 /*
461 463 * Note: The user-space smbd-d provides it own version of this function
462 464 * which directly calls the "kernel" module code (in user space).
463 465 */
464 466 int
465 467 smb_kmod_ioctl(int cmd, smb_ioc_header_t *ioc, uint32_t len)
466 468 {
467 469 int rc = EINVAL;
468 470
469 471 ioc->version = SMB_IOC_VERSION;
470 472 ioc->cmd = cmd;
471 473 ioc->len = len;
472 474 ioc->crc = 0;
473 475 ioc->crc = smb_crc_gen((uint8_t *)ioc, sizeof (smb_ioc_header_t));
474 476
475 477 if (smbdrv_fd != -1) {
476 478 if (ioctl(smbdrv_fd, cmd, ioc) < 0)
477 479 rc = errno;
478 480 else
479 481 rc = 0;
480 482 }
481 483 return (rc);
482 484 }
↓ open down ↓ |
374 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX