da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or http://www.opensolaris.org/os/licensing.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB specific functions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <stdio.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <string.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <ctype.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <stdlib.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <unistd.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <zone.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <errno.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <locale.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <fcntl.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/types.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/stat.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <syslog.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include "libshare.h"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include "libshare_impl.h"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <pwd.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <limits.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <libscf.h>
b56bf881a9655cb27b53cba1468312f7c6dfb0a2Antonello Cruz#include <libscf_priv.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <strings.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include "libshare_smb.h"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <rpcsvc/daemon_utils.h>
3db3f65c6274eb042354801a308c8e9bc4994553amw#include <smbsrv/smb_share.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/smbinfo.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/libsmb.h>
8d7e41661dc4633488e93b13363137523ce59977jose borrego#include <libdlpi.h>
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego#define SMB_CSC_BUFSZ 64
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#define SMB_VALID_SUB_CHRS "UDhMLmIiSPu" /* substitution characters */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/* internal functions */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_share_init(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void smb_share_fini(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_enable_share(sa_share_t);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_share_changed(sa_share_t);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_resource_changed(sa_resource_t);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_rename_resource(sa_handle_t, sa_resource_t, char *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_disable_share(sa_share_t share, char *);
687915e946710e354e302fa654bf53bf38b57cc6dougmstatic int smb_validate_property(sa_handle_t, sa_property_t, sa_optionset_t);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_set_proto_prop(sa_property_t);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic sa_protocol_properties_t smb_get_proto_set(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic char *smb_get_status(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_parse_optstring(sa_group_t, char *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic char *smb_format_options(sa_group_t, int);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_enable_service(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
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 *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_enable_resource(sa_resource_t);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_disable_resource(sa_resource_t);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic uint64_t smb_share_features(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_list_transient(sa_handle_t);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
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 *);
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borregostatic char *smb_csc_name(const 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 *);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
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 {
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego char *value;
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego uint32_t flag;
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego} cscopt[] = {
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { "disabled", SMB_SHRF_CSC_DISABLED },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { "manual", SMB_SHRF_CSC_MANUAL },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { "auto", SMB_SHRF_CSC_AUTO },
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego { "vdo", SMB_SHRF_CSC_VDO }
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego};
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/* size of basic format allocation */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define OPT_CHUNK 1024
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as/* size of string for types - big enough to hold "dependency" */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as#define SCFTYPE_LEN 32
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define PROTO_OPT_WINS1 6
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define PROTO_OPT_WINS_EXCLUDE 8
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borregotypedef struct smb_hostifs_walker {
8d7e41661dc4633488e93b13363137523ce59977jose borrego const char *hiw_ifname;
8d7e41661dc4633488e93b13363137523ce59977jose borrego boolean_t hiw_matchfound;
8d7e41661dc4633488e93b13363137523ce59977jose borrego} smb_hostifs_walker_t;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ops vector that provides the protocol specific info and operations
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * for share management.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstruct sa_plugin_ops sa_plugin_ops = {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw SA_PLUGIN_VERSION,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw SMB_PROTOCOL_NAME,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_share_init,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_share_fini,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_enable_share,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_disable_share,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_validate_property,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow NULL, /* valid_space */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow NULL, /* security_prop */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_parse_optstring,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_format_options,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_set_proto_prop,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_get_proto_set,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_get_status,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow NULL, /* space_alias */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow NULL, /* update_legacy */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow NULL, /* delete_legacy */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_share_changed,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_enable_resource,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_disable_resource,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_share_features,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_list_transient,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_resource_changed,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_rename_resource,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow NULL, /* run_command */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow NULL, /* command_help */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow NULL /* delete_proto_section */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstruct option_defs optdefs[] = {
8d7e41661dc4633488e93b13363137523ce59977jose borrego { SHOPT_AD_CONTAINER, OPT_TYPE_STRING },
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai { SHOPT_ABE, OPT_TYPE_BOOLEAN },
8d7e41661dc4633488e93b13363137523ce59977jose borrego { SHOPT_NAME, OPT_TYPE_NAME },
8d7e41661dc4633488e93b13363137523ce59977jose borrego { SHOPT_RO, OPT_TYPE_ACCLIST },
8d7e41661dc4633488e93b13363137523ce59977jose borrego { SHOPT_RW, OPT_TYPE_ACCLIST },
8d7e41661dc4633488e93b13363137523ce59977jose borrego { SHOPT_NONE, OPT_TYPE_ACCLIST },
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States { SHOPT_CATIA, OPT_TYPE_BOOLEAN },
8d7e41661dc4633488e93b13363137523ce59977jose borrego { SHOPT_CSC, OPT_TYPE_CSC },
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright { SHOPT_GUEST, OPT_TYPE_BOOLEAN },
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States { SHOPT_DFSROOT, OPT_TYPE_BOOLEAN },
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright { SHOPT_DESCRIPTION, OPT_TYPE_STRING },
8d7e41661dc4633488e93b13363137523ce59977jose borrego { NULL, NULL }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * findopt(name)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Lookup option "name" in the option table and return the table
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * index.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwfindopt(char *name)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int i;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (name != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; optdefs[i].tag != NULL; i++) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (strcmp(optdefs[i].tag, name) == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (i);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is_a_number(number)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is the string a number in one of the forms we want to use?
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregostatic boolean_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwis_a_number(char *number)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego boolean_t isnum = B_TRUE;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego boolean_t ishex = B_FALSE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (number == NULL || *number == '\0')
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (B_FALSE);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (strncasecmp(number, "0x", 2) == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw number += 2;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego ishex = B_TRUE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else if (*number == '-') {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego number++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego while (isnum && (*number != '\0')) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego isnum = (ishex) ? isxdigit(*number) : isdigit(*number);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego number++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (isnum);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States/*
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 States */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
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{
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);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States}
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * validresource(name)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregostatic boolean_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwvalidresource(const char *name)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw const char *cp;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t len;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (name == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (B_FALSE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw len = strlen(name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (len == 0 || len > SA_MAX_RESOURCE_NAME)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (B_FALSE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (strpbrk(name, "\"/\\[]:|<>+;,?*=\t") != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (B_FALSE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (cp = name; *cp != '\0'; cp++)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (iscntrl(*cp))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (B_FALSE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (B_TRUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego/*
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Check that the client-side caching (CSC) option value is valid.
8d7e41661dc4633488e93b13363137523ce59977jose borrego */
8d7e41661dc4633488e93b13363137523ce59977jose borregostatic boolean_t
8d7e41661dc4633488e93b13363137523ce59977jose borregovalidcsc(const char *value)
8d7e41661dc4633488e93b13363137523ce59977jose borrego{
8d7e41661dc4633488e93b13363137523ce59977jose borrego int i;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego for (i = 0; i < (sizeof (cscopt) / sizeof (cscopt[0])); ++i) {
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego if (strcasecmp(value, cscopt[i].value) == 0)
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (B_TRUE);
8d7e41661dc4633488e93b13363137523ce59977jose borrego }
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (B_FALSE);
8d7e41661dc4633488e93b13363137523ce59977jose borrego}
8d7e41661dc4633488e93b13363137523ce59977jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_isonline()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Determine if the SMF service instance is in the online state or
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * not. A number of operations depend on this state.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic boolean_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_isonline(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *str;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw boolean_t ret = B_FALSE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((str = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI)) != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = (strcmp(str, SCF_STATE_STRING_ONLINE) == 0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(str);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as/*
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * smb_isdisabled()
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as *
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Determine if the SMF service instance is in the disabled state or
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * not. A number of operations depend on this state.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5asstatic boolean_t
dc20a3024900c47dd2ee44b9707e6df38f7d62a5assmb_isdisabled(void)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as{
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as char *str;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as boolean_t ret = B_FALSE;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if ((str = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI)) != NULL) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as ret = (strcmp(str, SCF_STATE_STRING_DISABLED) == 0);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as free(str);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as return (ret);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as}
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as/*
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * smb_isautoenable()
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as *
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 */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5asstatic boolean_t
dc20a3024900c47dd2ee44b9707e6df38f7d62a5assmb_isautoenable(void)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as{
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as boolean_t ret = B_TRUE;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_simple_prop_t *prop;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as uint8_t *retstr;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as prop = scf_simple_prop_get(NULL, SMBD_DEFAULT_INSTANCE_FMRI,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as "application", "auto_enable");
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (prop != NULL) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as retstr = scf_simple_prop_next_boolean(prop);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as ret = *retstr != 0;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_simple_prop_free(prop);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as return (ret);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as}
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * smb_ismaint()
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * Determine if the SMF service instance is in the disabled state or
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * not. A number of operations depend on this state.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic boolean_t
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_ismaint(void)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb char *str;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb boolean_t ret = B_FALSE;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if ((str = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI)) != NULL) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb ret = (strcmp(str, SCF_STATE_STRING_MAINT) == 0);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb free(str);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (ret);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_enable_share(sa_share_t share)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *path;
3db3f65c6274eb042354801a308c8e9bc4994553amw smb_share_t si;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_resource_t resource;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw boolean_t iszfs;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw boolean_t privileged;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int err = SA_OK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw priv_set_t *priv_effective;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw boolean_t online;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
f85463f27ee24416b2ed04366664846e9b14ba9bdougm /*
8622ec4569457733001d4982ef7f5b44427069beGordon Ross * Don't support Trusted Extensions.
f85463f27ee24416b2ed04366664846e9b14ba9bdougm */
f85463f27ee24416b2ed04366664846e9b14ba9bdougm if (is_system_labeled()) {
f85463f27ee24416b2ed04366664846e9b14ba9bdougm (void) printf(dgettext(TEXT_DOMAIN,
f85463f27ee24416b2ed04366664846e9b14ba9bdougm "SMB: service not supported with Trusted Extensions\n"));
f85463f27ee24416b2ed04366664846e9b14ba9bdougm return (SA_NOT_SUPPORTED);
f85463f27ee24416b2ed04366664846e9b14ba9bdougm }
f85463f27ee24416b2ed04366664846e9b14ba9bdougm
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw priv_effective = priv_allocset();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) getppriv(PRIV_EFFECTIVE, priv_effective);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw privileged = (priv_isfullset(priv_effective) == B_TRUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw priv_freeset(priv_effective);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* get the path since it is important in several places */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw path = sa_get_share_attr(share, "path");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (path == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NO_SUCH_PATH);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as /*
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * If administratively disabled, don't try to start anything.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw online = smb_isonline();
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (!online && !smb_isautoenable() && smb_isdisabled())
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as goto done;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw iszfs = sa_path_is_zfs(path);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (iszfs) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (privileged == B_FALSE && !online) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!online) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) printf(dgettext(TEXT_DOMAIN,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "SMB: Cannot share remove "
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "file system: %s\n"), path);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) printf(dgettext(TEXT_DOMAIN,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "SMB: Service needs to be enabled "
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "by a privileged user\n"));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw err = SA_NO_PERMISSION;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw errno = EPERM;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (err) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(path);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (err);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (privileged == B_TRUE && !online) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw err = smb_enable_service();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (err != SA_OK) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) printf(dgettext(TEXT_DOMAIN,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "SMB: Unable to enable service\n"));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw online = B_TRUE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Don't bother trying to start shares if the service isn't
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * running.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!online)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw goto done;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Each share can have multiple resources */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (resource = sa_get_share_resource(share, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw resource != NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw resource = sa_get_next_resource(resource)) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego err = smb_build_shareinfo(share, resource, &si);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (err != SA_OK) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(path);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (err);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!iszfs) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego err = smb_share_create(&si);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw share_t sh;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
5ad42b1b1469908fabc0099764182e9ecbc04ddaSurya Prakki (void) sa_sharetab_fill_zfs(share, &sh, "smb");
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright err = sa_share_zfs(share, resource, (char *)path, &sh,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &si, ZFS_SHARE_SMB);
a63214d65accded81c7d937912d95a3532c47b5aBill Krier if (err != SA_OK) {
a63214d65accded81c7d937912d95a3532c47b5aBill Krier errno = err;
a63214d65accded81c7d937912d95a3532c47b5aBill Krier err = -1;
a63214d65accded81c7d937912d95a3532c47b5aBill Krier }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_emptyshare(&sh);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!iszfs)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) sa_update_sharetab(share, "smb");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwdone:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(path);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (err == NERR_DuplicateShare ? 0 : err);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_enable_resource(sa_resource_t resource)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_share_t share;
3db3f65c6274eb042354801a308c8e9bc4994553amw smb_share_t si;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as int ret = SA_OK;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as int err;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as boolean_t isonline;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw share = sa_get_resource_parent(resource);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (share == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NO_SUCH_PATH);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as /*
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * If administratively disabled, don't try to start anything.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as isonline = smb_isonline();
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (!isonline && !smb_isautoenable() && smb_isdisabled())
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (SA_OK);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (!isonline) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego (void) smb_enable_service();
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (!smb_isonline())
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (SA_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((ret = smb_build_shareinfo(share, resource, &si)) != SA_OK)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (ret);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as /*
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 */
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego err = smb_share_create(&si);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (err == NERR_Success || !(!isonline && err == NERR_DuplicateName))
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as (void) sa_update_sharetab(share, "smb");
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NOT_SHARED);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (SA_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Remove it from smb server hash.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_disable_resource(sa_resource_t resource)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *rname;
3db3f65c6274eb042354801a308c8e9bc4994553amw uint32_t res;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_share_t share;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rname = sa_get_resource_attr(resource, "name");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rname == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NO_SUCH_RESOURCE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smb_isonline()) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego res = smb_share_delete(rname);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (res != NERR_Success &&
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier res != NERR_NetNameNotFound) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(rname);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_CONFIG_ERR);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm sa_free_attr_string(rname);
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw share = sa_get_resource_parent(resource);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (share != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rname = sa_get_share_attr(share, "path");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rname != NULL) {
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm sa_handle_t handle;
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm handle = sa_find_group_handle((sa_group_t)resource);
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm (void) sa_delete_sharetab(handle, rname, "smb");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(rname);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Always return OK as smb/server may be down and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Shares will be picked up when loaded.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_share_changed(sa_share_t share)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The specified share has changed.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_share_changed(sa_share_t share)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *path;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_resource_t resource;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (!smb_isonline())
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (SA_OK);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* get the path since it is important in several places */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw path = sa_get_share_attr(share, "path");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (path == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NO_SUCH_PATH);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (resource = sa_get_share_resource(share, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw resource != NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw resource = sa_get_next_resource(resource))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) smb_resource_changed(resource);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(path);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_resource_changed(sa_resource_t resource)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The specified resource has changed.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_resource_changed(sa_resource_t resource)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw uint32_t res;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_share_t share;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego smb_share_t si;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (!smb_isonline())
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (SA_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((share = sa_get_resource_parent(resource)) == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_CONFIG_ERR);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((res = smb_build_shareinfo(share, resource, &si)) != SA_OK)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (res);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States res = smb_share_modify(&si);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (res != NERR_Success)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_CONFIG_ERR);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (smb_enable_service());
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm * smb_disable_share(sa_share_t share, char *path)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_disable_share(sa_share_t share, char *path)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *rname;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_resource_t resource;
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm sa_group_t parent;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw boolean_t iszfs;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int err = SA_OK;
a63214d65accded81c7d937912d95a3532c47b5aBill Krier int ret = SA_OK;
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm sa_handle_t handle;
1f713840d3b0fdc1eb54245ec133d1c87df73d13Doug McCallum boolean_t first = B_TRUE; /* work around sharetab issue */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm if (path == NULL)
a63214d65accded81c7d937912d95a3532c47b5aBill Krier return (ret);
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm /*
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.
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm */
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm parent = sa_get_parent_group(share);
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm iszfs = sa_group_is_zfs(parent);
8e314a4400960b022e9b9135577c1c0ceebd1e36dougm
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!smb_isonline())
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw goto done;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (resource = sa_get_share_resource(share, NULL);
a63214d65accded81c7d937912d95a3532c47b5aBill Krier resource != NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw resource = sa_get_next_resource(resource)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rname = sa_get_resource_attr(resource, "name");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rname == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw continue;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!iszfs) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego err = smb_share_delete(rname);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (err) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case NERR_NetNameNotFound:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case NERR_Success:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw err = SA_OK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw default:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw err = SA_CONFIG_ERR;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw share_t sh;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
5ad42b1b1469908fabc0099764182e9ecbc04ddaSurya Prakki (void) sa_sharetab_fill_zfs(share, &sh, "smb");
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright err = sa_share_zfs(share, resource, (char *)path, &sh,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rname, ZFS_UNSHARE_SMB);
a63214d65accded81c7d937912d95a3532c47b5aBill Krier if (err != SA_OK) {
a63214d65accded81c7d937912d95a3532c47b5aBill Krier switch (err) {
a63214d65accded81c7d937912d95a3532c47b5aBill Krier case EINVAL:
a63214d65accded81c7d937912d95a3532c47b5aBill Krier case ENOENT:
a63214d65accded81c7d937912d95a3532c47b5aBill Krier err = SA_OK;
a63214d65accded81c7d937912d95a3532c47b5aBill Krier break;
a63214d65accded81c7d937912d95a3532c47b5aBill Krier default:
a63214d65accded81c7d937912d95a3532c47b5aBill Krier /*
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.
a63214d65accded81c7d937912d95a3532c47b5aBill Krier */
a63214d65accded81c7d937912d95a3532c47b5aBill Krier if (!first)
a63214d65accded81c7d937912d95a3532c47b5aBill Krier err = SA_OK;
a63214d65accded81c7d937912d95a3532c47b5aBill Krier else
a63214d65accded81c7d937912d95a3532c47b5aBill Krier err = SA_SYSTEM_ERR;
a63214d65accded81c7d937912d95a3532c47b5aBill Krier break;
a63214d65accded81c7d937912d95a3532c47b5aBill Krier }
a63214d65accded81c7d937912d95a3532c47b5aBill Krier }
a63214d65accded81c7d937912d95a3532c47b5aBill Krier
1f713840d3b0fdc1eb54245ec133d1c87df73d13Doug McCallum first = B_FALSE;
1f713840d3b0fdc1eb54245ec133d1c87df73d13Doug McCallum
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_emptyshare(&sh);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
a63214d65accded81c7d937912d95a3532c47b5aBill Krier
a63214d65accded81c7d937912d95a3532c47b5aBill Krier if (err != SA_OK)
a63214d65accded81c7d937912d95a3532c47b5aBill Krier ret = err;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(rname);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwdone:
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm if (!iszfs) {
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm handle = sa_find_group_handle((sa_group_t)share);
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm if (handle != NULL)
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm (void) sa_delete_sharetab(handle, path, "smb");
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm else
a63214d65accded81c7d937912d95a3532c47b5aBill Krier ret = SA_SYSTEM_ERR;
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm }
a63214d65accded81c7d937912d95a3532c47b5aBill Krier return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
687915e946710e354e302fa654bf53bf38b57cc6dougm * smb_validate_property(handle, property, parent)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
687915e946710e354e302fa654bf53bf38b57cc6dougm/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
687915e946710e354e302fa654bf53bf38b57cc6dougmsmb_validate_property(sa_handle_t handle, sa_property_t property,
687915e946710e354e302fa654bf53bf38b57cc6dougm sa_optionset_t parent)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int ret = SA_OK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *propname;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int optindex;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_group_t parent_group;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *value;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States char *other;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw propname = sa_get_property_attr(property, "type");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((optindex = findopt(propname)) < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_NO_SUCH_PROP;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* need to validate value range here as well */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (ret == SA_OK) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw parent_group = sa_get_parent_group((sa_share_t)parent);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (optdefs[optindex].share && !sa_is_share(parent_group))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_PROP_SHARE_ONLY;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (ret != SA_OK) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (propname != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(propname);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw value = sa_get_property_attr(property, "value");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (value != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* first basic type checking */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (optdefs[optindex].type) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case OPT_TYPE_NUMBER:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* check that the value is all digits */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!is_a_number(value))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_BAD_VALUE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case OPT_TYPE_BOOLEAN:
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright ret = true_false_validator(0, value);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case OPT_TYPE_NAME:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Make sure no invalid characters
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (!validresource(value))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_BAD_VALUE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case OPT_TYPE_STRING:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* whatever is here should be ok */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
8d7e41661dc4633488e93b13363137523ce59977jose borrego case OPT_TYPE_CSC:
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (!validcsc(value))
8d7e41661dc4633488e93b13363137523ce59977jose borrego ret = SA_BAD_VALUE;
8d7e41661dc4633488e93b13363137523ce59977jose borrego break;
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 /*
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 */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (parent == NULL)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States break;
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 else
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 break;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
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 break;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States /*
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 */
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);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States }
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States break;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw default:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (value != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(value);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (ret == SA_OK && optdefs[optindex].check != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* do the property specific check */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = optdefs[optindex].check(property);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (propname != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(propname);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Protocol management functions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * properties defined in the default files are defined in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * proto_option_defs for parsing and validation.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstruct smb_proto_option_defs {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int smb_index;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int32_t minval;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int32_t maxval; /* In case of length of string this should be max */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int (*validator)(int, char *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int32_t refresh;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw} smb_proto_options[] = {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_SYS_CMNT, 0, MAX_VALUE_BUFLEN,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as string_length_check_validator, SMB_REFRESH_REFRESH },
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross { SMB_CI_MAX_WORKERS, SMB_PI_MAX_WORKERS_MIN, SMB_PI_MAX_WORKERS_MAX,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross range_check_validator, SMB_REFRESH_REFRESH },
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross { SMB_CI_NETBIOS_ENABLE, 0, 0, true_false_validator,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as SMB_REFRESH_REFRESH },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_NBSCOPE, 0, MAX_VALUE_BUFLEN,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as string_length_check_validator, 0 },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_LM_LEVEL, 2, 5, range_check_validator, 0 },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_KEEPALIVE, 20, 5400, range_check_validator_zero_ok,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as SMB_REFRESH_REFRESH },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_WINS_SRV1, 0, MAX_VALUE_BUFLEN,
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright ipv4_validator, SMB_REFRESH_REFRESH },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_WINS_SRV2, 0, MAX_VALUE_BUFLEN,
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright ipv4_validator, SMB_REFRESH_REFRESH },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_WINS_EXCL, 0, MAX_VALUE_BUFLEN,
8d7e41661dc4633488e93b13363137523ce59977jose borrego interface_validator, SMB_REFRESH_REFRESH },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_SIGNING_ENABLE, 0, 0, true_false_validator,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as SMB_REFRESH_REFRESH },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_SIGNING_REQD, 0, 0, true_false_validator,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as SMB_REFRESH_REFRESH },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_RESTRICT_ANON, 0, 0, true_false_validator,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as SMB_REFRESH_REFRESH },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_DOMAIN_SRV, 0, MAX_VALUE_BUFLEN,
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh hostname_validator, SMB_REFRESH_REFRESH },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_ADS_SITE, 0, MAX_VALUE_BUFLEN,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as string_length_check_validator, SMB_REFRESH_REFRESH },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_DYNDNS_ENABLE, 0, 0, true_false_validator, 0 },
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as { SMB_CI_AUTOHOME_MAP, 0, MAX_VALUE_BUFLEN, path_validator, 0 },
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego { SMB_CI_IPV6_ENABLE, 0, 0, true_false_validator,
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego SMB_REFRESH_REFRESH },
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross { SMB_CI_PRINT_ENABLE, 0, 0, print_enable_validator,
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh SMB_REFRESH_REFRESH },
5f1ef25c7a11451cbd3080dc3ce8e8db4ca996c4Aram Hăvărneanu { SMB_CI_TRAVERSE_MOUNTS, 0, 0, true_false_validator,
5f1ef25c7a11451cbd3080dc3ce8e8db4ca996c4Aram Hăvărneanu SMB_REFRESH_REFRESH },
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,
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright SMB_REFRESH_REFRESH },
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright { SMB_CI_DISPOSITION, 0, MAX_VALUE_BUFLEN,
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright disposition_validator, SMB_REFRESH_REFRESH },
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross { SMB_CI_MAX_PROTOCOL, 0, MAX_VALUE_BUFLEN, max_protocol_validator,
83d2dfe69259e79314662cf95e6d1f9103dcffe2Gordon Ross SMB_REFRESH_REFRESH },
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as#define SMB_OPT_NUM \
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as (sizeof (smb_proto_options) / sizeof (smb_proto_options[0]))
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check the range of value as int range.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwrange_check_validator(int index, char *value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int ret = SA_OK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!is_a_number(value)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_BAD_VALUE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int val;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw val = strtoul(value, NULL, 0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (val < smb_proto_options[index].minval ||
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw val > smb_proto_options[index].maxval)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_BAD_VALUE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check the range of value as int range.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwrange_check_validator_zero_ok(int index, char *value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int ret = SA_OK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!is_a_number(value)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_BAD_VALUE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int val;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw val = strtoul(value, NULL, 0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (val == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_OK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (val < smb_proto_options[index].minval ||
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw val > smb_proto_options[index].maxval)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_BAD_VALUE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check the length of the string
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstring_length_check_validator(int index, char *value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int ret = SA_OK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (value == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_BAD_VALUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (strlen(value) > smb_proto_options[index].maxval)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_BAD_VALUE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check yes/no
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwtrue_false_validator(int index, char *value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (value == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_BAD_VALUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((strcasecmp(value, "true") == 0) ||
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (strcasecmp(value, "false") == 0))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_BAD_VALUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross/*
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross * If printing support is compiled in, this is the same as:
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross * true_false_validator. Otherwise, only allow false.
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross */
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross/*ARGSUSED*/
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Rossstatic int
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Rossprint_enable_validator(int index, char *value)
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross{
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross if (value == NULL)
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross return (SA_BAD_VALUE);
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross#ifdef HAVE_CUPS
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross if (strcasecmp(value, "true") == 0)
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross return (SA_OK);
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross#endif
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross if (strcasecmp(value, "false") == 0)
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross return (SA_OK);
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross return (SA_BAD_VALUE);
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross}
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * Check IP v4 address.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightipv4_validator(int index, char *value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char sbytes[16];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (value == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_OK);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (strlen(value) == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_OK);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (inet_pton(AF_INET, value, (void *)sbytes) != 1)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_BAD_VALUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright/*
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 *
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.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright/*ARGSUSED*/
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic int
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintoshhostname_validator(int index, char *value)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright{
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh char sbytes[INET6_ADDRSTRLEN];
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh boolean_t new_label = B_TRUE;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh char *p;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh char label_terminator;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh int len;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (value == NULL)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_OK);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if ((len = strlen(value)) == 0)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh return (SA_OK);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (inet_pton(AF_INET, value, (void *)sbytes) == 1)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_OK);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (inet_pton(AF_INET6, value, (void *)sbytes) == 1)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh return (SA_OK);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (len >= MAXHOSTNAMELEN)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh return (SA_BAD_VALUE);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (strspn(value, "0123456789.") == len)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh return (SA_BAD_VALUE);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh label_terminator = *value;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh for (p = value; *p != '\0'; ++p) {
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (new_label) {
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (!isalnum(*p))
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh return (SA_BAD_VALUE);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh new_label = B_FALSE;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh label_terminator = *p;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh continue;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh }
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (*p == '.') {
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (!isalnum(label_terminator))
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh return (SA_BAD_VALUE);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh new_label = B_TRUE;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh label_terminator = *p;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh continue;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh }
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh label_terminator = *p;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (isalnum(*p) || *p == '-' || *p == '_')
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh continue;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh return (SA_BAD_VALUE);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh }
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (!isalnum(label_terminator))
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_BAD_VALUE);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_OK);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright}
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Call back function for dlpi_walk.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Returns TRUE if interface name exists on the host.
8d7e41661dc4633488e93b13363137523ce59977jose borrego */
8d7e41661dc4633488e93b13363137523ce59977jose borregostatic boolean_t
8d7e41661dc4633488e93b13363137523ce59977jose borregosmb_get_interface(const char *ifname, void *arg)
8d7e41661dc4633488e93b13363137523ce59977jose borrego{
8d7e41661dc4633488e93b13363137523ce59977jose borrego smb_hostifs_walker_t *iterp = arg;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego iterp->hiw_matchfound = (strcmp(ifname, iterp->hiw_ifname) == 0);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (iterp->hiw_matchfound);
8d7e41661dc4633488e93b13363137523ce59977jose borrego}
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego/*
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 */
8d7e41661dc4633488e93b13363137523ce59977jose borregostatic boolean_t
8d7e41661dc4633488e93b13363137523ce59977jose borregosmb_validate_interface(const char *ifname)
8d7e41661dc4633488e93b13363137523ce59977jose borrego{
8d7e41661dc4633488e93b13363137523ce59977jose borrego smb_hostifs_walker_t iter;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego if ((ifname == NULL) || (*ifname == '\0'))
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (B_FALSE);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego iter.hiw_ifname = ifname;
8d7e41661dc4633488e93b13363137523ce59977jose borrego iter.hiw_matchfound = B_FALSE;
8d7e41661dc4633488e93b13363137523ce59977jose borrego dlpi_walk(smb_get_interface, &iter, 0);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (iter.hiw_matchfound);
8d7e41661dc4633488e93b13363137523ce59977jose borrego}
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego/*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
8d7e41661dc4633488e93b13363137523ce59977jose borregointerface_validator(int index, char *value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
8d7e41661dc4633488e93b13363137523ce59977jose borrego char buf[16];
8d7e41661dc4633488e93b13363137523ce59977jose borrego int ret = SA_OK;
8d7e41661dc4633488e93b13363137523ce59977jose borrego char *ifname, *tmp, *p;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (value == NULL || *value == '\0')
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (strlen(value) > MAX_VALUE_BUFLEN)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_BAD_VALUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego if ((p = strdup(value)) == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NO_MEMORY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego tmp = p;
8d7e41661dc4633488e93b13363137523ce59977jose borrego while ((ifname = strsep(&tmp, ",")) != NULL) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (*ifname == '\0') {
8d7e41661dc4633488e93b13363137523ce59977jose borrego ret = SA_BAD_VALUE;
8d7e41661dc4633488e93b13363137523ce59977jose borrego break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (!smb_validate_interface(ifname)) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (inet_pton(AF_INET, ifname, (void *)buf) == 0) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego ret = SA_BAD_VALUE;
8d7e41661dc4633488e93b13363137523ce59977jose borrego break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego free(p);
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check path
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wrightpath_validator(int index, char *path)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct stat buffer;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int fd, status;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright if (path == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_BAD_VALUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright fd = open(path, O_RDONLY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (fd < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_BAD_VALUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw status = fstat(fd, &buffer);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(fd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (status < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_BAD_VALUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (buffer.st_mode & S_IFDIR)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_BAD_VALUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the protoset holds the defined options so we don't have to read
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * them multiple times
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic sa_protocol_properties_t protoset;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwfindprotoopt(char *name)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int i;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as char *sc_name;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as for (i = 0; i < SMB_OPT_NUM; i++) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as sc_name = smb_config_getname(smb_proto_options[i].smb_index);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (strcasecmp(sc_name, name) == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (i);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_load_proto_properties()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * read the smb config values from SMF.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_load_proto_properties()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_property_t prop;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as char value[MAX_VALUE_BUFLEN];
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as char *name;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int index;
e7bab3470ba5677ff5feec7af706721cfebcd6d5dougm int ret = SA_OK;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as int rc;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw protoset = sa_create_protocol_properties(SMB_PROTOCOL_NAME);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (protoset == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NO_MEMORY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
e7bab3470ba5677ff5feec7af706721cfebcd6d5dougm for (index = 0; index < SMB_OPT_NUM && ret == SA_OK; index++) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as rc = smb_config_get(smb_proto_options[index].smb_index,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as value, sizeof (value));
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (rc != SMBD_SMF_OK)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as continue;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as name = smb_config_getname(smb_proto_options[index].smb_index);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as prop = sa_create_property(name, value);
97df5ac96dbf15a7624a8e07b7dd686404d988c0dougm if (prop != NULL)
e7bab3470ba5677ff5feec7af706721cfebcd6d5dougm ret = sa_add_protocol_property(protoset, prop);
e7bab3470ba5677ff5feec7af706721cfebcd6d5dougm else
e7bab3470ba5677ff5feec7af706721cfebcd6d5dougm ret = SA_NO_MEMORY;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
e7bab3470ba5677ff5feec7af706721cfebcd6d5dougm return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_share_init()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Initialize the smb plugin.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_share_init(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (sa_plugin_ops.sa_init != smb_share_init)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_SYSTEM_ERR);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright smb_share_door_clnt_init();
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (smb_load_proto_properties());
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_share_fini()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_share_fini(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw xmlFreeNode(protoset);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw protoset = NULL;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright smb_share_door_clnt_fini();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_get_proto_set()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Return an optionset with all the protocol specific properties in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * it.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic sa_protocol_properties_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_get_proto_set(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (protoset);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as/*
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * smb_enable_dependencies()
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as *
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * SMBD_DEFAULT_INSTANCE_FMRI may have some dependencies that aren't
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * enabled. This will attempt to enable all of them.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5asstatic void
dc20a3024900c47dd2ee44b9707e6df38f7d62a5assmb_enable_dependencies(const char *fmri)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as{
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_handle_t *handle;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_service_t *service;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_instance_t *inst = NULL;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_iter_t *iter;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_property_t *prop;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_value_t *value;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_propertygroup_t *pg;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_scope_t *scope;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as char type[SCFTYPE_LEN];
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as char *dependency;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as char *servname;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as int maxlen;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as /*
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Get all required handles and storage.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as handle = scf_handle_create(SCF_VERSION);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (handle == NULL)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as return;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scf_handle_bind(handle) != 0) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_handle_destroy(handle);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as return;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as maxlen = scf_limit(SCF_LIMIT_MAX_VALUE_LENGTH);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (maxlen == (ssize_t)-1)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as maxlen = MAXPATHLEN;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as dependency = malloc(maxlen);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as service = scf_service_create(handle);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as iter = scf_iter_create(handle);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as pg = scf_pg_create(handle);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as prop = scf_property_create(handle);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as value = scf_value_create(handle);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scope = scf_scope_create(handle);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (service == NULL || iter == NULL || pg == NULL || prop == NULL ||
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as value == NULL || scope == NULL || dependency == NULL)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as goto done;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as /*
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 */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as (void) snprintf(dependency, maxlen, "%s", fmri + sizeof ("svc:"));
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as servname = strrchr(dependency, ':');
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (servname == NULL)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as goto done;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as *servname = '\0';
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as servname = dependency;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as /*
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 * on.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scf_handle_get_scope(handle, SCF_SCOPE_LOCAL, scope) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as goto done;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scf_scope_get_service(scope, servname, service) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as goto done;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scf_iter_service_pgs(iter, service) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as goto done;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as while (scf_iter_next_pg(iter, pg) > 0) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as char *services[2];
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as /*
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Have a property group for the service. See if it is
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * a dependency pg and only do operations on those.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scf_pg_get_type(pg, type, SCFTYPE_LEN) <= 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as continue;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (strncmp(type, SCF_GROUP_DEPENDENCY, SCFTYPE_LEN) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as continue;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as /*
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Have a dependency. Attempt to enable it.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scf_pg_get_property(pg, SCF_PROPERTY_ENTITIES, prop) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as continue;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scf_property_get_value(prop, value) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as continue;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as services[1] = NULL;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scf_value_get_as_string(value, dependency, maxlen) > 0) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as services[0] = dependency;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as _check_services(services);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5asdone:
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (dependency != NULL)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as free(dependency);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (value != NULL)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_value_destroy(value);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (prop != NULL)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_property_destroy(prop);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (pg != NULL)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_pg_destroy(pg);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (iter != NULL)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_iter_destroy(iter);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (scope != NULL)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_scope_destroy(scope);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (inst != NULL)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_instance_destroy(inst);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (service != NULL)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_service_destroy(service);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as (void) scf_handle_unbind(handle);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as scf_handle_destroy(handle);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as}
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * How long to wait for service to come online
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define WAIT_FOR_SERVICE 15
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_enable_service()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_enable_service(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int i;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int ret = SA_OK;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as char *service[] = { SMBD_DEFAULT_INSTANCE_FMRI, NULL };
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!smb_isonline()) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as /*
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.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smb_enable_dependencies(SMBD_DEFAULT_INSTANCE_FMRI);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as _check_services(service);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Wait for service to come online */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < WAIT_FOR_SERVICE; i++) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smb_isonline()) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as ret = SA_OK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb } else if (smb_ismaint()) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* maintenance requires help */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb ret = SA_SYSTEM_ERR;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* try another time */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_BUSY;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) sleep(1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_validate_proto_prop(index, name, value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_validate_proto_prop(int index, char *name, char *value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((name == NULL) || (index < 0))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_BAD_VALUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smb_proto_options[index].validator == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smb_proto_options[index].validator(index, value) == SA_OK)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_BAD_VALUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_set_proto_prop(prop)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * check that prop is valid.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_set_proto_prop(sa_property_t prop)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int ret = SA_OK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *name;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *value;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int index = -1;
55bf511df53aad0fdb7eb3fa349f0308cc05234cas struct smb_proto_option_defs *opt;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw name = sa_get_property_attr(prop, "type");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw value = sa_get_property_attr(prop, "value");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (name != NULL && value != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw index = findprotoopt(name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (index >= 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* should test for valid value */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = smb_validate_proto_prop(index, name, value);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (ret == SA_OK) {
55bf511df53aad0fdb7eb3fa349f0308cc05234cas opt = &smb_proto_options[index];
55bf511df53aad0fdb7eb3fa349f0308cc05234cas
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Save to SMF */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as (void) smb_config_set(opt->smb_index, value);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Specialized refresh mechanisms can
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * be flagged in the proto_options and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * processed here.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
55bf511df53aad0fdb7eb3fa349f0308cc05234cas if (opt->refresh & SMB_REFRESH_REFRESH)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb (void) smf_refresh_instance(
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb SMBD_DEFAULT_INSTANCE_FMRI);
55bf511df53aad0fdb7eb3fa349f0308cc05234cas else if (opt->refresh & SMB_REFRESH_RESTART)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) smf_restart_instance(
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw SMBD_DEFAULT_INSTANCE_FMRI);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
55bf511df53aad0fdb7eb3fa349f0308cc05234cas
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (name != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (value != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(value);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_get_status()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * What is the current status of the smbd? We use the SMF state here.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Caller must free the returned value.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_get_status(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
652601fb657e961ff66dadcd87ddfc146c5db0caRobert Mustacchi return (smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This protocol plugin require resource names
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic uint64_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_share_features(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_FEATURE_RESOURCE | SA_FEATURE_ALLOWSUBDIRS |
9e5da854b2fe0f3860a9b77dc30612faf2b0a42bdougm SA_FEATURE_ALLOWPARDIRS | SA_FEATURE_SERVER);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregosmb_add_transient(sa_handle_t handle, smb_share_t *si)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int err;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_share_t share;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_group_t group;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_resource_t resource;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh nvlist_t *nvl;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright char *opt;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (si == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_INVALID_NAME);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((share = sa_find_share(handle, si->shr_path)) == NULL) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((group = smb_get_defaultgrp(handle)) == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NO_SUCH_GROUP);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
3db3f65c6274eb042354801a308c8e9bc4994553amw share = sa_get_share(group, si->shr_path);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (share == NULL) {
3db3f65c6274eb042354801a308c8e9bc4994553amw share = sa_add_share(group, si->shr_path,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw SA_SHARE_TRANSIENT, &err);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (share == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NO_SUCH_PATH);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Now handle the resource. Make sure that the resource is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * transient and added to the share.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
3db3f65c6274eb042354801a308c8e9bc4994553amw resource = sa_get_share_resource(share, si->shr_name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (resource == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw resource = sa_add_resource(share,
3db3f65c6274eb042354801a308c8e9bc4994553amw si->shr_name, SA_SHARE_TRANSIENT, &err);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (resource == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NO_SUCH_RESOURCE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego if (si->shr_cmnt[0] != '\0')
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego (void) sa_set_resource_description(resource, si->shr_cmnt);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego if (si->shr_container[0] != '\0')
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego (void) sa_set_resource_attr(resource, SHOPT_AD_CONTAINER,
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego si->shr_container);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh return (SA_NO_MEMORY);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if ((opt = smb_csc_name(si)) != NULL)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh err |= nvlist_add_string(nvl, SHOPT_CSC, opt);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai opt = (si->shr_flags & SMB_SHRF_ABE) ? "true" : "false";
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh err |= nvlist_add_string(nvl, SHOPT_ABE, opt);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if ((si->shr_flags & SMB_SHRF_AUTOHOME) == 0) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright opt = (si->shr_flags & SMB_SHRF_GUEST_OK) ? "true" : "false";
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright err |= nvlist_add_string(nvl, SHOPT_GUEST, opt);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (si->shr_access_ro[0] != '\0')
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright err |= nvlist_add_string(nvl, SHOPT_RO, si->shr_access_ro);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (si->shr_access_rw[0] != '\0')
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright err |= nvlist_add_string(nvl, SHOPT_RW, si->shr_access_rw);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (si->shr_access_none[0] != '\0')
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright err |= nvlist_add_string(nvl, SHOPT_NONE, si->shr_access_none);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (err) {
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh nvlist_free(nvl);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh return (SA_CONFIG_ERR);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh err = smb_update_optionset_props(handle, resource, nvl);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh nvlist_free(nvl);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh return (err);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * Return smb transient shares.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_list_transient(sa_handle_t handle)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego int i, offset;
3db3f65c6274eb042354801a308c8e9bc4994553amw smb_shrlist_t list;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int res;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (smb_share_count() <= 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_OK);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw offset = 0;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego while (smb_share_list(offset, &list) == NERR_Success) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (list.sl_cnt == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego for (i = 0; i < list.sl_cnt; i++) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego res = smb_add_transient(handle, &(list.sl_shares[i]));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (res != SA_OK)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (res);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego offset += list.sl_cnt;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_OK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fix_resource_name(share, name, prefix)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Construct a name where the ZFS dataset has the prefix replaced with "name".
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwfix_resource_name(sa_share_t share, char *name, char *prefix)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego char buf[SA_MAX_RESOURCE_NAME + 1];
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego char *dataset;
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego size_t bufsz = SA_MAX_RESOURCE_NAME + 1;
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego size_t prelen;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright if (prefix == NULL)
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright return (strdup(name));
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw dataset = sa_get_share_attr(share, "dataset");
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego if (dataset == NULL)
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego return (strdup(name));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego (void) strlcpy(buf, name, bufsz);
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego prelen = strlen(prefix);
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego if (strncmp(dataset, prefix, prelen) == 0)
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego (void) strlcat(buf, dataset + prelen, bufsz);
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego sa_free_attr_string(dataset);
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego sa_fix_resource_name(buf);
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego return (strdup(buf));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_parse_optstring(group, options)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_parse_optstring(sa_group_t group, char *options)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *dup;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *base;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *lasts;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *token;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_optionset_t optionset;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_group_t parent = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_resource_t resource = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int iszfs = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int persist = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int need_optionset = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int ret = SA_OK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_property_t prop;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (sa_is_share(group)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *zfs;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw parent = sa_get_parent_group(group);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (parent != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw zfs = sa_get_group_attr(parent, "zfs");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (zfs != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(zfs);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw iszfs = 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw iszfs = sa_group_is_zfs(group);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (iszfs ||
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright strncmp(options, "name=", sizeof ("name=") - 1) == 0 ||
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw strstr(options, ",name=") != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_PROP_SHARE_ONLY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* do we have an existing optionset? */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw optionset = sa_get_optionset(group, "smb");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (optionset == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* didn't find existing optionset so create one */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw optionset = sa_create_optionset(group, "smb");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (optionset == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NO_MEMORY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If an optionset already exists, we've come through
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * twice so ignore the second time.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* We need a copy of options for the next part. */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw dup = strdup(options);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (dup == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NO_MEMORY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
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 *
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw persist = sa_is_persistent(group);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw base = dup;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw token = dup;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw lasts = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while (token != NULL && ret == SA_OK) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_OK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw token = strtok_r(base, ",", &lasts);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw base = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (token != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *value;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * All SMB properties have values so there
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * MUST be an '=' character. If it doesn't,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * it is a syntax error.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw value = strchr(token, '=');
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (value != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *value++ = '\0';
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_SYNTAX_ERR;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (strcmp(token, SHOPT_NAME) == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *prefix;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *name = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!iszfs) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_SYNTAX_ERR;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw prefix = sa_get_group_attr(parent, "prefix");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (prefix == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw prefix = sa_get_group_attr(parent,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "name");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (prefix != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) sa_set_group_attr(parent,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "prefix", prefix);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright name = fix_resource_name((sa_share_t)group,
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright value, prefix);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (name != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw resource = sa_add_resource(
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (sa_share_t)group, name,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw SA_SHARE_TRANSIENT, &ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_NO_MEMORY;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (prefix != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(prefix);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* A resource level optionset is needed */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw need_optionset = 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (resource == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_NO_MEMORY;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw continue;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (iszfs && strcmp(token, SHOPT_DESCRIPTION) == 0) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (resource == NULL)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (void) sa_set_share_description(
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (sa_share_t)group, value);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright else
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (void) sa_set_resource_description(
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright resource, value);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright continue;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (need_optionset) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw optionset = sa_create_optionset(resource,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "smb");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw need_optionset = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw prop = sa_create_property(token, value);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (prop == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_NO_MEMORY;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = sa_add_property(optionset, prop);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (ret != SA_OK)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!iszfs)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = sa_commit_properties(optionset, !persist);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(dup);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_sprint_option(rbuff, rbuffsize, incr, prop, sep)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_sprint_option(char **rbuff, size_t *rbuffsize, size_t incr,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_property_t prop, int sep)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *name;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *value;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int curlen;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *buff = *rbuff;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t buffsize = *rbuffsize;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw name = sa_get_property_attr(prop, "type");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw value = sa_get_property_attr(prop, "value");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (buff != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw curlen = strlen(buff);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw curlen = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (name != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int len;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw len = strlen(name) + sep;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A future RFE would be to replace this with more
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * generic code and to possibly handle more types.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 * interpret/transform.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (value != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw len += 1 + strlen(value);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw while (buffsize <= (curlen + len)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* need more room */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw buffsize += incr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw buff = realloc(buff, buffsize);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *rbuff = buff;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *rbuffsize = buffsize;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (buff == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* realloc failed so free everything */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (*rbuff != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(*rbuff);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw goto err;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (buff == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw goto err;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) snprintf(buff + curlen, buffsize - curlen,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "%s%s=%s", sep ? "," : "",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw name, value != NULL ? value : "\"\"");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwerr:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (name != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (value != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_attr_string(value);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_format_resource_options(resource, hier)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_format_options(sa_group_t group, int hier)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_optionset_t options = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_property_t prop;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int sep = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *buff;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t buffsize;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw buff = malloc(OPT_CHUNK);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (buff == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw buff[0] = '\0';
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw buffsize = OPT_CHUNK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw options = sa_get_derived_optionset(group, "smb", hier);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * do the default set first but skip any option that is also
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in the protocol specific optionset.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (options != NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (prop = sa_get_property(options, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw prop != NULL; prop = sa_get_next_property(prop)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * use this one since we skipped any
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * of these that were also in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * optdefault
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_sprint_option(&buff, &buffsize, OPT_CHUNK,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw prop, sep);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (buff == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
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 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (options != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_derived_optionset(
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw options);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (buff);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sep = 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (options != NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sa_free_derived_optionset(options);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (buff);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_rename_resource(resource, newname)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Change the current exported name of the resource to newname.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_rename_resource(sa_handle_t handle, sa_resource_t resource, char *newname)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int ret = SA_OK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int err;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *oldname;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (!smb_isonline())
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (SA_OK);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw oldname = sa_get_resource_attr(resource, "name");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (oldname == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SA_NO_SUCH_RESOURCE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego err = smb_share_rename(oldname, newname);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier sa_free_attr_string(oldname);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* improve error values somewhat */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (err) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case NERR_Success:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case NERR_InternalError:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_SYSTEM_ERR;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case NERR_DuplicateShare:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_DUPLICATE_NAME;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw default:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = SA_CONFIG_ERR;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregostatic int
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregosmb_build_shareinfo(sa_share_t share, sa_resource_t resource, smb_share_t *si)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego{
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego sa_optionset_t opts;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego char *path;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego char *rname;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego char *val = NULL;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States char csc_value[SMB_CSC_BUFSZ];
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego bzero(si, sizeof (smb_share_t));
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((path = sa_get_share_attr(share, "path")) == NULL)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (SA_NO_SUCH_PATH);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((rname = sa_get_resource_attr(resource, "name")) == NULL) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego sa_free_attr_string(path);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (SA_NO_SUCH_RESOURCE);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego }
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
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 sa_free_attr_string(path);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego sa_free_attr_string(rname);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego val = sa_get_resource_description(resource);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (val == NULL)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego val = sa_get_share_description(share);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (val != NULL) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego (void) strlcpy(si->shr_cmnt, val, sizeof (si->shr_cmnt));
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego sa_free_share_description(val);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego }
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
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);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (opts == NULL)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (SA_OK);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
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;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
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;
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai
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;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
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));
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
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);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
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;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
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;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego sa_free_derived_optionset(opts);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (SA_OK);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego}
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego/*
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 *
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 borrego */
8d7e41661dc4633488e93b13363137523ce59977jose borregostatic void
8d7e41661dc4633488e93b13363137523ce59977jose borregosmb_csc_option(const char *value, smb_share_t *si)
8d7e41661dc4633488e93b13363137523ce59977jose borrego{
8d7e41661dc4633488e93b13363137523ce59977jose borrego char buf[SMB_CSC_BUFSZ];
8d7e41661dc4633488e93b13363137523ce59977jose borrego int i;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego for (i = 0; i < (sizeof (cscopt) / sizeof (cscopt[0])); ++i) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (strcasecmp(value, cscopt[i].value) == 0) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego si->shr_flags |= cscopt[i].flag;
8d7e41661dc4633488e93b13363137523ce59977jose borrego break;
8d7e41661dc4633488e93b13363137523ce59977jose borrego }
8d7e41661dc4633488e93b13363137523ce59977jose borrego }
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego switch (si->shr_flags & SMB_SHRF_CSC_MASK) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego case 0:
8d7e41661dc4633488e93b13363137523ce59977jose borrego case SMB_SHRF_CSC_DISABLED:
8d7e41661dc4633488e93b13363137523ce59977jose borrego case SMB_SHRF_CSC_MANUAL:
8d7e41661dc4633488e93b13363137523ce59977jose borrego case SMB_SHRF_CSC_AUTO:
8d7e41661dc4633488e93b13363137523ce59977jose borrego case SMB_SHRF_CSC_VDO:
8d7e41661dc4633488e93b13363137523ce59977jose borrego break;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego default:
8d7e41661dc4633488e93b13363137523ce59977jose borrego buf[0] = '\0';
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego for (i = 0; i < (sizeof (cscopt) / sizeof (cscopt[0])); ++i) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (si->shr_flags & cscopt[i].flag) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego (void) strlcat(buf, " ", SMB_CSC_BUFSZ);
8d7e41661dc4633488e93b13363137523ce59977jose borrego (void) strlcat(buf, cscopt[i].value,
8d7e41661dc4633488e93b13363137523ce59977jose borrego SMB_CSC_BUFSZ);
8d7e41661dc4633488e93b13363137523ce59977jose borrego }
8d7e41661dc4633488e93b13363137523ce59977jose borrego }
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego syslog(LOG_ERR, "csc option conflict:%s", buf);
8d7e41661dc4633488e93b13363137523ce59977jose borrego break;
8d7e41661dc4633488e93b13363137523ce59977jose borrego }
8d7e41661dc4633488e93b13363137523ce59977jose borrego}
8d7e41661dc4633488e93b13363137523ce59977jose borrego
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego/*
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego * Return the option name for the first CSC flag (there should be only
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego * one) encountered in the share flags.
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego */
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borregostatic char *
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borregosmb_csc_name(const smb_share_t *si)
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego{
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego int i;
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego for (i = 0; i < (sizeof (cscopt) / sizeof (cscopt[0])); ++i) {
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego if (si->shr_flags & cscopt[i].flag)
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego return (cscopt[i].value);
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego }
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego return (NULL);
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego}
89dc44ce9705974a8bc4a39f1e878a0491a5be61jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego/*
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * smb_get_defaultgrp
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego *
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 *
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 */
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregostatic sa_group_t
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregosmb_get_defaultgrp(sa_handle_t handle)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego{
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego sa_group_t group = NULL;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego int err;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego group = sa_get_group(handle, SMB_DEFAULT_SHARE_GROUP);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (group != NULL)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (group);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego group = sa_create_group(handle, SMB_DEFAULT_SHARE_GROUP, &err);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (group == NULL)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (NULL);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (sa_create_optionset(group, SMB_DEFAULT_SHARE_GROUP) == NULL) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego (void) sa_remove_group(group);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego group = NULL;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego }
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (group);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego}
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright/*
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * Checks to see if the command args are the supported substitution specifier.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * i.e. <cmd> %U %S
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic int
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightcmd_validator(int index, char *value)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright{
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright char cmd[MAXPATHLEN];
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright char *ptr, *v;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright boolean_t skip_cmdname;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (string_length_check_validator(index, value) != SA_OK)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_BAD_VALUE);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (*value == '\0')
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_OK);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright (void) strlcpy(cmd, value, sizeof (cmd));
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright ptr = cmd;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright skip_cmdname = B_TRUE;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright do {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if ((v = strsep(&ptr, " ")) == NULL)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright break;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (*v != '\0') {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (skip_cmdname) {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright skip_cmdname = B_FALSE;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright continue;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright }
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if ((strlen(v) != 2) || *v != '%')
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_BAD_VALUE);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (strpbrk(v, SMB_VALID_SUB_CHRS) == NULL)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_BAD_VALUE);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright }
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright } while (v != NULL);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright /*
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * If skip_cmdname is still true then the string contains
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * only spaces. Don't allow such a string.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (skip_cmdname)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_BAD_VALUE);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_OK);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright}
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright/*ARGSUSED*/
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightstatic int
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightdisposition_validator(int index, char *value)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright{
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (value == NULL)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_BAD_VALUE);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (*value == '\0')
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_OK);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if ((strcasecmp(value, SMB_EXEC_DISP_CONTINUE) == 0) ||
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (strcasecmp(value, SMB_EXEC_DISP_TERMINATE) == 0))
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_OK);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (SA_BAD_VALUE);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright}
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross/*ARGSUSED*/
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic int
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossmax_protocol_validator(int index, char *value)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross{
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (value == NULL)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross return (SA_BAD_VALUE);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (*value == '\0')
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross return (SA_OK);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (smb_config_check_protocol(value) == 0)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross return (SA_OK);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross return (SA_BAD_VALUE);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross}
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh/*
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 *
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 mcintosh */
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintoshstatic int
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintoshsmb_update_optionset_props(sa_handle_t handle, sa_resource_t resource,
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh nvlist_t *nvl)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh{
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh sa_property_t prop;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh sa_optionset_t opts;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh int err = SA_OK;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh nvpair_t *cur;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh char *name, *val;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
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 (opts == NULL)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh return (SA_CONFIG_ERR);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh }
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh cur = nvlist_next_nvpair(nvl, NULL);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh while (cur != NULL) {
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh name = nvpair_name(cur);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh err = nvpair_value_string(cur, &val);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if ((err != 0) || (name == NULL) || (val == NULL)) {
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh err = SA_CONFIG_ERR;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh break;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh }
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh prop = NULL;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if ((prop = sa_get_property(opts, name)) == NULL) {
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh prop = sa_create_property(name, val);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (prop != NULL) {
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh err = sa_valid_property(handle, opts,
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh SMB_PROTOCOL_NAME, prop);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (err != SA_OK) {
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh (void) sa_remove_property(prop);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh break;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh }
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh }
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh err = sa_add_property(opts, prop);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (err != SA_OK)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh break;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh } else {
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh err = sa_update_property(prop, val);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh if (err != SA_OK)
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh break;
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh }
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh cur = nvlist_next_nvpair(nvl, cur);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh }
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh return (err);
96a62ada8aa6cb19b04270da282e7e21ba74b808joyce mcintosh}
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);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}