home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / rpc / publickey.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-15  |  2.8 KB  |  130 lines

  1. #ifndef lint
  2. static char sccsid[] =     "@(#)publickey.c    2.3 88/08/15 4.0 RPCSRC";
  3. #endif
  4. /*
  5.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  6.  * unrestricted use provided that this legend is included on all tape
  7.  * media and as a part of the software program in whole or part.  Users
  8.  * may copy or modify Sun RPC without charge, but are not authorized
  9.  * to license or distribute it to anyone else except as part of a product or
  10.  * program developed by the user.
  11.  * 
  12.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  13.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  14.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  15.  * 
  16.  * Sun RPC is provided with no support and without any obligation on the
  17.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  18.  * modification or enhancement.
  19.  * 
  20.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  21.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  22.  * OR ANY PART THEREOF.
  23.  * 
  24.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  25.  * or profits or other special, indirect and consequential damages, even if
  26.  * Sun has been advised of the possibility of such damages.
  27.  * 
  28.  * Sun Microsystems, Inc.
  29.  * 2550 Garcia Avenue
  30.  * Mountain View, California  94043
  31.  */
  32.  
  33. /* 
  34.  * Copyright (c) 1988 by Sun Microsystems, Inc.
  35.  * @(#) from SUN 1.3
  36.  */
  37.  
  38. /*
  39.  * Public key lookup routines
  40.  */
  41. #include <stdio.h>
  42. #include <pwd.h>
  43. #include <rpc/rpc.h>
  44. #include <rpc/key_prot.h>
  45.  
  46.  
  47. extern char *index();
  48. extern char *strcpy();
  49.  
  50. static char PKMAP[] = "publickey.byname";
  51.  
  52. /*
  53.  * Get somebody's encrypted secret key from the database, using
  54.  * the given passwd to decrypt it.
  55.  */
  56. getsecretkey(netname, secretkey, passwd)
  57.     char *netname;
  58.     char *secretkey;
  59.     char *passwd;
  60. {
  61.     char *domain;
  62.     int len;
  63.     char *lookup;
  64.     int err;
  65.     char *p;
  66.  
  67.  
  68.     err = yp_get_default_domain(&domain);
  69.     if (err) {
  70.         return(0);
  71.     }
  72.     err = yp_match(domain, PKMAP, netname, strlen(netname), &lookup, &len);
  73.     if (err) {
  74.         return(0);
  75.     }
  76.     lookup[len] = 0;
  77.     p = index(lookup,':');
  78.     if (p == NULL) {
  79.         free(lookup);
  80.         return(0);
  81.     }
  82.     p++;
  83.     if (!xdecrypt(p, passwd)) {
  84.         free(lookup);
  85.         return(0);
  86.     }
  87.     if (bcmp(p, p + HEXKEYBYTES, KEYCHECKSUMSIZE) != 0) {
  88.         secretkey[0] = 0;
  89.         free(lookup);
  90.         return(1);
  91.     }
  92.     p[HEXKEYBYTES] = 0;
  93.     (void) strcpy(secretkey, p);
  94.     free(lookup);
  95.     return(1);
  96. }
  97.  
  98.  
  99.  
  100. /*
  101.  * Get somebody's public key
  102.  */
  103. getpublickey(netname, publickey)
  104.     char *netname;
  105.     char *publickey;
  106. {
  107.     char *domain;
  108.     int len;
  109.     char *lookup;
  110.     int err;
  111.     char *p;
  112.  
  113.     err = yp_get_default_domain(&domain);    
  114.     if (err) {
  115.         return(0);
  116.     }
  117.     err = yp_match(domain, PKMAP, netname, strlen(netname), &lookup, &len);
  118.     if (err) {
  119.         return(0);
  120.     }
  121.     p = index(lookup, ':');
  122.     if (p == NULL) {
  123.         free(lookup);
  124.         return(0);
  125.     }
  126.     *p = 0;    
  127.     (void) strcpy(publickey, lookup);
  128.     return(1);
  129. }
  130.