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>
17 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
42 /* This should match the behavior of ParseLoginName on input so that the output
43 * and input are compatible. In names "." should show as \056 and in names and
44 * instances "@" should show as \100 */
47 ka_PrintUserID(char *prefix, /* part to be output before userID */
48 char *name, /* user name */
49 char *instance, /* instance, possible null or len=0 */
51 { /* for output following userID */
54 for (c = (unsigned char *)name; *c; c++)
55 if (isalnum(*c) || (ispunct(*c) && (*c != '.') && (*c != '@')))
58 printf("\\%0.3o", *c);
59 if (instance && strlen(instance)) {
61 for (c = (unsigned char *)instance; *c; c++)
62 if (isalnum(*c) || (ispunct(*c) && (*c != '@')))
65 printf("\\%0.3o", *c);
67 printf("%s", postfix);
71 ka_PrintBytes(char bs[], int bl)
75 for (i = 0; i < bl; i++) {
76 unsigned char c = bs[i];
81 /* converts a byte string to ascii. Return the number of unconverted bytes. */
84 ka_ConvertBytes(char *ascii, /* output buffer */
85 int alen, /* buffer length */
86 char bs[], /* byte string */
88 { /* number of bytes */
92 alen--; /* make room for termination */
93 for (i = 0; i < bl; i++) {
97 if (isalnum(c) || ispunct(c))
98 (*ascii++ = c), alen--;
103 *ascii++ = (c >> 6) + '0';
104 *ascii++ = (c >> 3 & 7) + '0';
105 *ascii++ = (c & 7) + '0';
109 *ascii = 0; /* terminate string */
110 return 0; /* all OK */
113 /* This is the inverse of the above function. The return value is the number
114 of bytes read. The blen parameter gived the maximum size of the output
118 ka_ReadBytes(char *ascii, char *binary, int blen)
123 while ((i < blen) && *cp) { /* get byte till null or full */
124 if (*cp == '\\') { /* get byte in octal */
126 c = (c << 3) + (*++cp) - '0';
127 c = (c << 3) + (*++cp) - '0';
130 c = *cp++; /* get byte */
137 umin(afs_uint32 a, afs_uint32 b)
145 /* ka_KeyCheckSum - returns a 32 bit cryptographic checksum of a DES encryption
146 * key. It encrypts a block of zeros and uses first 4 bytes as cksum. */
149 ka_KeyCheckSum(char *key, afs_uint32 * cksumP)
158 code = des_key_sched(key, s);
161 des_ecb_encrypt(block, block, s, ENCRYPT);
162 memcpy(&cksum, block, sizeof(afs_int32));
163 *cksumP = ntohl(cksum);
167 /* is the key all zeros? */
169 ka_KeyIsZero(register char *akey, register int alen)
172 for (i = 0; i < alen; i++) {
180 ka_timestr(afs_int32 time, char *tstr, afs_int32 tlen)
182 char tbuffer[32]; /* need at least 26 bytes */
183 time_t passtime; /* modern systems have 64 bit time */
186 strcpy(tstr, "no date"); /* special case this */
187 else if (time == NEVERDATE)
188 strcpy(tstr, "never");
191 strncpy(tstr, afs_ctime(&passtime, tbuffer, sizeof(tbuffer)), tlen);
192 tstr[strlen(tstr) - 1] = '\0'; /* punt the newline character */