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 2013 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 *);
88 static int smb_enable_resource(sa_resource_t
);
89 static int smb_disable_resource(sa_resource_t
);
90 static uint64_t smb_share_features(void);
91 static int smb_list_transient(sa_handle_t
);
93 static int smb_build_shareinfo(sa_share_t
, sa_resource_t
, smb_share_t
*);
94 static void smb_csc_option(const char *, smb_share_t
*);
95 static char *smb_csc_name(const smb_share_t
*);
96 static sa_group_t
smb_get_defaultgrp(sa_handle_t
);
97 static int interface_validator(int, char *);
98 static int smb_update_optionset_props(sa_handle_t
, sa_resource_t
, nvlist_t
*);
100 static boolean_t
smb_saprop_getbool(sa_optionset_t
, char *);
101 static boolean_t
smb_saprop_getstr(sa_optionset_t
, char *, char *, size_t);
107 { "disabled", SMB_SHRF_CSC_DISABLED
},
108 { "manual", SMB_SHRF_CSC_MANUAL
},
109 { "auto", SMB_SHRF_CSC_AUTO
},
110 { "vdo", SMB_SHRF_CSC_VDO
}
113 /* size of basic format allocation */
114 #define OPT_CHUNK 1024
116 /* size of string for types - big enough to hold "dependency" */
117 #define SCFTYPE_LEN 32
120 * Indexes of entries in smb_proto_options table.
121 * Changes to smb_proto_options table may require
122 * an update to these values.
124 #define PROTO_OPT_WINS1 6
125 #define PROTO_OPT_WINS_EXCLUDE 8
127 typedef struct smb_hostifs_walker
{
128 const char *hiw_ifname
;
129 boolean_t hiw_matchfound
;
130 } smb_hostifs_walker_t
;
134 * ops vector that provides the protocol specific info and operations
135 * for share management.
138 struct sa_plugin_ops sa_plugin_ops
= {
145 smb_validate_property
,
146 NULL
, /* valid_space */
147 NULL
, /* security_prop */
153 NULL
, /* space_alias */
154 NULL
, /* update_legacy */
155 NULL
, /* delete_legacy */
158 smb_disable_resource
,
161 smb_resource_changed
,
163 NULL
, /* run_command */
164 NULL
, /* command_help */
165 NULL
/* delete_proto_section */
168 struct option_defs optdefs
[] = {
169 { SHOPT_AD_CONTAINER
, OPT_TYPE_STRING
},
170 { SHOPT_ABE
, OPT_TYPE_BOOLEAN
},
171 { SHOPT_NAME
, OPT_TYPE_NAME
},
172 { SHOPT_RO
, OPT_TYPE_ACCLIST
},
173 { SHOPT_RW
, OPT_TYPE_ACCLIST
},
174 { SHOPT_NONE
, OPT_TYPE_ACCLIST
},
175 { SHOPT_CATIA
, OPT_TYPE_BOOLEAN
},
176 { SHOPT_CSC
, OPT_TYPE_CSC
},
177 { SHOPT_GUEST
, OPT_TYPE_BOOLEAN
},
178 { SHOPT_DFSROOT
, OPT_TYPE_BOOLEAN
},
179 { SHOPT_DESCRIPTION
, OPT_TYPE_STRING
},
186 * Lookup option "name" in the option table and return the table
194 for (i
= 0; optdefs
[i
].tag
!= NULL
; i
++) {
195 if (strcmp(optdefs
[i
].tag
, name
) == 0)
203 * is_a_number(number)
205 * is the string a number in one of the forms we want to use?
208 is_a_number(char *number
)
210 boolean_t isnum
= B_TRUE
;
211 boolean_t ishex
= B_FALSE
;
213 if (number
== NULL
|| *number
== '\0')
216 if (strncasecmp(number
, "0x", 2) == 0) {
219 } else if (*number
== '-') {
223 while (isnum
&& (*number
!= '\0')) {
224 isnum
= (ishex
) ? isxdigit(*number
) : isdigit(*number
);
232 * check ro vs rw values. Over time this may get beefed up.
233 * for now it just does simple checks.
237 check_rorw(char *v1
, char *v2
)
240 if (strcmp(v1
, v2
) == 0)
241 ret
= SA_VALUE_CONFLICT
;
246 * validresource(name)
248 * Check that name only has valid characters in it. The current valid
249 * set are the printable characters but not including:
250 * " / \ [ ] : | < > + ; , ? * = \t
251 * Note that space is included and there is a maximum length.
254 validresource(const char *name
)
263 if (len
== 0 || len
> SA_MAX_RESOURCE_NAME
)
266 if (strpbrk(name
, "\"/\\[]:|<>+;,?*=\t") != NULL
) {
270 for (cp
= name
; *cp
!= '\0'; cp
++)
278 * Check that the client-side caching (CSC) option value is valid.
281 validcsc(const char *value
)
285 for (i
= 0; i
< (sizeof (cscopt
) / sizeof (cscopt
[0])); ++i
) {
286 if (strcasecmp(value
, cscopt
[i
].value
) == 0)
296 * Determine if the SMF service instance is in the online state or
297 * not. A number of operations depend on this state.
303 boolean_t ret
= B_FALSE
;
305 if ((str
= smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI
)) != NULL
) {
306 ret
= (strcmp(str
, SCF_STATE_STRING_ONLINE
) == 0);
315 * Determine if the SMF service instance is in the disabled state or
316 * not. A number of operations depend on this state.
322 boolean_t ret
= B_FALSE
;
324 if ((str
= smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI
)) != NULL
) {
325 ret
= (strcmp(str
, SCF_STATE_STRING_DISABLED
) == 0);
334 * Determine if the SMF service instance auto_enabled set or not. A
335 * number of operations depend on this state. The property not being
336 * set or being set to true means autoenable. Only being set to false
337 * is not autoenabled.
340 smb_isautoenable(void)
342 boolean_t ret
= B_TRUE
;
343 scf_simple_prop_t
*prop
;
346 prop
= scf_simple_prop_get(NULL
, SMBD_DEFAULT_INSTANCE_FMRI
,
347 "application", "auto_enable");
349 retstr
= scf_simple_prop_next_boolean(prop
);
351 scf_simple_prop_free(prop
);
359 * Determine if the SMF service instance is in the disabled state or
360 * not. A number of operations depend on this state.
366 boolean_t ret
= B_FALSE
;
368 if ((str
= smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI
)) != NULL
) {
369 ret
= (strcmp(str
, SCF_STATE_STRING_MAINT
) == 0);
376 * smb_enable_share tells the implementation that it is to enable the share.
377 * This entails converting the path and options into the appropriate ioctl
378 * calls. It is assumed that all error checking of paths, etc. were
382 smb_enable_share(sa_share_t share
)
386 sa_resource_t resource
;
388 boolean_t privileged
;
390 priv_set_t
*priv_effective
;
394 * Don't support Trusted Extensions.
396 if (is_system_labeled()) {
397 (void) printf(dgettext(TEXT_DOMAIN
,
398 "SMB: service not supported with Trusted Extensions\n"));
399 return (SA_NOT_SUPPORTED
);
402 priv_effective
= priv_allocset();
403 (void) getppriv(PRIV_EFFECTIVE
, priv_effective
);
404 privileged
= (priv_isfullset(priv_effective
) == B_TRUE
);
405 priv_freeset(priv_effective
);
407 /* get the path since it is important in several places */
408 path
= sa_get_share_attr(share
, "path");
410 return (SA_NO_SUCH_PATH
);
413 * If administratively disabled, don't try to start anything.
415 online
= smb_isonline();
416 if (!online
&& !smb_isautoenable() && smb_isdisabled())
419 iszfs
= sa_path_is_zfs(path
);
423 if (privileged
== B_FALSE
&& !online
) {
426 (void) printf(dgettext(TEXT_DOMAIN
,
427 "SMB: Cannot share remove "
428 "file system: %s\n"), path
);
429 (void) printf(dgettext(TEXT_DOMAIN
,
430 "SMB: Service needs to be enabled "
431 "by a privileged user\n"));
432 err
= SA_NO_PERMISSION
;
436 sa_free_attr_string(path
);
443 if (privileged
== B_TRUE
&& !online
) {
444 err
= smb_enable_service();
446 (void) printf(dgettext(TEXT_DOMAIN
,
447 "SMB: Unable to enable service\n"));
454 * Don't bother trying to start shares if the service isn't
460 /* Each share can have multiple resources */
461 for (resource
= sa_get_share_resource(share
, NULL
);
463 resource
= sa_get_next_resource(resource
)) {
464 err
= smb_build_shareinfo(share
, resource
, &si
);
466 sa_free_attr_string(path
);
471 err
= smb_share_create(&si
);
475 (void) sa_sharetab_fill_zfs(share
, &sh
, "smb");
476 err
= sa_share_zfs(share
, resource
, (char *)path
, &sh
,
486 (void) sa_update_sharetab(share
, "smb");
488 sa_free_attr_string(path
);
490 return (err
== NERR_DuplicateShare
? 0 : err
);
494 * This is the share for CIFS all shares have resource names.
495 * Enable tells the smb server to update its hash. If it fails
496 * because smb server is down, we just ignore as smb server loads
497 * the resources from sharemanager at startup.
501 smb_enable_resource(sa_resource_t resource
)
509 share
= sa_get_resource_parent(resource
);
511 return (SA_NO_SUCH_PATH
);
514 * If administratively disabled, don't try to start anything.
516 isonline
= smb_isonline();
517 if (!isonline
&& !smb_isautoenable() && smb_isdisabled())
521 (void) smb_enable_service();
527 if ((ret
= smb_build_shareinfo(share
, resource
, &si
)) != SA_OK
)
531 * Attempt to add the share. Any error that occurs if it was
532 * online is an error but don't count NERR_DuplicateName if
533 * smb/server had to be brought online since bringing the
534 * service up will enable the share that was just added prior
535 * to the attempt to enable.
537 err
= smb_share_create(&si
);
538 if (err
== NERR_Success
|| !(!isonline
&& err
== NERR_DuplicateName
))
539 (void) sa_update_sharetab(share
, "smb");
541 return (SA_NOT_SHARED
);
547 * Remove it from smb server hash.
550 smb_disable_resource(sa_resource_t resource
)
556 rname
= sa_get_resource_attr(resource
, "name");
558 return (SA_NO_SUCH_RESOURCE
);
560 if (smb_isonline()) {
561 res
= smb_share_delete(rname
);
562 if (res
!= NERR_Success
&&
563 res
!= NERR_NetNameNotFound
) {
564 sa_free_attr_string(rname
);
565 return (SA_CONFIG_ERR
);
569 sa_free_attr_string(rname
);
571 share
= sa_get_resource_parent(resource
);
573 rname
= sa_get_share_attr(share
, "path");
577 handle
= sa_find_group_handle((sa_group_t
)resource
);
578 (void) sa_delete_sharetab(handle
, rname
, "smb");
579 sa_free_attr_string(rname
);
583 * Always return OK as smb/server may be down and
584 * Shares will be picked up when loaded.
590 * smb_share_changed(sa_share_t share)
592 * The specified share has changed.
595 smb_share_changed(sa_share_t share
)
598 sa_resource_t resource
;
603 /* get the path since it is important in several places */
604 path
= sa_get_share_attr(share
, "path");
606 return (SA_NO_SUCH_PATH
);
608 for (resource
= sa_get_share_resource(share
, NULL
);
610 resource
= sa_get_next_resource(resource
))
611 (void) smb_resource_changed(resource
);
613 sa_free_attr_string(path
);
619 * smb_resource_changed(sa_resource_t resource)
621 * The specified resource has changed.
624 smb_resource_changed(sa_resource_t resource
)
633 if ((share
= sa_get_resource_parent(resource
)) == NULL
)
634 return (SA_CONFIG_ERR
);
636 if ((res
= smb_build_shareinfo(share
, resource
, &si
)) != SA_OK
)
639 res
= smb_share_modify(&si
);
641 if (res
!= NERR_Success
)
642 return (SA_CONFIG_ERR
);
644 return (smb_enable_service());
648 * smb_disable_share(sa_share_t share, char *path)
650 * Unshare the specified share. Note that "path" is the same
651 * path as what is in the "share" object. It is passed in to avoid an
652 * additional lookup. A missing "path" value makes this a no-op
656 smb_disable_share(sa_share_t share
, char *path
)
659 sa_resource_t resource
;
665 boolean_t first
= B_TRUE
; /* work around sharetab issue */
671 * If the share is in a ZFS group we need to handle it
672 * differently. Just being on a ZFS file system isn't
673 * enough since we may be in a legacy share case.
675 parent
= sa_get_parent_group(share
);
676 iszfs
= sa_group_is_zfs(parent
);
681 for (resource
= sa_get_share_resource(share
, NULL
);
683 resource
= sa_get_next_resource(resource
)) {
684 rname
= sa_get_resource_attr(resource
, "name");
689 err
= smb_share_delete(rname
);
691 case NERR_NetNameNotFound
:
702 (void) sa_sharetab_fill_zfs(share
, &sh
, "smb");
703 err
= sa_share_zfs(share
, resource
, (char *)path
, &sh
,
704 rname
, ZFS_UNSHARE_SMB
);
713 * If we are no longer the first case,
714 * we don't care about the sa_share_zfs
715 * err if it is -1. This works around
716 * a problem in sharefs and should be
717 * removed when sharefs supports
718 * multiple entries per path.
735 sa_free_attr_string(rname
);
739 handle
= sa_find_group_handle((sa_group_t
)share
);
741 (void) sa_delete_sharetab(handle
, path
, "smb");
749 * smb_validate_property(handle, property, parent)
751 * Check that the property has a legitimate value for its type.
752 * Handle isn't currently used but may need to be in the future.
757 smb_validate_property(sa_handle_t handle
, sa_property_t property
,
758 sa_optionset_t parent
)
763 sa_group_t parent_group
;
767 propname
= sa_get_property_attr(property
, "type");
769 if ((optindex
= findopt(propname
)) < 0)
770 ret
= SA_NO_SUCH_PROP
;
772 /* need to validate value range here as well */
774 parent_group
= sa_get_parent_group((sa_share_t
)parent
);
775 if (optdefs
[optindex
].share
&& !sa_is_share(parent_group
))
776 ret
= SA_PROP_SHARE_ONLY
;
779 if (propname
!= NULL
)
780 sa_free_attr_string(propname
);
784 value
= sa_get_property_attr(property
, "value");
786 /* first basic type checking */
787 switch (optdefs
[optindex
].type
) {
788 case OPT_TYPE_NUMBER
:
789 /* check that the value is all digits */
790 if (!is_a_number(value
))
793 case OPT_TYPE_BOOLEAN
:
794 ret
= true_false_validator(0, value
);
798 * Make sure no invalid characters
800 if (!validresource(value
))
803 case OPT_TYPE_STRING
:
804 /* whatever is here should be ok */
807 if (!validcsc(value
))
810 case OPT_TYPE_ACCLIST
: {
814 * access list handling. Should eventually
815 * validate that all the values make sense.
816 * Also, ro and rw may have cross value
821 if (strcmp(propname
, SHOPT_RO
) == 0)
823 else if (strcmp(propname
, SHOPT_RW
) == 0)
830 /* compare rw(ro) with ro(rw) */
831 oprop
= sa_get_property(parent
, other
);
839 ovalue
= sa_get_property_attr(oprop
, "value");
840 if (ovalue
!= NULL
) {
841 ret
= check_rorw(value
, ovalue
);
842 sa_free_attr_string(ovalue
);
852 sa_free_attr_string(value
);
853 if (ret
== SA_OK
&& optdefs
[optindex
].check
!= NULL
)
854 /* do the property specific check */
855 ret
= optdefs
[optindex
].check(property
);
857 if (propname
!= NULL
)
858 sa_free_attr_string(propname
);
863 * Protocol management functions
865 * properties defined in the default files are defined in
866 * proto_option_defs for parsing and validation.
869 struct smb_proto_option_defs
{
872 int32_t maxval
; /* In case of length of string this should be max */
873 int (*validator
)(int, char *);
875 } smb_proto_options
[] = {
876 { SMB_CI_SYS_CMNT
, 0, MAX_VALUE_BUFLEN
,
877 string_length_check_validator
, SMB_REFRESH_REFRESH
},
878 { SMB_CI_MAX_WORKERS
, 64, 1024, range_check_validator
,
879 SMB_REFRESH_REFRESH
},
880 { SMB_CI_NBSCOPE
, 0, MAX_VALUE_BUFLEN
,
881 string_length_check_validator
, 0 },
882 { SMB_CI_LM_LEVEL
, 2, 5, range_check_validator
, 0 },
883 { SMB_CI_KEEPALIVE
, 20, 5400, range_check_validator_zero_ok
,
884 SMB_REFRESH_REFRESH
},
885 { SMB_CI_WINS_SRV1
, 0, MAX_VALUE_BUFLEN
,
886 ipv4_validator
, SMB_REFRESH_REFRESH
},
887 { SMB_CI_WINS_SRV2
, 0, MAX_VALUE_BUFLEN
,
888 ipv4_validator
, SMB_REFRESH_REFRESH
},
889 { SMB_CI_WINS_EXCL
, 0, MAX_VALUE_BUFLEN
,
890 interface_validator
, SMB_REFRESH_REFRESH
},
891 { SMB_CI_SIGNING_ENABLE
, 0, 0, true_false_validator
,
892 SMB_REFRESH_REFRESH
},
893 { SMB_CI_SIGNING_REQD
, 0, 0, true_false_validator
,
894 SMB_REFRESH_REFRESH
},
895 { SMB_CI_RESTRICT_ANON
, 0, 0, true_false_validator
,
896 SMB_REFRESH_REFRESH
},
897 { SMB_CI_DOMAIN_SRV
, 0, MAX_VALUE_BUFLEN
,
898 hostname_validator
, SMB_REFRESH_REFRESH
},
899 { SMB_CI_ADS_SITE
, 0, MAX_VALUE_BUFLEN
,
900 string_length_check_validator
, SMB_REFRESH_REFRESH
},
901 { SMB_CI_DYNDNS_ENABLE
, 0, 0, true_false_validator
, 0 },
902 { SMB_CI_AUTOHOME_MAP
, 0, MAX_VALUE_BUFLEN
, path_validator
, 0 },
903 { SMB_CI_IPV6_ENABLE
, 0, 0, true_false_validator
,
904 SMB_REFRESH_REFRESH
},
905 { SMB_CI_PRINT_ENABLE
, 0, 0, print_enable_validator
,
906 SMB_REFRESH_REFRESH
},
907 { SMB_CI_TRAVERSE_MOUNTS
, 0, 0, true_false_validator
,
908 SMB_REFRESH_REFRESH
},
909 { SMB_CI_MAP
, 0, MAX_VALUE_BUFLEN
, cmd_validator
, SMB_REFRESH_REFRESH
},
910 { SMB_CI_UNMAP
, 0, MAX_VALUE_BUFLEN
, cmd_validator
,
911 SMB_REFRESH_REFRESH
},
912 { SMB_CI_DISPOSITION
, 0, MAX_VALUE_BUFLEN
,
913 disposition_validator
, SMB_REFRESH_REFRESH
},
914 { SMB_CI_NETBIOS_ENABLE
, 0, 0, true_false_validator
,
915 SMB_REFRESH_REFRESH
},
918 #define SMB_OPT_NUM \
919 (sizeof (smb_proto_options) / sizeof (smb_proto_options[0]))
922 * Check the range of value as int range.
925 range_check_validator(int index
, char *value
)
929 if (!is_a_number(value
)) {
933 val
= strtoul(value
, NULL
, 0);
934 if (val
< smb_proto_options
[index
].minval
||
935 val
> smb_proto_options
[index
].maxval
)
942 * Check the range of value as int range.
945 range_check_validator_zero_ok(int index
, char *value
)
949 if (!is_a_number(value
)) {
953 val
= strtoul(value
, NULL
, 0);
957 if (val
< smb_proto_options
[index
].minval
||
958 val
> smb_proto_options
[index
].maxval
)
966 * Check the length of the string
969 string_length_check_validator(int index
, char *value
)
974 return (SA_BAD_VALUE
);
975 if (strlen(value
) > smb_proto_options
[index
].maxval
)
985 true_false_validator(int index
, char *value
)
988 return (SA_BAD_VALUE
);
989 if ((strcasecmp(value
, "true") == 0) ||
990 (strcasecmp(value
, "false") == 0))
992 return (SA_BAD_VALUE
);
996 * If printing support is compiled in, this is the same as:
997 * true_false_validator. Otherwise, only allow false.
1001 print_enable_validator(int index
, char *value
)
1004 return (SA_BAD_VALUE
);
1007 if (strcasecmp(value
, "true") == 0)
1010 if (strcasecmp(value
, "false") == 0)
1013 return (SA_BAD_VALUE
);
1017 * Check IP v4 address.
1021 ipv4_validator(int index
, char *value
)
1028 if (strlen(value
) == 0)
1031 if (inet_pton(AF_INET
, value
, (void *)sbytes
) != 1)
1032 return (SA_BAD_VALUE
);
1038 * Check that the specified name is an IP address (v4 or v6) or a hostname.
1039 * Per RFC 1035 and 1123, names may contain alphanumeric characters, hyphens
1040 * and dots. The first and last character of a label must be alphanumeric.
1041 * Interior characters may be alphanumeric or hypens.
1043 * Domain names should not contain underscores but we allow them because
1044 * Windows names are often in non-compliance with this rule.
1048 hostname_validator(int index
, char *value
)
1050 char sbytes
[INET6_ADDRSTRLEN
];
1051 boolean_t new_label
= B_TRUE
;
1053 char label_terminator
;
1059 if ((len
= strlen(value
)) == 0)
1062 if (inet_pton(AF_INET
, value
, (void *)sbytes
) == 1)
1065 if (inet_pton(AF_INET6
, value
, (void *)sbytes
) == 1)
1068 if (len
>= MAXHOSTNAMELEN
)
1069 return (SA_BAD_VALUE
);
1071 if (strspn(value
, "0123456789.") == len
)
1072 return (SA_BAD_VALUE
);
1074 label_terminator
= *value
;
1076 for (p
= value
; *p
!= '\0'; ++p
) {
1079 return (SA_BAD_VALUE
);
1080 new_label
= B_FALSE
;
1081 label_terminator
= *p
;
1086 if (!isalnum(label_terminator
))
1087 return (SA_BAD_VALUE
);
1089 label_terminator
= *p
;
1093 label_terminator
= *p
;
1095 if (isalnum(*p
) || *p
== '-' || *p
== '_')
1098 return (SA_BAD_VALUE
);
1101 if (!isalnum(label_terminator
))
1102 return (SA_BAD_VALUE
);
1108 * Call back function for dlpi_walk.
1109 * Returns TRUE if interface name exists on the host.
1112 smb_get_interface(const char *ifname
, void *arg
)
1114 smb_hostifs_walker_t
*iterp
= arg
;
1116 iterp
->hiw_matchfound
= (strcmp(ifname
, iterp
->hiw_ifname
) == 0);
1118 return (iterp
->hiw_matchfound
);
1122 * Checks to see if the input interface exists on the host.
1123 * Returns B_TRUE if the match is found, B_FALSE otherwise.
1126 smb_validate_interface(const char *ifname
)
1128 smb_hostifs_walker_t iter
;
1130 if ((ifname
== NULL
) || (*ifname
== '\0'))
1133 iter
.hiw_ifname
= ifname
;
1134 iter
.hiw_matchfound
= B_FALSE
;
1135 dlpi_walk(smb_get_interface
, &iter
, 0);
1137 return (iter
.hiw_matchfound
);
1141 * Check valid interfaces. Interface names value can be NULL or empty.
1142 * Returns SA_BAD_VALUE if interface cannot be found on the host.
1146 interface_validator(int index
, char *value
)
1150 char *ifname
, *tmp
, *p
;
1152 if (value
== NULL
|| *value
== '\0')
1155 if (strlen(value
) > MAX_VALUE_BUFLEN
)
1156 return (SA_BAD_VALUE
);
1158 if ((p
= strdup(value
)) == NULL
)
1159 return (SA_NO_MEMORY
);
1162 while ((ifname
= strsep(&tmp
, ",")) != NULL
) {
1163 if (*ifname
== '\0') {
1168 if (!smb_validate_interface(ifname
)) {
1169 if (inet_pton(AF_INET
, ifname
, (void *)buf
) == 0) {
1185 path_validator(int index
, char *path
)
1191 return (SA_BAD_VALUE
);
1193 fd
= open(path
, O_RDONLY
);
1195 return (SA_BAD_VALUE
);
1197 status
= fstat(fd
, &buffer
);
1201 return (SA_BAD_VALUE
);
1203 if (buffer
.st_mode
& S_IFDIR
)
1205 return (SA_BAD_VALUE
);
1209 * the protoset holds the defined options so we don't have to read
1210 * them multiple times
1212 static sa_protocol_properties_t protoset
;
1215 findprotoopt(char *name
)
1220 for (i
= 0; i
< SMB_OPT_NUM
; i
++) {
1221 sc_name
= smb_config_getname(smb_proto_options
[i
].smb_index
);
1222 if (strcasecmp(sc_name
, name
) == 0)
1230 * smb_load_proto_properties()
1232 * read the smb config values from SMF.
1236 smb_load_proto_properties()
1239 char value
[MAX_VALUE_BUFLEN
];
1245 protoset
= sa_create_protocol_properties(SMB_PROTOCOL_NAME
);
1246 if (protoset
== NULL
)
1247 return (SA_NO_MEMORY
);
1249 for (index
= 0; index
< SMB_OPT_NUM
&& ret
== SA_OK
; index
++) {
1250 rc
= smb_config_get(smb_proto_options
[index
].smb_index
,
1251 value
, sizeof (value
));
1252 if (rc
!= SMBD_SMF_OK
)
1254 name
= smb_config_getname(smb_proto_options
[index
].smb_index
);
1255 prop
= sa_create_property(name
, value
);
1257 ret
= sa_add_protocol_property(protoset
, prop
);
1267 * Initialize the smb plugin.
1271 smb_share_init(void)
1273 if (sa_plugin_ops
.sa_init
!= smb_share_init
)
1274 return (SA_SYSTEM_ERR
);
1276 smb_share_door_clnt_init();
1277 return (smb_load_proto_properties());
1285 smb_share_fini(void)
1287 xmlFreeNode(protoset
);
1290 smb_share_door_clnt_fini();
1294 * smb_get_proto_set()
1296 * Return an optionset with all the protocol specific properties in
1299 static sa_protocol_properties_t
1300 smb_get_proto_set(void)
1306 * smb_enable_dependencies()
1308 * SMBD_DEFAULT_INSTANCE_FMRI may have some dependencies that aren't
1309 * enabled. This will attempt to enable all of them.
1312 smb_enable_dependencies(const char *fmri
)
1314 scf_handle_t
*handle
;
1315 scf_service_t
*service
;
1316 scf_instance_t
*inst
= NULL
;
1318 scf_property_t
*prop
;
1320 scf_propertygroup_t
*pg
;
1322 char type
[SCFTYPE_LEN
];
1328 * Get all required handles and storage.
1330 handle
= scf_handle_create(SCF_VERSION
);
1334 if (scf_handle_bind(handle
) != 0) {
1335 scf_handle_destroy(handle
);
1339 maxlen
= scf_limit(SCF_LIMIT_MAX_VALUE_LENGTH
);
1340 if (maxlen
== (ssize_t
)-1)
1341 maxlen
= MAXPATHLEN
;
1343 dependency
= malloc(maxlen
);
1345 service
= scf_service_create(handle
);
1347 iter
= scf_iter_create(handle
);
1349 pg
= scf_pg_create(handle
);
1351 prop
= scf_property_create(handle
);
1353 value
= scf_value_create(handle
);
1355 scope
= scf_scope_create(handle
);
1357 if (service
== NULL
|| iter
== NULL
|| pg
== NULL
|| prop
== NULL
||
1358 value
== NULL
|| scope
== NULL
|| dependency
== NULL
)
1362 * We passed in the FMRI for the default instance but for
1363 * some things we need the simple form so construct it. Since
1364 * we reuse the storage that dependency points to, we need to
1365 * use the servname early.
1367 (void) snprintf(dependency
, maxlen
, "%s", fmri
+ sizeof ("svc:"));
1368 servname
= strrchr(dependency
, ':');
1369 if (servname
== NULL
)
1372 servname
= dependency
;
1375 * Setup to iterate over the service property groups, only
1376 * looking at those that are "dependency" types. The "entity"
1377 * property will have the FMRI of the service we are dependent
1380 if (scf_handle_get_scope(handle
, SCF_SCOPE_LOCAL
, scope
) != 0)
1383 if (scf_scope_get_service(scope
, servname
, service
) != 0)
1386 if (scf_iter_service_pgs(iter
, service
) != 0)
1389 while (scf_iter_next_pg(iter
, pg
) > 0) {
1392 * Have a property group for the service. See if it is
1393 * a dependency pg and only do operations on those.
1395 if (scf_pg_get_type(pg
, type
, SCFTYPE_LEN
) <= 0)
1398 if (strncmp(type
, SCF_GROUP_DEPENDENCY
, SCFTYPE_LEN
) != 0)
1401 * Have a dependency. Attempt to enable it.
1403 if (scf_pg_get_property(pg
, SCF_PROPERTY_ENTITIES
, prop
) != 0)
1406 if (scf_property_get_value(prop
, value
) != 0)
1411 if (scf_value_get_as_string(value
, dependency
, maxlen
) > 0) {
1412 services
[0] = dependency
;
1413 _check_services(services
);
1418 if (dependency
!= NULL
)
1421 scf_value_destroy(value
);
1423 scf_property_destroy(prop
);
1427 scf_iter_destroy(iter
);
1429 scf_scope_destroy(scope
);
1431 scf_instance_destroy(inst
);
1432 if (service
!= NULL
)
1433 scf_service_destroy(service
);
1435 (void) scf_handle_unbind(handle
);
1436 scf_handle_destroy(handle
);
1440 * How long to wait for service to come online
1442 #define WAIT_FOR_SERVICE 15
1445 * smb_enable_service()
1449 smb_enable_service(void)
1453 char *service
[] = { SMBD_DEFAULT_INSTANCE_FMRI
, NULL
};
1455 if (!smb_isonline()) {
1457 * Attempt to start the idmap, and other dependent
1458 * services, first. If it fails, the SMB service will
1459 * ultimately fail so we use that as the error. If we
1460 * don't try to enable idmap, smb won't start the
1461 * first time unless the admin has done it
1462 * manually. The service could be administratively
1463 * disabled so we won't always get started.
1465 smb_enable_dependencies(SMBD_DEFAULT_INSTANCE_FMRI
);
1466 _check_services(service
);
1468 /* Wait for service to come online */
1469 for (i
= 0; i
< WAIT_FOR_SERVICE
; i
++) {
1470 if (smb_isonline()) {
1473 } else if (smb_ismaint()) {
1474 /* maintenance requires help */
1475 ret
= SA_SYSTEM_ERR
;
1478 /* try another time */
1488 * smb_validate_proto_prop(index, name, value)
1490 * Verify that the property specified by name can take the new
1491 * value. This is a sanity check to prevent bad values getting into
1492 * the default files.
1495 smb_validate_proto_prop(int index
, char *name
, char *value
)
1497 if ((name
== NULL
) || (index
< 0))
1498 return (SA_BAD_VALUE
);
1500 if (smb_proto_options
[index
].validator
== NULL
)
1503 if (smb_proto_options
[index
].validator(index
, value
) == SA_OK
)
1505 return (SA_BAD_VALUE
);
1509 * smb_set_proto_prop(prop)
1511 * check that prop is valid.
1515 smb_set_proto_prop(sa_property_t prop
)
1521 struct smb_proto_option_defs
*opt
;
1523 name
= sa_get_property_attr(prop
, "type");
1524 value
= sa_get_property_attr(prop
, "value");
1525 if (name
!= NULL
&& value
!= NULL
) {
1526 index
= findprotoopt(name
);
1528 /* should test for valid value */
1529 ret
= smb_validate_proto_prop(index
, name
, value
);
1531 opt
= &smb_proto_options
[index
];
1534 (void) smb_config_set(opt
->smb_index
, value
);
1536 * Specialized refresh mechanisms can
1537 * be flagged in the proto_options and
1540 if (opt
->refresh
& SMB_REFRESH_REFRESH
)
1541 (void) smf_refresh_instance(
1542 SMBD_DEFAULT_INSTANCE_FMRI
);
1543 else if (opt
->refresh
& SMB_REFRESH_RESTART
)
1544 (void) smf_restart_instance(
1545 SMBD_DEFAULT_INSTANCE_FMRI
);
1551 sa_free_attr_string(name
);
1553 sa_free_attr_string(value
);
1561 * What is the current status of the smbd? We use the SMF state here.
1562 * Caller must free the returned value.
1566 smb_get_status(void)
1568 return (smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI
));
1572 * This protocol plugin require resource names
1575 smb_share_features(void)
1577 return (SA_FEATURE_RESOURCE
| SA_FEATURE_ALLOWSUBDIRS
|
1578 SA_FEATURE_ALLOWPARDIRS
| SA_FEATURE_SERVER
);
1582 * This should be used to convert smb_share_t to sa_resource_t
1583 * Should only be needed to build transient shares/resources to be
1584 * supplied to sharemgr to display.
1587 smb_add_transient(sa_handle_t handle
, smb_share_t
*si
)
1592 sa_resource_t resource
;
1597 return (SA_INVALID_NAME
);
1599 if ((share
= sa_find_share(handle
, si
->shr_path
)) == NULL
) {
1600 if ((group
= smb_get_defaultgrp(handle
)) == NULL
)
1601 return (SA_NO_SUCH_GROUP
);
1603 share
= sa_get_share(group
, si
->shr_path
);
1604 if (share
== NULL
) {
1605 share
= sa_add_share(group
, si
->shr_path
,
1606 SA_SHARE_TRANSIENT
, &err
);
1608 return (SA_NO_SUCH_PATH
);
1613 * Now handle the resource. Make sure that the resource is
1614 * transient and added to the share.
1616 resource
= sa_get_share_resource(share
, si
->shr_name
);
1617 if (resource
== NULL
) {
1618 resource
= sa_add_resource(share
,
1619 si
->shr_name
, SA_SHARE_TRANSIENT
, &err
);
1620 if (resource
== NULL
)
1621 return (SA_NO_SUCH_RESOURCE
);
1624 if (si
->shr_cmnt
[0] != '\0')
1625 (void) sa_set_resource_description(resource
, si
->shr_cmnt
);
1627 if (si
->shr_container
[0] != '\0')
1628 (void) sa_set_resource_attr(resource
, SHOPT_AD_CONTAINER
,
1631 if (nvlist_alloc(&nvl
, NV_UNIQUE_NAME
, 0) != 0)
1632 return (SA_NO_MEMORY
);
1634 if ((opt
= smb_csc_name(si
)) != NULL
)
1635 err
|= nvlist_add_string(nvl
, SHOPT_CSC
, opt
);
1637 opt
= (si
->shr_flags
& SMB_SHRF_ABE
) ? "true" : "false";
1638 err
|= nvlist_add_string(nvl
, SHOPT_ABE
, opt
);
1640 if ((si
->shr_flags
& SMB_SHRF_AUTOHOME
) == 0) {
1641 opt
= (si
->shr_flags
& SMB_SHRF_GUEST_OK
) ? "true" : "false";
1642 err
|= nvlist_add_string(nvl
, SHOPT_GUEST
, opt
);
1645 if (si
->shr_access_ro
[0] != '\0')
1646 err
|= nvlist_add_string(nvl
, SHOPT_RO
, si
->shr_access_ro
);
1648 if (si
->shr_access_rw
[0] != '\0')
1649 err
|= nvlist_add_string(nvl
, SHOPT_RW
, si
->shr_access_rw
);
1651 if (si
->shr_access_none
[0] != '\0')
1652 err
|= nvlist_add_string(nvl
, SHOPT_NONE
, si
->shr_access_none
);
1656 return (SA_CONFIG_ERR
);
1659 err
= smb_update_optionset_props(handle
, resource
, nvl
);
1666 * Return smb transient shares.
1669 smb_list_transient(sa_handle_t handle
)
1675 if (smb_share_count() <= 0)
1679 while (smb_share_list(offset
, &list
) == NERR_Success
) {
1680 if (list
.sl_cnt
== 0)
1683 for (i
= 0; i
< list
.sl_cnt
; i
++) {
1684 res
= smb_add_transient(handle
, &(list
.sl_shares
[i
]));
1688 offset
+= list
.sl_cnt
;
1695 * fix_resource_name(share, name, prefix)
1697 * Construct a name where the ZFS dataset has the prefix replaced with "name".
1700 fix_resource_name(sa_share_t share
, char *name
, char *prefix
)
1702 char buf
[SA_MAX_RESOURCE_NAME
+ 1];
1704 size_t bufsz
= SA_MAX_RESOURCE_NAME
+ 1;
1708 return (strdup(name
));
1710 dataset
= sa_get_share_attr(share
, "dataset");
1711 if (dataset
== NULL
)
1712 return (strdup(name
));
1714 (void) strlcpy(buf
, name
, bufsz
);
1715 prelen
= strlen(prefix
);
1717 if (strncmp(dataset
, prefix
, prelen
) == 0)
1718 (void) strlcat(buf
, dataset
+ prelen
, bufsz
);
1720 sa_free_attr_string(dataset
);
1721 sa_fix_resource_name(buf
);
1722 return (strdup(buf
));
1726 * smb_parse_optstring(group, options)
1728 * parse a compact option string into individual options. This allows
1729 * ZFS sharesmb and sharemgr "share" command to work. group can be a
1730 * group, a share or a resource.
1733 smb_parse_optstring(sa_group_t group
, char *options
)
1739 sa_optionset_t optionset
;
1740 sa_group_t parent
= NULL
;
1741 sa_resource_t resource
= NULL
;
1744 int need_optionset
= 0;
1749 * In order to not attempt to change ZFS properties unless
1750 * absolutely necessary, we never do it in the legacy parsing
1751 * so we need to keep track of this.
1753 if (sa_is_share(group
)) {
1756 parent
= sa_get_parent_group(group
);
1757 if (parent
!= NULL
) {
1758 zfs
= sa_get_group_attr(parent
, "zfs");
1760 sa_free_attr_string(zfs
);
1765 iszfs
= sa_group_is_zfs(group
);
1767 * If a ZFS group, then we need to see if a resource
1768 * name is being set. If so, bail with
1769 * SA_PROP_SHARE_ONLY, so we come back in with a share
1770 * instead of a group.
1773 strncmp(options
, "name=", sizeof ("name=") - 1) == 0 ||
1774 strstr(options
, ",name=") != NULL
) {
1775 return (SA_PROP_SHARE_ONLY
);
1779 /* do we have an existing optionset? */
1780 optionset
= sa_get_optionset(group
, "smb");
1781 if (optionset
== NULL
) {
1782 /* didn't find existing optionset so create one */
1783 optionset
= sa_create_optionset(group
, "smb");
1784 if (optionset
== NULL
)
1785 return (SA_NO_MEMORY
);
1788 * If an optionset already exists, we've come through
1789 * twice so ignore the second time.
1794 /* We need a copy of options for the next part. */
1795 dup
= strdup(options
);
1797 return (SA_NO_MEMORY
);
1800 * SMB properties are straightforward and are strings,
1801 * integers or booleans. Properties are separated by
1802 * commas. It will be necessary to parse quotes due to some
1803 * strings not having a restricted characters set.
1805 * Note that names will create a resource. For now, if there
1806 * is a set of properties "before" the first name="", those
1807 * properties will be placed on the group.
1809 persist
= sa_is_persistent(group
);
1813 while (token
!= NULL
&& ret
== SA_OK
) {
1815 token
= strtok_r(base
, ",", &lasts
);
1817 if (token
!= NULL
) {
1820 * All SMB properties have values so there
1821 * MUST be an '=' character. If it doesn't,
1822 * it is a syntax error.
1824 value
= strchr(token
, '=');
1825 if (value
!= NULL
) {
1828 ret
= SA_SYNTAX_ERR
;
1832 * We may need to handle a "name" property
1833 * that is a ZFS imposed resource name. Each
1834 * name would trigger getting a new "resource"
1835 * to put properties on. For now, assume no
1836 * "name" property for special handling.
1839 if (strcmp(token
, SHOPT_NAME
) == 0) {
1843 * We have a name, so now work on the
1844 * resource level. We have a "share"
1845 * in "group" due to the caller having
1846 * added it. If we are called with a
1847 * group, the check for group/share
1848 * at the beginning of this function
1849 * will bail out the parse if there is a
1850 * "name" but no share.
1853 ret
= SA_SYNTAX_ERR
;
1857 * Make sure the parent group has the
1858 * "prefix" property since we will
1859 * need to use this for constructing
1860 * inherited name= values.
1862 prefix
= sa_get_group_attr(parent
, "prefix");
1863 if (prefix
== NULL
) {
1864 prefix
= sa_get_group_attr(parent
,
1866 if (prefix
!= NULL
) {
1867 (void) sa_set_group_attr(parent
,
1871 name
= fix_resource_name((sa_share_t
)group
,
1874 resource
= sa_add_resource(
1875 (sa_share_t
)group
, name
,
1876 SA_SHARE_TRANSIENT
, &ret
);
1877 sa_free_attr_string(name
);
1882 sa_free_attr_string(prefix
);
1884 /* A resource level optionset is needed */
1887 if (resource
== NULL
) {
1894 if (iszfs
&& strcmp(token
, SHOPT_DESCRIPTION
) == 0) {
1895 if (resource
== NULL
)
1896 (void) sa_set_share_description(
1897 (sa_share_t
)group
, value
);
1899 (void) sa_set_resource_description(
1904 if (need_optionset
) {
1905 optionset
= sa_create_optionset(resource
,
1910 prop
= sa_create_property(token
, value
);
1914 ret
= sa_add_property(optionset
, prop
);
1918 ret
= sa_commit_properties(optionset
, !persist
);
1926 * smb_sprint_option(rbuff, rbuffsize, incr, prop, sep)
1928 * provides a mechanism to format SMB properties into legacy output
1929 * format. If the buffer would overflow, it is reallocated and grown
1930 * as appropriate. Special cases of converting internal form of values
1931 * to those used by "share" are done. this function does one property
1936 smb_sprint_option(char **rbuff
, size_t *rbuffsize
, size_t incr
,
1937 sa_property_t prop
, int sep
)
1942 char *buff
= *rbuff
;
1943 size_t buffsize
= *rbuffsize
;
1945 name
= sa_get_property_attr(prop
, "type");
1946 value
= sa_get_property_attr(prop
, "value");
1948 curlen
= strlen(buff
);
1953 len
= strlen(name
) + sep
;
1956 * A future RFE would be to replace this with more
1957 * generic code and to possibly handle more types.
1959 * For now, everything else is treated as a string. If
1960 * we get any properties that aren't exactly
1961 * name/value pairs, we may need to
1962 * interpret/transform.
1965 len
+= 1 + strlen(value
);
1967 while (buffsize
<= (curlen
+ len
)) {
1968 /* need more room */
1970 buff
= realloc(buff
, buffsize
);
1972 *rbuffsize
= buffsize
;
1974 /* realloc failed so free everything */
1982 (void) snprintf(buff
+ curlen
, buffsize
- curlen
,
1983 "%s%s=%s", sep
? "," : "",
1984 name
, value
!= NULL
? value
: "\"\"");
1989 sa_free_attr_string(name
);
1991 sa_free_attr_string(value
);
1995 * smb_format_resource_options(resource, hier)
1997 * format all the options on the group into a flattened option
1998 * string. If hier is non-zero, walk up the tree to get inherited
2003 smb_format_options(sa_group_t group
, int hier
)
2005 sa_optionset_t options
= NULL
;
2012 buff
= malloc(OPT_CHUNK
);
2017 buffsize
= OPT_CHUNK
;
2020 * We may have a an optionset relative to this item. format
2021 * these if we find them and then add any security definitions.
2024 options
= sa_get_derived_optionset(group
, "smb", hier
);
2027 * do the default set first but skip any option that is also
2028 * in the protocol specific optionset.
2030 if (options
!= NULL
) {
2031 for (prop
= sa_get_property(options
, NULL
);
2032 prop
!= NULL
; prop
= sa_get_next_property(prop
)) {
2034 * use this one since we skipped any
2035 * of these that were also in
2038 smb_sprint_option(&buff
, &buffsize
, OPT_CHUNK
,
2042 * buff could become NULL if there
2043 * isn't enough memory for
2044 * smb_sprint_option to realloc()
2045 * as necessary. We can't really
2046 * do anything about it at this
2047 * point so we return NULL. The
2048 * caller should handle the
2051 if (options
!= NULL
)
2052 sa_free_derived_optionset(
2060 if (options
!= NULL
)
2061 sa_free_derived_optionset(options
);
2066 * smb_rename_resource(resource, newname)
2068 * Change the current exported name of the resource to newname.
2072 smb_rename_resource(sa_handle_t handle
, sa_resource_t resource
, char *newname
)
2078 if (!smb_isonline())
2081 oldname
= sa_get_resource_attr(resource
, "name");
2082 if (oldname
== NULL
)
2083 return (SA_NO_SUCH_RESOURCE
);
2085 err
= smb_share_rename(oldname
, newname
);
2087 sa_free_attr_string(oldname
);
2089 /* improve error values somewhat */
2093 case NERR_InternalError
:
2094 ret
= SA_SYSTEM_ERR
;
2096 case NERR_DuplicateShare
:
2097 ret
= SA_DUPLICATE_NAME
;
2100 ret
= SA_CONFIG_ERR
;
2108 smb_build_shareinfo(sa_share_t share
, sa_resource_t resource
, smb_share_t
*si
)
2110 sa_optionset_t opts
;
2114 char csc_value
[SMB_CSC_BUFSZ
];
2116 bzero(si
, sizeof (smb_share_t
));
2118 if ((path
= sa_get_share_attr(share
, "path")) == NULL
)
2119 return (SA_NO_SUCH_PATH
);
2121 if ((rname
= sa_get_resource_attr(resource
, "name")) == NULL
) {
2122 sa_free_attr_string(path
);
2123 return (SA_NO_SUCH_RESOURCE
);
2126 (void) strlcpy(si
->shr_path
, path
, sizeof (si
->shr_path
));
2127 (void) strlcpy(si
->shr_name
, rname
, sizeof (si
->shr_name
));
2128 sa_free_attr_string(path
);
2129 sa_free_attr_string(rname
);
2131 val
= sa_get_resource_description(resource
);
2133 val
= sa_get_share_description(share
);
2136 (void) strlcpy(si
->shr_cmnt
, val
, sizeof (si
->shr_cmnt
));
2137 sa_free_share_description(val
);
2140 si
->shr_flags
= (sa_is_persistent(share
))
2141 ? SMB_SHRF_PERM
: SMB_SHRF_TRANS
;
2143 opts
= sa_get_derived_optionset(resource
, SMB_PROTOCOL_NAME
, 1);
2147 if (smb_saprop_getbool(opts
, SHOPT_CATIA
))
2148 si
->shr_flags
|= SMB_SHRF_CATIA
;
2150 if (smb_saprop_getbool(opts
, SHOPT_ABE
))
2151 si
->shr_flags
|= SMB_SHRF_ABE
;
2153 if (smb_saprop_getbool(opts
, SHOPT_GUEST
))
2154 si
->shr_flags
|= SMB_SHRF_GUEST_OK
;
2156 if (smb_saprop_getbool(opts
, SHOPT_DFSROOT
))
2157 si
->shr_flags
|= SMB_SHRF_DFSROOT
;
2159 (void) smb_saprop_getstr(opts
, SHOPT_AD_CONTAINER
, si
->shr_container
,
2160 sizeof (si
->shr_container
));
2162 if (smb_saprop_getstr(opts
, SHOPT_CSC
, csc_value
, sizeof (csc_value
)))
2163 smb_csc_option(csc_value
, si
);
2165 if (smb_saprop_getstr(opts
, SHOPT_RO
, si
->shr_access_ro
,
2166 sizeof (si
->shr_access_ro
)))
2167 si
->shr_flags
|= SMB_SHRF_ACC_RO
;
2169 if (smb_saprop_getstr(opts
, SHOPT_RW
, si
->shr_access_rw
,
2170 sizeof (si
->shr_access_rw
)))
2171 si
->shr_flags
|= SMB_SHRF_ACC_RW
;
2173 if (smb_saprop_getstr(opts
, SHOPT_NONE
, si
->shr_access_none
,
2174 sizeof (si
->shr_access_none
)))
2175 si
->shr_flags
|= SMB_SHRF_ACC_NONE
;
2177 sa_free_derived_optionset(opts
);
2182 * Map a client-side caching (CSC) option to the appropriate share
2183 * flag. Only one option is allowed; an error will be logged if
2184 * multiple options have been specified. We don't need to do anything
2185 * about multiple values here because the SRVSVC will not recognize
2186 * a value containing multiple flags and will return the default value.
2188 * If the option value is not recognized, it will be ignored: invalid
2189 * values will typically be caught and rejected by sharemgr.
2192 smb_csc_option(const char *value
, smb_share_t
*si
)
2194 char buf
[SMB_CSC_BUFSZ
];
2197 for (i
= 0; i
< (sizeof (cscopt
) / sizeof (cscopt
[0])); ++i
) {
2198 if (strcasecmp(value
, cscopt
[i
].value
) == 0) {
2199 si
->shr_flags
|= cscopt
[i
].flag
;
2204 switch (si
->shr_flags
& SMB_SHRF_CSC_MASK
) {
2206 case SMB_SHRF_CSC_DISABLED
:
2207 case SMB_SHRF_CSC_MANUAL
:
2208 case SMB_SHRF_CSC_AUTO
:
2209 case SMB_SHRF_CSC_VDO
:
2215 for (i
= 0; i
< (sizeof (cscopt
) / sizeof (cscopt
[0])); ++i
) {
2216 if (si
->shr_flags
& cscopt
[i
].flag
) {
2217 (void) strlcat(buf
, " ", SMB_CSC_BUFSZ
);
2218 (void) strlcat(buf
, cscopt
[i
].value
,
2223 syslog(LOG_ERR
, "csc option conflict:%s", buf
);
2229 * Return the option name for the first CSC flag (there should be only
2230 * one) encountered in the share flags.
2233 smb_csc_name(const smb_share_t
*si
)
2237 for (i
= 0; i
< (sizeof (cscopt
) / sizeof (cscopt
[0])); ++i
) {
2238 if (si
->shr_flags
& cscopt
[i
].flag
)
2239 return (cscopt
[i
].value
);
2246 * smb_get_defaultgrp
2248 * If default group for CIFS shares (i.e. "smb") exists
2249 * then it will return the group handle, otherwise it will
2250 * create the group and return the handle.
2252 * All the shares created by CIFS clients (this is only possible
2253 * via RPC) will be added to "smb" groups.
2256 smb_get_defaultgrp(sa_handle_t handle
)
2258 sa_group_t group
= NULL
;
2261 group
= sa_get_group(handle
, SMB_DEFAULT_SHARE_GROUP
);
2265 group
= sa_create_group(handle
, SMB_DEFAULT_SHARE_GROUP
, &err
);
2269 if (sa_create_optionset(group
, SMB_DEFAULT_SHARE_GROUP
) == NULL
) {
2270 (void) sa_remove_group(group
);
2278 * Checks to see if the command args are the supported substitution specifier.
2282 cmd_validator(int index
, char *value
)
2284 char cmd
[MAXPATHLEN
];
2286 boolean_t skip_cmdname
;
2288 if (string_length_check_validator(index
, value
) != SA_OK
)
2289 return (SA_BAD_VALUE
);
2294 (void) strlcpy(cmd
, value
, sizeof (cmd
));
2297 skip_cmdname
= B_TRUE
;
2299 if ((v
= strsep(&ptr
, " ")) == NULL
)
2305 skip_cmdname
= B_FALSE
;
2309 if ((strlen(v
) != 2) || *v
!= '%')
2310 return (SA_BAD_VALUE
);
2312 if (strpbrk(v
, SMB_VALID_SUB_CHRS
) == NULL
)
2313 return (SA_BAD_VALUE
);
2316 } while (v
!= NULL
);
2319 * If skip_cmdname is still true then the string contains
2320 * only spaces. Don't allow such a string.
2323 return (SA_BAD_VALUE
);
2330 disposition_validator(int index
, char *value
)
2333 return (SA_BAD_VALUE
);
2338 if ((strcasecmp(value
, SMB_EXEC_DISP_CONTINUE
) == 0) ||
2339 (strcasecmp(value
, SMB_EXEC_DISP_TERMINATE
) == 0))
2342 return (SA_BAD_VALUE
);
2346 * Updates the optionset properties of the share resource.
2347 * The properties are given as a list of name-value pair.
2348 * The name argument should be the optionset property name and the value
2349 * should be a valid value for the specified property.
2351 * When calling this function for permanent shares, the caller must also
2352 * call sa_commit_properties() to commit the changes to SMF.
2355 smb_update_optionset_props(sa_handle_t handle
, sa_resource_t resource
,
2359 sa_optionset_t opts
;
2364 if ((opts
= sa_get_optionset(resource
, SMB_PROTOCOL_NAME
)) == NULL
) {
2365 opts
= sa_create_optionset(resource
, SMB_PROTOCOL_NAME
);
2367 return (SA_CONFIG_ERR
);
2370 cur
= nvlist_next_nvpair(nvl
, NULL
);
2371 while (cur
!= NULL
) {
2372 name
= nvpair_name(cur
);
2373 err
= nvpair_value_string(cur
, &val
);
2374 if ((err
!= 0) || (name
== NULL
) || (val
== NULL
)) {
2375 err
= SA_CONFIG_ERR
;
2380 if ((prop
= sa_get_property(opts
, name
)) == NULL
) {
2381 prop
= sa_create_property(name
, val
);
2383 err
= sa_valid_property(handle
, opts
,
2384 SMB_PROTOCOL_NAME
, prop
);
2386 (void) sa_remove_property(prop
);
2390 err
= sa_add_property(opts
, prop
);
2394 err
= sa_update_property(prop
, val
);
2399 cur
= nvlist_next_nvpair(nvl
, cur
);
2406 smb_saprop_getbool(sa_optionset_t opts
, char *propname
)
2410 boolean_t propval
= B_FALSE
;
2412 prop
= sa_get_property(opts
, propname
);
2413 if ((val
= sa_get_property_attr(prop
, "value")) != NULL
) {
2414 if ((strcasecmp(val
, "true") == 0) || (strcmp(val
, "1") == 0))
2423 smb_saprop_getstr(sa_optionset_t opts
, char *propname
, char *buf
, size_t bufsz
)
2428 prop
= sa_get_property(opts
, propname
);
2429 if ((val
= sa_get_property_attr(prop
, "value")) != NULL
) {
2430 (void) strlcpy(buf
, val
, bufsz
);