2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
18 #include <hcrypto/des.h>
20 #include <afs/afsutil.h>
23 #include <rx/rxkad_convert.h>
29 /* This should match the behavior of ParseLoginName on input so that the output
30 * and input are compatible. In names "." should show as \056 and in names and
31 * instances "@" should show as \100 */
34 ka_PrintUserID(char *prefix, /* part to be output before userID */
35 char *name, /* user name */
36 char *instance, /* instance, possible null or len=0 */
38 { /* for output following userID */
41 for (c = (unsigned char *)name; *c; c++)
42 if (isalnum(*c) || (ispunct(*c) && (*c != '.') && (*c != '@')))
46 if (instance && strlen(instance)) {
48 for (c = (unsigned char *)instance; *c; c++)
49 if (isalnum(*c) || (ispunct(*c) && (*c != '@')))
54 printf("%s", postfix);
58 ka_PrintBytes(char bs[], int bl)
62 for (i = 0; i < bl; i++) {
63 unsigned char c = bs[i];
68 /* converts a byte string to ascii. Return the number of unconverted bytes. */
71 ka_ConvertBytes(char *ascii, /* output buffer */
72 int alen, /* buffer length */
73 char bs[], /* byte string */
75 { /* number of bytes */
79 alen--; /* make room for termination */
80 for (i = 0; i < bl; i++) {
84 if (isalnum(c) || ispunct(c))
85 (*ascii++ = c), alen--;
90 *ascii++ = (c >> 6) + '0';
91 *ascii++ = (c >> 3 & 7) + '0';
92 *ascii++ = (c & 7) + '0';
96 *ascii = 0; /* terminate string */
97 return 0; /* all OK */
100 /* This is the inverse of the above function. The return value is the number
101 of bytes read. The blen parameter gived the maximum size of the output
105 ka_ReadBytes(char *ascii, char *binary, int blen)
110 while ((i < blen) && *cp) { /* get byte till null or full */
111 if (*cp == '\\') { /* get byte in octal */
113 c = (c << 3) + (*++cp) - '0';
114 c = (c << 3) + (*++cp) - '0';
117 c = *cp++; /* get byte */
124 umin(afs_uint32 a, afs_uint32 b)
132 /* ka_KeyCheckSum - returns a 32 bit cryptographic checksum of a DES encryption
133 * key. It encrypts a block of zeros and uses first 4 bytes as cksum. */
136 ka_KeyCheckSum(char *key, afs_uint32 * cksumP)
145 code = DES_key_sched(charptr_to_cblock(key), &s);
148 DES_ecb_encrypt(&block, &block, &s, ENCRYPT);
149 memcpy(&cksum, &block, sizeof(afs_int32));
150 *cksumP = ntohl(cksum);
154 /* is the key all zeros? */
156 ka_KeyIsZero(char *akey, int alen)
159 for (i = 0; i < alen; i++) {
167 ka_timestr(afs_int32 time, char *tstr, afs_int32 tlen)
169 char tbuffer[32]; /* need at least 26 bytes */
170 time_t passtime; /* modern systems have 64 bit time */
175 if (time == NEVERDATE)
176 strcpy(tstr, "never");
178 if (!time || strftime(tbuffer, sizeof(tbuffer), "%c",
179 localtime_r(&passtime, &tm)) == 0)
180 strcpy(tstr, "no date");
182 strncpy(tstr, tbuffer, tlen);