coar 99/08/02 13:50:23
Modified: src/ap ap_sha1.c src/include ap.h ap_md5.h ap_sha1.h src/main http_main.c src/modules/standard mod_auth.c mod_auth_db.c mod_auth_dbm.c Removed: src/include ap_checkpass.h Log: Fix some spacing issues in the SHA1 and ap_validate_password changes. ap_validate_password() isn't called by anything in the core, so the link may well omit it -- causing DSO mod_auth* modules to fail to load. Force a reference to it into the core server so that won't happen. As soon as ap_checkpass.c includes any other symbols routinely referenced by the core, the kludge at the bottom of http_main.c can go away. Or earlier, if someone finds a better solution. Revision Changes Path 1.2 +100 -91 apache-1.3/src/ap/ap_sha1.c Index: ap_sha1.c =================================================================== RCS file: /home/cvs/apache-1.3/src/ap/ap_sha1.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ap_sha1.c 1999/08/02 10:13:44 1.1 +++ ap_sha1.c 1999/08/02 20:50:12 1.2 @@ -55,7 +55,7 @@ * * The only exported function: * - * ap_sha1_base64(char *clear, int len, char *out); + * ap_sha1_base64(const char *clear, int len, char *out); * * provides a means to SHA1 crypt/encode a plaintext password in * a way which makes password files compatible with those commonly @@ -140,19 +140,19 @@ #define SHA_DIGESTSIZE 20 typedef struct { - LONG digest[5]; /* message digest */ - LONG count_lo, count_hi; /* 64-bit bit count */ - LONG data[16]; /* SHA data buffer */ - int local; /* unprocessed amount in data */ - } SHA_INFO; - -void sha_init(SHA_INFO *); -void sha_update(SHA_INFO *, BYTE *, int); -void sha_final(SHA_INFO *); -void sha_raw_swap(SHA_INFO *); -void output64chunk(unsigned char, unsigned char, unsigned char, - int, unsigned char **); -void encode_mime64(unsigned char *, unsigned char *, int); + LONG digest[5]; /* message digest */ + LONG count_lo, count_hi; /* 64-bit bit count */ + LONG data[16]; /* SHA data buffer */ + int local; /* unprocessed amount in data */ +} SHA_INFO; + +static void sha_init(SHA_INFO *); +static void sha_update(SHA_INFO *, const BYTE *, int); +static void sha_final(SHA_INFO *); +static void sha_raw_swap(SHA_INFO *); +static void output64chunk(unsigned char, unsigned char, unsigned char, + int, unsigned char **); +static void encode_mime64(unsigned char *, unsigned char *, int); void sha1_base64(char *, int, char *); /* do SHA transformation */ @@ -217,14 +217,15 @@ } union endianTest { - long Long; - char Char[sizeof(long)]; + long Long; + char Char[sizeof(long)]; }; -char isLittleEndian() { - static union endianTest u; - u.Long = 1; - return(u.Char[0]==1); +static char isLittleEndian(void) +{ + static union endianTest u; + u.Long = 1; + return (u.Char[0] == 1); } /* change endianness of data */ @@ -236,25 +237,25 @@ BYTE ct[4], *cp; if (isLittleEndian()) { /* do the swap only if it is little endian */ - count /= sizeof(LONG); - cp = (BYTE *) buffer; - for (i = 0; i < count; ++i) { - ct[0] = cp[0]; - ct[1] = cp[1]; - ct[2] = cp[2]; - ct[3] = cp[3]; - cp[0] = ct[3]; - cp[1] = ct[2]; - cp[2] = ct[1]; - cp[3] = ct[0]; - cp += sizeof(LONG); - } + count /= sizeof(LONG); + cp = (BYTE *) buffer; + for (i = 0; i < count; ++i) { + ct[0] = cp[0]; + ct[1] = cp[1]; + ct[2] = cp[2]; + ct[3] = cp[3]; + cp[0] = ct[3]; + cp[1] = ct[2]; + cp[2] = ct[1]; + cp[3] = ct[0]; + cp += sizeof(LONG); + } } } /* initialize the SHA digest */ -void sha_init(SHA_INFO *sha_info) +static void sha_init(SHA_INFO *sha_info) { sha_info->digest[0] = 0x67452301L; sha_info->digest[1] = 0xefcdab89L; @@ -268,7 +269,7 @@ /* update the SHA digest */ -void sha_update(SHA_INFO *sha_info, BYTE *buffer, int count) +static void sha_update(SHA_INFO *sha_info, const BYTE *buffer, int count) { int i; @@ -289,7 +290,8 @@ if (sha_info->local == SHA_BLOCKSIZE) { maybe_byte_reverse(sha_info->data, SHA_BLOCKSIZE); sha_transform(sha_info); - } else { + } + else { return; } } @@ -306,7 +308,7 @@ /* finish computing the SHA digest */ -void sha_final(SHA_INFO *sha_info) +static void sha_final(SHA_INFO *sha_info) { int count; LONG lo_bit_count, hi_bit_count; @@ -320,15 +322,15 @@ maybe_byte_reverse(sha_info->data, SHA_BLOCKSIZE); sha_transform(sha_info); memset((BYTE *) sha_info->data, 0, SHA_BLOCKSIZE - 8); - } else { + } + else { memset(((BYTE *) sha_info->data) + count, 0, - SHA_BLOCKSIZE - 8 - count); + SHA_BLOCKSIZE - 8 - count); } maybe_byte_reverse(sha_info->data, SHA_BLOCKSIZE); sha_info->data[14] = hi_bit_count; sha_info->data[15] = lo_bit_count; sha_transform(sha_info); - } /* @@ -337,75 +339,82 @@ through with arrays of longs. */ -void sha_raw_swap(SHA_INFO *sha_info) { - int i; +static void sha_raw_swap(SHA_INFO *sha_info) +{ + int i; - for (i=0; i<5; ++i) - maybe_byte_reverse((LONG *) &sha_info->digest[i], 4); + for (i = 0; i < 5; ++i) { + maybe_byte_reverse((LONG *) &sha_info->digest[i], 4); + } } static char basis_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -void output64chunk(unsigned char c1, unsigned char c2, unsigned char c3, - int pads, unsigned char **outfile) { - *(*outfile)++ = basis_64[c1>>2]; +static void output64chunk(unsigned char c1, unsigned char c2, unsigned char c3, + int pads, unsigned char **outfile) +{ + *(*outfile)++ = basis_64[c1>>2]; - *(*outfile)++ = basis_64[((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)]; - if (pads == 2) { - *(*outfile)++ = '='; - *(*outfile)++ = '='; - } else if (pads) { - *(*outfile)++ = basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)]; - *(*outfile)++ = '='; - } else { - *(*outfile)++ = basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)]; - *(*outfile)++ = basis_64[c3 & 0x3F]; - } + *(*outfile)++ = basis_64[((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)]; + if (pads == 2) { + *(*outfile)++ = '='; + *(*outfile)++ = '='; + } + else if (pads) { + *(*outfile)++ = basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)]; + *(*outfile)++ = '='; + } + else { + *(*outfile)++ = basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)]; + *(*outfile)++ = basis_64[c3 & 0x3F]; + } } -void encode_mime64(unsigned char *in, unsigned char *out, int length) { - int diff, ct=0; +static void encode_mime64(unsigned char *in, unsigned char *out, int length) +{ + int diff, ct = 0; - while ( (diff= length - ct) ) { - if ( diff >= 3 ) { - diff = 3; - output64chunk(in[ct], in[ct+1], in[ct+2], 0, &out); - } - else if ( diff == 2 ) { - output64chunk(in[ct], in[ct+1], 0, 1, &out); - } - else if ( diff == 1 ) { - output64chunk(in[ct], 0, 0, 2, &out); + while ((diff = length - ct)) { + if ( diff >= 3 ) { + diff = 3; + output64chunk(in[ct], in[ct+1], in[ct+2], 0, &out); + } + else if (diff == 2) { + output64chunk(in[ct], in[ct+1], 0, 1, &out); + } + else if (diff == 1) { + output64chunk(in[ct], 0, 0, 2, &out); + } + ct += diff; } - ct += diff; - } - - *out++ = 0; + *out++ = 0; } /* {SHA} is the prefix used for base64 encoded sha1 in * ldap data interchange format. */ const char *sha1_id = "{SHA}"; + +API_EXPORT(void) ap_sha1_base64(const char *clear, int len, char *out) +{ + SHA_INFO context; + + if (!strncmp(clear, sha1_id, strlen(sha1_id))) { + clear += strlen(sha1_id); + } + + sha_init(&context); + sha_update(&context, clear, len); + sha_final(&context); -API_EXPORT(void) ap_sha1_base64(char *clear, int len, char *out) { - SHA_INFO context; + sha_raw_swap(&context); - if (!strncmp(clear,sha1_id,strlen(sha1_id))) - clear+=strlen(sha1_id); + /* private marker. */ + strcpy(out, sha1_id); - sha_init(&context); - sha_update(&context, clear, len); - sha_final(&context); - - sha_raw_swap(&context); - - /* private marker. */ - strcpy(out,sha1_id); - - /* SHA1 hash is always 20 chars */ - encode_mime64((char *)context.digest, out+strlen(sha1_id), 20); - /* output of MIME Base 64 encoded SHA1 is always 28 characters + strlen(sha1_id) */ + /* SHA1 hash is always 20 chars */ + encode_mime64((char *)context.digest, out+strlen(sha1_id), 20); + /* output of MIME Base 64 encoded SHA1 is always + * 28 characters + strlen(sha1_id) */ } 1.22 +1 -0 apache-1.3/src/include/ap.h Index: ap.h =================================================================== RCS file: /home/cvs/apache-1.3/src/include/ap.h,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- ap.h 1999/05/31 17:09:31 1.21 +++ ap.h 1999/08/02 20:50:14 1.22 @@ -159,6 +159,7 @@ __attribute__((format(printf,3,4))); API_EXPORT(int) ap_vsnprintf(char *buf, size_t len, const char *format, va_list ap); +API_EXPORT(char *) ap_validate_password(const char *passwd, const char *hash); #ifdef __cplusplus } 1.7 +0 -1 apache-1.3/src/include/ap_md5.h Index: ap_md5.h =================================================================== RCS file: /home/cvs/apache-1.3/src/include/ap_md5.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ap_md5.h 1999/08/02 10:13:45 1.6 +++ ap_md5.h 1999/08/02 20:50:14 1.7 @@ -114,7 +114,6 @@ const unsigned char *salt, char *result, size_t nbytes); API_EXPORT(void) ap_to64(char *s, unsigned long v, int n); -API_EXPORT(char *) ap_validate_password(const char *passwd, const char *hash); #ifdef __cplusplus } 1.2 +2 -2 apache-1.3/src/include/ap_sha1.h Index: ap_sha1.h =================================================================== RCS file: /home/cvs/apache-1.3/src/include/ap_sha1.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ap_sha1.h 1999/08/02 10:13:46 1.1 +++ ap_sha1.h 1999/08/02 20:50:15 1.2 @@ -84,8 +84,8 @@ extern "C" { #endif -const char * sha1_id; /* passwd prefix marker for SHA1 */ -API_EXPORT(void) ap_sha1_base64(char *, int, char *); +const char *sha1_id; /* passwd prefix marker for SHA1 */ +API_EXPORT(void) ap_sha1_base64(const char *clear, int len, char *out); #ifdef __cplusplus } 1.466 +11 -0 apache-1.3/src/main/http_main.c Index: http_main.c =================================================================== RCS file: /home/cvs/apache-1.3/src/main/http_main.c,v retrieving revision 1.465 retrieving revision 1.466 diff -u -r1.465 -r1.466 --- http_main.c 1999/07/29 18:13:43 1.465 +++ http_main.c 1999/08/02 20:50:20 1.466 @@ -6643,6 +6643,17 @@ #endif /* def OS2 */ #endif /* ndef SHARED_CORE_BOOTSTRAP */ +#ifndef SHARED_CORE_BOOTSTRAP +/* + * Force ap_validate_password() into the image so that modules like + * mod_auth can use it even if they're dynamically loaded. + */ +const void suck_in_ap_validate_password(void) +{ + ap_validate_password("a", "b"); +} +#endif + /* force Expat to be linked into the server executable */ #if defined(USE_EXPAT) && !defined(SHARED_CORE_BOOTSTRAP) #include "xmlparse.h" 1.47 +0 -1 apache-1.3/src/modules/standard/mod_auth.c Index: mod_auth.c =================================================================== RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_auth.c,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- mod_auth.c 1999/08/02 10:13:46 1.46 +++ mod_auth.c 1999/08/02 20:50:22 1.47 @@ -74,7 +74,6 @@ #include "http_core.h" #include "http_log.h" #include "http_protocol.h" -#include "ap_checkpass.h" typedef struct auth_config_struct { char *auth_pwfile; 1.42 +0 -1 apache-1.3/src/modules/standard/mod_auth_db.c Index: mod_auth_db.c =================================================================== RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_auth_db.c,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- mod_auth_db.c 1999/08/02 10:13:47 1.41 +++ mod_auth_db.c 1999/08/02 20:50:22 1.42 @@ -96,7 +96,6 @@ #include "http_log.h" #include "http_protocol.h" #include <db.h> -#include "ap_checkpass.h" #if defined(DB_VERSION_MAJOR) && (DB_VERSION_MAJOR == 2) #define DB2 1.48 +0 -1 apache-1.3/src/modules/standard/mod_auth_dbm.c Index: mod_auth_dbm.c =================================================================== RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_auth_dbm.c,v retrieving revision 1.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- mod_auth_dbm.c 1999/08/02 10:13:47 1.47 +++ mod_auth_dbm.c 1999/08/02 20:50:22 1.48 @@ -80,7 +80,6 @@ #else #include <ndbm.h> #endif -#include "ap_checkpass.h" /* * Module definition information - the part between the -START and -END