15331Samw /* 25331Samw * CDDL HEADER START 35331Samw * 45331Samw * The contents of this file are subject to the terms of the 55331Samw * Common Development and Distribution License (the "License"). 65331Samw * You may not use this file except in compliance with the License. 75331Samw * 85331Samw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95331Samw * or http://www.opensolaris.org/os/licensing. 105331Samw * See the License for the specific language governing permissions 115331Samw * and limitations under the License. 125331Samw * 135331Samw * When distributing Covered Code, include this CDDL HEADER in each 145331Samw * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155331Samw * If applicable, add the following below this CDDL HEADER, with the 165331Samw * fields enclosed by brackets "[]" replaced with your own identifying 175331Samw * information: Portions Copyright [yyyy] [name of copyright owner] 185331Samw * 195331Samw * CDDL HEADER END 205331Samw */ 215331Samw 225331Samw /* 235772Sas200622 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 245331Samw * Use is subject to license terms. 255331Samw */ 265331Samw 275331Samw #pragma ident "%Z%%M% %I% %E% SMI" 285331Samw 295331Samw /* 305331Samw * SMB specific functions 315331Samw */ 325331Samw #include <stdio.h> 335331Samw #include <string.h> 345331Samw #include <ctype.h> 355331Samw #include <stdlib.h> 365331Samw #include <unistd.h> 375331Samw #include <zone.h> 385331Samw #include <errno.h> 395331Samw #include <locale.h> 405331Samw #include <fcntl.h> 415331Samw #include <sys/types.h> 425331Samw #include <sys/stat.h> 435331Samw #include <syslog.h> 445331Samw #include "libshare.h" 455331Samw #include "libshare_impl.h" 465331Samw #include <pwd.h> 475331Samw #include <limits.h> 485331Samw #include <libscf.h> 495331Samw #include <strings.h> 505331Samw #include "libshare_smb.h" 515331Samw #include <rpcsvc/daemon_utils.h> 525331Samw #include <smbsrv/lmshare.h> 535331Samw #include <smbsrv/lmshare_door.h> 545331Samw #include <smbsrv/smbinfo.h> 555331Samw #include <smbsrv/libsmb.h> 565331Samw 575331Samw /* internal functions */ 585331Samw static int smb_share_init(void); 595331Samw static void smb_share_fini(void); 605331Samw static int smb_enable_share(sa_share_t); 615331Samw static int smb_share_changed(sa_share_t); 625331Samw static int smb_resource_changed(sa_resource_t); 635331Samw static int smb_rename_resource(sa_handle_t, sa_resource_t, char *); 645331Samw static int smb_disable_share(sa_share_t share, char *); 656214Sdougm static int smb_validate_property(sa_handle_t, sa_property_t, sa_optionset_t); 665331Samw static int smb_set_proto_prop(sa_property_t); 675331Samw static sa_protocol_properties_t smb_get_proto_set(void); 685331Samw static char *smb_get_status(void); 695331Samw static int smb_parse_optstring(sa_group_t, char *); 705331Samw static char *smb_format_options(sa_group_t, int); 715331Samw 725331Samw static int smb_enable_service(void); 735331Samw 745331Samw static int range_check_validator(int, char *); 755331Samw static int range_check_validator_zero_ok(int, char *); 765331Samw static int string_length_check_validator(int, char *); 775331Samw static int true_false_validator(int, char *); 785331Samw static int ip_address_validator_empty_ok(int, char *); 795331Samw static int ip_address_csv_list_validator_empty_ok(int, char *); 805331Samw static int path_validator(int, char *); 815331Samw 825331Samw static int smb_enable_resource(sa_resource_t); 835331Samw static int smb_disable_resource(sa_resource_t); 845331Samw static uint64_t smb_share_features(void); 855331Samw static int smb_list_transient(sa_handle_t); 865772Sas200622 875772Sas200622 extern void lmshrd_door_close(void); 885331Samw 895331Samw /* size of basic format allocation */ 905331Samw #define OPT_CHUNK 1024 915331Samw 925772Sas200622 /* size of string for types - big enough to hold "dependency" */ 935772Sas200622 #define SCFTYPE_LEN 32 945772Sas200622 955331Samw /* 965331Samw * Indexes of entries in smb_proto_options table. 975331Samw * Changes to smb_proto_options table may require 985331Samw * an update to these values. 995331Samw */ 1005331Samw #define PROTO_OPT_WINS1 6 1015331Samw #define PROTO_OPT_WINS_EXCLUDE 8 1025331Samw 1035331Samw 1045331Samw /* 1055331Samw * ops vector that provides the protocol specific info and operations 1065331Samw * for share management. 1075331Samw */ 1085331Samw 1095331Samw struct sa_plugin_ops sa_plugin_ops = { 1105331Samw SA_PLUGIN_VERSION, 1115331Samw SMB_PROTOCOL_NAME, 1125331Samw smb_share_init, 1135331Samw smb_share_fini, 1145331Samw smb_enable_share, 1155331Samw smb_disable_share, 1165331Samw smb_validate_property, 1176007Sthurlow NULL, /* valid_space */ 1186007Sthurlow NULL, /* security_prop */ 1195331Samw smb_parse_optstring, 1205331Samw smb_format_options, 1215331Samw smb_set_proto_prop, 1225331Samw smb_get_proto_set, 1235331Samw smb_get_status, 1246007Sthurlow NULL, /* space_alias */ 1256007Sthurlow NULL, /* update_legacy */ 1266007Sthurlow NULL, /* delete_legacy */ 1275331Samw smb_share_changed, 1285331Samw smb_enable_resource, 1295331Samw smb_disable_resource, 1305331Samw smb_share_features, 1315331Samw smb_list_transient, 1325331Samw smb_resource_changed, 1335331Samw smb_rename_resource, 1346007Sthurlow NULL, /* run_command */ 1356007Sthurlow NULL, /* command_help */ 1366007Sthurlow NULL /* delete_proto_section */ 1375331Samw }; 1385331Samw 1395331Samw /* 1405331Samw * option definitions. Make sure to keep the #define for the option 1415331Samw * index just before the entry it is the index for. Changing the order 1425331Samw * can cause breakage. 1435331Samw */ 1445331Samw 1455331Samw struct option_defs optdefs[] = { 1465331Samw {SHOPT_AD_CONTAINER, OPT_TYPE_STRING}, 1475331Samw {SHOPT_NAME, OPT_TYPE_NAME}, 1485331Samw {NULL, NULL}, 1495331Samw }; 1505331Samw 1515331Samw /* 1525331Samw * findopt(name) 1535331Samw * 1545331Samw * Lookup option "name" in the option table and return the table 1555331Samw * index. 1565331Samw */ 1575331Samw 1585331Samw static int 1595331Samw findopt(char *name) 1605331Samw { 1615331Samw int i; 1625331Samw if (name != NULL) { 1635331Samw for (i = 0; optdefs[i].tag != NULL; i++) { 1645331Samw if (strcmp(optdefs[i].tag, name) == 0) 1655331Samw return (i); 1665331Samw } 1675331Samw } 1685331Samw return (-1); 1695331Samw } 1705331Samw 1715331Samw /* 1725331Samw * is_a_number(number) 1735331Samw * 1745331Samw * is the string a number in one of the forms we want to use? 1755331Samw */ 1765331Samw 1775331Samw static int 1785331Samw is_a_number(char *number) 1795331Samw { 1805331Samw int ret = 1; 1815331Samw int hex = 0; 1825331Samw 1835331Samw if (strncmp(number, "0x", 2) == 0) { 1845331Samw number += 2; 1855331Samw hex = 1; 1865331Samw } else if (*number == '-') { 1875331Samw number++; /* skip the minus */ 1885331Samw } 1895331Samw 1905331Samw while (ret == 1 && *number != '\0') { 1915331Samw if (hex) { 1925331Samw ret = isxdigit(*number++); 1935331Samw } else { 1945331Samw ret = isdigit(*number++); 1955331Samw } 1965331Samw } 1975331Samw return (ret); 1985331Samw } 1995331Samw 2005331Samw /* 2015331Samw * validresource(name) 2025331Samw * 2035331Samw * Check that name only has valid characters in it. The current valid 2045331Samw * set are the printable characters but not including: 2055331Samw * " / \ [ ] : | < > + ; , ? * = \t 2065331Samw * Note that space is included and there is a maximum length. 2075331Samw */ 2085331Samw static int 2095331Samw validresource(const char *name) 2105331Samw { 2115331Samw const char *cp; 2125331Samw size_t len; 2135331Samw 2145331Samw if (name == NULL) 2155331Samw return (B_FALSE); 2165331Samw 2175331Samw len = strlen(name); 2185331Samw if (len == 0 || len > SA_MAX_RESOURCE_NAME) 2195331Samw return (B_FALSE); 2205331Samw 2215331Samw if (strpbrk(name, "\"/\\[]:|<>+;,?*=\t") != NULL) { 2225331Samw return (B_FALSE); 2235331Samw } 2245331Samw 2255331Samw for (cp = name; *cp != '\0'; cp++) 2265331Samw if (iscntrl(*cp)) 2275331Samw return (B_FALSE); 2285331Samw 2295331Samw return (B_TRUE); 2305331Samw } 2315331Samw 2325331Samw /* 2335331Samw * smb_isonline() 2345331Samw * 2355331Samw * Determine if the SMF service instance is in the online state or 2365331Samw * not. A number of operations depend on this state. 2375331Samw */ 2385331Samw static boolean_t 2395331Samw smb_isonline(void) 2405331Samw { 2415331Samw char *str; 2425331Samw boolean_t ret = B_FALSE; 2435331Samw 2445331Samw if ((str = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI)) != NULL) { 2455331Samw ret = (strcmp(str, SCF_STATE_STRING_ONLINE) == 0); 2465331Samw free(str); 2475331Samw } 2485331Samw return (ret); 2495331Samw } 2505331Samw 2515331Samw /* 2525772Sas200622 * smb_isdisabled() 2535772Sas200622 * 2545772Sas200622 * Determine if the SMF service instance is in the disabled state or 2555772Sas200622 * not. A number of operations depend on this state. 2565772Sas200622 */ 2575772Sas200622 static boolean_t 2585772Sas200622 smb_isdisabled(void) 2595772Sas200622 { 2605772Sas200622 char *str; 2615772Sas200622 boolean_t ret = B_FALSE; 2625772Sas200622 2635772Sas200622 if ((str = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI)) != NULL) { 2645772Sas200622 ret = (strcmp(str, SCF_STATE_STRING_DISABLED) == 0); 2655772Sas200622 free(str); 2665772Sas200622 } 2675772Sas200622 return (ret); 2685772Sas200622 } 2695772Sas200622 2705772Sas200622 /* 2715772Sas200622 * smb_isautoenable() 2725772Sas200622 * 2735772Sas200622 * Determine if the SMF service instance auto_enabled set or not. A 2745772Sas200622 * number of operations depend on this state. The property not being 2755772Sas200622 * set or being set to true means autoenable. Only being set to false 2765772Sas200622 * is not autoenabled. 2775772Sas200622 */ 2785772Sas200622 static boolean_t 2795772Sas200622 smb_isautoenable(void) 2805772Sas200622 { 2815772Sas200622 boolean_t ret = B_TRUE; 2825772Sas200622 scf_simple_prop_t *prop; 2835772Sas200622 uint8_t *retstr; 2845772Sas200622 2855772Sas200622 prop = scf_simple_prop_get(NULL, SMBD_DEFAULT_INSTANCE_FMRI, 2865772Sas200622 "application", "auto_enable"); 2875772Sas200622 if (prop != NULL) { 2885772Sas200622 retstr = scf_simple_prop_next_boolean(prop); 2895772Sas200622 ret = *retstr != 0; 2905772Sas200622 scf_simple_prop_free(prop); 2915772Sas200622 } 2925772Sas200622 return (ret); 2935772Sas200622 } 2945772Sas200622 2955772Sas200622 /* 2966030Sjb150015 * smb_ismaint() 2976030Sjb150015 * 2986030Sjb150015 * Determine if the SMF service instance is in the disabled state or 2996030Sjb150015 * not. A number of operations depend on this state. 3006030Sjb150015 */ 3016030Sjb150015 static boolean_t 3026030Sjb150015 smb_ismaint(void) 3036030Sjb150015 { 3046030Sjb150015 char *str; 3056030Sjb150015 boolean_t ret = B_FALSE; 3066030Sjb150015 3076030Sjb150015 if ((str = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI)) != NULL) { 3086030Sjb150015 ret = (strcmp(str, SCF_STATE_STRING_MAINT) == 0); 3096030Sjb150015 free(str); 3106030Sjb150015 } 3116030Sjb150015 return (ret); 3126030Sjb150015 } 3136030Sjb150015 3146030Sjb150015 /* 3155331Samw * smb_enable_share tells the implementation that it is to enable the share. 3165331Samw * This entails converting the path and options into the appropriate ioctl 3175331Samw * calls. It is assumed that all error checking of paths, etc. were 3185331Samw * done earlier. 3195331Samw */ 3205331Samw static int 3215331Samw smb_enable_share(sa_share_t share) 3225331Samw { 3235331Samw char *path; 3245331Samw char *rname; 3255331Samw lmshare_info_t si; 3265331Samw sa_resource_t resource; 3275331Samw boolean_t iszfs; 3285331Samw boolean_t privileged; 3295331Samw int err = SA_OK; 3305331Samw priv_set_t *priv_effective; 3315331Samw boolean_t online; 3325331Samw 3336270Sdougm /* 3346270Sdougm * We only start in the global zone and only run if we aren't 3356270Sdougm * running Trusted Extensions. 3366270Sdougm */ 3376270Sdougm if (getzoneid() != GLOBAL_ZONEID) { 3386270Sdougm (void) printf(dgettext(TEXT_DOMAIN, 3396270Sdougm "SMB: service not supported in local zone\n")); 3406270Sdougm return (SA_NOT_SUPPORTED); 3416270Sdougm } 3426270Sdougm if (is_system_labeled()) { 3436270Sdougm (void) printf(dgettext(TEXT_DOMAIN, 3446270Sdougm "SMB: service not supported with Trusted Extensions\n")); 3456270Sdougm return (SA_NOT_SUPPORTED); 3466270Sdougm } 3476270Sdougm 3485331Samw priv_effective = priv_allocset(); 3495331Samw (void) getppriv(PRIV_EFFECTIVE, priv_effective); 3505331Samw privileged = (priv_isfullset(priv_effective) == B_TRUE); 3515331Samw priv_freeset(priv_effective); 3525331Samw 3535331Samw /* get the path since it is important in several places */ 3545331Samw path = sa_get_share_attr(share, "path"); 3555331Samw if (path == NULL) 3565331Samw return (SA_NO_SUCH_PATH); 3575331Samw 3585772Sas200622 /* 3595772Sas200622 * If administratively disabled, don't try to start anything. 3605772Sas200622 */ 3615331Samw online = smb_isonline(); 3625772Sas200622 if (!online && !smb_isautoenable() && smb_isdisabled()) 3635772Sas200622 goto done; 3645331Samw 3655331Samw iszfs = sa_path_is_zfs(path); 3665331Samw 3675331Samw if (iszfs) { 3685331Samw 3695331Samw if (privileged == B_FALSE && !online) { 3705331Samw 3715331Samw if (!online) { 3725331Samw (void) printf(dgettext(TEXT_DOMAIN, 3735331Samw "SMB: Cannot share remove " 3745331Samw "file system: %s\n"), path); 3755331Samw (void) printf(dgettext(TEXT_DOMAIN, 3765331Samw "SMB: Service needs to be enabled " 3775331Samw "by a privileged user\n")); 3785331Samw err = SA_NO_PERMISSION; 3795331Samw errno = EPERM; 3805331Samw } 3815331Samw if (err) { 3825331Samw sa_free_attr_string(path); 3835331Samw return (err); 3845331Samw } 3855331Samw 3865331Samw } 3875331Samw } 3885331Samw 3895331Samw if (privileged == B_TRUE && !online) { 3905331Samw err = smb_enable_service(); 3915331Samw if (err != SA_OK) { 3925331Samw (void) printf(dgettext(TEXT_DOMAIN, 3935331Samw "SMB: Unable to enable service\n")); 3945331Samw /* 3955331Samw * For now, it is OK to not be able to enable 3965331Samw * the service. 3975331Samw */ 3986030Sjb150015 if (err == SA_BUSY || err == SA_SYSTEM_ERR) 3995331Samw err = SA_OK; 4005331Samw } else { 4015331Samw online = B_TRUE; 4025331Samw } 4035331Samw } 4045331Samw 4055331Samw /* 4065331Samw * Don't bother trying to start shares if the service isn't 4075331Samw * running. 4085331Samw */ 4095331Samw if (!online) 4105331Samw goto done; 4115331Samw 4125331Samw /* Each share can have multiple resources */ 4135331Samw for (resource = sa_get_share_resource(share, NULL); 4145331Samw resource != NULL; 4155331Samw resource = sa_get_next_resource(resource)) { 4165331Samw bzero(&si, sizeof (lmshare_info_t)); 4175331Samw rname = sa_get_resource_attr(resource, "name"); 4185331Samw if (rname == NULL) { 4195331Samw sa_free_attr_string(path); 4205331Samw return (SA_NO_SUCH_RESOURCE); 4215331Samw } 4225331Samw 423*6771Sjb150015 smb_build_lmshare_info(rname, path, resource, &si); 4245331Samw sa_free_attr_string(rname); 4255331Samw 4265331Samw if (!iszfs) { 4275331Samw err = lmshrd_add(&si); 4285331Samw } else { 4295331Samw share_t sh; 4305331Samw 4315331Samw sa_sharetab_fill_zfs(share, &sh, "smb"); 4325331Samw err = sa_share_zfs(share, (char *)path, &sh, 4335331Samw &si, ZFS_SHARE_SMB); 4345331Samw 4355331Samw sa_emptyshare(&sh); 4365331Samw } 4375331Samw } 4385331Samw if (!iszfs) 4395331Samw (void) sa_update_sharetab(share, "smb"); 4405331Samw done: 4415331Samw sa_free_attr_string(path); 4425331Samw 4435331Samw return (err == NERR_DuplicateShare ? 0 : err); 4445331Samw } 4455331Samw 4465331Samw /* 4475331Samw * This is the share for CIFS all shares have resource names. 4485331Samw * Enable tells the smb server to update its hash. If it fails 4495331Samw * because smb server is down, we just ignore as smb server loads 4505331Samw * the resources from sharemanager at startup. 4515331Samw */ 4525331Samw 4535331Samw static int 4545331Samw smb_enable_resource(sa_resource_t resource) 4555331Samw { 4565331Samw char *path; 4575331Samw char *rname; 4585331Samw sa_share_t share; 4595331Samw lmshare_info_t si; 4605772Sas200622 int ret = SA_OK; 4615772Sas200622 int err; 4625772Sas200622 boolean_t isonline; 4635331Samw 4645331Samw share = sa_get_resource_parent(resource); 4655331Samw if (share == NULL) 4665331Samw return (SA_NO_SUCH_PATH); 4675772Sas200622 4685772Sas200622 /* 4695772Sas200622 * If administratively disabled, don't try to start anything. 4705772Sas200622 */ 4715772Sas200622 isonline = smb_isonline(); 4725772Sas200622 if (!isonline && !smb_isautoenable() && smb_isdisabled()) 4735772Sas200622 goto done; 4745772Sas200622 4755772Sas200622 if (!isonline) 4765772Sas200622 ret = smb_enable_service(); 4775772Sas200622 if (!smb_isonline()) { 4785772Sas200622 ret = SA_OK; 4795772Sas200622 goto done; 4805772Sas200622 } 4815772Sas200622 4825331Samw path = sa_get_share_attr(share, "path"); 4835331Samw if (path == NULL) 4845331Samw return (SA_SYSTEM_ERR); 4855331Samw rname = sa_get_resource_attr(resource, "name"); 4865331Samw if (rname == NULL) { 4875331Samw sa_free_attr_string(path); 4885331Samw return (SA_NO_SUCH_RESOURCE); 4895331Samw } 4905331Samw 491*6771Sjb150015 smb_build_lmshare_info(rname, path, resource, &si); 4925331Samw sa_free_attr_string(path); 4935331Samw sa_free_attr_string(rname); 4945772Sas200622 4955772Sas200622 /* 4965772Sas200622 * Attempt to add the share. Any error that occurs if it was 4975772Sas200622 * online is an error but don't count NERR_DuplicateName if 4985772Sas200622 * smb/server had to be brought online since bringing the 4995772Sas200622 * service up will enable the share that was just added prior 5005772Sas200622 * to the attempt to enable. 5015772Sas200622 */ 5025772Sas200622 5035772Sas200622 err = lmshrd_add(&si); 5045772Sas200622 if (err == NERR_Success || !(!isonline && err == NERR_DuplicateName)) 5055772Sas200622 (void) sa_update_sharetab(share, "smb"); 5065772Sas200622 else 5075331Samw return (SA_NOT_SHARED); 5085331Samw 5095331Samw done: 5105331Samw return (ret); 5115331Samw } 5125331Samw 5135331Samw /* 5145331Samw * Remove it from smb server hash. 5155331Samw */ 5165331Samw static int 5175331Samw smb_disable_resource(sa_resource_t resource) 5185331Samw { 5195331Samw char *rname; 5205331Samw DWORD res; 5215331Samw sa_share_t share; 5225331Samw 5235331Samw rname = sa_get_resource_attr(resource, "name"); 5245331Samw if (rname == NULL) 5255331Samw return (SA_NO_SUCH_RESOURCE); 5265331Samw 5275331Samw if (smb_isonline()) { 5285331Samw res = lmshrd_delete(rname); 5295331Samw if (res != NERR_Success) { 5305331Samw sa_free_attr_string(rname); 5315331Samw return (SA_CONFIG_ERR); 5325331Samw } 5335331Samw } 5345951Sdougm 5355951Sdougm sa_free_attr_string(rname); 5365951Sdougm 5375331Samw share = sa_get_resource_parent(resource); 5385331Samw if (share != NULL) { 5395331Samw rname = sa_get_share_attr(share, "path"); 5405331Samw if (rname != NULL) { 5415951Sdougm sa_handle_t handle; 5425951Sdougm 5435951Sdougm handle = sa_find_group_handle((sa_group_t)resource); 5445951Sdougm (void) sa_delete_sharetab(handle, rname, "smb"); 5455331Samw sa_free_attr_string(rname); 5465331Samw } 5475331Samw } 5485331Samw /* 5495331Samw * Always return OK as smb/server may be down and 5505331Samw * Shares will be picked up when loaded. 5515331Samw */ 5525331Samw return (SA_OK); 5535331Samw } 5545331Samw 5555331Samw /* 5565331Samw * smb_share_changed(sa_share_t share) 5575331Samw * 5585331Samw * The specified share has changed. 5595331Samw */ 5605331Samw static int 5615331Samw smb_share_changed(sa_share_t share) 5625331Samw { 5635331Samw char *path; 5645331Samw sa_resource_t resource; 5655331Samw 5665331Samw /* get the path since it is important in several places */ 5675331Samw path = sa_get_share_attr(share, "path"); 5685331Samw if (path == NULL) 5695331Samw return (SA_NO_SUCH_PATH); 5705331Samw for (resource = sa_get_share_resource(share, NULL); 5715331Samw resource != NULL; 5725331Samw resource = sa_get_next_resource(resource)) 5735331Samw (void) smb_resource_changed(resource); 5745331Samw 5755331Samw sa_free_attr_string(path); 5765331Samw 5775331Samw return (SA_OK); 5785331Samw } 5795331Samw 5805331Samw /* 5815331Samw * smb_resource_changed(sa_resource_t resource) 5825331Samw * 5835331Samw * The specified resource has changed. 5845331Samw */ 5855331Samw static int 5865331Samw smb_resource_changed(sa_resource_t resource) 5875331Samw { 5885331Samw DWORD res; 5895331Samw lmshare_info_t si; 5905331Samw lmshare_info_t new_si; 5915331Samw char *rname, *path; 5925331Samw sa_share_t share; 5935331Samw 5945331Samw rname = sa_get_resource_attr(resource, "name"); 5955331Samw if (rname == NULL) 5965331Samw return (SA_NO_SUCH_RESOURCE); 5975331Samw 5985331Samw share = sa_get_resource_parent(resource); 5995331Samw if (share == NULL) { 6005331Samw sa_free_attr_string(rname); 6015331Samw return (SA_CONFIG_ERR); 6025331Samw } 6035331Samw 6045331Samw path = sa_get_share_attr(share, "path"); 6055331Samw if (path == NULL) { 6065331Samw sa_free_attr_string(rname); 6075331Samw return (SA_NO_SUCH_PATH); 6085331Samw } 6095331Samw 6105331Samw if (!smb_isonline()) { 6115331Samw sa_free_attr_string(rname); 6125331Samw return (SA_OK); 6135331Samw } 6145331Samw 6155331Samw /* Update the share cache in smb/server */ 6165331Samw res = lmshrd_getinfo(rname, &si); 6175331Samw if (res != NERR_Success) { 6185331Samw sa_free_attr_string(path); 6195331Samw sa_free_attr_string(rname); 6205331Samw return (SA_CONFIG_ERR); 6215331Samw } 6225331Samw 623*6771Sjb150015 smb_build_lmshare_info(rname, path, resource, &new_si); 6245331Samw sa_free_attr_string(path); 6255331Samw sa_free_attr_string(rname); 6265331Samw 6275331Samw /* 6285331Samw * Update all fields from sa_share_t 6295331Samw * Get derived values. 6305331Samw */ 6315331Samw if (lmshrd_setinfo(&new_si) != LMSHR_DOOR_SRV_SUCCESS) 6325331Samw return (SA_CONFIG_ERR); 6335331Samw return (smb_enable_service()); 6345331Samw } 6355331Samw 6365331Samw /* 6375800Sdougm * smb_disable_share(sa_share_t share, char *path) 6385331Samw * 6395800Sdougm * Unshare the specified share. Note that "path" is the same 6405800Sdougm * path as what is in the "share" object. It is passed in to avoid an 6415800Sdougm * additional lookup. A missing "path" value makes this a no-op 6425800Sdougm * function. 6435331Samw */ 6445331Samw static int 6455331Samw smb_disable_share(sa_share_t share, char *path) 6465331Samw { 6475331Samw char *rname; 6485331Samw sa_resource_t resource; 6495800Sdougm sa_group_t parent; 6505331Samw boolean_t iszfs; 6515331Samw int err = SA_OK; 6525951Sdougm sa_handle_t handle; 6535331Samw 6545800Sdougm if (path == NULL) 6555800Sdougm return (err); 6565800Sdougm 6575800Sdougm /* 6585800Sdougm * If the share is in a ZFS group we need to handle it 6595800Sdougm * differently. Just being on a ZFS file system isn't 6605800Sdougm * enough since we may be in a legacy share case. 6615800Sdougm */ 6625800Sdougm parent = sa_get_parent_group(share); 6635800Sdougm iszfs = sa_group_is_zfs(parent); 6645800Sdougm 6655331Samw if (!smb_isonline()) 6665331Samw goto done; 6675331Samw 6685331Samw for (resource = sa_get_share_resource(share, NULL); 6695331Samw resource != NULL; 6705331Samw resource = sa_get_next_resource(resource)) { 6715331Samw rname = sa_get_resource_attr(resource, "name"); 6725331Samw if (rname == NULL) { 6735331Samw continue; 6745331Samw } 6755331Samw if (!iszfs) { 6765331Samw err = lmshrd_delete(rname); 6775331Samw switch (err) { 6785331Samw case NERR_NetNameNotFound: 6795331Samw case NERR_Success: 6805331Samw err = SA_OK; 6815331Samw break; 6825331Samw default: 6835331Samw err = SA_CONFIG_ERR; 6845331Samw break; 6855331Samw } 6865331Samw } else { 6875331Samw share_t sh; 6885331Samw 6895331Samw sa_sharetab_fill_zfs(share, &sh, "smb"); 6905331Samw err = sa_share_zfs(share, (char *)path, &sh, 6915331Samw rname, ZFS_UNSHARE_SMB); 6925331Samw sa_emptyshare(&sh); 6935331Samw } 6945331Samw sa_free_attr_string(rname); 6955331Samw } 6965331Samw done: 6975951Sdougm if (!iszfs) { 6985951Sdougm handle = sa_find_group_handle((sa_group_t)share); 6995951Sdougm if (handle != NULL) 7005951Sdougm (void) sa_delete_sharetab(handle, path, "smb"); 7015951Sdougm else 7025951Sdougm err = SA_SYSTEM_ERR; 7035951Sdougm } 7045331Samw return (err); 7055331Samw } 7065331Samw 7075331Samw /* 7086214Sdougm * smb_validate_property(handle, property, parent) 7095331Samw * 7105331Samw * Check that the property has a legitimate value for its type. 7116214Sdougm * Handle isn't currently used but may need to be in the future. 7125331Samw */ 7135331Samw 7146214Sdougm /*ARGSUSED*/ 7155331Samw static int 7166214Sdougm smb_validate_property(sa_handle_t handle, sa_property_t property, 7176214Sdougm sa_optionset_t parent) 7185331Samw { 7195331Samw int ret = SA_OK; 7205331Samw char *propname; 7215331Samw int optindex; 7225331Samw sa_group_t parent_group; 7235331Samw char *value; 7245331Samw 7255331Samw propname = sa_get_property_attr(property, "type"); 7265331Samw 7275331Samw if ((optindex = findopt(propname)) < 0) 7285331Samw ret = SA_NO_SUCH_PROP; 7295331Samw 7305331Samw /* need to validate value range here as well */ 7315331Samw if (ret == SA_OK) { 7325331Samw parent_group = sa_get_parent_group((sa_share_t)parent); 7335331Samw if (optdefs[optindex].share && !sa_is_share(parent_group)) 7345331Samw ret = SA_PROP_SHARE_ONLY; 7355331Samw } 7365331Samw if (ret != SA_OK) { 7375331Samw if (propname != NULL) 7385331Samw sa_free_attr_string(propname); 7395331Samw return (ret); 7405331Samw } 7415331Samw 7425331Samw value = sa_get_property_attr(property, "value"); 7435331Samw if (value != NULL) { 7445331Samw /* first basic type checking */ 7455331Samw switch (optdefs[optindex].type) { 7465331Samw case OPT_TYPE_NUMBER: 7475331Samw /* check that the value is all digits */ 7485331Samw if (!is_a_number(value)) 7495331Samw ret = SA_BAD_VALUE; 7505331Samw break; 7515331Samw case OPT_TYPE_BOOLEAN: 7525331Samw if (strlen(value) == 0 || 7535331Samw strcasecmp(value, "true") == 0 || 7545331Samw strcmp(value, "1") == 0 || 7555331Samw strcasecmp(value, "false") == 0 || 7565331Samw strcmp(value, "0") == 0) { 7575331Samw ret = SA_OK; 7585331Samw } else { 7595331Samw ret = SA_BAD_VALUE; 7605331Samw } 7615331Samw break; 7625331Samw case OPT_TYPE_NAME: 7635331Samw /* 7645331Samw * Make sure no invalid characters 7655331Samw */ 7665331Samw if (validresource(value) == B_FALSE) 7675331Samw ret = SA_BAD_VALUE; 7685331Samw break; 7695331Samw case OPT_TYPE_STRING: 7705331Samw /* whatever is here should be ok */ 7715331Samw break; 7725331Samw default: 7735331Samw break; 7745331Samw } 7755331Samw } 7765331Samw 7775331Samw if (value != NULL) 7785331Samw sa_free_attr_string(value); 7795331Samw if (ret == SA_OK && optdefs[optindex].check != NULL) 7805331Samw /* do the property specific check */ 7815331Samw ret = optdefs[optindex].check(property); 7825331Samw 7835331Samw if (propname != NULL) 7845331Samw sa_free_attr_string(propname); 7855331Samw return (ret); 7865331Samw } 7875331Samw 7885331Samw /* 7895331Samw * Protocol management functions 7905331Samw * 7915331Samw * properties defined in the default files are defined in 7925331Samw * proto_option_defs for parsing and validation. 7935331Samw */ 7945331Samw 7955331Samw struct smb_proto_option_defs { 7965331Samw int smb_index; 7975331Samw int32_t minval; 7985331Samw int32_t maxval; /* In case of length of string this should be max */ 7995331Samw int (*validator)(int, char *); 8005331Samw int32_t refresh; 8015331Samw } smb_proto_options[] = { 8025772Sas200622 { SMB_CI_SYS_CMNT, 0, MAX_VALUE_BUFLEN, 8035772Sas200622 string_length_check_validator, SMB_REFRESH_REFRESH }, 8045772Sas200622 { SMB_CI_MAX_WORKERS, 64, 1024, range_check_validator, 8055772Sas200622 SMB_REFRESH_REFRESH }, 8065772Sas200622 { SMB_CI_NBSCOPE, 0, MAX_VALUE_BUFLEN, 8075772Sas200622 string_length_check_validator, 0 }, 8085772Sas200622 { SMB_CI_LM_LEVEL, 2, 5, range_check_validator, 0 }, 8095772Sas200622 { SMB_CI_KEEPALIVE, 20, 5400, range_check_validator_zero_ok, 8105772Sas200622 SMB_REFRESH_REFRESH }, 8115772Sas200622 { SMB_CI_WINS_SRV1, 0, MAX_VALUE_BUFLEN, 8125772Sas200622 ip_address_validator_empty_ok, SMB_REFRESH_REFRESH }, 8135772Sas200622 { SMB_CI_WINS_SRV2, 0, MAX_VALUE_BUFLEN, 8145772Sas200622 ip_address_validator_empty_ok, SMB_REFRESH_REFRESH }, 8155772Sas200622 { SMB_CI_WINS_EXCL, 0, MAX_VALUE_BUFLEN, 8165772Sas200622 ip_address_csv_list_validator_empty_ok, SMB_REFRESH_REFRESH }, 8175772Sas200622 { SMB_CI_SIGNING_ENABLE, 0, 0, true_false_validator, 8185772Sas200622 SMB_REFRESH_REFRESH }, 8195772Sas200622 { SMB_CI_SIGNING_REQD, 0, 0, true_false_validator, 8205772Sas200622 SMB_REFRESH_REFRESH }, 8215772Sas200622 { SMB_CI_RESTRICT_ANON, 0, 0, true_false_validator, 8225772Sas200622 SMB_REFRESH_REFRESH }, 8235772Sas200622 { SMB_CI_DOMAIN_SRV, 0, MAX_VALUE_BUFLEN, 8245772Sas200622 ip_address_validator_empty_ok, 0 }, 8255772Sas200622 { SMB_CI_ADS_SITE, 0, MAX_VALUE_BUFLEN, 8265772Sas200622 string_length_check_validator, SMB_REFRESH_REFRESH }, 8275772Sas200622 { SMB_CI_DYNDNS_ENABLE, 0, 0, true_false_validator, 0 }, 8285772Sas200622 { SMB_CI_AUTOHOME_MAP, 0, MAX_VALUE_BUFLEN, path_validator, 0 }, 8295331Samw }; 8305331Samw 8315772Sas200622 #define SMB_OPT_NUM \ 8325772Sas200622 (sizeof (smb_proto_options) / sizeof (smb_proto_options[0])) 8335772Sas200622 8345331Samw /* 8355331Samw * Check the range of value as int range. 8365331Samw */ 8375331Samw static int 8385331Samw range_check_validator(int index, char *value) 8395331Samw { 8405331Samw int ret = SA_OK; 8415331Samw 8425331Samw if (!is_a_number(value)) { 8435331Samw ret = SA_BAD_VALUE; 8445331Samw } else { 8455331Samw int val; 8465331Samw val = strtoul(value, NULL, 0); 8475331Samw if (val < smb_proto_options[index].minval || 8485331Samw val > smb_proto_options[index].maxval) 8495331Samw ret = SA_BAD_VALUE; 8505331Samw } 8515331Samw return (ret); 8525331Samw } 8535331Samw 8545331Samw /* 8555331Samw * Check the range of value as int range. 8565331Samw */ 8575331Samw static int 8585331Samw range_check_validator_zero_ok(int index, char *value) 8595331Samw { 8605331Samw int ret = SA_OK; 8615331Samw 8625331Samw if (!is_a_number(value)) { 8635331Samw ret = SA_BAD_VALUE; 8645331Samw } else { 8655331Samw int val; 8665331Samw val = strtoul(value, NULL, 0); 8675331Samw if (val == 0) 8685331Samw ret = SA_OK; 8695331Samw else { 8705331Samw if (val < smb_proto_options[index].minval || 8715331Samw val > smb_proto_options[index].maxval) 8725331Samw ret = SA_BAD_VALUE; 8735331Samw } 8745331Samw } 8755331Samw return (ret); 8765331Samw } 8775331Samw 8785331Samw /* 8795331Samw * Check the length of the string 8805331Samw */ 8815331Samw static int 8825331Samw string_length_check_validator(int index, char *value) 8835331Samw { 8845331Samw int ret = SA_OK; 8855331Samw 8865331Samw if (value == NULL) 8875331Samw return (SA_BAD_VALUE); 8885331Samw if (strlen(value) > smb_proto_options[index].maxval) 8895331Samw ret = SA_BAD_VALUE; 8905331Samw return (ret); 8915331Samw } 8925331Samw 8935331Samw /* 8945331Samw * Check yes/no 8955331Samw */ 8965331Samw /*ARGSUSED*/ 8975331Samw static int 8985331Samw true_false_validator(int index, char *value) 8995331Samw { 9005331Samw if (value == NULL) 9015331Samw return (SA_BAD_VALUE); 9025331Samw if ((strcasecmp(value, "true") == 0) || 9035331Samw (strcasecmp(value, "false") == 0)) 9045331Samw return (SA_OK); 9055331Samw return (SA_BAD_VALUE); 9065331Samw } 9075331Samw 9085331Samw /* 9095331Samw * Check IP address. 9105331Samw */ 9115331Samw /*ARGSUSED*/ 9125331Samw static int 9135331Samw ip_address_validator_empty_ok(int index, char *value) 9145331Samw { 9155331Samw char sbytes[16]; 9165331Samw int len; 9175331Samw 9185331Samw if (value == NULL) 9195331Samw return (SA_OK); 9205331Samw len = strlen(value); 9215331Samw if (len == 0) 9225331Samw return (SA_OK); 9235331Samw if (inet_pton(AF_INET, value, (void *)sbytes) != 1) 9245331Samw return (SA_BAD_VALUE); 9255331Samw 9265331Samw return (SA_OK); 9275331Samw } 9285331Samw 9295331Samw /* 9305331Samw * Check IP address list 9315331Samw */ 9325331Samw /*ARGSUSED*/ 9335331Samw static int 9345331Samw ip_address_csv_list_validator_empty_ok(int index, char *value) 9355331Samw { 9365331Samw char sbytes[16]; 9375331Samw char *ip, *tmp, *ctx; 9385331Samw 9395331Samw if (value == NULL || *value == '\0') 9405331Samw return (SA_OK); 9415331Samw 9425331Samw if (strlen(value) > MAX_VALUE_BUFLEN) 9435331Samw return (SA_BAD_VALUE); 9445331Samw 9455331Samw if ((tmp = strdup(value)) == NULL) 9465331Samw return (SA_NO_MEMORY); 9475331Samw 9485331Samw ip = strtok_r(tmp, ",", &ctx); 9495331Samw while (ip) { 9505331Samw if (strlen(ip) == 0) { 9515331Samw free(tmp); 9525331Samw return (SA_BAD_VALUE); 9535331Samw } 9545331Samw if (*ip != 0) { 9555331Samw if (inet_pton(AF_INET, ip, 9565331Samw (void *)sbytes) != 1) { 9575331Samw free(tmp); 9585331Samw return (SA_BAD_VALUE); 9595331Samw } 9605331Samw } 9615331Samw ip = strtok_r(0, ",", &ctx); 9625331Samw } 9635331Samw 9645331Samw free(tmp); 9655331Samw return (SA_OK); 9665331Samw } 9675331Samw 9685331Samw /* 9695331Samw * Check path 9705331Samw */ 9715331Samw /*ARGSUSED*/ 9725331Samw static int 9735331Samw path_validator(int index, char *value) 9745331Samw { 9755331Samw struct stat buffer; 9765331Samw int fd, status; 9775331Samw 9785331Samw if (value == NULL) 9795331Samw return (SA_BAD_VALUE); 9805331Samw 9815331Samw fd = open(value, O_RDONLY); 9825331Samw if (fd < 0) 9835331Samw return (SA_BAD_VALUE); 9845331Samw 9855331Samw status = fstat(fd, &buffer); 9865331Samw (void) close(fd); 9875331Samw 9885331Samw if (status < 0) 9895331Samw return (SA_BAD_VALUE); 9905331Samw 9915331Samw if (buffer.st_mode & S_IFDIR) 9925331Samw return (SA_OK); 9935331Samw return (SA_BAD_VALUE); 9945331Samw } 9955331Samw 9965331Samw /* 9975331Samw * the protoset holds the defined options so we don't have to read 9985331Samw * them multiple times 9995331Samw */ 10005331Samw static sa_protocol_properties_t protoset; 10015331Samw 10025331Samw static int 10035331Samw findprotoopt(char *name) 10045331Samw { 10055331Samw int i; 10065772Sas200622 char *sc_name; 10075772Sas200622 10085772Sas200622 for (i = 0; i < SMB_OPT_NUM; i++) { 10095772Sas200622 sc_name = smb_config_getname(smb_proto_options[i].smb_index); 10105772Sas200622 if (strcasecmp(sc_name, name) == 0) 10115331Samw return (i); 10125331Samw } 10135772Sas200622 10145331Samw return (-1); 10155331Samw } 10165331Samw 10175331Samw /* 10185331Samw * smb_load_proto_properties() 10195331Samw * 10205331Samw * read the smb config values from SMF. 10215331Samw */ 10225331Samw 10235331Samw static int 10245331Samw smb_load_proto_properties() 10255331Samw { 10265331Samw sa_property_t prop; 10275772Sas200622 char value[MAX_VALUE_BUFLEN]; 10285772Sas200622 char *name; 10295331Samw int index; 10306019Sdougm int ret = SA_OK; 10315772Sas200622 int rc; 10325331Samw 10335331Samw protoset = sa_create_protocol_properties(SMB_PROTOCOL_NAME); 10345331Samw if (protoset == NULL) 10355331Samw return (SA_NO_MEMORY); 10365331Samw 10376019Sdougm for (index = 0; index < SMB_OPT_NUM && ret == SA_OK; index++) { 10385772Sas200622 rc = smb_config_get(smb_proto_options[index].smb_index, 10395772Sas200622 value, sizeof (value)); 10405772Sas200622 if (rc != SMBD_SMF_OK) 10415772Sas200622 continue; 10425772Sas200622 name = smb_config_getname(smb_proto_options[index].smb_index); 10435772Sas200622 prop = sa_create_property(name, value); 10445454Sdougm if (prop != NULL) 10456019Sdougm ret = sa_add_protocol_property(protoset, prop); 10466019Sdougm else 10476019Sdougm ret = SA_NO_MEMORY; 10485331Samw } 10496019Sdougm return (ret); 10505331Samw } 10515331Samw 10525331Samw /* 10535331Samw * smb_share_init() 10545331Samw * 10555331Samw * Initialize the smb plugin. 10565331Samw */ 10575331Samw 10585331Samw static int 10595331Samw smb_share_init(void) 10605331Samw { 10615331Samw int ret = SA_OK; 10625331Samw 10635331Samw if (sa_plugin_ops.sa_init != smb_share_init) 10645331Samw return (SA_SYSTEM_ERR); 10655331Samw 10666019Sdougm ret = smb_load_proto_properties(); 10675331Samw 10685331Samw return (ret); 10695331Samw } 10705331Samw 10715331Samw /* 10725331Samw * smb_share_fini() 10735331Samw * 10745331Samw */ 10755331Samw static void 10765331Samw smb_share_fini(void) 10775331Samw { 10785331Samw xmlFreeNode(protoset); 10795331Samw protoset = NULL; 10805772Sas200622 10815772Sas200622 (void) lmshrd_door_close(); 10825331Samw } 10835331Samw 10845331Samw /* 10855331Samw * smb_get_proto_set() 10865331Samw * 10875331Samw * Return an optionset with all the protocol specific properties in 10885331Samw * it. 10895331Samw */ 10905331Samw static sa_protocol_properties_t 10915331Samw smb_get_proto_set(void) 10925331Samw { 10935331Samw return (protoset); 10945331Samw } 10955331Samw 10965331Samw /* 10975772Sas200622 * smb_enable_dependencies() 10985772Sas200622 * 10995772Sas200622 * SMBD_DEFAULT_INSTANCE_FMRI may have some dependencies that aren't 11005772Sas200622 * enabled. This will attempt to enable all of them. 11015772Sas200622 */ 11025772Sas200622 static void 11035772Sas200622 smb_enable_dependencies(const char *fmri) 11045772Sas200622 { 11055772Sas200622 scf_handle_t *handle; 11065772Sas200622 scf_service_t *service; 11075772Sas200622 scf_instance_t *inst = NULL; 11085772Sas200622 scf_iter_t *iter; 11095772Sas200622 scf_property_t *prop; 11105772Sas200622 scf_value_t *value; 11115772Sas200622 scf_propertygroup_t *pg; 11125772Sas200622 scf_scope_t *scope; 11135772Sas200622 char type[SCFTYPE_LEN]; 11145772Sas200622 char *dependency; 11155772Sas200622 char *servname; 11165772Sas200622 int maxlen; 11175772Sas200622 11185772Sas200622 /* 11195772Sas200622 * Get all required handles and storage. 11205772Sas200622 */ 11215772Sas200622 handle = scf_handle_create(SCF_VERSION); 11225772Sas200622 if (handle == NULL) 11235772Sas200622 return; 11245772Sas200622 11255772Sas200622 if (scf_handle_bind(handle) != 0) { 11265772Sas200622 scf_handle_destroy(handle); 11275772Sas200622 return; 11285772Sas200622 } 11295772Sas200622 11305772Sas200622 maxlen = scf_limit(SCF_LIMIT_MAX_VALUE_LENGTH); 11315772Sas200622 if (maxlen == (ssize_t)-1) 11325772Sas200622 maxlen = MAXPATHLEN; 11335772Sas200622 11345772Sas200622 dependency = malloc(maxlen); 11355772Sas200622 11365772Sas200622 service = scf_service_create(handle); 11375772Sas200622 11385772Sas200622 iter = scf_iter_create(handle); 11395772Sas200622 11405772Sas200622 pg = scf_pg_create(handle); 11415772Sas200622 11425772Sas200622 prop = scf_property_create(handle); 11435772Sas200622 11445772Sas200622 value = scf_value_create(handle); 11455772Sas200622 11465772Sas200622 scope = scf_scope_create(handle); 11475772Sas200622 11485772Sas200622 if (service == NULL || iter == NULL || pg == NULL || prop == NULL || 11495772Sas200622 value == NULL || scope == NULL || dependency == NULL) 11505772Sas200622 goto done; 11515772Sas200622 11525772Sas200622 /* 11535772Sas200622 * We passed in the FMRI for the default instance but for 11545772Sas200622 * some things we need the simple form so construct it. Since 11555772Sas200622 * we reuse the storage that dependency points to, we need to 11565772Sas200622 * use the servname early. 11575772Sas200622 */ 11585772Sas200622 (void) snprintf(dependency, maxlen, "%s", fmri + sizeof ("svc:")); 11595772Sas200622 servname = strrchr(dependency, ':'); 11605772Sas200622 if (servname == NULL) 11615772Sas200622 goto done; 11625772Sas200622 *servname = '\0'; 11635772Sas200622 servname = dependency; 11645772Sas200622 11655772Sas200622 /* 11665772Sas200622 * Setup to iterate over the service property groups, only 11675772Sas200622 * looking at those that are "dependency" types. The "entity" 11685772Sas200622 * property will have the FMRI of the service we are dependent 11695772Sas200622 * on. 11705772Sas200622 */ 11715772Sas200622 if (scf_handle_get_scope(handle, SCF_SCOPE_LOCAL, scope) != 0) 11725772Sas200622 goto done; 11735772Sas200622 11745772Sas200622 if (scf_scope_get_service(scope, servname, service) != 0) 11755772Sas200622 goto done; 11765772Sas200622 11775772Sas200622 if (scf_iter_service_pgs(iter, service) != 0) 11785772Sas200622 goto done; 11795772Sas200622 11805772Sas200622 while (scf_iter_next_pg(iter, pg) > 0) { 11815772Sas200622 char *services[2]; 11825772Sas200622 /* 11835772Sas200622 * Have a property group for the service. See if it is 11845772Sas200622 * a dependency pg and only do operations on those. 11855772Sas200622 */ 11865772Sas200622 if (scf_pg_get_type(pg, type, SCFTYPE_LEN) <= 0) 11875772Sas200622 continue; 11885772Sas200622 11895772Sas200622 if (strncmp(type, SCF_GROUP_DEPENDENCY, SCFTYPE_LEN) != 0) 11905772Sas200622 continue; 11915772Sas200622 /* 11925772Sas200622 * Have a dependency. Attempt to enable it. 11935772Sas200622 */ 11945772Sas200622 if (scf_pg_get_property(pg, SCF_PROPERTY_ENTITIES, prop) != 0) 11955772Sas200622 continue; 11965772Sas200622 11975772Sas200622 if (scf_property_get_value(prop, value) != 0) 11985772Sas200622 continue; 11995772Sas200622 12005772Sas200622 services[1] = NULL; 12015772Sas200622 12025772Sas200622 if (scf_value_get_as_string(value, dependency, maxlen) > 0) { 12035772Sas200622 services[0] = dependency; 12045772Sas200622 _check_services(services); 12055772Sas200622 } 12065772Sas200622 } 12075772Sas200622 12085772Sas200622 done: 12095772Sas200622 if (dependency != NULL) 12105772Sas200622 free(dependency); 12115772Sas200622 if (value != NULL) 12125772Sas200622 scf_value_destroy(value); 12135772Sas200622 if (prop != NULL) 12145772Sas200622 scf_property_destroy(prop); 12155772Sas200622 if (pg != NULL) 12165772Sas200622 scf_pg_destroy(pg); 12175772Sas200622 if (iter != NULL) 12185772Sas200622 scf_iter_destroy(iter); 12195772Sas200622 if (scope != NULL) 12205772Sas200622 scf_scope_destroy(scope); 12215772Sas200622 if (inst != NULL) 12225772Sas200622 scf_instance_destroy(inst); 12235772Sas200622 if (service != NULL) 12245772Sas200622 scf_service_destroy(service); 12255772Sas200622 12265772Sas200622 (void) scf_handle_unbind(handle); 12275772Sas200622 scf_handle_destroy(handle); 12285772Sas200622 } 12295772Sas200622 12305772Sas200622 /* 12315331Samw * How long to wait for service to come online 12325331Samw */ 12335331Samw #define WAIT_FOR_SERVICE 15 12345331Samw 12355331Samw /* 12365331Samw * smb_enable_service() 12375331Samw * 12385331Samw */ 12395331Samw static int 12405331Samw smb_enable_service(void) 12415331Samw { 12425331Samw int i; 12435331Samw int ret = SA_OK; 12445772Sas200622 char *service[] = { SMBD_DEFAULT_INSTANCE_FMRI, NULL }; 12455331Samw 12465331Samw if (!smb_isonline()) { 12475772Sas200622 /* 12485772Sas200622 * Attempt to start the idmap, and other dependent 12495772Sas200622 * services, first. If it fails, the SMB service will 12505772Sas200622 * ultimately fail so we use that as the error. If we 12515772Sas200622 * don't try to enable idmap, smb won't start the 12525772Sas200622 * first time unless the admin has done it 12535772Sas200622 * manually. The service could be administratively 12545772Sas200622 * disabled so we won't always get started. 12555772Sas200622 */ 12565772Sas200622 smb_enable_dependencies(SMBD_DEFAULT_INSTANCE_FMRI); 12575772Sas200622 _check_services(service); 12585331Samw 12595331Samw /* Wait for service to come online */ 12605331Samw for (i = 0; i < WAIT_FOR_SERVICE; i++) { 12615331Samw if (smb_isonline()) { 12625772Sas200622 ret = SA_OK; 12635331Samw break; 12646030Sjb150015 } else if (smb_ismaint()) { 12656030Sjb150015 /* maintenance requires help */ 12666030Sjb150015 ret = SA_SYSTEM_ERR; 12676030Sjb150015 break; 12686030Sjb150015 } else if (smb_isdisabled()) { 12696030Sjb150015 /* disabled is ok */ 12706030Sjb150015 ret = SA_OK; 12716030Sjb150015 break; 12725331Samw } else { 12736030Sjb150015 /* try another time */ 12745331Samw ret = SA_BUSY; 12755331Samw (void) sleep(1); 12765331Samw } 12775331Samw } 12785331Samw } 12795331Samw return (ret); 12805331Samw } 12815331Samw 12825331Samw /* 12835331Samw * smb_validate_proto_prop(index, name, value) 12845331Samw * 12855331Samw * Verify that the property specified by name can take the new 12865331Samw * value. This is a sanity check to prevent bad values getting into 12875331Samw * the default files. 12885331Samw */ 12895331Samw static int 12905331Samw smb_validate_proto_prop(int index, char *name, char *value) 12915331Samw { 12925331Samw if ((name == NULL) || (index < 0)) 12935331Samw return (SA_BAD_VALUE); 12945331Samw 12955331Samw if (smb_proto_options[index].validator == NULL) 12965331Samw return (SA_OK); 12975331Samw 12985331Samw if (smb_proto_options[index].validator(index, value) == SA_OK) 12995331Samw return (SA_OK); 13005331Samw return (SA_BAD_VALUE); 13015331Samw } 13025331Samw 13035331Samw /* 13045331Samw * smb_set_proto_prop(prop) 13055331Samw * 13065331Samw * check that prop is valid. 13075331Samw */ 13085331Samw /*ARGSUSED*/ 13095331Samw static int 13105331Samw smb_set_proto_prop(sa_property_t prop) 13115331Samw { 13125331Samw int ret = SA_OK; 13135331Samw char *name; 13145331Samw char *value; 13155331Samw int index = -1; 13165521Sas200622 struct smb_proto_option_defs *opt; 13175331Samw 13185331Samw name = sa_get_property_attr(prop, "type"); 13195331Samw value = sa_get_property_attr(prop, "value"); 13205331Samw if (name != NULL && value != NULL) { 13215331Samw index = findprotoopt(name); 13225331Samw if (index >= 0) { 13235331Samw /* should test for valid value */ 13245331Samw ret = smb_validate_proto_prop(index, name, value); 13255331Samw if (ret == SA_OK) { 13265521Sas200622 opt = &smb_proto_options[index]; 13275521Sas200622 13285331Samw /* Save to SMF */ 13295772Sas200622 (void) smb_config_set(opt->smb_index, value); 13305331Samw /* 13315331Samw * Specialized refresh mechanisms can 13325331Samw * be flagged in the proto_options and 13335331Samw * processed here. 13345331Samw */ 13355521Sas200622 if (opt->refresh & SMB_REFRESH_REFRESH) 13366139Sjb150015 (void) smf_refresh_instance( 13376139Sjb150015 SMBD_DEFAULT_INSTANCE_FMRI); 13385521Sas200622 else if (opt->refresh & SMB_REFRESH_RESTART) 13395331Samw (void) smf_restart_instance( 13405331Samw SMBD_DEFAULT_INSTANCE_FMRI); 13415331Samw } 13425331Samw } 13435331Samw } 13445521Sas200622 13455331Samw if (name != NULL) 13465331Samw sa_free_attr_string(name); 13475331Samw if (value != NULL) 13485331Samw sa_free_attr_string(value); 13495331Samw 13505331Samw return (ret); 13515331Samw } 13525331Samw 13535331Samw /* 13545331Samw * smb_get_status() 13555331Samw * 13565331Samw * What is the current status of the smbd? We use the SMF state here. 13575331Samw * Caller must free the returned value. 13585331Samw */ 13595331Samw 13605331Samw static char * 13615331Samw smb_get_status(void) 13625331Samw { 13635331Samw char *state = NULL; 13645331Samw state = smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI); 13655331Samw return (state != NULL ? state : "-"); 13665331Samw } 13675331Samw 13685331Samw /* 13695331Samw * This protocol plugin require resource names 13705331Samw */ 13715331Samw static uint64_t 13725331Samw smb_share_features(void) 13735331Samw { 13745331Samw return (SA_FEATURE_RESOURCE | SA_FEATURE_ALLOWSUBDIRS | 13756088Sdougm SA_FEATURE_ALLOWPARDIRS | SA_FEATURE_SERVER); 13765331Samw } 13775331Samw 13785331Samw /* 13795331Samw * This should be used to convert lmshare_info to sa_resource_t 13805331Samw * Should only be needed to build temp shares/resources to be 13815331Samw * supplied to sharemanager to display temp shares. 13825331Samw */ 13835331Samw static int 13845331Samw smb_build_tmp_sa_resource(sa_handle_t handle, lmshare_info_t *si) 13855331Samw { 13865331Samw int err; 13875331Samw sa_share_t share; 13885331Samw sa_group_t group; 13895331Samw sa_resource_t resource; 13905331Samw 13915331Samw if (si == NULL) 13925331Samw return (SA_INVALID_NAME); 13935331Samw 13945331Samw /* 13955331Samw * First determine if the "share path" is already shared 13965331Samw * somewhere. If it is, we have to use it as the authority on 13975331Samw * where the transient share lives so will use it's parent 13985331Samw * group. If it doesn't exist, it needs to land in "smb". 13995331Samw */ 14005331Samw 14015331Samw share = sa_find_share(handle, si->directory); 14025331Samw if (share != NULL) { 14035331Samw group = sa_get_parent_group(share); 14045331Samw } else { 14055331Samw group = smb_get_smb_share_group(handle); 14065331Samw if (group == NULL) 14075331Samw return (SA_NO_SUCH_GROUP); 14085331Samw share = sa_get_share(group, si->directory); 14095331Samw if (share == NULL) { 14105331Samw share = sa_add_share(group, si->directory, 14115331Samw SA_SHARE_TRANSIENT, &err); 14125331Samw if (share == NULL) 14135331Samw return (SA_NO_SUCH_PATH); 14145331Samw } 14155331Samw } 14165331Samw 14175331Samw /* 14185331Samw * Now handle the resource. Make sure that the resource is 14195331Samw * transient and added to the share. 14205331Samw */ 14215331Samw resource = sa_get_share_resource(share, si->share_name); 14225331Samw if (resource == NULL) { 14235331Samw resource = sa_add_resource(share, 14245331Samw si->share_name, SA_SHARE_TRANSIENT, &err); 14255331Samw if (resource == NULL) 14265331Samw return (SA_NO_SUCH_RESOURCE); 14275331Samw } 14285331Samw 14295331Samw /* set resource attributes now */ 14305331Samw (void) sa_set_resource_attr(resource, "description", si->comment); 14315331Samw (void) sa_set_resource_attr(resource, SHOPT_AD_CONTAINER, 14325331Samw si->container); 14335331Samw 14345331Samw return (SA_OK); 14355331Samw } 14365331Samw 14375331Samw /* 14385331Samw * Return smb transient shares. Note that we really want to look at 14395331Samw * all current shares from SMB in order to determine this. Transient 14405331Samw * shares should be those that don't appear in either the SMF or ZFS 14415331Samw * configurations. Those that are in the repositories will be 14425331Samw * filtered out by smb_build_tmp_sa_resource. 14435331Samw */ 14445331Samw static int 14455331Samw smb_list_transient(sa_handle_t handle) 14465331Samw { 14475331Samw int i, offset, num; 14485331Samw lmshare_list_t list; 14495331Samw int res; 14505331Samw 14515331Samw num = lmshrd_num_shares(); 14525331Samw if (num <= 0) 14535331Samw return (SA_OK); 14545331Samw offset = 0; 14555331Samw while (lmshrd_list(offset, &list) != NERR_InternalError) { 14565331Samw if (list.no == 0) 14575331Samw break; 14585331Samw for (i = 0; i < list.no; i++) { 14595331Samw res = smb_build_tmp_sa_resource(handle, 14605331Samw &(list.smbshr[i])); 14615331Samw if (res != SA_OK) 14625331Samw return (res); 14635331Samw } 14645331Samw offset += list.no; 14655331Samw } 14665331Samw 14675331Samw return (SA_OK); 14685331Samw } 14695331Samw 14705331Samw /* 14715331Samw * fix_resource_name(share, name, prefix) 14725331Samw * 14735331Samw * Construct a name where the ZFS dataset has the prefix replaced with "name". 14745331Samw */ 14755331Samw static char * 14765331Samw fix_resource_name(sa_share_t share, char *name, char *prefix) 14775331Samw { 14785331Samw char *dataset = NULL; 14795331Samw char *newname = NULL; 14805331Samw size_t psize; 14815331Samw size_t nsize; 14825331Samw 14835331Samw dataset = sa_get_share_attr(share, "dataset"); 14845331Samw 14855331Samw if (dataset != NULL && strcmp(dataset, prefix) != 0) { 14865331Samw psize = strlen(prefix); 14875331Samw if (strncmp(dataset, prefix, psize) == 0) { 14885331Samw /* need string plus ',' and NULL */ 14895331Samw nsize = (strlen(dataset) - psize) + strlen(name) + 2; 14905331Samw newname = calloc(nsize, 1); 14915331Samw if (newname != NULL) { 14925331Samw (void) snprintf(newname, nsize, "%s%s", name, 14935331Samw dataset + psize); 14945331Samw sa_fix_resource_name(newname); 14955331Samw } 14965331Samw sa_free_attr_string(dataset); 14975331Samw return (newname); 14985331Samw } 14995331Samw } 15005331Samw if (dataset != NULL) 15015331Samw sa_free_attr_string(dataset); 15025331Samw return (strdup(name)); 15035331Samw } 15045331Samw 15055331Samw /* 15065331Samw * smb_parse_optstring(group, options) 15075331Samw * 15085331Samw * parse a compact option string into individual options. This allows 15095331Samw * ZFS sharesmb and sharemgr "share" command to work. group can be a 15105331Samw * group, a share or a resource. 15115331Samw */ 15125331Samw static int 15135331Samw smb_parse_optstring(sa_group_t group, char *options) 15145331Samw { 15155331Samw char *dup; 15165331Samw char *base; 15175331Samw char *lasts; 15185331Samw char *token; 15195331Samw sa_optionset_t optionset; 15205331Samw sa_group_t parent = NULL; 15215331Samw sa_resource_t resource = NULL; 15225331Samw int iszfs = 0; 15235331Samw int persist = 0; 15245331Samw int need_optionset = 0; 15255331Samw int ret = SA_OK; 15265331Samw sa_property_t prop; 15275331Samw 15285331Samw /* 15295331Samw * In order to not attempt to change ZFS properties unless 15305331Samw * absolutely necessary, we never do it in the legacy parsing 15315331Samw * so we need to keep track of this. 15325331Samw */ 15335331Samw if (sa_is_share(group)) { 15345331Samw char *zfs; 15355331Samw 15365331Samw parent = sa_get_parent_group(group); 15375331Samw if (parent != NULL) { 15385331Samw zfs = sa_get_group_attr(parent, "zfs"); 15395331Samw if (zfs != NULL) { 15405331Samw sa_free_attr_string(zfs); 15415331Samw iszfs = 1; 15425331Samw } 15435331Samw } 15445331Samw } else { 15455331Samw iszfs = sa_group_is_zfs(group); 15465331Samw /* 15475331Samw * If a ZFS group, then we need to see if a resource 15485331Samw * name is being set. If so, bail with 15495331Samw * SA_PROP_SHARE_ONLY, so we come back in with a share 15505331Samw * instead of a group. 15515331Samw */ 15525331Samw if (strncmp(options, "name=", sizeof ("name=") - 1) == 0 || 15535331Samw strstr(options, ",name=") != NULL) { 15545331Samw return (SA_PROP_SHARE_ONLY); 15555331Samw } 15565331Samw } 15575331Samw 15585331Samw /* do we have an existing optionset? */ 15595331Samw optionset = sa_get_optionset(group, "smb"); 15605331Samw if (optionset == NULL) { 15615331Samw /* didn't find existing optionset so create one */ 15625331Samw optionset = sa_create_optionset(group, "smb"); 15635331Samw if (optionset == NULL) 15645331Samw return (SA_NO_MEMORY); 15655331Samw } else { 15665331Samw /* 15675331Samw * If an optionset already exists, we've come through 15685331Samw * twice so ignore the second time. 15695331Samw */ 15705331Samw return (ret); 15715331Samw } 15725331Samw 15735331Samw /* We need a copy of options for the next part. */ 15745331Samw dup = strdup(options); 15755331Samw if (dup == NULL) 15765331Samw return (SA_NO_MEMORY); 15775331Samw 15785331Samw /* 15795331Samw * SMB properties are straightforward and are strings, 15805331Samw * integers or booleans. Properties are separated by 15815331Samw * commas. It will be necessary to parse quotes due to some 15825331Samw * strings not having a restricted characters set. 15835331Samw * 15845331Samw * Note that names will create a resource. For now, if there 15855331Samw * is a set of properties "before" the first name="", those 15865331Samw * properties will be placed on the group. 15875331Samw */ 15885331Samw persist = sa_is_persistent(group); 15895331Samw base = dup; 15905331Samw token = dup; 15915331Samw lasts = NULL; 15925331Samw while (token != NULL && ret == SA_OK) { 15935331Samw ret = SA_OK; 15945331Samw token = strtok_r(base, ",", &lasts); 15955331Samw base = NULL; 15965331Samw if (token != NULL) { 15975331Samw char *value; 15985331Samw /* 15995331Samw * All SMB properties have values so there 16005331Samw * MUST be an '=' character. If it doesn't, 16015331Samw * it is a syntax error. 16025331Samw */ 16035331Samw value = strchr(token, '='); 16045331Samw if (value != NULL) { 16055331Samw *value++ = '\0'; 16065331Samw } else { 16075331Samw ret = SA_SYNTAX_ERR; 16085331Samw break; 16095331Samw } 16105331Samw /* 16115331Samw * We may need to handle a "name" property 16125331Samw * that is a ZFS imposed resource name. Each 16135331Samw * name would trigger getting a new "resource" 16145331Samw * to put properties on. For now, assume no 16155331Samw * "name" property for special handling. 16165331Samw */ 16175331Samw 16185331Samw if (strcmp(token, "name") == 0) { 16195331Samw char *prefix; 16205331Samw char *name = NULL; 16215331Samw /* 16225331Samw * We have a name, so now work on the 16235331Samw * resource level. We have a "share" 16245331Samw * in "group" due to the caller having 16255331Samw * added it. If we are called with a 16265331Samw * group, the check for group/share 16275331Samw * at the beginning of this function 16285331Samw * will bail out the parse if there is a 16295331Samw * "name" but no share. 16305331Samw */ 16315331Samw if (!iszfs) { 16325331Samw ret = SA_SYNTAX_ERR; 16335331Samw break; 16345331Samw } 16355331Samw /* 16365331Samw * Make sure the parent group has the 16375331Samw * "prefix" property since we will 16385331Samw * need to use this for constructing 16395331Samw * inherited name= values. 16405331Samw */ 16415331Samw prefix = sa_get_group_attr(parent, "prefix"); 16425331Samw if (prefix == NULL) { 16435331Samw prefix = sa_get_group_attr(parent, 16445331Samw "name"); 16455331Samw if (prefix != NULL) { 16465331Samw (void) sa_set_group_attr(parent, 16475331Samw "prefix", prefix); 16485331Samw } 16495331Samw } 16505331Samw name = fix_resource_name((sa_share_t)group, 16515331Samw value, prefix); 16525331Samw if (name != NULL) { 16535331Samw resource = sa_add_resource( 16545331Samw (sa_share_t)group, name, 16555331Samw SA_SHARE_TRANSIENT, &ret); 16565331Samw sa_free_attr_string(name); 16575331Samw } else { 16585331Samw ret = SA_NO_MEMORY; 16595331Samw } 16605331Samw if (prefix != NULL) 16615331Samw sa_free_attr_string(prefix); 16625331Samw 16635331Samw /* A resource level optionset is needed */ 16645331Samw 16655331Samw need_optionset = 1; 16665331Samw if (resource == NULL) { 16675331Samw ret = SA_NO_MEMORY; 16685331Samw break; 16695331Samw } 16705331Samw continue; 16715331Samw } 16725331Samw 16735331Samw if (need_optionset) { 16745331Samw optionset = sa_create_optionset(resource, 16755331Samw "smb"); 16765331Samw need_optionset = 0; 16775331Samw } 16785331Samw 16795331Samw prop = sa_create_property(token, value); 16805331Samw if (prop == NULL) 16815331Samw ret = SA_NO_MEMORY; 16825331Samw else 16835331Samw ret = sa_add_property(optionset, prop); 16845331Samw if (ret != SA_OK) 16855331Samw break; 16865331Samw if (!iszfs) 16875331Samw ret = sa_commit_properties(optionset, !persist); 16885331Samw } 16895331Samw } 16905331Samw free(dup); 16915331Samw return (ret); 16925331Samw } 16935331Samw 16945331Samw /* 16955331Samw * smb_sprint_option(rbuff, rbuffsize, incr, prop, sep) 16965331Samw * 16975331Samw * provides a mechanism to format SMB properties into legacy output 16985331Samw * format. If the buffer would overflow, it is reallocated and grown 16995331Samw * as appropriate. Special cases of converting internal form of values 17005331Samw * to those used by "share" are done. this function does one property 17015331Samw * at a time. 17025331Samw */ 17035331Samw 17045331Samw static void 17055331Samw smb_sprint_option(char **rbuff, size_t *rbuffsize, size_t incr, 17065331Samw sa_property_t prop, int sep) 17075331Samw { 17085331Samw char *name; 17095331Samw char *value; 17105331Samw int curlen; 17115331Samw char *buff = *rbuff; 17125331Samw size_t buffsize = *rbuffsize; 17135331Samw 17145331Samw name = sa_get_property_attr(prop, "type"); 17155331Samw value = sa_get_property_attr(prop, "value"); 17165331Samw if (buff != NULL) 17175331Samw curlen = strlen(buff); 17185331Samw else 17195331Samw curlen = 0; 17205331Samw if (name != NULL) { 17215331Samw int len; 17225331Samw len = strlen(name) + sep; 17235331Samw 17245331Samw /* 17255331Samw * A future RFE would be to replace this with more 17265331Samw * generic code and to possibly handle more types. 17275331Samw * 17285331Samw * For now, everything else is treated as a string. If 17295331Samw * we get any properties that aren't exactly 17305331Samw * name/value pairs, we may need to 17315331Samw * interpret/transform. 17325331Samw */ 17335331Samw if (value != NULL) 17345331Samw len += 1 + strlen(value); 17355331Samw 17365331Samw while (buffsize <= (curlen + len)) { 17375331Samw /* need more room */ 17385331Samw buffsize += incr; 17395331Samw buff = realloc(buff, buffsize); 17405331Samw *rbuff = buff; 17415331Samw *rbuffsize = buffsize; 17425331Samw if (buff == NULL) { 17435331Samw /* realloc failed so free everything */ 17445331Samw if (*rbuff != NULL) 17455331Samw free(*rbuff); 17465331Samw goto err; 17475331Samw } 17485331Samw } 17495331Samw if (buff == NULL) 17505331Samw goto err; 17515331Samw (void) snprintf(buff + curlen, buffsize - curlen, 17525331Samw "%s%s=%s", sep ? "," : "", 17535331Samw name, value != NULL ? value : "\"\""); 17545331Samw 17555331Samw } 17565331Samw err: 17575331Samw if (name != NULL) 17585331Samw sa_free_attr_string(name); 17595331Samw if (value != NULL) 17605331Samw sa_free_attr_string(value); 17615331Samw } 17625331Samw 17635331Samw /* 17645331Samw * smb_format_resource_options(resource, hier) 17655331Samw * 17665331Samw * format all the options on the group into a flattened option 17675331Samw * string. If hier is non-zero, walk up the tree to get inherited 17685331Samw * options. 17695331Samw */ 17705331Samw 17715331Samw static char * 17725331Samw smb_format_options(sa_group_t group, int hier) 17735331Samw { 17745331Samw sa_optionset_t options = NULL; 17755331Samw sa_property_t prop; 17765331Samw int sep = 0; 17775331Samw char *buff; 17785331Samw size_t buffsize; 17795331Samw 17805331Samw 17815331Samw buff = malloc(OPT_CHUNK); 17825331Samw if (buff == NULL) 17835331Samw return (NULL); 17845331Samw 17855331Samw buff[0] = '\0'; 17865331Samw buffsize = OPT_CHUNK; 17875331Samw 17885331Samw /* 17895331Samw * We may have a an optionset relative to this item. format 17905331Samw * these if we find them and then add any security definitions. 17915331Samw */ 17925331Samw 17935331Samw options = sa_get_derived_optionset(group, "smb", hier); 17945331Samw 17955331Samw /* 17965331Samw * do the default set first but skip any option that is also 17975331Samw * in the protocol specific optionset. 17985331Samw */ 17995331Samw if (options != NULL) { 18005331Samw for (prop = sa_get_property(options, NULL); 18015331Samw prop != NULL; prop = sa_get_next_property(prop)) { 18025331Samw /* 18035331Samw * use this one since we skipped any 18045331Samw * of these that were also in 18055331Samw * optdefault 18065331Samw */ 18075331Samw smb_sprint_option(&buff, &buffsize, OPT_CHUNK, 18085331Samw prop, sep); 18095331Samw if (buff == NULL) { 18105331Samw /* 18115331Samw * buff could become NULL if there 18125331Samw * isn't enough memory for 18135331Samw * smb_sprint_option to realloc() 18145331Samw * as necessary. We can't really 18155331Samw * do anything about it at this 18165331Samw * point so we return NULL. The 18175331Samw * caller should handle the 18185331Samw * failure. 18195331Samw */ 18205331Samw if (options != NULL) 18215331Samw sa_free_derived_optionset( 18225331Samw options); 18235331Samw return (buff); 18245331Samw } 18255331Samw sep = 1; 18265331Samw } 18275331Samw } 18285331Samw 18295331Samw if (options != NULL) 18305331Samw sa_free_derived_optionset(options); 18315331Samw return (buff); 18325331Samw } 18335331Samw 18345331Samw /* 18355331Samw * smb_rename_resource(resource, newname) 18365331Samw * 18375331Samw * Change the current exported name of the resource to newname. 18385331Samw */ 18395331Samw /*ARGSUSED*/ 18405331Samw int 18415331Samw smb_rename_resource(sa_handle_t handle, sa_resource_t resource, char *newname) 18425331Samw { 18435331Samw int ret = SA_OK; 18445331Samw int err; 18455331Samw char *oldname; 18465331Samw 18475331Samw oldname = sa_get_resource_attr(resource, "name"); 18485331Samw if (oldname == NULL) 18495331Samw return (SA_NO_SUCH_RESOURCE); 18505331Samw 18515331Samw err = lmshrd_rename(oldname, newname); 18525331Samw 18535331Samw /* improve error values somewhat */ 18545331Samw switch (err) { 18555331Samw case NERR_Success: 18565331Samw break; 18575331Samw case NERR_InternalError: 18585331Samw ret = SA_SYSTEM_ERR; 18595331Samw break; 18605331Samw case NERR_DuplicateShare: 18615331Samw ret = SA_DUPLICATE_NAME; 18625331Samw break; 18635331Samw default: 18645331Samw ret = SA_CONFIG_ERR; 18655331Samw break; 18665331Samw } 18675331Samw 18685331Samw return (ret); 18695331Samw } 1870