4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2016 Nexenta Systems, Inc.
25 * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
29 * NFS specific functions
42 #include "libshare_impl.h"
43 #include <nfs/export.h>
49 #include <rpcsvc/daemon_utils.h>
50 #include "nfslog_config.h"
51 #include "nfslogtab.h"
52 #include "libshare_nfs.h"
54 #include <nfs/nfssys.h>
55 #include <netconfig.h>
58 /* should really be in some global place */
60 #define OPT_CHUNK 1024
64 #define NFS_SERVER_SVC "svc:/network/nfs/server:default"
65 #define NFS_CLIENT_SVC (char *)"svc:/network/nfs/client:default"
67 /* internal functions */
68 static int nfs_init();
69 static void nfs_fini();
70 static int nfs_enable_share(sa_share_t
);
71 static int nfs_disable_share(sa_share_t
, char *);
72 static int nfs_validate_property(sa_handle_t
, sa_property_t
, sa_optionset_t
);
73 static int nfs_validate_security_mode(char *);
74 static int nfs_is_security_opt(char *);
75 static int nfs_parse_legacy_options(sa_group_t
, char *);
76 static char *nfs_format_options(sa_group_t
, int);
77 static int nfs_set_proto_prop(sa_property_t
);
78 static sa_protocol_properties_t
nfs_get_proto_set();
79 static char *nfs_get_status();
80 static char *nfs_space_alias(char *);
81 static uint64_t nfs_features();
84 * ops vector that provides the protocol specific info and operations
85 * for share management.
88 struct sa_plugin_ops sa_plugin_ops
= {
95 nfs_validate_property
,
96 nfs_validate_security_mode
,
98 nfs_parse_legacy_options
,
104 NULL
, /* update_legacy */
105 NULL
, /* delete_legacy */
106 NULL
, /* change_notify */
107 NULL
, /* enable_resource */
108 NULL
, /* disable_resource */
110 NULL
, /* transient shares */
111 NULL
, /* notify resource */
112 NULL
, /* rename_resource */
113 NULL
, /* run_command */
114 NULL
, /* command_help */
115 NULL
/* delete_proto_section */
119 * list of support services needed
120 * defines should come from head/rpcsvc/daemon_utils.h
123 static char *service_list_default
[] =
124 { STATD
, LOCKD
, MOUNTD
, NFSD
, NFSMAPID
, RQUOTAD
, REPARSED
, NULL
};
125 static char *service_list_logging
[] =
126 { STATD
, LOCKD
, MOUNTD
, NFSD
, NFSMAPID
, RQUOTAD
, NFSLOGD
, REPARSED
,
130 * option definitions. Make sure to keep the #define for the option
131 * index just before the entry it is the index for. Changing the order
132 * can cause breakage. E.g OPT_RW is index 1 and must precede the
133 * line that includes the SHOPT_RW and OPT_RW entries.
136 struct option_defs optdefs
[] = {
138 {SHOPT_RO
, OPT_RO
, OPT_TYPE_ACCLIST
},
140 {SHOPT_RW
, OPT_RW
, OPT_TYPE_ACCLIST
},
142 {SHOPT_ROOT
, OPT_ROOT
, OPT_TYPE_ACCLIST
},
144 {SHOPT_SECURE
, OPT_SECURE
, OPT_TYPE_DEPRECATED
},
146 {SHOPT_ANON
, OPT_ANON
, OPT_TYPE_USER
},
148 {SHOPT_WINDOW
, OPT_WINDOW
, OPT_TYPE_NUMBER
},
150 {SHOPT_NOSUID
, OPT_NOSUID
, OPT_TYPE_BOOLEAN
},
152 {SHOPT_ACLOK
, OPT_ACLOK
, OPT_TYPE_BOOLEAN
},
154 {SHOPT_NOSUB
, OPT_NOSUB
, OPT_TYPE_BOOLEAN
},
156 {SHOPT_SEC
, OPT_SEC
, OPT_TYPE_SECURITY
},
157 #define OPT_PUBLIC 10
158 {SHOPT_PUBLIC
, OPT_PUBLIC
, OPT_TYPE_BOOLEAN
, OPT_SHARE_ONLY
},
160 {SHOPT_INDEX
, OPT_INDEX
, OPT_TYPE_FILE
},
162 {SHOPT_LOG
, OPT_LOG
, OPT_TYPE_LOGTAG
},
164 {SHOPT_CKSUM
, OPT_CKSUM
, OPT_TYPE_STRINGSET
},
166 {SHOPT_NONE
, OPT_NONE
, OPT_TYPE_ACCLIST
},
167 #define OPT_ROOT_MAPPING 15
168 {SHOPT_ROOT_MAPPING
, OPT_ROOT_MAPPING
, OPT_TYPE_USER
},
169 #define OPT_CHARSET_MAP 16
170 {"", OPT_CHARSET_MAP
, OPT_TYPE_ACCLIST
},
171 #define OPT_NOACLFAB 17
172 {SHOPT_NOACLFAB
, OPT_NOACLFAB
, OPT_TYPE_BOOLEAN
},
173 #define OPT_UIDMAP 18
174 {SHOPT_UIDMAP
, OPT_UIDMAP
, OPT_TYPE_MAPPING
},
175 #define OPT_GIDMAP 19
176 {SHOPT_GIDMAP
, OPT_GIDMAP
, OPT_TYPE_MAPPING
},
177 #ifdef VOLATILE_FH_TEST /* XXX added for testing volatile fh's only */
179 {SHOPT_VOLFH
, OPT_VOLFH
},
180 #endif /* VOLATILE_FH_TEST */
185 * Codesets that may need to be converted to UTF-8 for file paths.
186 * Add new names here to add new property support. If we ever get a
187 * way to query the kernel for character sets, this should become
188 * dynamically loaded. Make sure changes here are reflected in
189 * cmd/fs.d/nfs/mountd/nfscmd.c
192 static char *legal_conv
[] = {
212 * list of properties that are related to security flavors.
214 static char *seclist
[] = {
226 /* structure for list of securities */
228 sa_security_t security
;
229 struct securities
*next
;
233 * findcharset(charset)
235 * Returns B_TRUE if the charset is a legal conversion otherwise
236 * B_FALSE. This will need to be rewritten to be more efficient when
237 * we have a dynamic list of legal conversions.
241 findcharset(char *charset
)
245 for (i
= 0; legal_conv
[i
] != NULL
; i
++)
246 if (strcmp(charset
, legal_conv
[i
]) == 0)
254 * Lookup option "name" in the option table and return the table
263 for (i
= 0; optdefs
[i
].tag
!= NULL
; i
++) {
264 if (strcmp(optdefs
[i
].tag
, name
) == 0)
265 return (optdefs
[i
].index
);
267 if (findcharset(name
))
268 return (OPT_CHARSET_MAP
);
276 * Return the type of option "name".
284 optdef
= findopt(name
);
286 return (optdefs
[optdef
].type
);
287 return (OPT_TYPE_ANY
);
291 * nfs_validate_security_mode(mode)
293 * is the specified mode string a valid one for use with NFS?
297 nfs_validate_security_mode(char *mode
)
302 (void) memset(&secinfo
, '\0', sizeof (secinfo
));
303 err
= nfs_getseconfig_byname(mode
, &secinfo
);
304 if (err
== SC_NOERROR
)
310 * nfs_is_security_opt(tok)
312 * check to see if tok represents an option that is only valid in some
317 nfs_is_security_opt(char *tok
)
321 for (i
= 0; seclist
[i
] != NULL
; i
++) {
322 if (strcmp(tok
, seclist
[i
]) == 0)
329 * find_security(seclist, sec)
331 * Walk the current list of security flavors and return true if it is
332 * present, else return false.
336 find_security(struct securities
*seclist
, sa_security_t sec
)
338 while (seclist
!= NULL
) {
339 if (seclist
->security
== sec
)
341 seclist
= seclist
->next
;
347 * make_security_list(group, securitymodes, proto)
348 * go through the list of securitymodes and add them to the
349 * group's list of security optionsets. We also keep a list of
350 * those optionsets so we don't have to find them later. All of
351 * these will get copies of the same properties.
354 static struct securities
*
355 make_security_list(sa_group_t group
, char *securitymodes
, char *proto
)
357 char *tok
, *next
= NULL
;
358 struct securities
*curp
, *headp
= NULL
, *prev
;
362 for (tok
= securitymodes
; tok
!= NULL
; tok
= next
) {
363 next
= strchr(tok
, ':');
366 if (strcmp(tok
, "default") == 0) {
367 /* resolve default into the real type */
368 tok
= nfs_space_alias(tok
);
371 check
= sa_get_security(group
, tok
, proto
);
373 /* add to the security list if it isn't there already */
374 if (check
== NULL
|| !find_security(headp
, check
)) {
375 curp
= (struct securities
*)calloc(1,
376 sizeof (struct securities
));
379 curp
->security
= sa_create_security(
382 curp
->security
= check
;
385 * note that the first time through the loop,
386 * headp will be NULL and prev will be
387 * undefined. Since headp is NULL, we set
388 * both it and prev to the curp (first
389 * structure to be allocated).
391 * later passes through the loop will have
392 * headp not being NULL and prev will be used
393 * to allocate at the end of the list.
407 sa_free_attr_string(tok
);
414 free_security_list(struct securities
*sec
)
416 struct securities
*next
;
418 for (next
= sec
->next
; sec
!= NULL
; sec
= next
) {
426 * nfs_alistcat(str1, str2, sep)
428 * concatenate str1 and str2 into a new string using sep as a separate
429 * character. If memory allocation fails, return NULL;
433 nfs_alistcat(char *str1
, char *str2
, char sep
)
438 len
= strlen(str1
) + strlen(str2
) + 2;
439 newstr
= (char *)malloc(len
);
441 (void) snprintf(newstr
, len
, "%s%c%s", str1
, sep
, str2
);
446 * add_security_prop(sec, name, value, persist, iszfs)
448 * Add the property to the securities structure. This accumulates
449 * properties for as part of parsing legacy options.
453 add_security_prop(struct securities
*sec
, char *name
, char *value
,
454 int persist
, int iszfs
)
459 for (; sec
!= NULL
; sec
= sec
->next
) {
461 if (strcmp(name
, SHOPT_RW
) == 0 ||
462 strcmp(name
, SHOPT_RO
) == 0)
469 * Get the existing property, if it exists, so we can
470 * determine what to do with it. The ro/rw/root
471 * properties can be merged if multiple instances of
472 * these properies are given. For example, if "rw"
473 * exists with a value "host1" and a later token of
474 * rw="host2" is seen, the values are merged into a
475 * single rw="host1:host2".
477 prop
= sa_get_property(sec
->security
, name
);
484 * The security options of ro/rw/root/uidmap/gidmap
485 * might appear multiple times. If they do, the values
486 * need to be merged. If it was previously empty, the
487 * new value alone is added.
489 oldvalue
= sa_get_property_attr(prop
, "value");
490 if (oldvalue
!= NULL
) {
493 if (strcmp(name
, SHOPT_UIDMAP
) == 0 ||
494 strcmp(name
, SHOPT_GIDMAP
) == 0)
498 * The general case is to concatenate the new
499 * value onto the old value for multiple
500 * rw(ro/root/uidmap/gidmap) properties. For
501 * rw/ro/root a special case exists when either
502 * the old or new is the "all" case. In the
503 * special case, if both are "all", then it is
504 * "all", else if one is an access-list, that
505 * replaces the "all".
507 if (strcmp(oldvalue
, "*") == 0) {
508 /* Replace old value with new value. */
509 newvalue
= strdup(value
);
510 } else if (strcmp(value
, "*") == 0 ||
511 strcmp(oldvalue
, value
) == 0) {
513 * Keep old value and ignore
519 * Make a new list of old plus new
522 newvalue
= nfs_alistcat(oldvalue
,
526 if (newvalue
!= NULL
) {
527 (void) sa_remove_property(prop
);
528 prop
= sa_create_property(name
,
530 ret
= sa_add_property(sec
->security
,
535 sa_free_attr_string(oldvalue
);
538 prop
= sa_create_property(name
, value
);
539 ret
= sa_add_property(sec
->security
, prop
);
541 if (ret
== SA_OK
&& !iszfs
) {
542 ret
= sa_commit_properties(sec
->security
, !persist
);
549 * check to see if group/share is persistent.
552 is_persistent(sa_group_t group
)
557 type
= sa_get_group_attr(group
, "type");
558 if (type
!= NULL
&& strcmp(type
, "persist") != 0)
561 sa_free_attr_string(type
);
566 * invalid_security(options)
568 * search option string for any invalid sec= type.
569 * return true (1) if any are not valid else false (0)
572 invalid_security(char *options
)
574 char *copy
, *base
, *token
, *value
;
577 copy
= strdup(options
);
579 while (token
!= NULL
&& ret
== 0) {
580 token
= strtok(base
, ",");
583 value
= strchr(token
, '=');
586 if (strcmp(token
, SHOPT_SEC
) == 0) {
587 /* HAVE security flavors so check them */
589 for (next
= NULL
, tok
= value
; tok
!= NULL
;
591 next
= strchr(tok
, ':');
594 ret
= !nfs_validate_security_mode(tok
);
607 * nfs_parse_legacy_options(group, options)
609 * Parse the old style options into internal format and store on the
610 * specified group. Group could be a share for full legacy support.
614 nfs_parse_legacy_options(sa_group_t group
, char *options
)
619 sa_optionset_t optionset
;
620 struct securities
*security_list
= NULL
;
628 /* do we have an existing optionset? */
629 optionset
= sa_get_optionset(group
, "nfs");
630 if (optionset
== NULL
) {
631 /* didn't find existing optionset so create one */
632 optionset
= sa_create_optionset(group
, "nfs");
635 * Have an existing optionset . Ideally, we would need
636 * to compare options in order to detect errors. For
637 * now, we assume that the first optionset is the
638 * correct one and the others will be the same. An
639 * empty optionset is the same as no optionset so we
640 * don't want to exit in that case. Getting an empty
641 * optionset can occur with ZFS property checking.
643 if (sa_get_property(optionset
, NULL
) != NULL
)
647 if (strcmp(options
, SHOPT_RW
) == 0) {
649 * there is a special case of only the option "rw"
650 * being the default option. We don't have to do
657 * check if security types are present and validate them. If
658 * any are not legal, fail.
661 if (invalid_security(options
)) {
662 return (SA_INVALID_SECURITY
);
666 * in order to not attempt to change ZFS properties unless
667 * absolutely necessary, we never do it in the legacy parsing.
669 if (sa_is_share(group
)) {
671 parent
= sa_get_parent_group(group
);
672 if (parent
!= NULL
) {
673 zfs
= sa_get_group_attr(parent
, "zfs");
675 sa_free_attr_string(zfs
);
680 iszfs
= sa_group_is_zfs(group
);
683 /* We need a copy of options for the next part. */
684 dup
= strdup(options
);
686 return (SA_NO_MEMORY
);
689 * we need to step through each option in the string and then
690 * add either the option or the security option as needed. If
691 * this is not a persistent share, don't commit to the
692 * repository. If there is an error, we also want to abort the
693 * processing and report it.
695 persist
= is_persistent(group
);
699 while (token
!= NULL
&& ret
== SA_OK
) {
700 token
= strtok_r(base
, ",", &lasts
);
705 * if the option has a value, it will have an '=' to
706 * separate the name from the value. The following
707 * code will result in value != NULL and token
708 * pointing to just the name if there is a value.
710 value
= strchr(token
, '=');
714 if (strcmp(token
, SHOPT_SEC
) == 0 ||
715 strcmp(token
, SHOPT_SECURE
) == 0) {
717 * Once in security parsing, we only
718 * do security. We do need to move
719 * between the security node and the
720 * toplevel. The security tag goes on
721 * the root while the following ones
722 * go on the security.
724 if (security_list
!= NULL
) {
726 * have an old list so close it and
729 free_security_list(security_list
);
731 if (strcmp(token
, SHOPT_SECURE
) == 0) {
739 security_list
= make_security_list(group
,
743 * Note that the "old" syntax allowed a
744 * default security model. This must be
745 * accounted for and internally converted to
746 * "standard" security structure.
748 if (nfs_is_security_opt(token
)) {
749 if (security_list
== NULL
) {
764 make_security_list(group
,
768 if (security_list
!= NULL
) {
769 ret
= add_security_prop(
770 security_list
, token
,
771 value
, persist
, iszfs
);
776 /* regular options */
778 if (strcmp(token
, SHOPT_RW
) ==
791 * In all cases, create the
792 * property specified. If the
793 * value was NULL, the default
794 * value will have been
797 prop
= sa_create_property(token
, value
);
798 ret
= sa_add_property(optionset
, prop
);
803 ret
= sa_commit_properties(
804 optionset
, !persist
);
810 if (security_list
!= NULL
)
811 free_security_list(security_list
);
818 * is_a_number(number)
820 * is the string a number in one of the forms we want to use?
824 is_a_number(char *number
)
829 if (strncmp(number
, "0x", 2) == 0) {
832 } else if (*number
== '-') {
833 number
++; /* skip the minus */
835 while (ret
== 1 && *number
!= '\0') {
837 ret
= isxdigit(*number
++);
839 ret
= isdigit(*number
++);
846 * Look for the specified tag in the configuration file. If it is found,
847 * enable logging and set the logging configuration information for exp.
850 configlog(struct exportdata
*exp
, char *tag
)
852 nfsl_config_t
*configlist
= NULL
, *configp
;
854 char globaltag
[] = DEFAULTTAG
;
857 * Sends config errors to stderr
859 nfsl_errs_to_syslog
= B_FALSE
;
862 * get the list of configuration settings
864 error
= nfsl_getconfig_list(&configlist
);
866 (void) fprintf(stderr
,
867 dgettext(TEXT_DOMAIN
, "Cannot get log configuration: %s\n"),
873 if ((configp
= nfsl_findconfig(configlist
, tag
, &error
)) == NULL
) {
874 nfsl_freeconfig_list(&configlist
);
875 (void) fprintf(stderr
,
876 dgettext(TEXT_DOMAIN
, "No tags matching \"%s\"\n"), tag
);
877 /* bad configuration */
882 if ((exp
->ex_tag
= strdup(tag
)) == NULL
) {
886 if ((exp
->ex_log_buffer
= strdup(configp
->nc_bufferpath
)) == NULL
) {
890 exp
->ex_flags
|= EX_LOG
;
891 if (configp
->nc_rpclogpath
!= NULL
)
892 exp
->ex_flags
|= EX_LOG_ALLOPS
;
894 if (configlist
!= NULL
)
895 nfsl_freeconfig_list(&configlist
);
900 free(exp
->ex_log_buffer
);
901 (void) fprintf(stderr
,
902 dgettext(TEXT_DOMAIN
, "Cannot set log configuration: %s\n"),
908 * fill_export_from_optionset(export, optionset)
910 * In order to share, we need to set all the possible general options
911 * into the export structure. Share info will be filled in by the
912 * caller. Various property values get turned into structure specific
917 fill_export_from_optionset(struct exportdata
*export
, sa_optionset_t optionset
)
919 sa_property_t option
;
922 for (option
= sa_get_property(optionset
, NULL
);
923 option
!= NULL
; option
= sa_get_next_property(option
)) {
929 * since options may be set/reset multiple times, always do an
930 * explicit set or clear of the option. This allows defaults
931 * to be set and then the protocol specific to override.
934 name
= sa_get_property_attr(option
, "type");
935 value
= sa_get_property_attr(option
, "value");
936 switch (findopt(name
)) {
938 if (value
!= NULL
&& is_a_number(value
)) {
939 val
= strtoul(value
, NULL
, 0);
942 pw
= getpwnam(value
!= NULL
? value
: "nobody");
950 export
->ex_anon
= val
;
953 if (value
!= NULL
&& (strcasecmp(value
, "true") == 0 ||
954 strcmp(value
, "1") == 0))
955 export
->ex_flags
|= EX_NOSUID
;
957 export
->ex_flags
&= ~EX_NOSUID
;
960 if (value
!= NULL
&& (strcasecmp(value
, "true") == 0 ||
961 strcmp(value
, "1") == 0))
962 export
->ex_flags
|= EX_ACLOK
;
964 export
->ex_flags
&= ~EX_ACLOK
;
967 if (value
!= NULL
&& (strcasecmp(value
, "true") == 0 ||
968 strcmp(value
, "1") == 0))
969 export
->ex_flags
|= EX_NOSUB
;
971 export
->ex_flags
&= ~EX_NOSUB
;
974 if (value
!= NULL
&& (strcasecmp(value
, "true") == 0 ||
975 strcmp(value
, "1") == 0))
976 export
->ex_flags
|= EX_PUBLIC
;
978 export
->ex_flags
&= ~EX_PUBLIC
;
981 if (value
!= NULL
&& (strcmp(value
, "..") == 0 ||
982 strchr(value
, '/') != NULL
)) {
983 /* this is an error */
984 (void) printf(dgettext(TEXT_DOMAIN
,
985 "NFS: index=\"%s\" not valid;"
986 "must be a filename.\n"),
990 if (value
!= NULL
&& *value
!= '\0' &&
991 strcmp(value
, ".") != 0) {
992 /* valid index file string */
993 if (export
->ex_index
!= NULL
) {
994 /* left over from "default" */
995 free(export
->ex_index
);
997 /* remember to free */
998 export
->ex_index
= strdup(value
);
999 if (export
->ex_index
== NULL
) {
1000 (void) printf(dgettext(TEXT_DOMAIN
,
1001 "NFS: out of memory setting "
1002 "index property\n"));
1005 export
->ex_flags
|= EX_INDEX
;
1010 value
= strdup("global");
1013 strlen(value
) ? value
: "global");
1015 case OPT_CHARSET_MAP
:
1017 * Set EX_CHARMAP when there is at least one
1018 * charmap conversion property. This will get
1019 * checked by the nfs server when it needs to.
1021 export
->ex_flags
|= EX_CHARMAP
;
1024 if (value
!= NULL
&& (strcasecmp(value
, "true") == 0 ||
1025 strcmp(value
, "1") == 0))
1026 export
->ex_flags
|= EX_NOACLFAB
;
1028 export
->ex_flags
&= ~EX_NOACLFAB
;
1031 /* have a syntactic error */
1032 (void) printf(dgettext(TEXT_DOMAIN
,
1033 "NFS: unrecognized option %s=%s\n"),
1034 name
!= NULL
? name
: "",
1035 value
!= NULL
? value
: "");
1039 sa_free_attr_string(name
);
1041 sa_free_attr_string(value
);
1047 * cleanup_export(export)
1049 * Cleanup the allocated areas so we don't leak memory
1053 cleanup_export(struct exportdata
*export
)
1057 free(export
->ex_index
);
1059 for (i
= 0; i
< export
->ex_seccnt
; i
++) {
1060 struct secinfo
*s
= &export
->ex_secinfo
[i
];
1062 while (s
->s_rootcnt
> 0)
1063 free(s
->s_rootnames
[--s
->s_rootcnt
]);
1065 free(s
->s_rootnames
);
1067 free(export
->ex_secinfo
);
1071 * Given a seconfig entry and a colon-separated
1072 * list of names, allocate an array big enough
1073 * to hold the root list, then convert each name to
1074 * a principal name according to the security
1075 * info and assign it to an array element.
1076 * Return the array and its size.
1079 get_rootnames(seconfig_t
*sec
, char *list
, int *count
)
1086 * Count the number of strings in the list.
1087 * This is the number of colon separators + 1.
1090 for (p
= list
; *p
; p
++)
1095 a
= (caddr_t
*)malloc(c
* sizeof (char *));
1097 (void) printf(dgettext(TEXT_DOMAIN
,
1098 "get_rootnames: no memory\n"));
1101 for (i
= 0; i
< c
; i
++) {
1102 host
= strtok(list
, ":");
1103 if (!nfs_get_root_principal(sec
, host
, &a
[i
])) {
1119 * fill_security_from_secopts(sp, secopts)
1121 * Fill the secinfo structure from the secopts optionset.
1125 fill_security_from_secopts(struct secinfo
*sp
, sa_security_t secopts
)
1130 int err
= SC_NOERROR
;
1133 type
= sa_get_security_attr(secopts
, "sectype");
1135 /* named security type needs secinfo to be filled in */
1136 err
= nfs_getseconfig_byname(type
, &sp
->s_secinfo
);
1137 sa_free_attr_string(type
);
1138 if (err
!= SC_NOERROR
)
1142 err
= nfs_getseconfig_default(&sp
->s_secinfo
);
1143 if (err
!= SC_NOERROR
)
1148 for (prop
= sa_get_property(secopts
, NULL
);
1149 prop
!= NULL
&& err
== SA_OK
;
1150 prop
= sa_get_next_property(prop
)) {
1154 name
= sa_get_property_attr(prop
, "type");
1155 value
= sa_get_property_attr(prop
, "value");
1157 longform
= value
!= NULL
&& strcmp(value
, "*") != 0;
1159 switch (findopt(name
)) {
1161 sp
->s_flags
|= longform
? M_ROL
: M_RO
;
1164 sp
->s_flags
|= longform
? M_RWL
: M_RW
;
1167 sp
->s_flags
|= M_ROOT
;
1169 * if we are using AUTH_UNIX, handle like other things
1172 if (sp
->s_secinfo
.sc_rpcnum
== AUTH_UNIX
)
1175 if (value
!= NULL
) {
1176 sp
->s_rootnames
= get_rootnames(&sp
->s_secinfo
,
1177 value
, &sp
->s_rootcnt
);
1178 if (sp
->s_rootnames
== NULL
) {
1180 (void) fprintf(stderr
,
1181 dgettext(TEXT_DOMAIN
,
1182 "Bad root list\n"));
1187 sp
->s_flags
|= M_NONE
;
1190 if (value
!= NULL
) {
1191 sp
->s_window
= atoi(value
);
1193 if (sp
->s_window
< 0)
1194 sp
->s_window
= DEF_WIN
;
1197 case OPT_ROOT_MAPPING
:
1198 if (value
!= NULL
&& is_a_number(value
)) {
1199 val
= strtoul(value
, NULL
, 0);
1202 pw
= getpwnam(value
!= NULL
? value
: "nobody");
1214 sp
->s_flags
|= M_MAP
;
1220 sa_free_attr_string(name
);
1222 sa_free_attr_string(value
);
1224 /* if rw/ro options not set, use default of RW */
1225 if ((sp
->s_flags
& NFS_RWMODES
) == 0)
1226 sp
->s_flags
|= M_RW
;
1231 * This is for testing only
1232 * It displays the export structure that
1233 * goes into the kernel.
1236 printarg(char *path
, struct exportdata
*ep
)
1244 (void) printf("%s:\n", path
);
1245 (void) printf("\tex_version = %d\n", ep
->ex_version
);
1246 (void) printf("\tex_path = %s\n", ep
->ex_path
);
1247 (void) printf("\tex_pathlen = %ld\n", (ulong_t
)ep
->ex_pathlen
);
1248 (void) printf("\tex_flags: (0x%02x) ", ep
->ex_flags
);
1249 if (ep
->ex_flags
& EX_NOSUID
)
1250 (void) printf("NOSUID ");
1251 if (ep
->ex_flags
& EX_ACLOK
)
1252 (void) printf("ACLOK ");
1253 if (ep
->ex_flags
& EX_PUBLIC
)
1254 (void) printf("PUBLIC ");
1255 if (ep
->ex_flags
& EX_NOSUB
)
1256 (void) printf("NOSUB ");
1257 if (ep
->ex_flags
& EX_LOG
)
1258 (void) printf("LOG ");
1259 if (ep
->ex_flags
& EX_CHARMAP
)
1260 (void) printf("CHARMAP ");
1261 if (ep
->ex_flags
& EX_LOG_ALLOPS
)
1262 (void) printf("LOG_ALLOPS ");
1263 if (ep
->ex_flags
== 0)
1264 (void) printf("(none)");
1265 (void) printf("\n");
1266 if (ep
->ex_flags
& EX_LOG
) {
1267 (void) printf("\tex_log_buffer = %s\n",
1268 (ep
->ex_log_buffer
? ep
->ex_log_buffer
: "(NULL)"));
1269 (void) printf("\tex_tag = %s\n",
1270 (ep
->ex_tag
? ep
->ex_tag
: "(NULL)"));
1272 (void) printf("\tex_anon = %d\n", ep
->ex_anon
);
1273 (void) printf("\tex_seccnt = %d\n", ep
->ex_seccnt
);
1274 (void) printf("\n");
1275 for (i
= 0; i
< ep
->ex_seccnt
; i
++) {
1276 sp
= &ep
->ex_secinfo
[i
];
1277 (void) printf("\t\ts_secinfo = %s\n", sp
->s_secinfo
.sc_name
);
1278 (void) printf("\t\ts_flags: (0x%02x) ", sp
->s_flags
);
1279 if (sp
->s_flags
& M_ROOT
) (void) printf("M_ROOT ");
1280 if (sp
->s_flags
& M_RO
) (void) printf("M_RO ");
1281 if (sp
->s_flags
& M_ROL
) (void) printf("M_ROL ");
1282 if (sp
->s_flags
& M_RW
) (void) printf("M_RW ");
1283 if (sp
->s_flags
& M_RWL
) (void) printf("M_RWL ");
1284 if (sp
->s_flags
& M_NONE
) (void) printf("M_NONE ");
1285 if (sp
->s_flags
& M_MAP
) (void) printf("M_MAP ");
1286 if (sp
->s_flags
== 0) (void) printf("(none)");
1287 (void) printf("\n");
1288 (void) printf("\t\ts_window = %d\n", sp
->s_window
);
1289 (void) printf("\t\ts_rootid = %d\n", sp
->s_rootid
);
1290 (void) printf("\t\ts_rootcnt = %d ", sp
->s_rootcnt
);
1291 (void) fflush(stdout
);
1292 for (j
= 0; j
< sp
->s_rootcnt
; j
++)
1293 (void) printf("%s ", sp
->s_rootnames
[j
] ?
1294 sp
->s_rootnames
[j
] : "<null>");
1295 (void) printf("\n\n");
1300 * count_security(opts)
1302 * Count the number of security types (flavors). The optionset has
1303 * been populated with the security flavors as a holding mechanism.
1304 * We later use this number to allocate data structures.
1308 count_security(sa_optionset_t opts
)
1313 for (prop
= sa_get_property(opts
, NULL
); prop
!= NULL
;
1314 prop
= sa_get_next_property(prop
)) {
1322 * nfs_sprint_option(rbuff, rbuffsize, incr, prop, sep)
1324 * provides a mechanism to format NFS properties into legacy output
1325 * format. If the buffer would overflow, it is reallocated and grown
1326 * as appropriate. Special cases of converting internal form of values
1327 * to those used by "share" are done. this function does one property
1332 nfs_sprint_option(char **rbuff
, size_t *rbuffsize
, size_t incr
,
1333 sa_property_t prop
, int sep
)
1338 char *buff
= *rbuff
;
1339 size_t buffsize
= *rbuffsize
;
1340 int printed
= B_FALSE
;
1342 name
= sa_get_property_attr(prop
, "type");
1343 value
= sa_get_property_attr(prop
, "value");
1345 curlen
= strlen(buff
);
1350 len
= strlen(name
) + sep
;
1353 * A future RFE would be to replace this with more
1354 * generic code and to possibly handle more types.
1356 switch (gettype(name
)) {
1357 case OPT_TYPE_BOOLEAN
:
1359 * For NFS, boolean value of FALSE means it
1360 * doesn't show up in the option list at all.
1362 if (value
!= NULL
&& strcasecmp(value
, "false") == 0)
1364 if (value
!= NULL
) {
1365 sa_free_attr_string(value
);
1369 case OPT_TYPE_ACCLIST
:
1370 if (value
!= NULL
&& strcmp(value
, "*") == 0) {
1371 sa_free_attr_string(value
);
1375 len
+= 1 + strlen(value
);
1378 case OPT_TYPE_LOGTAG
:
1379 if (value
!= NULL
&& strlen(value
) == 0) {
1380 sa_free_attr_string(value
);
1384 len
+= 1 + strlen(value
);
1389 len
+= 1 + strlen(value
);
1392 while (buffsize
<= (curlen
+ len
)) {
1393 /* need more room */
1395 buff
= realloc(buff
, buffsize
);
1397 /* realloc failed so free everything */
1402 *rbuffsize
= buffsize
;
1411 if (value
== NULL
) {
1412 (void) snprintf(buff
+ curlen
, buffsize
- curlen
,
1413 "%s%s", sep
? "," : "", name
);
1415 (void) snprintf(buff
+ curlen
, buffsize
- curlen
,
1416 "%s%s=%s", sep
? "," : "",
1417 name
, value
!= NULL
? value
: "");
1423 sa_free_attr_string(name
);
1425 sa_free_attr_string(value
);
1430 * nfs_format_options(group, hier)
1432 * format all the options on the group into an old-style option
1433 * string. If hier is non-zero, walk up the tree to get inherited
1438 nfs_format_options(sa_group_t group
, int hier
)
1440 sa_optionset_t options
= NULL
;
1441 sa_optionset_t secoptions
= NULL
;
1442 sa_property_t prop
, secprop
;
1443 sa_security_t security
= NULL
;
1446 char *sectype
= NULL
;
1450 buff
= malloc(OPT_CHUNK
);
1456 buffsize
= OPT_CHUNK
;
1459 * We may have a an optionset relative to this item. format
1460 * these if we find them and then add any security definitions.
1463 options
= sa_get_derived_optionset(group
, "nfs", hier
);
1466 * do the default set first but skip any option that is also
1467 * in the protocol specific optionset.
1469 if (options
!= NULL
) {
1470 for (prop
= sa_get_property(options
, NULL
);
1471 prop
!= NULL
; prop
= sa_get_next_property(prop
)) {
1473 * use this one since we skipped any
1474 * of these that were also in
1477 if (nfs_sprint_option(&buff
, &buffsize
, OPT_CHUNK
,
1482 * buff could become NULL if there
1483 * isn't enough memory for
1484 * nfs_sprint_option to realloc()
1485 * as necessary. We can't really
1486 * do anything about it at this
1487 * point so we return NULL. The
1488 * caller should handle the
1491 if (options
!= NULL
)
1492 sa_free_derived_optionset(
1498 secoptions
= (sa_optionset_t
)sa_get_all_security_types(group
,
1500 if (secoptions
!= NULL
) {
1501 for (secprop
= sa_get_property(secoptions
, NULL
);
1503 secprop
= sa_get_next_property(secprop
)) {
1504 sectype
= sa_get_property_attr(secprop
, "type");
1506 (sa_security_t
)sa_get_derived_security(
1507 group
, sectype
, "nfs", hier
);
1508 if (security
!= NULL
) {
1509 if (sectype
!= NULL
) {
1510 prop
= sa_create_property(
1514 if (nfs_sprint_option(&buff
,
1515 &buffsize
, OPT_CHUNK
, prop
, sep
))
1517 (void) sa_remove_property(prop
);
1521 for (prop
= sa_get_property(security
,
1522 NULL
); prop
!= NULL
;
1523 prop
= sa_get_next_property(prop
)) {
1524 if (nfs_sprint_option(&buff
,
1525 &buffsize
, OPT_CHUNK
, prop
, sep
))
1530 sa_free_derived_optionset(security
);
1532 if (sectype
!= NULL
)
1533 sa_free_attr_string(sectype
);
1535 sa_free_derived_optionset(secoptions
);
1538 if (options
!= NULL
)
1539 sa_free_derived_optionset(options
);
1544 * If we couldn't allocate memory for option printing, we need
1545 * to break out of the nested loops, cleanup and return NULL.
1547 if (secoptions
!= NULL
)
1548 sa_free_derived_optionset(secoptions
);
1549 if (security
!= NULL
)
1550 sa_free_derived_optionset(security
);
1551 if (sectype
!= NULL
)
1552 sa_free_attr_string(sectype
);
1553 if (options
!= NULL
)
1554 sa_free_derived_optionset(options
);
1559 * Append an entry to the nfslogtab file
1562 nfslogtab_add(char *dir
, char *buffer
, char *tag
)
1565 struct logtab_ent lep
;
1569 * Open the file for update and create it if necessary.
1570 * This may leave the I/O offset at the end of the file,
1571 * so rewind back to the beginning of the file.
1573 f
= fopen(NFSLOGTAB
, "a+");
1580 if (lockf(fileno(f
), F_LOCK
, 0L) < 0) {
1581 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
1582 "share complete, however failed to lock %s "
1583 "for update: %s\n"), NFSLOGTAB
, strerror(errno
));
1588 if (logtab_deactivate_after_boot(f
) == -1) {
1589 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
1590 "share complete, however could not deactivate "
1591 "entries in %s\n"), NFSLOGTAB
);
1597 * Remove entries matching buffer and sharepoint since we're
1598 * going to replace it with perhaps an entry with a new tag.
1600 if (logtab_rement(f
, buffer
, dir
, NULL
, -1)) {
1601 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
1602 "share complete, however could not remove matching "
1603 "entries in %s\n"), NFSLOGTAB
);
1609 * Deactivate all active entries matching this sharepoint
1611 if (logtab_deactivate(f
, NULL
, dir
, NULL
)) {
1612 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
1613 "share complete, however could not deactivate matching "
1614 "entries in %s\n"), NFSLOGTAB
);
1619 lep
.le_buffer
= buffer
;
1622 lep
.le_state
= LES_ACTIVE
;
1625 * Add new sharepoint / buffer location to nfslogtab
1627 if (logtab_putent(f
, &lep
) < 0) {
1628 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
1629 "share complete, however could not add %s to %s\n"),
1641 * Deactivate an entry from the nfslogtab file
1644 nfslogtab_deactivate(char *path
)
1649 f
= fopen(NFSLOGTAB
, "r+");
1654 if (lockf(fileno(f
), F_LOCK
, 0L) < 0) {
1656 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
1657 "share complete, however could not lock %s for "
1658 "update: %s\n"), NFSLOGTAB
, strerror(error
));
1661 if (logtab_deactivate(f
, NULL
, path
, NULL
) == -1) {
1663 (void) fprintf(stderr
,
1664 dgettext(TEXT_DOMAIN
,
1665 "share complete, however could not "
1666 "deactivate %s in %s\n"), path
, NFSLOGTAB
);
1677 * check_public(group, skipshare)
1679 * Check the group for any shares that have the public property
1680 * enabled. We skip "skipshare" since that is the one we are
1681 * working with. This is a separate function to make handling
1682 * subgroups simpler. Returns true if there is a share with public.
1685 check_public(sa_group_t group
, sa_share_t skipshare
)
1687 int exists
= B_FALSE
;
1693 for (share
= sa_get_share(group
, NULL
); share
!= NULL
;
1694 share
= sa_get_next_share(share
)) {
1695 if (share
== skipshare
)
1698 opt
= sa_get_optionset(share
, "nfs");
1701 prop
= sa_get_property(opt
, "public");
1704 shared
= sa_get_share_attr(share
, "shared");
1705 if (shared
!= NULL
) {
1706 exists
= strcmp(shared
, "true") == 0;
1707 sa_free_attr_string(shared
);
1708 if (exists
== B_TRUE
)
1717 * public_exists(handle, skipshare)
1719 * check to see if public option is set on any other share than the
1720 * one specified. Need to check zfs sub-groups as well as the top
1724 public_exists(sa_handle_t handle
, sa_share_t skipshare
)
1726 sa_group_t group
= NULL
;
1729 * If we don't have a handle, we can only do syntax check. We
1730 * can't check against other shares so we assume OK and will
1731 * catch the problem only when we actually try to apply it.
1736 if (skipshare
!= NULL
) {
1737 group
= sa_get_parent_group(skipshare
);
1739 return (SA_NO_SUCH_GROUP
);
1742 for (group
= sa_get_group(handle
, NULL
); group
!= NULL
;
1743 group
= sa_get_next_group(group
)) {
1744 /* Walk any ZFS subgroups as well as all standard groups */
1745 if (sa_group_is_zfs(group
)) {
1746 sa_group_t subgroup
;
1747 for (subgroup
= sa_get_sub_group(group
);
1749 subgroup
= sa_get_next_group(subgroup
)) {
1750 if (check_public(subgroup
, skipshare
))
1754 if (check_public(group
, skipshare
))
1762 * sa_enable_share at the protocol level, enable_share must tell the
1763 * implementation that it is to enable the share. This entails
1764 * converting the path and options into the appropriate ioctl
1765 * calls. It is assumed that all error checking of paths, etc. were
1769 nfs_enable_share(sa_share_t share
)
1771 struct exportdata export
;
1772 sa_optionset_t secoptlist
;
1784 /* Don't drop core if the NFS module isn't loaded. */
1785 (void) signal(SIGSYS
, SIG_IGN
);
1787 /* get the path since it is important in several places */
1788 path
= sa_get_share_attr(share
, "path");
1790 return (SA_NO_SUCH_PATH
);
1792 iszfs
= sa_path_is_zfs(path
);
1794 * find the optionsets and security sets. There may not be
1795 * any or there could be one or two for each of optionset and
1796 * security may have multiple, one per security type per
1799 opt
= sa_get_derived_optionset(share
, "nfs", 1);
1800 secoptlist
= (sa_optionset_t
)sa_get_all_security_types(share
, "nfs", 1);
1801 if (secoptlist
!= NULL
)
1802 num_secinfo
= MAX(1, count_security(secoptlist
));
1807 * walk through the options and fill in the structure
1811 (void) memset(&export
, '\0', sizeof (export
));
1814 * do non-security options first since there is only one after
1815 * the derived group is constructed.
1817 export
.ex_version
= EX_CURRENT_VERSION
;
1818 export
.ex_anon
= UID_NOBODY
; /* this is our default value */
1819 export
.ex_index
= NULL
;
1820 export
.ex_path
= path
;
1821 export
.ex_pathlen
= strlen(path
) + 1;
1824 err
= fill_export_from_optionset(&export
, opt
);
1827 * check to see if "public" is set. If it is, then make sure
1828 * no other share has it set. If it is already used, fail.
1831 handle
= sa_find_group_handle((sa_group_t
)share
);
1832 if (export
.ex_flags
& EX_PUBLIC
&& public_exists(handle
, share
)) {
1833 (void) printf(dgettext(TEXT_DOMAIN
,
1834 "NFS: Cannot share more than one file "
1835 "system with 'public' property\n"));
1836 err
= SA_NOT_ALLOWED
;
1840 sp
= calloc(num_secinfo
, sizeof (struct secinfo
));
1843 (void) printf(dgettext(TEXT_DOMAIN
,
1844 "NFS: NFS: no memory for security\n"));
1847 export
.ex_secinfo
= sp
;
1848 /* get default secinfo */
1849 export
.ex_seccnt
= num_secinfo
;
1851 * since we must have one security option defined, we
1852 * init to the default and then override as we find
1853 * defined security options. This handles the case
1854 * where we have no defined options but we need to set
1857 sp
[0].s_window
= DEF_WIN
;
1858 sp
[0].s_rootnames
= NULL
;
1859 /* setup a default in case no properties defined */
1860 if (nfs_getseconfig_default(&sp
[0].s_secinfo
)) {
1861 (void) printf(dgettext(TEXT_DOMAIN
,
1862 "NFS: nfs_getseconfig_default: failed to "
1863 "get default security mode\n"));
1864 err
= SA_CONFIG_ERR
;
1866 if (secoptlist
!= NULL
) {
1867 for (i
= 0, prop
= sa_get_property(secoptlist
, NULL
);
1868 prop
!= NULL
&& i
< num_secinfo
;
1869 prop
= sa_get_next_property(prop
), i
++) {
1871 sectype
= sa_get_property_attr(prop
, "type");
1873 * if sectype is NULL, we probably
1874 * have a memory problem and can't get
1875 * the correct values. Rather than
1876 * exporting with incorrect security,
1879 if (sectype
== NULL
) {
1881 (void) printf(dgettext(TEXT_DOMAIN
,
1882 "NFS: Cannot share %s: "
1883 "no memory\n"), path
);
1886 sec
= (sa_security_t
)sa_get_derived_security(
1887 share
, sectype
, "nfs", 1);
1888 sp
[i
].s_window
= DEF_WIN
;
1889 sp
[i
].s_rootcnt
= 0;
1890 sp
[i
].s_rootnames
= NULL
;
1891 (void) fill_security_from_secopts(&sp
[i
], sec
);
1893 sa_free_derived_security(sec
);
1894 if (sectype
!= NULL
)
1895 sa_free_attr_string(sectype
);
1899 * when we get here, we can do the exportfs system call and
1900 * initiate things. We probably want to enable the
1901 * svc:/network/nfs/server service first if it isn't running.
1903 /* check svc:/network/nfs/server status and start if needed */
1904 /* now add the share to the internal tables */
1905 printarg(path
, &export
);
1907 * call the exportfs system call which is implemented
1908 * via the nfssys() call as the EXPORTFS subfunction.
1911 struct exportfs_args ea
;
1914 priv_set_t
*priv_effective
;
1918 * If we aren't a privileged user
1919 * and NFS server service isn't running
1920 * then print out an error message
1924 priv_effective
= priv_allocset();
1925 (void) getppriv(PRIV_EFFECTIVE
, priv_effective
);
1927 privileged
= (priv_isfullset(priv_effective
) == B_TRUE
);
1928 priv_freeset(priv_effective
);
1931 (str
= smf_get_state(NFS_SERVER_SVC
)) != NULL
) {
1933 if (strcmp(str
, SCF_STATE_STRING_ONLINE
) != 0) {
1934 (void) printf(dgettext(TEXT_DOMAIN
,
1935 "NFS: Cannot share remote "
1936 "filesystem: %s\n"), path
);
1937 (void) printf(dgettext(TEXT_DOMAIN
,
1938 "NFS: Service needs to be enabled "
1939 "by a privileged user\n"));
1940 err
= SA_SYSTEM_ERR
;
1950 (void) sa_sharetab_fill_zfs(share
, &sh
, "nfs");
1951 err
= sa_share_zfs(share
, NULL
, path
, &sh
,
1952 &ea
, ZFS_SHARE_NFS
);
1960 err
= exportfs(path
, &export
);
1964 err
= SA_SYSTEM_ERR
;
1967 (void) printf(dgettext(TEXT_DOMAIN
,
1968 "NFS: Cannot share filesystems "
1969 "in non-global zones: %s\n"), path
);
1970 err
= SA_NOT_SUPPORTED
;
1973 if (getzoneid() != GLOBAL_ZONEID
) {
1974 (void) printf(dgettext(TEXT_DOMAIN
,
1975 "NFS: Cannot share file systems "
1976 "in non-global zones: %s\n"), path
);
1977 err
= SA_NOT_SUPPORTED
;
1980 err
= SA_NO_PERMISSION
;
1983 err
= SA_SHARE_EXISTS
;
1989 /* update sharetab with an add/modify */
1991 (void) sa_update_sharetab(share
, "nfs");
1997 * enable services as needed. This should probably be
1998 * done elsewhere in order to minimize the calls to
2002 * check to see if logging and other services need to
2003 * be triggered, but only if there wasn't an
2004 * error. This is probably where sharetab should be
2005 * updated with the NFS specific entry.
2007 if (export
.ex_flags
& EX_LOG
) {
2008 /* enable logging */
2009 if (nfslogtab_add(path
, export
.ex_log_buffer
,
2010 export
.ex_tag
) != 0) {
2011 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
2012 "Could not enable logging for %s\n"),
2015 _check_services(service_list_logging
);
2018 * don't have logging so remove it from file. It might
2019 * not be thre, but that doesn't matter.
2021 (void) nfslogtab_deactivate(path
);
2022 _check_services(service_list_default
);
2030 cleanup_export(&export
);
2032 sa_free_derived_optionset(opt
);
2033 if (secoptlist
!= NULL
)
2034 (void) sa_destroy_optionset(secoptlist
);
2039 * nfs_disable_share(share, path)
2041 * Unshare the specified share. Note that "path" is the same path as
2042 * what is in the "share" object. It is passed in to avoid an
2043 * additional lookup. A missing "path" value makes this a no-op
2047 nfs_disable_share(sa_share_t share
, char *path
)
2059 * If the share is in a ZFS group we need to handle it
2060 * differently. Just being on a ZFS file system isn't
2061 * enough since we may be in a legacy share case.
2063 parent
= sa_get_parent_group(share
);
2064 iszfs
= sa_group_is_zfs(parent
);
2066 struct exportfs_args ea
;
2071 sh
.sh_fstype
= "nfs";
2073 err
= sa_share_zfs(share
, NULL
, path
, &sh
,
2074 &ea
, ZFS_UNSHARE_NFS
);
2080 err
= exportfs(path
, NULL
);
2084 * TBD: only an error in some
2085 * cases - need better analysis
2090 ret
= SA_NO_PERMISSION
;
2091 if (getzoneid() != GLOBAL_ZONEID
) {
2092 ret
= SA_NOT_SUPPORTED
;
2097 ret
= SA_NO_SUCH_PATH
;
2100 ret
= SA_SYSTEM_ERR
;
2104 if (ret
== SA_OK
|| ret
== SA_NO_SUCH_PATH
) {
2105 handle
= sa_find_group_handle((sa_group_t
)share
);
2107 (void) sa_delete_sharetab(handle
, path
, "nfs");
2108 /* just in case it was logged */
2109 (void) nfslogtab_deactivate(path
);
2115 check_user(char *value
)
2119 if (!is_a_number(value
)) {
2122 * in this case it would have to be a
2125 pw
= getpwnam(value
);
2131 intval
= strtoull(value
, NULL
, 0);
2132 if (intval
> UID_MAX
&& intval
!= -1)
2140 check_group(char *value
)
2144 if (!is_a_number(value
)) {
2147 * in this case it would have to be a
2150 gr
= getgrnam(value
);
2156 intval
= strtoull(value
, NULL
, 0);
2157 if (intval
> UID_MAX
&& intval
!= -1)
2165 * check_rorwnone(v1, v2, v3)
2167 * check ro vs rw vs none values. Over time this may get beefed up.
2168 * for now it just does simple checks. v1 is never NULL but v2 or v3
2173 check_rorwnone(char *v1
, char *v2
, char *v3
)
2176 if (v2
!= NULL
&& strcmp(v1
, v2
) == 0)
2177 ret
= SA_VALUE_CONFLICT
;
2178 else if (v3
!= NULL
&& strcmp(v1
, v3
) == 0)
2179 ret
= SA_VALUE_CONFLICT
;
2185 * nfs_validate_property(handle, property, parent)
2187 * Check that the property has a legitimate value for its type.
2191 nfs_validate_property(sa_handle_t handle
, sa_property_t property
,
2192 sa_optionset_t parent
)
2199 nfsl_config_t
*configlist
;
2200 sa_group_t parent_group
;
2203 propname
= sa_get_property_attr(property
, "type");
2205 if ((optindex
= findopt(propname
)) < 0)
2206 ret
= SA_NO_SUCH_PROP
;
2208 /* need to validate value range here as well */
2211 parent_group
= sa_get_parent_group((sa_share_t
)parent
);
2212 if (optdefs
[optindex
].share
&& parent_group
!= NULL
&&
2213 !sa_is_share(parent_group
))
2214 ret
= SA_PROP_SHARE_ONLY
;
2217 if (optdefs
[optindex
].index
== OPT_PUBLIC
) {
2219 * Public is special in that only one instance can
2220 * be in the repository at the same time.
2222 if (public_exists(handle
, parent_group
)) {
2223 sa_free_attr_string(propname
);
2224 return (SA_VALUE_CONFLICT
);
2227 value
= sa_get_property_attr(property
, "value");
2228 if (value
!= NULL
) {
2229 /* first basic type checking */
2230 switch (optdefs
[optindex
].type
) {
2232 case OPT_TYPE_NUMBER
:
2233 /* check that the value is all digits */
2234 if (!is_a_number(value
))
2238 case OPT_TYPE_BOOLEAN
:
2239 if (strlen(value
) == 0 ||
2240 strcasecmp(value
, "true") == 0 ||
2241 strcmp(value
, "1") == 0 ||
2242 strcasecmp(value
, "false") == 0 ||
2243 strcmp(value
, "0") == 0) {
2251 ret
= check_user(value
);
2255 if (strcmp(value
, "..") == 0 ||
2256 strchr(value
, '/') != NULL
) {
2261 case OPT_TYPE_ACCLIST
: {
2262 sa_property_t oprop1
;
2263 sa_property_t oprop2
;
2264 char *ovalue1
= NULL
;
2265 char *ovalue2
= NULL
;
2270 * access list handling. Should eventually
2271 * validate that all the values make sense.
2272 * Also, ro and rw may have cross value
2275 if (strcmp(propname
, SHOPT_RO
) == 0) {
2277 other2
= SHOPT_NONE
;
2278 } else if (strcmp(propname
, SHOPT_RW
) == 0) {
2280 other2
= SHOPT_NONE
;
2281 } else if (strcmp(propname
, SHOPT_NONE
) == 0) {
2288 if (other1
== NULL
&& other2
== NULL
)
2291 /* compare rw(ro) with ro(rw) */
2293 oprop1
= sa_get_property(parent
, other1
);
2294 oprop2
= sa_get_property(parent
, other2
);
2295 if (oprop1
== NULL
&& oprop2
== NULL
)
2298 * Only potential confusion if other1
2299 * or other2 exists. Check the values
2300 * and run the check if there is a
2301 * value other than the one we are
2302 * explicitly looking at.
2304 ovalue1
= sa_get_property_attr(oprop1
, "value");
2305 ovalue2
= sa_get_property_attr(oprop2
, "value");
2306 if (ovalue1
!= NULL
|| ovalue2
!= NULL
)
2307 ret
= check_rorwnone(value
, ovalue1
,
2310 if (ovalue1
!= NULL
)
2311 sa_free_attr_string(ovalue1
);
2312 if (ovalue2
!= NULL
)
2313 sa_free_attr_string(ovalue2
);
2317 case OPT_TYPE_LOGTAG
:
2318 if (nfsl_getconfig_list(&configlist
) == 0) {
2320 if (value
== NULL
||
2321 strlen(value
) == 0) {
2323 sa_free_attr_string(
2325 value
= strdup("global");
2327 if (value
!= NULL
&&
2328 nfsl_findconfig(configlist
, value
,
2332 /* Must always free when done */
2333 nfsl_freeconfig_list(&configlist
);
2335 ret
= SA_CONFIG_ERR
;
2339 case OPT_TYPE_STRING
:
2340 /* whatever is here should be ok */
2343 case OPT_TYPE_SECURITY
:
2345 * The "sec" property isn't used in the
2346 * non-legacy parts of sharemgr. We need to
2347 * reject it here. For legacy, it is pulled
2348 * out well before we get here.
2350 ret
= SA_NO_SUCH_PROP
;
2353 case OPT_TYPE_MAPPING
: {
2359 sa_security_t security
;
2362 * mapping is only supported for sec=sys
2364 ret
= SA_CONFIG_ERR
;
2365 if (parent_group
== NULL
)
2368 for (security
= sa_get_security(parent_group
,
2369 NULL
, NULL
); security
!= NULL
;
2370 security
= sa_get_next_security(security
)) {
2374 type
= sa_get_security_attr(security
,
2379 if (strcmp(type
, "nfs") != 0) {
2380 sa_free_attr_string(type
);
2383 sa_free_attr_string(type
);
2385 sectype
= sa_get_security_attr(security
,
2387 if (sectype
== NULL
)
2390 if (strcmp(sectype
, "sys") != 0) {
2391 sa_free_attr_string(sectype
);
2392 ret
= SA_CONFIG_ERR
;
2395 sa_free_attr_string(sectype
);
2402 assert(optindex
== OPT_UIDMAP
||
2403 optindex
== OPT_GIDMAP
);
2404 f
= optindex
== OPT_UIDMAP
? check_user
:
2412 for (c
= p
; ret
== SA_OK
&& c
!= NULL
; c
= n
) {
2428 if (s
== NULL
|| t
== NULL
)
2431 if (ret
== SA_OK
&& *c
!= '\0' &&
2432 strcmp(c
, "*") != 0)
2435 if (ret
== SA_OK
&& *s
!= '\0' &&
2436 strcmp(s
, "-1") != 0)
2450 sa_free_attr_string(value
);
2452 if (ret
== SA_OK
&& optdefs
[optindex
].check
!= NULL
) {
2453 /* do the property specific check */
2454 ret
= optdefs
[optindex
].check(handle
, property
);
2459 if (propname
!= NULL
)
2460 sa_free_attr_string(propname
);
2465 * Protocol management functions
2467 * Properties defined in the default files are defined in
2468 * proto_option_defs for parsing and validation. If "other" and
2469 * "compare" are set, then the value for this property should be
2470 * compared against the property specified in "other" using the
2471 * "compare" check (either <= or >=) in order to ensure that the
2472 * values are in the correct range. E.g. setting server_versmin
2473 * higher than server_versmax should not be allowed.
2476 struct proto_option_defs
{
2478 char *name
; /* display name -- remove protocol identifier */
2490 #define OPT_CMP_GE 0
2491 #define OPT_CMP_LE 1
2492 int (*check
)(char *);
2493 } proto_options
[] = {
2494 #define PROTO_OPT_NFSD_SERVERS 0
2496 "servers", PROTO_OPT_NFSD_SERVERS
, OPT_TYPE_NUMBER
, 1024, SVC_NFSD
,
2498 #define PROTO_OPT_LOCKD_LISTEN_BACKLOG 1
2499 {"lockd_listen_backlog",
2500 "lockd_listen_backlog", PROTO_OPT_LOCKD_LISTEN_BACKLOG
,
2501 OPT_TYPE_NUMBER
, 32, SVC_LOCKD
, 32, INT32_MAX
},
2502 #define PROTO_OPT_LOCKD_SERVERS 2
2504 "lockd_servers", PROTO_OPT_LOCKD_SERVERS
, OPT_TYPE_NUMBER
, 256,
2505 SVC_LOCKD
, 1, INT32_MAX
},
2506 #define PROTO_OPT_LOCKD_RETRANSMIT_TIMEOUT 3
2507 {"lockd_retransmit_timeout",
2508 "lockd_retransmit_timeout", PROTO_OPT_LOCKD_RETRANSMIT_TIMEOUT
,
2509 OPT_TYPE_NUMBER
, 5, SVC_LOCKD
, 0, INT32_MAX
},
2510 #define PROTO_OPT_GRACE_PERIOD 4
2512 "grace_period", PROTO_OPT_GRACE_PERIOD
, OPT_TYPE_NUMBER
, 90,
2513 SVC_LOCKD
, 0, INT32_MAX
},
2514 #define PROTO_OPT_NFS_SERVER_VERSMIN 5
2515 {"nfs_server_versmin",
2516 "server_versmin", PROTO_OPT_NFS_SERVER_VERSMIN
, OPT_TYPE_NUMBER
,
2517 (int)NFS_VERSMIN_DEFAULT
, SVC_NFSD
|SVC_MOUNTD
, NFS_VERSMIN
,
2518 NFS_VERSMAX
, "server_versmax", OPT_CMP_LE
},
2519 #define PROTO_OPT_NFS_SERVER_VERSMAX 6
2520 {"nfs_server_versmax",
2521 "server_versmax", PROTO_OPT_NFS_SERVER_VERSMAX
, OPT_TYPE_NUMBER
,
2522 (int)NFS_VERSMAX_DEFAULT
, SVC_NFSD
|SVC_MOUNTD
, NFS_VERSMIN
,
2523 NFS_VERSMAX
, "server_versmin", OPT_CMP_GE
},
2524 #define PROTO_OPT_NFS_CLIENT_VERSMIN 7
2525 {"nfs_client_versmin",
2526 "client_versmin", PROTO_OPT_NFS_CLIENT_VERSMIN
, OPT_TYPE_NUMBER
,
2527 (int)NFS_VERSMIN_DEFAULT
, SVC_CLIENT
, NFS_VERSMIN
, NFS_VERSMAX
,
2528 "client_versmax", OPT_CMP_LE
},
2529 #define PROTO_OPT_NFS_CLIENT_VERSMAX 8
2530 {"nfs_client_versmax",
2531 "client_versmax", PROTO_OPT_NFS_CLIENT_VERSMAX
, OPT_TYPE_NUMBER
,
2532 (int)NFS_VERSMAX_DEFAULT
, SVC_CLIENT
, NFS_VERSMIN
, NFS_VERSMAX
,
2533 "client_versmin", OPT_CMP_GE
},
2534 #define PROTO_OPT_NFS_SERVER_DELEGATION 9
2535 {"nfs_server_delegation",
2536 "server_delegation", PROTO_OPT_NFS_SERVER_DELEGATION
,
2537 OPT_TYPE_ONOFF
, NFS_SERVER_DELEGATION_DEFAULT
, SVC_NFSD
, 0, 0},
2538 #define PROTO_OPT_NFSMAPID_DOMAIN 10
2540 "nfsmapid_domain", PROTO_OPT_NFSMAPID_DOMAIN
, OPT_TYPE_DOMAIN
,
2541 NULL
, SVC_NFSMAPID
, 0, 0},
2542 #define PROTO_OPT_NFSD_MAX_CONNECTIONS 11
2543 {"nfsd_max_connections",
2544 "max_connections", PROTO_OPT_NFSD_MAX_CONNECTIONS
,
2545 OPT_TYPE_NUMBER
, -1, SVC_NFSD
, -1, INT32_MAX
},
2546 #define PROTO_OPT_NFSD_PROTOCOL 12
2548 "protocol", PROTO_OPT_NFSD_PROTOCOL
, OPT_TYPE_PROTOCOL
, 0,
2550 #define PROTO_OPT_NFSD_LISTEN_BACKLOG 13
2551 {"nfsd_listen_backlog",
2552 "listen_backlog", PROTO_OPT_NFSD_LISTEN_BACKLOG
,
2553 OPT_TYPE_NUMBER
, 0, SVC_NFSD
, 0, INT32_MAX
},
2554 #define PROTO_OPT_NFSD_DEVICE 14
2556 "device", PROTO_OPT_NFSD_DEVICE
,
2557 OPT_TYPE_STRING
, NULL
, SVC_NFSD
, 0, 0},
2558 #define PROTO_OPT_MOUNTD_LISTEN_BACKLOG 15
2559 {"mountd_listen_backlog",
2560 "mountd_listen_backlog", PROTO_OPT_MOUNTD_LISTEN_BACKLOG
,
2561 OPT_TYPE_NUMBER
, 64, SVC_NFSD
|SVC_MOUNTD
, 1, INT32_MAX
},
2562 #define PROTO_OPT_MOUNTD_MAX_THREADS 16
2563 {"mountd_max_threads",
2564 "mountd_max_threads", PROTO_OPT_MOUNTD_MAX_THREADS
,
2565 OPT_TYPE_NUMBER
, 16, SVC_NFSD
|SVC_MOUNTD
, 1, INT32_MAX
},
2566 #define PROTO_OPT_MOUNTD_PORT 17
2568 "mountd_port", PROTO_OPT_MOUNTD_PORT
,
2569 OPT_TYPE_NUMBER
, 0, SVC_MOUNTD
, 1, UINT16_MAX
},
2570 #define PROTO_OPT_STATD_PORT 18
2572 "statd_port", PROTO_OPT_STATD_PORT
,
2573 OPT_TYPE_NUMBER
, 0, SVC_STATD
, 1, UINT16_MAX
},
2578 * the protoset holds the defined options so we don't have to read
2579 * them multiple times
2581 static sa_protocol_properties_t protoset
;
2584 findprotoopt(char *name
, int whichname
)
2587 for (i
= 0; proto_options
[i
].tag
!= NULL
; i
++) {
2588 if (whichname
== 1) {
2589 if (strcasecmp(proto_options
[i
].name
, name
) == 0)
2592 if (strcasecmp(proto_options
[i
].tag
, name
) == 0)
2602 * convert a string to lower case (inplace).
2606 fixcaselower(char *str
)
2609 *str
= tolower(*str
);
2615 * skipwhitespace(str)
2617 * Skip leading white space. It is assumed that it is called with a
2622 skipwhitespace(char *str
)
2624 while (*str
&& isspace(*str
))
2633 * Extract the property and value out of the line and create the
2634 * property in the optionset.
2637 extractprop(char *name
, char *value
)
2643 * Remove any leading
2646 name
= skipwhitespace(name
);
2648 index
= findprotoopt(name
, 1);
2651 prop
= sa_create_property(proto_options
[index
].name
, value
);
2653 ret
= sa_add_protocol_property(protoset
, prop
);
2661 getscftype(int type
)
2666 case OPT_TYPE_NUMBER
:
2667 ret
= SCF_TYPE_INTEGER
;
2669 case OPT_TYPE_BOOLEAN
:
2670 ret
= SCF_TYPE_BOOLEAN
;
2673 ret
= SCF_TYPE_ASTRING
;
2679 getsvcname(uint32_t svcs
)
2693 service
= NFS_CLIENT_SVC
;
2717 * initprotofromsmf()
2719 * Read NFS SMF properties and add the defined values to the
2720 * protoset. Note that default values are known from the built in
2721 * table in case SMF doesn't have a definition. Not having
2722 * SMF properties is OK since we have builtin default
2728 char name
[PATH_MAX
];
2729 char value
[PATH_MAX
];
2730 int ret
= SA_OK
, bufsz
= 0, i
;
2732 protoset
= sa_create_protocol_properties("nfs");
2733 if (protoset
!= NULL
) {
2734 for (i
= 0; proto_options
[i
].tag
!= NULL
; i
++) {
2738 bzero(value
, PATH_MAX
);
2739 (void) strncpy(name
, proto_options
[i
].name
, PATH_MAX
);
2740 /* Replace NULL with the correct instance */
2741 ptype
= getscftype(proto_options
[i
].type
);
2742 svc_name
= getsvcname(proto_options
[i
].svcs
);
2744 ret
= nfs_smf_get_prop(name
, value
,
2745 (char *)DEFAULT_INSTANCE
, ptype
,
2748 ret
= extractprop(name
, value
);
2761 * Add the default values for any property not defined
2762 * in NFS SMF repository.
2763 * Values are set according to their defined types.
2770 char number
[MAXDIGITS
];
2772 for (i
= 0; proto_options
[i
].tag
!= NULL
; i
++) {
2774 prop
= sa_get_protocol_property(protoset
,
2775 proto_options
[i
].name
);
2777 /* add the default value */
2778 switch (proto_options
[i
].type
) {
2779 case OPT_TYPE_NUMBER
:
2780 (void) snprintf(number
, sizeof (number
), "%d",
2781 proto_options
[i
].defvalue
.intval
);
2782 prop
= sa_create_property(proto_options
[i
].name
,
2786 case OPT_TYPE_BOOLEAN
:
2787 prop
= sa_create_property(proto_options
[i
].name
,
2788 proto_options
[i
].defvalue
.intval
?
2792 case OPT_TYPE_ONOFF
:
2793 prop
= sa_create_property(proto_options
[i
].name
,
2794 proto_options
[i
].defvalue
.intval
?
2799 /* treat as strings of zero length */
2800 prop
= sa_create_property(proto_options
[i
].name
,
2805 (void) sa_add_protocol_property(protoset
, prop
);
2813 if (protoset
!= NULL
) {
2814 xmlFreeNode(protoset
);
2822 * Initialize the NFS plugin.
2830 if (sa_plugin_ops
.sa_init
!= nfs_init
) {
2831 (void) printf(dgettext(TEXT_DOMAIN
,
2832 "NFS plugin not properly initialized\n"));
2833 return (SA_CONFIG_ERR
);
2836 ret
= initprotofromsmf();
2838 (void) printf(dgettext(TEXT_DOMAIN
,
2839 "NFS plugin problem with SMF repository: %s\n"),
2851 * uninitialize the NFS plugin. Want to avoid memory leaks.
2861 * nfs_get_proto_set()
2863 * Return an optionset with all the protocol specific properties in
2867 static sa_protocol_properties_t
2874 * service_in_state(service, chkstate)
2876 * Want to know if the specified service is in the desired state
2877 * (chkstate) or not. Return true (1) if it is and false (0) if it
2881 service_in_state(char *service
, const char *chkstate
)
2886 state
= smf_get_state(service
);
2887 if (state
!= NULL
) {
2888 /* got the state so get the equality for the return value */
2889 ret
= strcmp(state
, chkstate
) == 0 ? B_TRUE
: B_FALSE
;
2896 * restart_service(svcs)
2898 * Walk through the bit mask of services that need to be restarted in
2899 * order to use the new property values. Some properties affect
2900 * multiple daemons. Should only restart a service if it is currently
2905 restart_service(uint32_t svcs
)
2911 for (mask
= 1; svcs
!= 0; mask
<<= 1) {
2912 switch (svcs
& mask
) {
2941 service
= NFS_CLIENT_SVC
;
2948 * Only attempt to restart the service if it is
2949 * currently running. In the future, it may be
2950 * desirable to use smf_refresh_instance if the NFS
2951 * services ever implement the refresh method.
2953 if (service_in_state(service
, SCF_STATE_STRING_ONLINE
)) {
2954 ret
= smf_restart_instance(service
);
2956 * There are only a few SMF errors at this point, but
2957 * it is also possible that a bad value may have put
2958 * the service into maintenance if there wasn't an
2962 (void) fprintf(stderr
,
2963 dgettext(TEXT_DOMAIN
,
2964 "%s failed to restart: %s\n"),
2965 service
, scf_strerror(scf_error()));
2968 * Check whether it has gone to "maintenance"
2969 * mode or not. Maintenance implies something
2972 if (service_in_state(service
,
2973 SCF_STATE_STRING_MAINT
)) {
2974 (void) fprintf(stderr
,
2975 dgettext(TEXT_DOMAIN
,
2976 "%s failed to restart\n"),
2986 * nfs_minmax_check(name, value)
2988 * Verify that the value for the property specified by index is valid
2989 * relative to the opposite value in the case of a min/max variable.
2990 * Currently, server_minvers/server_maxvers and
2991 * client_minvers/client_maxvers are the only ones to check.
2995 nfs_minmax_check(int index
, int value
)
3000 sa_optionset_t opts
;
3003 if (proto_options
[index
].other
!= NULL
) {
3004 /* have a property to compare against */
3005 opts
= nfs_get_proto_set();
3006 prop
= sa_get_property(opts
, proto_options
[index
].other
);
3008 * If we don't find the property, assume default
3009 * values which will work since the max will be at the
3010 * max and the min at the min.
3013 pval
= sa_get_property_attr(prop
, "value");
3015 val
= strtoul(pval
, NULL
, 0);
3016 if (proto_options
[index
].compare
==
3018 ret
= value
<= val
? B_TRUE
: B_FALSE
;
3019 } else if (proto_options
[index
].compare
==
3021 ret
= value
>= val
? B_TRUE
: B_FALSE
;
3023 sa_free_attr_string(pval
);
3031 * nfs_validate_proto_prop(index, name, value)
3033 * Verify that the property specified by name can take the new
3034 * value. This is a sanity check to prevent bad values getting into
3035 * the default files. All values need to be checked against what is
3036 * allowed by their defined type. If a type isn't explicitly defined
3037 * here, it is treated as a string.
3039 * Note that OPT_TYPE_NUMBER will additionally check that the value is
3040 * within the range specified and potentially against another property
3041 * value as well as specified in the proto_options members other and
3046 nfs_validate_proto_prop(int index
, char *name
, char *value
)
3053 switch (proto_options
[index
].type
) {
3054 case OPT_TYPE_NUMBER
:
3055 if (!is_a_number(value
))
3059 val
= strtoul(value
, NULL
, 0);
3060 if (val
< proto_options
[index
].minval
||
3061 val
> proto_options
[index
].maxval
)
3064 * For server_versmin/server_versmax and
3065 * client_versmin/client_versmax, the value of the
3066 * min(max) should be checked to be correct relative
3067 * to the current max(min).
3069 if (!nfs_minmax_check(index
, val
)) {
3075 case OPT_TYPE_DOMAIN
:
3077 * needs to be a qualified domain so will have at
3078 * least one period and other characters on either
3079 * side of it. A zero length string is also allowed
3080 * and is the way to turn off the override.
3082 if (strlen(value
) == 0)
3084 cp
= strchr(value
, '.');
3085 if (cp
== NULL
|| cp
== value
|| strchr(value
, '@') != NULL
)
3089 case OPT_TYPE_BOOLEAN
:
3090 if (strlen(value
) == 0 ||
3091 strcasecmp(value
, "true") == 0 ||
3092 strcmp(value
, "1") == 0 ||
3093 strcasecmp(value
, "false") == 0 ||
3094 strcmp(value
, "0") == 0) {
3101 case OPT_TYPE_ONOFF
:
3102 if (strcasecmp(value
, "on") != 0 &&
3103 strcasecmp(value
, "off") != 0) {
3108 case OPT_TYPE_PROTOCOL
: {
3109 struct netconfig
*nconf
;
3111 boolean_t pfound
= B_FALSE
;
3113 if (strcasecmp(value
, "all") == 0)
3116 if ((nc
= setnetconfig()) == NULL
) {
3117 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
3118 "setnetconfig failed: %s\n"), strerror(errno
));
3120 while ((nconf
= getnetconfig(nc
)) != NULL
) {
3121 if (strcmp(nconf
->nc_proto
, value
) == 0) {
3126 (void) endnetconfig(nc
);
3135 /* treat as a string */
3142 * nfs_set_proto_prop(prop)
3144 * check that prop is valid.
3148 nfs_set_proto_prop(sa_property_t prop
)
3154 name
= sa_get_property_attr(prop
, "type");
3155 value
= sa_get_property_attr(prop
, "value");
3156 if (name
!= NULL
&& value
!= NULL
) {
3159 char *instance
= NULL
;
3160 int index
= findprotoopt(name
, 1);
3162 ret
= nfs_validate_proto_prop(index
, name
, value
);
3164 sctype
= getscftype(proto_options
[index
].type
);
3165 svc_name
= getsvcname(proto_options
[index
].svcs
);
3166 if (sctype
== SCF_TYPE_BOOLEAN
) {
3168 sa_free_attr_string(value
);
3169 if (string_to_boolean(value
) == 0)
3170 value
= strdup("0");
3172 value
= strdup("1");
3174 ret
= nfs_smf_set_prop(name
, value
, instance
, sctype
,
3177 restart_service(proto_options
[index
].svcs
);
3179 (void) printf(dgettext(TEXT_DOMAIN
,
3180 "Cannot restart NFS services : %s\n"),
3186 sa_free_attr_string(name
);
3188 sa_free_attr_string(value
);
3195 * What is the current status of the nfsd? We use the SMF state here.
3196 * Caller must free the returned value.
3202 return (smf_get_state(NFSD
));
3206 * nfs_space_alias(alias)
3208 * Lookup the space (security) name. If it is default, convert to the
3213 nfs_space_alias(char *space
)
3219 * Only the space named "default" is special. If it is used,
3220 * the default needs to be looked up and the real name used.
3221 * This is normally "sys" but could be changed. We always
3222 * change default to the real name.
3224 if (strcmp(space
, "default") == 0 &&
3225 nfs_getseconfig_default(&secconf
) == 0) {
3226 if (nfs_getseconfig_bynumber(secconf
.sc_nfsnum
, &secconf
) == 0)
3227 name
= secconf
.sc_name
;
3229 return (strdup(name
));
3235 * Return a mask of the features required.
3241 return ((uint64_t)SA_FEATURE_DFSTAB
| SA_FEATURE_SERVER
);