Commit d16d6f1f d16d6f1fce477a7cc1f84d51a6d79d45baa47483 by Alain Magloire

* sieve/{exitcodes.h hmac-md5.h md5.c md5.h md5global.h}: Removed.

	* sieve/md5-rsa.c: New file, clear identiy that the algo.
	is from RSA and not GNU md5.
	* sieve/md5-rsa.h : New file.
	* sieve/Makefile.am:  added md5-rsa.[ch].
	* sieve/message.h:  lcase() change for strlower ().
	* sieve/script.c: Include md5-rsa.h.
	* sieve/sieve-gram.y: lcase changed for strlower ().
	* sieve/util.c: Remove all the unnecassary code and
	only implement strlower() and strupper().
	* sieve/util.h: Only export strlower and struppper ().
1 parent a1c387de
...@@ -25,7 +25,6 @@ SRC = \ ...@@ -25,7 +25,6 @@ SRC = \
25 comparator.c \ 25 comparator.c \
26 imparse.c \ 26 imparse.c \
27 interp.c \ 27 interp.c \
28 md5.c \
29 message.c \ 28 message.c \
30 parseaddr.c \ 29 parseaddr.c \
31 script.c \ 30 script.c \
...@@ -38,12 +37,8 @@ SRC = \ ...@@ -38,12 +37,8 @@ SRC = \
38 37
39 HDR = \ 38 HDR = \
40 comparator.h \ 39 comparator.h \
41 exitcodes.h \
42 hmac-md5.h \
43 imparse.h \ 40 imparse.h \
44 interp.h \ 41 interp.h \
45 md5.h \
46 md5global.h \
47 message.h \ 42 message.h \
48 parseaddr.h \ 43 parseaddr.h \
49 script.h \ 44 script.h \
......
1 /* exitcodes.h -- wrapper around sysextis.h
2 * $Id$
3 *
4 * Copyright (c) 1998-2000 Carnegie Mellon University. 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 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. The name "Carnegie Mellon University" must not be used to
19 * endorse or promote products derived from this software without
20 * prior written permission. For permission or any other legal
21 * details, please contact
22 * Office of Technology Transfer
23 * Carnegie Mellon University
24 * 5000 Forbes Avenue
25 * Pittsburgh, PA 15213-3890
26 * (412) 268-4387, fax: (412) 268-7395
27 * tech-transfer@andrew.cmu.edu
28 *
29 * 4. Redistributions of any form whatsoever must retain the following
30 * acknowledgment:
31 * "This product includes software developed by Computing Services
32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
33 *
34 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
41 *
42 */
43
44 /* Sendmail has some weird ideas on what constitutes permenant failure. On
45 more than one occasion, we have gotten burned by this moving users around
46 through various inadvisable means, screwing up the mailboxes file,
47 whatever.
48
49 We don't want to fail out permenantly on things like EX_USAGE, EX_SOFTWARE,
50 etc., because that generally means someone was just screwing with the mail
51 store and we don't want to lose mail.
52
53 Instead, we map these EC_* codes to EX_* codes, thereby lying to Sendmail,
54 since we don't derive any benefit from Sendmail knowing what the error was.
55 We just want it to retry all the time anyway. This way, should sendmail's
56 behavior be different and we start deriving benefit from Sendmail knowing
57 stuff, we can easily change it back.
58
59 So other code uses the EC_* error, then we maybe change it to TEMPFAIL if
60 we don't agree on whether the error should be permenant or not.
61
62 Comments below stolen from sysexits.h. */
63
64 #ifndef INCLUDED_EXITCODES_H
65 #define INCLUDED_EXITCODES_H
66
67 #include <sysexits.h>
68
69 #define EC_OK 0 /* successful termination */
70
71 #define EC_USAGE EX_TEMPFAIL /* command line usage error */
72 #define EC_DATAERR EX_DATAERR /* data format error */
73 #define EC_NOINPUT EX_TEMPFAIL /* cannot open input */
74 #define EC_NOUSER EX_NOUSER /* addressee unknown */
75 #define EC_NOHOST EX_TEMPFAIL /* host name unknown */
76 #define EC_UNAVAILABLE EX_TEMPFAIL /* service unavailable */
77 #define EC_SOFTWARE EX_TEMPFAIL /* internal software error */
78 #define EC_OSERR EX_TEMPFAIL /* system error (e.g., can't fork) */
79 #define EC_OSFILE EX_TEMPFAIL /* critical OS file missing */
80 #define EC_CANTCREAT EX_TEMPFAIL /* can't create (user) output file */
81 #define EC_IOERR EX_TEMPFAIL /* input/output error */
82 #define EC_TEMPFAIL EX_TEMPFAIL /* user is invited to retry */
83 #define EC_PROTOCOL EX_TEMPFAIL /* remote error in protocol */
84 #define EC_NOPERM EX_TEMPFAIL /* permission denied */
85 #define EC_CONFIG EX_TEMPFAIL /* configuration error */
86
87 #endif /* INCLUDED_EXITCODES_H */
1 /* hmac-md5.h -- HMAC_MD5 functions
2 */
3
4 #ifndef HMAC_MD5_H
5 #define HMAC_MD5_H 1
6
7 #define HMAC_MD5_SIZE 16
8
9 /* intermediate MD5 context */
10 typedef struct HMAC_MD5_CTX_s {
11 MD5_CTX ictx, octx;
12 } HMAC_MD5_CTX;
13
14 /* intermediate HMAC state
15 * values stored in network byte order (Big Endian)
16 */
17 typedef struct HMAC_MD5_STATE_s {
18 UINT4 istate[4];
19 UINT4 ostate[4];
20 } HMAC_MD5_STATE;
21
22 /* One step hmac computation
23 *
24 * digest may be same as text or key
25 */
26 void hmac_md5(const unsigned char *text, int text_len,
27 const unsigned char *key, int key_len,
28 unsigned char digest[HMAC_MD5_SIZE]);
29
30 /* create context from key
31 */
32 void hmac_md5_init(HMAC_MD5_CTX *hmac,
33 const unsigned char *key, int key_len);
34
35 /* precalculate intermediate state from key
36 */
37 void hmac_md5_precalc(HMAC_MD5_STATE *hmac,
38 const unsigned char *key, int key_len);
39
40 /* initialize context from intermediate state
41 */
42 void hmac_md5_import(HMAC_MD5_CTX *hmac, HMAC_MD5_STATE *state);
43
44 #define hmac_md5_update(hmac, text, text_len) MD5Update(&(hmac)->ictx, (text), (text_len))
45
46 /* finish hmac from intermediate result. Intermediate result is zeroed.
47 */
48 void hmac_md5_final(unsigned char digest[HMAC_MD5_SIZE],
49 HMAC_MD5_CTX *hmac);
50
51 #endif /* HMAC_MD5_H */
1 /* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
2 */
3
4 /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
5 rights reserved.
6
7 License to copy and use this software is granted provided that it
8 is identified as the "RSA Data Security, Inc. MD5 Message-Digest
9 Algorithm" in all material mentioning or referencing this software
10 or this function.
11
12 License is also granted to make and use derivative works provided
13 that such works are identified as "derived from the RSA Data
14 Security, Inc. MD5 Message-Digest Algorithm" in all material
15 mentioning or referencing the derived work.
16
17 RSA Data Security, Inc. makes no representations concerning either
18 the merchantability of this software or the suitability of this
19 software for any particular purpose. It is provided "as is"
20 without express or implied warranty of any kind.
21
22 These notices must be retained in any copies of any part of this
23 documentation and/or software.
24 */
25
26 /* do i need all of this just for htonl()? damn. */
27 #include <sys/types.h>
28 #include <sys/param.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31
32 #include "md5global.h"
33 #include "md5.h"
34 #include "hmac-md5.h"
35
36 /* Constants for MD5Transform routine.
37 */
38
39 #define S11 7
40 #define S12 12
41 #define S13 17
42 #define S14 22
43 #define S21 5
44 #define S22 9
45 #define S23 14
46 #define S24 20
47 #define S31 4
48 #define S32 11
49 #define S33 16
50 #define S34 23
51 #define S41 6
52 #define S42 10
53 #define S43 15
54 #define S44 21
55
56 static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
57 static void Encode PROTO_LIST
58 ((unsigned char *, UINT4 *, unsigned int));
59 static void Decode PROTO_LIST
60 ((UINT4 *, unsigned char *, unsigned int));
61 static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
62 static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
63
64 static unsigned char PADDING[64] = {
65 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
66 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
67 };
68
69 /* F, G, H and I are basic MD5 functions.
70
71 */
72 #ifdef I
73 /* This might be defined via NANA */
74 #undef I
75 #endif
76
77 #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
78 #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
79 #define H(x, y, z) ((x) ^ (y) ^ (z))
80 #define I(x, y, z) ((y) ^ ((x) | (~z)))
81
82 /* ROTATE_LEFT rotates x left n bits.
83
84 */
85
86 #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
87
88 /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
89 Rotation is separate from addition to prevent recomputation.
90 */
91
92 #define FF(a, b, c, d, x, s, ac) { (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
93 #define GG(a, b, c, d, x, s, ac) { (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
94 #define HH(a, b, c, d, x, s, ac) { (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
95 #define II(a, b, c, d, x, s, ac) { (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
96
97 /* MD5 initialization. Begins an MD5 operation, writing a new context.
98 */
99
100 void MD5Init (context)
101 MD5_CTX *context; /* context */
102 {
103 context->count[0] = context->count[1] = 0;
104
105 /* Load magic initialization constants.
106
107 */
108 context->state[0] = 0x67452301;
109 context->state[1] = 0xefcdab89;
110 context->state[2] = 0x98badcfe;
111 context->state[3] = 0x10325476;
112 }
113
114 /* MD5 block update operation. Continues an MD5 message-digest
115 operation, processing another message block, and updating the context.
116 */
117
118 void MD5Update (context, input, inputLen)
119 MD5_CTX *context; /* context */
120 unsigned char *input; /* input block */
121 unsigned int inputLen; /* length of input block */
122 {
123 unsigned int i, index, partLen;
124
125 /* Compute number of bytes mod 64 */
126 index = (unsigned int)((context->count[0] >> 3) & 0x3F);
127
128 /* Update number of bits */
129 if ((context->count[0] += ((UINT4)inputLen << 3))
130 < ((UINT4)inputLen << 3))
131 context->count[1]++;
132 context->count[1] += ((UINT4)inputLen >> 29);
133
134 partLen = 64 - index;
135
136 /* Transform as many times as possible.
137
138 */
139 if (inputLen >= partLen) {
140 MD5_memcpy
141 ((POINTER)&context->buffer[index], (POINTER)input, partLen); MD5Transform
142 (context->state, context->buffer);
143
144 for (i = partLen; i + 63 < inputLen; i += 64)
145 MD5Transform (context->state, &input[i]);
146
147 index = 0;
148 }
149 else
150 i = 0;
151
152 /* Buffer remaining input */
153 MD5_memcpy
154 ((POINTER)&context->buffer[index], (POINTER)&input[i],
155 inputLen-i);
156
157 }
158
159 /* MD5 finalization. Ends an MD5 message-digest operation, writing the
160 the message digest and zeroizing the context.
161
162 */
163
164 void MD5Final (digest, context)
165 unsigned char digest[16]; /* message digest */
166 MD5_CTX *context; /* context */
167 {
168 unsigned char bits[8];
169 unsigned int index, padLen;
170
171 /* Save number of bits */
172 Encode (bits, context->count, 8);
173
174 /* Pad out to 56 mod 64.
175
176 */
177 index = (unsigned int)((context->count[0] >> 3) & 0x3f);
178 padLen = (index < 56) ? (56 - index) : (120 - index);
179 MD5Update (context, PADDING, padLen);
180
181 /* Append length (before padding) */
182 MD5Update (context, bits, 8);
183
184 /* Store state in digest */
185 Encode (digest, context->state, 16);
186
187 /* Zeroize sensitive information.
188
189 */
190 MD5_memset ((POINTER)context, 0, sizeof (*context));
191 }
192
193 /* MD5 basic transformation. Transforms state based on block.
194
195 */
196
197 static void MD5Transform (state, block)
198 UINT4 state[4];
199 unsigned char block[64];
200 {
201 UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
202
203 Decode (x, block, 64);
204
205 /* Round 1 */
206 FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
207 FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
208 FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
209 FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
210 FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
211 FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
212 FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
213 FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
214 FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
215 FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
216 FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
217 FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
218 FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
219 FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
220 FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
221 FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
222
223 /* Round 2 */
224 GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
225 GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
226 GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
227 GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
228 GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
229 GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
230 GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
231 GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
232 GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
233 GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
234 GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
235 GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
236 GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
237 GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
238 GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
239 GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
240
241 /* Round 3 */
242 HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
243 HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
244 HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
245 HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
246 HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
247 HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
248 HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
249 HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
250 HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
251 HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
252 HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
253 HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
254 HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
255 HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
256 HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
257 HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
258
259 /* Round 4 */
260 II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
261 II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
262 II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
263 II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
264 II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
265 II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
266 II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
267 II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
268 II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
269 II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
270 II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
271 II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
272 II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
273 II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
274 II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
275 II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
276
277 state[0] += a;
278 state[1] += b;
279 state[2] += c;
280 state[3] += d;
281
282 /* Zeroize sensitive information.
283 */
284 MD5_memset ((POINTER)x, 0, sizeof (x));
285 }
286
287 /* Encodes input (UINT4) into output (unsigned char). Assumes len is
288 a multiple of 4.
289
290 */
291
292 static void Encode (output, input, len)
293 unsigned char *output;
294 UINT4 *input;
295 unsigned int len;
296 {
297 unsigned int i, j;
298
299 for (i = 0, j = 0; j < len; i++, j += 4) {
300 output[j] = (unsigned char)(input[i] & 0xff);
301 output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
302 output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
303 output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
304 }
305 }
306
307 /* Decodes input (unsigned char) into output (UINT4). Assumes len is
308 a multiple of 4.
309
310 */
311
312 static void Decode (output, input, len)
313 UINT4 *output;
314 unsigned char *input;
315 unsigned int len;
316 {
317 unsigned int i, j;
318
319 for (i = 0, j = 0; j < len; i++, j += 4)
320 output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | (((UINT4)input[j+2]) << 16)
321 | (((UINT4)input[j+3]) << 24);
322 }
323
324 /* Note: Replace "for loop" with standard memcpy if possible.
325
326 */
327
328 static void MD5_memcpy (output, input, len)
329 POINTER output;
330 POINTER input;
331 unsigned int len;
332 {
333 unsigned int i;
334
335 for (i = 0; i < len; i++)
336 output[i] = input[i];
337 }
338
339 /* Note: Replace "for loop" with standard memset if possible.
340 */
341
342 static void MD5_memset (output, value, len)
343 POINTER output;
344 int value;
345 unsigned int len;
346 {
347 unsigned int i;
348
349 for (i = 0; i < len; i++)
350 ((char *)output)[i] = (char)value;
351 }
352
353 void hmac_md5_init(HMAC_MD5_CTX *hmac,
354 const unsigned char *key,
355 int key_len)
356 {
357 unsigned char k_ipad[65]; /* inner padding -
358 * key XORd with ipad
359 */
360 unsigned char k_opad[65]; /* outer padding -
361 * key XORd with opad
362 */
363 unsigned char tk[16];
364 int i;
365 /* if key is longer than 64 bytes reset it to key=MD5(key) */
366 if (key_len > 64) {
367
368 MD5_CTX tctx;
369
370 MD5Init(&tctx);
371 MD5Update(&tctx, key, key_len);
372 MD5Final(tk, &tctx);
373
374 key = tk;
375 key_len = 16;
376 }
377
378 /*
379 * the HMAC_MD5 transform looks like:
380 *
381 * MD5(K XOR opad, MD5(K XOR ipad, text))
382 *
383 * where K is an n byte key
384 * ipad is the byte 0x36 repeated 64 times
385 * opad is the byte 0x5c repeated 64 times
386 * and text is the data being protected
387 */
388
389 /* start out by storing key in pads */
390 MD5_memset(k_ipad, '\0', sizeof k_ipad);
391 MD5_memset(k_opad, '\0', sizeof k_opad);
392 MD5_memcpy( k_ipad, key, key_len);
393 MD5_memcpy( k_opad, key, key_len);
394
395 /* XOR key with ipad and opad values */
396 for (i=0; i<64; i++) {
397 k_ipad[i] ^= 0x36;
398 k_opad[i] ^= 0x5c;
399 }
400
401 MD5Init(&hmac->ictx); /* init inner context */
402 MD5Update(&hmac->ictx, k_ipad, 64); /* apply inner pad */
403
404 MD5Init(&hmac->octx); /* init outer context */
405 MD5Update(&hmac->octx, k_opad, 64); /* apply outer pad */
406
407 /* scrub the pads and key context (if used) */
408 MD5_memset(&k_ipad, 0, sizeof(k_ipad));
409 MD5_memset(&k_opad, 0, sizeof(k_opad));
410 MD5_memset(&tk, 0, sizeof(tk));
411
412 /* and we're done. */
413 }
414
415 /* The precalc and import routines here rely on the fact that we pad
416 * the key out to 64 bytes and use that to initialize the md5
417 * contexts, and that updating an md5 context with 64 bytes of data
418 * leaves nothing left over; all of the interesting state is contained
419 * in the state field, and none of it is left over in the count and
420 * buffer fields. So all we have to do is save the state field; we
421 * can zero the others when we reload it. Which is why the decision
422 * was made to pad the key out to 64 bytes in the first place. */
423 void hmac_md5_precalc(HMAC_MD5_STATE *state,
424 const unsigned char *key,
425 int key_len)
426 {
427 HMAC_MD5_CTX hmac;
428 unsigned lupe;
429
430 hmac_md5_init(&hmac, key, key_len);
431 for (lupe = 0; lupe < 4; lupe++) {
432 state->istate[lupe] = htonl(hmac.ictx.state[lupe]);
433 state->ostate[lupe] = htonl(hmac.octx.state[lupe]);
434 }
435 MD5_memset(&hmac, 0, sizeof(hmac));
436 }
437
438
439 void hmac_md5_import(HMAC_MD5_CTX *hmac,
440 HMAC_MD5_STATE *state)
441 {
442 unsigned lupe;
443 MD5_memset(hmac, 0, sizeof(HMAC_MD5_CTX));
444 for (lupe = 0; lupe < 4; lupe++) {
445 hmac->ictx.state[lupe] = ntohl(state->istate[lupe]);
446 hmac->octx.state[lupe] = ntohl(state->ostate[lupe]);
447 }
448 /* Init the counts to account for our having applied
449 * 64 bytes of key; this works out to 0x200 (64 << 3; see
450 * MD5Update above...) */
451 hmac->ictx.count[0] = hmac->octx.count[0] = 0x200;
452 }
453
454 void hmac_md5_final(unsigned char digest[HMAC_MD5_SIZE],
455 HMAC_MD5_CTX *hmac)
456 {
457 MD5Final(digest, &hmac->ictx); /* Finalize inner md5 */
458 MD5Update(&hmac->octx, digest, 16); /* Update outer ctx */
459 MD5Final(digest, &hmac->octx); /* Finalize outer md5 */
460 }
461
462
463 void hmac_md5(text, text_len, key, key_len, digest)
464 const unsigned char* text; /* pointer to data stream */
465 int text_len; /* length of data stream */
466 const unsigned char* key; /* pointer to authentication key */
467 int key_len; /* length of authentication key */
468 unsigned char *digest; /* caller digest to be filled in */
469 {
470 MD5_CTX context;
471
472 unsigned char k_ipad[65]; /* inner padding -
473 * key XORd with ipad
474 */
475 unsigned char k_opad[65]; /* outer padding -
476 * key XORd with opad
477 */
478 unsigned char tk[16];
479 int i;
480 /* if key is longer than 64 bytes reset it to key=MD5(key) */
481 if (key_len > 64) {
482
483 MD5_CTX tctx;
484
485 MD5Init(&tctx);
486 MD5Update(&tctx, key, key_len);
487 MD5Final(tk, &tctx);
488
489 key = tk;
490 key_len = 16;
491 }
492
493 /*
494 * the HMAC_MD5 transform looks like:
495 *
496 * MD5(K XOR opad, MD5(K XOR ipad, text))
497 *
498 * where K is an n byte key
499 * ipad is the byte 0x36 repeated 64 times
500 * opad is the byte 0x5c repeated 64 times
501 * and text is the data being protected
502 */
503
504 /* start out by storing key in pads */
505 MD5_memset(k_ipad, '\0', sizeof k_ipad);
506 MD5_memset(k_opad, '\0', sizeof k_opad);
507 MD5_memcpy( k_ipad, key, key_len);
508 MD5_memcpy( k_opad, key, key_len);
509
510 /* XOR key with ipad and opad values */
511 for (i=0; i<64; i++) {
512 k_ipad[i] ^= 0x36;
513 k_opad[i] ^= 0x5c;
514 }
515 /*
516 * perform inner MD5
517 */
518
519 MD5Init(&context); /* init context for 1st
520 * pass */
521 MD5Update(&context, k_ipad, 64); /* start with inner pad */
522 MD5Update(&context, text, text_len); /* then text of datagram */
523 MD5Final(digest, &context); /* finish up 1st pass */
524
525 /*
526 * perform outer MD5
527 */
528 MD5Init(&context); /* init context for 2nd
529 * pass */
530 MD5Update(&context, k_opad, 64); /* start with outer pad */
531 MD5Update(&context, digest, 16); /* then results of 1st
532 * hash */
533 MD5Final(digest, &context); /* finish up 2nd pass */
534
535 }
1 /* MD5.H - header file for MD5C.C
2 */
3
4 /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
5 rights reserved.
6
7 License to copy and use this software is granted provided that it
8 is identified as the "RSA Data Security, Inc. MD5 Message-Digest
9 Algorithm" in all material mentioning or referencing this software
10 or this function.
11
12 License is also granted to make and use derivative works provided
13 that such works are identified as "derived from the RSA Data
14 Security, Inc. MD5 Message-Digest Algorithm" in all material
15 mentioning or referencing the derived work.
16
17 RSA Data Security, Inc. makes no representations concerning either
18 the merchantability of this software or the suitability of this
19 software for any particular purpose. It is provided "as is"
20 without express or implied warranty of any kind.
21 These notices must be retained in any copies of any part of this
22 documentation and/or software.
23 */
24
25 /* MD5 context. */
26 typedef struct {
27 UINT4 state[4]; /* state (ABCD) */
28 UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
29 unsigned char buffer[64]; /* input buffer */
30 } MD5_CTX;
31
32 void MD5Init PROTO_LIST ((MD5_CTX *));
33 void MD5Update PROTO_LIST
34 ((MD5_CTX *, unsigned char *, unsigned int));
35 void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
36
37 void hmac_md5 PROTO_LIST ((unsigned char *, int, unsigned char *, int, unsigned char*));
1 /* GLOBAL.H - RSAREF types and constants
2 */
3
4 /* PROTOTYPES should be set to one if and only if the compiler supports
5 function argument prototyping.
6 The following makes PROTOTYPES default to 0 if it has not already
7 been defined with C compiler flags.
8 */
9 #ifndef PROTOTYPES
10 #define PROTOTYPES 0
11 #endif
12
13 /* POINTER defines a generic pointer type */
14 typedef unsigned char *POINTER;
15
16 /* UINT2 defines a two byte word */
17 typedef unsigned short int UINT2;
18
19 /* UINT4 defines a four byte word */
20 typedef unsigned long int UINT4;
21
22 /* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
23 If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
24 returns an empty list.
25 */
26 #if PROTOTYPES
27 #define PROTO_LIST(list) list
28 #else
29 #define PROTO_LIST(list) ()
30 #endif
31
...@@ -480,7 +480,7 @@ char *get_address(address_part_t addrpart, void **data, void **marker, ...@@ -480,7 +480,7 @@ char *get_address(address_part_t addrpart, void **data, void **marker,
480 ret = NULL; 480 ret = NULL;
481 } else { 481 } else {
482 if (canon_domain && a->domain) 482 if (canon_domain && a->domain)
483 lcase(a->domain); 483 strlower (a->domain);
484 484
485 switch (addrpart) { 485 switch (addrpart) {
486 case ADDRESS_ALL: 486 case ADDRESS_ALL:
......
...@@ -31,8 +31,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -31,8 +31,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 31
32 #include <stdlib.h> 32 #include <stdlib.h>
33 #include <string.h> 33 #include <string.h>
34 #include <md5global.h> 34 #include <md5-rsa.h>
35 #include <md5.h>
36 #include <ctype.h> 35 #include <ctype.h>
37 #ifdef HAVE_STRINGS_H 36 #ifdef HAVE_STRINGS_H
38 # include <strings.h> 37 # include <strings.h>
......
...@@ -630,7 +630,7 @@ static int verify_flag(char *f) ...@@ -630,7 +630,7 @@ static int verify_flag(char *f)
630 char errbuf[100]; 630 char errbuf[100];
631 631
632 if (f[0] == '\\') { 632 if (f[0] == '\\') {
633 lcase(f); 633 strlower(f);
634 if (strcmp(f, "\\seen") && strcmp(f, "\\answered") && 634 if (strcmp(f, "\\seen") && strcmp(f, "\\answered") &&
635 strcmp(f, "\\flagged") && strcmp(f, "\\draft") && 635 strcmp(f, "\\flagged") && strcmp(f, "\\draft") &&
636 strcmp(f, "\\deleted")) { 636 strcmp(f, "\\deleted")) {
......
1 /* util.c -- general utility functions 1 /* GNU mailutils - a suite of utilities for electronic mail
2 * 2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3 * Copyright (c) 1998-2000 Carnegie Mellon University. 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 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. The name "Carnegie Mellon University" must not be used to
18 * endorse or promote products derived from this software without
19 * prior written permission. For permission or any other legal
20 * details, please contact
21 * Office of Technology Transfer
22 * Carnegie Mellon University
23 * 5000 Forbes Avenue
24 * Pittsburgh, PA 15213-3890
25 * (412) 268-4387, fax: (412) 268-7395
26 * tech-transfer@andrew.cmu.edu
27 *
28 * 4. Redistributions of any form whatsoever must retain the following
29 * acknowledgment:
30 * "This product includes software developed by Computing Services
31 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
32 *
33 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
34 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
35 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
36 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
37 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
38 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
39 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
40 *
41 * Author: Chris Newman
42 * Start Date: 4/6/93
43 */
44 /* $Id$
45 */
46 3
47 #include <config.h> 4 This program is free software; you can redistribute it and/or modify
48 #include <stdio.h> 5 it under the terms of the GNU General Library Public License as published by
49 #include <ctype.h> 6 the Free Software Foundation; either version 2, or (at your option)
50 #include <string.h> 7 any later version.
51 #include "util.h"
52
53 /* from OS: */
54 extern char *malloc(), *realloc();
55
56 #define BEAUTYBUFSIZE 4096
57
58 const unsigned char convert_to_lowercase[256] = {
59 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
60 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
61 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
62 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
63 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
64 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
65 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
66 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
67 0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
68 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
69 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
70 'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
71 0x60, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
72 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
73 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
74 'x', 'y', 'z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
75 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
76 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
77 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
78 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
79 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
80 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
81 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
82 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
83 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
84 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
85 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
86 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
87 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
88 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
89 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
90 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
91 };
92
93 const unsigned char convert_to_uppercase[256] = {
94 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
95 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
96 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
97 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
98 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
99 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
100 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
101 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
102 0x40, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
103 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
104 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
105 'X', 'Y', 'Z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
106 0x60, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
107 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
108 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
109 'X', 'Y', 'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
110 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
111 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
112 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
113 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
114 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
115 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
116 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
117 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
118 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
119 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
120 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
121 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
122 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
123 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
124 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
125 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
126 };
127
128 /* convert string to all lower case
129 */
130 char *lcase(char* str)
131 {
132 char *scan = str;
133
134 while (*scan) {
135 *scan = TOLOWER(*scan);
136 scan++;
137 }
138
139 return (str);
140 }
141
142 /* convert string to all upper case
143 */
144 char *ucase(char* str)
145 {
146 char *scan = str;
147
148 while (*scan) {
149 *scan = convert_to_uppercase[(unsigned char)(*scan)];
150 scan++;
151 }
152
153 return (str);
154 }
155 8
156 /* clean up control characters in a string while copying it 9 This program is distributed in the hope that it will be useful,
157 * returns pointer to end of dst string. 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
158 * dst must have twice the length of source 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
159 */ 12 GNU Library General Public License for more details.
160 char *beautify_copy(char* dst, const char* src)
161 {
162 unsigned char c;
163
164 while (*src) {
165 c = *src++ & 0x7F;
166 if (!isprint(c)) {
167 *dst++ = '^';
168 if (c > ' ') {
169 c = '?';
170 } else {
171 c += '@';
172 }
173 }
174 *dst++ = c;
175 }
176 *dst = '\0';
177 13
178 return (dst); 14 You should have received a copy of the GNU Library General Public License
179 } 15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
180 17
18 #include <util.h>
19 #include <ctype.h>
181 20
182 /* clean up control characters in a string while copying it 21 char *
183 * returns pointer to a static buffer containing the cleaned-up version 22 strupper (char *s)
184 * returns NULL on malloc() error
185 */
186 char *beautify_string(const char* src)
187 { 23 {
188 static char *beautybuf = NULL; 24 char *t = s;
189 static int beautysize = 0;
190 int len;
191 25
192 len = strlen(src) * 2 + 1; 26 while (*t)
193 if (beautysize < len) { 27 {
194 if (!beautysize) { 28 if (islower ((unsigned)*t))
195 beautysize = len > BEAUTYBUFSIZE ? len : BEAUTYBUFSIZE; 29 *t = toupper ((unsigned)*t);
196 beautybuf = malloc(beautysize); 30 t++;
197 } else {
198 beautysize *= 2;
199 if (len > beautysize) beautysize = len;
200 beautybuf = realloc(beautybuf, beautysize);
201 }
202 if (!beautybuf) {
203 beautysize = 0;
204 return "";
205 } 31 }
206 } 32 return s;
207 (void) beautify_copy(beautybuf, src);
208
209 return (beautybuf);
210 } 33 }
211 34
212 /* do a binary search in a keyvalue array 35 char *
213 * nelem is the number of keyvalue elements in the kv array 36 strlower (char *s)
214 * cmpf is the comparison function (strcmp, strcasecmp, etc).
215 * returns NULL if not found, or key/value pair if found.
216 */
217 keyvalue *kv_bsearch(const char* key, keyvalue* kv, int nelem,
218 int (*cmpf) (const char *s1, const char *s2))
219 { 37 {
220 int top, mid = 0, bot, cmp = 0; 38 char *t = s;
221 39
222 cmp = 1; 40 while (*t)
223 bot = 0; 41 {
224 top = nelem - 1; 42 if (isupper ((unsigned)*t))
225 while (top >= bot && (cmp = (*cmpf)(key, kv[mid = (bot + top) >> 1].key))) 43 *t = tolower ((unsigned)*t);
226 if (cmp < 0) { 44 t++;
227 top = mid - 1;
228 } else {
229 bot = mid + 1;
230 } 45 }
231 46 return s;
232 return (cmp ? NULL : kv + mid);
233 } 47 }
......
1 /* util.h -- general utility functions 1 /* GNU mailutils - a suite of utilities for electronic mail
2 * $Id$ 2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3 *
4 * Copyright (c) 1999-2000 Carnegie Mellon University. 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 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. The name "Carnegie Mellon University" must not be used to
19 * endorse or promote products derived from this software without
20 * prior written permission. For permission or any other legal
21 * details, please contact
22 * Office of Technology Transfer
23 * Carnegie Mellon University
24 * 5000 Forbes Avenue
25 * Pittsburgh, PA 15213-3890
26 * (412) 268-4387, fax: (412) 268-7395
27 * tech-transfer@andrew.cmu.edu
28 *
29 * 4. Redistributions of any form whatsoever must retain the following
30 * acknowledgment:
31 * "This product includes software developed by Computing Services
32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
33 *
34 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
41 *
42 * Author: Chris Newman
43 * Start Date: 4/6/93
44 */
45 3
46 #ifndef INCLUDED_UTIL_H 4 This program is free software; you can redistribute it and/or modify
47 #define INCLUDED_UTIL_H 5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
48 8
49 extern const unsigned char convert_to_lowercase[256]; 9 This program is distributed in the hope that it will be useful,
50 extern const unsigned char convert_to_uppercase[256]; 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
51 13
52 #define TOUPPER(c) (convert_to_uppercase[(unsigned char)(c)]) 14 You should have received a copy of the GNU Library General Public License
53 #define TOLOWER(c) (convert_to_lowercase[(unsigned char)(c)]) 15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
54 17
55 typedef struct keyvalue { 18 #ifndef INCLUDED_UTIL_H
56 char *key, *value; 19 #define INCLUDED_UTIL_H
57 } keyvalue;
58 20
59 /* convert string to all lower case 21 /* convert string to all lower case
60 */ 22 */
61 extern char *lcase (char *str); 23 extern char *strlower (char *str);
62 24
63 /* convert string to all upper case 25 /* convert string to all upper case
64 */ 26 */
65 extern char *ucase (char *str); 27 extern char *strupper (char *str);
66
67 /* clean up control characters in a string while copying it
68 * returns pointer to end of dst string.
69 * dst must have twice the length of source
70 */
71 extern char *beautify_copy (char *dst, const char *src);
72
73 /* clean up control characters in a string while copying it
74 * returns pointer to a static buffer containing the cleaned-up version
75 * returns NULL on malloc() error
76 */
77 extern char *beautify_string (const char *src);
78
79 /* do a binary search in a keyvalue array
80 * nelem is the number of keyvalue elements in the kv array
81 * cmpf is the comparison function (strcmp, stricmp, etc).
82 * returns NULL if not found, or key/value pair if found.
83 */
84 extern keyvalue *kv_bsearch (const char *key, keyvalue *kv, int nelem,
85 int (*cmpf)(const char *s1, const char *s2));
86 28
87 #endif /* INCLUDED_UTIL_H */ 29 #endif /* INCLUDED_UTIL_H */
......