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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* from kerbd_handle.c 1.3 92/01/29 SMI */
30 * kwarnd_handle.c, Interface to kwarnd
39 #include <netconfig.h>
40 #include <sys/utsname.h>
52 * Keep the handle cached. This call may be made quite often.
56 getkwarnd_handle(void)
59 struct netconfig
*nconf
;
60 struct netconfig
*tpconf
;
61 struct timeval wait_time
;
63 static char *hostname
;
64 static bool_t first_time
= TRUE
;
67 * Total timeout (in seconds) talking to kwarnd.
69 #define TOTAL_TIMEOUT 5
73 if (!(localhandle
= setnetconfig()))
76 if (first_time
== TRUE
) {
77 if (uname(&u
) == -1) {
78 (void) endnetconfig(localhandle
);
79 return ((CLIENT
*)NULL
);
81 if ((hostname
= strdup(u
.nodename
)) == NULL
) {
82 (void) endnetconfig(localhandle
);
83 return ((CLIENT
*)NULL
);
87 while (nconf
= getnetconfig(localhandle
)) {
88 if (strcmp(nconf
->nc_protofmly
, NC_LOOPBACK
) == 0) {
89 if (nconf
->nc_semantics
== NC_TPI_COTS_ORD
) {
90 kwarn_clnt
= clnt_tp_create(hostname
,
91 KWARNPROG
, KWARNVERS
, nconf
);
93 dprt("got COTS_ORD\n");
101 if ((kwarn_clnt
== NULL
) && (tpconf
)) {
103 /* Now, try the connection-oriented loopback transport */
105 kwarn_clnt
= clnt_tp_create(hostname
, KWARNPROG
, KWARNVERS
,
113 (void) endnetconfig(localhandle
);
116 * This bit of code uses an as yet unimplemented argument to
117 * clnt_control(). CLSET_SVC_PRIV specifies that the underlying
118 * loopback transport should be checked to ensure it is
119 * connected to a process running as root. If so, the clnt_control()
120 * call returns TRUE. If not, it returns FALSE.
123 #ifdef CLSET_SVC_PRIV
125 if (clnt_control(kwarn_clnt
, CLSET_SVC_PRIV
, NULL
) != TRUE
) {
126 clnt_destroy(kwarn_clnt
);
131 if (kwarn_clnt
== NULL
)
134 kwarn_clnt
->cl_auth
= authsys_create("", getuid(), 0, 0, NULL
);
135 if (kwarn_clnt
->cl_auth
== NULL
) {
136 clnt_destroy(kwarn_clnt
);
140 wait_time
.tv_sec
= TOTAL_TIMEOUT
;
141 wait_time
.tv_usec
= 0;
142 (void) clnt_control(kwarn_clnt
, CLSET_TIMEOUT
, (char *)&wait_time
);
148 resetkwarnd_handle(void)
150 auth_destroy(kwarn_clnt
->cl_auth
);
151 clnt_destroy(kwarn_clnt
);