1549ec3ffSdougm /* 2549ec3ffSdougm * CDDL HEADER START 3549ec3ffSdougm * 4549ec3ffSdougm * The contents of this file are subject to the terms of the 5549ec3ffSdougm * Common Development and Distribution License (the "License"). 6549ec3ffSdougm * You may not use this file except in compliance with the License. 7549ec3ffSdougm * 8549ec3ffSdougm * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9549ec3ffSdougm * or http://www.opensolaris.org/os/licensing. 10549ec3ffSdougm * See the License for the specific language governing permissions 11549ec3ffSdougm * and limitations under the License. 12549ec3ffSdougm * 13549ec3ffSdougm * When distributing Covered Code, include this CDDL HEADER in each 14549ec3ffSdougm * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15549ec3ffSdougm * If applicable, add the following below this CDDL HEADER, with the 16549ec3ffSdougm * fields enclosed by brackets "[]" replaced with your own identifying 17549ec3ffSdougm * information: Portions Copyright [yyyy] [name of copyright owner] 18549ec3ffSdougm * 19549ec3ffSdougm * CDDL HEADER END 20549ec3ffSdougm */ 21549ec3ffSdougm 22549ec3ffSdougm /* 23*0616fd7fSPavel Filipensky * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. 24549ec3ffSdougm */ 25549ec3ffSdougm 26549ec3ffSdougm /* 27549ec3ffSdougm * NFS specific functions 28549ec3ffSdougm */ 29549ec3ffSdougm #include <stdio.h> 30549ec3ffSdougm #include <string.h> 31549ec3ffSdougm #include <ctype.h> 32549ec3ffSdougm #include <stdlib.h> 33549ec3ffSdougm #include <unistd.h> 34549ec3ffSdougm #include <zone.h> 35549ec3ffSdougm #include <errno.h> 36549ec3ffSdougm #include <locale.h> 37549ec3ffSdougm #include <signal.h> 38549ec3ffSdougm #include "libshare.h" 39549ec3ffSdougm #include "libshare_impl.h" 40549ec3ffSdougm #include <nfs/export.h> 41549ec3ffSdougm #include <pwd.h> 42549ec3ffSdougm #include <limits.h> 43549ec3ffSdougm #include <libscf.h> 44549ec3ffSdougm #include "nfslog_config.h" 45549ec3ffSdougm #include "nfslogtab.h" 46549ec3ffSdougm #include "libshare_nfs.h" 47549ec3ffSdougm #include <rpcsvc/daemon_utils.h> 48549ec3ffSdougm #include <nfs/nfs.h> 49ecd6cf80Smarks #include <nfs/nfssys.h> 50549ec3ffSdougm 51549ec3ffSdougm /* should really be in some global place */ 52549ec3ffSdougm #define DEF_WIN 30000 53549ec3ffSdougm #define OPT_CHUNK 1024 54549ec3ffSdougm 55549ec3ffSdougm int debug = 0; 56549ec3ffSdougm 57ecd6cf80Smarks #define NFS_SERVER_SVC "svc:/network/nfs/server:default" 58549ec3ffSdougm 59549ec3ffSdougm /* internal functions */ 60549ec3ffSdougm static int nfs_init(); 61549ec3ffSdougm static void nfs_fini(); 62549ec3ffSdougm static int nfs_enable_share(sa_share_t); 63ecd6cf80Smarks static int nfs_disable_share(sa_share_t, char *); 64687915e9Sdougm static int nfs_validate_property(sa_handle_t, sa_property_t, sa_optionset_t); 65549ec3ffSdougm static int nfs_validate_security_mode(char *); 66549ec3ffSdougm static int nfs_is_security_opt(char *); 67549ec3ffSdougm static int nfs_parse_legacy_options(sa_group_t, char *); 68549ec3ffSdougm static char *nfs_format_options(sa_group_t, int); 69549ec3ffSdougm static int nfs_set_proto_prop(sa_property_t); 70549ec3ffSdougm static sa_protocol_properties_t nfs_get_proto_set(); 71549ec3ffSdougm static char *nfs_get_status(); 72549ec3ffSdougm static char *nfs_space_alias(char *); 73da6c28aaSamw static uint64_t nfs_features(); 74549ec3ffSdougm 75549ec3ffSdougm /* 76549ec3ffSdougm * ops vector that provides the protocol specific info and operations 77549ec3ffSdougm * for share management. 78549ec3ffSdougm */ 79549ec3ffSdougm 80549ec3ffSdougm struct sa_plugin_ops sa_plugin_ops = { 81549ec3ffSdougm SA_PLUGIN_VERSION, 82549ec3ffSdougm "nfs", 83549ec3ffSdougm nfs_init, 84549ec3ffSdougm nfs_fini, 85549ec3ffSdougm nfs_enable_share, 86549ec3ffSdougm nfs_disable_share, 87549ec3ffSdougm nfs_validate_property, 88549ec3ffSdougm nfs_validate_security_mode, 89549ec3ffSdougm nfs_is_security_opt, 90549ec3ffSdougm nfs_parse_legacy_options, 91549ec3ffSdougm nfs_format_options, 92549ec3ffSdougm nfs_set_proto_prop, 93549ec3ffSdougm nfs_get_proto_set, 94549ec3ffSdougm nfs_get_status, 95549ec3ffSdougm nfs_space_alias, 96da6c28aaSamw NULL, /* update_legacy */ 97da6c28aaSamw NULL, /* delete_legacy */ 98da6c28aaSamw NULL, /* change_notify */ 99da6c28aaSamw NULL, /* enable_resource */ 100da6c28aaSamw NULL, /* disable_resource */ 101da6c28aaSamw nfs_features, 102da6c28aaSamw NULL, /* transient shares */ 103da6c28aaSamw NULL, /* notify resource */ 1044bff34e3Sthurlow NULL, /* rename_resource */ 1054bff34e3Sthurlow NULL, /* run_command */ 1064bff34e3Sthurlow NULL, /* command_help */ 1074bff34e3Sthurlow NULL /* delete_proto_section */ 108549ec3ffSdougm }; 109549ec3ffSdougm 110549ec3ffSdougm /* 111549ec3ffSdougm * list of support services needed 112549ec3ffSdougm * defines should come from head/rpcsvc/daemon_utils.h 113549ec3ffSdougm */ 114549ec3ffSdougm 115549ec3ffSdougm static char *service_list_default[] = 1162f172c55SRobert Thurlow { STATD, LOCKD, MOUNTD, NFSD, NFSMAPID, RQUOTAD, REPARSED, NULL }; 117549ec3ffSdougm static char *service_list_logging[] = 1182f172c55SRobert Thurlow { STATD, LOCKD, MOUNTD, NFSD, NFSMAPID, RQUOTAD, NFSLOGD, REPARSED, 1192f172c55SRobert Thurlow NULL }; 120549ec3ffSdougm 121549ec3ffSdougm /* 122549ec3ffSdougm * option definitions. Make sure to keep the #define for the option 123549ec3ffSdougm * index just before the entry it is the index for. Changing the order 124549ec3ffSdougm * can cause breakage. E.g OPT_RW is index 1 and must precede the 125549ec3ffSdougm * line that includes the SHOPT_RW and OPT_RW entries. 126549ec3ffSdougm */ 127549ec3ffSdougm 128549ec3ffSdougm struct option_defs optdefs[] = { 129549ec3ffSdougm #define OPT_RO 0 130549ec3ffSdougm {SHOPT_RO, OPT_RO, OPT_TYPE_ACCLIST}, 131549ec3ffSdougm #define OPT_RW 1 132549ec3ffSdougm {SHOPT_RW, OPT_RW, OPT_TYPE_ACCLIST}, 133549ec3ffSdougm #define OPT_ROOT 2 134549ec3ffSdougm {SHOPT_ROOT, OPT_ROOT, OPT_TYPE_ACCLIST}, 135549ec3ffSdougm #define OPT_SECURE 3 136549ec3ffSdougm {SHOPT_SECURE, OPT_SECURE, OPT_TYPE_DEPRECATED}, 137549ec3ffSdougm #define OPT_ANON 4 138549ec3ffSdougm {SHOPT_ANON, OPT_ANON, OPT_TYPE_USER}, 139549ec3ffSdougm #define OPT_WINDOW 5 140549ec3ffSdougm {SHOPT_WINDOW, OPT_WINDOW, OPT_TYPE_NUMBER}, 141549ec3ffSdougm #define OPT_NOSUID 6 142549ec3ffSdougm {SHOPT_NOSUID, OPT_NOSUID, OPT_TYPE_BOOLEAN}, 143549ec3ffSdougm #define OPT_ACLOK 7 144549ec3ffSdougm {SHOPT_ACLOK, OPT_ACLOK, OPT_TYPE_BOOLEAN}, 145549ec3ffSdougm #define OPT_NOSUB 8 146549ec3ffSdougm {SHOPT_NOSUB, OPT_NOSUB, OPT_TYPE_BOOLEAN}, 147549ec3ffSdougm #define OPT_SEC 9 148549ec3ffSdougm {SHOPT_SEC, OPT_SEC, OPT_TYPE_SECURITY}, 149549ec3ffSdougm #define OPT_PUBLIC 10 150549ec3ffSdougm {SHOPT_PUBLIC, OPT_PUBLIC, OPT_TYPE_BOOLEAN, OPT_SHARE_ONLY}, 151549ec3ffSdougm #define OPT_INDEX 11 152549ec3ffSdougm {SHOPT_INDEX, OPT_INDEX, OPT_TYPE_FILE}, 153549ec3ffSdougm #define OPT_LOG 12 154549ec3ffSdougm {SHOPT_LOG, OPT_LOG, OPT_TYPE_LOGTAG}, 155549ec3ffSdougm #define OPT_CKSUM 13 156549ec3ffSdougm {SHOPT_CKSUM, OPT_CKSUM, OPT_TYPE_STRINGSET}, 157b89a8333Snatalie li - Sun Microsystems - Irvine United States #define OPT_NONE 14 158b89a8333Snatalie li - Sun Microsystems - Irvine United States {SHOPT_NONE, OPT_NONE, OPT_TYPE_ACCLIST}, 159b89a8333Snatalie li - Sun Microsystems - Irvine United States #define OPT_ROOT_MAPPING 15 160b89a8333Snatalie li - Sun Microsystems - Irvine United States {SHOPT_ROOT_MAPPING, OPT_ROOT_MAPPING, OPT_TYPE_USER}, 161b89a8333Snatalie li - Sun Microsystems - Irvine United States #define OPT_CHARSET_MAP 16 162b89a8333Snatalie li - Sun Microsystems - Irvine United States {"", OPT_CHARSET_MAP, OPT_TYPE_ACCLIST}, 1636764e83bSVallish Vaidyeshwara #define OPT_NOACLFAB 17 1646764e83bSVallish Vaidyeshwara {SHOPT_NOACLFAB, OPT_NOACLFAB, OPT_TYPE_BOOLEAN}, 165549ec3ffSdougm #ifdef VOLATILE_FH_TEST /* XXX added for testing volatile fh's only */ 1666764e83bSVallish Vaidyeshwara #define OPT_VOLFH 18 167549ec3ffSdougm {SHOPT_VOLFH, OPT_VOLFH}, 168549ec3ffSdougm #endif /* VOLATILE_FH_TEST */ 169549ec3ffSdougm NULL 170549ec3ffSdougm }; 171549ec3ffSdougm 172549ec3ffSdougm /* 173b89a8333Snatalie li - Sun Microsystems - Irvine United States * Codesets that may need to be converted to UTF-8 for file paths. 174b89a8333Snatalie li - Sun Microsystems - Irvine United States * Add new names here to add new property support. If we ever get a 175b89a8333Snatalie li - Sun Microsystems - Irvine United States * way to query the kernel for character sets, this should become 176b89a8333Snatalie li - Sun Microsystems - Irvine United States * dynamically loaded. Make sure changes here are reflected in 177b89a8333Snatalie li - Sun Microsystems - Irvine United States * cmd/fs.d/nfs/mountd/nfscmd.c 178b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 179b89a8333Snatalie li - Sun Microsystems - Irvine United States 180b89a8333Snatalie li - Sun Microsystems - Irvine United States static char *legal_conv[] = { 181b89a8333Snatalie li - Sun Microsystems - Irvine United States "euc-cn", 182b89a8333Snatalie li - Sun Microsystems - Irvine United States "euc-jp", 183b89a8333Snatalie li - Sun Microsystems - Irvine United States "euc-jpms", 184b89a8333Snatalie li - Sun Microsystems - Irvine United States "euc-kr", 185b89a8333Snatalie li - Sun Microsystems - Irvine United States "euc-tw", 186b89a8333Snatalie li - Sun Microsystems - Irvine United States "iso8859-1", 187b89a8333Snatalie li - Sun Microsystems - Irvine United States "iso8859-2", 188b89a8333Snatalie li - Sun Microsystems - Irvine United States "iso8859-5", 189b89a8333Snatalie li - Sun Microsystems - Irvine United States "iso8859-6", 190b89a8333Snatalie li - Sun Microsystems - Irvine United States "iso8859-7", 191b89a8333Snatalie li - Sun Microsystems - Irvine United States "iso8859-8", 192b89a8333Snatalie li - Sun Microsystems - Irvine United States "iso8859-9", 193b89a8333Snatalie li - Sun Microsystems - Irvine United States "iso8859-13", 194b89a8333Snatalie li - Sun Microsystems - Irvine United States "iso8859-15", 195b89a8333Snatalie li - Sun Microsystems - Irvine United States "koi8-r", 196b89a8333Snatalie li - Sun Microsystems - Irvine United States NULL 197b89a8333Snatalie li - Sun Microsystems - Irvine United States }; 198b89a8333Snatalie li - Sun Microsystems - Irvine United States 199b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 200549ec3ffSdougm * list of properties that are related to security flavors. 201549ec3ffSdougm */ 202549ec3ffSdougm static char *seclist[] = { 203549ec3ffSdougm SHOPT_RO, 204549ec3ffSdougm SHOPT_RW, 205549ec3ffSdougm SHOPT_ROOT, 206549ec3ffSdougm SHOPT_WINDOW, 207b89a8333Snatalie li - Sun Microsystems - Irvine United States SHOPT_NONE, 208b89a8333Snatalie li - Sun Microsystems - Irvine United States SHOPT_ROOT_MAPPING, 209549ec3ffSdougm NULL 210549ec3ffSdougm }; 211549ec3ffSdougm 212549ec3ffSdougm /* structure for list of securities */ 213549ec3ffSdougm struct securities { 214549ec3ffSdougm sa_security_t security; 215549ec3ffSdougm struct securities *next; 216549ec3ffSdougm }; 217549ec3ffSdougm 218549ec3ffSdougm /* 219b89a8333Snatalie li - Sun Microsystems - Irvine United States * findcharset(charset) 220b89a8333Snatalie li - Sun Microsystems - Irvine United States * 221b89a8333Snatalie li - Sun Microsystems - Irvine United States * Returns B_TRUE if the charset is a legal conversion otherwise 222b89a8333Snatalie li - Sun Microsystems - Irvine United States * B_FALSE. This will need to be rewritten to be more efficient when 223b89a8333Snatalie li - Sun Microsystems - Irvine United States * we have a dynamic list of legal conversions. 224b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 225b89a8333Snatalie li - Sun Microsystems - Irvine United States 226b89a8333Snatalie li - Sun Microsystems - Irvine United States static boolean_t 227b89a8333Snatalie li - Sun Microsystems - Irvine United States findcharset(char *charset) 228b89a8333Snatalie li - Sun Microsystems - Irvine United States { 229b89a8333Snatalie li - Sun Microsystems - Irvine United States int i; 230b89a8333Snatalie li - Sun Microsystems - Irvine United States 231b89a8333Snatalie li - Sun Microsystems - Irvine United States for (i = 0; legal_conv[i] != NULL; i++) 232b89a8333Snatalie li - Sun Microsystems - Irvine United States if (strcmp(charset, legal_conv[i]) == 0) 233b89a8333Snatalie li - Sun Microsystems - Irvine United States return (B_TRUE); 234b89a8333Snatalie li - Sun Microsystems - Irvine United States return (B_FALSE); 235b89a8333Snatalie li - Sun Microsystems - Irvine United States } 236b89a8333Snatalie li - Sun Microsystems - Irvine United States 237b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 238549ec3ffSdougm * findopt(name) 239549ec3ffSdougm * 240549ec3ffSdougm * Lookup option "name" in the option table and return the table 241549ec3ffSdougm * index. 242549ec3ffSdougm */ 243549ec3ffSdougm 244549ec3ffSdougm static int 245549ec3ffSdougm findopt(char *name) 246549ec3ffSdougm { 247549ec3ffSdougm int i; 248549ec3ffSdougm if (name != NULL) { 249549ec3ffSdougm for (i = 0; optdefs[i].tag != NULL; i++) { 250549ec3ffSdougm if (strcmp(optdefs[i].tag, name) == 0) 251549ec3ffSdougm return (i); 252549ec3ffSdougm } 253b89a8333Snatalie li - Sun Microsystems - Irvine United States if (findcharset(name)) 254b89a8333Snatalie li - Sun Microsystems - Irvine United States return (OPT_CHARSET_MAP); 255549ec3ffSdougm } 256549ec3ffSdougm return (-1); 257549ec3ffSdougm } 258549ec3ffSdougm 259549ec3ffSdougm /* 260549ec3ffSdougm * gettype(name) 261549ec3ffSdougm * 262549ec3ffSdougm * Return the type of option "name". 263549ec3ffSdougm */ 264549ec3ffSdougm 265549ec3ffSdougm static int 266549ec3ffSdougm gettype(char *name) 267549ec3ffSdougm { 268549ec3ffSdougm int optdef; 269549ec3ffSdougm 270549ec3ffSdougm optdef = findopt(name); 271549ec3ffSdougm if (optdef != -1) 272549ec3ffSdougm return (optdefs[optdef].type); 273549ec3ffSdougm return (OPT_TYPE_ANY); 274549ec3ffSdougm } 275549ec3ffSdougm 276549ec3ffSdougm /* 277549ec3ffSdougm * nfs_validate_security_mode(mode) 278549ec3ffSdougm * 279549ec3ffSdougm * is the specified mode string a valid one for use with NFS? 280549ec3ffSdougm */ 281549ec3ffSdougm 282549ec3ffSdougm static int 283549ec3ffSdougm nfs_validate_security_mode(char *mode) 284549ec3ffSdougm { 285549ec3ffSdougm seconfig_t secinfo; 286549ec3ffSdougm int err; 287549ec3ffSdougm 288549ec3ffSdougm (void) memset(&secinfo, '\0', sizeof (secinfo)); 289549ec3ffSdougm err = nfs_getseconfig_byname(mode, &secinfo); 290549ec3ffSdougm if (err == SC_NOERROR) 291549ec3ffSdougm return (1); 292549ec3ffSdougm return (0); 293549ec3ffSdougm } 294549ec3ffSdougm 295549ec3ffSdougm /* 296549ec3ffSdougm * nfs_is_security_opt(tok) 297549ec3ffSdougm * 298549ec3ffSdougm * check to see if tok represents an option that is only valid in some 299549ec3ffSdougm * security flavor. 300549ec3ffSdougm */ 301549ec3ffSdougm 302549ec3ffSdougm static int 303549ec3ffSdougm nfs_is_security_opt(char *tok) 304549ec3ffSdougm { 305549ec3ffSdougm int i; 306549ec3ffSdougm 307549ec3ffSdougm for (i = 0; seclist[i] != NULL; i++) { 308549ec3ffSdougm if (strcmp(tok, seclist[i]) == 0) 309549ec3ffSdougm return (1); 310549ec3ffSdougm } 311549ec3ffSdougm return (0); 312549ec3ffSdougm } 313549ec3ffSdougm 314549ec3ffSdougm /* 315549ec3ffSdougm * find_security(seclist, sec) 316549ec3ffSdougm * 317549ec3ffSdougm * Walk the current list of security flavors and return true if it is 318549ec3ffSdougm * present, else return false. 319549ec3ffSdougm */ 320549ec3ffSdougm 321549ec3ffSdougm static int 322549ec3ffSdougm find_security(struct securities *seclist, sa_security_t sec) 323549ec3ffSdougm { 324549ec3ffSdougm while (seclist != NULL) { 325549ec3ffSdougm if (seclist->security == sec) 326549ec3ffSdougm return (1); 327549ec3ffSdougm seclist = seclist->next; 328549ec3ffSdougm } 329549ec3ffSdougm return (0); 330549ec3ffSdougm } 331549ec3ffSdougm 332549ec3ffSdougm /* 333549ec3ffSdougm * make_security_list(group, securitymodes, proto) 334549ec3ffSdougm * go through the list of securitymodes and add them to the 335549ec3ffSdougm * group's list of security optionsets. We also keep a list of 336549ec3ffSdougm * those optionsets so we don't have to find them later. All of 337549ec3ffSdougm * these will get copies of the same properties. 338549ec3ffSdougm */ 339549ec3ffSdougm 340549ec3ffSdougm static struct securities * 341549ec3ffSdougm make_security_list(sa_group_t group, char *securitymodes, char *proto) 342549ec3ffSdougm { 343549ec3ffSdougm char *tok, *next = NULL; 344549ec3ffSdougm struct securities *curp, *headp = NULL, *prev; 345549ec3ffSdougm sa_security_t check; 346549ec3ffSdougm int freetok = 0; 347549ec3ffSdougm 348549ec3ffSdougm for (tok = securitymodes; tok != NULL; tok = next) { 349549ec3ffSdougm next = strchr(tok, ':'); 350549ec3ffSdougm if (next != NULL) 351549ec3ffSdougm *next++ = '\0'; 352549ec3ffSdougm if (strcmp(tok, "default") == 0) { 353549ec3ffSdougm /* resolve default into the real type */ 354549ec3ffSdougm tok = nfs_space_alias(tok); 355549ec3ffSdougm freetok = 1; 356549ec3ffSdougm } 357549ec3ffSdougm check = sa_get_security(group, tok, proto); 358549ec3ffSdougm 359549ec3ffSdougm /* add to the security list if it isn't there already */ 360549ec3ffSdougm if (check == NULL || !find_security(headp, check)) { 361549ec3ffSdougm curp = (struct securities *)calloc(1, 362549ec3ffSdougm sizeof (struct securities)); 363549ec3ffSdougm if (curp != NULL) { 364549ec3ffSdougm if (check == NULL) { 365a3351425Sdougm curp->security = sa_create_security( 366a3351425Sdougm group, tok, proto); 367549ec3ffSdougm } else { 368549ec3ffSdougm curp->security = check; 369549ec3ffSdougm } 370549ec3ffSdougm /* 371549ec3ffSdougm * note that the first time through the loop, 372549ec3ffSdougm * headp will be NULL and prev will be 373549ec3ffSdougm * undefined. Since headp is NULL, we set 374549ec3ffSdougm * both it and prev to the curp (first 375549ec3ffSdougm * structure to be allocated). 376549ec3ffSdougm * 377549ec3ffSdougm * later passes through the loop will have 378549ec3ffSdougm * headp not being NULL and prev will be used 379549ec3ffSdougm * to allocate at the end of the list. 380549ec3ffSdougm */ 381549ec3ffSdougm if (headp == NULL) { 382549ec3ffSdougm headp = curp; 383549ec3ffSdougm prev = curp; 384549ec3ffSdougm } else { 385549ec3ffSdougm prev->next = curp; 386549ec3ffSdougm prev = curp; 387549ec3ffSdougm } 388549ec3ffSdougm } 389549ec3ffSdougm } 390549ec3ffSdougm 391549ec3ffSdougm if (freetok) { 392549ec3ffSdougm freetok = 0; 393549ec3ffSdougm sa_free_attr_string(tok); 394549ec3ffSdougm } 395549ec3ffSdougm } 396549ec3ffSdougm return (headp); 397549ec3ffSdougm } 398549ec3ffSdougm 399549ec3ffSdougm static void 400549ec3ffSdougm free_security_list(struct securities *sec) 401549ec3ffSdougm { 402549ec3ffSdougm struct securities *next; 403549ec3ffSdougm if (sec != NULL) { 404549ec3ffSdougm for (next = sec->next; sec != NULL; sec = next) { 405549ec3ffSdougm next = sec->next; 406549ec3ffSdougm free(sec); 407549ec3ffSdougm } 408549ec3ffSdougm } 409549ec3ffSdougm } 410549ec3ffSdougm 411549ec3ffSdougm /* 412549ec3ffSdougm * nfs_alistcat(str1, str2, sep) 413549ec3ffSdougm * 414549ec3ffSdougm * concatenate str1 and str2 into a new string using sep as a separate 415549ec3ffSdougm * character. If memory allocation fails, return NULL; 416549ec3ffSdougm */ 417549ec3ffSdougm 418549ec3ffSdougm static char * 419549ec3ffSdougm nfs_alistcat(char *str1, char *str2, char sep) 420549ec3ffSdougm { 421549ec3ffSdougm char *newstr; 422549ec3ffSdougm size_t len; 423549ec3ffSdougm 424549ec3ffSdougm len = strlen(str1) + strlen(str2) + 2; 425549ec3ffSdougm newstr = (char *)malloc(len); 426549ec3ffSdougm if (newstr != NULL) 427549ec3ffSdougm (void) snprintf(newstr, len, "%s%c%s", str1, sep, str2); 428549ec3ffSdougm return (newstr); 429549ec3ffSdougm } 430549ec3ffSdougm 431549ec3ffSdougm /* 432549ec3ffSdougm * add_security_prop(sec, name, value, persist) 433549ec3ffSdougm * 434549ec3ffSdougm * Add the property to the securities structure. This accumulates 435549ec3ffSdougm * properties for as part of parsing legacy options. 436549ec3ffSdougm */ 437549ec3ffSdougm 438549ec3ffSdougm static int 439549ec3ffSdougm add_security_prop(struct securities *sec, char *name, char *value, 440549ec3ffSdougm int persist, int iszfs) 441549ec3ffSdougm { 442549ec3ffSdougm sa_property_t prop; 443549ec3ffSdougm int ret = SA_OK; 444549ec3ffSdougm 445549ec3ffSdougm for (; sec != NULL; sec = sec->next) { 446549ec3ffSdougm if (value == NULL) { 447a3351425Sdougm if (strcmp(name, SHOPT_RW) == 0 || 448a3351425Sdougm strcmp(name, SHOPT_RO) == 0) 449549ec3ffSdougm value = "*"; 450549ec3ffSdougm else 451549ec3ffSdougm value = "true"; 452549ec3ffSdougm } 453549ec3ffSdougm 454549ec3ffSdougm /* 455549ec3ffSdougm * Get the existing property, if it exists, so we can 456549ec3ffSdougm * determine what to do with it. The ro/rw/root 457549ec3ffSdougm * properties can be merged if multiple instances of 458549ec3ffSdougm * these properies are given. For example, if "rw" 459549ec3ffSdougm * exists with a value "host1" and a later token of 460549ec3ffSdougm * rw="host2" is seen, the values are merged into a 461549ec3ffSdougm * single rw="host1:host2". 462549ec3ffSdougm */ 463549ec3ffSdougm prop = sa_get_property(sec->security, name); 464549ec3ffSdougm 465549ec3ffSdougm if (prop != NULL) { 466549ec3ffSdougm char *oldvalue; 467549ec3ffSdougm char *newvalue; 468549ec3ffSdougm 469549ec3ffSdougm /* 470549ec3ffSdougm * The security options of ro/rw/root might appear 471549ec3ffSdougm * multiple times. If they do, the values need to be 472549ec3ffSdougm * merged into an access list. If it was previously 473549ec3ffSdougm * empty, the new value alone is added. 474549ec3ffSdougm */ 475549ec3ffSdougm oldvalue = sa_get_property_attr(prop, "value"); 476549ec3ffSdougm if (oldvalue != NULL) { 477549ec3ffSdougm /* 478549ec3ffSdougm * The general case is to concatenate the new 479549ec3ffSdougm * value onto the old value for multiple 480549ec3ffSdougm * rw(ro/root) properties. A special case 481549ec3ffSdougm * exists when either the old or new is the 482549ec3ffSdougm * "all" case. In the special case, if both 483549ec3ffSdougm * are "all", then it is "all", else if one is 484549ec3ffSdougm * an access-list, that replaces the "all". 485549ec3ffSdougm */ 486549ec3ffSdougm if (strcmp(oldvalue, "*") == 0) { 487549ec3ffSdougm /* Replace old value with new value. */ 488549ec3ffSdougm newvalue = strdup(value); 48997df5ac9Sdougm } else if (strcmp(value, "*") == 0 || 49097df5ac9Sdougm strcmp(oldvalue, value) == 0) { 491a3351425Sdougm /* 492a3351425Sdougm * Keep old value and ignore 493a3351425Sdougm * the new value. 494a3351425Sdougm */ 495549ec3ffSdougm newvalue = NULL; 496549ec3ffSdougm } else { 497a3351425Sdougm /* 498a3351425Sdougm * Make a new list of old plus new 499a3351425Sdougm * access-list. 500a3351425Sdougm */ 501a3351425Sdougm newvalue = nfs_alistcat(oldvalue, 502a3351425Sdougm value, ':'); 503549ec3ffSdougm } 504549ec3ffSdougm 505549ec3ffSdougm if (newvalue != NULL) { 506549ec3ffSdougm (void) sa_remove_property(prop); 507a3351425Sdougm prop = sa_create_property(name, 508a3351425Sdougm newvalue); 509a3351425Sdougm ret = sa_add_property(sec->security, 510a3351425Sdougm prop); 511549ec3ffSdougm free(newvalue); 512549ec3ffSdougm } 513549ec3ffSdougm if (oldvalue != NULL) 514549ec3ffSdougm sa_free_attr_string(oldvalue); 515549ec3ffSdougm } 516549ec3ffSdougm } else { 517549ec3ffSdougm prop = sa_create_property(name, value); 518549ec3ffSdougm ret = sa_add_property(sec->security, prop); 519549ec3ffSdougm } 520549ec3ffSdougm if (ret == SA_OK && !iszfs) { 521549ec3ffSdougm ret = sa_commit_properties(sec->security, !persist); 522549ec3ffSdougm } 523549ec3ffSdougm } 524549ec3ffSdougm return (ret); 525549ec3ffSdougm } 526549ec3ffSdougm 527549ec3ffSdougm /* 528549ec3ffSdougm * check to see if group/share is persistent. 529549ec3ffSdougm */ 530549ec3ffSdougm static int 531549ec3ffSdougm is_persistent(sa_group_t group) 532549ec3ffSdougm { 533549ec3ffSdougm char *type; 534549ec3ffSdougm int persist = 1; 535549ec3ffSdougm 536549ec3ffSdougm type = sa_get_group_attr(group, "type"); 537549ec3ffSdougm if (type != NULL && strcmp(type, "persist") != 0) 538549ec3ffSdougm persist = 0; 539549ec3ffSdougm if (type != NULL) 540549ec3ffSdougm sa_free_attr_string(type); 541549ec3ffSdougm return (persist); 542549ec3ffSdougm } 543549ec3ffSdougm 544549ec3ffSdougm /* 545549ec3ffSdougm * invalid_security(options) 546549ec3ffSdougm * 547549ec3ffSdougm * search option string for any invalid sec= type. 548549ec3ffSdougm * return true (1) if any are not valid else false (0) 549549ec3ffSdougm */ 550549ec3ffSdougm static int 551549ec3ffSdougm invalid_security(char *options) 552549ec3ffSdougm { 553549ec3ffSdougm char *copy, *base, *token, *value; 554549ec3ffSdougm int ret = 0; 555549ec3ffSdougm 556549ec3ffSdougm copy = strdup(options); 557549ec3ffSdougm token = base = copy; 558549ec3ffSdougm while (token != NULL && ret == 0) { 559549ec3ffSdougm token = strtok(base, ","); 560549ec3ffSdougm base = NULL; 561549ec3ffSdougm if (token != NULL) { 562549ec3ffSdougm value = strchr(token, '='); 563549ec3ffSdougm if (value != NULL) 564549ec3ffSdougm *value++ = '\0'; 565549ec3ffSdougm if (strcmp(token, "sec") == 0) { 566a3351425Sdougm /* HAVE security flavors so check them */ 567549ec3ffSdougm char *tok, *next; 568a3351425Sdougm for (next = NULL, tok = value; tok != NULL; 569a3351425Sdougm tok = next) { 570549ec3ffSdougm next = strchr(tok, ':'); 571549ec3ffSdougm if (next != NULL) 572549ec3ffSdougm *next++ = '\0'; 573549ec3ffSdougm ret = !nfs_validate_security_mode(tok); 574549ec3ffSdougm if (ret) 575549ec3ffSdougm break; 576549ec3ffSdougm } 577549ec3ffSdougm } 578549ec3ffSdougm } 579549ec3ffSdougm } 580549ec3ffSdougm if (copy != NULL) 581549ec3ffSdougm free(copy); 582549ec3ffSdougm return (ret); 583549ec3ffSdougm } 584549ec3ffSdougm 585549ec3ffSdougm /* 586549ec3ffSdougm * nfs_parse_legacy_options(group, options) 587549ec3ffSdougm * 588549ec3ffSdougm * Parse the old style options into internal format and store on the 589549ec3ffSdougm * specified group. Group could be a share for full legacy support. 590549ec3ffSdougm */ 591549ec3ffSdougm 592549ec3ffSdougm static int 593549ec3ffSdougm nfs_parse_legacy_options(sa_group_t group, char *options) 594549ec3ffSdougm { 595aba7a40bSdougm char *dup; 596549ec3ffSdougm char *base; 597549ec3ffSdougm char *token; 598549ec3ffSdougm sa_optionset_t optionset; 599549ec3ffSdougm struct securities *security_list = NULL; 600549ec3ffSdougm sa_property_t prop; 601549ec3ffSdougm int ret = SA_OK; 602549ec3ffSdougm int iszfs = 0; 603549ec3ffSdougm sa_group_t parent; 604549ec3ffSdougm int persist = 0; 605549ec3ffSdougm char *lasts; 606549ec3ffSdougm 607549ec3ffSdougm /* do we have an existing optionset? */ 608549ec3ffSdougm optionset = sa_get_optionset(group, "nfs"); 609549ec3ffSdougm if (optionset == NULL) { 610549ec3ffSdougm /* didn't find existing optionset so create one */ 611549ec3ffSdougm optionset = sa_create_optionset(group, "nfs"); 612549ec3ffSdougm } else { 613549ec3ffSdougm /* 614da6c28aaSamw * Have an existing optionset . Ideally, we would need 615da6c28aaSamw * to compare options in order to detect errors. For 616da6c28aaSamw * now, we assume that the first optionset is the 617da6c28aaSamw * correct one and the others will be the same. An 618da6c28aaSamw * empty optionset is the same as no optionset so we 619da6c28aaSamw * don't want to exit in that case. Getting an empty 620da6c28aaSamw * optionset can occur with ZFS property checking. 621549ec3ffSdougm */ 622da6c28aaSamw if (sa_get_property(optionset, NULL) != NULL) 623549ec3ffSdougm return (ret); 624549ec3ffSdougm } 625549ec3ffSdougm 626549ec3ffSdougm if (strcmp(options, SHOPT_RW) == 0) { 627549ec3ffSdougm /* 628549ec3ffSdougm * there is a special case of only the option "rw" 629549ec3ffSdougm * being the default option. We don't have to do 630549ec3ffSdougm * anything. 631549ec3ffSdougm */ 632549ec3ffSdougm return (ret); 633549ec3ffSdougm } 634549ec3ffSdougm 635549ec3ffSdougm /* 636549ec3ffSdougm * check if security types are present and validate them. If 637549ec3ffSdougm * any are not legal, fail. 638549ec3ffSdougm */ 639549ec3ffSdougm 640549ec3ffSdougm if (invalid_security(options)) { 641549ec3ffSdougm return (SA_INVALID_SECURITY); 642549ec3ffSdougm } 643549ec3ffSdougm 644549ec3ffSdougm /* 645549ec3ffSdougm * in order to not attempt to change ZFS properties unless 646549ec3ffSdougm * absolutely necessary, we never do it in the legacy parsing. 647549ec3ffSdougm */ 648549ec3ffSdougm if (sa_is_share(group)) { 649549ec3ffSdougm char *zfs; 650549ec3ffSdougm parent = sa_get_parent_group(group); 651549ec3ffSdougm if (parent != NULL) { 652549ec3ffSdougm zfs = sa_get_group_attr(parent, "zfs"); 653549ec3ffSdougm if (zfs != NULL) { 654549ec3ffSdougm sa_free_attr_string(zfs); 655549ec3ffSdougm iszfs++; 656549ec3ffSdougm } 657549ec3ffSdougm } 658549ec3ffSdougm } else { 659549ec3ffSdougm iszfs = sa_group_is_zfs(group); 660549ec3ffSdougm } 661549ec3ffSdougm 662aba7a40bSdougm /* We need a copy of options for the next part. */ 663aba7a40bSdougm dup = strdup(options); 664aba7a40bSdougm if (dup == NULL) 665aba7a40bSdougm return (SA_NO_MEMORY); 666aba7a40bSdougm 667549ec3ffSdougm /* 668549ec3ffSdougm * we need to step through each option in the string and then 669549ec3ffSdougm * add either the option or the security option as needed. If 670549ec3ffSdougm * this is not a persistent share, don't commit to the 671549ec3ffSdougm * repository. If there is an error, we also want to abort the 672549ec3ffSdougm * processing and report it. 673549ec3ffSdougm */ 674549ec3ffSdougm persist = is_persistent(group); 675549ec3ffSdougm base = dup; 676549ec3ffSdougm token = dup; 677549ec3ffSdougm lasts = NULL; 678549ec3ffSdougm while (token != NULL && ret == SA_OK) { 679549ec3ffSdougm ret = SA_OK; 680549ec3ffSdougm token = strtok_r(base, ",", &lasts); 681549ec3ffSdougm base = NULL; 682549ec3ffSdougm if (token != NULL) { 683549ec3ffSdougm char *value; 684549ec3ffSdougm /* 685549ec3ffSdougm * if the option has a value, it will have an '=' to 686549ec3ffSdougm * separate the name from the value. The following 687549ec3ffSdougm * code will result in value != NULL and token 688549ec3ffSdougm * pointing to just the name if there is a value. 689549ec3ffSdougm */ 690549ec3ffSdougm value = strchr(token, '='); 691549ec3ffSdougm if (value != NULL) { 692549ec3ffSdougm *value++ = '\0'; 693549ec3ffSdougm } 694a3351425Sdougm if (strcmp(token, "sec") == 0 || 695a3351425Sdougm strcmp(token, "secure") == 0) { 696549ec3ffSdougm /* 697549ec3ffSdougm * Once in security parsing, we only 698549ec3ffSdougm * do security. We do need to move 699549ec3ffSdougm * between the security node and the 700549ec3ffSdougm * toplevel. The security tag goes on 701549ec3ffSdougm * the root while the following ones 702549ec3ffSdougm * go on the security. 703549ec3ffSdougm */ 704549ec3ffSdougm if (security_list != NULL) { 705a3351425Sdougm /* 706a3351425Sdougm * have an old list so close it and 707a3351425Sdougm * start the new 708a3351425Sdougm */ 709549ec3ffSdougm free_security_list(security_list); 710549ec3ffSdougm } 711549ec3ffSdougm if (strcmp(token, "secure") == 0) { 712549ec3ffSdougm value = "dh"; 713549ec3ffSdougm } else { 714549ec3ffSdougm if (value == NULL) { 715549ec3ffSdougm ret = SA_SYNTAX_ERR; 716549ec3ffSdougm break; 717549ec3ffSdougm } 718549ec3ffSdougm } 719a3351425Sdougm security_list = make_security_list(group, 720a3351425Sdougm value, "nfs"); 721549ec3ffSdougm } else { 722549ec3ffSdougm /* 723549ec3ffSdougm * Note that the "old" syntax allowed a 724549ec3ffSdougm * default security model This must be 725549ec3ffSdougm * accounted for and internally converted to 726549ec3ffSdougm * "standard" security structure. 727549ec3ffSdougm */ 728549ec3ffSdougm if (nfs_is_security_opt(token)) { 729549ec3ffSdougm if (security_list == NULL) { 730549ec3ffSdougm /* 731a3351425Sdougm * need to have a 732a3351425Sdougm * security 733a3351425Sdougm * option. This will 734a3351425Sdougm * be "closed" when a 735a3351425Sdougm * defined "sec=" 736a3351425Sdougm * option is 737a3351425Sdougm * seen. This is 738a3351425Sdougm * technically an 739a3351425Sdougm * error but will be 740a3351425Sdougm * allowed with 741a3351425Sdougm * warning. 742549ec3ffSdougm */ 743a3351425Sdougm security_list = 744a3351425Sdougm make_security_list(group, 745549ec3ffSdougm "default", 746549ec3ffSdougm "nfs"); 747549ec3ffSdougm } 748549ec3ffSdougm if (security_list != NULL) { 749a3351425Sdougm ret = add_security_prop( 750a3351425Sdougm security_list, token, 751a3351425Sdougm value, persist, iszfs); 752549ec3ffSdougm } else { 753549ec3ffSdougm ret = SA_NO_MEMORY; 754549ec3ffSdougm } 755549ec3ffSdougm } else { 756549ec3ffSdougm /* regular options */ 757549ec3ffSdougm if (value == NULL) { 758a3351425Sdougm if (strcmp(token, SHOPT_RW) == 759a3351425Sdougm 0 || strcmp(token, 760a3351425Sdougm SHOPT_RO) == 0) { 761549ec3ffSdougm value = "*"; 762a3351425Sdougm } else { 763549ec3ffSdougm value = "global"; 764a3351425Sdougm if (strcmp(token, 765a3351425Sdougm SHOPT_LOG) != 0) { 766549ec3ffSdougm value = "true"; 767549ec3ffSdougm } 768a3351425Sdougm } 769d6405362Sdougm } 770d6405362Sdougm /* 771d6405362Sdougm * In all cases, create the 772d6405362Sdougm * property specified. If the 773d6405362Sdougm * value was NULL, the default 774d6405362Sdougm * value will have been 775d6405362Sdougm * substituted. 776d6405362Sdougm */ 777d6405362Sdougm prop = sa_create_property(token, value); 778d6405362Sdougm ret = sa_add_property(optionset, prop); 779a3351425Sdougm if (ret != SA_OK) 780549ec3ffSdougm break; 781d6405362Sdougm 782549ec3ffSdougm if (!iszfs) { 783a3351425Sdougm ret = sa_commit_properties( 784a3351425Sdougm optionset, !persist); 785549ec3ffSdougm } 786549ec3ffSdougm } 787549ec3ffSdougm } 788549ec3ffSdougm } 789549ec3ffSdougm } 790549ec3ffSdougm if (security_list != NULL) 791549ec3ffSdougm free_security_list(security_list); 792aba7a40bSdougm 793549ec3ffSdougm free(dup); 794549ec3ffSdougm return (ret); 795549ec3ffSdougm } 796549ec3ffSdougm 797549ec3ffSdougm /* 798549ec3ffSdougm * is_a_number(number) 799549ec3ffSdougm * 800549ec3ffSdougm * is the string a number in one of the forms we want to use? 801549ec3ffSdougm */ 802549ec3ffSdougm 803549ec3ffSdougm static int 804549ec3ffSdougm is_a_number(char *number) 805549ec3ffSdougm { 806549ec3ffSdougm int ret = 1; 807549ec3ffSdougm int hex = 0; 808549ec3ffSdougm 809549ec3ffSdougm if (strncmp(number, "0x", 2) == 0) { 810549ec3ffSdougm number += 2; 811549ec3ffSdougm hex = 1; 812a3351425Sdougm } else if (*number == '-') { 813549ec3ffSdougm number++; /* skip the minus */ 814a3351425Sdougm } 815549ec3ffSdougm while (ret == 1 && *number != '\0') { 816549ec3ffSdougm if (hex) { 817549ec3ffSdougm ret = isxdigit(*number++); 818549ec3ffSdougm } else { 819549ec3ffSdougm ret = isdigit(*number++); 820549ec3ffSdougm } 821549ec3ffSdougm } 822549ec3ffSdougm return (ret); 823549ec3ffSdougm } 824549ec3ffSdougm 825549ec3ffSdougm /* 826549ec3ffSdougm * Look for the specified tag in the configuration file. If it is found, 827549ec3ffSdougm * enable logging and set the logging configuration information for exp. 828549ec3ffSdougm */ 829549ec3ffSdougm static void 830549ec3ffSdougm configlog(struct exportdata *exp, char *tag) 831549ec3ffSdougm { 832549ec3ffSdougm nfsl_config_t *configlist = NULL, *configp; 833549ec3ffSdougm int error = 0; 834549ec3ffSdougm char globaltag[] = DEFAULTTAG; 835549ec3ffSdougm 836549ec3ffSdougm /* 837549ec3ffSdougm * Sends config errors to stderr 838549ec3ffSdougm */ 839549ec3ffSdougm nfsl_errs_to_syslog = B_FALSE; 840549ec3ffSdougm 841549ec3ffSdougm /* 842549ec3ffSdougm * get the list of configuration settings 843549ec3ffSdougm */ 844549ec3ffSdougm error = nfsl_getconfig_list(&configlist); 845549ec3ffSdougm if (error) { 846549ec3ffSdougm (void) fprintf(stderr, 847a3351425Sdougm dgettext(TEXT_DOMAIN, "Cannot get log configuration: %s\n"), 848549ec3ffSdougm strerror(error)); 849549ec3ffSdougm } 850549ec3ffSdougm 851549ec3ffSdougm if (tag == NULL) 852549ec3ffSdougm tag = globaltag; 853549ec3ffSdougm if ((configp = nfsl_findconfig(configlist, tag, &error)) == NULL) { 854549ec3ffSdougm nfsl_freeconfig_list(&configlist); 855549ec3ffSdougm (void) fprintf(stderr, 856a3351425Sdougm dgettext(TEXT_DOMAIN, "No tags matching \"%s\"\n"), tag); 857549ec3ffSdougm /* bad configuration */ 858549ec3ffSdougm error = ENOENT; 859549ec3ffSdougm goto err; 860549ec3ffSdougm } 861549ec3ffSdougm 862549ec3ffSdougm if ((exp->ex_tag = strdup(tag)) == NULL) { 863549ec3ffSdougm error = ENOMEM; 864549ec3ffSdougm goto out; 865549ec3ffSdougm } 866549ec3ffSdougm if ((exp->ex_log_buffer = strdup(configp->nc_bufferpath)) == NULL) { 867549ec3ffSdougm error = ENOMEM; 868549ec3ffSdougm goto out; 869549ec3ffSdougm } 870549ec3ffSdougm exp->ex_flags |= EX_LOG; 871549ec3ffSdougm if (configp->nc_rpclogpath != NULL) 872549ec3ffSdougm exp->ex_flags |= EX_LOG_ALLOPS; 873549ec3ffSdougm out: 874549ec3ffSdougm if (configlist != NULL) 875549ec3ffSdougm nfsl_freeconfig_list(&configlist); 876549ec3ffSdougm 877549ec3ffSdougm err: 878549ec3ffSdougm if (error != 0) { 879549ec3ffSdougm if (exp->ex_flags != NULL) 880549ec3ffSdougm free(exp->ex_tag); 881549ec3ffSdougm if (exp->ex_log_buffer != NULL) 882549ec3ffSdougm free(exp->ex_log_buffer); 883549ec3ffSdougm (void) fprintf(stderr, 884a3351425Sdougm dgettext(TEXT_DOMAIN, "Cannot set log configuration: %s\n"), 885549ec3ffSdougm strerror(error)); 886549ec3ffSdougm } 887549ec3ffSdougm } 888549ec3ffSdougm 889549ec3ffSdougm /* 890549ec3ffSdougm * fill_export_from_optionset(export, optionset) 891549ec3ffSdougm * 892549ec3ffSdougm * In order to share, we need to set all the possible general options 893549ec3ffSdougm * into the export structure. Share info will be filled in by the 894549ec3ffSdougm * caller. Various property values get turned into structure specific 895549ec3ffSdougm * values. 896549ec3ffSdougm */ 897549ec3ffSdougm 898549ec3ffSdougm static int 899549ec3ffSdougm fill_export_from_optionset(struct exportdata *export, sa_optionset_t optionset) 900549ec3ffSdougm { 901549ec3ffSdougm sa_property_t option; 902549ec3ffSdougm int ret = SA_OK; 903549ec3ffSdougm 904549ec3ffSdougm for (option = sa_get_property(optionset, NULL); 905549ec3ffSdougm option != NULL; option = sa_get_next_property(option)) { 906549ec3ffSdougm char *name; 907549ec3ffSdougm char *value; 908549ec3ffSdougm uint32_t val; 909549ec3ffSdougm 910549ec3ffSdougm /* 911549ec3ffSdougm * since options may be set/reset multiple times, always do an 912549ec3ffSdougm * explicit set or clear of the option. This allows defaults 913da6c28aaSamw * to be set and then the protocol specific to override. 914549ec3ffSdougm */ 915549ec3ffSdougm 916549ec3ffSdougm name = sa_get_property_attr(option, "type"); 917549ec3ffSdougm value = sa_get_property_attr(option, "value"); 918549ec3ffSdougm switch (findopt(name)) { 919549ec3ffSdougm case OPT_ANON: 920549ec3ffSdougm if (value != NULL && is_a_number(value)) { 921549ec3ffSdougm val = strtoul(value, NULL, 0); 922549ec3ffSdougm } else { 923549ec3ffSdougm struct passwd *pw; 924549ec3ffSdougm pw = getpwnam(value != NULL ? value : "nobody"); 925549ec3ffSdougm if (pw != NULL) { 926549ec3ffSdougm val = pw->pw_uid; 927549ec3ffSdougm } else { 928549ec3ffSdougm val = UID_NOBODY; 929549ec3ffSdougm } 930549ec3ffSdougm endpwent(); 931549ec3ffSdougm } 932549ec3ffSdougm export->ex_anon = val; 933549ec3ffSdougm break; 934549ec3ffSdougm case OPT_NOSUID: 935a3351425Sdougm if (value != NULL && (strcasecmp(value, "true") == 0 || 936a3351425Sdougm strcmp(value, "1") == 0)) 937549ec3ffSdougm export->ex_flags |= EX_NOSUID; 938549ec3ffSdougm else 939549ec3ffSdougm export->ex_flags &= ~EX_NOSUID; 940549ec3ffSdougm break; 941549ec3ffSdougm case OPT_ACLOK: 942a3351425Sdougm if (value != NULL && (strcasecmp(value, "true") == 0 || 943549ec3ffSdougm strcmp(value, "1") == 0)) 944549ec3ffSdougm export->ex_flags |= EX_ACLOK; 945549ec3ffSdougm else 946549ec3ffSdougm export->ex_flags &= ~EX_ACLOK; 947549ec3ffSdougm break; 948549ec3ffSdougm case OPT_NOSUB: 949a3351425Sdougm if (value != NULL && (strcasecmp(value, "true") == 0 || 950a3351425Sdougm strcmp(value, "1") == 0)) 951549ec3ffSdougm export->ex_flags |= EX_NOSUB; 952549ec3ffSdougm else 953549ec3ffSdougm export->ex_flags &= ~EX_NOSUB; 954549ec3ffSdougm break; 955549ec3ffSdougm case OPT_PUBLIC: 956a3351425Sdougm if (value != NULL && (strcasecmp(value, "true") == 0 || 957a3351425Sdougm strcmp(value, "1") == 0)) 958549ec3ffSdougm export->ex_flags |= EX_PUBLIC; 959549ec3ffSdougm else 960549ec3ffSdougm export->ex_flags &= ~EX_PUBLIC; 961549ec3ffSdougm break; 962549ec3ffSdougm case OPT_INDEX: 963a3351425Sdougm if (value != NULL && (strcmp(value, "..") == 0 || 964a3351425Sdougm strchr(value, '/') != NULL)) { 965549ec3ffSdougm /* this is an error */ 966549ec3ffSdougm (void) printf(dgettext(TEXT_DOMAIN, 967549ec3ffSdougm "NFS: index=\"%s\" not valid;" 968549ec3ffSdougm "must be a filename.\n"), 969549ec3ffSdougm value); 970549ec3ffSdougm break; 971549ec3ffSdougm } 972549ec3ffSdougm if (value != NULL && *value != '\0' && 973549ec3ffSdougm strcmp(value, ".") != 0) { 974549ec3ffSdougm /* valid index file string */ 975549ec3ffSdougm if (export->ex_index != NULL) { 976549ec3ffSdougm /* left over from "default" */ 977549ec3ffSdougm free(export->ex_index); 978549ec3ffSdougm } 979a3351425Sdougm /* remember to free */ 980a3351425Sdougm export->ex_index = strdup(value); 981549ec3ffSdougm if (export->ex_index == NULL) { 982549ec3ffSdougm (void) printf(dgettext(TEXT_DOMAIN, 983549ec3ffSdougm "NFS: out of memory setting " 984549ec3ffSdougm "index property\n")); 985549ec3ffSdougm break; 986549ec3ffSdougm } 987549ec3ffSdougm export->ex_flags |= EX_INDEX; 988549ec3ffSdougm } 989549ec3ffSdougm break; 990549ec3ffSdougm case OPT_LOG: 991549ec3ffSdougm if (value == NULL) 992549ec3ffSdougm value = strdup("global"); 993549ec3ffSdougm if (value != NULL) 994a3351425Sdougm configlog(export, 995a3351425Sdougm strlen(value) ? value : "global"); 996549ec3ffSdougm break; 997b89a8333Snatalie li - Sun Microsystems - Irvine United States case OPT_CHARSET_MAP: 998b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 999b89a8333Snatalie li - Sun Microsystems - Irvine United States * Set EX_CHARMAP when there is at least one 1000b89a8333Snatalie li - Sun Microsystems - Irvine United States * charmap conversion property. This will get 1001b89a8333Snatalie li - Sun Microsystems - Irvine United States * checked by the nfs server when it needs to. 1002b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 1003b89a8333Snatalie li - Sun Microsystems - Irvine United States export->ex_flags |= EX_CHARMAP; 1004b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 10056764e83bSVallish Vaidyeshwara case OPT_NOACLFAB: 10066764e83bSVallish Vaidyeshwara if (value != NULL && (strcasecmp(value, "true") == 0 || 10076764e83bSVallish Vaidyeshwara strcmp(value, "1") == 0)) 10086764e83bSVallish Vaidyeshwara export->ex_flags |= EX_NOACLFAB; 10096764e83bSVallish Vaidyeshwara else 10106764e83bSVallish Vaidyeshwara export->ex_flags &= ~EX_NOACLFAB; 10116764e83bSVallish Vaidyeshwara break; 1012549ec3ffSdougm default: 1013549ec3ffSdougm /* have a syntactic error */ 1014549ec3ffSdougm (void) printf(dgettext(TEXT_DOMAIN, 1015549ec3ffSdougm "NFS: unrecognized option %s=%s\n"), 1016fe1c642dSBill Krier name != NULL ? name : "", 1017fe1c642dSBill Krier value != NULL ? value : ""); 1018549ec3ffSdougm break; 1019549ec3ffSdougm } 1020549ec3ffSdougm if (name != NULL) 1021549ec3ffSdougm sa_free_attr_string(name); 1022549ec3ffSdougm if (value != NULL) 1023549ec3ffSdougm sa_free_attr_string(value); 1024549ec3ffSdougm } 1025549ec3ffSdougm return (ret); 1026549ec3ffSdougm } 1027549ec3ffSdougm 1028549ec3ffSdougm /* 1029549ec3ffSdougm * cleanup_export(export) 1030549ec3ffSdougm * 1031549ec3ffSdougm * Cleanup the allocated areas so we don't leak memory 1032549ec3ffSdougm */ 1033549ec3ffSdougm 1034549ec3ffSdougm static void 1035549ec3ffSdougm cleanup_export(struct exportdata *export) 1036549ec3ffSdougm { 1037549ec3ffSdougm int i; 1038549ec3ffSdougm 1039549ec3ffSdougm if (export->ex_index != NULL) 1040549ec3ffSdougm free(export->ex_index); 1041549ec3ffSdougm if (export->ex_secinfo != NULL) { 1042549ec3ffSdougm for (i = 0; i < export->ex_seccnt; i++) 1043a3351425Sdougm if (export->ex_secinfo[i].s_rootnames != NULL) 1044549ec3ffSdougm free(export->ex_secinfo[i].s_rootnames); 1045549ec3ffSdougm free(export->ex_secinfo); 1046549ec3ffSdougm } 1047549ec3ffSdougm } 1048549ec3ffSdougm 1049549ec3ffSdougm /* 1050549ec3ffSdougm * Given a seconfig entry and a colon-separated 1051549ec3ffSdougm * list of names, allocate an array big enough 1052549ec3ffSdougm * to hold the root list, then convert each name to 1053549ec3ffSdougm * a principal name according to the security 1054549ec3ffSdougm * info and assign it to an array element. 1055549ec3ffSdougm * Return the array and its size. 1056549ec3ffSdougm */ 1057549ec3ffSdougm static caddr_t * 1058549ec3ffSdougm get_rootnames(seconfig_t *sec, char *list, int *count) 1059549ec3ffSdougm { 1060549ec3ffSdougm caddr_t *a; 1061549ec3ffSdougm int c, i; 1062549ec3ffSdougm char *host, *p; 1063549ec3ffSdougm 1064549ec3ffSdougm /* 1065549ec3ffSdougm * Count the number of strings in the list. 1066549ec3ffSdougm * This is the number of colon separators + 1. 1067549ec3ffSdougm */ 1068549ec3ffSdougm c = 1; 1069549ec3ffSdougm for (p = list; *p; p++) 1070549ec3ffSdougm if (*p == ':') 1071549ec3ffSdougm c++; 1072549ec3ffSdougm *count = c; 1073549ec3ffSdougm 1074549ec3ffSdougm a = (caddr_t *)malloc(c * sizeof (char *)); 1075549ec3ffSdougm if (a == NULL) { 1076549ec3ffSdougm (void) printf(dgettext(TEXT_DOMAIN, 1077549ec3ffSdougm "get_rootnames: no memory\n")); 1078549ec3ffSdougm } else { 1079549ec3ffSdougm for (i = 0; i < c; i++) { 1080549ec3ffSdougm host = strtok(list, ":"); 1081549ec3ffSdougm if (!nfs_get_root_principal(sec, host, &a[i])) { 1082549ec3ffSdougm free(a); 1083549ec3ffSdougm a = NULL; 1084549ec3ffSdougm break; 1085549ec3ffSdougm } 1086549ec3ffSdougm list = NULL; 1087549ec3ffSdougm } 1088549ec3ffSdougm } 1089549ec3ffSdougm 1090549ec3ffSdougm return (a); 1091549ec3ffSdougm } 1092549ec3ffSdougm 1093549ec3ffSdougm /* 1094549ec3ffSdougm * fill_security_from_secopts(sp, secopts) 1095549ec3ffSdougm * 1096549ec3ffSdougm * Fill the secinfo structure from the secopts optionset. 1097549ec3ffSdougm */ 1098549ec3ffSdougm 1099549ec3ffSdougm static int 1100549ec3ffSdougm fill_security_from_secopts(struct secinfo *sp, sa_security_t secopts) 1101549ec3ffSdougm { 1102549ec3ffSdougm sa_property_t prop; 1103549ec3ffSdougm char *type; 1104549ec3ffSdougm int longform; 1105549ec3ffSdougm int err = SC_NOERROR; 1106b89a8333Snatalie li - Sun Microsystems - Irvine United States uint32_t val; 1107549ec3ffSdougm 1108549ec3ffSdougm type = sa_get_security_attr(secopts, "sectype"); 1109549ec3ffSdougm if (type != NULL) { 1110549ec3ffSdougm /* named security type needs secinfo to be filled in */ 1111549ec3ffSdougm err = nfs_getseconfig_byname(type, &sp->s_secinfo); 1112549ec3ffSdougm sa_free_attr_string(type); 1113549ec3ffSdougm if (err != SC_NOERROR) 1114549ec3ffSdougm return (err); 1115549ec3ffSdougm } else { 1116549ec3ffSdougm /* default case */ 1117549ec3ffSdougm err = nfs_getseconfig_default(&sp->s_secinfo); 1118549ec3ffSdougm if (err != SC_NOERROR) 1119549ec3ffSdougm return (err); 1120549ec3ffSdougm } 1121549ec3ffSdougm 1122549ec3ffSdougm err = SA_OK; 1123549ec3ffSdougm for (prop = sa_get_property(secopts, NULL); 1124549ec3ffSdougm prop != NULL && err == SA_OK; 1125549ec3ffSdougm prop = sa_get_next_property(prop)) { 1126549ec3ffSdougm char *name; 1127549ec3ffSdougm char *value; 1128549ec3ffSdougm 1129549ec3ffSdougm name = sa_get_property_attr(prop, "type"); 1130549ec3ffSdougm value = sa_get_property_attr(prop, "value"); 1131549ec3ffSdougm 1132549ec3ffSdougm longform = value != NULL && strcmp(value, "*") != 0; 1133549ec3ffSdougm 1134549ec3ffSdougm switch (findopt(name)) { 1135549ec3ffSdougm case OPT_RO: 1136549ec3ffSdougm sp->s_flags |= longform ? M_ROL : M_RO; 1137549ec3ffSdougm break; 1138549ec3ffSdougm case OPT_RW: 1139549ec3ffSdougm sp->s_flags |= longform ? M_RWL : M_RW; 1140549ec3ffSdougm break; 1141549ec3ffSdougm case OPT_ROOT: 1142549ec3ffSdougm sp->s_flags |= M_ROOT; 1143549ec3ffSdougm /* 1144549ec3ffSdougm * if we are using AUTH_UNIX, handle like other things 1145549ec3ffSdougm * such as RO/RW 1146549ec3ffSdougm */ 1147549ec3ffSdougm if (sp->s_secinfo.sc_rpcnum == AUTH_UNIX) 1148549ec3ffSdougm continue; 1149549ec3ffSdougm /* not AUTH_UNIX */ 1150549ec3ffSdougm if (value != NULL) { 1151a3351425Sdougm sp->s_rootnames = get_rootnames(&sp->s_secinfo, 1152a3351425Sdougm value, &sp->s_rootcnt); 1153549ec3ffSdougm if (sp->s_rootnames == NULL) { 1154549ec3ffSdougm err = SA_BAD_VALUE; 1155a3351425Sdougm (void) fprintf(stderr, 1156a3351425Sdougm dgettext(TEXT_DOMAIN, 1157549ec3ffSdougm "Bad root list\n")); 1158549ec3ffSdougm } 1159549ec3ffSdougm } 1160549ec3ffSdougm break; 1161b89a8333Snatalie li - Sun Microsystems - Irvine United States case OPT_NONE: 1162b89a8333Snatalie li - Sun Microsystems - Irvine United States sp->s_flags |= M_NONE; 1163b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 1164549ec3ffSdougm case OPT_WINDOW: 1165549ec3ffSdougm if (value != NULL) { 1166549ec3ffSdougm sp->s_window = atoi(value); 1167a3351425Sdougm /* just in case */ 1168549ec3ffSdougm if (sp->s_window < 0) 1169a3351425Sdougm sp->s_window = DEF_WIN; 1170549ec3ffSdougm } 1171549ec3ffSdougm break; 1172b89a8333Snatalie li - Sun Microsystems - Irvine United States case OPT_ROOT_MAPPING: 1173b89a8333Snatalie li - Sun Microsystems - Irvine United States if (value != NULL && is_a_number(value)) { 1174b89a8333Snatalie li - Sun Microsystems - Irvine United States val = strtoul(value, NULL, 0); 1175b89a8333Snatalie li - Sun Microsystems - Irvine United States } else { 1176b89a8333Snatalie li - Sun Microsystems - Irvine United States struct passwd *pw; 1177b89a8333Snatalie li - Sun Microsystems - Irvine United States pw = getpwnam(value != NULL ? value : "nobody"); 1178b89a8333Snatalie li - Sun Microsystems - Irvine United States if (pw != NULL) { 1179b89a8333Snatalie li - Sun Microsystems - Irvine United States val = pw->pw_uid; 1180b89a8333Snatalie li - Sun Microsystems - Irvine United States } else { 1181b89a8333Snatalie li - Sun Microsystems - Irvine United States val = UID_NOBODY; 1182b89a8333Snatalie li - Sun Microsystems - Irvine United States } 1183b89a8333Snatalie li - Sun Microsystems - Irvine United States endpwent(); 1184b89a8333Snatalie li - Sun Microsystems - Irvine United States } 1185b89a8333Snatalie li - Sun Microsystems - Irvine United States sp->s_rootid = val; 1186b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 1187549ec3ffSdougm default: 1188549ec3ffSdougm break; 1189549ec3ffSdougm } 1190549ec3ffSdougm if (name != NULL) 1191549ec3ffSdougm sa_free_attr_string(name); 1192549ec3ffSdougm if (value != NULL) 1193549ec3ffSdougm sa_free_attr_string(value); 1194549ec3ffSdougm } 1195549ec3ffSdougm /* if rw/ro options not set, use default of RW */ 1196549ec3ffSdougm if ((sp->s_flags & NFS_RWMODES) == 0) 1197549ec3ffSdougm sp->s_flags |= M_RW; 1198549ec3ffSdougm return (err); 1199549ec3ffSdougm } 1200549ec3ffSdougm 1201549ec3ffSdougm /* 1202549ec3ffSdougm * This is for testing only 1203549ec3ffSdougm * It displays the export structure that 1204549ec3ffSdougm * goes into the kernel. 1205549ec3ffSdougm */ 1206549ec3ffSdougm static void 1207549ec3ffSdougm printarg(char *path, struct exportdata *ep) 1208549ec3ffSdougm { 1209549ec3ffSdougm int i, j; 1210549ec3ffSdougm struct secinfo *sp; 1211549ec3ffSdougm 1212549ec3ffSdougm if (debug == 0) 1213549ec3ffSdougm return; 1214549ec3ffSdougm 1215549ec3ffSdougm (void) printf("%s:\n", path); 1216549ec3ffSdougm (void) printf("\tex_version = %d\n", ep->ex_version); 1217549ec3ffSdougm (void) printf("\tex_path = %s\n", ep->ex_path); 1218549ec3ffSdougm (void) printf("\tex_pathlen = %ld\n", (ulong_t)ep->ex_pathlen); 1219549ec3ffSdougm (void) printf("\tex_flags: (0x%02x) ", ep->ex_flags); 1220549ec3ffSdougm if (ep->ex_flags & EX_NOSUID) 1221549ec3ffSdougm (void) printf("NOSUID "); 1222549ec3ffSdougm if (ep->ex_flags & EX_ACLOK) 1223549ec3ffSdougm (void) printf("ACLOK "); 1224549ec3ffSdougm if (ep->ex_flags & EX_PUBLIC) 1225549ec3ffSdougm (void) printf("PUBLIC "); 1226549ec3ffSdougm if (ep->ex_flags & EX_NOSUB) 1227549ec3ffSdougm (void) printf("NOSUB "); 1228549ec3ffSdougm if (ep->ex_flags & EX_LOG) 1229549ec3ffSdougm (void) printf("LOG "); 1230b89a8333Snatalie li - Sun Microsystems - Irvine United States if (ep->ex_flags & EX_CHARMAP) 1231b89a8333Snatalie li - Sun Microsystems - Irvine United States (void) printf("CHARMAP "); 1232549ec3ffSdougm if (ep->ex_flags & EX_LOG_ALLOPS) 1233549ec3ffSdougm (void) printf("LOG_ALLOPS "); 1234549ec3ffSdougm if (ep->ex_flags == 0) 1235549ec3ffSdougm (void) printf("(none)"); 1236549ec3ffSdougm (void) printf("\n"); 1237549ec3ffSdougm if (ep->ex_flags & EX_LOG) { 1238549ec3ffSdougm (void) printf("\tex_log_buffer = %s\n", 1239549ec3ffSdougm (ep->ex_log_buffer ? ep->ex_log_buffer : "(NULL)")); 1240549ec3ffSdougm (void) printf("\tex_tag = %s\n", 1241549ec3ffSdougm (ep->ex_tag ? ep->ex_tag : "(NULL)")); 1242549ec3ffSdougm } 1243549ec3ffSdougm (void) printf("\tex_anon = %d\n", ep->ex_anon); 1244549ec3ffSdougm (void) printf("\tex_seccnt = %d\n", ep->ex_seccnt); 1245549ec3ffSdougm (void) printf("\n"); 1246549ec3ffSdougm for (i = 0; i < ep->ex_seccnt; i++) { 1247549ec3ffSdougm sp = &ep->ex_secinfo[i]; 1248549ec3ffSdougm (void) printf("\t\ts_secinfo = %s\n", sp->s_secinfo.sc_name); 1249549ec3ffSdougm (void) printf("\t\ts_flags: (0x%02x) ", sp->s_flags); 1250549ec3ffSdougm if (sp->s_flags & M_ROOT) (void) printf("M_ROOT "); 1251549ec3ffSdougm if (sp->s_flags & M_RO) (void) printf("M_RO "); 1252549ec3ffSdougm if (sp->s_flags & M_ROL) (void) printf("M_ROL "); 1253549ec3ffSdougm if (sp->s_flags & M_RW) (void) printf("M_RW "); 1254549ec3ffSdougm if (sp->s_flags & M_RWL) (void) printf("M_RWL "); 1255b89a8333Snatalie li - Sun Microsystems - Irvine United States if (sp->s_flags & M_NONE) (void) printf("M_NONE "); 1256549ec3ffSdougm if (sp->s_flags == 0) (void) printf("(none)"); 1257549ec3ffSdougm (void) printf("\n"); 1258549ec3ffSdougm (void) printf("\t\ts_window = %d\n", sp->s_window); 1259b89a8333Snatalie li - Sun Microsystems - Irvine United States (void) printf("\t\ts_rootid = %d\n", sp->s_rootid); 1260549ec3ffSdougm (void) printf("\t\ts_rootcnt = %d ", sp->s_rootcnt); 1261549ec3ffSdougm (void) fflush(stdout); 1262549ec3ffSdougm for (j = 0; j < sp->s_rootcnt; j++) 1263549ec3ffSdougm (void) printf("%s ", sp->s_rootnames[j] ? 1264549ec3ffSdougm sp->s_rootnames[j] : "<null>"); 1265549ec3ffSdougm (void) printf("\n\n"); 1266549ec3ffSdougm } 1267549ec3ffSdougm } 1268549ec3ffSdougm 1269549ec3ffSdougm /* 1270549ec3ffSdougm * count_security(opts) 1271549ec3ffSdougm * 1272549ec3ffSdougm * Count the number of security types (flavors). The optionset has 1273549ec3ffSdougm * been populated with the security flavors as a holding mechanism. 1274549ec3ffSdougm * We later use this number to allocate data structures. 1275549ec3ffSdougm */ 1276549ec3ffSdougm 1277549ec3ffSdougm static int 1278549ec3ffSdougm count_security(sa_optionset_t opts) 1279549ec3ffSdougm { 1280549ec3ffSdougm int count = 0; 1281549ec3ffSdougm sa_property_t prop; 1282549ec3ffSdougm if (opts != NULL) { 1283549ec3ffSdougm for (prop = sa_get_property(opts, NULL); prop != NULL; 1284549ec3ffSdougm prop = sa_get_next_property(prop)) { 1285549ec3ffSdougm count++; 1286549ec3ffSdougm } 1287549ec3ffSdougm } 1288549ec3ffSdougm return (count); 1289549ec3ffSdougm } 1290549ec3ffSdougm 1291549ec3ffSdougm /* 1292549ec3ffSdougm * nfs_sprint_option(rbuff, rbuffsize, incr, prop, sep) 1293549ec3ffSdougm * 1294549ec3ffSdougm * provides a mechanism to format NFS properties into legacy output 1295549ec3ffSdougm * format. If the buffer would overflow, it is reallocated and grown 1296549ec3ffSdougm * as appropriate. Special cases of converting internal form of values 1297549ec3ffSdougm * to those used by "share" are done. this function does one property 1298549ec3ffSdougm * at a time. 1299549ec3ffSdougm */ 1300549ec3ffSdougm 1301aed5d200Sdougm static int 1302549ec3ffSdougm nfs_sprint_option(char **rbuff, size_t *rbuffsize, size_t incr, 1303549ec3ffSdougm sa_property_t prop, int sep) 1304549ec3ffSdougm { 1305549ec3ffSdougm char *name; 1306549ec3ffSdougm char *value; 1307549ec3ffSdougm int curlen; 1308549ec3ffSdougm char *buff = *rbuff; 1309549ec3ffSdougm size_t buffsize = *rbuffsize; 1310aed5d200Sdougm int printed = B_FALSE; 1311549ec3ffSdougm 1312549ec3ffSdougm name = sa_get_property_attr(prop, "type"); 1313549ec3ffSdougm value = sa_get_property_attr(prop, "value"); 1314549ec3ffSdougm if (buff != NULL) 1315549ec3ffSdougm curlen = strlen(buff); 1316549ec3ffSdougm else 1317549ec3ffSdougm curlen = 0; 1318549ec3ffSdougm if (name != NULL) { 1319549ec3ffSdougm int len; 1320549ec3ffSdougm len = strlen(name) + sep; 1321549ec3ffSdougm 1322549ec3ffSdougm /* 1323549ec3ffSdougm * A future RFE would be to replace this with more 1324549ec3ffSdougm * generic code and to possibly handle more types. 1325549ec3ffSdougm */ 1326549ec3ffSdougm switch (gettype(name)) { 1327549ec3ffSdougm case OPT_TYPE_BOOLEAN: 1328aed5d200Sdougm /* 1329aed5d200Sdougm * For NFS, boolean value of FALSE means it 1330aed5d200Sdougm * doesn't show up in the option list at all. 1331aed5d200Sdougm */ 1332a3351425Sdougm if (value != NULL && strcasecmp(value, "false") == 0) 1333aed5d200Sdougm goto skip; 1334aed5d200Sdougm if (value != NULL) { 1335549ec3ffSdougm sa_free_attr_string(value); 1336549ec3ffSdougm value = NULL; 1337aed5d200Sdougm } 1338549ec3ffSdougm break; 1339549ec3ffSdougm case OPT_TYPE_ACCLIST: 1340549ec3ffSdougm if (value != NULL && strcmp(value, "*") == 0) { 1341549ec3ffSdougm sa_free_attr_string(value); 1342549ec3ffSdougm value = NULL; 1343549ec3ffSdougm } else { 1344549ec3ffSdougm if (value != NULL) 1345549ec3ffSdougm len += 1 + strlen(value); 1346549ec3ffSdougm } 1347549ec3ffSdougm break; 1348549ec3ffSdougm case OPT_TYPE_LOGTAG: 1349549ec3ffSdougm if (value != NULL && strlen(value) == 0) { 1350549ec3ffSdougm sa_free_attr_string(value); 1351549ec3ffSdougm value = NULL; 1352549ec3ffSdougm } else { 1353549ec3ffSdougm if (value != NULL) 1354549ec3ffSdougm len += 1 + strlen(value); 1355549ec3ffSdougm } 1356549ec3ffSdougm break; 1357549ec3ffSdougm default: 1358549ec3ffSdougm if (value != NULL) 1359549ec3ffSdougm len += 1 + strlen(value); 1360549ec3ffSdougm break; 1361549ec3ffSdougm } 1362549ec3ffSdougm while (buffsize <= (curlen + len)) { 1363549ec3ffSdougm /* need more room */ 1364549ec3ffSdougm buffsize += incr; 1365549ec3ffSdougm buff = realloc(buff, buffsize); 1366549ec3ffSdougm if (buff == NULL) { 1367549ec3ffSdougm /* realloc failed so free everything */ 1368549ec3ffSdougm if (*rbuff != NULL) 1369549ec3ffSdougm free(*rbuff); 1370549ec3ffSdougm } 1371549ec3ffSdougm *rbuff = buff; 1372549ec3ffSdougm *rbuffsize = buffsize; 1373549ec3ffSdougm if (buff == NULL) 1374aed5d200Sdougm goto skip; 1375aed5d200Sdougm 1376aed5d200Sdougm } 1377aed5d200Sdougm 1378aed5d200Sdougm if (buff == NULL) 1379aed5d200Sdougm goto skip; 1380aed5d200Sdougm 1381a3351425Sdougm if (value == NULL) { 1382549ec3ffSdougm (void) snprintf(buff + curlen, buffsize - curlen, 1383549ec3ffSdougm "%s%s", sep ? "," : "", 1384549ec3ffSdougm name, value != NULL ? value : ""); 1385a3351425Sdougm } else { 1386549ec3ffSdougm (void) snprintf(buff + curlen, buffsize - curlen, 1387549ec3ffSdougm "%s%s=%s", sep ? "," : "", 1388549ec3ffSdougm name, value != NULL ? value : ""); 1389549ec3ffSdougm } 1390aed5d200Sdougm printed = B_TRUE; 1391a3351425Sdougm } 1392aed5d200Sdougm skip: 1393549ec3ffSdougm if (name != NULL) 1394549ec3ffSdougm sa_free_attr_string(name); 1395549ec3ffSdougm if (value != NULL) 1396549ec3ffSdougm sa_free_attr_string(value); 1397aed5d200Sdougm return (printed); 1398549ec3ffSdougm } 1399549ec3ffSdougm 1400549ec3ffSdougm /* 1401549ec3ffSdougm * nfs_format_options(group, hier) 1402549ec3ffSdougm * 1403549ec3ffSdougm * format all the options on the group into an old-style option 1404549ec3ffSdougm * string. If hier is non-zero, walk up the tree to get inherited 1405549ec3ffSdougm * options. 1406549ec3ffSdougm */ 1407549ec3ffSdougm 1408549ec3ffSdougm static char * 1409549ec3ffSdougm nfs_format_options(sa_group_t group, int hier) 1410549ec3ffSdougm { 1411549ec3ffSdougm sa_optionset_t options = NULL; 1412a3351425Sdougm sa_optionset_t secoptions = NULL; 1413549ec3ffSdougm sa_property_t prop, secprop; 1414a3351425Sdougm sa_security_t security = NULL; 1415549ec3ffSdougm char *buff; 1416549ec3ffSdougm size_t buffsize; 1417a3351425Sdougm char *sectype = NULL; 1418a3351425Sdougm int sep = 0; 1419a3351425Sdougm 1420a3351425Sdougm 1421a3351425Sdougm buff = malloc(OPT_CHUNK); 1422a3351425Sdougm if (buff == NULL) { 1423a3351425Sdougm return (NULL); 1424a3351425Sdougm } 1425a3351425Sdougm 1426a3351425Sdougm buff[0] = '\0'; 1427a3351425Sdougm buffsize = OPT_CHUNK; 1428a3351425Sdougm 1429a3351425Sdougm /* 1430a3351425Sdougm * We may have a an optionset relative to this item. format 1431a3351425Sdougm * these if we find them and then add any security definitions. 1432a3351425Sdougm */ 1433549ec3ffSdougm 1434549ec3ffSdougm options = sa_get_derived_optionset(group, "nfs", hier); 1435549ec3ffSdougm 1436549ec3ffSdougm /* 1437549ec3ffSdougm * do the default set first but skip any option that is also 1438549ec3ffSdougm * in the protocol specific optionset. 1439549ec3ffSdougm */ 1440549ec3ffSdougm if (options != NULL) { 1441a3351425Sdougm for (prop = sa_get_property(options, NULL); 1442a3351425Sdougm prop != NULL; prop = sa_get_next_property(prop)) { 1443549ec3ffSdougm /* 1444a3351425Sdougm * use this one since we skipped any 1445a3351425Sdougm * of these that were also in 1446a3351425Sdougm * optdefault 1447549ec3ffSdougm */ 1448aed5d200Sdougm if (nfs_sprint_option(&buff, &buffsize, OPT_CHUNK, 1449aed5d200Sdougm prop, sep)) 1450aed5d200Sdougm sep = 1; 1451549ec3ffSdougm if (buff == NULL) { 1452549ec3ffSdougm /* 1453a3351425Sdougm * buff could become NULL if there 1454a3351425Sdougm * isn't enough memory for 1455a3351425Sdougm * nfs_sprint_option to realloc() 1456a3351425Sdougm * as necessary. We can't really 1457a3351425Sdougm * do anything about it at this 1458a3351425Sdougm * point so we return NULL. The 1459a3351425Sdougm * caller should handle the 1460a3351425Sdougm * failure. 1461549ec3ffSdougm */ 1462a3351425Sdougm if (options != NULL) 1463a3351425Sdougm sa_free_derived_optionset( 1464a3351425Sdougm options); 1465549ec3ffSdougm return (buff); 1466549ec3ffSdougm } 1467549ec3ffSdougm } 1468549ec3ffSdougm } 1469549ec3ffSdougm secoptions = (sa_optionset_t)sa_get_all_security_types(group, 1470549ec3ffSdougm "nfs", hier); 1471549ec3ffSdougm if (secoptions != NULL) { 1472549ec3ffSdougm for (secprop = sa_get_property(secoptions, NULL); 1473a3351425Sdougm secprop != NULL; 1474a3351425Sdougm secprop = sa_get_next_property(secprop)) { 1475549ec3ffSdougm sectype = sa_get_property_attr(secprop, "type"); 1476a3351425Sdougm security = 1477a3351425Sdougm (sa_security_t)sa_get_derived_security( 1478a3351425Sdougm group, sectype, "nfs", hier); 1479549ec3ffSdougm if (security != NULL) { 1480549ec3ffSdougm if (sectype != NULL) { 1481a3351425Sdougm prop = sa_create_property( 1482a3351425Sdougm "sec", sectype); 1483aed5d200Sdougm if (prop == NULL) 1484aed5d200Sdougm goto err; 1485aed5d200Sdougm if (nfs_sprint_option(&buff, 1486aed5d200Sdougm &buffsize, OPT_CHUNK, prop, sep)) 1487549ec3ffSdougm sep = 1; 1488aed5d200Sdougm (void) sa_remove_property(prop); 1489aed5d200Sdougm if (buff == NULL) 1490aed5d200Sdougm goto err; 1491549ec3ffSdougm } 1492a3351425Sdougm for (prop = sa_get_property(security, 1493a3351425Sdougm NULL); prop != NULL; 1494549ec3ffSdougm prop = sa_get_next_property(prop)) { 1495aed5d200Sdougm if (nfs_sprint_option(&buff, 1496aed5d200Sdougm &buffsize, OPT_CHUNK, prop, sep)) 1497aed5d200Sdougm sep = 1; 1498a3351425Sdougm if (buff == NULL) 1499a3351425Sdougm goto err; 1500a3351425Sdougm } 1501a3351425Sdougm sa_free_derived_optionset(security); 1502a3351425Sdougm } 1503a3351425Sdougm if (sectype != NULL) 1504a3351425Sdougm sa_free_attr_string(sectype); 1505a3351425Sdougm } 1506a3351425Sdougm sa_free_derived_optionset(secoptions); 1507a3351425Sdougm } 1508549ec3ffSdougm 1509a3351425Sdougm if (options != NULL) 1510a3351425Sdougm sa_free_derived_optionset(options); 1511a3351425Sdougm return (buff); 1512a3351425Sdougm 1513a3351425Sdougm err: 1514a3351425Sdougm /* 1515a3351425Sdougm * If we couldn't allocate memory for option printing, we need 1516a3351425Sdougm * to break out of the nested loops, cleanup and return NULL. 1517a3351425Sdougm */ 1518a3351425Sdougm if (secoptions != NULL) 1519549ec3ffSdougm sa_free_derived_optionset(secoptions); 1520549ec3ffSdougm if (security != NULL) 1521549ec3ffSdougm sa_free_derived_optionset(security); 1522549ec3ffSdougm if (sectype != NULL) 1523549ec3ffSdougm sa_free_attr_string(sectype); 1524549ec3ffSdougm if (options != NULL) 1525549ec3ffSdougm sa_free_derived_optionset(options); 15268d7e4166Sjose borrego return (NULL); 1527549ec3ffSdougm } 1528a3351425Sdougm 1529549ec3ffSdougm /* 1530549ec3ffSdougm * Append an entry to the nfslogtab file 1531549ec3ffSdougm */ 1532549ec3ffSdougm static int 1533549ec3ffSdougm nfslogtab_add(dir, buffer, tag) 1534549ec3ffSdougm char *dir, *buffer, *tag; 1535549ec3ffSdougm { 1536549ec3ffSdougm FILE *f; 1537549ec3ffSdougm struct logtab_ent lep; 1538549ec3ffSdougm int error = 0; 1539549ec3ffSdougm 1540549ec3ffSdougm /* 1541549ec3ffSdougm * Open the file for update and create it if necessary. 1542549ec3ffSdougm * This may leave the I/O offset at the end of the file, 1543549ec3ffSdougm * so rewind back to the beginning of the file. 1544549ec3ffSdougm */ 1545549ec3ffSdougm f = fopen(NFSLOGTAB, "a+"); 1546549ec3ffSdougm if (f == NULL) { 1547549ec3ffSdougm error = errno; 1548549ec3ffSdougm goto out; 1549549ec3ffSdougm } 1550549ec3ffSdougm rewind(f); 1551549ec3ffSdougm 1552549ec3ffSdougm if (lockf(fileno(f), F_LOCK, 0L) < 0) { 1553549ec3ffSdougm (void) fprintf(stderr, dgettext(TEXT_DOMAIN, 1554549ec3ffSdougm "share complete, however failed to lock %s " 1555549ec3ffSdougm "for update: %s\n"), NFSLOGTAB, strerror(errno)); 1556549ec3ffSdougm error = -1; 1557549ec3ffSdougm goto out; 1558549ec3ffSdougm } 1559549ec3ffSdougm 1560549ec3ffSdougm if (logtab_deactivate_after_boot(f) == -1) { 1561549ec3ffSdougm (void) fprintf(stderr, dgettext(TEXT_DOMAIN, 1562549ec3ffSdougm "share complete, however could not deactivate " 1563549ec3ffSdougm "entries in %s\n"), NFSLOGTAB); 1564549ec3ffSdougm error = -1; 1565549ec3ffSdougm goto out; 1566549ec3ffSdougm } 1567549ec3ffSdougm 1568549ec3ffSdougm /* 1569549ec3ffSdougm * Remove entries matching buffer and sharepoint since we're 1570549ec3ffSdougm * going to replace it with perhaps an entry with a new tag. 1571549ec3ffSdougm */ 1572549ec3ffSdougm if (logtab_rement(f, buffer, dir, NULL, -1)) { 1573549ec3ffSdougm (void) fprintf(stderr, dgettext(TEXT_DOMAIN, 1574549ec3ffSdougm "share complete, however could not remove matching " 1575549ec3ffSdougm "entries in %s\n"), NFSLOGTAB); 1576549ec3ffSdougm error = -1; 1577549ec3ffSdougm goto out; 1578549ec3ffSdougm } 1579549ec3ffSdougm 1580549ec3ffSdougm /* 1581549ec3ffSdougm * Deactivate all active entries matching this sharepoint 1582549ec3ffSdougm */ 1583549ec3ffSdougm if (logtab_deactivate(f, NULL, dir, NULL)) { 1584549ec3ffSdougm (void) fprintf(stderr, dgettext(TEXT_DOMAIN, 1585549ec3ffSdougm "share complete, however could not deactivate matching " 1586549ec3ffSdougm "entries in %s\n"), NFSLOGTAB); 1587549ec3ffSdougm error = -1; 1588549ec3ffSdougm goto out; 1589549ec3ffSdougm } 1590549ec3ffSdougm 1591549ec3ffSdougm lep.le_buffer = buffer; 1592549ec3ffSdougm lep.le_path = dir; 1593549ec3ffSdougm lep.le_tag = tag; 1594549ec3ffSdougm lep.le_state = LES_ACTIVE; 1595549ec3ffSdougm 1596549ec3ffSdougm /* 1597549ec3ffSdougm * Add new sharepoint / buffer location to nfslogtab 1598549ec3ffSdougm */ 1599549ec3ffSdougm if (logtab_putent(f, &lep) < 0) { 1600549ec3ffSdougm (void) fprintf(stderr, dgettext(TEXT_DOMAIN, 1601549ec3ffSdougm "share complete, however could not add %s to %s\n"), 1602549ec3ffSdougm dir, NFSLOGTAB); 1603549ec3ffSdougm error = -1; 1604549ec3ffSdougm } 1605549ec3ffSdougm 1606549ec3ffSdougm out: 1607549ec3ffSdougm if (f != NULL) 1608549ec3ffSdougm (void) fclose(f); 1609549ec3ffSdougm return (error); 1610549ec3ffSdougm } 1611549ec3ffSdougm 1612549ec3ffSdougm /* 1613549ec3ffSdougm * Deactivate an entry from the nfslogtab file 1614549ec3ffSdougm */ 1615549ec3ffSdougm static int 1616549ec3ffSdougm nfslogtab_deactivate(path) 1617549ec3ffSdougm char *path; 1618549ec3ffSdougm { 1619549ec3ffSdougm FILE *f; 1620549ec3ffSdougm int error = 0; 1621549ec3ffSdougm 1622549ec3ffSdougm f = fopen(NFSLOGTAB, "r+"); 1623549ec3ffSdougm if (f == NULL) { 1624549ec3ffSdougm error = errno; 1625549ec3ffSdougm goto out; 1626549ec3ffSdougm } 1627549ec3ffSdougm if (lockf(fileno(f), F_LOCK, 0L) < 0) { 1628549ec3ffSdougm error = errno; 1629549ec3ffSdougm (void) fprintf(stderr, dgettext(TEXT_DOMAIN, 1630549ec3ffSdougm "share complete, however could not lock %s for " 1631549ec3ffSdougm "update: %s\n"), NFSLOGTAB, strerror(error)); 1632549ec3ffSdougm goto out; 1633549ec3ffSdougm } 1634549ec3ffSdougm if (logtab_deactivate(f, NULL, path, NULL) == -1) { 1635549ec3ffSdougm error = -1; 1636549ec3ffSdougm (void) fprintf(stderr, 1637549ec3ffSdougm dgettext(TEXT_DOMAIN, 1638549ec3ffSdougm "share complete, however could not " 1639549ec3ffSdougm "deactivate %s in %s\n"), path, NFSLOGTAB); 1640549ec3ffSdougm goto out; 1641549ec3ffSdougm } 1642549ec3ffSdougm 1643549ec3ffSdougm out: if (f != NULL) 1644549ec3ffSdougm (void) fclose(f); 1645549ec3ffSdougm 1646549ec3ffSdougm return (error); 1647549ec3ffSdougm } 1648549ec3ffSdougm 1649549ec3ffSdougm /* 1650546405c3Sdougm * check_public(group, skipshare) 1651546405c3Sdougm * 1652546405c3Sdougm * Check the group for any shares that have the public property 1653546405c3Sdougm * enabled. We skip "skipshare" since that is the one we are 1654546405c3Sdougm * working with. This is a separate function to make handling 1655546405c3Sdougm * subgroups simpler. Returns true if there is a share with public. 1656546405c3Sdougm */ 1657546405c3Sdougm static int 1658546405c3Sdougm check_public(sa_group_t group, sa_share_t skipshare) 1659546405c3Sdougm { 1660546405c3Sdougm int exists = B_FALSE; 1661546405c3Sdougm sa_share_t share; 1662546405c3Sdougm sa_optionset_t opt; 1663546405c3Sdougm sa_property_t prop; 1664546405c3Sdougm char *shared; 1665546405c3Sdougm 1666546405c3Sdougm for (share = sa_get_share(group, NULL); share != NULL; 1667546405c3Sdougm share = sa_get_next_share(share)) { 1668546405c3Sdougm if (share == skipshare) 1669546405c3Sdougm continue; 1670546405c3Sdougm 1671546405c3Sdougm opt = sa_get_optionset(share, "nfs"); 1672546405c3Sdougm if (opt == NULL) 1673546405c3Sdougm continue; 1674546405c3Sdougm prop = sa_get_property(opt, "public"); 1675546405c3Sdougm if (prop == NULL) 1676546405c3Sdougm continue; 1677546405c3Sdougm shared = sa_get_share_attr(share, "shared"); 1678546405c3Sdougm if (shared != NULL) { 1679546405c3Sdougm exists = strcmp(shared, "true") == 0; 1680546405c3Sdougm sa_free_attr_string(shared); 1681546405c3Sdougm if (exists == B_TRUE) 1682546405c3Sdougm break; 1683546405c3Sdougm } 1684546405c3Sdougm } 1685546405c3Sdougm 1686546405c3Sdougm return (exists); 1687546405c3Sdougm } 1688546405c3Sdougm 1689546405c3Sdougm /* 1690687915e9Sdougm * public_exists(handle, share) 1691549ec3ffSdougm * 1692549ec3ffSdougm * check to see if public option is set on any other share than the 1693546405c3Sdougm * one specified. Need to check zfs sub-groups as well as the top 1694546405c3Sdougm * level groups. 1695549ec3ffSdougm */ 1696549ec3ffSdougm static int 1697687915e9Sdougm public_exists(sa_handle_t handle, sa_share_t skipshare) 1698549ec3ffSdougm { 1699687915e9Sdougm sa_group_t group = NULL; 1700549ec3ffSdougm 17013b61b335Sdougm /* 17023b61b335Sdougm * If we don't have a handle, we can only do syntax check. We 17033b61b335Sdougm * can't check against other shares so we assume OK and will 17043b61b335Sdougm * catch the problem only when we actually try to apply it. 17053b61b335Sdougm */ 1706687915e9Sdougm if (handle == NULL) 17073b61b335Sdougm return (SA_OK); 1708687915e9Sdougm 1709687915e9Sdougm if (skipshare != NULL) { 1710549ec3ffSdougm group = sa_get_parent_group(skipshare); 1711549ec3ffSdougm if (group == NULL) 1712549ec3ffSdougm return (SA_NO_SUCH_GROUP); 1713687915e9Sdougm } 1714549ec3ffSdougm 1715549ec3ffSdougm for (group = sa_get_group(handle, NULL); group != NULL; 1716549ec3ffSdougm group = sa_get_next_group(group)) { 1717546405c3Sdougm /* Walk any ZFS subgroups as well as all standard groups */ 1718546405c3Sdougm if (sa_group_is_zfs(group)) { 1719546405c3Sdougm sa_group_t subgroup; 1720546405c3Sdougm for (subgroup = sa_get_sub_group(group); 1721546405c3Sdougm subgroup != NULL; 1722546405c3Sdougm subgroup = sa_get_next_group(subgroup)) { 1723546405c3Sdougm if (check_public(subgroup, skipshare)) 1724546405c3Sdougm return (B_TRUE); 1725546405c3Sdougm } 1726546405c3Sdougm } else { 1727546405c3Sdougm if (check_public(group, skipshare)) 1728546405c3Sdougm return (B_TRUE); 1729549ec3ffSdougm } 1730549ec3ffSdougm } 1731546405c3Sdougm return (B_FALSE); 1732549ec3ffSdougm } 1733549ec3ffSdougm 1734549ec3ffSdougm /* 1735549ec3ffSdougm * sa_enable_share at the protocol level, enable_share must tell the 1736549ec3ffSdougm * implementation that it is to enable the share. This entails 1737549ec3ffSdougm * converting the path and options into the appropriate ioctl 1738549ec3ffSdougm * calls. It is assumed that all error checking of paths, etc. were 1739549ec3ffSdougm * done earlier. 1740549ec3ffSdougm */ 1741549ec3ffSdougm static int 1742549ec3ffSdougm nfs_enable_share(sa_share_t share) 1743549ec3ffSdougm { 1744549ec3ffSdougm struct exportdata export; 1745549ec3ffSdougm sa_optionset_t secoptlist; 1746549ec3ffSdougm struct secinfo *sp; 1747549ec3ffSdougm int num_secinfo; 1748549ec3ffSdougm sa_optionset_t opt; 1749549ec3ffSdougm sa_security_t sec; 1750549ec3ffSdougm sa_property_t prop; 1751549ec3ffSdougm char *path; 1752549ec3ffSdougm int err = SA_OK; 1753546405c3Sdougm int i; 1754ecd6cf80Smarks int iszfs; 1755687915e9Sdougm sa_handle_t handle; 1756549ec3ffSdougm 1757549ec3ffSdougm /* Don't drop core if the NFS module isn't loaded. */ 1758549ec3ffSdougm (void) signal(SIGSYS, SIG_IGN); 1759549ec3ffSdougm 1760549ec3ffSdougm /* get the path since it is important in several places */ 1761549ec3ffSdougm path = sa_get_share_attr(share, "path"); 1762549ec3ffSdougm if (path == NULL) 1763549ec3ffSdougm return (SA_NO_SUCH_PATH); 1764549ec3ffSdougm 1765ecd6cf80Smarks iszfs = sa_path_is_zfs(path); 1766549ec3ffSdougm /* 1767549ec3ffSdougm * find the optionsets and security sets. There may not be 1768549ec3ffSdougm * any or there could be one or two for each of optionset and 1769549ec3ffSdougm * security may have multiple, one per security type per 1770549ec3ffSdougm * protocol type. 1771549ec3ffSdougm */ 1772549ec3ffSdougm opt = sa_get_derived_optionset(share, "nfs", 1); 1773549ec3ffSdougm secoptlist = (sa_optionset_t)sa_get_all_security_types(share, "nfs", 1); 1774549ec3ffSdougm if (secoptlist != NULL) 1775549ec3ffSdougm num_secinfo = MAX(1, count_security(secoptlist)); 1776549ec3ffSdougm else 1777549ec3ffSdougm num_secinfo = 1; 1778549ec3ffSdougm 1779549ec3ffSdougm /* 1780549ec3ffSdougm * walk through the options and fill in the structure 1781549ec3ffSdougm * appropriately. 1782549ec3ffSdougm */ 1783549ec3ffSdougm 1784549ec3ffSdougm (void) memset(&export, '\0', sizeof (export)); 1785549ec3ffSdougm 1786549ec3ffSdougm /* 1787549ec3ffSdougm * do non-security options first since there is only one after 1788549ec3ffSdougm * the derived group is constructed. 1789549ec3ffSdougm */ 1790549ec3ffSdougm export.ex_version = EX_CURRENT_VERSION; 1791549ec3ffSdougm export.ex_anon = UID_NOBODY; /* this is our default value */ 1792549ec3ffSdougm export.ex_index = NULL; 1793549ec3ffSdougm export.ex_path = path; 1794549ec3ffSdougm export.ex_pathlen = strlen(path) + 1; 1795549ec3ffSdougm 1796549ec3ffSdougm if (opt != NULL) 1797549ec3ffSdougm err = fill_export_from_optionset(&export, opt); 1798549ec3ffSdougm 1799549ec3ffSdougm /* 1800549ec3ffSdougm * check to see if "public" is set. If it is, then make sure 1801549ec3ffSdougm * no other share has it set. If it is already used, fail. 1802549ec3ffSdougm */ 1803549ec3ffSdougm 1804687915e9Sdougm handle = sa_find_group_handle((sa_group_t)share); 1805687915e9Sdougm if (export.ex_flags & EX_PUBLIC && public_exists(handle, share)) { 1806549ec3ffSdougm (void) printf(dgettext(TEXT_DOMAIN, 1807549ec3ffSdougm "NFS: Cannot share more than one file " 1808549ec3ffSdougm "system with 'public' property\n")); 1809549ec3ffSdougm err = SA_NOT_ALLOWED; 1810549ec3ffSdougm goto out; 1811549ec3ffSdougm } 1812549ec3ffSdougm 1813546405c3Sdougm sp = calloc(num_secinfo, sizeof (struct secinfo)); 1814549ec3ffSdougm if (sp == NULL) { 1815549ec3ffSdougm err = SA_NO_MEMORY; 1816546405c3Sdougm (void) printf(dgettext(TEXT_DOMAIN, 1817546405c3Sdougm "NFS: NFS: no memory for security\n")); 1818546405c3Sdougm goto out; 1819546405c3Sdougm } 1820549ec3ffSdougm export.ex_secinfo = sp; 1821549ec3ffSdougm /* get default secinfo */ 1822549ec3ffSdougm export.ex_seccnt = num_secinfo; 1823549ec3ffSdougm /* 1824549ec3ffSdougm * since we must have one security option defined, we 1825549ec3ffSdougm * init to the default and then override as we find 1826549ec3ffSdougm * defined security options. This handles the case 1827549ec3ffSdougm * where we have no defined options but we need to set 1828549ec3ffSdougm * up one. 1829549ec3ffSdougm */ 1830549ec3ffSdougm sp[0].s_window = DEF_WIN; 1831549ec3ffSdougm sp[0].s_rootnames = NULL; 1832549ec3ffSdougm /* setup a default in case no properties defined */ 1833549ec3ffSdougm if (nfs_getseconfig_default(&sp[0].s_secinfo)) { 1834549ec3ffSdougm (void) printf(dgettext(TEXT_DOMAIN, 1835549ec3ffSdougm "NFS: nfs_getseconfig_default: failed to " 1836549ec3ffSdougm "get default security mode\n")); 1837549ec3ffSdougm err = SA_CONFIG_ERR; 1838549ec3ffSdougm } 1839549ec3ffSdougm if (secoptlist != NULL) { 1840549ec3ffSdougm for (i = 0, prop = sa_get_property(secoptlist, NULL); 1841549ec3ffSdougm prop != NULL && i < num_secinfo; 1842549ec3ffSdougm prop = sa_get_next_property(prop), i++) { 1843549ec3ffSdougm char *sectype; 1844549ec3ffSdougm sectype = sa_get_property_attr(prop, "type"); 1845a3351425Sdougm /* 1846a3351425Sdougm * if sectype is NULL, we probably 1847a3351425Sdougm * have a memory problem and can't get 1848a3351425Sdougm * the correct values. Rather than 1849a3351425Sdougm * exporting with incorrect security, 1850a3351425Sdougm * don't share it. 1851a3351425Sdougm */ 1852a3351425Sdougm if (sectype == NULL) { 1853a3351425Sdougm err = SA_NO_MEMORY; 1854a3351425Sdougm (void) printf(dgettext(TEXT_DOMAIN, 1855a3351425Sdougm "NFS: Cannot share %s: " 1856a3351425Sdougm "no memory\n"), path); 1857a3351425Sdougm goto out; 1858a3351425Sdougm } 1859a3351425Sdougm sec = (sa_security_t)sa_get_derived_security( 1860a3351425Sdougm share, sectype, "nfs", 1); 1861549ec3ffSdougm sp[i].s_window = DEF_WIN; 1862549ec3ffSdougm sp[i].s_rootcnt = 0; 1863549ec3ffSdougm sp[i].s_rootnames = NULL; 1864549ec3ffSdougm (void) fill_security_from_secopts(&sp[i], sec); 1865549ec3ffSdougm if (sec != NULL) 1866549ec3ffSdougm sa_free_derived_security(sec); 1867549ec3ffSdougm if (sectype != NULL) 1868549ec3ffSdougm sa_free_attr_string(sectype); 1869549ec3ffSdougm } 1870549ec3ffSdougm } 1871549ec3ffSdougm /* 1872549ec3ffSdougm * when we get here, we can do the exportfs system call and 1873549ec3ffSdougm * initiate thinsg. We probably want to enable the nfs.server 1874549ec3ffSdougm * service first if it isn't running within SMF. 1875549ec3ffSdougm */ 1876549ec3ffSdougm /* check nfs.server status and start if needed */ 1877549ec3ffSdougm /* now add the share to the internal tables */ 1878549ec3ffSdougm printarg(path, &export); 1879549ec3ffSdougm /* 1880549ec3ffSdougm * call the exportfs system call which is implemented 1881549ec3ffSdougm * via the nfssys() call as the EXPORTFS subfunction. 1882549ec3ffSdougm */ 1883ecd6cf80Smarks if (iszfs) { 1884ecd6cf80Smarks struct exportfs_args ea; 1885ecd6cf80Smarks share_t sh; 1886ecd6cf80Smarks char *str; 1887ecd6cf80Smarks priv_set_t *priv_effective; 1888ecd6cf80Smarks int privileged; 1889ecd6cf80Smarks 1890ecd6cf80Smarks /* 1891ecd6cf80Smarks * If we aren't a privileged user 1892ecd6cf80Smarks * and NFS server service isn't running 1893ecd6cf80Smarks * then print out an error message 1894ecd6cf80Smarks * and return EPERM 1895ecd6cf80Smarks */ 1896ecd6cf80Smarks 1897ecd6cf80Smarks priv_effective = priv_allocset(); 1898ecd6cf80Smarks (void) getppriv(PRIV_EFFECTIVE, priv_effective); 1899ecd6cf80Smarks 1900ecd6cf80Smarks privileged = (priv_isfullset(priv_effective) == B_TRUE); 1901ecd6cf80Smarks priv_freeset(priv_effective); 1902ecd6cf80Smarks 1903ecd6cf80Smarks if (!privileged && 1904ecd6cf80Smarks (str = smf_get_state(NFS_SERVER_SVC)) != NULL) { 1905ecd6cf80Smarks err = 0; 1906ecd6cf80Smarks if (strcmp(str, SCF_STATE_STRING_ONLINE) != 0) { 1907ecd6cf80Smarks (void) printf(dgettext(TEXT_DOMAIN, 1908ecd6cf80Smarks "NFS: Cannot share remote " 1909ecd6cf80Smarks "filesystem: %s\n"), path); 1910ecd6cf80Smarks (void) printf(dgettext(TEXT_DOMAIN, 1911ecd6cf80Smarks "NFS: Service needs to be enabled " 1912ecd6cf80Smarks "by a privileged user\n")); 1913ecd6cf80Smarks err = SA_SYSTEM_ERR; 1914ecd6cf80Smarks errno = EPERM; 1915ecd6cf80Smarks } 1916ecd6cf80Smarks free(str); 1917ecd6cf80Smarks } 1918ecd6cf80Smarks 1919ecd6cf80Smarks if (err == 0) { 1920ecd6cf80Smarks ea.dname = path; 1921ecd6cf80Smarks ea.uex = &export; 1922ecd6cf80Smarks 19235ad42b1bSSurya Prakki (void) sa_sharetab_fill_zfs(share, &sh, "nfs"); 1924743a77edSAlan Wright err = sa_share_zfs(share, NULL, path, &sh, 1925da6c28aaSamw &ea, ZFS_SHARE_NFS); 1926a63214d6SBill Krier if (err != SA_OK) { 1927a63214d6SBill Krier errno = err; 1928a63214d6SBill Krier err = -1; 1929a63214d6SBill Krier } 1930ecd6cf80Smarks sa_emptyshare(&sh); 1931ecd6cf80Smarks } 1932ecd6cf80Smarks } else { 1933ecd6cf80Smarks err = exportfs(path, &export); 1934ecd6cf80Smarks } 1935ecd6cf80Smarks 1936ecd6cf80Smarks if (err < 0) { 1937549ec3ffSdougm err = SA_SYSTEM_ERR; 1938549ec3ffSdougm switch (errno) { 1939549ec3ffSdougm case EREMOTE: 1940549ec3ffSdougm (void) printf(dgettext(TEXT_DOMAIN, 1941ecd6cf80Smarks "NFS: Cannot share filesystems " 1942ecd6cf80Smarks "in non-global zones: %s\n"), path); 1943ecd6cf80Smarks err = SA_NOT_SUPPORTED; 1944549ec3ffSdougm break; 1945549ec3ffSdougm case EPERM: 1946549ec3ffSdougm if (getzoneid() != GLOBAL_ZONEID) { 1947549ec3ffSdougm (void) printf(dgettext(TEXT_DOMAIN, 1948549ec3ffSdougm "NFS: Cannot share file systems " 1949549ec3ffSdougm "in non-global zones: %s\n"), path); 1950549ec3ffSdougm err = SA_NOT_SUPPORTED; 1951549ec3ffSdougm break; 1952549ec3ffSdougm } 1953549ec3ffSdougm err = SA_NO_PERMISSION; 1954*0616fd7fSPavel Filipensky break; 1955*0616fd7fSPavel Filipensky case EEXIST: 1956*0616fd7fSPavel Filipensky err = SA_SHARE_EXISTS; 1957*0616fd7fSPavel Filipensky break; 1958549ec3ffSdougm default: 1959549ec3ffSdougm break; 1960549ec3ffSdougm } 1961549ec3ffSdougm } else { 1962549ec3ffSdougm /* update sharetab with an add/modify */ 1963ecd6cf80Smarks if (!iszfs) { 1964549ec3ffSdougm (void) sa_update_sharetab(share, "nfs"); 1965549ec3ffSdougm } 1966ecd6cf80Smarks } 1967549ec3ffSdougm 1968549ec3ffSdougm if (err == SA_OK) { 1969549ec3ffSdougm /* 1970549ec3ffSdougm * enable services as needed. This should probably be 1971549ec3ffSdougm * done elsewhere in order to minimize the calls to 1972549ec3ffSdougm * check services. 1973549ec3ffSdougm */ 1974549ec3ffSdougm /* 1975549ec3ffSdougm * check to see if logging and other services need to 1976549ec3ffSdougm * be triggered, but only if there wasn't an 1977549ec3ffSdougm * error. This is probably where sharetab should be 1978549ec3ffSdougm * updated with the NFS specific entry. 1979549ec3ffSdougm */ 1980549ec3ffSdougm if (export.ex_flags & EX_LOG) { 1981549ec3ffSdougm /* enable logging */ 1982549ec3ffSdougm if (nfslogtab_add(path, export.ex_log_buffer, 1983549ec3ffSdougm export.ex_tag) != 0) { 1984a3351425Sdougm (void) fprintf(stderr, dgettext(TEXT_DOMAIN, 1985549ec3ffSdougm "Could not enable logging for %s\n"), 1986549ec3ffSdougm path); 1987549ec3ffSdougm } 1988549ec3ffSdougm _check_services(service_list_logging); 1989549ec3ffSdougm } else { 1990549ec3ffSdougm /* 1991549ec3ffSdougm * don't have logging so remove it from file. It might 1992549ec3ffSdougm * not be thre, but that doesn't matter. 1993549ec3ffSdougm */ 1994549ec3ffSdougm (void) nfslogtab_deactivate(path); 1995549ec3ffSdougm _check_services(service_list_default); 1996549ec3ffSdougm } 1997549ec3ffSdougm } 1998549ec3ffSdougm 1999549ec3ffSdougm out: 2000549ec3ffSdougm if (path != NULL) 2001549ec3ffSdougm free(path); 2002549ec3ffSdougm 2003549ec3ffSdougm cleanup_export(&export); 2004549ec3ffSdougm if (opt != NULL) 2005549ec3ffSdougm sa_free_derived_optionset(opt); 2006549ec3ffSdougm if (secoptlist != NULL) 2007549ec3ffSdougm (void) sa_destroy_optionset(secoptlist); 2008549ec3ffSdougm return (err); 2009549ec3ffSdougm } 2010549ec3ffSdougm 2011549ec3ffSdougm /* 20128e314a44Sdougm * nfs_disable_share(share, path) 2013549ec3ffSdougm * 20148e314a44Sdougm * Unshare the specified share. Note that "path" is the same path as 20158e314a44Sdougm * what is in the "share" object. It is passed in to avoid an 20168e314a44Sdougm * additional lookup. A missing "path" value makes this a no-op 20178e314a44Sdougm * function. 2018549ec3ffSdougm */ 2019549ec3ffSdougm static int 2020ecd6cf80Smarks nfs_disable_share(sa_share_t share, char *path) 2021549ec3ffSdougm { 2022549ec3ffSdougm int err; 2023549ec3ffSdougm int ret = SA_OK; 2024ecd6cf80Smarks int iszfs; 20258e314a44Sdougm sa_group_t parent; 20265b6e0c46Sdougm sa_handle_t handle; 2027549ec3ffSdougm 20288e314a44Sdougm if (path == NULL) 20298e314a44Sdougm return (ret); 2030ecd6cf80Smarks 20318e314a44Sdougm /* 20328e314a44Sdougm * If the share is in a ZFS group we need to handle it 20338e314a44Sdougm * differently. Just being on a ZFS file system isn't 20348e314a44Sdougm * enough since we may be in a legacy share case. 20358e314a44Sdougm */ 20368e314a44Sdougm parent = sa_get_parent_group(share); 20378e314a44Sdougm iszfs = sa_group_is_zfs(parent); 2038ecd6cf80Smarks if (iszfs) { 2039ecd6cf80Smarks struct exportfs_args ea; 2040ecd6cf80Smarks share_t sh = { 0 }; 2041ecd6cf80Smarks ea.dname = path; 2042ecd6cf80Smarks ea.uex = NULL; 2043ecd6cf80Smarks sh.sh_path = path; 2044ecd6cf80Smarks sh.sh_fstype = "nfs"; 2045ecd6cf80Smarks 2046743a77edSAlan Wright err = sa_share_zfs(share, NULL, path, &sh, 2047da6c28aaSamw &ea, ZFS_UNSHARE_NFS); 2048a63214d6SBill Krier if (err != SA_OK) { 2049a63214d6SBill Krier errno = err; 2050a63214d6SBill Krier err = -1; 2051a63214d6SBill Krier } 20528e314a44Sdougm } else { 2053ecd6cf80Smarks err = exportfs(path, NULL); 20548e314a44Sdougm } 2055549ec3ffSdougm if (err < 0) { 2056a3351425Sdougm /* 2057ecd6cf80Smarks * TBD: only an error in some 2058ecd6cf80Smarks * cases - need better analysis 2059a3351425Sdougm */ 2060549ec3ffSdougm switch (errno) { 2061549ec3ffSdougm case EPERM: 2062549ec3ffSdougm case EACCES: 2063549ec3ffSdougm ret = SA_NO_PERMISSION; 2064ecd6cf80Smarks if (getzoneid() != GLOBAL_ZONEID) { 2065549ec3ffSdougm ret = SA_NOT_SUPPORTED; 2066ecd6cf80Smarks } 2067549ec3ffSdougm break; 2068549ec3ffSdougm case EINVAL: 2069549ec3ffSdougm case ENOENT: 2070549ec3ffSdougm ret = SA_NO_SUCH_PATH; 2071549ec3ffSdougm break; 2072549ec3ffSdougm default: 2073549ec3ffSdougm ret = SA_SYSTEM_ERR; 2074549ec3ffSdougm break; 2075549ec3ffSdougm } 2076549ec3ffSdougm } 2077549ec3ffSdougm if (ret == SA_OK || ret == SA_NO_SUCH_PATH) { 20785b6e0c46Sdougm handle = sa_find_group_handle((sa_group_t)share); 2079ecd6cf80Smarks if (!iszfs) 20805b6e0c46Sdougm (void) sa_delete_sharetab(handle, path, "nfs"); 2081549ec3ffSdougm /* just in case it was logged */ 2082ecd6cf80Smarks (void) nfslogtab_deactivate(path); 2083549ec3ffSdougm } 2084549ec3ffSdougm return (ret); 2085549ec3ffSdougm } 2086549ec3ffSdougm 2087549ec3ffSdougm /* 2088b89a8333Snatalie li - Sun Microsystems - Irvine United States * check_rorwnone(v1, v2, v3) 2089b89a8333Snatalie li - Sun Microsystems - Irvine United States * 2090b89a8333Snatalie li - Sun Microsystems - Irvine United States * check ro vs rw vs none values. Over time this may get beefed up. 2091b89a8333Snatalie li - Sun Microsystems - Irvine United States * for now it just does simple checks. v1 is never NULL but v2 or v3 2092b89a8333Snatalie li - Sun Microsystems - Irvine United States * could be. 2093549ec3ffSdougm */ 2094549ec3ffSdougm 2095549ec3ffSdougm static int 2096b89a8333Snatalie li - Sun Microsystems - Irvine United States check_rorwnone(char *v1, char *v2, char *v3) 2097549ec3ffSdougm { 2098549ec3ffSdougm int ret = SA_OK; 2099b89a8333Snatalie li - Sun Microsystems - Irvine United States if (v2 != NULL && strcmp(v1, v2) == 0) 2100549ec3ffSdougm ret = SA_VALUE_CONFLICT; 2101b89a8333Snatalie li - Sun Microsystems - Irvine United States else if (v3 != NULL && strcmp(v1, v3) == 0) 2102b89a8333Snatalie li - Sun Microsystems - Irvine United States ret = SA_VALUE_CONFLICT; 2103b89a8333Snatalie li - Sun Microsystems - Irvine United States 2104549ec3ffSdougm return (ret); 2105549ec3ffSdougm } 2106549ec3ffSdougm 2107549ec3ffSdougm /* 2108687915e9Sdougm * nfs_validate_property(handle, property, parent) 2109549ec3ffSdougm * 2110549ec3ffSdougm * Check that the property has a legitimate value for its type. 2111549ec3ffSdougm */ 2112549ec3ffSdougm 2113549ec3ffSdougm static int 2114687915e9Sdougm nfs_validate_property(sa_handle_t handle, sa_property_t property, 2115687915e9Sdougm sa_optionset_t parent) 2116549ec3ffSdougm { 2117549ec3ffSdougm int ret = SA_OK; 2118549ec3ffSdougm char *propname; 2119b89a8333Snatalie li - Sun Microsystems - Irvine United States char *other1; 2120b89a8333Snatalie li - Sun Microsystems - Irvine United States char *other2; 2121549ec3ffSdougm int optindex; 2122549ec3ffSdougm nfsl_config_t *configlist; 2123549ec3ffSdougm sa_group_t parent_group; 2124549ec3ffSdougm char *value; 2125549ec3ffSdougm 2126549ec3ffSdougm propname = sa_get_property_attr(property, "type"); 2127549ec3ffSdougm 2128549ec3ffSdougm if ((optindex = findopt(propname)) < 0) 2129549ec3ffSdougm ret = SA_NO_SUCH_PROP; 2130549ec3ffSdougm 2131549ec3ffSdougm /* need to validate value range here as well */ 2132549ec3ffSdougm 2133549ec3ffSdougm if (ret == SA_OK) { 2134549ec3ffSdougm parent_group = sa_get_parent_group((sa_share_t)parent); 2135687915e9Sdougm if (optdefs[optindex].share && parent_group != NULL && 2136687915e9Sdougm !sa_is_share(parent_group)) 2137549ec3ffSdougm ret = SA_PROP_SHARE_ONLY; 2138549ec3ffSdougm } 2139549ec3ffSdougm if (ret == SA_OK) { 2140687915e9Sdougm if (optdefs[optindex].index == OPT_PUBLIC) { 2141687915e9Sdougm /* 2142687915e9Sdougm * Public is special in that only one instance can 2143687915e9Sdougm * be in the repository at the same time. 2144687915e9Sdougm */ 2145687915e9Sdougm if (public_exists(handle, parent_group)) { 2146687915e9Sdougm sa_free_attr_string(propname); 2147687915e9Sdougm return (SA_VALUE_CONFLICT); 2148687915e9Sdougm } 2149687915e9Sdougm } 2150549ec3ffSdougm value = sa_get_property_attr(property, "value"); 2151549ec3ffSdougm if (value != NULL) { 2152549ec3ffSdougm /* first basic type checking */ 2153549ec3ffSdougm switch (optdefs[optindex].type) { 2154549ec3ffSdougm case OPT_TYPE_NUMBER: 2155549ec3ffSdougm /* check that the value is all digits */ 2156549ec3ffSdougm if (!is_a_number(value)) 2157549ec3ffSdougm ret = SA_BAD_VALUE; 2158549ec3ffSdougm break; 2159549ec3ffSdougm case OPT_TYPE_BOOLEAN: 2160549ec3ffSdougm if (strlen(value) == 0 || 2161549ec3ffSdougm strcasecmp(value, "true") == 0 || 2162549ec3ffSdougm strcmp(value, "1") == 0 || 2163549ec3ffSdougm strcasecmp(value, "false") == 0 || 2164549ec3ffSdougm strcmp(value, "0") == 0) { 2165549ec3ffSdougm ret = SA_OK; 2166549ec3ffSdougm } else { 2167549ec3ffSdougm ret = SA_BAD_VALUE; 2168549ec3ffSdougm } 2169549ec3ffSdougm break; 2170549ec3ffSdougm case OPT_TYPE_USER: 2171549ec3ffSdougm if (!is_a_number(value)) { 2172549ec3ffSdougm struct passwd *pw; 2173a3351425Sdougm /* 2174a3351425Sdougm * in this case it would have to be a 2175a3351425Sdougm * user name 2176a3351425Sdougm */ 2177549ec3ffSdougm pw = getpwnam(value); 2178549ec3ffSdougm if (pw == NULL) 2179549ec3ffSdougm ret = SA_BAD_VALUE; 2180549ec3ffSdougm endpwent(); 2181549ec3ffSdougm } else { 2182549ec3ffSdougm uint64_t intval; 2183549ec3ffSdougm intval = strtoull(value, NULL, 0); 2184549ec3ffSdougm if (intval > UID_MAX && intval != ~0) 2185549ec3ffSdougm ret = SA_BAD_VALUE; 2186549ec3ffSdougm } 2187549ec3ffSdougm break; 2188549ec3ffSdougm case OPT_TYPE_FILE: 2189549ec3ffSdougm if (strcmp(value, "..") == 0 || 2190549ec3ffSdougm strchr(value, '/') != NULL) { 2191549ec3ffSdougm ret = SA_BAD_VALUE; 2192549ec3ffSdougm } 2193549ec3ffSdougm break; 2194b89a8333Snatalie li - Sun Microsystems - Irvine United States case OPT_TYPE_ACCLIST: { 2195b89a8333Snatalie li - Sun Microsystems - Irvine United States sa_property_t oprop1; 2196b89a8333Snatalie li - Sun Microsystems - Irvine United States sa_property_t oprop2; 2197b89a8333Snatalie li - Sun Microsystems - Irvine United States char *ovalue1 = NULL; 2198b89a8333Snatalie li - Sun Microsystems - Irvine United States char *ovalue2 = NULL; 2199b89a8333Snatalie li - Sun Microsystems - Irvine United States 2200b89a8333Snatalie li - Sun Microsystems - Irvine United States if (parent == NULL) 2201b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 2202549ec3ffSdougm /* 2203549ec3ffSdougm * access list handling. Should eventually 2204549ec3ffSdougm * validate that all the values make sense. 2205549ec3ffSdougm * Also, ro and rw may have cross value 2206549ec3ffSdougm * conflicts. 2207549ec3ffSdougm */ 2208b89a8333Snatalie li - Sun Microsystems - Irvine United States if (strcmp(propname, SHOPT_RO) == 0) { 2209b89a8333Snatalie li - Sun Microsystems - Irvine United States other1 = SHOPT_RW; 2210b89a8333Snatalie li - Sun Microsystems - Irvine United States other2 = SHOPT_NONE; 2211b89a8333Snatalie li - Sun Microsystems - Irvine United States } else if (strcmp(propname, SHOPT_RW) == 0) { 2212b89a8333Snatalie li - Sun Microsystems - Irvine United States other1 = SHOPT_RO; 2213b89a8333Snatalie li - Sun Microsystems - Irvine United States other2 = SHOPT_NONE; 2214b89a8333Snatalie li - Sun Microsystems - Irvine United States } else if (strcmp(propname, SHOPT_NONE) == 0) { 2215b89a8333Snatalie li - Sun Microsystems - Irvine United States other1 = SHOPT_RO; 2216b89a8333Snatalie li - Sun Microsystems - Irvine United States other2 = SHOPT_RW; 2217b89a8333Snatalie li - Sun Microsystems - Irvine United States } else { 2218b89a8333Snatalie li - Sun Microsystems - Irvine United States other1 = NULL; 2219b89a8333Snatalie li - Sun Microsystems - Irvine United States other2 = NULL; 2220549ec3ffSdougm } 2221b89a8333Snatalie li - Sun Microsystems - Irvine United States if (other1 == NULL && other2 == NULL) 2222549ec3ffSdougm break; 2223b89a8333Snatalie li - Sun Microsystems - Irvine United States 2224b89a8333Snatalie li - Sun Microsystems - Irvine United States /* compare rw(ro) with ro(rw) */ 2225b89a8333Snatalie li - Sun Microsystems - Irvine United States 2226b89a8333Snatalie li - Sun Microsystems - Irvine United States oprop1 = sa_get_property(parent, other1); 2227b89a8333Snatalie li - Sun Microsystems - Irvine United States oprop2 = sa_get_property(parent, other2); 2228b89a8333Snatalie li - Sun Microsystems - Irvine United States if (oprop1 == NULL && oprop2 == NULL) 2229b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 2230b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 2231b89a8333Snatalie li - Sun Microsystems - Irvine United States * Only potential confusion if other1 2232b89a8333Snatalie li - Sun Microsystems - Irvine United States * or other2 exists. Check the values 2233b89a8333Snatalie li - Sun Microsystems - Irvine United States * and run the check if there is a 2234b89a8333Snatalie li - Sun Microsystems - Irvine United States * value other than the one we are 2235b89a8333Snatalie li - Sun Microsystems - Irvine United States * explicitly looking at. 2236b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 2237b89a8333Snatalie li - Sun Microsystems - Irvine United States ovalue1 = sa_get_property_attr(oprop1, "value"); 2238b89a8333Snatalie li - Sun Microsystems - Irvine United States ovalue2 = sa_get_property_attr(oprop2, "value"); 2239b89a8333Snatalie li - Sun Microsystems - Irvine United States if (ovalue1 != NULL || ovalue2 != NULL) 2240b89a8333Snatalie li - Sun Microsystems - Irvine United States ret = check_rorwnone(value, ovalue1, 2241b89a8333Snatalie li - Sun Microsystems - Irvine United States ovalue2); 2242b89a8333Snatalie li - Sun Microsystems - Irvine United States 2243b89a8333Snatalie li - Sun Microsystems - Irvine United States if (ovalue1 != NULL) 2244b89a8333Snatalie li - Sun Microsystems - Irvine United States sa_free_attr_string(ovalue1); 2245b89a8333Snatalie li - Sun Microsystems - Irvine United States if (ovalue2 != NULL) 2246b89a8333Snatalie li - Sun Microsystems - Irvine United States sa_free_attr_string(ovalue2); 2247b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 2248b89a8333Snatalie li - Sun Microsystems - Irvine United States } 2249549ec3ffSdougm case OPT_TYPE_LOGTAG: 2250549ec3ffSdougm if (nfsl_getconfig_list(&configlist) == 0) { 2251549ec3ffSdougm int error; 2252a3351425Sdougm if (value == NULL || 2253a3351425Sdougm strlen(value) == 0) { 2254549ec3ffSdougm if (value != NULL) 2255a3351425Sdougm sa_free_attr_string( 2256a3351425Sdougm value); 2257549ec3ffSdougm value = strdup("global"); 2258549ec3ffSdougm } 2259a3351425Sdougm if (value != NULL && 2260a3351425Sdougm nfsl_findconfig(configlist, value, 2261a3351425Sdougm &error) == NULL) { 2262549ec3ffSdougm ret = SA_BAD_VALUE; 2263a3351425Sdougm } 2264aed5d200Sdougm /* Must always free when done */ 2265aed5d200Sdougm nfsl_freeconfig_list(&configlist); 2266549ec3ffSdougm } else { 2267549ec3ffSdougm ret = SA_CONFIG_ERR; 2268549ec3ffSdougm } 2269549ec3ffSdougm break; 2270549ec3ffSdougm case OPT_TYPE_STRING: 2271549ec3ffSdougm /* whatever is here should be ok */ 2272549ec3ffSdougm break; 2273549ec3ffSdougm case OPT_TYPE_SECURITY: 2274549ec3ffSdougm /* 2275549ec3ffSdougm * The "sec" property isn't used in the 2276549ec3ffSdougm * non-legacy parts of sharemgr. We need to 2277549ec3ffSdougm * reject it here. For legacy, it is pulled 2278549ec3ffSdougm * out well before we get here. 2279549ec3ffSdougm */ 2280549ec3ffSdougm ret = SA_NO_SUCH_PROP; 2281549ec3ffSdougm break; 2282549ec3ffSdougm default: 2283549ec3ffSdougm break; 2284549ec3ffSdougm } 2285aed5d200Sdougm 2286aed5d200Sdougm if (value != NULL) 2287549ec3ffSdougm sa_free_attr_string(value); 2288aed5d200Sdougm 2289549ec3ffSdougm if (ret == SA_OK && optdefs[optindex].check != NULL) { 2290549ec3ffSdougm /* do the property specific check */ 2291687915e9Sdougm ret = optdefs[optindex].check(handle, property); 2292549ec3ffSdougm } 2293549ec3ffSdougm } 2294549ec3ffSdougm } 2295549ec3ffSdougm 2296549ec3ffSdougm if (propname != NULL) 2297549ec3ffSdougm sa_free_attr_string(propname); 2298549ec3ffSdougm return (ret); 2299549ec3ffSdougm } 2300549ec3ffSdougm 2301549ec3ffSdougm /* 2302549ec3ffSdougm * Protocol management functions 2303549ec3ffSdougm * 2304549ec3ffSdougm * Properties defined in the default files are defined in 2305549ec3ffSdougm * proto_option_defs for parsing and validation. If "other" and 2306549ec3ffSdougm * "compare" are set, then the value for this property should be 2307549ec3ffSdougm * compared against the property specified in "other" using the 2308549ec3ffSdougm * "compare" check (either <= or >=) in order to ensure that the 2309549ec3ffSdougm * values are in the correct range. E.g. setting server_versmin 2310549ec3ffSdougm * higher than server_versmax should not be allowed. 2311549ec3ffSdougm */ 2312549ec3ffSdougm 2313549ec3ffSdougm struct proto_option_defs { 2314549ec3ffSdougm char *tag; 2315549ec3ffSdougm char *name; /* display name -- remove protocol identifier */ 2316549ec3ffSdougm int index; 2317549ec3ffSdougm int type; 2318549ec3ffSdougm union { 2319549ec3ffSdougm int intval; 2320549ec3ffSdougm char *string; 2321549ec3ffSdougm } defvalue; 2322549ec3ffSdougm uint32_t svcs; 2323549ec3ffSdougm int32_t minval; 2324549ec3ffSdougm int32_t maxval; 2325549ec3ffSdougm char *file; 2326549ec3ffSdougm char *other; 2327549ec3ffSdougm int compare; 2328549ec3ffSdougm #define OPT_CMP_GE 0 2329549ec3ffSdougm #define OPT_CMP_LE 1 2330549ec3ffSdougm int (*check)(char *); 2331549ec3ffSdougm } proto_options[] = { 2332549ec3ffSdougm #define PROTO_OPT_NFSD_SERVERS 0 2333549ec3ffSdougm {"nfsd_servers", 2334549ec3ffSdougm "servers", PROTO_OPT_NFSD_SERVERS, OPT_TYPE_NUMBER, 16, SVC_NFSD, 2335549ec3ffSdougm 1, INT32_MAX, NFSADMIN}, 2336549ec3ffSdougm #define PROTO_OPT_LOCKD_LISTEN_BACKLOG 1 2337549ec3ffSdougm {"lockd_listen_backlog", 2338549ec3ffSdougm "lockd_listen_backlog", PROTO_OPT_LOCKD_LISTEN_BACKLOG, 2339549ec3ffSdougm OPT_TYPE_NUMBER, 32, SVC_LOCKD, 32, INT32_MAX, NFSADMIN}, 2340549ec3ffSdougm #define PROTO_OPT_LOCKD_SERVERS 2 2341549ec3ffSdougm {"lockd_servers", 2342549ec3ffSdougm "lockd_servers", PROTO_OPT_LOCKD_SERVERS, OPT_TYPE_NUMBER, 20, 2343549ec3ffSdougm SVC_LOCKD, 1, INT32_MAX, NFSADMIN}, 2344549ec3ffSdougm #define PROTO_OPT_LOCKD_RETRANSMIT_TIMEOUT 3 2345549ec3ffSdougm {"lockd_retransmit_timeout", 2346549ec3ffSdougm "lockd_retransmit_timeout", PROTO_OPT_LOCKD_RETRANSMIT_TIMEOUT, 2347549ec3ffSdougm OPT_TYPE_NUMBER, 5, SVC_LOCKD, 0, INT32_MAX, NFSADMIN}, 2348549ec3ffSdougm #define PROTO_OPT_GRACE_PERIOD 4 2349549ec3ffSdougm {"grace_period", 2350549ec3ffSdougm "grace_period", PROTO_OPT_GRACE_PERIOD, OPT_TYPE_NUMBER, 90, 2351549ec3ffSdougm SVC_LOCKD, 0, INT32_MAX, NFSADMIN}, 2352549ec3ffSdougm #define PROTO_OPT_NFS_SERVER_VERSMIN 5 2353549ec3ffSdougm {"nfs_server_versmin", 2354549ec3ffSdougm "server_versmin", PROTO_OPT_NFS_SERVER_VERSMIN, OPT_TYPE_NUMBER, 2355549ec3ffSdougm (int)NFS_VERSMIN_DEFAULT, SVC_NFSD|SVC_MOUNTD, NFS_VERSMIN, 2356549ec3ffSdougm NFS_VERSMAX, NFSADMIN, "server_versmax", OPT_CMP_LE}, 2357549ec3ffSdougm #define PROTO_OPT_NFS_SERVER_VERSMAX 6 2358549ec3ffSdougm {"nfs_server_versmax", 2359549ec3ffSdougm "server_versmax", PROTO_OPT_NFS_SERVER_VERSMAX, OPT_TYPE_NUMBER, 2360549ec3ffSdougm (int)NFS_VERSMAX_DEFAULT, SVC_NFSD|SVC_MOUNTD, NFS_VERSMIN, 2361549ec3ffSdougm NFS_VERSMAX, NFSADMIN, "server_versmin", OPT_CMP_GE}, 2362549ec3ffSdougm #define PROTO_OPT_NFS_CLIENT_VERSMIN 7 2363549ec3ffSdougm {"nfs_client_versmin", 2364549ec3ffSdougm "client_versmin", PROTO_OPT_NFS_CLIENT_VERSMIN, OPT_TYPE_NUMBER, 2365549ec3ffSdougm (int)NFS_VERSMIN_DEFAULT, NULL, NFS_VERSMIN, NFS_VERSMAX, 2366549ec3ffSdougm NFSADMIN, "client_versmax", OPT_CMP_LE}, 2367549ec3ffSdougm #define PROTO_OPT_NFS_CLIENT_VERSMAX 8 2368549ec3ffSdougm {"nfs_client_versmax", 2369549ec3ffSdougm "client_versmax", PROTO_OPT_NFS_CLIENT_VERSMAX, OPT_TYPE_NUMBER, 2370549ec3ffSdougm (int)NFS_VERSMAX_DEFAULT, NULL, NFS_VERSMIN, NFS_VERSMAX, 2371549ec3ffSdougm NFSADMIN, "client_versmin", OPT_CMP_GE}, 2372549ec3ffSdougm #define PROTO_OPT_NFS_SERVER_DELEGATION 9 2373549ec3ffSdougm {"nfs_server_delegation", 2374549ec3ffSdougm "server_delegation", PROTO_OPT_NFS_SERVER_DELEGATION, 2375549ec3ffSdougm OPT_TYPE_ONOFF, NFS_SERVER_DELEGATION_DEFAULT, SVC_NFSD, 0, 0, 2376549ec3ffSdougm NFSADMIN}, 2377549ec3ffSdougm #define PROTO_OPT_NFSMAPID_DOMAIN 10 2378549ec3ffSdougm {"nfsmapid_domain", 2379549ec3ffSdougm "nfsmapid_domain", PROTO_OPT_NFSMAPID_DOMAIN, OPT_TYPE_DOMAIN, 2380549ec3ffSdougm NULL, SVC_NFSMAPID, 0, 0, NFSADMIN}, 2381549ec3ffSdougm #define PROTO_OPT_NFSD_MAX_CONNECTIONS 11 2382549ec3ffSdougm {"nfsd_max_connections", 2383549ec3ffSdougm "max_connections", PROTO_OPT_NFSD_MAX_CONNECTIONS, 2384549ec3ffSdougm OPT_TYPE_NUMBER, -1, SVC_NFSD, -1, INT32_MAX, NFSADMIN}, 2385549ec3ffSdougm #define PROTO_OPT_NFSD_PROTOCOL 12 2386549ec3ffSdougm {"nfsd_protocol", 2387549ec3ffSdougm "protocol", PROTO_OPT_NFSD_PROTOCOL, OPT_TYPE_PROTOCOL, 0, 2388549ec3ffSdougm SVC_NFSD, 0, 0, NFSADMIN}, 2389549ec3ffSdougm #define PROTO_OPT_NFSD_LISTEN_BACKLOG 13 2390549ec3ffSdougm {"nfsd_listen_backlog", 2391549ec3ffSdougm "listen_backlog", PROTO_OPT_NFSD_LISTEN_BACKLOG, 2392549ec3ffSdougm OPT_TYPE_NUMBER, 0, 2393549ec3ffSdougm SVC_LOCKD, 0, INT32_MAX, NFSADMIN}, 2394549ec3ffSdougm {NULL} 2395549ec3ffSdougm }; 2396549ec3ffSdougm 2397549ec3ffSdougm /* 2398549ec3ffSdougm * the protoset holds the defined options so we don't have to read 2399549ec3ffSdougm * them multiple times 2400549ec3ffSdougm */ 2401aed5d200Sdougm static sa_protocol_properties_t protoset; 2402549ec3ffSdougm 2403549ec3ffSdougm static int 2404549ec3ffSdougm findprotoopt(char *name, int whichname) 2405549ec3ffSdougm { 2406549ec3ffSdougm int i; 2407549ec3ffSdougm for (i = 0; proto_options[i].tag != NULL; i++) { 2408549ec3ffSdougm if (whichname == 1) { 2409549ec3ffSdougm if (strcasecmp(proto_options[i].name, name) == 0) 2410549ec3ffSdougm return (i); 2411549ec3ffSdougm } else { 2412549ec3ffSdougm if (strcasecmp(proto_options[i].tag, name) == 0) 2413549ec3ffSdougm return (i); 2414549ec3ffSdougm } 2415549ec3ffSdougm } 2416549ec3ffSdougm return (-1); 2417549ec3ffSdougm } 2418549ec3ffSdougm 2419549ec3ffSdougm /* 2420549ec3ffSdougm * fixcaselower(str) 2421549ec3ffSdougm * 2422549ec3ffSdougm * convert a string to lower case (inplace). 2423549ec3ffSdougm */ 2424549ec3ffSdougm 2425549ec3ffSdougm static void 2426549ec3ffSdougm fixcaselower(char *str) 2427549ec3ffSdougm { 2428549ec3ffSdougm while (*str) { 2429549ec3ffSdougm *str = tolower(*str); 2430549ec3ffSdougm str++; 2431549ec3ffSdougm } 2432549ec3ffSdougm } 2433549ec3ffSdougm 2434549ec3ffSdougm /* 2435549ec3ffSdougm * fixcaseupper(str) 2436549ec3ffSdougm * 2437549ec3ffSdougm * convert a string to upper case (inplace). 2438549ec3ffSdougm */ 2439549ec3ffSdougm 2440549ec3ffSdougm static void 2441549ec3ffSdougm fixcaseupper(char *str) 2442549ec3ffSdougm { 2443549ec3ffSdougm while (*str) { 2444549ec3ffSdougm *str = toupper(*str); 2445549ec3ffSdougm str++; 2446549ec3ffSdougm } 2447549ec3ffSdougm } 2448549ec3ffSdougm 2449549ec3ffSdougm /* 2450330ef417Sdougm * skipwhitespace(str) 2451330ef417Sdougm * 2452330ef417Sdougm * Skip leading white space. It is assumed that it is called with a 2453330ef417Sdougm * valid pointer. 2454330ef417Sdougm */ 2455330ef417Sdougm 2456330ef417Sdougm static char * 2457330ef417Sdougm skipwhitespace(char *str) 2458330ef417Sdougm { 2459330ef417Sdougm while (*str && isspace(*str)) 2460330ef417Sdougm str++; 2461330ef417Sdougm 2462330ef417Sdougm return (str); 2463330ef417Sdougm } 2464330ef417Sdougm 2465330ef417Sdougm /* 2466a3351425Sdougm * extractprop() 2467a3351425Sdougm * 2468a3351425Sdougm * Extract the property and value out of the line and create the 2469a3351425Sdougm * property in the optionset. 2470a3351425Sdougm */ 2471e7bab347Sdougm static int 2472a3351425Sdougm extractprop(char *name, char *value) 2473a3351425Sdougm { 2474a3351425Sdougm sa_property_t prop; 2475a3351425Sdougm int index; 2476e7bab347Sdougm int ret = SA_OK; 2477a3351425Sdougm /* 2478a3351425Sdougm * Remove any leading 2479a3351425Sdougm * white space. 2480a3351425Sdougm */ 2481a3351425Sdougm name = skipwhitespace(name); 2482a3351425Sdougm 2483a3351425Sdougm index = findprotoopt(name, 0); 2484a3351425Sdougm if (index >= 0) { 2485a3351425Sdougm fixcaselower(name); 2486a3351425Sdougm prop = sa_create_property(proto_options[index].name, value); 2487a3351425Sdougm if (prop != NULL) 2488e7bab347Sdougm ret = sa_add_protocol_property(protoset, prop); 2489e7bab347Sdougm else 2490e7bab347Sdougm ret = SA_NO_MEMORY; 2491a3351425Sdougm } 2492e7bab347Sdougm return (ret); 2493a3351425Sdougm } 2494a3351425Sdougm 2495a3351425Sdougm /* 2496549ec3ffSdougm * initprotofromdefault() 2497549ec3ffSdougm * 2498917c27c8Sdougm * Read the default file(s) and add the defined values to the 2499549ec3ffSdougm * protoset. Note that default values are known from the built in 2500917c27c8Sdougm * table in case the file doesn't have a definition. Not having the 2501917c27c8Sdougm * /etc/default/nfs file is OK since we have builtin default 2502917c27c8Sdougm * values. The default file will get constructed as needed if values 2503917c27c8Sdougm * are changed from the defaults. 2504549ec3ffSdougm */ 2505549ec3ffSdougm 2506549ec3ffSdougm static int 2507549ec3ffSdougm initprotofromdefault() 2508549ec3ffSdougm { 2509549ec3ffSdougm FILE *nfs; 2510549ec3ffSdougm char buff[BUFSIZ]; 2511549ec3ffSdougm char *name; 2512549ec3ffSdougm char *value; 2513e7bab347Sdougm int ret = SA_OK; 2514549ec3ffSdougm 2515549ec3ffSdougm protoset = sa_create_protocol_properties("nfs"); 2516549ec3ffSdougm 2517549ec3ffSdougm if (protoset != NULL) { 2518549ec3ffSdougm nfs = fopen(NFSADMIN, "r"); 2519549ec3ffSdougm if (nfs != NULL) { 2520e7bab347Sdougm while (ret == SA_OK && 2521e7bab347Sdougm fgets(buff, sizeof (buff), nfs) != NULL) { 2522549ec3ffSdougm switch (buff[0]) { 2523549ec3ffSdougm case '\n': 2524549ec3ffSdougm case '#': 2525549ec3ffSdougm /* skip */ 2526549ec3ffSdougm break; 2527549ec3ffSdougm default: 2528549ec3ffSdougm name = buff; 2529549ec3ffSdougm buff[strlen(buff) - 1] = '\0'; 2530549ec3ffSdougm value = strchr(name, '='); 2531549ec3ffSdougm if (value != NULL) { 2532549ec3ffSdougm *value++ = '\0'; 2533e7bab347Sdougm ret = extractprop(name, value); 2534549ec3ffSdougm } 2535549ec3ffSdougm } 2536549ec3ffSdougm } 2537549ec3ffSdougm (void) fclose(nfs); 2538e7bab347Sdougm } else { 2539917c27c8Sdougm switch (errno) { 2540917c27c8Sdougm case EPERM: 2541917c27c8Sdougm case EACCES: 2542917c27c8Sdougm ret = SA_NO_PERMISSION; 2543917c27c8Sdougm break; 2544917c27c8Sdougm case ENOENT: 2545917c27c8Sdougm break; 2546917c27c8Sdougm default: 2547e7bab347Sdougm ret = SA_SYSTEM_ERR; 2548917c27c8Sdougm break; 2549917c27c8Sdougm } 2550549ec3ffSdougm } 2551e7bab347Sdougm } else { 2552e7bab347Sdougm ret = SA_NO_MEMORY; 2553549ec3ffSdougm } 2554e7bab347Sdougm return (ret); 2555549ec3ffSdougm } 2556549ec3ffSdougm 2557549ec3ffSdougm /* 2558a3351425Sdougm * add_defaults() 2559549ec3ffSdougm * 2560549ec3ffSdougm * Add the default values for any property not defined in the parsing 2561549ec3ffSdougm * of the default files. Values are set according to their defined 2562549ec3ffSdougm * types. 2563549ec3ffSdougm */ 2564549ec3ffSdougm 2565549ec3ffSdougm static void 2566549ec3ffSdougm add_defaults() 2567549ec3ffSdougm { 2568549ec3ffSdougm int i; 2569549ec3ffSdougm char number[MAXDIGITS]; 2570549ec3ffSdougm 2571549ec3ffSdougm for (i = 0; proto_options[i].tag != NULL; i++) { 2572549ec3ffSdougm sa_property_t prop; 2573a3351425Sdougm prop = sa_get_protocol_property(protoset, 2574a3351425Sdougm proto_options[i].name); 2575549ec3ffSdougm if (prop == NULL) { 2576549ec3ffSdougm /* add the default value */ 2577549ec3ffSdougm switch (proto_options[i].type) { 2578549ec3ffSdougm case OPT_TYPE_NUMBER: 2579549ec3ffSdougm (void) snprintf(number, sizeof (number), "%d", 2580549ec3ffSdougm proto_options[i].defvalue.intval); 2581a3351425Sdougm prop = sa_create_property(proto_options[i].name, 2582a3351425Sdougm number); 2583549ec3ffSdougm break; 2584549ec3ffSdougm 2585549ec3ffSdougm case OPT_TYPE_BOOLEAN: 2586549ec3ffSdougm prop = sa_create_property(proto_options[i].name, 2587549ec3ffSdougm proto_options[i].defvalue.intval ? 2588549ec3ffSdougm "true" : "false"); 2589549ec3ffSdougm break; 2590549ec3ffSdougm 2591549ec3ffSdougm case OPT_TYPE_ONOFF: 2592549ec3ffSdougm prop = sa_create_property(proto_options[i].name, 2593549ec3ffSdougm proto_options[i].defvalue.intval ? 2594549ec3ffSdougm "on" : "off"); 2595549ec3ffSdougm break; 2596549ec3ffSdougm 2597549ec3ffSdougm default: 2598549ec3ffSdougm /* treat as strings of zero length */ 2599a3351425Sdougm prop = sa_create_property(proto_options[i].name, 2600a3351425Sdougm ""); 2601549ec3ffSdougm break; 2602549ec3ffSdougm } 2603549ec3ffSdougm if (prop != NULL) 2604549ec3ffSdougm (void) sa_add_protocol_property(protoset, prop); 2605549ec3ffSdougm } 2606549ec3ffSdougm } 2607549ec3ffSdougm } 2608549ec3ffSdougm 2609549ec3ffSdougm static void 2610549ec3ffSdougm free_protoprops() 2611549ec3ffSdougm { 2612aed5d200Sdougm if (protoset != NULL) { 2613549ec3ffSdougm xmlFreeNode(protoset); 2614aed5d200Sdougm protoset = NULL; 2615aed5d200Sdougm } 2616549ec3ffSdougm } 2617549ec3ffSdougm 2618549ec3ffSdougm /* 2619549ec3ffSdougm * nfs_init() 2620549ec3ffSdougm * 2621549ec3ffSdougm * Initialize the NFS plugin. 2622549ec3ffSdougm */ 2623549ec3ffSdougm 2624549ec3ffSdougm static int 2625549ec3ffSdougm nfs_init() 2626549ec3ffSdougm { 2627549ec3ffSdougm int ret = SA_OK; 2628549ec3ffSdougm 2629917c27c8Sdougm if (sa_plugin_ops.sa_init != nfs_init) { 2630549ec3ffSdougm (void) printf(dgettext(TEXT_DOMAIN, 2631549ec3ffSdougm "NFS plugin not properly initialized\n")); 2632917c27c8Sdougm return (SA_CONFIG_ERR); 2633917c27c8Sdougm } 2634549ec3ffSdougm 2635549ec3ffSdougm ret = initprotofromdefault(); 2636917c27c8Sdougm if (ret != SA_OK) { 2637917c27c8Sdougm (void) printf(dgettext(TEXT_DOMAIN, 2638917c27c8Sdougm "NFS plugin problem with default file: %s\n"), 2639917c27c8Sdougm sa_errorstr(ret)); 2640917c27c8Sdougm ret = SA_OK; 2641917c27c8Sdougm } 2642549ec3ffSdougm add_defaults(); 2643549ec3ffSdougm 2644549ec3ffSdougm return (ret); 2645549ec3ffSdougm } 2646549ec3ffSdougm 2647549ec3ffSdougm /* 2648549ec3ffSdougm * nfs_fini() 2649549ec3ffSdougm * 2650549ec3ffSdougm * uninitialize the NFS plugin. Want to avoid memory leaks. 2651549ec3ffSdougm */ 2652549ec3ffSdougm 2653549ec3ffSdougm static void 2654549ec3ffSdougm nfs_fini() 2655549ec3ffSdougm { 2656549ec3ffSdougm free_protoprops(); 2657549ec3ffSdougm } 2658549ec3ffSdougm 2659549ec3ffSdougm /* 2660549ec3ffSdougm * nfs_get_proto_set() 2661549ec3ffSdougm * 2662549ec3ffSdougm * Return an optionset with all the protocol specific properties in 2663549ec3ffSdougm * it. 2664549ec3ffSdougm */ 2665549ec3ffSdougm 2666549ec3ffSdougm static sa_protocol_properties_t 2667549ec3ffSdougm nfs_get_proto_set() 2668549ec3ffSdougm { 2669549ec3ffSdougm return (protoset); 2670549ec3ffSdougm } 2671549ec3ffSdougm 2672549ec3ffSdougm struct deffile { 2673549ec3ffSdougm struct deffile *next; 2674549ec3ffSdougm char *line; 2675549ec3ffSdougm }; 2676549ec3ffSdougm 2677549ec3ffSdougm /* 2678549ec3ffSdougm * read_default_file(fname) 2679549ec3ffSdougm * 2680549ec3ffSdougm * Read the specified default file. We return a list of entries. This 2681549ec3ffSdougm * get used for adding or removing values. 2682549ec3ffSdougm */ 2683549ec3ffSdougm 2684549ec3ffSdougm static struct deffile * 2685549ec3ffSdougm read_default_file(char *fname) 2686549ec3ffSdougm { 2687549ec3ffSdougm FILE *file; 2688549ec3ffSdougm struct deffile *defs = NULL; 2689549ec3ffSdougm struct deffile *newdef; 2690549ec3ffSdougm struct deffile *prevdef = NULL; 2691549ec3ffSdougm char buff[BUFSIZ * 2]; 2692549ec3ffSdougm 2693549ec3ffSdougm file = fopen(fname, "r"); 2694549ec3ffSdougm if (file != NULL) { 2695549ec3ffSdougm while (fgets(buff, sizeof (buff), file) != NULL) { 2696a3351425Sdougm newdef = (struct deffile *)calloc(1, 2697a3351425Sdougm sizeof (struct deffile)); 2698549ec3ffSdougm if (newdef != NULL) { 2699330ef417Sdougm /* Make sure we skip any leading whitespace. */ 2700330ef417Sdougm newdef->line = strdup(skipwhitespace(buff)); 2701549ec3ffSdougm if (defs == NULL) { 2702549ec3ffSdougm prevdef = defs = newdef; 2703549ec3ffSdougm } else { 2704549ec3ffSdougm prevdef->next = newdef; 2705549ec3ffSdougm prevdef = newdef; 2706549ec3ffSdougm } 2707549ec3ffSdougm } 2708549ec3ffSdougm } 2709549ec3ffSdougm (void) fclose(file); 2710917c27c8Sdougm } else { 2711917c27c8Sdougm int ret = SA_OK; 2712917c27c8Sdougm switch (errno) { 2713917c27c8Sdougm case EPERM: 2714917c27c8Sdougm case EACCES: 2715917c27c8Sdougm ret = SA_NO_PERMISSION; 2716917c27c8Sdougm break; 2717917c27c8Sdougm case ENOENT: 2718917c27c8Sdougm break; 2719917c27c8Sdougm default: 2720917c27c8Sdougm ret = SA_SYSTEM_ERR; 2721917c27c8Sdougm break; 2722917c27c8Sdougm } 2723917c27c8Sdougm if (ret == SA_OK) { 2724917c27c8Sdougm /* Want at least one comment line */ 2725917c27c8Sdougm defs = (struct deffile *) 2726917c27c8Sdougm calloc(1, sizeof (struct deffile)); 2727917c27c8Sdougm defs->line = strdup("# NFS default file\n"); 2728917c27c8Sdougm } 2729917c27c8Sdougm } 2730549ec3ffSdougm return (defs); 2731549ec3ffSdougm } 2732549ec3ffSdougm 2733549ec3ffSdougm static void 2734549ec3ffSdougm free_default_file(struct deffile *defs) 2735549ec3ffSdougm { 2736549ec3ffSdougm struct deffile *curdefs = NULL; 2737549ec3ffSdougm 2738549ec3ffSdougm while (defs != NULL) { 2739549ec3ffSdougm curdefs = defs; 2740549ec3ffSdougm defs = defs->next; 2741549ec3ffSdougm if (curdefs->line != NULL) 2742549ec3ffSdougm free(curdefs->line); 2743549ec3ffSdougm free(curdefs); 2744549ec3ffSdougm } 2745549ec3ffSdougm } 2746549ec3ffSdougm 2747549ec3ffSdougm /* 2748549ec3ffSdougm * write_default_file(fname, defs) 2749549ec3ffSdougm * 2750549ec3ffSdougm * Write the default file back. 2751549ec3ffSdougm */ 2752549ec3ffSdougm 2753549ec3ffSdougm static int 2754549ec3ffSdougm write_default_file(char *fname, struct deffile *defs) 2755549ec3ffSdougm { 2756549ec3ffSdougm FILE *file; 2757549ec3ffSdougm int ret = SA_OK; 2758549ec3ffSdougm sigset_t old, new; 2759549ec3ffSdougm 2760549ec3ffSdougm file = fopen(fname, "w+"); 2761549ec3ffSdougm if (file != NULL) { 2762549ec3ffSdougm (void) sigprocmask(SIG_BLOCK, NULL, &new); 2763549ec3ffSdougm (void) sigaddset(&new, SIGHUP); 2764549ec3ffSdougm (void) sigaddset(&new, SIGINT); 2765549ec3ffSdougm (void) sigaddset(&new, SIGQUIT); 2766549ec3ffSdougm (void) sigaddset(&new, SIGTSTP); 2767549ec3ffSdougm (void) sigprocmask(SIG_SETMASK, &new, &old); 2768549ec3ffSdougm while (defs != NULL) { 2769549ec3ffSdougm (void) fputs(defs->line, file); 2770549ec3ffSdougm defs = defs->next; 2771549ec3ffSdougm } 2772549ec3ffSdougm (void) fsync(fileno(file)); 2773549ec3ffSdougm (void) sigprocmask(SIG_SETMASK, &old, NULL); 2774549ec3ffSdougm (void) fclose(file); 2775549ec3ffSdougm } else { 2776549ec3ffSdougm switch (errno) { 2777549ec3ffSdougm case EPERM: 2778549ec3ffSdougm case EACCES: 2779549ec3ffSdougm ret = SA_NO_PERMISSION; 2780549ec3ffSdougm break; 2781549ec3ffSdougm default: 2782549ec3ffSdougm ret = SA_SYSTEM_ERR; 2783549ec3ffSdougm } 2784549ec3ffSdougm } 2785549ec3ffSdougm return (ret); 2786549ec3ffSdougm } 2787549ec3ffSdougm 2788549ec3ffSdougm 2789549ec3ffSdougm /* 2790549ec3ffSdougm * set_default_file_value(tag, value) 2791549ec3ffSdougm * 2792549ec3ffSdougm * Set the default file value for tag to value. Then rewrite the file. 2793549ec3ffSdougm * tag and value are always set. The caller must ensure this. 2794549ec3ffSdougm */ 2795549ec3ffSdougm 2796549ec3ffSdougm #define MAX_STRING_LENGTH 256 2797549ec3ffSdougm static int 2798549ec3ffSdougm set_default_file_value(char *tag, char *value) 2799549ec3ffSdougm { 2800549ec3ffSdougm int ret = SA_OK; 2801549ec3ffSdougm struct deffile *root; 2802549ec3ffSdougm struct deffile *defs; 2803549ec3ffSdougm struct deffile *prev; 2804549ec3ffSdougm char string[MAX_STRING_LENGTH]; 2805549ec3ffSdougm int len; 2806917c27c8Sdougm boolean_t update = B_FALSE; 2807549ec3ffSdougm 2808549ec3ffSdougm (void) snprintf(string, MAX_STRING_LENGTH, "%s=", tag); 2809549ec3ffSdougm len = strlen(string); 2810549ec3ffSdougm 2811549ec3ffSdougm root = defs = read_default_file(NFSADMIN); 2812549ec3ffSdougm if (root == NULL) { 2813917c27c8Sdougm switch (errno) { 2814917c27c8Sdougm case EPERM: 2815917c27c8Sdougm case EACCES: 2816549ec3ffSdougm ret = SA_NO_PERMISSION; 2817917c27c8Sdougm break; 2818917c27c8Sdougm default: 2819917c27c8Sdougm ret = SA_NO_MEMORY; 2820917c27c8Sdougm break; 2821917c27c8Sdougm } 2822917c27c8Sdougm return (ret); 2823917c27c8Sdougm } 2824917c27c8Sdougm 2825549ec3ffSdougm while (defs != NULL) { 2826549ec3ffSdougm if (defs->line != NULL && 2827549ec3ffSdougm strncasecmp(defs->line, string, len) == 0) { 2828549ec3ffSdougm /* replace with the new value */ 2829549ec3ffSdougm free(defs->line); 2830549ec3ffSdougm fixcaseupper(tag); 2831a3351425Sdougm (void) snprintf(string, sizeof (string), 2832a3351425Sdougm "%s=%s\n", tag, value); 2833549ec3ffSdougm string[MAX_STRING_LENGTH - 1] = '\0'; 2834549ec3ffSdougm defs->line = strdup(string); 2835917c27c8Sdougm update = B_TRUE; 2836549ec3ffSdougm break; 2837549ec3ffSdougm } 2838549ec3ffSdougm defs = defs->next; 2839549ec3ffSdougm } 2840549ec3ffSdougm if (!update) { 2841549ec3ffSdougm defs = root; 2842549ec3ffSdougm /* didn't find, so see if it is a comment */ 2843549ec3ffSdougm (void) snprintf(string, MAX_STRING_LENGTH, "#%s=", tag); 2844549ec3ffSdougm len = strlen(string); 2845549ec3ffSdougm while (defs != NULL) { 2846549ec3ffSdougm if (strncasecmp(defs->line, string, len) == 0) { 2847549ec3ffSdougm /* replace with the new value */ 2848549ec3ffSdougm free(defs->line); 2849549ec3ffSdougm fixcaseupper(tag); 2850549ec3ffSdougm (void) snprintf(string, sizeof (string), 2851549ec3ffSdougm "%s=%s\n", tag, value); 2852549ec3ffSdougm string[MAX_STRING_LENGTH - 1] = '\0'; 2853549ec3ffSdougm defs->line = strdup(string); 2854917c27c8Sdougm update = B_TRUE; 2855549ec3ffSdougm break; 2856549ec3ffSdougm } 2857549ec3ffSdougm defs = defs->next; 2858549ec3ffSdougm } 2859549ec3ffSdougm } 2860549ec3ffSdougm if (!update) { 2861549ec3ffSdougm fixcaseupper(tag); 2862549ec3ffSdougm (void) snprintf(string, sizeof (string), "%s=%s\n", 2863549ec3ffSdougm tag, value); 2864549ec3ffSdougm prev = root; 2865549ec3ffSdougm while (prev->next != NULL) 2866549ec3ffSdougm prev = prev->next; 2867549ec3ffSdougm defs = malloc(sizeof (struct deffile)); 2868549ec3ffSdougm prev->next = defs; 2869549ec3ffSdougm if (defs != NULL) { 2870549ec3ffSdougm defs->next = NULL; 2871549ec3ffSdougm defs->line = strdup(string); 2872917c27c8Sdougm update = B_TRUE; 2873549ec3ffSdougm } 2874549ec3ffSdougm } 2875549ec3ffSdougm if (update) { 2876549ec3ffSdougm ret = write_default_file(NFSADMIN, root); 2877549ec3ffSdougm } 2878549ec3ffSdougm free_default_file(root); 2879549ec3ffSdougm return (ret); 2880549ec3ffSdougm } 2881549ec3ffSdougm 2882549ec3ffSdougm /* 2883549ec3ffSdougm * service_in_state(service, chkstate) 2884549ec3ffSdougm * 2885549ec3ffSdougm * Want to know if the specified service is in the desired state 2886549ec3ffSdougm * (chkstate) or not. Return true (1) if it is and false (0) if it 2887549ec3ffSdougm * isn't. 2888549ec3ffSdougm */ 2889549ec3ffSdougm static int 2890549ec3ffSdougm service_in_state(char *service, const char *chkstate) 2891549ec3ffSdougm { 2892549ec3ffSdougm char *state; 2893549ec3ffSdougm int ret = B_FALSE; 2894549ec3ffSdougm 2895549ec3ffSdougm state = smf_get_state(service); 2896549ec3ffSdougm if (state != NULL) { 2897549ec3ffSdougm /* got the state so get the equality for the return value */ 2898549ec3ffSdougm ret = strcmp(state, chkstate) == 0 ? B_TRUE : B_FALSE; 2899549ec3ffSdougm free(state); 2900549ec3ffSdougm } 2901549ec3ffSdougm return (ret); 2902549ec3ffSdougm } 2903549ec3ffSdougm 2904549ec3ffSdougm /* 2905549ec3ffSdougm * restart_service(svcs) 2906549ec3ffSdougm * 2907549ec3ffSdougm * Walk through the bit mask of services that need to be restarted in 2908549ec3ffSdougm * order to use the new property values. Some properties affect 2909549ec3ffSdougm * multiple daemons. Should only restart a service if it is currently 2910549ec3ffSdougm * enabled (online). 2911549ec3ffSdougm */ 2912549ec3ffSdougm 2913549ec3ffSdougm static void 2914549ec3ffSdougm restart_service(uint32_t svcs) 2915549ec3ffSdougm { 2916549ec3ffSdougm uint32_t mask; 2917549ec3ffSdougm int ret; 2918549ec3ffSdougm char *service; 2919549ec3ffSdougm 2920549ec3ffSdougm for (mask = 1; svcs != 0; mask <<= 1) { 2921549ec3ffSdougm switch (svcs & mask) { 2922549ec3ffSdougm case SVC_LOCKD: 2923549ec3ffSdougm service = LOCKD; 2924549ec3ffSdougm break; 2925549ec3ffSdougm case SVC_STATD: 2926549ec3ffSdougm service = STATD; 2927549ec3ffSdougm break; 2928549ec3ffSdougm case SVC_NFSD: 2929549ec3ffSdougm service = NFSD; 2930549ec3ffSdougm break; 2931549ec3ffSdougm case SVC_MOUNTD: 2932549ec3ffSdougm service = MOUNTD; 2933549ec3ffSdougm break; 2934549ec3ffSdougm case SVC_NFS4CBD: 2935549ec3ffSdougm service = NFS4CBD; 2936549ec3ffSdougm break; 2937549ec3ffSdougm case SVC_NFSMAPID: 2938549ec3ffSdougm service = NFSMAPID; 2939549ec3ffSdougm break; 2940549ec3ffSdougm case SVC_RQUOTAD: 2941549ec3ffSdougm service = RQUOTAD; 2942549ec3ffSdougm break; 2943549ec3ffSdougm case SVC_NFSLOGD: 2944549ec3ffSdougm service = NFSLOGD; 2945549ec3ffSdougm break; 29462f172c55SRobert Thurlow case SVC_REPARSED: 29472f172c55SRobert Thurlow service = REPARSED; 29482f172c55SRobert Thurlow break; 2949549ec3ffSdougm default: 2950549ec3ffSdougm continue; 2951549ec3ffSdougm } 2952549ec3ffSdougm 2953549ec3ffSdougm /* 2954549ec3ffSdougm * Only attempt to restart the service if it is 2955549ec3ffSdougm * currently running. In the future, it may be 2956549ec3ffSdougm * desirable to use smf_refresh_instance if the NFS 2957549ec3ffSdougm * services ever implement the refresh method. 2958549ec3ffSdougm */ 2959549ec3ffSdougm if (service_in_state(service, SCF_STATE_STRING_ONLINE)) { 2960549ec3ffSdougm ret = smf_restart_instance(service); 2961549ec3ffSdougm /* 2962549ec3ffSdougm * There are only a few SMF errors at this point, but 2963549ec3ffSdougm * it is also possible that a bad value may have put 2964549ec3ffSdougm * the service into maintenance if there wasn't an 2965549ec3ffSdougm * SMF level error. 2966549ec3ffSdougm */ 2967549ec3ffSdougm if (ret != 0) { 2968549ec3ffSdougm (void) fprintf(stderr, 2969549ec3ffSdougm dgettext(TEXT_DOMAIN, 2970549ec3ffSdougm "%s failed to restart: %s\n"), 2971549ec3ffSdougm scf_strerror(scf_error())); 2972549ec3ffSdougm } else { 2973549ec3ffSdougm /* 2974549ec3ffSdougm * Check whether it has gone to "maintenance" 2975549ec3ffSdougm * mode or not. Maintenance implies something 2976549ec3ffSdougm * went wrong. 2977549ec3ffSdougm */ 2978a3351425Sdougm if (service_in_state(service, 2979a3351425Sdougm SCF_STATE_STRING_MAINT)) { 2980549ec3ffSdougm (void) fprintf(stderr, 2981549ec3ffSdougm dgettext(TEXT_DOMAIN, 2982549ec3ffSdougm "%s failed to restart\n"), 2983549ec3ffSdougm service); 2984549ec3ffSdougm } 2985549ec3ffSdougm } 2986549ec3ffSdougm } 2987549ec3ffSdougm svcs &= ~mask; 2988549ec3ffSdougm } 2989549ec3ffSdougm } 2990549ec3ffSdougm 2991549ec3ffSdougm /* 2992549ec3ffSdougm * nfs_minmax_check(name, value) 2993549ec3ffSdougm * 2994549ec3ffSdougm * Verify that the value for the property specified by index is valid 2995549ec3ffSdougm * relative to the opposite value in the case of a min/max variable. 2996549ec3ffSdougm * Currently, server_minvers/server_maxvers and 2997549ec3ffSdougm * client_minvers/client_maxvers are the only ones to check. 2998549ec3ffSdougm */ 2999549ec3ffSdougm 3000549ec3ffSdougm static int 3001549ec3ffSdougm nfs_minmax_check(int index, int value) 3002549ec3ffSdougm { 3003549ec3ffSdougm int val; 3004549ec3ffSdougm char *pval; 3005549ec3ffSdougm sa_property_t prop; 3006549ec3ffSdougm sa_optionset_t opts; 3007549ec3ffSdougm int ret = B_TRUE; 3008549ec3ffSdougm 3009549ec3ffSdougm if (proto_options[index].other != NULL) { 3010549ec3ffSdougm /* have a property to compare against */ 3011549ec3ffSdougm opts = nfs_get_proto_set(); 3012549ec3ffSdougm prop = sa_get_property(opts, proto_options[index].other); 3013549ec3ffSdougm /* 3014549ec3ffSdougm * If we don't find the property, assume default 3015549ec3ffSdougm * values which will work since the max will be at the 3016549ec3ffSdougm * max and the min at the min. 3017549ec3ffSdougm */ 3018549ec3ffSdougm if (prop != NULL) { 3019549ec3ffSdougm pval = sa_get_property_attr(prop, "value"); 3020549ec3ffSdougm if (pval != NULL) { 3021549ec3ffSdougm val = strtoul(pval, NULL, 0); 3022a3351425Sdougm if (proto_options[index].compare == 3023a3351425Sdougm OPT_CMP_LE) { 3024549ec3ffSdougm ret = value <= val ? B_TRUE : B_FALSE; 3025a3351425Sdougm } else if (proto_options[index].compare == 3026a3351425Sdougm OPT_CMP_GE) { 3027549ec3ffSdougm ret = value >= val ? B_TRUE : B_FALSE; 3028549ec3ffSdougm } 3029fe1c642dSBill Krier sa_free_attr_string(pval); 3030549ec3ffSdougm } 3031549ec3ffSdougm } 3032549ec3ffSdougm } 3033549ec3ffSdougm return (ret); 3034549ec3ffSdougm } 3035549ec3ffSdougm 3036549ec3ffSdougm /* 3037549ec3ffSdougm * nfs_validate_proto_prop(index, name, value) 3038549ec3ffSdougm * 3039da6c28aaSamw * Verify that the property specified by name can take the new 3040549ec3ffSdougm * value. This is a sanity check to prevent bad values getting into 3041549ec3ffSdougm * the default files. All values need to be checked against what is 3042549ec3ffSdougm * allowed by their defined type. If a type isn't explicitly defined 3043549ec3ffSdougm * here, it is treated as a string. 3044549ec3ffSdougm * 3045549ec3ffSdougm * Note that OPT_TYPE_NUMBER will additionally check that the value is 3046549ec3ffSdougm * within the range specified and potentially against another property 3047549ec3ffSdougm * value as well as specified in the proto_options members other and 3048549ec3ffSdougm * compare. 3049549ec3ffSdougm */ 3050549ec3ffSdougm 3051549ec3ffSdougm static int 3052549ec3ffSdougm nfs_validate_proto_prop(int index, char *name, char *value) 3053549ec3ffSdougm { 3054549ec3ffSdougm int ret = SA_OK; 3055549ec3ffSdougm char *cp; 3056549ec3ffSdougm #ifdef lint 3057549ec3ffSdougm name = name; 3058549ec3ffSdougm #endif 3059549ec3ffSdougm 3060549ec3ffSdougm switch (proto_options[index].type) { 3061549ec3ffSdougm case OPT_TYPE_NUMBER: 3062549ec3ffSdougm if (!is_a_number(value)) 3063549ec3ffSdougm ret = SA_BAD_VALUE; 3064549ec3ffSdougm else { 3065549ec3ffSdougm int val; 3066549ec3ffSdougm val = strtoul(value, NULL, 0); 3067549ec3ffSdougm if (val < proto_options[index].minval || 3068549ec3ffSdougm val > proto_options[index].maxval) 3069549ec3ffSdougm ret = SA_BAD_VALUE; 3070549ec3ffSdougm /* 3071549ec3ffSdougm * For server_versmin/server_versmax and 3072549ec3ffSdougm * client_versmin/client_versmax, the value of the 3073549ec3ffSdougm * min(max) should be checked to be correct relative 3074549ec3ffSdougm * to the current max(min). 3075549ec3ffSdougm */ 3076549ec3ffSdougm if (!nfs_minmax_check(index, val)) { 3077549ec3ffSdougm ret = SA_BAD_VALUE; 3078549ec3ffSdougm } 3079549ec3ffSdougm } 3080549ec3ffSdougm break; 3081549ec3ffSdougm 3082549ec3ffSdougm case OPT_TYPE_DOMAIN: 3083549ec3ffSdougm /* 3084549ec3ffSdougm * needs to be a qualified domain so will have at 3085549ec3ffSdougm * least one period and other characters on either 3086549ec3ffSdougm * side of it. A zero length string is also allowed 3087549ec3ffSdougm * and is the way to turn off the override. 3088549ec3ffSdougm */ 3089549ec3ffSdougm if (strlen(value) == 0) 3090549ec3ffSdougm break; 3091549ec3ffSdougm cp = strchr(value, '.'); 3092549ec3ffSdougm if (cp == NULL || cp == value || strchr(value, '@') != NULL) 3093549ec3ffSdougm ret = SA_BAD_VALUE; 3094549ec3ffSdougm break; 3095549ec3ffSdougm 3096549ec3ffSdougm case OPT_TYPE_BOOLEAN: 3097549ec3ffSdougm if (strlen(value) == 0 || 3098549ec3ffSdougm strcasecmp(value, "true") == 0 || 3099549ec3ffSdougm strcmp(value, "1") == 0 || 3100549ec3ffSdougm strcasecmp(value, "false") == 0 || 3101549ec3ffSdougm strcmp(value, "0") == 0) { 3102549ec3ffSdougm ret = SA_OK; 3103549ec3ffSdougm } else { 3104549ec3ffSdougm ret = SA_BAD_VALUE; 3105549ec3ffSdougm } 3106549ec3ffSdougm break; 3107549ec3ffSdougm 3108549ec3ffSdougm case OPT_TYPE_ONOFF: 3109549ec3ffSdougm if (strcasecmp(value, "on") != 0 && 3110549ec3ffSdougm strcasecmp(value, "off") != 0) { 3111549ec3ffSdougm ret = SA_BAD_VALUE; 3112549ec3ffSdougm } 3113549ec3ffSdougm break; 3114549ec3ffSdougm 3115549ec3ffSdougm case OPT_TYPE_PROTOCOL: 3116917c27c8Sdougm if (strlen(value) != 0 && 3117917c27c8Sdougm strcasecmp(value, "all") != 0 && 3118549ec3ffSdougm strcasecmp(value, "tcp") != 0 && 3119549ec3ffSdougm strcasecmp(value, "udp") != 0) 3120549ec3ffSdougm ret = SA_BAD_VALUE; 3121549ec3ffSdougm break; 3122549ec3ffSdougm 3123549ec3ffSdougm default: 3124549ec3ffSdougm /* treat as a string */ 3125549ec3ffSdougm break; 3126549ec3ffSdougm } 3127549ec3ffSdougm return (ret); 3128549ec3ffSdougm } 3129549ec3ffSdougm 3130549ec3ffSdougm /* 3131549ec3ffSdougm * nfs_set_proto_prop(prop) 3132549ec3ffSdougm * 3133549ec3ffSdougm * check that prop is valid. 3134549ec3ffSdougm */ 3135549ec3ffSdougm 3136549ec3ffSdougm static int 3137549ec3ffSdougm nfs_set_proto_prop(sa_property_t prop) 3138549ec3ffSdougm { 3139549ec3ffSdougm int ret = SA_OK; 3140549ec3ffSdougm char *name; 3141549ec3ffSdougm char *value; 3142549ec3ffSdougm 3143549ec3ffSdougm name = sa_get_property_attr(prop, "type"); 3144549ec3ffSdougm value = sa_get_property_attr(prop, "value"); 3145549ec3ffSdougm if (name != NULL && value != NULL) { 3146549ec3ffSdougm int index = findprotoopt(name, 1); 3147549ec3ffSdougm if (index >= 0) { 3148549ec3ffSdougm /* should test for valid value */ 3149549ec3ffSdougm ret = nfs_validate_proto_prop(index, name, value); 3150549ec3ffSdougm if (ret == SA_OK) 3151a3351425Sdougm ret = set_default_file_value( 3152a3351425Sdougm proto_options[index].tag, value); 3153549ec3ffSdougm if (ret == SA_OK) 3154549ec3ffSdougm restart_service(proto_options[index].svcs); 3155549ec3ffSdougm } 3156549ec3ffSdougm } 3157549ec3ffSdougm if (name != NULL) 3158549ec3ffSdougm sa_free_attr_string(name); 3159549ec3ffSdougm if (value != NULL) 3160549ec3ffSdougm sa_free_attr_string(value); 3161549ec3ffSdougm return (ret); 3162549ec3ffSdougm } 3163549ec3ffSdougm 3164549ec3ffSdougm /* 3165549ec3ffSdougm * nfs_get_status() 3166549ec3ffSdougm * 3167549ec3ffSdougm * What is the current status of the nfsd? We use the SMF state here. 3168549ec3ffSdougm * Caller must free the returned value. 3169549ec3ffSdougm */ 3170549ec3ffSdougm 3171549ec3ffSdougm static char * 3172549ec3ffSdougm nfs_get_status() 3173549ec3ffSdougm { 3174549ec3ffSdougm char *state; 3175549ec3ffSdougm state = smf_get_state(NFSD); 3176549ec3ffSdougm return (state != NULL ? state : strdup("-")); 3177549ec3ffSdougm } 3178549ec3ffSdougm 3179549ec3ffSdougm /* 3180549ec3ffSdougm * nfs_space_alias(alias) 3181549ec3ffSdougm * 3182549ec3ffSdougm * Lookup the space (security) name. If it is default, convert to the 3183549ec3ffSdougm * real name. 3184549ec3ffSdougm */ 3185549ec3ffSdougm 3186549ec3ffSdougm static char * 3187549ec3ffSdougm nfs_space_alias(char *space) 3188549ec3ffSdougm { 3189549ec3ffSdougm char *name = space; 3190549ec3ffSdougm seconfig_t secconf; 3191549ec3ffSdougm 3192549ec3ffSdougm /* 3193549ec3ffSdougm * Only the space named "default" is special. If it is used, 3194549ec3ffSdougm * the default needs to be looked up and the real name used. 3195549ec3ffSdougm * This is normally "sys" but could be changed. We always 3196549ec3ffSdougm * change defautl to the real name. 3197549ec3ffSdougm */ 3198549ec3ffSdougm if (strcmp(space, "default") == 0 && 3199549ec3ffSdougm nfs_getseconfig_default(&secconf) == 0) { 3200549ec3ffSdougm if (nfs_getseconfig_bynumber(secconf.sc_nfsnum, &secconf) == 0) 3201549ec3ffSdougm name = secconf.sc_name; 3202549ec3ffSdougm } 3203549ec3ffSdougm return (strdup(name)); 3204549ec3ffSdougm } 3205da6c28aaSamw 3206da6c28aaSamw /* 3207da6c28aaSamw * nfs_features() 3208da6c28aaSamw * 3209da6c28aaSamw * Return a mask of the features required. 3210da6c28aaSamw */ 3211da6c28aaSamw 3212da6c28aaSamw static uint64_t 3213da6c28aaSamw nfs_features() 3214da6c28aaSamw { 32159e5da854Sdougm return ((uint64_t)SA_FEATURE_DFSTAB | SA_FEATURE_SERVER); 3216da6c28aaSamw } 3217