4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Usermode daemon which is responsible for sending kerberos credentials
28 * expiration warnings to the user, syslog or snmp (eventually), depending
29 * on how it is configured through /etc/krb5/warn.conf.
30 * the code in this file was borrowed from gssd.c
33 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/syslog.h>
38 #include <sys/termios.h>
40 #include <sys/resource.h>
41 #include <sys/utsname.h>
42 #include <sys/systeminfo.h>
55 int kwarnd_debug
= 0; /* enable debugging printfs */
57 extern void kwarnprog_1(struct svc_req
*, register SVCXPRT
*);
58 static void usage(void);
59 static void detachfromtty(void);
60 extern int svc_create_local_service(void (*) (),
61 ulong_t
, ulong_t
, char *, char *);
62 extern void kwarnd_check_warning_list(void);
63 extern bool_t
loadConfigFile(void);
65 /* following declarations needed in rpcgen-generated code */
66 int _rpcpmstart
= 0; /* Started by a port monitor ? */
67 int _rpcfdtype
; /* Whether Stream or Datagram ? */
68 int _rpcsvcdirty
; /* Still serving ? */
70 char myhostname
[MAXHOSTNAMELEN
] = {0};
71 char progname
[MAXNAMELEN
] = {0};
79 register SVCXPRT
*transp
;
82 char mname
[FMNAMESZ
+ 1];
83 int rpc_svc_mode
= RPC_SVC_MT_AUTO
;
85 /* set locale and domain for internationalization */
86 setlocale(LC_ALL
, "");
88 #if !defined(TEXT_DOMAIN)
89 #define TEXT_DOMAIN "SYS_TEST"
92 textdomain(TEXT_DOMAIN
);
94 (void) strlcpy(progname
, basename(argv
[0]), sizeof (progname
));
97 * Take special note that "getuid()" is called here. This call is used
98 * rather that app_krb5_user_uid(), to ensure ktkt_warnd(1M) is running
102 (void) setuid(0); /* DEBUG: set ruid to root */
105 (void) fprintf(stderr
,
106 gettext("[%s] must be run as root\n"), argv
[0]);
108 (void) fprintf(stderr
, gettext(" warning only\n"));
114 while ((c
= getopt(argc
, argv
, "d")) != -1)
117 /* turn on debugging */
124 if (optind
!= argc
) {
128 (void) gethostname(myhostname
, sizeof (myhostname
));
131 * Started by inetd if name of module just below stream
132 * head is either a sockmod or timod.
134 if (!ioctl(0, I_LOOK
, mname
) &&
135 ((strcmp(mname
, "sockmod") == 0) ||
136 (strcmp(mname
, "timod") == 0))) {
139 struct netconfig
*nconf
;
141 openlog("kwarnd", LOG_PID
, LOG_DAEMON
);
143 if ((netid
= getenv("NLSPROVIDER")) == NULL
) {
147 if ((nconf
= getnetconfigent(netid
)) == NULL
) {
148 syslog(LOG_ERR
, gettext("cannot get transport info"));
152 if (strcmp(mname
, "sockmod") == 0) {
153 if (ioctl(0, I_POP
, 0) || ioctl(0, I_PUSH
, "timod")) {
155 gettext("could not get the "
161 /* XXX - is nconf even needed here? */
162 if ((transp
= svc_tli_create(0, nconf
, NULL
, 0, 0)) == NULL
) {
163 syslog(LOG_ERR
, gettext("cannot create server handle"));
168 * We use a NULL nconf because KWARNPROG has already been
169 * registered with rpcbind.
171 if (!svc_reg(transp
, KWARNPROG
, KWARNVERS
, kwarnprog_1
, NULL
)) {
173 gettext("unable to register "
174 "(KWARNPROG, KWARNVERS)"));
179 freenetconfigent(nconf
);
185 openlog("kwarnd", LOG_PID
, LOG_DAEMON
);
187 if (svc_create_local_service(kwarnprog_1
, KWARNPROG
, KWARNVERS
,
188 "netpath", "kwarnd") == 0) {
189 syslog(LOG_ERR
, gettext("unable to create service"));
197 gettext("kwarnd start: \n"));
200 (void) signal(SIGCHLD
, SIG_IGN
);
202 if (thr_create(NULL
, 0,
203 (void *(*)(void *))kwarnd_check_warning_list
, NULL
,
204 THR_DETACHED
| THR_DAEMON
| THR_NEW_LWP
,
207 gettext("unable to create cache_cleanup thread"));
211 if (!loadConfigFile()) {
212 syslog(LOG_ERR
, gettext("could not read config file\n"));
216 if (!rpc_control(RPC_SVC_MTMODE_SET
, &rpc_svc_mode
)) {
217 syslog(LOG_ERR
, gettext("unable to set automatic MT mode"));
229 (void) fprintf(stderr
, gettext("usage: %s [-d]\n"), progname
);
242 perror(gettext("kwarnd: can not fork"));
252 * Close existing file descriptors, open "/dev/null" as
253 * standard input, output, and error, and detach from
254 * controlling terminal.
257 (void) open("/dev/null", O_RDONLY
);
258 (void) open("/dev/null", O_WRONLY
);
265 kwarnprog_1_freeresult(SVCXPRT
*transport
, xdrproc_t xdr_res
, caddr_t res
)
267 xdr_free(xdr_res
, res
);