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>
16 #include <sys/types.h>
20 #include <sys/socket.h>
21 #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 char *prefix, /* part to be output before userID */
40 char *name, /* user name */
41 char *instance, /* instance, possible null or len=0 */
42 char *postfix) /* for output following userID */
45 printf ("%s", prefix);
46 for (c=(unsigned char *)name; *c; c++)
47 if (isalnum(*c) || (ispunct(*c) && (*c != '.') && (*c != '@')))
49 else printf ("\\%0.3o", *c);
50 if (instance && strlen (instance)) {
52 for (c=(unsigned char *)instance; *c; c++)
53 if (isalnum(*c) || (ispunct(*c) && (*c != '@'))) printf ("%c", *c);
54 else printf ("\\%0.3o", *c);
56 printf ("%s", postfix);
65 for (i=0; i < bl; i++) {
66 unsigned char c = bs[i];
67 printf ("\\%0.3o", c);
71 /* converts a byte string to ascii. Return the number of unconverted bytes. */
74 char *ascii, /* output buffer */
75 int alen, /* buffer length */
76 char bs[], /* byte string */
77 int bl) /* number of bytes */
82 alen--; /* make room for termination */
83 for (i=0; i < bl; i++) {
85 if (alen <= 0) return bl-i;
86 if (isalnum(c) || ispunct(c)) (*ascii++ = c), alen--;
88 if (alen <= 3) return bl-i;
90 *ascii++ = (c>>6) + '0';
91 *ascii++ = (c>>3 & 7) + '0';
92 *ascii++ = (c&7) + '0';
96 *ascii = 0; /* terminate string */
97 return 0; /* all OK */
100 /* This is the inverse of the above function. The return value is the number
101 of bytes read. The blen parameter gived the maximum size of the output
112 while ((i < blen) && *cp) { /* get byte till null or full */
113 if (*cp == '\\') { /* get byte in octal */
115 c = (c<<3) + (*++cp) - '0';
116 c = (c<<3) + (*++cp) - '0';
118 } else c = *cp++; /* get byte */
132 /* ka_KeyCheckSum - returns a 32 bit cryptographic checksum of a DES encryption
133 * key. It encrypts a block of zeros and uses first 4 bytes as cksum. */
135 afs_int32 ka_KeyCheckSum (
146 code = des_key_sched (key, s);
147 if (code) return KABADKEY;
148 des_ecb_encrypt (block, block, s, ENCRYPT);
149 memcpy(&cksum, block, sizeof(afs_int32));
150 *cksumP = ntohl(cksum);
154 /* is the key all zeros? */
160 for(i=0;i<alen;i++) {
161 if (*akey++ != 0) return 0;
171 char tbuffer[32]; /* need at least 26 bytes */
172 time_t passtime; /* modern systems have 64 bit time */
174 if (!time) strcpy (tstr, "no date");/* special case this */
175 else if (time == NEVERDATE) strcpy(tstr, "never");
179 afs_ctime(&passtime, tbuffer, sizeof(tbuffer)), tlen);
180 tstr[strlen(tstr)-1] = '\0'; /* punt the newline character */