4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
28 * SMB specific functions
39 #include <sys/types.h>
44 #include "libshare_impl.h"
48 #include <libscf_priv.h>
50 #include <sys/cfgparam.h>
51 #include "libshare_smb.h"
52 #include <rpcsvc/daemon_utils.h>
53 #include <smbsrv/smb_share.h>
54 #include <smbsrv/smbinfo.h>
55 #include <smbsrv/libsmb.h>
58 #define SMB_CSC_BUFSZ 64
60 #define SMB_VALID_SUB_CHRS "UDhMLmIiSPu" /* substitution characters */
62 /* internal functions */
63 static int smb_share_init(void);
64 static void smb_share_fini(void);
65 static int smb_enable_share(sa_share_t
);
66 static int smb_share_changed(sa_share_t
);
67 static int smb_resource_changed(sa_resource_t
);
68 static int smb_rename_resource(sa_handle_t
, sa_resource_t
, char *);
69 static int smb_disable_share(sa_share_t share
, char *);
70 static int smb_validate_property(sa_handle_t
, sa_property_t
, sa_optionset_t
);
71 static int smb_set_proto_prop(sa_property_t
);
72 static sa_protocol_properties_t
smb_get_proto_set(void);
73 static char *smb_get_status(void);
74 static int smb_parse_optstring(sa_group_t
, char *);
75 static char *smb_format_options(sa_group_t
, int);
77 static int smb_enable_service(void);
79 static int range_check_validator(int, char *);
80 static int range_check_validator_zero_ok(int, char *);
81 static int string_length_check_validator(int, char *);
82 static int print_enable_validator(int, char *);
83 static int true_false_validator(int, char *);
84 static int ipv4_validator(int, char *);
85 static int hostname_validator(int, char *);
86 static int path_validator(int, char *);
87 static int cmd_validator(int, char *);
88 static int disposition_validator(int, char *);
89 static int max_protocol_validator(int, char *);
91 static int smb_enable_resource(sa_resource_t
);
92 static int smb_disable_resource(sa_resource_t
);
93 static uint64_t smb_share_features(void);
94 static int smb_list_transient(sa_handle_t
);
96 static int smb_build_shareinfo(sa_share_t
, sa_resource_t
, smb_share_t
*);
97 static void smb_csc_option(const char *, smb_share_t
*);
98 static char *smb_csc_name(const smb_share_t
*);
99 static sa_group_t
smb_get_defaultgrp(sa_handle_t
);
100 static int interface_validator(int, char *);
101 static int smb_update_optionset_props(sa_handle_t
, sa_resource_t
, nvlist_t
*);
103 static boolean_t
smb_saprop_getbool(sa_optionset_t
, char *);
104 static boolean_t
smb_saprop_getstr(sa_optionset_t
, char *, char *, size_t);
110 { "disabled", SMB_SHRF_CSC_DISABLED
},
111 { "manual", SMB_SHRF_CSC_MANUAL
},
112 { "auto", SMB_SHRF_CSC_AUTO
},
113 { "vdo", SMB_SHRF_CSC_VDO
}
116 /* size of basic format allocation */
117 #define OPT_CHUNK 1024
119 /* size of string for types - big enough to hold "dependency" */
120 #define SCFTYPE_LEN 32
123 * Indexes of entries in smb_proto_options table.
124 * Changes to smb_proto_options table may require
125 * an update to these values.
127 #define PROTO_OPT_WINS1 6
128 #define PROTO_OPT_WINS_EXCLUDE 8
130 typedef struct smb_hostifs_walker
{
131 const char *hiw_ifname
;
132 boolean_t hiw_matchfound
;
133 } smb_hostifs_walker_t
;
137 * ops vector that provides the protocol specific info and operations
138 * for share management.
141 struct sa_plugin_ops sa_plugin_ops
= {
148 smb_validate_property
,
149 NULL
, /* valid_space */
150 NULL
, /* security_prop */
156 NULL
, /* space_alias */
157 NULL
, /* update_legacy */
158 NULL
, /* delete_legacy */
161 smb_disable_resource
,
164 smb_resource_changed
,
166 NULL
, /* run_command */
167 NULL
, /* command_help */
168 NULL
/* delete_proto_section */
171 struct option_defs optdefs
[] = {
172 { SHOPT_AD_CONTAINER
, OPT_TYPE_STRING
},
173 { SHOPT_ABE
, OPT_TYPE_BOOLEAN
},
174 { SHOPT_NAME
, OPT_TYPE_NAME
},
175 { SHOPT_RO
, OPT_TYPE_ACCLIST
},
176 { SHOPT_RW
, OPT_TYPE_ACCLIST
},
177 { SHOPT_NONE
, OPT_TYPE_ACCLIST
},
178 { SHOPT_CATIA
, OPT_TYPE_BOOLEAN
},
179 { SHOPT_CSC
, OPT_TYPE_CSC
},
180 { SHOPT_GUEST
, OPT_TYPE_BOOLEAN
},
181 { SHOPT_DFSROOT
, OPT_TYPE_BOOLEAN
},
182 { SHOPT_DESCRIPTION
, OPT_TYPE_STRING
},
189 * Lookup option "name" in the option table and return the table
197 for (i
= 0; optdefs
[i
].tag
!= NULL
; i
++) {
198 if (strcmp(optdefs
[i
].tag
, name
) == 0)
206 * is_a_number(number)
208 * is the string a number in one of the forms we want to use?
211 is_a_number(char *number
)
213 boolean_t isnum
= B_TRUE
;
214 boolean_t ishex
= B_FALSE
;
216 if (number
== NULL
|| *number
== '\0')
219 if (strncasecmp(number
, "0x", 2) == 0) {
222 } else if (*number
== '-') {
226 while (isnum
&& (*number
!= '\0')) {
227 isnum
= (ishex
) ? isxdigit(*number
) : isdigit(*number
);
235 * check ro vs rw values. Over time this may get beefed up.
236 * for now it just does simple checks.
240 check_rorw(char *v1
, char *v2
)
243 if (strcmp(v1
, v2
) == 0)
244 ret
= SA_VALUE_CONFLICT
;
249 * validresource(name)
251 * Check that name only has valid characters in it. The current valid
252 * set are the printable characters but not including:
253 * " / \ [ ] : | < > + ; , ? * = \t
254 * Note that space is included and there is a maximum length.
257 validresource(const char *name
)
266 if (len
== 0 || len
> SA_MAX_RESOURCE_NAME
)
269 if (strpbrk(name
, "\"/\\[]:|<>+;,?*=\t") != NULL
) {
273 for (cp
= name
; *cp
!= '\0'; cp
++)
281 * Check that the client-side caching (CSC) option value is valid.
284 validcsc(const char *value
)
288 for (i
= 0; i
< (sizeof (cscopt
) / sizeof (cscopt
[0])); ++i
) {
289 if (strcasecmp(value
, cscopt
[i
].value
) == 0)
299 * Determine if the SMF service instance is in the online state or
300 * not. A number of operations depend on this state.
306 boolean_t ret
= B_FALSE
;
308 if ((str
= smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI
)) != NULL
) {
309 ret
= (strcmp(str
, SCF_STATE_STRING_ONLINE
) == 0);
318 * Determine if the SMF service instance is in the disabled state or
319 * not. A number of operations depend on this state.
325 boolean_t ret
= B_FALSE
;
327 if ((str
= smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI
)) != NULL
) {
328 ret
= (strcmp(str
, SCF_STATE_STRING_DISABLED
) == 0);
337 * Determine if the SMF service instance auto_enabled set or not. A
338 * number of operations depend on this state. The property not being
339 * set or being set to true means autoenable. Only being set to false
340 * is not autoenabled.
343 smb_isautoenable(void)
345 boolean_t ret
= B_TRUE
;
346 scf_simple_prop_t
*prop
;
349 prop
= scf_simple_prop_get(NULL
, SMBD_DEFAULT_INSTANCE_FMRI
,
350 "application", "auto_enable");
352 retstr
= scf_simple_prop_next_boolean(prop
);
354 scf_simple_prop_free(prop
);
362 * Determine if the SMF service instance is in the disabled state or
363 * not. A number of operations depend on this state.
369 boolean_t ret
= B_FALSE
;
371 if ((str
= smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI
)) != NULL
) {
372 ret
= (strcmp(str
, SCF_STATE_STRING_MAINT
) == 0);
379 * smb_enable_share tells the implementation that it is to enable the share.
380 * This entails converting the path and options into the appropriate ioctl
381 * calls. It is assumed that all error checking of paths, etc. were
385 smb_enable_share(sa_share_t share
)
389 sa_resource_t resource
;
391 boolean_t privileged
;
393 priv_set_t
*priv_effective
;
396 priv_effective
= priv_allocset();
397 (void) getppriv(PRIV_EFFECTIVE
, priv_effective
);
398 privileged
= (priv_isfullset(priv_effective
) == B_TRUE
);
399 priv_freeset(priv_effective
);
401 /* get the path since it is important in several places */
402 path
= sa_get_share_attr(share
, "path");
404 return (SA_NO_SUCH_PATH
);
407 * If administratively disabled, don't try to start anything.
409 online
= smb_isonline();
410 if (!online
&& !smb_isautoenable() && smb_isdisabled())
413 iszfs
= sa_path_is_zfs(path
);
417 if (privileged
== B_FALSE
&& !online
) {
420 (void) printf(dgettext(TEXT_DOMAIN
,
421 "SMB: Cannot share remove "
422 "file system: %s\n"), path
);
423 (void) printf(dgettext(TEXT_DOMAIN
,
424 "SMB: Service needs to be enabled "
425 "by a privileged user\n"));
426 err
= SA_NO_PERMISSION
;
430 sa_free_attr_string(path
);
437 if (privileged
== B_TRUE
&& !online
) {
438 err
= smb_enable_service();
440 (void) printf(dgettext(TEXT_DOMAIN
,
441 "SMB: Unable to enable service\n"));
448 * Don't bother trying to start shares if the service isn't
454 /* Each share can have multiple resources */
455 for (resource
= sa_get_share_resource(share
, NULL
);
457 resource
= sa_get_next_resource(resource
)) {
458 err
= smb_build_shareinfo(share
, resource
, &si
);
460 sa_free_attr_string(path
);
465 err
= smb_share_create(&si
);
469 (void) sa_sharetab_fill_zfs(share
, &sh
, "smb");
470 err
= sa_share_zfs(share
, resource
, (char *)path
, &sh
,
480 (void) sa_update_sharetab(share
, "smb");
482 sa_free_attr_string(path
);
484 return (err
== NERR_DuplicateShare
? 0 : err
);
488 * This is the share for CIFS all shares have resource names.
489 * Enable tells the smb server to update its hash. If it fails
490 * because smb server is down, we just ignore as smb server loads
491 * the resources from sharemanager at startup.
495 smb_enable_resource(sa_resource_t resource
)
503 share
= sa_get_resource_parent(resource
);
505 return (SA_NO_SUCH_PATH
);
508 * If administratively disabled, don't try to start anything.
510 isonline
= smb_isonline();
511 if (!isonline
&& !smb_isautoenable() && smb_isdisabled())
515 (void) smb_enable_service();
521 if ((ret
= smb_build_shareinfo(share
, resource
, &si
)) != SA_OK
)
525 * Attempt to add the share. Any error that occurs if it was
526 * online is an error but don't count NERR_DuplicateName if
527 * smb/server had to be brought online since bringing the
528 * service up will enable the share that was just added prior
529 * to the attempt to enable.
531 err
= smb_share_create(&si
);
532 if (err
== NERR_Success
|| !(!isonline
&& err
== NERR_DuplicateName
))
533 (void) sa_update_sharetab(share
, "smb");
535 return (SA_NOT_SHARED
);
541 * Remove it from smb server hash.
544 smb_disable_resource(sa_resource_t resource
)
550 rname
= sa_get_resource_attr(resource
, "name");
552 return (SA_NO_SUCH_RESOURCE
);
554 if (smb_isonline()) {
555 res
= smb_share_delete(rname
);
556 if (res
!= NERR_Success
&&
557 res
!= NERR_NetNameNotFound
) {
558 sa_free_attr_string(rname
);
559 return (SA_CONFIG_ERR
);
563 sa_free_attr_string(rname
);
565 share
= sa_get_resource_parent(resource
);
567 rname
= sa_get_share_attr(share
, "path");
571 handle
= sa_find_group_handle((sa_group_t
)resource
);
572 (void) sa_delete_sharetab(handle
, rname
, "smb");
573 sa_free_attr_string(rname
);
577 * Always return OK as smb/server may be down and
578 * Shares will be picked up when loaded.
584 * smb_share_changed(sa_share_t share)
586 * The specified share has changed.
589 smb_share_changed(sa_share_t share
)
592 sa_resource_t resource
;
597 /* get the path since it is important in several places */
598 path
= sa_get_share_attr(share
, "path");
600 return (SA_NO_SUCH_PATH
);
602 for (resource
= sa_get_share_resource(share
, NULL
);
604 resource
= sa_get_next_resource(resource
))
605 (void) smb_resource_changed(resource
);
607 sa_free_attr_string(path
);
613 * smb_resource_changed(sa_resource_t resource)
615 * The specified resource has changed.
618 smb_resource_changed(sa_resource_t resource
)
627 if ((share
= sa_get_resource_parent(resource
)) == NULL
)
628 return (SA_CONFIG_ERR
);
630 if ((res
= smb_build_shareinfo(share
, resource
, &si
)) != SA_OK
)
633 res
= smb_share_modify(&si
);
635 if (res
!= NERR_Success
)
636 return (SA_CONFIG_ERR
);
638 return (smb_enable_service());
642 * smb_disable_share(sa_share_t share, char *path)
644 * Unshare the specified share. Note that "path" is the same
645 * path as what is in the "share" object. It is passed in to avoid an
646 * additional lookup. A missing "path" value makes this a no-op
650 smb_disable_share(sa_share_t share
, char *path
)
653 sa_resource_t resource
;
659 boolean_t first
= B_TRUE
; /* work around sharetab issue */
665 * If the share is in a ZFS group we need to handle it
666 * differently. Just being on a ZFS file system isn't
667 * enough since we may be in a legacy share case.
669 parent
= sa_get_parent_group(share
);
670 iszfs
= sa_group_is_zfs(parent
);
675 for (resource
= sa_get_share_resource(share
, NULL
);
677 resource
= sa_get_next_resource(resource
)) {
678 rname
= sa_get_resource_attr(resource
, "name");
683 err
= smb_share_delete(rname
);
685 case NERR_NetNameNotFound
:
696 (void) sa_sharetab_fill_zfs(share
, &sh
, "smb");
697 err
= sa_share_zfs(share
, resource
, (char *)path
, &sh
,
698 rname
, ZFS_UNSHARE_SMB
);
707 * If we are no longer the first case,
708 * we don't care about the sa_share_zfs
709 * err if it is -1. This works around
710 * a problem in sharefs and should be
711 * removed when sharefs supports
712 * multiple entries per path.
729 sa_free_attr_string(rname
);
733 handle
= sa_find_group_handle((sa_group_t
)share
);
735 (void) sa_delete_sharetab(handle
, path
, "smb");
743 * smb_validate_property(handle, property, parent)
745 * Check that the property has a legitimate value for its type.
746 * Handle isn't currently used but may need to be in the future.
751 smb_validate_property(sa_handle_t handle
, sa_property_t property
,
752 sa_optionset_t parent
)
757 sa_group_t parent_group
;
761 propname
= sa_get_property_attr(property
, "type");
763 if ((optindex
= findopt(propname
)) < 0)
764 ret
= SA_NO_SUCH_PROP
;
766 /* need to validate value range here as well */
768 parent_group
= sa_get_parent_group((sa_share_t
)parent
);
769 if (optdefs
[optindex
].share
&& !sa_is_share(parent_group
))
770 ret
= SA_PROP_SHARE_ONLY
;
773 if (propname
!= NULL
)
774 sa_free_attr_string(propname
);
778 value
= sa_get_property_attr(property
, "value");
780 /* first basic type checking */
781 switch (optdefs
[optindex
].type
) {
782 case OPT_TYPE_NUMBER
:
783 /* check that the value is all digits */
784 if (!is_a_number(value
))
787 case OPT_TYPE_BOOLEAN
:
788 ret
= true_false_validator(0, value
);
792 * Make sure no invalid characters
794 if (!validresource(value
))
797 case OPT_TYPE_STRING
:
798 /* whatever is here should be ok */
801 if (!validcsc(value
))
804 case OPT_TYPE_ACCLIST
: {
808 * access list handling. Should eventually
809 * validate that all the values make sense.
810 * Also, ro and rw may have cross value
815 if (strcmp(propname
, SHOPT_RO
) == 0)
817 else if (strcmp(propname
, SHOPT_RW
) == 0)
824 /* compare rw(ro) with ro(rw) */
825 oprop
= sa_get_property(parent
, other
);
833 ovalue
= sa_get_property_attr(oprop
, "value");
834 if (ovalue
!= NULL
) {
835 ret
= check_rorw(value
, ovalue
);
836 sa_free_attr_string(ovalue
);
846 sa_free_attr_string(value
);
847 if (ret
== SA_OK
&& optdefs
[optindex
].check
!= NULL
)
848 /* do the property specific check */
849 ret
= optdefs
[optindex
].check(property
);
851 if (propname
!= NULL
)
852 sa_free_attr_string(propname
);
857 * Protocol management functions
859 * properties defined in the default files are defined in
860 * proto_option_defs for parsing and validation.
863 struct smb_proto_option_defs
{
866 int32_t maxval
; /* In case of length of string this should be max */
867 int (*validator
)(int, char *);
869 } smb_proto_options
[] = {
870 { SMB_CI_SYS_CMNT
, 0, MAX_VALUE_BUFLEN
,
871 string_length_check_validator
, SMB_REFRESH_REFRESH
},
872 { SMB_CI_MAX_WORKERS
, SMB_PI_MAX_WORKERS_MIN
, SMB_PI_MAX_WORKERS_MAX
,
873 range_check_validator
, SMB_REFRESH_REFRESH
},
874 { SMB_CI_NETBIOS_ENABLE
, 0, 0, true_false_validator
,
875 SMB_REFRESH_REFRESH
},
876 { SMB_CI_NBSCOPE
, 0, MAX_VALUE_BUFLEN
,
877 string_length_check_validator
, 0 },
878 { SMB_CI_LM_LEVEL
, 2, 5, range_check_validator
, 0 },
879 { SMB_CI_KEEPALIVE
, 20, 5400, range_check_validator_zero_ok
,
880 SMB_REFRESH_REFRESH
},
881 { SMB_CI_WINS_SRV1
, 0, MAX_VALUE_BUFLEN
,
882 ipv4_validator
, SMB_REFRESH_REFRESH
},
883 { SMB_CI_WINS_SRV2
, 0, MAX_VALUE_BUFLEN
,
884 ipv4_validator
, SMB_REFRESH_REFRESH
},
885 { SMB_CI_WINS_EXCL
, 0, MAX_VALUE_BUFLEN
,
886 interface_validator
, SMB_REFRESH_REFRESH
},
887 { SMB_CI_SIGNING_ENABLE
, 0, 0, true_false_validator
,
888 SMB_REFRESH_REFRESH
},
889 { SMB_CI_SIGNING_REQD
, 0, 0, true_false_validator
,
890 SMB_REFRESH_REFRESH
},
891 { SMB_CI_RESTRICT_ANON
, 0, 0, true_false_validator
,
892 SMB_REFRESH_REFRESH
},
893 { SMB_CI_DOMAIN_SRV
, 0, MAX_VALUE_BUFLEN
,
894 hostname_validator
, SMB_REFRESH_REFRESH
},
895 { SMB_CI_ADS_SITE
, 0, MAX_VALUE_BUFLEN
,
896 string_length_check_validator
, SMB_REFRESH_REFRESH
},
897 { SMB_CI_DYNDNS_ENABLE
, 0, 0, true_false_validator
, 0 },
898 { SMB_CI_AUTOHOME_MAP
, 0, MAX_VALUE_BUFLEN
, path_validator
, 0 },
899 { SMB_CI_IPV6_ENABLE
, 0, 0, true_false_validator
,
900 SMB_REFRESH_REFRESH
},
901 { SMB_CI_PRINT_ENABLE
, 0, 0, print_enable_validator
,
902 SMB_REFRESH_REFRESH
},
903 { SMB_CI_TRAVERSE_MOUNTS
, 0, 0, true_false_validator
,
904 SMB_REFRESH_REFRESH
},
905 { SMB_CI_MAP
, 0, MAX_VALUE_BUFLEN
, cmd_validator
, SMB_REFRESH_REFRESH
},
906 { SMB_CI_UNMAP
, 0, MAX_VALUE_BUFLEN
, cmd_validator
,
907 SMB_REFRESH_REFRESH
},
908 { SMB_CI_DISPOSITION
, 0, MAX_VALUE_BUFLEN
,
909 disposition_validator
, SMB_REFRESH_REFRESH
},
910 { SMB_CI_MAX_PROTOCOL
, 0, MAX_VALUE_BUFLEN
, max_protocol_validator
,
911 SMB_REFRESH_REFRESH
},
914 #define SMB_OPT_NUM \
915 (sizeof (smb_proto_options) / sizeof (smb_proto_options[0]))
918 * Check the range of value as int range.
921 range_check_validator(int index
, char *value
)
925 if (!is_a_number(value
)) {
929 val
= strtoul(value
, NULL
, 0);
930 if (val
< smb_proto_options
[index
].minval
||
931 val
> smb_proto_options
[index
].maxval
)
938 * Check the range of value as int range.
941 range_check_validator_zero_ok(int index
, char *value
)
945 if (!is_a_number(value
)) {
949 val
= strtoul(value
, NULL
, 0);
953 if (val
< smb_proto_options
[index
].minval
||
954 val
> smb_proto_options
[index
].maxval
)
962 * Check the length of the string
965 string_length_check_validator(int index
, char *value
)
970 return (SA_BAD_VALUE
);
971 if (strlen(value
) > smb_proto_options
[index
].maxval
)
981 true_false_validator(int index
, char *value
)
984 return (SA_BAD_VALUE
);
985 if ((strcasecmp(value
, "true") == 0) ||
986 (strcasecmp(value
, "false") == 0))
988 return (SA_BAD_VALUE
);
992 * If printing support is compiled in, this is the same as:
993 * true_false_validator. Otherwise, only allow false.
997 print_enable_validator(int index
, char *value
)
1000 return (SA_BAD_VALUE
);
1002 #ifdef CONFIG_SMB_PRINTING
1003 if (strcasecmp(value
, "true") == 0)
1006 if (strcasecmp(value
, "false") == 0)
1009 return (SA_BAD_VALUE
);
1013 * Check IP v4 address.
1017 ipv4_validator(int index
, char *value
)
1024 if (strlen(value
) == 0)
1027 if (inet_pton(AF_INET
, value
, (void *)sbytes
) != 1)
1028 return (SA_BAD_VALUE
);
1034 * Check that the specified name is an IP address (v4 or v6) or a hostname.
1035 * Per RFC 1035 and 1123, names may contain alphanumeric characters, hyphens
1036 * and dots. The first and last character of a label must be alphanumeric.
1037 * Interior characters may be alphanumeric or hypens.
1039 * Domain names should not contain underscores but we allow them because
1040 * Windows names are often in non-compliance with this rule.
1044 hostname_validator(int index
, char *value
)
1046 char sbytes
[INET6_ADDRSTRLEN
];
1047 boolean_t new_label
= B_TRUE
;
1049 char label_terminator
;
1055 if ((len
= strlen(value
)) == 0)
1058 if (inet_pton(AF_INET
, value
, (void *)sbytes
) == 1)
1061 if (inet_pton(AF_INET6
, value
, (void *)sbytes
) == 1)
1064 if (len
>= MAXHOSTNAMELEN
)
1065 return (SA_BAD_VALUE
);
1067 if (strspn(value
, "0123456789.") == len
)
1068 return (SA_BAD_VALUE
);
1070 label_terminator
= *value
;
1072 for (p
= value
; *p
!= '\0'; ++p
) {
1075 return (SA_BAD_VALUE
);
1076 new_label
= B_FALSE
;
1077 label_terminator
= *p
;
1082 if (!isalnum(label_terminator
))
1083 return (SA_BAD_VALUE
);
1085 label_terminator
= *p
;
1089 label_terminator
= *p
;
1091 if (isalnum(*p
) || *p
== '-' || *p
== '_')
1094 return (SA_BAD_VALUE
);
1097 if (!isalnum(label_terminator
))
1098 return (SA_BAD_VALUE
);
1104 * Call back function for dlpi_walk.
1105 * Returns TRUE if interface name exists on the host.
1108 smb_get_interface(const char *ifname
, void *arg
)
1110 smb_hostifs_walker_t
*iterp
= arg
;
1112 iterp
->hiw_matchfound
= (strcmp(ifname
, iterp
->hiw_ifname
) == 0);
1114 return (iterp
->hiw_matchfound
);
1118 * Checks to see if the input interface exists on the host.
1119 * Returns B_TRUE if the match is found, B_FALSE otherwise.
1122 smb_validate_interface(const char *ifname
)
1124 smb_hostifs_walker_t iter
;
1126 if ((ifname
== NULL
) || (*ifname
== '\0'))
1129 iter
.hiw_ifname
= ifname
;
1130 iter
.hiw_matchfound
= B_FALSE
;
1131 dlpi_walk(smb_get_interface
, &iter
, 0);
1133 return (iter
.hiw_matchfound
);
1137 * Check valid interfaces. Interface names value can be NULL or empty.
1138 * Returns SA_BAD_VALUE if interface cannot be found on the host.
1142 interface_validator(int index
, char *value
)
1146 char *ifname
, *tmp
, *p
;
1148 if (value
== NULL
|| *value
== '\0')
1151 if (strlen(value
) > MAX_VALUE_BUFLEN
)
1152 return (SA_BAD_VALUE
);
1154 if ((p
= strdup(value
)) == NULL
)
1155 return (SA_NO_MEMORY
);
1158 while ((ifname
= strsep(&tmp
, ",")) != NULL
) {
1159 if (*ifname
== '\0') {
1164 if (!smb_validate_interface(ifname
)) {
1165 if (inet_pton(AF_INET
, ifname
, (void *)buf
) == 0) {
1181 path_validator(int index
, char *path
)
1187 return (SA_BAD_VALUE
);
1189 fd
= open(path
, O_RDONLY
);
1191 return (SA_BAD_VALUE
);
1193 status
= fstat(fd
, &buffer
);
1197 return (SA_BAD_VALUE
);
1199 if (buffer
.st_mode
& S_IFDIR
)
1201 return (SA_BAD_VALUE
);
1205 * the protoset holds the defined options so we don't have to read
1206 * them multiple times
1208 static sa_protocol_properties_t protoset
;
1211 findprotoopt(char *name
)
1216 for (i
= 0; i
< SMB_OPT_NUM
; i
++) {
1217 sc_name
= smb_config_getname(smb_proto_options
[i
].smb_index
);
1218 if (strcasecmp(sc_name
, name
) == 0)
1226 * smb_load_proto_properties()
1228 * read the smb config values from SMF.
1232 smb_load_proto_properties()
1235 char value
[MAX_VALUE_BUFLEN
];
1241 protoset
= sa_create_protocol_properties(SMB_PROTOCOL_NAME
);
1242 if (protoset
== NULL
)
1243 return (SA_NO_MEMORY
);
1245 for (index
= 0; index
< SMB_OPT_NUM
&& ret
== SA_OK
; index
++) {
1246 rc
= smb_config_get(smb_proto_options
[index
].smb_index
,
1247 value
, sizeof (value
));
1248 if (rc
!= SMBD_SMF_OK
)
1250 name
= smb_config_getname(smb_proto_options
[index
].smb_index
);
1251 prop
= sa_create_property(name
, value
);
1253 ret
= sa_add_protocol_property(protoset
, prop
);
1263 * Initialize the smb plugin.
1267 smb_share_init(void)
1269 if (sa_plugin_ops
.sa_init
!= smb_share_init
)
1270 return (SA_SYSTEM_ERR
);
1272 smb_share_door_clnt_init();
1273 return (smb_load_proto_properties());
1281 smb_share_fini(void)
1283 xmlFreeNode(protoset
);
1286 smb_share_door_clnt_fini();
1290 * smb_get_proto_set()
1292 * Return an optionset with all the protocol specific properties in
1295 static sa_protocol_properties_t
1296 smb_get_proto_set(void)
1302 * smb_enable_dependencies()
1304 * SMBD_DEFAULT_INSTANCE_FMRI may have some dependencies that aren't
1305 * enabled. This will attempt to enable all of them.
1308 smb_enable_dependencies(const char *fmri
)
1310 scf_handle_t
*handle
;
1311 scf_service_t
*service
;
1312 scf_instance_t
*inst
= NULL
;
1314 scf_property_t
*prop
;
1316 scf_propertygroup_t
*pg
;
1318 char type
[SCFTYPE_LEN
];
1324 * Get all required handles and storage.
1326 handle
= scf_handle_create(SCF_VERSION
);
1330 if (scf_handle_bind(handle
) != 0) {
1331 scf_handle_destroy(handle
);
1335 maxlen
= scf_limit(SCF_LIMIT_MAX_VALUE_LENGTH
);
1336 if (maxlen
== (ssize_t
)-1)
1337 maxlen
= MAXPATHLEN
;
1339 dependency
= malloc(maxlen
);
1341 service
= scf_service_create(handle
);
1343 iter
= scf_iter_create(handle
);
1345 pg
= scf_pg_create(handle
);
1347 prop
= scf_property_create(handle
);
1349 value
= scf_value_create(handle
);
1351 scope
= scf_scope_create(handle
);
1353 if (service
== NULL
|| iter
== NULL
|| pg
== NULL
|| prop
== NULL
||
1354 value
== NULL
|| scope
== NULL
|| dependency
== NULL
)
1358 * We passed in the FMRI for the default instance but for
1359 * some things we need the simple form so construct it. Since
1360 * we reuse the storage that dependency points to, we need to
1361 * use the servname early.
1363 (void) snprintf(dependency
, maxlen
, "%s", fmri
+ sizeof ("svc:"));
1364 servname
= strrchr(dependency
, ':');
1365 if (servname
== NULL
)
1368 servname
= dependency
;
1371 * Setup to iterate over the service property groups, only
1372 * looking at those that are "dependency" types. The "entity"
1373 * property will have the FMRI of the service we are dependent
1376 if (scf_handle_get_scope(handle
, SCF_SCOPE_LOCAL
, scope
) != 0)
1379 if (scf_scope_get_service(scope
, servname
, service
) != 0)
1382 if (scf_iter_service_pgs(iter
, service
) != 0)
1385 while (scf_iter_next_pg(iter
, pg
) > 0) {
1388 * Have a property group for the service. See if it is
1389 * a dependency pg and only do operations on those.
1391 if (scf_pg_get_type(pg
, type
, SCFTYPE_LEN
) <= 0)
1394 if (strncmp(type
, SCF_GROUP_DEPENDENCY
, SCFTYPE_LEN
) != 0)
1397 * Have a dependency. Attempt to enable it.
1399 if (scf_pg_get_property(pg
, SCF_PROPERTY_ENTITIES
, prop
) != 0)
1402 if (scf_property_get_value(prop
, value
) != 0)
1407 if (scf_value_get_as_string(value
, dependency
, maxlen
) > 0) {
1408 services
[0] = dependency
;
1409 _check_services(services
);
1416 scf_value_destroy(value
);
1418 scf_property_destroy(prop
);
1422 scf_iter_destroy(iter
);
1424 scf_scope_destroy(scope
);
1426 scf_instance_destroy(inst
);
1427 if (service
!= NULL
)
1428 scf_service_destroy(service
);
1430 (void) scf_handle_unbind(handle
);
1431 scf_handle_destroy(handle
);
1435 * How long to wait for service to come online
1437 #define WAIT_FOR_SERVICE 15
1440 * smb_enable_service()
1444 smb_enable_service(void)
1448 char *service
[] = { SMBD_DEFAULT_INSTANCE_FMRI
, NULL
};
1450 if (!smb_isonline()) {
1452 * Attempt to start the idmap, and other dependent
1453 * services, first. If it fails, the SMB service will
1454 * ultimately fail so we use that as the error. If we
1455 * don't try to enable idmap, smb won't start the
1456 * first time unless the admin has done it
1457 * manually. The service could be administratively
1458 * disabled so we won't always get started.
1460 smb_enable_dependencies(SMBD_DEFAULT_INSTANCE_FMRI
);
1461 _check_services(service
);
1463 /* Wait for service to come online */
1464 for (i
= 0; i
< WAIT_FOR_SERVICE
; i
++) {
1465 if (smb_isonline()) {
1468 } else if (smb_ismaint()) {
1469 /* maintenance requires help */
1470 ret
= SA_SYSTEM_ERR
;
1473 /* try another time */
1483 * smb_validate_proto_prop(index, name, value)
1485 * Verify that the property specified by name can take the new
1486 * value. This is a sanity check to prevent bad values getting into
1487 * the default files.
1490 smb_validate_proto_prop(int index
, char *name
, char *value
)
1492 if ((name
== NULL
) || (index
< 0))
1493 return (SA_BAD_VALUE
);
1495 if (smb_proto_options
[index
].validator
== NULL
)
1498 if (smb_proto_options
[index
].validator(index
, value
) == SA_OK
)
1500 return (SA_BAD_VALUE
);
1504 * smb_set_proto_prop(prop)
1506 * check that prop is valid.
1510 smb_set_proto_prop(sa_property_t prop
)
1516 struct smb_proto_option_defs
*opt
;
1518 name
= sa_get_property_attr(prop
, "type");
1519 value
= sa_get_property_attr(prop
, "value");
1520 if (name
!= NULL
&& value
!= NULL
) {
1521 index
= findprotoopt(name
);
1523 /* should test for valid value */
1524 ret
= smb_validate_proto_prop(index
, name
, value
);
1526 opt
= &smb_proto_options
[index
];
1529 (void) smb_config_set(opt
->smb_index
, value
);
1531 * Specialized refresh mechanisms can
1532 * be flagged in the proto_options and
1535 if (opt
->refresh
& SMB_REFRESH_REFRESH
)
1536 (void) smf_refresh_instance(
1537 SMBD_DEFAULT_INSTANCE_FMRI
);
1538 else if (opt
->refresh
& SMB_REFRESH_RESTART
)
1539 (void) smf_restart_instance(
1540 SMBD_DEFAULT_INSTANCE_FMRI
);
1546 sa_free_attr_string(name
);
1548 sa_free_attr_string(value
);
1556 * What is the current status of the smbd? We use the SMF state here.
1557 * Caller must free the returned value.
1561 smb_get_status(void)
1563 return (smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI
));
1567 * This protocol plugin require resource names
1570 smb_share_features(void)
1572 return (SA_FEATURE_RESOURCE
| SA_FEATURE_ALLOWSUBDIRS
|
1573 SA_FEATURE_ALLOWPARDIRS
| SA_FEATURE_SERVER
);
1577 * This should be used to convert smb_share_t to sa_resource_t
1578 * Should only be needed to build transient shares/resources to be
1579 * supplied to sharemgr to display.
1582 smb_add_transient(sa_handle_t handle
, smb_share_t
*si
)
1587 sa_resource_t resource
;
1592 return (SA_INVALID_NAME
);
1594 if ((share
= sa_find_share(handle
, si
->shr_path
)) == NULL
) {
1595 if ((group
= smb_get_defaultgrp(handle
)) == NULL
)
1596 return (SA_NO_SUCH_GROUP
);
1598 share
= sa_get_share(group
, si
->shr_path
);
1599 if (share
== NULL
) {
1600 share
= sa_add_share(group
, si
->shr_path
,
1601 SA_SHARE_TRANSIENT
, &err
);
1603 return (SA_NO_SUCH_PATH
);
1608 * Now handle the resource. Make sure that the resource is
1609 * transient and added to the share.
1611 resource
= sa_get_share_resource(share
, si
->shr_name
);
1612 if (resource
== NULL
) {
1613 resource
= sa_add_resource(share
,
1614 si
->shr_name
, SA_SHARE_TRANSIENT
, &err
);
1615 if (resource
== NULL
)
1616 return (SA_NO_SUCH_RESOURCE
);
1619 if (si
->shr_cmnt
[0] != '\0')
1620 (void) sa_set_resource_description(resource
, si
->shr_cmnt
);
1622 if (si
->shr_container
[0] != '\0')
1623 (void) sa_set_resource_attr(resource
, SHOPT_AD_CONTAINER
,
1626 if (nvlist_alloc(&nvl
, NV_UNIQUE_NAME
, 0) != 0)
1627 return (SA_NO_MEMORY
);
1629 if ((opt
= smb_csc_name(si
)) != NULL
)
1630 err
|= nvlist_add_string(nvl
, SHOPT_CSC
, opt
);
1632 opt
= (si
->shr_flags
& SMB_SHRF_ABE
) ? "true" : "false";
1633 err
|= nvlist_add_string(nvl
, SHOPT_ABE
, opt
);
1635 if ((si
->shr_flags
& SMB_SHRF_AUTOHOME
) == 0) {
1636 opt
= (si
->shr_flags
& SMB_SHRF_GUEST_OK
) ? "true" : "false";
1637 err
|= nvlist_add_string(nvl
, SHOPT_GUEST
, opt
);
1640 if (si
->shr_access_ro
[0] != '\0')
1641 err
|= nvlist_add_string(nvl
, SHOPT_RO
, si
->shr_access_ro
);
1643 if (si
->shr_access_rw
[0] != '\0')
1644 err
|= nvlist_add_string(nvl
, SHOPT_RW
, si
->shr_access_rw
);
1646 if (si
->shr_access_none
[0] != '\0')
1647 err
|= nvlist_add_string(nvl
, SHOPT_NONE
, si
->shr_access_none
);
1651 return (SA_CONFIG_ERR
);
1654 err
= smb_update_optionset_props(handle
, resource
, nvl
);
1661 * Return smb transient shares.
1664 smb_list_transient(sa_handle_t handle
)
1670 if (smb_share_count() <= 0)
1674 while (smb_share_list(offset
, &list
) == NERR_Success
) {
1675 if (list
.sl_cnt
== 0)
1678 for (i
= 0; i
< list
.sl_cnt
; i
++) {
1679 res
= smb_add_transient(handle
, &(list
.sl_shares
[i
]));
1683 offset
+= list
.sl_cnt
;
1690 * fix_resource_name(share, name, prefix)
1692 * Construct a name where the ZFS dataset has the prefix replaced with "name".
1695 fix_resource_name(sa_share_t share
, char *name
, char *prefix
)
1697 char buf
[SA_MAX_RESOURCE_NAME
+ 1];
1699 size_t bufsz
= SA_MAX_RESOURCE_NAME
+ 1;
1703 return (strdup(name
));
1705 dataset
= sa_get_share_attr(share
, "dataset");
1706 if (dataset
== NULL
)
1707 return (strdup(name
));
1709 (void) strlcpy(buf
, name
, bufsz
);
1710 prelen
= strlen(prefix
);
1712 if (strncmp(dataset
, prefix
, prelen
) == 0)
1713 (void) strlcat(buf
, dataset
+ prelen
, bufsz
);
1715 sa_free_attr_string(dataset
);
1716 sa_fix_resource_name(buf
);
1717 return (strdup(buf
));
1721 * smb_parse_optstring(group, options)
1723 * parse a compact option string into individual options. This allows
1724 * ZFS sharesmb and sharemgr "share" command to work. group can be a
1725 * group, a share or a resource.
1728 smb_parse_optstring(sa_group_t group
, char *options
)
1734 sa_optionset_t optionset
;
1735 sa_group_t parent
= NULL
;
1736 sa_resource_t resource
= NULL
;
1739 int need_optionset
= 0;
1744 * In order to not attempt to change ZFS properties unless
1745 * absolutely necessary, we never do it in the legacy parsing
1746 * so we need to keep track of this.
1748 if (sa_is_share(group
)) {
1751 parent
= sa_get_parent_group(group
);
1752 if (parent
!= NULL
) {
1753 zfs
= sa_get_group_attr(parent
, "zfs");
1755 sa_free_attr_string(zfs
);
1760 iszfs
= sa_group_is_zfs(group
);
1762 * If a ZFS group, then we need to see if a resource
1763 * name is being set. If so, bail with
1764 * SA_PROP_SHARE_ONLY, so we come back in with a share
1765 * instead of a group.
1768 strncmp(options
, "name=", sizeof ("name=") - 1) == 0 ||
1769 strstr(options
, ",name=") != NULL
) {
1770 return (SA_PROP_SHARE_ONLY
);
1774 /* do we have an existing optionset? */
1775 optionset
= sa_get_optionset(group
, "smb");
1776 if (optionset
== NULL
) {
1777 /* didn't find existing optionset so create one */
1778 optionset
= sa_create_optionset(group
, "smb");
1779 if (optionset
== NULL
)
1780 return (SA_NO_MEMORY
);
1783 * If an optionset already exists, we've come through
1784 * twice so ignore the second time.
1789 /* We need a copy of options for the next part. */
1790 dup
= strdup(options
);
1792 return (SA_NO_MEMORY
);
1795 * SMB properties are straightforward and are strings,
1796 * integers or booleans. Properties are separated by
1797 * commas. It will be necessary to parse quotes due to some
1798 * strings not having a restricted characters set.
1800 * Note that names will create a resource. For now, if there
1801 * is a set of properties "before" the first name="", those
1802 * properties will be placed on the group.
1804 persist
= sa_is_persistent(group
);
1808 while (token
!= NULL
&& ret
== SA_OK
) {
1810 token
= strtok_r(base
, ",", &lasts
);
1812 if (token
!= NULL
) {
1815 * All SMB properties have values so there
1816 * MUST be an '=' character. If it doesn't,
1817 * it is a syntax error.
1819 value
= strchr(token
, '=');
1820 if (value
!= NULL
) {
1823 ret
= SA_SYNTAX_ERR
;
1827 * We may need to handle a "name" property
1828 * that is a ZFS imposed resource name. Each
1829 * name would trigger getting a new "resource"
1830 * to put properties on. For now, assume no
1831 * "name" property for special handling.
1834 if (strcmp(token
, SHOPT_NAME
) == 0) {
1838 * We have a name, so now work on the
1839 * resource level. We have a "share"
1840 * in "group" due to the caller having
1841 * added it. If we are called with a
1842 * group, the check for group/share
1843 * at the beginning of this function
1844 * will bail out the parse if there is a
1845 * "name" but no share.
1848 ret
= SA_SYNTAX_ERR
;
1852 * Make sure the parent group has the
1853 * "prefix" property since we will
1854 * need to use this for constructing
1855 * inherited name= values.
1857 prefix
= sa_get_group_attr(parent
, "prefix");
1858 if (prefix
== NULL
) {
1859 prefix
= sa_get_group_attr(parent
,
1861 if (prefix
!= NULL
) {
1862 (void) sa_set_group_attr(parent
,
1866 name
= fix_resource_name((sa_share_t
)group
,
1869 resource
= sa_add_resource(
1870 (sa_share_t
)group
, name
,
1871 SA_SHARE_TRANSIENT
, &ret
);
1872 sa_free_attr_string(name
);
1877 sa_free_attr_string(prefix
);
1879 /* A resource level optionset is needed */
1882 if (resource
== NULL
) {
1889 if (iszfs
&& strcmp(token
, SHOPT_DESCRIPTION
) == 0) {
1890 if (resource
== NULL
)
1891 (void) sa_set_share_description(
1892 (sa_share_t
)group
, value
);
1894 (void) sa_set_resource_description(
1899 if (need_optionset
) {
1900 optionset
= sa_create_optionset(resource
,
1905 prop
= sa_create_property(token
, value
);
1909 ret
= sa_add_property(optionset
, prop
);
1913 ret
= sa_commit_properties(optionset
, !persist
);
1921 * smb_sprint_option(rbuff, rbuffsize, incr, prop, sep)
1923 * provides a mechanism to format SMB properties into legacy output
1924 * format. If the buffer would overflow, it is reallocated and grown
1925 * as appropriate. Special cases of converting internal form of values
1926 * to those used by "share" are done. this function does one property
1931 smb_sprint_option(char **rbuff
, size_t *rbuffsize
, size_t incr
,
1932 sa_property_t prop
, int sep
)
1937 char *buff
= *rbuff
;
1938 size_t buffsize
= *rbuffsize
;
1940 name
= sa_get_property_attr(prop
, "type");
1941 value
= sa_get_property_attr(prop
, "value");
1943 curlen
= strlen(buff
);
1948 len
= strlen(name
) + sep
;
1951 * A future RFE would be to replace this with more
1952 * generic code and to possibly handle more types.
1954 * For now, everything else is treated as a string. If
1955 * we get any properties that aren't exactly
1956 * name/value pairs, we may need to
1957 * interpret/transform.
1960 len
+= 1 + strlen(value
);
1962 while (buffsize
<= (curlen
+ len
)) {
1963 /* need more room */
1965 buff
= realloc(buff
, buffsize
);
1967 *rbuffsize
= buffsize
;
1969 /* realloc failed so free everything */
1976 (void) snprintf(buff
+ curlen
, buffsize
- curlen
,
1977 "%s%s=%s", sep
? "," : "",
1978 name
, value
!= NULL
? value
: "\"\"");
1983 sa_free_attr_string(name
);
1985 sa_free_attr_string(value
);
1989 * smb_format_resource_options(resource, hier)
1991 * format all the options on the group into a flattened option
1992 * string. If hier is non-zero, walk up the tree to get inherited
1997 smb_format_options(sa_group_t group
, int hier
)
1999 sa_optionset_t options
= NULL
;
2006 buff
= malloc(OPT_CHUNK
);
2011 buffsize
= OPT_CHUNK
;
2014 * We may have a an optionset relative to this item. format
2015 * these if we find them and then add any security definitions.
2018 options
= sa_get_derived_optionset(group
, "smb", hier
);
2021 * do the default set first but skip any option that is also
2022 * in the protocol specific optionset.
2024 if (options
!= NULL
) {
2025 for (prop
= sa_get_property(options
, NULL
);
2026 prop
!= NULL
; prop
= sa_get_next_property(prop
)) {
2028 * use this one since we skipped any
2029 * of these that were also in
2032 smb_sprint_option(&buff
, &buffsize
, OPT_CHUNK
,
2036 * buff could become NULL if there
2037 * isn't enough memory for
2038 * smb_sprint_option to realloc()
2039 * as necessary. We can't really
2040 * do anything about it at this
2041 * point so we return NULL. The
2042 * caller should handle the
2045 if (options
!= NULL
)
2046 sa_free_derived_optionset(
2054 if (options
!= NULL
)
2055 sa_free_derived_optionset(options
);
2060 * smb_rename_resource(resource, newname)
2062 * Change the current exported name of the resource to newname.
2066 smb_rename_resource(sa_handle_t handle
, sa_resource_t resource
, char *newname
)
2072 if (!smb_isonline())
2075 oldname
= sa_get_resource_attr(resource
, "name");
2076 if (oldname
== NULL
)
2077 return (SA_NO_SUCH_RESOURCE
);
2079 err
= smb_share_rename(oldname
, newname
);
2081 sa_free_attr_string(oldname
);
2083 /* improve error values somewhat */
2087 case NERR_InternalError
:
2088 ret
= SA_SYSTEM_ERR
;
2090 case NERR_DuplicateShare
:
2091 ret
= SA_DUPLICATE_NAME
;
2094 ret
= SA_CONFIG_ERR
;
2102 smb_build_shareinfo(sa_share_t share
, sa_resource_t resource
, smb_share_t
*si
)
2104 sa_optionset_t opts
;
2108 char csc_value
[SMB_CSC_BUFSZ
];
2110 bzero(si
, sizeof (smb_share_t
));
2112 if ((path
= sa_get_share_attr(share
, "path")) == NULL
)
2113 return (SA_NO_SUCH_PATH
);
2115 if ((rname
= sa_get_resource_attr(resource
, "name")) == NULL
) {
2116 sa_free_attr_string(path
);
2117 return (SA_NO_SUCH_RESOURCE
);
2120 (void) strlcpy(si
->shr_path
, path
, sizeof (si
->shr_path
));
2121 (void) strlcpy(si
->shr_name
, rname
, sizeof (si
->shr_name
));
2122 sa_free_attr_string(path
);
2123 sa_free_attr_string(rname
);
2125 val
= sa_get_resource_description(resource
);
2127 val
= sa_get_share_description(share
);
2130 (void) strlcpy(si
->shr_cmnt
, val
, sizeof (si
->shr_cmnt
));
2131 sa_free_share_description(val
);
2134 si
->shr_flags
= (sa_is_persistent(share
))
2135 ? SMB_SHRF_PERM
: SMB_SHRF_TRANS
;
2137 opts
= sa_get_derived_optionset(resource
, SMB_PROTOCOL_NAME
, 1);
2141 if (smb_saprop_getbool(opts
, SHOPT_CATIA
))
2142 si
->shr_flags
|= SMB_SHRF_CATIA
;
2144 if (smb_saprop_getbool(opts
, SHOPT_ABE
))
2145 si
->shr_flags
|= SMB_SHRF_ABE
;
2147 if (smb_saprop_getbool(opts
, SHOPT_GUEST
))
2148 si
->shr_flags
|= SMB_SHRF_GUEST_OK
;
2150 if (smb_saprop_getbool(opts
, SHOPT_DFSROOT
))
2151 si
->shr_flags
|= SMB_SHRF_DFSROOT
;
2153 (void) smb_saprop_getstr(opts
, SHOPT_AD_CONTAINER
, si
->shr_container
,
2154 sizeof (si
->shr_container
));
2156 if (smb_saprop_getstr(opts
, SHOPT_CSC
, csc_value
, sizeof (csc_value
)))
2157 smb_csc_option(csc_value
, si
);
2159 if (smb_saprop_getstr(opts
, SHOPT_RO
, si
->shr_access_ro
,
2160 sizeof (si
->shr_access_ro
)))
2161 si
->shr_flags
|= SMB_SHRF_ACC_RO
;
2163 if (smb_saprop_getstr(opts
, SHOPT_RW
, si
->shr_access_rw
,
2164 sizeof (si
->shr_access_rw
)))
2165 si
->shr_flags
|= SMB_SHRF_ACC_RW
;
2167 if (smb_saprop_getstr(opts
, SHOPT_NONE
, si
->shr_access_none
,
2168 sizeof (si
->shr_access_none
)))
2169 si
->shr_flags
|= SMB_SHRF_ACC_NONE
;
2171 sa_free_derived_optionset(opts
);
2176 * Map a client-side caching (CSC) option to the appropriate share
2177 * flag. Only one option is allowed; an error will be logged if
2178 * multiple options have been specified. We don't need to do anything
2179 * about multiple values here because the SRVSVC will not recognize
2180 * a value containing multiple flags and will return the default value.
2182 * If the option value is not recognized, it will be ignored: invalid
2183 * values will typically be caught and rejected by sharemgr.
2186 smb_csc_option(const char *value
, smb_share_t
*si
)
2188 char buf
[SMB_CSC_BUFSZ
];
2191 for (i
= 0; i
< (sizeof (cscopt
) / sizeof (cscopt
[0])); ++i
) {
2192 if (strcasecmp(value
, cscopt
[i
].value
) == 0) {
2193 si
->shr_flags
|= cscopt
[i
].flag
;
2198 switch (si
->shr_flags
& SMB_SHRF_CSC_MASK
) {
2200 case SMB_SHRF_CSC_DISABLED
:
2201 case SMB_SHRF_CSC_MANUAL
:
2202 case SMB_SHRF_CSC_AUTO
:
2203 case SMB_SHRF_CSC_VDO
:
2209 for (i
= 0; i
< (sizeof (cscopt
) / sizeof (cscopt
[0])); ++i
) {
2210 if (si
->shr_flags
& cscopt
[i
].flag
) {
2211 (void) strlcat(buf
, " ", SMB_CSC_BUFSZ
);
2212 (void) strlcat(buf
, cscopt
[i
].value
,
2217 syslog(LOG_ERR
, "csc option conflict:%s", buf
);
2223 * Return the option name for the first CSC flag (there should be only
2224 * one) encountered in the share flags.
2227 smb_csc_name(const smb_share_t
*si
)
2231 for (i
= 0; i
< (sizeof (cscopt
) / sizeof (cscopt
[0])); ++i
) {
2232 if (si
->shr_flags
& cscopt
[i
].flag
)
2233 return (cscopt
[i
].value
);
2240 * smb_get_defaultgrp
2242 * If default group for CIFS shares (i.e. "smb") exists
2243 * then it will return the group handle, otherwise it will
2244 * create the group and return the handle.
2246 * All the shares created by CIFS clients (this is only possible
2247 * via RPC) will be added to "smb" groups.
2250 smb_get_defaultgrp(sa_handle_t handle
)
2252 sa_group_t group
= NULL
;
2255 group
= sa_get_group(handle
, SMB_DEFAULT_SHARE_GROUP
);
2259 group
= sa_create_group(handle
, SMB_DEFAULT_SHARE_GROUP
, &err
);
2263 if (sa_create_optionset(group
, SMB_DEFAULT_SHARE_GROUP
) == NULL
) {
2264 (void) sa_remove_group(group
);
2272 * Checks to see if the command args are the supported substitution specifier.
2276 cmd_validator(int index
, char *value
)
2278 char cmd
[MAXPATHLEN
];
2280 boolean_t skip_cmdname
;
2282 if (string_length_check_validator(index
, value
) != SA_OK
)
2283 return (SA_BAD_VALUE
);
2288 (void) strlcpy(cmd
, value
, sizeof (cmd
));
2291 skip_cmdname
= B_TRUE
;
2293 if ((v
= strsep(&ptr
, " ")) == NULL
)
2299 skip_cmdname
= B_FALSE
;
2303 if ((strlen(v
) != 2) || *v
!= '%')
2304 return (SA_BAD_VALUE
);
2306 if (strpbrk(v
, SMB_VALID_SUB_CHRS
) == NULL
)
2307 return (SA_BAD_VALUE
);
2310 } while (v
!= NULL
);
2313 * If skip_cmdname is still true then the string contains
2314 * only spaces. Don't allow such a string.
2317 return (SA_BAD_VALUE
);
2324 disposition_validator(int index
, char *value
)
2327 return (SA_BAD_VALUE
);
2332 if ((strcasecmp(value
, SMB_EXEC_DISP_CONTINUE
) == 0) ||
2333 (strcasecmp(value
, SMB_EXEC_DISP_TERMINATE
) == 0))
2336 return (SA_BAD_VALUE
);
2341 max_protocol_validator(int index
, char *value
)
2344 return (SA_BAD_VALUE
);
2349 if (smb_config_check_protocol(value
) == 0)
2352 return (SA_BAD_VALUE
);
2357 * Updates the optionset properties of the share resource.
2358 * The properties are given as a list of name-value pair.
2359 * The name argument should be the optionset property name and the value
2360 * should be a valid value for the specified property.
2362 * When calling this function for permanent shares, the caller must also
2363 * call sa_commit_properties() to commit the changes to SMF.
2366 smb_update_optionset_props(sa_handle_t handle
, sa_resource_t resource
,
2370 sa_optionset_t opts
;
2375 if ((opts
= sa_get_optionset(resource
, SMB_PROTOCOL_NAME
)) == NULL
) {
2376 opts
= sa_create_optionset(resource
, SMB_PROTOCOL_NAME
);
2378 return (SA_CONFIG_ERR
);
2381 cur
= nvlist_next_nvpair(nvl
, NULL
);
2382 while (cur
!= NULL
) {
2383 name
= nvpair_name(cur
);
2384 err
= nvpair_value_string(cur
, &val
);
2385 if ((err
!= 0) || (name
== NULL
) || (val
== NULL
)) {
2386 err
= SA_CONFIG_ERR
;
2391 if ((prop
= sa_get_property(opts
, name
)) == NULL
) {
2392 prop
= sa_create_property(name
, val
);
2394 err
= sa_valid_property(handle
, opts
,
2395 SMB_PROTOCOL_NAME
, prop
);
2397 (void) sa_remove_property(prop
);
2401 err
= sa_add_property(opts
, prop
);
2405 err
= sa_update_property(prop
, val
);
2410 cur
= nvlist_next_nvpair(nvl
, cur
);
2417 smb_saprop_getbool(sa_optionset_t opts
, char *propname
)
2421 boolean_t propval
= B_FALSE
;
2423 prop
= sa_get_property(opts
, propname
);
2424 if ((val
= sa_get_property_attr(prop
, "value")) != NULL
) {
2425 if ((strcasecmp(val
, "true") == 0) || (strcmp(val
, "1") == 0))
2434 smb_saprop_getstr(sa_optionset_t opts
, char *propname
, char *buf
, size_t bufsz
)
2439 prop
= sa_get_property(opts
, propname
);
2440 if ((val
= sa_get_property_attr(prop
, "value")) != NULL
) {
2441 (void) strlcpy(buf
, val
, bufsz
);