diff options
author | Damien Miller <djm@mindrot.org> | 2000-05-07 12:03:14 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2000-05-07 12:03:14 +1000 |
commit | e247cc402bc391650f014316363dbce78ad85dc7 (patch) | |
tree | 65d72c3d3514c6119f47017f14b71ed153485a5d /uuencode.c | |
parent | 0437b33e54fd72060d17908d6abf96bfabaacad2 (diff) |
- Remove references to SSLeay.
- Big OpenBSD CVS update
- markus@cvs.openbsd.org
[clientloop.c]
- typo
[session.c]
- update proctitle on pty alloc/dealloc, e.g. w/ windows client
[session.c]
- update proctitle for proto 1, too
[channels.h nchan.c serverloop.c session.c sshd.c]
- use c-style comments
- deraadt@cvs.openbsd.org
[scp.c]
- more atomicio
- markus@cvs.openbsd.org
[channels.c]
- set O_NONBLOCK
[ssh.1]
- update AUTHOR
[readconf.c ssh-keygen.c ssh.h]
- default DSA key file ~/.ssh/id_dsa
[clientloop.c]
- typo, rm verbose debug
- deraadt@cvs.openbsd.org
[ssh-keygen.1]
- document DSA use of ssh-keygen
[sshd.8]
- a start at describing what i understand of the DSA side
[ssh-keygen.1]
- document -X and -x
[ssh-keygen.c]
- simplify usage
- markus@cvs.openbsd.org
[sshd.8]
- there is no rhosts_dsa
[ssh-keygen.1]
- document -y, update -X,-x
[nchan.c]
- fix close for non-open ssh1 channels
[servconf.c servconf.h ssh.h sshd.8 sshd.c ]
- s/DsaKey/HostDSAKey/, document option
[sshconnect2.c]
- respect number_of_password_prompts
[channels.c channels.h servconf.c servconf.h session.c sshd.8]
- GatewayPorts for sshd, ok deraadt@
[ssh-add.1 ssh-agent.1 ssh.1]
- more doc on: DSA, id_dsa, known_hosts2, authorized_keys2
[ssh.1]
- more info on proto 2
[sshd.8]
- sync AUTHOR w/ ssh.1
[key.c key.h sshconnect.c]
- print key type when talking about host keys
[packet.c]
- clear padding in ssh2
[dsa.c key.c radix.c ssh.h sshconnect1.c uuencode.c uuencode.h]
- replace broken uuencode w/ libc b64_ntop
[auth2.c]
- log failure before sending the reply
[key.c radix.c uuencode.c]
- remote trailing comments before calling __b64_pton
[auth2.c readconf.c readconf.h servconf.c servconf.h ssh.1]
[sshconnect2.c sshd.8]
- add DSAAuthetication option to ssh/sshd, document SSH2 in sshd.8
- Bring in b64_ntop and b64_pton from OpenBSD libc (bsd-base64.[ch])
Diffstat (limited to 'uuencode.c')
-rw-r--r-- | uuencode.c | 110 |
1 files changed, 20 insertions, 90 deletions
diff --git a/uuencode.c b/uuencode.c index 626890050..fc84d5a58 100644 --- a/uuencode.c +++ b/uuencode.c | |||
@@ -1,106 +1,36 @@ | |||
1 | /* | 1 | /* |
2 | * base-64 encoding pinched from lynx2-7-2, who pinched it from rpem. | 2 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
3 | * Originally written by Mark Riordan 12 August 1990 and 17 Feb 1991 | ||
4 | * and placed in the public domain. | ||
5 | * | ||
6 | * Dug Song <dugsong@UMICH.EDU> | ||
7 | */ | 3 | */ |
8 | |||
9 | #include "includes.h" | 4 | #include "includes.h" |
10 | #include "xmalloc.h" | 5 | #include "xmalloc.h" |
11 | 6 | ||
12 | char six2pr[64] = { | 7 | #include <resolv.h> |
13 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', | ||
14 | 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', | ||
15 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', | ||
16 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', | ||
17 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' | ||
18 | }; | ||
19 | |||
20 | unsigned char pr2six[256]; | ||
21 | 8 | ||
22 | int | 9 | int |
23 | uuencode(unsigned char *bufin, unsigned int nbytes, char *bufcoded) | 10 | uuencode(unsigned char *src, unsigned int srclength, |
11 | char *target, size_t targsize) | ||
24 | { | 12 | { |
25 | /* ENC is the basic 1 character encoding function to make a char printing */ | 13 | return __b64_ntop(src, srclength, target, targsize); |
26 | #define ENC(c) six2pr[c] | ||
27 | |||
28 | register char *outptr = bufcoded; | ||
29 | unsigned int i; | ||
30 | |||
31 | for (i = 0; i < nbytes; i += 3) { | ||
32 | *(outptr++) = ENC(*bufin >> 2); /* c1 */ | ||
33 | *(outptr++) = ENC(((*bufin << 4) & 060) | ((bufin[1] >> 4) & 017)); /* c2 */ | ||
34 | *(outptr++) = ENC(((bufin[1] << 2) & 074) | ((bufin[2] >> 6) & 03)); /* c3 */ | ||
35 | *(outptr++) = ENC(bufin[2] & 077); /* c4 */ | ||
36 | bufin += 3; | ||
37 | } | ||
38 | if (i == nbytes + 1) { | ||
39 | outptr[-1] = '='; | ||
40 | } else if (i == nbytes + 2) { | ||
41 | outptr[-1] = '='; | ||
42 | outptr[-2] = '='; | ||
43 | } else if (i == nbytes) { | ||
44 | *(outptr++) = '='; | ||
45 | } | ||
46 | *outptr = '\0'; | ||
47 | return (outptr - bufcoded); | ||
48 | } | 14 | } |
49 | 15 | ||
50 | int | 16 | int |
51 | uudecode(const char *bufcoded, unsigned char *bufplain, int outbufsize) | 17 | uudecode(const char *src, unsigned char *target, size_t targsize) |
52 | { | 18 | { |
53 | /* single character decode */ | 19 | int len; |
54 | #define DEC(c) pr2six[(unsigned char)c] | 20 | char *encoded, *p; |
55 | #define MAXVAL 63 | ||
56 | |||
57 | static int first = 1; | ||
58 | int nbytesdecoded, j; | ||
59 | const char *bufin = bufcoded; | ||
60 | register unsigned char *bufout = bufplain; | ||
61 | register int nprbytes; | ||
62 | 21 | ||
63 | /* If this is the first call, initialize the mapping table. */ | 22 | /* copy the 'readonly' source */ |
64 | if (first) { | 23 | encoded = xstrdup(src); |
65 | first = 0; | 24 | /* skip whitespace and data */ |
66 | for (j = 0; j < 256; j++) | 25 | for (p = encoded; *p == ' ' || *p == '\t'; p++) |
67 | pr2six[j] = MAXVAL + 1; | ||
68 | for (j = 0; j < 64; j++) | ||
69 | pr2six[(unsigned char) six2pr[j]] = (unsigned char) j; | ||
70 | } | ||
71 | /* Strip leading whitespace. */ | ||
72 | while (*bufcoded == ' ' || *bufcoded == '\t') | ||
73 | bufcoded++; | ||
74 | |||
75 | /* | ||
76 | * Figure out how many characters are in the input buffer. If this | ||
77 | * would decode into more bytes than would fit into the output | ||
78 | * buffer, adjust the number of input bytes downwards. | ||
79 | */ | ||
80 | bufin = bufcoded; | ||
81 | while (DEC(*(bufin++)) <= MAXVAL) | ||
82 | ; | 26 | ; |
83 | nprbytes = bufin - bufcoded - 1; | 27 | for (; *p != '\0' && *p != ' ' && *p != '\t'; p++) |
84 | nbytesdecoded = ((nprbytes + 3) / 4) * 3; | 28 | ; |
85 | if (nbytesdecoded > outbufsize) | 29 | /* and remote trailing whitespace because __b64_pton needs this */ |
86 | nprbytes = (outbufsize * 4) / 3; | 30 | *p = '\0'; |
87 | 31 | len = __b64_pton(encoded, target, targsize); | |
88 | bufin = bufcoded; | 32 | xfree(encoded); |
89 | 33 | return len; | |
90 | while (nprbytes > 0) { | ||
91 | *(bufout++) = (unsigned char) (DEC(*bufin) << 2 | DEC(bufin[1]) >> 4); | ||
92 | *(bufout++) = (unsigned char) (DEC(bufin[1]) << 4 | DEC(bufin[2]) >> 2); | ||
93 | *(bufout++) = (unsigned char) (DEC(bufin[2]) << 6 | DEC(bufin[3])); | ||
94 | bufin += 4; | ||
95 | nprbytes -= 4; | ||
96 | } | ||
97 | if (nprbytes & 03) { | ||
98 | if (DEC(bufin[-2]) > MAXVAL) | ||
99 | nbytesdecoded -= 2; | ||
100 | else | ||
101 | nbytesdecoded -= 1; | ||
102 | } | ||
103 | return (nbytesdecoded); | ||
104 | } | 34 | } |
105 | 35 | ||
106 | void | 36 | void |
@@ -108,7 +38,7 @@ dump_base64(FILE *fp, unsigned char *data, int len) | |||
108 | { | 38 | { |
109 | unsigned char *buf = xmalloc(2*len); | 39 | unsigned char *buf = xmalloc(2*len); |
110 | int i, n; | 40 | int i, n; |
111 | n = uuencode(data, len, buf); | 41 | n = uuencode(data, len, buf, 2*len); |
112 | for (i = 0; i < n; i++) { | 42 | for (i = 0; i < n; i++) { |
113 | fprintf(fp, "%c", buf[i]); | 43 | fprintf(fp, "%c", buf[i]); |
114 | if (i % 70 == 69) | 44 | if (i % 70 == 69) |