/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2016 Nexenta Systems, Inc.
*/
/*
* NFS specific functions
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <zone.h>
#include <errno.h>
#include <locale.h>
#include <signal.h>
#include <strings.h>
#include "libshare.h"
#include "libshare_impl.h"
#include <pwd.h>
#include <grp.h>
#include <limits.h>
#include <libscf.h>
#include <syslog.h>
#include <rpcsvc/daemon_utils.h>
#include "nfslog_config.h"
#include "nfslogtab.h"
#include "libshare_nfs.h"
#include <netconfig.h>
#include "smfcfg.h"
/* should really be in some global place */
int debug = 0;
/* internal functions */
static int nfs_init();
static void nfs_fini();
static int nfs_enable_share(sa_share_t);
static int nfs_disable_share(sa_share_t, char *);
static int nfs_validate_security_mode(char *);
static int nfs_is_security_opt(char *);
static int nfs_parse_legacy_options(sa_group_t, char *);
static char *nfs_format_options(sa_group_t, int);
static int nfs_set_proto_prop(sa_property_t);
static sa_protocol_properties_t nfs_get_proto_set();
static char *nfs_get_status();
static char *nfs_space_alias(char *);
static uint64_t nfs_features();
/*
* ops vector that provides the protocol specific info and operations
* for share management.
*/
"nfs",
NULL, /* update_legacy */
NULL, /* delete_legacy */
NULL, /* change_notify */
NULL, /* enable_resource */
NULL, /* disable_resource */
NULL, /* transient shares */
NULL, /* notify resource */
NULL, /* rename_resource */
NULL, /* run_command */
NULL, /* command_help */
NULL /* delete_proto_section */
};
/*
* list of support services needed
* defines should come from head/rpcsvc/daemon_utils.h
*/
static char *service_list_default[] =
static char *service_list_logging[] =
NULL };
/*
* option definitions. Make sure to keep the #define for the option
* index just before the entry it is the index for. Changing the order
* can cause breakage. E.g OPT_RW is index 1 and must precede the
* line that includes the SHOPT_RW and OPT_RW entries.
*/
#define OPT_RO 0
#ifdef VOLATILE_FH_TEST /* XXX added for testing volatile fh's only */
{SHOPT_VOLFH, OPT_VOLFH},
#endif /* VOLATILE_FH_TEST */
};
/*
* Codesets that may need to be converted to UTF-8 for file paths.
* Add new names here to add new property support. If we ever get a
* way to query the kernel for character sets, this should become
* dynamically loaded. Make sure changes here are reflected in
*/
static char *legal_conv[] = {
"euc-cn",
"euc-jp",
"euc-jpms",
"euc-kr",
"euc-tw",
"iso8859-1",
"iso8859-2",
"iso8859-5",
"iso8859-6",
"iso8859-7",
"iso8859-8",
"iso8859-9",
"iso8859-13",
"iso8859-15",
"koi8-r",
};
/*
* list of properties that are related to security flavors.
*/
static char *seclist[] = {
};
/* structure for list of securities */
struct securities {
};
/*
* findcharset(charset)
*
* Returns B_TRUE if the charset is a legal conversion otherwise
* B_FALSE. This will need to be rewritten to be more efficient when
* we have a dynamic list of legal conversions.
*/
static boolean_t
{
int i;
for (i = 0; legal_conv[i] != NULL; i++)
return (B_TRUE);
return (B_FALSE);
}
/*
* findopt(name)
*
* Lookup option "name" in the option table and return the table
* index.
*/
static int
{
int i;
}
if (findcharset(name))
return (OPT_CHARSET_MAP);
}
return (-1);
}
/*
* gettype(name)
*
* Return the type of option "name".
*/
static int
{
int optdef;
if (optdef != -1)
return (OPT_TYPE_ANY);
}
/*
* nfs_validate_security_mode(mode)
*
* is the specified mode string a valid one for use with NFS?
*/
static int
{
int err;
if (err == SC_NOERROR)
return (1);
return (0);
}
/*
* nfs_is_security_opt(tok)
*
* check to see if tok represents an option that is only valid in some
* security flavor.
*/
static int
{
int i;
return (1);
}
return (0);
}
/*
* find_security(seclist, sec)
*
* Walk the current list of security flavors and return true if it is
* present, else return false.
*/
static int
{
return (1);
}
return (0);
}
/*
* make_security_list(group, securitymodes, proto)
* go through the list of securitymodes and add them to the
* group's list of security optionsets. We also keep a list of
* those optionsets so we don't have to find them later. All of
* these will get copies of the same properties.
*/
static struct securities *
{
int freetok = 0;
*next++ = '\0';
/* resolve default into the real type */
freetok = 1;
}
/* add to the security list if it isn't there already */
sizeof (struct securities));
} else {
}
/*
* note that the first time through the loop,
* headp will be NULL and prev will be
* undefined. Since headp is NULL, we set
* both it and prev to the curp (first
* structure to be allocated).
*
* later passes through the loop will have
* headp not being NULL and prev will be used
* to allocate at the end of the list.
*/
} else {
}
}
}
if (freetok) {
freetok = 0;
}
}
return (headp);
}
static void
{
}
}
}
/*
* nfs_alistcat(str1, str2, sep)
*
* concatenate str1 and str2 into a new string using sep as a separate
* character. If memory allocation fails, return NULL;
*/
static char *
{
char *newstr;
return (newstr);
}
/*
* add_security_prop(sec, name, value, persist, iszfs)
*
* Add the property to the securities structure. This accumulates
* properties for as part of parsing legacy options.
*/
static int
{
value = "*";
else
value = "true";
}
/*
* Get the existing property, if it exists, so we can
* properties can be merged if multiple instances of
* these properies are given. For example, if "rw"
* exists with a value "host1" and a later token of
* rw="host2" is seen, the values are merged into a
* single rw="host1:host2".
*/
char *oldvalue;
char *newvalue;
/*
* might appear multiple times. If they do, the values
* need to be merged. If it was previously empty, the
* new value alone is added.
*/
sep = '~';
/*
* The general case is to concatenate the new
* value onto the old value for multiple
* the old or new is the "all" case. In the
* special case, if both are "all", then it is
* "all", else if one is an access-list, that
* replaces the "all".
*/
/* Replace old value with new value. */
/*
* Keep old value and ignore
* the new value.
*/
} else {
/*
* Make a new list of old plus new
* access-list.
*/
}
(void) sa_remove_property(prop);
newvalue);
prop);
}
}
} else {
}
}
}
return (ret);
}
/*
*/
static int
{
char *type;
persist = 0;
return (persist);
}
/*
* invalid_security(options)
*
* search option string for any invalid sec= type.
* return true (1) if any are not valid else false (0)
*/
static int
{
int ret = 0;
*value++ = '\0';
/* HAVE security flavors so check them */
*next++ = '\0';
if (ret)
break;
}
}
}
}
return (ret);
}
/*
* nfs_parse_legacy_options(group, options)
*
* Parse the old style options into internal format and store on the
* specified group. Group could be a share for full legacy support.
*/
static int
{
char *dup;
char *base;
char *token;
int iszfs = 0;
int persist = 0;
char *lasts;
/* do we have an existing optionset? */
/* didn't find existing optionset so create one */
} else {
/*
* Have an existing optionset . Ideally, we would need
* to compare options in order to detect errors. For
* now, we assume that the first optionset is the
* correct one and the others will be the same. An
* empty optionset is the same as no optionset so we
* don't want to exit in that case. Getting an empty
* optionset can occur with ZFS property checking.
*/
return (ret);
}
/*
* there is a special case of only the option "rw"
* being the default option. We don't have to do
* anything.
*/
return (ret);
}
/*
* check if security types are present and validate them. If
* any are not legal, fail.
*/
if (invalid_security(options)) {
return (SA_INVALID_SECURITY);
}
/*
* in order to not attempt to change ZFS properties unless
* absolutely necessary, we never do it in the legacy parsing.
*/
if (sa_is_share(group)) {
char *zfs;
iszfs++;
}
}
} else {
}
/* We need a copy of options for the next part. */
return (SA_NO_MEMORY);
/*
* we need to step through each option in the string and then
* add either the option or the security option as needed. If
* this is not a persistent share, don't commit to the
* repository. If there is an error, we also want to abort the
* processing and report it.
*/
char *value;
/*
* if the option has a value, it will have an '=' to
* separate the name from the value. The following
* code will result in value != NULL and token
* pointing to just the name if there is a value.
*/
*value++ = '\0';
}
/*
* Once in security parsing, we only
* do security. We do need to move
* between the security node and the
* toplevel. The security tag goes on
* the root while the following ones
* go on the security.
*/
if (security_list != NULL) {
/*
* have an old list so close it and
* start the new
*/
}
value = "dh";
} else {
ret = SA_SYNTAX_ERR;
break;
}
}
value, "nfs");
} else {
/*
* Note that the "old" syntax allowed a
* default security model. This must be
* accounted for and internally converted to
* "standard" security structure.
*/
if (nfs_is_security_opt(token)) {
if (security_list == NULL) {
/*
* need to have a
* security
* option. This will
* be "closed" when a
* defined "sec="
* option is
* seen. This is
* technically an
* error but will be
* allowed with
* warning.
*/
"default",
"nfs");
}
if (security_list != NULL) {
} else {
ret = SA_NO_MEMORY;
}
} else {
/* regular options */
SHOPT_RO) == 0) {
value = "*";
} else {
value = "global";
SHOPT_LOG) != 0) {
value = "true";
}
}
}
/*
* In all cases, create the
* property specified. If the
* value was NULL, the default
* value will have been
* substituted.
*/
break;
if (!iszfs) {
}
}
}
}
}
if (security_list != NULL)
return (ret);
}
/*
* is_a_number(number)
*
* is the string a number in one of the forms we want to use?
*/
static int
{
int hex = 0;
number += 2;
hex = 1;
} else if (*number == '-') {
number++; /* skip the minus */
}
if (hex) {
} else {
}
}
return (ret);
}
/*
* Look for the specified tag in the configuration file. If it is found,
* enable logging and set the logging configuration information for exp.
*/
static void
{
int error = 0;
/*
* Sends config errors to stderr
*/
/*
* get the list of configuration settings
*/
if (error) {
}
/* bad configuration */
goto err;
}
goto out;
}
goto out;
}
out:
if (configlist != NULL)
err:
if (error != 0) {
}
}
/*
* fill_export_from_optionset(export, optionset)
*
* In order to share, we need to set all the possible general options
* into the export structure. Share info will be filled in by the
* caller. Various property values get turned into structure specific
* values.
*/
static int
{
char *name;
char *value;
/*
* explicit set or clear of the option. This allows defaults
* to be set and then the protocol specific to override.
*/
case OPT_ANON:
} else {
} else {
val = UID_NOBODY;
}
endpwent();
}
break;
case OPT_NOSUID:
else
break;
case OPT_ACLOK:
else
break;
case OPT_NOSUB:
else
break;
case OPT_PUBLIC:
else
break;
case OPT_INDEX:
/* this is an error */
"NFS: index=\"%s\" not valid;"
"must be a filename.\n"),
value);
break;
}
/* valid index file string */
/* left over from "default" */
}
/* remember to free */
"NFS: out of memory setting "
"index property\n"));
break;
}
}
break;
case OPT_LOG:
break;
case OPT_CHARSET_MAP:
/*
* Set EX_CHARMAP when there is at least one
* charmap conversion property. This will get
* checked by the nfs server when it needs to.
*/
break;
case OPT_NOACLFAB:
else
break;
default:
/* have a syntactic error */
"NFS: unrecognized option %s=%s\n"),
break;
}
}
return (ret);
}
/*
* cleanup_export(export)
*
* Cleanup the allocated areas so we don't leak memory
*/
static void
{
int i;
while (s->s_rootcnt > 0)
free(s->s_rootnames);
}
}
/*
* Given a seconfig entry and a colon-separated
* list of names, allocate an array big enough
* to hold the root list, then convert each name to
* a principal name according to the security
* info and assign it to an array element.
* Return the array and its size.
*/
static caddr_t *
{
caddr_t *a;
int c, i;
char *host, *p;
/*
* Count the number of strings in the list.
* This is the number of colon separators + 1.
*/
c = 1;
for (p = list; *p; p++)
if (*p == ':')
c++;
*count = c;
if (a == NULL) {
"get_rootnames: no memory\n"));
*count = 0;
} else {
for (i = 0; i < c; i++) {
while (i > 0)
free(a[--i]);
free(a);
a = NULL;
*count = 0;
break;
}
}
}
return (a);
}
/*
* fill_security_from_secopts(sp, secopts)
*
* Fill the secinfo structure from the secopts optionset.
*/
static int
{
char *type;
int longform;
/* named security type needs secinfo to be filled in */
if (err != SC_NOERROR)
return (err);
} else {
/* default case */
if (err != SC_NOERROR)
return (err);
}
char *name;
char *value;
case OPT_RO:
break;
case OPT_RW:
break;
case OPT_ROOT:
/*
* if we are using AUTH_UNIX, handle like other things
*/
break;
/* not AUTH_UNIX */
err = SA_BAD_VALUE;
"Bad root list\n"));
}
}
break;
case OPT_NONE:
break;
case OPT_WINDOW:
/* just in case */
}
break;
case OPT_ROOT_MAPPING:
} else {
} else {
val = UID_NOBODY;
}
endpwent();
}
break;
case OPT_UIDMAP:
case OPT_GIDMAP:
break;
default:
break;
}
}
return (err);
}
/*
* This is for testing only
* It displays the export structure that
* goes into the kernel.
*/
static void
{
int i, j;
if (debug == 0)
return;
(void) printf("NOSUID ");
(void) printf("ACLOK ");
(void) printf("PUBLIC ");
(void) printf("NOSUB ");
(void) printf("LOG ");
(void) printf("CHARMAP ");
(void) printf("LOG_ALLOPS ");
(void) printf("(none)");
(void) printf("\n");
(void) printf("\tex_log_buffer = %s\n",
(void) printf("\tex_tag = %s\n",
}
(void) printf("\n");
(void) printf("\n");
(void) printf("\n\n");
}
}
/*
* count_security(opts)
*
* Count the number of security types (flavors). The optionset has
* been populated with the security flavors as a holding mechanism.
* We later use this number to allocate data structures.
*/
static int
{
int count = 0;
count++;
}
}
return (count);
}
/*
* nfs_sprint_option(rbuff, rbuffsize, incr, prop, sep)
*
* provides a mechanism to format NFS properties into legacy output
* format. If the buffer would overflow, it is reallocated and grown
* as appropriate. Special cases of converting internal form of values
* to those used by "share" are done. this function does one property
* at a time.
*/
static int
{
char *name;
char *value;
int curlen;
else
curlen = 0;
int len;
/*
* A future RFE would be to replace this with more
* generic code and to possibly handle more types.
*/
case OPT_TYPE_BOOLEAN:
/*
* For NFS, boolean value of FALSE means it
* doesn't show up in the option list at all.
*/
goto skip;
}
break;
case OPT_TYPE_ACCLIST:
} else {
}
break;
case OPT_TYPE_LOGTAG:
} else {
}
break;
default:
break;
}
/* need more room */
/* realloc failed so free everything */
}
goto skip;
}
goto skip;
} else {
}
}
skip:
return (printed);
}
/*
* nfs_format_options(group, hier)
*
* format all the options on the group into an old-style option
* string. If hier is non-zero, walk up the tree to get inherited
* options.
*/
static char *
{
char *buff;
int sep = 0;
return (NULL);
}
buff[0] = '\0';
/*
* We may have a an optionset relative to this item. format
* these if we find them and then add any security definitions.
*/
/*
* do the default set first but skip any option that is also
* in the protocol specific optionset.
*/
/*
* use this one since we skipped any
* of these that were also in
* optdefault
*/
sep = 1;
/*
* buff could become NULL if there
* isn't enough memory for
* nfs_sprint_option to realloc()
* as necessary. We can't really
* do anything about it at this
* point so we return NULL. The
* caller should handle the
* failure.
*/
options);
return (buff);
}
}
}
"nfs", hier);
if (secoptions != NULL) {
security =
"sec", sectype);
goto err;
if (nfs_sprint_option(&buff,
sep = 1;
(void) sa_remove_property(prop);
goto err;
}
if (nfs_sprint_option(&buff,
sep = 1;
goto err;
}
}
}
}
return (buff);
err:
/*
* If we couldn't allocate memory for option printing, we need
* to break out of the nested loops, cleanup and return NULL.
*/
if (secoptions != NULL)
return (buff);
}
/*
* Append an entry to the nfslogtab file
*/
static int
{
FILE *f;
int error = 0;
/*
* Open the file for update and create it if necessary.
* This may leave the I/O offset at the end of the file,
* so rewind back to the beginning of the file.
*/
if (f == NULL) {
goto out;
}
rewind(f);
"share complete, however failed to lock %s "
error = -1;
goto out;
}
if (logtab_deactivate_after_boot(f) == -1) {
"share complete, however could not deactivate "
"entries in %s\n"), NFSLOGTAB);
error = -1;
goto out;
}
/*
* Remove entries matching buffer and sharepoint since we're
* going to replace it with perhaps an entry with a new tag.
*/
"share complete, however could not remove matching "
"entries in %s\n"), NFSLOGTAB);
error = -1;
goto out;
}
/*
* Deactivate all active entries matching this sharepoint
*/
"share complete, however could not deactivate matching "
"entries in %s\n"), NFSLOGTAB);
error = -1;
goto out;
}
/*
* Add new sharepoint / buffer location to nfslogtab
*/
if (logtab_putent(f, &lep) < 0) {
"share complete, however could not add %s to %s\n"),
error = -1;
}
out:
if (f != NULL)
(void) fclose(f);
return (error);
}
/*
* Deactivate an entry from the nfslogtab file
*/
static int
{
FILE *f;
int error = 0;
if (f == NULL) {
goto out;
}
"share complete, however could not lock %s for "
goto out;
}
error = -1;
"share complete, however could not "
goto out;
}
(void) fclose(f);
return (error);
}
/*
* check_public(group, skipshare)
*
* Check the group for any shares that have the public property
* enabled. We skip "skipshare" since that is the one we are
* working with. This is a separate function to make handling
* subgroups simpler. Returns true if there is a share with public.
*/
static int
{
char *shared;
continue;
continue;
continue;
break;
}
}
return (exists);
}
/*
* public_exists(handle, skipshare)
*
* check to see if public option is set on any other share than the
* one specified. Need to check zfs sub-groups as well as the top
* level groups.
*/
static int
{
/*
* If we don't have a handle, we can only do syntax check. We
* can't check against other shares so we assume OK and will
* catch the problem only when we actually try to apply it.
*/
return (SA_OK);
return (SA_NO_SUCH_GROUP);
}
/* Walk any ZFS subgroups as well as all standard groups */
if (sa_group_is_zfs(group)) {
return (B_TRUE);
}
} else {
return (B_TRUE);
}
}
return (B_FALSE);
}
/*
* sa_enable_share at the protocol level, enable_share must tell the
* implementation that it is to enable the share. This entails
* converting the path and options into the appropriate ioctl
* calls. It is assumed that all error checking of paths, etc. were
* done earlier.
*/
static int
{
int num_secinfo;
char *path;
int i;
int iszfs;
/* Don't drop core if the NFS module isn't loaded. */
/* get the path since it is important in several places */
return (SA_NO_SUCH_PATH);
/*
* find the optionsets and security sets. There may not be
* any or there could be one or two for each of optionset and
* security may have multiple, one per security type per
* protocol type.
*/
if (secoptlist != NULL)
else
num_secinfo = 1;
/*
* walk through the options and fill in the structure
* appropriately.
*/
/*
* do non-security options first since there is only one after
* the derived group is constructed.
*/
/*
* check to see if "public" is set. If it is, then make sure
* no other share has it set. If it is already used, fail.
*/
"NFS: Cannot share more than one file "
"system with 'public' property\n"));
goto out;
}
err = SA_NO_MEMORY;
"NFS: NFS: no memory for security\n"));
goto out;
}
/* get default secinfo */
/*
* since we must have one security option defined, we
* init to the default and then override as we find
* defined security options. This handles the case
* where we have no defined options but we need to set
* up one.
*/
/* setup a default in case no properties defined */
"NFS: nfs_getseconfig_default: failed to "
"get default security mode\n"));
err = SA_CONFIG_ERR;
}
if (secoptlist != NULL) {
char *sectype;
/*
* if sectype is NULL, we probably
* have a memory problem and can't get
* the correct values. Rather than
* exporting with incorrect security,
* don't share it.
*/
err = SA_NO_MEMORY;
"NFS: Cannot share %s: "
"no memory\n"), path);
goto out;
}
}
}
/*
* when we get here, we can do the exportfs system call and
* initiate things. We probably want to enable the
*/
/* now add the share to the internal tables */
/*
* call the exportfs system call which is implemented
* via the nfssys() call as the EXPORTFS subfunction.
*/
if (iszfs) {
char *str;
int privileged;
/*
* If we aren't a privileged user
* and NFS server service isn't running
* then print out an error message
* and return EPERM
*/
if (!privileged &&
err = 0;
"NFS: Cannot share remote "
"filesystem: %s\n"), path);
"NFS: Service needs to be enabled "
"by a privileged user\n"));
err = SA_SYSTEM_ERR;
}
}
if (err == 0) {
&ea, ZFS_SHARE_NFS);
err = -1;
}
sa_emptyshare(&sh);
}
} else {
}
if (err < 0) {
err = SA_SYSTEM_ERR;
switch (errno) {
case EREMOTE:
"NFS: Cannot share filesystems "
"in non-global zones: %s\n"), path);
break;
case EPERM:
if (getzoneid() != GLOBAL_ZONEID) {
"NFS: Cannot share file systems "
"in non-global zones: %s\n"), path);
break;
}
break;
case EEXIST:
break;
default:
break;
}
} else {
if (!iszfs) {
}
}
/*
* enable services as needed. This should probably be
* done elsewhere in order to minimize the calls to
* check services.
*/
/*
* check to see if logging and other services need to
* be triggered, but only if there wasn't an
* error. This is probably where sharetab should be
* updated with the NFS specific entry.
*/
/* enable logging */
"Could not enable logging for %s\n"),
path);
}
} else {
/*
* don't have logging so remove it from file. It might
* not be thre, but that doesn't matter.
*/
(void) nfslogtab_deactivate(path);
}
}
out:
if (secoptlist != NULL)
(void) sa_destroy_optionset(secoptlist);
return (err);
}
/*
* nfs_disable_share(share, path)
*
* Unshare the specified share. Note that "path" is the same path as
* what is in the "share" object. It is passed in to avoid an
* additional lookup. A missing "path" value makes this a no-op
* function.
*/
static int
{
int err;
int iszfs;
return (ret);
/*
* If the share is in a ZFS group we need to handle it
* differently. Just being on a ZFS file system isn't
* enough since we may be in a legacy share case.
*/
if (iszfs) {
&ea, ZFS_UNSHARE_NFS);
err = -1;
}
} else {
}
if (err < 0) {
/*
* TBD: only an error in some
* cases - need better analysis
*/
switch (errno) {
case EPERM:
case EACCES:
if (getzoneid() != GLOBAL_ZONEID) {
}
break;
case EINVAL:
case ENOENT:
break;
default:
ret = SA_SYSTEM_ERR;
break;
}
}
if (!iszfs)
/* just in case it was logged */
(void) nfslogtab_deactivate(path);
}
return (ret);
}
static int
{
if (!is_a_number(value)) {
/*
* in this case it would have to be a
* user name
*/
ret = SA_BAD_VALUE;
endpwent();
} else {
ret = SA_BAD_VALUE;
}
return (ret);
}
static int
{
if (!is_a_number(value)) {
/*
* in this case it would have to be a
* group name
*/
ret = SA_BAD_VALUE;
endgrent();
} else {
ret = SA_BAD_VALUE;
}
return (ret);
}
/*
* check_rorwnone(v1, v2, v3)
*
* check ro vs rw vs none values. Over time this may get beefed up.
* for now it just does simple checks. v1 is never NULL but v2 or v3
* could be.
*/
static int
{
return (ret);
}
/*
* nfs_validate_property(handle, property, parent)
*
* Check that the property has a legitimate value for its type.
*/
static int
{
char *propname;
char *other1;
char *other2;
int optindex;
char *value;
/* need to validate value range here as well */
}
/*
* Public is special in that only one instance can
* be in the repository at the same time.
*/
return (SA_VALUE_CONFLICT);
}
}
/* first basic type checking */
case OPT_TYPE_NUMBER:
/* check that the value is all digits */
if (!is_a_number(value))
ret = SA_BAD_VALUE;
break;
case OPT_TYPE_BOOLEAN:
} else {
ret = SA_BAD_VALUE;
}
break;
case OPT_TYPE_USER:
break;
case OPT_TYPE_FILE:
ret = SA_BAD_VALUE;
}
break;
case OPT_TYPE_ACCLIST: {
break;
/*
* access list handling. Should eventually
* validate that all the values make sense.
* Also, ro and rw may have cross value
* conflicts.
*/
other2 = SHOPT_NONE;
other2 = SHOPT_NONE;
} else {
}
break;
/* compare rw(ro) with ro(rw) */
break;
/*
* Only potential confusion if other1
* or other2 exists. Check the values
* and run the check if there is a
* value other than the one we are
* explicitly looking at.
*/
ovalue2);
break;
}
case OPT_TYPE_LOGTAG:
if (nfsl_getconfig_list(&configlist) == 0) {
int error;
value);
}
ret = SA_BAD_VALUE;
}
/* Must always free when done */
} else {
ret = SA_CONFIG_ERR;
}
break;
case OPT_TYPE_STRING:
/* whatever is here should be ok */
break;
case OPT_TYPE_SECURITY:
/*
* The "sec" property isn't used in the
* non-legacy parts of sharemgr. We need to
* reject it here. For legacy, it is pulled
* out well before we get here.
*/
break;
case OPT_TYPE_MAPPING: {
char *p;
char *n;
char *c;
int (*f)(char *);
/*
* mapping is only supported for sec=sys
*/
ret = SA_CONFIG_ERR;
if (parent_group == NULL)
break;
char *type;
char *sectype;
"type");
continue;
continue;
}
"sectype");
continue;
ret = SA_CONFIG_ERR;
break;
}
}
break;
optindex == OPT_GIDMAP);
if (p == NULL)
ret = SA_BAD_VALUE;
char *s;
char *t;
n = strchr(c, '~');
if (n != NULL)
*n++ = '\0';
s = strchr(c, ':');
if (s != NULL) {
*s++ = '\0';
t = strchr(s, ':');
if (t != NULL)
*t = '\0';
}
ret = SA_BAD_VALUE;
strcmp(c, "*") != 0)
ret = f(c);
strcmp(s, "-1") != 0)
ret = f(s);
}
free(p);
break;
}
default:
break;
}
/* do the property specific check */
}
}
}
return (ret);
}
/*
* Protocol management functions
*
* Properties defined in the default files are defined in
* proto_option_defs for parsing and validation. If "other" and
* "compare" are set, then the value for this property should be
* compared against the property specified in "other" using the
* "compare" check (either <= or >=) in order to ensure that the
* values are in the correct range. E.g. setting server_versmin
* higher than server_versmax should not be allowed.
*/
struct proto_option_defs {
char *tag;
int index;
int type;
union {
int intval;
char *string;
} defvalue;
char *other;
int compare;
#define OPT_CMP_GE 0
int (*check)(char *);
} proto_options[] = {
#define PROTO_OPT_NFSD_SERVERS 0
{"nfsd_servers",
1, INT32_MAX},
{"lockd_listen_backlog",
"lockd_listen_backlog", PROTO_OPT_LOCKD_LISTEN_BACKLOG,
{"lockd_servers",
{"lockd_retransmit_timeout",
"lockd_retransmit_timeout", PROTO_OPT_LOCKD_RETRANSMIT_TIMEOUT,
{"grace_period",
{"nfs_server_versmin",
{"nfs_server_versmax",
{"nfs_client_versmin",
"client_versmax", OPT_CMP_LE},
{"nfs_client_versmax",
"client_versmin", OPT_CMP_GE},
{"nfs_server_delegation",
"server_delegation", PROTO_OPT_NFS_SERVER_DELEGATION,
{"nfsmapid_domain",
NULL, SVC_NFSMAPID, 0, 0},
{"nfsd_max_connections",
"max_connections", PROTO_OPT_NFSD_MAX_CONNECTIONS,
{"nfsd_protocol",
SVC_NFSD, 0, 0},
{"nfsd_listen_backlog",
"listen_backlog", PROTO_OPT_NFSD_LISTEN_BACKLOG,
{"nfsd_device",
"device", PROTO_OPT_NFSD_DEVICE,
{"mountd_listen_backlog",
"mountd_listen_backlog", PROTO_OPT_MOUNTD_LISTEN_BACKLOG,
{"mountd_max_threads",
"mountd_max_threads", PROTO_OPT_MOUNTD_MAX_THREADS,
{NULL}
};
/*
* the protoset holds the defined options so we don't have to read
* them multiple times
*/
static int
{
int i;
if (whichname == 1) {
return (i);
} else {
return (i);
}
}
return (-1);
}
/*
* fixcaselower(str)
*
* convert a string to lower case (inplace).
*/
static void
{
while (*str) {
str++;
}
}
/*
* skipwhitespace(str)
*
* Skip leading white space. It is assumed that it is called with a
* valid pointer.
*/
static char *
{
str++;
return (str);
}
/*
* extractprop()
*
* Extract the property and value out of the line and create the
* property in the optionset.
*/
static int
{
int index;
/*
* Remove any leading
* white space.
*/
if (index >= 0) {
else
ret = SA_NO_MEMORY;
}
return (ret);
}
{
switch (type) {
case OPT_TYPE_NUMBER:
break;
case OPT_TYPE_BOOLEAN:
break;
default:
}
return (ret);
}
char *
{
char *service;
switch (svcs) {
case SVC_LOCKD:
break;
case SVC_STATD:
break;
case SVC_NFSD:
break;
case SVC_CLIENT:
break;
case SVC_NFS4CBD:
break;
case SVC_NFSMAPID:
break;
case SVC_RQUOTAD:
break;
case SVC_NFSLOGD:
break;
case SVC_REPARSED:
break;
default:
}
return (service);
}
/*
* initprotofromsmf()
*
* Read NFS SMF properties and add the defined values to the
* protoset. Note that default values are known from the built in
* table in case SMF doesn't have a definition. Not having
* SMF properties is OK since we have builtin default
* values.
*/
static int
{
char *svc_name;
/* Replace NULL with the correct instance */
(char *)DEFAULT_INSTANCE, ptype,
}
}
} else {
ret = SA_NO_MEMORY;
}
return (ret);
}
/*
* add_defaults()
*
* Add the default values for any property not defined
* in NFS SMF repository.
* Values are set according to their defined types.
*/
static void
{
int i;
proto_options[i].name);
/* add the default value */
switch (proto_options[i].type) {
case OPT_TYPE_NUMBER:
number);
break;
case OPT_TYPE_BOOLEAN:
"true" : "false");
break;
case OPT_TYPE_ONOFF:
"on" : "off");
break;
default:
/* treat as strings of zero length */
"");
break;
}
}
}
}
static void
{
}
}
/*
* nfs_init()
*
* Initialize the NFS plugin.
*/
static int
nfs_init()
{
"NFS plugin not properly initialized\n"));
return (SA_CONFIG_ERR);
}
ret = initprotofromsmf();
"NFS plugin problem with SMF repository: %s\n"),
sa_errorstr(ret));
}
add_defaults();
return (ret);
}
/*
* nfs_fini()
*
* uninitialize the NFS plugin. Want to avoid memory leaks.
*/
static void
nfs_fini()
{
}
/*
* nfs_get_proto_set()
*
* Return an optionset with all the protocol specific properties in
* it.
*/
static sa_protocol_properties_t
{
return (protoset);
}
/*
* service_in_state(service, chkstate)
*
* Want to know if the specified service is in the desired state
* (chkstate) or not. Return true (1) if it is and false (0) if it
* isn't.
*/
static int
{
char *state;
/* got the state so get the equality for the return value */
}
return (ret);
}
/*
* restart_service(svcs)
*
* Walk through the bit mask of services that need to be restarted in
* order to use the new property values. Some properties affect
* multiple daemons. Should only restart a service if it is currently
* enabled (online).
*/
static void
{
int ret;
char *service;
case SVC_LOCKD:
break;
case SVC_STATD:
break;
case SVC_NFSD:
break;
case SVC_MOUNTD:
break;
case SVC_NFS4CBD:
break;
case SVC_NFSMAPID:
break;
case SVC_RQUOTAD:
break;
case SVC_NFSLOGD:
break;
case SVC_REPARSED:
break;
case SVC_CLIENT:
break;
default:
continue;
}
/*
* Only attempt to restart the service if it is
* currently running. In the future, it may be
* desirable to use smf_refresh_instance if the NFS
* services ever implement the refresh method.
*/
/*
* There are only a few SMF errors at this point, but
* it is also possible that a bad value may have put
* the service into maintenance if there wasn't an
* SMF level error.
*/
if (ret != 0) {
"%s failed to restart: %s\n"),
} else {
/*
* Check whether it has gone to "maintenance"
* mode or not. Maintenance implies something
* went wrong.
*/
if (service_in_state(service,
"%s failed to restart\n"),
service);
}
}
}
}
}
/*
* nfs_minmax_check(name, value)
*
* Verify that the value for the property specified by index is valid
* Currently, server_minvers/server_maxvers and
* client_minvers/client_maxvers are the only ones to check.
*/
static int
{
int val;
char *pval;
/* have a property to compare against */
opts = nfs_get_proto_set();
/*
* If we don't find the property, assume default
* values which will work since the max will be at the
* max and the min at the min.
*/
OPT_CMP_LE) {
OPT_CMP_GE) {
}
}
}
}
return (ret);
}
/*
* nfs_validate_proto_prop(index, name, value)
*
* Verify that the property specified by name can take the new
* value. This is a sanity check to prevent bad values getting into
* the default files. All values need to be checked against what is
* allowed by their defined type. If a type isn't explicitly defined
* here, it is treated as a string.
*
* Note that OPT_TYPE_NUMBER will additionally check that the value is
* within the range specified and potentially against another property
* value as well as specified in the proto_options members other and
* compare.
*/
static int
{
char *cp;
#ifdef lint
#endif
case OPT_TYPE_NUMBER:
if (!is_a_number(value))
ret = SA_BAD_VALUE;
else {
int val;
ret = SA_BAD_VALUE;
/*
* For server_versmin/server_versmax and
* client_versmin/client_versmax, the value of the
* min(max) should be checked to be correct relative
* to the current max(min).
*/
ret = SA_BAD_VALUE;
}
}
break;
case OPT_TYPE_DOMAIN:
/*
* needs to be a qualified domain so will have at
* least one period and other characters on either
* side of it. A zero length string is also allowed
* and is the way to turn off the override.
*/
break;
ret = SA_BAD_VALUE;
break;
case OPT_TYPE_BOOLEAN:
} else {
ret = SA_BAD_VALUE;
}
break;
case OPT_TYPE_ONOFF:
ret = SA_BAD_VALUE;
}
break;
case OPT_TYPE_PROTOCOL: {
void *nc;
break;
} else {
break;
}
}
(void) endnetconfig(nc);
}
if (!pfound)
ret = SA_BAD_VALUE;
break;
}
default:
/* treat as a string */
break;
}
return (ret);
}
/*
* nfs_set_proto_prop(prop)
*
* check that prop is valid.
*/
static int
{
char *name;
char *value;
char *svc_name;
if (sctype == SCF_TYPE_BOOLEAN) {
if (string_to_boolean(value) == 0)
else
}
svc_name);
} else {
"Cannot restart NFS services : %s\n"),
sa_errorstr(ret));
}
}
}
return (ret);
}
/*
* nfs_get_status()
*
* What is the current status of the nfsd? We use the SMF state here.
* Caller must free the returned value.
*/
static char *
{
return (smf_get_state(NFSD));
}
/*
* nfs_space_alias(alias)
*
* Lookup the space (security) name. If it is default, convert to the
* real name.
*/
static char *
{
/*
* Only the space named "default" is special. If it is used,
* the default needs to be looked up and the real name used.
* This is normally "sys" but could be changed. We always
* change default to the real name.
*/
nfs_getseconfig_default(&secconf) == 0) {
}
}
/*
* nfs_features()
*
* Return a mask of the features required.
*/
static uint64_t
{
}