secretkey.c revision 256281
16059Samurai/* 26059Samurai * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 36059Samurai * unrestricted use provided that this legend is included on all tape 46059Samurai * media and as a part of the software program in whole or part. Users 56059Samurai * may copy or modify Sun RPC without charge, but are not authorized 66059Samurai * to license or distribute it to anyone else except as part of a product or 76059Samurai * program developed by the user or with the express written consent of 86059Samurai * Sun Microsystems, Inc. 96059Samurai * 106059Samurai * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 116059Samurai * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 126059Samurai * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 136059Samurai * 146059Samurai * Sun RPC is provided with no support and without any obligation on the 156059Samurai * part of Sun Microsystems, Inc. to assist in its use, correction, 166059Samurai * modification or enhancement. 176059Samurai * 186059Samurai * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 196059Samurai * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 2037010Sbrian * OR ANY PART THEREOF. 218857Srgrimes * 226059Samurai * In no event will Sun Microsystems, Inc. be liable for any lost revenue 236059Samurai * or profits or other special, indirect and consequential damages, even if 2436285Sbrian * Sun has been advised of the possibility of such damages. 2536452Sbrian * 2630715Sbrian * Sun Microsystems, Inc. 2730715Sbrian * 2550 Garcia Avenue 2830715Sbrian * Mountain View, California 94043 2930715Sbrian */ 3036285Sbrian 3136285Sbrian#include <sys/cdefs.h> 3230715Sbrian__FBSDID("$FreeBSD: stable/10/lib/librpcsvc/secretkey.c 189087 2009-02-26 20:32:11Z ed $"); 3330715Sbrian 346059Samurai#if !defined(lint) && defined(SCCSIDS) 3511336Samuraistatic char sccsid[] = "@(#)secretkey.c 1.8 91/03/11 Copyr 1986 Sun Micro"; 3630715Sbrian#endif 3730715Sbrian 3830715Sbrian/* 396059Samurai * secretkey.c 406059Samurai * Copyright (C) 1986, Sun Microsystems, Inc. 4118786Sjkh */ 4230715Sbrian 4330715Sbrian/* 4430715Sbrian * Secret key lookup routines 4530715Sbrian */ 4631061Sbrian#include <stdio.h> 4730715Sbrian#include <pwd.h> 4830715Sbrian#include <rpc/rpc.h> 4936285Sbrian#include <rpc/key_prot.h> 506059Samurai#include <rpcsvc/yp_prot.h> 5131514Sbrian#include <rpcsvc/ypclnt.h> 5213389Sphk#include <string.h> 5336285Sbrian 5436285Sbrianextern int xdecrypt( char *, char * ); 5536285Sbrian 566059Samurai/* 5736285Sbrian * Get somebody's encrypted secret key from the database, using the given 5836285Sbrian * passwd to decrypt it. 5936285Sbrian */ 6036285Sbrianint 6136285Sbriangetsecretkey(char *netname, char *secretkey, char *passwd) 6226142Sbrian{ 636735Samurai char lookup[3 * HEXKEYBYTES]; 6413389Sphk char *p; 6513389Sphk 6623840Sbrian if (secretkey == NULL) 6730715Sbrian return (0); 6831195Sbrian if (!getpublicandprivatekey(netname, lookup)) 6936285Sbrian return (0); 7036285Sbrian p = strchr(lookup, ':'); 7136285Sbrian if (p == NULL) { 7236285Sbrian return (0); 7336285Sbrian } 746059Samurai p++; 756735Samurai if (!xdecrypt(p, passwd)) { 766735Samurai return (0); 776735Samurai } 786735Samurai if (memcmp(p, p + HEXKEYBYTES, KEYCHECKSUMSIZE) != 0) { 796735Samurai secretkey[0] = '\0'; 806735Samurai return (1); 8136431Sbrian } 8230715Sbrian p[HEXKEYBYTES] = '\0'; 8331343Sbrian (void) strncpy(secretkey, p, HEXKEYBYTES); 8430715Sbrian secretkey[HEXKEYBYTES] = '\0'; 8536285Sbrian return (1); 8636285Sbrian} 876059Samurai