]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
NetBSD defines bswap16() and bswap32(). The re-definitions in [squid]/include/ntlmau...
authorrobertc <>
Wed, 6 Aug 2003 03:39:59 +0000 (03:39 +0000)
committerrobertc <>
Wed, 6 Aug 2003 03:39:59 +0000 (03:39 +0000)
configure
configure.in
helpers/ntlm_auth/SMB/ntlm_auth.c
helpers/ntlm_auth/fakeauth/fakeauth_auth.c
helpers/ntlm_auth/fakeauth/ntlm.h
helpers/ntlm_auth/winbind/wb_ntlm_auth.c
include/autoconf.h.in
include/ntlmauth.h
include/squid_endian.h [new file with mode: 0644]
lib/ntlmauth.c

index 34c5146223f6964567c57d60b79f553f902eef1b..ce238e24cade16c2135deb1964f0f6f35d1de00f 100755 (executable)
--- 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 \
 
 
 
+
+
+
+
 
 
 
@@ -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 \
index 9f4c8c649f2fb26db47d24dc4d2932a98ad4051a..c48758cf339e031316323bffce9c9db2931f9d0b 100644 (file)
@@ -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 \
index c8582917c771c28f8e7bd47c5e064dc9b680b802..a2126dd82c973837e9d481f6417e148e8752a041 100644 (file)
@@ -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;
index 9cfa6f3d4c69d311a80b533b8aa787df89a27fc3..b83a7bf3b4311069be08f1f5c4cdb20d14f2dddd 100644 (file)
@@ -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
index 08deda83d71e2b93110cf9a42829f0638a7e1c1e..b402aad8c78d6eed4343429b82ccb531e01018de 100644 (file)
@@ -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 <ad@interlude.eu.org>
  *
 #include <sys/types.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
+#include "squid_endian.h"
 
 /* NTLM request types that we know about */
 #define NTLM_NEGOTIATE         1
index c14fa5994344e6fda6952b4c93be49397b82bfa4..d0df7320544237263a10f7972b4f1257fc726c1d 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "wbntlm.h"
 #include "util.h"
+#include "squid_endian.h"
 /* stdio.h is included in wbntlm.h */
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -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;
index b373f26b111d7edcb4559156e29415686127d48a..8350eb7f791107f68b4e134fc705dcd37a3be5be 100644 (file)
 /* Define to 1 if you have the <bstring.h> 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
 
 /* Define to 1 if you have the <grp.h> 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
 
 /* Define to 1 if you have the <sys/bitypes.h> header file. */
 #undef HAVE_SYS_BITYPES_H
 
+/* Define to 1 if you have the <sys/bswap.h> header file. */
+#undef HAVE_SYS_BSWAP_H
+
 /* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
    */
 #undef HAVE_SYS_DIR_H
 
+/* Define to 1 if you have the <sys/endian.h> header file. */
+#undef HAVE_SYS_ENDIAN_H
+
 /* Define to 1 if you have the <sys/file.h> header file. */
 #undef HAVE_SYS_FILE_H
 
index 5dd26bf4e39fcfcd3f2112a7bbf6d43d5fed25dd..049c9057e5973cce6622b07914949ec28d0e7db5 100644 (file)
@@ -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 * * * * * * *
  *
 #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 <byteswap.h>
-#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 (file)
index 0000000..e45c382
--- /dev/null
@@ -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 <byteswap.h>
+ *
+ * Some systems define bswap16() and bswap32() in <sys/bswap.h>.  
+ *
+ * Some systems define htobe16()/be16toh() and friends in <sys/endian.h>.
+ */
+#include <sys/types.h>
+#if HAVE_BYTESWAP_H
+#  include <byteswap.h>
+#endif /* HAVE_BYTESWAP_H */
+#if HAVE_SYS_BSWAP_H
+#  include <sys/bswap.h>
+#endif /* HAVE_MACHINE_BSWAP_H */
+#if HAVE_SYS_ENDIAN_H
+#  include <sys/endian.h>
+#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 */
index 44fb912a8951132cc81b1c01170cb3d99cbf9a9e..23ae8f680f9c021c67f51a67d0c0c4ba36b68012 100644 (file)
@@ -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 |