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>
45 #include "../permit_xprt.h"
49 /* This should match the behavior of ParseLoginName on input so that the output
50 * and input are compatible. In names "." should show as \056 and in names and
51 * instances "@" should show as \100 */
54 char *prefix, /* part to be output before userID */
55 char *name, /* user name */
56 char *instance, /* instance, possible null or len=0 */
57 char *postfix) /* for output following userID */
60 printf ("%s", prefix);
61 for (c=(unsigned char *)name; *c; c++)
62 if (isalnum(*c) || (ispunct(*c) && (*c != '.') && (*c != '@')))
64 else printf ("\\%0.3o", *c);
65 if (instance && strlen (instance)) {
67 for (c=(unsigned char *)instance; *c; c++)
68 if (isalnum(*c) || (ispunct(*c) && (*c != '@'))) printf ("%c", *c);
69 else printf ("\\%0.3o", *c);
71 printf ("%s", postfix);
80 for (i=0; i < bl; i++) {
81 unsigned char c = bs[i];
82 printf ("\\%0.3o", c);
86 /* converts a byte string to ascii. Return the number of unconverted bytes. */
89 char *ascii, /* output buffer */
90 int alen, /* buffer length */
91 char bs[], /* byte string */
92 int bl) /* number of bytes */
97 alen--; /* make room for termination */
98 for (i=0; i < bl; i++) {
100 if (alen <= 0) return bl-i;
101 if (isalnum(c) || ispunct(c)) (*ascii++ = c), alen--;
103 if (alen <= 3) return bl-i;
105 *ascii++ = (c>>6) + '0';
106 *ascii++ = (c>>3 & 7) + '0';
107 *ascii++ = (c&7) + '0';
111 *ascii = 0; /* terminate string */
112 return 0; /* all OK */
115 /* This is the inverse of the above function. The return value is the number
116 of bytes read. The blen parameter gived the maximum size of the output
127 while ((i < blen) && *cp) { /* get byte till null or full */
128 if (*cp == '\\') { /* get byte in octal */
130 c = (c<<3) + (*++cp) - '0';
131 c = (c<<3) + (*++cp) - '0';
133 } else c = *cp++; /* get byte */
147 /* ka_KeyCheckSum - returns a 32 bit cryptographic checksum of a DES encryption
148 * key. It encrypts a block of zeros and uses first 4 bytes as cksum. */
150 afs_int32 ka_KeyCheckSum (
161 code = des_key_sched (key, s);
162 if (code) return KABADKEY;
163 des_ecb_encrypt (block, block, s, ENCRYPT);
164 bcopy (block, &cksum, sizeof(afs_int32));
165 *cksumP = ntohl(cksum);
169 /* is the key all zeros? */
175 for(i=0;i<alen;i++) {
176 if (*akey++ != 0) return 0;
186 char tbuffer[32]; /* need at least 26 bytes */
187 time_t passtime; /* modern systems have 64 bit time */
189 if (!time) strcpy (tstr, "no date");/* special case this */
190 else if (time == NEVERDATE) strcpy(tstr, "never");
194 afs_ctime(&passtime, tbuffer, sizeof(tbuffer)), tlen);
195 tstr[strlen(tstr)-1] = '\0'; /* punt the newline character */