diff options
Diffstat (limited to 'src')
369 files changed, 28066 insertions, 3474 deletions
diff --git a/src/lib/libc/crypt/Makefile.inc b/src/lib/libc/crypt/Makefile.inc new file mode 100644 index 0000000000..9d96d657db --- /dev/null +++ b/src/lib/libc/crypt/Makefile.inc | |||
@@ -0,0 +1,12 @@ | |||
1 | # $OpenBSD: Makefile.inc,v 1.10 1998/07/21 22:23:20 provos Exp $ | ||
2 | |||
3 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/crypt ${.CURDIR}/crypt | ||
4 | |||
5 | SRCS+= cast.c crypt.c morecrypt.c md5crypt.c arc4random.c blowfish.c | ||
6 | SRCS+= bcrypt.c | ||
7 | |||
8 | MAN+= crypt.3 blowfish.3 arc4random.3 | ||
9 | MLINKS+=crypt.3 encrypt.3 crypt.3 setkey.3 crypt.3 des_cipher.3 | ||
10 | MLINKS+=crypt.3 des_setkey.3 blowfish.3 blf_key.3 blowfish.3 blf_enc.3 | ||
11 | MLINKS+=blowfish.3 blf_dec.3 | ||
12 | MLINKS+=arc4random.3 arc4random_stir.3 arc4random.3 arc4random_addrandom.3 | ||
diff --git a/src/lib/libc/crypt/arc4random.3 b/src/lib/libc/crypt/arc4random.3 new file mode 100644 index 0000000000..741965c5ac --- /dev/null +++ b/src/lib/libc/crypt/arc4random.3 | |||
@@ -0,0 +1,83 @@ | |||
1 | .\" $OpenBSD: arc4random.3,v 1.4 1998/09/07 16:44:34 aaron Exp $ | ||
2 | .\" Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | ||
3 | .\" All rights reserved. | ||
4 | .\" | ||
5 | .\" Redistribution and use in source and binary forms, with or without | ||
6 | .\" modification, are permitted provided that the following conditions | ||
7 | .\" are met: | ||
8 | .\" 1. Redistributions of source code must retain the above copyright | ||
9 | .\" notice, this list of conditions and the following disclaimer. | ||
10 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
11 | .\" notice, this list of conditions and the following disclaimer in the | ||
12 | .\" documentation and/or other materials provided with the distribution. | ||
13 | .\" 3. All advertising materials mentioning features or use of this software | ||
14 | .\" must display the following acknowledgement: | ||
15 | .\" This product includes software developed by Niels Provos. | ||
16 | .\" 4. The name of the author may not be used to endorse or promote products | ||
17 | .\" derived from this software without specific prior written permission. | ||
18 | .\" | ||
19 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
20 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
21 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
22 | .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
23 | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
24 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
25 | .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
26 | .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
27 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
28 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | .\" | ||
30 | .\" Manual page, using -mandoc macros | ||
31 | .\" | ||
32 | .Dd April 15, 1997 | ||
33 | .Dt ARC4RANDOM 3 | ||
34 | .Os "OpenBSD 2.0" | ||
35 | .Sh NAME | ||
36 | .Nm arc4random, | ||
37 | .Nm arc4random_stir, | ||
38 | .Nm arc4random_addrandom | ||
39 | .Nd arc4 random number generator. | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <stdlib.h> | ||
42 | .Ft u_int32_t | ||
43 | .Fn arc4random "void" | ||
44 | .Ft void | ||
45 | .Fn arc4random_stir "void" | ||
46 | .Ft void | ||
47 | .Fn arc4random_addrandom "u_char *dat" "int datlen" | ||
48 | .Sh DESCRIPTION | ||
49 | The | ||
50 | .Fn arc4random | ||
51 | function uses the key stream generator employed by the | ||
52 | arc4 cipher, which uses 8*8 8 bit S-Boxes. The S-Boxes | ||
53 | can be in about | ||
54 | .if t 2\u\s71700\s10\d | ||
55 | .if n (2**1700) | ||
56 | states. | ||
57 | .Pp | ||
58 | The | ||
59 | .Fn arc4random_stir | ||
60 | function reads data from | ||
61 | .Pa /dev/arandom | ||
62 | and uses it to permutate the S-Boxes via | ||
63 | .Fn arc4random_addrandom . | ||
64 | .Pp | ||
65 | There is no need to call | ||
66 | .Fn arc4random_stir | ||
67 | before using | ||
68 | .Fn arc4random , | ||
69 | since | ||
70 | .Fn arc4random | ||
71 | automatically initalizes itself. | ||
72 | .Sh SEE ALSO | ||
73 | .Xr rand48 3 , | ||
74 | .Xr rand 3 , | ||
75 | .Xr random 3 | ||
76 | .Sh HISTORY | ||
77 | .Pa RC4 | ||
78 | has been designed by RSA Data Security, Inc. It was posted anonymously | ||
79 | to the USENET and was confirmed to be equivalent by several sources who | ||
80 | had access to the original cipher. Since | ||
81 | .Pa RC4 | ||
82 | used to be a trade secret, the cipher is now referred to as | ||
83 | .Pa ARC4 . | ||
diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c new file mode 100644 index 0000000000..5279c21518 --- /dev/null +++ b/src/lib/libc/crypt/arc4random.c | |||
@@ -0,0 +1,176 @@ | |||
1 | /* $OpenBSD: arc4random.c,v 1.3 1998/03/22 19:01:16 niklas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Arc4 random number generator for OpenBSD. | ||
5 | * Copyright 1996 David Mazieres <dm@lcs.mit.edu>. | ||
6 | * | ||
7 | * Modification and redistribution in source and binary forms is | ||
8 | * permitted provided that due credit is given to the author and the | ||
9 | * OpenBSD project (for instance by leaving this copyright notice | ||
10 | * intact). | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * This code is derived from section 17.1 of Applied Cryptography, | ||
15 | * second edition, which describes a stream cipher allegedly | ||
16 | * compatible with RSA Labs "RC4" cipher (the actual description of | ||
17 | * which is a trade secret). The same algorithm is used as a stream | ||
18 | * cipher called "arcfour" in Tatu Ylonen's ssh package. | ||
19 | * | ||
20 | * Here the stream cipher has been modified always to include the time | ||
21 | * when initializing the state. That makes it impossible to | ||
22 | * regenerate the same random sequence twice, so this can't be used | ||
23 | * for encryption, but will generate good random numbers. | ||
24 | * | ||
25 | * RC4 is a registered trademark of RSA Laboratories. | ||
26 | */ | ||
27 | |||
28 | #include <fcntl.h> | ||
29 | #include <stdlib.h> | ||
30 | #include <unistd.h> | ||
31 | #include <sys/types.h> | ||
32 | #include <sys/time.h> | ||
33 | |||
34 | #ifdef __GNUC__ | ||
35 | #define inline __inline | ||
36 | #else /* !__GNUC__ */ | ||
37 | #define inline | ||
38 | #endif /* !__GNUC__ */ | ||
39 | |||
40 | struct arc4_stream { | ||
41 | u_int8_t i; | ||
42 | u_int8_t j; | ||
43 | u_int8_t s[256]; | ||
44 | }; | ||
45 | |||
46 | int rs_initialized; | ||
47 | static struct arc4_stream rs; | ||
48 | |||
49 | static inline void | ||
50 | arc4_init(as) | ||
51 | struct arc4_stream *as; | ||
52 | { | ||
53 | int n; | ||
54 | |||
55 | for (n = 0; n < 256; n++) | ||
56 | as->s[n] = n; | ||
57 | as->i = 0; | ||
58 | as->j = 0; | ||
59 | } | ||
60 | |||
61 | static inline void | ||
62 | arc4_addrandom(as, dat, datlen) | ||
63 | struct arc4_stream *as; | ||
64 | u_char *dat; | ||
65 | int datlen; | ||
66 | { | ||
67 | int n; | ||
68 | u_int8_t si; | ||
69 | |||
70 | as->i--; | ||
71 | for (n = 0; n < 256; n++) { | ||
72 | as->i = (as->i + 1); | ||
73 | si = as->s[as->i]; | ||
74 | as->j = (as->j + si + dat[n % datlen]); | ||
75 | as->s[as->i] = as->s[as->j]; | ||
76 | as->s[as->j] = si; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | static void | ||
81 | arc4_stir(as) | ||
82 | struct arc4_stream *as; | ||
83 | { | ||
84 | int fd; | ||
85 | struct { | ||
86 | struct timeval tv; | ||
87 | u_int8_t rnd[128 - sizeof(struct timeval)]; | ||
88 | } rdat; | ||
89 | |||
90 | gettimeofday(&rdat.tv, NULL); | ||
91 | fd = open("/dev/arandom", O_RDONLY); | ||
92 | if (fd >= 0) { | ||
93 | read(fd, rdat.rnd, sizeof(rdat.rnd)); | ||
94 | close(fd); | ||
95 | } | ||
96 | /* fd < 0? Ah, what the heck. We'll just take whatever was on the | ||
97 | * stack... */ | ||
98 | |||
99 | arc4_addrandom(as, (void *) &rdat, sizeof(rdat)); | ||
100 | } | ||
101 | |||
102 | static inline u_int8_t | ||
103 | arc4_getbyte(as) | ||
104 | struct arc4_stream *as; | ||
105 | { | ||
106 | u_int8_t si, sj; | ||
107 | |||
108 | as->i = (as->i + 1); | ||
109 | si = as->s[as->i]; | ||
110 | as->j = (as->j + si); | ||
111 | sj = as->s[as->j]; | ||
112 | as->s[as->i] = sj; | ||
113 | as->s[as->j] = si; | ||
114 | return (as->s[(si + sj) & 0xff]); | ||
115 | } | ||
116 | |||
117 | static inline u_int32_t | ||
118 | arc4_getword(as) | ||
119 | struct arc4_stream *as; | ||
120 | { | ||
121 | u_int32_t val; | ||
122 | val = arc4_getbyte(as) << 24; | ||
123 | val |= arc4_getbyte(as) << 16; | ||
124 | val |= arc4_getbyte(as) << 8; | ||
125 | val |= arc4_getbyte(as); | ||
126 | return val; | ||
127 | } | ||
128 | |||
129 | void | ||
130 | arc4random_stir() | ||
131 | { | ||
132 | if (!rs_initialized) { | ||
133 | arc4_init(&rs); | ||
134 | rs_initialized = 1; | ||
135 | } | ||
136 | arc4_stir(&rs); | ||
137 | } | ||
138 | |||
139 | void | ||
140 | arc4random_addrandom(dat, datlen) | ||
141 | u_char *dat; | ||
142 | int datlen; | ||
143 | { | ||
144 | if (!rs_initialized) | ||
145 | arc4random_stir(); | ||
146 | arc4_addrandom(&rs, dat, datlen); | ||
147 | } | ||
148 | |||
149 | u_int32_t | ||
150 | arc4random() | ||
151 | { | ||
152 | if (!rs_initialized) | ||
153 | arc4random_stir(); | ||
154 | return arc4_getword(&rs); | ||
155 | } | ||
156 | |||
157 | #if 0 | ||
158 | /*-------- Test code for i386 --------*/ | ||
159 | #include <stdio.h> | ||
160 | #include <machine/pctr.h> | ||
161 | int | ||
162 | main(int argc, char **argv) | ||
163 | { | ||
164 | const int iter = 1000000; | ||
165 | int i; | ||
166 | pctrval v; | ||
167 | |||
168 | v = rdtsc(); | ||
169 | for (i = 0; i < iter; i++) | ||
170 | arc4random(); | ||
171 | v = rdtsc() - v; | ||
172 | v /= iter; | ||
173 | |||
174 | printf("%qd cycles\n", v); | ||
175 | } | ||
176 | #endif | ||
diff --git a/src/lib/libc/crypt/bcrypt.c b/src/lib/libc/crypt/bcrypt.c new file mode 100644 index 0000000000..1b121fb28f --- /dev/null +++ b/src/lib/libc/crypt/bcrypt.c | |||
@@ -0,0 +1,362 @@ | |||
1 | /* $OpenBSD: bcrypt.c,v 1.12 1998/08/10 18:33:07 provos Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. All advertising materials mentioning features or use of this software | ||
16 | * must display the following acknowledgement: | ||
17 | * This product includes software developed by Niels Provos. | ||
18 | * 4. The name of the author may not be used to endorse or promote products | ||
19 | * derived from this software without specific prior written permission. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
23 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
26 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
30 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | /* This password hashing algorithm was designed by David Mazieres | ||
34 | * <dm@lcs.mit.edu> and works as follows: | ||
35 | * | ||
36 | * 1. state := InitState () | ||
37 | * 2. state := ExpandKey (state, salt, password) 3. | ||
38 | * REPEAT rounds: | ||
39 | * state := ExpandKey (state, 0, salt) | ||
40 | * state := ExpandKey(state, 0, password) | ||
41 | * 4. ctext := "OrpheanBeholderScryDoubt" | ||
42 | * 5. REPEAT 64: | ||
43 | * ctext := Encrypt_ECB (state, ctext); | ||
44 | * 6. RETURN Concatenate (salt, ctext); | ||
45 | * | ||
46 | */ | ||
47 | |||
48 | #if 0 | ||
49 | #include <stdio.h> | ||
50 | #endif | ||
51 | |||
52 | #include <stdio.h> | ||
53 | #include <stdlib.h> | ||
54 | #include <sys/types.h> | ||
55 | #include <string.h> | ||
56 | #include <pwd.h> | ||
57 | #include <blf.h> | ||
58 | |||
59 | /* This implementation is adaptable to current computing power. | ||
60 | * You can have up to 2^31 rounds which should be enough for some | ||
61 | * time to come. | ||
62 | */ | ||
63 | |||
64 | #define BCRYPT_VERSION '2' | ||
65 | #define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */ | ||
66 | #define BCRYPT_BLOCKS 6 /* Ciphertext blocks */ | ||
67 | #define BCRYPT_MINROUNDS 16 /* we have log2(rounds) in salt */ | ||
68 | |||
69 | char *bcrypt_gensalt __P((u_int8_t)); | ||
70 | |||
71 | static void encode_salt __P((char *, u_int8_t *, u_int16_t, u_int8_t)); | ||
72 | static void encode_base64 __P((u_int8_t *, u_int8_t *, u_int16_t)); | ||
73 | static void decode_base64 __P((u_int8_t *, u_int16_t, u_int8_t *)); | ||
74 | |||
75 | static char encrypted[_PASSWORD_LEN]; | ||
76 | static char gsalt[BCRYPT_MAXSALT * 4 / 3 + 1]; | ||
77 | static char error[] = ":"; | ||
78 | |||
79 | const static u_int8_t Base64Code[] = | ||
80 | "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
81 | |||
82 | const static u_int8_t index_64[128] = | ||
83 | { | ||
84 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | ||
85 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | ||
86 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | ||
87 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | ||
88 | 255, 255, 255, 255, 255, 255, 0, 1, 54, 55, | ||
89 | 56, 57, 58, 59, 60, 61, 62, 63, 255, 255, | ||
90 | 255, 255, 255, 255, 255, 2, 3, 4, 5, 6, | ||
91 | 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, | ||
92 | 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, | ||
93 | 255, 255, 255, 255, 255, 255, 28, 29, 30, | ||
94 | 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, | ||
95 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, | ||
96 | 51, 52, 53, 255, 255, 255, 255, 255 | ||
97 | }; | ||
98 | #define CHAR64(c) ( (c) > 127 ? 255 : index_64[(c)]) | ||
99 | |||
100 | #ifdef __STDC__ | ||
101 | static void | ||
102 | decode_base64(u_int8_t *buffer, u_int16_t len, u_int8_t *data) | ||
103 | #else | ||
104 | static void | ||
105 | decode_base64(buffer, len, data) | ||
106 | u_int8_t *buffer; | ||
107 | u_int16_t len; | ||
108 | u_int8_t *data; | ||
109 | #endif | ||
110 | { | ||
111 | u_int8_t *bp = buffer; | ||
112 | u_int8_t *p = data; | ||
113 | u_int8_t c1, c2, c3, c4; | ||
114 | while (bp < buffer + len) { | ||
115 | c1 = CHAR64(*p); | ||
116 | c2 = CHAR64(*(p + 1)); | ||
117 | |||
118 | /* Invalid data */ | ||
119 | if (c1 == 255 || c2 == 255) | ||
120 | break; | ||
121 | |||
122 | *bp++ = (c1 << 2) | ((c2 & 0x30) >> 4); | ||
123 | if (bp >= buffer + len) | ||
124 | break; | ||
125 | |||
126 | c3 = CHAR64(*(p + 2)); | ||
127 | if (c3 == 255) | ||
128 | break; | ||
129 | |||
130 | *bp++ = ((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2); | ||
131 | if (bp >= buffer + len) | ||
132 | break; | ||
133 | |||
134 | c4 = CHAR64(*(p + 3)); | ||
135 | if (c4 == 255) | ||
136 | break; | ||
137 | *bp++ = ((c3 & 0x03) << 6) | c4; | ||
138 | |||
139 | p += 4; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | #ifdef __STDC__ | ||
144 | static void | ||
145 | encode_salt(char *salt, u_int8_t *csalt, u_int16_t clen, u_int8_t logr) | ||
146 | #else | ||
147 | static void | ||
148 | encode_salt(salt, csalt, clen, logr) | ||
149 | char *salt; | ||
150 | u_int8_t *csalt; | ||
151 | u_int16_t clen; | ||
152 | u_int8_t logr; | ||
153 | #endif | ||
154 | { | ||
155 | salt[0] = '$'; | ||
156 | salt[1] = BCRYPT_VERSION; | ||
157 | salt[2] = 'a'; | ||
158 | salt[3] = '$'; | ||
159 | |||
160 | snprintf(salt + 4, 4, "%2.2u$", logr); | ||
161 | |||
162 | encode_base64((u_int8_t *) salt + 7, csalt, clen); | ||
163 | } | ||
164 | /* Generates a salt for this version of crypt. | ||
165 | Since versions may change. Keeping this here | ||
166 | seems sensible. | ||
167 | */ | ||
168 | |||
169 | #ifdef __STDC__ | ||
170 | char * | ||
171 | bcrypt_gensalt(u_int8_t log_rounds) | ||
172 | #else | ||
173 | char * | ||
174 | bcrypt_gensalt(log_rounds) | ||
175 | u_int8_t log_rounds; | ||
176 | #endif | ||
177 | { | ||
178 | u_int8_t csalt[BCRYPT_MAXSALT]; | ||
179 | u_int16_t i; | ||
180 | u_int32_t seed = 0; | ||
181 | |||
182 | for (i = 0; i < BCRYPT_MAXSALT; i++) { | ||
183 | if (i % 4 == 0) | ||
184 | seed = arc4random(); | ||
185 | csalt[i] = seed & 0xff; | ||
186 | seed = seed >> 8; | ||
187 | } | ||
188 | |||
189 | if (log_rounds < 4) | ||
190 | log_rounds = 4; | ||
191 | |||
192 | encode_salt(gsalt, csalt, BCRYPT_MAXSALT, log_rounds); | ||
193 | return gsalt; | ||
194 | } | ||
195 | /* We handle $Vers$log2(NumRounds)$salt+passwd$ | ||
196 | i.e. $2$04$iwouldntknowwhattosayetKdJ6iFtacBqJdKe6aW7ou */ | ||
197 | |||
198 | char * | ||
199 | bcrypt(key, salt) | ||
200 | const char *key; | ||
201 | const char *salt; | ||
202 | { | ||
203 | blf_ctx state; | ||
204 | u_int32_t rounds, i, k; | ||
205 | u_int16_t j; | ||
206 | u_int8_t key_len, salt_len, logr, minor; | ||
207 | u_int8_t ciphertext[4 * BCRYPT_BLOCKS] = "OrpheanBeholderScryDoubt"; | ||
208 | u_int8_t csalt[BCRYPT_MAXSALT]; | ||
209 | u_int32_t cdata[BCRYPT_BLOCKS]; | ||
210 | |||
211 | /* Discard "$" identifier */ | ||
212 | salt++; | ||
213 | |||
214 | if (*salt > BCRYPT_VERSION) { | ||
215 | /* How do I handle errors ? Return ':' */ | ||
216 | return error; | ||
217 | } | ||
218 | |||
219 | /* Check for minor versions */ | ||
220 | if (salt[1] != '$') { | ||
221 | switch (salt[1]) { | ||
222 | case 'a': | ||
223 | /* 'ab' should not yield the same as 'abab' */ | ||
224 | minor = salt[1]; | ||
225 | salt++; | ||
226 | break; | ||
227 | default: | ||
228 | return error; | ||
229 | } | ||
230 | } else | ||
231 | minor = 0; | ||
232 | |||
233 | /* Discard version + "$" identifier */ | ||
234 | salt += 2; | ||
235 | |||
236 | if (salt[2] != '$') | ||
237 | /* Out of sync with passwd entry */ | ||
238 | return error; | ||
239 | |||
240 | /* Computer power doesnt increase linear, 2^x should be fine */ | ||
241 | if ((rounds = (u_int32_t) 1 << (logr = atoi(salt))) < BCRYPT_MINROUNDS) | ||
242 | return error; | ||
243 | |||
244 | /* Discard num rounds + "$" identifier */ | ||
245 | salt += 3; | ||
246 | |||
247 | /* We dont want the base64 salt but the raw data */ | ||
248 | decode_base64(csalt, BCRYPT_MAXSALT, (u_int8_t *) salt); | ||
249 | salt_len = BCRYPT_MAXSALT; | ||
250 | key_len = strlen(key) + (minor >= 'a' ? 1 : 0); | ||
251 | |||
252 | /* Setting up S-Boxes and Subkeys */ | ||
253 | Blowfish_initstate(&state); | ||
254 | Blowfish_expandstate(&state, csalt, salt_len, | ||
255 | (u_int8_t *) key, key_len); | ||
256 | for (k = 0; k < rounds; k++) { | ||
257 | Blowfish_expand0state(&state, (u_int8_t *) key, key_len); | ||
258 | Blowfish_expand0state(&state, csalt, salt_len); | ||
259 | } | ||
260 | |||
261 | /* This can be precomputed later */ | ||
262 | j = 0; | ||
263 | for (i = 0; i < BCRYPT_BLOCKS; i++) | ||
264 | cdata[i] = Blowfish_stream2word(ciphertext, 4 * BCRYPT_BLOCKS, &j); | ||
265 | |||
266 | /* Now do the encryption */ | ||
267 | for (k = 0; k < 64; k++) | ||
268 | blf_enc(&state, cdata, BCRYPT_BLOCKS / 2); | ||
269 | |||
270 | for (i = 0; i < BCRYPT_BLOCKS; i++) { | ||
271 | ciphertext[4 * i + 3] = cdata[i] & 0xff; | ||
272 | cdata[i] = cdata[i] >> 8; | ||
273 | ciphertext[4 * i + 2] = cdata[i] & 0xff; | ||
274 | cdata[i] = cdata[i] >> 8; | ||
275 | ciphertext[4 * i + 1] = cdata[i] & 0xff; | ||
276 | cdata[i] = cdata[i] >> 8; | ||
277 | ciphertext[4 * i + 0] = cdata[i] & 0xff; | ||
278 | } | ||
279 | |||
280 | |||
281 | i = 0; | ||
282 | encrypted[i++] = '$'; | ||
283 | encrypted[i++] = BCRYPT_VERSION; | ||
284 | if (minor) | ||
285 | encrypted[i++] = minor; | ||
286 | encrypted[i++] = '$'; | ||
287 | |||
288 | snprintf(encrypted + i, 4, "%2.2u$", logr); | ||
289 | |||
290 | encode_base64((u_int8_t *) encrypted + i + 3, csalt, BCRYPT_MAXSALT); | ||
291 | encode_base64((u_int8_t *) encrypted + strlen(encrypted), ciphertext, | ||
292 | 4 * BCRYPT_BLOCKS - 1); | ||
293 | return encrypted; | ||
294 | } | ||
295 | |||
296 | #ifdef __STDC__ | ||
297 | static void | ||
298 | encode_base64(u_int8_t *buffer, u_int8_t *data, u_int16_t len) | ||
299 | #else | ||
300 | static void | ||
301 | encode_base64(buffer, data, len) | ||
302 | u_int8_t *buffer; | ||
303 | u_int8_t *data; | ||
304 | u_int16_t len; | ||
305 | #endif | ||
306 | { | ||
307 | u_int8_t *bp = buffer; | ||
308 | u_int8_t *p = data; | ||
309 | u_int8_t c1, c2; | ||
310 | while (p < data + len) { | ||
311 | c1 = *p++; | ||
312 | *bp++ = Base64Code[(c1 >> 2)]; | ||
313 | c1 = (c1 & 0x03) << 4; | ||
314 | if (p >= data + len) { | ||
315 | *bp++ = Base64Code[c1]; | ||
316 | break; | ||
317 | } | ||
318 | c2 = *p++; | ||
319 | c1 |= (c2 >> 4) & 0x0f; | ||
320 | *bp++ = Base64Code[c1]; | ||
321 | c1 = (c2 & 0x0f) << 2; | ||
322 | if (p >= data + len) { | ||
323 | *bp++ = Base64Code[c1]; | ||
324 | break; | ||
325 | } | ||
326 | c2 = *p++; | ||
327 | c1 |= (c2 >> 6) & 0x03; | ||
328 | *bp++ = Base64Code[c1]; | ||
329 | *bp++ = Base64Code[c2 & 0x3f]; | ||
330 | } | ||
331 | *bp = '\0'; | ||
332 | } | ||
333 | #if 0 | ||
334 | void | ||
335 | main() | ||
336 | { | ||
337 | char blubber[73]; | ||
338 | char salt[100]; | ||
339 | char *p; | ||
340 | salt[0] = '$'; | ||
341 | salt[1] = BCRYPT_VERSION; | ||
342 | salt[2] = '$'; | ||
343 | |||
344 | snprintf(salt + 3, 4, "%2.2u$", 5); | ||
345 | |||
346 | printf("24 bytes of salt: "); | ||
347 | fgets(salt + 6, 94, stdin); | ||
348 | salt[99] = 0; | ||
349 | printf("72 bytes of password: "); | ||
350 | fpurge(stdin); | ||
351 | fgets(blubber, 73, stdin); | ||
352 | blubber[72] = 0; | ||
353 | |||
354 | p = crypt(blubber, salt); | ||
355 | printf("Passwd entry: %s\n\n", p); | ||
356 | |||
357 | p = bcrypt_gensalt(5); | ||
358 | printf("Generated salt: %s\n", p); | ||
359 | p = crypt(blubber, p); | ||
360 | printf("Passwd entry: %s\n", p); | ||
361 | } | ||
362 | #endif | ||
diff --git a/src/lib/libc/crypt/blowfish.3 b/src/lib/libc/crypt/blowfish.3 new file mode 100644 index 0000000000..02a1ef8738 --- /dev/null +++ b/src/lib/libc/crypt/blowfish.3 | |||
@@ -0,0 +1,104 @@ | |||
1 | .\" $OpenBSD: blowfish.3,v 1.2 1998/08/10 18:40:58 provos Exp $ | ||
2 | .\" Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | ||
3 | .\" All rights reserved. | ||
4 | .\" | ||
5 | .\" Redistribution and use in source and binary forms, with or without | ||
6 | .\" modification, are permitted provided that the following conditions | ||
7 | .\" are met: | ||
8 | .\" 1. Redistributions of source code must retain the above copyright | ||
9 | .\" notice, this list of conditions and the following disclaimer. | ||
10 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
11 | .\" notice, this list of conditions and the following disclaimer in the | ||
12 | .\" documentation and/or other materials provided with the distribution. | ||
13 | .\" 3. All advertising materials mentioning features or use of this software | ||
14 | .\" must display the following acknowledgement: | ||
15 | .\" This product includes software developed by Niels Provos. | ||
16 | .\" 4. The name of the author may not be used to endorse or promote products | ||
17 | .\" derived from this software without specific prior written permission. | ||
18 | .\" | ||
19 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
20 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
21 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
22 | .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
23 | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
24 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
25 | .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
26 | .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
27 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
28 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | .\" | ||
30 | .\" Manual page, using -mandoc macros | ||
31 | .\" | ||
32 | .Dd February 13, 1997 | ||
33 | .Dt BLOWFISH 3 | ||
34 | .Os "OpenBSD 2.0" | ||
35 | .Sh NAME | ||
36 | .Nm blf_key, | ||
37 | .Nm blf_enc, | ||
38 | .Nm blf_dec | ||
39 | .Nd Blowfish encryption | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <blf.h> | ||
42 | .Ft void | ||
43 | .Fn blf_key "blf_ctx *state" "const u_int8_t *key" "u_int16_t keylen" | ||
44 | .Ft void | ||
45 | .Fn blf_enc "blf_ctx *state" "u_int32_t *data" "u_int16_t datalen" | ||
46 | .Ft void | ||
47 | .Fn blf_dec "blf_ctx *state" "u_int32_t *data" "u_int16_t datalen" | ||
48 | .Ft void | ||
49 | .Fn blf_ecb_encrypt "blf_ctx *state" "u_int8_t *data" "u_int32_t datalen" | ||
50 | .Ft void | ||
51 | .Fn blf_ecb_decrypt "blf_ctx *state" "u_int8_t *data" "u_int32_t datalen" | ||
52 | .Ft void | ||
53 | .Fn blf_cbc_encrypt "blf_ctx *state" "u_int8_t *iv" "u_int8_t *data" "u_int32_t datalen" | ||
54 | .Ft void | ||
55 | .Fn blf_cbc_decrypt "blf_ctx *state" "u_int8_t *iv" "u_int8_t *data" "u_int32_t datalen" | ||
56 | .Sh DESCRIPTION | ||
57 | .Pa Blowfish | ||
58 | is a fast unpatented block cipher designed by Bruce Schneier. | ||
59 | It basically consists of a 16 times iterated Feistel network. | ||
60 | The block size is 64 bit and the key size is maximal 448 bit. | ||
61 | .Pp | ||
62 | The | ||
63 | .Fn blf_key | ||
64 | function initializes the 4 8bit S-boxes and the 18 Subkeys with | ||
65 | the hexadecimal digits of Pi. The key is used for further randomization. | ||
66 | The first argument to | ||
67 | .Fn blf_enc | ||
68 | is the initalized state derived from | ||
69 | .Fn blf_key . | ||
70 | The stream of 32-bit words is encrypted in Electronic Codebook | ||
71 | Mode (ECB) and | ||
72 | .Pa datalen | ||
73 | must be even. | ||
74 | .Fn blf_dec | ||
75 | is used for decrypting Blowfish encrypted blocks. | ||
76 | .Pp | ||
77 | The functions | ||
78 | .Fn blf_ecb_encrypt | ||
79 | and | ||
80 | .Fn blf_ecb_decrypt | ||
81 | are used for encrypting and decrypting octet streams in ECB mode. | ||
82 | The functions | ||
83 | .Fn blf_cbc_encrypt | ||
84 | and | ||
85 | .Fn blf_cbc_decrypt | ||
86 | are used for encrypting and decrypting octet streams in | ||
87 | Cipherblock Chaining Mode (CBC). | ||
88 | .Pp | ||
89 | The functions | ||
90 | .Fn Blowfish_initstate , | ||
91 | .Fn Blowfish_expand0state , | ||
92 | .Fn Blowfish_expandstate , | ||
93 | .Fn Blowfish_encipher | ||
94 | and | ||
95 | .Fn Blowfish_decipher | ||
96 | are used for customization of the | ||
97 | .Pa Blowfish | ||
98 | cipher, e.g. for the blowfish password hashing function. | ||
99 | .Sh SEE ALSO | ||
100 | .Xr crypt 3 , | ||
101 | .Xr passwd 1 , | ||
102 | .Xr passwd 5 | ||
103 | .Sh AUTHOR | ||
104 | Niels Provos <provos@physnet.uni-hamburg.de> | ||
diff --git a/src/lib/libc/crypt/blowfish.c b/src/lib/libc/crypt/blowfish.c new file mode 100644 index 0000000000..6cddbc64b3 --- /dev/null +++ b/src/lib/libc/crypt/blowfish.c | |||
@@ -0,0 +1,774 @@ | |||
1 | /* $OpenBSD: blowfish.c,v 1.12 1998/08/30 22:35:39 niklas Exp $ */ | ||
2 | /* | ||
3 | * Blowfish block cipher for OpenBSD | ||
4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Implementation advice by David Mazieres <dm@lcs.mit.edu>. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * 2. Redistributions in binary form must reproduce the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer in the | ||
16 | * documentation and/or other materials provided with the distribution. | ||
17 | * 3. All advertising materials mentioning features or use of this software | ||
18 | * must display the following acknowledgement: | ||
19 | * This product includes software developed by Niels Provos. | ||
20 | * 4. The name of the author may not be used to endorse or promote products | ||
21 | * derived from this software without specific prior written permission. | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | /* | ||
36 | * This code is derived from section 14.3 and the given source | ||
37 | * in section V of Applied Cryptography, second edition. | ||
38 | * Blowfish is an unpatented fast block cipher designed by | ||
39 | * Bruce Schneier. | ||
40 | */ | ||
41 | |||
42 | #if 0 | ||
43 | #include <stdio.h> /* used for debugging */ | ||
44 | #include <string.h> | ||
45 | #endif | ||
46 | |||
47 | #include <sys/types.h> | ||
48 | #include <blf.h> | ||
49 | |||
50 | #undef inline | ||
51 | #ifdef __GNUC__ | ||
52 | #define inline __inline | ||
53 | #else /* !__GNUC__ */ | ||
54 | #define inline | ||
55 | #endif /* !__GNUC__ */ | ||
56 | |||
57 | /* Function for Feistel Networks */ | ||
58 | |||
59 | #define F(bc, x) ((((bc)->S[0][((x) & 0xFF000000) >> 24] \ | ||
60 | + (bc)->S[1][((x) &0xFF0000 ) >> 16]) \ | ||
61 | ^ (bc)->S[2][((x) & 0xFF00) >> 8]) \ | ||
62 | + (bc)->S[3][(x) & 0x00FF]) | ||
63 | |||
64 | #define BLFRND(bc,i,j,n) (i ^= F(bc,j) ^ (bc)->P[n]) | ||
65 | |||
66 | void | ||
67 | Blowfish_encipher(c, xl, xr) | ||
68 | blf_ctx *c; | ||
69 | u_int32_t *xl; | ||
70 | u_int32_t *xr; | ||
71 | { | ||
72 | u_int32_t Xl; | ||
73 | u_int32_t Xr; | ||
74 | |||
75 | Xl = *xl; | ||
76 | Xr = *xr; | ||
77 | |||
78 | Xl ^= c->P[0]; | ||
79 | BLFRND(c, Xr, Xl, 1); BLFRND(c, Xl, Xr, 2); | ||
80 | BLFRND(c, Xr, Xl, 3); BLFRND(c, Xl, Xr, 4); | ||
81 | BLFRND(c, Xr, Xl, 5); BLFRND(c, Xl, Xr, 6); | ||
82 | BLFRND(c, Xr, Xl, 7); BLFRND(c, Xl, Xr, 8); | ||
83 | BLFRND(c, Xr, Xl, 9); BLFRND(c, Xl, Xr, 10); | ||
84 | BLFRND(c, Xr, Xl, 11); BLFRND(c, Xl, Xr, 12); | ||
85 | BLFRND(c, Xr, Xl, 13); BLFRND(c, Xl, Xr, 14); | ||
86 | BLFRND(c, Xr, Xl, 15); BLFRND(c, Xl, Xr, 16); | ||
87 | |||
88 | *xl = Xr ^ c->P[17]; | ||
89 | *xr = Xl; | ||
90 | } | ||
91 | |||
92 | void | ||
93 | Blowfish_decipher(c, xl, xr) | ||
94 | blf_ctx *c; | ||
95 | u_int32_t *xl; | ||
96 | u_int32_t *xr; | ||
97 | { | ||
98 | u_int32_t Xl; | ||
99 | u_int32_t Xr; | ||
100 | |||
101 | Xl = *xl; | ||
102 | Xr = *xr; | ||
103 | |||
104 | Xl ^= c->P[17]; | ||
105 | BLFRND(c, Xr, Xl, 16); BLFRND(c, Xl, Xr, 15); | ||
106 | BLFRND(c, Xr, Xl, 14); BLFRND(c, Xl, Xr, 13); | ||
107 | BLFRND(c, Xr, Xl, 12); BLFRND(c, Xl, Xr, 11); | ||
108 | BLFRND(c, Xr, Xl, 10); BLFRND(c, Xl, Xr, 9); | ||
109 | BLFRND(c, Xr, Xl, 8); BLFRND(c, Xl, Xr, 7); | ||
110 | BLFRND(c, Xr, Xl, 6); BLFRND(c, Xl, Xr, 5); | ||
111 | BLFRND(c, Xr, Xl, 4); BLFRND(c, Xl, Xr, 3); | ||
112 | BLFRND(c, Xr, Xl, 2); BLFRND(c, Xl, Xr, 1); | ||
113 | |||
114 | *xl = Xr ^ c->P[0]; | ||
115 | *xr = Xl; | ||
116 | } | ||
117 | |||
118 | void | ||
119 | Blowfish_initstate(c) | ||
120 | blf_ctx *c; | ||
121 | { | ||
122 | |||
123 | /* P-box and S-box tables initialized with digits of Pi */ | ||
124 | |||
125 | const blf_ctx initstate = | ||
126 | |||
127 | { { | ||
128 | { | ||
129 | 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, | ||
130 | 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, | ||
131 | 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, | ||
132 | 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, | ||
133 | 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, | ||
134 | 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, | ||
135 | 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, | ||
136 | 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, | ||
137 | 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, | ||
138 | 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, | ||
139 | 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, | ||
140 | 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, | ||
141 | 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, | ||
142 | 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, | ||
143 | 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, | ||
144 | 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, | ||
145 | 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, | ||
146 | 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, | ||
147 | 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, | ||
148 | 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, | ||
149 | 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, | ||
150 | 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, | ||
151 | 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, | ||
152 | 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, | ||
153 | 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, | ||
154 | 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, | ||
155 | 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, | ||
156 | 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, | ||
157 | 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, | ||
158 | 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, | ||
159 | 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, | ||
160 | 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, | ||
161 | 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, | ||
162 | 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, | ||
163 | 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, | ||
164 | 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, | ||
165 | 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, | ||
166 | 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, | ||
167 | 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, | ||
168 | 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, | ||
169 | 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, | ||
170 | 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, | ||
171 | 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, | ||
172 | 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, | ||
173 | 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, | ||
174 | 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, | ||
175 | 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, | ||
176 | 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, | ||
177 | 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, | ||
178 | 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, | ||
179 | 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, | ||
180 | 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, | ||
181 | 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, | ||
182 | 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, | ||
183 | 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, | ||
184 | 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, | ||
185 | 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, | ||
186 | 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, | ||
187 | 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, | ||
188 | 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, | ||
189 | 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, | ||
190 | 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, | ||
191 | 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, | ||
192 | 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a}, | ||
193 | { | ||
194 | 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, | ||
195 | 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, | ||
196 | 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, | ||
197 | 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, | ||
198 | 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, | ||
199 | 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, | ||
200 | 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, | ||
201 | 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, | ||
202 | 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, | ||
203 | 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, | ||
204 | 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, | ||
205 | 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, | ||
206 | 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, | ||
207 | 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, | ||
208 | 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, | ||
209 | 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, | ||
210 | 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, | ||
211 | 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, | ||
212 | 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, | ||
213 | 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, | ||
214 | 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, | ||
215 | 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, | ||
216 | 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, | ||
217 | 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, | ||
218 | 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, | ||
219 | 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, | ||
220 | 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, | ||
221 | 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, | ||
222 | 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, | ||
223 | 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, | ||
224 | 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, | ||
225 | 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, | ||
226 | 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, | ||
227 | 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, | ||
228 | 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, | ||
229 | 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, | ||
230 | 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, | ||
231 | 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, | ||
232 | 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, | ||
233 | 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, | ||
234 | 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, | ||
235 | 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, | ||
236 | 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, | ||
237 | 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, | ||
238 | 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, | ||
239 | 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, | ||
240 | 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, | ||
241 | 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, | ||
242 | 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, | ||
243 | 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, | ||
244 | 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, | ||
245 | 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, | ||
246 | 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, | ||
247 | 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, | ||
248 | 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, | ||
249 | 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, | ||
250 | 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, | ||
251 | 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, | ||
252 | 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, | ||
253 | 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, | ||
254 | 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, | ||
255 | 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, | ||
256 | 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, | ||
257 | 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7}, | ||
258 | { | ||
259 | 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, | ||
260 | 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, | ||
261 | 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, | ||
262 | 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, | ||
263 | 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, | ||
264 | 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, | ||
265 | 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, | ||
266 | 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, | ||
267 | 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, | ||
268 | 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, | ||
269 | 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, | ||
270 | 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, | ||
271 | 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, | ||
272 | 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, | ||
273 | 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, | ||
274 | 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, | ||
275 | 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, | ||
276 | 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, | ||
277 | 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, | ||
278 | 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, | ||
279 | 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, | ||
280 | 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, | ||
281 | 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, | ||
282 | 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, | ||
283 | 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, | ||
284 | 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, | ||
285 | 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, | ||
286 | 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, | ||
287 | 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, | ||
288 | 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, | ||
289 | 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, | ||
290 | 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, | ||
291 | 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, | ||
292 | 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, | ||
293 | 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, | ||
294 | 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, | ||
295 | 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, | ||
296 | 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, | ||
297 | 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, | ||
298 | 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, | ||
299 | 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, | ||
300 | 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, | ||
301 | 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, | ||
302 | 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, | ||
303 | 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, | ||
304 | 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, | ||
305 | 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, | ||
306 | 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, | ||
307 | 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, | ||
308 | 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, | ||
309 | 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, | ||
310 | 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, | ||
311 | 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, | ||
312 | 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, | ||
313 | 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, | ||
314 | 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, | ||
315 | 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, | ||
316 | 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, | ||
317 | 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, | ||
318 | 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, | ||
319 | 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, | ||
320 | 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, | ||
321 | 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, | ||
322 | 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0}, | ||
323 | { | ||
324 | 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, | ||
325 | 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, | ||
326 | 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, | ||
327 | 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, | ||
328 | 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, | ||
329 | 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, | ||
330 | 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, | ||
331 | 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, | ||
332 | 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, | ||
333 | 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, | ||
334 | 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, | ||
335 | 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, | ||
336 | 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, | ||
337 | 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, | ||
338 | 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, | ||
339 | 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, | ||
340 | 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, | ||
341 | 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, | ||
342 | 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, | ||
343 | 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, | ||
344 | 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, | ||
345 | 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, | ||
346 | 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, | ||
347 | 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, | ||
348 | 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, | ||
349 | 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, | ||
350 | 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, | ||
351 | 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, | ||
352 | 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, | ||
353 | 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, | ||
354 | 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, | ||
355 | 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, | ||
356 | 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, | ||
357 | 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, | ||
358 | 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, | ||
359 | 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, | ||
360 | 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, | ||
361 | 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, | ||
362 | 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, | ||
363 | 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, | ||
364 | 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, | ||
365 | 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, | ||
366 | 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, | ||
367 | 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, | ||
368 | 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, | ||
369 | 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, | ||
370 | 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, | ||
371 | 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, | ||
372 | 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, | ||
373 | 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, | ||
374 | 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, | ||
375 | 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, | ||
376 | 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, | ||
377 | 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, | ||
378 | 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, | ||
379 | 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, | ||
380 | 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, | ||
381 | 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, | ||
382 | 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, | ||
383 | 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, | ||
384 | 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, | ||
385 | 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, | ||
386 | 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, | ||
387 | 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6} | ||
388 | }, | ||
389 | { | ||
390 | 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, | ||
391 | 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, | ||
392 | 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, | ||
393 | 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, | ||
394 | 0x9216d5d9, 0x8979fb1b | ||
395 | } }; | ||
396 | |||
397 | *c = initstate; | ||
398 | |||
399 | } | ||
400 | |||
401 | #ifdef __STDC__ | ||
402 | u_int32_t | ||
403 | Blowfish_stream2word(const u_int8_t *data, u_int16_t databytes, u_int16_t *current) | ||
404 | #else | ||
405 | u_int32_t | ||
406 | Blowfish_stream2word(data, databytes, current) | ||
407 | const u_int8_t *data; | ||
408 | u_int16_t databytes; | ||
409 | u_int16_t *current; | ||
410 | #endif | ||
411 | { | ||
412 | u_int8_t i; | ||
413 | u_int16_t j; | ||
414 | u_int32_t temp; | ||
415 | |||
416 | temp = 0x00000000; | ||
417 | j = *current; | ||
418 | |||
419 | for (i = 0; i < 4; i++, j++) { | ||
420 | if (j >= databytes) | ||
421 | j = 0; | ||
422 | temp = (temp << 8) | data[j]; | ||
423 | } | ||
424 | |||
425 | *current = j; | ||
426 | return temp; | ||
427 | } | ||
428 | |||
429 | #if __STDC__ | ||
430 | void | ||
431 | Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes) | ||
432 | #else | ||
433 | void | ||
434 | Blowfish_expand0state(c, key, keybytes) | ||
435 | blf_ctx *c; | ||
436 | const u_int8_t *key; | ||
437 | u_int16_t keybytes; | ||
438 | #endif | ||
439 | { | ||
440 | u_int16_t i; | ||
441 | u_int16_t j; | ||
442 | u_int16_t k; | ||
443 | u_int32_t temp; | ||
444 | u_int32_t datal; | ||
445 | u_int32_t datar; | ||
446 | |||
447 | j = 0; | ||
448 | for (i = 0; i < BLF_N + 2; i++) { | ||
449 | /* Extract 4 int8 to 1 int32 from keystream */ | ||
450 | temp = Blowfish_stream2word(key, keybytes, &j); | ||
451 | c->P[i] = c->P[i] ^ temp; | ||
452 | } | ||
453 | |||
454 | j = 0; | ||
455 | datal = 0x00000000; | ||
456 | datar = 0x00000000; | ||
457 | for (i = 0; i < BLF_N + 2; i += 2) { | ||
458 | Blowfish_encipher(c, &datal, &datar); | ||
459 | |||
460 | c->P[i] = datal; | ||
461 | c->P[i + 1] = datar; | ||
462 | } | ||
463 | |||
464 | for (i = 0; i < 4; i++) { | ||
465 | for (k = 0; k < 256; k += 2) { | ||
466 | Blowfish_encipher(c, &datal, &datar); | ||
467 | |||
468 | c->S[i][k] = datal; | ||
469 | c->S[i][k + 1] = datar; | ||
470 | } | ||
471 | } | ||
472 | } | ||
473 | |||
474 | |||
475 | #if __STDC__ | ||
476 | void | ||
477 | Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes, | ||
478 | const u_int8_t *key, u_int16_t keybytes) | ||
479 | #else | ||
480 | void | ||
481 | Blowfish_expandstate(c, data, databytes, key, keybytes) | ||
482 | blf_ctx *c; | ||
483 | const u_int8_t *data; | ||
484 | u_int16_t databytes; | ||
485 | const u_int8_t *key; | ||
486 | u_int16_t keybytes; | ||
487 | #endif | ||
488 | { | ||
489 | u_int16_t i; | ||
490 | u_int16_t j; | ||
491 | u_int16_t k; | ||
492 | u_int32_t temp; | ||
493 | u_int32_t datal; | ||
494 | u_int32_t datar; | ||
495 | |||
496 | j = 0; | ||
497 | for (i = 0; i < BLF_N + 2; i++) { | ||
498 | /* Extract 4 int8 to 1 int32 from keystream */ | ||
499 | temp = Blowfish_stream2word(key, keybytes, &j); | ||
500 | c->P[i] = c->P[i] ^ temp; | ||
501 | } | ||
502 | |||
503 | j = 0; | ||
504 | datal = 0x00000000; | ||
505 | datar = 0x00000000; | ||
506 | for (i = 0; i < BLF_N + 2; i += 2) { | ||
507 | datal ^= Blowfish_stream2word(data, databytes, &j); | ||
508 | datar ^= Blowfish_stream2word(data, databytes, &j); | ||
509 | Blowfish_encipher(c, &datal, &datar); | ||
510 | |||
511 | c->P[i] = datal; | ||
512 | c->P[i + 1] = datar; | ||
513 | } | ||
514 | |||
515 | for (i = 0; i < 4; i++) { | ||
516 | for (k = 0; k < 256; k += 2) { | ||
517 | datal ^= Blowfish_stream2word(data, databytes, &j); | ||
518 | datar ^= Blowfish_stream2word(data, databytes, &j); | ||
519 | Blowfish_encipher(c, &datal, &datar); | ||
520 | |||
521 | c->S[i][k] = datal; | ||
522 | c->S[i][k + 1] = datar; | ||
523 | } | ||
524 | } | ||
525 | |||
526 | } | ||
527 | |||
528 | #if __STDC__ | ||
529 | void | ||
530 | blf_key(blf_ctx *c, const u_int8_t *k, u_int16_t len) | ||
531 | #else | ||
532 | void | ||
533 | blf_key(c, k, len) | ||
534 | blf_ctx *c; | ||
535 | const u_int8_t *k; | ||
536 | u_int16_t len; | ||
537 | #endif | ||
538 | { | ||
539 | /* Initalize S-boxes and subkeys with Pi */ | ||
540 | Blowfish_initstate(c); | ||
541 | |||
542 | /* Transform S-boxes and subkeys with key */ | ||
543 | Blowfish_expand0state(c, k, len); | ||
544 | } | ||
545 | |||
546 | #if __STDC__ | ||
547 | void | ||
548 | blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks) | ||
549 | #else | ||
550 | void | ||
551 | blf_enc(c, data, blocks) | ||
552 | blf_ctx *c; | ||
553 | u_int32_t *data; | ||
554 | u_int16_t blocks; | ||
555 | #endif | ||
556 | { | ||
557 | u_int32_t *d; | ||
558 | u_int16_t i; | ||
559 | |||
560 | d = data; | ||
561 | for (i = 0; i < blocks; i++) { | ||
562 | Blowfish_encipher(c, d, d + 1); | ||
563 | d += 2; | ||
564 | } | ||
565 | } | ||
566 | |||
567 | #if __STDC__ | ||
568 | void | ||
569 | blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks) | ||
570 | #else | ||
571 | void | ||
572 | blf_dec(c, data, blocks) | ||
573 | blf_ctx *c; | ||
574 | u_int32_t *data; | ||
575 | u_int16_t blocks; | ||
576 | #endif | ||
577 | { | ||
578 | u_int32_t *d; | ||
579 | u_int16_t i; | ||
580 | |||
581 | d = data; | ||
582 | for (i = 0; i < blocks; i++) { | ||
583 | Blowfish_decipher(c, d, d + 1); | ||
584 | d += 2; | ||
585 | } | ||
586 | } | ||
587 | |||
588 | #if __STDC__ | ||
589 | void | ||
590 | blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len) | ||
591 | #else | ||
592 | void | ||
593 | blf_ecb_encrypt(c, data, len) | ||
594 | blf_ctx *c; | ||
595 | u_int8_t *data; | ||
596 | u_int32_t len; | ||
597 | #endif | ||
598 | { | ||
599 | u_int32_t l, r; | ||
600 | u_int32_t i; | ||
601 | |||
602 | for (i = 0; i < len; i += 8) { | ||
603 | l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; | ||
604 | r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; | ||
605 | Blowfish_encipher(c, &l, &r); | ||
606 | data[0] = l >> 24 & 0xff; | ||
607 | data[1] = l >> 16 & 0xff; | ||
608 | data[2] = l >> 8 & 0xff; | ||
609 | data[3] = l & 0xff; | ||
610 | data[4] = r >> 24 & 0xff; | ||
611 | data[5] = r >> 16 & 0xff; | ||
612 | data[6] = r >> 8 & 0xff; | ||
613 | data[7] = r & 0xff; | ||
614 | data += 8; | ||
615 | } | ||
616 | } | ||
617 | |||
618 | #if __STDC__ | ||
619 | void | ||
620 | blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len) | ||
621 | #else | ||
622 | void | ||
623 | blf_ecb_decrypt(c, data, len) | ||
624 | blf_ctx *c; | ||
625 | u_int8_t *data; | ||
626 | u_int32_t len; | ||
627 | #endif | ||
628 | { | ||
629 | u_int32_t l, r; | ||
630 | u_int32_t i; | ||
631 | |||
632 | for (i = 0; i < len; i += 8) { | ||
633 | l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; | ||
634 | r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; | ||
635 | Blowfish_decipher(c, &l, &r); | ||
636 | data[0] = l >> 24 & 0xff; | ||
637 | data[1] = l >> 16 & 0xff; | ||
638 | data[2] = l >> 8 & 0xff; | ||
639 | data[3] = l & 0xff; | ||
640 | data[4] = r >> 24 & 0xff; | ||
641 | data[5] = r >> 16 & 0xff; | ||
642 | data[6] = r >> 8 & 0xff; | ||
643 | data[7] = r & 0xff; | ||
644 | data += 8; | ||
645 | } | ||
646 | } | ||
647 | |||
648 | #if __STDC__ | ||
649 | void | ||
650 | blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len) | ||
651 | #else | ||
652 | void | ||
653 | blf_cbc_encrypt(c, iv, data, len) | ||
654 | blf_ctx *c; | ||
655 | u_int8_t *iv; | ||
656 | u_int8_t *data; | ||
657 | u_int32_t len; | ||
658 | #endif | ||
659 | { | ||
660 | u_int32_t l, r; | ||
661 | u_int32_t i, j; | ||
662 | |||
663 | for (i = 0; i < len; i += 8) { | ||
664 | for (j = 0; j < 8; j++) | ||
665 | data[j] ^= iv[j]; | ||
666 | l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; | ||
667 | r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; | ||
668 | Blowfish_encipher(c, &l, &r); | ||
669 | data[0] = l >> 24 & 0xff; | ||
670 | data[1] = l >> 16 & 0xff; | ||
671 | data[2] = l >> 8 & 0xff; | ||
672 | data[3] = l & 0xff; | ||
673 | data[4] = r >> 24 & 0xff; | ||
674 | data[5] = r >> 16 & 0xff; | ||
675 | data[6] = r >> 8 & 0xff; | ||
676 | data[7] = r & 0xff; | ||
677 | iv = data; | ||
678 | data += 8; | ||
679 | } | ||
680 | } | ||
681 | |||
682 | #if __STDC__ | ||
683 | void | ||
684 | blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len) | ||
685 | #else | ||
686 | void | ||
687 | blf_cbc_decrypt(c, iva, data, len) | ||
688 | blf_ctx *c; | ||
689 | u_int8_t *iva; | ||
690 | u_int8_t *data; | ||
691 | u_int32_t len; | ||
692 | #endif | ||
693 | { | ||
694 | u_int32_t l, r; | ||
695 | u_int8_t *iv; | ||
696 | u_int32_t i, j; | ||
697 | |||
698 | iv = data + len - 16; | ||
699 | data = data + len - 8; | ||
700 | for (i = len - 8; i >= 8; i -= 8) { | ||
701 | l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; | ||
702 | r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; | ||
703 | Blowfish_decipher(c, &l, &r); | ||
704 | data[0] = l >> 24 & 0xff; | ||
705 | data[1] = l >> 16 & 0xff; | ||
706 | data[2] = l >> 8 & 0xff; | ||
707 | data[3] = l & 0xff; | ||
708 | data[4] = r >> 24 & 0xff; | ||
709 | data[5] = r >> 16 & 0xff; | ||
710 | data[6] = r >> 8 & 0xff; | ||
711 | data[7] = r & 0xff; | ||
712 | for (j = 0; j < 8; j++) | ||
713 | data[j] ^= iv[j]; | ||
714 | iv = data; | ||
715 | data -= 8; | ||
716 | } | ||
717 | l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; | ||
718 | r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; | ||
719 | Blowfish_decipher(c, &l, &r); | ||
720 | data[0] = l >> 24 & 0xff; | ||
721 | data[1] = l >> 16 & 0xff; | ||
722 | data[2] = l >> 8 & 0xff; | ||
723 | data[3] = l & 0xff; | ||
724 | data[4] = r >> 24 & 0xff; | ||
725 | data[5] = r >> 16 & 0xff; | ||
726 | data[6] = r >> 8 & 0xff; | ||
727 | data[7] = r & 0xff; | ||
728 | for (j = 0; j < 8; j++) | ||
729 | data[j] ^= iva[j]; | ||
730 | } | ||
731 | |||
732 | #if 0 | ||
733 | void | ||
734 | report(u_int32_t data[], u_int16_t len) | ||
735 | { | ||
736 | u_int16_t i; | ||
737 | for (i = 0; i < len; i += 2) | ||
738 | printf("Block %0hd: %08lx %08lx.\n", | ||
739 | i / 2, data[i], data[i + 1]); | ||
740 | } | ||
741 | void | ||
742 | main(void) | ||
743 | { | ||
744 | |||
745 | blf_ctx c; | ||
746 | char key[] = "AAAAA"; | ||
747 | char key2[] = "abcdefghijklmnopqrstuvwxyz"; | ||
748 | |||
749 | u_int32_t data[10]; | ||
750 | u_int32_t data2[] = | ||
751 | {0x424c4f57l, 0x46495348l}; | ||
752 | |||
753 | u_int16_t i; | ||
754 | |||
755 | /* First test */ | ||
756 | for (i = 0; i < 10; i++) | ||
757 | data[i] = i; | ||
758 | |||
759 | blf_key(&c, (u_int8_t *) key, 5); | ||
760 | blf_enc(&c, data, 5); | ||
761 | blf_dec(&c, data, 1); | ||
762 | blf_dec(&c, data + 2, 4); | ||
763 | printf("Should read as 0 - 9.\n"); | ||
764 | report(data, 10); | ||
765 | |||
766 | /* Second test */ | ||
767 | blf_key(&c, (u_int8_t *) key2, strlen(key2)); | ||
768 | blf_enc(&c, data2, 1); | ||
769 | printf("\nShould read as: 0x324ed0fe 0xf413a203.\n"); | ||
770 | report(data2, 2); | ||
771 | blf_dec(&c, data2, 1); | ||
772 | report(data2, 2); | ||
773 | } | ||
774 | #endif | ||
diff --git a/src/lib/libc/crypt/cast.c b/src/lib/libc/crypt/cast.c new file mode 100644 index 0000000000..264138f03e --- /dev/null +++ b/src/lib/libc/crypt/cast.c | |||
@@ -0,0 +1,779 @@ | |||
1 | /* $OpenBSD: cast.c,v 1.2 1998/07/21 22:42:03 provos Exp $ */ | ||
2 | /* | ||
3 | * CAST-128 in C | ||
4 | * Written by Steve Reid <sreid@sea-to-sky.net> | ||
5 | * 100% Public Domain - no warranty | ||
6 | * Released 1997.10.11 | ||
7 | */ | ||
8 | |||
9 | #include <sys/types.h> | ||
10 | |||
11 | #include <cast.h> | ||
12 | |||
13 | /* CAST S-Boxes */ | ||
14 | |||
15 | static const u_int32_t cast_sbox1[256] = { | ||
16 | 0x30FB40D4, 0x9FA0FF0B, 0x6BECCD2F, 0x3F258C7A, | ||
17 | 0x1E213F2F, 0x9C004DD3, 0x6003E540, 0xCF9FC949, | ||
18 | 0xBFD4AF27, 0x88BBBDB5, 0xE2034090, 0x98D09675, | ||
19 | 0x6E63A0E0, 0x15C361D2, 0xC2E7661D, 0x22D4FF8E, | ||
20 | 0x28683B6F, 0xC07FD059, 0xFF2379C8, 0x775F50E2, | ||
21 | 0x43C340D3, 0xDF2F8656, 0x887CA41A, 0xA2D2BD2D, | ||
22 | 0xA1C9E0D6, 0x346C4819, 0x61B76D87, 0x22540F2F, | ||
23 | 0x2ABE32E1, 0xAA54166B, 0x22568E3A, 0xA2D341D0, | ||
24 | 0x66DB40C8, 0xA784392F, 0x004DFF2F, 0x2DB9D2DE, | ||
25 | 0x97943FAC, 0x4A97C1D8, 0x527644B7, 0xB5F437A7, | ||
26 | 0xB82CBAEF, 0xD751D159, 0x6FF7F0ED, 0x5A097A1F, | ||
27 | 0x827B68D0, 0x90ECF52E, 0x22B0C054, 0xBC8E5935, | ||
28 | 0x4B6D2F7F, 0x50BB64A2, 0xD2664910, 0xBEE5812D, | ||
29 | 0xB7332290, 0xE93B159F, 0xB48EE411, 0x4BFF345D, | ||
30 | 0xFD45C240, 0xAD31973F, 0xC4F6D02E, 0x55FC8165, | ||
31 | 0xD5B1CAAD, 0xA1AC2DAE, 0xA2D4B76D, 0xC19B0C50, | ||
32 | 0x882240F2, 0x0C6E4F38, 0xA4E4BFD7, 0x4F5BA272, | ||
33 | 0x564C1D2F, 0xC59C5319, 0xB949E354, 0xB04669FE, | ||
34 | 0xB1B6AB8A, 0xC71358DD, 0x6385C545, 0x110F935D, | ||
35 | 0x57538AD5, 0x6A390493, 0xE63D37E0, 0x2A54F6B3, | ||
36 | 0x3A787D5F, 0x6276A0B5, 0x19A6FCDF, 0x7A42206A, | ||
37 | 0x29F9D4D5, 0xF61B1891, 0xBB72275E, 0xAA508167, | ||
38 | 0x38901091, 0xC6B505EB, 0x84C7CB8C, 0x2AD75A0F, | ||
39 | 0x874A1427, 0xA2D1936B, 0x2AD286AF, 0xAA56D291, | ||
40 | 0xD7894360, 0x425C750D, 0x93B39E26, 0x187184C9, | ||
41 | 0x6C00B32D, 0x73E2BB14, 0xA0BEBC3C, 0x54623779, | ||
42 | 0x64459EAB, 0x3F328B82, 0x7718CF82, 0x59A2CEA6, | ||
43 | 0x04EE002E, 0x89FE78E6, 0x3FAB0950, 0x325FF6C2, | ||
44 | 0x81383F05, 0x6963C5C8, 0x76CB5AD6, 0xD49974C9, | ||
45 | 0xCA180DCF, 0x380782D5, 0xC7FA5CF6, 0x8AC31511, | ||
46 | 0x35E79E13, 0x47DA91D0, 0xF40F9086, 0xA7E2419E, | ||
47 | 0x31366241, 0x051EF495, 0xAA573B04, 0x4A805D8D, | ||
48 | 0x548300D0, 0x00322A3C, 0xBF64CDDF, 0xBA57A68E, | ||
49 | 0x75C6372B, 0x50AFD341, 0xA7C13275, 0x915A0BF5, | ||
50 | 0x6B54BFAB, 0x2B0B1426, 0xAB4CC9D7, 0x449CCD82, | ||
51 | 0xF7FBF265, 0xAB85C5F3, 0x1B55DB94, 0xAAD4E324, | ||
52 | 0xCFA4BD3F, 0x2DEAA3E2, 0x9E204D02, 0xC8BD25AC, | ||
53 | 0xEADF55B3, 0xD5BD9E98, 0xE31231B2, 0x2AD5AD6C, | ||
54 | 0x954329DE, 0xADBE4528, 0xD8710F69, 0xAA51C90F, | ||
55 | 0xAA786BF6, 0x22513F1E, 0xAA51A79B, 0x2AD344CC, | ||
56 | 0x7B5A41F0, 0xD37CFBAD, 0x1B069505, 0x41ECE491, | ||
57 | 0xB4C332E6, 0x032268D4, 0xC9600ACC, 0xCE387E6D, | ||
58 | 0xBF6BB16C, 0x6A70FB78, 0x0D03D9C9, 0xD4DF39DE, | ||
59 | 0xE01063DA, 0x4736F464, 0x5AD328D8, 0xB347CC96, | ||
60 | 0x75BB0FC3, 0x98511BFB, 0x4FFBCC35, 0xB58BCF6A, | ||
61 | 0xE11F0ABC, 0xBFC5FE4A, 0xA70AEC10, 0xAC39570A, | ||
62 | 0x3F04442F, 0x6188B153, 0xE0397A2E, 0x5727CB79, | ||
63 | 0x9CEB418F, 0x1CACD68D, 0x2AD37C96, 0x0175CB9D, | ||
64 | 0xC69DFF09, 0xC75B65F0, 0xD9DB40D8, 0xEC0E7779, | ||
65 | 0x4744EAD4, 0xB11C3274, 0xDD24CB9E, 0x7E1C54BD, | ||
66 | 0xF01144F9, 0xD2240EB1, 0x9675B3FD, 0xA3AC3755, | ||
67 | 0xD47C27AF, 0x51C85F4D, 0x56907596, 0xA5BB15E6, | ||
68 | 0x580304F0, 0xCA042CF1, 0x011A37EA, 0x8DBFAADB, | ||
69 | 0x35BA3E4A, 0x3526FFA0, 0xC37B4D09, 0xBC306ED9, | ||
70 | 0x98A52666, 0x5648F725, 0xFF5E569D, 0x0CED63D0, | ||
71 | 0x7C63B2CF, 0x700B45E1, 0xD5EA50F1, 0x85A92872, | ||
72 | 0xAF1FBDA7, 0xD4234870, 0xA7870BF3, 0x2D3B4D79, | ||
73 | 0x42E04198, 0x0CD0EDE7, 0x26470DB8, 0xF881814C, | ||
74 | 0x474D6AD7, 0x7C0C5E5C, 0xD1231959, 0x381B7298, | ||
75 | 0xF5D2F4DB, 0xAB838653, 0x6E2F1E23, 0x83719C9E, | ||
76 | 0xBD91E046, 0x9A56456E, 0xDC39200C, 0x20C8C571, | ||
77 | 0x962BDA1C, 0xE1E696FF, 0xB141AB08, 0x7CCA89B9, | ||
78 | 0x1A69E783, 0x02CC4843, 0xA2F7C579, 0x429EF47D, | ||
79 | 0x427B169C, 0x5AC9F049, 0xDD8F0F00, 0x5C8165BF | ||
80 | }; | ||
81 | |||
82 | static const u_int32_t cast_sbox2[256] = { | ||
83 | 0x1F201094, 0xEF0BA75B, 0x69E3CF7E, 0x393F4380, | ||
84 | 0xFE61CF7A, 0xEEC5207A, 0x55889C94, 0x72FC0651, | ||
85 | 0xADA7EF79, 0x4E1D7235, 0xD55A63CE, 0xDE0436BA, | ||
86 | 0x99C430EF, 0x5F0C0794, 0x18DCDB7D, 0xA1D6EFF3, | ||
87 | 0xA0B52F7B, 0x59E83605, 0xEE15B094, 0xE9FFD909, | ||
88 | 0xDC440086, 0xEF944459, 0xBA83CCB3, 0xE0C3CDFB, | ||
89 | 0xD1DA4181, 0x3B092AB1, 0xF997F1C1, 0xA5E6CF7B, | ||
90 | 0x01420DDB, 0xE4E7EF5B, 0x25A1FF41, 0xE180F806, | ||
91 | 0x1FC41080, 0x179BEE7A, 0xD37AC6A9, 0xFE5830A4, | ||
92 | 0x98DE8B7F, 0x77E83F4E, 0x79929269, 0x24FA9F7B, | ||
93 | 0xE113C85B, 0xACC40083, 0xD7503525, 0xF7EA615F, | ||
94 | 0x62143154, 0x0D554B63, 0x5D681121, 0xC866C359, | ||
95 | 0x3D63CF73, 0xCEE234C0, 0xD4D87E87, 0x5C672B21, | ||
96 | 0x071F6181, 0x39F7627F, 0x361E3084, 0xE4EB573B, | ||
97 | 0x602F64A4, 0xD63ACD9C, 0x1BBC4635, 0x9E81032D, | ||
98 | 0x2701F50C, 0x99847AB4, 0xA0E3DF79, 0xBA6CF38C, | ||
99 | 0x10843094, 0x2537A95E, 0xF46F6FFE, 0xA1FF3B1F, | ||
100 | 0x208CFB6A, 0x8F458C74, 0xD9E0A227, 0x4EC73A34, | ||
101 | 0xFC884F69, 0x3E4DE8DF, 0xEF0E0088, 0x3559648D, | ||
102 | 0x8A45388C, 0x1D804366, 0x721D9BFD, 0xA58684BB, | ||
103 | 0xE8256333, 0x844E8212, 0x128D8098, 0xFED33FB4, | ||
104 | 0xCE280AE1, 0x27E19BA5, 0xD5A6C252, 0xE49754BD, | ||
105 | 0xC5D655DD, 0xEB667064, 0x77840B4D, 0xA1B6A801, | ||
106 | 0x84DB26A9, 0xE0B56714, 0x21F043B7, 0xE5D05860, | ||
107 | 0x54F03084, 0x066FF472, 0xA31AA153, 0xDADC4755, | ||
108 | 0xB5625DBF, 0x68561BE6, 0x83CA6B94, 0x2D6ED23B, | ||
109 | 0xECCF01DB, 0xA6D3D0BA, 0xB6803D5C, 0xAF77A709, | ||
110 | 0x33B4A34C, 0x397BC8D6, 0x5EE22B95, 0x5F0E5304, | ||
111 | 0x81ED6F61, 0x20E74364, 0xB45E1378, 0xDE18639B, | ||
112 | 0x881CA122, 0xB96726D1, 0x8049A7E8, 0x22B7DA7B, | ||
113 | 0x5E552D25, 0x5272D237, 0x79D2951C, 0xC60D894C, | ||
114 | 0x488CB402, 0x1BA4FE5B, 0xA4B09F6B, 0x1CA815CF, | ||
115 | 0xA20C3005, 0x8871DF63, 0xB9DE2FCB, 0x0CC6C9E9, | ||
116 | 0x0BEEFF53, 0xE3214517, 0xB4542835, 0x9F63293C, | ||
117 | 0xEE41E729, 0x6E1D2D7C, 0x50045286, 0x1E6685F3, | ||
118 | 0xF33401C6, 0x30A22C95, 0x31A70850, 0x60930F13, | ||
119 | 0x73F98417, 0xA1269859, 0xEC645C44, 0x52C877A9, | ||
120 | 0xCDFF33A6, 0xA02B1741, 0x7CBAD9A2, 0x2180036F, | ||
121 | 0x50D99C08, 0xCB3F4861, 0xC26BD765, 0x64A3F6AB, | ||
122 | 0x80342676, 0x25A75E7B, 0xE4E6D1FC, 0x20C710E6, | ||
123 | 0xCDF0B680, 0x17844D3B, 0x31EEF84D, 0x7E0824E4, | ||
124 | 0x2CCB49EB, 0x846A3BAE, 0x8FF77888, 0xEE5D60F6, | ||
125 | 0x7AF75673, 0x2FDD5CDB, 0xA11631C1, 0x30F66F43, | ||
126 | 0xB3FAEC54, 0x157FD7FA, 0xEF8579CC, 0xD152DE58, | ||
127 | 0xDB2FFD5E, 0x8F32CE19, 0x306AF97A, 0x02F03EF8, | ||
128 | 0x99319AD5, 0xC242FA0F, 0xA7E3EBB0, 0xC68E4906, | ||
129 | 0xB8DA230C, 0x80823028, 0xDCDEF3C8, 0xD35FB171, | ||
130 | 0x088A1BC8, 0xBEC0C560, 0x61A3C9E8, 0xBCA8F54D, | ||
131 | 0xC72FEFFA, 0x22822E99, 0x82C570B4, 0xD8D94E89, | ||
132 | 0x8B1C34BC, 0x301E16E6, 0x273BE979, 0xB0FFEAA6, | ||
133 | 0x61D9B8C6, 0x00B24869, 0xB7FFCE3F, 0x08DC283B, | ||
134 | 0x43DAF65A, 0xF7E19798, 0x7619B72F, 0x8F1C9BA4, | ||
135 | 0xDC8637A0, 0x16A7D3B1, 0x9FC393B7, 0xA7136EEB, | ||
136 | 0xC6BCC63E, 0x1A513742, 0xEF6828BC, 0x520365D6, | ||
137 | 0x2D6A77AB, 0x3527ED4B, 0x821FD216, 0x095C6E2E, | ||
138 | 0xDB92F2FB, 0x5EEA29CB, 0x145892F5, 0x91584F7F, | ||
139 | 0x5483697B, 0x2667A8CC, 0x85196048, 0x8C4BACEA, | ||
140 | 0x833860D4, 0x0D23E0F9, 0x6C387E8A, 0x0AE6D249, | ||
141 | 0xB284600C, 0xD835731D, 0xDCB1C647, 0xAC4C56EA, | ||
142 | 0x3EBD81B3, 0x230EABB0, 0x6438BC87, 0xF0B5B1FA, | ||
143 | 0x8F5EA2B3, 0xFC184642, 0x0A036B7A, 0x4FB089BD, | ||
144 | 0x649DA589, 0xA345415E, 0x5C038323, 0x3E5D3BB9, | ||
145 | 0x43D79572, 0x7E6DD07C, 0x06DFDF1E, 0x6C6CC4EF, | ||
146 | 0x7160A539, 0x73BFBE70, 0x83877605, 0x4523ECF1 | ||
147 | }; | ||
148 | |||
149 | static const u_int32_t cast_sbox3[256] = { | ||
150 | 0x8DEFC240, 0x25FA5D9F, 0xEB903DBF, 0xE810C907, | ||
151 | 0x47607FFF, 0x369FE44B, 0x8C1FC644, 0xAECECA90, | ||
152 | 0xBEB1F9BF, 0xEEFBCAEA, 0xE8CF1950, 0x51DF07AE, | ||
153 | 0x920E8806, 0xF0AD0548, 0xE13C8D83, 0x927010D5, | ||
154 | 0x11107D9F, 0x07647DB9, 0xB2E3E4D4, 0x3D4F285E, | ||
155 | 0xB9AFA820, 0xFADE82E0, 0xA067268B, 0x8272792E, | ||
156 | 0x553FB2C0, 0x489AE22B, 0xD4EF9794, 0x125E3FBC, | ||
157 | 0x21FFFCEE, 0x825B1BFD, 0x9255C5ED, 0x1257A240, | ||
158 | 0x4E1A8302, 0xBAE07FFF, 0x528246E7, 0x8E57140E, | ||
159 | 0x3373F7BF, 0x8C9F8188, 0xA6FC4EE8, 0xC982B5A5, | ||
160 | 0xA8C01DB7, 0x579FC264, 0x67094F31, 0xF2BD3F5F, | ||
161 | 0x40FFF7C1, 0x1FB78DFC, 0x8E6BD2C1, 0x437BE59B, | ||
162 | 0x99B03DBF, 0xB5DBC64B, 0x638DC0E6, 0x55819D99, | ||
163 | 0xA197C81C, 0x4A012D6E, 0xC5884A28, 0xCCC36F71, | ||
164 | 0xB843C213, 0x6C0743F1, 0x8309893C, 0x0FEDDD5F, | ||
165 | 0x2F7FE850, 0xD7C07F7E, 0x02507FBF, 0x5AFB9A04, | ||
166 | 0xA747D2D0, 0x1651192E, 0xAF70BF3E, 0x58C31380, | ||
167 | 0x5F98302E, 0x727CC3C4, 0x0A0FB402, 0x0F7FEF82, | ||
168 | 0x8C96FDAD, 0x5D2C2AAE, 0x8EE99A49, 0x50DA88B8, | ||
169 | 0x8427F4A0, 0x1EAC5790, 0x796FB449, 0x8252DC15, | ||
170 | 0xEFBD7D9B, 0xA672597D, 0xADA840D8, 0x45F54504, | ||
171 | 0xFA5D7403, 0xE83EC305, 0x4F91751A, 0x925669C2, | ||
172 | 0x23EFE941, 0xA903F12E, 0x60270DF2, 0x0276E4B6, | ||
173 | 0x94FD6574, 0x927985B2, 0x8276DBCB, 0x02778176, | ||
174 | 0xF8AF918D, 0x4E48F79E, 0x8F616DDF, 0xE29D840E, | ||
175 | 0x842F7D83, 0x340CE5C8, 0x96BBB682, 0x93B4B148, | ||
176 | 0xEF303CAB, 0x984FAF28, 0x779FAF9B, 0x92DC560D, | ||
177 | 0x224D1E20, 0x8437AA88, 0x7D29DC96, 0x2756D3DC, | ||
178 | 0x8B907CEE, 0xB51FD240, 0xE7C07CE3, 0xE566B4A1, | ||
179 | 0xC3E9615E, 0x3CF8209D, 0x6094D1E3, 0xCD9CA341, | ||
180 | 0x5C76460E, 0x00EA983B, 0xD4D67881, 0xFD47572C, | ||
181 | 0xF76CEDD9, 0xBDA8229C, 0x127DADAA, 0x438A074E, | ||
182 | 0x1F97C090, 0x081BDB8A, 0x93A07EBE, 0xB938CA15, | ||
183 | 0x97B03CFF, 0x3DC2C0F8, 0x8D1AB2EC, 0x64380E51, | ||
184 | 0x68CC7BFB, 0xD90F2788, 0x12490181, 0x5DE5FFD4, | ||
185 | 0xDD7EF86A, 0x76A2E214, 0xB9A40368, 0x925D958F, | ||
186 | 0x4B39FFFA, 0xBA39AEE9, 0xA4FFD30B, 0xFAF7933B, | ||
187 | 0x6D498623, 0x193CBCFA, 0x27627545, 0x825CF47A, | ||
188 | 0x61BD8BA0, 0xD11E42D1, 0xCEAD04F4, 0x127EA392, | ||
189 | 0x10428DB7, 0x8272A972, 0x9270C4A8, 0x127DE50B, | ||
190 | 0x285BA1C8, 0x3C62F44F, 0x35C0EAA5, 0xE805D231, | ||
191 | 0x428929FB, 0xB4FCDF82, 0x4FB66A53, 0x0E7DC15B, | ||
192 | 0x1F081FAB, 0x108618AE, 0xFCFD086D, 0xF9FF2889, | ||
193 | 0x694BCC11, 0x236A5CAE, 0x12DECA4D, 0x2C3F8CC5, | ||
194 | 0xD2D02DFE, 0xF8EF5896, 0xE4CF52DA, 0x95155B67, | ||
195 | 0x494A488C, 0xB9B6A80C, 0x5C8F82BC, 0x89D36B45, | ||
196 | 0x3A609437, 0xEC00C9A9, 0x44715253, 0x0A874B49, | ||
197 | 0xD773BC40, 0x7C34671C, 0x02717EF6, 0x4FEB5536, | ||
198 | 0xA2D02FFF, 0xD2BF60C4, 0xD43F03C0, 0x50B4EF6D, | ||
199 | 0x07478CD1, 0x006E1888, 0xA2E53F55, 0xB9E6D4BC, | ||
200 | 0xA2048016, 0x97573833, 0xD7207D67, 0xDE0F8F3D, | ||
201 | 0x72F87B33, 0xABCC4F33, 0x7688C55D, 0x7B00A6B0, | ||
202 | 0x947B0001, 0x570075D2, 0xF9BB88F8, 0x8942019E, | ||
203 | 0x4264A5FF, 0x856302E0, 0x72DBD92B, 0xEE971B69, | ||
204 | 0x6EA22FDE, 0x5F08AE2B, 0xAF7A616D, 0xE5C98767, | ||
205 | 0xCF1FEBD2, 0x61EFC8C2, 0xF1AC2571, 0xCC8239C2, | ||
206 | 0x67214CB8, 0xB1E583D1, 0xB7DC3E62, 0x7F10BDCE, | ||
207 | 0xF90A5C38, 0x0FF0443D, 0x606E6DC6, 0x60543A49, | ||
208 | 0x5727C148, 0x2BE98A1D, 0x8AB41738, 0x20E1BE24, | ||
209 | 0xAF96DA0F, 0x68458425, 0x99833BE5, 0x600D457D, | ||
210 | 0x282F9350, 0x8334B362, 0xD91D1120, 0x2B6D8DA0, | ||
211 | 0x642B1E31, 0x9C305A00, 0x52BCE688, 0x1B03588A, | ||
212 | 0xF7BAEFD5, 0x4142ED9C, 0xA4315C11, 0x83323EC5, | ||
213 | 0xDFEF4636, 0xA133C501, 0xE9D3531C, 0xEE353783 | ||
214 | }; | ||
215 | |||
216 | static const u_int32_t cast_sbox4[256] = { | ||
217 | 0x9DB30420, 0x1FB6E9DE, 0xA7BE7BEF, 0xD273A298, | ||
218 | 0x4A4F7BDB, 0x64AD8C57, 0x85510443, 0xFA020ED1, | ||
219 | 0x7E287AFF, 0xE60FB663, 0x095F35A1, 0x79EBF120, | ||
220 | 0xFD059D43, 0x6497B7B1, 0xF3641F63, 0x241E4ADF, | ||
221 | 0x28147F5F, 0x4FA2B8CD, 0xC9430040, 0x0CC32220, | ||
222 | 0xFDD30B30, 0xC0A5374F, 0x1D2D00D9, 0x24147B15, | ||
223 | 0xEE4D111A, 0x0FCA5167, 0x71FF904C, 0x2D195FFE, | ||
224 | 0x1A05645F, 0x0C13FEFE, 0x081B08CA, 0x05170121, | ||
225 | 0x80530100, 0xE83E5EFE, 0xAC9AF4F8, 0x7FE72701, | ||
226 | 0xD2B8EE5F, 0x06DF4261, 0xBB9E9B8A, 0x7293EA25, | ||
227 | 0xCE84FFDF, 0xF5718801, 0x3DD64B04, 0xA26F263B, | ||
228 | 0x7ED48400, 0x547EEBE6, 0x446D4CA0, 0x6CF3D6F5, | ||
229 | 0x2649ABDF, 0xAEA0C7F5, 0x36338CC1, 0x503F7E93, | ||
230 | 0xD3772061, 0x11B638E1, 0x72500E03, 0xF80EB2BB, | ||
231 | 0xABE0502E, 0xEC8D77DE, 0x57971E81, 0xE14F6746, | ||
232 | 0xC9335400, 0x6920318F, 0x081DBB99, 0xFFC304A5, | ||
233 | 0x4D351805, 0x7F3D5CE3, 0xA6C866C6, 0x5D5BCCA9, | ||
234 | 0xDAEC6FEA, 0x9F926F91, 0x9F46222F, 0x3991467D, | ||
235 | 0xA5BF6D8E, 0x1143C44F, 0x43958302, 0xD0214EEB, | ||
236 | 0x022083B8, 0x3FB6180C, 0x18F8931E, 0x281658E6, | ||
237 | 0x26486E3E, 0x8BD78A70, 0x7477E4C1, 0xB506E07C, | ||
238 | 0xF32D0A25, 0x79098B02, 0xE4EABB81, 0x28123B23, | ||
239 | 0x69DEAD38, 0x1574CA16, 0xDF871B62, 0x211C40B7, | ||
240 | 0xA51A9EF9, 0x0014377B, 0x041E8AC8, 0x09114003, | ||
241 | 0xBD59E4D2, 0xE3D156D5, 0x4FE876D5, 0x2F91A340, | ||
242 | 0x557BE8DE, 0x00EAE4A7, 0x0CE5C2EC, 0x4DB4BBA6, | ||
243 | 0xE756BDFF, 0xDD3369AC, 0xEC17B035, 0x06572327, | ||
244 | 0x99AFC8B0, 0x56C8C391, 0x6B65811C, 0x5E146119, | ||
245 | 0x6E85CB75, 0xBE07C002, 0xC2325577, 0x893FF4EC, | ||
246 | 0x5BBFC92D, 0xD0EC3B25, 0xB7801AB7, 0x8D6D3B24, | ||
247 | 0x20C763EF, 0xC366A5FC, 0x9C382880, 0x0ACE3205, | ||
248 | 0xAAC9548A, 0xECA1D7C7, 0x041AFA32, 0x1D16625A, | ||
249 | 0x6701902C, 0x9B757A54, 0x31D477F7, 0x9126B031, | ||
250 | 0x36CC6FDB, 0xC70B8B46, 0xD9E66A48, 0x56E55A79, | ||
251 | 0x026A4CEB, 0x52437EFF, 0x2F8F76B4, 0x0DF980A5, | ||
252 | 0x8674CDE3, 0xEDDA04EB, 0x17A9BE04, 0x2C18F4DF, | ||
253 | 0xB7747F9D, 0xAB2AF7B4, 0xEFC34D20, 0x2E096B7C, | ||
254 | 0x1741A254, 0xE5B6A035, 0x213D42F6, 0x2C1C7C26, | ||
255 | 0x61C2F50F, 0x6552DAF9, 0xD2C231F8, 0x25130F69, | ||
256 | 0xD8167FA2, 0x0418F2C8, 0x001A96A6, 0x0D1526AB, | ||
257 | 0x63315C21, 0x5E0A72EC, 0x49BAFEFD, 0x187908D9, | ||
258 | 0x8D0DBD86, 0x311170A7, 0x3E9B640C, 0xCC3E10D7, | ||
259 | 0xD5CAD3B6, 0x0CAEC388, 0xF73001E1, 0x6C728AFF, | ||
260 | 0x71EAE2A1, 0x1F9AF36E, 0xCFCBD12F, 0xC1DE8417, | ||
261 | 0xAC07BE6B, 0xCB44A1D8, 0x8B9B0F56, 0x013988C3, | ||
262 | 0xB1C52FCA, 0xB4BE31CD, 0xD8782806, 0x12A3A4E2, | ||
263 | 0x6F7DE532, 0x58FD7EB6, 0xD01EE900, 0x24ADFFC2, | ||
264 | 0xF4990FC5, 0x9711AAC5, 0x001D7B95, 0x82E5E7D2, | ||
265 | 0x109873F6, 0x00613096, 0xC32D9521, 0xADA121FF, | ||
266 | 0x29908415, 0x7FBB977F, 0xAF9EB3DB, 0x29C9ED2A, | ||
267 | 0x5CE2A465, 0xA730F32C, 0xD0AA3FE8, 0x8A5CC091, | ||
268 | 0xD49E2CE7, 0x0CE454A9, 0xD60ACD86, 0x015F1919, | ||
269 | 0x77079103, 0xDEA03AF6, 0x78A8565E, 0xDEE356DF, | ||
270 | 0x21F05CBE, 0x8B75E387, 0xB3C50651, 0xB8A5C3EF, | ||
271 | 0xD8EEB6D2, 0xE523BE77, 0xC2154529, 0x2F69EFDF, | ||
272 | 0xAFE67AFB, 0xF470C4B2, 0xF3E0EB5B, 0xD6CC9876, | ||
273 | 0x39E4460C, 0x1FDA8538, 0x1987832F, 0xCA007367, | ||
274 | 0xA99144F8, 0x296B299E, 0x492FC295, 0x9266BEAB, | ||
275 | 0xB5676E69, 0x9BD3DDDA, 0xDF7E052F, 0xDB25701C, | ||
276 | 0x1B5E51EE, 0xF65324E6, 0x6AFCE36C, 0x0316CC04, | ||
277 | 0x8644213E, 0xB7DC59D0, 0x7965291F, 0xCCD6FD43, | ||
278 | 0x41823979, 0x932BCDF6, 0xB657C34D, 0x4EDFD282, | ||
279 | 0x7AE5290C, 0x3CB9536B, 0x851E20FE, 0x9833557E, | ||
280 | 0x13ECF0B0, 0xD3FFB372, 0x3F85C5C1, 0x0AEF7ED2 | ||
281 | }; | ||
282 | |||
283 | static const u_int32_t cast_sbox5[256] = { | ||
284 | 0x7EC90C04, 0x2C6E74B9, 0x9B0E66DF, 0xA6337911, | ||
285 | 0xB86A7FFF, 0x1DD358F5, 0x44DD9D44, 0x1731167F, | ||
286 | 0x08FBF1FA, 0xE7F511CC, 0xD2051B00, 0x735ABA00, | ||
287 | 0x2AB722D8, 0x386381CB, 0xACF6243A, 0x69BEFD7A, | ||
288 | 0xE6A2E77F, 0xF0C720CD, 0xC4494816, 0xCCF5C180, | ||
289 | 0x38851640, 0x15B0A848, 0xE68B18CB, 0x4CAADEFF, | ||
290 | 0x5F480A01, 0x0412B2AA, 0x259814FC, 0x41D0EFE2, | ||
291 | 0x4E40B48D, 0x248EB6FB, 0x8DBA1CFE, 0x41A99B02, | ||
292 | 0x1A550A04, 0xBA8F65CB, 0x7251F4E7, 0x95A51725, | ||
293 | 0xC106ECD7, 0x97A5980A, 0xC539B9AA, 0x4D79FE6A, | ||
294 | 0xF2F3F763, 0x68AF8040, 0xED0C9E56, 0x11B4958B, | ||
295 | 0xE1EB5A88, 0x8709E6B0, 0xD7E07156, 0x4E29FEA7, | ||
296 | 0x6366E52D, 0x02D1C000, 0xC4AC8E05, 0x9377F571, | ||
297 | 0x0C05372A, 0x578535F2, 0x2261BE02, 0xD642A0C9, | ||
298 | 0xDF13A280, 0x74B55BD2, 0x682199C0, 0xD421E5EC, | ||
299 | 0x53FB3CE8, 0xC8ADEDB3, 0x28A87FC9, 0x3D959981, | ||
300 | 0x5C1FF900, 0xFE38D399, 0x0C4EFF0B, 0x062407EA, | ||
301 | 0xAA2F4FB1, 0x4FB96976, 0x90C79505, 0xB0A8A774, | ||
302 | 0xEF55A1FF, 0xE59CA2C2, 0xA6B62D27, 0xE66A4263, | ||
303 | 0xDF65001F, 0x0EC50966, 0xDFDD55BC, 0x29DE0655, | ||
304 | 0x911E739A, 0x17AF8975, 0x32C7911C, 0x89F89468, | ||
305 | 0x0D01E980, 0x524755F4, 0x03B63CC9, 0x0CC844B2, | ||
306 | 0xBCF3F0AA, 0x87AC36E9, 0xE53A7426, 0x01B3D82B, | ||
307 | 0x1A9E7449, 0x64EE2D7E, 0xCDDBB1DA, 0x01C94910, | ||
308 | 0xB868BF80, 0x0D26F3FD, 0x9342EDE7, 0x04A5C284, | ||
309 | 0x636737B6, 0x50F5B616, 0xF24766E3, 0x8ECA36C1, | ||
310 | 0x136E05DB, 0xFEF18391, 0xFB887A37, 0xD6E7F7D4, | ||
311 | 0xC7FB7DC9, 0x3063FCDF, 0xB6F589DE, 0xEC2941DA, | ||
312 | 0x26E46695, 0xB7566419, 0xF654EFC5, 0xD08D58B7, | ||
313 | 0x48925401, 0xC1BACB7F, 0xE5FF550F, 0xB6083049, | ||
314 | 0x5BB5D0E8, 0x87D72E5A, 0xAB6A6EE1, 0x223A66CE, | ||
315 | 0xC62BF3CD, 0x9E0885F9, 0x68CB3E47, 0x086C010F, | ||
316 | 0xA21DE820, 0xD18B69DE, 0xF3F65777, 0xFA02C3F6, | ||
317 | 0x407EDAC3, 0xCBB3D550, 0x1793084D, 0xB0D70EBA, | ||
318 | 0x0AB378D5, 0xD951FB0C, 0xDED7DA56, 0x4124BBE4, | ||
319 | 0x94CA0B56, 0x0F5755D1, 0xE0E1E56E, 0x6184B5BE, | ||
320 | 0x580A249F, 0x94F74BC0, 0xE327888E, 0x9F7B5561, | ||
321 | 0xC3DC0280, 0x05687715, 0x646C6BD7, 0x44904DB3, | ||
322 | 0x66B4F0A3, 0xC0F1648A, 0x697ED5AF, 0x49E92FF6, | ||
323 | 0x309E374F, 0x2CB6356A, 0x85808573, 0x4991F840, | ||
324 | 0x76F0AE02, 0x083BE84D, 0x28421C9A, 0x44489406, | ||
325 | 0x736E4CB8, 0xC1092910, 0x8BC95FC6, 0x7D869CF4, | ||
326 | 0x134F616F, 0x2E77118D, 0xB31B2BE1, 0xAA90B472, | ||
327 | 0x3CA5D717, 0x7D161BBA, 0x9CAD9010, 0xAF462BA2, | ||
328 | 0x9FE459D2, 0x45D34559, 0xD9F2DA13, 0xDBC65487, | ||
329 | 0xF3E4F94E, 0x176D486F, 0x097C13EA, 0x631DA5C7, | ||
330 | 0x445F7382, 0x175683F4, 0xCDC66A97, 0x70BE0288, | ||
331 | 0xB3CDCF72, 0x6E5DD2F3, 0x20936079, 0x459B80A5, | ||
332 | 0xBE60E2DB, 0xA9C23101, 0xEBA5315C, 0x224E42F2, | ||
333 | 0x1C5C1572, 0xF6721B2C, 0x1AD2FFF3, 0x8C25404E, | ||
334 | 0x324ED72F, 0x4067B7FD, 0x0523138E, 0x5CA3BC78, | ||
335 | 0xDC0FD66E, 0x75922283, 0x784D6B17, 0x58EBB16E, | ||
336 | 0x44094F85, 0x3F481D87, 0xFCFEAE7B, 0x77B5FF76, | ||
337 | 0x8C2302BF, 0xAAF47556, 0x5F46B02A, 0x2B092801, | ||
338 | 0x3D38F5F7, 0x0CA81F36, 0x52AF4A8A, 0x66D5E7C0, | ||
339 | 0xDF3B0874, 0x95055110, 0x1B5AD7A8, 0xF61ED5AD, | ||
340 | 0x6CF6E479, 0x20758184, 0xD0CEFA65, 0x88F7BE58, | ||
341 | 0x4A046826, 0x0FF6F8F3, 0xA09C7F70, 0x5346ABA0, | ||
342 | 0x5CE96C28, 0xE176EDA3, 0x6BAC307F, 0x376829D2, | ||
343 | 0x85360FA9, 0x17E3FE2A, 0x24B79767, 0xF5A96B20, | ||
344 | 0xD6CD2595, 0x68FF1EBF, 0x7555442C, 0xF19F06BE, | ||
345 | 0xF9E0659A, 0xEEB9491D, 0x34010718, 0xBB30CAB8, | ||
346 | 0xE822FE15, 0x88570983, 0x750E6249, 0xDA627E55, | ||
347 | 0x5E76FFA8, 0xB1534546, 0x6D47DE08, 0xEFE9E7D4 | ||
348 | }; | ||
349 | |||
350 | static const u_int32_t cast_sbox6[256] = { | ||
351 | 0xF6FA8F9D, 0x2CAC6CE1, 0x4CA34867, 0xE2337F7C, | ||
352 | 0x95DB08E7, 0x016843B4, 0xECED5CBC, 0x325553AC, | ||
353 | 0xBF9F0960, 0xDFA1E2ED, 0x83F0579D, 0x63ED86B9, | ||
354 | 0x1AB6A6B8, 0xDE5EBE39, 0xF38FF732, 0x8989B138, | ||
355 | 0x33F14961, 0xC01937BD, 0xF506C6DA, 0xE4625E7E, | ||
356 | 0xA308EA99, 0x4E23E33C, 0x79CBD7CC, 0x48A14367, | ||
357 | 0xA3149619, 0xFEC94BD5, 0xA114174A, 0xEAA01866, | ||
358 | 0xA084DB2D, 0x09A8486F, 0xA888614A, 0x2900AF98, | ||
359 | 0x01665991, 0xE1992863, 0xC8F30C60, 0x2E78EF3C, | ||
360 | 0xD0D51932, 0xCF0FEC14, 0xF7CA07D2, 0xD0A82072, | ||
361 | 0xFD41197E, 0x9305A6B0, 0xE86BE3DA, 0x74BED3CD, | ||
362 | 0x372DA53C, 0x4C7F4448, 0xDAB5D440, 0x6DBA0EC3, | ||
363 | 0x083919A7, 0x9FBAEED9, 0x49DBCFB0, 0x4E670C53, | ||
364 | 0x5C3D9C01, 0x64BDB941, 0x2C0E636A, 0xBA7DD9CD, | ||
365 | 0xEA6F7388, 0xE70BC762, 0x35F29ADB, 0x5C4CDD8D, | ||
366 | 0xF0D48D8C, 0xB88153E2, 0x08A19866, 0x1AE2EAC8, | ||
367 | 0x284CAF89, 0xAA928223, 0x9334BE53, 0x3B3A21BF, | ||
368 | 0x16434BE3, 0x9AEA3906, 0xEFE8C36E, 0xF890CDD9, | ||
369 | 0x80226DAE, 0xC340A4A3, 0xDF7E9C09, 0xA694A807, | ||
370 | 0x5B7C5ECC, 0x221DB3A6, 0x9A69A02F, 0x68818A54, | ||
371 | 0xCEB2296F, 0x53C0843A, 0xFE893655, 0x25BFE68A, | ||
372 | 0xB4628ABC, 0xCF222EBF, 0x25AC6F48, 0xA9A99387, | ||
373 | 0x53BDDB65, 0xE76FFBE7, 0xE967FD78, 0x0BA93563, | ||
374 | 0x8E342BC1, 0xE8A11BE9, 0x4980740D, 0xC8087DFC, | ||
375 | 0x8DE4BF99, 0xA11101A0, 0x7FD37975, 0xDA5A26C0, | ||
376 | 0xE81F994F, 0x9528CD89, 0xFD339FED, 0xB87834BF, | ||
377 | 0x5F04456D, 0x22258698, 0xC9C4C83B, 0x2DC156BE, | ||
378 | 0x4F628DAA, 0x57F55EC5, 0xE2220ABE, 0xD2916EBF, | ||
379 | 0x4EC75B95, 0x24F2C3C0, 0x42D15D99, 0xCD0D7FA0, | ||
380 | 0x7B6E27FF, 0xA8DC8AF0, 0x7345C106, 0xF41E232F, | ||
381 | 0x35162386, 0xE6EA8926, 0x3333B094, 0x157EC6F2, | ||
382 | 0x372B74AF, 0x692573E4, 0xE9A9D848, 0xF3160289, | ||
383 | 0x3A62EF1D, 0xA787E238, 0xF3A5F676, 0x74364853, | ||
384 | 0x20951063, 0x4576698D, 0xB6FAD407, 0x592AF950, | ||
385 | 0x36F73523, 0x4CFB6E87, 0x7DA4CEC0, 0x6C152DAA, | ||
386 | 0xCB0396A8, 0xC50DFE5D, 0xFCD707AB, 0x0921C42F, | ||
387 | 0x89DFF0BB, 0x5FE2BE78, 0x448F4F33, 0x754613C9, | ||
388 | 0x2B05D08D, 0x48B9D585, 0xDC049441, 0xC8098F9B, | ||
389 | 0x7DEDE786, 0xC39A3373, 0x42410005, 0x6A091751, | ||
390 | 0x0EF3C8A6, 0x890072D6, 0x28207682, 0xA9A9F7BE, | ||
391 | 0xBF32679D, 0xD45B5B75, 0xB353FD00, 0xCBB0E358, | ||
392 | 0x830F220A, 0x1F8FB214, 0xD372CF08, 0xCC3C4A13, | ||
393 | 0x8CF63166, 0x061C87BE, 0x88C98F88, 0x6062E397, | ||
394 | 0x47CF8E7A, 0xB6C85283, 0x3CC2ACFB, 0x3FC06976, | ||
395 | 0x4E8F0252, 0x64D8314D, 0xDA3870E3, 0x1E665459, | ||
396 | 0xC10908F0, 0x513021A5, 0x6C5B68B7, 0x822F8AA0, | ||
397 | 0x3007CD3E, 0x74719EEF, 0xDC872681, 0x073340D4, | ||
398 | 0x7E432FD9, 0x0C5EC241, 0x8809286C, 0xF592D891, | ||
399 | 0x08A930F6, 0x957EF305, 0xB7FBFFBD, 0xC266E96F, | ||
400 | 0x6FE4AC98, 0xB173ECC0, 0xBC60B42A, 0x953498DA, | ||
401 | 0xFBA1AE12, 0x2D4BD736, 0x0F25FAAB, 0xA4F3FCEB, | ||
402 | 0xE2969123, 0x257F0C3D, 0x9348AF49, 0x361400BC, | ||
403 | 0xE8816F4A, 0x3814F200, 0xA3F94043, 0x9C7A54C2, | ||
404 | 0xBC704F57, 0xDA41E7F9, 0xC25AD33A, 0x54F4A084, | ||
405 | 0xB17F5505, 0x59357CBE, 0xEDBD15C8, 0x7F97C5AB, | ||
406 | 0xBA5AC7B5, 0xB6F6DEAF, 0x3A479C3A, 0x5302DA25, | ||
407 | 0x653D7E6A, 0x54268D49, 0x51A477EA, 0x5017D55B, | ||
408 | 0xD7D25D88, 0x44136C76, 0x0404A8C8, 0xB8E5A121, | ||
409 | 0xB81A928A, 0x60ED5869, 0x97C55B96, 0xEAEC991B, | ||
410 | 0x29935913, 0x01FDB7F1, 0x088E8DFA, 0x9AB6F6F5, | ||
411 | 0x3B4CBF9F, 0x4A5DE3AB, 0xE6051D35, 0xA0E1D855, | ||
412 | 0xD36B4CF1, 0xF544EDEB, 0xB0E93524, 0xBEBB8FBD, | ||
413 | 0xA2D762CF, 0x49C92F54, 0x38B5F331, 0x7128A454, | ||
414 | 0x48392905, 0xA65B1DB8, 0x851C97BD, 0xD675CF2F | ||
415 | }; | ||
416 | |||
417 | static const u_int32_t cast_sbox7[256] = { | ||
418 | 0x85E04019, 0x332BF567, 0x662DBFFF, 0xCFC65693, | ||
419 | 0x2A8D7F6F, 0xAB9BC912, 0xDE6008A1, 0x2028DA1F, | ||
420 | 0x0227BCE7, 0x4D642916, 0x18FAC300, 0x50F18B82, | ||
421 | 0x2CB2CB11, 0xB232E75C, 0x4B3695F2, 0xB28707DE, | ||
422 | 0xA05FBCF6, 0xCD4181E9, 0xE150210C, 0xE24EF1BD, | ||
423 | 0xB168C381, 0xFDE4E789, 0x5C79B0D8, 0x1E8BFD43, | ||
424 | 0x4D495001, 0x38BE4341, 0x913CEE1D, 0x92A79C3F, | ||
425 | 0x089766BE, 0xBAEEADF4, 0x1286BECF, 0xB6EACB19, | ||
426 | 0x2660C200, 0x7565BDE4, 0x64241F7A, 0x8248DCA9, | ||
427 | 0xC3B3AD66, 0x28136086, 0x0BD8DFA8, 0x356D1CF2, | ||
428 | 0x107789BE, 0xB3B2E9CE, 0x0502AA8F, 0x0BC0351E, | ||
429 | 0x166BF52A, 0xEB12FF82, 0xE3486911, 0xD34D7516, | ||
430 | 0x4E7B3AFF, 0x5F43671B, 0x9CF6E037, 0x4981AC83, | ||
431 | 0x334266CE, 0x8C9341B7, 0xD0D854C0, 0xCB3A6C88, | ||
432 | 0x47BC2829, 0x4725BA37, 0xA66AD22B, 0x7AD61F1E, | ||
433 | 0x0C5CBAFA, 0x4437F107, 0xB6E79962, 0x42D2D816, | ||
434 | 0x0A961288, 0xE1A5C06E, 0x13749E67, 0x72FC081A, | ||
435 | 0xB1D139F7, 0xF9583745, 0xCF19DF58, 0xBEC3F756, | ||
436 | 0xC06EBA30, 0x07211B24, 0x45C28829, 0xC95E317F, | ||
437 | 0xBC8EC511, 0x38BC46E9, 0xC6E6FA14, 0xBAE8584A, | ||
438 | 0xAD4EBC46, 0x468F508B, 0x7829435F, 0xF124183B, | ||
439 | 0x821DBA9F, 0xAFF60FF4, 0xEA2C4E6D, 0x16E39264, | ||
440 | 0x92544A8B, 0x009B4FC3, 0xABA68CED, 0x9AC96F78, | ||
441 | 0x06A5B79A, 0xB2856E6E, 0x1AEC3CA9, 0xBE838688, | ||
442 | 0x0E0804E9, 0x55F1BE56, 0xE7E5363B, 0xB3A1F25D, | ||
443 | 0xF7DEBB85, 0x61FE033C, 0x16746233, 0x3C034C28, | ||
444 | 0xDA6D0C74, 0x79AAC56C, 0x3CE4E1AD, 0x51F0C802, | ||
445 | 0x98F8F35A, 0x1626A49F, 0xEED82B29, 0x1D382FE3, | ||
446 | 0x0C4FB99A, 0xBB325778, 0x3EC6D97B, 0x6E77A6A9, | ||
447 | 0xCB658B5C, 0xD45230C7, 0x2BD1408B, 0x60C03EB7, | ||
448 | 0xB9068D78, 0xA33754F4, 0xF430C87D, 0xC8A71302, | ||
449 | 0xB96D8C32, 0xEBD4E7BE, 0xBE8B9D2D, 0x7979FB06, | ||
450 | 0xE7225308, 0x8B75CF77, 0x11EF8DA4, 0xE083C858, | ||
451 | 0x8D6B786F, 0x5A6317A6, 0xFA5CF7A0, 0x5DDA0033, | ||
452 | 0xF28EBFB0, 0xF5B9C310, 0xA0EAC280, 0x08B9767A, | ||
453 | 0xA3D9D2B0, 0x79D34217, 0x021A718D, 0x9AC6336A, | ||
454 | 0x2711FD60, 0x438050E3, 0x069908A8, 0x3D7FEDC4, | ||
455 | 0x826D2BEF, 0x4EEB8476, 0x488DCF25, 0x36C9D566, | ||
456 | 0x28E74E41, 0xC2610ACA, 0x3D49A9CF, 0xBAE3B9DF, | ||
457 | 0xB65F8DE6, 0x92AEAF64, 0x3AC7D5E6, 0x9EA80509, | ||
458 | 0xF22B017D, 0xA4173F70, 0xDD1E16C3, 0x15E0D7F9, | ||
459 | 0x50B1B887, 0x2B9F4FD5, 0x625ABA82, 0x6A017962, | ||
460 | 0x2EC01B9C, 0x15488AA9, 0xD716E740, 0x40055A2C, | ||
461 | 0x93D29A22, 0xE32DBF9A, 0x058745B9, 0x3453DC1E, | ||
462 | 0xD699296E, 0x496CFF6F, 0x1C9F4986, 0xDFE2ED07, | ||
463 | 0xB87242D1, 0x19DE7EAE, 0x053E561A, 0x15AD6F8C, | ||
464 | 0x66626C1C, 0x7154C24C, 0xEA082B2A, 0x93EB2939, | ||
465 | 0x17DCB0F0, 0x58D4F2AE, 0x9EA294FB, 0x52CF564C, | ||
466 | 0x9883FE66, 0x2EC40581, 0x763953C3, 0x01D6692E, | ||
467 | 0xD3A0C108, 0xA1E7160E, 0xE4F2DFA6, 0x693ED285, | ||
468 | 0x74904698, 0x4C2B0EDD, 0x4F757656, 0x5D393378, | ||
469 | 0xA132234F, 0x3D321C5D, 0xC3F5E194, 0x4B269301, | ||
470 | 0xC79F022F, 0x3C997E7E, 0x5E4F9504, 0x3FFAFBBD, | ||
471 | 0x76F7AD0E, 0x296693F4, 0x3D1FCE6F, 0xC61E45BE, | ||
472 | 0xD3B5AB34, 0xF72BF9B7, 0x1B0434C0, 0x4E72B567, | ||
473 | 0x5592A33D, 0xB5229301, 0xCFD2A87F, 0x60AEB767, | ||
474 | 0x1814386B, 0x30BCC33D, 0x38A0C07D, 0xFD1606F2, | ||
475 | 0xC363519B, 0x589DD390, 0x5479F8E6, 0x1CB8D647, | ||
476 | 0x97FD61A9, 0xEA7759F4, 0x2D57539D, 0x569A58CF, | ||
477 | 0xE84E63AD, 0x462E1B78, 0x6580F87E, 0xF3817914, | ||
478 | 0x91DA55F4, 0x40A230F3, 0xD1988F35, 0xB6E318D2, | ||
479 | 0x3FFA50BC, 0x3D40F021, 0xC3C0BDAE, 0x4958C24C, | ||
480 | 0x518F36B2, 0x84B1D370, 0x0FEDCE83, 0x878DDADA, | ||
481 | 0xF2A279C7, 0x94E01BE8, 0x90716F4B, 0x954B8AA3 | ||
482 | }; | ||
483 | |||
484 | static const u_int32_t cast_sbox8[256] = { | ||
485 | 0xE216300D, 0xBBDDFFFC, 0xA7EBDABD, 0x35648095, | ||
486 | 0x7789F8B7, 0xE6C1121B, 0x0E241600, 0x052CE8B5, | ||
487 | 0x11A9CFB0, 0xE5952F11, 0xECE7990A, 0x9386D174, | ||
488 | 0x2A42931C, 0x76E38111, 0xB12DEF3A, 0x37DDDDFC, | ||
489 | 0xDE9ADEB1, 0x0A0CC32C, 0xBE197029, 0x84A00940, | ||
490 | 0xBB243A0F, 0xB4D137CF, 0xB44E79F0, 0x049EEDFD, | ||
491 | 0x0B15A15D, 0x480D3168, 0x8BBBDE5A, 0x669DED42, | ||
492 | 0xC7ECE831, 0x3F8F95E7, 0x72DF191B, 0x7580330D, | ||
493 | 0x94074251, 0x5C7DCDFA, 0xABBE6D63, 0xAA402164, | ||
494 | 0xB301D40A, 0x02E7D1CA, 0x53571DAE, 0x7A3182A2, | ||
495 | 0x12A8DDEC, 0xFDAA335D, 0x176F43E8, 0x71FB46D4, | ||
496 | 0x38129022, 0xCE949AD4, 0xB84769AD, 0x965BD862, | ||
497 | 0x82F3D055, 0x66FB9767, 0x15B80B4E, 0x1D5B47A0, | ||
498 | 0x4CFDE06F, 0xC28EC4B8, 0x57E8726E, 0x647A78FC, | ||
499 | 0x99865D44, 0x608BD593, 0x6C200E03, 0x39DC5FF6, | ||
500 | 0x5D0B00A3, 0xAE63AFF2, 0x7E8BD632, 0x70108C0C, | ||
501 | 0xBBD35049, 0x2998DF04, 0x980CF42A, 0x9B6DF491, | ||
502 | 0x9E7EDD53, 0x06918548, 0x58CB7E07, 0x3B74EF2E, | ||
503 | 0x522FFFB1, 0xD24708CC, 0x1C7E27CD, 0xA4EB215B, | ||
504 | 0x3CF1D2E2, 0x19B47A38, 0x424F7618, 0x35856039, | ||
505 | 0x9D17DEE7, 0x27EB35E6, 0xC9AFF67B, 0x36BAF5B8, | ||
506 | 0x09C467CD, 0xC18910B1, 0xE11DBF7B, 0x06CD1AF8, | ||
507 | 0x7170C608, 0x2D5E3354, 0xD4DE495A, 0x64C6D006, | ||
508 | 0xBCC0C62C, 0x3DD00DB3, 0x708F8F34, 0x77D51B42, | ||
509 | 0x264F620F, 0x24B8D2BF, 0x15C1B79E, 0x46A52564, | ||
510 | 0xF8D7E54E, 0x3E378160, 0x7895CDA5, 0x859C15A5, | ||
511 | 0xE6459788, 0xC37BC75F, 0xDB07BA0C, 0x0676A3AB, | ||
512 | 0x7F229B1E, 0x31842E7B, 0x24259FD7, 0xF8BEF472, | ||
513 | 0x835FFCB8, 0x6DF4C1F2, 0x96F5B195, 0xFD0AF0FC, | ||
514 | 0xB0FE134C, 0xE2506D3D, 0x4F9B12EA, 0xF215F225, | ||
515 | 0xA223736F, 0x9FB4C428, 0x25D04979, 0x34C713F8, | ||
516 | 0xC4618187, 0xEA7A6E98, 0x7CD16EFC, 0x1436876C, | ||
517 | 0xF1544107, 0xBEDEEE14, 0x56E9AF27, 0xA04AA441, | ||
518 | 0x3CF7C899, 0x92ECBAE6, 0xDD67016D, 0x151682EB, | ||
519 | 0xA842EEDF, 0xFDBA60B4, 0xF1907B75, 0x20E3030F, | ||
520 | 0x24D8C29E, 0xE139673B, 0xEFA63FB8, 0x71873054, | ||
521 | 0xB6F2CF3B, 0x9F326442, 0xCB15A4CC, 0xB01A4504, | ||
522 | 0xF1E47D8D, 0x844A1BE5, 0xBAE7DFDC, 0x42CBDA70, | ||
523 | 0xCD7DAE0A, 0x57E85B7A, 0xD53F5AF6, 0x20CF4D8C, | ||
524 | 0xCEA4D428, 0x79D130A4, 0x3486EBFB, 0x33D3CDDC, | ||
525 | 0x77853B53, 0x37EFFCB5, 0xC5068778, 0xE580B3E6, | ||
526 | 0x4E68B8F4, 0xC5C8B37E, 0x0D809EA2, 0x398FEB7C, | ||
527 | 0x132A4F94, 0x43B7950E, 0x2FEE7D1C, 0x223613BD, | ||
528 | 0xDD06CAA2, 0x37DF932B, 0xC4248289, 0xACF3EBC3, | ||
529 | 0x5715F6B7, 0xEF3478DD, 0xF267616F, 0xC148CBE4, | ||
530 | 0x9052815E, 0x5E410FAB, 0xB48A2465, 0x2EDA7FA4, | ||
531 | 0xE87B40E4, 0xE98EA084, 0x5889E9E1, 0xEFD390FC, | ||
532 | 0xDD07D35B, 0xDB485694, 0x38D7E5B2, 0x57720101, | ||
533 | 0x730EDEBC, 0x5B643113, 0x94917E4F, 0x503C2FBA, | ||
534 | 0x646F1282, 0x7523D24A, 0xE0779695, 0xF9C17A8F, | ||
535 | 0x7A5B2121, 0xD187B896, 0x29263A4D, 0xBA510CDF, | ||
536 | 0x81F47C9F, 0xAD1163ED, 0xEA7B5965, 0x1A00726E, | ||
537 | 0x11403092, 0x00DA6D77, 0x4A0CDD61, 0xAD1F4603, | ||
538 | 0x605BDFB0, 0x9EEDC364, 0x22EBE6A8, 0xCEE7D28A, | ||
539 | 0xA0E736A0, 0x5564A6B9, 0x10853209, 0xC7EB8F37, | ||
540 | 0x2DE705CA, 0x8951570F, 0xDF09822B, 0xBD691A6C, | ||
541 | 0xAA12E4F2, 0x87451C0F, 0xE0F6A27A, 0x3ADA4819, | ||
542 | 0x4CF1764F, 0x0D771C2B, 0x67CDB156, 0x350D8384, | ||
543 | 0x5938FA0F, 0x42399EF3, 0x36997B07, 0x0E84093D, | ||
544 | 0x4AA93E61, 0x8360D87B, 0x1FA98B0C, 0x1149382C, | ||
545 | 0xE97625A5, 0x0614D1B7, 0x0E25244B, 0x0C768347, | ||
546 | 0x589E8D82, 0x0D2059D1, 0xA466BB1E, 0xF8DA0A82, | ||
547 | 0x04F19130, 0xBA6E4EC0, 0x99265164, 0x1EE7230D, | ||
548 | 0x50B2AD80, 0xEAEE6801, 0x8DB2A283, 0xEA8BF59E | ||
549 | }; | ||
550 | |||
551 | /* Macros to access 8-bit bytes out of a 32-bit word */ | ||
552 | #define U8a(x) ( (u_int8_t) (x>>24) ) | ||
553 | #define U8b(x) ( (u_int8_t) ((x>>16)&255) ) | ||
554 | #define U8c(x) ( (u_int8_t) ((x>>8)&255) ) | ||
555 | #define U8d(x) ( (u_int8_t) ((x)&255) ) | ||
556 | |||
557 | /* Circular left shift */ | ||
558 | #define ROL(x, n) ( ((x)<<(n)) | ((x)>>(32-(n))) ) | ||
559 | |||
560 | /* CAST-128 uses three different round functions */ | ||
561 | #define F1(l, r, i) \ | ||
562 | t = ROL(key->xkey[i] + r, key->xkey[i+16]); \ | ||
563 | l ^= ((cast_sbox1[U8a(t)] ^ cast_sbox2[U8b(t)]) - \ | ||
564 | cast_sbox3[U8c(t)]) + cast_sbox4[U8d(t)]; | ||
565 | #define F2(l, r, i) \ | ||
566 | t = ROL(key->xkey[i] ^ r, key->xkey[i+16]); \ | ||
567 | l ^= ((cast_sbox1[U8a(t)] - cast_sbox2[U8b(t)]) + \ | ||
568 | cast_sbox3[U8c(t)]) ^ cast_sbox4[U8d(t)]; | ||
569 | #define F3(l, r, i) \ | ||
570 | t = ROL(key->xkey[i] - r, key->xkey[i+16]); \ | ||
571 | l ^= ((cast_sbox1[U8a(t)] + cast_sbox2[U8b(t)]) ^ \ | ||
572 | cast_sbox3[U8c(t)]) - cast_sbox4[U8d(t)]; | ||
573 | |||
574 | |||
575 | /***** Encryption Function *****/ | ||
576 | |||
577 | void cast_encrypt(cast_key* key, u_int8_t* inblock, u_int8_t* outblock) | ||
578 | { | ||
579 | u_int32_t t, l, r; | ||
580 | |||
581 | /* Get inblock into l,r */ | ||
582 | l = ((u_int32_t)inblock[0] << 24) | ((u_int32_t)inblock[1] << 16) | | ||
583 | ((u_int32_t)inblock[2] << 8) | (u_int32_t)inblock[3]; | ||
584 | r = ((u_int32_t)inblock[4] << 24) | ((u_int32_t)inblock[5] << 16) | | ||
585 | ((u_int32_t)inblock[6] << 8) | (u_int32_t)inblock[7]; | ||
586 | /* Do the work */ | ||
587 | F1(l, r, 0); | ||
588 | F2(r, l, 1); | ||
589 | F3(l, r, 2); | ||
590 | F1(r, l, 3); | ||
591 | F2(l, r, 4); | ||
592 | F3(r, l, 5); | ||
593 | F1(l, r, 6); | ||
594 | F2(r, l, 7); | ||
595 | F3(l, r, 8); | ||
596 | F1(r, l, 9); | ||
597 | F2(l, r, 10); | ||
598 | F3(r, l, 11); | ||
599 | /* Only do full 16 rounds if key length > 80 bits */ | ||
600 | if (key->rounds > 12) { | ||
601 | F1(l, r, 12); | ||
602 | F2(r, l, 13); | ||
603 | F3(l, r, 14); | ||
604 | F1(r, l, 15); | ||
605 | } | ||
606 | /* Put l,r into outblock */ | ||
607 | outblock[0] = U8a(r); | ||
608 | outblock[1] = U8b(r); | ||
609 | outblock[2] = U8c(r); | ||
610 | outblock[3] = U8d(r); | ||
611 | outblock[4] = U8a(l); | ||
612 | outblock[5] = U8b(l); | ||
613 | outblock[6] = U8c(l); | ||
614 | outblock[7] = U8d(l); | ||
615 | /* Wipe clean */ | ||
616 | t = l = r = 0; | ||
617 | } | ||
618 | |||
619 | |||
620 | /***** Decryption Function *****/ | ||
621 | |||
622 | void cast_decrypt(cast_key* key, u_int8_t* inblock, u_int8_t* outblock) | ||
623 | { | ||
624 | u_int32_t t, l, r; | ||
625 | |||
626 | /* Get inblock into l,r */ | ||
627 | r = ((u_int32_t)inblock[0] << 24) | ((u_int32_t)inblock[1] << 16) | | ||
628 | ((u_int32_t)inblock[2] << 8) | (u_int32_t)inblock[3]; | ||
629 | l = ((u_int32_t)inblock[4] << 24) | ((u_int32_t)inblock[5] << 16) | | ||
630 | ((u_int32_t)inblock[6] << 8) | (u_int32_t)inblock[7]; | ||
631 | /* Do the work */ | ||
632 | /* Only do full 16 rounds if key length > 80 bits */ | ||
633 | if (key->rounds > 12) { | ||
634 | F1(r, l, 15); | ||
635 | F3(l, r, 14); | ||
636 | F2(r, l, 13); | ||
637 | F1(l, r, 12); | ||
638 | } | ||
639 | F3(r, l, 11); | ||
640 | F2(l, r, 10); | ||
641 | F1(r, l, 9); | ||
642 | F3(l, r, 8); | ||
643 | F2(r, l, 7); | ||
644 | F1(l, r, 6); | ||
645 | F3(r, l, 5); | ||
646 | F2(l, r, 4); | ||
647 | F1(r, l, 3); | ||
648 | F3(l, r, 2); | ||
649 | F2(r, l, 1); | ||
650 | F1(l, r, 0); | ||
651 | /* Put l,r into outblock */ | ||
652 | outblock[0] = U8a(l); | ||
653 | outblock[1] = U8b(l); | ||
654 | outblock[2] = U8c(l); | ||
655 | outblock[3] = U8d(l); | ||
656 | outblock[4] = U8a(r); | ||
657 | outblock[5] = U8b(r); | ||
658 | outblock[6] = U8c(r); | ||
659 | outblock[7] = U8d(r); | ||
660 | /* Wipe clean */ | ||
661 | t = l = r = 0; | ||
662 | } | ||
663 | |||
664 | |||
665 | /***** Key Schedual *****/ | ||
666 | |||
667 | void cast_setkey(cast_key* key, u_int8_t* rawkey, int keybytes) | ||
668 | { | ||
669 | u_int32_t t[4], z[4], x[4]; | ||
670 | int i; | ||
671 | |||
672 | /* Set number of rounds to 12 or 16, depending on key length */ | ||
673 | key->rounds = (keybytes <= 10 ? 12 : 16); | ||
674 | |||
675 | /* Copy key to workspace x */ | ||
676 | for (i = 0; i < 4; i++) { | ||
677 | x[i] = 0; | ||
678 | if ((i*4+0) < keybytes) x[i] = (u_int32_t)rawkey[i*4+0] << 24; | ||
679 | if ((i*4+1) < keybytes) x[i] |= (u_int32_t)rawkey[i*4+1] << 16; | ||
680 | if ((i*4+2) < keybytes) x[i] |= (u_int32_t)rawkey[i*4+2] << 8; | ||
681 | if ((i*4+3) < keybytes) x[i] |= (u_int32_t)rawkey[i*4+3]; | ||
682 | } | ||
683 | /* Generate 32 subkeys, four at a time */ | ||
684 | for (i = 0; i < 32; i+=4) { | ||
685 | switch (i & 4) { | ||
686 | case 0: | ||
687 | t[0] = z[0] = x[0] ^ cast_sbox5[U8b(x[3])] ^ | ||
688 | cast_sbox6[U8d(x[3])] ^ cast_sbox7[U8a(x[3])] ^ | ||
689 | cast_sbox8[U8c(x[3])] ^ cast_sbox7[U8a(x[2])]; | ||
690 | t[1] = z[1] = x[2] ^ cast_sbox5[U8a(z[0])] ^ | ||
691 | cast_sbox6[U8c(z[0])] ^ cast_sbox7[U8b(z[0])] ^ | ||
692 | cast_sbox8[U8d(z[0])] ^ cast_sbox8[U8c(x[2])]; | ||
693 | t[2] = z[2] = x[3] ^ cast_sbox5[U8d(z[1])] ^ | ||
694 | cast_sbox6[U8c(z[1])] ^ cast_sbox7[U8b(z[1])] ^ | ||
695 | cast_sbox8[U8a(z[1])] ^ cast_sbox5[U8b(x[2])]; | ||
696 | t[3] = z[3] = x[1] ^ cast_sbox5[U8c(z[2])] ^ | ||
697 | cast_sbox6[U8b(z[2])] ^ cast_sbox7[U8d(z[2])] ^ | ||
698 | cast_sbox8[U8a(z[2])] ^ cast_sbox6[U8d(x[2])]; | ||
699 | break; | ||
700 | case 4: | ||
701 | t[0] = x[0] = z[2] ^ cast_sbox5[U8b(z[1])] ^ | ||
702 | cast_sbox6[U8d(z[1])] ^ cast_sbox7[U8a(z[1])] ^ | ||
703 | cast_sbox8[U8c(z[1])] ^ cast_sbox7[U8a(z[0])]; | ||
704 | t[1] = x[1] = z[0] ^ cast_sbox5[U8a(x[0])] ^ | ||
705 | cast_sbox6[U8c(x[0])] ^ cast_sbox7[U8b(x[0])] ^ | ||
706 | cast_sbox8[U8d(x[0])] ^ cast_sbox8[U8c(z[0])]; | ||
707 | t[2] = x[2] = z[1] ^ cast_sbox5[U8d(x[1])] ^ | ||
708 | cast_sbox6[U8c(x[1])] ^ cast_sbox7[U8b(x[1])] ^ | ||
709 | cast_sbox8[U8a(x[1])] ^ cast_sbox5[U8b(z[0])]; | ||
710 | t[3] = x[3] = z[3] ^ cast_sbox5[U8c(x[2])] ^ | ||
711 | cast_sbox6[U8b(x[2])] ^ cast_sbox7[U8d(x[2])] ^ | ||
712 | cast_sbox8[U8a(x[2])] ^ cast_sbox6[U8d(z[0])]; | ||
713 | break; | ||
714 | } | ||
715 | switch (i & 12) { | ||
716 | case 0: | ||
717 | case 12: | ||
718 | key->xkey[i+0] = cast_sbox5[U8a(t[2])] ^ cast_sbox6[U8b(t[2])] ^ | ||
719 | cast_sbox7[U8d(t[1])] ^ cast_sbox8[U8c(t[1])]; | ||
720 | key->xkey[i+1] = cast_sbox5[U8c(t[2])] ^ cast_sbox6[U8d(t[2])] ^ | ||
721 | cast_sbox7[U8b(t[1])] ^ cast_sbox8[U8a(t[1])]; | ||
722 | key->xkey[i+2] = cast_sbox5[U8a(t[3])] ^ cast_sbox6[U8b(t[3])] ^ | ||
723 | cast_sbox7[U8d(t[0])] ^ cast_sbox8[U8c(t[0])]; | ||
724 | key->xkey[i+3] = cast_sbox5[U8c(t[3])] ^ cast_sbox6[U8d(t[3])] ^ | ||
725 | cast_sbox7[U8b(t[0])] ^ cast_sbox8[U8a(t[0])]; | ||
726 | break; | ||
727 | case 4: | ||
728 | case 8: | ||
729 | key->xkey[i+0] = cast_sbox5[U8d(t[0])] ^ cast_sbox6[U8c(t[0])] ^ | ||
730 | cast_sbox7[U8a(t[3])] ^ cast_sbox8[U8b(t[3])]; | ||
731 | key->xkey[i+1] = cast_sbox5[U8b(t[0])] ^ cast_sbox6[U8a(t[0])] ^ | ||
732 | cast_sbox7[U8c(t[3])] ^ cast_sbox8[U8d(t[3])]; | ||
733 | key->xkey[i+2] = cast_sbox5[U8d(t[1])] ^ cast_sbox6[U8c(t[1])] ^ | ||
734 | cast_sbox7[U8a(t[2])] ^ cast_sbox8[U8b(t[2])]; | ||
735 | key->xkey[i+3] = cast_sbox5[U8b(t[1])] ^ cast_sbox6[U8a(t[1])] ^ | ||
736 | cast_sbox7[U8c(t[2])] ^ cast_sbox8[U8d(t[2])]; | ||
737 | break; | ||
738 | } | ||
739 | switch (i & 12) { | ||
740 | case 0: | ||
741 | key->xkey[i+0] ^= cast_sbox5[U8c(z[0])]; | ||
742 | key->xkey[i+1] ^= cast_sbox6[U8c(z[1])]; | ||
743 | key->xkey[i+2] ^= cast_sbox7[U8b(z[2])]; | ||
744 | key->xkey[i+3] ^= cast_sbox8[U8a(z[3])]; | ||
745 | break; | ||
746 | case 4: | ||
747 | key->xkey[i+0] ^= cast_sbox5[U8a(x[2])]; | ||
748 | key->xkey[i+1] ^= cast_sbox6[U8b(x[3])]; | ||
749 | key->xkey[i+2] ^= cast_sbox7[U8d(x[0])]; | ||
750 | key->xkey[i+3] ^= cast_sbox8[U8d(x[1])]; | ||
751 | break; | ||
752 | case 8: | ||
753 | key->xkey[i+0] ^= cast_sbox5[U8b(z[2])]; | ||
754 | key->xkey[i+1] ^= cast_sbox6[U8a(z[3])]; | ||
755 | key->xkey[i+2] ^= cast_sbox7[U8c(z[0])]; | ||
756 | key->xkey[i+3] ^= cast_sbox8[U8c(z[1])]; | ||
757 | break; | ||
758 | case 12: | ||
759 | key->xkey[i+0] ^= cast_sbox5[U8d(x[0])]; | ||
760 | key->xkey[i+1] ^= cast_sbox6[U8d(x[1])]; | ||
761 | key->xkey[i+2] ^= cast_sbox7[U8a(x[2])]; | ||
762 | key->xkey[i+3] ^= cast_sbox8[U8b(x[3])]; | ||
763 | break; | ||
764 | } | ||
765 | if (i >= 16) { | ||
766 | key->xkey[i+0] &= 31; | ||
767 | key->xkey[i+1] &= 31; | ||
768 | key->xkey[i+2] &= 31; | ||
769 | key->xkey[i+3] &= 31; | ||
770 | } | ||
771 | } | ||
772 | /* Wipe clean */ | ||
773 | for (i = 0; i < 4; i++) { | ||
774 | t[i] = x[i] = z[i] = 0; | ||
775 | } | ||
776 | } | ||
777 | |||
778 | /* Made in Canada */ | ||
779 | |||
diff --git a/src/lib/libc/crypt/crypt.3 b/src/lib/libc/crypt/crypt.3 new file mode 100644 index 0000000000..524645de55 --- /dev/null +++ b/src/lib/libc/crypt/crypt.3 | |||
@@ -0,0 +1,298 @@ | |||
1 | .\" $OpenBSD: crypt.3,v 1.11 1998/02/27 12:17:45 deraadt Exp $ | ||
2 | .\" | ||
3 | .\" FreeSec: libcrypt | ||
4 | .\" | ||
5 | .\" Copyright (c) 1994 David Burren | ||
6 | .\" All rights reserved. | ||
7 | .\" | ||
8 | .\" Redistribution and use in source and binary forms, with or without | ||
9 | .\" modification, are permitted provided that the following conditions | ||
10 | .\" are met: | ||
11 | .\" 1. Redistributions of source code must retain the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer. | ||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer in the | ||
15 | .\" documentation and/or other materials provided with the distribution. | ||
16 | .\" 4. Neither the name of the author nor the names of other contributors | ||
17 | .\" may be used to endorse or promote products derived from this software | ||
18 | .\" without specific prior written permission. | ||
19 | .\" | ||
20 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
30 | .\" SUCH DAMAGE. | ||
31 | .\" | ||
32 | .\" Manual page, using -mandoc macros | ||
33 | .\" | ||
34 | .Dd March 9, 1994 | ||
35 | .Dt CRYPT 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm crypt , | ||
39 | .Nm setkey , | ||
40 | .Nm encrypt , | ||
41 | .Nm des_setkey , | ||
42 | .Nm des_cipher | ||
43 | .Nd DES encryption | ||
44 | .Sh SYNOPSIS | ||
45 | .Fd #include <unistd.h> | ||
46 | .Ft char | ||
47 | .Fn *crypt "const char *key" "const char *setting" | ||
48 | .Ft int | ||
49 | .Fn setkey "char *key" | ||
50 | .Ft int | ||
51 | .Fn encrypt "char *block" "int flag" | ||
52 | .Ft int | ||
53 | .Fn des_setkey "const char *key" | ||
54 | .Ft int | ||
55 | .Fn des_cipher "const char *in" "char *out" "int32_t salt" "int count" | ||
56 | .Sh DESCRIPTION | ||
57 | The | ||
58 | .Fn crypt | ||
59 | function performs password encryption, based on the | ||
60 | .Tn NBS | ||
61 | Data Encryption Standard (DES). | ||
62 | Additional code has been added to deter key search attempts and to use | ||
63 | stronger hashing algorithms. | ||
64 | The first argument to | ||
65 | .Fn crypt | ||
66 | is a | ||
67 | .Dv null Ns -terminated | ||
68 | string, typically a user's typed password. | ||
69 | The second is in one of three forms: | ||
70 | if it begins with an underscore (``_'') then an extended format is used | ||
71 | in interpreting both the key and the setting, as outlined below. If it begins | ||
72 | with an string character (``$'') and a number then a different algorithm | ||
73 | is used depending on the number. At the moment a ``$1'' chooses MD5 hashing | ||
74 | and a ``$2'' chooses Blowfish hashing, see below for more information. | ||
75 | .Ss Extended crypt: | ||
76 | .Pp | ||
77 | The | ||
78 | .Ar key | ||
79 | is divided into groups of 8 characters (the last group is null-padded) | ||
80 | and the low-order 7 bits of each each character (56 bits per group) are | ||
81 | used to form the DES key as follows: | ||
82 | the first group of 56 bits becomes the initial DES key. | ||
83 | For each additional group, the XOR of the encryption of the current DES | ||
84 | key with itself and the group bits becomes the next DES key. | ||
85 | .Pp | ||
86 | The setting is a 9-character array consisting of an underscore followed | ||
87 | by 4 bytes of iteration count and 4 bytes of salt. | ||
88 | These are encoded as printable characters, 6 bits per character, | ||
89 | least significant character first. | ||
90 | The values 0 to 63 are encoded as ``./0-9A-Za-z''. | ||
91 | This allows 24 bits for both | ||
92 | .Fa count | ||
93 | and | ||
94 | .Fa salt . | ||
95 | .Ss "MD5" crypt: | ||
96 | .Pp | ||
97 | For | ||
98 | .Tn MD5 | ||
99 | crypt the version number, | ||
100 | .Fa salt | ||
101 | and the hashed password are separated | ||
102 | by the ``$'' character. The maximum length of a password is limited by | ||
103 | the length counter of the MD5 context, which is about | ||
104 | 2**64. A valid MD5 password entry looks like this: | ||
105 | .Pp | ||
106 | ``$1$caeiHQwX$hsKqOjrFRRN6K32OWkCBf1''. | ||
107 | .Pp | ||
108 | The whole MD5 password string is passed as | ||
109 | .Fa setting | ||
110 | for interpretation. | ||
111 | .Ss "Blowfish" crypt: | ||
112 | .Pp | ||
113 | The | ||
114 | .Tn Blowfish | ||
115 | version of crypt has 128 bits of | ||
116 | .Fa salt | ||
117 | in order to make building | ||
118 | dictionaries of common passwords space consuming. The initial state | ||
119 | of the | ||
120 | .Tn Blowfish | ||
121 | cipher is expanded using the | ||
122 | .Fa salt | ||
123 | and the | ||
124 | .Fa password | ||
125 | repeating the process a variable number of rounds, which is encoded in | ||
126 | the password string. The maximum password length is 72. The final Blowfish | ||
127 | password entry is created by encrypting | ||
128 | the string ``OrpheanBeholderScryDoubt'' with the | ||
129 | .Tn Blowfish | ||
130 | state 64 times. | ||
131 | .Pp | ||
132 | The version number, the logarithm of the number of rounds and | ||
133 | the concatenation of salt and | ||
134 | hashed password are separated by the ``$'' character. An encoded ``8'' | ||
135 | would specify 256 rounds. | ||
136 | A valid Blowfish password looks like this: | ||
137 | .Pp | ||
138 | ``$2a$12$eIAq8PR8sIUnJ1HaohxX2O9x9Qlm2vK97LJ5dsXdmB.eXF42qjchC''. | ||
139 | .Pp | ||
140 | The whole Blowfish password string is passed as | ||
141 | .Fa setting | ||
142 | for interpretation. | ||
143 | .Ss "Traditional" crypt: | ||
144 | .Pp | ||
145 | The first 8 bytes of the key are null-padded, and the low-order 7 bits of | ||
146 | each character is used to form the 56-bit | ||
147 | .Tn DES | ||
148 | key. | ||
149 | .Pp | ||
150 | The setting is a 2-character array of the ASCII-encoded salt. | ||
151 | Thus only 12 bits of | ||
152 | .Fa salt | ||
153 | are used. | ||
154 | .Fa count | ||
155 | is set to 25. | ||
156 | .Ss DES Algorithm: | ||
157 | .Pp | ||
158 | The | ||
159 | .Fa salt | ||
160 | introduces disorder in the | ||
161 | .Tn DES | ||
162 | algorithm in one of 16777216 or 4096 possible ways | ||
163 | (ie. with 24 or 12 bits: if bit | ||
164 | .Em i | ||
165 | of the | ||
166 | .Ar salt | ||
167 | is set, then bits | ||
168 | .Em i | ||
169 | and | ||
170 | .Em i+24 | ||
171 | are swapped in the | ||
172 | .Tn DES | ||
173 | E-box output). | ||
174 | .Pp | ||
175 | The DES key is used to encrypt a 64-bit constant using | ||
176 | .Ar count | ||
177 | iterations of | ||
178 | .Tn DES . | ||
179 | The value returned is a | ||
180 | .Dv null Ns -terminated | ||
181 | string, 20 or 13 bytes (plus null) in length, consisting of the | ||
182 | .Ar setting | ||
183 | followed by the encoded 64-bit encryption. | ||
184 | .Pp | ||
185 | The functions, | ||
186 | .Fn encrypt , | ||
187 | .Fn setkey , | ||
188 | .Fn des_setkey | ||
189 | and | ||
190 | .Fn des_cipher | ||
191 | provide access to the | ||
192 | .Tn DES | ||
193 | algorithm itself. | ||
194 | .Fn setkey | ||
195 | is passed a 64-byte array of binary values (numeric 0 or 1). | ||
196 | A 56-bit key is extracted from this array by dividing the | ||
197 | array into groups of 8, and ignoring the last bit in each group. | ||
198 | That bit is reserved for a byte parity check by DES, but is ignored | ||
199 | by these functions. | ||
200 | .Pp | ||
201 | The | ||
202 | .Fa block | ||
203 | argument to | ||
204 | .Fn encrypt | ||
205 | is also a 64-byte array of binary values. | ||
206 | If the value of | ||
207 | .Fa flag | ||
208 | is 0, | ||
209 | .Fa block | ||
210 | is encrypted otherwise it is decrypted. | ||
211 | The result is returned in the original array | ||
212 | .Fa block | ||
213 | after using the key specified by | ||
214 | .Fn setkey | ||
215 | to process it. | ||
216 | .Pp | ||
217 | The argument to | ||
218 | .Fn des_setkey | ||
219 | is a character array of length 8. | ||
220 | The least significant bit (the parity bit) in each character is ignored, | ||
221 | and the remaining bits are concatenated to form a 56-bit key. | ||
222 | The function | ||
223 | .Fn des_cipher | ||
224 | encrypts (or decrypts if | ||
225 | .Fa count | ||
226 | is negative) the 64-bits stored in the 8 characters at | ||
227 | .Fa in | ||
228 | using | ||
229 | .Xr abs 3 | ||
230 | of | ||
231 | .Fa count | ||
232 | iterations of | ||
233 | .Tn DES | ||
234 | and stores the 64-bit result in the 8 characters at | ||
235 | .Fa out | ||
236 | (which may be the same as | ||
237 | .Fa in | ||
238 | ). | ||
239 | The | ||
240 | .Fa salt | ||
241 | specifies perturbations to the | ||
242 | .Tn DES | ||
243 | E-box output as described above. | ||
244 | .Pp | ||
245 | The function | ||
246 | .Fn crypt | ||
247 | returns a pointer to the encrypted value on success, and NULL on failure. | ||
248 | The functions | ||
249 | .Fn setkey , | ||
250 | .Fn encrypt , | ||
251 | .Fn des_setkey , | ||
252 | and | ||
253 | .Fn des_cipher | ||
254 | return 0 on success and 1 on failure. | ||
255 | .Pp | ||
256 | The | ||
257 | .Fn crypt , | ||
258 | .Fn setkey | ||
259 | and | ||
260 | .Fn des_setkey | ||
261 | functions all manipulate the same key space. | ||
262 | .Sh SEE ALSO | ||
263 | .Xr login 1 , | ||
264 | .Xr passwd 1 , | ||
265 | .Xr blowfish 3 , | ||
266 | .Xr getpass 3 , | ||
267 | .Xr md5 3 , | ||
268 | .Xr passwd 5 | ||
269 | .Sh BUGS | ||
270 | The | ||
271 | .Fn crypt | ||
272 | function returns a pointer to static data, and subsequent calls to | ||
273 | .Fn crypt | ||
274 | will modify the same object. | ||
275 | .Sh HISTORY | ||
276 | A rotor-based | ||
277 | .Fn crypt | ||
278 | function appeared in | ||
279 | .At v6 . | ||
280 | The current style | ||
281 | .Fn crypt | ||
282 | first appeared in | ||
283 | .At v7 . | ||
284 | .Pp | ||
285 | This library (FreeSec 1.0) was developed outside the United States of America | ||
286 | as an unencumbered replacement for the U.S.-only libcrypt encryption | ||
287 | library. | ||
288 | Programs linked against the | ||
289 | .Fn crypt | ||
290 | interface may be exported from the U.S.A. only if they use | ||
291 | .Fn crypt | ||
292 | solely for authentication purposes and avoid use of | ||
293 | the other programmer interfaces listed above. Special care has been taken | ||
294 | in the library so that programs which only use the | ||
295 | .Fn crypt | ||
296 | interface do not pull in the other components. | ||
297 | .Sh AUTHOR | ||
298 | David Burren <davidb@werj.com.au> | ||
diff --git a/src/lib/libc/crypt/crypt.c b/src/lib/libc/crypt/crypt.c new file mode 100644 index 0000000000..8fd319a4f3 --- /dev/null +++ b/src/lib/libc/crypt/crypt.c | |||
@@ -0,0 +1,714 @@ | |||
1 | /* $OpenBSD: crypt.c,v 1.13 1998/03/22 19:01:18 niklas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * FreeSec: libcrypt | ||
5 | * | ||
6 | * Copyright (c) 1994 David Burren | ||
7 | * All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * 2. Redistributions in binary form must reproduce the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer in the | ||
16 | * documentation and/or other materials provided with the distribution. | ||
17 | * 4. Neither the name of the author nor the names of other contributors | ||
18 | * may be used to endorse or promote products derived from this software | ||
19 | * without specific prior written permission. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
31 | * SUCH DAMAGE. | ||
32 | * | ||
33 | * | ||
34 | * This is an original implementation of the DES and the crypt(3) interfaces | ||
35 | * by David Burren <davidb@werj.com.au>. | ||
36 | * | ||
37 | * An excellent reference on the underlying algorithm (and related | ||
38 | * algorithms) is: | ||
39 | * | ||
40 | * B. Schneier, Applied Cryptography: protocols, algorithms, | ||
41 | * and source code in C, John Wiley & Sons, 1994. | ||
42 | * | ||
43 | * Note that in that book's description of DES the lookups for the initial, | ||
44 | * pbox, and final permutations are inverted (this has been brought to the | ||
45 | * attention of the author). A list of errata for this book has been | ||
46 | * posted to the sci.crypt newsgroup by the author and is available for FTP. | ||
47 | * | ||
48 | * NOTE: | ||
49 | * This file has a static version of des_setkey() so that crypt.o exports | ||
50 | * only the crypt() interface. This is required to make binaries linked | ||
51 | * against crypt.o exportable or re-exportable from the USA. | ||
52 | */ | ||
53 | |||
54 | #if defined(LIBC_SCCS) && !defined(lint) | ||
55 | static char rcsid[] = "$OpenBSD: crypt.c,v 1.13 1998/03/22 19:01:18 niklas Exp $"; | ||
56 | #endif /* LIBC_SCCS and not lint */ | ||
57 | |||
58 | #include <sys/types.h> | ||
59 | #include <sys/param.h> | ||
60 | #include <pwd.h> | ||
61 | #include <string.h> | ||
62 | |||
63 | #ifdef DEBUG | ||
64 | # include <stdio.h> | ||
65 | #endif | ||
66 | |||
67 | static u_char IP[64] = { | ||
68 | 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, | ||
69 | 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, | ||
70 | 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, | ||
71 | 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 | ||
72 | }; | ||
73 | |||
74 | static u_char inv_key_perm[64]; | ||
75 | static u_char u_key_perm[56]; | ||
76 | static u_char key_perm[56] = { | ||
77 | 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, | ||
78 | 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, | ||
79 | 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, | ||
80 | 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 | ||
81 | }; | ||
82 | |||
83 | static u_char key_shifts[16] = { | ||
84 | 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 | ||
85 | }; | ||
86 | |||
87 | static u_char inv_comp_perm[56]; | ||
88 | static u_char comp_perm[48] = { | ||
89 | 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, | ||
90 | 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, | ||
91 | 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, | ||
92 | 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 | ||
93 | }; | ||
94 | |||
95 | /* | ||
96 | * No E box is used, as it's replaced by some ANDs, shifts, and ORs. | ||
97 | */ | ||
98 | |||
99 | static u_char u_sbox[8][64]; | ||
100 | static u_char sbox[8][64] = { | ||
101 | { | ||
102 | 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, | ||
103 | 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, | ||
104 | 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, | ||
105 | 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 | ||
106 | }, | ||
107 | { | ||
108 | 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, | ||
109 | 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, | ||
110 | 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, | ||
111 | 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 | ||
112 | }, | ||
113 | { | ||
114 | 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, | ||
115 | 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, | ||
116 | 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, | ||
117 | 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 | ||
118 | }, | ||
119 | { | ||
120 | 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, | ||
121 | 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, | ||
122 | 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, | ||
123 | 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 | ||
124 | }, | ||
125 | { | ||
126 | 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, | ||
127 | 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, | ||
128 | 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, | ||
129 | 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 | ||
130 | }, | ||
131 | { | ||
132 | 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, | ||
133 | 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, | ||
134 | 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, | ||
135 | 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 | ||
136 | }, | ||
137 | { | ||
138 | 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, | ||
139 | 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, | ||
140 | 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, | ||
141 | 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 | ||
142 | }, | ||
143 | { | ||
144 | 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, | ||
145 | 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, | ||
146 | 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, | ||
147 | 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 | ||
148 | } | ||
149 | }; | ||
150 | |||
151 | static u_char un_pbox[32]; | ||
152 | static u_char pbox[32] = { | ||
153 | 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, | ||
154 | 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 | ||
155 | }; | ||
156 | |||
157 | static u_int32_t bits32[32] = | ||
158 | { | ||
159 | 0x80000000, 0x40000000, 0x20000000, 0x10000000, | ||
160 | 0x08000000, 0x04000000, 0x02000000, 0x01000000, | ||
161 | 0x00800000, 0x00400000, 0x00200000, 0x00100000, | ||
162 | 0x00080000, 0x00040000, 0x00020000, 0x00010000, | ||
163 | 0x00008000, 0x00004000, 0x00002000, 0x00001000, | ||
164 | 0x00000800, 0x00000400, 0x00000200, 0x00000100, | ||
165 | 0x00000080, 0x00000040, 0x00000020, 0x00000010, | ||
166 | 0x00000008, 0x00000004, 0x00000002, 0x00000001 | ||
167 | }; | ||
168 | |||
169 | static u_char bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; | ||
170 | |||
171 | static u_int32_t saltbits; | ||
172 | static int32_t old_salt; | ||
173 | static u_int32_t *bits28, *bits24; | ||
174 | static u_char init_perm[64], final_perm[64]; | ||
175 | static u_int32_t en_keysl[16], en_keysr[16]; | ||
176 | static u_int32_t de_keysl[16], de_keysr[16]; | ||
177 | static int des_initialised = 0; | ||
178 | static u_char m_sbox[4][4096]; | ||
179 | static u_int32_t psbox[4][256]; | ||
180 | static u_int32_t ip_maskl[8][256], ip_maskr[8][256]; | ||
181 | static u_int32_t fp_maskl[8][256], fp_maskr[8][256]; | ||
182 | static u_int32_t key_perm_maskl[8][128], key_perm_maskr[8][128]; | ||
183 | static u_int32_t comp_maskl[8][128], comp_maskr[8][128]; | ||
184 | static u_int32_t old_rawkey0, old_rawkey1; | ||
185 | |||
186 | static u_char ascii64[] = | ||
187 | "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
188 | /* 0000000000111111111122222222223333333333444444444455555555556666 */ | ||
189 | /* 0123456789012345678901234567890123456789012345678901234567890123 */ | ||
190 | |||
191 | static __inline int | ||
192 | ascii_to_bin(ch) | ||
193 | char ch; | ||
194 | { | ||
195 | if (ch > 'z') | ||
196 | return(0); | ||
197 | if (ch >= 'a') | ||
198 | return(ch - 'a' + 38); | ||
199 | if (ch > 'Z') | ||
200 | return(0); | ||
201 | if (ch >= 'A') | ||
202 | return(ch - 'A' + 12); | ||
203 | if (ch > '9') | ||
204 | return(0); | ||
205 | if (ch >= '.') | ||
206 | return(ch - '.'); | ||
207 | return(0); | ||
208 | } | ||
209 | |||
210 | static void | ||
211 | des_init() | ||
212 | { | ||
213 | int i, j, b, k, inbit, obit; | ||
214 | u_int32_t *p, *il, *ir, *fl, *fr; | ||
215 | |||
216 | old_rawkey0 = old_rawkey1 = 0; | ||
217 | saltbits = 0; | ||
218 | old_salt = 0; | ||
219 | bits24 = (bits28 = bits32 + 4) + 4; | ||
220 | |||
221 | /* | ||
222 | * Invert the S-boxes, reordering the input bits. | ||
223 | */ | ||
224 | for (i = 0; i < 8; i++) | ||
225 | for (j = 0; j < 64; j++) { | ||
226 | b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); | ||
227 | u_sbox[i][j] = sbox[i][b]; | ||
228 | } | ||
229 | |||
230 | /* | ||
231 | * Convert the inverted S-boxes into 4 arrays of 8 bits. | ||
232 | * Each will handle 12 bits of the S-box input. | ||
233 | */ | ||
234 | for (b = 0; b < 4; b++) | ||
235 | for (i = 0; i < 64; i++) | ||
236 | for (j = 0; j < 64; j++) | ||
237 | m_sbox[b][(i << 6) | j] = | ||
238 | (u_sbox[(b << 1)][i] << 4) | | ||
239 | u_sbox[(b << 1) + 1][j]; | ||
240 | |||
241 | /* | ||
242 | * Set up the initial & final permutations into a useful form, and | ||
243 | * initialise the inverted key permutation. | ||
244 | */ | ||
245 | for (i = 0; i < 64; i++) { | ||
246 | init_perm[final_perm[i] = IP[i] - 1] = i; | ||
247 | inv_key_perm[i] = 255; | ||
248 | } | ||
249 | |||
250 | /* | ||
251 | * Invert the key permutation and initialise the inverted key | ||
252 | * compression permutation. | ||
253 | */ | ||
254 | for (i = 0; i < 56; i++) { | ||
255 | u_key_perm[i] = key_perm[i] - 1; | ||
256 | inv_key_perm[key_perm[i] - 1] = i; | ||
257 | inv_comp_perm[i] = 255; | ||
258 | } | ||
259 | |||
260 | /* | ||
261 | * Invert the key compression permutation. | ||
262 | */ | ||
263 | for (i = 0; i < 48; i++) { | ||
264 | inv_comp_perm[comp_perm[i] - 1] = i; | ||
265 | } | ||
266 | |||
267 | /* | ||
268 | * Set up the OR-mask arrays for the initial and final permutations, | ||
269 | * and for the key initial and compression permutations. | ||
270 | */ | ||
271 | for (k = 0; k < 8; k++) { | ||
272 | for (i = 0; i < 256; i++) { | ||
273 | *(il = &ip_maskl[k][i]) = 0; | ||
274 | *(ir = &ip_maskr[k][i]) = 0; | ||
275 | *(fl = &fp_maskl[k][i]) = 0; | ||
276 | *(fr = &fp_maskr[k][i]) = 0; | ||
277 | for (j = 0; j < 8; j++) { | ||
278 | inbit = 8 * k + j; | ||
279 | if (i & bits8[j]) { | ||
280 | if ((obit = init_perm[inbit]) < 32) | ||
281 | *il |= bits32[obit]; | ||
282 | else | ||
283 | *ir |= bits32[obit-32]; | ||
284 | if ((obit = final_perm[inbit]) < 32) | ||
285 | *fl |= bits32[obit]; | ||
286 | else | ||
287 | *fr |= bits32[obit - 32]; | ||
288 | } | ||
289 | } | ||
290 | } | ||
291 | for (i = 0; i < 128; i++) { | ||
292 | *(il = &key_perm_maskl[k][i]) = 0; | ||
293 | *(ir = &key_perm_maskr[k][i]) = 0; | ||
294 | for (j = 0; j < 7; j++) { | ||
295 | inbit = 8 * k + j; | ||
296 | if (i & bits8[j + 1]) { | ||
297 | if ((obit = inv_key_perm[inbit]) == 255) | ||
298 | continue; | ||
299 | if (obit < 28) | ||
300 | *il |= bits28[obit]; | ||
301 | else | ||
302 | *ir |= bits28[obit - 28]; | ||
303 | } | ||
304 | } | ||
305 | *(il = &comp_maskl[k][i]) = 0; | ||
306 | *(ir = &comp_maskr[k][i]) = 0; | ||
307 | for (j = 0; j < 7; j++) { | ||
308 | inbit = 7 * k + j; | ||
309 | if (i & bits8[j + 1]) { | ||
310 | if ((obit=inv_comp_perm[inbit]) == 255) | ||
311 | continue; | ||
312 | if (obit < 24) | ||
313 | *il |= bits24[obit]; | ||
314 | else | ||
315 | *ir |= bits24[obit - 24]; | ||
316 | } | ||
317 | } | ||
318 | } | ||
319 | } | ||
320 | |||
321 | /* | ||
322 | * Invert the P-box permutation, and convert into OR-masks for | ||
323 | * handling the output of the S-box arrays setup above. | ||
324 | */ | ||
325 | for (i = 0; i < 32; i++) | ||
326 | un_pbox[pbox[i] - 1] = i; | ||
327 | |||
328 | for (b = 0; b < 4; b++) | ||
329 | for (i = 0; i < 256; i++) { | ||
330 | *(p = &psbox[b][i]) = 0; | ||
331 | for (j = 0; j < 8; j++) { | ||
332 | if (i & bits8[j]) | ||
333 | *p |= bits32[un_pbox[8 * b + j]]; | ||
334 | } | ||
335 | } | ||
336 | |||
337 | des_initialised = 1; | ||
338 | } | ||
339 | |||
340 | static void | ||
341 | setup_salt(salt) | ||
342 | int32_t salt; | ||
343 | { | ||
344 | u_int32_t obit, saltbit; | ||
345 | int i; | ||
346 | |||
347 | if (salt == old_salt) | ||
348 | return; | ||
349 | old_salt = salt; | ||
350 | |||
351 | saltbits = 0; | ||
352 | saltbit = 1; | ||
353 | obit = 0x800000; | ||
354 | for (i = 0; i < 24; i++) { | ||
355 | if (salt & saltbit) | ||
356 | saltbits |= obit; | ||
357 | saltbit <<= 1; | ||
358 | obit >>= 1; | ||
359 | } | ||
360 | } | ||
361 | |||
362 | static int | ||
363 | des_setkey(key) | ||
364 | const char *key; | ||
365 | { | ||
366 | u_int32_t k0, k1, rawkey0, rawkey1; | ||
367 | int shifts, round; | ||
368 | |||
369 | if (!des_initialised) | ||
370 | des_init(); | ||
371 | |||
372 | rawkey0 = ntohl(*(u_int32_t *) key); | ||
373 | rawkey1 = ntohl(*(u_int32_t *) (key + 4)); | ||
374 | |||
375 | if ((rawkey0 | rawkey1) | ||
376 | && rawkey0 == old_rawkey0 | ||
377 | && rawkey1 == old_rawkey1) { | ||
378 | /* | ||
379 | * Already setup for this key. | ||
380 | * This optimisation fails on a zero key (which is weak and | ||
381 | * has bad parity anyway) in order to simplify the starting | ||
382 | * conditions. | ||
383 | */ | ||
384 | return(0); | ||
385 | } | ||
386 | old_rawkey0 = rawkey0; | ||
387 | old_rawkey1 = rawkey1; | ||
388 | |||
389 | /* | ||
390 | * Do key permutation and split into two 28-bit subkeys. | ||
391 | */ | ||
392 | k0 = key_perm_maskl[0][rawkey0 >> 25] | ||
393 | | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] | ||
394 | | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] | ||
395 | | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] | ||
396 | | key_perm_maskl[4][rawkey1 >> 25] | ||
397 | | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] | ||
398 | | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] | ||
399 | | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; | ||
400 | k1 = key_perm_maskr[0][rawkey0 >> 25] | ||
401 | | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] | ||
402 | | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] | ||
403 | | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] | ||
404 | | key_perm_maskr[4][rawkey1 >> 25] | ||
405 | | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] | ||
406 | | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] | ||
407 | | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; | ||
408 | /* | ||
409 | * Rotate subkeys and do compression permutation. | ||
410 | */ | ||
411 | shifts = 0; | ||
412 | for (round = 0; round < 16; round++) { | ||
413 | u_int32_t t0, t1; | ||
414 | |||
415 | shifts += key_shifts[round]; | ||
416 | |||
417 | t0 = (k0 << shifts) | (k0 >> (28 - shifts)); | ||
418 | t1 = (k1 << shifts) | (k1 >> (28 - shifts)); | ||
419 | |||
420 | de_keysl[15 - round] = | ||
421 | en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] | ||
422 | | comp_maskl[1][(t0 >> 14) & 0x7f] | ||
423 | | comp_maskl[2][(t0 >> 7) & 0x7f] | ||
424 | | comp_maskl[3][t0 & 0x7f] | ||
425 | | comp_maskl[4][(t1 >> 21) & 0x7f] | ||
426 | | comp_maskl[5][(t1 >> 14) & 0x7f] | ||
427 | | comp_maskl[6][(t1 >> 7) & 0x7f] | ||
428 | | comp_maskl[7][t1 & 0x7f]; | ||
429 | |||
430 | de_keysr[15 - round] = | ||
431 | en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] | ||
432 | | comp_maskr[1][(t0 >> 14) & 0x7f] | ||
433 | | comp_maskr[2][(t0 >> 7) & 0x7f] | ||
434 | | comp_maskr[3][t0 & 0x7f] | ||
435 | | comp_maskr[4][(t1 >> 21) & 0x7f] | ||
436 | | comp_maskr[5][(t1 >> 14) & 0x7f] | ||
437 | | comp_maskr[6][(t1 >> 7) & 0x7f] | ||
438 | | comp_maskr[7][t1 & 0x7f]; | ||
439 | } | ||
440 | return(0); | ||
441 | } | ||
442 | |||
443 | static int | ||
444 | do_des(l_in, r_in, l_out, r_out, count) | ||
445 | u_int32_t l_in, r_in, *l_out, *r_out; | ||
446 | int count; | ||
447 | { | ||
448 | /* | ||
449 | * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. | ||
450 | */ | ||
451 | u_int32_t l, r, *kl, *kr, *kl1, *kr1; | ||
452 | u_int32_t f, r48l, r48r; | ||
453 | int round; | ||
454 | |||
455 | if (count == 0) { | ||
456 | return(1); | ||
457 | } else if (count > 0) { | ||
458 | /* | ||
459 | * Encrypting | ||
460 | */ | ||
461 | kl1 = en_keysl; | ||
462 | kr1 = en_keysr; | ||
463 | } else { | ||
464 | /* | ||
465 | * Decrypting | ||
466 | */ | ||
467 | count = -count; | ||
468 | kl1 = de_keysl; | ||
469 | kr1 = de_keysr; | ||
470 | } | ||
471 | |||
472 | /* | ||
473 | * Do initial permutation (IP). | ||
474 | */ | ||
475 | l = ip_maskl[0][l_in >> 24] | ||
476 | | ip_maskl[1][(l_in >> 16) & 0xff] | ||
477 | | ip_maskl[2][(l_in >> 8) & 0xff] | ||
478 | | ip_maskl[3][l_in & 0xff] | ||
479 | | ip_maskl[4][r_in >> 24] | ||
480 | | ip_maskl[5][(r_in >> 16) & 0xff] | ||
481 | | ip_maskl[6][(r_in >> 8) & 0xff] | ||
482 | | ip_maskl[7][r_in & 0xff]; | ||
483 | r = ip_maskr[0][l_in >> 24] | ||
484 | | ip_maskr[1][(l_in >> 16) & 0xff] | ||
485 | | ip_maskr[2][(l_in >> 8) & 0xff] | ||
486 | | ip_maskr[3][l_in & 0xff] | ||
487 | | ip_maskr[4][r_in >> 24] | ||
488 | | ip_maskr[5][(r_in >> 16) & 0xff] | ||
489 | | ip_maskr[6][(r_in >> 8) & 0xff] | ||
490 | | ip_maskr[7][r_in & 0xff]; | ||
491 | |||
492 | while (count--) { | ||
493 | /* | ||
494 | * Do each round. | ||
495 | */ | ||
496 | kl = kl1; | ||
497 | kr = kr1; | ||
498 | round = 16; | ||
499 | while (round--) { | ||
500 | /* | ||
501 | * Expand R to 48 bits (simulate the E-box). | ||
502 | */ | ||
503 | r48l = ((r & 0x00000001) << 23) | ||
504 | | ((r & 0xf8000000) >> 9) | ||
505 | | ((r & 0x1f800000) >> 11) | ||
506 | | ((r & 0x01f80000) >> 13) | ||
507 | | ((r & 0x001f8000) >> 15); | ||
508 | |||
509 | r48r = ((r & 0x0001f800) << 7) | ||
510 | | ((r & 0x00001f80) << 5) | ||
511 | | ((r & 0x000001f8) << 3) | ||
512 | | ((r & 0x0000001f) << 1) | ||
513 | | ((r & 0x80000000) >> 31); | ||
514 | /* | ||
515 | * Do salting for crypt() and friends, and | ||
516 | * XOR with the permuted key. | ||
517 | */ | ||
518 | f = (r48l ^ r48r) & saltbits; | ||
519 | r48l ^= f ^ *kl++; | ||
520 | r48r ^= f ^ *kr++; | ||
521 | /* | ||
522 | * Do sbox lookups (which shrink it back to 32 bits) | ||
523 | * and do the pbox permutation at the same time. | ||
524 | */ | ||
525 | f = psbox[0][m_sbox[0][r48l >> 12]] | ||
526 | | psbox[1][m_sbox[1][r48l & 0xfff]] | ||
527 | | psbox[2][m_sbox[2][r48r >> 12]] | ||
528 | | psbox[3][m_sbox[3][r48r & 0xfff]]; | ||
529 | /* | ||
530 | * Now that we've permuted things, complete f(). | ||
531 | */ | ||
532 | f ^= l; | ||
533 | l = r; | ||
534 | r = f; | ||
535 | } | ||
536 | r = l; | ||
537 | l = f; | ||
538 | } | ||
539 | /* | ||
540 | * Do final permutation (inverse of IP). | ||
541 | */ | ||
542 | *l_out = fp_maskl[0][l >> 24] | ||
543 | | fp_maskl[1][(l >> 16) & 0xff] | ||
544 | | fp_maskl[2][(l >> 8) & 0xff] | ||
545 | | fp_maskl[3][l & 0xff] | ||
546 | | fp_maskl[4][r >> 24] | ||
547 | | fp_maskl[5][(r >> 16) & 0xff] | ||
548 | | fp_maskl[6][(r >> 8) & 0xff] | ||
549 | | fp_maskl[7][r & 0xff]; | ||
550 | *r_out = fp_maskr[0][l >> 24] | ||
551 | | fp_maskr[1][(l >> 16) & 0xff] | ||
552 | | fp_maskr[2][(l >> 8) & 0xff] | ||
553 | | fp_maskr[3][l & 0xff] | ||
554 | | fp_maskr[4][r >> 24] | ||
555 | | fp_maskr[5][(r >> 16) & 0xff] | ||
556 | | fp_maskr[6][(r >> 8) & 0xff] | ||
557 | | fp_maskr[7][r & 0xff]; | ||
558 | return(0); | ||
559 | } | ||
560 | |||
561 | static int | ||
562 | des_cipher(in, out, salt, count) | ||
563 | const char *in; | ||
564 | char *out; | ||
565 | int32_t salt; | ||
566 | int count; | ||
567 | { | ||
568 | u_int32_t l_out, r_out, rawl, rawr; | ||
569 | u_int32_t x[2]; | ||
570 | int retval; | ||
571 | |||
572 | if (!des_initialised) | ||
573 | des_init(); | ||
574 | |||
575 | setup_salt(salt); | ||
576 | |||
577 | memcpy(x, in, sizeof x); | ||
578 | rawl = ntohl(x[0]); | ||
579 | rawr = ntohl(x[1]); | ||
580 | retval = do_des(rawl, rawr, &l_out, &r_out, count); | ||
581 | |||
582 | x[0] = htonl(l_out); | ||
583 | x[1] = htonl(r_out); | ||
584 | memcpy(out, x, sizeof x); | ||
585 | return(retval); | ||
586 | } | ||
587 | |||
588 | char * | ||
589 | crypt(key, setting) | ||
590 | const char *key; | ||
591 | const char *setting; | ||
592 | { | ||
593 | int i; | ||
594 | u_int32_t count, salt, l, r0, r1, keybuf[2]; | ||
595 | u_char *p, *q; | ||
596 | static u_char output[21]; | ||
597 | extern char *md5crypt __P((const char *, const char *)); | ||
598 | extern char *bcrypt __P((const char *, const char *)); | ||
599 | |||
600 | if (setting[0] == '$') { | ||
601 | switch (setting[1]) { | ||
602 | case '1': | ||
603 | return (md5crypt(key, setting)); | ||
604 | default: | ||
605 | return bcrypt(key, setting); | ||
606 | } | ||
607 | } | ||
608 | |||
609 | if (!des_initialised) | ||
610 | des_init(); | ||
611 | |||
612 | /* | ||
613 | * Copy the key, shifting each character up by one bit | ||
614 | * and padding with zeros. | ||
615 | */ | ||
616 | q = (u_char *) keybuf; | ||
617 | while ((q - (u_char *) keybuf) < sizeof(keybuf)) { | ||
618 | if ((*q++ = *key << 1)) | ||
619 | key++; | ||
620 | } | ||
621 | if (des_setkey((u_char *) keybuf)) | ||
622 | return(NULL); | ||
623 | |||
624 | if (*setting == _PASSWORD_EFMT1) { | ||
625 | /* | ||
626 | * "new"-style: | ||
627 | * setting - underscore, 4 bytes of count, 4 bytes of salt | ||
628 | * key - unlimited characters | ||
629 | */ | ||
630 | for (i = 1, count = 0; i < 5; i++) | ||
631 | count |= ascii_to_bin(setting[i]) << (i - 1) * 6; | ||
632 | |||
633 | for (i = 5, salt = 0; i < 9; i++) | ||
634 | salt |= ascii_to_bin(setting[i]) << (i - 5) * 6; | ||
635 | |||
636 | while (*key) { | ||
637 | /* | ||
638 | * Encrypt the key with itself. | ||
639 | */ | ||
640 | if (des_cipher((u_char*)keybuf, (u_char*)keybuf, 0, 1)) | ||
641 | return(NULL); | ||
642 | /* | ||
643 | * And XOR with the next 8 characters of the key. | ||
644 | */ | ||
645 | q = (u_char *) keybuf; | ||
646 | while (((q - (u_char *) keybuf) < sizeof(keybuf)) && | ||
647 | *key) | ||
648 | *q++ ^= *key++ << 1; | ||
649 | |||
650 | if (des_setkey((u_char *) keybuf)) | ||
651 | return(NULL); | ||
652 | } | ||
653 | strncpy((char *)output, setting, 9); | ||
654 | |||
655 | /* | ||
656 | * Double check that we weren't given a short setting. | ||
657 | * If we were, the above code will probably have created | ||
658 | * wierd values for count and salt, but we don't really care. | ||
659 | * Just make sure the output string doesn't have an extra | ||
660 | * NUL in it. | ||
661 | */ | ||
662 | output[9] = '\0'; | ||
663 | p = output + strlen((const char *)output); | ||
664 | } else { | ||
665 | /* | ||
666 | * "old"-style: | ||
667 | * setting - 2 bytes of salt | ||
668 | * key - up to 8 characters | ||
669 | */ | ||
670 | count = 25; | ||
671 | |||
672 | salt = (ascii_to_bin(setting[1]) << 6) | ||
673 | | ascii_to_bin(setting[0]); | ||
674 | |||
675 | output[0] = setting[0]; | ||
676 | /* | ||
677 | * If the encrypted password that the salt was extracted from | ||
678 | * is only 1 character long, the salt will be corrupted. We | ||
679 | * need to ensure that the output string doesn't have an extra | ||
680 | * NUL in it! | ||
681 | */ | ||
682 | output[1] = setting[1] ? setting[1] : output[0]; | ||
683 | |||
684 | p = output + 2; | ||
685 | } | ||
686 | setup_salt(salt); | ||
687 | /* | ||
688 | * Do it. | ||
689 | */ | ||
690 | if (do_des(0, 0, &r0, &r1, count)) | ||
691 | return(NULL); | ||
692 | /* | ||
693 | * Now encode the result... | ||
694 | */ | ||
695 | l = (r0 >> 8); | ||
696 | *p++ = ascii64[(l >> 18) & 0x3f]; | ||
697 | *p++ = ascii64[(l >> 12) & 0x3f]; | ||
698 | *p++ = ascii64[(l >> 6) & 0x3f]; | ||
699 | *p++ = ascii64[l & 0x3f]; | ||
700 | |||
701 | l = (r0 << 16) | ((r1 >> 16) & 0xffff); | ||
702 | *p++ = ascii64[(l >> 18) & 0x3f]; | ||
703 | *p++ = ascii64[(l >> 12) & 0x3f]; | ||
704 | *p++ = ascii64[(l >> 6) & 0x3f]; | ||
705 | *p++ = ascii64[l & 0x3f]; | ||
706 | |||
707 | l = r1 << 2; | ||
708 | *p++ = ascii64[(l >> 12) & 0x3f]; | ||
709 | *p++ = ascii64[(l >> 6) & 0x3f]; | ||
710 | *p++ = ascii64[l & 0x3f]; | ||
711 | *p = 0; | ||
712 | |||
713 | return((char *)output); | ||
714 | } | ||
diff --git a/src/lib/libc/crypt/md5crypt.c b/src/lib/libc/crypt/md5crypt.c new file mode 100644 index 0000000000..7ec60f38e0 --- /dev/null +++ b/src/lib/libc/crypt/md5crypt.c | |||
@@ -0,0 +1,157 @@ | |||
1 | /* $OpenBSD: md5crypt.c,v 1.9 1997/07/23 20:58:27 kstailey Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * ---------------------------------------------------------------------------- | ||
5 | * "THE BEER-WARE LICENSE" (Revision 42): | ||
6 | * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you | ||
7 | * can do whatever you want with this stuff. If we meet some day, and you think | ||
8 | * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp | ||
9 | * ---------------------------------------------------------------------------- | ||
10 | * | ||
11 | * $FreeBSD: crypt.c,v 1.5 1996/10/14 08:34:02 phk Exp $ | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #if defined(LIBC_SCCS) && !defined(lint) | ||
16 | static char rcsid[] = "$OpenBSD: md5crypt.c,v 1.9 1997/07/23 20:58:27 kstailey Exp $"; | ||
17 | #endif /* LIBC_SCCS and not lint */ | ||
18 | |||
19 | #include <unistd.h> | ||
20 | #include <stdio.h> | ||
21 | #include <string.h> | ||
22 | #include <md5.h> | ||
23 | #include <string.h> | ||
24 | |||
25 | static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */ | ||
26 | "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
27 | |||
28 | static void to64 __P((char *, u_int32_t, int)); | ||
29 | |||
30 | static void | ||
31 | to64(s, v, n) | ||
32 | char *s; | ||
33 | u_int32_t v; | ||
34 | int n; | ||
35 | { | ||
36 | while (--n >= 0) { | ||
37 | *s++ = itoa64[v&0x3f]; | ||
38 | v >>= 6; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | /* | ||
43 | * UNIX password | ||
44 | * | ||
45 | * Use MD5 for what it is best at... | ||
46 | */ | ||
47 | |||
48 | char * | ||
49 | md5crypt(pw, salt) | ||
50 | register const char *pw; | ||
51 | register const char *salt; | ||
52 | { | ||
53 | /* | ||
54 | * This string is magic for this algorithm. Having | ||
55 | * it this way, we can get get better later on | ||
56 | */ | ||
57 | static unsigned char *magic = (unsigned char *)"$1$"; | ||
58 | |||
59 | static char passwd[120], *p; | ||
60 | static const unsigned char *sp,*ep; | ||
61 | unsigned char final[16]; | ||
62 | int sl,pl,i; | ||
63 | MD5_CTX ctx,ctx1; | ||
64 | u_int32_t l; | ||
65 | |||
66 | /* Refine the Salt first */ | ||
67 | sp = (const unsigned char *)salt; | ||
68 | |||
69 | /* If it starts with the magic string, then skip that */ | ||
70 | if(!strncmp((const char *)sp,(const char *)magic,strlen((const char *)magic))) | ||
71 | sp += strlen((const char *)magic); | ||
72 | |||
73 | /* It stops at the first '$', max 8 chars */ | ||
74 | for(ep=sp;*ep && *ep != '$' && ep < (sp+8);ep++) | ||
75 | continue; | ||
76 | |||
77 | /* get the length of the true salt */ | ||
78 | sl = ep - sp; | ||
79 | |||
80 | MD5Init(&ctx); | ||
81 | |||
82 | /* The password first, since that is what is most unknown */ | ||
83 | MD5Update(&ctx,(const unsigned char *)pw,strlen(pw)); | ||
84 | |||
85 | /* Then our magic string */ | ||
86 | MD5Update(&ctx,magic,strlen((const char *)magic)); | ||
87 | |||
88 | /* Then the raw salt */ | ||
89 | MD5Update(&ctx,sp,sl); | ||
90 | |||
91 | /* Then just as many characters of the MD5(pw,salt,pw) */ | ||
92 | MD5Init(&ctx1); | ||
93 | MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); | ||
94 | MD5Update(&ctx1,sp,sl); | ||
95 | MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); | ||
96 | MD5Final(final,&ctx1); | ||
97 | for(pl = strlen(pw); pl > 0; pl -= 16) | ||
98 | MD5Update(&ctx,final,pl>16 ? 16 : pl); | ||
99 | |||
100 | /* Don't leave anything around in vm they could use. */ | ||
101 | memset(final,0,sizeof final); | ||
102 | |||
103 | /* Then something really weird... */ | ||
104 | for (i = strlen(pw); i ; i >>= 1) | ||
105 | if(i&1) | ||
106 | MD5Update(&ctx, final, 1); | ||
107 | else | ||
108 | MD5Update(&ctx, (const unsigned char *)pw, 1); | ||
109 | |||
110 | /* Now make the output string */ | ||
111 | strcpy(passwd,(const char *)magic); | ||
112 | strncat(passwd,(const char *)sp,sl); | ||
113 | strcat(passwd,"$"); | ||
114 | |||
115 | MD5Final(final,&ctx); | ||
116 | |||
117 | /* | ||
118 | * and now, just to make sure things don't run too fast | ||
119 | * On a 60 Mhz Pentium this takes 34 msec, so you would | ||
120 | * need 30 seconds to build a 1000 entry dictionary... | ||
121 | */ | ||
122 | for(i=0;i<1000;i++) { | ||
123 | MD5Init(&ctx1); | ||
124 | if(i & 1) | ||
125 | MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); | ||
126 | else | ||
127 | MD5Update(&ctx1,final,16); | ||
128 | |||
129 | if(i % 3) | ||
130 | MD5Update(&ctx1,sp,sl); | ||
131 | |||
132 | if(i % 7) | ||
133 | MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); | ||
134 | |||
135 | if(i & 1) | ||
136 | MD5Update(&ctx1,final,16); | ||
137 | else | ||
138 | MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); | ||
139 | MD5Final(final,&ctx1); | ||
140 | } | ||
141 | |||
142 | p = passwd + strlen(passwd); | ||
143 | |||
144 | l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; to64(p,l,4); p += 4; | ||
145 | l = (final[ 1]<<16) | (final[ 7]<<8) | final[13]; to64(p,l,4); p += 4; | ||
146 | l = (final[ 2]<<16) | (final[ 8]<<8) | final[14]; to64(p,l,4); p += 4; | ||
147 | l = (final[ 3]<<16) | (final[ 9]<<8) | final[15]; to64(p,l,4); p += 4; | ||
148 | l = (final[ 4]<<16) | (final[10]<<8) | final[ 5]; to64(p,l,4); p += 4; | ||
149 | l = final[11] ; to64(p,l,2); p += 2; | ||
150 | *p = '\0'; | ||
151 | |||
152 | /* Don't leave anything around in vm they could use. */ | ||
153 | memset(final,0,sizeof final); | ||
154 | |||
155 | return passwd; | ||
156 | } | ||
157 | |||
diff --git a/src/lib/libc/crypt/morecrypt.c b/src/lib/libc/crypt/morecrypt.c new file mode 100644 index 0000000000..e9e0ced4c1 --- /dev/null +++ b/src/lib/libc/crypt/morecrypt.c | |||
@@ -0,0 +1,628 @@ | |||
1 | /* $OpenBSD: morecrypt.c,v 1.9 1998/03/22 19:01:20 niklas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * FreeSec: libcrypt | ||
5 | * | ||
6 | * Copyright (c) 1994 David Burren | ||
7 | * All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * 2. Redistributions in binary form must reproduce the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer in the | ||
16 | * documentation and/or other materials provided with the distribution. | ||
17 | * 4. Neither the name of the author nor the names of other contributors | ||
18 | * may be used to endorse or promote products derived from this software | ||
19 | * without specific prior written permission. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
31 | * SUCH DAMAGE. | ||
32 | * | ||
33 | * | ||
34 | * This is an original implementation of the DES and the crypt(3) interfaces | ||
35 | * by David Burren <davidb@werj.com.au>. | ||
36 | * | ||
37 | * An excellent reference on the underlying algorithm (and related | ||
38 | * algorithms) is: | ||
39 | * | ||
40 | * B. Schneier, Applied Cryptography: protocols, algorithms, | ||
41 | * and source code in C, John Wiley & Sons, 1994. | ||
42 | * | ||
43 | * Note that in that book's description of DES the lookups for the initial, | ||
44 | * pbox, and final permutations are inverted (this has been brought to the | ||
45 | * attention of the author). A list of errata for this book has been | ||
46 | * posted to the sci.crypt newsgroup by the author and is available for FTP. | ||
47 | * | ||
48 | * NOTE: | ||
49 | * This file must copy certain chunks of crypt.c for legal reasons. | ||
50 | * crypt.c can only export the interface crypt(), to make binaries | ||
51 | * exportable from the USA. Hence, to also have the other crypto interfaces | ||
52 | * available we have to copy pieces... | ||
53 | */ | ||
54 | |||
55 | #if defined(LIBC_SCCS) && !defined(lint) | ||
56 | static char rcsid[] = "$OpenBSD: morecrypt.c,v 1.9 1998/03/22 19:01:20 niklas Exp $"; | ||
57 | #endif /* LIBC_SCCS and not lint */ | ||
58 | |||
59 | #include <sys/types.h> | ||
60 | #include <sys/param.h> | ||
61 | #include <pwd.h> | ||
62 | #include <string.h> | ||
63 | |||
64 | #ifdef DEBUG | ||
65 | # include <stdio.h> | ||
66 | #endif | ||
67 | |||
68 | static u_char IP[64] = { | ||
69 | 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, | ||
70 | 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, | ||
71 | 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, | ||
72 | 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 | ||
73 | }; | ||
74 | |||
75 | static u_char inv_key_perm[64]; | ||
76 | static u_char u_key_perm[56]; | ||
77 | static u_char key_perm[56] = { | ||
78 | 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, | ||
79 | 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, | ||
80 | 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, | ||
81 | 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 | ||
82 | }; | ||
83 | |||
84 | static u_char key_shifts[16] = { | ||
85 | 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 | ||
86 | }; | ||
87 | |||
88 | static u_char inv_comp_perm[56]; | ||
89 | static u_char comp_perm[48] = { | ||
90 | 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, | ||
91 | 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, | ||
92 | 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, | ||
93 | 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 | ||
94 | }; | ||
95 | |||
96 | /* | ||
97 | * No E box is used, as it's replaced by some ANDs, shifts, and ORs. | ||
98 | */ | ||
99 | |||
100 | static u_char u_sbox[8][64]; | ||
101 | static u_char sbox[8][64] = { | ||
102 | { | ||
103 | 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, | ||
104 | 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, | ||
105 | 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, | ||
106 | 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 | ||
107 | }, | ||
108 | { | ||
109 | 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, | ||
110 | 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, | ||
111 | 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, | ||
112 | 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 | ||
113 | }, | ||
114 | { | ||
115 | 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, | ||
116 | 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, | ||
117 | 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, | ||
118 | 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 | ||
119 | }, | ||
120 | { | ||
121 | 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, | ||
122 | 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, | ||
123 | 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, | ||
124 | 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 | ||
125 | }, | ||
126 | { | ||
127 | 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, | ||
128 | 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, | ||
129 | 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, | ||
130 | 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 | ||
131 | }, | ||
132 | { | ||
133 | 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, | ||
134 | 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, | ||
135 | 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, | ||
136 | 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 | ||
137 | }, | ||
138 | { | ||
139 | 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, | ||
140 | 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, | ||
141 | 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, | ||
142 | 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 | ||
143 | }, | ||
144 | { | ||
145 | 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, | ||
146 | 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, | ||
147 | 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, | ||
148 | 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 | ||
149 | } | ||
150 | }; | ||
151 | |||
152 | static u_char un_pbox[32]; | ||
153 | static u_char pbox[32] = { | ||
154 | 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, | ||
155 | 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 | ||
156 | }; | ||
157 | |||
158 | static u_int32_t bits32[32] = | ||
159 | { | ||
160 | 0x80000000, 0x40000000, 0x20000000, 0x10000000, | ||
161 | 0x08000000, 0x04000000, 0x02000000, 0x01000000, | ||
162 | 0x00800000, 0x00400000, 0x00200000, 0x00100000, | ||
163 | 0x00080000, 0x00040000, 0x00020000, 0x00010000, | ||
164 | 0x00008000, 0x00004000, 0x00002000, 0x00001000, | ||
165 | 0x00000800, 0x00000400, 0x00000200, 0x00000100, | ||
166 | 0x00000080, 0x00000040, 0x00000020, 0x00000010, | ||
167 | 0x00000008, 0x00000004, 0x00000002, 0x00000001 | ||
168 | }; | ||
169 | |||
170 | static u_char bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; | ||
171 | |||
172 | static u_int32_t saltbits; | ||
173 | static int32_t old_salt; | ||
174 | static u_int32_t *bits28, *bits24; | ||
175 | static u_char init_perm[64], final_perm[64]; | ||
176 | static u_int32_t en_keysl[16], en_keysr[16]; | ||
177 | static u_int32_t de_keysl[16], de_keysr[16]; | ||
178 | static int des_initialised = 0; | ||
179 | static u_char m_sbox[4][4096]; | ||
180 | static u_int32_t psbox[4][256]; | ||
181 | static u_int32_t ip_maskl[8][256], ip_maskr[8][256]; | ||
182 | static u_int32_t fp_maskl[8][256], fp_maskr[8][256]; | ||
183 | static u_int32_t key_perm_maskl[8][128], key_perm_maskr[8][128]; | ||
184 | static u_int32_t comp_maskl[8][128], comp_maskr[8][128]; | ||
185 | static u_int32_t old_rawkey0, old_rawkey1; | ||
186 | |||
187 | static __inline int | ||
188 | ascii_to_bin(ch) | ||
189 | char ch; | ||
190 | { | ||
191 | if (ch > 'z') | ||
192 | return(0); | ||
193 | if (ch >= 'a') | ||
194 | return(ch - 'a' + 38); | ||
195 | if (ch > 'Z') | ||
196 | return(0); | ||
197 | if (ch >= 'A') | ||
198 | return(ch - 'A' + 12); | ||
199 | if (ch > '9') | ||
200 | return(0); | ||
201 | if (ch >= '.') | ||
202 | return(ch - '.'); | ||
203 | return(0); | ||
204 | } | ||
205 | |||
206 | void | ||
207 | des_init() | ||
208 | { | ||
209 | int i, j, b, k, inbit, obit; | ||
210 | u_int32_t *p, *il, *ir, *fl, *fr; | ||
211 | |||
212 | old_rawkey0 = old_rawkey1 = 0; | ||
213 | saltbits = 0; | ||
214 | old_salt = 0; | ||
215 | bits24 = (bits28 = bits32 + 4) + 4; | ||
216 | |||
217 | /* | ||
218 | * Invert the S-boxes, reordering the input bits. | ||
219 | */ | ||
220 | for (i = 0; i < 8; i++) | ||
221 | for (j = 0; j < 64; j++) { | ||
222 | b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); | ||
223 | u_sbox[i][j] = sbox[i][b]; | ||
224 | } | ||
225 | |||
226 | /* | ||
227 | * Convert the inverted S-boxes into 4 arrays of 8 bits. | ||
228 | * Each will handle 12 bits of the S-box input. | ||
229 | */ | ||
230 | for (b = 0; b < 4; b++) | ||
231 | for (i = 0; i < 64; i++) | ||
232 | for (j = 0; j < 64; j++) | ||
233 | m_sbox[b][(i << 6) | j] = | ||
234 | (u_sbox[(b << 1)][i] << 4) | | ||
235 | u_sbox[(b << 1) + 1][j]; | ||
236 | |||
237 | /* | ||
238 | * Set up the initial & final permutations into a useful form, and | ||
239 | * initialise the inverted key permutation. | ||
240 | */ | ||
241 | for (i = 0; i < 64; i++) { | ||
242 | init_perm[final_perm[i] = IP[i] - 1] = i; | ||
243 | inv_key_perm[i] = 255; | ||
244 | } | ||
245 | |||
246 | /* | ||
247 | * Invert the key permutation and initialise the inverted key | ||
248 | * compression permutation. | ||
249 | */ | ||
250 | for (i = 0; i < 56; i++) { | ||
251 | u_key_perm[i] = key_perm[i] - 1; | ||
252 | inv_key_perm[key_perm[i] - 1] = i; | ||
253 | inv_comp_perm[i] = 255; | ||
254 | } | ||
255 | |||
256 | /* | ||
257 | * Invert the key compression permutation. | ||
258 | */ | ||
259 | for (i = 0; i < 48; i++) { | ||
260 | inv_comp_perm[comp_perm[i] - 1] = i; | ||
261 | } | ||
262 | |||
263 | /* | ||
264 | * Set up the OR-mask arrays for the initial and final permutations, | ||
265 | * and for the key initial and compression permutations. | ||
266 | */ | ||
267 | for (k = 0; k < 8; k++) { | ||
268 | for (i = 0; i < 256; i++) { | ||
269 | *(il = &ip_maskl[k][i]) = 0; | ||
270 | *(ir = &ip_maskr[k][i]) = 0; | ||
271 | *(fl = &fp_maskl[k][i]) = 0; | ||
272 | *(fr = &fp_maskr[k][i]) = 0; | ||
273 | for (j = 0; j < 8; j++) { | ||
274 | inbit = 8 * k + j; | ||
275 | if (i & bits8[j]) { | ||
276 | if ((obit = init_perm[inbit]) < 32) | ||
277 | *il |= bits32[obit]; | ||
278 | else | ||
279 | *ir |= bits32[obit-32]; | ||
280 | if ((obit = final_perm[inbit]) < 32) | ||
281 | *fl |= bits32[obit]; | ||
282 | else | ||
283 | *fr |= bits32[obit - 32]; | ||
284 | } | ||
285 | } | ||
286 | } | ||
287 | for (i = 0; i < 128; i++) { | ||
288 | *(il = &key_perm_maskl[k][i]) = 0; | ||
289 | *(ir = &key_perm_maskr[k][i]) = 0; | ||
290 | for (j = 0; j < 7; j++) { | ||
291 | inbit = 8 * k + j; | ||
292 | if (i & bits8[j + 1]) { | ||
293 | if ((obit = inv_key_perm[inbit]) == 255) | ||
294 | continue; | ||
295 | if (obit < 28) | ||
296 | *il |= bits28[obit]; | ||
297 | else | ||
298 | *ir |= bits28[obit - 28]; | ||
299 | } | ||
300 | } | ||
301 | *(il = &comp_maskl[k][i]) = 0; | ||
302 | *(ir = &comp_maskr[k][i]) = 0; | ||
303 | for (j = 0; j < 7; j++) { | ||
304 | inbit = 7 * k + j; | ||
305 | if (i & bits8[j + 1]) { | ||
306 | if ((obit=inv_comp_perm[inbit]) == 255) | ||
307 | continue; | ||
308 | if (obit < 24) | ||
309 | *il |= bits24[obit]; | ||
310 | else | ||
311 | *ir |= bits24[obit - 24]; | ||
312 | } | ||
313 | } | ||
314 | } | ||
315 | } | ||
316 | |||
317 | /* | ||
318 | * Invert the P-box permutation, and convert into OR-masks for | ||
319 | * handling the output of the S-box arrays setup above. | ||
320 | */ | ||
321 | for (i = 0; i < 32; i++) | ||
322 | un_pbox[pbox[i] - 1] = i; | ||
323 | |||
324 | for (b = 0; b < 4; b++) | ||
325 | for (i = 0; i < 256; i++) { | ||
326 | *(p = &psbox[b][i]) = 0; | ||
327 | for (j = 0; j < 8; j++) { | ||
328 | if (i & bits8[j]) | ||
329 | *p |= bits32[un_pbox[8 * b + j]]; | ||
330 | } | ||
331 | } | ||
332 | |||
333 | des_initialised = 1; | ||
334 | } | ||
335 | |||
336 | void | ||
337 | setup_salt(salt) | ||
338 | int32_t salt; | ||
339 | { | ||
340 | u_int32_t obit, saltbit; | ||
341 | int i; | ||
342 | |||
343 | if (salt == old_salt) | ||
344 | return; | ||
345 | old_salt = salt; | ||
346 | |||
347 | saltbits = 0; | ||
348 | saltbit = 1; | ||
349 | obit = 0x800000; | ||
350 | for (i = 0; i < 24; i++) { | ||
351 | if (salt & saltbit) | ||
352 | saltbits |= obit; | ||
353 | saltbit <<= 1; | ||
354 | obit >>= 1; | ||
355 | } | ||
356 | } | ||
357 | |||
358 | int | ||
359 | do_des(l_in, r_in, l_out, r_out, count) | ||
360 | u_int32_t l_in, r_in, *l_out, *r_out; | ||
361 | int count; | ||
362 | { | ||
363 | /* | ||
364 | * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. | ||
365 | */ | ||
366 | u_int32_t l, r, *kl, *kr, *kl1, *kr1; | ||
367 | u_int32_t f, r48l, r48r; | ||
368 | int round; | ||
369 | |||
370 | if (count == 0) { | ||
371 | return(1); | ||
372 | } else if (count > 0) { | ||
373 | /* | ||
374 | * Encrypting | ||
375 | */ | ||
376 | kl1 = en_keysl; | ||
377 | kr1 = en_keysr; | ||
378 | } else { | ||
379 | /* | ||
380 | * Decrypting | ||
381 | */ | ||
382 | count = -count; | ||
383 | kl1 = de_keysl; | ||
384 | kr1 = de_keysr; | ||
385 | } | ||
386 | |||
387 | /* | ||
388 | * Do initial permutation (IP). | ||
389 | */ | ||
390 | l = ip_maskl[0][l_in >> 24] | ||
391 | | ip_maskl[1][(l_in >> 16) & 0xff] | ||
392 | | ip_maskl[2][(l_in >> 8) & 0xff] | ||
393 | | ip_maskl[3][l_in & 0xff] | ||
394 | | ip_maskl[4][r_in >> 24] | ||
395 | | ip_maskl[5][(r_in >> 16) & 0xff] | ||
396 | | ip_maskl[6][(r_in >> 8) & 0xff] | ||
397 | | ip_maskl[7][r_in & 0xff]; | ||
398 | r = ip_maskr[0][l_in >> 24] | ||
399 | | ip_maskr[1][(l_in >> 16) & 0xff] | ||
400 | | ip_maskr[2][(l_in >> 8) & 0xff] | ||
401 | | ip_maskr[3][l_in & 0xff] | ||
402 | | ip_maskr[4][r_in >> 24] | ||
403 | | ip_maskr[5][(r_in >> 16) & 0xff] | ||
404 | | ip_maskr[6][(r_in >> 8) & 0xff] | ||
405 | | ip_maskr[7][r_in & 0xff]; | ||
406 | |||
407 | while (count--) { | ||
408 | /* | ||
409 | * Do each round. | ||
410 | */ | ||
411 | kl = kl1; | ||
412 | kr = kr1; | ||
413 | round = 16; | ||
414 | while (round--) { | ||
415 | /* | ||
416 | * Expand R to 48 bits (simulate the E-box). | ||
417 | */ | ||
418 | r48l = ((r & 0x00000001) << 23) | ||
419 | | ((r & 0xf8000000) >> 9) | ||
420 | | ((r & 0x1f800000) >> 11) | ||
421 | | ((r & 0x01f80000) >> 13) | ||
422 | | ((r & 0x001f8000) >> 15); | ||
423 | |||
424 | r48r = ((r & 0x0001f800) << 7) | ||
425 | | ((r & 0x00001f80) << 5) | ||
426 | | ((r & 0x000001f8) << 3) | ||
427 | | ((r & 0x0000001f) << 1) | ||
428 | | ((r & 0x80000000) >> 31); | ||
429 | /* | ||
430 | * Do salting for crypt() and friends, and | ||
431 | * XOR with the permuted key. | ||
432 | */ | ||
433 | f = (r48l ^ r48r) & saltbits; | ||
434 | r48l ^= f ^ *kl++; | ||
435 | r48r ^= f ^ *kr++; | ||
436 | /* | ||
437 | * Do sbox lookups (which shrink it back to 32 bits) | ||
438 | * and do the pbox permutation at the same time. | ||
439 | */ | ||
440 | f = psbox[0][m_sbox[0][r48l >> 12]] | ||
441 | | psbox[1][m_sbox[1][r48l & 0xfff]] | ||
442 | | psbox[2][m_sbox[2][r48r >> 12]] | ||
443 | | psbox[3][m_sbox[3][r48r & 0xfff]]; | ||
444 | /* | ||
445 | * Now that we've permuted things, complete f(). | ||
446 | */ | ||
447 | f ^= l; | ||
448 | l = r; | ||
449 | r = f; | ||
450 | } | ||
451 | r = l; | ||
452 | l = f; | ||
453 | } | ||
454 | /* | ||
455 | * Do final permutation (inverse of IP). | ||
456 | */ | ||
457 | *l_out = fp_maskl[0][l >> 24] | ||
458 | | fp_maskl[1][(l >> 16) & 0xff] | ||
459 | | fp_maskl[2][(l >> 8) & 0xff] | ||
460 | | fp_maskl[3][l & 0xff] | ||
461 | | fp_maskl[4][r >> 24] | ||
462 | | fp_maskl[5][(r >> 16) & 0xff] | ||
463 | | fp_maskl[6][(r >> 8) & 0xff] | ||
464 | | fp_maskl[7][r & 0xff]; | ||
465 | *r_out = fp_maskr[0][l >> 24] | ||
466 | | fp_maskr[1][(l >> 16) & 0xff] | ||
467 | | fp_maskr[2][(l >> 8) & 0xff] | ||
468 | | fp_maskr[3][l & 0xff] | ||
469 | | fp_maskr[4][r >> 24] | ||
470 | | fp_maskr[5][(r >> 16) & 0xff] | ||
471 | | fp_maskr[6][(r >> 8) & 0xff] | ||
472 | | fp_maskr[7][r & 0xff]; | ||
473 | return(0); | ||
474 | } | ||
475 | |||
476 | int | ||
477 | des_cipher(in, out, salt, count) | ||
478 | const char *in; | ||
479 | char *out; | ||
480 | long salt; | ||
481 | int count; | ||
482 | { | ||
483 | u_int32_t l_out, r_out, rawl, rawr; | ||
484 | u_int32_t x[2]; | ||
485 | int retval; | ||
486 | |||
487 | if (!des_initialised) | ||
488 | des_init(); | ||
489 | |||
490 | setup_salt((int32_t)salt); | ||
491 | |||
492 | memcpy(x, in, sizeof x); | ||
493 | rawl = ntohl(x[0]); | ||
494 | rawr = ntohl(x[1]); | ||
495 | retval = do_des(rawl, rawr, &l_out, &r_out, count); | ||
496 | |||
497 | x[0] = htonl(l_out); | ||
498 | x[1] = htonl(r_out); | ||
499 | memcpy(out, x, sizeof x); | ||
500 | return(retval); | ||
501 | } | ||
502 | |||
503 | int | ||
504 | des_setkey(key) | ||
505 | const char *key; | ||
506 | { | ||
507 | u_int32_t k0, k1, rawkey0, rawkey1; | ||
508 | int shifts, round; | ||
509 | |||
510 | if (!des_initialised) | ||
511 | des_init(); | ||
512 | |||
513 | rawkey0 = ntohl(*(u_int32_t *) key); | ||
514 | rawkey1 = ntohl(*(u_int32_t *) (key + 4)); | ||
515 | |||
516 | if ((rawkey0 | rawkey1) | ||
517 | && rawkey0 == old_rawkey0 | ||
518 | && rawkey1 == old_rawkey1) { | ||
519 | /* | ||
520 | * Already setup for this key. | ||
521 | * This optimisation fails on a zero key (which is weak and | ||
522 | * has bad parity anyway) in order to simplify the starting | ||
523 | * conditions. | ||
524 | */ | ||
525 | return(0); | ||
526 | } | ||
527 | old_rawkey0 = rawkey0; | ||
528 | old_rawkey1 = rawkey1; | ||
529 | |||
530 | /* | ||
531 | * Do key permutation and split into two 28-bit subkeys. | ||
532 | */ | ||
533 | k0 = key_perm_maskl[0][rawkey0 >> 25] | ||
534 | | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] | ||
535 | | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] | ||
536 | | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] | ||
537 | | key_perm_maskl[4][rawkey1 >> 25] | ||
538 | | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] | ||
539 | | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] | ||
540 | | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; | ||
541 | k1 = key_perm_maskr[0][rawkey0 >> 25] | ||
542 | | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] | ||
543 | | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] | ||
544 | | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] | ||
545 | | key_perm_maskr[4][rawkey1 >> 25] | ||
546 | | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] | ||
547 | | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] | ||
548 | | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; | ||
549 | /* | ||
550 | * Rotate subkeys and do compression permutation. | ||
551 | */ | ||
552 | shifts = 0; | ||
553 | for (round = 0; round < 16; round++) { | ||
554 | u_int32_t t0, t1; | ||
555 | |||
556 | shifts += key_shifts[round]; | ||
557 | |||
558 | t0 = (k0 << shifts) | (k0 >> (28 - shifts)); | ||
559 | t1 = (k1 << shifts) | (k1 >> (28 - shifts)); | ||
560 | |||
561 | de_keysl[15 - round] = | ||
562 | en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] | ||
563 | | comp_maskl[1][(t0 >> 14) & 0x7f] | ||
564 | | comp_maskl[2][(t0 >> 7) & 0x7f] | ||
565 | | comp_maskl[3][t0 & 0x7f] | ||
566 | | comp_maskl[4][(t1 >> 21) & 0x7f] | ||
567 | | comp_maskl[5][(t1 >> 14) & 0x7f] | ||
568 | | comp_maskl[6][(t1 >> 7) & 0x7f] | ||
569 | | comp_maskl[7][t1 & 0x7f]; | ||
570 | |||
571 | de_keysr[15 - round] = | ||
572 | en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] | ||
573 | | comp_maskr[1][(t0 >> 14) & 0x7f] | ||
574 | | comp_maskr[2][(t0 >> 7) & 0x7f] | ||
575 | | comp_maskr[3][t0 & 0x7f] | ||
576 | | comp_maskr[4][(t1 >> 21) & 0x7f] | ||
577 | | comp_maskr[5][(t1 >> 14) & 0x7f] | ||
578 | | comp_maskr[6][(t1 >> 7) & 0x7f] | ||
579 | | comp_maskr[7][t1 & 0x7f]; | ||
580 | } | ||
581 | return(0); | ||
582 | } | ||
583 | |||
584 | int | ||
585 | setkey(key) | ||
586 | const char *key; | ||
587 | { | ||
588 | int i, j; | ||
589 | u_int32_t packed_keys[2]; | ||
590 | u_char *p; | ||
591 | |||
592 | p = (u_char *) packed_keys; | ||
593 | |||
594 | for (i = 0; i < 8; i++) { | ||
595 | p[i] = 0; | ||
596 | for (j = 0; j < 8; j++) | ||
597 | if (*key++ & 1) | ||
598 | p[i] |= bits8[j]; | ||
599 | } | ||
600 | return(des_setkey(p)); | ||
601 | } | ||
602 | |||
603 | int | ||
604 | encrypt(block, flag) | ||
605 | char *block; | ||
606 | int flag; | ||
607 | { | ||
608 | u_int32_t io[2]; | ||
609 | u_char *p; | ||
610 | int i, j, retval; | ||
611 | |||
612 | if (!des_initialised) | ||
613 | des_init(); | ||
614 | |||
615 | setup_salt((int32_t)0); | ||
616 | p = (u_char *)block; | ||
617 | for (i = 0; i < 2; i++) { | ||
618 | io[i] = 0L; | ||
619 | for (j = 0; j < 32; j++) | ||
620 | if (*p++ & 1) | ||
621 | io[i] |= bits32[j]; | ||
622 | } | ||
623 | retval = do_des(io[0], io[1], io, io + 1, flag ? -1 : 1); | ||
624 | for (i = 0; i < 2; i++) | ||
625 | for (j = 0; j < 32; j++) | ||
626 | block[(i << 5) | j] = (io[i] & bits32[j]) ? 1 : 0; | ||
627 | return(retval); | ||
628 | } | ||
diff --git a/src/lib/libc/include/namespace.h b/src/lib/libc/include/namespace.h index 803657e006..4a51f15ddf 100644 --- a/src/lib/libc/include/namespace.h +++ b/src/lib/libc/include/namespace.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $NetBSD: namespace.h,v 1.2 1995/02/27 13:02:12 cgd Exp $ */ | 1 | /* $OpenBSD: namespace.h,v 1.2 1996/08/19 08:28:08 tholo Exp $ */ |
2 | 2 | ||
3 | #define catclose _catclose | 3 | #define catclose _catclose |
4 | #define catgets _catgets | 4 | #define catgets _catgets |
diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc index 2d220067e4..935a1904c1 100644 --- a/src/lib/libc/net/Makefile.inc +++ b/src/lib/libc/net/Makefile.inc | |||
@@ -1,16 +1,19 @@ | |||
1 | # $NetBSD: Makefile.inc,v 1.23 1995/03/02 09:09:07 chopps Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.16 1998/08/29 21:11:40 deraadt Exp $ |
2 | # @(#)Makefile.inc 8.2 (Berkeley) 9/5/93 | ||
3 | 2 | ||
4 | # net sources | 3 | # net sources |
5 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/net ${.CURDIR}/net | 4 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/net ${.CURDIR}/net |
6 | 5 | ||
7 | SRCS+= gethostnamadr.c getnetbyaddr.c getnetbyname.c getnetent.c \ | 6 | CFLAGS+=-DRESOLVSORT |
8 | getproto.c getprotoent.c getprotoname.c getservbyname.c \ | 7 | |
8 | SRCS+= base64.c gethostnamadr.c getnetbyaddr.c getnetbyname.c getnetent.c \ | ||
9 | getnetnamadr.c getproto.c getprotoent.c getprotoname.c getservbyname.c \ | ||
9 | getservbyport.c getservent.c herror.c inet_addr.c inet_lnaof.c \ | 10 | getservbyport.c getservent.c herror.c inet_addr.c inet_lnaof.c \ |
10 | inet_makeaddr.c inet_netof.c inet_network.c inet_ntoa.c \ | 11 | inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \ |
11 | iso_addr.c linkaddr.c ns_addr.c ns_ntoa.c rcmd.c recv.c res_comp.c \ | 12 | inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c \ |
12 | res_debug.c res_init.c res_mkquery.c res_query.c res_send.c \ | 13 | inet_pton.c ipx_addr.c ipx_ntoa.c \ |
13 | send.c sethostent.c ethers.c | 14 | iso_addr.c linkaddr.c ns_addr.c ns_ntoa.c nsap_addr.c rcmd.c recv.c \ |
15 | res_comp.c res_data.c res_debug.c res_init.c res_mkquery.c res_query.c \ | ||
16 | res_random.c res_send.c send.c sethostent.c ethers.c rcmdsh.c | ||
14 | 17 | ||
15 | # machine-dependent net sources | 18 | # machine-dependent net sources |
16 | # m-d Makefile.inc must include sources for: | 19 | # m-d Makefile.inc must include sources for: |
@@ -18,16 +21,21 @@ SRCS+= gethostnamadr.c getnetbyaddr.c getnetbyname.c getnetent.c \ | |||
18 | 21 | ||
19 | .include "${.CURDIR}/arch/${MACHINE_ARCH}/net/Makefile.inc" | 22 | .include "${.CURDIR}/arch/${MACHINE_ARCH}/net/Makefile.inc" |
20 | 23 | ||
21 | MAN+= byteorder.3 gethostbyname.3 getnetent.3 getprotoent.3 getservent.3 \ | 24 | MAN+= byteorder.3 ethers.3 gethostbyname.3 getnetent.3 getprotoent.3 \ |
22 | inet.3 linkaddr.3 ns.3 rcmd.3 resolver.3 ethers.3 | 25 | getservent.3 inet.3 inet_net.3 iso_addr.3 link_addr.3 ns.3 ipx.3 \ |
26 | rcmd.3 rcmdsh.3 resolver.3 | ||
23 | 27 | ||
24 | MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ | 28 | MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ |
25 | byteorder.3 ntohs.3 | 29 | byteorder.3 ntohs.3 byteorder.3 htobe16.3 byteorder.3 htobe32.3 \ |
30 | byteorder.3 betoh16.3 byteorder.3 betoh32.3 byteorder.3 htole16.3 \ | ||
31 | byteorder.3 htole32.3 byteorder.3 letoh16.3 byteorder.3 letoh32.3 \ | ||
32 | byteorder.3 swap16.3 byteorder.3 swap32.3 | ||
26 | MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ | 33 | MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ |
27 | ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3 | 34 | ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3 ethers.3 ether_addr.3 |
28 | MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \ | 35 | MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \ |
29 | gethostbyname.3 sethostent.3 gethostbyname.3 gethostent.3 \ | 36 | gethostbyname.3 sethostent.3 gethostbyname.3 gethostent.3 \ |
30 | gethostbyname.3 herror.3 | 37 | gethostbyname.3 herror.3 gethostbyname.3 gethostbyname2.3 \ |
38 | gethostbyname.3 hstrerror.3 | ||
31 | MLINKS+=getnetent.3 endnetent.3 getnetent.3 getnetbyaddr.3 \ | 39 | MLINKS+=getnetent.3 endnetent.3 getnetent.3 getnetbyaddr.3 \ |
32 | getnetent.3 getnetbyname.3 getnetent.3 setnetent.3 | 40 | getnetent.3 getnetbyname.3 getnetent.3 setnetent.3 |
33 | MLINKS+=getprotoent.3 endprotoent.3 getprotoent.3 getprotobyname.3 \ | 41 | MLINKS+=getprotoent.3 endprotoent.3 getprotoent.3 getprotobyname.3 \ |
@@ -37,8 +45,10 @@ MLINKS+=getservent.3 endservent.3 getservent.3 getservbyname.3 \ | |||
37 | MLINKS+=inet.3 addr.3 inet.3 inet_addr.3 inet.3 inet_aton.3 \ | 45 | MLINKS+=inet.3 addr.3 inet.3 inet_addr.3 inet.3 inet_aton.3 \ |
38 | inet.3 inet_lnaof.3 inet.3 inet_makeaddr.3 inet.3 inet_netof.3 \ | 46 | inet.3 inet_lnaof.3 inet.3 inet_makeaddr.3 inet.3 inet_netof.3 \ |
39 | inet.3 inet_network.3 inet.3 inet_ntoa.3 inet.3 network.3 \ | 47 | inet.3 inet_network.3 inet.3 inet_ntoa.3 inet.3 network.3 \ |
40 | inet.3 ntoa.3 | 48 | inet.3 ntoa.3 inet.3 inet_ntop.3 inet.3 inet_pton.3 |
41 | MLINKS+=linkaddr.3 linkntoa.3 | 49 | MLINKS+=iso_addr.3 iso_ntoa.3 |
50 | MLINKS+=link_addr.3 link_ntoa.3 | ||
51 | MLINKS+=ipx.3 ipx_addr.3 ipx.3 ipx_ntoa.3 | ||
42 | MLINKS+=ns.3 ns_addr.3 ns.3 ns_ntoa.3 | 52 | MLINKS+=ns.3 ns_addr.3 ns.3 ns_ntoa.3 |
43 | MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 | 53 | MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 |
44 | MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ | 54 | MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ |
diff --git a/src/lib/libc/net/base64.c b/src/lib/libc/net/base64.c new file mode 100644 index 0000000000..452fe5afcc --- /dev/null +++ b/src/lib/libc/net/base64.c | |||
@@ -0,0 +1,317 @@ | |||
1 | /* $OpenBSD: base64.c,v 1.3 1997/11/08 20:46:55 deraadt Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1996 by Internet Software Consortium. | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
11 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
12 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
13 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
14 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
15 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
16 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
17 | * SOFTWARE. | ||
18 | */ | ||
19 | |||
20 | /* | ||
21 | * Portions Copyright (c) 1995 by International Business Machines, Inc. | ||
22 | * | ||
23 | * International Business Machines, Inc. (hereinafter called IBM) grants | ||
24 | * permission under its copyrights to use, copy, modify, and distribute this | ||
25 | * Software with or without fee, provided that the above copyright notice and | ||
26 | * all paragraphs of this notice appear in all copies, and that the name of IBM | ||
27 | * not be used in connection with the marketing of any product incorporating | ||
28 | * the Software or modifications thereof, without specific, written prior | ||
29 | * permission. | ||
30 | * | ||
31 | * To the extent it has a right to do so, IBM grants an immunity from suit | ||
32 | * under its patents, if any, for the use, sale or manufacture of products to | ||
33 | * the extent that such products are used for performing Domain Name System | ||
34 | * dynamic updates in TCP/IP networks by means of the Software. No immunity is | ||
35 | * granted for any product per se or for any other function of any product. | ||
36 | * | ||
37 | * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, | ||
38 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
39 | * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, | ||
40 | * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING | ||
41 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN | ||
42 | * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. | ||
43 | */ | ||
44 | |||
45 | #include <sys/types.h> | ||
46 | #include <sys/param.h> | ||
47 | #include <sys/socket.h> | ||
48 | #include <netinet/in.h> | ||
49 | #include <arpa/inet.h> | ||
50 | #include <arpa/nameser.h> | ||
51 | |||
52 | #include <ctype.h> | ||
53 | #include <resolv.h> | ||
54 | #include <stdio.h> | ||
55 | |||
56 | #include <stdlib.h> | ||
57 | #include <string.h> | ||
58 | |||
59 | #define Assert(Cond) if (!(Cond)) abort() | ||
60 | |||
61 | static const char Base64[] = | ||
62 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
63 | static const char Pad64 = '='; | ||
64 | |||
65 | /* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) | ||
66 | The following encoding technique is taken from RFC 1521 by Borenstein | ||
67 | and Freed. It is reproduced here in a slightly edited form for | ||
68 | convenience. | ||
69 | |||
70 | A 65-character subset of US-ASCII is used, enabling 6 bits to be | ||
71 | represented per printable character. (The extra 65th character, "=", | ||
72 | is used to signify a special processing function.) | ||
73 | |||
74 | The encoding process represents 24-bit groups of input bits as output | ||
75 | strings of 4 encoded characters. Proceeding from left to right, a | ||
76 | 24-bit input group is formed by concatenating 3 8-bit input groups. | ||
77 | These 24 bits are then treated as 4 concatenated 6-bit groups, each | ||
78 | of which is translated into a single digit in the base64 alphabet. | ||
79 | |||
80 | Each 6-bit group is used as an index into an array of 64 printable | ||
81 | characters. The character referenced by the index is placed in the | ||
82 | output string. | ||
83 | |||
84 | Table 1: The Base64 Alphabet | ||
85 | |||
86 | Value Encoding Value Encoding Value Encoding Value Encoding | ||
87 | 0 A 17 R 34 i 51 z | ||
88 | 1 B 18 S 35 j 52 0 | ||
89 | 2 C 19 T 36 k 53 1 | ||
90 | 3 D 20 U 37 l 54 2 | ||
91 | 4 E 21 V 38 m 55 3 | ||
92 | 5 F 22 W 39 n 56 4 | ||
93 | 6 G 23 X 40 o 57 5 | ||
94 | 7 H 24 Y 41 p 58 6 | ||
95 | 8 I 25 Z 42 q 59 7 | ||
96 | 9 J 26 a 43 r 60 8 | ||
97 | 10 K 27 b 44 s 61 9 | ||
98 | 11 L 28 c 45 t 62 + | ||
99 | 12 M 29 d 46 u 63 / | ||
100 | 13 N 30 e 47 v | ||
101 | 14 O 31 f 48 w (pad) = | ||
102 | 15 P 32 g 49 x | ||
103 | 16 Q 33 h 50 y | ||
104 | |||
105 | Special processing is performed if fewer than 24 bits are available | ||
106 | at the end of the data being encoded. A full encoding quantum is | ||
107 | always completed at the end of a quantity. When fewer than 24 input | ||
108 | bits are available in an input group, zero bits are added (on the | ||
109 | right) to form an integral number of 6-bit groups. Padding at the | ||
110 | end of the data is performed using the '=' character. | ||
111 | |||
112 | Since all base64 input is an integral number of octets, only the | ||
113 | ------------------------------------------------- | ||
114 | following cases can arise: | ||
115 | |||
116 | (1) the final quantum of encoding input is an integral | ||
117 | multiple of 24 bits; here, the final unit of encoded | ||
118 | output will be an integral multiple of 4 characters | ||
119 | with no "=" padding, | ||
120 | (2) the final quantum of encoding input is exactly 8 bits; | ||
121 | here, the final unit of encoded output will be two | ||
122 | characters followed by two "=" padding characters, or | ||
123 | (3) the final quantum of encoding input is exactly 16 bits; | ||
124 | here, the final unit of encoded output will be three | ||
125 | characters followed by one "=" padding character. | ||
126 | */ | ||
127 | |||
128 | int | ||
129 | b64_ntop(src, srclength, target, targsize) | ||
130 | u_char const *src; | ||
131 | size_t srclength; | ||
132 | char *target; | ||
133 | size_t targsize; | ||
134 | { | ||
135 | size_t datalength = 0; | ||
136 | u_char input[3]; | ||
137 | u_char output[4]; | ||
138 | int i; | ||
139 | |||
140 | while (2 < srclength) { | ||
141 | input[0] = *src++; | ||
142 | input[1] = *src++; | ||
143 | input[2] = *src++; | ||
144 | srclength -= 3; | ||
145 | |||
146 | output[0] = input[0] >> 2; | ||
147 | output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); | ||
148 | output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); | ||
149 | output[3] = input[2] & 0x3f; | ||
150 | Assert(output[0] < 64); | ||
151 | Assert(output[1] < 64); | ||
152 | Assert(output[2] < 64); | ||
153 | Assert(output[3] < 64); | ||
154 | |||
155 | if (datalength + 4 > targsize) | ||
156 | return (-1); | ||
157 | target[datalength++] = Base64[output[0]]; | ||
158 | target[datalength++] = Base64[output[1]]; | ||
159 | target[datalength++] = Base64[output[2]]; | ||
160 | target[datalength++] = Base64[output[3]]; | ||
161 | } | ||
162 | |||
163 | /* Now we worry about padding. */ | ||
164 | if (0 != srclength) { | ||
165 | /* Get what's left. */ | ||
166 | input[0] = input[1] = input[2] = '\0'; | ||
167 | for (i = 0; i < srclength; i++) | ||
168 | input[i] = *src++; | ||
169 | |||
170 | output[0] = input[0] >> 2; | ||
171 | output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); | ||
172 | output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); | ||
173 | Assert(output[0] < 64); | ||
174 | Assert(output[1] < 64); | ||
175 | Assert(output[2] < 64); | ||
176 | |||
177 | if (datalength + 4 > targsize) | ||
178 | return (-1); | ||
179 | target[datalength++] = Base64[output[0]]; | ||
180 | target[datalength++] = Base64[output[1]]; | ||
181 | if (srclength == 1) | ||
182 | target[datalength++] = Pad64; | ||
183 | else | ||
184 | target[datalength++] = Base64[output[2]]; | ||
185 | target[datalength++] = Pad64; | ||
186 | } | ||
187 | if (datalength >= targsize) | ||
188 | return (-1); | ||
189 | target[datalength] = '\0'; /* Returned value doesn't count \0. */ | ||
190 | return (datalength); | ||
191 | } | ||
192 | |||
193 | /* skips all whitespace anywhere. | ||
194 | converts characters, four at a time, starting at (or after) | ||
195 | src from base - 64 numbers into three 8 bit bytes in the target area. | ||
196 | it returns the number of data bytes stored at the target, or -1 on error. | ||
197 | */ | ||
198 | |||
199 | int | ||
200 | b64_pton(src, target, targsize) | ||
201 | char const *src; | ||
202 | u_char *target; | ||
203 | size_t targsize; | ||
204 | { | ||
205 | int tarindex, state, ch; | ||
206 | char *pos; | ||
207 | |||
208 | state = 0; | ||
209 | tarindex = 0; | ||
210 | |||
211 | while ((ch = *src++) != '\0') { | ||
212 | if (isspace(ch)) /* Skip whitespace anywhere. */ | ||
213 | continue; | ||
214 | |||
215 | if (ch == Pad64) | ||
216 | break; | ||
217 | |||
218 | pos = strchr(Base64, ch); | ||
219 | if (pos == 0) /* A non-base64 character. */ | ||
220 | return (-1); | ||
221 | |||
222 | switch (state) { | ||
223 | case 0: | ||
224 | if (target) { | ||
225 | if (tarindex >= targsize) | ||
226 | return (-1); | ||
227 | target[tarindex] = (pos - Base64) << 2; | ||
228 | } | ||
229 | state = 1; | ||
230 | break; | ||
231 | case 1: | ||
232 | if (target) { | ||
233 | if (tarindex + 1 >= targsize) | ||
234 | return (-1); | ||
235 | target[tarindex] |= (pos - Base64) >> 4; | ||
236 | target[tarindex+1] = ((pos - Base64) & 0x0f) | ||
237 | << 4 ; | ||
238 | } | ||
239 | tarindex++; | ||
240 | state = 2; | ||
241 | break; | ||
242 | case 2: | ||
243 | if (target) { | ||
244 | if (tarindex + 1 >= targsize) | ||
245 | return (-1); | ||
246 | target[tarindex] |= (pos - Base64) >> 2; | ||
247 | target[tarindex+1] = ((pos - Base64) & 0x03) | ||
248 | << 6; | ||
249 | } | ||
250 | tarindex++; | ||
251 | state = 3; | ||
252 | break; | ||
253 | case 3: | ||
254 | if (target) { | ||
255 | if (tarindex >= targsize) | ||
256 | return (-1); | ||
257 | target[tarindex] |= (pos - Base64); | ||
258 | } | ||
259 | tarindex++; | ||
260 | state = 0; | ||
261 | break; | ||
262 | } | ||
263 | } | ||
264 | |||
265 | /* | ||
266 | * We are done decoding Base-64 chars. Let's see if we ended | ||
267 | * on a byte boundary, and/or with erroneous trailing characters. | ||
268 | */ | ||
269 | |||
270 | if (ch == Pad64) { /* We got a pad char. */ | ||
271 | ch = *src++; /* Skip it, get next. */ | ||
272 | switch (state) { | ||
273 | case 0: /* Invalid = in first position */ | ||
274 | case 1: /* Invalid = in second position */ | ||
275 | return (-1); | ||
276 | |||
277 | case 2: /* Valid, means one byte of info */ | ||
278 | /* Skip any number of spaces. */ | ||
279 | for (; ch != '\0'; ch = *src++) | ||
280 | if (!isspace(ch)) | ||
281 | break; | ||
282 | /* Make sure there is another trailing = sign. */ | ||
283 | if (ch != Pad64) | ||
284 | return (-1); | ||
285 | ch = *src++; /* Skip the = */ | ||
286 | /* Fall through to "single trailing =" case. */ | ||
287 | /* FALLTHROUGH */ | ||
288 | |||
289 | case 3: /* Valid, means two bytes of info */ | ||
290 | /* | ||
291 | * We know this char is an =. Is there anything but | ||
292 | * whitespace after it? | ||
293 | */ | ||
294 | for (; ch != '\0'; ch = *src++) | ||
295 | if (!isspace(ch)) | ||
296 | return (-1); | ||
297 | |||
298 | /* | ||
299 | * Now make sure for cases 2 and 3 that the "extra" | ||
300 | * bits that slopped past the last full byte were | ||
301 | * zeros. If we don't check them, they become a | ||
302 | * subliminal channel. | ||
303 | */ | ||
304 | if (target && target[tarindex] != 0) | ||
305 | return (-1); | ||
306 | } | ||
307 | } else { | ||
308 | /* | ||
309 | * We ended by seeing the end of the string. Make sure we | ||
310 | * have no partial bytes lying around. | ||
311 | */ | ||
312 | if (state != 0) | ||
313 | return (-1); | ||
314 | } | ||
315 | |||
316 | return (tarindex); | ||
317 | } | ||
diff --git a/src/lib/libc/net/byteorder.3 b/src/lib/libc/net/byteorder.3 index 701a69f688..f2788b25dc 100644 --- a/src/lib/libc/net/byteorder.3 +++ b/src/lib/libc/net/byteorder.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $NetBSD: byteorder.3,v 1.3 1995/02/25 06:20:27 cgd Exp $ | 1 | .\" $OpenBSD: byteorder.3,v 1.5 1997/11/19 23:30:17 niklas Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1983, 1991, 1993 | 3 | .\" Copyright (c) 1983, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -31,8 +31,6 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" @(#)byteorder.3 8.1 (Berkeley) 6/4/93 | ||
35 | .\" | ||
36 | .Dd June 4, 1993 | 34 | .Dd June 4, 1993 |
37 | .Dt BYTEORDER 3 | 35 | .Dt BYTEORDER 3 |
38 | .Os BSD 4.2 | 36 | .Os BSD 4.2 |
@@ -40,26 +38,101 @@ | |||
40 | .Nm htonl , | 38 | .Nm htonl , |
41 | .Nm htons , | 39 | .Nm htons , |
42 | .Nm ntohl , | 40 | .Nm ntohl , |
43 | .Nm ntohs | 41 | .Nm ntohs , |
44 | .Nd convert values between host and network byte order | 42 | .Nm htobe32 , |
43 | .Nm htobe16 , | ||
44 | .Nm betoh32 , | ||
45 | .Nm betoh16 , | ||
46 | .Nm htole32 , | ||
47 | .Nm htole16 , | ||
48 | .Nm letoh32 , | ||
49 | .Nm letoh16 , | ||
50 | .Nm swap32 , | ||
51 | .Nm swap16 | ||
52 | .Nd convert values between different byte orderings | ||
45 | .Sh SYNOPSIS | 53 | .Sh SYNOPSIS |
46 | .Fd #include <sys/param.h> | 54 | .Fd #include <sys/types.h> |
47 | .Ft u_long | 55 | .Fd #include <machine/endian.h> |
48 | .Fn htonl "u_long hostlong" | 56 | .Ft u_int32_t |
49 | .Ft u_short | 57 | .Fn htonl "u_int32_t host32" |
50 | .Fn htons "u_short hostshort" | 58 | .Ft u_int16_t |
51 | .Ft u_long | 59 | .Fn htons "u_int16_t host16" |
52 | .Fn ntohl "u_long netlong" | 60 | .Ft u_int32_t |
53 | .Ft u_short | 61 | .Fn ntohl "u_int32_t net32" |
54 | .Fn ntohs "u_short netshort" | 62 | .Ft u_int16_t |
63 | .Fn ntohs "u_int16_t net16" | ||
64 | .Ft u_int32_t | ||
65 | .Fn htobe32 "u_int32_t host32" | ||
66 | .Ft u_int16_t | ||
67 | .Fn htobe16 "u_int16_t host16" | ||
68 | .Ft u_int32_t | ||
69 | .Fn betoh32 "u_int32_t big32" | ||
70 | .Ft u_int16_t | ||
71 | .Fn betoh16 "u_int16_t big16" | ||
72 | .Ft u_int32_t | ||
73 | .Fn htole32 "u_int32_t host32" | ||
74 | .Ft u_int16_t | ||
75 | .Fn htole16 "u_int16_t host16" | ||
76 | .Ft u_int32_t | ||
77 | .Fn letoh32 "u_int32_t little32" | ||
78 | .Ft u_int16_t | ||
79 | .Fn letoh16 "u_int16_t little16" | ||
80 | .Ft u_int32_t | ||
81 | .Fn swap32 "u_int32_t val32" | ||
82 | .Ft u_int16_t | ||
83 | .Fn swap16 "u_int16_t val16" | ||
55 | .Sh DESCRIPTION | 84 | .Sh DESCRIPTION |
56 | These routines convert 16 and 32 bit quantities between network | 85 | These routines convert 16 and 32 bit quantities between different |
57 | byte order and host byte order. | 86 | byte orderings. The "swap" functions reverse the byte ordering of |
87 | the given quantity, the others converts either from/to the native | ||
88 | byte order used by the host to/from either little- or big-endian (a.k.a | ||
89 | network) order. | ||
90 | .Pp | ||
91 | Apart from the "swap" functions, the names can be described by this form: | ||
92 | {src-order}to{dst-order}{size}. | ||
93 | Both {src-order} and {dst-order} can take the following forms: | ||
94 | .Bl -tag -width "be " | ||
95 | .It Em h | ||
96 | host order | ||
97 | .It Em n | ||
98 | network order (big-endian) | ||
99 | .It Em be | ||
100 | big-endian (Most significant byte first) | ||
101 | .It Em le | ||
102 | little-endian (Least significant byte first) | ||
103 | .El | ||
104 | .Pp | ||
105 | One of the specified orderings must be "h". | ||
106 | {Size} will take these forms: | ||
107 | .Bl -tag -width "32 " | ||
108 | .It Em l | ||
109 | long (32-bit, used in conjunction with forms involving "n") | ||
110 | .It Em s | ||
111 | short (16-bit, used in conjunction with forms involving "n") | ||
112 | .It Em 16 | ||
113 | 16-bit | ||
114 | .It Em 32 | ||
115 | 32-bit | ||
116 | .El | ||
117 | .Pp | ||
118 | The "swap" functions are of the form: swap{size}. | ||
119 | .Pp | ||
120 | Names involving "n" convert quantities between network | ||
121 | byte order and host byte order. The last letter (s/l) is a mnemonic | ||
122 | for the traditional names for such quantities, short and long, | ||
123 | respectively. Today, the C concept of "short"/"long" integers | ||
124 | need not coincide with this traditional misunderstanding. | ||
58 | On machines which have a byte order which is the same as the network | 125 | On machines which have a byte order which is the same as the network |
59 | order, routines are defined as null macros. | 126 | order, routines are defined as null macros. |
60 | .Pp | 127 | .Pp |
61 | These routines are most often used in conjunction with Internet | 128 | The functions involving either "be", "le" or "swap" use the numbers |
62 | addresses and ports as returned by | 129 | (16/32) for specifying the bitwidth of the quantities they operate on. |
130 | Currently all supported architectures are either big- or little-endian | ||
131 | so either the "be" or the "le" variants are implemented as null macros. | ||
132 | .Pp | ||
133 | The routines mentioned above which have either {src-order} or {dst-order} | ||
134 | set to "n" are most often used in | ||
135 | conjunction with Internet addresses and ports as returned by | ||
63 | .Xr gethostbyname 3 | 136 | .Xr gethostbyname 3 |
64 | and | 137 | and |
65 | .Xr getservent 3 . | 138 | .Xr getservent 3 . |
@@ -73,6 +146,10 @@ functions appeared in | |||
73 | .Bx 4.2 . | 146 | .Bx 4.2 . |
74 | .Sh BUGS | 147 | .Sh BUGS |
75 | On the | 148 | On the |
76 | .Tn VAX | 149 | .Tn vax , |
150 | .Tn alpha , | ||
151 | .Tn i386 , | ||
152 | and so far | ||
153 | .Tn mips | ||
77 | bytes are handled backwards from most everyone else in | 154 | bytes are handled backwards from most everyone else in |
78 | the world. This is not expected to be fixed in the near future. | 155 | the world. This is not expected to be fixed in the near future. |
diff --git a/src/lib/libc/net/ethers.3 b/src/lib/libc/net/ethers.3 index 81e6c65935..f5db308115 100644 --- a/src/lib/libc/net/ethers.3 +++ b/src/lib/libc/net/ethers.3 | |||
@@ -1,15 +1,17 @@ | |||
1 | .\" $OpenBSD: ethers.3,v 1.9 1998/05/12 09:15:19 deraadt Exp $ | ||
1 | .\" | 2 | .\" |
2 | .\" Written by roland@frob.com. Public domain. | 3 | .\" Written by roland@frob.com. Public domain. |
3 | .\" | 4 | .\" |
4 | .Dd December 16, 1993 | 5 | .Dd December 16, 1993 |
5 | .Dt ETHERS 3 | 6 | .Dt ETHERS 3 |
6 | .Os NetBSD | 7 | .Os |
7 | .Sh NAME | 8 | .Sh NAME |
9 | .Nm ether_aton , | ||
8 | .Nm ether_ntoa , | 10 | .Nm ether_ntoa , |
9 | .Nm ether_addr , | 11 | .Nm ether_addr , |
10 | .Nm ether_ntohost , | 12 | .Nm ether_ntohost , |
11 | .Nm ether_hostton , | 13 | .Nm ether_hostton , |
12 | .Nm ether_line , | 14 | .Nm ether_line |
13 | .Nd get ethers entry | 15 | .Nd get ethers entry |
14 | .Sh SYNOPSIS | 16 | .Sh SYNOPSIS |
15 | .Fd #include <netinet/if_ether.h> | 17 | .Fd #include <netinet/if_ether.h> |
@@ -17,15 +19,18 @@ | |||
17 | .Fn ether_ntoa "struct ether_addr *e" | 19 | .Fn ether_ntoa "struct ether_addr *e" |
18 | .Ft struct ether_addr * | 20 | .Ft struct ether_addr * |
19 | .Fn ether_aton "char *s" | 21 | .Fn ether_aton "char *s" |
22 | .Ft int | ||
20 | .Fn ether_ntohost "char *hostname" "struct ether_addr *e" | 23 | .Fn ether_ntohost "char *hostname" "struct ether_addr *e" |
24 | .Ft int | ||
21 | .Fn ether_hostton "char *hostname" "struct ether_addr *e" | 25 | .Fn ether_hostton "char *hostname" "struct ether_addr *e" |
26 | .Ft int | ||
22 | .Fn ether_line "char *l" "struct ether_addr *e" "char *hostname" | 27 | .Fn ether_line "char *l" "struct ether_addr *e" "char *hostname" |
23 | .Sh DESCRIPTION | 28 | .Sh DESCRIPTION |
24 | Ethernet addresses are represented by the | 29 | Ethernet addresses are represented by the |
25 | following structure: | 30 | following structure: |
26 | .Bd -literal -offset indent | 31 | .Bd -literal -offset indent |
27 | struct ether_addr { | 32 | struct ether_addr { |
28 | u_char ether_addr_octet[6]; | 33 | u_int8_t ether_addr_octet[6]; |
29 | }; | 34 | }; |
30 | .Ed | 35 | .Ed |
31 | .Pp | 36 | .Pp |
@@ -51,12 +56,15 @@ addresses, | |||
51 | The | 56 | The |
52 | .Fn ether_ntohost | 57 | .Fn ether_ntohost |
53 | function looks up the given Ethernet address and writes the associated | 58 | function looks up the given Ethernet address and writes the associated |
54 | host name into the character buffer passed. | 59 | host name into the character buffer passed. This buffer should be |
60 | .Ev MAXHOSTNAMELEN | ||
61 | characters in size. | ||
55 | The | 62 | The |
56 | .Fn ether_hostton | 63 | .Fn ether_hostton |
57 | function looks up the given host name and writes the associated | 64 | function looks up the given host name and writes the associated |
58 | Ethernet address into the structure passed. Both functions return | 65 | Ethernet address into the structure passed. Both functions return |
59 | zero if they find the requested host name or address, and -1 if not. | 66 | zero if they find the requested host name or address, and -1 if not. |
67 | .Pp | ||
60 | Each call reads | 68 | Each call reads |
61 | .Pa /etc/ethers | 69 | .Pa /etc/ethers |
62 | from the beginning; if a + appears alone on a line in the file, then | 70 | from the beginning; if a + appears alone on a line in the file, then |
@@ -76,6 +84,9 @@ function parses a line from the | |||
76 | file and fills in the passed ``struct ether_addr'' and character | 84 | file and fills in the passed ``struct ether_addr'' and character |
77 | buffer with the Ethernet address and host name on the line. It | 85 | buffer with the Ethernet address and host name on the line. It |
78 | returns zero if the line was successfully parsed and -1 if not. | 86 | returns zero if the line was successfully parsed and -1 if not. |
87 | The character buffer buffer should be | ||
88 | .Ev MAXHOSTNAMELEN | ||
89 | characters in size. | ||
79 | .Sh FILES | 90 | .Sh FILES |
80 | .Bl -tag -width /etc/ethers -compact | 91 | .Bl -tag -width /etc/ethers -compact |
81 | .It Pa /etc/ethers | 92 | .It Pa /etc/ethers |
@@ -95,8 +106,4 @@ NetBSD 0.9b. | |||
95 | .Sh BUGS | 106 | .Sh BUGS |
96 | The data space used by these functions is static; if future use | 107 | The data space used by these functions is static; if future use |
97 | requires the data, it should be copied before any subsequent calls to | 108 | requires the data, it should be copied before any subsequent calls to |
98 | these functions overwrite it. There is no way to restrict how many | 109 | these functions overwrite it. |
99 | character will be written into the host name buffer passed. A very | ||
100 | long line in | ||
101 | .Pa /etc/ethers | ||
102 | could overflow your buffer. | ||
diff --git a/src/lib/libc/net/ethers.c b/src/lib/libc/net/ethers.c index 0f32b9b71b..9df876b6f4 100644 --- a/src/lib/libc/net/ethers.c +++ b/src/lib/libc/net/ethers.c | |||
@@ -1,12 +1,42 @@ | |||
1 | /* $NetBSD: ethers.c,v 1.5 1995/02/25 06:20:28 cgd Exp $ */ | 1 | /* $OpenBSD: ethers.c,v 1.9 1998/06/21 22:13:44 millert Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * ethers(3N) a la Sun. | 4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> |
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The name of the author may not be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
5 | * | 17 | * |
6 | * Written by Roland McGrath <roland@frob.com> 10/14/93. | 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
7 | * Public domain. | 19 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
20 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
21 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | /* | ||
31 | * ethers(3) a la Sun. | ||
32 | * Originally Written by Roland McGrath <roland@frob.com> 10/14/93. | ||
33 | * Substantially modified by Todd C. Miller <Todd.Miller@courtesan.com> | ||
8 | */ | 34 | */ |
9 | 35 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | ||
37 | static char rcsid[] = "$OpenBSD: ethers.c,v 1.9 1998/06/21 22:13:44 millert Exp $"; | ||
38 | #endif /* LIBC_SCCS and not lint */ | ||
39 | |||
10 | #include <sys/types.h> | 40 | #include <sys/types.h> |
11 | #include <sys/socket.h> | 41 | #include <sys/socket.h> |
12 | #include <net/if.h> | 42 | #include <net/if.h> |
@@ -18,22 +48,60 @@ | |||
18 | #include <stdio.h> | 48 | #include <stdio.h> |
19 | #include <stdlib.h> | 49 | #include <stdlib.h> |
20 | #include <string.h> | 50 | #include <string.h> |
51 | #include <ctype.h> | ||
21 | 52 | ||
22 | #ifndef _PATH_ETHERS | 53 | #ifndef _PATH_ETHERS |
23 | #define _PATH_ETHERS "/etc/ethers" | 54 | #define _PATH_ETHERS "/etc/ethers" |
24 | #endif | 55 | #endif |
25 | 56 | ||
57 | static char * _ether_aton __P((char *, struct ether_addr *)); | ||
58 | |||
26 | char * | 59 | char * |
27 | ether_ntoa(e) | 60 | ether_ntoa(e) |
28 | struct ether_addr *e; | 61 | struct ether_addr *e; |
29 | { | 62 | { |
30 | static char a[] = "xx:xx:xx:xx:xx:xx"; | 63 | static char a[] = "xx:xx:xx:xx:xx:xx"; |
31 | 64 | ||
32 | sprintf(a, "%02x:%02x:%02x:%02x:%02x:%02x", | 65 | if (e->ether_addr_octet[0] > 0xFF || e->ether_addr_octet[1] > 0xFF || |
66 | e->ether_addr_octet[2] > 0xFF || e->ether_addr_octet[3] > 0xFF || | ||
67 | e->ether_addr_octet[4] > 0xFF || e->ether_addr_octet[5] > 0xFF) { | ||
68 | errno = EINVAL; | ||
69 | return (NULL); | ||
70 | } | ||
71 | |||
72 | (void)sprintf(a, "%02x:%02x:%02x:%02x:%02x:%02x", | ||
33 | e->ether_addr_octet[0], e->ether_addr_octet[1], | 73 | e->ether_addr_octet[0], e->ether_addr_octet[1], |
34 | e->ether_addr_octet[2], e->ether_addr_octet[3], | 74 | e->ether_addr_octet[2], e->ether_addr_octet[3], |
35 | e->ether_addr_octet[4], e->ether_addr_octet[5]); | 75 | e->ether_addr_octet[4], e->ether_addr_octet[5]); |
36 | return a; | 76 | |
77 | return (a); | ||
78 | } | ||
79 | |||
80 | static char * | ||
81 | _ether_aton(s, e) | ||
82 | char *s; | ||
83 | struct ether_addr *e; | ||
84 | { | ||
85 | int i; | ||
86 | long l; | ||
87 | char *pp; | ||
88 | |||
89 | while (isspace(*s)) | ||
90 | s++; | ||
91 | |||
92 | /* expect 6 hex octets separated by ':' or space/NUL if last octet */ | ||
93 | for (i = 0; i < 6; i++) { | ||
94 | l = strtol(s, &pp, 16); | ||
95 | if (pp == s || l > 0xFF) | ||
96 | return (NULL); | ||
97 | if (!(*pp == ':' || (i == 5 && (isspace(*pp) || *pp == '\0')))) | ||
98 | return (NULL); | ||
99 | e->ether_addr_octet[i] = (u_char)l; | ||
100 | s = pp + 1; | ||
101 | } | ||
102 | |||
103 | /* return character after the octets ala strtol(3) */ | ||
104 | return (pp); | ||
37 | } | 105 | } |
38 | 106 | ||
39 | struct ether_addr * | 107 | struct ether_addr * |
@@ -41,33 +109,32 @@ ether_aton(s) | |||
41 | char *s; | 109 | char *s; |
42 | { | 110 | { |
43 | static struct ether_addr n; | 111 | static struct ether_addr n; |
44 | u_int i[6]; | 112 | |
45 | 113 | return (_ether_aton(s, &n) ? &n : NULL); | |
46 | if (sscanf(s, " %x:%x:%x:%x:%x:%x ", &i[0], &i[1], | ||
47 | &i[2], &i[3], &i[4], &i[5]) == 6) { | ||
48 | n.ether_addr_octet[0] = (u_char)i[0]; | ||
49 | n.ether_addr_octet[1] = (u_char)i[1]; | ||
50 | n.ether_addr_octet[2] = (u_char)i[2]; | ||
51 | n.ether_addr_octet[3] = (u_char)i[3]; | ||
52 | n.ether_addr_octet[4] = (u_char)i[4]; | ||
53 | n.ether_addr_octet[5] = (u_char)i[5]; | ||
54 | return &n; | ||
55 | } | ||
56 | return NULL; | ||
57 | } | 114 | } |
58 | 115 | ||
116 | int | ||
59 | ether_ntohost(hostname, e) | 117 | ether_ntohost(hostname, e) |
60 | char *hostname; | 118 | char *hostname; |
61 | struct ether_addr *e; | 119 | struct ether_addr *e; |
62 | { | 120 | { |
63 | FILE *f; | 121 | FILE *f; |
64 | char buf[BUFSIZ]; | 122 | char buf[BUFSIZ+1], *p; |
123 | size_t len; | ||
65 | struct ether_addr try; | 124 | struct ether_addr try; |
66 | |||
67 | #ifdef YP | 125 | #ifdef YP |
68 | char trybuf[sizeof "xx:xx:xx:xx:xx:xx"]; | 126 | char trybuf[sizeof("xx:xx:xx:xx:xx:xx")]; |
69 | int trylen; | 127 | int trylen; |
128 | #endif | ||
129 | |||
130 | if (e->ether_addr_octet[0] > 0xFF || e->ether_addr_octet[1] > 0xFF || | ||
131 | e->ether_addr_octet[2] > 0xFF || e->ether_addr_octet[3] > 0xFF || | ||
132 | e->ether_addr_octet[4] > 0xFF || e->ether_addr_octet[5] > 0xFF) { | ||
133 | errno = EINVAL; | ||
134 | return (-1); | ||
135 | } | ||
70 | 136 | ||
137 | #ifdef YP | ||
71 | sprintf(trybuf, "%x:%x:%x:%x:%x:%x", | 138 | sprintf(trybuf, "%x:%x:%x:%x:%x:%x", |
72 | e->ether_addr_octet[0], e->ether_addr_octet[1], | 139 | e->ether_addr_octet[0], e->ether_addr_octet[1], |
73 | e->ether_addr_octet[2], e->ether_addr_octet[3], | 140 | e->ether_addr_octet[2], e->ether_addr_octet[3], |
@@ -76,12 +143,19 @@ ether_ntohost(hostname, e) | |||
76 | #endif | 143 | #endif |
77 | 144 | ||
78 | f = fopen(_PATH_ETHERS, "r"); | 145 | f = fopen(_PATH_ETHERS, "r"); |
79 | if (f==NULL) | 146 | if (f == NULL) |
80 | return -1; | 147 | return (-1); |
81 | while (fgets(buf, sizeof buf, f)) { | 148 | while ((p = fgetln(f, &len)) != NULL) { |
149 | if (p[len-1] == '\n') | ||
150 | len--; | ||
151 | if (len > sizeof(buf) - 2) | ||
152 | continue; | ||
153 | (void)memcpy(buf, p, len); | ||
154 | buf[len] = '\n'; /* code assumes newlines later on */ | ||
155 | buf[len+1] = '\0'; | ||
82 | #ifdef YP | 156 | #ifdef YP |
83 | /* A + in the file means try YP now. */ | 157 | /* A + in the file means try YP now. */ |
84 | if (!strncmp(buf, "+\n", sizeof buf)) { | 158 | if (!strncmp(buf, "+\n", sizeof(buf))) { |
85 | char *ypbuf, *ypdom; | 159 | char *ypbuf, *ypdom; |
86 | int ypbuflen; | 160 | int ypbuflen; |
87 | 161 | ||
@@ -93,42 +167,51 @@ ether_ntohost(hostname, e) | |||
93 | if (ether_line(ypbuf, &try, hostname) == 0) { | 167 | if (ether_line(ypbuf, &try, hostname) == 0) { |
94 | free(ypbuf); | 168 | free(ypbuf); |
95 | (void)fclose(f); | 169 | (void)fclose(f); |
96 | return 0; | 170 | return (0); |
97 | } | 171 | } |
98 | free(ypbuf); | 172 | free(ypbuf); |
99 | continue; | 173 | continue; |
100 | } | 174 | } |
101 | #endif | 175 | #endif |
102 | if (ether_line(buf, &try, hostname) == 0 && | 176 | if (ether_line(buf, &try, hostname) == 0 && |
103 | bcmp((char *)&try, (char *)e, sizeof try) == 0) { | 177 | memcmp((void *)&try, (void *)e, sizeof(try)) == 0) { |
104 | (void)fclose(f); | 178 | (void)fclose(f); |
105 | return 0; | 179 | return (0); |
106 | } | 180 | } |
107 | } | 181 | } |
108 | (void)fclose(f); | 182 | (void)fclose(f); |
109 | errno = ENOENT; | 183 | errno = ENOENT; |
110 | return -1; | 184 | return (-1); |
111 | } | 185 | } |
112 | 186 | ||
187 | int | ||
113 | ether_hostton(hostname, e) | 188 | ether_hostton(hostname, e) |
114 | char *hostname; | 189 | char *hostname; |
115 | struct ether_addr *e; | 190 | struct ether_addr *e; |
116 | { | 191 | { |
117 | FILE *f; | 192 | FILE *f; |
118 | char buf[BUFSIZ]; | 193 | char buf[BUFSIZ+1], *p; |
119 | char try[MAXHOSTNAMELEN]; | 194 | char try[MAXHOSTNAMELEN]; |
195 | size_t len; | ||
120 | #ifdef YP | 196 | #ifdef YP |
121 | int hostlen = strlen(hostname); | 197 | int hostlen = strlen(hostname); |
122 | #endif | 198 | #endif |
123 | 199 | ||
124 | f = fopen(_PATH_ETHERS, "r"); | 200 | f = fopen(_PATH_ETHERS, "r"); |
125 | if (f==NULL) | 201 | if (f==NULL) |
126 | return -1; | 202 | return (-1); |
127 | 203 | ||
128 | while (fgets(buf, sizeof buf, f)) { | 204 | while ((p = fgetln(f, &len)) != NULL) { |
205 | if (p[len-1] == '\n') | ||
206 | len--; | ||
207 | if (len > sizeof(buf) - 2) | ||
208 | continue; | ||
209 | memcpy(buf, p, len); | ||
210 | buf[len] = '\n'; /* code assumes newlines later on */ | ||
211 | buf[len+1] = '\0'; | ||
129 | #ifdef YP | 212 | #ifdef YP |
130 | /* A + in the file means try YP now. */ | 213 | /* A + in the file means try YP now. */ |
131 | if (!strncmp(buf, "+\n", sizeof buf)) { | 214 | if (!strncmp(buf, "+\n", sizeof(buf))) { |
132 | char *ypbuf, *ypdom; | 215 | char *ypbuf, *ypdom; |
133 | int ypbuflen; | 216 | int ypbuflen; |
134 | 217 | ||
@@ -140,7 +223,7 @@ ether_hostton(hostname, e) | |||
140 | if (ether_line(ypbuf, e, try) == 0) { | 223 | if (ether_line(ypbuf, e, try) == 0) { |
141 | free(ypbuf); | 224 | free(ypbuf); |
142 | (void)fclose(f); | 225 | (void)fclose(f); |
143 | return 0; | 226 | return (0); |
144 | } | 227 | } |
145 | free(ypbuf); | 228 | free(ypbuf); |
146 | continue; | 229 | continue; |
@@ -148,31 +231,40 @@ ether_hostton(hostname, e) | |||
148 | #endif | 231 | #endif |
149 | if (ether_line(buf, e, try) == 0 && strcmp(hostname, try) == 0) { | 232 | if (ether_line(buf, e, try) == 0 && strcmp(hostname, try) == 0) { |
150 | (void)fclose(f); | 233 | (void)fclose(f); |
151 | return 0; | 234 | return (0); |
152 | } | 235 | } |
153 | } | 236 | } |
154 | (void)fclose(f); | 237 | (void)fclose(f); |
155 | errno = ENOENT; | 238 | errno = ENOENT; |
156 | return -1; | 239 | return (-1); |
157 | } | 240 | } |
158 | 241 | ||
159 | ether_line(l, e, hostname) | 242 | int |
160 | char *l; | 243 | ether_line(line, e, hostname) |
244 | char *line; | ||
161 | struct ether_addr *e; | 245 | struct ether_addr *e; |
162 | char *hostname; | 246 | char *hostname; |
163 | { | 247 | { |
164 | u_int i[6]; | 248 | char *p; |
165 | 249 | size_t n; | |
166 | if (sscanf(l, " %x:%x:%x:%x:%x:%x %s\n", &i[0], &i[1], | 250 | |
167 | &i[2], &i[3], &i[4], &i[5], hostname) == 7) { | 251 | /* Parse "xx:xx:xx:xx:xx:xx" */ |
168 | e->ether_addr_octet[0] = (u_char)i[0]; | 252 | if ((p = _ether_aton(line, e)) == NULL || (*p != ' ' && *p != '\t')) |
169 | e->ether_addr_octet[1] = (u_char)i[1]; | 253 | goto bad; |
170 | e->ether_addr_octet[2] = (u_char)i[2]; | 254 | |
171 | e->ether_addr_octet[3] = (u_char)i[3]; | 255 | /* Now get the hostname */ |
172 | e->ether_addr_octet[4] = (u_char)i[4]; | 256 | while (isspace(*p)) |
173 | e->ether_addr_octet[5] = (u_char)i[5]; | 257 | p++; |
174 | return 0; | 258 | if (*p == '\0') |
175 | } | 259 | goto bad; |
260 | n = strcspn(p, " \t\n"); | ||
261 | if (n >= MAXHOSTNAMELEN) | ||
262 | goto bad; | ||
263 | (void)strncpy(hostname, p, n); | ||
264 | hostname[n] = '\0'; | ||
265 | return (0); | ||
266 | |||
267 | bad: | ||
176 | errno = EINVAL; | 268 | errno = EINVAL; |
177 | return -1; | 269 | return (-1); |
178 | } | 270 | } |
diff --git a/src/lib/libc/net/gethostbyname.3 b/src/lib/libc/net/gethostbyname.3 index bac0368296..37069c0a59 100644 --- a/src/lib/libc/net/gethostbyname.3 +++ b/src/lib/libc/net/gethostbyname.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $NetBSD: gethostbyname.3,v 1.6 1995/02/25 06:20:28 cgd Exp $ | 1 | .\" $OpenBSD: gethostbyname.3,v 1.9 1998/09/07 16:44:35 aaron Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1983, 1987, 1991, 1993 | 3 | .\" Copyright (c) 1983, 1987, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -31,17 +31,17 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" @(#)gethostbyname.3 8.2 (Berkeley) 4/19/94 | 34 | .Dd March 13, 1997 |
35 | .\" | ||
36 | .Dd April 19, 1994 | ||
37 | .Dt GETHOSTBYNAME 3 | 35 | .Dt GETHOSTBYNAME 3 |
38 | .Os BSD 4.2 | 36 | .Os |
39 | .Sh NAME | 37 | .Sh NAME |
40 | .Nm gethostbyname , | 38 | .Nm gethostbyname , |
39 | .Nm gethostbyname2 , | ||
41 | .Nm gethostbyaddr , | 40 | .Nm gethostbyaddr , |
42 | .Nm gethostent , | 41 | .Nm gethostent , |
43 | .Nm sethostent , | 42 | .Nm sethostent , |
44 | .Nm endhostent , | 43 | .Nm endhostent , |
44 | .Nm hstrerror , | ||
45 | .Nm herror | 45 | .Nm herror |
46 | .Nd get network host entry | 46 | .Nd get network host entry |
47 | .Sh SYNOPSIS | 47 | .Sh SYNOPSIS |
@@ -50,12 +50,19 @@ | |||
50 | .Ft struct hostent * | 50 | .Ft struct hostent * |
51 | .Fn gethostbyname "const char *name" | 51 | .Fn gethostbyname "const char *name" |
52 | .Ft struct hostent * | 52 | .Ft struct hostent * |
53 | .Fn gethostbyname2 "const char *name" "int af" | ||
54 | .Ft struct hostent * | ||
53 | .Fn gethostbyaddr "const char *addr" "int len" "int type" | 55 | .Fn gethostbyaddr "const char *addr" "int len" "int type" |
54 | .Ft struct hostent * | 56 | .Ft struct hostent * |
55 | .Fn gethostent void | 57 | .Fn gethostent void |
58 | .Ft void | ||
56 | .Fn sethostent "int stayopen" | 59 | .Fn sethostent "int stayopen" |
60 | .Ft void | ||
57 | .Fn endhostent void | 61 | .Fn endhostent void |
58 | .Fn herror "char *string" | 62 | .Ft void |
63 | .Fn herror "const char *string" | ||
64 | .Ft const char * | ||
65 | .Fn hstrerror "int err" | ||
59 | .Sh DESCRIPTION | 66 | .Sh DESCRIPTION |
60 | The | 67 | The |
61 | .Fn gethostbyname | 68 | .Fn gethostbyname |
@@ -92,8 +99,7 @@ Official name of the host. | |||
92 | .It Fa h_aliases | 99 | .It Fa h_aliases |
93 | A zero terminated array of alternate names for the host. | 100 | A zero terminated array of alternate names for the host. |
94 | .It Fa h_addrtype | 101 | .It Fa h_addrtype |
95 | The type of address being returned; currently always | 102 | The type of address being returned. |
96 | .Dv AF_INET . | ||
97 | .It Fa h_length | 103 | .It Fa h_length |
98 | The length, in bytes, of the address. | 104 | The length, in bytes, of the address. |
99 | .It Fa h_addr_list | 105 | .It Fa h_addr_list |
@@ -103,6 +109,7 @@ Host addresses are returned in network byte order. | |||
103 | The first address in | 109 | The first address in |
104 | .Fa h_addr_list ; | 110 | .Fa h_addr_list ; |
105 | this is for backward compatibility. | 111 | this is for backward compatibility. |
112 | .El | ||
106 | .Pp | 113 | .Pp |
107 | When using the nameserver, | 114 | When using the nameserver, |
108 | .Fn gethostbyname | 115 | .Fn gethostbyname |
@@ -116,6 +123,14 @@ See | |||
116 | .Xr hostname 7 | 123 | .Xr hostname 7 |
117 | for the domain search procedure and the alias file format. | 124 | for the domain search procedure and the alias file format. |
118 | .Pp | 125 | .Pp |
126 | .Fn Gethostbyname2 | ||
127 | is an advanced form of | ||
128 | .Fn gethostbyname | ||
129 | which allows lookups in address families other than | ||
130 | .Dv AF_INET , | ||
131 | for example | ||
132 | .Dv AF_INET6 . | ||
133 | .Pp | ||
119 | The | 134 | The |
120 | .Fn sethostent | 135 | .Fn sethostent |
121 | function | 136 | function |
@@ -141,13 +156,27 @@ function | |||
141 | closes the | 156 | closes the |
142 | .Tn TCP | 157 | .Tn TCP |
143 | connection. | 158 | connection. |
159 | .Pp | ||
160 | The | ||
161 | .Fn herror | ||
162 | function prints an error message describing the failure. If its argument | ||
163 | .Fa string | ||
164 | is | ||
165 | .Pf non Dv -NULL , | ||
166 | it is prepended to the message string and separated from it by a colon | ||
167 | and a space. The error message is printed with a trailing newline. | ||
168 | The contents of the error message is the same as that returned by | ||
169 | .Fn hstrerror | ||
170 | with argument | ||
171 | .Fa h_errno . | ||
144 | .Sh FILES | 172 | .Sh FILES |
145 | .Bl -tag -width /etc/hosts -compact | 173 | .Bl -tag -width /etc/hosts -compact |
146 | .It Pa /etc/hosts | 174 | .It Pa /etc/hosts |
147 | .El | 175 | .El |
148 | .Sh DIAGNOSTICS | 176 | .Sh DIAGNOSTICS |
149 | Error return status from | 177 | Error return status from |
150 | .Fn gethostbyname | 178 | .Fn gethostbyname , |
179 | .Fn gethostbyname2 , | ||
151 | and | 180 | and |
152 | .Fn gethostbyaddr | 181 | .Fn gethostbyaddr |
153 | is indicated by return of a null pointer. | 182 | is indicated by return of a null pointer. |
@@ -155,15 +184,6 @@ The external integer | |||
155 | .Va h_errno | 184 | .Va h_errno |
156 | may then be checked to see whether this is a temporary failure | 185 | may then be checked to see whether this is a temporary failure |
157 | or an invalid or unknown host. | 186 | or an invalid or unknown host. |
158 | The routine | ||
159 | .Fn herror | ||
160 | can be used to print an error message describing the failure. | ||
161 | If its argument | ||
162 | .Fa string | ||
163 | is | ||
164 | .Pf non Dv -NULL , | ||
165 | it is printed, followed by a colon and a space. | ||
166 | The error message is printed with a trailing newline. | ||
167 | .Pp | 187 | .Pp |
168 | The variable | 188 | The variable |
169 | .Va h_errno | 189 | .Va h_errno |
@@ -197,20 +217,6 @@ for example, a mail-forwarder may be registered for this domain. | |||
197 | The | 217 | The |
198 | .Fn gethostent | 218 | .Fn gethostent |
199 | function | 219 | function |
200 | is defined, and | ||
201 | .Fn sethostent | ||
202 | and | ||
203 | .Fn endhostent | ||
204 | are redefined, | ||
205 | when | ||
206 | .Xr libc 3 | ||
207 | is built to use only the routines to lookup in | ||
208 | .Pa /etc/hosts | ||
209 | and not the name server. | ||
210 | .Pp | ||
211 | The | ||
212 | .Fn gethostent | ||
213 | function | ||
214 | reads the next line of | 220 | reads the next line of |
215 | .Pa /etc/hosts , | 221 | .Pa /etc/hosts , |
216 | opening the file if necessary. | 222 | opening the file if necessary. |
@@ -224,7 +230,8 @@ If the | |||
224 | .Fa stayopen | 230 | .Fa stayopen |
225 | argument is non-zero, | 231 | argument is non-zero, |
226 | the file will not be closed after each call to | 232 | the file will not be closed after each call to |
227 | .Fn gethostbyname | 233 | .Fn gethostbyname , |
234 | .Fn gethostbyname2 , | ||
228 | or | 235 | or |
229 | .Fn gethostbyaddr . | 236 | .Fn gethostbyaddr . |
230 | .Pp | 237 | .Pp |
@@ -251,4 +258,9 @@ These functions use static data storage; | |||
251 | if the data is needed for future use, it should be | 258 | if the data is needed for future use, it should be |
252 | copied before any subsequent calls overwrite it. | 259 | copied before any subsequent calls overwrite it. |
253 | Only the Internet | 260 | Only the Internet |
254 | address format is currently understood. | 261 | address formats are currently understood. |
262 | .Pp | ||
263 | YP does not support any address families other than | ||
264 | .Dv AF_INET | ||
265 | and uses | ||
266 | the traditional database format. | ||
diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c index ec3f14a900..7321225863 100644 --- a/src/lib/libc/net/gethostnamadr.c +++ b/src/lib/libc/net/gethostnamadr.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: gethostnamadr.c,v 1.13 1995/05/21 16:21:14 mycroft Exp $ */ | ||
2 | |||
3 | /*- | 1 | /*- |
4 | * Copyright (c) 1985, 1988, 1993 | 2 | * Copyright (c) 1985, 1988, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -54,12 +52,7 @@ | |||
54 | */ | 52 | */ |
55 | 53 | ||
56 | #if defined(LIBC_SCCS) && !defined(lint) | 54 | #if defined(LIBC_SCCS) && !defined(lint) |
57 | #if 0 | 55 | static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.30 1998/03/16 05:06:55 millert Exp $"; |
58 | static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; | ||
59 | static char rcsid[] = "$Id: gethnamaddr.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel "; | ||
60 | #else | ||
61 | static char rcsid[] = "$NetBSD: gethostnamadr.c,v 1.13 1995/05/21 16:21:14 mycroft Exp $"; | ||
62 | #endif | ||
63 | #endif /* LIBC_SCCS and not lint */ | 56 | #endif /* LIBC_SCCS and not lint */ |
64 | 57 | ||
65 | #include <sys/param.h> | 58 | #include <sys/param.h> |
@@ -73,12 +66,16 @@ static char rcsid[] = "$NetBSD: gethostnamadr.c,v 1.13 1995/05/21 16:21:14 mycro | |||
73 | #include <ctype.h> | 66 | #include <ctype.h> |
74 | #include <errno.h> | 67 | #include <errno.h> |
75 | #include <string.h> | 68 | #include <string.h> |
69 | #include <syslog.h> | ||
76 | #ifdef YP | 70 | #ifdef YP |
77 | #include <rpc/rpc.h> | 71 | #include <rpc/rpc.h> |
78 | #include <rpcsvc/yp_prot.h> | 72 | #include <rpcsvc/yp.h> |
79 | #include <rpcsvc/ypclnt.h> | 73 | #include <rpcsvc/ypclnt.h> |
74 | #include "ypinternal.h" | ||
80 | #endif | 75 | #endif |
81 | 76 | ||
77 | #define MULTI_PTRS_ARE_ALIASES 1 /* XXX - experimental */ | ||
78 | |||
82 | #define MAXALIASES 35 | 79 | #define MAXALIASES 35 |
83 | #define MAXADDRS 35 | 80 | #define MAXADDRS 35 |
84 | 81 | ||
@@ -91,10 +88,26 @@ static char *__ypdomain; | |||
91 | static struct hostent host; | 88 | static struct hostent host; |
92 | static char *host_aliases[MAXALIASES]; | 89 | static char *host_aliases[MAXALIASES]; |
93 | static char hostbuf[BUFSIZ+1]; | 90 | static char hostbuf[BUFSIZ+1]; |
94 | static struct in_addr host_addr; | 91 | static union { |
92 | struct in_addr _host_in_addr; | ||
93 | u_char _host_addr[16]; /* IPv4 or IPv6 */ | ||
94 | } _host_addr_u; | ||
95 | #define host_addr _host_addr_u._host_addr | ||
95 | static FILE *hostf = NULL; | 96 | static FILE *hostf = NULL; |
96 | static int stayopen = 0; | 97 | static int stayopen = 0; |
97 | 98 | ||
99 | static void map_v4v6_address __P((const char *src, char *dst)); | ||
100 | static void map_v4v6_hostent __P((struct hostent *hp, char **bp, int *len)); | ||
101 | |||
102 | #ifdef RESOLVSORT | ||
103 | static void addrsort __P((char **, int)); | ||
104 | #endif | ||
105 | |||
106 | int _hokchar __P((const char *)); | ||
107 | |||
108 | static const char AskedForGot[] = | ||
109 | "gethostby*.getanswer: asked for \"%s\", got \"%s\""; | ||
110 | |||
98 | #if PACKETSZ > 1024 | 111 | #if PACKETSZ > 1024 |
99 | #define MAXPACKET PACKETSZ | 112 | #define MAXPACKET PACKETSZ |
100 | #else | 113 | #else |
@@ -107,31 +120,81 @@ typedef union { | |||
107 | } querybuf; | 120 | } querybuf; |
108 | 121 | ||
109 | typedef union { | 122 | typedef union { |
110 | int32_t al; | 123 | int32_t al; |
111 | char ac; | 124 | char ac; |
112 | } align; | 125 | } align; |
113 | 126 | ||
114 | static int qcomp __P((struct in_addr **, struct in_addr **)); | 127 | static struct hostent *getanswer __P((const querybuf *, int, const char *, |
115 | static struct hostent *getanswer __P((querybuf *, int, int)); | 128 | int)); |
116 | 129 | ||
117 | extern int h_errno; | 130 | extern int h_errno; |
118 | 131 | ||
132 | int | ||
133 | _hokchar(p) | ||
134 | const char *p; | ||
135 | { | ||
136 | char c; | ||
137 | |||
138 | /* | ||
139 | * Many people do not obey RFC 822 and 1035. The valid | ||
140 | * characters are a-z, A-Z, 0-9, '-' and . But the others | ||
141 | * tested for below can happen, and we must be more permissive | ||
142 | * than the resolver until those idiots clean up their act. | ||
143 | * We let '/' through, but not '..' | ||
144 | */ | ||
145 | while ((c = *p++)) { | ||
146 | if (('a' <= c && c <= 'z') || | ||
147 | ('A' <= c && c <= 'Z') || | ||
148 | ('0' <= c && c <= '9')) | ||
149 | continue; | ||
150 | if (strchr("-_/", c)) | ||
151 | continue; | ||
152 | if (c == '.' && *p != '.') | ||
153 | continue; | ||
154 | return 0; | ||
155 | } | ||
156 | return 1; | ||
157 | } | ||
158 | |||
119 | static struct hostent * | 159 | static struct hostent * |
120 | getanswer(answer, anslen, iquery) | 160 | getanswer(answer, anslen, qname, qtype) |
121 | querybuf *answer; | 161 | const querybuf *answer; |
122 | int anslen; | 162 | int anslen; |
123 | int iquery; | 163 | const char *qname; |
164 | int qtype; | ||
124 | { | 165 | { |
125 | register HEADER *hp; | 166 | register const HEADER *hp; |
126 | register u_char *cp; | 167 | register const u_char *cp; |
127 | register int n; | 168 | register int n; |
128 | u_char *eom; | 169 | const u_char *eom; |
129 | char *bp, **ap; | 170 | char *bp, **ap, **hap; |
130 | int type, class, buflen, ancount, qdcount; | 171 | int type, class, buflen, ancount, qdcount; |
131 | int haveanswer, getclass = C_ANY; | 172 | int haveanswer, had_error; |
132 | char **hap; | 173 | int toobig = 0; |
174 | char tbuf[MAXDNAME]; | ||
175 | const char *tname; | ||
176 | int (*name_ok) __P((const char *)); | ||
133 | 177 | ||
178 | tname = qname; | ||
179 | host.h_name = NULL; | ||
134 | eom = answer->buf + anslen; | 180 | eom = answer->buf + anslen; |
181 | switch (qtype) { | ||
182 | case T_A: | ||
183 | case T_AAAA: | ||
184 | #ifdef USE_RESOLV_NAME_OK | ||
185 | name_ok = res_hnok; | ||
186 | break; | ||
187 | #endif | ||
188 | case T_PTR: | ||
189 | #ifdef USE_RESOLV_NAME_OK | ||
190 | name_ok = res_dnok; | ||
191 | #else | ||
192 | name_ok = _hokchar; | ||
193 | #endif | ||
194 | break; | ||
195 | default: | ||
196 | return (NULL); | ||
197 | } | ||
135 | /* | 198 | /* |
136 | * find first satisfactory answer | 199 | * find first satisfactory answer |
137 | */ | 200 | */ |
@@ -139,31 +202,29 @@ getanswer(answer, anslen, iquery) | |||
139 | ancount = ntohs(hp->ancount); | 202 | ancount = ntohs(hp->ancount); |
140 | qdcount = ntohs(hp->qdcount); | 203 | qdcount = ntohs(hp->qdcount); |
141 | bp = hostbuf; | 204 | bp = hostbuf; |
142 | buflen = sizeof(hostbuf); | 205 | buflen = sizeof hostbuf; |
143 | cp = answer->buf + sizeof(HEADER); | 206 | cp = answer->buf + HFIXEDSZ; |
144 | if (qdcount) { | 207 | if (qdcount != 1) { |
145 | if (iquery) { | 208 | h_errno = NO_RECOVERY; |
146 | if ((n = dn_expand((u_char *)answer->buf, | 209 | return (NULL); |
147 | (u_char *)eom, (u_char *)cp, (u_char *)bp, | 210 | } |
148 | buflen)) < 0) { | 211 | n = dn_expand(answer->buf, eom, cp, bp, buflen); |
149 | h_errno = NO_RECOVERY; | 212 | if ((n < 0) || !(*name_ok)(bp)) { |
150 | return ((struct hostent *) NULL); | 213 | h_errno = NO_RECOVERY; |
151 | } | 214 | return (NULL); |
152 | cp += n + QFIXEDSZ; | 215 | } |
153 | host.h_name = bp; | 216 | cp += n + QFIXEDSZ; |
154 | n = strlen(bp) + 1; | 217 | if (qtype == T_A || qtype == T_AAAA) { |
155 | bp += n; | 218 | /* res_send() has already verified that the query name is the |
156 | buflen -= n; | 219 | * same as the one we sent; this just gets the expanded name |
157 | } else | 220 | * (i.e., with the succeeding search-domain tacked on). |
158 | cp += __dn_skipname(cp, eom) + QFIXEDSZ; | 221 | */ |
159 | while (--qdcount > 0) | 222 | n = strlen(bp) + 1; /* for the \0 */ |
160 | cp += __dn_skipname(cp, eom) + QFIXEDSZ; | 223 | host.h_name = bp; |
161 | } else if (iquery) { | 224 | bp += n; |
162 | if (hp->aa) | 225 | buflen -= n; |
163 | h_errno = HOST_NOT_FOUND; | 226 | /* The qname can be abbreviated, but h_name is now absolute. */ |
164 | else | 227 | qname = host.h_name; |
165 | h_errno = TRY_AGAIN; | ||
166 | return ((struct hostent *) NULL); | ||
167 | } | 228 | } |
168 | ap = host_aliases; | 229 | ap = host_aliases; |
169 | *ap = NULL; | 230 | *ap = NULL; |
@@ -172,104 +233,256 @@ getanswer(answer, anslen, iquery) | |||
172 | *hap = NULL; | 233 | *hap = NULL; |
173 | host.h_addr_list = h_addr_ptrs; | 234 | host.h_addr_list = h_addr_ptrs; |
174 | haveanswer = 0; | 235 | haveanswer = 0; |
175 | while (--ancount >= 0 && cp < eom) { | 236 | had_error = 0; |
176 | if ((n = dn_expand((u_char *)answer->buf, (u_char *)eom, | 237 | while (ancount-- > 0 && cp < eom && !had_error) { |
177 | (u_char *)cp, (u_char *)bp, buflen)) < 0) | 238 | n = dn_expand(answer->buf, eom, cp, bp, buflen); |
178 | break; | 239 | if ((n < 0) || !(*name_ok)(bp)) { |
179 | cp += n; | 240 | had_error++; |
241 | continue; | ||
242 | } | ||
243 | cp += n; /* name */ | ||
180 | type = _getshort(cp); | 244 | type = _getshort(cp); |
181 | cp += sizeof(u_int16_t); | 245 | cp += INT16SZ; /* type */ |
182 | class = _getshort(cp); | 246 | class = _getshort(cp); |
183 | cp += sizeof(u_int16_t) + sizeof(u_int32_t); | 247 | cp += INT16SZ + INT32SZ; /* class, TTL */ |
184 | n = _getshort(cp); | 248 | n = _getshort(cp); |
185 | cp += sizeof(u_int16_t); | 249 | cp += INT16SZ; /* len */ |
186 | if (type == T_CNAME) { | 250 | if (class != C_IN) { |
251 | /* XXX - debug? syslog? */ | ||
187 | cp += n; | 252 | cp += n; |
253 | continue; /* XXX - had_error++ ? */ | ||
254 | } | ||
255 | if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { | ||
188 | if (ap >= &host_aliases[MAXALIASES-1]) | 256 | if (ap >= &host_aliases[MAXALIASES-1]) |
189 | continue; | 257 | continue; |
258 | n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); | ||
259 | if ((n < 0) || !(*name_ok)(tbuf)) { | ||
260 | had_error++; | ||
261 | continue; | ||
262 | } | ||
263 | cp += n; | ||
264 | /* Store alias. */ | ||
190 | *ap++ = bp; | 265 | *ap++ = bp; |
191 | n = strlen(bp) + 1; | 266 | n = strlen(bp) + 1; /* for the \0 */ |
267 | bp += n; | ||
268 | buflen -= n; | ||
269 | /* Get canonical name. */ | ||
270 | n = strlen(tbuf) + 1; /* for the \0 */ | ||
271 | if (n > buflen) { | ||
272 | had_error++; | ||
273 | continue; | ||
274 | } | ||
275 | strcpy(bp, tbuf); | ||
276 | host.h_name = bp; | ||
192 | bp += n; | 277 | bp += n; |
193 | buflen -= n; | 278 | buflen -= n; |
194 | continue; | 279 | continue; |
195 | } | 280 | } |
196 | if (iquery && type == T_PTR) { | 281 | if (qtype == T_PTR && type == T_CNAME) { |
197 | if ((n = dn_expand((u_char *)answer->buf, | 282 | n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); |
198 | (u_char *)eom, (u_char *)cp, (u_char *)bp, | 283 | if ((n < 0) || !res_hnok(tbuf)) { |
199 | buflen)) < 0) | 284 | had_error++; |
200 | break; | 285 | continue; |
286 | } | ||
201 | cp += n; | 287 | cp += n; |
202 | host.h_name = bp; | 288 | /* Get canonical name. */ |
203 | return(&host); | 289 | n = strlen(tbuf) + 1; /* for the \0 */ |
290 | if (n > buflen) { | ||
291 | had_error++; | ||
292 | continue; | ||
293 | } | ||
294 | strcpy(bp, tbuf); | ||
295 | tname = bp; | ||
296 | bp += n; | ||
297 | buflen -= n; | ||
298 | continue; | ||
204 | } | 299 | } |
205 | if (iquery || type != T_A) { | 300 | if (type != qtype) { |
206 | #ifdef DEBUG | 301 | syslog(LOG_NOTICE|LOG_AUTH, |
207 | if (_res.options & RES_DEBUG) | 302 | "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"", |
208 | printf("unexpected answer type %d, size %d\n", | 303 | qname, p_class(C_IN), p_type(qtype), |
209 | type, n); | 304 | p_type(type)); |
210 | #endif | ||
211 | cp += n; | 305 | cp += n; |
212 | continue; | 306 | continue; /* XXX - had_error++ ? */ |
213 | } | 307 | } |
214 | if (haveanswer) { | 308 | switch (type) { |
215 | if (n != host.h_length) { | 309 | case T_PTR: |
310 | if (strcasecmp(tname, bp) != 0) { | ||
311 | syslog(LOG_NOTICE|LOG_AUTH, | ||
312 | AskedForGot, qname, bp); | ||
216 | cp += n; | 313 | cp += n; |
217 | continue; | 314 | continue; /* XXX - had_error++ ? */ |
315 | } | ||
316 | n = dn_expand(answer->buf, eom, cp, bp, buflen); | ||
317 | if ((n < 0) || !res_hnok(bp)) { | ||
318 | had_error++; | ||
319 | break; | ||
320 | } | ||
321 | #if MULTI_PTRS_ARE_ALIASES | ||
322 | cp += n; | ||
323 | if (!haveanswer) | ||
324 | host.h_name = bp; | ||
325 | else if (ap < &host_aliases[MAXALIASES-1]) | ||
326 | *ap++ = bp; | ||
327 | else | ||
328 | n = -1; | ||
329 | if (n != -1) { | ||
330 | n = strlen(bp) + 1; /* for the \0 */ | ||
331 | bp += n; | ||
332 | buflen -= n; | ||
218 | } | 333 | } |
219 | if (class != getclass) { | 334 | break; |
335 | #else | ||
336 | host.h_name = bp; | ||
337 | if (_res.options & RES_USE_INET6) { | ||
338 | n = strlen(bp) + 1; /* for the \0 */ | ||
339 | bp += n; | ||
340 | buflen -= n; | ||
341 | map_v4v6_hostent(&host, &bp, &buflen); | ||
342 | } | ||
343 | h_errno = NETDB_SUCCESS; | ||
344 | return (&host); | ||
345 | #endif | ||
346 | case T_A: | ||
347 | case T_AAAA: | ||
348 | if (strcasecmp(host.h_name, bp) != 0) { | ||
349 | syslog(LOG_NOTICE|LOG_AUTH, | ||
350 | AskedForGot, host.h_name, bp); | ||
351 | cp += n; | ||
352 | continue; /* XXX - had_error++ ? */ | ||
353 | } | ||
354 | if (n != host.h_length) { | ||
220 | cp += n; | 355 | cp += n; |
221 | continue; | 356 | continue; |
222 | } | 357 | } |
223 | } else { | 358 | if (!haveanswer) { |
224 | host.h_length = n; | 359 | register int nn; |
225 | getclass = class; | 360 | |
226 | host.h_addrtype = (class == C_IN) ? AF_INET : AF_UNSPEC; | ||
227 | if (!iquery) { | ||
228 | host.h_name = bp; | 361 | host.h_name = bp; |
229 | bp += strlen(bp) + 1; | 362 | nn = strlen(bp) + 1; /* for the \0 */ |
363 | bp += nn; | ||
364 | buflen -= nn; | ||
230 | } | 365 | } |
231 | } | ||
232 | 366 | ||
233 | bp += sizeof(align) - ((u_long)bp % sizeof(align)); | 367 | bp += sizeof(align) - ((u_long)bp % sizeof(align)); |
234 | 368 | ||
235 | if (bp + n >= &hostbuf[sizeof(hostbuf)]) { | 369 | if (bp + n >= &hostbuf[sizeof hostbuf]) { |
370 | #ifdef DEBUG | ||
371 | if (_res.options & RES_DEBUG) | ||
372 | printf("size (%d) too big\n", n); | ||
373 | #endif | ||
374 | had_error++; | ||
375 | continue; | ||
376 | } | ||
377 | if (hap >= &h_addr_ptrs[MAXADDRS-1]) { | ||
378 | if (!toobig++) | ||
236 | #ifdef DEBUG | 379 | #ifdef DEBUG |
237 | if (_res.options & RES_DEBUG) | 380 | if (_res.options & RES_DEBUG) |
238 | printf("size (%d) too big\n", n); | 381 | printf("Too many addresses (%d)\n", MAXADDRS); |
239 | #endif | 382 | #endif |
383 | cp += n; | ||
384 | continue; | ||
385 | } | ||
386 | bcopy(cp, *hap++ = bp, n); | ||
387 | bp += n; | ||
388 | buflen -= n; | ||
389 | cp += n; | ||
240 | break; | 390 | break; |
241 | } | 391 | } |
242 | bcopy(cp, *hap++ = bp, n); | 392 | if (!had_error) |
243 | bp +=n; | 393 | haveanswer++; |
244 | cp += n; | ||
245 | haveanswer++; | ||
246 | } | 394 | } |
247 | if (haveanswer) { | 395 | if (haveanswer) { |
248 | *ap = NULL; | 396 | *ap = NULL; |
249 | *hap = NULL; | 397 | *hap = NULL; |
250 | if (_res.nsort) { | 398 | # if defined(RESOLVSORT) |
251 | qsort(host.h_addr_list, haveanswer, | 399 | /* |
252 | sizeof(struct in_addr), | 400 | * Note: we sort even if host can take only one address |
253 | (int (*)__P((const void *, const void *)))qcomp); | 401 | * in its return structures - should give it the "best" |
402 | * address in that case, not some random one | ||
403 | */ | ||
404 | if (_res.nsort && haveanswer > 1 && qtype == T_A) | ||
405 | addrsort(h_addr_ptrs, haveanswer); | ||
406 | # endif /*RESOLVSORT*/ | ||
407 | if (!host.h_name) { | ||
408 | n = strlen(qname) + 1; /* for the \0 */ | ||
409 | if (n > buflen) | ||
410 | goto try_again; | ||
411 | strcpy(bp, qname); | ||
412 | host.h_name = bp; | ||
413 | bp += n; | ||
414 | buflen -= n; | ||
254 | } | 415 | } |
416 | if (_res.options & RES_USE_INET6) | ||
417 | map_v4v6_hostent(&host, &bp, &buflen); | ||
418 | h_errno = NETDB_SUCCESS; | ||
255 | return (&host); | 419 | return (&host); |
256 | } else { | ||
257 | h_errno = TRY_AGAIN; | ||
258 | return ((struct hostent *) NULL); | ||
259 | } | 420 | } |
421 | try_again: | ||
422 | h_errno = TRY_AGAIN; | ||
423 | return (NULL); | ||
260 | } | 424 | } |
261 | 425 | ||
262 | struct hostent * | 426 | struct hostent * |
263 | gethostbyname(name) | 427 | gethostbyname(name) |
264 | const char *name; | 428 | const char *name; |
265 | { | 429 | { |
430 | struct hostent *hp; | ||
431 | extern struct hostent *_gethtbyname2(); | ||
432 | |||
433 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | ||
434 | return (_gethtbyname2(name, AF_INET)); | ||
435 | |||
436 | if (_res.options & RES_USE_INET6) { | ||
437 | hp = gethostbyname2(name, AF_INET6); | ||
438 | if (hp) | ||
439 | return (hp); | ||
440 | } | ||
441 | return (gethostbyname2(name, AF_INET)); | ||
442 | } | ||
443 | |||
444 | struct hostent * | ||
445 | gethostbyname2(name, af) | ||
446 | const char *name; | ||
447 | int af; | ||
448 | { | ||
266 | querybuf buf; | 449 | querybuf buf; |
267 | register const char *cp; | 450 | register const char *cp; |
268 | int n, i; | 451 | char *bp; |
269 | extern struct hostent *_gethtbyname(), *_yp_gethtbyname(); | 452 | int n, size, type, len, i; |
453 | extern struct hostent *_gethtbyname2(), *_yp_gethtbyname(); | ||
270 | register struct hostent *hp; | 454 | register struct hostent *hp; |
271 | char lookups[MAXDNSLUS]; | 455 | char lookups[MAXDNSLUS]; |
272 | 456 | ||
457 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | ||
458 | return (_gethtbyname2(name, af)); | ||
459 | |||
460 | switch (af) { | ||
461 | case AF_INET: | ||
462 | size = INADDRSZ; | ||
463 | type = T_A; | ||
464 | break; | ||
465 | case AF_INET6: | ||
466 | size = IN6ADDRSZ; | ||
467 | type = T_AAAA; | ||
468 | break; | ||
469 | default: | ||
470 | h_errno = NETDB_INTERNAL; | ||
471 | errno = EAFNOSUPPORT; | ||
472 | return (NULL); | ||
473 | } | ||
474 | |||
475 | host.h_addrtype = af; | ||
476 | host.h_length = size; | ||
477 | |||
478 | /* | ||
479 | * if there aren't any dots, it could be a user-level alias. | ||
480 | * this is also done in res_query() since we are not the only | ||
481 | * function that looks up host names. | ||
482 | */ | ||
483 | if (!strchr(name, '.') && (cp = __hostalias(name))) | ||
484 | name = cp; | ||
485 | |||
273 | /* | 486 | /* |
274 | * disallow names consisting only of digits/dots, unless | 487 | * disallow names consisting only of digits/dots, unless |
275 | * they end in a dot. | 488 | * they end in a dot. |
@@ -284,26 +497,59 @@ gethostbyname(name) | |||
284 | * Fake up a hostent as if we'd actually | 497 | * Fake up a hostent as if we'd actually |
285 | * done a lookup. | 498 | * done a lookup. |
286 | */ | 499 | */ |
287 | if (!inet_aton(name, &host_addr)) { | 500 | if (inet_pton(af, name, host_addr) <= 0) { |
288 | h_errno = HOST_NOT_FOUND; | 501 | h_errno = HOST_NOT_FOUND; |
289 | return((struct hostent *) NULL); | 502 | return (NULL); |
290 | } | 503 | } |
291 | host.h_name = (char *)name; | 504 | strncpy(hostbuf, name, MAXHOSTNAMELEN-1); |
505 | hostbuf[MAXHOSTNAMELEN-1] = '\0'; | ||
506 | bp = hostbuf + MAXHOSTNAMELEN; | ||
507 | len = sizeof hostbuf - MAXHOSTNAMELEN; | ||
508 | host.h_name = hostbuf; | ||
292 | host.h_aliases = host_aliases; | 509 | host.h_aliases = host_aliases; |
293 | host_aliases[0] = NULL; | 510 | host_aliases[0] = NULL; |
294 | host.h_addrtype = AF_INET; | 511 | h_addr_ptrs[0] = (char *)host_addr; |
295 | host.h_length = sizeof(u_int32_t); | ||
296 | h_addr_ptrs[0] = (char *)&host_addr; | ||
297 | h_addr_ptrs[1] = NULL; | 512 | h_addr_ptrs[1] = NULL; |
298 | host.h_addr_list = h_addr_ptrs; | 513 | host.h_addr_list = h_addr_ptrs; |
514 | if (_res.options & RES_USE_INET6) | ||
515 | map_v4v6_hostent(&host, &bp, &len); | ||
516 | h_errno = NETDB_SUCCESS; | ||
299 | return (&host); | 517 | return (&host); |
300 | } | 518 | } |
301 | if (!isdigit(*cp) && *cp != '.') | 519 | if (!isdigit(*cp) && *cp != '.') |
302 | break; | 520 | break; |
303 | } | 521 | } |
304 | 522 | if ((isxdigit(name[0]) && strchr(name, ':') != NULL) || | |
305 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 523 | name[0] == ':') |
306 | return (_gethtbyname(name)); | 524 | for (cp = name;; ++cp) { |
525 | if (!*cp) { | ||
526 | if (*--cp == '.') | ||
527 | break; | ||
528 | /* | ||
529 | * All-IPv6-legal, no dot at the end. | ||
530 | * Fake up a hostent as if we'd actually | ||
531 | * done a lookup. | ||
532 | */ | ||
533 | if (inet_pton(af, name, host_addr) <= 0) { | ||
534 | h_errno = HOST_NOT_FOUND; | ||
535 | return (NULL); | ||
536 | } | ||
537 | strncpy(hostbuf, name, MAXHOSTNAMELEN-1); | ||
538 | hostbuf[MAXHOSTNAMELEN-1] = '\0'; | ||
539 | bp = hostbuf + MAXHOSTNAMELEN; | ||
540 | len = sizeof hostbuf - MAXHOSTNAMELEN; | ||
541 | host.h_name = hostbuf; | ||
542 | host.h_aliases = host_aliases; | ||
543 | host_aliases[0] = NULL; | ||
544 | h_addr_ptrs[0] = (char *)host_addr; | ||
545 | h_addr_ptrs[1] = NULL; | ||
546 | host.h_addr_list = h_addr_ptrs; | ||
547 | h_errno = NETDB_SUCCESS; | ||
548 | return (&host); | ||
549 | } | ||
550 | if (!isxdigit(*cp) && *cp != ':' && *cp != '.') | ||
551 | break; | ||
552 | } | ||
307 | 553 | ||
308 | bcopy(_res.lookups, lookups, sizeof lookups); | 554 | bcopy(_res.lookups, lookups, sizeof lookups); |
309 | if (lookups[0] == '\0') | 555 | if (lookups[0] == '\0') |
@@ -314,11 +560,13 @@ gethostbyname(name) | |||
314 | switch (lookups[i]) { | 560 | switch (lookups[i]) { |
315 | #ifdef YP | 561 | #ifdef YP |
316 | case 'y': | 562 | case 'y': |
317 | hp = _yp_gethtbyname(name); | 563 | /* YP only supports AF_INET. */ |
564 | if (af == AF_INET) | ||
565 | hp = _yp_gethtbyname(name); | ||
318 | break; | 566 | break; |
319 | #endif | 567 | #endif |
320 | case 'b': | 568 | case 'b': |
321 | if ((n = res_search(name, C_IN, T_A, buf.buf, | 569 | if ((n = res_search(name, C_IN, type, buf.buf, |
322 | sizeof(buf))) < 0) { | 570 | sizeof(buf))) < 0) { |
323 | #ifdef DEBUG | 571 | #ifdef DEBUG |
324 | if (_res.options & RES_DEBUG) | 572 | if (_res.options & RES_DEBUG) |
@@ -326,38 +574,79 @@ gethostbyname(name) | |||
326 | #endif | 574 | #endif |
327 | break; | 575 | break; |
328 | } | 576 | } |
329 | hp = getanswer(&buf, n, 0); | 577 | hp = getanswer(&buf, n, name, type); |
330 | break; | 578 | break; |
331 | case 'f': | 579 | case 'f': |
332 | hp = _gethtbyname(name); | 580 | hp = _gethtbyname2(name, af); |
333 | break; | 581 | break; |
334 | } | 582 | } |
335 | } | 583 | } |
584 | /* XXX h_errno not correct in all cases... */ | ||
336 | return (hp); | 585 | return (hp); |
337 | } | 586 | } |
338 | 587 | ||
339 | struct hostent * | 588 | struct hostent * |
340 | gethostbyaddr(addr, len, type) | 589 | gethostbyaddr(addr, len, af) |
341 | const char *addr; | 590 | const char *addr; /* XXX should have been def'd as u_char! */ |
342 | int len, type; | 591 | int len, af; |
343 | { | 592 | { |
344 | int n, i; | 593 | const u_char *uaddr = (const u_char *)addr; |
594 | static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff }; | ||
595 | static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 }; | ||
596 | int n, size, i; | ||
345 | querybuf buf; | 597 | querybuf buf; |
346 | register struct hostent *hp; | 598 | register struct hostent *hp; |
347 | char qbuf[MAXDNAME]; | 599 | char qbuf[MAXDNAME+1], *qp; |
348 | extern struct hostent *_gethtbyaddr(), *_yp_gethtbyaddr(); | 600 | extern struct hostent *_gethtbyaddr(), *_yp_gethtbyaddr(); |
349 | char lookups[MAXDNSLUS]; | 601 | char lookups[MAXDNSLUS]; |
350 | 602 | ||
351 | if (type != AF_INET) | ||
352 | return ((struct hostent *) NULL); | ||
353 | (void)sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", | ||
354 | ((unsigned)addr[3] & 0xff), | ||
355 | ((unsigned)addr[2] & 0xff), | ||
356 | ((unsigned)addr[1] & 0xff), | ||
357 | ((unsigned)addr[0] & 0xff)); | ||
358 | |||
359 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 603 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) |
360 | return (_gethtbyaddr(addr, len, type)); | 604 | return (_gethtbyaddr(addr, len, af)); |
605 | |||
606 | if (af == AF_INET6 && len == IN6ADDRSZ && | ||
607 | (!bcmp(uaddr, mapped, sizeof mapped) || | ||
608 | !bcmp(uaddr, tunnelled, sizeof tunnelled))) { | ||
609 | /* Unmap. */ | ||
610 | addr += sizeof mapped; | ||
611 | uaddr += sizeof mapped; | ||
612 | af = AF_INET; | ||
613 | len = INADDRSZ; | ||
614 | } | ||
615 | switch (af) { | ||
616 | case AF_INET: | ||
617 | size = INADDRSZ; | ||
618 | break; | ||
619 | case AF_INET6: | ||
620 | size = IN6ADDRSZ; | ||
621 | break; | ||
622 | default: | ||
623 | errno = EAFNOSUPPORT; | ||
624 | h_errno = NETDB_INTERNAL; | ||
625 | return (NULL); | ||
626 | } | ||
627 | if (size != len) { | ||
628 | errno = EINVAL; | ||
629 | h_errno = NETDB_INTERNAL; | ||
630 | return (NULL); | ||
631 | } | ||
632 | switch (af) { | ||
633 | case AF_INET: | ||
634 | (void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", | ||
635 | (uaddr[3] & 0xff), | ||
636 | (uaddr[2] & 0xff), | ||
637 | (uaddr[1] & 0xff), | ||
638 | (uaddr[0] & 0xff)); | ||
639 | break; | ||
640 | case AF_INET6: | ||
641 | qp = qbuf; | ||
642 | for (n = IN6ADDRSZ - 1; n >= 0; n--) { | ||
643 | qp += sprintf(qp, "%x.%x.", | ||
644 | uaddr[n] & 0xf, | ||
645 | (uaddr[n] >> 4) & 0xf); | ||
646 | } | ||
647 | strcpy(qp, "ip6.int"); | ||
648 | break; | ||
649 | } | ||
361 | 650 | ||
362 | bcopy(_res.lookups, lookups, sizeof lookups); | 651 | bcopy(_res.lookups, lookups, sizeof lookups); |
363 | if (lookups[0] == '\0') | 652 | if (lookups[0] == '\0') |
@@ -368,11 +657,14 @@ gethostbyaddr(addr, len, type) | |||
368 | switch (lookups[i]) { | 657 | switch (lookups[i]) { |
369 | #ifdef YP | 658 | #ifdef YP |
370 | case 'y': | 659 | case 'y': |
371 | hp = _yp_gethtbyaddr(addr, len, type); | 660 | /* YP only supports AF_INET. */ |
661 | if (af == AF_INET) | ||
662 | hp = _yp_gethtbyaddr(addr); | ||
372 | break; | 663 | break; |
373 | #endif | 664 | #endif |
374 | case 'b': | 665 | case 'b': |
375 | n = res_query(qbuf, C_IN, T_PTR, (char *)&buf, sizeof(buf)); | 666 | n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, |
667 | sizeof buf.buf); | ||
376 | if (n < 0) { | 668 | if (n < 0) { |
377 | #ifdef DEBUG | 669 | #ifdef DEBUG |
378 | if (_res.options & RES_DEBUG) | 670 | if (_res.options & RES_DEBUG) |
@@ -380,20 +672,27 @@ gethostbyaddr(addr, len, type) | |||
380 | #endif | 672 | #endif |
381 | break; | 673 | break; |
382 | } | 674 | } |
383 | hp = getanswer(&buf, n, 1); | 675 | if (!(hp = getanswer(&buf, n, qbuf, T_PTR))) |
384 | if (hp == NULL) | ||
385 | break; | 676 | break; |
386 | hp->h_addrtype = type; | 677 | hp->h_addrtype = af; |
387 | hp->h_length = len; | 678 | hp->h_length = len; |
388 | h_addr_ptrs[0] = (char *)&host_addr; | 679 | bcopy(addr, host_addr, len); |
389 | h_addr_ptrs[1] = (char *)0; | 680 | h_addr_ptrs[0] = (char *)host_addr; |
390 | host_addr = *(struct in_addr *)addr; | 681 | h_addr_ptrs[1] = NULL; |
682 | if (af == AF_INET && (_res.options & RES_USE_INET6)) { | ||
683 | map_v4v6_address((char*)host_addr, | ||
684 | (char*)host_addr); | ||
685 | hp->h_addrtype = AF_INET6; | ||
686 | hp->h_length = IN6ADDRSZ; | ||
687 | } | ||
688 | h_errno = NETDB_SUCCESS; | ||
391 | break; | 689 | break; |
392 | case 'f': | 690 | case 'f': |
393 | hp = _gethtbyaddr(addr, len, type); | 691 | hp = _gethtbyaddr(addr, len, af); |
394 | break; | 692 | break; |
395 | } | 693 | } |
396 | } | 694 | } |
695 | /* XXX h_errno not correct in all cases... */ | ||
397 | return (hp); | 696 | return (hp); |
398 | } | 697 | } |
399 | 698 | ||
@@ -422,35 +721,57 @@ _gethtent() | |||
422 | { | 721 | { |
423 | char *p; | 722 | char *p; |
424 | register char *cp, **q; | 723 | register char *cp, **q; |
724 | int af; | ||
725 | size_t len; | ||
425 | 726 | ||
426 | if (hostf == NULL && (hostf = fopen(_PATH_HOSTS, "r" )) == NULL) | 727 | if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) { |
728 | h_errno = NETDB_INTERNAL; | ||
427 | return (NULL); | 729 | return (NULL); |
428 | again: | 730 | } |
429 | if ((p = fgets(hostbuf, BUFSIZ, hostf)) == NULL) | 731 | again: |
732 | if ((p = fgetln(hostf, &len)) == NULL) { | ||
733 | h_errno = HOST_NOT_FOUND; | ||
430 | return (NULL); | 734 | return (NULL); |
431 | if (*p == '#') | 735 | } |
736 | if (p[len-1] == '\n') | ||
737 | len--; | ||
738 | if (len >= sizeof(hostbuf) || len == 0) | ||
432 | goto again; | 739 | goto again; |
433 | cp = strpbrk(p, "#\n"); | 740 | p = memcpy(hostbuf, p, len); |
434 | if (cp == NULL) | 741 | hostbuf[len] = '\0'; |
742 | if (*p == '#') | ||
435 | goto again; | 743 | goto again; |
436 | *cp = '\0'; | 744 | if ((cp = strchr(p, '#'))) |
437 | cp = strpbrk(p, " \t"); | 745 | *cp = '\0'; |
438 | if (cp == NULL) | 746 | if (!(cp = strpbrk(p, " \t"))) |
439 | goto again; | 747 | goto again; |
440 | *cp++ = '\0'; | 748 | *cp++ = '\0'; |
441 | /* THIS STUFF IS INTERNET SPECIFIC */ | 749 | if ((_res.options & RES_USE_INET6) && |
442 | h_addr_ptrs[0] = (char *)&host_addr; | 750 | inet_pton(AF_INET6, p, host_addr) > 0) { |
751 | af = AF_INET6; | ||
752 | len = IN6ADDRSZ; | ||
753 | } else if (inet_pton(AF_INET, p, host_addr) > 0) { | ||
754 | if (_res.options & RES_USE_INET6) { | ||
755 | map_v4v6_address((char*)host_addr, (char*)host_addr); | ||
756 | af = AF_INET6; | ||
757 | len = IN6ADDRSZ; | ||
758 | } else { | ||
759 | af = AF_INET; | ||
760 | len = INADDRSZ; | ||
761 | } | ||
762 | } else { | ||
763 | goto again; | ||
764 | } | ||
765 | h_addr_ptrs[0] = (char *)host_addr; | ||
443 | h_addr_ptrs[1] = NULL; | 766 | h_addr_ptrs[1] = NULL; |
444 | (void) inet_aton(p, &host_addr); | ||
445 | host.h_addr_list = h_addr_ptrs; | 767 | host.h_addr_list = h_addr_ptrs; |
446 | host.h_length = sizeof(u_int32_t); | 768 | host.h_length = len; |
447 | host.h_addrtype = AF_INET; | 769 | host.h_addrtype = af; |
448 | while (*cp == ' ' || *cp == '\t') | 770 | while (*cp == ' ' || *cp == '\t') |
449 | cp++; | 771 | cp++; |
450 | host.h_name = cp; | 772 | host.h_name = cp; |
451 | q = host.h_aliases = host_aliases; | 773 | q = host.h_aliases = host_aliases; |
452 | cp = strpbrk(cp, " \t"); | 774 | if ((cp = strpbrk(cp, " \t"))) |
453 | if (cp != NULL) | ||
454 | *cp++ = '\0'; | 775 | *cp++ = '\0'; |
455 | while (cp && *cp) { | 776 | while (cp && *cp) { |
456 | if (*cp == ' ' || *cp == '\t') { | 777 | if (*cp == ' ' || *cp == '\t') { |
@@ -459,70 +780,73 @@ again: | |||
459 | } | 780 | } |
460 | if (q < &host_aliases[MAXALIASES - 1]) | 781 | if (q < &host_aliases[MAXALIASES - 1]) |
461 | *q++ = cp; | 782 | *q++ = cp; |
462 | cp = strpbrk(cp, " \t"); | 783 | if ((cp = strpbrk(cp, " \t"))) |
463 | if (cp != NULL) | ||
464 | *cp++ = '\0'; | 784 | *cp++ = '\0'; |
465 | } | 785 | } |
466 | *q = NULL; | 786 | *q = NULL; |
787 | if (_res.options & RES_USE_INET6) { | ||
788 | char *bp = hostbuf; | ||
789 | int buflen = sizeof hostbuf; | ||
790 | |||
791 | map_v4v6_hostent(&host, &bp, &buflen); | ||
792 | } | ||
793 | h_errno = NETDB_SUCCESS; | ||
467 | return (&host); | 794 | return (&host); |
468 | } | 795 | } |
469 | 796 | ||
470 | struct hostent * | 797 | struct hostent * |
471 | _gethtbyname(name) | 798 | _gethtbyname(name) |
472 | char *name; | 799 | const char *name; |
800 | { | ||
801 | extern struct hostent *_gethtbyname2(); | ||
802 | struct hostent *hp; | ||
803 | |||
804 | if (_res.options & RES_USE_INET6) { | ||
805 | hp = _gethtbyname2(name, AF_INET6); | ||
806 | if (hp) | ||
807 | return (hp); | ||
808 | } | ||
809 | return (_gethtbyname2(name, AF_INET)); | ||
810 | } | ||
811 | |||
812 | struct hostent * | ||
813 | _gethtbyname2(name, af) | ||
814 | const char *name; | ||
815 | int af; | ||
473 | { | 816 | { |
474 | register struct hostent *p; | 817 | register struct hostent *p; |
475 | register char **cp; | 818 | register char **cp; |
476 | 819 | ||
477 | _sethtent(0); | 820 | _sethtent(0); |
478 | while (p = _gethtent()) { | 821 | while ((p = _gethtent())) { |
822 | if (p->h_addrtype != af) | ||
823 | continue; | ||
479 | if (strcasecmp(p->h_name, name) == 0) | 824 | if (strcasecmp(p->h_name, name) == 0) |
480 | break; | 825 | break; |
481 | for (cp = p->h_aliases; *cp != 0; cp++) | 826 | for (cp = p->h_aliases; *cp != 0; cp++) |
482 | if (strcasecmp(*cp, name) == 0) | 827 | if (strcasecmp(*cp, name) == 0) |
483 | goto found; | 828 | goto found; |
484 | } | 829 | } |
485 | found: | 830 | found: |
486 | _endhtent(); | 831 | _endhtent(); |
487 | if (p==NULL) | ||
488 | h_errno = HOST_NOT_FOUND; | ||
489 | return (p); | 832 | return (p); |
490 | } | 833 | } |
491 | 834 | ||
492 | struct hostent * | 835 | struct hostent * |
493 | _gethtbyaddr(addr, len, type) | 836 | _gethtbyaddr(addr, len, af) |
494 | const char *addr; | 837 | const char *addr; |
495 | int len, type; | 838 | int len, af; |
496 | { | 839 | { |
497 | register struct hostent *p; | 840 | register struct hostent *p; |
498 | 841 | ||
499 | _sethtent(0); | 842 | _sethtent(0); |
500 | while (p = _gethtent()) | 843 | while ((p = _gethtent())) |
501 | if (p->h_addrtype == type && !bcmp(p->h_addr, addr, len)) | 844 | if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len)) |
502 | break; | 845 | break; |
503 | _endhtent(); | 846 | _endhtent(); |
504 | if (p==NULL) | ||
505 | h_errno = HOST_NOT_FOUND; | ||
506 | return (p); | 847 | return (p); |
507 | } | 848 | } |
508 | 849 | ||
509 | static int | ||
510 | qcomp(a1, a2) | ||
511 | struct in_addr **a1, **a2; | ||
512 | { | ||
513 | int pos1, pos2; | ||
514 | |||
515 | for (pos1 = 0; pos1 < _res.nsort; pos1++) | ||
516 | if (_res.sort_list[pos1].addr.s_addr == | ||
517 | ((*a1)->s_addr & _res.sort_list[pos1].mask)) | ||
518 | break; | ||
519 | for (pos2 = 0; pos2 < _res.nsort; pos2++) | ||
520 | if (_res.sort_list[pos2].addr.s_addr == | ||
521 | ((*a2)->s_addr & _res.sort_list[pos2].mask)) | ||
522 | break; | ||
523 | return pos1 - pos2; | ||
524 | } | ||
525 | |||
526 | #ifdef YP | 850 | #ifdef YP |
527 | struct hostent * | 851 | struct hostent * |
528 | _yphostent(line) | 852 | _yphostent(line) |
@@ -537,7 +861,7 @@ _yphostent(line) | |||
537 | 861 | ||
538 | host.h_name = NULL; | 862 | host.h_name = NULL; |
539 | host.h_addr_list = h_addr_ptrs; | 863 | host.h_addr_list = h_addr_ptrs; |
540 | host.h_length = sizeof(u_int32_t); | 864 | host.h_length = INADDRSZ; |
541 | host.h_addrtype = AF_INET; | 865 | host.h_addrtype = AF_INET; |
542 | hap = h_addr_ptrs; | 866 | hap = h_addr_ptrs; |
543 | buf = host_addrs; | 867 | buf = host_addrs; |
@@ -598,9 +922,8 @@ done: | |||
598 | } | 922 | } |
599 | 923 | ||
600 | struct hostent * | 924 | struct hostent * |
601 | _yp_gethtbyaddr(addr, len, type) | 925 | _yp_gethtbyaddr(addr) |
602 | const char *addr; | 926 | const char *addr; |
603 | int len, type; | ||
604 | { | 927 | { |
605 | struct hostent *hp = (struct hostent *)NULL; | 928 | struct hostent *hp = (struct hostent *)NULL; |
606 | static char *__ypcurrent; | 929 | static char *__ypcurrent; |
@@ -636,6 +959,8 @@ _yp_gethtbyname(name) | |||
636 | static char *__ypcurrent; | 959 | static char *__ypcurrent; |
637 | int __ypcurrentlen, r; | 960 | int __ypcurrentlen, r; |
638 | 961 | ||
962 | if (strlen(name) >= MAXHOSTNAMELEN) | ||
963 | return (NULL); | ||
639 | if (!__ypdomain) { | 964 | if (!__ypdomain) { |
640 | if (_yp_check(&__ypdomain) == 0) | 965 | if (_yp_check(&__ypdomain) == 0) |
641 | return (hp); | 966 | return (hp); |
@@ -645,10 +970,110 @@ _yp_gethtbyname(name) | |||
645 | __ypcurrent = NULL; | 970 | __ypcurrent = NULL; |
646 | r = yp_match(__ypdomain, "hosts.byname", name, | 971 | r = yp_match(__ypdomain, "hosts.byname", name, |
647 | strlen(name), &__ypcurrent, &__ypcurrentlen); | 972 | strlen(name), &__ypcurrent, &__ypcurrentlen); |
648 | if (r==0) | 973 | if (r == 0) |
649 | hp = _yphostent(__ypcurrent); | 974 | hp = _yphostent(__ypcurrent); |
650 | if (hp==NULL) | 975 | if (hp == NULL) |
651 | h_errno = HOST_NOT_FOUND; | 976 | h_errno = HOST_NOT_FOUND; |
652 | return (hp); | 977 | return (hp); |
653 | } | 978 | } |
654 | #endif | 979 | #endif |
980 | |||
981 | static void | ||
982 | map_v4v6_address(src, dst) | ||
983 | const char *src; | ||
984 | char *dst; | ||
985 | { | ||
986 | u_char *p = (u_char *)dst; | ||
987 | char tmp[INADDRSZ]; | ||
988 | int i; | ||
989 | |||
990 | /* Stash a temporary copy so our caller can update in place. */ | ||
991 | bcopy(src, tmp, INADDRSZ); | ||
992 | /* Mark this ipv6 addr as a mapped ipv4. */ | ||
993 | for (i = 0; i < 10; i++) | ||
994 | *p++ = 0x00; | ||
995 | *p++ = 0xff; | ||
996 | *p++ = 0xff; | ||
997 | /* Retrieve the saved copy and we're done. */ | ||
998 | bcopy(tmp, (void*)p, INADDRSZ); | ||
999 | } | ||
1000 | |||
1001 | static void | ||
1002 | map_v4v6_hostent(hp, bpp, lenp) | ||
1003 | struct hostent *hp; | ||
1004 | char **bpp; | ||
1005 | int *lenp; | ||
1006 | { | ||
1007 | char **ap; | ||
1008 | |||
1009 | if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ) | ||
1010 | return; | ||
1011 | hp->h_addrtype = AF_INET6; | ||
1012 | hp->h_length = IN6ADDRSZ; | ||
1013 | for (ap = hp->h_addr_list; *ap; ap++) { | ||
1014 | int i = sizeof(align) - ((u_long)*bpp % sizeof(align)); | ||
1015 | |||
1016 | if (*lenp < (i + IN6ADDRSZ)) { | ||
1017 | /* Out of memory. Truncate address list here. XXX */ | ||
1018 | *ap = NULL; | ||
1019 | return; | ||
1020 | } | ||
1021 | *bpp += i; | ||
1022 | *lenp -= i; | ||
1023 | map_v4v6_address(*ap, *bpp); | ||
1024 | *ap = *bpp; | ||
1025 | *bpp += IN6ADDRSZ; | ||
1026 | *lenp -= IN6ADDRSZ; | ||
1027 | } | ||
1028 | } | ||
1029 | |||
1030 | struct hostent * | ||
1031 | gethostent() | ||
1032 | { | ||
1033 | return (_gethtent()); | ||
1034 | } | ||
1035 | |||
1036 | #ifdef RESOLVSORT | ||
1037 | static void | ||
1038 | addrsort(ap, num) | ||
1039 | char **ap; | ||
1040 | int num; | ||
1041 | { | ||
1042 | int i, j; | ||
1043 | char **p; | ||
1044 | short aval[MAXADDRS]; | ||
1045 | int needsort = 0; | ||
1046 | |||
1047 | p = ap; | ||
1048 | for (i = 0; i < num; i++, p++) { | ||
1049 | for (j = 0 ; (unsigned)j < _res.nsort; j++) | ||
1050 | if (_res.sort_list[j].addr.s_addr == | ||
1051 | (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask)) | ||
1052 | break; | ||
1053 | aval[i] = j; | ||
1054 | if (needsort == 0 && i > 0 && j < aval[i-1]) | ||
1055 | needsort = i; | ||
1056 | } | ||
1057 | if (!needsort) | ||
1058 | return; | ||
1059 | |||
1060 | while (needsort < num) { | ||
1061 | for (j = needsort - 1; j >= 0; j--) { | ||
1062 | if (aval[j] > aval[j+1]) { | ||
1063 | char *hp; | ||
1064 | |||
1065 | i = aval[j]; | ||
1066 | aval[j] = aval[j+1]; | ||
1067 | aval[j+1] = i; | ||
1068 | |||
1069 | hp = ap[j]; | ||
1070 | ap[j] = ap[j+1]; | ||
1071 | ap[j+1] = hp; | ||
1072 | |||
1073 | } else | ||
1074 | break; | ||
1075 | } | ||
1076 | needsort++; | ||
1077 | } | ||
1078 | } | ||
1079 | #endif | ||
diff --git a/src/lib/libc/net/getnetbyaddr.c b/src/lib/libc/net/getnetbyaddr.c index c193860e36..925d1d5895 100644 --- a/src/lib/libc/net/getnetbyaddr.c +++ b/src/lib/libc/net/getnetbyaddr.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: getnetbyaddr.c,v 1.4 1995/02/25 06:20:30 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: getnetbyaddr.c,v 1.5 1997/07/09 01:08:28 millert Exp $"; |
38 | static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getnetbyaddr.c,v 1.4 1995/02/25 06:20:30 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <netdb.h> | 38 | #include <netdb.h> |
@@ -46,14 +40,14 @@ static char rcsid[] = "$NetBSD: getnetbyaddr.c,v 1.4 1995/02/25 06:20:30 cgd Exp | |||
46 | extern int _net_stayopen; | 40 | extern int _net_stayopen; |
47 | 41 | ||
48 | struct netent * | 42 | struct netent * |
49 | getnetbyaddr(net, type) | 43 | _getnetbyaddr(net, type) |
50 | register long net; | 44 | register in_addr_t net; |
51 | register int type; | 45 | register int type; |
52 | { | 46 | { |
53 | register struct netent *p; | 47 | register struct netent *p; |
54 | 48 | ||
55 | setnetent(_net_stayopen); | 49 | setnetent(_net_stayopen); |
56 | while (p = getnetent()) | 50 | while ((p = getnetent())) |
57 | if (p->n_addrtype == type && p->n_net == net) | 51 | if (p->n_addrtype == type && p->n_net == net) |
58 | break; | 52 | break; |
59 | if (!_net_stayopen) | 53 | if (!_net_stayopen) |
diff --git a/src/lib/libc/net/getnetbyname.c b/src/lib/libc/net/getnetbyname.c index 93a2e1256c..4e39cf6860 100644 --- a/src/lib/libc/net/getnetbyname.c +++ b/src/lib/libc/net/getnetbyname.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: getnetbyname.c,v 1.4 1995/02/25 06:20:31 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: getnetbyname.c,v 1.5 1997/07/09 01:08:29 millert Exp $"; |
38 | static char sccsid[] = "@(#)getnetbyname.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getnetbyname.c,v 1.4 1995/02/25 06:20:31 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <netdb.h> | 38 | #include <netdb.h> |
@@ -47,18 +41,18 @@ static char rcsid[] = "$NetBSD: getnetbyname.c,v 1.4 1995/02/25 06:20:31 cgd Exp | |||
47 | extern int _net_stayopen; | 41 | extern int _net_stayopen; |
48 | 42 | ||
49 | struct netent * | 43 | struct netent * |
50 | getnetbyname(name) | 44 | _getnetbyname(name) |
51 | register const char *name; | 45 | register const char *name; |
52 | { | 46 | { |
53 | register struct netent *p; | 47 | register struct netent *p; |
54 | register char **cp; | 48 | register char **cp; |
55 | 49 | ||
56 | setnetent(_net_stayopen); | 50 | setnetent(_net_stayopen); |
57 | while (p = getnetent()) { | 51 | while ((p = getnetent())) { |
58 | if (strcmp(p->n_name, name) == 0) | 52 | if (strcasecmp(p->n_name, name) == 0) |
59 | break; | 53 | break; |
60 | for (cp = p->n_aliases; *cp != 0; cp++) | 54 | for (cp = p->n_aliases; *cp != 0; cp++) |
61 | if (strcmp(*cp, name) == 0) | 55 | if (strcasecmp(*cp, name) == 0) |
62 | goto found; | 56 | goto found; |
63 | } | 57 | } |
64 | found: | 58 | found: |
diff --git a/src/lib/libc/net/getnetent.3 b/src/lib/libc/net/getnetent.3 index d4f0bedbf9..5864b75839 100644 --- a/src/lib/libc/net/getnetent.3 +++ b/src/lib/libc/net/getnetent.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $NetBSD: getnetent.3,v 1.3 1995/02/25 06:20:32 cgd Exp $ | 1 | .\" $OpenBSD: getnetent.3,v 1.5 1998/03/16 05:06:56 millert Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1983, 1991, 1993 | 3 | .\" Copyright (c) 1983, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -31,11 +31,9 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93 | 34 | .Dd March 13, 1997 |
35 | .\" | ||
36 | .Dd June 4, 1993 | ||
37 | .Dt GETNETENT 3 | 35 | .Dt GETNETENT 3 |
38 | .Os BSD 4.2 | 36 | .Os |
39 | .Sh NAME | 37 | .Sh NAME |
40 | .Nm getnetent , | 38 | .Nm getnetent , |
41 | .Nm getnetbyaddr , | 39 | .Nm getnetbyaddr , |
@@ -50,7 +48,7 @@ | |||
50 | .Ft struct netent * | 48 | .Ft struct netent * |
51 | .Fn getnetbyname "char *name" | 49 | .Fn getnetbyname "char *name" |
52 | .Ft struct netent * | 50 | .Ft struct netent * |
53 | .Fn getnetbyaddr "long net" "int type" | 51 | .Fn getnetbyaddr "in_addr_t net" "int type" |
54 | .Fn setnetent "int stayopen" | 52 | .Fn setnetent "int stayopen" |
55 | .Fn endnetent | 53 | .Fn endnetent |
56 | .Sh DESCRIPTION | 54 | .Sh DESCRIPTION |
@@ -70,7 +68,7 @@ struct netent { | |||
70 | char *n_name; /* official name of net */ | 68 | char *n_name; /* official name of net */ |
71 | char **n_aliases; /* alias list */ | 69 | char **n_aliases; /* alias list */ |
72 | int n_addrtype; /* net number type */ | 70 | int n_addrtype; /* net number type */ |
73 | unsigned long n_net; /* net number */ | 71 | in_addr_t n_net; /* net number */ |
74 | }; | 72 | }; |
75 | .Ed | 73 | .Ed |
76 | .Pp | 74 | .Pp |
@@ -113,11 +111,10 @@ The | |||
113 | function | 111 | function |
114 | and | 112 | and |
115 | .Fn getnetbyaddr | 113 | .Fn getnetbyaddr |
116 | sequentially search from the beginning | 114 | search the domain name server if the system is configured to use one. |
117 | of the file until a matching | 115 | If the search fails, or no name server is configured, they sequentially |
118 | net name or | 116 | search from the beginning of the file until a matching net name or |
119 | net address and type is found, | 117 | net address and type is found, or until |
120 | or until | ||
121 | .Dv EOF | 118 | .Dv EOF |
122 | is encountered. | 119 | is encountered. |
123 | Network numbers are supplied in host order. | 120 | Network numbers are supplied in host order. |
@@ -131,7 +128,8 @@ Null pointer | |||
131 | .Dv EOF | 128 | .Dv EOF |
132 | or error. | 129 | or error. |
133 | .Sh SEE ALSO | 130 | .Sh SEE ALSO |
134 | .Xr networks 5 | 131 | .Xr networks 5 , |
132 | .Xr resolver 3 | ||
135 | .Sh HISTORY | 133 | .Sh HISTORY |
136 | The | 134 | The |
137 | .Fn getnetent , | 135 | .Fn getnetent , |
@@ -143,11 +141,8 @@ and | |||
143 | functions appeared in | 141 | functions appeared in |
144 | .Bx 4.2 . | 142 | .Bx 4.2 . |
145 | .Sh BUGS | 143 | .Sh BUGS |
146 | The data space used by | 144 | The data space used by these functions is static; if future use |
147 | these functions is static; if future use requires the data, it should be | 145 | requires the data, it should be copied before any subsequent calls |
148 | copied before any subsequent calls to these functions overwrite it. | 146 | to these functions overwrite it. Only Internet network numbers |
149 | Only Internet network | 147 | are currently understood. Expecting network numbers to fit in no |
150 | numbers are currently understood. | 148 | more than 32 bits is naive. |
151 | Expecting network numbers to fit | ||
152 | in no more than 32 bits is probably | ||
153 | naive. | ||
diff --git a/src/lib/libc/net/getnetent.c b/src/lib/libc/net/getnetent.c index b4e16b8f5d..8f618a1d5e 100644 --- a/src/lib/libc/net/getnetent.c +++ b/src/lib/libc/net/getnetent.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: getnetent.c,v 1.4 1995/02/25 06:20:33 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: getnetent.c,v 1.8 1998/03/16 05:06:57 millert Exp $"; |
38 | static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getnetent.c,v 1.4 1995/02/25 06:20:33 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/types.h> | 38 | #include <sys/types.h> |
@@ -81,22 +75,27 @@ endnetent() | |||
81 | struct netent * | 75 | struct netent * |
82 | getnetent() | 76 | getnetent() |
83 | { | 77 | { |
84 | char *p; | 78 | char *p, *cp, **q; |
85 | register char *cp, **q; | 79 | size_t len; |
86 | 80 | ||
87 | if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) | 81 | if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) |
88 | return (NULL); | 82 | return (NULL); |
89 | again: | 83 | again: |
90 | p = fgets(line, BUFSIZ, netf); | 84 | if ((p = fgetln(netf, &len)) == NULL) |
91 | if (p == NULL) | ||
92 | return (NULL); | 85 | return (NULL); |
93 | if (*p == '#') | 86 | if (p[len-1] == '\n') |
87 | len--; | ||
88 | if (len >= sizeof(line) || len == 0) | ||
94 | goto again; | 89 | goto again; |
95 | cp = strpbrk(p, "#\n"); | 90 | p = memcpy(line, p, len); |
96 | if (cp == NULL) | 91 | line[len] = '\0'; |
92 | if (*p == '#') | ||
97 | goto again; | 93 | goto again; |
98 | *cp = '\0'; | 94 | if ((cp = strchr(p, '#')) != NULL) |
95 | *cp = '\0'; | ||
99 | net.n_name = p; | 96 | net.n_name = p; |
97 | if (strlen(net.n_name) >= MAXHOSTNAMELEN-1) | ||
98 | net.n_name[MAXHOSTNAMELEN-1] = '\0'; | ||
100 | cp = strpbrk(p, " \t"); | 99 | cp = strpbrk(p, " \t"); |
101 | if (cp == NULL) | 100 | if (cp == NULL) |
102 | goto again; | 101 | goto again; |
@@ -116,8 +115,11 @@ again: | |||
116 | cp++; | 115 | cp++; |
117 | continue; | 116 | continue; |
118 | } | 117 | } |
119 | if (q < &net_aliases[MAXALIASES - 1]) | 118 | if (q < &net_aliases[MAXALIASES - 1]) { |
120 | *q++ = cp; | 119 | *q++ = cp; |
120 | if (strlen(cp) >= MAXHOSTNAMELEN-1) | ||
121 | cp[MAXHOSTNAMELEN-1] = '\0'; | ||
122 | } | ||
121 | cp = strpbrk(cp, " \t"); | 123 | cp = strpbrk(cp, " \t"); |
122 | if (cp != NULL) | 124 | if (cp != NULL) |
123 | *cp++ = '\0'; | 125 | *cp++ = '\0'; |
diff --git a/src/lib/libc/net/getnetnamadr.c b/src/lib/libc/net/getnetnamadr.c new file mode 100644 index 0000000000..de208bbac9 --- /dev/null +++ b/src/lib/libc/net/getnetnamadr.c | |||
@@ -0,0 +1,382 @@ | |||
1 | /* $OpenBSD: getnetnamadr.c,v 1.10 1997/12/02 01:34:05 deraadt Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1997, Jason Downs. All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * 3. All advertising materials mentioning features or use of this software | ||
15 | * must display the following acknowledgement: | ||
16 | * This product includes software developed by Jason Downs for the | ||
17 | * OpenBSD system. | ||
18 | * 4. Neither the name(s) of the author(s) nor the name OpenBSD | ||
19 | * may be used to endorse or promote products derived from this software | ||
20 | * without specific prior written permission. | ||
21 | * | ||
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS | ||
23 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, | ||
26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | * SUCH DAMAGE. | ||
33 | */ | ||
34 | /* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro | ||
35 | * Dep. Matematica Universidade de Coimbra, Portugal, Europe | ||
36 | * | ||
37 | * Permission to use, copy, modify, and distribute this software for any | ||
38 | * purpose with or without fee is hereby granted, provided that the above | ||
39 | * copyright notice and this permission notice appear in all copies. | ||
40 | */ | ||
41 | /* | ||
42 | * Copyright (c) 1983, 1993 | ||
43 | * The Regents of the University of California. All rights reserved. | ||
44 | * | ||
45 | * Redistribution and use in source and binary forms, with or without | ||
46 | * modification, are permitted provided that the following conditions | ||
47 | * are met: | ||
48 | * 1. Redistributions of source code must retain the above copyright | ||
49 | * notice, this list of conditions and the following disclaimer. | ||
50 | * 2. Redistributions in binary form must reproduce the above copyright | ||
51 | * notice, this list of conditions and the following disclaimer in the | ||
52 | * documentation and/or other materials provided with the distribution. | ||
53 | * 3. All advertising materials mentioning features or use of this software | ||
54 | * must display the following acknowledgement: | ||
55 | * This product includes software developed by the University of | ||
56 | * California, Berkeley and its contributors. | ||
57 | * 4. Neither the name of the University nor the names of its contributors | ||
58 | * may be used to endorse or promote products derived from this software | ||
59 | * without specific prior written permission. | ||
60 | * | ||
61 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
62 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
63 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
64 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
65 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
66 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
67 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
68 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
69 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
70 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
71 | * SUCH DAMAGE. | ||
72 | */ | ||
73 | |||
74 | #if defined(LIBC_SCCS) && !defined(lint) | ||
75 | #if 0 | ||
76 | static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93"; | ||
77 | static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; | ||
78 | static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; | ||
79 | #else | ||
80 | static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.10 1997/12/02 01:34:05 deraadt Exp $"; | ||
81 | #endif | ||
82 | #endif /* LIBC_SCCS and not lint */ | ||
83 | |||
84 | #include <sys/types.h> | ||
85 | #include <sys/param.h> | ||
86 | #include <sys/socket.h> | ||
87 | #include <netinet/in.h> | ||
88 | #include <arpa/inet.h> | ||
89 | #include <arpa/nameser.h> | ||
90 | |||
91 | #include <stdio.h> | ||
92 | #include <netdb.h> | ||
93 | #include <resolv.h> | ||
94 | #include <ctype.h> | ||
95 | #include <errno.h> | ||
96 | #include <string.h> | ||
97 | |||
98 | extern int h_errno; | ||
99 | |||
100 | struct netent *_getnetbyaddr __P((in_addr_t net, int type)); | ||
101 | struct netent *_getnetbyname __P((const char *name)); | ||
102 | |||
103 | int _hokchar __P((const char *)); | ||
104 | |||
105 | #define BYADDR 0 | ||
106 | #define BYNAME 1 | ||
107 | #define MAXALIASES 35 | ||
108 | |||
109 | #if PACKETSZ > 1024 | ||
110 | #define MAXPACKET PACKETSZ | ||
111 | #else | ||
112 | #define MAXPACKET 1024 | ||
113 | #endif | ||
114 | |||
115 | typedef union { | ||
116 | HEADER hdr; | ||
117 | u_char buf[MAXPACKET]; | ||
118 | } querybuf; | ||
119 | |||
120 | typedef union { | ||
121 | long al; | ||
122 | char ac; | ||
123 | } align; | ||
124 | |||
125 | static struct netent * | ||
126 | getnetanswer(answer, anslen, net_i) | ||
127 | querybuf *answer; | ||
128 | int anslen; | ||
129 | int net_i; | ||
130 | { | ||
131 | |||
132 | register HEADER *hp; | ||
133 | register u_char *cp; | ||
134 | register int n; | ||
135 | u_char *eom; | ||
136 | int type, class, buflen, ancount, qdcount, haveanswer, i, nchar; | ||
137 | char aux1[MAXHOSTNAMELEN], aux2[MAXHOSTNAMELEN], ans[MAXHOSTNAMELEN]; | ||
138 | char *in, *st, *pauxt, *bp, **ap; | ||
139 | char *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0; | ||
140 | static struct netent net_entry; | ||
141 | static char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1]; | ||
142 | |||
143 | /* | ||
144 | * find first satisfactory answer | ||
145 | * | ||
146 | * answer --> +------------+ ( MESSAGE ) | ||
147 | * | Header | | ||
148 | * +------------+ | ||
149 | * | Question | the question for the name server | ||
150 | * +------------+ | ||
151 | * | Answer | RRs answering the question | ||
152 | * +------------+ | ||
153 | * | Authority | RRs pointing toward an authority | ||
154 | * | Additional | RRs holding additional information | ||
155 | * +------------+ | ||
156 | */ | ||
157 | eom = answer->buf + anslen; | ||
158 | hp = &answer->hdr; | ||
159 | ancount = ntohs(hp->ancount); /* #/records in the answer section */ | ||
160 | qdcount = ntohs(hp->qdcount); /* #/entries in the question section */ | ||
161 | bp = netbuf; | ||
162 | buflen = sizeof(netbuf); | ||
163 | cp = answer->buf + HFIXEDSZ; | ||
164 | if (!qdcount) { | ||
165 | if (hp->aa) | ||
166 | h_errno = HOST_NOT_FOUND; | ||
167 | else | ||
168 | h_errno = TRY_AGAIN; | ||
169 | return (NULL); | ||
170 | } | ||
171 | while (qdcount-- > 0) | ||
172 | cp += __dn_skipname(cp, eom) + QFIXEDSZ; | ||
173 | ap = net_aliases; | ||
174 | *ap = NULL; | ||
175 | net_entry.n_aliases = net_aliases; | ||
176 | haveanswer = 0; | ||
177 | while (--ancount >= 0 && cp < eom) { | ||
178 | n = dn_expand(answer->buf, eom, cp, bp, buflen); | ||
179 | #ifdef USE_RESOLV_NAME_OK | ||
180 | if ((n < 0) || !res_dnok(bp)) | ||
181 | #else | ||
182 | if ((n < 0) || !_hokchar(bp)) | ||
183 | #endif | ||
184 | break; | ||
185 | cp += n; | ||
186 | ans[0] = '\0'; | ||
187 | (void)strncpy(&ans[0], bp, sizeof ans-1); | ||
188 | ans[sizeof ans-1] = '\0'; | ||
189 | GETSHORT(type, cp); | ||
190 | GETSHORT(class, cp); | ||
191 | cp += INT32SZ; /* TTL */ | ||
192 | GETSHORT(n, cp); | ||
193 | if (class == C_IN && type == T_PTR) { | ||
194 | n = dn_expand(answer->buf, eom, cp, bp, buflen); | ||
195 | if ((n < 0) || !res_hnok(bp)) { | ||
196 | cp += n; | ||
197 | return (NULL); | ||
198 | } | ||
199 | cp += n; | ||
200 | *ap++ = bp; | ||
201 | bp += strlen(bp) + 1; | ||
202 | net_entry.n_addrtype = | ||
203 | (class == C_IN) ? AF_INET : AF_UNSPEC; | ||
204 | haveanswer++; | ||
205 | } | ||
206 | } | ||
207 | if (haveanswer) { | ||
208 | *ap = NULL; | ||
209 | switch (net_i) { | ||
210 | case BYADDR: | ||
211 | net_entry.n_name = *net_entry.n_aliases; | ||
212 | net_entry.n_net = 0L; | ||
213 | break; | ||
214 | case BYNAME: | ||
215 | in = *net_entry.n_aliases; | ||
216 | net_entry.n_name = &ans[0]; | ||
217 | aux2[0] = '\0'; | ||
218 | for (i = 0; i < 4; i++) { | ||
219 | for (st = in, nchar = 0; | ||
220 | *st != '.'; | ||
221 | st++, nchar++) | ||
222 | ; | ||
223 | if (nchar != 1 || *in != '0' || flag) { | ||
224 | flag = 1; | ||
225 | (void)strncpy(paux1, | ||
226 | (i==0) ? in : in-1, | ||
227 | (i==0) ?nchar : nchar+1); | ||
228 | paux1[(i==0) ? nchar : nchar+1] = '\0'; | ||
229 | pauxt = paux2; | ||
230 | paux2 = strcat(paux1, paux2); | ||
231 | paux1 = pauxt; | ||
232 | } | ||
233 | in = ++st; | ||
234 | } | ||
235 | net_entry.n_net = inet_network(paux2); | ||
236 | break; | ||
237 | } | ||
238 | net_entry.n_aliases++; | ||
239 | return (&net_entry); | ||
240 | } | ||
241 | h_errno = TRY_AGAIN; | ||
242 | return (NULL); | ||
243 | } | ||
244 | |||
245 | struct netent * | ||
246 | getnetbyaddr(net, net_type) | ||
247 | register in_addr_t net; | ||
248 | register int net_type; | ||
249 | { | ||
250 | unsigned int netbr[4]; | ||
251 | int nn, anslen; | ||
252 | querybuf buf; | ||
253 | char qbuf[MAXDNAME]; | ||
254 | in_addr_t net2; | ||
255 | struct netent *net_entry = NULL; | ||
256 | char lookups[MAXDNSLUS]; | ||
257 | int i; | ||
258 | |||
259 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | ||
260 | return(_getnetbyaddr(net, net_type)); | ||
261 | |||
262 | bcopy(_res.lookups, lookups, sizeof lookups); | ||
263 | if (lookups[0] == '\0') | ||
264 | strncpy(lookups, "bf", sizeof lookups); | ||
265 | |||
266 | for (i = 0; i < MAXDNSLUS && lookups[i]; i++) { | ||
267 | switch (lookups[i]) { | ||
268 | #ifdef YP | ||
269 | case 'y': | ||
270 | /* There is no YP support. */ | ||
271 | break; | ||
272 | #endif /* YP */ | ||
273 | case 'b': | ||
274 | if (net_type != AF_INET) | ||
275 | break; /* DNS only supports AF_INET? */ | ||
276 | |||
277 | for (nn = 4, net2 = net; net2; net2 >>= 8) | ||
278 | netbr[--nn] = net2 & 0xff; | ||
279 | switch (nn) { | ||
280 | case 3: /* Class A */ | ||
281 | snprintf(qbuf, sizeof(qbuf), | ||
282 | "0.0.0.%u.in-addr.arpa", netbr[3]); | ||
283 | break; | ||
284 | case 2: /* Class B */ | ||
285 | snprintf(qbuf, sizeof(qbuf), | ||
286 | "0.0.%u.%u.in-addr.arpa", | ||
287 | netbr[3], netbr[2]); | ||
288 | break; | ||
289 | case 1: /* Class C */ | ||
290 | snprintf(qbuf, sizeof(qbuf), | ||
291 | "0.%u.%u.%u.in-addr.arpa", | ||
292 | netbr[3], netbr[2], netbr[1]); | ||
293 | break; | ||
294 | case 0: /* Class D - E */ | ||
295 | snprintf(qbuf, sizeof(qbuf), | ||
296 | "%u.%u.%u.%u.in-addr.arpa", | ||
297 | netbr[3], netbr[2], netbr[1], netbr[0]); | ||
298 | break; | ||
299 | } | ||
300 | anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, | ||
301 | sizeof(buf)); | ||
302 | if (anslen < 0) { | ||
303 | #ifdef DEBUG | ||
304 | if (_res.options & RES_DEBUG) | ||
305 | printf("res_query failed\n"); | ||
306 | #endif | ||
307 | break; | ||
308 | } | ||
309 | net_entry = getnetanswer(&buf, anslen, BYADDR); | ||
310 | if (net_entry != NULL) { | ||
311 | unsigned u_net = net; /* maybe net should be unsigned ? */ | ||
312 | |||
313 | /* Strip trailing zeros */ | ||
314 | while ((u_net & 0xff) == 0 && u_net != 0) | ||
315 | u_net >>= 8; | ||
316 | net_entry->n_net = u_net; | ||
317 | return (net_entry); | ||
318 | } | ||
319 | break; | ||
320 | case 'f': | ||
321 | net_entry = _getnetbyaddr(net, net_type); | ||
322 | if (net_entry != NULL) | ||
323 | return (net_entry); | ||
324 | } | ||
325 | } | ||
326 | |||
327 | /* Nothing matched. */ | ||
328 | return (NULL); | ||
329 | } | ||
330 | |||
331 | struct netent * | ||
332 | getnetbyname(net) | ||
333 | register const char *net; | ||
334 | { | ||
335 | int anslen; | ||
336 | querybuf buf; | ||
337 | char qbuf[MAXDNAME]; | ||
338 | struct netent *net_entry = NULL; | ||
339 | char lookups[MAXDNSLUS]; | ||
340 | int i; | ||
341 | |||
342 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | ||
343 | return (_getnetbyname(net)); | ||
344 | |||
345 | bcopy(_res.lookups, lookups, sizeof lookups); | ||
346 | if (lookups[0] == '\0') | ||
347 | strncpy(lookups, "bf", sizeof lookups); | ||
348 | |||
349 | for (i = 0; i < MAXDNSLUS && lookups[i]; i++) { | ||
350 | switch (lookups[i]) { | ||
351 | #ifdef YP | ||
352 | case 'y': | ||
353 | /* There is no YP support. */ | ||
354 | break; | ||
355 | #endif /* YP */ | ||
356 | case 'b': | ||
357 | strncpy(qbuf, net, sizeof qbuf-1); | ||
358 | qbuf[sizeof qbuf-1] = '\0'; | ||
359 | anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, | ||
360 | sizeof(buf)); | ||
361 | if (anslen < 0) { | ||
362 | #ifdef DEBUG | ||
363 | if (_res.options & RES_DEBUG) | ||
364 | printf("res_query failed\n"); | ||
365 | #endif | ||
366 | break; | ||
367 | } | ||
368 | net_entry = getnetanswer(&buf, anslen, BYNAME); | ||
369 | if (net_entry != NULL) | ||
370 | return (net_entry); | ||
371 | break; | ||
372 | case 'f': | ||
373 | net_entry = _getnetbyname(net); | ||
374 | if (net_entry != NULL) | ||
375 | return (net_entry); | ||
376 | break; | ||
377 | } | ||
378 | } | ||
379 | |||
380 | /* Nothing matched. */ | ||
381 | return (NULL); | ||
382 | } | ||
diff --git a/src/lib/libc/net/getproto.c b/src/lib/libc/net/getproto.c index 49c09b0806..474d8d9427 100644 --- a/src/lib/libc/net/getproto.c +++ b/src/lib/libc/net/getproto.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: getproto.c,v 1.4 1995/02/25 06:20:33 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: getproto.c,v 1.3 1997/07/09 01:08:31 millert Exp $"; |
38 | static char sccsid[] = "@(#)getproto.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getproto.c,v 1.4 1995/02/25 06:20:33 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <netdb.h> | 38 | #include <netdb.h> |
@@ -52,7 +46,7 @@ getprotobynumber(proto) | |||
52 | register struct protoent *p; | 46 | register struct protoent *p; |
53 | 47 | ||
54 | setprotoent(_proto_stayopen); | 48 | setprotoent(_proto_stayopen); |
55 | while (p = getprotoent()) | 49 | while ((p = getprotoent())) |
56 | if (p->p_proto == proto) | 50 | if (p->p_proto == proto) |
57 | break; | 51 | break; |
58 | if (!_proto_stayopen) | 52 | if (!_proto_stayopen) |
diff --git a/src/lib/libc/net/getprotoent.3 b/src/lib/libc/net/getprotoent.3 index 8d607199ef..f67987954f 100644 --- a/src/lib/libc/net/getprotoent.3 +++ b/src/lib/libc/net/getprotoent.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $NetBSD: getprotoent.3,v 1.3 1995/02/25 06:20:34 cgd Exp $ | 1 | .\" $OpenBSD: getprotoent.3,v 1.2 1996/08/19 08:28:50 tholo Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1983, 1991, 1993 | 3 | .\" Copyright (c) 1983, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -31,8 +31,6 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" @(#)getprotoent.3 8.1 (Berkeley) 6/4/93 | ||
35 | .\" | ||
36 | .Dd June 4, 1993 | 34 | .Dd June 4, 1993 |
37 | .Dt GETPROTOENT 3 | 35 | .Dt GETPROTOENT 3 |
38 | .Os BSD 4.2 | 36 | .Os BSD 4.2 |
diff --git a/src/lib/libc/net/getprotoent.c b/src/lib/libc/net/getprotoent.c index 1179b9029b..2bef526e7a 100644 --- a/src/lib/libc/net/getprotoent.c +++ b/src/lib/libc/net/getprotoent.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: getprotoent.c,v 1.4 1995/02/25 06:20:35 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.3 1998/03/16 05:06:59 millert Exp $"; |
38 | static char sccsid[] = "@(#)getprotoent.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getprotoent.c,v 1.4 1995/02/25 06:20:35 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/types.h> | 38 | #include <sys/types.h> |
@@ -80,20 +74,24 @@ endprotoent() | |||
80 | struct protoent * | 74 | struct protoent * |
81 | getprotoent() | 75 | getprotoent() |
82 | { | 76 | { |
83 | char *p; | 77 | char *p, *cp, **q; |
84 | register char *cp, **q; | 78 | size_t len; |
85 | 79 | ||
86 | if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) | 80 | if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) |
87 | return (NULL); | 81 | return (NULL); |
88 | again: | 82 | again: |
89 | if ((p = fgets(line, BUFSIZ, protof)) == NULL) | 83 | if ((p = fgetln(protof, &len)) == NULL) |
90 | return (NULL); | 84 | return (NULL); |
91 | if (*p == '#') | 85 | if (p[len-1] == '\n') |
86 | len--; | ||
87 | if (len >= sizeof(line) || len == 0) | ||
92 | goto again; | 88 | goto again; |
93 | cp = strpbrk(p, "#\n"); | 89 | p = memcpy(line, p, len); |
94 | if (cp == NULL) | 90 | line[len] = '\0'; |
91 | if (*p == '#') | ||
95 | goto again; | 92 | goto again; |
96 | *cp = '\0'; | 93 | if ((cp = strchr(p, '#')) != NULL) |
94 | *cp = '\0'; | ||
97 | proto.p_name = p; | 95 | proto.p_name = p; |
98 | cp = strpbrk(p, " \t"); | 96 | cp = strpbrk(p, " \t"); |
99 | if (cp == NULL) | 97 | if (cp == NULL) |
diff --git a/src/lib/libc/net/getprotoname.c b/src/lib/libc/net/getprotoname.c index 4f8cf21c3f..7a4e5fede5 100644 --- a/src/lib/libc/net/getprotoname.c +++ b/src/lib/libc/net/getprotoname.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: getprotoname.c,v 1.4 1995/02/25 06:20:36 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: getprotoname.c,v 1.3 1997/07/09 01:08:32 millert Exp $"; |
38 | static char sccsid[] = "@(#)getprotoname.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getprotoname.c,v 1.4 1995/02/25 06:20:36 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <netdb.h> | 38 | #include <netdb.h> |
@@ -54,7 +48,7 @@ getprotobyname(name) | |||
54 | register char **cp; | 48 | register char **cp; |
55 | 49 | ||
56 | setprotoent(_proto_stayopen); | 50 | setprotoent(_proto_stayopen); |
57 | while (p = getprotoent()) { | 51 | while ((p = getprotoent())) { |
58 | if (strcmp(p->p_name, name) == 0) | 52 | if (strcmp(p->p_name, name) == 0) |
59 | break; | 53 | break; |
60 | for (cp = p->p_aliases; *cp != 0; cp++) | 54 | for (cp = p->p_aliases; *cp != 0; cp++) |
diff --git a/src/lib/libc/net/getservbyname.c b/src/lib/libc/net/getservbyname.c index b4a6311966..25f0e27d06 100644 --- a/src/lib/libc/net/getservbyname.c +++ b/src/lib/libc/net/getservbyname.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: getservbyname.c,v 1.4 1995/02/25 06:20:36 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: getservbyname.c,v 1.3 1997/07/09 01:08:34 millert Exp $"; |
38 | static char sccsid[] = "@(#)getservbyname.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getservbyname.c,v 1.4 1995/02/25 06:20:36 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <netdb.h> | 38 | #include <netdb.h> |
@@ -54,7 +48,7 @@ getservbyname(name, proto) | |||
54 | register char **cp; | 48 | register char **cp; |
55 | 49 | ||
56 | setservent(_serv_stayopen); | 50 | setservent(_serv_stayopen); |
57 | while (p = getservent()) { | 51 | while ((p = getservent())) { |
58 | if (strcmp(name, p->s_name) == 0) | 52 | if (strcmp(name, p->s_name) == 0) |
59 | goto gotname; | 53 | goto gotname; |
60 | for (cp = p->s_aliases; *cp; cp++) | 54 | for (cp = p->s_aliases; *cp; cp++) |
diff --git a/src/lib/libc/net/getservbyport.c b/src/lib/libc/net/getservbyport.c index c34790737b..4b063760d2 100644 --- a/src/lib/libc/net/getservbyport.c +++ b/src/lib/libc/net/getservbyport.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: getservbyport.c,v 1.4 1995/02/25 06:20:37 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: getservbyport.c,v 1.3 1997/07/09 01:08:35 millert Exp $"; |
38 | static char sccsid[] = "@(#)getservbyport.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getservbyport.c,v 1.4 1995/02/25 06:20:37 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <netdb.h> | 38 | #include <netdb.h> |
@@ -54,7 +48,7 @@ getservbyport(port, proto) | |||
54 | register struct servent *p; | 48 | register struct servent *p; |
55 | 49 | ||
56 | setservent(_serv_stayopen); | 50 | setservent(_serv_stayopen); |
57 | while (p = getservent()) { | 51 | while ((p = getservent())) { |
58 | if (p->s_port != port) | 52 | if (p->s_port != port) |
59 | continue; | 53 | continue; |
60 | if (proto == 0 || strcmp(p->s_proto, proto) == 0) | 54 | if (proto == 0 || strcmp(p->s_proto, proto) == 0) |
diff --git a/src/lib/libc/net/getservent.3 b/src/lib/libc/net/getservent.3 index 9e0656be00..d1684c28c4 100644 --- a/src/lib/libc/net/getservent.3 +++ b/src/lib/libc/net/getservent.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $NetBSD: getservent.3,v 1.3 1995/02/25 06:20:38 cgd Exp $ | 1 | .\" $OpenBSD: getservent.3,v 1.3 1996/08/30 02:00:11 millert Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1983, 1991, 1993 | 3 | .\" Copyright (c) 1983, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -31,8 +31,6 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" @(#)getservent.3 8.3 (Berkeley) 1/12/94 | ||
35 | .\" | ||
36 | .Dd January 12, 1994 | 34 | .Dd January 12, 1994 |
37 | .Dt GETSERVENT 3 | 35 | .Dt GETSERVENT 3 |
38 | .Os BSD 4.2 | 36 | .Os BSD 4.2 |
@@ -50,7 +48,7 @@ | |||
50 | .Ft struct servent * | 48 | .Ft struct servent * |
51 | .Fn getservbyname "char *name" "char *proto" | 49 | .Fn getservbyname "char *name" "char *proto" |
52 | .Ft struct servent * | 50 | .Ft struct servent * |
53 | .Fn getservbyport "int port" proto | 51 | .Fn getservbyport "int port" "char *proto" |
54 | .Ft void | 52 | .Ft void |
55 | .Fn setservent "int stayopen" | 53 | .Fn setservent "int stayopen" |
56 | .Ft void | 54 | .Ft void |
diff --git a/src/lib/libc/net/getservent.c b/src/lib/libc/net/getservent.c index 316891450e..7d8cb6d8ca 100644 --- a/src/lib/libc/net/getservent.c +++ b/src/lib/libc/net/getservent.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: getservent.c,v 1.4 1995/02/25 06:20:38 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: getservent.c,v 1.4 1998/03/16 05:07:00 millert Exp $"; |
38 | static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getservent.c,v 1.4 1995/02/25 06:20:38 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/types.h> | 38 | #include <sys/types.h> |
@@ -80,20 +74,24 @@ endservent() | |||
80 | struct servent * | 74 | struct servent * |
81 | getservent() | 75 | getservent() |
82 | { | 76 | { |
83 | char *p; | 77 | char *p, *cp, **q; |
84 | register char *cp, **q; | 78 | size_t len; |
85 | 79 | ||
86 | if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) | 80 | if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) |
87 | return (NULL); | 81 | return (NULL); |
88 | again: | 82 | again: |
89 | if ((p = fgets(line, BUFSIZ, servf)) == NULL) | 83 | if ((p = fgetln(servf, &len)) == NULL) |
90 | return (NULL); | 84 | return (NULL); |
91 | if (*p == '#') | 85 | if (p[len-1] == '\n') |
86 | len--; | ||
87 | if (len >= sizeof(line) || len == 0) | ||
92 | goto again; | 88 | goto again; |
93 | cp = strpbrk(p, "#\n"); | 89 | p = memcpy(line, p, len); |
94 | if (cp == NULL) | 90 | line[len] = '\0'; |
91 | if (*p == '#') | ||
95 | goto again; | 92 | goto again; |
96 | *cp = '\0'; | 93 | if ((cp = strchr(p, '#')) != NULL) |
94 | *cp = '\0'; | ||
97 | serv.s_name = p; | 95 | serv.s_name = p; |
98 | p = strpbrk(p, " \t"); | 96 | p = strpbrk(p, " \t"); |
99 | if (p == NULL) | 97 | if (p == NULL) |
@@ -105,7 +103,7 @@ again: | |||
105 | if (cp == NULL) | 103 | if (cp == NULL) |
106 | goto again; | 104 | goto again; |
107 | *cp++ = '\0'; | 105 | *cp++ = '\0'; |
108 | serv.s_port = htons((u_short)atoi(p)); | 106 | serv.s_port = htons((in_port_t)atoi(p)); |
109 | serv.s_proto = cp; | 107 | serv.s_proto = cp; |
110 | q = serv.s_aliases = serv_aliases; | 108 | q = serv.s_aliases = serv_aliases; |
111 | cp = strpbrk(cp, " \t"); | 109 | cp = strpbrk(cp, " \t"); |
diff --git a/src/lib/libc/net/herror.c b/src/lib/libc/net/herror.c index 41adbf1055..737bb115a7 100644 --- a/src/lib/libc/net/herror.c +++ b/src/lib/libc/net/herror.c | |||
@@ -1,9 +1,11 @@ | |||
1 | /* $NetBSD: herror.c,v 1.5 1995/02/25 06:20:39 cgd Exp $ */ | 1 | /* $OpenBSD: herror.c,v 1.4 1997/03/13 19:07:28 downsj Exp $ */ |
2 | 2 | ||
3 | /*- | 3 | /* |
4 | * ++Copyright++ 1987, 1993 | ||
5 | * - | ||
4 | * Copyright (c) 1987, 1993 | 6 | * Copyright (c) 1987, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 7 | * The Regents of the University of California. All rights reserved. |
6 | * | 8 | * |
7 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions |
9 | * are met: | 11 | * are met: |
@@ -14,12 +16,12 @@ | |||
14 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
15 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. All advertising materials mentioning features or use of this software |
16 | * must display the following acknowledgement: | 18 | * must display the following acknowledgement: |
17 | * This product includes software developed by the University of | 19 | * This product includes software developed by the University of |
18 | * California, Berkeley and its contributors. | 20 | * California, Berkeley and its contributors. |
19 | * 4. Neither the name of the University nor the names of its contributors | 21 | * 4. Neither the name of the University nor the names of its contributors |
20 | * may be used to endorse or promote products derived from this software | 22 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. | 23 | * without specific prior written permission. |
22 | * | 24 | * |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -56,26 +58,27 @@ | |||
56 | #if defined(LIBC_SCCS) && !defined(lint) | 58 | #if defined(LIBC_SCCS) && !defined(lint) |
57 | #if 0 | 59 | #if 0 |
58 | static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; | 60 | static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; |
59 | static char rcsid[] = "$Id: herror.c,v 4.9.1.1 1993/05/02 23:14:35 vixie Rel "; | 61 | static char rcsid[] = "$From: herror.c,v 8.3 1996/08/05 08:31:35 vixie Exp $"; |
60 | #else | 62 | #else |
61 | static char rcsid[] = "$NetBSD: herror.c,v 1.5 1995/02/25 06:20:39 cgd Exp $"; | 63 | static char rcsid[] = "$OpenBSD: herror.c,v 1.4 1997/03/13 19:07:28 downsj Exp $"; |
62 | #endif | 64 | #endif |
63 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
64 | 66 | ||
65 | #include <sys/types.h> | 67 | #include <sys/types.h> |
68 | #include <sys/param.h> | ||
66 | #include <sys/uio.h> | 69 | #include <sys/uio.h> |
67 | #include <netdb.h> | 70 | #include <netdb.h> |
68 | #include <unistd.h> | 71 | #include <unistd.h> |
69 | #include <string.h> | 72 | #include <string.h> |
70 | 73 | ||
71 | char *h_errlist[] = { | 74 | const char *h_errlist[] = { |
72 | "Error 0", | 75 | "Resolver Error 0 (no error)", |
73 | "Unknown host", /* 1 HOST_NOT_FOUND */ | 76 | "Unknown host", /* 1 HOST_NOT_FOUND */ |
74 | "Host name lookup failure", /* 2 TRY_AGAIN */ | 77 | "Host name lookup failure", /* 2 TRY_AGAIN */ |
75 | "Unknown server error", /* 3 NO_RECOVERY */ | 78 | "Unknown server error", /* 3 NO_RECOVERY */ |
76 | "No address associated with name", /* 4 NO_ADDRESS */ | 79 | "No address associated with name", /* 4 NO_ADDRESS */ |
77 | }; | 80 | }; |
78 | int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; | 81 | int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; |
79 | 82 | ||
80 | extern int h_errno; | 83 | extern int h_errno; |
81 | 84 | ||
@@ -98,8 +101,7 @@ herror(s) | |||
98 | v->iov_len = 2; | 101 | v->iov_len = 2; |
99 | v++; | 102 | v++; |
100 | } | 103 | } |
101 | v->iov_base = (u_int)h_errno < h_nerr ? | 104 | v->iov_base = (char *)hstrerror(h_errno); |
102 | h_errlist[h_errno] : "Unknown error"; | ||
103 | v->iov_len = strlen(v->iov_base); | 105 | v->iov_len = strlen(v->iov_base); |
104 | v++; | 106 | v++; |
105 | v->iov_base = "\n"; | 107 | v->iov_base = "\n"; |
@@ -107,9 +109,13 @@ herror(s) | |||
107 | writev(STDERR_FILENO, iov, (v - iov) + 1); | 109 | writev(STDERR_FILENO, iov, (v - iov) + 1); |
108 | } | 110 | } |
109 | 111 | ||
110 | char * | 112 | const char * |
111 | hstrerror(err) | 113 | hstrerror(err) |
112 | int err; | 114 | int err; |
113 | { | 115 | { |
114 | return (u_int)err < h_nerr ? h_errlist[err] : "Unknown resolver error"; | 116 | if (err < 0) |
117 | return ("Resolver internal error"); | ||
118 | else if (err < h_nerr) | ||
119 | return (h_errlist[err]); | ||
120 | return ("Unknown resolver error"); | ||
115 | } | 121 | } |
diff --git a/src/lib/libc/net/htonl.c b/src/lib/libc/net/htonl.c index ac85cb0fd7..73b7432731 100644 --- a/src/lib/libc/net/htonl.c +++ b/src/lib/libc/net/htonl.c | |||
@@ -1,29 +1,25 @@ | |||
1 | /* $NetBSD: htonl.c,v 1.5 1995/04/28 23:25:14 jtc Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Written by J.T. Conklin <jtc@netbsd.org>. | 2 | * Written by J.T. Conklin <jtc@netbsd.org>. |
5 | * Public domain. | 3 | * Public domain. |
6 | */ | 4 | */ |
7 | 5 | ||
8 | #if defined(LIBC_SCCS) && !defined(lint) | 6 | #if defined(LIBC_SCCS) && !defined(lint) |
9 | static char *rcsid = "$NetBSD: htonl.c,v 1.5 1995/04/28 23:25:14 jtc Exp $"; | 7 | static char *rcsid = "$OpenBSD: htonl.c,v 1.4 1996/12/12 03:19:55 tholo Exp $"; |
10 | #endif | 8 | #endif /* LIBC_SCCS and not lint */ |
11 | 9 | ||
12 | #include <sys/types.h> | 10 | #include <sys/types.h> |
13 | #include <machine/endian.h> | 11 | #include <machine/endian.h> |
14 | 12 | ||
15 | #undef htonl | 13 | #undef htonl |
16 | 14 | ||
17 | unsigned long | 15 | u_int32_t |
18 | htonl(x) | 16 | htonl(x) |
19 | unsigned long x; | 17 | u_int32_t x; |
20 | { | 18 | { |
21 | u_int32_t y = x; | ||
22 | |||
23 | #if BYTE_ORDER == LITTLE_ENDIAN | 19 | #if BYTE_ORDER == LITTLE_ENDIAN |
24 | u_char *s = (u_char *)&y; | 20 | u_char *s = (u_char *)&x; |
25 | return s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]; | 21 | return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); |
26 | #else | 22 | #else |
27 | return y; | 23 | return x; |
28 | #endif | 24 | #endif |
29 | } | 25 | } |
diff --git a/src/lib/libc/net/htons.c b/src/lib/libc/net/htons.c index b2500a51d1..47cf25952d 100644 --- a/src/lib/libc/net/htons.c +++ b/src/lib/libc/net/htons.c | |||
@@ -1,26 +1,28 @@ | |||
1 | /* $NetBSD: htons.c,v 1.5 1995/04/28 23:25:19 jtc Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Written by J.T. Conklin <jtc@netbsd.org>. | 2 | * Written by J.T. Conklin <jtc@netbsd.org>. |
5 | * Public domain. | 3 | * Public domain. |
6 | */ | 4 | */ |
7 | 5 | ||
8 | #if defined(LIBC_SCCS) && !defined(lint) | 6 | #if defined(LIBC_SCCS) && !defined(lint) |
9 | static char *rcsid = "$NetBSD: htons.c,v 1.5 1995/04/28 23:25:19 jtc Exp $"; | 7 | static char *rcsid = "$OpenBSD: htons.c,v 1.6 1997/07/25 20:30:07 mickey Exp $"; |
10 | #endif | 8 | #endif /* LIBC_SCCS and not lint */ |
11 | 9 | ||
12 | #include <sys/types.h> | 10 | #include <sys/types.h> |
13 | #include <machine/endian.h> | 11 | #include <machine/endian.h> |
14 | 12 | ||
15 | #undef htons | 13 | #undef htons |
16 | 14 | ||
17 | unsigned short | 15 | u_int16_t |
16 | #ifdef __STDC__ | ||
17 | htons(u_int16_t x) | ||
18 | #else | ||
18 | htons(x) | 19 | htons(x) |
19 | unsigned short x; | 20 | u_int16_t x; |
21 | #endif | ||
20 | { | 22 | { |
21 | #if BYTE_ORDER == LITTLE_ENDIAN | 23 | #if BYTE_ORDER == LITTLE_ENDIAN |
22 | u_char *s = (u_char *) &x; | 24 | u_char *s = (u_char *) &x; |
23 | return s[0] << 8 | s[1]; | 25 | return (u_int16_t)(s[0] << 8 | s[1]); |
24 | #else | 26 | #else |
25 | return x; | 27 | return x; |
26 | #endif | 28 | #endif |
diff --git a/src/lib/libc/net/inet.3 b/src/lib/libc/net/inet.3 index 49bac97e96..2fb86cd927 100644 --- a/src/lib/libc/net/inet.3 +++ b/src/lib/libc/net/inet.3 | |||
@@ -1,4 +1,5 @@ | |||
1 | .\" $NetBSD: inet.3,v 1.4 1995/02/27 09:45:26 chopps Exp $ | 1 | .\" $OpenBSD: inet.3,v 1.4 1997/06/23 04:01:11 millert Exp $ |
2 | .\" $NetBSD: inet.3,v 1.7 1997/06/18 02:25:24 lukem Exp $ | ||
2 | .\" | 3 | .\" |
3 | .\" Copyright (c) 1983, 1990, 1991, 1993 | 4 | .\" Copyright (c) 1983, 1990, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 5 | .\" The Regents of the University of California. All rights reserved. |
@@ -33,36 +34,42 @@ | |||
33 | .\" | 34 | .\" |
34 | .\" @(#)inet.3 8.1 (Berkeley) 6/4/93 | 35 | .\" @(#)inet.3 8.1 (Berkeley) 6/4/93 |
35 | .\" | 36 | .\" |
36 | .Dd June 4, 1993 | 37 | .Dd June 18, 1997 |
37 | .Dt INET 3 | 38 | .Dt INET 3 |
38 | .Os BSD 4.2 | 39 | .Os BSD 4.2 |
39 | .Sh NAME | 40 | .Sh NAME |
40 | .Nm inet_aton , | ||
41 | .Nm inet_addr , | 41 | .Nm inet_addr , |
42 | .Nm inet_aton , | ||
43 | .Nm inet_lnaof , | ||
44 | .Nm inet_makeaddr , | ||
45 | .Nm inet_netof , | ||
42 | .Nm inet_network , | 46 | .Nm inet_network , |
43 | .Nm inet_ntoa , | 47 | .Nm inet_ntoa , |
44 | .Nm inet_makeaddr , | 48 | .Nm inet_ntop , |
45 | .Nm inet_lnaof , | 49 | .Nm inet_pton |
46 | .Nm inet_netof | ||
47 | .Nd Internet address manipulation routines | 50 | .Nd Internet address manipulation routines |
48 | .Sh SYNOPSIS | 51 | .Sh SYNOPSIS |
49 | .Fd #include <sys/socket.h> | 52 | .Fd #include <sys/socket.h> |
50 | .Fd #include <netinet/in.h> | 53 | .Fd #include <netinet/in.h> |
51 | .Fd #include <arpa/inet.h> | 54 | .Fd #include <arpa/inet.h> |
52 | .Ft int | 55 | .Ft in_addr_t |
53 | .Fn inet_aton "const char *cp" "struct in_addr *pin" | ||
54 | .Ft unsigned long | ||
55 | .Fn inet_addr "const char *cp" | 56 | .Fn inet_addr "const char *cp" |
56 | .Ft unsigned long | 57 | .Ft int |
58 | .Fn inet_aton "const char *cp" "struct in_addr *addr" | ||
59 | .Ft in_addr_t | ||
60 | .Fn inet_lnaof "struct in_addr in" | ||
61 | .Ft struct in_addr | ||
62 | .Fn inet_makeaddr "unsigned long net" "unsigned long lna" | ||
63 | .Ft in_addr_t | ||
64 | .Fn inet_netof "struct in_addr in" | ||
65 | .Ft in_addr_t | ||
57 | .Fn inet_network "const char *cp" | 66 | .Fn inet_network "const char *cp" |
58 | .Ft char * | 67 | .Ft char * |
59 | .Fn inet_ntoa "struct in_addr in" | 68 | .Fn inet_ntoa "struct in_addr in" |
60 | .Ft struct in_addr | 69 | .Ft const char * |
61 | .Fn inet_makeaddr "int net" "int lna" | 70 | .Fn inet_ntop "int af" "const void *src" "char *dst" "size_t size" |
62 | .Ft unsigned long | 71 | .Ft int |
63 | .Fn inet_lnaof "struct in_addr in" | 72 | .Fn inet_pton "int af" "const char *src" "void *dst" |
64 | .Ft unsigned long | ||
65 | .Fn inet_netof "struct in_addr in" | ||
66 | .Sh DESCRIPTION | 73 | .Sh DESCRIPTION |
67 | The routines | 74 | The routines |
68 | .Fn inet_aton , | 75 | .Fn inet_aton , |
@@ -74,6 +81,17 @@ numbers expressed in the Internet standard | |||
74 | .Ql \&. | 81 | .Ql \&. |
75 | notation. | 82 | notation. |
76 | The | 83 | The |
84 | .Fn inet_pton | ||
85 | function converts a presentation format address (that is, printable form | ||
86 | as held in a character string) to network format (usually a | ||
87 | .Ft struct in_addr | ||
88 | or some other internal binary representation, in network byte order). It | ||
89 | returns 1 if the address was valid for the specified address family, or | ||
90 | 0 if the address wasn't parseable in the specified address family, or -1 | ||
91 | if some system error occurred (in which case | ||
92 | .Va errno | ||
93 | will have been set). This function is presently valid for AF_INET and | ||
94 | AF_INET6. The | ||
77 | .Fn inet_aton | 95 | .Fn inet_aton |
78 | routine interprets the specified character string as an Internet address, | 96 | routine interprets the specified character string as an Internet address, |
79 | placing the address into the structure provided. | 97 | placing the address into the structure provided. |
@@ -86,6 +104,16 @@ and | |||
86 | functions return numbers suitable for use | 104 | functions return numbers suitable for use |
87 | as Internet addresses and Internet network | 105 | as Internet addresses and Internet network |
88 | numbers, respectively. | 106 | numbers, respectively. |
107 | .Pp | ||
108 | The function | ||
109 | .Fn inet_ntop | ||
110 | converts an address from network format (usually a | ||
111 | .Ft struct in_addr | ||
112 | or some other binary form, in network byte order) to presentation format | ||
113 | (suitable for external display purposes). It returns NULL if a system | ||
114 | error occurs (in which case, | ||
115 | .Va errno | ||
116 | will have been set), or it returns a pointer to the destination string. | ||
89 | The routine | 117 | The routine |
90 | .Fn inet_ntoa | 118 | .Fn inet_ntoa |
91 | takes an Internet address and returns an | 119 | takes an Internet address and returns an |
@@ -108,7 +136,7 @@ All Internet addresses are returned in network | |||
108 | order (bytes ordered from left to right). | 136 | order (bytes ordered from left to right). |
109 | All network numbers and local address parts are | 137 | All network numbers and local address parts are |
110 | returned as machine format integer values. | 138 | returned as machine format integer values. |
111 | .Sh INTERNET ADDRESSES | 139 | .Sh INTERNET ADDRESSES (IP VERSION 4) |
112 | Values specified using the | 140 | Values specified using the |
113 | .Ql \&. | 141 | .Ql \&. |
114 | notation take one | 142 | notation take one |
@@ -124,15 +152,14 @@ When four parts are specified, each is interpreted | |||
124 | as a byte of data and assigned, from left to right, | 152 | as a byte of data and assigned, from left to right, |
125 | to the four bytes of an Internet address. Note | 153 | to the four bytes of an Internet address. Note |
126 | that when an Internet address is viewed as a 32-bit | 154 | that when an Internet address is viewed as a 32-bit |
127 | integer quantity on the | 155 | integer quantity on a system that uses little-endian |
128 | .Tn VAX | 156 | byte order (such as the |
129 | the bytes referred to | 157 | .Tn Intel 386, 486 |
130 | above appear as | 158 | and |
159 | .Tn Pentium | ||
160 | processors) the bytes referred to above appear as | ||
131 | .Dq Li d.c.b.a . | 161 | .Dq Li d.c.b.a . |
132 | That is, | 162 | That is, little-endian bytes are ordered from right to left. |
133 | .Tn VAX | ||
134 | bytes are | ||
135 | ordered from right to left. | ||
136 | .Pp | 163 | .Pp |
137 | When a three part address is specified, the last | 164 | When a three part address is specified, the last |
138 | part is interpreted as a 16-bit quantity and placed | 165 | part is interpreted as a 16-bit quantity and placed |
@@ -161,6 +188,68 @@ may be decimal, octal, or hexadecimal, as specified | |||
161 | in the C language (i.e., a leading 0x or 0X implies | 188 | in the C language (i.e., a leading 0x or 0X implies |
162 | hexadecimal; otherwise, a leading 0 implies octal; | 189 | hexadecimal; otherwise, a leading 0 implies octal; |
163 | otherwise, the number is interpreted as decimal). | 190 | otherwise, the number is interpreted as decimal). |
191 | .Sh INTERNET ADDRESSES (IP VERSION 6) | ||
192 | The presentation format of an IPv6 address is given in [RFC1884 2.2]: | ||
193 | .Pp | ||
194 | There are three conventional forms for representing IPv6 addresses as | ||
195 | text strings: | ||
196 | .Bl -enum | ||
197 | .It | ||
198 | The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the | ||
199 | hexadecimal values of the eight 16-bit pieces of the address. | ||
200 | Examples: | ||
201 | .Bd -literal -offset indent | ||
202 | FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 | ||
203 | 1080:0:0:0:8:800:200C:417A | ||
204 | .Ed | ||
205 | .Pp | ||
206 | Note that it is not necessary to write the leading zeros in an | ||
207 | individual field, but there must be at least one numeral in | ||
208 | every field (except for the case described in 2.). | ||
209 | .It | ||
210 | Due to the method of allocating certain styles of IPv6 | ||
211 | addresses, it will be common for addresses to contain long | ||
212 | strings of zero bits. In order to make writing addresses | ||
213 | .Pp | ||
214 | containing zero bits easier a special syntax is available to | ||
215 | compress the zeros. The use of ``::'' indicates multiple groups | ||
216 | of 16-bits of zeros. The ``::'' can only appear once in an | ||
217 | address. The ``::'' can also be used to compress the leading | ||
218 | and/or trailing zeros in an address. | ||
219 | .Pp | ||
220 | For example the following addresses: | ||
221 | .Bd -literal -offset indent | ||
222 | 1080:0:0:0:8:800:200C:417A a unicast address | ||
223 | FF01:0:0:0:0:0:0:43 a multicast address | ||
224 | 0:0:0:0:0:0:0:1 the loopback address | ||
225 | 0:0:0:0:0:0:0:0 the unspecified addresses | ||
226 | .Ed | ||
227 | .Pp | ||
228 | may be represented as: | ||
229 | .Bd -literal -offset indent | ||
230 | 1080::8:800:200C:417A a unicast address | ||
231 | FF01::43 a multicast address | ||
232 | ::1 the loopback address | ||
233 | :: the unspecified addresses | ||
234 | .Ed | ||
235 | .It | ||
236 | An alternative form that is sometimes more convenient when | ||
237 | dealing with a mixed environment of IPv4 and IPv6 nodes is | ||
238 | x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values | ||
239 | of the six high-order 16-bit pieces of the address, and the 'd's | ||
240 | are the decimal values of the four low-order 8-bit pieces of the | ||
241 | address (standard IPv4 representation). Examples: | ||
242 | .Bd -literal -offset indent | ||
243 | 0:0:0:0:0:0:13.1.68.3 | ||
244 | 0:0:0:0:0:FFFF:129.144.52.38 | ||
245 | .Ed | ||
246 | .Pp | ||
247 | or in compressed form: | ||
248 | .Bd -literal -offset indent | ||
249 | ::13.1.68.3 | ||
250 | ::FFFF:129.144.52.38 | ||
251 | .Ed | ||
252 | .El | ||
164 | .Sh DIAGNOSTICS | 253 | .Sh DIAGNOSTICS |
165 | The constant | 254 | The constant |
166 | .Dv INADDR_NONE | 255 | .Dv INADDR_NONE |
@@ -170,14 +259,44 @@ and | |||
170 | .Fn inet_network | 259 | .Fn inet_network |
171 | for malformed requests. | 260 | for malformed requests. |
172 | .Sh SEE ALSO | 261 | .Sh SEE ALSO |
262 | .Xr byteorder 3 , | ||
173 | .Xr gethostbyname 3 , | 263 | .Xr gethostbyname 3 , |
174 | .Xr getnetent 3 , | 264 | .Xr getnetent 3 , |
265 | .Xr inet_net 3 , | ||
175 | .Xr hosts 5 , | 266 | .Xr hosts 5 , |
176 | .Xr networks 5 , | 267 | .Xr networks 5 |
268 | .Sh STANDARDS | ||
269 | The | ||
270 | .Nm inet_ntop | ||
271 | and | ||
272 | .Nm inet_pton | ||
273 | functions conforms to the IETF IPng BSD API and address formatting | ||
274 | specifications. Note that | ||
275 | .Nm inet_pton | ||
276 | does not accept 1-, 2-, or 3-part dotted addresses; all four parts | ||
277 | must be specified. This is a narrower input set than that accepted by | ||
278 | .Nm inet_aton . | ||
177 | .Sh HISTORY | 279 | .Sh HISTORY |
178 | These | 280 | The |
179 | functions appeared in | 281 | .Nm inet_addr , |
282 | .Nm inet_network , | ||
283 | .Nm inet_makeaddr , | ||
284 | .Nm inet_lnaof | ||
285 | and | ||
286 | .Nm inet_netof | ||
287 | functions appeared in | ||
180 | .Bx 4.2 . | 288 | .Bx 4.2 . |
289 | The | ||
290 | .Nm inet_aton | ||
291 | and | ||
292 | .Nm inet_ntoa | ||
293 | functions appeared in | ||
294 | .Bx 4.3 . | ||
295 | The | ||
296 | .Nm inet_pton | ||
297 | and | ||
298 | .Nm inet_ntop | ||
299 | functions appeared in BIND 4.9.4. | ||
181 | .Sh BUGS | 300 | .Sh BUGS |
182 | The value | 301 | The value |
183 | .Dv INADDR_NONE | 302 | .Dv INADDR_NONE |
@@ -187,11 +306,14 @@ cannot return that value without indicating failure. | |||
187 | The newer | 306 | The newer |
188 | .Fn inet_aton | 307 | .Fn inet_aton |
189 | function does not share this problem. | 308 | function does not share this problem. |
309 | .Pp | ||
190 | The problem of host byte ordering versus network byte ordering is | 310 | The problem of host byte ordering versus network byte ordering is |
191 | confusing. | 311 | confusing. |
312 | .Pp | ||
192 | The string returned by | 313 | The string returned by |
193 | .Fn inet_ntoa | 314 | .Fn inet_ntoa |
194 | resides in a static memory area. | 315 | resides in a static memory area. |
195 | .Pp | 316 | .Pp |
196 | Inet_addr should return a | 317 | .Fn inet_addr |
197 | .Fa struct in_addr . | 318 | should return a |
319 | .Fa "struct in_addr" . | ||
diff --git a/src/lib/libc/net/inet_addr.c b/src/lib/libc/net/inet_addr.c index b5b9d8302f..5e4dcdafb2 100644 --- a/src/lib/libc/net/inet_addr.c +++ b/src/lib/libc/net/inet_addr.c | |||
@@ -1,9 +1,11 @@ | |||
1 | /* $NetBSD: inet_addr.c,v 1.5 1995/02/25 06:20:41 cgd Exp $ */ | 1 | /* $OpenBSD: inet_addr.c,v 1.5 1997/04/05 21:13:10 millert Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * ++Copyright++ 1983, 1990, 1993 | ||
5 | * - | ||
4 | * Copyright (c) 1983, 1990, 1993 | 6 | * Copyright (c) 1983, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 7 | * The Regents of the University of California. All rights reserved. |
6 | * | 8 | * |
7 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions |
9 | * are met: | 11 | * are met: |
@@ -14,12 +16,12 @@ | |||
14 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
15 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. All advertising materials mentioning features or use of this software |
16 | * must display the following acknowledgement: | 18 | * must display the following acknowledgement: |
17 | * This product includes software developed by the University of | 19 | * This product includes software developed by the University of |
18 | * California, Berkeley and its contributors. | 20 | * California, Berkeley and its contributors. |
19 | * 4. Neither the name of the University nor the names of its contributors | 21 | * 4. Neither the name of the University nor the names of its contributors |
20 | * may be used to endorse or promote products derived from this software | 22 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. | 23 | * without specific prior written permission. |
22 | * | 24 | * |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -31,16 +33,38 @@ | |||
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
33 | * SUCH DAMAGE. | 35 | * SUCH DAMAGE. |
36 | * - | ||
37 | * Portions Copyright (c) 1993 by Digital Equipment Corporation. | ||
38 | * | ||
39 | * Permission to use, copy, modify, and distribute this software for any | ||
40 | * purpose with or without fee is hereby granted, provided that the above | ||
41 | * copyright notice and this permission notice appear in all copies, and that | ||
42 | * the name of Digital Equipment Corporation not be used in advertising or | ||
43 | * publicity pertaining to distribution of the document or software without | ||
44 | * specific, written prior permission. | ||
45 | * | ||
46 | * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL | ||
47 | * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES | ||
48 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT | ||
49 | * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
50 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
51 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
52 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
53 | * SOFTWARE. | ||
54 | * - | ||
55 | * --Copyright-- | ||
34 | */ | 56 | */ |
35 | 57 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 58 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 59 | #if 0 |
38 | static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; | 60 | static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; |
61 | static char rcsid[] = "$From: inet_addr.c,v 8.5 1996/08/05 08:31:35 vixie Exp $"; | ||
39 | #else | 62 | #else |
40 | static char rcsid[] = "$NetBSD: inet_addr.c,v 1.5 1995/02/25 06:20:41 cgd Exp $"; | 63 | static char rcsid[] = "$OpenBSD: inet_addr.c,v 1.5 1997/04/05 21:13:10 millert Exp $"; |
41 | #endif | 64 | #endif |
42 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
43 | 66 | ||
67 | #include <sys/types.h> | ||
44 | #include <sys/param.h> | 68 | #include <sys/param.h> |
45 | #include <netinet/in.h> | 69 | #include <netinet/in.h> |
46 | #include <arpa/inet.h> | 70 | #include <arpa/inet.h> |
@@ -50,7 +74,7 @@ static char rcsid[] = "$NetBSD: inet_addr.c,v 1.5 1995/02/25 06:20:41 cgd Exp $" | |||
50 | * Ascii internet address interpretation routine. | 74 | * Ascii internet address interpretation routine. |
51 | * The value returned is in network order. | 75 | * The value returned is in network order. |
52 | */ | 76 | */ |
53 | u_long | 77 | in_addr_t |
54 | inet_addr(cp) | 78 | inet_addr(cp) |
55 | register const char *cp; | 79 | register const char *cp; |
56 | { | 80 | { |
@@ -73,56 +97,58 @@ inet_aton(cp, addr) | |||
73 | register const char *cp; | 97 | register const char *cp; |
74 | struct in_addr *addr; | 98 | struct in_addr *addr; |
75 | { | 99 | { |
76 | register u_long val; | 100 | register in_addr_t val; |
77 | register int base, n; | 101 | register int base, n; |
78 | register char c; | 102 | register char c; |
79 | u_int parts[4]; | 103 | u_int parts[4]; |
80 | register u_int *pp = parts; | 104 | register u_int *pp = parts; |
81 | 105 | ||
106 | c = *cp; | ||
82 | for (;;) { | 107 | for (;;) { |
83 | /* | 108 | /* |
84 | * Collect number up to ``.''. | 109 | * Collect number up to ``.''. |
85 | * Values are specified as for C: | 110 | * Values are specified as for C: |
86 | * 0x=hex, 0=octal, other=decimal. | 111 | * 0x=hex, 0=octal, isdigit=decimal. |
87 | */ | 112 | */ |
113 | if (!isdigit(c)) | ||
114 | return (0); | ||
88 | val = 0; base = 10; | 115 | val = 0; base = 10; |
89 | if (*cp == '0') { | 116 | if (c == '0') { |
90 | if (*++cp == 'x' || *cp == 'X') | 117 | c = *++cp; |
91 | base = 16, cp++; | 118 | if (c == 'x' || c == 'X') |
119 | base = 16, c = *++cp; | ||
92 | else | 120 | else |
93 | base = 8; | 121 | base = 8; |
94 | } | 122 | } |
95 | while ((c = *cp) != '\0') { | 123 | for (;;) { |
96 | if (isascii(c) && isdigit(c)) { | 124 | if (isascii(c) && isdigit(c)) { |
97 | val = (val * base) + (c - '0'); | 125 | val = (val * base) + (c - '0'); |
98 | cp++; | 126 | c = *++cp; |
99 | continue; | 127 | } else if (base == 16 && isascii(c) && isxdigit(c)) { |
100 | } | 128 | val = (val << 4) | |
101 | if (base == 16 && isascii(c) && isxdigit(c)) { | ||
102 | val = (val << 4) + | ||
103 | (c + 10 - (islower(c) ? 'a' : 'A')); | 129 | (c + 10 - (islower(c) ? 'a' : 'A')); |
104 | cp++; | 130 | c = *++cp; |
105 | continue; | 131 | } else |
106 | } | 132 | break; |
107 | break; | ||
108 | } | 133 | } |
109 | if (*cp == '.') { | 134 | if (c == '.') { |
110 | /* | 135 | /* |
111 | * Internet format: | 136 | * Internet format: |
112 | * a.b.c.d | 137 | * a.b.c.d |
113 | * a.b.c (with c treated as 16-bits) | 138 | * a.b.c (with c treated as 16 bits) |
114 | * a.b (with b treated as 24 bits) | 139 | * a.b (with b treated as 24 bits) |
115 | */ | 140 | */ |
116 | if (pp >= parts + 3 || val > 0xff) | 141 | if (pp >= parts + 3) |
117 | return (0); | 142 | return (0); |
118 | *pp++ = val, cp++; | 143 | *pp++ = val; |
144 | c = *++cp; | ||
119 | } else | 145 | } else |
120 | break; | 146 | break; |
121 | } | 147 | } |
122 | /* | 148 | /* |
123 | * Check for trailing characters. | 149 | * Check for trailing characters. |
124 | */ | 150 | */ |
125 | if (*cp && (!isascii(*cp) || !isspace(*cp))) | 151 | if (c != '\0' && (!isascii(c) || !isspace(c))) |
126 | return (0); | 152 | return (0); |
127 | /* | 153 | /* |
128 | * Concoct the address according to | 154 | * Concoct the address according to |
@@ -131,6 +157,9 @@ inet_aton(cp, addr) | |||
131 | n = pp - parts + 1; | 157 | n = pp - parts + 1; |
132 | switch (n) { | 158 | switch (n) { |
133 | 159 | ||
160 | case 0: | ||
161 | return (0); /* initial nondigit */ | ||
162 | |||
134 | case 1: /* a -- 32 bits */ | 163 | case 1: /* a -- 32 bits */ |
135 | break; | 164 | break; |
136 | 165 | ||
diff --git a/src/lib/libc/net/inet_lnaof.c b/src/lib/libc/net/inet_lnaof.c index ce1257bf68..6aed18699b 100644 --- a/src/lib/libc/net/inet_lnaof.c +++ b/src/lib/libc/net/inet_lnaof.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: inet_lnaof.c,v 1.4 1995/02/25 06:20:42 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: inet_lnaof.c,v 1.3 1997/04/05 21:13:11 millert Exp $"; |
38 | static char sccsid[] = "@(#)inet_lnaof.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: inet_lnaof.c,v 1.4 1995/02/25 06:20:42 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/param.h> | 38 | #include <sys/param.h> |
@@ -50,11 +44,11 @@ static char rcsid[] = "$NetBSD: inet_lnaof.c,v 1.4 1995/02/25 06:20:42 cgd Exp $ | |||
50 | * internet address; handles class a/b/c network | 44 | * internet address; handles class a/b/c network |
51 | * number formats. | 45 | * number formats. |
52 | */ | 46 | */ |
53 | u_long | 47 | in_addr_t |
54 | inet_lnaof(in) | 48 | inet_lnaof(in) |
55 | struct in_addr in; | 49 | struct in_addr in; |
56 | { | 50 | { |
57 | register u_long i = ntohl(in.s_addr); | 51 | register in_addr_t i = ntohl(in.s_addr); |
58 | 52 | ||
59 | if (IN_CLASSA(i)) | 53 | if (IN_CLASSA(i)) |
60 | return ((i)&IN_CLASSA_HOST); | 54 | return ((i)&IN_CLASSA_HOST); |
diff --git a/src/lib/libc/net/inet_makeaddr.c b/src/lib/libc/net/inet_makeaddr.c index 84d366e03a..196a589e4c 100644 --- a/src/lib/libc/net/inet_makeaddr.c +++ b/src/lib/libc/net/inet_makeaddr.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: inet_makeaddr.c,v 1.4 1995/02/25 06:20:42 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: inet_makeaddr.c,v 1.3 1997/04/05 21:13:12 millert Exp $"; |
38 | static char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: inet_makeaddr.c,v 1.4 1995/02/25 06:20:42 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/param.h> | 38 | #include <sys/param.h> |
@@ -51,9 +45,9 @@ static char rcsid[] = "$NetBSD: inet_makeaddr.c,v 1.4 1995/02/25 06:20:42 cgd Ex | |||
51 | */ | 45 | */ |
52 | struct in_addr | 46 | struct in_addr |
53 | inet_makeaddr(net, host) | 47 | inet_makeaddr(net, host) |
54 | u_long net, host; | 48 | in_addr_t net, host; |
55 | { | 49 | { |
56 | u_long addr; | 50 | in_addr_t addr; |
57 | 51 | ||
58 | if (net < 128) | 52 | if (net < 128) |
59 | addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); | 53 | addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); |
diff --git a/src/lib/libc/net/inet_net.3 b/src/lib/libc/net/inet_net.3 new file mode 100644 index 0000000000..1a42aff6ea --- /dev/null +++ b/src/lib/libc/net/inet_net.3 | |||
@@ -0,0 +1,149 @@ | |||
1 | .\" $OpenBSD: inet_net.3,v 1.1 1997/06/23 03:37:26 millert Exp $ | ||
2 | .\" $NetBSD: inet_net.3,v 1.1 1997/06/18 02:25:27 lukem Exp $ | ||
3 | .\" | ||
4 | .\" Copyright (c) 1997 The NetBSD Foundation, Inc. | ||
5 | .\" All rights reserved. | ||
6 | .\" | ||
7 | .\" This code is derived from software contributed to The NetBSD Foundation | ||
8 | .\" by Luke Mewburn. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. All advertising materials mentioning features or use of this software | ||
19 | .\" must display the following acknowledgement: | ||
20 | .\" This product includes software developed by the NetBSD | ||
21 | .\" Foundation, Inc. and its contributors. | ||
22 | .\" 4. Neither the name of The NetBSD Foundation nor the names of its | ||
23 | .\" contributors may be used to endorse or promote products derived | ||
24 | .\" from this software without specific prior written permission. | ||
25 | .\" | ||
26 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
27 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
28 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
29 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE | ||
30 | .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
31 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
32 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
33 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
34 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
35 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
36 | .\" POSSIBILITY OF SUCH DAMAGE. | ||
37 | .\" | ||
38 | .Dd June 18, 1997 | ||
39 | .Dt INET_NET 3 | ||
40 | .Os | ||
41 | .Sh NAME | ||
42 | .Nm inet_net_ntop , | ||
43 | .Nm inet_net_pton | ||
44 | .Nd Internet network number manipulation routines | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <sys/socket.h> | ||
47 | .Fd #include <netinet/in.h> | ||
48 | .Fd #include <arpa/inet.h> | ||
49 | .Ft char * | ||
50 | .Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" | ||
51 | .Ft int | ||
52 | .Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" | ||
53 | .Sh DESCRIPTION | ||
54 | The | ||
55 | .Fn inet_net_ntop | ||
56 | function converts an Internet network number from network format (usually a | ||
57 | .Ft struct in_addr | ||
58 | or some other binary form, in network byte order) to CIDR presentation format | ||
59 | (suitable for external display purposes). | ||
60 | .Fa bits | ||
61 | is the number of bits in | ||
62 | .Fa src | ||
63 | that are the network number. | ||
64 | It returns NULL if a system error occurs (in which case, | ||
65 | .Va errno | ||
66 | will have been set), or it returns a pointer to the destination string. | ||
67 | .Pp | ||
68 | The | ||
69 | .Fn inet_net_pton | ||
70 | function converts a presentation format Internet network number (that is, | ||
71 | printable form as held in a character string) to network format (usually a | ||
72 | .Ft struct in_addr | ||
73 | or some other internal binary representation, in network byte order). | ||
74 | It returns the number of bits (either computed based on the class, or | ||
75 | specified with /CIDR), or -1 if a failure occurred | ||
76 | (in which case | ||
77 | .Va errno | ||
78 | will have been set. | ||
79 | It will be set to | ||
80 | .Er ENOENT | ||
81 | if the Internet network number was not valid). | ||
82 | .Pp | ||
83 | The currently supported value for | ||
84 | .Fa af | ||
85 | is: AF_INET. | ||
86 | .Fa size | ||
87 | is the size of the result buffer | ||
88 | .Fa dst . | ||
89 | .Pp | ||
90 | .Sh NETWORK NUMBERS (IP VERSION 4) | ||
91 | Internet network numbers may be specified in one of the following forms: | ||
92 | .Bd -literal -offset indent | ||
93 | a.b.c.d/bits | ||
94 | a.b.c.d | ||
95 | a.b.c | ||
96 | a.b | ||
97 | a | ||
98 | .Ed | ||
99 | .Pp | ||
100 | When four parts are specified, each is interpreted | ||
101 | as a byte of data and assigned, from left to right, | ||
102 | to the four bytes of an Internet network number. Note | ||
103 | that when an Internet network number is viewed as a 32-bit | ||
104 | integer quantity on a system that uses little-endian | ||
105 | byte order (such as the | ||
106 | .Tn Intel 386, 486 | ||
107 | and | ||
108 | .Tn Pentium | ||
109 | processors) the bytes referred to above appear as | ||
110 | .Dq Li d.c.b.a . | ||
111 | That is, little-endian bytes are ordered from right to left. | ||
112 | .Pp | ||
113 | When a three part number is specified, the last | ||
114 | part is interpreted as a 16-bit quantity and placed | ||
115 | in the right-most two bytes of the Internet network number. | ||
116 | This makes the three part number format convenient | ||
117 | for specifying Class B network numbers as | ||
118 | .Dq Li 128.net.host . | ||
119 | .Pp | ||
120 | When a two part number is supplied, the last part | ||
121 | is interpreted as a 24-bit quantity and placed in | ||
122 | the right most three bytes of the Internet network number. | ||
123 | This makes the two part number format convenient | ||
124 | for specifying Class A network numbers as | ||
125 | .Dq Li net.host . | ||
126 | .Pp | ||
127 | When only one part is given, the value is stored | ||
128 | directly in the Internet network number without any byte | ||
129 | rearrangement. | ||
130 | .Pp | ||
131 | All numbers supplied as | ||
132 | .Dq parts | ||
133 | in a | ||
134 | .Ql \&. | ||
135 | notation | ||
136 | may be decimal, octal, or hexadecimal, as specified | ||
137 | in the C language (i.e., a leading 0x or 0X implies | ||
138 | hexadecimal; otherwise, a leading 0 implies octal; | ||
139 | otherwise, the number is interpreted as decimal). | ||
140 | .Sh SEE ALSO | ||
141 | .Xr byteorder 3 , | ||
142 | .Xr inet 3 , | ||
143 | .Xr networks 5 | ||
144 | .Sh HISTORY | ||
145 | The | ||
146 | .Nm inet_net_ntop | ||
147 | and | ||
148 | .Nm inet_net_pton | ||
149 | functions first appeared in BIND 4.9.4. | ||
diff --git a/src/lib/libc/net/inet_net_ntop.c b/src/lib/libc/net/inet_net_ntop.c new file mode 100644 index 0000000000..943ec44550 --- /dev/null +++ b/src/lib/libc/net/inet_net_ntop.c | |||
@@ -0,0 +1,139 @@ | |||
1 | /* $OpenBSD: inet_net_ntop.c,v 1.1 1997/03/13 19:07:30 downsj Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1996 by Internet Software Consortium. | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
11 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
12 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
13 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
14 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
15 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
16 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
17 | * SOFTWARE. | ||
18 | */ | ||
19 | |||
20 | #if defined(LIBC_SCCS) && !defined(lint) | ||
21 | #if 0 | ||
22 | static const char rcsid[] = "$From: inet_net_ntop.c,v 8.2 1996/08/08 06:54:44 vixie Exp $"; | ||
23 | #else | ||
24 | static const char rcsid[] = "$OpenBSD: inet_net_ntop.c,v 1.1 1997/03/13 19:07:30 downsj Exp $"; | ||
25 | #endif | ||
26 | #endif | ||
27 | |||
28 | #include <sys/types.h> | ||
29 | #include <sys/socket.h> | ||
30 | #include <netinet/in.h> | ||
31 | #include <arpa/inet.h> | ||
32 | |||
33 | #include <errno.h> | ||
34 | #include <stdio.h> | ||
35 | #include <string.h> | ||
36 | #include <stdlib.h> | ||
37 | |||
38 | static char * inet_net_ntop_ipv4 __P((const u_char *src, int bits, | ||
39 | char *dst, size_t size)); | ||
40 | |||
41 | /* | ||
42 | * char * | ||
43 | * inet_net_ntop(af, src, bits, dst, size) | ||
44 | * convert network number from network to presentation format. | ||
45 | * generates CIDR style result always. | ||
46 | * return: | ||
47 | * pointer to dst, or NULL if an error occurred (check errno). | ||
48 | * author: | ||
49 | * Paul Vixie (ISC), July 1996 | ||
50 | */ | ||
51 | char * | ||
52 | inet_net_ntop(af, src, bits, dst, size) | ||
53 | int af; | ||
54 | const void *src; | ||
55 | int bits; | ||
56 | char *dst; | ||
57 | size_t size; | ||
58 | { | ||
59 | switch (af) { | ||
60 | case AF_INET: | ||
61 | return (inet_net_ntop_ipv4(src, bits, dst, size)); | ||
62 | default: | ||
63 | errno = EAFNOSUPPORT; | ||
64 | return (NULL); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | /* | ||
69 | * static char * | ||
70 | * inet_net_ntop_ipv4(src, bits, dst, size) | ||
71 | * convert IPv4 network number from network to presentation format. | ||
72 | * generates CIDR style result always. | ||
73 | * return: | ||
74 | * pointer to dst, or NULL if an error occurred (check errno). | ||
75 | * note: | ||
76 | * network byte order assumed. this means 192.5.5.240/28 has | ||
77 | * 0x11110000 in its fourth octet. | ||
78 | * author: | ||
79 | * Paul Vixie (ISC), July 1996 | ||
80 | */ | ||
81 | static char * | ||
82 | inet_net_ntop_ipv4(src, bits, dst, size) | ||
83 | const u_char *src; | ||
84 | int bits; | ||
85 | char *dst; | ||
86 | size_t size; | ||
87 | { | ||
88 | char *odst = dst; | ||
89 | char *t; | ||
90 | u_int m; | ||
91 | int b; | ||
92 | |||
93 | if (bits < 0 || bits > 32) { | ||
94 | errno = EINVAL; | ||
95 | return (NULL); | ||
96 | } | ||
97 | if (bits == 0) { | ||
98 | if (size < sizeof "0") | ||
99 | goto emsgsize; | ||
100 | *dst++ = '0'; | ||
101 | *dst = '\0'; | ||
102 | } | ||
103 | |||
104 | /* Format whole octets. */ | ||
105 | for (b = bits / 8; b > 0; b--) { | ||
106 | if (size < sizeof "255.") | ||
107 | goto emsgsize; | ||
108 | t = dst; | ||
109 | dst += sprintf(dst, "%u", *src++); | ||
110 | if (b > 1) { | ||
111 | *dst++ = '.'; | ||
112 | *dst = '\0'; | ||
113 | } | ||
114 | size -= (size_t)(dst - t); | ||
115 | } | ||
116 | |||
117 | /* Format partial octet. */ | ||
118 | b = bits % 8; | ||
119 | if (b > 0) { | ||
120 | if (size < sizeof ".255") | ||
121 | goto emsgsize; | ||
122 | t = dst; | ||
123 | if (dst != odst) | ||
124 | *dst++ = '.'; | ||
125 | m = ((1 << b) - 1) << (8 - b); | ||
126 | dst += sprintf(dst, "%u", *src & m); | ||
127 | size -= (size_t)(dst - t); | ||
128 | } | ||
129 | |||
130 | /* Format CIDR /width. */ | ||
131 | if (size < sizeof "/32") | ||
132 | goto emsgsize; | ||
133 | dst += sprintf(dst, "/%u", bits); | ||
134 | return (odst); | ||
135 | |||
136 | emsgsize: | ||
137 | errno = EMSGSIZE; | ||
138 | return (NULL); | ||
139 | } | ||
diff --git a/src/lib/libc/net/inet_net_pton.c b/src/lib/libc/net/inet_net_pton.c new file mode 100644 index 0000000000..b529e83664 --- /dev/null +++ b/src/lib/libc/net/inet_net_pton.c | |||
@@ -0,0 +1,207 @@ | |||
1 | /* $OpenBSD: inet_net_pton.c,v 1.1 1997/03/13 19:07:30 downsj Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1996 by Internet Software Consortium. | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
11 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
12 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
13 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
14 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
15 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
16 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
17 | * SOFTWARE. | ||
18 | */ | ||
19 | |||
20 | #if defined(LIBC_SCCS) && !defined(lint) | ||
21 | #if 0 | ||
22 | static const char rcsid[] = "$From: inet_net_pton.c,v 8.3 1996/11/11 06:36:52 vixie Exp $"; | ||
23 | #else | ||
24 | static const char rcsid[] = "$OpenBSD: inet_net_pton.c,v 1.1 1997/03/13 19:07:30 downsj Exp $"; | ||
25 | #endif | ||
26 | #endif | ||
27 | |||
28 | #include <sys/types.h> | ||
29 | #include <sys/socket.h> | ||
30 | #include <netinet/in.h> | ||
31 | #include <arpa/inet.h> | ||
32 | |||
33 | #include <assert.h> | ||
34 | #include <ctype.h> | ||
35 | #include <errno.h> | ||
36 | #include <stdio.h> | ||
37 | #include <string.h> | ||
38 | #include <stdlib.h> | ||
39 | |||
40 | static int inet_net_pton_ipv4 __P((const char *src, u_char *dst, | ||
41 | size_t size)); | ||
42 | |||
43 | /* | ||
44 | * static int | ||
45 | * inet_net_pton(af, src, dst, size) | ||
46 | * convert network number from presentation to network format. | ||
47 | * accepts hex octets, hex strings, decimal octets, and /CIDR. | ||
48 | * "size" is in bytes and describes "dst". | ||
49 | * return: | ||
50 | * number of bits, either imputed classfully or specified with /CIDR, | ||
51 | * or -1 if some failure occurred (check errno). ENOENT means it was | ||
52 | * not a valid network specification. | ||
53 | * author: | ||
54 | * Paul Vixie (ISC), June 1996 | ||
55 | */ | ||
56 | int | ||
57 | inet_net_pton(af, src, dst, size) | ||
58 | int af; | ||
59 | const char *src; | ||
60 | void *dst; | ||
61 | size_t size; | ||
62 | { | ||
63 | switch (af) { | ||
64 | case AF_INET: | ||
65 | return (inet_net_pton_ipv4(src, dst, size)); | ||
66 | default: | ||
67 | errno = EAFNOSUPPORT; | ||
68 | return (-1); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | /* | ||
73 | * static int | ||
74 | * inet_net_pton_ipv4(src, dst, size) | ||
75 | * convert IPv4 network number from presentation to network format. | ||
76 | * accepts hex octets, hex strings, decimal octets, and /CIDR. | ||
77 | * "size" is in bytes and describes "dst". | ||
78 | * return: | ||
79 | * number of bits, either imputed classfully or specified with /CIDR, | ||
80 | * or -1 if some failure occurred (check errno). ENOENT means it was | ||
81 | * not an IPv4 network specification. | ||
82 | * note: | ||
83 | * network byte order assumed. this means 192.5.5.240/28 has | ||
84 | * 0x11110000 in its fourth octet. | ||
85 | * author: | ||
86 | * Paul Vixie (ISC), June 1996 | ||
87 | */ | ||
88 | static int | ||
89 | inet_net_pton_ipv4(src, dst, size) | ||
90 | const char *src; | ||
91 | u_char *dst; | ||
92 | size_t size; | ||
93 | { | ||
94 | static const char | ||
95 | xdigits[] = "0123456789abcdef", | ||
96 | digits[] = "0123456789"; | ||
97 | int n, ch, tmp, dirty, bits; | ||
98 | const u_char *odst = dst; | ||
99 | |||
100 | ch = *src++; | ||
101 | if (ch == '0' && (src[0] == 'x' || src[0] == 'X') | ||
102 | && isascii(src[1]) && isxdigit(src[1])) { | ||
103 | /* Hexadecimal: Eat nybble string. */ | ||
104 | if (size <= 0) | ||
105 | goto emsgsize; | ||
106 | *dst = 0, dirty = 0; | ||
107 | src++; /* skip x or X. */ | ||
108 | while ((ch = *src++) != '\0' && | ||
109 | isascii(ch) && isxdigit(ch)) { | ||
110 | if (isupper(ch)) | ||
111 | ch = tolower(ch); | ||
112 | n = strchr(xdigits, ch) - xdigits; | ||
113 | assert(n >= 0 && n <= 15); | ||
114 | *dst |= n; | ||
115 | if (!dirty++) | ||
116 | *dst <<= 4; | ||
117 | else if (size-- > 0) | ||
118 | *++dst = 0, dirty = 0; | ||
119 | else | ||
120 | goto emsgsize; | ||
121 | } | ||
122 | if (dirty) | ||
123 | size--; | ||
124 | } else if (isascii(ch) && isdigit(ch)) { | ||
125 | /* Decimal: eat dotted digit string. */ | ||
126 | for (;;) { | ||
127 | tmp = 0; | ||
128 | do { | ||
129 | n = strchr(digits, ch) - digits; | ||
130 | assert(n >= 0 && n <= 9); | ||
131 | tmp *= 10; | ||
132 | tmp += n; | ||
133 | if (tmp > 255) | ||
134 | goto enoent; | ||
135 | } while ((ch = *src++) != '\0' && | ||
136 | isascii(ch) && isdigit(ch)); | ||
137 | if (size-- <= 0) | ||
138 | goto emsgsize; | ||
139 | *dst++ = (u_char) tmp; | ||
140 | if (ch == '\0' || ch == '/') | ||
141 | break; | ||
142 | if (ch != '.') | ||
143 | goto enoent; | ||
144 | ch = *src++; | ||
145 | if (!isascii(ch) || !isdigit(ch)) | ||
146 | goto enoent; | ||
147 | } | ||
148 | } else | ||
149 | goto enoent; | ||
150 | |||
151 | bits = -1; | ||
152 | if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) { | ||
153 | /* CIDR width specifier. Nothing can follow it. */ | ||
154 | ch = *src++; /* Skip over the /. */ | ||
155 | bits = 0; | ||
156 | do { | ||
157 | n = strchr(digits, ch) - digits; | ||
158 | assert(n >= 0 && n <= 9); | ||
159 | bits *= 10; | ||
160 | bits += n; | ||
161 | } while ((ch = *src++) != '\0' && | ||
162 | isascii(ch) && isdigit(ch)); | ||
163 | if (ch != '\0') | ||
164 | goto enoent; | ||
165 | if (bits > 32) | ||
166 | goto emsgsize; | ||
167 | } | ||
168 | |||
169 | /* Firey death and destruction unless we prefetched EOS. */ | ||
170 | if (ch != '\0') | ||
171 | goto enoent; | ||
172 | |||
173 | /* If nothing was written to the destination, we found no address. */ | ||
174 | if (dst == odst) | ||
175 | goto enoent; | ||
176 | /* If no CIDR spec was given, infer width from net class. */ | ||
177 | if (bits == -1) { | ||
178 | if (*odst >= 240) /* Class E */ | ||
179 | bits = 32; | ||
180 | else if (*odst >= 224) /* Class D */ | ||
181 | bits = 4; | ||
182 | else if (*odst >= 192) /* Class C */ | ||
183 | bits = 24; | ||
184 | else if (*odst >= 128) /* Class B */ | ||
185 | bits = 16; | ||
186 | else /* Class A */ | ||
187 | bits = 8; | ||
188 | /* If imputed mask is narrower than specified octets, widen. */ | ||
189 | if (bits >= 8 && bits < ((dst - odst) * 8)) | ||
190 | bits = (dst - odst) * 8; | ||
191 | } | ||
192 | /* Extend network to cover the actual mask. */ | ||
193 | while (bits > ((dst - odst) * 8)) { | ||
194 | if (size-- <= 0) | ||
195 | goto emsgsize; | ||
196 | *dst++ = '\0'; | ||
197 | } | ||
198 | return (bits); | ||
199 | |||
200 | enoent: | ||
201 | errno = ENOENT; | ||
202 | return (-1); | ||
203 | |||
204 | emsgsize: | ||
205 | errno = EMSGSIZE; | ||
206 | return (-1); | ||
207 | } | ||
diff --git a/src/lib/libc/net/inet_neta.c b/src/lib/libc/net/inet_neta.c new file mode 100644 index 0000000000..ffcddd8d91 --- /dev/null +++ b/src/lib/libc/net/inet_neta.c | |||
@@ -0,0 +1,83 @@ | |||
1 | /* $OpenBSD: inet_neta.c,v 1.2 1997/04/05 21:13:12 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1996 by Internet Software Consortium. | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
11 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
12 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
13 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
14 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
15 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
16 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
17 | * SOFTWARE. | ||
18 | */ | ||
19 | |||
20 | #if defined(LIBC_SCCS) && !defined(lint) | ||
21 | #if 0 | ||
22 | static const char rcsid[] = "$Id: inet_neta.c,v 1.2 1997/04/05 21:13:12 millert Exp $"; | ||
23 | #else | ||
24 | static const char rcsid[] = "$OpenBSD: inet_neta.c,v 1.2 1997/04/05 21:13:12 millert Exp $"; | ||
25 | #endif | ||
26 | #endif | ||
27 | |||
28 | #include <sys/types.h> | ||
29 | #include <sys/socket.h> | ||
30 | #include <netinet/in.h> | ||
31 | #include <arpa/inet.h> | ||
32 | |||
33 | #include <errno.h> | ||
34 | #include <stdio.h> | ||
35 | #include <string.h> | ||
36 | |||
37 | /* | ||
38 | * char * | ||
39 | * inet_neta(src, dst, size) | ||
40 | * format an in_addr_t network number into presentation format. | ||
41 | * return: | ||
42 | * pointer to dst, or NULL if an error occurred (check errno). | ||
43 | * note: | ||
44 | * format of ``src'' is as for inet_network(). | ||
45 | * author: | ||
46 | * Paul Vixie (ISC), July 1996 | ||
47 | */ | ||
48 | char * | ||
49 | inet_neta(src, dst, size) | ||
50 | in_addr_t src; | ||
51 | char *dst; | ||
52 | size_t size; | ||
53 | { | ||
54 | char *odst = dst; | ||
55 | char *tp; | ||
56 | |||
57 | while (src & 0xffffffff) { | ||
58 | u_char b = (src & 0xff000000) >> 24; | ||
59 | |||
60 | src <<= 8; | ||
61 | if (b) { | ||
62 | if (size < sizeof "255.") | ||
63 | goto emsgsize; | ||
64 | tp = dst; | ||
65 | dst += sprintf(dst, "%u", b); | ||
66 | if (src != 0L) { | ||
67 | *dst++ = '.'; | ||
68 | *dst = '\0'; | ||
69 | } | ||
70 | size -= (size_t)(dst - tp); | ||
71 | } | ||
72 | } | ||
73 | if (dst == odst) { | ||
74 | if (size < sizeof "0.0.0.0") | ||
75 | goto emsgsize; | ||
76 | strcpy(dst, "0.0.0.0"); | ||
77 | } | ||
78 | return (odst); | ||
79 | |||
80 | emsgsize: | ||
81 | errno = EMSGSIZE; | ||
82 | return (NULL); | ||
83 | } | ||
diff --git a/src/lib/libc/net/inet_netof.c b/src/lib/libc/net/inet_netof.c index 02f52ca318..f3b9c01697 100644 --- a/src/lib/libc/net/inet_netof.c +++ b/src/lib/libc/net/inet_netof.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: inet_netof.c,v 1.4 1995/02/25 06:20:43 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: inet_netof.c,v 1.3 1997/04/05 21:13:13 millert Exp $"; |
38 | static char sccsid[] = "@(#)inet_netof.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: inet_netof.c,v 1.4 1995/02/25 06:20:43 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/param.h> | 38 | #include <sys/param.h> |
@@ -49,11 +43,11 @@ static char rcsid[] = "$NetBSD: inet_netof.c,v 1.4 1995/02/25 06:20:43 cgd Exp $ | |||
49 | * Return the network number from an internet | 43 | * Return the network number from an internet |
50 | * address; handles class a/b/c network #'s. | 44 | * address; handles class a/b/c network #'s. |
51 | */ | 45 | */ |
52 | u_long | 46 | in_addr_t |
53 | inet_netof(in) | 47 | inet_netof(in) |
54 | struct in_addr in; | 48 | struct in_addr in; |
55 | { | 49 | { |
56 | register u_long i = ntohl(in.s_addr); | 50 | register in_addr_t i = ntohl(in.s_addr); |
57 | 51 | ||
58 | if (IN_CLASSA(i)) | 52 | if (IN_CLASSA(i)) |
59 | return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); | 53 | return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); |
diff --git a/src/lib/libc/net/inet_network.c b/src/lib/libc/net/inet_network.c index 35105fa75a..8a9a555d62 100644 --- a/src/lib/libc/net/inet_network.c +++ b/src/lib/libc/net/inet_network.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: inet_network.c,v 1.4 1995/02/25 06:20:45 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: inet_network.c,v 1.7 1997/07/09 01:08:37 millert Exp $"; |
38 | static char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: inet_network.c,v 1.4 1995/02/25 06:20:45 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/types.h> | 38 | #include <sys/types.h> |
@@ -51,13 +45,13 @@ static char rcsid[] = "$NetBSD: inet_network.c,v 1.4 1995/02/25 06:20:45 cgd Exp | |||
51 | * The library routines call this routine to interpret | 45 | * The library routines call this routine to interpret |
52 | * network numbers. | 46 | * network numbers. |
53 | */ | 47 | */ |
54 | u_long | 48 | in_addr_t |
55 | inet_network(cp) | 49 | inet_network(cp) |
56 | register const char *cp; | 50 | register const char *cp; |
57 | { | 51 | { |
58 | register u_long val, base, n; | 52 | register in_addr_t val, base, n; |
59 | register char c; | 53 | register char c; |
60 | u_long parts[4], *pp = parts; | 54 | in_addr_t parts[4], *pp = parts; |
61 | register int i; | 55 | register int i; |
62 | 56 | ||
63 | again: | 57 | again: |
@@ -66,7 +60,7 @@ again: | |||
66 | base = 8, cp++; | 60 | base = 8, cp++; |
67 | if (*cp == 'x' || *cp == 'X') | 61 | if (*cp == 'x' || *cp == 'X') |
68 | base = 16, cp++; | 62 | base = 16, cp++; |
69 | while (c = *cp) { | 63 | while ((c = *cp)) { |
70 | if (isdigit(c)) { | 64 | if (isdigit(c)) { |
71 | val = (val * base) + (c - '0'); | 65 | val = (val * base) + (c - '0'); |
72 | cp++; | 66 | cp++; |
@@ -80,7 +74,7 @@ again: | |||
80 | break; | 74 | break; |
81 | } | 75 | } |
82 | if (*cp == '.') { | 76 | if (*cp == '.') { |
83 | if (pp >= parts + 4) | 77 | if (pp >= parts + 3) |
84 | return (INADDR_NONE); | 78 | return (INADDR_NONE); |
85 | *pp++ = val, cp++; | 79 | *pp++ = val, cp++; |
86 | goto again; | 80 | goto again; |
@@ -89,11 +83,10 @@ again: | |||
89 | return (INADDR_NONE); | 83 | return (INADDR_NONE); |
90 | *pp++ = val; | 84 | *pp++ = val; |
91 | n = pp - parts; | 85 | n = pp - parts; |
92 | if (n > 4) | 86 | for (val = 0, i = 0; i < 4; i++) { |
93 | return (INADDR_NONE); | ||
94 | for (val = 0, i = 0; i < n; i++) { | ||
95 | val <<= 8; | 87 | val <<= 8; |
96 | val |= parts[i] & 0xff; | 88 | if (i < n) |
89 | val |= parts[i] & 0xff; | ||
97 | } | 90 | } |
98 | return (val); | 91 | return (val); |
99 | } | 92 | } |
diff --git a/src/lib/libc/net/inet_ntoa.c b/src/lib/libc/net/inet_ntoa.c index 2da0ab00ff..148732ba5a 100644 --- a/src/lib/libc/net/inet_ntoa.c +++ b/src/lib/libc/net/inet_ntoa.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: inet_ntoa.c,v 1.4 1995/02/25 06:20:46 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: inet_ntoa.c,v 1.2 1996/08/19 08:29:16 tholo Exp $"; |
38 | static char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: inet_ntoa.c,v 1.4 1995/02/25 06:20:46 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | /* | 38 | /* |
diff --git a/src/lib/libc/net/inet_ntop.c b/src/lib/libc/net/inet_ntop.c new file mode 100644 index 0000000000..64d0d13768 --- /dev/null +++ b/src/lib/libc/net/inet_ntop.c | |||
@@ -0,0 +1,194 @@ | |||
1 | /* $OpenBSD: inet_ntop.c,v 1.1 1997/03/13 19:07:32 downsj Exp $ */ | ||
2 | |||
3 | /* Copyright (c) 1996 by Internet Software Consortium. | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
10 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
11 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
12 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
13 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
14 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
15 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #if defined(LIBC_SCCS) && !defined(lint) | ||
20 | #if 0 | ||
21 | static char rcsid[] = "$From: inet_ntop.c,v 8.7 1996/08/05 08:41:18 vixie Exp $"; | ||
22 | #else | ||
23 | static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.1 1997/03/13 19:07:32 downsj Exp $"; | ||
24 | #endif | ||
25 | #endif /* LIBC_SCCS and not lint */ | ||
26 | |||
27 | #include <sys/param.h> | ||
28 | #include <sys/types.h> | ||
29 | #include <sys/socket.h> | ||
30 | #include <netinet/in.h> | ||
31 | #include <arpa/inet.h> | ||
32 | #include <arpa/nameser.h> | ||
33 | #include <string.h> | ||
34 | #include <errno.h> | ||
35 | #include <stdio.h> | ||
36 | |||
37 | /* | ||
38 | * WARNING: Don't even consider trying to compile this on a system where | ||
39 | * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. | ||
40 | */ | ||
41 | |||
42 | static const char *inet_ntop4 __P((const u_char *src, char *dst, size_t size)); | ||
43 | static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size)); | ||
44 | |||
45 | /* char * | ||
46 | * inet_ntop(af, src, dst, size) | ||
47 | * convert a network format address to presentation format. | ||
48 | * return: | ||
49 | * pointer to presentation format address (`dst'), or NULL (see errno). | ||
50 | * author: | ||
51 | * Paul Vixie, 1996. | ||
52 | */ | ||
53 | const char * | ||
54 | inet_ntop(af, src, dst, size) | ||
55 | int af; | ||
56 | const void *src; | ||
57 | char *dst; | ||
58 | size_t size; | ||
59 | { | ||
60 | switch (af) { | ||
61 | case AF_INET: | ||
62 | return (inet_ntop4(src, dst, size)); | ||
63 | case AF_INET6: | ||
64 | return (inet_ntop6(src, dst, size)); | ||
65 | default: | ||
66 | errno = EAFNOSUPPORT; | ||
67 | return (NULL); | ||
68 | } | ||
69 | /* NOTREACHED */ | ||
70 | } | ||
71 | |||
72 | /* const char * | ||
73 | * inet_ntop4(src, dst, size) | ||
74 | * format an IPv4 address, more or less like inet_ntoa() | ||
75 | * return: | ||
76 | * `dst' (as a const) | ||
77 | * notes: | ||
78 | * (1) uses no statics | ||
79 | * (2) takes a u_char* not an in_addr as input | ||
80 | * author: | ||
81 | * Paul Vixie, 1996. | ||
82 | */ | ||
83 | static const char * | ||
84 | inet_ntop4(src, dst, size) | ||
85 | const u_char *src; | ||
86 | char *dst; | ||
87 | size_t size; | ||
88 | { | ||
89 | static const char fmt[] = "%u.%u.%u.%u"; | ||
90 | char tmp[sizeof "255.255.255.255"]; | ||
91 | |||
92 | if (sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) > size) { | ||
93 | errno = ENOSPC; | ||
94 | return (NULL); | ||
95 | } | ||
96 | strcpy(dst, tmp); | ||
97 | return (dst); | ||
98 | } | ||
99 | |||
100 | /* const char * | ||
101 | * inet_ntop6(src, dst, size) | ||
102 | * convert IPv6 binary address into presentation (printable) format | ||
103 | * author: | ||
104 | * Paul Vixie, 1996. | ||
105 | */ | ||
106 | static const char * | ||
107 | inet_ntop6(src, dst, size) | ||
108 | const u_char *src; | ||
109 | char *dst; | ||
110 | size_t size; | ||
111 | { | ||
112 | /* | ||
113 | * Note that int32_t and int16_t need only be "at least" large enough | ||
114 | * to contain a value of the specified size. On some systems, like | ||
115 | * Crays, there is no such thing as an integer variable with 16 bits. | ||
116 | * Keep this in mind if you think this function should have been coded | ||
117 | * to use pointer overlays. All the world's not a VAX. | ||
118 | */ | ||
119 | char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; | ||
120 | struct { int base, len; } best, cur; | ||
121 | u_int words[IN6ADDRSZ / INT16SZ]; | ||
122 | int i; | ||
123 | |||
124 | /* | ||
125 | * Preprocess: | ||
126 | * Copy the input (bytewise) array into a wordwise array. | ||
127 | * Find the longest run of 0x00's in src[] for :: shorthanding. | ||
128 | */ | ||
129 | memset(words, '\0', sizeof words); | ||
130 | for (i = 0; i < IN6ADDRSZ; i++) | ||
131 | words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); | ||
132 | best.base = -1; | ||
133 | cur.base = -1; | ||
134 | for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { | ||
135 | if (words[i] == 0) { | ||
136 | if (cur.base == -1) | ||
137 | cur.base = i, cur.len = 1; | ||
138 | else | ||
139 | cur.len++; | ||
140 | } else { | ||
141 | if (cur.base != -1) { | ||
142 | if (best.base == -1 || cur.len > best.len) | ||
143 | best = cur; | ||
144 | cur.base = -1; | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | if (cur.base != -1) { | ||
149 | if (best.base == -1 || cur.len > best.len) | ||
150 | best = cur; | ||
151 | } | ||
152 | if (best.base != -1 && best.len < 2) | ||
153 | best.base = -1; | ||
154 | |||
155 | /* | ||
156 | * Format the result. | ||
157 | */ | ||
158 | tp = tmp; | ||
159 | for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { | ||
160 | /* Are we inside the best run of 0x00's? */ | ||
161 | if (best.base != -1 && i >= best.base && | ||
162 | i < (best.base + best.len)) { | ||
163 | if (i == best.base) | ||
164 | *tp++ = ':'; | ||
165 | continue; | ||
166 | } | ||
167 | /* Are we following an initial run of 0x00s or any real hex? */ | ||
168 | if (i != 0) | ||
169 | *tp++ = ':'; | ||
170 | /* Is this address an encapsulated IPv4? */ | ||
171 | if (i == 6 && best.base == 0 && | ||
172 | (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { | ||
173 | if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) | ||
174 | return (NULL); | ||
175 | tp += strlen(tp); | ||
176 | break; | ||
177 | } | ||
178 | tp += sprintf(tp, "%x", words[i]); | ||
179 | } | ||
180 | /* Was it a trailing run of 0x00's? */ | ||
181 | if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) | ||
182 | *tp++ = ':'; | ||
183 | *tp++ = '\0'; | ||
184 | |||
185 | /* | ||
186 | * Check for overflow, copy, and we're done. | ||
187 | */ | ||
188 | if ((size_t)(tp - tmp) > size) { | ||
189 | errno = ENOSPC; | ||
190 | return (NULL); | ||
191 | } | ||
192 | strcpy(dst, tmp); | ||
193 | return (dst); | ||
194 | } | ||
diff --git a/src/lib/libc/net/inet_pton.c b/src/lib/libc/net/inet_pton.c new file mode 100644 index 0000000000..46b4b24819 --- /dev/null +++ b/src/lib/libc/net/inet_pton.c | |||
@@ -0,0 +1,220 @@ | |||
1 | /* $OpenBSD: inet_pton.c,v 1.2 1997/04/13 05:08:24 deraadt Exp $ */ | ||
2 | |||
3 | /* Copyright (c) 1996 by Internet Software Consortium. | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
10 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
11 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
12 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
13 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
14 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
15 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #if defined(LIBC_SCCS) && !defined(lint) | ||
20 | #if 0 | ||
21 | static char rcsid[] = "$From: inet_pton.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; | ||
22 | #else | ||
23 | static char rcsid[] = "$OpenBSD: inet_pton.c,v 1.2 1997/04/13 05:08:24 deraadt Exp $"; | ||
24 | #endif | ||
25 | #endif /* LIBC_SCCS and not lint */ | ||
26 | |||
27 | #include <sys/param.h> | ||
28 | #include <sys/types.h> | ||
29 | #include <sys/socket.h> | ||
30 | #include <netinet/in.h> | ||
31 | #include <arpa/inet.h> | ||
32 | #include <arpa/nameser.h> | ||
33 | #include <string.h> | ||
34 | #include <errno.h> | ||
35 | |||
36 | /* | ||
37 | * WARNING: Don't even consider trying to compile this on a system where | ||
38 | * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. | ||
39 | */ | ||
40 | |||
41 | static int inet_pton4 __P((const char *src, u_char *dst)); | ||
42 | static int inet_pton6 __P((const char *src, u_char *dst)); | ||
43 | |||
44 | /* int | ||
45 | * inet_pton(af, src, dst) | ||
46 | * convert from presentation format (which usually means ASCII printable) | ||
47 | * to network format (which is usually some kind of binary format). | ||
48 | * return: | ||
49 | * 1 if the address was valid for the specified address family | ||
50 | * 0 if the address wasn't valid (`dst' is untouched in this case) | ||
51 | * -1 if some other error occurred (`dst' is untouched in this case, too) | ||
52 | * author: | ||
53 | * Paul Vixie, 1996. | ||
54 | */ | ||
55 | int | ||
56 | inet_pton(af, src, dst) | ||
57 | int af; | ||
58 | const char *src; | ||
59 | void *dst; | ||
60 | { | ||
61 | switch (af) { | ||
62 | case AF_INET: | ||
63 | return (inet_pton4(src, dst)); | ||
64 | case AF_INET6: | ||
65 | return (inet_pton6(src, dst)); | ||
66 | default: | ||
67 | errno = EAFNOSUPPORT; | ||
68 | return (-1); | ||
69 | } | ||
70 | /* NOTREACHED */ | ||
71 | } | ||
72 | |||
73 | /* int | ||
74 | * inet_pton4(src, dst) | ||
75 | * like inet_aton() but without all the hexadecimal and shorthand. | ||
76 | * return: | ||
77 | * 1 if `src' is a valid dotted quad, else 0. | ||
78 | * notice: | ||
79 | * does not touch `dst' unless it's returning 1. | ||
80 | * author: | ||
81 | * Paul Vixie, 1996. | ||
82 | */ | ||
83 | static int | ||
84 | inet_pton4(src, dst) | ||
85 | const char *src; | ||
86 | u_char *dst; | ||
87 | { | ||
88 | static const char digits[] = "0123456789"; | ||
89 | int saw_digit, octets, ch; | ||
90 | u_char tmp[INADDRSZ], *tp; | ||
91 | |||
92 | saw_digit = 0; | ||
93 | octets = 0; | ||
94 | *(tp = tmp) = 0; | ||
95 | while ((ch = *src++) != '\0') { | ||
96 | const char *pch; | ||
97 | |||
98 | if ((pch = strchr(digits, ch)) != NULL) { | ||
99 | u_int new = *tp * 10 + (pch - digits); | ||
100 | |||
101 | if (new > 255) | ||
102 | return (0); | ||
103 | if (! saw_digit) { | ||
104 | if (++octets > 4) | ||
105 | return (0); | ||
106 | saw_digit = 1; | ||
107 | } | ||
108 | *tp = new; | ||
109 | } else if (ch == '.' && saw_digit) { | ||
110 | if (octets == 4) | ||
111 | return (0); | ||
112 | *++tp = 0; | ||
113 | saw_digit = 0; | ||
114 | } else | ||
115 | return (0); | ||
116 | } | ||
117 | if (octets < 4) | ||
118 | return (0); | ||
119 | |||
120 | memcpy(dst, tmp, INADDRSZ); | ||
121 | return (1); | ||
122 | } | ||
123 | |||
124 | /* int | ||
125 | * inet_pton6(src, dst) | ||
126 | * convert presentation level address to network order binary form. | ||
127 | * return: | ||
128 | * 1 if `src' is a valid [RFC1884 2.2] address, else 0. | ||
129 | * notice: | ||
130 | * (1) does not touch `dst' unless it's returning 1. | ||
131 | * (2) :: in a full address is silently ignored. | ||
132 | * credit: | ||
133 | * inspired by Mark Andrews. | ||
134 | * author: | ||
135 | * Paul Vixie, 1996. | ||
136 | */ | ||
137 | static int | ||
138 | inet_pton6(src, dst) | ||
139 | const char *src; | ||
140 | u_char *dst; | ||
141 | { | ||
142 | static const char xdigits_l[] = "0123456789abcdef", | ||
143 | xdigits_u[] = "0123456789ABCDEF"; | ||
144 | u_char tmp[IN6ADDRSZ], *tp, *endp, *colonp; | ||
145 | const char *xdigits, *curtok; | ||
146 | int ch, saw_xdigit; | ||
147 | u_int val; | ||
148 | |||
149 | memset((tp = tmp), '\0', IN6ADDRSZ); | ||
150 | endp = tp + IN6ADDRSZ; | ||
151 | colonp = NULL; | ||
152 | /* Leading :: requires some special handling. */ | ||
153 | if (*src == ':') | ||
154 | if (*++src != ':') | ||
155 | return (0); | ||
156 | curtok = src; | ||
157 | saw_xdigit = 0; | ||
158 | val = 0; | ||
159 | while ((ch = *src++) != '\0') { | ||
160 | const char *pch; | ||
161 | |||
162 | if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) | ||
163 | pch = strchr((xdigits = xdigits_u), ch); | ||
164 | if (pch != NULL) { | ||
165 | val <<= 4; | ||
166 | val |= (pch - xdigits); | ||
167 | if (val > 0xffff) | ||
168 | return (0); | ||
169 | saw_xdigit = 1; | ||
170 | continue; | ||
171 | } | ||
172 | if (ch == ':') { | ||
173 | curtok = src; | ||
174 | if (!saw_xdigit) { | ||
175 | if (colonp) | ||
176 | return (0); | ||
177 | colonp = tp; | ||
178 | continue; | ||
179 | } | ||
180 | if (tp + INT16SZ > endp) | ||
181 | return (0); | ||
182 | *tp++ = (u_char) (val >> 8) & 0xff; | ||
183 | *tp++ = (u_char) val & 0xff; | ||
184 | saw_xdigit = 0; | ||
185 | val = 0; | ||
186 | continue; | ||
187 | } | ||
188 | if (ch == '.' && ((tp + INADDRSZ) <= endp) && | ||
189 | inet_pton4(curtok, tp) > 0) { | ||
190 | tp += INADDRSZ; | ||
191 | saw_xdigit = 0; | ||
192 | break; /* '\0' was seen by inet_pton4(). */ | ||
193 | } | ||
194 | return (0); | ||
195 | } | ||
196 | if (saw_xdigit) { | ||
197 | if (tp + INT16SZ > endp) | ||
198 | return (0); | ||
199 | *tp++ = (u_char) (val >> 8) & 0xff; | ||
200 | *tp++ = (u_char) val & 0xff; | ||
201 | } | ||
202 | if (colonp != NULL) { | ||
203 | /* | ||
204 | * Since some memmove()'s erroneously fail to handle | ||
205 | * overlapping regions, we'll do the shift by hand. | ||
206 | */ | ||
207 | const int n = tp - colonp; | ||
208 | int i; | ||
209 | |||
210 | for (i = 1; i <= n; i++) { | ||
211 | endp[- i] = colonp[n - i]; | ||
212 | colonp[n - i] = 0; | ||
213 | } | ||
214 | tp = endp; | ||
215 | } | ||
216 | if (tp != endp) | ||
217 | return (0); | ||
218 | memcpy(dst, tmp, IN6ADDRSZ); | ||
219 | return (1); | ||
220 | } | ||
diff --git a/src/lib/libc/net/ipx.3 b/src/lib/libc/net/ipx.3 new file mode 100644 index 0000000000..073be74807 --- /dev/null +++ b/src/lib/libc/net/ipx.3 | |||
@@ -0,0 +1,126 @@ | |||
1 | .\" $OpenBSD: ipx.3,v 1.3 1997/09/09 11:45:17 kstailey Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1986, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
5 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | ||
7 | .\" modification, are permitted provided that the following conditions | ||
8 | .\" are met: | ||
9 | .\" 1. Redistributions of source code must retain the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer. | ||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer in the | ||
13 | .\" documentation and/or other materials provided with the distribution. | ||
14 | .\" 3. All advertising materials mentioning features or use of this software | ||
15 | .\" must display the following acknowledgement: | ||
16 | .\" This product includes software developed by the University of | ||
17 | .\" California, Berkeley and its contributors. | ||
18 | .\" 4. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd June 4, 1993 | ||
35 | .Dt IPX 3 | ||
36 | .Os OpenBSD 1.2 | ||
37 | .Sh NAME | ||
38 | .Nm ipx_addr , | ||
39 | .Nm ipx_ntoa | ||
40 | .Nd IPX address conversion routines | ||
41 | .Sh SYNOPSIS | ||
42 | .Fd #include <sys/types.h> | ||
43 | .Fd #include <netipx/ipx.h> | ||
44 | .Ft struct ipx_addr | ||
45 | .Fn ipx_addr "char *cp" | ||
46 | .Ft char * | ||
47 | .Fn ipx_ntoa "struct ipx_addr ipx" | ||
48 | .Sh DESCRIPTION | ||
49 | The routine | ||
50 | .Fn ipx_addr | ||
51 | interprets character strings representing | ||
52 | .Tn IPX | ||
53 | addresses, returning binary information suitable | ||
54 | for use in system calls. | ||
55 | The routine | ||
56 | .Fn ipx_ntoa | ||
57 | takes | ||
58 | .Tn IPX | ||
59 | addresses and returns | ||
60 | .Tn ASCII | ||
61 | strings representing the address in a | ||
62 | notation in common use: | ||
63 | .Bd -filled -offset indent | ||
64 | <network number>.<host number>.<port number> | ||
65 | .Ed | ||
66 | .Pp | ||
67 | Trailing zero fields are suppressed, and each number is printed in hexadecimal, | ||
68 | in a format suitable for input to | ||
69 | .Fn ipx_addr . | ||
70 | Any fields lacking super-decimal digits will have a | ||
71 | trailing | ||
72 | .Ql H | ||
73 | appended. | ||
74 | .Pp | ||
75 | An effort has been made to insure that | ||
76 | .Fn ipx_addr | ||
77 | be compatible with most formats in common use. | ||
78 | It will first separate an address into 1 to 3 fields using a single delimiter | ||
79 | chosen from | ||
80 | period | ||
81 | .Ql \&. , | ||
82 | colon | ||
83 | .Ql \&: | ||
84 | or pound-sign | ||
85 | .Ql \&# . | ||
86 | Each field is then examined for byte separators (colon or period). | ||
87 | If there are byte separators, each subfield separated is taken to be | ||
88 | a small hexadecimal number, and the entirety is taken as a network-byte-ordered | ||
89 | quantity to be zero extended in the high-network-order bytes. | ||
90 | Next, the field is inspected for hyphens, in which case | ||
91 | the field is assumed to be a number in decimal notation | ||
92 | with hyphens separating the millenia. | ||
93 | Next, the field is assumed to be a number: | ||
94 | It is interpreted | ||
95 | as hexadecimal if there is a leading | ||
96 | .Ql 0x | ||
97 | (as in C), | ||
98 | a trailing | ||
99 | .Ql H | ||
100 | (as in Mesa), or there are any super-decimal digits present. | ||
101 | It is interpreted as octal is there is a leading | ||
102 | .Ql 0 | ||
103 | and there are no super-octal digits. | ||
104 | Otherwise, it is converted as a decimal number. | ||
105 | .Sh RETURN VALUES | ||
106 | None. (See | ||
107 | .Sx BUGS . ) | ||
108 | .Sh SEE ALSO | ||
109 | .Xr ns 4 , | ||
110 | .Xr hosts 5 , | ||
111 | .Xr networks 5 | ||
112 | .Sh HISTORY | ||
113 | The precursor | ||
114 | .Fn ns_addr | ||
115 | and | ||
116 | .Fn ns_ntoa | ||
117 | functions appeared in | ||
118 | .Bx 4.3 . | ||
119 | .Sh BUGS | ||
120 | The string returned by | ||
121 | .Fn ipx_ntoa | ||
122 | resides in a static memory area. | ||
123 | The function | ||
124 | .Fn ipx_addr | ||
125 | should diagnose improperly formed input, and there should be an unambiguous | ||
126 | way to recognize this. | ||
diff --git a/src/lib/libc/net/ipx_addr.c b/src/lib/libc/net/ipx_addr.c new file mode 100644 index 0000000000..a76e03e913 --- /dev/null +++ b/src/lib/libc/net/ipx_addr.c | |||
@@ -0,0 +1,229 @@ | |||
1 | /* | ||
2 | * Copyright (c) 1986, 1993 | ||
3 | * The Regents of the University of California. All rights reserved. | ||
4 | * | ||
5 | * This code is derived from software contributed to Berkeley by | ||
6 | * J.Q. Johnson. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * 3. All advertising materials mentioning features or use of this software | ||
17 | * must display the following acknowledgement: | ||
18 | * This product includes software developed by the University of | ||
19 | * California, Berkeley and its contributors. | ||
20 | * 4. Neither the name of the University nor the names of its contributors | ||
21 | * may be used to endorse or promote products derived from this software | ||
22 | * without specific prior written permission. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
34 | * SUCH DAMAGE. | ||
35 | * | ||
36 | * from @(#)ipx_addr.c | ||
37 | */ | ||
38 | |||
39 | #if defined(LIBC_SCCS) && !defined(lint) | ||
40 | static char rcsid[] = "$OpenBSD: ipx_addr.c,v 1.3 1997/07/09 01:08:39 millert Exp $"; | ||
41 | #endif /* LIBC_SCCS and not lint */ | ||
42 | |||
43 | #include <sys/param.h> | ||
44 | #include <netipx/ipx.h> | ||
45 | #include <stdio.h> | ||
46 | #include <string.h> | ||
47 | |||
48 | static struct ipx_addr addr, zero_addr; | ||
49 | |||
50 | static void Field(), cvtbase(); | ||
51 | |||
52 | struct ipx_addr | ||
53 | ipx_addr(name) | ||
54 | const char *name; | ||
55 | { | ||
56 | char separator; | ||
57 | char *hostname, *socketname, *cp; | ||
58 | char buf[50]; | ||
59 | |||
60 | (void)strncpy(buf, name, sizeof(buf) - 1); | ||
61 | buf[sizeof(buf) - 1] = '\0'; | ||
62 | |||
63 | /* | ||
64 | * First, figure out what he intends as a field separtor. | ||
65 | * Despite the way this routine is written, the prefered | ||
66 | * form 2-272.AA001234H.01777, i.e. XDE standard. | ||
67 | * Great efforts are made to insure backward compatability. | ||
68 | */ | ||
69 | if ((hostname = strchr(buf, '#'))) | ||
70 | separator = '#'; | ||
71 | else { | ||
72 | hostname = strchr(buf, '.'); | ||
73 | if ((cp = strchr(buf, ':')) && | ||
74 | ((hostname && cp < hostname) || (hostname == 0))) { | ||
75 | hostname = cp; | ||
76 | separator = ':'; | ||
77 | } else | ||
78 | separator = '.'; | ||
79 | } | ||
80 | if (hostname) | ||
81 | *hostname++ = 0; | ||
82 | |||
83 | addr = zero_addr; | ||
84 | Field(buf, addr.ipx_net.c_net, 4); | ||
85 | if (hostname == 0) | ||
86 | return (addr); /* No separator means net only */ | ||
87 | |||
88 | socketname = strchr(hostname, separator); | ||
89 | if (socketname) { | ||
90 | *socketname++ = 0; | ||
91 | Field(socketname, (u_char *)&addr.ipx_port, 2); | ||
92 | } | ||
93 | |||
94 | Field(hostname, addr.ipx_host.c_host, 6); | ||
95 | |||
96 | return (addr); | ||
97 | } | ||
98 | |||
99 | static void | ||
100 | Field(buf, out, len) | ||
101 | char *buf; | ||
102 | u_char *out; | ||
103 | int len; | ||
104 | { | ||
105 | register char *bp = buf; | ||
106 | int i, ibase, base16 = 0, base10 = 0, clen = 0; | ||
107 | int hb[6], *hp; | ||
108 | char *fmt; | ||
109 | |||
110 | /* | ||
111 | * first try 2-273#2-852-151-014#socket | ||
112 | */ | ||
113 | if ((*buf != '-') && | ||
114 | (1 < (i = sscanf(buf, "%d-%d-%d-%d-%d", | ||
115 | &hb[0], &hb[1], &hb[2], &hb[3], &hb[4])))) { | ||
116 | cvtbase(1000L, 256, hb, i, out, len); | ||
117 | return; | ||
118 | } | ||
119 | /* | ||
120 | * try form 8E1#0.0.AA.0.5E.E6#socket | ||
121 | */ | ||
122 | if (1 < (i = sscanf(buf,"%x.%x.%x.%x.%x.%x", | ||
123 | &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) { | ||
124 | cvtbase(256L, 256, hb, i, out, len); | ||
125 | return; | ||
126 | } | ||
127 | /* | ||
128 | * try form 8E1#0:0:AA:0:5E:E6#socket | ||
129 | */ | ||
130 | if (1 < (i = sscanf(buf,"%x:%x:%x:%x:%x:%x", | ||
131 | &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) { | ||
132 | cvtbase(256L, 256, hb, i, out, len); | ||
133 | return; | ||
134 | } | ||
135 | /* | ||
136 | * This is REALLY stretching it but there was a | ||
137 | * comma notation separting shorts -- definitely non standard | ||
138 | */ | ||
139 | if (1 < (i = sscanf(buf,"%x,%x,%x", | ||
140 | &hb[0], &hb[1], &hb[2]))) { | ||
141 | hb[0] = htons(hb[0]); hb[1] = htons(hb[1]); | ||
142 | hb[2] = htons(hb[2]); | ||
143 | cvtbase(65536L, 256, hb, i, out, len); | ||
144 | return; | ||
145 | } | ||
146 | |||
147 | /* Need to decide if base 10, 16 or 8 */ | ||
148 | while (*bp) switch (*bp++) { | ||
149 | |||
150 | case '0': case '1': case '2': case '3': case '4': case '5': | ||
151 | case '6': case '7': case '-': | ||
152 | break; | ||
153 | |||
154 | case '8': case '9': | ||
155 | base10 = 1; | ||
156 | break; | ||
157 | |||
158 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': | ||
159 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': | ||
160 | base16 = 1; | ||
161 | break; | ||
162 | |||
163 | case 'x': case 'X': | ||
164 | *--bp = '0'; | ||
165 | base16 = 1; | ||
166 | break; | ||
167 | |||
168 | case 'h': case 'H': | ||
169 | base16 = 1; | ||
170 | /* fall into */ | ||
171 | |||
172 | default: | ||
173 | *--bp = 0; /* Ends Loop */ | ||
174 | } | ||
175 | if (base16) { | ||
176 | fmt = "%3x"; | ||
177 | ibase = 4096; | ||
178 | } else if (base10 == 0 && *buf == '0') { | ||
179 | fmt = "%3o"; | ||
180 | ibase = 512; | ||
181 | } else { | ||
182 | fmt = "%3d"; | ||
183 | ibase = 1000; | ||
184 | } | ||
185 | |||
186 | for (bp = buf; *bp++; ) clen++; | ||
187 | if (clen == 0) clen++; | ||
188 | if (clen > 18) clen = 18; | ||
189 | i = ((clen - 1) / 3) + 1; | ||
190 | bp = clen + buf - 3; | ||
191 | hp = hb + i - 1; | ||
192 | |||
193 | while (hp > hb) { | ||
194 | (void)sscanf(bp, fmt, hp); | ||
195 | bp[0] = 0; | ||
196 | hp--; | ||
197 | bp -= 3; | ||
198 | } | ||
199 | (void)sscanf(buf, fmt, hp); | ||
200 | cvtbase((long)ibase, 256, hb, i, out, len); | ||
201 | } | ||
202 | |||
203 | static void | ||
204 | cvtbase(oldbase,newbase,input,inlen,result,reslen) | ||
205 | long oldbase; | ||
206 | int newbase; | ||
207 | int input[]; | ||
208 | int inlen; | ||
209 | unsigned char result[]; | ||
210 | int reslen; | ||
211 | { | ||
212 | int d, e; | ||
213 | long sum; | ||
214 | |||
215 | e = 1; | ||
216 | while (e > 0 && reslen > 0) { | ||
217 | d = 0; e = 0; sum = 0; | ||
218 | /* long division: input=input/newbase */ | ||
219 | while (d < inlen) { | ||
220 | sum = sum*oldbase + (long) input[d]; | ||
221 | e += (sum > 0); | ||
222 | input[d++] = sum / newbase; | ||
223 | sum %= newbase; | ||
224 | } | ||
225 | result[--reslen] = sum; /* accumulate remainder */ | ||
226 | } | ||
227 | for (d=0; d < reslen; d++) | ||
228 | result[d] = 0; | ||
229 | } | ||
diff --git a/src/lib/libc/net/ipx_ntoa.c b/src/lib/libc/net/ipx_ntoa.c new file mode 100644 index 0000000000..1dcfe7181b --- /dev/null +++ b/src/lib/libc/net/ipx_ntoa.c | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * Copyright (c) 1986, 1993 | ||
3 | * The Regents of the University of California. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * 1. Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * 2. Redistributions in binary form must reproduce the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer in the | ||
12 | * documentation and/or other materials provided with the distribution. | ||
13 | * 3. All advertising materials mentioning features or use of this software | ||
14 | * must display the following acknowledgement: | ||
15 | * This product includes software developed by the University of | ||
16 | * California, Berkeley and its contributors. | ||
17 | * 4. Neither the name of the University nor the names of its contributors | ||
18 | * may be used to endorse or promote products derived from this software | ||
19 | * without specific prior written permission. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
31 | * SUCH DAMAGE. | ||
32 | */ | ||
33 | |||
34 | #if defined(LIBC_SCCS) && !defined(lint) | ||
35 | static char rcsid[] = "$OpenBSD: ipx_ntoa.c,v 1.2 1996/08/19 08:29:20 tholo Exp $"; | ||
36 | #endif /* LIBC_SCCS and not lint */ | ||
37 | |||
38 | #include <sys/param.h> | ||
39 | #include <netipx/ipx.h> | ||
40 | #include <stdio.h> | ||
41 | |||
42 | char * | ||
43 | ipx_ntoa(addr) | ||
44 | struct ipx_addr addr; | ||
45 | { | ||
46 | static char obuf[] = "xxxx.xx:xx:xx:xx:xx:xx.uuuuu"; | ||
47 | |||
48 | sprintf(obuf, "%8xH.%02x:%02x:%02x:%02x:%02x:%02x.%u", | ||
49 | ntohl(addr.ipx_net.l_net), | ||
50 | addr.ipx_host.c_host[0], | ||
51 | addr.ipx_host.c_host[1], | ||
52 | addr.ipx_host.c_host[2], | ||
53 | addr.ipx_host.c_host[3], | ||
54 | addr.ipx_host.c_host[4], | ||
55 | addr.ipx_host.c_host[5], | ||
56 | ntohs(addr.ipx_port)); | ||
57 | return (obuf); | ||
58 | } | ||
diff --git a/src/lib/libc/net/iso_addr.3 b/src/lib/libc/net/iso_addr.3 index 95c136e5fc..d9bf9086be 100644 --- a/src/lib/libc/net/iso_addr.3 +++ b/src/lib/libc/net/iso_addr.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $NetBSD: iso_addr.3,v 1.2 1995/02/25 06:20:46 cgd Exp $ | 1 | .\" $OpenBSD: iso_addr.3,v 1.2 1996/08/19 08:29:22 tholo Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1993 | 3 | .\" Copyright (c) 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -31,8 +31,6 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" @(#)iso_addr.3 8.1 (Berkeley) 6/4/93 | ||
35 | .\" | ||
36 | .Dd June 4, 1993 | 34 | .Dd June 4, 1993 |
37 | .Dt ISO_ADDR 3 | 35 | .Dt ISO_ADDR 3 |
38 | .Os | 36 | .Os |
diff --git a/src/lib/libc/net/iso_addr.c b/src/lib/libc/net/iso_addr.c index c26ec1a64a..01561e395b 100644 --- a/src/lib/libc/net/iso_addr.c +++ b/src/lib/libc/net/iso_addr.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: iso_addr.c,v 1.4 1995/02/25 06:20:47 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1989, 1993 | 2 | * Copyright (c) 1989, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: iso_addr.c,v 1.2 1996/08/19 08:29:23 tholo Exp $"; |
38 | static char sccsid[] = "@(#)iso_addr.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: iso_addr.c,v 1.4 1995/02/25 06:20:47 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/types.h> | 38 | #include <sys/types.h> |
diff --git a/src/lib/libc/net/linkaddr.3 b/src/lib/libc/net/link_addr.3 index 1a2af9b30d..eb6c952177 100644 --- a/src/lib/libc/net/linkaddr.3 +++ b/src/lib/libc/net/link_addr.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $NetBSD: linkaddr.3,v 1.2 1995/02/25 06:20:48 cgd Exp $ | 1 | .\" $OpenBSD: link_addr.3,v 1.2 1996/08/19 08:29:25 tholo Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1993 | 3 | .\" Copyright (c) 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -34,8 +34,6 @@ | |||
34 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 34 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
35 | .\" SUCH DAMAGE. | 35 | .\" SUCH DAMAGE. |
36 | .\" | 36 | .\" |
37 | .\" @(#)linkaddr.3 8.1 (Berkeley) 7/28/93 | ||
38 | .\" | ||
39 | .Dd July 28, 1993 | 37 | .Dd July 28, 1993 |
40 | .Dt LINK_ADDR 3 | 38 | .Dt LINK_ADDR 3 |
41 | .Os BSD 4.4 | 39 | .Os BSD 4.4 |
diff --git a/src/lib/libc/net/linkaddr.c b/src/lib/libc/net/linkaddr.c index 19a0de3abd..fb522f3233 100644 --- a/src/lib/libc/net/linkaddr.c +++ b/src/lib/libc/net/linkaddr.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: linkaddr.c,v 1.5 1995/02/25 06:20:49 cgd Exp $ */ | ||
2 | |||
3 | /*- | 1 | /*- |
4 | * Copyright (c) 1990, 1993 | 2 | * Copyright (c) 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: linkaddr.c,v 1.2 1996/08/19 08:29:27 tholo Exp $"; |
38 | static char sccsid[] = "@(#)linkaddr.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: linkaddr.c,v 1.5 1995/02/25 06:20:49 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/types.h> | 38 | #include <sys/types.h> |
diff --git a/src/lib/libc/net/ns.3 b/src/lib/libc/net/ns.3 index f89b4fe042..6e096d9f4b 100644 --- a/src/lib/libc/net/ns.3 +++ b/src/lib/libc/net/ns.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $NetBSD: ns.3,v 1.3 1995/02/25 06:20:50 cgd Exp $ | 1 | .\" $OpenBSD: ns.3,v 1.2 1996/08/19 08:29:29 tholo Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1986, 1991, 1993 | 3 | .\" Copyright (c) 1986, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -31,8 +31,6 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" @(#)ns.3 8.1 (Berkeley) 6/4/93 | ||
35 | .\" | ||
36 | .Dd June 4, 1993 | 34 | .Dd June 4, 1993 |
37 | .Dt NS 3 | 35 | .Dt NS 3 |
38 | .Os BSD 4.3 | 36 | .Os BSD 4.3 |
diff --git a/src/lib/libc/net/ns_addr.c b/src/lib/libc/net/ns_addr.c index f75ddb23b7..8f2e4bc513 100644 --- a/src/lib/libc/net/ns_addr.c +++ b/src/lib/libc/net/ns_addr.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: ns_addr.c,v 1.5 1995/02/25 06:20:51 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1986, 1993 | 2 | * Copyright (c) 1986, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -37,11 +35,7 @@ | |||
37 | */ | 35 | */ |
38 | 36 | ||
39 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
40 | #if 0 | 38 | static char rcsid[] = "$OpenBSD: ns_addr.c,v 1.4 1997/07/21 20:31:05 deraadt Exp $"; |
41 | static char sccsid[] = "@(#)ns_addr.c 8.1 (Berkeley) 6/7/93"; | ||
42 | #else | ||
43 | static char rcsid[] = "$NetBSD: ns_addr.c,v 1.5 1995/02/25 06:20:51 cgd Exp $"; | ||
44 | #endif | ||
45 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
46 | 40 | ||
47 | #include <sys/param.h> | 41 | #include <sys/param.h> |
@@ -51,7 +45,8 @@ static char rcsid[] = "$NetBSD: ns_addr.c,v 1.5 1995/02/25 06:20:51 cgd Exp $"; | |||
51 | 45 | ||
52 | static struct ns_addr addr, zero_addr; | 46 | static struct ns_addr addr, zero_addr; |
53 | 47 | ||
54 | static void Field(), cvtbase(); | 48 | static void Field __P((char *, u_int8_t *, int)); |
49 | static void cvtbase __P((long, int, int[], int, u_int8_t[], int)); | ||
55 | 50 | ||
56 | struct ns_addr | 51 | struct ns_addr |
57 | ns_addr(name) | 52 | ns_addr(name) |
@@ -70,7 +65,7 @@ ns_addr(name) | |||
70 | * form 2-272.AA001234H.01777, i.e. XDE standard. | 65 | * form 2-272.AA001234H.01777, i.e. XDE standard. |
71 | * Great efforts are made to insure backward compatability. | 66 | * Great efforts are made to insure backward compatability. |
72 | */ | 67 | */ |
73 | if (hostname = strchr(buf, '#')) | 68 | if ((hostname = strchr(buf, '#'))) |
74 | separator = '#'; | 69 | separator = '#'; |
75 | else { | 70 | else { |
76 | hostname = strchr(buf, '.'); | 71 | hostname = strchr(buf, '.'); |
@@ -95,7 +90,7 @@ ns_addr(name) | |||
95 | Field(socketname, (u_char *)&addr.x_port, 2); | 90 | Field(socketname, (u_char *)&addr.x_port, 2); |
96 | } | 91 | } |
97 | 92 | ||
98 | Field(hostname, addr.x_host.c_host, 6); | 93 | Field(hostname, (u_char *)addr.x_host.c_host, 6); |
99 | 94 | ||
100 | return (addr); | 95 | return (addr); |
101 | } | 96 | } |
diff --git a/src/lib/libc/net/ns_ntoa.c b/src/lib/libc/net/ns_ntoa.c index ad3265399b..c33f710966 100644 --- a/src/lib/libc/net/ns_ntoa.c +++ b/src/lib/libc/net/ns_ntoa.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: ns_ntoa.c,v 1.4 1995/02/25 06:20:51 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1986, 1993 | 2 | * Copyright (c) 1986, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,32 +32,29 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: ns_ntoa.c,v 1.7 1997/08/24 21:25:48 millert Exp $"; |
38 | static char sccsid[] = "@(#)ns_ntoa.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: ns_ntoa.c,v 1.4 1995/02/25 06:20:51 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/param.h> | 38 | #include <sys/param.h> |
45 | #include <netns/ns.h> | 39 | #include <netns/ns.h> |
46 | #include <stdio.h> | 40 | #include <stdio.h> |
47 | 41 | ||
42 | static char *spectHex __P((char *)); | ||
43 | |||
48 | char * | 44 | char * |
49 | ns_ntoa(addr) | 45 | ns_ntoa(addr) |
50 | struct ns_addr addr; | 46 | struct ns_addr addr; |
51 | { | 47 | { |
52 | static char obuf[40]; | 48 | static char obuf[40]; |
53 | union { union ns_net net_e; u_long long_e; } net; | 49 | union { union ns_net net_e; u_int32_t long_e; } net; |
54 | u_short port = htons(addr.x_port); | 50 | in_port_t port = htons(addr.x_port); |
55 | register char *cp; | 51 | register char *cp; |
56 | char *cp2; | 52 | char *cp2; |
57 | register u_char *up = addr.x_host.c_host; | 53 | register u_char *up = addr.x_host.c_host; |
58 | u_char *uplim = up + 6; | 54 | u_char *uplim = up + 6; |
59 | static char *spectHex(); | ||
60 | 55 | ||
61 | net.net_e = addr.x_net; | 56 | net.net_e = addr.x_net; |
62 | sprintf(obuf, "%lx", ntohl(net.long_e)); | 57 | sprintf(obuf, "%x", ntohl(net.long_e)); |
63 | cp = spectHex(obuf); | 58 | cp = spectHex(obuf); |
64 | cp2 = cp + 1; | 59 | cp2 = cp + 1; |
65 | while (*up==0 && up < uplim) up++; | 60 | while (*up==0 && up < uplim) up++; |
diff --git a/src/lib/libc/net/nsap_addr.c b/src/lib/libc/net/nsap_addr.c new file mode 100644 index 0000000000..22a5f8d66e --- /dev/null +++ b/src/lib/libc/net/nsap_addr.c | |||
@@ -0,0 +1,109 @@ | |||
1 | /* $OpenBSD: nsap_addr.c,v 1.4 1997/07/09 01:08:45 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1996 by Internet Software Consortium. | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
11 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
12 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
13 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
14 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
15 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
16 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
17 | * SOFTWARE. | ||
18 | */ | ||
19 | |||
20 | #if defined(LIBC_SCCS) && !defined(lint) | ||
21 | #if 0 | ||
22 | static char rcsid[] = "$From: nsap_addr.c,v 8.3 1996/08/05 08:31:35 vixie Exp $"; | ||
23 | #else | ||
24 | static char rcsid[] = "$OpenBSD: nsap_addr.c,v 1.4 1997/07/09 01:08:45 millert Exp $"; | ||
25 | #endif | ||
26 | #endif /* LIBC_SCCS and not lint */ | ||
27 | |||
28 | #include <sys/types.h> | ||
29 | #include <sys/param.h> | ||
30 | #include <sys/socket.h> | ||
31 | #include <netinet/in.h> | ||
32 | #include <arpa/nameser.h> | ||
33 | #include <ctype.h> | ||
34 | #include <resolv.h> | ||
35 | |||
36 | static char | ||
37 | xtob(c) | ||
38 | register int c; | ||
39 | { | ||
40 | return (c - (((c >= '0') && (c <= '9')) ? '0' : '7')); | ||
41 | } | ||
42 | |||
43 | u_int | ||
44 | inet_nsap_addr(ascii, binary, maxlen) | ||
45 | const char *ascii; | ||
46 | u_char *binary; | ||
47 | int maxlen; | ||
48 | { | ||
49 | register u_char c, nib; | ||
50 | u_int len = 0; | ||
51 | |||
52 | while ((c = *ascii++) != '\0' && len < maxlen) { | ||
53 | if (c == '.' || c == '+' || c == '/') | ||
54 | continue; | ||
55 | if (!isascii(c)) | ||
56 | return (0); | ||
57 | if (islower(c)) | ||
58 | c = toupper(c); | ||
59 | if (isxdigit(c)) { | ||
60 | nib = xtob(c); | ||
61 | if ((c = *ascii++)) { | ||
62 | c = toupper(c); | ||
63 | if (isxdigit(c)) { | ||
64 | *binary++ = (nib << 4) | xtob(c); | ||
65 | len++; | ||
66 | } else | ||
67 | return (0); | ||
68 | } | ||
69 | else | ||
70 | return (0); | ||
71 | } | ||
72 | else | ||
73 | return (0); | ||
74 | } | ||
75 | return (len); | ||
76 | } | ||
77 | |||
78 | char * | ||
79 | inet_nsap_ntoa(binlen, binary, ascii) | ||
80 | int binlen; | ||
81 | register const u_char *binary; | ||
82 | register char *ascii; | ||
83 | { | ||
84 | register int nib; | ||
85 | int i; | ||
86 | static char tmpbuf[255*3]; | ||
87 | char *start; | ||
88 | |||
89 | if (ascii) | ||
90 | start = ascii; | ||
91 | else { | ||
92 | ascii = tmpbuf; | ||
93 | start = tmpbuf; | ||
94 | } | ||
95 | |||
96 | if (binlen > 255) | ||
97 | binlen = 255; | ||
98 | |||
99 | for (i = 0; i < binlen; i++) { | ||
100 | nib = *binary >> 4; | ||
101 | *ascii++ = nib + (nib < 10 ? '0' : '7'); | ||
102 | nib = *binary++ & 0x0f; | ||
103 | *ascii++ = nib + (nib < 10 ? '0' : '7'); | ||
104 | if (((i % 2) == 0 && (i + 1) < binlen)) | ||
105 | *ascii++ = '.'; | ||
106 | } | ||
107 | *ascii = '\0'; | ||
108 | return (start); | ||
109 | } | ||
diff --git a/src/lib/libc/net/ntohl.c b/src/lib/libc/net/ntohl.c index 05b7f4c9a3..7d3e227e60 100644 --- a/src/lib/libc/net/ntohl.c +++ b/src/lib/libc/net/ntohl.c | |||
@@ -1,29 +1,25 @@ | |||
1 | /* $NetBSD: ntohl.c,v 1.5 1995/04/28 23:25:21 jtc Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Written by J.T. Conklin <jtc@netbsd.org>. | 2 | * Written by J.T. Conklin <jtc@netbsd.org>. |
5 | * Public domain. | 3 | * Public domain. |
6 | */ | 4 | */ |
7 | 5 | ||
8 | #if defined(LIBC_SCCS) && !defined(lint) | 6 | #if defined(LIBC_SCCS) && !defined(lint) |
9 | static char *rcsid = "$NetBSD: ntohl.c,v 1.5 1995/04/28 23:25:21 jtc Exp $"; | 7 | static char *rcsid = "$OpenBSD: ntohl.c,v 1.4 1996/12/12 03:19:56 tholo Exp $"; |
10 | #endif | 8 | #endif /* LIBC_SCCS and not lint */ |
11 | 9 | ||
12 | #include <sys/types.h> | 10 | #include <sys/types.h> |
13 | #include <machine/endian.h> | 11 | #include <machine/endian.h> |
14 | 12 | ||
15 | #undef ntohl | 13 | #undef ntohl |
16 | 14 | ||
17 | unsigned long | 15 | u_int32_t |
18 | ntohl(x) | 16 | ntohl(x) |
19 | unsigned long x; | 17 | u_int32_t x; |
20 | { | 18 | { |
21 | u_int32_t y = x; | ||
22 | |||
23 | #if BYTE_ORDER == LITTLE_ENDIAN | 19 | #if BYTE_ORDER == LITTLE_ENDIAN |
24 | u_char *s = (u_char *)&y; | 20 | u_char *s = (u_char *)&x; |
25 | return s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]; | 21 | return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); |
26 | #else | 22 | #else |
27 | return y; | 23 | return x; |
28 | #endif | 24 | #endif |
29 | } | 25 | } |
diff --git a/src/lib/libc/net/ntohs.c b/src/lib/libc/net/ntohs.c index 93ab83ee4d..cf6414d4a6 100644 --- a/src/lib/libc/net/ntohs.c +++ b/src/lib/libc/net/ntohs.c | |||
@@ -1,26 +1,28 @@ | |||
1 | /* $NetBSD: ntohs.c,v 1.5 1995/04/28 23:25:23 jtc Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Written by J.T. Conklin <jtc@netbsd.org>. | 2 | * Written by J.T. Conklin <jtc@netbsd.org>. |
5 | * Public domain. | 3 | * Public domain. |
6 | */ | 4 | */ |
7 | 5 | ||
8 | #if defined(LIBC_SCCS) && !defined(lint) | 6 | #if defined(LIBC_SCCS) && !defined(lint) |
9 | static char *rcsid = "$NetBSD: ntohs.c,v 1.5 1995/04/28 23:25:23 jtc Exp $"; | 7 | static char *rcsid = "$OpenBSD: ntohs.c,v 1.6 1997/07/25 20:30:07 mickey Exp $"; |
10 | #endif | 8 | #endif /* LIBC_SCCS and not lint */ |
11 | 9 | ||
12 | #include <sys/types.h> | 10 | #include <sys/types.h> |
13 | #include <machine/endian.h> | 11 | #include <machine/endian.h> |
14 | 12 | ||
15 | #undef ntohs | 13 | #undef ntohs |
16 | 14 | ||
17 | unsigned short | 15 | u_int16_t |
16 | #ifdef __STDC__ | ||
17 | ntohs(u_int16_t x) | ||
18 | #else | ||
18 | ntohs(x) | 19 | ntohs(x) |
19 | unsigned short x; | 20 | u_int16_t x; |
21 | #endif | ||
20 | { | 22 | { |
21 | #if BYTE_ORDER == LITTLE_ENDIAN | 23 | #if BYTE_ORDER == LITTLE_ENDIAN |
22 | u_char *s = (u_char *) &x; | 24 | u_char *s = (u_char *) &x; |
23 | return s[0] << 8 | s[1]; | 25 | return (u_int16_t)(s[0] << 8 | s[1]); |
24 | #else | 26 | #else |
25 | return x; | 27 | return x; |
26 | #endif | 28 | #endif |
diff --git a/src/lib/libc/net/rcmd.3 b/src/lib/libc/net/rcmd.3 index 4db847c392..e69e822834 100644 --- a/src/lib/libc/net/rcmd.3 +++ b/src/lib/libc/net/rcmd.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $NetBSD: rcmd.3,v 1.8 1995/02/25 06:20:52 cgd Exp $ | 1 | .\" $OpenBSD: rcmd.3,v 1.10 1997/09/29 18:25:47 deraadt Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1983, 1991, 1993 | 3 | .\" Copyright (c) 1983, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -31,8 +31,6 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" @(#)rcmd.3 8.1 (Berkeley) 6/4/93 | ||
35 | .\" | ||
36 | .Dd June 4, 1993 | 34 | .Dd June 4, 1993 |
37 | .Dt RCMD 3 | 35 | .Dt RCMD 3 |
38 | .Os BSD 4.2 | 36 | .Os BSD 4.2 |
@@ -49,16 +47,30 @@ | |||
49 | .Ft int | 47 | .Ft int |
50 | .Fn rresvport "int *port" | 48 | .Fn rresvport "int *port" |
51 | .Ft int | 49 | .Ft int |
52 | .Fn iruserok "u_long raddr" "int superuser" "const char *ruser" "const char *luser" | 50 | .Fn iruserok "u_int32_t raddr" "int superuser" "const char *ruser" "const char *luser" |
53 | .Ft int | 51 | .Ft int |
54 | .Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" | 52 | .Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" |
55 | .Sh DESCRIPTION | 53 | .Sh DESCRIPTION |
56 | The | 54 | The |
57 | .Fn rcmd | 55 | .Fn rcmd |
58 | function | 56 | function |
59 | is used by the super-user to execute a command on | 57 | is used by the super-user to execute a command on a remote |
60 | a remote machine using an authentication scheme based | 58 | machine using an authentication scheme based on reserved |
61 | on reserved port numbers. | 59 | port numbers. If the calling process is not setuid and the |
60 | .Li RSH | ||
61 | environment variable is set and | ||
62 | .Fa inport | ||
63 | is | ||
64 | .Li shell/tcp , | ||
65 | .Xr rcmdsh 3 | ||
66 | is called instead with the value of | ||
67 | .Li RSH . | ||
68 | Alternately, if the user is not the super-user, | ||
69 | .Fn rcmd | ||
70 | will invoke | ||
71 | .Xr rcmdsh 3 | ||
72 | to run the command via | ||
73 | .Xr rsh 1 . | ||
62 | The | 74 | The |
63 | .Fn rresvport | 75 | .Fn rresvport |
64 | function | 76 | function |
@@ -90,6 +102,9 @@ is set to the standard name of the host | |||
90 | and a connection is established to a server | 102 | and a connection is established to a server |
91 | residing at the well-known Internet port | 103 | residing at the well-known Internet port |
92 | .Fa inport . | 104 | .Fa inport . |
105 | If the user is not the super-user, the only valid port is | ||
106 | .Li shell/tcp , | ||
107 | (usually port 514). | ||
93 | .Pp | 108 | .Pp |
94 | If the connection succeeds, | 109 | If the connection succeeds, |
95 | a socket in the Internet domain of type | 110 | a socket in the Internet domain of type |
@@ -121,6 +136,9 @@ command) will be made the same as the | |||
121 | and no | 136 | and no |
122 | provision is made for sending arbitrary signals to the remote process, | 137 | provision is made for sending arbitrary signals to the remote process, |
123 | although you may be able to get its attention by using out-of-band data. | 138 | although you may be able to get its attention by using out-of-band data. |
139 | Note that if the user is not the super-user, | ||
140 | .Fa fd2p | ||
141 | must be 0. | ||
124 | .Pp | 142 | .Pp |
125 | The protocol is described in detail in | 143 | The protocol is described in detail in |
126 | .Xr rshd 8 . | 144 | .Xr rshd 8 . |
@@ -134,6 +152,9 @@ by | |||
134 | and several other functions. Privileged Internet ports are those | 152 | and several other functions. Privileged Internet ports are those |
135 | in the range 0 to 1023. Only the super-user | 153 | in the range 0 to 1023. Only the super-user |
136 | is allowed to bind an address of this sort to a socket. | 154 | is allowed to bind an address of this sort to a socket. |
155 | .Fn rresvport | ||
156 | needs to be seeded with a port number; if that port | ||
157 | is not available it will find another. | ||
137 | .Pp | 158 | .Pp |
138 | The | 159 | The |
139 | .Fn iruserok | 160 | .Fn iruserok |
@@ -165,7 +186,7 @@ and | |||
165 | .Fn ruserok | 186 | .Fn ruserok |
166 | return \-1. | 187 | return \-1. |
167 | If the local domain (as obtained from | 188 | If the local domain (as obtained from |
168 | .Xr gethostname 2 ) | 189 | .Xr gethostname 3 ) |
169 | is the same as the remote domain, only the machine name need be specified. | 190 | is the same as the remote domain, only the machine name need be specified. |
170 | .Pp | 191 | .Pp |
171 | If the IP address of the remote host is known, | 192 | If the IP address of the remote host is known, |
@@ -195,8 +216,10 @@ is overloaded to mean ``All network ports in use.'' | |||
195 | .Xr rsh 1 , | 216 | .Xr rsh 1 , |
196 | .Xr intro 2 , | 217 | .Xr intro 2 , |
197 | .Xr rexec 3 , | 218 | .Xr rexec 3 , |
219 | .Xr rcmdsh 3 , | ||
198 | .Xr rexecd 8 , | 220 | .Xr rexecd 8 , |
199 | .Xr rlogind 8 , | 221 | .Xr rlogind 8 , |
222 | .Xr bindresvport 3 , | ||
200 | .Xr rshd 8 | 223 | .Xr rshd 8 |
201 | .Sh HISTORY | 224 | .Sh HISTORY |
202 | These | 225 | These |
diff --git a/src/lib/libc/net/rcmd.c b/src/lib/libc/net/rcmd.c index e0310031b0..c933f5b447 100644 --- a/src/lib/libc/net/rcmd.c +++ b/src/lib/libc/net/rcmd.c | |||
@@ -1,6 +1,5 @@ | |||
1 | /* $NetBSD: rcmd.c,v 1.12 1995/06/03 22:33:34 mycroft Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
2 | * Copyright (c) 1995, 1996, 1998 Theo de Raadt. All rights reserved. | ||
4 | * Copyright (c) 1983, 1993, 1994 | 3 | * Copyright (c) 1983, 1993, 1994 |
5 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
6 | * | 5 | * |
@@ -16,6 +15,7 @@ | |||
16 | * must display the following acknowledgement: | 15 | * must display the following acknowledgement: |
17 | * This product includes software developed by the University of | 16 | * This product includes software developed by the University of |
18 | * California, Berkeley and its contributors. | 17 | * California, Berkeley and its contributors. |
18 | * This product includes software developed by Theo de Raadt. | ||
19 | * 4. Neither the name of the University nor the names of its contributors | 19 | * 4. Neither the name of the University nor the names of its contributors |
20 | * may be used to endorse or promote products derived from this software | 20 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. | 21 | * without specific prior written permission. |
@@ -34,11 +34,7 @@ | |||
34 | */ | 34 | */ |
35 | 35 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 36 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 37 | static char *rcsid = "$OpenBSD: rcmd.c,v 1.31 1998/03/19 00:30:05 millert Exp $"; |
38 | static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; | ||
39 | #else | ||
40 | static char *rcsid = "$NetBSD: rcmd.c,v 1.12 1995/06/03 22:33:34 mycroft Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 38 | #endif /* LIBC_SCCS and not lint */ |
43 | 39 | ||
44 | #include <sys/param.h> | 40 | #include <sys/param.h> |
@@ -57,24 +53,46 @@ static char *rcsid = "$NetBSD: rcmd.c,v 1.12 1995/06/03 22:33:34 mycroft Exp $"; | |||
57 | #include <stdio.h> | 53 | #include <stdio.h> |
58 | #include <ctype.h> | 54 | #include <ctype.h> |
59 | #include <string.h> | 55 | #include <string.h> |
56 | #include <syslog.h> | ||
57 | #include <stdlib.h> | ||
58 | #include <netgroup.h> | ||
60 | 59 | ||
61 | int __ivaliduser __P((FILE *, u_long, const char *, const char *)); | 60 | int __ivaliduser __P((FILE *, in_addr_t, const char *, const char *)); |
62 | static int __icheckhost __P((u_long, const char *)); | 61 | static int __icheckhost __P((u_int32_t, const char *)); |
62 | static char *__gethostloop __P((u_int32_t)); | ||
63 | 63 | ||
64 | int | 64 | int |
65 | rcmd(ahost, rport, locuser, remuser, cmd, fd2p) | 65 | rcmd(ahost, rport, locuser, remuser, cmd, fd2p) |
66 | char **ahost; | 66 | char **ahost; |
67 | u_short rport; | 67 | in_port_t rport; |
68 | const char *locuser, *remuser, *cmd; | 68 | const char *locuser, *remuser, *cmd; |
69 | int *fd2p; | 69 | int *fd2p; |
70 | { | 70 | { |
71 | struct hostent *hp; | 71 | struct hostent *hp; |
72 | struct sockaddr_in sin, from; | 72 | struct sockaddr_in sin, from; |
73 | fd_set reads; | 73 | fd_set *readsp = NULL; |
74 | long oldmask; | 74 | int oldmask; |
75 | pid_t pid; | 75 | pid_t pid; |
76 | int s, lport, timo; | 76 | int s, lport, timo; |
77 | char c; | 77 | char c, *p; |
78 | |||
79 | /* call rcmdsh() with specified remote shell if appropriate. */ | ||
80 | if (!issetugid() && (p = getenv("RSH"))) { | ||
81 | struct servent *sp = getservbyname("shell", "tcp"); | ||
82 | |||
83 | if (sp && sp->s_port == rport) | ||
84 | return (rcmdsh(ahost, rport, locuser, remuser, | ||
85 | cmd, p)); | ||
86 | } | ||
87 | |||
88 | /* use rsh(1) if non-root and remote port is shell. */ | ||
89 | if (geteuid()) { | ||
90 | struct servent *sp = getservbyname("shell", "tcp"); | ||
91 | |||
92 | if (sp && sp->s_port == rport) | ||
93 | return (rcmdsh(ahost, rport, locuser, remuser, | ||
94 | cmd, NULL)); | ||
95 | } | ||
78 | 96 | ||
79 | pid = getpid(); | 97 | pid = getpid(); |
80 | hp = gethostbyname(*ahost); | 98 | hp = gethostbyname(*ahost); |
@@ -83,6 +101,7 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p) | |||
83 | return (-1); | 101 | return (-1); |
84 | } | 102 | } |
85 | *ahost = hp->h_name; | 103 | *ahost = hp->h_name; |
104 | |||
86 | oldmask = sigblock(sigmask(SIGURG)); | 105 | oldmask = sigblock(sigmask(SIGURG)); |
87 | for (timo = 1, lport = IPPORT_RESERVED - 1;;) { | 106 | for (timo = 1, lport = IPPORT_RESERVED - 1;;) { |
88 | s = rresvport(&lport); | 107 | s = rresvport(&lport); |
@@ -97,6 +116,7 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p) | |||
97 | return (-1); | 116 | return (-1); |
98 | } | 117 | } |
99 | fcntl(s, F_SETOWN, pid); | 118 | fcntl(s, F_SETOWN, pid); |
119 | bzero(&sin, sizeof sin); | ||
100 | sin.sin_len = sizeof(struct sockaddr_in); | 120 | sin.sin_len = sizeof(struct sockaddr_in); |
101 | sin.sin_family = hp->h_addrtype; | 121 | sin.sin_family = hp->h_addrtype; |
102 | sin.sin_port = rport; | 122 | sin.sin_port = rport; |
@@ -130,7 +150,13 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p) | |||
130 | sigsetmask(oldmask); | 150 | sigsetmask(oldmask); |
131 | return (-1); | 151 | return (-1); |
132 | } | 152 | } |
153 | #if 0 | ||
154 | /* | ||
155 | * try to rresvport() to the same port. This will make rresvport() | ||
156 | * fail it's first bind, resulting in it choosing a random port. | ||
157 | */ | ||
133 | lport--; | 158 | lport--; |
159 | #endif | ||
134 | if (fd2p == 0) { | 160 | if (fd2p == 0) { |
135 | write(s, "", 1); | 161 | write(s, "", 1); |
136 | lport = 0; | 162 | lport = 0; |
@@ -138,9 +164,13 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p) | |||
138 | char num[8]; | 164 | char num[8]; |
139 | int s2 = rresvport(&lport), s3; | 165 | int s2 = rresvport(&lport), s3; |
140 | int len = sizeof(from); | 166 | int len = sizeof(from); |
167 | int fdssize = howmany(MAX(s, s2)+1, NFDBITS) * sizeof(fd_mask); | ||
141 | 168 | ||
142 | if (s2 < 0) | 169 | if (s2 < 0) |
143 | goto bad; | 170 | goto bad; |
171 | readsp = (fd_set *)malloc(fdssize); | ||
172 | if (readsp == NULL) | ||
173 | goto bad; | ||
144 | listen(s2, 1); | 174 | listen(s2, 1); |
145 | (void)snprintf(num, sizeof(num), "%d", lport); | 175 | (void)snprintf(num, sizeof(num), "%d", lport); |
146 | if (write(s, num, strlen(num)+1) != strlen(num)+1) { | 176 | if (write(s, num, strlen(num)+1) != strlen(num)+1) { |
@@ -150,12 +180,13 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p) | |||
150 | (void)close(s2); | 180 | (void)close(s2); |
151 | goto bad; | 181 | goto bad; |
152 | } | 182 | } |
153 | FD_ZERO(&reads); | 183 | again: |
154 | FD_SET(s, &reads); | 184 | bzero(readsp, fdssize); |
155 | FD_SET(s2, &reads); | 185 | FD_SET(s, readsp); |
186 | FD_SET(s2, readsp); | ||
156 | errno = 0; | 187 | errno = 0; |
157 | if (select(MAX(s, s2) + 1, &reads, 0, 0, 0) < 1 || | 188 | if (select(MAX(s, s2) + 1, readsp, 0, 0, 0) < 1 || |
158 | !FD_ISSET(s2, &reads)) { | 189 | !FD_ISSET(s2, readsp)) { |
159 | if (errno != 0) | 190 | if (errno != 0) |
160 | (void)fprintf(stderr, | 191 | (void)fprintf(stderr, |
161 | "rcmd: select (setting up stderr): %s\n", | 192 | "rcmd: select (setting up stderr): %s\n", |
@@ -167,6 +198,14 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p) | |||
167 | goto bad; | 198 | goto bad; |
168 | } | 199 | } |
169 | s3 = accept(s2, (struct sockaddr *)&from, &len); | 200 | s3 = accept(s2, (struct sockaddr *)&from, &len); |
201 | /* | ||
202 | * XXX careful for ftp bounce attacks. If discovered, shut them | ||
203 | * down and check for the real auxiliary channel to connect. | ||
204 | */ | ||
205 | if (from.sin_family == AF_INET && from.sin_port == htons(20)) { | ||
206 | close(s3); | ||
207 | goto again; | ||
208 | } | ||
170 | (void)close(s2); | 209 | (void)close(s2); |
171 | if (s3 < 0) { | 210 | if (s3 < 0) { |
172 | (void)fprintf(stderr, | 211 | (void)fprintf(stderr, |
@@ -201,11 +240,14 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p) | |||
201 | goto bad2; | 240 | goto bad2; |
202 | } | 241 | } |
203 | sigsetmask(oldmask); | 242 | sigsetmask(oldmask); |
243 | free(readsp); | ||
204 | return (s); | 244 | return (s); |
205 | bad2: | 245 | bad2: |
206 | if (lport) | 246 | if (lport) |
207 | (void)close(*fd2p); | 247 | (void)close(*fd2p); |
208 | bad: | 248 | bad: |
249 | if (readsp) | ||
250 | free(readsp); | ||
209 | (void)close(s); | 251 | (void)close(s); |
210 | sigsetmask(oldmask); | 252 | sigsetmask(oldmask); |
211 | return (-1); | 253 | return (-1); |
@@ -218,27 +260,29 @@ rresvport(alport) | |||
218 | struct sockaddr_in sin; | 260 | struct sockaddr_in sin; |
219 | int s; | 261 | int s; |
220 | 262 | ||
263 | bzero(&sin, sizeof sin); | ||
221 | sin.sin_len = sizeof(struct sockaddr_in); | 264 | sin.sin_len = sizeof(struct sockaddr_in); |
222 | sin.sin_family = AF_INET; | 265 | sin.sin_family = AF_INET; |
223 | sin.sin_addr.s_addr = INADDR_ANY; | 266 | sin.sin_addr.s_addr = INADDR_ANY; |
224 | s = socket(AF_INET, SOCK_STREAM, 0); | 267 | s = socket(AF_INET, SOCK_STREAM, 0); |
225 | if (s < 0) | 268 | if (s < 0) |
226 | return (-1); | 269 | return (-1); |
227 | for (;;) { | 270 | sin.sin_port = htons((in_port_t)*alport); |
228 | sin.sin_port = htons((u_short)*alport); | 271 | if (*alport < IPPORT_RESERVED - 1) { |
229 | if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) | 272 | if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) |
230 | return (s); | 273 | return (s); |
231 | if (errno != EADDRINUSE) { | 274 | if (errno != EADDRINUSE) { |
232 | (void)close(s); | 275 | (void)close(s); |
233 | return (-1); | 276 | return (-1); |
234 | } | 277 | } |
235 | (*alport)--; | ||
236 | if (*alport == IPPORT_RESERVED/2) { | ||
237 | (void)close(s); | ||
238 | errno = EAGAIN; /* close */ | ||
239 | return (-1); | ||
240 | } | ||
241 | } | 278 | } |
279 | sin.sin_port = 0; | ||
280 | if (bindresvport(s, &sin) == -1) { | ||
281 | (void)close(s); | ||
282 | return (-1); | ||
283 | } | ||
284 | *alport = (int)ntohs(sin.sin_port); | ||
285 | return (s); | ||
242 | } | 286 | } |
243 | 287 | ||
244 | int __check_rhosts_file = 1; | 288 | int __check_rhosts_file = 1; |
@@ -253,7 +297,7 @@ ruserok(rhost, superuser, ruser, luser) | |||
253 | char **ap; | 297 | char **ap; |
254 | int i; | 298 | int i; |
255 | #define MAXADDRS 35 | 299 | #define MAXADDRS 35 |
256 | u_long addrs[MAXADDRS + 1]; | 300 | u_int32_t addrs[MAXADDRS + 1]; |
257 | 301 | ||
258 | if ((hp = gethostbyname(rhost)) == NULL) | 302 | if ((hp = gethostbyname(rhost)) == NULL) |
259 | return (-1); | 303 | return (-1); |
@@ -262,7 +306,7 @@ ruserok(rhost, superuser, ruser, luser) | |||
262 | addrs[i] = 0; | 306 | addrs[i] = 0; |
263 | 307 | ||
264 | for (i = 0; i < MAXADDRS && addrs[i]; i++) | 308 | for (i = 0; i < MAXADDRS && addrs[i]; i++) |
265 | if (iruserok(addrs[i], superuser, ruser, luser) == 0) | 309 | if (iruserok((in_addr_t)addrs[i], superuser, ruser, luser) == 0) |
266 | return (0); | 310 | return (0); |
267 | return (-1); | 311 | return (-1); |
268 | } | 312 | } |
@@ -278,7 +322,7 @@ ruserok(rhost, superuser, ruser, luser) | |||
278 | */ | 322 | */ |
279 | int | 323 | int |
280 | iruserok(raddr, superuser, ruser, luser) | 324 | iruserok(raddr, superuser, ruser, luser) |
281 | u_long raddr; | 325 | u_int32_t raddr; |
282 | int superuser; | 326 | int superuser; |
283 | const char *ruser, *luser; | 327 | const char *ruser, *luser; |
284 | { | 328 | { |
@@ -352,41 +396,47 @@ again: | |||
352 | * Returns 0 if ok, -1 if not ok. | 396 | * Returns 0 if ok, -1 if not ok. |
353 | */ | 397 | */ |
354 | int | 398 | int |
355 | __ivaliduser(hostf, raddr, luser, ruser) | 399 | __ivaliduser(hostf, raddrl, luser, ruser) |
356 | FILE *hostf; | 400 | FILE *hostf; |
357 | u_long raddr; | 401 | in_addr_t raddrl; |
358 | const char *luser, *ruser; | 402 | const char *luser, *ruser; |
359 | { | 403 | { |
360 | register char *user, *p; | 404 | register char *user, *p; |
361 | int ch; | 405 | char *buf; |
362 | char buf[MAXHOSTNAMELEN + 128]; /* host + login */ | ||
363 | const char *auser, *ahost; | 406 | const char *auser, *ahost; |
364 | int hostok, userok; | 407 | int hostok, userok; |
365 | char rhost[MAXHOSTNAMELEN]; | 408 | char *rhost = (char *)-1; |
366 | struct hostent *hp; | ||
367 | char domain[MAXHOSTNAMELEN]; | 409 | char domain[MAXHOSTNAMELEN]; |
410 | u_int32_t raddr = (u_int32_t)raddrl; | ||
411 | size_t buflen; | ||
368 | 412 | ||
369 | getdomainname(domain, sizeof(domain)); | 413 | getdomainname(domain, sizeof(domain)); |
370 | 414 | ||
371 | while (fgets(buf, sizeof(buf), hostf)) { | 415 | while ((buf = fgetln(hostf, &buflen))) { |
372 | p = buf; | 416 | p = buf; |
373 | /* Skip lines that are too long. */ | 417 | if (*p == '#') |
374 | if (strchr(p, '\n') == NULL) { | ||
375 | while ((ch = getc(hostf)) != '\n' && ch != EOF); | ||
376 | continue; | 418 | continue; |
377 | } | 419 | while (*p != '\n' && *p != ' ' && *p != '\t' && p < buf + buflen) { |
378 | while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') { | 420 | if (!isprint(*p)) |
421 | goto bail; | ||
379 | *p = isupper(*p) ? tolower(*p) : *p; | 422 | *p = isupper(*p) ? tolower(*p) : *p; |
380 | p++; | 423 | p++; |
381 | } | 424 | } |
425 | if (p >= buf + buflen) | ||
426 | continue; | ||
382 | if (*p == ' ' || *p == '\t') { | 427 | if (*p == ' ' || *p == '\t') { |
383 | *p++ = '\0'; | 428 | *p++ = '\0'; |
384 | while (*p == ' ' || *p == '\t') | 429 | while ((*p == ' ' || *p == '\t') && p < buf + buflen) |
385 | p++; | 430 | p++; |
431 | if (p >= buf + buflen) | ||
432 | continue; | ||
386 | user = p; | 433 | user = p; |
387 | while (*p != '\n' && *p != ' ' && | 434 | while (*p != '\n' && *p != ' ' && |
388 | *p != '\t' && *p != '\0') | 435 | *p != '\t' && p < buf + buflen) { |
436 | if (!isprint(*p)) | ||
437 | goto bail; | ||
389 | p++; | 438 | p++; |
439 | } | ||
390 | } else | 440 | } else |
391 | user = p; | 441 | user = p; |
392 | *p = '\0'; | 442 | *p = '\0'; |
@@ -397,25 +447,27 @@ __ivaliduser(hostf, raddr, luser, ruser) | |||
397 | auser = *user ? user : luser; | 447 | auser = *user ? user : luser; |
398 | ahost = buf; | 448 | ahost = buf; |
399 | 449 | ||
400 | if ((hp = gethostbyaddr((char *) &raddr, | 450 | if (strlen(ahost) >= MAXHOSTNAMELEN) |
401 | sizeof(raddr), AF_INET)) == NULL) { | 451 | continue; |
402 | abort(); | ||
403 | return -1; | ||
404 | } | ||
405 | (void) strncpy(rhost, hp->h_name, sizeof(rhost)); | ||
406 | rhost[sizeof(rhost) - 1] = '\0'; | ||
407 | 452 | ||
453 | /* | ||
454 | * innetgr() must lookup a hostname (we do not attempt | ||
455 | * to change the semantics so that netgroups may have | ||
456 | * #.#.#.# addresses in the list.) | ||
457 | */ | ||
408 | if (ahost[0] == '+') | 458 | if (ahost[0] == '+') |
409 | switch (ahost[1]) { | 459 | switch (ahost[1]) { |
410 | case '\0': | 460 | case '\0': |
411 | hostok = 1; | 461 | hostok = 1; |
412 | break; | 462 | break; |
413 | |||
414 | case '@': | 463 | case '@': |
415 | hostok = innetgr(&ahost[2], rhost, NULL, | 464 | if (rhost == (char *)-1) |
416 | domain); | 465 | rhost = __gethostloop(raddr); |
466 | hostok = 0; | ||
467 | if (rhost) | ||
468 | hostok = innetgr(&ahost[2], rhost, | ||
469 | NULL, domain); | ||
417 | break; | 470 | break; |
418 | |||
419 | default: | 471 | default: |
420 | hostok = __icheckhost(raddr, &ahost[1]); | 472 | hostok = __icheckhost(raddr, &ahost[1]); |
421 | break; | 473 | break; |
@@ -425,12 +477,14 @@ __ivaliduser(hostf, raddr, luser, ruser) | |||
425 | case '\0': | 477 | case '\0': |
426 | hostok = -1; | 478 | hostok = -1; |
427 | break; | 479 | break; |
428 | |||
429 | case '@': | 480 | case '@': |
430 | hostok = -innetgr(&ahost[2], rhost, NULL, | 481 | if (rhost == (char *)-1) |
431 | domain); | 482 | rhost = __gethostloop(raddr); |
483 | hostok = 0; | ||
484 | if (rhost) | ||
485 | hostok = -innetgr(&ahost[2], rhost, | ||
486 | NULL, domain); | ||
432 | break; | 487 | break; |
433 | |||
434 | default: | 488 | default: |
435 | hostok = -__icheckhost(raddr, &ahost[1]); | 489 | hostok = -__icheckhost(raddr, &ahost[1]); |
436 | break; | 490 | break; |
@@ -444,14 +498,12 @@ __ivaliduser(hostf, raddr, luser, ruser) | |||
444 | case '\0': | 498 | case '\0': |
445 | userok = 1; | 499 | userok = 1; |
446 | break; | 500 | break; |
447 | |||
448 | case '@': | 501 | case '@': |
449 | userok = innetgr(&auser[2], NULL, ruser, | 502 | userok = innetgr(&auser[2], NULL, ruser, |
450 | domain); | 503 | domain); |
451 | break; | 504 | break; |
452 | |||
453 | default: | 505 | default: |
454 | userok = strcmp(ruser, &auser[1]) == 0; | 506 | userok = strcmp(ruser, &auser[1]) ? 0 : 1; |
455 | break; | 507 | break; |
456 | } | 508 | } |
457 | else if (auser[0] == '-') | 509 | else if (auser[0] == '-') |
@@ -459,59 +511,97 @@ __ivaliduser(hostf, raddr, luser, ruser) | |||
459 | case '\0': | 511 | case '\0': |
460 | userok = -1; | 512 | userok = -1; |
461 | break; | 513 | break; |
462 | |||
463 | case '@': | 514 | case '@': |
464 | userok = -innetgr(&auser[2], NULL, ruser, | 515 | userok = -innetgr(&auser[2], NULL, ruser, |
465 | domain); | 516 | domain); |
466 | break; | 517 | break; |
467 | |||
468 | default: | 518 | default: |
469 | userok = -(strcmp(ruser, &auser[1]) == 0); | 519 | userok = strcmp(ruser, &auser[1]) ? 0 : -1; |
470 | break; | 520 | break; |
471 | } | 521 | } |
472 | else | 522 | else |
473 | userok = strcmp(ruser, auser) == 0; | 523 | userok = strcmp(ruser, auser) ? 0 : 1; |
474 | 524 | ||
475 | /* Check if one component did not match */ | 525 | /* Check if one component did not match */ |
476 | if (hostok == 0 || userok == 0) | 526 | if (hostok == 0 || userok == 0) |
477 | continue; | 527 | continue; |
478 | 528 | ||
479 | /* Check if we got a forbidden pair */ | 529 | /* Check if we got a forbidden pair */ |
480 | if (userok == -1 || hostok == -1) | 530 | if (userok <= -1 || hostok <= -1) |
481 | return -1; | 531 | return (-1); |
482 | 532 | ||
483 | /* Check if we got a valid pair */ | 533 | /* Check if we got a valid pair */ |
484 | if (hostok == 1 && userok == 1) | 534 | if (hostok >= 1 && userok >= 1) |
485 | return 0; | 535 | return (0); |
486 | } | 536 | } |
487 | return -1; | 537 | bail: |
538 | return (-1); | ||
488 | } | 539 | } |
489 | 540 | ||
490 | /* | 541 | /* |
491 | * Returns "true" if match, 0 if no match. | 542 | * Returns "true" if match, 0 if no match. If we do not find any |
543 | * semblance of an A->PTR->A loop, allow a simple #.#.#.# match to work. | ||
492 | */ | 544 | */ |
493 | static int | 545 | static int |
494 | __icheckhost(raddr, lhost) | 546 | __icheckhost(raddr, lhost) |
495 | u_long raddr; | 547 | u_int32_t raddr; |
496 | const char *lhost; | 548 | const char *lhost; |
497 | { | 549 | { |
498 | register struct hostent *hp; | 550 | register struct hostent *hp; |
499 | register u_long laddr; | ||
500 | register char **pp; | 551 | register char **pp; |
552 | struct in_addr in; | ||
553 | |||
554 | hp = gethostbyname(lhost); | ||
555 | if (hp != NULL) { | ||
556 | /* Spin through ip addresses. */ | ||
557 | for (pp = hp->h_addr_list; *pp; ++pp) | ||
558 | if (!bcmp(&raddr, *pp, sizeof(raddr))) | ||
559 | return (1); | ||
560 | } | ||
501 | 561 | ||
502 | /* Try for raw ip address first. */ | 562 | in.s_addr = raddr; |
503 | if (isdigit(*lhost) && (long)(laddr = inet_addr(lhost)) != -1) | 563 | if (strcmp(lhost, inet_ntoa(in)) == 0) |
504 | return (raddr == laddr); | 564 | return (1); |
505 | |||
506 | /* Better be a hostname. */ | ||
507 | if ((hp = gethostbyname(lhost)) == NULL) | ||
508 | return (0); | ||
509 | |||
510 | /* Spin through ip addresses. */ | ||
511 | for (pp = hp->h_addr_list; *pp; ++pp) | ||
512 | if (!bcmp(&raddr, *pp, sizeof(u_long))) | ||
513 | return (1); | ||
514 | |||
515 | /* No match. */ | ||
516 | return (0); | 565 | return (0); |
517 | } | 566 | } |
567 | |||
568 | /* | ||
569 | * Return the hostname associated with the supplied address. | ||
570 | * Do a reverse lookup as well for security. If a loop cannot | ||
571 | * be found, pack the result of inet_ntoa() into the string. | ||
572 | */ | ||
573 | static char * | ||
574 | __gethostloop(raddr) | ||
575 | u_int32_t raddr; | ||
576 | { | ||
577 | static char remotehost[MAXHOSTNAMELEN]; | ||
578 | struct hostent *hp; | ||
579 | struct in_addr in; | ||
580 | |||
581 | hp = gethostbyaddr((char *) &raddr, sizeof(raddr), AF_INET); | ||
582 | if (hp == NULL) | ||
583 | return (NULL); | ||
584 | |||
585 | /* | ||
586 | * Look up the name and check that the supplied | ||
587 | * address is in the list | ||
588 | */ | ||
589 | strncpy(remotehost, hp->h_name, sizeof(remotehost) - 1); | ||
590 | remotehost[sizeof(remotehost) - 1] = '\0'; | ||
591 | hp = gethostbyname(remotehost); | ||
592 | if (hp == NULL) | ||
593 | return (NULL); | ||
594 | |||
595 | for (; hp->h_addr_list[0] != NULL; hp->h_addr_list++) | ||
596 | if (!bcmp(hp->h_addr_list[0], (caddr_t)&raddr, sizeof(raddr))) | ||
597 | return (remotehost); | ||
598 | |||
599 | /* | ||
600 | * either the DNS adminstrator has made a configuration | ||
601 | * mistake, or someone has attempted to spoof us | ||
602 | */ | ||
603 | in.s_addr = raddr; | ||
604 | syslog(LOG_NOTICE, "rcmd: address %s not listed for host %s", | ||
605 | inet_ntoa(in), hp->h_name); | ||
606 | return (NULL); | ||
607 | } | ||
diff --git a/src/lib/libc/stdlib/realloc.3 b/src/lib/libc/net/rcmdsh.3 index 66f09b2081..fd89acee8f 100644 --- a/src/lib/libc/stdlib/realloc.3 +++ b/src/lib/libc/net/rcmdsh.3 | |||
@@ -1,5 +1,7 @@ | |||
1 | .\" Copyright (c) 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: rcmdsh.3,v 1.3 1998/06/26 17:54:09 millert Exp $ |
2 | .\" All rights reserved. | 2 | .\" |
3 | .\" Copyright (c) 1983, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | 5 | .\" |
4 | .\" Redistribution and use in source and binary forms, with or without | 6 | .\" Redistribution and use in source and binary forms, with or without |
5 | .\" modification, are permitted provided that the following conditions | 7 | .\" modification, are permitted provided that the following conditions |
@@ -29,72 +31,78 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
31 | .\" | 33 | .\" |
32 | .\" from: @(#)realloc.3 5.1 (Berkeley) 5/2/91 | 34 | .Dd Sep 1, 1996 |
33 | .\" $Id: realloc.3,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $ | 35 | .Dt RCMDSH 3 |
34 | .\" | 36 | .Os OpenBSD |
35 | .Dd May 2, 1991 | ||
36 | .Dt REALLOC 3 | ||
37 | .Os | ||
38 | .Sh NAME | 37 | .Sh NAME |
39 | .Nm realloc | 38 | .Nm rcmdsh |
40 | .Nd reallocation of memory function | 39 | .Nd return a stream to a remote command without superuser |
41 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
42 | .Fd #include <stdlib.h> | 41 | .Fd #include <unistd.h> |
43 | .Ft void * | 42 | .Ft int |
44 | .Fn realloc "void *ptr" "size_t size" | 43 | .Fn rcmdsh "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "char *rshprog" |
45 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
46 | The | 45 | The |
47 | .Fn realloc | 46 | .Fn rcmdsh |
48 | function changes the size of the object pointed to by | 47 | function |
49 | .Fa ptr | 48 | is used by normal users to execute a command on |
50 | to the size specified by | 49 | a remote machine using an authentication scheme based |
51 | .Fa size . | 50 | on reserved port numbers using |
52 | The contents of the object are unchanged up to the lesser | 51 | .Xr rshd 8 |
53 | of the new and old sizes. | 52 | or the value of |
54 | If the new size is larger, the value of the newly allocated portion | 53 | .Fa rshprog |
55 | of the object is indeterminate. | 54 | (if non-NULL). |
56 | If | ||
57 | .Fa ptr | ||
58 | is a null pointer, the | ||
59 | .Fn realloc | ||
60 | function behaves like the | ||
61 | .Xr malloc 3 | ||
62 | function for the specified size. | ||
63 | Otherwise, if | ||
64 | .Fa ptr | ||
65 | does not match a pointer earlier returned by the | ||
66 | .Xr calloc 3 , | ||
67 | .Xr malloc 3 , | ||
68 | or | ||
69 | .Fn realloc | ||
70 | function, or if the space has been deallocated | ||
71 | by a call to the | ||
72 | .Xr free | ||
73 | or | ||
74 | .Fn realloc | ||
75 | function, unpredictable and usually detrimental | ||
76 | behavior will occur. | ||
77 | If the space cannot be allocated, the object | ||
78 | pointed to by | ||
79 | .Fa ptr | ||
80 | is unchanged. | ||
81 | If | ||
82 | .Fa size | ||
83 | is zero and | ||
84 | .Fa ptr | ||
85 | is not a null pointer, the object it points to is freed. | ||
86 | .Pp | 55 | .Pp |
87 | The | 56 | The |
88 | .Fn realloc | 57 | .Fn rcmdsh |
89 | function returns either a null pointer or a pointer | 58 | function |
90 | to the possibly moved allocated space. | 59 | looks up the host |
60 | .Fa *ahost | ||
61 | using | ||
62 | .Xr gethostbyname 3 , | ||
63 | returning \-1 if the host does not exist. | ||
64 | Otherwise | ||
65 | .Fa *ahost | ||
66 | is set to the standard name of the host | ||
67 | and a connection is established to a server | ||
68 | residing at the well-known Internet port | ||
69 | .Li shell/tcp | ||
70 | (or whatever port is used by | ||
71 | .Fa rshprog | ||
72 | ). The parameter | ||
73 | .Fa inport | ||
74 | is ignored; it is only included to provide an interface similar to | ||
75 | .Xr rcmd 3 . | ||
76 | .Pp | ||
77 | If the connection succeeds, | ||
78 | a socket in the | ||
79 | .Tn UNIX | ||
80 | domain of type | ||
81 | .Dv SOCK_STREAM | ||
82 | is returned to the caller, and given to the remote | ||
83 | command as | ||
84 | .Em stdin | ||
85 | and | ||
86 | .Em stdout , | ||
87 | and | ||
88 | .Em stderr . | ||
89 | .Sh DIAGNOSTICS | ||
90 | The | ||
91 | .Fn rcmdsh | ||
92 | function | ||
93 | returns a valid socket descriptor on success. | ||
94 | It returns \-1 on error and prints a diagnostic message on the standard error. | ||
91 | .Sh SEE ALSO | 95 | .Sh SEE ALSO |
92 | .Xr alloca 3 , | 96 | .Xr rsh 1 , |
93 | .Xr calloc 3 , | 97 | .Xr socketpair 2 , |
94 | .Xr free 3 , | 98 | .Xr rcmd 3 , |
95 | .Xr malloc 3 , | 99 | .Xr rshd 8 |
96 | .Sh STANDARDS | 100 | .Sh BUGS |
101 | If | ||
102 | .Xr rsh 1 | ||
103 | gets an error a file descriptor is still returned instead of \-1. | ||
104 | .Sh HISTORY | ||
97 | The | 105 | The |
98 | .Fn realloc | 106 | .Fn rcmdsh |
99 | function conforms to | 107 | function first appeared in |
100 | .St -ansiC . | 108 | .Ox 2.0 . |
diff --git a/src/lib/libc/net/rcmdsh.c b/src/lib/libc/net/rcmdsh.c new file mode 100644 index 0000000000..93523a4c56 --- /dev/null +++ b/src/lib/libc/net/rcmdsh.c | |||
@@ -0,0 +1,124 @@ | |||
1 | /* $OpenBSD: rcmdsh.c,v 1.5 1998/04/25 16:23:58 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * This is an rcmd() replacement originally by | ||
5 | * Chris Siebenmann <cks@utcc.utoronto.ca>. | ||
6 | */ | ||
7 | |||
8 | #if defined(LIBC_SCCS) && !defined(lint) | ||
9 | static char *rcsid = "$OpenBSD: rcmdsh.c,v 1.5 1998/04/25 16:23:58 millert Exp $"; | ||
10 | #endif /* LIBC_SCCS and not lint */ | ||
11 | |||
12 | #include <sys/types.h> | ||
13 | #include <sys/socket.h> | ||
14 | #include <sys/wait.h> | ||
15 | #include <signal.h> | ||
16 | #include <errno.h> | ||
17 | #include <netdb.h> | ||
18 | #include <stdio.h> | ||
19 | #include <string.h> | ||
20 | #include <pwd.h> | ||
21 | #include <paths.h> | ||
22 | #include <unistd.h> | ||
23 | |||
24 | /* | ||
25 | * This is a replacement rcmd() function that uses the rsh(1) | ||
26 | * program in place of a direct rcmd(3) function call so as to | ||
27 | * avoid having to be root. Note that rport is ignored. | ||
28 | */ | ||
29 | /* ARGSUSED */ | ||
30 | int | ||
31 | rcmdsh(ahost, rport, locuser, remuser, cmd, rshprog) | ||
32 | char **ahost; | ||
33 | int rport; | ||
34 | const char *locuser, *remuser, *cmd; | ||
35 | char *rshprog; | ||
36 | { | ||
37 | struct hostent *hp; | ||
38 | int cpid, sp[2]; | ||
39 | char *p; | ||
40 | struct passwd *pw; | ||
41 | |||
42 | /* What rsh/shell to use. */ | ||
43 | if (rshprog == NULL) | ||
44 | rshprog = _PATH_RSH; | ||
45 | |||
46 | /* locuser must exist on this host. */ | ||
47 | if ((pw = getpwnam(locuser)) == NULL) { | ||
48 | (void) fprintf(stderr, "rcmdsh: unknown user: %s\n", locuser); | ||
49 | return(-1); | ||
50 | } | ||
51 | |||
52 | /* Validate remote hostname. */ | ||
53 | if (strcmp(*ahost, "localhost") != 0) { | ||
54 | if ((hp = gethostbyname(*ahost)) == NULL) { | ||
55 | herror(*ahost); | ||
56 | return(-1); | ||
57 | } | ||
58 | *ahost = hp->h_name; | ||
59 | } | ||
60 | |||
61 | /* Get a socketpair we'll use for stdin and stdout. */ | ||
62 | if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sp) < 0) { | ||
63 | perror("rcmdsh: socketpair"); | ||
64 | return(-1); | ||
65 | } | ||
66 | |||
67 | cpid = fork(); | ||
68 | if (cpid < 0) { | ||
69 | perror("rcmdsh: fork failed"); | ||
70 | return(-1); | ||
71 | } else if (cpid == 0) { | ||
72 | /* | ||
73 | * Child. We use sp[1] to be stdin/stdout, and close sp[0]. | ||
74 | */ | ||
75 | (void) close(sp[0]); | ||
76 | if (dup2(sp[1], 0) < 0 || dup2(0, 1) < 0) { | ||
77 | perror("rcmdsh: dup2 failed"); | ||
78 | _exit(255); | ||
79 | } | ||
80 | /* Fork again to lose parent. */ | ||
81 | cpid = fork(); | ||
82 | if (cpid < 0) { | ||
83 | perror("rcmdsh: fork to lose parent failed"); | ||
84 | _exit(255); | ||
85 | } | ||
86 | if (cpid > 0) | ||
87 | _exit(0); | ||
88 | |||
89 | /* In grandchild here. Become local user for rshprog. */ | ||
90 | if (setuid(pw->pw_uid)) { | ||
91 | (void) fprintf(stderr, "rcmdsh: setuid(%u): %s\n", | ||
92 | pw->pw_uid, strerror(errno)); | ||
93 | _exit(255); | ||
94 | } | ||
95 | |||
96 | /* | ||
97 | * If remote host is "localhost" and local and remote user | ||
98 | * are the same, avoid running remote shell for efficiency. | ||
99 | */ | ||
100 | if (!strcmp(*ahost, "localhost") && !strcmp(locuser, remuser)) { | ||
101 | if (pw->pw_shell[0] == '\0') | ||
102 | rshprog = _PATH_BSHELL; | ||
103 | else | ||
104 | rshprog = pw->pw_shell; | ||
105 | p = strrchr(rshprog, '/'); | ||
106 | execlp(rshprog, p ? p+1 : rshprog, "-c", cmd, | ||
107 | (char *) NULL); | ||
108 | } else { | ||
109 | p = strrchr(rshprog, '/'); | ||
110 | execlp(rshprog, p ? p+1 : rshprog, *ahost, "-l", | ||
111 | remuser, cmd, (char *) NULL); | ||
112 | } | ||
113 | (void) fprintf(stderr, "rcmdsh: execlp %s failed: %s\n", | ||
114 | rshprog, strerror(errno)); | ||
115 | _exit(255); | ||
116 | } else { | ||
117 | /* Parent. close sp[1], return sp[0]. */ | ||
118 | (void) close(sp[1]); | ||
119 | /* Reap child. */ | ||
120 | (void) wait(NULL); | ||
121 | return(sp[0]); | ||
122 | } | ||
123 | /* NOTREACHED */ | ||
124 | } | ||
diff --git a/src/lib/libc/net/recv.c b/src/lib/libc/net/recv.c index 44296378cb..d209a07213 100644 --- a/src/lib/libc/net/recv.c +++ b/src/lib/libc/net/recv.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: recv.c,v 1.6 1995/02/25 06:20:54 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1988, 1993 | 2 | * Copyright (c) 1988, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: recv.c,v 1.2 1996/08/19 08:29:40 tholo Exp $"; |
38 | static char sccsid[] = "@(#)recv.c 8.2 (Berkeley) 2/21/94"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: recv.c,v 1.6 1995/02/25 06:20:54 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/types.h> | 38 | #include <sys/types.h> |
diff --git a/src/lib/libc/net/res_comp.c b/src/lib/libc/net/res_comp.c index 9d7bbecdda..f7a0358967 100644 --- a/src/lib/libc/net/res_comp.c +++ b/src/lib/libc/net/res_comp.c | |||
@@ -1,9 +1,11 @@ | |||
1 | /* $NetBSD: res_comp.c,v 1.6 1995/02/25 06:20:55 cgd Exp $ */ | 1 | /* $OpenBSD: res_comp.c,v 1.8 1997/07/09 01:08:49 millert Exp $ */ |
2 | 2 | ||
3 | /*- | 3 | /* |
4 | * ++Copyright++ 1985, 1993 | ||
5 | * - | ||
4 | * Copyright (c) 1985, 1993 | 6 | * Copyright (c) 1985, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 7 | * The Regents of the University of California. All rights reserved. |
6 | * | 8 | * |
7 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions |
9 | * are met: | 11 | * are met: |
@@ -14,12 +16,12 @@ | |||
14 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
15 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. All advertising materials mentioning features or use of this software |
16 | * must display the following acknowledgement: | 18 | * must display the following acknowledgement: |
17 | * This product includes software developed by the University of | 19 | * This product includes software developed by the University of |
18 | * California, Berkeley and its contributors. | 20 | * California, Berkeley and its contributors. |
19 | * 4. Neither the name of the University nor the names of its contributors | 21 | * 4. Neither the name of the University nor the names of its contributors |
20 | * may be used to endorse or promote products derived from this software | 22 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. | 23 | * without specific prior written permission. |
22 | * | 24 | * |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -56,19 +58,26 @@ | |||
56 | #if defined(LIBC_SCCS) && !defined(lint) | 58 | #if defined(LIBC_SCCS) && !defined(lint) |
57 | #if 0 | 59 | #if 0 |
58 | static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; | 60 | static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; |
59 | static char rcsid[] = "$Id: res_comp.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel "; | 61 | static char rcsid[] = "$From: res_comp.c,v 8.11 1996/12/02 09:17:22 vixie Exp $"; |
60 | #else | 62 | #else |
61 | static char rcsid[] = "$NetBSD: res_comp.c,v 1.6 1995/02/25 06:20:55 cgd Exp $"; | 63 | static char rcsid[] = "$OpenBSD: res_comp.c,v 1.8 1997/07/09 01:08:49 millert Exp $"; |
62 | #endif | 64 | #endif |
63 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
64 | 66 | ||
67 | #include <sys/types.h> | ||
65 | #include <sys/param.h> | 68 | #include <sys/param.h> |
66 | #include <arpa/nameser.h> | ||
67 | #include <netinet/in.h> | 69 | #include <netinet/in.h> |
68 | #include <resolv.h> | 70 | #include <arpa/nameser.h> |
71 | |||
69 | #include <stdio.h> | 72 | #include <stdio.h> |
73 | #include <resolv.h> | ||
74 | #include <ctype.h> | ||
70 | 75 | ||
71 | static int dn_find(); | 76 | #include <unistd.h> |
77 | #include <string.h> | ||
78 | |||
79 | static int dn_find __P((u_char *exp_dn, u_char *msg, | ||
80 | u_char **dnptrs, u_char **lastdnptr)); | ||
72 | 81 | ||
73 | /* | 82 | /* |
74 | * Expand compressed domain name 'comp_dn' to full domain name. | 83 | * Expand compressed domain name 'comp_dn' to full domain name. |
@@ -77,23 +86,27 @@ static int dn_find(); | |||
77 | * 'exp_dn' is a pointer to a buffer of size 'length' for the result. | 86 | * 'exp_dn' is a pointer to a buffer of size 'length' for the result. |
78 | * Return size of compressed name or -1 if there was an error. | 87 | * Return size of compressed name or -1 if there was an error. |
79 | */ | 88 | */ |
89 | int | ||
80 | dn_expand(msg, eomorig, comp_dn, exp_dn, length) | 90 | dn_expand(msg, eomorig, comp_dn, exp_dn, length) |
81 | const u_char *msg, *eomorig, *comp_dn; | 91 | const u_char *msg, *eomorig, *comp_dn; |
82 | u_char *exp_dn; | 92 | char *exp_dn; |
83 | int length; | 93 | int length; |
84 | { | 94 | { |
85 | register u_char *cp, *dn; | 95 | register const u_char *cp; |
96 | register char *dn; | ||
86 | register int n, c; | 97 | register int n, c; |
87 | u_char *eom; | 98 | char *eom; |
88 | int len = -1, checked = 0; | 99 | int len = -1, checked = 0; |
89 | 100 | ||
90 | dn = exp_dn; | 101 | dn = exp_dn; |
91 | cp = (u_char *)comp_dn; | 102 | cp = comp_dn; |
103 | if (length > MAXHOSTNAMELEN-1) | ||
104 | length = MAXHOSTNAMELEN-1; | ||
92 | eom = exp_dn + length; | 105 | eom = exp_dn + length; |
93 | /* | 106 | /* |
94 | * fetch next label in domain name | 107 | * fetch next label in domain name |
95 | */ | 108 | */ |
96 | while (n = *cp++) { | 109 | while ((n = *cp++)) { |
97 | /* | 110 | /* |
98 | * Check for indirection | 111 | * Check for indirection |
99 | */ | 112 | */ |
@@ -108,23 +121,23 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) | |||
108 | return (-1); | 121 | return (-1); |
109 | checked += n + 1; | 122 | checked += n + 1; |
110 | while (--n >= 0) { | 123 | while (--n >= 0) { |
111 | if ((c = *cp++) == '.') { | 124 | if (((c = *cp++) == '.') || (c == '\\')) { |
112 | if (dn + n + 2 >= eom) | 125 | if (dn + n + 2 >= eom) |
113 | return (-1); | 126 | return (-1); |
114 | *dn++ = '\\'; | 127 | *dn++ = '\\'; |
115 | } | 128 | } |
116 | *dn++ = c; | 129 | *dn++ = c; |
117 | if (cp >= eomorig) /* out of range */ | 130 | if (cp >= eomorig) /* out of range */ |
118 | return(-1); | 131 | return (-1); |
119 | } | 132 | } |
120 | break; | 133 | break; |
121 | 134 | ||
122 | case INDIR_MASK: | 135 | case INDIR_MASK: |
123 | if (len < 0) | 136 | if (len < 0) |
124 | len = cp - comp_dn + 1; | 137 | len = cp - comp_dn + 1; |
125 | cp = (u_char *)msg + (((n & 0x3f) << 8) | (*cp & 0xff)); | 138 | cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff)); |
126 | if (cp < msg || cp >= eomorig) /* out of range */ | 139 | if (cp < msg || cp >= eomorig) /* out of range */ |
127 | return(-1); | 140 | return (-1); |
128 | checked += 2; | 141 | checked += 2; |
129 | /* | 142 | /* |
130 | * Check for loops in the compressed name; | 143 | * Check for loops in the compressed name; |
@@ -157,8 +170,9 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) | |||
157 | * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' | 170 | * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' |
158 | * is NULL, we don't update the list. | 171 | * is NULL, we don't update the list. |
159 | */ | 172 | */ |
173 | int | ||
160 | dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) | 174 | dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) |
161 | const u_char *exp_dn; | 175 | const char *exp_dn; |
162 | u_char *comp_dn, **dnptrs, **lastdnptr; | 176 | u_char *comp_dn, **dnptrs, **lastdnptr; |
163 | int length; | 177 | int length; |
164 | { | 178 | { |
@@ -170,6 +184,7 @@ dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) | |||
170 | dn = (u_char *)exp_dn; | 184 | dn = (u_char *)exp_dn; |
171 | cp = comp_dn; | 185 | cp = comp_dn; |
172 | eob = cp + length; | 186 | eob = cp + length; |
187 | lpp = cpp = NULL; | ||
173 | if (dnptrs != NULL) { | 188 | if (dnptrs != NULL) { |
174 | if ((msg = *dnptrs++) != NULL) { | 189 | if ((msg = *dnptrs++) != NULL) { |
175 | for (cpp = dnptrs; *cpp != NULL; cpp++) | 190 | for (cpp = dnptrs; *cpp != NULL; cpp++) |
@@ -235,13 +250,14 @@ dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) | |||
235 | /* | 250 | /* |
236 | * Skip over a compressed domain name. Return the size or -1. | 251 | * Skip over a compressed domain name. Return the size or -1. |
237 | */ | 252 | */ |
253 | int | ||
238 | __dn_skipname(comp_dn, eom) | 254 | __dn_skipname(comp_dn, eom) |
239 | const u_char *comp_dn, *eom; | 255 | const u_char *comp_dn, *eom; |
240 | { | 256 | { |
241 | register u_char *cp; | 257 | register const u_char *cp; |
242 | register int n; | 258 | register int n; |
243 | 259 | ||
244 | cp = (u_char *)comp_dn; | 260 | cp = comp_dn; |
245 | while (cp < eom && (n = *cp++)) { | 261 | while (cp < eom && (n = *cp++)) { |
246 | /* | 262 | /* |
247 | * check for indirection | 263 | * check for indirection |
@@ -259,10 +275,19 @@ __dn_skipname(comp_dn, eom) | |||
259 | break; | 275 | break; |
260 | } | 276 | } |
261 | if (cp > eom) | 277 | if (cp > eom) |
262 | return -1; | 278 | return (-1); |
263 | return (cp - comp_dn); | 279 | return (cp - comp_dn); |
264 | } | 280 | } |
265 | 281 | ||
282 | static int | ||
283 | mklower(ch) | ||
284 | register int ch; | ||
285 | { | ||
286 | if (isascii(ch) && isupper(ch)) | ||
287 | return (tolower(ch)); | ||
288 | return (ch); | ||
289 | } | ||
290 | |||
266 | /* | 291 | /* |
267 | * Search for expanded name from a list of previously compressed names. | 292 | * Search for expanded name from a list of previously compressed names. |
268 | * Return the offset from msg if found or -1. | 293 | * Return the offset from msg if found or -1. |
@@ -281,7 +306,7 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) | |||
281 | for (cpp = dnptrs; cpp < lastdnptr; cpp++) { | 306 | for (cpp = dnptrs; cpp < lastdnptr; cpp++) { |
282 | dn = exp_dn; | 307 | dn = exp_dn; |
283 | sp = cp = *cpp; | 308 | sp = cp = *cpp; |
284 | while (n = *cp++) { | 309 | while ((n = *cp++)) { |
285 | /* | 310 | /* |
286 | * check for indirection | 311 | * check for indirection |
287 | */ | 312 | */ |
@@ -292,7 +317,7 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) | |||
292 | goto next; | 317 | goto next; |
293 | if (*dn == '\\') | 318 | if (*dn == '\\') |
294 | dn++; | 319 | dn++; |
295 | if (*dn++ != *cp++) | 320 | if (mklower(*dn++) != mklower(*cp++)) |
296 | goto next; | 321 | goto next; |
297 | } | 322 | } |
298 | if ((n = *dn++) == '\0' && *cp == '\0') | 323 | if ((n = *dn++) == '\0' && *cp == '\0') |
@@ -301,11 +326,12 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) | |||
301 | continue; | 326 | continue; |
302 | goto next; | 327 | goto next; |
303 | 328 | ||
304 | default: /* illegal type */ | ||
305 | return (-1); | ||
306 | |||
307 | case INDIR_MASK: /* indirection */ | 329 | case INDIR_MASK: /* indirection */ |
308 | cp = msg + (((n & 0x3f) << 8) | *cp); | 330 | cp = msg + (((n & 0x3f) << 8) | *cp); |
331 | break; | ||
332 | |||
333 | default: /* illegal type */ | ||
334 | return (-1); | ||
309 | } | 335 | } |
310 | } | 336 | } |
311 | if (*dn == '\0') | 337 | if (*dn == '\0') |
@@ -316,16 +342,124 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) | |||
316 | } | 342 | } |
317 | 343 | ||
318 | /* | 344 | /* |
319 | * Routines to insert/extract short/long's. Must account for byte | 345 | * Verify that a domain name uses an acceptable character set. |
320 | * order and non-alignment problems. This code at least has the | 346 | */ |
321 | * advantage of being portable. | 347 | |
322 | * | 348 | /* |
323 | * used by sendmail. | 349 | * Note the conspicuous absence of ctype macros in these definitions. On |
350 | * non-ASCII hosts, we can't depend on string literals or ctype macros to | ||
351 | * tell us anything about network-format data. The rest of the BIND system | ||
352 | * is not careful about this, but for some reason, we're doing it right here. | ||
353 | */ | ||
354 | #define PERIOD 0x2e | ||
355 | #define hyphenchar(c) ((c) == 0x2d) | ||
356 | #define bslashchar(c) ((c) == 0x5c) | ||
357 | #define periodchar(c) ((c) == PERIOD) | ||
358 | #define asterchar(c) ((c) == 0x2a) | ||
359 | #define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \ | ||
360 | || ((c) >= 0x61 && (c) <= 0x7a)) | ||
361 | #define digitchar(c) ((c) >= 0x30 && (c) <= 0x39) | ||
362 | |||
363 | #define borderchar(c) (alphachar(c) || digitchar(c)) | ||
364 | #define middlechar(c) (borderchar(c) || hyphenchar(c)) | ||
365 | #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) | ||
366 | |||
367 | int | ||
368 | res_hnok(dn) | ||
369 | const char *dn; | ||
370 | { | ||
371 | int pch = PERIOD, ch = *dn++; | ||
372 | |||
373 | while (ch != '\0') { | ||
374 | int nch = *dn++; | ||
375 | |||
376 | if (periodchar(ch)) { | ||
377 | ; | ||
378 | } else if (periodchar(pch)) { | ||
379 | if (!borderchar(ch)) | ||
380 | return (0); | ||
381 | } else if (periodchar(nch) || nch == '\0') { | ||
382 | if (!borderchar(ch)) | ||
383 | return (0); | ||
384 | } else { | ||
385 | if (!middlechar(ch)) | ||
386 | return (0); | ||
387 | } | ||
388 | pch = ch, ch = nch; | ||
389 | } | ||
390 | return (1); | ||
391 | } | ||
392 | |||
393 | /* | ||
394 | * hostname-like (A, MX, WKS) owners can have "*" as their first label | ||
395 | * but must otherwise be as a host name. | ||
396 | */ | ||
397 | int | ||
398 | res_ownok(dn) | ||
399 | const char *dn; | ||
400 | { | ||
401 | if (asterchar(dn[0])) { | ||
402 | if (periodchar(dn[1])) | ||
403 | return (res_hnok(dn+2)); | ||
404 | if (dn[1] == '\0') | ||
405 | return (1); | ||
406 | } | ||
407 | return (res_hnok(dn)); | ||
408 | } | ||
409 | |||
410 | /* | ||
411 | * SOA RNAMEs and RP RNAMEs can have any printable character in their first | ||
412 | * label, but the rest of the name has to look like a host name. | ||
324 | */ | 413 | */ |
414 | int | ||
415 | res_mailok(dn) | ||
416 | const char *dn; | ||
417 | { | ||
418 | int ch, escaped = 0; | ||
419 | |||
420 | /* "." is a valid missing representation */ | ||
421 | if (*dn == '\0') | ||
422 | return(1); | ||
423 | |||
424 | /* otherwise <label>.<hostname> */ | ||
425 | while ((ch = *dn++) != '\0') { | ||
426 | if (!domainchar(ch)) | ||
427 | return (0); | ||
428 | if (!escaped && periodchar(ch)) | ||
429 | break; | ||
430 | if (escaped) | ||
431 | escaped = 0; | ||
432 | else if (bslashchar(ch)) | ||
433 | escaped = 1; | ||
434 | } | ||
435 | if (periodchar(ch)) | ||
436 | return (res_hnok(dn)); | ||
437 | return(0); | ||
438 | } | ||
325 | 439 | ||
326 | u_short | 440 | /* |
441 | * This function is quite liberal, since RFC 1034's character sets are only | ||
442 | * recommendations. | ||
443 | */ | ||
444 | int | ||
445 | res_dnok(dn) | ||
446 | const char *dn; | ||
447 | { | ||
448 | int ch; | ||
449 | |||
450 | while ((ch = *dn++) != '\0') | ||
451 | if (!domainchar(ch)) | ||
452 | return (0); | ||
453 | return (1); | ||
454 | } | ||
455 | |||
456 | /* | ||
457 | * Routines to insert/extract short/long's. | ||
458 | */ | ||
459 | |||
460 | u_int16_t | ||
327 | _getshort(msgp) | 461 | _getshort(msgp) |
328 | register u_char *msgp; | 462 | register const u_char *msgp; |
329 | { | 463 | { |
330 | register u_int16_t u; | 464 | register u_int16_t u; |
331 | 465 | ||
@@ -333,9 +467,21 @@ _getshort(msgp) | |||
333 | return (u); | 467 | return (u); |
334 | } | 468 | } |
335 | 469 | ||
470 | #ifdef NeXT | ||
471 | /* | ||
472 | * nExt machines have some funky library conventions, which we must maintain. | ||
473 | */ | ||
474 | u_int16_t | ||
475 | res_getshort(msgp) | ||
476 | register const u_char *msgp; | ||
477 | { | ||
478 | return (_getshort(msgp)); | ||
479 | } | ||
480 | #endif | ||
481 | |||
336 | u_int32_t | 482 | u_int32_t |
337 | _getlong(msgp) | 483 | _getlong(msgp) |
338 | register u_char *msgp; | 484 | register const u_char *msgp; |
339 | { | 485 | { |
340 | register u_int32_t u; | 486 | register u_int32_t u; |
341 | 487 | ||
@@ -345,7 +491,7 @@ _getlong(msgp) | |||
345 | 491 | ||
346 | void | 492 | void |
347 | #if defined(__STDC__) || defined(__cplusplus) | 493 | #if defined(__STDC__) || defined(__cplusplus) |
348 | __putshort(register u_int16_t s, register u_char *msgp) | 494 | __putshort(register u_int16_t s, register u_char *msgp) /* must match proto */ |
349 | #else | 495 | #else |
350 | __putshort(s, msgp) | 496 | __putshort(s, msgp) |
351 | register u_int16_t s; | 497 | register u_int16_t s; |
diff --git a/src/lib/libc/net/res_data.c b/src/lib/libc/net/res_data.c new file mode 100644 index 0000000000..b0d19c36bb --- /dev/null +++ b/src/lib/libc/net/res_data.c | |||
@@ -0,0 +1,117 @@ | |||
1 | /* $OpenBSD: res_data.c,v 1.1 1997/03/13 19:07:36 downsj Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * ++Copyright++ 1995 | ||
5 | * - | ||
6 | * Copyright (c) 1995 | ||
7 | * The Regents of the University of California. All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * 2. Redistributions in binary form must reproduce the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer in the | ||
16 | * documentation and/or other materials provided with the distribution. | ||
17 | * 3. All advertising materials mentioning features or use of this software | ||
18 | * must display the following acknowledgement: | ||
19 | * This product includes software developed by the University of | ||
20 | * California, Berkeley and its contributors. | ||
21 | * 4. Neither the name of the University nor the names of its contributors | ||
22 | * may be used to endorse or promote products derived from this software | ||
23 | * without specific prior written permission. | ||
24 | * | ||
25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
35 | * SUCH DAMAGE. | ||
36 | * - | ||
37 | * Portions Copyright (c) 1993 by Digital Equipment Corporation. | ||
38 | * | ||
39 | * Permission to use, copy, modify, and distribute this software for any | ||
40 | * purpose with or without fee is hereby granted, provided that the above | ||
41 | * copyright notice and this permission notice appear in all copies, and that | ||
42 | * the name of Digital Equipment Corporation not be used in advertising or | ||
43 | * publicity pertaining to distribution of the document or software without | ||
44 | * specific, written prior permission. | ||
45 | * | ||
46 | * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL | ||
47 | * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES | ||
48 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT | ||
49 | * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
50 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
51 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
52 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
53 | * SOFTWARE. | ||
54 | * - | ||
55 | * --Copyright-- | ||
56 | */ | ||
57 | |||
58 | #if defined(LIBC_SCCS) && !defined(lint) | ||
59 | #if 0 | ||
60 | static char rcsid[] = "$From: res_data.c,v 8.2 1996/08/05 08:31:35 vixie Exp $"; | ||
61 | #else | ||
62 | static char rcsid[] = "$OpenBSD: res_data.c,v 1.1 1997/03/13 19:07:36 downsj Exp $"; | ||
63 | #endif | ||
64 | #endif /* LIBC_SCCS and not lint */ | ||
65 | |||
66 | #include <sys/types.h> | ||
67 | #include <sys/param.h> | ||
68 | #include <sys/socket.h> | ||
69 | #include <sys/time.h> | ||
70 | #include <netinet/in.h> | ||
71 | #include <arpa/inet.h> | ||
72 | #include <arpa/nameser.h> | ||
73 | |||
74 | #include <stdio.h> | ||
75 | #include <ctype.h> | ||
76 | #include <resolv.h> | ||
77 | #include <unistd.h> | ||
78 | #include <stdlib.h> | ||
79 | #include <string.h> | ||
80 | |||
81 | const char *_res_opcodes[] = { | ||
82 | "QUERY", | ||
83 | "IQUERY", | ||
84 | "CQUERYM", | ||
85 | "CQUERYU", /* experimental */ | ||
86 | "NOTIFY", /* experimental */ | ||
87 | "5", | ||
88 | "6", | ||
89 | "7", | ||
90 | "8", | ||
91 | "UPDATEA", | ||
92 | "UPDATED", | ||
93 | "UPDATEDA", | ||
94 | "UPDATEM", | ||
95 | "UPDATEMA", | ||
96 | "ZONEINIT", | ||
97 | "ZONEREF", | ||
98 | }; | ||
99 | |||
100 | const char *_res_resultcodes[] = { | ||
101 | "NOERROR", | ||
102 | "FORMERR", | ||
103 | "SERVFAIL", | ||
104 | "NXDOMAIN", | ||
105 | "NOTIMP", | ||
106 | "REFUSED", | ||
107 | "6", | ||
108 | "7", | ||
109 | "8", | ||
110 | "9", | ||
111 | "10", | ||
112 | "11", | ||
113 | "12", | ||
114 | "13", | ||
115 | "14", | ||
116 | "NOCHANGE", | ||
117 | }; | ||
diff --git a/src/lib/libc/net/res_debug.c b/src/lib/libc/net/res_debug.c index d841293f18..c2725395a0 100644 --- a/src/lib/libc/net/res_debug.c +++ b/src/lib/libc/net/res_debug.c | |||
@@ -1,9 +1,11 @@ | |||
1 | /* $NetBSD: res_debug.c,v 1.7 1995/02/25 06:20:56 cgd Exp $ */ | 1 | /* $OpenBSD: res_debug.c,v 1.9 1998/03/19 00:30:06 millert Exp $ */ |
2 | 2 | ||
3 | /*- | 3 | /* |
4 | * ++Copyright++ 1985, 1990, 1993 | ||
5 | * - | ||
4 | * Copyright (c) 1985, 1990, 1993 | 6 | * Copyright (c) 1985, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 7 | * The Regents of the University of California. All rights reserved. |
6 | * | 8 | * |
7 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions |
9 | * are met: | 11 | * are met: |
@@ -50,174 +52,185 @@ | |||
50 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | 52 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
51 | * SOFTWARE. | 53 | * SOFTWARE. |
52 | * - | 54 | * - |
55 | * Portions Copyright (c) 1995 by International Business Machines, Inc. | ||
56 | * | ||
57 | * International Business Machines, Inc. (hereinafter called IBM) grants | ||
58 | * permission under its copyrights to use, copy, modify, and distribute this | ||
59 | * Software with or without fee, provided that the above copyright notice and | ||
60 | * all paragraphs of this notice appear in all copies, and that the name of IBM | ||
61 | * not be used in connection with the marketing of any product incorporating | ||
62 | * the Software or modifications thereof, without specific, written prior | ||
63 | * permission. | ||
64 | * | ||
65 | * To the extent it has a right to do so, IBM grants an immunity from suit | ||
66 | * under its patents, if any, for the use, sale or manufacture of products to | ||
67 | * the extent that such products are used for performing Domain Name System | ||
68 | * dynamic updates in TCP/IP networks by means of the Software. No immunity is | ||
69 | * granted for any product per se or for any other function of any product. | ||
70 | * | ||
71 | * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, | ||
72 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
73 | * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, | ||
74 | * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING | ||
75 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN | ||
76 | * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. | ||
53 | * --Copyright-- | 77 | * --Copyright-- |
54 | */ | 78 | */ |
55 | 79 | ||
56 | #if defined(LIBC_SCCS) && !defined(lint) | 80 | #if defined(LIBC_SCCS) && !defined(lint) |
57 | #if 0 | 81 | #if 0 |
58 | static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; | 82 | static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; |
83 | static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $"; | ||
59 | #else | 84 | #else |
60 | static char rcsid[] = "$NetBSD: res_debug.c,v 1.7 1995/02/25 06:20:56 cgd Exp $"; | 85 | static char rcsid[] = "$OpenBSD: res_debug.c,v 1.9 1998/03/19 00:30:06 millert Exp $"; |
61 | #endif | 86 | #endif |
62 | #endif /* LIBC_SCCS and not lint */ | 87 | #endif /* LIBC_SCCS and not lint */ |
63 | 88 | ||
64 | #include <sys/param.h> | 89 | #include <sys/param.h> |
90 | #include <sys/types.h> | ||
91 | #include <sys/socket.h> | ||
65 | #include <netinet/in.h> | 92 | #include <netinet/in.h> |
66 | #include <arpa/inet.h> | 93 | #include <arpa/inet.h> |
67 | #include <arpa/nameser.h> | 94 | #include <arpa/nameser.h> |
95 | |||
96 | #include <ctype.h> | ||
97 | #include <netdb.h> | ||
68 | #include <resolv.h> | 98 | #include <resolv.h> |
69 | #include <stdio.h> | 99 | #include <stdio.h> |
70 | #include <string.h> | 100 | #include <time.h> |
71 | 101 | ||
72 | void __fp_query(); | 102 | #include <stdlib.h> |
73 | char *__p_class(), *__p_time(), *__p_type(); | 103 | #include <string.h> |
74 | char *p_cdname(), *p_fqname(), *p_rr(); | ||
75 | static char *p_option __P((u_int32_t)); | ||
76 | |||
77 | char *_res_opcodes[] = { | ||
78 | "QUERY", | ||
79 | "IQUERY", | ||
80 | "CQUERYM", | ||
81 | "CQUERYU", | ||
82 | "4", | ||
83 | "5", | ||
84 | "6", | ||
85 | "7", | ||
86 | "8", | ||
87 | "UPDATEA", | ||
88 | "UPDATED", | ||
89 | "UPDATEDA", | ||
90 | "UPDATEM", | ||
91 | "UPDATEMA", | ||
92 | "ZONEINIT", | ||
93 | "ZONEREF", | ||
94 | }; | ||
95 | |||
96 | char *_res_resultcodes[] = { | ||
97 | "NOERROR", | ||
98 | "FORMERR", | ||
99 | "SERVFAIL", | ||
100 | "NXDOMAIN", | ||
101 | "NOTIMP", | ||
102 | "REFUSED", | ||
103 | "6", | ||
104 | "7", | ||
105 | "8", | ||
106 | "9", | ||
107 | "10", | ||
108 | "11", | ||
109 | "12", | ||
110 | "13", | ||
111 | "14", | ||
112 | "NOCHANGE", | ||
113 | }; | ||
114 | 104 | ||
115 | static char retbuf[16]; | 105 | extern const char *_res_opcodes[]; |
106 | extern const char *_res_resultcodes[]; | ||
116 | 107 | ||
117 | static char * | 108 | /* XXX: we should use getservbyport() instead. */ |
109 | static const char * | ||
118 | dewks(wks) | 110 | dewks(wks) |
119 | int wks; | 111 | int wks; |
120 | { | 112 | { |
113 | static char nbuf[20]; | ||
114 | |||
121 | switch (wks) { | 115 | switch (wks) { |
122 | case 5: return("rje"); | 116 | case 5: return "rje"; |
123 | case 7: return("echo"); | 117 | case 7: return "echo"; |
124 | case 9: return("discard"); | 118 | case 9: return "discard"; |
125 | case 11: return("systat"); | 119 | case 11: return "systat"; |
126 | case 13: return("daytime"); | 120 | case 13: return "daytime"; |
127 | case 15: return("netstat"); | 121 | case 15: return "netstat"; |
128 | case 17: return("qotd"); | 122 | case 17: return "qotd"; |
129 | case 19: return("chargen"); | 123 | case 19: return "chargen"; |
130 | case 20: return("ftp-data"); | 124 | case 20: return "ftp-data"; |
131 | case 21: return("ftp"); | 125 | case 21: return "ftp"; |
132 | case 23: return("telnet"); | 126 | case 23: return "telnet"; |
133 | case 25: return("smtp"); | 127 | case 25: return "smtp"; |
134 | case 37: return("time"); | 128 | case 37: return "time"; |
135 | case 39: return("rlp"); | 129 | case 39: return "rlp"; |
136 | case 42: return("name"); | 130 | case 42: return "name"; |
137 | case 43: return("whois"); | 131 | case 43: return "whois"; |
138 | case 53: return("domain"); | 132 | case 53: return "domain"; |
139 | case 57: return("apts"); | 133 | case 57: return "apts"; |
140 | case 59: return("apfs"); | 134 | case 59: return "apfs"; |
141 | case 67: return("bootps"); | 135 | case 67: return "bootps"; |
142 | case 68: return("bootpc"); | 136 | case 68: return "bootpc"; |
143 | case 69: return("tftp"); | 137 | case 69: return "tftp"; |
144 | case 77: return("rje"); | 138 | case 77: return "rje"; |
145 | case 79: return("finger"); | 139 | case 79: return "finger"; |
146 | case 87: return("link"); | 140 | case 87: return "link"; |
147 | case 95: return("supdup"); | 141 | case 95: return "supdup"; |
148 | case 100: return("newacct"); | 142 | case 100: return "newacct"; |
149 | case 101: return("hostnames"); | 143 | case 101: return "hostnames"; |
150 | case 102: return("iso-tsap"); | 144 | case 102: return "iso-tsap"; |
151 | case 103: return("x400"); | 145 | case 103: return "x400"; |
152 | case 104: return("x400-snd"); | 146 | case 104: return "x400-snd"; |
153 | case 105: return("csnet-ns"); | 147 | case 105: return "csnet-ns"; |
154 | case 109: return("pop-2"); | 148 | case 109: return "pop-2"; |
155 | case 111: return("sunrpc"); | 149 | case 111: return "sunrpc"; |
156 | case 113: return("auth"); | 150 | case 113: return "auth"; |
157 | case 115: return("sftp"); | 151 | case 115: return "sftp"; |
158 | case 117: return("uucp-path"); | 152 | case 117: return "uucp-path"; |
159 | case 119: return("nntp"); | 153 | case 119: return "nntp"; |
160 | case 121: return("erpc"); | 154 | case 121: return "erpc"; |
161 | case 123: return("ntp"); | 155 | case 123: return "ntp"; |
162 | case 133: return("statsrv"); | 156 | case 133: return "statsrv"; |
163 | case 136: return("profile"); | 157 | case 136: return "profile"; |
164 | case 144: return("NeWS"); | 158 | case 144: return "NeWS"; |
165 | case 161: return("snmp"); | 159 | case 161: return "snmp"; |
166 | case 162: return("snmp-trap"); | 160 | case 162: return "snmp-trap"; |
167 | case 170: return("print-srv"); | 161 | case 170: return "print-srv"; |
168 | default: (void) sprintf(retbuf, "%d", wks); return(retbuf); | 162 | default: (void) sprintf(nbuf, "%d", wks); return (nbuf); |
169 | } | 163 | } |
170 | } | 164 | } |
171 | 165 | ||
172 | static char * | 166 | /* XXX: we should use getprotobynumber() instead. */ |
167 | static const char * | ||
173 | deproto(protonum) | 168 | deproto(protonum) |
174 | int protonum; | 169 | int protonum; |
175 | { | 170 | { |
171 | static char nbuf[20]; | ||
172 | |||
176 | switch (protonum) { | 173 | switch (protonum) { |
177 | case 1: return("icmp"); | 174 | case 1: return "icmp"; |
178 | case 2: return("igmp"); | 175 | case 2: return "igmp"; |
179 | case 3: return("ggp"); | 176 | case 3: return "ggp"; |
180 | case 5: return("st"); | 177 | case 5: return "st"; |
181 | case 6: return("tcp"); | 178 | case 6: return "tcp"; |
182 | case 7: return("ucl"); | 179 | case 7: return "ucl"; |
183 | case 8: return("egp"); | 180 | case 8: return "egp"; |
184 | case 9: return("igp"); | 181 | case 9: return "igp"; |
185 | case 11: return("nvp-II"); | 182 | case 11: return "nvp-II"; |
186 | case 12: return("pup"); | 183 | case 12: return "pup"; |
187 | case 16: return("chaos"); | 184 | case 16: return "chaos"; |
188 | case 17: return("udp"); | 185 | case 17: return "udp"; |
189 | default: (void) sprintf(retbuf, "%d", protonum); return(retbuf); | 186 | default: (void) sprintf(nbuf, "%d", protonum); return (nbuf); |
190 | } | 187 | } |
191 | } | 188 | } |
192 | 189 | ||
193 | static char * | 190 | static const u_char * |
194 | do_rrset(msg, cp, cnt, pflag, file, hs) | 191 | do_rrset(msg, len, cp, cnt, pflag, file, hs) |
195 | int cnt, pflag; | 192 | int cnt, pflag, len; |
196 | char *cp,*msg, *hs; | 193 | const u_char *cp, *msg; |
194 | const char *hs; | ||
197 | FILE *file; | 195 | FILE *file; |
198 | { | 196 | { |
199 | int n; | 197 | int n; |
200 | int sflag; | 198 | int sflag; |
199 | |||
201 | /* | 200 | /* |
202 | * Print answer records | 201 | * Print answer records. |
203 | */ | 202 | */ |
204 | sflag = (_res.pfcode & pflag); | 203 | sflag = (_res.pfcode & pflag); |
205 | if (n = ntohs(cnt)) { | 204 | if ((n = ntohs(cnt))) { |
206 | if ((!_res.pfcode) || ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) | 205 | if ((!_res.pfcode) || |
206 | ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) | ||
207 | fprintf(file, hs); | 207 | fprintf(file, hs); |
208 | while (--n >= 0) { | 208 | while (--n >= 0) { |
209 | cp = p_rr(cp, msg, file); | 209 | if ((!_res.pfcode) || sflag) { |
210 | if ((cp-msg) > PACKETSZ) | 210 | cp = p_rr(cp, msg, file); |
211 | } else { | ||
212 | unsigned int dlen; | ||
213 | cp += __dn_skipname(cp, cp + MAXCDNAME); | ||
214 | cp += INT16SZ; | ||
215 | cp += INT16SZ; | ||
216 | cp += INT32SZ; | ||
217 | dlen = _getshort((u_char*)cp); | ||
218 | cp += INT16SZ; | ||
219 | cp += dlen; | ||
220 | } | ||
221 | if ((cp - msg) > len) | ||
211 | return (NULL); | 222 | return (NULL); |
212 | } | 223 | } |
213 | if ((!_res.pfcode) || ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) | 224 | if ((!_res.pfcode) || |
225 | ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) | ||
214 | putc('\n', file); | 226 | putc('\n', file); |
215 | } | 227 | } |
216 | return(cp); | 228 | return (cp); |
217 | } | 229 | } |
218 | 230 | ||
231 | void | ||
219 | __p_query(msg) | 232 | __p_query(msg) |
220 | char *msg; | 233 | const u_char *msg; |
221 | { | 234 | { |
222 | __fp_query(msg, stdout); | 235 | __fp_query(msg, stdout); |
223 | } | 236 | } |
@@ -231,15 +244,14 @@ __fp_resstat(statp, file) | |||
231 | struct __res_state *statp; | 244 | struct __res_state *statp; |
232 | FILE *file; | 245 | FILE *file; |
233 | { | 246 | { |
234 | int bit; | 247 | register u_long mask; |
235 | 248 | ||
236 | fprintf(file, ";; res options:"); | 249 | fprintf(file, ";; res options:"); |
237 | if (!statp) | 250 | if (!statp) |
238 | statp = &_res; | 251 | statp = &_res; |
239 | for (bit = 0; bit < 32; bit++) { /* XXX 32 - bad assumption! */ | 252 | for (mask = 1; mask != 0; mask <<= 1) |
240 | if (statp->options & (1<<bit)) | 253 | if (statp->options & mask) |
241 | fprintf(file, " %s", p_option(1<<bit)); | 254 | fprintf(file, " %s", p_option(mask)); |
242 | } | ||
243 | putc('\n', file); | 255 | putc('\n', file); |
244 | } | 256 | } |
245 | 257 | ||
@@ -248,109 +260,151 @@ __fp_resstat(statp, file) | |||
248 | * This is intended to be primarily a debugging routine. | 260 | * This is intended to be primarily a debugging routine. |
249 | */ | 261 | */ |
250 | void | 262 | void |
251 | __fp_query(msg,file) | 263 | __fp_nquery(msg, len, file) |
252 | char *msg; | 264 | const u_char *msg; |
265 | int len; | ||
253 | FILE *file; | 266 | FILE *file; |
254 | { | 267 | { |
255 | register char *cp; | 268 | register const u_char *cp, *endMark; |
256 | register HEADER *hp; | 269 | register const HEADER *hp; |
257 | register int n; | 270 | register int n; |
258 | 271 | ||
272 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | ||
273 | return; | ||
274 | |||
275 | #define TruncTest(x) if (x > endMark) goto trunc | ||
276 | #define ErrorTest(x) if (x == NULL) goto error | ||
277 | |||
259 | /* | 278 | /* |
260 | * Print header fields. | 279 | * Print header fields. |
261 | */ | 280 | */ |
262 | hp = (HEADER *)msg; | 281 | hp = (HEADER *)msg; |
263 | cp = msg + sizeof(HEADER); | 282 | cp = msg + HFIXEDSZ; |
283 | endMark = msg + len; | ||
264 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || hp->rcode) { | 284 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || hp->rcode) { |
265 | fprintf(file,";; ->>HEADER<<- opcode: %s, status: %s, id: %d", | 285 | fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d", |
266 | _res_opcodes[hp->opcode], | 286 | _res_opcodes[hp->opcode], |
267 | _res_resultcodes[hp->rcode], | 287 | _res_resultcodes[hp->rcode], |
268 | ntohs(hp->id)); | 288 | ntohs(hp->id)); |
269 | putc('\n', file); | 289 | putc('\n', file); |
270 | } | 290 | } |
271 | putc(';', file); | 291 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX)) |
292 | putc(';', file); | ||
272 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) { | 293 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) { |
273 | fprintf(file,"; flags:"); | 294 | fprintf(file, "; flags:"); |
274 | if (hp->qr) | 295 | if (hp->qr) |
275 | fprintf(file," qr"); | 296 | fprintf(file, " qr"); |
276 | if (hp->aa) | 297 | if (hp->aa) |
277 | fprintf(file," aa"); | 298 | fprintf(file, " aa"); |
278 | if (hp->tc) | 299 | if (hp->tc) |
279 | fprintf(file," tc"); | 300 | fprintf(file, " tc"); |
280 | if (hp->rd) | 301 | if (hp->rd) |
281 | fprintf(file," rd"); | 302 | fprintf(file, " rd"); |
282 | if (hp->ra) | 303 | if (hp->ra) |
283 | fprintf(file," ra"); | 304 | fprintf(file, " ra"); |
284 | if (hp->pr) | 305 | if (hp->unused) |
285 | fprintf(file," pr"); | 306 | fprintf(file, " UNUSED-BIT-ON"); |
307 | if (hp->ad) | ||
308 | fprintf(file, " ad"); | ||
309 | if (hp->cd) | ||
310 | fprintf(file, " cd"); | ||
286 | } | 311 | } |
287 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) { | 312 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) { |
288 | fprintf(file,"; Ques: %d", ntohs(hp->qdcount)); | 313 | fprintf(file, "; Ques: %d", ntohs(hp->qdcount)); |
289 | fprintf(file,", Ans: %d", ntohs(hp->ancount)); | 314 | fprintf(file, ", Ans: %d", ntohs(hp->ancount)); |
290 | fprintf(file,", Auth: %d", ntohs(hp->nscount)); | 315 | fprintf(file, ", Auth: %d", ntohs(hp->nscount)); |
291 | fprintf(file,", Addit: %d\n", ntohs(hp->arcount)); | 316 | fprintf(file, ", Addit: %d", ntohs(hp->arcount)); |
292 | } | 317 | } |
293 | #if 0 | 318 | if ((!_res.pfcode) || (_res.pfcode & |
294 | if (_res.pfcode & (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1)) { | 319 | (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) { |
295 | putc('\n',file); | 320 | putc('\n',file); |
296 | } | 321 | } |
297 | #endif | ||
298 | /* | 322 | /* |
299 | * Print question records. | 323 | * Print question records. |
300 | */ | 324 | */ |
301 | if (n = ntohs(hp->qdcount)) { | 325 | if ((n = ntohs(hp->qdcount))) { |
302 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | 326 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) |
303 | fprintf(file,";; QUESTIONS:\n"); | 327 | fprintf(file, ";; QUESTIONS:\n"); |
304 | while (--n >= 0) { | 328 | while (--n >= 0) { |
305 | fprintf(file,";;\t"); | 329 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) |
306 | cp = p_cdname(cp, msg, file); | 330 | fprintf(file, ";;\t"); |
307 | if (cp == NULL) | 331 | TruncTest(cp); |
308 | return; | 332 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) |
333 | cp = p_cdnname(cp, msg, len, file); | ||
334 | else { | ||
335 | int n; | ||
336 | char name[MAXDNAME]; | ||
337 | |||
338 | if ((n = dn_expand(msg, msg+len, cp, name, | ||
339 | sizeof name)) < 0) | ||
340 | cp = NULL; | ||
341 | else | ||
342 | cp += n; | ||
343 | } | ||
344 | ErrorTest(cp); | ||
345 | TruncTest(cp); | ||
309 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | 346 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) |
310 | fprintf(file, ", type = %s", | 347 | fprintf(file, ", type = %s", |
311 | __p_type(_getshort(cp))); | 348 | __p_type(_getshort((u_char*)cp))); |
312 | cp += sizeof(u_int16_t); | 349 | cp += INT16SZ; |
350 | TruncTest(cp); | ||
313 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | 351 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) |
314 | fprintf(file, ", class = %s\n\n", | 352 | fprintf(file, ", class = %s\n", |
315 | __p_class(_getshort(cp))); | 353 | __p_class(_getshort((u_char*)cp))); |
316 | cp += sizeof(u_int16_t); | 354 | cp += INT16SZ; |
355 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | ||
356 | putc('\n', file); | ||
317 | } | 357 | } |
318 | } | 358 | } |
319 | /* | 359 | /* |
320 | * Print authoritative answer records | 360 | * Print authoritative answer records |
321 | */ | 361 | */ |
322 | cp = do_rrset(msg, cp, hp->ancount, RES_PRF_ANS, file, | 362 | TruncTest(cp); |
363 | cp = do_rrset(msg, len, cp, hp->ancount, RES_PRF_ANS, file, | ||
323 | ";; ANSWERS:\n"); | 364 | ";; ANSWERS:\n"); |
324 | if (cp == NULL) | 365 | ErrorTest(cp); |
325 | return; | ||
326 | 366 | ||
327 | /* | 367 | /* |
328 | * print name server records | 368 | * print name server records |
329 | */ | 369 | */ |
330 | cp = do_rrset(msg, cp, hp->nscount, RES_PRF_AUTH, file, | 370 | TruncTest(cp); |
371 | cp = do_rrset(msg, len, cp, hp->nscount, RES_PRF_AUTH, file, | ||
331 | ";; AUTHORITY RECORDS:\n"); | 372 | ";; AUTHORITY RECORDS:\n"); |
332 | if (!cp) | 373 | ErrorTest(cp); |
333 | return; | ||
334 | 374 | ||
375 | TruncTest(cp); | ||
335 | /* | 376 | /* |
336 | * print additional records | 377 | * print additional records |
337 | */ | 378 | */ |
338 | cp = do_rrset(msg, cp, hp->arcount, RES_PRF_ADD, file, | 379 | cp = do_rrset(msg, len, cp, hp->arcount, RES_PRF_ADD, file, |
339 | ";; ADDITIONAL RECORDS:\n"); | 380 | ";; ADDITIONAL RECORDS:\n"); |
340 | if (!cp) | 381 | ErrorTest(cp); |
341 | return; | 382 | return; |
383 | trunc: | ||
384 | fprintf(file, "\n;; ...truncated\n"); | ||
385 | return; | ||
386 | error: | ||
387 | fprintf(file, "\n;; ...malformed\n"); | ||
342 | } | 388 | } |
343 | 389 | ||
344 | char * | 390 | void |
345 | p_cdname(cp, msg, file) | 391 | __fp_query(msg, file) |
346 | char *cp, *msg; | 392 | const u_char *msg; |
393 | FILE *file; | ||
394 | { | ||
395 | fp_nquery(msg, PACKETSZ, file); | ||
396 | } | ||
397 | |||
398 | const u_char * | ||
399 | __p_cdnname(cp, msg, len, file) | ||
400 | const u_char *cp, *msg; | ||
401 | int len; | ||
347 | FILE *file; | 402 | FILE *file; |
348 | { | 403 | { |
349 | char name[MAXDNAME]; | 404 | char name[MAXDNAME]; |
350 | int n; | 405 | int n; |
351 | 406 | ||
352 | if ((n = dn_expand((u_char *)msg, (u_char *)cp + MAXCDNAME, | 407 | if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0) |
353 | (u_char *)cp, (u_char *)name, sizeof(name))) < 0) | ||
354 | return (NULL); | 408 | return (NULL); |
355 | if (name[0] == '\0') | 409 | if (name[0] == '\0') |
356 | putc('.', file); | 410 | putc('.', file); |
@@ -359,54 +413,94 @@ p_cdname(cp, msg, file) | |||
359 | return (cp + n); | 413 | return (cp + n); |
360 | } | 414 | } |
361 | 415 | ||
362 | char * | 416 | const u_char * |
363 | p_fqname(cp, msg, file) | 417 | __p_cdname(cp, msg, file) |
364 | char *cp, *msg; | 418 | const u_char *cp, *msg; |
365 | FILE *file; | 419 | FILE *file; |
366 | { | 420 | { |
367 | char name[MAXDNAME]; | 421 | return (p_cdnname(cp, msg, PACKETSZ, file)); |
368 | int n, len; | 422 | } |
369 | 423 | ||
370 | if ((n = dn_expand((u_char *)msg, (u_char *)cp + MAXCDNAME, | 424 | |
371 | (u_char *)cp, (u_char *)name, sizeof(name))) < 0) | 425 | /* Return a fully-qualified domain name from a compressed name (with |
426 | length supplied). */ | ||
427 | |||
428 | const u_char * | ||
429 | __p_fqnname(cp, msg, msglen, name, namelen) | ||
430 | const u_char *cp, *msg; | ||
431 | int msglen; | ||
432 | char *name; | ||
433 | int namelen; | ||
434 | { | ||
435 | int n, newlen; | ||
436 | |||
437 | if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0) | ||
372 | return (NULL); | 438 | return (NULL); |
373 | if (name[0] == '\0') { | 439 | newlen = strlen (name); |
374 | putc('.', file); | 440 | if (newlen == 0 || name[newlen - 1] != '.') { |
375 | } else { | 441 | if (newlen+1 >= namelen) /* Lack space for final dot */ |
376 | fputs(name, file); | 442 | return (NULL); |
377 | if (name[strlen(name) - 1] != '.') | 443 | else |
378 | putc('.', file); | 444 | strcpy(name + newlen, "."); |
379 | } | 445 | } |
380 | return (cp + n); | 446 | return (cp + n); |
381 | } | 447 | } |
382 | 448 | ||
449 | /* XXX: the rest of these functions need to become length-limited, too. (vix) | ||
450 | */ | ||
451 | |||
452 | const u_char * | ||
453 | __p_fqname(cp, msg, file) | ||
454 | const u_char *cp, *msg; | ||
455 | FILE *file; | ||
456 | { | ||
457 | char name[MAXDNAME]; | ||
458 | const u_char *n; | ||
459 | |||
460 | n = __p_fqnname(cp, msg, MAXCDNAME, name, sizeof name); | ||
461 | if (n == NULL) | ||
462 | return (NULL); | ||
463 | fputs(name, file); | ||
464 | return (n); | ||
465 | } | ||
466 | |||
383 | /* | 467 | /* |
384 | * Print resource record fields in human readable form. | 468 | * Print resource record fields in human readable form. |
385 | */ | 469 | */ |
386 | char * | 470 | const u_char * |
387 | p_rr(cp, msg, file) | 471 | __p_rr(cp, msg, file) |
388 | char *cp, *msg; | 472 | const u_char *cp, *msg; |
389 | FILE *file; | 473 | FILE *file; |
390 | { | 474 | { |
391 | int type, class, dlen, n, c; | 475 | int type, class, dlen, n, c; |
392 | struct in_addr inaddr; | 476 | struct in_addr inaddr; |
393 | char *cp1, *cp2; | 477 | const u_char *cp1, *cp2; |
394 | u_int32_t tmpttl, t; | 478 | u_int32_t tmpttl, t; |
395 | int lcnt; | 479 | int lcnt; |
480 | u_int16_t keyflags; | ||
481 | char rrname[MAXDNAME]; /* The fqdn of this RR */ | ||
482 | char base64_key[MAX_KEY_BASE64]; | ||
396 | 483 | ||
397 | if ((cp = p_fqname(cp, msg, file)) == NULL) | 484 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { |
485 | h_errno = NETDB_INTERNAL; | ||
486 | return (NULL); | ||
487 | } | ||
488 | cp = __p_fqnname(cp, msg, MAXCDNAME, rrname, sizeof rrname); | ||
489 | if (!cp) | ||
398 | return (NULL); /* compression error */ | 490 | return (NULL); /* compression error */ |
399 | type = _getshort(cp); | 491 | fputs(rrname, file); |
400 | cp += sizeof(u_int16_t); | 492 | |
401 | class = _getshort(cp); | 493 | type = _getshort((u_char*)cp); |
402 | cp += sizeof(u_int16_t); | 494 | cp += INT16SZ; |
403 | tmpttl = _getlong(cp); | 495 | class = _getshort((u_char*)cp); |
404 | cp += sizeof(u_int32_t); | 496 | cp += INT16SZ; |
405 | dlen = _getshort(cp); | 497 | tmpttl = _getlong((u_char*)cp); |
406 | cp += sizeof(u_int16_t); | 498 | cp += INT32SZ; |
499 | dlen = _getshort((u_char*)cp); | ||
500 | cp += INT16SZ; | ||
407 | cp1 = cp; | 501 | cp1 = cp; |
408 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_TTLID)) | 502 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_TTLID)) |
409 | fprintf(file, "\t%lu", tmpttl); | 503 | fprintf(file, "\t%lu", (u_long)tmpttl); |
410 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_CLASS)) | 504 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_CLASS)) |
411 | fprintf(file, "\t%s", __p_class(class)); | 505 | fprintf(file, "\t%s", __p_class(class)); |
412 | fprintf(file, "\t%s", __p_type(type)); | 506 | fprintf(file, "\t%s", __p_type(type)); |
@@ -418,21 +512,21 @@ p_rr(cp, msg, file) | |||
418 | switch (class) { | 512 | switch (class) { |
419 | case C_IN: | 513 | case C_IN: |
420 | case C_HS: | 514 | case C_HS: |
421 | bcopy(cp, (char *)&inaddr, sizeof(inaddr)); | 515 | bcopy(cp, (char *)&inaddr, INADDRSZ); |
422 | if (dlen == 4) { | 516 | if (dlen == 4) { |
423 | fprintf(file,"\t%s", inet_ntoa(inaddr)); | 517 | fprintf(file, "\t%s", inet_ntoa(inaddr)); |
424 | cp += dlen; | 518 | cp += dlen; |
425 | } else if (dlen == 7) { | 519 | } else if (dlen == 7) { |
426 | char *address; | 520 | char *address; |
427 | u_char protocol; | 521 | u_char protocol; |
428 | u_short port; | 522 | in_port_t port; |
429 | 523 | ||
430 | address = inet_ntoa(inaddr); | 524 | address = inet_ntoa(inaddr); |
431 | cp += sizeof(inaddr); | 525 | cp += INADDRSZ; |
432 | protocol = *(u_char*)cp; | 526 | protocol = *(u_char*)cp; |
433 | cp += sizeof(u_char); | 527 | cp += sizeof (u_char); |
434 | port = _getshort(cp); | 528 | port = _getshort((u_char*)cp); |
435 | cp += sizeof(u_int16_t); | 529 | cp += INT16SZ; |
436 | fprintf(file, "\t%s\t; proto %d, port %d", | 530 | fprintf(file, "\t%s\t; proto %d, port %d", |
437 | address, protocol, port); | 531 | address, protocol, port); |
438 | } | 532 | } |
@@ -448,98 +542,205 @@ p_rr(cp, msg, file) | |||
448 | case T_NS: | 542 | case T_NS: |
449 | case T_PTR: | 543 | case T_PTR: |
450 | putc('\t', file); | 544 | putc('\t', file); |
451 | cp = p_fqname(cp, msg, file); | 545 | if ((cp = p_fqname(cp, msg, file)) == NULL) |
546 | return (NULL); | ||
452 | break; | 547 | break; |
453 | 548 | ||
454 | case T_HINFO: | 549 | case T_HINFO: |
455 | if (n = *cp++) { | 550 | case T_ISDN: |
456 | fprintf(file,"\t%.*s", n, cp); | 551 | cp2 = cp + dlen; |
457 | cp += n; | 552 | (void) fputs("\t\"", file); |
553 | if ((n = (unsigned char) *cp++) != 0) { | ||
554 | for (c = n; c > 0 && cp < cp2; c--) { | ||
555 | if (strchr("\n\"\\", *cp)) | ||
556 | (void) putc('\\', file); | ||
557 | (void) putc(*cp++, file); | ||
558 | } | ||
458 | } | 559 | } |
459 | if (n = *cp++) { | 560 | putc('"', file); |
460 | fprintf(file,"\t%.*s", n, cp); | 561 | if (cp < cp2 && (n = (unsigned char) *cp++) != 0) { |
461 | cp += n; | 562 | (void) fputs ("\t\"", file); |
563 | for (c = n; c > 0 && cp < cp2; c--) { | ||
564 | if (strchr("\n\"\\", *cp)) | ||
565 | (void) putc('\\', file); | ||
566 | (void) putc(*cp++, file); | ||
567 | } | ||
568 | putc('"', file); | ||
569 | } else if (type == T_HINFO) { | ||
570 | (void) fputs("\"?\"", file); | ||
571 | fprintf(file, "\n;; *** Warning *** OS-type missing"); | ||
462 | } | 572 | } |
463 | break; | 573 | break; |
464 | 574 | ||
465 | case T_SOA: | 575 | case T_SOA: |
466 | putc('\t', file); | 576 | putc('\t', file); |
467 | cp = p_fqname(cp, msg, file); /* origin */ | 577 | if ((cp = p_fqname(cp, msg, file)) == NULL) |
578 | return (NULL); | ||
468 | putc(' ', file); | 579 | putc(' ', file); |
469 | cp = p_fqname(cp, msg, file); /* mail addr */ | 580 | if ((cp = p_fqname(cp, msg, file)) == NULL) |
581 | return (NULL); | ||
470 | fputs(" (\n", file); | 582 | fputs(" (\n", file); |
471 | t = _getlong(cp); cp += sizeof(u_int32_t); | 583 | t = _getlong((u_char*)cp); cp += INT32SZ; |
472 | fprintf(file,"\t\t\t%lu\t; serial\n", t); | 584 | fprintf(file, "\t\t\t%lu\t; serial\n", (u_long)t); |
473 | t = _getlong(cp); cp += sizeof(u_int32_t); | 585 | t = _getlong((u_char*)cp); cp += INT32SZ; |
474 | fprintf(file,"\t\t\t%lu\t; refresh (%s)\n", t, __p_time(t)); | 586 | fprintf(file, "\t\t\t%lu\t; refresh (%s)\n", |
475 | t = _getlong(cp); cp += sizeof(u_int32_t); | 587 | (u_long)t, __p_time(t)); |
476 | fprintf(file,"\t\t\t%lu\t; retry (%s)\n", t, __p_time(t)); | 588 | t = _getlong((u_char*)cp); cp += INT32SZ; |
477 | t = _getlong(cp); cp += sizeof(u_int32_t); | 589 | fprintf(file, "\t\t\t%lu\t; retry (%s)\n", |
478 | fprintf(file,"\t\t\t%lu\t; expire (%s)\n", t, __p_time(t)); | 590 | (u_long)t, __p_time(t)); |
479 | t = _getlong(cp); cp += sizeof(u_int32_t); | 591 | t = _getlong((u_char*)cp); cp += INT32SZ; |
480 | fprintf(file,"\t\t\t%lu )\t; minimum (%s)", t, __p_time(t)); | 592 | fprintf(file, "\t\t\t%lu\t; expire (%s)\n", |
593 | (u_long)t, __p_time(t)); | ||
594 | t = _getlong((u_char*)cp); cp += INT32SZ; | ||
595 | fprintf(file, "\t\t\t%lu )\t; minimum (%s)", | ||
596 | (u_long)t, __p_time(t)); | ||
481 | break; | 597 | break; |
482 | 598 | ||
483 | case T_MX: | 599 | case T_MX: |
484 | case T_AFSDB: | 600 | case T_AFSDB: |
485 | fprintf(file,"\t%d ", _getshort(cp)); | 601 | case T_RT: |
486 | cp += sizeof(u_int16_t); | 602 | fprintf(file, "\t%d ", _getshort((u_char*)cp)); |
487 | cp = p_fqname(cp, msg, file); | 603 | cp += INT16SZ; |
604 | if ((cp = p_fqname(cp, msg, file)) == NULL) | ||
605 | return (NULL); | ||
606 | break; | ||
607 | |||
608 | case T_PX: | ||
609 | fprintf(file, "\t%d ", _getshort((u_char*)cp)); | ||
610 | cp += INT16SZ; | ||
611 | if ((cp = p_fqname(cp, msg, file)) == NULL) | ||
612 | return (NULL); | ||
613 | putc(' ', file); | ||
614 | if ((cp = p_fqname(cp, msg, file)) == NULL) | ||
615 | return (NULL); | ||
488 | break; | 616 | break; |
489 | 617 | ||
490 | case T_TXT: | 618 | case T_X25: |
619 | cp2 = cp + dlen; | ||
491 | (void) fputs("\t\"", file); | 620 | (void) fputs("\t\"", file); |
621 | if ((n = (unsigned char) *cp++) != 0) { | ||
622 | for (c = n; c > 0 && cp < cp2; c--) { | ||
623 | if (strchr("\n\"\\", *cp)) | ||
624 | (void) putc('\\', file); | ||
625 | (void) putc(*cp++, file); | ||
626 | } | ||
627 | } | ||
628 | putc('"', file); | ||
629 | break; | ||
630 | |||
631 | case T_TXT: | ||
632 | (void) putc('\t', file); | ||
492 | cp2 = cp1 + dlen; | 633 | cp2 = cp1 + dlen; |
493 | while (cp < cp2) { | 634 | while (cp < cp2) { |
494 | if (n = (unsigned char) *cp++) { | 635 | putc('"', file); |
495 | for (c = n; c > 0 && cp < cp2; c--) | 636 | if ((n = (unsigned char) *cp++)) { |
496 | if (*cp == '\n') { | 637 | for (c = n; c > 0 && cp < cp2; c--) { |
497 | (void) putc('\\', file); | 638 | if (strchr("\n\"\\", *cp)) |
498 | (void) putc(*cp++, file); | 639 | (void) putc('\\', file); |
499 | } else | 640 | (void) putc(*cp++, file); |
500 | (void) putc(*cp++, file); | 641 | } |
501 | } | 642 | } |
643 | putc('"', file); | ||
644 | if (cp < cp2) | ||
645 | putc(' ', file); | ||
502 | } | 646 | } |
503 | putc('"', file); | 647 | break; |
504 | break; | 648 | |
649 | case T_NSAP: | ||
650 | (void) fprintf(file, "\t%s", inet_nsap_ntoa(dlen, cp, NULL)); | ||
651 | cp += dlen; | ||
652 | break; | ||
653 | |||
654 | case T_AAAA: { | ||
655 | char t[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; | ||
656 | |||
657 | fprintf(file, "\t%s", inet_ntop(AF_INET6, cp, t, sizeof t)); | ||
658 | cp += dlen; | ||
659 | break; | ||
660 | } | ||
661 | |||
662 | case T_LOC: { | ||
663 | char t[255]; | ||
664 | |||
665 | fprintf(file, "\t%s", loc_ntoa(cp, t)); | ||
666 | cp += dlen; | ||
667 | break; | ||
668 | } | ||
669 | |||
670 | case T_NAPTR: { | ||
671 | u_int order, preference; | ||
672 | |||
673 | order = _getshort(cp); cp += INT16SZ; | ||
674 | preference = _getshort(cp); cp += INT16SZ; | ||
675 | fprintf(file, "\t%u %u ",order, preference); | ||
676 | /* Flags */ | ||
677 | n = *cp++; | ||
678 | fprintf(file,"\"%.*s\" ", (int)n, cp); | ||
679 | cp += n; | ||
680 | /* Service */ | ||
681 | n = *cp++; | ||
682 | fprintf(file,"\"%.*s\" ", (int)n, cp); | ||
683 | cp += n; | ||
684 | /* Regexp */ | ||
685 | n = *cp++; | ||
686 | fprintf(file,"\"%.*s\" ", (int)n, cp); | ||
687 | cp += n; | ||
688 | if ((cp = p_fqname(cp, msg, file)) == NULL) | ||
689 | return (NULL); | ||
690 | break; | ||
691 | } | ||
692 | |||
693 | case T_SRV: { | ||
694 | u_int priority, weight, port; | ||
695 | |||
696 | priority = _getshort(cp); cp += INT16SZ; | ||
697 | weight = _getshort(cp); cp += INT16SZ; | ||
698 | port = _getshort(cp); cp += INT16SZ; | ||
699 | fprintf(file, "\t%u %u %u ", priority, weight, port); | ||
700 | if ((cp = p_fqname(cp, msg, file)) == NULL) | ||
701 | return (NULL); | ||
702 | break; | ||
703 | } | ||
505 | 704 | ||
506 | case T_MINFO: | 705 | case T_MINFO: |
507 | case T_RP: | 706 | case T_RP: |
508 | putc('\t', file); | 707 | putc('\t', file); |
509 | cp = p_fqname(cp, msg, file); | 708 | if ((cp = p_fqname(cp, msg, file)) == NULL) |
709 | return (NULL); | ||
510 | putc(' ', file); | 710 | putc(' ', file); |
511 | cp = p_fqname(cp, msg, file); | 711 | if ((cp = p_fqname(cp, msg, file)) == NULL) |
712 | return (NULL); | ||
512 | break; | 713 | break; |
513 | 714 | ||
514 | case T_UINFO: | 715 | case T_UINFO: |
515 | putc('\t', file); | 716 | putc('\t', file); |
516 | fputs(cp, file); | 717 | fputs((char *)cp, file); |
517 | cp += dlen; | 718 | cp += dlen; |
518 | break; | 719 | break; |
519 | 720 | ||
520 | case T_UID: | 721 | case T_UID: |
521 | case T_GID: | 722 | case T_GID: |
522 | if (dlen == 4) { | 723 | if (dlen == 4) { |
523 | fprintf(file,"\t%u", _getlong(cp)); | 724 | fprintf(file, "\t%u", _getlong((u_char*)cp)); |
524 | cp += sizeof(int32_t); | 725 | cp += INT32SZ; |
525 | } | 726 | } |
526 | break; | 727 | break; |
527 | 728 | ||
528 | case T_WKS: | 729 | case T_WKS: |
529 | if (dlen < sizeof(u_int32_t) + 1) | 730 | if (dlen < INT32SZ + 1) |
530 | break; | 731 | break; |
531 | bcopy(cp, (char *)&inaddr, sizeof(inaddr)); | 732 | bcopy(cp, (char *)&inaddr, INADDRSZ); |
532 | cp += sizeof(u_int32_t); | 733 | cp += INT32SZ; |
533 | fprintf(file, "\t%s %s ( ", | 734 | fprintf(file, "\t%s %s ( ", |
534 | inet_ntoa(inaddr), | 735 | inet_ntoa(inaddr), |
535 | deproto((int) *cp)); | 736 | deproto((int) *cp)); |
536 | cp += sizeof(u_char); | 737 | cp += sizeof (u_char); |
537 | n = 0; | 738 | n = 0; |
538 | lcnt = 0; | 739 | lcnt = 0; |
539 | while (cp < cp1 + dlen) { | 740 | while (cp < cp1 + dlen) { |
540 | c = *cp++; | 741 | c = *cp++; |
541 | do { | 742 | do { |
542 | if (c & 0200) { | 743 | if (c & 0200) { |
543 | if (lcnt == 0) { | 744 | if (lcnt == 0) { |
544 | fputs("\n\t\t\t", file); | 745 | fputs("\n\t\t\t", file); |
545 | lcnt = 5; | 746 | lcnt = 5; |
@@ -548,17 +749,83 @@ p_rr(cp, msg, file) | |||
548 | putc(' ', file); | 749 | putc(' ', file); |
549 | lcnt--; | 750 | lcnt--; |
550 | } | 751 | } |
551 | c <<= 1; | 752 | c <<= 1; |
552 | } while (++n & 07); | 753 | } while (++n & 07); |
553 | } | 754 | } |
554 | putc(')', file); | 755 | putc(')', file); |
555 | break; | 756 | break; |
556 | 757 | ||
758 | case T_KEY: | ||
759 | putc('\t', file); | ||
760 | keyflags = _getshort(cp); | ||
761 | cp += 2; | ||
762 | fprintf(file,"0x%04x", keyflags ); /* flags */ | ||
763 | fprintf(file," %u", *cp++); /* protocol */ | ||
764 | fprintf(file," %u (", *cp++); /* algorithm */ | ||
765 | |||
766 | n = b64_ntop(cp, (cp1 + dlen) - cp, | ||
767 | base64_key, sizeof base64_key); | ||
768 | for (c = 0; c < n; ++c) { | ||
769 | if (0 == (c & 0x3F)) | ||
770 | fprintf(file, "\n\t"); | ||
771 | putc(base64_key[c], file); /* public key data */ | ||
772 | } | ||
773 | |||
774 | fprintf(file, " )"); | ||
775 | if (n < 0) | ||
776 | fprintf(file, "\t; BAD BASE64"); | ||
777 | fflush(file); | ||
778 | cp = cp1 + dlen; | ||
779 | break; | ||
780 | |||
781 | case T_SIG: | ||
782 | type = _getshort((u_char*)cp); | ||
783 | cp += INT16SZ; | ||
784 | fprintf(file, " %s", p_type(type)); | ||
785 | fprintf(file, "\t%d", *cp++); /* algorithm */ | ||
786 | /* Check label value and print error if wrong. */ | ||
787 | n = *cp++; | ||
788 | c = dn_count_labels (rrname); | ||
789 | if (n != c) | ||
790 | fprintf(file, "\t; LABELS WRONG (%d should be %d)\n\t", | ||
791 | n, c); | ||
792 | /* orig ttl */ | ||
793 | n = _getlong((u_char*)cp); | ||
794 | if (n != tmpttl) | ||
795 | fprintf(file, " %u", n); | ||
796 | cp += INT32SZ; | ||
797 | /* sig expire */ | ||
798 | fprintf(file, " (\n\t%s", | ||
799 | __p_secstodate(_getlong((u_char*)cp))); | ||
800 | cp += INT32SZ; | ||
801 | /* time signed */ | ||
802 | fprintf(file, " %s", __p_secstodate(_getlong((u_char*)cp))); | ||
803 | cp += INT32SZ; | ||
804 | /* sig footprint */ | ||
805 | fprintf(file," %u ", _getshort((u_char*)cp)); | ||
806 | cp += INT16SZ; | ||
807 | /* signer's name */ | ||
808 | cp = p_fqname(cp, msg, file); | ||
809 | n = b64_ntop(cp, (cp1 + dlen) - cp, | ||
810 | base64_key, sizeof base64_key); | ||
811 | for (c = 0; c < n; c++) { | ||
812 | if (0 == (c & 0x3F)) | ||
813 | fprintf (file, "\n\t"); | ||
814 | putc(base64_key[c], file); /* signature */ | ||
815 | } | ||
816 | /* Clean up... */ | ||
817 | fprintf(file, " )"); | ||
818 | if (n < 0) | ||
819 | fprintf(file, "\t; BAD BASE64"); | ||
820 | fflush(file); | ||
821 | cp = cp1+dlen; | ||
822 | break; | ||
823 | |||
557 | #ifdef ALLOW_T_UNSPEC | 824 | #ifdef ALLOW_T_UNSPEC |
558 | case T_UNSPEC: | 825 | case T_UNSPEC: |
559 | { | 826 | { |
560 | int NumBytes = 8; | 827 | int NumBytes = 8; |
561 | char *DataPtr; | 828 | u_char *DataPtr; |
562 | int i; | 829 | int i; |
563 | 830 | ||
564 | if (dlen < NumBytes) NumBytes = dlen; | 831 | if (dlen < NumBytes) NumBytes = dlen; |
@@ -572,7 +839,7 @@ p_rr(cp, msg, file) | |||
572 | #endif /* ALLOW_T_UNSPEC */ | 839 | #endif /* ALLOW_T_UNSPEC */ |
573 | 840 | ||
574 | default: | 841 | default: |
575 | fprintf(file,"\t?%d?", type); | 842 | fprintf(file, "\t?%d?", type); |
576 | cp += dlen; | 843 | cp += dlen; |
577 | } | 844 | } |
578 | #if 0 | 845 | #if 0 |
@@ -581,136 +848,205 @@ p_rr(cp, msg, file) | |||
581 | putc('\n', file); | 848 | putc('\n', file); |
582 | #endif | 849 | #endif |
583 | if (cp - cp1 != dlen) { | 850 | if (cp - cp1 != dlen) { |
584 | fprintf(file,";; packet size error (found %d, dlen was %d)\n", | 851 | fprintf(file, ";; packet size error (found %ld, dlen was %d)\n", |
585 | cp - cp1, dlen); | 852 | (long)(cp - cp1), dlen); |
586 | cp = NULL; | 853 | cp = NULL; |
587 | } | 854 | } |
588 | return (cp); | 855 | return (cp); |
589 | } | 856 | } |
590 | 857 | ||
591 | static char nbuf[40]; | 858 | /* |
859 | * Names of RR classes and qclasses. Classes and qclasses are the same, except | ||
860 | * that C_ANY is a qclass but not a class. (You can ask for records of class | ||
861 | * C_ANY, but you can't have any records of that class in the database.) | ||
862 | */ | ||
863 | const struct res_sym __p_class_syms[] = { | ||
864 | {C_IN, "IN"}, | ||
865 | {C_CHAOS, "CHAOS"}, | ||
866 | {C_HS, "HS"}, | ||
867 | {C_HS, "HESIOD"}, | ||
868 | {C_ANY, "ANY"}, | ||
869 | {C_IN, (char *)0} | ||
870 | }; | ||
592 | 871 | ||
593 | /* | 872 | /* |
594 | * Return a string for the type | 873 | * Names of RR types and qtypes. Types and qtypes are the same, except |
874 | * that T_ANY is a qtype but not a type. (You can ask for records of type | ||
875 | * T_ANY, but you can't have any records of that type in the database.) | ||
595 | */ | 876 | */ |
596 | char * | 877 | const struct res_sym __p_type_syms[] = { |
597 | __p_type(type) | 878 | {T_A, "A", "address"}, |
598 | int type; | 879 | {T_NS, "NS", "name server"}, |
599 | { | 880 | {T_MD, "MD", "mail destination (deprecated)"}, |
600 | switch (type) { | 881 | {T_MF, "MF", "mail forwarder (deprecated)"}, |
601 | case T_A: | 882 | {T_CNAME, "CNAME", "canonical name"}, |
602 | return("A"); | 883 | {T_SOA, "SOA", "start of authority"}, |
603 | case T_NS: /* authoritative server */ | 884 | {T_MB, "MB", "mailbox"}, |
604 | return("NS"); | 885 | {T_MG, "MG", "mail group member"}, |
605 | case T_CNAME: /* canonical name */ | 886 | {T_MR, "MR", "mail rename"}, |
606 | return("CNAME"); | 887 | {T_NULL, "NULL", "null"}, |
607 | case T_SOA: /* start of authority zone */ | 888 | {T_WKS, "WKS", "well-known service (deprecated)"}, |
608 | return("SOA"); | 889 | {T_PTR, "PTR", "domain name pointer"}, |
609 | case T_MB: /* mailbox domain name */ | 890 | {T_HINFO, "HINFO", "host information"}, |
610 | return("MB"); | 891 | {T_MINFO, "MINFO", "mailbox information"}, |
611 | case T_MG: /* mail group member */ | 892 | {T_MX, "MX", "mail exchanger"}, |
612 | return("MG"); | 893 | {T_TXT, "TXT", "text"}, |
613 | case T_MR: /* mail rename name */ | 894 | {T_RP, "RP", "responsible person"}, |
614 | return("MR"); | 895 | {T_AFSDB, "AFSDB", "DCE or AFS server"}, |
615 | case T_NULL: /* null resource record */ | 896 | {T_X25, "X25", "X25 address"}, |
616 | return("NULL"); | 897 | {T_ISDN, "ISDN", "ISDN address"}, |
617 | case T_WKS: /* well known service */ | 898 | {T_RT, "RT", "router"}, |
618 | return("WKS"); | 899 | {T_NSAP, "NSAP", "nsap address"}, |
619 | case T_PTR: /* domain name pointer */ | 900 | {T_NSAP_PTR, "NSAP_PTR", "domain name pointer"}, |
620 | return("PTR"); | 901 | {T_SIG, "SIG", "signature"}, |
621 | case T_HINFO: /* host information */ | 902 | {T_KEY, "KEY", "key"}, |
622 | return("HINFO"); | 903 | {T_PX, "PX", "mapping information"}, |
623 | case T_MINFO: /* mailbox information */ | 904 | {T_GPOS, "GPOS", "geographical position (withdrawn)"}, |
624 | return("MINFO"); | 905 | {T_AAAA, "AAAA", "IPv6 address"}, |
625 | case T_MX: /* mail routing info */ | 906 | {T_LOC, "LOC", "location"}, |
626 | return("MX"); | 907 | {T_NXT, "NXT", "next valid name (unimplemented)"}, |
627 | case T_TXT: /* text */ | 908 | {T_EID, "EID", "endpoint identifier (unimplemented)"}, |
628 | return("TXT"); | 909 | {T_NIMLOC, "NIMLOC", "NIMROD locator (unimplemented)"}, |
629 | case T_RP: /* responsible person */ | 910 | {T_SRV, "SRV", "server selection"}, |
630 | return("RP"); | 911 | {T_ATMA, "ATMA", "ATM address (unimplemented)"}, |
631 | case T_AFSDB: /* AFS cell database */ | 912 | {T_IXFR, "IXFR", "incremental zone transfer"}, |
632 | return("AFSDB"); | 913 | {T_AXFR, "AXFR", "zone transfer"}, |
633 | case T_AXFR: /* zone transfer */ | 914 | {T_MAILB, "MAILB", "mailbox-related data (deprecated)"}, |
634 | return("AXFR"); | 915 | {T_MAILA, "MAILA", "mail agent (deprecated)"}, |
635 | case T_MAILB: /* mail box */ | 916 | {T_UINFO, "UINFO", "user information (nonstandard)"}, |
636 | return("MAILB"); | 917 | {T_UID, "UID", "user ID (nonstandard)"}, |
637 | case T_MAILA: /* mail address */ | 918 | {T_GID, "GID", "group ID (nonstandard)"}, |
638 | return("MAILA"); | 919 | {T_NAPTR, "NAPTR", "URN Naming Authority"}, |
639 | case T_ANY: /* matches any type */ | ||
640 | return("ANY"); | ||
641 | case T_UINFO: | ||
642 | return("UINFO"); | ||
643 | case T_UID: | ||
644 | return("UID"); | ||
645 | case T_GID: | ||
646 | return("GID"); | ||
647 | #ifdef ALLOW_T_UNSPEC | 920 | #ifdef ALLOW_T_UNSPEC |
648 | case T_UNSPEC: | 921 | {T_UNSPEC, "UNSPEC", "unspecified data (nonstandard)"}, |
649 | return("UNSPEC"); | ||
650 | #endif /* ALLOW_T_UNSPEC */ | 922 | #endif /* ALLOW_T_UNSPEC */ |
923 | {T_ANY, "ANY", "\"any\""}, | ||
924 | {0, NULL, NULL} | ||
925 | }; | ||
651 | 926 | ||
652 | default: | 927 | int |
653 | (void)sprintf(nbuf, "%d", type); | 928 | __sym_ston(syms, name, success) |
654 | return(nbuf); | 929 | const struct res_sym *syms; |
930 | char *name; | ||
931 | int *success; | ||
932 | { | ||
933 | for (; syms->name != 0; syms++) { | ||
934 | if (strcasecmp (name, syms->name) == 0) { | ||
935 | if (success) | ||
936 | *success = 1; | ||
937 | return (syms->number); | ||
938 | } | ||
939 | } | ||
940 | if (success) | ||
941 | *success = 0; | ||
942 | return (syms->number); /* The default value. */ | ||
943 | } | ||
944 | |||
945 | const char * | ||
946 | __sym_ntos(syms, number, success) | ||
947 | const struct res_sym *syms; | ||
948 | int number; | ||
949 | int *success; | ||
950 | { | ||
951 | static char unname[20]; | ||
952 | |||
953 | for (; syms->name != 0; syms++) { | ||
954 | if (number == syms->number) { | ||
955 | if (success) | ||
956 | *success = 1; | ||
957 | return (syms->name); | ||
958 | } | ||
959 | } | ||
960 | |||
961 | sprintf (unname, "%d", number); | ||
962 | if (success) | ||
963 | *success = 0; | ||
964 | return (unname); | ||
965 | } | ||
966 | |||
967 | |||
968 | const char * | ||
969 | __sym_ntop(syms, number, success) | ||
970 | const struct res_sym *syms; | ||
971 | int number; | ||
972 | int *success; | ||
973 | { | ||
974 | static char unname[20]; | ||
975 | |||
976 | for (; syms->name != 0; syms++) { | ||
977 | if (number == syms->number) { | ||
978 | if (success) | ||
979 | *success = 1; | ||
980 | return (syms->humanname); | ||
981 | } | ||
655 | } | 982 | } |
983 | sprintf(unname, "%d", number); | ||
984 | if (success) | ||
985 | *success = 0; | ||
986 | return (unname); | ||
987 | } | ||
988 | |||
989 | /* | ||
990 | * Return a string for the type | ||
991 | */ | ||
992 | const char * | ||
993 | __p_type(type) | ||
994 | int type; | ||
995 | { | ||
996 | return (__sym_ntos (__p_type_syms, type, (int *)0)); | ||
656 | } | 997 | } |
657 | 998 | ||
658 | /* | 999 | /* |
659 | * Return a mnemonic for class | 1000 | * Return a mnemonic for class |
660 | */ | 1001 | */ |
661 | char * | 1002 | const char * |
662 | __p_class(class) | 1003 | __p_class(class) |
663 | int class; | 1004 | int class; |
664 | { | 1005 | { |
665 | 1006 | return (__sym_ntos (__p_class_syms, class, (int *)0)); | |
666 | switch (class) { | ||
667 | case C_IN: /* internet class */ | ||
668 | return("IN"); | ||
669 | case C_HS: /* hesiod class */ | ||
670 | return("HS"); | ||
671 | case C_ANY: /* matches any class */ | ||
672 | return("ANY"); | ||
673 | default: | ||
674 | (void)sprintf(nbuf, "%d", class); | ||
675 | return(nbuf); | ||
676 | } | ||
677 | } | 1007 | } |
678 | 1008 | ||
679 | /* | 1009 | /* |
680 | * Return a mnemonic for an option | 1010 | * Return a mnemonic for an option |
681 | */ | 1011 | */ |
682 | static char * | 1012 | const char * |
683 | p_option(option) | 1013 | __p_option(option) |
684 | u_int32_t option; | 1014 | u_long option; |
685 | { | 1015 | { |
1016 | static char nbuf[40]; | ||
1017 | |||
686 | switch (option) { | 1018 | switch (option) { |
687 | case RES_INIT: return "init"; | 1019 | case RES_INIT: return "init"; |
688 | case RES_DEBUG: return "debug"; | 1020 | case RES_DEBUG: return "debug"; |
689 | case RES_AAONLY: return "aaonly"; | 1021 | case RES_AAONLY: return "aaonly(unimpl)"; |
690 | case RES_USEVC: return "usevc"; | 1022 | case RES_USEVC: return "usevc"; |
691 | case RES_PRIMARY: return "primry"; | 1023 | case RES_PRIMARY: return "primry(unimpl)"; |
692 | case RES_IGNTC: return "igntc"; | 1024 | case RES_IGNTC: return "igntc"; |
693 | case RES_RECURSE: return "recurs"; | 1025 | case RES_RECURSE: return "recurs"; |
694 | case RES_DEFNAMES: return "defnam"; | 1026 | case RES_DEFNAMES: return "defnam"; |
695 | case RES_STAYOPEN: return "styopn"; | 1027 | case RES_STAYOPEN: return "styopn"; |
696 | case RES_DNSRCH: return "dnsrch"; | 1028 | case RES_DNSRCH: return "dnsrch"; |
697 | default: sprintf(nbuf, "?0x%x?", option); return nbuf; | 1029 | case RES_INSECURE1: return "insecure1"; |
1030 | case RES_INSECURE2: return "insecure2"; | ||
1031 | default: sprintf(nbuf, "?0x%lx?", (u_long)option); | ||
1032 | return (nbuf); | ||
698 | } | 1033 | } |
699 | } | 1034 | } |
700 | 1035 | ||
701 | /* | 1036 | /* |
702 | * Return a mnemonic for a time to live | 1037 | * Return a mnemonic for a time to live |
703 | */ | 1038 | */ |
704 | char * | 1039 | const char * |
705 | __p_time(value) | 1040 | p_time(value) |
706 | u_int32_t value; | 1041 | u_int32_t value; |
707 | { | 1042 | { |
1043 | static char nbuf[40]; | ||
708 | int secs, mins, hours, days; | 1044 | int secs, mins, hours, days; |
709 | register char *p; | 1045 | register char *p; |
710 | 1046 | ||
711 | if (value == 0) { | 1047 | if (value == 0) { |
712 | strcpy(nbuf, "0 secs"); | 1048 | strcpy(nbuf, "0 secs"); |
713 | return(nbuf); | 1049 | return (nbuf); |
714 | } | 1050 | } |
715 | 1051 | ||
716 | secs = value % 60; | 1052 | secs = value % 60; |
@@ -745,5 +1081,438 @@ __p_time(value) | |||
745 | *p++ = ' '; | 1081 | *p++ = ' '; |
746 | (void)sprintf(p, "%d sec%s", PLURALIZE(secs)); | 1082 | (void)sprintf(p, "%d sec%s", PLURALIZE(secs)); |
747 | } | 1083 | } |
748 | return(nbuf); | 1084 | return (nbuf); |
1085 | } | ||
1086 | |||
1087 | /* | ||
1088 | * routines to convert between on-the-wire RR format and zone file format. | ||
1089 | * Does not contain conversion to/from decimal degrees; divide or multiply | ||
1090 | * by 60*60*1000 for that. | ||
1091 | */ | ||
1092 | |||
1093 | static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000, | ||
1094 | 1000000,10000000,100000000,1000000000}; | ||
1095 | |||
1096 | /* takes an XeY precision/size value, returns a string representation. */ | ||
1097 | static const char * | ||
1098 | precsize_ntoa(prec) | ||
1099 | u_int8_t prec; | ||
1100 | { | ||
1101 | static char retbuf[sizeof "90000000.00"]; | ||
1102 | unsigned long val; | ||
1103 | int mantissa, exponent; | ||
1104 | |||
1105 | mantissa = (int)((prec >> 4) & 0x0f) % 10; | ||
1106 | exponent = (int)((prec >> 0) & 0x0f) % 10; | ||
1107 | |||
1108 | val = mantissa * poweroften[exponent]; | ||
1109 | |||
1110 | (void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100); | ||
1111 | return (retbuf); | ||
1112 | } | ||
1113 | |||
1114 | /* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */ | ||
1115 | static u_int8_t | ||
1116 | precsize_aton(strptr) | ||
1117 | char **strptr; | ||
1118 | { | ||
1119 | unsigned int mval = 0, cmval = 0; | ||
1120 | u_int8_t retval = 0; | ||
1121 | register char *cp; | ||
1122 | register int exponent; | ||
1123 | register int mantissa; | ||
1124 | |||
1125 | cp = *strptr; | ||
1126 | |||
1127 | while (isdigit(*cp)) | ||
1128 | mval = mval * 10 + (*cp++ - '0'); | ||
1129 | |||
1130 | if (*cp == '.') { /* centimeters */ | ||
1131 | cp++; | ||
1132 | if (isdigit(*cp)) { | ||
1133 | cmval = (*cp++ - '0') * 10; | ||
1134 | if (isdigit(*cp)) { | ||
1135 | cmval += (*cp++ - '0'); | ||
1136 | } | ||
1137 | } | ||
1138 | } | ||
1139 | cmval = (mval * 100) + cmval; | ||
1140 | |||
1141 | for (exponent = 0; exponent < 9; exponent++) | ||
1142 | if (cmval < poweroften[exponent+1]) | ||
1143 | break; | ||
1144 | |||
1145 | mantissa = cmval / poweroften[exponent]; | ||
1146 | if (mantissa > 9) | ||
1147 | mantissa = 9; | ||
1148 | |||
1149 | retval = (mantissa << 4) | exponent; | ||
1150 | |||
1151 | *strptr = cp; | ||
1152 | |||
1153 | return (retval); | ||
1154 | } | ||
1155 | |||
1156 | /* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */ | ||
1157 | static u_int32_t | ||
1158 | latlon2ul(latlonstrptr,which) | ||
1159 | char **latlonstrptr; | ||
1160 | int *which; | ||
1161 | { | ||
1162 | register char *cp; | ||
1163 | u_int32_t retval; | ||
1164 | int deg = 0, min = 0, secs = 0, secsfrac = 0; | ||
1165 | |||
1166 | cp = *latlonstrptr; | ||
1167 | |||
1168 | while (isdigit(*cp)) | ||
1169 | deg = deg * 10 + (*cp++ - '0'); | ||
1170 | |||
1171 | while (isspace(*cp)) | ||
1172 | cp++; | ||
1173 | |||
1174 | if (!(isdigit(*cp))) | ||
1175 | goto fndhemi; | ||
1176 | |||
1177 | while (isdigit(*cp)) | ||
1178 | min = min * 10 + (*cp++ - '0'); | ||
1179 | |||
1180 | while (isspace(*cp)) | ||
1181 | cp++; | ||
1182 | |||
1183 | if (!(isdigit(*cp))) | ||
1184 | goto fndhemi; | ||
1185 | |||
1186 | while (isdigit(*cp)) | ||
1187 | secs = secs * 10 + (*cp++ - '0'); | ||
1188 | |||
1189 | if (*cp == '.') { /* decimal seconds */ | ||
1190 | cp++; | ||
1191 | if (isdigit(*cp)) { | ||
1192 | secsfrac = (*cp++ - '0') * 100; | ||
1193 | if (isdigit(*cp)) { | ||
1194 | secsfrac += (*cp++ - '0') * 10; | ||
1195 | if (isdigit(*cp)) { | ||
1196 | secsfrac += (*cp++ - '0'); | ||
1197 | } | ||
1198 | } | ||
1199 | } | ||
1200 | } | ||
1201 | |||
1202 | while (!isspace(*cp)) /* if any trailing garbage */ | ||
1203 | cp++; | ||
1204 | |||
1205 | while (isspace(*cp)) | ||
1206 | cp++; | ||
1207 | |||
1208 | fndhemi: | ||
1209 | switch (*cp) { | ||
1210 | case 'N': case 'n': | ||
1211 | case 'E': case 'e': | ||
1212 | retval = ((unsigned)1<<31) | ||
1213 | + (((((deg * 60) + min) * 60) + secs) * 1000) | ||
1214 | + secsfrac; | ||
1215 | break; | ||
1216 | case 'S': case 's': | ||
1217 | case 'W': case 'w': | ||
1218 | retval = ((unsigned)1<<31) | ||
1219 | - (((((deg * 60) + min) * 60) + secs) * 1000) | ||
1220 | - secsfrac; | ||
1221 | break; | ||
1222 | default: | ||
1223 | retval = 0; /* invalid value -- indicates error */ | ||
1224 | break; | ||
1225 | } | ||
1226 | |||
1227 | switch (*cp) { | ||
1228 | case 'N': case 'n': | ||
1229 | case 'S': case 's': | ||
1230 | *which = 1; /* latitude */ | ||
1231 | break; | ||
1232 | case 'E': case 'e': | ||
1233 | case 'W': case 'w': | ||
1234 | *which = 2; /* longitude */ | ||
1235 | break; | ||
1236 | default: | ||
1237 | *which = 0; /* error */ | ||
1238 | break; | ||
1239 | } | ||
1240 | |||
1241 | cp++; /* skip the hemisphere */ | ||
1242 | |||
1243 | while (!isspace(*cp)) /* if any trailing garbage */ | ||
1244 | cp++; | ||
1245 | |||
1246 | while (isspace(*cp)) /* move to next field */ | ||
1247 | cp++; | ||
1248 | |||
1249 | *latlonstrptr = cp; | ||
1250 | |||
1251 | return (retval); | ||
1252 | } | ||
1253 | |||
1254 | /* converts a zone file representation in a string to an RDATA on-the-wire | ||
1255 | * representation. */ | ||
1256 | int | ||
1257 | loc_aton(ascii, binary) | ||
1258 | const char *ascii; | ||
1259 | u_char *binary; | ||
1260 | { | ||
1261 | const char *maxcp; | ||
1262 | u_char *bcp; | ||
1263 | char *cp; | ||
1264 | |||
1265 | u_int32_t latit = 0, longit = 0, alt = 0; | ||
1266 | u_int32_t lltemp1 = 0, lltemp2 = 0; | ||
1267 | int altmeters = 0, altfrac = 0, altsign = 1; | ||
1268 | u_int8_t hp = 0x16; /* default = 1e6 cm = 10000.00m = 10km */ | ||
1269 | u_int8_t vp = 0x13; /* default = 1e3 cm = 10.00m */ | ||
1270 | u_int8_t siz = 0x12; /* default = 1e2 cm = 1.00m */ | ||
1271 | int which1 = 0, which2 = 0; | ||
1272 | |||
1273 | cp = (char *)ascii; | ||
1274 | maxcp = cp + strlen(ascii); | ||
1275 | |||
1276 | lltemp1 = latlon2ul(&cp, &which1); | ||
1277 | |||
1278 | lltemp2 = latlon2ul(&cp, &which2); | ||
1279 | |||
1280 | switch (which1 + which2) { | ||
1281 | case 3: /* 1 + 2, the only valid combination */ | ||
1282 | if ((which1 == 1) && (which2 == 2)) { /* normal case */ | ||
1283 | latit = lltemp1; | ||
1284 | longit = lltemp2; | ||
1285 | } else if ((which1 == 2) && (which2 == 1)) { /* reversed */ | ||
1286 | longit = lltemp1; | ||
1287 | latit = lltemp2; | ||
1288 | } else { /* some kind of brokenness */ | ||
1289 | return (0); | ||
1290 | } | ||
1291 | break; | ||
1292 | default: /* we didn't get one of each */ | ||
1293 | return (0); | ||
1294 | } | ||
1295 | |||
1296 | /* altitude */ | ||
1297 | if (*cp == '-') { | ||
1298 | altsign = -1; | ||
1299 | cp++; | ||
1300 | } | ||
1301 | |||
1302 | if (*cp == '+') | ||
1303 | cp++; | ||
1304 | |||
1305 | while (isdigit(*cp)) | ||
1306 | altmeters = altmeters * 10 + (*cp++ - '0'); | ||
1307 | |||
1308 | if (*cp == '.') { /* decimal meters */ | ||
1309 | cp++; | ||
1310 | if (isdigit(*cp)) { | ||
1311 | altfrac = (*cp++ - '0') * 10; | ||
1312 | if (isdigit(*cp)) { | ||
1313 | altfrac += (*cp++ - '0'); | ||
1314 | } | ||
1315 | } | ||
1316 | } | ||
1317 | |||
1318 | alt = (10000000 + (altsign * (altmeters * 100 + altfrac))); | ||
1319 | |||
1320 | while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ | ||
1321 | cp++; | ||
1322 | |||
1323 | while (isspace(*cp) && (cp < maxcp)) | ||
1324 | cp++; | ||
1325 | |||
1326 | if (cp >= maxcp) | ||
1327 | goto defaults; | ||
1328 | |||
1329 | siz = precsize_aton(&cp); | ||
1330 | |||
1331 | while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ | ||
1332 | cp++; | ||
1333 | |||
1334 | while (isspace(*cp) && (cp < maxcp)) | ||
1335 | cp++; | ||
1336 | |||
1337 | if (cp >= maxcp) | ||
1338 | goto defaults; | ||
1339 | |||
1340 | hp = precsize_aton(&cp); | ||
1341 | |||
1342 | while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ | ||
1343 | cp++; | ||
1344 | |||
1345 | while (isspace(*cp) && (cp < maxcp)) | ||
1346 | cp++; | ||
1347 | |||
1348 | if (cp >= maxcp) | ||
1349 | goto defaults; | ||
1350 | |||
1351 | vp = precsize_aton(&cp); | ||
1352 | |||
1353 | defaults: | ||
1354 | |||
1355 | bcp = binary; | ||
1356 | *bcp++ = (u_int8_t) 0; /* version byte */ | ||
1357 | *bcp++ = siz; | ||
1358 | *bcp++ = hp; | ||
1359 | *bcp++ = vp; | ||
1360 | PUTLONG(latit,bcp); | ||
1361 | PUTLONG(longit,bcp); | ||
1362 | PUTLONG(alt,bcp); | ||
1363 | |||
1364 | return (16); /* size of RR in octets */ | ||
1365 | } | ||
1366 | |||
1367 | /* takes an on-the-wire LOC RR and formats it in a human readable format. */ | ||
1368 | const char * | ||
1369 | loc_ntoa(binary, ascii) | ||
1370 | const u_char *binary; | ||
1371 | char *ascii; | ||
1372 | { | ||
1373 | static char *error = "?"; | ||
1374 | register const u_char *cp = binary; | ||
1375 | |||
1376 | int latdeg, latmin, latsec, latsecfrac; | ||
1377 | int longdeg, longmin, longsec, longsecfrac; | ||
1378 | char northsouth, eastwest; | ||
1379 | int altmeters, altfrac, altsign; | ||
1380 | |||
1381 | const int referencealt = 100000 * 100; | ||
1382 | |||
1383 | int32_t latval, longval, altval; | ||
1384 | u_int32_t templ; | ||
1385 | u_int8_t sizeval, hpval, vpval, versionval; | ||
1386 | |||
1387 | char *sizestr, *hpstr, *vpstr; | ||
1388 | |||
1389 | versionval = *cp++; | ||
1390 | |||
1391 | if (versionval) { | ||
1392 | sprintf(ascii, "; error: unknown LOC RR version"); | ||
1393 | return (ascii); | ||
1394 | } | ||
1395 | |||
1396 | sizeval = *cp++; | ||
1397 | |||
1398 | hpval = *cp++; | ||
1399 | vpval = *cp++; | ||
1400 | |||
1401 | GETLONG(templ, cp); | ||
1402 | latval = (templ - ((unsigned)1<<31)); | ||
1403 | |||
1404 | GETLONG(templ, cp); | ||
1405 | longval = (templ - ((unsigned)1<<31)); | ||
1406 | |||
1407 | GETLONG(templ, cp); | ||
1408 | if (templ < referencealt) { /* below WGS 84 spheroid */ | ||
1409 | altval = referencealt - templ; | ||
1410 | altsign = -1; | ||
1411 | } else { | ||
1412 | altval = templ - referencealt; | ||
1413 | altsign = 1; | ||
1414 | } | ||
1415 | |||
1416 | if (latval < 0) { | ||
1417 | northsouth = 'S'; | ||
1418 | latval = -latval; | ||
1419 | } else | ||
1420 | northsouth = 'N'; | ||
1421 | |||
1422 | latsecfrac = latval % 1000; | ||
1423 | latval = latval / 1000; | ||
1424 | latsec = latval % 60; | ||
1425 | latval = latval / 60; | ||
1426 | latmin = latval % 60; | ||
1427 | latval = latval / 60; | ||
1428 | latdeg = latval; | ||
1429 | |||
1430 | if (longval < 0) { | ||
1431 | eastwest = 'W'; | ||
1432 | longval = -longval; | ||
1433 | } else | ||
1434 | eastwest = 'E'; | ||
1435 | |||
1436 | longsecfrac = longval % 1000; | ||
1437 | longval = longval / 1000; | ||
1438 | longsec = longval % 60; | ||
1439 | longval = longval / 60; | ||
1440 | longmin = longval % 60; | ||
1441 | longval = longval / 60; | ||
1442 | longdeg = longval; | ||
1443 | |||
1444 | altfrac = altval % 100; | ||
1445 | altmeters = (altval / 100) * altsign; | ||
1446 | |||
1447 | if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL) | ||
1448 | sizestr = error; | ||
1449 | if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL) | ||
1450 | hpstr = error; | ||
1451 | if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL) | ||
1452 | vpstr = error; | ||
1453 | |||
1454 | sprintf(ascii, | ||
1455 | "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm", | ||
1456 | latdeg, latmin, latsec, latsecfrac, northsouth, | ||
1457 | longdeg, longmin, longsec, longsecfrac, eastwest, | ||
1458 | altmeters, altfrac, sizestr, hpstr, vpstr); | ||
1459 | |||
1460 | if (sizestr != error) | ||
1461 | free(sizestr); | ||
1462 | if (hpstr != error) | ||
1463 | free(hpstr); | ||
1464 | if (vpstr != error) | ||
1465 | free(vpstr); | ||
1466 | |||
1467 | return (ascii); | ||
1468 | } | ||
1469 | |||
1470 | |||
1471 | /* Return the number of DNS hierarchy levels in the name. */ | ||
1472 | int | ||
1473 | __dn_count_labels(name) | ||
1474 | char *name; | ||
1475 | { | ||
1476 | int i, len, count; | ||
1477 | |||
1478 | len = strlen(name); | ||
1479 | |||
1480 | for(i = 0, count = 0; i < len; i++) { | ||
1481 | if (name[i] == '.') | ||
1482 | count++; | ||
1483 | } | ||
1484 | |||
1485 | /* don't count initial wildcard */ | ||
1486 | if (name[0] == '*') | ||
1487 | if (count) | ||
1488 | count--; | ||
1489 | |||
1490 | /* don't count the null label for root. */ | ||
1491 | /* if terminating '.' not found, must adjust */ | ||
1492 | /* count to include last label */ | ||
1493 | if (len > 0 && name[len-1] != '.') | ||
1494 | count++; | ||
1495 | return (count); | ||
1496 | } | ||
1497 | |||
1498 | |||
1499 | /* | ||
1500 | * Make dates expressed in seconds-since-Jan-1-1970 easy to read. | ||
1501 | * SIG records are required to be printed like this, by the Secure DNS RFC. | ||
1502 | */ | ||
1503 | char * | ||
1504 | __p_secstodate (secs) | ||
1505 | unsigned long secs; | ||
1506 | { | ||
1507 | static char output[15]; /* YYYYMMDDHHMMSS and null */ | ||
1508 | time_t clock = secs; | ||
1509 | struct tm *time; | ||
1510 | |||
1511 | time = gmtime(&clock); | ||
1512 | time->tm_year += 1900; | ||
1513 | time->tm_mon += 1; | ||
1514 | sprintf(output, "%04d%02d%02d%02d%02d%02d", | ||
1515 | time->tm_year, time->tm_mon, time->tm_mday, | ||
1516 | time->tm_hour, time->tm_min, time->tm_sec); | ||
1517 | return (output); | ||
749 | } | 1518 | } |
diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c index 33cc8d39f1..df176b7fa1 100644 --- a/src/lib/libc/net/res_init.c +++ b/src/lib/libc/net/res_init.c | |||
@@ -1,9 +1,11 @@ | |||
1 | /* $NetBSD: res_init.c,v 1.8 1995/06/03 22:33:36 mycroft Exp $ */ | 1 | /* $OpenBSD: res_init.c,v 1.16 1998/03/16 05:07:01 millert Exp $ */ |
2 | 2 | ||
3 | /*- | 3 | /* |
4 | * ++Copyright++ 1985, 1989, 1993 | ||
5 | * - | ||
4 | * Copyright (c) 1985, 1989, 1993 | 6 | * Copyright (c) 1985, 1989, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 7 | * The Regents of the University of California. All rights reserved. |
6 | * | 8 | * |
7 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions |
9 | * are met: | 11 | * are met: |
@@ -14,12 +16,12 @@ | |||
14 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
15 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. All advertising materials mentioning features or use of this software |
16 | * must display the following acknowledgement: | 18 | * must display the following acknowledgement: |
17 | * This product includes software developed by the University of | 19 | * This product includes software developed by the University of |
18 | * California, Berkeley and its contributors. | 20 | * California, Berkeley and its contributors. |
19 | * 4. Neither the name of the University nor the names of its contributors | 21 | * 4. Neither the name of the University nor the names of its contributors |
20 | * may be used to endorse or promote products derived from this software | 22 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. | 23 | * without specific prior written permission. |
22 | * | 24 | * |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -56,77 +58,150 @@ | |||
56 | #if defined(LIBC_SCCS) && !defined(lint) | 58 | #if defined(LIBC_SCCS) && !defined(lint) |
57 | #if 0 | 59 | #if 0 |
58 | static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; | 60 | static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; |
59 | static char rcsid[] = "$Id: res_init.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel "; | 61 | static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; |
60 | #else | 62 | #else |
61 | static char rcsid[] = "$NetBSD: res_init.c,v 1.8 1995/06/03 22:33:36 mycroft Exp $"; | 63 | static char rcsid[] = "$OpenBSD: res_init.c,v 1.16 1998/03/16 05:07:01 millert Exp $"; |
62 | #endif | 64 | #endif |
63 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
64 | 66 | ||
67 | #include <sys/types.h> | ||
65 | #include <sys/param.h> | 68 | #include <sys/param.h> |
66 | #include <sys/socket.h> | 69 | #include <sys/socket.h> |
70 | #include <sys/time.h> | ||
67 | #include <netinet/in.h> | 71 | #include <netinet/in.h> |
68 | #include <arpa/inet.h> | 72 | #include <arpa/inet.h> |
69 | #include <arpa/nameser.h> | 73 | #include <arpa/nameser.h> |
74 | |||
75 | #include <stdio.h> | ||
76 | #include <ctype.h> | ||
70 | #include <resolv.h> | 77 | #include <resolv.h> |
71 | #include <unistd.h> | 78 | #include <unistd.h> |
72 | #include <stdio.h> | ||
73 | #include <stdlib.h> | 79 | #include <stdlib.h> |
74 | #include <string.h> | 80 | #include <string.h> |
75 | 81 | ||
82 | /*-------------------------------------- info about "sortlist" -------------- | ||
83 | * Marc Majka 1994/04/16 | ||
84 | * Allan Nathanson 1994/10/29 (BIND 4.9.3.x) | ||
85 | * | ||
86 | * NetInfo resolver configuration directory support. | ||
87 | * | ||
88 | * Allow a NetInfo directory to be created in the hierarchy which | ||
89 | * contains the same information as the resolver configuration file. | ||
90 | * | ||
91 | * - The local domain name is stored as the value of the "domain" property. | ||
92 | * - The Internet address(es) of the name server(s) are stored as values | ||
93 | * of the "nameserver" property. | ||
94 | * - The name server addresses are stored as values of the "nameserver" | ||
95 | * property. | ||
96 | * - The search list for host-name lookup is stored as values of the | ||
97 | * "search" property. | ||
98 | * - The sortlist comprised of IP address netmask pairs are stored as | ||
99 | * values of the "sortlist" property. The IP address and optional netmask | ||
100 | * should be seperated by a slash (/) or ampersand (&) character. | ||
101 | * - Internal resolver variables can be set from the value of the "options" | ||
102 | * property. | ||
103 | */ | ||
104 | |||
76 | static void res_setoptions __P((char *, char *)); | 105 | static void res_setoptions __P((char *, char *)); |
106 | |||
107 | #ifdef RESOLVSORT | ||
108 | static const char sort_mask[] = "/&"; | ||
109 | #define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL) | ||
77 | static u_int32_t net_mask __P((struct in_addr)); | 110 | static u_int32_t net_mask __P((struct in_addr)); |
111 | #endif | ||
78 | 112 | ||
79 | /* | 113 | /* |
80 | * Resolver state default settings | 114 | * Resolver state default settings. |
81 | */ | 115 | */ |
82 | 116 | ||
83 | struct __res_state _res = { | 117 | struct __res_state _res |
84 | RES_TIMEOUT, /* retransmition time interval */ | 118 | # if defined(__BIND_RES_TEXT) |
85 | 4, /* number of times to retransmit */ | 119 | = { RES_TIMEOUT, } /* Motorola, et al. */ |
86 | RES_DEFAULT, /* options flags */ | 120 | # endif |
87 | 1, /* number of name servers */ | 121 | ; |
88 | }; | ||
89 | 122 | ||
90 | /* | 123 | /* |
91 | * Set up default settings. If the configuration file exist, the values | 124 | * Set up default settings. If the configuration file exist, the values |
92 | * there will have precedence. Otherwise, the server address is set to | 125 | * there will have precedence. Otherwise, the server address is set to |
93 | * INADDR_ANY and the default domain name comes from the gethostname(). | 126 | * INADDR_ANY and the default domain name comes from the gethostname(). |
94 | * | 127 | * |
95 | * The configuration file should only be used if you want to redefine your | 128 | * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1 |
96 | * domain or run without a server on your machine. | 129 | * rather than INADDR_ANY ("0.0.0.0") as the default name server address |
130 | * since it was noted that INADDR_ANY actually meant ``the first interface | ||
131 | * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface, | ||
132 | * it had to be "up" in order for you to reach your own name server. It | ||
133 | * was later decided that since the recommended practice is to always | ||
134 | * install local static routes through 127.0.0.1 for all your network | ||
135 | * interfaces, that we could solve this problem without a code change. | ||
136 | * | ||
137 | * The configuration file should always be used, since it is the only way | ||
138 | * to specify a default domain. If you are running a server on your local | ||
139 | * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1" | ||
140 | * in the configuration file. | ||
97 | * | 141 | * |
98 | * Return 0 if completes successfully, -1 on error | 142 | * Return 0 if completes successfully, -1 on error |
99 | */ | 143 | */ |
144 | int | ||
100 | res_init() | 145 | res_init() |
101 | { | 146 | { |
102 | register FILE *fp; | 147 | register FILE *fp; |
103 | register char *cp, **pp, *net; | 148 | register char *cp, **pp; |
104 | register int n; | 149 | register int n; |
105 | char buf[BUFSIZ], buf2[BUFSIZ]; | 150 | char buf[BUFSIZ]; |
106 | int nserv = 0; /* number of nameserver records read from file */ | 151 | int nserv = 0; /* number of nameserver records read from file */ |
107 | int haveenv = 0; | 152 | int haveenv = 0; |
108 | int havesearch = 0; | 153 | int havesearch = 0; |
154 | size_t len; | ||
155 | #ifdef RESOLVSORT | ||
109 | int nsort = 0; | 156 | int nsort = 0; |
110 | u_long mask; | 157 | char *net; |
158 | #endif | ||
159 | #ifndef RFC1535 | ||
160 | int dots; | ||
161 | #endif | ||
162 | |||
163 | /* | ||
164 | * These three fields used to be statically initialized. This made | ||
165 | * it hard to use this code in a shared library. It is necessary, | ||
166 | * now that we're doing dynamic initialization here, that we preserve | ||
167 | * the old semantics: if an application modifies one of these three | ||
168 | * fields of _res before res_init() is called, res_init() will not | ||
169 | * alter them. Of course, if an application is setting them to | ||
170 | * _zero_ before calling res_init(), hoping to override what used | ||
171 | * to be the static default, we can't detect it and unexpected results | ||
172 | * will follow. Zero for any of these fields would make no sense, | ||
173 | * so one can safely assume that the applications were already getting | ||
174 | * unexpected results. | ||
175 | * | ||
176 | * _res.options is tricky since some apps were known to diddle the bits | ||
177 | * before res_init() was first called. We can't replicate that semantic | ||
178 | * with dynamic initialization (they may have turned bits off that are | ||
179 | * set in RES_DEFAULT). Our solution is to declare such applications | ||
180 | * "broken". They could fool us by setting RES_INIT but none do (yet). | ||
181 | */ | ||
182 | if (!_res.retrans) | ||
183 | _res.retrans = RES_TIMEOUT; | ||
184 | if (!_res.retry) | ||
185 | _res.retry = 4; | ||
186 | if (!(_res.options & RES_INIT)) | ||
187 | _res.options = RES_DEFAULT; | ||
111 | 188 | ||
112 | _res.nsaddr.sin_len = sizeof(struct sockaddr_in); | ||
113 | _res.nsaddr.sin_family = AF_INET; | ||
114 | _res.nsaddr.sin_port = htons(NAMESERVER_PORT); | ||
115 | #ifdef USELOOPBACK | 189 | #ifdef USELOOPBACK |
116 | _res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); | 190 | _res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); |
117 | #else | 191 | #else |
118 | _res.nsaddr.sin_addr.s_addr = INADDR_ANY; | 192 | _res.nsaddr.sin_addr.s_addr = INADDR_ANY; |
119 | #endif | 193 | #endif |
194 | _res.nsaddr.sin_family = AF_INET; | ||
195 | _res.nsaddr.sin_port = htons(NAMESERVER_PORT); | ||
120 | _res.nscount = 1; | 196 | _res.nscount = 1; |
121 | _res.ndots = 1; | 197 | _res.ndots = 1; |
122 | _res.pfcode = 0; | 198 | _res.pfcode = 0; |
123 | strncpy(_res.lookups, "f", sizeof _res.lookups); | 199 | strncpy(_res.lookups, "f", sizeof _res.lookups); |
124 | 200 | ||
125 | /* Allow user to override the local domain definition */ | 201 | /* Allow user to override the local domain definition */ |
126 | if ((cp = getenv("LOCALDOMAIN")) != NULL) { | 202 | if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) { |
127 | (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); | 203 | (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); |
128 | if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) | 204 | _res.defdname[sizeof(_res.defdname) - 1] = '\0'; |
129 | *cp = '\0'; | ||
130 | haveenv++; | 205 | haveenv++; |
131 | 206 | ||
132 | /* | 207 | /* |
@@ -140,7 +215,7 @@ res_init() | |||
140 | pp = _res.dnsrch; | 215 | pp = _res.dnsrch; |
141 | *pp++ = cp; | 216 | *pp++ = cp; |
142 | for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) { | 217 | for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) { |
143 | if (*cp == '\n') /* silly backwards compat */ | 218 | if (*cp == '\n') /* silly backwards compat */ |
144 | break; | 219 | break; |
145 | else if (*cp == ' ' || *cp == '\t') { | 220 | else if (*cp == ' ' || *cp == '\t') { |
146 | *cp = 0; | 221 | *cp = 0; |
@@ -158,16 +233,29 @@ res_init() | |||
158 | *pp++ = 0; | 233 | *pp++ = 0; |
159 | } | 234 | } |
160 | 235 | ||
236 | #define MATCH(line, name) \ | ||
237 | (!strncmp(line, name, sizeof(name) - 1) && \ | ||
238 | (line[sizeof(name) - 1] == ' ' || \ | ||
239 | line[sizeof(name) - 1] == '\t')) | ||
240 | |||
161 | if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { | 241 | if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { |
162 | strncpy(_res.lookups, "bf", sizeof _res.lookups); | 242 | strncpy(_res.lookups, "bf", sizeof _res.lookups); |
163 | 243 | ||
164 | /* read the config file */ | 244 | /* read the config file */ |
165 | while (fgets(buf, sizeof(buf), fp) != NULL) { | 245 | buf[0] = '\0'; |
246 | while ((cp = fgetln(fp, &len)) != NULL) { | ||
247 | /* skip lines that are too long or zero length */ | ||
248 | if (len >= sizeof(buf) || len == 0) | ||
249 | continue; | ||
250 | (void)memcpy(buf, cp, len); | ||
251 | buf[len] = '\0'; | ||
166 | /* skip comments */ | 252 | /* skip comments */ |
167 | if ((*buf == ';') || (*buf == '#')) | 253 | if ((cp = strpbrk(buf, ";#")) != NULL) |
254 | *cp = '\0'; | ||
255 | if (buf[0] == '\0') | ||
168 | continue; | 256 | continue; |
169 | /* read default domain name */ | 257 | /* read default domain name */ |
170 | if (!strncmp(buf, "domain", sizeof("domain") - 1)) { | 258 | if (MATCH(buf, "domain")) { |
171 | if (haveenv) /* skip if have from environ */ | 259 | if (haveenv) /* skip if have from environ */ |
172 | continue; | 260 | continue; |
173 | cp = buf + sizeof("domain") - 1; | 261 | cp = buf + sizeof("domain") - 1; |
@@ -175,15 +263,15 @@ res_init() | |||
175 | cp++; | 263 | cp++; |
176 | if ((*cp == '\0') || (*cp == '\n')) | 264 | if ((*cp == '\0') || (*cp == '\n')) |
177 | continue; | 265 | continue; |
178 | (void)strncpy(_res.defdname, cp, | 266 | strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); |
179 | sizeof(_res.defdname) - 1); | 267 | _res.defdname[sizeof(_res.defdname) - 1] = '\0'; |
180 | if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) | 268 | if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) |
181 | *cp = '\0'; | 269 | *cp = '\0'; |
182 | havesearch = 0; | 270 | havesearch = 0; |
183 | continue; | 271 | continue; |
184 | } | 272 | } |
185 | /* lookup types */ | 273 | /* lookup types */ |
186 | if (!strncmp(buf, "lookup", sizeof("lookup") -1)) { | 274 | if (MATCH(buf, "lookup")) { |
187 | char *sp = NULL; | 275 | char *sp = NULL; |
188 | 276 | ||
189 | bzero(_res.lookups, sizeof _res.lookups); | 277 | bzero(_res.lookups, sizeof _res.lookups); |
@@ -210,7 +298,7 @@ res_init() | |||
210 | continue; | 298 | continue; |
211 | } | 299 | } |
212 | /* set search list */ | 300 | /* set search list */ |
213 | if (!strncmp(buf, "search", sizeof("search") - 1)) { | 301 | if (MATCH(buf, "search")) { |
214 | if (haveenv) /* skip if have from environ */ | 302 | if (haveenv) /* skip if have from environ */ |
215 | continue; | 303 | continue; |
216 | cp = buf + sizeof("search") - 1; | 304 | cp = buf + sizeof("search") - 1; |
@@ -218,8 +306,8 @@ res_init() | |||
218 | cp++; | 306 | cp++; |
219 | if ((*cp == '\0') || (*cp == '\n')) | 307 | if ((*cp == '\0') || (*cp == '\n')) |
220 | continue; | 308 | continue; |
221 | (void)strncpy(_res.defdname, cp, | 309 | strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); |
222 | sizeof(_res.defdname) - 1); | 310 | _res.defdname[sizeof(_res.defdname) - 1] = '\0'; |
223 | if ((cp = strchr(_res.defdname, '\n')) != NULL) | 311 | if ((cp = strchr(_res.defdname, '\n')) != NULL) |
224 | *cp = '\0'; | 312 | *cp = '\0'; |
225 | /* | 313 | /* |
@@ -247,92 +335,125 @@ res_init() | |||
247 | continue; | 335 | continue; |
248 | } | 336 | } |
249 | /* read nameservers to query */ | 337 | /* read nameservers to query */ |
250 | if (!strncmp(buf, "nameserver", sizeof("nameserver") - 1) && | 338 | if (MATCH(buf, "nameserver") && nserv < MAXNS) { |
251 | nserv < MAXNS) { | 339 | struct in_addr a; |
252 | struct in_addr a; | ||
253 | 340 | ||
254 | cp = buf + sizeof("nameserver") - 1; | 341 | cp = buf + sizeof("nameserver") - 1; |
255 | while (*cp == ' ' || *cp == '\t') | 342 | while (*cp == ' ' || *cp == '\t') |
256 | cp++; | 343 | cp++; |
257 | if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) { | 344 | if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) { |
258 | _res.nsaddr_list[nserv].sin_len = sizeof(struct sockaddr_in); | 345 | _res.nsaddr_list[nserv].sin_addr = a; |
259 | _res.nsaddr_list[nserv].sin_family = AF_INET; | 346 | _res.nsaddr_list[nserv].sin_family = AF_INET; |
260 | _res.nsaddr_list[nserv].sin_port = | 347 | _res.nsaddr_list[nserv].sin_port = |
261 | htons(NAMESERVER_PORT); | 348 | htons(NAMESERVER_PORT); |
262 | _res.nsaddr_list[nserv].sin_addr = a; | ||
263 | nserv++; | 349 | nserv++; |
264 | } | 350 | } |
265 | continue; | 351 | continue; |
266 | } | 352 | } |
267 | if (!strncmp(buf, "sortlist", sizeof("sortlist") - 1)) { | 353 | #ifdef RESOLVSORT |
354 | if (MATCH(buf, "sortlist")) { | ||
268 | struct in_addr a; | 355 | struct in_addr a; |
269 | 356 | ||
270 | cp = buf + sizeof("sortlist") - 1; | 357 | cp = buf + sizeof("sortlist") - 1; |
271 | while (*cp == ' ' || *cp == '\t') | 358 | while (nsort < MAXRESOLVSORT) { |
272 | cp++; | 359 | while (*cp == ' ' || *cp == '\t') |
273 | while (sscanf(cp,"%[0-9./]s", buf2) && nsort < MAXRESOLVSORT) { | 360 | cp++; |
274 | if (net = strchr(buf2, '/')) | 361 | if (*cp == '\0' || *cp == '\n' || *cp == ';') |
275 | *net = '\0'; | 362 | break; |
276 | if (inet_aton(buf2, &a)) { | 363 | net = cp; |
364 | while (*cp && !ISSORTMASK(*cp) && *cp != ';' && | ||
365 | isascii(*cp) && !isspace(*cp)) | ||
366 | cp++; | ||
367 | n = *cp; | ||
368 | *cp = 0; | ||
369 | if (inet_aton(net, &a)) { | ||
277 | _res.sort_list[nsort].addr = a; | 370 | _res.sort_list[nsort].addr = a; |
278 | if (net && inet_aton(net+1, &a)) { | 371 | if (ISSORTMASK(n)) { |
279 | _res.sort_list[nsort].mask = a.s_addr; | 372 | *cp++ = n; |
280 | } else { | 373 | net = cp; |
281 | _res.sort_list[nsort].mask = | 374 | while (*cp && *cp != ';' && |
375 | isascii(*cp) && !isspace(*cp)) | ||
376 | cp++; | ||
377 | n = *cp; | ||
378 | *cp = 0; | ||
379 | if (inet_aton(net, &a)) { | ||
380 | _res.sort_list[nsort].mask = a.s_addr; | ||
381 | } else { | ||
382 | _res.sort_list[nsort].mask = | ||
282 | net_mask(_res.sort_list[nsort].addr); | 383 | net_mask(_res.sort_list[nsort].addr); |
384 | } | ||
385 | } else { | ||
386 | _res.sort_list[nsort].mask = | ||
387 | net_mask(_res.sort_list[nsort].addr); | ||
283 | } | 388 | } |
284 | nsort++; | 389 | nsort++; |
285 | } | 390 | } |
286 | if (net) | 391 | *cp = n; |
287 | *net = '/'; | ||
288 | cp += strlen(buf2); | ||
289 | while (*cp == ' ' || *cp == '\t') | ||
290 | cp++; | ||
291 | } | 392 | } |
292 | continue; | 393 | continue; |
293 | } | 394 | } |
294 | if (!strncmp(buf, "options", sizeof("options") -1)) { | 395 | #endif |
396 | if (MATCH(buf, "options")) { | ||
295 | res_setoptions(buf + sizeof("options") - 1, "conf"); | 397 | res_setoptions(buf + sizeof("options") - 1, "conf"); |
296 | continue; | 398 | continue; |
297 | } | 399 | } |
298 | } | 400 | } |
299 | if (nserv > 1) | 401 | if (nserv > 1) |
300 | _res.nscount = nserv; | 402 | _res.nscount = nserv; |
403 | #ifdef RESOLVSORT | ||
301 | _res.nsort = nsort; | 404 | _res.nsort = nsort; |
405 | #endif | ||
302 | (void) fclose(fp); | 406 | (void) fclose(fp); |
303 | } | 407 | } |
304 | if (_res.defdname[0] == 0) { | 408 | if (_res.defdname[0] == 0 && |
305 | if (gethostname(buf, sizeof(_res.defdname) - 1) == 0 && | 409 | gethostname(buf, sizeof(_res.defdname) - 1) == 0 && |
306 | (cp = strchr(buf, '.'))) | 410 | (cp = strchr(buf, '.')) != NULL) |
307 | (void)strcpy(_res.defdname, cp + 1); | 411 | { |
412 | strncpy(_res.defdname, cp + 1, | ||
413 | sizeof(_res.defdname) - 1); | ||
414 | _res.defdname[sizeof(_res.defdname) - 1] = '\0'; | ||
308 | } | 415 | } |
309 | 416 | ||
310 | /* find components of local domain that might be searched */ | 417 | /* find components of local domain that might be searched */ |
311 | if (havesearch == 0) { | 418 | if (havesearch == 0) { |
312 | pp = _res.dnsrch; | 419 | pp = _res.dnsrch; |
313 | *pp++ = _res.defdname; | 420 | *pp++ = _res.defdname; |
314 | #ifndef SEARCH_LOCAL_DOMAINS | ||
315 | *pp = NULL; | 421 | *pp = NULL; |
316 | #else | 422 | |
317 | for (cp = _res.defdname, n = 0; *cp; cp++) | 423 | #ifndef RFC1535 |
318 | if (*cp == '.') | 424 | dots = 0; |
319 | n++; | 425 | for (cp = _res.defdname; *cp; cp++) |
426 | dots += (*cp == '.'); | ||
427 | |||
320 | cp = _res.defdname; | 428 | cp = _res.defdname; |
321 | for (; n >= LOCALDOMAINPARTS && pp < _res.dnsrch + MAXDFLSRCH; | 429 | while (pp < _res.dnsrch + MAXDFLSRCH) { |
322 | n--) { | 430 | if (dots < LOCALDOMAINPARTS) |
323 | cp = strchr(cp, '.'); | 431 | break; |
324 | *pp++ = ++cp; | 432 | cp = strchr(cp, '.') + 1; /* we know there is one */ |
433 | *pp++ = cp; | ||
434 | dots--; | ||
325 | } | 435 | } |
326 | *pp++ = 0; | 436 | *pp = NULL; |
327 | #endif | 437 | #ifdef DEBUG |
438 | if (_res.options & RES_DEBUG) { | ||
439 | printf(";; res_init()... default dnsrch list:\n"); | ||
440 | for (pp = _res.dnsrch; *pp; pp++) | ||
441 | printf(";;\t%s\n", *pp); | ||
442 | printf(";;\t..END..\n"); | ||
443 | } | ||
444 | #endif /* DEBUG */ | ||
445 | #endif /* !RFC1535 */ | ||
328 | } | 446 | } |
329 | 447 | ||
330 | if ((cp = getenv("RES_OPTIONS")) != NULL) | 448 | if (issetugid()) |
449 | _res.options |= RES_NOALIASES; | ||
450 | else if ((cp = getenv("RES_OPTIONS")) != NULL) | ||
331 | res_setoptions(cp, "env"); | 451 | res_setoptions(cp, "env"); |
332 | _res.options |= RES_INIT; | 452 | _res.options |= RES_INIT; |
333 | return (0); | 453 | return (0); |
334 | } | 454 | } |
335 | 455 | ||
456 | /* ARGSUSED */ | ||
336 | static void | 457 | static void |
337 | res_setoptions(options, source) | 458 | res_setoptions(options, source) |
338 | char *options, *source; | 459 | char *options, *source; |
@@ -341,28 +462,26 @@ res_setoptions(options, source) | |||
341 | int i; | 462 | int i; |
342 | 463 | ||
343 | #ifdef DEBUG | 464 | #ifdef DEBUG |
344 | if (_res.options & RES_DEBUG) { | 465 | if (_res.options & RES_DEBUG) |
345 | printf(";; res_setoptions(\"%s\", \"%s\")...\n", | 466 | printf(";; res_setoptions(\"%s\", \"%s\")...\n", |
346 | options, source); | 467 | options, source); |
347 | } | ||
348 | #endif | 468 | #endif |
349 | while (*cp) { | 469 | while (*cp) { |
350 | /* skip leading and inner runs of spaces */ | 470 | /* skip leading and inner runs of spaces */ |
351 | while (*cp == ' ' || *cp == '\t') | 471 | while (*cp == ' ' || *cp == '\t') |
352 | cp++; | 472 | cp++; |
353 | /* search for and process individual options */ | 473 | /* search for and process individual options */ |
354 | if (!strncmp(cp, "ndots:", sizeof("ndots:")-1)) { | 474 | if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) { |
355 | i = atoi(cp + sizeof("ndots:") - 1); | 475 | i = atoi(cp + sizeof("ndots:") - 1); |
356 | if (i <= RES_MAXNDOTS) | 476 | if (i <= RES_MAXNDOTS) |
357 | _res.ndots = i; | 477 | _res.ndots = i; |
358 | else | 478 | else |
359 | _res.ndots = RES_MAXNDOTS; | 479 | _res.ndots = RES_MAXNDOTS; |
360 | #ifdef DEBUG | 480 | #ifdef DEBUG |
361 | if (_res.options & RES_DEBUG) { | 481 | if (_res.options & RES_DEBUG) |
362 | printf(";;\tndots=%d\n", _res.ndots); | 482 | printf(";;\tndots=%d\n", _res.ndots); |
363 | } | ||
364 | #endif | 483 | #endif |
365 | } else if (!strncmp(cp, "debug", sizeof("debug")-1)) { | 484 | } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) { |
366 | #ifdef DEBUG | 485 | #ifdef DEBUG |
367 | if (!(_res.options & RES_DEBUG)) { | 486 | if (!(_res.options & RES_DEBUG)) { |
368 | printf(";; res_setoptions(\"%s\", \"%s\")..\n", | 487 | printf(";; res_setoptions(\"%s\", \"%s\")..\n", |
@@ -371,6 +490,8 @@ res_setoptions(options, source) | |||
371 | } | 490 | } |
372 | printf(";;\tdebug\n"); | 491 | printf(";;\tdebug\n"); |
373 | #endif | 492 | #endif |
493 | } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) { | ||
494 | _res.options |= RES_USE_INET6; | ||
374 | } else { | 495 | } else { |
375 | /* XXX - print a warning here? */ | 496 | /* XXX - print a warning here? */ |
376 | } | 497 | } |
@@ -380,6 +501,8 @@ res_setoptions(options, source) | |||
380 | } | 501 | } |
381 | } | 502 | } |
382 | 503 | ||
504 | #ifdef RESOLVSORT | ||
505 | /* XXX - should really support CIDR which means explicit masks always. */ | ||
383 | static u_int32_t | 506 | static u_int32_t |
384 | net_mask(in) /* XXX - should really use system's version of this */ | 507 | net_mask(in) /* XXX - should really use system's version of this */ |
385 | struct in_addr in; | 508 | struct in_addr in; |
@@ -388,7 +511,8 @@ net_mask(in) /* XXX - should really use system's version of this */ | |||
388 | 511 | ||
389 | if (IN_CLASSA(i)) | 512 | if (IN_CLASSA(i)) |
390 | return (htonl(IN_CLASSA_NET)); | 513 | return (htonl(IN_CLASSA_NET)); |
391 | if (IN_CLASSB(i)) | 514 | else if (IN_CLASSB(i)) |
392 | return (htonl(IN_CLASSB_NET)); | 515 | return (htonl(IN_CLASSB_NET)); |
393 | return (htonl(IN_CLASSC_NET)); | 516 | return (htonl(IN_CLASSC_NET)); |
394 | } | 517 | } |
518 | #endif | ||
diff --git a/src/lib/libc/net/res_mkquery.c b/src/lib/libc/net/res_mkquery.c index 25f025e147..3e7e2ae5d3 100644 --- a/src/lib/libc/net/res_mkquery.c +++ b/src/lib/libc/net/res_mkquery.c | |||
@@ -1,9 +1,11 @@ | |||
1 | /* $NetBSD: res_mkquery.c,v 1.5 1995/02/25 06:20:58 cgd Exp $ */ | 1 | /* $OpenBSD: res_mkquery.c,v 1.8 1997/04/13 22:37:21 provos Exp $ */ |
2 | 2 | ||
3 | /*- | 3 | /* |
4 | * ++Copyright++ 1985, 1993 | ||
5 | * - | ||
4 | * Copyright (c) 1985, 1993 | 6 | * Copyright (c) 1985, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 7 | * The Regents of the University of California. All rights reserved. |
6 | * | 8 | * |
7 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions |
9 | * are met: | 11 | * are met: |
@@ -14,12 +16,12 @@ | |||
14 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
15 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. All advertising materials mentioning features or use of this software |
16 | * must display the following acknowledgement: | 18 | * must display the following acknowledgement: |
17 | * This product includes software developed by the University of | 19 | * This product includes software developed by the University of |
18 | * California, Berkeley and its contributors. | 20 | * California, Berkeley and its contributors. |
19 | * 4. Neither the name of the University nor the names of its contributors | 21 | * 4. Neither the name of the University nor the names of its contributors |
20 | * may be used to endorse or promote products derived from this software | 22 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. | 23 | * without specific prior written permission. |
22 | * | 24 | * |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -56,39 +58,47 @@ | |||
56 | #if defined(LIBC_SCCS) && !defined(lint) | 58 | #if defined(LIBC_SCCS) && !defined(lint) |
57 | #if 0 | 59 | #if 0 |
58 | static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; | 60 | static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; |
59 | static char rcsid[] = "$Id: res_mkquery.c,v 4.9.1.2 1993/05/17 10:00:01 vixie Exp "; | 61 | static char rcsid[] = "$From: res_mkquery.c,v 8.5 1996/08/27 08:33:28 vixie Exp $"; |
60 | #else | 62 | #else |
61 | static char rcsid[] = "$NetBSD: res_mkquery.c,v 1.5 1995/02/25 06:20:58 cgd Exp $"; | 63 | static char rcsid[] = "$OpenBSD: res_mkquery.c,v 1.8 1997/04/13 22:37:21 provos Exp $"; |
62 | #endif | 64 | #endif |
63 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
64 | 66 | ||
67 | #include <sys/types.h> | ||
65 | #include <sys/param.h> | 68 | #include <sys/param.h> |
66 | #include <netinet/in.h> | 69 | #include <netinet/in.h> |
67 | #include <arpa/nameser.h> | 70 | #include <arpa/nameser.h> |
68 | #include <resolv.h> | 71 | |
69 | #include <stdio.h> | 72 | #include <stdio.h> |
73 | #include <netdb.h> | ||
74 | #include <resolv.h> | ||
70 | #include <string.h> | 75 | #include <string.h> |
71 | 76 | ||
72 | /* | 77 | /* |
73 | * Form all types of queries. | 78 | * Form all types of queries. |
74 | * Returns the size of the result or -1. | 79 | * Returns the size of the result or -1. |
75 | */ | 80 | */ |
81 | /* ARGSUSED */ | ||
82 | int | ||
76 | res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) | 83 | res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) |
77 | int op; /* opcode of query */ | 84 | int op; /* opcode of query */ |
78 | const char *dname; /* domain name */ | 85 | const char *dname; /* domain name */ |
79 | int class, type; /* class and type of query */ | 86 | int class, type; /* class and type of query */ |
80 | const char *data; /* resource record data */ | 87 | const u_char *data; /* resource record data */ |
81 | int datalen; /* length of data */ | 88 | int datalen; /* length of data */ |
82 | const char *newrr_in; /* new rr for modify or append */ | 89 | const u_char *newrr_in; /* new rr for modify or append */ |
83 | char *buf; /* buffer to put query */ | 90 | u_char *buf; /* buffer to put query */ |
84 | int buflen; /* size of buffer */ | 91 | int buflen; /* size of buffer */ |
85 | { | 92 | { |
86 | register HEADER *hp; | 93 | register HEADER *hp; |
87 | register char *cp; | 94 | register u_char *cp; |
88 | register int n; | 95 | register int n; |
89 | struct rrec *newrr = (struct rrec *) newrr_in; | 96 | u_char *dnptrs[20], **dpp, **lastdnptr; |
90 | char *dnptrs[10], **dpp, **lastdnptr; | ||
91 | 97 | ||
98 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | ||
99 | h_errno = NETDB_INTERNAL; | ||
100 | return (-1); | ||
101 | } | ||
92 | #ifdef DEBUG | 102 | #ifdef DEBUG |
93 | if (_res.options & RES_DEBUG) | 103 | if (_res.options & RES_DEBUG) |
94 | printf(";; res_mkquery(%d, %s, %d, %d)\n", | 104 | printf(";; res_mkquery(%d, %s, %d, %d)\n", |
@@ -96,38 +106,43 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) | |||
96 | #endif | 106 | #endif |
97 | /* | 107 | /* |
98 | * Initialize header fields. | 108 | * Initialize header fields. |
109 | * | ||
110 | * A special random number generator is used to create non predictable | ||
111 | * and non repeating ids over a long period. It also avoids reuse | ||
112 | * by switching between two distinct number cycles. | ||
99 | */ | 113 | */ |
100 | if ((buf == NULL) || (buflen < sizeof(HEADER))) | 114 | |
101 | return(-1); | 115 | if ((buf == NULL) || (buflen < HFIXEDSZ)) |
102 | bzero(buf, sizeof(HEADER)); | 116 | return (-1); |
117 | bzero(buf, HFIXEDSZ); | ||
103 | hp = (HEADER *) buf; | 118 | hp = (HEADER *) buf; |
104 | hp->id = htons(++_res.id); | 119 | _res.id = res_randomid(); |
120 | hp->id = htons(_res.id); | ||
105 | hp->opcode = op; | 121 | hp->opcode = op; |
106 | hp->pr = (_res.options & RES_PRIMARY) != 0; | ||
107 | hp->rd = (_res.options & RES_RECURSE) != 0; | 122 | hp->rd = (_res.options & RES_RECURSE) != 0; |
108 | hp->rcode = NOERROR; | 123 | hp->rcode = NOERROR; |
109 | cp = buf + sizeof(HEADER); | 124 | cp = buf + HFIXEDSZ; |
110 | buflen -= sizeof(HEADER); | 125 | buflen -= HFIXEDSZ; |
111 | dpp = dnptrs; | 126 | dpp = dnptrs; |
112 | *dpp++ = buf; | 127 | *dpp++ = buf; |
113 | *dpp++ = NULL; | 128 | *dpp++ = NULL; |
114 | lastdnptr = dnptrs + sizeof(dnptrs)/sizeof(dnptrs[0]); | 129 | lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0]; |
115 | /* | 130 | /* |
116 | * perform opcode specific processing | 131 | * perform opcode specific processing |
117 | */ | 132 | */ |
118 | switch (op) { | 133 | switch (op) { |
119 | case QUERY: | 134 | case QUERY: /*FALLTHROUGH*/ |
135 | case NS_NOTIFY_OP: | ||
120 | if ((buflen -= QFIXEDSZ) < 0) | 136 | if ((buflen -= QFIXEDSZ) < 0) |
121 | return(-1); | 137 | return (-1); |
122 | if ((n = dn_comp((u_char *)dname, (u_char *)cp, buflen, | 138 | if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0) |
123 | (u_char **)dnptrs, (u_char **)lastdnptr)) < 0) | ||
124 | return (-1); | 139 | return (-1); |
125 | cp += n; | 140 | cp += n; |
126 | buflen -= n; | 141 | buflen -= n; |
127 | __putshort(type, (u_char *)cp); | 142 | __putshort(type, cp); |
128 | cp += sizeof(u_int16_t); | 143 | cp += INT16SZ; |
129 | __putshort(class, (u_char *)cp); | 144 | __putshort(class, cp); |
130 | cp += sizeof(u_int16_t); | 145 | cp += INT16SZ; |
131 | hp->qdcount = htons(1); | 146 | hp->qdcount = htons(1); |
132 | if (op == QUERY || data == NULL) | 147 | if (op == QUERY || data == NULL) |
133 | break; | 148 | break; |
@@ -135,19 +150,19 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) | |||
135 | * Make an additional record for completion domain. | 150 | * Make an additional record for completion domain. |
136 | */ | 151 | */ |
137 | buflen -= RRFIXEDSZ; | 152 | buflen -= RRFIXEDSZ; |
138 | if ((n = dn_comp((u_char *)data, (u_char *)cp, buflen, | 153 | n = dn_comp((char *)data, cp, buflen, dnptrs, lastdnptr); |
139 | (u_char **)dnptrs, (u_char **)lastdnptr)) < 0) | 154 | if (n < 0) |
140 | return (-1); | 155 | return (-1); |
141 | cp += n; | 156 | cp += n; |
142 | buflen -= n; | 157 | buflen -= n; |
143 | __putshort(T_NULL, (u_char *)cp); | 158 | __putshort(T_NULL, cp); |
144 | cp += sizeof(u_int16_t); | 159 | cp += INT16SZ; |
145 | __putshort(class, (u_char *)cp); | 160 | __putshort(class, cp); |
146 | cp += sizeof(u_int16_t); | 161 | cp += INT16SZ; |
147 | __putlong(0, (u_char *)cp); | 162 | __putlong(0, cp); |
148 | cp += sizeof(u_int32_t); | 163 | cp += INT32SZ; |
149 | __putshort(0, (u_char *)cp); | 164 | __putshort(0, cp); |
150 | cp += sizeof(u_int16_t); | 165 | cp += INT16SZ; |
151 | hp->arcount = htons(1); | 166 | hp->arcount = htons(1); |
152 | break; | 167 | break; |
153 | 168 | ||
@@ -158,79 +173,23 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) | |||
158 | if (buflen < 1 + RRFIXEDSZ + datalen) | 173 | if (buflen < 1 + RRFIXEDSZ + datalen) |
159 | return (-1); | 174 | return (-1); |
160 | *cp++ = '\0'; /* no domain name */ | 175 | *cp++ = '\0'; /* no domain name */ |
161 | __putshort(type, (u_char *)cp); | ||
162 | cp += sizeof(u_int16_t); | ||
163 | __putshort(class, (u_char *)cp); | ||
164 | cp += sizeof(u_int16_t); | ||
165 | __putlong(0, (u_char *)cp); | ||
166 | cp += sizeof(u_int32_t); | ||
167 | __putshort(datalen, (u_char *)cp); | ||
168 | cp += sizeof(u_int16_t); | ||
169 | if (datalen) { | ||
170 | bcopy(data, cp, datalen); | ||
171 | cp += datalen; | ||
172 | } | ||
173 | hp->ancount = htons(1); | ||
174 | break; | ||
175 | |||
176 | #ifdef ALLOW_UPDATES | ||
177 | /* | ||
178 | * For UPDATEM/UPDATEMA, do UPDATED/UPDATEDA followed by UPDATEA | ||
179 | * (Record to be modified is followed by its replacement in msg.) | ||
180 | */ | ||
181 | case UPDATEM: | ||
182 | case UPDATEMA: | ||
183 | |||
184 | case UPDATED: | ||
185 | /* | ||
186 | * The res code for UPDATED and UPDATEDA is the same; user | ||
187 | * calls them differently: specifies data for UPDATED; server | ||
188 | * ignores data if specified for UPDATEDA. | ||
189 | */ | ||
190 | case UPDATEDA: | ||
191 | buflen -= RRFIXEDSZ + datalen; | ||
192 | if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0) | ||
193 | return (-1); | ||
194 | cp += n; | ||
195 | __putshort(type, cp); | 176 | __putshort(type, cp); |
196 | cp += sizeof(u_int16_t); | 177 | cp += INT16SZ; |
197 | __putshort(class, cp); | 178 | __putshort(class, cp); |
198 | cp += sizeof(u_int16_t); | 179 | cp += INT16SZ; |
199 | __putlong(0, cp); | 180 | __putlong(0, cp); |
200 | cp += sizeof(u_int32_t); | 181 | cp += INT32SZ; |
201 | __putshort(datalen, cp); | 182 | __putshort(datalen, cp); |
202 | cp += sizeof(u_int16_t); | 183 | cp += INT16SZ; |
203 | if (datalen) { | 184 | if (datalen) { |
204 | bcopy(data, cp, datalen); | 185 | bcopy(data, cp, datalen); |
205 | cp += datalen; | 186 | cp += datalen; |
206 | } | 187 | } |
207 | if ( (op == UPDATED) || (op == UPDATEDA) ) { | 188 | hp->ancount = htons(1); |
208 | hp->ancount = htons(0); | ||
209 | break; | ||
210 | } | ||
211 | /* Else UPDATEM/UPDATEMA, so drop into code for UPDATEA */ | ||
212 | |||
213 | case UPDATEA: /* Add new resource record */ | ||
214 | buflen -= RRFIXEDSZ + datalen; | ||
215 | if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0) | ||
216 | return (-1); | ||
217 | cp += n; | ||
218 | __putshort(newrr->r_type, cp); | ||
219 | cp += sizeof(u_int16_t); | ||
220 | __putshort(newrr->r_class, cp); | ||
221 | cp += sizeof(u_int16_t); | ||
222 | __putlong(0, cp); | ||
223 | cp += sizeof(u_int32_t); | ||
224 | __putshort(newrr->r_size, cp); | ||
225 | cp += sizeof(u_int16_t); | ||
226 | if (newrr->r_size) { | ||
227 | bcopy(newrr->r_data, cp, newrr->r_size); | ||
228 | cp += newrr->r_size; | ||
229 | } | ||
230 | hp->ancount = htons(0); | ||
231 | break; | 189 | break; |
232 | 190 | ||
233 | #endif /* ALLOW_UPDATES */ | 191 | default: |
192 | return (-1); | ||
234 | } | 193 | } |
235 | return (cp - buf); | 194 | return (cp - buf); |
236 | } | 195 | } |
diff --git a/src/lib/libc/net/res_query.c b/src/lib/libc/net/res_query.c index 7649462e56..a08897b45a 100644 --- a/src/lib/libc/net/res_query.c +++ b/src/lib/libc/net/res_query.c | |||
@@ -1,9 +1,11 @@ | |||
1 | /* $NetBSD: res_query.c,v 1.9 1995/02/25 06:58:58 cgd Exp $ */ | 1 | /* $OpenBSD: res_query.c,v 1.12 1998/08/31 18:15:29 deraadt Exp $ */ |
2 | 2 | ||
3 | /*- | 3 | /* |
4 | * ++Copyright++ 1988, 1993 | ||
5 | * - | ||
4 | * Copyright (c) 1988, 1993 | 6 | * Copyright (c) 1988, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 7 | * The Regents of the University of California. All rights reserved. |
6 | * | 8 | * |
7 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions |
9 | * are met: | 11 | * are met: |
@@ -14,12 +16,12 @@ | |||
14 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
15 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. All advertising materials mentioning features or use of this software |
16 | * must display the following acknowledgement: | 18 | * must display the following acknowledgement: |
17 | * This product includes software developed by the University of | 19 | * This product includes software developed by the University of |
18 | * California, Berkeley and its contributors. | 20 | * California, Berkeley and its contributors. |
19 | * 4. Neither the name of the University nor the names of its contributors | 21 | * 4. Neither the name of the University nor the names of its contributors |
20 | * may be used to endorse or promote products derived from this software | 22 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. | 23 | * without specific prior written permission. |
22 | * | 24 | * |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -56,23 +58,26 @@ | |||
56 | #if defined(LIBC_SCCS) && !defined(lint) | 58 | #if defined(LIBC_SCCS) && !defined(lint) |
57 | #if 0 | 59 | #if 0 |
58 | static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; | 60 | static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; |
59 | static char rcsid[] = "$Id: res_query.c,v 1.1 1993/06/01 09:42:14 vixie Exp vixie "; | 61 | static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $"; |
60 | #else | 62 | #else |
61 | static char rcsid[] = "$NetBSD: res_query.c,v 1.9 1995/02/25 06:58:58 cgd Exp $"; | 63 | static char rcsid[] = "$OpenBSD: res_query.c,v 1.12 1998/08/31 18:15:29 deraadt Exp $"; |
62 | #endif | 64 | #endif |
63 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
64 | 66 | ||
67 | #include <sys/types.h> | ||
65 | #include <sys/param.h> | 68 | #include <sys/param.h> |
66 | #include <netinet/in.h> | 69 | #include <netinet/in.h> |
67 | #include <arpa/inet.h> | 70 | #include <arpa/inet.h> |
68 | #include <arpa/nameser.h> | 71 | #include <arpa/nameser.h> |
72 | |||
73 | #include <stdio.h> | ||
69 | #include <netdb.h> | 74 | #include <netdb.h> |
70 | #include <resolv.h> | 75 | #include <resolv.h> |
71 | #include <stdio.h> | ||
72 | #include <ctype.h> | 76 | #include <ctype.h> |
73 | #include <errno.h> | 77 | #include <errno.h> |
74 | #include <stdlib.h> | 78 | #include <stdlib.h> |
75 | #include <string.h> | 79 | #include <string.h> |
80 | #include <unistd.h> | ||
76 | 81 | ||
77 | #if PACKETSZ > 1024 | 82 | #if PACKETSZ > 1024 |
78 | #define MAXPACKET PACKETSZ | 83 | #define MAXPACKET PACKETSZ |
@@ -80,7 +85,7 @@ static char rcsid[] = "$NetBSD: res_query.c,v 1.9 1995/02/25 06:58:58 cgd Exp $" | |||
80 | #define MAXPACKET 1024 | 85 | #define MAXPACKET 1024 |
81 | #endif | 86 | #endif |
82 | 87 | ||
83 | char *__hostalias __P((const char *)); | 88 | const char *hostalias __P((const char *)); |
84 | int h_errno; | 89 | int h_errno; |
85 | 90 | ||
86 | /* | 91 | /* |
@@ -90,27 +95,33 @@ int h_errno; | |||
90 | * if no error is indicated and the answer count is nonzero. | 95 | * if no error is indicated and the answer count is nonzero. |
91 | * Return the size of the response on success, -1 on error. | 96 | * Return the size of the response on success, -1 on error. |
92 | * Error number is left in h_errno. | 97 | * Error number is left in h_errno. |
98 | * | ||
93 | * Caller must parse answer and determine whether it answers the question. | 99 | * Caller must parse answer and determine whether it answers the question. |
94 | */ | 100 | */ |
101 | int | ||
95 | res_query(name, class, type, answer, anslen) | 102 | res_query(name, class, type, answer, anslen) |
96 | char *name; /* domain name */ | 103 | const char *name; /* domain name */ |
97 | int class, type; /* class and type of query */ | 104 | int class, type; /* class and type of query */ |
98 | u_char *answer; /* buffer to put answer */ | 105 | u_char *answer; /* buffer to put answer */ |
99 | int anslen; /* size of answer buffer */ | 106 | int anslen; /* size of answer buffer */ |
100 | { | 107 | { |
101 | char buf[MAXPACKET]; | 108 | u_char buf[MAXPACKET]; |
102 | HEADER *hp; | 109 | register HEADER *hp = (HEADER *) answer; |
103 | int n; | 110 | int n; |
104 | 111 | ||
105 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 112 | hp->rcode = NOERROR; /* default */ |
113 | |||
114 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | ||
115 | h_errno = NETDB_INTERNAL; | ||
106 | return (-1); | 116 | return (-1); |
117 | } | ||
107 | #ifdef DEBUG | 118 | #ifdef DEBUG |
108 | if (_res.options & RES_DEBUG) | 119 | if (_res.options & RES_DEBUG) |
109 | printf(";; res_query(%s, %d, %d)\n", name, class, type); | 120 | printf(";; res_query(%s, %d, %d)\n", name, class, type); |
110 | #endif | 121 | #endif |
111 | n = res_mkquery(QUERY, name, class, type, (char *)NULL, 0, NULL, | ||
112 | buf, sizeof(buf)); | ||
113 | 122 | ||
123 | n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, | ||
124 | buf, sizeof(buf)); | ||
114 | if (n <= 0) { | 125 | if (n <= 0) { |
115 | #ifdef DEBUG | 126 | #ifdef DEBUG |
116 | if (_res.options & RES_DEBUG) | 127 | if (_res.options & RES_DEBUG) |
@@ -119,7 +130,7 @@ res_query(name, class, type, answer, anslen) | |||
119 | h_errno = NO_RECOVERY; | 130 | h_errno = NO_RECOVERY; |
120 | return (n); | 131 | return (n); |
121 | } | 132 | } |
122 | n = res_send(buf, n, (char *)answer, anslen); | 133 | n = res_send(buf, n, answer, anslen); |
123 | if (n < 0) { | 134 | if (n < 0) { |
124 | #ifdef DEBUG | 135 | #ifdef DEBUG |
125 | if (_res.options & RES_DEBUG) | 136 | if (_res.options & RES_DEBUG) |
@@ -129,7 +140,6 @@ res_query(name, class, type, answer, anslen) | |||
129 | return (n); | 140 | return (n); |
130 | } | 141 | } |
131 | 142 | ||
132 | hp = (HEADER *) answer; | ||
133 | if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) { | 143 | if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) { |
134 | #ifdef DEBUG | 144 | #ifdef DEBUG |
135 | if (_res.options & RES_DEBUG) | 145 | if (_res.options & RES_DEBUG) |
@@ -137,21 +147,21 @@ res_query(name, class, type, answer, anslen) | |||
137 | ntohs(hp->ancount)); | 147 | ntohs(hp->ancount)); |
138 | #endif | 148 | #endif |
139 | switch (hp->rcode) { | 149 | switch (hp->rcode) { |
140 | case NXDOMAIN: | 150 | case NXDOMAIN: |
141 | h_errno = HOST_NOT_FOUND; | 151 | h_errno = HOST_NOT_FOUND; |
142 | break; | 152 | break; |
143 | case SERVFAIL: | 153 | case SERVFAIL: |
144 | h_errno = TRY_AGAIN; | 154 | h_errno = TRY_AGAIN; |
145 | break; | 155 | break; |
146 | case NOERROR: | 156 | case NOERROR: |
147 | h_errno = NO_DATA; | 157 | h_errno = NO_DATA; |
148 | break; | 158 | break; |
149 | case FORMERR: | 159 | case FORMERR: |
150 | case NOTIMP: | 160 | case NOTIMP: |
151 | case REFUSED: | 161 | case REFUSED: |
152 | default: | 162 | default: |
153 | h_errno = NO_RECOVERY; | 163 | h_errno = NO_RECOVERY; |
154 | break; | 164 | break; |
155 | } | 165 | } |
156 | return (-1); | 166 | return (-1); |
157 | } | 167 | } |
@@ -162,9 +172,7 @@ res_query(name, class, type, answer, anslen) | |||
162 | * Formulate a normal query, send, and retrieve answer in supplied buffer. | 172 | * Formulate a normal query, send, and retrieve answer in supplied buffer. |
163 | * Return the size of the response on success, -1 on error. | 173 | * Return the size of the response on success, -1 on error. |
164 | * If enabled, implement search rules until answer or unrecoverable failure | 174 | * If enabled, implement search rules until answer or unrecoverable failure |
165 | * is detected. Error number is left in h_errno. | 175 | * is detected. Error code, if any, is left in h_errno. |
166 | * Only useful for queries in the same name hierarchy as the local host | ||
167 | * (not, for example, for host address-to-name lookups in domain in-addr.arpa). | ||
168 | */ | 176 | */ |
169 | int | 177 | int |
170 | res_search(name, class, type, answer, anslen) | 178 | res_search(name, class, type, answer, anslen) |
@@ -173,28 +181,29 @@ res_search(name, class, type, answer, anslen) | |||
173 | u_char *answer; /* buffer to put answer */ | 181 | u_char *answer; /* buffer to put answer */ |
174 | int anslen; /* size of answer */ | 182 | int anslen; /* size of answer */ |
175 | { | 183 | { |
176 | register char *cp, **domain; | 184 | register const char *cp, * const *domain; |
177 | int dots, trailing_dot, ret, got_nodata, saved_herrno, tried_as_is; | 185 | HEADER *hp = (HEADER *) answer; |
186 | u_int dots; | ||
187 | int trailing_dot, ret, saved_herrno; | ||
188 | int got_nodata = 0, got_servfail = 0, tried_as_is = 0; | ||
178 | 189 | ||
179 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 190 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { |
191 | h_errno = NETDB_INTERNAL; | ||
180 | return (-1); | 192 | return (-1); |
181 | 193 | } | |
182 | got_nodata = 0; | ||
183 | errno = 0; | 194 | errno = 0; |
184 | h_errno = HOST_NOT_FOUND; /* default, if we never query */ | 195 | h_errno = HOST_NOT_FOUND; /* default, if we never query */ |
185 | dots = 0; | 196 | dots = 0; |
186 | for (cp = (char *)name; *cp; cp++) { | 197 | for (cp = name; *cp; cp++) |
187 | if (*cp == '.') | 198 | dots += (*cp == '.'); |
188 | dots++; | ||
189 | } | ||
190 | trailing_dot = 0; | 199 | trailing_dot = 0; |
191 | if ((cp > name) && (*--cp == '.')) | 200 | if (cp > name && *--cp == '.') |
192 | trailing_dot++; | 201 | trailing_dot++; |
193 | 202 | ||
194 | /* | 203 | /* |
195 | * if there aren't any dots, it could be a user-level alias | 204 | * if there aren't any dots, it could be a user-level alias |
196 | */ | 205 | */ |
197 | if (!dots && (cp = __hostalias(name))) | 206 | if (!dots && (cp = __hostalias(name)) != NULL) |
198 | return (res_query(cp, class, type, answer, anslen)); | 207 | return (res_query(cp, class, type, answer, anslen)); |
199 | 208 | ||
200 | /* | 209 | /* |
@@ -202,7 +211,6 @@ res_search(name, class, type, answer, anslen) | |||
202 | * 'as is'. The threshold can be set with the "ndots" option. | 211 | * 'as is'. The threshold can be set with the "ndots" option. |
203 | */ | 212 | */ |
204 | saved_herrno = -1; | 213 | saved_herrno = -1; |
205 | tried_as_is = 0; | ||
206 | if (dots >= _res.ndots) { | 214 | if (dots >= _res.ndots) { |
207 | ret = res_querydomain(name, NULL, class, type, answer, anslen); | 215 | ret = res_querydomain(name, NULL, class, type, answer, anslen); |
208 | if (ret > 0) | 216 | if (ret > 0) |
@@ -219,13 +227,17 @@ res_search(name, class, type, answer, anslen) | |||
219 | */ | 227 | */ |
220 | if ((!dots && (_res.options & RES_DEFNAMES)) || | 228 | if ((!dots && (_res.options & RES_DEFNAMES)) || |
221 | (dots && !trailing_dot && (_res.options & RES_DNSRCH))) { | 229 | (dots && !trailing_dot && (_res.options & RES_DNSRCH))) { |
222 | for (domain = _res.dnsrch; *domain; domain++) { | 230 | int done = 0; |
223 | int done = 0; | 231 | |
232 | for (domain = (const char * const *)_res.dnsrch; | ||
233 | *domain && !done; | ||
234 | domain++) { | ||
224 | 235 | ||
225 | ret = res_querydomain(name, *domain, class, type, | 236 | ret = res_querydomain(name, *domain, class, type, |
226 | answer, anslen); | 237 | answer, anslen); |
227 | if (ret > 0) | 238 | if (ret > 0) |
228 | return (ret); | 239 | return (ret); |
240 | |||
229 | /* | 241 | /* |
230 | * If no server present, give up. | 242 | * If no server present, give up. |
231 | * If name isn't found in this domain, | 243 | * If name isn't found in this domain, |
@@ -251,24 +263,27 @@ res_search(name, class, type, answer, anslen) | |||
251 | case HOST_NOT_FOUND: | 263 | case HOST_NOT_FOUND: |
252 | /* keep trying */ | 264 | /* keep trying */ |
253 | break; | 265 | break; |
266 | case TRY_AGAIN: | ||
267 | if (hp->rcode == SERVFAIL) { | ||
268 | /* try next search element, if any */ | ||
269 | got_servfail++; | ||
270 | break; | ||
271 | } | ||
272 | /* FALLTHROUGH */ | ||
254 | default: | 273 | default: |
255 | /* anything else implies that we're done */ | 274 | /* anything else implies that we're done */ |
256 | done++; | 275 | done++; |
257 | } | 276 | } |
258 | /* | 277 | |
259 | * if we got here for some reason other than DNSRCH, | 278 | /* if we got here for some reason other than DNSRCH, |
260 | * we only wanted one iteration of the loop, so stop. | 279 | * we only wanted one iteration of the loop, so stop. |
261 | */ | 280 | */ |
262 | if (!(_res.options & RES_DNSRCH)) | 281 | if (!(_res.options & RES_DNSRCH)) |
263 | done++; | 282 | done++; |
264 | |||
265 | if (done) | ||
266 | break; | ||
267 | } | 283 | } |
268 | } | 284 | } |
269 | 285 | ||
270 | /* | 286 | /* if we have not already tried the name "as is", do that now. |
271 | * if we have not already tried the name "as is", do that now. | ||
272 | * note that we do this regardless of how many dots were in the | 287 | * note that we do this regardless of how many dots were in the |
273 | * name or whether it ends with a dot. | 288 | * name or whether it ends with a dot. |
274 | */ | 289 | */ |
@@ -276,11 +291,9 @@ res_search(name, class, type, answer, anslen) | |||
276 | ret = res_querydomain(name, NULL, class, type, answer, anslen); | 291 | ret = res_querydomain(name, NULL, class, type, answer, anslen); |
277 | if (ret > 0) | 292 | if (ret > 0) |
278 | return (ret); | 293 | return (ret); |
279 | saved_herrno = h_errno; | ||
280 | } | 294 | } |
281 | 295 | ||
282 | /* | 296 | /* if we got here, we didn't satisfy the search. |
283 | * if we got here, we didn't satisfy the search. | ||
284 | * if we did an initial full query, return that query's h_errno | 297 | * if we did an initial full query, return that query's h_errno |
285 | * (note that we wouldn't be here if that query had succeeded). | 298 | * (note that we wouldn't be here if that query had succeeded). |
286 | * else if we ever got a nodata, send that back as the reason. | 299 | * else if we ever got a nodata, send that back as the reason. |
@@ -291,6 +304,8 @@ res_search(name, class, type, answer, anslen) | |||
291 | h_errno = saved_herrno; | 304 | h_errno = saved_herrno; |
292 | else if (got_nodata) | 305 | else if (got_nodata) |
293 | h_errno = NO_DATA; | 306 | h_errno = NO_DATA; |
307 | else if (got_servfail) | ||
308 | h_errno = TRY_AGAIN; | ||
294 | return (-1); | 309 | return (-1); |
295 | } | 310 | } |
296 | 311 | ||
@@ -298,20 +313,25 @@ res_search(name, class, type, answer, anslen) | |||
298 | * Perform a call on res_query on the concatenation of name and domain, | 313 | * Perform a call on res_query on the concatenation of name and domain, |
299 | * removing a trailing dot from name if domain is NULL. | 314 | * removing a trailing dot from name if domain is NULL. |
300 | */ | 315 | */ |
316 | int | ||
301 | res_querydomain(name, domain, class, type, answer, anslen) | 317 | res_querydomain(name, domain, class, type, answer, anslen) |
302 | char *name, *domain; | 318 | const char *name, *domain; |
303 | int class, type; /* class and type of query */ | 319 | int class, type; /* class and type of query */ |
304 | u_char *answer; /* buffer to put answer */ | 320 | u_char *answer; /* buffer to put answer */ |
305 | int anslen; /* size of answer */ | 321 | int anslen; /* size of answer */ |
306 | { | 322 | { |
307 | char nbuf[2*MAXDNAME+2]; | 323 | char nbuf[MAXDNAME*2+1]; |
308 | char *longname = nbuf; | 324 | const char *longname = nbuf; |
309 | int n; | 325 | int n; |
310 | 326 | ||
327 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | ||
328 | h_errno = NETDB_INTERNAL; | ||
329 | return (-1); | ||
330 | } | ||
311 | #ifdef DEBUG | 331 | #ifdef DEBUG |
312 | if (_res.options & RES_DEBUG) | 332 | if (_res.options & RES_DEBUG) |
313 | printf(";; res_querydomain(%s, %s, %d, %d)\n", | 333 | printf(";; res_querydomain(%s, %s, %d, %d)\n", |
314 | name, domain, class, type); | 334 | name, domain?domain:"<Nil>", class, type); |
315 | #endif | 335 | #endif |
316 | if (domain == NULL) { | 336 | if (domain == NULL) { |
317 | /* | 337 | /* |
@@ -325,38 +345,50 @@ res_querydomain(name, domain, class, type, answer, anslen) | |||
325 | } else | 345 | } else |
326 | longname = name; | 346 | longname = name; |
327 | } else | 347 | } else |
328 | (void)sprintf(nbuf, "%.*s.%.*s", | 348 | sprintf(nbuf, "%.*s.%.*s", MAXDNAME, name, MAXDNAME, domain); |
329 | MAXDNAME, name, MAXDNAME, domain); | ||
330 | 349 | ||
331 | return (res_query(longname, class, type, answer, anslen)); | 350 | return (res_query(longname, class, type, answer, anslen)); |
332 | } | 351 | } |
333 | 352 | ||
334 | char * | 353 | const char * |
335 | __hostalias(name) | 354 | hostalias(name) |
336 | register const char *name; | 355 | register const char *name; |
337 | { | 356 | { |
338 | register char *cp1, *cp2; | 357 | register char *cp1, *cp2; |
339 | FILE *fp; | 358 | FILE *fp; |
340 | char *file, *getenv(), *strcpy(), *strncpy(); | 359 | char *file; |
341 | char buf[BUFSIZ]; | 360 | char buf[BUFSIZ]; |
342 | static char abuf[MAXDNAME]; | 361 | static char abuf[MAXDNAME]; |
362 | size_t len; | ||
343 | 363 | ||
364 | if (_res.options & RES_NOALIASES) | ||
365 | return (NULL); | ||
344 | file = getenv("HOSTALIASES"); | 366 | file = getenv("HOSTALIASES"); |
345 | if (file == NULL || (fp = fopen(file, "r")) == NULL) | 367 | if (issetugid() != 0 || file == NULL || (fp = fopen(file, "r")) == NULL) |
346 | return (NULL); | 368 | return (NULL); |
347 | buf[sizeof(buf) - 1] = '\0'; | 369 | setbuf(fp, NULL); |
348 | while (fgets(buf, sizeof(buf), fp)) { | 370 | while ((cp1 = fgetln(fp, &len)) != NULL) { |
349 | for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1); | 371 | if (cp1[len-1] == '\n') |
372 | len--; | ||
373 | if (len >= sizeof(buf) || len == 0) | ||
374 | continue; | ||
375 | (void)memcpy(buf, cp1, len); | ||
376 | buf[len] = '\0'; | ||
377 | |||
378 | for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1) | ||
379 | ; | ||
350 | if (!*cp1) | 380 | if (!*cp1) |
351 | break; | 381 | break; |
352 | *cp1 = '\0'; | 382 | *cp1 = '\0'; |
353 | if (!strcasecmp(buf, name)) { | 383 | if (!strcasecmp(buf, name)) { |
354 | while (isspace(*++cp1)); | 384 | while (isspace(*++cp1)) |
385 | ; | ||
355 | if (!*cp1) | 386 | if (!*cp1) |
356 | break; | 387 | break; |
357 | for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2); | 388 | for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2) |
389 | ; | ||
390 | strncpy(abuf, cp1, sizeof(abuf) - 1); | ||
358 | abuf[sizeof(abuf) - 1] = *cp2 = '\0'; | 391 | abuf[sizeof(abuf) - 1] = *cp2 = '\0'; |
359 | (void)strncpy(abuf, cp1, sizeof(abuf) - 1); | ||
360 | fclose(fp); | 392 | fclose(fp); |
361 | return (abuf); | 393 | return (abuf); |
362 | } | 394 | } |
diff --git a/src/lib/libc/net/res_random.c b/src/lib/libc/net/res_random.c new file mode 100644 index 0000000000..bd32a50c33 --- /dev/null +++ b/src/lib/libc/net/res_random.c | |||
@@ -0,0 +1,233 @@ | |||
1 | /* $OpenBSD: res_random.c,v 1.7 1997/07/25 20:30:08 mickey Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Theo de Raadt <deraadt@openbsd.org> came up with the idea of using | ||
8 | * such a mathematical system to generate more random (yet non-repeating) | ||
9 | * ids to solve the resolver/named problem. But Niels designed the | ||
10 | * actual system based on the constraints. | ||
11 | * | ||
12 | * Redistribution and use in source and binary forms, with or without | ||
13 | * modification, are permitted provided that the following conditions | ||
14 | * are met: | ||
15 | * 1. Redistributions of source code must retain the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer. | ||
17 | * 2. Redistributions in binary form must reproduce the above copyright | ||
18 | * notice, this list of conditions and the following disclaimer in the | ||
19 | * documentation and/or other materials provided with the distribution. | ||
20 | * 3. All advertising materials mentioning features or use of this software | ||
21 | * must display the following acknowledgement: | ||
22 | * This product includes software developed by Niels Provos. | ||
23 | * 4. The name of the author may not be used to endorse or promote products | ||
24 | * derived from this software without specific prior written permission. | ||
25 | * | ||
26 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
27 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
28 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
29 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
30 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
31 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
32 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
33 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
35 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
36 | */ | ||
37 | |||
38 | /* | ||
39 | * seed = random 15bit | ||
40 | * n = prime, g0 = generator to n, | ||
41 | * j = random so that gcd(j,n-1) == 1 | ||
42 | * g = g0^j mod n will be a generator again. | ||
43 | * | ||
44 | * X[0] = random seed. | ||
45 | * X[n] = a*X[n-1]+b mod m is a Linear Congruential Generator | ||
46 | * with a = 7^(even random) mod m, | ||
47 | * b = random with gcd(b,m) == 1 | ||
48 | * m = 31104 and a maximal period of m-1. | ||
49 | * | ||
50 | * The transaction id is determined by: | ||
51 | * id[n] = seed xor (g^X[n] mod n) | ||
52 | * | ||
53 | * Effectivly the id is restricted to the lower 15 bits, thus | ||
54 | * yielding two different cycles by toggling the msb on and off. | ||
55 | * This avoids reuse issues caused by reseeding. | ||
56 | * | ||
57 | * The 16 bit space is very small and brute force attempts are | ||
58 | * entirly feasible, we skip a random number of transaction ids | ||
59 | * so that an attacker will not get sequential ids. | ||
60 | */ | ||
61 | |||
62 | #include <sys/types.h> | ||
63 | #include <netinet/in.h> | ||
64 | #include <sys/time.h> | ||
65 | #include <resolv.h> | ||
66 | |||
67 | #include <unistd.h> | ||
68 | #include <stdlib.h> | ||
69 | #include <string.h> | ||
70 | |||
71 | #define RU_OUT 180 /* Time after wich will be reseeded */ | ||
72 | #define RU_MAX 30000 /* Uniq cycle, avoid blackjack prediction */ | ||
73 | #define RU_GEN 2 /* Starting generator */ | ||
74 | #define RU_N 32749 /* RU_N-1 = 2*2*3*2729 */ | ||
75 | #define RU_AGEN 7 /* determine ru_a as RU_AGEN^(2*rand) */ | ||
76 | #define RU_M 31104 /* RU_M = 2^7*3^5 - don't change */ | ||
77 | |||
78 | #define PFAC_N 3 | ||
79 | const static u_int16_t pfacts[PFAC_N] = { | ||
80 | 2, | ||
81 | 3, | ||
82 | 2729 | ||
83 | }; | ||
84 | |||
85 | static u_int16_t ru_x; | ||
86 | static u_int16_t ru_seed; | ||
87 | static u_int16_t ru_a, ru_b; | ||
88 | static u_int16_t ru_g; | ||
89 | static u_int16_t ru_counter = 0; | ||
90 | static u_int16_t ru_msb = 0; | ||
91 | static long ru_reseed; | ||
92 | static u_int32_t tmp; /* Storage for unused random */ | ||
93 | static struct timeval tv; | ||
94 | |||
95 | static u_int16_t pmod __P((u_int16_t, u_int16_t, u_int16_t)); | ||
96 | static void res_initid __P((void)); | ||
97 | |||
98 | /* | ||
99 | * Do a fast modular exponation, returned value will be in the range | ||
100 | * of 0 - (mod-1) | ||
101 | */ | ||
102 | |||
103 | #ifdef __STDC__ | ||
104 | static u_int16_t | ||
105 | pmod(u_int16_t gen, u_int16_t exp, u_int16_t mod) | ||
106 | #else | ||
107 | static u_int16_t | ||
108 | pmod(gen, exp, mod) | ||
109 | u_int16_t gen, exp, mod; | ||
110 | #endif | ||
111 | { | ||
112 | u_int16_t s, t, u; | ||
113 | |||
114 | s = 1; | ||
115 | t = gen; | ||
116 | u = exp; | ||
117 | |||
118 | while (u) { | ||
119 | if (u & 1) | ||
120 | s = (s*t) % mod; | ||
121 | u >>= 1; | ||
122 | t = (t*t) % mod; | ||
123 | } | ||
124 | return (s); | ||
125 | } | ||
126 | |||
127 | /* | ||
128 | * Initalizes the seed and chooses a suitable generator. Also toggles | ||
129 | * the msb flag. The msb flag is used to generate two distinct | ||
130 | * cycles of random numbers and thus avoiding reuse of ids. | ||
131 | * | ||
132 | * This function is called from res_randomid() when needed, an | ||
133 | * application does not have to worry about it. | ||
134 | */ | ||
135 | static void | ||
136 | res_initid() | ||
137 | { | ||
138 | u_int16_t j, i; | ||
139 | int noprime = 1; | ||
140 | |||
141 | tmp = arc4random(); | ||
142 | ru_x = (tmp & 0xFFFF) % RU_M; | ||
143 | |||
144 | /* 15 bits of random seed */ | ||
145 | ru_seed = (tmp >> 16) & 0x7FFF; | ||
146 | |||
147 | tmp = arc4random(); | ||
148 | |||
149 | /* Determine the LCG we use */ | ||
150 | ru_b = (tmp & 0xfffe) | 1; | ||
151 | ru_a = pmod(RU_AGEN, (tmp >> 16) & 0xfffe, RU_M); | ||
152 | while (ru_b % 3 == 0) | ||
153 | ru_b += 2; | ||
154 | |||
155 | tmp = arc4random(); | ||
156 | j = tmp % RU_N; | ||
157 | tmp = tmp >> 16; | ||
158 | |||
159 | /* | ||
160 | * Do a fast gcd(j,RU_N-1), so we can find a j with | ||
161 | * gcd(j, RU_N-1) == 1, giving a new generator for | ||
162 | * RU_GEN^j mod RU_N | ||
163 | */ | ||
164 | |||
165 | while (noprime) { | ||
166 | for (i=0; i<PFAC_N; i++) | ||
167 | if (j%pfacts[i] == 0) | ||
168 | break; | ||
169 | |||
170 | if (i>=PFAC_N) | ||
171 | noprime = 0; | ||
172 | else | ||
173 | j = (j+1) % RU_N; | ||
174 | } | ||
175 | |||
176 | ru_g = pmod(RU_GEN,j,RU_N); | ||
177 | ru_counter = 0; | ||
178 | |||
179 | gettimeofday(&tv, NULL); | ||
180 | ru_reseed = tv.tv_sec + RU_OUT; | ||
181 | ru_msb = ru_msb == 0x8000 ? 0 : 0x8000; | ||
182 | } | ||
183 | |||
184 | u_int | ||
185 | res_randomid() | ||
186 | { | ||
187 | int i, n; | ||
188 | |||
189 | gettimeofday(&tv, NULL); | ||
190 | if (ru_counter >= RU_MAX || tv.tv_sec > ru_reseed) | ||
191 | res_initid(); | ||
192 | |||
193 | if (!tmp) | ||
194 | tmp = arc4random(); | ||
195 | |||
196 | /* Skip a random number of ids */ | ||
197 | n = tmp & 0x7; tmp = tmp >> 3; | ||
198 | if (ru_counter + n >= RU_MAX) | ||
199 | res_initid(); | ||
200 | |||
201 | for (i=0; i<=n; i++) | ||
202 | /* Linear Congruential Generator */ | ||
203 | ru_x = (ru_a*ru_x + ru_b) % RU_M; | ||
204 | |||
205 | ru_counter += i; | ||
206 | |||
207 | return (ru_seed ^ pmod(ru_g,ru_x,RU_N)) | ru_msb; | ||
208 | } | ||
209 | |||
210 | #if 0 | ||
211 | void | ||
212 | main(int argc, char **argv) | ||
213 | { | ||
214 | int i, n; | ||
215 | u_int16_t wert; | ||
216 | |||
217 | res_initid(); | ||
218 | |||
219 | printf("Generator: %d\n", ru_g); | ||
220 | printf("Seed: %d\n", ru_seed); | ||
221 | printf("Reseed at %ld\n", ru_reseed); | ||
222 | printf("Ru_X: %d\n", ru_x); | ||
223 | printf("Ru_A: %d\n", ru_a); | ||
224 | printf("Ru_B: %d\n", ru_b); | ||
225 | |||
226 | n = atoi(argv[1]); | ||
227 | for (i=0;i<n;i++) { | ||
228 | wert = res_randomid(); | ||
229 | printf("%06d\n", wert); | ||
230 | } | ||
231 | } | ||
232 | #endif | ||
233 | |||
diff --git a/src/lib/libc/net/res_send.c b/src/lib/libc/net/res_send.c index e608358180..0cda3510eb 100644 --- a/src/lib/libc/net/res_send.c +++ b/src/lib/libc/net/res_send.c | |||
@@ -1,9 +1,11 @@ | |||
1 | /* $NetBSD: res_send.c,v 1.4 1995/02/25 06:21:01 cgd Exp $ */ | 1 | /* $OpenBSD: res_send.c,v 1.8 1998/03/19 00:30:08 millert Exp $ */ |
2 | 2 | ||
3 | /*- | 3 | /* |
4 | * ++Copyright++ 1985, 1989, 1993 | ||
5 | * - | ||
4 | * Copyright (c) 1985, 1989, 1993 | 6 | * Copyright (c) 1985, 1989, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 7 | * The Regents of the University of California. All rights reserved. |
6 | * | 8 | * |
7 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions |
9 | * are met: | 11 | * are met: |
@@ -14,12 +16,12 @@ | |||
14 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
15 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. All advertising materials mentioning features or use of this software |
16 | * must display the following acknowledgement: | 18 | * must display the following acknowledgement: |
17 | * This product includes software developed by the University of | 19 | * This product includes software developed by the University of |
18 | * California, Berkeley and its contributors. | 20 | * California, Berkeley and its contributors. |
19 | * 4. Neither the name of the University nor the names of its contributors | 21 | * 4. Neither the name of the University nor the names of its contributors |
20 | * may be used to endorse or promote products derived from this software | 22 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. | 23 | * without specific prior written permission. |
22 | * | 24 | * |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -56,16 +58,24 @@ | |||
56 | #if defined(LIBC_SCCS) && !defined(lint) | 58 | #if defined(LIBC_SCCS) && !defined(lint) |
57 | #if 0 | 59 | #if 0 |
58 | static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; | 60 | static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; |
59 | static char rcsid[] = "$Id: res_send.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel "; | 61 | static char rcsid[] = "$From: res_send.c,v 8.12 1996/10/08 04:51:06 vixie Exp $"; |
60 | #else | 62 | #else |
61 | static char rcsid[] = "$NetBSD: res_send.c,v 1.4 1995/02/25 06:21:01 cgd Exp $"; | 63 | static char rcsid[] = "$OpenBSD: res_send.c,v 1.8 1998/03/19 00:30:08 millert Exp $"; |
62 | #endif | 64 | #endif |
63 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
64 | 66 | ||
67 | /* change this to "0" | ||
68 | * if you talk to a lot | ||
69 | * of multi-homed SunOS | ||
70 | * ("broken") name servers. | ||
71 | */ | ||
72 | #define CHECK_SRVR_ADDR 1 /* XXX - should be in options.h */ | ||
73 | |||
65 | /* | 74 | /* |
66 | * Send query to name server and wait for reply. | 75 | * Send query to name server and wait for reply. |
67 | */ | 76 | */ |
68 | 77 | ||
78 | #include <sys/types.h> | ||
69 | #include <sys/param.h> | 79 | #include <sys/param.h> |
70 | #include <sys/time.h> | 80 | #include <sys/time.h> |
71 | #include <sys/socket.h> | 81 | #include <sys/socket.h> |
@@ -73,16 +83,21 @@ static char rcsid[] = "$NetBSD: res_send.c,v 1.4 1995/02/25 06:21:01 cgd Exp $"; | |||
73 | #include <netinet/in.h> | 83 | #include <netinet/in.h> |
74 | #include <arpa/nameser.h> | 84 | #include <arpa/nameser.h> |
75 | #include <arpa/inet.h> | 85 | #include <arpa/inet.h> |
86 | |||
76 | #include <stdio.h> | 87 | #include <stdio.h> |
88 | #include <netdb.h> | ||
77 | #include <errno.h> | 89 | #include <errno.h> |
78 | #include <resolv.h> | 90 | #include <resolv.h> |
79 | #include <unistd.h> | 91 | #include <stdlib.h> |
80 | #include <string.h> | 92 | #include <string.h> |
93 | #include <unistd.h> | ||
81 | 94 | ||
82 | static int s = -1; /* socket used for communications */ | 95 | static int s = -1; /* socket used for communications */ |
83 | static struct sockaddr no_addr; | 96 | static int connected = 0; /* is the socket connected */ |
97 | static int vc = 0; /* is the socket a virtual ciruit? */ | ||
84 | 98 | ||
85 | #ifndef FD_SET | 99 | #ifndef FD_SET |
100 | /* XXX - should be in portability.h */ | ||
86 | #define NFDBITS 32 | 101 | #define NFDBITS 32 |
87 | #define FD_SETSIZE 32 | 102 | #define FD_SETSIZE 32 |
88 | #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) | 103 | #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) |
@@ -91,121 +106,313 @@ static struct sockaddr no_addr; | |||
91 | #define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) | 106 | #define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) |
92 | #endif | 107 | #endif |
93 | 108 | ||
94 | res_send(buf, buflen, answer, anslen) | 109 | #define CAN_RECONNECT 1 |
95 | const char *buf; | 110 | |
111 | #ifndef DEBUG | ||
112 | # define Dprint(cond, args) /*empty*/ | ||
113 | # define DprintQ(cond, args, query, size) /*empty*/ | ||
114 | # define Aerror(file, string, error, address) /*empty*/ | ||
115 | # define Perror(file, string, error) /*empty*/ | ||
116 | #else | ||
117 | # define Dprint(cond, args) if (cond) {fprintf args;} else {} | ||
118 | # define DprintQ(cond, args, query, size) if (cond) {\ | ||
119 | fprintf args;\ | ||
120 | __fp_nquery(query, size, stdout);\ | ||
121 | } else {} | ||
122 | static void | ||
123 | Aerror(file, string, error, address) | ||
124 | FILE *file; | ||
125 | char *string; | ||
126 | int error; | ||
127 | struct sockaddr_in address; | ||
128 | { | ||
129 | int save = errno; | ||
130 | |||
131 | if (_res.options & RES_DEBUG) { | ||
132 | fprintf(file, "res_send: %s ([%s].%u): %s\n", | ||
133 | string, | ||
134 | inet_ntoa(address.sin_addr), | ||
135 | ntohs(address.sin_port), | ||
136 | strerror(error)); | ||
137 | } | ||
138 | errno = save; | ||
139 | } | ||
140 | static void | ||
141 | Perror(file, string, error) | ||
142 | FILE *file; | ||
143 | char *string; | ||
144 | int error; | ||
145 | { | ||
146 | int save = errno; | ||
147 | |||
148 | if (_res.options & RES_DEBUG) { | ||
149 | fprintf(file, "res_send: %s: %s\n", | ||
150 | string, strerror(error)); | ||
151 | } | ||
152 | errno = save; | ||
153 | } | ||
154 | #endif | ||
155 | |||
156 | static res_send_qhook Qhook = NULL; | ||
157 | static res_send_rhook Rhook = NULL; | ||
158 | |||
159 | void | ||
160 | res_send_setqhook(hook) | ||
161 | res_send_qhook hook; | ||
162 | { | ||
163 | |||
164 | Qhook = hook; | ||
165 | } | ||
166 | |||
167 | void | ||
168 | res_send_setrhook(hook) | ||
169 | res_send_rhook hook; | ||
170 | { | ||
171 | |||
172 | Rhook = hook; | ||
173 | } | ||
174 | |||
175 | /* int | ||
176 | * res_isourserver(ina) | ||
177 | * looks up "ina" in _res.ns_addr_list[] | ||
178 | * returns: | ||
179 | * 0 : not found | ||
180 | * >0 : found | ||
181 | * author: | ||
182 | * paul vixie, 29may94 | ||
183 | */ | ||
184 | int | ||
185 | res_isourserver(inp) | ||
186 | const struct sockaddr_in *inp; | ||
187 | { | ||
188 | struct sockaddr_in ina; | ||
189 | register int ns, ret; | ||
190 | |||
191 | ina = *inp; | ||
192 | ret = 0; | ||
193 | for (ns = 0; ns < _res.nscount; ns++) { | ||
194 | register const struct sockaddr_in *srv = &_res.nsaddr_list[ns]; | ||
195 | |||
196 | if (srv->sin_family == ina.sin_family && | ||
197 | srv->sin_port == ina.sin_port && | ||
198 | (srv->sin_addr.s_addr == INADDR_ANY || | ||
199 | srv->sin_addr.s_addr == ina.sin_addr.s_addr)) { | ||
200 | ret++; | ||
201 | break; | ||
202 | } | ||
203 | } | ||
204 | return (ret); | ||
205 | } | ||
206 | |||
207 | /* int | ||
208 | * res_nameinquery(name, type, class, buf, eom) | ||
209 | * look for (name,type,class) in the query section of packet (buf,eom) | ||
210 | * returns: | ||
211 | * -1 : format error | ||
212 | * 0 : not found | ||
213 | * >0 : found | ||
214 | * author: | ||
215 | * paul vixie, 29may94 | ||
216 | */ | ||
217 | int | ||
218 | res_nameinquery(name, type, class, buf, eom) | ||
219 | const char *name; | ||
220 | register int type, class; | ||
221 | const u_char *buf, *eom; | ||
222 | { | ||
223 | register const u_char *cp = buf + HFIXEDSZ; | ||
224 | int qdcount = ntohs(((HEADER*)buf)->qdcount); | ||
225 | |||
226 | while (qdcount-- > 0) { | ||
227 | char tname[MAXDNAME+1]; | ||
228 | register int n, ttype, tclass; | ||
229 | |||
230 | n = dn_expand(buf, eom, cp, tname, sizeof tname); | ||
231 | if (n < 0) | ||
232 | return (-1); | ||
233 | cp += n; | ||
234 | ttype = _getshort(cp); cp += INT16SZ; | ||
235 | tclass = _getshort(cp); cp += INT16SZ; | ||
236 | if (ttype == type && | ||
237 | tclass == class && | ||
238 | strcasecmp(tname, name) == 0) | ||
239 | return (1); | ||
240 | } | ||
241 | return (0); | ||
242 | } | ||
243 | |||
244 | /* int | ||
245 | * res_queriesmatch(buf1, eom1, buf2, eom2) | ||
246 | * is there a 1:1 mapping of (name,type,class) | ||
247 | * in (buf1,eom1) and (buf2,eom2)? | ||
248 | * returns: | ||
249 | * -1 : format error | ||
250 | * 0 : not a 1:1 mapping | ||
251 | * >0 : is a 1:1 mapping | ||
252 | * author: | ||
253 | * paul vixie, 29may94 | ||
254 | */ | ||
255 | int | ||
256 | res_queriesmatch(buf1, eom1, buf2, eom2) | ||
257 | const u_char *buf1, *eom1; | ||
258 | const u_char *buf2, *eom2; | ||
259 | { | ||
260 | register const u_char *cp = buf1 + HFIXEDSZ; | ||
261 | int qdcount = ntohs(((HEADER*)buf1)->qdcount); | ||
262 | |||
263 | if (qdcount != ntohs(((HEADER*)buf2)->qdcount)) | ||
264 | return (0); | ||
265 | while (qdcount-- > 0) { | ||
266 | char tname[MAXDNAME+1]; | ||
267 | register int n, ttype, tclass; | ||
268 | |||
269 | n = dn_expand(buf1, eom1, cp, tname, sizeof tname); | ||
270 | if (n < 0) | ||
271 | return (-1); | ||
272 | cp += n; | ||
273 | ttype = _getshort(cp); cp += INT16SZ; | ||
274 | tclass = _getshort(cp); cp += INT16SZ; | ||
275 | if (!res_nameinquery(tname, ttype, tclass, buf2, eom2)) | ||
276 | return (0); | ||
277 | } | ||
278 | return (1); | ||
279 | } | ||
280 | |||
281 | int | ||
282 | res_send(buf, buflen, ans, anssiz) | ||
283 | const u_char *buf; | ||
96 | int buflen; | 284 | int buflen; |
97 | char *answer; | 285 | u_char *ans; |
98 | int anslen; | 286 | int anssiz; |
99 | { | 287 | { |
100 | register int n; | ||
101 | int try, v_circuit, resplen, ns; | ||
102 | int gotsomewhere = 0, connected = 0; | ||
103 | int connreset = 0; | ||
104 | u_short id, len; | ||
105 | char *cp; | ||
106 | fd_set dsmask; | ||
107 | struct timeval timeout; | ||
108 | HEADER *hp = (HEADER *) buf; | 288 | HEADER *hp = (HEADER *) buf; |
109 | HEADER *anhp = (HEADER *) answer; | 289 | HEADER *anhp = (HEADER *) ans; |
110 | u_int badns; /* XXX NSMAX can't exceed #/bits per this */ | 290 | int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns; |
111 | struct iovec iov[2]; | 291 | register int n; |
112 | int terrno = ETIMEDOUT; | 292 | u_int badns; /* XXX NSMAX can't exceed #/bits in this var */ |
113 | char junk[512]; | 293 | |
114 | 294 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | |
115 | #ifdef DEBUG | 295 | /* errno should have been set by res_init() in this case. */ |
116 | if ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY)) { | 296 | return (-1); |
117 | printf(";; res_send()\n"); | ||
118 | __p_query(buf); | ||
119 | } | 297 | } |
120 | #endif | 298 | DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY), |
121 | if (!(_res.options & RES_INIT)) | 299 | (stdout, ";; res_send()\n"), buf, buflen); |
122 | if (res_init() == -1) { | ||
123 | return(-1); | ||
124 | } | ||
125 | v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ; | 300 | v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ; |
126 | id = hp->id; | 301 | gotsomewhere = 0; |
302 | connreset = 0; | ||
303 | terrno = ETIMEDOUT; | ||
127 | badns = 0; | 304 | badns = 0; |
305 | |||
128 | /* | 306 | /* |
129 | * Send request, RETRY times, or until successful | 307 | * Send request, RETRY times, or until successful |
130 | */ | 308 | */ |
131 | for (try = 0; try < _res.retry; try++) { | 309 | for (try = 0; try < _res.retry; try++) { |
132 | for (ns = 0; ns < _res.nscount; ns++) { | 310 | for (ns = 0; ns < _res.nscount; ns++) { |
133 | if (badns & (1<<ns)) | 311 | struct sockaddr_in *nsap = &_res.nsaddr_list[ns]; |
134 | continue; | 312 | same_ns: |
135 | #ifdef DEBUG | 313 | if (badns & (1 << ns)) { |
136 | if (_res.options & RES_DEBUG) | 314 | res_close(); |
137 | printf(";; Querying server (# %d) address = %s\n", | 315 | goto next_ns; |
138 | ns+1, | 316 | } |
139 | inet_ntoa(_res.nsaddr_list[ns].sin_addr)); | 317 | |
140 | #endif | 318 | if (Qhook) { |
141 | usevc: | 319 | int done = 0, loops = 0; |
320 | |||
321 | do { | ||
322 | res_sendhookact act; | ||
323 | |||
324 | act = (*Qhook)(&nsap, &buf, &buflen, | ||
325 | ans, anssiz, &resplen); | ||
326 | switch (act) { | ||
327 | case res_goahead: | ||
328 | done = 1; | ||
329 | break; | ||
330 | case res_nextns: | ||
331 | res_close(); | ||
332 | goto next_ns; | ||
333 | case res_done: | ||
334 | return (resplen); | ||
335 | case res_modified: | ||
336 | /* give the hook another try */ | ||
337 | if (++loops < 42) /*doug adams*/ | ||
338 | break; | ||
339 | /*FALLTHROUGH*/ | ||
340 | case res_error: | ||
341 | /*FALLTHROUGH*/ | ||
342 | default: | ||
343 | return (-1); | ||
344 | } | ||
345 | } while (!done); | ||
346 | } | ||
347 | |||
348 | Dprint(_res.options & RES_DEBUG, | ||
349 | (stdout, ";; Querying server (# %d) address = %s\n", | ||
350 | ns + 1, inet_ntoa(nsap->sin_addr))); | ||
351 | |||
142 | if (v_circuit) { | 352 | if (v_circuit) { |
143 | int truncated = 0; | 353 | int truncated; |
354 | struct iovec iov[2]; | ||
355 | u_short len; | ||
356 | u_char *cp; | ||
144 | 357 | ||
145 | /* | 358 | /* |
146 | * Use virtual circuit; | 359 | * Use virtual circuit; |
147 | * at most one attempt per server. | 360 | * at most one attempt per server. |
148 | */ | 361 | */ |
149 | try = _res.retry; | 362 | try = _res.retry; |
150 | if (s < 0) { | 363 | truncated = 0; |
151 | s = socket(AF_INET, SOCK_STREAM, 0); | 364 | if ((s < 0) || (!vc)) { |
365 | if (s >= 0) | ||
366 | res_close(); | ||
367 | |||
368 | s = socket(PF_INET, SOCK_STREAM, 0); | ||
152 | if (s < 0) { | 369 | if (s < 0) { |
153 | terrno = errno; | 370 | terrno = errno; |
154 | #ifdef DEBUG | 371 | Perror(stderr, "socket(vc)", errno); |
155 | if (_res.options & RES_DEBUG) | 372 | return (-1); |
156 | perror("socket (vc) failed"); | ||
157 | #endif | ||
158 | continue; | ||
159 | } | 373 | } |
160 | if (connect(s, | 374 | errno = 0; |
161 | (struct sockaddr *)&(_res.nsaddr_list[ns]), | 375 | if (connect(s, (struct sockaddr *)nsap, |
162 | sizeof(struct sockaddr)) < 0) { | 376 | sizeof(struct sockaddr)) < 0) { |
163 | terrno = errno; | 377 | terrno = errno; |
164 | #ifdef DEBUG | 378 | Aerror(stderr, "connect/vc", |
165 | if (_res.options & RES_DEBUG) | 379 | errno, *nsap); |
166 | perror("connect failed"); | 380 | badns |= (1 << ns); |
167 | #endif | 381 | res_close(); |
168 | (void) close(s); | 382 | goto next_ns; |
169 | s = -1; | ||
170 | continue; | ||
171 | } | 383 | } |
384 | vc = 1; | ||
172 | } | 385 | } |
173 | /* | 386 | /* |
174 | * Send length & message | 387 | * Send length & message |
175 | */ | 388 | */ |
176 | len = htons((u_short)buflen); | 389 | putshort((u_short)buflen, (u_char*)&len); |
177 | iov[0].iov_base = (caddr_t)&len; | 390 | iov[0].iov_base = (caddr_t)&len; |
178 | iov[0].iov_len = sizeof(len); | 391 | iov[0].iov_len = INT16SZ; |
179 | iov[1].iov_base = (char *)buf; | 392 | iov[1].iov_base = (caddr_t)buf; |
180 | iov[1].iov_len = buflen; | 393 | iov[1].iov_len = buflen; |
181 | if (writev(s, iov, 2) != sizeof(len) + buflen) { | 394 | if (writev(s, iov, 2) != (INT16SZ + buflen)) { |
182 | terrno = errno; | 395 | terrno = errno; |
183 | #ifdef DEBUG | 396 | Perror(stderr, "write failed", errno); |
184 | if (_res.options & RES_DEBUG) | 397 | badns |= (1 << ns); |
185 | perror("write failed"); | 398 | res_close(); |
186 | #endif | 399 | goto next_ns; |
187 | (void) close(s); | ||
188 | s = -1; | ||
189 | continue; | ||
190 | } | 400 | } |
191 | /* | 401 | /* |
192 | * Receive length & response | 402 | * Receive length & response |
193 | */ | 403 | */ |
194 | cp = answer; | 404 | read_len: |
195 | len = sizeof(short); | 405 | cp = ans; |
196 | while (len != 0 && | 406 | len = INT16SZ; |
197 | (n = read(s, (char *)cp, (int)len)) > 0) { | 407 | while ((n = read(s, (char *)cp, (int)len)) > 0) { |
198 | cp += n; | 408 | cp += n; |
199 | len -= n; | 409 | if ((len -= n) <= 0) |
410 | break; | ||
200 | } | 411 | } |
201 | if (n <= 0) { | 412 | if (n <= 0) { |
202 | terrno = errno; | 413 | terrno = errno; |
203 | #ifdef DEBUG | 414 | Perror(stderr, "read failed", errno); |
204 | if (_res.options & RES_DEBUG) | 415 | res_close(); |
205 | perror("read failed"); | ||
206 | #endif | ||
207 | (void) close(s); | ||
208 | s = -1; | ||
209 | /* | 416 | /* |
210 | * A long running process might get its TCP | 417 | * A long running process might get its TCP |
211 | * connection reset if the remote server was | 418 | * connection reset if the remote server was |
@@ -217,35 +424,32 @@ res_send(buf, buflen, answer, anslen) | |||
217 | */ | 424 | */ |
218 | if (terrno == ECONNRESET && !connreset) { | 425 | if (terrno == ECONNRESET && !connreset) { |
219 | connreset = 1; | 426 | connreset = 1; |
220 | ns--; | 427 | res_close(); |
428 | goto same_ns; | ||
221 | } | 429 | } |
222 | continue; | 430 | res_close(); |
431 | goto next_ns; | ||
223 | } | 432 | } |
224 | cp = answer; | 433 | resplen = _getshort(ans); |
225 | if ((resplen = ntohs(*(u_short *)cp)) > anslen) { | 434 | if (resplen > anssiz) { |
226 | #ifdef DEBUG | 435 | Dprint(_res.options & RES_DEBUG, |
227 | if (_res.options & RES_DEBUG) | 436 | (stdout, ";; response truncated\n") |
228 | fprintf(stderr, | 437 | ); |
229 | ";; response truncated\n"); | ||
230 | #endif | ||
231 | len = anslen; | ||
232 | truncated = 1; | 438 | truncated = 1; |
439 | len = anssiz; | ||
233 | } else | 440 | } else |
234 | len = resplen; | 441 | len = resplen; |
442 | cp = ans; | ||
235 | while (len != 0 && | 443 | while (len != 0 && |
236 | (n = read(s, (char *)cp, (int)len)) > 0) { | 444 | (n = read(s, (char *)cp, (int)len)) > 0) { |
237 | cp += n; | 445 | cp += n; |
238 | len -= n; | 446 | len -= n; |
239 | } | 447 | } |
240 | if (n <= 0) { | 448 | if (n <= 0) { |
241 | terrno = errno; | 449 | terrno = errno; |
242 | #ifdef DEBUG | 450 | Perror(stderr, "read(vc)", errno); |
243 | if (_res.options & RES_DEBUG) | 451 | res_close(); |
244 | perror("read failed"); | 452 | goto next_ns; |
245 | #endif | ||
246 | (void) close(s); | ||
247 | s = -1; | ||
248 | continue; | ||
249 | } | 453 | } |
250 | if (truncated) { | 454 | if (truncated) { |
251 | /* | 455 | /* |
@@ -253,33 +457,57 @@ res_send(buf, buflen, answer, anslen) | |||
253 | * so connection stays in synch. | 457 | * so connection stays in synch. |
254 | */ | 458 | */ |
255 | anhp->tc = 1; | 459 | anhp->tc = 1; |
256 | len = resplen - anslen; | 460 | len = resplen - anssiz; |
257 | while (len != 0) { | 461 | while (len != 0) { |
258 | n = (len > sizeof(junk) ? | 462 | char junk[PACKETSZ]; |
259 | sizeof(junk) : len); | 463 | |
464 | n = (len > sizeof(junk) | ||
465 | ? sizeof(junk) | ||
466 | : len); | ||
260 | if ((n = read(s, junk, n)) > 0) | 467 | if ((n = read(s, junk, n)) > 0) |
261 | len -= n; | 468 | len -= n; |
262 | else | 469 | else |
263 | break; | 470 | break; |
264 | } | 471 | } |
265 | } | 472 | } |
473 | /* | ||
474 | * The calling applicating has bailed out of | ||
475 | * a previous call and failed to arrange to have | ||
476 | * the circuit closed or the server has got | ||
477 | * itself confused. Anyway drop the packet and | ||
478 | * wait for the correct one. | ||
479 | */ | ||
480 | if (hp->id != anhp->id) { | ||
481 | DprintQ((_res.options & RES_DEBUG) || | ||
482 | (_res.pfcode & RES_PRF_REPLY), | ||
483 | (stdout, ";; old answer (unexpected):\n"), | ||
484 | ans, (resplen>anssiz)?anssiz:resplen); | ||
485 | goto read_len; | ||
486 | } | ||
266 | } else { | 487 | } else { |
267 | /* | 488 | /* |
268 | * Use datagrams. | 489 | * Use datagrams. |
269 | */ | 490 | */ |
270 | if (s < 0) { | 491 | struct timeval timeout; |
271 | s = socket(AF_INET, SOCK_DGRAM, 0); | 492 | fd_set *dsmaskp; |
493 | struct sockaddr_in from; | ||
494 | int fromlen; | ||
495 | |||
496 | if ((s < 0) || vc) { | ||
497 | if (vc) | ||
498 | res_close(); | ||
499 | s = socket(PF_INET, SOCK_DGRAM, 0); | ||
272 | if (s < 0) { | 500 | if (s < 0) { |
273 | terrno = errno; | 501 | #if !CAN_RECONNECT |
274 | #ifdef DEBUG | 502 | bad_dg_sock: |
275 | if (_res.options & RES_DEBUG) | ||
276 | perror("socket (dg) failed"); | ||
277 | #endif | 503 | #endif |
278 | continue; | 504 | terrno = errno; |
505 | Perror(stderr, "socket(dg)", errno); | ||
506 | return (-1); | ||
279 | } | 507 | } |
508 | connected = 0; | ||
280 | } | 509 | } |
281 | /* | 510 | /* |
282 | * I'm tired of answering this question, so: | ||
283 | * On a 4.3BSD+ machine (client and server, | 511 | * On a 4.3BSD+ machine (client and server, |
284 | * actually), sending to a nameserver datagram | 512 | * actually), sending to a nameserver datagram |
285 | * port with no nameserver will cause an | 513 | * port with no nameserver will cause an |
@@ -296,29 +524,27 @@ res_send(buf, buflen, answer, anslen) | |||
296 | */ | 524 | */ |
297 | if (_res.nscount == 1 || (try == 0 && ns == 0)) { | 525 | if (_res.nscount == 1 || (try == 0 && ns == 0)) { |
298 | /* | 526 | /* |
299 | * Don't use connect if we might | 527 | * Connect only if we are sure we won't |
300 | * still receive a response | 528 | * receive a response from another server. |
301 | * from another server. | ||
302 | */ | 529 | */ |
303 | if (connected == 0) { | 530 | if (!connected) { |
304 | if (connect(s, | 531 | if (connect(s, (struct sockaddr *)nsap, |
305 | (struct sockaddr *) | 532 | sizeof(struct sockaddr) |
306 | &_res.nsaddr_list[ns], | 533 | ) < 0) { |
307 | sizeof(struct sockaddr)) < 0) { | 534 | Aerror(stderr, |
308 | #ifdef DEBUG | 535 | "connect(dg)", |
309 | if (_res.options & RES_DEBUG) | 536 | errno, *nsap); |
310 | perror("connect"); | 537 | badns |= (1 << ns); |
311 | #endif | 538 | res_close(); |
312 | continue; | 539 | goto next_ns; |
313 | } | 540 | } |
314 | connected = 1; | 541 | connected = 1; |
315 | } | 542 | } |
316 | if (send(s, buf, buflen, 0) != buflen) { | 543 | if (send(s, (char*)buf, buflen, 0) != buflen) { |
317 | #ifdef DEBUG | 544 | Perror(stderr, "send", errno); |
318 | if (_res.options & RES_DEBUG) | 545 | badns |= (1 << ns); |
319 | perror("send"); | 546 | res_close(); |
320 | #endif | 547 | goto next_ns; |
321 | continue; | ||
322 | } | 548 | } |
323 | } else { | 549 | } else { |
324 | /* | 550 | /* |
@@ -326,18 +552,36 @@ res_send(buf, buflen, answer, anslen) | |||
326 | * for responses from more than one server. | 552 | * for responses from more than one server. |
327 | */ | 553 | */ |
328 | if (connected) { | 554 | if (connected) { |
329 | (void) connect(s, &no_addr, | 555 | #if CAN_RECONNECT |
330 | sizeof(no_addr)); | 556 | struct sockaddr_in no_addr; |
557 | |||
558 | no_addr.sin_family = AF_INET; | ||
559 | no_addr.sin_addr.s_addr = INADDR_ANY; | ||
560 | no_addr.sin_port = 0; | ||
561 | (void) connect(s, | ||
562 | (struct sockaddr *) | ||
563 | &no_addr, | ||
564 | sizeof(no_addr)); | ||
565 | #else | ||
566 | int s1 = socket(PF_INET, SOCK_DGRAM,0); | ||
567 | if (s1 < 0) | ||
568 | goto bad_dg_sock; | ||
569 | (void) dup2(s1, s); | ||
570 | (void) close(s1); | ||
571 | Dprint(_res.options & RES_DEBUG, | ||
572 | (stdout, ";; new DG socket\n")) | ||
573 | #endif | ||
331 | connected = 0; | 574 | connected = 0; |
575 | errno = 0; | ||
332 | } | 576 | } |
333 | if (sendto(s, buf, buflen, 0, | 577 | if (sendto(s, (char*)buf, buflen, 0, |
334 | (struct sockaddr *)&_res.nsaddr_list[ns], | 578 | (struct sockaddr *)nsap, |
335 | sizeof(struct sockaddr)) != buflen) { | 579 | sizeof(struct sockaddr)) |
336 | #ifdef DEBUG | 580 | != buflen) { |
337 | if (_res.options & RES_DEBUG) | 581 | Aerror(stderr, "sendto", errno, *nsap); |
338 | perror("sendto"); | 582 | badns |= (1 << ns); |
339 | #endif | 583 | res_close(); |
340 | continue; | 584 | goto next_ns; |
341 | } | 585 | } |
342 | } | 586 | } |
343 | 587 | ||
@@ -350,110 +594,169 @@ res_send(buf, buflen, answer, anslen) | |||
350 | if ((long) timeout.tv_sec <= 0) | 594 | if ((long) timeout.tv_sec <= 0) |
351 | timeout.tv_sec = 1; | 595 | timeout.tv_sec = 1; |
352 | timeout.tv_usec = 0; | 596 | timeout.tv_usec = 0; |
353 | wait: | 597 | wait: |
354 | FD_ZERO(&dsmask); | 598 | dsmaskp = (fd_set *)calloc(howmany(s+1, NFDBITS), |
355 | FD_SET(s, &dsmask); | 599 | sizeof(fd_mask)); |
356 | n = select(s+1, &dsmask, (fd_set *)NULL, | 600 | if (dsmaskp == NULL) { |
357 | (fd_set *)NULL, &timeout); | 601 | res_close(); |
602 | goto next_ns; | ||
603 | } | ||
604 | FD_SET(s, dsmaskp); | ||
605 | n = select(s+1, dsmaskp, (fd_set *)NULL, | ||
606 | (fd_set *)NULL, &timeout); | ||
607 | free(dsmaskp); | ||
358 | if (n < 0) { | 608 | if (n < 0) { |
359 | #ifdef DEBUG | 609 | if (errno == EINTR) |
360 | if (_res.options & RES_DEBUG) | 610 | goto wait; |
361 | perror("select"); | 611 | Perror(stderr, "select", errno); |
362 | #endif | 612 | res_close(); |
363 | continue; | 613 | goto next_ns; |
364 | } | 614 | } |
365 | if (n == 0) { | 615 | if (n == 0) { |
366 | /* | 616 | /* |
367 | * timeout | 617 | * timeout |
368 | */ | 618 | */ |
369 | #ifdef DEBUG | 619 | Dprint(_res.options & RES_DEBUG, |
370 | if (_res.options & RES_DEBUG) | 620 | (stdout, ";; timeout\n")); |
371 | printf(";; timeout\n"); | ||
372 | #endif | ||
373 | gotsomewhere = 1; | 621 | gotsomewhere = 1; |
374 | continue; | 622 | res_close(); |
623 | goto next_ns; | ||
375 | } | 624 | } |
376 | if ((resplen = recv(s, answer, anslen, 0)) <= 0) { | 625 | errno = 0; |
377 | #ifdef DEBUG | 626 | fromlen = sizeof(struct sockaddr_in); |
378 | if (_res.options & RES_DEBUG) | 627 | resplen = recvfrom(s, (char*)ans, anssiz, 0, |
379 | perror("recvfrom"); | 628 | (struct sockaddr *)&from, &fromlen); |
380 | #endif | 629 | if (resplen <= 0) { |
381 | continue; | 630 | Perror(stderr, "recvfrom", errno); |
631 | res_close(); | ||
632 | goto next_ns; | ||
382 | } | 633 | } |
383 | gotsomewhere = 1; | 634 | gotsomewhere = 1; |
384 | if (id != anhp->id) { | 635 | if (hp->id != anhp->id) { |
385 | /* | 636 | /* |
386 | * response from old query, ignore it | 637 | * response from old query, ignore it. |
638 | * XXX - potential security hazard could | ||
639 | * be detected here. | ||
387 | */ | 640 | */ |
388 | #ifdef DEBUG | 641 | DprintQ((_res.options & RES_DEBUG) || |
389 | if ((_res.options & RES_DEBUG) || | 642 | (_res.pfcode & RES_PRF_REPLY), |
390 | (_res.pfcode & RES_PRF_REPLY)) { | 643 | (stdout, ";; old answer:\n"), |
391 | printf(";; old answer:\n"); | 644 | ans, (resplen>anssiz)?anssiz:resplen); |
392 | __p_query(answer); | 645 | goto wait; |
393 | } | 646 | } |
647 | #if CHECK_SRVR_ADDR | ||
648 | if (!(_res.options & RES_INSECURE1) && | ||
649 | !res_isourserver(&from)) { | ||
650 | /* | ||
651 | * response from wrong server? ignore it. | ||
652 | * XXX - potential security hazard could | ||
653 | * be detected here. | ||
654 | */ | ||
655 | DprintQ((_res.options & RES_DEBUG) || | ||
656 | (_res.pfcode & RES_PRF_REPLY), | ||
657 | (stdout, ";; not our server:\n"), | ||
658 | ans, (resplen>anssiz)?anssiz:resplen); | ||
659 | goto wait; | ||
660 | } | ||
394 | #endif | 661 | #endif |
662 | if (!(_res.options & RES_INSECURE2) && | ||
663 | !res_queriesmatch(buf, buf + buflen, | ||
664 | ans, ans + anssiz)) { | ||
665 | /* | ||
666 | * response contains wrong query? ignore it. | ||
667 | * XXX - potential security hazard could | ||
668 | * be detected here. | ||
669 | */ | ||
670 | DprintQ((_res.options & RES_DEBUG) || | ||
671 | (_res.pfcode & RES_PRF_REPLY), | ||
672 | (stdout, ";; wrong query name:\n"), | ||
673 | ans, (resplen>anssiz)?anssiz:resplen); | ||
395 | goto wait; | 674 | goto wait; |
396 | } | 675 | } |
397 | if (anhp->rcode == SERVFAIL || anhp->rcode == NOTIMP || | 676 | if (anhp->rcode == SERVFAIL || |
677 | anhp->rcode == NOTIMP || | ||
398 | anhp->rcode == REFUSED) { | 678 | anhp->rcode == REFUSED) { |
399 | #ifdef DEBUG | 679 | DprintQ(_res.options & RES_DEBUG, |
400 | if (_res.options & RES_DEBUG) { | 680 | (stdout, "server rejected query:\n"), |
401 | printf("server rejected query:\n"); | 681 | ans, (resplen>anssiz)?anssiz:resplen); |
402 | __p_query(answer); | 682 | badns |= (1 << ns); |
403 | } | 683 | res_close(); |
404 | #endif | 684 | /* don't retry if called from dig */ |
405 | badns |= (1<<ns); | 685 | if (!_res.pfcode) |
406 | continue; | 686 | goto next_ns; |
407 | } | 687 | } |
408 | if (!(_res.options & RES_IGNTC) && anhp->tc) { | 688 | if (!(_res.options & RES_IGNTC) && anhp->tc) { |
409 | /* | 689 | /* |
410 | * get rest of answer; | 690 | * get rest of answer; |
411 | * use TCP with same server. | 691 | * use TCP with same server. |
412 | */ | 692 | */ |
413 | #ifdef DEBUG | 693 | Dprint(_res.options & RES_DEBUG, |
414 | if (_res.options & RES_DEBUG) | 694 | (stdout, ";; truncated answer\n")); |
415 | printf(";; truncated answer\n"); | ||
416 | #endif | ||
417 | (void) close(s); | ||
418 | s = -1; | ||
419 | v_circuit = 1; | 695 | v_circuit = 1; |
420 | goto usevc; | 696 | res_close(); |
697 | goto same_ns; | ||
421 | } | 698 | } |
422 | } | 699 | } /*if vc/dg*/ |
423 | #ifdef DEBUG | 700 | Dprint((_res.options & RES_DEBUG) || |
424 | if (_res.options & RES_DEBUG) | 701 | ((_res.pfcode & RES_PRF_REPLY) && |
425 | printf(";; got answer:\n"); | 702 | (_res.pfcode & RES_PRF_HEAD1)), |
426 | if ((_res.options & RES_DEBUG) || | 703 | (stdout, ";; got answer:\n")); |
427 | (_res.pfcode & RES_PRF_REPLY)) | 704 | DprintQ((_res.options & RES_DEBUG) || |
428 | __p_query(answer); | 705 | (_res.pfcode & RES_PRF_REPLY), |
429 | #endif | 706 | (stdout, ""), |
707 | ans, (resplen>anssiz)?anssiz:resplen); | ||
430 | /* | 708 | /* |
431 | * If using virtual circuits, we assume that the first server | 709 | * If using virtual circuits, we assume that the first server |
432 | * is preferred * over the rest (i.e. it is on the local | 710 | * is preferred over the rest (i.e. it is on the local |
433 | * machine) and only keep that one open. | 711 | * machine) and only keep that one open. |
434 | * If we have temporarily opened a virtual circuit, | 712 | * If we have temporarily opened a virtual circuit, |
435 | * or if we haven't been asked to keep a socket open, | 713 | * or if we haven't been asked to keep a socket open, |
436 | * close the socket. | 714 | * close the socket. |
437 | */ | 715 | */ |
438 | if ((v_circuit && | 716 | if ((v_circuit && (!(_res.options & RES_USEVC) || ns != 0)) || |
439 | ((_res.options & RES_USEVC) == 0 || ns != 0)) || | 717 | !(_res.options & RES_STAYOPEN)) { |
440 | (_res.options & RES_STAYOPEN) == 0) { | 718 | res_close(); |
441 | (void) close(s); | 719 | } |
442 | s = -1; | 720 | if (Rhook) { |
721 | int done = 0, loops = 0; | ||
722 | |||
723 | do { | ||
724 | res_sendhookact act; | ||
725 | |||
726 | act = (*Rhook)(nsap, buf, buflen, | ||
727 | ans, anssiz, &resplen); | ||
728 | switch (act) { | ||
729 | case res_goahead: | ||
730 | case res_done: | ||
731 | done = 1; | ||
732 | break; | ||
733 | case res_nextns: | ||
734 | res_close(); | ||
735 | goto next_ns; | ||
736 | case res_modified: | ||
737 | /* give the hook another try */ | ||
738 | if (++loops < 42) /*doug adams*/ | ||
739 | break; | ||
740 | /*FALLTHROUGH*/ | ||
741 | case res_error: | ||
742 | /*FALLTHROUGH*/ | ||
743 | default: | ||
744 | return (-1); | ||
745 | } | ||
746 | } while (!done); | ||
747 | |||
443 | } | 748 | } |
444 | return (resplen); | 749 | return (resplen); |
445 | } | 750 | next_ns: ; |
446 | } | 751 | } /*foreach ns*/ |
447 | if (s >= 0) { | 752 | } /*foreach retry*/ |
448 | (void) close(s); | 753 | res_close(); |
449 | s = -1; | 754 | if (!v_circuit) { |
450 | } | 755 | if (!gotsomewhere) |
451 | if (v_circuit == 0) | ||
452 | if (gotsomewhere == 0) | ||
453 | errno = ECONNREFUSED; /* no nameservers found */ | 756 | errno = ECONNREFUSED; /* no nameservers found */ |
454 | else | 757 | else |
455 | errno = ETIMEDOUT; /* no answer obtained */ | 758 | errno = ETIMEDOUT; /* no answer obtained */ |
456 | else | 759 | } else |
457 | errno = terrno; | 760 | errno = terrno; |
458 | return (-1); | 761 | return (-1); |
459 | } | 762 | } |
@@ -465,10 +768,13 @@ wait: | |||
465 | * | 768 | * |
466 | * This routine is not expected to be user visible. | 769 | * This routine is not expected to be user visible. |
467 | */ | 770 | */ |
468 | _res_close() | 771 | void |
772 | res_close() | ||
469 | { | 773 | { |
470 | if (s != -1) { | 774 | if (s >= 0) { |
471 | (void) close(s); | 775 | (void) close(s); |
472 | s = -1; | 776 | s = -1; |
777 | connected = 0; | ||
778 | vc = 0; | ||
473 | } | 779 | } |
474 | } | 780 | } |
diff --git a/src/lib/libc/net/resolver.3 b/src/lib/libc/net/resolver.3 index 99abe17f03..98718d448a 100644 --- a/src/lib/libc/net/resolver.3 +++ b/src/lib/libc/net/resolver.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $NetBSD: resolver.3,v 1.5 1995/02/25 06:21:02 cgd Exp $ | 1 | .\" $OpenBSD: resolver.3,v 1.5 1998/09/05 17:41:44 deraadt Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1985, 1991, 1993 | 3 | .\" Copyright (c) 1985, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -31,8 +31,6 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" @(#)resolver.3 8.1 (Berkeley) 6/4/93 | ||
35 | .\" | ||
36 | .Dd June 4, 1993 | 34 | .Dd June 4, 1993 |
37 | .Dt RESOLVER 3 | 35 | .Dt RESOLVER 3 |
38 | .Os BSD 4.3 | 36 | .Os BSD 4.3 |
@@ -112,7 +110,7 @@ are defined in | |||
112 | and are as follows. | 110 | and are as follows. |
113 | Options are stored as a simple bit mask containing the bitwise ``or'' | 111 | Options are stored as a simple bit mask containing the bitwise ``or'' |
114 | of the options enabled. | 112 | of the options enabled. |
115 | .Bl -tag -width RES_DEFNAMES | 113 | .Bl -tag -width RES_USE_INET6 |
116 | .It Dv RES_INIT | 114 | .It Dv RES_INIT |
117 | True if the initial name server address and default domain name are | 115 | True if the initial name server address and default domain name are |
118 | initialized (i.e., | 116 | initialized (i.e., |
@@ -165,6 +163,8 @@ will search for host names in the current domain and in parent domains; see | |||
165 | This is used by the standard host lookup routine | 163 | This is used by the standard host lookup routine |
166 | .Xr gethostbyname 3 . | 164 | .Xr gethostbyname 3 . |
167 | This option is enabled by default. | 165 | This option is enabled by default. |
166 | .It Dv RES_USE_INET6 | ||
167 | Enable support for IPv6 addresses. | ||
168 | .El | 168 | .El |
169 | .Pp | 169 | .Pp |
170 | The | 170 | The |
@@ -282,7 +282,7 @@ The compression uses | |||
282 | an array of pointers | 282 | an array of pointers |
283 | .Fa dnptrs | 283 | .Fa dnptrs |
284 | to previously-compressed names in the current message. | 284 | to previously-compressed names in the current message. |
285 | The first pointer points to | 285 | The first pointer points |
286 | to the beginning of the message and the list ends with | 286 | to the beginning of the message and the list ends with |
287 | .Dv NULL . | 287 | .Dv NULL . |
288 | The limit to the array is specified by | 288 | The limit to the array is specified by |
@@ -333,6 +333,7 @@ see | |||
333 | .%T RFC1033 , | 333 | .%T RFC1033 , |
334 | .%T RFC1034 , | 334 | .%T RFC1034 , |
335 | .%T RFC1035 , | 335 | .%T RFC1035 , |
336 | .%T RFC1535 , | ||
336 | .%T RFC974 | 337 | .%T RFC974 |
337 | .Rs | 338 | .Rs |
338 | .%T "Name Server Operations Guide for BIND" | 339 | .%T "Name Server Operations Guide for BIND" |
diff --git a/src/lib/libc/net/send.c b/src/lib/libc/net/send.c index 88f3550ec6..8495931ca3 100644 --- a/src/lib/libc/net/send.c +++ b/src/lib/libc/net/send.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: send.c,v 1.6 1995/02/25 06:21:02 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1988, 1993 | 2 | * Copyright (c) 1988, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: send.c,v 1.2 1996/08/19 08:29:52 tholo Exp $"; |
38 | static char sccsid[] = "@(#)send.c 8.2 (Berkeley) 2/21/94"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: send.c,v 1.6 1995/02/25 06:21:02 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/types.h> | 38 | #include <sys/types.h> |
diff --git a/src/lib/libc/net/sethostent.c b/src/lib/libc/net/sethostent.c index 00f6499695..5392a2f11b 100644 --- a/src/lib/libc/net/sethostent.c +++ b/src/lib/libc/net/sethostent.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: sethostent.c,v 1.4 1995/02/25 06:21:03 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1985, 1993 | 2 | * Copyright (c) 1985, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: sethostent.c,v 1.4 1997/03/15 21:53:50 pefo Exp $"; |
38 | static char sccsid[] = "@(#)sethostent.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: sethostent.c,v 1.4 1995/02/25 06:21:03 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/param.h> | 38 | #include <sys/param.h> |
@@ -49,7 +43,11 @@ static char rcsid[] = "$NetBSD: sethostent.c,v 1.4 1995/02/25 06:21:03 cgd Exp $ | |||
49 | 43 | ||
50 | void | 44 | void |
51 | sethostent(stayopen) | 45 | sethostent(stayopen) |
46 | int stayopen; | ||
52 | { | 47 | { |
48 | |||
49 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | ||
50 | return; | ||
53 | if (stayopen) | 51 | if (stayopen) |
54 | _res.options |= RES_STAYOPEN | RES_USEVC; | 52 | _res.options |= RES_STAYOPEN | RES_USEVC; |
55 | } | 53 | } |
@@ -58,5 +56,5 @@ void | |||
58 | endhostent() | 56 | endhostent() |
59 | { | 57 | { |
60 | _res.options &= ~(RES_STAYOPEN | RES_USEVC); | 58 | _res.options &= ~(RES_STAYOPEN | RES_USEVC); |
61 | _res_close(); | 59 | res_close(); |
62 | } | 60 | } |
diff --git a/src/lib/libc/stdlib/Makefile.inc b/src/lib/libc/stdlib/Makefile.inc index 782a4ab022..e75fc0d8bf 100644 --- a/src/lib/libc/stdlib/Makefile.inc +++ b/src/lib/libc/stdlib/Makefile.inc | |||
@@ -1,24 +1,28 @@ | |||
1 | # from: @(#)Makefile.inc 5.6 (Berkeley) 6/4/91 | 1 | # $OpenBDS: Makefile.inc,v 1.6 1996/08/21 03:47:21 tholo Exp $ |
2 | # $Id: Makefile.inc,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $ | ||
3 | 2 | ||
4 | # stdlib sources | 3 | # stdlib sources |
5 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/stdlib ${.CURDIR}/stdlib | 4 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/stdlib ${.CURDIR}/stdlib |
6 | 5 | ||
7 | SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c bsearch.c calloc.c \ | 6 | SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c bsearch.c calloc.c \ |
8 | exit.c getenv.c getopt.c heapsort.c l64a.c malloc.c merge.c \ | 7 | cfree.c exit.c getenv.c getopt.c getsubopt.c heapsort.c l64a.c \ |
9 | multibyte.c putenv.c qsort.c radixsort.c rand.c random.c realpath.c \ | 8 | malloc.c merge.c multibyte.c putenv.c qsort.c radixsort.c rand.c \ |
10 | setenv.c strtod.c strtol.c strtoq.c strtoul.c strtouq.c system.c \ | 9 | random.c realpath.c setenv.c strtod.c strtol.c strtoq.c strtoul.c \ |
10 | strtouq.c system.c tfind.c tsearch.c \ | ||
11 | _rand48.c drand48.c erand48.c jrand48.c lcong48.c lrand48.c \ | 11 | _rand48.c drand48.c erand48.c jrand48.c lcong48.c lrand48.c \ |
12 | mrand48.c nrand48.c seed48.c srand48.c qabs.c qdiv.c | 12 | mrand48.c nrand48.c seed48.c srand48.c qabs.c qdiv.c |
13 | 13 | ||
14 | .if (${MACHINE_ARCH} == "m68k") | 14 | .if (${MACHINE_ARCH} == "m68k") |
15 | SRCS+= abs.S div.c labs.c ldiv.c | 15 | SRCS+= abs.S div.c labs.c ldiv.c |
16 | LSRCS+= abs.c | ||
16 | .elif (${MACHINE_ARCH} == "i386") | 17 | .elif (${MACHINE_ARCH} == "i386") |
17 | SRCS+= abs.S div.S labs.S ldiv.S | 18 | SRCS+= abs.S div.S labs.S ldiv.S |
19 | LSRCS+= abs.c div.c labs.c ldiv.c | ||
18 | .elif (${MACHINE_ARCH} == "ns32k") | 20 | .elif (${MACHINE_ARCH} == "ns32k") |
19 | SRCS+= abs.S div.c labs.c ldiv.c | 21 | SRCS+= abs.S div.c labs.c ldiv.c |
22 | LSRCS+= abs.c | ||
20 | .elif (${MACHINE_ARCH} == "tahoe") | 23 | .elif (${MACHINE_ARCH} == "tahoe") |
21 | SRCS+= abs.S div.c labs.c ldiv.c | 24 | SRCS+= abs.S div.c labs.c ldiv.c |
25 | LSRCS+= abs.c | ||
22 | .elif (${MACHINE_ARCH} == "vax") | 26 | .elif (${MACHINE_ARCH} == "vax") |
23 | SRCS+= abs.c div.c labs.c ldiv.c | 27 | SRCS+= abs.c div.c labs.c ldiv.c |
24 | .elif (${MACHINE_ARCH} == "alpha") | 28 | .elif (${MACHINE_ARCH} == "alpha") |
@@ -28,18 +32,23 @@ SRCS+= abs.c div.c labs.c ldiv.c | |||
28 | SRCS+= abs.c div.c labs.c ldiv.c | 32 | SRCS+= abs.c div.c labs.c ldiv.c |
29 | .endif | 33 | .endif |
30 | 34 | ||
31 | MAN+= abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ | 35 | MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ |
32 | calloc.3 div.3 exit.3 free.3 getenv.3 getopt.3 labs.3 ldiv.3 \ | 36 | calloc.3 div.3 exit.3 getenv.3 getopt.3 getsubopt.3 labs.3 ldiv.3 \ |
33 | malloc.3 memory.3 qabs.3 qdiv.3 qsort.3 radixsort.3 rand48.3 \ | 37 | malloc.3 memory.3 qabs.3 qdiv.3 qsort.3 radixsort.3 rand48.3 rand.3 \ |
34 | rand.3 random.3 realloc.3 realpath.3 strtod.3 strtol.3 strtoul.3 \ | 38 | random.3 realpath.3 strtod.3 strtol.3 strtoul.3 system.3 tsearch.3 |
35 | system.3 | ||
36 | 39 | ||
37 | MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3 | 40 | MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3 |
41 | MLINKS+=malloc.3 free.3 malloc.3 realloc.3 | ||
42 | MLINKS+=malloc.3 cfree.3 | ||
38 | MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 | 43 | MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 |
39 | MLINKS+=rand.3 srand.3 | 44 | MLINKS+=rand.3 srand.3 |
40 | MLINKS+=strtol.3 strtoq.3 | ||
41 | MLINKS+=strtoul.3 strtouq.3 | ||
42 | MLINKS+=random.3 initstate.3 random.3 setstate.3 random.3 srandom.3 | 45 | MLINKS+=random.3 initstate.3 random.3 setstate.3 random.3 srandom.3 |
43 | MLINKS+=rand48.3 drand48.3 rand48.3 erand48.3 rand48.3 lrand48.3 | 46 | MLINKS+=rand48.3 drand48.3 rand48.3 erand48.3 rand48.3 lrand48.3 |
44 | MLINKS+=rand48.3 mrand48.3 rand48.3 nrand48.3 rand48.3 jrand48.3 | 47 | MLINKS+=rand48.3 mrand48.3 rand48.3 nrand48.3 rand48.3 jrand48.3 |
45 | MLINKS+=rand48.3 srand48.3 rand48.3 seed48.3 rand48.3 lcong48.3 | 48 | MLINKS+=rand48.3 srand48.3 rand48.3 seed48.3 rand48.3 lcong48.3 |
49 | MLINKS+=strtol.3 strtoq.3 | ||
50 | MLINKS+=strtoul.3 strtouq.3 | ||
51 | MLINKS+=tsearch.3 tfind.3 | ||
52 | MLINKS+=tsearch.3 tdelete.3 | ||
53 | MLINKS+=tsearch.3 twalk.3 | ||
54 | MLINKS+=a64l.3 l64a.3 | ||
diff --git a/src/lib/libc/stdlib/_rand48.c b/src/lib/libc/stdlib/_rand48.c index 83ade4645a..fed7372f68 100644 --- a/src/lib/libc/stdlib/_rand48.c +++ b/src/lib/libc/stdlib/_rand48.c | |||
@@ -11,6 +11,10 @@ | |||
11 | * to anyone/anything when using this software. | 11 | * to anyone/anything when using this software. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #if defined(LIBC_SCCS) && !defined(lint) | ||
15 | static char rcsid[] = "$OpenBSD: _rand48.c,v 1.2 1996/08/19 08:33:19 tholo Exp $"; | ||
16 | #endif /* LIBC_SCCS and not lint */ | ||
17 | |||
14 | #include "rand48.h" | 18 | #include "rand48.h" |
15 | 19 | ||
16 | unsigned short __rand48_seed[3] = { | 20 | unsigned short __rand48_seed[3] = { |
diff --git a/src/lib/libc/stdlib/a64l.3 b/src/lib/libc/stdlib/a64l.3 new file mode 100644 index 0000000000..4ec707adf1 --- /dev/null +++ b/src/lib/libc/stdlib/a64l.3 | |||
@@ -0,0 +1,122 @@ | |||
1 | .\" | ||
2 | .\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> | ||
3 | .\" All rights reserved. | ||
4 | .\" | ||
5 | .\" Redistribution and use in source and binary forms, with or without | ||
6 | .\" modification, are permitted provided that the following conditions | ||
7 | .\" are met: | ||
8 | .\" 1. Redistributions of source code must retain the above copyright | ||
9 | .\" notice, this list of conditions and the following disclaimer. | ||
10 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
11 | .\" notice, this list of conditions and the following disclaimer in the | ||
12 | .\" documentation and/or other materials provided with the distribution. | ||
13 | .\" 3. The name of the author may not be used to endorse or promote products | ||
14 | .\" derived from this software without specific prior written permission. | ||
15 | .\" | ||
16 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
17 | .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
18 | .\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
19 | .\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
20 | .\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
21 | .\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
22 | .\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
23 | .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
24 | .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
25 | .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | .\" | ||
27 | .\" $OpenBSD: a64l.3,v 1.2 1998/06/21 22:13:48 millert Exp $ | ||
28 | .\" | ||
29 | .Dd August 17, 1997 | ||
30 | .Dt A64L 3 | ||
31 | .Os | ||
32 | .Sh NAME | ||
33 | .Nm a64l , | ||
34 | .Nm l64a | ||
35 | .Nd convert between 32-bit integer and radix-64 ASCII string | ||
36 | .Sh SYNOPSIS | ||
37 | .Fd #include <stdlib.h> | ||
38 | .Ft long | ||
39 | .Fn a64l "const char *s" | ||
40 | .Ft char * | ||
41 | .Fn l64a "long l" | ||
42 | .Sh DESCRIPTION | ||
43 | The | ||
44 | .Fn a64l | ||
45 | and | ||
46 | .Fn l64a | ||
47 | functions are used to maintain numbers stored in radix-64 | ||
48 | ASCII characters. This is a notation by which 32-bit integers | ||
49 | can be represented by up to six characters; each character | ||
50 | represents a "digit" in a radix-64 notation. | ||
51 | .Pp | ||
52 | The characters used to represent "digits" are '.' for 0, '/' for 1, | ||
53 | '0' through '9' for 2-11, 'A' through 'Z' for 12-37, and 'a' through | ||
54 | 'z' for 38-63. | ||
55 | .Pp | ||
56 | The | ||
57 | .Fn a64l | ||
58 | function takes a pointer to a null-terminated radix-64 representation | ||
59 | and returns a corresponding 32-bit value. If the string pointed to by | ||
60 | .Ar s | ||
61 | contains more than six characters, | ||
62 | .Fn a64l | ||
63 | will use the first six. | ||
64 | .Fn A64l | ||
65 | scans the character string from left to right, decoding | ||
66 | each character as a 6-bit radix-64 number. If a long integer is | ||
67 | larger than 32 bits, the return value will be sign-extended. | ||
68 | .Pp | ||
69 | .Fn l64a | ||
70 | takes a long integer argument | ||
71 | .Ar l | ||
72 | and returns a pointer to the corresponding radix-64 representation. | ||
73 | .Sh RETURN VALUES | ||
74 | On success, | ||
75 | .Fn a64l | ||
76 | returns a 32-bit representation of | ||
77 | .Ar s . | ||
78 | If | ||
79 | .Ar s | ||
80 | is a NULL pointer or if it contains "digits" other than those described above, | ||
81 | .Fn a64l | ||
82 | returns -1L and sets the global variable errno to | ||
83 | .Va EINVAL . | ||
84 | .Pp | ||
85 | On success, | ||
86 | .Fn l64a | ||
87 | returns a pointer to a string containing the radix-64 representation of | ||
88 | .Ar l . | ||
89 | If | ||
90 | .Ar l | ||
91 | is 0, | ||
92 | .Fn l64a | ||
93 | returns a pointer to the empty string. | ||
94 | If | ||
95 | .Ar l | ||
96 | is negative, | ||
97 | .Fn l64a | ||
98 | returns a NULL pointer and sets the global variable errno to | ||
99 | .Va EINVAL . | ||
100 | .Sh WARNINGS | ||
101 | The value returned by | ||
102 | .Fn l64a | ||
103 | is a pointer into a static buffer, the contents of which | ||
104 | will be overwritten by subsequent calls. | ||
105 | .Pp | ||
106 | The value returned by | ||
107 | .Fn a64l | ||
108 | may be incorrect if the value is too large; for that reason, only strings | ||
109 | that resulted from a call to | ||
110 | .Fn l64a | ||
111 | should be used to call | ||
112 | .Fn a64l . | ||
113 | .Pp | ||
114 | If a long integer is larger than 32 bits, only the low-order | ||
115 | 32 bits are used. | ||
116 | .Sh STANDARDS | ||
117 | The | ||
118 | .Fn a64l | ||
119 | and | ||
120 | .Fn l64a | ||
121 | functions conform to | ||
122 | .St -xpg4.2 . | ||
diff --git a/src/lib/libc/stdlib/a64l.c b/src/lib/libc/stdlib/a64l.c index 03fc77e034..a68f0a6dcd 100644 --- a/src/lib/libc/stdlib/a64l.c +++ b/src/lib/libc/stdlib/a64l.c | |||
@@ -4,8 +4,11 @@ | |||
4 | */ | 4 | */ |
5 | 5 | ||
6 | #if defined(LIBC_SCCS) && !defined(lint) | 6 | #if defined(LIBC_SCCS) && !defined(lint) |
7 | static char *rcsid = "$NetBSD: a64l.c,v 1.3 1995/05/11 23:04:47 jtc Exp $"; | 7 | static char *rcsid = "$OpenBSD: a64l.c,v 1.3 1997/08/17 22:58:34 millert Exp $"; |
8 | #endif | 8 | #endif /* LIBC_SCCS and not lint */ |
9 | |||
10 | #include <errno.h> | ||
11 | #include <stdlib.h> | ||
9 | 12 | ||
10 | long | 13 | long |
11 | a64l(s) | 14 | a64l(s) |
@@ -14,21 +17,30 @@ a64l(s) | |||
14 | long value, digit, shift; | 17 | long value, digit, shift; |
15 | int i; | 18 | int i; |
16 | 19 | ||
20 | if (s == NULL) { | ||
21 | errno = EINVAL; | ||
22 | return(-1L); | ||
23 | } | ||
24 | |||
17 | value = 0; | 25 | value = 0; |
18 | shift = 0; | 26 | shift = 0; |
19 | for (i = 0; *s && i < 6; i++, s++) { | 27 | for (i = 0; *s && i < 6; i++, s++) { |
20 | if (*s <= '/') | 28 | if (*s >= '.' && *s <= '/') |
21 | digit = *s - '.'; | 29 | digit = *s - '.'; |
22 | else if (*s <= '9') | 30 | else if (*s >= '0' && *s <= '9') |
23 | digit = *s - '0' + 2; | 31 | digit = *s - '0' + 2; |
24 | else if (*s <= 'Z') | 32 | else if (*s >= 'A' && *s <= 'Z') |
25 | digit = *s - 'A' + 12; | 33 | digit = *s - 'A' + 12; |
26 | else | 34 | else if (*s >= 'a' && *s <= 'z') |
27 | digit = *s - 'a' + 38; | 35 | digit = *s - 'a' + 38; |
36 | else { | ||
37 | errno = EINVAL; | ||
38 | return(-1L); | ||
39 | } | ||
28 | 40 | ||
29 | value |= digit << shift; | 41 | value |= digit << shift; |
30 | shift += 6; | 42 | shift += 6; |
31 | } | 43 | } |
32 | 44 | ||
33 | return (long) value; | 45 | return(value); |
34 | } | 46 | } |
diff --git a/src/lib/libc/stdlib/abort.3 b/src/lib/libc/stdlib/abort.3 index ab57327585..92c9a354d0 100644 --- a/src/lib/libc/stdlib/abort.3 +++ b/src/lib/libc/stdlib/abort.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)abort.3 6.7 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: abort.3,v 1.4 1997/07/17 07:39:41 deraadt Exp $ |
37 | .\" $Id: abort.3,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt ABORT 3 | 39 | .Dt ABORT 3 |
@@ -54,7 +53,7 @@ signal | |||
54 | .Dv SIGABRT | 53 | .Dv SIGABRT |
55 | is being caught and the signal handler does not return. | 54 | is being caught and the signal handler does not return. |
56 | .Pp | 55 | .Pp |
57 | No open streams are closed or flushed. | 56 | Any open streams are flushed and closed. |
58 | .Sh RETURN VALUES | 57 | .Sh RETURN VALUES |
59 | The | 58 | The |
60 | .Nm abort | 59 | .Nm abort |
@@ -62,10 +61,10 @@ function | |||
62 | never returns. | 61 | never returns. |
63 | .Sh SEE ALSO | 62 | .Sh SEE ALSO |
64 | .Xr sigaction 2 , | 63 | .Xr sigaction 2 , |
65 | .Xr exit 2 | 64 | .Xr exit 3 |
66 | .Sh STANDARDS | 65 | .Sh STANDARDS |
67 | The | 66 | The |
68 | .Fn abort | 67 | .Fn abort |
69 | function | 68 | function |
70 | conforms to | 69 | conforms to |
71 | .St -ansiC . | 70 | .St -p1003.1-90 . |
diff --git a/src/lib/libc/stdlib/abort.c b/src/lib/libc/stdlib/abort.c index c298e016b4..4ea8a2ca4b 100644 --- a/src/lib/libc/stdlib/abort.c +++ b/src/lib/libc/stdlib/abort.c | |||
@@ -32,19 +32,22 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)abort.c 5.11 (Berkeley) 2/23/91";*/ | 35 | static char *rcsid = "$OpenBSD: abort.c,v 1.5 1997/06/22 20:21:25 tholo Exp $"; |
36 | static char *rcsid = "$Id: abort.c,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <signal.h> | 38 | #include <signal.h> |
40 | #include <stdlib.h> | 39 | #include <stdlib.h> |
41 | #include <unistd.h> | 40 | #include <unistd.h> |
42 | 41 | ||
42 | void (*__cleanup)(); | ||
43 | |||
43 | void | 44 | void |
44 | abort() | 45 | abort() |
45 | { | 46 | { |
47 | static int cleanup_called = 0; | ||
46 | sigset_t mask; | 48 | sigset_t mask; |
47 | 49 | ||
50 | |||
48 | sigfillset(&mask); | 51 | sigfillset(&mask); |
49 | /* | 52 | /* |
50 | * don't block SIGABRT to give any handler a chance; we ignore | 53 | * don't block SIGABRT to give any handler a chance; we ignore |
@@ -52,6 +55,15 @@ abort() | |||
52 | */ | 55 | */ |
53 | sigdelset(&mask, SIGABRT); | 56 | sigdelset(&mask, SIGABRT); |
54 | (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); | 57 | (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); |
58 | |||
59 | /* | ||
60 | * POSIX requires we flush stdio buffers on abort | ||
61 | */ | ||
62 | if (cleanup_called == 0 && __cleanup != NULL) { | ||
63 | cleanup_called = 1; | ||
64 | (*__cleanup)(); | ||
65 | } | ||
66 | |||
55 | (void)kill(getpid(), SIGABRT); | 67 | (void)kill(getpid(), SIGABRT); |
56 | 68 | ||
57 | /* | 69 | /* |
diff --git a/src/lib/libc/stdlib/abs.3 b/src/lib/libc/stdlib/abs.3 index 4748d89e77..77f82b9402 100644 --- a/src/lib/libc/stdlib/abs.3 +++ b/src/lib/libc/stdlib/abs.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)abs.3 6.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: abs.3,v 1.2 1996/08/19 08:33:21 tholo Exp $ |
37 | .\" $Id: abs.3,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt ABS 3 | 39 | .Dt ABS 3 |
diff --git a/src/lib/libc/stdlib/abs.c b/src/lib/libc/stdlib/abs.c index 64468e0224..7c79e4073c 100644 --- a/src/lib/libc/stdlib/abs.c +++ b/src/lib/libc/stdlib/abs.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)abs.c 5.2 (Berkeley) 5/17/90";*/ | 35 | static char *rcsid = "$OpenBSD: abs.c,v 1.2 1996/08/19 08:33:21 tholo Exp $"; |
36 | static char *rcsid = "$Id: abs.c,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
diff --git a/src/lib/libc/stdlib/alloca.3 b/src/lib/libc/stdlib/alloca.3 index dcb97ab11c..ef87220772 100644 --- a/src/lib/libc/stdlib/alloca.3 +++ b/src/lib/libc/stdlib/alloca.3 | |||
@@ -29,8 +29,7 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
31 | .\" | 31 | .\" |
32 | .\" from: @(#)alloca.3 5.1 (Berkeley) 5/2/91 | 32 | .\" $OpenBSD: alloca.3,v 1.3 1996/08/19 08:33:22 tholo Exp $ |
33 | .\" $Id: alloca.3,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $ | ||
34 | .\" | 33 | .\" |
35 | .Dd May 2, 1991 | 34 | .Dd May 2, 1991 |
36 | .Dt ALLOCA 3 | 35 | .Dt ALLOCA 3 |
@@ -55,9 +54,6 @@ return. | |||
55 | The | 54 | The |
56 | .Fn alloca | 55 | .Fn alloca |
57 | function returns a pointer to the beginning of the allocated space. | 56 | function returns a pointer to the beginning of the allocated space. |
58 | If the allocation failed, a | ||
59 | .Dv NULL | ||
60 | pointer is returned. | ||
61 | .Sh SEE ALSO | 57 | .Sh SEE ALSO |
62 | .Xr brk 2 , | 58 | .Xr brk 2 , |
63 | .Xr pagesize 2 | 59 | .Xr pagesize 2 |
diff --git a/src/lib/libc/stdlib/atexit.3 b/src/lib/libc/stdlib/atexit.3 index 07de054d3c..0b10f010fa 100644 --- a/src/lib/libc/stdlib/atexit.3 +++ b/src/lib/libc/stdlib/atexit.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)atexit.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: atexit.3,v 1.2 1996/08/19 08:33:22 tholo Exp $ |
37 | .\" $Id: atexit.3,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt ATEXIT 3 | 39 | .Dt ATEXIT 3 |
diff --git a/src/lib/libc/stdlib/atexit.c b/src/lib/libc/stdlib/atexit.c index 4da1eb0d9c..c0fb624141 100644 --- a/src/lib/libc/stdlib/atexit.c +++ b/src/lib/libc/stdlib/atexit.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)atexit.c 5.2 (Berkeley) 11/14/90";*/ | 38 | static char *rcsid = "$OpenBSD: atexit.c,v 1.2 1996/08/19 08:33:22 tholo Exp $"; |
39 | static char *rcsid = "$Id: atexit.c,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <stdlib.h> | 41 | #include <stdlib.h> |
diff --git a/src/lib/libc/stdlib/atexit.h b/src/lib/libc/stdlib/atexit.h index 8b756e8fe2..e41a7cb86c 100644 --- a/src/lib/libc/stdlib/atexit.h +++ b/src/lib/libc/stdlib/atexit.h | |||
@@ -30,8 +30,7 @@ | |||
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
31 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
32 | * | 32 | * |
33 | * from: @(#)atexit.h 5.1 (Berkeley) 5/15/90 | 33 | * $OpenBSD: atexit.h,v 1.2 1996/08/19 08:33:23 tholo Exp $ |
34 | * $Id: atexit.h,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $ | ||
35 | */ | 34 | */ |
36 | 35 | ||
37 | /* must be at least 32 to guarantee ANSI conformance */ | 36 | /* must be at least 32 to guarantee ANSI conformance */ |
diff --git a/src/lib/libc/stdlib/atof.3 b/src/lib/libc/stdlib/atof.3 index 53e04f71c5..cc1b500b0f 100644 --- a/src/lib/libc/stdlib/atof.3 +++ b/src/lib/libc/stdlib/atof.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)atof.3 6.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: atof.3,v 1.2 1996/08/19 08:33:23 tholo Exp $ |
37 | .\" $Id: atof.3,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt ATOF 3 | 39 | .Dt ATOF 3 |
diff --git a/src/lib/libc/stdlib/atof.c b/src/lib/libc/stdlib/atof.c index 9202de50bb..30bac19899 100644 --- a/src/lib/libc/stdlib/atof.c +++ b/src/lib/libc/stdlib/atof.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)atof.c 5.3 (Berkeley) 1/8/93";*/ | 35 | static char *rcsid = "$OpenBSD: atof.c,v 1.2 1996/08/19 08:33:24 tholo Exp $"; |
36 | static char *rcsid = "$Id: atof.c,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
diff --git a/src/lib/libc/stdlib/atoi.3 b/src/lib/libc/stdlib/atoi.3 index 219ba73c00..280a989e8e 100644 --- a/src/lib/libc/stdlib/atoi.3 +++ b/src/lib/libc/stdlib/atoi.3 | |||
@@ -1,5 +1,5 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" Copyright (c) 1990, 1991, 1993 |
2 | .\" All rights reserved. | 2 | .\" The Regents of the University of California. All rights reserved. |
3 | .\" | 3 | .\" |
4 | .\" This code is derived from software contributed to Berkeley by | 4 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" the American National Standards Committee X3, on Information | 5 | .\" the American National Standards Committee X3, on Information |
@@ -33,10 +33,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)atoi.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: atoi.3,v 1.2 1996/08/10 04:51:31 tholo Exp $ |
37 | .\" $Id: atoi.3,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 4, 1993 |
40 | .Dt ATOI 3 | 39 | .Dt ATOI 3 |
41 | .Os | 40 | .Os |
42 | .Sh NAME | 41 | .Sh NAME |
@@ -58,7 +57,6 @@ to | |||
58 | representation. | 57 | representation. |
59 | .Pp | 58 | .Pp |
60 | It is equivalent to: | 59 | It is equivalent to: |
61 | .Pp | ||
62 | .Bd -literal -offset indent | 60 | .Bd -literal -offset indent |
63 | (int)strtol(nptr, (char **)NULL, 10); | 61 | (int)strtol(nptr, (char **)NULL, 10); |
64 | .Ed | 62 | .Ed |
diff --git a/src/lib/libc/stdlib/atoi.c b/src/lib/libc/stdlib/atoi.c index df7845f90c..a74d6e1351 100644 --- a/src/lib/libc/stdlib/atoi.c +++ b/src/lib/libc/stdlib/atoi.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)atoi.c 5.7 (Berkeley) 2/23/91";*/ | 35 | static char *rcsid = "$OpenBSD: atoi.c,v 1.2 1996/08/19 08:33:24 tholo Exp $"; |
36 | static char *rcsid = "$Id: atoi.c,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
diff --git a/src/lib/libc/stdlib/atol.3 b/src/lib/libc/stdlib/atol.3 index 86e3d324a3..2b49bd1f2c 100644 --- a/src/lib/libc/stdlib/atol.3 +++ b/src/lib/libc/stdlib/atol.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)atol.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: atol.3,v 1.2 1996/08/19 08:33:25 tholo Exp $ |
37 | .\" $Id: atol.3,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt ATOL 3 | 39 | .Dt ATOL 3 |
diff --git a/src/lib/libc/stdlib/atol.c b/src/lib/libc/stdlib/atol.c index 31ed06298b..528a932214 100644 --- a/src/lib/libc/stdlib/atol.c +++ b/src/lib/libc/stdlib/atol.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)atol.c 5.7 (Berkeley) 2/23/91";*/ | 35 | static char *rcsid = "$OpenBSD: atol.c,v 1.2 1996/08/19 08:33:26 tholo Exp $"; |
36 | static char *rcsid = "$Id: atol.c,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
diff --git a/src/lib/libc/stdlib/bsearch.3 b/src/lib/libc/stdlib/bsearch.3 index 1622c96c6b..570a4227b4 100644 --- a/src/lib/libc/stdlib/bsearch.3 +++ b/src/lib/libc/stdlib/bsearch.3 | |||
@@ -1,5 +1,5 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" Copyright (c) 1990, 1991, 1993, 1994 |
2 | .\" All rights reserved. | 2 | .\" The Regents of the University of California. All rights reserved. |
3 | .\" | 3 | .\" |
4 | .\" This code is derived from software contributed to Berkeley by | 4 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" the American National Standards Committee X3, on Information | 5 | .\" the American National Standards Committee X3, on Information |
@@ -33,10 +33,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)bsearch.3 5.6 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: bsearch.3,v 1.3 1997/06/13 23:41:35 deraadt Exp $ |
37 | .\" $Id: bsearch.3,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd April 19, 1994 |
40 | .Dt BSEARCH 3 | 39 | .Dt BSEARCH 3 |
41 | .Os | 40 | .Os |
42 | .Sh NAME | 41 | .Sh NAME |
@@ -65,7 +64,7 @@ to the comparison function referenced by | |||
65 | The | 64 | The |
66 | .Fa compar | 65 | .Fa compar |
67 | routine | 66 | routine |
68 | is expected to have two | 67 | is expected to have |
69 | two arguments which point to the | 68 | two arguments which point to the |
70 | .Fa key | 69 | .Fa key |
71 | object and to an array member, in that order, and should return an integer | 70 | object and to an array member, in that order, and should return an integer |
@@ -83,7 +82,7 @@ If two members compare as equal, which member is matched is unspecified. | |||
83 | .Xr db 3 , | 82 | .Xr db 3 , |
84 | .Xr lsearch 3 , | 83 | .Xr lsearch 3 , |
85 | .Xr qsort 3 , | 84 | .Xr qsort 3 , |
86 | .\" .Xr tsearch 3 | 85 | .Xr tsearch 3 |
87 | .Sh STANDARDS | 86 | .Sh STANDARDS |
88 | The | 87 | The |
89 | .Fn bsearch | 88 | .Fn bsearch |
diff --git a/src/lib/libc/stdlib/bsearch.c b/src/lib/libc/stdlib/bsearch.c index fac03f694f..eeef9bffc6 100644 --- a/src/lib/libc/stdlib/bsearch.c +++ b/src/lib/libc/stdlib/bsearch.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)bsearch.c 5.4 (Berkeley) 2/23/91";*/ | 35 | static char *rcsid = "$OpenBSD: bsearch.c,v 1.2 1996/08/19 08:33:26 tholo Exp $"; |
36 | static char *rcsid = "$Id: bsearch.c,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
diff --git a/src/lib/libc/stdlib/calloc.3 b/src/lib/libc/stdlib/calloc.3 index d0754b46a0..13a912169c 100644 --- a/src/lib/libc/stdlib/calloc.3 +++ b/src/lib/libc/stdlib/calloc.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)calloc.3 5.2 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: calloc.3,v 1.3 1996/12/10 09:06:10 deraadt Exp $ |
37 | .\" $Id: calloc.3,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt CALLOC 3 | 39 | .Dt CALLOC 3 |
@@ -58,7 +57,7 @@ The space is initialized to all bits zero. | |||
58 | The | 57 | The |
59 | .Fn calloc | 58 | .Fn calloc |
60 | function returns | 59 | function returns |
61 | a pointer to the | 60 | a pointer to |
62 | the allocated space if successful; otherwise a null pointer is returned. | 61 | the allocated space if successful; otherwise a null pointer is returned. |
63 | .Sh SEE ALSO | 62 | .Sh SEE ALSO |
64 | .Xr malloc 3 , | 63 | .Xr malloc 3 , |
diff --git a/src/lib/libc/stdlib/calloc.c b/src/lib/libc/stdlib/calloc.c index 3353fab052..a2c4f84493 100644 --- a/src/lib/libc/stdlib/calloc.c +++ b/src/lib/libc/stdlib/calloc.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)calloc.c 5.6 (Berkeley) 2/23/91";*/ | 35 | static char *rcsid = "$OpenBSD: calloc.c,v 1.3 1996/08/20 17:42:33 downsj Exp $"; |
36 | static char *rcsid = "$Id: calloc.c,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
@@ -47,7 +46,8 @@ calloc(num, size) | |||
47 | register void *p; | 46 | register void *p; |
48 | 47 | ||
49 | size *= num; | 48 | size *= num; |
50 | if (p = malloc(size)) | 49 | p = malloc(size); |
50 | if (p) | ||
51 | memset(p, '\0', size); | 51 | memset(p, '\0', size); |
52 | return(p); | 52 | return(p); |
53 | } | 53 | } |
diff --git a/src/lib/libc/stdlib/cfree.c b/src/lib/libc/stdlib/cfree.c new file mode 100644 index 0000000000..3af32039a9 --- /dev/null +++ b/src/lib/libc/stdlib/cfree.c | |||
@@ -0,0 +1,49 @@ | |||
1 | /* $OpenBSD: cfree.c,v 1.1 1996/08/21 03:47:22 tholo Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com> | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. All advertising materials mentioning features or use of this software | ||
16 | * must display the following acknowledgement: | ||
17 | * This product includes software developed by SigmaSoft, Th. Lockert. | ||
18 | * 4. The name of the author may not be used to endorse or promote products | ||
19 | * derived from this software without specific prior written permission. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
22 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
23 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
24 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
27 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
28 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
30 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #if defined(LIBC_SCCS) && !defined(lint) | ||
34 | static char rcsid[] = "$OpenBSD: cfree.c,v 1.1 1996/08/21 03:47:22 tholo Exp $"; | ||
35 | #endif /* LIBC_SCCS and not lint */ | ||
36 | |||
37 | #include <sys/cdefs.h> | ||
38 | |||
39 | #ifdef __indr_reference | ||
40 | __indr_reference(free, cfree); | ||
41 | #else | ||
42 | |||
43 | void | ||
44 | cfree(p) | ||
45 | void *p; | ||
46 | { | ||
47 | free(p); | ||
48 | } | ||
49 | #endif | ||
diff --git a/src/lib/libc/stdlib/div.3 b/src/lib/libc/stdlib/div.3 index a4730694a5..0d8c56d86b 100644 --- a/src/lib/libc/stdlib/div.3 +++ b/src/lib/libc/stdlib/div.3 | |||
@@ -31,8 +31,7 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" from: @(#)div.3 5.2 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: div.3,v 1.2 1996/08/19 08:33:28 tholo Exp $ |
35 | .\" $Id: div.3,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $ | ||
36 | .\" | 35 | .\" |
37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
38 | .Dt DIV 3 | 37 | .Dt DIV 3 |
diff --git a/src/lib/libc/stdlib/div.c b/src/lib/libc/stdlib/div.c index 122ac0deec..c1fae29008 100644 --- a/src/lib/libc/stdlib/div.c +++ b/src/lib/libc/stdlib/div.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)div.c 5.2 (Berkeley) 4/16/91";*/ | 38 | static char *rcsid = "$OpenBSD: div.c,v 1.2 1996/08/19 08:33:29 tholo Exp $"; |
39 | static char *rcsid = "$Id: div.c,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <stdlib.h> /* div_t */ | 41 | #include <stdlib.h> /* div_t */ |
diff --git a/src/lib/libc/stdlib/drand48.c b/src/lib/libc/stdlib/drand48.c index ae1a8634dc..02886d5b62 100644 --- a/src/lib/libc/stdlib/drand48.c +++ b/src/lib/libc/stdlib/drand48.c | |||
@@ -11,6 +11,10 @@ | |||
11 | * to anyone/anything when using this software. | 11 | * to anyone/anything when using this software. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #if defined(LIBC_SCCS) && !defined(lint) | ||
15 | static char rcsid[] = "$OpenBSD: drand48.c,v 1.2 1996/08/19 08:33:29 tholo Exp $"; | ||
16 | #endif /* LIBC_SCCS and not lint */ | ||
17 | |||
14 | #include "rand48.h" | 18 | #include "rand48.h" |
15 | 19 | ||
16 | extern unsigned short __rand48_seed[3]; | 20 | extern unsigned short __rand48_seed[3]; |
diff --git a/src/lib/libc/stdlib/erand48.c b/src/lib/libc/stdlib/erand48.c index cc9fbf770c..b92dacffcc 100644 --- a/src/lib/libc/stdlib/erand48.c +++ b/src/lib/libc/stdlib/erand48.c | |||
@@ -11,6 +11,10 @@ | |||
11 | * to anyone/anything when using this software. | 11 | * to anyone/anything when using this software. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #if defined(LIBC_SCCS) && !defined(lint) | ||
15 | static char rcsid[] = "$OpenBSD: erand48.c,v 1.2 1996/08/19 08:33:29 tholo Exp $"; | ||
16 | #endif /* LIBC_SCCS and not lint */ | ||
17 | |||
14 | #include "rand48.h" | 18 | #include "rand48.h" |
15 | 19 | ||
16 | double | 20 | double |
diff --git a/src/lib/libc/stdlib/exit.3 b/src/lib/libc/stdlib/exit.3 index adb81ffcb4..6dd2affef9 100644 --- a/src/lib/libc/stdlib/exit.3 +++ b/src/lib/libc/stdlib/exit.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)exit.3 6.6 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: exit.3,v 1.2 1996/08/19 08:33:30 tholo Exp $ |
37 | .\" $Id: exit.3,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt EXIT 3 | 39 | .Dt EXIT 3 |
diff --git a/src/lib/libc/stdlib/exit.c b/src/lib/libc/stdlib/exit.c index b1412f42bb..e358c94fd6 100644 --- a/src/lib/libc/stdlib/exit.c +++ b/src/lib/libc/stdlib/exit.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)exit.c 5.4 (Berkeley) 2/23/91";*/ | 35 | static char *rcsid = "$OpenBSD: exit.c,v 1.2 1996/08/19 08:33:30 tholo Exp $"; |
36 | static char *rcsid = "$Id: exit.c,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
diff --git a/src/lib/libc/stdlib/free.3 b/src/lib/libc/stdlib/free.3 deleted file mode 100644 index 3d0131d7de..0000000000 --- a/src/lib/libc/stdlib/free.3 +++ /dev/null | |||
@@ -1,82 +0,0 @@ | |||
1 | .\" Copyright (c) 1991 The Regents of the University of California. | ||
2 | .\" All rights reserved. | ||
3 | .\" | ||
4 | .\" This code is derived from software contributed to Berkeley by | ||
5 | .\" the American National Standards Committee X3, on Information | ||
6 | .\" Processing Systems. | ||
7 | .\" | ||
8 | .\" Redistribution and use in source and binary forms, with or without | ||
9 | .\" modification, are permitted provided that the following conditions | ||
10 | .\" are met: | ||
11 | .\" 1. Redistributions of source code must retain the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer. | ||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer in the | ||
15 | .\" documentation and/or other materials provided with the distribution. | ||
16 | .\" 3. All advertising materials mentioning features or use of this software | ||
17 | .\" must display the following acknowledgement: | ||
18 | .\" This product includes software developed by the University of | ||
19 | .\" California, Berkeley and its contributors. | ||
20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
21 | .\" may be used to endorse or promote products derived from this software | ||
22 | .\" without specific prior written permission. | ||
23 | .\" | ||
24 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
25 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
26 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
27 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
28 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
29 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
30 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
31 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
32 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
34 | .\" SUCH DAMAGE. | ||
35 | .\" | ||
36 | .\" from: @(#)free.3 5.2 (Berkeley) 6/29/91 | ||
37 | .\" $Id: free.3,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt FREE 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm free | ||
44 | .Nd free up memory allocated with malloc, calloc or realloc | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <stdlib.h> | ||
47 | .Ft void | ||
48 | .Fn free "void *ptr" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn free | ||
52 | function causes the space pointed to by | ||
53 | .Fa ptr | ||
54 | to be deallocated, that is, made available | ||
55 | for further allocation. | ||
56 | If | ||
57 | .Fa ptr | ||
58 | is a null pointer, no action occurs. | ||
59 | Otherwise, if the argument does not match a pointer earlier | ||
60 | returned by the | ||
61 | .Xr calloc , | ||
62 | .Xr malloc , | ||
63 | or | ||
64 | .Xr realloc | ||
65 | function, or if the space has been deallocated by a call to | ||
66 | .Fn free | ||
67 | or | ||
68 | .Xr realloc , | ||
69 | general havoc may occur. | ||
70 | .Sh RETURN VALUES | ||
71 | The | ||
72 | .Fn free | ||
73 | function returns no value. | ||
74 | .Sh SEE ALSO | ||
75 | .Xr calloc 3 , | ||
76 | .Xr malloc 3 , | ||
77 | .Xr realloc 3 | ||
78 | .Sh STANDARDS | ||
79 | The | ||
80 | .Fn free | ||
81 | function conforms to | ||
82 | .St -ansiC . | ||
diff --git a/src/lib/libc/stdlib/getenv.3 b/src/lib/libc/stdlib/getenv.3 index 411eb35da4..24a8d3d095 100644 --- a/src/lib/libc/stdlib/getenv.3 +++ b/src/lib/libc/stdlib/getenv.3 | |||
@@ -1,5 +1,5 @@ | |||
1 | .\" Copyright (c) 1988, 1991 The Regents of the University of California. | 1 | .\" Copyright (c) 1988, 1991, 1993 |
2 | .\" All rights reserved. | 2 | .\" The Regents of the University of California. All rights reserved. |
3 | .\" | 3 | .\" |
4 | .\" This code is derived from software contributed to Berkeley by | 4 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" the American National Standards Committee X3, on Information | 5 | .\" the American National Standards Committee X3, on Information |
@@ -33,10 +33,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)getenv.3 6.11 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: getenv.3,v 1.2 1996/08/10 05:03:00 tholo Exp $ |
37 | .\" $Id: getenv.3,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd December 11, 1993 |
40 | .Dt GETENV 3 | 39 | .Dt GETENV 3 |
41 | .Os | 40 | .Os |
42 | .Sh NAME | 41 | .Sh NAME |
@@ -75,7 +74,7 @@ function obtains the current value of the environment variable, | |||
75 | .Ar name . | 74 | .Ar name . |
76 | If the variable | 75 | If the variable |
77 | .Ar name | 76 | .Ar name |
78 | is not in the current environment , | 77 | is not in the current environment, |
79 | a null pointer is returned. | 78 | a null pointer is returned. |
80 | .Pp | 79 | .Pp |
81 | The | 80 | The |
@@ -121,7 +120,7 @@ return zero if successful; otherwise the global variable | |||
121 | is set to indicate the error and a | 120 | is set to indicate the error and a |
122 | \-1 is returned. | 121 | \-1 is returned. |
123 | .Sh ERRORS | 122 | .Sh ERRORS |
124 | .Bl -tag -width Er | 123 | .Bl -tag -width [ENOMEM] |
125 | .It Bq Er ENOMEM | 124 | .It Bq Er ENOMEM |
126 | The function | 125 | The function |
127 | .Fn setenv | 126 | .Fn setenv |
diff --git a/src/lib/libc/stdlib/getenv.c b/src/lib/libc/stdlib/getenv.c index 09d47f2149..4db86df915 100644 --- a/src/lib/libc/stdlib/getenv.c +++ b/src/lib/libc/stdlib/getenv.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 1987 Regents of the University of California. | 2 | * Copyright (c) 1987, 1993 |
3 | * All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
@@ -32,28 +32,13 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)getenv.c 5.8 (Berkeley) 2/23/91";*/ | 35 | static char *rcsid = "$OpenBSD: getenv.c,v 1.4 1998/07/16 18:02:33 deraadt Exp $"; |
36 | static char *rcsid = "$Id: getenv.c,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
40 | #include <string.h> | 39 | #include <string.h> |
41 | 40 | ||
42 | /* | 41 | /* |
43 | * getenv -- | ||
44 | * Returns ptr to value associated with name, if any, else NULL. | ||
45 | */ | ||
46 | char * | ||
47 | getenv(name) | ||
48 | const char *name; | ||
49 | { | ||
50 | int offset; | ||
51 | char *__findenv(); | ||
52 | |||
53 | return(__findenv(name, &offset)); | ||
54 | } | ||
55 | |||
56 | /* | ||
57 | * __findenv -- | 42 | * __findenv -- |
58 | * Returns pointer to value associated with name, if any, else NULL. | 43 | * Returns pointer to value associated with name, if any, else NULL. |
59 | * Sets offset to be the offset of the name/value combination in the | 44 | * Sets offset to be the offset of the name/value combination in the |
@@ -64,19 +49,41 @@ getenv(name) | |||
64 | */ | 49 | */ |
65 | char * | 50 | char * |
66 | __findenv(name, offset) | 51 | __findenv(name, offset) |
67 | register char *name; | 52 | register const char *name; |
68 | int *offset; | 53 | int *offset; |
69 | { | 54 | { |
70 | extern char **environ; | 55 | extern char **environ; |
71 | register int len; | 56 | register int len, i; |
72 | register char **P, *C; | 57 | register const char *np; |
58 | register char **p, *cp; | ||
73 | 59 | ||
74 | for (C = name, len = 0; *C && *C != '='; ++C, ++len); | 60 | if (name == NULL || environ == NULL) |
75 | for (P = environ; *P; ++P) | 61 | return (NULL); |
76 | if (!strncmp(*P, name, len)) | 62 | for (np = name; *np && *np != '='; ++np) |
77 | if (*(C = *P + len) == '=') { | 63 | ; |
78 | *offset = P - environ; | 64 | len = np - name; |
79 | return(++C); | 65 | for (p = environ; (cp = *p) != NULL; ++p) { |
80 | } | 66 | for (np = name, i = len; i && *cp; i--) |
81 | return(NULL); | 67 | if (*cp++ != *np++) |
68 | break; | ||
69 | if (i == 0 && *cp++ == '=') { | ||
70 | *offset = p - environ; | ||
71 | return (cp); | ||
72 | } | ||
73 | } | ||
74 | return (NULL); | ||
75 | } | ||
76 | |||
77 | /* | ||
78 | * getenv -- | ||
79 | * Returns ptr to value associated with name, if any, else NULL. | ||
80 | */ | ||
81 | char * | ||
82 | getenv(name) | ||
83 | const char *name; | ||
84 | { | ||
85 | int offset; | ||
86 | char *__findenv(); | ||
87 | |||
88 | return(__findenv(name, &offset)); | ||
82 | } | 89 | } |
diff --git a/src/lib/libc/stdlib/getopt.3 b/src/lib/libc/stdlib/getopt.3 index f843881afd..4340ff54fd 100644 --- a/src/lib/libc/stdlib/getopt.3 +++ b/src/lib/libc/stdlib/getopt.3 | |||
@@ -29,7 +29,7 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
31 | .\" | 31 | .\" |
32 | .\" @(#)getopt.3 8.4 (Berkeley) 4/19/94 | 32 | .\" $OpenBSD: getopt.3,v 1.6 1998/05/05 19:36:03 deraadt Exp $ |
33 | .\" | 33 | .\" |
34 | .Dd April 19, 1994 | 34 | .Dd April 19, 1994 |
35 | .Dt GETOPT 3 | 35 | .Dt GETOPT 3 |
@@ -137,12 +137,12 @@ returns \-1. | |||
137 | If the | 137 | If the |
138 | .Fn getopt | 138 | .Fn getopt |
139 | function encounters a character not found in the string | 139 | function encounters a character not found in the string |
140 | .Va optarg | 140 | .Va optstring |
141 | or detects | 141 | or detects |
142 | a missing option argument it writes an error message and returns | 142 | a missing option argument it writes an error message to |
143 | .Ql ? | 143 | .Em stderr |
144 | to the | 144 | and returns |
145 | .Em stderr . | 145 | .Ql ? . |
146 | Setting | 146 | Setting |
147 | .Va opterr | 147 | .Va opterr |
148 | to a zero will disable these error messages. | 148 | to a zero will disable these error messages. |
@@ -174,8 +174,8 @@ extern int optind; | |||
174 | int bflag, ch, fd; | 174 | int bflag, ch, fd; |
175 | 175 | ||
176 | bflag = 0; | 176 | bflag = 0; |
177 | while ((ch = getopt(argc, argv, "bf:")) != -1) | 177 | while ((ch = getopt(argc, argv, "bf:")) != -1) { |
178 | switch(ch) { | 178 | switch (ch) { |
179 | case 'b': | 179 | case 'b': |
180 | bflag = 1; | 180 | bflag = 1; |
181 | break; | 181 | break; |
@@ -189,6 +189,7 @@ while ((ch = getopt(argc, argv, "bf:")) != -1) | |||
189 | case '?': | 189 | case '?': |
190 | default: | 190 | default: |
191 | usage(); | 191 | usage(); |
192 | } | ||
192 | } | 193 | } |
193 | argc -= optind; | 194 | argc -= optind; |
194 | argv += optind; | 195 | argv += optind; |
@@ -213,7 +214,7 @@ from | |||
213 | .Pp | 214 | .Pp |
214 | A single dash | 215 | A single dash |
215 | .Dq Li - | 216 | .Dq Li - |
216 | may be specified as an character in | 217 | may be specified as a character in |
217 | .Fa optstring , | 218 | .Fa optstring , |
218 | however it should | 219 | however it should |
219 | .Em never | 220 | .Em never |
diff --git a/src/lib/libc/stdlib/getopt.c b/src/lib/libc/stdlib/getopt.c index 63c5e6a479..b7f6163662 100644 --- a/src/lib/libc/stdlib/getopt.c +++ b/src/lib/libc/stdlib/getopt.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /* static char sccsid[] = "from: @(#)getopt.c 8.2 (Berkeley) 4/2/94"; */ | 35 | static char *rcsid = "$OpenBSD: getopt.c,v 1.2 1996/08/19 08:33:32 tholo Exp $"; |
36 | static char *rcsid = "$Id: getopt.c,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdio.h> | 38 | #include <stdio.h> |
diff --git a/src/lib/libc/stdlib/getsubopt.3 b/src/lib/libc/stdlib/getsubopt.3 new file mode 100644 index 0000000000..8acc91bdd1 --- /dev/null +++ b/src/lib/libc/stdlib/getsubopt.3 | |||
@@ -0,0 +1,148 @@ | |||
1 | .\" $OpenBSD: getsubopt.3,v 1.2 1998/06/15 17:55:07 mickey Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
5 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | ||
7 | .\" modification, are permitted provided that the following conditions | ||
8 | .\" are met: | ||
9 | .\" 1. Redistributions of source code must retain the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer. | ||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer in the | ||
13 | .\" documentation and/or other materials provided with the distribution. | ||
14 | .\" 3. All advertising materials mentioning features or use of this software | ||
15 | .\" must display the following acknowledgement: | ||
16 | .\" This product includes software developed by the University of | ||
17 | .\" California, Berkeley and its contributors. | ||
18 | .\" 4. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .\" @(#)getsubopt.3 8.1 (Berkeley) 6/9/93 | ||
35 | .\" | ||
36 | .Dd June 9, 1993 | ||
37 | .Dt GETSUBOPT 3 | ||
38 | .Os | ||
39 | .Sh NAME | ||
40 | .Nm getsubopt | ||
41 | .Nd get sub options from an argument | ||
42 | .Sh SYNOPSIS | ||
43 | .Fd #include <stdlib.h> | ||
44 | .Vt extern char *suboptarg | ||
45 | .Ft int | ||
46 | .Fn getsubopt "char **optionp" "char * const *tokens" "char **valuep" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn getsubopt | ||
50 | function | ||
51 | parses a string containing tokens delimited by one or more tab, space or | ||
52 | comma | ||
53 | .Pq Ql \&, | ||
54 | characters. | ||
55 | It is intended for use in parsing groups of option arguments provided | ||
56 | as part of a utility command line. | ||
57 | .Pp | ||
58 | The argument | ||
59 | .Fa optionp | ||
60 | is a pointer to a pointer to the string. | ||
61 | The argument | ||
62 | .Fa tokens | ||
63 | is a pointer to a | ||
64 | .Dv NULL Ns -terminated | ||
65 | array of pointers to strings. | ||
66 | .Pp | ||
67 | The | ||
68 | .Fn getsubopt | ||
69 | function | ||
70 | returns the zero-based offset of the pointer in the | ||
71 | .Fa tokens | ||
72 | array referencing a string which matches the first token | ||
73 | in the string, or, \-1 if the string contains no tokens or | ||
74 | .Fa tokens | ||
75 | does not contain a matching string. | ||
76 | .Pp | ||
77 | If the token is of the form ``name=value'', the location referenced by | ||
78 | .Fa valuep | ||
79 | will be set to point to the start of the ``value'' portion of the token. | ||
80 | .Pp | ||
81 | On return from | ||
82 | .Fn getsubopt , | ||
83 | .Fa optionp | ||
84 | will be set to point to the start of the next token in the string, | ||
85 | or the null at the end of the string if no more tokens are present. | ||
86 | The external variable | ||
87 | .Fa suboptarg | ||
88 | will be set to point to the start of the current token, or | ||
89 | .Dv NULL | ||
90 | if no | ||
91 | tokens were present. | ||
92 | The argument | ||
93 | .Fa valuep | ||
94 | will be set to point to the ``value'' portion of the token, or | ||
95 | .Dv NULL | ||
96 | if no ``value'' portion was present. | ||
97 | .Sh EXAMPLE | ||
98 | .Bd -literal -compact | ||
99 | char *tokens[] = { | ||
100 | #define ONE 0 | ||
101 | "one", | ||
102 | #define TWO 1 | ||
103 | "two", | ||
104 | NULL | ||
105 | }; | ||
106 | |||
107 | \&... | ||
108 | |||
109 | extern char *optarg, *suboptarg; | ||
110 | char *options, *value; | ||
111 | |||
112 | while ((ch = getopt(argc, argv, "ab:")) != \-1) { | ||
113 | switch(ch) { | ||
114 | case 'a': | ||
115 | /* process ``a'' option */ | ||
116 | break; | ||
117 | case 'b': | ||
118 | options = optarg; | ||
119 | while (*options) { | ||
120 | switch(getsubopt(&options, tokens, &value)) { | ||
121 | case ONE: | ||
122 | /* process ``one'' sub option */ | ||
123 | break; | ||
124 | case TWO: | ||
125 | /* process ``two'' sub option */ | ||
126 | if (!value) | ||
127 | error("no value for two"); | ||
128 | i = atoi(value); | ||
129 | break; | ||
130 | case \-1: | ||
131 | if (suboptarg) | ||
132 | error("illegal sub option %s", | ||
133 | suboptarg); | ||
134 | else | ||
135 | error("missing sub option"); | ||
136 | break; | ||
137 | } | ||
138 | break; | ||
139 | } | ||
140 | .Ed | ||
141 | .Sh SEE ALSO | ||
142 | .Xr getopt 3 , | ||
143 | .Xr strsep 3 | ||
144 | .Sh HISTORY | ||
145 | The | ||
146 | .Fn getsubopt | ||
147 | function first appeared in | ||
148 | .Bx 4.4 . | ||
diff --git a/src/lib/libc/stdlib/getsubopt.c b/src/lib/libc/stdlib/getsubopt.c new file mode 100644 index 0000000000..1667a31d7d --- /dev/null +++ b/src/lib/libc/stdlib/getsubopt.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /* $OpenBSD: getsubopt.c,v 1.1 1997/08/20 04:02:17 millert Exp $ */ | ||
2 | |||
3 | /*- | ||
4 | * Copyright (c) 1990, 1993 | ||
5 | * The Regents of the University of California. All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. All advertising materials mentioning features or use of this software | ||
16 | * must display the following acknowledgement: | ||
17 | * This product includes software developed by the University of | ||
18 | * California, Berkeley and its contributors. | ||
19 | * 4. Neither the name of the University nor the names of its contributors | ||
20 | * may be used to endorse or promote products derived from this software | ||
21 | * without specific prior written permission. | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
33 | * SUCH DAMAGE. | ||
34 | */ | ||
35 | |||
36 | #ifndef lint | ||
37 | #if 0 | ||
38 | static char sccsid[] = "@(#)getsubopt.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$OpenBSD: getsubopt.c,v 1.1 1997/08/20 04:02:17 millert Exp $"; | ||
41 | #endif | ||
42 | #endif /* not lint */ | ||
43 | |||
44 | #include <unistd.h> | ||
45 | #include <stdlib.h> | ||
46 | #include <string.h> | ||
47 | |||
48 | /* | ||
49 | * The SVID interface to getsubopt provides no way of figuring out which | ||
50 | * part of the suboptions list wasn't matched. This makes error messages | ||
51 | * tricky... The extern variable suboptarg is a pointer to the token | ||
52 | * which didn't match. | ||
53 | */ | ||
54 | char *suboptarg; | ||
55 | |||
56 | int | ||
57 | getsubopt(optionp, tokens, valuep) | ||
58 | register char **optionp, **valuep; | ||
59 | register char * const *tokens; | ||
60 | { | ||
61 | register int cnt; | ||
62 | register char *p; | ||
63 | |||
64 | suboptarg = *valuep = NULL; | ||
65 | |||
66 | if (!optionp || !*optionp) | ||
67 | return(-1); | ||
68 | |||
69 | /* skip leading white-space, commas */ | ||
70 | for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); | ||
71 | |||
72 | if (!*p) { | ||
73 | *optionp = p; | ||
74 | return(-1); | ||
75 | } | ||
76 | |||
77 | /* save the start of the token, and skip the rest of the token. */ | ||
78 | for (suboptarg = p; | ||
79 | *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';); | ||
80 | |||
81 | if (*p) { | ||
82 | /* | ||
83 | * If there's an equals sign, set the value pointer, and | ||
84 | * skip over the value part of the token. Terminate the | ||
85 | * token. | ||
86 | */ | ||
87 | if (*p == '=') { | ||
88 | *p = '\0'; | ||
89 | for (*valuep = ++p; | ||
90 | *p && *p != ',' && *p != ' ' && *p != '\t'; ++p); | ||
91 | if (*p) | ||
92 | *p++ = '\0'; | ||
93 | } else | ||
94 | *p++ = '\0'; | ||
95 | /* Skip any whitespace or commas after this token. */ | ||
96 | for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); | ||
97 | } | ||
98 | |||
99 | /* set optionp for next round. */ | ||
100 | *optionp = p; | ||
101 | |||
102 | for (cnt = 0; *tokens; ++tokens, ++cnt) | ||
103 | if (!strcmp(suboptarg, *tokens)) | ||
104 | return(cnt); | ||
105 | return(-1); | ||
106 | } | ||
diff --git a/src/lib/libc/stdlib/heapsort.c b/src/lib/libc/stdlib/heapsort.c index bd998fa357..e3e4392e05 100644 --- a/src/lib/libc/stdlib/heapsort.c +++ b/src/lib/libc/stdlib/heapsort.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char sccsid[] = "from: @(#)heapsort.c 8.1 (Berkeley) 6/4/93";*/ | 38 | static char *rcsid = "$OpenBSD: heapsort.c,v 1.2 1996/08/19 08:33:32 tholo Exp $"; |
39 | static char *rcsid = "$Id: heapsort.c,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <sys/types.h> | 41 | #include <sys/types.h> |
diff --git a/src/lib/libc/stdlib/jrand48.c b/src/lib/libc/stdlib/jrand48.c index 205781e0ee..99cddb71e5 100644 --- a/src/lib/libc/stdlib/jrand48.c +++ b/src/lib/libc/stdlib/jrand48.c | |||
@@ -11,6 +11,10 @@ | |||
11 | * to anyone/anything when using this software. | 11 | * to anyone/anything when using this software. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #if defined(LIBC_SCCS) && !defined(lint) | ||
15 | static char rcsid[] = "$OpenBSD: jrand48.c,v 1.2 1996/08/19 08:33:33 tholo Exp $"; | ||
16 | #endif /* LIBC_SCCS and not lint */ | ||
17 | |||
14 | #include "rand48.h" | 18 | #include "rand48.h" |
15 | 19 | ||
16 | long | 20 | long |
diff --git a/src/lib/libc/stdlib/l64a.c b/src/lib/libc/stdlib/l64a.c index 3069b31bf6..4e99391254 100644 --- a/src/lib/libc/stdlib/l64a.c +++ b/src/lib/libc/stdlib/l64a.c | |||
@@ -4,13 +4,14 @@ | |||
4 | */ | 4 | */ |
5 | 5 | ||
6 | #if defined(LIBC_SCCS) && !defined(lint) | 6 | #if defined(LIBC_SCCS) && !defined(lint) |
7 | static char *rcsid = "$NetBSD: l64a.c,v 1.4 1995/05/11 23:04:52 jtc Exp $"; | 7 | static char *rcsid = "$OpenBSD: l64a.c,v 1.3 1997/08/17 22:58:34 millert Exp $"; |
8 | #endif | 8 | #endif /* LIBC_SCCS and not lint */ |
9 | 9 | ||
10 | #include <errno.h> | ||
10 | #include <stdlib.h> | 11 | #include <stdlib.h> |
11 | 12 | ||
12 | char * | 13 | char * |
13 | l64a (value) | 14 | l64a(value) |
14 | long value; | 15 | long value; |
15 | { | 16 | { |
16 | static char buf[8]; | 17 | static char buf[8]; |
@@ -18,8 +19,10 @@ l64a (value) | |||
18 | int digit; | 19 | int digit; |
19 | int i; | 20 | int i; |
20 | 21 | ||
21 | if (!value) | 22 | if (value < 0) { |
22 | return NULL; | 23 | errno = EINVAL; |
24 | return(NULL); | ||
25 | } | ||
23 | 26 | ||
24 | for (i = 0; value != 0 && i < 6; i++) { | 27 | for (i = 0; value != 0 && i < 6; i++) { |
25 | digit = value & 0x3f; | 28 | digit = value & 0x3f; |
@@ -39,5 +42,5 @@ l64a (value) | |||
39 | 42 | ||
40 | *s = '\0'; | 43 | *s = '\0'; |
41 | 44 | ||
42 | return buf; | 45 | return(buf); |
43 | } | 46 | } |
diff --git a/src/lib/libc/stdlib/labs.3 b/src/lib/libc/stdlib/labs.3 index 28e4d2053c..05eae329df 100644 --- a/src/lib/libc/stdlib/labs.3 +++ b/src/lib/libc/stdlib/labs.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)labs.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: labs.3,v 1.2 1996/08/19 08:33:34 tholo Exp $ |
37 | .\" $Id: labs.3,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt LABS 3 | 39 | .Dt LABS 3 |
diff --git a/src/lib/libc/stdlib/labs.c b/src/lib/libc/stdlib/labs.c index ccf1415792..f20e2c29be 100644 --- a/src/lib/libc/stdlib/labs.c +++ b/src/lib/libc/stdlib/labs.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)labs.c 5.2 (Berkeley) 5/17/90";*/ | 35 | static char *rcsid = "$OpenBSD: labs.c,v 1.2 1996/08/19 08:33:34 tholo Exp $"; |
36 | static char *rcsid = "$Id: labs.c,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
diff --git a/src/lib/libc/stdlib/lcong48.c b/src/lib/libc/stdlib/lcong48.c index 965d46b17a..44bd74e48a 100644 --- a/src/lib/libc/stdlib/lcong48.c +++ b/src/lib/libc/stdlib/lcong48.c | |||
@@ -11,6 +11,10 @@ | |||
11 | * to anyone/anything when using this software. | 11 | * to anyone/anything when using this software. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #if defined(LIBC_SCCS) && !defined(lint) | ||
15 | static char rcsid[] = "$OpenBSD: lcong48.c,v 1.2 1996/08/19 08:33:35 tholo Exp $"; | ||
16 | #endif /* LIBC_SCCS and not lint */ | ||
17 | |||
14 | #include "rand48.h" | 18 | #include "rand48.h" |
15 | 19 | ||
16 | extern unsigned short __rand48_seed[3]; | 20 | extern unsigned short __rand48_seed[3]; |
diff --git a/src/lib/libc/stdlib/ldiv.3 b/src/lib/libc/stdlib/ldiv.3 index a7b5ccf878..8757f4ddd5 100644 --- a/src/lib/libc/stdlib/ldiv.3 +++ b/src/lib/libc/stdlib/ldiv.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)ldiv.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: ldiv.3,v 1.2 1996/08/19 08:33:35 tholo Exp $ |
37 | .\" $Id: ldiv.3,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt LDIV 3 | 39 | .Dt LDIV 3 |
diff --git a/src/lib/libc/stdlib/ldiv.c b/src/lib/libc/stdlib/ldiv.c index f7074507e5..908c2bf0aa 100644 --- a/src/lib/libc/stdlib/ldiv.c +++ b/src/lib/libc/stdlib/ldiv.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)ldiv.c 5.2 (Berkeley) 4/16/91";*/ | 38 | static char *rcsid = "$OpenBSD: ldiv.c,v 1.2 1996/08/19 08:33:35 tholo Exp $"; |
39 | static char *rcsid = "$Id: ldiv.c,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <stdlib.h> /* ldiv_t */ | 41 | #include <stdlib.h> /* ldiv_t */ |
diff --git a/src/lib/libc/stdlib/lrand48.c b/src/lib/libc/stdlib/lrand48.c index 8e7f26237f..6b7524a51b 100644 --- a/src/lib/libc/stdlib/lrand48.c +++ b/src/lib/libc/stdlib/lrand48.c | |||
@@ -11,6 +11,10 @@ | |||
11 | * to anyone/anything when using this software. | 11 | * to anyone/anything when using this software. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #if defined(LIBC_SCCS) && !defined(lint) | ||
15 | static char rcsid[] = "$OpenBSD: lrand48.c,v 1.2 1996/08/19 08:33:36 tholo Exp $"; | ||
16 | #endif /* LIBC_SCCS and not lint */ | ||
17 | |||
14 | #include "rand48.h" | 18 | #include "rand48.h" |
15 | 19 | ||
16 | extern unsigned short __rand48_seed[3]; | 20 | extern unsigned short __rand48_seed[3]; |
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index 3bbf2bf65e..d5f8837ec2 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
@@ -1,5 +1,5 @@ | |||
1 | .\" Copyright (c) 1980, 1991 Regents of the University of California. | 1 | .\" Copyright (c) 1980, 1991, 1993 |
2 | .\" All rights reserved. | 2 | .\" The Regents of the University of California. All rights reserved. |
3 | .\" | 3 | .\" |
4 | .\" This code is derived from software contributed to Berkeley by | 4 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" the American National Standards Committee X3, on Information | 5 | .\" the American National Standards Committee X3, on Information |
@@ -33,19 +33,33 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)malloc.3 6.7 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: malloc.3,v 1.9 1998/08/15 20:32:02 deraadt Exp $ |
37 | .\" $Id: malloc.3,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd August 27, 1996 |
40 | .Dt MALLOC 3 | 39 | .Dt MALLOC 3 |
41 | .Os BSD 4 | 40 | .Os OpenBSD |
42 | .Sh NAME | 41 | .Sh NAME |
43 | .Nm malloc | 42 | .Nm malloc , |
44 | .Nd general memory allocation function | 43 | .Nd general memory allocation function |
44 | .Pp | ||
45 | .Nm free , | ||
46 | .Nm cfree | ||
47 | .Nd free up memory allocated with malloc, calloc or realloc | ||
48 | .Pp | ||
49 | .Nm realloc | ||
50 | .Nd reallocation of memory function | ||
45 | .Sh SYNOPSIS | 51 | .Sh SYNOPSIS |
46 | .Fd #include <stdlib.h> | 52 | .Fd #include <stdlib.h> |
47 | .Ft void * | 53 | .Ft void * |
48 | .Fn malloc "size_t size" | 54 | .Fn malloc "size_t size" |
55 | .Ft void | ||
56 | .Fn free "void *ptr" | ||
57 | .Ft void | ||
58 | .Fn cfree "void *ptr" | ||
59 | .Ft void * | ||
60 | .Fn realloc "void *ptr" "size_t size" | ||
61 | .Ft char * | ||
62 | .Va malloc_options | ||
49 | .Sh DESCRIPTION | 63 | .Sh DESCRIPTION |
50 | The | 64 | The |
51 | .Fn malloc | 65 | .Fn malloc |
@@ -62,30 +76,275 @@ suitably aligned (after possible pointer | |||
62 | coercion) for storage of any type of object. If the space is of | 76 | coercion) for storage of any type of object. If the space is of |
63 | .Em pagesize | 77 | .Em pagesize |
64 | or larger, the memory returned will be page-aligned. | 78 | or larger, the memory returned will be page-aligned. |
79 | .Pp | ||
80 | Allocation of a zero size object returns a pointer to a zero size object. | ||
81 | .Pp | ||
82 | The | ||
83 | .Fn free | ||
84 | function causes the space pointed to by | ||
85 | .Fa ptr | ||
86 | to be deallocated, that is, at least made available for further allocation, | ||
87 | but if possible, it will passed back to the kernel with | ||
88 | .Xr sbrk 2 . | ||
89 | If | ||
90 | .Fa ptr | ||
91 | is a null pointer, no action occurs. | ||
92 | .Pp | ||
93 | A | ||
94 | .Fn cfree | ||
95 | function is also provided for compatibility with old systems and other | ||
96 | .Nm malloc | ||
97 | libraries; it is simply an alias for | ||
98 | .Fn free . | ||
99 | .Pp | ||
100 | The | ||
101 | .Fn realloc | ||
102 | function changes the size of the object pointed to by | ||
103 | .Fa ptr | ||
104 | to the size specified by | ||
105 | .Fa size . | ||
106 | The contents of the object are unchanged up to the lesser | ||
107 | of the new and old sizes. | ||
108 | If the new size is larger, the value of the newly allocated portion | ||
109 | of the object is indeterminate and uninitialized. | ||
110 | If | ||
111 | .Fa ptr | ||
112 | is a null pointer, the | ||
113 | .Fn realloc | ||
114 | function behaves like the | ||
115 | .Fn malloc | ||
116 | function for the specified size. | ||
117 | If the space cannot be allocated, the object | ||
118 | pointed to by | ||
119 | .Fa ptr | ||
120 | is unchanged. | ||
121 | If | ||
122 | .Fa size | ||
123 | is zero and | ||
124 | .Fa ptr | ||
125 | is not a null pointer, the object it points to is freed and a new zero size | ||
126 | object is returned. | ||
127 | .Pp | ||
128 | When using | ||
129 | .Fn realloc | ||
130 | one must be careful to avoid the following idiom: | ||
131 | .Pp | ||
132 | .Bd -literal -offset indent | ||
133 | if ((p = realloc(p, nsize)) == NULL) | ||
134 | return NULL; | ||
135 | .Ed | ||
136 | .Pp | ||
137 | In most cases, this will result in a leak of memory. | ||
138 | As stated earlier, a return value of | ||
139 | .Fa NULL | ||
140 | indicates that the old object still remains allocated. | ||
141 | Better code looks like this: | ||
142 | .Bd -literal -offset indent | ||
143 | if ((p2 = realloc(p, nsize)) == NULL) { | ||
144 | if (p) | ||
145 | free(p); | ||
146 | p = NULL; | ||
147 | return NULL; | ||
148 | } | ||
149 | p = p2; | ||
150 | .Ed | ||
151 | .Pp | ||
152 | Malloc will first look for a symbolic link called | ||
153 | .Pa /etc/malloc.conf | ||
154 | and next check the environment for a variable called | ||
155 | .Ev MALLOC_OPTIONS | ||
156 | and finally for the global variable | ||
157 | .Va malloc_options | ||
158 | and scan them for flags in that order. | ||
159 | Flags are single letters, uppercase means on, lowercase means off. | ||
160 | .Bl -tag -width indent | ||
161 | .It A | ||
162 | ``abort'' malloc will coredump the process, rather than tolerate failure. | ||
163 | This is a very handy debugging aid, since the core file will represent the | ||
164 | time of failure, | ||
165 | rather than when the NULL pointer was accessed. | ||
166 | |||
167 | .It D | ||
168 | ``dump'' malloc will dump statistics in a file called ``malloc.out'' at exit. | ||
169 | This option requires the library to have been compiled with -DMALLOC_STATS in | ||
170 | order to have any effect. | ||
171 | |||
172 | .It J | ||
173 | ``junk'' fill some junk into the area allocated. | ||
174 | Currently junk is bytes of 0xd0, this is pronounced ``Duh'' :-) | ||
175 | |||
176 | .It H | ||
177 | ``hint'' pass a hint to the kernel about pages we don't use. If the | ||
178 | machine is paging a lot this may help a bit. | ||
179 | |||
180 | .It N | ||
181 | Do not output warning messages when encountering possible corruption | ||
182 | or bad pointers. | ||
183 | |||
184 | .It R | ||
185 | ``realloc'' always reallocate when | ||
186 | .Fn realloc | ||
187 | is called, even if the initial allocation was big enough. | ||
188 | This can substantially aid in compacting memory. | ||
189 | |||
190 | .It U | ||
191 | ``utrace'' generate entries for | ||
192 | .Xr ktrace 1 | ||
193 | for all operations. | ||
194 | Consult the source for this one. | ||
195 | |||
196 | .It X | ||
197 | ``xmalloc'' | ||
198 | rather than return failure, | ||
199 | .Xr abort 3 | ||
200 | the program with a diagnostic message on stderr. | ||
201 | It is the intention that this option be set at compile time by | ||
202 | including in the source: | ||
203 | .Bd -literal -offset indent | ||
204 | extern char *malloc_options; | ||
205 | malloc_options = "X"; | ||
206 | .Ed | ||
207 | |||
208 | .It Z | ||
209 | ``zero'' fill some junk into the area allocated (see ``J''), | ||
210 | except for the exact length the user asked for, which is zeroed. | ||
211 | |||
212 | .It < | ||
213 | ``Half the cache size'' Reduce the size of the cache by a factor of two. | ||
214 | |||
215 | .It > | ||
216 | ``Double the cache size'' Double the size of the cache by a factor of two. | ||
217 | .El | ||
218 | .Pp | ||
219 | So to set a systemwide reduction of cache size and coredumps on problems | ||
220 | one would: | ||
221 | .Li ln -s 'A<' /etc/malloc.conf | ||
222 | .Pp | ||
223 | The ``J'' and ``Z'' is mostly for testing and debugging, | ||
224 | if a program changes behavior if either of these options are used, | ||
225 | it is buggy. | ||
226 | .Pp | ||
227 | The default cache size is 16 pages. | ||
228 | .Sh ENVIRONMENT | ||
229 | See above. | ||
65 | .Sh RETURN VALUES | 230 | .Sh RETURN VALUES |
66 | The | 231 | The |
67 | .Fn malloc | 232 | .Fn malloc |
68 | function returns | 233 | function returns |
69 | a pointer to the allocated space if successful; otherwise | 234 | a pointer to the allocated space if successful; otherwise |
70 | a null pointer is returned. | 235 | a null pointer is returned. |
236 | .Pp | ||
237 | The | ||
238 | .Fn free | ||
239 | function returns no value. | ||
240 | .Pp | ||
241 | The | ||
242 | .Fn realloc | ||
243 | function a pointer to the possibly moved allocated space; | ||
244 | otherwise a null pointer is returned. | ||
245 | .Sh MESSAGES | ||
246 | If | ||
247 | .Fn malloc , | ||
248 | .Fn free | ||
249 | or | ||
250 | .Fn realloc | ||
251 | detects an error or warning condition, | ||
252 | a message will be printed to filedescriptor | ||
253 | 2 (not using stdio). | ||
254 | Errors will always result in the process being | ||
255 | .Xr abort 2 'ed, | ||
256 | If the ``A'' option has been specified, also warnings will | ||
257 | .Xr abort 2 | ||
258 | the process. | ||
259 | .Pp | ||
260 | Here is a brief description of the error messages and what they mean: | ||
261 | .Pp | ||
262 | ``(ES): mumble mumble mumble'': | ||
263 | malloc have been compiled with -DEXTRA_SANITY and something looks | ||
264 | fishy in there. Consult sources and or wizards. | ||
265 | .Pp | ||
266 | ``allocation failed'' | ||
267 | if the ``A'' option is specified it is an error for | ||
268 | .Fn malloc | ||
269 | or | ||
270 | .Fn realloc | ||
271 | to return NULL. | ||
272 | .Pp | ||
273 | ``mmap(2) failed, check limits.'' | ||
274 | This is a rather weird condition that is most likely to mean that | ||
275 | the system is seriously overloaded or that your ulimits are sick. | ||
276 | .Pp | ||
277 | ``freelist is destroyed.'' | ||
278 | mallocs internal freelist has been stomped on. | ||
279 | .Pp | ||
280 | Here is a brief description of the warning messages and what they mean: | ||
281 | .Pp | ||
282 | ``chunk/page is already free.'' | ||
283 | A pointer to a free chunk is attempted freed again. | ||
284 | .Pp | ||
285 | ``junk pointer, too high to make sense.'' | ||
286 | The pointer doesn't make sense. It's above the area of memory that | ||
287 | malloc knows something about. | ||
288 | This could be a pointer from some | ||
289 | .Xr mmap 2 'ed | ||
290 | memory. | ||
291 | .Pp | ||
292 | ``junk pointer, too low to make sense.'' | ||
293 | The pointer doesn't make sense. It's below the area of memory that | ||
294 | malloc knows something about. | ||
295 | This pointer probably came from your data or bss segments. | ||
296 | .Pp | ||
297 | ``malloc() has never been called.'' | ||
298 | Nothing has ever been allocated, yet something is being freed or | ||
299 | realloc'ed. | ||
300 | .Pp | ||
301 | ``modified (chunk-/page-) pointer.'' | ||
302 | The pointer passed to free or realloc has been modified. | ||
303 | .Pp | ||
304 | ``pointer to wrong page.'' | ||
305 | The pointer that malloc is trying to free is not pointing to | ||
306 | a sensible page. | ||
307 | .Pp | ||
308 | ``recursive call.'' | ||
309 | You have tried to call recursively into these functions. | ||
310 | I can only imagine this as happening if you call one of these | ||
311 | functions from a signal function, which happens to be called | ||
312 | while you're already in here. | ||
313 | Well, sorry to say: that's not supported. | ||
314 | If this is a problem for you I'd like to hear about it. It | ||
315 | would be possible to add a sigblock() around this package, | ||
316 | but it would have a performance penalty that is not acceptable | ||
317 | as the default. | ||
318 | .Pp | ||
319 | ``unknown char in MALLOC_OPTIONS'' | ||
320 | we found something we didn't understand. | ||
71 | .Sh SEE ALSO | 321 | .Sh SEE ALSO |
72 | .Xr brk 2 , | 322 | .Xr brk 2 , |
73 | .Xr getpagesize 2 , | ||
74 | .Xr free 3 , | ||
75 | .Xr calloc 3 , | ||
76 | .Xr alloca 3 , | 323 | .Xr alloca 3 , |
77 | .Xr realloc 3 , | 324 | .Xr calloc 3 , |
325 | .Xr getpagesize 3 , | ||
78 | .Xr memory 3 | 326 | .Xr memory 3 |
327 | .Pa /usr/share/doc/papers/malloc.ascii.gz | ||
79 | .Sh STANDARDS | 328 | .Sh STANDARDS |
80 | The | 329 | The |
81 | .Fn malloc | 330 | .Fn malloc |
82 | function conforms to | 331 | function conforms to |
83 | .St -ansiC . | 332 | .St -ansiC . |
84 | .Sh BUGS | 333 | .Sh HISTORY |
85 | The current implementation of | 334 | The present implementation of malloc started out as a filesystem on a drum |
86 | .Xr malloc | 335 | attached to a 20bit binary challenged computer built with discrete germanium |
87 | does not always fail gracefully when system | 336 | transistors, and it has since graduated to handle primary storage rather than |
88 | memory limits are approached. | 337 | secondary. |
89 | It may fail to allocate memory when larger free blocks could be broken | 338 | .Pp |
90 | up, or when limits are exceeded because the size is rounded up. | 339 | The main difference from other malloc implementations are believed to be that |
91 | It is optimized for sizes that are powers of two. | 340 | the free pages are not accessed until allocated. |
341 | Most malloc implementations will store a data structure containing a, | ||
342 | possibly double-, linked list in the free chunks of memory, used to tie | ||
343 | all the free memory together. | ||
344 | That is a quite suboptimal thing to do. | ||
345 | Every time the free-list is traversed, all the otherwise unused, and very | ||
346 | likely paged out, pages get faulted into primary memory, just to see what | ||
347 | lies after them in the list. | ||
348 | .Pp | ||
349 | On systems which are paging, this can make a factor five in difference on the | ||
350 | page-faults of a process. | ||
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 3c57fad024..d1d8759791 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
@@ -1,421 +1,1242 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | 2 | * ---------------------------------------------------------------------------- |
3 | * All rights reserved. | 3 | * "THE BEER-WARE LICENSE" (Revision 42): |
4 | * | 4 | * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * can do whatever you want with this stuff. If we meet some day, and you think |
6 | * modification, are permitted provided that the following conditions | 6 | * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp |
7 | * are met: | 7 | * ---------------------------------------------------------------------------- |
8 | * 1. Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * 2. Redistributions in binary form must reproduce the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer in the | ||
12 | * documentation and/or other materials provided with the distribution. | ||
13 | * 3. All advertising materials mentioning features or use of this software | ||
14 | * must display the following acknowledgement: | ||
15 | * This product includes software developed by the University of | ||
16 | * California, Berkeley and its contributors. | ||
17 | * 4. Neither the name of the University nor the names of its contributors | ||
18 | * may be used to endorse or promote products derived from this software | ||
19 | * without specific prior written permission. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
31 | * SUCH DAMAGE. | ||
32 | */ | 8 | */ |
33 | 9 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 10 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)malloc.c 5.11 (Berkeley) 2/23/91";*/ | 11 | static char rcsid[] = "$OpenBSD: malloc.c,v 1.32 1998/08/06 16:26:32 millert Exp $"; |
36 | static char *rcsid = "$Id: malloc.c,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 12 | #endif /* LIBC_SCCS and not lint */ |
38 | 13 | ||
39 | /* | 14 | /* |
40 | * malloc.c (Caltech) 2/21/82 | 15 | * Defining MALLOC_EXTRA_SANITY will enable extra checks which are |
41 | * Chris Kingsley, kingsley@cit-20. | 16 | * related to internal conditions and consistency in malloc.c. This has |
42 | * | 17 | * a noticeable runtime performance hit, and generally will not do you |
43 | * This is a very fast storage allocator. It allocates blocks of a small | 18 | * any good unless you fiddle with the internals of malloc or want |
44 | * number of different sizes, and keeps free lists of each size. Blocks that | 19 | * to catch random pointer corruption as early as possible. |
45 | * don't exactly fit are passed up to the next larger size. In this | ||
46 | * implementation, the available sizes are 2^n-4 (or 2^n-10) bytes long. | ||
47 | * This is designed for use in a virtual memory environment. | ||
48 | */ | 20 | */ |
21 | #ifndef MALLOC_EXTRA_SANITY | ||
22 | #undef MALLOC_EXTRA_SANITY | ||
23 | #endif | ||
49 | 24 | ||
50 | #include <sys/types.h> | 25 | /* |
26 | * Defining MALLOC_STATS will enable you to call malloc_dump() and set | ||
27 | * the [dD] options in the MALLOC_OPTIONS environment variable. | ||
28 | * It has no run-time performance hit, but does pull in stdio... | ||
29 | */ | ||
30 | #ifndef MALLOC_STATS | ||
31 | #undef MALLOC_STATS | ||
32 | #endif | ||
33 | |||
34 | /* | ||
35 | * What to use for Junk. This is the byte value we use to fill with | ||
36 | * when the 'J' option is enabled. | ||
37 | */ | ||
38 | #define SOME_JUNK 0xd0 /* as in "Duh" :-) */ | ||
39 | |||
40 | #include <stdio.h> | ||
51 | #include <stdlib.h> | 41 | #include <stdlib.h> |
52 | #include <string.h> | 42 | #include <string.h> |
53 | #include <unistd.h> | 43 | #include <unistd.h> |
44 | #include <fcntl.h> | ||
45 | #include <errno.h> | ||
46 | #include <sys/types.h> | ||
47 | #include <sys/param.h> | ||
48 | #include <sys/mman.h> | ||
49 | |||
50 | /* | ||
51 | * The basic parameters you can tweak. | ||
52 | * | ||
53 | * malloc_pageshift pagesize = 1 << malloc_pageshift | ||
54 | * It's probably best if this is the native | ||
55 | * page size, but it shouldn't have to be. | ||
56 | * | ||
57 | * malloc_minsize minimum size of an allocation in bytes. | ||
58 | * If this is too small it's too much work | ||
59 | * to manage them. This is also the smallest | ||
60 | * unit of alignment used for the storage | ||
61 | * returned by malloc/realloc. | ||
62 | * | ||
63 | */ | ||
64 | |||
65 | #if defined(__i386__) && defined(__FreeBSD__) | ||
66 | # define malloc_pageshift 12U | ||
67 | # define malloc_minsize 16U | ||
68 | #endif /* __i386__ && __FreeBSD__ */ | ||
54 | 69 | ||
55 | #define NULL 0 | 70 | #if defined(__sparc__) && !defined(__OpenBSD__) |
71 | # define malloc_pageshirt 12U | ||
72 | # define malloc_minsize 16U | ||
73 | # define MAP_ANON (0) | ||
74 | # define USE_DEV_ZERO | ||
75 | # define MADV_FREE MADV_DONTNEED | ||
76 | #endif /* __sparc__ */ | ||
56 | 77 | ||
57 | static void morecore(); | 78 | /* Insert your combination here... */ |
58 | static int findbucket(); | 79 | #if defined(__FOOCPU__) && defined(__BAROS__) |
80 | # define malloc_pageshift 12U | ||
81 | # define malloc_minsize 16U | ||
82 | #endif /* __FOOCPU__ && __BAROS__ */ | ||
83 | |||
84 | #if defined(__OpenBSD__) && !defined(__sparc__) | ||
85 | # define malloc_pageshift (PGSHIFT) | ||
86 | # define malloc_minsize 16U | ||
87 | #endif /* __OpenBSD__ */ | ||
88 | |||
89 | #ifdef _THREAD_SAFE | ||
90 | #include <pthread.h> | ||
91 | static pthread_mutex_t malloc_lock; | ||
92 | #define THREAD_LOCK() pthread_mutex_lock(&malloc_lock) | ||
93 | #define THREAD_UNLOCK() pthread_mutex_unlock(&malloc_lock) | ||
94 | #define THREAD_LOCK_INIT() pthread_mutex_init(&malloc_lock, 0); | ||
95 | #else | ||
96 | #define THREAD_LOCK() | ||
97 | #define THREAD_UNLOCK() | ||
98 | #define THREAD_LOCK_INIT() | ||
99 | #endif | ||
59 | 100 | ||
60 | /* | 101 | /* |
61 | * The overhead on a block is at least 4 bytes. When free, this space | 102 | * No user serviceable parts behind this point. |
62 | * contains a pointer to the next free block, and the bottom two bits must | 103 | * |
63 | * be zero. When in use, the first byte is set to MAGIC, and the second | 104 | * This structure describes a page worth of chunks. |
64 | * byte is the size index. The remaining bytes are for alignment. | ||
65 | * If range checking is enabled then a second word holds the size of the | ||
66 | * requested block, less 1, rounded up to a multiple of sizeof(RMAGIC). | ||
67 | * The order of elements is critical: ov_magic must overlay the low order | ||
68 | * bits of ov_next, and ov_magic can not be a valid ov_next bit pattern. | ||
69 | */ | 105 | */ |
70 | union overhead { | 106 | |
71 | union overhead *ov_next; /* when free */ | 107 | struct pginfo { |
72 | struct { | 108 | struct pginfo *next; /* next on the free list */ |
73 | u_char ovu_magic; /* magic number */ | 109 | void *page; /* Pointer to the page */ |
74 | u_char ovu_index; /* bucket # */ | 110 | u_short size; /* size of this page's chunks */ |
75 | #ifdef RCHECK | 111 | u_short shift; /* How far to shift for this size chunks */ |
76 | u_short ovu_rmagic; /* range magic number */ | 112 | u_short free; /* How many free chunks */ |
77 | u_long ovu_size; /* actual block size */ | 113 | u_short total; /* How many chunk */ |
78 | #endif | 114 | u_long bits[1]; /* Which chunks are free */ |
79 | } ovu; | 115 | }; |
80 | #define ov_magic ovu.ovu_magic | 116 | |
81 | #define ov_index ovu.ovu_index | 117 | /* |
82 | #define ov_rmagic ovu.ovu_rmagic | 118 | * This structure describes a number of free pages. |
83 | #define ov_size ovu.ovu_size | 119 | */ |
120 | |||
121 | struct pgfree { | ||
122 | struct pgfree *next; /* next run of free pages */ | ||
123 | struct pgfree *prev; /* prev run of free pages */ | ||
124 | void *page; /* pointer to free pages */ | ||
125 | void *end; /* pointer to end of free pages */ | ||
126 | u_long size; /* number of bytes free */ | ||
84 | }; | 127 | }; |
85 | 128 | ||
86 | #define MAGIC 0xef /* magic # on accounting info */ | 129 | /* |
87 | #define RMAGIC 0x5555 /* magic # on range info */ | 130 | * How many bits per u_long in the bitmap. |
131 | * Change only if not 8 bits/byte | ||
132 | */ | ||
133 | #define MALLOC_BITS (8*sizeof(u_long)) | ||
134 | |||
135 | /* | ||
136 | * Magic values to put in the page_directory | ||
137 | */ | ||
138 | #define MALLOC_NOT_MINE ((struct pginfo*) 0) | ||
139 | #define MALLOC_FREE ((struct pginfo*) 1) | ||
140 | #define MALLOC_FIRST ((struct pginfo*) 2) | ||
141 | #define MALLOC_FOLLOW ((struct pginfo*) 3) | ||
142 | #define MALLOC_MAGIC ((struct pginfo*) 4) | ||
143 | |||
144 | #ifndef malloc_pageshift | ||
145 | #define malloc_pageshift 12U | ||
146 | #endif | ||
147 | |||
148 | #ifndef malloc_minsize | ||
149 | #define malloc_minsize 16U | ||
150 | #endif | ||
151 | |||
152 | #ifndef malloc_pageshift | ||
153 | #error "malloc_pageshift undefined" | ||
154 | #endif | ||
155 | |||
156 | #if !defined(malloc_pagesize) | ||
157 | #define malloc_pagesize (1UL<<malloc_pageshift) | ||
158 | #endif | ||
159 | |||
160 | #if ((1UL<<malloc_pageshift) != malloc_pagesize) | ||
161 | #error "(1UL<<malloc_pageshift) != malloc_pagesize" | ||
162 | #endif | ||
163 | |||
164 | #ifndef malloc_maxsize | ||
165 | #define malloc_maxsize ((malloc_pagesize)>>1) | ||
166 | #endif | ||
167 | |||
168 | /* A mask for the offset inside a page. */ | ||
169 | #define malloc_pagemask ((malloc_pagesize)-1) | ||
170 | |||
171 | #define pageround(foo) (((foo) + (malloc_pagemask))&(~(malloc_pagemask))) | ||
172 | #define ptr2index(foo) (((u_long)(foo) >> malloc_pageshift)-malloc_origo) | ||
88 | 173 | ||
89 | #ifdef RCHECK | 174 | /* fd of /dev/zero */ |
90 | #define RSLOP sizeof (u_short) | 175 | #ifdef USE_DEV_ZERO |
176 | static int fdzero; | ||
177 | #define MMAP_FD fdzero | ||
178 | #define INIT_MMAP() \ | ||
179 | { if ((fdzero=open("/dev/zero", O_RDWR, 0000)) == -1) \ | ||
180 | wrterror("open of /dev/zero"); } | ||
91 | #else | 181 | #else |
92 | #define RSLOP 0 | 182 | #define MMAP_FD (-1) |
183 | #define INIT_MMAP() | ||
93 | #endif | 184 | #endif |
94 | 185 | ||
186 | /* Set when initialization has been done */ | ||
187 | static unsigned malloc_started; | ||
188 | |||
189 | /* Number of free pages we cache */ | ||
190 | static unsigned malloc_cache = 16; | ||
191 | |||
192 | /* The offset from pagenumber to index into the page directory */ | ||
193 | static u_long malloc_origo; | ||
194 | |||
195 | /* The last index in the page directory we care about */ | ||
196 | static u_long last_index; | ||
197 | |||
198 | /* Pointer to page directory. Allocated "as if with" malloc */ | ||
199 | static struct pginfo **page_dir; | ||
200 | |||
201 | /* How many slots in the page directory */ | ||
202 | static size_t malloc_ninfo; | ||
203 | |||
204 | /* Free pages line up here */ | ||
205 | static struct pgfree free_list; | ||
206 | |||
207 | /* Abort(), user doesn't handle problems. */ | ||
208 | static int malloc_abort; | ||
209 | |||
210 | /* Are we trying to die ? */ | ||
211 | static int suicide; | ||
212 | |||
213 | #ifdef MALLOC_STATS | ||
214 | /* dump statistics */ | ||
215 | static int malloc_stats; | ||
216 | #endif | ||
217 | |||
218 | /* avoid outputting warnings? */ | ||
219 | static int malloc_silent; | ||
220 | |||
221 | /* always realloc ? */ | ||
222 | static int malloc_realloc; | ||
223 | |||
224 | #ifdef __FreeBSD__ | ||
225 | /* pass the kernel a hint on free pages ? */ | ||
226 | static int malloc_hint; | ||
227 | #endif | ||
228 | |||
229 | /* xmalloc behaviour ? */ | ||
230 | static int malloc_xmalloc; | ||
231 | |||
232 | /* zero fill ? */ | ||
233 | static int malloc_zero; | ||
234 | |||
235 | /* junk fill ? */ | ||
236 | static int malloc_junk; | ||
237 | |||
238 | #ifdef __FreeBSD__ | ||
239 | /* utrace ? */ | ||
240 | static int malloc_utrace; | ||
241 | |||
242 | struct ut { void *p; size_t s; void *r; }; | ||
243 | |||
244 | void utrace __P((struct ut *, int)); | ||
245 | |||
246 | #define UTRACE(a, b, c) \ | ||
247 | if (malloc_utrace) \ | ||
248 | {struct ut u; u.p=a; u.s = b; u.r=c; utrace(&u, sizeof u);} | ||
249 | #else /* !__FreeBSD__ */ | ||
250 | #define UTRACE(a,b,c) | ||
251 | #endif | ||
252 | |||
253 | /* my last break. */ | ||
254 | static void *malloc_brk; | ||
255 | |||
256 | /* one location cache for free-list holders */ | ||
257 | static struct pgfree *px; | ||
258 | |||
259 | /* compile-time options */ | ||
260 | char *malloc_options; | ||
261 | |||
262 | /* Name of the current public function */ | ||
263 | static char *malloc_func; | ||
264 | |||
265 | /* Macro for mmap */ | ||
266 | #define MMAP(size) \ | ||
267 | mmap((void *)0, (size), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, \ | ||
268 | MMAP_FD, (off_t)0); | ||
269 | |||
95 | /* | 270 | /* |
96 | * nextf[i] is the pointer to the next free block of size 2^(i+3). The | 271 | * Necessary function declarations |
97 | * smallest allocatable block is 8 bytes. The overhead information | ||
98 | * precedes the data area returned to the user. | ||
99 | */ | 272 | */ |
100 | #define NBUCKETS 30 | 273 | static int extend_pgdir(u_long index); |
101 | static union overhead *nextf[NBUCKETS]; | 274 | static void *imalloc(size_t size); |
102 | extern char *sbrk(); | 275 | static void ifree(void *ptr); |
276 | static void *irealloc(void *ptr, size_t size); | ||
277 | static void *malloc_bytes(size_t size); | ||
278 | |||
279 | #ifdef MALLOC_STATS | ||
280 | void | ||
281 | malloc_dump(fd) | ||
282 | FILE *fd; | ||
283 | { | ||
284 | struct pginfo **pd; | ||
285 | struct pgfree *pf; | ||
286 | int j; | ||
287 | |||
288 | pd = page_dir; | ||
289 | |||
290 | /* print out all the pages */ | ||
291 | for(j=0;j<=last_index;j++) { | ||
292 | fprintf(fd, "%08lx %5d ", (j+malloc_origo) << malloc_pageshift, j); | ||
293 | if (pd[j] == MALLOC_NOT_MINE) { | ||
294 | for(j++;j<=last_index && pd[j] == MALLOC_NOT_MINE;j++) | ||
295 | ; | ||
296 | j--; | ||
297 | fprintf(fd, ".. %5d not mine\n", j); | ||
298 | } else if (pd[j] == MALLOC_FREE) { | ||
299 | for(j++;j<=last_index && pd[j] == MALLOC_FREE;j++) | ||
300 | ; | ||
301 | j--; | ||
302 | fprintf(fd, ".. %5d free\n", j); | ||
303 | } else if (pd[j] == MALLOC_FIRST) { | ||
304 | for(j++;j<=last_index && pd[j] == MALLOC_FOLLOW;j++) | ||
305 | ; | ||
306 | j--; | ||
307 | fprintf(fd, ".. %5d in use\n", j); | ||
308 | } else if (pd[j] < MALLOC_MAGIC) { | ||
309 | fprintf(fd, "(%p)\n", pd[j]); | ||
310 | } else { | ||
311 | fprintf(fd, "%p %d (of %d) x %d @ %p --> %p\n", | ||
312 | pd[j], pd[j]->free, pd[j]->total, | ||
313 | pd[j]->size, pd[j]->page, pd[j]->next); | ||
314 | } | ||
315 | } | ||
316 | |||
317 | for(pf=free_list.next; pf; pf=pf->next) { | ||
318 | fprintf(fd, "Free: @%p [%p...%p[ %ld ->%p <-%p\n", | ||
319 | pf, pf->page, pf->end, pf->size, pf->prev, pf->next); | ||
320 | if (pf == pf->next) { | ||
321 | fprintf(fd, "Free_list loops.\n"); | ||
322 | break; | ||
323 | } | ||
324 | } | ||
325 | |||
326 | /* print out various info */ | ||
327 | fprintf(fd, "Minsize\t%d\n", malloc_minsize); | ||
328 | fprintf(fd, "Maxsize\t%d\n", malloc_maxsize); | ||
329 | fprintf(fd, "Pagesize\t%lu\n", (u_long)malloc_pagesize); | ||
330 | fprintf(fd, "Pageshift\t%d\n", malloc_pageshift); | ||
331 | fprintf(fd, "FirstPage\t%ld\n", malloc_origo); | ||
332 | fprintf(fd, "LastPage\t%ld %lx\n", last_index+malloc_pageshift, | ||
333 | (last_index + malloc_pageshift) << malloc_pageshift); | ||
334 | fprintf(fd, "Break\t%ld\n", (u_long)sbrk(0) >> malloc_pageshift); | ||
335 | } | ||
336 | #endif /* MALLOC_STATS */ | ||
337 | |||
338 | extern char *__progname; | ||
339 | |||
340 | static void | ||
341 | wrterror(p) | ||
342 | char *p; | ||
343 | { | ||
344 | char *q = " error: "; | ||
345 | write(2, __progname, strlen(__progname)); | ||
346 | write(2, malloc_func, strlen(malloc_func)); | ||
347 | write(2, q, strlen(q)); | ||
348 | write(2, p, strlen(p)); | ||
349 | suicide = 1; | ||
350 | #ifdef MALLOC_STATS | ||
351 | if (malloc_stats) | ||
352 | malloc_dump(stderr); | ||
353 | #endif /* MALLOC_STATS */ | ||
354 | abort(); | ||
355 | } | ||
356 | |||
357 | static void | ||
358 | wrtwarning(p) | ||
359 | char *p; | ||
360 | { | ||
361 | char *q = " warning: "; | ||
362 | if (malloc_abort) | ||
363 | wrterror(p); | ||
364 | else if (malloc_silent) | ||
365 | return; | ||
366 | write(2, __progname, strlen(__progname)); | ||
367 | write(2, malloc_func, strlen(malloc_func)); | ||
368 | write(2, q, strlen(q)); | ||
369 | write(2, p, strlen(p)); | ||
370 | } | ||
371 | |||
372 | #ifdef MALLOC_STATS | ||
373 | static void | ||
374 | malloc_exit() | ||
375 | { | ||
376 | FILE *fd = fopen("malloc.out", "a"); | ||
377 | char *q = "malloc() warning: Couldn't dump stats.\n"; | ||
378 | if (fd) { | ||
379 | malloc_dump(fd); | ||
380 | fclose(fd); | ||
381 | } else | ||
382 | write(2, q, strlen(q)); | ||
383 | } | ||
384 | #endif /* MALLOC_STATS */ | ||
103 | 385 | ||
104 | static int pagesz; /* page size */ | ||
105 | static int pagebucket; /* page size bucket */ | ||
106 | 386 | ||
107 | #ifdef MSTATS | ||
108 | /* | 387 | /* |
109 | * nmalloc[i] is the difference between the number of mallocs and frees | 388 | * Allocate a number of pages from the OS |
110 | * for a given block size. | ||
111 | */ | 389 | */ |
112 | static u_int nmalloc[NBUCKETS]; | 390 | static void * |
113 | #include <stdio.h> | 391 | map_pages(pages) |
114 | #endif | 392 | int pages; |
393 | { | ||
394 | caddr_t result, tail; | ||
115 | 395 | ||
116 | #if defined(DEBUG) || defined(RCHECK) | 396 | result = (caddr_t)pageround((u_long)sbrk(0)); |
117 | #define ASSERT(p) if (!(p)) botch("p") | 397 | tail = result + (pages << malloc_pageshift); |
118 | #include <stdio.h> | 398 | |
119 | static | 399 | if (brk(tail)) { |
120 | botch(s) | 400 | #ifdef MALLOC_EXTRA_SANITY |
121 | char *s; | 401 | wrterror("(ES): map_pages fails\n"); |
402 | #endif /* MALLOC_EXTRA_SANITY */ | ||
403 | return 0; | ||
404 | } | ||
405 | |||
406 | last_index = ptr2index(tail) - 1; | ||
407 | malloc_brk = tail; | ||
408 | |||
409 | if ((last_index+1) >= malloc_ninfo && !extend_pgdir(last_index)) | ||
410 | return 0; | ||
411 | |||
412 | return result; | ||
413 | } | ||
414 | |||
415 | /* | ||
416 | * Extend page directory | ||
417 | */ | ||
418 | static int | ||
419 | extend_pgdir(index) | ||
420 | u_long index; | ||
122 | { | 421 | { |
123 | fprintf(stderr, "\r\nassertion botched: %s\r\n", s); | 422 | struct pginfo **new, **old; |
124 | (void) fflush(stderr); /* just in case user buffered it */ | 423 | size_t i, oldlen; |
125 | abort(); | 424 | |
425 | /* Make it this many pages */ | ||
426 | i = index * sizeof *page_dir; | ||
427 | i /= malloc_pagesize; | ||
428 | i += 2; | ||
429 | |||
430 | /* remember the old mapping size */ | ||
431 | oldlen = malloc_ninfo * sizeof *page_dir; | ||
432 | |||
433 | /* | ||
434 | * NOTE: we allocate new pages and copy the directory rather than tempt | ||
435 | * fate by trying to "grow" the region.. There is nothing to prevent | ||
436 | * us from accidently re-mapping space that's been allocated by our caller | ||
437 | * via dlopen() or other mmap(). | ||
438 | * | ||
439 | * The copy problem is not too bad, as there is 4K of page index per | ||
440 | * 4MB of malloc arena. | ||
441 | * | ||
442 | * We can totally avoid the copy if we open a file descriptor to associate | ||
443 | * the anon mappings with. Then, when we remap the pages at the new | ||
444 | * address, the old pages will be "magically" remapped.. But this means | ||
445 | * keeping open a "secret" file descriptor..... | ||
446 | */ | ||
447 | |||
448 | /* Get new pages */ | ||
449 | new = (struct pginfo**) MMAP(i * malloc_pagesize); | ||
450 | if (new == (struct pginfo **)-1) | ||
451 | return 0; | ||
452 | |||
453 | /* Copy the old stuff */ | ||
454 | memcpy(new, page_dir, | ||
455 | malloc_ninfo * sizeof *page_dir); | ||
456 | |||
457 | /* register the new size */ | ||
458 | malloc_ninfo = i * malloc_pagesize / sizeof *page_dir; | ||
459 | |||
460 | /* swap the pointers */ | ||
461 | old = page_dir; | ||
462 | page_dir = new; | ||
463 | |||
464 | /* Now free the old stuff */ | ||
465 | munmap(old, oldlen); | ||
466 | return 1; | ||
126 | } | 467 | } |
127 | #else | ||
128 | #define ASSERT(p) | ||
129 | #endif | ||
130 | 468 | ||
131 | void * | 469 | /* |
132 | malloc(nbytes) | 470 | * Initialize the world |
133 | size_t nbytes; | 471 | */ |
472 | static void | ||
473 | malloc_init () | ||
134 | { | 474 | { |
135 | register union overhead *op; | 475 | char *p, b[64]; |
136 | register long bucket, n; | 476 | int i, j; |
137 | register unsigned amt; | 477 | int save_errno = errno; |
138 | 478 | ||
139 | /* | 479 | THREAD_LOCK_INIT(); |
140 | * First time malloc is called, setup page size and | 480 | |
141 | * align break pointer so all data will be page aligned. | 481 | INIT_MMAP(); |
142 | */ | 482 | |
143 | if (pagesz == 0) { | 483 | #ifdef MALLOC_EXTRA_SANITY |
144 | pagesz = n = getpagesize(); | 484 | malloc_junk = 1; |
145 | op = (union overhead *)sbrk(0); | 485 | #endif /* MALLOC_EXTRA_SANITY */ |
146 | n = n - sizeof (*op) - ((long)op & (n - 1)); | 486 | |
147 | if (n < 0) | 487 | for (i = 0; i < 3; i++) { |
148 | n += pagesz; | 488 | if (i == 0) { |
149 | if (n) { | 489 | j = readlink("/etc/malloc.conf", b, sizeof b - 1); |
150 | if (sbrk(n) == (char *)-1) | 490 | if (j <= 0) |
151 | return (NULL); | 491 | continue; |
152 | } | 492 | b[j] = '\0'; |
153 | bucket = 0; | 493 | p = b; |
154 | amt = 8; | 494 | } else if (i == 1) { |
155 | while (pagesz > amt) { | 495 | if (issetugid() == 0) |
156 | amt <<= 1; | 496 | p = getenv("MALLOC_OPTIONS"); |
157 | bucket++; | 497 | else |
158 | } | 498 | continue; |
159 | pagebucket = bucket; | 499 | } else if (i == 2) { |
500 | p = malloc_options; | ||
160 | } | 501 | } |
161 | /* | 502 | for (; p && *p; p++) { |
162 | * Convert amount of memory requested into closest block size | 503 | switch (*p) { |
163 | * stored in hash buckets which satisfies request. | 504 | case '>': malloc_cache <<= 1; break; |
164 | * Account for space used per block for accounting. | 505 | case '<': malloc_cache >>= 1; break; |
165 | */ | 506 | case 'a': malloc_abort = 0; break; |
166 | if (nbytes <= (n = pagesz - sizeof (*op) - RSLOP)) { | 507 | case 'A': malloc_abort = 1; break; |
167 | #ifndef RCHECK | 508 | #ifdef MALLOC_STATS |
168 | amt = 8; /* size of first bucket */ | 509 | case 'd': malloc_stats = 0; break; |
169 | bucket = 0; | 510 | case 'D': malloc_stats = 1; break; |
170 | #else | 511 | #endif /* MALLOC_STATS */ |
171 | amt = 16; /* size of first bucket */ | 512 | #ifdef __FreeBSD__ |
172 | bucket = 1; | 513 | case 'h': malloc_hint = 0; break; |
173 | #endif | 514 | case 'H': malloc_hint = 1; break; |
174 | n = -((long)sizeof (*op) + RSLOP); | 515 | #endif /* __FreeBSD__ */ |
175 | } else { | 516 | case 'r': malloc_realloc = 0; break; |
176 | amt = pagesz; | 517 | case 'R': malloc_realloc = 1; break; |
177 | bucket = pagebucket; | 518 | case 'j': malloc_junk = 0; break; |
519 | case 'J': malloc_junk = 1; break; | ||
520 | case 'n': malloc_silent = 0; break; | ||
521 | case 'N': malloc_silent = 1; break; | ||
522 | #ifdef __FreeBSD__ | ||
523 | case 'u': malloc_utrace = 0; break; | ||
524 | case 'U': malloc_utrace = 1; break; | ||
525 | #endif /* __FreeBSD__ */ | ||
526 | case 'x': malloc_xmalloc = 0; break; | ||
527 | case 'X': malloc_xmalloc = 1; break; | ||
528 | case 'z': malloc_zero = 0; break; | ||
529 | case 'Z': malloc_zero = 1; break; | ||
530 | default: | ||
531 | j = malloc_abort; | ||
532 | malloc_abort = 0; | ||
533 | wrtwarning("unknown char in MALLOC_OPTIONS\n"); | ||
534 | malloc_abort = j; | ||
535 | break; | ||
536 | } | ||
178 | } | 537 | } |
179 | while (nbytes > amt + n) { | 538 | } |
180 | amt <<= 1; | 539 | |
181 | if (amt == 0) | 540 | UTRACE(0, 0, 0); |
182 | return (NULL); | 541 | |
183 | bucket++; | 542 | /* |
543 | * We want junk in the entire allocation, and zero only in the part | ||
544 | * the user asked for. | ||
545 | */ | ||
546 | if (malloc_zero) | ||
547 | malloc_junk=1; | ||
548 | |||
549 | #ifdef MALLOC_STATS | ||
550 | if (malloc_stats) | ||
551 | atexit(malloc_exit); | ||
552 | #endif /* MALLOC_STATS */ | ||
553 | |||
554 | /* Allocate one page for the page directory */ | ||
555 | page_dir = (struct pginfo **) MMAP(malloc_pagesize); | ||
556 | |||
557 | if (page_dir == (struct pginfo **) -1) | ||
558 | wrterror("mmap(2) failed, check limits.\n"); | ||
559 | |||
560 | /* | ||
561 | * We need a maximum of malloc_pageshift buckets, steal these from the | ||
562 | * front of the page_directory; | ||
563 | */ | ||
564 | malloc_origo = ((u_long)pageround((u_long)sbrk(0))) >> malloc_pageshift; | ||
565 | malloc_origo -= malloc_pageshift; | ||
566 | |||
567 | malloc_ninfo = malloc_pagesize / sizeof *page_dir; | ||
568 | |||
569 | /* Been here, done that */ | ||
570 | malloc_started++; | ||
571 | |||
572 | /* Recalculate the cache size in bytes, and make sure it's nonzero */ | ||
573 | |||
574 | if (!malloc_cache) | ||
575 | malloc_cache++; | ||
576 | |||
577 | malloc_cache <<= malloc_pageshift; | ||
578 | |||
579 | /* | ||
580 | * This is a nice hack from Kaleb Keithly (kaleb@x.org). | ||
581 | * We can sbrk(2) further back when we keep this on a low address. | ||
582 | */ | ||
583 | px = (struct pgfree *) imalloc (sizeof *px); | ||
584 | errno = save_errno; | ||
585 | } | ||
586 | |||
587 | /* | ||
588 | * Allocate a number of complete pages | ||
589 | */ | ||
590 | static void * | ||
591 | malloc_pages(size) | ||
592 | size_t size; | ||
593 | { | ||
594 | void *p, *delay_free = 0; | ||
595 | int i; | ||
596 | struct pgfree *pf; | ||
597 | u_long index; | ||
598 | |||
599 | size = pageround(size); | ||
600 | |||
601 | p = 0; | ||
602 | /* Look for free pages before asking for more */ | ||
603 | for(pf = free_list.next; pf; pf = pf->next) { | ||
604 | |||
605 | #ifdef MALLOC_EXTRA_SANITY | ||
606 | if (pf->size & malloc_pagemask) | ||
607 | wrterror("(ES): junk length entry on free_list\n"); | ||
608 | if (!pf->size) | ||
609 | wrterror("(ES): zero length entry on free_list\n"); | ||
610 | if (pf->page == pf->end) | ||
611 | wrterror("(ES): zero entry on free_list\n"); | ||
612 | if (pf->page > pf->end) | ||
613 | wrterror("(ES): sick entry on free_list\n"); | ||
614 | if ((void*)pf->page >= (void*)sbrk(0)) | ||
615 | wrterror("(ES): entry on free_list past brk\n"); | ||
616 | if (page_dir[ptr2index(pf->page)] != MALLOC_FREE) | ||
617 | wrterror("(ES): non-free first page on free-list\n"); | ||
618 | if (page_dir[ptr2index(pf->end)-1] != MALLOC_FREE) | ||
619 | wrterror("(ES): non-free last page on free-list\n"); | ||
620 | #endif /* MALLOC_EXTRA_SANITY */ | ||
621 | |||
622 | if (pf->size < size) | ||
623 | continue; | ||
624 | |||
625 | if (pf->size == size) { | ||
626 | p = pf->page; | ||
627 | if (pf->next) | ||
628 | pf->next->prev = pf->prev; | ||
629 | pf->prev->next = pf->next; | ||
630 | delay_free = pf; | ||
631 | break; | ||
632 | } | ||
633 | |||
634 | p = pf->page; | ||
635 | pf->page = (char *)pf->page + size; | ||
636 | pf->size -= size; | ||
637 | break; | ||
638 | } | ||
639 | |||
640 | #ifdef MALLOC_EXTRA_SANITY | ||
641 | if (p && page_dir[ptr2index(p)] != MALLOC_FREE) | ||
642 | wrterror("(ES): allocated non-free page on free-list\n"); | ||
643 | #endif /* MALLOC_EXTRA_SANITY */ | ||
644 | |||
645 | size >>= malloc_pageshift; | ||
646 | |||
647 | /* Map new pages */ | ||
648 | if (!p) | ||
649 | p = map_pages(size); | ||
650 | |||
651 | if (p) { | ||
652 | |||
653 | index = ptr2index(p); | ||
654 | page_dir[index] = MALLOC_FIRST; | ||
655 | for (i=1;i<size;i++) | ||
656 | page_dir[index+i] = MALLOC_FOLLOW; | ||
657 | |||
658 | if (malloc_junk) | ||
659 | memset(p, SOME_JUNK, size << malloc_pageshift); | ||
660 | } | ||
661 | |||
662 | if (delay_free) { | ||
663 | if (!px) | ||
664 | px = delay_free; | ||
665 | else | ||
666 | ifree(delay_free); | ||
667 | } | ||
668 | |||
669 | return p; | ||
670 | } | ||
671 | |||
672 | /* | ||
673 | * Allocate a page of fragments | ||
674 | */ | ||
675 | |||
676 | static __inline__ int | ||
677 | malloc_make_chunks(bits) | ||
678 | int bits; | ||
679 | { | ||
680 | struct pginfo *bp; | ||
681 | void *pp; | ||
682 | int i, k, l; | ||
683 | |||
684 | /* Allocate a new bucket */ | ||
685 | pp = malloc_pages((size_t)malloc_pagesize); | ||
686 | if (!pp) | ||
687 | return 0; | ||
688 | |||
689 | /* Find length of admin structure */ | ||
690 | l = sizeof *bp - sizeof(u_long); | ||
691 | l += sizeof(u_long) * | ||
692 | (((malloc_pagesize >> bits)+MALLOC_BITS-1) / MALLOC_BITS); | ||
693 | |||
694 | /* Don't waste more than two chunks on this */ | ||
695 | if ((1UL<<(bits)) <= l+l) { | ||
696 | bp = (struct pginfo *)pp; | ||
697 | } else { | ||
698 | bp = (struct pginfo *)imalloc(l); | ||
699 | if (!bp) { | ||
700 | ifree(pp); | ||
701 | return 0; | ||
184 | } | 702 | } |
185 | /* | 703 | } |
186 | * If nothing in hash bucket right now, | 704 | |
187 | * request more memory from the system. | 705 | bp->size = (1UL<<bits); |
188 | */ | 706 | bp->shift = bits; |
189 | if ((op = nextf[bucket]) == NULL) { | 707 | bp->total = bp->free = malloc_pagesize >> bits; |
190 | morecore(bucket); | 708 | bp->page = pp; |
191 | if ((op = nextf[bucket]) == NULL) | 709 | |
192 | return (NULL); | 710 | /* set all valid bits in the bitmap */ |
711 | k = bp->total; | ||
712 | i = 0; | ||
713 | |||
714 | /* Do a bunch at a time */ | ||
715 | for(;k-i >= MALLOC_BITS; i += MALLOC_BITS) | ||
716 | bp->bits[i / MALLOC_BITS] = ~0UL; | ||
717 | |||
718 | for(; i < k; i++) | ||
719 | bp->bits[i/MALLOC_BITS] |= 1UL<<(i%MALLOC_BITS); | ||
720 | |||
721 | if (bp == bp->page) { | ||
722 | /* Mark the ones we stole for ourselves */ | ||
723 | for(i=0;l > 0;i++) { | ||
724 | bp->bits[i/MALLOC_BITS] &= ~(1UL<<(i%MALLOC_BITS)); | ||
725 | bp->free--; | ||
726 | bp->total--; | ||
727 | l -= (1 << bits); | ||
193 | } | 728 | } |
194 | /* remove from linked list */ | 729 | } |
195 | nextf[bucket] = op->ov_next; | 730 | |
196 | op->ov_magic = MAGIC; | 731 | /* MALLOC_LOCK */ |
197 | op->ov_index = bucket; | 732 | |
198 | #ifdef MSTATS | 733 | page_dir[ptr2index(pp)] = bp; |
199 | nmalloc[bucket]++; | 734 | |
200 | #endif | 735 | bp->next = page_dir[bits]; |
201 | #ifdef RCHECK | 736 | page_dir[bits] = bp; |
202 | /* | 737 | |
203 | * Record allocated size of block and | 738 | /* MALLOC_UNLOCK */ |
204 | * bound space with magic numbers. | 739 | |
205 | */ | 740 | return 1; |
206 | op->ov_size = (nbytes + RSLOP - 1) & ~(RSLOP - 1); | ||
207 | op->ov_rmagic = RMAGIC; | ||
208 | *(u_short *)((caddr_t)(op + 1) + op->ov_size) = RMAGIC; | ||
209 | #endif | ||
210 | return ((char *)(op + 1)); | ||
211 | } | 741 | } |
212 | 742 | ||
213 | /* | 743 | /* |
214 | * Allocate more memory to the indicated bucket. | 744 | * Allocate a fragment |
215 | */ | 745 | */ |
216 | static void | 746 | static void * |
217 | morecore(bucket) | 747 | malloc_bytes(size) |
218 | int bucket; | 748 | size_t size; |
219 | { | 749 | { |
220 | register union overhead *op; | 750 | int i,j; |
221 | register long sz; /* size of desired block */ | 751 | u_long u; |
222 | long amt; /* amount to allocate */ | 752 | struct pginfo *bp; |
223 | int nblks; /* how many blocks we get */ | 753 | int k; |
754 | u_long *lp; | ||
224 | 755 | ||
225 | /* | 756 | /* Don't bother with anything less than this */ |
226 | * sbrk_size <= 0 only for big, FLUFFY, requests (about | 757 | if (size < malloc_minsize) |
227 | * 2^30 bytes on a VAX, I think) or for a negative arg. | 758 | size = malloc_minsize; |
228 | */ | 759 | |
229 | sz = 1 << (bucket + 3); | 760 | /* Find the right bucket */ |
230 | #ifdef DEBUG | 761 | j = 1; |
231 | ASSERT(sz > 0); | 762 | i = size-1; |
232 | #else | 763 | while (i >>= 1) |
233 | if (sz <= 0) | 764 | j++; |
234 | return; | 765 | |
235 | #endif | 766 | /* If it's empty, make a page more of that size chunks */ |
236 | if (sz < pagesz) { | 767 | if (!page_dir[j] && !malloc_make_chunks(j)) |
237 | amt = pagesz; | 768 | return 0; |
238 | nblks = amt / sz; | 769 | |
239 | } else { | 770 | bp = page_dir[j]; |
240 | amt = sz + pagesz; | 771 | |
241 | nblks = 1; | 772 | /* Find first word of bitmap which isn't empty */ |
242 | } | 773 | for (lp = bp->bits; !*lp; lp++) |
243 | op = (union overhead *)sbrk(amt); | 774 | ; |
244 | /* no more room! */ | 775 | |
245 | if ((long)op == -1) | 776 | /* Find that bit, and tweak it */ |
246 | return; | 777 | u = 1; |
247 | /* | 778 | k = 0; |
248 | * Add new memory allocated to that on | 779 | while (!(*lp & u)) { |
249 | * free list for this hash bucket. | 780 | u += u; |
250 | */ | 781 | k++; |
251 | nextf[bucket] = op; | 782 | } |
252 | while (--nblks > 0) { | 783 | *lp ^= u; |
253 | op->ov_next = (union overhead *)((caddr_t)op + sz); | 784 | |
254 | op = (union overhead *)((caddr_t)op + sz); | 785 | /* If there are no more free, remove from free-list */ |
255 | } | 786 | if (!--bp->free) { |
787 | page_dir[j] = bp->next; | ||
788 | bp->next = 0; | ||
789 | } | ||
790 | |||
791 | /* Adjust to the real offset of that chunk */ | ||
792 | k += (lp-bp->bits)*MALLOC_BITS; | ||
793 | k <<= bp->shift; | ||
794 | |||
795 | if (malloc_junk) | ||
796 | memset((char *)bp->page + k, SOME_JUNK, bp->size); | ||
797 | |||
798 | return (u_char *)bp->page + k; | ||
256 | } | 799 | } |
257 | 800 | ||
258 | void | 801 | /* |
259 | free(cp) | 802 | * Allocate a piece of memory |
260 | void *cp; | 803 | */ |
261 | { | 804 | static void * |
262 | register long size; | 805 | imalloc(size) |
263 | register union overhead *op; | 806 | size_t size; |
264 | 807 | { | |
265 | if (cp == NULL) | 808 | void *result; |
266 | return; | 809 | |
267 | op = (union overhead *)((caddr_t)cp - sizeof (union overhead)); | 810 | if (!malloc_started) |
268 | #ifdef DEBUG | 811 | malloc_init(); |
269 | ASSERT(op->ov_magic == MAGIC); /* make sure it was in use */ | 812 | |
270 | #else | 813 | if (suicide) |
271 | if (op->ov_magic != MAGIC) | 814 | abort(); |
272 | return; /* sanity */ | 815 | |
273 | #endif | 816 | if ((size + malloc_pagesize) < size) /* Check for overflow */ |
274 | #ifdef RCHECK | 817 | result = 0; |
275 | ASSERT(op->ov_rmagic == RMAGIC); | 818 | else if (size <= malloc_maxsize) |
276 | ASSERT(*(u_short *)((caddr_t)(op + 1) + op->ov_size) == RMAGIC); | 819 | result = malloc_bytes(size); |
277 | #endif | 820 | else |
278 | size = op->ov_index; | 821 | result = malloc_pages(size); |
279 | ASSERT(size < NBUCKETS); | 822 | |
280 | op->ov_next = nextf[size]; /* also clobbers ov_magic */ | 823 | if (malloc_abort && !result) |
281 | nextf[size] = op; | 824 | wrterror("allocation failed.\n"); |
282 | #ifdef MSTATS | 825 | |
283 | nmalloc[size]--; | 826 | if (malloc_zero && result) |
284 | #endif | 827 | memset(result, 0, size); |
828 | |||
829 | return result; | ||
285 | } | 830 | } |
286 | 831 | ||
287 | /* | 832 | /* |
288 | * When a program attempts "storage compaction" as mentioned in the | 833 | * Change the size of an allocation. |
289 | * old malloc man page, it realloc's an already freed block. Usually | ||
290 | * this is the last block it freed; occasionally it might be farther | ||
291 | * back. We have to search all the free lists for the block in order | ||
292 | * to determine its bucket: 1st we make one pass thru the lists | ||
293 | * checking only the first block in each; if that fails we search | ||
294 | * ``realloc_srchlen'' blocks in each list for a match (the variable | ||
295 | * is extern so the caller can modify it). If that fails we just copy | ||
296 | * however many bytes was given to realloc() and hope it's not huge. | ||
297 | */ | 834 | */ |
298 | int realloc_srchlen = 4; /* 4 should be plenty, -1 =>'s whole list */ | 835 | static void * |
836 | irealloc(ptr, size) | ||
837 | void *ptr; | ||
838 | size_t size; | ||
839 | { | ||
840 | void *p; | ||
841 | u_long osize, index; | ||
842 | struct pginfo **mp; | ||
843 | int i; | ||
299 | 844 | ||
300 | void * | 845 | if (suicide) |
301 | realloc(cp, nbytes) | 846 | abort(); |
302 | void *cp; | 847 | |
303 | size_t nbytes; | 848 | if (!malloc_started) { |
304 | { | 849 | wrtwarning("malloc() has never been called.\n"); |
305 | register u_long onb; | 850 | return 0; |
306 | register long i; | 851 | } |
307 | union overhead *op; | 852 | |
308 | char *res; | 853 | index = ptr2index(ptr); |
309 | int was_alloced = 0; | 854 | |
310 | 855 | if (index < malloc_pageshift) { | |
311 | if (cp == NULL) | 856 | wrtwarning("junk pointer, too low to make sense.\n"); |
312 | return (malloc(nbytes)); | 857 | return 0; |
313 | op = (union overhead *)((caddr_t)cp - sizeof (union overhead)); | 858 | } |
314 | if (op->ov_magic == MAGIC) { | 859 | |
315 | was_alloced++; | 860 | if (index > last_index) { |
316 | i = op->ov_index; | 861 | wrtwarning("junk pointer, too high to make sense.\n"); |
317 | } else { | 862 | return 0; |
318 | /* | 863 | } |
319 | * Already free, doing "compaction". | 864 | |
320 | * | 865 | mp = &page_dir[index]; |
321 | * Search for the old block of memory on the | 866 | |
322 | * free list. First, check the most common | 867 | if (*mp == MALLOC_FIRST) { /* Page allocation */ |
323 | * case (last element free'd), then (this failing) | 868 | |
324 | * the last ``realloc_srchlen'' items free'd. | 869 | /* Check the pointer */ |
325 | * If all lookups fail, then assume the size of | 870 | if ((u_long)ptr & malloc_pagemask) { |
326 | * the memory block being realloc'd is the | 871 | wrtwarning("modified (page-) pointer.\n"); |
327 | * largest possible (so that all "nbytes" of new | 872 | return 0; |
328 | * memory are copied into). Note that this could cause | 873 | } |
329 | * a memory fault if the old area was tiny, and the moon | 874 | |
330 | * is gibbous. However, that is very unlikely. | 875 | /* Find the size in bytes */ |
331 | */ | 876 | for (osize = malloc_pagesize; *++mp == MALLOC_FOLLOW;) |
332 | if ((i = findbucket(op, 1)) < 0 && | 877 | osize += malloc_pagesize; |
333 | (i = findbucket(op, realloc_srchlen)) < 0) | 878 | |
334 | i = NBUCKETS; | 879 | if (!malloc_realloc && /* unless we have to, */ |
880 | size <= osize && /* .. or are too small, */ | ||
881 | size > (osize - malloc_pagesize)) { /* .. or can free a page, */ | ||
882 | return ptr; /* don't do anything. */ | ||
883 | } | ||
884 | |||
885 | } else if (*mp >= MALLOC_MAGIC) { /* Chunk allocation */ | ||
886 | |||
887 | /* Check the pointer for sane values */ | ||
888 | if (((u_long)ptr & ((*mp)->size-1))) { | ||
889 | wrtwarning("modified (chunk-) pointer.\n"); | ||
890 | return 0; | ||
335 | } | 891 | } |
336 | onb = 1 << (i + 3); | 892 | |
337 | if (onb < pagesz) | 893 | /* Find the chunk index in the page */ |
338 | onb -= sizeof (*op) + RSLOP; | 894 | i = ((u_long)ptr & malloc_pagemask) >> (*mp)->shift; |
895 | |||
896 | /* Verify that it isn't a free chunk already */ | ||
897 | if ((*mp)->bits[i/MALLOC_BITS] & (1UL<<(i%MALLOC_BITS))) { | ||
898 | wrtwarning("chunk is already free.\n"); | ||
899 | return 0; | ||
900 | } | ||
901 | |||
902 | osize = (*mp)->size; | ||
903 | |||
904 | if (!malloc_realloc && /* Unless we have to, */ | ||
905 | size < osize && /* ..or are too small, */ | ||
906 | (size > osize/2 || /* ..or could use a smaller size, */ | ||
907 | osize == malloc_minsize)) { /* ..(if there is one) */ | ||
908 | return ptr; /* ..Don't do anything */ | ||
909 | } | ||
910 | |||
911 | } else { | ||
912 | wrtwarning("pointer to wrong page.\n"); | ||
913 | return 0; | ||
914 | } | ||
915 | |||
916 | p = imalloc(size); | ||
917 | |||
918 | if (p) { | ||
919 | /* copy the lesser of the two sizes, and free the old one */ | ||
920 | if (osize < size) | ||
921 | memcpy(p, ptr, osize); | ||
339 | else | 922 | else |
340 | onb += pagesz - sizeof (*op) - RSLOP; | 923 | memcpy(p, ptr, size); |
341 | /* avoid the copy if same size block */ | 924 | ifree(ptr); |
342 | if (was_alloced) { | 925 | } |
343 | if (i) { | 926 | return p; |
344 | i = 1 << (i + 2); | 927 | } |
345 | if (i < pagesz) | 928 | |
346 | i -= sizeof (*op) + RSLOP; | 929 | /* |
347 | else | 930 | * Free a sequence of pages |
348 | i += pagesz - sizeof (*op) - RSLOP; | 931 | */ |
349 | } | 932 | |
350 | if (nbytes <= onb && nbytes > i) { | 933 | static __inline__ void |
351 | #ifdef RCHECK | 934 | free_pages(ptr, index, info) |
352 | op->ov_size = (nbytes + RSLOP - 1) & ~(RSLOP - 1); | 935 | void *ptr; |
353 | *(u_short *)((caddr_t)(op + 1) + op->ov_size) = RMAGIC; | 936 | int index; |
937 | struct pginfo *info; | ||
938 | { | ||
939 | int i; | ||
940 | struct pgfree *pf, *pt=0; | ||
941 | u_long l; | ||
942 | void *tail; | ||
943 | |||
944 | if (info == MALLOC_FREE) { | ||
945 | wrtwarning("page is already free.\n"); | ||
946 | return; | ||
947 | } | ||
948 | |||
949 | if (info != MALLOC_FIRST) { | ||
950 | wrtwarning("pointer to wrong page.\n"); | ||
951 | return; | ||
952 | } | ||
953 | |||
954 | if ((u_long)ptr & malloc_pagemask) { | ||
955 | wrtwarning("modified (page-) pointer.\n"); | ||
956 | return; | ||
957 | } | ||
958 | |||
959 | /* Count how many pages and mark them free at the same time */ | ||
960 | page_dir[index] = MALLOC_FREE; | ||
961 | for (i = 1; page_dir[index+i] == MALLOC_FOLLOW; i++) | ||
962 | page_dir[index + i] = MALLOC_FREE; | ||
963 | |||
964 | l = i << malloc_pageshift; | ||
965 | |||
966 | if (malloc_junk) | ||
967 | memset(ptr, SOME_JUNK, l); | ||
968 | |||
969 | #ifdef __FreeBSD__ | ||
970 | if (malloc_hint) | ||
971 | madvise(ptr, l, MADV_FREE); | ||
354 | #endif | 972 | #endif |
355 | return(cp); | 973 | |
356 | } else | 974 | tail = (char *)ptr+l; |
357 | free(cp); | 975 | |
976 | /* add to free-list */ | ||
977 | if (!px) | ||
978 | px = imalloc(sizeof *px); /* This cannot fail... */ | ||
979 | px->page = ptr; | ||
980 | px->end = tail; | ||
981 | px->size = l; | ||
982 | if (!free_list.next) { | ||
983 | |||
984 | /* Nothing on free list, put this at head */ | ||
985 | px->next = free_list.next; | ||
986 | px->prev = &free_list; | ||
987 | free_list.next = px; | ||
988 | pf = px; | ||
989 | px = 0; | ||
990 | |||
991 | } else { | ||
992 | |||
993 | /* Find the right spot, leave pf pointing to the modified entry. */ | ||
994 | tail = (char *)ptr+l; | ||
995 | |||
996 | for(pf = free_list.next; pf->end < ptr && pf->next; pf = pf->next) | ||
997 | ; /* Race ahead here */ | ||
998 | |||
999 | if (pf->page > tail) { | ||
1000 | /* Insert before entry */ | ||
1001 | px->next = pf; | ||
1002 | px->prev = pf->prev; | ||
1003 | pf->prev = px; | ||
1004 | px->prev->next = px; | ||
1005 | pf = px; | ||
1006 | px = 0; | ||
1007 | } else if (pf->end == ptr ) { | ||
1008 | /* Append to the previous entry */ | ||
1009 | pf->end = (char *)pf->end + l; | ||
1010 | pf->size += l; | ||
1011 | if (pf->next && pf->end == pf->next->page ) { | ||
1012 | /* And collapse the next too. */ | ||
1013 | pt = pf->next; | ||
1014 | pf->end = pt->end; | ||
1015 | pf->size += pt->size; | ||
1016 | pf->next = pt->next; | ||
1017 | if (pf->next) | ||
1018 | pf->next->prev = pf; | ||
1019 | } | ||
1020 | } else if (pf->page == tail) { | ||
1021 | /* Prepend to entry */ | ||
1022 | pf->size += l; | ||
1023 | pf->page = ptr; | ||
1024 | } else if (!pf->next) { | ||
1025 | /* Append at tail of chain */ | ||
1026 | px->next = 0; | ||
1027 | px->prev = pf; | ||
1028 | pf->next = px; | ||
1029 | pf = px; | ||
1030 | px = 0; | ||
1031 | } else { | ||
1032 | wrterror("freelist is destroyed.\n"); | ||
358 | } | 1033 | } |
359 | if ((res = malloc(nbytes)) == NULL) | 1034 | } |
360 | return (NULL); | 1035 | |
361 | if (cp != res) /* common optimization if "compacting" */ | 1036 | /* Return something to OS ? */ |
362 | bcopy(cp, res, (nbytes < onb) ? nbytes : onb); | 1037 | if (!pf->next && /* If we're the last one, */ |
363 | return (res); | 1038 | pf->size > malloc_cache && /* ..and the cache is full, */ |
1039 | pf->end == malloc_brk && /* ..and none behind us, */ | ||
1040 | malloc_brk == sbrk(0)) { /* ..and it's OK to do... */ | ||
1041 | |||
1042 | /* | ||
1043 | * Keep the cache intact. Notice that the '>' above guarantees that | ||
1044 | * the pf will always have at least one page afterwards. | ||
1045 | */ | ||
1046 | pf->end = (char *)pf->page + malloc_cache; | ||
1047 | pf->size = malloc_cache; | ||
1048 | |||
1049 | brk(pf->end); | ||
1050 | malloc_brk = pf->end; | ||
1051 | |||
1052 | index = ptr2index(pf->end); | ||
1053 | last_index = index - 1; | ||
1054 | |||
1055 | for(i=index;i <= last_index;) | ||
1056 | page_dir[i++] = MALLOC_NOT_MINE; | ||
1057 | |||
1058 | /* XXX: We could realloc/shrink the pagedir here I guess. */ | ||
1059 | } | ||
1060 | if (pt) | ||
1061 | ifree(pt); | ||
364 | } | 1062 | } |
365 | 1063 | ||
366 | /* | 1064 | /* |
367 | * Search ``srchlen'' elements of each free list for a block whose | 1065 | * Free a chunk, and possibly the page it's on, if the page becomes empty. |
368 | * header starts at ``freep''. If srchlen is -1 search the whole list. | ||
369 | * Return bucket number, or -1 if not found. | ||
370 | */ | 1066 | */ |
371 | static | 1067 | |
372 | findbucket(freep, srchlen) | 1068 | /* ARGSUSED */ |
373 | union overhead *freep; | 1069 | static __inline__ void |
374 | int srchlen; | 1070 | free_bytes(ptr, index, info) |
1071 | void *ptr; | ||
1072 | int index; | ||
1073 | struct pginfo *info; | ||
375 | { | 1074 | { |
376 | register union overhead *p; | 1075 | int i; |
377 | register int i, j; | 1076 | struct pginfo **mp; |
378 | 1077 | void *vp; | |
379 | for (i = 0; i < NBUCKETS; i++) { | 1078 | |
380 | j = 0; | 1079 | /* Find the chunk number on the page */ |
381 | for (p = nextf[i]; p && j != srchlen; p = p->ov_next) { | 1080 | i = ((u_long)ptr & malloc_pagemask) >> info->shift; |
382 | if (p == freep) | 1081 | |
383 | return (i); | 1082 | if (((u_long)ptr & (info->size-1))) { |
384 | j++; | 1083 | wrtwarning("modified (chunk-) pointer.\n"); |
385 | } | 1084 | return; |
386 | } | 1085 | } |
387 | return (-1); | 1086 | |
1087 | if (info->bits[i/MALLOC_BITS] & (1UL<<(i%MALLOC_BITS))) { | ||
1088 | wrtwarning("chunk is already free.\n"); | ||
1089 | return; | ||
1090 | } | ||
1091 | |||
1092 | if (malloc_junk) | ||
1093 | memset(ptr, SOME_JUNK, info->size); | ||
1094 | |||
1095 | info->bits[i/MALLOC_BITS] |= 1UL<<(i%MALLOC_BITS); | ||
1096 | info->free++; | ||
1097 | |||
1098 | mp = page_dir + info->shift; | ||
1099 | |||
1100 | if (info->free == 1) { | ||
1101 | |||
1102 | /* Page became non-full */ | ||
1103 | |||
1104 | mp = page_dir + info->shift; | ||
1105 | /* Insert in address order */ | ||
1106 | while (*mp && (*mp)->next && (*mp)->next->page < info->page) | ||
1107 | mp = &(*mp)->next; | ||
1108 | info->next = *mp; | ||
1109 | *mp = info; | ||
1110 | return; | ||
1111 | } | ||
1112 | |||
1113 | if (info->free != info->total) | ||
1114 | return; | ||
1115 | |||
1116 | /* Find & remove this page in the queue */ | ||
1117 | while (*mp != info) { | ||
1118 | mp = &((*mp)->next); | ||
1119 | #ifdef MALLOC_EXTRA_SANITY | ||
1120 | if (!*mp) | ||
1121 | wrterror("(ES): Not on queue\n"); | ||
1122 | #endif /* MALLOC_EXTRA_SANITY */ | ||
1123 | } | ||
1124 | *mp = info->next; | ||
1125 | |||
1126 | /* Free the page & the info structure if need be */ | ||
1127 | page_dir[ptr2index(info->page)] = MALLOC_FIRST; | ||
1128 | vp = info->page; /* Order is important ! */ | ||
1129 | if(vp != (void*)info) | ||
1130 | ifree(info); | ||
1131 | ifree(vp); | ||
1132 | } | ||
1133 | |||
1134 | static void | ||
1135 | ifree(ptr) | ||
1136 | void *ptr; | ||
1137 | { | ||
1138 | struct pginfo *info; | ||
1139 | int index; | ||
1140 | |||
1141 | /* This is legal */ | ||
1142 | if (!ptr) | ||
1143 | return; | ||
1144 | |||
1145 | if (!malloc_started) { | ||
1146 | wrtwarning("malloc() has never been called.\n"); | ||
1147 | return; | ||
1148 | } | ||
1149 | |||
1150 | /* If we're already sinking, don't make matters any worse. */ | ||
1151 | if (suicide) | ||
1152 | return; | ||
1153 | |||
1154 | index = ptr2index(ptr); | ||
1155 | |||
1156 | if (index < malloc_pageshift) { | ||
1157 | wrtwarning("junk pointer, too low to make sense.\n"); | ||
1158 | return; | ||
1159 | } | ||
1160 | |||
1161 | if (index > last_index) { | ||
1162 | wrtwarning("junk pointer, too high to make sense.\n"); | ||
1163 | return; | ||
1164 | } | ||
1165 | |||
1166 | info = page_dir[index]; | ||
1167 | |||
1168 | if (info < MALLOC_MAGIC) | ||
1169 | free_pages(ptr, index, info); | ||
1170 | else | ||
1171 | free_bytes(ptr, index, info); | ||
1172 | return; | ||
388 | } | 1173 | } |
389 | 1174 | ||
390 | #ifdef MSTATS | ||
391 | /* | 1175 | /* |
392 | * mstats - print out statistics about malloc | 1176 | * These are the public exported interface routines. |
393 | * | ||
394 | * Prints two lines of numbers, one showing the length of the free list | ||
395 | * for each size category, the second showing the number of mallocs - | ||
396 | * frees for each size category. | ||
397 | */ | 1177 | */ |
398 | mstats(s) | 1178 | |
399 | char *s; | 1179 | static int malloc_active; |
1180 | |||
1181 | void * | ||
1182 | malloc(size_t size) | ||
1183 | { | ||
1184 | register void *r; | ||
1185 | |||
1186 | malloc_func = " in malloc():"; | ||
1187 | THREAD_LOCK(); | ||
1188 | if (malloc_active++) { | ||
1189 | wrtwarning("recursive call.\n"); | ||
1190 | malloc_active--; | ||
1191 | return (0); | ||
1192 | } | ||
1193 | r = imalloc(size); | ||
1194 | UTRACE(0, size, r); | ||
1195 | malloc_active--; | ||
1196 | THREAD_UNLOCK(); | ||
1197 | if (malloc_xmalloc && !r) | ||
1198 | wrterror("out of memory.\n"); | ||
1199 | return (r); | ||
1200 | } | ||
1201 | |||
1202 | void | ||
1203 | free(void *ptr) | ||
400 | { | 1204 | { |
401 | register int i, j; | 1205 | malloc_func = " in free():"; |
402 | register union overhead *p; | 1206 | THREAD_LOCK(); |
403 | int totfree = 0, | 1207 | if (malloc_active++) { |
404 | totused = 0; | 1208 | wrtwarning("recursive call.\n"); |
405 | 1209 | malloc_active--; | |
406 | fprintf(stderr, "Memory allocation statistics %s\nfree:\t", s); | 1210 | return; |
407 | for (i = 0; i < NBUCKETS; i++) { | 1211 | } |
408 | for (j = 0, p = nextf[i]; p; p = p->ov_next, j++) | 1212 | ifree(ptr); |
409 | ; | 1213 | UTRACE(ptr, 0, 0); |
410 | fprintf(stderr, " %d", j); | 1214 | malloc_active--; |
411 | totfree += j * (1 << (i + 3)); | 1215 | THREAD_UNLOCK(); |
412 | } | 1216 | return; |
413 | fprintf(stderr, "\nused:\t"); | 1217 | } |
414 | for (i = 0; i < NBUCKETS; i++) { | 1218 | |
415 | fprintf(stderr, " %d", nmalloc[i]); | 1219 | void * |
416 | totused += nmalloc[i] * (1 << (i + 3)); | 1220 | realloc(void *ptr, size_t size) |
417 | } | 1221 | { |
418 | fprintf(stderr, "\n\tTotal in use: %d, total free: %d\n", | 1222 | register void *r; |
419 | totused, totfree); | 1223 | |
1224 | malloc_func = " in realloc():"; | ||
1225 | THREAD_LOCK(); | ||
1226 | if (malloc_active++) { | ||
1227 | wrtwarning("recursive call.\n"); | ||
1228 | malloc_active--; | ||
1229 | return (0); | ||
1230 | } | ||
1231 | if (!ptr) { | ||
1232 | r = imalloc(size); | ||
1233 | } else { | ||
1234 | r = irealloc(ptr, size); | ||
1235 | } | ||
1236 | UTRACE(ptr, size, r); | ||
1237 | malloc_active--; | ||
1238 | THREAD_UNLOCK(); | ||
1239 | if (malloc_xmalloc && !r) | ||
1240 | wrterror("out of memory.\n"); | ||
1241 | return (r); | ||
420 | } | 1242 | } |
421 | #endif | ||
diff --git a/src/lib/libc/stdlib/memory.3 b/src/lib/libc/stdlib/memory.3 index 735252c837..712c7c45d2 100644 --- a/src/lib/libc/stdlib/memory.3 +++ b/src/lib/libc/stdlib/memory.3 | |||
@@ -29,8 +29,7 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
31 | .\" | 31 | .\" |
32 | .\" from: @(#)memory.3 5.1 (Berkeley) 5/2/91 | 32 | .\" $OpenBSD: memory.3,v 1.2 1996/08/19 08:33:37 tholo Exp $ |
33 | .\" $Id: memory.3,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $ | ||
34 | .\" | 33 | .\" |
35 | .Dd May 2, 1991 | 34 | .Dd May 2, 1991 |
36 | .Dt MEMORY 3 | 35 | .Dt MEMORY 3 |
diff --git a/src/lib/libc/stdlib/merge.c b/src/lib/libc/stdlib/merge.c index 381fdc0830..0a1015ad9d 100644 --- a/src/lib/libc/stdlib/merge.c +++ b/src/lib/libc/stdlib/merge.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char sccsid[] = "from: @(#)merge.c 8.2 (Berkeley) 2/14/94";*/ | 38 | static char *rcsid = "$OpenBSD: merge.c,v 1.3 1996/09/15 09:31:50 tholo Exp $"; |
39 | static char *rcsid = "$Id: merge.c,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | /* | 41 | /* |
@@ -148,7 +147,7 @@ mergesort(base, nmemb, size, cmp) | |||
148 | sense = 0; | 147 | sense = 0; |
149 | } | 148 | } |
150 | if (!big) { /* here i = 0 */ | 149 | if (!big) { /* here i = 0 */ |
151 | LINEAR: while ((b += size) < t && cmp(q, b) >sense) | 150 | while ((b += size) < t && cmp(q, b) >sense) |
152 | if (++i == 6) { | 151 | if (++i == 6) { |
153 | big = 1; | 152 | big = 1; |
154 | goto EXPONENTIAL; | 153 | goto EXPONENTIAL; |
@@ -169,7 +168,7 @@ EXPONENTIAL: for (i = size; ; i <<= 1) | |||
169 | goto FASTCASE; | 168 | goto FASTCASE; |
170 | } else | 169 | } else |
171 | b = p; | 170 | b = p; |
172 | SLOWCASE: while (t > b+size) { | 171 | while (t > b+size) { |
173 | i = (((t - b) / size) >> 1) * size; | 172 | i = (((t - b) / size) >> 1) * size; |
174 | if ((*cmp)(q, p = b + i) <= sense) | 173 | if ((*cmp)(q, p = b + i) <= sense) |
175 | t = p; | 174 | t = p; |
diff --git a/src/lib/libc/stdlib/mrand48.c b/src/lib/libc/stdlib/mrand48.c index 43356e66b3..cd34260b5c 100644 --- a/src/lib/libc/stdlib/mrand48.c +++ b/src/lib/libc/stdlib/mrand48.c | |||
@@ -11,6 +11,10 @@ | |||
11 | * to anyone/anything when using this software. | 11 | * to anyone/anything when using this software. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #if defined(LIBC_SCCS) && !defined(lint) | ||
15 | static char rcsid[] = "$OpenBSD: mrand48.c,v 1.2 1996/08/19 08:33:39 tholo Exp $"; | ||
16 | #endif /* LIBC_SCCS and not lint */ | ||
17 | |||
14 | #include "rand48.h" | 18 | #include "rand48.h" |
15 | 19 | ||
16 | extern unsigned short __rand48_seed[3]; | 20 | extern unsigned short __rand48_seed[3]; |
diff --git a/src/lib/libc/stdlib/multibyte.c b/src/lib/libc/stdlib/multibyte.c index fe1cd5781b..12e70c4a2c 100644 --- a/src/lib/libc/stdlib/multibyte.c +++ b/src/lib/libc/stdlib/multibyte.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)multibyte.c 5.1 (Berkeley) 2/18/91";*/ | 35 | static char *rcsid = "$OpenBSD: multibyte.c,v 1.2 1996/08/19 08:33:39 tholo Exp $"; |
36 | static char *rcsid = "$Id: multibyte.c,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
diff --git a/src/lib/libc/stdlib/nrand48.c b/src/lib/libc/stdlib/nrand48.c index 63f839cb05..b1ec2cebb1 100644 --- a/src/lib/libc/stdlib/nrand48.c +++ b/src/lib/libc/stdlib/nrand48.c | |||
@@ -11,6 +11,10 @@ | |||
11 | * to anyone/anything when using this software. | 11 | * to anyone/anything when using this software. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #if defined(LIBC_SCCS) && !defined(lint) | ||
15 | static char rcsid[] = "$OpenBSD: nrand48.c,v 1.2 1996/08/19 08:33:40 tholo Exp $"; | ||
16 | #endif /* LIBC_SCCS and not lint */ | ||
17 | |||
14 | #include "rand48.h" | 18 | #include "rand48.h" |
15 | 19 | ||
16 | long | 20 | long |
diff --git a/src/lib/libc/stdlib/putenv.c b/src/lib/libc/stdlib/putenv.c index 2194c2c608..d8c4886d4b 100644 --- a/src/lib/libc/stdlib/putenv.c +++ b/src/lib/libc/stdlib/putenv.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /*- | 1 | /*- |
2 | * Copyright (c) 1988 The Regents of the University of California. | 2 | * Copyright (c) 1988, 1993 |
3 | * All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)putenv.c 5.4 (Berkeley) 2/23/91";*/ | 35 | static char *rcsid = "$OpenBSD: putenv.c,v 1.2 1996/08/10 05:03:00 tholo Exp $"; |
36 | static char *rcsid = "$Id: putenv.c,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
@@ -43,17 +42,17 @@ int | |||
43 | putenv(str) | 42 | putenv(str) |
44 | const char *str; | 43 | const char *str; |
45 | { | 44 | { |
46 | register char *p, *equal; | 45 | char *p, *equal; |
47 | int rval; | 46 | int rval; |
48 | 47 | ||
49 | if (!(p = strdup(str))) | 48 | if ((p = strdup(str)) == NULL) |
50 | return(1); | 49 | return (-1); |
51 | if (!(equal = strchr(p, '='))) { | 50 | if ((equal = strchr(p, '=')) == NULL) { |
52 | (void)free(p); | 51 | (void)free(p); |
53 | return(1); | 52 | return (-1); |
54 | } | 53 | } |
55 | *equal = '\0'; | 54 | *equal = '\0'; |
56 | rval = setenv(p, equal + 1, 1); | 55 | rval = setenv(p, equal + 1, 1); |
57 | (void)free(p); | 56 | (void)free(p); |
58 | return(rval); | 57 | return (rval); |
59 | } | 58 | } |
diff --git a/src/lib/libc/stdlib/qabs.3 b/src/lib/libc/stdlib/qabs.3 index cb1e052191..92a8bdc4b9 100644 --- a/src/lib/libc/stdlib/qabs.3 +++ b/src/lib/libc/stdlib/qabs.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)labs.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: qabs.3,v 1.2 1996/08/19 08:33:40 tholo Exp $ |
37 | .\" $Id: qabs.3,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt QABS 3 | 39 | .Dt QABS 3 |
diff --git a/src/lib/libc/stdlib/qabs.c b/src/lib/libc/stdlib/qabs.c index 9c51a8baa9..ccc42cbec6 100644 --- a/src/lib/libc/stdlib/qabs.c +++ b/src/lib/libc/stdlib/qabs.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)labs.c 5.2 (Berkeley) 5/17/90";*/ | 35 | static char *rcsid = "$OpenBSD: qabs.c,v 1.2 1996/08/19 08:33:40 tholo Exp $"; |
36 | static char *rcsid = "$Id: qabs.c,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
diff --git a/src/lib/libc/stdlib/qdiv.3 b/src/lib/libc/stdlib/qdiv.3 index 0efcfc96ef..12aca0b1ea 100644 --- a/src/lib/libc/stdlib/qdiv.3 +++ b/src/lib/libc/stdlib/qdiv.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)qdiv.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: qdiv.3,v 1.2 1996/08/19 08:33:41 tholo Exp $ |
37 | .\" $Id: qdiv.3,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt QDIV 3 | 39 | .Dt QDIV 3 |
diff --git a/src/lib/libc/stdlib/qdiv.c b/src/lib/libc/stdlib/qdiv.c index 8f8e3f89c4..07e84cd649 100644 --- a/src/lib/libc/stdlib/qdiv.c +++ b/src/lib/libc/stdlib/qdiv.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)ldiv.c 5.2 (Berkeley) 4/16/91";*/ | 38 | static char *rcsid = "$OpenBSD: qdiv.c,v 1.2 1996/08/19 08:33:41 tholo Exp $"; |
39 | static char *rcsid = "$Id: qdiv.c,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <stdlib.h> /* qdiv_t */ | 41 | #include <stdlib.h> /* qdiv_t */ |
diff --git a/src/lib/libc/stdlib/qsort.3 b/src/lib/libc/stdlib/qsort.3 index eb122cde12..a65c5819d0 100644 --- a/src/lib/libc/stdlib/qsort.3 +++ b/src/lib/libc/stdlib/qsort.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)qsort.3 8.1 (Berkeley) 6/4/93 | 36 | .\" $OpenBSD: qsort.3,v 1.2 1996/08/19 08:33:42 tholo Exp $ |
37 | .\" $Id: qsort.3,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 4, 1993 | 38 | .Dd June 4, 1993 |
40 | .Dt QSORT 3 | 39 | .Dt QSORT 3 |
diff --git a/src/lib/libc/stdlib/qsort.c b/src/lib/libc/stdlib/qsort.c index c06bd54054..1c3020b595 100644 --- a/src/lib/libc/stdlib/qsort.c +++ b/src/lib/libc/stdlib/qsort.c | |||
@@ -32,15 +32,14 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char sccsid[] = "from: @(#)qsort.c 8.1 (Berkeley) 6/4/93";*/ | 35 | static char *rcsid = "$OpenBSD: qsort.c,v 1.5 1997/06/20 11:19:38 deraadt Exp $"; |
36 | static char *rcsid = "$Id: qsort.c,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <sys/types.h> | 38 | #include <sys/types.h> |
40 | #include <stdlib.h> | 39 | #include <stdlib.h> |
41 | 40 | ||
42 | static inline char *med3 __P((char *, char *, char *, int (*)())); | 41 | static __inline char *med3 __P((char *, char *, char *, int (*)())); |
43 | static inline void swapfunc __P((char *, char *, int, int)); | 42 | static __inline void swapfunc __P((char *, char *, int, int)); |
44 | 43 | ||
45 | #define min(a, b) (a) < (b) ? a : b | 44 | #define min(a, b) (a) < (b) ? a : b |
46 | 45 | ||
@@ -61,12 +60,12 @@ static inline void swapfunc __P((char *, char *, int, int)); | |||
61 | #define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ | 60 | #define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ |
62 | es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; | 61 | es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; |
63 | 62 | ||
64 | static inline void | 63 | static __inline void |
65 | swapfunc(a, b, n, swaptype) | 64 | swapfunc(a, b, n, swaptype) |
66 | char *a, *b; | 65 | char *a, *b; |
67 | int n, swaptype; | 66 | int n, swaptype; |
68 | { | 67 | { |
69 | if(swaptype <= 1) | 68 | if (swaptype <= 1) |
70 | swapcode(long, a, b, n) | 69 | swapcode(long, a, b, n) |
71 | else | 70 | else |
72 | swapcode(char, a, b, n) | 71 | swapcode(char, a, b, n) |
@@ -82,7 +81,7 @@ swapfunc(a, b, n, swaptype) | |||
82 | 81 | ||
83 | #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) | 82 | #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) |
84 | 83 | ||
85 | static inline char * | 84 | static __inline char * |
86 | med3(a, b, c, cmp) | 85 | med3(a, b, c, cmp) |
87 | char *a, *b, *c; | 86 | char *a, *b, *c; |
88 | int (*cmp)(); | 87 | int (*cmp)(); |
@@ -93,27 +92,28 @@ med3(a, b, c, cmp) | |||
93 | } | 92 | } |
94 | 93 | ||
95 | void | 94 | void |
96 | qsort(a, n, es, cmp) | 95 | qsort(aa, n, es, cmp) |
97 | void *a; | 96 | void *aa; |
98 | size_t n, es; | 97 | size_t n, es; |
99 | int (*cmp)(); | 98 | int (*cmp)(); |
100 | { | 99 | { |
101 | char *pa, *pb, *pc, *pd, *pl, *pm, *pn; | 100 | char *pa, *pb, *pc, *pd, *pl, *pm, *pn; |
102 | int d, r, swaptype, swap_cnt; | 101 | int d, r, swaptype, swap_cnt; |
102 | register char *a = aa; | ||
103 | 103 | ||
104 | loop: SWAPINIT(a, es); | 104 | loop: SWAPINIT(a, es); |
105 | swap_cnt = 0; | 105 | swap_cnt = 0; |
106 | if (n < 7) { | 106 | if (n < 7) { |
107 | for (pm = a + es; pm < (char *) a + n * es; pm += es) | 107 | for (pm = (char *)a + es; pm < (char *) a + n * es; pm += es) |
108 | for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; | 108 | for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; |
109 | pl -= es) | 109 | pl -= es) |
110 | swap(pl, pl - es); | 110 | swap(pl, pl - es); |
111 | return; | 111 | return; |
112 | } | 112 | } |
113 | pm = a + (n / 2) * es; | 113 | pm = (char *)a + (n / 2) * es; |
114 | if (n > 7) { | 114 | if (n > 7) { |
115 | pl = a; | 115 | pl = (char *)a; |
116 | pn = a + (n - 1) * es; | 116 | pn = (char *)a + (n - 1) * es; |
117 | if (n > 40) { | 117 | if (n > 40) { |
118 | d = (n / 8) * es; | 118 | d = (n / 8) * es; |
119 | pl = med3(pl, pl + d, pl + 2 * d, cmp); | 119 | pl = med3(pl, pl + d, pl + 2 * d, cmp); |
@@ -123,9 +123,9 @@ loop: SWAPINIT(a, es); | |||
123 | pm = med3(pl, pm, pn, cmp); | 123 | pm = med3(pl, pm, pn, cmp); |
124 | } | 124 | } |
125 | swap(a, pm); | 125 | swap(a, pm); |
126 | pa = pb = a + es; | 126 | pa = pb = (char *)a + es; |
127 | 127 | ||
128 | pc = pd = a + (n - 1) * es; | 128 | pc = pd = (char *)a + (n - 1) * es; |
129 | for (;;) { | 129 | for (;;) { |
130 | while (pb <= pc && (r = cmp(pb, a)) <= 0) { | 130 | while (pb <= pc && (r = cmp(pb, a)) <= 0) { |
131 | if (r == 0) { | 131 | if (r == 0) { |
@@ -151,14 +151,14 @@ loop: SWAPINIT(a, es); | |||
151 | pc -= es; | 151 | pc -= es; |
152 | } | 152 | } |
153 | if (swap_cnt == 0) { /* Switch to insertion sort */ | 153 | if (swap_cnt == 0) { /* Switch to insertion sort */ |
154 | for (pm = a + es; pm < (char *) a + n * es; pm += es) | 154 | for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) |
155 | for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; | 155 | for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; |
156 | pl -= es) | 156 | pl -= es) |
157 | swap(pl, pl - es); | 157 | swap(pl, pl - es); |
158 | return; | 158 | return; |
159 | } | 159 | } |
160 | 160 | ||
161 | pn = a + n * es; | 161 | pn = (char *)a + n * es; |
162 | r = min(pa - (char *)a, pb - pa); | 162 | r = min(pa - (char *)a, pb - pa); |
163 | vecswap(a, pb - r, r); | 163 | vecswap(a, pb - r, r); |
164 | r = min(pd - pc, pn - pd - es); | 164 | r = min(pd - pc, pn - pd - es); |
diff --git a/src/lib/libc/stdlib/radixsort.3 b/src/lib/libc/stdlib/radixsort.3 index a2af9f17a4..8b0ea89a0f 100644 --- a/src/lib/libc/stdlib/radixsort.3 +++ b/src/lib/libc/stdlib/radixsort.3 | |||
@@ -29,8 +29,7 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
31 | .\" | 31 | .\" |
32 | .\" from: @(#)radixsort.3 8.2 (Berkeley) 1/27/94 | 32 | .\" $OpenBSD: radixsort.3,v 1.4 1998/06/15 17:55:08 mickey Exp $ |
33 | .\" $Id: radixsort.3,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $ | ||
34 | .\" | 33 | .\" |
35 | .Dd January 27, 1994 | 34 | .Dd January 27, 1994 |
36 | .Dt RADIXSORT 3 | 35 | .Dt RADIXSORT 3 |
@@ -42,9 +41,9 @@ | |||
42 | .Fd #include <limits.h> | 41 | .Fd #include <limits.h> |
43 | .Fd #include <stdlib.h> | 42 | .Fd #include <stdlib.h> |
44 | .Ft int | 43 | .Ft int |
45 | .Fn radixsort "u_char **base" "int nmemb" "u_char *table" "u_int endbyte" | 44 | .Fn radixsort "const u_char **base" "int nmemb" "const u_char *table" "u_int endbyte" |
46 | .Ft int | 45 | .Ft int |
47 | .Fn sradixsort "u_char **base" "int nmemb" "u_char *table" "u_int endbyte" | 46 | .Fn sradixsort "const u_char **base" "int nmemb" "const u_char *table" "u_int endbyte" |
48 | .Sh DESCRIPTION | 47 | .Sh DESCRIPTION |
49 | The | 48 | The |
50 | .Fn radixsort | 49 | .Fn radixsort |
@@ -158,4 +157,5 @@ for any of the errors specified for the library routine | |||
158 | .Sh HISTORY | 157 | .Sh HISTORY |
159 | The | 158 | The |
160 | .Fn radixsort | 159 | .Fn radixsort |
161 | function first appeared in 4.4BSD. | 160 | function first appeared in |
161 | .Bx 4.4 . | ||
diff --git a/src/lib/libc/stdlib/radixsort.c b/src/lib/libc/stdlib/radixsort.c index dd51013c94..41ed962466 100644 --- a/src/lib/libc/stdlib/radixsort.c +++ b/src/lib/libc/stdlib/radixsort.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char sccsid[] = "from: @(#)radixsort.c 8.1 (Berkeley) 6/4/93";*/ | 38 | static char *rcsid = "$OpenBSD: radixsort.c,v 1.3 1996/08/19 08:33:44 tholo Exp $"; |
39 | static char *rcsid = "$Id: radixsort.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | /* | 41 | /* |
@@ -61,7 +60,7 @@ typedef struct { | |||
61 | int sn, si; | 60 | int sn, si; |
62 | } stack; | 61 | } stack; |
63 | 62 | ||
64 | static inline void simplesort | 63 | static __inline void simplesort |
65 | __P((const u_char **, int, int, const u_char *, u_int)); | 64 | __P((const u_char **, int, int, const u_char *, u_int)); |
66 | static void r_sort_a __P((const u_char **, int, int, const u_char *, u_int)); | 65 | static void r_sort_a __P((const u_char **, int, int, const u_char *, u_int)); |
67 | static void r_sort_b __P((const u_char **, | 66 | static void r_sort_b __P((const u_char **, |
@@ -295,7 +294,7 @@ r_sort_b(a, ta, n, i, tr, endch) | |||
295 | } | 294 | } |
296 | } | 295 | } |
297 | 296 | ||
298 | static inline void | 297 | static __inline void |
299 | simplesort(a, n, b, tr, endch) /* insertion sort */ | 298 | simplesort(a, n, b, tr, endch) /* insertion sort */ |
300 | register const u_char **a; | 299 | register const u_char **a; |
301 | int n, b; | 300 | int n, b; |
diff --git a/src/lib/libc/stdlib/rand.3 b/src/lib/libc/stdlib/rand.3 index a0e7740e66..32d32761f1 100644 --- a/src/lib/libc/stdlib/rand.3 +++ b/src/lib/libc/stdlib/rand.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)rand.3 6.7 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: rand.3,v 1.4 1998/07/05 19:54:22 millert Exp $ |
37 | .\" $Id: rand.3,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt RAND 3 | 39 | .Dt RAND 3 |
@@ -51,7 +50,8 @@ | |||
51 | .Fn rand void | 50 | .Fn rand void |
52 | .Sh DESCRIPTION | 51 | .Sh DESCRIPTION |
53 | .Bf -symbolic | 52 | .Bf -symbolic |
54 | These interfaces are obsoleted by random(3). | 53 | These interfaces are obsoleted by |
54 | .Xr random 3 . | ||
55 | .Ef | 55 | .Ef |
56 | .Pp | 56 | .Pp |
57 | The | 57 | The |
@@ -74,6 +74,8 @@ with the same seed value. | |||
74 | If no seed value is provided, the functions are automatically | 74 | If no seed value is provided, the functions are automatically |
75 | seeded with a value of 1. | 75 | seeded with a value of 1. |
76 | .Sh SEE ALSO | 76 | .Sh SEE ALSO |
77 | .Xr arc4random 3 , | ||
78 | .Xr rand48 3 , | ||
77 | .Xr random 3 | 79 | .Xr random 3 |
78 | .Sh STANDARDS | 80 | .Sh STANDARDS |
79 | The | 81 | The |
diff --git a/src/lib/libc/stdlib/rand.c b/src/lib/libc/stdlib/rand.c index 361d473448..f270ffd986 100644 --- a/src/lib/libc/stdlib/rand.c +++ b/src/lib/libc/stdlib/rand.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)rand.c 5.6 (Berkeley) 6/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: rand.c,v 1.2 1996/08/19 08:33:44 tholo Exp $"; |
36 | static char *rcsid = "$Id: rand.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <sys/types.h> | 38 | #include <sys/types.h> |
diff --git a/src/lib/libc/stdlib/rand48.3 b/src/lib/libc/stdlib/rand48.3 index 5a772c9a8c..d5236a4779 100644 --- a/src/lib/libc/stdlib/rand48.3 +++ b/src/lib/libc/stdlib/rand48.3 | |||
@@ -9,7 +9,7 @@ | |||
9 | .\" of any kind. I shall in no event be liable for anything that happens | 9 | .\" of any kind. I shall in no event be liable for anything that happens |
10 | .\" to anyone/anything when using this software. | 10 | .\" to anyone/anything when using this software. |
11 | .\" | 11 | .\" |
12 | .\" $Id: rand48.3,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $ | 12 | .\" $OpenBSD: rand48.3,v 1.3 1998/07/05 19:54:23 millert Exp $ |
13 | .\" | 13 | .\" |
14 | .Dd October 8, 1993 | 14 | .Dd October 8, 1993 |
15 | .Dt RAND48 3 | 15 | .Dt RAND48 3 |
@@ -156,5 +156,6 @@ For a more powerful random number generator, see | |||
156 | .Sh AUTHOR | 156 | .Sh AUTHOR |
157 | Martin Birgmeier | 157 | Martin Birgmeier |
158 | .Sh SEE ALSO | 158 | .Sh SEE ALSO |
159 | .Xr arc4random 3 , | ||
159 | .Xr rand 3 , | 160 | .Xr rand 3 , |
160 | .Xr random 3 . | 161 | .Xr random 3 . |
diff --git a/src/lib/libc/stdlib/rand48.h b/src/lib/libc/stdlib/rand48.h index 12496d1c8c..e7cb3e0333 100644 --- a/src/lib/libc/stdlib/rand48.h +++ b/src/lib/libc/stdlib/rand48.h | |||
@@ -9,6 +9,8 @@ | |||
9 | * This software is provided ``as is'', and comes with no warranties | 9 | * This software is provided ``as is'', and comes with no warranties |
10 | * of any kind. I shall in no event be liable for anything that happens | 10 | * of any kind. I shall in no event be liable for anything that happens |
11 | * to anyone/anything when using this software. | 11 | * to anyone/anything when using this software. |
12 | * | ||
13 | * $OpenBSD: rand48.h,v 1.2 1996/08/19 08:33:45 tholo Exp $ | ||
12 | */ | 14 | */ |
13 | 15 | ||
14 | #ifndef _RAND48_H_ | 16 | #ifndef _RAND48_H_ |
diff --git a/src/lib/libc/stdlib/random.3 b/src/lib/libc/stdlib/random.3 index 38c15a9803..acfbd8cdeb 100644 --- a/src/lib/libc/stdlib/random.3 +++ b/src/lib/libc/stdlib/random.3 | |||
@@ -29,8 +29,7 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
31 | .\" | 31 | .\" |
32 | .\" from: @(#)random.3 6.5 (Berkeley) 4/19/91 | 32 | .\" $OpenBSD: random.3,v 1.6 1998/07/05 19:54:25 millert Exp $ |
33 | .\" $Id: random.3,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $ | ||
34 | .\" | 33 | .\" |
35 | .Dd April 19, 1991 | 34 | .Dd April 19, 1991 |
36 | .Dt RANDOM 3 | 35 | .Dt RANDOM 3 |
@@ -46,11 +45,11 @@ | |||
46 | .Ft long | 45 | .Ft long |
47 | .Fn random void | 46 | .Fn random void |
48 | .Ft void | 47 | .Ft void |
49 | .Fn srandom "unsigned seed" | 48 | .Fn srandom "unsigned int seed" |
50 | .Ft char * | 49 | .Ft char * |
51 | .Fn initstate "unsigned seed" "char *state" "int n" | 50 | .Fn initstate "unsigned int seed" "char *state" "size_t n" |
52 | .Ft char * | 51 | .Ft char * |
53 | .Fn setstate "char *state" | 52 | .Fn setstate "const char *state" |
54 | .Sh DESCRIPTION | 53 | .Sh DESCRIPTION |
55 | The | 54 | The |
56 | .Fn random | 55 | .Fn random |
@@ -60,6 +59,12 @@ default table of size 31 long integers to return successive pseudo-random | |||
60 | numbers in the range from 0 to | 59 | numbers in the range from 0 to |
61 | .if t 2\u\s731\s10\d\(mi1. | 60 | .if t 2\u\s731\s10\d\(mi1. |
62 | .if n (2**31)\(mi1. | 61 | .if n (2**31)\(mi1. |
62 | The maximum value returned by | ||
63 | .Fn random | ||
64 | is | ||
65 | .Dv LONG_MAX | ||
66 | (as defined by the header file | ||
67 | .Aq Pa limits.h ) . | ||
63 | The period of this random number generator is very large, approximately | 68 | The period of this random number generator is very large, approximately |
64 | .if t 16\(mu(2\u\s731\s10\d\(mi1). | 69 | .if t 16\(mu(2\u\s731\s10\d\(mi1). |
65 | .if n 16*((2**31)\(mi1). | 70 | .if n 16*((2**31)\(mi1). |
@@ -157,7 +162,18 @@ is called with less than 8 bytes of state information, or if | |||
157 | detects that the state information has been garbled, error | 162 | detects that the state information has been garbled, error |
158 | messages are printed on the standard error output. | 163 | messages are printed on the standard error output. |
159 | .Sh SEE ALSO | 164 | .Sh SEE ALSO |
165 | .Xr arc4random 3 , | ||
166 | .Xr drand48 3 , | ||
160 | .Xr rand 3 | 167 | .Xr rand 3 |
168 | .Sh STANDARDS | ||
169 | The | ||
170 | .Fn random , | ||
171 | .Fn srandom , | ||
172 | .Fn initstate , | ||
173 | and | ||
174 | .Fn setstate | ||
175 | functions conform to | ||
176 | .St -xpg4.2 . | ||
161 | .Sh HISTORY | 177 | .Sh HISTORY |
162 | These | 178 | These |
163 | functions appeared in | 179 | functions appeared in |
diff --git a/src/lib/libc/stdlib/random.c b/src/lib/libc/stdlib/random.c index 469b6d976a..79344f30f1 100644 --- a/src/lib/libc/stdlib/random.c +++ b/src/lib/libc/stdlib/random.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)random.c 5.9 (Berkeley) 2/23/91";*/ | 35 | static char *rcsid = "$OpenBSD: random.c,v 1.6 1998/02/07 02:16:25 millert Exp $"; |
36 | static char *rcsid = "$Id: random.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdio.h> | 38 | #include <stdio.h> |
@@ -136,12 +135,12 @@ static int seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; | |||
136 | 135 | ||
137 | static long randtbl[DEG_3 + 1] = { | 136 | static long randtbl[DEG_3 + 1] = { |
138 | TYPE_3, | 137 | TYPE_3, |
139 | 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5, | 138 | 0x991539b1, 0x16a5bce3, 0x6774a4cd, 0x3e01511e, 0x4e508aaa, 0x61048c05, |
140 | 0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, | 139 | 0xf5500617, 0x846b7115, 0x6a19892c, 0x896a97af, 0xdb48f936, 0x14898454, |
141 | 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, | 140 | 0x37ffd106, 0xb58bff9c, 0x59e17104, 0xcf918a49, 0x09378c83, 0x52c7a471, |
142 | 0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, | 141 | 0x8d293ea9, 0x1f4fc301, 0xc3db71be, 0x39b44e1c, 0xf8a44ef9, 0x4c8b80b1, |
143 | 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b, | 142 | 0x19edc328, 0x87bf4bdd, 0xc9b240e5, 0xe9ee4b1b, 0x4382aee7, 0x535b6b41, |
144 | 0x27fb47b9, | 143 | 0xf3bec5da, |
145 | }; | 144 | }; |
146 | 145 | ||
147 | /* | 146 | /* |
@@ -193,15 +192,26 @@ void | |||
193 | srandom(x) | 192 | srandom(x) |
194 | u_int x; | 193 | u_int x; |
195 | { | 194 | { |
196 | register int i, j; | 195 | register long int test; |
196 | register int i; | ||
197 | ldiv_t val; | ||
197 | 198 | ||
198 | if (rand_type == TYPE_0) | 199 | if (rand_type == TYPE_0) |
199 | state[0] = x; | 200 | state[0] = x; |
200 | else { | 201 | else { |
201 | j = 1; | ||
202 | state[0] = x; | 202 | state[0] = x; |
203 | for (i = 1; i < rand_deg; i++) | 203 | for (i = 1; i < rand_deg; i++) { |
204 | state[i] = 1103515245 * state[i - 1] + 12345; | 204 | /* |
205 | * Implement the following, without overflowing 31 bits: | ||
206 | * | ||
207 | * state[i] = (16807 * state[i - 1]) % 2147483647; | ||
208 | * | ||
209 | * 2^31-1 (prime) = 2147483647 = 127773*16807+2836 | ||
210 | */ | ||
211 | val = ldiv(state[i-1], 127773); | ||
212 | test = 16807 * val.rem - 2836 * val.quot; | ||
213 | state[i] = test + (test < 0 ? 2147483647 : 0); | ||
214 | } | ||
205 | fptr = &state[rand_sep]; | 215 | fptr = &state[rand_sep]; |
206 | rptr = &state[0]; | 216 | rptr = &state[0]; |
207 | for (i = 0; i < 10 * rand_deg; i++) | 217 | for (i = 0; i < 10 * rand_deg; i++) |
@@ -232,7 +242,7 @@ char * | |||
232 | initstate(seed, arg_state, n) | 242 | initstate(seed, arg_state, n) |
233 | u_int seed; /* seed for R.N.G. */ | 243 | u_int seed; /* seed for R.N.G. */ |
234 | char *arg_state; /* pointer to state array */ | 244 | char *arg_state; /* pointer to state array */ |
235 | int n; /* # bytes of state info */ | 245 | size_t n; /* # bytes of state info */ |
236 | { | 246 | { |
237 | register char *ostate = (char *)(&state[-1]); | 247 | register char *ostate = (char *)(&state[-1]); |
238 | 248 | ||
@@ -240,11 +250,8 @@ initstate(seed, arg_state, n) | |||
240 | state[-1] = rand_type; | 250 | state[-1] = rand_type; |
241 | else | 251 | else |
242 | state[-1] = MAX_TYPES * (rptr - state) + rand_type; | 252 | state[-1] = MAX_TYPES * (rptr - state) + rand_type; |
243 | if (n < BREAK_0) { | 253 | if (n < BREAK_0) |
244 | (void)fprintf(stderr, | 254 | return(NULL); |
245 | "random: not enough state (%d bytes); ignored.\n", n); | ||
246 | return(0); | ||
247 | } | ||
248 | if (n < BREAK_1) { | 255 | if (n < BREAK_1) { |
249 | rand_type = TYPE_0; | 256 | rand_type = TYPE_0; |
250 | rand_deg = DEG_0; | 257 | rand_deg = DEG_0; |
@@ -293,7 +300,7 @@ initstate(seed, arg_state, n) | |||
293 | */ | 300 | */ |
294 | char * | 301 | char * |
295 | setstate(arg_state) | 302 | setstate(arg_state) |
296 | char *arg_state; | 303 | const char *arg_state; |
297 | { | 304 | { |
298 | register long *new_state = (long *)arg_state; | 305 | register long *new_state = (long *)arg_state; |
299 | register int type = new_state[0] % MAX_TYPES; | 306 | register int type = new_state[0] % MAX_TYPES; |
@@ -315,8 +322,7 @@ setstate(arg_state) | |||
315 | rand_sep = seps[type]; | 322 | rand_sep = seps[type]; |
316 | break; | 323 | break; |
317 | default: | 324 | default: |
318 | (void)fprintf(stderr, | 325 | return(NULL); |
319 | "random: state info corrupted; not changed.\n"); | ||
320 | } | 326 | } |
321 | state = &new_state[1]; | 327 | state = &new_state[1]; |
322 | if (rand_type != TYPE_0) { | 328 | if (rand_type != TYPE_0) { |
diff --git a/src/lib/libc/stdlib/realpath.3 b/src/lib/libc/stdlib/realpath.3 index 9d8b1ff2ce..cc140029e4 100644 --- a/src/lib/libc/stdlib/realpath.3 +++ b/src/lib/libc/stdlib/realpath.3 | |||
@@ -32,10 +32,9 @@ | |||
32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
33 | .\" SUCH DAMAGE. | 33 | .\" SUCH DAMAGE. |
34 | .\" | 34 | .\" |
35 | .\" from: @(#)realpath.3 8.2 (Berkeley) 2/16/94 | 35 | .\" $OpenBSD: realpath.3,v 1.3 1997/05/30 07:48:30 deraadt Exp $ |
36 | .\" $Id: realpath.3,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $ | ||
37 | .\" | 36 | .\" |
38 | .Dd "February 16, 1994" | 37 | .Dd February, 16, 1994 |
39 | .Dt REALPATH 3 | 38 | .Dt REALPATH 3 |
40 | .Os | 39 | .Os |
41 | .Sh NAME | 40 | .Sh NAME |
diff --git a/src/lib/libc/stdlib/realpath.c b/src/lib/libc/stdlib/realpath.c index e349b7e068..0288601464 100644 --- a/src/lib/libc/stdlib/realpath.c +++ b/src/lib/libc/stdlib/realpath.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char sccsid[] = "from: @(#)realpath.c 8.1 (Berkeley) 2/16/94";*/ | 38 | static char *rcsid = "$OpenBSD: realpath.c,v 1.4 1998/05/18 09:55:19 deraadt Exp $"; |
39 | static char *rcsid = "$Id: realpath.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <sys/param.h> | 41 | #include <sys/param.h> |
@@ -63,6 +62,7 @@ realpath(path, resolved) | |||
63 | struct stat sb; | 62 | struct stat sb; |
64 | int fd, n, rootd, serrno; | 63 | int fd, n, rootd, serrno; |
65 | char *p, *q, wbuf[MAXPATHLEN]; | 64 | char *p, *q, wbuf[MAXPATHLEN]; |
65 | int symlinks = 0; | ||
66 | 66 | ||
67 | /* Save the starting point. */ | 67 | /* Save the starting point. */ |
68 | if ((fd = open(".", O_RDONLY)) < 0) { | 68 | if ((fd = open(".", O_RDONLY)) < 0) { |
@@ -101,7 +101,11 @@ loop: | |||
101 | /* Deal with the last component. */ | 101 | /* Deal with the last component. */ |
102 | if (lstat(p, &sb) == 0) { | 102 | if (lstat(p, &sb) == 0) { |
103 | if (S_ISLNK(sb.st_mode)) { | 103 | if (S_ISLNK(sb.st_mode)) { |
104 | n = readlink(p, resolved, MAXPATHLEN); | 104 | if (++symlinks > MAXSYMLINKS) { |
105 | errno = ELOOP; | ||
106 | goto err1; | ||
107 | } | ||
108 | n = readlink(p, resolved, MAXPATHLEN-1); | ||
105 | if (n < 0) | 109 | if (n < 0) |
106 | goto err1; | 110 | goto err1; |
107 | resolved[n] = '\0'; | 111 | resolved[n] = '\0'; |
diff --git a/src/lib/libc/stdlib/seed48.c b/src/lib/libc/stdlib/seed48.c index e3d31901dd..c4dcd0ead8 100644 --- a/src/lib/libc/stdlib/seed48.c +++ b/src/lib/libc/stdlib/seed48.c | |||
@@ -11,6 +11,10 @@ | |||
11 | * to anyone/anything when using this software. | 11 | * to anyone/anything when using this software. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #if defined(LIBC_SCCS) && !defined(lint) | ||
15 | static char rcsid[] = "$OpenBSD: seed48.c,v 1.2 1996/08/19 08:33:48 tholo Exp $"; | ||
16 | #endif /* LIBC_SCCS and not lint */ | ||
17 | |||
14 | #include "rand48.h" | 18 | #include "rand48.h" |
15 | 19 | ||
16 | extern unsigned short __rand48_seed[3]; | 20 | extern unsigned short __rand48_seed[3]; |
diff --git a/src/lib/libc/stdlib/setenv.c b/src/lib/libc/stdlib/setenv.c index a36669888d..b6f261e61c 100644 --- a/src/lib/libc/stdlib/setenv.c +++ b/src/lib/libc/stdlib/setenv.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)setenv.c 5.6 (Berkeley) 6/4/91";*/ | 35 | static char *rcsid = "$OpenBSD: setenv.c,v 1.3 1998/02/02 22:44:53 millert Exp $"; |
36 | static char *rcsid = "$Id: setenv.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <stdlib.h> | 38 | #include <stdlib.h> |
@@ -72,10 +71,11 @@ setenv(name, value, rewrite) | |||
72 | 71 | ||
73 | for (P = environ, cnt = 0; *P; ++P, ++cnt); | 72 | for (P = environ, cnt = 0; *P; ++P, ++cnt); |
74 | if (alloced) { /* just increase size */ | 73 | if (alloced) { /* just increase size */ |
75 | environ = (char **)realloc((char *)environ, | 74 | P = (char **)realloc((void *)environ, |
76 | (size_t)(sizeof(char *) * (cnt + 2))); | 75 | (size_t)(sizeof(char *) * (cnt + 2))); |
77 | if (!environ) | 76 | if (!P) |
78 | return (-1); | 77 | return (-1); |
78 | environ = P; | ||
79 | } | 79 | } |
80 | else { /* get new space */ | 80 | else { /* get new space */ |
81 | alloced = 1; /* copy old entries into it */ | 81 | alloced = 1; /* copy old entries into it */ |
diff --git a/src/lib/libc/stdlib/srand48.c b/src/lib/libc/stdlib/srand48.c index daf733f93e..fcff8a172e 100644 --- a/src/lib/libc/stdlib/srand48.c +++ b/src/lib/libc/stdlib/srand48.c | |||
@@ -11,6 +11,10 @@ | |||
11 | * to anyone/anything when using this software. | 11 | * to anyone/anything when using this software. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #if defined(LIBC_SCCS) && !defined(lint) | ||
15 | static char rcsid[] = "$OpenBSD: srand48.c,v 1.2 1996/08/19 08:33:49 tholo Exp $"; | ||
16 | #endif /* LIBC_SCCS and not lint */ | ||
17 | |||
14 | #include "rand48.h" | 18 | #include "rand48.h" |
15 | 19 | ||
16 | extern unsigned short __rand48_seed[3]; | 20 | extern unsigned short __rand48_seed[3]; |
diff --git a/src/lib/libc/stdlib/strtod.3 b/src/lib/libc/stdlib/strtod.3 index 0b7f973857..3476fa41d6 100644 --- a/src/lib/libc/stdlib/strtod.3 +++ b/src/lib/libc/stdlib/strtod.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strtod.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strtod.3,v 1.2 1996/08/19 08:33:49 tholo Exp $ |
37 | .\" $Id: strtod.3,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRTOD 3 | 39 | .Dt STRTOD 3 |
diff --git a/src/lib/libc/stdlib/strtod.c b/src/lib/libc/stdlib/strtod.c index b13fa128f5..55d9e91224 100644 --- a/src/lib/libc/stdlib/strtod.c +++ b/src/lib/libc/stdlib/strtod.c | |||
@@ -90,12 +90,13 @@ | |||
90 | */ | 90 | */ |
91 | 91 | ||
92 | #if defined(LIBC_SCCS) && !defined(lint) | 92 | #if defined(LIBC_SCCS) && !defined(lint) |
93 | static char *rcsid = "$Id: strtod.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $"; | 93 | static char *rcsid = "$OpenBSD: strtod.c,v 1.12 1998/08/28 20:49:24 mickey Exp $"; |
94 | #endif /* LIBC_SCCS and not lint */ | 94 | #endif /* LIBC_SCCS and not lint */ |
95 | 95 | ||
96 | #if defined(__m68k__) || defined(__sparc__) || defined(__i386__) || \ | 96 | #if defined(__m68k__) || defined(__sparc__) || defined(__i386__) || \ |
97 | defined(__mips__) || defined(__ns32k__) || defined(__alpha__) | 97 | defined(__mips__) || defined(__ns32k__) || defined(__alpha__) || \ |
98 | #include <machine/endian.h> | 98 | defined(__powerpc__) || defined(__m88k__) || defined(__hppa__) |
99 | #include <sys/types.h> | ||
99 | #if BYTE_ORDER == BIG_ENDIAN | 100 | #if BYTE_ORDER == BIG_ENDIAN |
100 | #define IEEE_BIG_ENDIAN | 101 | #define IEEE_BIG_ENDIAN |
101 | #else | 102 | #else |
@@ -103,6 +104,15 @@ static char *rcsid = "$Id: strtod.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $" | |||
103 | #endif | 104 | #endif |
104 | #endif | 105 | #endif |
105 | 106 | ||
107 | #ifdef __arm32__ | ||
108 | /* | ||
109 | * Although the CPU is little endian the FP has different | ||
110 | * byte and word endianness. The byte order is still little endian | ||
111 | * but the word order is big endian. | ||
112 | */ | ||
113 | #define IEEE_BIG_ENDIAN | ||
114 | #endif | ||
115 | |||
106 | #ifdef vax | 116 | #ifdef vax |
107 | #define VAX | 117 | #define VAX |
108 | #endif | 118 | #endif |
@@ -212,19 +222,24 @@ Exactly one of IEEE_LITTLE_ENDIAN IEEE_BIG_ENDIAN, VAX, or | |||
212 | IBM should be defined. | 222 | IBM should be defined. |
213 | #endif | 223 | #endif |
214 | 224 | ||
225 | typedef union { | ||
226 | double d; | ||
227 | ULong ul[2]; | ||
228 | } _double; | ||
229 | #define value(x) ((x).d) | ||
215 | #ifdef IEEE_LITTLE_ENDIAN | 230 | #ifdef IEEE_LITTLE_ENDIAN |
216 | #define word0(x) ((ULong *)&x)[1] | 231 | #define word0(x) ((x).ul[1]) |
217 | #define word1(x) ((ULong *)&x)[0] | 232 | #define word1(x) ((x).ul[0]) |
218 | #else | 233 | #else |
219 | #define word0(x) ((ULong *)&x)[0] | 234 | #define word0(x) ((x).ul[0]) |
220 | #define word1(x) ((ULong *)&x)[1] | 235 | #define word1(x) ((x).ul[1]) |
221 | #endif | 236 | #endif |
222 | 237 | ||
223 | /* The following definition of Storeinc is appropriate for MIPS processors. | 238 | /* The following definition of Storeinc is appropriate for MIPS processors. |
224 | * An alternative that might be better on some machines is | 239 | * An alternative that might be better on some machines is |
225 | * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) | 240 | * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) |
226 | */ | 241 | */ |
227 | #if defined(IEEE_LITTLE_ENDIAN) + defined(VAX) | 242 | #if defined(IEEE_LITTLE_ENDIAN) + defined(VAX) + defined(__arm32__) |
228 | #define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ | 243 | #define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ |
229 | ((unsigned short *)a)[0] = (unsigned short)c, a++) | 244 | ((unsigned short *)a)[0] = (unsigned short)c, a++) |
230 | #else | 245 | #else |
@@ -899,14 +914,16 @@ diff | |||
899 | static double | 914 | static double |
900 | ulp | 915 | ulp |
901 | #ifdef KR_headers | 916 | #ifdef KR_headers |
902 | (x) double x; | 917 | (_x) double _x; |
903 | #else | 918 | #else |
904 | (double x) | 919 | (double _x) |
905 | #endif | 920 | #endif |
906 | { | 921 | { |
922 | _double x; | ||
907 | register Long L; | 923 | register Long L; |
908 | double a; | 924 | _double a; |
909 | 925 | ||
926 | value(x) = _x; | ||
910 | L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; | 927 | L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; |
911 | #ifndef Sudden_Underflow | 928 | #ifndef Sudden_Underflow |
912 | if (L > 0) { | 929 | if (L > 0) { |
@@ -931,7 +948,7 @@ ulp | |||
931 | } | 948 | } |
932 | } | 949 | } |
933 | #endif | 950 | #endif |
934 | return a; | 951 | return value(a); |
935 | } | 952 | } |
936 | 953 | ||
937 | static double | 954 | static double |
@@ -944,7 +961,7 @@ b2d | |||
944 | { | 961 | { |
945 | ULong *xa, *xa0, w, y, z; | 962 | ULong *xa, *xa0, w, y, z; |
946 | int k; | 963 | int k; |
947 | double d; | 964 | _double d; |
948 | #ifdef VAX | 965 | #ifdef VAX |
949 | ULong d0, d1; | 966 | ULong d0, d1; |
950 | #else | 967 | #else |
@@ -1001,22 +1018,27 @@ b2d | |||
1001 | #undef d0 | 1018 | #undef d0 |
1002 | #undef d1 | 1019 | #undef d1 |
1003 | #endif | 1020 | #endif |
1004 | return d; | 1021 | return value(d); |
1005 | } | 1022 | } |
1006 | 1023 | ||
1007 | static Bigint * | 1024 | static Bigint * |
1008 | d2b | 1025 | d2b |
1009 | #ifdef KR_headers | 1026 | #ifdef KR_headers |
1010 | (d, e, bits) double d; int *e, *bits; | 1027 | (_d, e, bits) double d; int *e, *bits; |
1011 | #else | 1028 | #else |
1012 | (double d, int *e, int *bits) | 1029 | (double _d, int *e, int *bits) |
1013 | #endif | 1030 | #endif |
1014 | { | 1031 | { |
1015 | Bigint *b; | 1032 | Bigint *b; |
1016 | int de, i, k; | 1033 | int de, i, k; |
1017 | ULong *x, y, z; | 1034 | ULong *x, y, z; |
1035 | _double d; | ||
1018 | #ifdef VAX | 1036 | #ifdef VAX |
1019 | ULong d0, d1; | 1037 | ULong d0, d1; |
1038 | #endif | ||
1039 | |||
1040 | value(d) = _d; | ||
1041 | #ifdef VAX | ||
1020 | d0 = word0(d) >> 16 | word0(d) << 16; | 1042 | d0 = word0(d) >> 16 | word0(d) << 16; |
1021 | d1 = word1(d) >> 16 | word1(d) << 16; | 1043 | d1 = word1(d) >> 16 | word1(d) << 16; |
1022 | #else | 1044 | #else |
@@ -1141,11 +1163,11 @@ ratio | |||
1141 | (Bigint *a, Bigint *b) | 1163 | (Bigint *a, Bigint *b) |
1142 | #endif | 1164 | #endif |
1143 | { | 1165 | { |
1144 | double da, db; | 1166 | _double da, db; |
1145 | int k, ka, kb; | 1167 | int k, ka, kb; |
1146 | 1168 | ||
1147 | da = b2d(a, &ka); | 1169 | value(da) = b2d(a, &ka); |
1148 | db = b2d(b, &kb); | 1170 | value(db) = b2d(b, &kb); |
1149 | #ifdef Pack_32 | 1171 | #ifdef Pack_32 |
1150 | k = ka - kb + 32*(a->wds - b->wds); | 1172 | k = ka - kb + 32*(a->wds - b->wds); |
1151 | #else | 1173 | #else |
@@ -1171,7 +1193,7 @@ ratio | |||
1171 | word0(db) += k*Exp_msk1; | 1193 | word0(db) += k*Exp_msk1; |
1172 | } | 1194 | } |
1173 | #endif | 1195 | #endif |
1174 | return da / db; | 1196 | return value(da) / value(db); |
1175 | } | 1197 | } |
1176 | 1198 | ||
1177 | static CONST double | 1199 | static CONST double |
@@ -1211,7 +1233,8 @@ strtod | |||
1211 | int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, | 1233 | int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, |
1212 | e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; | 1234 | e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; |
1213 | CONST char *s, *s0, *s1; | 1235 | CONST char *s, *s0, *s1; |
1214 | double aadj, aadj1, adj, rv, rv0; | 1236 | double aadj, aadj1, adj; |
1237 | _double rv, rv0; | ||
1215 | Long L; | 1238 | Long L; |
1216 | ULong y, z; | 1239 | ULong y, z; |
1217 | Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; | 1240 | Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; |
@@ -1223,10 +1246,10 @@ strtod | |||
1223 | #endif | 1246 | #endif |
1224 | 1247 | ||
1225 | sign = nz0 = nz = 0; | 1248 | sign = nz0 = nz = 0; |
1226 | rv = 0.; | 1249 | value(rv) = 0.; |
1227 | 1250 | ||
1228 | 1251 | ||
1229 | for(s = s00; isspace(*s); s++) | 1252 | for(s = s00; isspace((unsigned char) *s); s++) |
1230 | ; | 1253 | ; |
1231 | 1254 | ||
1232 | if (*s == '-') { | 1255 | if (*s == '-') { |
@@ -1340,9 +1363,9 @@ strtod | |||
1340 | if (!nd0) | 1363 | if (!nd0) |
1341 | nd0 = nd; | 1364 | nd0 = nd; |
1342 | k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; | 1365 | k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; |
1343 | rv = y; | 1366 | value(rv) = y; |
1344 | if (k > 9) | 1367 | if (k > 9) |
1345 | rv = tens[k - 9] * rv + z; | 1368 | value(rv) = tens[k - 9] * value(rv) + z; |
1346 | bd0 = 0; | 1369 | bd0 = 0; |
1347 | if (nd <= DBL_DIG | 1370 | if (nd <= DBL_DIG |
1348 | #ifndef RND_PRODQUOT | 1371 | #ifndef RND_PRODQUOT |
@@ -1356,7 +1379,8 @@ strtod | |||
1356 | #ifdef VAX | 1379 | #ifdef VAX |
1357 | goto vax_ovfl_check; | 1380 | goto vax_ovfl_check; |
1358 | #else | 1381 | #else |
1359 | /* rv = */ rounded_product(rv, tens[e]); | 1382 | /* value(rv) = */ rounded_product(value(rv), |
1383 | tens[e]); | ||
1360 | goto ret; | 1384 | goto ret; |
1361 | #endif | 1385 | #endif |
1362 | } | 1386 | } |
@@ -1366,27 +1390,30 @@ strtod | |||
1366 | * this for larger i values. | 1390 | * this for larger i values. |
1367 | */ | 1391 | */ |
1368 | e -= i; | 1392 | e -= i; |
1369 | rv *= tens[i]; | 1393 | value(rv) *= tens[i]; |
1370 | #ifdef VAX | 1394 | #ifdef VAX |
1371 | /* VAX exponent range is so narrow we must | 1395 | /* VAX exponent range is so narrow we must |
1372 | * worry about overflow here... | 1396 | * worry about overflow here... |
1373 | */ | 1397 | */ |
1374 | vax_ovfl_check: | 1398 | vax_ovfl_check: |
1375 | word0(rv) -= P*Exp_msk1; | 1399 | word0(rv) -= P*Exp_msk1; |
1376 | /* rv = */ rounded_product(rv, tens[e]); | 1400 | /* value(rv) = */ rounded_product(value(rv), |
1401 | tens[e]); | ||
1377 | if ((word0(rv) & Exp_mask) | 1402 | if ((word0(rv) & Exp_mask) |
1378 | > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) | 1403 | > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) |
1379 | goto ovfl; | 1404 | goto ovfl; |
1380 | word0(rv) += P*Exp_msk1; | 1405 | word0(rv) += P*Exp_msk1; |
1381 | #else | 1406 | #else |
1382 | /* rv = */ rounded_product(rv, tens[e]); | 1407 | /* value(rv) = */ rounded_product(value(rv), |
1408 | tens[e]); | ||
1383 | #endif | 1409 | #endif |
1384 | goto ret; | 1410 | goto ret; |
1385 | } | 1411 | } |
1386 | } | 1412 | } |
1387 | #ifndef Inaccurate_Divide | 1413 | #ifndef Inaccurate_Divide |
1388 | else if (e >= -Ten_pmax) { | 1414 | else if (e >= -Ten_pmax) { |
1389 | /* rv = */ rounded_quotient(rv, tens[-e]); | 1415 | /* value(rv) = */ rounded_quotient(value(rv), |
1416 | tens[-e]); | ||
1390 | goto ret; | 1417 | goto ret; |
1391 | } | 1418 | } |
1392 | #endif | 1419 | #endif |
@@ -1397,13 +1424,13 @@ strtod | |||
1397 | 1424 | ||
1398 | if (e1 > 0) { | 1425 | if (e1 > 0) { |
1399 | if (i = e1 & 15) | 1426 | if (i = e1 & 15) |
1400 | rv *= tens[i]; | 1427 | value(rv) *= tens[i]; |
1401 | if (e1 &= ~15) { | 1428 | if (e1 &= ~15) { |
1402 | if (e1 > DBL_MAX_10_EXP) { | 1429 | if (e1 > DBL_MAX_10_EXP) { |
1403 | ovfl: | 1430 | ovfl: |
1404 | errno = ERANGE; | 1431 | errno = ERANGE; |
1405 | #ifdef __STDC__ | 1432 | #ifdef __STDC__ |
1406 | rv = HUGE_VAL; | 1433 | value(rv) = HUGE_VAL; |
1407 | #else | 1434 | #else |
1408 | /* Can't trust HUGE_VAL */ | 1435 | /* Can't trust HUGE_VAL */ |
1409 | #ifdef IEEE_Arith | 1436 | #ifdef IEEE_Arith |
@@ -1421,10 +1448,10 @@ strtod | |||
1421 | if (e1 >>= 4) { | 1448 | if (e1 >>= 4) { |
1422 | for(j = 0; e1 > 1; j++, e1 >>= 1) | 1449 | for(j = 0; e1 > 1; j++, e1 >>= 1) |
1423 | if (e1 & 1) | 1450 | if (e1 & 1) |
1424 | rv *= bigtens[j]; | 1451 | value(rv) *= bigtens[j]; |
1425 | /* The last multiplication could overflow. */ | 1452 | /* The last multiplication could overflow. */ |
1426 | word0(rv) -= P*Exp_msk1; | 1453 | word0(rv) -= P*Exp_msk1; |
1427 | rv *= bigtens[j]; | 1454 | value(rv) *= bigtens[j]; |
1428 | if ((z = word0(rv) & Exp_mask) | 1455 | if ((z = word0(rv) & Exp_mask) |
1429 | > Exp_msk1*(DBL_MAX_EXP+Bias-P)) | 1456 | > Exp_msk1*(DBL_MAX_EXP+Bias-P)) |
1430 | goto ovfl; | 1457 | goto ovfl; |
@@ -1443,23 +1470,23 @@ strtod | |||
1443 | else if (e1 < 0) { | 1470 | else if (e1 < 0) { |
1444 | e1 = -e1; | 1471 | e1 = -e1; |
1445 | if (i = e1 & 15) | 1472 | if (i = e1 & 15) |
1446 | rv /= tens[i]; | 1473 | value(rv) /= tens[i]; |
1447 | if (e1 &= ~15) { | 1474 | if (e1 &= ~15) { |
1448 | e1 >>= 4; | 1475 | e1 >>= 4; |
1449 | if (e1 >= 1 << n_bigtens) | 1476 | if (e1 >= 1 << n_bigtens) |
1450 | goto undfl; | 1477 | goto undfl; |
1451 | for(j = 0; e1 > 1; j++, e1 >>= 1) | 1478 | for(j = 0; e1 > 1; j++, e1 >>= 1) |
1452 | if (e1 & 1) | 1479 | if (e1 & 1) |
1453 | rv *= tinytens[j]; | 1480 | value(rv) *= tinytens[j]; |
1454 | /* The last multiplication could underflow. */ | 1481 | /* The last multiplication could underflow. */ |
1455 | rv0 = rv; | 1482 | value(rv0) = value(rv); |
1456 | rv *= tinytens[j]; | 1483 | value(rv) *= tinytens[j]; |
1457 | if (!rv) { | 1484 | if (!value(rv)) { |
1458 | rv = 2.*rv0; | 1485 | value(rv) = 2.*value(rv0); |
1459 | rv *= tinytens[j]; | 1486 | value(rv) *= tinytens[j]; |
1460 | if (!rv) { | 1487 | if (!value(rv)) { |
1461 | undfl: | 1488 | undfl: |
1462 | rv = 0.; | 1489 | value(rv) = 0.; |
1463 | errno = ERANGE; | 1490 | errno = ERANGE; |
1464 | if (bd0) | 1491 | if (bd0) |
1465 | goto retfree; | 1492 | goto retfree; |
@@ -1483,7 +1510,7 @@ strtod | |||
1483 | for(;;) { | 1510 | for(;;) { |
1484 | bd = Balloc(bd0->k); | 1511 | bd = Balloc(bd0->k); |
1485 | Bcopy(bd, bd0); | 1512 | Bcopy(bd, bd0); |
1486 | bb = d2b(rv, &bbe, &bbbits); /* rv = bb * 2^bbe */ | 1513 | bb = d2b(value(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */ |
1487 | bs = i2b(1); | 1514 | bs = i2b(1); |
1488 | 1515 | ||
1489 | if (e >= 0) { | 1516 | if (e >= 0) { |
@@ -1595,12 +1622,12 @@ strtod | |||
1595 | break; | 1622 | break; |
1596 | #endif | 1623 | #endif |
1597 | if (dsign) | 1624 | if (dsign) |
1598 | rv += ulp(rv); | 1625 | value(rv) += ulp(value(rv)); |
1599 | #ifndef ROUND_BIASED | 1626 | #ifndef ROUND_BIASED |
1600 | else { | 1627 | else { |
1601 | rv -= ulp(rv); | 1628 | value(rv) -= ulp(value(rv)); |
1602 | #ifndef Sudden_Underflow | 1629 | #ifndef Sudden_Underflow |
1603 | if (!rv) | 1630 | if (!value(rv)) |
1604 | goto undfl; | 1631 | goto undfl; |
1605 | #endif | 1632 | #endif |
1606 | } | 1633 | } |
@@ -1651,10 +1678,10 @@ strtod | |||
1651 | /* Check for overflow */ | 1678 | /* Check for overflow */ |
1652 | 1679 | ||
1653 | if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { | 1680 | if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { |
1654 | rv0 = rv; | 1681 | value(rv0) = value(rv); |
1655 | word0(rv) -= P*Exp_msk1; | 1682 | word0(rv) -= P*Exp_msk1; |
1656 | adj = aadj1 * ulp(rv); | 1683 | adj = aadj1 * ulp(value(rv)); |
1657 | rv += adj; | 1684 | value(rv) += adj; |
1658 | if ((word0(rv) & Exp_mask) >= | 1685 | if ((word0(rv) & Exp_mask) >= |
1659 | Exp_msk1*(DBL_MAX_EXP+Bias-P)) { | 1686 | Exp_msk1*(DBL_MAX_EXP+Bias-P)) { |
1660 | if (word0(rv0) == Big0 && word1(rv0) == Big1) | 1687 | if (word0(rv0) == Big0 && word1(rv0) == Big1) |
@@ -1669,10 +1696,10 @@ strtod | |||
1669 | else { | 1696 | else { |
1670 | #ifdef Sudden_Underflow | 1697 | #ifdef Sudden_Underflow |
1671 | if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { | 1698 | if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { |
1672 | rv0 = rv; | 1699 | value(rv0) = value(rv); |
1673 | word0(rv) += P*Exp_msk1; | 1700 | word0(rv) += P*Exp_msk1; |
1674 | adj = aadj1 * ulp(rv); | 1701 | adj = aadj1 * ulp(value(rv)); |
1675 | rv += adj; | 1702 | value(rv) += adj; |
1676 | #ifdef IBM | 1703 | #ifdef IBM |
1677 | if ((word0(rv) & Exp_mask) < P*Exp_msk1) | 1704 | if ((word0(rv) & Exp_mask) < P*Exp_msk1) |
1678 | #else | 1705 | #else |
@@ -1690,8 +1717,8 @@ strtod | |||
1690 | word0(rv) -= P*Exp_msk1; | 1717 | word0(rv) -= P*Exp_msk1; |
1691 | } | 1718 | } |
1692 | else { | 1719 | else { |
1693 | adj = aadj1 * ulp(rv); | 1720 | adj = aadj1 * ulp(value(rv)); |
1694 | rv += adj; | 1721 | value(rv) += adj; |
1695 | } | 1722 | } |
1696 | #else | 1723 | #else |
1697 | /* Compute adj so that the IEEE rounding rules will | 1724 | /* Compute adj so that the IEEE rounding rules will |
@@ -1706,8 +1733,8 @@ strtod | |||
1706 | if (!dsign) | 1733 | if (!dsign) |
1707 | aadj1 = -aadj1; | 1734 | aadj1 = -aadj1; |
1708 | } | 1735 | } |
1709 | adj = aadj1 * ulp(rv); | 1736 | adj = aadj1 * ulp(value(rv)); |
1710 | rv += adj; | 1737 | value(rv) += adj; |
1711 | #endif | 1738 | #endif |
1712 | } | 1739 | } |
1713 | z = word0(rv) & Exp_mask; | 1740 | z = word0(rv) & Exp_mask; |
@@ -1738,7 +1765,7 @@ strtod | |||
1738 | ret: | 1765 | ret: |
1739 | if (se) | 1766 | if (se) |
1740 | *se = (char *)s; | 1767 | *se = (char *)s; |
1741 | return sign ? -rv : rv; | 1768 | return sign ? -value(rv) : value(rv); |
1742 | } | 1769 | } |
1743 | 1770 | ||
1744 | static int | 1771 | static int |
@@ -1884,10 +1911,10 @@ quorem | |||
1884 | char * | 1911 | char * |
1885 | __dtoa | 1912 | __dtoa |
1886 | #ifdef KR_headers | 1913 | #ifdef KR_headers |
1887 | (d, mode, ndigits, decpt, sign, rve) | 1914 | (_d, mode, ndigits, decpt, sign, rve) |
1888 | double d; int mode, ndigits, *decpt, *sign; char **rve; | 1915 | double _d; int mode, ndigits, *decpt, *sign; char **rve; |
1889 | #else | 1916 | #else |
1890 | (double d, int mode, int ndigits, int *decpt, int *sign, char **rve) | 1917 | (double _d, int mode, int ndigits, int *decpt, int *sign, char **rve) |
1891 | #endif | 1918 | #endif |
1892 | { | 1919 | { |
1893 | /* Arguments ndigits, decpt, sign are similar to those | 1920 | /* Arguments ndigits, decpt, sign are similar to those |
@@ -1933,11 +1960,13 @@ __dtoa | |||
1933 | ULong x; | 1960 | ULong x; |
1934 | #endif | 1961 | #endif |
1935 | Bigint *b, *b1, *delta, *mlo, *mhi, *S; | 1962 | Bigint *b, *b1, *delta, *mlo, *mhi, *S; |
1936 | double d2, ds, eps; | 1963 | double ds; |
1937 | char *s, *s0; | 1964 | char *s, *s0; |
1938 | static Bigint *result; | 1965 | static Bigint *result; |
1939 | static int result_k; | 1966 | static int result_k; |
1967 | _double d, d2, eps; | ||
1940 | 1968 | ||
1969 | value(d) = _d; | ||
1941 | if (result) { | 1970 | if (result) { |
1942 | result->k = result_k; | 1971 | result->k = result_k; |
1943 | result->maxwds = 1 << result_k; | 1972 | result->maxwds = 1 << result_k; |
@@ -1977,9 +2006,9 @@ __dtoa | |||
1977 | } | 2006 | } |
1978 | #endif | 2007 | #endif |
1979 | #ifdef IBM | 2008 | #ifdef IBM |
1980 | d += 0; /* normalize */ | 2009 | value(d) += 0; /* normalize */ |
1981 | #endif | 2010 | #endif |
1982 | if (!d) { | 2011 | if (!value(d)) { |
1983 | *decpt = 1; | 2012 | *decpt = 1; |
1984 | s = "0"; | 2013 | s = "0"; |
1985 | if (rve) | 2014 | if (rve) |
@@ -1987,18 +2016,18 @@ __dtoa | |||
1987 | return s; | 2016 | return s; |
1988 | } | 2017 | } |
1989 | 2018 | ||
1990 | b = d2b(d, &be, &bbits); | 2019 | b = d2b(value(d), &be, &bbits); |
1991 | #ifdef Sudden_Underflow | 2020 | #ifdef Sudden_Underflow |
1992 | i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); | 2021 | i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); |
1993 | #else | 2022 | #else |
1994 | if (i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) { | 2023 | if (i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) { |
1995 | #endif | 2024 | #endif |
1996 | d2 = d; | 2025 | value(d2) = value(d); |
1997 | word0(d2) &= Frac_mask1; | 2026 | word0(d2) &= Frac_mask1; |
1998 | word0(d2) |= Exp_11; | 2027 | word0(d2) |= Exp_11; |
1999 | #ifdef IBM | 2028 | #ifdef IBM |
2000 | if (j = 11 - hi0bits(word0(d2) & Frac_mask)) | 2029 | if (j = 11 - hi0bits(word0(d2) & Frac_mask)) |
2001 | d2 /= 1 << j; | 2030 | value(d2) /= 1 << j; |
2002 | #endif | 2031 | #endif |
2003 | 2032 | ||
2004 | /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 | 2033 | /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 |
@@ -2037,19 +2066,20 @@ __dtoa | |||
2037 | i = bbits + be + (Bias + (P-1) - 1); | 2066 | i = bbits + be + (Bias + (P-1) - 1); |
2038 | x = i > 32 ? word0(d) << 64 - i | word1(d) >> i - 32 | 2067 | x = i > 32 ? word0(d) << 64 - i | word1(d) >> i - 32 |
2039 | : word1(d) << 32 - i; | 2068 | : word1(d) << 32 - i; |
2040 | d2 = x; | 2069 | value(d2) = x; |
2041 | word0(d2) -= 31*Exp_msk1; /* adjust exponent */ | 2070 | word0(d2) -= 31*Exp_msk1; /* adjust exponent */ |
2042 | i -= (Bias + (P-1) - 1) + 1; | 2071 | i -= (Bias + (P-1) - 1) + 1; |
2043 | denorm = 1; | 2072 | denorm = 1; |
2044 | } | 2073 | } |
2045 | #endif | 2074 | #endif |
2046 | ds = (d2-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; | 2075 | ds = (value(d2)-1.5)*0.289529654602168 + 0.1760912590558 + |
2076 | i*0.301029995663981; | ||
2047 | k = (int)ds; | 2077 | k = (int)ds; |
2048 | if (ds < 0. && ds != k) | 2078 | if (ds < 0. && ds != k) |
2049 | k--; /* want k = floor(ds) */ | 2079 | k--; /* want k = floor(ds) */ |
2050 | k_check = 1; | 2080 | k_check = 1; |
2051 | if (k >= 0 && k <= Ten_pmax) { | 2081 | if (k >= 0 && k <= Ten_pmax) { |
2052 | if (d < tens[k]) | 2082 | if (value(d) < tens[k]) |
2053 | k--; | 2083 | k--; |
2054 | k_check = 0; | 2084 | k_check = 0; |
2055 | } | 2085 | } |
@@ -2116,7 +2146,7 @@ __dtoa | |||
2116 | /* Try to get by with floating-point arithmetic. */ | 2146 | /* Try to get by with floating-point arithmetic. */ |
2117 | 2147 | ||
2118 | i = 0; | 2148 | i = 0; |
2119 | d2 = d; | 2149 | value(d2) = value(d); |
2120 | k0 = k; | 2150 | k0 = k; |
2121 | ilim0 = ilim; | 2151 | ilim0 = ilim; |
2122 | ieps = 2; /* conservative */ | 2152 | ieps = 2; /* conservative */ |
@@ -2126,7 +2156,7 @@ __dtoa | |||
2126 | if (j & Bletch) { | 2156 | if (j & Bletch) { |
2127 | /* prevent overflows */ | 2157 | /* prevent overflows */ |
2128 | j &= Bletch - 1; | 2158 | j &= Bletch - 1; |
2129 | d /= bigtens[n_bigtens-1]; | 2159 | value(d) /= bigtens[n_bigtens-1]; |
2130 | ieps++; | 2160 | ieps++; |
2131 | } | 2161 | } |
2132 | for(; j; j >>= 1, i++) | 2162 | for(; j; j >>= 1, i++) |
@@ -2134,32 +2164,32 @@ __dtoa | |||
2134 | ieps++; | 2164 | ieps++; |
2135 | ds *= bigtens[i]; | 2165 | ds *= bigtens[i]; |
2136 | } | 2166 | } |
2137 | d /= ds; | 2167 | value(d) /= ds; |
2138 | } | 2168 | } |
2139 | else if (j1 = -k) { | 2169 | else if (j1 = -k) { |
2140 | d *= tens[j1 & 0xf]; | 2170 | value(d) *= tens[j1 & 0xf]; |
2141 | for(j = j1 >> 4; j; j >>= 1, i++) | 2171 | for(j = j1 >> 4; j; j >>= 1, i++) |
2142 | if (j & 1) { | 2172 | if (j & 1) { |
2143 | ieps++; | 2173 | ieps++; |
2144 | d *= bigtens[i]; | 2174 | value(d) *= bigtens[i]; |
2145 | } | 2175 | } |
2146 | } | 2176 | } |
2147 | if (k_check && d < 1. && ilim > 0) { | 2177 | if (k_check && value(d) < 1. && ilim > 0) { |
2148 | if (ilim1 <= 0) | 2178 | if (ilim1 <= 0) |
2149 | goto fast_failed; | 2179 | goto fast_failed; |
2150 | ilim = ilim1; | 2180 | ilim = ilim1; |
2151 | k--; | 2181 | k--; |
2152 | d *= 10.; | 2182 | value(d) *= 10.; |
2153 | ieps++; | 2183 | ieps++; |
2154 | } | 2184 | } |
2155 | eps = ieps*d + 7.; | 2185 | value(eps) = ieps*value(d) + 7.; |
2156 | word0(eps) -= (P-1)*Exp_msk1; | 2186 | word0(eps) -= (P-1)*Exp_msk1; |
2157 | if (ilim == 0) { | 2187 | if (ilim == 0) { |
2158 | S = mhi = 0; | 2188 | S = mhi = 0; |
2159 | d -= 5.; | 2189 | value(d) -= 5.; |
2160 | if (d > eps) | 2190 | if (value(d) > value(eps)) |
2161 | goto one_digit; | 2191 | goto one_digit; |
2162 | if (d < -eps) | 2192 | if (value(d) < -value(eps)) |
2163 | goto no_digits; | 2193 | goto no_digits; |
2164 | goto fast_failed; | 2194 | goto fast_failed; |
2165 | } | 2195 | } |
@@ -2168,33 +2198,33 @@ __dtoa | |||
2168 | /* Use Steele & White method of only | 2198 | /* Use Steele & White method of only |
2169 | * generating digits needed. | 2199 | * generating digits needed. |
2170 | */ | 2200 | */ |
2171 | eps = 0.5/tens[ilim-1] - eps; | 2201 | value(eps) = 0.5/tens[ilim-1] - value(eps); |
2172 | for(i = 0;;) { | 2202 | for(i = 0;;) { |
2173 | L = d; | 2203 | L = value(d); |
2174 | d -= L; | 2204 | value(d) -= L; |
2175 | *s++ = '0' + (int)L; | 2205 | *s++ = '0' + (int)L; |
2176 | if (d < eps) | 2206 | if (value(d) < value(eps)) |
2177 | goto ret1; | 2207 | goto ret1; |
2178 | if (1. - d < eps) | 2208 | if (1. - value(d) < value(eps)) |
2179 | goto bump_up; | 2209 | goto bump_up; |
2180 | if (++i >= ilim) | 2210 | if (++i >= ilim) |
2181 | break; | 2211 | break; |
2182 | eps *= 10.; | 2212 | value(eps) *= 10.; |
2183 | d *= 10.; | 2213 | value(d) *= 10.; |
2184 | } | 2214 | } |
2185 | } | 2215 | } |
2186 | else { | 2216 | else { |
2187 | #endif | 2217 | #endif |
2188 | /* Generate ilim digits, then fix them up. */ | 2218 | /* Generate ilim digits, then fix them up. */ |
2189 | eps *= tens[ilim-1]; | 2219 | value(eps) *= tens[ilim-1]; |
2190 | for(i = 1;; i++, d *= 10.) { | 2220 | for(i = 1;; i++, value(d) *= 10.) { |
2191 | L = d; | 2221 | L = value(d); |
2192 | d -= L; | 2222 | value(d) -= L; |
2193 | *s++ = '0' + (int)L; | 2223 | *s++ = '0' + (int)L; |
2194 | if (i == ilim) { | 2224 | if (i == ilim) { |
2195 | if (d > 0.5 + eps) | 2225 | if (value(d) > 0.5 + value(eps)) |
2196 | goto bump_up; | 2226 | goto bump_up; |
2197 | else if (d < 0.5 - eps) { | 2227 | else if (value(d) < 0.5 - value(eps)) { |
2198 | while(*--s == '0'); | 2228 | while(*--s == '0'); |
2199 | s++; | 2229 | s++; |
2200 | goto ret1; | 2230 | goto ret1; |
@@ -2207,7 +2237,7 @@ __dtoa | |||
2207 | #endif | 2237 | #endif |
2208 | fast_failed: | 2238 | fast_failed: |
2209 | s = s0; | 2239 | s = s0; |
2210 | d = d2; | 2240 | value(d) = value(d2); |
2211 | k = k0; | 2241 | k = k0; |
2212 | ilim = ilim0; | 2242 | ilim = ilim0; |
2213 | } | 2243 | } |
@@ -2219,24 +2249,24 @@ __dtoa | |||
2219 | ds = tens[k]; | 2249 | ds = tens[k]; |
2220 | if (ndigits < 0 && ilim <= 0) { | 2250 | if (ndigits < 0 && ilim <= 0) { |
2221 | S = mhi = 0; | 2251 | S = mhi = 0; |
2222 | if (ilim < 0 || d <= 5*ds) | 2252 | if (ilim < 0 || value(d) <= 5*ds) |
2223 | goto no_digits; | 2253 | goto no_digits; |
2224 | goto one_digit; | 2254 | goto one_digit; |
2225 | } | 2255 | } |
2226 | for(i = 1;; i++) { | 2256 | for(i = 1;; i++) { |
2227 | L = d / ds; | 2257 | L = value(d) / ds; |
2228 | d -= L*ds; | 2258 | value(d) -= L*ds; |
2229 | #ifdef Check_FLT_ROUNDS | 2259 | #ifdef Check_FLT_ROUNDS |
2230 | /* If FLT_ROUNDS == 2, L will usually be high by 1 */ | 2260 | /* If FLT_ROUNDS == 2, L will usually be high by 1 */ |
2231 | if (d < 0) { | 2261 | if (value(d) < 0) { |
2232 | L--; | 2262 | L--; |
2233 | d += ds; | 2263 | value(d) += ds; |
2234 | } | 2264 | } |
2235 | #endif | 2265 | #endif |
2236 | *s++ = '0' + (int)L; | 2266 | *s++ = '0' + (int)L; |
2237 | if (i == ilim) { | 2267 | if (i == ilim) { |
2238 | d += d; | 2268 | value(d) += value(d); |
2239 | if (d > ds || d == ds && L & 1) { | 2269 | if (value(d) > ds || value(d) == ds && L & 1) { |
2240 | bump_up: | 2270 | bump_up: |
2241 | while(*--s == '9') | 2271 | while(*--s == '9') |
2242 | if (s == s0) { | 2272 | if (s == s0) { |
@@ -2248,7 +2278,7 @@ __dtoa | |||
2248 | } | 2278 | } |
2249 | break; | 2279 | break; |
2250 | } | 2280 | } |
2251 | if (!(d *= 10.)) | 2281 | if (!(value(d) *= 10.)) |
2252 | break; | 2282 | break; |
2253 | } | 2283 | } |
2254 | goto ret1; | 2284 | goto ret1; |
diff --git a/src/lib/libc/stdlib/strtol.3 b/src/lib/libc/stdlib/strtol.3 index 808ba90165..b7d2cd1225 100644 --- a/src/lib/libc/stdlib/strtol.3 +++ b/src/lib/libc/stdlib/strtol.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strtol.3 5.4 (Berkeley) 6/25/92 | 36 | .\" $OpenBSD: strtol.3,v 1.3 1996/08/19 08:33:51 tholo Exp $ |
37 | .\" $Id: strtol.3,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 25, 1992 | 38 | .Dd June 25, 1992 |
40 | .Dt STRTOL 3 | 39 | .Dt STRTOL 3 |
@@ -46,13 +45,13 @@ | |||
46 | .Fd #include <stdlib.h> | 45 | .Fd #include <stdlib.h> |
47 | .Fd #include <limits.h> | 46 | .Fd #include <limits.h> |
48 | .Ft long | 47 | .Ft long |
49 | .Fn strtol "char *nptr" "char **endptr" "int base" | 48 | .Fn strtol "const char *nptr" "char **endptr" "int base" |
50 | 49 | ||
51 | .Fd #include <sys/types.h> | 50 | .Fd #include <sys/types.h> |
52 | .Fd #include <stdlib.h> | 51 | .Fd #include <stdlib.h> |
53 | .Fd #include <limits.h> | 52 | .Fd #include <limits.h> |
54 | .Ft quad_t | 53 | .Ft quad_t |
55 | .Fn strtoq "char *nptr" "char **endptr" "int base" | 54 | .Fn strtoq "const char *nptr" "char **endptr" "int base" |
56 | .Sh DESCRIPTION | 55 | .Sh DESCRIPTION |
57 | The | 56 | The |
58 | .Fn strtol | 57 | .Fn strtol |
diff --git a/src/lib/libc/stdlib/strtol.c b/src/lib/libc/stdlib/strtol.c index 6f374abd5f..e4ad557fd5 100644 --- a/src/lib/libc/stdlib/strtol.c +++ b/src/lib/libc/stdlib/strtol.c | |||
@@ -32,13 +32,12 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strtol.c 5.4 (Berkeley) 2/23/91";*/ | 35 | static char *rcsid = "$OpenBSD: strtol.c,v 1.4 1996/08/19 08:33:51 tholo Exp $"; |
36 | static char *rcsid = "$Id: strtol.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <limits.h> | ||
40 | #include <ctype.h> | 38 | #include <ctype.h> |
41 | #include <errno.h> | 39 | #include <errno.h> |
40 | #include <limits.h> | ||
42 | #include <stdlib.h> | 41 | #include <stdlib.h> |
43 | 42 | ||
44 | 43 | ||
@@ -54,25 +53,28 @@ strtol(nptr, endptr, base) | |||
54 | char **endptr; | 53 | char **endptr; |
55 | register int base; | 54 | register int base; |
56 | { | 55 | { |
57 | register const char *s = nptr; | 56 | register const char *s; |
58 | register unsigned long acc; | 57 | register long acc, cutoff; |
59 | register int c; | 58 | register int c; |
60 | register unsigned long cutoff; | 59 | register int neg, any, cutlim; |
61 | register int neg = 0, any, cutlim; | ||
62 | 60 | ||
63 | /* | 61 | /* |
64 | * Skip white space and pick up leading +/- sign if any. | 62 | * Skip white space and pick up leading +/- sign if any. |
65 | * If base is 0, allow 0x for hex and 0 for octal, else | 63 | * If base is 0, allow 0x for hex and 0 for octal, else |
66 | * assume decimal; if base is already 16, allow 0x. | 64 | * assume decimal; if base is already 16, allow 0x. |
67 | */ | 65 | */ |
66 | s = nptr; | ||
68 | do { | 67 | do { |
69 | c = *s++; | 68 | c = (unsigned char) *s++; |
70 | } while (isspace(c)); | 69 | } while (isspace(c)); |
71 | if (c == '-') { | 70 | if (c == '-') { |
72 | neg = 1; | 71 | neg = 1; |
73 | c = *s++; | 72 | c = *s++; |
74 | } else if (c == '+') | 73 | } else { |
75 | c = *s++; | 74 | neg = 0; |
75 | if (c == '+') | ||
76 | c = *s++; | ||
77 | } | ||
76 | if ((base == 0 || base == 16) && | 78 | if ((base == 0 || base == 16) && |
77 | c == '0' && (*s == 'x' || *s == 'X')) { | 79 | c == '0' && (*s == 'x' || *s == 'X')) { |
78 | c = s[1]; | 80 | c = s[1]; |
@@ -99,10 +101,17 @@ strtol(nptr, endptr, base) | |||
99 | * Set any if any `digits' consumed; make it negative to indicate | 101 | * Set any if any `digits' consumed; make it negative to indicate |
100 | * overflow. | 102 | * overflow. |
101 | */ | 103 | */ |
102 | cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; | 104 | cutoff = neg ? LONG_MIN : LONG_MAX; |
103 | cutlim = cutoff % (unsigned long)base; | 105 | cutlim = cutoff % base; |
104 | cutoff /= (unsigned long)base; | 106 | cutoff /= base; |
105 | for (acc = 0, any = 0;; c = *s++) { | 107 | if (neg) { |
108 | if (cutlim > 0) { | ||
109 | cutlim -= base; | ||
110 | cutoff += 1; | ||
111 | } | ||
112 | cutlim = -cutlim; | ||
113 | } | ||
114 | for (acc = 0, any = 0;; c = (unsigned char) *s++) { | ||
106 | if (isdigit(c)) | 115 | if (isdigit(c)) |
107 | c -= '0'; | 116 | c -= '0'; |
108 | else if (isalpha(c)) | 117 | else if (isalpha(c)) |
@@ -111,19 +120,30 @@ strtol(nptr, endptr, base) | |||
111 | break; | 120 | break; |
112 | if (c >= base) | 121 | if (c >= base) |
113 | break; | 122 | break; |
114 | if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) | 123 | if (any < 0) |
115 | any = -1; | 124 | continue; |
116 | else { | 125 | if (neg) { |
117 | any = 1; | 126 | if (acc < cutoff || acc == cutoff && c > cutlim) { |
118 | acc *= base; | 127 | any = -1; |
119 | acc += c; | 128 | acc = LONG_MIN; |
129 | errno = ERANGE; | ||
130 | } else { | ||
131 | any = 1; | ||
132 | acc *= base; | ||
133 | acc -= c; | ||
134 | } | ||
135 | } else { | ||
136 | if (acc > cutoff || acc == cutoff && c > cutlim) { | ||
137 | any = -1; | ||
138 | acc = LONG_MAX; | ||
139 | errno = ERANGE; | ||
140 | } else { | ||
141 | any = 1; | ||
142 | acc *= base; | ||
143 | acc += c; | ||
144 | } | ||
120 | } | 145 | } |
121 | } | 146 | } |
122 | if (any < 0) { | ||
123 | acc = neg ? LONG_MIN : LONG_MAX; | ||
124 | errno = ERANGE; | ||
125 | } else if (neg) | ||
126 | acc = -acc; | ||
127 | if (endptr != 0) | 147 | if (endptr != 0) |
128 | *endptr = (char *) (any ? s - 1 : nptr); | 148 | *endptr = (char *) (any ? s - 1 : nptr); |
129 | return (acc); | 149 | return (acc); |
diff --git a/src/lib/libc/stdlib/strtoq.c b/src/lib/libc/stdlib/strtoq.c index fc559e9d7f..44aabd73f0 100644 --- a/src/lib/libc/stdlib/strtoq.c +++ b/src/lib/libc/stdlib/strtoq.c | |||
@@ -32,14 +32,14 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | static char sccsid[] = "@(#)strtoq.c 5.1 (Berkeley) 6/26/92"; | 35 | static char rcsid[] = "$OpenBSD: strtoq.c,v 1.4 1996/08/19 08:33:52 tholo Exp $"; |
36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
37 | 37 | ||
38 | #include <sys/types.h> | 38 | #include <sys/types.h> |
39 | 39 | ||
40 | #include <limits.h> | ||
41 | #include <errno.h> | ||
42 | #include <ctype.h> | 40 | #include <ctype.h> |
41 | #include <errno.h> | ||
42 | #include <limits.h> | ||
43 | #include <stdlib.h> | 43 | #include <stdlib.h> |
44 | 44 | ||
45 | /* | 45 | /* |
@@ -55,9 +55,8 @@ strtoq(nptr, endptr, base) | |||
55 | register int base; | 55 | register int base; |
56 | { | 56 | { |
57 | register const char *s; | 57 | register const char *s; |
58 | register u_quad_t acc; | 58 | register quad_t acc, cutoff; |
59 | register int c; | 59 | register int c; |
60 | register u_quad_t qbase, cutoff; | ||
61 | register int neg, any, cutlim; | 60 | register int neg, any, cutlim; |
62 | 61 | ||
63 | /* | 62 | /* |
@@ -67,7 +66,7 @@ strtoq(nptr, endptr, base) | |||
67 | */ | 66 | */ |
68 | s = nptr; | 67 | s = nptr; |
69 | do { | 68 | do { |
70 | c = *s++; | 69 | c = (unsigned char) *s++; |
71 | } while (isspace(c)); | 70 | } while (isspace(c)); |
72 | if (c == '-') { | 71 | if (c == '-') { |
73 | neg = 1; | 72 | neg = 1; |
@@ -104,11 +103,17 @@ strtoq(nptr, endptr, base) | |||
104 | * Set any if any `digits' consumed; make it negative to indicate | 103 | * Set any if any `digits' consumed; make it negative to indicate |
105 | * overflow. | 104 | * overflow. |
106 | */ | 105 | */ |
107 | qbase = (unsigned)base; | 106 | cutoff = neg ? QUAD_MIN : QUAD_MAX; |
108 | cutoff = neg ? -(u_quad_t)QUAD_MIN : QUAD_MAX; | 107 | cutlim = cutoff % base; |
109 | cutlim = cutoff % qbase; | 108 | cutoff /= base; |
110 | cutoff /= qbase; | 109 | if (neg) { |
111 | for (acc = 0, any = 0;; c = *s++) { | 110 | if (cutlim > 0) { |
111 | cutlim -= base; | ||
112 | cutoff += 1; | ||
113 | } | ||
114 | cutlim = -cutlim; | ||
115 | } | ||
116 | for (acc = 0, any = 0;; c = (unsigned char) *s++) { | ||
112 | if (isdigit(c)) | 117 | if (isdigit(c)) |
113 | c -= '0'; | 118 | c -= '0'; |
114 | else if (isalpha(c)) | 119 | else if (isalpha(c)) |
@@ -117,19 +122,30 @@ strtoq(nptr, endptr, base) | |||
117 | break; | 122 | break; |
118 | if (c >= base) | 123 | if (c >= base) |
119 | break; | 124 | break; |
120 | if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) | 125 | if (any < 0) |
121 | any = -1; | 126 | continue; |
122 | else { | 127 | if (neg) { |
123 | any = 1; | 128 | if (acc < cutoff || acc == cutoff && c > cutlim) { |
124 | acc *= qbase; | 129 | any = -1; |
125 | acc += c; | 130 | acc = QUAD_MIN; |
131 | errno = ERANGE; | ||
132 | } else { | ||
133 | any = 1; | ||
134 | acc *= base; | ||
135 | acc -= c; | ||
136 | } | ||
137 | } else { | ||
138 | if (acc > cutoff || acc == cutoff && c > cutlim) { | ||
139 | any = -1; | ||
140 | acc = QUAD_MAX; | ||
141 | errno = ERANGE; | ||
142 | } else { | ||
143 | any = 1; | ||
144 | acc *= base; | ||
145 | acc += c; | ||
146 | } | ||
126 | } | 147 | } |
127 | } | 148 | } |
128 | if (any < 0) { | ||
129 | acc = neg ? QUAD_MIN : QUAD_MAX; | ||
130 | errno = ERANGE; | ||
131 | } else if (neg) | ||
132 | acc = -acc; | ||
133 | if (endptr != 0) | 149 | if (endptr != 0) |
134 | *endptr = (char *) (any ? s - 1 : nptr); | 150 | *endptr = (char *) (any ? s - 1 : nptr); |
135 | return (acc); | 151 | return (acc); |
diff --git a/src/lib/libc/stdlib/strtoul.3 b/src/lib/libc/stdlib/strtoul.3 index db551b0141..b8234122a2 100644 --- a/src/lib/libc/stdlib/strtoul.3 +++ b/src/lib/libc/stdlib/strtoul.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strtoul.3 5.4 (Berkeley) 6/25/92 | 36 | .\" $OpenBSD: strtoul.3,v 1.2 1996/08/19 08:33:52 tholo Exp $ |
37 | .\" $Id: strtoul.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 25, 1992 | 38 | .Dd June 25, 1992 |
40 | .Dt STRTOUL 3 | 39 | .Dt STRTOUL 3 |
diff --git a/src/lib/libc/stdlib/strtoul.c b/src/lib/libc/stdlib/strtoul.c index 00f7210fa1..d3b363fa04 100644 --- a/src/lib/libc/stdlib/strtoul.c +++ b/src/lib/libc/stdlib/strtoul.c | |||
@@ -32,13 +32,12 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strtoul.c 5.3 (Berkeley) 2/23/91";*/ | 35 | static char *rcsid = "$OpenBSD: strtoul.c,v 1.4 1996/08/19 08:33:52 tholo Exp $"; |
36 | static char *rcsid = "$Id: strtoul.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <limits.h> | ||
40 | #include <ctype.h> | 38 | #include <ctype.h> |
41 | #include <errno.h> | 39 | #include <errno.h> |
40 | #include <limits.h> | ||
42 | #include <stdlib.h> | 41 | #include <stdlib.h> |
43 | 42 | ||
44 | /* | 43 | /* |
@@ -53,23 +52,26 @@ strtoul(nptr, endptr, base) | |||
53 | char **endptr; | 52 | char **endptr; |
54 | register int base; | 53 | register int base; |
55 | { | 54 | { |
56 | register const char *s = nptr; | 55 | register const char *s; |
57 | register unsigned long acc; | 56 | register unsigned long acc, cutoff; |
58 | register int c; | 57 | register int c; |
59 | register unsigned long cutoff; | 58 | register int neg, any, cutlim; |
60 | register int neg = 0, any, cutlim; | ||
61 | 59 | ||
62 | /* | 60 | /* |
63 | * See strtol for comments as to the logic used. | 61 | * See strtol for comments as to the logic used. |
64 | */ | 62 | */ |
63 | s = nptr; | ||
65 | do { | 64 | do { |
66 | c = *s++; | 65 | c = (unsigned char) *s++; |
67 | } while (isspace(c)); | 66 | } while (isspace(c)); |
68 | if (c == '-') { | 67 | if (c == '-') { |
69 | neg = 1; | 68 | neg = 1; |
70 | c = *s++; | 69 | c = *s++; |
71 | } else if (c == '+') | 70 | } else { |
72 | c = *s++; | 71 | neg = 0; |
72 | if (c == '+') | ||
73 | c = *s++; | ||
74 | } | ||
73 | if ((base == 0 || base == 16) && | 75 | if ((base == 0 || base == 16) && |
74 | c == '0' && (*s == 'x' || *s == 'X')) { | 76 | c == '0' && (*s == 'x' || *s == 'X')) { |
75 | c = s[1]; | 77 | c = s[1]; |
@@ -78,9 +80,10 @@ strtoul(nptr, endptr, base) | |||
78 | } | 80 | } |
79 | if (base == 0) | 81 | if (base == 0) |
80 | base = c == '0' ? 8 : 10; | 82 | base = c == '0' ? 8 : 10; |
81 | cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; | 83 | |
82 | cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; | 84 | cutoff = ULONG_MAX / (unsigned long)base; |
83 | for (acc = 0, any = 0;; c = *s++) { | 85 | cutlim = ULONG_MAX % (unsigned long)base; |
86 | for (acc = 0, any = 0;; c = (unsigned char) *s++) { | ||
84 | if (isdigit(c)) | 87 | if (isdigit(c)) |
85 | c -= '0'; | 88 | c -= '0'; |
86 | else if (isalpha(c)) | 89 | else if (isalpha(c)) |
@@ -89,18 +92,19 @@ strtoul(nptr, endptr, base) | |||
89 | break; | 92 | break; |
90 | if (c >= base) | 93 | if (c >= base) |
91 | break; | 94 | break; |
92 | if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) | 95 | if (any < 0) |
96 | continue; | ||
97 | if (acc > cutoff || acc == cutoff && c > cutlim) { | ||
93 | any = -1; | 98 | any = -1; |
94 | else { | 99 | acc = ULONG_MAX; |
100 | errno = ERANGE; | ||
101 | } else { | ||
95 | any = 1; | 102 | any = 1; |
96 | acc *= base; | 103 | acc *= (unsigned long)base; |
97 | acc += c; | 104 | acc += c; |
98 | } | 105 | } |
99 | } | 106 | } |
100 | if (any < 0) { | 107 | if (neg && any > 0) |
101 | acc = ULONG_MAX; | ||
102 | errno = ERANGE; | ||
103 | } else if (neg) | ||
104 | acc = -acc; | 108 | acc = -acc; |
105 | if (endptr != 0) | 109 | if (endptr != 0) |
106 | *endptr = (char *) (any ? s - 1 : nptr); | 110 | *endptr = (char *) (any ? s - 1 : nptr); |
diff --git a/src/lib/libc/stdlib/strtouq.c b/src/lib/libc/stdlib/strtouq.c index cc647d8d28..1f29a22f33 100644 --- a/src/lib/libc/stdlib/strtouq.c +++ b/src/lib/libc/stdlib/strtouq.c | |||
@@ -32,14 +32,14 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | static char sccsid[] = "@(#)strtouq.c 5.1 (Berkeley) 6/26/92"; | 35 | static char rcsid[] = "$OpenBSD: strtouq.c,v 1.4 1996/08/19 08:33:53 tholo Exp $"; |
36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
37 | 37 | ||
38 | #include <sys/types.h> | 38 | #include <sys/types.h> |
39 | 39 | ||
40 | #include <limits.h> | ||
41 | #include <errno.h> | ||
42 | #include <ctype.h> | 40 | #include <ctype.h> |
41 | #include <errno.h> | ||
42 | #include <limits.h> | ||
43 | #include <stdlib.h> | 43 | #include <stdlib.h> |
44 | 44 | ||
45 | /* | 45 | /* |
@@ -54,10 +54,9 @@ strtouq(nptr, endptr, base) | |||
54 | char **endptr; | 54 | char **endptr; |
55 | register int base; | 55 | register int base; |
56 | { | 56 | { |
57 | register const char *s = nptr; | 57 | register const char *s; |
58 | register u_quad_t acc; | 58 | register u_quad_t acc, cutoff; |
59 | register int c; | 59 | register int c; |
60 | register u_quad_t qbase, cutoff; | ||
61 | register int neg, any, cutlim; | 60 | register int neg, any, cutlim; |
62 | 61 | ||
63 | /* | 62 | /* |
@@ -65,7 +64,7 @@ strtouq(nptr, endptr, base) | |||
65 | */ | 64 | */ |
66 | s = nptr; | 65 | s = nptr; |
67 | do { | 66 | do { |
68 | c = *s++; | 67 | c = (unsigned char) *s++; |
69 | } while (isspace(c)); | 68 | } while (isspace(c)); |
70 | if (c == '-') { | 69 | if (c == '-') { |
71 | neg = 1; | 70 | neg = 1; |
@@ -83,10 +82,10 @@ strtouq(nptr, endptr, base) | |||
83 | } | 82 | } |
84 | if (base == 0) | 83 | if (base == 0) |
85 | base = c == '0' ? 8 : 10; | 84 | base = c == '0' ? 8 : 10; |
86 | qbase = (unsigned)base; | 85 | |
87 | cutoff = (u_quad_t)UQUAD_MAX / qbase; | 86 | cutoff = UQUAD_MAX / (u_quad_t)base; |
88 | cutlim = (u_quad_t)UQUAD_MAX % qbase; | 87 | cutlim = UQUAD_MAX % (u_quad_t)base; |
89 | for (acc = 0, any = 0;; c = *s++) { | 88 | for (acc = 0, any = 0;; c = (unsigned char) *s++) { |
90 | if (isdigit(c)) | 89 | if (isdigit(c)) |
91 | c -= '0'; | 90 | c -= '0'; |
92 | else if (isalpha(c)) | 91 | else if (isalpha(c)) |
@@ -95,18 +94,19 @@ strtouq(nptr, endptr, base) | |||
95 | break; | 94 | break; |
96 | if (c >= base) | 95 | if (c >= base) |
97 | break; | 96 | break; |
98 | if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) | 97 | if (any < 0) |
98 | continue; | ||
99 | if (acc > cutoff || acc == cutoff && c > cutlim) { | ||
99 | any = -1; | 100 | any = -1; |
100 | else { | 101 | acc = UQUAD_MAX; |
102 | errno = ERANGE; | ||
103 | } else { | ||
101 | any = 1; | 104 | any = 1; |
102 | acc *= qbase; | 105 | acc *= (u_quad_t)base; |
103 | acc += c; | 106 | acc += c; |
104 | } | 107 | } |
105 | } | 108 | } |
106 | if (any < 0) { | 109 | if (neg && any > 0) |
107 | acc = UQUAD_MAX; | ||
108 | errno = ERANGE; | ||
109 | } else if (neg) | ||
110 | acc = -acc; | 110 | acc = -acc; |
111 | if (endptr != 0) | 111 | if (endptr != 0) |
112 | *endptr = (char *) (any ? s - 1 : nptr); | 112 | *endptr = (char *) (any ? s - 1 : nptr); |
diff --git a/src/lib/libc/stdlib/system.3 b/src/lib/libc/stdlib/system.3 index 520f51db0a..985adb07de 100644 --- a/src/lib/libc/stdlib/system.3 +++ b/src/lib/libc/stdlib/system.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)system.3 6.5 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: system.3,v 1.5 1996/12/11 23:09:53 tholo Exp $ |
37 | .\" $Id: system.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt SYSTEM 3 | 39 | .Dt SYSTEM 3 |
@@ -72,7 +71,7 @@ will return non-zero. | |||
72 | Otherwise, | 71 | Otherwise, |
73 | .Fn system | 72 | .Fn system |
74 | returns the termination status of the shell in the format specified by | 73 | returns the termination status of the shell in the format specified by |
75 | .Xr waitpid 3 . | 74 | .Xr waitpid 2 . |
76 | .Sh RETURN VALUES | 75 | .Sh RETURN VALUES |
77 | If a child process cannot be created, or the termination status of | 76 | If a child process cannot be created, or the termination status of |
78 | the shell cannot be obtained, | 77 | the shell cannot be obtained, |
@@ -87,8 +86,8 @@ returns the termination status for a program that terminates with a call of | |||
87 | .Sh SEE ALSO | 86 | .Sh SEE ALSO |
88 | .Xr sh 1 , | 87 | .Xr sh 1 , |
89 | .Xr execve 2 , | 88 | .Xr execve 2 , |
90 | .Xr popen 3 , | 89 | .Xr waitpid 2 , |
91 | .Xr waitpid 3 , | 90 | .Xr popen 3 |
92 | .Sh STANDARDS | 91 | .Sh STANDARDS |
93 | The | 92 | The |
94 | .Fn system | 93 | .Fn system |
@@ -96,4 +95,4 @@ function | |||
96 | conforms to | 95 | conforms to |
97 | .St -ansiC | 96 | .St -ansiC |
98 | and | 97 | and |
99 | .St -1003.2-92 . | 98 | .St -p1003.2-92 . |
diff --git a/src/lib/libc/stdlib/system.c b/src/lib/libc/stdlib/system.c index c2f39325f6..3e1b047393 100644 --- a/src/lib/libc/stdlib/system.c +++ b/src/lib/libc/stdlib/system.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)system.c 5.10 (Berkeley) 2/23/91";*/ | 35 | static char *rcsid = "$OpenBSD: system.c,v 1.3 1996/09/15 09:31:52 tholo Exp $"; |
36 | static char *rcsid = "$Id: system.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <sys/types.h> | 38 | #include <sys/types.h> |
@@ -53,11 +52,13 @@ system(command) | |||
53 | sig_t intsave, quitsave; | 52 | sig_t intsave, quitsave; |
54 | int omask; | 53 | int omask; |
55 | int pstat; | 54 | int pstat; |
56 | char *argp[] = {"sh", "-c", (char *) command, NULL}; | 55 | char *argp[] = {"sh", "-c", NULL, NULL}; |
57 | 56 | ||
58 | if (!command) /* just checking... */ | 57 | if (!command) /* just checking... */ |
59 | return(1); | 58 | return(1); |
60 | 59 | ||
60 | argp[2] = (char *)command; | ||
61 | |||
61 | omask = sigblock(sigmask(SIGCHLD)); | 62 | omask = sigblock(sigmask(SIGCHLD)); |
62 | switch(pid = vfork()) { | 63 | switch(pid = vfork()) { |
63 | case -1: /* error */ | 64 | case -1: /* error */ |
diff --git a/src/lib/libc/stdlib/tfind.c b/src/lib/libc/stdlib/tfind.c new file mode 100644 index 0000000000..9e5bd4b0f2 --- /dev/null +++ b/src/lib/libc/stdlib/tfind.c | |||
@@ -0,0 +1,41 @@ | |||
1 | /* | ||
2 | * Tree search generalized from Knuth (6.2.2) Algorithm T just like | ||
3 | * the AT&T man page says. | ||
4 | * | ||
5 | * The node_t structure is for internal use only, lint doesn't grok it. | ||
6 | * | ||
7 | * Written by reading the System V Interface Definition, not the code. | ||
8 | * | ||
9 | * Totally public domain. | ||
10 | */ | ||
11 | /*LINTLIBRARY*/ | ||
12 | #include <search.h> | ||
13 | |||
14 | typedef struct node_t | ||
15 | { | ||
16 | char *key; | ||
17 | struct node_t *llink, *rlink; | ||
18 | } node; | ||
19 | |||
20 | /* find a node, or return 0 */ | ||
21 | void * | ||
22 | tfind(vkey, vrootp, compar) | ||
23 | const void *vkey; /* key to be found */ | ||
24 | void *const *vrootp; /* address of the tree root */ | ||
25 | int (*compar) __P((const void *, const void *)); | ||
26 | { | ||
27 | char *key = (char *)vkey; | ||
28 | node **rootp = (node **)vrootp; | ||
29 | |||
30 | if (rootp == (struct node_t **)0) | ||
31 | return ((struct node_t *)0); | ||
32 | while (*rootp != (struct node_t *)0) { /* T1: */ | ||
33 | int r; | ||
34 | if ((r = (*compar)(key, (*rootp)->key)) == 0) /* T2: */ | ||
35 | return (*rootp); /* key found */ | ||
36 | rootp = (r < 0) ? | ||
37 | &(*rootp)->llink : /* T3: follow left branch */ | ||
38 | &(*rootp)->rlink; /* T4: follow right branch */ | ||
39 | } | ||
40 | return (node *)0; | ||
41 | } | ||
diff --git a/src/lib/libc/stdlib/tsearch.3 b/src/lib/libc/stdlib/tsearch.3 new file mode 100644 index 0000000000..dbdae7943c --- /dev/null +++ b/src/lib/libc/stdlib/tsearch.3 | |||
@@ -0,0 +1,116 @@ | |||
1 | .\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> | ||
2 | .\" All rights reserved. | ||
3 | .\" | ||
4 | .\" Redistribution and use in source and binary forms, with or without | ||
5 | .\" modification, are permitted provided that the following conditions | ||
6 | .\" are met: | ||
7 | .\" 1. Redistributions of source code must retain the above copyright | ||
8 | .\" notice, this list of conditions and the following disclaimer. | ||
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer in the | ||
11 | .\" documentation and/or other materials provided with the distribution. | ||
12 | .\" 3. The name of the author may not be used to endorse or promote products | ||
13 | .\" derived from this software without specific prior written permission. | ||
14 | .\" | ||
15 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
16 | .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
17 | .\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
18 | .\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | .\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
20 | .\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
21 | .\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
22 | .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
23 | .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
24 | .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
25 | .\" | ||
26 | .\" $OpenBSD: tsearch.3,v 1.2 1998/06/21 22:13:49 millert Exp $ | ||
27 | .\" | ||
28 | .Dd June 15, 1997 | ||
29 | .Dt TSEARCH 3 | ||
30 | .Os | ||
31 | .Sh NAME | ||
32 | .Nm tsearch, tfind, tdelete, twalk | ||
33 | .Nd manipulate binary search trees | ||
34 | .Sh SYNOPSIS | ||
35 | .Fd #include <search.h> | ||
36 | .Ft void * | ||
37 | .Fn tdelete "const void *key" "void **rootp", "int (*compar) (const void *, const void *)" | ||
38 | .Ft void * | ||
39 | .Fn tfind "const void *key" "void * const *rootp", "int (*compar) (const void *, const void *)" | ||
40 | .Ft void * | ||
41 | .Fn tsearch "const void *key" "void **rootp", "int (*compar) (const void *, const void *)" | ||
42 | .Ft void | ||
43 | .Fn twalk "const void *root" "void (*compar) (const void *, VISIT, int)" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn tdelete , | ||
47 | .Fn tfind , | ||
48 | .Fn tsearch , | ||
49 | and | ||
50 | .Fn twalk | ||
51 | functions manage binary search trees based on algorithms T and D | ||
52 | from Knuth (6.2.2). The comparison function passed in by | ||
53 | the user has the same style of return values as | ||
54 | .Xr strcmp 3 . | ||
55 | .Pp | ||
56 | .Fn Tfind | ||
57 | searches for the datum matched by the argument | ||
58 | .Fa key | ||
59 | in the binary tree rooted at | ||
60 | .Fa rootp , | ||
61 | returning a pointer to the datum if it is found and NULL | ||
62 | if it is not. | ||
63 | .Pp | ||
64 | .Fn Tsearch | ||
65 | is identical to | ||
66 | .Fn tfind | ||
67 | except that if no match is found, | ||
68 | .Fa key | ||
69 | is inserted into the tree and a pointer to it is returned. If | ||
70 | .Fa rootp | ||
71 | points to a NULL value a new binary search tree is created. | ||
72 | .Pp | ||
73 | .Fn Tdelete | ||
74 | deletes a node from the specified binary search tree and returns | ||
75 | a pointer to the parent of the node to be deleted. | ||
76 | It takes the same arguments as | ||
77 | .Fn tfind | ||
78 | and | ||
79 | .Fn tsearch . | ||
80 | If the node to be deleted is the root of the binary search tree, | ||
81 | .Fa rootp | ||
82 | will be adjusted. | ||
83 | .Pp | ||
84 | .Fn Twalk | ||
85 | walks the binary search tree rooted in | ||
86 | .fa root | ||
87 | and calls the function | ||
88 | .Fa action | ||
89 | on each node. | ||
90 | .Fa Action | ||
91 | is called with three arguments: a pointer to the current node, | ||
92 | a value from the enum | ||
93 | .Sy "typedef enum { preorder, postorder, endorder, leaf } VISIT;" | ||
94 | specifying the traversal type, and a node level (where level | ||
95 | zero is the root of the tree). | ||
96 | .Sh SEE ALSO | ||
97 | .Xr bsearch 3 , | ||
98 | .Xr hsearch 3 , | ||
99 | .Xr lsearch 3 | ||
100 | .Sh RETURN VALUES | ||
101 | The | ||
102 | .Fn tsearch | ||
103 | function returns NULL if allocation of a new node fails (usually | ||
104 | due to a lack of free memory). | ||
105 | .Pp | ||
106 | .Fn Tfind , | ||
107 | .Fn tsearch , | ||
108 | and | ||
109 | .Fn tdelete | ||
110 | return NULL if | ||
111 | .Fa rootp | ||
112 | is NULL or the datum cannot be found. | ||
113 | .Pp | ||
114 | The | ||
115 | .Fn twalk | ||
116 | function returns no value. | ||
diff --git a/src/lib/libc/stdlib/tsearch.c b/src/lib/libc/stdlib/tsearch.c new file mode 100644 index 0000000000..562ace1845 --- /dev/null +++ b/src/lib/libc/stdlib/tsearch.c | |||
@@ -0,0 +1,126 @@ | |||
1 | /* | ||
2 | * Tree search generalized from Knuth (6.2.2) Algorithm T just like | ||
3 | * the AT&T man page says. | ||
4 | * | ||
5 | * The node_t structure is for internal use only, lint doesn't grok it. | ||
6 | * | ||
7 | * Written by reading the System V Interface Definition, not the code. | ||
8 | * | ||
9 | * Totally public domain. | ||
10 | */ | ||
11 | /*LINTLIBRARY*/ | ||
12 | |||
13 | #include <search.h> | ||
14 | #include <stdlib.h> | ||
15 | |||
16 | typedef struct node_t { | ||
17 | char *key; | ||
18 | struct node_t *left, *right; | ||
19 | } node; | ||
20 | |||
21 | /* find or insert datum into search tree */ | ||
22 | void * | ||
23 | tsearch(vkey, vrootp, compar) | ||
24 | const void *vkey; /* key to be located */ | ||
25 | void **vrootp; /* address of tree root */ | ||
26 | int (*compar) __P((const void *, const void *)); | ||
27 | { | ||
28 | register node *q; | ||
29 | char *key = (char *)vkey; | ||
30 | node **rootp = (node **)vrootp; | ||
31 | |||
32 | if (rootp == (struct node_t **)0) | ||
33 | return ((void *)0); | ||
34 | while (*rootp != (struct node_t *)0) { /* Knuth's T1: */ | ||
35 | int r; | ||
36 | |||
37 | if ((r = (*compar)(key, (*rootp)->key)) == 0) /* T2: */ | ||
38 | return ((void *)*rootp); /* we found it! */ | ||
39 | rootp = (r < 0) ? | ||
40 | &(*rootp)->left : /* T3: follow left branch */ | ||
41 | &(*rootp)->right; /* T4: follow right branch */ | ||
42 | } | ||
43 | q = (node *) malloc(sizeof(node)); /* T5: key not found */ | ||
44 | if (q != (struct node_t *)0) { /* make new node */ | ||
45 | *rootp = q; /* link new node to old */ | ||
46 | q->key = key; /* initialize new node */ | ||
47 | q->left = q->right = (struct node_t *)0; | ||
48 | } | ||
49 | return ((void *)q); | ||
50 | } | ||
51 | |||
52 | /* delete node with given key */ | ||
53 | void * | ||
54 | tdelete(vkey, vrootp, compar) | ||
55 | const void *vkey; /* key to be deleted */ | ||
56 | void **vrootp; /* address of the root of tree */ | ||
57 | int (*compar) __P((const void *, const void *)); | ||
58 | { | ||
59 | node **rootp = (node **)vrootp; | ||
60 | char *key = (char *)vkey; | ||
61 | node *p; | ||
62 | register node *q; | ||
63 | register node *r; | ||
64 | int cmp; | ||
65 | |||
66 | if (rootp == (struct node_t **)0 || (p = *rootp) == (struct node_t *)0) | ||
67 | return ((struct node_t *)0); | ||
68 | while ((cmp = (*compar)(key, (*rootp)->key)) != 0) { | ||
69 | p = *rootp; | ||
70 | rootp = (cmp < 0) ? | ||
71 | &(*rootp)->left : /* follow left branch */ | ||
72 | &(*rootp)->right; /* follow right branch */ | ||
73 | if (*rootp == (struct node_t *)0) | ||
74 | return ((void *)0); /* key not found */ | ||
75 | } | ||
76 | r = (*rootp)->right; /* D1: */ | ||
77 | if ((q = (*rootp)->left) == (struct node_t *)0) /* Left (struct node_t *)0? */ | ||
78 | q = r; | ||
79 | else if (r != (struct node_t *)0) { /* Right link is null? */ | ||
80 | if (r->left == (struct node_t *)0) { /* D2: Find successor */ | ||
81 | r->left = q; | ||
82 | q = r; | ||
83 | } else { /* D3: Find (struct node_t *)0 link */ | ||
84 | for (q = r->left; q->left != (struct node_t *)0; q = r->left) | ||
85 | r = q; | ||
86 | r->left = q->right; | ||
87 | q->left = (*rootp)->left; | ||
88 | q->right = (*rootp)->right; | ||
89 | } | ||
90 | } | ||
91 | free((struct node_t *) *rootp); /* D4: Free node */ | ||
92 | *rootp = q; /* link parent to new node */ | ||
93 | return(p); | ||
94 | } | ||
95 | |||
96 | /* Walk the nodes of a tree */ | ||
97 | static void | ||
98 | trecurse(root, action, level) | ||
99 | register node *root; /* Root of the tree to be walked */ | ||
100 | register void (*action)(); /* Function to be called at each node */ | ||
101 | register int level; | ||
102 | { | ||
103 | if (root->left == (struct node_t *)0 && root->right == (struct node_t *)0) | ||
104 | (*action)(root, leaf, level); | ||
105 | else { | ||
106 | (*action)(root, preorder, level); | ||
107 | if (root->left != (struct node_t *)0) | ||
108 | trecurse(root->left, action, level + 1); | ||
109 | (*action)(root, postorder, level); | ||
110 | if (root->right != (struct node_t *)0) | ||
111 | trecurse(root->right, action, level + 1); | ||
112 | (*action)(root, endorder, level); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | /* Walk the nodes of a tree */ | ||
117 | void | ||
118 | twalk(vroot, action) | ||
119 | const void *vroot; /* Root of the tree to be walked */ | ||
120 | void (*action) __P((const void *, VISIT, int)); | ||
121 | { | ||
122 | node *root = (node *)vroot; | ||
123 | |||
124 | if (root != (node *)0 && action != (void(*)())0) | ||
125 | trecurse(root, action, 0); | ||
126 | } | ||
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc index 2b7ce63a63..076db78945 100644 --- a/src/lib/libc/string/Makefile.inc +++ b/src/lib/libc/string/Makefile.inc | |||
@@ -1,11 +1,10 @@ | |||
1 | # from: @(#)Makefile.inc 5.6 (Berkeley) 3/5/91 | 1 | # $OpenBSD: Makefile.inc,v 1.5 1998/07/01 01:29:44 millert Exp $ |
2 | # $Id: Makefile.inc,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
3 | 2 | ||
4 | # string sources | 3 | # string sources |
5 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/string ${.CURDIR}/string | 4 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/string ${.CURDIR}/string |
6 | 5 | ||
7 | SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ | 6 | SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ |
8 | strftime.c strmode.c strsignal.c strtok.c strxfrm.c \ | 7 | strlcat.c strlcpy.c strmode.c strsignal.c strtok.c strxfrm.c \ |
9 | __strerror.c __strsignal.c | 8 | __strerror.c __strsignal.c |
10 | 9 | ||
11 | # machine-dependent net sources | 10 | # machine-dependent net sources |
@@ -95,14 +94,35 @@ strrchr.so: rindex.c | |||
95 | -o ${.TARGET} | 94 | -o ${.TARGET} |
96 | .endif | 95 | .endif |
97 | 96 | ||
97 | # build .ln files for memmove, memcpy, strchr and strrchr always from | ||
98 | # bcopy, index, and rindex | ||
99 | LOBJS+= memmove.ln memcpy.ln strchr.ln strrchr.ln | ||
100 | |||
101 | memmove.ln: bcopy.c | ||
102 | lint ${LINTFLAGS} -DMEMMOVE ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
103 | ${.CURDIR}/string/bcopy.c | ||
104 | |||
105 | memcpy.ln: bcopy.c | ||
106 | lint ${LINTFLAGS} -DMEMCOPY ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
107 | ${.CURDIR}/string/bcopy.c | ||
108 | |||
109 | strchr.ln: index.c | ||
110 | lint ${LINTFLAGS} -DSTRCHR ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
111 | ${.CURDIR}/string/index.c | ||
112 | |||
113 | strrchr.ln: rindex.c | ||
114 | lint ${LINTFLAGS} -DSTRRCHR ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
115 | ${.CURDIR}/string/rindex.c | ||
116 | |||
98 | MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 memccpy.3 memchr.3 \ | 117 | MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 memccpy.3 memchr.3 \ |
99 | memcmp.3 memcpy.3 memmove.3 memset.3 rindex.3 strcasecmp.3 strcat.3 \ | 118 | memcmp.3 memcpy.3 memmove.3 memset.3 rindex.3 strcasecmp.3 strcat.3 \ |
100 | strchr.3 strcmp.3 strcoll.3 strcpy.3 strcspn.3 strerror.3 strftime.3 \ | 119 | strchr.3 strcmp.3 strcoll.3 strcpy.3 strcspn.3 strerror.3 \ |
101 | string.3 strlen.3 strmode.3 strdup.3 strpbrk.3 strrchr.3 strsep.3 \ | 120 | string.3 strlen.3 strmode.3 strdup.3 strpbrk.3 strrchr.3 strsep.3 \ |
102 | strsignal.3 strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 | 121 | strsignal.3 strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 strlcpy.3 |
103 | 122 | ||
104 | MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 | 123 | MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 |
105 | MLINKS+=strcasecmp.3 strncasecmp.3 | 124 | MLINKS+=strcasecmp.3 strncasecmp.3 |
106 | MLINKS+=strcat.3 strncat.3 | 125 | MLINKS+=strcat.3 strncat.3 |
107 | MLINKS+=strcmp.3 strncmp.3 | 126 | MLINKS+=strcmp.3 strncmp.3 |
108 | MLINKS+=strcpy.3 strncpy.3 | 127 | MLINKS+=strcpy.3 strncpy.3 |
128 | MLINKS+=strlcpy.3 strlcat.3 | ||
diff --git a/src/lib/libc/string/__strerror.c b/src/lib/libc/string/__strerror.c index cd604906db..9c023f8a53 100644 --- a/src/lib/libc/string/__strerror.c +++ b/src/lib/libc/string/__strerror.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 35 | static char *rcsid = "$OpenBSD: __strerror.c,v 1.6 1996/09/25 08:17:30 deraadt Exp $"; |
36 | static char *rcsid = "$Id: __strerror.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #ifdef NLS | 38 | #ifdef NLS |
@@ -46,9 +45,26 @@ static char *rcsid = "$Id: __strerror.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Ex | |||
46 | #define sys_errlist _sys_errlist | 45 | #define sys_errlist _sys_errlist |
47 | #define sys_nerr _sys_nerr | 46 | #define sys_nerr _sys_nerr |
48 | 47 | ||
48 | #include <errno.h> | ||
49 | #include <limits.h> | ||
49 | #include <stdio.h> | 50 | #include <stdio.h> |
50 | #include <string.h> | 51 | #include <string.h> |
51 | 52 | ||
53 | static char *itoa(num) | ||
54 | int num; | ||
55 | { | ||
56 | static char buffer[11]; | ||
57 | char *p; | ||
58 | |||
59 | p = buffer + 4; | ||
60 | while (num >= 10) { | ||
61 | *--p = (num % 10) + '0'; | ||
62 | num /= 10; | ||
63 | } | ||
64 | *p = (num % 10) + '0'; | ||
65 | return p; | ||
66 | } | ||
67 | |||
52 | /* | 68 | /* |
53 | * Since perror() is not allowed to change the contents of strerror()'s | 69 | * Since perror() is not allowed to change the contents of strerror()'s |
54 | * static buffer, both functions supply their own buffers to the | 70 | * static buffer, both functions supply their own buffers to the |
@@ -60,28 +76,31 @@ __strerror(num, buf) | |||
60 | int num; | 76 | int num; |
61 | char *buf; | 77 | char *buf; |
62 | { | 78 | { |
63 | #define UPREFIX "Unknown error: %u" | 79 | #define UPREFIX "Unknown error: " |
64 | register unsigned int errnum; | 80 | register unsigned int errnum; |
65 | 81 | ||
66 | #ifdef NLS | 82 | #ifdef NLS |
67 | nl_catd catd ; | 83 | nl_catd catd; |
68 | catd = catopen("libc", 0); | 84 | catd = catopen("libc", 0); |
69 | #endif | 85 | #endif |
70 | 86 | ||
71 | errnum = num; /* convert to unsigned */ | 87 | errnum = num; /* convert to unsigned */ |
72 | if (errnum < sys_nerr) { | 88 | if (errnum < sys_nerr) { |
73 | #ifdef NLS | 89 | #ifdef NLS |
74 | strcpy(buf, catgets(catd, 1, errnum, | 90 | strncpy(buf, catgets(catd, 1, errnum, |
75 | (char *)sys_errlist[errnum])); | 91 | (char *)sys_errlist[errnum]), NL_TEXTMAX-1); |
92 | buf[NL_TEXTMAX - 1] = '\0'; | ||
76 | #else | 93 | #else |
77 | return(sys_errlist[errnum]); | 94 | return(sys_errlist[errnum]); |
78 | #endif | 95 | #endif |
79 | } else { | 96 | } else { |
80 | #ifdef NLS | 97 | #ifdef NLS |
81 | sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), errnum); | 98 | strncpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX-1); |
99 | buf[NL_TEXTMAX - 1] = '\0'; | ||
82 | #else | 100 | #else |
83 | sprintf(buf, UPREFIX, errnum); | 101 | strcpy(buf, UPREFIX); |
84 | #endif | 102 | #endif |
103 | strncat(buf, itoa(errnum), NL_TEXTMAX-strlen(buf)-1); | ||
85 | } | 104 | } |
86 | 105 | ||
87 | #ifdef NLS | 106 | #ifdef NLS |
diff --git a/src/lib/libc/string/__strsignal.c b/src/lib/libc/string/__strsignal.c index 1937e2d608..ae0df72cd3 100644 --- a/src/lib/libc/string/__strsignal.c +++ b/src/lib/libc/string/__strsignal.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 35 | static char *rcsid = "$OpenBSD: __strsignal.c,v 1.5 1996/09/25 13:19:01 deraadt Exp $"; |
36 | static char *rcsid = "$Id: __strsignal.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #ifdef NLS | 38 | #ifdef NLS |
@@ -46,15 +45,31 @@ static char *rcsid = "$Id: __strsignal.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt E | |||
46 | #define sys_siglist _sys_siglist | 45 | #define sys_siglist _sys_siglist |
47 | 46 | ||
48 | #include <stdio.h> | 47 | #include <stdio.h> |
48 | #include <limits.h> | ||
49 | #include <signal.h> | 49 | #include <signal.h> |
50 | #include <string.h> | 50 | #include <string.h> |
51 | 51 | ||
52 | static char *itoa(num) | ||
53 | int num; | ||
54 | { | ||
55 | static char buffer[11]; | ||
56 | char *p; | ||
57 | |||
58 | p = buffer + 4; | ||
59 | while (num >= 10) { | ||
60 | *--p = (num % 10) + '0'; | ||
61 | num /= 10; | ||
62 | } | ||
63 | *p = (num % 10) + '0'; | ||
64 | return p; | ||
65 | } | ||
66 | |||
52 | char * | 67 | char * |
53 | __strsignal(num, buf) | 68 | __strsignal(num, buf) |
54 | int num; | 69 | int num; |
55 | char *buf; | 70 | char *buf; |
56 | { | 71 | { |
57 | #define UPREFIX "Unknown signal: %u" | 72 | #define UPREFIX "Unknown signal: " |
58 | register unsigned int signum; | 73 | register unsigned int signum; |
59 | 74 | ||
60 | #ifdef NLS | 75 | #ifdef NLS |
@@ -65,17 +80,20 @@ __strsignal(num, buf) | |||
65 | signum = num; /* convert to unsigned */ | 80 | signum = num; /* convert to unsigned */ |
66 | if (signum < NSIG) { | 81 | if (signum < NSIG) { |
67 | #ifdef NLS | 82 | #ifdef NLS |
68 | strcpy(buf, catgets(catd, 2, signum, | 83 | strncpy(buf, catgets(catd, 2, signum, |
69 | (char *)sys_siglist[signum])); | 84 | (char *)sys_siglist[signum]), NL_TEXTMAX-1); |
85 | buf[NL_TEXTMAX-1] = '\0'; | ||
70 | #else | 86 | #else |
71 | return((char *)sys_siglist[signum]); | 87 | return((char *)sys_siglist[signum]); |
72 | #endif | 88 | #endif |
73 | } else { | 89 | } else { |
74 | #ifdef NLS | 90 | #ifdef NLS |
75 | sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), signum); | 91 | strncpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX-1); |
92 | buf[NL_TEXTMAX-1] = '\0'; | ||
76 | #else | 93 | #else |
77 | sprintf(buf, UPREFIX, signum); | 94 | strcpy(buf, UPREFIX); |
78 | #endif | 95 | #endif |
96 | strncat(buf, itoa(signum), NL_TEXTMAX-strlen(buf)-1); | ||
79 | } | 97 | } |
80 | 98 | ||
81 | #ifdef NLS | 99 | #ifdef NLS |
diff --git a/src/lib/libc/string/bcmp.3 b/src/lib/libc/string/bcmp.3 index 118c55c579..9234b5739d 100644 --- a/src/lib/libc/string/bcmp.3 +++ b/src/lib/libc/string/bcmp.3 | |||
@@ -31,8 +31,7 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" from: @(#)bcmp.3 5.4 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: bcmp.3,v 1.2 1996/08/19 08:33:56 tholo Exp $ |
35 | .\" $Id: bcmp.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
36 | .\" | 35 | .\" |
37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
38 | .Dt BCMP 3 | 37 | .Dt BCMP 3 |
diff --git a/src/lib/libc/string/bcmp.c b/src/lib/libc/string/bcmp.c index 2cc38baee3..4ed00975a4 100644 --- a/src/lib/libc/string/bcmp.c +++ b/src/lib/libc/string/bcmp.c | |||
@@ -32,15 +32,19 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)bcmp.c 5.6 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: bcmp.c,v 1.4 1996/08/19 08:33:57 tholo Exp $"; |
36 | static char *rcsid = "$Id: bcmp.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
38 | #ifndef _KERNEL | ||
39 | #include <string.h> | 39 | #include <string.h> |
40 | #else | ||
41 | #include <lib/libkern/libkern.h> | ||
42 | #endif | ||
40 | 43 | ||
41 | /* | 44 | /* |
42 | * bcmp -- vax cmpc3 instruction | 45 | * bcmp -- vax cmpc3 instruction |
43 | */ | 46 | */ |
47 | int | ||
44 | bcmp(b1, b2, length) | 48 | bcmp(b1, b2, length) |
45 | const void *b1, *b2; | 49 | const void *b1, *b2; |
46 | register size_t length; | 50 | register size_t length; |
diff --git a/src/lib/libc/string/bcopy.3 b/src/lib/libc/string/bcopy.3 index 6db3812caf..4e841562e0 100644 --- a/src/lib/libc/string/bcopy.3 +++ b/src/lib/libc/string/bcopy.3 | |||
@@ -32,8 +32,7 @@ | |||
32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
33 | .\" SUCH DAMAGE. | 33 | .\" SUCH DAMAGE. |
34 | .\" | 34 | .\" |
35 | .\" from: @(#)bcopy.3 5.3 (Berkeley) 4/19/91 | 35 | .\" $OpenBSD: bcopy.3,v 1.2 1996/08/19 08:33:57 tholo Exp $ |
36 | .\" $Id: bcopy.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
37 | .\" | 36 | .\" |
38 | .Dd April 19, 1991 | 37 | .Dd April 19, 1991 |
39 | .Dt BCOPY 3 | 38 | .Dt BCOPY 3 |
diff --git a/src/lib/libc/string/bcopy.c b/src/lib/libc/string/bcopy.c index 92feed66ea..023a3b2db2 100644 --- a/src/lib/libc/string/bcopy.c +++ b/src/lib/libc/string/bcopy.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)bcopy.c 5.11 (Berkeley) 6/21/91";*/ | 38 | static char *rcsid = "$OpenBSD: bcopy.c,v 1.2 1996/08/19 08:33:58 tholo Exp $"; |
39 | static char *rcsid = "$Id: bcopy.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/bm.3 b/src/lib/libc/string/bm.3 index 2264a6a1c4..c942930163 100644 --- a/src/lib/libc/string/bm.3 +++ b/src/lib/libc/string/bm.3 | |||
@@ -32,8 +32,7 @@ | |||
32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
33 | .\" SUCH DAMAGE. | 33 | .\" SUCH DAMAGE. |
34 | .\" | 34 | .\" |
35 | .\" from: @(#)bm.3 8.4 (Berkeley) 6/21/94 | 35 | .\" $OpenBSD: bm.3,v 1.2 1996/08/19 08:33:58 tholo Exp $ |
36 | .\" $Id: bm.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
37 | .\" | 36 | .\" |
38 | .TH BM 3 | 37 | .TH BM 3 |
39 | .SH NAME | 38 | .SH NAME |
diff --git a/src/lib/libc/string/bm.c b/src/lib/libc/string/bm.c index 68eac22ecc..b191d340f6 100644 --- a/src/lib/libc/string/bm.c +++ b/src/lib/libc/string/bm.c | |||
@@ -34,10 +34,9 @@ | |||
34 | * SUCH DAMAGE. | 34 | * SUCH DAMAGE. |
35 | */ | 35 | */ |
36 | 36 | ||
37 | #ifndef lint | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /* from: static char sccsid[] = "@(#)bm.c 8.7 (Berkeley) 6/21/94"; */ | 38 | static char *rcsid = "$OpenBSD: bm.c,v 1.3 1996/08/19 08:33:59 tholo Exp $"; |
39 | static char *rcsid = "$Id: bm.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | 39 | #endif /* LIBC_SCCS and not lint */ |
40 | #endif /* not lint */ | ||
41 | 40 | ||
42 | #include <sys/types.h> | 41 | #include <sys/types.h> |
43 | 42 | ||
diff --git a/src/lib/libc/string/bstring.3 b/src/lib/libc/string/bstring.3 index 12fcfb0cc1..b553fd0beb 100644 --- a/src/lib/libc/string/bstring.3 +++ b/src/lib/libc/string/bstring.3 | |||
@@ -31,8 +31,7 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" from: @(#)bstring.3 6.8 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: bstring.3,v 1.2 1996/08/19 08:33:59 tholo Exp $ |
35 | .\" $Id: bstring.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | 35 | .\" |
37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
38 | .Dt BSTRING 3 | 37 | .Dt BSTRING 3 |
diff --git a/src/lib/libc/string/bzero.3 b/src/lib/libc/string/bzero.3 index 4f0141e051..a8e55a63c1 100644 --- a/src/lib/libc/string/bzero.3 +++ b/src/lib/libc/string/bzero.3 | |||
@@ -31,8 +31,7 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" from: @(#)bzero.3 5.3 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: bzero.3,v 1.2 1996/08/19 08:34:00 tholo Exp $ |
35 | .\" $Id: bzero.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | 35 | .\" |
37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
38 | .Dt BZERO 3 | 37 | .Dt BZERO 3 |
diff --git a/src/lib/libc/string/bzero.c b/src/lib/libc/string/bzero.c index 4865e396ef..3e660a307f 100644 --- a/src/lib/libc/string/bzero.c +++ b/src/lib/libc/string/bzero.c | |||
@@ -32,11 +32,14 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)bzero.c 5.7 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: bzero.c,v 1.3 1996/08/19 08:34:00 tholo Exp $"; |
36 | static char *rcsid = "$Id: bzero.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
38 | #ifndef _KERNEL | ||
39 | #include <string.h> | 39 | #include <string.h> |
40 | #else | ||
41 | #include <lib/libkern/libkern.h> | ||
42 | #endif | ||
40 | 43 | ||
41 | /* | 44 | /* |
42 | * bzero -- vax movc5 instruction | 45 | * bzero -- vax movc5 instruction |
diff --git a/src/lib/libc/string/ffs.3 b/src/lib/libc/string/ffs.3 index 6464bea2b1..9ef08aef8e 100644 --- a/src/lib/libc/string/ffs.3 +++ b/src/lib/libc/string/ffs.3 | |||
@@ -31,8 +31,7 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" from: @(#)ffs.3 5.3 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: ffs.3,v 1.2 1996/08/19 08:34:01 tholo Exp $ |
35 | .\" $Id: ffs.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | 35 | .\" |
37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
38 | .Dt FFS 3 | 37 | .Dt FFS 3 |
diff --git a/src/lib/libc/string/ffs.c b/src/lib/libc/string/ffs.c index 42bc87ddea..a0767e50ad 100644 --- a/src/lib/libc/string/ffs.c +++ b/src/lib/libc/string/ffs.c | |||
@@ -32,11 +32,14 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)ffs.c 5.4 (Berkeley) 5/17/90";*/ | 35 | static char *rcsid = "$OpenBSD: ffs.c,v 1.3 1996/08/19 08:34:01 tholo Exp $"; |
36 | static char *rcsid = "$Id: ffs.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
38 | #ifndef _KERNEL | ||
39 | #include <string.h> | 39 | #include <string.h> |
40 | #else | ||
41 | #include <lib/libkern/libkern.h> | ||
42 | #endif | ||
40 | 43 | ||
41 | /* | 44 | /* |
42 | * ffs -- vax ffs instruction | 45 | * ffs -- vax ffs instruction |
diff --git a/src/lib/libc/string/index.3 b/src/lib/libc/string/index.3 index 847b03628b..d236a73a48 100644 --- a/src/lib/libc/string/index.3 +++ b/src/lib/libc/string/index.3 | |||
@@ -31,8 +31,7 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" from: @(#)index.3 5.3 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: index.3,v 1.4 1997/12/30 01:09:49 deraadt Exp $ |
35 | .\" $Id: index.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | 35 | .\" |
37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
38 | .Dt INDEX 3 | 37 | .Dt INDEX 3 |
@@ -55,9 +54,9 @@ locates the first character matching | |||
55 | in the null-terminated string | 54 | in the null-terminated string |
56 | .Fa s . | 55 | .Fa s . |
57 | .Sh RETURN VALUES | 56 | .Sh RETURN VALUES |
58 | The character | 57 | If the character |
59 | .Fa c | 58 | .Fa c |
60 | is returned if it is found; otherwise | 59 | is found, a pointer to it is returned; otherwise |
61 | .Dv NULL | 60 | .Dv NULL |
62 | is returned. | 61 | is returned. |
63 | If | 62 | If |
@@ -77,7 +76,7 @@ locates the terminating '\e0'. | |||
77 | .Xr strstr 3 , | 76 | .Xr strstr 3 , |
78 | .Xr strtok 3 | 77 | .Xr strtok 3 |
79 | .Sh HISTORY | 78 | .Sh HISTORY |
80 | A | 79 | An |
81 | .Fn index | 80 | .Fn index |
82 | function appeared in | 81 | function appeared in |
83 | .At v6 . | 82 | .At v6 . |
diff --git a/src/lib/libc/string/index.c b/src/lib/libc/string/index.c index 3d9c05f961..86c4e75f12 100644 --- a/src/lib/libc/string/index.c +++ b/src/lib/libc/string/index.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)index.c 5.7 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: index.c,v 1.2 1996/08/19 08:34:02 tholo Exp $"; |
36 | static char *rcsid = "$Id: index.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <string.h> | 38 | #include <string.h> |
diff --git a/src/lib/libc/string/memccpy.3 b/src/lib/libc/string/memccpy.3 index 61df704028..c2e15b1405 100644 --- a/src/lib/libc/string/memccpy.3 +++ b/src/lib/libc/string/memccpy.3 | |||
@@ -1,5 +1,7 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: memccpy.3,v 1.4 1998/06/15 17:55:09 mickey Exp $ |
2 | .\" All rights reserved. | 2 | .\" |
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | 5 | .\" |
4 | .\" Redistribution and use in source and binary forms, with or without | 6 | .\" Redistribution and use in source and binary forms, with or without |
5 | .\" modification, are permitted provided that the following conditions | 7 | .\" modification, are permitted provided that the following conditions |
@@ -29,14 +31,14 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
31 | .\" | 33 | .\" |
32 | .\" from: @(#)memccpy.3 5.4 (Berkeley) 4/19/91 | 34 | .\" @(#)memccpy.3 8.1 (Berkeley) 6/9/93 |
33 | .\" $Id: memccpy.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
34 | .\" | 35 | .\" |
35 | .Dd April 19, 1991 | 36 | .Dd June 9, 1993 |
36 | .Dt MEMCCPY 3 | 37 | .Dt MEMCCPY 3 |
37 | .Os | 38 | .Os |
38 | .Sh NAME | 39 | .Sh NAME |
39 | .Nm memccpy | 40 | .Nm memccpy |
41 | .Nd copy string until character found | ||
40 | .Sh SYNOPSIS | 42 | .Sh SYNOPSIS |
41 | .Fd #include <string.h> | 43 | .Fd #include <string.h> |
42 | .Ft void * | 44 | .Ft void * |
@@ -69,5 +71,5 @@ bytes are copied, and a NULL pointer is returned. | |||
69 | .Sh HISTORY | 71 | .Sh HISTORY |
70 | The | 72 | The |
71 | .Fn memccpy | 73 | .Fn memccpy |
72 | function is | 74 | function first appeared in |
73 | .Ud . | 75 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/memccpy.c b/src/lib/libc/string/memccpy.c index 3a1d7bcca1..020e6e5679 100644 --- a/src/lib/libc/string/memccpy.c +++ b/src/lib/libc/string/memccpy.c | |||
@@ -1,6 +1,8 @@ | |||
1 | /* $OpenBSD: memccpy.c,v 1.3 1997/08/20 04:09:39 millert Exp $ */ | ||
2 | |||
1 | /*- | 3 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 4 | * Copyright (c) 1990, 1993 |
3 | * All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. |
4 | * | 6 | * |
5 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions |
@@ -32,8 +34,11 @@ | |||
32 | */ | 34 | */ |
33 | 35 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 36 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)memccpy.c 5.8 (Berkeley) 5/30/91";*/ | 37 | #if 0 |
36 | static char *rcsid = "$Id: memccpy.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | 38 | static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93"; |
39 | #else | ||
40 | static char *rcsid = "$OpenBSD: memccpy.c,v 1.3 1997/08/20 04:09:39 millert Exp $"; | ||
41 | #endif | ||
37 | #endif /* LIBC_SCCS and not lint */ | 42 | #endif /* LIBC_SCCS and not lint */ |
38 | 43 | ||
39 | #include <string.h> | 44 | #include <string.h> |
diff --git a/src/lib/libc/string/memchr.3 b/src/lib/libc/string/memchr.3 index 265711e3b5..56a2aee9ce 100644 --- a/src/lib/libc/string/memchr.3 +++ b/src/lib/libc/string/memchr.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)memchr.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: memchr.3,v 1.2 1996/08/19 08:34:04 tholo Exp $ |
37 | .\" $Id: memchr.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt MEMCHR 3 | 39 | .Dt MEMCHR 3 |
diff --git a/src/lib/libc/string/memchr.c b/src/lib/libc/string/memchr.c index 61652c6bb1..2ebb5dab32 100644 --- a/src/lib/libc/string/memchr.c +++ b/src/lib/libc/string/memchr.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)memchr.c 5.6 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: memchr.c,v 1.2 1996/08/19 08:34:04 tholo Exp $"; |
39 | static char *rcsid = "$Id: memchr.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/memcmp.3 b/src/lib/libc/string/memcmp.3 index 13901c1009..34c5f60861 100644 --- a/src/lib/libc/string/memcmp.3 +++ b/src/lib/libc/string/memcmp.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)memcmp.3 5.5 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: memcmp.3,v 1.3 1996/12/10 09:06:11 deraadt Exp $ |
37 | .\" $Id: memcmp.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt MEMCMP 3 | 39 | .Dt MEMCMP 3 |
@@ -61,7 +60,7 @@ bytes long. | |||
61 | The | 60 | The |
62 | .Fn memcmp | 61 | .Fn memcmp |
63 | function | 62 | function |
64 | returns zero if the the two strings are identical, | 63 | returns zero if the two strings are identical, |
65 | otherwise returns the difference between the first two differing bytes | 64 | otherwise returns the difference between the first two differing bytes |
66 | (treated as unsigned char values, so that | 65 | (treated as unsigned char values, so that |
67 | .Sq Li \e200 | 66 | .Sq Li \e200 |
diff --git a/src/lib/libc/string/memcmp.c b/src/lib/libc/string/memcmp.c index 23d2ab2393..5ce33e2998 100644 --- a/src/lib/libc/string/memcmp.c +++ b/src/lib/libc/string/memcmp.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)memcmp.c 5.6 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: memcmp.c,v 1.2 1996/08/19 08:34:05 tholo Exp $"; |
39 | static char *rcsid = "$Id: memcmp.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/memcpy.3 b/src/lib/libc/string/memcpy.3 index 3f4bb643c9..75eb00b2d5 100644 --- a/src/lib/libc/string/memcpy.3 +++ b/src/lib/libc/string/memcpy.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)memcpy.3 5.5 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: memcpy.3,v 1.2 1996/08/19 08:34:06 tholo Exp $ |
37 | .\" $Id: memcpy.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt MEMCPY 3 | 39 | .Dt MEMCPY 3 |
diff --git a/src/lib/libc/string/memmove.3 b/src/lib/libc/string/memmove.3 index 24422e7971..95f6b7596c 100644 --- a/src/lib/libc/string/memmove.3 +++ b/src/lib/libc/string/memmove.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)memmove.3 5.5 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: memmove.3,v 1.2 1996/08/19 08:34:07 tholo Exp $ |
37 | .\" $Id: memmove.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt MEMMOVE 3 | 39 | .Dt MEMMOVE 3 |
diff --git a/src/lib/libc/string/memset.3 b/src/lib/libc/string/memset.3 index 1afc052182..e1d8583732 100644 --- a/src/lib/libc/string/memset.3 +++ b/src/lib/libc/string/memset.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)memset.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: memset.3,v 1.3 1997/08/24 21:56:45 deraadt Exp $ |
37 | .\" $Id: memset.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt MEMSET 3 | 39 | .Dt MEMSET 3 |
@@ -56,6 +55,12 @@ bytes of value | |||
56 | .Fa c | 55 | .Fa c |
57 | (converted to an unsigned char) to the string | 56 | (converted to an unsigned char) to the string |
58 | .Fa b . | 57 | .Fa b . |
58 | .Sh RETURN VALUES | ||
59 | The | ||
60 | .Fn memset | ||
61 | function | ||
62 | returns the original value of | ||
63 | .Fa b . | ||
59 | .Sh SEE ALSO | 64 | .Sh SEE ALSO |
60 | .Xr bzero 3 , | 65 | .Xr bzero 3 , |
61 | .Xr swab 3 | 66 | .Xr swab 3 |
diff --git a/src/lib/libc/string/memset.c b/src/lib/libc/string/memset.c index 117de2e80b..c3373a21a9 100644 --- a/src/lib/libc/string/memset.c +++ b/src/lib/libc/string/memset.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)memset.c 5.6 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: memset.c,v 1.2 1996/08/19 08:34:07 tholo Exp $"; |
39 | static char *rcsid = "$Id: memset.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/rindex.3 b/src/lib/libc/string/rindex.3 index b13b3513e0..db7f8e1cd8 100644 --- a/src/lib/libc/string/rindex.3 +++ b/src/lib/libc/string/rindex.3 | |||
@@ -31,8 +31,7 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" from: @(#)rindex.3 5.2 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: rindex.3,v 1.3 1997/12/30 01:09:49 deraadt Exp $ |
35 | .\" $Id: rindex.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | 35 | .\" |
37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
38 | .Dt RINDEX 3 | 37 | .Dt RINDEX 3 |
@@ -55,7 +54,7 @@ matching | |||
55 | .Em char ) | 54 | .Em char ) |
56 | in the null-terminated string | 55 | in the null-terminated string |
57 | .Fa s . | 56 | .Fa s . |
58 | The character c is returned if it is found; otherwise NULL is returned. | 57 | If the character c is found, a pointer to it is returned; otherwise NULL is returned. |
59 | If | 58 | If |
60 | .Fa c | 59 | .Fa c |
61 | is | 60 | is |
diff --git a/src/lib/libc/string/rindex.c b/src/lib/libc/string/rindex.c index 1b84c92072..f18553f667 100644 --- a/src/lib/libc/string/rindex.c +++ b/src/lib/libc/string/rindex.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)rindex.c 5.9 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: rindex.c,v 1.2 1996/08/19 08:34:08 tholo Exp $"; |
36 | static char *rcsid = "$Id: rindex.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <string.h> | 38 | #include <string.h> |
diff --git a/src/lib/libc/string/strcasecmp.3 b/src/lib/libc/string/strcasecmp.3 index 46e9010e4f..52a13055ee 100644 --- a/src/lib/libc/string/strcasecmp.3 +++ b/src/lib/libc/string/strcasecmp.3 | |||
@@ -1,5 +1,7 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: strcasecmp.3,v 1.4 1998/06/15 17:55:11 mickey Exp $ |
2 | .\" All rights reserved. | 2 | .\" |
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | 5 | .\" |
4 | .\" This code is derived from software contributed to Berkeley by | 6 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" Chris Torek. | 7 | .\" Chris Torek. |
@@ -31,10 +33,9 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
33 | .\" | 35 | .\" |
34 | .\" from: @(#)strcasecmp.3 5.4 (Berkeley) 4/19/91 | 36 | .\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93 |
35 | .\" $Id: strcasecmp.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | 37 | .\" |
37 | .Dd April 19, 1991 | 38 | .Dd June 9, 1993 |
38 | .Dt STRCASECMP 3 | 39 | .Dt STRCASECMP 3 |
39 | .Os | 40 | .Os |
40 | .Sh NAME | 41 | .Sh NAME |
@@ -84,5 +85,5 @@ The | |||
84 | .Fn strcasecmp | 85 | .Fn strcasecmp |
85 | and | 86 | and |
86 | .Fn strncasecmp | 87 | .Fn strncasecmp |
87 | functions are | 88 | functions first appeared in |
88 | .Ud . | 89 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/strcasecmp.c b/src/lib/libc/string/strcasecmp.c index 79bd0081e3..1f487524aa 100644 --- a/src/lib/libc/string/strcasecmp.c +++ b/src/lib/libc/string/strcasecmp.c | |||
@@ -1,6 +1,8 @@ | |||
1 | /* $OpenBSD: strcasecmp.c,v 1.3 1997/08/20 04:13:57 millert Exp $ */ | ||
2 | |||
1 | /* | 3 | /* |
2 | * Copyright (c) 1987 Regents of the University of California. | 4 | * Copyright (c) 1987, 1993 |
3 | * All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. |
4 | * | 6 | * |
5 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions |
@@ -31,13 +33,16 @@ | |||
31 | * SUCH DAMAGE. | 33 | * SUCH DAMAGE. |
32 | */ | 34 | */ |
33 | 35 | ||
36 | #include <string.h> | ||
37 | |||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 38 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static const char sccsid[] = "from: @(#)strcasecmp.c 5.10 (Berkeley) 1/26/91";*/ | 39 | #if 0 |
36 | static char *rcsid = "$Id: strcasecmp.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | 40 | static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; |
41 | #else | ||
42 | static char *rcsid = "$OpenBSD: strcasecmp.c,v 1.3 1997/08/20 04:13:57 millert Exp $"; | ||
43 | #endif | ||
37 | #endif /* LIBC_SCCS and not lint */ | 44 | #endif /* LIBC_SCCS and not lint */ |
38 | 45 | ||
39 | #include <string.h> | ||
40 | |||
41 | typedef unsigned char u_char; | 46 | typedef unsigned char u_char; |
42 | 47 | ||
43 | /* | 48 | /* |
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3 index 5357d65754..686afd3f2e 100644 --- a/src/lib/libc/string/strcat.3 +++ b/src/lib/libc/string/strcat.3 | |||
@@ -33,10 +33,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strcat.3 5.6 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strcat.3,v 1.3 1997/07/09 00:19:53 millert Exp $ |
37 | .\" $Id: strcat.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd July 8, 1997 |
40 | .Dt STRCAT 3 | 39 | .Dt STRCAT 3 |
41 | .Os | 40 | .Os |
42 | .Sh NAME | 41 | .Sh NAME |
@@ -69,7 +68,10 @@ The | |||
69 | function | 68 | function |
70 | appends not more than | 69 | appends not more than |
71 | .Fa count | 70 | .Fa count |
72 | characters. | 71 | characters where space for the terminating |
72 | .Ql \e0 | ||
73 | should not be included in | ||
74 | .Fa count . | ||
73 | .Sh RETURN VALUES | 75 | .Sh RETURN VALUES |
74 | The | 76 | The |
75 | .Fn strcat | 77 | .Fn strcat |
diff --git a/src/lib/libc/string/strcat.c b/src/lib/libc/string/strcat.c index e741b84f03..374a2b7464 100644 --- a/src/lib/libc/string/strcat.c +++ b/src/lib/libc/string/strcat.c | |||
@@ -32,11 +32,14 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strcat.c 5.6 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: strcat.c,v 1.4 1996/08/19 08:34:10 tholo Exp $"; |
36 | static char *rcsid = "$Id: strcat.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
38 | #ifndef _KERNEL | ||
39 | #include <string.h> | 39 | #include <string.h> |
40 | #else | ||
41 | #include <lib/libkern/libkern.h> | ||
42 | #endif | ||
40 | 43 | ||
41 | char * | 44 | char * |
42 | strcat(s, append) | 45 | strcat(s, append) |
@@ -46,6 +49,6 @@ strcat(s, append) | |||
46 | char *save = s; | 49 | char *save = s; |
47 | 50 | ||
48 | for (; *s; ++s); | 51 | for (; *s; ++s); |
49 | while (*s++ = *append++); | 52 | while ((*s++ = *append++) != '\0'); |
50 | return(save); | 53 | return(save); |
51 | } | 54 | } |
diff --git a/src/lib/libc/string/strchr.3 b/src/lib/libc/string/strchr.3 index 18b50301f3..c3bc2f8817 100644 --- a/src/lib/libc/string/strchr.3 +++ b/src/lib/libc/string/strchr.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strchr.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strchr.3,v 1.3 1997/12/29 22:31:50 deraadt Exp $ |
37 | .\" $Id: strchr.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRCHR 3 | 39 | .Dt STRCHR 3 |
@@ -54,7 +53,7 @@ function locates the first occurrence of | |||
54 | in the string pointed to by | 53 | in the string pointed to by |
55 | .Ar s . | 54 | .Ar s . |
56 | The terminating | 55 | The terminating |
57 | .Dv NULL | 56 | .Dv NUL |
58 | character is considered part of the string. | 57 | character is considered part of the string. |
59 | If | 58 | If |
60 | .Fa c | 59 | .Fa c |
diff --git a/src/lib/libc/string/strcmp.3 b/src/lib/libc/string/strcmp.3 index fecaa85410..91e51d68fc 100644 --- a/src/lib/libc/string/strcmp.3 +++ b/src/lib/libc/string/strcmp.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strcmp.3 5.6 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strcmp.3,v 1.2 1996/08/19 08:34:11 tholo Exp $ |
37 | .\" $Id: strcmp.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRCMP 3 | 39 | .Dt STRCMP 3 |
diff --git a/src/lib/libc/string/strcmp.c b/src/lib/libc/string/strcmp.c index ae19e2e26e..9a5b208323 100644 --- a/src/lib/libc/string/strcmp.c +++ b/src/lib/libc/string/strcmp.c | |||
@@ -35,11 +35,14 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)strcmp.c 5.5 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strcmp.c,v 1.3 1996/08/19 08:34:12 tholo Exp $"; |
39 | static char *rcsid = "$Id: strcmp.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
41 | #ifndef _KERNEL | ||
42 | #include <string.h> | 42 | #include <string.h> |
43 | #else | ||
44 | #include <lib/libkern/libkern.h> | ||
45 | #endif | ||
43 | 46 | ||
44 | /* | 47 | /* |
45 | * Compare strings. | 48 | * Compare strings. |
diff --git a/src/lib/libc/string/strcoll.3 b/src/lib/libc/string/strcoll.3 index 12f73f98f2..20af998885 100644 --- a/src/lib/libc/string/strcoll.3 +++ b/src/lib/libc/string/strcoll.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strcoll.3 5.6 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strcoll.3,v 1.2 1996/08/19 08:34:12 tholo Exp $ |
37 | .\" $Id: strcoll.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRCOLL 3 | 39 | .Dt STRCOLL 3 |
diff --git a/src/lib/libc/string/strcoll.c b/src/lib/libc/string/strcoll.c index 86c742cba9..dca0b10d25 100644 --- a/src/lib/libc/string/strcoll.c +++ b/src/lib/libc/string/strcoll.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)strcoll.c 5.2 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strcoll.c,v 1.2 1996/08/19 08:34:13 tholo Exp $"; |
39 | static char *rcsid = "$Id: strcoll.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3 index 1ca12c2707..33da6e619e 100644 --- a/src/lib/libc/string/strcpy.3 +++ b/src/lib/libc/string/strcpy.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strcpy.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strcpy.3,v 1.2 1996/08/19 08:34:13 tholo Exp $ |
37 | .\" $Id: strcpy.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRCPY 3 | 39 | .Dt STRCPY 3 |
diff --git a/src/lib/libc/string/strcpy.c b/src/lib/libc/string/strcpy.c index 669bfde23e..76b063fc10 100644 --- a/src/lib/libc/string/strcpy.c +++ b/src/lib/libc/string/strcpy.c | |||
@@ -32,11 +32,14 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strcpy.c 5.7 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: strcpy.c,v 1.4 1996/08/19 08:34:14 tholo Exp $"; |
36 | static char *rcsid = "$Id: strcpy.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
38 | #ifndef _KERNEL | ||
39 | #include <string.h> | 39 | #include <string.h> |
40 | #else | ||
41 | #include <lib/libkern/libkern.h> | ||
42 | #endif | ||
40 | 43 | ||
41 | char * | 44 | char * |
42 | strcpy(to, from) | 45 | strcpy(to, from) |
@@ -45,6 +48,6 @@ strcpy(to, from) | |||
45 | { | 48 | { |
46 | char *save = to; | 49 | char *save = to; |
47 | 50 | ||
48 | for (; *to = *from; ++from, ++to); | 51 | for (; (*to = *from) != '\0'; ++from, ++to); |
49 | return(save); | 52 | return(save); |
50 | } | 53 | } |
diff --git a/src/lib/libc/string/strcspn.3 b/src/lib/libc/string/strcspn.3 index cc9e5c2fe3..93c6d8f84c 100644 --- a/src/lib/libc/string/strcspn.3 +++ b/src/lib/libc/string/strcspn.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strcspn.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strcspn.3,v 1.2 1996/08/19 08:34:14 tholo Exp $ |
37 | .\" $Id: strcspn.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRCSPN 3 | 39 | .Dt STRCSPN 3 |
diff --git a/src/lib/libc/string/strcspn.c b/src/lib/libc/string/strcspn.c index acb4d2a3af..f7261564a7 100644 --- a/src/lib/libc/string/strcspn.c +++ b/src/lib/libc/string/strcspn.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)strcspn.c 5.6 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strcspn.c,v 1.2 1996/08/19 08:34:15 tholo Exp $"; |
39 | static char *rcsid = "$Id: strcspn.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/strdup.3 b/src/lib/libc/string/strdup.3 index 925cbf3d46..6abbba57cb 100644 --- a/src/lib/libc/string/strdup.3 +++ b/src/lib/libc/string/strdup.3 | |||
@@ -1,5 +1,7 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: strdup.3,v 1.6 1998/08/19 05:51:14 pjanzen Exp $ |
2 | .\" All rights reserved. | 2 | .\" |
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | 5 | .\" |
4 | .\" Redistribution and use in source and binary forms, with or without | 6 | .\" Redistribution and use in source and binary forms, with or without |
5 | .\" modification, are permitted provided that the following conditions | 7 | .\" modification, are permitted provided that the following conditions |
@@ -29,10 +31,9 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
31 | .\" | 33 | .\" |
32 | .\" from: @(#)strdup.3 5.3 (Berkeley) 4/19/91 | 34 | .\" @(#)strdup.3 8.1 (Berkeley) 6/9/93 |
33 | .\" $Id: strdup.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
34 | .\" | 35 | .\" |
35 | .Dd April 19, 1991 | 36 | .Dd June 9, 1993 |
36 | .Dt STRDUP 3 | 37 | .Dt STRDUP 3 |
37 | .Os | 38 | .Os |
38 | .Sh NAME | 39 | .Sh NAME |
@@ -53,13 +54,15 @@ does the copy, and returns a pointer to it. | |||
53 | The pointer may subsequently be used as an | 54 | The pointer may subsequently be used as an |
54 | argument to the function | 55 | argument to the function |
55 | .Xr free 3 . | 56 | .Xr free 3 . |
57 | .Pp | ||
58 | If insufficient memory is available, NULL is returned. | ||
56 | .Sh SEE ALSO | 59 | .Sh SEE ALSO |
57 | .Xr free 3 , | 60 | .Xr free 3 , |
58 | .Xr malloc 3 , | 61 | .Xr malloc 3 , |
59 | .Xt strcpy 3 , | 62 | .Xr strcpy 3 , |
60 | .Xt strlen 3 | 63 | .Xr strlen 3 |
61 | .Sh HISTORY | 64 | .Sh HISTORY |
62 | The | 65 | The |
63 | .Fn strdup | 66 | .Fn strdup |
64 | function | 67 | function first appeared in |
65 | .Ud . | 68 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/strdup.c b/src/lib/libc/string/strdup.c index 27ede44110..be7f7ad094 100644 --- a/src/lib/libc/string/strdup.c +++ b/src/lib/libc/string/strdup.c | |||
@@ -1,6 +1,8 @@ | |||
1 | /* $OpenBSD: strdup.c,v 1.3 1997/08/20 04:18:52 millert Exp $ */ | ||
2 | |||
1 | /* | 3 | /* |
2 | * Copyright (c) 1988 The Regents of the University of California. | 4 | * Copyright (c) 1988, 1993 |
3 | * All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. |
4 | * | 6 | * |
5 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions |
@@ -32,10 +34,16 @@ | |||
32 | */ | 34 | */ |
33 | 35 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 36 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strdup.c 5.4 (Berkeley) 2/24/91";*/ | 37 | #if 0 |
36 | static char *rcsid = "$Id: strdup.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | 38 | static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; |
39 | #else | ||
40 | static char *rcsid = "$OpenBSD: strdup.c,v 1.3 1997/08/20 04:18:52 millert Exp $"; | ||
41 | #endif | ||
37 | #endif /* LIBC_SCCS and not lint */ | 42 | #endif /* LIBC_SCCS and not lint */ |
38 | 43 | ||
44 | #include <sys/types.h> | ||
45 | |||
46 | #include <stddef.h> | ||
39 | #include <stdlib.h> | 47 | #include <stdlib.h> |
40 | #include <string.h> | 48 | #include <string.h> |
41 | 49 | ||
@@ -43,12 +51,12 @@ char * | |||
43 | strdup(str) | 51 | strdup(str) |
44 | const char *str; | 52 | const char *str; |
45 | { | 53 | { |
46 | size_t len; | 54 | size_t siz; |
47 | char *copy; | 55 | char *copy; |
48 | 56 | ||
49 | len = strlen(str) + 1; | 57 | siz = strlen(str) + 1; |
50 | if (!(copy = malloc(len))) | 58 | if ((copy = malloc(siz)) == NULL) |
51 | return((char *)NULL); | 59 | return(NULL); |
52 | memcpy(copy, str, len); | 60 | (void)memcpy(copy, str, siz); |
53 | return(copy); | 61 | return(copy); |
54 | } | 62 | } |
diff --git a/src/lib/libc/string/strerror.3 b/src/lib/libc/string/strerror.3 index c9d8504dbb..487c2b0e9f 100644 --- a/src/lib/libc/string/strerror.3 +++ b/src/lib/libc/string/strerror.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strerror.3 6.9 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strerror.3,v 1.2 1996/08/19 08:34:16 tholo Exp $ |
37 | .\" $Id: strerror.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRERROR 3 | 39 | .Dt STRERROR 3 |
diff --git a/src/lib/libc/string/strerror.c b/src/lib/libc/string/strerror.c index c3f5ab5d98..0e2690c3dd 100644 --- a/src/lib/libc/string/strerror.c +++ b/src/lib/libc/string/strerror.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 35 | static char *rcsid = "$OpenBSD: strerror.c,v 1.2 1996/08/19 08:34:17 tholo Exp $"; |
36 | static char *rcsid = "$Id: strerror.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <string.h> | 38 | #include <string.h> |
diff --git a/src/lib/libc/string/strftime.3 b/src/lib/libc/string/strftime.3 deleted file mode 100644 index f14db4bb13..0000000000 --- a/src/lib/libc/string/strftime.3 +++ /dev/null | |||
@@ -1,202 +0,0 @@ | |||
1 | .\" Copyright (c) 1989, 1991 The Regents of the University of California. | ||
2 | .\" All rights reserved. | ||
3 | .\" | ||
4 | .\" This code is derived from software contributed to Berkeley by | ||
5 | .\" the American National Standards Committee X3, on Information | ||
6 | .\" Processing Systems. | ||
7 | .\" | ||
8 | .\" Redistribution and use in source and binary forms, with or without | ||
9 | .\" modification, are permitted provided that the following conditions | ||
10 | .\" are met: | ||
11 | .\" 1. Redistributions of source code must retain the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer. | ||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer in the | ||
15 | .\" documentation and/or other materials provided with the distribution. | ||
16 | .\" 3. All advertising materials mentioning features or use of this software | ||
17 | .\" must display the following acknowledgement: | ||
18 | .\" This product includes software developed by the University of | ||
19 | .\" California, Berkeley and its contributors. | ||
20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
21 | .\" may be used to endorse or promote products derived from this software | ||
22 | .\" without specific prior written permission. | ||
23 | .\" | ||
24 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
25 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
26 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
27 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
28 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
29 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
30 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
31 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
32 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
34 | .\" SUCH DAMAGE. | ||
35 | .\" | ||
36 | .\" from: @(#)strftime.3 5.12 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strftime.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRFTIME 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strftime | ||
44 | .Nd format date and time | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <time.h> | ||
47 | .Ft size_t | ||
48 | .Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strftime | ||
52 | function formats the information from | ||
53 | .Fa timeptr | ||
54 | into the buffer | ||
55 | .Fa buf | ||
56 | according to the string pointed to by | ||
57 | .Fa format . | ||
58 | .Pp | ||
59 | The | ||
60 | .Fa format | ||
61 | string consists of zero or more conversion specifications and | ||
62 | ordinary characters. | ||
63 | All ordinary characters are copied directly into the buffer. | ||
64 | A conversion specification consists of a percent sign | ||
65 | .Ql % | ||
66 | and one other character. | ||
67 | .Pp | ||
68 | No more than | ||
69 | .Fa maxsize | ||
70 | characters will be placed into the array. | ||
71 | If the total number of resulting characters, including the terminating | ||
72 | null character, is not more than | ||
73 | .Fa maxsize , | ||
74 | .Fn strftime | ||
75 | returns the number of characters in the array, not counting the | ||
76 | terminating null. | ||
77 | Otherwise, zero is returned. | ||
78 | .Pp | ||
79 | Each conversion specification is replaced by the characters as | ||
80 | follows which are then copied into the buffer. | ||
81 | .Bl -tag -width "xxxx" | ||
82 | .It Cm \&%A | ||
83 | is replaced by the locale's full weekday name. | ||
84 | .It Cm %a | ||
85 | is replaced by the locale's abbreviated weekday name. | ||
86 | .It Cm \&%B | ||
87 | is replaced by the locale's full month name. | ||
88 | .It Cm \&%b No or Cm \&%h | ||
89 | is replaced by the locale's abbreviated month name. | ||
90 | .It Cm \&%C | ||
91 | is replaced by the century (a year divided by 100 and truncated to an integer) | ||
92 | as a decimal number (00-99). | ||
93 | .It Cm \&%c | ||
94 | is replaced by the locale's appropriate date and time representation. | ||
95 | .It Cm \&%D | ||
96 | is replaced by the date in the format | ||
97 | .Dq Li %m/%d/%y . | ||
98 | .It Cm \&%d | ||
99 | is replaced by the day of the month as a decimal number (01-31). | ||
100 | .It Cm \&%e | ||
101 | is replaced by the day of month as a decimal number (1-31); | ||
102 | single digits are preceded by a blank. | ||
103 | .It Cm \&%H | ||
104 | is replaced by the hour (24-hour clock) as a decimal number (00-23). | ||
105 | .It Cm \&%I | ||
106 | is replaced by the hour (12-hour clock) as a decimal number (01-12). | ||
107 | .It Cm \&%j | ||
108 | is replaced by the day of the year as a decimal number (001-366). | ||
109 | .It Cm \&%k | ||
110 | is replaced by the hour (24-hour clock) as a decimal number (0-23); | ||
111 | single digits are preceded by a blank. | ||
112 | .It Cm \&%l | ||
113 | is replaced by the hour (12-hour clock) as a decimal number (1-12); | ||
114 | single digits are preceded by a blank. | ||
115 | .It Cm \&%M | ||
116 | is replaced by the minute as a decimal number (00-59). | ||
117 | .It Cm %m | ||
118 | is replaced by the month as a decimal number (01-12). | ||
119 | .It Cm %n | ||
120 | is replaced by a newline. | ||
121 | .It Cm %p | ||
122 | is replaced by the locale's equivalent of either | ||
123 | .Dq Tn AM | ||
124 | or | ||
125 | .Dq Tn PM . | ||
126 | .It Cm \&%R | ||
127 | is replaced by the time in the format | ||
128 | .Dq Li %H:%M . | ||
129 | .It Cm \&%r | ||
130 | is replaced by the locale's representation of 12-hour clock time | ||
131 | using AM/PM notation. | ||
132 | .It Cm \&%T | ||
133 | is replaced by the time in the format | ||
134 | .Dq Li %H:%M:%S . | ||
135 | .It Cm \&%t | ||
136 | is replaced by a tab. | ||
137 | .It Cm \&%S | ||
138 | is replaced by the second as a decimal number (00-60). | ||
139 | .It Cm %s | ||
140 | is replaced by the number of seconds since the Epoch, UCT (see | ||
141 | .Xr mktime 3 ) . | ||
142 | .It Cm \&%U | ||
143 | is replaced by the week number of the year (Sunday as the first day of | ||
144 | the week) as a decimal number (00-53). | ||
145 | .It Cm \&%u | ||
146 | is replaced by the weekday (Monday as the first day of the week) | ||
147 | as a decimal number (1-7). | ||
148 | .It Cm \&%V | ||
149 | is replaced by the week number of the year (Monday as the first day of | ||
150 | the week) as a decimal number (01-53). If the week containing January | ||
151 | 1 has four or more days in the new year, then it is week 1; otherwise | ||
152 | it is week 53 of the previous year, and the next week is week 1. | ||
153 | .It Cm \&%W | ||
154 | is replaced by the week number of the year (Monday as the first day of | ||
155 | the week) as a decimal number (00-53). | ||
156 | .It Cm \&%w | ||
157 | is replaced by the weekday (Sunday as the first day of the week) | ||
158 | as a decimal number (0-6). | ||
159 | .It Cm \&%X | ||
160 | is replaced by the locale's appropriate date representation. | ||
161 | .It Cm \&%x | ||
162 | is replaced by the locale's appropriate time representation. | ||
163 | .It Cm \&%Y | ||
164 | is replaced by the year with century as a decimal number. | ||
165 | .It Cm \&%y | ||
166 | is replaced by the year without century as a decimal number (00-99). | ||
167 | .It Cm \&%Z | ||
168 | is replaced by the time zone name. | ||
169 | .It Cm %% | ||
170 | is replaced by | ||
171 | .Ql % . | ||
172 | .El | ||
173 | .Sh SEE ALSO | ||
174 | .Xr date 1 , | ||
175 | .Xr ctime 3 , | ||
176 | .Xr printf 1 , | ||
177 | .Xr printf 3 | ||
178 | .Sh STANDARDS | ||
179 | The | ||
180 | .Fn strftime | ||
181 | function | ||
182 | conforms to | ||
183 | .St -ansiC . | ||
184 | The | ||
185 | .Ql \&%C , | ||
186 | .Ql \&%D , | ||
187 | .Ql \&%e , | ||
188 | .Ql \&%h , | ||
189 | .Ql \&%k , | ||
190 | .Ql \&%l , | ||
191 | .Ql \&%n , | ||
192 | .Ql \&%r , | ||
193 | .Ql \&%R , | ||
194 | .Ql \&%s . | ||
195 | .Ql \&%t , | ||
196 | .Ql \&%T , | ||
197 | .Ql \&%u , | ||
198 | and | ||
199 | .Ql \&%V | ||
200 | conversion specifications are extensions. | ||
201 | .Sh BUGS | ||
202 | There is no conversion specification for the phase of the moon. | ||
diff --git a/src/lib/libc/string/strftime.c b/src/lib/libc/string/strftime.c deleted file mode 100644 index fffa9ecbb0..0000000000 --- a/src/lib/libc/string/strftime.c +++ /dev/null | |||
@@ -1,317 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 1989 The Regents of the University of California. | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * 1. Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * 2. Redistributions in binary form must reproduce the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer in the | ||
12 | * documentation and/or other materials provided with the distribution. | ||
13 | * 3. All advertising materials mentioning features or use of this software | ||
14 | * must display the following acknowledgement: | ||
15 | * This product includes software developed by the University of | ||
16 | * California, Berkeley and its contributors. | ||
17 | * 4. Neither the name of the University nor the names of its contributors | ||
18 | * may be used to endorse or promote products derived from this software | ||
19 | * without specific prior written permission. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
31 | * SUCH DAMAGE. | ||
32 | */ | ||
33 | |||
34 | #if defined(LIBC_SCCS) && !defined(lint) | ||
35 | /*static char *sccsid = "from: @(#)strftime.c 5.11 (Berkeley) 2/24/91";*/ | ||
36 | static char *rcsid = "$Id: strftime.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <sys/localedef.h> | ||
40 | #include <locale.h> | ||
41 | #include <string.h> | ||
42 | #include <tzfile.h> | ||
43 | #include <time.h> | ||
44 | |||
45 | static size_t gsize; | ||
46 | static char *pt; | ||
47 | static int _add(), _conv(), _secs(); | ||
48 | static size_t _fmt(); | ||
49 | |||
50 | size_t | ||
51 | strftime(s, maxsize, format, t) | ||
52 | char *s; | ||
53 | size_t maxsize; | ||
54 | const char *format; | ||
55 | const struct tm *t; | ||
56 | { | ||
57 | tzset(); | ||
58 | |||
59 | pt = s; | ||
60 | if ((gsize = maxsize) < 1) | ||
61 | return(0); | ||
62 | if (_fmt(format, t)) { | ||
63 | *pt = '\0'; | ||
64 | return(maxsize - gsize); | ||
65 | } | ||
66 | return(0); | ||
67 | } | ||
68 | |||
69 | #define SUN_WEEK(t) (((t)->tm_yday + 7 - \ | ||
70 | ((t)->tm_wday)) / 7) | ||
71 | #define MON_WEEK(t) (((t)->tm_yday + 7 - \ | ||
72 | ((t)->tm_wday ? (t)->tm_wday - 1 : 6)) / 7) | ||
73 | static size_t | ||
74 | _fmt(format, t) | ||
75 | register char *format; | ||
76 | struct tm *t; | ||
77 | { | ||
78 | for (; *format; ++format) { | ||
79 | if (*format == '%') { | ||
80 | ++format; | ||
81 | if (*format == 'E') { | ||
82 | /* Alternate Era */ | ||
83 | ++format; | ||
84 | } else if (*format == 'O') { | ||
85 | /* Alternate numeric symbols */ | ||
86 | ++format; | ||
87 | } | ||
88 | switch(*format) { | ||
89 | case '\0': | ||
90 | --format; | ||
91 | break; | ||
92 | case 'A': | ||
93 | if (t->tm_wday < 0 || t->tm_wday > 6) | ||
94 | return(0); | ||
95 | if (!_add(_CurrentTimeLocale->day[t->tm_wday])) | ||
96 | return(0); | ||
97 | continue; | ||
98 | case 'a': | ||
99 | if (t->tm_wday < 0 || t->tm_wday > 6) | ||
100 | return(0); | ||
101 | if (!_add(_CurrentTimeLocale->abday[t->tm_wday])) | ||
102 | return(0); | ||
103 | continue; | ||
104 | case 'B': | ||
105 | if (t->tm_mon < 0 || t->tm_mon > 11) | ||
106 | return(0); | ||
107 | if (!_add(_CurrentTimeLocale->mon[t->tm_mon])) | ||
108 | return(0); | ||
109 | continue; | ||
110 | case 'b': | ||
111 | case 'h': | ||
112 | if (t->tm_mon < 0 || t->tm_mon > 11) | ||
113 | return(0); | ||
114 | if (!_add(_CurrentTimeLocale->abmon[t->tm_mon])) | ||
115 | return(0); | ||
116 | continue; | ||
117 | case 'C': | ||
118 | if (!_conv((t->tm_year + TM_YEAR_BASE) / 100, | ||
119 | 2, '0')) | ||
120 | return(0); | ||
121 | continue; | ||
122 | case 'c': | ||
123 | if (!_fmt(_CurrentTimeLocale->d_t_fmt, t)) | ||
124 | return(0); | ||
125 | continue; | ||
126 | case 'D': | ||
127 | if (!_fmt("%m/%d/%y", t)) | ||
128 | return(0); | ||
129 | continue; | ||
130 | case 'd': | ||
131 | if (!_conv(t->tm_mday, 2, '0')) | ||
132 | return(0); | ||
133 | continue; | ||
134 | case 'e': | ||
135 | if (!_conv(t->tm_mday, 2, ' ')) | ||
136 | return(0); | ||
137 | continue; | ||
138 | case 'H': | ||
139 | if (!_conv(t->tm_hour, 2, '0')) | ||
140 | return(0); | ||
141 | continue; | ||
142 | case 'I': | ||
143 | if (!_conv(t->tm_hour % 12 ? | ||
144 | t->tm_hour % 12 : 12, 2, '0')) | ||
145 | return(0); | ||
146 | continue; | ||
147 | case 'j': | ||
148 | if (!_conv(t->tm_yday + 1, 3, '0')) | ||
149 | return(0); | ||
150 | continue; | ||
151 | case 'k': | ||
152 | if (!_conv(t->tm_hour, 2, ' ')) | ||
153 | return(0); | ||
154 | continue; | ||
155 | case 'l': | ||
156 | if (!_conv(t->tm_hour % 12 ? | ||
157 | t->tm_hour % 12: 12, 2, ' ')) | ||
158 | return(0); | ||
159 | continue; | ||
160 | case 'M': | ||
161 | if (!_conv(t->tm_min, 2, '0')) | ||
162 | return(0); | ||
163 | continue; | ||
164 | case 'm': | ||
165 | if (!_conv(t->tm_mon + 1, 2, '0')) | ||
166 | return(0); | ||
167 | continue; | ||
168 | case 'n': | ||
169 | if (!_add("\n")) | ||
170 | return(0); | ||
171 | continue; | ||
172 | case 'p': | ||
173 | if (!_add(_CurrentTimeLocale->am_pm[t->tm_hour >= 12])) | ||
174 | return(0); | ||
175 | continue; | ||
176 | case 'R': | ||
177 | if (!_fmt("%H:%M", t)) | ||
178 | return(0); | ||
179 | continue; | ||
180 | case 'r': | ||
181 | if (!_fmt(_CurrentTimeLocale->t_fmt_ampm, t)) | ||
182 | return(0); | ||
183 | continue; | ||
184 | case 'S': | ||
185 | if (!_conv(t->tm_sec, 2, '0')) | ||
186 | return(0); | ||
187 | continue; | ||
188 | case 's': | ||
189 | if (!_secs(t)) | ||
190 | return(0); | ||
191 | continue; | ||
192 | case 'T': | ||
193 | if (!_fmt("%H:%M:%S", t)) | ||
194 | return(0); | ||
195 | continue; | ||
196 | case 't': | ||
197 | if (!_add("\t")) | ||
198 | return(0); | ||
199 | continue; | ||
200 | case 'U': | ||
201 | if (!_conv(SUN_WEEK(t), 2, '0')) | ||
202 | return(0); | ||
203 | continue; | ||
204 | case 'u': | ||
205 | if (!_conv(t->tm_wday ? t->tm_wday : 7, 2, '0')) | ||
206 | return(0); | ||
207 | continue; | ||
208 | case 'V': | ||
209 | { | ||
210 | /* ISO 8601 Week Of Year: | ||
211 | If the week (Monday - Sunday) containing | ||
212 | January 1 has four or more days in the new | ||
213 | year, then it is week 1; otherwise it is | ||
214 | week 53 of the previous year and the next | ||
215 | week is week one. */ | ||
216 | |||
217 | int week = MON_WEEK(t); | ||
218 | |||
219 | if (((t->tm_yday + 7 - (t->tm_wday + 1)) % 7) >= 4) { | ||
220 | week++; | ||
221 | } else if (week == 0) { | ||
222 | week = 53; | ||
223 | } | ||
224 | |||
225 | if (!_conv(week, 2, '0')) | ||
226 | return(0); | ||
227 | continue; | ||
228 | } | ||
229 | case 'W': | ||
230 | if (!_conv(MON_WEEK(t), 2, '0')) | ||
231 | return(0); | ||
232 | continue; | ||
233 | case 'w': | ||
234 | if (!_conv(t->tm_wday, 1, '0')) | ||
235 | return(0); | ||
236 | continue; | ||
237 | case 'x': | ||
238 | if (!_fmt(_CurrentTimeLocale->d_fmt, t)) | ||
239 | return(0); | ||
240 | continue; | ||
241 | case 'X': | ||
242 | if (!_fmt(_CurrentTimeLocale->t_fmt, t)) | ||
243 | return(0); | ||
244 | continue; | ||
245 | case 'y': | ||
246 | if (!_conv((t->tm_year + TM_YEAR_BASE) % 100, | ||
247 | 2, '0')) | ||
248 | return(0); | ||
249 | continue; | ||
250 | case 'Y': | ||
251 | if (!_conv((t->tm_year + TM_YEAR_BASE), 4, '0')) | ||
252 | return(0); | ||
253 | continue; | ||
254 | case 'Z': | ||
255 | if (t->tm_zone && !_add(t->tm_zone)) | ||
256 | return(0); | ||
257 | continue; | ||
258 | case '%': | ||
259 | /* | ||
260 | * X311J/88-090 (4.12.3.5): if conversion char is | ||
261 | * undefined, behavior is undefined. Print out the | ||
262 | * character itself as printf(3) does. | ||
263 | */ | ||
264 | default: | ||
265 | break; | ||
266 | } | ||
267 | } | ||
268 | if (!gsize--) | ||
269 | return(0); | ||
270 | *pt++ = *format; | ||
271 | } | ||
272 | return(gsize); | ||
273 | } | ||
274 | |||
275 | static | ||
276 | _secs(t) | ||
277 | struct tm *t; | ||
278 | { | ||
279 | static char buf[15]; | ||
280 | register time_t s; | ||
281 | register char *p; | ||
282 | struct tm tmp; | ||
283 | |||
284 | /* Make a copy, mktime(3) modifies the tm struct. */ | ||
285 | tmp = *t; | ||
286 | s = mktime(&tmp); | ||
287 | for (p = buf + sizeof(buf) - 2; s > 0 && p > buf; s /= 10) | ||
288 | *p-- = s % 10 + '0'; | ||
289 | return(_add(++p)); | ||
290 | } | ||
291 | |||
292 | static | ||
293 | _conv(n, digits, pad) | ||
294 | int n, digits; | ||
295 | char pad; | ||
296 | { | ||
297 | static char buf[10]; | ||
298 | register char *p; | ||
299 | |||
300 | for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits) | ||
301 | *p-- = n % 10 + '0'; | ||
302 | while (p > buf && digits-- > 0) | ||
303 | *p-- = pad; | ||
304 | return(_add(++p)); | ||
305 | } | ||
306 | |||
307 | static | ||
308 | _add(str) | ||
309 | register char *str; | ||
310 | { | ||
311 | for (;; ++pt, --gsize) { | ||
312 | if (!gsize) | ||
313 | return(0); | ||
314 | if (!(*pt = *str++)) | ||
315 | return(1); | ||
316 | } | ||
317 | } | ||
diff --git a/src/lib/libc/string/string.3 b/src/lib/libc/string/string.3 index aaf97e0321..323d4f3040 100644 --- a/src/lib/libc/string/string.3 +++ b/src/lib/libc/string/string.3 | |||
@@ -31,8 +31,7 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" from: @(#)string.3 6.9 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: string.3,v 1.3 1998/09/06 22:23:18 aaron Exp $ |
35 | .\" $Id: string.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
36 | .\" | 35 | .\" |
37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
38 | .Dt STRING 3 | 37 | .Dt STRING 3 |
@@ -103,7 +102,7 @@ | |||
103 | .Fn rindex "const char *s" "int c" | 102 | .Fn rindex "const char *s" "int c" |
104 | .Sh DESCRIPTION | 103 | .Sh DESCRIPTION |
105 | The string functions | 104 | The string functions |
106 | functions manipulate strings terminated by a | 105 | manipulate strings terminated by a |
107 | null byte. | 106 | null byte. |
108 | .Pp | 107 | .Pp |
109 | See the specific manual pages for more information. | 108 | See the specific manual pages for more information. |
diff --git a/src/lib/libc/string/strlcat.c b/src/lib/libc/string/strlcat.c new file mode 100644 index 0000000000..2e8c56926e --- /dev/null +++ b/src/lib/libc/string/strlcat.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* $OpenBSD: strlcat.c,v 1.1 1998/07/01 01:29:45 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The name of the author may not be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
19 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
20 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
21 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #if defined(LIBC_SCCS) && !defined(lint) | ||
31 | static char *rcsid = "$OpenBSD: strlcat.c,v 1.1 1998/07/01 01:29:45 millert Exp $"; | ||
32 | #endif /* LIBC_SCCS and not lint */ | ||
33 | |||
34 | #include <sys/types.h> | ||
35 | #include <string.h> | ||
36 | |||
37 | /* | ||
38 | * Appends src to string dst of size siz (unlike strncat, siz is the | ||
39 | * full size of dst, not space left). At most siz-1 characters | ||
40 | * will be copied. Always NUL terminates (unless siz == 0). | ||
41 | * Returns strlen(src); if retval >= siz, truncation occurred. | ||
42 | */ | ||
43 | size_t strlcat(dst, src, siz) | ||
44 | char *dst; | ||
45 | const char *src; | ||
46 | size_t siz; | ||
47 | { | ||
48 | register char *d = dst; | ||
49 | register const char *s = src; | ||
50 | register size_t n = siz; | ||
51 | size_t dlen; | ||
52 | |||
53 | /* Find the end of dst and adjust bytes left */ | ||
54 | while (*d != '\0' && n != 0) | ||
55 | d++; | ||
56 | dlen = d - dst; | ||
57 | n -= dlen; | ||
58 | |||
59 | if (n == 0) | ||
60 | return(dlen + strlen(s)); | ||
61 | while (*s != '\0') { | ||
62 | if (n != 1) { | ||
63 | *d++ = *s; | ||
64 | n--; | ||
65 | } | ||
66 | s++; | ||
67 | } | ||
68 | *d = '\0'; | ||
69 | |||
70 | return(dlen + (s - src)); /* count does not include NUL */ | ||
71 | } | ||
diff --git a/src/lib/libc/string/strlcpy.3 b/src/lib/libc/string/strlcpy.3 new file mode 100644 index 0000000000..5ce444d6fa --- /dev/null +++ b/src/lib/libc/string/strlcpy.3 | |||
@@ -0,0 +1,140 @@ | |||
1 | .\" $OpenBSD: strlcpy.3,v 1.2 1998/07/06 19:17:21 millert Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | ||
7 | .\" modification, are permitted provided that the following conditions | ||
8 | .\" are met: | ||
9 | .\" 1. Redistributions of source code must retain the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer. | ||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer in the | ||
13 | .\" documentation and/or other materials provided with the distribution. | ||
14 | .\" 3. The name of the author may not be used to endorse or promote products | ||
15 | .\" derived from this software without specific prior written permission. | ||
16 | .\" | ||
17 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
18 | .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
19 | .\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
20 | .\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
21 | .\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
22 | .\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
23 | .\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
24 | .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
25 | .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
26 | .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
27 | .\" | ||
28 | .Dd June 22, 1998 | ||
29 | .Dt STRLCPY 3 | ||
30 | .Os | ||
31 | .Sh NAME | ||
32 | .Nm strlcpy, | ||
33 | .Nm strlcat | ||
34 | .Nd size-bounded string copying and concatenation | ||
35 | .Sh SYNOPSIS | ||
36 | .Fd #include <string.h> | ||
37 | .Ft size_t | ||
38 | .Fn strlcpy "char *dst" "const char *src" "size_t size" | ||
39 | .Ft size_t | ||
40 | .Fn strlcat "char *dst" "const char *src" "size_t size" | ||
41 | .Sh DESCRIPTION | ||
42 | The | ||
43 | .Fn strlcpy | ||
44 | and | ||
45 | .Fn strlcat | ||
46 | functions copy and concatenate strings respectively. They are designed | ||
47 | to be safer, more consistent, and less error prone replacements for | ||
48 | .Xr strncpy 3 | ||
49 | and | ||
50 | .Xr strncat 3 . | ||
51 | Unlike those functions, | ||
52 | .Fn strlcpy | ||
53 | and | ||
54 | .Fn strlcat | ||
55 | take the full size of the buffer (not just the length) and guarantee to | ||
56 | NUL-terminate the result (as long as | ||
57 | .Fa size | ||
58 | is larger than 0). Note that you should include a byte for the NUL in | ||
59 | .Fa size . | ||
60 | .Pp | ||
61 | The | ||
62 | .Fn strlcpy | ||
63 | function copies up to | ||
64 | .Fa size | ||
65 | - 1 characters from the NUL-terminated string | ||
66 | .Fa src | ||
67 | to | ||
68 | .Fa dst , | ||
69 | NUL-terminating the result. | ||
70 | .Pp | ||
71 | The | ||
72 | .Fn strlcat | ||
73 | function appends the NUL-terminated string | ||
74 | .Fa src | ||
75 | to the end of | ||
76 | .Fa dst . | ||
77 | It will append at most | ||
78 | .Fa size | ||
79 | - strlen(dst) - 1 bytes, NUL-terminating the result. | ||
80 | .Sh RETURN VALUES | ||
81 | The | ||
82 | .Fn strlcpy | ||
83 | and | ||
84 | .Fn strlcat | ||
85 | functions return the total length of the string they tried to | ||
86 | create. For | ||
87 | .Fn strlcpy | ||
88 | that means the length of | ||
89 | .Fa src . | ||
90 | For | ||
91 | .Fn strlcat | ||
92 | that means the initial length of | ||
93 | .Fa dst | ||
94 | plus | ||
95 | the length of | ||
96 | .Fa src . | ||
97 | While this may seem somewhat confusing it was done to make | ||
98 | truncation detection simple. | ||
99 | .Sh EXAMPLES | ||
100 | The following code fragment illustrates the simple case: | ||
101 | .Bd -literal -offset indent | ||
102 | char *s, *p, buf[BUFSIZ]; | ||
103 | |||
104 | .Li ... | ||
105 | |||
106 | (void)strlcpy(buf, s, sizeof(buf)); | ||
107 | (void)strlcat(buf, p, sizeof(buf)); | ||
108 | .Ed | ||
109 | .Pp | ||
110 | To detect truncation, perhaps while building a pathname, something | ||
111 | like the following might be used: | ||
112 | .Bd -literal -offset indent | ||
113 | char *dir, *file, pname[MAXPATHNAMELEN]; | ||
114 | |||
115 | .Li ... | ||
116 | |||
117 | if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname)) | ||
118 | goto toolong; | ||
119 | if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname)) | ||
120 | goto toolong; | ||
121 | .Ed | ||
122 | .Pp | ||
123 | Since we know how many characters we copied the first time, we can | ||
124 | speed things up a bit by using a copy instead on an append: | ||
125 | .Bd -literal -offset indent | ||
126 | char *dir, *file, pname[MAXPATHNAMELEN]; | ||
127 | size_t n; | ||
128 | |||
129 | .Li ... | ||
130 | |||
131 | n = strlcpy(pname, dir, sizeof(pname)); | ||
132 | if (n >= sizeof(pname)) | ||
133 | goto toolong; | ||
134 | if (strlcpy(pname + n, file, sizeof(pname)) >= sizeof(pname) - n) | ||
135 | goto toolong; | ||
136 | .Ed | ||
137 | .Sh SEE ALSO | ||
138 | .Xr snprintf 3 , | ||
139 | .Xr strncpy 3 , | ||
140 | .Xr strncat 3 | ||
diff --git a/src/lib/libc/string/strlcpy.c b/src/lib/libc/string/strlcpy.c new file mode 100644 index 0000000000..1a60445599 --- /dev/null +++ b/src/lib/libc/string/strlcpy.c | |||
@@ -0,0 +1,63 @@ | |||
1 | /* $OpenBSD: strlcpy.c,v 1.1 1998/07/01 01:29:45 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The name of the author may not be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
19 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
20 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
21 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #if defined(LIBC_SCCS) && !defined(lint) | ||
31 | static char *rcsid = "$OpenBSD: strlcpy.c,v 1.1 1998/07/01 01:29:45 millert Exp $"; | ||
32 | #endif /* LIBC_SCCS and not lint */ | ||
33 | |||
34 | #include <sys/types.h> | ||
35 | #include <string.h> | ||
36 | |||
37 | /* | ||
38 | * Copy src to string dst of size siz. At most siz-1 characters | ||
39 | * will be copied. Always NUL terminates (unless siz == 0). | ||
40 | * Returns strlen(src); if retval >= siz, truncation occurred. | ||
41 | */ | ||
42 | size_t strlcpy(dst, src, siz) | ||
43 | char *dst; | ||
44 | char *src; | ||
45 | size_t siz; | ||
46 | { | ||
47 | register char *d = dst; | ||
48 | register const char *s = src; | ||
49 | register size_t n = siz; | ||
50 | |||
51 | if (n == 0) | ||
52 | return(strlen(s)); | ||
53 | while (*s != '\0') { | ||
54 | if (n != 1) { | ||
55 | *d++ = *s; | ||
56 | n--; | ||
57 | } | ||
58 | s++; | ||
59 | } | ||
60 | *d = '\0'; | ||
61 | |||
62 | return(s - src); /* count does not include NUL */ | ||
63 | } | ||
diff --git a/src/lib/libc/string/strlen.3 b/src/lib/libc/string/strlen.3 index f4aff363ee..99e7dd19c3 100644 --- a/src/lib/libc/string/strlen.3 +++ b/src/lib/libc/string/strlen.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strlen.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strlen.3,v 1.2 1996/08/19 08:34:19 tholo Exp $ |
37 | .\" $Id: strlen.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRLEN 3 | 39 | .Dt STRLEN 3 |
diff --git a/src/lib/libc/string/strlen.c b/src/lib/libc/string/strlen.c index d23aadafc0..332d5766f9 100644 --- a/src/lib/libc/string/strlen.c +++ b/src/lib/libc/string/strlen.c | |||
@@ -32,11 +32,14 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strlen.c 5.5 (Berkeley) 1/26/91";*/ | 35 | static char *rcsid = "$OpenBSD: strlen.c,v 1.3 1996/08/19 08:34:19 tholo Exp $"; |
36 | static char *rcsid = "$Id: strlen.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
38 | #ifndef _KERNEL | ||
39 | #include <string.h> | 39 | #include <string.h> |
40 | #else | ||
41 | #include <lib/libkern/libkern.h> | ||
42 | #endif | ||
40 | 43 | ||
41 | size_t | 44 | size_t |
42 | strlen(str) | 45 | strlen(str) |
diff --git a/src/lib/libc/string/strmode.3 b/src/lib/libc/string/strmode.3 index 1907e7ab03..3db953704d 100644 --- a/src/lib/libc/string/strmode.3 +++ b/src/lib/libc/string/strmode.3 | |||
@@ -1,5 +1,7 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: strmode.3,v 1.6 1998/06/15 17:55:13 mickey Exp $ |
2 | .\" All rights reserved. | 2 | .\" |
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | 5 | .\" |
4 | .\" Redistribution and use in source and binary forms, with or without | 6 | .\" Redistribution and use in source and binary forms, with or without |
5 | .\" modification, are permitted provided that the following conditions | 7 | .\" modification, are permitted provided that the following conditions |
@@ -29,10 +31,9 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
31 | .\" | 33 | .\" |
32 | .\" from: @(#)strmode.3 5.4 (Berkeley) 7/31/91 | 34 | .\" @(#)strmode.3 8.3 (Berkeley) 7/28/94 |
33 | .\" $Id: strmode.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
34 | .\" | 35 | .\" |
35 | .Dd July 31, 1991 | 36 | .Dd July 28, 1994 |
36 | .Dt STRMODE 3 | 37 | .Dt STRMODE 3 |
37 | .Os | 38 | .Os |
38 | .Sh NAME | 39 | .Sh NAME |
@@ -53,7 +54,7 @@ converts a file | |||
53 | into a symbolic string which is stored in the location referenced by | 54 | into a symbolic string which is stored in the location referenced by |
54 | .Fa bp . | 55 | .Fa bp . |
55 | This stored string is eleven characters in length plus a trailing | 56 | This stored string is eleven characters in length plus a trailing |
56 | .Dv NULL . | 57 | .Dv NUL . |
57 | .Pp | 58 | .Pp |
58 | The first character is the inode type, and will be one of the following: | 59 | The first character is the inode type, and will be one of the following: |
59 | .Pp | 60 | .Pp |
@@ -72,6 +73,8 @@ symbolic link | |||
72 | fifo | 73 | fifo |
73 | .It s | 74 | .It s |
74 | socket | 75 | socket |
76 | .It w | ||
77 | whiteout | ||
75 | .It ? | 78 | .It ? |
76 | unknown inode type | 79 | unknown inode type |
77 | .El | 80 | .El |
@@ -98,28 +101,28 @@ The third character is the first of the following characters that apply: | |||
98 | .Bl -tag -width xxxx | 101 | .Bl -tag -width xxxx |
99 | .It S | 102 | .It S |
100 | If the character is part of the owner permissions and the file is not | 103 | If the character is part of the owner permissions and the file is not |
101 | executable or the directory is not searchable, by the owner, and the | 104 | executable or the directory is not searchable by the owner, and the |
102 | set-user-id bit is set. | 105 | set-user-id bit is set. |
103 | .It S | 106 | .It S |
104 | If the character is part of the group permissions and the file is not | 107 | If the character is part of the group permissions and the file is not |
105 | executable or the directory is not searchable, by the group, and the | 108 | executable or the directory is not searchable by the group, and the |
106 | set-group-id bit is set. | 109 | set-group-id bit is set. |
107 | .It T | 110 | .It T |
108 | If the character is part of the other permissions and the file is not | 111 | If the character is part of the other permissions and the file is not |
109 | executable or the directory is not searchable, by others, and the ``sticky'' | 112 | executable or the directory is not searchable by others, and the ``sticky'' |
110 | .Pq Dv S_ISVTX | 113 | .Pq Dv S_ISVTX |
111 | bit is set. | 114 | bit is set. |
112 | .It s | 115 | .It s |
113 | If the character is part of the owner permissions and the file is | 116 | If the character is part of the owner permissions and the file is |
114 | executable or the directory searchable, by the owner, and the set-user-id | 117 | executable or the directory searchable by the owner, and the set-user-id |
115 | bit is set. | 118 | bit is set. |
116 | .It s | 119 | .It s |
117 | If the character is part of the group permissions and the file is | 120 | If the character is part of the group permissions and the file is |
118 | executable or the directory searchable, by the group, and the set-group-id | 121 | executable or the directory searchable by the group, and the set-group-id |
119 | bit is set. | 122 | bit is set. |
120 | .It t | 123 | .It t |
121 | If the character is part of the other permissions and the file is | 124 | If the character is part of the other permissions and the file is |
122 | executable or the directory searchable, by others, and the ``sticky'' | 125 | executable or the directory searchable by others, and the ``sticky'' |
123 | .Pq Dv S_ISVTX | 126 | .Pq Dv S_ISVTX |
124 | bit is set. | 127 | bit is set. |
125 | .It x | 128 | .It x |
@@ -128,7 +131,7 @@ The file is executable or the directory is searchable. | |||
128 | None of the above apply. | 131 | None of the above apply. |
129 | .El | 132 | .El |
130 | .Pp | 133 | .Pp |
131 | The last character is a plus sign ``+'' if any there are any alternate | 134 | The last character is a plus sign ``+'' if there are any alternate |
132 | or additional access control methods associated with the inode, otherwise | 135 | or additional access control methods associated with the inode, otherwise |
133 | it will be a space. | 136 | it will be a space. |
134 | .Sh RETURN VALUES | 137 | .Sh RETURN VALUES |
@@ -145,5 +148,5 @@ always returns 0. | |||
145 | .Sh HISTORY | 148 | .Sh HISTORY |
146 | The | 149 | The |
147 | .Fn strmode | 150 | .Fn strmode |
148 | function | 151 | function first appeared in |
149 | .Ud . | 152 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/strmode.c b/src/lib/libc/string/strmode.c index 441fc76e90..5e7f15e857 100644 --- a/src/lib/libc/string/strmode.c +++ b/src/lib/libc/string/strmode.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strmode.c 5.3 (Berkeley) 5/18/90";*/ | 35 | static char *rcsid = "$OpenBSD: strmode.c,v 1.3 1997/06/13 13:57:20 deraadt Exp $"; |
36 | static char *rcsid = "$Id: strmode.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <sys/types.h> | 38 | #include <sys/types.h> |
@@ -70,6 +69,11 @@ strmode(mode, p) | |||
70 | *p++ = 'p'; | 69 | *p++ = 'p'; |
71 | break; | 70 | break; |
72 | #endif | 71 | #endif |
72 | #ifdef S_IFWHT | ||
73 | case S_IFWHT: /* whiteout */ | ||
74 | *p++ = 'w'; | ||
75 | break; | ||
76 | #endif | ||
73 | default: /* unknown */ | 77 | default: /* unknown */ |
74 | *p++ = '?'; | 78 | *p++ = '?'; |
75 | break; | 79 | break; |
diff --git a/src/lib/libc/string/strncat.c b/src/lib/libc/string/strncat.c index 3d96452af4..27ae2ba324 100644 --- a/src/lib/libc/string/strncat.c +++ b/src/lib/libc/string/strncat.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)strncat.c 5.6 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strncat.c,v 1.2 1996/08/19 08:34:21 tholo Exp $"; |
39 | static char *rcsid = "$Id: strncat.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/strncmp.c b/src/lib/libc/string/strncmp.c index 0638d4dcf2..0224957f8b 100644 --- a/src/lib/libc/string/strncmp.c +++ b/src/lib/libc/string/strncmp.c | |||
@@ -32,11 +32,14 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strncmp.c 5.6 (Berkeley) 1/26/91";*/ | 35 | static char *rcsid = "$OpenBSD: strncmp.c,v 1.3 1996/08/19 08:34:21 tholo Exp $"; |
36 | static char *rcsid = "$Id: strncmp.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
38 | #ifndef _KERNEL | ||
39 | #include <string.h> | 39 | #include <string.h> |
40 | #else | ||
41 | #include <lib/libkern/libkern.h> | ||
42 | #endif | ||
40 | 43 | ||
41 | int | 44 | int |
42 | strncmp(s1, s2, n) | 45 | strncmp(s1, s2, n) |
diff --git a/src/lib/libc/string/strncpy.c b/src/lib/libc/string/strncpy.c index 5215311b75..01bc8a872e 100644 --- a/src/lib/libc/string/strncpy.c +++ b/src/lib/libc/string/strncpy.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)strncpy.c 5.6 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strncpy.c,v 1.2 1996/08/19 08:34:22 tholo Exp $"; |
39 | static char *rcsid = "$Id: strncpy.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/strpbrk.3 b/src/lib/libc/string/strpbrk.3 index 8578546c05..5876f560a9 100644 --- a/src/lib/libc/string/strpbrk.3 +++ b/src/lib/libc/string/strpbrk.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strpbrk.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strpbrk.3,v 1.2 1996/08/19 08:34:22 tholo Exp $ |
37 | .\" $Id: strpbrk.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRPBRK 3 | 39 | .Dt STRPBRK 3 |
diff --git a/src/lib/libc/string/strpbrk.c b/src/lib/libc/string/strpbrk.c index f1d542a525..748a3a8c94 100644 --- a/src/lib/libc/string/strpbrk.c +++ b/src/lib/libc/string/strpbrk.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strpbrk.c 5.8 (Berkeley) 1/26/91";*/ | 35 | static char *rcsid = "$OpenBSD: strpbrk.c,v 1.2 1996/08/19 08:34:23 tholo Exp $"; |
36 | static char *rcsid = "$Id: strpbrk.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <string.h> | 38 | #include <string.h> |
diff --git a/src/lib/libc/string/strrchr.3 b/src/lib/libc/string/strrchr.3 index 1d98cbff24..6dd00d32fb 100644 --- a/src/lib/libc/string/strrchr.3 +++ b/src/lib/libc/string/strrchr.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strrchr.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strrchr.3,v 1.2 1996/08/19 08:34:23 tholo Exp $ |
37 | .\" $Id: strrchr.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRRCHR 3 | 39 | .Dt STRRCHR 3 |
diff --git a/src/lib/libc/string/strsep.3 b/src/lib/libc/string/strsep.3 index 21aa7376f2..5af262a074 100644 --- a/src/lib/libc/string/strsep.3 +++ b/src/lib/libc/string/strsep.3 | |||
@@ -1,8 +1,11 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: strsep.3,v 1.4 1998/06/15 17:55:14 mickey Exp $ |
2 | .\" All rights reserved. | 2 | .\" |
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | 5 | .\" |
4 | .\" This code is derived from software contributed to Berkeley by | 6 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" Chris Torek. | 7 | .\" Chris Torek. |
8 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | 9 | .\" Redistribution and use in source and binary forms, with or without |
7 | .\" modification, are permitted provided that the following conditions | 10 | .\" modification, are permitted provided that the following conditions |
8 | .\" are met: | 11 | .\" are met: |
@@ -31,10 +34,9 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 34 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 35 | .\" SUCH DAMAGE. |
33 | .\" | 36 | .\" |
34 | .\" from: @(#)strsep.3 5.3 (Berkeley) 4/19/91 | 37 | .\" @(#)strsep.3 8.1 (Berkeley) 6/9/93 |
35 | .\" $Id: strsep.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
36 | .\" | 38 | .\" |
37 | .Dd April 19, 1991 | 39 | .Dd June 9, 1993 |
38 | .Dt STRSEP 3 | 40 | .Dt STRSEP 3 |
39 | .Os | 41 | .Os |
40 | .Sh NAME | 42 | .Sh NAME |
@@ -47,23 +49,29 @@ | |||
47 | .Sh DESCRIPTION | 49 | .Sh DESCRIPTION |
48 | The | 50 | The |
49 | .Fn strsep | 51 | .Fn strsep |
50 | locates in the null-terminated string at | 52 | function locates, in the string referenced by |
51 | .Fa *stringp | ||
52 | the first occurrence of any character in | ||
53 | .Fa delim | ||
54 | and replaces this with a | ||
55 | .Ql \e0 , | ||
56 | records the location of the immediate following character in | ||
57 | .Fa *stringp , | 53 | .Fa *stringp , |
58 | then returns the original value of | 54 | the first occurrence of any character in the string |
55 | .Fa delim | ||
56 | (or the terminating | ||
57 | .Ql \e0 | ||
58 | character) and replaces it with a | ||
59 | .Ql \e0 . | ||
60 | The location of the next character after the delimiter character | ||
61 | (or NULL, if the end of the string was reached) is stored in | ||
59 | .Fa *stringp . | 62 | .Fa *stringp . |
60 | If no delimiter characters are found, | 63 | The original value of |
61 | .Fn strsep | 64 | .Fa *stringp |
62 | sets | 65 | is returned. |
66 | .Pp | ||
67 | An ``empty'' field, i.e. one caused by two adjacent delimiter characters, | ||
68 | can be detected by comparing the location referenced by the pointer returned | ||
69 | in | ||
63 | .Fa *stringp | 70 | .Fa *stringp |
64 | to | 71 | to |
65 | .Dv NULL ; | 72 | .Ql \e0 . |
66 | if | 73 | .Pp |
74 | If | ||
67 | .Fa *stringp | 75 | .Fa *stringp |
68 | is initially | 76 | is initially |
69 | .Dv NULL , | 77 | .Dv NULL , |
@@ -73,20 +81,30 @@ returns | |||
73 | .Sh EXAMPLES | 81 | .Sh EXAMPLES |
74 | The following uses | 82 | The following uses |
75 | .Fn strsep | 83 | .Fn strsep |
76 | to parse strings containing runs of white space, | 84 | to parse a string, containing tokens delimited by white space, into an |
77 | making up an argument vector: | 85 | argument vector: |
78 | .Bd -literal -offset indent | 86 | .Bd -literal -offset indent |
79 | char inputstring[100]; | 87 | char **ap, *argv[10], *inputstring; |
80 | char **argv[51], **ap = argv, *p, *val; | 88 | |
81 | /* set up inputstring */ | 89 | for (ap = argv; (*ap = strsep(&inputstring, " \et")) != NULL;) |
82 | for (p = inputstring; p != NULL; ) { | 90 | if (**ap != '\e0') |
83 | while ((val = strsep(&p, " \et")) != NULL && *val == '\e0'); | 91 | ++ap; |
84 | *ap++ = val; | ||
85 | } | ||
86 | *ap = 0; | ||
87 | .Ed | 92 | .Ed |
88 | .Sh HISTORY | 93 | .Sh HISTORY |
89 | The | 94 | The |
90 | .Fn strsep | 95 | .Fn strsep |
91 | function is | 96 | function |
92 | .Ud . | 97 | is intended as a replacement for the |
98 | .Fn strtok | ||
99 | function. | ||
100 | While the | ||
101 | .Fn strtok | ||
102 | function should be preferred for portability reasons (it conforms to | ||
103 | .St -ansiC ) | ||
104 | it is unable to handle empty fields, i.e. detect fields delimited by | ||
105 | two adjacent delimiter characters, or to be used for more than a single | ||
106 | string at a time. | ||
107 | The | ||
108 | .Fn strsep | ||
109 | function first appeared in | ||
110 | .Bx 4.4 . | ||
diff --git a/src/lib/libc/string/strsep.c b/src/lib/libc/string/strsep.c index 69be7fe046..b69b715fc5 100644 --- a/src/lib/libc/string/strsep.c +++ b/src/lib/libc/string/strsep.c | |||
@@ -1,6 +1,8 @@ | |||
1 | /* $OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert Exp $ */ | ||
2 | |||
1 | /*- | 3 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 4 | * Copyright (c) 1990, 1993 |
3 | * All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. |
4 | * | 6 | * |
5 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions |
@@ -31,15 +33,19 @@ | |||
31 | * SUCH DAMAGE. | 33 | * SUCH DAMAGE. |
32 | */ | 34 | */ |
33 | 35 | ||
36 | #include <string.h> | ||
37 | #include <stdio.h> | ||
38 | |||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 39 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static const char sccsid[] = "from: @(#)strsep.c 5.4 (Berkeley) 1/26/91";*/ | 40 | #if 0 |
36 | static char *rcsid = "$Id: strsep.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | 41 | static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; |
42 | #else | ||
43 | static char *rcsid = "$OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert Exp $"; | ||
44 | #endif | ||
37 | #endif /* LIBC_SCCS and not lint */ | 45 | #endif /* LIBC_SCCS and not lint */ |
38 | 46 | ||
39 | #include <string.h> | ||
40 | |||
41 | /* | 47 | /* |
42 | * Get next token from string *stringp, where tokens are nonempty | 48 | * Get next token from string *stringp, where tokens are possibly-empty |
43 | * strings separated by characters from delim. | 49 | * strings separated by characters from delim. |
44 | * | 50 | * |
45 | * Writes NULs into the string at *stringp to end tokens. | 51 | * Writes NULs into the string at *stringp to end tokens. |
@@ -47,7 +53,7 @@ static char *rcsid = "$Id: strsep.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $" | |||
47 | * On return, *stringp points past the last NUL written (if there might | 53 | * On return, *stringp points past the last NUL written (if there might |
48 | * be further tokens), or is NULL (if there are definitely no more tokens). | 54 | * be further tokens), or is NULL (if there are definitely no more tokens). |
49 | * | 55 | * |
50 | * If *stringp is NULL, strtoken returns NULL. | 56 | * If *stringp is NULL, strsep returns NULL. |
51 | */ | 57 | */ |
52 | char * | 58 | char * |
53 | strsep(stringp, delim) | 59 | strsep(stringp, delim) |
diff --git a/src/lib/libc/string/strsignal.3 b/src/lib/libc/string/strsignal.3 index 3287fef53e..42e433c259 100644 --- a/src/lib/libc/string/strsignal.3 +++ b/src/lib/libc/string/strsignal.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strerror.3 6.9 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strsignal.3,v 1.2 1996/08/19 08:34:25 tholo Exp $ |
37 | .\" $Id: strsignal.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRSIGNAL 3 | 39 | .Dt STRSIGNAL 3 |
diff --git a/src/lib/libc/string/strsignal.c b/src/lib/libc/string/strsignal.c index ec4a267edf..cf03af5963 100644 --- a/src/lib/libc/string/strsignal.c +++ b/src/lib/libc/string/strsignal.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 35 | static char *rcsid = "$OpenBSD: strsignal.c,v 1.2 1996/08/19 08:34:25 tholo Exp $"; |
36 | static char *rcsid = "$Id: strsignal.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <string.h> | 38 | #include <string.h> |
diff --git a/src/lib/libc/string/strspn.3 b/src/lib/libc/string/strspn.3 index 4de03aa58b..7d15470dee 100644 --- a/src/lib/libc/string/strspn.3 +++ b/src/lib/libc/string/strspn.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strspn.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strspn.3,v 1.3 1996/08/19 08:34:25 tholo Exp $ |
37 | .\" $Id: strspn.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRSPN 3 | 39 | .Dt STRSPN 3 |
@@ -48,7 +47,7 @@ | |||
48 | .Fn strspn "const char *s" "const char *charset" | 47 | .Fn strspn "const char *s" "const char *charset" |
49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
50 | The | 49 | The |
51 | .Xr strcspn | 50 | .Fn strspn |
52 | function | 51 | function |
53 | spans the initial part of the null-terminated string | 52 | spans the initial part of the null-terminated string |
54 | .Fa s | 53 | .Fa s |
diff --git a/src/lib/libc/string/strspn.c b/src/lib/libc/string/strspn.c index 6224b25c2a..41940f9190 100644 --- a/src/lib/libc/string/strspn.c +++ b/src/lib/libc/string/strspn.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strspn.c 5.8 (Berkeley) 1/26/91";*/ | 35 | static char *rcsid = "$OpenBSD: strspn.c,v 1.2 1996/08/19 08:34:26 tholo Exp $"; |
36 | static char *rcsid = "$Id: strspn.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <string.h> | 38 | #include <string.h> |
diff --git a/src/lib/libc/string/strstr.3 b/src/lib/libc/string/strstr.3 index 24fdf540ed..fa455b426a 100644 --- a/src/lib/libc/string/strstr.3 +++ b/src/lib/libc/string/strstr.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strstr.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strstr.3,v 1.2 1996/08/19 08:34:26 tholo Exp $ |
37 | .\" $Id: strstr.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRSTR 3 | 39 | .Dt STRSTR 3 |
diff --git a/src/lib/libc/string/strstr.c b/src/lib/libc/string/strstr.c index 1ed59e357b..763c7e29d7 100644 --- a/src/lib/libc/string/strstr.c +++ b/src/lib/libc/string/strstr.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)strstr.c 5.2 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strstr.c,v 1.2 1996/08/19 08:34:27 tholo Exp $"; |
39 | static char *rcsid = "$Id: strstr.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/strtok.3 b/src/lib/libc/string/strtok.3 index 644bd10aed..876e0eb515 100644 --- a/src/lib/libc/string/strtok.3 +++ b/src/lib/libc/string/strtok.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strtok.3 5.8 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strtok.3,v 1.3 1998/04/28 07:36:55 deraadt Exp $ |
37 | .\" $Id: strtok.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRTOK 3 | 39 | .Dt STRTOK 3 |
@@ -49,7 +48,8 @@ | |||
49 | .Fn strtok "char *str" "const char *sep" | 48 | .Fn strtok "char *str" "const char *sep" |
50 | .Sh DESCRIPTION | 49 | .Sh DESCRIPTION |
51 | .Bf -symbolic | 50 | .Bf -symbolic |
52 | This interface is obsoleted by strsep(3). | 51 | This interface is obsoleted by |
52 | .Xr strsep 3 . | ||
53 | .Ef | 53 | .Ef |
54 | .Pp | 54 | .Pp |
55 | The | 55 | The |
diff --git a/src/lib/libc/string/strtok.c b/src/lib/libc/string/strtok.c index 9f712579bf..2fce04c3ad 100644 --- a/src/lib/libc/string/strtok.c +++ b/src/lib/libc/string/strtok.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strtok.c 5.8 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: strtok.c,v 1.2 1996/08/19 08:34:28 tholo Exp $"; |
36 | static char *rcsid = "$Id: strtok.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #include <string.h> | 38 | #include <string.h> |
diff --git a/src/lib/libc/string/strxfrm.3 b/src/lib/libc/string/strxfrm.3 index 84fd945472..3ebdd42c29 100644 --- a/src/lib/libc/string/strxfrm.3 +++ b/src/lib/libc/string/strxfrm.3 | |||
@@ -33,8 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" from: @(#)strxfrm.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strxfrm.3,v 1.2 1996/08/19 08:34:28 tholo Exp $ |
37 | .\" $Id: strxfrm.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 37 | .\" |
39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
40 | .Dt STRXFRM 3 | 39 | .Dt STRXFRM 3 |
diff --git a/src/lib/libc/string/strxfrm.c b/src/lib/libc/string/strxfrm.c index d9df77b957..6b258edecc 100644 --- a/src/lib/libc/string/strxfrm.c +++ b/src/lib/libc/string/strxfrm.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)strxfrm.c 5.2 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strxfrm.c,v 1.2 1996/08/19 08:34:29 tholo Exp $"; |
39 | static char *rcsid = "$Id: strxfrm.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/swab.3 b/src/lib/libc/string/swab.3 index 133c487bbd..d1bfc358fb 100644 --- a/src/lib/libc/string/swab.3 +++ b/src/lib/libc/string/swab.3 | |||
@@ -29,8 +29,7 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
31 | .\" | 31 | .\" |
32 | .\" from: @(#)swab.3 6.6 (Berkeley) 5/1/91 | 32 | .\" $OpenBSD: swab.3,v 1.3 1998/02/10 02:19:48 deraadt Exp $ |
33 | .\" $Id: swab.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
34 | .\" | 33 | .\" |
35 | .Dd May 1, 1991 | 34 | .Dd May 1, 1991 |
36 | .Dt SWAB 3 | 35 | .Dt SWAB 3 |
@@ -39,7 +38,7 @@ | |||
39 | .Nm swab | 38 | .Nm swab |
40 | .Nd swap adjacent bytes | 39 | .Nd swap adjacent bytes |
41 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
42 | .Fd #include <string.h> | 41 | .Fd #include <unistd.h> |
43 | .Ft void | 42 | .Ft void |
44 | .Fn swab "const void *src" "void *dst" "size_t len" | 43 | .Fn swab "const void *src" "void *dst" "size_t len" |
45 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
diff --git a/src/lib/libc/string/swab.c b/src/lib/libc/string/swab.c index f33fc53bd6..311cf13a53 100644 --- a/src/lib/libc/string/swab.c +++ b/src/lib/libc/string/swab.c | |||
@@ -35,11 +35,10 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char *sccsid = "from: @(#)swab.c 5.10 (Berkeley) 3/6/91";*/ | 38 | static char *rcsid = "$OpenBSD: swab.c,v 1.3 1998/02/10 02:19:48 deraadt Exp $"; |
39 | static char *rcsid = "$Id: swab.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <string.h> | 41 | #include <unistd.h> |
43 | 42 | ||
44 | void | 43 | void |
45 | swab(from, to, len) | 44 | swab(from, to, len) |
diff --git a/src/lib/libcrypto/Makefile.ssl b/src/lib/libcrypto/Makefile.ssl new file mode 100644 index 0000000000..efdbba38ac --- /dev/null +++ b/src/lib/libcrypto/Makefile.ssl | |||
@@ -0,0 +1,161 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= crypto | ||
6 | TOP= .. | ||
7 | CC= cc | ||
8 | INCLUDE= -I. -I../include | ||
9 | INCLUDES= -I.. -I../../include | ||
10 | CFLAG= -g | ||
11 | INSTALLTOP= /usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | RM= /bin/rm -f | ||
16 | AR= ar r | ||
17 | |||
18 | MAKE= make -f Makefile.ssl | ||
19 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
20 | MAKEFILE= Makefile.ssl | ||
21 | |||
22 | PEX_LIBS= | ||
23 | EX_LIBS= | ||
24 | |||
25 | CFLAGS= $(INCLUDE) $(CFLAG) -DCFLAGS=" \"$(CC) $(CFLAG)\" " | ||
26 | |||
27 | ERR=crypto | ||
28 | ERRC=cpt_err | ||
29 | |||
30 | LIBS= | ||
31 | |||
32 | SDIRS= md2 md5 sha mdc2 hmac ripemd \ | ||
33 | des rc2 rc4 rc5 idea bf cast \ | ||
34 | bn rsa dsa dh \ | ||
35 | buffer bio stack lhash rand err objects \ | ||
36 | evp pem x509 \ | ||
37 | asn1 conf txt_db pkcs7 | ||
38 | |||
39 | GENERAL=Makefile README | ||
40 | |||
41 | LIB= $(TOP)/libcrypto.a | ||
42 | LIBSRC= cryptlib.c mem.c cversion.c ex_data.c $(ERRC).c | ||
43 | LIBOBJ= cryptlib.o mem.o cversion.o ex_data.o $(ERRC).o | ||
44 | |||
45 | SRC= $(LIBSRC) | ||
46 | |||
47 | EXHEADER= crypto.h cryptall.h | ||
48 | HEADER= cryptlib.h date.h $(EXHEADER) | ||
49 | |||
50 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
51 | |||
52 | top: | ||
53 | @(cd ..; $(MAKE) DIRS=$(DIR) all) | ||
54 | |||
55 | all: date.h lib subdirs | ||
56 | |||
57 | date.h: ../Makefile.ssl ../VERSION | ||
58 | echo "#define DATE \"`date`\"" >date.h | ||
59 | |||
60 | subdirs: | ||
61 | @for i in $(SDIRS) ;\ | ||
62 | do \ | ||
63 | (cd $$i; echo "making all in $$i..."; \ | ||
64 | $(MAKE) CC='$(CC)' INCLUDES='${INCLUDES}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_MULW='${BN_MULW}' DES_ENC='${DES_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' AR='${AR}' all ); \ | ||
65 | done; | ||
66 | |||
67 | files: | ||
68 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
69 | @for i in $(SDIRS) ;\ | ||
70 | do \ | ||
71 | (cd $$i; echo "making 'files' in $$i..."; \ | ||
72 | $(MAKE) files ); \ | ||
73 | done; | ||
74 | |||
75 | links: | ||
76 | /bin/rm -f Makefile | ||
77 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
78 | $(TOP)/util/mklink.sh ../include $(HEADER) ; | ||
79 | $(TOP)/util/mklink.sh ../test $(TEST) ; | ||
80 | $(TOP)/util/mklink.sh ../apps $(APPS) ; | ||
81 | $(TOP)/util/point.sh Makefile.ssl Makefile; | ||
82 | @for i in $(SDIRS) ;\ | ||
83 | do \ | ||
84 | (cd $$i; echo "making links in $$i..."; \ | ||
85 | $(MAKE) links ); \ | ||
86 | done; | ||
87 | |||
88 | lib: $(LIBOBJ) | ||
89 | $(AR) $(LIB) $(LIBOBJ) | ||
90 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
91 | @touch lib | ||
92 | |||
93 | libs: | ||
94 | @for i in $(SDIRS) ;\ | ||
95 | do \ | ||
96 | (cd $$i; echo "making libs in $$i..."; \ | ||
97 | $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' lib ); \ | ||
98 | done; | ||
99 | |||
100 | tests: | ||
101 | @for i in $(SDIRS) ;\ | ||
102 | do \ | ||
103 | (cd $$i; echo "making tests in $$i..."; \ | ||
104 | $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' tests ); \ | ||
105 | done; | ||
106 | |||
107 | install: | ||
108 | @for i in $(EXHEADER) ;\ | ||
109 | do \ | ||
110 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
111 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
112 | done; | ||
113 | @for i in $(SDIRS) ;\ | ||
114 | do \ | ||
115 | (cd $$i; echo "making install in $$i..."; \ | ||
116 | $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' install ); \ | ||
117 | done; | ||
118 | |||
119 | lint: | ||
120 | @for i in $(SDIRS) ;\ | ||
121 | do \ | ||
122 | (cd $$i; echo "making lint in $$i..."; \ | ||
123 | $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' lint ); \ | ||
124 | done; | ||
125 | |||
126 | depend: | ||
127 | $(MAKEDEPEND) $(INCLUDE) $(PROGS) $(LIBSRC) | ||
128 | @for i in $(SDIRS) ;\ | ||
129 | do \ | ||
130 | (cd $$i; echo "making depend in $$i..."; \ | ||
131 | $(MAKE) MAKEFILE='${MAKEFILE}' INCLUDES='${INCLUDES}' MAKEDEPEND='${MAKEDEPEND}' depend ); \ | ||
132 | done; | ||
133 | |||
134 | clean: | ||
135 | /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
136 | @for i in $(SDIRS) ;\ | ||
137 | do \ | ||
138 | (cd $$i; echo "making clean in $$i..."; \ | ||
139 | $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' clean ); \ | ||
140 | done; | ||
141 | |||
142 | dclean: | ||
143 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
144 | mv -f Makefile.new $(MAKEFILE) | ||
145 | @for i in $(SDIRS) ;\ | ||
146 | do \ | ||
147 | (cd $$i; echo "making dclean in $$i..."; \ | ||
148 | $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' dclean ); \ | ||
149 | done; | ||
150 | |||
151 | errors: | ||
152 | perl ./err/err_code.pl -conf err/ssleay.ec *.c */*.c ../ssl/*.c ../rsaref/*.c | ||
153 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
154 | perl err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
155 | @for i in $(SDIRS) ;\ | ||
156 | do \ | ||
157 | (cd $$i; echo "making errors in $$i..."; \ | ||
158 | $(MAKE) errors ); \ | ||
159 | done; | ||
160 | |||
161 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/asn1/Makefile.ssl b/src/lib/libcrypto/asn1/Makefile.ssl new file mode 100644 index 0000000000..30751bd156 --- /dev/null +++ b/src/lib/libcrypto/asn1/Makefile.ssl | |||
@@ -0,0 +1,120 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/asn1/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= asn1 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=asn1 | ||
19 | ERRC=asn1_err | ||
20 | GENERAL=Makefile README | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= a_object.c a_bitstr.c a_utctm.c a_int.c a_octet.c a_print.c \ | ||
26 | a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c \ | ||
27 | a_sign.c a_digest.c a_verify.c \ | ||
28 | x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c \ | ||
29 | x_name.c x_cinf.c x_x509.c x_crl.c x_info.c x_spki.c \ | ||
30 | d2i_r_pr.c i2d_r_pr.c d2i_r_pu.c i2d_r_pu.c \ | ||
31 | d2i_s_pr.c i2d_s_pr.c d2i_s_pu.c i2d_s_pu.c \ | ||
32 | d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\ | ||
33 | t_req.c t_x509.c t_pkey.c \ | ||
34 | p7_i_s.c p7_signi.c p7_signd.c p7_recip.c p7_enc_c.c p7_evp.c \ | ||
35 | p7_dgst.c p7_s_e.c p7_enc.c p7_lib.c \ | ||
36 | f_int.c f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c d2i_dsap.c n_pkey.c \ | ||
37 | a_hdr.c x_pkey.c a_bool.c x_exten.c \ | ||
38 | asn1_par.c asn1_lib.c $(ERRC).c a_meth.c a_bytes.c \ | ||
39 | evp_asn1.c | ||
40 | LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_int.o a_octet.o a_print.o \ | ||
41 | a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o \ | ||
42 | a_sign.o a_digest.o a_verify.o \ | ||
43 | x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o \ | ||
44 | x_name.o x_cinf.o x_x509.o x_crl.o x_info.o x_spki.o \ | ||
45 | d2i_r_pr.o i2d_r_pr.o d2i_r_pu.o i2d_r_pu.o \ | ||
46 | d2i_s_pr.o i2d_s_pr.o d2i_s_pu.o i2d_s_pu.o \ | ||
47 | d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \ | ||
48 | t_req.o t_x509.o t_pkey.o \ | ||
49 | p7_i_s.o p7_signi.o p7_signd.o p7_recip.o p7_enc_c.o p7_evp.o \ | ||
50 | p7_dgst.o p7_s_e.o p7_enc.o p7_lib.o \ | ||
51 | f_int.o f_string.o i2d_dhp.o i2d_dsap.o d2i_dhp.o d2i_dsap.o n_pkey.o \ | ||
52 | a_hdr.o x_pkey.o a_bool.o x_exten.o \ | ||
53 | asn1_par.o asn1_lib.o $(ERRC).o a_meth.o a_bytes.o \ | ||
54 | evp_asn1.o | ||
55 | |||
56 | SRC= $(LIBSRC) | ||
57 | |||
58 | EXHEADER= asn1.h asn1_mac.h | ||
59 | HEADER= $(EXHEADER) | ||
60 | |||
61 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
62 | |||
63 | top: | ||
64 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
65 | |||
66 | test: test.c | ||
67 | cc -g -I../../include -c test.c | ||
68 | cc -g -I../../include -o test test.o -L../.. -lcrypto | ||
69 | |||
70 | pk: pk.c | ||
71 | cc -g -I../../include -c pk.c | ||
72 | cc -g -I../../include -o pk pk.o -L../.. -lcrypto | ||
73 | |||
74 | all: lib | ||
75 | |||
76 | lib: $(LIBOBJ) | ||
77 | $(AR) $(LIB) $(LIBOBJ) | ||
78 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
79 | @touch lib | ||
80 | |||
81 | files: | ||
82 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
83 | |||
84 | links: | ||
85 | /bin/rm -f Makefile | ||
86 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
87 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
88 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
89 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
90 | |||
91 | install: | ||
92 | @for i in $(EXHEADER) ; \ | ||
93 | do \ | ||
94 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
95 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
96 | done; | ||
97 | |||
98 | tags: | ||
99 | ctags $(SRC) | ||
100 | |||
101 | tests: | ||
102 | |||
103 | lint: | ||
104 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
105 | |||
106 | depend: | ||
107 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
108 | |||
109 | dclean: | ||
110 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
111 | mv -f Makefile.new $(MAKEFILE) | ||
112 | |||
113 | clean: | ||
114 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
115 | |||
116 | errors: | ||
117 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
118 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
119 | |||
120 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/asn1/f.c b/src/lib/libcrypto/asn1/f.c new file mode 100644 index 0000000000..2ab3a262ac --- /dev/null +++ b/src/lib/libcrypto/asn1/f.c | |||
@@ -0,0 +1,80 @@ | |||
1 | /* crypto/asn1/f.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | #include <stdio.h> | ||
59 | #include "asn1.h" | ||
60 | #include "err.h" | ||
61 | |||
62 | main() | ||
63 | { | ||
64 | ASN1_TYPE *at; | ||
65 | char buf[512]; | ||
66 | int n; | ||
67 | long l; | ||
68 | |||
69 | at=ASN1_TYPE_new(); | ||
70 | |||
71 | n=ASN1_TYPE_set_int_octetstring(at,98736,"01234567",8); | ||
72 | printf("%d\n",n); | ||
73 | n=ASN1_TYPE_get_int_octetstring(at,&l,buf,8); | ||
74 | buf[8]='\0'; | ||
75 | printf("%ld %d %d\n",l,n,buf[8]); | ||
76 | buf[8]='\0'; | ||
77 | printf("%s\n",buf); | ||
78 | ERR_load_crypto_strings(); | ||
79 | ERR_print_errors_fp(stderr); | ||
80 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_cinf.c b/src/lib/libcrypto/asn1/x_cinf.c new file mode 100644 index 0000000000..4fc2cc9f6e --- /dev/null +++ b/src/lib/libcrypto/asn1/x_cinf.c | |||
@@ -0,0 +1,197 @@ | |||
1 | /* crypto/asn1/x_cinf.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | |||
63 | /* | ||
64 | * ASN1err(ASN1_F_D2I_X509_CINF,ASN1_R_LENGTH_MISMATCH); | ||
65 | * ASN1err(ASN1_F_X509_CINF_NEW,ASN1_R_LENGTH_MISMATCH); | ||
66 | */ | ||
67 | |||
68 | int i2d_X509_CINF(a,pp) | ||
69 | X509_CINF *a; | ||
70 | unsigned char **pp; | ||
71 | { | ||
72 | int v1=0,v2=0; | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | M_ASN1_I2D_len_EXP_opt(a->version,i2d_ASN1_INTEGER,0,v1); | ||
76 | M_ASN1_I2D_len(a->serialNumber, i2d_ASN1_INTEGER); | ||
77 | M_ASN1_I2D_len(a->signature, i2d_X509_ALGOR); | ||
78 | M_ASN1_I2D_len(a->issuer, i2d_X509_NAME); | ||
79 | M_ASN1_I2D_len(a->validity, i2d_X509_VAL); | ||
80 | M_ASN1_I2D_len(a->subject, i2d_X509_NAME); | ||
81 | M_ASN1_I2D_len(a->key, i2d_X509_PUBKEY); | ||
82 | M_ASN1_I2D_len_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING); | ||
83 | M_ASN1_I2D_len_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING); | ||
84 | M_ASN1_I2D_len_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); | ||
85 | |||
86 | M_ASN1_I2D_seq_total(); | ||
87 | |||
88 | M_ASN1_I2D_put_EXP_opt(a->version,i2d_ASN1_INTEGER,0,v1); | ||
89 | M_ASN1_I2D_put(a->serialNumber, i2d_ASN1_INTEGER); | ||
90 | M_ASN1_I2D_put(a->signature, i2d_X509_ALGOR); | ||
91 | M_ASN1_I2D_put(a->issuer, i2d_X509_NAME); | ||
92 | M_ASN1_I2D_put(a->validity, i2d_X509_VAL); | ||
93 | M_ASN1_I2D_put(a->subject, i2d_X509_NAME); | ||
94 | M_ASN1_I2D_put(a->key, i2d_X509_PUBKEY); | ||
95 | M_ASN1_I2D_put_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING,1); | ||
96 | M_ASN1_I2D_put_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING,2); | ||
97 | M_ASN1_I2D_put_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); | ||
98 | |||
99 | M_ASN1_I2D_finish(); | ||
100 | } | ||
101 | |||
102 | X509_CINF *d2i_X509_CINF(a,pp,length) | ||
103 | X509_CINF **a; | ||
104 | unsigned char **pp; | ||
105 | long length; | ||
106 | { | ||
107 | int ver=0; | ||
108 | M_ASN1_D2I_vars(a,X509_CINF *,X509_CINF_new); | ||
109 | |||
110 | M_ASN1_D2I_Init(); | ||
111 | M_ASN1_D2I_start_sequence(); | ||
112 | /* we have the optional version field */ | ||
113 | if (M_ASN1_next == (V_ASN1_CONTEXT_SPECIFIC | V_ASN1_CONSTRUCTED | 0)) | ||
114 | { | ||
115 | M_ASN1_D2I_get_EXP_opt(ret->version,d2i_ASN1_INTEGER,0); | ||
116 | if (ret->version->data != NULL) | ||
117 | ver=ret->version->data[0]; | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | if (ret->version != NULL) | ||
122 | { | ||
123 | ASN1_INTEGER_free(ret->version); | ||
124 | ret->version=NULL; | ||
125 | } | ||
126 | } | ||
127 | M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER); | ||
128 | M_ASN1_D2I_get(ret->signature,d2i_X509_ALGOR); | ||
129 | M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME); | ||
130 | M_ASN1_D2I_get(ret->validity,d2i_X509_VAL); | ||
131 | M_ASN1_D2I_get(ret->subject,d2i_X509_NAME); | ||
132 | M_ASN1_D2I_get(ret->key,d2i_X509_PUBKEY); | ||
133 | if (ver >= 1) /* version 2 extensions */ | ||
134 | { | ||
135 | if (ret->issuerUID != NULL) | ||
136 | { | ||
137 | ASN1_BIT_STRING_free(ret->issuerUID); | ||
138 | ret->issuerUID=NULL; | ||
139 | } | ||
140 | if (ret->subjectUID != NULL) | ||
141 | { | ||
142 | ASN1_BIT_STRING_free(ret->subjectUID); | ||
143 | ret->issuerUID=NULL; | ||
144 | } | ||
145 | M_ASN1_D2I_get_IMP_opt(ret->issuerUID,d2i_ASN1_BIT_STRING, 1, | ||
146 | V_ASN1_BIT_STRING); | ||
147 | M_ASN1_D2I_get_IMP_opt(ret->subjectUID,d2i_ASN1_BIT_STRING, 2, | ||
148 | V_ASN1_BIT_STRING); | ||
149 | } | ||
150 | if (ver >= 2) /* version 3 extensions */ | ||
151 | { | ||
152 | if (ret->extensions != NULL) | ||
153 | while (sk_num(ret->extensions)) | ||
154 | X509_EXTENSION_free((X509_EXTENSION *) | ||
155 | sk_pop(ret->extensions)); | ||
156 | M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION,3, | ||
157 | V_ASN1_SEQUENCE); | ||
158 | } | ||
159 | M_ASN1_D2I_Finish(a,X509_CINF_free,ASN1_F_D2I_X509_CINF); | ||
160 | } | ||
161 | |||
162 | X509_CINF *X509_CINF_new() | ||
163 | { | ||
164 | X509_CINF *ret=NULL; | ||
165 | |||
166 | M_ASN1_New_Malloc(ret,X509_CINF); | ||
167 | ret->version=NULL; | ||
168 | M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new); | ||
169 | M_ASN1_New(ret->signature,X509_ALGOR_new); | ||
170 | M_ASN1_New(ret->issuer,X509_NAME_new); | ||
171 | M_ASN1_New(ret->validity,X509_VAL_new); | ||
172 | M_ASN1_New(ret->subject,X509_NAME_new); | ||
173 | M_ASN1_New(ret->key,X509_PUBKEY_new); | ||
174 | ret->issuerUID=NULL; | ||
175 | ret->subjectUID=NULL; | ||
176 | ret->extensions=NULL; | ||
177 | return(ret); | ||
178 | M_ASN1_New_Error(ASN1_F_X509_CINF_NEW); | ||
179 | } | ||
180 | |||
181 | void X509_CINF_free(a) | ||
182 | X509_CINF *a; | ||
183 | { | ||
184 | if (a == NULL) return; | ||
185 | ASN1_INTEGER_free(a->version); | ||
186 | ASN1_INTEGER_free(a->serialNumber); | ||
187 | X509_ALGOR_free(a->signature); | ||
188 | X509_NAME_free(a->issuer); | ||
189 | X509_VAL_free(a->validity); | ||
190 | X509_NAME_free(a->subject); | ||
191 | X509_PUBKEY_free(a->key); | ||
192 | ASN1_BIT_STRING_free(a->issuerUID); | ||
193 | ASN1_BIT_STRING_free(a->subjectUID); | ||
194 | sk_pop_free(a->extensions,X509_EXTENSION_free); | ||
195 | Free((char *)a); | ||
196 | } | ||
197 | |||
diff --git a/src/lib/libcrypto/bf/Makefile.ssl b/src/lib/libcrypto/bf/Makefile.ssl new file mode 100644 index 0000000000..236671f238 --- /dev/null +++ b/src/lib/libcrypto/bf/Makefile.ssl | |||
@@ -0,0 +1,107 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/blowfish/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= bf | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | CPP= $(CC) -E | ||
9 | INCLUDES= | ||
10 | CFLAG=-g | ||
11 | INSTALLTOP=/usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | AR= ar r | ||
16 | |||
17 | BF_ENC= bf_enc.o | ||
18 | # or use | ||
19 | #DES_ENC= bx86-elf.o | ||
20 | |||
21 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
22 | |||
23 | GENERAL=Makefile | ||
24 | TEST=bftest.c | ||
25 | APPS= | ||
26 | |||
27 | LIB=$(TOP)/libcrypto.a | ||
28 | LIBSRC=bf_skey.c bf_ecb.c bf_enc.c bf_cfb64.c bf_ofb64.c | ||
29 | LIBOBJ=bf_skey.o bf_ecb.o $(BF_ENC) bf_cfb64.o bf_ofb64.o | ||
30 | |||
31 | SRC= $(LIBSRC) | ||
32 | |||
33 | EXHEADER= blowfish.h | ||
34 | HEADER= bf_pi.h bf_locl.h $(EXHEADER) | ||
35 | |||
36 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
37 | |||
38 | top: | ||
39 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
40 | |||
41 | all: lib | ||
42 | |||
43 | lib: $(LIBOBJ) | ||
44 | $(AR) $(LIB) $(LIBOBJ) | ||
45 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
46 | @touch lib | ||
47 | |||
48 | # elf | ||
49 | asm/bx86-elf.o: asm/bx86unix.cpp | ||
50 | $(CPP) -DELF asm/bx86unix.cpp | as -o asm/bx86-elf.o | ||
51 | |||
52 | # solaris | ||
53 | asm/bx86-sol.o: asm/bx86unix.cpp | ||
54 | $(CC) -E -DSOL asm/bx86unix.cpp | sed 's/^#.*//' > asm/bx86-sol.s | ||
55 | as -o asm/bx86-sol.o asm/bx86-sol.s | ||
56 | rm -f asm/bx86-sol.s | ||
57 | |||
58 | # a.out | ||
59 | asm/bx86-out.o: asm/bx86unix.cpp | ||
60 | $(CPP) -DOUT asm/bx86unix.cpp | as -o asm/bx86-out.o | ||
61 | |||
62 | # bsdi | ||
63 | asm/bx86bsdi.o: asm/bx86unix.cpp | ||
64 | $(CPP) -DBSDI asm/bx86unix.cpp | as -o asm/bx86bsdi.o | ||
65 | |||
66 | asm/bx86unix.cpp: | ||
67 | (cd asm; perl bf-586.pl cpp >bx86unix.cpp) | ||
68 | |||
69 | files: | ||
70 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
71 | |||
72 | links: | ||
73 | /bin/rm -f Makefile | ||
74 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
75 | $(TOP)/util/point.sh ../../doc/blowfish.doc blowfish.doc ; | ||
76 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
77 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
78 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
79 | |||
80 | install: | ||
81 | @for i in $(EXHEADER) ; \ | ||
82 | do \ | ||
83 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
84 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
85 | done; | ||
86 | |||
87 | tags: | ||
88 | ctags $(SRC) | ||
89 | |||
90 | tests: | ||
91 | |||
92 | lint: | ||
93 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
94 | |||
95 | depend: | ||
96 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
97 | |||
98 | dclean: | ||
99 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
100 | mv -f Makefile.new $(MAKEFILE) | ||
101 | |||
102 | clean: | ||
103 | /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
104 | |||
105 | errors: | ||
106 | |||
107 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/bio/Makefile.ssl b/src/lib/libcrypto/bio/Makefile.ssl new file mode 100644 index 0000000000..42e11e1c94 --- /dev/null +++ b/src/lib/libcrypto/bio/Makefile.ssl | |||
@@ -0,0 +1,92 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/bio/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= bio | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=bio | ||
19 | ERRC=bio_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= bio_lib.c bio_cb.c $(ERRC).c \ | ||
26 | bss_mem.c bss_null.c bss_fd.c \ | ||
27 | bss_file.c bss_sock.c bss_conn.c \ | ||
28 | bf_null.c bf_buff.c b_print.c b_dump.c \ | ||
29 | b_sock.c bss_acpt.c bf_nbio.c | ||
30 | LIBOBJ= bio_lib.o bio_cb.o $(ERRC).o \ | ||
31 | bss_mem.o bss_null.o bss_fd.o \ | ||
32 | bss_file.o bss_sock.o bss_conn.o \ | ||
33 | bf_null.o bf_buff.o b_print.o b_dump.o \ | ||
34 | b_sock.o bss_acpt.o bf_nbio.o | ||
35 | |||
36 | SRC= $(LIBSRC) | ||
37 | |||
38 | EXHEADER= bio.h bss_file.c | ||
39 | HEADER= $(EXHEADER) | ||
40 | |||
41 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
42 | |||
43 | top: | ||
44 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
45 | |||
46 | all: lib | ||
47 | |||
48 | lib: $(LIBOBJ) | ||
49 | $(AR) $(LIB) $(LIBOBJ) | ||
50 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
51 | @touch lib | ||
52 | |||
53 | files: | ||
54 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
55 | |||
56 | links: | ||
57 | /bin/rm -f Makefile | ||
58 | $(TOP)/util/point.sh Makefile.ssl Makefile; | ||
59 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
60 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
61 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
62 | |||
63 | install: | ||
64 | @for i in $(EXHEADER) bss_file.c ; \ | ||
65 | do \ | ||
66 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
67 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
68 | done; | ||
69 | |||
70 | tags: | ||
71 | ctags $(SRC) | ||
72 | |||
73 | tests: | ||
74 | |||
75 | lint: | ||
76 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
77 | |||
78 | depend: | ||
79 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
80 | |||
81 | dclean: | ||
82 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
83 | mv -f Makefile.new $(MAKEFILE) | ||
84 | |||
85 | clean: | ||
86 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
87 | |||
88 | errors: | ||
89 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
90 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
91 | |||
92 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/bn/Makefile.ssl b/src/lib/libcrypto/bn/Makefile.ssl new file mode 100644 index 0000000000..9809d26cbc --- /dev/null +++ b/src/lib/libcrypto/bn/Makefile.ssl | |||
@@ -0,0 +1,133 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/bn/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= bn | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | BN_MULW= bn_mulw.o | ||
17 | # or use | ||
18 | #BN_MULW= bn86-elf.o | ||
19 | |||
20 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
21 | |||
22 | ERR=bn | ||
23 | ERRC=bn_err | ||
24 | GENERAL=Makefile | ||
25 | TEST=bntest.c exptest.c | ||
26 | APPS= | ||
27 | |||
28 | LIB=$(TOP)/libcrypto.a | ||
29 | LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mod.c bn_mul.c \ | ||
30 | bn_print.c bn_rand.c bn_shift.c bn_sub.c bn_word.c bn_blind.c \ | ||
31 | bn_gcd.c bn_prime.c $(ERRC).c bn_sqr.c bn_mulw.c bn_recp.c bn_mont.c \ | ||
32 | bn_mpi.c | ||
33 | |||
34 | LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_mod.o bn_mul.o \ | ||
35 | bn_print.o bn_rand.o bn_shift.o bn_sub.o bn_word.o bn_blind.o \ | ||
36 | bn_gcd.o bn_prime.o $(ERRC).o bn_sqr.o $(BN_MULW) bn_recp.o bn_mont.o \ | ||
37 | bn_mpi.o | ||
38 | |||
39 | |||
40 | SRC= $(LIBSRC) | ||
41 | |||
42 | EXHEADER= bn.h | ||
43 | HEADER= bn_lcl.h bn_prime.h $(EXHEADER) | ||
44 | |||
45 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
46 | |||
47 | top: | ||
48 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
49 | |||
50 | all: lib | ||
51 | |||
52 | knuth: bn_knuth.c | ||
53 | cc -pg -I.. -I../../include bn_knuth.c -o knuth $(LIB) #../../../libefence.a | ||
54 | |||
55 | knuth.fast: bn_knuth.c | ||
56 | cc -pg -fast -I.. -I../../include bn_knuth.c -o knuth $(LIB) #../../../libefence.a | ||
57 | |||
58 | |||
59 | lib: $(LIBOBJ) | ||
60 | $(AR) $(LIB) $(LIBOBJ) | ||
61 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
62 | @touch lib | ||
63 | |||
64 | # elf | ||
65 | asm/bn86-elf.o: asm/bn86unix.cpp | ||
66 | $(CPP) -DELF asm/bn86unix.cpp | as -o asm/bn86-elf.o | ||
67 | |||
68 | # solaris | ||
69 | asm/bn86-sol.o: asm/bn86unix.cpp | ||
70 | $(CC) -E -DSOL asm/bn86unix.cpp | sed 's/^#.*//' > asm/bn86-sol.s | ||
71 | as -o asm/bn86-sol.o asm/bn86-sol.s | ||
72 | rm -f asm/bn86-sol.s | ||
73 | |||
74 | # a.out | ||
75 | asm/bn86-out.o: asm/bn86unix.cpp | ||
76 | $(CPP) -DOUT asm/bn86unix.cpp | as -o asm/bn86-out.o | ||
77 | |||
78 | # bsdi | ||
79 | asm/bn86bsdi.o: asm/bn86unix.cpp | ||
80 | $(CPP) -DBSDI asm/bn86unix.cpp | as -o asm/bn86bsdi.o | ||
81 | |||
82 | asm/bn86unix.cpp: | ||
83 | (cd asm; perl bn-586.pl cpp >bn86unix.cpp ) | ||
84 | |||
85 | files: | ||
86 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
87 | |||
88 | links: | ||
89 | /bin/rm -f Makefile | ||
90 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
91 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
92 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
93 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
94 | |||
95 | install: | ||
96 | @for i in $(EXHEADER) ; \ | ||
97 | do \ | ||
98 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
99 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
100 | done; | ||
101 | |||
102 | exptest: | ||
103 | /bin/rm -f exptest | ||
104 | gcc -I../../include -g2 -ggdb -o exptest exptest.c ../../libcrypto.a | ||
105 | |||
106 | div: | ||
107 | /bin/rm -f a.out | ||
108 | gcc -I.. -g div.c ../../libcrypto.a | ||
109 | |||
110 | tags: | ||
111 | ctags $(SRC) | ||
112 | |||
113 | tests: | ||
114 | |||
115 | lint: | ||
116 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
117 | |||
118 | depend: | ||
119 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
120 | |||
121 | dclean: | ||
122 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
123 | mv -f Makefile.new $(MAKEFILE) | ||
124 | |||
125 | clean: | ||
126 | /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff bn_mulw.s | ||
127 | |||
128 | errors: | ||
129 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).org # special case .org | ||
130 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
131 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
132 | |||
133 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/buffer/Makefile.ssl b/src/lib/libcrypto/buffer/Makefile.ssl new file mode 100644 index 0000000000..a5f150e523 --- /dev/null +++ b/src/lib/libcrypto/buffer/Makefile.ssl | |||
@@ -0,0 +1,84 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/buffer/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= buffer | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=buffer | ||
19 | ERRC=buf_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= buffer.c $(ERRC).c | ||
26 | LIBOBJ= buffer.o $(ERRC).o | ||
27 | |||
28 | SRC= $(LIBSRC) | ||
29 | |||
30 | EXHEADER= buffer.h | ||
31 | HEADER= $(EXHEADER) | ||
32 | |||
33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
34 | |||
35 | top: | ||
36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
37 | |||
38 | all: lib | ||
39 | |||
40 | lib: $(LIBOBJ) | ||
41 | $(AR) $(LIB) $(LIBOBJ) | ||
42 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
43 | @touch lib | ||
44 | |||
45 | files: | ||
46 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
47 | |||
48 | links: | ||
49 | /bin/rm -f Makefile | ||
50 | $(TOP)/util/point.sh Makefile.ssl Makefile; | ||
51 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
52 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
53 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
54 | |||
55 | install: | ||
56 | @for i in $(EXHEADER) ; \ | ||
57 | do \ | ||
58 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
59 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
60 | done; | ||
61 | |||
62 | tags: | ||
63 | ctags $(SRC) | ||
64 | |||
65 | tests: | ||
66 | |||
67 | lint: | ||
68 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
69 | |||
70 | depend: | ||
71 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
72 | |||
73 | dclean: | ||
74 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
75 | mv -f Makefile.new $(MAKEFILE) | ||
76 | |||
77 | clean: | ||
78 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
79 | |||
80 | errors: | ||
81 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
82 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
83 | |||
84 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/cast/Makefile.ssl b/src/lib/libcrypto/cast/Makefile.ssl new file mode 100644 index 0000000000..0143827ae5 --- /dev/null +++ b/src/lib/libcrypto/cast/Makefile.ssl | |||
@@ -0,0 +1,109 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/cast/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= cast | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | CPP= $(CC) -E | ||
9 | INCLUDES= | ||
10 | CFLAG=-g | ||
11 | INSTALLTOP=/usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | AR= ar r | ||
16 | |||
17 | CAST_ENC=c_enc.o | ||
18 | # or use | ||
19 | #CAST_ENC=asm/cx86-elf.o | ||
20 | #CAST_ENC=asm/cx86-out.o | ||
21 | #CAST_ENC=asm/cx86-sol.o | ||
22 | #CAST_ENC=asm/cx86bdsi.o | ||
23 | |||
24 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
25 | |||
26 | GENERAL=Makefile | ||
27 | TEST=casttest.c | ||
28 | APPS= | ||
29 | |||
30 | LIB=$(TOP)/libcrypto.a | ||
31 | LIBSRC=c_skey.c c_ecb.c c_enc.c c_cfb64.c c_ofb64.c | ||
32 | LIBOBJ=c_skey.o c_ecb.o $(CAST_ENC) c_cfb64.o c_ofb64.o | ||
33 | |||
34 | SRC= $(LIBSRC) | ||
35 | |||
36 | EXHEADER= cast.h | ||
37 | HEADER= cast_s.h cast_lcl.h $(EXHEADER) | ||
38 | |||
39 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
40 | |||
41 | top: | ||
42 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
43 | |||
44 | all: lib | ||
45 | |||
46 | lib: $(LIBOBJ) | ||
47 | $(AR) $(LIB) $(LIBOBJ) | ||
48 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
49 | @touch lib | ||
50 | |||
51 | # elf | ||
52 | asm/cx86-elf.o: asm/cx86unix.cpp | ||
53 | $(CPP) -DELF asm/cx86unix.cpp | as -o asm/cx86-elf.o | ||
54 | |||
55 | # solaris | ||
56 | asm/cx86-sol.o: asm/cx86unix.cpp | ||
57 | $(CC) -E -DSOL asm/cx86unix.cpp | sed 's/^#.*//' > asm/cx86-sol.s | ||
58 | as -o asm/cx86-sol.o asm/cx86-sol.s | ||
59 | rm -f asm/cx86-sol.s | ||
60 | |||
61 | # a.out | ||
62 | asm/cx86-out.o: asm/cx86unix.cpp | ||
63 | $(CPP) -DOUT asm/cx86unix.cpp | as -o asm/cx86-out.o | ||
64 | |||
65 | # bsdi | ||
66 | asm/cx86bsdi.o: asm/cx86unix.cpp | ||
67 | $(CPP) -DBSDI asm/cx86unix.cpp | as -o asm/cx86bsdi.o | ||
68 | |||
69 | asm/cx86unix.cpp: | ||
70 | (cd asm; perl cast-586.pl cpp >cx86unix.cpp) | ||
71 | |||
72 | files: | ||
73 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
74 | |||
75 | links: | ||
76 | /bin/rm -f Makefile | ||
77 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
78 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
79 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
80 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
81 | |||
82 | install: | ||
83 | @for i in $(EXHEADER) ; \ | ||
84 | do \ | ||
85 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
86 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
87 | done; | ||
88 | |||
89 | tags: | ||
90 | ctags $(SRC) | ||
91 | |||
92 | tests: | ||
93 | |||
94 | lint: | ||
95 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
96 | |||
97 | depend: | ||
98 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
99 | |||
100 | dclean: | ||
101 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
102 | mv -f Makefile.new $(MAKEFILE) | ||
103 | |||
104 | clean: | ||
105 | /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
106 | |||
107 | errors: | ||
108 | |||
109 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/conf/Makefile.ssl b/src/lib/libcrypto/conf/Makefile.ssl new file mode 100644 index 0000000000..00e917aa44 --- /dev/null +++ b/src/lib/libcrypto/conf/Makefile.ssl | |||
@@ -0,0 +1,85 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/conf/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= conf | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=conf | ||
19 | ERRC=conf_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= conf.c $(ERRC).c | ||
26 | |||
27 | LIBOBJ= conf.o $(ERRC).o | ||
28 | |||
29 | SRC= $(LIBSRC) | ||
30 | |||
31 | EXHEADER= conf.h | ||
32 | HEADER= conf_lcl.h $(EXHEADER) | ||
33 | |||
34 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
35 | |||
36 | top: | ||
37 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
38 | |||
39 | all: lib | ||
40 | |||
41 | lib: $(LIBOBJ) | ||
42 | $(AR) $(LIB) $(LIBOBJ) | ||
43 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
44 | @touch lib | ||
45 | |||
46 | files: | ||
47 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
48 | |||
49 | links: | ||
50 | /bin/rm -f Makefile | ||
51 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
52 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
53 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
54 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
55 | |||
56 | install: | ||
57 | @for i in $(EXHEADER) ; \ | ||
58 | do \ | ||
59 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
60 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
61 | done; | ||
62 | |||
63 | tags: | ||
64 | ctags $(SRC) | ||
65 | |||
66 | tests: | ||
67 | |||
68 | lint: | ||
69 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
70 | |||
71 | depend: | ||
72 | $(MAKEDEPEND) $(INCLUDES) $(LIBSRC) | ||
73 | |||
74 | dclean: | ||
75 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
76 | mv -f Makefile.new $(MAKEFILE) | ||
77 | |||
78 | clean: | ||
79 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
80 | |||
81 | errors: | ||
82 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
83 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
84 | |||
85 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/des/FILES b/src/lib/libcrypto/des/FILES new file mode 100644 index 0000000000..4c7ea2de7a --- /dev/null +++ b/src/lib/libcrypto/des/FILES | |||
@@ -0,0 +1,96 @@ | |||
1 | /* General stuff */ | ||
2 | COPYRIGHT - Copyright info. | ||
3 | MODES.DES - A description of the features of the different modes of DES. | ||
4 | FILES - This file. | ||
5 | INSTALL - How to make things compile. | ||
6 | Imakefile - For use with kerberos. | ||
7 | README - What this package is. | ||
8 | VERSION - Which version this is and what was changed. | ||
9 | KERBEROS - Kerberos version 4 notes. | ||
10 | Makefile.PL - An old makefile to build with perl5, not current. | ||
11 | Makefile.ssl - The SSLeay makefile | ||
12 | Makefile.uni - The normal unix makefile. | ||
13 | GNUmakefile - The makefile for use with glibc. | ||
14 | makefile.bc - A Borland C makefile | ||
15 | times - Some outputs from 'speed' on some machines. | ||
16 | vms.com - For use when compiling under VMS | ||
17 | |||
18 | /* My SunOS des(1) replacement */ | ||
19 | des.c - des(1) source code. | ||
20 | des.man - des(1) manual. | ||
21 | |||
22 | /* Testing and timing programs. */ | ||
23 | destest.c - Source for libdes.a test program. | ||
24 | speed.c - Source for libdes.a timing program. | ||
25 | rpw.c - Source for libdes.a testing password reading routines. | ||
26 | |||
27 | /* libdes.a source code */ | ||
28 | des_crypt.man - libdes.a manual page. | ||
29 | des.h - Public libdes.a header file. | ||
30 | ecb_enc.c - des_ecb_encrypt() source, this contains the basic DES code. | ||
31 | ecb3_enc.c - des_ecb3_encrypt() source. | ||
32 | cbc_ckm.c - des_cbc_cksum() source. | ||
33 | cbc_enc.c - des_cbc_encrypt() source. | ||
34 | ncbc_enc.c - des_cbc_encrypt() that is 'normal' in that it copies | ||
35 | the new iv values back in the passed iv vector. | ||
36 | ede_enc.c - des_ede3_cbc_encrypt() cbc mode des using triple DES. | ||
37 | cbc3_enc.c - des_3cbc_encrypt() source, don't use this function. | ||
38 | cfb_enc.c - des_cfb_encrypt() source. | ||
39 | cfb64enc.c - des_cfb64_encrypt() cfb in 64 bit mode but setup to be | ||
40 | used as a stream cipher. | ||
41 | cfb64ede.c - des_ede3_cfb64_encrypt() cfb in 64 bit mode but setup to be | ||
42 | used as a stream cipher and using triple DES. | ||
43 | ofb_enc.c - des_cfb_encrypt() source. | ||
44 | ofb64_enc.c - des_ofb_encrypt() ofb in 64 bit mode but setup to be | ||
45 | used as a stream cipher. | ||
46 | ofb64ede.c - des_ede3_ofb64_encrypt() ofb in 64 bit mode but setup to be | ||
47 | used as a stream cipher and using triple DES. | ||
48 | enc_read.c - des_enc_read() source. | ||
49 | enc_writ.c - des_enc_write() source. | ||
50 | pcbc_enc.c - des_pcbc_encrypt() source. | ||
51 | qud_cksm.c - quad_cksum() source. | ||
52 | rand_key.c - des_random_key() source. | ||
53 | read_pwd.c - Source for des_read_password() plus related functions. | ||
54 | set_key.c - Source for des_set_key(). | ||
55 | str2key.c - Covert a string of any length into a key. | ||
56 | fcrypt.c - A small, fast version of crypt(3). | ||
57 | des_locl.h - Internal libdes.a header file. | ||
58 | podd.h - Odd parity tables - used in des_set_key(). | ||
59 | sk.h - Lookup tables used in des_set_key(). | ||
60 | spr.h - What is left of the S tables - used in ecb_encrypt(). | ||
61 | des_ver.h - header file for the external definition of the | ||
62 | version string. | ||
63 | des.doc - SSLeay documentation for the library. | ||
64 | |||
65 | /* The perl scripts - you can ignore these files they are only | ||
66 | * included for the curious */ | ||
67 | des.pl - des in perl anyone? des_set_key and des_ecb_encrypt | ||
68 | both done in a perl library. | ||
69 | testdes.pl - Testing program for des.pl | ||
70 | doIP - Perl script used to develop IP xor/shift code. | ||
71 | doPC1 - Perl script used to develop PC1 xor/shift code. | ||
72 | doPC2 - Generates sk.h. | ||
73 | PC1 - Output of doPC1 should be the same as output from PC1. | ||
74 | PC2 - used in development of doPC2. | ||
75 | shifts.pl - Perl library used by my perl scripts. | ||
76 | |||
77 | /* I started making a perl5 dynamic library for libdes | ||
78 | * but did not fully finish, these files are part of that effort. */ | ||
79 | DES.pm | ||
80 | DES.pod | ||
81 | DES.xs | ||
82 | t | ||
83 | typemap | ||
84 | |||
85 | /* The following are for use with sun RPC implementaions. */ | ||
86 | rpc_des.h | ||
87 | rpc_enc.c | ||
88 | |||
89 | /* The following are contibuted by Mark Murray <mark@grondar.za>. They | ||
90 | * are not normally built into libdes due to machine specific routines | ||
91 | * contained in them. They are for use in the most recent incarnation of | ||
92 | * export kerberos v 4 (eBones). */ | ||
93 | supp.c | ||
94 | new_rkey.c | ||
95 | |||
96 | |||
diff --git a/src/lib/libcrypto/des/Makefile.ssl b/src/lib/libcrypto/des/Makefile.ssl new file mode 100644 index 0000000000..78b5189ee3 --- /dev/null +++ b/src/lib/libcrypto/des/Makefile.ssl | |||
@@ -0,0 +1,140 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/des/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= des | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | CPP= $(CC) -E | ||
9 | INCLUDES= | ||
10 | CFLAG=-g | ||
11 | INSTALLTOP=/usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | AR= ar r | ||
16 | DES_ENC= des_enc.o fcrypt_b.o | ||
17 | # or use | ||
18 | #DES_ENC= dx86-elf.o yx86-elf.o | ||
19 | |||
20 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
21 | |||
22 | GENERAL=Makefile des.org des_locl.org | ||
23 | TEST=destest.c | ||
24 | APPS= | ||
25 | |||
26 | LIB=$(TOP)/libcrypto.a | ||
27 | LIBSRC= cbc_cksm.c cbc_enc.c cfb64enc.c cfb_enc.c \ | ||
28 | ecb3_enc.c ecb_enc.c enc_read.c enc_writ.c \ | ||
29 | fcrypt.c ofb64enc.c ofb_enc.c pcbc_enc.c \ | ||
30 | qud_cksm.c rand_key.c read_pwd.c rpc_enc.c set_key.c \ | ||
31 | des_enc.c fcrypt_b.c read2pwd.c \ | ||
32 | fcrypt.c xcbc_enc.c \ | ||
33 | str2key.c cfb64ede.c ofb64ede.c supp.c | ||
34 | |||
35 | LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \ | ||
36 | ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \ | ||
37 | enc_read.o enc_writ.o ofb64enc.o \ | ||
38 | ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \ | ||
39 | ${DES_ENC} read2pwd.o \ | ||
40 | fcrypt.o xcbc_enc.o read_pwd.o rpc_enc.o cbc_cksm.o supp.o | ||
41 | |||
42 | SRC= $(LIBSRC) | ||
43 | |||
44 | EXHEADER= des.h | ||
45 | HEADER= des_locl.h rpc_des.h podd.h sk.h spr.h des_ver.h $(EXHEADER) | ||
46 | |||
47 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
48 | |||
49 | top: | ||
50 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
51 | |||
52 | all: lib | ||
53 | |||
54 | lib: $(LIBOBJ) | ||
55 | $(AR) $(LIB) $(LIBOBJ) | ||
56 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
57 | @touch lib | ||
58 | |||
59 | # elf | ||
60 | asm/dx86-elf.o: asm/dx86unix.cpp | ||
61 | $(CPP) -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o | ||
62 | |||
63 | asm/yx86-elf.o: asm/yx86unix.cpp | ||
64 | $(CPP) -DELF asm/yx86unix.cpp | as -o asm/yx86-elf.o | ||
65 | |||
66 | # solaris | ||
67 | asm/dx86-sol.o: asm/dx86unix.cpp | ||
68 | $(CC) -E -DSOL asm/dx86unix.cpp | sed 's/^#.*//' > asm/dx86-sol.s | ||
69 | as -o asm/dx86-sol.o asm/dx86-sol.s | ||
70 | rm -f asm/dx86-sol.s | ||
71 | |||
72 | asm/yx86-sol.o: asm/yx86unix.cpp | ||
73 | $(CC) -E -DSOL asm/yx86unix.cpp | sed 's/^#.*//' > asm/yx86-sol.s | ||
74 | as -o asm/yx86-sol.o asm/yx86-sol.s | ||
75 | rm -f asm/yx86-sol.s | ||
76 | |||
77 | # a.out | ||
78 | asm/dx86-out.o: asm/dx86unix.cpp | ||
79 | $(CPP) -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o | ||
80 | |||
81 | asm/yx86-out.o: asm/yx86unix.cpp | ||
82 | $(CPP) -DOUT asm/yx86unix.cpp | as -o asm/yx86-out.o | ||
83 | |||
84 | # bsdi | ||
85 | asm/dx86bsdi.o: asm/dx86unix.cpp | ||
86 | $(CPP) -DBSDI asm/dx86unix.cpp | as -o asm/dx86bsdi.o | ||
87 | |||
88 | asm/yx86bsdi.o: asm/yx86unix.cpp | ||
89 | $(CPP) -DBSDI asm/yx86unix.cpp | as -o asm/yx86bsdi.o | ||
90 | |||
91 | asm/dx86unix.cpp: | ||
92 | (cd asm; perl des-586.pl cpp >dx86unix.cpp) | ||
93 | |||
94 | asm/yx86unix.cpp: | ||
95 | (cd asm; perl crypt586.pl cpp >yx86unix.cpp) | ||
96 | |||
97 | files: | ||
98 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
99 | |||
100 | links: | ||
101 | /bin/rm -f Makefile | ||
102 | $(TOP)/util/point.sh Makefile.ssl Makefile | ||
103 | /bin/rm -f des.doc | ||
104 | /bin/rm -fr asm/perlasm | ||
105 | $(TOP)/util/point.sh ../../perlasm asm/perlasm | ||
106 | $(TOP)/util/point.sh ../../doc/des.doc des.doc | ||
107 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
108 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
109 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
110 | |||
111 | install: installs | ||
112 | |||
113 | installs: | ||
114 | @for i in $(EXHEADER) ; \ | ||
115 | do \ | ||
116 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
117 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
118 | done; | ||
119 | |||
120 | tags: | ||
121 | ctags $(SRC) | ||
122 | |||
123 | tests: | ||
124 | |||
125 | lint: | ||
126 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
127 | |||
128 | depend: | ||
129 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
130 | |||
131 | dclean: | ||
132 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
133 | mv -f Makefile.new $(MAKEFILE) | ||
134 | |||
135 | clean: | ||
136 | /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
137 | |||
138 | errors: | ||
139 | |||
140 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/dh/Makefile.ssl b/src/lib/libcrypto/dh/Makefile.ssl new file mode 100644 index 0000000000..dfa7e4525d --- /dev/null +++ b/src/lib/libcrypto/dh/Makefile.ssl | |||
@@ -0,0 +1,84 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/dh/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= dh | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=dh | ||
19 | ERRC=dh_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= dhtest.c | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= dh_gen.c dh_key.c dh_lib.c dh_check.c $(ERRC).c | ||
26 | LIBOBJ= dh_gen.o dh_key.o dh_lib.o dh_check.o $(ERRC).o | ||
27 | |||
28 | SRC= $(LIBSRC) | ||
29 | |||
30 | EXHEADER= dh.h | ||
31 | HEADER= $(EXHEADER) | ||
32 | |||
33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
34 | |||
35 | top: | ||
36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
37 | |||
38 | all: lib | ||
39 | |||
40 | lib: $(LIBOBJ) | ||
41 | $(AR) $(LIB) $(LIBOBJ) | ||
42 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
43 | @touch lib | ||
44 | |||
45 | files: | ||
46 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
47 | |||
48 | links: | ||
49 | /bin/rm -f Makefile | ||
50 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
51 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
52 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
53 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
54 | |||
55 | install: | ||
56 | @for i in $(EXHEADER) ; \ | ||
57 | do \ | ||
58 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
59 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
60 | done; | ||
61 | |||
62 | tags: | ||
63 | ctags $(SRC) | ||
64 | |||
65 | tests: | ||
66 | |||
67 | lint: | ||
68 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
69 | |||
70 | depend: | ||
71 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
72 | |||
73 | dclean: | ||
74 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
75 | mv -f Makefile.new $(MAKEFILE) | ||
76 | |||
77 | clean: | ||
78 | /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
79 | |||
80 | errors: | ||
81 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
82 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
83 | |||
84 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/dsa/Makefile.ssl b/src/lib/libcrypto/dsa/Makefile.ssl new file mode 100644 index 0000000000..2cc4ddb39e --- /dev/null +++ b/src/lib/libcrypto/dsa/Makefile.ssl | |||
@@ -0,0 +1,84 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/dsa/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= dsa | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=dsa | ||
19 | ERRC=dsa_err | ||
20 | GENERAL=Makefile | ||
21 | TEST=dsatest.c | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_vrf.c dsa_sign.c $(ERRC).c | ||
26 | LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_vrf.o dsa_sign.o $(ERRC).o | ||
27 | |||
28 | SRC= $(LIBSRC) | ||
29 | |||
30 | EXHEADER= dsa.h | ||
31 | HEADER= $(EXHEADER) | ||
32 | |||
33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
34 | |||
35 | top: | ||
36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
37 | |||
38 | all: lib | ||
39 | |||
40 | lib: $(LIBOBJ) | ||
41 | $(AR) $(LIB) $(LIBOBJ) | ||
42 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
43 | @touch lib | ||
44 | |||
45 | files: | ||
46 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
47 | |||
48 | links: | ||
49 | /bin/rm -f Makefile | ||
50 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
51 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
52 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
53 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
54 | |||
55 | install: | ||
56 | @for i in $(EXHEADER) ; \ | ||
57 | do \ | ||
58 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
59 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
60 | done; | ||
61 | |||
62 | tags: | ||
63 | ctags $(SRC) | ||
64 | |||
65 | tests: | ||
66 | |||
67 | lint: | ||
68 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
69 | |||
70 | depend: | ||
71 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
72 | |||
73 | dclean: | ||
74 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
75 | mv -f Makefile.new $(MAKEFILE) | ||
76 | |||
77 | clean: | ||
78 | /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
79 | |||
80 | errors: | ||
81 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
82 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
83 | |||
84 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/err/Makefile.ssl b/src/lib/libcrypto/err/Makefile.ssl new file mode 100644 index 0000000000..57c87eb041 --- /dev/null +++ b/src/lib/libcrypto/err/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/err/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= err | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST= | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=err.c err_all.c err_prn.c | ||
24 | LIBOBJ=err.o err_all.o err_prn.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= err.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/evp/Makefile.ssl b/src/lib/libcrypto/evp/Makefile.ssl new file mode 100644 index 0000000000..8bf2516458 --- /dev/null +++ b/src/lib/libcrypto/evp/Makefile.ssl | |||
@@ -0,0 +1,111 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/evp/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= evp | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=evp | ||
19 | ERRC=evp_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= encode.c digest.c evp_enc.c evp_key.c \ | ||
26 | e_ecb_d.c e_cbc_d.c e_cfb_d.c e_ofb_d.c \ | ||
27 | e_ecb_i.c e_cbc_i.c e_cfb_i.c e_ofb_i.c \ | ||
28 | e_ecb_3d.c e_cbc_3d.c e_rc4.c names.c \ | ||
29 | e_cfb_3d.c e_ofb_3d.c e_xcbc_d.c \ | ||
30 | e_ecb_r2.c e_cbc_r2.c e_cfb_r2.c e_ofb_r2.c \ | ||
31 | e_ecb_bf.c e_cbc_bf.c e_cfb_bf.c e_ofb_bf.c \ | ||
32 | e_ecb_c.c e_cbc_c.c e_cfb_c.c e_ofb_c.c \ | ||
33 | e_ecb_r5.c e_cbc_r5.c e_cfb_r5.c e_ofb_r5.c \ | ||
34 | m_null.c m_md2.c m_md5.c m_sha.c m_sha1.c m_dss.c m_dss1.c m_mdc2.c \ | ||
35 | m_ripemd.c \ | ||
36 | p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \ | ||
37 | bio_md.c bio_b64.c bio_enc.c $(ERRC).c e_null.c \ | ||
38 | c_all.c evp_lib.c | ||
39 | |||
40 | LIBOBJ= encode.o digest.o evp_enc.o evp_key.o \ | ||
41 | e_ecb_d.o e_cbc_d.o e_cfb_d.o e_ofb_d.o \ | ||
42 | e_ecb_i.o e_cbc_i.o e_cfb_i.o e_ofb_i.o \ | ||
43 | e_ecb_3d.o e_cbc_3d.o e_rc4.o names.o \ | ||
44 | e_cfb_3d.o e_ofb_3d.o e_xcbc_d.o \ | ||
45 | e_ecb_r2.o e_cbc_r2.o e_cfb_r2.o e_ofb_r2.o \ | ||
46 | e_ecb_bf.o e_cbc_bf.o e_cfb_bf.o e_ofb_bf.o \ | ||
47 | e_ecb_c.o e_cbc_c.o e_cfb_c.o e_ofb_c.o \ | ||
48 | e_ecb_r5.o e_cbc_r5.o e_cfb_r5.o e_ofb_r5.o \ | ||
49 | m_null.o m_md2.o m_md5.o m_sha.o m_sha1.o m_dss.o m_dss1.o m_mdc2.o \ | ||
50 | m_ripemd.o \ | ||
51 | p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \ | ||
52 | bio_md.o bio_b64.o bio_enc.o $(ERRC).o e_null.o \ | ||
53 | c_all.o evp_lib.o | ||
54 | |||
55 | SRC= $(LIBSRC) | ||
56 | |||
57 | EXHEADER= evp.h | ||
58 | HEADER= $(EXHEADER) | ||
59 | |||
60 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
61 | |||
62 | top: | ||
63 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
64 | |||
65 | all: lib | ||
66 | |||
67 | lib: $(LIBOBJ) | ||
68 | $(AR) $(LIB) $(LIBOBJ) | ||
69 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
70 | @touch lib | ||
71 | |||
72 | files: | ||
73 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
74 | |||
75 | links: | ||
76 | /bin/rm -f Makefile | ||
77 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
78 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
79 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
80 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
81 | |||
82 | install: | ||
83 | @for i in $(EXHEADER) ; \ | ||
84 | do \ | ||
85 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
86 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
87 | done; | ||
88 | |||
89 | tags: | ||
90 | ctags $(SRC) | ||
91 | |||
92 | tests: | ||
93 | |||
94 | lint: | ||
95 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
96 | |||
97 | depend: | ||
98 | $(MAKEDEPEND) $(INCLUDES) $(LIBSRC) | ||
99 | |||
100 | dclean: | ||
101 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
102 | mv -f Makefile.new $(MAKEFILE) | ||
103 | |||
104 | clean: | ||
105 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
106 | |||
107 | errors: | ||
108 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
109 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
110 | |||
111 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/hmac/Makefile.ssl b/src/lib/libcrypto/hmac/Makefile.ssl new file mode 100644 index 0000000000..7a042b7261 --- /dev/null +++ b/src/lib/libcrypto/hmac/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/md/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= hmac | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST=hmactest.c | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=hmac.c | ||
24 | LIBOBJ=hmac.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= hmac.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/idea/Makefile.ssl b/src/lib/libcrypto/idea/Makefile.ssl new file mode 100644 index 0000000000..41b42ce03b --- /dev/null +++ b/src/lib/libcrypto/idea/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/idea/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= idea | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST=ideatest.c | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=i_cbc.c i_cfb64.c i_ofb64.c i_ecb.c i_skey.c | ||
24 | LIBOBJ=i_cbc.o i_cfb64.o i_ofb64.o i_ecb.o i_skey.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= idea.h | ||
29 | HEADER= idea_lcl.h $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/lhash/Makefile.ssl b/src/lib/libcrypto/lhash/Makefile.ssl new file mode 100644 index 0000000000..cb08547b4f --- /dev/null +++ b/src/lib/libcrypto/lhash/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/lhash/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= lhash | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST= | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=lhash.c lh_stats.c | ||
24 | LIBOBJ=lhash.o lh_stats.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= lhash.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/md2/Makefile.ssl b/src/lib/libcrypto/md2/Makefile.ssl new file mode 100644 index 0000000000..d8e7200c83 --- /dev/null +++ b/src/lib/libcrypto/md2/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/md/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= md | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST=md2test.c | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=md2_dgst.c md5_one.c | ||
24 | LIBOBJ=md2_dgst.o md2_one.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= md2.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/md5/Makefile.ssl b/src/lib/libcrypto/md5/Makefile.ssl new file mode 100644 index 0000000000..47e1ce05ca --- /dev/null +++ b/src/lib/libcrypto/md5/Makefile.ssl | |||
@@ -0,0 +1,104 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/md5/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= md5 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | CPP= $(CC) -E | ||
9 | INCLUDES= | ||
10 | CFLAG=-g | ||
11 | INSTALLTOP=/usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | AR= ar r | ||
16 | |||
17 | MD5_ASM_OBJ= | ||
18 | |||
19 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
20 | |||
21 | GENERAL=Makefile | ||
22 | TEST=md5test.c | ||
23 | APPS=md5.c | ||
24 | |||
25 | LIB=$(TOP)/libcrypto.a | ||
26 | LIBSRC=md5_dgst.c md5_one.c | ||
27 | LIBOBJ=md5_dgst.o md5_one.o $(MD5_ASM_OBJ) | ||
28 | |||
29 | SRC= $(LIBSRC) | ||
30 | |||
31 | EXHEADER= md5.h | ||
32 | HEADER= md5_locl.h $(EXHEADER) | ||
33 | |||
34 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
35 | |||
36 | top: | ||
37 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
38 | |||
39 | all: lib | ||
40 | |||
41 | lib: $(LIBOBJ) | ||
42 | $(AR) $(LIB) $(LIBOBJ) | ||
43 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
44 | @touch lib | ||
45 | |||
46 | # elf | ||
47 | asm/mx86-elf.o: asm/mx86unix.cpp | ||
48 | $(CPP) -DELF asm/mx86unix.cpp | as -o asm/mx86-elf.o | ||
49 | |||
50 | # solaris | ||
51 | asm/mx86-sol.o: asm/mx86unix.cpp | ||
52 | $(CC) -E -DSOL asm/mx86unix.cpp | sed 's/^#.*//' > asm/mx86-sol.s | ||
53 | as -o asm/mx86-sol.o asm/mx86-sol.s | ||
54 | rm -f asm/mx86-sol.s | ||
55 | |||
56 | # a.out | ||
57 | asm/mx86-out.o: asm/mx86unix.cpp | ||
58 | $(CPP) -DOUT asm/mx86unix.cpp | as -o asm/mx86-out.o | ||
59 | |||
60 | # bsdi | ||
61 | asm/mx86bsdi.o: asm/mx86unix.cpp | ||
62 | $(CPP) -DBSDI asm/mx86unix.cpp | as -o asm/mx86bsdi.o | ||
63 | |||
64 | asm/mx86unix.cpp: | ||
65 | (cd asm; perl md5-586.pl cpp >mx86unix.cpp) | ||
66 | |||
67 | files: | ||
68 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
69 | |||
70 | links: | ||
71 | /bin/rm -f Makefile | ||
72 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
73 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
74 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
75 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
76 | |||
77 | install: | ||
78 | @for i in $(EXHEADER) ; \ | ||
79 | do \ | ||
80 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
81 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
82 | done; | ||
83 | |||
84 | tags: | ||
85 | ctags $(SRC) | ||
86 | |||
87 | tests: | ||
88 | |||
89 | lint: | ||
90 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
91 | |||
92 | depend: | ||
93 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
94 | |||
95 | dclean: | ||
96 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
97 | mv -f Makefile.new $(MAKEFILE) | ||
98 | |||
99 | clean: | ||
100 | /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
101 | |||
102 | errors: | ||
103 | |||
104 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/mdc2/Makefile.ssl b/src/lib/libcrypto/mdc2/Makefile.ssl new file mode 100644 index 0000000000..495a2789a0 --- /dev/null +++ b/src/lib/libcrypto/mdc2/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/mdc2/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= mdc2 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST= mdc2test.c | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=mdc2dgst.c mdc2_one.c | ||
24 | LIBOBJ=mdc2dgst.o mdc2_one.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= mdc2.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/objects/Makefile.ssl b/src/lib/libcrypto/objects/Makefile.ssl new file mode 100644 index 0000000000..320523cea1 --- /dev/null +++ b/src/lib/libcrypto/objects/Makefile.ssl | |||
@@ -0,0 +1,87 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/objects/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= objects | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=objects | ||
19 | ERRC=obj_err | ||
20 | GENERAL=Makefile README | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= obj_dat.c obj_lib.c $(ERRC).c | ||
26 | LIBOBJ= obj_dat.o obj_lib.o $(ERRC).o | ||
27 | |||
28 | SRC= $(LIBSRC) | ||
29 | |||
30 | EXHEADER= objects.h | ||
31 | HEADER= $(EXHEADER) obj_dat.h | ||
32 | |||
33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
34 | |||
35 | top: | ||
36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
37 | |||
38 | all: obj_dat.h lib | ||
39 | |||
40 | obj_dat.h: objects.h obj_dat.pl | ||
41 | perl ./obj_dat.pl < objects.h > obj_dat.h | ||
42 | |||
43 | lib: $(LIBOBJ) | ||
44 | $(AR) $(LIB) $(LIBOBJ) | ||
45 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
46 | @touch lib | ||
47 | |||
48 | files: | ||
49 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
50 | |||
51 | links: | ||
52 | /bin/rm -f Makefile | ||
53 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
54 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
55 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
56 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
57 | |||
58 | install: | ||
59 | @for i in $(EXHEADER) ; \ | ||
60 | do \ | ||
61 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
62 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
63 | done; | ||
64 | |||
65 | tags: | ||
66 | ctags $(SRC) | ||
67 | |||
68 | tests: | ||
69 | |||
70 | lint: | ||
71 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
72 | |||
73 | depend: | ||
74 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
75 | |||
76 | dclean: | ||
77 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
78 | mv -f Makefile.new $(MAKEFILE) | ||
79 | |||
80 | clean: | ||
81 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
82 | |||
83 | errors: | ||
84 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
85 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
86 | |||
87 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/pem/Makefile.ssl b/src/lib/libcrypto/pem/Makefile.ssl new file mode 100644 index 0000000000..fc04a88fd9 --- /dev/null +++ b/src/lib/libcrypto/pem/Makefile.ssl | |||
@@ -0,0 +1,96 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/pem/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= pem | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=pem | ||
19 | ERRC=pem_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | CTX_SIZE= ctx_size | ||
25 | |||
26 | LIB=$(TOP)/libcrypto.a | ||
27 | LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c $(ERRC).c | ||
28 | |||
29 | LIBOBJ= pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o $(ERRC).o | ||
30 | |||
31 | SRC= $(LIBSRC) | ||
32 | |||
33 | EXHEADER= pem.h | ||
34 | HEADER= $(EXHEADER) | ||
35 | |||
36 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
37 | |||
38 | top: | ||
39 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
40 | |||
41 | all: pem.h lib | ||
42 | |||
43 | pem.h: $(CTX_SIZE) | ||
44 | ./$(CTX_SIZE) <pem.org >pem.new | ||
45 | if [ -f pem.h ]; then mv -f pem.h pem.old; fi | ||
46 | mv -f pem.new pem.h | ||
47 | |||
48 | $(CTX_SIZE): $(CTX_SIZE).o | ||
49 | $(CC) $(CFLAGS) -o $(CTX_SIZE) $(CTX_SIZE).o | ||
50 | |||
51 | lib: $(LIBOBJ) | ||
52 | $(AR) $(LIB) $(LIBOBJ) | ||
53 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
54 | @touch lib | ||
55 | |||
56 | files: | ||
57 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
58 | |||
59 | links: | ||
60 | /bin/rm -f Makefile | ||
61 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
62 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
63 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
64 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
65 | |||
66 | install: | ||
67 | @for i in $(EXHEADER) ; \ | ||
68 | do \ | ||
69 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
70 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
71 | done; | ||
72 | |||
73 | tags: | ||
74 | ctags $(SRC) | ||
75 | |||
76 | tests: | ||
77 | |||
78 | lint: | ||
79 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
80 | |||
81 | depend: | ||
82 | $(MAKEDEPEND) $(INCLUDES) $(CTX_SIZE).c $(LIBSRC) | ||
83 | |||
84 | dclean: | ||
85 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
86 | mv -f Makefile.new $(MAKEFILE) | ||
87 | |||
88 | clean: | ||
89 | /bin/rm -f $(CTX_SIZE) *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
90 | |||
91 | errors: | ||
92 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).org # SPECIAL CASE .org | ||
93 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
94 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
95 | |||
96 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/pkcs7/Makefile.ssl b/src/lib/libcrypto/pkcs7/Makefile.ssl new file mode 100644 index 0000000000..a88359b320 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/Makefile.ssl | |||
@@ -0,0 +1,86 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/asn1/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= pkcs7 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=pkcs7 | ||
19 | ERRC=pkcs7err | ||
20 | GENERAL=Makefile README | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= pk7_lib.c pkcs7err.c pk7_doit.c | ||
26 | LIBOBJ= pk7_lib.o pkcs7err.o pk7_doit.o | ||
27 | |||
28 | SRC= $(LIBSRC) | ||
29 | |||
30 | EXHEADER= pkcs7.h | ||
31 | HEADER= $(EXHEADER) | ||
32 | |||
33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
34 | |||
35 | top: | ||
36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
37 | |||
38 | test: | ||
39 | |||
40 | all: lib | ||
41 | |||
42 | lib: $(LIBOBJ) | ||
43 | $(AR) $(LIB) $(LIBOBJ) | ||
44 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
45 | @touch lib | ||
46 | |||
47 | files: | ||
48 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
49 | |||
50 | links: | ||
51 | /bin/rm -f Makefile | ||
52 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
53 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
54 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
55 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
56 | |||
57 | install: | ||
58 | @for i in $(EXHEADER) ; \ | ||
59 | do \ | ||
60 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
61 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
62 | done; | ||
63 | |||
64 | tags: | ||
65 | ctags $(SRC) | ||
66 | |||
67 | tests: | ||
68 | |||
69 | lint: | ||
70 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
71 | |||
72 | depend: | ||
73 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
74 | |||
75 | dclean: | ||
76 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
77 | mv -f Makefile.new $(MAKEFILE) | ||
78 | |||
79 | clean: | ||
80 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
81 | |||
82 | errors: | ||
83 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
84 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
85 | |||
86 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/rand/Makefile.ssl b/src/lib/libcrypto/rand/Makefile.ssl new file mode 100644 index 0000000000..d04f0a9b43 --- /dev/null +++ b/src/lib/libcrypto/rand/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/rand/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rand | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST= randtest.c | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=md_rand.c randfile.c | ||
24 | LIBOBJ=md_rand.o randfile.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= rand.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/rc2/Makefile.ssl b/src/lib/libcrypto/rc2/Makefile.ssl new file mode 100644 index 0000000000..c5138f13e2 --- /dev/null +++ b/src/lib/libcrypto/rc2/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/rc2/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rc2 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST=rc2test.c | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=rc2_ecb.c rc2_skey.c rc2_cbc.c rc2cfb64.c rc2ofb64.c | ||
24 | LIBOBJ=rc2_ecb.o rc2_skey.o rc2_cbc.o rc2cfb64.o rc2ofb64.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= rc2.h | ||
29 | HEADER= rc2_locl.h $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/rc4/Makefile.ssl b/src/lib/libcrypto/rc4/Makefile.ssl new file mode 100644 index 0000000000..19c1e980f3 --- /dev/null +++ b/src/lib/libcrypto/rc4/Makefile.ssl | |||
@@ -0,0 +1,108 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/rc4/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rc4 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | RC4_ENC=rc4_enc.o | ||
17 | # or use | ||
18 | #RC4_ENC=asm/rx86-elf.o | ||
19 | #RC4_ENC=asm/rx86-out.o | ||
20 | #RC4_ENC=asm/rx86-sol.o | ||
21 | #RC4_ENC=asm/rx86bdsi.o | ||
22 | |||
23 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
24 | |||
25 | GENERAL=Makefile | ||
26 | TEST=rc4test.c | ||
27 | APPS= | ||
28 | |||
29 | LIB=$(TOP)/libcrypto.a | ||
30 | LIBSRC=rc4_skey.c rc4_enc.c | ||
31 | LIBOBJ=rc4_skey.o $(RC4_ENC) | ||
32 | |||
33 | SRC= $(LIBSRC) | ||
34 | |||
35 | EXHEADER= rc4.h | ||
36 | HEADER= $(EXHEADER) rc4_locl.h | ||
37 | |||
38 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
39 | |||
40 | top: | ||
41 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
42 | |||
43 | all: lib | ||
44 | |||
45 | lib: $(LIBOBJ) | ||
46 | $(AR) $(LIB) $(LIBOBJ) | ||
47 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
48 | @touch lib | ||
49 | |||
50 | # elf | ||
51 | asm/rx86-elf.o: asm/rx86unix.cpp | ||
52 | $(CPP) -DELF asm/rx86unix.cpp | as -o asm/rx86-elf.o | ||
53 | |||
54 | # solaris | ||
55 | asm/rx86-sol.o: asm/rx86unix.cpp | ||
56 | $(CC) -E -DSOL asm/rx86unix.cpp | sed 's/^#.*//' > asm/rx86-sol.s | ||
57 | as -o asm/rx86-sol.o asm/rx86-sol.s | ||
58 | rm -f asm/rx86-sol.s | ||
59 | |||
60 | # a.out | ||
61 | asm/rx86-out.o: asm/rx86unix.cpp | ||
62 | $(CPP) -DOUT asm/rx86unix.cpp | as -o asm/rx86-out.o | ||
63 | |||
64 | # bsdi | ||
65 | asm/rx86bsdi.o: asm/rx86unix.cpp | ||
66 | $(CPP) -DBSDI asm/rx86unix.cpp | as -o asm/rx86bsdi.o | ||
67 | |||
68 | asm/rx86unix.cpp: | ||
69 | (cd asm; perl rc4-586.pl cpp >rx86unix.cpp) | ||
70 | |||
71 | files: | ||
72 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
73 | |||
74 | links: | ||
75 | /bin/rm -f Makefile | ||
76 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
77 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
78 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
79 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
80 | |||
81 | install: | ||
82 | @for i in $(EXHEADER) ; \ | ||
83 | do \ | ||
84 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
85 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
86 | done; | ||
87 | |||
88 | tags: | ||
89 | ctags $(SRC) | ||
90 | |||
91 | tests: | ||
92 | |||
93 | lint: | ||
94 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
95 | |||
96 | depend: | ||
97 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
98 | |||
99 | dclean: | ||
100 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
101 | mv -f Makefile.new $(MAKEFILE) | ||
102 | |||
103 | clean: | ||
104 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o | ||
105 | |||
106 | errors: | ||
107 | |||
108 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/rc5/Makefile.ssl b/src/lib/libcrypto/rc5/Makefile.ssl new file mode 100644 index 0000000000..5e98ee2348 --- /dev/null +++ b/src/lib/libcrypto/rc5/Makefile.ssl | |||
@@ -0,0 +1,107 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/rc5/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rc5 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | CPP= $(CC) -E | ||
9 | INCLUDES= | ||
10 | CFLAG=-g | ||
11 | INSTALLTOP=/usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | AR= ar r | ||
16 | |||
17 | RC5_ENC= rc5_enc.o | ||
18 | # or use | ||
19 | #DES_ENC= r586-elf.o | ||
20 | |||
21 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
22 | |||
23 | GENERAL=Makefile | ||
24 | TEST=rc5test.c | ||
25 | APPS= | ||
26 | |||
27 | LIB=$(TOP)/libcrypto.a | ||
28 | LIBSRC=rc5_skey.c rc5_ecb.c rc5_enc.c rc5cfb64.c rc5ofb64.c | ||
29 | LIBOBJ=rc5_skey.o rc5_ecb.o $(RC5_ENC) rc5cfb64.o rc5ofb64.o | ||
30 | |||
31 | SRC= $(LIBSRC) | ||
32 | |||
33 | EXHEADER= rc5.h | ||
34 | HEADER= rc5_locl.h $(EXHEADER) | ||
35 | |||
36 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
37 | |||
38 | top: | ||
39 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
40 | |||
41 | all: lib | ||
42 | |||
43 | lib: $(LIBOBJ) | ||
44 | $(AR) $(LIB) $(LIBOBJ) | ||
45 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
46 | @touch lib | ||
47 | |||
48 | # elf | ||
49 | asm/r586-elf.o: asm/r586unix.cpp | ||
50 | $(CPP) -DELF asm/r586unix.cpp | as -o asm/r586-elf.o | ||
51 | |||
52 | # solaris | ||
53 | asm/r586-sol.o: asm/r586unix.cpp | ||
54 | $(CC) -E -DSOL asm/r586unix.cpp | sed 's/^#.*//' > asm/r586-sol.s | ||
55 | as -o asm/r586-sol.o asm/r586-sol.s | ||
56 | rm -f asm/r586-sol.s | ||
57 | |||
58 | # a.out | ||
59 | asm/r586-out.o: asm/r586unix.cpp | ||
60 | $(CPP) -DOUT asm/r586unix.cpp | as -o asm/r586-out.o | ||
61 | |||
62 | # bsdi | ||
63 | asm/r586bsdi.o: asm/r586unix.cpp | ||
64 | $(CPP) -DBSDI asm/r586unix.cpp | as -o asm/r586bsdi.o | ||
65 | |||
66 | asm/r586unix.cpp: | ||
67 | (cd asm; perl rc5-586.pl cpp >r586unix.cpp) | ||
68 | |||
69 | files: | ||
70 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
71 | |||
72 | links: | ||
73 | /bin/rm -f Makefile | ||
74 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
75 | $(TOP)/util/point.sh ../../doc/rc5.doc rc5.doc ; | ||
76 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
77 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
78 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
79 | |||
80 | install: | ||
81 | @for i in $(EXHEADER) ; \ | ||
82 | do \ | ||
83 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
84 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
85 | done; | ||
86 | |||
87 | tags: | ||
88 | ctags $(SRC) | ||
89 | |||
90 | tests: | ||
91 | |||
92 | lint: | ||
93 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
94 | |||
95 | depend: | ||
96 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
97 | |||
98 | dclean: | ||
99 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
100 | mv -f Makefile.new $(MAKEFILE) | ||
101 | |||
102 | clean: | ||
103 | /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
104 | |||
105 | errors: | ||
106 | |||
107 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/rc5/asm/rc5-586.pl b/src/lib/libcrypto/rc5/asm/rc5-586.pl new file mode 100644 index 0000000000..172bd9ee1b --- /dev/null +++ b/src/lib/libcrypto/rc5/asm/rc5-586.pl | |||
@@ -0,0 +1,109 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | push(@INC,"perlasm","../../perlasm"); | ||
4 | require "x86asm.pl"; | ||
5 | require "cbc.pl"; | ||
6 | |||
7 | &asm_init($ARGV[0],"rc5-586.pl"); | ||
8 | |||
9 | $RC5_MAX_ROUNDS=16; | ||
10 | $RC5_32_OFF=($RC5_MAX_ROUNDS+2)*4; | ||
11 | $A="edi"; | ||
12 | $B="esi"; | ||
13 | $S="ebp"; | ||
14 | $tmp1="eax"; | ||
15 | $r="ebx"; | ||
16 | $tmpc="ecx"; | ||
17 | $tmp4="edx"; | ||
18 | |||
19 | &RC5_32_encrypt("RC5_32_encrypt",1); | ||
20 | &RC5_32_encrypt("RC5_32_decrypt",0); | ||
21 | &cbc("RC5_32_cbc_encrypt","RC5_32_encrypt","RC5_32_decrypt",0,4,5,3,-1,-1); | ||
22 | &asm_finish(); | ||
23 | |||
24 | sub RC5_32_encrypt | ||
25 | { | ||
26 | local($name,$enc)=@_; | ||
27 | |||
28 | &function_begin_B($name,""); | ||
29 | |||
30 | &comment(""); | ||
31 | |||
32 | &push("ebp"); | ||
33 | &push("esi"); | ||
34 | &push("edi"); | ||
35 | &mov($tmp4,&wparam(0)); | ||
36 | &mov($S,&wparam(1)); | ||
37 | |||
38 | &comment("Load the 2 words"); | ||
39 | &mov($A,&DWP(0,$tmp4,"",0)); | ||
40 | &mov($B,&DWP(4,$tmp4,"",0)); | ||
41 | |||
42 | &push($r); | ||
43 | &mov($r, &DWP(0,$S,"",0)); | ||
44 | |||
45 | # encrypting part | ||
46 | |||
47 | if ($enc) | ||
48 | { | ||
49 | &add($A, &DWP(4+0,$S,"",0)); | ||
50 | &add($B, &DWP(4+4,$S,"",0)); | ||
51 | |||
52 | for ($i=0; $i<$RC5_MAX_ROUNDS; $i++) | ||
53 | { | ||
54 | &xor($A, $B); | ||
55 | &mov($tmp1, &DWP(12+$i*8,$S,"",0)); | ||
56 | &mov($tmpc, $B); | ||
57 | &rotl($A, &LB("ecx")); | ||
58 | &add($A, $tmp1); | ||
59 | |||
60 | &xor($B, $A); | ||
61 | &mov($tmp1, &DWP(16+$i*8,$S,"",0)); | ||
62 | &mov($tmpc, $A); | ||
63 | &rotl($B, &LB("ecx")); | ||
64 | &add($B, $tmp1); | ||
65 | if (($i == 7) || ($i == 11)) | ||
66 | { | ||
67 | &cmp($r, $i+1); | ||
68 | &je(&label("rc5_exit")); | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | else | ||
73 | { | ||
74 | &cmp($r, 12); | ||
75 | &je(&label("rc5_dec_12")); | ||
76 | &cmp($r, 8); | ||
77 | &je(&label("rc5_dec_8")); | ||
78 | for ($i=$RC5_MAX_ROUNDS; $i > 0; $i--) | ||
79 | { | ||
80 | &set_label("rc5_dec_$i") if ($i == 12) || ($i == 8); | ||
81 | &mov($tmp1, &DWP($i*8+8,$S,"",0)); | ||
82 | &sub($B, $tmp1); | ||
83 | &mov($tmpc, $A); | ||
84 | &rotr($B, &LB("ecx")); | ||
85 | &xor($B, $A); | ||
86 | |||
87 | &mov($tmp1, &DWP($i*8+4,$S,"",0)); | ||
88 | &sub($A, $tmp1); | ||
89 | &mov($tmpc, $B); | ||
90 | &rotr($A, &LB("ecx")); | ||
91 | &xor($A, $B); | ||
92 | } | ||
93 | &sub($B, &DWP(4+4,$S,"",0)); | ||
94 | &sub($A, &DWP(4+0,$S,"",0)); | ||
95 | } | ||
96 | |||
97 | &set_label("rc5_exit"); | ||
98 | &mov(&DWP(0,$tmp4,"",0),$A); | ||
99 | &mov(&DWP(4,$tmp4,"",0),$B); | ||
100 | |||
101 | &pop("ebx"); | ||
102 | &pop("edi"); | ||
103 | &pop("esi"); | ||
104 | &pop("ebp"); | ||
105 | &ret(); | ||
106 | &function_end_B($name); | ||
107 | } | ||
108 | |||
109 | |||
diff --git a/src/lib/libcrypto/ripemd/Makefile.ssl b/src/lib/libcrypto/ripemd/Makefile.ssl new file mode 100644 index 0000000000..67d47ceb2c --- /dev/null +++ b/src/lib/libcrypto/ripemd/Makefile.ssl | |||
@@ -0,0 +1,104 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/ripemd/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= ripemd | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | CPP= $(CC) -E | ||
9 | INCLUDES= | ||
10 | CFLAG=-g | ||
11 | INSTALLTOP=/usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | AR= ar r | ||
16 | |||
17 | RIP_ASM_OBJ= | ||
18 | |||
19 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
20 | |||
21 | GENERAL=Makefile | ||
22 | TEST=rmdtest.c | ||
23 | APPS=rmd160.c | ||
24 | |||
25 | LIB=$(TOP)/libcrypto.a | ||
26 | LIBSRC=rmd_dgst.c rmd_one.c | ||
27 | LIBOBJ=rmd_dgst.o rmd_one.o $(RMD160_ASM_OBJ) | ||
28 | |||
29 | SRC= $(LIBSRC) | ||
30 | |||
31 | EXHEADER= ripemd.h | ||
32 | HEADER= rmd_locl.h rmdconst.h $(EXHEADER) | ||
33 | |||
34 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
35 | |||
36 | top: | ||
37 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
38 | |||
39 | all: lib | ||
40 | |||
41 | lib: $(LIBOBJ) | ||
42 | $(AR) $(LIB) $(LIBOBJ) | ||
43 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
44 | @touch lib | ||
45 | |||
46 | # elf | ||
47 | asm/rm86-elf.o: asm/rm86unix.cpp | ||
48 | $(CPP) -DELF asm/rm86unix.cpp | as -o asm/rm86-elf.o | ||
49 | |||
50 | # solaris | ||
51 | asm/rm86-sol.o: asm/rm86unix.cpp | ||
52 | $(CC) -E -DSOL asm/rm86unix.cpp | sed 's/^#.*//' > asm/rm86-sol.s | ||
53 | as -o asm/rm86-sol.o asm/rm86-sol.s | ||
54 | rm -f asm/rm86-sol.s | ||
55 | |||
56 | # a.out | ||
57 | asm/rm86-out.o: asm/rm86unix.cpp | ||
58 | $(CPP) -DOUT asm/rm86unix.cpp | as -o asm/rm86-out.o | ||
59 | |||
60 | # bsdi | ||
61 | asm/rm86bsdi.o: asm/rm86unix.cpp | ||
62 | $(CPP) -DBSDI asm/rm86unix.cpp | as -o asm/rm86bsdi.o | ||
63 | |||
64 | asm/rm86unix.cpp: | ||
65 | (cd asm; perl rmd-586.pl cpp >rm86unix.cpp) | ||
66 | |||
67 | files: | ||
68 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
69 | |||
70 | links: | ||
71 | /bin/rm -f Makefile | ||
72 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
73 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
74 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
75 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
76 | |||
77 | install: | ||
78 | @for i in $(EXHEADER) ; \ | ||
79 | do \ | ||
80 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
81 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
82 | done; | ||
83 | |||
84 | tags: | ||
85 | ctags $(SRC) | ||
86 | |||
87 | tests: | ||
88 | |||
89 | lint: | ||
90 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
91 | |||
92 | depend: | ||
93 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
94 | |||
95 | dclean: | ||
96 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
97 | mv -f Makefile.new $(MAKEFILE) | ||
98 | |||
99 | clean: | ||
100 | /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
101 | |||
102 | errors: | ||
103 | |||
104 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/rsa/Makefile.ssl b/src/lib/libcrypto/rsa/Makefile.ssl new file mode 100644 index 0000000000..d52f2e609e --- /dev/null +++ b/src/lib/libcrypto/rsa/Makefile.ssl | |||
@@ -0,0 +1,86 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/rsa/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rsa | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=rsa | ||
19 | ERRC=rsa_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c $(ERRC).c \ | ||
26 | rsa_pk1.c rsa_ssl.c rsa_none.c | ||
27 | LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o $(ERRC).o \ | ||
28 | rsa_pk1.o rsa_ssl.o rsa_none.o | ||
29 | |||
30 | SRC= $(LIBSRC) | ||
31 | |||
32 | EXHEADER= rsa.h | ||
33 | HEADER= $(EXHEADER) | ||
34 | |||
35 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
36 | |||
37 | top: | ||
38 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
39 | |||
40 | all: lib | ||
41 | |||
42 | lib: $(LIBOBJ) | ||
43 | $(AR) $(LIB) $(LIBOBJ) | ||
44 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
45 | @touch lib | ||
46 | |||
47 | files: | ||
48 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
49 | |||
50 | links: | ||
51 | /bin/rm -f Makefile | ||
52 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
53 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
54 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
55 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
56 | |||
57 | install: | ||
58 | @for i in $(EXHEADER) ; \ | ||
59 | do \ | ||
60 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
61 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
62 | done; | ||
63 | |||
64 | tags: | ||
65 | ctags $(SRC) | ||
66 | |||
67 | tests: | ||
68 | |||
69 | lint: | ||
70 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
71 | |||
72 | depend: | ||
73 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
74 | |||
75 | dclean: | ||
76 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
77 | mv -f Makefile.new $(MAKEFILE) | ||
78 | |||
79 | clean: | ||
80 | /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
81 | |||
82 | errors: | ||
83 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
84 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
85 | |||
86 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/sha/Makefile.ssl b/src/lib/libcrypto/sha/Makefile.ssl new file mode 100644 index 0000000000..eeb545d140 --- /dev/null +++ b/src/lib/libcrypto/sha/Makefile.ssl | |||
@@ -0,0 +1,103 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/sha/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= sha | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | SHA1_ASM_OBJ= | ||
17 | |||
18 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
19 | |||
20 | GENERAL=Makefile | ||
21 | TEST=shatest.c sha1test.c | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC=sha_dgst.c sha1dgst.c sha_one.c sha1_one.c | ||
26 | LIBOBJ=sha_dgst.o sha1dgst.o sha_one.o sha1_one.o $(SHA1_ASM_OBJ) | ||
27 | |||
28 | SRC= $(LIBSRC) | ||
29 | |||
30 | EXHEADER= sha.h | ||
31 | HEADER= sha_locl.h $(EXHEADER) | ||
32 | |||
33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
34 | |||
35 | top: | ||
36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
37 | |||
38 | all: lib | ||
39 | |||
40 | lib: $(LIBOBJ) | ||
41 | $(AR) $(LIB) $(LIBOBJ) | ||
42 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
43 | @touch lib | ||
44 | |||
45 | # elf | ||
46 | asm/sx86-elf.o: asm/sx86unix.cpp | ||
47 | $(CPP) -DELF asm/sx86unix.cpp | as -o asm/sx86-elf.o | ||
48 | |||
49 | # solaris | ||
50 | asm/sx86-sol.o: asm/sx86unix.cpp | ||
51 | $(CC) -E -DSOL asm/sx86unix.cpp | sed 's/^#.*//' > asm/sx86-sol.s | ||
52 | as -o asm/sx86-sol.o asm/sx86-sol.s | ||
53 | rm -f asm/sx86-sol.s | ||
54 | |||
55 | # a.out | ||
56 | asm/sx86-out.o: asm/sx86unix.cpp | ||
57 | $(CPP) -DOUT asm/sx86unix.cpp | as -o asm/sx86-out.o | ||
58 | |||
59 | # bsdi | ||
60 | asm/sx86bsdi.o: asm/sx86unix.cpp | ||
61 | $(CPP) -DBSDI asm/sx86unix.cpp | as -o asm/sx86bsdi.o | ||
62 | |||
63 | asm/sx86unix.cpp: | ||
64 | (cd asm; perl sha1-586.pl cpp >sx86unix.cpp) | ||
65 | |||
66 | files: | ||
67 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
68 | |||
69 | links: | ||
70 | /bin/rm -f Makefile | ||
71 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
72 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
73 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
74 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
75 | |||
76 | install: | ||
77 | @for i in $(EXHEADER) ; \ | ||
78 | do \ | ||
79 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
80 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
81 | done; | ||
82 | |||
83 | tags: | ||
84 | ctags $(SRC) | ||
85 | |||
86 | tests: | ||
87 | |||
88 | lint: | ||
89 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
90 | |||
91 | depend: | ||
92 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
93 | |||
94 | dclean: | ||
95 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
96 | mv -f Makefile.new $(MAKEFILE) | ||
97 | |||
98 | clean: | ||
99 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o | ||
100 | |||
101 | errors: | ||
102 | |||
103 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/stack/Makefile.ssl b/src/lib/libcrypto/stack/Makefile.ssl new file mode 100644 index 0000000000..0d232c08cf --- /dev/null +++ b/src/lib/libcrypto/stack/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/stack/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= stack | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST= | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=stack.c | ||
24 | LIBOBJ=stack.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= stack.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/txt_db/Makefile.ssl b/src/lib/libcrypto/txt_db/Makefile.ssl new file mode 100644 index 0000000000..76e511534f --- /dev/null +++ b/src/lib/libcrypto/txt_db/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/txt_db/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= txt_db | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST= | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=txt_db.c | ||
24 | LIBOBJ=txt_db.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= txt_db.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/x509/Makefile.ssl b/src/lib/libcrypto/x509/Makefile.ssl new file mode 100644 index 0000000000..1c1ca2ffa0 --- /dev/null +++ b/src/lib/libcrypto/x509/Makefile.ssl | |||
@@ -0,0 +1,96 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/x509/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= x509 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=x509 | ||
19 | ERRC=x509_err | ||
20 | GENERAL=Makefile README | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c \ | ||
26 | x509_obj.c x509_req.c x509_vfy.c \ | ||
27 | x509_set.c x509rset.c $(ERRC).c \ | ||
28 | x509name.c x509_v3.c x509_ext.c x509pack.c \ | ||
29 | x509type.c x509_lu.c x_all.c x509_txt.c \ | ||
30 | by_file.c by_dir.c \ | ||
31 | v3_net.c v3_x509.c | ||
32 | LIBOBJ= x509_def.o x509_d2.o x509_r2x.o x509_cmp.o \ | ||
33 | x509_obj.o x509_req.o x509_vfy.o \ | ||
34 | x509_set.o x509rset.o $(ERRC).o \ | ||
35 | x509name.o x509_v3.o x509_ext.o x509pack.o \ | ||
36 | x509type.o x509_lu.o x_all.o x509_txt.o \ | ||
37 | by_file.o by_dir.o \ | ||
38 | v3_net.o v3_x509.o | ||
39 | |||
40 | SRC= $(LIBSRC) | ||
41 | |||
42 | EXHEADER= x509.h x509_vfy.h | ||
43 | HEADER= $(EXHEADER) | ||
44 | |||
45 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
46 | |||
47 | top: | ||
48 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
49 | |||
50 | all: lib | ||
51 | |||
52 | lib: $(LIBOBJ) | ||
53 | $(AR) $(LIB) $(LIBOBJ) | ||
54 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
55 | @touch lib | ||
56 | |||
57 | files: | ||
58 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
59 | |||
60 | links: | ||
61 | /bin/rm -f Makefile | ||
62 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
63 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
64 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
65 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
66 | |||
67 | install: | ||
68 | @for i in $(EXHEADER) ; \ | ||
69 | do \ | ||
70 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
71 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
72 | done; | ||
73 | |||
74 | tags: | ||
75 | ctags $(SRC) | ||
76 | |||
77 | tests: | ||
78 | |||
79 | lint: | ||
80 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
81 | |||
82 | depend: | ||
83 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
84 | |||
85 | dclean: | ||
86 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
87 | mv -f Makefile.new $(MAKEFILE) | ||
88 | |||
89 | clean: | ||
90 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
91 | |||
92 | errors: | ||
93 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
94 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
95 | |||
96 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/Makefile.ssl b/src/lib/libssl/src/Makefile.ssl new file mode 100644 index 0000000000..da7f885985 --- /dev/null +++ b/src/lib/libssl/src/Makefile.ssl | |||
@@ -0,0 +1,331 @@ | |||
1 | # | ||
2 | # Makefile for all the SSL related library routines and utilities | ||
3 | VERSION = 0.9.0a | ||
4 | # | ||
5 | # make install will install: | ||
6 | # libraries into $INSTALLTOP/lib | ||
7 | # headers into $INSTALLTOP/include | ||
8 | # utilities into $INSTALLTOP/bin | ||
9 | # | ||
10 | # By default INSTALLTOP is set to /usr/local/ssl | ||
11 | # If you want things install elsewere, consider running | ||
12 | # perl util/ssldir.pl /new/path | ||
13 | # | ||
14 | # Interesting Mailing Lists: | ||
15 | # ssl-bugs@mincom.oz.au | ||
16 | # ssl-users@mincom.oz.au | ||
17 | # | ||
18 | # To join the Mailing Lists: | ||
19 | # ssl-bugs-request@mincom.oz.au | ||
20 | # ssl-users-request@mincom.oz.au | ||
21 | # | ||
22 | # If you must get hold of people directly (we much prefer the above | ||
23 | # lists to be used if the question is of general interest!): | ||
24 | # Eric Young <eay@cryptsoft.com> | ||
25 | # Tim Hudson <tjh@cryptsoft.com> | ||
26 | # or both <ssleay@cryptsoft.com> | ||
27 | # | ||
28 | # The primary distribution of SSLeay is from | ||
29 | # ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL | ||
30 | # | ||
31 | # NOCONST - Define for C compilers that don't like the const key word. | ||
32 | # NOPROTO - Define in if your compiler does not support prototypes. | ||
33 | # RSAref - Define if we are to link with RSAref. | ||
34 | # NO_IDEA - Define to build without the IDEA algorithm | ||
35 | # NO_RC4 - Define to build without the RC4 algorithm | ||
36 | # NO_RC2 - Define to build without the RC2 algorithm | ||
37 | # THREADS - Define when building with threads, you will probably also need any | ||
38 | # system defines as well, i.e. _REENTERANT for Solaris 2.[34] | ||
39 | # TERMIO - Define the termio terminal subsystem, needed if sgtty is missing. | ||
40 | # TERMIOS - Define the termios terminal subsystem, Silicon Graphics. | ||
41 | # LONGCRYPT - Define to use HPUX 10.x's long password modification to crypt(3). | ||
42 | # DEVRANDOM - Give this the value of the 'random device' if your OS supports | ||
43 | # one. 32 bytes will be read from this when the random | ||
44 | # number generator is initalised. | ||
45 | # SSL_ALLOW_ADH - define if you want the server to be able to use the | ||
46 | # SSLv3 anon-DH ciphers. | ||
47 | # SSL_ALLOW_ENULL - define if you want the server to be able to use the | ||
48 | # NULL encryption ciphers. | ||
49 | # | ||
50 | # LOCK_DEBUG - turns on lots of lock debug output :-) | ||
51 | # REF_CHECK - turn on some xyz_free() assertions. | ||
52 | # REF_PRINT - prints some stuff on structure free. | ||
53 | # CRYPTO_MDEBUG - turns on my 'memory leak' detecting stuff | ||
54 | # MFUNC - Make all Malloc/Free/Realloc calls call | ||
55 | # CRYPTO_malloc/CRYPTO_free/CRYPTO_realloc which can be setup to | ||
56 | # call application defined callbacks via CRYPTO_set_mem_functions() | ||
57 | # MD5_ASM needs to be defined to use the x86 assembler for MD5 | ||
58 | # SHA1_ASM needs to be defined to use the x86 assembler for SHA1 | ||
59 | # RMD160_ASM needs to be defined to use the x86 assembler for RIPEMD160 | ||
60 | |||
61 | |||
62 | CC= gcc | ||
63 | #CFLAG= -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DMD5_ASM -DSHA1_ASM -DRMD160_ASM | ||
64 | CFLAG= -DNO_IDEA -DTERMIOS -DBN_ASM -DL_ENDIAN -D_ANSI_SOURCE -fomit-frame-pointer -O3 -m486 -Wall -DSHA1_ASM -DMD5_ASM -DRMD160_ASM | ||
65 | PEX_LIBS= -L. -L.. -L../.. -L../../.. | ||
66 | EX_LIBS= | ||
67 | AR=ar r | ||
68 | |||
69 | # Set BN_MULW to bn_mulw.o if you want to use the C version | ||
70 | BN_MULW= asm/bn86-out.o | ||
71 | #BN_MULW= bn_mulw.o | ||
72 | #BN_MULW= asm/bn86-elf.o # elf, linux-elf | ||
73 | #BN_MULW= asm/bn86-sol.o # solaris | ||
74 | #BN_MULW= asm/bn86-out.o # a.out, FreeBSD | ||
75 | #BN_MULW= asm/bn86bsdi.o # bsdi | ||
76 | #BN_MULW= asm/alpha.o # DEC Alpha | ||
77 | #BN_MULW= asm/pa-risc2.o # HP-UX PA-RISC | ||
78 | #BN_MULW= asm/r3000.o # SGI MIPS cpu | ||
79 | #BN_MULW= asm/sparc.o # Sun solaris/SunOS | ||
80 | #BN_MULW= asm/bn-win32.o # Windows 95/NT | ||
81 | #BN_MULW= asm/x86w16.o # 16 bit code for Windows 3.1/DOS | ||
82 | #BN_MULW= asm/x86w32.o # 32 bit code for Windows 3.1 | ||
83 | |||
84 | # Set DES_ENC to des_enc.o if you want to use the C version | ||
85 | #There are 4 x86 assember options. | ||
86 | DES_ENC= asm/dx86-out.o asm/yx86-out.o | ||
87 | #DES_ENC= des_enc.o fcrypt_b.o # C | ||
88 | #DES_ENC= asm/dx86-elf.o asm/yx86-elf.o # elf | ||
89 | #DES_ENC= asm/dx86-sol.o asm/yx86-sol.o # solaris | ||
90 | #DES_ENC= asm/dx86-out.o asm/yx86-out.o # a.out, FreeBSD | ||
91 | #DES_ENC= asm/dx86bsdi.o asm/yx86bsdi.o # bsdi | ||
92 | |||
93 | # Set BF_ENC to bf_enc.o if you want to use the C version | ||
94 | #There are 4 x86 assember options. | ||
95 | BF_ENC= asm/bx86-out.o | ||
96 | #BF_ENC= bf_enc.o | ||
97 | #BF_ENC= asm/bx86-elf.o # elf | ||
98 | #BF_ENC= asm/bx86-sol.o # solaris | ||
99 | #BF_ENC= asm/bx86-out.o # a.out, FreeBSD | ||
100 | #BF_ENC= asm/bx86bsdi.o # bsdi | ||
101 | |||
102 | # Set CAST_ENC to c_enc.o if you want to use the C version | ||
103 | #There are 4 x86 assember options. | ||
104 | CAST_ENC= asm/cx86-out.o | ||
105 | #CAST_ENC= c_enc.o | ||
106 | #CAST_ENC= asm/cx86-elf.o # elf | ||
107 | #CAST_ENC= asm/cx86-sol.o # solaris | ||
108 | #CAST_ENC= asm/cx86-out.o # a.out, FreeBSD | ||
109 | #CAST_ENC= asm/cx86bsdi.o # bsdi | ||
110 | |||
111 | # Set RC4_ENC to rc4_enc.o if you want to use the C version | ||
112 | #There are 4 x86 assember options. | ||
113 | RC4_ENC= asm/rx86-out.o | ||
114 | #RC4_ENC= rc4_enc.o | ||
115 | #RC4_ENC= asm/rx86-elf.o # elf | ||
116 | #RC4_ENC= asm/rx86-sol.o # solaris | ||
117 | #RC4_ENC= asm/rx86-out.o # a.out, FreeBSD | ||
118 | #RC4_ENC= asm/rx86bsdi.o # bsdi | ||
119 | |||
120 | # Set RC5_ENC to rc5_enc.o if you want to use the C version | ||
121 | #There are 4 x86 assember options. | ||
122 | RC5_ENC= asm/r586-out.o | ||
123 | #RC5_ENC= rc5_enc.o | ||
124 | #RC5_ENC= asm/r586-elf.o # elf | ||
125 | #RC5_ENC= asm/r586-sol.o # solaris | ||
126 | #RC5_ENC= asm/r586-out.o # a.out, FreeBSD | ||
127 | #RC5_ENC= asm/r586bsdi.o # bsdi | ||
128 | |||
129 | # Also need MD5_ASM defined | ||
130 | MD5_ASM_OBJ= asm/mx86-out.o | ||
131 | #MD5_ASM_OBJ= asm/mx86-elf.o # elf | ||
132 | #MD5_ASM_OBJ= asm/mx86-sol.o # solaris | ||
133 | #MD5_ASM_OBJ= asm/mx86-out.o # a.out, FreeBSD | ||
134 | #MD5_ASM_OBJ= asm/mx86bsdi.o # bsdi | ||
135 | |||
136 | # Also need SHA1_ASM defined | ||
137 | SHA1_ASM_OBJ= asm/sx86-out.o | ||
138 | #SHA1_ASM_OBJ= asm/sx86-elf.o # elf | ||
139 | #SHA1_ASM_OBJ= asm/sx86-sol.o # solaris | ||
140 | #SHA1_ASM_OBJ= asm/sx86-out.o # a.out, FreeBSD | ||
141 | #SHA1_ASM_OBJ= asm/sx86bsdi.o # bsdi | ||
142 | |||
143 | # Also need RMD160_ASM defined | ||
144 | RMD160_ASM_OBJ= asm/rm86-out.o | ||
145 | #RMD160_ASM_OBJ= asm/rm86-elf.o # elf | ||
146 | #RMD160_ASM_OBJ= asm/rm86-sol.o # solaris | ||
147 | #RMD160_ASM_OBJ= asm/rm86-out.o # a.out, FreeBSD | ||
148 | #RMD160_ASM_OBJ= asm/rm86bsdi.o # bsdi | ||
149 | |||
150 | DIRS= crypto ssl rsaref apps test tools | ||
151 | # dirs in crypto to build | ||
152 | SDIRS= \ | ||
153 | md2 md5 sha mdc2 hmac ripemd \ | ||
154 | des rc2 rc4 rc5 idea bf cast \ | ||
155 | bn rsa dsa dh \ | ||
156 | buffer bio stack lhash rand err objects \ | ||
157 | evp pem asn1 x509 conf txt_db pkcs7 | ||
158 | |||
159 | # If you change the INSTALLTOP, make sure to also change the values | ||
160 | # in crypto/location.h | ||
161 | INSTALLTOP=/usr/ssl | ||
162 | |||
163 | MAKEFILE= Makefile.ssl | ||
164 | MAKE= make -f Makefile.ssl | ||
165 | |||
166 | MAN1=1 | ||
167 | MAN3=3 | ||
168 | SHELL=/bin/sh | ||
169 | |||
170 | TOP= . | ||
171 | ONEDIRS=out tmp | ||
172 | EDIRS= times doc bugs util include certs ms shlib mt demos perl dep | ||
173 | MISC= COPYRIGHT Configure HISTORY.066 INSTALL Makefile.ssl Makefile \ | ||
174 | README TODO HISTORY README.066 README.080 README.090 \ | ||
175 | VERSION PROBLEMS MINFO makefile.one e_os.h \ | ||
176 | MICROSOFT makevms.com config PATENTS | ||
177 | WDIRS= windows | ||
178 | LIBS= libcrypto.a libssl.a | ||
179 | |||
180 | GENERAL= Makefile | ||
181 | BASENAME= SSLeay | ||
182 | NAME= $(BASENAME)-$(VERSION) | ||
183 | TARFILE= $(NAME).tar | ||
184 | WTARFILE= $(NAME)-win.tar | ||
185 | EXHEADER= e_os.h | ||
186 | HEADER= e_os.h | ||
187 | |||
188 | all: | ||
189 | @for i in $(DIRS) ;\ | ||
190 | do \ | ||
191 | (cd $$i; echo "making $$i..."; \ | ||
192 | $(MAKE) CC='${CC}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_MULW='${BN_MULW}' DES_ENC='${DES_ENC}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' SDIRS='${SDIRS}' AR='${AR}' all ); \ | ||
193 | done; | ||
194 | |||
195 | sub_all: | ||
196 | @for i in $(DIRS) ;\ | ||
197 | do \ | ||
198 | (cd $$i; echo "making $$i..."; \ | ||
199 | $(MAKE) CC='${CC}' CFLAG='${CFLAG}' SDIRS='$(SDIRS)' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_MULW='${BN_MULW}' DES_ENC='${DES_ENC}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' AR='${AR}' all ); \ | ||
200 | done; | ||
201 | |||
202 | clean: | ||
203 | /bin/rm -f shlib/*.o *.o core a.out fluff *.map | ||
204 | @for i in $(DIRS) ;\ | ||
205 | do \ | ||
206 | (cd $$i; echo "cleaning $$i..."; \ | ||
207 | $(MAKE) SDIRS='${SDIRS}' clean ); \ | ||
208 | /bin/rm -f $(LIBS); \ | ||
209 | done; | ||
210 | /bin/rm -f *.a *.o speed.* *.map *.so .pure core | ||
211 | /bin/rm -f $(TARFILE) | ||
212 | @for i in $(ONEDIRS) ;\ | ||
213 | do \ | ||
214 | /bin/rm -fr $$i/*; \ | ||
215 | done | ||
216 | |||
217 | makefile.one: files | ||
218 | perl util/mk1mf.pl >makefile.one; \ | ||
219 | sh util/do_ms.sh | ||
220 | |||
221 | files: MINFO | ||
222 | perl $(TOP)/util/files.pl Makefile.ssl > $(TOP)/MINFO | ||
223 | @for i in $(DIRS) ;\ | ||
224 | do \ | ||
225 | (cd $$i; echo "making 'files' in $$i..."; \ | ||
226 | $(MAKE) SDIRS='${SDIRS}' files ); \ | ||
227 | done; | ||
228 | |||
229 | links: | ||
230 | /bin/rm -f Makefile; | ||
231 | ./util/point.sh Makefile.ssl Makefile; | ||
232 | $(TOP)/util/mklink.sh include $(EXHEADER) ; | ||
233 | @for i in $(DIRS) ;\ | ||
234 | do \ | ||
235 | (cd $$i; echo "making links in $$i..."; \ | ||
236 | $(MAKE) SDIRS='${SDIRS}' links ); \ | ||
237 | done; | ||
238 | # @(cd apps; sh ./mklinks) | ||
239 | @( SSLEAY="`pwd`/apps/ssleay"; export SSLEAY; sh tools/c_rehash certs ) | ||
240 | |||
241 | dclean: | ||
242 | /bin/rm -f *.bak | ||
243 | @for i in $(DIRS) ;\ | ||
244 | do \ | ||
245 | (cd $$i; echo "undoing makedepend in $$i..."; \ | ||
246 | $(MAKE) SDIRS='${SDIRS}' dclean ); \ | ||
247 | done; | ||
248 | |||
249 | rehash: | ||
250 | @(PATH="`pwd`/apps:${PATH}"; sh tools/c_rehash certs) | ||
251 | |||
252 | test: tests | ||
253 | |||
254 | tests: | ||
255 | (cd test; echo "testing $$i..."; \ | ||
256 | $(MAKE) CC='${CC}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_MULW='${BN_MULW}' DES_ENC='${DES_ENC}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' SDIRS='${SDIRS}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' AR='${AR}' tests ); | ||
257 | @apps/ssleay version -a | ||
258 | |||
259 | depend: | ||
260 | @for i in $(DIRS) ;\ | ||
261 | do \ | ||
262 | (cd $$i; echo "making dependancies $$i..."; \ | ||
263 | $(MAKE) SDIRS='${SDIRS}' depend ); \ | ||
264 | done; | ||
265 | |||
266 | lint: | ||
267 | @for i in $(DIRS) ;\ | ||
268 | do \ | ||
269 | (cd $$i; echo "making lint $$i..."; \ | ||
270 | $(MAKE) SDIRS='${SDIRS}' lint ); \ | ||
271 | done; | ||
272 | |||
273 | tags: | ||
274 | @for i in $(DIRS) ;\ | ||
275 | do \ | ||
276 | (cd $$i; echo "making tags $$i..."; \ | ||
277 | $(MAKE) SDIRS='${SDIRS}' tags ); \ | ||
278 | done; | ||
279 | |||
280 | errors: | ||
281 | @for i in $(DIRS) ;\ | ||
282 | do \ | ||
283 | (cd $$i; echo "making errors in $$i..."; \ | ||
284 | $(MAKE) SDIRS='${SDIRS}' errors ); \ | ||
285 | done; | ||
286 | |||
287 | tar: | ||
288 | @(cd ..;\ | ||
289 | mv $(BASENAME) $(NAME); \ | ||
290 | export STUFF; \ | ||
291 | for i in $(MISC) $(DIRS) $(EDIRS) $(ONEDIRS) ;\ | ||
292 | do \ | ||
293 | STUFF="$$STUFF $(NAME)/$$i"; \ | ||
294 | done; \ | ||
295 | tar cf $(NAME)/$(TARFILE) $$STUFF; \ | ||
296 | mv $(NAME) $(BASENAME) ) | ||
297 | gzip -f $(TARFILE) | ||
298 | |||
299 | dist: | ||
300 | perl Configure dist | ||
301 | perl util/up_ver.pl ${VERSION} | ||
302 | @$(MAKE) dist_pem_h | ||
303 | @$(MAKE) SDIRS='${SDIRS}' clean | ||
304 | @$(MAKE) SDIRS='${SDIRS}' dclean | ||
305 | @(cd apps; sh ./rmlinks) | ||
306 | @$(MAKE) makefile.one | ||
307 | @$(MAKE) tar | ||
308 | |||
309 | dist_pem_h: | ||
310 | (cd crypto/pem; $(MAKE) SDIRS='${SDIRS}' CFLAG='${CFLAG}' pem.h; $(MAKE) clean) | ||
311 | |||
312 | install: all | ||
313 | @-mkdir -p $(INSTALLTOP)/bin 2>/dev/null | ||
314 | @-mkdir -p $(INSTALLTOP)/lib 2>/dev/null | ||
315 | @-mkdir -p $(INSTALLTOP)/include 2>/dev/null | ||
316 | @-mkdir -p $(INSTALLTOP)/certs 2>/dev/null | ||
317 | @-mkdir -p $(INSTALLTOP)/private 2>/dev/null | ||
318 | @for i in $(DIRS) ;\ | ||
319 | do \ | ||
320 | (cd $$i; echo "installing $$i..."; \ | ||
321 | $(MAKE) CC='${CC}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' EX_LIBS='${EX_LIBS}' SDIRS='${SDIRS}' install ); \ | ||
322 | done | ||
323 | @for i in $(LIBS) ;\ | ||
324 | do \ | ||
325 | ( echo installing $$i; \ | ||
326 | cp $$i $(INSTALLTOP)/lib; \ | ||
327 | sh util/ranlib.sh $(INSTALLTOP)/lib/$$i; \ | ||
328 | chmod 644 $(INSTALLTOP)/lib/$$i ); \ | ||
329 | done | ||
330 | |||
331 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/apps/Makefile.ssl b/src/lib/libssl/src/apps/Makefile.ssl new file mode 100644 index 0000000000..1cace40ab7 --- /dev/null +++ b/src/lib/libssl/src/apps/Makefile.ssl | |||
@@ -0,0 +1,144 @@ | |||
1 | # | ||
2 | # SSLeay/apps/Makefile.ssl | ||
3 | # | ||
4 | |||
5 | DIR= apps | ||
6 | TOP= .. | ||
7 | CC= cc | ||
8 | INCLUDES= -I../include | ||
9 | CFLAG= -g -static | ||
10 | INSTALLTOP= /usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | RM= /bin/rm -f | ||
15 | |||
16 | PEX_LIBS= | ||
17 | EX_LIBS= | ||
18 | |||
19 | CFLAGS= -DMONOLITH $(INCLUDES) $(CFLAG) | ||
20 | |||
21 | GENERAL=Makefile | ||
22 | |||
23 | DLIBCRYPTO=../libcrypto.a | ||
24 | DLIBSSL=../libssl.a | ||
25 | LIBCRYPTO=-L.. -lcrypto | ||
26 | LIBSSL=-L.. -lssl | ||
27 | |||
28 | SSLEAY= ssleay | ||
29 | |||
30 | SCRIPTS=CA.sh der_chop | ||
31 | |||
32 | EXE= $(SSLEAY) | ||
33 | |||
34 | E_EXE= verify asn1pars req dgst dh enc gendh errstr ca crl \ | ||
35 | rsa dsa dsaparam \ | ||
36 | x509 genrsa s_server s_client speed \ | ||
37 | s_time version pkcs7 crl2pkcs7 sess_id ciphers | ||
38 | |||
39 | PROGS= $(SSLEAY).c | ||
40 | |||
41 | A_OBJ=apps.o | ||
42 | A_SRC=apps.c | ||
43 | S_OBJ= s_cb.o s_socket.o | ||
44 | S_SRC= s_cb.c s_socket.c | ||
45 | |||
46 | E_OBJ= verify.o asn1pars.o req.o dgst.o dh.o enc.o gendh.o errstr.o ca.o \ | ||
47 | pkcs7.o crl2p7.o crl.o \ | ||
48 | rsa.o dsa.o dsaparam.o \ | ||
49 | x509.o genrsa.o s_server.o s_client.o speed.o \ | ||
50 | s_time.o $(A_OBJ) $(S_OBJ) version.o sess_id.o \ | ||
51 | ciphers.o | ||
52 | |||
53 | # pem_mail.o | ||
54 | |||
55 | E_SRC= verify.c asn1pars.c req.c dgst.c dh.c enc.c gendh.c errstr.c ca.c \ | ||
56 | pkcs7.c crl2p7.c crl.c \ | ||
57 | rsa.c dsa.c dsaparam.c \ | ||
58 | x509.c genrsa.c s_server.c s_client.c speed.c \ | ||
59 | s_time.c $(A_SRC) $(S_SRC) version.c sess_id.c \ | ||
60 | ciphers.c | ||
61 | |||
62 | # pem_mail.c | ||
63 | |||
64 | SRC=$(E_SRC) | ||
65 | |||
66 | EXHEADER= | ||
67 | HEADER= apps.h progs.h s_apps.h \ | ||
68 | testdsa.h testrsa.h \ | ||
69 | $(EXHEADER) | ||
70 | |||
71 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
72 | |||
73 | top: | ||
74 | @(cd ..; $(MAKE) DIRS=$(DIR) all) | ||
75 | |||
76 | all: exe | ||
77 | |||
78 | exe: $(EXE) | ||
79 | |||
80 | req: sreq.o $(A_OBJ) $(DLIBCRYPTO) | ||
81 | $(CC) -o req $(CFLAG) sreq.o $(A_OBJ) $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
82 | |||
83 | sreq.o: req.c | ||
84 | $(CC) -c $(INCLUDES) $(CFLAG) -o sreq.o req.c | ||
85 | |||
86 | files: | ||
87 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
88 | |||
89 | install: mklinks | ||
90 | @for i in $(EXE) $(SCRIPTS) mklinks; \ | ||
91 | do \ | ||
92 | (echo installing $$i; \ | ||
93 | cp $$i $(INSTALLTOP)/bin/$$i; \ | ||
94 | chmod 755 $(INSTALLTOP)/bin/$$i ); \ | ||
95 | done; \ | ||
96 | cp ssleay.cnf $(INSTALLTOP)/lib | ||
97 | chmod 644 $(INSTALLTOP)/lib/ssleay.cnf | ||
98 | cd $(INSTALLTOP)/bin; \ | ||
99 | /bin/sh ./mklinks; \ | ||
100 | /bin/rm -f ./mklinks | ||
101 | |||
102 | tags: | ||
103 | ctags $(SRC) | ||
104 | |||
105 | tests: | ||
106 | |||
107 | links: | ||
108 | /bin/rm -f Makefile | ||
109 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
110 | |||
111 | lint: | ||
112 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
113 | |||
114 | depend: | ||
115 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(SRC) | ||
116 | |||
117 | dclean: | ||
118 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
119 | mv -f Makefile.new $(MAKEFILE) | ||
120 | |||
121 | errors: | ||
122 | |||
123 | clean: | ||
124 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff $(EXE) | ||
125 | /bin/rm -f req | ||
126 | |||
127 | $(DLIBSSL): | ||
128 | (cd ../ssl; $(MAKE)) | ||
129 | |||
130 | $(DLIBCRYPTO): | ||
131 | (cd ../crypto; $(MAKE)) | ||
132 | |||
133 | $(SSLEAY): progs.h $(E_OBJ) $(SSLEAY).o $(DLIBCRYPTO) $(DLIBSSL) | ||
134 | $(RM) $(SSLEAY) | ||
135 | $(CC) -o $(SSLEAY) $(CFLAGS) $(SSLEAY).o $(E_OBJ) $(PEX_LIBS) $(LIBSSL) $(LIBCRYPTO) $(EX_LIBS) | ||
136 | |||
137 | progs.h: | ||
138 | perl ./g_ssleay.pl $(E_EXE) >progs.h | ||
139 | $(RM) $(SSLEAY).o | ||
140 | |||
141 | mklinks: | ||
142 | perl ./g_ssleay.pl $(E_EXE) >progs.h | ||
143 | |||
144 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/apps/der_chop b/src/lib/libssl/src/apps/der_chop new file mode 100644 index 0000000000..4639330c10 --- /dev/null +++ b/src/lib/libssl/src/apps/der_chop | |||
@@ -0,0 +1,305 @@ | |||
1 | #!/usr/local/bin/perl | ||
2 | # | ||
3 | # der_chop ... this is one total hack that Eric is really not proud of | ||
4 | # so don't look at it and don't ask for support | ||
5 | # | ||
6 | # The "documentation" for this (i.e. all the comments) are my fault --tjh | ||
7 | # | ||
8 | # This program takes the "raw" output of derparse/asn1parse and | ||
9 | # converts it into tokens and then runs regular expression matches | ||
10 | # to try to figure out what to grab to get the things that are needed | ||
11 | # and it is possible that this will do the wrong thing as it is a *hack* | ||
12 | # | ||
13 | # SSLeay 0.5.2+ should have direct read support for x509 (via -inform NET) | ||
14 | # [I know ... promises promises :-)] | ||
15 | # | ||
16 | # To convert a Netscape Certificate: | ||
17 | # der_chop < ServerCert.der > cert.pem | ||
18 | # To convert a Netscape Key (and encrypt it again to protect it) | ||
19 | # rsa -inform NET -in ServerKey.der -des > key.pem | ||
20 | # | ||
21 | # 23-Apr-96 eay Added the extra ASN.1 string types, I still think this | ||
22 | # is an evil hack. If nothing else the parsing should | ||
23 | # be relative, not absolute. | ||
24 | # 19-Apr-96 tjh hacked (with eay) into 0.5.x format | ||
25 | # | ||
26 | # Tim Hudson | ||
27 | # tjh@cryptsoft.com | ||
28 | # | ||
29 | |||
30 | |||
31 | require 'getopts.pl'; | ||
32 | |||
33 | $debug=0; | ||
34 | |||
35 | # this was the 0.4.x way of doing things ... | ||
36 | $cmd="derparse"; | ||
37 | $x509_cmd="x509"; | ||
38 | $crl_cmd="crl"; | ||
39 | $rc4_cmd="rc4"; | ||
40 | $md2_cmd="md2"; | ||
41 | $md4_cmd="md4"; | ||
42 | $rsa_cmd="rsa -des -inform der "; | ||
43 | |||
44 | # this was the 0.5.x way of doing things ... | ||
45 | $cmd="ssleay asn1parse"; | ||
46 | $x509_cmd="ssleay x509"; | ||
47 | $crl_cmd="ssleay crl"; | ||
48 | $rc4_cmd="ssleay rc4"; | ||
49 | $md2_cmd="ssleay md2"; | ||
50 | $md4_cmd="ssleay md4"; | ||
51 | $rsa_cmd="ssleay rsa -des -inform der "; | ||
52 | |||
53 | &Getopts('vd:') || die "usage:$0 [-v] [-d num] file"; | ||
54 | $depth=($opt_d =~ /^\d+$/)?$opt_d:0; | ||
55 | |||
56 | &init_der(); | ||
57 | |||
58 | if ($#ARGV != -1) | ||
59 | { | ||
60 | foreach $file (@ARGV) | ||
61 | { | ||
62 | print STDERR "doing $file\n"; | ||
63 | &dofile($file); | ||
64 | } | ||
65 | } | ||
66 | else | ||
67 | { | ||
68 | $file="/tmp/a$$.DER"; | ||
69 | open(OUT,">$file") || die "unable to open $file:$!\n"; | ||
70 | for (;;) | ||
71 | { | ||
72 | $i=sysread(STDIN,$b,1024*10); | ||
73 | last if ($i <= 0); | ||
74 | $i=syswrite(OUT,$b,$i); | ||
75 | } | ||
76 | &dofile($file); | ||
77 | unlink($file); | ||
78 | } | ||
79 | |||
80 | sub dofile | ||
81 | { | ||
82 | local($file)=@_; | ||
83 | local(@p); | ||
84 | |||
85 | $b=&load_file($file); | ||
86 | @p=&load_file_parse($file); | ||
87 | |||
88 | foreach $_ (@p) | ||
89 | { | ||
90 | ($off,$d,$hl,$len)=&parse_line($_); | ||
91 | $d-=$depth; | ||
92 | next if ($d != 0); | ||
93 | next if ($len == 0); | ||
94 | |||
95 | $o=substr($b,$off,$len+$hl); | ||
96 | ($str,@data)=&der_str($o); | ||
97 | print "$str\n" if ($opt_v); | ||
98 | if ($str =~ /^$crl/) | ||
99 | { | ||
100 | open(OUT,"|$crl_cmd -inform d -hash -issuer") || | ||
101 | die "unable to run $crl_cmd:$!\n"; | ||
102 | print OUT $o; | ||
103 | close(OUT); | ||
104 | } | ||
105 | elsif ($str =~ /^$x509/) | ||
106 | { | ||
107 | open(OUT,"|$x509_cmd -inform d -hash -subject -issuer") | ||
108 | || die "unable to run $x509_cmd:$!\n"; | ||
109 | print OUT $o; | ||
110 | close(OUT); | ||
111 | } | ||
112 | elsif ($str =~ /^$rsa/) | ||
113 | { | ||
114 | ($type)=($data[3] =~ /OBJECT_IDENTIFIER :(.*)\s*$/); | ||
115 | next unless ($type eq "rsaEncryption"); | ||
116 | ($off,$d,$hl,$len)=&parse_line($data[5]); | ||
117 | $os=substr($o,$off+$hl,$len); | ||
118 | open(OUT,"|$rsa_cmd") | ||
119 | || die "unable to run $rsa_cmd:$!\n"; | ||
120 | print OUT $os; | ||
121 | close(OUT); | ||
122 | } | ||
123 | elsif ($str =~ /^0G-1D-1G/) | ||
124 | { | ||
125 | ($off,$d,$hl,$len)=&parse_line($data[1]); | ||
126 | $os=substr($o,$off+$hl,$len); | ||
127 | print STDERR "<$os>\n" if $opt_v; | ||
128 | &do_certificate($o,@data) | ||
129 | if (($os eq "certificate") && | ||
130 | ($str =! /^0G-1D-1G-2G-3F-3E-2D/)); | ||
131 | &do_private_key($o,@data) | ||
132 | if (($os eq "private-key") && | ||
133 | ($str =! /^0G-1D-1G-2G-3F-3E-2D/)); | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | |||
138 | sub der_str | ||
139 | { | ||
140 | local($str)=@_; | ||
141 | local(*OUT,*IN,@a,$t,$d,$ret); | ||
142 | local($file)="/tmp/b$$.DER"; | ||
143 | local(@ret); | ||
144 | |||
145 | open(OUT,">$file"); | ||
146 | print OUT $str; | ||
147 | close(OUT); | ||
148 | open(IN,"$cmd -inform 'd' -in $file |") || | ||
149 | die "unable to run $cmd:$!\n"; | ||
150 | $ret=""; | ||
151 | while (<IN>) | ||
152 | { | ||
153 | chop; | ||
154 | push(@ret,$_); | ||
155 | |||
156 | print STDERR "$_\n" if ($debug); | ||
157 | |||
158 | @a=split(/\s*:\s*/); | ||
159 | ($d)=($a[1] =~ /d=\s*(\d+)/); | ||
160 | $a[2] =~ s/\s+$//; | ||
161 | $t=$DER_s2i{$a[2]}; | ||
162 | $ret.="$d$t-"; | ||
163 | } | ||
164 | close(IN); | ||
165 | unlink($file); | ||
166 | chop $ret; | ||
167 | $ret =~ s/(-3H(-4G-5F-5[IJKMQRS])+)+/-NAME/g; | ||
168 | $ret =~ s/(-3G-4B-4L)+/-RCERT/g; | ||
169 | return($ret,@ret); | ||
170 | } | ||
171 | |||
172 | sub init_der | ||
173 | { | ||
174 | $crl= "0G-1G-2G-3F-3E-2G-NAME-2L-2L-2G-RCERT-1G-2F-2E-1C"; | ||
175 | $x509="0G-1G-2B-2G-3F-3E-2G-NAME-2G-3L-3L-2G-NAME-2G-3G-4F-4E-3C-1G-2F-2E-1C"; | ||
176 | $rsa= "0G-1B-1G-2F-2E-1D"; | ||
177 | |||
178 | %DER_i2s=( | ||
179 | # SSLeay 0.4.x has this list | ||
180 | "A","EOC", | ||
181 | "B","INTEGER", | ||
182 | "C","BIT STRING", | ||
183 | "D","OCTET STRING", | ||
184 | "E","NULL", | ||
185 | "F","OBJECT", | ||
186 | "G","SEQUENCE", | ||
187 | "H","SET", | ||
188 | "I","PRINTABLESTRING", | ||
189 | "J","T61STRING", | ||
190 | "K","IA5STRING", | ||
191 | "L","UTCTIME", | ||
192 | "M","NUMERICSTRING", | ||
193 | "N","VIDEOTEXSTRING", | ||
194 | "O","GENERALIZEDTIME", | ||
195 | "P","GRAPHICSTRING", | ||
196 | "Q","ISO64STRING", | ||
197 | "R","GENERALSTRING", | ||
198 | "S","UNIVERSALSTRING", | ||
199 | |||
200 | # SSLeay 0.5.x changed some things ... and I'm | ||
201 | # leaving in the old stuff but adding in these | ||
202 | # to handle the new as well --tjh | ||
203 | # - Well I've just taken them out and added the extra new | ||
204 | # ones :-) - eay | ||
205 | ); | ||
206 | |||
207 | foreach (keys %DER_i2s) | ||
208 | { $DER_s2i{$DER_i2s{$_}}=$_; } | ||
209 | } | ||
210 | |||
211 | sub parse_line | ||
212 | { | ||
213 | local($_)=@_; | ||
214 | |||
215 | return(/\s*(\d+):d=\s*(\d+)\s+hl=\s*(\d+)\s+l=\s*(\d+|inf)\s/); | ||
216 | } | ||
217 | |||
218 | # 0:d=0 hl=4 l=377 cons: univ: SEQUENCE | ||
219 | # 4:d=1 hl=2 l= 11 prim: univ: OCTET_STRING | ||
220 | # 17:d=1 hl=4 l=360 cons: univ: SEQUENCE | ||
221 | # 21:d=2 hl=2 l= 12 cons: univ: SEQUENCE | ||
222 | # 23:d=3 hl=2 l= 8 prim: univ: OBJECT_IDENTIFIER :rc4 | ||
223 | # 33:d=3 hl=2 l= 0 prim: univ: NULL | ||
224 | # 35:d=2 hl=4 l=342 prim: univ: OCTET_STRING | ||
225 | sub do_private_key | ||
226 | { | ||
227 | local($data,@struct)=@_; | ||
228 | local($file)="/tmp/b$$.DER"; | ||
229 | local($off,$d,$hl,$len,$_,$b,@p,$s); | ||
230 | |||
231 | ($type)=($struct[4] =~ /OBJECT_IDENTIFIER :(.*)\s*$/); | ||
232 | if ($type eq "rc4") | ||
233 | { | ||
234 | ($off,$d,$hl,$len)=&parse_line($struct[6]); | ||
235 | open(OUT,"|$rc4_cmd >$file") || | ||
236 | die "unable to run $rc4_cmd:$!\n"; | ||
237 | print OUT substr($data,$off+$hl,$len); | ||
238 | close(OUT); | ||
239 | |||
240 | $b=&load_file($file); | ||
241 | unlink($file); | ||
242 | |||
243 | ($s,@p)=&der_str($b); | ||
244 | die "unknown rsa key type\n$s\n" | ||
245 | if ($s ne '0G-1B-1G-2F-2E-1D'); | ||
246 | local($off,$d,$hl,$len)=&parse_line($p[5]); | ||
247 | $b=substr($b,$off+$hl,$len); | ||
248 | ($s,@p)=&der_str($b); | ||
249 | open(OUT,"|$rsa_cmd") || die "unable to run $rsa_cmd:$!\n"; | ||
250 | print OUT $b; | ||
251 | close(OUT); | ||
252 | } | ||
253 | else | ||
254 | { | ||
255 | print "'$type' is unknown\n"; | ||
256 | exit(1); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | sub do_certificate | ||
261 | { | ||
262 | local($data,@struct)=@_; | ||
263 | local($file)="/tmp/b$$.DER"; | ||
264 | local($off,$d,$hl,$len,$_,$b,@p,$s); | ||
265 | |||
266 | ($off,$d,$hl,$len)=&parse_line($struct[2]); | ||
267 | $b=substr($data,$off,$len+$hl); | ||
268 | |||
269 | open(OUT,"|$x509_cmd -inform d") || die "unable to run $x509_cmd:$!\n"; | ||
270 | print OUT $b; | ||
271 | close(OUT); | ||
272 | } | ||
273 | |||
274 | sub load_file | ||
275 | { | ||
276 | local($file)=@_; | ||
277 | local(*IN,$r,$b,$i); | ||
278 | |||
279 | $r=""; | ||
280 | open(IN,"<$file") || die "unable to open $file:$!\n"; | ||
281 | for (;;) | ||
282 | { | ||
283 | $i=sysread(IN,$b,10240); | ||
284 | last if ($i <= 0); | ||
285 | $r.=$b; | ||
286 | } | ||
287 | close(IN); | ||
288 | return($r); | ||
289 | } | ||
290 | |||
291 | sub load_file_parse | ||
292 | { | ||
293 | local($file)=@_; | ||
294 | local(*IN,$r,@ret,$_,$i,$n,$b); | ||
295 | |||
296 | open(IN,"$cmd -inform d -in $file|") | ||
297 | || die "unable to run der_parse\n"; | ||
298 | while (<IN>) | ||
299 | { | ||
300 | chop; | ||
301 | push(@ret,$_); | ||
302 | } | ||
303 | return($r,@ret); | ||
304 | } | ||
305 | |||
diff --git a/src/lib/libssl/src/certs/ICE-CA.pem b/src/lib/libssl/src/certs/ICE-CA.pem new file mode 100644 index 0000000000..75652366c2 --- /dev/null +++ b/src/lib/libssl/src/certs/ICE-CA.pem | |||
@@ -0,0 +1,59 @@ | |||
1 | Certificate: | ||
2 | Data: | ||
3 | Version: 3 (0x2) | ||
4 | Serial Number: 1 (0x1) | ||
5 | Signature Algorithm: md5WithRSAEncryption | ||
6 | Issuer: O=European ICE-TEL project, OU=V3-Certification Authority | ||
7 | Validity | ||
8 | Not Before: Apr 2 17:35:53 1997 GMT | ||
9 | Not After : Apr 2 17:35:53 1998 GMT | ||
10 | Subject: O=European ICE-TEL project, OU=V3-Certification Authority, L=Darmstadt | ||
11 | Subject Public Key Info: | ||
12 | Public Key Algorithm: rsa | ||
13 | RSA Public Key: (512 bit) | ||
14 | Modulus (512 bit): | ||
15 | 00:82:75:ba:f6:d1:60:b5:f9:15:b3:6a:dd:29:8f: | ||
16 | 8b:a4:6f:1a:88:e0:50:43:40:0b:79:41:d5:d3:16: | ||
17 | 44:7d:74:65:17:42:06:52:0b:e9:50:c8:10:cd:24: | ||
18 | e2:ae:8d:22:30:73:e6:b4:b7:93:1f:e5:6e:a2:ae: | ||
19 | 49:11:a5:c9:45 | ||
20 | Exponent: 65537 (0x10001) | ||
21 | X509v3 extensions: | ||
22 | X509v3 Authority Key Identifier: | ||
23 | 0.........z.."p......e.. | ||
24 | X509v3 Subject Key Identifier: | ||
25 | ..~r..:..B.44fu......3 | ||
26 | X509v3 Key Usage: critical | ||
27 | .... | ||
28 | X509v3 Certificate Policies: critical | ||
29 | 0.0...*... | ||
30 | X509v3 Subject Alternative Name: | ||
31 | 0!..secude-support@darmstadt.gmd.de | ||
32 | X509v3 Issuer Alternative Name: | ||
33 | 0I..ice-tel-ca@darmstadt.gmd.de.*http://www.darmstadt.gmd.de/ice-tel/euroca | ||
34 | X509v3 Basic Constraints: critical | ||
35 | 0.... | ||
36 | X509v3 CRL Distribution Points: | ||
37 | 0200...,.*http://www.darmstadt.gmd.de/ice-tel/euroca | ||
38 | Signature Algorithm: md5WithRSAEncryption | ||
39 | 17:a2:88:b7:99:5a:05:41:e4:13:34:67:e6:1f:3e:26:ec:4b: | ||
40 | 69:f9:3e:28:22:be:9d:1c:ab:41:6f:0c:00:85:fe:45:74:f6: | ||
41 | 98:f0:ce:9b:65:53:4a:50:42:c7:d4:92:bd:d7:a2:a8:3d:98: | ||
42 | 88:73:cd:60:28:79:a3:fc:48:7a | ||
43 | -----BEGIN CERTIFICATE----- | ||
44 | MIICzDCCAnagAwIBAgIBATANBgkqhkiG9w0BAQQFADBIMSEwHwYDVQQKExhFdXJv | ||
45 | cGVhbiBJQ0UtVEVMIHByb2plY3QxIzAhBgNVBAsTGlYzLUNlcnRpZmljYXRpb24g | ||
46 | QXV0aG9yaXR5MB4XDTk3MDQwMjE3MzU1M1oXDTk4MDQwMjE3MzU1M1owXDEhMB8G | ||
47 | A1UEChMYRXVyb3BlYW4gSUNFLVRFTCBwcm9qZWN0MSMwIQYDVQQLExpWMy1DZXJ0 | ||
48 | aWZpY2F0aW9uIEF1dGhvcml0eTESMBAGA1UEBxMJRGFybXN0YWR0MFkwCgYEVQgB | ||
49 | AQICAgADSwAwSAJBAIJ1uvbRYLX5FbNq3SmPi6RvGojgUENAC3lB1dMWRH10ZRdC | ||
50 | BlIL6VDIEM0k4q6NIjBz5rS3kx/lbqKuSRGlyUUCAwEAAaOCATgwggE0MB8GA1Ud | ||
51 | IwQYMBaAFIr3yNUOx3ro1yJw4AuJ1bbsZbzPMB0GA1UdDgQWBBR+cvL4OoacQog0 | ||
52 | NGZ1w9T80aIRMzAOBgNVHQ8BAf8EBAMCAfYwFAYDVR0gAQH/BAowCDAGBgQqAwQF | ||
53 | MCoGA1UdEQQjMCGBH3NlY3VkZS1zdXBwb3J0QGRhcm1zdGFkdC5nbWQuZGUwUgYD | ||
54 | VR0SBEswSYEbaWNlLXRlbC1jYUBkYXJtc3RhZHQuZ21kLmRlhipodHRwOi8vd3d3 | ||
55 | LmRhcm1zdGFkdC5nbWQuZGUvaWNlLXRlbC9ldXJvY2EwDwYDVR0TAQH/BAUwAwEB | ||
56 | /zA7BgNVHR8ENDAyMDCgLqAshipodHRwOi8vd3d3LmRhcm1zdGFkdC5nbWQuZGUv | ||
57 | aWNlLXRlbC9ldXJvY2EwDQYJKoZIhvcNAQEEBQADQQAXooi3mVoFQeQTNGfmHz4m | ||
58 | 7Etp+T4oIr6dHKtBbwwAhf5FdPaY8M6bZVNKUELH1JK916KoPZiIc81gKHmj/Eh6 | ||
59 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/src/certs/ICE-root.pem b/src/lib/libssl/src/certs/ICE-root.pem new file mode 100644 index 0000000000..fa991599c9 --- /dev/null +++ b/src/lib/libssl/src/certs/ICE-root.pem | |||
@@ -0,0 +1,48 @@ | |||
1 | Certificate: | ||
2 | Data: | ||
3 | Version: 3 (0x2) | ||
4 | Serial Number: 0 (0x0) | ||
5 | Signature Algorithm: md5WithRSAEncryption | ||
6 | Issuer: O=European ICE-TEL project, OU=V3-Certification Authority | ||
7 | Validity | ||
8 | Not Before: Apr 2 17:33:36 1997 GMT | ||
9 | Not After : Apr 2 17:33:36 1998 GMT | ||
10 | Subject: O=European ICE-TEL project, OU=V3-Certification Authority | ||
11 | Subject Public Key Info: | ||
12 | Public Key Algorithm: rsa | ||
13 | RSA Public Key: (512 bit) | ||
14 | Modulus (512 bit): | ||
15 | 00:80:3e:eb:ae:47:a9:fe:10:54:0b:81:8b:9c:2b: | ||
16 | 82:ab:3a:61:36:65:8b:f3:73:9f:ac:ac:7a:15:a7: | ||
17 | 13:8f:b4:c4:ba:a3:0f:bc:a5:58:8d:cc:b1:93:31: | ||
18 | 9e:81:9e:8c:19:61:86:fa:52:73:54:d1:97:76:22: | ||
19 | e7:c7:9f:41:cd | ||
20 | Exponent: 65537 (0x10001) | ||
21 | X509v3 extensions: | ||
22 | X509v3 Subject Key Identifier: | ||
23 | ........z.."p......e.. | ||
24 | X509v3 Key Usage: critical | ||
25 | .... | ||
26 | X509v3 Subject Alternative Name: | ||
27 | 0I.*http://www.darmstadt.gmd.de/ice-tel/euroca..ice-tel-ca@darmstadt.gmd.de | ||
28 | X509v3 Basic Constraints: critical | ||
29 | 0.... | ||
30 | Signature Algorithm: md5WithRSAEncryption | ||
31 | 76:69:61:db:b7:cf:8b:06:9e:d8:8c:96:53:d2:4d:a8:23:a6: | ||
32 | 03:44:e8:8f:24:a5:c0:84:a8:4b:77:d4:2d:2b:7d:37:91:67: | ||
33 | f2:2c:ce:02:31:4c:6b:cc:ce:f2:68:a6:11:11:ab:7d:88:b8: | ||
34 | 7e:22:9f:25:06:60:bd:79:30:3d | ||
35 | -----BEGIN CERTIFICATE----- | ||
36 | MIICFjCCAcCgAwIBAgIBADANBgkqhkiG9w0BAQQFADBIMSEwHwYDVQQKExhFdXJv | ||
37 | cGVhbiBJQ0UtVEVMIHByb2plY3QxIzAhBgNVBAsTGlYzLUNlcnRpZmljYXRpb24g | ||
38 | QXV0aG9yaXR5MB4XDTk3MDQwMjE3MzMzNloXDTk4MDQwMjE3MzMzNlowSDEhMB8G | ||
39 | A1UEChMYRXVyb3BlYW4gSUNFLVRFTCBwcm9qZWN0MSMwIQYDVQQLExpWMy1DZXJ0 | ||
40 | aWZpY2F0aW9uIEF1dGhvcml0eTBZMAoGBFUIAQECAgIAA0sAMEgCQQCAPuuuR6n+ | ||
41 | EFQLgYucK4KrOmE2ZYvzc5+srHoVpxOPtMS6ow+8pViNzLGTMZ6BnowZYYb6UnNU | ||
42 | 0Zd2IufHn0HNAgMBAAGjgZcwgZQwHQYDVR0OBBYEFIr3yNUOx3ro1yJw4AuJ1bbs | ||
43 | ZbzPMA4GA1UdDwEB/wQEAwIB9jBSBgNVHREESzBJhipodHRwOi8vd3d3LmRhcm1z | ||
44 | dGFkdC5nbWQuZGUvaWNlLXRlbC9ldXJvY2GBG2ljZS10ZWwtY2FAZGFybXN0YWR0 | ||
45 | LmdtZC5kZTAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBBAUAA0EAdmlh27fP | ||
46 | iwae2IyWU9JNqCOmA0TojySlwISoS3fULSt9N5Fn8izOAjFMa8zO8mimERGrfYi4 | ||
47 | fiKfJQZgvXkwPQ== | ||
48 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/src/certs/ICE-user.pem b/src/lib/libssl/src/certs/ICE-user.pem new file mode 100644 index 0000000000..28065fd37d --- /dev/null +++ b/src/lib/libssl/src/certs/ICE-user.pem | |||
@@ -0,0 +1,63 @@ | |||
1 | Certificate: | ||
2 | Data: | ||
3 | Version: 3 (0x2) | ||
4 | Serial Number: 1 (0x1) | ||
5 | Signature Algorithm: md5WithRSAEncryption | ||
6 | Issuer: O=European ICE-TEL project, OU=V3-Certification Authority, L=Darmstadt | ||
7 | Validity | ||
8 | Not Before: Apr 2 17:35:59 1997 GMT | ||
9 | Not After : Apr 2 17:35:59 1998 GMT | ||
10 | Subject: O=European ICE-TEL project, OU=V3-Certification Authority, L=Darmstadt, CN=USER | ||
11 | Subject Public Key Info: | ||
12 | Public Key Algorithm: rsa | ||
13 | RSA Public Key: (512 bit) | ||
14 | Modulus (512 bit): | ||
15 | 00:a8:a8:53:63:49:1b:93:c3:c3:0b:6c:88:11:55: | ||
16 | de:7e:6a:e2:f9:52:a0:dc:69:25:c4:c8:bf:55:e1: | ||
17 | 31:a8:ce:e4:a9:29:85:99:8a:15:9a:de:f6:2f:e1: | ||
18 | b4:50:5f:5e:04:75:a6:f4:76:dc:3c:0e:39:dc:3a: | ||
19 | be:3e:a4:61:8b | ||
20 | Exponent: 65537 (0x10001) | ||
21 | X509v3 extensions: | ||
22 | X509v3 Authority Key Identifier: | ||
23 | 0...~r..:..B.44fu......3 | ||
24 | X509v3 Subject Key Identifier: | ||
25 | ...... .*...1.*....... | ||
26 | X509v3 Key Usage: critical | ||
27 | .... | ||
28 | X509v3 Certificate Policies: critical | ||
29 | 0.0...*...0....... | ||
30 | X509v3 Subject Alternative Name: | ||
31 | 0:..user@darmstadt.gmd.de.!http://www.darmstadt.gmd.de/~user | ||
32 | X509v3 Issuer Alternative Name: | ||
33 | 0....gmdca@gmd.de..http://www.gmd.de..saturn.darmstadt.gmd.de.\1!0...U. | ||
34 | ..European ICE-TEL project1#0!..U....V3-Certification Authority1.0...U....Darmstadt..141.12.62.26 | ||
35 | X509v3 Basic Constraints: critical | ||
36 | 0. | ||
37 | X509v3 CRL Distribution Points: | ||
38 | 0.0.......gmdca@gmd.de | ||
39 | Signature Algorithm: md5WithRSAEncryption | ||
40 | 69:0c:e1:b7:a7:f2:d8:fb:e8:69:c0:13:cd:37:ad:21:06:22: | ||
41 | 4d:e8:c6:db:f1:04:0b:b7:e0:b3:d6:0c:81:03:ce:c3:6a:3e: | ||
42 | c7:e7:24:24:a4:92:64:c2:83:83:06:42:53:0e:6f:09:1e:84: | ||
43 | 9a:f7:6f:63:9b:94:99:83:d6:a4 | ||
44 | -----BEGIN CERTIFICATE----- | ||
45 | MIIDTzCCAvmgAwIBAgIBATANBgkqhkiG9w0BAQQFADBcMSEwHwYDVQQKExhFdXJv | ||
46 | cGVhbiBJQ0UtVEVMIHByb2plY3QxIzAhBgNVBAsTGlYzLUNlcnRpZmljYXRpb24g | ||
47 | QXV0aG9yaXR5MRIwEAYDVQQHEwlEYXJtc3RhZHQwHhcNOTcwNDAyMTczNTU5WhcN | ||
48 | OTgwNDAyMTczNTU5WjBrMSEwHwYDVQQKExhFdXJvcGVhbiBJQ0UtVEVMIHByb2pl | ||
49 | Y3QxIzAhBgNVBAsTGlYzLUNlcnRpZmljYXRpb24gQXV0aG9yaXR5MRIwEAYDVQQH | ||
50 | EwlEYXJtc3RhZHQxDTALBgNVBAMTBFVTRVIwWTAKBgRVCAEBAgICAANLADBIAkEA | ||
51 | qKhTY0kbk8PDC2yIEVXefmri+VKg3GklxMi/VeExqM7kqSmFmYoVmt72L+G0UF9e | ||
52 | BHWm9HbcPA453Dq+PqRhiwIDAQABo4IBmDCCAZQwHwYDVR0jBBgwFoAUfnLy+DqG | ||
53 | nEKINDRmdcPU/NGiETMwHQYDVR0OBBYEFJfc4B8gjSoRmLUx4Sq/ucIYiMrPMA4G | ||
54 | A1UdDwEB/wQEAwIB8DAcBgNVHSABAf8EEjAQMAYGBCoDBAUwBgYECQgHBjBDBgNV | ||
55 | HREEPDA6gRV1c2VyQGRhcm1zdGFkdC5nbWQuZGWGIWh0dHA6Ly93d3cuZGFybXN0 | ||
56 | YWR0LmdtZC5kZS9+dXNlcjCBsQYDVR0SBIGpMIGmgQxnbWRjYUBnbWQuZGWGEWh0 | ||
57 | dHA6Ly93d3cuZ21kLmRlghdzYXR1cm4uZGFybXN0YWR0LmdtZC5kZaRcMSEwHwYD | ||
58 | VQQKExhFdXJvcGVhbiBJQ0UtVEVMIHByb2plY3QxIzAhBgNVBAsTGlYzLUNlcnRp | ||
59 | ZmljYXRpb24gQXV0aG9yaXR5MRIwEAYDVQQHEwlEYXJtc3RhZHSHDDE0MS4xMi42 | ||
60 | Mi4yNjAMBgNVHRMBAf8EAjAAMB0GA1UdHwQWMBQwEqAQoA6BDGdtZGNhQGdtZC5k | ||
61 | ZTANBgkqhkiG9w0BAQQFAANBAGkM4ben8tj76GnAE803rSEGIk3oxtvxBAu34LPW | ||
62 | DIEDzsNqPsfnJCSkkmTCg4MGQlMObwkehJr3b2OblJmD1qQ= | ||
63 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/src/certs/ICE.crl b/src/lib/libssl/src/certs/ICE.crl new file mode 100644 index 0000000000..21939e8cc4 --- /dev/null +++ b/src/lib/libssl/src/certs/ICE.crl | |||
@@ -0,0 +1,9 @@ | |||
1 | -----BEGIN X509 CRL----- | ||
2 | MIIBNDCBnjANBgkqhkiG9w0BAQIFADBFMSEwHwYDVQQKExhFdXJvcGVhbiBJQ0Ut | ||
3 | VEVMIFByb2plY3QxIDAeBgNVBAsTF0NlcnRpZmljYXRpb24gQXV0aG9yaXR5Fw05 | ||
4 | NzA2MDkxNDQyNDNaFw05NzA3MDkxNDQyNDNaMCgwEgIBChcNOTcwMzAzMTQ0MjU0 | ||
5 | WjASAgEJFw05NjEwMDIxMjI5MjdaMA0GCSqGSIb3DQEBAgUAA4GBAH4vgWo2Tej/ | ||
6 | i7kbiw4Imd30If91iosjClNpBFwvwUDBclPEeMuYimHbLOk4H8Nofc0fw11+U/IO | ||
7 | KSNouUDcqG7B64oY7c4SXKn+i1MWOb5OJiWeodX3TehHjBlyWzoNMWCnYA8XqFP1 | ||
8 | mOKp8Jla1BibEZf14+/HqCi2hnZUiEXh | ||
9 | -----END X509 CRL----- | ||
diff --git a/src/lib/libssl/src/certs/ca-cert.pem b/src/lib/libssl/src/certs/ca-cert.pem new file mode 100644 index 0000000000..6dd974d70d --- /dev/null +++ b/src/lib/libssl/src/certs/ca-cert.pem | |||
@@ -0,0 +1,31 @@ | |||
1 | issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test PCA (1024 bit) | ||
2 | subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit) | ||
3 | -----BEGIN CERTIFICATE----- | ||
4 | MIICJjCCAY8CAQAwDQYJKoZIhvcNAQEEBQAwXDELMAkGA1UEBhMCQVUxEzARBgNV | ||
5 | BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRwwGgYD | ||
6 | VQQDExNUZXN0IFBDQSAoMTAyNCBiaXQpMB4XDTk3MDYwOTEzNTc0M1oXDTAxMDYw | ||
7 | OTEzNTc0M1owWzELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxGjAY | ||
8 | BgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYDVQQDExJUZXN0IENBICgxMDI0 | ||
9 | IGJpdCkwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKO7o8t116VP6cgybTsZ | ||
10 | DCZhr95nYlZuya3aCi1IKoztqwWnjbmDFIriOqGFPrZQ+moMETC9D59iRW/dFXSv | ||
11 | 1F65ka/XY2hLh9exCCo7XuUcDs53Qp3bI3AmMqHjgzE8oO3ajyJAzJkTTOUecQU2 | ||
12 | mw/gI4tMM0LqWMQS7luTy4+xAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAM7achv3v | ||
13 | hLQJcv/65eGEpBXM40ZDVoFQFFJWaY5p883HTqLB1x4FdzsXHH0QKBTcKpWwqyu4 | ||
14 | YDm3fb8oDugw72bCzfyZK/zVZPR/hVlqI/fvU109Qoc+7oPvIXWky71HfcK6ZBCA | ||
15 | q30KIqGM/uoM60INq97qjDmCJapagcNBGQs= | ||
16 | -----END CERTIFICATE----- | ||
17 | -----BEGIN RSA PRIVATE KEY----- | ||
18 | MIICXQIBAAKBgQCju6PLddelT+nIMm07GQwmYa/eZ2JWbsmt2gotSCqM7asFp425 | ||
19 | gxSK4jqhhT62UPpqDBEwvQ+fYkVv3RV0r9ReuZGv12NoS4fXsQgqO17lHA7Od0Kd | ||
20 | 2yNwJjKh44MxPKDt2o8iQMyZE0zlHnEFNpsP4COLTDNC6ljEEu5bk8uPsQIDAQAB | ||
21 | AoGAVZmpFZsDZfr0l2S9tLLwpjRWNOlKATQkno6q2WesT0eGLQufTciY+c8ypfU6 | ||
22 | hyio8r5iUl/VhhdjhAtKx1mRpiotftHo/eYf8rtsrnprOnWG0bWjLjtIoMbcxGn2 | ||
23 | J3bN6LJmbJMjDs0eJ3KnTu646F3nDUw2oGAwmpzKXA1KAP0CQQDRvQhxk2D3Pehs | ||
24 | HvG665u2pB5ipYQngEFlZO7RHJZzJOZEWSLuuMqaF/7pTfA5jiBvWqCgJeCRRInL | ||
25 | 21ru4dlPAkEAx9jj7BgKn5TYnMoBSSe0afjsV9oApVpN1Nacb1YDtCwy+scp3++s | ||
26 | nFxlv98wxIlSdpwMUn+AUWfjiWR7Tu/G/wJBAJ/KjwZIrFVxewP0x2ILYsTRYLzz | ||
27 | MS4PDsO7FB+I0i7DbBOifXS2oNSpd3I0CNMwrxFnUHzynpbOStVfN3ZL5w0CQQCa | ||
28 | pwFahxBRhkJKsxhjoFJBX9yl75JoY4Wvm5Tbo9ih6UJaRx3kqfkN14L2BKYcsZgb | ||
29 | KY9vmDOYy6iNfjDeWTfJAkBkfPUb8oTJ/nSP5zN6sqGxSY4krc4xLxpRmxoJ8HL2 | ||
30 | XfhqXkTzbU13RX9JJ/NZ8vQN9Vm2NhxRGJocQkmcdVtJ | ||
31 | -----END RSA PRIVATE KEY----- | ||
diff --git a/src/lib/libssl/src/certs/dsa-ca.pem b/src/lib/libssl/src/certs/dsa-ca.pem new file mode 100644 index 0000000000..9eb08f3ddd --- /dev/null +++ b/src/lib/libssl/src/certs/dsa-ca.pem | |||
@@ -0,0 +1,43 @@ | |||
1 | -----BEGIN DSA PRIVATE KEY----- | ||
2 | Proc-Type: 4,ENCRYPTED | ||
3 | DEK-Info: DES-EDE3-CBC,C5B6C7CC9E1FE2C0 | ||
4 | |||
5 | svCXBcBRhMuU22UXOfiKZA+thmz6KYXpt1Yg5Rd+TYQcQ1MdvNy0B0tkP1SxzDq0 | ||
6 | Xh1eMeTML9/9/0rKakgNXXXbpi5RB8t6BmwRSyej89F7nn1mtR3qzoyPRpp15SDl | ||
7 | Tn67C+2v+HDF3MFk88hiNCYkNbcmi7TWvChsl8N1r7wdZwtIox56yXdgxw6ZIpa/ | ||
8 | par0oUCzN7fiavPgCWz1kfPNSaBQSdxwH7TZi5tMHAr0J3C7a7QRnZfE09R59Uqr | ||
9 | zslrq+ndIw1BZAxoY0SlBu+iFOVaBVlwToC4AsHkv7j7l8ITtr7f42YbBa44D9TO | ||
10 | uOhONmkk/v3Fso4RaOEzdKZC+hnmmzvHs6TiTWm6yzJgSFwyOUK0eGmKEeVxpcH5 | ||
11 | rUOlHOwzen+FFtocZDZAfdFnb7QY7L/boQvyA5A+ZbRG4DUpmBQeQsSaICHM5Rxx | ||
12 | 1QaLF413VNPXTLPbW0ilSc2H8x2iZTIVKfd33oSO6NhXPtSYQgfecEF4BvNHY5c4 | ||
13 | HovjT4mckbK95bcBzoCHu43vuSQkmZzdYo/ydSZt6zoPavbBLueTpgSbdXiDi827 | ||
14 | MVqOsYxGCb+kez0FoDSTgw== | ||
15 | -----END DSA PRIVATE KEY----- | ||
16 | -----BEGIN CERTIFICATE REQUEST----- | ||
17 | MIICUjCCAhECAQAwUjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUx | ||
18 | ITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDELMAkGA1UEAxMCQ0Ew | ||
19 | ggG0MIIBKQYFKw4DAgwwggEeAoGBAKc/boW/QWopffCfRxkwkJoJHdpqMx7FPYaW | ||
20 | sxXgUy6P4FmCc5A+dTGZR3pS+4Xk2aZ7OJtoioSbh8YetX6GS1NbWc9xZRmIbs5m | ||
21 | rmuINvvsKNzC16W75Sw5JkvamnAYlTeVEFYj9hXtugRe3jlP/bdDH7WkZW/NgBHk | ||
22 | cJVbUM1JAhUA9wcx7fpsBgPVhYocrJxl51BmZW8CgYBN30wDppGK9RlvUEYlmeVo | ||
23 | bzDjaeHls12YuyiGSPzemQQ/X4gMnHMkDSBduSqaPxiWJ+Rih8F7dGJT/GEnqHqR | ||
24 | CZ228U2cVA9YBu5JdAfOVX4jzhb2ytxaYQF+yXG1TfbcNCmHaPZeIJOz2/XkCWxB | ||
25 | F5WS6wG1c6Vqftgy7Q4CuAOBhAACgYAapll6iqz9XrZFlk2GCVcB+KihxWnH7IuH | ||
26 | vSLw9YUrJahcBHmbpvt494lF4gC5w3WPM+vXJofbusk4GoQEEsQNMDaah4m49uUq | ||
27 | AylOVFJJJXuirVJ+o+0TtOFDITEAl+YZZariXOD7tdOSOl9RLMPC6+daHKS9e68u | ||
28 | 3enxhqnDGaAAMAkGBSsOAwIbBQADMAAwLQIVAJGVuFsG/0DBuSZ0jF7ypdU0/G0v | ||
29 | AhQfeF5BoMMDbX/kidUVpQ6gadPlZA== | ||
30 | -----END CERTIFICATE REQUEST----- | ||
31 | -----BEGIN CERTIFICATE----- | ||
32 | MIIBrjCCAWwCAQswCQYFKw4DAhsFADBTMQswCQYDVQQGEwJBVTETMBEGA1UECBMK | ||
33 | U29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMQww | ||
34 | CgYDVQQDEwNQQ0EwHhcNOTcwNjE1MDIxNDI5WhcNOTcwNzE1MDIxNDI5WjBSMQsw | ||
35 | CQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJu | ||
36 | ZXQgV2lkZ2l0cyBQdHkgTHRkMQswCQYDVQQDEwJDQTCBkjAJBgUrDgMCDAUAA4GE | ||
37 | AAKBgBqmWXqKrP1etkWWTYYJVwH4qKHFacfsi4e9IvD1hSslqFwEeZum+3j3iUXi | ||
38 | ALnDdY8z69cmh9u6yTgahAQSxA0wNpqHibj25SoDKU5UUkkle6KtUn6j7RO04UMh | ||
39 | MQCX5hllquJc4Pu105I6X1Esw8Lr51ocpL17ry7d6fGGqcMZMAkGBSsOAwIbBQAD | ||
40 | MQAwLgIVAJ4wtQsANPxHo7Q4IQZYsL12SKdbAhUAjJ9n38zxT+iai2164xS+LIfa | ||
41 | C1Q= | ||
42 | -----END CERTIFICATE----- | ||
43 | |||
diff --git a/src/lib/libssl/src/certs/dsa-pca.pem b/src/lib/libssl/src/certs/dsa-pca.pem new file mode 100644 index 0000000000..e3641ad47e --- /dev/null +++ b/src/lib/libssl/src/certs/dsa-pca.pem | |||
@@ -0,0 +1,49 @@ | |||
1 | -----BEGIN DSA PRIVATE KEY----- | ||
2 | Proc-Type: 4,ENCRYPTED | ||
3 | DEK-Info: DES-EDE3-CBC,F80EEEBEEA7386C4 | ||
4 | |||
5 | GZ9zgFcHOlnhPoiSbVi/yXc9mGoj44A6IveD4UlpSEUt6Xbse3Fr0KHIUyQ3oGnS | ||
6 | mClKoAp/eOTb5Frhto85SzdsxYtac+X1v5XwdzAMy2KowHVk1N8A5jmE2OlkNPNt | ||
7 | of132MNlo2cyIRYaa35PPYBGNCmUm7YcYS8O90YtkrQZZTf4+2C4kllhMcdkQwkr | ||
8 | FWSWC8YOQ7w0LHb4cX1FejHHom9Nd/0PN3vn3UyySvfOqoR7nbXkrpHXmPIr0hxX | ||
9 | RcF0aXcV/CzZ1/nfXWQf4o3+oD0T22SDoVcZY60IzI0oIc3pNCbDV3uKNmgekrFd | ||
10 | qOUJ+QW8oWp7oefRx62iBfIeC8DZunohMXaWAQCU0sLQOR4yEdeUCnzCSywe0bG1 | ||
11 | diD0KYaEe+Yub1BQH4aLsBgDjardgpJRTQLq0DUvw0/QGO1irKTJzegEDNVBKrVn | ||
12 | V4AHOKT1CUKqvGNRP1UnccUDTF6miOAtaj/qpzra7sSk7dkGBvIEeFoAg84kfh9h | ||
13 | hVvF1YyzC9bwZepruoqoUwke/WdNIR5ymOVZ/4Liw0JdIOcq+atbdRX08niqIRkf | ||
14 | dsZrUj4leo3zdefYUQ7w4N2Ns37yDFq7 | ||
15 | -----END DSA PRIVATE KEY----- | ||
16 | -----BEGIN CERTIFICATE REQUEST----- | ||
17 | MIICVTCCAhMCAQAwUzELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUx | ||
18 | ITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEMMAoGA1UEAxMDUENB | ||
19 | MIIBtTCCASkGBSsOAwIMMIIBHgKBgQCnP26Fv0FqKX3wn0cZMJCaCR3aajMexT2G | ||
20 | lrMV4FMuj+BZgnOQPnUxmUd6UvuF5NmmezibaIqEm4fGHrV+hktTW1nPcWUZiG7O | ||
21 | Zq5riDb77Cjcwtelu+UsOSZL2ppwGJU3lRBWI/YV7boEXt45T/23Qx+1pGVvzYAR | ||
22 | 5HCVW1DNSQIVAPcHMe36bAYD1YWKHKycZedQZmVvAoGATd9MA6aRivUZb1BGJZnl | ||
23 | aG8w42nh5bNdmLsohkj83pkEP1+IDJxzJA0gXbkqmj8YlifkYofBe3RiU/xhJ6h6 | ||
24 | kQmdtvFNnFQPWAbuSXQHzlV+I84W9srcWmEBfslxtU323DQph2j2XiCTs9v15Als | ||
25 | QReVkusBtXOlan7YMu0OArgDgYUAAoGBAKbtuR5AdW+ICjCFe2ixjUiJJzM2IKwe | ||
26 | 6NZEMXg39+HQ1UTPTmfLZLps+rZfolHDXuRKMXbGFdSF0nXYzotPCzi7GauwEJTZ | ||
27 | yr27ZZjA1C6apGSQ9GzuwNvZ4rCXystVEagAS8OQ4H3D4dWS17Zg31ICb5o4E5r0 | ||
28 | z09o/Uz46u0VoAAwCQYFKw4DAhsFAAMxADAuAhUArRubTxsbIXy3AhtjQ943AbNB | ||
29 | nSICFQCu+g1iW3jwF+gOcbroD4S/ZcvB3w== | ||
30 | -----END CERTIFICATE REQUEST----- | ||
31 | -----BEGIN CERTIFICATE----- | ||
32 | MIIC0zCCApECAQAwCQYFKw4DAhsFADBTMQswCQYDVQQGEwJBVTETMBEGA1UECBMK | ||
33 | U29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMQww | ||
34 | CgYDVQQDEwNQQ0EwHhcNOTcwNjE0MjI1NDQ1WhcNOTcwNzE0MjI1NDQ1WjBTMQsw | ||
35 | CQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJu | ||
36 | ZXQgV2lkZ2l0cyBQdHkgTHRkMQwwCgYDVQQDEwNQQ0EwggG1MIIBKQYFKw4DAgww | ||
37 | ggEeAoGBAKc/boW/QWopffCfRxkwkJoJHdpqMx7FPYaWsxXgUy6P4FmCc5A+dTGZ | ||
38 | R3pS+4Xk2aZ7OJtoioSbh8YetX6GS1NbWc9xZRmIbs5mrmuINvvsKNzC16W75Sw5 | ||
39 | JkvamnAYlTeVEFYj9hXtugRe3jlP/bdDH7WkZW/NgBHkcJVbUM1JAhUA9wcx7fps | ||
40 | BgPVhYocrJxl51BmZW8CgYBN30wDppGK9RlvUEYlmeVobzDjaeHls12YuyiGSPze | ||
41 | mQQ/X4gMnHMkDSBduSqaPxiWJ+Rih8F7dGJT/GEnqHqRCZ228U2cVA9YBu5JdAfO | ||
42 | VX4jzhb2ytxaYQF+yXG1TfbcNCmHaPZeIJOz2/XkCWxBF5WS6wG1c6Vqftgy7Q4C | ||
43 | uAOBhQACgYEApu25HkB1b4gKMIV7aLGNSIknMzYgrB7o1kQxeDf34dDVRM9OZ8tk | ||
44 | umz6tl+iUcNe5EoxdsYV1IXSddjOi08LOLsZq7AQlNnKvbtlmMDULpqkZJD0bO7A | ||
45 | 29nisJfKy1URqABLw5DgfcPh1ZLXtmDfUgJvmjgTmvTPT2j9TPjq7RUwCQYFKw4D | ||
46 | AhsFAAMxADAuAhUAvtv6AkMolix1Jvy3UnVEIUqdCUICFQC+jq8P49mwrY9oJ24n | ||
47 | 5rKUjNBhSg== | ||
48 | -----END CERTIFICATE----- | ||
49 | |||
diff --git a/src/lib/libssl/src/certs/factory.pem b/src/lib/libssl/src/certs/factory.pem new file mode 100644 index 0000000000..8e28b391b2 --- /dev/null +++ b/src/lib/libssl/src/certs/factory.pem | |||
@@ -0,0 +1,15 @@ | |||
1 | -----BEGIN CERTIFICATE----- | ||
2 | MIICTTCCAbagAwIBAgIBADANBgkqhkiG9w0BAQQFADBMMQswCQYDVQQGEwJHQjEM | ||
3 | MAoGA1UEChMDVUNMMRgwFgYDVQQLEw9JQ0UtVEVMIFByb2plY3QxFTATBgNVBAMT | ||
4 | DFRydXN0RmFjdG9yeTAeFw05NzA0MjIxNDM5MTRaFw05ODA0MjIxNDM5MTRaMEwx | ||
5 | CzAJBgNVBAYTAkdCMQwwCgYDVQQKEwNVQ0wxGDAWBgNVBAsTD0lDRS1URUwgUHJv | ||
6 | amVjdDEVMBMGA1UEAxMMVHJ1c3RGYWN0b3J5MIGcMAoGBFUIAQECAgQAA4GNADCB | ||
7 | iQKBgQCEieR8NcXkUW1f0G6aC6u0i8q/98JqS6RxK5YmHIGKCkuTWAUjzLfUa4dt | ||
8 | U9igGCjTuxaDqlzEim+t/02pmiBZT9HaX++35MjQPUWmsChcYU5WyzGErXi+rQaw | ||
9 | zlwS73zM8qiPj/97lXYycWhgL0VaiDSPxRXEUdWoaGruom4mNQIDAQABo0IwQDAd | ||
10 | BgNVHQ4EFgQUHal1LZr7oVg5z6lYzrhTgZRCmcUwDgYDVR0PAQH/BAQDAgH2MA8G | ||
11 | A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAfaggfl6FZoioecjv0dq8 | ||
12 | /DXo/u11iMZvXn08gjX/zl2b4wtPbShOSY5FhkSm8GeySasz+/Nwb/uzfnIhokWi | ||
13 | lfPZHtlCWtXbIy/TN51eJyq04ceDCQDWvLC2enVg9KB+GJ34b5c5VaPRzq8MBxsA | ||
14 | S7ELuYGtmYgYm9NZOIr7yU0= | ||
15 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/src/certs/nortelCA.pem b/src/lib/libssl/src/certs/nortelCA.pem new file mode 100644 index 0000000000..207f34ab3a --- /dev/null +++ b/src/lib/libssl/src/certs/nortelCA.pem | |||
@@ -0,0 +1,16 @@ | |||
1 | -----BEGIN CERTIFICATE----- | ||
2 | MIICajCCAdMCBDGA0QUwDQYJKoZIhvcNAQEEBQAwfTELMAkGA1UEBhMCQ2ExDzAN | ||
3 | BgNVBAcTBk5lcGVhbjEeMBwGA1UECxMVTm8gTGlhYmlsaXR5IEFjY2VwdGVkMR8w | ||
4 | HQYDVQQKExZGb3IgRGVtbyBQdXJwb3NlcyBPbmx5MRwwGgYDVQQDExNFbnRydXN0 | ||
5 | IERlbW8gV2ViIENBMB4XDTk2MDQyNjEzMzUwMVoXDTA2MDQyNjEzMzUwMVowfTEL | ||
6 | MAkGA1UEBhMCQ2ExDzANBgNVBAcTBk5lcGVhbjEeMBwGA1UECxMVTm8gTGlhYmls | ||
7 | aXR5IEFjY2VwdGVkMR8wHQYDVQQKExZGb3IgRGVtbyBQdXJwb3NlcyBPbmx5MRww | ||
8 | GgYDVQQDExNFbnRydXN0IERlbW8gV2ViIENBMIGdMA0GCSqGSIb3DQEBAQUAA4GL | ||
9 | ADCBhwKBgQCaroS7O1DA0hm4IefNYU1cx/nqOmzEnk291d1XqznDeF4wEgakbkCc | ||
10 | zTKxK791yNpXG5RmngqH7cygDRTHZJ6mfCRn0wGC+AI00F2vYTGqPGRQL1N3lZT0 | ||
11 | YDKFC0SQeMMjFIZ1aeQigroFQnHo0VB3zWIMpNkka8PY9lxHZAmWwQIBAzANBgkq | ||
12 | hkiG9w0BAQQFAAOBgQBAx0UMVA1s54lMQyXjMX5kj99FJN5itb8bK1Rk+cegPQPF | ||
13 | cWO9SEWyEjjBjIkjjzAwBkaEszFsNGxemxtXvwjIm1xEUMTVlPEWTs2qnDvAUA9W | ||
14 | YqhWbhH0toGT36236QAsqCZ76rbTRVSSX2BHyJwJMG2tCRv7kRJ//NIgxj3H4w== | ||
15 | -----END CERTIFICATE----- | ||
16 | |||
diff --git a/src/lib/libssl/src/certs/pca-cert.pem b/src/lib/libssl/src/certs/pca-cert.pem new file mode 100644 index 0000000000..140e9a6b43 --- /dev/null +++ b/src/lib/libssl/src/certs/pca-cert.pem | |||
@@ -0,0 +1,31 @@ | |||
1 | issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test PCA (1024 bit) | ||
2 | subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test PCA (1024 bit) | ||
3 | -----BEGIN CERTIFICATE----- | ||
4 | MIICJzCCAZACAQAwDQYJKoZIhvcNAQEEBQAwXDELMAkGA1UEBhMCQVUxEzARBgNV | ||
5 | BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRwwGgYD | ||
6 | VQQDExNUZXN0IFBDQSAoMTAyNCBiaXQpMB4XDTk3MDYwOTEzNTczN1oXDTAxMDYw | ||
7 | OTEzNTczN1owXDELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxGjAY | ||
8 | BgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRwwGgYDVQQDExNUZXN0IFBDQSAoMTAy | ||
9 | NCBiaXQpMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCdoWk/3+WcMlfjIrkg | ||
10 | 40ketmnQaEogQe1LLcuOJV6rKfUSAsPgwgsabJ/wn8TxA1yy3eKJbFl3OiUXMRsp | ||
11 | 22Jp85PmemiDzyUIStwk72qhp1imbANZvlmlCFKiQrjUyuDfu4TABmn+kkt3vR1Y | ||
12 | BEOGt+IFye1UBVSATVdRJ2UVhwIDAQABMA0GCSqGSIb3DQEBBAUAA4GBABNA1u/S | ||
13 | Cg/LJZWb7GliiKJsvuhxlE4E5JxQF2zMub/CSNbF97//tYSyj96sxeFQxZXbcjm9 | ||
14 | xt6mr/xNLA4szNQMJ4P+L7b5e/jC5DSqlwS+CUYJgaFs/SP+qJoCSu1bR3IM9XWO | ||
15 | cRBpDmcBbYLkSyB92WURvsZ1LtjEcn+cdQVI | ||
16 | -----END CERTIFICATE----- | ||
17 | -----BEGIN RSA PRIVATE KEY----- | ||
18 | MIICXAIBAAKBgQCdoWk/3+WcMlfjIrkg40ketmnQaEogQe1LLcuOJV6rKfUSAsPg | ||
19 | wgsabJ/wn8TxA1yy3eKJbFl3OiUXMRsp22Jp85PmemiDzyUIStwk72qhp1imbANZ | ||
20 | vlmlCFKiQrjUyuDfu4TABmn+kkt3vR1YBEOGt+IFye1UBVSATVdRJ2UVhwIDAQAB | ||
21 | AoGAba4fTtuap5l7/8ZsbE7Z1O32KJY4ZcOZukLOLUUhXxXduT+FTgGWujc0/rgc | ||
22 | z9qYCLlNZHOouMYTgtSfYvuMuLZ11VIt0GYH+nRioLShE59Yy+zCRyC+gPigS1kz | ||
23 | xvo14AsOIPYV14Tk/SsHyq6E0eTk7VzaIE197giiINUERPECQQDSKmtPTh/lRKw7 | ||
24 | HSZSM0I1mFWn/1zqrAbontRQY5w98QWIOe5qmzYyFbPXYT3d9BzlsMyhgiRNoBbD | ||
25 | yvohSHXJAkEAwAHx6ezAZeWWzD5yXD36nyjpkVCw7Tk7TSmOceLJMWt1QcrCfqlS | ||
26 | xA5jjpQ6Z8suU5DdtWAryM2sAir1WisYzwJAd6Zcx56jvAQ3xcPXsE6scBTVFzrj | ||
27 | 7FqZ6E+cclPzfLQ+QQsyOBE7bpI6e/FJppY26XGZXo3YGzV8IGXrt40oOQJALETG | ||
28 | h86EFXo3qGOFbmsDy4pdP5nBERCu8X1xUCSfintiD4c2DInxgS5oGclnJeMcjTvL | ||
29 | QjQoJCX3UJCi/OUO1QJBAKgcDHWjMvt+l1pjJBsSEZ0HX9AAIIVx0RQmbFGS+F2Q | ||
30 | hhu5l77WnnZOQ9vvhV5u7NPCUF9nhU3jh60qWWO8mkc= | ||
31 | -----END RSA PRIVATE KEY----- | ||
diff --git a/src/lib/libssl/src/certs/rsa-cca.pem b/src/lib/libssl/src/certs/rsa-cca.pem new file mode 100644 index 0000000000..69f5c1c84c --- /dev/null +++ b/src/lib/libssl/src/certs/rsa-cca.pem | |||
@@ -0,0 +1,19 @@ | |||
1 | subject=/C=US/O=RSA Data Security, Inc./OU=Commercial Certification Authority | ||
2 | issuer= /C=US/O=RSA Data Security, Inc./OU=Commercial Certification Authority | ||
3 | notBefore=941104185834Z | ||
4 | notAfter =991103185834Z | ||
5 | -----BEGIN X509 CERTIFICATE----- | ||
6 | |||
7 | MIICIzCCAZACBQJBAAAWMA0GCSqGSIb3DQEBAgUAMFwxCzAJBgNVBAYTAlVTMSAw | ||
8 | HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjErMCkGA1UECxMiQ29tbWVy | ||
9 | Y2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NDExMDQxODU4MzRaFw05 | ||
10 | OTExMDMxODU4MzRaMFwxCzAJBgNVBAYTAlVTMSAwHgYDVQQKExdSU0EgRGF0YSBT | ||
11 | ZWN1cml0eSwgSW5jLjErMCkGA1UECxMiQ29tbWVyY2lhbCBDZXJ0aWZpY2F0aW9u | ||
12 | IEF1dGhvcml0eTCBmzANBgkqhkiG9w0BAQEFAAOBiQAwgYUCfgCk+4Fie84QJ93o | ||
13 | 975sbsZwmdu41QUDaSiCnHJ/lj+O7Kwpkj+KFPhCdr69XQO5kNTQvAayUTNfxMK/ | ||
14 | touPmbZiImDd298ggrTKoi8tUO2UMt7gVY3UaOLgTNLNBRYulWZcYVI4HlGogqHE | ||
15 | 7yXpCuaLK44xZtn42f29O2nZ6wIDAQABMA0GCSqGSIb3DQEBAgUAA34AdrW2EP4j | ||
16 | 9/dZYkuwX5zBaLxJu7NJbyFHXSudVMQAKD+YufKKg5tgf+tQx6sFEC097TgCwaVI | ||
17 | 0v5loMC86qYjFmZsGySp8+x5NRhPJsjjr1BKx6cxa9B8GJ1Qv6km+iYrRpwUqbtb | ||
18 | MJhCKLVLU7tDCZJAuqiqWqTGtotXTcU= | ||
19 | -----END X509 CERTIFICATE----- | ||
diff --git a/src/lib/libssl/src/certs/timCA.pem b/src/lib/libssl/src/certs/timCA.pem new file mode 100644 index 0000000000..9c8d5bf9c6 --- /dev/null +++ b/src/lib/libssl/src/certs/timCA.pem | |||
@@ -0,0 +1,16 @@ | |||
1 | Tims test GCI CA | ||
2 | |||
3 | -----BEGIN CERTIFICATE----- | ||
4 | MIIB8DCCAZoCAQAwDQYJKoZIhvcNAQEEBQAwgYIxCzAJBgNVBAYTAkFVMRMwEQYD | ||
5 | VQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5 | ||
6 | cHRTb2Z0IFB0eSBMdGQxFDASBgNVBAsTC2RldmVsb3BtZW50MRkwFwYDVQQDExBD | ||
7 | cnlwdFNvZnQgRGV2IENBMB4XDTk3MDMyMjEzMzQwNFoXDTk4MDMyMjEzMzQwNFow | ||
8 | gYIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhC | ||
9 | cmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxFDASBgNVBAsTC2Rl | ||
10 | dmVsb3BtZW50MRkwFwYDVQQDExBDcnlwdFNvZnQgRGV2IENBMFwwDQYJKoZIhvcN | ||
11 | AQEBBQADSwAwSAJBAOAOAqogG5QwAmLhzyO4CoRnx/wVy4NZP4dxJy83O1EnL0rw | ||
12 | OdsamJKvPOLHgSXo3gDu9uVyvCf/QJmZAmC5ml8CAwEAATANBgkqhkiG9w0BAQQF | ||
13 | AANBADRRS/GVdd7rAqRW6SdmgLJduOU2yq3avBu99kRqbp9A/dLu6r6jU+eP4oOA | ||
14 | TfdbFZtAAD2Hx9jUtY3tfdrJOb8= | ||
15 | -----END CERTIFICATE----- | ||
16 | |||
diff --git a/src/lib/libssl/src/certs/tjhCA.pem b/src/lib/libssl/src/certs/tjhCA.pem new file mode 100644 index 0000000000..67bee1b200 --- /dev/null +++ b/src/lib/libssl/src/certs/tjhCA.pem | |||
@@ -0,0 +1,15 @@ | |||
1 | -----BEGIN CERTIFICATE----- | ||
2 | MIICVjCCAgACAQAwDQYJKoZIhvcNAQEEBQAwgbUxCzAJBgNVBAYTAkFVMRMwEQYD | ||
3 | VQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5 | ||
4 | cHRTb2Z0IFB0eSBMdGQxLDAqBgNVBAsTI1dPUlRITEVTUyBDRVJUSUZJQ0FUSU9O | ||
5 | IEFVVEhPUklUSUVTMTQwMgYDVQQDEytaRVJPIFZBTFVFIENBIC0gREVNT05TVFJB | ||
6 | VElPTiBQVVJQT1NFUyBPTkxZMB4XDTk3MDQwMzEzMjI1NFoXDTk4MDQwMzEzMjI1 | ||
7 | NFowgbUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH | ||
8 | EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxLDAqBgNVBAsT | ||
9 | I1dPUlRITEVTUyBDRVJUSUZJQ0FUSU9OIEFVVEhPUklUSUVTMTQwMgYDVQQDEyta | ||
10 | RVJPIFZBTFVFIENBIC0gREVNT05TVFJBVElPTiBQVVJQT1NFUyBPTkxZMFwwDQYJ | ||
11 | KoZIhvcNAQEBBQADSwAwSAJBAOZ7T7yqP/tyspcko3yPY1y0Cm2EmwNvzW4QgVXR | ||
12 | Fjs3HmJ4xtSpXdo6mwcGezL3Abt/aQXaxv9PU8xt+Jr0OFUCAwEAATANBgkqhkiG | ||
13 | 9w0BAQQFAANBAOQpYmGgyCqCy1OljgJhCqQOu627oVlHzK1L+t9vBaMfn40AVUR4 | ||
14 | WzQVWO31KTgi5vTK1U+3h46fgUWqQ0h+6rU= | ||
15 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/src/certs/vsign2.pem b/src/lib/libssl/src/certs/vsign2.pem new file mode 100644 index 0000000000..2386e149d0 --- /dev/null +++ b/src/lib/libssl/src/certs/vsign2.pem | |||
@@ -0,0 +1,31 @@ | |||
1 | subject=/L=Internet/O=VeriSign, Inc./OU=VeriSign Class 2 CA - Individual Subscriber | ||
2 | issuer= /L=Internet/O=VeriSign, Inc./OU=VeriSign Class 2 CA - Individual Subscriber | ||
3 | |||
4 | -----BEGIN CERTIFICATE----- | ||
5 | MIIEkzCCA/ygAwIBAgIRANDTUpSRL3nTFeMrMayFSPAwDQYJKoZIhvcNAQECBQAw | ||
6 | YjERMA8GA1UEBxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQw | ||
7 | MgYDVQQLEytWZXJpU2lnbiBDbGFzcyAyIENBIC0gSW5kaXZpZHVhbCBTdWJzY3Jp | ||
8 | YmVyMB4XDTk2MDYwNDAwMDAwMFoXDTk4MDYwNDIzNTk1OVowYjERMA8GA1UEBxMI | ||
9 | SW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJp | ||
10 | U2lnbiBDbGFzcyAyIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyMIGfMA0GCSqG | ||
11 | SIb3DQEBAQUAA4GNADCBiQKBgQC6A+2czKGRcYMfm8gdnk+0de99TDDzsqo0v5nb | ||
12 | RsbUmMcdRQ7nsMbRWe0SAb/9QoLTZ/cJ0iOBqdrkz7UpqqKarVoTSdlSMVM92tWp | ||
13 | 3bJncZHQD1t4xd6lQVdI1/T6R+5J0T1ukOdsI9Jmf+F28S6g3R3L1SFwiHKeZKZv | ||
14 | z+793wIDAQABo4ICRzCCAkMwggIpBgNVHQMBAf8EggIdMIICGTCCAhUwggIRBgtg | ||
15 | hkgBhvhFAQcBATCCAgAWggGrVGhpcyBjZXJ0aWZpY2F0ZSBpbmNvcnBvcmF0ZXMg | ||
16 | YnkgcmVmZXJlbmNlLCBhbmQgaXRzIHVzZSBpcyBzdHJpY3RseSBzdWJqZWN0IHRv | ||
17 | LCB0aGUgVmVyaVNpZ24gQ2VydGlmaWNhdGlvbiBQcmFjdGljZSBTdGF0ZW1lbnQg | ||
18 | KENQUyksIGF2YWlsYWJsZSBhdDogaHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL0NQ | ||
19 | Uy0xLjA7IGJ5IEUtbWFpbCBhdCBDUFMtcmVxdWVzdHNAdmVyaXNpZ24uY29tOyBv | ||
20 | ciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMuLCAyNTkzIENvYXN0IEF2ZS4sIE1v | ||
21 | dW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBUZWwuICsxICg0MTUpIDk2MS04ODMw | ||
22 | IENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2lnbiwgSW5jLiAgQWxsIFJpZ2h0cyBS | ||
23 | ZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVTIERJU0NMQUlNRUQgYW5kIExJQUJJ | ||
24 | TElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcBAQGhDgYMYIZIAYb4RQEHAQECMC8w | ||
25 | LRYraHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEuMDAU | ||
26 | BglghkgBhvhCAQEBAf8EBAMCAgQwDQYJKoZIhvcNAQECBQADgYEApRJRkNBqLLgs | ||
27 | 53IR/d18ODdLOWMTZ+QOOxBrq460iBEdUwgF8vmPRX1ku7UiDeNzaLlurE6eFqHq | ||
28 | 2zPyK5j60zfTLVJMWKcQWwTJLjHtXrW8pxhNtFc6Fdvy5ZkHnC/9NIl7/t4U6WqB | ||
29 | p4y+p7SdMIkEwIZfds0VbnQyX5MRUJY= | ||
30 | -----END CERTIFICATE----- | ||
31 | |||
diff --git a/src/lib/libssl/src/crypto/Makefile.ssl b/src/lib/libssl/src/crypto/Makefile.ssl new file mode 100644 index 0000000000..efdbba38ac --- /dev/null +++ b/src/lib/libssl/src/crypto/Makefile.ssl | |||
@@ -0,0 +1,161 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= crypto | ||
6 | TOP= .. | ||
7 | CC= cc | ||
8 | INCLUDE= -I. -I../include | ||
9 | INCLUDES= -I.. -I../../include | ||
10 | CFLAG= -g | ||
11 | INSTALLTOP= /usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | RM= /bin/rm -f | ||
16 | AR= ar r | ||
17 | |||
18 | MAKE= make -f Makefile.ssl | ||
19 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
20 | MAKEFILE= Makefile.ssl | ||
21 | |||
22 | PEX_LIBS= | ||
23 | EX_LIBS= | ||
24 | |||
25 | CFLAGS= $(INCLUDE) $(CFLAG) -DCFLAGS=" \"$(CC) $(CFLAG)\" " | ||
26 | |||
27 | ERR=crypto | ||
28 | ERRC=cpt_err | ||
29 | |||
30 | LIBS= | ||
31 | |||
32 | SDIRS= md2 md5 sha mdc2 hmac ripemd \ | ||
33 | des rc2 rc4 rc5 idea bf cast \ | ||
34 | bn rsa dsa dh \ | ||
35 | buffer bio stack lhash rand err objects \ | ||
36 | evp pem x509 \ | ||
37 | asn1 conf txt_db pkcs7 | ||
38 | |||
39 | GENERAL=Makefile README | ||
40 | |||
41 | LIB= $(TOP)/libcrypto.a | ||
42 | LIBSRC= cryptlib.c mem.c cversion.c ex_data.c $(ERRC).c | ||
43 | LIBOBJ= cryptlib.o mem.o cversion.o ex_data.o $(ERRC).o | ||
44 | |||
45 | SRC= $(LIBSRC) | ||
46 | |||
47 | EXHEADER= crypto.h cryptall.h | ||
48 | HEADER= cryptlib.h date.h $(EXHEADER) | ||
49 | |||
50 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
51 | |||
52 | top: | ||
53 | @(cd ..; $(MAKE) DIRS=$(DIR) all) | ||
54 | |||
55 | all: date.h lib subdirs | ||
56 | |||
57 | date.h: ../Makefile.ssl ../VERSION | ||
58 | echo "#define DATE \"`date`\"" >date.h | ||
59 | |||
60 | subdirs: | ||
61 | @for i in $(SDIRS) ;\ | ||
62 | do \ | ||
63 | (cd $$i; echo "making all in $$i..."; \ | ||
64 | $(MAKE) CC='$(CC)' INCLUDES='${INCLUDES}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_MULW='${BN_MULW}' DES_ENC='${DES_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' AR='${AR}' all ); \ | ||
65 | done; | ||
66 | |||
67 | files: | ||
68 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
69 | @for i in $(SDIRS) ;\ | ||
70 | do \ | ||
71 | (cd $$i; echo "making 'files' in $$i..."; \ | ||
72 | $(MAKE) files ); \ | ||
73 | done; | ||
74 | |||
75 | links: | ||
76 | /bin/rm -f Makefile | ||
77 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
78 | $(TOP)/util/mklink.sh ../include $(HEADER) ; | ||
79 | $(TOP)/util/mklink.sh ../test $(TEST) ; | ||
80 | $(TOP)/util/mklink.sh ../apps $(APPS) ; | ||
81 | $(TOP)/util/point.sh Makefile.ssl Makefile; | ||
82 | @for i in $(SDIRS) ;\ | ||
83 | do \ | ||
84 | (cd $$i; echo "making links in $$i..."; \ | ||
85 | $(MAKE) links ); \ | ||
86 | done; | ||
87 | |||
88 | lib: $(LIBOBJ) | ||
89 | $(AR) $(LIB) $(LIBOBJ) | ||
90 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
91 | @touch lib | ||
92 | |||
93 | libs: | ||
94 | @for i in $(SDIRS) ;\ | ||
95 | do \ | ||
96 | (cd $$i; echo "making libs in $$i..."; \ | ||
97 | $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' lib ); \ | ||
98 | done; | ||
99 | |||
100 | tests: | ||
101 | @for i in $(SDIRS) ;\ | ||
102 | do \ | ||
103 | (cd $$i; echo "making tests in $$i..."; \ | ||
104 | $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' tests ); \ | ||
105 | done; | ||
106 | |||
107 | install: | ||
108 | @for i in $(EXHEADER) ;\ | ||
109 | do \ | ||
110 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
111 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
112 | done; | ||
113 | @for i in $(SDIRS) ;\ | ||
114 | do \ | ||
115 | (cd $$i; echo "making install in $$i..."; \ | ||
116 | $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' install ); \ | ||
117 | done; | ||
118 | |||
119 | lint: | ||
120 | @for i in $(SDIRS) ;\ | ||
121 | do \ | ||
122 | (cd $$i; echo "making lint in $$i..."; \ | ||
123 | $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' lint ); \ | ||
124 | done; | ||
125 | |||
126 | depend: | ||
127 | $(MAKEDEPEND) $(INCLUDE) $(PROGS) $(LIBSRC) | ||
128 | @for i in $(SDIRS) ;\ | ||
129 | do \ | ||
130 | (cd $$i; echo "making depend in $$i..."; \ | ||
131 | $(MAKE) MAKEFILE='${MAKEFILE}' INCLUDES='${INCLUDES}' MAKEDEPEND='${MAKEDEPEND}' depend ); \ | ||
132 | done; | ||
133 | |||
134 | clean: | ||
135 | /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
136 | @for i in $(SDIRS) ;\ | ||
137 | do \ | ||
138 | (cd $$i; echo "making clean in $$i..."; \ | ||
139 | $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' clean ); \ | ||
140 | done; | ||
141 | |||
142 | dclean: | ||
143 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
144 | mv -f Makefile.new $(MAKEFILE) | ||
145 | @for i in $(SDIRS) ;\ | ||
146 | do \ | ||
147 | (cd $$i; echo "making dclean in $$i..."; \ | ||
148 | $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' dclean ); \ | ||
149 | done; | ||
150 | |||
151 | errors: | ||
152 | perl ./err/err_code.pl -conf err/ssleay.ec *.c */*.c ../ssl/*.c ../rsaref/*.c | ||
153 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
154 | perl err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
155 | @for i in $(SDIRS) ;\ | ||
156 | do \ | ||
157 | (cd $$i; echo "making errors in $$i..."; \ | ||
158 | $(MAKE) errors ); \ | ||
159 | done; | ||
160 | |||
161 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/asn1/Makefile.ssl b/src/lib/libssl/src/crypto/asn1/Makefile.ssl new file mode 100644 index 0000000000..30751bd156 --- /dev/null +++ b/src/lib/libssl/src/crypto/asn1/Makefile.ssl | |||
@@ -0,0 +1,120 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/asn1/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= asn1 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=asn1 | ||
19 | ERRC=asn1_err | ||
20 | GENERAL=Makefile README | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= a_object.c a_bitstr.c a_utctm.c a_int.c a_octet.c a_print.c \ | ||
26 | a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c \ | ||
27 | a_sign.c a_digest.c a_verify.c \ | ||
28 | x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c \ | ||
29 | x_name.c x_cinf.c x_x509.c x_crl.c x_info.c x_spki.c \ | ||
30 | d2i_r_pr.c i2d_r_pr.c d2i_r_pu.c i2d_r_pu.c \ | ||
31 | d2i_s_pr.c i2d_s_pr.c d2i_s_pu.c i2d_s_pu.c \ | ||
32 | d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\ | ||
33 | t_req.c t_x509.c t_pkey.c \ | ||
34 | p7_i_s.c p7_signi.c p7_signd.c p7_recip.c p7_enc_c.c p7_evp.c \ | ||
35 | p7_dgst.c p7_s_e.c p7_enc.c p7_lib.c \ | ||
36 | f_int.c f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c d2i_dsap.c n_pkey.c \ | ||
37 | a_hdr.c x_pkey.c a_bool.c x_exten.c \ | ||
38 | asn1_par.c asn1_lib.c $(ERRC).c a_meth.c a_bytes.c \ | ||
39 | evp_asn1.c | ||
40 | LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_int.o a_octet.o a_print.o \ | ||
41 | a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o \ | ||
42 | a_sign.o a_digest.o a_verify.o \ | ||
43 | x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o \ | ||
44 | x_name.o x_cinf.o x_x509.o x_crl.o x_info.o x_spki.o \ | ||
45 | d2i_r_pr.o i2d_r_pr.o d2i_r_pu.o i2d_r_pu.o \ | ||
46 | d2i_s_pr.o i2d_s_pr.o d2i_s_pu.o i2d_s_pu.o \ | ||
47 | d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \ | ||
48 | t_req.o t_x509.o t_pkey.o \ | ||
49 | p7_i_s.o p7_signi.o p7_signd.o p7_recip.o p7_enc_c.o p7_evp.o \ | ||
50 | p7_dgst.o p7_s_e.o p7_enc.o p7_lib.o \ | ||
51 | f_int.o f_string.o i2d_dhp.o i2d_dsap.o d2i_dhp.o d2i_dsap.o n_pkey.o \ | ||
52 | a_hdr.o x_pkey.o a_bool.o x_exten.o \ | ||
53 | asn1_par.o asn1_lib.o $(ERRC).o a_meth.o a_bytes.o \ | ||
54 | evp_asn1.o | ||
55 | |||
56 | SRC= $(LIBSRC) | ||
57 | |||
58 | EXHEADER= asn1.h asn1_mac.h | ||
59 | HEADER= $(EXHEADER) | ||
60 | |||
61 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
62 | |||
63 | top: | ||
64 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
65 | |||
66 | test: test.c | ||
67 | cc -g -I../../include -c test.c | ||
68 | cc -g -I../../include -o test test.o -L../.. -lcrypto | ||
69 | |||
70 | pk: pk.c | ||
71 | cc -g -I../../include -c pk.c | ||
72 | cc -g -I../../include -o pk pk.o -L../.. -lcrypto | ||
73 | |||
74 | all: lib | ||
75 | |||
76 | lib: $(LIBOBJ) | ||
77 | $(AR) $(LIB) $(LIBOBJ) | ||
78 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
79 | @touch lib | ||
80 | |||
81 | files: | ||
82 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
83 | |||
84 | links: | ||
85 | /bin/rm -f Makefile | ||
86 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
87 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
88 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
89 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
90 | |||
91 | install: | ||
92 | @for i in $(EXHEADER) ; \ | ||
93 | do \ | ||
94 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
95 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
96 | done; | ||
97 | |||
98 | tags: | ||
99 | ctags $(SRC) | ||
100 | |||
101 | tests: | ||
102 | |||
103 | lint: | ||
104 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
105 | |||
106 | depend: | ||
107 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
108 | |||
109 | dclean: | ||
110 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
111 | mv -f Makefile.new $(MAKEFILE) | ||
112 | |||
113 | clean: | ||
114 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
115 | |||
116 | errors: | ||
117 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
118 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
119 | |||
120 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/asn1/f.c b/src/lib/libssl/src/crypto/asn1/f.c new file mode 100644 index 0000000000..2ab3a262ac --- /dev/null +++ b/src/lib/libssl/src/crypto/asn1/f.c | |||
@@ -0,0 +1,80 @@ | |||
1 | /* crypto/asn1/f.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | #include <stdio.h> | ||
59 | #include "asn1.h" | ||
60 | #include "err.h" | ||
61 | |||
62 | main() | ||
63 | { | ||
64 | ASN1_TYPE *at; | ||
65 | char buf[512]; | ||
66 | int n; | ||
67 | long l; | ||
68 | |||
69 | at=ASN1_TYPE_new(); | ||
70 | |||
71 | n=ASN1_TYPE_set_int_octetstring(at,98736,"01234567",8); | ||
72 | printf("%d\n",n); | ||
73 | n=ASN1_TYPE_get_int_octetstring(at,&l,buf,8); | ||
74 | buf[8]='\0'; | ||
75 | printf("%ld %d %d\n",l,n,buf[8]); | ||
76 | buf[8]='\0'; | ||
77 | printf("%s\n",buf); | ||
78 | ERR_load_crypto_strings(); | ||
79 | ERR_print_errors_fp(stderr); | ||
80 | } | ||
diff --git a/src/lib/libssl/src/crypto/asn1/x_cinf.c b/src/lib/libssl/src/crypto/asn1/x_cinf.c new file mode 100644 index 0000000000..4fc2cc9f6e --- /dev/null +++ b/src/lib/libssl/src/crypto/asn1/x_cinf.c | |||
@@ -0,0 +1,197 @@ | |||
1 | /* crypto/asn1/x_cinf.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | |||
63 | /* | ||
64 | * ASN1err(ASN1_F_D2I_X509_CINF,ASN1_R_LENGTH_MISMATCH); | ||
65 | * ASN1err(ASN1_F_X509_CINF_NEW,ASN1_R_LENGTH_MISMATCH); | ||
66 | */ | ||
67 | |||
68 | int i2d_X509_CINF(a,pp) | ||
69 | X509_CINF *a; | ||
70 | unsigned char **pp; | ||
71 | { | ||
72 | int v1=0,v2=0; | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | M_ASN1_I2D_len_EXP_opt(a->version,i2d_ASN1_INTEGER,0,v1); | ||
76 | M_ASN1_I2D_len(a->serialNumber, i2d_ASN1_INTEGER); | ||
77 | M_ASN1_I2D_len(a->signature, i2d_X509_ALGOR); | ||
78 | M_ASN1_I2D_len(a->issuer, i2d_X509_NAME); | ||
79 | M_ASN1_I2D_len(a->validity, i2d_X509_VAL); | ||
80 | M_ASN1_I2D_len(a->subject, i2d_X509_NAME); | ||
81 | M_ASN1_I2D_len(a->key, i2d_X509_PUBKEY); | ||
82 | M_ASN1_I2D_len_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING); | ||
83 | M_ASN1_I2D_len_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING); | ||
84 | M_ASN1_I2D_len_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); | ||
85 | |||
86 | M_ASN1_I2D_seq_total(); | ||
87 | |||
88 | M_ASN1_I2D_put_EXP_opt(a->version,i2d_ASN1_INTEGER,0,v1); | ||
89 | M_ASN1_I2D_put(a->serialNumber, i2d_ASN1_INTEGER); | ||
90 | M_ASN1_I2D_put(a->signature, i2d_X509_ALGOR); | ||
91 | M_ASN1_I2D_put(a->issuer, i2d_X509_NAME); | ||
92 | M_ASN1_I2D_put(a->validity, i2d_X509_VAL); | ||
93 | M_ASN1_I2D_put(a->subject, i2d_X509_NAME); | ||
94 | M_ASN1_I2D_put(a->key, i2d_X509_PUBKEY); | ||
95 | M_ASN1_I2D_put_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING,1); | ||
96 | M_ASN1_I2D_put_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING,2); | ||
97 | M_ASN1_I2D_put_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); | ||
98 | |||
99 | M_ASN1_I2D_finish(); | ||
100 | } | ||
101 | |||
102 | X509_CINF *d2i_X509_CINF(a,pp,length) | ||
103 | X509_CINF **a; | ||
104 | unsigned char **pp; | ||
105 | long length; | ||
106 | { | ||
107 | int ver=0; | ||
108 | M_ASN1_D2I_vars(a,X509_CINF *,X509_CINF_new); | ||
109 | |||
110 | M_ASN1_D2I_Init(); | ||
111 | M_ASN1_D2I_start_sequence(); | ||
112 | /* we have the optional version field */ | ||
113 | if (M_ASN1_next == (V_ASN1_CONTEXT_SPECIFIC | V_ASN1_CONSTRUCTED | 0)) | ||
114 | { | ||
115 | M_ASN1_D2I_get_EXP_opt(ret->version,d2i_ASN1_INTEGER,0); | ||
116 | if (ret->version->data != NULL) | ||
117 | ver=ret->version->data[0]; | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | if (ret->version != NULL) | ||
122 | { | ||
123 | ASN1_INTEGER_free(ret->version); | ||
124 | ret->version=NULL; | ||
125 | } | ||
126 | } | ||
127 | M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER); | ||
128 | M_ASN1_D2I_get(ret->signature,d2i_X509_ALGOR); | ||
129 | M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME); | ||
130 | M_ASN1_D2I_get(ret->validity,d2i_X509_VAL); | ||
131 | M_ASN1_D2I_get(ret->subject,d2i_X509_NAME); | ||
132 | M_ASN1_D2I_get(ret->key,d2i_X509_PUBKEY); | ||
133 | if (ver >= 1) /* version 2 extensions */ | ||
134 | { | ||
135 | if (ret->issuerUID != NULL) | ||
136 | { | ||
137 | ASN1_BIT_STRING_free(ret->issuerUID); | ||
138 | ret->issuerUID=NULL; | ||
139 | } | ||
140 | if (ret->subjectUID != NULL) | ||
141 | { | ||
142 | ASN1_BIT_STRING_free(ret->subjectUID); | ||
143 | ret->issuerUID=NULL; | ||
144 | } | ||
145 | M_ASN1_D2I_get_IMP_opt(ret->issuerUID,d2i_ASN1_BIT_STRING, 1, | ||
146 | V_ASN1_BIT_STRING); | ||
147 | M_ASN1_D2I_get_IMP_opt(ret->subjectUID,d2i_ASN1_BIT_STRING, 2, | ||
148 | V_ASN1_BIT_STRING); | ||
149 | } | ||
150 | if (ver >= 2) /* version 3 extensions */ | ||
151 | { | ||
152 | if (ret->extensions != NULL) | ||
153 | while (sk_num(ret->extensions)) | ||
154 | X509_EXTENSION_free((X509_EXTENSION *) | ||
155 | sk_pop(ret->extensions)); | ||
156 | M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION,3, | ||
157 | V_ASN1_SEQUENCE); | ||
158 | } | ||
159 | M_ASN1_D2I_Finish(a,X509_CINF_free,ASN1_F_D2I_X509_CINF); | ||
160 | } | ||
161 | |||
162 | X509_CINF *X509_CINF_new() | ||
163 | { | ||
164 | X509_CINF *ret=NULL; | ||
165 | |||
166 | M_ASN1_New_Malloc(ret,X509_CINF); | ||
167 | ret->version=NULL; | ||
168 | M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new); | ||
169 | M_ASN1_New(ret->signature,X509_ALGOR_new); | ||
170 | M_ASN1_New(ret->issuer,X509_NAME_new); | ||
171 | M_ASN1_New(ret->validity,X509_VAL_new); | ||
172 | M_ASN1_New(ret->subject,X509_NAME_new); | ||
173 | M_ASN1_New(ret->key,X509_PUBKEY_new); | ||
174 | ret->issuerUID=NULL; | ||
175 | ret->subjectUID=NULL; | ||
176 | ret->extensions=NULL; | ||
177 | return(ret); | ||
178 | M_ASN1_New_Error(ASN1_F_X509_CINF_NEW); | ||
179 | } | ||
180 | |||
181 | void X509_CINF_free(a) | ||
182 | X509_CINF *a; | ||
183 | { | ||
184 | if (a == NULL) return; | ||
185 | ASN1_INTEGER_free(a->version); | ||
186 | ASN1_INTEGER_free(a->serialNumber); | ||
187 | X509_ALGOR_free(a->signature); | ||
188 | X509_NAME_free(a->issuer); | ||
189 | X509_VAL_free(a->validity); | ||
190 | X509_NAME_free(a->subject); | ||
191 | X509_PUBKEY_free(a->key); | ||
192 | ASN1_BIT_STRING_free(a->issuerUID); | ||
193 | ASN1_BIT_STRING_free(a->subjectUID); | ||
194 | sk_pop_free(a->extensions,X509_EXTENSION_free); | ||
195 | Free((char *)a); | ||
196 | } | ||
197 | |||
diff --git a/src/lib/libssl/src/crypto/bf/Makefile.ssl b/src/lib/libssl/src/crypto/bf/Makefile.ssl new file mode 100644 index 0000000000..236671f238 --- /dev/null +++ b/src/lib/libssl/src/crypto/bf/Makefile.ssl | |||
@@ -0,0 +1,107 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/blowfish/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= bf | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | CPP= $(CC) -E | ||
9 | INCLUDES= | ||
10 | CFLAG=-g | ||
11 | INSTALLTOP=/usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | AR= ar r | ||
16 | |||
17 | BF_ENC= bf_enc.o | ||
18 | # or use | ||
19 | #DES_ENC= bx86-elf.o | ||
20 | |||
21 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
22 | |||
23 | GENERAL=Makefile | ||
24 | TEST=bftest.c | ||
25 | APPS= | ||
26 | |||
27 | LIB=$(TOP)/libcrypto.a | ||
28 | LIBSRC=bf_skey.c bf_ecb.c bf_enc.c bf_cfb64.c bf_ofb64.c | ||
29 | LIBOBJ=bf_skey.o bf_ecb.o $(BF_ENC) bf_cfb64.o bf_ofb64.o | ||
30 | |||
31 | SRC= $(LIBSRC) | ||
32 | |||
33 | EXHEADER= blowfish.h | ||
34 | HEADER= bf_pi.h bf_locl.h $(EXHEADER) | ||
35 | |||
36 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
37 | |||
38 | top: | ||
39 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
40 | |||
41 | all: lib | ||
42 | |||
43 | lib: $(LIBOBJ) | ||
44 | $(AR) $(LIB) $(LIBOBJ) | ||
45 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
46 | @touch lib | ||
47 | |||
48 | # elf | ||
49 | asm/bx86-elf.o: asm/bx86unix.cpp | ||
50 | $(CPP) -DELF asm/bx86unix.cpp | as -o asm/bx86-elf.o | ||
51 | |||
52 | # solaris | ||
53 | asm/bx86-sol.o: asm/bx86unix.cpp | ||
54 | $(CC) -E -DSOL asm/bx86unix.cpp | sed 's/^#.*//' > asm/bx86-sol.s | ||
55 | as -o asm/bx86-sol.o asm/bx86-sol.s | ||
56 | rm -f asm/bx86-sol.s | ||
57 | |||
58 | # a.out | ||
59 | asm/bx86-out.o: asm/bx86unix.cpp | ||
60 | $(CPP) -DOUT asm/bx86unix.cpp | as -o asm/bx86-out.o | ||
61 | |||
62 | # bsdi | ||
63 | asm/bx86bsdi.o: asm/bx86unix.cpp | ||
64 | $(CPP) -DBSDI asm/bx86unix.cpp | as -o asm/bx86bsdi.o | ||
65 | |||
66 | asm/bx86unix.cpp: | ||
67 | (cd asm; perl bf-586.pl cpp >bx86unix.cpp) | ||
68 | |||
69 | files: | ||
70 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
71 | |||
72 | links: | ||
73 | /bin/rm -f Makefile | ||
74 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
75 | $(TOP)/util/point.sh ../../doc/blowfish.doc blowfish.doc ; | ||
76 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
77 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
78 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
79 | |||
80 | install: | ||
81 | @for i in $(EXHEADER) ; \ | ||
82 | do \ | ||
83 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
84 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
85 | done; | ||
86 | |||
87 | tags: | ||
88 | ctags $(SRC) | ||
89 | |||
90 | tests: | ||
91 | |||
92 | lint: | ||
93 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
94 | |||
95 | depend: | ||
96 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
97 | |||
98 | dclean: | ||
99 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
100 | mv -f Makefile.new $(MAKEFILE) | ||
101 | |||
102 | clean: | ||
103 | /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
104 | |||
105 | errors: | ||
106 | |||
107 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/bio/Makefile.ssl b/src/lib/libssl/src/crypto/bio/Makefile.ssl new file mode 100644 index 0000000000..42e11e1c94 --- /dev/null +++ b/src/lib/libssl/src/crypto/bio/Makefile.ssl | |||
@@ -0,0 +1,92 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/bio/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= bio | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=bio | ||
19 | ERRC=bio_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= bio_lib.c bio_cb.c $(ERRC).c \ | ||
26 | bss_mem.c bss_null.c bss_fd.c \ | ||
27 | bss_file.c bss_sock.c bss_conn.c \ | ||
28 | bf_null.c bf_buff.c b_print.c b_dump.c \ | ||
29 | b_sock.c bss_acpt.c bf_nbio.c | ||
30 | LIBOBJ= bio_lib.o bio_cb.o $(ERRC).o \ | ||
31 | bss_mem.o bss_null.o bss_fd.o \ | ||
32 | bss_file.o bss_sock.o bss_conn.o \ | ||
33 | bf_null.o bf_buff.o b_print.o b_dump.o \ | ||
34 | b_sock.o bss_acpt.o bf_nbio.o | ||
35 | |||
36 | SRC= $(LIBSRC) | ||
37 | |||
38 | EXHEADER= bio.h bss_file.c | ||
39 | HEADER= $(EXHEADER) | ||
40 | |||
41 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
42 | |||
43 | top: | ||
44 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
45 | |||
46 | all: lib | ||
47 | |||
48 | lib: $(LIBOBJ) | ||
49 | $(AR) $(LIB) $(LIBOBJ) | ||
50 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
51 | @touch lib | ||
52 | |||
53 | files: | ||
54 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
55 | |||
56 | links: | ||
57 | /bin/rm -f Makefile | ||
58 | $(TOP)/util/point.sh Makefile.ssl Makefile; | ||
59 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
60 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
61 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
62 | |||
63 | install: | ||
64 | @for i in $(EXHEADER) bss_file.c ; \ | ||
65 | do \ | ||
66 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
67 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
68 | done; | ||
69 | |||
70 | tags: | ||
71 | ctags $(SRC) | ||
72 | |||
73 | tests: | ||
74 | |||
75 | lint: | ||
76 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
77 | |||
78 | depend: | ||
79 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
80 | |||
81 | dclean: | ||
82 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
83 | mv -f Makefile.new $(MAKEFILE) | ||
84 | |||
85 | clean: | ||
86 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
87 | |||
88 | errors: | ||
89 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
90 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
91 | |||
92 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/bn/Makefile.ssl b/src/lib/libssl/src/crypto/bn/Makefile.ssl new file mode 100644 index 0000000000..9809d26cbc --- /dev/null +++ b/src/lib/libssl/src/crypto/bn/Makefile.ssl | |||
@@ -0,0 +1,133 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/bn/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= bn | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | BN_MULW= bn_mulw.o | ||
17 | # or use | ||
18 | #BN_MULW= bn86-elf.o | ||
19 | |||
20 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
21 | |||
22 | ERR=bn | ||
23 | ERRC=bn_err | ||
24 | GENERAL=Makefile | ||
25 | TEST=bntest.c exptest.c | ||
26 | APPS= | ||
27 | |||
28 | LIB=$(TOP)/libcrypto.a | ||
29 | LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mod.c bn_mul.c \ | ||
30 | bn_print.c bn_rand.c bn_shift.c bn_sub.c bn_word.c bn_blind.c \ | ||
31 | bn_gcd.c bn_prime.c $(ERRC).c bn_sqr.c bn_mulw.c bn_recp.c bn_mont.c \ | ||
32 | bn_mpi.c | ||
33 | |||
34 | LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_mod.o bn_mul.o \ | ||
35 | bn_print.o bn_rand.o bn_shift.o bn_sub.o bn_word.o bn_blind.o \ | ||
36 | bn_gcd.o bn_prime.o $(ERRC).o bn_sqr.o $(BN_MULW) bn_recp.o bn_mont.o \ | ||
37 | bn_mpi.o | ||
38 | |||
39 | |||
40 | SRC= $(LIBSRC) | ||
41 | |||
42 | EXHEADER= bn.h | ||
43 | HEADER= bn_lcl.h bn_prime.h $(EXHEADER) | ||
44 | |||
45 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
46 | |||
47 | top: | ||
48 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
49 | |||
50 | all: lib | ||
51 | |||
52 | knuth: bn_knuth.c | ||
53 | cc -pg -I.. -I../../include bn_knuth.c -o knuth $(LIB) #../../../libefence.a | ||
54 | |||
55 | knuth.fast: bn_knuth.c | ||
56 | cc -pg -fast -I.. -I../../include bn_knuth.c -o knuth $(LIB) #../../../libefence.a | ||
57 | |||
58 | |||
59 | lib: $(LIBOBJ) | ||
60 | $(AR) $(LIB) $(LIBOBJ) | ||
61 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
62 | @touch lib | ||
63 | |||
64 | # elf | ||
65 | asm/bn86-elf.o: asm/bn86unix.cpp | ||
66 | $(CPP) -DELF asm/bn86unix.cpp | as -o asm/bn86-elf.o | ||
67 | |||
68 | # solaris | ||
69 | asm/bn86-sol.o: asm/bn86unix.cpp | ||
70 | $(CC) -E -DSOL asm/bn86unix.cpp | sed 's/^#.*//' > asm/bn86-sol.s | ||
71 | as -o asm/bn86-sol.o asm/bn86-sol.s | ||
72 | rm -f asm/bn86-sol.s | ||
73 | |||
74 | # a.out | ||
75 | asm/bn86-out.o: asm/bn86unix.cpp | ||
76 | $(CPP) -DOUT asm/bn86unix.cpp | as -o asm/bn86-out.o | ||
77 | |||
78 | # bsdi | ||
79 | asm/bn86bsdi.o: asm/bn86unix.cpp | ||
80 | $(CPP) -DBSDI asm/bn86unix.cpp | as -o asm/bn86bsdi.o | ||
81 | |||
82 | asm/bn86unix.cpp: | ||
83 | (cd asm; perl bn-586.pl cpp >bn86unix.cpp ) | ||
84 | |||
85 | files: | ||
86 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
87 | |||
88 | links: | ||
89 | /bin/rm -f Makefile | ||
90 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
91 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
92 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
93 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
94 | |||
95 | install: | ||
96 | @for i in $(EXHEADER) ; \ | ||
97 | do \ | ||
98 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
99 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
100 | done; | ||
101 | |||
102 | exptest: | ||
103 | /bin/rm -f exptest | ||
104 | gcc -I../../include -g2 -ggdb -o exptest exptest.c ../../libcrypto.a | ||
105 | |||
106 | div: | ||
107 | /bin/rm -f a.out | ||
108 | gcc -I.. -g div.c ../../libcrypto.a | ||
109 | |||
110 | tags: | ||
111 | ctags $(SRC) | ||
112 | |||
113 | tests: | ||
114 | |||
115 | lint: | ||
116 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
117 | |||
118 | depend: | ||
119 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
120 | |||
121 | dclean: | ||
122 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
123 | mv -f Makefile.new $(MAKEFILE) | ||
124 | |||
125 | clean: | ||
126 | /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff bn_mulw.s | ||
127 | |||
128 | errors: | ||
129 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).org # special case .org | ||
130 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
131 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
132 | |||
133 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/buffer/Makefile.ssl b/src/lib/libssl/src/crypto/buffer/Makefile.ssl new file mode 100644 index 0000000000..a5f150e523 --- /dev/null +++ b/src/lib/libssl/src/crypto/buffer/Makefile.ssl | |||
@@ -0,0 +1,84 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/buffer/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= buffer | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=buffer | ||
19 | ERRC=buf_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= buffer.c $(ERRC).c | ||
26 | LIBOBJ= buffer.o $(ERRC).o | ||
27 | |||
28 | SRC= $(LIBSRC) | ||
29 | |||
30 | EXHEADER= buffer.h | ||
31 | HEADER= $(EXHEADER) | ||
32 | |||
33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
34 | |||
35 | top: | ||
36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
37 | |||
38 | all: lib | ||
39 | |||
40 | lib: $(LIBOBJ) | ||
41 | $(AR) $(LIB) $(LIBOBJ) | ||
42 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
43 | @touch lib | ||
44 | |||
45 | files: | ||
46 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
47 | |||
48 | links: | ||
49 | /bin/rm -f Makefile | ||
50 | $(TOP)/util/point.sh Makefile.ssl Makefile; | ||
51 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
52 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
53 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
54 | |||
55 | install: | ||
56 | @for i in $(EXHEADER) ; \ | ||
57 | do \ | ||
58 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
59 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
60 | done; | ||
61 | |||
62 | tags: | ||
63 | ctags $(SRC) | ||
64 | |||
65 | tests: | ||
66 | |||
67 | lint: | ||
68 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
69 | |||
70 | depend: | ||
71 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
72 | |||
73 | dclean: | ||
74 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
75 | mv -f Makefile.new $(MAKEFILE) | ||
76 | |||
77 | clean: | ||
78 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
79 | |||
80 | errors: | ||
81 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
82 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
83 | |||
84 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/cast/Makefile.ssl b/src/lib/libssl/src/crypto/cast/Makefile.ssl new file mode 100644 index 0000000000..0143827ae5 --- /dev/null +++ b/src/lib/libssl/src/crypto/cast/Makefile.ssl | |||
@@ -0,0 +1,109 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/cast/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= cast | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | CPP= $(CC) -E | ||
9 | INCLUDES= | ||
10 | CFLAG=-g | ||
11 | INSTALLTOP=/usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | AR= ar r | ||
16 | |||
17 | CAST_ENC=c_enc.o | ||
18 | # or use | ||
19 | #CAST_ENC=asm/cx86-elf.o | ||
20 | #CAST_ENC=asm/cx86-out.o | ||
21 | #CAST_ENC=asm/cx86-sol.o | ||
22 | #CAST_ENC=asm/cx86bdsi.o | ||
23 | |||
24 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
25 | |||
26 | GENERAL=Makefile | ||
27 | TEST=casttest.c | ||
28 | APPS= | ||
29 | |||
30 | LIB=$(TOP)/libcrypto.a | ||
31 | LIBSRC=c_skey.c c_ecb.c c_enc.c c_cfb64.c c_ofb64.c | ||
32 | LIBOBJ=c_skey.o c_ecb.o $(CAST_ENC) c_cfb64.o c_ofb64.o | ||
33 | |||
34 | SRC= $(LIBSRC) | ||
35 | |||
36 | EXHEADER= cast.h | ||
37 | HEADER= cast_s.h cast_lcl.h $(EXHEADER) | ||
38 | |||
39 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
40 | |||
41 | top: | ||
42 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
43 | |||
44 | all: lib | ||
45 | |||
46 | lib: $(LIBOBJ) | ||
47 | $(AR) $(LIB) $(LIBOBJ) | ||
48 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
49 | @touch lib | ||
50 | |||
51 | # elf | ||
52 | asm/cx86-elf.o: asm/cx86unix.cpp | ||
53 | $(CPP) -DELF asm/cx86unix.cpp | as -o asm/cx86-elf.o | ||
54 | |||
55 | # solaris | ||
56 | asm/cx86-sol.o: asm/cx86unix.cpp | ||
57 | $(CC) -E -DSOL asm/cx86unix.cpp | sed 's/^#.*//' > asm/cx86-sol.s | ||
58 | as -o asm/cx86-sol.o asm/cx86-sol.s | ||
59 | rm -f asm/cx86-sol.s | ||
60 | |||
61 | # a.out | ||
62 | asm/cx86-out.o: asm/cx86unix.cpp | ||
63 | $(CPP) -DOUT asm/cx86unix.cpp | as -o asm/cx86-out.o | ||
64 | |||
65 | # bsdi | ||
66 | asm/cx86bsdi.o: asm/cx86unix.cpp | ||
67 | $(CPP) -DBSDI asm/cx86unix.cpp | as -o asm/cx86bsdi.o | ||
68 | |||
69 | asm/cx86unix.cpp: | ||
70 | (cd asm; perl cast-586.pl cpp >cx86unix.cpp) | ||
71 | |||
72 | files: | ||
73 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
74 | |||
75 | links: | ||
76 | /bin/rm -f Makefile | ||
77 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
78 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
79 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
80 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
81 | |||
82 | install: | ||
83 | @for i in $(EXHEADER) ; \ | ||
84 | do \ | ||
85 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
86 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
87 | done; | ||
88 | |||
89 | tags: | ||
90 | ctags $(SRC) | ||
91 | |||
92 | tests: | ||
93 | |||
94 | lint: | ||
95 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
96 | |||
97 | depend: | ||
98 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
99 | |||
100 | dclean: | ||
101 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
102 | mv -f Makefile.new $(MAKEFILE) | ||
103 | |||
104 | clean: | ||
105 | /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
106 | |||
107 | errors: | ||
108 | |||
109 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/conf/Makefile.ssl b/src/lib/libssl/src/crypto/conf/Makefile.ssl new file mode 100644 index 0000000000..00e917aa44 --- /dev/null +++ b/src/lib/libssl/src/crypto/conf/Makefile.ssl | |||
@@ -0,0 +1,85 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/conf/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= conf | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=conf | ||
19 | ERRC=conf_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= conf.c $(ERRC).c | ||
26 | |||
27 | LIBOBJ= conf.o $(ERRC).o | ||
28 | |||
29 | SRC= $(LIBSRC) | ||
30 | |||
31 | EXHEADER= conf.h | ||
32 | HEADER= conf_lcl.h $(EXHEADER) | ||
33 | |||
34 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
35 | |||
36 | top: | ||
37 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
38 | |||
39 | all: lib | ||
40 | |||
41 | lib: $(LIBOBJ) | ||
42 | $(AR) $(LIB) $(LIBOBJ) | ||
43 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
44 | @touch lib | ||
45 | |||
46 | files: | ||
47 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
48 | |||
49 | links: | ||
50 | /bin/rm -f Makefile | ||
51 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
52 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
53 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
54 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
55 | |||
56 | install: | ||
57 | @for i in $(EXHEADER) ; \ | ||
58 | do \ | ||
59 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
60 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
61 | done; | ||
62 | |||
63 | tags: | ||
64 | ctags $(SRC) | ||
65 | |||
66 | tests: | ||
67 | |||
68 | lint: | ||
69 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
70 | |||
71 | depend: | ||
72 | $(MAKEDEPEND) $(INCLUDES) $(LIBSRC) | ||
73 | |||
74 | dclean: | ||
75 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
76 | mv -f Makefile.new $(MAKEFILE) | ||
77 | |||
78 | clean: | ||
79 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
80 | |||
81 | errors: | ||
82 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
83 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
84 | |||
85 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/des/FILES b/src/lib/libssl/src/crypto/des/FILES new file mode 100644 index 0000000000..4c7ea2de7a --- /dev/null +++ b/src/lib/libssl/src/crypto/des/FILES | |||
@@ -0,0 +1,96 @@ | |||
1 | /* General stuff */ | ||
2 | COPYRIGHT - Copyright info. | ||
3 | MODES.DES - A description of the features of the different modes of DES. | ||
4 | FILES - This file. | ||
5 | INSTALL - How to make things compile. | ||
6 | Imakefile - For use with kerberos. | ||
7 | README - What this package is. | ||
8 | VERSION - Which version this is and what was changed. | ||
9 | KERBEROS - Kerberos version 4 notes. | ||
10 | Makefile.PL - An old makefile to build with perl5, not current. | ||
11 | Makefile.ssl - The SSLeay makefile | ||
12 | Makefile.uni - The normal unix makefile. | ||
13 | GNUmakefile - The makefile for use with glibc. | ||
14 | makefile.bc - A Borland C makefile | ||
15 | times - Some outputs from 'speed' on some machines. | ||
16 | vms.com - For use when compiling under VMS | ||
17 | |||
18 | /* My SunOS des(1) replacement */ | ||
19 | des.c - des(1) source code. | ||
20 | des.man - des(1) manual. | ||
21 | |||
22 | /* Testing and timing programs. */ | ||
23 | destest.c - Source for libdes.a test program. | ||
24 | speed.c - Source for libdes.a timing program. | ||
25 | rpw.c - Source for libdes.a testing password reading routines. | ||
26 | |||
27 | /* libdes.a source code */ | ||
28 | des_crypt.man - libdes.a manual page. | ||
29 | des.h - Public libdes.a header file. | ||
30 | ecb_enc.c - des_ecb_encrypt() source, this contains the basic DES code. | ||
31 | ecb3_enc.c - des_ecb3_encrypt() source. | ||
32 | cbc_ckm.c - des_cbc_cksum() source. | ||
33 | cbc_enc.c - des_cbc_encrypt() source. | ||
34 | ncbc_enc.c - des_cbc_encrypt() that is 'normal' in that it copies | ||
35 | the new iv values back in the passed iv vector. | ||
36 | ede_enc.c - des_ede3_cbc_encrypt() cbc mode des using triple DES. | ||
37 | cbc3_enc.c - des_3cbc_encrypt() source, don't use this function. | ||
38 | cfb_enc.c - des_cfb_encrypt() source. | ||
39 | cfb64enc.c - des_cfb64_encrypt() cfb in 64 bit mode but setup to be | ||
40 | used as a stream cipher. | ||
41 | cfb64ede.c - des_ede3_cfb64_encrypt() cfb in 64 bit mode but setup to be | ||
42 | used as a stream cipher and using triple DES. | ||
43 | ofb_enc.c - des_cfb_encrypt() source. | ||
44 | ofb64_enc.c - des_ofb_encrypt() ofb in 64 bit mode but setup to be | ||
45 | used as a stream cipher. | ||
46 | ofb64ede.c - des_ede3_ofb64_encrypt() ofb in 64 bit mode but setup to be | ||
47 | used as a stream cipher and using triple DES. | ||
48 | enc_read.c - des_enc_read() source. | ||
49 | enc_writ.c - des_enc_write() source. | ||
50 | pcbc_enc.c - des_pcbc_encrypt() source. | ||
51 | qud_cksm.c - quad_cksum() source. | ||
52 | rand_key.c - des_random_key() source. | ||
53 | read_pwd.c - Source for des_read_password() plus related functions. | ||
54 | set_key.c - Source for des_set_key(). | ||
55 | str2key.c - Covert a string of any length into a key. | ||
56 | fcrypt.c - A small, fast version of crypt(3). | ||
57 | des_locl.h - Internal libdes.a header file. | ||
58 | podd.h - Odd parity tables - used in des_set_key(). | ||
59 | sk.h - Lookup tables used in des_set_key(). | ||
60 | spr.h - What is left of the S tables - used in ecb_encrypt(). | ||
61 | des_ver.h - header file for the external definition of the | ||
62 | version string. | ||
63 | des.doc - SSLeay documentation for the library. | ||
64 | |||
65 | /* The perl scripts - you can ignore these files they are only | ||
66 | * included for the curious */ | ||
67 | des.pl - des in perl anyone? des_set_key and des_ecb_encrypt | ||
68 | both done in a perl library. | ||
69 | testdes.pl - Testing program for des.pl | ||
70 | doIP - Perl script used to develop IP xor/shift code. | ||
71 | doPC1 - Perl script used to develop PC1 xor/shift code. | ||
72 | doPC2 - Generates sk.h. | ||
73 | PC1 - Output of doPC1 should be the same as output from PC1. | ||
74 | PC2 - used in development of doPC2. | ||
75 | shifts.pl - Perl library used by my perl scripts. | ||
76 | |||
77 | /* I started making a perl5 dynamic library for libdes | ||
78 | * but did not fully finish, these files are part of that effort. */ | ||
79 | DES.pm | ||
80 | DES.pod | ||
81 | DES.xs | ||
82 | t | ||
83 | typemap | ||
84 | |||
85 | /* The following are for use with sun RPC implementaions. */ | ||
86 | rpc_des.h | ||
87 | rpc_enc.c | ||
88 | |||
89 | /* The following are contibuted by Mark Murray <mark@grondar.za>. They | ||
90 | * are not normally built into libdes due to machine specific routines | ||
91 | * contained in them. They are for use in the most recent incarnation of | ||
92 | * export kerberos v 4 (eBones). */ | ||
93 | supp.c | ||
94 | new_rkey.c | ||
95 | |||
96 | |||
diff --git a/src/lib/libssl/src/crypto/des/Makefile.ssl b/src/lib/libssl/src/crypto/des/Makefile.ssl new file mode 100644 index 0000000000..78b5189ee3 --- /dev/null +++ b/src/lib/libssl/src/crypto/des/Makefile.ssl | |||
@@ -0,0 +1,140 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/des/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= des | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | CPP= $(CC) -E | ||
9 | INCLUDES= | ||
10 | CFLAG=-g | ||
11 | INSTALLTOP=/usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | AR= ar r | ||
16 | DES_ENC= des_enc.o fcrypt_b.o | ||
17 | # or use | ||
18 | #DES_ENC= dx86-elf.o yx86-elf.o | ||
19 | |||
20 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
21 | |||
22 | GENERAL=Makefile des.org des_locl.org | ||
23 | TEST=destest.c | ||
24 | APPS= | ||
25 | |||
26 | LIB=$(TOP)/libcrypto.a | ||
27 | LIBSRC= cbc_cksm.c cbc_enc.c cfb64enc.c cfb_enc.c \ | ||
28 | ecb3_enc.c ecb_enc.c enc_read.c enc_writ.c \ | ||
29 | fcrypt.c ofb64enc.c ofb_enc.c pcbc_enc.c \ | ||
30 | qud_cksm.c rand_key.c read_pwd.c rpc_enc.c set_key.c \ | ||
31 | des_enc.c fcrypt_b.c read2pwd.c \ | ||
32 | fcrypt.c xcbc_enc.c \ | ||
33 | str2key.c cfb64ede.c ofb64ede.c supp.c | ||
34 | |||
35 | LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \ | ||
36 | ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \ | ||
37 | enc_read.o enc_writ.o ofb64enc.o \ | ||
38 | ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \ | ||
39 | ${DES_ENC} read2pwd.o \ | ||
40 | fcrypt.o xcbc_enc.o read_pwd.o rpc_enc.o cbc_cksm.o supp.o | ||
41 | |||
42 | SRC= $(LIBSRC) | ||
43 | |||
44 | EXHEADER= des.h | ||
45 | HEADER= des_locl.h rpc_des.h podd.h sk.h spr.h des_ver.h $(EXHEADER) | ||
46 | |||
47 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
48 | |||
49 | top: | ||
50 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
51 | |||
52 | all: lib | ||
53 | |||
54 | lib: $(LIBOBJ) | ||
55 | $(AR) $(LIB) $(LIBOBJ) | ||
56 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
57 | @touch lib | ||
58 | |||
59 | # elf | ||
60 | asm/dx86-elf.o: asm/dx86unix.cpp | ||
61 | $(CPP) -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o | ||
62 | |||
63 | asm/yx86-elf.o: asm/yx86unix.cpp | ||
64 | $(CPP) -DELF asm/yx86unix.cpp | as -o asm/yx86-elf.o | ||
65 | |||
66 | # solaris | ||
67 | asm/dx86-sol.o: asm/dx86unix.cpp | ||
68 | $(CC) -E -DSOL asm/dx86unix.cpp | sed 's/^#.*//' > asm/dx86-sol.s | ||
69 | as -o asm/dx86-sol.o asm/dx86-sol.s | ||
70 | rm -f asm/dx86-sol.s | ||
71 | |||
72 | asm/yx86-sol.o: asm/yx86unix.cpp | ||
73 | $(CC) -E -DSOL asm/yx86unix.cpp | sed 's/^#.*//' > asm/yx86-sol.s | ||
74 | as -o asm/yx86-sol.o asm/yx86-sol.s | ||
75 | rm -f asm/yx86-sol.s | ||
76 | |||
77 | # a.out | ||
78 | asm/dx86-out.o: asm/dx86unix.cpp | ||
79 | $(CPP) -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o | ||
80 | |||
81 | asm/yx86-out.o: asm/yx86unix.cpp | ||
82 | $(CPP) -DOUT asm/yx86unix.cpp | as -o asm/yx86-out.o | ||
83 | |||
84 | # bsdi | ||
85 | asm/dx86bsdi.o: asm/dx86unix.cpp | ||
86 | $(CPP) -DBSDI asm/dx86unix.cpp | as -o asm/dx86bsdi.o | ||
87 | |||
88 | asm/yx86bsdi.o: asm/yx86unix.cpp | ||
89 | $(CPP) -DBSDI asm/yx86unix.cpp | as -o asm/yx86bsdi.o | ||
90 | |||
91 | asm/dx86unix.cpp: | ||
92 | (cd asm; perl des-586.pl cpp >dx86unix.cpp) | ||
93 | |||
94 | asm/yx86unix.cpp: | ||
95 | (cd asm; perl crypt586.pl cpp >yx86unix.cpp) | ||
96 | |||
97 | files: | ||
98 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
99 | |||
100 | links: | ||
101 | /bin/rm -f Makefile | ||
102 | $(TOP)/util/point.sh Makefile.ssl Makefile | ||
103 | /bin/rm -f des.doc | ||
104 | /bin/rm -fr asm/perlasm | ||
105 | $(TOP)/util/point.sh ../../perlasm asm/perlasm | ||
106 | $(TOP)/util/point.sh ../../doc/des.doc des.doc | ||
107 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
108 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
109 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
110 | |||
111 | install: installs | ||
112 | |||
113 | installs: | ||
114 | @for i in $(EXHEADER) ; \ | ||
115 | do \ | ||
116 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
117 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
118 | done; | ||
119 | |||
120 | tags: | ||
121 | ctags $(SRC) | ||
122 | |||
123 | tests: | ||
124 | |||
125 | lint: | ||
126 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
127 | |||
128 | depend: | ||
129 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
130 | |||
131 | dclean: | ||
132 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
133 | mv -f Makefile.new $(MAKEFILE) | ||
134 | |||
135 | clean: | ||
136 | /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
137 | |||
138 | errors: | ||
139 | |||
140 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/dh/Makefile.ssl b/src/lib/libssl/src/crypto/dh/Makefile.ssl new file mode 100644 index 0000000000..dfa7e4525d --- /dev/null +++ b/src/lib/libssl/src/crypto/dh/Makefile.ssl | |||
@@ -0,0 +1,84 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/dh/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= dh | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=dh | ||
19 | ERRC=dh_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= dhtest.c | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= dh_gen.c dh_key.c dh_lib.c dh_check.c $(ERRC).c | ||
26 | LIBOBJ= dh_gen.o dh_key.o dh_lib.o dh_check.o $(ERRC).o | ||
27 | |||
28 | SRC= $(LIBSRC) | ||
29 | |||
30 | EXHEADER= dh.h | ||
31 | HEADER= $(EXHEADER) | ||
32 | |||
33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
34 | |||
35 | top: | ||
36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
37 | |||
38 | all: lib | ||
39 | |||
40 | lib: $(LIBOBJ) | ||
41 | $(AR) $(LIB) $(LIBOBJ) | ||
42 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
43 | @touch lib | ||
44 | |||
45 | files: | ||
46 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
47 | |||
48 | links: | ||
49 | /bin/rm -f Makefile | ||
50 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
51 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
52 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
53 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
54 | |||
55 | install: | ||
56 | @for i in $(EXHEADER) ; \ | ||
57 | do \ | ||
58 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
59 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
60 | done; | ||
61 | |||
62 | tags: | ||
63 | ctags $(SRC) | ||
64 | |||
65 | tests: | ||
66 | |||
67 | lint: | ||
68 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
69 | |||
70 | depend: | ||
71 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
72 | |||
73 | dclean: | ||
74 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
75 | mv -f Makefile.new $(MAKEFILE) | ||
76 | |||
77 | clean: | ||
78 | /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
79 | |||
80 | errors: | ||
81 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
82 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
83 | |||
84 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/dsa/Makefile.ssl b/src/lib/libssl/src/crypto/dsa/Makefile.ssl new file mode 100644 index 0000000000..2cc4ddb39e --- /dev/null +++ b/src/lib/libssl/src/crypto/dsa/Makefile.ssl | |||
@@ -0,0 +1,84 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/dsa/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= dsa | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=dsa | ||
19 | ERRC=dsa_err | ||
20 | GENERAL=Makefile | ||
21 | TEST=dsatest.c | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_vrf.c dsa_sign.c $(ERRC).c | ||
26 | LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_vrf.o dsa_sign.o $(ERRC).o | ||
27 | |||
28 | SRC= $(LIBSRC) | ||
29 | |||
30 | EXHEADER= dsa.h | ||
31 | HEADER= $(EXHEADER) | ||
32 | |||
33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
34 | |||
35 | top: | ||
36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
37 | |||
38 | all: lib | ||
39 | |||
40 | lib: $(LIBOBJ) | ||
41 | $(AR) $(LIB) $(LIBOBJ) | ||
42 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
43 | @touch lib | ||
44 | |||
45 | files: | ||
46 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
47 | |||
48 | links: | ||
49 | /bin/rm -f Makefile | ||
50 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
51 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
52 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
53 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
54 | |||
55 | install: | ||
56 | @for i in $(EXHEADER) ; \ | ||
57 | do \ | ||
58 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
59 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
60 | done; | ||
61 | |||
62 | tags: | ||
63 | ctags $(SRC) | ||
64 | |||
65 | tests: | ||
66 | |||
67 | lint: | ||
68 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
69 | |||
70 | depend: | ||
71 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
72 | |||
73 | dclean: | ||
74 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
75 | mv -f Makefile.new $(MAKEFILE) | ||
76 | |||
77 | clean: | ||
78 | /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
79 | |||
80 | errors: | ||
81 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
82 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
83 | |||
84 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/err/Makefile.ssl b/src/lib/libssl/src/crypto/err/Makefile.ssl new file mode 100644 index 0000000000..57c87eb041 --- /dev/null +++ b/src/lib/libssl/src/crypto/err/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/err/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= err | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST= | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=err.c err_all.c err_prn.c | ||
24 | LIBOBJ=err.o err_all.o err_prn.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= err.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/evp/Makefile.ssl b/src/lib/libssl/src/crypto/evp/Makefile.ssl new file mode 100644 index 0000000000..8bf2516458 --- /dev/null +++ b/src/lib/libssl/src/crypto/evp/Makefile.ssl | |||
@@ -0,0 +1,111 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/evp/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= evp | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=evp | ||
19 | ERRC=evp_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= encode.c digest.c evp_enc.c evp_key.c \ | ||
26 | e_ecb_d.c e_cbc_d.c e_cfb_d.c e_ofb_d.c \ | ||
27 | e_ecb_i.c e_cbc_i.c e_cfb_i.c e_ofb_i.c \ | ||
28 | e_ecb_3d.c e_cbc_3d.c e_rc4.c names.c \ | ||
29 | e_cfb_3d.c e_ofb_3d.c e_xcbc_d.c \ | ||
30 | e_ecb_r2.c e_cbc_r2.c e_cfb_r2.c e_ofb_r2.c \ | ||
31 | e_ecb_bf.c e_cbc_bf.c e_cfb_bf.c e_ofb_bf.c \ | ||
32 | e_ecb_c.c e_cbc_c.c e_cfb_c.c e_ofb_c.c \ | ||
33 | e_ecb_r5.c e_cbc_r5.c e_cfb_r5.c e_ofb_r5.c \ | ||
34 | m_null.c m_md2.c m_md5.c m_sha.c m_sha1.c m_dss.c m_dss1.c m_mdc2.c \ | ||
35 | m_ripemd.c \ | ||
36 | p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \ | ||
37 | bio_md.c bio_b64.c bio_enc.c $(ERRC).c e_null.c \ | ||
38 | c_all.c evp_lib.c | ||
39 | |||
40 | LIBOBJ= encode.o digest.o evp_enc.o evp_key.o \ | ||
41 | e_ecb_d.o e_cbc_d.o e_cfb_d.o e_ofb_d.o \ | ||
42 | e_ecb_i.o e_cbc_i.o e_cfb_i.o e_ofb_i.o \ | ||
43 | e_ecb_3d.o e_cbc_3d.o e_rc4.o names.o \ | ||
44 | e_cfb_3d.o e_ofb_3d.o e_xcbc_d.o \ | ||
45 | e_ecb_r2.o e_cbc_r2.o e_cfb_r2.o e_ofb_r2.o \ | ||
46 | e_ecb_bf.o e_cbc_bf.o e_cfb_bf.o e_ofb_bf.o \ | ||
47 | e_ecb_c.o e_cbc_c.o e_cfb_c.o e_ofb_c.o \ | ||
48 | e_ecb_r5.o e_cbc_r5.o e_cfb_r5.o e_ofb_r5.o \ | ||
49 | m_null.o m_md2.o m_md5.o m_sha.o m_sha1.o m_dss.o m_dss1.o m_mdc2.o \ | ||
50 | m_ripemd.o \ | ||
51 | p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \ | ||
52 | bio_md.o bio_b64.o bio_enc.o $(ERRC).o e_null.o \ | ||
53 | c_all.o evp_lib.o | ||
54 | |||
55 | SRC= $(LIBSRC) | ||
56 | |||
57 | EXHEADER= evp.h | ||
58 | HEADER= $(EXHEADER) | ||
59 | |||
60 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
61 | |||
62 | top: | ||
63 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
64 | |||
65 | all: lib | ||
66 | |||
67 | lib: $(LIBOBJ) | ||
68 | $(AR) $(LIB) $(LIBOBJ) | ||
69 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
70 | @touch lib | ||
71 | |||
72 | files: | ||
73 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
74 | |||
75 | links: | ||
76 | /bin/rm -f Makefile | ||
77 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
78 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
79 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
80 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
81 | |||
82 | install: | ||
83 | @for i in $(EXHEADER) ; \ | ||
84 | do \ | ||
85 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
86 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
87 | done; | ||
88 | |||
89 | tags: | ||
90 | ctags $(SRC) | ||
91 | |||
92 | tests: | ||
93 | |||
94 | lint: | ||
95 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
96 | |||
97 | depend: | ||
98 | $(MAKEDEPEND) $(INCLUDES) $(LIBSRC) | ||
99 | |||
100 | dclean: | ||
101 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
102 | mv -f Makefile.new $(MAKEFILE) | ||
103 | |||
104 | clean: | ||
105 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
106 | |||
107 | errors: | ||
108 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
109 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
110 | |||
111 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/hmac/Makefile.ssl b/src/lib/libssl/src/crypto/hmac/Makefile.ssl new file mode 100644 index 0000000000..7a042b7261 --- /dev/null +++ b/src/lib/libssl/src/crypto/hmac/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/md/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= hmac | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST=hmactest.c | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=hmac.c | ||
24 | LIBOBJ=hmac.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= hmac.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/idea/Makefile.ssl b/src/lib/libssl/src/crypto/idea/Makefile.ssl new file mode 100644 index 0000000000..41b42ce03b --- /dev/null +++ b/src/lib/libssl/src/crypto/idea/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/idea/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= idea | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST=ideatest.c | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=i_cbc.c i_cfb64.c i_ofb64.c i_ecb.c i_skey.c | ||
24 | LIBOBJ=i_cbc.o i_cfb64.o i_ofb64.o i_ecb.o i_skey.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= idea.h | ||
29 | HEADER= idea_lcl.h $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/lhash/Makefile.ssl b/src/lib/libssl/src/crypto/lhash/Makefile.ssl new file mode 100644 index 0000000000..cb08547b4f --- /dev/null +++ b/src/lib/libssl/src/crypto/lhash/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/lhash/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= lhash | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST= | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=lhash.c lh_stats.c | ||
24 | LIBOBJ=lhash.o lh_stats.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= lhash.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/md2/Makefile.ssl b/src/lib/libssl/src/crypto/md2/Makefile.ssl new file mode 100644 index 0000000000..d8e7200c83 --- /dev/null +++ b/src/lib/libssl/src/crypto/md2/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/md/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= md | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST=md2test.c | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=md2_dgst.c md5_one.c | ||
24 | LIBOBJ=md2_dgst.o md2_one.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= md2.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/md5/Makefile.ssl b/src/lib/libssl/src/crypto/md5/Makefile.ssl new file mode 100644 index 0000000000..47e1ce05ca --- /dev/null +++ b/src/lib/libssl/src/crypto/md5/Makefile.ssl | |||
@@ -0,0 +1,104 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/md5/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= md5 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | CPP= $(CC) -E | ||
9 | INCLUDES= | ||
10 | CFLAG=-g | ||
11 | INSTALLTOP=/usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | AR= ar r | ||
16 | |||
17 | MD5_ASM_OBJ= | ||
18 | |||
19 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
20 | |||
21 | GENERAL=Makefile | ||
22 | TEST=md5test.c | ||
23 | APPS=md5.c | ||
24 | |||
25 | LIB=$(TOP)/libcrypto.a | ||
26 | LIBSRC=md5_dgst.c md5_one.c | ||
27 | LIBOBJ=md5_dgst.o md5_one.o $(MD5_ASM_OBJ) | ||
28 | |||
29 | SRC= $(LIBSRC) | ||
30 | |||
31 | EXHEADER= md5.h | ||
32 | HEADER= md5_locl.h $(EXHEADER) | ||
33 | |||
34 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
35 | |||
36 | top: | ||
37 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
38 | |||
39 | all: lib | ||
40 | |||
41 | lib: $(LIBOBJ) | ||
42 | $(AR) $(LIB) $(LIBOBJ) | ||
43 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
44 | @touch lib | ||
45 | |||
46 | # elf | ||
47 | asm/mx86-elf.o: asm/mx86unix.cpp | ||
48 | $(CPP) -DELF asm/mx86unix.cpp | as -o asm/mx86-elf.o | ||
49 | |||
50 | # solaris | ||
51 | asm/mx86-sol.o: asm/mx86unix.cpp | ||
52 | $(CC) -E -DSOL asm/mx86unix.cpp | sed 's/^#.*//' > asm/mx86-sol.s | ||
53 | as -o asm/mx86-sol.o asm/mx86-sol.s | ||
54 | rm -f asm/mx86-sol.s | ||
55 | |||
56 | # a.out | ||
57 | asm/mx86-out.o: asm/mx86unix.cpp | ||
58 | $(CPP) -DOUT asm/mx86unix.cpp | as -o asm/mx86-out.o | ||
59 | |||
60 | # bsdi | ||
61 | asm/mx86bsdi.o: asm/mx86unix.cpp | ||
62 | $(CPP) -DBSDI asm/mx86unix.cpp | as -o asm/mx86bsdi.o | ||
63 | |||
64 | asm/mx86unix.cpp: | ||
65 | (cd asm; perl md5-586.pl cpp >mx86unix.cpp) | ||
66 | |||
67 | files: | ||
68 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
69 | |||
70 | links: | ||
71 | /bin/rm -f Makefile | ||
72 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
73 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
74 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
75 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
76 | |||
77 | install: | ||
78 | @for i in $(EXHEADER) ; \ | ||
79 | do \ | ||
80 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
81 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
82 | done; | ||
83 | |||
84 | tags: | ||
85 | ctags $(SRC) | ||
86 | |||
87 | tests: | ||
88 | |||
89 | lint: | ||
90 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
91 | |||
92 | depend: | ||
93 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
94 | |||
95 | dclean: | ||
96 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
97 | mv -f Makefile.new $(MAKEFILE) | ||
98 | |||
99 | clean: | ||
100 | /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
101 | |||
102 | errors: | ||
103 | |||
104 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/mdc2/Makefile.ssl b/src/lib/libssl/src/crypto/mdc2/Makefile.ssl new file mode 100644 index 0000000000..495a2789a0 --- /dev/null +++ b/src/lib/libssl/src/crypto/mdc2/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/mdc2/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= mdc2 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST= mdc2test.c | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=mdc2dgst.c mdc2_one.c | ||
24 | LIBOBJ=mdc2dgst.o mdc2_one.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= mdc2.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/objects/Makefile.ssl b/src/lib/libssl/src/crypto/objects/Makefile.ssl new file mode 100644 index 0000000000..320523cea1 --- /dev/null +++ b/src/lib/libssl/src/crypto/objects/Makefile.ssl | |||
@@ -0,0 +1,87 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/objects/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= objects | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=objects | ||
19 | ERRC=obj_err | ||
20 | GENERAL=Makefile README | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= obj_dat.c obj_lib.c $(ERRC).c | ||
26 | LIBOBJ= obj_dat.o obj_lib.o $(ERRC).o | ||
27 | |||
28 | SRC= $(LIBSRC) | ||
29 | |||
30 | EXHEADER= objects.h | ||
31 | HEADER= $(EXHEADER) obj_dat.h | ||
32 | |||
33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
34 | |||
35 | top: | ||
36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
37 | |||
38 | all: obj_dat.h lib | ||
39 | |||
40 | obj_dat.h: objects.h obj_dat.pl | ||
41 | perl ./obj_dat.pl < objects.h > obj_dat.h | ||
42 | |||
43 | lib: $(LIBOBJ) | ||
44 | $(AR) $(LIB) $(LIBOBJ) | ||
45 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
46 | @touch lib | ||
47 | |||
48 | files: | ||
49 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
50 | |||
51 | links: | ||
52 | /bin/rm -f Makefile | ||
53 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
54 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
55 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
56 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
57 | |||
58 | install: | ||
59 | @for i in $(EXHEADER) ; \ | ||
60 | do \ | ||
61 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
62 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
63 | done; | ||
64 | |||
65 | tags: | ||
66 | ctags $(SRC) | ||
67 | |||
68 | tests: | ||
69 | |||
70 | lint: | ||
71 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
72 | |||
73 | depend: | ||
74 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
75 | |||
76 | dclean: | ||
77 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
78 | mv -f Makefile.new $(MAKEFILE) | ||
79 | |||
80 | clean: | ||
81 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
82 | |||
83 | errors: | ||
84 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
85 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
86 | |||
87 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/pem/Makefile.ssl b/src/lib/libssl/src/crypto/pem/Makefile.ssl new file mode 100644 index 0000000000..fc04a88fd9 --- /dev/null +++ b/src/lib/libssl/src/crypto/pem/Makefile.ssl | |||
@@ -0,0 +1,96 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/pem/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= pem | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=pem | ||
19 | ERRC=pem_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | CTX_SIZE= ctx_size | ||
25 | |||
26 | LIB=$(TOP)/libcrypto.a | ||
27 | LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c $(ERRC).c | ||
28 | |||
29 | LIBOBJ= pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o $(ERRC).o | ||
30 | |||
31 | SRC= $(LIBSRC) | ||
32 | |||
33 | EXHEADER= pem.h | ||
34 | HEADER= $(EXHEADER) | ||
35 | |||
36 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
37 | |||
38 | top: | ||
39 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
40 | |||
41 | all: pem.h lib | ||
42 | |||
43 | pem.h: $(CTX_SIZE) | ||
44 | ./$(CTX_SIZE) <pem.org >pem.new | ||
45 | if [ -f pem.h ]; then mv -f pem.h pem.old; fi | ||
46 | mv -f pem.new pem.h | ||
47 | |||
48 | $(CTX_SIZE): $(CTX_SIZE).o | ||
49 | $(CC) $(CFLAGS) -o $(CTX_SIZE) $(CTX_SIZE).o | ||
50 | |||
51 | lib: $(LIBOBJ) | ||
52 | $(AR) $(LIB) $(LIBOBJ) | ||
53 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
54 | @touch lib | ||
55 | |||
56 | files: | ||
57 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
58 | |||
59 | links: | ||
60 | /bin/rm -f Makefile | ||
61 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
62 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
63 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
64 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
65 | |||
66 | install: | ||
67 | @for i in $(EXHEADER) ; \ | ||
68 | do \ | ||
69 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
70 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
71 | done; | ||
72 | |||
73 | tags: | ||
74 | ctags $(SRC) | ||
75 | |||
76 | tests: | ||
77 | |||
78 | lint: | ||
79 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
80 | |||
81 | depend: | ||
82 | $(MAKEDEPEND) $(INCLUDES) $(CTX_SIZE).c $(LIBSRC) | ||
83 | |||
84 | dclean: | ||
85 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
86 | mv -f Makefile.new $(MAKEFILE) | ||
87 | |||
88 | clean: | ||
89 | /bin/rm -f $(CTX_SIZE) *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
90 | |||
91 | errors: | ||
92 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).org # SPECIAL CASE .org | ||
93 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
94 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
95 | |||
96 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/pkcs7/Makefile.ssl b/src/lib/libssl/src/crypto/pkcs7/Makefile.ssl new file mode 100644 index 0000000000..a88359b320 --- /dev/null +++ b/src/lib/libssl/src/crypto/pkcs7/Makefile.ssl | |||
@@ -0,0 +1,86 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/asn1/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= pkcs7 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=pkcs7 | ||
19 | ERRC=pkcs7err | ||
20 | GENERAL=Makefile README | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= pk7_lib.c pkcs7err.c pk7_doit.c | ||
26 | LIBOBJ= pk7_lib.o pkcs7err.o pk7_doit.o | ||
27 | |||
28 | SRC= $(LIBSRC) | ||
29 | |||
30 | EXHEADER= pkcs7.h | ||
31 | HEADER= $(EXHEADER) | ||
32 | |||
33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
34 | |||
35 | top: | ||
36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
37 | |||
38 | test: | ||
39 | |||
40 | all: lib | ||
41 | |||
42 | lib: $(LIBOBJ) | ||
43 | $(AR) $(LIB) $(LIBOBJ) | ||
44 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
45 | @touch lib | ||
46 | |||
47 | files: | ||
48 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
49 | |||
50 | links: | ||
51 | /bin/rm -f Makefile | ||
52 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
53 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
54 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
55 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
56 | |||
57 | install: | ||
58 | @for i in $(EXHEADER) ; \ | ||
59 | do \ | ||
60 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
61 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
62 | done; | ||
63 | |||
64 | tags: | ||
65 | ctags $(SRC) | ||
66 | |||
67 | tests: | ||
68 | |||
69 | lint: | ||
70 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
71 | |||
72 | depend: | ||
73 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
74 | |||
75 | dclean: | ||
76 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
77 | mv -f Makefile.new $(MAKEFILE) | ||
78 | |||
79 | clean: | ||
80 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
81 | |||
82 | errors: | ||
83 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
84 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
85 | |||
86 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/rand/Makefile.ssl b/src/lib/libssl/src/crypto/rand/Makefile.ssl new file mode 100644 index 0000000000..d04f0a9b43 --- /dev/null +++ b/src/lib/libssl/src/crypto/rand/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/rand/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rand | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST= randtest.c | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=md_rand.c randfile.c | ||
24 | LIBOBJ=md_rand.o randfile.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= rand.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/rc2/Makefile.ssl b/src/lib/libssl/src/crypto/rc2/Makefile.ssl new file mode 100644 index 0000000000..c5138f13e2 --- /dev/null +++ b/src/lib/libssl/src/crypto/rc2/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/rc2/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rc2 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST=rc2test.c | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=rc2_ecb.c rc2_skey.c rc2_cbc.c rc2cfb64.c rc2ofb64.c | ||
24 | LIBOBJ=rc2_ecb.o rc2_skey.o rc2_cbc.o rc2cfb64.o rc2ofb64.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= rc2.h | ||
29 | HEADER= rc2_locl.h $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/rc4/Makefile.ssl b/src/lib/libssl/src/crypto/rc4/Makefile.ssl new file mode 100644 index 0000000000..19c1e980f3 --- /dev/null +++ b/src/lib/libssl/src/crypto/rc4/Makefile.ssl | |||
@@ -0,0 +1,108 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/rc4/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rc4 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | RC4_ENC=rc4_enc.o | ||
17 | # or use | ||
18 | #RC4_ENC=asm/rx86-elf.o | ||
19 | #RC4_ENC=asm/rx86-out.o | ||
20 | #RC4_ENC=asm/rx86-sol.o | ||
21 | #RC4_ENC=asm/rx86bdsi.o | ||
22 | |||
23 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
24 | |||
25 | GENERAL=Makefile | ||
26 | TEST=rc4test.c | ||
27 | APPS= | ||
28 | |||
29 | LIB=$(TOP)/libcrypto.a | ||
30 | LIBSRC=rc4_skey.c rc4_enc.c | ||
31 | LIBOBJ=rc4_skey.o $(RC4_ENC) | ||
32 | |||
33 | SRC= $(LIBSRC) | ||
34 | |||
35 | EXHEADER= rc4.h | ||
36 | HEADER= $(EXHEADER) rc4_locl.h | ||
37 | |||
38 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
39 | |||
40 | top: | ||
41 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
42 | |||
43 | all: lib | ||
44 | |||
45 | lib: $(LIBOBJ) | ||
46 | $(AR) $(LIB) $(LIBOBJ) | ||
47 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
48 | @touch lib | ||
49 | |||
50 | # elf | ||
51 | asm/rx86-elf.o: asm/rx86unix.cpp | ||
52 | $(CPP) -DELF asm/rx86unix.cpp | as -o asm/rx86-elf.o | ||
53 | |||
54 | # solaris | ||
55 | asm/rx86-sol.o: asm/rx86unix.cpp | ||
56 | $(CC) -E -DSOL asm/rx86unix.cpp | sed 's/^#.*//' > asm/rx86-sol.s | ||
57 | as -o asm/rx86-sol.o asm/rx86-sol.s | ||
58 | rm -f asm/rx86-sol.s | ||
59 | |||
60 | # a.out | ||
61 | asm/rx86-out.o: asm/rx86unix.cpp | ||
62 | $(CPP) -DOUT asm/rx86unix.cpp | as -o asm/rx86-out.o | ||
63 | |||
64 | # bsdi | ||
65 | asm/rx86bsdi.o: asm/rx86unix.cpp | ||
66 | $(CPP) -DBSDI asm/rx86unix.cpp | as -o asm/rx86bsdi.o | ||
67 | |||
68 | asm/rx86unix.cpp: | ||
69 | (cd asm; perl rc4-586.pl cpp >rx86unix.cpp) | ||
70 | |||
71 | files: | ||
72 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
73 | |||
74 | links: | ||
75 | /bin/rm -f Makefile | ||
76 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
77 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
78 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
79 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
80 | |||
81 | install: | ||
82 | @for i in $(EXHEADER) ; \ | ||
83 | do \ | ||
84 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
85 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
86 | done; | ||
87 | |||
88 | tags: | ||
89 | ctags $(SRC) | ||
90 | |||
91 | tests: | ||
92 | |||
93 | lint: | ||
94 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
95 | |||
96 | depend: | ||
97 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
98 | |||
99 | dclean: | ||
100 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
101 | mv -f Makefile.new $(MAKEFILE) | ||
102 | |||
103 | clean: | ||
104 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o | ||
105 | |||
106 | errors: | ||
107 | |||
108 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/rc5/Makefile.ssl b/src/lib/libssl/src/crypto/rc5/Makefile.ssl new file mode 100644 index 0000000000..5e98ee2348 --- /dev/null +++ b/src/lib/libssl/src/crypto/rc5/Makefile.ssl | |||
@@ -0,0 +1,107 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/rc5/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rc5 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | CPP= $(CC) -E | ||
9 | INCLUDES= | ||
10 | CFLAG=-g | ||
11 | INSTALLTOP=/usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | AR= ar r | ||
16 | |||
17 | RC5_ENC= rc5_enc.o | ||
18 | # or use | ||
19 | #DES_ENC= r586-elf.o | ||
20 | |||
21 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
22 | |||
23 | GENERAL=Makefile | ||
24 | TEST=rc5test.c | ||
25 | APPS= | ||
26 | |||
27 | LIB=$(TOP)/libcrypto.a | ||
28 | LIBSRC=rc5_skey.c rc5_ecb.c rc5_enc.c rc5cfb64.c rc5ofb64.c | ||
29 | LIBOBJ=rc5_skey.o rc5_ecb.o $(RC5_ENC) rc5cfb64.o rc5ofb64.o | ||
30 | |||
31 | SRC= $(LIBSRC) | ||
32 | |||
33 | EXHEADER= rc5.h | ||
34 | HEADER= rc5_locl.h $(EXHEADER) | ||
35 | |||
36 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
37 | |||
38 | top: | ||
39 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
40 | |||
41 | all: lib | ||
42 | |||
43 | lib: $(LIBOBJ) | ||
44 | $(AR) $(LIB) $(LIBOBJ) | ||
45 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
46 | @touch lib | ||
47 | |||
48 | # elf | ||
49 | asm/r586-elf.o: asm/r586unix.cpp | ||
50 | $(CPP) -DELF asm/r586unix.cpp | as -o asm/r586-elf.o | ||
51 | |||
52 | # solaris | ||
53 | asm/r586-sol.o: asm/r586unix.cpp | ||
54 | $(CC) -E -DSOL asm/r586unix.cpp | sed 's/^#.*//' > asm/r586-sol.s | ||
55 | as -o asm/r586-sol.o asm/r586-sol.s | ||
56 | rm -f asm/r586-sol.s | ||
57 | |||
58 | # a.out | ||
59 | asm/r586-out.o: asm/r586unix.cpp | ||
60 | $(CPP) -DOUT asm/r586unix.cpp | as -o asm/r586-out.o | ||
61 | |||
62 | # bsdi | ||
63 | asm/r586bsdi.o: asm/r586unix.cpp | ||
64 | $(CPP) -DBSDI asm/r586unix.cpp | as -o asm/r586bsdi.o | ||
65 | |||
66 | asm/r586unix.cpp: | ||
67 | (cd asm; perl rc5-586.pl cpp >r586unix.cpp) | ||
68 | |||
69 | files: | ||
70 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
71 | |||
72 | links: | ||
73 | /bin/rm -f Makefile | ||
74 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
75 | $(TOP)/util/point.sh ../../doc/rc5.doc rc5.doc ; | ||
76 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
77 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
78 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
79 | |||
80 | install: | ||
81 | @for i in $(EXHEADER) ; \ | ||
82 | do \ | ||
83 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
84 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
85 | done; | ||
86 | |||
87 | tags: | ||
88 | ctags $(SRC) | ||
89 | |||
90 | tests: | ||
91 | |||
92 | lint: | ||
93 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
94 | |||
95 | depend: | ||
96 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
97 | |||
98 | dclean: | ||
99 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
100 | mv -f Makefile.new $(MAKEFILE) | ||
101 | |||
102 | clean: | ||
103 | /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
104 | |||
105 | errors: | ||
106 | |||
107 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/rc5/asm/rc5-586.pl b/src/lib/libssl/src/crypto/rc5/asm/rc5-586.pl new file mode 100644 index 0000000000..172bd9ee1b --- /dev/null +++ b/src/lib/libssl/src/crypto/rc5/asm/rc5-586.pl | |||
@@ -0,0 +1,109 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | push(@INC,"perlasm","../../perlasm"); | ||
4 | require "x86asm.pl"; | ||
5 | require "cbc.pl"; | ||
6 | |||
7 | &asm_init($ARGV[0],"rc5-586.pl"); | ||
8 | |||
9 | $RC5_MAX_ROUNDS=16; | ||
10 | $RC5_32_OFF=($RC5_MAX_ROUNDS+2)*4; | ||
11 | $A="edi"; | ||
12 | $B="esi"; | ||
13 | $S="ebp"; | ||
14 | $tmp1="eax"; | ||
15 | $r="ebx"; | ||
16 | $tmpc="ecx"; | ||
17 | $tmp4="edx"; | ||
18 | |||
19 | &RC5_32_encrypt("RC5_32_encrypt",1); | ||
20 | &RC5_32_encrypt("RC5_32_decrypt",0); | ||
21 | &cbc("RC5_32_cbc_encrypt","RC5_32_encrypt","RC5_32_decrypt",0,4,5,3,-1,-1); | ||
22 | &asm_finish(); | ||
23 | |||
24 | sub RC5_32_encrypt | ||
25 | { | ||
26 | local($name,$enc)=@_; | ||
27 | |||
28 | &function_begin_B($name,""); | ||
29 | |||
30 | &comment(""); | ||
31 | |||
32 | &push("ebp"); | ||
33 | &push("esi"); | ||
34 | &push("edi"); | ||
35 | &mov($tmp4,&wparam(0)); | ||
36 | &mov($S,&wparam(1)); | ||
37 | |||
38 | &comment("Load the 2 words"); | ||
39 | &mov($A,&DWP(0,$tmp4,"",0)); | ||
40 | &mov($B,&DWP(4,$tmp4,"",0)); | ||
41 | |||
42 | &push($r); | ||
43 | &mov($r, &DWP(0,$S,"",0)); | ||
44 | |||
45 | # encrypting part | ||
46 | |||
47 | if ($enc) | ||
48 | { | ||
49 | &add($A, &DWP(4+0,$S,"",0)); | ||
50 | &add($B, &DWP(4+4,$S,"",0)); | ||
51 | |||
52 | for ($i=0; $i<$RC5_MAX_ROUNDS; $i++) | ||
53 | { | ||
54 | &xor($A, $B); | ||
55 | &mov($tmp1, &DWP(12+$i*8,$S,"",0)); | ||
56 | &mov($tmpc, $B); | ||
57 | &rotl($A, &LB("ecx")); | ||
58 | &add($A, $tmp1); | ||
59 | |||
60 | &xor($B, $A); | ||
61 | &mov($tmp1, &DWP(16+$i*8,$S,"",0)); | ||
62 | &mov($tmpc, $A); | ||
63 | &rotl($B, &LB("ecx")); | ||
64 | &add($B, $tmp1); | ||
65 | if (($i == 7) || ($i == 11)) | ||
66 | { | ||
67 | &cmp($r, $i+1); | ||
68 | &je(&label("rc5_exit")); | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | else | ||
73 | { | ||
74 | &cmp($r, 12); | ||
75 | &je(&label("rc5_dec_12")); | ||
76 | &cmp($r, 8); | ||
77 | &je(&label("rc5_dec_8")); | ||
78 | for ($i=$RC5_MAX_ROUNDS; $i > 0; $i--) | ||
79 | { | ||
80 | &set_label("rc5_dec_$i") if ($i == 12) || ($i == 8); | ||
81 | &mov($tmp1, &DWP($i*8+8,$S,"",0)); | ||
82 | &sub($B, $tmp1); | ||
83 | &mov($tmpc, $A); | ||
84 | &rotr($B, &LB("ecx")); | ||
85 | &xor($B, $A); | ||
86 | |||
87 | &mov($tmp1, &DWP($i*8+4,$S,"",0)); | ||
88 | &sub($A, $tmp1); | ||
89 | &mov($tmpc, $B); | ||
90 | &rotr($A, &LB("ecx")); | ||
91 | &xor($A, $B); | ||
92 | } | ||
93 | &sub($B, &DWP(4+4,$S,"",0)); | ||
94 | &sub($A, &DWP(4+0,$S,"",0)); | ||
95 | } | ||
96 | |||
97 | &set_label("rc5_exit"); | ||
98 | &mov(&DWP(0,$tmp4,"",0),$A); | ||
99 | &mov(&DWP(4,$tmp4,"",0),$B); | ||
100 | |||
101 | &pop("ebx"); | ||
102 | &pop("edi"); | ||
103 | &pop("esi"); | ||
104 | &pop("ebp"); | ||
105 | &ret(); | ||
106 | &function_end_B($name); | ||
107 | } | ||
108 | |||
109 | |||
diff --git a/src/lib/libssl/src/crypto/ripemd/Makefile.ssl b/src/lib/libssl/src/crypto/ripemd/Makefile.ssl new file mode 100644 index 0000000000..67d47ceb2c --- /dev/null +++ b/src/lib/libssl/src/crypto/ripemd/Makefile.ssl | |||
@@ -0,0 +1,104 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/ripemd/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= ripemd | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | CPP= $(CC) -E | ||
9 | INCLUDES= | ||
10 | CFLAG=-g | ||
11 | INSTALLTOP=/usr/local/ssl | ||
12 | MAKE= make -f Makefile.ssl | ||
13 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
14 | MAKEFILE= Makefile.ssl | ||
15 | AR= ar r | ||
16 | |||
17 | RIP_ASM_OBJ= | ||
18 | |||
19 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
20 | |||
21 | GENERAL=Makefile | ||
22 | TEST=rmdtest.c | ||
23 | APPS=rmd160.c | ||
24 | |||
25 | LIB=$(TOP)/libcrypto.a | ||
26 | LIBSRC=rmd_dgst.c rmd_one.c | ||
27 | LIBOBJ=rmd_dgst.o rmd_one.o $(RMD160_ASM_OBJ) | ||
28 | |||
29 | SRC= $(LIBSRC) | ||
30 | |||
31 | EXHEADER= ripemd.h | ||
32 | HEADER= rmd_locl.h rmdconst.h $(EXHEADER) | ||
33 | |||
34 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
35 | |||
36 | top: | ||
37 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
38 | |||
39 | all: lib | ||
40 | |||
41 | lib: $(LIBOBJ) | ||
42 | $(AR) $(LIB) $(LIBOBJ) | ||
43 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
44 | @touch lib | ||
45 | |||
46 | # elf | ||
47 | asm/rm86-elf.o: asm/rm86unix.cpp | ||
48 | $(CPP) -DELF asm/rm86unix.cpp | as -o asm/rm86-elf.o | ||
49 | |||
50 | # solaris | ||
51 | asm/rm86-sol.o: asm/rm86unix.cpp | ||
52 | $(CC) -E -DSOL asm/rm86unix.cpp | sed 's/^#.*//' > asm/rm86-sol.s | ||
53 | as -o asm/rm86-sol.o asm/rm86-sol.s | ||
54 | rm -f asm/rm86-sol.s | ||
55 | |||
56 | # a.out | ||
57 | asm/rm86-out.o: asm/rm86unix.cpp | ||
58 | $(CPP) -DOUT asm/rm86unix.cpp | as -o asm/rm86-out.o | ||
59 | |||
60 | # bsdi | ||
61 | asm/rm86bsdi.o: asm/rm86unix.cpp | ||
62 | $(CPP) -DBSDI asm/rm86unix.cpp | as -o asm/rm86bsdi.o | ||
63 | |||
64 | asm/rm86unix.cpp: | ||
65 | (cd asm; perl rmd-586.pl cpp >rm86unix.cpp) | ||
66 | |||
67 | files: | ||
68 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
69 | |||
70 | links: | ||
71 | /bin/rm -f Makefile | ||
72 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
73 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
74 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
75 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
76 | |||
77 | install: | ||
78 | @for i in $(EXHEADER) ; \ | ||
79 | do \ | ||
80 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
81 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
82 | done; | ||
83 | |||
84 | tags: | ||
85 | ctags $(SRC) | ||
86 | |||
87 | tests: | ||
88 | |||
89 | lint: | ||
90 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
91 | |||
92 | depend: | ||
93 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
94 | |||
95 | dclean: | ||
96 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
97 | mv -f Makefile.new $(MAKEFILE) | ||
98 | |||
99 | clean: | ||
100 | /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
101 | |||
102 | errors: | ||
103 | |||
104 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/rsa/Makefile.ssl b/src/lib/libssl/src/crypto/rsa/Makefile.ssl new file mode 100644 index 0000000000..d52f2e609e --- /dev/null +++ b/src/lib/libssl/src/crypto/rsa/Makefile.ssl | |||
@@ -0,0 +1,86 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/rsa/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rsa | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=rsa | ||
19 | ERRC=rsa_err | ||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c $(ERRC).c \ | ||
26 | rsa_pk1.c rsa_ssl.c rsa_none.c | ||
27 | LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o $(ERRC).o \ | ||
28 | rsa_pk1.o rsa_ssl.o rsa_none.o | ||
29 | |||
30 | SRC= $(LIBSRC) | ||
31 | |||
32 | EXHEADER= rsa.h | ||
33 | HEADER= $(EXHEADER) | ||
34 | |||
35 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
36 | |||
37 | top: | ||
38 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
39 | |||
40 | all: lib | ||
41 | |||
42 | lib: $(LIBOBJ) | ||
43 | $(AR) $(LIB) $(LIBOBJ) | ||
44 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
45 | @touch lib | ||
46 | |||
47 | files: | ||
48 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
49 | |||
50 | links: | ||
51 | /bin/rm -f Makefile | ||
52 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
53 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
54 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
55 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
56 | |||
57 | install: | ||
58 | @for i in $(EXHEADER) ; \ | ||
59 | do \ | ||
60 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
61 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
62 | done; | ||
63 | |||
64 | tags: | ||
65 | ctags $(SRC) | ||
66 | |||
67 | tests: | ||
68 | |||
69 | lint: | ||
70 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
71 | |||
72 | depend: | ||
73 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
74 | |||
75 | dclean: | ||
76 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
77 | mv -f Makefile.new $(MAKEFILE) | ||
78 | |||
79 | clean: | ||
80 | /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
81 | |||
82 | errors: | ||
83 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
84 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
85 | |||
86 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/sha/Makefile.ssl b/src/lib/libssl/src/crypto/sha/Makefile.ssl new file mode 100644 index 0000000000..eeb545d140 --- /dev/null +++ b/src/lib/libssl/src/crypto/sha/Makefile.ssl | |||
@@ -0,0 +1,103 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/sha/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= sha | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | SHA1_ASM_OBJ= | ||
17 | |||
18 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
19 | |||
20 | GENERAL=Makefile | ||
21 | TEST=shatest.c sha1test.c | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC=sha_dgst.c sha1dgst.c sha_one.c sha1_one.c | ||
26 | LIBOBJ=sha_dgst.o sha1dgst.o sha_one.o sha1_one.o $(SHA1_ASM_OBJ) | ||
27 | |||
28 | SRC= $(LIBSRC) | ||
29 | |||
30 | EXHEADER= sha.h | ||
31 | HEADER= sha_locl.h $(EXHEADER) | ||
32 | |||
33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
34 | |||
35 | top: | ||
36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
37 | |||
38 | all: lib | ||
39 | |||
40 | lib: $(LIBOBJ) | ||
41 | $(AR) $(LIB) $(LIBOBJ) | ||
42 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
43 | @touch lib | ||
44 | |||
45 | # elf | ||
46 | asm/sx86-elf.o: asm/sx86unix.cpp | ||
47 | $(CPP) -DELF asm/sx86unix.cpp | as -o asm/sx86-elf.o | ||
48 | |||
49 | # solaris | ||
50 | asm/sx86-sol.o: asm/sx86unix.cpp | ||
51 | $(CC) -E -DSOL asm/sx86unix.cpp | sed 's/^#.*//' > asm/sx86-sol.s | ||
52 | as -o asm/sx86-sol.o asm/sx86-sol.s | ||
53 | rm -f asm/sx86-sol.s | ||
54 | |||
55 | # a.out | ||
56 | asm/sx86-out.o: asm/sx86unix.cpp | ||
57 | $(CPP) -DOUT asm/sx86unix.cpp | as -o asm/sx86-out.o | ||
58 | |||
59 | # bsdi | ||
60 | asm/sx86bsdi.o: asm/sx86unix.cpp | ||
61 | $(CPP) -DBSDI asm/sx86unix.cpp | as -o asm/sx86bsdi.o | ||
62 | |||
63 | asm/sx86unix.cpp: | ||
64 | (cd asm; perl sha1-586.pl cpp >sx86unix.cpp) | ||
65 | |||
66 | files: | ||
67 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
68 | |||
69 | links: | ||
70 | /bin/rm -f Makefile | ||
71 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
72 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
73 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
74 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
75 | |||
76 | install: | ||
77 | @for i in $(EXHEADER) ; \ | ||
78 | do \ | ||
79 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
80 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
81 | done; | ||
82 | |||
83 | tags: | ||
84 | ctags $(SRC) | ||
85 | |||
86 | tests: | ||
87 | |||
88 | lint: | ||
89 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
90 | |||
91 | depend: | ||
92 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
93 | |||
94 | dclean: | ||
95 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
96 | mv -f Makefile.new $(MAKEFILE) | ||
97 | |||
98 | clean: | ||
99 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o | ||
100 | |||
101 | errors: | ||
102 | |||
103 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/stack/Makefile.ssl b/src/lib/libssl/src/crypto/stack/Makefile.ssl new file mode 100644 index 0000000000..0d232c08cf --- /dev/null +++ b/src/lib/libssl/src/crypto/stack/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/stack/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= stack | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST= | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=stack.c | ||
24 | LIBOBJ=stack.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= stack.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/txt_db/Makefile.ssl b/src/lib/libssl/src/crypto/txt_db/Makefile.ssl new file mode 100644 index 0000000000..76e511534f --- /dev/null +++ b/src/lib/libssl/src/crypto/txt_db/Makefile.ssl | |||
@@ -0,0 +1,80 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/txt_db/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= txt_db | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | GENERAL=Makefile | ||
19 | TEST= | ||
20 | APPS= | ||
21 | |||
22 | LIB=$(TOP)/libcrypto.a | ||
23 | LIBSRC=txt_db.c | ||
24 | LIBOBJ=txt_db.o | ||
25 | |||
26 | SRC= $(LIBSRC) | ||
27 | |||
28 | EXHEADER= txt_db.h | ||
29 | HEADER= $(EXHEADER) | ||
30 | |||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
32 | |||
33 | top: | ||
34 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
35 | |||
36 | all: lib | ||
37 | |||
38 | lib: $(LIBOBJ) | ||
39 | $(AR) $(LIB) $(LIBOBJ) | ||
40 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
41 | @touch lib | ||
42 | |||
43 | files: | ||
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
45 | |||
46 | links: | ||
47 | /bin/rm -f Makefile | ||
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | |||
53 | install: | ||
54 | @for i in $(EXHEADER) ; \ | ||
55 | do \ | ||
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
58 | done; | ||
59 | |||
60 | tags: | ||
61 | ctags $(SRC) | ||
62 | |||
63 | tests: | ||
64 | |||
65 | lint: | ||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
67 | |||
68 | depend: | ||
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
70 | |||
71 | dclean: | ||
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
73 | mv -f Makefile.new $(MAKEFILE) | ||
74 | |||
75 | clean: | ||
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
77 | |||
78 | errors: | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/crypto/x509/Makefile.ssl b/src/lib/libssl/src/crypto/x509/Makefile.ssl new file mode 100644 index 0000000000..1c1ca2ffa0 --- /dev/null +++ b/src/lib/libssl/src/crypto/x509/Makefile.ssl | |||
@@ -0,0 +1,96 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/x509/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= x509 | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=x509 | ||
19 | ERRC=x509_err | ||
20 | GENERAL=Makefile README | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c \ | ||
26 | x509_obj.c x509_req.c x509_vfy.c \ | ||
27 | x509_set.c x509rset.c $(ERRC).c \ | ||
28 | x509name.c x509_v3.c x509_ext.c x509pack.c \ | ||
29 | x509type.c x509_lu.c x_all.c x509_txt.c \ | ||
30 | by_file.c by_dir.c \ | ||
31 | v3_net.c v3_x509.c | ||
32 | LIBOBJ= x509_def.o x509_d2.o x509_r2x.o x509_cmp.o \ | ||
33 | x509_obj.o x509_req.o x509_vfy.o \ | ||
34 | x509_set.o x509rset.o $(ERRC).o \ | ||
35 | x509name.o x509_v3.o x509_ext.o x509pack.o \ | ||
36 | x509type.o x509_lu.o x_all.o x509_txt.o \ | ||
37 | by_file.o by_dir.o \ | ||
38 | v3_net.o v3_x509.o | ||
39 | |||
40 | SRC= $(LIBSRC) | ||
41 | |||
42 | EXHEADER= x509.h x509_vfy.h | ||
43 | HEADER= $(EXHEADER) | ||
44 | |||
45 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
46 | |||
47 | top: | ||
48 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
49 | |||
50 | all: lib | ||
51 | |||
52 | lib: $(LIBOBJ) | ||
53 | $(AR) $(LIB) $(LIBOBJ) | ||
54 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
55 | @touch lib | ||
56 | |||
57 | files: | ||
58 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
59 | |||
60 | links: | ||
61 | /bin/rm -f Makefile | ||
62 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
63 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
64 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
65 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
66 | |||
67 | install: | ||
68 | @for i in $(EXHEADER) ; \ | ||
69 | do \ | ||
70 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
71 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
72 | done; | ||
73 | |||
74 | tags: | ||
75 | ctags $(SRC) | ||
76 | |||
77 | tests: | ||
78 | |||
79 | lint: | ||
80 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
81 | |||
82 | depend: | ||
83 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
84 | |||
85 | dclean: | ||
86 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
87 | mv -f Makefile.new $(MAKEFILE) | ||
88 | |||
89 | clean: | ||
90 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
91 | |||
92 | errors: | ||
93 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
94 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
95 | |||
96 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/ssl/Makefile.ssl b/src/lib/libssl/src/ssl/Makefile.ssl new file mode 100644 index 0000000000..f4b13bf83b --- /dev/null +++ b/src/lib/libssl/src/ssl/Makefile.ssl | |||
@@ -0,0 +1,100 @@ | |||
1 | # | ||
2 | # SSLeay/ssl/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= ssl | ||
6 | TOP= .. | ||
7 | CC= cc | ||
8 | INCLUDES= -I../crypto -I../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | AR= ar r | ||
15 | |||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
17 | |||
18 | ERR=ssl | ||
19 | ERRC=ssl_err | ||
20 | GENERAL=Makefile README | ||
21 | TEST=ssltest.c | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libssl.a | ||
25 | LIBSRC= \ | ||
26 | s2_meth.c s2_srvr.c s2_clnt.c s2_lib.c s2_enc.c s2_pkt.c \ | ||
27 | s3_meth.c s3_srvr.c s3_clnt.c s3_lib.c s3_enc.c s3_pkt.c s3_both.c \ | ||
28 | s23_meth.c s23_srvr.c s23_clnt.c s23_lib.c s23_pkt.c \ | ||
29 | t1_meth.c t1_srvr.c t1_clnt.c t1_lib.c t1_enc.c \ | ||
30 | ssl_lib.c ssl_err2.c ssl_cert.c ssl_sess.c \ | ||
31 | ssl_ciph.c ssl_stat.c ssl_rsa.c \ | ||
32 | ssl_asn1.c ssl_txt.c ssl_algs.c \ | ||
33 | bio_ssl.c $(ERRC).c | ||
34 | LIBOBJ= \ | ||
35 | s2_meth.o s2_srvr.o s2_clnt.o s2_lib.o s2_enc.o s2_pkt.o \ | ||
36 | s3_meth.o s3_srvr.o s3_clnt.o s3_lib.o s3_enc.o s3_pkt.o s3_both.o \ | ||
37 | s23_meth.o s23_srvr.o s23_clnt.o s23_lib.o s23_pkt.o \ | ||
38 | t1_meth.o t1_srvr.o t1_clnt.o t1_lib.o t1_enc.o \ | ||
39 | ssl_lib.o ssl_err2.o ssl_cert.o ssl_sess.o \ | ||
40 | ssl_ciph.o ssl_stat.o ssl_rsa.o \ | ||
41 | ssl_asn1.o ssl_txt.o ssl_algs.o \ | ||
42 | bio_ssl.o $(ERRC).o | ||
43 | |||
44 | SRC= $(LIBSRC) | ||
45 | |||
46 | EXHEADER= ssl.h ssl2.h ssl3.h ssl23.h tls1.h | ||
47 | HEADER= $(EXHEADER) ssl_locl.h | ||
48 | |||
49 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
50 | |||
51 | top: | ||
52 | (cd ..; $(MAKE) DIRS=$(DIR) all) | ||
53 | |||
54 | all: lib | ||
55 | |||
56 | lib: $(LIBOBJ) | ||
57 | $(AR) $(LIB) $(LIBOBJ) | ||
58 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
59 | @touch lib | ||
60 | |||
61 | files: | ||
62 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
63 | |||
64 | links: | ||
65 | /bin/rm -f Makefile | ||
66 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
67 | $(TOP)/util/mklink.sh ../include $(EXHEADER) | ||
68 | $(TOP)/util/mklink.sh ../test $(TEST) | ||
69 | $(TOP)/util/mklink.sh ../apps $(APPS) | ||
70 | |||
71 | install: | ||
72 | @for i in $(EXHEADER) ; \ | ||
73 | do \ | ||
74 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
75 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
76 | done; | ||
77 | |||
78 | tags: | ||
79 | ctags $(SRC) | ||
80 | |||
81 | tests: | ||
82 | |||
83 | lint: | ||
84 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
85 | |||
86 | depend: | ||
87 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
88 | |||
89 | dclean: | ||
90 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
91 | mv -f Makefile.new $(MAKEFILE) | ||
92 | |||
93 | clean: | ||
94 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
95 | |||
96 | errors: | ||
97 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
98 | perl ../crypto/err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
99 | |||
100 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/test/Makefile.ssl b/src/lib/libssl/src/test/Makefile.ssl new file mode 100644 index 0000000000..b3de76751e --- /dev/null +++ b/src/lib/libssl/src/test/Makefile.ssl | |||
@@ -0,0 +1,294 @@ | |||
1 | # | ||
2 | # test/Makefile.ssl | ||
3 | # | ||
4 | |||
5 | DIR= test | ||
6 | TOP= .. | ||
7 | CC= cc | ||
8 | INCLUDES= -I../include | ||
9 | CFLAG= -g | ||
10 | INSTALLTOP= /usr/local/ssl | ||
11 | MAKEFILE= Makefile.ssl | ||
12 | MAKE= make -f $(MAKEFILE) | ||
13 | MAKEDEPEND= makedepend -f$(MAKEFILE) | ||
14 | |||
15 | PEX_LIBS= | ||
16 | EX_LIBS= #-lnsl -lsocket | ||
17 | |||
18 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
19 | |||
20 | GENERAL=Makefile.ssl | ||
21 | |||
22 | DLIBCRYPTO= ../libcrypto.a | ||
23 | DLIBSSL= ../libssl.a | ||
24 | LIBCRYPTO= -L.. -lcrypto | ||
25 | LIBSSL= -L.. -lssl | ||
26 | |||
27 | BNTEST= bntest | ||
28 | EXPTEST= exptest | ||
29 | IDEATEST= ideatest | ||
30 | SHATEST= shatest | ||
31 | SHA1TEST= sha1test | ||
32 | MDC2TEST= mdc2test | ||
33 | RMDTEST= rmdtest | ||
34 | MD2TEST= md2test | ||
35 | MD5TEST= md5test | ||
36 | HMACTEST= hmactest | ||
37 | RC2TEST= rc2test | ||
38 | RC4TEST= rc4test | ||
39 | RC5TEST= rc5test | ||
40 | BFTEST= bftest | ||
41 | CASTTEST= casttest | ||
42 | DESTEST= destest | ||
43 | RANDTEST= randtest | ||
44 | DHTEST= dhtest | ||
45 | DSATEST= dsatest | ||
46 | METHTEST= methtest | ||
47 | SSLTEST= ssltest | ||
48 | |||
49 | EXE= $(BNTEST) $(IDEATEST) $(MD2TEST) $(MD5TEST) $(HMACTEST) \ | ||
50 | $(RC2TEST) $(RC4TEST) $(RC5TEST) \ | ||
51 | $(DESTEST) $(SHATEST) $(SHA1TEST) $(MDC2TEST) $(RMDTEST) \ | ||
52 | $(RANDTEST) $(DHTEST) \ | ||
53 | $(BFTEST) $(CASTTEST) $(SSLTEST) $(EXPTEST) $(DSATEST) | ||
54 | |||
55 | # $(METHTEST) | ||
56 | |||
57 | OBJ= $(BNTEST).o $(IDEATEST).o $(MD2TEST).o $(MD5TEST).o $(HMACTEST).o \ | ||
58 | $(RC2TEST).o $(RC4TEST).o $(RC5TEST).o \ | ||
59 | $(DESTEST).o $(SHATEST).o $(SHA1TEST).o $(MDC2TEST).o $(RMDTEST).o \ | ||
60 | $(RANDTEST).o $(DHTEST).o $(CASTTEST).o \ | ||
61 | $(BFTEST).o $(SSLTEST).o $(DSATEST).o $(EXPTEST).o | ||
62 | SRC= $(BNTEST).c $(IDEATEST).c $(MD2TEST).c $(MD5TEST).c $(HMACTEST).c \ | ||
63 | $(RC2TEST).c $(RC4TEST).c $(RC5TEST).c \ | ||
64 | $(DESTEST).c $(SHATEST).c $(SHA1TEST).c $(MDC2TEST).c $(RMDTEST).c \ | ||
65 | $(RANDTEST).c $(DHTEST).c $(CASTTEST).c \ | ||
66 | $(BFTEST).c $(SSLTEST).c $(DSATEST).c $(EXPTEST).c | ||
67 | |||
68 | EXHEADER= | ||
69 | HEADER= $(EXHEADER) | ||
70 | |||
71 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
72 | |||
73 | top: | ||
74 | (cd ..; $(MAKE) DIRS=$(DIR) all) | ||
75 | |||
76 | all: exe | ||
77 | |||
78 | exe: $(EXE) | ||
79 | |||
80 | files: | ||
81 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
82 | |||
83 | links: | ||
84 | /bin/rm -f Makefile | ||
85 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
86 | |||
87 | errors: | ||
88 | |||
89 | install: | ||
90 | |||
91 | tags: | ||
92 | ctags $(SRC) | ||
93 | |||
94 | tests: exe apps \ | ||
95 | test_des test_idea test_sha test_md5 test_hmac test_md2 test_mdc2 \ | ||
96 | test_rc2 test_rc4 test_rc5 test_bf test_cast \ | ||
97 | test_rand test_enc test_x509 test_rsa test_crl test_sid test_req \ | ||
98 | test_pkcs7 test_bn test_verify test_dh test_dsa test_reqgen \ | ||
99 | test_ss test_ssl test_ca | ||
100 | |||
101 | apps: | ||
102 | @(cd ../apps; $(MAKE) CC='${CC}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' all) | ||
103 | |||
104 | test_des: | ||
105 | #./$(DESTEST) | ||
106 | |||
107 | test_idea: | ||
108 | ./$(IDEATEST) | ||
109 | |||
110 | test_sha: | ||
111 | ./$(SHATEST) | ||
112 | ./$(SHA1TEST) | ||
113 | |||
114 | test_mdc2: | ||
115 | ./$(MDC2TEST) | ||
116 | |||
117 | test_md5: | ||
118 | ./$(MD5TEST) | ||
119 | |||
120 | test_hmac: | ||
121 | ./$(HMACTEST) | ||
122 | |||
123 | test_md2: | ||
124 | ./$(MD2TEST) | ||
125 | |||
126 | test_rmd: | ||
127 | ./$(RMDTEST) | ||
128 | |||
129 | test_bf: | ||
130 | ./$(BFTEST) | ||
131 | |||
132 | test_cast: | ||
133 | ./$(CASTTEST) | ||
134 | |||
135 | test_rc2: | ||
136 | ./$(RC2TEST) | ||
137 | |||
138 | test_rc4: | ||
139 | ./$(RC4TEST) | ||
140 | |||
141 | test_rc5: | ||
142 | ./$(RC5TEST) | ||
143 | |||
144 | test_rand: | ||
145 | ./$(RANDTEST) | ||
146 | |||
147 | test_enc: | ||
148 | @sh ./testenc | ||
149 | |||
150 | test_x509: | ||
151 | echo test normal x509v1 certificate | ||
152 | sh ./tx509 2>/dev/null | ||
153 | echo test first x509v3 certificate | ||
154 | sh ./tx509 v3-cert1.pem 2>/dev/null | ||
155 | echo test second x509v3 certificate | ||
156 | sh ./tx509 v3-cert2.pem 2>/dev/null | ||
157 | |||
158 | test_rsa: | ||
159 | @sh ./trsa 2>/dev/null | ||
160 | |||
161 | test_crl: | ||
162 | @sh ./tcrl 2>/dev/null | ||
163 | |||
164 | test_sid: | ||
165 | @sh ./tsid 2>/dev/null | ||
166 | |||
167 | test_req: | ||
168 | @sh ./treq 2>/dev/null | ||
169 | @sh ./treq testreq2.pem 2>/dev/null | ||
170 | |||
171 | test_pkcs7: | ||
172 | @sh ./tpkcs7 2>/dev/null | ||
173 | @sh ./tpkcs7d 2>/dev/null | ||
174 | |||
175 | test_bn: | ||
176 | @echo 'test a^b%c implementations' | ||
177 | ./$(EXPTEST) | ||
178 | @echo starting big number library test, could take a while... | ||
179 | @(./$(BNTEST)|bc) | awk '{ \ | ||
180 | if ($$0 != "0") {print "error"; exit(1); } \ | ||
181 | if (((NR+1)%64) == 0) print NR+1," tests done"; }' | ||
182 | |||
183 | test_verify: | ||
184 | @echo "The following command should have some OK's and some failures" | ||
185 | @echo "There are definitly a few expired certificates" | ||
186 | ../apps/ssleay verify -CApath ../certs ../certs/*.pem | ||
187 | |||
188 | test_dh: | ||
189 | @echo "Generate as set of DH parameters" | ||
190 | ./$(DHTEST) | ||
191 | |||
192 | test_dsa: | ||
193 | @echo "Generate as set of DSA parameters" | ||
194 | ./$(DSATEST) | ||
195 | |||
196 | test_reqgen: | ||
197 | @echo "Generate and verify a certificate request" | ||
198 | @sh ./testgen | ||
199 | |||
200 | test_ss: | ||
201 | @echo "Generate and certify a test certificate" | ||
202 | @sh ./testss | ||
203 | |||
204 | test_ssl: | ||
205 | @echo "test SSL protocol" | ||
206 | @sh ./testssl | ||
207 | |||
208 | test_ca: | ||
209 | @echo "Generate and certify a test certificate via the 'ca' program" | ||
210 | @sh ./testca | ||
211 | |||
212 | lint: | ||
213 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
214 | |||
215 | depend: | ||
216 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(SRC) | ||
217 | |||
218 | dclean: | ||
219 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
220 | mv -f Makefile.new $(MAKEFILE) | ||
221 | |||
222 | clean: | ||
223 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff $(EXE) *.ss log | ||
224 | |||
225 | $(DLIBSSL): | ||
226 | (cd ../ssl; $(MAKE)) | ||
227 | |||
228 | $(DLIBCRYPTO): | ||
229 | (cd ../crypto; $(MAKE)) | ||
230 | |||
231 | $(BNTEST): $(BNTEST).o $(DLIBCRYPTO) | ||
232 | $(CC) -o $(BNTEST) $(CFLAGS) $(BNTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
233 | |||
234 | $(EXPTEST): $(EXPTEST).o $(DLIBCRYPTO) | ||
235 | $(CC) -o $(EXPTEST) $(CFLAGS) $(EXPTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
236 | |||
237 | $(IDEATEST): $(IDEATEST).o $(DLIBCRYPTO) | ||
238 | $(CC) -o $(IDEATEST) $(CFLAGS) $(IDEATEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
239 | |||
240 | $(MD2TEST): $(MD2TEST).o $(DLIBCRYPTO) | ||
241 | $(CC) -o $(MD2TEST) $(CFLAGS) $(MD2TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
242 | |||
243 | $(SHATEST): $(SHATEST).o $(DLIBCRYPTO) | ||
244 | $(CC) -o $(SHATEST) $(CFLAGS) $(SHATEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
245 | |||
246 | $(SHA1TEST): $(SHA1TEST).o $(DLIBCRYPTO) | ||
247 | $(CC) -o $(SHA1TEST) $(CFLAGS) $(SHA1TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
248 | |||
249 | $(RMDTEST): $(RMDTEST).o $(DLIBCRYPTO) | ||
250 | $(CC) -o $(RMDTEST) $(CFLAGS) $(RMDTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
251 | |||
252 | $(MDC2TEST): $(MDC2TEST).o $(DLIBCRYPTO) | ||
253 | $(CC) -o $(MDC2TEST) $(CFLAGS) $(MDC2TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
254 | |||
255 | $(MD5TEST): $(MD5TEST).o $(DLIBCRYPTO) | ||
256 | $(CC) -o $(MD5TEST) $(CFLAGS) $(MD5TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
257 | |||
258 | $(HMACTEST): $(HMACTEST).o $(DLIBCRYPTO) | ||
259 | $(CC) -o $(HMACTEST) $(CFLAGS) $(HMACTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
260 | |||
261 | $(RC2TEST): $(RC2TEST).o $(DLIBCRYPTO) | ||
262 | $(CC) -o $(RC2TEST) $(CFLAGS) $(RC2TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
263 | |||
264 | $(BFTEST): $(BFTEST).o $(DLIBCRYPTO) | ||
265 | $(CC) -o $(BFTEST) $(CFLAGS) $(BFTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
266 | |||
267 | $(CASTTEST): $(CASTTEST).o $(DLIBCRYPTO) | ||
268 | $(CC) -o $(CASTTEST) $(CFLAGS) $(CASTTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
269 | |||
270 | $(RC4TEST): $(RC4TEST).o $(DLIBCRYPTO) | ||
271 | $(CC) -o $(RC4TEST) $(CFLAGS) $(RC4TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
272 | |||
273 | $(RC5TEST): $(RC5TEST).o $(DLIBCRYPTO) | ||
274 | $(CC) -o $(RC5TEST) $(CFLAGS) $(RC5TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
275 | |||
276 | $(DESTEST): $(DESTEST).o $(DLIBCRYPTO) | ||
277 | $(CC) -o $(DESTEST) $(CFLAGS) $(DESTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
278 | |||
279 | $(RANDTEST): $(RANDTEST).o $(DLIBCRYPTO) | ||
280 | $(CC) -o $(RANDTEST) $(CFLAGS) $(RANDTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
281 | |||
282 | $(DHTEST): $(DHTEST).o $(DLIBCRYPTO) | ||
283 | $(CC) -o $(DHTEST) $(CFLAGS) $(DHTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
284 | |||
285 | $(DSATEST): $(DSATEST).o $(DLIBCRYPTO) | ||
286 | $(CC) -o $(DSATEST) $(CFLAGS) $(DSATEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
287 | |||
288 | $(METHTEST): $(METHTEST).o $(DLIBCRYPTO) | ||
289 | $(CC) -o $(METHTEST) $(CFLAGS) $(METHTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
290 | |||
291 | $(SSLTEST): $(SSLTEST).o $(DLIBSSL) $(DLIBCRYPTO) | ||
292 | $(CC) -o $(SSLTEST) $(CFLAGS) $(SSLTEST).o $(PEX_LIBS) $(LIBSSL) $(LIBCRYPTO) $(EX_LIBS) | ||
293 | |||
294 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/src/tools/Makefile.ssl b/src/lib/libssl/src/tools/Makefile.ssl new file mode 100644 index 0000000000..537e97d268 --- /dev/null +++ b/src/lib/libssl/src/tools/Makefile.ssl | |||
@@ -0,0 +1,54 @@ | |||
1 | # | ||
2 | # SSLeay/tools/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= tools | ||
6 | TOP= .. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALLTOP=/usr/local/ssl | ||
11 | MAKE= make -f Makefile.ssl | ||
12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
13 | MAKEFILE= Makefile.ssl | ||
14 | |||
15 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
16 | |||
17 | GENERAL=Makefile.ssl | ||
18 | TEST= | ||
19 | APPS= c_hash c_info c_issuer c_name c_rehash | ||
20 | |||
21 | all: | ||
22 | |||
23 | install: | ||
24 | @for i in $(APPS) ; \ | ||
25 | do \ | ||
26 | (cp $$i $(INSTALLTOP)/bin/$$i; \ | ||
27 | chmod 755 $(INSTALLTOP)/bin/$$i ); \ | ||
28 | done; | ||
29 | |||
30 | files: | ||
31 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
32 | |||
33 | links: | ||
34 | /bin/rm -f Makefile | ||
35 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
36 | |||
37 | lint: | ||
38 | |||
39 | tags: | ||
40 | |||
41 | errors: | ||
42 | |||
43 | depend: | ||
44 | |||
45 | dclean: | ||
46 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
47 | mv -f Makefile.new $(MAKEFILE) | ||
48 | |||
49 | clean: | ||
50 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
51 | |||
52 | errors: | ||
53 | |||
54 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libssl/test/Makefile.ssl b/src/lib/libssl/test/Makefile.ssl new file mode 100644 index 0000000000..b3de76751e --- /dev/null +++ b/src/lib/libssl/test/Makefile.ssl | |||
@@ -0,0 +1,294 @@ | |||
1 | # | ||
2 | # test/Makefile.ssl | ||
3 | # | ||
4 | |||
5 | DIR= test | ||
6 | TOP= .. | ||
7 | CC= cc | ||
8 | INCLUDES= -I../include | ||
9 | CFLAG= -g | ||
10 | INSTALLTOP= /usr/local/ssl | ||
11 | MAKEFILE= Makefile.ssl | ||
12 | MAKE= make -f $(MAKEFILE) | ||
13 | MAKEDEPEND= makedepend -f$(MAKEFILE) | ||
14 | |||
15 | PEX_LIBS= | ||
16 | EX_LIBS= #-lnsl -lsocket | ||
17 | |||
18 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
19 | |||
20 | GENERAL=Makefile.ssl | ||
21 | |||
22 | DLIBCRYPTO= ../libcrypto.a | ||
23 | DLIBSSL= ../libssl.a | ||
24 | LIBCRYPTO= -L.. -lcrypto | ||
25 | LIBSSL= -L.. -lssl | ||
26 | |||
27 | BNTEST= bntest | ||
28 | EXPTEST= exptest | ||
29 | IDEATEST= ideatest | ||
30 | SHATEST= shatest | ||
31 | SHA1TEST= sha1test | ||
32 | MDC2TEST= mdc2test | ||
33 | RMDTEST= rmdtest | ||
34 | MD2TEST= md2test | ||
35 | MD5TEST= md5test | ||
36 | HMACTEST= hmactest | ||
37 | RC2TEST= rc2test | ||
38 | RC4TEST= rc4test | ||
39 | RC5TEST= rc5test | ||
40 | BFTEST= bftest | ||
41 | CASTTEST= casttest | ||
42 | DESTEST= destest | ||
43 | RANDTEST= randtest | ||
44 | DHTEST= dhtest | ||
45 | DSATEST= dsatest | ||
46 | METHTEST= methtest | ||
47 | SSLTEST= ssltest | ||
48 | |||
49 | EXE= $(BNTEST) $(IDEATEST) $(MD2TEST) $(MD5TEST) $(HMACTEST) \ | ||
50 | $(RC2TEST) $(RC4TEST) $(RC5TEST) \ | ||
51 | $(DESTEST) $(SHATEST) $(SHA1TEST) $(MDC2TEST) $(RMDTEST) \ | ||
52 | $(RANDTEST) $(DHTEST) \ | ||
53 | $(BFTEST) $(CASTTEST) $(SSLTEST) $(EXPTEST) $(DSATEST) | ||
54 | |||
55 | # $(METHTEST) | ||
56 | |||
57 | OBJ= $(BNTEST).o $(IDEATEST).o $(MD2TEST).o $(MD5TEST).o $(HMACTEST).o \ | ||
58 | $(RC2TEST).o $(RC4TEST).o $(RC5TEST).o \ | ||
59 | $(DESTEST).o $(SHATEST).o $(SHA1TEST).o $(MDC2TEST).o $(RMDTEST).o \ | ||
60 | $(RANDTEST).o $(DHTEST).o $(CASTTEST).o \ | ||
61 | $(BFTEST).o $(SSLTEST).o $(DSATEST).o $(EXPTEST).o | ||
62 | SRC= $(BNTEST).c $(IDEATEST).c $(MD2TEST).c $(MD5TEST).c $(HMACTEST).c \ | ||
63 | $(RC2TEST).c $(RC4TEST).c $(RC5TEST).c \ | ||
64 | $(DESTEST).c $(SHATEST).c $(SHA1TEST).c $(MDC2TEST).c $(RMDTEST).c \ | ||
65 | $(RANDTEST).c $(DHTEST).c $(CASTTEST).c \ | ||
66 | $(BFTEST).c $(SSLTEST).c $(DSATEST).c $(EXPTEST).c | ||
67 | |||
68 | EXHEADER= | ||
69 | HEADER= $(EXHEADER) | ||
70 | |||
71 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
72 | |||
73 | top: | ||
74 | (cd ..; $(MAKE) DIRS=$(DIR) all) | ||
75 | |||
76 | all: exe | ||
77 | |||
78 | exe: $(EXE) | ||
79 | |||
80 | files: | ||
81 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
82 | |||
83 | links: | ||
84 | /bin/rm -f Makefile | ||
85 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
86 | |||
87 | errors: | ||
88 | |||
89 | install: | ||
90 | |||
91 | tags: | ||
92 | ctags $(SRC) | ||
93 | |||
94 | tests: exe apps \ | ||
95 | test_des test_idea test_sha test_md5 test_hmac test_md2 test_mdc2 \ | ||
96 | test_rc2 test_rc4 test_rc5 test_bf test_cast \ | ||
97 | test_rand test_enc test_x509 test_rsa test_crl test_sid test_req \ | ||
98 | test_pkcs7 test_bn test_verify test_dh test_dsa test_reqgen \ | ||
99 | test_ss test_ssl test_ca | ||
100 | |||
101 | apps: | ||
102 | @(cd ../apps; $(MAKE) CC='${CC}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' all) | ||
103 | |||
104 | test_des: | ||
105 | #./$(DESTEST) | ||
106 | |||
107 | test_idea: | ||
108 | ./$(IDEATEST) | ||
109 | |||
110 | test_sha: | ||
111 | ./$(SHATEST) | ||
112 | ./$(SHA1TEST) | ||
113 | |||
114 | test_mdc2: | ||
115 | ./$(MDC2TEST) | ||
116 | |||
117 | test_md5: | ||
118 | ./$(MD5TEST) | ||
119 | |||
120 | test_hmac: | ||
121 | ./$(HMACTEST) | ||
122 | |||
123 | test_md2: | ||
124 | ./$(MD2TEST) | ||
125 | |||
126 | test_rmd: | ||
127 | ./$(RMDTEST) | ||
128 | |||
129 | test_bf: | ||
130 | ./$(BFTEST) | ||
131 | |||
132 | test_cast: | ||
133 | ./$(CASTTEST) | ||
134 | |||
135 | test_rc2: | ||
136 | ./$(RC2TEST) | ||
137 | |||
138 | test_rc4: | ||
139 | ./$(RC4TEST) | ||
140 | |||
141 | test_rc5: | ||
142 | ./$(RC5TEST) | ||
143 | |||
144 | test_rand: | ||
145 | ./$(RANDTEST) | ||
146 | |||
147 | test_enc: | ||
148 | @sh ./testenc | ||
149 | |||
150 | test_x509: | ||
151 | echo test normal x509v1 certificate | ||
152 | sh ./tx509 2>/dev/null | ||
153 | echo test first x509v3 certificate | ||
154 | sh ./tx509 v3-cert1.pem 2>/dev/null | ||
155 | echo test second x509v3 certificate | ||
156 | sh ./tx509 v3-cert2.pem 2>/dev/null | ||
157 | |||
158 | test_rsa: | ||
159 | @sh ./trsa 2>/dev/null | ||
160 | |||
161 | test_crl: | ||
162 | @sh ./tcrl 2>/dev/null | ||
163 | |||
164 | test_sid: | ||
165 | @sh ./tsid 2>/dev/null | ||
166 | |||
167 | test_req: | ||
168 | @sh ./treq 2>/dev/null | ||
169 | @sh ./treq testreq2.pem 2>/dev/null | ||
170 | |||
171 | test_pkcs7: | ||
172 | @sh ./tpkcs7 2>/dev/null | ||
173 | @sh ./tpkcs7d 2>/dev/null | ||
174 | |||
175 | test_bn: | ||
176 | @echo 'test a^b%c implementations' | ||
177 | ./$(EXPTEST) | ||
178 | @echo starting big number library test, could take a while... | ||
179 | @(./$(BNTEST)|bc) | awk '{ \ | ||
180 | if ($$0 != "0") {print "error"; exit(1); } \ | ||
181 | if (((NR+1)%64) == 0) print NR+1," tests done"; }' | ||
182 | |||
183 | test_verify: | ||
184 | @echo "The following command should have some OK's and some failures" | ||
185 | @echo "There are definitly a few expired certificates" | ||
186 | ../apps/ssleay verify -CApath ../certs ../certs/*.pem | ||
187 | |||
188 | test_dh: | ||
189 | @echo "Generate as set of DH parameters" | ||
190 | ./$(DHTEST) | ||
191 | |||
192 | test_dsa: | ||
193 | @echo "Generate as set of DSA parameters" | ||
194 | ./$(DSATEST) | ||
195 | |||
196 | test_reqgen: | ||
197 | @echo "Generate and verify a certificate request" | ||
198 | @sh ./testgen | ||
199 | |||
200 | test_ss: | ||
201 | @echo "Generate and certify a test certificate" | ||
202 | @sh ./testss | ||
203 | |||
204 | test_ssl: | ||
205 | @echo "test SSL protocol" | ||
206 | @sh ./testssl | ||
207 | |||
208 | test_ca: | ||
209 | @echo "Generate and certify a test certificate via the 'ca' program" | ||
210 | @sh ./testca | ||
211 | |||
212 | lint: | ||
213 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
214 | |||
215 | depend: | ||
216 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(SRC) | ||
217 | |||
218 | dclean: | ||
219 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
220 | mv -f Makefile.new $(MAKEFILE) | ||
221 | |||
222 | clean: | ||
223 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff $(EXE) *.ss log | ||
224 | |||
225 | $(DLIBSSL): | ||
226 | (cd ../ssl; $(MAKE)) | ||
227 | |||
228 | $(DLIBCRYPTO): | ||
229 | (cd ../crypto; $(MAKE)) | ||
230 | |||
231 | $(BNTEST): $(BNTEST).o $(DLIBCRYPTO) | ||
232 | $(CC) -o $(BNTEST) $(CFLAGS) $(BNTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
233 | |||
234 | $(EXPTEST): $(EXPTEST).o $(DLIBCRYPTO) | ||
235 | $(CC) -o $(EXPTEST) $(CFLAGS) $(EXPTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
236 | |||
237 | $(IDEATEST): $(IDEATEST).o $(DLIBCRYPTO) | ||
238 | $(CC) -o $(IDEATEST) $(CFLAGS) $(IDEATEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
239 | |||
240 | $(MD2TEST): $(MD2TEST).o $(DLIBCRYPTO) | ||
241 | $(CC) -o $(MD2TEST) $(CFLAGS) $(MD2TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
242 | |||
243 | $(SHATEST): $(SHATEST).o $(DLIBCRYPTO) | ||
244 | $(CC) -o $(SHATEST) $(CFLAGS) $(SHATEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
245 | |||
246 | $(SHA1TEST): $(SHA1TEST).o $(DLIBCRYPTO) | ||
247 | $(CC) -o $(SHA1TEST) $(CFLAGS) $(SHA1TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
248 | |||
249 | $(RMDTEST): $(RMDTEST).o $(DLIBCRYPTO) | ||
250 | $(CC) -o $(RMDTEST) $(CFLAGS) $(RMDTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
251 | |||
252 | $(MDC2TEST): $(MDC2TEST).o $(DLIBCRYPTO) | ||
253 | $(CC) -o $(MDC2TEST) $(CFLAGS) $(MDC2TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
254 | |||
255 | $(MD5TEST): $(MD5TEST).o $(DLIBCRYPTO) | ||
256 | $(CC) -o $(MD5TEST) $(CFLAGS) $(MD5TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
257 | |||
258 | $(HMACTEST): $(HMACTEST).o $(DLIBCRYPTO) | ||
259 | $(CC) -o $(HMACTEST) $(CFLAGS) $(HMACTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
260 | |||
261 | $(RC2TEST): $(RC2TEST).o $(DLIBCRYPTO) | ||
262 | $(CC) -o $(RC2TEST) $(CFLAGS) $(RC2TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
263 | |||
264 | $(BFTEST): $(BFTEST).o $(DLIBCRYPTO) | ||
265 | $(CC) -o $(BFTEST) $(CFLAGS) $(BFTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
266 | |||
267 | $(CASTTEST): $(CASTTEST).o $(DLIBCRYPTO) | ||
268 | $(CC) -o $(CASTTEST) $(CFLAGS) $(CASTTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
269 | |||
270 | $(RC4TEST): $(RC4TEST).o $(DLIBCRYPTO) | ||
271 | $(CC) -o $(RC4TEST) $(CFLAGS) $(RC4TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
272 | |||
273 | $(RC5TEST): $(RC5TEST).o $(DLIBCRYPTO) | ||
274 | $(CC) -o $(RC5TEST) $(CFLAGS) $(RC5TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
275 | |||
276 | $(DESTEST): $(DESTEST).o $(DLIBCRYPTO) | ||
277 | $(CC) -o $(DESTEST) $(CFLAGS) $(DESTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
278 | |||
279 | $(RANDTEST): $(RANDTEST).o $(DLIBCRYPTO) | ||
280 | $(CC) -o $(RANDTEST) $(CFLAGS) $(RANDTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
281 | |||
282 | $(DHTEST): $(DHTEST).o $(DLIBCRYPTO) | ||
283 | $(CC) -o $(DHTEST) $(CFLAGS) $(DHTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
284 | |||
285 | $(DSATEST): $(DSATEST).o $(DLIBCRYPTO) | ||
286 | $(CC) -o $(DSATEST) $(CFLAGS) $(DSATEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
287 | |||
288 | $(METHTEST): $(METHTEST).o $(DLIBCRYPTO) | ||
289 | $(CC) -o $(METHTEST) $(CFLAGS) $(METHTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) | ||
290 | |||
291 | $(SSLTEST): $(SSLTEST).o $(DLIBSSL) $(DLIBCRYPTO) | ||
292 | $(CC) -o $(SSLTEST) $(CFLAGS) $(SSLTEST).o $(PEX_LIBS) $(LIBSSL) $(LIBCRYPTO) $(EX_LIBS) | ||
293 | |||
294 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/regress/lib/libc/db/Makefile b/src/regress/lib/libc/db/Makefile index 5bf343bf64..d42dc96315 100644 --- a/src/regress/lib/libc/db/Makefile +++ b/src/regress/lib/libc/db/Makefile | |||
@@ -1,11 +1,11 @@ | |||
1 | # $NetBSD: Makefile,v 1.10 1995/04/20 22:39:11 cgd Exp $ | 1 | # $NetBSD: Makefile,v 1.11 1995/12/12 01:54:15 cgd Exp $ |
2 | # @(#)Makefile 8.1 (Berkeley) 6/4/93 | 2 | # @(#)Makefile 8.1 (Berkeley) 6/4/93 |
3 | 3 | ||
4 | PROG= dbtest | 4 | PROG= dbtest |
5 | 5 | ||
6 | # add -DSTATISTICS to CFLAGS to get usage statistics. Note that | 6 | # add -DSTATISTICS to CFLAGS to get usage statistics. Note that |
7 | # for this to work, libc must be compiled with -DSTATISTICS as well | 7 | # for this to work, libc must be compiled with -DSTATISTICS as well |
8 | CFLAGS= -g -D__DBINTERFACE_PRIVATE -DDEBUG | 8 | CFLAGS+= -g -D__DBINTERFACE_PRIVATE -DDEBUG |
9 | NOMAN= noman | 9 | NOMAN= noman |
10 | CLEANFILES+= t1 t2 t3 | 10 | CLEANFILES+= t1 t2 t3 |
11 | 11 | ||
diff --git a/src/regress/lib/libc/db/README b/src/regress/lib/libc/db/README index 3b290b09d8..fddf5c3d5a 100644 --- a/src/regress/lib/libc/db/README +++ b/src/regress/lib/libc/db/README | |||
@@ -1,5 +1,5 @@ | |||
1 | # $NetBSD: README,v 1.4 1995/04/20 22:39:18 cgd Exp $ | 1 | # $NetBSD: README,v 1.5 1996/05/03 21:54:19 cgd Exp $ |
2 | # @(#)README 8.4 (Berkeley) 6/20/94 | 2 | # @(#)README 8.8 (Berkeley) 7/31/94 |
3 | 3 | ||
4 | To run the tests, enter "make regress". | 4 | To run the tests, enter "make regress". |
5 | 5 | ||
@@ -9,8 +9,11 @@ the test runs, and even larger files (the database files) are created in | |||
9 | variable TMPDIR to a directory where the files can be built. | 9 | variable TMPDIR to a directory where the files can be built. |
10 | 10 | ||
11 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | 11 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
12 | The script file consists of lines with a initial character which is | 12 | The script file consists of lines with an initial character which is |
13 | the "command" for that line. Legal characters are as follows: | 13 | the command for that line, or an initial character indicating a key |
14 | or data entry for a previous command. | ||
15 | |||
16 | Legal command characters are as follows: | ||
14 | 17 | ||
15 | c: compare a record | 18 | c: compare a record |
16 | + must be followed by [kK][dD]; the data value in the database | 19 | + must be followed by [kK][dD]; the data value in the database |
@@ -19,17 +22,24 @@ c: compare a record | |||
19 | e: echo a string | 22 | e: echo a string |
20 | + writes out the rest of the line into the output file; if the | 23 | + writes out the rest of the line into the output file; if the |
21 | last character is not a carriage-return, a newline is appended. | 24 | last character is not a carriage-return, a newline is appended. |
25 | f: set the flags for the next command | ||
26 | + no value zero's the flags | ||
22 | g: do a get command | 27 | g: do a get command |
23 | + must be followed by [kK] | 28 | + must be followed by [kK] |
24 | + writes out the retrieved data DBT. | 29 | + writes out the retrieved data DBT. |
30 | o [r]: dump [reverse] | ||
31 | + dump the database out, if 'r' is set, in reverse order. | ||
25 | p: do a put command | 32 | p: do a put command |
26 | + must be followed by [kK][dD] | 33 | + must be followed by [kK][dD] |
27 | r: do a del command | 34 | r: do a del command |
28 | + must be followed by [kK] | 35 | + must be followed by [kK] unless R_CURSOR flag set. |
36 | S: sync the database | ||
29 | s: do a seq command | 37 | s: do a seq command |
38 | + must be followed by [kK] if R_CURSOR flag set. | ||
30 | + writes out the retrieved data DBT. | 39 | + writes out the retrieved data DBT. |
31 | f: set the flags for the next command | 40 | |
32 | + no value zero's the flags | 41 | Legal key/data characters are as follows: |
42 | |||
33 | D [file]: data file | 43 | D [file]: data file |
34 | + set the current data value to the contents of the file | 44 | + set the current data value to the contents of the file |
35 | d [data]: | 45 | d [data]: |
@@ -38,17 +48,21 @@ K [file]: key file | |||
38 | + set the current key value to the contents of the file | 48 | + set the current key value to the contents of the file |
39 | k [data]: | 49 | k [data]: |
40 | + set the current key value to the contents of the line. | 50 | + set the current key value to the contents of the line. |
41 | o [r]: dump [reverse] | 51 | |
42 | + dump the database out, if 'r' is set, in reverse order. | 52 | Blank lines, lines with leading white space, and lines with leading |
53 | hash marks (#) are ignored. | ||
43 | 54 | ||
44 | Options to dbtest are as follows: | 55 | Options to dbtest are as follows: |
45 | 56 | ||
57 | -d: Set the DB_LOCK flag. | ||
46 | -f: Use the file argument as the database file. | 58 | -f: Use the file argument as the database file. |
47 | -i: Use the rest of the argument to set elements in the info | 59 | -i: Use the rest of the argument to set elements in the info |
48 | structure. If the type is btree, then "-i cachesize=10240" | 60 | structure. If the type is btree, then "-i cachesize=10240" |
49 | will set BTREEINFO.cachesize to 10240. | 61 | will set BTREEINFO.cachesize to 10240. |
50 | -o: The rest of the argument is the output file instead of | 62 | -o: The rest of the argument is the output file instead of |
51 | using stdout. | 63 | using stdout. |
64 | -s: Don't delete the database file before opening it, i.e. | ||
65 | use the database file from a previous run. | ||
52 | 66 | ||
53 | Dbtest requires two arguments, the type of access "hash", "recno" or | 67 | Dbtest requires two arguments, the type of access "hash", "recno" |
54 | "btree", and the script name. | 68 | or "btree", and the script name or "-" to indicate stdin. |
diff --git a/src/regress/lib/libc/db/dbtest.c b/src/regress/lib/libc/db/dbtest.c index 1fcf09af97..6ccfba5011 100644 --- a/src/regress/lib/libc/db/dbtest.c +++ b/src/regress/lib/libc/db/dbtest.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* $NetBSD: dbtest.c,v 1.7 1995/04/20 22:39:22 cgd Exp $ */ | 1 | /* $NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $ */ |
2 | 2 | ||
3 | /*- | 3 | /*- |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993, 1994 |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
@@ -35,15 +35,15 @@ | |||
35 | 35 | ||
36 | #ifndef lint | 36 | #ifndef lint |
37 | static char copyright[] = | 37 | static char copyright[] = |
38 | "@(#) Copyright (c) 1992, 1993\n\ | 38 | "@(#) Copyright (c) 1992, 1993, 1994\n\ |
39 | The Regents of the University of California. All rights reserved.\n"; | 39 | The Regents of the University of California. All rights reserved.\n"; |
40 | #endif /* not lint */ | 40 | #endif /* not lint */ |
41 | 41 | ||
42 | #ifndef lint | 42 | #ifndef lint |
43 | #if 0 | 43 | #if 0 |
44 | static char sccsid[] = "@(#)dbtest.c 8.8 (Berkeley) 2/21/94"; | 44 | static char sccsid[] = "@(#)dbtest.c 8.17 (Berkeley) 9/1/94"; |
45 | #else | 45 | #else |
46 | static char rcsid[] = "$NetBSD: dbtest.c,v 1.7 1995/04/20 22:39:22 cgd Exp $"; | 46 | static char rcsid[] = "$NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $"; |
47 | #endif | 47 | #endif |
48 | #endif /* not lint */ | 48 | #endif /* not lint */ |
49 | 49 | ||
@@ -71,6 +71,8 @@ void get __P((DB *, DBT *)); | |||
71 | void getdata __P((DB *, DBT *, DBT *)); | 71 | void getdata __P((DB *, DBT *, DBT *)); |
72 | void put __P((DB *, DBT *, DBT *)); | 72 | void put __P((DB *, DBT *, DBT *)); |
73 | void rem __P((DB *, DBT *)); | 73 | void rem __P((DB *, DBT *)); |
74 | char *sflags __P((int)); | ||
75 | void synk __P((DB *)); | ||
74 | void *rfile __P((char *, size_t *)); | 76 | void *rfile __P((char *, size_t *)); |
75 | void seq __P((DB *, DBT *)); | 77 | void seq __P((DB *, DBT *)); |
76 | u_int setflags __P((char *)); | 78 | u_int setflags __P((char *)); |
@@ -78,13 +80,14 @@ void *setinfo __P((DBTYPE, char *)); | |||
78 | void usage __P((void)); | 80 | void usage __P((void)); |
79 | void *xmalloc __P((char *, size_t)); | 81 | void *xmalloc __P((char *, size_t)); |
80 | 82 | ||
81 | DBTYPE type; | 83 | DBTYPE type; /* Database type. */ |
82 | void *infop; | 84 | void *infop; /* Iflags. */ |
83 | u_long lineno; | 85 | u_long lineno; /* Current line in test script. */ |
84 | u_int flags; | 86 | u_int flags; /* Current DB flags. */ |
85 | int ofd = STDOUT_FILENO; | 87 | int ofd = STDOUT_FILENO; /* Standard output fd. */ |
86 | 88 | ||
87 | DB *XXdbp; /* Global for gdb. */ | 89 | DB *XXdbp; /* Global for gdb. */ |
90 | int XXlineno; /* Fast breakpoint for gdb. */ | ||
88 | 91 | ||
89 | int | 92 | int |
90 | main(argc, argv) | 93 | main(argc, argv) |
@@ -97,14 +100,15 @@ main(argc, argv) | |||
97 | DB *dbp; | 100 | DB *dbp; |
98 | DBT data, key, keydata; | 101 | DBT data, key, keydata; |
99 | size_t len; | 102 | size_t len; |
100 | int ch, oflags; | 103 | int ch, oflags, sflag; |
101 | char *fname, *infoarg, *p, buf[8 * 1024]; | 104 | char *fname, *infoarg, *p, *t, buf[8 * 1024]; |
102 | 105 | ||
103 | infoarg = NULL; | 106 | infoarg = NULL; |
104 | fname = NULL; | 107 | fname = NULL; |
105 | oflags = O_CREAT | O_RDWR; | 108 | oflags = O_CREAT | O_RDWR; |
106 | while ((ch = getopt(argc, argv, "f:i:lo:")) != EOF) | 109 | sflag = 0; |
107 | switch(ch) { | 110 | while ((ch = getopt(argc, argv, "f:i:lo:s")) != -1) |
111 | switch (ch) { | ||
108 | case 'f': | 112 | case 'f': |
109 | fname = optarg; | 113 | fname = optarg; |
110 | break; | 114 | break; |
@@ -119,6 +123,9 @@ main(argc, argv) | |||
119 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) | 123 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) |
120 | err("%s: %s", optarg, strerror(errno)); | 124 | err("%s: %s", optarg, strerror(errno)); |
121 | break; | 125 | break; |
126 | case 's': | ||
127 | sflag = 1; | ||
128 | break; | ||
122 | case '?': | 129 | case '?': |
123 | default: | 130 | default: |
124 | usage(); | 131 | usage(); |
@@ -133,8 +140,8 @@ main(argc, argv) | |||
133 | type = dbtype(*argv++); | 140 | type = dbtype(*argv++); |
134 | 141 | ||
135 | /* Open the descriptor file. */ | 142 | /* Open the descriptor file. */ |
136 | if (freopen(*argv, "r", stdin) == NULL) | 143 | if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) |
137 | err("%s: %s", *argv, strerror(errno)); | 144 | err("%s: %s", *argv, strerror(errno)); |
138 | 145 | ||
139 | /* Set up the db structure as necessary. */ | 146 | /* Set up the db structure as necessary. */ |
140 | if (infoarg == NULL) | 147 | if (infoarg == NULL) |
@@ -145,7 +152,10 @@ main(argc, argv) | |||
145 | if (*p != '\0') | 152 | if (*p != '\0') |
146 | infop = setinfo(type, p); | 153 | infop = setinfo(type, p); |
147 | 154 | ||
148 | /* Open the DB. */ | 155 | /* |
156 | * Open the DB. Delete any preexisting copy, you almost never | ||
157 | * want it around, and it often screws up tests. | ||
158 | */ | ||
149 | if (fname == NULL) { | 159 | if (fname == NULL) { |
150 | p = getenv("TMPDIR"); | 160 | p = getenv("TMPDIR"); |
151 | if (p == NULL) | 161 | if (p == NULL) |
@@ -153,7 +163,9 @@ main(argc, argv) | |||
153 | (void)sprintf(buf, "%s/__dbtest", p); | 163 | (void)sprintf(buf, "%s/__dbtest", p); |
154 | fname = buf; | 164 | fname = buf; |
155 | (void)unlink(buf); | 165 | (void)unlink(buf); |
156 | } | 166 | } else if (!sflag) |
167 | (void)unlink(fname); | ||
168 | |||
157 | if ((dbp = dbopen(fname, | 169 | if ((dbp = dbopen(fname, |
158 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) | 170 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) |
159 | err("dbopen: %s", strerror(errno)); | 171 | err("dbopen: %s", strerror(errno)); |
@@ -162,8 +174,16 @@ main(argc, argv) | |||
162 | state = COMMAND; | 174 | state = COMMAND; |
163 | for (lineno = 1; | 175 | for (lineno = 1; |
164 | (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { | 176 | (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { |
165 | len = strlen(buf); | 177 | /* Delete the newline, displaying the key/data is easier. */ |
166 | switch(*p) { | 178 | if (ofd == STDOUT_FILENO && (t = strchr(p, '\n')) != NULL) |
179 | *t = '\0'; | ||
180 | if ((len = strlen(buf)) == 0 || isspace(*p) || *p == '#') | ||
181 | continue; | ||
182 | |||
183 | /* Convenient gdb break point. */ | ||
184 | if (XXlineno == lineno) | ||
185 | XXlineno = 1; | ||
186 | switch (*p) { | ||
167 | case 'c': /* compare */ | 187 | case 'c': /* compare */ |
168 | if (state != COMMAND) | 188 | if (state != COMMAND) |
169 | err("line %lu: not expecting command", lineno); | 189 | err("line %lu: not expecting command", lineno); |
@@ -176,7 +196,8 @@ main(argc, argv) | |||
176 | /* Don't display the newline, if CR at EOL. */ | 196 | /* Don't display the newline, if CR at EOL. */ |
177 | if (p[len - 2] == '\r') | 197 | if (p[len - 2] == '\r') |
178 | --len; | 198 | --len; |
179 | if (write(ofd, p + 1, len - 1) != len - 1) | 199 | if (write(ofd, p + 1, len - 1) != len - 1 || |
200 | write(ofd, "\n", 1) != 1) | ||
180 | err("write: %s", strerror(errno)); | 201 | err("write: %s", strerror(errno)); |
181 | break; | 202 | break; |
182 | case 'g': /* get */ | 203 | case 'g': /* get */ |
@@ -194,8 +215,19 @@ main(argc, argv) | |||
194 | case 'r': /* remove */ | 215 | case 'r': /* remove */ |
195 | if (state != COMMAND) | 216 | if (state != COMMAND) |
196 | err("line %lu: not expecting command", lineno); | 217 | err("line %lu: not expecting command", lineno); |
197 | state = KEY; | 218 | if (flags == R_CURSOR) { |
198 | command = REMOVE; | 219 | rem(dbp, &key); |
220 | state = COMMAND; | ||
221 | } else { | ||
222 | state = KEY; | ||
223 | command = REMOVE; | ||
224 | } | ||
225 | break; | ||
226 | case 'S': /* sync */ | ||
227 | if (state != COMMAND) | ||
228 | err("line %lu: not expecting command", lineno); | ||
229 | synk(dbp); | ||
230 | state = COMMAND; | ||
199 | break; | 231 | break; |
200 | case 's': /* seq */ | 232 | case 's': /* seq */ |
201 | if (state != COMMAND) | 233 | if (state != COMMAND) |
@@ -219,7 +251,7 @@ main(argc, argv) | |||
219 | err("line %lu: not expecting data", lineno); | 251 | err("line %lu: not expecting data", lineno); |
220 | data.data = xmalloc(p + 1, len - 1); | 252 | data.data = xmalloc(p + 1, len - 1); |
221 | data.size = len - 1; | 253 | data.size = len - 1; |
222 | ldata: switch(command) { | 254 | ldata: switch (command) { |
223 | case COMPARE: | 255 | case COMPARE: |
224 | compare(&keydata, &data); | 256 | compare(&keydata, &data); |
225 | break; | 257 | break; |
@@ -255,7 +287,7 @@ ldata: switch(command) { | |||
255 | key.data = xmalloc(p + 1, len - 1); | 287 | key.data = xmalloc(p + 1, len - 1); |
256 | key.size = len - 1; | 288 | key.size = len - 1; |
257 | } | 289 | } |
258 | lkey: switch(command) { | 290 | lkey: switch (command) { |
259 | case COMPARE: | 291 | case COMPARE: |
260 | getdata(dbp, &key, &keydata); | 292 | getdata(dbp, &key, &keydata); |
261 | state = DATA; | 293 | state = DATA; |
@@ -271,13 +303,13 @@ lkey: switch(command) { | |||
271 | break; | 303 | break; |
272 | case REMOVE: | 304 | case REMOVE: |
273 | rem(dbp, &key); | 305 | rem(dbp, &key); |
274 | if (type != DB_RECNO) | 306 | if ((type != DB_RECNO) && (flags != R_CURSOR)) |
275 | free(key.data); | 307 | free(key.data); |
276 | state = COMMAND; | 308 | state = COMMAND; |
277 | break; | 309 | break; |
278 | case SEQ: | 310 | case SEQ: |
279 | seq(dbp, &key); | 311 | seq(dbp, &key); |
280 | if (type != DB_RECNO) | 312 | if ((type != DB_RECNO) && (flags != R_CURSOR)) |
281 | free(key.data); | 313 | free(key.data); |
282 | state = COMMAND; | 314 | state = COMMAND; |
283 | break; | 315 | break; |
@@ -291,11 +323,15 @@ lkey: switch(command) { | |||
291 | break; | 323 | break; |
292 | default: | 324 | default: |
293 | err("line %lu: %s: unknown command character", | 325 | err("line %lu: %s: unknown command character", |
294 | p, lineno); | 326 | lineno, p); |
295 | } | 327 | } |
296 | } | 328 | } |
297 | #ifdef STATISTICS | 329 | #ifdef STATISTICS |
298 | if (type == DB_BTREE) | 330 | /* |
331 | * -l must be used (DB_LOCK must be set) for this to be | ||
332 | * used, otherwise a page will be locked and it will fail. | ||
333 | */ | ||
334 | if (type == DB_BTREE && oflags & DB_LOCK) | ||
299 | __bt_stat(dbp); | 335 | __bt_stat(dbp); |
300 | #endif | 336 | #endif |
301 | if (dbp->close(dbp)) | 337 | if (dbp->close(dbp)) |
@@ -305,7 +341,6 @@ lkey: switch(command) { | |||
305 | } | 341 | } |
306 | 342 | ||
307 | #define NOOVERWRITE "put failed, would overwrite key\n" | 343 | #define NOOVERWRITE "put failed, would overwrite key\n" |
308 | #define NOSUCHKEY "get failed, no such key\n" | ||
309 | 344 | ||
310 | void | 345 | void |
311 | compare(db1, db2) | 346 | compare(db1, db2) |
@@ -334,17 +369,23 @@ get(dbp, kp) | |||
334 | { | 369 | { |
335 | DBT data; | 370 | DBT data; |
336 | 371 | ||
337 | switch(dbp->get(dbp, kp, &data, flags)) { | 372 | switch (dbp->get(dbp, kp, &data, flags)) { |
338 | case 0: | 373 | case 0: |
339 | (void)write(ofd, data.data, data.size); | 374 | (void)write(ofd, data.data, data.size); |
375 | if (ofd == STDOUT_FILENO) | ||
376 | (void)write(ofd, "\n", 1); | ||
340 | break; | 377 | break; |
341 | case -1: | 378 | case -1: |
342 | err("line %lu: get: %s", lineno, strerror(errno)); | 379 | err("line %lu: get: %s", lineno, strerror(errno)); |
343 | /* NOTREACHED */ | 380 | /* NOTREACHED */ |
344 | case 1: | 381 | case 1: |
345 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | 382 | #define NOSUCHKEY "get failed, no such key\n" |
346 | (void)fprintf(stderr, "%d: %.*s: %s\n", | 383 | if (ofd != STDOUT_FILENO) |
347 | lineno, kp->size, kp->data, NOSUCHKEY); | 384 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); |
385 | else | ||
386 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
387 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
388 | #undef NOSUCHKEY | ||
348 | break; | 389 | break; |
349 | } | 390 | } |
350 | } | 391 | } |
@@ -354,14 +395,14 @@ getdata(dbp, kp, dp) | |||
354 | DB *dbp; | 395 | DB *dbp; |
355 | DBT *kp, *dp; | 396 | DBT *kp, *dp; |
356 | { | 397 | { |
357 | switch(dbp->get(dbp, kp, dp, flags)) { | 398 | switch (dbp->get(dbp, kp, dp, flags)) { |
358 | case 0: | 399 | case 0: |
359 | return; | 400 | return; |
360 | case -1: | 401 | case -1: |
361 | err("line %lu: getdata: %s", lineno, strerror(errno)); | 402 | err("line %lu: getdata: %s", lineno, strerror(errno)); |
362 | /* NOTREACHED */ | 403 | /* NOTREACHED */ |
363 | case 1: | 404 | case 1: |
364 | err("line %lu: get failed, no such key", lineno); | 405 | err("line %lu: getdata failed, no such key", lineno); |
365 | /* NOTREACHED */ | 406 | /* NOTREACHED */ |
366 | } | 407 | } |
367 | } | 408 | } |
@@ -371,7 +412,7 @@ put(dbp, kp, dp) | |||
371 | DB *dbp; | 412 | DB *dbp; |
372 | DBT *kp, *dp; | 413 | DBT *kp, *dp; |
373 | { | 414 | { |
374 | switch(dbp->put(dbp, kp, dp, flags)) { | 415 | switch (dbp->put(dbp, kp, dp, flags)) { |
375 | case 0: | 416 | case 0: |
376 | break; | 417 | break; |
377 | case -1: | 418 | case -1: |
@@ -388,34 +429,67 @@ rem(dbp, kp) | |||
388 | DB *dbp; | 429 | DB *dbp; |
389 | DBT *kp; | 430 | DBT *kp; |
390 | { | 431 | { |
391 | switch(dbp->del(dbp, kp, flags)) { | 432 | switch (dbp->del(dbp, kp, flags)) { |
392 | case 0: | 433 | case 0: |
393 | break; | 434 | break; |
394 | case -1: | 435 | case -1: |
395 | err("line %lu: get: %s", lineno, strerror(errno)); | 436 | err("line %lu: rem: %s", lineno, strerror(errno)); |
396 | /* NOTREACHED */ | 437 | /* NOTREACHED */ |
397 | case 1: | 438 | case 1: |
398 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | 439 | #define NOSUCHKEY "rem failed, no such key\n" |
440 | if (ofd != STDOUT_FILENO) | ||
441 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
442 | else if (flags != R_CURSOR) | ||
443 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
444 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
445 | else | ||
446 | (void)fprintf(stderr, | ||
447 | "%d: rem of cursor failed\n", lineno); | ||
448 | #undef NOSUCHKEY | ||
399 | break; | 449 | break; |
400 | } | 450 | } |
401 | } | 451 | } |
402 | 452 | ||
403 | void | 453 | void |
454 | synk(dbp) | ||
455 | DB *dbp; | ||
456 | { | ||
457 | switch (dbp->sync(dbp, flags)) { | ||
458 | case 0: | ||
459 | break; | ||
460 | case -1: | ||
461 | err("line %lu: synk: %s", lineno, strerror(errno)); | ||
462 | /* NOTREACHED */ | ||
463 | } | ||
464 | } | ||
465 | |||
466 | void | ||
404 | seq(dbp, kp) | 467 | seq(dbp, kp) |
405 | DB *dbp; | 468 | DB *dbp; |
406 | DBT *kp; | 469 | DBT *kp; |
407 | { | 470 | { |
408 | DBT data; | 471 | DBT data; |
409 | 472 | ||
410 | switch(dbp->seq(dbp, kp, &data, flags)) { | 473 | switch (dbp->seq(dbp, kp, &data, flags)) { |
411 | case 0: | 474 | case 0: |
412 | (void)write(ofd, data.data, data.size); | 475 | (void)write(ofd, data.data, data.size); |
476 | if (ofd == STDOUT_FILENO) | ||
477 | (void)write(ofd, "\n", 1); | ||
413 | break; | 478 | break; |
414 | case -1: | 479 | case -1: |
415 | err("line %lu: seq: %s", lineno, strerror(errno)); | 480 | err("line %lu: seq: %s", lineno, strerror(errno)); |
416 | /* NOTREACHED */ | 481 | /* NOTREACHED */ |
417 | case 1: | 482 | case 1: |
418 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | 483 | #define NOSUCHKEY "seq failed, no such key\n" |
484 | if (ofd != STDOUT_FILENO) | ||
485 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
486 | else if (flags == R_CURSOR) | ||
487 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
488 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
489 | else | ||
490 | (void)fprintf(stderr, | ||
491 | "%d: seq (%s) failed\n", lineno, sflags(flags)); | ||
492 | #undef NOSUCHKEY | ||
419 | break; | 493 | break; |
420 | } | 494 | } |
421 | } | 495 | } |
@@ -436,9 +510,11 @@ dump(dbp, rev) | |||
436 | nflags = R_NEXT; | 510 | nflags = R_NEXT; |
437 | } | 511 | } |
438 | for (;; flags = nflags) | 512 | for (;; flags = nflags) |
439 | switch(dbp->seq(dbp, &key, &data, flags)) { | 513 | switch (dbp->seq(dbp, &key, &data, flags)) { |
440 | case 0: | 514 | case 0: |
441 | (void)write(ofd, data.data, data.size); | 515 | (void)write(ofd, data.data, data.size); |
516 | if (ofd == STDOUT_FILENO) | ||
517 | (void)write(ofd, "\n", 1); | ||
442 | break; | 518 | break; |
443 | case 1: | 519 | case 1: |
444 | goto done; | 520 | goto done; |
@@ -454,34 +530,45 @@ u_int | |||
454 | setflags(s) | 530 | setflags(s) |
455 | char *s; | 531 | char *s; |
456 | { | 532 | { |
457 | char *p, *index(); | 533 | char *p; |
458 | 534 | ||
459 | for (; isspace(*s); ++s); | 535 | for (; isspace(*s); ++s); |
460 | if (*s == '\n') | 536 | if (*s == '\n' || *s == '\0') |
461 | return (0); | 537 | return (0); |
462 | if ((p = index(s, '\n')) != NULL) | 538 | if ((p = strchr(s, '\n')) != NULL) |
463 | *p = '\0'; | 539 | *p = '\0'; |
464 | if (!strcmp(s, "R_CURSOR")) | 540 | if (!strcmp(s, "R_CURSOR")) return (R_CURSOR); |
465 | return (R_CURSOR); | 541 | if (!strcmp(s, "R_FIRST")) return (R_FIRST); |
466 | if (!strcmp(s, "R_FIRST")) | 542 | if (!strcmp(s, "R_IAFTER")) return (R_IAFTER); |
467 | return (R_FIRST); | 543 | if (!strcmp(s, "R_IBEFORE")) return (R_IBEFORE); |
468 | if (!strcmp(s, "R_IAFTER")) | 544 | if (!strcmp(s, "R_LAST")) return (R_LAST); |
469 | return (R_IAFTER); | 545 | if (!strcmp(s, "R_NEXT")) return (R_NEXT); |
470 | if (!strcmp(s, "R_IBEFORE")) | 546 | if (!strcmp(s, "R_NOOVERWRITE")) return (R_NOOVERWRITE); |
471 | return (R_IBEFORE); | 547 | if (!strcmp(s, "R_PREV")) return (R_PREV); |
472 | if (!strcmp(s, "R_LAST")) | 548 | if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR); |
473 | return (R_LAST); | 549 | |
474 | if (!strcmp(s, "R_NEXT")) | ||
475 | return (R_NEXT); | ||
476 | if (!strcmp(s, "R_NOOVERWRITE")) | ||
477 | return (R_NOOVERWRITE); | ||
478 | if (!strcmp(s, "R_PREV")) | ||
479 | return (R_PREV); | ||
480 | if (!strcmp(s, "R_SETCURSOR")) | ||
481 | return (R_SETCURSOR); | ||
482 | err("line %lu: %s: unknown flag", lineno, s); | 550 | err("line %lu: %s: unknown flag", lineno, s); |
483 | /* NOTREACHED */ | 551 | /* NOTREACHED */ |
484 | } | 552 | } |
553 | |||
554 | char * | ||
555 | sflags(flags) | ||
556 | int flags; | ||
557 | { | ||
558 | switch (flags) { | ||
559 | case R_CURSOR: return ("R_CURSOR"); | ||
560 | case R_FIRST: return ("R_FIRST"); | ||
561 | case R_IAFTER: return ("R_IAFTER"); | ||
562 | case R_IBEFORE: return ("R_IBEFORE"); | ||
563 | case R_LAST: return ("R_LAST"); | ||
564 | case R_NEXT: return ("R_NEXT"); | ||
565 | case R_NOOVERWRITE: return ("R_NOOVERWRITE"); | ||
566 | case R_PREV: return ("R_PREV"); | ||
567 | case R_SETCURSOR: return ("R_SETCURSOR"); | ||
568 | } | ||
569 | |||
570 | return ("UNKNOWN!"); | ||
571 | } | ||
485 | 572 | ||
486 | DBTYPE | 573 | DBTYPE |
487 | dbtype(s) | 574 | dbtype(s) |
@@ -505,15 +592,15 @@ setinfo(type, s) | |||
505 | static BTREEINFO ib; | 592 | static BTREEINFO ib; |
506 | static HASHINFO ih; | 593 | static HASHINFO ih; |
507 | static RECNOINFO rh; | 594 | static RECNOINFO rh; |
508 | char *eq, *index(); | 595 | char *eq; |
509 | 596 | ||
510 | if ((eq = index(s, '=')) == NULL) | 597 | if ((eq = strchr(s, '=')) == NULL) |
511 | err("%s: illegal structure set statement", s); | 598 | err("%s: illegal structure set statement", s); |
512 | *eq++ = '\0'; | 599 | *eq++ = '\0'; |
513 | if (!isdigit(*eq)) | 600 | if (!isdigit(*eq)) |
514 | err("%s: structure set statement must be a number", s); | 601 | err("%s: structure set statement must be a number", s); |
515 | 602 | ||
516 | switch(type) { | 603 | switch (type) { |
517 | case DB_BTREE: | 604 | case DB_BTREE: |
518 | if (!strcmp("flags", s)) { | 605 | if (!strcmp("flags", s)) { |
519 | ib.flags = atoi(eq); | 606 | ib.flags = atoi(eq); |
@@ -601,10 +688,10 @@ rfile(name, lenp) | |||
601 | struct stat sb; | 688 | struct stat sb; |
602 | void *p; | 689 | void *p; |
603 | int fd; | 690 | int fd; |
604 | char *np, *index(); | 691 | char *np; |
605 | 692 | ||
606 | for (; isspace(*name); ++name); | 693 | for (; isspace(*name); ++name); |
607 | if ((np = index(name, '\n')) != NULL) | 694 | if ((np = strchr(name, '\n')) != NULL) |
608 | *np = '\0'; | 695 | *np = '\0'; |
609 | if ((fd = open(name, O_RDONLY, 0)) < 0 || | 696 | if ((fd = open(name, O_RDONLY, 0)) < 0 || |
610 | fstat(fd, &sb)) | 697 | fstat(fd, &sb)) |
@@ -642,14 +729,14 @@ usage() | |||
642 | exit(1); | 729 | exit(1); |
643 | } | 730 | } |
644 | 731 | ||
645 | #if __STDC__ | 732 | #ifdef __STDC__ |
646 | #include <stdarg.h> | 733 | #include <stdarg.h> |
647 | #else | 734 | #else |
648 | #include <varargs.h> | 735 | #include <varargs.h> |
649 | #endif | 736 | #endif |
650 | 737 | ||
651 | void | 738 | void |
652 | #if __STDC__ | 739 | #ifdef __STDC__ |
653 | err(const char *fmt, ...) | 740 | err(const char *fmt, ...) |
654 | #else | 741 | #else |
655 | err(fmt, va_alist) | 742 | err(fmt, va_alist) |
@@ -658,7 +745,7 @@ err(fmt, va_alist) | |||
658 | #endif | 745 | #endif |
659 | { | 746 | { |
660 | va_list ap; | 747 | va_list ap; |
661 | #if __STDC__ | 748 | #ifdef __STDC__ |
662 | va_start(ap, fmt); | 749 | va_start(ap, fmt); |
663 | #else | 750 | #else |
664 | va_start(ap); | 751 | va_start(ap); |
diff --git a/src/regress/lib/libc/db/run.test b/src/regress/lib/libc/db/run.test index 4073310a31..acbd3f49e1 100644 --- a/src/regress/lib/libc/db/run.test +++ b/src/regress/lib/libc/db/run.test | |||
@@ -1,19 +1,27 @@ | |||
1 | #!/bin/sh - | 1 | #!/bin/sh - |
2 | # $NetBSD: run.test,v 1.7 1995/04/20 22:39:27 cgd Exp $ | ||
3 | # | 2 | # |
4 | # @(#)run.test 8.8 (Berkeley) 6/16/94 | 3 | # $NetBSD: run.test,v 1.8 1996/05/03 21:57:51 cgd Exp $ |
4 | # @(#)run.test 8.10 (Berkeley) 7/26/94 | ||
5 | # | 5 | # |
6 | 6 | ||
7 | # db regression tests | 7 | # db regression tests |
8 | main() | 8 | main() |
9 | { | 9 | { |
10 | 10 | ||
11 | DICT=/usr/share/dict/web2 | 11 | PROG=./dbtest |
12 | PROG=./dbtest | 12 | TMP1=t1 |
13 | TMP1=t1 | 13 | TMP2=t2 |
14 | TMP2=t2 | 14 | TMP3=t3 |
15 | TMP3=t3 | ||
16 | 15 | ||
16 | if [ -f /usr/share/dict/words ]; then | ||
17 | DICT=/usr/share/dict/words | ||
18 | elif [ -f /usr/dict/words ]; then | ||
19 | DICT=/usr/dict/words | ||
20 | else | ||
21 | echo 'run.test: no dictionary' | ||
22 | exit 1 | ||
23 | fi | ||
24 | |||
17 | if [ $# -eq 0 ]; then | 25 | if [ $# -eq 0 ]; then |
18 | for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do | 26 | for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do |
19 | test$t | 27 | test$t |
@@ -345,7 +353,7 @@ test7() | |||
345 | for (i = 1; i <= 120; ++i) | 353 | for (i = 1; i <= 120; ++i) |
346 | printf("%05d: input key %d: %s\n", i, i, $0); | 354 | printf("%05d: input key %d: %s\n", i, i, $0); |
347 | printf("%05d: input key %d: %s\n", 120, 120, $0); | 355 | printf("%05d: input key %d: %s\n", 120, 120, $0); |
348 | printf("get failed, no such key\n"); | 356 | printf("seq failed, no such key\n"); |
349 | printf("%05d: input key %d: %s\n", 1, 1, $0); | 357 | printf("%05d: input key %d: %s\n", 1, 1, $0); |
350 | printf("%05d: input key %d: %s\n", 2, 2, $0); | 358 | printf("%05d: input key %d: %s\n", 2, 2, $0); |
351 | exit; | 359 | exit; |
@@ -364,10 +372,10 @@ test7() | |||
364 | for (i = 1; i <= 120; ++i) | 372 | for (i = 1; i <= 120; ++i) |
365 | printf("s\n"); | 373 | printf("s\n"); |
366 | printf("fR_CURSOR\ns\nk120\n"); | 374 | printf("fR_CURSOR\ns\nk120\n"); |
367 | printf("r\nk120\n"); | 375 | printf("r\n"); |
368 | printf("fR_NEXT\ns\n"); | 376 | printf("fR_NEXT\ns\n"); |
369 | printf("fR_CURSOR\ns\nk1\n"); | 377 | printf("fR_CURSOR\ns\nk1\n"); |
370 | printf("r\nk1\n"); | 378 | printf("r\n"); |
371 | printf("fR_FIRST\ns\n"); | 379 | printf("fR_FIRST\ns\n"); |
372 | }' > $TMP2 | 380 | }' > $TMP2 |
373 | $PROG -o $TMP3 recno $TMP2 | 381 | $PROG -o $TMP3 recno $TMP2 |
@@ -397,8 +405,6 @@ test8() | |||
397 | printf("e\t%d of 10 \n", i); | 405 | printf("e\t%d of 10 \n", i); |
398 | printf("r\nkkey1\nr\nkkey2\n"); | 406 | printf("r\nkkey1\nr\nkkey2\n"); |
399 | } | 407 | } |
400 | printf("e\n"); | ||
401 | printf("eend of test8 run\n"); | ||
402 | }' > $TMP1 | 408 | }' > $TMP1 |
403 | $PROG btree $TMP1 | 409 | $PROG btree $TMP1 |
404 | # $PROG hash $TMP1 | 410 | # $PROG hash $TMP1 |
@@ -459,7 +465,7 @@ test10() | |||
459 | printf("p\nk%d\nd%s\n", ++i, $0); | 465 | printf("p\nk%d\nd%s\n", ++i, $0); |
460 | } | 466 | } |
461 | END { | 467 | END { |
462 | printf("fR_CURSOR\nr\nk1\n"); | 468 | printf("fR_CURSOR\nr\n"); |
463 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); | 469 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); |
464 | }' > $TMP2 | 470 | }' > $TMP2 |
465 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 | 471 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 |
@@ -573,7 +579,8 @@ test13() | |||
573 | echo g | 579 | echo g |
574 | echo k$i | 580 | echo k$i |
575 | done > $TMP2 | 581 | done > $TMP2 |
576 | $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | 582 | $PROG -s \ |
583 | -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | ||
577 | if (cmp -s $TMP1 $TMP3) ; then : | 584 | if (cmp -s $TMP1 $TMP3) ; then : |
578 | else | 585 | else |
579 | echo "test13: $type/$order get failed" | 586 | echo "test13: $type/$order get failed" |
diff --git a/src/regress/lib/libc/ieeefp/Makefile b/src/regress/lib/libc/ieeefp/Makefile index 4e2e517b03..0f453a31e9 100644 --- a/src/regress/lib/libc/ieeefp/Makefile +++ b/src/regress/lib/libc/ieeefp/Makefile | |||
@@ -1,10 +1,6 @@ | |||
1 | # $NetBSD: Makefile,v 1.4 1995/10/03 21:59:36 phil Exp $ | 1 | # $NetBSD: Makefile,v 1.5 1996/04/09 16:54:18 phil Exp $ |
2 | 2 | ||
3 | .if ${MACHINE} == "pc532" | ||
4 | SUBDIR+= round | ||
5 | .else | ||
6 | SUBDIR+= except round | 3 | SUBDIR+= except round |
7 | .endif | ||
8 | 4 | ||
9 | regress: _SUBDIRUSE | 5 | regress: _SUBDIRUSE |
10 | 6 | ||
diff --git a/src/regress/lib/libc/ieeefp/except/except.c b/src/regress/lib/libc/ieeefp/except/except.c index 0ffdcdd468..a2a107a788 100644 --- a/src/regress/lib/libc/ieeefp/except/except.c +++ b/src/regress/lib/libc/ieeefp/except/except.c | |||
@@ -12,6 +12,7 @@ static volatile const double zero = 0.0; | |||
12 | static volatile const double huge = DBL_MAX; | 12 | static volatile const double huge = DBL_MAX; |
13 | static volatile const double tiny = DBL_MIN; | 13 | static volatile const double tiny = DBL_MIN; |
14 | 14 | ||
15 | int | ||
15 | main() | 16 | main() |
16 | { | 17 | { |
17 | volatile double x; | 18 | volatile double x; |
diff --git a/src/regress/lib/libc/regex/debug.c b/src/regress/lib/libc/regex/debug.c index 861f550611..41cd4a557d 100644 --- a/src/regress/lib/libc/regex/debug.c +++ b/src/regress/lib/libc/regex/debug.c | |||
@@ -218,7 +218,7 @@ FILE *d; | |||
218 | fprintf(d, ">"); | 218 | fprintf(d, ">"); |
219 | break; | 219 | break; |
220 | default: | 220 | default: |
221 | fprintf(d, "!%d(%d)!", OP(*s), opnd); | 221 | fprintf(d, "!%ld(%ld)!", (long)OP(*s), (long)opnd); |
222 | break; | 222 | break; |
223 | } | 223 | } |
224 | if (!done) | 224 | if (!done) |
diff --git a/src/regress/lib/libc/regex/main.c b/src/regress/lib/libc/regex/main.c index 8d88a8b9b8..6e63ffc235 100644 --- a/src/regress/lib/libc/regex/main.c +++ b/src/regress/lib/libc/regex/main.c | |||
@@ -1,10 +1,13 @@ | |||
1 | /* $OpenBSD: main.c,v 1.3 1997/01/15 23:41:07 millert Exp $ */ | ||
1 | /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ | 2 | /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ |
2 | 3 | ||
3 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <stdlib.h> | ||
4 | #include <string.h> | 6 | #include <string.h> |
5 | #include <sys/types.h> | 7 | #include <sys/types.h> |
6 | #include <regex.h> | 8 | #include <regex.h> |
7 | #include <assert.h> | 9 | #include <assert.h> |
10 | #include <unistd.h> | ||
8 | 11 | ||
9 | #include "main.ih" | 12 | #include "main.ih" |
10 | 13 | ||
@@ -25,6 +28,7 @@ extern void regprint(); | |||
25 | /* | 28 | /* |
26 | - main - do the simple case, hand off to regress() for regression | 29 | - main - do the simple case, hand off to regress() for regression |
27 | */ | 30 | */ |
31 | int | ||
28 | main(argc, argv) | 32 | main(argc, argv) |
29 | int argc; | 33 | int argc; |
30 | char *argv[]; | 34 | char *argv[]; |
@@ -43,7 +47,7 @@ char *argv[]; | |||
43 | 47 | ||
44 | progname = argv[0]; | 48 | progname = argv[0]; |
45 | 49 | ||
46 | while ((c = getopt(argc, argv, "c:e:S:E:x")) != EOF) | 50 | while ((c = getopt(argc, argv, "c:e:S:E:x")) != -1) |
47 | switch (c) { | 51 | switch (c) { |
48 | case 'c': /* compile options */ | 52 | case 'c': /* compile options */ |
49 | copts = options('c', optarg); | 53 | copts = options('c', optarg); |
@@ -102,10 +106,10 @@ char *argv[]; | |||
102 | exit(status); | 106 | exit(status); |
103 | } | 107 | } |
104 | if (!(copts®_NOSUB)) { | 108 | if (!(copts®_NOSUB)) { |
105 | len = (int)(subs[0].rm_eo - subs[0].rm_so); | 109 | len = (size_t)(subs[0].rm_eo - subs[0].rm_so); |
106 | if (subs[0].rm_so != -1) { | 110 | if (subs[0].rm_so != -1) { |
107 | if (len != 0) | 111 | if (len != 0) |
108 | printf("match `%.*s'\n", len, | 112 | printf("match `%.*s'\n", (int)len, |
109 | argv[optind] + subs[0].rm_so); | 113 | argv[optind] + subs[0].rm_so); |
110 | else | 114 | else |
111 | printf("match `'@%.1s\n", | 115 | printf("match `'@%.1s\n", |
@@ -501,7 +505,6 @@ efind(name) | |||
501 | char *name; | 505 | char *name; |
502 | { | 506 | { |
503 | static char efbuf[100]; | 507 | static char efbuf[100]; |
504 | size_t n; | ||
505 | regex_t re; | 508 | regex_t re; |
506 | 509 | ||
507 | sprintf(efbuf, "REG_%s", name); | 510 | sprintf(efbuf, "REG_%s", name); |
diff --git a/src/regress/lib/libc/setjmp/jmptest.c b/src/regress/lib/libc/setjmp/jmptest.c index f2cecc9178..16a482640a 100644 --- a/src/regress/lib/libc/setjmp/jmptest.c +++ b/src/regress/lib/libc/setjmp/jmptest.c | |||
@@ -32,6 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <sys/types.h> | 34 | #include <sys/types.h> |
35 | #include <err.h> | ||
35 | #include <setjmp.h> | 36 | #include <setjmp.h> |
36 | #include <signal.h> | 37 | #include <signal.h> |
37 | #include <stdio.h> | 38 | #include <stdio.h> |
@@ -101,7 +102,7 @@ main(argc, argv) | |||
101 | #endif | 102 | #endif |
102 | 103 | ||
103 | sa.sa_handler = aborthandler; | 104 | sa.sa_handler = aborthandler; |
104 | sa.sa_mask = 0; | 105 | sigemptyset(&sa.sa_mask); |
105 | sa.sa_flags = 0; | 106 | sa.sa_flags = 0; |
106 | if (sigaction(SIGABRT, &sa, NULL) == -1) | 107 | if (sigaction(SIGABRT, &sa, NULL) == -1) |
107 | err(1, "sigaction failed"); | 108 | err(1, "sigaction failed"); |
diff --git a/src/usr.bin/nc/Makefile b/src/usr.bin/nc/Makefile new file mode 100644 index 0000000000..086a9e5ee8 --- /dev/null +++ b/src/usr.bin/nc/Makefile | |||
@@ -0,0 +1,7 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 1997/09/21 11:50:13 deraadt Exp $ | ||
2 | |||
3 | CFLAGS+= -DTELNET | ||
4 | PROG= nc | ||
5 | SRCS= netcat.c | ||
6 | |||
7 | .include <bsd.prog.mk> | ||
diff --git a/src/usr.bin/nc/README b/src/usr.bin/nc/README new file mode 100644 index 0000000000..4235bc41ac --- /dev/null +++ b/src/usr.bin/nc/README | |||
@@ -0,0 +1,946 @@ | |||
1 | Netcat 1.10 | ||
2 | =========== /\_/\ | ||
3 | / 0 0 \ | ||
4 | Netcat is a simple Unix utility which reads and writes data ====v==== | ||
5 | across network connections, using TCP or UDP protocol. \ W / | ||
6 | It is designed to be a reliable "back-end" tool that can | | _ | ||
7 | be used directly or easily driven by other programs and / ___ \ / | ||
8 | scripts. At the same time, it is a feature-rich network / / \ \ | | ||
9 | debugging and exploration tool, since it can create almost (((-----)))-' | ||
10 | any kind of connection you would need and has several / | ||
11 | interesting built-in capabilities. Netcat, or "nc" as the ( ___ | ||
12 | actual program is named, should have been supplied long ago \__.=|___E | ||
13 | as another one of those cryptic but standard Unix tools. / | ||
14 | |||
15 | In the simplest usage, "nc host port" creates a TCP connection to the given | ||
16 | port on the given target host. Your standard input is then sent to the host, | ||
17 | and anything that comes back across the connection is sent to your standard | ||
18 | output. This continues indefinitely, until the network side of the connection | ||
19 | shuts down. Note that this behavior is different from most other applications | ||
20 | which shut everything down and exit after an end-of-file on the standard input. | ||
21 | |||
22 | Netcat can also function as a server, by listening for inbound connections | ||
23 | on arbitrary ports and then doing the same reading and writing. With minor | ||
24 | limitations, netcat doesn't really care if it runs in "client" or "server" | ||
25 | mode -- it still shovels data back and forth until there isn't any more left. | ||
26 | In either mode, shutdown can be forced after a configurable time of inactivity | ||
27 | on the network side. | ||
28 | |||
29 | And it can do this via UDP too, so netcat is possibly the "udp telnet-like" | ||
30 | application you always wanted for testing your UDP-mode servers. UDP, as the | ||
31 | "U" implies, gives less reliable data transmission than TCP connections and | ||
32 | some systems may have trouble sending large amounts of data that way, but it's | ||
33 | still a useful capability to have. | ||
34 | |||
35 | You may be asking "why not just use telnet to connect to arbitrary ports?" | ||
36 | Valid question, and here are some reasons. Telnet has the "standard input | ||
37 | EOF" problem, so one must introduce calculated delays in driving scripts to | ||
38 | allow network output to finish. This is the main reason netcat stays running | ||
39 | until the *network* side closes. Telnet also will not transfer arbitrary | ||
40 | binary data, because certain characters are interpreted as telnet options and | ||
41 | are thus removed from the data stream. Telnet also emits some of its | ||
42 | diagnostic messages to standard output, where netcat keeps such things | ||
43 | religiously separated from its *output* and will never modify any of the real | ||
44 | data in transit unless you *really* want it to. And of course telnet is | ||
45 | incapable of listening for inbound connections, or using UDP instead. Netcat | ||
46 | doesn't have any of these limitations, is much smaller and faster than telnet, | ||
47 | and has many other advantages. | ||
48 | |||
49 | Some of netcat's major features are: | ||
50 | |||
51 | Outbound or inbound connections, TCP or UDP, to or from any ports | ||
52 | Full DNS forward/reverse checking, with appropriate warnings | ||
53 | Ability to use any local source port | ||
54 | Ability to use any locally-configured network source address | ||
55 | Built-in port-scanning capabilities, with randomizer | ||
56 | Built-in loose source-routing capability | ||
57 | Can read command line arguments from standard input | ||
58 | Slow-send mode, one line every N seconds | ||
59 | Hex dump of transmitted and received data | ||
60 | Optional ability to let another program service established connections | ||
61 | Optional telnet-options responder | ||
62 | |||
63 | Efforts have been made to have netcat "do the right thing" in all its various | ||
64 | modes. If you believe that it is doing the wrong thing under whatever | ||
65 | circumstances, please notify me and tell me how you think it should behave. | ||
66 | If netcat is not able to do some task you think up, minor tweaks to the code | ||
67 | will probably fix that. It provides a basic and easily-modified template for | ||
68 | writing other network applications, and I certainly encourage people to make | ||
69 | custom mods and send in any improvements they make to it. This is the second | ||
70 | release; the overall differences from 1.00 are relatively minor and have mostly | ||
71 | to do with portability and bugfixes. Many people provided greatly appreciated | ||
72 | fixes and comments on the 1.00 release. Continued feedback from the Internet | ||
73 | community is always welcome! | ||
74 | |||
75 | Netcat is entirely my own creation, although plenty of other code was used as | ||
76 | examples. It is freely given away to the Internet community in the hope that | ||
77 | it will be useful, with no restrictions except giving credit where it is due. | ||
78 | No GPLs, Berkeley copyrights or any of that nonsense. The author assumes NO | ||
79 | responsibility for how anyone uses it. If netcat makes you rich somehow and | ||
80 | you're feeling generous, mail me a check. If you are affiliated in any way | ||
81 | with Microsoft Network, get a life. Always ski in control. Comments, | ||
82 | questions, and patches to hobbit@avian.org. | ||
83 | |||
84 | Building | ||
85 | ======== | ||
86 | |||
87 | Compiling is fairly straightforward. Examine the Makefile for a SYSTYPE that | ||
88 | matches yours, and do "make <systype>". The executable "nc" should appear. | ||
89 | If there is no relevant SYSTYPE section, try "generic". If you create new | ||
90 | sections for generic.h and Makefile to support another platform, please follow | ||
91 | the given format and mail back the diffs. | ||
92 | |||
93 | There are a couple of other settable #defines in netcat.c, which you can | ||
94 | include as DFLAGS="-DTHIS -DTHAT" to your "make" invocation without having to | ||
95 | edit the Makefile. See the following discussions for what they are and do. | ||
96 | |||
97 | If you want to link against the resolver library on SunOS [recommended] and | ||
98 | you have BIND 4.9.x, you may need to change XLIBS=-lresolv in the Makefile to | ||
99 | XLIBS="-lresolv -l44bsd". | ||
100 | |||
101 | Linux sys/time.h does not really support presetting of FD_SETSIZE; a harmless | ||
102 | warning is issued. | ||
103 | |||
104 | Some systems may warn about pointer types for signal(). No problem, though. | ||
105 | |||
106 | Exploration of features | ||
107 | ======================= | ||
108 | |||
109 | Where to begin? Netcat is at the same time so simple and versatile, it's like | ||
110 | trying to describe everything you can do with your Swiss Army knife. This will | ||
111 | go over the basics; you should also read the usage examples and notes later on | ||
112 | which may give you even more ideas about what this sort of tool is good for. | ||
113 | |||
114 | If no command arguments are given at all, netcat asks for them, reads a line | ||
115 | from standard input, and breaks it up into arguments internally. This can be | ||
116 | useful when driving netcat from certain types of scripts, with the side effect | ||
117 | of hiding your command line arguments from "ps" displays. | ||
118 | |||
119 | The host argument can be a name or IP address. If -n is specified, netcat | ||
120 | will only accept numeric IP addresses and do no DNS lookups for anything. If | ||
121 | -n is not given and -v is turned on, netcat will do a full forward and reverse | ||
122 | name and address lookup for the host, and warn you about the all-too-common | ||
123 | problem of mismatched names in the DNS. This often takes a little longer for | ||
124 | connection setup, but is useful to know about. There are circumstances under | ||
125 | which this can *save* time, such as when you want to know the name for some IP | ||
126 | address and also connect there. Netcat will just tell you all about it, saving | ||
127 | the manual steps of looking up the hostname yourself. Normally mismatch- | ||
128 | checking is case-insensitive per the DNS spec, but you can define ANAL at | ||
129 | compile time to make it case-sensitive -- sometimes useful for uncovering minor | ||
130 | errors in your own DNS files while poking around your networks. | ||
131 | |||
132 | A port argument is required for outbound connections, and can be numeric or a | ||
133 | name as listed in /etc/services. If -n is specified, only numeric arguments | ||
134 | are valid. Special syntax and/or more than one port argument cause different | ||
135 | behavior -- see details below about port-scanning. | ||
136 | |||
137 | The -v switch controls the verbosity level of messages sent to standard error. | ||
138 | You will probably want to run netcat most of the time with -v turned on, so you | ||
139 | can see info about the connections it is trying to make. You will probably | ||
140 | also want to give a smallish -w argument, which limits the time spent trying to | ||
141 | make a connection. I usually alias "nc" to "nc -v -w 3", which makes it | ||
142 | function just about the same for things I would otherwise use telnet to do. | ||
143 | The timeout is easily changed by a subsequent -w argument which overrides the | ||
144 | earlier one. Specifying -v more than once makes diagnostic output MORE | ||
145 | verbose. If -v is not specified at all, netcat silently does its work unless | ||
146 | some error happens, whereupon it describes the error and exits with a nonzero | ||
147 | status. Refused network connections are generally NOT considered to be errors, | ||
148 | unless you only asked for a single TCP port and it was refused. | ||
149 | |||
150 | Note that -w also sets the network inactivity timeout. This does not have any | ||
151 | effect until standard input closes, but then if nothing further arrives from | ||
152 | the network in the next <timeout> seconds, netcat tries to read the net once | ||
153 | more for good measure, and then closes and exits. There are a lot of network | ||
154 | services now that accept a small amount of input and return a large amount of | ||
155 | output, such as Gopher and Web servers, which is the main reason netcat was | ||
156 | written to "block" on the network staying open rather than standard input. | ||
157 | Handling the timeout this way gives uniform behavior with network servers that | ||
158 | *don't* close by themselves until told to. | ||
159 | |||
160 | UDP connections are opened instead of TCP when -u is specified. These aren't | ||
161 | really "connections" per se since UDP is a connectionless protocol, although | ||
162 | netcat does internally use the "connected UDP socket" mechanism that most | ||
163 | kernels support. Although netcat claims that an outgoing UDP connection is | ||
164 | "open" immediately, no data is sent until something is read from standard | ||
165 | input. Only thereafter is it possible to determine whether there really is a | ||
166 | UDP server on the other end, and often you just can't tell. Most UDP protocols | ||
167 | use timeouts and retries to do their thing and in many cases won't bother | ||
168 | answering at all, so you should specify a timeout and hope for the best. You | ||
169 | will get more out of UDP connections if standard input is fed from a source | ||
170 | of data that looks like various kinds of server requests. | ||
171 | |||
172 | To obtain a hex dump file of the data sent either way, use "-o logfile". The | ||
173 | dump lines begin with "<" or ">" to respectively indicate "from the net" or | ||
174 | "to the net", and contain the total count per direction, and hex and ascii | ||
175 | representations of the traffic. Capturing a hex dump naturally slows netcat | ||
176 | down a bit, so don't use it where speed is critical. | ||
177 | |||
178 | Netcat can bind to any local port, subject to privilege restrictions and ports | ||
179 | that are already in use. It is also possible to use a specific local network | ||
180 | source address if it is that of a network interface on your machine. [Note: | ||
181 | this does not work correctly on all platforms.] Use "-p portarg" to grab a | ||
182 | specific local port, and "-s ip-addr" or "-s name" to have that be your source | ||
183 | IP address. This is often referred to as "anchoring the socket". Root users | ||
184 | can grab any unused source port including the "reserved" ones less than 1024. | ||
185 | Absence of -p will bind to whatever unused port the system gives you, just like | ||
186 | any other normal client connection, unless you use -r [see below]. | ||
187 | |||
188 | Listen mode will cause netcat to wait for an inbound connection, and then the | ||
189 | same data transfer happens. Thus, you can do "nc -l -p 1234 < filename" and | ||
190 | when someone else connects to your port 1234, the file is sent to them whether | ||
191 | they wanted it or not. Listen mode is generally used along with a local port | ||
192 | argument -- this is required for UDP mode, while TCP mode can have the system | ||
193 | assign one and tell you what it is if -v is turned on. If you specify a target | ||
194 | host and optional port in listen mode, netcat will accept an inbound connection | ||
195 | only from that host and if you specify one, only from that foreign source port. | ||
196 | In verbose mode you'll be informed about the inbound connection, including what | ||
197 | address and port it came from, and since listening on "any" applies to several | ||
198 | possibilities, which address it came *to* on your end. If the system supports | ||
199 | IP socket options, netcat will attempt to retrieve any such options from an | ||
200 | inbound connection and print them out in hex. | ||
201 | |||
202 | If netcat is compiled with -DGAPING_SECURITY_HOLE, the -e argument specifies | ||
203 | a program to exec after making or receiving a successful connection. In the | ||
204 | listening mode, this works similarly to "inetd" but only for a single instance. | ||
205 | Use with GREAT CARE. This piece of the code is normally not enabled; if you | ||
206 | know what you're doing, have fun. This hack also works in UDP mode. Note that | ||
207 | you can only supply -e with the name of the program, but no arguments. If you | ||
208 | want to launch something with an argument list, write a two-line wrapper script | ||
209 | or just use inetd like always. | ||
210 | |||
211 | If netcat is compiled with -DTELNET, the -t argument enables it to respond | ||
212 | to telnet option negotiation [always in the negative, i.e. DONT or WONT]. | ||
213 | This allows it to connect to a telnetd and get past the initial negotiation | ||
214 | far enough to get a login prompt from the server. Since this feature has | ||
215 | the potential to modify the data stream, it is not enabled by default. You | ||
216 | have to understand why you might need this and turn on the #define yourself. | ||
217 | |||
218 | Data from the network connection is always delivered to standard output as | ||
219 | efficiently as possible, using large 8K reads and writes. Standard input is | ||
220 | normally sent to the net the same way, but the -i switch specifies an "interval | ||
221 | time" which slows this down considerably. Standard input is still read in | ||
222 | large batches, but netcat then tries to find where line breaks exist and sends | ||
223 | one line every interval time. Note that if standard input is a terminal, data | ||
224 | is already read line by line, so unless you make the -i interval rather long, | ||
225 | what you type will go out at a fairly normal rate. -i is really designed | ||
226 | for use when you want to "measure out" what is read from files or pipes. | ||
227 | |||
228 | Port-scanning is a popular method for exploring what's out there. Netcat | ||
229 | accepts its commands with options first, then the target host, and everything | ||
230 | thereafter is interpreted as port names or numbers, or ranges of ports in M-N | ||
231 | syntax. CAVEAT: some port names in /etc/services contain hyphens -- netcat | ||
232 | currently will not correctly parse those, so specify ranges using numbers if | ||
233 | you can. If more than one port is thus specified, netcat connects to *all* of | ||
234 | them, sending the same batch of data from standard input [up to 8K worth] to | ||
235 | each one that is successfully connected to. Specifying multiple ports also | ||
236 | suppresses diagnostic messages about refused connections, unless -v is | ||
237 | specified twice for "more verbosity". This way you normally get notified only | ||
238 | about genuinely open connections. Example: "nc -v -w 2 -z target 20-30" will | ||
239 | try connecting to every port between 20 and 30 [inclusive] at the target, and | ||
240 | will likely inform you about an FTP server, telnet server, and mailer along the | ||
241 | way. The -z switch prevents sending any data to a TCP connection and very | ||
242 | limited probe data to a UDP connection, and is thus useful as a fast scanning | ||
243 | mode just to see what ports the target is listening on. To limit scanning | ||
244 | speed if desired, -i will insert a delay between each port probe. There are | ||
245 | some pitfalls with regard to UDP scanning, described later, but in general it | ||
246 | works well. | ||
247 | |||
248 | For each range of ports specified, scanning is normally done downward within | ||
249 | that range. If the -r switch is used, scanning hops randomly around within | ||
250 | that range and reports open ports as it finds them. [If you want them listed | ||
251 | in order regardless, pipe standard error through "sort"...] In addition, if | ||
252 | random mode is in effect, the local source ports are also randomized. This | ||
253 | prevents netcat from exhibiting any kind of regular pattern in its scanning. | ||
254 | You can exert fairly fine control over your scan by judicious use of -r and | ||
255 | selected port ranges to cover. If you use -r for a single connection, the | ||
256 | source port will have a random value above 8192, rather than the next one the | ||
257 | kernel would have assigned you. Note that selecting a specific local port | ||
258 | with -p overrides any local-port randomization. | ||
259 | |||
260 | Many people are interested in testing network connectivity using IP source | ||
261 | routing, even if it's only to make sure their own firewalls are blocking | ||
262 | source-routed packets. On systems that support it, the -g switch can be used | ||
263 | multiple times [up to 8] to construct a loose-source-routed path for your | ||
264 | connection, and the -G argument positions the "hop pointer" within the list. | ||
265 | If your network allows source-routed traffic in and out, you can test | ||
266 | connectivity to your own services via remote points in the internet. Note that | ||
267 | although newer BSD-flavor telnets also have source-routing capability, it isn't | ||
268 | clearly documented and the command syntax is somewhat clumsy. Netcat's | ||
269 | handling of "-g" is modeled after "traceroute". | ||
270 | |||
271 | Netcat tries its best to behave just like "cat". It currently does nothing to | ||
272 | terminal input modes, and does no end-of-line conversion. Standard input from | ||
273 | a terminal is read line by line with normal editing characters in effect. You | ||
274 | can freely suspend out of an interactive connection and resume. ^C or whatever | ||
275 | your interrupt character is will make netcat close the network connection and | ||
276 | exit. A switch to place the terminal in raw mode has been considered, but so | ||
277 | far has not been necessary. You can send raw binary data by reading it out of | ||
278 | a file or piping from another program, so more meaningful effort would be spent | ||
279 | writing an appropriate front-end driver. | ||
280 | |||
281 | Netcat is not an "arbitrary packet generator", but the ability to talk to raw | ||
282 | sockets and/or nit/bpf/dlpi may appear at some point. Such things are clearly | ||
283 | useful; I refer you to Darren Reed's excellent ip_filter package, which now | ||
284 | includes a tool to construct and send raw packets with any contents you want. | ||
285 | |||
286 | Example uses -- the light side | ||
287 | ============================== | ||
288 | |||
289 | Again, this is a very partial list of possibilities, but it may get you to | ||
290 | think up more applications for netcat. Driving netcat with simple shell or | ||
291 | expect scripts is an easy and flexible way to do fairly complex tasks, | ||
292 | especially if you're not into coding network tools in C. My coding isn't | ||
293 | particularly strong either [although undoubtedly better after writing this | ||
294 | thing!], so I tend to construct bare-metal tools like this that I can trivially | ||
295 | plug into other applications. Netcat doubles as a teaching tool -- one can | ||
296 | learn a great deal about more complex network protocols by trying to simulate | ||
297 | them through raw connections! | ||
298 | |||
299 | An example of netcat as a backend for something else is the shell-script | ||
300 | Web browser, which simply asks for the relevant parts of a URL and pipes | ||
301 | "GET /what/ever" into a netcat connection to the server. I used to do this | ||
302 | with telnet, and had to use calculated sleep times and other stupidity to | ||
303 | kludge around telnet's limitations. Netcat guarantees that I get the whole | ||
304 | page, and since it transfers all the data unmodified, I can even pull down | ||
305 | binary image files and display them elsewhere later. Some folks may find the | ||
306 | idea of a shell-script web browser silly and strange, but it starts up and | ||
307 | gets me my info a hell of a lot faster than a GUI browser and doesn't hide | ||
308 | any contents of links and forms and such. This is included, as scripts/web, | ||
309 | along with several other web-related examples. | ||
310 | |||
311 | Netcat is an obvious replacement for telnet as a tool for talking to daemons. | ||
312 | For example, it is easier to type "nc host 25", talk to someone's mailer, and | ||
313 | just ^C out than having to type ^]c or QUIT as telnet would require you to do. | ||
314 | You can quickly catalog the services on your network by telling netcat to | ||
315 | connect to well-known services and collect greetings, or at least scan for open | ||
316 | ports. You'll probably want to collect netcat's diagnostic messages in your | ||
317 | output files, so be sure to include standard error in the output using | ||
318 | `>& file' in *csh or `> file 2>&1' in bourne shell. | ||
319 | |||
320 | A scanning example: "echo QUIT | nc -v -w 5 target 20-250 500-600 5990-7000" | ||
321 | will inform you about a target's various well-known TCP servers, including | ||
322 | r-services, X, IRC, and maybe a few you didn't expect. Sending in QUIT and | ||
323 | using the timeout will almost guarantee that you see some kind of greeting or | ||
324 | error from each service, which usually indicates what it is and what version. | ||
325 | [Beware of the "chargen" port, though...] SATAN uses exactly this technique to | ||
326 | collect host information, and indeed some of the ideas herein were taken from | ||
327 | the SATAN backend tools. If you script this up to try every host in your | ||
328 | subnet space and just let it run, you will not only see all the services, | ||
329 | you'll find out about hosts that aren't correctly listed in your DNS. Then you | ||
330 | can compare new snapshots against old snapshots to see changes. For going | ||
331 | after particular services, a more intrusive example is in scripts/probe. | ||
332 | |||
333 | Netcat can be used as a simple data transfer agent, and it doesn't really | ||
334 | matter which end is the listener and which end is the client -- input at one | ||
335 | side arrives at the other side as output. It is helpful to start the listener | ||
336 | at the receiving side with no timeout specified, and then give the sending side | ||
337 | a small timeout. That way the listener stays listening until you contact it, | ||
338 | and after data stops flowing the client will time out, shut down, and take the | ||
339 | listener with it. Unless the intervening network is fraught with problems, | ||
340 | this should be completely reliable, and you can always increase the timeout. A | ||
341 | typical example of something "rsh" is often used for: on one side, | ||
342 | |||
343 | nc -l -p 1234 | uncompress -c | tar xvfp - | ||
344 | |||
345 | and then on the other side | ||
346 | |||
347 | tar cfp - /some/dir | compress -c | nc -w 3 othermachine 1234 | ||
348 | |||
349 | will transfer the contents of a directory from one machine to another, without | ||
350 | having to worry about .rhosts files, user accounts, or inetd configurations | ||
351 | at either end. Again, it matters not which is the listener or receiver; the | ||
352 | "tarring" machine could just as easily be running the listener instead. One | ||
353 | could conceivably use a scheme like this for backups, by having cron-jobs fire | ||
354 | up listeners and backup handlers [which can be restricted to specific addresses | ||
355 | and ports between each other] and pipe "dump" or "tar" on one machine to "dd | ||
356 | of=/dev/tapedrive" on another as usual. Since netcat returns a nonzero exit | ||
357 | status for a denied listener connection, scripts to handle such tasks could | ||
358 | easily log and reject connect attempts from third parties, and then retry. | ||
359 | |||
360 | Another simple data-transfer example: shipping things to a PC that doesn't have | ||
361 | any network applications yet except a TCP stack and a web browser. Point the | ||
362 | browser at an arbitrary port on a Unix server by telling it to download | ||
363 | something like http://unixbox:4444/foo, and have a listener on the Unix side | ||
364 | ready to ship out a file when the connect comes in. The browser may pervert | ||
365 | binary data when told to save the URL, but you can dig the raw data out of | ||
366 | the on-disk cache. | ||
367 | |||
368 | If you build netcat with GAPING_SECURITY_HOLE defined, you can use it as an | ||
369 | "inetd" substitute to test experimental network servers that would otherwise | ||
370 | run under "inetd". A script or program will have its input and output hooked | ||
371 | to the network the same way, perhaps sans some fancier signal handling. Given | ||
372 | that most network services do not bind to a particular local address, whether | ||
373 | they are under "inetd" or not, it is possible for netcat avoid the "address | ||
374 | already in use" error by binding to a specific address. This lets you [as | ||
375 | root, for low ports] place netcat "in the way" of a standard service, since | ||
376 | inbound connections are generally sent to such specifically-bound listeners | ||
377 | first and fall back to the ones bound to "any". This allows for a one-off | ||
378 | experimental simulation of some service, without having to screw around with | ||
379 | inetd.conf. Running with -v turned on and collecting a connection log from | ||
380 | standard error is recommended. | ||
381 | |||
382 | Netcat as well can make an outbound connection and then run a program or script | ||
383 | on the originating end, with input and output connected to the same network | ||
384 | port. This "inverse inetd" capability could enhance the backup-server concept | ||
385 | described above or help facilitate things such as a "network dialback" concept. | ||
386 | The possibilities are many and varied here; if such things are intended as | ||
387 | security mechanisms, it may be best to modify netcat specifically for the | ||
388 | purpose instead of wrapping such functions in scripts. | ||
389 | |||
390 | Speaking of inetd, netcat will function perfectly well *under* inetd as a TCP | ||
391 | connection redirector for inbound services, like a "plug-gw" without the | ||
392 | authentication step. This is very useful for doing stuff like redirecting | ||
393 | traffic through your firewall out to other places like web servers and mail | ||
394 | hubs, while posing no risk to the firewall machine itself. Put netcat behind | ||
395 | inetd and tcp_wrappers, perhaps thusly: | ||
396 | |||
397 | www stream tcp nowait nobody /etc/tcpd /bin/nc -w 3 realwww 80 | ||
398 | |||
399 | and you have a simple and effective "application relay" with access control | ||
400 | and logging. Note use of the wait time as a "safety" in case realwww isn't | ||
401 | reachable or the calling user aborts the connection -- otherwise the relay may | ||
402 | hang there forever. | ||
403 | |||
404 | You can use netcat to generate huge amounts of useless network data for | ||
405 | various performance testing. For example, doing | ||
406 | |||
407 | yes AAAAAAAAAAAAAAAAAAAAAA | nc -v -v -l -p 2222 > /dev/null | ||
408 | |||
409 | on one side and then hitting it with | ||
410 | |||
411 | yes BBBBBBBBBBBBBBBBBBBBBB | nc othermachine 2222 > /dev/null | ||
412 | |||
413 | from another host will saturate your wires with A's and B's. The "very | ||
414 | verbose" switch usage will tell you how many of each were sent and received | ||
415 | after you interrupt either side. Using UDP mode produces tremendously MORE | ||
416 | trash per unit time in the form of fragmented 8 Kbyte mobygrams -- enough to | ||
417 | stress-test kernels and network interfaces. Firing random binary data into | ||
418 | various network servers may help expose bugs in their input handling, which | ||
419 | nowadays is a popular thing to explore. A simple example data-generator is | ||
420 | given in data/data.c included in this package, along with a small collection | ||
421 | of canned input files to generate various packet contents. This program is | ||
422 | documented in its beginning comments, but of interest here is using "%r" to | ||
423 | generate random bytes at well-chosen points in a data stream. If you can | ||
424 | crash your daemon, you likely have a security problem. | ||
425 | |||
426 | The hex dump feature may be useful for debugging odd network protocols, | ||
427 | especially if you don't have any network monitoring equipment handy or aren't | ||
428 | root where you'd need to run "tcpdump" or something. Bind a listening netcat | ||
429 | to a local port, and have it run a script which in turn runs another netcat | ||
430 | to the real service and captures the hex dump to a log file. This sets up a | ||
431 | transparent relay between your local port and wherever the real service is. | ||
432 | Be sure that the script-run netcat does *not* use -v, or the extra info it | ||
433 | sends to standard error may confuse the protocol. Note also that you cannot | ||
434 | have the "listen/exec" netcat do the data capture, since once the connection | ||
435 | arrives it is no longer netcat that is running. | ||
436 | |||
437 | Binding to an arbitrary local port allows you to simulate things like r-service | ||
438 | clients, if you are root locally. For example, feeding "^@root^@joe^@pwd^@" | ||
439 | [where ^@ is a null, and root/joe could be any other local/remote username | ||
440 | pair] into a "rsh" or "rlogin" server, FROM your port 1023 for example, | ||
441 | duplicates what the server expects to receive. Thus, you can test for insecure | ||
442 | .rhosts files around your network without having to create new user accounts on | ||
443 | your client machine. The program data/rservice.c can aid this process by | ||
444 | constructing the "rcmd" protocol bytes. Doing this also prevents "rshd" from | ||
445 | trying to create that separate standard-error socket and still gives you an | ||
446 | input path, as opposed to the usual action of "rsh -n". Using netcat for | ||
447 | things like this can be really useful sometimes, because rsh and rlogin | ||
448 | generally want a host *name* as an argument and won't accept IP addresses. If | ||
449 | your client-end DNS is hosed, as may be true when you're trying to extract | ||
450 | backup sets on to a dumb client, "netcat -n" wins where normal rsh/rlogin is | ||
451 | useless. | ||
452 | |||
453 | If you are unsure that a remote syslogger is working, test it with netcat. | ||
454 | Make a UDP connection to port 514 and type in "<0>message", which should | ||
455 | correspond to "kern.emerg" and cause syslogd to scream into every file it has | ||
456 | open [and possibly all over users' terminals]. You can tame this down by | ||
457 | using a different number and use netcat inside routine scripts to send syslog | ||
458 | messages to places that aren't configured in syslog.conf. For example, | ||
459 | "echo '<38>message' | nc -w 1 -u loggerhost 514" should send to auth.notice | ||
460 | on loggerhost. The exact number may vary; check against your syslog.h first. | ||
461 | |||
462 | Netcat provides several ways for you to test your own packet filters. If you | ||
463 | bind to a port normally protected against outside access and make a connection | ||
464 | to somewhere outside your own network, the return traffic will be coming to | ||
465 | your chosen port from the "outside" and should be blocked. TCP may get through | ||
466 | if your filter passes all "ack syn", but it shouldn't be even doing that to low | ||
467 | ports on your network. Remember to test with UDP traffic as well! If your | ||
468 | filter passes at least outbound source-routed IP packets, bouncing a connection | ||
469 | back to yourself via some gateway outside your network will create "incoming" | ||
470 | traffic with your source address, which should get dropped by a correctly | ||
471 | configured anti-spoofing filter. This is a "non-test" if you're also dropping | ||
472 | source-routing, but it's good to be able to test for that too. Any packet | ||
473 | filter worth its salt will be blocking source-routed packets in both | ||
474 | directions, but you never know what interesting quirks you might turn up by | ||
475 | playing around with source ports and addresses and watching the wires with a | ||
476 | network monitor. | ||
477 | |||
478 | You can use netcat to protect your own workstation's X server against outside | ||
479 | access. X is stupid enough to listen for connections on "any" and never tell | ||
480 | you when new connections arrive, which is one reason it is so vulnerable. Once | ||
481 | you have all your various X windows up and running you can use netcat to bind | ||
482 | just to your ethernet address and listen to port 6000. Any new connections | ||
483 | from outside the machine will hit netcat instead your X server, and you get a | ||
484 | log of who's trying. You can either tell netcat to drop the connection, or | ||
485 | perhaps run another copy of itself to relay to your actual X server on | ||
486 | "localhost". This may not work for dedicated X terminals, but it may be | ||
487 | possible to authorize your X terminal only for its boot server, and run a relay | ||
488 | netcat over on the server that will in turn talk to your X terminal. Since | ||
489 | netcat only handles one listening connection per run, make sure that whatever | ||
490 | way you rig it causes another one to run and listen on 6000 soon afterward, or | ||
491 | your real X server will be reachable once again. A very minimal script just | ||
492 | to protect yourself could be | ||
493 | |||
494 | while true ; do | ||
495 | nc -v -l -s <your-addr> -p 6000 localhost 2 | ||
496 | done | ||
497 | |||
498 | which causes netcat to accept and then close any inbound connection to your | ||
499 | workstation's normal ethernet address, and another copy is immediately run by | ||
500 | the script. Send standard error to a file for a log of connection attempts. | ||
501 | If your system can't do the "specific bind" thing all is not lost; run your | ||
502 | X server on display ":1" or port 6001, and netcat can still function as a probe | ||
503 | alarm by listening on 6000. | ||
504 | |||
505 | Does your shell-account provider allow personal Web pages, but not CGI scripts? | ||
506 | You can have netcat listen on a particular port to execute a program or script | ||
507 | of your choosing, and then just point to the port with a URL in your homepage. | ||
508 | The listener could even exist on a completely different machine, avoiding the | ||
509 | potential ire of the homepage-host administrators. Since the script will get | ||
510 | the raw browser query as input it won't look like a typical CGI script, and | ||
511 | since it's running under your UID you need to write it carefully. You may want | ||
512 | to write a netcat-based script as a wrapper that reads a query and sets up | ||
513 | environment variables for a regular CGI script. The possibilities for using | ||
514 | netcat and scripts to handle Web stuff are almost endless. Again, see the | ||
515 | examples under scripts/. | ||
516 | |||
517 | Example uses -- the dark side | ||
518 | ============================= | ||
519 | |||
520 | Equal time is deserved here, since a versatile tool like this can be useful | ||
521 | to any Shade of Hat. I could use my Victorinox to either fix your car or | ||
522 | disassemble it, right? You can clearly use something like netcat to attack | ||
523 | or defend -- I don't try to govern anyone's social outlook, I just build tools. | ||
524 | Regardless of your intentions, you should still be aware of these threats to | ||
525 | your own systems. | ||
526 | |||
527 | The first obvious thing is scanning someone *else's* network for vulnerable | ||
528 | services. Files containing preconstructed data, be it exploratory or | ||
529 | exploitive, can be fed in as standard input, including command-line arguments | ||
530 | to netcat itself to keep "ps" ignorant of your doings. The more random the | ||
531 | scanning, the less likelihood of detection by humans, scan-detectors, or | ||
532 | dynamic filtering, and with -i you'll wait longer but avoid loading down the | ||
533 | target's network. Some examples for crafting various standard UDP probes are | ||
534 | given in data/*.d. | ||
535 | |||
536 | Some configurations of packet filters attempt to solve the FTP-data problem by | ||
537 | just allowing such connections from the outside. These come FROM port 20, TO | ||
538 | high TCP ports inside -- if you locally bind to port 20, you may find yourself | ||
539 | able to bypass filtering in some cases. Maybe not to low ports "inside", but | ||
540 | perhaps to TCP NFS servers, X servers, Prospero, ciscos that listen on 200x | ||
541 | and 400x... Similar bypassing may be possible for UDP [and maybe TCP too] if a | ||
542 | connection comes from port 53; a filter may assume it's a nameserver response. | ||
543 | |||
544 | Using -e in conjunction with binding to a specific address can enable "server | ||
545 | takeover" by getting in ahead of the real ones, whereupon you can snarf data | ||
546 | sent in and feed your own back out. At the very least you can log a hex dump | ||
547 | of someone else's session. If you are root, you can certainly use -s and -e to | ||
548 | run various hacked daemons without having to touch inetd.conf or the real | ||
549 | daemons themselves. You may not always have the root access to deal with low | ||
550 | ports, but what if you are on a machine that also happens to be an NFS server? | ||
551 | You might be able to collect some interesting things from port 2049, including | ||
552 | local file handles. There are several other servers that run on high ports | ||
553 | that are likely candidates for takeover, including many of the RPC services on | ||
554 | some platforms [yppasswdd, anyone?]. Kerberos tickets, X cookies, and IRC | ||
555 | traffic also come to mind. RADIUS-based terminal servers connect incoming | ||
556 | users to shell-account machines on a high port, usually 1642 or thereabouts. | ||
557 | SOCKS servers run on 1080. Do "netstat -a" and get creative. | ||
558 | |||
559 | There are some daemons that are well-written enough to bind separately to all | ||
560 | the local interfaces, possibly with an eye toward heading off this sort of | ||
561 | problem. Named from recent BIND releases, and NTP, are two that come to mind. | ||
562 | Netstat will show these listening on address.53 instead of *.53. You won't | ||
563 | be able to get in front of these on any of the real interface addresses, which | ||
564 | of course is especially interesting in the case of named, but these servers | ||
565 | sometimes forget about things like "alias" interface addresses or interfaces | ||
566 | that appear later on such as dynamic PPP links. There are some hacked web | ||
567 | servers and versions of "inetd" floating around that specifically bind as well, | ||
568 | based on a configuration file -- these generally *are* bound to alias addresses | ||
569 | to offer several different address-based services from one machine. | ||
570 | |||
571 | Using -e to start a remote backdoor shell is another obvious sort of thing, | ||
572 | easier than constructing a file for inetd to listen on "ingreslock" or | ||
573 | something, and you can access-control it against other people by specifying a | ||
574 | client host and port. Experience with this truly demonstrates how fragile the | ||
575 | barrier between being "logged in" or not really is, and is further expressed by | ||
576 | scripts/bsh. If you're already behind a firewall, it may be easier to make an | ||
577 | *outbound* connection and then run a shell; a small wrapper script can | ||
578 | periodically try connecting to a known place and port, you can later listen | ||
579 | there until the inbound connection arrives, and there's your shell. Running | ||
580 | a shell via UDP has several interesting features, although be aware that once | ||
581 | "connected", the UDP stub sockets tend to show up in "netstat" just like TCP | ||
582 | connections and may not be quite as subtle as you wanted. Packets may also be | ||
583 | lost, so use TCP if you need reliable connections. But since UDP is | ||
584 | connectionless, a hookup of this sort will stick around almost forever, even if | ||
585 | you ^C out of netcat or do a reboot on your side, and you only need to remember | ||
586 | the ports you used on both ends to reestablish. And outbound UDP-plus-exec | ||
587 | connection creates the connected socket and starts the program immediately. On | ||
588 | a listening UDP connection, the socket is created once a first packet is | ||
589 | received. In either case, though, such a "connection" has the interesting side | ||
590 | effect that only your client-side IP address and [chosen?] source port will | ||
591 | thereafter be able to talk to it. Instant access control! A non-local third | ||
592 | party would have to do ALL of the following to take over such a session: | ||
593 | |||
594 | forge UDP with your source address [trivial to do; see below] | ||
595 | guess the port numbers of BOTH ends, or sniff the wire for them | ||
596 | arrange to block ICMP or UDP return traffic between it and your real | ||
597 | source, so the session doesn't die with a network write error. | ||
598 | |||
599 | The companion program data/rservice.c is helpful in scripting up any sort of | ||
600 | r-service username or password guessing attack. The arguments to "rservice" | ||
601 | are simply the strings that get null-terminated and passed over an "rcmd"-style | ||
602 | connection, with the assumption that the client does not need a separate | ||
603 | standard-error port. Brute-force password banging is best done via "rexec" if | ||
604 | it is available since it is less likely to log failed attempts. Thus, doing | ||
605 | "rservice joe joespass pwd | nc target exec" should return joe's home dir if | ||
606 | the password is right, or "Permission denied." Plug in a dictionary and go to | ||
607 | town. If you're attacking rsh/rlogin, remember to be root and bind to a port | ||
608 | between 512 and 1023 on your end, and pipe in "rservice joe joe pwd" and such. | ||
609 | |||
610 | Netcat can prevent inadvertently sending extra information over a telnet | ||
611 | connection. Use "nc -t" in place of telnet, and daemons that try to ask for | ||
612 | things like USER and TERM environment variables will get no useful answers, as | ||
613 | they otherwise would from a more recent telnet program. Some telnetds actually | ||
614 | try to collect this stuff and then plug the USER variable into "login" so that | ||
615 | the caller is then just asked for a password! This mechanism could cause a | ||
616 | login attempt as YOUR real username to be logged over there if you use a | ||
617 | Borman-based telnet instead of "nc -t". | ||
618 | |||
619 | Got an unused network interface configured in your kernel [e.g. SLIP], or | ||
620 | support for alias addresses? Ifconfig one to be any address you like, and bind | ||
621 | to it with -s to enable all sorts of shenanigans with bogus source addresses. | ||
622 | The interface probably has to be UP before this works; some SLIP versions | ||
623 | need a far-end address before this is true. Hammering on UDP services is then | ||
624 | a no-brainer. What you can do to an unfiltered syslog daemon should be fairly | ||
625 | obvious; trimming the conf file can help protect against it. Many routers out | ||
626 | there still blindly believe what they receive via RIP and other routing | ||
627 | protocols. Although most UDP echo and chargen servers check if an incoming | ||
628 | packet was sent from *another* "internal" UDP server, there are many that still | ||
629 | do not, any two of which [or many, for that matter] could keep each other | ||
630 | entertained for hours at the expense of bandwidth. And you can always make | ||
631 | someone wonder why she's being probed by nsa.gov. | ||
632 | |||
633 | Your TCP spoofing possibilities are mostly limited to destinations you can | ||
634 | source-route to while locally bound to your phony address. Many sites block | ||
635 | source-routed packets these days for precisely this reason. If your kernel | ||
636 | does oddball things when sending source-routed packets, try moving the pointer | ||
637 | around with -G. You may also have to fiddle with the routing on your own | ||
638 | machine before you start receiving packets back. Warning: some machines still | ||
639 | send out traffic using the source address of the outbound interface, regardless | ||
640 | of your binding, especially in the case of localhost. Check first. If you can | ||
641 | open a connection but then get no data back from it, the target host is | ||
642 | probably killing the IP options on its end [this is an option inside TCP | ||
643 | wrappers and several other packages], which happens after the 3-way handshake | ||
644 | is completed. If you send some data and observe the "send-q" side of "netstat" | ||
645 | for that connection increasing but never getting sent, that's another symptom. | ||
646 | Beware: if Sendmail 8.7.x detects a source-routed SMTP connection, it extracts | ||
647 | the hop list and sticks it in the Received: header! | ||
648 | |||
649 | SYN bombing [sometimes called "hosing"] can disable many TCP servers, and if | ||
650 | you hit one often enough, you can keep it unreachable for days. As is true of | ||
651 | many other denial-of-service attacks, there is currently no defense against it | ||
652 | except maybe at the human level. Making kernel SOMAXCONN considerably larger | ||
653 | than the default and the half-open timeout smaller can help, and indeed some | ||
654 | people running large high-performance web servers have *had* to do that just to | ||
655 | handle normal traffic. Taking out mailers and web servers is sociopathic, but | ||
656 | on the other hand it is sometimes useful to be able to, say, disable a site's | ||
657 | identd daemon for a few minutes. If someone realizes what is going on, | ||
658 | backtracing will still be difficult since the packets have a phony source | ||
659 | address, but calls to enough ISP NOCs might eventually pinpoint the source. | ||
660 | It is also trivial for a clueful ISP to watch for or even block outgoing | ||
661 | packets with obviously fake source addresses, but as we know many of them are | ||
662 | not clueful or willing to get involved in such hassles. Besides, outbound | ||
663 | packets with an [otherwise unreachable] source address in one of their net | ||
664 | blocks would look fairly legitimate. | ||
665 | |||
666 | Notes | ||
667 | ===== | ||
668 | |||
669 | A discussion of various caveats, subtleties, and the design of the innards. | ||
670 | |||
671 | As of version 1.07 you can construct a single file containing command arguments | ||
672 | and then some data to transfer. Netcat is now smart enough to pick out the | ||
673 | first line and build the argument list, and send any remaining data across the | ||
674 | net to one or multiple ports. The first release of netcat had trouble with | ||
675 | this -- it called fgets() for the command line argument, which behind the | ||
676 | scenes does a large read() from standard input, perhaps 4096 bytes or so, and | ||
677 | feeds that out to the fgets() library routine. By the time netcat 1.00 started | ||
678 | directly read()ing stdin for more data, 4096 bytes of it were gone. It now | ||
679 | uses raw read() everywhere and does the right thing whether reading from files, | ||
680 | pipes, or ttys. If you use this for multiple-port connections, the single | ||
681 | block of data will now be a maximum of 8K minus the first line. Improvements | ||
682 | have been made to the logic in sending the saved chunk to each new port. Note | ||
683 | that any command-line arguments hidden using this mechanism could still be | ||
684 | extracted from a core dump. | ||
685 | |||
686 | When netcat receives an inbound UDP connection, it creates a "connected socket" | ||
687 | back to the source of the connection so that it can also send out data using | ||
688 | normal write(). Using this mechanism instead of recvfrom/sendto has several | ||
689 | advantages -- the read/write select loop is simplified, and ICMP errors can in | ||
690 | effect be received by non-root users. However, it has the subtle side effect | ||
691 | that if further UDP packets arrive from the caller but from different source | ||
692 | ports, the listener will not receive them. UDP listen mode on a multihomed | ||
693 | machine may have similar quirks unless you specifically bind to one of its | ||
694 | addresses. It is not clear that kernel support for UDP connected sockets | ||
695 | and/or my understanding of it is entirely complete here, so experiment... | ||
696 | |||
697 | You should be aware of some subtleties concerning UDP scanning. If -z is on, | ||
698 | netcat attempts to send a single null byte to the target port, twice, with a | ||
699 | small time in between. You can either use the -w timeout, or netcat will try | ||
700 | to make a "sideline" TCP connection to the target to introduce a small time | ||
701 | delay equal to the round-trip time between you and the target. Note that if | ||
702 | you have a -w timeout and -i timeout set, BOTH take effect and you wait twice | ||
703 | as long. The TCP connection is to a normally refused port to minimize traffic, | ||
704 | but if you notice a UDP fast-scan taking somewhat longer than it should, it | ||
705 | could be that the target is actually listening on the TCP port. Either way, | ||
706 | any ICMP port-unreachable messages from the target should have arrived in the | ||
707 | meantime. The second single-byte UDP probe is then sent. Under BSD kernels, | ||
708 | the ICMP error is delivered to the "connected socket" and the second write | ||
709 | returns an error, which tells netcat that there is NOT a UDP service there. | ||
710 | While Linux seems to be a fortunate exception, under many SYSV derived kernels | ||
711 | the ICMP is not delivered, and netcat starts reporting that *all* the ports are | ||
712 | "open" -- clearly wrong. [Some systems may not even *have* the "udp connected | ||
713 | socket" concept, and netcat in its current form will not work for UDP at all.] | ||
714 | If -z is specified and only one UDP port is probed, netcat's exit status | ||
715 | reflects whether the connection was "open" or "refused" as with TCP. | ||
716 | |||
717 | It may also be that UDP packets are being blocked by filters with no ICMP error | ||
718 | returns, in which case everything will time out and return "open". This all | ||
719 | sounds backwards, but that's how UDP works. If you're not sure, try "echo | ||
720 | w00gumz | nc -u -w 2 target 7" to see if you can reach its UDP echo port at | ||
721 | all. You should have no trouble using a BSD-flavor system to scan for UDP | ||
722 | around your own network, although flooding a target with the high activity that | ||
723 | -z generates will cause it to occasionally drop packets and indicate false | ||
724 | "opens". A more "correct" way to do this is collect and analyze the ICMP | ||
725 | errors, as does SATAN's "udp_scan" backend, but then again there's no guarantee | ||
726 | that the ICMP gets back to you either. Udp_scan also does the zero-byte | ||
727 | probes but is excruciatingly careful to calculate its own round-trip timing | ||
728 | average and dynamically set its own response timeouts along with decoding any | ||
729 | ICMP received. Netcat uses a much sleazier method which is nonetheless quite | ||
730 | effective. Cisco routers are known to have a "dead time" in between ICMP | ||
731 | responses about unreachable UDP ports, so a fast scan of a cisco will show | ||
732 | almost everything "open". If you are looking for a specific UDP service, you | ||
733 | can construct a file containing the right bytes to trigger a response from the | ||
734 | other end and send that as standard input. Netcat will read up to 8K of the | ||
735 | file and send the same data to every UDP port given. Note that you must use a | ||
736 | timeout in this case [as would any other UDP client application] since the | ||
737 | two-write probe only happens if -z is specified. | ||
738 | |||
739 | Many telnet servers insist on a specific set of option negotiations before | ||
740 | presenting a login banner. On a raw connection you will see this as small | ||
741 | amount of binary gook. My attempts to create fixed input bytes to make a | ||
742 | telnetd happy worked some places but failed against newer BSD-flavor ones, | ||
743 | possibly due to timing problems, but there are a couple of much better | ||
744 | workarounds. First, compile with -DTELNET and use -t if you just want to get | ||
745 | past the option negotiation and talk to something on a telnet port. You will | ||
746 | still see the binary gook -- in fact you'll see a lot more of it as the options | ||
747 | are responded to behind the scenes. The telnet responder does NOT update the | ||
748 | total byte count, or show up in the hex dump -- it just responds negatively to | ||
749 | any options read from the incoming data stream. If you want to use a normal | ||
750 | full-blown telnet to get to something but also want some of netcat's features | ||
751 | involved like settable ports or timeouts, construct a tiny "foo" script: | ||
752 | |||
753 | #! /bin/sh | ||
754 | exec nc -otheroptions targethost 23 | ||
755 | |||
756 | and then do | ||
757 | |||
758 | nc -l -p someport -e foo localhost & | ||
759 | telnet localhost someport | ||
760 | |||
761 | and your telnet should connect transparently through the exec'ed netcat to | ||
762 | the target, using whatever options you supplied in the "foo" script. Don't | ||
763 | use -t inside the script, or you'll wind up sending *two* option responses. | ||
764 | |||
765 | I've observed inconsistent behavior under some Linuxes [perhaps just older | ||
766 | ones?] when binding in listen mode. Sometimes netcat binds only to "localhost" | ||
767 | if invoked with no address or port arguments, and sometimes it is unable to | ||
768 | bind to a specific address for listening if something else is already listening | ||
769 | on "any". The former problem can be worked around by specifying "-s 0.0.0.0", | ||
770 | which will do the right thing despite netcat claiming that it's listening on | ||
771 | [127.0.0.1]. This is a known problem -- for example, there's a mention of it | ||
772 | in the makefile for SOCKS. On the flip side, binding to localhost and sending | ||
773 | packets to some other machine doesn't work as you'd expect -- they go out with | ||
774 | the source address of the sending interface instead. The Linux kernel contains | ||
775 | a specific check to ensure that packets from 127.0.0.1 are never sent to the | ||
776 | wire; other kernels may contain similar code. Linux, of course, *still* | ||
777 | doesn't support source-routing, but they claim that it and many other network | ||
778 | improvements are at least breathing hard. | ||
779 | |||
780 | There are several possible errors associated with making TCP connections, but | ||
781 | to specifically see anything other than "refused", one must wait the full | ||
782 | kernel-defined timeout for a connection to fail. Netcat's mechanism of | ||
783 | wrapping an alarm timer around the connect prevents the *real* network error | ||
784 | from being returned -- "errno" at that point indicates "interrupted system | ||
785 | call" since the connect attempt was interrupted. Some old 4.3 BSD kernels | ||
786 | would actually return things like "host unreachable" immediately if that was | ||
787 | the case, but most newer kernels seem to wait the full timeout and *then* pass | ||
788 | back the real error. Go figure. In this case, I'd argue that the old way was | ||
789 | better, despite those same kernels generally being the ones that tear down | ||
790 | *established* TCP connections when ICMP-bombed. | ||
791 | |||
792 | Incoming socket options are passed to applications by the kernel in the | ||
793 | kernel's own internal format. The socket-options structure for source-routing | ||
794 | contains the "first-hop" IP address first, followed by the rest of the real | ||
795 | options list. The kernel uses this as is when sending reply packets -- the | ||
796 | structure is therefore designed to be more useful to the kernel than to humans, | ||
797 | but the hex dump of it that netcat produces is still useful to have. | ||
798 | |||
799 | Kernels treat source-routing options somewhat oddly, but it sort of makes sense | ||
800 | once one understands what's going on internally. The options list of addresses | ||
801 | must contain hop1, hop2, ..., destination. When a source-routed packet is sent | ||
802 | by the kernel [at least BSD], the actual destination address becomes irrelevant | ||
803 | because it is replaced with "hop1", "hop1" is removed from the options list, | ||
804 | and all the other addresses in the list are shifted up to fill the hole. Thus | ||
805 | the outbound packet is sent from your chosen source address to the first | ||
806 | *gateway*, and the options list now contains hop2, ..., destination. During | ||
807 | all this address shuffling, the kernel does NOT change the pointer value, which | ||
808 | is why it is useful to be able to set the pointer yourself -- you can construct | ||
809 | some really bizarre return paths, and send your traffic fairly directly to the | ||
810 | target but around some larger loop on the way back. Some Sun kernels seem to | ||
811 | never flip the source-route around if it contains less than three hops, never | ||
812 | reset the pointer anyway, and tries to send the packet [with options containing | ||
813 | a "completed" source route!!] directly back to the source. This is way broken, | ||
814 | of course. [Maybe ipforwarding has to be on? I haven't had an opportunity to | ||
815 | beat on it thoroughly yet.] | ||
816 | |||
817 | "Credits" section: The original idea for netcat fell out of a long-standing | ||
818 | desire and fruitless search for a tool resembling it and having the same | ||
819 | features. After reading some other network code and realizing just how many | ||
820 | cool things about sockets could be controlled by the calling user, I started | ||
821 | on the basics and the rest fell together pretty quickly. Some port-scanning | ||
822 | ideas were taken from Venema/Farmer's SATAN tool kit, and Pluvius' "pscan" | ||
823 | utility. Healthy amounts of BSD kernel source were perused in an attempt to | ||
824 | dope out socket options and source-route handling; additional help was obtained | ||
825 | from Dave Borman's telnet sources. The select loop is loosely based on fairly | ||
826 | well-known code from "rsh" and Richard Stevens' "sock" program [which itself is | ||
827 | sort of a "netcat" with more obscure features], with some more paranoid | ||
828 | sanity-checking thrown in to guard against the distinct likelihood that there | ||
829 | are subtleties about such things I still don't understand. I found the | ||
830 | argument-hiding method cleanly implemented in Barrett's "deslogin"; reading the | ||
831 | line as input allows greater versatility and is much less prone to cause | ||
832 | bizarre problems than the more common trick of overwriting the argv array. | ||
833 | After the first release, several people contributed portability fixes; they are | ||
834 | credited in generic.h and the Makefile. Lauren Burka inspired the ascii art | ||
835 | for this revised document. Dean Gaudet at Wired supplied a precursor to | ||
836 | the hex-dump code, and mudge@l0pht.com originally experimented with and | ||
837 | supplied code for the telnet-options responder. Outbound "-e <prog>" resulted | ||
838 | from a need to quietly bypass a firewall installation. Other suggestions and | ||
839 | patches have rolled in for which I am always grateful, but there are only 26 | ||
840 | hours per day and a discussion of feature creep near the end of this document. | ||
841 | |||
842 | Netcat was written with the Russian railroad in mind -- conservatively built | ||
843 | and solid, but it *will* get you there. While the coding style is fairly | ||
844 | "tight", I have attempted to present it cleanly [keeping *my* lines under 80 | ||
845 | characters, dammit] and put in plenty of comments as to why certain things | ||
846 | are done. Items I know to be questionable are clearly marked with "XXX". | ||
847 | Source code was made to be modified, but determining where to start is | ||
848 | difficult with some of the tangles of spaghetti code that are out there. | ||
849 | Here are some of the major points I feel are worth mentioning about netcat's | ||
850 | internal design, whether or not you agree with my approach. | ||
851 | |||
852 | Except for generic.h, which changes to adapt more platforms, netcat is a single | ||
853 | source file. This has the distinct advantage of only having to include headers | ||
854 | once and not having to re-declare all my functions in a billion different | ||
855 | places. I have attempted to contain all the gross who's-got-what-.h-file | ||
856 | things in one small dumping ground. Functions are placed "dependencies-first", | ||
857 | such that when the compiler runs into the calls later, it already knows the | ||
858 | type and arguments and won't complain. No function prototyping -- not even the | ||
859 | __P(()) crock -- is used, since it is more portable and a file of this size is | ||
860 | easy enough to check manually. Each function has a standard-format comment | ||
861 | ahead of it, which is easily found using the regexp " :$". I freely use gotos. | ||
862 | Loops and if-clauses are made as small and non-nested as possible, and the ends | ||
863 | of same *marked* for clarity [I wish everyone would do this!!]. | ||
864 | |||
865 | Large structures and buffers are all malloc()ed up on the fly, slightly larger | ||
866 | than the size asked for and zeroed out. This reduces the chances of damage | ||
867 | from those "end of the buffer" fencepost errors or runaway pointers escaping | ||
868 | off the end. These things are permanent per run, so nothing needs to be freed | ||
869 | until the program exits. | ||
870 | |||
871 | File descriptor zero is always expected to be standard input, even if it is | ||
872 | closed. If a new network descriptor winds up being zero, a different one is | ||
873 | asked for which will be nonzero, and fd zero is simply left kicking around | ||
874 | for the rest of the run. Why? Because everything else assumes that stdin is | ||
875 | always zero and "netfd" is always positive. This may seem silly, but it was a | ||
876 | lot easier to code. The new fd is obtained directly as a new socket, because | ||
877 | trying to simply dup() a new fd broke subsequent socket-style use of the new fd | ||
878 | under Solaris' stupid streams handling in the socket library. | ||
879 | |||
880 | The catch-all message and error handlers are implemented with an ample list of | ||
881 | phoney arguments to get around various problems with varargs. Varargs seems | ||
882 | like deliberate obfuscation in the first place, and using it would also | ||
883 | require use of vfprintf() which not all platforms support. The trailing | ||
884 | sleep in bail() is to allow output to flush, which is sometimes needed if | ||
885 | netcat is already on the other end of a network connection. | ||
886 | |||
887 | The reader may notice that the section that does DNS lookups seems much | ||
888 | gnarlier and more confusing than other parts. This is NOT MY FAULT. The | ||
889 | sockaddr and hostent abstractions are an abortion that forces the coder to | ||
890 | deal with it. Then again, a lot of BSD kernel code looks like similar | ||
891 | struct-pointer hell. I try to straighten it out somewhat by defining my own | ||
892 | HINF structure, containing names, ascii-format IP addresses, and binary IP | ||
893 | addresses. I fill this structure exactly once per host argument, and squirrel | ||
894 | everything safely away and handy for whatever wants to reference it later. | ||
895 | |||
896 | Where many other network apps use the FIONBIO ioctl to set non-blocking I/O | ||
897 | on network sockets, netcat uses straightforward blocking I/O everywhere. | ||
898 | This makes everything very lock-step, relying on the network and filesystem | ||
899 | layers to feed in data when needed. Data read in is completely written out | ||
900 | before any more is fetched. This may not be quite the right thing to do under | ||
901 | some OSes that don't do timed select() right, but this remains to be seen. | ||
902 | |||
903 | The hexdump routine is written to be as fast as possible, which is why it does | ||
904 | so much work itself instead of just sprintf()ing everything together. Each | ||
905 | dump line is built into a single buffer and atomically written out using the | ||
906 | lowest level I/O calls. Further improvements could undoubtedly be made by | ||
907 | using writev() and eliminating all sprintf()s, but it seems to fly right along | ||
908 | as is. If both exec-a-prog mode and a hexdump file is asked for, the hexdump | ||
909 | flag is deliberately turned off to avoid creating random zero-length files. | ||
910 | Files are opened in "truncate" mode; if you want "append" mode instead, change | ||
911 | the open flags in main(). | ||
912 | |||
913 | main() may look a bit hairy, but that's only because it has to go down the | ||
914 | argv list and handle multiple ports, random mode, and exit status. Efforts | ||
915 | have been made to place a minimum of code inside the getopt() loop. Any real | ||
916 | work is sent off to functions in what is hopefully a straightforward way. | ||
917 | |||
918 | Obligatory vendor-bash: If "nc" had become a standard utility years ago, | ||
919 | the commercial vendors would have likely packaged it setuid root and with | ||
920 | -DGAPING_SECURITY_HOLE turned on but not documented. It is hoped that netcat | ||
921 | will aid people in finding and fixing the no-brainer holes of this sort that | ||
922 | keep appearing, by allowing easier experimentation with the "bare metal" of | ||
923 | the network layer. | ||
924 | |||
925 | It could be argued that netcat already has too many features. I have tried | ||
926 | to avoid "feature creep" by limiting netcat's base functionality only to those | ||
927 | things which are truly relevant to making network connections and the everyday | ||
928 | associated DNS lossage we're used to. Option switches already have slightly | ||
929 | overloaded functionality. Random port mode is sort of pushing it. The | ||
930 | hex-dump feature went in later because it *is* genuinely useful. The | ||
931 | telnet-responder code *almost* verges on the gratuitous, especially since it | ||
932 | mucks with the data stream, and is left as an optional piece. Many people have | ||
933 | asked for example "how 'bout adding encryption?" and my response is that such | ||
934 | things should be separate entities that could pipe their data *through* netcat | ||
935 | instead of having their own networking code. I am therefore not completely | ||
936 | enthusiastic about adding any more features to this thing, although you are | ||
937 | still free to send along any mods you think are useful. | ||
938 | |||
939 | Nonetheless, at this point I think of netcat as my tcp/ip swiss army knife, | ||
940 | and the numerous companion programs and scripts to go with it as duct tape. | ||
941 | Duct tape of course has a light side and a dark side and binds the universe | ||
942 | together, and if I wrap enough of it around what I'm trying to accomplish, | ||
943 | it *will* work. Alternatively, if netcat is a large hammer, there are many | ||
944 | network protocols that are increasingly looking like nails by now... | ||
945 | |||
946 | _H* 960320 v1.10 RELEASE -- happy spring! | ||
diff --git a/src/usr.bin/nc/data/Makefile b/src/usr.bin/nc/data/Makefile new file mode 100644 index 0000000000..65cf185358 --- /dev/null +++ b/src/usr.bin/nc/data/Makefile | |||
@@ -0,0 +1,10 @@ | |||
1 | all: data rservice xor | ||
2 | |||
3 | data: data.c | ||
4 | cc -s -O -o data data.c | ||
5 | rservice: rservice.c | ||
6 | cc -s -O -o rservice rservice.c | ||
7 | xor: xor.c | ||
8 | cc -s -O -o xor xor.c | ||
9 | clean: | ||
10 | rm -f *.o data rservice xor | ||
diff --git a/src/usr.bin/nc/data/README b/src/usr.bin/nc/data/README new file mode 100644 index 0000000000..7e4b9fbf63 --- /dev/null +++ b/src/usr.bin/nc/data/README | |||
@@ -0,0 +1,9 @@ | |||
1 | For now, read the header comments inside each of these for documentation. | ||
2 | The programs are simple enough that they don't really need a Makefile any more | ||
3 | complex than the one given; ymmv. Data and xor may also be useful on DOS, | ||
4 | which is why there are hooks for it in the code. | ||
5 | |||
6 | data.c a primitive atob / btoa byte generator | ||
7 | *.d example input to "data -g" | ||
8 | rservice.c a utility for scripting up rsh/rexec attacks | ||
9 | xor.c generic xor handler | ||
diff --git a/src/usr.bin/nc/data/data.c b/src/usr.bin/nc/data/data.c new file mode 100644 index 0000000000..56c167fd96 --- /dev/null +++ b/src/usr.bin/nc/data/data.c | |||
@@ -0,0 +1,274 @@ | |||
1 | /* primitive arbitrary-data frontend for netcat. 0.9 960226 | ||
2 | only handles one value per ascii line, but at least parses 0xNN too | ||
3 | an input line containing "%r" during "-g" generates a random byte | ||
4 | |||
5 | todo: | ||
6 | make work on msloss jus' for kicks [workin' on it...] | ||
7 | |||
8 | syntax: data -X [limit] | ||
9 | where X is one of | ||
10 | d: dump raw bytes to ascii format | ||
11 | g: generate raw bytes from ascii input | ||
12 | c: generate ??? of value -- NOTYET | ||
13 | r: generate all random bytes | ||
14 | and limit is how many bytes to generate or dump [unspecified = infinite] | ||
15 | |||
16 | *Hobbit*, started 951004 or so and randomly screwed around with since */ | ||
17 | |||
18 | #include <stdio.h> | ||
19 | |||
20 | #ifdef MSDOS /* for MSC only at the moment... */ | ||
21 | #include <fcntl.h> | ||
22 | #else /* MSDOS */ | ||
23 | #include <sys/file.h> | ||
24 | #define HAVE_RANDOM /* XXX: might have to change */ | ||
25 | #endif /* MSDOS */ | ||
26 | |||
27 | static char buf_in [128]; | ||
28 | static char buf_raw [8192]; | ||
29 | static char surveysez[] = "survey sez... XXX\n"; | ||
30 | |||
31 | /* fgetss : | ||
32 | wrapper for fgets, that yanks trailing newlines. Doing the work ourselves | ||
33 | instead of calling strchr/strlen/whatever */ | ||
34 | char * fgetss (buf, len, from) | ||
35 | char * buf; | ||
36 | size_t len; | ||
37 | FILE * from; | ||
38 | { | ||
39 | register int x; | ||
40 | register char * p, * q; | ||
41 | p = fgets (buf, len, from); /* returns ptr to buf */ | ||
42 | if (! p) | ||
43 | return (NULL); | ||
44 | q = p; | ||
45 | for (x = 0; x < len; x++) { | ||
46 | *p = (*p & 0x7f); /* rip parity, just in case */ | ||
47 | switch (*p) { | ||
48 | case '\n': | ||
49 | case '\r': | ||
50 | case '\0': | ||
51 | *p = '\0'; | ||
52 | return (q); | ||
53 | } /* switch */ | ||
54 | p++; | ||
55 | } /* for */ | ||
56 | } /* fgetss */ | ||
57 | |||
58 | /* randint: | ||
59 | swiped from rndb.c. Generates an INT, you have to mask down to char. */ | ||
60 | int randint() | ||
61 | { | ||
62 | register int q; | ||
63 | register int x; | ||
64 | |||
65 | #ifndef HAVE_RANDOM | ||
66 | q = rand(); | ||
67 | #else | ||
68 | q = random(); | ||
69 | #endif | ||
70 | x = ((q >> 8) & 0xff); /* perturb low byte using some higher bits */ | ||
71 | x = q ^ x; | ||
72 | return (x); | ||
73 | } | ||
74 | |||
75 | main (argc, argv) | ||
76 | int argc; | ||
77 | char ** argv; | ||
78 | { | ||
79 | register unsigned char * p; | ||
80 | register char * q; | ||
81 | register int x; | ||
82 | int bc = 0; | ||
83 | int limit = 0; /* num to gen, or 0 = infinite */ | ||
84 | register int xlimit; /* running limit */ | ||
85 | FILE * txt; /* line-by-line ascii file */ | ||
86 | int raw; /* raw bytes fd */ | ||
87 | int dumping = 0; /* cmd flags ... */ | ||
88 | int genning = 0; | ||
89 | int randing = 0; | ||
90 | |||
91 | memset (buf_in, 0, sizeof (buf_in)); | ||
92 | memset (buf_raw, 0, sizeof (buf_raw)); | ||
93 | |||
94 | xlimit = 1; /* doubles as "exit flag" */ | ||
95 | bc = 1; /* preload, assuming "dump" */ | ||
96 | x = getpid() + 687319; | ||
97 | /* if your library doesnt have srandom/random, use srand/rand. [from rnd.c] */ | ||
98 | #ifndef HAVE_RANDOM | ||
99 | srand (time(0) + x); | ||
100 | #else | ||
101 | srandom (time(0) + x); | ||
102 | #endif | ||
103 | |||
104 | #ifdef O_BINARY | ||
105 | /* DOS stupidity */ | ||
106 | /* Aha: *here's* where that setmode() lib call conflict in ?BSD came from */ | ||
107 | x = setmode (0, O_BINARY); /* make stdin raw */ | ||
108 | if (x < 0) { | ||
109 | fprintf (stderr, "stdin binary setmode oops: %d\n", x); | ||
110 | exit (1); | ||
111 | } | ||
112 | x = setmode (1, O_BINARY); /* make stdout raw */ | ||
113 | if (x < 0) { | ||
114 | fprintf (stderr, "stdout binary setmode oops: %d\n", x); | ||
115 | exit (1); | ||
116 | } | ||
117 | #endif /* O_BINARY */ | ||
118 | |||
119 | if (argv[1]) { | ||
120 | p = argv[1]; /* shit-simple single arg parser... */ | ||
121 | if (*p == '-') /* dash is optional, we'll deal */ | ||
122 | p++; | ||
123 | if (*p == 'd') | ||
124 | dumping++; | ||
125 | if (*p == 'g') | ||
126 | genning++; | ||
127 | if (*p == 'r') | ||
128 | randing++; | ||
129 | } /* if argv 1 */ | ||
130 | |||
131 | /* optional second argument: limit # of bytes shoveled either way */ | ||
132 | if (argv[2]) { | ||
133 | x = atoi (argv[2]); | ||
134 | if (x) | ||
135 | limit = x; | ||
136 | else | ||
137 | goto wrong; | ||
138 | xlimit = limit; | ||
139 | } | ||
140 | |||
141 | /* Since this prog would likely best be written in assmbler, I'm gonna | ||
142 | write it *like* assembler. So there. */ | ||
143 | |||
144 | if (randing) | ||
145 | goto do_rand; | ||
146 | |||
147 | nextbuf: /* loop sleaze */ | ||
148 | |||
149 | if (dumping) { /* switch off to wherever */ | ||
150 | if (genning) | ||
151 | goto wrong; | ||
152 | goto do_dump; | ||
153 | } | ||
154 | if (genning) | ||
155 | goto do_gen; | ||
156 | wrong: | ||
157 | fprintf (stderr, surveysez); /* if both or neither */ | ||
158 | exit (1); | ||
159 | |||
160 | do_gen: | ||
161 | /* here if genning -- original functionality */ | ||
162 | q = buf_raw; | ||
163 | bc = 0; | ||
164 | /* suck up lines until eof or buf_raw is full */ | ||
165 | while (1) { | ||
166 | p = fgetss (buf_in, 120, stdin); | ||
167 | if (! p) | ||
168 | break; /* EOF */ | ||
169 | /* super-primitive version first: one thingie per line */ | ||
170 | if (*p == '#') /* comment */ | ||
171 | continue; | ||
172 | if (*p == '\0') /* blank line */ | ||
173 | continue; | ||
174 | if (*p == '%') { /* escape char? */ | ||
175 | p++; | ||
176 | if (*p == 'r') { /* random byte */ | ||
177 | x = randint(); | ||
178 | goto stuff; | ||
179 | } /* %r */ | ||
180 | } /* if "%" escape */ | ||
181 | if (*p == '0') | ||
182 | if (*(p+1) == 'x') /* 0x?? */ | ||
183 | goto hex; | ||
184 | x = atoi (p); /* reg'lar decimal number */ | ||
185 | goto stuff; | ||
186 | |||
187 | hex: | ||
188 | /* A 65 a 97 */ | ||
189 | /* xxx: use a conversion table for this or something. Since we ripped the | ||
190 | parity bit, we only need a preset array of 128 with downconversion factors | ||
191 | loaded in *once*. maybe look at scanf... */ | ||
192 | p++; p++; /* point at hex-chars */ | ||
193 | x = 0; | ||
194 | if ((*p > 96) && (*p < 123)) /* a-z */ | ||
195 | *p = (*p - 32); /* this is massively clumsy */ | ||
196 | if ((*p > 64) && (*p < 71)) /* A-F */ | ||
197 | x = (*p - 55); | ||
198 | if ((*p > 47) && (*p < 58)) /* digits */ | ||
199 | x = (*p - 48); | ||
200 | p++; | ||
201 | if (*p) /* another digit? */ | ||
202 | x = (x << 4); /* shift to hi half */ | ||
203 | if ((*p > 96) && (*p < 123)) /* a-z */ | ||
204 | *p = (*p - 32); | ||
205 | if ((*p > 64) && (*p < 71)) /* A-F */ | ||
206 | x = (x | (*p - 55)); /* lo half */ | ||
207 | if ((*p > 47) && (*p < 58)) /* digits */ | ||
208 | x = (x | (*p - 48)); | ||
209 | |||
210 | /* fall thru */ | ||
211 | stuff: /* cvt to byte and add to buffer */ | ||
212 | *q = (x & 0xff); | ||
213 | q++; | ||
214 | bc++; | ||
215 | if (limit) { | ||
216 | xlimit--; | ||
217 | if (xlimit == 0) /* max num reached */ | ||
218 | break; | ||
219 | } /* limit */ | ||
220 | if (bc >= sizeof (buf_raw)) /* buffer full */ | ||
221 | break; | ||
222 | } /* while 1 */ | ||
223 | |||
224 | /* now in theory we have our buffer formed; shovel it out */ | ||
225 | x = write (1, buf_raw, bc); | ||
226 | if (x <= 0) { | ||
227 | fprintf (stderr, "write oops: %d\n", x); | ||
228 | exit (1); | ||
229 | } | ||
230 | if (xlimit && p) | ||
231 | goto nextbuf; /* go get some more */ | ||
232 | exit (0); | ||
233 | |||
234 | do_dump: | ||
235 | /* here if dumping raw stuff into an ascii file */ | ||
236 | /* gad, this is *so* much simpler! can we say "don't rewrite printf"? */ | ||
237 | x = read (0, buf_raw, 8192); | ||
238 | if (x <= 0) | ||
239 | exit (0); | ||
240 | q = buf_raw; | ||
241 | for ( ; x > 0; x--) { | ||
242 | p = q; | ||
243 | printf ("%-3.3d # 0x%-2.2x # ", *p, *p); | ||
244 | if ((*p > 31) && (*p < 127)) | ||
245 | printf ("%c %d\n", *p, bc); | ||
246 | else | ||
247 | printf (". %d\n", bc); | ||
248 | q++; | ||
249 | bc++; | ||
250 | if (limit) { | ||
251 | xlimit--; | ||
252 | if (xlimit == 0) { | ||
253 | fflush (stdout); | ||
254 | exit (0); | ||
255 | } | ||
256 | } /* limit */ | ||
257 | } /* for */ | ||
258 | goto nextbuf; | ||
259 | |||
260 | do_rand: | ||
261 | /* here if generating all-random bytes. Stays in this loop */ | ||
262 | p = buf_raw; | ||
263 | while (1) { | ||
264 | *p = (randint() & 0xff); | ||
265 | write (1, p, 1); /* makes very slow! */ | ||
266 | if (limit) { | ||
267 | xlimit--; | ||
268 | if (xlimit == 0) | ||
269 | break; | ||
270 | } | ||
271 | } /* while */ | ||
272 | exit (0); | ||
273 | |||
274 | } /* main */ | ||
diff --git a/src/usr.bin/nc/data/dns-any.d b/src/usr.bin/nc/data/dns-any.d new file mode 100644 index 0000000000..77b014cf70 --- /dev/null +++ b/src/usr.bin/nc/data/dns-any.d | |||
@@ -0,0 +1,36 @@ | |||
1 | # dns "any for ." query, to udp 53 | ||
2 | # if tcp: precede with 2 bytes of len: | ||
3 | # 0 | ||
4 | # 17 | ||
5 | # you should get at least *one* record back out | ||
6 | |||
7 | # HEADER: | ||
8 | 0 # query id = 2 | ||
9 | 2 | ||
10 | |||
11 | 1 # flags/opcodes = query, dorecurse | ||
12 | 0 | ||
13 | |||
14 | 0 # qdcount, i.e. nqueries: 1 | ||
15 | 1 | ||
16 | |||
17 | 0 # ancount: answers, 0 | ||
18 | 0 | ||
19 | |||
20 | 0 # nscount: 0 | ||
21 | 0 | ||
22 | |||
23 | 0 # addl records: 0 | ||
24 | 0 | ||
25 | |||
26 | # end of fixed header | ||
27 | |||
28 | 0 # name-len: 0 for ".", lenbyte plus name-bytes otherwise | ||
29 | |||
30 | 0 # type: any, 255 | ||
31 | 0xff | ||
32 | |||
33 | 0 # class: IN | ||
34 | 1 | ||
35 | |||
36 | # i think that's it.. | ||
diff --git a/src/usr.bin/nc/data/nfs-0.d b/src/usr.bin/nc/data/nfs-0.d new file mode 100644 index 0000000000..0360938227 --- /dev/null +++ b/src/usr.bin/nc/data/nfs-0.d | |||
@@ -0,0 +1,59 @@ | |||
1 | # UDP NFS null-proc call; finds active NFS listeners on port 2049. | ||
2 | # If you get *something* back, there's an NFS server there. | ||
3 | |||
4 | 000 # XID: 4 trash bytes | ||
5 | 001 | ||
6 | 002 | ||
7 | 003 | ||
8 | |||
9 | 000 # CALL: 0 | ||
10 | 000 | ||
11 | 000 | ||
12 | 000 | ||
13 | |||
14 | 000 # RPC version: 2 | ||
15 | 000 | ||
16 | 000 | ||
17 | 002 | ||
18 | |||
19 | 000 # nfs: 100003 | ||
20 | 001 | ||
21 | 0x86 | ||
22 | 0xa3 | ||
23 | |||
24 | 000 # version: 1 | ||
25 | 000 | ||
26 | 000 | ||
27 | 001 | ||
28 | |||
29 | 000 # procedure number: 0 | ||
30 | 000 | ||
31 | 000 | ||
32 | 000 | ||
33 | |||
34 | 000 # port: junk | ||
35 | 000 | ||
36 | 000 | ||
37 | 000 | ||
38 | |||
39 | 000 # auth trash | ||
40 | 000 | ||
41 | 000 | ||
42 | 000 | ||
43 | |||
44 | 000 # auth trash | ||
45 | 000 | ||
46 | 000 | ||
47 | 000 | ||
48 | |||
49 | 000 # auth trash | ||
50 | 000 | ||
51 | 000 | ||
52 | 000 | ||
53 | |||
54 | 000 # extra auth trash? probably not needed | ||
55 | 000 | ||
56 | 000 | ||
57 | 000 | ||
58 | |||
59 | # that's it! | ||
diff --git a/src/usr.bin/nc/data/pm.d b/src/usr.bin/nc/data/pm.d new file mode 100644 index 0000000000..fe327693a9 --- /dev/null +++ b/src/usr.bin/nc/data/pm.d | |||
@@ -0,0 +1,8 @@ | |||
1 | # obligatory duplicate of dr delete's Livingston portmaster crash, aka | ||
2 | # telnet break. Fire into its telnet listener. An *old* bug by now, but | ||
3 | # consider the small window one might obtain from a slightly out-of-rev PM | ||
4 | # used as a firewall, that starts routing IP traffic BEFORE its filter sets | ||
5 | # are fully loaded... | ||
6 | |||
7 | 255 # 0xff # . 1 | ||
8 | 243 # 0xf3 # . 2 | ||
diff --git a/src/usr.bin/nc/data/pmap-dump.d b/src/usr.bin/nc/data/pmap-dump.d new file mode 100644 index 0000000000..bc6b63277d --- /dev/null +++ b/src/usr.bin/nc/data/pmap-dump.d | |||
@@ -0,0 +1,60 @@ | |||
1 | # portmap dump request: like "rpcinfo -p" but via UDP instead | ||
2 | # send to UDP 111 and hope it's not a logging portmapper! | ||
3 | # split into longwords, since rpc apparently only deals with them | ||
4 | |||
5 | 001 # 0x01 # . # XID: 4 trash bytes | ||
6 | 002 # 0x02 # . | ||
7 | 003 # 0x03 # . | ||
8 | 004 # 0x04 # . | ||
9 | |||
10 | 000 # 0x00 # . # MSG: int 0=call, 1=reply | ||
11 | 000 # 0x00 # . | ||
12 | 000 # 0x00 # . | ||
13 | 000 # 0x00 # . | ||
14 | |||
15 | 000 # 0x00 # . # pmap call body: rpc version=2 | ||
16 | 000 # 0x00 # . | ||
17 | 000 # 0x00 # . | ||
18 | 002 # 0x02 # . | ||
19 | |||
20 | 000 # 0x00 # . # pmap call body: prog=PMAP, 100000 | ||
21 | 001 # 0x01 # . | ||
22 | 134 # 0x86 # . | ||
23 | 160 # 0xa0 # . | ||
24 | |||
25 | 000 # 0x00 # . # pmap call body: progversion=2 | ||
26 | 000 # 0x00 # . | ||
27 | 000 # 0x00 # . | ||
28 | 002 # 0x02 # . | ||
29 | |||
30 | 000 # 0x00 # . # pmap call body: proc=DUMP, 4 | ||
31 | 000 # 0x00 # . | ||
32 | 000 # 0x00 # . | ||
33 | 004 # 0x04 # . | ||
34 | |||
35 | # with AUTH_NONE, there are 4 zero integers [16 bytes] here | ||
36 | |||
37 | 000 # 0x00 # . # auth junk: cb_cred: auth_unix = 1; NONE = 0 | ||
38 | 000 # 0x00 # . | ||
39 | 000 # 0x00 # . | ||
40 | 000 # 0x00 # . | ||
41 | |||
42 | 000 # 0x00 # . # auth junk | ||
43 | 000 # 0x00 # . | ||
44 | 000 # 0x00 # . | ||
45 | 000 # 0x00 # . | ||
46 | |||
47 | 000 # 0x00 # . # auth junk | ||
48 | 000 # 0x00 # . | ||
49 | 000 # 0x00 # . | ||
50 | 000 # 0x00 # . | ||
51 | |||
52 | 000 # 0x00 # . # auth junk | ||
53 | 000 # 0x00 # . | ||
54 | 000 # 0x00 # . | ||
55 | 000 # 0x00 # . | ||
56 | |||
57 | # The reply you get back contains your XID, int 1 if "accepted", and | ||
58 | # a whole mess of gobbledygook containing program numbers, versions, | ||
59 | # and ports that rpcinfo knows how to decode. For the moment, you get | ||
60 | # to wade through it yourself... | ||
diff --git a/src/usr.bin/nc/data/pmap-mnt.d b/src/usr.bin/nc/data/pmap-mnt.d new file mode 100644 index 0000000000..00588ba41f --- /dev/null +++ b/src/usr.bin/nc/data/pmap-mnt.d | |||
@@ -0,0 +1,78 @@ | |||
1 | # portmap request for mountd [or whatever; see where prog=MOUNT] | ||
2 | # send to UDP 111 and hope it's not a logging portmapper! | ||
3 | # split into longwords, since rpc apparently only deals with them | ||
4 | |||
5 | 001 # 0x01 # . # XID: 4 trash bytes | ||
6 | 002 # 0x02 # . | ||
7 | 003 # 0x03 # . | ||
8 | 004 # 0x04 # . | ||
9 | |||
10 | 000 # 0x00 # . # MSG: int 0=call, 1=reply | ||
11 | 000 # 0x00 # . | ||
12 | 000 # 0x00 # . | ||
13 | 000 # 0x00 # . | ||
14 | |||
15 | 000 # 0x00 # . # pmap call body: rpc version=2 | ||
16 | 000 # 0x00 # . | ||
17 | 000 # 0x00 # . | ||
18 | 002 # 0x02 # . | ||
19 | |||
20 | 000 # 0x00 # . # pmap call body: prog=PMAP, 100000 | ||
21 | 001 # 0x01 # . | ||
22 | 134 # 0x86 # . | ||
23 | 160 # 0xa0 # . | ||
24 | |||
25 | 000 # 0x00 # . # pmap call body: progversion=2 | ||
26 | 000 # 0x00 # . | ||
27 | 000 # 0x00 # . | ||
28 | 002 # 0x02 # . | ||
29 | |||
30 | 000 # 0x00 # . # pmap call body: proc=GETPORT, 3 | ||
31 | 000 # 0x00 # . | ||
32 | 000 # 0x00 # . | ||
33 | 003 # 0x03 # . | ||
34 | |||
35 | # with AUTH_NONE, there are 4 zero integers [16 bytes] here | ||
36 | |||
37 | 000 # 0x00 # . # auth junk: cb_cred: auth_unix = 1; NONE = 0 | ||
38 | 000 # 0x00 # . | ||
39 | 000 # 0x00 # . | ||
40 | 000 # 0x00 # . | ||
41 | |||
42 | 000 # 0x00 # . # auth junk | ||
43 | 000 # 0x00 # . | ||
44 | 000 # 0x00 # . | ||
45 | 000 # 0x00 # . | ||
46 | |||
47 | 000 # 0x00 # . # auth junk | ||
48 | 000 # 0x00 # . | ||
49 | 000 # 0x00 # . | ||
50 | 000 # 0x00 # . | ||
51 | |||
52 | 000 # 0x00 # . # auth junk | ||
53 | 000 # 0x00 # . | ||
54 | 000 # 0x00 # . | ||
55 | 000 # 0x00 # . | ||
56 | |||
57 | 000 # 0x00 # . # prog=MOUNT, 100005 | ||
58 | 001 # 0x01 # . | ||
59 | 134 # 0x86 # . | ||
60 | 165 # 0xa5 # . | ||
61 | |||
62 | 000 # 0x00 # . # progversion=1 | ||
63 | 000 # 0x00 # . | ||
64 | 000 # 0x00 # . | ||
65 | 001 # 0x01 # . | ||
66 | |||
67 | 000 # 0x00 # . # protocol=udp, 17 | ||
68 | 000 # 0x00 # . | ||
69 | 000 # 0x00 # . | ||
70 | 017 # 0x11 # . | ||
71 | |||
72 | 000 # 0x00 # . # proc num = junk | ||
73 | 000 # 0x00 # . | ||
74 | 000 # 0x00 # . | ||
75 | 000 # 0x00 # . | ||
76 | |||
77 | # The reply you get back contains your XID, int 1 if "accepted", and | ||
78 | # mountd's port number at the end or 0 if not registered. | ||
diff --git a/src/usr.bin/nc/data/rip.d b/src/usr.bin/nc/data/rip.d new file mode 100644 index 0000000000..da505e2143 --- /dev/null +++ b/src/usr.bin/nc/data/rip.d | |||
@@ -0,0 +1,52 @@ | |||
1 | # struct netinfo { | ||
2 | # struct sockaddr rip_dst; /* destination net/host */ | ||
3 | # int rip_metric; /* cost of route */ | ||
4 | # }; | ||
5 | # struct rip { | ||
6 | # u_char rip_cmd; /* request/response */ | ||
7 | # u_char rip_vers; /* protocol version # */ | ||
8 | # u_char rip_res1[2]; /* pad to 32-bit boundary */ | ||
9 | # union { | ||
10 | # struct netinfo ru_nets[1]; /* variable length... */ | ||
11 | # char ru_tracefile[1]; /* ditto ... */ | ||
12 | # } ripun; | ||
13 | #define rip_nets ripun.ru_nets | ||
14 | #define rip_tracefile ripun.ru_tracefile | ||
15 | #define RIPCMD_REQUEST 1 /* want info */ | ||
16 | #define RIPCMD_RESPONSE 2 /* responding to request */ | ||
17 | #define RIPCMD_TRACEON 3 /* turn tracing on */ | ||
18 | #define RIPCMD_TRACEOFF 4 /* turn it off */ | ||
19 | #define HOPCNT_INFINITY 16 /* per Xerox NS */ | ||
20 | #define MAXPACKETSIZE 512 /* max broadcast size */ | ||
21 | |||
22 | ### RIP packet redux | ||
23 | ### UDP send FROM clued-rtr/520 to target/520 | ||
24 | 2 # RIPCMD_RESPONSE | ||
25 | 1 # version | ||
26 | 0 # padding | ||
27 | 0 | ||
28 | |||
29 | # sockaddr-plus-metric structs begin, as many as necessary... | ||
30 | 0 # len | ||
31 | 2 # AF_INET | ||
32 | 0 # port | ||
33 | 0 | ||
34 | # addr bytes: | ||
35 | X | ||
36 | Y | ||
37 | Z | ||
38 | Q | ||
39 | 0 # filler, out to 16 bytes [sizeof (sockaddr)] ... | ||
40 | 0 | ||
41 | 0 | ||
42 | 0 | ||
43 | 0 | ||
44 | 0 | ||
45 | 0 | ||
46 | 0 | ||
47 | 0 # metric: net-order integer | ||
48 | 0 | ||
49 | 0 | ||
50 | 1 | ||
51 | |||
52 | ## that's it | ||
diff --git a/src/usr.bin/nc/data/rservice.c b/src/usr.bin/nc/data/rservice.c new file mode 100644 index 0000000000..1085d9cb78 --- /dev/null +++ b/src/usr.bin/nc/data/rservice.c | |||
@@ -0,0 +1,68 @@ | |||
1 | /* generate ^@string1^@string2^@cmd^@ input to netcat, for scripting up | ||
2 | rsh/rexec attacks. Needs to be a prog because shells strip out nulls. | ||
3 | |||
4 | args: | ||
5 | locuser remuser [cmd] | ||
6 | remuser passwd [cmd] | ||
7 | |||
8 | cmd defaults to "pwd". | ||
9 | |||
10 | ... whatever. _H*/ | ||
11 | |||
12 | #include <stdio.h> | ||
13 | |||
14 | /* change if you like; "id" is a good one for figuring out if you won too */ | ||
15 | static char cmd[] = "pwd"; | ||
16 | |||
17 | static char buf [256]; | ||
18 | |||
19 | main(argc, argv) | ||
20 | int argc; | ||
21 | char * argv[]; | ||
22 | { | ||
23 | register int x; | ||
24 | register int y; | ||
25 | char * p; | ||
26 | char * q; | ||
27 | |||
28 | p = buf; | ||
29 | memset (buf, 0, 256); | ||
30 | |||
31 | p++; /* first null */ | ||
32 | y = 1; | ||
33 | |||
34 | if (! argv[1]) | ||
35 | goto wrong; | ||
36 | x = strlen (argv[1]); | ||
37 | memcpy (p, argv[1], x); /* first arg plus another null */ | ||
38 | x++; | ||
39 | p += x; | ||
40 | y += x; | ||
41 | |||
42 | if (! argv[2]) | ||
43 | goto wrong; | ||
44 | x = strlen (argv[2]); | ||
45 | memcpy (p, argv[2], x); /* second arg plus null */ | ||
46 | x++; | ||
47 | p += x; | ||
48 | y += x; | ||
49 | |||
50 | q = cmd; | ||
51 | if (argv[3]) | ||
52 | q = argv[3]; | ||
53 | x = strlen (q); /* not checked -- bfd */ | ||
54 | memcpy (p, q, x); /* the command, plus final null */ | ||
55 | x++; | ||
56 | p += x; | ||
57 | y += x; | ||
58 | |||
59 | memcpy (p, "\n", 1); /* and a newline, so it goes */ | ||
60 | y++; | ||
61 | |||
62 | write (1, buf, y); /* zot! */ | ||
63 | exit (0); | ||
64 | |||
65 | wrong: | ||
66 | fprintf (stderr, "wrong! needs 2 or more args.\n"); | ||
67 | exit (1); | ||
68 | } | ||
diff --git a/src/usr.bin/nc/data/showmount.d b/src/usr.bin/nc/data/showmount.d new file mode 100644 index 0000000000..499794bc8a --- /dev/null +++ b/src/usr.bin/nc/data/showmount.d | |||
@@ -0,0 +1,63 @@ | |||
1 | # UDP mountd call. Use as input to find mount daemons and avoid portmap. | ||
2 | # Useful proc numbers are 2, 5, and 6. | ||
3 | # UDP-scan around between 600-800 to find most mount daemons. | ||
4 | # Using this with "2", plugged into "nc -u -v -w 2 victim X-Y" will | ||
5 | # directly scan *and* dump the current exports when mountd is hit. | ||
6 | # combine stdout *and* stderr thru "strings" or something to clean it up | ||
7 | |||
8 | 000 # XID: 4 trash bytes | ||
9 | 001 | ||
10 | 002 | ||
11 | 003 | ||
12 | |||
13 | 000 # CALL: 0 | ||
14 | 000 | ||
15 | 000 | ||
16 | 000 | ||
17 | |||
18 | 000 # RPC version: 2 | ||
19 | 000 | ||
20 | 000 | ||
21 | 002 | ||
22 | |||
23 | 000 # mount: 100005 | ||
24 | 001 | ||
25 | 0x86 | ||
26 | 0xa5 | ||
27 | |||
28 | 000 # mount version: 1 | ||
29 | 000 | ||
30 | 000 | ||
31 | 001 | ||
32 | |||
33 | 000 # procedure number -- put what you need here: | ||
34 | 000 # 2 = dump [showmount -e] | ||
35 | 000 # 5 = exportlist [showmount -a] | ||
36 | xxx # "sed s/xxx/$1/ | data -g | nc ..." or some such... | ||
37 | |||
38 | 000 # port: junk | ||
39 | 000 | ||
40 | 000 | ||
41 | 000 | ||
42 | |||
43 | 000 # auth trash | ||
44 | 000 | ||
45 | 000 | ||
46 | 000 | ||
47 | |||
48 | 000 # auth trash | ||
49 | 000 | ||
50 | 000 | ||
51 | 000 | ||
52 | |||
53 | 000 # auth trash | ||
54 | 000 | ||
55 | 000 | ||
56 | 000 | ||
57 | |||
58 | 000 # extra auth trash? probably not needed | ||
59 | 000 | ||
60 | 000 | ||
61 | 000 | ||
62 | |||
63 | # that's it! | ||
diff --git a/src/usr.bin/nc/data/xor.c b/src/usr.bin/nc/data/xor.c new file mode 100644 index 0000000000..9feead0cba --- /dev/null +++ b/src/usr.bin/nc/data/xor.c | |||
@@ -0,0 +1,92 @@ | |||
1 | /* Generic xor handler. | ||
2 | |||
3 | With no args, xors stdin against 0xFF to stdout. A single argument is a | ||
4 | file to read xor-bytes out of. Any zero in the xor-bytes array is treated | ||
5 | as the end; if you need to xor against a string that *includes* zeros, | ||
6 | you're on your own. | ||
7 | |||
8 | The indirect file can be generated easily with data.c. | ||
9 | |||
10 | Written because there are so many lame schemes for "masking" plaintext | ||
11 | passwords and the like floating around, and it's handy to just run an | ||
12 | obscure binary-format configuration file through this and look for strings. | ||
13 | |||
14 | *Hobbit*, 960208 */ | ||
15 | |||
16 | #include <stdio.h> | ||
17 | #include <fcntl.h> | ||
18 | |||
19 | char buf[8192]; | ||
20 | char bytes[256]; | ||
21 | char * py; | ||
22 | |||
23 | /* do the xor, in place. Uses global ptr "py" to maintain "bytes" state */ | ||
24 | xorb (buf, len) | ||
25 | char * buf; | ||
26 | int len; | ||
27 | { | ||
28 | register int x; | ||
29 | register char * pb; | ||
30 | |||
31 | pb = buf; | ||
32 | x = len; | ||
33 | while (x > 0) { | ||
34 | *pb = (*pb ^ *py); | ||
35 | pb++; | ||
36 | py++; | ||
37 | if (! *py) | ||
38 | py = bytes; | ||
39 | x--; | ||
40 | } | ||
41 | } /* xorb */ | ||
42 | |||
43 | /* blah */ | ||
44 | main (argc, argv) | ||
45 | int argc; | ||
46 | char ** argv; | ||
47 | { | ||
48 | register int x = 0; | ||
49 | register int y; | ||
50 | |||
51 | /* manually preload; xor-with-0xFF is all too common */ | ||
52 | memset (bytes, 0, sizeof (bytes)); | ||
53 | bytes[0] = 0xff; | ||
54 | |||
55 | /* if file named in any arg, reload from that */ | ||
56 | #ifdef O_BINARY /* DOS shit... */ | ||
57 | x = setmode (0, O_BINARY); /* make stdin raw */ | ||
58 | if (x < 0) { | ||
59 | fprintf (stderr, "stdin binary setmode oops: %d\n", x); | ||
60 | exit (1); | ||
61 | } | ||
62 | x = setmode (1, O_BINARY); /* make stdout raw */ | ||
63 | if (x < 0) { | ||
64 | fprintf (stderr, "stdout binary setmode oops: %d\n", x); | ||
65 | exit (1); | ||
66 | } | ||
67 | #endif /* O_BINARY */ | ||
68 | |||
69 | if (argv[1]) | ||
70 | #ifdef O_BINARY | ||
71 | x = open (argv[1], O_RDONLY | O_BINARY); | ||
72 | #else | ||
73 | x = open (argv[1], O_RDONLY); | ||
74 | #endif | ||
75 | if (x > 0) { | ||
76 | read (x, bytes, 250); /* nothin' fancy here */ | ||
77 | close (x); | ||
78 | } | ||
79 | py = bytes; | ||
80 | x = 1; | ||
81 | while (x > 0) { | ||
82 | x = read (0, buf, sizeof (buf)); | ||
83 | if (x <= 0) | ||
84 | break; | ||
85 | xorb (buf, x); | ||
86 | y = write (1, buf, x); | ||
87 | if (y <= 0) | ||
88 | exit (1); | ||
89 | } | ||
90 | exit (0); | ||
91 | } | ||
92 | |||
diff --git a/src/usr.bin/nc/generic.h b/src/usr.bin/nc/generic.h new file mode 100644 index 0000000000..b3dd5f5dc6 --- /dev/null +++ b/src/usr.bin/nc/generic.h | |||
@@ -0,0 +1,377 @@ | |||
1 | /* generic.h -- anything you don't #undef at the end remains in effect. | ||
2 | The ONLY things that go in here are generic indicator flags; it's up | ||
3 | to your programs to declare and call things based on those flags. | ||
4 | |||
5 | You should only need to make changes via a minimal system-specific section | ||
6 | at the end of this file. To build a new section, rip through this and | ||
7 | check everything it mentions on your platform, and #undef that which needs | ||
8 | it. If you generate a system-specific section you didn't find in here, | ||
9 | please mail me a copy so I can update the "master". | ||
10 | |||
11 | I realize I'm probably inventing another pseudo-standard here, but | ||
12 | goddamnit, everybody ELSE has already, and I can't include all of their | ||
13 | hairball schemes too. HAVE_xx conforms to the gnu/autoconf usage and | ||
14 | seems to be the most common format. In fact, I dug a lot of these out | ||
15 | of autoconf and tried to common them all together using "stupidh" to | ||
16 | collect data from platforms. | ||
17 | |||
18 | In disgust... _H* 940910, 941115, 950511. Pseudo-version: 1.3 | ||
19 | |||
20 | Updated 951104 with many patches from netcat feedback, and properly | ||
21 | closed a lot of slop in open-ended comments: version 1.4 | ||
22 | 960217 + nextstep: version 1.5 | ||
23 | */ | ||
24 | |||
25 | #ifndef GENERIC_H /* only run through this once */ | ||
26 | #define GENERIC_H | ||
27 | |||
28 | /* =============================== */ | ||
29 | /* System calls, lib routines, etc */ | ||
30 | /* =============================== */ | ||
31 | |||
32 | /* How does your system declare malloc, void or char? Usually void, but go | ||
33 | ask the SunOS people why they had to be different... */ | ||
34 | #define VOID_MALLOC | ||
35 | |||
36 | /* notably from fwtk/firewall.h: posix locking? */ | ||
37 | #define HAVE_FLOCK /* otherwise it's lockf() */ | ||
38 | |||
39 | /* if you don't have setsid(), you might have setpgrp(). */ | ||
40 | #define HAVE_SETSID | ||
41 | |||
42 | /* random() is generally considered better than rand() */ | ||
43 | #define HAVE_RANDOM | ||
44 | |||
45 | /* the srand48/lrand48/etc family is s'posedly even better */ | ||
46 | #define HAVE_RAND48 | ||
47 | /* bmc@telebase and others have suggested these macros if a box *does* have | ||
48 | rand48. Will consider for later if we're doing something that really | ||
49 | requires stronger random numbers, but netcat and such certainly doesn't. | ||
50 | #define srandom(seed) srand48((long) seed) | ||
51 | #define random() lrand48() */ | ||
52 | |||
53 | /* if your machine doesn't have lstat(), it should have stat() [dos...] */ | ||
54 | #define HAVE_LSTAT | ||
55 | |||
56 | /* different kinds of term ioctls. How to recognize them, very roughly: | ||
57 | sysv/POSIX_ME_HARDER: termio[s].h, struct termio[s], tty.c_*[] | ||
58 | bsd/old stuff: sgtty.h, ioctl(TIOCSETP), sgttyb.sg_*, tchars.t_* */ | ||
59 | #define HAVE_TERMIOS | ||
60 | |||
61 | /* dbm vs ndbm */ | ||
62 | #define HAVE_NDBM | ||
63 | |||
64 | /* extended utmp/wtmp stuff. MOST machines still do NOT have this SV-ism */ | ||
65 | #define UTMPX | ||
66 | |||
67 | /* some systems have nice() which takes *relative* values... [resource.h] */ | ||
68 | #define HAVE_SETPRIORITY | ||
69 | |||
70 | /* a sysvism, I think, but ... */ | ||
71 | #define HAVE_SYSINFO | ||
72 | |||
73 | /* ============= */ | ||
74 | /* Include files */ | ||
75 | /* ============= */ | ||
76 | |||
77 | /* Presence of these can be determined via a script that sniffs them | ||
78 | out if you aren't sure. See "stupidh"... */ | ||
79 | |||
80 | /* stdlib comes with most modern compilers, but ya never know */ | ||
81 | #define HAVE_STDLIB_H | ||
82 | |||
83 | /* not on a DOS box! */ | ||
84 | #define HAVE_UNISTD_H | ||
85 | |||
86 | /* stdarg is a weird one */ | ||
87 | #define HAVE_STDARG_H | ||
88 | |||
89 | /* dir.h or maybe ndir.h otherwise. */ | ||
90 | #define HAVE_DIRENT_H | ||
91 | |||
92 | /* string or strings */ | ||
93 | #define HAVE_STRINGS_H | ||
94 | |||
95 | /* if you don't have lastlog.h, what you want might be in login.h */ | ||
96 | #define HAVE_LASTLOG_H | ||
97 | |||
98 | /* predefines for _PATH_various */ | ||
99 | #define HAVE_PATHS_H | ||
100 | |||
101 | /* some SV-flavors break select stuff out separately */ | ||
102 | #define HAVE_SELECT_H | ||
103 | |||
104 | /* assorted others */ | ||
105 | #define HAVE_PARAM_H /* in sys/ */ | ||
106 | #define HAVE_SYSMACROS_H /* in sys/ */ | ||
107 | #define HAVE_TTYENT_H /* securetty et al */ | ||
108 | |||
109 | /* ==================== */ | ||
110 | |||
111 | /* Still maybe have to do something about the following, if it's even | ||
112 | worth it. I just grepped a lot of these out of various code, without | ||
113 | looking them up yet: | ||
114 | |||
115 | #define HAVE_EINPROGRESS | ||
116 | #define HAVE_F_SETOWN | ||
117 | HAVE_FILIO_H ... fionbio, fiosetown, etc... will need for hairier | ||
118 | select loops. | ||
119 | #define HAVE_SETENV ... now *there's* a hairy one; **environ is portable | ||
120 | #define BIG_ENDIAN/little_endian ... *please* try to avoid this stupidity | ||
121 | and LSBFIRST/MSBFIRST | ||
122 | #define HAVE_GETUSERSHELL ... you could always pull it out of getpwent() | ||
123 | #define HAVE_SETE[UG]ID ... lib or syscall, it varies on diff platforms | ||
124 | #define HAVE_STRCHR ... should actually be handled by string/strings | ||
125 | #define HAVE_PSTAT | ||
126 | #define HAVE_ST_BLKSIZE ... a stat() thing? | ||
127 | #define HAVE_IP_TOS | ||
128 | #define HAVE_STRFTIME ... screw this, we'll just INCLUDE one for lame | ||
129 | old boxes that don't have it [sunos 3.x, early 4.x?] | ||
130 | #define HAVE_VFPRINTF | ||
131 | #define HAVE_SHADOW_PASSWD ... in its multitudinous schemes?? ... how | ||
132 | about sumpin' like #define SHADOW_PASSWD_TYPE ... could get grody. | ||
133 | ... looks like sysv /etc/shadow, getspent() family is common. | ||
134 | #define SIG* ... what a swamp, punt for now; should all be in signal.h | ||
135 | #define HAVE_STRCSPN ... see larry wall's comment in the fwtk regex code | ||
136 | #define ULTRIX_AUTH ... bwahaha. | ||
137 | #define HAVE_YP or NIS or whatever you wanna call it this week | ||
138 | randomness about VARARGS?? | ||
139 | --- later stuff to be considered --- | ||
140 | #define UINT4 ... u-int on alpha/osf, i.e. __alpha/__osf__, ulong elsewhere? | ||
141 | dont name it that, though, it'll conflict with extant .h files like md5 | ||
142 | randomness about machine/endian.h, machine/inline.h -- bsdi, net/2 | ||
143 | randomness about _PATH_WTMP vs WTMP_FILE and where they even live!! | ||
144 | #define HAVE_SYS_ERRLIST ... whether it's in stdio.h or not [bsd 4.4] | ||
145 | --- still more stuff | ||
146 | #define HAVE_SETENV | ||
147 | #define _PATH_UTMP vs UTMP_FILE, a la deslogind?! | ||
148 | #define HAVE_DAEMON | ||
149 | #define HAVE_INETADDR [vixie bind?] | ||
150 | lseek: SEEK_SET vs L_SET and associated lossage [epi-notes, old 386Mach] | ||
151 | bsdi: ioctl_compat.h ? | ||
152 | --- takin' some ifdefs from CNS krb: | ||
153 | F_GETOWN/F_SETOWN | ||
154 | CRAY: long = 8 bytes, etc [class with alpha?] | ||
155 | CGETENT | ||
156 | SIGINFO | ||
157 | SIGTSTP SIGTTOU SIGWINCH | ||
158 | SPX? | ||
159 | SYSV_TERMIO -- covered elsewhere, I hope | ||
160 | TIOCEXT TIOCFLUSH TIOC[GS]WINSIZ | ||
161 | NEWINIT: something about init cleaning up dead login processes [telnet?] | ||
162 | PARENT_DOES_UTMP, too [telnet] | ||
163 | VDISCARD | ||
164 | VEOL/VEOL2/VLNEXT VREPRINT -- termios stuff?, and related... | ||
165 | STREAMSPTY/STREAMSPTYEM | ||
166 | AF_INET/AF_UNSPEC, PF_* | ||
167 | ECHOCTL/ECHOKE | ||
168 | F_ULOCK [?!] | ||
169 | setpgrp/getpgrp() ONEARG business.. | ||
170 | HAVE_ALLOCA | ||
171 | HAVE_GETUTENT | ||
172 | HAVE_SYS_SELECT_H [irix!] | ||
173 | HAVE_DIRENT [old 386mach has *direct.h*!] | ||
174 | HAVE_SIGSET | ||
175 | HAVE_VFORK_H and HAVE_VFORK | ||
176 | HAVE_VHANGUP | ||
177 | HAVE_VSPRINTF | ||
178 | HAVE_IPTOS_* | ||
179 | HAVE_STRCASECMP, STRNCASECMP | ||
180 | HAVE_SYS_FCNTL_H | ||
181 | HAVE_SYS_TIME_H | ||
182 | HAVE_UTIMES | ||
183 | NOTTYENT [?] | ||
184 | HAVE_FCHMOD | ||
185 | HAVE_GETUSERSHELL | ||
186 | HAVE_SIGCONTEXT [stack hair, very machine-specific] | ||
187 | YYLINENO? | ||
188 | POSIX_SIGNALS | ||
189 | POSIX_TERMIOS | ||
190 | SETPROCTITLE -- breaks some places, like fbsd sendmail | ||
191 | SIG* -- actual signal names? some are missing | ||
192 | SIOCGIFCONF | ||
193 | SO_BROADCAST | ||
194 | SHMEM [krb tickets] | ||
195 | VARARGS, or HAVE_VARARGS | ||
196 | CBAUD | ||
197 | ... and B300, B9600, etc etc | ||
198 | HAVE_BZERO vs memset/memcpy | ||
199 | HAVE_SETVBUF | ||
200 | HAVE_STRDUP | ||
201 | HAVE_GETENV | ||
202 | HAVE_STRSAVE | ||
203 | HAVE_STBLKSIZE [stat?] | ||
204 | HAVE_STREAM_H -- in sys/, ref sendmail 8.7 for IP_SRCROUTE | ||
205 | FCHMOD | ||
206 | INITGROUPS -- most machines seem to *have* | ||
207 | SETREUID | ||
208 | SNPRINTF | ||
209 | SETPGRP semantics bsd vs. sys5 style | ||
210 | |||
211 | There's also the issue about WHERE various .h files live, sys/ or otherwise. | ||
212 | There's a BIG swamp lurking where network code of any sort lives. | ||
213 | */ | ||
214 | |||
215 | /* ======================== */ | ||
216 | /* System-specific sections */ | ||
217 | /* ======================== */ | ||
218 | |||
219 | /* By turning OFF various bits of the above, you can customize for | ||
220 | a given platform. Yes, we're ignoring the stock compiler predefines | ||
221 | and using our own plugged in via the Makefile. */ | ||
222 | |||
223 | /* DOS boxes, with MSC; you may need to adapt to a different compiler. */ | ||
224 | /* looks like later ones *do* have dirent.h, for example */ | ||
225 | #ifdef MSDOS | ||
226 | #undef HAVE_FLOCK | ||
227 | #undef HAVE_RANDOM | ||
228 | #undef HAVE_LSTAT | ||
229 | #undef HAVE_TERMIOS | ||
230 | #undef UTMPX | ||
231 | #undef HAVE_SYSINFO | ||
232 | #undef HAVE_UNISTD_H | ||
233 | #undef HAVE_DIRENT_H /* unless you have the k00l little wrapper from L5!! */ | ||
234 | #undef HAVE_STRINGS_H | ||
235 | #undef HAVE_LASTLOG_H | ||
236 | #undef HAVE_PATHS_H | ||
237 | #undef HAVE_PARAM_H | ||
238 | #undef HAVE_SYSMACROS_H | ||
239 | #undef HAVE_SELECT_H | ||
240 | #undef HAVE_TTYENT_H | ||
241 | #endif /* MSDOS */ | ||
242 | |||
243 | /* buglix 4.x; dunno about 3.x on down. should be bsd4.2 */ | ||
244 | #ifdef ULTRIX | ||
245 | #undef UTMPX | ||
246 | #undef HAVE_PATHS_H | ||
247 | #undef HAVE_SYSMACROS_H | ||
248 | #undef HAVE_SELECT_H | ||
249 | #endif /* buglix */ | ||
250 | |||
251 | /* some of this might still be broken on older sunoses */ | ||
252 | #ifdef SUNOS | ||
253 | #undef VOID_MALLOC | ||
254 | #undef UTMPX | ||
255 | #undef HAVE_PATHS_H | ||
256 | #undef HAVE_SELECT_H | ||
257 | #endif /* sunos */ | ||
258 | |||
259 | /* "contact your vendor for a fix" */ | ||
260 | #ifdef SOLARIS | ||
261 | /* has UTMPX */ | ||
262 | #undef HAVE_RANDOM | ||
263 | #undef HAVE_SETPRIORITY | ||
264 | #undef HAVE_STRINGS_H /* this is genuinely the case, go figure */ | ||
265 | #undef HAVE_PATHS_H | ||
266 | #undef HAVE_SELECT_H | ||
267 | #undef HAVE_TTYENT_H | ||
268 | #endif /* SOLARIS */ | ||
269 | |||
270 | /* whatever aix variant MIT had at the time; 3.2.x?? */ | ||
271 | #ifdef AIX | ||
272 | #undef UTMPX | ||
273 | #undef HAVE_LASTLOG_H | ||
274 | #define HAVE_LOGIN_H /* "special", in the educational sense */ | ||
275 | #endif /* aix */ | ||
276 | |||
277 | /* linux, which is trying as desperately as the gnu folks can to be | ||
278 | POSIXLY_CORRECT. I think I'm gonna hurl... */ | ||
279 | #ifdef LINUX | ||
280 | #undef UTMPX | ||
281 | #undef HAVE_SYSINFO | ||
282 | #undef HAVE_SELECT_H | ||
283 | #undef HAVE_TTYENT_H | ||
284 | #endif /* linux */ | ||
285 | |||
286 | /* irix 5.x; may not be correct for earlier ones */ | ||
287 | #ifdef IRIX | ||
288 | /* wow, does irix really have everything?! */ | ||
289 | #endif /* irix */ | ||
290 | |||
291 | /* osf on alphas */ | ||
292 | #ifdef OSF | ||
293 | #undef UTMPX | ||
294 | #undef HAVE_SELECT_H | ||
295 | #endif /* osf */ | ||
296 | |||
297 | /* they's some FUCKED UP paths in this one! */ | ||
298 | #ifdef FREEBSD | ||
299 | #undef UTMPX | ||
300 | #undef HAVE_SYSINFO | ||
301 | #undef HAVE_LASTLOG_H | ||
302 | #undef HAVE_SYSMACROS_H | ||
303 | #undef HAVE_SELECT_H /* actually a lie, but only for kernel */ | ||
304 | #endif /* freebsd */ | ||
305 | |||
306 | /* Originally from the sidewinder site, of all places, but subsequently | ||
307 | checked further under a more normal bsdi 2.0 */ | ||
308 | #ifdef BSDI | ||
309 | #undef UTMPX | ||
310 | #undef HAVE_LASTLOG_H | ||
311 | #undef HAVE_SYSMACROS_H | ||
312 | /* and their malloc.h was in sys/ ?! */ | ||
313 | #undef HAVE_SELECT_H | ||
314 | #endif /* bsdi */ | ||
315 | |||
316 | /* netbsd/44lite, jives with amiga-netbsd from cactus */ | ||
317 | #ifdef NETBSD | ||
318 | #undef UTMPX | ||
319 | #undef HAVE_SYSINFO | ||
320 | #undef HAVE_LASTLOG_H | ||
321 | #undef HAVE_SELECT_H | ||
322 | #endif /* netbsd */ | ||
323 | |||
324 | /* Hpux 9.0x, from BBN and various patches sent in */ | ||
325 | #ifdef HPUX | ||
326 | #undef HAVE_RANDOM /* but *does* have ?rand48 -- need to consider.. */ | ||
327 | #undef HAVE_UTMPX | ||
328 | #undef HAVE_LASTLOG_H /* has utmp/wtmp/btmp nonsense, and pututline() */ | ||
329 | #undef HAVE_PATHS_H | ||
330 | #undef HAVE_SELECT_H | ||
331 | #undef HAVE_TTYENT_H | ||
332 | #endif /* hockeypux */ | ||
333 | |||
334 | /* Unixware [a loose definition of "unix", to be sure], 1.1.2 [at least] | ||
335 | from Brian Clapper. He wasn't sure about 2.0... */ | ||
336 | #ifdef UNIXWARE | ||
337 | /* has UTMPX */ | ||
338 | #undef HAVE_SETPRIORITY | ||
339 | /* NOTE: UnixWare does provide the BSD stuff, in "/usr/ucbinclude" (headers) | ||
340 | and "/usr/ucblib" (libraries). However, I've run into problems linking | ||
341 | stuff out of that version of the C library, when objects are also coming | ||
342 | out of the "regular" C library. My advice: Avoid the BSD compatibility | ||
343 | stuff wherever possible. Brian Clapper <bmc@telebase.com> */ | ||
344 | #undef HAVE_STRINGS_H | ||
345 | #undef HAVE_PATHS_H | ||
346 | #undef HAVE_TTYENT_H | ||
347 | #endif /* UNIXWARE */ | ||
348 | |||
349 | /* A/UX 3.1.x from darieb@sandia.gov */ | ||
350 | #ifdef AUX | ||
351 | #undef HAVE_RANDOM | ||
352 | #undef HAVE_SELECT_H /* xxx: untested */ | ||
353 | #endif /* a/ux */ | ||
354 | |||
355 | /* NeXTSTEP 3.2 motorola mudge@l0pht.com xxx should also work with | ||
356 | white hardware and Sparc/HPPA. Should work with 3.3 too as it's | ||
357 | 4.3 / 4.4 bsd wrapped around mach */ | ||
358 | #ifdef NEXT | ||
359 | #undef UTMPX | ||
360 | #undef HAVE_SELECT_X | ||
361 | #endif /* NeXTSTEP 3.2 motorola */ | ||
362 | |||
363 | /* Make some "generic" assumptions if all else fails */ | ||
364 | #ifdef GENERIC | ||
365 | #undef HAVE_FLOCK | ||
366 | #if defined(SYSV) && (SYSV < 4) /* TW leftover: old SV doesnt have symlinks */ | ||
367 | #undef HAVE_LSTAT | ||
368 | #endif /* old SYSV */ | ||
369 | #undef HAVE_TERMIOS | ||
370 | #undef UTMPX | ||
371 | #undef HAVE_PATHS_H | ||
372 | #undef HAVE_SELECT_H | ||
373 | #endif /* generic */ | ||
374 | |||
375 | /* ================ */ | ||
376 | #endif /* GENERIC_H */ | ||
377 | |||
diff --git a/src/usr.bin/nc/nc.1 b/src/usr.bin/nc/nc.1 new file mode 100644 index 0000000000..8d87051c73 --- /dev/null +++ b/src/usr.bin/nc/nc.1 | |||
@@ -0,0 +1,215 @@ | |||
1 | .\" $OpenBSD: nc.1,v 1.5 1998/09/28 06:57:35 millert Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1996 David Sacerdote | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | ||
7 | .\" modification, are permitted provided that the following conditions | ||
8 | .\" are met: | ||
9 | .\" 1. Redistributions of source code must retain the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer. | ||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer in the | ||
13 | .\" documentation and/or other materials provided with the distribution. | ||
14 | .\" 3. The name of the author may not be used to endorse or promote products | ||
15 | .\" derived from this software without specific prior written permission | ||
16 | .\" | ||
17 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
18 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
19 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
20 | .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
21 | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
22 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
23 | .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
24 | .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
26 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
27 | .\" | ||
28 | .Dd August 1, 1996 | ||
29 | .Dt NC 1 | ||
30 | .Os | ||
31 | .Sh NAME | ||
32 | .Nm nc | ||
33 | .Nd "arbitrary TCP and UDP connections and listens" | ||
34 | .Sh SYNOPSIS | ||
35 | .Nm nc | ||
36 | .Op Fl e Ar command | ||
37 | .Op Fl g Ar intermediates | ||
38 | .Op Fl G Ar hopcount | ||
39 | .Op Fl i Ar interval | ||
40 | .Op Fl lnrtuvz | ||
41 | .Op Fl o Ar filename | ||
42 | .Op Fl p Ar source port | ||
43 | .Op Fl s Ar ip address | ||
44 | .Op Fl w Ar timeout | ||
45 | .Op Ar hostname | ||
46 | .Op Ar port[s...] | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Nm nc | ||
50 | (or | ||
51 | .Nm netcat ) | ||
52 | utility is used for just about anything under the sun | ||
53 | involving TCP or UDP. It can open TCP connections, send UDP packets, | ||
54 | listen on arbitrary TCP and UDP ports, do port scanning, and source | ||
55 | routing. Unlike | ||
56 | .Xr telnet 1 , | ||
57 | .Nm nc | ||
58 | scripts nicely, and separates error messages onto standard error instead | ||
59 | of sending them to standard output, as | ||
60 | .Xr telnet 1 | ||
61 | does with some. | ||
62 | .Pp | ||
63 | Destination ports can be single integers, names as listed in | ||
64 | .Xr services 5 , | ||
65 | or ranges. Ranges are in the form nn-mm, and several separate ports and/or | ||
66 | ranges may be specified on the command line. | ||
67 | .Pp | ||
68 | Common uses include: | ||
69 | .Bl -bullet | ||
70 | .It | ||
71 | simple TCP proxies | ||
72 | .It | ||
73 | shell\-script based HTTP clients and servers | ||
74 | .It | ||
75 | network daemon testing | ||
76 | .It | ||
77 | source routing based connectivity testing | ||
78 | .It | ||
79 | and much, much more | ||
80 | .El | ||
81 | .Pp | ||
82 | The options are as follows: | ||
83 | .Bl -tag -width Ds | ||
84 | .It Fl e Ar command | ||
85 | Execute the specified command, using data from the network for stdin, | ||
86 | and sending stdout and stderr to the network. This option is only present if | ||
87 | .Nm nc | ||
88 | was compiled with the GAPING_SECURITY_HOLE compile time option, since it | ||
89 | allows users to make arbitrary programs available to anyone on the network. | ||
90 | .It Fl g Ar intermediate-host | ||
91 | Specifies a hop along a loose source routed path. Can be used more than | ||
92 | once to build a chain of hop points. | ||
93 | .It Fl G Ar pointer | ||
94 | Positions the "hop counter" within the list of machines in the path of | ||
95 | a source routed packet. Must be a multiple of 4. | ||
96 | .It Fl i Ar seconds | ||
97 | Specifies a delay time interval between lines of text sent and received. | ||
98 | Also causes a delay time between connections to multiple ports. | ||
99 | .It Fl l | ||
100 | Is used to specify that | ||
101 | .Nm nc | ||
102 | should listen for an incoming connection, rather than initiate a | ||
103 | connection to a remote host. Any hostname/IP address and port arguments | ||
104 | restrict the source of inbound connections to only that address and | ||
105 | source port. | ||
106 | .It Fl n | ||
107 | Do not do DNS lookups on any of the specified addresses or hostnames, or | ||
108 | names of port numbers from /etc/services. | ||
109 | .It Fl o Ar filename | ||
110 | Create a hexadecimal log of data transferred in the specified file. | ||
111 | Each line begins with ``<'' or ``>''. ``<'' means "from the net" and ``>'' | ||
112 | means "to the net". | ||
113 | .It Fl p Ar port | ||
114 | Specifies the source port | ||
115 | .Nm nc | ||
116 | should use, subject to privilege restrictions and availability. | ||
117 | .It Fl r | ||
118 | Specifies that source and/or destination ports should be chosen semi-randomly | ||
119 | instead of sequentially within a range or in the order that the | ||
120 | system assigns. | ||
121 | .It Fl s Ar hostname/ip-address | ||
122 | Specifies the IP of the interface which is used to send the packets. | ||
123 | On some platforms, this can be used for UDP spoofing by using | ||
124 | .Xr ifconfig 8 | ||
125 | to bring up a dummy interface with the desired source IP address. | ||
126 | .It Fl t | ||
127 | Causes | ||
128 | .Nm nc | ||
129 | to send RFC854 DON'T and WON'T responses to RFC854 DO | ||
130 | and WILL requests. This makes it possible to use | ||
131 | .Nm nc | ||
132 | to script telnet sessions. The presence of this option can be | ||
133 | enabled or disabled as a compile-time option. | ||
134 | .It Fl u | ||
135 | Use UDP instead of TCP. | ||
136 | On most platforms, | ||
137 | .Nm nc | ||
138 | will behave as if a connection is established until it receives an | ||
139 | ICMP packet indicating that there is no program listening to what it | ||
140 | sends. | ||
141 | .It Fl v | ||
142 | Verbose. Cause | ||
143 | .Nm nc | ||
144 | to display connection information. Using | ||
145 | .Fl v | ||
146 | more than once will cause | ||
147 | .Nm nc | ||
148 | to become even more verbose. | ||
149 | .It Fl w Ar timeout | ||
150 | Specifies the number of seconds | ||
151 | .Nm nc | ||
152 | should wait before deciding that | ||
153 | an attempt to establish a connection is hopeless. | ||
154 | Also used to specify how long to wait for more network data after standard | ||
155 | input closes. | ||
156 | .It Fl z | ||
157 | Specifies that | ||
158 | .Nm nc | ||
159 | should just scan for listening | ||
160 | daemons, without sending any data to them. Diagnostic messages about refused | ||
161 | connections will not be | ||
162 | displayed unless | ||
163 | .Fl v | ||
164 | is specified twice. | ||
165 | .Sh EXAMPLES | ||
166 | .Bl -tag -width x | ||
167 | .It Li "nc" | ||
168 | Wait for the user to type what would normally be command-line | ||
169 | arguments in at stdin. | ||
170 | .It Li "nc example.host 42" | ||
171 | Open a TCP connection to port 42 of example.host. If the connection | ||
172 | fails, do not display any error messages, but simply exit. | ||
173 | .It Li "nc -p 31337 example.host 42" | ||
174 | Open a TCP connection to port 42 of example.host, and use port 31337 | ||
175 | as the source port. | ||
176 | .It Li "nc -w 5 example.host 42" | ||
177 | Open a TCP connection to port 42 of example.host, and time out after | ||
178 | five seconds while attempting to connect. | ||
179 | .It Li "nc -u example.host 53" | ||
180 | Send any data from stdin | ||
181 | to UDP port 53 of example.host, and display any data returned. | ||
182 | .It Li "nc -s 10.1.2.3 example.host 42" | ||
183 | Open a TCP connection to port 42 of example.host using 10.1.2.3 as the | ||
184 | IP for the local end of the connection. | ||
185 | .It Li "nc -v example.host 42" | ||
186 | Open a TCP connection to port 42 of example.host, displaying some | ||
187 | diagnostic messages on stderr. | ||
188 | .It Li "nc -v -v example.host 42" | ||
189 | Open a TCP connection to port 42 of example.host, displaying all | ||
190 | diagnostic messages on stderr. | ||
191 | .It Li "nc -v -z example.host 20-30" | ||
192 | Attempt to open TCP connections to ports 20 through 30 of | ||
193 | example.host, and report which ones | ||
194 | .Nm nc | ||
195 | was able to connect to. | ||
196 | .It Li "nc -v -u -z -w 3 example.host 20-30" | ||
197 | Send UDP packets to ports 20-30 of example.host, and report which ones | ||
198 | did not respond with an ICMP packet after three seconds. | ||
199 | .It Li "nc -l -p 3000" | ||
200 | Listen on TCP port 3000, and once there is a connection, send stdin to | ||
201 | the remote host, and send data from the remote host to stdout. | ||
202 | .It Li "echo foobar | nc example.host 1000" | ||
203 | Connect to port 1000 of example.host, send the string "foobar" | ||
204 | followed by a newline, and move data from port 1000 of example.host to | ||
205 | stdout until example.host closes the connection. | ||
206 | .El | ||
207 | .Sh SEE ALSO | ||
208 | .Xr cat 1 , | ||
209 | .Xr telnet 1 | ||
210 | .Pp | ||
211 | The | ||
212 | .Nm netcat | ||
213 | .Pa README . | ||
214 | .Sh AUTHOR | ||
215 | *Hobbit* [hobbit@avian.org] | ||
diff --git a/src/usr.bin/nc/netcat.blurb b/src/usr.bin/nc/netcat.blurb new file mode 100644 index 0000000000..2c540ad9dc --- /dev/null +++ b/src/usr.bin/nc/netcat.blurb | |||
@@ -0,0 +1,61 @@ | |||
1 | Netcat 1.10 is an updated release of Netcat, a simple Unix utility which reads | ||
2 | and writes data across network connections using TCP or UDP protocol. It is | ||
3 | designed to be a reliable "back-end" tool that can be used directly or easily | ||
4 | driven by other programs and scripts. At the same time it is a feature-rich | ||
5 | network debugging and exploration tool, since it can create almost any kind of | ||
6 | connection you would need and has several interesting built-in capabilities. | ||
7 | |||
8 | Some of netcat's major features are: | ||
9 | |||
10 | Outbound or inbound connections, TCP or UDP, to or from any ports | ||
11 | Full DNS forward/reverse checking, with appropriate warnings | ||
12 | Ability to use any local source port | ||
13 | Ability to use any locally-configured network source address | ||
14 | Built-in port-scanning capabilities, with randomizer | ||
15 | Built-in loose source-routing capability | ||
16 | Can read command line arguments from standard input | ||
17 | Slow-send mode, one line every N seconds | ||
18 | Hex dump of transmitted and received data | ||
19 | Optional ability to let another program service established connections | ||
20 | Optional telnet-options responder | ||
21 | |||
22 | A very short list of potential uses: | ||
23 | |||
24 | Script backends | ||
25 | Scanning ports and inventorying services, automated probes | ||
26 | Backup handlers | ||
27 | File transfers | ||
28 | Server testing, simulation, debugging, and hijacking | ||
29 | Firewall testing | ||
30 | Proxy gatewaying | ||
31 | Network performance testing | ||
32 | Address spoofing tests | ||
33 | Protecting X servers | ||
34 | 1001 other uses you'll likely come up with | ||
35 | |||
36 | Changes between the 1.00 release and this release: | ||
37 | |||
38 | Better portability -- updated generic.h and Makefile [thanx folks!] | ||
39 | Indication of local-end interface address on inbound connections | ||
40 | That's *Dave* Borman's telnet, not Paul Borman... | ||
41 | Better indication of DNS errors | ||
42 | Total byte counts printed if -v -v is used | ||
43 | A bunch of front-end driver companion programs and scripts | ||
44 | Better handling of stdin arguments-plus-data | ||
45 | Hex-dump feature | ||
46 | Telnet responder | ||
47 | Program exec works inbound or outbound now | ||
48 | |||
49 | Netcat and the associated package is a product of Avian Research, and is freely | ||
50 | available in full source form with no restrictions save an obligation to give | ||
51 | credit where due. Get it via anonymous FTP at avian.org:/src/hacks/nc110.tgz | ||
52 | which is a gzipped tar file and not to be confused with its version 1.00 | ||
53 | precursor, nc100.tgz. Other distribution formats can be accomodated upon | ||
54 | request. Netcat is also mirrored at the following [faster] sites: | ||
55 | |||
56 | zippy.telcom.arizona.edu:/pub/mirrors/avian.org/hacks/nc110.tgz | ||
57 | ftp.sterling.com:/mirrors/avian.org/src/hacks/nc110.tgz | ||
58 | coast.cs.purdue.edu:/pub/tools/unix/netcat/nc110.tgz | ||
59 | ftp.rge.com:/pub/security/coast/mirrors/avian.org/netcat/nc110.tgz | ||
60 | |||
61 | _H* 960320 | ||
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c new file mode 100644 index 0000000000..bb0b30749d --- /dev/null +++ b/src/usr.bin/nc/netcat.c | |||
@@ -0,0 +1,1670 @@ | |||
1 | /* Netcat 1.10 RELEASE 960320 | ||
2 | |||
3 | A damn useful little "backend" utility begun 950915 or thereabouts, | ||
4 | as *Hobbit*'s first real stab at some sockets programming. Something that | ||
5 | should have and indeed may have existed ten years ago, but never became a | ||
6 | standard Unix utility. IMHO, "nc" could take its place right next to cat, | ||
7 | cp, rm, mv, dd, ls, and all those other cryptic and Unix-like things. | ||
8 | |||
9 | Read the README for the whole story, doc, applications, etc. | ||
10 | |||
11 | Layout: | ||
12 | conditional includes: | ||
13 | includes: | ||
14 | handy defines: | ||
15 | globals: | ||
16 | malloced globals: | ||
17 | cmd-flag globals: | ||
18 | support routines: | ||
19 | readwrite select loop: | ||
20 | main: | ||
21 | |||
22 | bluesky: | ||
23 | parse ranges of IP address as well as ports, perhaps | ||
24 | RAW mode! | ||
25 | backend progs to grab a pty and look like a real telnetd?! | ||
26 | backend progs to do various encryption modes??!?! | ||
27 | */ | ||
28 | |||
29 | #include "generic.h" /* same as with L5, skey, etc */ | ||
30 | |||
31 | /* conditional includes -- a very messy section which you may have to dink | ||
32 | for your own architecture [and please send diffs...]: */ | ||
33 | /* #undef _POSIX_SOURCE /* might need this for something? */ | ||
34 | #define HAVE_BIND /* ASSUMPTION -- seems to work everywhere! */ | ||
35 | #define HAVE_HELP /* undefine if you dont want the help text */ | ||
36 | /* #define ANAL /* if you want case-sensitive DNS matching */ | ||
37 | |||
38 | #ifdef HAVE_STDLIB_H | ||
39 | #include <stdlib.h> | ||
40 | #else | ||
41 | #include <malloc.h> | ||
42 | #endif | ||
43 | #ifdef HAVE_SELECT_H /* random SV variants need this */ | ||
44 | #include <sys/select.h> | ||
45 | #endif | ||
46 | |||
47 | /* have to do this *before* including types.h. xxx: Linux still has it wrong */ | ||
48 | #ifdef FD_SETSIZE /* should be in types.h, butcha never know. */ | ||
49 | #undef FD_SETSIZE /* if we ever need more than 16 active */ | ||
50 | #endif /* fd's, something is horribly wrong! */ | ||
51 | #define FD_SETSIZE 16 /* <-- this'll give us a long anyways, wtf */ | ||
52 | #include <sys/types.h> /* *now* do it. Sigh, this is broken */ | ||
53 | |||
54 | #ifdef HAVE_RANDOM /* aficionados of ?rand48() should realize */ | ||
55 | #define SRAND srandom /* that this doesn't need *strong* random */ | ||
56 | #define RAND random /* numbers just to mix up port numbers!! */ | ||
57 | #else | ||
58 | #define SRAND srand | ||
59 | #define RAND rand | ||
60 | #endif /* HAVE_RANDOM */ | ||
61 | |||
62 | /* includes: */ | ||
63 | #include <sys/time.h> /* timeval, time_t */ | ||
64 | #include <setjmp.h> /* jmp_buf et al */ | ||
65 | #include <sys/socket.h> /* basics, SO_ and AF_ defs, sockaddr, ... */ | ||
66 | #include <netinet/in.h> /* sockaddr_in, htons, in_addr */ | ||
67 | #include <netinet/in_systm.h> /* misc crud that netinet/ip.h references */ | ||
68 | #include <netinet/ip.h> /* IPOPT_LSRR, header stuff */ | ||
69 | #include <netdb.h> /* hostent, gethostby*, getservby* */ | ||
70 | #include <arpa/inet.h> /* inet_ntoa */ | ||
71 | #include <stdio.h> | ||
72 | #include <string.h> /* strcpy, strchr, yadda yadda */ | ||
73 | #include <errno.h> | ||
74 | #include <signal.h> | ||
75 | #include <fcntl.h> /* O_WRONLY et al */ | ||
76 | |||
77 | /* handy stuff: */ | ||
78 | #define SA struct sockaddr /* socket overgeneralization braindeath */ | ||
79 | #define SAI struct sockaddr_in /* ... whoever came up with this model */ | ||
80 | #define IA struct in_addr /* ... should be taken out and shot, */ | ||
81 | /* ... not that TLI is any better. sigh.. */ | ||
82 | #define SLEAZE_PORT 31337 /* for UDP-scan RTT trick, change if ya want */ | ||
83 | #define USHORT unsigned short /* use these for options an' stuff */ | ||
84 | #define BIGSIZ 8192 /* big buffers */ | ||
85 | |||
86 | #ifndef INADDR_NONE | ||
87 | #define INADDR_NONE 0xffffffff | ||
88 | #endif | ||
89 | |||
90 | struct host_poop { | ||
91 | char name[MAXHOSTNAMELEN]; /* dns name */ | ||
92 | char addrs[8][24]; /* ascii-format IP addresses */ | ||
93 | struct in_addr iaddrs[8]; /* real addresses: in_addr.s_addr: ulong */ | ||
94 | }; | ||
95 | #define HINF struct host_poop | ||
96 | |||
97 | struct port_poop { | ||
98 | char name [64]; /* name in /etc/services */ | ||
99 | char anum [8]; /* ascii-format number */ | ||
100 | USHORT num; /* real host-order number */ | ||
101 | }; | ||
102 | #define PINF struct port_poop | ||
103 | |||
104 | /* globals: */ | ||
105 | jmp_buf jbuf; /* timer crud */ | ||
106 | int jval = 0; /* timer crud */ | ||
107 | int netfd = -1; | ||
108 | int ofd = 0; /* hexdump output fd */ | ||
109 | static char unknown[] = "(UNKNOWN)"; | ||
110 | static char p_tcp[] = "tcp"; /* for getservby* */ | ||
111 | static char p_udp[] = "udp"; | ||
112 | #ifdef HAVE_BIND | ||
113 | extern int h_errno; | ||
114 | /* stolen almost wholesale from bsd herror.c */ | ||
115 | static char * h_errs[] = { | ||
116 | "Error 0", /* but we *don't* use this */ | ||
117 | "Unknown host", /* 1 HOST_NOT_FOUND */ | ||
118 | "Host name lookup failure", /* 2 TRY_AGAIN */ | ||
119 | "Unknown server error", /* 3 NO_RECOVERY */ | ||
120 | "No address associated with name", /* 4 NO_ADDRESS */ | ||
121 | }; | ||
122 | #else | ||
123 | int h_errno; /* just so we *do* have it available */ | ||
124 | #endif /* HAVE_BIND */ | ||
125 | int gatesidx = 0; /* LSRR hop count */ | ||
126 | int gatesptr = 4; /* initial LSRR pointer, settable */ | ||
127 | USHORT Single = 1; /* zero if scanning */ | ||
128 | unsigned int insaved = 0; /* stdin-buffer size for multi-mode */ | ||
129 | unsigned int wrote_out = 0; /* total stdout bytes */ | ||
130 | unsigned int wrote_net = 0; /* total net bytes */ | ||
131 | static char wrote_txt[] = " sent %d, rcvd %d"; | ||
132 | static char hexnibs[20] = "0123456789abcdef "; | ||
133 | |||
134 | /* will malloc up the following globals: */ | ||
135 | struct timeval * timer1 = NULL; | ||
136 | struct timeval * timer2 = NULL; | ||
137 | SAI * lclend = NULL; /* sockaddr_in structs */ | ||
138 | SAI * remend = NULL; | ||
139 | HINF ** gates = NULL; /* LSRR hop hostpoop */ | ||
140 | char * optbuf = NULL; /* LSRR or sockopts */ | ||
141 | char * bigbuf_in; /* data buffers */ | ||
142 | char * bigbuf_net; | ||
143 | fd_set * ding1; /* for select loop */ | ||
144 | fd_set * ding2; | ||
145 | PINF * portpoop = NULL; /* for getportpoop / getservby* */ | ||
146 | unsigned char * stage = NULL; /* hexdump line buffer */ | ||
147 | |||
148 | /* global cmd flags: */ | ||
149 | USHORT o_alla = 0; | ||
150 | unsigned int o_interval = 0; | ||
151 | USHORT o_listen = 0; | ||
152 | USHORT o_nflag = 0; | ||
153 | USHORT o_wfile = 0; | ||
154 | USHORT o_random = 0; | ||
155 | USHORT o_udpmode = 0; | ||
156 | USHORT o_verbose = 0; | ||
157 | unsigned int o_wait = 0; | ||
158 | USHORT o_zero = 0; | ||
159 | /* o_tn in optional section */ | ||
160 | |||
161 | /* Debug macro: squirt whatever message and sleep a bit so we can see it go | ||
162 | by. need to call like Debug ((stuff)) [with no ; ] so macro args match! | ||
163 | Beware: writes to stdOUT... */ | ||
164 | #ifdef DEBUG | ||
165 | #define Debug(x) printf x; printf ("\n"); fflush (stdout); sleep (1); | ||
166 | #else | ||
167 | #define Debug(x) /* nil... */ | ||
168 | #endif | ||
169 | |||
170 | |||
171 | /* support routines -- the bulk of this thing. Placed in such an order that | ||
172 | we don't have to forward-declare anything: */ | ||
173 | |||
174 | /* holler : | ||
175 | fake varargs -- need to do this way because we wind up calling through | ||
176 | more levels of indirection than vanilla varargs can handle, and not all | ||
177 | machines have vfprintf/vsyslog/whatever! 6 params oughta be enough. */ | ||
178 | void holler (str, p1, p2, p3, p4, p5, p6) | ||
179 | char * str; | ||
180 | char * p1, * p2, * p3, * p4, * p5, * p6; | ||
181 | { | ||
182 | if (o_verbose) { | ||
183 | fprintf (stderr, str, p1, p2, p3, p4, p5, p6); | ||
184 | #ifdef HAVE_BIND | ||
185 | if (h_errno) { /* if host-lookup variety of error ... */ | ||
186 | if (h_errno > 4) /* oh no you don't, either */ | ||
187 | fprintf (stderr, "preposterous h_errno: %d", h_errno); | ||
188 | else | ||
189 | fprintf (stderr, h_errs[h_errno]); /* handle it here */ | ||
190 | h_errno = 0; /* and reset for next call */ | ||
191 | } | ||
192 | #endif | ||
193 | if (errno) { /* this gives funny-looking messages, but */ | ||
194 | perror (" "); /* it's more portable than sys_errlist[]... */ | ||
195 | } else /* xxx: do something better? */ | ||
196 | fprintf (stderr, "\n"); | ||
197 | fflush (stderr); | ||
198 | } | ||
199 | } /* holler */ | ||
200 | |||
201 | /* bail : | ||
202 | error-exit handler, callable from anywhere */ | ||
203 | void bail (str, p1, p2, p3, p4, p5, p6) | ||
204 | char * str; | ||
205 | char * p1, * p2, * p3, * p4, * p5, * p6; | ||
206 | { | ||
207 | o_verbose = 1; | ||
208 | holler (str, p1, p2, p3, p4, p5, p6); | ||
209 | close (netfd); | ||
210 | sleep (1); | ||
211 | exit (1); | ||
212 | } /* bail */ | ||
213 | |||
214 | /* catch : | ||
215 | no-brainer interrupt handler */ | ||
216 | void catch () | ||
217 | { | ||
218 | errno = 0; | ||
219 | if (o_verbose > 1) /* normally we don't care */ | ||
220 | bail (wrote_txt, wrote_net, wrote_out); | ||
221 | bail (" punt!"); | ||
222 | } | ||
223 | |||
224 | /* timeout and other signal handling cruft */ | ||
225 | void tmtravel () | ||
226 | { | ||
227 | signal (SIGALRM, SIG_IGN); | ||
228 | alarm (0); | ||
229 | if (jval == 0) | ||
230 | bail ("spurious timer interrupt!"); | ||
231 | longjmp (jbuf, jval); | ||
232 | } | ||
233 | |||
234 | /* arm : | ||
235 | set the timer. Zero secs arg means unarm */ | ||
236 | void arm (num, secs) | ||
237 | unsigned int num; | ||
238 | unsigned int secs; | ||
239 | { | ||
240 | if (secs == 0) { /* reset */ | ||
241 | signal (SIGALRM, SIG_IGN); | ||
242 | alarm (0); | ||
243 | jval = 0; | ||
244 | } else { /* set */ | ||
245 | signal (SIGALRM, tmtravel); | ||
246 | alarm (secs); | ||
247 | jval = num; | ||
248 | } /* if secs */ | ||
249 | } /* arm */ | ||
250 | |||
251 | /* Hmalloc : | ||
252 | malloc up what I want, rounded up to *4, and pre-zeroed. Either succeeds | ||
253 | or bails out on its own, so that callers don't have to worry about it. */ | ||
254 | char * Hmalloc (size) | ||
255 | unsigned int size; | ||
256 | { | ||
257 | unsigned int s = (size + 4) & 0xfffffffc; /* 4GB?! */ | ||
258 | char * p = malloc (s); | ||
259 | if (p != NULL) | ||
260 | memset (p, 0, s); | ||
261 | else | ||
262 | bail ("Hmalloc %d failed", s); | ||
263 | return (p); | ||
264 | } /* Hmalloc */ | ||
265 | |||
266 | /* findline : | ||
267 | find the next newline in a buffer; return inclusive size of that "line", | ||
268 | or the entire buffer size, so the caller knows how much to then write(). | ||
269 | Not distinguishing \n vs \r\n for the nonce; it just works as is... */ | ||
270 | unsigned int findline (buf, siz) | ||
271 | char * buf; | ||
272 | unsigned int siz; | ||
273 | { | ||
274 | register char * p; | ||
275 | register int x; | ||
276 | if (! buf) /* various sanity checks... */ | ||
277 | return (0); | ||
278 | if (siz > BIGSIZ) | ||
279 | return (0); | ||
280 | x = siz; | ||
281 | for (p = buf; x > 0; x--) { | ||
282 | if (*p == '\n') { | ||
283 | x = (int) (p - buf); | ||
284 | x++; /* 'sokay if it points just past the end! */ | ||
285 | Debug (("findline returning %d", x)) | ||
286 | return (x); | ||
287 | } | ||
288 | p++; | ||
289 | } /* for */ | ||
290 | Debug (("findline returning whole thing: %d", siz)) | ||
291 | return (siz); | ||
292 | } /* findline */ | ||
293 | |||
294 | /* comparehosts : | ||
295 | cross-check the host_poop we have so far against new gethostby*() info, | ||
296 | and holler about mismatches. Perhaps gratuitous, but it can't hurt to | ||
297 | point out when someone's DNS is fukt. Returns 1 if mismatch, in case | ||
298 | someone else wants to do something about it. */ | ||
299 | int comparehosts (poop, hp) | ||
300 | HINF * poop; | ||
301 | struct hostent * hp; | ||
302 | { | ||
303 | errno = 0; | ||
304 | h_errno = 0; | ||
305 | /* The DNS spec is officially case-insensitive, but for those times when you | ||
306 | *really* wanna see any and all discrepancies, by all means define this. */ | ||
307 | #ifdef ANAL | ||
308 | if (strcmp (poop->name, hp->h_name) != 0) { /* case-sensitive */ | ||
309 | #else | ||
310 | if (strcasecmp (poop->name, hp->h_name) != 0) { /* normal */ | ||
311 | #endif | ||
312 | holler ("DNS fwd/rev mismatch: %s != %s", poop->name, hp->h_name); | ||
313 | return (1); | ||
314 | } | ||
315 | return (0); | ||
316 | /* ... do we need to do anything over and above that?? */ | ||
317 | } /* comparehosts */ | ||
318 | |||
319 | /* gethostpoop : | ||
320 | resolve a host 8 ways from sunday; return a new host_poop struct with its | ||
321 | info. The argument can be a name or [ascii] IP address; it will try its | ||
322 | damndest to deal with it. "numeric" governs whether we do any DNS at all, | ||
323 | and we also check o_verbose for what's appropriate work to do. */ | ||
324 | HINF * gethostpoop (name, numeric) | ||
325 | char * name; | ||
326 | USHORT numeric; | ||
327 | { | ||
328 | struct hostent * hostent; | ||
329 | struct in_addr iaddr; | ||
330 | register HINF * poop = NULL; | ||
331 | register int x; | ||
332 | |||
333 | /* I really want to strangle the twit who dreamed up all these sockaddr and | ||
334 | hostent abstractions, and then forced them all to be incompatible with | ||
335 | each other so you *HAVE* to do all this ridiculous casting back and forth. | ||
336 | If that wasn't bad enough, all the doc insists on referring to local ports | ||
337 | and addresses as "names", which makes NO sense down at the bare metal. | ||
338 | |||
339 | What an absolutely horrid paradigm, and to think of all the people who | ||
340 | have been wasting significant amounts of time fighting with this stupid | ||
341 | deliberate obfuscation over the last 10 years... then again, I like | ||
342 | languages wherein a pointer is a pointer, what you put there is your own | ||
343 | business, the compiler stays out of your face, and sheep are nervous. | ||
344 | Maybe that's why my C code reads like assembler half the time... */ | ||
345 | |||
346 | /* If we want to see all the DNS stuff, do the following hair -- | ||
347 | if inet_addr, do reverse and forward with any warnings; otherwise try | ||
348 | to do forward and reverse with any warnings. In other words, as long | ||
349 | as we're here, do a complete DNS check on these clowns. Yes, it slows | ||
350 | things down a bit for a first run, but once it's cached, who cares? */ | ||
351 | |||
352 | errno = 0; | ||
353 | h_errno = 0; | ||
354 | if (name) | ||
355 | poop = (HINF *) Hmalloc (sizeof (HINF)); | ||
356 | if (! poop) | ||
357 | bail ("gethostpoop fuxored"); | ||
358 | strcpy (poop->name, unknown); /* preload it */ | ||
359 | /* see wzv:workarounds.c for dg/ux return-a-struct inet_addr lossage */ | ||
360 | iaddr.s_addr = inet_addr (name); | ||
361 | |||
362 | if (iaddr.s_addr == INADDR_NONE) { /* here's the great split: names... */ | ||
363 | if (numeric) | ||
364 | bail ("Can't parse %s as an IP address", name); | ||
365 | hostent = gethostbyname (name); | ||
366 | if (! hostent) | ||
367 | /* failure to look up a name is fatal, since we can't do anything with it */ | ||
368 | bail ("%s: forward host lookup failed: ", name); | ||
369 | strncpy (poop->name, hostent->h_name, MAXHOSTNAMELEN - 1); | ||
370 | poop->name[MAXHOSTNAMELEN - 1] = '\0'; | ||
371 | for (x = 0; hostent->h_addr_list[x] && (x < 8); x++) { | ||
372 | memcpy (&poop->iaddrs[x], hostent->h_addr_list[x], sizeof (IA)); | ||
373 | strncpy (poop->addrs[x], inet_ntoa (poop->iaddrs[x]), | ||
374 | sizeof (poop->addrs[0])-1); | ||
375 | poop->addrs[x][sizeof (poop->addrs[0]) - 1] = '\0'; | ||
376 | } /* for x -> addrs, part A */ | ||
377 | if (! o_verbose) /* if we didn't want to see the */ | ||
378 | return (poop); /* inverse stuff, we're done. */ | ||
379 | /* do inverse lookups in separate loop based on our collected forward addrs, | ||
380 | since gethostby* tends to crap into the same buffer over and over */ | ||
381 | for (x = 0; poop->iaddrs[x].s_addr && (x < 8); x++) { | ||
382 | hostent = gethostbyaddr ((char *)&poop->iaddrs[x], | ||
383 | sizeof (IA), AF_INET); | ||
384 | if ((! hostent) || (! hostent-> h_name)) | ||
385 | holler ("Warning: inverse host lookup failed for %s: ", | ||
386 | poop->addrs[x]); | ||
387 | else | ||
388 | (void) comparehosts (poop, hostent); | ||
389 | } /* for x -> addrs, part B */ | ||
390 | |||
391 | } else { /* not INADDR_NONE: numeric addresses... */ | ||
392 | memcpy (poop->iaddrs, &iaddr, sizeof (IA)); | ||
393 | strncpy (poop->addrs[0], inet_ntoa (iaddr), sizeof (poop->addrs)-1); | ||
394 | poop->addrs[0][sizeof (poop->addrs)-1] = '\0'; | ||
395 | if (numeric) /* if numeric-only, we're done */ | ||
396 | return (poop); | ||
397 | if (! o_verbose) /* likewise if we don't want */ | ||
398 | return (poop); /* the full DNS hair */ | ||
399 | hostent = gethostbyaddr ((char *) &iaddr, sizeof (IA), AF_INET); | ||
400 | /* numeric or not, failure to look up a PTR is *not* considered fatal */ | ||
401 | if (! hostent) | ||
402 | holler ("%s: inverse host lookup failed: ", name); | ||
403 | else { | ||
404 | strncpy (poop->name, hostent->h_name, MAXHOSTNAMELEN - 1); | ||
405 | poop->name[MAXHOSTNAMELEN-1] = '\0'; | ||
406 | hostent = gethostbyname (poop->name); | ||
407 | if ((! hostent) || (! hostent->h_addr_list[0])) | ||
408 | holler ("Warning: forward host lookup failed for %s: ", | ||
409 | poop->name); | ||
410 | else | ||
411 | (void) comparehosts (poop, hostent); | ||
412 | } /* if hostent */ | ||
413 | } /* INADDR_NONE Great Split */ | ||
414 | |||
415 | /* whatever-all went down previously, we should now have a host_poop struct | ||
416 | with at least one IP address in it. */ | ||
417 | h_errno = 0; | ||
418 | return (poop); | ||
419 | } /* gethostpoop */ | ||
420 | |||
421 | /* getportpoop : | ||
422 | Same general idea as gethostpoop -- look up a port in /etc/services, fill | ||
423 | in global port_poop, but return the actual port *number*. Pass ONE of: | ||
424 | pstring to resolve stuff like "23" or "exec"; | ||
425 | pnum to reverse-resolve something that's already a number. | ||
426 | If o_nflag is on, fill in what we can but skip the getservby??? stuff. | ||
427 | Might as well have consistent behavior here, and it *is* faster. */ | ||
428 | USHORT getportpoop (pstring, pnum) | ||
429 | char * pstring; | ||
430 | unsigned int pnum; | ||
431 | { | ||
432 | struct servent * servent; | ||
433 | register int x; | ||
434 | register int y; | ||
435 | char * whichp = p_tcp; | ||
436 | if (o_udpmode) | ||
437 | whichp = p_udp; | ||
438 | portpoop->name[0] = '?'; /* fast preload */ | ||
439 | portpoop->name[1] = '\0'; | ||
440 | |||
441 | /* case 1: reverse-lookup of a number; placed first since this case is much | ||
442 | more frequent if we're scanning */ | ||
443 | if (pnum) { | ||
444 | if (pstring) /* one or the other, pleeze */ | ||
445 | return (0); | ||
446 | x = pnum; | ||
447 | if (o_nflag) /* go faster, skip getservbyblah */ | ||
448 | goto gp_finish; | ||
449 | y = htons (x); /* gotta do this -- see Fig.1 below */ | ||
450 | servent = getservbyport (y, whichp); | ||
451 | if (servent) { | ||
452 | y = ntohs (servent->s_port); | ||
453 | if (x != y) /* "never happen" */ | ||
454 | holler ("Warning: port-bynum mismatch, %d != %d", x, y); | ||
455 | strncpy (portpoop->name, servent->s_name, sizeof (portpoop->name)-1); | ||
456 | portpoop->name[sizeof (portpoop->name)-1] = '\0'; | ||
457 | } /* if servent */ | ||
458 | goto gp_finish; | ||
459 | } /* if pnum */ | ||
460 | |||
461 | /* case 2: resolve a string, but we still give preference to numbers instead | ||
462 | of trying to resolve conflicts. None of the entries in *my* extensive | ||
463 | /etc/services begins with a digit, so this should "always work" unless | ||
464 | you're at 3com and have some company-internal services defined... */ | ||
465 | if (pstring) { | ||
466 | if (pnum) /* one or the other, pleeze */ | ||
467 | return (0); | ||
468 | x = atoi (pstring); | ||
469 | if (x) | ||
470 | return (getportpoop (NULL, x)); /* recurse for numeric-string-arg */ | ||
471 | if (o_nflag) /* can't use names! */ | ||
472 | return (0); | ||
473 | servent = getservbyname (pstring, whichp); | ||
474 | if (servent) { | ||
475 | strncpy (portpoop->name, servent->s_name, sizeof (portpoop->name)-1); | ||
476 | portpoop->name[sizeof (portpoop->name)-1] = '\0'; | ||
477 | x = ntohs (servent->s_port); | ||
478 | goto gp_finish; | ||
479 | } /* if servent */ | ||
480 | } /* if pstring */ | ||
481 | |||
482 | return (0); /* catches any problems so far */ | ||
483 | |||
484 | /* Obligatory netdb.h-inspired rant: servent.s_port is supposed to be an int. | ||
485 | Despite this, we still have to treat it as a short when copying it around. | ||
486 | Not only that, but we have to convert it *back* into net order for | ||
487 | getservbyport to work. Manpages generally aren't clear on all this, but | ||
488 | there are plenty of examples in which it is just quietly done. More BSD | ||
489 | lossage... since everything getserv* ever deals with is local to our own | ||
490 | host, why bother with all this network-order/host-order crap at all?! | ||
491 | That should be saved for when we want to actually plug the port[s] into | ||
492 | some real network calls -- and guess what, we have to *re*-convert at that | ||
493 | point as well. Fuckheads. */ | ||
494 | |||
495 | gp_finish: | ||
496 | /* Fall here whether or not we have a valid servent at this point, with | ||
497 | x containing our [host-order and therefore useful, dammit] port number */ | ||
498 | sprintf (portpoop->anum, "%d", x); /* always load any numeric specs! */ | ||
499 | portpoop->num = (x & 0xffff); /* ushort, remember... */ | ||
500 | return (portpoop->num); | ||
501 | } /* getportpoop */ | ||
502 | |||
503 | /* nextport : | ||
504 | Come up with the next port to try, be it random or whatever. "block" is | ||
505 | a ptr to randports array, whose bytes [so far] carry these meanings: | ||
506 | 0 ignore | ||
507 | 1 to be tested | ||
508 | 2 tested [which is set as we find them here] | ||
509 | returns a USHORT random port, or 0 if all the t-b-t ones are used up. */ | ||
510 | USHORT nextport (block) | ||
511 | char * block; | ||
512 | { | ||
513 | register unsigned int x; | ||
514 | register unsigned int y; | ||
515 | |||
516 | y = 70000; /* high safety count for rnd-tries */ | ||
517 | while (y > 0) { | ||
518 | x = (RAND() & 0xffff); | ||
519 | if (block[x] == 1) { /* try to find a not-done one... */ | ||
520 | block[x] = 2; | ||
521 | break; | ||
522 | } | ||
523 | x = 0; /* bummer. */ | ||
524 | y--; | ||
525 | } /* while y */ | ||
526 | if (x) | ||
527 | return (x); | ||
528 | |||
529 | y = 65535; /* no random one, try linear downsearch */ | ||
530 | while (y > 0) { /* if they're all used, we *must* be sure! */ | ||
531 | if (block[y] == 1) { | ||
532 | block[y] = 2; | ||
533 | break; | ||
534 | } | ||
535 | y--; | ||
536 | } /* while y */ | ||
537 | if (y) | ||
538 | return (y); /* at least one left */ | ||
539 | |||
540 | return (0); /* no more left! */ | ||
541 | } /* nextport */ | ||
542 | |||
543 | /* loadports : | ||
544 | set "to be tested" indications in BLOCK, from LO to HI. Almost too small | ||
545 | to be a separate routine, but makes main() a little cleaner... */ | ||
546 | void loadports (block, lo, hi) | ||
547 | char * block; | ||
548 | USHORT lo; | ||
549 | USHORT hi; | ||
550 | { | ||
551 | USHORT x; | ||
552 | |||
553 | if (! block) | ||
554 | bail ("loadports: no block?!"); | ||
555 | if ((! lo) || (! hi)) | ||
556 | bail ("loadports: bogus values %d, %d", lo, hi); | ||
557 | x = hi; | ||
558 | while (lo <= x) { | ||
559 | block[x] = 1; | ||
560 | x--; | ||
561 | } | ||
562 | } /* loadports */ | ||
563 | |||
564 | #ifdef GAPING_SECURITY_HOLE | ||
565 | char * pr00gie = NULL; /* global ptr to -e arg */ | ||
566 | |||
567 | /* doexec : | ||
568 | fiddle all the file descriptors around, and hand off to another prog. Sort | ||
569 | of like a one-off "poor man's inetd". This is the only section of code | ||
570 | that would be security-critical, which is why it's ifdefed out by default. | ||
571 | Use at your own hairy risk; if you leave shells lying around behind open | ||
572 | listening ports you deserve to lose!! */ | ||
573 | doexec (fd) | ||
574 | int fd; | ||
575 | { | ||
576 | register char * p; | ||
577 | |||
578 | dup2 (fd, 0); /* the precise order of fiddlage */ | ||
579 | close (fd); /* is apparently crucial; this is */ | ||
580 | dup2 (0, 1); /* swiped directly out of "inetd". */ | ||
581 | dup2 (0, 2); | ||
582 | p = strrchr (pr00gie, '/'); /* shorter argv[0] */ | ||
583 | if (p) | ||
584 | p++; | ||
585 | else | ||
586 | p = pr00gie; | ||
587 | Debug (("gonna exec %s as %s...", pr00gie, p)) | ||
588 | execl (pr00gie, p, NULL); | ||
589 | bail ("exec %s failed", pr00gie); /* this gets sent out. Hmm... */ | ||
590 | } /* doexec */ | ||
591 | #endif /* GAPING_SECURITY_HOLE */ | ||
592 | |||
593 | /* doconnect : | ||
594 | do all the socket stuff, and return an fd for one of | ||
595 | an open outbound TCP connection | ||
596 | a UDP stub-socket thingie | ||
597 | with appropriate socket options set up if we wanted source-routing, or | ||
598 | an unconnected TCP or UDP socket to listen on. | ||
599 | Examines various global o_blah flags to figure out what-all to do. */ | ||
600 | int doconnect (rad, rp, lad, lp) | ||
601 | IA * rad; | ||
602 | USHORT rp; | ||
603 | IA * lad; | ||
604 | USHORT lp; | ||
605 | { | ||
606 | register int nnetfd; | ||
607 | register int rr; | ||
608 | int x, y; | ||
609 | errno = 0; | ||
610 | |||
611 | /* grab a socket; set opts */ | ||
612 | newskt: | ||
613 | if (o_udpmode) | ||
614 | nnetfd = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP); | ||
615 | else | ||
616 | nnetfd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); | ||
617 | if (nnetfd < 0) | ||
618 | bail ("Can't get socket"); | ||
619 | if (nnetfd == 0) /* if stdin was closed this might *be* 0, */ | ||
620 | goto newskt; /* so grab another. See text for why... */ | ||
621 | x = 1; | ||
622 | rr = setsockopt (nnetfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof (x)); | ||
623 | if (rr == -1) | ||
624 | holler ("nnetfd reuseaddr failed"); /* ??? */ | ||
625 | #ifdef SO_REUSEPORT /* doesnt exist everywhere... */ | ||
626 | rr = setsockopt (nnetfd, SOL_SOCKET, SO_REUSEPORT, &x, sizeof (x)); | ||
627 | if (rr == -1) | ||
628 | holler ("nnetfd reuseport failed"); /* ??? */ | ||
629 | #endif | ||
630 | #if 0 | ||
631 | /* If you want to screw with RCVBUF/SNDBUF, do it here. Liudvikas Bukys at | ||
632 | Rochester sent this example, which would involve YET MORE options and is | ||
633 | just archived here in case you want to mess with it. o_xxxbuf are global | ||
634 | integers set in main() getopt loop, and check for rr == 0 afterward. */ | ||
635 | rr = setsockopt(nnetfd, SOL_SOCKET, SO_RCVBUF, &o_rcvbuf, sizeof o_rcvbuf); | ||
636 | rr = setsockopt(nnetfd, SOL_SOCKET, SO_SNDBUF, &o_sndbuf, sizeof o_sndbuf); | ||
637 | #endif | ||
638 | |||
639 | /* fill in all the right sockaddr crud */ | ||
640 | lclend->sin_family = AF_INET; | ||
641 | |||
642 | /* fill in all the right sockaddr crud */ | ||
643 | lclend->sin_family = AF_INET; | ||
644 | remend->sin_family = AF_INET; | ||
645 | |||
646 | /* if lad/lp, do appropriate binding */ | ||
647 | if (lad) | ||
648 | memcpy (&lclend->sin_addr.s_addr, lad, sizeof (IA)); | ||
649 | if (lp) | ||
650 | lclend->sin_port = htons (lp); | ||
651 | rr = 0; | ||
652 | if (lad || lp) { | ||
653 | x = (int) lp; | ||
654 | /* try a few times for the local bind, a la ftp-data-port... */ | ||
655 | for (y = 4; y > 0; y--) { | ||
656 | rr = bind (nnetfd, (SA *)lclend, sizeof (SA)); | ||
657 | if (rr == 0) | ||
658 | break; | ||
659 | if (errno != EADDRINUSE) | ||
660 | break; | ||
661 | else { | ||
662 | holler ("retrying local %s:%d", inet_ntoa (lclend->sin_addr), lp); | ||
663 | sleep (2); | ||
664 | errno = 0; /* clear from sleep */ | ||
665 | } /* if EADDRINUSE */ | ||
666 | } /* for y counter */ | ||
667 | } /* if lad or lp */ | ||
668 | if (rr) | ||
669 | bail ("Can't grab %s:%d with bind", | ||
670 | inet_ntoa(lclend->sin_addr), lp); | ||
671 | |||
672 | if (o_listen) | ||
673 | return (nnetfd); /* thanks, that's all for today */ | ||
674 | |||
675 | memcpy (&remend->sin_addr.s_addr, rad, sizeof (IA)); | ||
676 | remend->sin_port = htons (rp); | ||
677 | |||
678 | /* rough format of LSRR option and explanation of weirdness. | ||
679 | Option comes after IP-hdr dest addr in packet, padded to *4, and ihl > 5. | ||
680 | IHL is multiples of 4, i.e. real len = ip_hl << 2. | ||
681 | type 131 1 ; 0x83: copied, option class 0, number 3 | ||
682 | len 1 ; of *whole* option! | ||
683 | pointer 1 ; nxt-hop-addr; 1-relative, not 0-relative | ||
684 | addrlist... var ; 4 bytes per hop-addr | ||
685 | pad-to-32 var ; ones, i.e. "NOP" | ||
686 | |||
687 | If we want to route A -> B via hops C and D, we must add C, D, *and* B to the | ||
688 | options list. Why? Because when we hand the kernel A -> B with list C, D, B | ||
689 | the "send shuffle" inside the kernel changes it into A -> C with list D, B and | ||
690 | the outbound packet gets sent to C. If B wasn't also in the hops list, the | ||
691 | final destination would have been lost at this point. | ||
692 | |||
693 | When C gets the packet, it changes it to A -> D with list C', B where C' is | ||
694 | the interface address that C used to forward the packet. This "records" the | ||
695 | route hop from B's point of view, i.e. which address points "toward" B. This | ||
696 | is to make B better able to return the packets. The pointer gets bumped by 4, | ||
697 | so that D does the right thing instead of trying to forward back to C. | ||
698 | |||
699 | When B finally gets the packet, it sees that the pointer is at the end of the | ||
700 | LSRR list and is thus "completed". B will then try to use the packet instead | ||
701 | of forwarding it, i.e. deliver it up to some application. | ||
702 | |||
703 | Note that by moving the pointer yourself, you could send the traffic directly | ||
704 | to B but have it return via your preconstructed source-route. Playing with | ||
705 | this and watching "tcpdump -v" is the best way to understand what's going on. | ||
706 | |||
707 | Only works for TCP in BSD-flavor kernels. UDP is a loss; udp_input calls | ||
708 | stripoptions() early on, and the code to save the srcrt is notdef'ed. | ||
709 | Linux is also still a loss at 1.3.x it looks like; the lsrr code is { }... | ||
710 | */ | ||
711 | |||
712 | /* if any -g arguments were given, set up source-routing. We hit this after | ||
713 | the gates are all looked up and ready to rock, any -G pointer is set, | ||
714 | and gatesidx is now the *number* of hops */ | ||
715 | if (gatesidx) { /* if we wanted any srcrt hops ... */ | ||
716 | /* don't even bother compiling if we can't do IP options here! */ | ||
717 | #ifdef IP_OPTIONS | ||
718 | if (! optbuf) { /* and don't already *have* a srcrt set */ | ||
719 | char * opp; /* then do all this setup hair */ | ||
720 | optbuf = Hmalloc (48); | ||
721 | opp = optbuf; | ||
722 | *opp++ = IPOPT_LSRR; /* option */ | ||
723 | *opp++ = (char) | ||
724 | (((gatesidx + 1) * sizeof (IA)) + 3) & 0xff; /* length */ | ||
725 | *opp++ = gatesptr; /* pointer */ | ||
726 | /* opp now points at first hop addr -- insert the intermediate gateways */ | ||
727 | for ( x = 0; x < gatesidx; x++) { | ||
728 | memcpy (opp, gates[x]->iaddrs, sizeof (IA)); | ||
729 | opp += sizeof (IA); | ||
730 | } | ||
731 | /* and tack the final destination on the end [needed!] */ | ||
732 | memcpy (opp, rad, sizeof (IA)); | ||
733 | opp += sizeof (IA); | ||
734 | *opp = IPOPT_NOP; /* alignment filler */ | ||
735 | } /* if empty optbuf */ | ||
736 | /* calculate length of whole option mess, which is (3 + [hops] + [final] + 1), | ||
737 | and apply it [have to do this every time through, of course] */ | ||
738 | x = ((gatesidx + 1) * sizeof (IA)) + 4; | ||
739 | rr = setsockopt (nnetfd, IPPROTO_IP, IP_OPTIONS, optbuf, x); | ||
740 | if (rr == -1) | ||
741 | bail ("srcrt setsockopt fuxored"); | ||
742 | #else /* IP_OPTIONS */ | ||
743 | holler ("Warning: source routing unavailable on this machine, ignoring"); | ||
744 | #endif /* IP_OPTIONS*/ | ||
745 | } /* if gatesidx */ | ||
746 | |||
747 | /* wrap connect inside a timer, and hit it */ | ||
748 | arm (1, o_wait); | ||
749 | if (setjmp (jbuf) == 0) { | ||
750 | rr = connect (nnetfd, (SA *)remend, sizeof (SA)); | ||
751 | } else { /* setjmp: connect failed... */ | ||
752 | rr = -1; | ||
753 | errno = ETIMEDOUT; /* fake it */ | ||
754 | } | ||
755 | arm (0, 0); | ||
756 | if (rr == 0) | ||
757 | return (nnetfd); | ||
758 | close (nnetfd); /* clean up junked socket FD!! */ | ||
759 | return (-1); | ||
760 | } /* doconnect */ | ||
761 | |||
762 | /* dolisten : | ||
763 | just like doconnect, and in fact calls a hunk of doconnect, but listens for | ||
764 | incoming and returns an open connection *from* someplace. If we were | ||
765 | given host/port args, any connections from elsewhere are rejected. This | ||
766 | in conjunction with local-address binding should limit things nicely... */ | ||
767 | int dolisten (rad, rp, lad, lp) | ||
768 | IA * rad; | ||
769 | USHORT rp; | ||
770 | IA * lad; | ||
771 | USHORT lp; | ||
772 | { | ||
773 | register int nnetfd; | ||
774 | register int rr; | ||
775 | HINF * whozis = NULL; | ||
776 | int x; | ||
777 | char * cp; | ||
778 | USHORT z; | ||
779 | errno = 0; | ||
780 | |||
781 | /* Pass everything off to doconnect, who in o_listen mode just gets a socket */ | ||
782 | nnetfd = doconnect (rad, rp, lad, lp); | ||
783 | if (nnetfd <= 0) | ||
784 | return (-1); | ||
785 | if (o_udpmode) { /* apparently UDP can listen ON */ | ||
786 | if (! lp) /* "port 0", but that's not useful */ | ||
787 | bail ("UDP listen needs -p arg"); | ||
788 | } else { | ||
789 | rr = listen (nnetfd, 1); /* gotta listen() before we can get */ | ||
790 | if (rr < 0) /* our local random port. sheesh. */ | ||
791 | bail ("local listen fuxored"); | ||
792 | } | ||
793 | |||
794 | /* Various things that follow temporarily trash bigbuf_net, which might contain | ||
795 | a copy of any recvfrom()ed packet, but we'll read() another copy later. */ | ||
796 | |||
797 | /* I can't believe I have to do all this to get my own goddamn bound address | ||
798 | and port number. It should just get filled in during bind() or something. | ||
799 | All this is only useful if we didn't say -p for listening, since if we | ||
800 | said -p we *know* what port we're listening on. At any rate we won't bother | ||
801 | with it all unless we wanted to see it, although listening quietly on a | ||
802 | random unknown port is probably not very useful without "netstat". */ | ||
803 | if (o_verbose) { | ||
804 | x = sizeof (SA); /* how 'bout getsockNUM instead, pinheads?! */ | ||
805 | rr = getsockname (nnetfd, (SA *) lclend, &x); | ||
806 | if (rr < 0) | ||
807 | holler ("local getsockname failed"); | ||
808 | strcpy (bigbuf_net, "listening on ["); /* buffer reuse... */ | ||
809 | if (lclend->sin_addr.s_addr) | ||
810 | strcat (bigbuf_net, inet_ntoa (lclend->sin_addr)); | ||
811 | else | ||
812 | strcat (bigbuf_net, "any"); | ||
813 | strcat (bigbuf_net, "] %d ..."); | ||
814 | z = ntohs (lclend->sin_port); | ||
815 | holler (bigbuf_net, z); | ||
816 | } /* verbose -- whew!! */ | ||
817 | |||
818 | /* UDP is a speeeeecial case -- we have to do I/O *and* get the calling | ||
819 | party's particulars all at once, listen() and accept() don't apply. | ||
820 | At least in the BSD universe, however, recvfrom/PEEK is enough to tell | ||
821 | us something came in, and we can set things up so straight read/write | ||
822 | actually does work after all. Yow. YMMV on strange platforms! */ | ||
823 | if (o_udpmode) { | ||
824 | x = sizeof (SA); /* retval for recvfrom */ | ||
825 | arm (2, o_wait); /* might as well timeout this, too */ | ||
826 | if (setjmp (jbuf) == 0) { /* do timeout for initial connect */ | ||
827 | rr = recvfrom /* and here we block... */ | ||
828 | (nnetfd, bigbuf_net, BIGSIZ, MSG_PEEK, (SA *) remend, &x); | ||
829 | Debug (("dolisten/recvfrom ding, rr = %d, netbuf %s ", rr, bigbuf_net)) | ||
830 | } else | ||
831 | goto dol_tmo; /* timeout */ | ||
832 | arm (0, 0); | ||
833 | /* I'm not completely clear on how this works -- BSD seems to make UDP | ||
834 | just magically work in a connect()ed context, but we'll undoubtedly run | ||
835 | into systems this deal doesn't work on. For now, we apparently have to | ||
836 | issue a connect() on our just-tickled socket so we can write() back. | ||
837 | Again, why the fuck doesn't it just get filled in and taken care of?! | ||
838 | This hack is anything but optimal. Basically, if you want your listener | ||
839 | to also be able to send data back, you need this connect() line, which | ||
840 | also has the side effect that now anything from a different source or even a | ||
841 | different port on the other end won't show up and will cause ICMP errors. | ||
842 | I guess that's what they meant by "connect". | ||
843 | Let's try to remember what the "U" is *really* for, eh? */ | ||
844 | rr = connect (nnetfd, (SA *)remend, sizeof (SA)); | ||
845 | goto whoisit; | ||
846 | } /* o_udpmode */ | ||
847 | |||
848 | /* fall here for TCP */ | ||
849 | x = sizeof (SA); /* retval for accept */ | ||
850 | arm (2, o_wait); /* wrap this in a timer, too; 0 = forever */ | ||
851 | if (setjmp (jbuf) == 0) { | ||
852 | rr = accept (nnetfd, (SA *)remend, &x); | ||
853 | } else | ||
854 | goto dol_tmo; /* timeout */ | ||
855 | arm (0, 0); | ||
856 | close (nnetfd); /* dump the old socket */ | ||
857 | nnetfd = rr; /* here's our new one */ | ||
858 | |||
859 | whoisit: | ||
860 | if (rr < 0) | ||
861 | goto dol_err; /* bail out if any errors so far */ | ||
862 | |||
863 | /* If we can, look for any IP options. Useful for testing the receiving end of | ||
864 | such things, and is a good exercise in dealing with it. We do this before | ||
865 | the connect message, to ensure that the connect msg is uniformly the LAST | ||
866 | thing to emerge after all the intervening crud. Doesn't work for UDP on | ||
867 | any machines I've tested, but feel free to surprise me. */ | ||
868 | #ifdef IP_OPTIONS | ||
869 | if (! o_verbose) /* if we wont see it, we dont care */ | ||
870 | goto dol_noop; | ||
871 | optbuf = Hmalloc (40); | ||
872 | x = 40; | ||
873 | rr = getsockopt (nnetfd, IPPROTO_IP, IP_OPTIONS, optbuf, &x); | ||
874 | if (rr < 0) | ||
875 | holler ("getsockopt failed"); | ||
876 | Debug (("ipoptions ret len %d", x)) | ||
877 | if (x) { /* we've got options, lessee em... */ | ||
878 | unsigned char * q = (unsigned char *) optbuf; | ||
879 | char * p = bigbuf_net; /* local variables, yuk! */ | ||
880 | char * pp = &bigbuf_net[128]; /* get random space farther out... */ | ||
881 | memset (bigbuf_net, 0, 256); /* clear it all first */ | ||
882 | while (x > 0) { | ||
883 | sprintf (pp, "%2.2x ", *q); /* clumsy, but works: turn into hex */ | ||
884 | strcat (p, pp); /* and build the final string */ | ||
885 | q++; p++; | ||
886 | x--; | ||
887 | } | ||
888 | holler ("IP options: %s", bigbuf_net); | ||
889 | } /* if x, i.e. any options */ | ||
890 | dol_noop: | ||
891 | #endif /* IP_OPTIONS */ | ||
892 | |||
893 | /* find out what address the connection was *to* on our end, in case we're | ||
894 | doing a listen-on-any on a multihomed machine. This allows one to | ||
895 | offer different services via different alias addresses, such as the | ||
896 | "virtual web site" hack. */ | ||
897 | memset (bigbuf_net, 0, 64); | ||
898 | cp = &bigbuf_net[32]; | ||
899 | x = sizeof (SA); | ||
900 | rr = getsockname (nnetfd, (SA *) lclend, &x); | ||
901 | if (rr < 0) | ||
902 | holler ("post-rcv getsockname failed"); | ||
903 | strcpy (cp, inet_ntoa (lclend->sin_addr)); | ||
904 | |||
905 | /* now check out who it is. We don't care about mismatched DNS names here, | ||
906 | but any ADDR and PORT we specified had better fucking well match the caller. | ||
907 | Converting from addr to inet_ntoa and back again is a bit of a kludge, but | ||
908 | gethostpoop wants a string and there's much gnarlier code out there already, | ||
909 | so I don't feel bad. | ||
910 | The *real* question is why BFD sockets wasn't designed to allow listens for | ||
911 | connections *from* specific hosts/ports, instead of requiring the caller to | ||
912 | accept the connection and then reject undesireable ones by closing. In | ||
913 | other words, we need a TCP MSG_PEEK. */ | ||
914 | z = ntohs (remend->sin_port); | ||
915 | strcpy (bigbuf_net, inet_ntoa (remend->sin_addr)); | ||
916 | whozis = gethostpoop (bigbuf_net, o_nflag); | ||
917 | errno = 0; | ||
918 | x = 0; /* use as a flag... */ | ||
919 | if (rad) /* xxx: fix to go down the *list* if we have one? */ | ||
920 | if (memcmp (rad, whozis->iaddrs, sizeof (SA))) | ||
921 | x = 1; | ||
922 | if (rp) | ||
923 | if (z != rp) | ||
924 | x = 1; | ||
925 | if (x) /* guilty! */ | ||
926 | bail ("invalid connection to [%s] from %s [%s] %d", | ||
927 | cp, whozis->name, whozis->addrs[0], z); | ||
928 | holler ("connect to [%s] from %s [%s] %d", /* oh, you're okay.. */ | ||
929 | cp, whozis->name, whozis->addrs[0], z); | ||
930 | return (nnetfd); /* open! */ | ||
931 | |||
932 | dol_tmo: | ||
933 | errno = ETIMEDOUT; /* fake it */ | ||
934 | dol_err: | ||
935 | close (nnetfd); | ||
936 | return (-1); | ||
937 | } /* dolisten */ | ||
938 | |||
939 | /* udptest : | ||
940 | fire a couple of packets at a UDP target port, just to see if it's really | ||
941 | there. On BSD kernels, ICMP host/port-unreachable errors get delivered to | ||
942 | our socket as ECONNREFUSED write errors. On SV kernels, we lose; we'll have | ||
943 | to collect and analyze raw ICMP ourselves a la satan's probe_udp_ports | ||
944 | backend. Guess where one could swipe the appropriate code from... | ||
945 | |||
946 | Use the time delay between writes if given, otherwise use the "tcp ping" | ||
947 | trick for getting the RTT. [I got that idea from pluvius, and warped it.] | ||
948 | Return either the original fd, or clean up and return -1. */ | ||
949 | udptest (fd, where) | ||
950 | int fd; | ||
951 | IA * where; | ||
952 | { | ||
953 | register int rr; | ||
954 | |||
955 | rr = write (fd, bigbuf_in, 1); | ||
956 | if (rr != 1) | ||
957 | holler ("udptest first write failed?! errno %d", errno); | ||
958 | if (o_wait) | ||
959 | sleep (o_wait); | ||
960 | else { | ||
961 | /* use the tcp-ping trick: try connecting to a normally refused port, which | ||
962 | causes us to block for the time that SYN gets there and RST gets back. | ||
963 | Not completely reliable, but it *does* mostly work. */ | ||
964 | o_udpmode = 0; /* so doconnect does TCP this time */ | ||
965 | /* Set a temporary connect timeout, so packet filtration doesnt cause | ||
966 | us to hang forever, and hit it */ | ||
967 | o_wait = 5; /* enough that we'll notice?? */ | ||
968 | rr = doconnect (where, SLEAZE_PORT, 0, 0); | ||
969 | if (rr > 0) | ||
970 | close (rr); /* in case it *did* open */ | ||
971 | o_wait = 0; /* reset it */ | ||
972 | o_udpmode++; /* we *are* still doing UDP, right? */ | ||
973 | } /* if o_wait */ | ||
974 | errno = 0; /* clear from sleep */ | ||
975 | rr = write (fd, bigbuf_in, 1); | ||
976 | if (rr == 1) /* if write error, no UDP listener */ | ||
977 | return (fd); | ||
978 | close (fd); /* use it or lose it! */ | ||
979 | return (-1); | ||
980 | } /* udptest */ | ||
981 | |||
982 | /* oprint : | ||
983 | Hexdump bytes shoveled either way to a running logfile, in the format: | ||
984 | D offset - - - - --- 16 bytes --- - - - - # .... ascii ..... | ||
985 | where "which" sets the direction indicator, D: | ||
986 | 0 -- sent to network, or ">" | ||
987 | 1 -- rcvd and printed to stdout, or "<" | ||
988 | and "buf" and "n" are data-block and length. If the current block generates | ||
989 | a partial line, so be it; we *want* that lockstep indication of who sent | ||
990 | what when. Adapted from dgaudet's original example -- but must be ripping | ||
991 | *fast*, since we don't want to be too disk-bound... */ | ||
992 | void oprint (which, buf, n) | ||
993 | int which; | ||
994 | char * buf; | ||
995 | int n; | ||
996 | { | ||
997 | int bc; /* in buffer count */ | ||
998 | int obc; /* current "global" offset */ | ||
999 | int soc; /* stage write count */ | ||
1000 | register unsigned char * p; /* main buf ptr; m.b. unsigned here */ | ||
1001 | register unsigned char * op; /* out hexdump ptr */ | ||
1002 | register unsigned char * a; /* out asc-dump ptr */ | ||
1003 | register int x; | ||
1004 | register unsigned int y; | ||
1005 | |||
1006 | if (! ofd) | ||
1007 | bail ("oprint called with no open fd?!"); | ||
1008 | if (n == 0) | ||
1009 | return; | ||
1010 | |||
1011 | op = stage; | ||
1012 | if (which) { | ||
1013 | *op = '<'; | ||
1014 | obc = wrote_out; /* use the globals! */ | ||
1015 | } else { | ||
1016 | *op = '>'; | ||
1017 | obc = wrote_net; | ||
1018 | } | ||
1019 | op++; /* preload "direction" */ | ||
1020 | *op = ' '; | ||
1021 | p = (unsigned char *) buf; | ||
1022 | bc = n; | ||
1023 | stage[59] = '#'; /* preload separator */ | ||
1024 | stage[60] = ' '; | ||
1025 | |||
1026 | while (bc) { /* for chunk-o-data ... */ | ||
1027 | x = 16; | ||
1028 | soc = 78; /* len of whole formatted line */ | ||
1029 | if (bc < x) { | ||
1030 | soc = soc - 16 + bc; /* fiddle for however much is left */ | ||
1031 | x = (bc * 3) + 11; /* 2 digits + space per, after D & offset */ | ||
1032 | op = &stage[x]; | ||
1033 | x = 16 - bc; | ||
1034 | while (x) { | ||
1035 | *op++ = ' '; /* preload filler spaces */ | ||
1036 | *op++ = ' '; | ||
1037 | *op++ = ' '; | ||
1038 | x--; | ||
1039 | } | ||
1040 | x = bc; /* re-fix current linecount */ | ||
1041 | } /* if bc < x */ | ||
1042 | |||
1043 | bc -= x; /* fix wrt current line size */ | ||
1044 | sprintf (&stage[2], "%8.8x ", obc); /* xxx: still slow? */ | ||
1045 | obc += x; /* fix current offset */ | ||
1046 | op = &stage[11]; /* where hex starts */ | ||
1047 | a = &stage[61]; /* where ascii starts */ | ||
1048 | |||
1049 | while (x) { /* for line of dump, however long ... */ | ||
1050 | y = (int)(*p >> 4); /* hi half */ | ||
1051 | *op = hexnibs[y]; | ||
1052 | op++; | ||
1053 | y = (int)(*p & 0x0f); /* lo half */ | ||
1054 | *op = hexnibs[y]; | ||
1055 | op++; | ||
1056 | *op = ' '; | ||
1057 | op++; | ||
1058 | if ((*p > 31) && (*p < 127)) | ||
1059 | *a = *p; /* printing */ | ||
1060 | else | ||
1061 | *a = '.'; /* nonprinting, loose def */ | ||
1062 | a++; | ||
1063 | p++; | ||
1064 | x--; | ||
1065 | } /* while x */ | ||
1066 | *a = '\n'; /* finish the line */ | ||
1067 | x = write (ofd, stage, soc); | ||
1068 | if (x < 0) | ||
1069 | bail ("ofd write err"); | ||
1070 | } /* while bc */ | ||
1071 | } /* oprint */ | ||
1072 | |||
1073 | #ifdef TELNET | ||
1074 | USHORT o_tn = 0; /* global -t option */ | ||
1075 | |||
1076 | /* atelnet : | ||
1077 | Answer anything that looks like telnet negotiation with don't/won't. | ||
1078 | This doesn't modify any data buffers, update the global output count, | ||
1079 | or show up in a hexdump -- it just shits into the outgoing stream. | ||
1080 | Idea and codebase from Mudge@l0pht.com. */ | ||
1081 | void atelnet (buf, size) | ||
1082 | unsigned char * buf; /* has to be unsigned here! */ | ||
1083 | unsigned int size; | ||
1084 | { | ||
1085 | static unsigned char obuf [4]; /* tiny thing to build responses into */ | ||
1086 | register int x; | ||
1087 | register unsigned char y; | ||
1088 | register unsigned char * p; | ||
1089 | |||
1090 | y = 0; | ||
1091 | p = buf; | ||
1092 | x = size; | ||
1093 | while (x > 0) { | ||
1094 | if (*p != 255) /* IAC? */ | ||
1095 | goto notiac; | ||
1096 | obuf[0] = 255; | ||
1097 | p++; x--; | ||
1098 | if ((*p == 251) || (*p == 252)) /* WILL or WONT */ | ||
1099 | y = 254; /* -> DONT */ | ||
1100 | if ((*p == 253) || (*p == 254)) /* DO or DONT */ | ||
1101 | y = 252; /* -> WONT */ | ||
1102 | if (y) { | ||
1103 | obuf[1] = y; | ||
1104 | p++; x--; | ||
1105 | obuf[2] = *p; /* copy actual option byte */ | ||
1106 | (void) write (netfd, obuf, 3); | ||
1107 | /* if one wanted to bump wrote_net or do a hexdump line, here's the place */ | ||
1108 | y = 0; | ||
1109 | } /* if y */ | ||
1110 | notiac: | ||
1111 | p++; x--; | ||
1112 | } /* while x */ | ||
1113 | } /* atelnet */ | ||
1114 | #endif /* TELNET */ | ||
1115 | |||
1116 | /* readwrite : | ||
1117 | handle stdin/stdout/network I/O. Bwahaha!! -- the select loop from hell. | ||
1118 | In this instance, return what might become our exit status. */ | ||
1119 | int readwrite (fd) | ||
1120 | int fd; | ||
1121 | { | ||
1122 | register int rr; | ||
1123 | register char * zp; /* stdin buf ptr */ | ||
1124 | register char * np; /* net-in buf ptr */ | ||
1125 | unsigned int rzleft; | ||
1126 | unsigned int rnleft; | ||
1127 | USHORT netretry; /* net-read retry counter */ | ||
1128 | USHORT wretry; /* net-write sanity counter */ | ||
1129 | USHORT wfirst; /* one-shot flag to skip first net read */ | ||
1130 | |||
1131 | /* if you don't have all this FD_* macro hair in sys/types.h, you'll have to | ||
1132 | either find it or do your own bit-bashing: *ding1 |= (1 << fd), etc... */ | ||
1133 | if (fd > FD_SETSIZE) { | ||
1134 | holler ("Preposterous fd value %d", fd); | ||
1135 | return (1); | ||
1136 | } | ||
1137 | FD_SET (fd, ding1); /* global: the net is open */ | ||
1138 | netretry = 2; | ||
1139 | wfirst = 0; | ||
1140 | rzleft = rnleft = 0; | ||
1141 | if (insaved) { | ||
1142 | rzleft = insaved; /* preload multi-mode fakeouts */ | ||
1143 | zp = bigbuf_in; | ||
1144 | wfirst = 1; | ||
1145 | if (Single) /* if not scanning, this is a one-off first */ | ||
1146 | insaved = 0; /* buffer left over from argv construction, */ | ||
1147 | else { | ||
1148 | FD_CLR (0, ding1); /* OR we've already got our repeat chunk, */ | ||
1149 | close (0); /* so we won't need any more stdin */ | ||
1150 | } /* Single */ | ||
1151 | } /* insaved */ | ||
1152 | if (o_interval) | ||
1153 | sleep (o_interval); /* pause *before* sending stuff, too */ | ||
1154 | errno = 0; /* clear from sleep, close, whatever */ | ||
1155 | |||
1156 | /* and now the big ol' select shoveling loop ... */ | ||
1157 | while (FD_ISSET (fd, ding1)) { /* i.e. till the *net* closes! */ | ||
1158 | wretry = 8200; /* more than we'll ever hafta write */ | ||
1159 | if (wfirst) { /* any saved stdin buffer? */ | ||
1160 | wfirst = 0; /* clear flag for the duration */ | ||
1161 | goto shovel; /* and go handle it first */ | ||
1162 | } | ||
1163 | *ding2 = *ding1; /* FD_COPY ain't portable... */ | ||
1164 | /* some systems, notably linux, crap into their select timers on return, so | ||
1165 | we create a expendable copy and give *that* to select. *Fuck* me ... */ | ||
1166 | if (timer1) | ||
1167 | memcpy (timer2, timer1, sizeof (struct timeval)); | ||
1168 | rr = select (16, ding2, 0, 0, timer2); /* here it is, kiddies */ | ||
1169 | if (rr < 0) { | ||
1170 | if (errno != EINTR) { /* might have gotten ^Zed, etc ?*/ | ||
1171 | holler ("select fuxored"); | ||
1172 | close (fd); | ||
1173 | return (1); | ||
1174 | } | ||
1175 | } /* select fuckup */ | ||
1176 | /* if we have a timeout AND stdin is closed AND we haven't heard anything | ||
1177 | from the net during that time, assume it's dead and close it too. */ | ||
1178 | if (rr == 0) { | ||
1179 | if (! FD_ISSET (0, ding1)) | ||
1180 | netretry--; /* we actually try a coupla times. */ | ||
1181 | if (! netretry) { | ||
1182 | if (o_verbose > 1) /* normally we don't care */ | ||
1183 | holler ("net timeout"); | ||
1184 | close (fd); | ||
1185 | return (0); /* not an error! */ | ||
1186 | } | ||
1187 | } /* select timeout */ | ||
1188 | /* xxx: should we check the exception fds too? The read fds seem to give | ||
1189 | us the right info, and none of the examples I found bothered. */ | ||
1190 | |||
1191 | /* Ding!! Something arrived, go check all the incoming hoppers, net first */ | ||
1192 | if (FD_ISSET (fd, ding2)) { /* net: ding! */ | ||
1193 | rr = read (fd, bigbuf_net, BIGSIZ); | ||
1194 | if (rr <= 0) { | ||
1195 | FD_CLR (fd, ding1); /* net closed, we'll finish up... */ | ||
1196 | rzleft = 0; /* can't write anymore: broken pipe */ | ||
1197 | } else { | ||
1198 | rnleft = rr; | ||
1199 | np = bigbuf_net; | ||
1200 | #ifdef TELNET | ||
1201 | if (o_tn) | ||
1202 | atelnet (np, rr); /* fake out telnet stuff */ | ||
1203 | #endif /* TELNET */ | ||
1204 | } /* if rr */ | ||
1205 | Debug (("got %d from the net, errno %d", rr, errno)) | ||
1206 | } /* net:ding */ | ||
1207 | |||
1208 | /* if we're in "slowly" mode there's probably still stuff in the stdin | ||
1209 | buffer, so don't read unless we really need MORE INPUT! MORE INPUT! */ | ||
1210 | if (rzleft) | ||
1211 | goto shovel; | ||
1212 | |||
1213 | /* okay, suck more stdin */ | ||
1214 | if (FD_ISSET (0, ding2)) { /* stdin: ding! */ | ||
1215 | rr = read (0, bigbuf_in, BIGSIZ); | ||
1216 | /* Considered making reads here smaller for UDP mode, but 8192-byte | ||
1217 | mobygrams are kinda fun and exercise the reassembler. */ | ||
1218 | if (rr <= 0) { /* at end, or fukt, or ... */ | ||
1219 | FD_CLR (0, ding1); /* disable and close stdin */ | ||
1220 | close (0); | ||
1221 | } else { | ||
1222 | rzleft = rr; | ||
1223 | zp = bigbuf_in; | ||
1224 | /* special case for multi-mode -- we'll want to send this one buffer to every | ||
1225 | open TCP port or every UDP attempt, so save its size and clean up stdin */ | ||
1226 | if (! Single) { /* we might be scanning... */ | ||
1227 | insaved = rr; /* save len */ | ||
1228 | FD_CLR (0, ding1); /* disable further junk from stdin */ | ||
1229 | close (0); /* really, I mean it */ | ||
1230 | } /* Single */ | ||
1231 | } /* if rr/read */ | ||
1232 | } /* stdin:ding */ | ||
1233 | |||
1234 | shovel: | ||
1235 | /* now that we've dingdonged all our thingdings, send off the results. | ||
1236 | Geez, why does this look an awful lot like the big loop in "rsh"? ... | ||
1237 | not sure if the order of this matters, but write net -> stdout first. */ | ||
1238 | |||
1239 | /* sanity check. Works because they're both unsigned... */ | ||
1240 | if ((rzleft > 8200) || (rnleft > 8200)) { | ||
1241 | holler ("Bogus buffers: %d, %d", rzleft, rnleft); | ||
1242 | rzleft = rnleft = 0; | ||
1243 | } | ||
1244 | /* net write retries sometimes happen on UDP connections */ | ||
1245 | if (! wretry) { /* is something hung? */ | ||
1246 | holler ("too many output retries"); | ||
1247 | return (1); | ||
1248 | } | ||
1249 | if (rnleft) { | ||
1250 | rr = write (1, np, rnleft); | ||
1251 | if (rr > 0) { | ||
1252 | if (o_wfile) | ||
1253 | oprint (1, np, rr); /* log the stdout */ | ||
1254 | np += rr; /* fix up ptrs and whatnot */ | ||
1255 | rnleft -= rr; /* will get sanity-checked above */ | ||
1256 | wrote_out += rr; /* global count */ | ||
1257 | } | ||
1258 | Debug (("wrote %d to stdout, errno %d", rr, errno)) | ||
1259 | } /* rnleft */ | ||
1260 | if (rzleft) { | ||
1261 | if (o_interval) /* in "slowly" mode ?? */ | ||
1262 | rr = findline (zp, rzleft); | ||
1263 | else | ||
1264 | rr = rzleft; | ||
1265 | rr = write (fd, zp, rr); /* one line, or the whole buffer */ | ||
1266 | if (rr > 0) { | ||
1267 | if (o_wfile) | ||
1268 | oprint (0, zp, rr); /* log what got sent */ | ||
1269 | zp += rr; | ||
1270 | rzleft -= rr; | ||
1271 | wrote_net += rr; /* global count */ | ||
1272 | } | ||
1273 | Debug (("wrote %d to net, errno %d", rr, errno)) | ||
1274 | } /* rzleft */ | ||
1275 | if (o_interval) { /* cycle between slow lines, or ... */ | ||
1276 | sleep (o_interval); | ||
1277 | errno = 0; /* clear from sleep */ | ||
1278 | continue; /* ...with hairy select loop... */ | ||
1279 | } | ||
1280 | if ((rzleft) || (rnleft)) { /* shovel that shit till they ain't */ | ||
1281 | wretry--; /* none left, and get another load */ | ||
1282 | goto shovel; | ||
1283 | } | ||
1284 | } /* while ding1:netfd is open */ | ||
1285 | |||
1286 | /* XXX: maybe want a more graceful shutdown() here, or screw around with | ||
1287 | linger times?? I suspect that I don't need to since I'm always doing | ||
1288 | blocking reads and writes and my own manual "last ditch" efforts to read | ||
1289 | the net again after a timeout. I haven't seen any screwups yet, but it's | ||
1290 | not like my test network is particularly busy... */ | ||
1291 | close (fd); | ||
1292 | return (0); | ||
1293 | } /* readwrite */ | ||
1294 | |||
1295 | /* main : | ||
1296 | now we pull it all together... */ | ||
1297 | main (argc, argv) | ||
1298 | int argc; | ||
1299 | char ** argv; | ||
1300 | { | ||
1301 | #ifndef HAVE_GETOPT | ||
1302 | extern char * optarg; | ||
1303 | extern int optind, optopt; | ||
1304 | #endif | ||
1305 | register int x; | ||
1306 | register char *cp; | ||
1307 | HINF * gp; | ||
1308 | HINF * whereto = NULL; | ||
1309 | HINF * wherefrom = NULL; | ||
1310 | IA * ouraddr = NULL; | ||
1311 | IA * themaddr = NULL; | ||
1312 | USHORT o_lport = 0; | ||
1313 | USHORT ourport = 0; | ||
1314 | USHORT loport = 0; /* for scanning stuff */ | ||
1315 | USHORT hiport = 0; | ||
1316 | USHORT curport = 0; | ||
1317 | char * randports = NULL; | ||
1318 | |||
1319 | #ifdef HAVE_BIND | ||
1320 | /* can *you* say "cc -yaddayadda netcat.c -lresolv -l44bsd" on SunLOSs? */ | ||
1321 | res_init(); | ||
1322 | #endif | ||
1323 | /* I was in this barbershop quartet in Skokie IL ... */ | ||
1324 | /* round up the usual suspects, i.e. malloc up all the stuff we need */ | ||
1325 | lclend = (SAI *) Hmalloc (sizeof (SA)); | ||
1326 | remend = (SAI *) Hmalloc (sizeof (SA)); | ||
1327 | bigbuf_in = Hmalloc (BIGSIZ); | ||
1328 | bigbuf_net = Hmalloc (BIGSIZ); | ||
1329 | ding1 = (fd_set *) Hmalloc (sizeof (fd_set)); | ||
1330 | ding2 = (fd_set *) Hmalloc (sizeof (fd_set)); | ||
1331 | portpoop = (PINF *) Hmalloc (sizeof (PINF)); | ||
1332 | |||
1333 | errno = 0; | ||
1334 | gatesptr = 4; | ||
1335 | h_errno = 0; | ||
1336 | |||
1337 | /* catch a signal or two for cleanup */ | ||
1338 | signal (SIGINT, catch); | ||
1339 | signal (SIGQUIT, catch); | ||
1340 | signal (SIGTERM, catch); | ||
1341 | /* and suppress others... */ | ||
1342 | #ifdef SIGURG | ||
1343 | signal (SIGURG, SIG_IGN); | ||
1344 | #endif | ||
1345 | #ifdef SIGPIPE | ||
1346 | signal (SIGPIPE, SIG_IGN); /* important! */ | ||
1347 | #endif | ||
1348 | |||
1349 | /* if no args given at all, get 'em from stdin, construct an argv, and hand | ||
1350 | anything left over to readwrite(). */ | ||
1351 | if (argc == 1) { | ||
1352 | cp = argv[0]; | ||
1353 | argv = (char **) Hmalloc (128 * sizeof (char *)); /* XXX: 128? */ | ||
1354 | argv[0] = cp; /* leave old prog name intact */ | ||
1355 | cp = Hmalloc (BIGSIZ); | ||
1356 | argv[1] = cp; /* head of new arg block */ | ||
1357 | fprintf (stderr, "Cmd line: "); | ||
1358 | fflush (stderr); /* I dont care if it's unbuffered or not! */ | ||
1359 | insaved = read (0, cp, BIGSIZ); /* we're gonna fake fgets() here */ | ||
1360 | if (insaved <= 0) | ||
1361 | bail ("wrong"); | ||
1362 | x = findline (cp, insaved); | ||
1363 | if (x) | ||
1364 | insaved -= x; /* remaining chunk size to be sent */ | ||
1365 | if (insaved) /* which might be zero... */ | ||
1366 | memcpy (bigbuf_in, &cp[x], insaved); | ||
1367 | cp = strchr (argv[1], '\n'); | ||
1368 | if (cp) | ||
1369 | *cp = '\0'; | ||
1370 | cp = strchr (argv[1], '\r'); /* look for ^M too */ | ||
1371 | if (cp) | ||
1372 | *cp = '\0'; | ||
1373 | |||
1374 | /* find and stash pointers to remaining new "args" */ | ||
1375 | cp = argv[1]; | ||
1376 | cp++; /* skip past first char */ | ||
1377 | x = 2; /* we know argv 0 and 1 already */ | ||
1378 | for (; *cp != '\0'; cp++) { | ||
1379 | if (*cp == ' ') { | ||
1380 | *cp = '\0'; /* smash all spaces */ | ||
1381 | continue; | ||
1382 | } else { | ||
1383 | if (*(cp-1) == '\0') { | ||
1384 | argv[x] = cp; | ||
1385 | x++; | ||
1386 | } | ||
1387 | } /* if space */ | ||
1388 | } /* for cp */ | ||
1389 | argc = x; | ||
1390 | } /* if no args given */ | ||
1391 | |||
1392 | /* If your shitbox doesn't have getopt, step into the nineties already. */ | ||
1393 | /* optarg, optind = next-argv-component [i.e. flag arg]; optopt = last-char */ | ||
1394 | while ((x = getopt (argc, argv, "ae:g:G:hi:lno:p:rs:tuvw:z")) != -1) { | ||
1395 | /* Debug (("in go: x now %c, optarg %x optind %d", x, optarg, optind)) */ | ||
1396 | switch (x) { | ||
1397 | case 'a': | ||
1398 | bail ("all-A-records NIY"); | ||
1399 | o_alla++; break; | ||
1400 | #ifdef GAPING_SECURITY_HOLE | ||
1401 | case 'e': /* prog to exec */ | ||
1402 | pr00gie = optarg; | ||
1403 | break; | ||
1404 | #endif | ||
1405 | case 'G': /* srcrt gateways pointer val */ | ||
1406 | x = atoi (optarg); | ||
1407 | if ((x) && (x == (x & 0x1c))) /* mask off bits of fukt values */ | ||
1408 | gatesptr = x; | ||
1409 | else | ||
1410 | bail ("invalid hop pointer %d, must be multiple of 4 <= 28", x); | ||
1411 | break; | ||
1412 | case 'g': /* srcroute hop[s] */ | ||
1413 | if (gatesidx > 8) | ||
1414 | bail ("too many -g hops"); | ||
1415 | if (gates == NULL) /* eat this, Billy-boy */ | ||
1416 | gates = (HINF **) Hmalloc (sizeof (HINF *) * 10); | ||
1417 | gp = gethostpoop (optarg, o_nflag); | ||
1418 | if (gp) | ||
1419 | gates[gatesidx] = gp; | ||
1420 | gatesidx++; | ||
1421 | break; | ||
1422 | case 'h': | ||
1423 | errno = 0; | ||
1424 | #ifdef HAVE_HELP | ||
1425 | helpme(); /* exits by itself */ | ||
1426 | #else | ||
1427 | bail ("no help available, dork -- RTFS"); | ||
1428 | #endif | ||
1429 | case 'i': /* line-interval time */ | ||
1430 | o_interval = atoi (optarg) & 0xffff; | ||
1431 | if (! o_interval) | ||
1432 | bail ("invalid interval time %s", optarg); | ||
1433 | break; | ||
1434 | case 'l': /* listen mode */ | ||
1435 | o_listen++; break; | ||
1436 | case 'n': /* numeric-only, no DNS lookups */ | ||
1437 | o_nflag++; break; | ||
1438 | case 'o': /* hexdump log */ | ||
1439 | stage = (unsigned char *) optarg; | ||
1440 | o_wfile++; break; | ||
1441 | case 'p': /* local source port */ | ||
1442 | o_lport = getportpoop (optarg, 0); | ||
1443 | if (o_lport == 0) | ||
1444 | bail ("invalid local port %s", optarg); | ||
1445 | break; | ||
1446 | case 'r': /* randomize various things */ | ||
1447 | o_random++; break; | ||
1448 | case 's': /* local source address */ | ||
1449 | /* do a full lookup [since everything else goes through the same mill], | ||
1450 | unless -n was previously specified. In fact, careful placement of -n can | ||
1451 | be useful, so we'll still pass o_nflag here instead of forcing numeric. */ | ||
1452 | wherefrom = gethostpoop (optarg, o_nflag); | ||
1453 | ouraddr = &wherefrom->iaddrs[0]; | ||
1454 | break; | ||
1455 | #ifdef TELNET | ||
1456 | case 't': /* do telnet fakeout */ | ||
1457 | o_tn++; break; | ||
1458 | #endif /* TELNET */ | ||
1459 | case 'u': /* use UDP */ | ||
1460 | o_udpmode++; break; | ||
1461 | case 'v': /* verbose */ | ||
1462 | o_verbose++; break; | ||
1463 | case 'w': /* wait time */ | ||
1464 | o_wait = atoi (optarg); | ||
1465 | if (o_wait <= 0) | ||
1466 | bail ("invalid wait-time %s", optarg); | ||
1467 | timer1 = (struct timeval *) Hmalloc (sizeof (struct timeval)); | ||
1468 | timer2 = (struct timeval *) Hmalloc (sizeof (struct timeval)); | ||
1469 | timer1->tv_sec = o_wait; /* we need two. see readwrite()... */ | ||
1470 | break; | ||
1471 | case 'z': /* little or no data xfer */ | ||
1472 | o_zero++; | ||
1473 | break; | ||
1474 | default: | ||
1475 | errno = 0; | ||
1476 | bail ("nc -h for help"); | ||
1477 | } /* switch x */ | ||
1478 | } /* while getopt */ | ||
1479 | |||
1480 | /* other misc initialization */ | ||
1481 | Debug (("fd_set size %d", sizeof (*ding1))) /* how big *is* it? */ | ||
1482 | FD_SET (0, ding1); /* stdin *is* initially open */ | ||
1483 | if (o_random) { | ||
1484 | SRAND (time (0)); | ||
1485 | randports = Hmalloc (65536); /* big flag array for ports */ | ||
1486 | } | ||
1487 | #ifdef GAPING_SECURITY_HOLE | ||
1488 | if (pr00gie) { | ||
1489 | close (0); /* won't need stdin */ | ||
1490 | o_wfile = 0; /* -o with -e is meaningless! */ | ||
1491 | ofd = 0; | ||
1492 | } | ||
1493 | #endif /* G_S_H */ | ||
1494 | if (o_wfile) { | ||
1495 | ofd = open (stage, O_WRONLY | O_CREAT | O_TRUNC, 0664); | ||
1496 | if (ofd <= 0) /* must be > extant 0/1/2 */ | ||
1497 | bail ("can't open %s", stage); | ||
1498 | stage = (unsigned char *) Hmalloc (100); | ||
1499 | } | ||
1500 | |||
1501 | /* optind is now index of first non -x arg */ | ||
1502 | Debug (("after go: x now %c, optarg %x optind %d", x, optarg, optind)) | ||
1503 | /* Debug (("optind up to %d at host-arg %s", optind, argv[optind])) */ | ||
1504 | /* gonna only use first addr of host-list, like our IQ was normal; if you wanna | ||
1505 | get fancy with addresses, look up the list yourself and plug 'em in for now. | ||
1506 | unless we finally implement -a, that is. */ | ||
1507 | if (argv[optind]) | ||
1508 | whereto = gethostpoop (argv[optind], o_nflag); | ||
1509 | if (whereto && whereto->iaddrs) | ||
1510 | themaddr = &whereto->iaddrs[0]; | ||
1511 | if (themaddr) | ||
1512 | optind++; /* skip past valid host lookup */ | ||
1513 | errno = 0; | ||
1514 | h_errno = 0; | ||
1515 | |||
1516 | /* Handle listen mode here, and exit afterward. Only does one connect; | ||
1517 | this is arguably the right thing to do. A "persistent listen-and-fork" | ||
1518 | mode a la inetd has been thought about, but not implemented. A tiny | ||
1519 | wrapper script can handle such things... */ | ||
1520 | if (o_listen) { | ||
1521 | curport = 0; /* rem port *can* be zero here... */ | ||
1522 | if (argv[optind]) { /* any rem-port-arg? */ | ||
1523 | curport = getportpoop (argv[optind], 0); | ||
1524 | if (curport == 0) /* if given, demand correctness */ | ||
1525 | bail ("invalid port %s", argv[optind]); | ||
1526 | } /* if port-arg */ | ||
1527 | netfd = dolisten (themaddr, curport, ouraddr, o_lport); | ||
1528 | /* dolisten does its own connect reporting, so we don't holler anything here */ | ||
1529 | if (netfd > 0) { | ||
1530 | #ifdef GAPING_SECURITY_HOLE | ||
1531 | if (pr00gie) /* -e given? */ | ||
1532 | doexec (netfd); | ||
1533 | #endif /* GAPING_SECURITY_HOLE */ | ||
1534 | x = readwrite (netfd); /* it even works with UDP! */ | ||
1535 | if (o_verbose > 1) /* normally we don't care */ | ||
1536 | holler (wrote_txt, wrote_net, wrote_out); | ||
1537 | exit (x); /* "pack out yer trash" */ | ||
1538 | } else /* if no netfd */ | ||
1539 | bail ("no connection"); | ||
1540 | } /* o_listen */ | ||
1541 | |||
1542 | /* fall thru to outbound connects. Now we're more picky about args... */ | ||
1543 | if (! themaddr) | ||
1544 | bail ("no destination"); | ||
1545 | if (argv[optind] == NULL) | ||
1546 | bail ("no port[s] to connect to"); | ||
1547 | if (argv[optind + 1]) /* look ahead: any more port args given? */ | ||
1548 | Single = 0; /* multi-mode, case A */ | ||
1549 | ourport = o_lport; /* which can be 0 */ | ||
1550 | |||
1551 | /* everything from here down is treated as as ports and/or ranges thereof, so | ||
1552 | it's all enclosed in this big ol' argv-parsin' loop. Any randomization is | ||
1553 | done within each given *range*, but in separate chunks per each succeeding | ||
1554 | argument, so we can control the pattern somewhat. */ | ||
1555 | while (argv[optind]) { | ||
1556 | hiport = loport = 0; | ||
1557 | cp = strchr (argv[optind], '-'); /* nn-mm range? */ | ||
1558 | if (cp) { | ||
1559 | *cp = '\0'; | ||
1560 | cp++; | ||
1561 | hiport = getportpoop (cp, 0); | ||
1562 | if (hiport == 0) | ||
1563 | bail ("invalid port %s", cp); | ||
1564 | } /* if found a dash */ | ||
1565 | loport = getportpoop (argv[optind], 0); | ||
1566 | if (loport == 0) | ||
1567 | bail ("invalid port %s", argv[optind]); | ||
1568 | if (hiport > loport) { /* was it genuinely a range? */ | ||
1569 | Single = 0; /* multi-mode, case B */ | ||
1570 | curport = hiport; /* start high by default */ | ||
1571 | if (o_random) { /* maybe populate the random array */ | ||
1572 | loadports (randports, loport, hiport); | ||
1573 | curport = nextport (randports); | ||
1574 | } | ||
1575 | } else /* not a range, including args like "25-25" */ | ||
1576 | curport = loport; | ||
1577 | Debug (("Single %d, curport %d", Single, curport)) | ||
1578 | |||
1579 | /* Now start connecting to these things. curport is already preloaded. */ | ||
1580 | while (loport <= curport) { | ||
1581 | if ((! o_lport) && (o_random)) { /* -p overrides random local-port */ | ||
1582 | ourport = (RAND() & 0xffff); /* random local-bind -- well above */ | ||
1583 | if (ourport < 8192) /* resv and any likely listeners??? */ | ||
1584 | ourport += 8192; /* if it *still* conflicts, use -s. */ | ||
1585 | } | ||
1586 | curport = getportpoop (NULL, curport); | ||
1587 | netfd = doconnect (themaddr, curport, ouraddr, ourport); | ||
1588 | Debug (("netfd %d from port %d to port %d", netfd, ourport, curport)) | ||
1589 | if (netfd > 0) | ||
1590 | if (o_zero && o_udpmode) /* if UDP scanning... */ | ||
1591 | netfd = udptest (netfd, themaddr); | ||
1592 | if (netfd > 0) { /* Yow, are we OPEN YET?! */ | ||
1593 | x = 0; /* pre-exit status */ | ||
1594 | holler ("%s [%s] %d (%s) open", | ||
1595 | whereto->name, whereto->addrs[0], curport, portpoop->name); | ||
1596 | #ifdef GAPING_SECURITY_HOLE | ||
1597 | if (pr00gie) /* exec is valid for outbound, too */ | ||
1598 | doexec (netfd); | ||
1599 | #endif /* GAPING_SECURITY_HOLE */ | ||
1600 | if (! o_zero) | ||
1601 | x = readwrite (netfd); /* go shovel shit */ | ||
1602 | } else { /* no netfd... */ | ||
1603 | x = 1; /* preload exit status for later */ | ||
1604 | /* if we're scanning at a "one -v" verbosity level, don't print refusals. | ||
1605 | Give it another -v if you want to see everything. */ | ||
1606 | if ((Single || (o_verbose > 1)) || (errno != ECONNREFUSED)) | ||
1607 | holler ("%s [%s] %d (%s)", | ||
1608 | whereto->name, whereto->addrs[0], curport, portpoop->name); | ||
1609 | } /* if netfd */ | ||
1610 | close (netfd); /* just in case we didn't already */ | ||
1611 | if (o_interval) | ||
1612 | sleep (o_interval); /* if -i, delay between ports too */ | ||
1613 | if (o_random) | ||
1614 | curport = nextport (randports); | ||
1615 | else | ||
1616 | curport--; /* just decrement... */ | ||
1617 | } /* while curport within current range */ | ||
1618 | optind++; | ||
1619 | } /* while remaining port-args -- end of big argv-ports loop*/ | ||
1620 | |||
1621 | errno = 0; | ||
1622 | if (o_verbose > 1) /* normally we don't care */ | ||
1623 | holler (wrote_txt, wrote_net, wrote_out); | ||
1624 | if (Single) | ||
1625 | exit (x); /* give us status on one connection */ | ||
1626 | exit (0); /* otherwise, we're just done */ | ||
1627 | } /* main */ | ||
1628 | |||
1629 | #ifdef HAVE_HELP /* unless we wanna be *really* cryptic */ | ||
1630 | /* helpme : | ||
1631 | the obvious */ | ||
1632 | helpme() | ||
1633 | { | ||
1634 | o_verbose = 1; | ||
1635 | holler ("[v1.10]\n\ | ||
1636 | connect to somewhere: nc [-options] hostname port[s] [ports] ... \n\ | ||
1637 | listen for inbound: nc -l -p port [-options] [hostname] [port]\n\ | ||
1638 | options:"); | ||
1639 | /* sigh, this necessarily gets messy. And the trailing \ characters may be | ||
1640 | interpreted oddly by some compilers, generating or not generating extra | ||
1641 | newlines as they bloody please. u-fix... */ | ||
1642 | #ifdef GAPING_SECURITY_HOLE /* needs to be separate holler() */ | ||
1643 | holler ("\ | ||
1644 | -e prog program to exec after connect [dangerous!!]"); | ||
1645 | #endif | ||
1646 | holler ("\ | ||
1647 | -g gateway source-routing hop point[s], up to 8\n\ | ||
1648 | -G num source-routing pointer: 4, 8, 12, ...\n\ | ||
1649 | -h this cruft\n\ | ||
1650 | -i secs delay interval for lines sent, ports scanned\n\ | ||
1651 | -l listen mode, for inbound connects\n\ | ||
1652 | -n numeric-only IP addresses, no DNS\n\ | ||
1653 | -o file hex dump of traffic\n\ | ||
1654 | -p port local port number\n\ | ||
1655 | -r randomize local and remote ports\n\ | ||
1656 | -s addr local source address"); | ||
1657 | #ifdef TELNET | ||
1658 | holler ("\ | ||
1659 | -t answer TELNET negotiation"); | ||
1660 | #endif | ||
1661 | holler ("\ | ||
1662 | -u UDP mode\n\ | ||
1663 | -v verbose [use twice to be more verbose]\n\ | ||
1664 | -w secs timeout for connects and final net reads\n\ | ||
1665 | -z zero-I/O mode [used for scanning]"); | ||
1666 | bail ("port numbers can be individual or ranges: lo-hi [inclusive]"); | ||
1667 | } /* helpme */ | ||
1668 | #endif /* HAVE_HELP */ | ||
1669 | |||
1670 | /* None genuine without this seal! _H*/ | ||
diff --git a/src/usr.bin/nc/scripts/README b/src/usr.bin/nc/scripts/README new file mode 100644 index 0000000000..07aee0c8ea --- /dev/null +++ b/src/usr.bin/nc/scripts/README | |||
@@ -0,0 +1,5 @@ | |||
1 | A collection of example scripts that use netcat as a backend, each | ||
2 | documented by its own internal comments. | ||
3 | |||
4 | I'll be the first to admit that some of these are seriously *sick*, | ||
5 | but they do work and are quite useful to me on a daily basis. | ||
diff --git a/src/usr.bin/nc/scripts/alta b/src/usr.bin/nc/scripts/alta new file mode 100644 index 0000000000..7a091767e8 --- /dev/null +++ b/src/usr.bin/nc/scripts/alta | |||
@@ -0,0 +1,33 @@ | |||
1 | #! /bin/sh | ||
2 | ## special handler for altavista, since they only hand out chunks of 10 at | ||
3 | ## a time. Tries to isolate out results without the leading/trailing trash. | ||
4 | ## multiword arguments are foo+bar, as usual. | ||
5 | ## Second optional arg switches the "what" field, to e.g. "news" | ||
6 | |||
7 | test "${1}" = "" && echo 'Needs an argument to search for!' && exit 1 | ||
8 | WHAT="web" | ||
9 | test "${2}" && WHAT="${2}" | ||
10 | |||
11 | # convert multiple args | ||
12 | PLUSARG="`echo $* | sed 's/ /+/g'`" | ||
13 | |||
14 | # Plug in arg. only doing simple-q for now; pg=aq for advanced-query | ||
15 | # embedded quotes define phrases; otherwise it goes wild on multi-words | ||
16 | QB="GET /cgi-bin/query?pg=q&what=${WHAT}&fmt=c&q=\"${PLUSARG}\"" | ||
17 | |||
18 | # ping 'em once, to get the routing warm | ||
19 | nc -z -w 8 www.altavista.digital.com 24015 2> /dev/null | ||
20 | echo "=== Altavista ===" | ||
21 | |||
22 | for xx in 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 \ | ||
23 | 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 ; do | ||
24 | echo "${QB}&stq=${xx}" | nc -w 15 www.altavista.digital.com 80 | \ | ||
25 | egrep '^<a href="http://' | ||
26 | done | ||
27 | |||
28 | exit 0 | ||
29 | |||
30 | # old filter stuff | ||
31 | sed -e '/Documents .* matching .* query /,/query?.*stq=.* Document/p' \ | ||
32 | -e d | ||
33 | |||
diff --git a/src/usr.bin/nc/scripts/bsh b/src/usr.bin/nc/scripts/bsh new file mode 100644 index 0000000000..796e480354 --- /dev/null +++ b/src/usr.bin/nc/scripts/bsh | |||
@@ -0,0 +1,29 @@ | |||
1 | #! /bin/sh | ||
2 | ## a little wrapper to "password" and re-launch a shell-listener. | ||
3 | ## Arg is taken as the port to listen on. Define "NC" to point wherever. | ||
4 | |||
5 | NC=nc | ||
6 | |||
7 | case "$1" in | ||
8 | ?* ) | ||
9 | LPN="$1" | ||
10 | export LPN | ||
11 | sleep 1 | ||
12 | echo "-l -p $LPN -e $0" | $NC > /dev/null 2>&1 & | ||
13 | echo "launched on port $LPN" | ||
14 | exit 0 | ||
15 | ;; | ||
16 | esac | ||
17 | |||
18 | # here we play inetd | ||
19 | echo "-l -p $LPN -e $0" | $NC > /dev/null 2>&1 & | ||
20 | |||
21 | while read qq ; do | ||
22 | case "$qq" in | ||
23 | # here's yer password | ||
24 | gimme ) | ||
25 | cd / | ||
26 | exec csh -i | ||
27 | ;; | ||
28 | esac | ||
29 | done | ||
diff --git a/src/usr.bin/nc/scripts/dist.sh b/src/usr.bin/nc/scripts/dist.sh new file mode 100644 index 0000000000..4d2534a0e3 --- /dev/null +++ b/src/usr.bin/nc/scripts/dist.sh | |||
@@ -0,0 +1,23 @@ | |||
1 | #! /bin/sh | ||
2 | ## This is a quick example listen-exec server, which was used for a while to | ||
3 | ## distribute netcat prereleases. It illustrates use of netcat both as a | ||
4 | ## "fake inetd" and a syslogger, and how easy it then is to crock up a fairly | ||
5 | ## functional server that restarts its own listener and does full connection | ||
6 | ## logging. In a half-screen of shell script!! | ||
7 | |||
8 | PORT=31337 | ||
9 | |||
10 | sleep 1 | ||
11 | SRC=`tail -1 dist.log` | ||
12 | echo "<36>elite: ${SRC}" | ./nc -u -w 1 localhost 514 > /dev/null 2>&1 | ||
13 | echo ";;; Hi, ${SRC}..." | ||
14 | echo ";;; This is a PRERELEASE version of 'netcat', tar/gzip/uuencoded." | ||
15 | echo ";;; Unless you are capturing this somehow, it won't do you much good." | ||
16 | echo ";;; Ready?? Here it comes! Have phun ..." | ||
17 | sleep 8 | ||
18 | cat dist.file | ||
19 | sleep 1 | ||
20 | ./nc -v -l -p ${PORT} -e dist.sh < /dev/null >> dist.log 2>&1 & | ||
21 | sleep 1 | ||
22 | echo "<36>elite: done" | ./nc -u -w 1 localhost 514 > /dev/null 2>&1 | ||
23 | exit 0 | ||
diff --git a/src/usr.bin/nc/scripts/irc b/src/usr.bin/nc/scripts/irc new file mode 100644 index 0000000000..3557d7a0c6 --- /dev/null +++ b/src/usr.bin/nc/scripts/irc | |||
@@ -0,0 +1,79 @@ | |||
1 | #! /bin/sh | ||
2 | ## Shit-simple script to supply the "privmsg <recipient>" of IRC typein, and | ||
3 | ## keep the connection alive. Pipe this thru "nc -v -w 5 irc-server port". | ||
4 | ## Note that this mechanism makes the script easy to debug without being live, | ||
5 | ## since it just echoes everything bound for the server. | ||
6 | ## if you want autologin-type stuff, construct some appropriate files and | ||
7 | ## shovel them in using the "<" mechanism. | ||
8 | |||
9 | # magic arg: if "tick", do keepalive process instead of main loop | ||
10 | if test "$1" = "tick" ; then | ||
11 | # ignore most signals; the parent will nuke the kid | ||
12 | # doesn't stop ^Z, of course. | ||
13 | trap '' 1 2 3 13 14 15 16 | ||
14 | while true ; do | ||
15 | sleep 60 | ||
16 | echo "PONG !" | ||
17 | done | ||
18 | fi | ||
19 | |||
20 | # top level: fire ourselves off as the keepalive process, and keep track of it | ||
21 | sh $0 tick & | ||
22 | ircpp=$! | ||
23 | echo "[Keepalive: $ircpp]" >&2 | ||
24 | # catch our own batch of signals: hup int quit pipe alrm term urg | ||
25 | trap 'kill -9 $ircpp ; exit 0' 1 2 3 13 14 15 16 | ||
26 | sleep 2 | ||
27 | |||
28 | sender='' | ||
29 | savecmd='' | ||
30 | |||
31 | # the big honkin' loop... | ||
32 | while read xx yy ; do | ||
33 | case "${xx}" in | ||
34 | # blank line: do nothing | ||
35 | "") | ||
36 | continue | ||
37 | ;; | ||
38 | # new channel or recipient; if bare ">", we're back to raw literal mode. | ||
39 | ">") | ||
40 | if test "${yy}" ; then | ||
41 | sender="privmsg ${yy} :" | ||
42 | else | ||
43 | sender='' | ||
44 | fi | ||
45 | continue | ||
46 | ;; | ||
47 | # send crud from a file, one line per second. Can you say "skr1pt kidz"?? | ||
48 | # *Note: uses current "recipient" if set. | ||
49 | "<") | ||
50 | if test -f "${yy}" ; then | ||
51 | ( while read zz ; do | ||
52 | sleep 1 | ||
53 | echo "${sender}${zz}" | ||
54 | done ) < "$yy" | ||
55 | echo "[done]" >&2 | ||
56 | else | ||
57 | echo "[File $yy not found]" >&2 | ||
58 | fi | ||
59 | continue | ||
60 | ;; | ||
61 | # do and save a single command, for quick repeat | ||
62 | "/") | ||
63 | if test "${yy}" ; then | ||
64 | savecmd="${yy}" | ||
65 | fi | ||
66 | echo "${savecmd}" | ||
67 | ;; | ||
68 | # default case goes to recipient, just like always | ||
69 | *) | ||
70 | echo "${sender}${xx} ${yy}" | ||
71 | continue | ||
72 | ;; | ||
73 | esac | ||
74 | done | ||
75 | |||
76 | # parting shot, if you want it | ||
77 | echo "quit :Bye all!" | ||
78 | kill -9 $ircpp | ||
79 | exit 0 | ||
diff --git a/src/usr.bin/nc/scripts/iscan b/src/usr.bin/nc/scripts/iscan new file mode 100644 index 0000000000..6279bc817f --- /dev/null +++ b/src/usr.bin/nc/scripts/iscan | |||
@@ -0,0 +1,35 @@ | |||
1 | #! /bin/sh | ||
2 | ## duplicate DaveG's ident-scan thingie using netcat. Oooh, he'll be pissed. | ||
3 | ## args: target port [port port port ...] | ||
4 | ## hose stdout *and* stderr together. | ||
5 | ## | ||
6 | ## advantages: runs slower than ident-scan, giving remote inetd less cause | ||
7 | ## for alarm, and only hits the few known daemon ports you specify. | ||
8 | ## disadvantages: requires numeric-only port args, the output sleazitude, | ||
9 | ## and won't work for r-services when coming from high source ports. | ||
10 | |||
11 | case "${2}" in | ||
12 | "" ) echo needs HOST and at least one PORT ; exit 1 ;; | ||
13 | esac | ||
14 | |||
15 | # ping 'em once and see if they *are* running identd | ||
16 | nc -z -w 9 "$1" 113 || { echo "oops, $1 isn't running identd" ; exit 0 ; } | ||
17 | |||
18 | # generate a randomish base port | ||
19 | RP=`expr $$ % 999 + 31337` | ||
20 | |||
21 | TRG="$1" | ||
22 | shift | ||
23 | |||
24 | while test "$1" ; do | ||
25 | nc -v -w 8 -p ${RP} "$TRG" ${1} < /dev/null > /dev/null & | ||
26 | PROC=$! | ||
27 | sleep 3 | ||
28 | echo "${1},${RP}" | nc -w 4 -r "$TRG" 113 2>&1 | ||
29 | sleep 2 | ||
30 | # does this look like a lamer script or what... | ||
31 | kill -HUP $PROC | ||
32 | RP=`expr ${RP} + 1` | ||
33 | shift | ||
34 | done | ||
35 | |||
diff --git a/src/usr.bin/nc/scripts/ncp b/src/usr.bin/nc/scripts/ncp new file mode 100644 index 0000000000..1931b03385 --- /dev/null +++ b/src/usr.bin/nc/scripts/ncp | |||
@@ -0,0 +1,46 @@ | |||
1 | #! /bin/sh | ||
2 | ## Like "rcp" but uses netcat on a high port. | ||
3 | ## do "ncp targetfile" on the RECEIVING machine | ||
4 | ## then do "ncp sourcefile receivinghost" on the SENDING machine | ||
5 | ## if invoked as "nzp" instead, compresses transit data. | ||
6 | |||
7 | ## pick your own personal favorite port, which will be used on both ends. | ||
8 | ## You should probably change this for your own uses. | ||
9 | MYPORT=23456 | ||
10 | |||
11 | ## if "nc" isn't systemwide or in your PATH, add the right place | ||
12 | # PATH=${HOME}:${PATH} ; export PATH | ||
13 | |||
14 | test "$3" && echo "too many args" && exit 1 | ||
15 | test ! "$1" && echo "no args?" && exit 1 | ||
16 | me=`echo $0 | sed 's+.*/++'` | ||
17 | test "$me" = "nzp" && echo '[compressed mode]' | ||
18 | |||
19 | # if second arg, it's a host to send an [extant] file to. | ||
20 | if test "$2" ; then | ||
21 | test ! -f "$1" && echo "can't find $1" && exit 1 | ||
22 | if test "$me" = "nzp" ; then | ||
23 | compress -c < "$1" | nc -v -w 2 $2 $MYPORT && exit 0 | ||
24 | else | ||
25 | nc -v -w 2 $2 $MYPORT < "$1" && exit 0 | ||
26 | fi | ||
27 | echo "transfer FAILED!" | ||
28 | exit 1 | ||
29 | fi | ||
30 | |||
31 | # fall here for receiver. Ask before trashing existing files | ||
32 | if test -f "$1" ; then | ||
33 | echo -n "Overwrite $1? " | ||
34 | read aa | ||
35 | test ! "$aa" = "y" && echo "[punted!]" && exit 1 | ||
36 | fi | ||
37 | # 30 seconds oughta be pleeeeenty of time, but change if you want. | ||
38 | if test "$me" = "nzp" ; then | ||
39 | nc -v -w 30 -p $MYPORT -l < /dev/null | uncompress -c > "$1" && exit 0 | ||
40 | else | ||
41 | nc -v -w 30 -p $MYPORT -l < /dev/null > "$1" && exit 0 | ||
42 | fi | ||
43 | echo "transfer FAILED!" | ||
44 | # clean up, since even if the transfer failed, $1 is already trashed | ||
45 | rm -f "$1" | ||
46 | exit 1 | ||
diff --git a/src/usr.bin/nc/scripts/probe b/src/usr.bin/nc/scripts/probe new file mode 100644 index 0000000000..c47dc3f495 --- /dev/null +++ b/src/usr.bin/nc/scripts/probe | |||
@@ -0,0 +1,50 @@ | |||
1 | #! /bin/sh | ||
2 | ## launch a whole buncha shit at yon victim in no particular order; capture | ||
3 | ## stderr+stdout in one place. Run as root for rservice and low -p to work. | ||
4 | ## Fairly thorough example of using netcat to collect a lot of host info. | ||
5 | ## Will set off every intrusion alarm in existence on a paranoid machine! | ||
6 | |||
7 | # where .d files are kept; "." if nothing else | ||
8 | DDIR=../data | ||
9 | # address of some well-connected router that groks LSRR | ||
10 | GATE=192.157.69.11 | ||
11 | |||
12 | # might conceivably wanna change this for different run styles | ||
13 | UCMD='nc -v -w 8' | ||
14 | |||
15 | test ! "$1" && echo Needs victim arg && exit 1 | ||
16 | |||
17 | echo '' | $UCMD -w 9 -r "$1" 13 79 6667 2>&1 | ||
18 | echo '0' | $UCMD "$1" 79 2>&1 | ||
19 | # if LSRR was passed thru, should get refusal here: | ||
20 | $UCMD -z -r -g $GATE "$1" 6473 2>&1 | ||
21 | $UCMD -r -z "$1" 6000 4000-4004 111 53 2105 137-140 1-20 540-550 95 87 2>&1 | ||
22 | # -s `hostname` may be wrong for some multihomed machines | ||
23 | echo 'UDP echoecho!' | nc -u -p 7 -s `hostname` -w 3 "$1" 7 19 2>&1 | ||
24 | echo '113,10158' | $UCMD -p 10158 "$1" 113 2>&1 | ||
25 | rservice bin bin | $UCMD -p 1019 "$1" shell 2>&1 | ||
26 | echo QUIT | $UCMD -w 8 -r "$1" 25 158 159 119 110 109 1109 142-144 220 23 2>&1 | ||
27 | # newline after any telnet trash | ||
28 | echo '' | ||
29 | echo PASV | $UCMD -r "$1" 21 2>&1 | ||
30 | echo 'GET /' | $UCMD -w 10 "$1" 80 81 210 70 2>&1 | ||
31 | # sometimes contains useful directory info: | ||
32 | echo 'GET /robots.txt' | $UCMD -w 10 "$1" 80 2>&1 | ||
33 | # now the big red lights go on | ||
34 | rservice bin bin 9600/9600 | $UCMD -p 1020 "$1" login 2>&1 | ||
35 | rservice root root | $UCMD -r "$1" exec 2>&1 | ||
36 | echo 'BEGIN big udp -- everything may look "open" if packet-filtered' | ||
37 | data -g < ${DDIR}/nfs-0.d | $UCMD -i 1 -u "$1" 2049 | od -x 2>&1 | ||
38 | # no wait-time, uses RTT hack | ||
39 | nc -v -z -u -r "$1" 111 66-70 88 53 87 161-164 121-123 213 49 2>&1 | ||
40 | nc -v -z -u -r "$1" 137-140 694-712 747-770 175-180 2103 510-530 2>&1 | ||
41 | echo 'END big udp' | ||
42 | $UCMD -r -z "$1" 175-180 2000-2003 530-533 1524 1525 666 213 8000 6250 2>&1 | ||
43 | # Use our identd-sniffer! | ||
44 | iscan "$1" 21 25 79 80 111 53 6667 6000 2049 119 2>&1 | ||
45 | # this gets pretty intrusive, but what the fuck. Probe for portmap first | ||
46 | if nc -w 5 -z -u "$1" 111 ; then | ||
47 | showmount -e "$1" 2>&1 | ||
48 | rpcinfo -p "$1" 2>&1 | ||
49 | fi | ||
50 | exit 0 | ||
diff --git a/src/usr.bin/nc/scripts/web b/src/usr.bin/nc/scripts/web new file mode 100644 index 0000000000..382b18e1e3 --- /dev/null +++ b/src/usr.bin/nc/scripts/web | |||
@@ -0,0 +1,148 @@ | |||
1 | #! /bin/sh | ||
2 | ## The web sucks. It is a mighty dismal kludge built out of a thousand | ||
3 | ## tiny dismal kludges all band-aided together, and now these bottom-line | ||
4 | ## clueless pinheads who never heard of "TCP handshake" want to run | ||
5 | ## *commerce* over the damn thing. Ye godz. Welcome to TV of the next | ||
6 | ## century -- six million channels of worthless shit to choose from, and | ||
7 | ## about as much security as today's cable industry! | ||
8 | ## | ||
9 | ## Having grown mightily tired of pain in the ass browsers, I decided | ||
10 | ## to build the minimalist client. It doesn't handle POST, just GETs, but | ||
11 | ## the majority of cgi forms handlers apparently ignore the method anyway. | ||
12 | ## A distinct advantage is that it *doesn't* pass on any other information | ||
13 | ## to the server, like Referer: or info about your local machine such as | ||
14 | ## Netscum tries to! | ||
15 | ## | ||
16 | ## Since the first version, this has become the *almost*-minimalist client, | ||
17 | ## but it saves a lot of typing now. And with netcat as its backend, it's | ||
18 | ## totally the balls. Don't have netcat? Get it here in /src/hacks! | ||
19 | ## _H* 950824, updated 951009 et seq. | ||
20 | ## | ||
21 | ## args: hostname [port]. You feed it the filename-parts of URLs. | ||
22 | ## In the loop, HOST, PORT, and SAVE do the right things; a null line | ||
23 | ## gets the previous spec again [useful for initial timeouts]; EOF to exit. | ||
24 | ## Relative URLs behave like a "cd" to wherever the last slash appears, or | ||
25 | ## just use the last component with the saved preceding "directory" part. | ||
26 | ## "\" clears the "filename" part and asks for just the "directory", and | ||
27 | ## ".." goes up one "directory" level while retaining the "filename" part. | ||
28 | ## Play around; you'll get used to it. | ||
29 | |||
30 | if test "$1" = "" ; then | ||
31 | echo Needs hostname arg. | ||
32 | exit 1 | ||
33 | fi | ||
34 | umask 022 | ||
35 | |||
36 | # optional PATH fixup | ||
37 | # PATH=${HOME}:${PATH} ; export PATH | ||
38 | |||
39 | test "${PAGER}" || PAGER=more | ||
40 | BACKEND="nc -v -w 15" | ||
41 | TMPAGE=/tmp/web$$ | ||
42 | host="$1" | ||
43 | port="80" | ||
44 | if test "$2" != "" ; then | ||
45 | port="$2" | ||
46 | fi | ||
47 | |||
48 | spec="/" | ||
49 | specD="/" | ||
50 | specF='' | ||
51 | saving='' | ||
52 | |||
53 | # be vaguely smart about temp file usage. Use your own homedir if you're | ||
54 | # paranoid about someone symlink-racing your shell script, jeez. | ||
55 | rm -f ${TMPAGE} | ||
56 | test -f ${TMPAGE} && echo "Can't use ${TMPAGE}" && exit 1 | ||
57 | |||
58 | # get loopy. Yes, I know "echo -n" aint portable. Everything echoed would | ||
59 | # need "\c" tacked onto the end in an SV universe, which you can fix yourself. | ||
60 | while echo -n "${specD}${specF} " && read spec ; do | ||
61 | case $spec in | ||
62 | HOST) | ||
63 | echo -n 'New host: ' | ||
64 | read host | ||
65 | continue | ||
66 | ;; | ||
67 | PORT) | ||
68 | echo -n 'New port: ' | ||
69 | read port | ||
70 | continue | ||
71 | ;; | ||
72 | SAVE) | ||
73 | echo -n 'Save file: ' | ||
74 | read saving | ||
75 | # if we've already got a page, save it | ||
76 | test "${saving}" && test -f ${TMPAGE} && | ||
77 | echo "=== ${host}:${specD}${specF} ===" >> $saving && | ||
78 | cat ${TMPAGE} >> $saving && echo '' >> $saving | ||
79 | continue | ||
80 | ;; | ||
81 | # changing the logic a bit here. Keep a state-concept of "current dir" | ||
82 | # and "current file". Dir is /foo/bar/ ; file is "baz" or null. | ||
83 | # leading slash: create whole new state. | ||
84 | /*) | ||
85 | specF=`echo "${spec}" | sed 's|.*/||'` | ||
86 | specD=`echo "${spec}" | sed 's|\(.*/\).*|\1|'` | ||
87 | spec="${specD}${specF}" | ||
88 | ;; | ||
89 | # embedded slash: adding to the path. "file" part can be blank, too | ||
90 | */*) | ||
91 | specF=`echo "${spec}" | sed 's|.*/||'` | ||
92 | specD=`echo "${specD}${spec}" | sed 's|\(.*/\).*|\1|'` | ||
93 | ;; | ||
94 | # dotdot: jump "up" one level and just reprompt [confirms what it did...] | ||
95 | ..) | ||
96 | specD=`echo "${specD}" | sed 's|\(.*/\)..*/|\1|'` | ||
97 | continue | ||
98 | ;; | ||
99 | # blank line: do nothing, which will re-get the current one | ||
100 | '') | ||
101 | ;; | ||
102 | # hack-quoted blank line: "\" means just zero out "file" part | ||
103 | '\') | ||
104 | specF='' | ||
105 | ;; | ||
106 | # sigh | ||
107 | '?') | ||
108 | echo Help yourself. Read the script fer krissake. | ||
109 | continue | ||
110 | ;; | ||
111 | # anything else is taken as a "file" part | ||
112 | *) | ||
113 | specF=${spec} | ||
114 | ;; | ||
115 | esac | ||
116 | |||
117 | # now put it together and stuff it down a connection. Some lame non-unix | ||
118 | # http servers assume they'll never get simple-query format, and wait till | ||
119 | # an extra newline arrives. If you're up against one of these, change | ||
120 | # below to (echo GET "$spec" ; echo '') | $BACKEND ... | ||
121 | spec="${specD}${specF}" | ||
122 | echo GET "${spec}" | $BACKEND $host $port > ${TMPAGE} | ||
123 | ${PAGER} ${TMPAGE} | ||
124 | |||
125 | # save in a format that still shows the URLs we hit after a de-html run | ||
126 | if test "${saving}" ; then | ||
127 | echo "=== ${host}:${spec} ===" >> $saving | ||
128 | cat ${TMPAGE} >> $saving | ||
129 | echo '' >> $saving | ||
130 | fi | ||
131 | done | ||
132 | rm -f ${TMPAGE} | ||
133 | exit 0 | ||
134 | |||
135 | ####### | ||
136 | # Encoding notes, finally from RFC 1738: | ||
137 | # %XX -- hex-encode of special chars | ||
138 | # allowed alphas in a URL: $_-.+!*'(), | ||
139 | # relative names *not* described, but obviously used all over the place | ||
140 | # transport://user:pass@host:port/path/name?query-string | ||
141 | # wais: port 210, //host:port/database?search or /database/type/file? | ||
142 | # cgi-bin/script?arg1=foo&arg2=bar&... scripts have to parse xxx&yyy&zzz | ||
143 | # ISMAP imagemap stuff: /bin/foobar.map?xxx,yyy -- have to guess at coords! | ||
144 | # local access-ctl files: ncsa: .htaccess ; cern: .www_acl | ||
145 | ####### | ||
146 | # SEARCH ENGINES: fortunately, all are GET forms or at least work that way... | ||
147 | # multi-word args for most cases: foo+bar | ||
148 | # See 'websearch' for concise results of this research... | ||
diff --git a/src/usr.bin/nc/scripts/webproxy b/src/usr.bin/nc/scripts/webproxy new file mode 100644 index 0000000000..cee2d29fd1 --- /dev/null +++ b/src/usr.bin/nc/scripts/webproxy | |||
@@ -0,0 +1,138 @@ | |||
1 | #! /bin/sh | ||
2 | ## Web proxy, following the grand tradition of Web things being handled by | ||
3 | ## gross scripts. Uses netcat to listen on a high port [default 8000], | ||
4 | ## picks apart requests and sends them on to the right place. Point this | ||
5 | ## at the browser client machine you'll be coming from [to limit access to | ||
6 | ## only it], and point the browser's concept of an HTTP proxy to the | ||
7 | ## machine running this. Takes a single argument of the client that will | ||
8 | ## be using it, and rejects connections from elsewhere. LOGS the queries | ||
9 | ## to a configurable logfile, which can be an interesting read later on! | ||
10 | ## If the argument is "reset", the listener and logfile are cleaned up. | ||
11 | ## | ||
12 | ## This works surprisingly fast and well, for a shell script, although may | ||
13 | ## randomly fail when hammered by a browser that tries to open several | ||
14 | ## connections at once. Drop the "maximum connections" in your browser if | ||
15 | ## this is a problem. | ||
16 | ## | ||
17 | ## A more degenerate case of this, or preferably a small C program that | ||
18 | ## does the same thing under inetd, could handle a small site's worth of | ||
19 | ## proxy queries. Given the way browsers are evolving, proxies like this | ||
20 | ## can play an important role in protecting your own privacy. | ||
21 | ## | ||
22 | ## If you grabbed this in ASCII mode, search down for "eew" and make sure | ||
23 | ## the embedded-CR check is intact, or requests might hang. | ||
24 | ## | ||
25 | ## Doesn't handle POST forms. Who cares, if you're just watching HTTV? | ||
26 | ## Dumbness here has a highly desirable side effect: it only sends the first | ||
27 | ## GET line, since that's all you really ever need to send, and suppresses | ||
28 | ## the other somewhat revealing trash that most browsers insist on sending. | ||
29 | |||
30 | # set these as you wish: proxy port... | ||
31 | PORT=8000 | ||
32 | # logfile spec: a real file or /dev/null if you don't care | ||
33 | LFILE=${0}.log | ||
34 | # optional: where to dump connect info, so you can see if anything went wrong | ||
35 | # CFILE=${0}.conn | ||
36 | # optional extra args to the listener "nc", for instance "-s inside-net-addr" | ||
37 | # XNC='' | ||
38 | |||
39 | # functionality switch has to be done fast, so the next listener can start | ||
40 | # prelaunch check: if no current client and no args, bail. | ||
41 | case "${1}${CLIENT}" in | ||
42 | "") | ||
43 | echo needs client hostname | ||
44 | exit 1 | ||
45 | ;; | ||
46 | esac | ||
47 | |||
48 | case "${1}" in | ||
49 | "") | ||
50 | # Make like inetd, and run the next relayer process NOW. All the redirection | ||
51 | # is necessary so this shell has NO remaining channel open to the net. | ||
52 | # This will hang around for 10 minutes, and exit if no new connections arrive. | ||
53 | # Using -n for speed, avoiding any DNS/port lookups. | ||
54 | nc -w 600 -n -l -p $PORT -e "$0" $XNC "$CLIENT" < /dev/null > /dev/null \ | ||
55 | 2> $CFILE & | ||
56 | ;; | ||
57 | esac | ||
58 | |||
59 | # no client yet and had an arg, this checking can be much slower now | ||
60 | umask 077 | ||
61 | |||
62 | if test "$1" ; then | ||
63 | # if magic arg, just clean up and then hit our own port to cause server exit | ||
64 | if test "$1" = "reset" ; then | ||
65 | rm -f $LFILE | ||
66 | test -f "$CFILE" && rm -f $CFILE | ||
67 | nc -w 1 -n 127.0.0.1 $PORT < /dev/null > /dev/null 2>&1 | ||
68 | exit 0 | ||
69 | fi | ||
70 | # find our ass with both hands | ||
71 | test ! -f "$0" && echo "Oops, cannot find my own corporeal being" && exit 1 | ||
72 | # correct launch: set up client access control, passed along thru environment. | ||
73 | CLIENT="$1" | ||
74 | export CLIENT | ||
75 | test "$CFILE" || CFILE=/dev/null | ||
76 | export CFILE | ||
77 | touch "$CFILE" | ||
78 | # tell us what happened during the last run, if possible | ||
79 | if test -f "$CFILE" ; then | ||
80 | echo "Last connection results:" | ||
81 | cat $CFILE | ||
82 | fi | ||
83 | |||
84 | # ping client machine and get its bare IP address | ||
85 | CLIENT=`nc -z -v -w 8 "$1" 22000 2>&1 | sed 's/.*\[\(..*\)\].*/\1/'` | ||
86 | test ! "$CLIENT" && echo "Can't find address of $1" && exit 1 | ||
87 | |||
88 | # if this was an initial launch, be informative about it | ||
89 | echo "=== Launch: $CLIENT" >> $LFILE | ||
90 | echo "Proxy running -- will accept connections on $PORT from $CLIENT" | ||
91 | echo " Logging queries to $LFILE" | ||
92 | test -f "$CFILE" && echo " and connection fuckups to $CFILE" | ||
93 | |||
94 | # and run the first listener, showing us output just for the first hit | ||
95 | nc -v -w 600 -n -l -p $PORT -e "$0" $XNC "$CLIENT" & | ||
96 | exit 0 | ||
97 | fi | ||
98 | |||
99 | # Fall here to handle a page. | ||
100 | # GET type://host.name:80/file/path HTTP/1.0 | ||
101 | # Additional: trash | ||
102 | # More: trash | ||
103 | # <newline> | ||
104 | |||
105 | read x1 x2 x3 x4 | ||
106 | echo "=== query: $x1 $x2 $x3 $x4" >> $LFILE | ||
107 | test "$x4" && echo "extra junk after request: $x4" && exit 0 | ||
108 | # nuke questionable characters and split up the request | ||
109 | hurl=`echo "$x2" | sed -e "s+.*//++" -e 's+[\`'\''|$;<>{}\\!*()"]++g'` | ||
110 | # echo massaged hurl: $hurl >> $LFILE | ||
111 | hh=`echo "$hurl" | sed -e "s+/.*++" -e "s+:.*++"` | ||
112 | hp=`echo "$hurl" | sed -e "s+.*:++" -e "s+/.*++"` | ||
113 | test "$hp" = "$hh" && hp=80 | ||
114 | hf=`echo "$hurl" | sed -e "s+[^/]*++"` | ||
115 | # echo total split: $hh : $hp : $hf >> $LFILE | ||
116 | # suck in and log the entire request, because we're curious | ||
117 | # Fails on multipart stuff like forms; oh well... | ||
118 | if test "$x3" ; then | ||
119 | while read xx ; do | ||
120 | echo "${xx}" >> $LFILE | ||
121 | test "${xx}" || break | ||
122 | # eew, buried returns, gross but necessary for DOS stupidity: | ||
123 | test "${xx}" = " " && break | ||
124 | done | ||
125 | fi | ||
126 | # check for non-GET *after* we log the query... | ||
127 | test "$x1" != "GET" && echo "sorry, this proxy only does GETs" && exit 0 | ||
128 | # no, you can *not* phone home, you miserable piece of shit | ||
129 | test "`echo $hh | fgrep -i netscap`" && \ | ||
130 | echo "access to Netscam's servers <b>DENIED.</b>" && exit 0 | ||
131 | # Do it. 30 sec net-wait time oughta be *plenty*... | ||
132 | # Some braindead servers have forgotten how to handle the simple-query syntax. | ||
133 | # If necessary, replace below with (echo "$x1 $hf" ; echo '') | nc... | ||
134 | echo "$x1 $hf" | nc -w 30 "$hh" "$hp" 2> /dev/null || \ | ||
135 | echo "oops, can't get to $hh : $hp". | ||
136 | echo "sent \"$x1 $hf\" to $hh : $hp" >> $LFILE | ||
137 | exit 0 | ||
138 | |||
diff --git a/src/usr.bin/nc/scripts/webrelay b/src/usr.bin/nc/scripts/webrelay new file mode 100644 index 0000000000..829a8b0708 --- /dev/null +++ b/src/usr.bin/nc/scripts/webrelay | |||
@@ -0,0 +1,44 @@ | |||
1 | #! /bin/sh | ||
2 | ## web relay -- a degenerate version of webproxy, usable with browsers that | ||
3 | ## don't understand proxies. This just forwards connections to a given server. | ||
4 | ## No query logging, no access control [although you can add it to XNC for | ||
5 | ## your own run], and full-URL links will undoubtedly confuse the browser | ||
6 | ## if it can't reach the server directly. This was actually written before | ||
7 | ## the full proxy was, and it shows. | ||
8 | ## The arguments in this case are the destination server and optional port. | ||
9 | ## Please flame pinheads who use self-referential absolute links. | ||
10 | |||
11 | # set these as you wish: proxy port... | ||
12 | PORT=8000 | ||
13 | # any extra args to the listening "nc", for instance "-s inside-net-addr" | ||
14 | XNC='' | ||
15 | |||
16 | # functionality switch, which has to be done fast to start the next listener | ||
17 | case "${1}${RDEST}" in | ||
18 | "") | ||
19 | echo needs hostname | ||
20 | exit 1 | ||
21 | ;; | ||
22 | esac | ||
23 | |||
24 | case "${1}" in | ||
25 | "") | ||
26 | # no args: fire off new relayer process NOW. Will hang around for 10 minutes | ||
27 | nc -w 600 -l -n -p $PORT -e "$0" $XNC < /dev/null > /dev/null 2>&1 & | ||
28 | # and handle this request, which will simply fail if vars not set yet. | ||
29 | exec nc -w 15 $RDEST $RPORT | ||
30 | ;; | ||
31 | esac | ||
32 | |||
33 | # Fall here for setup; this can now be slower. | ||
34 | RDEST="$1" | ||
35 | RPORT="$2" | ||
36 | test "$RPORT" || RPORT=80 | ||
37 | export RDEST RPORT | ||
38 | |||
39 | # Launch the first relayer same as above, but let its error msgs show up | ||
40 | # will hang around for a minute, and exit if no new connections arrive. | ||
41 | nc -v -w 600 -l -p $PORT -e "$0" $XNC < /dev/null > /dev/null & | ||
42 | echo \ | ||
43 | "Relay to ${RDEST}:${RPORT} running -- point your browser here on port $PORT" | ||
44 | exit 0 | ||
diff --git a/src/usr.bin/nc/scripts/websearch b/src/usr.bin/nc/scripts/websearch new file mode 100644 index 0000000000..60c3a3356a --- /dev/null +++ b/src/usr.bin/nc/scripts/websearch | |||
@@ -0,0 +1,77 @@ | |||
1 | #! /bin/sh | ||
2 | ## Hit the major search engines. Hose the [large] output to a file! | ||
3 | ## autoconverts multiple arguments into the right format for given servers -- | ||
4 | ## usually worda+wordb, with certain lame exceptions like dejanews. | ||
5 | ## Extracting and post-sorting the URLs is highly recommended... | ||
6 | ## | ||
7 | ## Altavista currently handled by a separate script; may merge at some point. | ||
8 | ## | ||
9 | ## _H* original 950824, updated 951218 and 960209 | ||
10 | |||
11 | test "${1}" = "" && echo 'Needs argument[s] to search for!' && exit 1 | ||
12 | PLUSARG="`echo $* | sed 's/ /+/g'`" | ||
13 | PIPEARG="`echo ${PLUSARG} | sed 's/+/|/g'`" | ||
14 | IFILE=/tmp/.webq.$$ | ||
15 | |||
16 | # Don't have "nc"? Get "netcat" from avian.org and add it to your toolkit. | ||
17 | doquery () { | ||
18 | echo GET "$1" | nc -v -i 1 -w 30 "$2" "$3" | ||
19 | } | ||
20 | |||
21 | # changed since original: now supplying port numbers and separator lines... | ||
22 | |||
23 | echo "=== Yahoo ===" | ||
24 | doquery "/bin/search?p=${PLUSARG}&n=300&w=w&s=a" search.yahoo.com 80 | ||
25 | |||
26 | echo '' ; echo "=== Webcrawler ===" | ||
27 | doquery "/cgi-bin/WebQuery?searchText=${PLUSARG}&maxHits=300" webcrawler.com 80 | ||
28 | |||
29 | # the infoseek lamers want "registration" before they do a real search, but... | ||
30 | echo '' ; echo "=== Infoseek ===" | ||
31 | echo " is broken." | ||
32 | # doquery "WW/IS/Titles?qt=${PLUSARG}" www2.infoseek.com 80 | ||
33 | # ... which doesn't work cuz their lame server wants the extra newlines, WITH | ||
34 | # CRLF pairs ferkrissake. Fuck 'em for now, they're hopelessly broken. If | ||
35 | # you want to play, the basic idea and query formats follow. | ||
36 | # echo "GET /WW/IS/Titles?qt=${PLUSARG}" > $IFILE | ||
37 | # echo "" >> $IFILE | ||
38 | # nc -v -w 30 guide-p.infoseek.com 80 < $IFILE | ||
39 | |||
40 | # this is kinda flakey; might have to do twice?? | ||
41 | echo '' ; echo "=== Opentext ===" | ||
42 | doquery "/omw/simplesearch?SearchFor=${PLUSARG}&mode=phrase" \ | ||
43 | search.opentext.com 80 | ||
44 | |||
45 | # looks like inktomi will only take hits=100, or defaults back to 30 | ||
46 | # we try to suppress all the stupid rating dots here, too | ||
47 | echo '' ; echo "=== Inktomi ===" | ||
48 | doquery "/query/?query=${PLUSARG}&hits=100" ink3.cs.berkeley.edu 1234 | \ | ||
49 | sed '/^<IMG ALT.*inktomi.*\.gif">$/d' | ||
50 | |||
51 | #djnews lame shit limits hits to 120 and has nonstandard format | ||
52 | echo '' ; echo "=== Dejanews ===" | ||
53 | doquery "/cgi-bin/nph-dnquery?query=${PIPEARG}+maxhits=110+format=terse+defaultOp=AND" \ | ||
54 | smithers.dejanews.com 80 | ||
55 | |||
56 | # OLD lycos: used to work until they fucking BROKE it... | ||
57 | # doquery "/cgi-bin/pursuit?query=${PLUSARG}&maxhits=300&terse=1" \ | ||
58 | # query5.lycos.cs.cmu.edu 80 | ||
59 | # NEW lycos: wants the User-agent field present in query or it returns nothing | ||
60 | # 960206: webmaster@lycos duly bitched at | ||
61 | # 960208: reply received; here's how we will now handle it: | ||
62 | echo \ | ||
63 | "GET /cgi-bin/pursuit?query=${PLUSARG}&maxhits=300&terse=terse&matchmode=and&minscore=.5 HTTP/1.x" \ | ||
64 | > $IFILE | ||
65 | echo "User-agent: *FUCK OFF*" >> $IFILE | ||
66 | echo "Why: go ask todd@pointcom.com (Todd Whitney)" >> $IFILE | ||
67 | echo '' >> $IFILE | ||
68 | echo '' ; echo "=== Lycos ===" | ||
69 | nc -v -i 1 -w 30 twelve.srv.lycos.com 80 < $IFILE | ||
70 | |||
71 | rm -f $IFILE | ||
72 | exit 0 | ||
73 | |||
74 | # CURRENTLY BROKEN [?] | ||
75 | # infoseek | ||
76 | |||
77 | # some args need to be redone to ensure whatever "and" mode applies | ||