secretkey.c revision 26213
126213Swpaul/* 226213Swpaul * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 326213Swpaul * unrestricted use provided that this legend is included on all tape 426213Swpaul * media and as a part of the software program in whole or part. Users 526213Swpaul * may copy or modify Sun RPC without charge, but are not authorized 626213Swpaul * to license or distribute it to anyone else except as part of a product or 726213Swpaul * program developed by the user or with the express written consent of 826213Swpaul * Sun Microsystems, Inc. 926213Swpaul * 1026213Swpaul * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 1126213Swpaul * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 1226213Swpaul * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 1326213Swpaul * 1426213Swpaul * Sun RPC is provided with no support and without any obligation on the 1526213Swpaul * part of Sun Microsystems, Inc. to assist in its use, correction, 1626213Swpaul * modification or enhancement. 1726213Swpaul * 1826213Swpaul * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 1926213Swpaul * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 2026213Swpaul * OR ANY PART THEREOF. 2126213Swpaul * 2226213Swpaul * In no event will Sun Microsystems, Inc. be liable for any lost revenue 2326213Swpaul * or profits or other special, indirect and consequential damages, even if 2426213Swpaul * Sun has been advised of the possibility of such damages. 2526213Swpaul * 2626213Swpaul * Sun Microsystems, Inc. 2726213Swpaul * 2550 Garcia Avenue 2826213Swpaul * Mountain View, California 94043 2926213Swpaul */ 3026213Swpaul#if !defined(lint) && defined(SCCSIDS) 3126213Swpaulstatic char sccsid[] = "@(#)secretkey.c 1.8 91/03/11 Copyr 1986 Sun Micro"; 3226213Swpaul#endif 3326213Swpaul 3426213Swpaul/* 3526213Swpaul * secretkey.c 3626213Swpaul * Copyright (C) 1986, Sun Microsystems, Inc. 3726213Swpaul */ 3826213Swpaul 3926213Swpaul/* 4026213Swpaul * Secret key lookup routines 4126213Swpaul */ 4226213Swpaul#include <stdio.h> 4326213Swpaul#include <pwd.h> 4426213Swpaul#include <rpc/rpc.h> 4526213Swpaul#include <rpc/key_prot.h> 4626213Swpaul#include <rpcsvc/yp_prot.h> 4726213Swpaul#include <rpcsvc/ypclnt.h> 4826213Swpaul#include <string.h> 4926213Swpaul 5026213Swpaulextern int xdecrypt __P(( char *, char * )); 5126213Swpaul 5226213Swpaul/* 5326213Swpaul * Get somebody's encrypted secret key from the database, using the given 5426213Swpaul * passwd to decrypt it. 5526213Swpaul */ 5626213Swpaulint 5726213Swpaulgetsecretkey(netname, secretkey, passwd) 5826213Swpaul char *netname; 5926213Swpaul char *secretkey; 6026213Swpaul char *passwd; 6126213Swpaul{ 6226213Swpaul char lookup[3 * HEXKEYBYTES]; 6326213Swpaul char *p; 6426213Swpaul 6526213Swpaul if (secretkey == NULL) 6626213Swpaul return (0); 6726213Swpaul if (!getpublicandprivatekey(netname, lookup)) 6826213Swpaul return (0); 6926213Swpaul p = strchr(lookup, ':'); 7026213Swpaul if (p == NULL) { 7126213Swpaul return (0); 7226213Swpaul } 7326213Swpaul p++; 7426213Swpaul if (!xdecrypt(p, passwd)) { 7526213Swpaul return (0); 7626213Swpaul } 7726213Swpaul if (memcmp(p, p + HEXKEYBYTES, KEYCHECKSUMSIZE) != 0) { 7826213Swpaul secretkey[0] = '\0'; 7926213Swpaul return (1); 8026213Swpaul } 8126213Swpaul p[HEXKEYBYTES] = '\0'; 8226213Swpaul (void) strncpy(secretkey, p, HEXKEYBYTES); 8326213Swpaul secretkey[HEXKEYBYTES] = '\0'; 8426213Swpaul return (1); 8526213Swpaul} 86