xref: /illumos-gate/usr/src/cmd/krb5/kwarn/kwarnd_clnt_stubs.c (revision 3ce5372277f4657ad0e52d36c979527c4ca22de2)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  *  stub module for kwarnd.
29  */
30 
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include "kwarnd.h"
34 #include <rpc/rpc.h>
35 
36 #include <sys/types.h>
37 #include <sys/devops.h>
38 #include <sys/open.h>
39 #include <sys/stat.h>
40 #include <sys/conf.h>
41 #include <sys/ddi.h>
42 #include <sys/sunddi.h>
43 #include <sys/uio.h>
44 #include <syslog.h>
45 
46 extern CLIENT *getkwarnd_handle(void);
47 extern void resetkwarnd_handle(void);
48 
49 OM_UINT32
50 kwarn_add_warning(WARNING_NAME_T warning_name, int cred_exp_time)
51 {
52 	kwarn_add_warning_arg args;
53 	kwarn_add_warning_res res;
54 	enum clnt_stat ret;
55 	boolean_t first = TRUE;
56 	CLIENT *clnt;
57 
58 	/* check the input/output parameters */
59 	if (warning_name == NULL || cred_exp_time == 0)
60 		return (1);
61 
62 rebind:
63 	/* get the client handle to kwarnd */
64 	if ((clnt = getkwarnd_handle()) == NULL) {
65 		/*
66 		 * Let app output if an error occurs but we'll syslog to
67 		 * DEBUG to get error details if needed.
68 		 */
69 		syslog(LOG_DEBUG, "%s",
70 		    clnt_spcreateerror("getkwarnd_handle"));
71 		return (1);
72 	}
73 
74 	/* set the rpc parameters */
75 	args.cred_exp_time = cred_exp_time;
76 	args.warning_name = warning_name;
77 
78 	/* call the remote procedure */
79 	memset(&res, 0, sizeof (res));
80 	ret = kwarn_add_warning_1(&args, &res, clnt);
81 	if (ret != RPC_SUCCESS) {
82 		/*
83 		 * Could have timed out due to the process restarting for
84 		 * various reasons. Should attempt to rebind in the case
85 		 * process is actually running.
86 		 */
87 		if (ret == RPC_TIMEDOUT && first) {
88 			resetkwarnd_handle();
89 			first = FALSE;
90 			goto rebind;
91 		}
92 		return (1);
93 	}
94 
95 	/* nothing to free */
96 
97 	return (res.status);
98 }
99 
100 OM_UINT32
101 kwarn_del_warning(WARNING_NAME_T warning_name)
102 {
103 	kwarn_del_warning_arg args;
104 	kwarn_del_warning_res res;
105 	enum clnt_stat ret;
106 	boolean_t first = TRUE;
107 	CLIENT *clnt;
108 
109 	/* check the output parameters */
110 	if (warning_name == NULL)
111 		return (1);
112 
113 rebind:
114 	/* get the client GSSD handle */
115 	if ((clnt = getkwarnd_handle()) == NULL) {
116 		/*
117 		 * Let app output if an error occurs but we'll syslog to
118 		 * DEBUG to get error details if needed.
119 		 */
120 		syslog(LOG_DEBUG, "%s",
121 		    clnt_spcreateerror("getkwarnd_handle"));
122 		return (1);
123 	}
124 
125 	/* set the input parameters */
126 	args.warning_name = warning_name;
127 
128 	/* call the remote procedure */
129 	memset(&res, 0, sizeof (res));
130 	ret = kwarn_del_warning_1(&args, &res, clnt);
131 	if (ret != RPC_SUCCESS) {
132 		/*
133 		 * Could have timed out due to the process restarting for
134 		 * various reasons. Should attempt to rebind in the case
135 		 * process is actually running.
136 		 */
137 		if (ret == RPC_TIMEDOUT && first) {
138 			resetkwarnd_handle();
139 			first = FALSE;
140 			goto rebind;
141 		}
142 		return (1);
143 	}
144 
145 	/* nothing to free */
146 
147 	return (res.status);
148 }
149