xref: /titanic_50/usr/src/cmd/krb5/kwarn/kwarnd_clnt_stubs.c (revision a51287096c163d49f314be2853367563999e083c)
17c478bd9Sstevel@tonic-gate /*
232885d59Sgtb  * CDDL HEADER START
332885d59Sgtb  *
432885d59Sgtb  * The contents of this file are subject to the terms of the
532885d59Sgtb  * Common Development and Distribution License (the "License").
632885d59Sgtb  * You may not use this file except in compliance with the License.
732885d59Sgtb  *
832885d59Sgtb  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
932885d59Sgtb  * or http://www.opensolaris.org/os/licensing.
1032885d59Sgtb  * See the License for the specific language governing permissions
1132885d59Sgtb  * and limitations under the License.
1232885d59Sgtb  *
1332885d59Sgtb  * When distributing Covered Code, include this CDDL HEADER in each
1432885d59Sgtb  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1532885d59Sgtb  * If applicable, add the following below this CDDL HEADER, with the
1632885d59Sgtb  * fields enclosed by brackets "[]" replaced with your own identifying
1732885d59Sgtb  * information: Portions Copyright [yyyy] [name of copyright owner]
1832885d59Sgtb  *
1932885d59Sgtb  * CDDL HEADER END
2032885d59Sgtb  */
2132885d59Sgtb 
2232885d59Sgtb /*
2332885d59Sgtb  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
2432885d59Sgtb  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  *  stub module for kwarnd.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <stdio.h>
327c478bd9Sstevel@tonic-gate #include <stdlib.h>
337c478bd9Sstevel@tonic-gate #include "kwarnd.h"
347c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/devops.h>
387c478bd9Sstevel@tonic-gate #include <sys/open.h>
397c478bd9Sstevel@tonic-gate #include <sys/stat.h>
407c478bd9Sstevel@tonic-gate #include <sys/conf.h>
417c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
427c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
437c478bd9Sstevel@tonic-gate #include <sys/uio.h>
4432885d59Sgtb #include <syslog.h>
457c478bd9Sstevel@tonic-gate 
46*a5128709SShawn Emery extern CLIENT *getkwarnd_handle(void);
47*a5128709SShawn Emery extern void resetkwarnd_handle(void);
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate OM_UINT32
kwarn_add_warning(WARNING_NAME_T warning_name,int cred_exp_time)507c478bd9Sstevel@tonic-gate kwarn_add_warning(WARNING_NAME_T warning_name, int cred_exp_time)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate 	kwarn_add_warning_arg args;
537c478bd9Sstevel@tonic-gate 	kwarn_add_warning_res res;
54*a5128709SShawn Emery 	enum clnt_stat ret;
55*a5128709SShawn Emery 	boolean_t first = TRUE;
56*a5128709SShawn Emery 	CLIENT *clnt;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	/* check the input/output parameters */
597c478bd9Sstevel@tonic-gate 	if (warning_name == NULL || cred_exp_time == 0)
607c478bd9Sstevel@tonic-gate 		return (1);
617c478bd9Sstevel@tonic-gate 
62*a5128709SShawn Emery rebind:
637c478bd9Sstevel@tonic-gate 	/* get the client handle to kwarnd */
647c478bd9Sstevel@tonic-gate 	if ((clnt = getkwarnd_handle()) == NULL) {
6532885d59Sgtb 		/*
6632885d59Sgtb 		 * Let app output if an error occurs but we'll syslog to
6732885d59Sgtb 		 * DEBUG to get error details if needed.
6832885d59Sgtb 		 */
6932885d59Sgtb 		syslog(LOG_DEBUG, "%s",
7032885d59Sgtb 		    clnt_spcreateerror("getkwarnd_handle"));
717c478bd9Sstevel@tonic-gate 		return (1);
727c478bd9Sstevel@tonic-gate 	}
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	/* set the rpc parameters */
757c478bd9Sstevel@tonic-gate 	args.cred_exp_time = cred_exp_time;
767c478bd9Sstevel@tonic-gate 	args.warning_name = warning_name;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	/* call the remote procedure */
797c478bd9Sstevel@tonic-gate 	memset(&res, 0, sizeof (res));
80*a5128709SShawn Emery 	ret = kwarn_add_warning_1(&args, &res, clnt);
81*a5128709SShawn Emery 	if (ret != RPC_SUCCESS) {
82*a5128709SShawn Emery 		/*
83*a5128709SShawn Emery 		 * Could have timed out due to the process restarting for
84*a5128709SShawn Emery 		 * various reasons. Should attempt to rebind in the case
85*a5128709SShawn Emery 		 * process is actually running.
86*a5128709SShawn Emery 		 */
87*a5128709SShawn Emery 		if (ret == RPC_TIMEDOUT && first) {
88*a5128709SShawn Emery 			resetkwarnd_handle();
89*a5128709SShawn Emery 			first = FALSE;
90*a5128709SShawn Emery 			goto rebind;
91*a5128709SShawn Emery 		}
927c478bd9Sstevel@tonic-gate 		return (1);
937c478bd9Sstevel@tonic-gate 	}
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	/* nothing to free */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	return (res.status);
987c478bd9Sstevel@tonic-gate }
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate OM_UINT32
kwarn_del_warning(WARNING_NAME_T warning_name)1017c478bd9Sstevel@tonic-gate kwarn_del_warning(WARNING_NAME_T warning_name)
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate 	kwarn_del_warning_arg args;
1047c478bd9Sstevel@tonic-gate 	kwarn_del_warning_res res;
105*a5128709SShawn Emery 	enum clnt_stat ret;
106*a5128709SShawn Emery 	boolean_t first = TRUE;
107*a5128709SShawn Emery 	CLIENT *clnt;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	/* check the output parameters */
1107c478bd9Sstevel@tonic-gate 	if (warning_name == NULL)
1117c478bd9Sstevel@tonic-gate 		return (1);
1127c478bd9Sstevel@tonic-gate 
113*a5128709SShawn Emery rebind:
1147c478bd9Sstevel@tonic-gate 	/* get the client GSSD handle */
1157c478bd9Sstevel@tonic-gate 	if ((clnt = getkwarnd_handle()) == NULL) {
11632885d59Sgtb 		/*
11732885d59Sgtb 		 * Let app output if an error occurs but we'll syslog to
11832885d59Sgtb 		 * DEBUG to get error details if needed.
11932885d59Sgtb 		 */
12032885d59Sgtb 		syslog(LOG_DEBUG, "%s",
12132885d59Sgtb 		    clnt_spcreateerror("getkwarnd_handle"));
1227c478bd9Sstevel@tonic-gate 		return (1);
1237c478bd9Sstevel@tonic-gate 	}
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	/* set the input parameters */
1267c478bd9Sstevel@tonic-gate 	args.warning_name = warning_name;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	/* call the remote procedure */
1297c478bd9Sstevel@tonic-gate 	memset(&res, 0, sizeof (res));
130*a5128709SShawn Emery 	ret = kwarn_del_warning_1(&args, &res, clnt);
131*a5128709SShawn Emery 	if (ret != RPC_SUCCESS) {
132*a5128709SShawn Emery 		/*
133*a5128709SShawn Emery 		 * Could have timed out due to the process restarting for
134*a5128709SShawn Emery 		 * various reasons. Should attempt to rebind in the case
135*a5128709SShawn Emery 		 * process is actually running.
136*a5128709SShawn Emery 		 */
137*a5128709SShawn Emery 		if (ret == RPC_TIMEDOUT && first) {
138*a5128709SShawn Emery 			resetkwarnd_handle();
139*a5128709SShawn Emery 			first = FALSE;
140*a5128709SShawn Emery 			goto rebind;
141*a5128709SShawn Emery 		}
1427c478bd9Sstevel@tonic-gate 		return (1);
1437c478bd9Sstevel@tonic-gate 	}
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	/* nothing to free */
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	return (res.status);
1487c478bd9Sstevel@tonic-gate }
149