sysidnfs4.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "sysidnfs4.h"
#include "config_nfs4.h"
static char *term;
static char *progname;
/*
* Validate entered domain using the
* same rules applied by nfsmapid(1m).
*/
static n4err_t
domain_validate(char *ds)
{
int i;
return (NFS4_ERROR_BAD_DOMAIN);
}
}
}
/*
* set TERM env var to something sane
*/
static int
set_term(void)
{
if (putenv(TERM_DEFAULT)) {
return (1);
}
}
return (0);
}
static void
clear_state(void)
{
/*
* remove the state file so the user gets prompted again
*/
(void) unlink(NFS4STE_FILE);
}
static void
touch_state(void)
{
int fd;
/*
* create the state file so we don't get prompted again
*/
errno = 0;
} else
}
/*
* Prompt user for whether the default NFSv4 derived domainname
* should be overriden (ie. Manual) or used (ie. Auto).
*/
static n4act_t
prompt_for_action(void)
{
char *p;
/*
* Issue first prompt for action
*/
do {
ibuf[0] == 'N') {
return (NFS4_AUTO);
return (NFS4_MANUAL);
} else {
/*
* Ctrl-D
*/
clear_state();
exit(0);
}
/*
* Unrecognized value
*/
/* CONSTCOND */
} while (1);
/* NOTREACHED */
}
/*
* Remove any trailing newlines or carriage returns. Note that we _must_
* make a copy of the working buffer since the one pointed to by str is
* after our caller has returned.
*/
char *
{
int i;
int len;
char *cs;
char *p;
return (NULL);
if (*p == '\n' || *p == '\r')
*p = '\0';
return (cs);
}
/*
* Prompt user for the domain to use for inbound and outbound 'owner'
* and 'owner_group' attribute strings. The domain specified is run
* thru validation checks and if valid, the NFSMAPID_DOMAIN setting
*/
static char *
prompt_for_domain(void)
{
char ibuf[NS_MAXCDNAME];
char *p;
char *domain;
/*
* Issue first prompt for domain
*/
do {
/*
* Ctrl-D
*/
clear_state();
exit(0);
/*
* We're presenting the user with the NFSMAPID_DOMAIN
* value (if available). If user hits <enter> and we
* have a valid cur_domain, we're done. Otherwise,
* we keep on nagging.
*/
return (cur_domain);
} else {
if (rv == NFS4_SUCCESS)
return (domain);
}
/* CONSTCOND */
} while (1);
/* NOTREACHED */
}
void
{
}
int
{
const char *pattern = "NFSMAPID_DOMAIN";
char *dom;
int c;
(void) textdomain(TEXT_DOMAIN);
(void) set_term();
/*
* When called from sysidconfig(1m), the '-c' flag is specified;
* however, to follow a specific ordering after a sys-unconfig
* reboot, '-c' should be no-op'd so that no prompts are emitted
* until after the system has been fully configured. This requires
* sysidnfs4 to be called directly (ie. w/o any flags) from the
* /lib/svc/method/sysidtool-system script for first boot after
* either fresh install _or_ sys-unconfig.
*/
switch (c) {
case 'c':
/* silent no-op */
exit(0);
/* NOTREACHED */
case 'u':
/*
* sysidnfs4 needs to continue to respond to
* the '-u' flag when sys-unconfig is called
* so the NFS4STE_FILE is removed and thus,
* the prompts are re-issued on reboot.
*/
clear_state();
exit(0);
/* NOTREACHED */
case 'h':
case '?':
default:
usage(-1);
/*NOTREACHED*/
}
}
/*
* Check config file first. If there is an active NFSMAPID_DOMAIN
* line, we use the value as the default to prompt the user with.
* If by any chance, the value is "Auto", we just comment the line
* and bail.
*/
goto done;
}
/*
* To prompt or not to prompt... that is the question. If we have
* done this successfully already, the state file should exist !
*/
errno = 0;
exit(0);
switch (prompt_for_action()) {
case NFS4_AUTO:
break;
case NFS4_MANUAL:
dom = prompt_for_domain();
else
if (cur_domain[0] == '\0')
break;
default:
break;
}
done:
touch_state();
exit(0);
}