xref: /illumos-gate/usr/src/lib/libnsl/key/publickey.c (revision a71e11ee)
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
5004388ebScasper  * Common Development and Distribution License (the "License").
6004388ebScasper  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2161961e0fSrobinson 
227c478bd9Sstevel@tonic-gate /*
2336e852a1SRaja Andra  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
26d00075c7SMarcel Telka /*
27d00075c7SMarcel Telka  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
28d00075c7SMarcel Telka  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
317c478bd9Sstevel@tonic-gate /* All Rights Reserved */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
357c478bd9Sstevel@tonic-gate  * under license from the Regents of the University of California.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * publickey.c
407c478bd9Sstevel@tonic-gate  *
417c478bd9Sstevel@tonic-gate  *
427c478bd9Sstevel@tonic-gate  * Public and Private (secret) key lookup routines. These functions
437c478bd9Sstevel@tonic-gate  * are used by the secure RPC auth_des flavor to get the public and
447c478bd9Sstevel@tonic-gate  * private keys for secure RPC principals. Originally designed to
457c478bd9Sstevel@tonic-gate  * talk only to YP, AT&T modified them to talk to files, and now
467c478bd9Sstevel@tonic-gate  * they can also talk to NIS+. The policy for these lookups is now
477c478bd9Sstevel@tonic-gate  * defined in terms of the nameservice switch as follows :
487c478bd9Sstevel@tonic-gate  *	publickey: nis files
497c478bd9Sstevel@tonic-gate  *
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate #include "mt.h"
527c478bd9Sstevel@tonic-gate #include "../rpc/rpc_mt.h"
537c478bd9Sstevel@tonic-gate #include <stdio.h>
547c478bd9Sstevel@tonic-gate #include <stdlib.h>
557c478bd9Sstevel@tonic-gate #include <string.h>
567c478bd9Sstevel@tonic-gate #include <syslog.h>
577c478bd9Sstevel@tonic-gate #include <assert.h>
587c478bd9Sstevel@tonic-gate #include <sys/types.h>
597c478bd9Sstevel@tonic-gate #include <pwd.h>
607c478bd9Sstevel@tonic-gate #include "nsswitch.h"
617c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
627c478bd9Sstevel@tonic-gate #include <rpc/key_prot.h>
637c478bd9Sstevel@tonic-gate #include <rpcsvc/nis.h>
647c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h>
657c478bd9Sstevel@tonic-gate #include <rpcsvc/nis_dhext.h>
667c478bd9Sstevel@tonic-gate #include <thread.h>
677c478bd9Sstevel@tonic-gate #include "../nis/gen/nis_clnt.h"
687c478bd9Sstevel@tonic-gate #include <nss_dbdefs.h>
697c478bd9Sstevel@tonic-gate 
7036e852a1SRaja Andra 
717c478bd9Sstevel@tonic-gate static const char *PKMAP = "publickey.byname";
727c478bd9Sstevel@tonic-gate static const char *PKFILE = "/etc/publickey";
737c478bd9Sstevel@tonic-gate static const char dh_caps_str[] = "DH";
747c478bd9Sstevel@tonic-gate static const char des_caps_str[] = AUTH_DES_AUTH_TYPE;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate static char	*netname2hashname(const char *, char *, int, keylen_t,
777c478bd9Sstevel@tonic-gate 				algtype_t);
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	WORKBUFSIZE 1024
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate extern int xdecrypt();
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate extern int __yp_match_cflookup(char *, char *, char *, int, char **,
847c478bd9Sstevel@tonic-gate 			int *, int *);
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate  * default publickey policy:
897c478bd9Sstevel@tonic-gate  *	publickey: nis [NOTFOUND = return] files
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*	NSW_NOTSUCCESS  NSW_NOTFOUND   NSW_UNAVAIL    NSW_TRYAGAIN */
947c478bd9Sstevel@tonic-gate #define	DEF_ACTION {__NSW_RETURN, __NSW_RETURN, __NSW_CONTINUE, __NSW_CONTINUE}
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate static struct __nsw_lookup lookup_files = {"files", DEF_ACTION, NULL, NULL},
977c478bd9Sstevel@tonic-gate 		lookup_nis = {"nis", DEF_ACTION, NULL, &lookup_files};
987c478bd9Sstevel@tonic-gate static struct __nsw_switchconfig publickey_default =
997c478bd9Sstevel@tonic-gate 			{0, "publickey", 2, &lookup_nis};
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate #ifndef NUL
1027c478bd9Sstevel@tonic-gate #define	NUL '\0'
1037c478bd9Sstevel@tonic-gate #endif
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate extern mutex_t serialize_pkey;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate static int extract_secret();
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * db_root is used for switch backends.
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate static DEFINE_NSS_DB_ROOT(db_root);
1137c478bd9Sstevel@tonic-gate 
114cb5caa98Sdjl /*
115cb5caa98Sdjl  * str2key
116cb5caa98Sdjl  */
117cb5caa98Sdjl /* ARGSUSED */
118cb5caa98Sdjl static int
str2key(const char * instr,int lenstr,void * ent,char * buffer,int buflen)119*a71e11eeSToomas Soome str2key(const char *instr, int lenstr, void *ent, char *buffer, int buflen)
120*a71e11eeSToomas Soome {
121cb5caa98Sdjl 	if (lenstr + 1 > buflen)
122cb5caa98Sdjl 		return (NSS_STR_PARSE_ERANGE);
123cb5caa98Sdjl 	/*
124cb5caa98Sdjl 	 * We copy the input string into the output buffer
125cb5caa98Sdjl 	 */
126cb5caa98Sdjl 	(void) memcpy(buffer, instr, lenstr);
127cb5caa98Sdjl 	buffer[lenstr] = '\0';
128cb5caa98Sdjl 
129cb5caa98Sdjl 	return (NSS_STR_PARSE_SUCCESS);
130cb5caa98Sdjl }
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  * These functions are the "backends" for the switch for public keys. They
1337c478bd9Sstevel@tonic-gate  * get both the public and private keys from each of the supported name
13436e852a1SRaja Andra  * services (nis, files). They are passed the appropriate parameters
1357c478bd9Sstevel@tonic-gate  * and return 0 if unsuccessful with *errp set, or 1 when they got just the
1367c478bd9Sstevel@tonic-gate  * public key and 3 when they got both the public and private keys.
1377c478bd9Sstevel@tonic-gate  *
1387c478bd9Sstevel@tonic-gate  *
1397c478bd9Sstevel@tonic-gate  * getkey_nis()
1407c478bd9Sstevel@tonic-gate  *
1417c478bd9Sstevel@tonic-gate  * Internal implementation of getpublickey() using NIS (aka Yellow Pages,
1427c478bd9Sstevel@tonic-gate  * aka YP).
1437c478bd9Sstevel@tonic-gate  *
1447c478bd9Sstevel@tonic-gate  * NOTE : *** this function returns nsswitch codes and _not_ the
1457c478bd9Sstevel@tonic-gate  * value returned by getpublickey.
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate static int
getkeys_nis(int * errp,char * netname,char * pkey,char * skey,char * passwd)14861961e0fSrobinson getkeys_nis(int *errp, char *netname, char *pkey, char *skey, char *passwd)
1497c478bd9Sstevel@tonic-gate {
1507c478bd9Sstevel@tonic-gate 	char 	*domain;
1517c478bd9Sstevel@tonic-gate 	char	*keyval = NULL;
1527c478bd9Sstevel@tonic-gate 	int	keylen, err, r = 0;
1537c478bd9Sstevel@tonic-gate 	char	*p;
1547c478bd9Sstevel@tonic-gate 	int	len;
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	p = strchr(netname, '@');
15761961e0fSrobinson 	if (!p) {
1587c478bd9Sstevel@tonic-gate 		*errp = __NSW_UNAVAIL;
1597c478bd9Sstevel@tonic-gate 		return (0);
1607c478bd9Sstevel@tonic-gate 	}
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	domain = ++p;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	/*
1667c478bd9Sstevel@tonic-gate 	 * Instead of calling yp_match(), we use __yp_match_cflookup() here
1677c478bd9Sstevel@tonic-gate 	 * which has time-out control for the binding operation to nis
1687c478bd9Sstevel@tonic-gate 	 * servers.
1697c478bd9Sstevel@tonic-gate 	 */
1707c478bd9Sstevel@tonic-gate 	err = __yp_match_cflookup(domain, (char *)PKMAP, netname,
17136e852a1SRaja Andra 	    strlen(netname), &keyval, &keylen, 0);
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	switch (err) {
1747c478bd9Sstevel@tonic-gate 	case YPERR_KEY :
1757c478bd9Sstevel@tonic-gate 		if (keyval)
1767c478bd9Sstevel@tonic-gate 			free(keyval);
1777c478bd9Sstevel@tonic-gate 		*errp = __NSW_NOTFOUND;
1787c478bd9Sstevel@tonic-gate 		return (0);
1797c478bd9Sstevel@tonic-gate 	default :
1807c478bd9Sstevel@tonic-gate 		if (keyval)
1817c478bd9Sstevel@tonic-gate 			free(keyval);
1827c478bd9Sstevel@tonic-gate 		*errp = __NSW_UNAVAIL;
1837c478bd9Sstevel@tonic-gate 		return (0);
1847c478bd9Sstevel@tonic-gate 	case 0:
1857c478bd9Sstevel@tonic-gate 		break;
1867c478bd9Sstevel@tonic-gate 	}
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	p = strchr(keyval, ':');
1897c478bd9Sstevel@tonic-gate 	if (p == NULL) {
1907c478bd9Sstevel@tonic-gate 		free(keyval);
1917c478bd9Sstevel@tonic-gate 		*errp = __NSW_NOTFOUND;
1927c478bd9Sstevel@tonic-gate 		return (0);
1937c478bd9Sstevel@tonic-gate 	}
1947c478bd9Sstevel@tonic-gate 	*p = 0;
1957c478bd9Sstevel@tonic-gate 	if (pkey) {
1967c478bd9Sstevel@tonic-gate 		len = strlen(keyval);
1977c478bd9Sstevel@tonic-gate 		if (len > HEXKEYBYTES) {
1987c478bd9Sstevel@tonic-gate 			free(keyval);
1997c478bd9Sstevel@tonic-gate 			*errp = __NSW_NOTFOUND;
2007c478bd9Sstevel@tonic-gate 			return (0);
2017c478bd9Sstevel@tonic-gate 		}
2027c478bd9Sstevel@tonic-gate 		(void) strcpy(pkey, keyval);
2037c478bd9Sstevel@tonic-gate 	}
2047c478bd9Sstevel@tonic-gate 	r = 1;
2057c478bd9Sstevel@tonic-gate 	p++;
2067c478bd9Sstevel@tonic-gate 	if (skey && extract_secret(p, skey, passwd))
2077c478bd9Sstevel@tonic-gate 		r |= 2;
2087c478bd9Sstevel@tonic-gate 	free(keyval);
2097c478bd9Sstevel@tonic-gate 	*errp = __NSW_SUCCESS;
2107c478bd9Sstevel@tonic-gate 	return (r);
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate /*
2147c478bd9Sstevel@tonic-gate  * getkey_files()
2157c478bd9Sstevel@tonic-gate  *
2167c478bd9Sstevel@tonic-gate  * The files version of getpublickey. This function attempts to
2177c478bd9Sstevel@tonic-gate  * get the publickey from the file PKFILE .
2187c478bd9Sstevel@tonic-gate  *
2197c478bd9Sstevel@tonic-gate  * This function defines the format of the /etc/publickey file to
2207c478bd9Sstevel@tonic-gate  * be :
2217c478bd9Sstevel@tonic-gate  *	netname <whitespace> publickey:privatekey
2227c478bd9Sstevel@tonic-gate  *
2237c478bd9Sstevel@tonic-gate  * NOTE : *** this function returns nsswitch codes and _not_ the
2247c478bd9Sstevel@tonic-gate  * value returned by getpublickey.
2257c478bd9Sstevel@tonic-gate  */
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate static int
getkeys_files(int * errp,char * netname,char * pkey,char * skey,char * passwd)22861961e0fSrobinson getkeys_files(int *errp, char *netname, char *pkey, char *skey, char *passwd)
2297c478bd9Sstevel@tonic-gate {
2307c478bd9Sstevel@tonic-gate 	char *mkey;
2317c478bd9Sstevel@tonic-gate 	char *mval;
2327c478bd9Sstevel@tonic-gate 	char buf[WORKBUFSIZE];
2337c478bd9Sstevel@tonic-gate 	int	r = 0;
2347c478bd9Sstevel@tonic-gate 	char *res;
235004388ebScasper 	FILE *fd;
2367c478bd9Sstevel@tonic-gate 	char *p;
2377c478bd9Sstevel@tonic-gate 	char *lasts;
2387c478bd9Sstevel@tonic-gate 
239004388ebScasper 	fd = fopen(PKFILE, "rF");
240004388ebScasper 	if (fd == NULL) {
2417c478bd9Sstevel@tonic-gate 		*errp = __NSW_UNAVAIL;
2427c478bd9Sstevel@tonic-gate 		return (0);
2437c478bd9Sstevel@tonic-gate 	}
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	/* Search through the file linearly :-( */
246004388ebScasper 	while ((res = fgets(buf, WORKBUFSIZE, fd)) != NULL) {
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 		if ((res[0] == '#') || (res[0] == '\n'))
2497c478bd9Sstevel@tonic-gate 			continue;
2507c478bd9Sstevel@tonic-gate 		else {
2517c478bd9Sstevel@tonic-gate 			mkey = strtok_r(buf, "\t ", &lasts);
2527c478bd9Sstevel@tonic-gate 			if (mkey == NULL) {
2537c478bd9Sstevel@tonic-gate 				syslog(LOG_INFO,
2547c478bd9Sstevel@tonic-gate 				"getpublickey: Bad record in %s for %s",
25536e852a1SRaja Andra 				    PKFILE, netname);
2567c478bd9Sstevel@tonic-gate 				continue;
2577c478bd9Sstevel@tonic-gate 			}
25861961e0fSrobinson 			mval = strtok_r(NULL, " \t#\n", &lasts);
2597c478bd9Sstevel@tonic-gate 			if (mval == NULL) {
2607c478bd9Sstevel@tonic-gate 				syslog(LOG_INFO,
2617c478bd9Sstevel@tonic-gate 				"getpublickey: Bad record in %s for %s",
26236e852a1SRaja Andra 				    PKFILE, netname);
2637c478bd9Sstevel@tonic-gate 				continue;
2647c478bd9Sstevel@tonic-gate 			}
2657c478bd9Sstevel@tonic-gate 			/* NOTE : Case insensitive compare. */
2667c478bd9Sstevel@tonic-gate 			if (strcasecmp(mkey, netname) == 0) {
2677c478bd9Sstevel@tonic-gate 				p = strchr(mval, ':');
2687c478bd9Sstevel@tonic-gate 				if (p == NULL) {
2697c478bd9Sstevel@tonic-gate 					syslog(LOG_INFO,
2707c478bd9Sstevel@tonic-gate 				"getpublickey: Bad record in %s for %s",
27136e852a1SRaja Andra 					    PKFILE, netname);
2727c478bd9Sstevel@tonic-gate 					continue;
2737c478bd9Sstevel@tonic-gate 				}
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 				*p = 0;
2767c478bd9Sstevel@tonic-gate 				if (pkey) {
2777c478bd9Sstevel@tonic-gate 					int len = strlen(mval);
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 					if (len > HEXKEYBYTES) {
2807c478bd9Sstevel@tonic-gate 						syslog(LOG_INFO,
2817c478bd9Sstevel@tonic-gate 				"getpublickey: Bad record in %s for %s",
28236e852a1SRaja Andra 						    PKFILE, netname);
2837c478bd9Sstevel@tonic-gate 						continue;
2847c478bd9Sstevel@tonic-gate 					}
2857c478bd9Sstevel@tonic-gate 					(void) strcpy(pkey, mval);
2867c478bd9Sstevel@tonic-gate 				}
2877c478bd9Sstevel@tonic-gate 				r = 1;
2887c478bd9Sstevel@tonic-gate 				p++;
2897c478bd9Sstevel@tonic-gate 				if (skey && extract_secret(p, skey, passwd))
2907c478bd9Sstevel@tonic-gate 					r |= 2;
291004388ebScasper 				(void) fclose(fd);
2927c478bd9Sstevel@tonic-gate 				*errp = __NSW_SUCCESS;
2937c478bd9Sstevel@tonic-gate 				return (r);
2947c478bd9Sstevel@tonic-gate 			}
2957c478bd9Sstevel@tonic-gate 		}
2967c478bd9Sstevel@tonic-gate 	}
2977c478bd9Sstevel@tonic-gate 
298004388ebScasper 	(void) fclose(fd);
2997c478bd9Sstevel@tonic-gate 	*errp = __NSW_NOTFOUND;
3007c478bd9Sstevel@tonic-gate 	return (0);
3017c478bd9Sstevel@tonic-gate }
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate /*
3047c478bd9Sstevel@tonic-gate  * getpublickey(netname, key)
3057c478bd9Sstevel@tonic-gate  *
3067c478bd9Sstevel@tonic-gate  * This is the actual exported interface for this function.
3077c478bd9Sstevel@tonic-gate  */
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate int
__getpublickey_cached(char * netname,char * pkey,int * from_cache)31061961e0fSrobinson __getpublickey_cached(char *netname, char *pkey, int *from_cache)
3117c478bd9Sstevel@tonic-gate {
3127c478bd9Sstevel@tonic-gate 	return (__getpublickey_cached_g(netname, KEYSIZE, 0, pkey,
31336e852a1SRaja Andra 	    HEXKEYBYTES+1, from_cache));
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate int
getpublickey(const char * netname,char * pkey)31761961e0fSrobinson getpublickey(const char *netname, char *pkey)
3187c478bd9Sstevel@tonic-gate {
3197c478bd9Sstevel@tonic-gate 	return (__getpublickey_cached((char *)netname, pkey, (int *)0));
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate void
__getpublickey_flush(const char * netname)3237c478bd9Sstevel@tonic-gate __getpublickey_flush(const char *netname)
3247c478bd9Sstevel@tonic-gate {
3257c478bd9Sstevel@tonic-gate 	__getpublickey_flush_g(netname, 192, 0);
3267c478bd9Sstevel@tonic-gate }
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate int
getsecretkey(const char * netname,char * skey,const char * passwd)32961961e0fSrobinson getsecretkey(const char *netname, char *skey, const char *passwd)
3307c478bd9Sstevel@tonic-gate {
3317c478bd9Sstevel@tonic-gate 	return (getsecretkey_g(netname, KEYSIZE, 0, skey, HEXKEYBYTES+1,
33236e852a1SRaja Andra 	    passwd));
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate /*
3367c478bd9Sstevel@tonic-gate  *  Routines to cache publickeys.
3377c478bd9Sstevel@tonic-gate  */
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate /*
3417c478bd9Sstevel@tonic-gate  * Generic DH (any size keys) version of extract_secret.
3427c478bd9Sstevel@tonic-gate  */
3437c478bd9Sstevel@tonic-gate static int
extract_secret_g(char * raw,char * private,int prilen,char * passwd,char * netname,keylen_t keylen,algtype_t algtype)3447c478bd9Sstevel@tonic-gate extract_secret_g(
345*a71e11eeSToomas Soome     char	*raw,		/* in  */
346*a71e11eeSToomas Soome     char	*private,	/* out */
347*a71e11eeSToomas Soome     int		prilen,		/* in  */
348*a71e11eeSToomas Soome     char	*passwd,	/* in  */
349*a71e11eeSToomas Soome     char	*netname,	/* in  */
350*a71e11eeSToomas Soome     keylen_t	keylen,		/* in  */
351*a71e11eeSToomas Soome     algtype_t	algtype)	/* in  */
3527c478bd9Sstevel@tonic-gate {
3537c478bd9Sstevel@tonic-gate 	char	*buf = malloc(strlen(raw) + 1); /* private tmp buf */
3547c478bd9Sstevel@tonic-gate 	char	*p;
3557c478bd9Sstevel@tonic-gate 
35661961e0fSrobinson 	if (!buf || !passwd || !raw || !private || !prilen ||
357*a71e11eeSToomas Soome 	    !VALID_KEYALG(keylen, algtype)) {
3587c478bd9Sstevel@tonic-gate 		if (private)
3597c478bd9Sstevel@tonic-gate 			*private = NUL;
3607c478bd9Sstevel@tonic-gate 		if (buf)
3617c478bd9Sstevel@tonic-gate 			free(buf);
3627c478bd9Sstevel@tonic-gate 		return (0);
3637c478bd9Sstevel@tonic-gate 	}
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 	(void) strcpy(buf, raw);
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	/* strip off pesky colon if it exists */
3687c478bd9Sstevel@tonic-gate 	p = strchr(buf, ':');
3697c478bd9Sstevel@tonic-gate 	if (p) {
3707c478bd9Sstevel@tonic-gate 		*p = 0;
3717c478bd9Sstevel@tonic-gate 	}
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	/* raw buf has chksum appended, so let's verify it too */
37461961e0fSrobinson 	if (!xdecrypt_g(buf, keylen, algtype, passwd, netname, TRUE)) {
3757c478bd9Sstevel@tonic-gate 		private[0] = 0;
3767c478bd9Sstevel@tonic-gate 		free(buf);
3777c478bd9Sstevel@tonic-gate 		return (1); /* yes, return 1 even if xdecrypt fails */
3787c478bd9Sstevel@tonic-gate 	}
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 	if (strlen(buf) >= prilen) {
3817c478bd9Sstevel@tonic-gate 		private[0] = 0;
3827c478bd9Sstevel@tonic-gate 		free(buf);
3837c478bd9Sstevel@tonic-gate 		return (0);
3847c478bd9Sstevel@tonic-gate 	}
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	(void) strcpy(private, buf);
3877c478bd9Sstevel@tonic-gate 	free(buf);
3887c478bd9Sstevel@tonic-gate 	return (1);
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate /*
3927c478bd9Sstevel@tonic-gate  * extract_secret()
3937c478bd9Sstevel@tonic-gate  *
3947c478bd9Sstevel@tonic-gate  * This generic function will extract the private key
3957c478bd9Sstevel@tonic-gate  * from a string using the given password. Note that
3967c478bd9Sstevel@tonic-gate  * it uses the DES based function xdecrypt()
3977c478bd9Sstevel@tonic-gate  */
3987c478bd9Sstevel@tonic-gate static int
extract_secret(char * raw,char * private,char * passwd)39961961e0fSrobinson extract_secret(char *raw, char *private, char *passwd)
4007c478bd9Sstevel@tonic-gate {
4017c478bd9Sstevel@tonic-gate 	return (extract_secret_g(raw, private, HEXKEYBYTES+1, passwd,
40236e852a1SRaja Andra 	    NULL, KEYSIZE, 0));
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate /*
4067c478bd9Sstevel@tonic-gate  * getkeys_ldap_g()
4077c478bd9Sstevel@tonic-gate  *
4087c478bd9Sstevel@tonic-gate  * Fetches the key pair from LDAP.  This version handles any size
4097c478bd9Sstevel@tonic-gate  * DH keys.
4107c478bd9Sstevel@tonic-gate  */
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate void
_nss_initf_publickey(nss_db_params_t * p)4137c478bd9Sstevel@tonic-gate _nss_initf_publickey(nss_db_params_t *p)
4147c478bd9Sstevel@tonic-gate {
4157c478bd9Sstevel@tonic-gate 	p->name = NSS_DBNAM_PUBLICKEY;
4167c478bd9Sstevel@tonic-gate 	p->default_config = NSS_DEFCONF_PUBLICKEY;
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate static int
getkeys_ldap_g(int * err,char * netname,char * pkey,int pkeylen,char * skey,int skeylen,char * passwd,keylen_t keylen,algtype_t algtype)4217c478bd9Sstevel@tonic-gate getkeys_ldap_g(
4227c478bd9Sstevel@tonic-gate 	int		*err,		/* in  */
4237c478bd9Sstevel@tonic-gate 	char		*netname,	/* in  */
4247c478bd9Sstevel@tonic-gate 	char		*pkey,		/* out */
4257c478bd9Sstevel@tonic-gate 	int		pkeylen,	/* in  */
4267c478bd9Sstevel@tonic-gate 	char		*skey,		/* out */
4277c478bd9Sstevel@tonic-gate 	int		skeylen,	/* in  */
4287c478bd9Sstevel@tonic-gate 	char		*passwd,	/* in  */
4297c478bd9Sstevel@tonic-gate 	keylen_t	keylen,		/* in  */
4307c478bd9Sstevel@tonic-gate 	algtype_t	algtype)	/* in  */
4317c478bd9Sstevel@tonic-gate {
4327c478bd9Sstevel@tonic-gate 	int		r = 0;
4337c478bd9Sstevel@tonic-gate 	char		*p;
4347c478bd9Sstevel@tonic-gate 	char		keytypename[NIS_MAXNAMELEN+1];
4357c478bd9Sstevel@tonic-gate 	int		len;
4367c478bd9Sstevel@tonic-gate 	const bool_t	classic_des = AUTH_DES_KEY(keylen, algtype);
4377c478bd9Sstevel@tonic-gate 	int		rc = 0;
4387c478bd9Sstevel@tonic-gate 	nss_XbyY_args_t arg;
4397c478bd9Sstevel@tonic-gate 	nss_XbyY_buf_t	*buf = NULL;
4407c478bd9Sstevel@tonic-gate 	char		*keyval;
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate 	NSS_XbyY_ALLOC(&buf, 0, NSS_BUFLEN_PUBLICKEY);
4437c478bd9Sstevel@tonic-gate 
444cb5caa98Sdjl 	NSS_XbyY_INIT(&arg, buf->result, buf->buffer, buf->buflen, str2key);
4457c478bd9Sstevel@tonic-gate 	arg.key.pkey.name = netname;
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate 	/*
4487c478bd9Sstevel@tonic-gate 	 * LDAP stores the public and secret key info in entries using
4497c478bd9Sstevel@tonic-gate 	 * nisKeyObject objectclass.  Each key is tagged with the
4507c478bd9Sstevel@tonic-gate 	 * keytype, keylength, and algorithm.  The tag has the following
4517c478bd9Sstevel@tonic-gate 	 * format: {<keytype><keylength>-<algorithm>}.  For example,
4527c478bd9Sstevel@tonic-gate 	 * {DH192-0}.
4537c478bd9Sstevel@tonic-gate 	 */
4547c478bd9Sstevel@tonic-gate 	if (classic_des)
4557c478bd9Sstevel@tonic-gate 		(void) strcpy(keytypename, "{DH192-0}");
4567c478bd9Sstevel@tonic-gate 	else
4577c478bd9Sstevel@tonic-gate 		(void) sprintf(keytypename, "{%s%d-%d}",
45836e852a1SRaja Andra 		    dh_caps_str, keylen, algtype);
4597c478bd9Sstevel@tonic-gate 	arg.key.pkey.keytype = keytypename;
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	if (nss_search(&db_root, _nss_initf_publickey, NSS_DBOP_KEYS_BYNAME,
46236e852a1SRaja Andra 	    &arg) != NSS_SUCCESS) {
4637c478bd9Sstevel@tonic-gate 		NSS_XbyY_FREE(&buf);
4647c478bd9Sstevel@tonic-gate 		*err = __NSW_NOTFOUND;
4657c478bd9Sstevel@tonic-gate 		return (0);
4667c478bd9Sstevel@tonic-gate 	}
4677c478bd9Sstevel@tonic-gate 	keyval = buf->buffer;
4687c478bd9Sstevel@tonic-gate 	p = strchr(keyval, ':');
4697c478bd9Sstevel@tonic-gate 	if (p == NULL) {
4707c478bd9Sstevel@tonic-gate 		NSS_XbyY_FREE(&buf);
4717c478bd9Sstevel@tonic-gate 		*err = __NSW_NOTFOUND;
4727c478bd9Sstevel@tonic-gate 		return (0);
4737c478bd9Sstevel@tonic-gate 	}
4747c478bd9Sstevel@tonic-gate 	*p = 0;
4757c478bd9Sstevel@tonic-gate 	if (pkey) {
4767c478bd9Sstevel@tonic-gate 		len = strlen(keyval);
4777c478bd9Sstevel@tonic-gate 		if (len > HEXKEYBYTES) {
4787c478bd9Sstevel@tonic-gate 			NSS_XbyY_FREE(&buf);
4797c478bd9Sstevel@tonic-gate 			*err = __NSW_NOTFOUND;
4807c478bd9Sstevel@tonic-gate 			return (0);
4817c478bd9Sstevel@tonic-gate 		}
4827c478bd9Sstevel@tonic-gate 		(void) strcpy(pkey, keyval);
4837c478bd9Sstevel@tonic-gate 	}
4847c478bd9Sstevel@tonic-gate 	r = 1;
4857c478bd9Sstevel@tonic-gate 	p++;
4867c478bd9Sstevel@tonic-gate 	if (skey && extract_secret(p, skey, passwd))
4877c478bd9Sstevel@tonic-gate 		r |= 2;
4887c478bd9Sstevel@tonic-gate 	NSS_XbyY_FREE(&buf);
4897c478bd9Sstevel@tonic-gate 	*err = __NSW_SUCCESS;
4907c478bd9Sstevel@tonic-gate 	return (r);
4917c478bd9Sstevel@tonic-gate }
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate /*
4957c478bd9Sstevel@tonic-gate  * Convert a netname to a name we will hash on.  For classic_des,
4967c478bd9Sstevel@tonic-gate  * just copy netname as is.  But for new and improved ("now in
4977c478bd9Sstevel@tonic-gate  * new longer sizes!") DHEXT, add a ":keylen-algtype" suffix to hash on.
4987c478bd9Sstevel@tonic-gate  *
4997c478bd9Sstevel@tonic-gate  * Returns the hashname string on success or NULL on failure.
5007c478bd9Sstevel@tonic-gate  */
5017c478bd9Sstevel@tonic-gate static char *
netname2hashname(const char * netname,char * hashname,int bufsiz,keylen_t keylen,algtype_t algtype)5027c478bd9Sstevel@tonic-gate netname2hashname(
5037c478bd9Sstevel@tonic-gate 	const char *netname,
5047c478bd9Sstevel@tonic-gate 	char *hashname,
5057c478bd9Sstevel@tonic-gate 	int bufsiz,
5067c478bd9Sstevel@tonic-gate 	keylen_t keylen,
5077c478bd9Sstevel@tonic-gate 	algtype_t algtype)
5087c478bd9Sstevel@tonic-gate {
5097c478bd9Sstevel@tonic-gate 	const bool_t classic_des = AUTH_DES_KEY(keylen, algtype);
5107c478bd9Sstevel@tonic-gate 
51161961e0fSrobinson 	if (!netname || !hashname || !bufsiz)
5127c478bd9Sstevel@tonic-gate 		return (NULL);
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 	if (classic_des) {
5157c478bd9Sstevel@tonic-gate 		if (bufsiz > strlen(netname))
5167c478bd9Sstevel@tonic-gate 			(void) strcpy(hashname, netname);
51761961e0fSrobinson 		else
5187c478bd9Sstevel@tonic-gate 			return (NULL);
5197c478bd9Sstevel@tonic-gate 	} else {
5207c478bd9Sstevel@tonic-gate 		char tmp[128];
5217c478bd9Sstevel@tonic-gate 		(void) sprintf(tmp, ":%d-%d", keylen, algtype);
5227c478bd9Sstevel@tonic-gate 		if (bufsiz > (strlen(netname) + strlen(tmp)))
5237c478bd9Sstevel@tonic-gate 			(void) sprintf(hashname, "%s%s", netname, tmp);
52461961e0fSrobinson 		else
5257c478bd9Sstevel@tonic-gate 			return (NULL);
5267c478bd9Sstevel@tonic-gate 	}
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate 	return (hashname);
5297c478bd9Sstevel@tonic-gate }
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate /*
5327c478bd9Sstevel@tonic-gate  * Flush netname's publickey of the given key length and algorithm type.
5337c478bd9Sstevel@tonic-gate  */
5347c478bd9Sstevel@tonic-gate void
__getpublickey_flush_g(const char * netname,keylen_t keylen,algtype_t algtype)5357c478bd9Sstevel@tonic-gate __getpublickey_flush_g(const char *netname, keylen_t keylen, algtype_t algtype)
5367c478bd9Sstevel@tonic-gate {
537*a71e11eeSToomas Soome 	char	hashname[MAXNETNAMELEN+1];
538*a71e11eeSToomas Soome 
539*a71e11eeSToomas Soome 	(void) netname2hashname(netname, hashname, MAXNETNAMELEN, keylen,
540*a71e11eeSToomas Soome 	    algtype);
5417c478bd9Sstevel@tonic-gate }
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate /*
5447c478bd9Sstevel@tonic-gate  * Generic DH (any size keys) version of __getpublickey_cached.
5457c478bd9Sstevel@tonic-gate  */
5467c478bd9Sstevel@tonic-gate int
__getpublickey_cached_g(const char netname[],keylen_t keylen,algtype_t algtype,char * pkey,size_t pkeylen,int * from_cache)5477c478bd9Sstevel@tonic-gate __getpublickey_cached_g(const char netname[],	/* in  */
548*a71e11eeSToomas Soome     keylen_t keylen,	/* in  */
549*a71e11eeSToomas Soome     algtype_t algtype,	/* in  */
550*a71e11eeSToomas Soome     char *pkey,		/* out */
551*a71e11eeSToomas Soome     size_t pkeylen,	/* in  */
552*a71e11eeSToomas Soome     int *from_cache)	/* in/out  */
5537c478bd9Sstevel@tonic-gate {
5547c478bd9Sstevel@tonic-gate 	int	needfree = 1, res, err;
5557c478bd9Sstevel@tonic-gate 	struct __nsw_switchconfig *conf;
5567c478bd9Sstevel@tonic-gate 	struct __nsw_lookup *look;
5577c478bd9Sstevel@tonic-gate 	enum __nsw_parse_err perr;
5587c478bd9Sstevel@tonic-gate 	const bool_t classic_des = AUTH_DES_KEY(keylen, algtype);
5597c478bd9Sstevel@tonic-gate 	int	retry_cache = 0;
5607c478bd9Sstevel@tonic-gate 
56161961e0fSrobinson 	if (!netname || !pkey)
5627c478bd9Sstevel@tonic-gate 		return (0);
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate 	conf = __nsw_getconfig("publickey", &perr);
56561961e0fSrobinson 	if (!conf) {
5667c478bd9Sstevel@tonic-gate 		conf = &publickey_default;
5677c478bd9Sstevel@tonic-gate 		needfree = 0;
5687c478bd9Sstevel@tonic-gate 	}
5697c478bd9Sstevel@tonic-gate 	for (look = conf->lookups; look; look = look->next) {
57036e852a1SRaja Andra 		if (strcmp(look->service_name, "ldap") == 0) {
5717c478bd9Sstevel@tonic-gate 			res = getkeys_ldap_g(&err, (char *)netname,
57236e852a1SRaja Andra 			    pkey, pkeylen, NULL, 0, NULL,
57336e852a1SRaja Andra 			    keylen, algtype);
5747c478bd9Sstevel@tonic-gate 		/* long DH keys will not be in nis or files */
5757c478bd9Sstevel@tonic-gate 		} else if (classic_des &&
57636e852a1SRaja Andra 		    strcmp(look->service_name, "nis") == 0)
5777c478bd9Sstevel@tonic-gate 			res = getkeys_nis(&err, (char *)netname, pkey,
57836e852a1SRaja Andra 			    NULL, NULL);
5797c478bd9Sstevel@tonic-gate 		else if (classic_des &&
58036e852a1SRaja Andra 		    strcmp(look->service_name, "files") == 0)
5817c478bd9Sstevel@tonic-gate 			res = getkeys_files(&err, (char *)netname, pkey,
58236e852a1SRaja Andra 			    NULL, NULL);
5837c478bd9Sstevel@tonic-gate 		else {
5847c478bd9Sstevel@tonic-gate 			syslog(LOG_INFO, "Unknown publickey nameservice '%s'",
58536e852a1SRaja Andra 			    look->service_name);
5867c478bd9Sstevel@tonic-gate 			err = __NSW_UNAVAIL;
587d00075c7SMarcel Telka 			res = 0;
5887c478bd9Sstevel@tonic-gate 		}
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate 		switch (look->actions[err]) {
5917c478bd9Sstevel@tonic-gate 		case __NSW_CONTINUE :
5927c478bd9Sstevel@tonic-gate 			continue;
5937c478bd9Sstevel@tonic-gate 		case __NSW_RETURN :
5947c478bd9Sstevel@tonic-gate 			if (needfree)
5957c478bd9Sstevel@tonic-gate 				__nsw_freeconfig(conf);
5967c478bd9Sstevel@tonic-gate 			return ((res & 1) != 0);
5977c478bd9Sstevel@tonic-gate 		default :
5987c478bd9Sstevel@tonic-gate 			syslog(LOG_INFO, "Unknown action for nameservice %s",
59936e852a1SRaja Andra 			    look->service_name);
6007c478bd9Sstevel@tonic-gate 		}
6017c478bd9Sstevel@tonic-gate 	}
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate 	if (needfree)
6047c478bd9Sstevel@tonic-gate 		__nsw_freeconfig(conf);
6057c478bd9Sstevel@tonic-gate 	return (0);
6067c478bd9Sstevel@tonic-gate }
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate /*
6117c478bd9Sstevel@tonic-gate  * Generic (all sizes) DH version of getpublickey.
6127c478bd9Sstevel@tonic-gate  */
6137c478bd9Sstevel@tonic-gate int
getpublickey_g(const char * netname,int keylen,int algtype,char * pkey,size_t pkeylen)6147c478bd9Sstevel@tonic-gate getpublickey_g(
6157c478bd9Sstevel@tonic-gate 	const char *netname,	/* in  */
6167c478bd9Sstevel@tonic-gate 	int keylen,		/* in  */
6177c478bd9Sstevel@tonic-gate 	int algtype,		/* in  */
6187c478bd9Sstevel@tonic-gate 	char *pkey,		/* out  */
6197c478bd9Sstevel@tonic-gate 	size_t pkeylen)		/* in  */
6207c478bd9Sstevel@tonic-gate {
6217c478bd9Sstevel@tonic-gate 	return (__getpublickey_cached_g(netname, keylen, algtype, pkey,
62236e852a1SRaja Andra 	    pkeylen, (int *)0));
6237c478bd9Sstevel@tonic-gate }
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate /*
6267c478bd9Sstevel@tonic-gate  * Generic (all sizes) DH version of getsecretkey_g.
6277c478bd9Sstevel@tonic-gate  */
6287c478bd9Sstevel@tonic-gate int
getsecretkey_g(const char * netname,keylen_t keylen,algtype_t algtype,char * skey,size_t skeylen,const char * passwd)6297c478bd9Sstevel@tonic-gate getsecretkey_g(
6307c478bd9Sstevel@tonic-gate 	const char	*netname,	/* in  */
6317c478bd9Sstevel@tonic-gate 	keylen_t	keylen,		/* in  */
6327c478bd9Sstevel@tonic-gate 	algtype_t	algtype,	/* in  */
6337c478bd9Sstevel@tonic-gate 	char		*skey,		/* out */
6347c478bd9Sstevel@tonic-gate 	size_t		skeylen,	/* in  */
6357c478bd9Sstevel@tonic-gate 	const char	*passwd)	/* in  */
6367c478bd9Sstevel@tonic-gate {
6377c478bd9Sstevel@tonic-gate 	int	needfree = 1, res, err;
6387c478bd9Sstevel@tonic-gate 	struct __nsw_switchconfig *conf;
6397c478bd9Sstevel@tonic-gate 	struct __nsw_lookup *look;
6407c478bd9Sstevel@tonic-gate 	enum __nsw_parse_err perr;
6417c478bd9Sstevel@tonic-gate 	const bool_t classic_des = AUTH_DES_KEY(keylen, algtype);
6427c478bd9Sstevel@tonic-gate 
64361961e0fSrobinson 	if (!netname || !skey || !skeylen)
6447c478bd9Sstevel@tonic-gate 		return (0);
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate 	conf = __nsw_getconfig("publickey", &perr);
6477c478bd9Sstevel@tonic-gate 
64861961e0fSrobinson 	if (!conf) {
6497c478bd9Sstevel@tonic-gate 		conf = &publickey_default;
6507c478bd9Sstevel@tonic-gate 		needfree = 0;
6517c478bd9Sstevel@tonic-gate 	}
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate 	for (look = conf->lookups; look; look = look->next) {
65436e852a1SRaja Andra 		if (strcmp(look->service_name, "ldap") == 0)
6557c478bd9Sstevel@tonic-gate 			res = getkeys_ldap_g(&err, (char *)netname,
65636e852a1SRaja Andra 			    NULL, 0, skey, skeylen,
65736e852a1SRaja Andra 			    (char *)passwd, keylen, algtype);
6587c478bd9Sstevel@tonic-gate 		/* long DH keys will not be in nis or files */
6597c478bd9Sstevel@tonic-gate 		else if (classic_des && strcmp(look->service_name, "nis") == 0)
6607c478bd9Sstevel@tonic-gate 			res = getkeys_nis(&err, (char *)netname,
66136e852a1SRaja Andra 			    NULL, skey, (char *)passwd);
6627c478bd9Sstevel@tonic-gate 		else if (classic_des &&
66336e852a1SRaja Andra 		    strcmp(look->service_name, "files") == 0)
6647c478bd9Sstevel@tonic-gate 			res = getkeys_files(&err, (char *)netname,
66536e852a1SRaja Andra 			    NULL, skey, (char *)passwd);
6667c478bd9Sstevel@tonic-gate 		else {
6677c478bd9Sstevel@tonic-gate 			syslog(LOG_INFO, "Unknown publickey nameservice '%s'",
66836e852a1SRaja Andra 			    look->service_name);
6697c478bd9Sstevel@tonic-gate 			err = __NSW_UNAVAIL;
670d00075c7SMarcel Telka 			res = 0;
6717c478bd9Sstevel@tonic-gate 		}
6727c478bd9Sstevel@tonic-gate 		switch (look->actions[err]) {
6737c478bd9Sstevel@tonic-gate 		case __NSW_CONTINUE :
6747c478bd9Sstevel@tonic-gate 			continue;
6757c478bd9Sstevel@tonic-gate 		case __NSW_RETURN :
6767c478bd9Sstevel@tonic-gate 			if (needfree)
6777c478bd9Sstevel@tonic-gate 				__nsw_freeconfig(conf);
6787c478bd9Sstevel@tonic-gate 			return ((res & 2) != 0);
6797c478bd9Sstevel@tonic-gate 		default :
6807c478bd9Sstevel@tonic-gate 			syslog(LOG_INFO, "Unknown action for nameservice %s",
68136e852a1SRaja Andra 			    look->service_name);
6827c478bd9Sstevel@tonic-gate 		}
6837c478bd9Sstevel@tonic-gate 	}
6847c478bd9Sstevel@tonic-gate 	if (needfree)
6857c478bd9Sstevel@tonic-gate 		__nsw_freeconfig(conf);
6867c478bd9Sstevel@tonic-gate 	return (0);
6877c478bd9Sstevel@tonic-gate }
688