kwarnd.c revision faebf79429f1b4c0f9334ac0f880806edf891f1f
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Usermode daemon which is responsible for sending kerberos credentials
* expiration warnings to the user, syslog or snmp (eventually), depending
* the code in this file was borrowed from gssd.c
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <unistd.h>
#include <sys/resource.h>
#include <sys/systeminfo.h>
#include <stdlib.h>
#include <stropts.h>
#include <fcntl.h>
#include <strings.h>
#include <syslog.h>
#include <thread.h>
#include <netdb.h>
#include <libgen.h>
#include "kwarnd.h"
#define MAXTHREADS 64
int kwarnd_debug = 0; /* enable debugging printfs */
static void usage(void);
static void detachfromtty(void);
extern int svc_create_local_service(void (*) (),
extern void kwarnd_check_warning_list(void);
extern bool_t loadConfigFile(void);
/* following declarations needed in rpcgen-generated code */
int _rpcpmstart = 0; /* Started by a port monitor ? */
int _rpcfdtype; /* Whether Stream or Datagram ? */
int _rpcsvcdirty; /* Still serving ? */
char myhostname[MAXHOSTNAMELEN] = {0};
char progname[MAXNAMELEN] = {0};
int
int argc;
char **argv;
{
extern int optind;
int c;
int rpc_svc_mode = RPC_SVC_MT_AUTO;
extern int _getuid();
/* set locale and domain for internationalization */
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
/*
* take special note that "_getuid()" is called here. This is necessary
* since we must fake out the mechanism libraries calls to getuid()
* with a special routine that is provided as part of kwarnd. However,
* the call below MUST call the real getuid() to ensure it is running
* as root.
*/
#ifdef DEBUG
(void) setuid(0); /* DEBUG: set ruid to root */
#endif /* DEBUG */
if (_getuid()) {
#ifdef DEBUG
#else /* !DEBUG */
exit(1);
#endif /* DEBUG */
}
switch (c) {
case 'd':
/* turn on debugging */
kwarnd_debug = 1;
break;
default:
usage();
}
usage();
}
/*
* Started by inetd if name of module just below stream
* head is either a sockmod or timod.
*/
char *netid;
netid = "ticotsord";
}
exit(1);
}
gettext("could not get the "
"right module"));
exit(1);
}
}
/* XXX - is nconf even needed here? */
exit(1);
}
/*
* We use a NULL nconf because KWARNPROG has already been
* registered with rpcbind.
*/
gettext("unable to register "
"(KWARNPROG, KWARNVERS)"));
exit(1);
}
if (nconf)
} else {
if (!kwarnd_debug)
"netpath", "kwarnd") == 0) {
exit(1);
}
}
if (kwarnd_debug) {
gettext("kwarnd start: \n"));
}
if (thr_create(NULL, 0,
(void *(*)(void *))kwarnd_check_warning_list, NULL,
NULL)) {
gettext("unable to create cache_cleanup thread"));
exit(1);
}
if (!loadConfigFile()) {
exit(1);
}
exit(1);
}
svc_run();
abort();
/*NOTREACHED*/
#ifdef lint
return (1);
#endif
}
static void
usage(void)
{
exit(1);
}
/*
* detach from tty
*/
static void
detachfromtty(void)
{
switch (fork()) {
case -1:
exit(1);
/*NOTREACHED*/
case 0:
break;
default:
exit(0);
}
/*
* standard input, output, and error, and detach from
* controlling terminal.
*/
closefrom(0);
(void) dup(1);
(void) setsid();
}
/*ARGSUSED*/
int
{
return (1);
}