secretkey.c revision 26213
138032Speter/* 2249729Sgshapiro * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 364562Sgshapiro * unrestricted use provided that this legend is included on all tape 438032Speter * media and as a part of the software program in whole or part. Users 538032Speter * may copy or modify Sun RPC without charge, but are not authorized 638032Speter * to license or distribute it to anyone else except as part of a product or 738032Speter * program developed by the user or with the express written consent of 838032Speter * Sun Microsystems, Inc. 938032Speter * 1038032Speter * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 1138032Speter * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 1238032Speter * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 1338032Speter * 1464562Sgshapiro * Sun RPC is provided with no support and without any obligation on the 1590792Sgshapiro * part of Sun Microsystems, Inc. to assist in its use, correction, 16132943Sgshapiro * modification or enhancement. 1790792Sgshapiro * 1890792Sgshapiro * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 1964562Sgshapiro * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 20249729Sgshapiro * OR ANY PART THEREOF. 2164562Sgshapiro * 22157001Sgshapiro * In no event will Sun Microsystems, Inc. be liable for any lost revenue 23132943Sgshapiro * or profits or other special, indirect and consequential damages, even if 24132943Sgshapiro * Sun has been advised of the possibility of such damages. 2590792Sgshapiro * 2690792Sgshapiro * Sun Microsystems, Inc. 2790792Sgshapiro * 2550 Garcia Avenue 2890792Sgshapiro * Mountain View, California 94043 2990792Sgshapiro */ 3064562Sgshapiro#if !defined(lint) && defined(SCCSIDS) 3190792Sgshapirostatic char sccsid[] = "@(#)secretkey.c 1.8 91/03/11 Copyr 1986 Sun Micro"; 3290792Sgshapiro#endif 33244833Sgshapiro 3490792Sgshapiro/* 3538032Speter * secretkey.c 3690792Sgshapiro * Copyright (C) 1986, Sun Microsystems, Inc. 3790792Sgshapiro */ 3838032Speter 3990792Sgshapiro/* 4090792Sgshapiro * Secret key lookup routines 4190792Sgshapiro */ 4290792Sgshapiro#include <stdio.h> 4390792Sgshapiro#include <pwd.h> 4490792Sgshapiro#include <rpc/rpc.h> 45168515Sgshapiro#include <rpc/key_prot.h> 46168515Sgshapiro#include <rpcsvc/yp_prot.h> 47168515Sgshapiro#include <rpcsvc/ypclnt.h> 48168515Sgshapiro#include <string.h> 4990792Sgshapiro 5090792Sgshapiroextern int xdecrypt __P(( char *, char * )); 5190792Sgshapiro 5290792Sgshapiro/* 5390792Sgshapiro * Get somebody's encrypted secret key from the database, using the given 5490792Sgshapiro * passwd to decrypt it. 5590792Sgshapiro */ 5690792Sgshapiroint 5790792Sgshapirogetsecretkey(netname, secretkey, passwd) 5890792Sgshapiro char *netname; 5990792Sgshapiro char *secretkey; 6090792Sgshapiro char *passwd; 6190792Sgshapiro{ 6290792Sgshapiro char lookup[3 * HEXKEYBYTES]; 6390792Sgshapiro char *p; 6490792Sgshapiro 6590792Sgshapiro if (secretkey == NULL) 66132943Sgshapiro return (0); 6790792Sgshapiro if (!getpublicandprivatekey(netname, lookup)) 6890792Sgshapiro return (0); 6990792Sgshapiro p = strchr(lookup, ':'); 7090792Sgshapiro if (p == NULL) { 71132943Sgshapiro return (0); 72132943Sgshapiro } 73132943Sgshapiro p++; 7464562Sgshapiro if (!xdecrypt(p, passwd)) { 7564562Sgshapiro return (0); 7690792Sgshapiro } 77120256Sgshapiro if (memcmp(p, p + HEXKEYBYTES, KEYCHECKSUMSIZE) != 0) { 78120256Sgshapiro secretkey[0] = '\0'; 79120256Sgshapiro return (1); 80120256Sgshapiro } 81120256Sgshapiro p[HEXKEYBYTES] = '\0'; 82120256Sgshapiro (void) strncpy(secretkey, p, HEXKEYBYTES); 83120256Sgshapiro secretkey[HEXKEYBYTES] = '\0'; 84120256Sgshapiro return (1); 85147078Sgshapiro} 86147078Sgshapiro