da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
c586600796766c83eb9485c446886fd9ed2359a9Keyur Desai * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB specific functions
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#define SMB_VALID_SUB_CHRS "UDhMLmIiSPu" /* substitution characters */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/* internal functions */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_share_init(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void smb_share_fini(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_rename_resource(sa_handle_t, sa_resource_t, char *);
687915e946710e354e302fa654bf53bf38b57cc6dougmstatic int smb_validate_property(sa_handle_t, sa_property_t, sa_optionset_t);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic char *smb_get_status(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_enable_service(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int range_check_validator(int, char *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int range_check_validator_zero_ok(int, char *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int string_length_check_validator(int, char *);
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Rossstatic int print_enable_validator(int, char *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int true_false_validator(int, char *);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic int ipv4_validator(int, char *);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintoshstatic int hostname_validator(int, char *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int path_validator(int, char *);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic int cmd_validator(int, char *);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic int disposition_validator(int, char *);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic int max_protocol_validator(int, char *);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregostatic int smb_build_shareinfo(sa_share_t, sa_resource_t, smb_share_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregostatic void smb_csc_option(const char *, smb_share_t *);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregostatic sa_group_t smb_get_defaultgrp(sa_handle_t);
8d7e41661dc4633488e93b13363137523ce59977jose borregostatic int interface_validator(int, char *);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintoshstatic int smb_update_optionset_props(sa_handle_t, sa_resource_t, nvlist_t *);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic boolean_t smb_saprop_getbool(sa_optionset_t, char *);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic boolean_t smb_saprop_getstr(sa_optionset_t, char *, char *, size_t);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borregostatic struct {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/* size of basic format allocation */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as/* size of string for types - big enough to hold "dependency" */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Indexes of entries in smb_proto_options table.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Changes to smb_proto_options table may require
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * an update to these values.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ops vector that provides the protocol specific info and operations
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * for share management.
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States { SHOPT_CATIA, OPT_TYPE_BOOLEAN },
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States { SHOPT_DFSROOT, OPT_TYPE_BOOLEAN },
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * findopt(name)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Lookup option "name" in the option table and return the table
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (i);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is_a_number(number)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is the string a number in one of the forms we want to use?
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego isnum = (ishex) ? isxdigit(*number) : isdigit(*number);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * check ro vs rw values. Over time this may get beefed up.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * for now it just does simple checks.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statesstatic int
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statescheck_rorw(char *v1, char *v2)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States int ret = SA_OK;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (strcmp(v1, v2) == 0)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States ret = SA_VALUE_CONFLICT;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * validresource(name)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check that name only has valid characters in it. The current valid
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * set are the printable characters but not including:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * " / \ [ ] : | < > + ; , ? * = \t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Note that space is included and there is a maximum length.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Check that the client-side caching (CSC) option value is valid.
8d7e41661dc4633488e93b13363137523ce59977jose borrego for (i = 0; i < (sizeof (cscopt) / sizeof (cscopt[0])); ++i) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_isonline()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Determine if the SMF service instance is in the online state or
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * not. A number of operations depend on this state.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((str = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI)) != NULL) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * smb_isdisabled()
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Determine if the SMF service instance is in the disabled state or
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * not. A number of operations depend on this state.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if ((str = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI)) != NULL) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * smb_isautoenable()
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Determine if the SMF service instance auto_enabled set or not. A
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * number of operations depend on this state. The property not being
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * set or being set to true means autoenable. Only being set to false
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * is not autoenabled.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as prop = scf_simple_prop_get(NULL, SMBD_DEFAULT_INSTANCE_FMRI,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * smb_ismaint()
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * Determine if the SMF service instance is in the disabled state or
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * not. A number of operations depend on this state.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if ((str = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI)) != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_enable_share tells the implementation that it is to enable the share.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This entails converting the path and options into the appropriate ioctl
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * calls. It is assumed that all error checking of paths, etc. were
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * done earlier.
8622ec4569457733001d4982ef7f5b44427069beGordon Ross * Don't support Trusted Extensions.
f85463f27ee24416b2ed04366664846e9b14ba9bdougm "SMB: service not supported with Trusted Extensions\n"));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw privileged = (priv_isfullset(priv_effective) == B_TRUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* get the path since it is important in several places */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * If administratively disabled, don't try to start anything.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "SMB: Cannot share remove "
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "SMB: Service needs to be enabled "
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "by a privileged user\n"));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "SMB: Unable to enable service\n"));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Don't bother trying to start shares if the service isn't
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * running.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Each share can have multiple resources */
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego err = smb_build_shareinfo(share, resource, &si);
5ad42b1b1469908fabc0099764182e9ecbc04ddaSurya Prakki (void) sa_sharetab_fill_zfs(share, &sh, "smb");
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright err = sa_share_zfs(share, resource, (char *)path, &sh,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This is the share for CIFS all shares have resource names.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Enable tells the smb server to update its hash. If it fails
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * because smb server is down, we just ignore as smb server loads
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the resources from sharemanager at startup.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * If administratively disabled, don't try to start anything.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (!isonline && !smb_isautoenable() && smb_isdisabled())
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((ret = smb_build_shareinfo(share, resource, &si)) != SA_OK)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Attempt to add the share. Any error that occurs if it was
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * online is an error but don't count NERR_DuplicateName if
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * smb/server had to be brought online since bringing the
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * service up will enable the share that was just added prior
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * to the attempt to enable.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (err == NERR_Success || !(!isonline && err == NERR_DuplicateName))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Remove it from smb server hash.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Always return OK as smb/server may be down and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Shares will be picked up when loaded.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_share_changed(sa_share_t share)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The specified share has changed.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* get the path since it is important in several places */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_resource_changed(sa_resource_t resource)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The specified resource has changed.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((share = sa_get_resource_parent(resource)) == NULL)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((res = smb_build_shareinfo(share, resource, &si)) != SA_OK)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States res = smb_share_modify(&si);
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm * smb_disable_share(sa_share_t share, char *path)
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm * Unshare the specified share. Note that "path" is the same
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm * path as what is in the "share" object. It is passed in to avoid an
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm * additional lookup. A missing "path" value makes this a no-op
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm * function.
1f713840d3b0fdc1eb54245ec133d1c87df73d13Doug McCallum boolean_t first = B_TRUE; /* work around sharetab issue */
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm * If the share is in a ZFS group we need to handle it
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm * differently. Just being on a ZFS file system isn't
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm * enough since we may be in a legacy share case.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (err) {
5ad42b1b1469908fabc0099764182e9ecbc04ddaSurya Prakki (void) sa_sharetab_fill_zfs(share, &sh, "smb");
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright err = sa_share_zfs(share, resource, (char *)path, &sh,
a63214d65accded81c7d937912d95a3532c47b5aBill Krier * If we are no longer the first case,
a63214d65accded81c7d937912d95a3532c47b5aBill Krier * we don't care about the sa_share_zfs
a63214d65accded81c7d937912d95a3532c47b5aBill Krier * err if it is -1. This works around
a63214d65accded81c7d937912d95a3532c47b5aBill Krier * a problem in sharefs and should be
a63214d65accded81c7d937912d95a3532c47b5aBill Krier * removed when sharefs supports
a63214d65accded81c7d937912d95a3532c47b5aBill Krier * multiple entries per path.
687915e946710e354e302fa654bf53bf38b57cc6dougm * smb_validate_property(handle, property, parent)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check that the property has a legitimate value for its type.
687915e946710e354e302fa654bf53bf38b57cc6dougm * Handle isn't currently used but may need to be in the future.
687915e946710e354e302fa654bf53bf38b57cc6dougm/*ARGSUSED*/
687915e946710e354e302fa654bf53bf38b57cc6dougmsmb_validate_property(sa_handle_t handle, sa_property_t property,
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char *other;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* need to validate value range here as well */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (optdefs[optindex].share && !sa_is_share(parent_group))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* first basic type checking */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* check that the value is all digits */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Make sure no invalid characters
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* whatever is here should be ok */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States case OPT_TYPE_ACCLIST: {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States sa_property_t oprop;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char *ovalue;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * access list handling. Should eventually
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * validate that all the values make sense.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Also, ro and rw may have cross value
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * conflicts.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (parent == NULL)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (strcmp(propname, SHOPT_RO) == 0)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States other = SHOPT_RW;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States else if (strcmp(propname, SHOPT_RW) == 0)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States other = SHOPT_RO;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States other = NULL;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (other == NULL)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /* compare rw(ro) with ro(rw) */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States oprop = sa_get_property(parent, other);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (oprop == NULL)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * only potential
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * confusion if other
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * exists
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States ovalue = sa_get_property_attr(oprop, "value");
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (ovalue != NULL) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States ret = check_rorw(value, ovalue);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States sa_free_attr_string(ovalue);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* do the property specific check */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Protocol management functions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * properties defined in the default files are defined in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * proto_option_defs for parsing and validation.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int32_t maxval; /* In case of length of string this should be max */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross { SMB_CI_MAX_WORKERS, SMB_PI_MAX_WORKERS_MIN, SMB_PI_MAX_WORKERS_MAX,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross { SMB_CI_NETBIOS_ENABLE, 0, 0, true_false_validator,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_KEEPALIVE, 20, 5400, range_check_validator_zero_ok,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_AUTOHOME_MAP, 0, MAX_VALUE_BUFLEN, path_validator, 0 },
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego { SMB_CI_IPV6_ENABLE, 0, 0, true_false_validator,
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross { SMB_CI_PRINT_ENABLE, 0, 0, print_enable_validator,
5f1ef25c7a11451cbd3080dc3ce8e8db4ca996c4Aram Hăvărneanu { SMB_CI_TRAVERSE_MOUNTS, 0, 0, true_false_validator,
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright { SMB_CI_MAP, 0, MAX_VALUE_BUFLEN, cmd_validator, SMB_REFRESH_REFRESH },
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright { SMB_CI_UNMAP, 0, MAX_VALUE_BUFLEN, cmd_validator,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross { SMB_CI_MAX_PROTOCOL, 0, MAX_VALUE_BUFLEN, max_protocol_validator,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as (sizeof (smb_proto_options) / sizeof (smb_proto_options[0]))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check the range of value as int range.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check the range of value as int range.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check the length of the string
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross * If printing support is compiled in, this is the same as:
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross * true_false_validator. Otherwise, only allow false.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * Check IP v4 address.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh * Check that the specified name is an IP address (v4 or v6) or a hostname.
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh * Per RFC 1035 and 1123, names may contain alphanumeric characters, hyphens
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh * and dots. The first and last character of a label must be alphanumeric.
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh * Interior characters may be alphanumeric or hypens.
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh * Domain names should not contain underscores but we allow them because
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh * Windows names are often in non-compliance with this rule.
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (inet_pton(AF_INET, value, (void *)sbytes) == 1)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (inet_pton(AF_INET6, value, (void *)sbytes) == 1)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (*p == '.') {
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Call back function for dlpi_walk.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Returns TRUE if interface name exists on the host.
8d7e41661dc4633488e93b13363137523ce59977jose borregosmb_get_interface(const char *ifname, void *arg)
8d7e41661dc4633488e93b13363137523ce59977jose borrego iterp->hiw_matchfound = (strcmp(ifname, iterp->hiw_ifname) == 0);
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Checks to see if the input interface exists on the host.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Returns B_TRUE if the match is found, B_FALSE otherwise.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Check valid interfaces. Interface names value can be NULL or empty.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Returns SA_BAD_VALUE if interface cannot be found on the host.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (inet_pton(AF_INET, ifname, (void *)buf) == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check path
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the protoset holds the defined options so we don't have to read
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * them multiple times
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as for (i = 0; i < SMB_OPT_NUM; i++) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as sc_name = smb_config_getname(smb_proto_options[i].smb_index);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (i);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_load_proto_properties()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * read the smb config values from SMF.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw protoset = sa_create_protocol_properties(SMB_PROTOCOL_NAME);
e7bab3470ba5677ff5feec7af706721cfebcd6d5dougm for (index = 0; index < SMB_OPT_NUM && ret == SA_OK; index++) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as name = smb_config_getname(smb_proto_options[index].smb_index);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_share_init()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Initialize the smb plugin.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_share_fini()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_get_proto_set()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Return an optionset with all the protocol specific properties in
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * smb_enable_dependencies()
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * SMBD_DEFAULT_INSTANCE_FMRI may have some dependencies that aren't
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * enabled. This will attempt to enable all of them.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5asstatic void
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Get all required handles and storage.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (service == NULL || iter == NULL || pg == NULL || prop == NULL ||
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * We passed in the FMRI for the default instance but for
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * some things we need the simple form so construct it. Since
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * we reuse the storage that dependency points to, we need to
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * use the servname early.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as (void) snprintf(dependency, maxlen, "%s", fmri + sizeof ("svc:"));
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Setup to iterate over the service property groups, only
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * looking at those that are "dependency" types. The "entity"
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * property will have the FMRI of the service we are dependent
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scf_handle_get_scope(handle, SCF_SCOPE_LOCAL, scope) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scf_scope_get_service(scope, servname, service) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Have a property group for the service. See if it is
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * a dependency pg and only do operations on those.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (strncmp(type, SCF_GROUP_DEPENDENCY, SCFTYPE_LEN) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Have a dependency. Attempt to enable it.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scf_pg_get_property(pg, SCF_PROPERTY_ENTITIES, prop) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scf_value_get_as_string(value, dependency, maxlen) > 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * How long to wait for service to come online
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_enable_service()
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Attempt to start the idmap, and other dependent
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * services, first. If it fails, the SMB service will
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * ultimately fail so we use that as the error. If we
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * don't try to enable idmap, smb won't start the
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * first time unless the admin has done it
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * manually. The service could be administratively
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * disabled so we won't always get started.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Wait for service to come online */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < WAIT_FOR_SERVICE; i++) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb } else if (smb_ismaint()) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* maintenance requires help */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* try another time */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_validate_proto_prop(index, name, value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Verify that the property specified by name can take the new
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * value. This is a sanity check to prevent bad values getting into
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the default files.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_validate_proto_prop(int index, char *name, char *value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smb_proto_options[index].validator(index, value) == SA_OK)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_set_proto_prop(prop)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * check that prop is valid.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (index >= 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* should test for valid value */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Save to SMF */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Specialized refresh mechanisms can
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * be flagged in the proto_options and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * processed here.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_get_status()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * What is the current status of the smbd? We use the SMF state here.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Caller must free the returned value.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic char *
652601fb657e961ff66dadcd87ddfc146c5db0caRobert Mustacchi return (smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This protocol plugin require resource names
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * This should be used to convert smb_share_t to sa_resource_t
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * Should only be needed to build transient shares/resources to be
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * supplied to sharemgr to display.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregosmb_add_transient(sa_handle_t handle, smb_share_t *si)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((share = sa_find_share(handle, si->shr_path)) == NULL) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((group = smb_get_defaultgrp(handle)) == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Now handle the resource. Make sure that the resource is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * transient and added to the share.
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego (void) sa_set_resource_description(resource, si->shr_cmnt);
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego (void) sa_set_resource_attr(resource, SHOPT_AD_CONTAINER,
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh err |= nvlist_add_string(nvl, SHOPT_CSC, opt);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai opt = (si->shr_flags & SMB_SHRF_ABE) ? "true" : "false";
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh err |= nvlist_add_string(nvl, SHOPT_ABE, opt);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright opt = (si->shr_flags & SMB_SHRF_GUEST_OK) ? "true" : "false";
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright err |= nvlist_add_string(nvl, SHOPT_GUEST, opt);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright err |= nvlist_add_string(nvl, SHOPT_RO, si->shr_access_ro);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright err |= nvlist_add_string(nvl, SHOPT_RW, si->shr_access_rw);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright err |= nvlist_add_string(nvl, SHOPT_NONE, si->shr_access_none);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh err = smb_update_optionset_props(handle, resource, nvl);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * Return smb transient shares.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego while (smb_share_list(offset, &list) == NERR_Success) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego res = smb_add_transient(handle, &(list.sl_shares[i]));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fix_resource_name(share, name, prefix)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Construct a name where the ZFS dataset has the prefix replaced with "name".
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwfix_resource_name(sa_share_t share, char *name, char *prefix)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_parse_optstring(group, options)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * parse a compact option string into individual options. This allows
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ZFS sharesmb and sharemgr "share" command to work. group can be a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * group, a share or a resource.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * In order to not attempt to change ZFS properties unless
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * absolutely necessary, we never do it in the legacy parsing
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * so we need to keep track of this.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If a ZFS group, then we need to see if a resource
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * name is being set. If so, bail with
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SA_PROP_SHARE_ONLY, so we come back in with a share
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * instead of a group.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright strncmp(options, "name=", sizeof ("name=") - 1) == 0 ||
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* do we have an existing optionset? */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* didn't find existing optionset so create one */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If an optionset already exists, we've come through
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * twice so ignore the second time.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* We need a copy of options for the next part. */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB properties are straightforward and are strings,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * integers or booleans. Properties are separated by
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * commas. It will be necessary to parse quotes due to some
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * strings not having a restricted characters set.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Note that names will create a resource. For now, if there
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is a set of properties "before" the first name="", those
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * properties will be placed on the group.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * All SMB properties have values so there
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * MUST be an '=' character. If it doesn't,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * it is a syntax error.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * We may need to handle a "name" property
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * that is a ZFS imposed resource name. Each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * name would trigger getting a new "resource"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to put properties on. For now, assume no
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * "name" property for special handling.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * We have a name, so now work on the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * resource level. We have a "share"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in "group" due to the caller having
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * added it. If we are called with a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * group, the check for group/share
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * at the beginning of this function
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * will bail out the parse if there is a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * "name" but no share.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Make sure the parent group has the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * "prefix" property since we will
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * need to use this for constructing
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * inherited name= values.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* A resource level optionset is needed */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (iszfs && strcmp(token, SHOPT_DESCRIPTION) == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_sprint_option(rbuff, rbuffsize, incr, prop, sep)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * provides a mechanism to format SMB properties into legacy output
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * format. If the buffer would overflow, it is reallocated and grown
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * as appropriate. Special cases of converting internal form of values
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to those used by "share" are done. this function does one property
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * at a time.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_sprint_option(char **rbuff, size_t *rbuffsize, size_t incr,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A future RFE would be to replace this with more
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * generic code and to possibly handle more types.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * For now, everything else is treated as a string. If
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * we get any properties that aren't exactly
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * name/value pairs, we may need to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* need more room */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* realloc failed so free everything */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_format_resource_options(resource, hier)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * format all the options on the group into a flattened option
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * string. If hier is non-zero, walk up the tree to get inherited
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * options.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * We may have a an optionset relative to this item. format
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * these if we find them and then add any security definitions.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * do the default set first but skip any option that is also
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in the protocol specific optionset.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * use this one since we skipped any
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * of these that were also in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * optdefault
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * buff could become NULL if there
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * isn't enough memory for
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_sprint_option to realloc()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * as necessary. We can't really
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * do anything about it at this
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * point so we return NULL. The
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * caller should handle the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * failure.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_rename_resource(resource, newname)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Change the current exported name of the resource to newname.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_rename_resource(sa_handle_t handle, sa_resource_t resource, char *newname)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* improve error values somewhat */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (err) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregosmb_build_shareinfo(sa_share_t share, sa_resource_t resource, smb_share_t *si)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States char csc_value[SMB_CSC_BUFSZ];
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((path = sa_get_share_attr(share, "path")) == NULL)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((rname = sa_get_resource_attr(resource, "name")) == NULL) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego (void) strlcpy(si->shr_path, path, sizeof (si->shr_path));
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego (void) strlcpy(si->shr_name, rname, sizeof (si->shr_name));
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego (void) strlcpy(si->shr_cmnt, val, sizeof (si->shr_cmnt));
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States si->shr_flags = (sa_is_persistent(share))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States ? SMB_SHRF_PERM : SMB_SHRF_TRANS;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego opts = sa_get_derived_optionset(resource, SMB_PROTOCOL_NAME, 1);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_saprop_getbool(opts, SHOPT_CATIA))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States si->shr_flags |= SMB_SHRF_CATIA;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_saprop_getbool(opts, SHOPT_ABE))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States si->shr_flags |= SMB_SHRF_ABE;
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_saprop_getbool(opts, SHOPT_GUEST))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States si->shr_flags |= SMB_SHRF_GUEST_OK;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_saprop_getbool(opts, SHOPT_DFSROOT))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States si->shr_flags |= SMB_SHRF_DFSROOT;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) smb_saprop_getstr(opts, SHOPT_AD_CONTAINER, si->shr_container,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States sizeof (si->shr_container));
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_saprop_getstr(opts, SHOPT_CSC, csc_value, sizeof (csc_value)))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_csc_option(csc_value, si);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_saprop_getstr(opts, SHOPT_RO, si->shr_access_ro,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States sizeof (si->shr_access_ro)))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States si->shr_flags |= SMB_SHRF_ACC_RO;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_saprop_getstr(opts, SHOPT_RW, si->shr_access_rw,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States sizeof (si->shr_access_rw)))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States si->shr_flags |= SMB_SHRF_ACC_RW;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_saprop_getstr(opts, SHOPT_NONE, si->shr_access_none,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States sizeof (si->shr_access_none)))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States si->shr_flags |= SMB_SHRF_ACC_NONE;
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Map a client-side caching (CSC) option to the appropriate share
8d7e41661dc4633488e93b13363137523ce59977jose borrego * flag. Only one option is allowed; an error will be logged if
8d7e41661dc4633488e93b13363137523ce59977jose borrego * multiple options have been specified. We don't need to do anything
8d7e41661dc4633488e93b13363137523ce59977jose borrego * about multiple values here because the SRVSVC will not recognize
8d7e41661dc4633488e93b13363137523ce59977jose borrego * a value containing multiple flags and will return the default value.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * If the option value is not recognized, it will be ignored: invalid
8d7e41661dc4633488e93b13363137523ce59977jose borrego * values will typically be caught and rejected by sharemgr.
8d7e41661dc4633488e93b13363137523ce59977jose borregosmb_csc_option(const char *value, smb_share_t *si)
8d7e41661dc4633488e93b13363137523ce59977jose borrego for (i = 0; i < (sizeof (cscopt) / sizeof (cscopt[0])); ++i) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego for (i = 0; i < (sizeof (cscopt) / sizeof (cscopt[0])); ++i) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego syslog(LOG_ERR, "csc option conflict:%s", buf);
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego * Return the option name for the first CSC flag (there should be only
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego * one) encountered in the share flags.
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borregostatic char *
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego for (i = 0; i < (sizeof (cscopt) / sizeof (cscopt[0])); ++i) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * smb_get_defaultgrp
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * If default group for CIFS shares (i.e. "smb") exists
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * then it will return the group handle, otherwise it will
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * create the group and return the handle.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * All the shares created by CIFS clients (this is only possible
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * via RPC) will be added to "smb" groups.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego group = sa_get_group(handle, SMB_DEFAULT_SHARE_GROUP);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego group = sa_create_group(handle, SMB_DEFAULT_SHARE_GROUP, &err);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (sa_create_optionset(group, SMB_DEFAULT_SHARE_GROUP) == NULL) {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * Checks to see if the command args are the supported substitution specifier.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * i.e. <cmd> %U %S
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (string_length_check_validator(index, value) != SA_OK)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (*v != '\0') {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright } while (v != NULL);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * If skip_cmdname is still true then the string contains
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * only spaces. Don't allow such a string.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if ((strcasecmp(value, SMB_EXEC_DISP_CONTINUE) == 0) ||
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (strcasecmp(value, SMB_EXEC_DISP_TERMINATE) == 0))
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh * Updates the optionset properties of the share resource.
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh * The properties are given as a list of name-value pair.
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh * The name argument should be the optionset property name and the value
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh * should be a valid value for the specified property.
c586600796766c83eb9485c446886fd9ed2359a9Keyur Desai * When calling this function for permanent shares, the caller must also
c586600796766c83eb9485c446886fd9ed2359a9Keyur Desai * call sa_commit_properties() to commit the changes to SMF.
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintoshsmb_update_optionset_props(sa_handle_t handle, sa_resource_t resource,
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if ((opts = sa_get_optionset(resource, SMB_PROTOCOL_NAME)) == NULL) {
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh opts = sa_create_optionset(resource, SMB_PROTOCOL_NAME);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if ((err != 0) || (name == NULL) || (val == NULL)) {
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if ((prop = sa_get_property(opts, name)) == NULL) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic boolean_t
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statessmb_saprop_getbool(sa_optionset_t opts, char *propname)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States sa_property_t prop;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States char *val;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States boolean_t propval = B_FALSE;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States prop = sa_get_property(opts, propname);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if ((val = sa_get_property_attr(prop, "value")) != NULL) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if ((strcasecmp(val, "true") == 0) || (strcmp(val, "1") == 0))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States propval = B_TRUE;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States free(val);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (propval);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic boolean_t
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statessmb_saprop_getstr(sa_optionset_t opts, char *propname, char *buf, size_t bufsz)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States sa_property_t prop;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States char *val;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States prop = sa_get_property(opts, propname);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if ((val = sa_get_property_attr(prop, "value")) != NULL) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States (void) strlcpy(buf, val, bufsz);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States free(val);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (B_TRUE);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (B_FALSE);