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.
28 * 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
);
606 * nfs_parse_legacy_options(group, options)
608 * Parse the old style options into internal format and store on the
609 * specified group. Group could be a share for full legacy support.
613 nfs_parse_legacy_options(sa_group_t group
, char *options
)
618 sa_optionset_t optionset
;
619 struct securities
*security_list
= NULL
;
627 /* do we have an existing optionset? */
628 optionset
= sa_get_optionset(group
, "nfs");
629 if (optionset
== NULL
) {
630 /* didn't find existing optionset so create one */
631 optionset
= sa_create_optionset(group
, "nfs");
634 * Have an existing optionset . Ideally, we would need
635 * to compare options in order to detect errors. For
636 * now, we assume that the first optionset is the
637 * correct one and the others will be the same. An
638 * empty optionset is the same as no optionset so we
639 * don't want to exit in that case. Getting an empty
640 * optionset can occur with ZFS property checking.
642 if (sa_get_property(optionset
, NULL
) != NULL
)
646 if (strcmp(options
, SHOPT_RW
) == 0) {
648 * there is a special case of only the option "rw"
649 * being the default option. We don't have to do
656 * check if security types are present and validate them. If
657 * any are not legal, fail.
660 if (invalid_security(options
)) {
661 return (SA_INVALID_SECURITY
);
665 * in order to not attempt to change ZFS properties unless
666 * absolutely necessary, we never do it in the legacy parsing.
668 if (sa_is_share(group
)) {
670 parent
= sa_get_parent_group(group
);
671 if (parent
!= NULL
) {
672 zfs
= sa_get_group_attr(parent
, "zfs");
674 sa_free_attr_string(zfs
);
679 iszfs
= sa_group_is_zfs(group
);
682 /* We need a copy of options for the next part. */
683 dup
= strdup(options
);
685 return (SA_NO_MEMORY
);
688 * we need to step through each option in the string and then
689 * add either the option or the security option as needed. If
690 * this is not a persistent share, don't commit to the
691 * repository. If there is an error, we also want to abort the
692 * processing and report it.
694 persist
= is_persistent(group
);
698 while (token
!= NULL
&& ret
== SA_OK
) {
699 token
= strtok_r(base
, ",", &lasts
);
704 * if the option has a value, it will have an '=' to
705 * separate the name from the value. The following
706 * code will result in value != NULL and token
707 * pointing to just the name if there is a value.
709 value
= strchr(token
, '=');
713 if (strcmp(token
, SHOPT_SEC
) == 0 ||
714 strcmp(token
, SHOPT_SECURE
) == 0) {
716 * Once in security parsing, we only
717 * do security. We do need to move
718 * between the security node and the
719 * toplevel. The security tag goes on
720 * the root while the following ones
721 * go on the security.
723 if (security_list
!= NULL
) {
725 * have an old list so close it and
728 free_security_list(security_list
);
730 if (strcmp(token
, SHOPT_SECURE
) == 0) {
738 security_list
= make_security_list(group
,
742 * Note that the "old" syntax allowed a
743 * default security model. This must be
744 * accounted for and internally converted to
745 * "standard" security structure.
747 if (nfs_is_security_opt(token
)) {
748 if (security_list
== NULL
) {
763 make_security_list(group
,
767 if (security_list
!= NULL
) {
768 ret
= add_security_prop(
769 security_list
, token
,
770 value
, persist
, iszfs
);
775 /* regular options */
777 if (strcmp(token
, SHOPT_RW
) ==
790 * In all cases, create the
791 * property specified. If the
792 * value was NULL, the default
793 * value will have been
796 prop
= sa_create_property(token
, value
);
797 ret
= sa_add_property(optionset
, prop
);
802 ret
= sa_commit_properties(
803 optionset
, !persist
);
809 if (security_list
!= NULL
)
810 free_security_list(security_list
);
817 * is_a_number(number)
819 * is the string a number in one of the forms we want to use?
823 is_a_number(char *number
)
828 if (strncmp(number
, "0x", 2) == 0) {
831 } else if (*number
== '-') {
832 number
++; /* skip the minus */
834 while (ret
== 1 && *number
!= '\0') {
836 ret
= isxdigit(*number
++);
838 ret
= isdigit(*number
++);
845 * Look for the specified tag in the configuration file. If it is found,
846 * enable logging and set the logging configuration information for exp.
849 configlog(struct exportdata
*exp
, char *tag
)
851 nfsl_config_t
*configlist
= NULL
, *configp
;
853 char globaltag
[] = DEFAULTTAG
;
856 * Sends config errors to stderr
858 nfsl_errs_to_syslog
= B_FALSE
;
861 * get the list of configuration settings
863 error
= nfsl_getconfig_list(&configlist
);
865 (void) fprintf(stderr
,
866 dgettext(TEXT_DOMAIN
, "Cannot get log configuration: %s\n"),
872 if ((configp
= nfsl_findconfig(configlist
, tag
, &error
)) == NULL
) {
873 nfsl_freeconfig_list(&configlist
);
874 (void) fprintf(stderr
,
875 dgettext(TEXT_DOMAIN
, "No tags matching \"%s\"\n"), tag
);
876 /* bad configuration */
881 if ((exp
->ex_tag
= strdup(tag
)) == NULL
) {
885 if ((exp
->ex_log_buffer
= strdup(configp
->nc_bufferpath
)) == NULL
) {
889 exp
->ex_flags
|= EX_LOG
;
890 if (configp
->nc_rpclogpath
!= NULL
)
891 exp
->ex_flags
|= EX_LOG_ALLOPS
;
893 if (configlist
!= NULL
)
894 nfsl_freeconfig_list(&configlist
);
899 free(exp
->ex_log_buffer
);
900 (void) fprintf(stderr
,
901 dgettext(TEXT_DOMAIN
, "Cannot set log configuration: %s\n"),
907 * fill_export_from_optionset(export, optionset)
909 * In order to share, we need to set all the possible general options
910 * into the export structure. Share info will be filled in by the
911 * caller. Various property values get turned into structure specific
916 fill_export_from_optionset(struct exportdata
*export
, sa_optionset_t optionset
)
918 sa_property_t option
;
921 for (option
= sa_get_property(optionset
, NULL
);
922 option
!= NULL
; option
= sa_get_next_property(option
)) {
928 * since options may be set/reset multiple times, always do an
929 * explicit set or clear of the option. This allows defaults
930 * to be set and then the protocol specific to override.
933 name
= sa_get_property_attr(option
, "type");
934 value
= sa_get_property_attr(option
, "value");
935 switch (findopt(name
)) {
937 if (value
!= NULL
&& is_a_number(value
)) {
938 val
= strtoul(value
, NULL
, 0);
941 pw
= getpwnam(value
!= NULL
? value
: "nobody");
949 export
->ex_anon
= val
;
952 if (value
!= NULL
&& (strcasecmp(value
, "true") == 0 ||
953 strcmp(value
, "1") == 0))
954 export
->ex_flags
|= EX_NOSUID
;
956 export
->ex_flags
&= ~EX_NOSUID
;
959 if (value
!= NULL
&& (strcasecmp(value
, "true") == 0 ||
960 strcmp(value
, "1") == 0))
961 export
->ex_flags
|= EX_ACLOK
;
963 export
->ex_flags
&= ~EX_ACLOK
;
966 if (value
!= NULL
&& (strcasecmp(value
, "true") == 0 ||
967 strcmp(value
, "1") == 0))
968 export
->ex_flags
|= EX_NOSUB
;
970 export
->ex_flags
&= ~EX_NOSUB
;
973 if (value
!= NULL
&& (strcasecmp(value
, "true") == 0 ||
974 strcmp(value
, "1") == 0))
975 export
->ex_flags
|= EX_PUBLIC
;
977 export
->ex_flags
&= ~EX_PUBLIC
;
980 if (value
!= NULL
&& (strcmp(value
, "..") == 0 ||
981 strchr(value
, '/') != NULL
)) {
982 /* this is an error */
983 (void) printf(dgettext(TEXT_DOMAIN
,
984 "NFS: index=\"%s\" not valid;"
985 "must be a filename.\n"),
989 if (value
!= NULL
&& *value
!= '\0' &&
990 strcmp(value
, ".") != 0) {
991 /* valid index file string */
992 if (export
->ex_index
!= NULL
) {
993 /* left over from "default" */
994 free(export
->ex_index
);
996 /* remember to free */
997 export
->ex_index
= strdup(value
);
998 if (export
->ex_index
== NULL
) {
999 (void) printf(dgettext(TEXT_DOMAIN
,
1000 "NFS: out of memory setting "
1001 "index property\n"));
1004 export
->ex_flags
|= EX_INDEX
;
1009 value
= strdup("global");
1012 strlen(value
) ? value
: "global");
1014 case OPT_CHARSET_MAP
:
1016 * Set EX_CHARMAP when there is at least one
1017 * charmap conversion property. This will get
1018 * checked by the nfs server when it needs to.
1020 export
->ex_flags
|= EX_CHARMAP
;
1023 if (value
!= NULL
&& (strcasecmp(value
, "true") == 0 ||
1024 strcmp(value
, "1") == 0))
1025 export
->ex_flags
|= EX_NOACLFAB
;
1027 export
->ex_flags
&= ~EX_NOACLFAB
;
1030 /* have a syntactic error */
1031 (void) printf(dgettext(TEXT_DOMAIN
,
1032 "NFS: unrecognized option %s=%s\n"),
1033 name
!= NULL
? name
: "",
1034 value
!= NULL
? value
: "");
1038 sa_free_attr_string(name
);
1040 sa_free_attr_string(value
);
1046 * cleanup_export(export)
1048 * Cleanup the allocated areas so we don't leak memory
1052 cleanup_export(struct exportdata
*export
)
1056 free(export
->ex_index
);
1058 for (i
= 0; i
< export
->ex_seccnt
; i
++) {
1059 struct secinfo
*s
= &export
->ex_secinfo
[i
];
1061 while (s
->s_rootcnt
> 0)
1062 free(s
->s_rootnames
[--s
->s_rootcnt
]);
1064 free(s
->s_rootnames
);
1066 free(export
->ex_secinfo
);
1070 * Given a seconfig entry and a colon-separated
1071 * list of names, allocate an array big enough
1072 * to hold the root list, then convert each name to
1073 * a principal name according to the security
1074 * info and assign it to an array element.
1075 * Return the array and its size.
1078 get_rootnames(seconfig_t
*sec
, char *list
, int *count
)
1085 * Count the number of strings in the list.
1086 * This is the number of colon separators + 1.
1089 for (p
= list
; *p
; p
++)
1094 a
= (caddr_t
*)malloc(c
* sizeof (char *));
1096 (void) printf(dgettext(TEXT_DOMAIN
,
1097 "get_rootnames: no memory\n"));
1100 for (i
= 0; i
< c
; i
++) {
1101 host
= strtok(list
, ":");
1102 if (!nfs_get_root_principal(sec
, host
, &a
[i
])) {
1118 * fill_security_from_secopts(sp, secopts)
1120 * Fill the secinfo structure from the secopts optionset.
1124 fill_security_from_secopts(struct secinfo
*sp
, sa_security_t secopts
)
1129 int err
= SC_NOERROR
;
1132 type
= sa_get_security_attr(secopts
, "sectype");
1134 /* named security type needs secinfo to be filled in */
1135 err
= nfs_getseconfig_byname(type
, &sp
->s_secinfo
);
1136 sa_free_attr_string(type
);
1137 if (err
!= SC_NOERROR
)
1141 err
= nfs_getseconfig_default(&sp
->s_secinfo
);
1142 if (err
!= SC_NOERROR
)
1147 for (prop
= sa_get_property(secopts
, NULL
);
1148 prop
!= NULL
&& err
== SA_OK
;
1149 prop
= sa_get_next_property(prop
)) {
1153 name
= sa_get_property_attr(prop
, "type");
1154 value
= sa_get_property_attr(prop
, "value");
1156 longform
= value
!= NULL
&& strcmp(value
, "*") != 0;
1158 switch (findopt(name
)) {
1160 sp
->s_flags
|= longform
? M_ROL
: M_RO
;
1163 sp
->s_flags
|= longform
? M_RWL
: M_RW
;
1166 sp
->s_flags
|= M_ROOT
;
1168 * if we are using AUTH_UNIX, handle like other things
1171 if (sp
->s_secinfo
.sc_rpcnum
== AUTH_UNIX
)
1174 if (value
!= NULL
) {
1175 sp
->s_rootnames
= get_rootnames(&sp
->s_secinfo
,
1176 value
, &sp
->s_rootcnt
);
1177 if (sp
->s_rootnames
== NULL
) {
1179 (void) fprintf(stderr
,
1180 dgettext(TEXT_DOMAIN
,
1181 "Bad root list\n"));
1186 sp
->s_flags
|= M_NONE
;
1189 if (value
!= NULL
) {
1190 sp
->s_window
= atoi(value
);
1192 if (sp
->s_window
< 0)
1193 sp
->s_window
= DEF_WIN
;
1196 case OPT_ROOT_MAPPING
:
1197 if (value
!= NULL
&& is_a_number(value
)) {
1198 val
= strtoul(value
, NULL
, 0);
1201 pw
= getpwnam(value
!= NULL
? value
: "nobody");
1213 sp
->s_flags
|= M_MAP
;
1219 sa_free_attr_string(name
);
1221 sa_free_attr_string(value
);
1223 /* if rw/ro options not set, use default of RW */
1224 if ((sp
->s_flags
& NFS_RWMODES
) == 0)
1225 sp
->s_flags
|= M_RW
;
1230 * This is for testing only
1231 * It displays the export structure that
1232 * goes into the kernel.
1235 printarg(char *path
, struct exportdata
*ep
)
1243 (void) printf("%s:\n", path
);
1244 (void) printf("\tex_version = %d\n", ep
->ex_version
);
1245 (void) printf("\tex_path = %s\n", ep
->ex_path
);
1246 (void) printf("\tex_pathlen = %ld\n", (ulong_t
)ep
->ex_pathlen
);
1247 (void) printf("\tex_flags: (0x%02x) ", ep
->ex_flags
);
1248 if (ep
->ex_flags
& EX_NOSUID
)
1249 (void) printf("NOSUID ");
1250 if (ep
->ex_flags
& EX_ACLOK
)
1251 (void) printf("ACLOK ");
1252 if (ep
->ex_flags
& EX_PUBLIC
)
1253 (void) printf("PUBLIC ");
1254 if (ep
->ex_flags
& EX_NOSUB
)
1255 (void) printf("NOSUB ");
1256 if (ep
->ex_flags
& EX_LOG
)
1257 (void) printf("LOG ");
1258 if (ep
->ex_flags
& EX_CHARMAP
)
1259 (void) printf("CHARMAP ");
1260 if (ep
->ex_flags
& EX_LOG_ALLOPS
)
1261 (void) printf("LOG_ALLOPS ");
1262 if (ep
->ex_flags
== 0)
1263 (void) printf("(none)");
1264 (void) printf("\n");
1265 if (ep
->ex_flags
& EX_LOG
) {
1266 (void) printf("\tex_log_buffer = %s\n",
1267 (ep
->ex_log_buffer
? ep
->ex_log_buffer
: "(NULL)"));
1268 (void) printf("\tex_tag = %s\n",
1269 (ep
->ex_tag
? ep
->ex_tag
: "(NULL)"));
1271 (void) printf("\tex_anon = %d\n", ep
->ex_anon
);
1272 (void) printf("\tex_seccnt = %d\n", ep
->ex_seccnt
);
1273 (void) printf("\n");
1274 for (i
= 0; i
< ep
->ex_seccnt
; i
++) {
1275 sp
= &ep
->ex_secinfo
[i
];
1276 (void) printf("\t\ts_secinfo = %s\n", sp
->s_secinfo
.sc_name
);
1277 (void) printf("\t\ts_flags: (0x%02x) ", sp
->s_flags
);
1278 if (sp
->s_flags
& M_ROOT
) (void) printf("M_ROOT ");
1279 if (sp
->s_flags
& M_RO
) (void) printf("M_RO ");
1280 if (sp
->s_flags
& M_ROL
) (void) printf("M_ROL ");
1281 if (sp
->s_flags
& M_RW
) (void) printf("M_RW ");
1282 if (sp
->s_flags
& M_RWL
) (void) printf("M_RWL ");
1283 if (sp
->s_flags
& M_NONE
) (void) printf("M_NONE ");
1284 if (sp
->s_flags
& M_MAP
) (void) printf("M_MAP ");
1285 if (sp
->s_flags
== 0) (void) printf("(none)");
1286 (void) printf("\n");
1287 (void) printf("\t\ts_window = %d\n", sp
->s_window
);
1288 (void) printf("\t\ts_rootid = %d\n", sp
->s_rootid
);
1289 (void) printf("\t\ts_rootcnt = %d ", sp
->s_rootcnt
);
1290 (void) fflush(stdout
);
1291 for (j
= 0; j
< sp
->s_rootcnt
; j
++)
1292 (void) printf("%s ", sp
->s_rootnames
[j
] ?
1293 sp
->s_rootnames
[j
] : "<null>");
1294 (void) printf("\n\n");
1299 * count_security(opts)
1301 * Count the number of security types (flavors). The optionset has
1302 * been populated with the security flavors as a holding mechanism.
1303 * We later use this number to allocate data structures.
1307 count_security(sa_optionset_t opts
)
1312 for (prop
= sa_get_property(opts
, NULL
); prop
!= NULL
;
1313 prop
= sa_get_next_property(prop
)) {
1321 * nfs_sprint_option(rbuff, rbuffsize, incr, prop, sep)
1323 * provides a mechanism to format NFS properties into legacy output
1324 * format. If the buffer would overflow, it is reallocated and grown
1325 * as appropriate. Special cases of converting internal form of values
1326 * to those used by "share" are done. this function does one property
1331 nfs_sprint_option(char **rbuff
, size_t *rbuffsize
, size_t incr
,
1332 sa_property_t prop
, int sep
)
1337 char *buff
= *rbuff
;
1338 size_t buffsize
= *rbuffsize
;
1339 int printed
= B_FALSE
;
1341 name
= sa_get_property_attr(prop
, "type");
1342 value
= sa_get_property_attr(prop
, "value");
1344 curlen
= strlen(buff
);
1349 len
= strlen(name
) + sep
;
1352 * A future RFE would be to replace this with more
1353 * generic code and to possibly handle more types.
1355 switch (gettype(name
)) {
1356 case OPT_TYPE_BOOLEAN
:
1358 * For NFS, boolean value of FALSE means it
1359 * doesn't show up in the option list at all.
1361 if (value
!= NULL
&& strcasecmp(value
, "false") == 0)
1363 if (value
!= NULL
) {
1364 sa_free_attr_string(value
);
1368 case OPT_TYPE_ACCLIST
:
1369 if (value
!= NULL
&& strcmp(value
, "*") == 0) {
1370 sa_free_attr_string(value
);
1374 len
+= 1 + strlen(value
);
1377 case OPT_TYPE_LOGTAG
:
1378 if (value
!= NULL
&& strlen(value
) == 0) {
1379 sa_free_attr_string(value
);
1383 len
+= 1 + strlen(value
);
1388 len
+= 1 + strlen(value
);
1391 while (buffsize
<= (curlen
+ len
)) {
1392 /* need more room */
1394 buff
= realloc(buff
, buffsize
);
1396 /* realloc failed so free everything */
1400 *rbuffsize
= buffsize
;
1409 if (value
== NULL
) {
1410 (void) snprintf(buff
+ curlen
, buffsize
- curlen
,
1411 "%s%s", sep
? "," : "", name
);
1413 (void) snprintf(buff
+ curlen
, buffsize
- curlen
,
1414 "%s%s=%s", sep
? "," : "",
1415 name
, value
!= NULL
? value
: "");
1421 sa_free_attr_string(name
);
1423 sa_free_attr_string(value
);
1428 * nfs_format_options(group, hier)
1430 * format all the options on the group into an old-style option
1431 * string. If hier is non-zero, walk up the tree to get inherited
1436 nfs_format_options(sa_group_t group
, int hier
)
1438 sa_optionset_t options
= NULL
;
1439 sa_optionset_t secoptions
= NULL
;
1440 sa_property_t prop
, secprop
;
1441 sa_security_t security
= NULL
;
1444 char *sectype
= NULL
;
1448 buff
= malloc(OPT_CHUNK
);
1454 buffsize
= OPT_CHUNK
;
1457 * We may have a an optionset relative to this item. format
1458 * these if we find them and then add any security definitions.
1461 options
= sa_get_derived_optionset(group
, "nfs", hier
);
1464 * do the default set first but skip any option that is also
1465 * in the protocol specific optionset.
1467 if (options
!= NULL
) {
1468 for (prop
= sa_get_property(options
, NULL
);
1469 prop
!= NULL
; prop
= sa_get_next_property(prop
)) {
1471 * use this one since we skipped any
1472 * of these that were also in
1475 if (nfs_sprint_option(&buff
, &buffsize
, OPT_CHUNK
,
1480 * buff could become NULL if there
1481 * isn't enough memory for
1482 * nfs_sprint_option to realloc()
1483 * as necessary. We can't really
1484 * do anything about it at this
1485 * point so we return NULL. The
1486 * caller should handle the
1489 if (options
!= NULL
)
1490 sa_free_derived_optionset(
1496 secoptions
= (sa_optionset_t
)sa_get_all_security_types(group
,
1498 if (secoptions
!= NULL
) {
1499 for (secprop
= sa_get_property(secoptions
, NULL
);
1501 secprop
= sa_get_next_property(secprop
)) {
1502 sectype
= sa_get_property_attr(secprop
, "type");
1504 (sa_security_t
)sa_get_derived_security(
1505 group
, sectype
, "nfs", hier
);
1506 if (security
!= NULL
) {
1507 if (sectype
!= NULL
) {
1508 prop
= sa_create_property(
1512 if (nfs_sprint_option(&buff
,
1513 &buffsize
, OPT_CHUNK
, prop
, sep
))
1515 (void) sa_remove_property(prop
);
1519 for (prop
= sa_get_property(security
,
1520 NULL
); prop
!= NULL
;
1521 prop
= sa_get_next_property(prop
)) {
1522 if (nfs_sprint_option(&buff
,
1523 &buffsize
, OPT_CHUNK
, prop
, sep
))
1528 sa_free_derived_optionset(security
);
1530 if (sectype
!= NULL
)
1531 sa_free_attr_string(sectype
);
1533 sa_free_derived_optionset(secoptions
);
1536 if (options
!= NULL
)
1537 sa_free_derived_optionset(options
);
1542 * If we couldn't allocate memory for option printing, we need
1543 * to break out of the nested loops, cleanup and return NULL.
1545 if (secoptions
!= NULL
)
1546 sa_free_derived_optionset(secoptions
);
1547 if (security
!= NULL
)
1548 sa_free_derived_optionset(security
);
1549 if (sectype
!= NULL
)
1550 sa_free_attr_string(sectype
);
1551 if (options
!= NULL
)
1552 sa_free_derived_optionset(options
);
1557 * Append an entry to the nfslogtab file
1560 nfslogtab_add(char *dir
, char *buffer
, char *tag
)
1563 struct logtab_ent lep
;
1567 * Open the file for update and create it if necessary.
1568 * This may leave the I/O offset at the end of the file,
1569 * so rewind back to the beginning of the file.
1571 f
= fopen(NFSLOGTAB
, "a+");
1578 if (lockf(fileno(f
), F_LOCK
, 0L) < 0) {
1579 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
1580 "share complete, however failed to lock %s "
1581 "for update: %s\n"), NFSLOGTAB
, strerror(errno
));
1586 if (logtab_deactivate_after_boot(f
) == -1) {
1587 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
1588 "share complete, however could not deactivate "
1589 "entries in %s\n"), NFSLOGTAB
);
1595 * Remove entries matching buffer and sharepoint since we're
1596 * going to replace it with perhaps an entry with a new tag.
1598 if (logtab_rement(f
, buffer
, dir
, NULL
, -1)) {
1599 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
1600 "share complete, however could not remove matching "
1601 "entries in %s\n"), NFSLOGTAB
);
1607 * Deactivate all active entries matching this sharepoint
1609 if (logtab_deactivate(f
, NULL
, dir
, NULL
)) {
1610 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
1611 "share complete, however could not deactivate matching "
1612 "entries in %s\n"), NFSLOGTAB
);
1617 lep
.le_buffer
= buffer
;
1620 lep
.le_state
= LES_ACTIVE
;
1623 * Add new sharepoint / buffer location to nfslogtab
1625 if (logtab_putent(f
, &lep
) < 0) {
1626 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
1627 "share complete, however could not add %s to %s\n"),
1639 * Deactivate an entry from the nfslogtab file
1642 nfslogtab_deactivate(char *path
)
1647 f
= fopen(NFSLOGTAB
, "r+");
1652 if (lockf(fileno(f
), F_LOCK
, 0L) < 0) {
1654 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
1655 "share complete, however could not lock %s for "
1656 "update: %s\n"), NFSLOGTAB
, strerror(error
));
1659 if (logtab_deactivate(f
, NULL
, path
, NULL
) == -1) {
1661 (void) fprintf(stderr
,
1662 dgettext(TEXT_DOMAIN
,
1663 "share complete, however could not "
1664 "deactivate %s in %s\n"), path
, NFSLOGTAB
);
1675 * check_public(group, skipshare)
1677 * Check the group for any shares that have the public property
1678 * enabled. We skip "skipshare" since that is the one we are
1679 * working with. This is a separate function to make handling
1680 * subgroups simpler. Returns true if there is a share with public.
1683 check_public(sa_group_t group
, sa_share_t skipshare
)
1685 int exists
= B_FALSE
;
1691 for (share
= sa_get_share(group
, NULL
); share
!= NULL
;
1692 share
= sa_get_next_share(share
)) {
1693 if (share
== skipshare
)
1696 opt
= sa_get_optionset(share
, "nfs");
1699 prop
= sa_get_property(opt
, "public");
1702 shared
= sa_get_share_attr(share
, "shared");
1703 if (shared
!= NULL
) {
1704 exists
= strcmp(shared
, "true") == 0;
1705 sa_free_attr_string(shared
);
1706 if (exists
== B_TRUE
)
1715 * public_exists(handle, skipshare)
1717 * check to see if public option is set on any other share than the
1718 * one specified. Need to check zfs sub-groups as well as the top
1722 public_exists(sa_handle_t handle
, sa_share_t skipshare
)
1724 sa_group_t group
= NULL
;
1727 * If we don't have a handle, we can only do syntax check. We
1728 * can't check against other shares so we assume OK and will
1729 * catch the problem only when we actually try to apply it.
1734 if (skipshare
!= NULL
) {
1735 group
= sa_get_parent_group(skipshare
);
1737 return (SA_NO_SUCH_GROUP
);
1740 for (group
= sa_get_group(handle
, NULL
); group
!= NULL
;
1741 group
= sa_get_next_group(group
)) {
1742 /* Walk any ZFS subgroups as well as all standard groups */
1743 if (sa_group_is_zfs(group
)) {
1744 sa_group_t subgroup
;
1745 for (subgroup
= sa_get_sub_group(group
);
1747 subgroup
= sa_get_next_group(subgroup
)) {
1748 if (check_public(subgroup
, skipshare
))
1752 if (check_public(group
, skipshare
))
1760 * sa_enable_share at the protocol level, enable_share must tell the
1761 * implementation that it is to enable the share. This entails
1762 * converting the path and options into the appropriate ioctl
1763 * calls. It is assumed that all error checking of paths, etc. were
1767 nfs_enable_share(sa_share_t share
)
1769 struct exportdata export
;
1770 sa_optionset_t secoptlist
;
1782 /* Don't drop core if the NFS module isn't loaded. */
1783 (void) signal(SIGSYS
, SIG_IGN
);
1785 /* get the path since it is important in several places */
1786 path
= sa_get_share_attr(share
, "path");
1788 return (SA_NO_SUCH_PATH
);
1790 iszfs
= sa_path_is_zfs(path
);
1792 * find the optionsets and security sets. There may not be
1793 * any or there could be one or two for each of optionset and
1794 * security may have multiple, one per security type per
1797 opt
= sa_get_derived_optionset(share
, "nfs", 1);
1798 secoptlist
= (sa_optionset_t
)sa_get_all_security_types(share
, "nfs", 1);
1799 if (secoptlist
!= NULL
)
1800 num_secinfo
= MAX(1, count_security(secoptlist
));
1805 * walk through the options and fill in the structure
1809 (void) memset(&export
, '\0', sizeof (export
));
1812 * do non-security options first since there is only one after
1813 * the derived group is constructed.
1815 export
.ex_version
= EX_CURRENT_VERSION
;
1816 export
.ex_anon
= UID_NOBODY
; /* this is our default value */
1817 export
.ex_index
= NULL
;
1818 export
.ex_path
= path
;
1819 export
.ex_pathlen
= strlen(path
) + 1;
1822 err
= fill_export_from_optionset(&export
, opt
);
1825 * check to see if "public" is set. If it is, then make sure
1826 * no other share has it set. If it is already used, fail.
1829 handle
= sa_find_group_handle((sa_group_t
)share
);
1830 if (export
.ex_flags
& EX_PUBLIC
&& public_exists(handle
, share
)) {
1831 (void) printf(dgettext(TEXT_DOMAIN
,
1832 "NFS: Cannot share more than one file "
1833 "system with 'public' property\n"));
1834 err
= SA_NOT_ALLOWED
;
1838 sp
= calloc(num_secinfo
, sizeof (struct secinfo
));
1841 (void) printf(dgettext(TEXT_DOMAIN
,
1842 "NFS: NFS: no memory for security\n"));
1845 export
.ex_secinfo
= sp
;
1846 /* get default secinfo */
1847 export
.ex_seccnt
= num_secinfo
;
1849 * since we must have one security option defined, we
1850 * init to the default and then override as we find
1851 * defined security options. This handles the case
1852 * where we have no defined options but we need to set
1855 sp
[0].s_window
= DEF_WIN
;
1856 sp
[0].s_rootnames
= NULL
;
1857 /* setup a default in case no properties defined */
1858 if (nfs_getseconfig_default(&sp
[0].s_secinfo
)) {
1859 (void) printf(dgettext(TEXT_DOMAIN
,
1860 "NFS: nfs_getseconfig_default: failed to "
1861 "get default security mode\n"));
1862 err
= SA_CONFIG_ERR
;
1864 if (secoptlist
!= NULL
) {
1865 for (i
= 0, prop
= sa_get_property(secoptlist
, NULL
);
1866 prop
!= NULL
&& i
< num_secinfo
;
1867 prop
= sa_get_next_property(prop
), i
++) {
1869 sectype
= sa_get_property_attr(prop
, "type");
1871 * if sectype is NULL, we probably
1872 * have a memory problem and can't get
1873 * the correct values. Rather than
1874 * exporting with incorrect security,
1877 if (sectype
== NULL
) {
1879 (void) printf(dgettext(TEXT_DOMAIN
,
1880 "NFS: Cannot share %s: "
1881 "no memory\n"), path
);
1884 sec
= (sa_security_t
)sa_get_derived_security(
1885 share
, sectype
, "nfs", 1);
1886 sp
[i
].s_window
= DEF_WIN
;
1887 sp
[i
].s_rootcnt
= 0;
1888 sp
[i
].s_rootnames
= NULL
;
1889 (void) fill_security_from_secopts(&sp
[i
], sec
);
1891 sa_free_derived_security(sec
);
1892 if (sectype
!= NULL
)
1893 sa_free_attr_string(sectype
);
1897 * when we get here, we can do the exportfs system call and
1898 * initiate things. We probably want to enable the
1899 * svc:/network/nfs/server service first if it isn't running.
1901 /* check svc:/network/nfs/server status and start if needed */
1902 /* now add the share to the internal tables */
1903 printarg(path
, &export
);
1905 * call the exportfs system call which is implemented
1906 * via the nfssys() call as the EXPORTFS subfunction.
1909 struct exportfs_args ea
;
1912 priv_set_t
*priv_effective
;
1916 * If we aren't a privileged user
1917 * and NFS server service isn't running
1918 * then print out an error message
1922 priv_effective
= priv_allocset();
1923 (void) getppriv(PRIV_EFFECTIVE
, priv_effective
);
1925 privileged
= (priv_isfullset(priv_effective
) == B_TRUE
);
1926 priv_freeset(priv_effective
);
1929 (str
= smf_get_state(NFS_SERVER_SVC
)) != NULL
) {
1931 if (strcmp(str
, SCF_STATE_STRING_ONLINE
) != 0) {
1932 (void) printf(dgettext(TEXT_DOMAIN
,
1933 "NFS: Cannot share remote "
1934 "filesystem: %s\n"), path
);
1935 (void) printf(dgettext(TEXT_DOMAIN
,
1936 "NFS: Service needs to be enabled "
1937 "by a privileged user\n"));
1938 err
= SA_SYSTEM_ERR
;
1948 (void) sa_sharetab_fill_zfs(share
, &sh
, "nfs");
1949 err
= sa_share_zfs(share
, NULL
, path
, &sh
,
1950 &ea
, ZFS_SHARE_NFS
);
1958 err
= exportfs(path
, &export
);
1962 err
= SA_SYSTEM_ERR
;
1965 (void) printf(dgettext(TEXT_DOMAIN
,
1966 "NFS: Cannot share filesystems "
1967 "in non-global zones: %s\n"), path
);
1968 err
= SA_NOT_SUPPORTED
;
1971 if (getzoneid() != GLOBAL_ZONEID
) {
1972 (void) printf(dgettext(TEXT_DOMAIN
,
1973 "NFS: Cannot share file systems "
1974 "in non-global zones: %s\n"), path
);
1975 err
= SA_NOT_SUPPORTED
;
1978 err
= SA_NO_PERMISSION
;
1981 err
= SA_SHARE_EXISTS
;
1987 /* update sharetab with an add/modify */
1989 (void) sa_update_sharetab(share
, "nfs");
1995 * enable services as needed. This should probably be
1996 * done elsewhere in order to minimize the calls to
2000 * check to see if logging and other services need to
2001 * be triggered, but only if there wasn't an
2002 * error. This is probably where sharetab should be
2003 * updated with the NFS specific entry.
2005 if (export
.ex_flags
& EX_LOG
) {
2006 /* enable logging */
2007 if (nfslogtab_add(path
, export
.ex_log_buffer
,
2008 export
.ex_tag
) != 0) {
2009 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
2010 "Could not enable logging for %s\n"),
2013 _check_services(service_list_logging
);
2016 * don't have logging so remove it from file. It might
2017 * not be thre, but that doesn't matter.
2019 (void) nfslogtab_deactivate(path
);
2020 _check_services(service_list_default
);
2027 cleanup_export(&export
);
2029 sa_free_derived_optionset(opt
);
2030 if (secoptlist
!= NULL
)
2031 (void) sa_destroy_optionset(secoptlist
);
2036 * nfs_disable_share(share, path)
2038 * Unshare the specified share. Note that "path" is the same path as
2039 * what is in the "share" object. It is passed in to avoid an
2040 * additional lookup. A missing "path" value makes this a no-op
2044 nfs_disable_share(sa_share_t share
, char *path
)
2056 * If the share is in a ZFS group we need to handle it
2057 * differently. Just being on a ZFS file system isn't
2058 * enough since we may be in a legacy share case.
2060 parent
= sa_get_parent_group(share
);
2061 iszfs
= sa_group_is_zfs(parent
);
2063 struct exportfs_args ea
;
2068 sh
.sh_fstype
= "nfs";
2070 err
= sa_share_zfs(share
, NULL
, path
, &sh
,
2071 &ea
, ZFS_UNSHARE_NFS
);
2077 err
= exportfs(path
, NULL
);
2081 * TBD: only an error in some
2082 * cases - need better analysis
2087 ret
= SA_NO_PERMISSION
;
2088 if (getzoneid() != GLOBAL_ZONEID
) {
2089 ret
= SA_NOT_SUPPORTED
;
2094 ret
= SA_NO_SUCH_PATH
;
2097 ret
= SA_SYSTEM_ERR
;
2101 if (ret
== SA_OK
|| ret
== SA_NO_SUCH_PATH
) {
2102 handle
= sa_find_group_handle((sa_group_t
)share
);
2104 (void) sa_delete_sharetab(handle
, path
, "nfs");
2105 /* just in case it was logged */
2106 (void) nfslogtab_deactivate(path
);
2112 check_user(char *value
)
2116 if (!is_a_number(value
)) {
2119 * in this case it would have to be a
2122 pw
= getpwnam(value
);
2128 intval
= strtoull(value
, NULL
, 0);
2129 if (intval
> UID_MAX
&& intval
!= -1)
2137 check_group(char *value
)
2141 if (!is_a_number(value
)) {
2144 * in this case it would have to be a
2147 gr
= getgrnam(value
);
2153 intval
= strtoull(value
, NULL
, 0);
2154 if (intval
> UID_MAX
&& intval
!= -1)
2162 * check_rorwnone(v1, v2, v3)
2164 * check ro vs rw vs none values. Over time this may get beefed up.
2165 * for now it just does simple checks. v1 is never NULL but v2 or v3
2170 check_rorwnone(char *v1
, char *v2
, char *v3
)
2173 if (v2
!= NULL
&& strcmp(v1
, v2
) == 0)
2174 ret
= SA_VALUE_CONFLICT
;
2175 else if (v3
!= NULL
&& strcmp(v1
, v3
) == 0)
2176 ret
= SA_VALUE_CONFLICT
;
2182 * nfs_validate_property(handle, property, parent)
2184 * Check that the property has a legitimate value for its type.
2188 nfs_validate_property(sa_handle_t handle
, sa_property_t property
,
2189 sa_optionset_t parent
)
2196 nfsl_config_t
*configlist
;
2197 sa_group_t parent_group
;
2200 propname
= sa_get_property_attr(property
, "type");
2202 if ((optindex
= findopt(propname
)) < 0)
2203 ret
= SA_NO_SUCH_PROP
;
2205 /* need to validate value range here as well */
2208 parent_group
= sa_get_parent_group((sa_share_t
)parent
);
2209 if (optdefs
[optindex
].share
&& parent_group
!= NULL
&&
2210 !sa_is_share(parent_group
))
2211 ret
= SA_PROP_SHARE_ONLY
;
2214 if (optdefs
[optindex
].index
== OPT_PUBLIC
) {
2216 * Public is special in that only one instance can
2217 * be in the repository at the same time.
2219 if (public_exists(handle
, parent_group
)) {
2220 sa_free_attr_string(propname
);
2221 return (SA_VALUE_CONFLICT
);
2224 value
= sa_get_property_attr(property
, "value");
2225 if (value
!= NULL
) {
2226 /* first basic type checking */
2227 switch (optdefs
[optindex
].type
) {
2229 case OPT_TYPE_NUMBER
:
2230 /* check that the value is all digits */
2231 if (!is_a_number(value
))
2235 case OPT_TYPE_BOOLEAN
:
2236 if (strlen(value
) == 0 ||
2237 strcasecmp(value
, "true") == 0 ||
2238 strcmp(value
, "1") == 0 ||
2239 strcasecmp(value
, "false") == 0 ||
2240 strcmp(value
, "0") == 0) {
2248 ret
= check_user(value
);
2252 if (strcmp(value
, "..") == 0 ||
2253 strchr(value
, '/') != NULL
) {
2258 case OPT_TYPE_ACCLIST
: {
2259 sa_property_t oprop1
;
2260 sa_property_t oprop2
;
2261 char *ovalue1
= NULL
;
2262 char *ovalue2
= NULL
;
2267 * access list handling. Should eventually
2268 * validate that all the values make sense.
2269 * Also, ro and rw may have cross value
2272 if (strcmp(propname
, SHOPT_RO
) == 0) {
2274 other2
= SHOPT_NONE
;
2275 } else if (strcmp(propname
, SHOPT_RW
) == 0) {
2277 other2
= SHOPT_NONE
;
2278 } else if (strcmp(propname
, SHOPT_NONE
) == 0) {
2285 if (other1
== NULL
&& other2
== NULL
)
2288 /* compare rw(ro) with ro(rw) */
2290 oprop1
= sa_get_property(parent
, other1
);
2291 oprop2
= sa_get_property(parent
, other2
);
2292 if (oprop1
== NULL
&& oprop2
== NULL
)
2295 * Only potential confusion if other1
2296 * or other2 exists. Check the values
2297 * and run the check if there is a
2298 * value other than the one we are
2299 * explicitly looking at.
2301 ovalue1
= sa_get_property_attr(oprop1
, "value");
2302 ovalue2
= sa_get_property_attr(oprop2
, "value");
2303 if (ovalue1
!= NULL
|| ovalue2
!= NULL
)
2304 ret
= check_rorwnone(value
, ovalue1
,
2307 if (ovalue1
!= NULL
)
2308 sa_free_attr_string(ovalue1
);
2309 if (ovalue2
!= NULL
)
2310 sa_free_attr_string(ovalue2
);
2314 case OPT_TYPE_LOGTAG
:
2315 if (nfsl_getconfig_list(&configlist
) == 0) {
2317 if (value
== NULL
||
2318 strlen(value
) == 0) {
2320 sa_free_attr_string(
2322 value
= strdup("global");
2324 if (value
!= NULL
&&
2325 nfsl_findconfig(configlist
, value
,
2329 /* Must always free when done */
2330 nfsl_freeconfig_list(&configlist
);
2332 ret
= SA_CONFIG_ERR
;
2336 case OPT_TYPE_STRING
:
2337 /* whatever is here should be ok */
2340 case OPT_TYPE_SECURITY
:
2342 * The "sec" property isn't used in the
2343 * non-legacy parts of sharemgr. We need to
2344 * reject it here. For legacy, it is pulled
2345 * out well before we get here.
2347 ret
= SA_NO_SUCH_PROP
;
2350 case OPT_TYPE_MAPPING
: {
2356 sa_security_t security
;
2359 * mapping is only supported for sec=sys
2361 ret
= SA_CONFIG_ERR
;
2362 if (parent_group
== NULL
)
2365 for (security
= sa_get_security(parent_group
,
2366 NULL
, NULL
); security
!= NULL
;
2367 security
= sa_get_next_security(security
)) {
2371 type
= sa_get_security_attr(security
,
2376 if (strcmp(type
, "nfs") != 0) {
2377 sa_free_attr_string(type
);
2380 sa_free_attr_string(type
);
2382 sectype
= sa_get_security_attr(security
,
2384 if (sectype
== NULL
)
2387 if (strcmp(sectype
, "sys") != 0) {
2388 sa_free_attr_string(sectype
);
2389 ret
= SA_CONFIG_ERR
;
2392 sa_free_attr_string(sectype
);
2399 assert(optindex
== OPT_UIDMAP
||
2400 optindex
== OPT_GIDMAP
);
2401 f
= optindex
== OPT_UIDMAP
? check_user
:
2409 for (c
= p
; ret
== SA_OK
&& c
!= NULL
; c
= n
) {
2425 if (s
== NULL
|| t
== NULL
)
2428 if (ret
== SA_OK
&& *c
!= '\0' &&
2429 strcmp(c
, "*") != 0)
2432 if (ret
== SA_OK
&& *s
!= '\0' &&
2433 strcmp(s
, "-1") != 0)
2447 sa_free_attr_string(value
);
2449 if (ret
== SA_OK
&& optdefs
[optindex
].check
!= NULL
) {
2450 /* do the property specific check */
2451 ret
= optdefs
[optindex
].check(handle
, property
);
2456 if (propname
!= NULL
)
2457 sa_free_attr_string(propname
);
2462 * Protocol management functions
2464 * Properties defined in the default files are defined in
2465 * proto_option_defs for parsing and validation. If "other" and
2466 * "compare" are set, then the value for this property should be
2467 * compared against the property specified in "other" using the
2468 * "compare" check (either <= or >=) in order to ensure that the
2469 * values are in the correct range. E.g. setting server_versmin
2470 * higher than server_versmax should not be allowed.
2473 struct proto_option_defs
{
2475 char *name
; /* display name -- remove protocol identifier */
2487 #define OPT_CMP_GE 0
2488 #define OPT_CMP_LE 1
2489 int (*check
)(char *);
2490 } proto_options
[] = {
2491 #define PROTO_OPT_NFSD_SERVERS 0
2493 "servers", PROTO_OPT_NFSD_SERVERS
, OPT_TYPE_NUMBER
, 1024, SVC_NFSD
,
2495 #define PROTO_OPT_LOCKD_LISTEN_BACKLOG 1
2496 {"lockd_listen_backlog",
2497 "lockd_listen_backlog", PROTO_OPT_LOCKD_LISTEN_BACKLOG
,
2498 OPT_TYPE_NUMBER
, 32, SVC_LOCKD
, 32, INT32_MAX
},
2499 #define PROTO_OPT_LOCKD_SERVERS 2
2501 "lockd_servers", PROTO_OPT_LOCKD_SERVERS
, OPT_TYPE_NUMBER
, 256,
2502 SVC_LOCKD
, 1, INT32_MAX
},
2503 #define PROTO_OPT_LOCKD_RETRANSMIT_TIMEOUT 3
2504 {"lockd_retransmit_timeout",
2505 "lockd_retransmit_timeout", PROTO_OPT_LOCKD_RETRANSMIT_TIMEOUT
,
2506 OPT_TYPE_NUMBER
, 5, SVC_LOCKD
, 0, INT32_MAX
},
2507 #define PROTO_OPT_GRACE_PERIOD 4
2509 "grace_period", PROTO_OPT_GRACE_PERIOD
, OPT_TYPE_NUMBER
, 90,
2510 SVC_LOCKD
, 0, INT32_MAX
},
2511 #define PROTO_OPT_NFS_SERVER_VERSMIN 5
2512 {"nfs_server_versmin",
2513 "server_versmin", PROTO_OPT_NFS_SERVER_VERSMIN
, OPT_TYPE_NUMBER
,
2514 (int)NFS_VERSMIN_DEFAULT
, SVC_NFSD
|SVC_MOUNTD
, NFS_VERSMIN
,
2515 NFS_VERSMAX
, "server_versmax", OPT_CMP_LE
},
2516 #define PROTO_OPT_NFS_SERVER_VERSMAX 6
2517 {"nfs_server_versmax",
2518 "server_versmax", PROTO_OPT_NFS_SERVER_VERSMAX
, OPT_TYPE_NUMBER
,
2519 (int)NFS_VERSMAX_DEFAULT
, SVC_NFSD
|SVC_MOUNTD
, NFS_VERSMIN
,
2520 NFS_VERSMAX
, "server_versmin", OPT_CMP_GE
},
2521 #define PROTO_OPT_NFS_CLIENT_VERSMIN 7
2522 {"nfs_client_versmin",
2523 "client_versmin", PROTO_OPT_NFS_CLIENT_VERSMIN
, OPT_TYPE_NUMBER
,
2524 (int)NFS_VERSMIN_DEFAULT
, SVC_CLIENT
, NFS_VERSMIN
, NFS_VERSMAX
,
2525 "client_versmax", OPT_CMP_LE
},
2526 #define PROTO_OPT_NFS_CLIENT_VERSMAX 8
2527 {"nfs_client_versmax",
2528 "client_versmax", PROTO_OPT_NFS_CLIENT_VERSMAX
, OPT_TYPE_NUMBER
,
2529 (int)NFS_VERSMAX_DEFAULT
, SVC_CLIENT
, NFS_VERSMIN
, NFS_VERSMAX
,
2530 "client_versmin", OPT_CMP_GE
},
2531 #define PROTO_OPT_NFS_SERVER_DELEGATION 9
2532 {"nfs_server_delegation",
2533 "server_delegation", PROTO_OPT_NFS_SERVER_DELEGATION
,
2534 OPT_TYPE_ONOFF
, NFS_SERVER_DELEGATION_DEFAULT
, SVC_NFSD
, 0, 0},
2535 #define PROTO_OPT_NFSMAPID_DOMAIN 10
2537 "nfsmapid_domain", PROTO_OPT_NFSMAPID_DOMAIN
, OPT_TYPE_DOMAIN
,
2538 0, SVC_NFSMAPID
, 0, 0},
2539 #define PROTO_OPT_NFSD_MAX_CONNECTIONS 11
2540 {"nfsd_max_connections",
2541 "max_connections", PROTO_OPT_NFSD_MAX_CONNECTIONS
,
2542 OPT_TYPE_NUMBER
, -1, SVC_NFSD
, -1, INT32_MAX
},
2543 #define PROTO_OPT_NFSD_PROTOCOL 12
2545 "protocol", PROTO_OPT_NFSD_PROTOCOL
, OPT_TYPE_PROTOCOL
, 0,
2547 #define PROTO_OPT_NFSD_LISTEN_BACKLOG 13
2548 {"nfsd_listen_backlog",
2549 "listen_backlog", PROTO_OPT_NFSD_LISTEN_BACKLOG
,
2550 OPT_TYPE_NUMBER
, 0, SVC_NFSD
, 0, INT32_MAX
},
2551 #define PROTO_OPT_NFSD_DEVICE 14
2553 "device", PROTO_OPT_NFSD_DEVICE
,
2554 OPT_TYPE_STRING
, 0, SVC_NFSD
, 0, 0},
2555 #define PROTO_OPT_MOUNTD_LISTEN_BACKLOG 15
2556 {"mountd_listen_backlog",
2557 "mountd_listen_backlog", PROTO_OPT_MOUNTD_LISTEN_BACKLOG
,
2558 OPT_TYPE_NUMBER
, 64, SVC_NFSD
|SVC_MOUNTD
, 1, INT32_MAX
},
2559 #define PROTO_OPT_MOUNTD_MAX_THREADS 16
2560 {"mountd_max_threads",
2561 "mountd_max_threads", PROTO_OPT_MOUNTD_MAX_THREADS
,
2562 OPT_TYPE_NUMBER
, 16, SVC_NFSD
|SVC_MOUNTD
, 1, INT32_MAX
},
2567 * the protoset holds the defined options so we don't have to read
2568 * them multiple times
2570 static sa_protocol_properties_t protoset
;
2573 findprotoopt(char *name
, int whichname
)
2576 for (i
= 0; proto_options
[i
].tag
!= NULL
; i
++) {
2577 if (whichname
== 1) {
2578 if (strcasecmp(proto_options
[i
].name
, name
) == 0)
2581 if (strcasecmp(proto_options
[i
].tag
, name
) == 0)
2591 * convert a string to lower case (inplace).
2595 fixcaselower(char *str
)
2598 *str
= tolower(*str
);
2604 * skipwhitespace(str)
2606 * Skip leading white space. It is assumed that it is called with a
2611 skipwhitespace(char *str
)
2613 while (*str
&& isspace(*str
))
2622 * Extract the property and value out of the line and create the
2623 * property in the optionset.
2626 extractprop(char *name
, char *value
)
2632 * Remove any leading
2635 name
= skipwhitespace(name
);
2637 index
= findprotoopt(name
, 1);
2640 prop
= sa_create_property(proto_options
[index
].name
, value
);
2642 ret
= sa_add_protocol_property(protoset
, prop
);
2650 getscftype(int type
)
2655 case OPT_TYPE_NUMBER
:
2656 ret
= SCF_TYPE_INTEGER
;
2658 case OPT_TYPE_BOOLEAN
:
2659 ret
= SCF_TYPE_BOOLEAN
;
2662 ret
= SCF_TYPE_ASTRING
;
2668 getsvcname(uint32_t svcs
)
2682 service
= NFS_CLIENT_SVC
;
2706 * initprotofromsmf()
2708 * Read NFS SMF properties and add the defined values to the
2709 * protoset. Note that default values are known from the built in
2710 * table in case SMF doesn't have a definition. Not having
2711 * SMF properties is OK since we have builtin default
2717 char name
[PATH_MAX
];
2718 char value
[PATH_MAX
];
2719 int ret
= SA_OK
, bufsz
= 0, i
;
2721 protoset
= sa_create_protocol_properties("nfs");
2722 if (protoset
!= NULL
) {
2723 for (i
= 0; proto_options
[i
].tag
!= NULL
; i
++) {
2727 bzero(value
, PATH_MAX
);
2728 (void) strncpy(name
, proto_options
[i
].name
, PATH_MAX
);
2729 /* Replace NULL with the correct instance */
2730 ptype
= getscftype(proto_options
[i
].type
);
2731 svc_name
= getsvcname(proto_options
[i
].svcs
);
2733 ret
= nfs_smf_get_prop(name
, value
,
2734 (char *)DEFAULT_INSTANCE
, ptype
,
2737 ret
= extractprop(name
, value
);
2750 * Add the default values for any property not defined
2751 * in NFS SMF repository.
2752 * Values are set according to their defined types.
2759 char number
[MAXDIGITS
];
2761 for (i
= 0; proto_options
[i
].tag
!= NULL
; i
++) {
2763 prop
= sa_get_protocol_property(protoset
,
2764 proto_options
[i
].name
);
2766 /* add the default value */
2767 switch (proto_options
[i
].type
) {
2768 case OPT_TYPE_NUMBER
:
2769 (void) snprintf(number
, sizeof (number
), "%d",
2770 proto_options
[i
].defvalue
.intval
);
2771 prop
= sa_create_property(proto_options
[i
].name
,
2775 case OPT_TYPE_BOOLEAN
:
2776 prop
= sa_create_property(proto_options
[i
].name
,
2777 proto_options
[i
].defvalue
.intval
?
2781 case OPT_TYPE_ONOFF
:
2782 prop
= sa_create_property(proto_options
[i
].name
,
2783 proto_options
[i
].defvalue
.intval
?
2788 /* treat as strings of zero length */
2789 prop
= sa_create_property(proto_options
[i
].name
,
2794 (void) sa_add_protocol_property(protoset
, prop
);
2802 if (protoset
!= NULL
) {
2803 xmlFreeNode(protoset
);
2811 * Initialize the NFS plugin.
2819 if (sa_plugin_ops
.sa_init
!= nfs_init
) {
2820 (void) printf(dgettext(TEXT_DOMAIN
,
2821 "NFS plugin not properly initialized\n"));
2822 return (SA_CONFIG_ERR
);
2825 ret
= initprotofromsmf();
2827 (void) printf(dgettext(TEXT_DOMAIN
,
2828 "NFS plugin problem with SMF repository: %s\n"),
2840 * uninitialize the NFS plugin. Want to avoid memory leaks.
2850 * nfs_get_proto_set()
2852 * Return an optionset with all the protocol specific properties in
2856 static sa_protocol_properties_t
2863 * service_in_state(service, chkstate)
2865 * Want to know if the specified service is in the desired state
2866 * (chkstate) or not. Return true (1) if it is and false (0) if it
2870 service_in_state(char *service
, const char *chkstate
)
2875 state
= smf_get_state(service
);
2876 if (state
!= NULL
) {
2877 /* got the state so get the equality for the return value */
2878 ret
= strcmp(state
, chkstate
) == 0 ? B_TRUE
: B_FALSE
;
2885 * restart_service(svcs)
2887 * Walk through the bit mask of services that need to be restarted in
2888 * order to use the new property values. Some properties affect
2889 * multiple daemons. Should only restart a service if it is currently
2894 restart_service(uint32_t svcs
)
2900 for (mask
= 1; svcs
!= 0; mask
<<= 1) {
2901 switch (svcs
& mask
) {
2930 service
= NFS_CLIENT_SVC
;
2937 * Only attempt to restart the service if it is
2938 * currently running. In the future, it may be
2939 * desirable to use smf_refresh_instance if the NFS
2940 * services ever implement the refresh method.
2942 if (service_in_state(service
, SCF_STATE_STRING_ONLINE
)) {
2943 ret
= smf_restart_instance(service
);
2945 * There are only a few SMF errors at this point, but
2946 * it is also possible that a bad value may have put
2947 * the service into maintenance if there wasn't an
2951 (void) fprintf(stderr
,
2952 dgettext(TEXT_DOMAIN
,
2953 "%s failed to restart: %s\n"),
2954 service
, scf_strerror(scf_error()));
2957 * Check whether it has gone to "maintenance"
2958 * mode or not. Maintenance implies something
2961 if (service_in_state(service
,
2962 SCF_STATE_STRING_MAINT
)) {
2963 (void) fprintf(stderr
,
2964 dgettext(TEXT_DOMAIN
,
2965 "%s failed to restart\n"),
2975 * nfs_minmax_check(name, value)
2977 * Verify that the value for the property specified by index is valid
2978 * relative to the opposite value in the case of a min/max variable.
2979 * Currently, server_minvers/server_maxvers and
2980 * client_minvers/client_maxvers are the only ones to check.
2984 nfs_minmax_check(int index
, int value
)
2989 sa_optionset_t opts
;
2992 if (proto_options
[index
].other
!= NULL
) {
2993 /* have a property to compare against */
2994 opts
= nfs_get_proto_set();
2995 prop
= sa_get_property(opts
, proto_options
[index
].other
);
2997 * If we don't find the property, assume default
2998 * values which will work since the max will be at the
2999 * max and the min at the min.
3002 pval
= sa_get_property_attr(prop
, "value");
3004 val
= strtoul(pval
, NULL
, 0);
3005 if (proto_options
[index
].compare
==
3007 ret
= value
<= val
? B_TRUE
: B_FALSE
;
3008 } else if (proto_options
[index
].compare
==
3010 ret
= value
>= val
? B_TRUE
: B_FALSE
;
3012 sa_free_attr_string(pval
);
3020 * nfs_validate_proto_prop(index, name, value)
3022 * Verify that the property specified by name can take the new
3023 * value. This is a sanity check to prevent bad values getting into
3024 * the default files. All values need to be checked against what is
3025 * allowed by their defined type. If a type isn't explicitly defined
3026 * here, it is treated as a string.
3028 * Note that OPT_TYPE_NUMBER will additionally check that the value is
3029 * within the range specified and potentially against another property
3030 * value as well as specified in the proto_options members other and
3035 nfs_validate_proto_prop(int index
, char *name
, char *value
)
3039 switch (proto_options
[index
].type
) {
3040 case OPT_TYPE_NUMBER
:
3041 if (!is_a_number(value
))
3045 val
= strtoul(value
, NULL
, 0);
3046 if (val
< proto_options
[index
].minval
||
3047 val
> proto_options
[index
].maxval
)
3050 * For server_versmin/server_versmax and
3051 * client_versmin/client_versmax, the value of the
3052 * min(max) should be checked to be correct relative
3053 * to the current max(min).
3055 if (!nfs_minmax_check(index
, val
)) {
3061 case OPT_TYPE_DOMAIN
:
3063 * needs to be a qualified domain so will have at
3064 * least one period and other characters on either
3065 * side of it. A zero length string is also allowed
3066 * and is the way to turn off the override.
3068 if (strlen(value
) == 0)
3070 cp
= strchr(value
, '.');
3071 if (cp
== NULL
|| cp
== value
|| strchr(value
, '@') != NULL
)
3075 case OPT_TYPE_BOOLEAN
:
3076 if (strlen(value
) == 0 ||
3077 strcasecmp(value
, "true") == 0 ||
3078 strcmp(value
, "1") == 0 ||
3079 strcasecmp(value
, "false") == 0 ||
3080 strcmp(value
, "0") == 0) {
3087 case OPT_TYPE_ONOFF
:
3088 if (strcasecmp(value
, "on") != 0 &&
3089 strcasecmp(value
, "off") != 0) {
3094 case OPT_TYPE_PROTOCOL
: {
3095 struct netconfig
*nconf
;
3097 boolean_t pfound
= B_FALSE
;
3099 if (strcasecmp(value
, "all") == 0)
3102 if ((nc
= setnetconfig()) == NULL
) {
3103 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
,
3104 "setnetconfig failed: %s\n"), strerror(errno
));
3106 while ((nconf
= getnetconfig(nc
)) != NULL
) {
3107 if (strcmp(nconf
->nc_proto
, value
) == 0) {
3112 (void) endnetconfig(nc
);
3121 /* treat as a string */
3128 * nfs_set_proto_prop(prop)
3130 * check that prop is valid.
3134 nfs_set_proto_prop(sa_property_t prop
)
3140 name
= sa_get_property_attr(prop
, "type");
3141 value
= sa_get_property_attr(prop
, "value");
3142 if (name
!= NULL
&& value
!= NULL
) {
3145 char *instance
= NULL
;
3146 int index
= findprotoopt(name
, 1);
3148 ret
= nfs_validate_proto_prop(index
, name
, value
);
3150 sctype
= getscftype(proto_options
[index
].type
);
3151 svc_name
= getsvcname(proto_options
[index
].svcs
);
3152 if (sctype
== SCF_TYPE_BOOLEAN
) {
3154 sa_free_attr_string(value
);
3155 if (string_to_boolean(value
) == 0)
3156 value
= strdup("0");
3158 value
= strdup("1");
3160 ret
= nfs_smf_set_prop(name
, value
, instance
, sctype
,
3163 restart_service(proto_options
[index
].svcs
);
3165 (void) printf(dgettext(TEXT_DOMAIN
,
3166 "Cannot restart NFS services : %s\n"),
3172 sa_free_attr_string(name
);
3174 sa_free_attr_string(value
);
3181 * What is the current status of the nfsd? We use the SMF state here.
3182 * Caller must free the returned value.
3188 return (smf_get_state(NFSD
));
3192 * nfs_space_alias(alias)
3194 * Lookup the space (security) name. If it is default, convert to the
3199 nfs_space_alias(char *space
)
3205 * Only the space named "default" is special. If it is used,
3206 * the default needs to be looked up and the real name used.
3207 * This is normally "sys" but could be changed. We always
3208 * change default to the real name.
3210 if (strcmp(space
, "default") == 0 &&
3211 nfs_getseconfig_default(&secconf
) == 0) {
3212 if (nfs_getseconfig_bynumber(secconf
.sc_nfsnum
, &secconf
) == 0)
3213 name
= secconf
.sc_name
;
3215 return (strdup(name
));
3221 * Return a mask of the features required.
3227 return ((uint64_t)SA_FEATURE_DFSTAB
| SA_FEATURE_SERVER
);