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>
14 #include <afs/afsutil.h>
16 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
31 #include <des_prototypes.h>
36 /* This should match the behavior of ParseLoginName on input so that the output
37 * and input are compatible. In names "." should show as \056 and in names and
38 * instances "@" should show as \100 */
41 ka_PrintUserID(char *prefix, /* part to be output before userID */
42 char *name, /* user name */
43 char *instance, /* instance, possible null or len=0 */
45 { /* for output following userID */
48 for (c = (unsigned char *)name; *c; c++)
49 if (isalnum(*c) || (ispunct(*c) && (*c != '.') && (*c != '@')))
53 if (instance && strlen(instance)) {
55 for (c = (unsigned char *)instance; *c; c++)
56 if (isalnum(*c) || (ispunct(*c) && (*c != '@')))
61 printf("%s", postfix);
65 ka_PrintBytes(char bs[], int bl)
69 for (i = 0; i < bl; i++) {
70 unsigned char c = bs[i];
75 /* converts a byte string to ascii. Return the number of unconverted bytes. */
78 ka_ConvertBytes(char *ascii, /* output buffer */
79 int alen, /* buffer length */
80 char bs[], /* byte string */
82 { /* number of bytes */
86 alen--; /* make room for termination */
87 for (i = 0; i < bl; i++) {
91 if (isalnum(c) || ispunct(c))
92 (*ascii++ = c), alen--;
97 *ascii++ = (c >> 6) + '0';
98 *ascii++ = (c >> 3 & 7) + '0';
99 *ascii++ = (c & 7) + '0';
103 *ascii = 0; /* terminate string */
104 return 0; /* all OK */
107 /* This is the inverse of the above function. The return value is the number
108 of bytes read. The blen parameter gived the maximum size of the output
112 ka_ReadBytes(char *ascii, char *binary, int blen)
117 while ((i < blen) && *cp) { /* get byte till null or full */
118 if (*cp == '\\') { /* get byte in octal */
120 c = (c << 3) + (*++cp) - '0';
121 c = (c << 3) + (*++cp) - '0';
124 c = *cp++; /* get byte */
131 umin(afs_uint32 a, afs_uint32 b)
139 /* ka_KeyCheckSum - returns a 32 bit cryptographic checksum of a DES encryption
140 * key. It encrypts a block of zeros and uses first 4 bytes as cksum. */
143 ka_KeyCheckSum(char *key, afs_uint32 * cksumP)
152 code = des_key_sched(key, s);
155 des_ecb_encrypt(block, block, s, ENCRYPT);
156 memcpy(&cksum, block, sizeof(afs_int32));
157 *cksumP = ntohl(cksum);
161 /* is the key all zeros? */
163 ka_KeyIsZero(register char *akey, register int alen)
166 for (i = 0; i < alen; i++) {
174 ka_timestr(afs_int32 time, char *tstr, afs_int32 tlen)
176 char tbuffer[32]; /* need at least 26 bytes */
177 time_t passtime; /* modern systems have 64 bit time */
180 strcpy(tstr, "no date"); /* special case this */
181 else if (time == NEVERDATE)
182 strcpy(tstr, "never");
185 strncpy(tstr, afs_ctime(&passtime, tbuffer, sizeof(tbuffer)), tlen);
186 tstr[strlen(tstr) - 1] = '\0'; /* punt the newline character */