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>
43 #include "libshare_impl.h"
47 #include <libscf_priv.h>
49 #include "libshare_smb.h"
50 #include <rpcsvc/daemon_utils.h>
51 #include <smbsrv/smb_share.h>
52 #include <smbsrv/smbinfo.h>
53 #include <smbsrv/libsmb.h>
56 #define SMB_CSC_BUFSZ 64
58 #define SMB_VALID_SUB_CHRS "UDhMLmIiSPu" /* substitution characters */
60 /* internal functions */
61 static int smb_share_init(void);
62 static void smb_share_fini(void);
63 static int smb_enable_share(sa_share_t
);
64 static int smb_share_changed(sa_share_t
);
65 static int smb_resource_changed(sa_resource_t
);
66 static int smb_rename_resource(sa_handle_t
, sa_resource_t
, char *);
67 static int smb_disable_share(sa_share_t share
, char *);
68 static int smb_validate_property(sa_handle_t
, sa_property_t
, sa_optionset_t
);
69 static int smb_set_proto_prop(sa_property_t
);
70 static sa_protocol_properties_t
smb_get_proto_set(void);
71 static char *smb_get_status(void);
72 static int smb_parse_optstring(sa_group_t
, char *);
73 static char *smb_format_options(sa_group_t
, int);
75 static int smb_enable_service(void);
77 static int range_check_validator(int, char *);
78 static int range_check_validator_zero_ok(int, char *);
79 static int string_length_check_validator(int, char *);
80 static int print_enable_validator(int, char *);
81 static int true_false_validator(int, char *);
82 static int ipv4_validator(int, char *);
83 static int hostname_validator(int, char *);
84 static int path_validator(int, char *);
85 static int cmd_validator(int, char *);
86 static int disposition_validator(int, char *);
87 static int max_protocol_validator(int, char *);
89 static int smb_enable_resource(sa_resource_t
);
90 static int smb_disable_resource(sa_resource_t
);
91 static uint64_t smb_share_features(void);
92 static int smb_list_transient(sa_handle_t
);
94 static int smb_build_shareinfo(sa_share_t
, sa_resource_t
, smb_share_t
*);
95 static void smb_csc_option(const char *, smb_share_t
*);
96 static char *smb_csc_name(const smb_share_t
*);
97 static sa_group_t
smb_get_defaultgrp(sa_handle_t
);
98 static int interface_validator(int, char *);
99 static int smb_update_optionset_props(sa_handle_t
, sa_resource_t
, nvlist_t
*);
101 static boolean_t
smb_saprop_getbool(sa_optionset_t
, char *);
102 static boolean_t
smb_saprop_getstr(sa_optionset_t
, char *, char *, size_t);
108 { "disabled", SMB_SHRF_CSC_DISABLED
},
109 { "manual", SMB_SHRF_CSC_MANUAL
},
110 { "auto", SMB_SHRF_CSC_AUTO
},
111 { "vdo", SMB_SHRF_CSC_VDO
}
114 /* size of basic format allocation */
115 #define OPT_CHUNK 1024
117 /* size of string for types - big enough to hold "dependency" */
118 #define SCFTYPE_LEN 32
121 * Indexes of entries in smb_proto_options table.
122 * Changes to smb_proto_options table may require
123 * an update to these values.
125 #define PROTO_OPT_WINS1 6
126 #define PROTO_OPT_WINS_EXCLUDE 8
128 typedef struct smb_hostifs_walker
{
129 const char *hiw_ifname
;
130 boolean_t hiw_matchfound
;
131 } smb_hostifs_walker_t
;
135 * ops vector that provides the protocol specific info and operations
136 * for share management.
139 struct sa_plugin_ops sa_plugin_ops
= {
146 smb_validate_property
,
147 NULL
, /* valid_space */
148 NULL
, /* security_prop */
154 NULL
, /* space_alias */
155 NULL
, /* update_legacy */
156 NULL
, /* delete_legacy */
159 smb_disable_resource
,
162 smb_resource_changed
,
164 NULL
, /* run_command */
165 NULL
, /* command_help */
166 NULL
/* delete_proto_section */
169 struct option_defs optdefs
[] = {
170 { SHOPT_AD_CONTAINER
, OPT_TYPE_STRING
},
171 { SHOPT_ABE
, OPT_TYPE_BOOLEAN
},
172 { SHOPT_NAME
, OPT_TYPE_NAME
},
173 { SHOPT_RO
, OPT_TYPE_ACCLIST
},
174 { SHOPT_RW
, OPT_TYPE_ACCLIST
},
175 { SHOPT_NONE
, OPT_TYPE_ACCLIST
},
176 { SHOPT_CATIA
, OPT_TYPE_BOOLEAN
},
177 { SHOPT_CSC
, OPT_TYPE_CSC
},
178 { SHOPT_GUEST
, OPT_TYPE_BOOLEAN
},
179 { SHOPT_DFSROOT
, OPT_TYPE_BOOLEAN
},
180 { SHOPT_DESCRIPTION
, OPT_TYPE_STRING
},
187 * Lookup option "name" in the option table and return the table
195 for (i
= 0; optdefs
[i
].tag
!= NULL
; i
++) {
196 if (strcmp(optdefs
[i
].tag
, name
) == 0)
204 * is_a_number(number)
206 * is the string a number in one of the forms we want to use?
209 is_a_number(char *number
)
211 boolean_t isnum
= B_TRUE
;
212 boolean_t ishex
= B_FALSE
;
214 if (number
== NULL
|| *number
== '\0')
217 if (strncasecmp(number
, "0x", 2) == 0) {
220 } else if (*number
== '-') {
224 while (isnum
&& (*number
!= '\0')) {
225 isnum
= (ishex
) ? isxdigit(*number
) : isdigit(*number
);
233 * check ro vs rw values. Over time this may get beefed up.
234 * for now it just does simple checks.
238 check_rorw(char *v1
, char *v2
)
241 if (strcmp(v1
, v2
) == 0)
242 ret
= SA_VALUE_CONFLICT
;
247 * validresource(name)
249 * Check that name only has valid characters in it. The current valid
250 * set are the printable characters but not including:
251 * " / \ [ ] : | < > + ; , ? * = \t
252 * Note that space is included and there is a maximum length.
255 validresource(const char *name
)
264 if (len
== 0 || len
> SA_MAX_RESOURCE_NAME
)
267 if (strpbrk(name
, "\"/\\[]:|<>+;,?*=\t") != NULL
) {
271 for (cp
= name
; *cp
!= '\0'; cp
++)
279 * Check that the client-side caching (CSC) option value is valid.
282 validcsc(const char *value
)
286 for (i
= 0; i
< (sizeof (cscopt
) / sizeof (cscopt
[0])); ++i
) {
287 if (strcasecmp(value
, cscopt
[i
].value
) == 0)
297 * Determine if the SMF service instance is in the online state or
298 * not. A number of operations depend on this state.
304 boolean_t ret
= B_FALSE
;
306 if ((str
= smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI
)) != NULL
) {
307 ret
= (strcmp(str
, SCF_STATE_STRING_ONLINE
) == 0);
316 * Determine if the SMF service instance is in the disabled state or
317 * not. A number of operations depend on this state.
323 boolean_t ret
= B_FALSE
;
325 if ((str
= smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI
)) != NULL
) {
326 ret
= (strcmp(str
, SCF_STATE_STRING_DISABLED
) == 0);
335 * Determine if the SMF service instance auto_enabled set or not. A
336 * number of operations depend on this state. The property not being
337 * set or being set to true means autoenable. Only being set to false
338 * is not autoenabled.
341 smb_isautoenable(void)
343 boolean_t ret
= B_TRUE
;
344 scf_simple_prop_t
*prop
;
347 prop
= scf_simple_prop_get(NULL
, SMBD_DEFAULT_INSTANCE_FMRI
,
348 "application", "auto_enable");
350 retstr
= scf_simple_prop_next_boolean(prop
);
352 scf_simple_prop_free(prop
);
360 * Determine if the SMF service instance is in the disabled state or
361 * not. A number of operations depend on this state.
367 boolean_t ret
= B_FALSE
;
369 if ((str
= smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI
)) != NULL
) {
370 ret
= (strcmp(str
, SCF_STATE_STRING_MAINT
) == 0);
377 * smb_enable_share tells the implementation that it is to enable the share.
378 * This entails converting the path and options into the appropriate ioctl
379 * calls. It is assumed that all error checking of paths, etc. were
383 smb_enable_share(sa_share_t share
)
387 sa_resource_t resource
;
389 boolean_t privileged
;
391 priv_set_t
*priv_effective
;
395 * Don't support Trusted Extensions.
397 if (is_system_labeled()) {
398 (void) printf(dgettext(TEXT_DOMAIN
,
399 "SMB: service not supported with Trusted Extensions\n"));
400 return (SA_NOT_SUPPORTED
);
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
);
408 /* get the path since it is important in several places */
409 path
= sa_get_share_attr(share
, "path");
411 return (SA_NO_SUCH_PATH
);
414 * If administratively disabled, don't try to start anything.
416 online
= smb_isonline();
417 if (!online
&& !smb_isautoenable() && smb_isdisabled())
420 iszfs
= sa_path_is_zfs(path
);
424 if (privileged
== B_FALSE
&& !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
;
437 sa_free_attr_string(path
);
444 if (privileged
== B_TRUE
&& !online
) {
445 err
= smb_enable_service();
447 (void) printf(dgettext(TEXT_DOMAIN
,
448 "SMB: Unable to enable service\n"));
455 * Don't bother trying to start shares if the service isn't
461 /* Each share can have multiple resources */
462 for (resource
= sa_get_share_resource(share
, NULL
);
464 resource
= sa_get_next_resource(resource
)) {
465 err
= smb_build_shareinfo(share
, resource
, &si
);
467 sa_free_attr_string(path
);
472 err
= smb_share_create(&si
);
476 (void) sa_sharetab_fill_zfs(share
, &sh
, "smb");
477 err
= sa_share_zfs(share
, resource
, (char *)path
, &sh
,
487 (void) sa_update_sharetab(share
, "smb");
489 sa_free_attr_string(path
);
491 return (err
== NERR_DuplicateShare
? 0 : err
);
495 * This is the share for CIFS all shares have resource names.
496 * Enable tells the smb server to update its hash. If it fails
497 * because smb server is down, we just ignore as smb server loads
498 * the resources from sharemanager at startup.
502 smb_enable_resource(sa_resource_t resource
)
510 share
= sa_get_resource_parent(resource
);
512 return (SA_NO_SUCH_PATH
);
515 * If administratively disabled, don't try to start anything.
517 isonline
= smb_isonline();
518 if (!isonline
&& !smb_isautoenable() && smb_isdisabled())
522 (void) smb_enable_service();
528 if ((ret
= smb_build_shareinfo(share
, resource
, &si
)) != SA_OK
)
532 * Attempt to add the share. Any error that occurs if it was
533 * online is an error but don't count NERR_DuplicateName if
534 * smb/server had to be brought online since bringing the
535 * service up will enable the share that was just added prior
536 * to the attempt to enable.
538 err
= smb_share_create(&si
);
539 if (err
== NERR_Success
|| !(!isonline
&& err
== NERR_DuplicateName
))
540 (void) sa_update_sharetab(share
, "smb");
542 return (SA_NOT_SHARED
);
548 * Remove it from smb server hash.
551 smb_disable_resource(sa_resource_t resource
)
557 rname
= sa_get_resource_attr(resource
, "name");
559 return (SA_NO_SUCH_RESOURCE
);
561 if (smb_isonline()) {
562 res
= smb_share_delete(rname
);
563 if (res
!= NERR_Success
&&
564 res
!= NERR_NetNameNotFound
) {
565 sa_free_attr_string(rname
);
566 return (SA_CONFIG_ERR
);
570 sa_free_attr_string(rname
);
572 share
= sa_get_resource_parent(resource
);
574 rname
= sa_get_share_attr(share
, "path");
578 handle
= sa_find_group_handle((sa_group_t
)resource
);
579 (void) sa_delete_sharetab(handle
, rname
, "smb");
580 sa_free_attr_string(rname
);
584 * Always return OK as smb/server may be down and
585 * Shares will be picked up when loaded.
591 * smb_share_changed(sa_share_t share)
593 * The specified share has changed.
596 smb_share_changed(sa_share_t share
)
599 sa_resource_t resource
;
604 /* get the path since it is important in several places */
605 path
= sa_get_share_attr(share
, "path");
607 return (SA_NO_SUCH_PATH
);
609 for (resource
= sa_get_share_resource(share
, NULL
);
611 resource
= sa_get_next_resource(resource
))
612 (void) smb_resource_changed(resource
);
614 sa_free_attr_string(path
);
620 * smb_resource_changed(sa_resource_t resource)
622 * The specified resource has changed.
625 smb_resource_changed(sa_resource_t resource
)
634 if ((share
= sa_get_resource_parent(resource
)) == NULL
)
635 return (SA_CONFIG_ERR
);
637 if ((res
= smb_build_shareinfo(share
, resource
, &si
)) != SA_OK
)
640 res
= smb_share_modify(&si
);
642 if (res
!= NERR_Success
)
643 return (SA_CONFIG_ERR
);
645 return (smb_enable_service());
649 * smb_disable_share(sa_share_t share, char *path)
651 * Unshare the specified share. Note that "path" is the same
652 * path as what is in the "share" object. It is passed in to avoid an
653 * additional lookup. A missing "path" value makes this a no-op
657 smb_disable_share(sa_share_t share
, char *path
)
660 sa_resource_t resource
;
666 boolean_t first
= B_TRUE
; /* work around sharetab issue */
672 * If the share is in a ZFS group we need to handle it
673 * differently. Just being on a ZFS file system isn't
674 * enough since we may be in a legacy share case.
676 parent
= sa_get_parent_group(share
);
677 iszfs
= sa_group_is_zfs(parent
);
682 for (resource
= sa_get_share_resource(share
, NULL
);
684 resource
= sa_get_next_resource(resource
)) {
685 rname
= sa_get_resource_attr(resource
, "name");
690 err
= smb_share_delete(rname
);
692 case NERR_NetNameNotFound
:
703 (void) sa_sharetab_fill_zfs(share
, &sh
, "smb");
704 err
= sa_share_zfs(share
, resource
, (char *)path
, &sh
,
705 rname
, ZFS_UNSHARE_SMB
);
714 * If we are no longer the first case,
715 * we don't care about the sa_share_zfs
716 * err if it is -1. This works around
717 * a problem in sharefs and should be
718 * removed when sharefs supports
719 * multiple entries per path.
736 sa_free_attr_string(rname
);
740 handle
= sa_find_group_handle((sa_group_t
)share
);
742 (void) sa_delete_sharetab(handle
, path
, "smb");
750 * smb_validate_property(handle, property, parent)
752 * Check that the property has a legitimate value for its type.
753 * Handle isn't currently used but may need to be in the future.
758 smb_validate_property(sa_handle_t handle
, sa_property_t property
,
759 sa_optionset_t parent
)
764 sa_group_t parent_group
;
768 propname
= sa_get_property_attr(property
, "type");
770 if ((optindex
= findopt(propname
)) < 0)
771 ret
= SA_NO_SUCH_PROP
;
773 /* need to validate value range here as well */
775 parent_group
= sa_get_parent_group((sa_share_t
)parent
);
776 if (optdefs
[optindex
].share
&& !sa_is_share(parent_group
))
777 ret
= SA_PROP_SHARE_ONLY
;
780 if (propname
!= NULL
)
781 sa_free_attr_string(propname
);
785 value
= sa_get_property_attr(property
, "value");
787 /* first basic type checking */
788 switch (optdefs
[optindex
].type
) {
789 case OPT_TYPE_NUMBER
:
790 /* check that the value is all digits */
791 if (!is_a_number(value
))
794 case OPT_TYPE_BOOLEAN
:
795 ret
= true_false_validator(0, value
);
799 * Make sure no invalid characters
801 if (!validresource(value
))
804 case OPT_TYPE_STRING
:
805 /* whatever is here should be ok */
808 if (!validcsc(value
))
811 case OPT_TYPE_ACCLIST
: {
815 * access list handling. Should eventually
816 * validate that all the values make sense.
817 * Also, ro and rw may have cross value
822 if (strcmp(propname
, SHOPT_RO
) == 0)
824 else if (strcmp(propname
, SHOPT_RW
) == 0)
831 /* compare rw(ro) with ro(rw) */
832 oprop
= sa_get_property(parent
, other
);
840 ovalue
= sa_get_property_attr(oprop
, "value");
841 if (ovalue
!= NULL
) {
842 ret
= check_rorw(value
, ovalue
);
843 sa_free_attr_string(ovalue
);
853 sa_free_attr_string(value
);
854 if (ret
== SA_OK
&& optdefs
[optindex
].check
!= NULL
)
855 /* do the property specific check */
856 ret
= optdefs
[optindex
].check(property
);
858 if (propname
!= NULL
)
859 sa_free_attr_string(propname
);
864 * Protocol management functions
866 * properties defined in the default files are defined in
867 * proto_option_defs for parsing and validation.
870 struct smb_proto_option_defs
{
873 int32_t maxval
; /* In case of length of string this should be max */
874 int (*validator
)(int, char *);
876 } smb_proto_options
[] = {
877 { SMB_CI_SYS_CMNT
, 0, MAX_VALUE_BUFLEN
,
878 string_length_check_validator
, SMB_REFRESH_REFRESH
},
879 { SMB_CI_MAX_WORKERS
, SMB_PI_MAX_WORKERS_MIN
, SMB_PI_MAX_WORKERS_MAX
,
880 range_check_validator
, SMB_REFRESH_REFRESH
},
881 { SMB_CI_NETBIOS_ENABLE
, 0, 0, true_false_validator
,
882 SMB_REFRESH_REFRESH
},
883 { SMB_CI_NBSCOPE
, 0, MAX_VALUE_BUFLEN
,
884 string_length_check_validator
, 0 },
885 { SMB_CI_LM_LEVEL
, 2, 5, range_check_validator
, 0 },
886 { SMB_CI_KEEPALIVE
, 20, 5400, range_check_validator_zero_ok
,
887 SMB_REFRESH_REFRESH
},
888 { SMB_CI_WINS_SRV1
, 0, MAX_VALUE_BUFLEN
,
889 ipv4_validator
, SMB_REFRESH_REFRESH
},
890 { SMB_CI_WINS_SRV2
, 0, MAX_VALUE_BUFLEN
,
891 ipv4_validator
, SMB_REFRESH_REFRESH
},
892 { SMB_CI_WINS_EXCL
, 0, MAX_VALUE_BUFLEN
,
893 interface_validator
, SMB_REFRESH_REFRESH
},
894 { SMB_CI_SIGNING_ENABLE
, 0, 0, true_false_validator
,
895 SMB_REFRESH_REFRESH
},
896 { SMB_CI_SIGNING_REQD
, 0, 0, true_false_validator
,
897 SMB_REFRESH_REFRESH
},
898 { SMB_CI_RESTRICT_ANON
, 0, 0, true_false_validator
,
899 SMB_REFRESH_REFRESH
},
900 { SMB_CI_DOMAIN_SRV
, 0, MAX_VALUE_BUFLEN
,
901 hostname_validator
, SMB_REFRESH_REFRESH
},
902 { SMB_CI_ADS_SITE
, 0, MAX_VALUE_BUFLEN
,
903 string_length_check_validator
, SMB_REFRESH_REFRESH
},
904 { SMB_CI_DYNDNS_ENABLE
, 0, 0, true_false_validator
, 0 },
905 { SMB_CI_AUTOHOME_MAP
, 0, MAX_VALUE_BUFLEN
, path_validator
, 0 },
906 { SMB_CI_IPV6_ENABLE
, 0, 0, true_false_validator
,
907 SMB_REFRESH_REFRESH
},
908 { SMB_CI_PRINT_ENABLE
, 0, 0, print_enable_validator
,
909 SMB_REFRESH_REFRESH
},
910 { SMB_CI_TRAVERSE_MOUNTS
, 0, 0, true_false_validator
,
911 SMB_REFRESH_REFRESH
},
912 { SMB_CI_MAP
, 0, MAX_VALUE_BUFLEN
, cmd_validator
, SMB_REFRESH_REFRESH
},
913 { SMB_CI_UNMAP
, 0, MAX_VALUE_BUFLEN
, cmd_validator
,
914 SMB_REFRESH_REFRESH
},
915 { SMB_CI_DISPOSITION
, 0, MAX_VALUE_BUFLEN
,
916 disposition_validator
, SMB_REFRESH_REFRESH
},
917 { SMB_CI_MAX_PROTOCOL
, 0, MAX_VALUE_BUFLEN
, max_protocol_validator
,
918 SMB_REFRESH_REFRESH
},
921 #define SMB_OPT_NUM \
922 (sizeof (smb_proto_options) / sizeof (smb_proto_options[0]))
925 * Check the range of value as int range.
928 range_check_validator(int index
, char *value
)
932 if (!is_a_number(value
)) {
936 val
= strtoul(value
, NULL
, 0);
937 if (val
< smb_proto_options
[index
].minval
||
938 val
> smb_proto_options
[index
].maxval
)
945 * Check the range of value as int range.
948 range_check_validator_zero_ok(int index
, char *value
)
952 if (!is_a_number(value
)) {
956 val
= strtoul(value
, NULL
, 0);
960 if (val
< smb_proto_options
[index
].minval
||
961 val
> smb_proto_options
[index
].maxval
)
969 * Check the length of the string
972 string_length_check_validator(int index
, char *value
)
977 return (SA_BAD_VALUE
);
978 if (strlen(value
) > smb_proto_options
[index
].maxval
)
988 true_false_validator(int index
, char *value
)
991 return (SA_BAD_VALUE
);
992 if ((strcasecmp(value
, "true") == 0) ||
993 (strcasecmp(value
, "false") == 0))
995 return (SA_BAD_VALUE
);
999 * If printing support is compiled in, this is the same as:
1000 * true_false_validator. Otherwise, only allow false.
1004 print_enable_validator(int index
, char *value
)
1007 return (SA_BAD_VALUE
);
1010 if (strcasecmp(value
, "true") == 0)
1013 if (strcasecmp(value
, "false") == 0)
1016 return (SA_BAD_VALUE
);
1020 * Check IP v4 address.
1024 ipv4_validator(int index
, char *value
)
1031 if (strlen(value
) == 0)
1034 if (inet_pton(AF_INET
, value
, (void *)sbytes
) != 1)
1035 return (SA_BAD_VALUE
);
1041 * Check that the specified name is an IP address (v4 or v6) or a hostname.
1042 * Per RFC 1035 and 1123, names may contain alphanumeric characters, hyphens
1043 * and dots. The first and last character of a label must be alphanumeric.
1044 * Interior characters may be alphanumeric or hypens.
1046 * Domain names should not contain underscores but we allow them because
1047 * Windows names are often in non-compliance with this rule.
1051 hostname_validator(int index
, char *value
)
1053 char sbytes
[INET6_ADDRSTRLEN
];
1054 boolean_t new_label
= B_TRUE
;
1056 char label_terminator
;
1062 if ((len
= strlen(value
)) == 0)
1065 if (inet_pton(AF_INET
, value
, (void *)sbytes
) == 1)
1068 if (inet_pton(AF_INET6
, value
, (void *)sbytes
) == 1)
1071 if (len
>= MAXHOSTNAMELEN
)
1072 return (SA_BAD_VALUE
);
1074 if (strspn(value
, "0123456789.") == len
)
1075 return (SA_BAD_VALUE
);
1077 label_terminator
= *value
;
1079 for (p
= value
; *p
!= '\0'; ++p
) {
1082 return (SA_BAD_VALUE
);
1083 new_label
= B_FALSE
;
1084 label_terminator
= *p
;
1089 if (!isalnum(label_terminator
))
1090 return (SA_BAD_VALUE
);
1092 label_terminator
= *p
;
1096 label_terminator
= *p
;
1098 if (isalnum(*p
) || *p
== '-' || *p
== '_')
1101 return (SA_BAD_VALUE
);
1104 if (!isalnum(label_terminator
))
1105 return (SA_BAD_VALUE
);
1111 * Call back function for dlpi_walk.
1112 * Returns TRUE if interface name exists on the host.
1115 smb_get_interface(const char *ifname
, void *arg
)
1117 smb_hostifs_walker_t
*iterp
= arg
;
1119 iterp
->hiw_matchfound
= (strcmp(ifname
, iterp
->hiw_ifname
) == 0);
1121 return (iterp
->hiw_matchfound
);
1125 * Checks to see if the input interface exists on the host.
1126 * Returns B_TRUE if the match is found, B_FALSE otherwise.
1129 smb_validate_interface(const char *ifname
)
1131 smb_hostifs_walker_t iter
;
1133 if ((ifname
== NULL
) || (*ifname
== '\0'))
1136 iter
.hiw_ifname
= ifname
;
1137 iter
.hiw_matchfound
= B_FALSE
;
1138 dlpi_walk(smb_get_interface
, &iter
, 0);
1140 return (iter
.hiw_matchfound
);
1144 * Check valid interfaces. Interface names value can be NULL or empty.
1145 * Returns SA_BAD_VALUE if interface cannot be found on the host.
1149 interface_validator(int index
, char *value
)
1153 char *ifname
, *tmp
, *p
;
1155 if (value
== NULL
|| *value
== '\0')
1158 if (strlen(value
) > MAX_VALUE_BUFLEN
)
1159 return (SA_BAD_VALUE
);
1161 if ((p
= strdup(value
)) == NULL
)
1162 return (SA_NO_MEMORY
);
1165 while ((ifname
= strsep(&tmp
, ",")) != NULL
) {
1166 if (*ifname
== '\0') {
1171 if (!smb_validate_interface(ifname
)) {
1172 if (inet_pton(AF_INET
, ifname
, (void *)buf
) == 0) {
1188 path_validator(int index
, char *path
)
1194 return (SA_BAD_VALUE
);
1196 fd
= open(path
, O_RDONLY
);
1198 return (SA_BAD_VALUE
);
1200 status
= fstat(fd
, &buffer
);
1204 return (SA_BAD_VALUE
);
1206 if (buffer
.st_mode
& S_IFDIR
)
1208 return (SA_BAD_VALUE
);
1212 * the protoset holds the defined options so we don't have to read
1213 * them multiple times
1215 static sa_protocol_properties_t protoset
;
1218 findprotoopt(char *name
)
1223 for (i
= 0; i
< SMB_OPT_NUM
; i
++) {
1224 sc_name
= smb_config_getname(smb_proto_options
[i
].smb_index
);
1225 if (strcasecmp(sc_name
, name
) == 0)
1233 * smb_load_proto_properties()
1235 * read the smb config values from SMF.
1239 smb_load_proto_properties()
1242 char value
[MAX_VALUE_BUFLEN
];
1248 protoset
= sa_create_protocol_properties(SMB_PROTOCOL_NAME
);
1249 if (protoset
== NULL
)
1250 return (SA_NO_MEMORY
);
1252 for (index
= 0; index
< SMB_OPT_NUM
&& ret
== SA_OK
; index
++) {
1253 rc
= smb_config_get(smb_proto_options
[index
].smb_index
,
1254 value
, sizeof (value
));
1255 if (rc
!= SMBD_SMF_OK
)
1257 name
= smb_config_getname(smb_proto_options
[index
].smb_index
);
1258 prop
= sa_create_property(name
, value
);
1260 ret
= sa_add_protocol_property(protoset
, prop
);
1270 * Initialize the smb plugin.
1274 smb_share_init(void)
1276 if (sa_plugin_ops
.sa_init
!= smb_share_init
)
1277 return (SA_SYSTEM_ERR
);
1279 smb_share_door_clnt_init();
1280 return (smb_load_proto_properties());
1288 smb_share_fini(void)
1290 xmlFreeNode(protoset
);
1293 smb_share_door_clnt_fini();
1297 * smb_get_proto_set()
1299 * Return an optionset with all the protocol specific properties in
1302 static sa_protocol_properties_t
1303 smb_get_proto_set(void)
1309 * smb_enable_dependencies()
1311 * SMBD_DEFAULT_INSTANCE_FMRI may have some dependencies that aren't
1312 * enabled. This will attempt to enable all of them.
1315 smb_enable_dependencies(const char *fmri
)
1317 scf_handle_t
*handle
;
1318 scf_service_t
*service
;
1319 scf_instance_t
*inst
= NULL
;
1321 scf_property_t
*prop
;
1323 scf_propertygroup_t
*pg
;
1325 char type
[SCFTYPE_LEN
];
1331 * Get all required handles and storage.
1333 handle
= scf_handle_create(SCF_VERSION
);
1337 if (scf_handle_bind(handle
) != 0) {
1338 scf_handle_destroy(handle
);
1342 maxlen
= scf_limit(SCF_LIMIT_MAX_VALUE_LENGTH
);
1343 if (maxlen
== (ssize_t
)-1)
1344 maxlen
= MAXPATHLEN
;
1346 dependency
= malloc(maxlen
);
1348 service
= scf_service_create(handle
);
1350 iter
= scf_iter_create(handle
);
1352 pg
= scf_pg_create(handle
);
1354 prop
= scf_property_create(handle
);
1356 value
= scf_value_create(handle
);
1358 scope
= scf_scope_create(handle
);
1360 if (service
== NULL
|| iter
== NULL
|| pg
== NULL
|| prop
== NULL
||
1361 value
== NULL
|| scope
== NULL
|| dependency
== NULL
)
1365 * We passed in the FMRI for the default instance but for
1366 * some things we need the simple form so construct it. Since
1367 * we reuse the storage that dependency points to, we need to
1368 * use the servname early.
1370 (void) snprintf(dependency
, maxlen
, "%s", fmri
+ sizeof ("svc:"));
1371 servname
= strrchr(dependency
, ':');
1372 if (servname
== NULL
)
1375 servname
= dependency
;
1378 * Setup to iterate over the service property groups, only
1379 * looking at those that are "dependency" types. The "entity"
1380 * property will have the FMRI of the service we are dependent
1383 if (scf_handle_get_scope(handle
, SCF_SCOPE_LOCAL
, scope
) != 0)
1386 if (scf_scope_get_service(scope
, servname
, service
) != 0)
1389 if (scf_iter_service_pgs(iter
, service
) != 0)
1392 while (scf_iter_next_pg(iter
, pg
) > 0) {
1395 * Have a property group for the service. See if it is
1396 * a dependency pg and only do operations on those.
1398 if (scf_pg_get_type(pg
, type
, SCFTYPE_LEN
) <= 0)
1401 if (strncmp(type
, SCF_GROUP_DEPENDENCY
, SCFTYPE_LEN
) != 0)
1404 * Have a dependency. Attempt to enable it.
1406 if (scf_pg_get_property(pg
, SCF_PROPERTY_ENTITIES
, prop
) != 0)
1409 if (scf_property_get_value(prop
, value
) != 0)
1414 if (scf_value_get_as_string(value
, dependency
, maxlen
) > 0) {
1415 services
[0] = dependency
;
1416 _check_services(services
);
1421 if (dependency
!= NULL
)
1424 scf_value_destroy(value
);
1426 scf_property_destroy(prop
);
1430 scf_iter_destroy(iter
);
1432 scf_scope_destroy(scope
);
1434 scf_instance_destroy(inst
);
1435 if (service
!= NULL
)
1436 scf_service_destroy(service
);
1438 (void) scf_handle_unbind(handle
);
1439 scf_handle_destroy(handle
);
1443 * How long to wait for service to come online
1445 #define WAIT_FOR_SERVICE 15
1448 * smb_enable_service()
1452 smb_enable_service(void)
1456 char *service
[] = { SMBD_DEFAULT_INSTANCE_FMRI
, NULL
};
1458 if (!smb_isonline()) {
1460 * Attempt to start the idmap, and other dependent
1461 * services, first. If it fails, the SMB service will
1462 * ultimately fail so we use that as the error. If we
1463 * don't try to enable idmap, smb won't start the
1464 * first time unless the admin has done it
1465 * manually. The service could be administratively
1466 * disabled so we won't always get started.
1468 smb_enable_dependencies(SMBD_DEFAULT_INSTANCE_FMRI
);
1469 _check_services(service
);
1471 /* Wait for service to come online */
1472 for (i
= 0; i
< WAIT_FOR_SERVICE
; i
++) {
1473 if (smb_isonline()) {
1476 } else if (smb_ismaint()) {
1477 /* maintenance requires help */
1478 ret
= SA_SYSTEM_ERR
;
1481 /* try another time */
1491 * smb_validate_proto_prop(index, name, value)
1493 * Verify that the property specified by name can take the new
1494 * value. This is a sanity check to prevent bad values getting into
1495 * the default files.
1498 smb_validate_proto_prop(int index
, char *name
, char *value
)
1500 if ((name
== NULL
) || (index
< 0))
1501 return (SA_BAD_VALUE
);
1503 if (smb_proto_options
[index
].validator
== NULL
)
1506 if (smb_proto_options
[index
].validator(index
, value
) == SA_OK
)
1508 return (SA_BAD_VALUE
);
1512 * smb_set_proto_prop(prop)
1514 * check that prop is valid.
1518 smb_set_proto_prop(sa_property_t prop
)
1524 struct smb_proto_option_defs
*opt
;
1526 name
= sa_get_property_attr(prop
, "type");
1527 value
= sa_get_property_attr(prop
, "value");
1528 if (name
!= NULL
&& value
!= NULL
) {
1529 index
= findprotoopt(name
);
1531 /* should test for valid value */
1532 ret
= smb_validate_proto_prop(index
, name
, value
);
1534 opt
= &smb_proto_options
[index
];
1537 (void) smb_config_set(opt
->smb_index
, value
);
1539 * Specialized refresh mechanisms can
1540 * be flagged in the proto_options and
1543 if (opt
->refresh
& SMB_REFRESH_REFRESH
)
1544 (void) smf_refresh_instance(
1545 SMBD_DEFAULT_INSTANCE_FMRI
);
1546 else if (opt
->refresh
& SMB_REFRESH_RESTART
)
1547 (void) smf_restart_instance(
1548 SMBD_DEFAULT_INSTANCE_FMRI
);
1554 sa_free_attr_string(name
);
1556 sa_free_attr_string(value
);
1564 * What is the current status of the smbd? We use the SMF state here.
1565 * Caller must free the returned value.
1569 smb_get_status(void)
1571 return (smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI
));
1575 * This protocol plugin require resource names
1578 smb_share_features(void)
1580 return (SA_FEATURE_RESOURCE
| SA_FEATURE_ALLOWSUBDIRS
|
1581 SA_FEATURE_ALLOWPARDIRS
| SA_FEATURE_SERVER
);
1585 * This should be used to convert smb_share_t to sa_resource_t
1586 * Should only be needed to build transient shares/resources to be
1587 * supplied to sharemgr to display.
1590 smb_add_transient(sa_handle_t handle
, smb_share_t
*si
)
1595 sa_resource_t resource
;
1600 return (SA_INVALID_NAME
);
1602 if ((share
= sa_find_share(handle
, si
->shr_path
)) == NULL
) {
1603 if ((group
= smb_get_defaultgrp(handle
)) == NULL
)
1604 return (SA_NO_SUCH_GROUP
);
1606 share
= sa_get_share(group
, si
->shr_path
);
1607 if (share
== NULL
) {
1608 share
= sa_add_share(group
, si
->shr_path
,
1609 SA_SHARE_TRANSIENT
, &err
);
1611 return (SA_NO_SUCH_PATH
);
1616 * Now handle the resource. Make sure that the resource is
1617 * transient and added to the share.
1619 resource
= sa_get_share_resource(share
, si
->shr_name
);
1620 if (resource
== NULL
) {
1621 resource
= sa_add_resource(share
,
1622 si
->shr_name
, SA_SHARE_TRANSIENT
, &err
);
1623 if (resource
== NULL
)
1624 return (SA_NO_SUCH_RESOURCE
);
1627 if (si
->shr_cmnt
[0] != '\0')
1628 (void) sa_set_resource_description(resource
, si
->shr_cmnt
);
1630 if (si
->shr_container
[0] != '\0')
1631 (void) sa_set_resource_attr(resource
, SHOPT_AD_CONTAINER
,
1634 if (nvlist_alloc(&nvl
, NV_UNIQUE_NAME
, 0) != 0)
1635 return (SA_NO_MEMORY
);
1637 if ((opt
= smb_csc_name(si
)) != NULL
)
1638 err
|= nvlist_add_string(nvl
, SHOPT_CSC
, opt
);
1640 opt
= (si
->shr_flags
& SMB_SHRF_ABE
) ? "true" : "false";
1641 err
|= nvlist_add_string(nvl
, SHOPT_ABE
, opt
);
1643 if ((si
->shr_flags
& SMB_SHRF_AUTOHOME
) == 0) {
1644 opt
= (si
->shr_flags
& SMB_SHRF_GUEST_OK
) ? "true" : "false";
1645 err
|= nvlist_add_string(nvl
, SHOPT_GUEST
, opt
);
1648 if (si
->shr_access_ro
[0] != '\0')
1649 err
|= nvlist_add_string(nvl
, SHOPT_RO
, si
->shr_access_ro
);
1651 if (si
->shr_access_rw
[0] != '\0')
1652 err
|= nvlist_add_string(nvl
, SHOPT_RW
, si
->shr_access_rw
);
1654 if (si
->shr_access_none
[0] != '\0')
1655 err
|= nvlist_add_string(nvl
, SHOPT_NONE
, si
->shr_access_none
);
1659 return (SA_CONFIG_ERR
);
1662 err
= smb_update_optionset_props(handle
, resource
, nvl
);
1669 * Return smb transient shares.
1672 smb_list_transient(sa_handle_t handle
)
1678 if (smb_share_count() <= 0)
1682 while (smb_share_list(offset
, &list
) == NERR_Success
) {
1683 if (list
.sl_cnt
== 0)
1686 for (i
= 0; i
< list
.sl_cnt
; i
++) {
1687 res
= smb_add_transient(handle
, &(list
.sl_shares
[i
]));
1691 offset
+= list
.sl_cnt
;
1698 * fix_resource_name(share, name, prefix)
1700 * Construct a name where the ZFS dataset has the prefix replaced with "name".
1703 fix_resource_name(sa_share_t share
, char *name
, char *prefix
)
1705 char buf
[SA_MAX_RESOURCE_NAME
+ 1];
1707 size_t bufsz
= SA_MAX_RESOURCE_NAME
+ 1;
1711 return (strdup(name
));
1713 dataset
= sa_get_share_attr(share
, "dataset");
1714 if (dataset
== NULL
)
1715 return (strdup(name
));
1717 (void) strlcpy(buf
, name
, bufsz
);
1718 prelen
= strlen(prefix
);
1720 if (strncmp(dataset
, prefix
, prelen
) == 0)
1721 (void) strlcat(buf
, dataset
+ prelen
, bufsz
);
1723 sa_free_attr_string(dataset
);
1724 sa_fix_resource_name(buf
);
1725 return (strdup(buf
));
1729 * smb_parse_optstring(group, options)
1731 * parse a compact option string into individual options. This allows
1732 * ZFS sharesmb and sharemgr "share" command to work. group can be a
1733 * group, a share or a resource.
1736 smb_parse_optstring(sa_group_t group
, char *options
)
1742 sa_optionset_t optionset
;
1743 sa_group_t parent
= NULL
;
1744 sa_resource_t resource
= NULL
;
1747 int need_optionset
= 0;
1752 * In order to not attempt to change ZFS properties unless
1753 * absolutely necessary, we never do it in the legacy parsing
1754 * so we need to keep track of this.
1756 if (sa_is_share(group
)) {
1759 parent
= sa_get_parent_group(group
);
1760 if (parent
!= NULL
) {
1761 zfs
= sa_get_group_attr(parent
, "zfs");
1763 sa_free_attr_string(zfs
);
1768 iszfs
= sa_group_is_zfs(group
);
1770 * If a ZFS group, then we need to see if a resource
1771 * name is being set. If so, bail with
1772 * SA_PROP_SHARE_ONLY, so we come back in with a share
1773 * instead of a group.
1776 strncmp(options
, "name=", sizeof ("name=") - 1) == 0 ||
1777 strstr(options
, ",name=") != NULL
) {
1778 return (SA_PROP_SHARE_ONLY
);
1782 /* do we have an existing optionset? */
1783 optionset
= sa_get_optionset(group
, "smb");
1784 if (optionset
== NULL
) {
1785 /* didn't find existing optionset so create one */
1786 optionset
= sa_create_optionset(group
, "smb");
1787 if (optionset
== NULL
)
1788 return (SA_NO_MEMORY
);
1791 * If an optionset already exists, we've come through
1792 * twice so ignore the second time.
1797 /* We need a copy of options for the next part. */
1798 dup
= strdup(options
);
1800 return (SA_NO_MEMORY
);
1803 * SMB properties are straightforward and are strings,
1804 * integers or booleans. Properties are separated by
1805 * commas. It will be necessary to parse quotes due to some
1806 * strings not having a restricted characters set.
1808 * Note that names will create a resource. For now, if there
1809 * is a set of properties "before" the first name="", those
1810 * properties will be placed on the group.
1812 persist
= sa_is_persistent(group
);
1816 while (token
!= NULL
&& ret
== SA_OK
) {
1818 token
= strtok_r(base
, ",", &lasts
);
1820 if (token
!= NULL
) {
1823 * All SMB properties have values so there
1824 * MUST be an '=' character. If it doesn't,
1825 * it is a syntax error.
1827 value
= strchr(token
, '=');
1828 if (value
!= NULL
) {
1831 ret
= SA_SYNTAX_ERR
;
1835 * We may need to handle a "name" property
1836 * that is a ZFS imposed resource name. Each
1837 * name would trigger getting a new "resource"
1838 * to put properties on. For now, assume no
1839 * "name" property for special handling.
1842 if (strcmp(token
, SHOPT_NAME
) == 0) {
1846 * We have a name, so now work on the
1847 * resource level. We have a "share"
1848 * in "group" due to the caller having
1849 * added it. If we are called with a
1850 * group, the check for group/share
1851 * at the beginning of this function
1852 * will bail out the parse if there is a
1853 * "name" but no share.
1856 ret
= SA_SYNTAX_ERR
;
1860 * Make sure the parent group has the
1861 * "prefix" property since we will
1862 * need to use this for constructing
1863 * inherited name= values.
1865 prefix
= sa_get_group_attr(parent
, "prefix");
1866 if (prefix
== NULL
) {
1867 prefix
= sa_get_group_attr(parent
,
1869 if (prefix
!= NULL
) {
1870 (void) sa_set_group_attr(parent
,
1874 name
= fix_resource_name((sa_share_t
)group
,
1877 resource
= sa_add_resource(
1878 (sa_share_t
)group
, name
,
1879 SA_SHARE_TRANSIENT
, &ret
);
1880 sa_free_attr_string(name
);
1885 sa_free_attr_string(prefix
);
1887 /* A resource level optionset is needed */
1890 if (resource
== NULL
) {
1897 if (iszfs
&& strcmp(token
, SHOPT_DESCRIPTION
) == 0) {
1898 if (resource
== NULL
)
1899 (void) sa_set_share_description(
1900 (sa_share_t
)group
, value
);
1902 (void) sa_set_resource_description(
1907 if (need_optionset
) {
1908 optionset
= sa_create_optionset(resource
,
1913 prop
= sa_create_property(token
, value
);
1917 ret
= sa_add_property(optionset
, prop
);
1921 ret
= sa_commit_properties(optionset
, !persist
);
1929 * smb_sprint_option(rbuff, rbuffsize, incr, prop, sep)
1931 * provides a mechanism to format SMB properties into legacy output
1932 * format. If the buffer would overflow, it is reallocated and grown
1933 * as appropriate. Special cases of converting internal form of values
1934 * to those used by "share" are done. this function does one property
1939 smb_sprint_option(char **rbuff
, size_t *rbuffsize
, size_t incr
,
1940 sa_property_t prop
, int sep
)
1945 char *buff
= *rbuff
;
1946 size_t buffsize
= *rbuffsize
;
1948 name
= sa_get_property_attr(prop
, "type");
1949 value
= sa_get_property_attr(prop
, "value");
1951 curlen
= strlen(buff
);
1956 len
= strlen(name
) + sep
;
1959 * A future RFE would be to replace this with more
1960 * generic code and to possibly handle more types.
1962 * For now, everything else is treated as a string. If
1963 * we get any properties that aren't exactly
1964 * name/value pairs, we may need to
1965 * interpret/transform.
1968 len
+= 1 + strlen(value
);
1970 while (buffsize
<= (curlen
+ len
)) {
1971 /* need more room */
1973 buff
= realloc(buff
, buffsize
);
1975 *rbuffsize
= buffsize
;
1977 /* realloc failed so free everything */
1985 (void) snprintf(buff
+ curlen
, buffsize
- curlen
,
1986 "%s%s=%s", sep
? "," : "",
1987 name
, value
!= NULL
? value
: "\"\"");
1992 sa_free_attr_string(name
);
1994 sa_free_attr_string(value
);
1998 * smb_format_resource_options(resource, hier)
2000 * format all the options on the group into a flattened option
2001 * string. If hier is non-zero, walk up the tree to get inherited
2006 smb_format_options(sa_group_t group
, int hier
)
2008 sa_optionset_t options
= NULL
;
2015 buff
= malloc(OPT_CHUNK
);
2020 buffsize
= OPT_CHUNK
;
2023 * We may have a an optionset relative to this item. format
2024 * these if we find them and then add any security definitions.
2027 options
= sa_get_derived_optionset(group
, "smb", hier
);
2030 * do the default set first but skip any option that is also
2031 * in the protocol specific optionset.
2033 if (options
!= NULL
) {
2034 for (prop
= sa_get_property(options
, NULL
);
2035 prop
!= NULL
; prop
= sa_get_next_property(prop
)) {
2037 * use this one since we skipped any
2038 * of these that were also in
2041 smb_sprint_option(&buff
, &buffsize
, OPT_CHUNK
,
2045 * buff could become NULL if there
2046 * isn't enough memory for
2047 * smb_sprint_option to realloc()
2048 * as necessary. We can't really
2049 * do anything about it at this
2050 * point so we return NULL. The
2051 * caller should handle the
2054 if (options
!= NULL
)
2055 sa_free_derived_optionset(
2063 if (options
!= NULL
)
2064 sa_free_derived_optionset(options
);
2069 * smb_rename_resource(resource, newname)
2071 * Change the current exported name of the resource to newname.
2075 smb_rename_resource(sa_handle_t handle
, sa_resource_t resource
, char *newname
)
2081 if (!smb_isonline())
2084 oldname
= sa_get_resource_attr(resource
, "name");
2085 if (oldname
== NULL
)
2086 return (SA_NO_SUCH_RESOURCE
);
2088 err
= smb_share_rename(oldname
, newname
);
2090 sa_free_attr_string(oldname
);
2092 /* improve error values somewhat */
2096 case NERR_InternalError
:
2097 ret
= SA_SYSTEM_ERR
;
2099 case NERR_DuplicateShare
:
2100 ret
= SA_DUPLICATE_NAME
;
2103 ret
= SA_CONFIG_ERR
;
2111 smb_build_shareinfo(sa_share_t share
, sa_resource_t resource
, smb_share_t
*si
)
2113 sa_optionset_t opts
;
2117 char csc_value
[SMB_CSC_BUFSZ
];
2119 bzero(si
, sizeof (smb_share_t
));
2121 if ((path
= sa_get_share_attr(share
, "path")) == NULL
)
2122 return (SA_NO_SUCH_PATH
);
2124 if ((rname
= sa_get_resource_attr(resource
, "name")) == NULL
) {
2125 sa_free_attr_string(path
);
2126 return (SA_NO_SUCH_RESOURCE
);
2129 (void) strlcpy(si
->shr_path
, path
, sizeof (si
->shr_path
));
2130 (void) strlcpy(si
->shr_name
, rname
, sizeof (si
->shr_name
));
2131 sa_free_attr_string(path
);
2132 sa_free_attr_string(rname
);
2134 val
= sa_get_resource_description(resource
);
2136 val
= sa_get_share_description(share
);
2139 (void) strlcpy(si
->shr_cmnt
, val
, sizeof (si
->shr_cmnt
));
2140 sa_free_share_description(val
);
2143 si
->shr_flags
= (sa_is_persistent(share
))
2144 ? SMB_SHRF_PERM
: SMB_SHRF_TRANS
;
2146 opts
= sa_get_derived_optionset(resource
, SMB_PROTOCOL_NAME
, 1);
2150 if (smb_saprop_getbool(opts
, SHOPT_CATIA
))
2151 si
->shr_flags
|= SMB_SHRF_CATIA
;
2153 if (smb_saprop_getbool(opts
, SHOPT_ABE
))
2154 si
->shr_flags
|= SMB_SHRF_ABE
;
2156 if (smb_saprop_getbool(opts
, SHOPT_GUEST
))
2157 si
->shr_flags
|= SMB_SHRF_GUEST_OK
;
2159 if (smb_saprop_getbool(opts
, SHOPT_DFSROOT
))
2160 si
->shr_flags
|= SMB_SHRF_DFSROOT
;
2162 (void) smb_saprop_getstr(opts
, SHOPT_AD_CONTAINER
, si
->shr_container
,
2163 sizeof (si
->shr_container
));
2165 if (smb_saprop_getstr(opts
, SHOPT_CSC
, csc_value
, sizeof (csc_value
)))
2166 smb_csc_option(csc_value
, si
);
2168 if (smb_saprop_getstr(opts
, SHOPT_RO
, si
->shr_access_ro
,
2169 sizeof (si
->shr_access_ro
)))
2170 si
->shr_flags
|= SMB_SHRF_ACC_RO
;
2172 if (smb_saprop_getstr(opts
, SHOPT_RW
, si
->shr_access_rw
,
2173 sizeof (si
->shr_access_rw
)))
2174 si
->shr_flags
|= SMB_SHRF_ACC_RW
;
2176 if (smb_saprop_getstr(opts
, SHOPT_NONE
, si
->shr_access_none
,
2177 sizeof (si
->shr_access_none
)))
2178 si
->shr_flags
|= SMB_SHRF_ACC_NONE
;
2180 sa_free_derived_optionset(opts
);
2185 * Map a client-side caching (CSC) option to the appropriate share
2186 * flag. Only one option is allowed; an error will be logged if
2187 * multiple options have been specified. We don't need to do anything
2188 * about multiple values here because the SRVSVC will not recognize
2189 * a value containing multiple flags and will return the default value.
2191 * If the option value is not recognized, it will be ignored: invalid
2192 * values will typically be caught and rejected by sharemgr.
2195 smb_csc_option(const char *value
, smb_share_t
*si
)
2197 char buf
[SMB_CSC_BUFSZ
];
2200 for (i
= 0; i
< (sizeof (cscopt
) / sizeof (cscopt
[0])); ++i
) {
2201 if (strcasecmp(value
, cscopt
[i
].value
) == 0) {
2202 si
->shr_flags
|= cscopt
[i
].flag
;
2207 switch (si
->shr_flags
& SMB_SHRF_CSC_MASK
) {
2209 case SMB_SHRF_CSC_DISABLED
:
2210 case SMB_SHRF_CSC_MANUAL
:
2211 case SMB_SHRF_CSC_AUTO
:
2212 case SMB_SHRF_CSC_VDO
:
2218 for (i
= 0; i
< (sizeof (cscopt
) / sizeof (cscopt
[0])); ++i
) {
2219 if (si
->shr_flags
& cscopt
[i
].flag
) {
2220 (void) strlcat(buf
, " ", SMB_CSC_BUFSZ
);
2221 (void) strlcat(buf
, cscopt
[i
].value
,
2226 syslog(LOG_ERR
, "csc option conflict:%s", buf
);
2232 * Return the option name for the first CSC flag (there should be only
2233 * one) encountered in the share flags.
2236 smb_csc_name(const smb_share_t
*si
)
2240 for (i
= 0; i
< (sizeof (cscopt
) / sizeof (cscopt
[0])); ++i
) {
2241 if (si
->shr_flags
& cscopt
[i
].flag
)
2242 return (cscopt
[i
].value
);
2249 * smb_get_defaultgrp
2251 * If default group for CIFS shares (i.e. "smb") exists
2252 * then it will return the group handle, otherwise it will
2253 * create the group and return the handle.
2255 * All the shares created by CIFS clients (this is only possible
2256 * via RPC) will be added to "smb" groups.
2259 smb_get_defaultgrp(sa_handle_t handle
)
2261 sa_group_t group
= NULL
;
2264 group
= sa_get_group(handle
, SMB_DEFAULT_SHARE_GROUP
);
2268 group
= sa_create_group(handle
, SMB_DEFAULT_SHARE_GROUP
, &err
);
2272 if (sa_create_optionset(group
, SMB_DEFAULT_SHARE_GROUP
) == NULL
) {
2273 (void) sa_remove_group(group
);
2281 * Checks to see if the command args are the supported substitution specifier.
2285 cmd_validator(int index
, char *value
)
2287 char cmd
[MAXPATHLEN
];
2289 boolean_t skip_cmdname
;
2291 if (string_length_check_validator(index
, value
) != SA_OK
)
2292 return (SA_BAD_VALUE
);
2297 (void) strlcpy(cmd
, value
, sizeof (cmd
));
2300 skip_cmdname
= B_TRUE
;
2302 if ((v
= strsep(&ptr
, " ")) == NULL
)
2308 skip_cmdname
= B_FALSE
;
2312 if ((strlen(v
) != 2) || *v
!= '%')
2313 return (SA_BAD_VALUE
);
2315 if (strpbrk(v
, SMB_VALID_SUB_CHRS
) == NULL
)
2316 return (SA_BAD_VALUE
);
2319 } while (v
!= NULL
);
2322 * If skip_cmdname is still true then the string contains
2323 * only spaces. Don't allow such a string.
2326 return (SA_BAD_VALUE
);
2333 disposition_validator(int index
, char *value
)
2336 return (SA_BAD_VALUE
);
2341 if ((strcasecmp(value
, SMB_EXEC_DISP_CONTINUE
) == 0) ||
2342 (strcasecmp(value
, SMB_EXEC_DISP_TERMINATE
) == 0))
2345 return (SA_BAD_VALUE
);
2350 max_protocol_validator(int index
, char *value
)
2353 return (SA_BAD_VALUE
);
2358 if (smb_config_check_protocol(value
) == 0)
2361 return (SA_BAD_VALUE
);
2366 * Updates the optionset properties of the share resource.
2367 * The properties are given as a list of name-value pair.
2368 * The name argument should be the optionset property name and the value
2369 * should be a valid value for the specified property.
2371 * When calling this function for permanent shares, the caller must also
2372 * call sa_commit_properties() to commit the changes to SMF.
2375 smb_update_optionset_props(sa_handle_t handle
, sa_resource_t resource
,
2379 sa_optionset_t opts
;
2384 if ((opts
= sa_get_optionset(resource
, SMB_PROTOCOL_NAME
)) == NULL
) {
2385 opts
= sa_create_optionset(resource
, SMB_PROTOCOL_NAME
);
2387 return (SA_CONFIG_ERR
);
2390 cur
= nvlist_next_nvpair(nvl
, NULL
);
2391 while (cur
!= NULL
) {
2392 name
= nvpair_name(cur
);
2393 err
= nvpair_value_string(cur
, &val
);
2394 if ((err
!= 0) || (name
== NULL
) || (val
== NULL
)) {
2395 err
= SA_CONFIG_ERR
;
2400 if ((prop
= sa_get_property(opts
, name
)) == NULL
) {
2401 prop
= sa_create_property(name
, val
);
2403 err
= sa_valid_property(handle
, opts
,
2404 SMB_PROTOCOL_NAME
, prop
);
2406 (void) sa_remove_property(prop
);
2410 err
= sa_add_property(opts
, prop
);
2414 err
= sa_update_property(prop
, val
);
2419 cur
= nvlist_next_nvpair(nvl
, cur
);
2426 smb_saprop_getbool(sa_optionset_t opts
, char *propname
)
2430 boolean_t propval
= B_FALSE
;
2432 prop
= sa_get_property(opts
, propname
);
2433 if ((val
= sa_get_property_attr(prop
, "value")) != NULL
) {
2434 if ((strcasecmp(val
, "true") == 0) || (strcmp(val
, "1") == 0))
2443 smb_saprop_getstr(sa_optionset_t opts
, char *propname
, char *buf
, size_t bufsz
)
2448 prop
= sa_get_property(opts
, propname
);
2449 if ((val
= sa_get_property_attr(prop
, "value")) != NULL
) {
2450 (void) strlcpy(buf
, val
, bufsz
);