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
11 * Revision 2.4 1990/10/01 10:01:37
12 * Include <netinet/in.h> so ntohl is defined properly.
14 * Revision 2.3 90/09/28 16:18:23
16 * Move KeyIsZero here.
17 * Add KeyCheckSum function.
19 * Revision 2.2 90/09/19 08:31:04
20 * Include afs/param.h.
22 * Revision 2.1 90/08/29 08:37:41
23 * Start with clean version to sync test and dev trees.
26 #include <afs/param.h>
28 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
46 /* This should match the behavior of ParseLoginName on input so that the output
47 * and input are compatible. In names "." should show as \056 and in names and
48 * instances "@" should show as \100 */
51 char *prefix, /* part to be output before userID */
52 char *name, /* user name */
53 char *instance, /* instance, possible null or len=0 */
54 char *postfix) /* for output following userID */
57 printf ("%s", prefix);
58 for (c=(unsigned char *)name; *c; c++)
59 if (isalnum(*c) || (ispunct(*c) && (*c != '.') && (*c != '@')))
61 else printf ("\\%0.3o", *c);
62 if (instance && strlen (instance)) {
64 for (c=(unsigned char *)instance; *c; c++)
65 if (isalnum(*c) || (ispunct(*c) && (*c != '@'))) printf ("%c", *c);
66 else printf ("\\%0.3o", *c);
68 printf ("%s", postfix);
77 for (i=0; i < bl; i++) {
78 unsigned char c = bs[i];
79 printf ("\\%0.3o", c);
83 /* converts a byte string to ascii. Return the number of unconverted bytes. */
86 char *ascii, /* output buffer */
87 int alen, /* buffer length */
88 char bs[], /* byte string */
89 int bl) /* number of bytes */
94 alen--; /* make room for termination */
95 for (i=0; i < bl; i++) {
97 if (alen <= 0) return bl-i;
98 if (isalnum(c) || ispunct(c)) (*ascii++ = c), alen--;
100 if (alen <= 3) return bl-i;
102 *ascii++ = (c>>6) + '0';
103 *ascii++ = (c>>3 & 7) + '0';
104 *ascii++ = (c&7) + '0';
108 *ascii = 0; /* terminate string */
109 return 0; /* all OK */
112 /* This is the inverse of the above function. The return value is the number
113 of bytes read. The blen parameter gived the maximum size of the output
124 while ((i < blen) && *cp) { /* get byte till null or full */
125 if (*cp == '\\') { /* get byte in octal */
127 c = (c<<3) + (*++cp) - '0';
128 c = (c<<3) + (*++cp) - '0';
130 } else c = *cp++; /* get byte */
144 /* ka_KeyCheckSum - returns a 32 bit cryptographic checksum of a DES encryption
145 * key. It encrypts a block of zeros and uses first 4 bytes as cksum. */
147 afs_int32 ka_KeyCheckSum (
158 code = des_key_sched (key, s);
159 if (code) return KABADKEY;
160 des_ecb_encrypt (block, block, s, ENCRYPT);
161 bcopy (block, &cksum, sizeof(afs_int32));
162 *cksumP = ntohl(cksum);
166 /* is the key all zeros? */
172 for(i=0;i<alen;i++) {
173 if (*akey++ != 0) return 0;
183 char tbuffer[32]; /* need at least 26 bytes */
184 time_t passtime; /* modern systems have 64 bit time */
186 if (!time) strcpy (tstr, "no date");/* special case this */
187 else if (time == NEVERDATE) strcpy(tstr, "never");
191 afs_ctime(&passtime, tbuffer, sizeof(tbuffer)), tlen);
192 tstr[strlen(tstr)-1] = '\0'; /* punt the newline character */