Print this page
NEX-16502 libshare needs to support SMB in a zone
Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
NEX-9808 SMB3 persistent handles
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-5665 SMB2 oplock leases
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-9808 SMB3 persistent handles
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-5665 SMB2 oplock leases
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-9497 SMB should bypass ACL traverse checking
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-10019 SMB server min_protocol setting
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-5273 SMB 3 Encryption
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-4598 SMB2 credit shortage with Mac client
Reviewed by: Bayard Bell <bayard.bell@nexenta.com>
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Matt Barden <Matt.Barden@nexenta.com>
NEX-3863 Would like an SMB share property to enable/disable quotas
Reviewed by: Bayard Bell <bayard.bell@nexenta.com>
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-3629 CLONE NEX-3624 SMB server max_workers cannot be increased above 1024
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Alek Pinchuk <alek@nexenta.com>
NEX-3611 CLONE NEX-3550 Replace smb2_enable with max_protocol
Reviewed by: Yuri Pankov <Yuri.Pankov@nexenta.com>
4295 libshare sa_get_proto_status sometimes returns unallocated strings
Reviewed by: Marcel Telka <marcel@telka.sk>
Approved by: Garrett D'Amore <garrett@damore.org>
NEX-1050 enable_smb2 should be smb2_enable
NEX-1022 SMB2 should be enabled by default
SMB-50 User-mode SMB server
Includes work by these authors:
Thomas Keiser <thomas.keiser@nexenta.com>
Albert Lee <trisk@nexenta.com>
SMB-65 SMB server in non-global zones (data structure changes)
Many things move to the smb_server_t object, and
many functions gain an sv arg (which server).
re #13470 rb4432 Sync some SMB differences from illumos
re #7930 rb3848 failover error: cannot share pool/folder - smb add share failed
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libshare/smb/libshare_smb.c
+++ new/usr/src/lib/libshare/smb/libshare_smb.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
|
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
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 - * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
24 + * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
25 25 */
26 26
27 27 /*
28 28 * SMB specific functions
29 29 */
30 30 #include <stdio.h>
31 31 #include <string.h>
32 32 #include <ctype.h>
33 33 #include <stdlib.h>
34 34 #include <unistd.h>
35 35 #include <zone.h>
36 36 #include <errno.h>
37 37 #include <locale.h>
38 38 #include <fcntl.h>
39 39 #include <sys/types.h>
40 40 #include <sys/stat.h>
41 41 #include <syslog.h>
42 42 #include "libshare.h"
43 43 #include "libshare_impl.h"
44 44 #include <pwd.h>
45 45 #include <limits.h>
46 46 #include <libscf.h>
47 47 #include <libscf_priv.h>
48 48 #include <strings.h>
49 49 #include "libshare_smb.h"
50 50 #include <rpcsvc/daemon_utils.h>
51 51 #include <smbsrv/smb_share.h>
52 52 #include <smbsrv/smbinfo.h>
53 53 #include <smbsrv/libsmb.h>
54 54 #include <libdlpi.h>
55 55
56 56 #define SMB_CSC_BUFSZ 64
57 57
58 58 #define SMB_VALID_SUB_CHRS "UDhMLmIiSPu" /* substitution characters */
59 59
60 60 /* internal functions */
61 61 static int smb_share_init(void);
62 62 static void smb_share_fini(void);
63 63 static int smb_enable_share(sa_share_t);
64 64 static int smb_share_changed(sa_share_t);
65 65 static int smb_resource_changed(sa_resource_t);
66 66 static int smb_rename_resource(sa_handle_t, sa_resource_t, char *);
67 67 static int smb_disable_share(sa_share_t share, char *);
68 68 static int smb_validate_property(sa_handle_t, sa_property_t, sa_optionset_t);
69 69 static int smb_set_proto_prop(sa_property_t);
70 70 static sa_protocol_properties_t smb_get_proto_set(void);
71 71 static char *smb_get_status(void);
72 72 static int smb_parse_optstring(sa_group_t, char *);
73 73 static char *smb_format_options(sa_group_t, int);
74 74
75 75 static int smb_enable_service(void);
76 76
|
↓ open down ↓ |
42 lines elided |
↑ open up ↑ |
77 77 static int range_check_validator(int, char *);
78 78 static int range_check_validator_zero_ok(int, char *);
79 79 static int string_length_check_validator(int, char *);
80 80 static int print_enable_validator(int, char *);
81 81 static int true_false_validator(int, char *);
82 82 static int ipv4_validator(int, char *);
83 83 static int hostname_validator(int, char *);
84 84 static int path_validator(int, char *);
85 85 static int cmd_validator(int, char *);
86 86 static int disposition_validator(int, char *);
87 -static int max_protocol_validator(int, char *);
87 +static int protocol_validator(int, char *);
88 +static int require_validator(int, char *);
88 89
89 90 static int smb_enable_resource(sa_resource_t);
90 91 static int smb_disable_resource(sa_resource_t);
91 92 static uint64_t smb_share_features(void);
92 93 static int smb_list_transient(sa_handle_t);
93 94
94 95 static int smb_build_shareinfo(sa_share_t, sa_resource_t, smb_share_t *);
95 96 static void smb_csc_option(const char *, smb_share_t *);
96 97 static char *smb_csc_name(const smb_share_t *);
97 98 static sa_group_t smb_get_defaultgrp(sa_handle_t);
98 99 static int interface_validator(int, char *);
99 100 static int smb_update_optionset_props(sa_handle_t, sa_resource_t, nvlist_t *);
100 101
101 -static boolean_t smb_saprop_getbool(sa_optionset_t, char *);
102 +static boolean_t smb_saprop_getbool(sa_optionset_t, char *, boolean_t);
102 103 static boolean_t smb_saprop_getstr(sa_optionset_t, char *, char *, size_t);
103 104
104 105 static struct {
105 106 char *value;
106 107 uint32_t flag;
107 108 } cscopt[] = {
108 109 { "disabled", SMB_SHRF_CSC_DISABLED },
109 110 { "manual", SMB_SHRF_CSC_MANUAL },
110 111 { "auto", SMB_SHRF_CSC_AUTO },
111 112 { "vdo", SMB_SHRF_CSC_VDO }
112 113 };
113 114
114 115 /* size of basic format allocation */
115 116 #define OPT_CHUNK 1024
116 117
117 118 /* size of string for types - big enough to hold "dependency" */
118 119 #define SCFTYPE_LEN 32
119 120
120 121 /*
121 122 * Indexes of entries in smb_proto_options table.
122 123 * Changes to smb_proto_options table may require
123 124 * an update to these values.
124 125 */
125 126 #define PROTO_OPT_WINS1 6
126 127 #define PROTO_OPT_WINS_EXCLUDE 8
127 128
128 129 typedef struct smb_hostifs_walker {
129 130 const char *hiw_ifname;
130 131 boolean_t hiw_matchfound;
131 132 } smb_hostifs_walker_t;
132 133
133 134
134 135 /*
135 136 * ops vector that provides the protocol specific info and operations
136 137 * for share management.
137 138 */
138 139
139 140 struct sa_plugin_ops sa_plugin_ops = {
140 141 SA_PLUGIN_VERSION,
141 142 SMB_PROTOCOL_NAME,
142 143 smb_share_init,
143 144 smb_share_fini,
144 145 smb_enable_share,
145 146 smb_disable_share,
146 147 smb_validate_property,
147 148 NULL, /* valid_space */
148 149 NULL, /* security_prop */
149 150 smb_parse_optstring,
150 151 smb_format_options,
151 152 smb_set_proto_prop,
152 153 smb_get_proto_set,
153 154 smb_get_status,
154 155 NULL, /* space_alias */
155 156 NULL, /* update_legacy */
156 157 NULL, /* delete_legacy */
157 158 smb_share_changed,
158 159 smb_enable_resource,
159 160 smb_disable_resource,
160 161 smb_share_features,
161 162 smb_list_transient,
162 163 smb_resource_changed,
163 164 smb_rename_resource,
164 165 NULL, /* run_command */
165 166 NULL, /* command_help */
166 167 NULL /* delete_proto_section */
167 168 };
168 169
169 170 struct option_defs optdefs[] = {
170 171 { SHOPT_AD_CONTAINER, OPT_TYPE_STRING },
|
↓ open down ↓ |
59 lines elided |
↑ open up ↑ |
171 172 { SHOPT_ABE, OPT_TYPE_BOOLEAN },
172 173 { SHOPT_NAME, OPT_TYPE_NAME },
173 174 { SHOPT_RO, OPT_TYPE_ACCLIST },
174 175 { SHOPT_RW, OPT_TYPE_ACCLIST },
175 176 { SHOPT_NONE, OPT_TYPE_ACCLIST },
176 177 { SHOPT_CATIA, OPT_TYPE_BOOLEAN },
177 178 { SHOPT_CSC, OPT_TYPE_CSC },
178 179 { SHOPT_GUEST, OPT_TYPE_BOOLEAN },
179 180 { SHOPT_DFSROOT, OPT_TYPE_BOOLEAN },
180 181 { SHOPT_DESCRIPTION, OPT_TYPE_STRING },
182 + { SHOPT_CA, OPT_TYPE_BOOLEAN },
183 + { SHOPT_FSO, OPT_TYPE_BOOLEAN },
184 + { SHOPT_QUOTAS, OPT_TYPE_BOOLEAN },
185 + { SHOPT_ENCRYPT, OPT_TYPE_STRING },
181 186 { NULL, NULL }
182 187 };
183 188
184 189 /*
185 190 * findopt(name)
186 191 *
187 192 * Lookup option "name" in the option table and return the table
188 193 * index.
189 194 */
190 195 static int
191 196 findopt(char *name)
192 197 {
193 198 int i;
194 199 if (name != NULL) {
195 200 for (i = 0; optdefs[i].tag != NULL; i++) {
196 201 if (strcmp(optdefs[i].tag, name) == 0)
197 202 return (i);
198 203 }
199 204 }
200 205 return (-1);
201 206 }
202 207
203 208 /*
204 209 * is_a_number(number)
205 210 *
206 211 * is the string a number in one of the forms we want to use?
207 212 */
208 213 static boolean_t
209 214 is_a_number(char *number)
210 215 {
211 216 boolean_t isnum = B_TRUE;
212 217 boolean_t ishex = B_FALSE;
213 218
214 219 if (number == NULL || *number == '\0')
215 220 return (B_FALSE);
216 221
217 222 if (strncasecmp(number, "0x", 2) == 0) {
218 223 number += 2;
219 224 ishex = B_TRUE;
220 225 } else if (*number == '-') {
221 226 number++;
222 227 }
223 228
224 229 while (isnum && (*number != '\0')) {
225 230 isnum = (ishex) ? isxdigit(*number) : isdigit(*number);
226 231 number++;
227 232 }
228 233
229 234 return (isnum);
230 235 }
231 236
232 237 /*
233 238 * check ro vs rw values. Over time this may get beefed up.
234 239 * for now it just does simple checks.
235 240 */
236 241
237 242 static int
238 243 check_rorw(char *v1, char *v2)
239 244 {
240 245 int ret = SA_OK;
241 246 if (strcmp(v1, v2) == 0)
242 247 ret = SA_VALUE_CONFLICT;
243 248 return (ret);
244 249 }
245 250
246 251 /*
247 252 * validresource(name)
248 253 *
249 254 * Check that name only has valid characters in it. The current valid
250 255 * set are the printable characters but not including:
251 256 * " / \ [ ] : | < > + ; , ? * = \t
252 257 * Note that space is included and there is a maximum length.
253 258 */
254 259 static boolean_t
255 260 validresource(const char *name)
256 261 {
257 262 const char *cp;
258 263 size_t len;
259 264
260 265 if (name == NULL)
261 266 return (B_FALSE);
262 267
263 268 len = strlen(name);
264 269 if (len == 0 || len > SA_MAX_RESOURCE_NAME)
265 270 return (B_FALSE);
266 271
267 272 if (strpbrk(name, "\"/\\[]:|<>+;,?*=\t") != NULL) {
268 273 return (B_FALSE);
269 274 }
270 275
271 276 for (cp = name; *cp != '\0'; cp++)
272 277 if (iscntrl(*cp))
273 278 return (B_FALSE);
274 279
275 280 return (B_TRUE);
276 281 }
277 282
278 283 /*
279 284 * Check that the client-side caching (CSC) option value is valid.
280 285 */
281 286 static boolean_t
282 287 validcsc(const char *value)
283 288 {
284 289 int i;
285 290
286 291 for (i = 0; i < (sizeof (cscopt) / sizeof (cscopt[0])); ++i) {
287 292 if (strcasecmp(value, cscopt[i].value) == 0)
288 293 return (B_TRUE);
289 294 }
290 295
291 296 return (B_FALSE);
292 297 }
293 298
294 299 /*
295 300 * smb_isonline()
296 301 *
297 302 * Determine if the SMF service instance is in the online state or
298 303 * not. A number of operations depend on this state.
299 304 */
300 305 static boolean_t
301 306 smb_isonline(void)
302 307 {
303 308 char *str;
304 309 boolean_t ret = B_FALSE;
305 310
306 311 if ((str = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI)) != NULL) {
307 312 ret = (strcmp(str, SCF_STATE_STRING_ONLINE) == 0);
308 313 free(str);
309 314 }
310 315 return (ret);
311 316 }
312 317
313 318 /*
314 319 * smb_isdisabled()
315 320 *
316 321 * Determine if the SMF service instance is in the disabled state or
317 322 * not. A number of operations depend on this state.
318 323 */
319 324 static boolean_t
320 325 smb_isdisabled(void)
321 326 {
322 327 char *str;
323 328 boolean_t ret = B_FALSE;
324 329
325 330 if ((str = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI)) != NULL) {
326 331 ret = (strcmp(str, SCF_STATE_STRING_DISABLED) == 0);
327 332 free(str);
328 333 }
329 334 return (ret);
330 335 }
331 336
332 337 /*
333 338 * smb_isautoenable()
334 339 *
335 340 * Determine if the SMF service instance auto_enabled set or not. A
336 341 * number of operations depend on this state. The property not being
337 342 * set or being set to true means autoenable. Only being set to false
338 343 * is not autoenabled.
339 344 */
340 345 static boolean_t
341 346 smb_isautoenable(void)
342 347 {
343 348 boolean_t ret = B_TRUE;
344 349 scf_simple_prop_t *prop;
345 350 uint8_t *retstr;
346 351
347 352 prop = scf_simple_prop_get(NULL, SMBD_DEFAULT_INSTANCE_FMRI,
348 353 "application", "auto_enable");
349 354 if (prop != NULL) {
350 355 retstr = scf_simple_prop_next_boolean(prop);
351 356 ret = *retstr != 0;
352 357 scf_simple_prop_free(prop);
353 358 }
354 359 return (ret);
355 360 }
356 361
357 362 /*
358 363 * smb_ismaint()
359 364 *
360 365 * Determine if the SMF service instance is in the disabled state or
361 366 * not. A number of operations depend on this state.
362 367 */
363 368 static boolean_t
364 369 smb_ismaint(void)
365 370 {
366 371 char *str;
367 372 boolean_t ret = B_FALSE;
368 373
369 374 if ((str = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI)) != NULL) {
370 375 ret = (strcmp(str, SCF_STATE_STRING_MAINT) == 0);
371 376 free(str);
372 377 }
373 378 return (ret);
374 379 }
375 380
376 381 /*
377 382 * smb_enable_share tells the implementation that it is to enable the share.
378 383 * This entails converting the path and options into the appropriate ioctl
|
↓ open down ↓ |
188 lines elided |
↑ open up ↑ |
379 384 * calls. It is assumed that all error checking of paths, etc. were
380 385 * done earlier.
381 386 */
382 387 static int
383 388 smb_enable_share(sa_share_t share)
384 389 {
385 390 char *path;
386 391 smb_share_t si;
387 392 sa_resource_t resource;
388 393 boolean_t iszfs;
389 - boolean_t privileged;
390 394 int err = SA_OK;
391 - priv_set_t *priv_effective;
392 395 boolean_t online;
393 396
394 397 /*
395 398 * Don't support Trusted Extensions.
396 399 */
397 400 if (is_system_labeled()) {
398 401 (void) printf(dgettext(TEXT_DOMAIN,
399 402 "SMB: service not supported with Trusted Extensions\n"));
400 403 return (SA_NOT_SUPPORTED);
401 404 }
402 405
403 - priv_effective = priv_allocset();
404 - (void) getppriv(PRIV_EFFECTIVE, priv_effective);
405 - privileged = (priv_isfullset(priv_effective) == B_TRUE);
406 - priv_freeset(priv_effective);
407 -
408 406 /* get the path since it is important in several places */
409 407 path = sa_get_share_attr(share, "path");
410 408 if (path == NULL)
411 409 return (SA_NO_SUCH_PATH);
412 410
413 411 /*
414 412 * If administratively disabled, don't try to start anything.
415 413 */
416 414 online = smb_isonline();
417 415 if (!online && !smb_isautoenable() && smb_isdisabled())
418 416 goto done;
419 417
420 418 iszfs = sa_path_is_zfs(path);
421 419
422 - if (iszfs) {
423 -
424 - if (privileged == B_FALSE && !online) {
425 -
426 - if (!online) {
427 - (void) printf(dgettext(TEXT_DOMAIN,
428 - "SMB: Cannot share remove "
429 - "file system: %s\n"), path);
430 - (void) printf(dgettext(TEXT_DOMAIN,
431 - "SMB: Service needs to be enabled "
432 - "by a privileged user\n"));
433 - err = SA_NO_PERMISSION;
434 - errno = EPERM;
435 - }
436 - if (err) {
437 - sa_free_attr_string(path);
438 - return (err);
439 - }
440 -
441 - }
442 - }
443 -
444 - if (privileged == B_TRUE && !online) {
420 + if (!online) {
445 421 err = smb_enable_service();
446 422 if (err != SA_OK) {
447 423 (void) printf(dgettext(TEXT_DOMAIN,
448 424 "SMB: Unable to enable service\n"));
449 425 } else {
450 426 online = B_TRUE;
451 427 }
452 428 }
453 429
454 430 /*
455 431 * Don't bother trying to start shares if the service isn't
456 432 * running.
457 433 */
458 434 if (!online)
459 435 goto done;
460 436
461 437 /* Each share can have multiple resources */
462 438 for (resource = sa_get_share_resource(share, NULL);
463 439 resource != NULL;
464 440 resource = sa_get_next_resource(resource)) {
465 441 err = smb_build_shareinfo(share, resource, &si);
466 442 if (err != SA_OK) {
467 443 sa_free_attr_string(path);
468 444 return (err);
469 445 }
470 446
471 447 if (!iszfs) {
472 448 err = smb_share_create(&si);
473 449 } else {
474 450 share_t sh;
475 451
476 452 (void) sa_sharetab_fill_zfs(share, &sh, "smb");
477 453 err = sa_share_zfs(share, resource, (char *)path, &sh,
478 454 &si, ZFS_SHARE_SMB);
479 455 if (err != SA_OK) {
480 456 errno = err;
481 457 err = -1;
482 458 }
483 459 sa_emptyshare(&sh);
484 460 }
485 461 }
486 462 if (!iszfs)
487 463 (void) sa_update_sharetab(share, "smb");
488 464 done:
489 465 sa_free_attr_string(path);
490 466
491 467 return (err == NERR_DuplicateShare ? 0 : err);
492 468 }
493 469
494 470 /*
495 471 * This is the share for CIFS all shares have resource names.
496 472 * Enable tells the smb server to update its hash. If it fails
497 473 * because smb server is down, we just ignore as smb server loads
498 474 * the resources from sharemanager at startup.
499 475 */
500 476
501 477 static int
502 478 smb_enable_resource(sa_resource_t resource)
503 479 {
504 480 sa_share_t share;
505 481 smb_share_t si;
506 482 int ret = SA_OK;
507 483 int err;
508 484 boolean_t isonline;
509 485
510 486 share = sa_get_resource_parent(resource);
511 487 if (share == NULL)
512 488 return (SA_NO_SUCH_PATH);
513 489
514 490 /*
515 491 * If administratively disabled, don't try to start anything.
516 492 */
517 493 isonline = smb_isonline();
518 494 if (!isonline && !smb_isautoenable() && smb_isdisabled())
519 495 return (SA_OK);
520 496
521 497 if (!isonline) {
522 498 (void) smb_enable_service();
523 499
524 500 if (!smb_isonline())
525 501 return (SA_OK);
526 502 }
527 503
528 504 if ((ret = smb_build_shareinfo(share, resource, &si)) != SA_OK)
529 505 return (ret);
530 506
531 507 /*
532 508 * Attempt to add the share. Any error that occurs if it was
533 509 * online is an error but don't count NERR_DuplicateName if
534 510 * smb/server had to be brought online since bringing the
535 511 * service up will enable the share that was just added prior
536 512 * to the attempt to enable.
537 513 */
538 514 err = smb_share_create(&si);
539 515 if (err == NERR_Success || !(!isonline && err == NERR_DuplicateName))
540 516 (void) sa_update_sharetab(share, "smb");
541 517 else
542 518 return (SA_NOT_SHARED);
543 519
544 520 return (SA_OK);
545 521 }
546 522
547 523 /*
548 524 * Remove it from smb server hash.
549 525 */
550 526 static int
551 527 smb_disable_resource(sa_resource_t resource)
552 528 {
553 529 char *rname;
554 530 uint32_t res;
555 531 sa_share_t share;
556 532
557 533 rname = sa_get_resource_attr(resource, "name");
558 534 if (rname == NULL)
559 535 return (SA_NO_SUCH_RESOURCE);
560 536
561 537 if (smb_isonline()) {
562 538 res = smb_share_delete(rname);
563 539 if (res != NERR_Success &&
564 540 res != NERR_NetNameNotFound) {
565 541 sa_free_attr_string(rname);
566 542 return (SA_CONFIG_ERR);
567 543 }
568 544 }
569 545
570 546 sa_free_attr_string(rname);
571 547
572 548 share = sa_get_resource_parent(resource);
573 549 if (share != NULL) {
574 550 rname = sa_get_share_attr(share, "path");
575 551 if (rname != NULL) {
576 552 sa_handle_t handle;
577 553
578 554 handle = sa_find_group_handle((sa_group_t)resource);
579 555 (void) sa_delete_sharetab(handle, rname, "smb");
580 556 sa_free_attr_string(rname);
581 557 }
582 558 }
583 559 /*
584 560 * Always return OK as smb/server may be down and
585 561 * Shares will be picked up when loaded.
586 562 */
587 563 return (SA_OK);
588 564 }
589 565
590 566 /*
591 567 * smb_share_changed(sa_share_t share)
592 568 *
593 569 * The specified share has changed.
594 570 */
595 571 static int
596 572 smb_share_changed(sa_share_t share)
597 573 {
598 574 char *path;
599 575 sa_resource_t resource;
600 576
601 577 if (!smb_isonline())
602 578 return (SA_OK);
603 579
604 580 /* get the path since it is important in several places */
605 581 path = sa_get_share_attr(share, "path");
606 582 if (path == NULL)
607 583 return (SA_NO_SUCH_PATH);
608 584
609 585 for (resource = sa_get_share_resource(share, NULL);
610 586 resource != NULL;
611 587 resource = sa_get_next_resource(resource))
612 588 (void) smb_resource_changed(resource);
613 589
614 590 sa_free_attr_string(path);
615 591
616 592 return (SA_OK);
617 593 }
618 594
619 595 /*
620 596 * smb_resource_changed(sa_resource_t resource)
621 597 *
622 598 * The specified resource has changed.
623 599 */
624 600 static int
625 601 smb_resource_changed(sa_resource_t resource)
626 602 {
627 603 uint32_t res;
628 604 sa_share_t share;
629 605 smb_share_t si;
630 606
631 607 if (!smb_isonline())
632 608 return (SA_OK);
633 609
634 610 if ((share = sa_get_resource_parent(resource)) == NULL)
635 611 return (SA_CONFIG_ERR);
636 612
637 613 if ((res = smb_build_shareinfo(share, resource, &si)) != SA_OK)
638 614 return (res);
639 615
640 616 res = smb_share_modify(&si);
641 617
642 618 if (res != NERR_Success)
643 619 return (SA_CONFIG_ERR);
644 620
645 621 return (smb_enable_service());
646 622 }
647 623
648 624 /*
649 625 * smb_disable_share(sa_share_t share, char *path)
650 626 *
651 627 * Unshare the specified share. Note that "path" is the same
652 628 * path as what is in the "share" object. It is passed in to avoid an
653 629 * additional lookup. A missing "path" value makes this a no-op
654 630 * function.
655 631 */
656 632 static int
657 633 smb_disable_share(sa_share_t share, char *path)
658 634 {
659 635 char *rname;
660 636 sa_resource_t resource;
661 637 sa_group_t parent;
662 638 boolean_t iszfs;
663 639 int err = SA_OK;
664 640 int ret = SA_OK;
665 641 sa_handle_t handle;
666 642 boolean_t first = B_TRUE; /* work around sharetab issue */
667 643
668 644 if (path == NULL)
669 645 return (ret);
670 646
671 647 /*
672 648 * If the share is in a ZFS group we need to handle it
673 649 * differently. Just being on a ZFS file system isn't
674 650 * enough since we may be in a legacy share case.
675 651 */
676 652 parent = sa_get_parent_group(share);
677 653 iszfs = sa_group_is_zfs(parent);
678 654
679 655 if (!smb_isonline())
680 656 goto done;
681 657
682 658 for (resource = sa_get_share_resource(share, NULL);
683 659 resource != NULL;
684 660 resource = sa_get_next_resource(resource)) {
685 661 rname = sa_get_resource_attr(resource, "name");
686 662 if (rname == NULL) {
687 663 continue;
688 664 }
689 665 if (!iszfs) {
690 666 err = smb_share_delete(rname);
691 667 switch (err) {
692 668 case NERR_NetNameNotFound:
693 669 case NERR_Success:
694 670 err = SA_OK;
695 671 break;
696 672 default:
697 673 err = SA_CONFIG_ERR;
698 674 break;
699 675 }
700 676 } else {
701 677 share_t sh;
702 678
703 679 (void) sa_sharetab_fill_zfs(share, &sh, "smb");
704 680 err = sa_share_zfs(share, resource, (char *)path, &sh,
705 681 rname, ZFS_UNSHARE_SMB);
706 682 if (err != SA_OK) {
707 683 switch (err) {
708 684 case EINVAL:
709 685 case ENOENT:
710 686 err = SA_OK;
711 687 break;
712 688 default:
713 689 /*
714 690 * If we are no longer the first case,
715 691 * we don't care about the sa_share_zfs
716 692 * err if it is -1. This works around
717 693 * a problem in sharefs and should be
718 694 * removed when sharefs supports
719 695 * multiple entries per path.
720 696 */
721 697 if (!first)
722 698 err = SA_OK;
723 699 else
724 700 err = SA_SYSTEM_ERR;
725 701 break;
726 702 }
727 703 }
728 704
729 705 first = B_FALSE;
730 706
731 707 sa_emptyshare(&sh);
732 708 }
733 709
734 710 if (err != SA_OK)
735 711 ret = err;
736 712 sa_free_attr_string(rname);
737 713 }
738 714 done:
739 715 if (!iszfs) {
740 716 handle = sa_find_group_handle((sa_group_t)share);
741 717 if (handle != NULL)
742 718 (void) sa_delete_sharetab(handle, path, "smb");
743 719 else
744 720 ret = SA_SYSTEM_ERR;
745 721 }
746 722 return (ret);
747 723 }
748 724
749 725 /*
750 726 * smb_validate_property(handle, property, parent)
751 727 *
752 728 * Check that the property has a legitimate value for its type.
753 729 * Handle isn't currently used but may need to be in the future.
754 730 */
755 731
756 732 /*ARGSUSED*/
757 733 static int
758 734 smb_validate_property(sa_handle_t handle, sa_property_t property,
759 735 sa_optionset_t parent)
760 736 {
761 737 int ret = SA_OK;
762 738 char *propname;
763 739 int optindex;
764 740 sa_group_t parent_group;
765 741 char *value;
766 742 char *other;
767 743
768 744 propname = sa_get_property_attr(property, "type");
769 745
770 746 if ((optindex = findopt(propname)) < 0)
771 747 ret = SA_NO_SUCH_PROP;
772 748
773 749 /* need to validate value range here as well */
774 750 if (ret == SA_OK) {
775 751 parent_group = sa_get_parent_group((sa_share_t)parent);
776 752 if (optdefs[optindex].share && !sa_is_share(parent_group))
777 753 ret = SA_PROP_SHARE_ONLY;
778 754 }
779 755 if (ret != SA_OK) {
780 756 if (propname != NULL)
781 757 sa_free_attr_string(propname);
782 758 return (ret);
783 759 }
784 760
785 761 value = sa_get_property_attr(property, "value");
786 762 if (value != NULL) {
787 763 /* first basic type checking */
788 764 switch (optdefs[optindex].type) {
789 765 case OPT_TYPE_NUMBER:
790 766 /* check that the value is all digits */
791 767 if (!is_a_number(value))
792 768 ret = SA_BAD_VALUE;
793 769 break;
794 770 case OPT_TYPE_BOOLEAN:
795 771 ret = true_false_validator(0, value);
796 772 break;
797 773 case OPT_TYPE_NAME:
798 774 /*
799 775 * Make sure no invalid characters
800 776 */
801 777 if (!validresource(value))
802 778 ret = SA_BAD_VALUE;
803 779 break;
804 780 case OPT_TYPE_STRING:
805 781 /* whatever is here should be ok */
806 782 break;
807 783 case OPT_TYPE_CSC:
808 784 if (!validcsc(value))
809 785 ret = SA_BAD_VALUE;
810 786 break;
811 787 case OPT_TYPE_ACCLIST: {
812 788 sa_property_t oprop;
813 789 char *ovalue;
814 790 /*
815 791 * access list handling. Should eventually
816 792 * validate that all the values make sense.
817 793 * Also, ro and rw may have cross value
818 794 * conflicts.
819 795 */
820 796 if (parent == NULL)
821 797 break;
822 798 if (strcmp(propname, SHOPT_RO) == 0)
823 799 other = SHOPT_RW;
824 800 else if (strcmp(propname, SHOPT_RW) == 0)
825 801 other = SHOPT_RO;
826 802 else
827 803 other = NULL;
828 804 if (other == NULL)
829 805 break;
830 806
831 807 /* compare rw(ro) with ro(rw) */
832 808 oprop = sa_get_property(parent, other);
833 809 if (oprop == NULL)
834 810 break;
835 811 /*
836 812 * only potential
837 813 * confusion if other
838 814 * exists
839 815 */
840 816 ovalue = sa_get_property_attr(oprop, "value");
841 817 if (ovalue != NULL) {
842 818 ret = check_rorw(value, ovalue);
843 819 sa_free_attr_string(ovalue);
844 820 }
845 821 break;
846 822 }
847 823 default:
848 824 break;
849 825 }
850 826 }
851 827
852 828 if (value != NULL)
853 829 sa_free_attr_string(value);
854 830 if (ret == SA_OK && optdefs[optindex].check != NULL)
855 831 /* do the property specific check */
856 832 ret = optdefs[optindex].check(property);
857 833
858 834 if (propname != NULL)
859 835 sa_free_attr_string(propname);
860 836 return (ret);
861 837 }
862 838
863 839 /*
864 840 * Protocol management functions
865 841 *
866 842 * properties defined in the default files are defined in
867 843 * proto_option_defs for parsing and validation.
868 844 */
869 845
870 846 struct smb_proto_option_defs {
871 847 int smb_index;
872 848 int32_t minval;
873 849 int32_t maxval; /* In case of length of string this should be max */
874 850 int (*validator)(int, char *);
875 851 int32_t refresh;
876 852 } smb_proto_options[] = {
877 853 { SMB_CI_SYS_CMNT, 0, MAX_VALUE_BUFLEN,
878 854 string_length_check_validator, SMB_REFRESH_REFRESH },
879 855 { SMB_CI_MAX_WORKERS, SMB_PI_MAX_WORKERS_MIN, SMB_PI_MAX_WORKERS_MAX,
880 856 range_check_validator, SMB_REFRESH_REFRESH },
881 857 { SMB_CI_NETBIOS_ENABLE, 0, 0, true_false_validator,
882 858 SMB_REFRESH_REFRESH },
883 859 { SMB_CI_NBSCOPE, 0, MAX_VALUE_BUFLEN,
884 860 string_length_check_validator, 0 },
885 861 { SMB_CI_LM_LEVEL, 2, 5, range_check_validator, 0 },
886 862 { SMB_CI_KEEPALIVE, 20, 5400, range_check_validator_zero_ok,
887 863 SMB_REFRESH_REFRESH },
888 864 { SMB_CI_WINS_SRV1, 0, MAX_VALUE_BUFLEN,
889 865 ipv4_validator, SMB_REFRESH_REFRESH },
890 866 { SMB_CI_WINS_SRV2, 0, MAX_VALUE_BUFLEN,
891 867 ipv4_validator, SMB_REFRESH_REFRESH },
892 868 { SMB_CI_WINS_EXCL, 0, MAX_VALUE_BUFLEN,
893 869 interface_validator, SMB_REFRESH_REFRESH },
894 870 { SMB_CI_SIGNING_ENABLE, 0, 0, true_false_validator,
895 871 SMB_REFRESH_REFRESH },
896 872 { SMB_CI_SIGNING_REQD, 0, 0, true_false_validator,
897 873 SMB_REFRESH_REFRESH },
898 874 { SMB_CI_RESTRICT_ANON, 0, 0, true_false_validator,
899 875 SMB_REFRESH_REFRESH },
900 876 { SMB_CI_DOMAIN_SRV, 0, MAX_VALUE_BUFLEN,
901 877 hostname_validator, SMB_REFRESH_REFRESH },
902 878 { SMB_CI_ADS_SITE, 0, MAX_VALUE_BUFLEN,
903 879 string_length_check_validator, SMB_REFRESH_REFRESH },
904 880 { SMB_CI_DYNDNS_ENABLE, 0, 0, true_false_validator, 0 },
905 881 { SMB_CI_AUTOHOME_MAP, 0, MAX_VALUE_BUFLEN, path_validator, 0 },
906 882 { SMB_CI_IPV6_ENABLE, 0, 0, true_false_validator,
|
↓ open down ↓ |
452 lines elided |
↑ open up ↑ |
907 883 SMB_REFRESH_REFRESH },
908 884 { SMB_CI_PRINT_ENABLE, 0, 0, print_enable_validator,
909 885 SMB_REFRESH_REFRESH },
910 886 { SMB_CI_TRAVERSE_MOUNTS, 0, 0, true_false_validator,
911 887 SMB_REFRESH_REFRESH },
912 888 { SMB_CI_MAP, 0, MAX_VALUE_BUFLEN, cmd_validator, SMB_REFRESH_REFRESH },
913 889 { SMB_CI_UNMAP, 0, MAX_VALUE_BUFLEN, cmd_validator,
914 890 SMB_REFRESH_REFRESH },
915 891 { SMB_CI_DISPOSITION, 0, MAX_VALUE_BUFLEN,
916 892 disposition_validator, SMB_REFRESH_REFRESH },
917 - { SMB_CI_MAX_PROTOCOL, 0, MAX_VALUE_BUFLEN, max_protocol_validator,
893 + { SMB_CI_MAX_PROTOCOL, 0, MAX_VALUE_BUFLEN, protocol_validator,
918 894 SMB_REFRESH_REFRESH },
895 + { SMB_CI_ENCRYPT, 0, MAX_VALUE_BUFLEN, require_validator,
896 + SMB_REFRESH_REFRESH },
897 + { SMB_CI_MIN_PROTOCOL, 0, MAX_VALUE_BUFLEN, protocol_validator,
898 + SMB_REFRESH_REFRESH },
899 + { SMB_CI_BYPASS_TRAVERSE_CHECKING, 0, 0, true_false_validator,
900 + SMB_REFRESH_REFRESH },
901 + { SMB_CI_OPLOCK_ENABLE, 0, 0, true_false_validator,
902 + SMB_REFRESH_REFRESH },
919 903 };
920 904
921 905 #define SMB_OPT_NUM \
922 906 (sizeof (smb_proto_options) / sizeof (smb_proto_options[0]))
923 907
908 +static int
909 +require_validator(int index, char *value)
910 +{
911 + if (string_length_check_validator(index, value) != SA_OK)
912 + return (SA_BAD_VALUE);
913 +
914 + if (strcmp(value, "required") == 0)
915 + return (SA_OK);
916 +
917 + if (strcmp(value, "disabled") == 0)
918 + return (SA_OK);
919 +
920 + if (strcmp(value, "enabled") == 0)
921 + return (SA_OK);
922 +
923 + return (SA_BAD_VALUE);
924 +}
925 +
924 926 /*
925 927 * Check the range of value as int range.
926 928 */
927 929 static int
928 930 range_check_validator(int index, char *value)
929 931 {
930 932 int ret = SA_OK;
931 933
932 934 if (!is_a_number(value)) {
933 935 ret = SA_BAD_VALUE;
934 936 } else {
935 937 int val;
936 938 val = strtoul(value, NULL, 0);
937 939 if (val < smb_proto_options[index].minval ||
938 940 val > smb_proto_options[index].maxval)
939 941 ret = SA_BAD_VALUE;
940 942 }
941 943 return (ret);
942 944 }
943 945
944 946 /*
945 947 * Check the range of value as int range.
946 948 */
947 949 static int
948 950 range_check_validator_zero_ok(int index, char *value)
949 951 {
950 952 int ret = SA_OK;
951 953
952 954 if (!is_a_number(value)) {
953 955 ret = SA_BAD_VALUE;
954 956 } else {
955 957 int val;
956 958 val = strtoul(value, NULL, 0);
957 959 if (val == 0)
958 960 ret = SA_OK;
959 961 else {
960 962 if (val < smb_proto_options[index].minval ||
961 963 val > smb_proto_options[index].maxval)
962 964 ret = SA_BAD_VALUE;
963 965 }
964 966 }
965 967 return (ret);
966 968 }
967 969
968 970 /*
969 971 * Check the length of the string
970 972 */
971 973 static int
972 974 string_length_check_validator(int index, char *value)
973 975 {
974 976 int ret = SA_OK;
975 977
976 978 if (value == NULL)
977 979 return (SA_BAD_VALUE);
978 980 if (strlen(value) > smb_proto_options[index].maxval)
979 981 ret = SA_BAD_VALUE;
980 982 return (ret);
981 983 }
982 984
983 985 /*
984 986 * Check yes/no
985 987 */
986 988 /*ARGSUSED*/
987 989 static int
988 990 true_false_validator(int index, char *value)
989 991 {
990 992 if (value == NULL)
991 993 return (SA_BAD_VALUE);
992 994 if ((strcasecmp(value, "true") == 0) ||
993 995 (strcasecmp(value, "false") == 0))
994 996 return (SA_OK);
995 997 return (SA_BAD_VALUE);
996 998 }
997 999
998 1000 /*
999 1001 * If printing support is compiled in, this is the same as:
1000 1002 * true_false_validator. Otherwise, only allow false.
1001 1003 */
1002 1004 /*ARGSUSED*/
1003 1005 static int
1004 1006 print_enable_validator(int index, char *value)
1005 1007 {
1006 1008 if (value == NULL)
1007 1009 return (SA_BAD_VALUE);
1008 1010
1009 1011 #ifdef HAVE_CUPS
1010 1012 if (strcasecmp(value, "true") == 0)
1011 1013 return (SA_OK);
1012 1014 #endif
1013 1015 if (strcasecmp(value, "false") == 0)
1014 1016 return (SA_OK);
1015 1017
1016 1018 return (SA_BAD_VALUE);
1017 1019 }
1018 1020
1019 1021 /*
1020 1022 * Check IP v4 address.
1021 1023 */
1022 1024 /*ARGSUSED*/
1023 1025 static int
1024 1026 ipv4_validator(int index, char *value)
1025 1027 {
1026 1028 char sbytes[16];
1027 1029
1028 1030 if (value == NULL)
1029 1031 return (SA_OK);
1030 1032
1031 1033 if (strlen(value) == 0)
1032 1034 return (SA_OK);
1033 1035
1034 1036 if (inet_pton(AF_INET, value, (void *)sbytes) != 1)
1035 1037 return (SA_BAD_VALUE);
1036 1038
1037 1039 return (SA_OK);
1038 1040 }
1039 1041
1040 1042 /*
1041 1043 * Check that the specified name is an IP address (v4 or v6) or a hostname.
1042 1044 * Per RFC 1035 and 1123, names may contain alphanumeric characters, hyphens
1043 1045 * and dots. The first and last character of a label must be alphanumeric.
1044 1046 * Interior characters may be alphanumeric or hypens.
1045 1047 *
1046 1048 * Domain names should not contain underscores but we allow them because
1047 1049 * Windows names are often in non-compliance with this rule.
1048 1050 */
1049 1051 /*ARGSUSED*/
1050 1052 static int
1051 1053 hostname_validator(int index, char *value)
1052 1054 {
1053 1055 char sbytes[INET6_ADDRSTRLEN];
1054 1056 boolean_t new_label = B_TRUE;
1055 1057 char *p;
1056 1058 char label_terminator;
1057 1059 int len;
1058 1060
1059 1061 if (value == NULL)
1060 1062 return (SA_OK);
1061 1063
1062 1064 if ((len = strlen(value)) == 0)
1063 1065 return (SA_OK);
1064 1066
1065 1067 if (inet_pton(AF_INET, value, (void *)sbytes) == 1)
1066 1068 return (SA_OK);
1067 1069
1068 1070 if (inet_pton(AF_INET6, value, (void *)sbytes) == 1)
1069 1071 return (SA_OK);
1070 1072
1071 1073 if (len >= MAXHOSTNAMELEN)
1072 1074 return (SA_BAD_VALUE);
1073 1075
1074 1076 if (strspn(value, "0123456789.") == len)
1075 1077 return (SA_BAD_VALUE);
1076 1078
1077 1079 label_terminator = *value;
1078 1080
1079 1081 for (p = value; *p != '\0'; ++p) {
1080 1082 if (new_label) {
1081 1083 if (!isalnum(*p))
1082 1084 return (SA_BAD_VALUE);
1083 1085 new_label = B_FALSE;
1084 1086 label_terminator = *p;
1085 1087 continue;
1086 1088 }
1087 1089
1088 1090 if (*p == '.') {
1089 1091 if (!isalnum(label_terminator))
1090 1092 return (SA_BAD_VALUE);
1091 1093 new_label = B_TRUE;
1092 1094 label_terminator = *p;
1093 1095 continue;
1094 1096 }
1095 1097
1096 1098 label_terminator = *p;
1097 1099
1098 1100 if (isalnum(*p) || *p == '-' || *p == '_')
1099 1101 continue;
1100 1102
1101 1103 return (SA_BAD_VALUE);
1102 1104 }
1103 1105
1104 1106 if (!isalnum(label_terminator))
1105 1107 return (SA_BAD_VALUE);
1106 1108
1107 1109 return (SA_OK);
1108 1110 }
1109 1111
1110 1112 /*
1111 1113 * Call back function for dlpi_walk.
1112 1114 * Returns TRUE if interface name exists on the host.
1113 1115 */
1114 1116 static boolean_t
1115 1117 smb_get_interface(const char *ifname, void *arg)
1116 1118 {
1117 1119 smb_hostifs_walker_t *iterp = arg;
1118 1120
1119 1121 iterp->hiw_matchfound = (strcmp(ifname, iterp->hiw_ifname) == 0);
1120 1122
1121 1123 return (iterp->hiw_matchfound);
1122 1124 }
1123 1125
1124 1126 /*
1125 1127 * Checks to see if the input interface exists on the host.
1126 1128 * Returns B_TRUE if the match is found, B_FALSE otherwise.
1127 1129 */
1128 1130 static boolean_t
1129 1131 smb_validate_interface(const char *ifname)
1130 1132 {
1131 1133 smb_hostifs_walker_t iter;
1132 1134
1133 1135 if ((ifname == NULL) || (*ifname == '\0'))
1134 1136 return (B_FALSE);
1135 1137
1136 1138 iter.hiw_ifname = ifname;
1137 1139 iter.hiw_matchfound = B_FALSE;
1138 1140 dlpi_walk(smb_get_interface, &iter, 0);
1139 1141
1140 1142 return (iter.hiw_matchfound);
1141 1143 }
1142 1144
1143 1145 /*
1144 1146 * Check valid interfaces. Interface names value can be NULL or empty.
1145 1147 * Returns SA_BAD_VALUE if interface cannot be found on the host.
1146 1148 */
1147 1149 /*ARGSUSED*/
1148 1150 static int
1149 1151 interface_validator(int index, char *value)
1150 1152 {
1151 1153 char buf[16];
1152 1154 int ret = SA_OK;
1153 1155 char *ifname, *tmp, *p;
1154 1156
1155 1157 if (value == NULL || *value == '\0')
1156 1158 return (ret);
1157 1159
1158 1160 if (strlen(value) > MAX_VALUE_BUFLEN)
1159 1161 return (SA_BAD_VALUE);
1160 1162
1161 1163 if ((p = strdup(value)) == NULL)
1162 1164 return (SA_NO_MEMORY);
1163 1165
1164 1166 tmp = p;
1165 1167 while ((ifname = strsep(&tmp, ",")) != NULL) {
1166 1168 if (*ifname == '\0') {
1167 1169 ret = SA_BAD_VALUE;
1168 1170 break;
1169 1171 }
1170 1172
1171 1173 if (!smb_validate_interface(ifname)) {
1172 1174 if (inet_pton(AF_INET, ifname, (void *)buf) == 0) {
1173 1175 ret = SA_BAD_VALUE;
1174 1176 break;
1175 1177 }
1176 1178 }
1177 1179 }
1178 1180
1179 1181 free(p);
1180 1182 return (ret);
1181 1183 }
1182 1184
1183 1185 /*
1184 1186 * Check path
1185 1187 */
1186 1188 /*ARGSUSED*/
1187 1189 static int
1188 1190 path_validator(int index, char *path)
1189 1191 {
1190 1192 struct stat buffer;
1191 1193 int fd, status;
1192 1194
1193 1195 if (path == NULL)
1194 1196 return (SA_BAD_VALUE);
1195 1197
1196 1198 fd = open(path, O_RDONLY);
1197 1199 if (fd < 0)
1198 1200 return (SA_BAD_VALUE);
1199 1201
1200 1202 status = fstat(fd, &buffer);
1201 1203 (void) close(fd);
1202 1204
1203 1205 if (status < 0)
1204 1206 return (SA_BAD_VALUE);
1205 1207
1206 1208 if (buffer.st_mode & S_IFDIR)
1207 1209 return (SA_OK);
1208 1210 return (SA_BAD_VALUE);
1209 1211 }
1210 1212
1211 1213 /*
1212 1214 * the protoset holds the defined options so we don't have to read
1213 1215 * them multiple times
1214 1216 */
1215 1217 static sa_protocol_properties_t protoset;
1216 1218
1217 1219 static int
1218 1220 findprotoopt(char *name)
1219 1221 {
1220 1222 int i;
1221 1223 char *sc_name;
1222 1224
1223 1225 for (i = 0; i < SMB_OPT_NUM; i++) {
1224 1226 sc_name = smb_config_getname(smb_proto_options[i].smb_index);
1225 1227 if (strcasecmp(sc_name, name) == 0)
1226 1228 return (i);
1227 1229 }
1228 1230
1229 1231 return (-1);
1230 1232 }
1231 1233
1232 1234 /*
1233 1235 * smb_load_proto_properties()
1234 1236 *
1235 1237 * read the smb config values from SMF.
1236 1238 */
1237 1239
1238 1240 static int
1239 1241 smb_load_proto_properties()
1240 1242 {
1241 1243 sa_property_t prop;
1242 1244 char value[MAX_VALUE_BUFLEN];
1243 1245 char *name;
1244 1246 int index;
1245 1247 int ret = SA_OK;
1246 1248 int rc;
1247 1249
1248 1250 protoset = sa_create_protocol_properties(SMB_PROTOCOL_NAME);
1249 1251 if (protoset == NULL)
1250 1252 return (SA_NO_MEMORY);
1251 1253
1252 1254 for (index = 0; index < SMB_OPT_NUM && ret == SA_OK; index++) {
1253 1255 rc = smb_config_get(smb_proto_options[index].smb_index,
1254 1256 value, sizeof (value));
1255 1257 if (rc != SMBD_SMF_OK)
1256 1258 continue;
1257 1259 name = smb_config_getname(smb_proto_options[index].smb_index);
1258 1260 prop = sa_create_property(name, value);
1259 1261 if (prop != NULL)
1260 1262 ret = sa_add_protocol_property(protoset, prop);
1261 1263 else
1262 1264 ret = SA_NO_MEMORY;
1263 1265 }
1264 1266 return (ret);
1265 1267 }
1266 1268
1267 1269 /*
1268 1270 * smb_share_init()
1269 1271 *
1270 1272 * Initialize the smb plugin.
1271 1273 */
1272 1274
1273 1275 static int
1274 1276 smb_share_init(void)
1275 1277 {
1276 1278 if (sa_plugin_ops.sa_init != smb_share_init)
1277 1279 return (SA_SYSTEM_ERR);
1278 1280
1279 1281 smb_share_door_clnt_init();
1280 1282 return (smb_load_proto_properties());
1281 1283 }
1282 1284
1283 1285 /*
1284 1286 * smb_share_fini()
1285 1287 *
1286 1288 */
1287 1289 static void
1288 1290 smb_share_fini(void)
1289 1291 {
1290 1292 xmlFreeNode(protoset);
1291 1293 protoset = NULL;
1292 1294
1293 1295 smb_share_door_clnt_fini();
1294 1296 }
1295 1297
1296 1298 /*
1297 1299 * smb_get_proto_set()
1298 1300 *
1299 1301 * Return an optionset with all the protocol specific properties in
1300 1302 * it.
1301 1303 */
1302 1304 static sa_protocol_properties_t
1303 1305 smb_get_proto_set(void)
1304 1306 {
1305 1307 return (protoset);
1306 1308 }
1307 1309
1308 1310 /*
1309 1311 * smb_enable_dependencies()
1310 1312 *
1311 1313 * SMBD_DEFAULT_INSTANCE_FMRI may have some dependencies that aren't
1312 1314 * enabled. This will attempt to enable all of them.
1313 1315 */
1314 1316 static void
1315 1317 smb_enable_dependencies(const char *fmri)
1316 1318 {
1317 1319 scf_handle_t *handle;
1318 1320 scf_service_t *service;
1319 1321 scf_instance_t *inst = NULL;
1320 1322 scf_iter_t *iter;
1321 1323 scf_property_t *prop;
1322 1324 scf_value_t *value;
1323 1325 scf_propertygroup_t *pg;
1324 1326 scf_scope_t *scope;
1325 1327 char type[SCFTYPE_LEN];
1326 1328 char *dependency;
1327 1329 char *servname;
1328 1330 int maxlen;
1329 1331
1330 1332 /*
1331 1333 * Get all required handles and storage.
1332 1334 */
1333 1335 handle = scf_handle_create(SCF_VERSION);
1334 1336 if (handle == NULL)
1335 1337 return;
1336 1338
1337 1339 if (scf_handle_bind(handle) != 0) {
1338 1340 scf_handle_destroy(handle);
1339 1341 return;
1340 1342 }
1341 1343
1342 1344 maxlen = scf_limit(SCF_LIMIT_MAX_VALUE_LENGTH);
1343 1345 if (maxlen == (ssize_t)-1)
1344 1346 maxlen = MAXPATHLEN;
1345 1347
1346 1348 dependency = malloc(maxlen);
1347 1349
1348 1350 service = scf_service_create(handle);
1349 1351
1350 1352 iter = scf_iter_create(handle);
1351 1353
1352 1354 pg = scf_pg_create(handle);
1353 1355
1354 1356 prop = scf_property_create(handle);
1355 1357
1356 1358 value = scf_value_create(handle);
1357 1359
1358 1360 scope = scf_scope_create(handle);
1359 1361
1360 1362 if (service == NULL || iter == NULL || pg == NULL || prop == NULL ||
1361 1363 value == NULL || scope == NULL || dependency == NULL)
1362 1364 goto done;
1363 1365
1364 1366 /*
1365 1367 * We passed in the FMRI for the default instance but for
1366 1368 * some things we need the simple form so construct it. Since
1367 1369 * we reuse the storage that dependency points to, we need to
1368 1370 * use the servname early.
1369 1371 */
1370 1372 (void) snprintf(dependency, maxlen, "%s", fmri + sizeof ("svc:"));
1371 1373 servname = strrchr(dependency, ':');
1372 1374 if (servname == NULL)
1373 1375 goto done;
1374 1376 *servname = '\0';
1375 1377 servname = dependency;
1376 1378
1377 1379 /*
1378 1380 * Setup to iterate over the service property groups, only
1379 1381 * looking at those that are "dependency" types. The "entity"
1380 1382 * property will have the FMRI of the service we are dependent
1381 1383 * on.
1382 1384 */
1383 1385 if (scf_handle_get_scope(handle, SCF_SCOPE_LOCAL, scope) != 0)
1384 1386 goto done;
1385 1387
1386 1388 if (scf_scope_get_service(scope, servname, service) != 0)
1387 1389 goto done;
1388 1390
1389 1391 if (scf_iter_service_pgs(iter, service) != 0)
1390 1392 goto done;
1391 1393
1392 1394 while (scf_iter_next_pg(iter, pg) > 0) {
1393 1395 char *services[2];
1394 1396 /*
1395 1397 * Have a property group for the service. See if it is
1396 1398 * a dependency pg and only do operations on those.
1397 1399 */
1398 1400 if (scf_pg_get_type(pg, type, SCFTYPE_LEN) <= 0)
1399 1401 continue;
1400 1402
1401 1403 if (strncmp(type, SCF_GROUP_DEPENDENCY, SCFTYPE_LEN) != 0)
1402 1404 continue;
1403 1405 /*
1404 1406 * Have a dependency. Attempt to enable it.
1405 1407 */
1406 1408 if (scf_pg_get_property(pg, SCF_PROPERTY_ENTITIES, prop) != 0)
1407 1409 continue;
1408 1410
1409 1411 if (scf_property_get_value(prop, value) != 0)
1410 1412 continue;
1411 1413
1412 1414 services[1] = NULL;
1413 1415
1414 1416 if (scf_value_get_as_string(value, dependency, maxlen) > 0) {
1415 1417 services[0] = dependency;
1416 1418 _check_services(services);
1417 1419 }
1418 1420 }
1419 1421
1420 1422 done:
1421 1423 if (dependency != NULL)
1422 1424 free(dependency);
1423 1425 if (value != NULL)
1424 1426 scf_value_destroy(value);
1425 1427 if (prop != NULL)
1426 1428 scf_property_destroy(prop);
1427 1429 if (pg != NULL)
1428 1430 scf_pg_destroy(pg);
1429 1431 if (iter != NULL)
1430 1432 scf_iter_destroy(iter);
1431 1433 if (scope != NULL)
1432 1434 scf_scope_destroy(scope);
1433 1435 if (inst != NULL)
1434 1436 scf_instance_destroy(inst);
1435 1437 if (service != NULL)
1436 1438 scf_service_destroy(service);
1437 1439
1438 1440 (void) scf_handle_unbind(handle);
1439 1441 scf_handle_destroy(handle);
1440 1442 }
1441 1443
1442 1444 /*
1443 1445 * How long to wait for service to come online
1444 1446 */
1445 1447 #define WAIT_FOR_SERVICE 15
1446 1448
1447 1449 /*
1448 1450 * smb_enable_service()
1449 1451 *
1450 1452 */
1451 1453 static int
1452 1454 smb_enable_service(void)
1453 1455 {
1454 1456 int i;
1455 1457 int ret = SA_OK;
1456 1458 char *service[] = { SMBD_DEFAULT_INSTANCE_FMRI, NULL };
1457 1459
1458 1460 if (!smb_isonline()) {
1459 1461 /*
1460 1462 * Attempt to start the idmap, and other dependent
1461 1463 * services, first. If it fails, the SMB service will
1462 1464 * ultimately fail so we use that as the error. If we
1463 1465 * don't try to enable idmap, smb won't start the
1464 1466 * first time unless the admin has done it
1465 1467 * manually. The service could be administratively
1466 1468 * disabled so we won't always get started.
1467 1469 */
1468 1470 smb_enable_dependencies(SMBD_DEFAULT_INSTANCE_FMRI);
1469 1471 _check_services(service);
1470 1472
1471 1473 /* Wait for service to come online */
1472 1474 for (i = 0; i < WAIT_FOR_SERVICE; i++) {
1473 1475 if (smb_isonline()) {
1474 1476 ret = SA_OK;
1475 1477 break;
1476 1478 } else if (smb_ismaint()) {
1477 1479 /* maintenance requires help */
1478 1480 ret = SA_SYSTEM_ERR;
1479 1481 break;
1480 1482 } else {
1481 1483 /* try another time */
1482 1484 ret = SA_BUSY;
1483 1485 (void) sleep(1);
1484 1486 }
1485 1487 }
1486 1488 }
1487 1489 return (ret);
1488 1490 }
1489 1491
1490 1492 /*
1491 1493 * smb_validate_proto_prop(index, name, value)
1492 1494 *
1493 1495 * Verify that the property specified by name can take the new
1494 1496 * value. This is a sanity check to prevent bad values getting into
1495 1497 * the default files.
1496 1498 */
1497 1499 static int
1498 1500 smb_validate_proto_prop(int index, char *name, char *value)
1499 1501 {
1500 1502 if ((name == NULL) || (index < 0))
1501 1503 return (SA_BAD_VALUE);
1502 1504
1503 1505 if (smb_proto_options[index].validator == NULL)
1504 1506 return (SA_OK);
1505 1507
1506 1508 if (smb_proto_options[index].validator(index, value) == SA_OK)
1507 1509 return (SA_OK);
1508 1510 return (SA_BAD_VALUE);
1509 1511 }
1510 1512
1511 1513 /*
1512 1514 * smb_set_proto_prop(prop)
1513 1515 *
1514 1516 * check that prop is valid.
1515 1517 */
1516 1518 /*ARGSUSED*/
1517 1519 static int
1518 1520 smb_set_proto_prop(sa_property_t prop)
1519 1521 {
1520 1522 int ret = SA_OK;
1521 1523 char *name;
1522 1524 char *value;
1523 1525 int index = -1;
1524 1526 struct smb_proto_option_defs *opt;
1525 1527
1526 1528 name = sa_get_property_attr(prop, "type");
|
↓ open down ↓ |
593 lines elided |
↑ open up ↑ |
1527 1529 value = sa_get_property_attr(prop, "value");
1528 1530 if (name != NULL && value != NULL) {
1529 1531 index = findprotoopt(name);
1530 1532 if (index >= 0) {
1531 1533 /* should test for valid value */
1532 1534 ret = smb_validate_proto_prop(index, name, value);
1533 1535 if (ret == SA_OK) {
1534 1536 opt = &smb_proto_options[index];
1535 1537
1536 1538 /* Save to SMF */
1537 - (void) smb_config_set(opt->smb_index, value);
1539 + if (smb_config_set(opt->smb_index,
1540 + value) != 0) {
1541 + ret = SA_BAD_VALUE;
1542 + goto out;
1543 + }
1538 1544 /*
1539 1545 * Specialized refresh mechanisms can
1540 1546 * be flagged in the proto_options and
1541 1547 * processed here.
1542 1548 */
1543 1549 if (opt->refresh & SMB_REFRESH_REFRESH)
1544 1550 (void) smf_refresh_instance(
1545 1551 SMBD_DEFAULT_INSTANCE_FMRI);
1546 1552 else if (opt->refresh & SMB_REFRESH_RESTART)
1547 1553 (void) smf_restart_instance(
1548 1554 SMBD_DEFAULT_INSTANCE_FMRI);
1549 1555 }
1550 1556 }
1551 1557 }
1552 1558
1559 +out:
1553 1560 if (name != NULL)
1554 1561 sa_free_attr_string(name);
1555 1562 if (value != NULL)
1556 1563 sa_free_attr_string(value);
1557 1564
1558 1565 return (ret);
1559 1566 }
1560 1567
1561 1568 /*
1562 1569 * smb_get_status()
1563 1570 *
1564 1571 * What is the current status of the smbd? We use the SMF state here.
1565 1572 * Caller must free the returned value.
1566 1573 */
1567 1574
1568 1575 static char *
1569 1576 smb_get_status(void)
1570 1577 {
1571 1578 return (smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI));
1572 1579 }
1573 1580
1574 1581 /*
1575 1582 * This protocol plugin require resource names
1576 1583 */
1577 1584 static uint64_t
1578 1585 smb_share_features(void)
1579 1586 {
1580 1587 return (SA_FEATURE_RESOURCE | SA_FEATURE_ALLOWSUBDIRS |
1581 1588 SA_FEATURE_ALLOWPARDIRS | SA_FEATURE_SERVER);
1582 1589 }
1583 1590
1584 1591 /*
1585 1592 * This should be used to convert smb_share_t to sa_resource_t
1586 1593 * Should only be needed to build transient shares/resources to be
1587 1594 * supplied to sharemgr to display.
1588 1595 */
1589 1596 static int
1590 1597 smb_add_transient(sa_handle_t handle, smb_share_t *si)
1591 1598 {
1592 1599 int err;
1593 1600 sa_share_t share;
1594 1601 sa_group_t group;
1595 1602 sa_resource_t resource;
1596 1603 nvlist_t *nvl;
1597 1604 char *opt;
1598 1605
1599 1606 if (si == NULL)
1600 1607 return (SA_INVALID_NAME);
1601 1608
1602 1609 if ((share = sa_find_share(handle, si->shr_path)) == NULL) {
1603 1610 if ((group = smb_get_defaultgrp(handle)) == NULL)
1604 1611 return (SA_NO_SUCH_GROUP);
1605 1612
1606 1613 share = sa_get_share(group, si->shr_path);
1607 1614 if (share == NULL) {
1608 1615 share = sa_add_share(group, si->shr_path,
1609 1616 SA_SHARE_TRANSIENT, &err);
1610 1617 if (share == NULL)
1611 1618 return (SA_NO_SUCH_PATH);
1612 1619 }
1613 1620 }
1614 1621
1615 1622 /*
1616 1623 * Now handle the resource. Make sure that the resource is
1617 1624 * transient and added to the share.
1618 1625 */
1619 1626 resource = sa_get_share_resource(share, si->shr_name);
1620 1627 if (resource == NULL) {
1621 1628 resource = sa_add_resource(share,
1622 1629 si->shr_name, SA_SHARE_TRANSIENT, &err);
1623 1630 if (resource == NULL)
1624 1631 return (SA_NO_SUCH_RESOURCE);
1625 1632 }
1626 1633
1627 1634 if (si->shr_cmnt[0] != '\0')
1628 1635 (void) sa_set_resource_description(resource, si->shr_cmnt);
1629 1636
1630 1637 if (si->shr_container[0] != '\0')
1631 1638 (void) sa_set_resource_attr(resource, SHOPT_AD_CONTAINER,
1632 1639 si->shr_container);
1633 1640
1634 1641 if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0)
1635 1642 return (SA_NO_MEMORY);
1636 1643
1637 1644 if ((opt = smb_csc_name(si)) != NULL)
1638 1645 err |= nvlist_add_string(nvl, SHOPT_CSC, opt);
1639 1646
1640 1647 opt = (si->shr_flags & SMB_SHRF_ABE) ? "true" : "false";
1641 1648 err |= nvlist_add_string(nvl, SHOPT_ABE, opt);
1642 1649
1643 1650 if ((si->shr_flags & SMB_SHRF_AUTOHOME) == 0) {
1644 1651 opt = (si->shr_flags & SMB_SHRF_GUEST_OK) ? "true" : "false";
1645 1652 err |= nvlist_add_string(nvl, SHOPT_GUEST, opt);
1646 1653 }
1647 1654
1648 1655 if (si->shr_access_ro[0] != '\0')
1649 1656 err |= nvlist_add_string(nvl, SHOPT_RO, si->shr_access_ro);
1650 1657
1651 1658 if (si->shr_access_rw[0] != '\0')
1652 1659 err |= nvlist_add_string(nvl, SHOPT_RW, si->shr_access_rw);
1653 1660
1654 1661 if (si->shr_access_none[0] != '\0')
1655 1662 err |= nvlist_add_string(nvl, SHOPT_NONE, si->shr_access_none);
1656 1663
1657 1664 if (err) {
1658 1665 nvlist_free(nvl);
1659 1666 return (SA_CONFIG_ERR);
1660 1667 }
1661 1668
1662 1669 err = smb_update_optionset_props(handle, resource, nvl);
1663 1670
1664 1671 nvlist_free(nvl);
1665 1672 return (err);
1666 1673 }
1667 1674
1668 1675 /*
1669 1676 * Return smb transient shares.
1670 1677 */
1671 1678 static int
1672 1679 smb_list_transient(sa_handle_t handle)
1673 1680 {
1674 1681 int i, offset;
1675 1682 smb_shrlist_t list;
1676 1683 int res;
1677 1684
1678 1685 if (smb_share_count() <= 0)
1679 1686 return (SA_OK);
1680 1687
1681 1688 offset = 0;
1682 1689 while (smb_share_list(offset, &list) == NERR_Success) {
1683 1690 if (list.sl_cnt == 0)
1684 1691 break;
1685 1692
1686 1693 for (i = 0; i < list.sl_cnt; i++) {
1687 1694 res = smb_add_transient(handle, &(list.sl_shares[i]));
1688 1695 if (res != SA_OK)
1689 1696 return (res);
1690 1697 }
1691 1698 offset += list.sl_cnt;
1692 1699 }
1693 1700
1694 1701 return (SA_OK);
1695 1702 }
1696 1703
1697 1704 /*
1698 1705 * fix_resource_name(share, name, prefix)
1699 1706 *
1700 1707 * Construct a name where the ZFS dataset has the prefix replaced with "name".
1701 1708 */
1702 1709 static char *
1703 1710 fix_resource_name(sa_share_t share, char *name, char *prefix)
1704 1711 {
1705 1712 char buf[SA_MAX_RESOURCE_NAME + 1];
1706 1713 char *dataset;
1707 1714 size_t bufsz = SA_MAX_RESOURCE_NAME + 1;
1708 1715 size_t prelen;
1709 1716
1710 1717 if (prefix == NULL)
1711 1718 return (strdup(name));
1712 1719
1713 1720 dataset = sa_get_share_attr(share, "dataset");
1714 1721 if (dataset == NULL)
1715 1722 return (strdup(name));
1716 1723
1717 1724 (void) strlcpy(buf, name, bufsz);
1718 1725 prelen = strlen(prefix);
1719 1726
1720 1727 if (strncmp(dataset, prefix, prelen) == 0)
1721 1728 (void) strlcat(buf, dataset + prelen, bufsz);
1722 1729
1723 1730 sa_free_attr_string(dataset);
1724 1731 sa_fix_resource_name(buf);
1725 1732 return (strdup(buf));
1726 1733 }
1727 1734
1728 1735 /*
1729 1736 * smb_parse_optstring(group, options)
1730 1737 *
1731 1738 * parse a compact option string into individual options. This allows
1732 1739 * ZFS sharesmb and sharemgr "share" command to work. group can be a
1733 1740 * group, a share or a resource.
1734 1741 */
1735 1742 static int
1736 1743 smb_parse_optstring(sa_group_t group, char *options)
1737 1744 {
1738 1745 char *dup;
1739 1746 char *base;
1740 1747 char *lasts;
1741 1748 char *token;
1742 1749 sa_optionset_t optionset;
1743 1750 sa_group_t parent = NULL;
1744 1751 sa_resource_t resource = NULL;
1745 1752 int iszfs = 0;
1746 1753 int persist = 0;
1747 1754 int need_optionset = 0;
1748 1755 int ret = SA_OK;
1749 1756 sa_property_t prop;
1750 1757
1751 1758 /*
1752 1759 * In order to not attempt to change ZFS properties unless
1753 1760 * absolutely necessary, we never do it in the legacy parsing
1754 1761 * so we need to keep track of this.
1755 1762 */
1756 1763 if (sa_is_share(group)) {
1757 1764 char *zfs;
1758 1765
1759 1766 parent = sa_get_parent_group(group);
1760 1767 if (parent != NULL) {
1761 1768 zfs = sa_get_group_attr(parent, "zfs");
1762 1769 if (zfs != NULL) {
1763 1770 sa_free_attr_string(zfs);
1764 1771 iszfs = 1;
1765 1772 }
1766 1773 }
1767 1774 } else {
1768 1775 iszfs = sa_group_is_zfs(group);
1769 1776 /*
1770 1777 * If a ZFS group, then we need to see if a resource
1771 1778 * name is being set. If so, bail with
1772 1779 * SA_PROP_SHARE_ONLY, so we come back in with a share
1773 1780 * instead of a group.
1774 1781 */
1775 1782 if (iszfs ||
1776 1783 strncmp(options, "name=", sizeof ("name=") - 1) == 0 ||
1777 1784 strstr(options, ",name=") != NULL) {
1778 1785 return (SA_PROP_SHARE_ONLY);
1779 1786 }
1780 1787 }
1781 1788
1782 1789 /* do we have an existing optionset? */
1783 1790 optionset = sa_get_optionset(group, "smb");
1784 1791 if (optionset == NULL) {
1785 1792 /* didn't find existing optionset so create one */
1786 1793 optionset = sa_create_optionset(group, "smb");
1787 1794 if (optionset == NULL)
1788 1795 return (SA_NO_MEMORY);
1789 1796 } else {
1790 1797 /*
1791 1798 * If an optionset already exists, we've come through
1792 1799 * twice so ignore the second time.
1793 1800 */
1794 1801 return (ret);
1795 1802 }
1796 1803
1797 1804 /* We need a copy of options for the next part. */
1798 1805 dup = strdup(options);
1799 1806 if (dup == NULL)
1800 1807 return (SA_NO_MEMORY);
1801 1808
1802 1809 /*
1803 1810 * SMB properties are straightforward and are strings,
1804 1811 * integers or booleans. Properties are separated by
1805 1812 * commas. It will be necessary to parse quotes due to some
1806 1813 * strings not having a restricted characters set.
1807 1814 *
1808 1815 * Note that names will create a resource. For now, if there
1809 1816 * is a set of properties "before" the first name="", those
1810 1817 * properties will be placed on the group.
1811 1818 */
1812 1819 persist = sa_is_persistent(group);
1813 1820 base = dup;
1814 1821 token = dup;
1815 1822 lasts = NULL;
1816 1823 while (token != NULL && ret == SA_OK) {
1817 1824 ret = SA_OK;
1818 1825 token = strtok_r(base, ",", &lasts);
1819 1826 base = NULL;
1820 1827 if (token != NULL) {
1821 1828 char *value;
1822 1829 /*
1823 1830 * All SMB properties have values so there
1824 1831 * MUST be an '=' character. If it doesn't,
1825 1832 * it is a syntax error.
1826 1833 */
1827 1834 value = strchr(token, '=');
1828 1835 if (value != NULL) {
1829 1836 *value++ = '\0';
1830 1837 } else {
1831 1838 ret = SA_SYNTAX_ERR;
1832 1839 break;
1833 1840 }
1834 1841 /*
1835 1842 * We may need to handle a "name" property
1836 1843 * that is a ZFS imposed resource name. Each
1837 1844 * name would trigger getting a new "resource"
1838 1845 * to put properties on. For now, assume no
1839 1846 * "name" property for special handling.
1840 1847 */
1841 1848
1842 1849 if (strcmp(token, SHOPT_NAME) == 0) {
1843 1850 char *prefix;
1844 1851 char *name = NULL;
1845 1852 /*
1846 1853 * We have a name, so now work on the
1847 1854 * resource level. We have a "share"
1848 1855 * in "group" due to the caller having
1849 1856 * added it. If we are called with a
1850 1857 * group, the check for group/share
1851 1858 * at the beginning of this function
1852 1859 * will bail out the parse if there is a
1853 1860 * "name" but no share.
1854 1861 */
1855 1862 if (!iszfs) {
1856 1863 ret = SA_SYNTAX_ERR;
1857 1864 break;
1858 1865 }
1859 1866 /*
1860 1867 * Make sure the parent group has the
1861 1868 * "prefix" property since we will
1862 1869 * need to use this for constructing
1863 1870 * inherited name= values.
1864 1871 */
1865 1872 prefix = sa_get_group_attr(parent, "prefix");
1866 1873 if (prefix == NULL) {
1867 1874 prefix = sa_get_group_attr(parent,
1868 1875 "name");
1869 1876 if (prefix != NULL) {
1870 1877 (void) sa_set_group_attr(parent,
1871 1878 "prefix", prefix);
1872 1879 }
1873 1880 }
1874 1881 name = fix_resource_name((sa_share_t)group,
1875 1882 value, prefix);
1876 1883 if (name != NULL) {
1877 1884 resource = sa_add_resource(
1878 1885 (sa_share_t)group, name,
1879 1886 SA_SHARE_TRANSIENT, &ret);
1880 1887 sa_free_attr_string(name);
1881 1888 } else {
1882 1889 ret = SA_NO_MEMORY;
1883 1890 }
1884 1891 if (prefix != NULL)
1885 1892 sa_free_attr_string(prefix);
1886 1893
1887 1894 /* A resource level optionset is needed */
1888 1895
1889 1896 need_optionset = 1;
1890 1897 if (resource == NULL) {
1891 1898 ret = SA_NO_MEMORY;
1892 1899 break;
1893 1900 }
1894 1901 continue;
1895 1902 }
1896 1903
1897 1904 if (iszfs && strcmp(token, SHOPT_DESCRIPTION) == 0) {
1898 1905 if (resource == NULL)
1899 1906 (void) sa_set_share_description(
1900 1907 (sa_share_t)group, value);
1901 1908 else
1902 1909 (void) sa_set_resource_description(
1903 1910 resource, value);
1904 1911 continue;
1905 1912 }
1906 1913
1907 1914 if (need_optionset) {
1908 1915 optionset = sa_create_optionset(resource,
1909 1916 "smb");
1910 1917 need_optionset = 0;
1911 1918 }
1912 1919
1913 1920 prop = sa_create_property(token, value);
1914 1921 if (prop == NULL)
1915 1922 ret = SA_NO_MEMORY;
1916 1923 else
1917 1924 ret = sa_add_property(optionset, prop);
1918 1925 if (ret != SA_OK)
1919 1926 break;
1920 1927 if (!iszfs)
1921 1928 ret = sa_commit_properties(optionset, !persist);
1922 1929 }
1923 1930 }
1924 1931 free(dup);
1925 1932 return (ret);
1926 1933 }
1927 1934
1928 1935 /*
1929 1936 * smb_sprint_option(rbuff, rbuffsize, incr, prop, sep)
|
↓ open down ↓ |
367 lines elided |
↑ open up ↑ |
1930 1937 *
1931 1938 * provides a mechanism to format SMB properties into legacy output
1932 1939 * format. If the buffer would overflow, it is reallocated and grown
1933 1940 * as appropriate. Special cases of converting internal form of values
1934 1941 * to those used by "share" are done. this function does one property
1935 1942 * at a time.
1936 1943 */
1937 1944
1938 1945 static void
1939 1946 smb_sprint_option(char **rbuff, size_t *rbuffsize, size_t incr,
1940 - sa_property_t prop, int sep)
1947 + sa_property_t prop, int sep)
1941 1948 {
1942 1949 char *name;
1943 1950 char *value;
1944 1951 int curlen;
1945 1952 char *buff = *rbuff;
1946 1953 size_t buffsize = *rbuffsize;
1947 1954
1948 1955 name = sa_get_property_attr(prop, "type");
1949 1956 value = sa_get_property_attr(prop, "value");
1950 1957 if (buff != NULL)
1951 1958 curlen = strlen(buff);
1952 1959 else
1953 1960 curlen = 0;
1954 1961 if (name != NULL) {
1955 1962 int len;
1956 1963 len = strlen(name) + sep;
1957 1964
1958 1965 /*
1959 1966 * A future RFE would be to replace this with more
1960 1967 * generic code and to possibly handle more types.
1961 1968 *
1962 1969 * For now, everything else is treated as a string. If
1963 1970 * we get any properties that aren't exactly
1964 1971 * name/value pairs, we may need to
1965 1972 * interpret/transform.
1966 1973 */
1967 1974 if (value != NULL)
1968 1975 len += 1 + strlen(value);
1969 1976
1970 1977 while (buffsize <= (curlen + len)) {
1971 1978 /* need more room */
1972 1979 buffsize += incr;
1973 1980 buff = realloc(buff, buffsize);
1974 1981 *rbuff = buff;
1975 1982 *rbuffsize = buffsize;
1976 1983 if (buff == NULL) {
1977 1984 /* realloc failed so free everything */
1978 1985 if (*rbuff != NULL)
1979 1986 free(*rbuff);
1980 1987 goto err;
1981 1988 }
1982 1989 }
1983 1990 if (buff == NULL)
1984 1991 goto err;
1985 1992 (void) snprintf(buff + curlen, buffsize - curlen,
1986 1993 "%s%s=%s", sep ? "," : "",
1987 1994 name, value != NULL ? value : "\"\"");
1988 1995
1989 1996 }
1990 1997 err:
1991 1998 if (name != NULL)
1992 1999 sa_free_attr_string(name);
1993 2000 if (value != NULL)
1994 2001 sa_free_attr_string(value);
1995 2002 }
1996 2003
1997 2004 /*
1998 2005 * smb_format_resource_options(resource, hier)
1999 2006 *
2000 2007 * format all the options on the group into a flattened option
2001 2008 * string. If hier is non-zero, walk up the tree to get inherited
2002 2009 * options.
2003 2010 */
2004 2011
2005 2012 static char *
2006 2013 smb_format_options(sa_group_t group, int hier)
2007 2014 {
2008 2015 sa_optionset_t options = NULL;
2009 2016 sa_property_t prop;
2010 2017 int sep = 0;
2011 2018 char *buff;
2012 2019 size_t buffsize;
2013 2020
2014 2021
2015 2022 buff = malloc(OPT_CHUNK);
2016 2023 if (buff == NULL)
2017 2024 return (NULL);
2018 2025
2019 2026 buff[0] = '\0';
2020 2027 buffsize = OPT_CHUNK;
2021 2028
2022 2029 /*
2023 2030 * We may have a an optionset relative to this item. format
2024 2031 * these if we find them and then add any security definitions.
2025 2032 */
2026 2033
2027 2034 options = sa_get_derived_optionset(group, "smb", hier);
2028 2035
2029 2036 /*
2030 2037 * do the default set first but skip any option that is also
2031 2038 * in the protocol specific optionset.
2032 2039 */
2033 2040 if (options != NULL) {
2034 2041 for (prop = sa_get_property(options, NULL);
2035 2042 prop != NULL; prop = sa_get_next_property(prop)) {
2036 2043 /*
2037 2044 * use this one since we skipped any
2038 2045 * of these that were also in
2039 2046 * optdefault
2040 2047 */
2041 2048 smb_sprint_option(&buff, &buffsize, OPT_CHUNK,
2042 2049 prop, sep);
2043 2050 if (buff == NULL) {
2044 2051 /*
2045 2052 * buff could become NULL if there
2046 2053 * isn't enough memory for
2047 2054 * smb_sprint_option to realloc()
2048 2055 * as necessary. We can't really
2049 2056 * do anything about it at this
2050 2057 * point so we return NULL. The
2051 2058 * caller should handle the
2052 2059 * failure.
2053 2060 */
2054 2061 if (options != NULL)
2055 2062 sa_free_derived_optionset(
2056 2063 options);
2057 2064 return (buff);
2058 2065 }
2059 2066 sep = 1;
2060 2067 }
2061 2068 }
2062 2069
2063 2070 if (options != NULL)
2064 2071 sa_free_derived_optionset(options);
2065 2072 return (buff);
2066 2073 }
2067 2074
2068 2075 /*
2069 2076 * smb_rename_resource(resource, newname)
2070 2077 *
2071 2078 * Change the current exported name of the resource to newname.
2072 2079 */
2073 2080 /*ARGSUSED*/
2074 2081 int
2075 2082 smb_rename_resource(sa_handle_t handle, sa_resource_t resource, char *newname)
2076 2083 {
2077 2084 int ret = SA_OK;
2078 2085 int err;
2079 2086 char *oldname;
2080 2087
2081 2088 if (!smb_isonline())
2082 2089 return (SA_OK);
2083 2090
2084 2091 oldname = sa_get_resource_attr(resource, "name");
2085 2092 if (oldname == NULL)
2086 2093 return (SA_NO_SUCH_RESOURCE);
2087 2094
2088 2095 err = smb_share_rename(oldname, newname);
2089 2096
2090 2097 sa_free_attr_string(oldname);
2091 2098
2092 2099 /* improve error values somewhat */
2093 2100 switch (err) {
2094 2101 case NERR_Success:
2095 2102 break;
2096 2103 case NERR_InternalError:
2097 2104 ret = SA_SYSTEM_ERR;
2098 2105 break;
2099 2106 case NERR_DuplicateShare:
2100 2107 ret = SA_DUPLICATE_NAME;
2101 2108 break;
2102 2109 default:
2103 2110 ret = SA_CONFIG_ERR;
2104 2111 break;
2105 2112 }
2106 2113
2107 2114 return (ret);
|
↓ open down ↓ |
157 lines elided |
↑ open up ↑ |
2108 2115 }
2109 2116
2110 2117 static int
2111 2118 smb_build_shareinfo(sa_share_t share, sa_resource_t resource, smb_share_t *si)
2112 2119 {
2113 2120 sa_optionset_t opts;
2114 2121 char *path;
2115 2122 char *rname;
2116 2123 char *val = NULL;
2117 2124 char csc_value[SMB_CSC_BUFSZ];
2125 + char strbuf[sizeof ("required")];
2118 2126
2119 2127 bzero(si, sizeof (smb_share_t));
2120 2128
2121 2129 if ((path = sa_get_share_attr(share, "path")) == NULL)
2122 2130 return (SA_NO_SUCH_PATH);
2123 2131
2124 2132 if ((rname = sa_get_resource_attr(resource, "name")) == NULL) {
2125 2133 sa_free_attr_string(path);
2126 2134 return (SA_NO_SUCH_RESOURCE);
2127 2135 }
2128 2136
2129 2137 (void) strlcpy(si->shr_path, path, sizeof (si->shr_path));
2130 2138 (void) strlcpy(si->shr_name, rname, sizeof (si->shr_name));
2131 2139 sa_free_attr_string(path);
2132 2140 sa_free_attr_string(rname);
2133 2141
2134 2142 val = sa_get_resource_description(resource);
2135 2143 if (val == NULL)
2136 2144 val = sa_get_share_description(share);
2137 2145
2138 2146 if (val != NULL) {
2139 2147 (void) strlcpy(si->shr_cmnt, val, sizeof (si->shr_cmnt));
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
2140 2148 sa_free_share_description(val);
2141 2149 }
2142 2150
2143 2151 si->shr_flags = (sa_is_persistent(share))
2144 2152 ? SMB_SHRF_PERM : SMB_SHRF_TRANS;
2145 2153
2146 2154 opts = sa_get_derived_optionset(resource, SMB_PROTOCOL_NAME, 1);
2147 2155 if (opts == NULL)
2148 2156 return (SA_OK);
2149 2157
2150 - if (smb_saprop_getbool(opts, SHOPT_CATIA))
2158 + if (smb_saprop_getbool(opts, SHOPT_CATIA, B_FALSE))
2151 2159 si->shr_flags |= SMB_SHRF_CATIA;
2152 2160
2153 - if (smb_saprop_getbool(opts, SHOPT_ABE))
2161 + if (smb_saprop_getbool(opts, SHOPT_ABE, B_FALSE))
2154 2162 si->shr_flags |= SMB_SHRF_ABE;
2155 2163
2156 - if (smb_saprop_getbool(opts, SHOPT_GUEST))
2164 + if (smb_saprop_getbool(opts, SHOPT_GUEST, B_FALSE))
2157 2165 si->shr_flags |= SMB_SHRF_GUEST_OK;
2158 2166
2159 - if (smb_saprop_getbool(opts, SHOPT_DFSROOT))
2167 + if (smb_saprop_getbool(opts, SHOPT_DFSROOT, B_FALSE))
2160 2168 si->shr_flags |= SMB_SHRF_DFSROOT;
2161 2169
2170 + if (smb_saprop_getbool(opts, SHOPT_CA, B_FALSE))
2171 + si->shr_flags |= SMB_SHRF_CA;
2172 +
2173 + if (smb_saprop_getbool(opts, SHOPT_FSO, B_FALSE))
2174 + si->shr_flags |= SMB_SHRF_FSO;
2175 +
2176 + /* Quotas are enabled by default. */
2177 + if (smb_saprop_getbool(opts, SHOPT_QUOTAS, B_TRUE))
2178 + si->shr_flags |= SMB_SHRF_QUOTAS;
2179 +
2180 + if (smb_saprop_getstr(opts, SHOPT_ENCRYPT, strbuf, sizeof (strbuf)))
2181 + smb_cfg_set_require(strbuf, &si->shr_encrypt);
2182 +
2162 2183 (void) smb_saprop_getstr(opts, SHOPT_AD_CONTAINER, si->shr_container,
2163 2184 sizeof (si->shr_container));
2164 2185
2165 2186 if (smb_saprop_getstr(opts, SHOPT_CSC, csc_value, sizeof (csc_value)))
2166 2187 smb_csc_option(csc_value, si);
2167 2188
2168 2189 if (smb_saprop_getstr(opts, SHOPT_RO, si->shr_access_ro,
2169 2190 sizeof (si->shr_access_ro)))
2170 2191 si->shr_flags |= SMB_SHRF_ACC_RO;
2171 2192
2172 2193 if (smb_saprop_getstr(opts, SHOPT_RW, si->shr_access_rw,
2173 2194 sizeof (si->shr_access_rw)))
2174 2195 si->shr_flags |= SMB_SHRF_ACC_RW;
2175 2196
2176 2197 if (smb_saprop_getstr(opts, SHOPT_NONE, si->shr_access_none,
2177 2198 sizeof (si->shr_access_none)))
2178 2199 si->shr_flags |= SMB_SHRF_ACC_NONE;
2179 2200
2180 2201 sa_free_derived_optionset(opts);
2181 2202 return (SA_OK);
2182 2203 }
2183 2204
2184 2205 /*
2185 2206 * Map a client-side caching (CSC) option to the appropriate share
2186 2207 * flag. Only one option is allowed; an error will be logged if
2187 2208 * multiple options have been specified. We don't need to do anything
2188 2209 * about multiple values here because the SRVSVC will not recognize
2189 2210 * a value containing multiple flags and will return the default value.
2190 2211 *
2191 2212 * If the option value is not recognized, it will be ignored: invalid
2192 2213 * values will typically be caught and rejected by sharemgr.
2193 2214 */
2194 2215 static void
2195 2216 smb_csc_option(const char *value, smb_share_t *si)
2196 2217 {
2197 2218 char buf[SMB_CSC_BUFSZ];
2198 2219 int i;
2199 2220
2200 2221 for (i = 0; i < (sizeof (cscopt) / sizeof (cscopt[0])); ++i) {
2201 2222 if (strcasecmp(value, cscopt[i].value) == 0) {
2202 2223 si->shr_flags |= cscopt[i].flag;
2203 2224 break;
2204 2225 }
2205 2226 }
2206 2227
2207 2228 switch (si->shr_flags & SMB_SHRF_CSC_MASK) {
2208 2229 case 0:
2209 2230 case SMB_SHRF_CSC_DISABLED:
2210 2231 case SMB_SHRF_CSC_MANUAL:
2211 2232 case SMB_SHRF_CSC_AUTO:
2212 2233 case SMB_SHRF_CSC_VDO:
2213 2234 break;
2214 2235
2215 2236 default:
2216 2237 buf[0] = '\0';
2217 2238
2218 2239 for (i = 0; i < (sizeof (cscopt) / sizeof (cscopt[0])); ++i) {
2219 2240 if (si->shr_flags & cscopt[i].flag) {
2220 2241 (void) strlcat(buf, " ", SMB_CSC_BUFSZ);
2221 2242 (void) strlcat(buf, cscopt[i].value,
2222 2243 SMB_CSC_BUFSZ);
2223 2244 }
2224 2245 }
2225 2246
2226 2247 syslog(LOG_ERR, "csc option conflict:%s", buf);
2227 2248 break;
2228 2249 }
2229 2250 }
2230 2251
2231 2252 /*
2232 2253 * Return the option name for the first CSC flag (there should be only
2233 2254 * one) encountered in the share flags.
2234 2255 */
2235 2256 static char *
2236 2257 smb_csc_name(const smb_share_t *si)
2237 2258 {
2238 2259 int i;
2239 2260
2240 2261 for (i = 0; i < (sizeof (cscopt) / sizeof (cscopt[0])); ++i) {
2241 2262 if (si->shr_flags & cscopt[i].flag)
2242 2263 return (cscopt[i].value);
2243 2264 }
2244 2265
2245 2266 return (NULL);
2246 2267 }
2247 2268
2248 2269 /*
2249 2270 * smb_get_defaultgrp
2250 2271 *
2251 2272 * If default group for CIFS shares (i.e. "smb") exists
2252 2273 * then it will return the group handle, otherwise it will
2253 2274 * create the group and return the handle.
2254 2275 *
2255 2276 * All the shares created by CIFS clients (this is only possible
2256 2277 * via RPC) will be added to "smb" groups.
2257 2278 */
2258 2279 static sa_group_t
2259 2280 smb_get_defaultgrp(sa_handle_t handle)
2260 2281 {
2261 2282 sa_group_t group = NULL;
2262 2283 int err;
2263 2284
2264 2285 group = sa_get_group(handle, SMB_DEFAULT_SHARE_GROUP);
2265 2286 if (group != NULL)
2266 2287 return (group);
2267 2288
2268 2289 group = sa_create_group(handle, SMB_DEFAULT_SHARE_GROUP, &err);
2269 2290 if (group == NULL)
2270 2291 return (NULL);
2271 2292
2272 2293 if (sa_create_optionset(group, SMB_DEFAULT_SHARE_GROUP) == NULL) {
2273 2294 (void) sa_remove_group(group);
2274 2295 group = NULL;
2275 2296 }
2276 2297
2277 2298 return (group);
2278 2299 }
2279 2300
2280 2301 /*
2281 2302 * Checks to see if the command args are the supported substitution specifier.
2282 2303 * i.e. <cmd> %U %S
2283 2304 */
2284 2305 static int
2285 2306 cmd_validator(int index, char *value)
2286 2307 {
2287 2308 char cmd[MAXPATHLEN];
2288 2309 char *ptr, *v;
2289 2310 boolean_t skip_cmdname;
2290 2311
2291 2312 if (string_length_check_validator(index, value) != SA_OK)
2292 2313 return (SA_BAD_VALUE);
2293 2314
2294 2315 if (*value == '\0')
2295 2316 return (SA_OK);
2296 2317
2297 2318 (void) strlcpy(cmd, value, sizeof (cmd));
2298 2319
2299 2320 ptr = cmd;
2300 2321 skip_cmdname = B_TRUE;
2301 2322 do {
2302 2323 if ((v = strsep(&ptr, " ")) == NULL)
2303 2324 break;
2304 2325
2305 2326 if (*v != '\0') {
2306 2327
2307 2328 if (skip_cmdname) {
2308 2329 skip_cmdname = B_FALSE;
2309 2330 continue;
2310 2331 }
2311 2332
2312 2333 if ((strlen(v) != 2) || *v != '%')
2313 2334 return (SA_BAD_VALUE);
2314 2335
2315 2336 if (strpbrk(v, SMB_VALID_SUB_CHRS) == NULL)
2316 2337 return (SA_BAD_VALUE);
2317 2338 }
2318 2339
2319 2340 } while (v != NULL);
2320 2341
2321 2342 /*
2322 2343 * If skip_cmdname is still true then the string contains
2323 2344 * only spaces. Don't allow such a string.
2324 2345 */
2325 2346 if (skip_cmdname)
2326 2347 return (SA_BAD_VALUE);
2327 2348
2328 2349 return (SA_OK);
2329 2350 }
2330 2351
2331 2352 /*ARGSUSED*/
2332 2353 static int
2333 2354 disposition_validator(int index, char *value)
2334 2355 {
2335 2356 if (value == NULL)
2336 2357 return (SA_BAD_VALUE);
2337 2358
2338 2359 if (*value == '\0')
2339 2360 return (SA_OK);
|
↓ open down ↓ |
168 lines elided |
↑ open up ↑ |
2340 2361
2341 2362 if ((strcasecmp(value, SMB_EXEC_DISP_CONTINUE) == 0) ||
2342 2363 (strcasecmp(value, SMB_EXEC_DISP_TERMINATE) == 0))
2343 2364 return (SA_OK);
2344 2365
2345 2366 return (SA_BAD_VALUE);
2346 2367 }
2347 2368
2348 2369 /*ARGSUSED*/
2349 2370 static int
2350 -max_protocol_validator(int index, char *value)
2371 +protocol_validator(int index, char *value)
2351 2372 {
2352 2373 if (value == NULL)
2353 2374 return (SA_BAD_VALUE);
2354 2375
2355 2376 if (*value == '\0')
2356 2377 return (SA_OK);
2357 2378
2358 2379 if (smb_config_check_protocol(value) == 0)
2359 2380 return (SA_OK);
2360 2381
2361 2382 return (SA_BAD_VALUE);
2362 2383
2363 2384 }
2364 2385
2365 2386 /*
2366 2387 * Updates the optionset properties of the share resource.
2367 2388 * The properties are given as a list of name-value pair.
2368 2389 * The name argument should be the optionset property name and the value
2369 2390 * should be a valid value for the specified property.
2370 2391 *
2371 2392 * When calling this function for permanent shares, the caller must also
2372 2393 * call sa_commit_properties() to commit the changes to SMF.
2373 2394 */
2374 2395 static int
2375 2396 smb_update_optionset_props(sa_handle_t handle, sa_resource_t resource,
2376 2397 nvlist_t *nvl)
2377 2398 {
2378 2399 sa_property_t prop;
2379 2400 sa_optionset_t opts;
2380 2401 int err = SA_OK;
2381 2402 nvpair_t *cur;
2382 2403 char *name, *val;
2383 2404
2384 2405 if ((opts = sa_get_optionset(resource, SMB_PROTOCOL_NAME)) == NULL) {
2385 2406 opts = sa_create_optionset(resource, SMB_PROTOCOL_NAME);
2386 2407 if (opts == NULL)
2387 2408 return (SA_CONFIG_ERR);
2388 2409 }
2389 2410
2390 2411 cur = nvlist_next_nvpair(nvl, NULL);
2391 2412 while (cur != NULL) {
2392 2413 name = nvpair_name(cur);
2393 2414 err = nvpair_value_string(cur, &val);
2394 2415 if ((err != 0) || (name == NULL) || (val == NULL)) {
2395 2416 err = SA_CONFIG_ERR;
2396 2417 break;
2397 2418 }
2398 2419
2399 2420 prop = NULL;
2400 2421 if ((prop = sa_get_property(opts, name)) == NULL) {
2401 2422 prop = sa_create_property(name, val);
2402 2423 if (prop != NULL) {
2403 2424 err = sa_valid_property(handle, opts,
2404 2425 SMB_PROTOCOL_NAME, prop);
2405 2426 if (err != SA_OK) {
2406 2427 (void) sa_remove_property(prop);
2407 2428 break;
2408 2429 }
2409 2430 }
2410 2431 err = sa_add_property(opts, prop);
2411 2432 if (err != SA_OK)
2412 2433 break;
2413 2434 } else {
2414 2435 err = sa_update_property(prop, val);
2415 2436 if (err != SA_OK)
|
↓ open down ↓ |
55 lines elided |
↑ open up ↑ |
2416 2437 break;
2417 2438 }
2418 2439
2419 2440 cur = nvlist_next_nvpair(nvl, cur);
2420 2441 }
2421 2442
2422 2443 return (err);
2423 2444 }
2424 2445
2425 2446 static boolean_t
2426 -smb_saprop_getbool(sa_optionset_t opts, char *propname)
2447 +smb_saprop_getbool(sa_optionset_t opts, char *propname, boolean_t def)
2427 2448 {
2428 2449 sa_property_t prop;
2429 2450 char *val;
2430 - boolean_t propval = B_FALSE;
2451 + boolean_t ret = def;
2431 2452
2432 2453 prop = sa_get_property(opts, propname);
2433 2454 if ((val = sa_get_property_attr(prop, "value")) != NULL) {
2434 - if ((strcasecmp(val, "true") == 0) || (strcmp(val, "1") == 0))
2435 - propval = B_TRUE;
2455 + if (def) {
2456 + /* Default is true, ret false if... */
2457 + if ((strcasecmp(val, "false") == 0) ||
2458 + (strcmp(val, "0") == 0))
2459 + ret = B_FALSE;
2460 + } else {
2461 + /* Default is false, ret true if... */
2462 + if ((strcasecmp(val, "true") == 0) ||
2463 + (strcmp(val, "1") == 0))
2464 + ret = B_TRUE;
2465 + }
2436 2466 free(val);
2437 2467 }
2438 2468
2439 - return (propval);
2469 + return (ret);
2440 2470 }
2441 2471
2442 2472 static boolean_t
2443 2473 smb_saprop_getstr(sa_optionset_t opts, char *propname, char *buf, size_t bufsz)
2444 2474 {
2445 2475 sa_property_t prop;
2446 2476 char *val;
2447 2477
2448 2478 prop = sa_get_property(opts, propname);
2449 2479 if ((val = sa_get_property_attr(prop, "value")) != NULL) {
2450 2480 (void) strlcpy(buf, val, bufsz);
2451 2481 free(val);
2452 2482 return (B_TRUE);
2453 2483 }
2454 2484
2455 2485 return (B_FALSE);
2456 2486 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX