17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate *
227c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate *
257c478bd9Sstevel@tonic-gate * Copyright (c) 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T
267c478bd9Sstevel@tonic-gate * All Rights Reserved
277c478bd9Sstevel@tonic-gate *
287c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley
297c478bd9Sstevel@tonic-gate * 4.3 BSD under license from the Regents of the University of
307c478bd9Sstevel@tonic-gate * California.
317c478bd9Sstevel@tonic-gate */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
347c478bd9Sstevel@tonic-gate /* from kerbd_handle.c 1.3 92/01/29 SMI */
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate * gssd_handle.c, Interface to gssd
387c478bd9Sstevel@tonic-gate *
397c478bd9Sstevel@tonic-gate */
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate #include <unistd.h>
427c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
437c478bd9Sstevel@tonic-gate #include <rpc/clnt.h>
447c478bd9Sstevel@tonic-gate #include <stdio.h>
457c478bd9Sstevel@tonic-gate #include <string.h>
467c478bd9Sstevel@tonic-gate #include <netconfig.h>
477c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
487c478bd9Sstevel@tonic-gate #include "gssd.h"
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate #ifdef DEBUG
517c478bd9Sstevel@tonic-gate #define dprt(msg) (void) fprintf(stderr, "%s\n", msg);
527c478bd9Sstevel@tonic-gate #else
537c478bd9Sstevel@tonic-gate #define dprt(msg)
547c478bd9Sstevel@tonic-gate #endif /* DEBUG */
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate * Keep the handle cached. This call may be made quite often.
597c478bd9Sstevel@tonic-gate */
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate CLIENT *
getgssd_handle()627c478bd9Sstevel@tonic-gate getgssd_handle()
637c478bd9Sstevel@tonic-gate {
647c478bd9Sstevel@tonic-gate void *localhandle;
657c478bd9Sstevel@tonic-gate struct netconfig *nconf;
667c478bd9Sstevel@tonic-gate struct netconfig *tpconf;
677c478bd9Sstevel@tonic-gate static CLIENT *clnt;
687c478bd9Sstevel@tonic-gate struct timeval wait_time;
697c478bd9Sstevel@tonic-gate struct utsname u;
707c478bd9Sstevel@tonic-gate static char *hostname;
717c478bd9Sstevel@tonic-gate static bool_t first_time = TRUE;
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate #define TOTAL_TIMEOUT 1000 /* total timeout talking to gssd */
747c478bd9Sstevel@tonic-gate #define TOTAL_TRIES 1 /* Number of tries */
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate if (clnt)
777c478bd9Sstevel@tonic-gate return (clnt);
787c478bd9Sstevel@tonic-gate if (!(localhandle = setnetconfig()))
797c478bd9Sstevel@tonic-gate return (NULL);
807c478bd9Sstevel@tonic-gate tpconf = NULL;
817c478bd9Sstevel@tonic-gate if (first_time == TRUE) {
827c478bd9Sstevel@tonic-gate if (uname(&u) == -1)
837c478bd9Sstevel@tonic-gate return ((CLIENT *) NULL);
847c478bd9Sstevel@tonic-gate if ((hostname = strdup(u.nodename)) == (char *)NULL)
857c478bd9Sstevel@tonic-gate return ((CLIENT *) NULL);
867c478bd9Sstevel@tonic-gate first_time = FALSE;
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate while (nconf = getnetconfig(localhandle)) {
897c478bd9Sstevel@tonic-gate if (strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0) {
907c478bd9Sstevel@tonic-gate if (nconf->nc_semantics == NC_TPI_COTS_ORD) {
917c478bd9Sstevel@tonic-gate clnt = clnt_tp_create(hostname,
927c478bd9Sstevel@tonic-gate GSSPROG, GSSVERS, nconf);
937c478bd9Sstevel@tonic-gate if (clnt) {
947c478bd9Sstevel@tonic-gate dprt("got COTS_ORD\n");
957c478bd9Sstevel@tonic-gate break;
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate } else {
987c478bd9Sstevel@tonic-gate tpconf = nconf;
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate if ((clnt == NULL) && (tpconf)) {
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate /* Now, try the connection-oriented loopback transport */
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate clnt = clnt_tp_create(hostname, GSSPROG, GSSVERS, tpconf);
1077c478bd9Sstevel@tonic-gate #ifdef DEBUG
1087c478bd9Sstevel@tonic-gate if (clnt) {
1097c478bd9Sstevel@tonic-gate dprt("got COTS\n");
1107c478bd9Sstevel@tonic-gate }
111*ebd1706eSgtb #endif /* DEBUG */
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate endnetconfig(localhandle);
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate * This bit of code uses an as yet unimplemented argument to
1177c478bd9Sstevel@tonic-gate * clnt_control(). CLSET_SVC_PRIV specifies that the underlying
1187c478bd9Sstevel@tonic-gate * loopback transport should be checked to ensure it is
1197c478bd9Sstevel@tonic-gate * connected to a process running as root. If so, the clnt_control()
1207c478bd9Sstevel@tonic-gate * call returns TRUE. If not, it returns FALSE.
1217c478bd9Sstevel@tonic-gate */
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate #ifdef CLSET_SVC_PRIV
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate if (clnt_control(clnt, CLSET_SVC_PRIV, NULL) != TRUE) {
1267c478bd9Sstevel@tonic-gate clnt_destroy(clnt);
1277c478bd9Sstevel@tonic-gate clnt = NULL;
1287c478bd9Sstevel@tonic-gate return (NULL);
1297c478bd9Sstevel@tonic-gate {
1307c478bd9Sstevel@tonic-gate #endif
1317c478bd9Sstevel@tonic-gate if (clnt == NULL)
1327c478bd9Sstevel@tonic-gate return (NULL);
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate clnt->cl_auth = authsys_create("", getuid(), 0, 0, NULL);
1357c478bd9Sstevel@tonic-gate if (clnt->cl_auth == NULL) {
1367c478bd9Sstevel@tonic-gate clnt_destroy(clnt);
1377c478bd9Sstevel@tonic-gate clnt = NULL;
1387c478bd9Sstevel@tonic-gate return (NULL);
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate wait_time.tv_sec = TOTAL_TIMEOUT/TOTAL_TRIES;
1417c478bd9Sstevel@tonic-gate wait_time.tv_usec = 0;
1427c478bd9Sstevel@tonic-gate (void) clnt_control(clnt, CLSET_RETRY_TIMEOUT, (char *)&wait_time);
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate return (clnt);
1457c478bd9Sstevel@tonic-gate }
146