From: robertc <> Date: Wed, 6 Aug 2003 03:39:59 +0000 (+0000) Subject: NetBSD defines bswap16() and bswap32(). The re-definitions in [squid]/include/ntlmau... X-Git-Tag: SQUID_3_0_PRE3~36 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f95768907ff7b9c8cede22385513afdf57e1f1de;p=thirdparty%2Fsquid.git NetBSD defines bswap16() and bswap32(). The re-definitions in [squid]/include/ntlmauth.c cause compile errors. I'll send a patch to the squid-dev list soon. - Alan Barrett (bug #724) --- diff --git a/configure b/configure index 34c5146223..ce238e24ca 100755 --- a/configure +++ b/configure @@ -7397,6 +7397,8 @@ done + + @@ -7444,6 +7446,8 @@ for ac_header in \ string.h \ strings.h \ sys/bitypes.h \ + sys/bswap.h \ + sys/endian.h \ sys/file.h \ sys/ioctl.h \ sys/param.h \ @@ -15565,6 +15569,10 @@ fi + + + + @@ -15575,6 +15583,8 @@ for ac_func in \ bcopy \ bswap_16 \ bswap_32 \ + bswap16 \ + bswap32 \ crypt \ fchmod \ getdtablesize \ @@ -15583,6 +15593,8 @@ for ac_func in \ getrlimit \ getrusage \ getspnam \ + htobe16 \ + htole16 \ lrand48 \ mallinfo \ mallocblksize \ diff --git a/configure.in b/configure.in index 9f4c8c649f..c48758cf33 100644 --- a/configure.in +++ b/configure.in @@ -3,7 +3,7 @@ dnl Configuration input file for Squid dnl dnl Duane Wessels, wessels@nlanr.net, February 1996 (autoconf v2.9) dnl -dnl $Id: configure.in,v 1.342 2003/07/28 20:41:05 robertc Exp $ +dnl $Id: configure.in,v 1.343 2003/08/05 21:40:00 robertc Exp $ dnl dnl dnl @@ -13,7 +13,7 @@ AC_CONFIG_SRCDIR([src/main.cc]) AC_CONFIG_AUX_DIR(cfgaux) AM_INIT_AUTOMAKE(squid, 3.0-PRE2-CVS) AM_CONFIG_HEADER(include/autoconf.h) -AC_REVISION($Revision: 1.342 $)dnl +AC_REVISION($Revision: 1.343 $)dnl AC_PREFIX_DEFAULT(/usr/local/squid) AM_MAINTAINER_MODE @@ -1474,6 +1474,8 @@ AC_CHECK_HEADERS( \ string.h \ strings.h \ sys/bitypes.h \ + sys/bswap.h \ + sys/endian.h \ sys/file.h \ sys/ioctl.h \ sys/param.h \ @@ -1925,6 +1927,8 @@ AC_CHECK_FUNCS(\ bcopy \ bswap_16 \ bswap_32 \ + bswap16 \ + bswap32 \ crypt \ fchmod \ getdtablesize \ @@ -1933,6 +1937,8 @@ AC_CHECK_FUNCS(\ getrlimit \ getrusage \ getspnam \ + htobe16 \ + htole16 \ lrand48 \ mallinfo \ mallocblksize \ diff --git a/helpers/ntlm_auth/SMB/ntlm_auth.c b/helpers/ntlm_auth/SMB/ntlm_auth.c index c8582917c7..a2126dd82c 100644 --- a/helpers/ntlm_auth/SMB/ntlm_auth.c +++ b/helpers/ntlm_auth/SMB/ntlm_auth.c @@ -18,6 +18,7 @@ #include "config.h" #include "ntlmauth.h" #include "ntlm.h" +#include "squid_endian.h" #include "util.h" #include "smbval/smblib-common.h" #include "smbval/rfcnb-error.h" @@ -308,7 +309,7 @@ manage_request() SEND("NA Broken authentication packet"); return; } - switch WSWAP(fast_header->type) { + switch le32toh(fast_header->type) { case NTLM_NEGOTIATE: SEND("NA Invalid negotiation request received"); return; diff --git a/helpers/ntlm_auth/fakeauth/fakeauth_auth.c b/helpers/ntlm_auth/fakeauth/fakeauth_auth.c index 9cfa6f3d4c..b83a7bf3b4 100644 --- a/helpers/ntlm_auth/fakeauth/fakeauth_auth.c +++ b/helpers/ntlm_auth/fakeauth/fakeauth_auth.c @@ -14,6 +14,7 @@ #include "config.h" #include "ntlmauth.h" +#include "squid_endian.h" #include "ntlm.h" #include "util.h" @@ -78,9 +79,9 @@ ntlmMakeChallenge(struct ntlm_challenge *chal) memset(chal, 0, sizeof(*chal)); memcpy(chal->hdr.signature, "NTLMSSP", 8); - chal->flags = WSWAP(0x00018206); - chal->hdr.type = WSWAP(NTLM_CHALLENGE); - chal->unknown[6] = SSWAP(0x003a); + chal->flags = htole32(0x00018206); + chal->hdr.type = htole32(NTLM_CHALLENGE); + chal->unknown[6] = htole16(0x003a); d = (char *) chal + 48; i = 0; @@ -89,8 +90,8 @@ ntlmMakeChallenge(struct ntlm_challenge *chal) while (authenticate_ntlm_domain[i++]); - chal->target.offset = WSWAP(48); - chal->target.maxlen = SSWAP(i); + chal->target.offset = htole32(48); + chal->target.maxlen = htole16(i); chal->target.len = chal->target.maxlen; #ifdef NTLM_STATIC_CHALLENGE @@ -125,10 +126,10 @@ ntlmCheckHeader(ntlmhdr * hdr, int type) if (type == NTLM_ANY) return 0; - if (WSWAP(hdr->type) != type) { + if (le32toh(hdr->type) != type) { /* don't report this error - it's ok as we do a if() around this function */ // fprintf(stderr, "ntlmCheckHeader: type is %d, wanted %d\n", - // WSWAP(hdr->type), type); + // le32toh(hdr->type), type); return (-1); } return (0); @@ -145,8 +146,8 @@ ntlmGetString(ntlmhdr * hdr, strhdr * str, int flags) char *d, *sc; int l, o; - l = SSWAP(str->len); - o = WSWAP(str->offset); + l = le16toh(str->len); + o = le32toh(str->offset); /* Sanity checks. XXX values arbitrarialy chosen */ if (l <= 0 || l >= 32 || o >= 256) { @@ -159,7 +160,7 @@ ntlmGetString(ntlmhdr * hdr, strhdr * str, int flags) d = buf; for (l >>= 1; l; s++, l--) { - c = SSWAP(*s); + c = le16toh(*s); if (c > 254 || c == '\0' || !isprint(c)) { fprintf(stderr, "ntlmGetString: bad uni: %04x\n", c); return (NULL); @@ -258,7 +259,7 @@ main() ntlmMakeChallenge(&chal); len = sizeof(chal) - sizeof(chal.pad) + - SSWAP(chal.target.maxlen); + le16toh(chal.target.maxlen); data = (char *) base64_encode_bin((char *) &chal, len); printf("TT %s\n", data); } else if (strncasecmp(buf, "KK ", 3) == 0) { @@ -287,7 +288,7 @@ main() ntlmMakeChallenge(&chal); len = sizeof(chal) - sizeof(chal.pad) + - SSWAP(chal.target.maxlen); + le16toh(chal.target.maxlen); data = (char *) base64_encode_bin((char *) &chal, len); printf("CH %s\n", data); } else if (!ntlmCheckHeader diff --git a/helpers/ntlm_auth/fakeauth/ntlm.h b/helpers/ntlm_auth/fakeauth/ntlm.h index 08deda83d7..b402aad8c7 100644 --- a/helpers/ntlm_auth/fakeauth/ntlm.h +++ b/helpers/ntlm_auth/fakeauth/ntlm.h @@ -1,5 +1,5 @@ /* - * $Id: ntlm.h,v 1.5 2003/01/23 00:36:35 robertc Exp $ + * $Id: ntlm.h,v 1.6 2003/08/05 21:40:02 robertc Exp $ * * AUTHOR: Andrew Doran * @@ -41,13 +41,7 @@ #include /* All of this cruft is little endian */ -#ifdef WORDS_BIGENDIAN -#define SSWAP(x) (bswap16((x))) -#define WSWAP(x) (bswap32((x))) -#else -#define SSWAP(x) (x) -#define WSWAP(x) (x) -#endif +#include "squid_endian.h" /* NTLM request types that we know about */ #define NTLM_NEGOTIATE 1 diff --git a/helpers/ntlm_auth/winbind/wb_ntlm_auth.c b/helpers/ntlm_auth/winbind/wb_ntlm_auth.c index c14fa59943..d0df732054 100644 --- a/helpers/ntlm_auth/winbind/wb_ntlm_auth.c +++ b/helpers/ntlm_auth/winbind/wb_ntlm_auth.c @@ -26,6 +26,7 @@ #include "wbntlm.h" #include "util.h" +#include "squid_endian.h" /* stdio.h is included in wbntlm.h */ #include #include @@ -316,7 +317,7 @@ try_again: return; } /* Understand what we got */ - switch WSWAP(fast_header->type) { + switch le32toh(fast_header->type) { case NTLM_NEGOTIATE: authfail("-", "-", "Received neg-request while expecting auth packet"); return; diff --git a/include/autoconf.h.in b/include/autoconf.h.in index b373f26b11..8350eb7f79 100644 --- a/include/autoconf.h.in +++ b/include/autoconf.h.in @@ -82,6 +82,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_BSTRING_H +/* Define to 1 if you have the `bswap16' function. */ +#undef HAVE_BSWAP16 + +/* Define to 1 if you have the `bswap32' function. */ +#undef HAVE_BSWAP32 + /* Define to 1 if you have the `bswap_16' function. */ #undef HAVE_BSWAP_16 @@ -152,6 +158,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_GRP_H +/* Define to 1 if you have the `htobe16' function. */ +#undef HAVE_HTOBE16 + +/* Define to 1 if you have the `htole16' function. */ +#undef HAVE_HTOLE16 + /* int is defined in system headers */ #undef HAVE_INT @@ -510,10 +522,16 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_BITYPES_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_BSWAP_H + /* Define to 1 if you have the header file, and it defines `DIR'. */ #undef HAVE_SYS_DIR_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_ENDIAN_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_FILE_H diff --git a/include/ntlmauth.h b/include/ntlmauth.h index 5dd26bf4e3..049c9057e5 100644 --- a/include/ntlmauth.h +++ b/include/ntlmauth.h @@ -1,5 +1,5 @@ /* - * $Id: ntlmauth.h,v 1.11 2003/05/12 18:49:11 hno Exp $ + * $Id: ntlmauth.h,v 1.12 2003/08/05 21:40:04 robertc Exp $ * * * * * * * * * Legal stuff * * * * * * * * @@ -57,24 +57,7 @@ #include "config.h" /* All of this cruft is little endian */ -#ifdef WORDS_BIGENDIAN -#define SSWAP(x) (bswap16((x))) -#define WSWAP(x) (bswap32((x))) -#else -#define SSWAP(x) (x) -#define WSWAP(x) (x) -#endif - -#ifdef HAVE_BYTESWAP_H -#include -#define bswap16(x) bswap_16(x) -#define bswap32(x) bswap_32(x) -#else /* HAVE_BISTWAP_H */ -#define bswap16(x) (((((u_int16_t)x) >> 8) & 0xff) | ((((u_int16_t)x) & 0xff) << 8)) -#define bswap32(x) \ - (((((u_int32_t)x) & 0xff000000) >> 24) | ((((u_int32_t)x) & 0x00ff0000) >> 8) | \ - ((((u_int32_t)x) & 0x0000ff00) << 8) | ((((u_int32_t)x) & 0x000000ff) << 24)) -#endif /* HAVE_BITSWAP_H */ +#include "squid_endian.h" /* Used internally. Microsoft seems to think this is right, I believe them. * Right. */ diff --git a/include/squid_endian.h b/include/squid_endian.h new file mode 100644 index 0000000000..e45c382757 --- /dev/null +++ b/include/squid_endian.h @@ -0,0 +1,148 @@ +/* + * $Id: squid_endian.h,v 1.1 2003/08/05 21:40:07 robertc Exp $ + * + * AUTHOR: Alan Barrett + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#ifndef SQUID_ENDIAN_H +#define SQUID_ENDIAN_H + +/* + * Macros to deal with byte swapping. These macros provide + * the following interface: + * + * // Byte-swap + * u_int16_t bswap16(u_int16_t); + * u_int32_t bswap32(u_int32_t); + * + * // Convert from host byte order to big-endian, and vice versa. + * u_int16_t htobe16(u_int16_t); // equivalent to htons() + * u_int32_t htobe32(u_int32_t); // equivalent to htonl() + * u_int16_t be16toh(u_int16_t); // equivalent to ntohs() + * u_int32_t be32toh(u_int32_t); // equivalent to ntohs() + * + * // Convert from host byte order to little-endian, and vice versa. + * u_int16_t htole16(u_int16_t); + * u_int32_t htole32(u_int32_t); + * u_int16_t le16toh(u_int16_t); + * u_int32_t le32toh(u_int32_t); + */ + +#include "config.h" +#include "squid_types.h" + +/* + * Some systems define bswap_16() and bswap_32() in + * + * Some systems define bswap16() and bswap32() in . + * + * Some systems define htobe16()/be16toh() and friends in . + */ +#include +#if HAVE_BYTESWAP_H +# include +#endif /* HAVE_BYTESWAP_H */ +#if HAVE_SYS_BSWAP_H +# include +#endif /* HAVE_MACHINE_BSWAP_H */ +#if HAVE_SYS_ENDIAN_H +# include +#endif /* HAVE_SYS_ENDIAN_H */ + +/* + * Define bswap16() and bswap32() in terms of bswap_16() and bswap_32(), + * or the hard way. + */ +#if ! HAVE_BSWAP16 && ! defined(bswap16) +# if defined(bswap_16) +# define bswap16(x) bswap_16(x) +# else +# define bswap16(x) \ + ((((u_int16_t)x) >> 8) & 0xff) | ((((u_int16_t)x) & 0xff) << 8)) +# endif +#endif /* ! HAVE_BSWAP16 && ! defined(bswap16) */ +#if ! HAVE_BSWAP32 && ! defined(bswap32) +# if defined(bswap_32) +# define bswap32(x) bswap_32(x) +# else +# define bswap32(x) \ + (((((u_int32_t)x) & 0xff000000) >> 24) | \ + ((((u_int32_t)x) & 0x00ff0000) >> 8) | \ + ((((u_int32_t)x) & 0x0000ff00) << 8) | \ + ((((u_int32_t)x) & 0x000000ff) << 24)) +# endif +#endif /* ! HAVE_BSWAP32 && ! defined(bswap32) */ + +/* + * Define htobe*()/be*toh() in terms of hton*()/ntoh*(). + * + * XXX: If htobe16() is missing, we assume that the other *be*() functions + * are also missing. + */ +#if ! HAVE_HTOBE16 && ! defined(htobe16) +# ifdef WORDS_BIGENDIAN +# define htobe16(x) (x) +# define htobe32(x) (x) +# define be16toh(x) (x) +# define be32toh(x) (x) +# else /* ! WORDS_BIGENDIAN */ +# define htobe16(x) htons(x) +# define htobe32(x) htonl(x) +# define be16toh(x) ntohs(x) +# define be32toh(x) ntohl(x) +# endif /* ! WORDS_BIGENDIAN */ +#endif /* ! HAVE_HTOBE16 && ! defined(htobe16) */ + +/* + * Define htole*()/le*toh() in terms of bswap*(). + * + * XXX: If htole16() is missing, we assume that the other *le*() functions + * are also missing. + */ +#if ! HAVE_HTOLE16 && ! defined(htole16) +# ifdef WORDS_BIGENDIAN +# define htole16(x) bswap16(x) +# define htole32(x) bswap32(x) +# define le16toh(x) bswap16(x) +# define le32toh(x) bswap32(x) +# else /* ! WORDS_BIGENDIAN */ + /* + * XXX: What about unusual byte orders like 3412 or 2143 ? + * Nothing else in squid seems to care about them, + * so we don't worry about them here either. + */ +# define htole16(x) (x) +# define htole32(x) (x) +# define le16toh(x) (x) +# define le32toh(x) (x) +# endif /* ! WORDS_BIGENDIAN */ +#endif /* ! HAVE_HTOLE16 && ! defined(htole16) */ + +#endif /* SQUID_ENDIAN_H */ diff --git a/lib/ntlmauth.c b/lib/ntlmauth.c index 44fb912a89..23ae8f680f 100644 --- a/lib/ntlmauth.c +++ b/lib/ntlmauth.c @@ -1,5 +1,5 @@ /* - * $Id: ntlmauth.c,v 1.8 2003/01/23 00:37:01 robertc Exp $ + * $Id: ntlmauth.c,v 1.9 2003/08/05 21:40:09 robertc Exp $ * * * * * * * * * Legal stuff * * * * * * * * @@ -31,6 +31,7 @@ #endif #include "ntlmauth.h" +#include "squid_endian.h" #include "util.h" /* for base64-related stuff */ #if UNUSED_CODE @@ -80,8 +81,8 @@ ntlm_fetch_string(char *packet, int32_t length, strhdr * str) lstring_zero(rv); - l = SSWAP(str->len); - o = WSWAP(str->offset); + l = le16toh(str->len); + o = le32toh(str->offset); /* debug("fetch_string(plength=%d,l=%d,o=%d)\n",length,l,o); */ if (l < 0 || l > MAX_FIELD_LENGTH || o + l > length || o == 0) { @@ -109,9 +110,9 @@ ntlm_add_to_payload(char *payload, int *payload_length, int l = (*payload_length); memcpy(payload + l, toadd, toadd_length); - hdr->len = SSWAP(toadd_length); - hdr->maxlen = SSWAP(toadd_length); - hdr->offset = WSWAP(l + base_offset); /* 48 is the base offset of the payload */ + hdr->len = htole16(toadd_length); + hdr->maxlen = htole16(toadd_length); + hdr->offset = htole32(l + base_offset); /* 48 is the base offset of the payload */ (*payload_length) += toadd_length; } @@ -130,10 +131,10 @@ ntlm_make_challenge(char *domain, char *domain_controller, const char *encoded; memset(&ch, 0, sizeof(ntlm_challenge)); /* reset */ memcpy(ch.signature, "NTLMSSP", 8); /* set the signature */ - ch.type = WSWAP(NTLM_CHALLENGE); /* this is a challenge */ + ch.type = htole32(NTLM_CHALLENGE); /* this is a challenge */ ntlm_add_to_payload(ch.payload, &pl, &ch.target, domain, strlen(domain), NTLM_CHALLENGE_HEADER_OFFSET); - ch.flags = WSWAP( + ch.flags = htole32( REQUEST_NON_NT_SESSION_KEY | CHALLENGE_TARGET_IS_DOMAIN | NEGOTIATE_ALWAYS_SIGN |