libshare_nfs.c revision 8e314a4400960b022e9b9135577c1c0ceebd1e36
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* 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 "libshare.h"
#include "libshare_impl.h"
#include <pwd.h>
#include <limits.h>
#include <libscf.h>
#include "nfslog_config.h"
#include "nfslogtab.h"
#include "libshare_nfs.h"
#include <rpcsvc/daemon_utils.h>
/* should really be in some global place */
#define DEF_WIN 30000
#define OPT_CHUNK 1024
int debug = 0;
#define NFS_SERVER_SVC "svc:/network/nfs/server:default"
/* 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.
*/
struct sa_plugin_ops sa_plugin_ops = {
"nfs",
NULL, /* update_legacy */
NULL, /* delete_legacy */
NULL, /* change_notify */
NULL, /* enable_resource */
NULL, /* disable_resource */
NULL, /* transient shares */
NULL, /* notify resource */
};
/*
* list of support services needed
* defines should come from head/rpcsvc/daemon_utils.h
*/
static char *service_list_default[] =
static char *service_list_logging[] =
/*
* 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.
*/
struct option_defs optdefs[] = {
#define OPT_RO 0
#define OPT_RW 1
#define OPT_ROOT 2
#define OPT_SECURE 3
#define OPT_ANON 4
#define OPT_WINDOW 5
#define OPT_NOSUID 6
#define OPT_ACLOK 7
#define OPT_NOSUB 8
#define OPT_SEC 9
#define OPT_PUBLIC 10
#define OPT_INDEX 11
#define OPT_LOG 12
#define OPT_CKSUM 13
#ifdef VOLATILE_FH_TEST /* XXX added for testing volatile fh's only */
#define OPT_VOLFH 14
{SHOPT_VOLFH, OPT_VOLFH},
#endif /* VOLATILE_FH_TEST */
};
/*
* list of properties that are related to security flavors.
*/
static char *seclist[] = {
};
/* structure for list of securities */
struct securities {
struct securities *next;
};
/*
* findopt(name)
*
* Lookup option "name" in the option table and return the table
* index.
*/
static int
{
int i;
return (i);
}
}
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
nfs_validate_security_mode(char *mode)
{
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
nfs_is_security_opt(char *tok)
{
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
{
struct securities *next;
}
}
}
/*
* 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)
*
* 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;
/*
* multiple times. If they do, the values need to be
* merged into an access list. If it was previously
* empty, the new value alone is added.
*/
/*
* The general case is to concatenate the new
* value onto the old value for multiple
* exists when either 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.
*/
value, ':');
}
(void) sa_remove_property(prop);
newvalue);
prop);
}
}
} else {
}
}
}
return (ret);
}
/*
*/
static int
{
char *type;
int persist = 1;
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
invalid_security(char *options)
{
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
is_a_number(char *number)
{
int ret = 1;
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;
char globaltag[] = DEFAULTTAG;
/*
* 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;
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;
}
}
/*
* 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"));
} else {
for (i = 0; i < c; i++) {
free(a);
a = NULL;
break;
}
}
}
return (a);
}
/*
* fill_security_from_secopts(sp, secopts)
*
* Fill the secinfo structure from the secopts optionset.
*/
static int
{
char *type;
int longform;
int err = SC_NOERROR;
/* 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
*/
continue;
/* not AUTH_UNIX */
err = SA_BAD_VALUE;
"Bad root list\n"));
}
}
break;
case OPT_WINDOW:
/* just in case */
}
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("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;
struct logtab_ent lep;
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
char *path;
{
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(share)
*
* 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
{
return (SA_NO_SUCH_GROUP);
return (SA_SYSTEM_ERR);
/* 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
{
struct exportdata export;
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 thinsg. We probably want to enable the nfs.server
* service first if it isn't running within SMF.
*/
/* check nfs.server status and start if needed */
/* 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) {
struct exportfs_args ea;
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);
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;
}
/* FALLTHROUGH */
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) {
struct exportfs_args ea;
&ea, ZFS_UNSHARE_NFS);
} 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);
}
/*
* check ro vs rw values. Over time this may get beefed up.
* for now it just does simple checks.
*/
static int
{
return (ret);
}
/*
* nfs_validate_property(property, parent)
*
* Check that the property has a legitimate value for its type.
*/
static int
{
char *propname;
char *other;
int optindex;
char *value;
/* need to validate value range here as well */
}
/* 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:
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;
}
break;
case OPT_TYPE_FILE:
ret = SA_BAD_VALUE;
}
break;
case OPT_TYPE_ACCLIST:
/*
* access list handling. Should eventually
* validate that all the values make sense.
* Also, ro and rw may have cross value
* conflicts.
*/
else
/* compare rw(ro) with ro(rw) */
/*
* only potential
* confusion if other
* exists
*/
char *ovalue;
oprop, "value");
ovalue);
ovalue);
}
}
}
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;
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;
char *name; /* display name -- remove protocol identifier */
int index;
int type;
union {
int intval;
char *string;
} defvalue;
char *file;
char *other;
int compare;
#define OPT_CMP_GE 0
#define OPT_CMP_LE 1
int (*check)(char *);
} proto_options[] = {
#define PROTO_OPT_NFSD_SERVERS 0
{"nfsd_servers",
#define PROTO_OPT_LOCKD_LISTEN_BACKLOG 1
{"lockd_listen_backlog",
"lockd_listen_backlog", PROTO_OPT_LOCKD_LISTEN_BACKLOG,
#define PROTO_OPT_LOCKD_SERVERS 2
{"lockd_servers",
#define PROTO_OPT_LOCKD_RETRANSMIT_TIMEOUT 3
{"lockd_retransmit_timeout",
"lockd_retransmit_timeout", PROTO_OPT_LOCKD_RETRANSMIT_TIMEOUT,
#define PROTO_OPT_GRACE_PERIOD 4
{"grace_period",
#define PROTO_OPT_NFS_SERVER_VERSMIN 5
{"nfs_server_versmin",
#define PROTO_OPT_NFS_SERVER_VERSMAX 6
{"nfs_server_versmax",
#define PROTO_OPT_NFS_CLIENT_VERSMIN 7
{"nfs_client_versmin",
#define PROTO_OPT_NFS_CLIENT_VERSMAX 8
{"nfs_client_versmax",
#define PROTO_OPT_NFS_SERVER_DELEGATION 9
{"nfs_server_delegation",
"server_delegation", PROTO_OPT_NFS_SERVER_DELEGATION,
NFSADMIN},
#define PROTO_OPT_NFSMAPID_DOMAIN 10
{"nfsmapid_domain",
#define PROTO_OPT_NFSD_MAX_CONNECTIONS 11
{"nfsd_max_connections",
"max_connections", PROTO_OPT_NFSD_MAX_CONNECTIONS,
#define PROTO_OPT_NFSD_PROTOCOL 12
{"nfsd_protocol",
#define PROTO_OPT_NFSD_LISTEN_BACKLOG 13
{"nfsd_listen_backlog",
"listen_backlog", PROTO_OPT_NFSD_LISTEN_BACKLOG,
OPT_TYPE_NUMBER, 0,
{NULL}
};
/*
* the protoset holds the defined options so we don't have to read
* them multiple times
*/
static sa_protocol_properties_t protoset;
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
fixcaselower(char *str)
{
while (*str) {
str++;
}
}
/*
* fixcaseupper(str)
*
* convert a string to upper case (inplace).
*/
static void
fixcaseupper(char *str)
{
while (*str) {
str++;
}
}
/*
* skipwhitespace(str)
*
* Skip leading white space. It is assumed that it is called with a
* valid pointer.
*/
static char *
skipwhitespace(char *str)
{
str++;
return (str);
}
/*
* extractprop()
*
* Extract the property and value out of the line and create the
* property in the optionset.
*/
static void
{
int index;
/*
* Remove any leading
* white space.
*/
if (index >= 0) {
}
}
/*
* initprotofromdefault()
*
* read the default file(s) and add the defined values to the
* protoset. Note that default values are known from the built in
* table in case the file doesn't have a definition.
*/
static int
{
char *name;
char *value;
switch (buff[0]) {
case '\n':
case '#':
/* skip */
break;
default:
*value++ = '\0';
}
}
}
}
}
return (SA_NO_MEMORY);
return (SA_OK);
}
/*
* add_defaults()
*
* Add the default values for any property not defined in the parsing
* of the default files. 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"));
ret = initprotofromdefault();
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);
}
struct deffile {
char *line;
};
/*
* read_default_file(fname)
*
* Read the specified default file. We return a list of entries. This
* get used for adding or removing values.
*/
static struct deffile *
read_default_file(char *fname)
{
sizeof (struct deffile));
/* Make sure we skip any leading whitespace. */
} else {
}
}
}
}
return (defs);
}
static void
{
}
}
/*
* write_default_file(fname, defs)
*
* Write the default file back.
*/
static int
{
}
} else {
switch (errno) {
case EPERM:
case EACCES:
break;
default:
ret = SA_SYSTEM_ERR;
}
}
return (ret);
}
/*
* set_default_file_value(tag, value)
*
* Set the default file value for tag to value. Then rewrite the file.
* tag and value are always set. The caller must ensure this.
*/
#define MAX_STRING_LENGTH 256
static int
{
char string[MAX_STRING_LENGTH];
int len;
int update = 0;
else
ret = SA_SYSTEM_ERR;
} else {
/* replace with the new value */
update = 1;
break;
}
}
if (!update) {
/* didn't find, so see if it is a comment */
/* replace with the new value */
update = 1;
break;
}
}
}
if (!update) {
}
}
if (update) {
}
}
return (ret);
}
/*
* 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;
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"),
scf_strerror(scf_error()));
} 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:
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;
if (index >= 0) {
/* should test for valid value */
}
}
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 *
{
char *state;
}
/*
* nfs_space_alias(alias)
*
* Lookup the space (security) name. If it is default, convert to the
* real name.
*/
static char *
nfs_space_alias(char *space)
{
/*
* 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 defautl to the real name.
*/
nfs_getseconfig_default(&secconf) == 0) {
}
}
/*
* nfs_features()
*
* Return a mask of the features required.
*/
static uint64_t
{
return ((uint64_t)SA_FEATURE_DFSTAB);
}