cachemgr.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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <signal.h>
#include <netdir.h>
#include <errno.h>
#include <rpcsvc/daemon_utils.h>
#include <priv.h>
#include <priv_utils.h>
#include "nis_cache.h"
#define NIS_CACHEMGR_UID 0
#define NIS_CACHEMGR_GID 3
int mgr_verbose;
int alarm_rang = 0;
int got_sighup = 0;
extern int __nis_debuglevel;
extern nis_error __nis_CacheMgrInit_discard(int);
static char *create_ti_server();
static void my_svc_run();
static void do_timers();
static void do_config();
static void set_file_ownership(char *);
void
hangup_handler(int sig)
{
got_sighup = 1;
}
void
cache_purge_handler(int sig)
{
alarm_rang = 1;
}
/*
* Cleanup, set signal handler to default, and send ourselves
* the signal again.
*/
void
cache_cleanup_handler(int sig)
{
}
char *name;
{
printf("\t\t-d [debug_level]\n");
printf("\t\t-i <initialize cache when starting up>\n");
printf("\t\t-m [max size of cache file (in pages) ]\n");
"\t\t-n <insecure mode - directory object signatures not checked>.\n");
printf("\t\t-s [initial size of cache file (in pages)]\n");
printf("\t\t-v <verbose - sends events to syslog>\n");
exit(1);
}
{
int c;
int n;
int pid;
int console;
char *p;
int init_cache = 0;
char *options = 0;
char *uaddr;
/*
* Ensure all files are owned by nis_cachemgr.
*/
if (console == -1) {
exit(1);
}
/*
* Make the process a privilege aware daemon.
* Only "basic" privileges are required.
*/
" sufficient privileges\n");
exit(1);
}
/*
* Make sure any files we create without explicit permissions
* aren't group or world writeable.
*/
(void) umask(0022);
switch (c) {
case 'd':
break;
case 'i':
init_cache = 1;
break;
case 'm':
case 'n':
case 's':
/* obsolete */
break;
case 'v':
mgr_verbose = 1;
break;
case 'o':
break;
default:
break;
}
}
"can't turn on privilege debug flag. %s\n",
exit(1);
}
/*
* We pass options to the cache library through the
* environment variable NIS_OPTIONS. If options are
* passed on the command line, then we put them into
* the environment.
*/
if (options) {
p = (char *)malloc(n);
if (p == NULL) {
exit(1);
}
strcpy(p, "NIS_OPTIONS=");
putenv(p);
}
if (init_cache) {
}
if (err != NIS_SUCCESS) {
exit(1);
}
if (!__nis_debuglevel) {
if (pid == -1) {
perror("fork");
exit(1);
} else if (pid != 0) {
exit(0);
}
close(0);
close(1);
close(2);
setsid();
}
/*
* Remove unnecessary privileges - fork and exec.
* Removing permitted privileges also removes effective privileges.
*/
"can't set reduced privileges. %s\n",
}
uaddr = create_ti_server();
if (mgr_verbose)
do_timers();
my_svc_run();
exit(1);
}
static void set_file_ownership(char *file)
{
return;
exit(1);
}
exit(1);
}
}
}
static
void
{
int i;
int npollfds = 0;
while (1) {
if (got_sighup) {
got_sighup = 0;
do_config();
} else if (alarm_rang) {
alarm_rang = 0;
do_timers();
}
if (npollfds != svc_max_pollfd) {
sizeof (pollfd_t) * svc_max_pollfd);
}
if (npollfds == 0)
break; /* None waiting, hence return */
/*
* Get existing array of pollfd's, should really compress
* this but it shouldn't get very large (or sparse).
*/
sizeof (pollfd_t) * svc_max_pollfd);
case -1:
/*
* We ignore all errors, continuing with the assumption
* that it was set by the signal handlers (or any
* other outside event) and not caused by poll().
*/
case 0:
continue;
default:
svc_getreq_poll(pollset, i);
}
}
}
static
void
{
}
static
void
{
secs = __nis_CacheMgrTimers();
}
static
char *
{
char *uaddr;
void *nc_handle;
/*
* we want to get a loopback transport to have clients talk to the
* cachemgr
* this provides security in the sense that only local folk can access
* the cachemgr. Also, it makes the messages inherently more reliable.
* we also want a CLTS transport so search in the netconfig database
* for this type of transport.
* This is an implicit protocol between the cachemgr and the clients
* and the clients make the same selection of trasport (in
* cache_getclnt.c) and use the uaddr that the cachemgr writes into
* the cache file. This uaddr would be valid only for this transport
* that both agree on implicitly.
* If the selection scheme is changed here it should also be changed
* in the client side (cache_getclnt.c)
*/
nc_handle = setnetconfig();
break;
}
}
if (!found_loopback) {
"Could not get loopback transport from netconfig database");
exit(1);
}
/* create a new transport endpoint */
if (!transp) {
"create_ti_server: cannot create server handle on loopback transport");
exit(1);
}
return (uaddr);
}
/*
* Service routines.
*/
void *
{
if (mgr_verbose)
}
void *
{
if (mgr_verbose)
}
void *
{
if (mgr_verbose)
}
void *
{
if (mgr_verbose)
}
{
if (mgr_verbose)
return (&err);
}
{
if (mgr_verbose)
return (&err);
}
{
if (mgr_verbose)
return (&err);
}
{
static refresh_res res;
if (mgr_verbose)
return (&res);
}
{
static refresh_res res;
if (mgr_verbose)
/* xdr_free old result */
else
return (&res);
}
{
static refresh_res res;
if (mgr_verbose)
/* xdr_free old result */
} else {
}
return (&res);
}