secretkey.c revision 92917
1210284Sjmallett/* 2232812Sjmallett * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3215990Sjmallett * unrestricted use provided that this legend is included on all tape 4210284Sjmallett * media and as a part of the software program in whole or part. Users 5210284Sjmallett * may copy or modify Sun RPC without charge, but are not authorized 6215990Sjmallett * to license or distribute it to anyone else except as part of a product or 7215990Sjmallett * program developed by the user or with the express written consent of 8215990Sjmallett * Sun Microsystems, Inc. 9210284Sjmallett * 10215990Sjmallett * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 11215990Sjmallett * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 12210284Sjmallett * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 13215990Sjmallett * 14215990Sjmallett * Sun RPC is provided with no support and without any obligation on the 15215990Sjmallett * part of Sun Microsystems, Inc. to assist in its use, correction, 16215990Sjmallett * modification or enhancement. 17215990Sjmallett * 18232812Sjmallett * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 19215990Sjmallett * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 20215990Sjmallett * OR ANY PART THEREOF. 21215990Sjmallett * 22215990Sjmallett * In no event will Sun Microsystems, Inc. be liable for any lost revenue 23215990Sjmallett * or profits or other special, indirect and consequential damages, even if 24215990Sjmallett * Sun has been advised of the possibility of such damages. 25215990Sjmallett * 26215990Sjmallett * Sun Microsystems, Inc. 27215990Sjmallett * 2550 Garcia Avenue 28215990Sjmallett * Mountain View, California 94043 29232812Sjmallett */ 30215990Sjmallett 31215990Sjmallett#include <sys/cdefs.h> 32215990Sjmallett__FBSDID("$FreeBSD: head/lib/librpcsvc/secretkey.c 92917 2002-03-21 23:54:04Z obrien $"); 33215990Sjmallett 34215990Sjmallett#if !defined(lint) && defined(SCCSIDS) 35215990Sjmallettstatic char sccsid[] = "@(#)secretkey.c 1.8 91/03/11 Copyr 1986 Sun Micro"; 36215990Sjmallett#endif 37215990Sjmallett 38210284Sjmallett/* 39210284Sjmallett * secretkey.c 40210284Sjmallett * Copyright (C) 1986, Sun Microsystems, Inc. 41210284Sjmallett */ 42210284Sjmallett 43210284Sjmallett/* 44210284Sjmallett * Secret key lookup routines 45215990Sjmallett */ 46210284Sjmallett#include <stdio.h> 47210284Sjmallett#include <pwd.h> 48210284Sjmallett#include <rpc/rpc.h> 49210284Sjmallett#include <rpc/key_prot.h> 50210284Sjmallett#include <rpcsvc/yp_prot.h> 51210284Sjmallett#include <rpcsvc/ypclnt.h> 52210284Sjmallett#include <string.h> 53232812Sjmallett 54210284Sjmallettextern int xdecrypt( char *, char * ); 55210284Sjmallett 56210284Sjmallett/* 57210284Sjmallett * Get somebody's encrypted secret key from the database, using the given 58210284Sjmallett * passwd to decrypt it. 59210284Sjmallett */ 60210284Sjmallettint 61210284Sjmallettgetsecretkey(netname, secretkey, passwd) 62210284Sjmallett char *netname; 63210284Sjmallett char *secretkey; 64210284Sjmallett char *passwd; 65210284Sjmallett{ 66210284Sjmallett char lookup[3 * HEXKEYBYTES]; 67210284Sjmallett char *p; 68210284Sjmallett 69210284Sjmallett if (secretkey == NULL) 70210284Sjmallett return (0); 71210284Sjmallett if (!getpublicandprivatekey(netname, lookup)) 72210284Sjmallett return (0); 73210284Sjmallett p = strchr(lookup, ':'); 74210284Sjmallett if (p == NULL) { 75210284Sjmallett return (0); 76210284Sjmallett } 77210284Sjmallett p++; 78210284Sjmallett if (!xdecrypt(p, passwd)) { 79210284Sjmallett return (0); 80210284Sjmallett } 81210284Sjmallett if (memcmp(p, p + HEXKEYBYTES, KEYCHECKSUMSIZE) != 0) { 82210284Sjmallett secretkey[0] = '\0'; 83210284Sjmallett return (1); 84210284Sjmallett } 85210284Sjmallett p[HEXKEYBYTES] = '\0'; 86210284Sjmallett (void) strncpy(secretkey, p, HEXKEYBYTES); 87210284Sjmallett secretkey[HEXKEYBYTES] = '\0'; 88210284Sjmallett return (1); 89210284Sjmallett} 90210284Sjmallett