config_nfs4.c revision 1160694128cd3980cc06abe31af529a887efd310
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <strings.h>
#include <errno.h>
#include <assert.h>
#include "config_nfs4.h"
#define NFS4_MAX_DOM_LEN 1024
static int work_fd;
static int nfs4_fd;
char cur_domain[NFS4_MAX_DOM_LEN];
char nfs4cfg_file[NFS4_MAX_DOM_LEN];
static char work_file[NFS4_MAX_DOM_LEN];
static nfs4cfg_err_t
{
char *t;
char dir[NFS4_MAX_DOM_LEN];
char *pfx = "mapid";
else
/*
* Note: tempnam() can still default to P_tmpdir if
* access perms to the 'dir' are incompatible
*/
return (NFS4CFG_ERR_WRK_FNAME);
return (NFS4CFG_OK);
}
static nfs4cfg_err_t
{
int n4_fd;
errno = 0;
return (NFS4CFG_ERR_CFG_STAT);
/*
* config file does not exist, so we create it
*/
return (NFS4CFG_ERR_CFG_OPEN_RW);
return (NFS4CFG_ERR_CFG_FDOPEN);
}
return (NFS4CFG_ERR_CFG_WCHOWN);
}
return (NFS4CFG_ERR_CFG_CREAT);
}
/*
* config file exists; open it and
* create the appropriate work file
*/
return (NFS4CFG_ERR_CFG_OPEN_RO);
return (NFS4CFG_ERR_CFG_FDOPEN);
}
return (NFS4CFG_OK);
}
static nfs4cfg_err_t
{
int wk_fd;
return (NFS4CFG_ERR_WRK_OPEN);
return (NFS4CFG_ERR_WRK_FDOPEN);
}
return (NFS4CFG_ERR_WRK_WCHMOD);
}
return (NFS4CFG_ERR_WRK_WCHOWN);
}
return (NFS4CFG_OK);
}
static nfs4cfg_err_t
{
return (rv);
return (rv);
}
static void
{
char ibuf[NFS4_MAX_DOM_LEN];
char obuf[NFS4_MAX_DOM_LEN];
char *iptr;
char *p;
char *wptr;
continue;
/*
* Some other line than the one we're interested
* in. Just write it out and fetch the next line.
*/
/*
* If pattern was found at the beginning of the
* line _or_ even if it wasn't, if the first char
* is not a #, go ahead and insert the # and puke
* it out.
*/
} else
/* already commented */
}
}
static int
{
char ibuf[NFS4_MAX_DOM_LEN];
char *iptr;
char *p;
int rv = 0;
continue;
/*
* If the line is commented out or it's some other
* line than the one we're interested in, move on
*/
continue;
else if (p == ibuf) {
/*
* If pattern is found at the beginning of the line,
* the setting is active. Use this to present to the
* user as the default _iff_ the file does not exist.
*/
extern char *chomp(char *);
p++;
/*
* If the sysadmin specified "Auto" from the
* sysidcfg script, then continue to comment
* the entry and we're done.
*/
}
break;
}
}
return (rv);
}
static void
{
char ibuf[NFS4_MAX_DOM_LEN];
char obuf[NFS4_MAX_DOM_LEN];
char *iptr;
char *p;
char *wptr;
int done;
done = 0;
continue;
/*
* Some other line than the one we're interested
* in. Just write it out and fetch the next line.
*/
} else if (p == ibuf) {
/*
* pattern found uncommented at the beginning of
* the line, so make sure we set the proper value
* and write it out.
*/
if (!done) {
} else {
/*
* If we've already set the pattern to the
* specified value and we happen to encounter
* additional active line(s), then comment
* them out.
*/
}
done++;
} else if (ibuf[0] == '#') {
/*
* pattern was found to be commented. Set to the
* specified value if we haven't already done so.
*/
if (!done) {
} else {
/*
* Value was set previously and input line
* is already commented; just write it out.
*/
}
done++;
} else {
/*
* Found the pattern, but not commented and with
* some garbo at the front. Take the conservative
* approach and comment it out.
*/
}
}
}
static void
{
char obuf[NFS4_MAX_DOM_LEN];
}
int
{
nfs4cfg_err_t rv = 0;
char c;
/*
* Make a working copy of the config file.
*/
if (cmd == NFS4CMD_CHECK) {
return ((int)rv);
} else {
return ((int)rv);
if (rv == NFS4CFG_ERR_CFG_CREAT &&
cmd == NFS4CMD_CONFIG) {
/*
* revisit if NFS4CMD_UNCOMMENT
* is ever implemented
*/
return (0);
}
return ((int)rv);
}
}
/*
* Make necessary changes to working copy of the file
*/
switch (cmd) {
case NFS4CMD_CHECK:
return (rv);
/* NOTREACHED */
case NFS4CMD_CONFIG:
break;
case NFS4CMD_UNCONFIG:
/* FALLTHROUGH */
case NFS4CMD_UNCOMMENT:
break; /* ENOTSUP */
case NFS4CMD_COMMENT:
default:
break;
}
/*
* Install working copy (new file) over (old) config file
*/
return (NFS4CFG_ERR_WRK_RENAME);
}
return (0);
}