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>
15 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
34 /* This should match the behavior of ParseLoginName on input so that the output
35 * and input are compatible. In names "." should show as \056 and in names and
36 * instances "@" should show as \100 */
39 ka_PrintUserID(char *prefix, /* part to be output before userID */
40 char *name, /* user name */
41 char *instance, /* instance, possible null or len=0 */
43 { /* for output following userID */
46 for (c = (unsigned char *)name; *c; c++)
47 if (isalnum(*c) || (ispunct(*c) && (*c != '.') && (*c != '@')))
51 if (instance && strlen(instance)) {
53 for (c = (unsigned char *)instance; *c; c++)
54 if (isalnum(*c) || (ispunct(*c) && (*c != '@')))
59 printf("%s", postfix);
63 ka_PrintBytes(char bs[], int bl)
67 for (i = 0; i < bl; i++) {
68 unsigned char c = bs[i];
73 /* converts a byte string to ascii. Return the number of unconverted bytes. */
76 ka_ConvertBytes(char *ascii, /* output buffer */
77 int alen, /* buffer length */
78 char bs[], /* byte string */
80 { /* number of bytes */
84 alen--; /* make room for termination */
85 for (i = 0; i < bl; i++) {
89 if (isalnum(c) || ispunct(c))
90 (*ascii++ = c), alen--;
95 *ascii++ = (c >> 6) + '0';
96 *ascii++ = (c >> 3 & 7) + '0';
97 *ascii++ = (c & 7) + '0';
101 *ascii = 0; /* terminate string */
102 return 0; /* all OK */
105 /* This is the inverse of the above function. The return value is the number
106 of bytes read. The blen parameter gived the maximum size of the output
110 ka_ReadBytes(char *ascii, char *binary, int blen)
115 while ((i < blen) && *cp) { /* get byte till null or full */
116 if (*cp == '\\') { /* get byte in octal */
118 c = (c << 3) + (*++cp) - '0';
119 c = (c << 3) + (*++cp) - '0';
122 c = *cp++; /* get byte */
129 umin(afs_uint32 a, afs_uint32 b)
137 /* ka_KeyCheckSum - returns a 32 bit cryptographic checksum of a DES encryption
138 * key. It encrypts a block of zeros and uses first 4 bytes as cksum. */
141 ka_KeyCheckSum(char *key, afs_uint32 * cksumP)
150 code = des_key_sched(key, s);
153 des_ecb_encrypt(block, block, s, ENCRYPT);
154 memcpy(&cksum, block, sizeof(afs_int32));
155 *cksumP = ntohl(cksum);
159 /* is the key all zeros? */
161 ka_KeyIsZero(register char *akey, register int alen)
164 for (i = 0; i < alen; i++) {
172 ka_timestr(afs_int32 time, char *tstr, afs_int32 tlen)
174 char tbuffer[32]; /* need at least 26 bytes */
175 time_t passtime; /* modern systems have 64 bit time */
178 strcpy(tstr, "no date"); /* special case this */
179 else if (time == NEVERDATE)
180 strcpy(tstr, "never");
183 strncpy(tstr, afs_ctime(&passtime, tbuffer, sizeof(tbuffer)), tlen);
184 tstr[strlen(tstr) - 1] = '\0'; /* punt the newline character */