Print this page
pass 2
first pass


  23  * Copyright 1999-2003 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  28 /*        All Rights Reserved   */
  29 
  30 #pragma ident   "%Z%%M% %I%     %E% SMI"
  31 
  32 #include <stdlib.h>
  33 #include <string.h>
  34 #include <libintl.h>
  35 #include <locale.h>
  36 #include <errno.h>
  37 #include <unistd.h>
  38 #include <ctype.h>
  39 #include <syslog.h>
  40 #include <sys/time.h>
  41 #include "ns_sldap.h"
  42 #include "ns_internal.h"
  43 /* EXPORT DELETE START */
  44 #include <crypt.h>
  45 
  46 #define NS_DOMESTIC     1
  47 
  48 static  char            t1[ROTORSIZE];
  49 static  char            t2[ROTORSIZE];
  50 static  char            t3[ROTORSIZE];
  51 static  char            hexdig[] = "0123456789abcdef";
  52 
  53 static mutex_t          ns_crypt_lock = DEFAULTMUTEX;
  54 static boolean_t        crypt_inited = B_FALSE;
  55 
  56 static int
  57 is_cleartext(const char *pwd)
  58 {
  59         if (0 == strncmp(pwd, CRYPTMARK, strlen(CRYPTMARK)))
  60                 return (FALSE);
  61         return (TRUE);
  62 }
  63 
  64 
  65 static char *
  66 hex2ascii(char *aString, int aLen)
  67 {


  96 static char *
  97 ascii2hex(char *anHexaStr, int *aResLen)
  98 {
  99         int theLen = 0;
 100         char *theRes = malloc(strlen(anHexaStr) /2 + 1);
 101 
 102         if (theRes == NULL)
 103                 return (NULL);
 104         while (isxdigit(*anHexaStr)) {
 105                 theRes[theLen] = unhex(*anHexaStr) << 4;
 106                 if (++anHexaStr != '\0') {
 107                         theRes[theLen] += unhex(*anHexaStr);
 108                         anHexaStr++;
 109                 }
 110                 theLen++;
 111         }
 112         theRes[theLen] = '\0';
 113         *aResLen = theLen;
 114         return (theRes);
 115 }
 116 /* EXPORT DELETE END */
 117 
 118 
 119 static void
 120 c_setup()
 121 {
 122 /* EXPORT DELETE START */
 123         int ic, i, k, temp;
 124         unsigned random;
 125         char buf[13];
 126         int seed;
 127 
 128         (void) mutex_lock(&ns_crypt_lock);
 129         if (crypt_inited) {
 130                 (void) mutex_unlock(&ns_crypt_lock);
 131                 return;
 132         }
 133         (void) strcpy(buf, "Homer J");
 134         buf[8] = buf[0];
 135         buf[9] = buf[1];
 136         (void) strncpy(buf, (char *)crypt(buf, &buf[8]), 13);
 137         seed = 123;
 138         for (i = 0; i < 13; i++)
 139                 seed = seed*buf[i] + i;
 140         for (i = 0; i < ROTORSIZE; i++) {
 141                 t1[i] = i;
 142                 t3[i] = 0;


 173                 c_setup();
 174         i = 0;
 175         n1 = 0;
 176         n2 = 0;
 177         if ((s = (char *)malloc(2 * len + 1)) != NULL) {
 178                 while (i < len) {
 179                     s[i] = t2[(t3[(t1[(str[i]+n1)&MASK]+n2)&MASK]-n2)&MASK]-n1;
 180                     i++;
 181                     n1++;
 182                     if (n1 == ROTORSIZE) {
 183                         n1 = 0;
 184                         n2++;
 185                         if (n2 == ROTORSIZE) n2 = 0;
 186                     }
 187                 }
 188                 s[i] = '\0';
 189                 if (mod_len != NULL)
 190                     *mod_len = i;
 191         }
 192         return (s);
 193 /* EXPORT DELETE END */
 194 }
 195 
 196 
 197 char *
 198 evalue(char *ptr)
 199 {
 200 /* EXPORT DELETE START */
 201         char *modv, *str, *ev;
 202         int modv_len;
 203         size_t len;
 204 
 205         /*
 206          * if not cleartext, return a copy of what ptr
 207          * points to as that is what evalue does below.
 208          */
 209         if (FALSE == is_cleartext(ptr)) {
 210                 str = strdup(ptr);
 211                 return (str);
 212         }
 213 
 214         modv = modvalue(ptr, strlen(ptr), &modv_len);
 215         str = hex2ascii(modv, modv_len);
 216         free(modv);
 217         modv = NULL;
 218         len = strlen(str) + strlen(CRYPTMARK) + 1;
 219         ev = malloc(len);
 220         if (ev == NULL) {
 221                 free(str);
 222                 return (NULL);
 223         }
 224         (void) snprintf(ev, len, CRYPTMARK "%s", str);
 225         free(str);
 226         str = NULL;
 227         return (ev);
 228 #ifndef NS_DOMESTIC
 229 /* EXPORT DELETE END */
 230         return (strdup(ptr));
 231 /* EXPORT DELETE START */
 232 #endif
 233 /* EXPORT DELETE END */
 234 }
 235 
 236 
 237 char *
 238 dvalue(char *ptr)
 239 {
 240 /* EXPORT DELETE START */
 241         char *modv, *str, *sb;
 242         int len;
 243 
 244         /* if cleartext return NULL (error!) */
 245         if (TRUE == is_cleartext(ptr))
 246                 return (NULL);
 247 
 248         sb = strchr(ptr, '}');
 249         sb++;
 250         len = strlen(sb);
 251         str = ascii2hex(sb, &len);
 252         modv = modvalue(str, len, NULL);
 253         free(str);
 254         str = NULL;
 255         return (modv);
 256 #ifndef NS_DOMESTIC
 257 /* EXPORT DELETE END */
 258         return (strdup(ptr));
 259 /* EXPORT DELETE START */
 260 #endif
 261 /* EXPORT DELETE END */
 262 }


  23  * Copyright 1999-2003 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  28 /*        All Rights Reserved   */
  29 
  30 #pragma ident   "%Z%%M% %I%     %E% SMI"
  31 
  32 #include <stdlib.h>
  33 #include <string.h>
  34 #include <libintl.h>
  35 #include <locale.h>
  36 #include <errno.h>
  37 #include <unistd.h>
  38 #include <ctype.h>
  39 #include <syslog.h>
  40 #include <sys/time.h>
  41 #include "ns_sldap.h"
  42 #include "ns_internal.h"

  43 #include <crypt.h>
  44 


  45 static  char            t1[ROTORSIZE];
  46 static  char            t2[ROTORSIZE];
  47 static  char            t3[ROTORSIZE];
  48 static  char            hexdig[] = "0123456789abcdef";
  49 
  50 static mutex_t          ns_crypt_lock = DEFAULTMUTEX;
  51 static boolean_t        crypt_inited = B_FALSE;
  52 
  53 static int
  54 is_cleartext(const char *pwd)
  55 {
  56         if (0 == strncmp(pwd, CRYPTMARK, strlen(CRYPTMARK)))
  57                 return (FALSE);
  58         return (TRUE);
  59 }
  60 
  61 
  62 static char *
  63 hex2ascii(char *aString, int aLen)
  64 {


  93 static char *
  94 ascii2hex(char *anHexaStr, int *aResLen)
  95 {
  96         int theLen = 0;
  97         char *theRes = malloc(strlen(anHexaStr) /2 + 1);
  98 
  99         if (theRes == NULL)
 100                 return (NULL);
 101         while (isxdigit(*anHexaStr)) {
 102                 theRes[theLen] = unhex(*anHexaStr) << 4;
 103                 if (++anHexaStr != '\0') {
 104                         theRes[theLen] += unhex(*anHexaStr);
 105                         anHexaStr++;
 106                 }
 107                 theLen++;
 108         }
 109         theRes[theLen] = '\0';
 110         *aResLen = theLen;
 111         return (theRes);
 112 }

 113 
 114 
 115 static void
 116 c_setup()
 117 {

 118         int ic, i, k, temp;
 119         unsigned random;
 120         char buf[13];
 121         int seed;
 122 
 123         (void) mutex_lock(&ns_crypt_lock);
 124         if (crypt_inited) {
 125                 (void) mutex_unlock(&ns_crypt_lock);
 126                 return;
 127         }
 128         (void) strcpy(buf, "Homer J");
 129         buf[8] = buf[0];
 130         buf[9] = buf[1];
 131         (void) strncpy(buf, (char *)crypt(buf, &buf[8]), 13);
 132         seed = 123;
 133         for (i = 0; i < 13; i++)
 134                 seed = seed*buf[i] + i;
 135         for (i = 0; i < ROTORSIZE; i++) {
 136                 t1[i] = i;
 137                 t3[i] = 0;


 168                 c_setup();
 169         i = 0;
 170         n1 = 0;
 171         n2 = 0;
 172         if ((s = (char *)malloc(2 * len + 1)) != NULL) {
 173                 while (i < len) {
 174                     s[i] = t2[(t3[(t1[(str[i]+n1)&MASK]+n2)&MASK]-n2)&MASK]-n1;
 175                     i++;
 176                     n1++;
 177                     if (n1 == ROTORSIZE) {
 178                         n1 = 0;
 179                         n2++;
 180                         if (n2 == ROTORSIZE) n2 = 0;
 181                     }
 182                 }
 183                 s[i] = '\0';
 184                 if (mod_len != NULL)
 185                     *mod_len = i;
 186         }
 187         return (s);

 188 }
 189 
 190 
 191 char *
 192 evalue(char *ptr)
 193 {

 194         char *modv, *str, *ev;
 195         int modv_len;
 196         size_t len;
 197 
 198         /*
 199          * if not cleartext, return a copy of what ptr
 200          * points to as that is what evalue does below.
 201          */
 202         if (FALSE == is_cleartext(ptr)) {
 203                 str = strdup(ptr);
 204                 return (str);
 205         }
 206 
 207         modv = modvalue(ptr, strlen(ptr), &modv_len);
 208         str = hex2ascii(modv, modv_len);
 209         free(modv);
 210         modv = NULL;
 211         len = strlen(str) + strlen(CRYPTMARK) + 1;
 212         ev = malloc(len);
 213         if (ev == NULL) {
 214                 free(str);
 215                 return (NULL);
 216         }
 217         (void) snprintf(ev, len, CRYPTMARK "%s", str);
 218         free(str);
 219         str = NULL;
 220         return (ev);






 221 }
 222 
 223 
 224 char *
 225 dvalue(char *ptr)
 226 {

 227         char *modv, *str, *sb;
 228         int len;
 229 
 230         /* if cleartext return NULL (error!) */
 231         if (TRUE == is_cleartext(ptr))
 232                 return (NULL);
 233 
 234         sb = strchr(ptr, '}');
 235         sb++;
 236         len = strlen(sb);
 237         str = ascii2hex(sb, &len);
 238         modv = modvalue(str, len, NULL);
 239         free(str);
 240         str = NULL;
 241         return (modv);






 242 }