xref: /titanic_52/usr/src/cmd/krb5/kwarn/kwarnd_proc.c (revision 24da5b34f49324ed742a340010ed5bd3d4e06625)
17c478bd9Sstevel@tonic-gate /*
2faebf794Sgtb  * CDDL HEADER START
3faebf794Sgtb  *
4faebf794Sgtb  * The contents of this file are subject to the terms of the
5faebf794Sgtb  * Common Development and Distribution License (the "License").
6faebf794Sgtb  * You may not use this file except in compliance with the License.
7faebf794Sgtb  *
8faebf794Sgtb  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9faebf794Sgtb  * or http://www.opensolaris.org/os/licensing.
10faebf794Sgtb  * See the License for the specific language governing permissions
11faebf794Sgtb  * and limitations under the License.
12faebf794Sgtb  *
13faebf794Sgtb  * When distributing Covered Code, include this CDDL HEADER in each
14faebf794Sgtb  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15faebf794Sgtb  * If applicable, add the following below this CDDL HEADER, with the
16faebf794Sgtb  * fields enclosed by brackets "[]" replaced with your own identifying
17faebf794Sgtb  * information: Portions Copyright [yyyy] [name of copyright owner]
18faebf794Sgtb  *
19faebf794Sgtb  * CDDL HEADER END
20faebf794Sgtb  */
21faebf794Sgtb /*
22*24da5b34Srie  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  *  RPC server procedures for the usermode daemon kwarnd.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <stdio.h>
337c478bd9Sstevel@tonic-gate #include <unistd.h>
347c478bd9Sstevel@tonic-gate #include <pwd.h>
357c478bd9Sstevel@tonic-gate #include <grp.h>
367c478bd9Sstevel@tonic-gate #include <strings.h>
377c478bd9Sstevel@tonic-gate #include <string.h>
387c478bd9Sstevel@tonic-gate #include <sys/param.h>
397c478bd9Sstevel@tonic-gate #include <sys/syslog.h>
407c478bd9Sstevel@tonic-gate #include "kwarnd.h"
417c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
427c478bd9Sstevel@tonic-gate #include <stdlib.h>
437c478bd9Sstevel@tonic-gate #include <syslog.h>
447c478bd9Sstevel@tonic-gate #include <poll.h>
457c478bd9Sstevel@tonic-gate #include <utmpx.h>
467c478bd9Sstevel@tonic-gate #include <pwd.h>
477c478bd9Sstevel@tonic-gate #include <strings.h>
487c478bd9Sstevel@tonic-gate #include <ctype.h>
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #include <k5-int.h>
517c478bd9Sstevel@tonic-gate #include <profile/prof_int.h>
527c478bd9Sstevel@tonic-gate #include <com_err.h>
537c478bd9Sstevel@tonic-gate #include <libintl.h>
547c478bd9Sstevel@tonic-gate #include <krb5.h>
557c478bd9Sstevel@tonic-gate 
56faebf794Sgtb extern char progname[];
57faebf794Sgtb 
587c478bd9Sstevel@tonic-gate struct k5_data
597c478bd9Sstevel@tonic-gate {
607c478bd9Sstevel@tonic-gate 	krb5_context ctx;
617c478bd9Sstevel@tonic-gate 	krb5_ccache cc;
627c478bd9Sstevel@tonic-gate 	krb5_principal me;
637c478bd9Sstevel@tonic-gate 	char *name;
647c478bd9Sstevel@tonic-gate };
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #define	MAIL		"mail"
687c478bd9Sstevel@tonic-gate #define	MAILPATH	"/usr/bin/mail"
697c478bd9Sstevel@tonic-gate #define	DEFAULT_CONFIG	"* terminal 30m"
707c478bd9Sstevel@tonic-gate #define	CONF_FILENAME	"/etc/krb5/warn.conf"
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /* warn.conf info */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate typedef struct config_entry_s {
757c478bd9Sstevel@tonic-gate 	struct config_entry_s		*next;
767c478bd9Sstevel@tonic-gate 	int				seconds_to_warn;
777c478bd9Sstevel@tonic-gate 	char				*principal;
787c478bd9Sstevel@tonic-gate 	char				*where_to;
797c478bd9Sstevel@tonic-gate 	char				*email;
807c478bd9Sstevel@tonic-gate 	int				renew;
817c478bd9Sstevel@tonic-gate 	int				log_success;
827c478bd9Sstevel@tonic-gate 	int				log_failure;
837c478bd9Sstevel@tonic-gate } config_entry_list_t;
847c478bd9Sstevel@tonic-gate static config_entry_list_t		*config_entry_list;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /* list of principals to be warned */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate typedef struct cred_warning_list_s {
897c478bd9Sstevel@tonic-gate 	struct cred_warning_list_s 	*next;
907c478bd9Sstevel@tonic-gate 	WARNING_NAME_T			warn_name;
917c478bd9Sstevel@tonic-gate 	time_t				cred_exp_time;
927c478bd9Sstevel@tonic-gate 	time_t				cred_warn_time;
937c478bd9Sstevel@tonic-gate 	mutex_t				cwm;
947c478bd9Sstevel@tonic-gate } cred_warning_list_t;
957c478bd9Sstevel@tonic-gate static cred_warning_list_t		*cred_warning_list;
967c478bd9Sstevel@tonic-gate static rwlock_t				cred_lock = DEFAULTRWLOCK;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate static bool_t
997c478bd9Sstevel@tonic-gate del_warning_pvt(char *);
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate static config_entry_list_t *
1027c478bd9Sstevel@tonic-gate find_warning_info(char *);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate static bool_t
1057c478bd9Sstevel@tonic-gate parseConfigLine(char *buffer);
1067c478bd9Sstevel@tonic-gate 
107814a60b1Sgtb extern int warn_send(char *, char *);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate extern int kwarnd_debug;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate cred_warning_list_t *
1127c478bd9Sstevel@tonic-gate find_cred_warning(WARNING_NAME_T warn_name)
1137c478bd9Sstevel@tonic-gate {
1147c478bd9Sstevel@tonic-gate 	cred_warning_list_t	*cw;
1157c478bd9Sstevel@tonic-gate 	if (!cred_warning_list)
1167c478bd9Sstevel@tonic-gate 		return (NULL);
1177c478bd9Sstevel@tonic-gate 	for (cw = cred_warning_list; cw != NULL; cw = cw->next) {
1187c478bd9Sstevel@tonic-gate 		if (strcmp(warn_name, cw->warn_name) != 0)
1197c478bd9Sstevel@tonic-gate 			continue;
1207c478bd9Sstevel@tonic-gate 		return (cw);
1217c478bd9Sstevel@tonic-gate 	}
1227c478bd9Sstevel@tonic-gate 	return (NULL);
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate  * add a principal to the principal warning list
1277c478bd9Sstevel@tonic-gate  */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate bool_t
1307c478bd9Sstevel@tonic-gate kwarn_add_warning_1_svc(kwarn_add_warning_arg *argp,
1317c478bd9Sstevel@tonic-gate 			kwarn_add_warning_res *res,
1327c478bd9Sstevel@tonic-gate 			struct svc_req *rqstp)
1337c478bd9Sstevel@tonic-gate {
1347c478bd9Sstevel@tonic-gate 	cred_warning_list_t	*cred_warning;
1357c478bd9Sstevel@tonic-gate 	config_entry_list_t *config_entry;
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 	if (kwarnd_debug) {
1387c478bd9Sstevel@tonic-gate 		printf("kwarn_add_warning_1_svc start; cWlist=%p\n",
1397c478bd9Sstevel@tonic-gate 		    cred_warning_list);
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 		printf("kwarn_add_warning_1_svc: principal %s",
1427c478bd9Sstevel@tonic-gate 		    argp->warning_name);
1437c478bd9Sstevel@tonic-gate 		printf(" exp time: %d\n", argp->cred_exp_time);
1447c478bd9Sstevel@tonic-gate 	}
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /*
1477c478bd9Sstevel@tonic-gate  *  if there is no entry in the config file that matches the principal to
1487c478bd9Sstevel@tonic-gate  *  be added to the warning list, return true because we are not going to
1497c478bd9Sstevel@tonic-gate  *  send a warning for this principal.
1507c478bd9Sstevel@tonic-gate  */
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	if ((config_entry = find_warning_info(argp->warning_name)) == NULL) {
1537c478bd9Sstevel@tonic-gate 		if (kwarnd_debug)
1547c478bd9Sstevel@tonic-gate 			printf(
1557c478bd9Sstevel@tonic-gate 		"kwarn_add_warning_1_svc find_warn_info: fails, cWlist=%p\n",
1567c478bd9Sstevel@tonic-gate 				cred_warning_list);
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 		return (TRUE);
1597c478bd9Sstevel@tonic-gate 	}
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate  * see if a warning has already been created for this principal, if so
1637c478bd9Sstevel@tonic-gate  * update the warning time.
1647c478bd9Sstevel@tonic-gate  */
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	rw_wrlock(&cred_lock);
1677c478bd9Sstevel@tonic-gate 	if (cred_warning = find_cred_warning(argp->warning_name)) {
1687c478bd9Sstevel@tonic-gate 		rw_unlock(&cred_lock);
1697c478bd9Sstevel@tonic-gate 		mutex_lock(&cred_warning->cwm);
1707c478bd9Sstevel@tonic-gate 		cred_warning->cred_exp_time = argp->cred_exp_time;
1717c478bd9Sstevel@tonic-gate 		cred_warning->cred_warn_time = argp->cred_exp_time
1727c478bd9Sstevel@tonic-gate 			- config_entry->seconds_to_warn;
1737c478bd9Sstevel@tonic-gate 		mutex_unlock(&cred_warning->cwm);
1747c478bd9Sstevel@tonic-gate 	} else {
1757c478bd9Sstevel@tonic-gate 		cred_warning = (cred_warning_list_t *)malloc(
1767c478bd9Sstevel@tonic-gate 				sizeof (*cred_warning_list));
1777c478bd9Sstevel@tonic-gate 		if (cred_warning == NULL) {
1787c478bd9Sstevel@tonic-gate 			rw_unlock(&cred_lock);
1797c478bd9Sstevel@tonic-gate 			res->status = 1;
1807c478bd9Sstevel@tonic-gate 			return (FALSE);
1817c478bd9Sstevel@tonic-gate 		}
1827c478bd9Sstevel@tonic-gate 		(void) memset((char *)cred_warning, 0,
1837c478bd9Sstevel@tonic-gate 			    sizeof (*cred_warning_list));
1847c478bd9Sstevel@tonic-gate 		cred_warning->cred_exp_time = argp->cred_exp_time;
1857c478bd9Sstevel@tonic-gate 		cred_warning->cred_warn_time = argp->cred_exp_time
1867c478bd9Sstevel@tonic-gate 			- config_entry->seconds_to_warn;
1877c478bd9Sstevel@tonic-gate 		cred_warning->warn_name = strdup(argp->warning_name);
1887c478bd9Sstevel@tonic-gate 		if (cred_warning->warn_name == NULL) {
1897c478bd9Sstevel@tonic-gate 			free(cred_warning);
1907c478bd9Sstevel@tonic-gate 			rw_unlock(&cred_lock);
1917c478bd9Sstevel@tonic-gate 			res->status = 1;
1927c478bd9Sstevel@tonic-gate 			return (FALSE);
1937c478bd9Sstevel@tonic-gate 		}
1947c478bd9Sstevel@tonic-gate 		mutex_init(&cred_warning->cwm,  USYNC_THREAD, NULL);
1957c478bd9Sstevel@tonic-gate 		cred_warning->next = cred_warning_list;
1967c478bd9Sstevel@tonic-gate 		cred_warning_list = cred_warning;
1977c478bd9Sstevel@tonic-gate 		rw_unlock(&cred_lock);
1987c478bd9Sstevel@tonic-gate 	}
1997c478bd9Sstevel@tonic-gate 	res->status = 0;
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	if (kwarnd_debug)
2027c478bd9Sstevel@tonic-gate 		printf(
2037c478bd9Sstevel@tonic-gate 		"kwarn_add_warning_1_svc end: returns true; cWlist=%p\n",
2047c478bd9Sstevel@tonic-gate 		cred_warning_list);
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	return (TRUE);
2077c478bd9Sstevel@tonic-gate }
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate /*
2107c478bd9Sstevel@tonic-gate  * delete a warning request for a given principal
2117c478bd9Sstevel@tonic-gate  */
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate bool_t
2147c478bd9Sstevel@tonic-gate kwarn_del_warning_1_svc(kwarn_del_warning_arg *argp,
2157c478bd9Sstevel@tonic-gate 			kwarn_del_warning_res *res,
2167c478bd9Sstevel@tonic-gate 			struct svc_req *rqstp)
2177c478bd9Sstevel@tonic-gate {
2187c478bd9Sstevel@tonic-gate 	if (kwarnd_debug)
2197c478bd9Sstevel@tonic-gate 		printf(gettext("delete principal %s requested\n"),
2207c478bd9Sstevel@tonic-gate 		    argp->warning_name);
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	if (del_warning_pvt(argp->warning_name) == TRUE) {
2237c478bd9Sstevel@tonic-gate 		res->status = 0;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 		if (kwarnd_debug)
2267c478bd9Sstevel@tonic-gate 			printf(gettext("delete principal %s completed\n"),
2277c478bd9Sstevel@tonic-gate 			    argp->warning_name);
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 		return (TRUE);
2307c478bd9Sstevel@tonic-gate 	} else {
2317c478bd9Sstevel@tonic-gate 		res->status = 1;
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 		if (kwarnd_debug)
2347c478bd9Sstevel@tonic-gate 			printf(gettext("delete principal %s failed\n"),
2357c478bd9Sstevel@tonic-gate 				argp->warning_name);
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 		return (TRUE);
2387c478bd9Sstevel@tonic-gate 	}
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate static bool_t
2427c478bd9Sstevel@tonic-gate del_warning_pvt(char *warning_name)
2437c478bd9Sstevel@tonic-gate {
2447c478bd9Sstevel@tonic-gate 	cred_warning_list_t	*cred_warning, *prev;
2457c478bd9Sstevel@tonic-gate 	rw_wrlock(&cred_lock);
2467c478bd9Sstevel@tonic-gate 	for (prev = NULL, cred_warning = cred_warning_list;
2477c478bd9Sstevel@tonic-gate 		cred_warning != NULL; prev = cred_warning,
2487c478bd9Sstevel@tonic-gate 		cred_warning = cred_warning->next) {
2497c478bd9Sstevel@tonic-gate 		if (strcmp(cred_warning->warn_name, warning_name) == 0) {
2507c478bd9Sstevel@tonic-gate 			if (!prev)
2517c478bd9Sstevel@tonic-gate 				cred_warning_list = cred_warning->next;
2527c478bd9Sstevel@tonic-gate 			else
2537c478bd9Sstevel@tonic-gate 				prev->next = cred_warning->next;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 			free(cred_warning->warn_name);
2567c478bd9Sstevel@tonic-gate 			free(cred_warning);
2577c478bd9Sstevel@tonic-gate 			rw_unlock(&cred_lock);
2587c478bd9Sstevel@tonic-gate 			return (TRUE);
2597c478bd9Sstevel@tonic-gate 		}
2607c478bd9Sstevel@tonic-gate 	}
2617c478bd9Sstevel@tonic-gate 	rw_unlock(&cred_lock);
2627c478bd9Sstevel@tonic-gate 	return (FALSE);
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate /*
2667c478bd9Sstevel@tonic-gate  * load the warn.conf file into the config_entry list.
2677c478bd9Sstevel@tonic-gate  */
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate bool_t
2707c478bd9Sstevel@tonic-gate loadConfigFile(void)
2717c478bd9Sstevel@tonic-gate {
2727c478bd9Sstevel@tonic-gate 	char	buffer[BUFSIZ];
2737c478bd9Sstevel@tonic-gate 	FILE	*cfgfile;
2747c478bd9Sstevel@tonic-gate 	bool_t	retval = TRUE;
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate 	if ((cfgfile = fopen(CONF_FILENAME, "r")) == NULL) {
2777c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
2787c478bd9Sstevel@tonic-gate 			"could not open config file \"%s\"\n"),
2797c478bd9Sstevel@tonic-gate 			CONF_FILENAME);
2807c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
2817c478bd9Sstevel@tonic-gate 			"using default options \"%s\"\n"),
2827c478bd9Sstevel@tonic-gate 			DEFAULT_CONFIG);
2837c478bd9Sstevel@tonic-gate 		retval = parseConfigLine(DEFAULT_CONFIG);
2847c478bd9Sstevel@tonic-gate 	} else {
2857c478bd9Sstevel@tonic-gate 		(void) memset(buffer, 0, sizeof (buffer));
2867c478bd9Sstevel@tonic-gate 		while ((fgets(buffer, BUFSIZ, cfgfile) != NULL) &&
2877c478bd9Sstevel@tonic-gate 			(retval == TRUE))
2887c478bd9Sstevel@tonic-gate 			retval = parseConfigLine(buffer);
2897c478bd9Sstevel@tonic-gate 		fclose(cfgfile);
2907c478bd9Sstevel@tonic-gate 	}
2917c478bd9Sstevel@tonic-gate 	return (retval);
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate /*
2957c478bd9Sstevel@tonic-gate  * Return TRUE if we get a valid opt and update flags appro.
2967c478bd9Sstevel@tonic-gate  */
2977c478bd9Sstevel@tonic-gate static bool_t
2987c478bd9Sstevel@tonic-gate cmp_renew_opts(char *opt,
2997c478bd9Sstevel@tonic-gate 	    int *log_success, /* out */
3007c478bd9Sstevel@tonic-gate 	    int *log_failure) /* out */
3017c478bd9Sstevel@tonic-gate {
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	if (strncasecmp(opt, "log",
3047c478bd9Sstevel@tonic-gate 			sizeof ("log")) == 0) {
3057c478bd9Sstevel@tonic-gate 		*log_success = *log_failure = 1;
3067c478bd9Sstevel@tonic-gate 	} else if (strncasecmp(opt, "log-success",
3077c478bd9Sstevel@tonic-gate 			    sizeof ("log-success")) == 0) {
3087c478bd9Sstevel@tonic-gate 		*log_success = 1;
3097c478bd9Sstevel@tonic-gate 	} else if (strncasecmp(opt, "log-failure",
3107c478bd9Sstevel@tonic-gate 			    sizeof ("log-failure")) == 0) {
3117c478bd9Sstevel@tonic-gate 		*log_failure = 1;
3127c478bd9Sstevel@tonic-gate 	} else {
3137c478bd9Sstevel@tonic-gate 		if (kwarnd_debug)
3147c478bd9Sstevel@tonic-gate 			printf("cmp_renew_opts: renew bad opt=`%s'\n",
3157c478bd9Sstevel@tonic-gate 			    opt ? opt : "null");
3167c478bd9Sstevel@tonic-gate 		return (FALSE);
3177c478bd9Sstevel@tonic-gate 	}
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	return (TRUE);
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate /*
3237c478bd9Sstevel@tonic-gate  * Make the config_entry item for the config_entry_list, based on
3247c478bd9Sstevel@tonic-gate  * buffer.  The formats are
3257c478bd9Sstevel@tonic-gate  *
3267c478bd9Sstevel@tonic-gate  *    <principal> [renew[:<opt1,...optN>]] syslog|terminal <time>
3277c478bd9Sstevel@tonic-gate  *    <principal> [renew[:<opt1,...optN>]] mail <time> <e-mail address>
3287c478bd9Sstevel@tonic-gate  *
3297c478bd9Sstevel@tonic-gate  * where renew opts will be:
3307c478bd9Sstevel@tonic-gate  *
3317c478bd9Sstevel@tonic-gate  *     log-success
3327c478bd9Sstevel@tonic-gate  *		- Log the result of the renew attempt on success using
3337c478bd9Sstevel@tonic-gate  *		  the specified method (syslog|terminal|mail)
3347c478bd9Sstevel@tonic-gate  *
3357c478bd9Sstevel@tonic-gate  *      log-failure
3367c478bd9Sstevel@tonic-gate  *		- Log the result of the renew attempt on failure using
3377c478bd9Sstevel@tonic-gate  *		  the specified method (syslog|terminal|mail)
3387c478bd9Sstevel@tonic-gate  *
3397c478bd9Sstevel@tonic-gate  *      log
3407c478bd9Sstevel@tonic-gate  *               - Same as specifing both log-failure and log-success
3417c478bd9Sstevel@tonic-gate  *
3427c478bd9Sstevel@tonic-gate  *		  Note if no log options are given, there will be no logging.
3437c478bd9Sstevel@tonic-gate  *
3447c478bd9Sstevel@tonic-gate  */
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate static bool_t
3477c478bd9Sstevel@tonic-gate parseConfigLine(char *buffer)
3487c478bd9Sstevel@tonic-gate {
3497c478bd9Sstevel@tonic-gate 	char *principal, *send_to, *emailid, *ends, *tm;
3507c478bd9Sstevel@tonic-gate 	char			*exptime;
3517c478bd9Sstevel@tonic-gate 	int			time_mode;
3527c478bd9Sstevel@tonic-gate 	time_t			etime;
3537c478bd9Sstevel@tonic-gate 	config_entry_list_t	*config_entry;
3547c478bd9Sstevel@tonic-gate 	int renew = 0;
3557c478bd9Sstevel@tonic-gate 	int log_success = 0;
3567c478bd9Sstevel@tonic-gate 	int log_failure = 0;
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 	/* ignore comments */
3597c478bd9Sstevel@tonic-gate 	if (*buffer == '#')
3607c478bd9Sstevel@tonic-gate 		return (TRUE);
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 	if (kwarnd_debug)
3637c478bd9Sstevel@tonic-gate 		printf("parseconf: buffer=%s", buffer);
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 	/* find end of principal */
3667c478bd9Sstevel@tonic-gate 	principal = buffer;
3677c478bd9Sstevel@tonic-gate 	for (send_to = buffer; *send_to && !isspace(*send_to);
3687c478bd9Sstevel@tonic-gate 		send_to++);
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	/* find first non whitespace after principal (start of send_to) */
3717c478bd9Sstevel@tonic-gate 	if (*send_to) {
3727c478bd9Sstevel@tonic-gate 		*send_to = '\0';
3737c478bd9Sstevel@tonic-gate 		send_to++;
3747c478bd9Sstevel@tonic-gate 		while (*send_to && isspace(*send_to))
3757c478bd9Sstevel@tonic-gate 			send_to++;
3767c478bd9Sstevel@tonic-gate 	}
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 	/* if no send_to, continue, bad entry */
3797c478bd9Sstevel@tonic-gate 	if (! *send_to)
3807c478bd9Sstevel@tonic-gate 		return (TRUE);
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 	/* find end of send_to */
3837c478bd9Sstevel@tonic-gate 	for (ends = send_to; *ends && !isspace(*ends);
3847c478bd9Sstevel@tonic-gate 		ends++);
3857c478bd9Sstevel@tonic-gate 	if (*ends)
3867c478bd9Sstevel@tonic-gate 		*ends = '\0';
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 	if (strchr(send_to, ':')) {
3907c478bd9Sstevel@tonic-gate 		/* we've got renew opts */
3917c478bd9Sstevel@tonic-gate 		char *st = NULL, *op = NULL;
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 		op = strdup(send_to);
3947c478bd9Sstevel@tonic-gate 		if (!op)
3957c478bd9Sstevel@tonic-gate 			return (FALSE);
3967c478bd9Sstevel@tonic-gate 		st = strchr(op, ':');
3977c478bd9Sstevel@tonic-gate 		*st = '\0';
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate 		if (strncasecmp(op, "renew", sizeof ("renew")) == 0) {
4007c478bd9Sstevel@tonic-gate 			renew = 1;
4017c478bd9Sstevel@tonic-gate 		} else {
4027c478bd9Sstevel@tonic-gate 			free(op);
4037c478bd9Sstevel@tonic-gate 			/* got a ':' but not preceeded w/renew, badent, skip */
4047c478bd9Sstevel@tonic-gate 			if (kwarnd_debug)
4057c478bd9Sstevel@tonic-gate 				printf("parseconf: colon badent, skip\n");
4067c478bd9Sstevel@tonic-gate 			return (TRUE);
4077c478bd9Sstevel@tonic-gate 		}
4087c478bd9Sstevel@tonic-gate 		free(op);
4097c478bd9Sstevel@tonic-gate 		op = NULL;
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate 		st++;
4127c478bd9Sstevel@tonic-gate 		if (!st || !*st || isspace(*st)) {
4137c478bd9Sstevel@tonic-gate 			if (kwarnd_debug)
4147c478bd9Sstevel@tonic-gate 				printf("parseconf: st badent, skip\n");
4157c478bd9Sstevel@tonic-gate 			/* bad ent, skip */
4167c478bd9Sstevel@tonic-gate 			return (TRUE);
4177c478bd9Sstevel@tonic-gate 		}
4187c478bd9Sstevel@tonic-gate 		if (renew && strchr(st, ',')) {
4197c478bd9Sstevel@tonic-gate 			while (1) {
4207c478bd9Sstevel@tonic-gate 				/* loop thru comma seperated list-o-opts */
4217c478bd9Sstevel@tonic-gate 				char *comma = NULL, *c = NULL, *l = NULL;
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate 				if (st && (comma = strchr(st, ','))) {
4247c478bd9Sstevel@tonic-gate 					l = strdup(st);
4257c478bd9Sstevel@tonic-gate 					if (!l)
4267c478bd9Sstevel@tonic-gate 						return (FALSE);
4277c478bd9Sstevel@tonic-gate 					c = strchr(l, ',');
4287c478bd9Sstevel@tonic-gate 					*c = '\0';
4297c478bd9Sstevel@tonic-gate 					if (!cmp_renew_opts(l, &log_success,
4307c478bd9Sstevel@tonic-gate 							    &log_failure)) {
4317c478bd9Sstevel@tonic-gate 						free(l);
4327c478bd9Sstevel@tonic-gate 						/* badent, skip */
4337c478bd9Sstevel@tonic-gate 						return (TRUE);
4347c478bd9Sstevel@tonic-gate 					}
4357c478bd9Sstevel@tonic-gate 					free(l);
4367c478bd9Sstevel@tonic-gate 					l = NULL;
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate 					st = comma;
4397c478bd9Sstevel@tonic-gate 					st++;
4407c478bd9Sstevel@tonic-gate 				} else {
4417c478bd9Sstevel@tonic-gate 					if (st) {
4427c478bd9Sstevel@tonic-gate 						if (!cmp_renew_opts(st,
4437c478bd9Sstevel@tonic-gate 							    &log_success,
4447c478bd9Sstevel@tonic-gate 							    &log_failure)) {
4457c478bd9Sstevel@tonic-gate 							/* badent, skip */
4467c478bd9Sstevel@tonic-gate 							return (TRUE);
4477c478bd9Sstevel@tonic-gate 						}
4487c478bd9Sstevel@tonic-gate 					}
4497c478bd9Sstevel@tonic-gate 					break;
4507c478bd9Sstevel@tonic-gate 				}
4517c478bd9Sstevel@tonic-gate 			} /* while */
4527c478bd9Sstevel@tonic-gate 		} else if (st) {
4537c478bd9Sstevel@tonic-gate 			/* we just have one opt */
4547c478bd9Sstevel@tonic-gate 			if (!cmp_renew_opts(st, &log_success, &log_failure)) {
4557c478bd9Sstevel@tonic-gate 				/* badent, skip */
4567c478bd9Sstevel@tonic-gate 				return (TRUE);
4577c478bd9Sstevel@tonic-gate 			}
4587c478bd9Sstevel@tonic-gate 		}
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate 		/* if send_to is "renew", note it and refind send_to */
4617c478bd9Sstevel@tonic-gate 	} else if (strncasecmp(send_to, "renew",
4627c478bd9Sstevel@tonic-gate 			    sizeof ("renew")) == 0) {
4637c478bd9Sstevel@tonic-gate 		renew = 1;
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	}
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	if (kwarnd_debug) {
4687c478bd9Sstevel@tonic-gate 		printf("parseconf: renew=%d, log failure=%d, log success=%d\n",
4697c478bd9Sstevel@tonic-gate 		    renew, log_failure, log_success);
4707c478bd9Sstevel@tonic-gate 	}
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	if (renew) {
4737c478bd9Sstevel@tonic-gate 		/* find first non whitespace after send_to (start of exptime) */
4747c478bd9Sstevel@tonic-gate 		for (send_to = ends+1; *send_to && isspace(*send_to);
4757c478bd9Sstevel@tonic-gate 		    send_to++);
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 		/* if no send_to, continue, bad entry */
4787c478bd9Sstevel@tonic-gate 		if (! *send_to) {
4797c478bd9Sstevel@tonic-gate 			if (kwarnd_debug)
4807c478bd9Sstevel@tonic-gate 				printf("parseconf: no send_to, badent, skip\n");
4817c478bd9Sstevel@tonic-gate 			return (TRUE);
4827c478bd9Sstevel@tonic-gate 		}
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate 		/* find end of send_to */
4857c478bd9Sstevel@tonic-gate 		for (ends = send_to; *ends && !isspace(*ends);
4867c478bd9Sstevel@tonic-gate 		    ends++);
4877c478bd9Sstevel@tonic-gate 		if (*ends)
4887c478bd9Sstevel@tonic-gate 			*ends = '\0';
4897c478bd9Sstevel@tonic-gate 	}
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate 	/* find first non whitespace after send_to (start of exptime) */
4937c478bd9Sstevel@tonic-gate 	for (exptime = ends+1; *exptime && isspace(*exptime);
4947c478bd9Sstevel@tonic-gate 		exptime++);
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 	/* if no exptime, continue, bad entry */
4977c478bd9Sstevel@tonic-gate 	if (! *exptime) {
4987c478bd9Sstevel@tonic-gate 		if (kwarnd_debug)
4997c478bd9Sstevel@tonic-gate 			printf("parseconf: no exptime, badent, skip\n");
5007c478bd9Sstevel@tonic-gate 		return (TRUE);
5017c478bd9Sstevel@tonic-gate 	}
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate 	/* find end of exptime */
5047c478bd9Sstevel@tonic-gate 	for (ends = exptime; *ends && !isspace(*ends); ends++);
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate 	tm = ends - 1;
5077c478bd9Sstevel@tonic-gate 	if (*tm == 's')
5087c478bd9Sstevel@tonic-gate 		time_mode = 1;
5097c478bd9Sstevel@tonic-gate 	else if (*tm == 'm')
5107c478bd9Sstevel@tonic-gate 		time_mode = 2;
5117c478bd9Sstevel@tonic-gate 	else if (*tm == 'h')
5127c478bd9Sstevel@tonic-gate 		time_mode = 3;
5137c478bd9Sstevel@tonic-gate 	else
5147c478bd9Sstevel@tonic-gate 		time_mode = 1;
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 	if (*tm)
5177c478bd9Sstevel@tonic-gate 		*tm = '\0';
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate 	if (kwarnd_debug) {
5207c478bd9Sstevel@tonic-gate 		printf("parseconf: send_to = '%s', exptime='%s'\n",
5217c478bd9Sstevel@tonic-gate 		    send_to, exptime);
5227c478bd9Sstevel@tonic-gate 	}
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate 	/* find first non whitespace after exptime (start of emailid) */
5257c478bd9Sstevel@tonic-gate 	for (emailid = ends+1; *emailid && isspace(*emailid); emailid++);
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 	/* find end of emailid */
5287c478bd9Sstevel@tonic-gate 	if (*emailid) {
5297c478bd9Sstevel@tonic-gate 		for (ends = emailid; *ends && !isspace(*ends);
5307c478bd9Sstevel@tonic-gate 			ends++);
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate 		if (*ends)
5337c478bd9Sstevel@tonic-gate 			*ends = '\0';
5347c478bd9Sstevel@tonic-gate 	}
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 	/* if send to mail and no mail address, bad entry */
5377c478bd9Sstevel@tonic-gate 	if ((strcmp(send_to, "mail") == 0) && (!*emailid)) {
5387c478bd9Sstevel@tonic-gate 		if (kwarnd_debug)
5397c478bd9Sstevel@tonic-gate 			printf("parseconf: returns true; no mail addr\n");
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext("missing mail address"
5427c478bd9Sstevel@tonic-gate 			" in config entry: \n%s %s %s "
5437c478bd9Sstevel@tonic-gate 			" cannot mail warning"), principal,
5447c478bd9Sstevel@tonic-gate 			send_to, exptime);
5457c478bd9Sstevel@tonic-gate 		return (TRUE);
5467c478bd9Sstevel@tonic-gate 	}
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate 	/* create an entry */
5497c478bd9Sstevel@tonic-gate 	config_entry = (config_entry_list_t *)
5507c478bd9Sstevel@tonic-gate 		malloc(sizeof (*config_entry_list));
5517c478bd9Sstevel@tonic-gate 	if (config_entry == NULL)
5527c478bd9Sstevel@tonic-gate 		return (FALSE);
5537c478bd9Sstevel@tonic-gate 	(void) memset(config_entry, 0, sizeof (*config_entry_list));
5547c478bd9Sstevel@tonic-gate 	config_entry->principal = strdup(principal);
5557c478bd9Sstevel@tonic-gate 	if (config_entry->principal == NULL)
5567c478bd9Sstevel@tonic-gate 		return (FALSE);
5577c478bd9Sstevel@tonic-gate 	config_entry->where_to = strdup(send_to);
5587c478bd9Sstevel@tonic-gate 	if (config_entry->where_to == NULL)
5597c478bd9Sstevel@tonic-gate 		return (FALSE);
5607c478bd9Sstevel@tonic-gate 	etime = atol(exptime);
5617c478bd9Sstevel@tonic-gate 	if (time_mode == 1)
5627c478bd9Sstevel@tonic-gate 		config_entry->seconds_to_warn = etime;
5637c478bd9Sstevel@tonic-gate 	else if (time_mode == 2)
5647c478bd9Sstevel@tonic-gate 		config_entry->seconds_to_warn = etime * 60;
5657c478bd9Sstevel@tonic-gate 	else if (time_mode == 3)
5667c478bd9Sstevel@tonic-gate 		config_entry->seconds_to_warn = etime * 60 * 60;
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 	if (*emailid) {
5697c478bd9Sstevel@tonic-gate 		config_entry->email = strdup(emailid);
5707c478bd9Sstevel@tonic-gate 		if (config_entry->email == NULL)
5717c478bd9Sstevel@tonic-gate 			return (FALSE);
5727c478bd9Sstevel@tonic-gate 	}
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate 	config_entry->renew = renew;
5757c478bd9Sstevel@tonic-gate 	config_entry->log_success = log_success;
5767c478bd9Sstevel@tonic-gate 	config_entry->log_failure = log_failure;
5777c478bd9Sstevel@tonic-gate 	config_entry->next = config_entry_list;
5787c478bd9Sstevel@tonic-gate 	config_entry_list = config_entry;
5797c478bd9Sstevel@tonic-gate 	if (kwarnd_debug)
5807c478bd9Sstevel@tonic-gate 		printf("parseconf: returns true; celist=%p\n",
5817c478bd9Sstevel@tonic-gate 		    config_entry_list);
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 	return (TRUE);
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate /*
5877c478bd9Sstevel@tonic-gate  * find a specific warn.conf entry.
5887c478bd9Sstevel@tonic-gate  */
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate static config_entry_list_t *
5917c478bd9Sstevel@tonic-gate find_warning_info(char *principal)
5927c478bd9Sstevel@tonic-gate {
5937c478bd9Sstevel@tonic-gate 	config_entry_list_t	*config_entry;
5947c478bd9Sstevel@tonic-gate 	/* look for a specific entry */
5957c478bd9Sstevel@tonic-gate 	for (config_entry = config_entry_list; config_entry;
5967c478bd9Sstevel@tonic-gate 		config_entry = config_entry->next) {
5977c478bd9Sstevel@tonic-gate 		if (strcmp(config_entry->principal, principal) == 0) {
5987c478bd9Sstevel@tonic-gate 			return (config_entry);
5997c478bd9Sstevel@tonic-gate 		}
6007c478bd9Sstevel@tonic-gate 	}
6017c478bd9Sstevel@tonic-gate 	/* look for a wild card entry */
6027c478bd9Sstevel@tonic-gate 	for (config_entry = config_entry_list; config_entry;
6037c478bd9Sstevel@tonic-gate 		config_entry = config_entry->next) {
6047c478bd9Sstevel@tonic-gate 		if (strcmp(config_entry->principal, "*") == 0) {
6057c478bd9Sstevel@tonic-gate 			return (config_entry);
6067c478bd9Sstevel@tonic-gate 		}
6077c478bd9Sstevel@tonic-gate 	}
6087c478bd9Sstevel@tonic-gate 	/* nothing found */
6097c478bd9Sstevel@tonic-gate 	return (NULL);
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate }
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate /*
6147c478bd9Sstevel@tonic-gate  * create a pipe, fork and exec a command,
6157c478bd9Sstevel@tonic-gate  */
6167c478bd9Sstevel@tonic-gate static FILE *
6177c478bd9Sstevel@tonic-gate safe_popen_w(char *path_to_cmd, char **argv)
6187c478bd9Sstevel@tonic-gate {
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate 	int fd[2];
6217c478bd9Sstevel@tonic-gate 	FILE *fp;
6227c478bd9Sstevel@tonic-gate 	char *envp[2];
6237c478bd9Sstevel@tonic-gate 
6247c478bd9Sstevel@tonic-gate 	if (pipe(fd) == -1)
6257c478bd9Sstevel@tonic-gate 		return (NULL);
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 	switch (fork()) {
6297c478bd9Sstevel@tonic-gate 	case -1:
6307c478bd9Sstevel@tonic-gate 		(void) close(fd[0]);
6317c478bd9Sstevel@tonic-gate 		(void) close(fd[1]);
6327c478bd9Sstevel@tonic-gate 		return (NULL);
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate 	case 0:
6357c478bd9Sstevel@tonic-gate 		close(fd[1]);
6367c478bd9Sstevel@tonic-gate 		/* fd[0] is the end we read from */
6377c478bd9Sstevel@tonic-gate 		if (fd[0] != 0) {
6387c478bd9Sstevel@tonic-gate 			close(0);
6397c478bd9Sstevel@tonic-gate 			dup(fd[0]);
6407c478bd9Sstevel@tonic-gate 		}
6417c478bd9Sstevel@tonic-gate 		close(1);
6427c478bd9Sstevel@tonic-gate 		close(2);
6437c478bd9Sstevel@tonic-gate 		envp[0] = "PATH=/usr/bin";
6447c478bd9Sstevel@tonic-gate 		envp[1] = NULL;
6457c478bd9Sstevel@tonic-gate #ifdef	DEBUG
6467c478bd9Sstevel@tonic-gate 		{
6477c478bd9Sstevel@tonic-gate 			int fd;
6487c478bd9Sstevel@tonic-gate 			fd = open("/tmp/kwarn.out", O_WRONLY|O_TRUNC|O_CREAT,
6497c478bd9Sstevel@tonic-gate 				0666);
6507c478bd9Sstevel@tonic-gate 			if (fd != 1)
6517c478bd9Sstevel@tonic-gate 				dup(fd);
6527c478bd9Sstevel@tonic-gate 			if (fd != 2)
6537c478bd9Sstevel@tonic-gate 				dup(fd);
6547c478bd9Sstevel@tonic-gate 		}
6557c478bd9Sstevel@tonic-gate #endif
6567c478bd9Sstevel@tonic-gate 		(void) execve(path_to_cmd, argv, envp);
6577c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, "warnd: %m");
6587c478bd9Sstevel@tonic-gate 		_exit(1);
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	default:
6617c478bd9Sstevel@tonic-gate 		close(fd[0]);
6627c478bd9Sstevel@tonic-gate 		/* fd[1] is the end we write to */
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate 		fp = fdopen(fd[1], "w");
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 		if (fp == NULL) {
6677c478bd9Sstevel@tonic-gate 			(void) close(fd[1]);
6687c478bd9Sstevel@tonic-gate 			return (NULL);
6697c478bd9Sstevel@tonic-gate 		}
6707c478bd9Sstevel@tonic-gate 		return (fp);
6717c478bd9Sstevel@tonic-gate 	}
6727c478bd9Sstevel@tonic-gate }
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate 
675*24da5b34Srie static uid_t krb5_cc_uid;
6767c478bd9Sstevel@tonic-gate 
6777c478bd9Sstevel@tonic-gate void
6787c478bd9Sstevel@tonic-gate set_warnd_uid(uid_t uid)
6797c478bd9Sstevel@tonic-gate {
6807c478bd9Sstevel@tonic-gate 	/*
681*24da5b34Srie 	 * set the value of krb5_cc_uid, so it can be retrieved when
682*24da5b34Srie 	 * app_krb5_user_uid() is called by the underlying mechanism libraries.
6837c478bd9Sstevel@tonic-gate 	 */
6847c478bd9Sstevel@tonic-gate 	if (kwarnd_debug)
6857c478bd9Sstevel@tonic-gate 		printf("set_warnd_uid called with uid = %d\n", uid);
686*24da5b34Srie 	krb5_cc_uid = uid;
6877c478bd9Sstevel@tonic-gate }
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate uid_t
690*24da5b34Srie app_krb5_user_uid(void)
6917c478bd9Sstevel@tonic-gate {
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate 	/*
694*24da5b34Srie 	 * return the value set when one of the kwarnd procedures was
6957c478bd9Sstevel@tonic-gate 	 * entered. This is the value of the uid under which the
6967c478bd9Sstevel@tonic-gate 	 * underlying mechanism library must operate in order to
6977c478bd9Sstevel@tonic-gate 	 * get the user's credentials. This call is necessary since
698*24da5b34Srie 	 * kwarnd runs as root and credentials are many times stored
6997c478bd9Sstevel@tonic-gate 	 * in files and directories specific to the user
7007c478bd9Sstevel@tonic-gate 	 */
7017c478bd9Sstevel@tonic-gate 	if (kwarnd_debug)
702*24da5b34Srie 		printf("app_krb5_user_uid called and returning uid = %d\n",
703*24da5b34Srie 		    krb5_cc_uid);
704*24da5b34Srie 	return (krb5_cc_uid);
7057c478bd9Sstevel@tonic-gate }
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate static bool_t
7097c478bd9Sstevel@tonic-gate getpruid(char *pr, uid_t *uid)
7107c478bd9Sstevel@tonic-gate {
7117c478bd9Sstevel@tonic-gate 	char *rcp1 = NULL, *rcp2 = NULL, *rcp3 = NULL;
7127c478bd9Sstevel@tonic-gate 	struct passwd *pw;
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate 	rcp1 = strdup(pr);
7157c478bd9Sstevel@tonic-gate 	if (!rcp1)
7167c478bd9Sstevel@tonic-gate 		return (FALSE);
7177c478bd9Sstevel@tonic-gate 	rcp2 = strtok(rcp1, "@");
7187c478bd9Sstevel@tonic-gate 	rcp3 = strtok(rcp2, "/");
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate 	if (rcp3) {
7217c478bd9Sstevel@tonic-gate 		pw = getpwnam(rcp3);
7227c478bd9Sstevel@tonic-gate 		*uid = pw->pw_uid;
7237c478bd9Sstevel@tonic-gate 		free(rcp1);
7247c478bd9Sstevel@tonic-gate 		return (TRUE);
7257c478bd9Sstevel@tonic-gate 	}
7267c478bd9Sstevel@tonic-gate 
7277c478bd9Sstevel@tonic-gate 	free(rcp1);
7287c478bd9Sstevel@tonic-gate 	return (FALSE);
7297c478bd9Sstevel@tonic-gate }
7307c478bd9Sstevel@tonic-gate 
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate static krb5_error_code
7337c478bd9Sstevel@tonic-gate renew_creds(
7347c478bd9Sstevel@tonic-gate 	char *princ,
7357c478bd9Sstevel@tonic-gate 	time_t *new_exp_time) /* out */
7367c478bd9Sstevel@tonic-gate {
7377c478bd9Sstevel@tonic-gate 	krb5_creds my_creds;
7387c478bd9Sstevel@tonic-gate 	krb5_error_code code = 0;
7397c478bd9Sstevel@tonic-gate 	struct k5_data k5;
7407c478bd9Sstevel@tonic-gate 
741*24da5b34Srie 	uid_t saved_u = app_krb5_user_uid();
7427c478bd9Sstevel@tonic-gate 	uid_t u;
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 	if (kwarnd_debug)
745*24da5b34Srie 		printf("renew start: uid=%d\n", app_krb5_user_uid());
7467c478bd9Sstevel@tonic-gate 
7477c478bd9Sstevel@tonic-gate 	if (!getpruid(princ, &u)) {
7487c478bd9Sstevel@tonic-gate 		if (kwarnd_debug)
7497c478bd9Sstevel@tonic-gate 			printf("renew: getpruid failed, princ='%s'\n",
7507c478bd9Sstevel@tonic-gate 			    princ ? princ : "<null>");
7517c478bd9Sstevel@tonic-gate 
7527c478bd9Sstevel@tonic-gate 		return (-1); /* better err num? */
7537c478bd9Sstevel@tonic-gate 	}
7547c478bd9Sstevel@tonic-gate 
7557c478bd9Sstevel@tonic-gate 	set_warnd_uid(u);
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate 	(void) memset(&my_creds, 0, sizeof (my_creds));
7587c478bd9Sstevel@tonic-gate 	(void) memset(&k5, 0, sizeof (k5));
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate 	if (code = krb5_init_context(&k5.ctx)) {
7617c478bd9Sstevel@tonic-gate 		com_err(progname, code,
7627c478bd9Sstevel@tonic-gate 			gettext("while initializing Kerberos 5 library"));
7637c478bd9Sstevel@tonic-gate 		goto out;
7647c478bd9Sstevel@tonic-gate 	}
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate 	if ((code = krb5_cc_default(k5.ctx, &k5.cc))) {
7677c478bd9Sstevel@tonic-gate 		com_err(progname, code,
7687c478bd9Sstevel@tonic-gate 			gettext("while getting default ccache"));
7697c478bd9Sstevel@tonic-gate 		goto out;
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate 	}
7727c478bd9Sstevel@tonic-gate 
7737c478bd9Sstevel@tonic-gate 	if ((code = krb5_parse_name(k5.ctx, princ,
7747c478bd9Sstevel@tonic-gate 				    &k5.me))) {
7757c478bd9Sstevel@tonic-gate 		com_err(progname, code, gettext("when parsing name %s"),
7767c478bd9Sstevel@tonic-gate 			princ);
7777c478bd9Sstevel@tonic-gate 		goto out;
7787c478bd9Sstevel@tonic-gate 	}
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate 	if ((code = krb5_get_renewed_creds(k5.ctx, &my_creds, k5.me, k5.cc,
7817c478bd9Sstevel@tonic-gate 					NULL))) {
7827c478bd9Sstevel@tonic-gate 		com_err(progname, code, gettext("while renewing creds"));
7837c478bd9Sstevel@tonic-gate 		goto out;
7847c478bd9Sstevel@tonic-gate 	}
7857c478bd9Sstevel@tonic-gate 
7867c478bd9Sstevel@tonic-gate 	if (code = krb5_cc_initialize(k5.ctx, k5.cc, k5.me)) {
7877c478bd9Sstevel@tonic-gate 		com_err(progname, code, gettext("when initializing cache %s"),
7887c478bd9Sstevel@tonic-gate 			"defcc");
7897c478bd9Sstevel@tonic-gate 		goto out;
7907c478bd9Sstevel@tonic-gate 	}
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate 	if (code = krb5_cc_store_cred(k5.ctx, k5.cc, &my_creds)) {
7937c478bd9Sstevel@tonic-gate 		com_err(progname, code, gettext("while storing credentials"));
7947c478bd9Sstevel@tonic-gate 		goto out;
7957c478bd9Sstevel@tonic-gate 	}
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate 	/* "return" new expire time */
7987c478bd9Sstevel@tonic-gate 	*new_exp_time = my_creds.times.endtime;
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate out:
8017c478bd9Sstevel@tonic-gate 	krb5_free_cred_contents(k5.ctx, &my_creds);
8027c478bd9Sstevel@tonic-gate 
8037c478bd9Sstevel@tonic-gate 	if (k5.name)
8047c478bd9Sstevel@tonic-gate 		krb5_free_unparsed_name(k5.ctx, k5.name);
8057c478bd9Sstevel@tonic-gate 	if (k5.me)
8067c478bd9Sstevel@tonic-gate 		krb5_free_principal(k5.ctx, k5.me);
8077c478bd9Sstevel@tonic-gate 	if (k5.cc)
8087c478bd9Sstevel@tonic-gate 		krb5_cc_close(k5.ctx, k5.cc);
8097c478bd9Sstevel@tonic-gate 	if (k5.ctx)
8107c478bd9Sstevel@tonic-gate 		krb5_free_context(k5.ctx);
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate 	set_warnd_uid(saved_u);
8137c478bd9Sstevel@tonic-gate 
8147c478bd9Sstevel@tonic-gate 	if (kwarnd_debug)
8157c478bd9Sstevel@tonic-gate 		printf("renew end: code=%s, uid=%d\n", error_message(code),
816*24da5b34Srie 		    app_krb5_user_uid());
8177c478bd9Sstevel@tonic-gate 
8187c478bd9Sstevel@tonic-gate 	return (code);
8197c478bd9Sstevel@tonic-gate }
8207c478bd9Sstevel@tonic-gate 
8217c478bd9Sstevel@tonic-gate static bool_t
8227c478bd9Sstevel@tonic-gate loggedon(char *name)
8237c478bd9Sstevel@tonic-gate {
8247c478bd9Sstevel@tonic-gate 	register struct utmpx *ubuf;
8257c478bd9Sstevel@tonic-gate 	char    *rcp1 = NULL, *rcp2 = NULL, *rcp3 = NULL;
8267c478bd9Sstevel@tonic-gate 
8277c478bd9Sstevel@tonic-gate 	/*
8287c478bd9Sstevel@tonic-gate 	 * strip any realm or instance from principal so we can match
8297c478bd9Sstevel@tonic-gate 	 * against unix userid.
8307c478bd9Sstevel@tonic-gate 	 */
8317c478bd9Sstevel@tonic-gate 	rcp1 = strdup(name);
8327c478bd9Sstevel@tonic-gate 	if (!rcp1)
8337c478bd9Sstevel@tonic-gate 		return (FALSE);
8347c478bd9Sstevel@tonic-gate 	rcp2 = strtok(rcp1, "@");
8357c478bd9Sstevel@tonic-gate 	rcp3 = strtok(rcp2, "/");
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate 	/*
8387c478bd9Sstevel@tonic-gate 	 * Scan through the "utmpx" file for the
8397c478bd9Sstevel@tonic-gate 	 * entry for the person we want to send to.
8407c478bd9Sstevel@tonic-gate 	 */
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate 	setutxent();
8437c478bd9Sstevel@tonic-gate 	while ((ubuf = getutxent()) != NULL) {
8447c478bd9Sstevel@tonic-gate 		if (ubuf->ut_type == USER_PROCESS) {
8457c478bd9Sstevel@tonic-gate 			if (strncmp(rcp3, ubuf->ut_user,
8467c478bd9Sstevel@tonic-gate 				    sizeof (ubuf->ut_user)) == 0) {
8477c478bd9Sstevel@tonic-gate 				free(rcp1);
8487c478bd9Sstevel@tonic-gate 				endutxent();
8497c478bd9Sstevel@tonic-gate 				return (TRUE);
8507c478bd9Sstevel@tonic-gate 
8517c478bd9Sstevel@tonic-gate 			}
8527c478bd9Sstevel@tonic-gate 		}
8537c478bd9Sstevel@tonic-gate 	}
8547c478bd9Sstevel@tonic-gate 	free(rcp1);
8557c478bd9Sstevel@tonic-gate 	endutxent();
8567c478bd9Sstevel@tonic-gate 
8577c478bd9Sstevel@tonic-gate 	if (kwarnd_debug)
8587c478bd9Sstevel@tonic-gate 		printf("loggedon: returning false for user `%s'\n", rcp1);
8597c478bd9Sstevel@tonic-gate 
8607c478bd9Sstevel@tonic-gate 	return (FALSE);
8617c478bd9Sstevel@tonic-gate }
8627c478bd9Sstevel@tonic-gate 
8637c478bd9Sstevel@tonic-gate /*
8647c478bd9Sstevel@tonic-gate  * main loop to check the cred warning list and send the warnings
8657c478bd9Sstevel@tonic-gate  * the appropriate location based on warn.conf or auto-renew creds.
8667c478bd9Sstevel@tonic-gate  */
8677c478bd9Sstevel@tonic-gate 
8687c478bd9Sstevel@tonic-gate void
8697c478bd9Sstevel@tonic-gate kwarnd_check_warning_list(void)
8707c478bd9Sstevel@tonic-gate { /* func */
8717c478bd9Sstevel@tonic-gate 	cred_warning_list_t	*cw;  /* cred warning */
8727c478bd9Sstevel@tonic-gate 	config_entry_list_t	*ce;  /* config entry */
8737c478bd9Sstevel@tonic-gate 	time_t			now;
8747c478bd9Sstevel@tonic-gate 	int			minutes;
8757c478bd9Sstevel@tonic-gate 	char			buff[256];
8767c478bd9Sstevel@tonic-gate 	char			cmdline[256];
8777c478bd9Sstevel@tonic-gate 	FILE			*fp;
8787c478bd9Sstevel@tonic-gate 	char			*subj = "Kerberos credentials expiring";
8797c478bd9Sstevel@tonic-gate 	char			*renew_subj = "Kerberos credentials renewed";
8807c478bd9Sstevel@tonic-gate 
8817c478bd9Sstevel@tonic-gate 	if (kwarnd_debug)
882*24da5b34Srie 		printf("check list: start: uid=%d, cw list=%p\n",
883*24da5b34Srie 		    app_krb5_user_uid(), cred_warning_list);
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate 	while (1) {
8867c478bd9Sstevel@tonic-gate 		(void) poll(NULL, NULL, 60000);
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate 		for (cw = cred_warning_list;
8897c478bd9Sstevel@tonic-gate 			cw != NULL;
8907c478bd9Sstevel@tonic-gate 			cw = cw->next) {
8917c478bd9Sstevel@tonic-gate 			int send_msg = 0;
8927c478bd9Sstevel@tonic-gate 
8937c478bd9Sstevel@tonic-gate 			time(&now);
8947c478bd9Sstevel@tonic-gate 			if (now >= cw->cred_warn_time) {
8957c478bd9Sstevel@tonic-gate 				int renew_attempted = 0;
8967c478bd9Sstevel@tonic-gate 				int renew_failed = 0;
8977c478bd9Sstevel@tonic-gate 				int renew_tooclose = 0;
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate 				if (kwarnd_debug)
9007c478bd9Sstevel@tonic-gate 					printf("checklist: now >= warn_t\n");
9017c478bd9Sstevel@tonic-gate 
9027c478bd9Sstevel@tonic-gate 				ce = find_warning_info(cw->warn_name);
9037c478bd9Sstevel@tonic-gate 				minutes = (cw->cred_exp_time -
9047c478bd9Sstevel@tonic-gate 					now + 59) / 60;
9057c478bd9Sstevel@tonic-gate 
9067c478bd9Sstevel@tonic-gate 				if (kwarnd_debug)
9077c478bd9Sstevel@tonic-gate 					printf("checklist: where_to=%s\n",
9087c478bd9Sstevel@tonic-gate 					    ce->where_to ?
9097c478bd9Sstevel@tonic-gate 					    ce->where_to : "null");
9107c478bd9Sstevel@tonic-gate 
9117c478bd9Sstevel@tonic-gate 				if (ce->renew &&
9127c478bd9Sstevel@tonic-gate 				    loggedon(cw->warn_name)) {
9137c478bd9Sstevel@tonic-gate 					krb5_error_code code;
9147c478bd9Sstevel@tonic-gate 					time_t new_exp_time;
9157c478bd9Sstevel@tonic-gate 
9167c478bd9Sstevel@tonic-gate 					renew_attempted = 1;
9177c478bd9Sstevel@tonic-gate 					code = renew_creds(
9187c478bd9Sstevel@tonic-gate 						cw->warn_name,
9197c478bd9Sstevel@tonic-gate 						&new_exp_time);
9207c478bd9Sstevel@tonic-gate 					if (!code) {
9217c478bd9Sstevel@tonic-gate 						/* krb5 api renew success */
9227c478bd9Sstevel@tonic-gate 
9237c478bd9Sstevel@tonic-gate 						/*
9247c478bd9Sstevel@tonic-gate 						 * So we had api success
9257c478bd9Sstevel@tonic-gate 						 * but the new exp time
9267c478bd9Sstevel@tonic-gate 						 * is same as current one
9277c478bd9Sstevel@tonic-gate 						 * so we are too close
9287c478bd9Sstevel@tonic-gate 						 * to Renewable_life time.
9297c478bd9Sstevel@tonic-gate 						 */
9307c478bd9Sstevel@tonic-gate 						if (cw->cred_exp_time
9317c478bd9Sstevel@tonic-gate 						    == new_exp_time) {
9327c478bd9Sstevel@tonic-gate 							renew_tooclose = 1;
9337c478bd9Sstevel@tonic-gate 							if (kwarnd_debug)
9347c478bd9Sstevel@tonic-gate 								printf(
9357c478bd9Sstevel@tonic-gate 		"checklist: new expire time same as old expire time\n");
9367c478bd9Sstevel@tonic-gate 
9377c478bd9Sstevel@tonic-gate 							if (ce->log_failure) {
9387c478bd9Sstevel@tonic-gate 								send_msg = 1;
9397c478bd9Sstevel@tonic-gate 								snprintf(buff,
9407c478bd9Sstevel@tonic-gate 								sizeof (buff),
9417c478bd9Sstevel@tonic-gate 					gettext("%s:\r\nYour kerberos"
9427c478bd9Sstevel@tonic-gate 					" credentials have not been renewed"
9437c478bd9Sstevel@tonic-gate 					" (too close to Renewable_life).\r\n"
9447c478bd9Sstevel@tonic-gate 					"Please run kinit(1).\r\n"),
9457c478bd9Sstevel@tonic-gate 								cw->warn_name);
9467c478bd9Sstevel@tonic-gate 							}
9477c478bd9Sstevel@tonic-gate 						} else {
9487c478bd9Sstevel@tonic-gate 							/* update times */
9497c478bd9Sstevel@tonic-gate 							cw->cred_exp_time =
9507c478bd9Sstevel@tonic-gate 								new_exp_time;
9517c478bd9Sstevel@tonic-gate 							cw->cred_warn_time =
9527c478bd9Sstevel@tonic-gate 							    new_exp_time -
9537c478bd9Sstevel@tonic-gate 							    ce->seconds_to_warn;
9547c478bd9Sstevel@tonic-gate 						}
9557c478bd9Sstevel@tonic-gate 
9567c478bd9Sstevel@tonic-gate 						if (kwarnd_debug)
9577c478bd9Sstevel@tonic-gate 							printf(
9587c478bd9Sstevel@tonic-gate 						    "check list: new_w_t=%d\n",
9597c478bd9Sstevel@tonic-gate 						    cw->cred_warn_time);
9607c478bd9Sstevel@tonic-gate 
9617c478bd9Sstevel@tonic-gate 						if (!renew_tooclose &&
9627c478bd9Sstevel@tonic-gate 						    ce->log_success) {
9637c478bd9Sstevel@tonic-gate 							if (kwarnd_debug)
9647c478bd9Sstevel@tonic-gate 								printf(
9657c478bd9Sstevel@tonic-gate 						"check list: log success\n");
9667c478bd9Sstevel@tonic-gate 
9677c478bd9Sstevel@tonic-gate 							send_msg = 1;
9687c478bd9Sstevel@tonic-gate 							snprintf(buff,
9697c478bd9Sstevel@tonic-gate 								sizeof (buff),
9707c478bd9Sstevel@tonic-gate 						gettext("%s:\r\nYour kerberos"
9717c478bd9Sstevel@tonic-gate 					" credentials have been renewed.\r\n"),
9727c478bd9Sstevel@tonic-gate 								cw->warn_name);
9737c478bd9Sstevel@tonic-gate 						}
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate 					}  /* !(code) */
9767c478bd9Sstevel@tonic-gate 
9777c478bd9Sstevel@tonic-gate 					if (!renew_tooclose && code &&
9787c478bd9Sstevel@tonic-gate 					    ce->log_failure) {
9797c478bd9Sstevel@tonic-gate 						if (kwarnd_debug)
9807c478bd9Sstevel@tonic-gate 							printf(
9817c478bd9Sstevel@tonic-gate 						"check list: log FAIL\n");
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 						send_msg = 1;
9847c478bd9Sstevel@tonic-gate 						snprintf(buff,
9857c478bd9Sstevel@tonic-gate 							sizeof (buff),
9867c478bd9Sstevel@tonic-gate 					    gettext("%s:\r\nYour kerberos"
9877c478bd9Sstevel@tonic-gate 				" credentials failed to be renewed (%s).\r\n"),
9887c478bd9Sstevel@tonic-gate 							cw->warn_name,
9897c478bd9Sstevel@tonic-gate 							error_message(code));
9907c478bd9Sstevel@tonic-gate 					}
9917c478bd9Sstevel@tonic-gate 					renew_failed = code ? 1 : 0;
9927c478bd9Sstevel@tonic-gate 
9937c478bd9Sstevel@tonic-gate 				} else if (minutes > 0) {
9947c478bd9Sstevel@tonic-gate 					send_msg = 1;
9957c478bd9Sstevel@tonic-gate 					snprintf(buff, sizeof (buff),
9967c478bd9Sstevel@tonic-gate 					gettext("%s:\r\nyour kerberos"
9977c478bd9Sstevel@tonic-gate 					" credentials expire in less than"
9987c478bd9Sstevel@tonic-gate 					" %d minutes.\r\n"),
9997c478bd9Sstevel@tonic-gate 					cw->warn_name,
10007c478bd9Sstevel@tonic-gate 					minutes);
10017c478bd9Sstevel@tonic-gate 				} else {
10027c478bd9Sstevel@tonic-gate 					send_msg = 1;
10037c478bd9Sstevel@tonic-gate 					snprintf(buff, sizeof (buff),
10047c478bd9Sstevel@tonic-gate 					gettext("%s:\r\nyour kerberos"
10057c478bd9Sstevel@tonic-gate 					" credentials have expired.\r\n"),
10067c478bd9Sstevel@tonic-gate 					cw->warn_name);
10077c478bd9Sstevel@tonic-gate 				}
10087c478bd9Sstevel@tonic-gate 
10097c478bd9Sstevel@tonic-gate 				if (kwarnd_debug)
10107c478bd9Sstevel@tonic-gate 					printf("checklist: send_msg=%d\n",
10117c478bd9Sstevel@tonic-gate 					    send_msg);
10127c478bd9Sstevel@tonic-gate 				if (!send_msg)
10137c478bd9Sstevel@tonic-gate 					goto del_warning;
10147c478bd9Sstevel@tonic-gate 
10157c478bd9Sstevel@tonic-gate 				if (strncmp(ce->where_to,
10167c478bd9Sstevel@tonic-gate 					    "mail", sizeof ("mail")) == 0) {
10177c478bd9Sstevel@tonic-gate 					char *argv[3];
10187c478bd9Sstevel@tonic-gate 
10197c478bd9Sstevel@tonic-gate 					argv[0] = MAIL;
10207c478bd9Sstevel@tonic-gate 					(void) snprintf(cmdline,
10217c478bd9Sstevel@tonic-gate 							sizeof (cmdline),
10227c478bd9Sstevel@tonic-gate 							"%s",
10237c478bd9Sstevel@tonic-gate 							ce->email);
10247c478bd9Sstevel@tonic-gate 					argv[1] = cmdline;
10257c478bd9Sstevel@tonic-gate 					argv[2] = NULL;
10267c478bd9Sstevel@tonic-gate 
10277c478bd9Sstevel@tonic-gate 					fp = safe_popen_w(MAILPATH, argv);
10287c478bd9Sstevel@tonic-gate 
10297c478bd9Sstevel@tonic-gate 					if (fp) {
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate 						(void) fprintf(fp,
10327c478bd9Sstevel@tonic-gate 						"To: %s\nSubject: %s\n\n%s\n",
10337c478bd9Sstevel@tonic-gate 							    ce->email,
10347c478bd9Sstevel@tonic-gate 							    renew_attempted
10357c478bd9Sstevel@tonic-gate 							    ? renew_subj : subj,
10367c478bd9Sstevel@tonic-gate 							    buff);
10377c478bd9Sstevel@tonic-gate 
10387c478bd9Sstevel@tonic-gate 					    fclose(fp);
10397c478bd9Sstevel@tonic-gate 					} else {
10407c478bd9Sstevel@tonic-gate 					    syslog(LOG_ERR,
10417c478bd9Sstevel@tonic-gate 						gettext("could not fork "
10427c478bd9Sstevel@tonic-gate 						"mail program to e-mail "
10437c478bd9Sstevel@tonic-gate 						"warning to %s\n"),
10447c478bd9Sstevel@tonic-gate 						cmdline);
10457c478bd9Sstevel@tonic-gate 					}
10467c478bd9Sstevel@tonic-gate 
10477c478bd9Sstevel@tonic-gate 				} else if (strncmp(ce->where_to,
10487c478bd9Sstevel@tonic-gate 						"terminal",
10497c478bd9Sstevel@tonic-gate 						sizeof ("terminal")) == 0) {
10507c478bd9Sstevel@tonic-gate 
10517c478bd9Sstevel@tonic-gate 					warn_send(cw->warn_name,
10527c478bd9Sstevel@tonic-gate 						buff);
10537c478bd9Sstevel@tonic-gate 
10547c478bd9Sstevel@tonic-gate 				} else if (send_msg && strncmp(ce->where_to,
10557c478bd9Sstevel@tonic-gate 							    "syslog",
10567c478bd9Sstevel@tonic-gate 						sizeof ("syslog")) == 0) {
10577c478bd9Sstevel@tonic-gate 					syslog(LOG_NOTICE|LOG_AUTH,
10587c478bd9Sstevel@tonic-gate 					    "%s",
10597c478bd9Sstevel@tonic-gate 					    buff);
10607c478bd9Sstevel@tonic-gate #if 0
10617c478bd9Sstevel@tonic-gate 				} else if (strncmp(ce->where_to,
10627c478bd9Sstevel@tonic-gate 						"snmp",
10637c478bd9Sstevel@tonic-gate 						sizeof ("snmp")) == 0) {
10647c478bd9Sstevel@tonic-gate #endif
10657c478bd9Sstevel@tonic-gate 				} else {
10667c478bd9Sstevel@tonic-gate 					if (kwarnd_debug)
10677c478bd9Sstevel@tonic-gate 						printf(
10687c478bd9Sstevel@tonic-gate 						"unknown msg method=`%s'\n",
10697c478bd9Sstevel@tonic-gate 						ce->where_to);
10707c478bd9Sstevel@tonic-gate 
10717c478bd9Sstevel@tonic-gate 					exit(1);
10727c478bd9Sstevel@tonic-gate 				}
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate 			del_warning:
10757c478bd9Sstevel@tonic-gate 				if (!renew_attempted || renew_failed ||
10767c478bd9Sstevel@tonic-gate 				    renew_tooclose) {
10777c478bd9Sstevel@tonic-gate 					if (del_warning_pvt(cw->warn_name)
10787c478bd9Sstevel@tonic-gate 					    == TRUE) {
10797c478bd9Sstevel@tonic-gate 
10807c478bd9Sstevel@tonic-gate 						if (kwarnd_debug)
10817c478bd9Sstevel@tonic-gate 							printf(
10827c478bd9Sstevel@tonic-gate 						"check list: del warn succ\n");
10837c478bd9Sstevel@tonic-gate 
10847c478bd9Sstevel@tonic-gate 						break;
10857c478bd9Sstevel@tonic-gate 					} else {
10867c478bd9Sstevel@tonic-gate 						if (kwarnd_debug)
10877c478bd9Sstevel@tonic-gate 							printf(
10887c478bd9Sstevel@tonic-gate 						"could not delete warning\n");
10897c478bd9Sstevel@tonic-gate 
10907c478bd9Sstevel@tonic-gate 						syslog(LOG_ERR, gettext(
10917c478bd9Sstevel@tonic-gate 						"could not delete warning"));
10927c478bd9Sstevel@tonic-gate 
10937c478bd9Sstevel@tonic-gate 						exit(1);
10947c478bd9Sstevel@tonic-gate 					    }
10957c478bd9Sstevel@tonic-gate 					}
10967c478bd9Sstevel@tonic-gate 
10977c478bd9Sstevel@tonic-gate 				} /* if (now) */
10987c478bd9Sstevel@tonic-gate 		} /* for */
10997c478bd9Sstevel@tonic-gate 	} /* while */
11007c478bd9Sstevel@tonic-gate }  /* func */
1101