/*
* 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
*/
/*
*/
/*
* Simple doors name server cache daemon
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include <locale.h>
#include <zone.h>
#include <signal.h>
#include <sys/resource.h>
#include "cache.h"
#include "nscd_log.h"
#include "nscd_selfcred.h"
#include "nscd_frontend.h"
#include "nscd_common.h"
#include "nscd_admin.h"
#include "nscd_door.h"
#include "nscd_switch.h"
extern int optind;
extern int opterr;
extern int optopt;
extern char *optarg;
/* assume this is a single nscd or, if multiple, the main nscd */
extern int _logfd;
extern nsc_ctx_t *cache_ctx_p[];
static void usage(char *);
static void detachfromtty(void);
static int will_become_server;
static char *
getcacheopt(char *s)
{
while (*s && *s != ',')
s++;
}
/*
* declaring this causes the files backend to use hashing
* this is of course an utter hack, but provides a nice
* quiet back door to enable this feature for only the nscd.
*/
void
__nss_use_files_hash(void)
{
}
static int saved_argc = 0;
static void
{
saved_execname[0] = 0;
}
}
int
{
int opt;
int errflg = 0;
int showstats = 0;
int doset = 0;
char *ret_locale;
char *ret_textdomain;
if (ret_locale == NULL)
if (ret_textdomain == NULL)
/*
* The admin model for TX is that labeled zones are managed
* in global zone where most trusted configuration database
* resides. However, nscd will run in any labeled zone if
* file /var/tsol/doors/nscd_per_label exists.
*/
gettext("With Trusted Extensions nscd runs only in the "
"global zone (if nscd_per_label flag not set)\n"));
exit(1);
}
}
/*
* Special case non-root user here - he can just print stats
*/
if (geteuid()) {
if (argc != 2 ||
gettext("Must be root to use any option other than -g\n\n"));
}
gettext("%s doesn't appear to be running.\n"),
argv[0]);
exit(1);
}
gettext("unable to get configuration and statistics data\n"));
exit(1);
}
exit(0);
}
/*
* Determine if there is already a daemon (main nscd) running.
* If not, will start it. Forker NSCD will always become a
* daemon.
*/
will_become_server = 1;
/*
* allow time for the main nscd to get ready
* to receive the IMHERE door request this
* process will send later
*/
(void) usleep(100000);
}
/*
* first get the config file path. Also detect
* invalid option as soon as possible.
*/
switch (opt) {
case 'f':
exit(1);
break;
case 'g':
if (will_become_server) {
gettext("nscd not running, no statistics to show\n\n"));
errflg++;
}
break;
case 'i':
if (will_become_server) {
gettext("nscd not running, no cache to invalidate\n\n"));
errflg++;
}
break;
case '?':
errflg++;
break;
}
}
if (errflg)
/*
* perform more initialization and load configuration
* if to become server
*/
if (will_become_server) {
exit(1);
}
/*
* initialize cache store
*/
exit(1);
}
}
/*
* process usual options
*/
*msg = '\0';
switch (opt) {
case 'K': /* undocumented feature */
(void) _nscd_doorcall(NSCD_KILLSERVER);
exit(0);
break;
case 'G':
case 'g':
showstats++;
break;
case 'p':
doset++;
errflg++;
break;
case 'n':
doset++;
errflg++;
break;
case 'c':
doset++;
errflg++;
break;
case 'i':
doset++;
errflg++;
break;
case 'l':
doset++;
break;
case 'd':
doset++;
sizeof (debug_level));
break;
case 'S':
/* silently ignore secure-mode */
break;
case 's':
/* silently ignore suggested-size */
break;
case 'o':
/* silently ignore old-data-ok */
break;
case 'h':
doset++;
errflg++;
break;
case 'e':
doset++;
errflg++;
break;
case 'F':
break;
default:
errflg++;
break;
}
}
if (errflg) {
if (*msg != '\0')
}
/*
* if main nscd already running and not forker nscd,
* can only do admin work
*/
if (!will_become_server) {
if (showstats) {
if (_nscd_client_getadmin('g')) {
gettext("Cannot contact nscd properly(?)\n"));
exit(1);
}
}
if (doset) {
if (_nscd_client_setadmin() < 0) {
gettext("Error during admin call\n"));
exit(1);
}
}
gettext("%s already running.... no administration option specified\n"),
argv[0]);
}
exit(0);
}
}
/*
* daemon from here on
*/
/* save enough info in case need to restart or fork */
saved_argc = argc;
saved_argv = argv;
/*
* if a log file is not specified, set it to
*/
if (*logfile == '\0') {
if (*debug_level != '\0')
/* we're debugging... */
else
}
/* activate command options */
gettext("unable to set command line options\n"));
exit(1);
}
if (*debug_level != '\0') {
/* we're debugging, no forking of nscd */
/*
* forker nscd will be started if self credential
* is configured
*/
} else {
/*
* daemonize the nscd (forker nscd will also
* be started if self credential is configured)
*/
}
} else { /* NSCD_FORKER */
/*
* To avoid PUN (Per User Nscd) processes from becoming
* zombies after they exit, the forking nscd should
* ignore the SIGCLD signal so that it does not
* need to wait for every child PUN to exit.
*/
(void) dup(0);
if (_logfd != 2)
(void) dup(0);
}
/* set NOFILE to unlimited */
exit(1);
}
/* set up door and establish our own server thread pool */
(me, "unable to set up door\n");
exit(1);
}
/* inform the main nscd that this forker is ready */
if (_whoami == NSCD_FORKER) {
int ret;
}
for (;;) {
(void) pause();
(void) _nscd_doorcall(NSCD_REFRESH);
}
/* NOTREACHED */
/*LINTED E_FUNC_HAS_NO_RETURN_STMT*/
}
static void
usage(char *s)
{
"Usage: %s [-d debug_level] [-l logfilename]\n", s);
" [-p cachename,positive_time_to_live]\n");
" [-n cachename,negative_time_to_live]\n");
" [-i cachename]\n");
" [-h cachename,keep_hot_count]\n");
" [-e cachename,\"yes\"|\"no\"] [-g] " \
"[-c cachename,\"yes\"|\"no\"]\n");
" [-f configfilename] \n");
"\n Supported caches:\n");
" auth_attr, bootparams, ethers\n");
" exec_attr, group, hosts, ipnodes, netmasks\n");
" networks, passwd, printers, prof_attr, project\n");
" protocols, rpc, services, tnrhtp, tnrhdb\n");
" user_attr\n");
exit(1);
}
/*
* detach from tty
*/
static void
detachfromtty(void)
{
if (_logfd > 0) {
int i;
for (i = 0; i < _logfd; i++)
(void) close(i);
} else
closefrom(0);
(void) chdir("/");
switch (fork1()) {
case (pid_t)-1:
(me, "unable to fork: pid = %d, %s\n",
exit(1);
break;
case 0:
/* start the forker nscd if so configured */
break;
default:
exit(0);
}
(void) setsid();
(void) dup(0);
if (_logfd != 2)
(void) dup(0);
/*
* start monitoring the states of the name service clients
*/
rc = _nscd_init_smf_monitor();
if (rc != NSCD_SUCCESS) {
exit(-1);
}
}