diff -Ncr squid-2.4.STABLE6/ChangeLog squid-2.4.STABLE7/ChangeLog *** squid-2.4.STABLE6/ChangeLog Tue Mar 19 16:52:08 2002 --- squid-2.4.STABLE7/ChangeLog Tue Jul 2 09:49:44 2002 *************** *** 1,3 **** --- 1,24 ---- + Changes to Squid-2.4.STABLE7 (July 2, 2002): + + - Squid now drops any requests using transfer-encoding. + Squid is a HTTP/1.0 proxy and as such do not support + the use of transfer-encoding. + - The MSNT auth helper has been updated to v2.0.3+fixes for + buffer overflow security issues found in this helper. + - A security issue in how Squid forwards proxy authentication + credentials has been fixed + - Minor changes to support Apple MAC OS X and some other platforms + more easily. + - The client -T option has been implemented + - HTCP related bugfixes in "squid -k reconfigure" + - Several bugfixes and cleanup of the Gopher client, both + to correct some security issues and to make Squid properly + render certain Gopher menus. + - FTP data channels are now sanity checked to match the address of + the requested FTP server. This to prevent theft or injection of + data. See the new ftp_sanitycheck directive if this is not desired. + - Security fixes in how Squid parses FTP directory listings into HTML + Changes to Squid-2.4.STABLE6 (March 19, 2002): - The patch for 2.4.STABLE5 was insufficnetly tested and diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/Makefile.in squid-2.4.STABLE7/auth_modules/MSNT/Makefile.in *** squid-2.4.STABLE6/auth_modules/MSNT/Makefile.in Tue Jan 16 14:12:26 2001 --- squid-2.4.STABLE7/auth_modules/MSNT/Makefile.in Wed Jun 26 13:39:05 2002 *************** *** 1,7 **** # # Makefile for the Squid Object Cache server # ! # $Id: Makefile.in,v 1.4.2.1 2001/01/16 21:12:26 hno Exp $ # # Uncomment and customize the following to suit your needs: # --- 1,7 ---- # # Makefile for the Squid Object Cache server # ! # $Id: Makefile.in,v 1.4.2.2 2002/06/26 19:39:05 hno Exp $ # # Uncomment and customize the following to suit your needs: # *************** *** 50,60 **** AUTH_LIBS = $(XTRA_LIBS) LIBPROGS = $(AUTH_EXE) ! OBJS = md4.o rfcnb-io.o rfcnb-util.o session.o msntauth.o \ ! smbdes.o smbencrypt.o smblib-util.o smblib.o \ ! valid.o denyusers.o allowusers.o confload.o all: $(AUTH_EXE) $(AUTH_EXE): $(OBJS) $(CC) $(LDFLAGS) $(OBJS) -o $@ $(AUTH_LIBS) --- 50,64 ---- AUTH_LIBS = $(XTRA_LIBS) LIBPROGS = $(AUTH_EXE) ! OBJS = allowusers.o md4.o rfcnb-util.o smbencrypt.o \ ! usersfile.o confload.o msntauth.o session.o \ ! smblib.o valid.o denyusers.o rfcnb-io.o smbdes.o \ ! smblib-util.o all: $(AUTH_EXE) + + confload.o: $(srcdir)/confload.c + $(CC) -c $(CFLAGS) -DSYSCONFDIR=\"$(sysconfdir)\" $(srcdir)/confload.c -o confload.o $(AUTH_EXE): $(OBJS) $(CC) $(LDFLAGS) $(OBJS) -o $@ $(AUTH_LIBS) diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/README.html squid-2.4.STABLE7/auth_modules/MSNT/README.html *** squid-2.4.STABLE6/auth_modules/MSNT/README.html Fri Nov 3 11:08:02 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/README.html Wed Jun 26 13:24:42 2002 *************** *** 6,19 ****

! MSNT Auth v2.0.1
! Squid web proxy Authentication module
Antonino Iannella, Stellar-X Pty Ltd
! Fri Sep 29 15:53:33 CST 2000

Contents

--- 6,21 ----

! MSNT Auth v2.0.3-squid.1
! Squid web proxy NT authentication module
Antonino Iannella, Stellar-X Pty Ltd
! Sun Sep 2 15:01:58 CST 2001
! Modified by the Squid HTTP Proxy team
! Wed Jun 26 21:16:32 CEST 2002

Contents

*************** *** 21,27 ****

Introduction

*************** *** 45,58 **** authentication module by William Welliver (hwellive@intersil.com).

! Usage is simple. It accepts a username and password on standard input ! and will return OK if the username/password is valid for the domain, or ERR if there was some problem. Check syslog messages for reported problems.

Msntauth is released under the GNU General Public License and ! is available from http://stellarx.tripod.com.

Installation

--- 46,65 ---- authentication module by William Welliver (hwellive@intersil.com).

! Usage is simple. It accepts a username and password on standard input. ! It will return OK if the username/password is valid for the domain, or ERR if there was some problem. Check syslog messages for reported problems.

Msntauth is released under the GNU General Public License and ! is available from ! http://www.tripod.com/stellarx. ! It also ships with the Squid web proxy, ! http://www.squid-proxy.org. ! !

! Msntauth has not been tested with Windows 2000 domains yet.

Installation

*************** *** 60,65 **** --- 67,83 ---- Make any changes to the source code you need.

+ If you are using the source provided with Squid, then Msntauth + will be compiled when you compile Squid. Refer to Squid documentation + for details. + +

+ If you have downloaded Msntauth from the Stellar-X website, then + copy Makefile.MSNT to Makefile. + Review the Makefile, and modify based on target platform or + site requirements. + +

Type 'make', then 'make install', then 'make clean'.

*************** *** 73,89 ****

Hopefully nobody has problems compiling msntauth. - In the future I plan to use GNU automake. !

Other compiling issues

The Makefile uses the GCC compiler, and assumes that it is in the current PATH. Msntauth is known to compile properly on Redhat Linux 6, and FreeBSD 3.1 without problems. Other operating systems are untested, but use a recent copy of the GNU C compiler. ! Smbencrypt.c has the '#include ' line commented out. ! Remove the comment for S5R4 systems, like Solaris.

When compiling under Solaris, the socket libraries must be linked to. --- 91,106 ----

Hopefully nobody has problems compiling msntauth. !

Issues when compiling

The Makefile uses the GCC compiler, and assumes that it is in the current PATH. Msntauth is known to compile properly on Redhat Linux 6, and FreeBSD 3.1 without problems. Other operating systems are untested, but use a recent copy of the GNU C compiler. ! In Smbencrypt.c, '#include ' only gets included when ! compiled with Solaris.

When compiling under Solaris, the socket libraries must be linked to. *************** *** 91,102 **** CFLAGS line. It always helps to have /usr/ccs/bin in your path prior to compiling.

Configuration file

! Msntauth uses a configuration file which is a break from previous ! releases. The file is /usr/local/squid/etc/msntauth.conf. ! If this needs to be changed, it is defined in confload.h.

An example configuration file is provided. It looks like --- 108,126 ---- CFLAGS line. It always helps to have /usr/ccs/bin in your path prior to compiling. +

+ For Digital Unix/Tru64, review the INSTALL line in the makefile. +

Configuration file

! Msntauth uses a configuration file as of version 2. ! The file is /usr/local/squid/etc/msntauth.conf. ! If this path needs to be changed, it is defined in confload.c - ! !

!   #define CONFIGFILE   "/usr/local/squid/etc/msntauth.conf"
! 

An example configuration file is provided. It looks like *************** *** 119,128 ****

NT servers are used to query user accounts. The 'server' lines are used for this, with the PDC, BDC, and NT domain as parameters. ! Up to 5 servers/domains can be queried. If this is not enough ! modify the MAXSERVERS define in confload.h. At least one server must be specified, or msntauth will not run.

When a user provides a username/password, each of these --- 143,156 ----

NT servers are used to query user accounts. The 'server' lines are used for this, with the PDC, BDC, and NT domain as parameters. ! Up to 5 servers/domains can be queried. If this is not enough, ! modify the MAXSERVERS define in confload.c. At least one server must be specified, or msntauth will not run. + Server names must be resolvable by the system. If not, msntauth + reports an error. If you can't ping it, you might have a host + resolution problem. + You can't use NetBIOS hostnames, nor IP addresses.

When a user provides a username/password, each of these *************** *** 147,153 ****

The denied user file is set using the 'denyusers' directive ! in msntauth.h. The denied user file contains a list of usernames in no particular structure or form. If the file does not exist, no users are denied. The file must be readable by the web proxy user. --- 175,181 ----

The denied user file is set using the 'denyusers' directive ! in msntauth.conf. The denied user file contains a list of usernames in no particular structure or form. If the file does not exist, no users are denied. The file must be readable by the web proxy user. *************** *** 165,171 ****

The allowed user file is set using the 'allowusers' directive ! in msntauth.h. If the file does not exist or if empty, all users are allowed.

--- 193,199 ----

The allowed user file is set using the 'allowusers' directive ! in msntauth.conf. If the file does not exist or if empty, all users are allowed.

*************** *** 204,214 **** http_access allow password http_access allow http_access deny all -

! You will also need to review the following directives -

    proxy_auth_realm enterprise web gateway
--- 232,247 ----
    http_access allow password
    http_access allow 
    http_access deny all
  

! You will also need to review the following directives. The number of ! msntauth children spawned is set with authenticate_children. ! The number of children needed is site-dependent, so some ! experimentation may be required to find the best number. ! There should be no visible delay in performance with Squid once ! msntauth is in use. As an example, a firm with 1500 users and a T1 ! internet connection required a value of 30.-

    proxy_auth_realm enterprise web gateway
***************
*** 245,256 ****
  If the above didn't work as expected, you may need to modify the main()
  function in msntauth.c. Inform the maintainer of any problems.
  
  

Contact details

To contact the maintainer of this package, email Antonino Iannella ! at antonino@usa.net, antonino.iannella@usa.net, or ! antonino.iannella@camtech.com.au.

The latest version may be found on http://members.tripod.com/stellarx. --- 278,300 ---- If the above didn't work as expected, you may need to modify the main() function in msntauth.c. Inform the maintainer of any problems. +

+ Usernames cannot have whitespace in them, but passwords can. + +

+ As of version 2.0.3, the msntauth version can be found in the executable. + Type this to retrieve it - + +

+   strings msntauth | grep -i msntauth
+ 
+

Contact details

To contact the maintainer of this package, email Antonino Iannella ! at antonino@rager.com.au, or antonino.iannella@santos.com.au, or ring ! +61 8408 800 007.

The latest version may be found on http://members.tripod.com/stellarx. *************** *** 275,297 **** patch smblib.c < smblib.c.patch

!

Known limitation

! !

! Usernames are checked if they are allowed or denied. If a username ! is found as a substring of a different username in these files, ! the user will be affected somehow. For example, if 'jpeterman' has ! been explicitly denied in the denyusers file, then 'jpeter' who ! is trying to use the proxy, will be denied. If this causes anyone ! any problems, then I'll fix it. ! !

! As of version 2.0.1, this problem has been fixed. ! !

Changes since last revision

! The following list of changes have been made to improve msntauth. I have not had a chance to do too much testing due to lack of resources. There should be no problems, though. --- 319,328 ---- patch smblib.c < smblib.c.patch !

Revision history

! The following sequence of changes have been made to improve msntauth. I have not had a chance to do too much testing due to lack of resources. There should be no problems, though. *************** *** 305,316 ****

  • Added the use of a configuration file, instead of hard-coding NT server details
  • Allowed for querying multiple NT servers and domains (this was a hot issue)
  • Changed README into an HTML document to improve readability !
  • Didn't make use of GNU autoconf. I will in future, I promise. !
  • Removed denied/allowed username substring search limitation.

    ! Hopefully msntauth and Squid is now a more valuable product. Feel free to send me success or problem stories. --- 336,356 ----

  • Added the use of a configuration file, instead of hard-coding NT server details
  • Allowed for querying multiple NT servers and domains (this was a hot issue)
  • Changed README into an HTML document to improve readability !
  • Removed denied/allowed username substring search limitation !
  • Fixed a bug which occurred when reading denied/allowed usernames !
  • Allows whitespace in passwords !
  • To check user list changes, doesn't use an alarm every minute. !
  • Fixed a sigaction compilation error, causing problems on FreeBSD and HPUX !
  • Removed a problem of finding a valid username as a substring in the denied user list. !
  • Support email address change from antonino@usa.net to antonino@rager.com.au. !
  • Msntauth was successfully tested on Tru64. !
  • PDC and BDC hostnames are now checked if they are resolvable. !
  • Smbencrypt.c does not have to be checked for Solaris systems any more. !
  • Imbedded version information in the executable.

    ! Hopefully msntauth and Squid prove to be a valuable auditing combination. Feel free to send me success or problem stories. diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/allowusers.c squid-2.4.STABLE7/auth_modules/MSNT/allowusers.c *** squid-2.4.STABLE6/auth_modules/MSNT/allowusers.c Fri Nov 3 11:08:02 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/allowusers.c Wed Jun 26 13:24:42 2002 *************** *** 1,210 **** /* ! allowusers.c ! (C) 2000 Antonino Iannella, Stellar-X Pty Ltd ! Released under GPL, see COPYING-2.0 for details. ! ! These routines are to allow users attempting to use the proxy which ! have been explicitly allowed by the system administrator. ! The code originated from denyusers.c. ! */ - #include #include - #include - #include #include ! #include ! #include ! #include ! #include #include ! #define NAMELEN 50 /* Maximum username length */ ! /* Global variables */ ! char *AllowedUsers; /* Pointer to string of allowed users */ ! off_t AllowUserSize; /* Size of allowed users file */ ! struct stat FileBuf; /* Stat data buffer */ ! time_t LastModTime; /* Last allowed user file modification time */ ! ! char Allowuserpath[MAXPATHLEN]; /* MAXPATHLEN defined in param.h */ ! ! /* Function declarations */ ! ! int Read_allowusers(); ! int Check_ifuserallowed(char *); ! void Checkforchange(); ! void Checktimer(); ! ! /* ! Reads the allowed users file for all users to be permitted. ! Returns 0 if the user list was successfully loaded, ! and 1 in case of error. ! Logs any messages to the syslog daemon. ! */ ! ! int Read_allowusers() { ! FILE *AFile; /* Allowed users file pointer */ ! off_t APos = 0; /* File counter */ ! char AChar; /* Character buffer */ ! ! /* Stat the file. If it does not exist, save the size as zero. ! Clear the allowed user string. Return. */ ! if (stat(Allowuserpath, &FileBuf) == -1) ! { ! if (errno == ENOENT) ! { ! LastModTime = (time_t) 0; ! AllowUserSize = 0; ! free(AllowedUsers); ! AllowedUsers = malloc(sizeof(char)); ! AllowedUsers[0] = '\0'; ! return 0; ! } ! else ! { ! syslog(LOG_USER | LOG_ERR, strerror(errno)); ! return 1; ! } ! } ! ! /* If it exists, save the modification time and size */ ! LastModTime = FileBuf.st_mtime; ! AllowUserSize = FileBuf.st_size; ! ! /* Handle the special case of a zero length file */ ! if (AllowUserSize == 0) ! { ! free(AllowedUsers); ! AllowedUsers = malloc(sizeof(char)); ! AllowedUsers[0] = '\0'; ! return 0; ! } ! ! /* Free and allocate space for a string to store the allowed usernames */ ! free(AllowedUsers); ! ! if ((AllowedUsers = malloc(sizeof(char) * (AllowUserSize + 3))) == NULL) ! { ! syslog(LOG_USER | LOG_ERR, "Read_allowusers: malloc(AllowedUsers) failed."); ! return 1; ! } ! ! /* Open the allowed users file. Report any errors. */ ! ! if ((AFile = fopen(Allowuserpath, "r")) == NULL) ! { ! syslog(LOG_USER | LOG_ERR, "Read_allowusers: Failed to open allowed user file."); ! syslog(LOG_USER | LOG_ERR, strerror(errno)); ! return 1; ! } ! ! /* Read user names into the AllowedUsers string. ! Make sure each string is delimited by a space. */ ! ! AllowedUsers[APos++] = ' '; ! ! while (!feof(AFile)) ! { ! if ((AChar = fgetc(AFile)) == EOF) ! break; ! else ! { ! if (isspace(AChar)) ! AllowedUsers[APos++] = ' '; ! else ! AllowedUsers[APos++] = toupper(AChar); } ! } ! ! AllowedUsers[APos++] = ' '; ! AllowedUsers[APos] = '\0'; ! fclose(AFile); ! return 0; } ! /* ! Check to see if the username provided by Squid appears in the allowed ! user list. Returns 0 if the user was not found, and 1 if they were. ! */ ! ! int Check_ifuserallowed(char *ConnectingUser) { ! static char CUBuf[NAMELEN + 1]; ! static int x; ! static char AllowMsg[256]; ! ! /* If user string is empty, allow */ ! if (ConnectingUser[0] == '\0') ! return 1; ! ! /* If allowed user list is empty, allow all users. ! If no users are supposed to be using the proxy, stop squid instead. */ ! if (AllowUserSize == 0) ! return 1; ! ! /* Check if username string is found in the allowed user list. ! If so, allow. If not, deny. Reconstruct the username ! to have whitespace, to avoid finding wrong string subsets. */ ! ! sscanf(ConnectingUser, " %s ", CUBuf); ! sprintf(CUBuf, " %s ", CUBuf); ! ! for (x = 0; x <= strlen(CUBuf); x++) ! CUBuf[x] = toupper(CUBuf[x]); ! ! if (strstr(AllowedUsers, CUBuf) != NULL) ! return 1; ! else /* If NULL, they are not allowed to use the proxy */ ! { ! sprintf(AllowMsg, "Denied access to user '%s'.", CUBuf); ! syslog(LOG_USER | LOG_ERR, AllowMsg); ! return 0; ! } } ! /* ! Checks if there has been a change in the allowed users file. ! If the modification time has changed, then reload the allowed user list. ! This function is called by the SIGHUP signal handler. ! */ ! ! void Check_forallowchange() { ! struct stat ChkBuf; /* Stat data buffer */ ! ! /* Stat the allowed users file. If it cannot be accessed, return. */ ! ! if (stat(Allowuserpath, &ChkBuf) == -1) ! { ! if (errno == ENOENT) ! { ! LastModTime = (time_t) 0; ! AllowUserSize = 0; ! free(AllowedUsers); ! AllowedUsers = malloc(sizeof(char)); ! AllowedUsers[0] = '\0'; ! return; ! } ! else /* Report error when accessing file */ ! { ! syslog(LOG_USER | LOG_ERR, strerror(errno)); ! return; ! } ! } ! ! /* If found, compare the modification time with the previously-recorded ! modification time. ! If the modification time has changed, reload the allowed user list. ! Log a message of its actions. */ ! ! if (ChkBuf.st_mtime != LastModTime) ! { ! syslog(LOG_USER | LOG_INFO, "Check_forallowchange: Reloading allowed user list."); ! Read_allowusers(); ! } } - --- 1,49 ---- /* ! * allowusers.c ! * (C) 2000 Antonino Iannella, Stellar-X Pty Ltd ! * Released under GPL, see COPYING-2.0 for details. ! * ! * These routines are to allow users attempting to use the proxy which ! * have been explicitly allowed by the system administrator. ! * The code originated from denyusers.c. ! */ #include #include ! #include #include + #include + #include "usersfile.h" + #include "msntauth.h" ! static usersfile AllowUsers; ! static int init = 0; ! /* shared */ ! char Allowuserpath[MAXPATHLEN]; /* MAXPATHLEN defined in param.h */ ! int ! Read_allowusers(void) { ! if (!init) { ! memset(&AllowUsers, '\0', sizeof(AllowUsers)); ! init = 1; } ! if (*Allowuserpath) ! return Read_usersfile(Allowuserpath, &AllowUsers); ! else ! return 0; } ! int ! Check_ifuserallowed(char *ConnectingUser) { ! return Check_userlist(&AllowUsers, ConnectingUser); } ! void ! Check_forallowchange(void) { ! Check_forfilechange(&AllowUsers); } diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/byteorder.h squid-2.4.STABLE7/auth_modules/MSNT/byteorder.h *** squid-2.4.STABLE6/auth_modules/MSNT/byteorder.h Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/byteorder.h Wed Jun 26 13:24:42 2002 *************** *** 1,36 **** /* ! Unix SMB/Netbios implementation. ! Version 1.9. ! SMB Byte handling ! Copyright (C) Andrew Tridgell 1992-1995 ! ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #ifndef _BYTEORDER_H_ #define _BYTEORDER_H_ /* ! This file implements macros for machine independent short and ! int manipulation ! */ #undef CAREFUL_ALIGNMENT /* we know that the 386 can handle misalignment and has the "right" ! byteorder */ #ifdef __i386__ #define CAREFUL_ALIGNMENT 0 #endif --- 1,36 ---- /* ! * Unix SMB/Netbios implementation. ! * Version 1.9. ! * SMB Byte handling ! * Copyright (C) Andrew Tridgell 1992-1995 ! * ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #ifndef _BYTEORDER_H_ #define _BYTEORDER_H_ /* ! * This file implements macros for machine independent short and ! * int manipulation ! */ #undef CAREFUL_ALIGNMENT /* we know that the 386 can handle misalignment and has the "right" ! * byteorder */ #ifdef __i386__ #define CAREFUL_ALIGNMENT 0 #endif *************** *** 44,50 **** #define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val)) typedef unsigned short uint16; ! typedef unsigned int uint32; #if CAREFUL_ALIGNMENT #define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8) --- 44,50 ---- #define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val)) typedef unsigned short uint16; ! typedef unsigned int uint32; #if CAREFUL_ALIGNMENT #define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8) *************** *** 59,69 **** #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val))) #else /* this handles things for architectures like the 386 that can handle ! alignment errors */ /* ! WARNING: This section is dependent on the length of int16 and int32 ! being correct ! */ #define SVAL(buf,pos) (*(uint16 *)((char *)(buf) + (pos))) #define IVAL(buf,pos) (*(uint32 *)((char *)(buf) + (pos))) #define SVALS(buf,pos) (*(int16 *)((char *)(buf) + (pos))) --- 59,69 ---- #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val))) #else /* this handles things for architectures like the 386 that can handle ! * alignment errors */ /* ! * WARNING: This section is dependent on the length of int16 and int32 ! * being correct ! */ #define SVAL(buf,pos) (*(uint16 *)((char *)(buf) + (pos))) #define IVAL(buf,pos) (*(uint32 *)((char *)(buf) + (pos))) #define SVALS(buf,pos) (*(int16 *)((char *)(buf) + (pos))) diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/confload.c squid-2.4.STABLE7/auth_modules/MSNT/confload.c *** squid-2.4.STABLE6/auth_modules/MSNT/confload.c Fri Nov 3 11:08:02 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/confload.c Wed Jun 26 13:24:43 2002 *************** *** 1,14 **** /* ! confload.c ! (C) 2000 Antonino Iannella, Stellar-X Pty Ltd ! Released under GPL, see COPYING-2.0 for details. ! ! These routines load the msntauth configuration file. ! It stores the servers to query, sets the denied and ! allowed user files, and provides the ! authenticating function. ! */ #include #include --- 1,14 ---- /* ! * confload.c ! * (C) 2000 Antonino Iannella, Stellar-X Pty Ltd ! * Released under GPL, see COPYING-2.0 for details. ! * ! * These routines load the msntauth configuration file. ! * It stores the servers to query, sets the denied and ! * allowed user files, and provides the ! * authenticating function. ! */ #include #include *************** *** 16,250 **** #include #include #include ! #define CONFIGFILE "/usr/local/squid/etc/msntauth.conf" /* Path to configuration file */ ! #define DENYUSERSDEFAULT "/usr/local/squid/etc/denyusers" ! #define ALLOWUSERSDEFAULT "/usr/local/squid/etc/allowusers" ! #define MAXSERVERS 5 /* Maximum number of servers to query. This number can be increased. */ #define NTHOSTLEN 65 ! extern char Denyuserpath[MAXPATHLEN]; /* MAXPATHLEN defined in param.h */ extern char Allowuserpath[MAXPATHLEN]; ! typedef struct _ServerTuple ! { ! char pdc[NTHOSTLEN]; ! char bdc[NTHOSTLEN]; ! char domain[NTHOSTLEN]; } ServerTuple; ! ServerTuple ServerArray[MAXSERVERS]; /* Array of servers to query */ ! int Serversqueried = 0; /* Number of servers queried */ /* Declarations */ ! int OpenConfigFile(); ! void ProcessLine(char *); ! void AddServer(char *, char *, char *); ! int QueryServers(char *, char *); ! int QueryServerForUser(int, char *, char *); ! extern int Valid_User(char *,char *,char *,char *, char *); ! /* ! Opens and reads the configuration file. ! Returns 0 on success, or 1 for error. ! */ ! int OpenConfigFile() { ! FILE *ConfigFile; ! char Confbuf[2049]; /* Line reading buffer */ ! /* Initialise defaults */ ! Serversqueried = 0; ! strcpy(Denyuserpath, DENYUSERSDEFAULT); ! strcpy(Allowuserpath, ALLOWUSERSDEFAULT); ! ! /* Open file */ ! if ((ConfigFile = fopen(CONFIGFILE, "r")) == NULL) ! { ! syslog(LOG_USER | LOG_ERR, "OpenConfigFile: Failed to open %s.", CONFIGFILE); ! syslog(LOG_USER | LOG_ERR, strerror(errno)); ! return 1; ! } ! ! /* Read in, one line at a time */ ! ! while (!feof(ConfigFile)) ! { ! Confbuf[0] = '\0'; ! fgets(Confbuf, 2049, ConfigFile); ! ProcessLine(Confbuf); ! } ! ! /* Check that at least one server is being queried. Report error if not. ! Denied and allowed user files are hardcoded, so it's fine if they're ! not set in the confugration file. */ ! ! if (Serversqueried == 0) ! { ! syslog(LOG_USER | LOG_ERR, "OpenConfigFile: No servers set in %s. At least one is needed.", CONFIGFILE); ! return 1; ! } ! fclose(ConfigFile); ! return 0; } /* Parses a configuration file line. */ ! void ProcessLine(char *Linebuf) { ! char *Directive; ! char *Param1; ! char *Param2; ! char *Param3; ! ! /* Ignore empty lines */ ! if (strlen(Linebuf) == 0) ! return; ! ! /* Break up on whitespaces */ ! if ((Directive = strtok(Linebuf, " \t\n")) == NULL) ! return; ! ! /* Check for a comment line. If found, stop . */ ! if (Directive[0] == '#') ! return; ! ! /* Check for server line. Check for 3 parameters. */ ! if (strcasecmp(Directive, "server") == 0) ! { ! Param1 = strtok(NULL, " \t\n"); ! Param2 = strtok(NULL, " \t\n"); ! Param3 = strtok(NULL, " \t\n"); ! ! if ((Param1[0] == '\0') || ! (Param2[0] == '\0') || ! (Param3[0] == '\0')) ! { ! syslog(LOG_USER | LOG_ERR, "ProcessLine: A 'server' line needs PDC, BDC, and domain parameters."); ! return; ! } ! ! AddServer(Param1, Param2, Param3); ! return; ! } ! ! /* Check for denyusers line */ ! if (strcasecmp(Directive, "denyusers") == 0) ! { ! Param1 = strtok(NULL, " \t\n"); ! ! if (Param1[0] == '\0') ! { ! syslog(LOG_USER | LOG_ERR, "ProcessLine: A 'denyusers' line needs a filename parameter."); ! return; ! } ! ! strcpy(Denyuserpath, Param1); ! return; ! } ! ! /* Check for allowusers line */ ! if (strcasecmp(Directive, "allowusers") == 0) ! { ! Param1 = strtok(NULL, " \t\n"); ! ! if (Param1[0] == '\0') ! { ! syslog(LOG_USER | LOG_ERR, "ProcessLine: An 'allowusers' line needs a filename parameter."); ! return; ! } ! ! strcpy(Allowuserpath, Param1); ! return; ! } ! ! /* Reports error for unknown line */ ! syslog(LOG_USER | LOG_ERR, "ProcessLine: Ignoring '%s' line.", Directive); } /* ! Adds a server to query to the server array. ! Checks if the number of servers to query is not exceeded. ! Does not allow parameters longer than NTHOSTLEN. ! */ ! void AddServer(char *ParamPDC, char *ParamBDC, char *ParamDomain) { ! if (Serversqueried + 1 > MAXSERVERS) ! { ! syslog(LOG_USER | LOG_ERR, "ProcessLine: Ignoring '%s' server line; too many servers.", ParamPDC); ! return; ! } ! ! Serversqueried++; ! strncpy(ServerArray[Serversqueried].pdc, ParamPDC, NTHOSTLEN); ! strncpy(ServerArray[Serversqueried].bdc, ParamBDC, NTHOSTLEN); ! strncpy(ServerArray[Serversqueried].domain, ParamDomain, NTHOSTLEN); ! ServerArray[Serversqueried].pdc[NTHOSTLEN - 1] = '\0'; ! ServerArray[Serversqueried].bdc[NTHOSTLEN - 1] = '\0'; ! ServerArray[Serversqueried].domain[NTHOSTLEN - 1] = '\0'; } /* ! Cycles through all servers to query. ! Returns 0 if one server could authenticate the user. ! Returns 1 if no server authenticated the user. ! */ ! int QueryServers(char *username, char *password) { ! int Queryresult = 1; /* Default result is an error */ ! int x = 1; ! ! while (x <= Serversqueried) ! { /* Query one server. Change Queryresult if user passed. */ ! if (QueryServerForUser(x++, username, password) == 0) ! { ! Queryresult = 0; ! break; } ! } ! ! return Queryresult; } /* ! Attempts to authenticate the user with one server. ! Logs syslog messages for different errors. ! Returns 0 on success, non-zero on failure. ! */ ! int QueryServerForUser(int x, char *username, char *password) { ! int result = 1; ! result = Valid_User(username, password, ServerArray[x].pdc, ! ServerArray[x].bdc, ServerArray[x].domain); ! switch (result) /* Write any helpful syslog messages */ ! { ! case 0 : break; ! case 1 : syslog(LOG_AUTHPRIV | LOG_INFO, "Server error when checking %s.", username); ! break; ! case 2 : syslog(LOG_AUTHPRIV | LOG_INFO, "Protocol error when checking %s.", username); ! break; ! case 3 : syslog(LOG_AUTHPRIV | LOG_INFO, "Authentication failed for %s.", username); ! } ! return result; } /* Valid_User return codes - ! ! 0 - User authenticated successfully. ! 1 - Server error. ! 2 - Protocol error. ! 3 - Logon error; Incorrect password or username given. ! */ ! --- 16,264 ---- #include #include #include + #include + #include ! #include "msntauth.h" ! #include "valid.h" ! /* Path to configuration file */ ! #ifndef SYSCONFDIR ! #define SYSCONFDIR "/usr/local/squid/etc" ! #endif ! #define CONFIGFILE SYSCONFDIR "/msntauth.conf" ! ! /* Maximum number of servers to query. This number can be increased. */ ! #define MAXSERVERS 5 #define NTHOSTLEN 65 ! extern char Denyuserpath[MAXPATHLEN]; /* MAXPATHLEN defined in param.h */ extern char Allowuserpath[MAXPATHLEN]; ! typedef struct _ServerTuple { ! char pdc[NTHOSTLEN]; ! char bdc[NTHOSTLEN]; ! char domain[NTHOSTLEN]; } ServerTuple; ! ServerTuple ServerArray[MAXSERVERS]; /* Array of servers to query */ ! int Serversqueried = 0; /* Number of servers queried */ /* Declarations */ ! static void ProcessLine(char *); ! static void AddServer(char *, char *, char *); ! static int QueryServerForUser(int, char *, char *); /* ! * Opens and reads the configuration file. ! * Returns 0 on success, or 1 for error. ! */ ! int ! OpenConfigFile(void) { ! FILE *ConfigFile; ! char Confbuf[2049]; /* Line reading buffer */ ! /* Initialise defaults */ ! Serversqueried = 0; ! memset(ServerArray, '\0', sizeof(ServerArray)); ! memset(Denyuserpath, '\0', MAXPATHLEN); ! memset(Allowuserpath, '\0', MAXPATHLEN); ! ! /* Open file */ ! if ((ConfigFile = fopen(CONFIGFILE, "r")) == NULL) { ! syslog(LOG_ERR, "OpenConfigFile: Failed to open %s.", CONFIGFILE); ! syslog(LOG_ERR, "%s", strerror(errno)); ! return 1; ! } ! /* Read in, one line at a time */ ! while (!feof(ConfigFile)) { ! Confbuf[0] = '\0'; ! if (NULL == fgets(Confbuf, 2048, ConfigFile)) ! break; ! Confbuf[2048] = '\0'; ! ProcessLine(Confbuf); ! } ! /* ! * Check that at least one server is being queried. Report error if not. ! * Denied and allowed user files are hardcoded, so it's fine if they're ! * not set in the confugration file. ! */ ! if (Serversqueried == 0) { ! syslog(LOG_ERR, "OpenConfigFile: No servers set in %s. At least one is needed.", CONFIGFILE); ! return 1; ! } ! fclose(ConfigFile); ! return 0; } /* Parses a configuration file line. */ ! static void ! ProcessLine(char *Linebuf) { ! char *Directive; ! char *Param1; ! char *Param2; ! char *Param3; ! ! /* Ignore empty lines */ ! if (strlen(Linebuf) == 0) ! return; ! ! /* Break up on whitespaces */ ! if ((Directive = strtok(Linebuf, " \t\n")) == NULL) ! return; ! ! /* Check for a comment line. If found, stop . */ ! if (Directive[0] == '#') ! return; ! ! /* Check for server line. Check for 3 parameters. */ ! if (strcasecmp(Directive, "server") == 0) { ! Param1 = strtok(NULL, " \t\n"); ! if (NULL == Param1) { ! syslog(LOG_ERR, "ProcessLine: 'server' missing PDC parameter."); ! return; ! } ! Param2 = strtok(NULL, " \t\n"); ! if (NULL == Param2) { ! syslog(LOG_ERR, "ProcessLine: 'server' missing BDC parameter."); ! return; ! } ! Param3 = strtok(NULL, " \t\n"); ! if (NULL == Param3) { ! syslog(LOG_ERR, "ProcessLine: 'server' missing domain parameter."); ! return; ! } ! AddServer(Param1, Param2, Param3); ! return; ! } ! /* Check for denyusers line */ ! if (strcasecmp(Directive, "denyusers") == 0) { ! Param1 = strtok(NULL, " \t\n"); ! ! if (NULL == Param1) { ! syslog(LOG_ERR, "ProcessLine: A 'denyusers' line needs a filename parameter."); ! return; ! } ! memset(Denyuserpath, '\0', MAXPATHLEN); ! strncpy(Denyuserpath, Param1, MAXPATHLEN - 1); ! return; ! } ! /* Check for allowusers line */ ! if (strcasecmp(Directive, "allowusers") == 0) { ! Param1 = strtok(NULL, " \t\n"); ! ! if (NULL == Param1) { ! syslog(LOG_ERR, "ProcessLine: An 'allowusers' line needs a filename parameter."); ! return; ! } ! memset(Allowuserpath, '\0', MAXPATHLEN); ! strncpy(Allowuserpath, Param1, MAXPATHLEN - 1); ! return; ! } ! /* Reports error for unknown line */ ! syslog(LOG_ERR, "ProcessLine: Ignoring '%s' line.", Directive); } /* ! * Adds a server to query to the server array. ! * Checks if the server IP is resolvable. ! * Checks if the number of servers to query is not exceeded. ! * Does not allow parameters longer than NTHOSTLEN. ! */ ! void ! AddServer(char *ParamPDC, char *ParamBDC, char *ParamDomain) { ! if (Serversqueried == MAXSERVERS) { ! syslog(LOG_ERR, "AddServer: Ignoring '%s' server line; " ! "too many servers.", ParamPDC); ! return; ! } ! if (gethostbyname(ParamPDC) == NULL) { ! syslog(LOG_ERR, "AddServer: Ignoring host '%s'. " ! "Cannot resolve its address.", ParamPDC); ! return; ! } ! if (gethostbyname(ParamBDC) == NULL) { ! syslog(LOG_USER | LOG_ERR, "AddServer: Ignoring host '%s'. " ! "Cannot resolve its address.", ParamBDC); ! return; ! } ! /* NOTE: ServerArray is zeroed in OpenConfigFile() */ ! assert(Serversqueried < MAXSERVERS); ! strncpy(ServerArray[Serversqueried].pdc, ParamPDC, NTHOSTLEN - 1); ! strncpy(ServerArray[Serversqueried].bdc, ParamBDC, NTHOSTLEN - 1); ! strncpy(ServerArray[Serversqueried].domain, ParamDomain, NTHOSTLEN - 1); ! Serversqueried++; } /* ! * Cycles through all servers to query. ! * Returns 0 if one server could authenticate the user. ! * Returns 1 if no server authenticated the user. ! */ ! int ! QueryServers(char *username, char *password) { ! int i; ! for (i = 0; i < Serversqueried; i++) { ! if (0 == QueryServerForUser(i, username, password)) ! return 0; } ! return 1; } /* ! * Attempts to authenticate the user with one server. ! * Logs syslog messages for different errors. ! * Returns 0 on success, non-zero on failure. ! */ ! ! /* Define for systems which don't support it, like Solaris */ ! #ifndef LOG_AUTHPRIV ! #define LOG_AUTHPRIV LOG_AUTH ! #endif ! static int ! QueryServerForUser(int x, char *username, char *password) { ! int result = 1; ! result = Valid_User(username, password, ServerArray[x].pdc, ! ServerArray[x].bdc, ServerArray[x].domain); ! switch (result) { /* Write any helpful syslog messages */ ! case 0: ! break; ! case 1: ! syslog(LOG_AUTHPRIV | LOG_INFO, "Server error when checking %s.", ! username); ! break; ! case 2: ! syslog(LOG_AUTHPRIV | LOG_INFO, "Protocol error when checking %s.", ! username); ! break; ! case 3: ! syslog(LOG_AUTHPRIV | LOG_INFO, "Authentication failed for %s.", ! username); ! break; ! } ! return result; } /* Valid_User return codes - ! * ! * 0 - User authenticated successfully. ! * 1 - Server error. ! * 2 - Protocol error. ! * 3 - Logon error; Incorrect password or username given. ! */ diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/denyusers.c squid-2.4.STABLE7/auth_modules/MSNT/denyusers.c *** squid-2.4.STABLE6/auth_modules/MSNT/denyusers.c Fri Nov 3 11:08:02 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/denyusers.c Wed Jun 26 13:24:43 2002 *************** *** 9,197 **** * Routines at the bottom also use the allowed user functions. */ - #include #include - #include - #include #include - #include - #include #include ! #include #include ! #define NAMELEN 50 /* Maximum username length */ ! ! /* Global variables */ ! ! char *DeniedUsers; /* Pointer to string of denied users */ ! off_t DenyUserSize; /* Size of denied user file */ ! struct stat FileBuf; /* Stat data buffer */ ! time_t LastModTime; /* Last denied user file modification time */ char Denyuserpath[MAXPATHLEN]; /* MAXPATHLEN defined in param.h */ ! /* Function declarations */ ! ! int Read_denyusers(); ! int Check_ifuserdenied(char *); ! int Check_user(char *); ! void Checktimer(); ! void Check_forchange(); ! void Check_fordenychange(); ! extern void Check_forallowchange(); /* For allowed users */ ! extern int Check_ifuserallowed(char *); ! ! /* ! * Reads Denyuserpath for all users to be excluded. ! * Returns 0 if the user list was successfully loaded, ! * and 1 in case of error. ! * Logs any messages to the syslog daemon. ! */ ! ! int ! Read_denyusers() { ! FILE *DFile; /* Denied user file pointer */ ! off_t DPos = 0; /* File counter */ ! char DChar; /* Character buffer */ ! ! /* Stat the file. If it does not exist, save the size as zero. ! * Clear the denied user string. Return. */ ! if (stat(Denyuserpath, &FileBuf) == -1) { ! if (errno == ENOENT) { ! LastModTime = (time_t) 0; ! DenyUserSize = 0; ! free(DeniedUsers); ! DeniedUsers = malloc(sizeof(char)); ! DeniedUsers[0] = '\0'; ! return 0; ! } else { ! syslog(LOG_USER | LOG_ERR, strerror(errno)); ! return 1; ! } ! } ! /* If it exists, save the modification time and size */ ! LastModTime = FileBuf.st_mtime; ! DenyUserSize = FileBuf.st_size; ! ! /* Handle the special case of a zero length file */ ! if (DenyUserSize == 0) { ! free(DeniedUsers); ! DeniedUsers = malloc(sizeof(char)); ! DeniedUsers[0] = '\0'; return 0; ! } ! /* Free and allocate space for a string to store the denied usernames */ ! free(DeniedUsers); ! ! if ((DeniedUsers = malloc(sizeof(char) * (DenyUserSize + 3))) == NULL) { ! syslog(LOG_USER | LOG_ERR, "Read_denyusers: malloc(DeniedUsers) failed."); ! return 1; ! } ! /* Open the denied user file. Report any errors. */ ! ! if ((DFile = fopen(Denyuserpath, "r")) == NULL) { ! syslog(LOG_USER | LOG_ERR, "Read_denyusers: Failed to open denied user file."); ! syslog(LOG_USER | LOG_ERR, strerror(errno)); ! return 1; ! } ! /* Read user names into the DeniedUsers string. ! * Make sure each string is delimited by a space. */ ! ! DeniedUsers[DPos++] = ' '; ! ! while (!feof(DFile)) { ! if ((DChar = fgetc(DFile)) == EOF) ! break; ! else { ! if (isspace(DChar)) ! DeniedUsers[DPos++] = ' '; ! else ! DeniedUsers[DPos++] = toupper(DChar); ! } ! } ! DeniedUsers[DPos++] = ' '; ! DeniedUsers[DPos] = '\0'; ! fclose(DFile); ! return 0; } /* * Check to see if the username provided by Squid appears in the denied * user list. Returns 0 if the user was not found, and 1 if they were. */ ! int Check_ifuserdenied(char *ConnectingUser) { - static char CUBuf[NAMELEN + 1]; - static int x; - static char DenyMsg[256]; - /* If user string is empty, deny */ if (ConnectingUser[0] == '\0') return 1; /* If denied user list is empty, allow */ ! if (DenyUserSize == 0) return 0; ! /* Check if username string is found in the denied user list. ! * If so, deny. If not, allow. Reconstruct the username ! * to have whitespace, to avoid finding wrong string subsets. */ ! ! sscanf(ConnectingUser, " %s ", CUBuf); ! sprintf(CUBuf, " %s ", CUBuf); ! ! for (x = 0; x <= strlen(CUBuf); x++) ! CUBuf[x] = toupper(CUBuf[x]); ! ! if (strstr(DeniedUsers, CUBuf) == NULL) ! return 0; ! else { ! sprintf(DenyMsg, "Denied access to user '%s'.", CUBuf); ! syslog(LOG_USER | LOG_ERR, DenyMsg); ! return 1; ! } ! } ! ! /* ! * Checks if there has been a change in the denied user file. ! * If the modification time has changed, then reload the denied user list. ! * This function is called by the SIGHUP signal handler. ! */ ! ! void ! Check_fordenychange() ! { ! struct stat ChkBuf; /* Stat data buffer */ ! ! /* Stat the denied user file. If it cannot be accessed, return. */ ! ! if (stat(Denyuserpath, &ChkBuf) == -1) { ! if (errno == ENOENT) { ! LastModTime = (time_t) 0; ! DenyUserSize = 0; ! free(DeniedUsers); ! DeniedUsers = malloc(sizeof(char)); ! DeniedUsers[0] = '\0'; ! return; ! } else { /* Report error when accessing file */ ! syslog(LOG_USER | LOG_ERR, strerror(errno)); ! return; ! } ! } ! /* If found, compare the modification time with the previously-recorded ! * modification time. ! * If the modification time has changed, reload the denied user list. ! * Log a message of its actions. */ ! ! if (ChkBuf.st_mtime != LastModTime) { ! syslog(LOG_USER | LOG_INFO, "Check_fordenychange: Reloading denied user list."); ! Read_denyusers(); ! } } /* --- 9,66 ---- * Routines at the bottom also use the allowed user functions. */ #include #include #include ! #include #include + #include + #include "usersfile.h" + #include "msntauth.h" ! static usersfile DenyUsers; ! static int init = 0; + /* shared */ char Denyuserpath[MAXPATHLEN]; /* MAXPATHLEN defined in param.h */ ! int ! Read_denyusers(void) { ! if (!init) { ! memset(&DenyUsers, '\0', sizeof(DenyUsers)); ! init = 1; ! } ! if (*Denyuserpath) ! return Read_usersfile(Denyuserpath, &DenyUsers); ! else return 0; ! } ! static void ! Check_fordenychange(void) ! { ! Check_forfilechange(&DenyUsers); } + /* * Check to see if the username provided by Squid appears in the denied * user list. Returns 0 if the user was not found, and 1 if they were. */ ! static int Check_ifuserdenied(char *ConnectingUser) { /* If user string is empty, deny */ if (ConnectingUser[0] == '\0') return 1; /* If denied user list is empty, allow */ ! if (DenyUsers.Inuse == 0) return 0; ! return Check_userlist(&DenyUsers, ConnectingUser); } /* *************** *** 200,206 **** * Else return 0. */ ! int Check_user(char *ConnectingUser) { if (Check_ifuserdenied(ConnectingUser) == 1) --- 69,75 ---- * Else return 0. */ ! int Check_user(char *ConnectingUser) { if (Check_ifuserdenied(ConnectingUser) == 1) *************** *** 218,225 **** * It is also run after every 60 seconds, at the next request. */ ! void ! Check_forchange() { Check_fordenychange(); Check_forallowchange(); --- 87,94 ---- * It is also run after every 60 seconds, at the next request. */ ! void ! Check_forchange(int signal) { Check_fordenychange(); Check_forallowchange(); *************** *** 231,237 **** * denied user file. If longer than one minute hasn't passed, return. */ ! void Checktimer() { static time_t Lasttime; /* The last time the timer was checked */ --- 100,106 ---- * denied user file. If longer than one minute hasn't passed, return. */ ! void Checktimer() { static time_t Lasttime; /* The last time the timer was checked */ *************** *** 243,249 **** if (difftime(Currenttime, Lasttime) < 60) return; else { ! Check_forchange(); Lasttime = Currenttime; } } --- 112,118 ---- if (difftime(Currenttime, Lasttime) < 60) return; else { ! Check_forchange(-1); Lasttime = Currenttime; } } diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/md4.c squid-2.4.STABLE7/auth_modules/MSNT/md4.c *** squid-2.4.STABLE6/auth_modules/MSNT/md4.c Wed Oct 20 12:50:40 1999 --- squid-2.4.STABLE7/auth_modules/MSNT/md4.c Wed Jun 26 13:24:43 2002 *************** *** 1,53 **** /* ! Unix SMB/Netbios implementation. ! Version 1.9. ! a implementation of MD4 designed for use in the SMB authentication protocol ! Copyright (C) Andrew Tridgell 1997 ! ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ /* NOTE: This code makes no attempt to be fast! ! ! It assumes that a int is at least 32 bits long ! */ typedef unsigned int uint32; static uint32 A, B, C, D; ! static uint32 F(uint32 X, uint32 Y, uint32 Z) { ! return (X&Y) | ((~X)&Z); } ! static uint32 G(uint32 X, uint32 Y, uint32 Z) { ! return (X&Y) | (X&Z) | (Y&Z); } ! static uint32 H(uint32 X, uint32 Y, uint32 Z) { ! return X^Y^Z; } ! static uint32 lshift(uint32 x, int s) { ! x &= 0xFFFFFFFF; ! return ((x<>(32-s)); } #define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s) --- 1,59 ---- /* ! * Unix SMB/Netbios implementation. ! * Version 1.9. ! * a implementation of MD4 designed for use in the SMB authentication protocol ! * Copyright (C) Andrew Tridgell 1997 ! * ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ + #include + #include "md4.h" /* NOTE: This code makes no attempt to be fast! ! * ! * It assumes that a int is at least 32 bits long ! */ typedef unsigned int uint32; static uint32 A, B, C, D; ! static uint32 ! F(uint32 X, uint32 Y, uint32 Z) { ! return (X & Y) | ((~X) & Z); } ! static uint32 ! G(uint32 X, uint32 Y, uint32 Z) { ! return (X & Y) | (X & Z) | (Y & Z); } ! static uint32 ! H(uint32 X, uint32 Y, uint32 Z) { ! return X ^ Y ^ Z; } ! static uint32 ! lshift(uint32 x, int s) { ! x &= 0xFFFFFFFF; ! return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s)); } #define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s) *************** *** 55,171 **** #define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + (uint32)0x6ED9EBA1,s) /* this applies md4 to 64 byte chunks */ ! static void mdfour64(uint32 *M) { ! int j; ! uint32 AA, BB, CC, DD; ! uint32 X[16]; ! ! for (j=0;j<16;j++) ! X[j] = M[j]; ! ! AA = A; BB = B; CC = C; DD = D; ! ! ROUND1(A,B,C,D, 0, 3); ROUND1(D,A,B,C, 1, 7); ! ROUND1(C,D,A,B, 2, 11); ROUND1(B,C,D,A, 3, 19); ! ROUND1(A,B,C,D, 4, 3); ROUND1(D,A,B,C, 5, 7); ! ROUND1(C,D,A,B, 6, 11); ROUND1(B,C,D,A, 7, 19); ! ROUND1(A,B,C,D, 8, 3); ROUND1(D,A,B,C, 9, 7); ! ROUND1(C,D,A,B, 10, 11); ROUND1(B,C,D,A, 11, 19); ! ROUND1(A,B,C,D, 12, 3); ROUND1(D,A,B,C, 13, 7); ! ROUND1(C,D,A,B, 14, 11); ROUND1(B,C,D,A, 15, 19); ! ! ROUND2(A,B,C,D, 0, 3); ROUND2(D,A,B,C, 4, 5); ! ROUND2(C,D,A,B, 8, 9); ROUND2(B,C,D,A, 12, 13); ! ROUND2(A,B,C,D, 1, 3); ROUND2(D,A,B,C, 5, 5); ! ROUND2(C,D,A,B, 9, 9); ROUND2(B,C,D,A, 13, 13); ! ROUND2(A,B,C,D, 2, 3); ROUND2(D,A,B,C, 6, 5); ! ROUND2(C,D,A,B, 10, 9); ROUND2(B,C,D,A, 14, 13); ! ROUND2(A,B,C,D, 3, 3); ROUND2(D,A,B,C, 7, 5); ! ROUND2(C,D,A,B, 11, 9); ROUND2(B,C,D,A, 15, 13); ! ! ROUND3(A,B,C,D, 0, 3); ROUND3(D,A,B,C, 8, 9); ! ROUND3(C,D,A,B, 4, 11); ROUND3(B,C,D,A, 12, 15); ! ROUND3(A,B,C,D, 2, 3); ROUND3(D,A,B,C, 10, 9); ! ROUND3(C,D,A,B, 6, 11); ROUND3(B,C,D,A, 14, 15); ! ROUND3(A,B,C,D, 1, 3); ROUND3(D,A,B,C, 9, 9); ! ROUND3(C,D,A,B, 5, 11); ROUND3(B,C,D,A, 13, 15); ! ROUND3(A,B,C,D, 3, 3); ROUND3(D,A,B,C, 11, 9); ! ROUND3(C,D,A,B, 7, 11); ROUND3(B,C,D,A, 15, 15); ! ! A += AA; B += BB; C += CC; D += DD; ! ! A &= 0xFFFFFFFF; B &= 0xFFFFFFFF; ! C &= 0xFFFFFFFF; D &= 0xFFFFFFFF; ! ! for (j=0;j<16;j++) ! X[j] = 0; ! } ! ! static void copy64(uint32 *M, unsigned char *in) ! { ! int i; ! ! for (i=0;i<16;i++) ! M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) | ! (in[i*4+1]<<8) | (in[i*4+0]<<0); ! } ! ! static void copy4(unsigned char *out,uint32 x) ! { ! out[0] = x&0xFF; ! out[1] = (x>>8)&0xFF; ! out[2] = (x>>16)&0xFF; ! out[3] = (x>>24)&0xFF; } /* produce a md4 message digest from data of length n bytes */ ! void mdfour(unsigned char *out, unsigned char *in, int n) { ! unsigned char buf[128]; ! uint32 M[16]; ! uint32 b = n * 8; ! int i; ! ! A = 0x67452301; ! B = 0xefcdab89; ! C = 0x98badcfe; ! D = 0x10325476; ! ! while (n > 64) { ! copy64(M, in); ! mdfour64(M); ! in += 64; ! n -= 64; ! } ! ! for (i=0;i<128;i++) ! buf[i] = 0; ! memcpy(buf, in, n); ! buf[n] = 0x80; ! ! if (n <= 55) { ! copy4(buf+56, b); ! copy64(M, buf); ! mdfour64(M); ! } else { ! copy4(buf+120, b); ! copy64(M, buf); ! mdfour64(M); ! copy64(M, buf+64); ! mdfour64(M); ! } ! for (i=0;i<128;i++) ! buf[i] = 0; copy64(M, buf); ! copy4(out, A); ! copy4(out+4, B); ! copy4(out+8, C); ! copy4(out+12, D); ! ! A = B = C = D = 0; } - - --- 61,211 ---- #define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + (uint32)0x6ED9EBA1,s) /* this applies md4 to 64 byte chunks */ ! static void ! mdfour64(uint32 * M) { ! int j; ! uint32 AA, BB, CC, DD; ! uint32 X[16]; ! ! for (j = 0; j < 16; j++) ! X[j] = M[j]; ! ! AA = A; ! BB = B; ! CC = C; ! DD = D; ! ! ROUND1(A, B, C, D, 0, 3); ! ROUND1(D, A, B, C, 1, 7); ! ROUND1(C, D, A, B, 2, 11); ! ROUND1(B, C, D, A, 3, 19); ! ROUND1(A, B, C, D, 4, 3); ! ROUND1(D, A, B, C, 5, 7); ! ROUND1(C, D, A, B, 6, 11); ! ROUND1(B, C, D, A, 7, 19); ! ROUND1(A, B, C, D, 8, 3); ! ROUND1(D, A, B, C, 9, 7); ! ROUND1(C, D, A, B, 10, 11); ! ROUND1(B, C, D, A, 11, 19); ! ROUND1(A, B, C, D, 12, 3); ! ROUND1(D, A, B, C, 13, 7); ! ROUND1(C, D, A, B, 14, 11); ! ROUND1(B, C, D, A, 15, 19); ! ! ROUND2(A, B, C, D, 0, 3); ! ROUND2(D, A, B, C, 4, 5); ! ROUND2(C, D, A, B, 8, 9); ! ROUND2(B, C, D, A, 12, 13); ! ROUND2(A, B, C, D, 1, 3); ! ROUND2(D, A, B, C, 5, 5); ! ROUND2(C, D, A, B, 9, 9); ! ROUND2(B, C, D, A, 13, 13); ! ROUND2(A, B, C, D, 2, 3); ! ROUND2(D, A, B, C, 6, 5); ! ROUND2(C, D, A, B, 10, 9); ! ROUND2(B, C, D, A, 14, 13); ! ROUND2(A, B, C, D, 3, 3); ! ROUND2(D, A, B, C, 7, 5); ! ROUND2(C, D, A, B, 11, 9); ! ROUND2(B, C, D, A, 15, 13); ! ! ROUND3(A, B, C, D, 0, 3); ! ROUND3(D, A, B, C, 8, 9); ! ROUND3(C, D, A, B, 4, 11); ! ROUND3(B, C, D, A, 12, 15); ! ROUND3(A, B, C, D, 2, 3); ! ROUND3(D, A, B, C, 10, 9); ! ROUND3(C, D, A, B, 6, 11); ! ROUND3(B, C, D, A, 14, 15); ! ROUND3(A, B, C, D, 1, 3); ! ROUND3(D, A, B, C, 9, 9); ! ROUND3(C, D, A, B, 5, 11); ! ROUND3(B, C, D, A, 13, 15); ! ROUND3(A, B, C, D, 3, 3); ! ROUND3(D, A, B, C, 11, 9); ! ROUND3(C, D, A, B, 7, 11); ! ROUND3(B, C, D, A, 15, 15); ! ! A += AA; ! B += BB; ! C += CC; ! D += DD; ! ! A &= 0xFFFFFFFF; ! B &= 0xFFFFFFFF; ! C &= 0xFFFFFFFF; ! D &= 0xFFFFFFFF; ! ! for (j = 0; j < 16; j++) ! X[j] = 0; ! } ! ! static void ! copy64(uint32 * M, unsigned char *in) ! { ! int i; ! ! for (i = 0; i < 16; i++) ! M[i] = (in[i * 4 + 3] << 24) | (in[i * 4 + 2] << 16) | ! (in[i * 4 + 1] << 8) | (in[i * 4 + 0] << 0); ! } ! ! static void ! copy4(unsigned char *out, uint32 x) ! { ! out[0] = x & 0xFF; ! out[1] = (x >> 8) & 0xFF; ! out[2] = (x >> 16) & 0xFF; ! out[3] = (x >> 24) & 0xFF; } /* produce a md4 message digest from data of length n bytes */ ! void ! mdfour(unsigned char *out, unsigned char *in, int n) { ! unsigned char buf[128]; ! uint32 M[16]; ! uint32 b = n * 8; ! int i; ! ! A = 0x67452301; ! B = 0xefcdab89; ! C = 0x98badcfe; ! D = 0x10325476; ! ! while (n > 64) { ! copy64(M, in); ! mdfour64(M); ! in += 64; ! n -= 64; ! } ! ! for (i = 0; i < 128; i++) ! buf[i] = 0; ! memcpy(buf, in, n); ! buf[n] = 0x80; ! if (n <= 55) { ! copy4(buf + 56, b); copy64(M, buf); + mdfour64(M); + } else { + copy4(buf + 120, b); + copy64(M, buf); + mdfour64(M); + copy64(M, buf + 64); + mdfour64(M); + } + + for (i = 0; i < 128; i++) + buf[i] = 0; + copy64(M, buf); + + copy4(out, A); + copy4(out + 4, B); + copy4(out + 8, C); + copy4(out + 12, D); ! A = B = C = D = 0; } diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/md4.h squid-2.4.STABLE7/auth_modules/MSNT/md4.h *** squid-2.4.STABLE6/auth_modules/MSNT/md4.h Wed Dec 31 17:00:00 1969 --- squid-2.4.STABLE7/auth_modules/MSNT/md4.h Wed Jun 26 13:24:43 2002 *************** *** 0 **** --- 1,2 ---- + /* md4.c */ + void mdfour(unsigned char *out, unsigned char *in, int n); diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/msntauth-v2.0.lsm squid-2.4.STABLE7/auth_modules/MSNT/msntauth-v2.0.lsm *** squid-2.4.STABLE6/auth_modules/MSNT/msntauth-v2.0.lsm Fri Nov 3 11:08:02 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/msntauth-v2.0.lsm Wed Jun 26 13:24:43 2002 *************** *** 1,13 **** Begin3 Title: msntauth Version: 2.0 ! Entered-date: 10OCT00 Description: Squid web proxy NT domain authentication module Keywords: Squid WWW proxy SMB NT domain authentication module source ! Author: antonino.iannella@usa.net (Antonino Iannella) ! Maintained-by: antonino.iannella@usa.net (Antonino Iannella) Primary-site: sunsite.unc.edu /pub/Linux/system/network/misc msntauth-v2.0.tgz ! Original-site: http://stellarx.tripod.com Copying-policy: GPL End --- 1,13 ---- Begin3 Title: msntauth Version: 2.0 ! Entered-date: 01SEP01 Description: Squid web proxy NT domain authentication module Keywords: Squid WWW proxy SMB NT domain authentication module source ! Author: antonino@rager.com.au (Antonino Iannella) ! Maintained-by: antonino@rager.com.au (Antonino Iannella) Primary-site: sunsite.unc.edu /pub/Linux/system/network/misc msntauth-v2.0.tgz ! Original-site: http://members.tripod.com/stellarx Copying-policy: GPL End diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/msntauth.c squid-2.4.STABLE7/auth_modules/MSNT/msntauth.c *** squid-2.4.STABLE6/auth_modules/MSNT/msntauth.c Fri Nov 3 11:08:02 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/msntauth.c Wed Jun 26 13:24:43 2002 *************** *** 1,121 **** /* ! MSNT - Microsoft Windows NT domain squid authenticator module ! Version 1.2 by Stellar-X Pty Ltd, Antonino Iannella ! Fri Sep 22 00:56:05 CST 2000 ! ! Modified to act as a Squid authenticator module. ! Removed all Pike stuff. ! Returns OK for a successful authentication, or ERR upon error. ! ! Uses code from - ! Andrew Tridgell 1997 ! Richard Sharpe 1996 ! Bill Welliver 1999 ! Duane Wessels 2000 ! ! Released under GNU Public License ! ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #include #include #include #include ! extern int OpenConfigFile(); ! extern int QueryServers(char *, char *); ! extern void Checktimer(); ! extern void Check_forchange(); ! extern int Read_denyusers(void); ! extern int Read_allowusers(void); ! extern int Check_user(char *); /* Main program for simple authentication. ! Reads the denied user file. Sets alarm timer. ! Scans and checks for Squid input, and attempts to validate the user. ! */ ! int main() { ! char username[256]; ! char password[256]; ! char wstr[256]; ! ! /* Read configuration file. Abort wildly if error. */ ! if (OpenConfigFile() == 1) ! return 1; ! ! /* Read denied and allowed user files. ! If they fails, there is a serious problem. ! Check syslog messages. Deny all users while in this state. ! The msntauth process should then be killed. */ ! ! if ((Read_denyusers() == 1) || (Read_allowusers() == 1)) ! { ! while (1) ! { ! fgets(wstr, 255, stdin); ! puts("ERR"); ! fflush(stdout); ! } ! } ! ! /* Make Check_forchange() the handle for HUP signals. ! Don't use alarms any more. I don't think it was very ! portable between systems. */ ! signal(SIGHUP, Check_forchange); ! ! while (1) ! { ! /* Read whole line from standard input. Terminate on break. */ ! if (fgets(wstr, 255, stdin) == NULL) ! break; ! ! /* Clear any current settings */ ! username[0] = '\0'; ! password[0] = '\0'; ! sscanf(wstr, "%s %s", username, password); /* Extract parameters */ ! ! /* Check for invalid or blank entries */ ! if ((username[0] == '\0') || (password[0] == '\0')) ! { ! puts("ERR"); ! fflush(stdout); ! continue; } ! ! Checktimer(); /* Check if the user lists have changed */ ! ! /* Check if user is explicitly denied or allowed. ! If user passes both checks, they can be authenticated. */ ! ! if (Check_user(username) == 1) ! puts("ERR"); ! else ! { ! if (QueryServers(username, password) == 0) ! puts("OK"); ! else ! puts("ERR"); } ! fflush(stdout); ! } ! ! return 0; } - --- 1,134 ---- /* ! * MSNT - Microsoft Windows NT domain squid authenticator module ! * Version 2.0 by Stellar-X Pty Ltd, Antonino Iannella ! * Sun Sep 2 14:39:53 CST 2001 ! * ! * Modified to act as a Squid authenticator module. ! * Removed all Pike stuff. ! * Returns OK for a successful authentication, or ERR upon error. ! * ! * Uses code from - ! * Andrew Tridgell 1997 ! * Richard Sharpe 1996 ! * Bill Welliver 1999 ! * Duane Wessels 2000 (wessels@squid-cache.org) ! * ! * Released under GNU Public License ! * ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #include #include #include + #include #include ! #include "msntauth.h" ! ! extern char version[]; ! char msntauth_version[] = "Msntauth v2.0.3 (C) 2 Sep 2001 Stellar-X Antonino Iannella.\nModified by the Squid HTTP Proxy team 26 Jun 2002"; /* Main program for simple authentication. ! * Reads the denied user file. Sets alarm timer. ! * Scans and checks for Squid input, and attempts to validate the user. ! */ ! int ! main(int argc, char **argv) { ! char username[256]; ! char password[256]; ! char wstr[256]; ! int err = 0; ! ! openlog("msnt_auth", LOG_PID, LOG_USER); ! setbuf(stdout, NULL); ! ! /* Read configuration file. Abort wildly if error. */ ! if (OpenConfigFile() == 1) ! return 1; ! ! /* ! * Read denied and allowed user files. ! * If they fails, there is a serious problem. ! * Check syslog messages. Deny all users while in this state. ! * The msntauth process should then be killed. ! */ ! if ((Read_denyusers() == 1) || (Read_allowusers() == 1)) { ! while (1) { ! memset(wstr, '\0', sizeof(wstr)); ! fgets(wstr, 255, stdin); ! puts("ERR"); ! } } ! /* ! * Make Check_forchange() the handle for HUP signals. ! * Don't use alarms any more. I don't think it was very ! * portable between systems. ! * XXX this should be sigaction() ! */ ! signal(SIGHUP, Check_forchange); ! ! while (1) { ! int n; ! /* Read whole line from standard input. Terminate on break. */ ! memset(wstr, '\0', sizeof(wstr)); ! if (fgets(wstr, 255, stdin) == NULL) ! break; ! /* ignore this line if we didn't get the end-of-line marker */ ! if (NULL == strchr(wstr, '\n')) { ! err = 1; ! continue; ! } ! if (err) ! goto error; ! ! /* ! * extract username and password. ! * XXX is sscanf() safe? ! */ ! username[0] = '\0'; ! password[0] = '\0'; ! n = sscanf(wstr, "%s %[^\n]", username, password); ! if (2 != n) { ! puts("ERR"); ! continue; ! } ! /* Check for invalid or blank entries */ ! if ((username[0] == '\0') || (password[0] == '\0')) { ! puts("ERR"); ! continue; ! } ! Checktimer(); /* Check if the user lists have changed */ ! ! /* ! * Check if user is explicitly denied or allowed. ! * If user passes both checks, they can be authenticated. ! */ ! if (Check_user(username) == 1) ! puts("ERR"); ! else if (QueryServers(username, password) == 0) ! puts("OK"); ! else { ! error: ! puts("ERR"); ! } ! err = 0; } ! return 0; } diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/msntauth.h squid-2.4.STABLE7/auth_modules/MSNT/msntauth.h *** squid-2.4.STABLE6/auth_modules/MSNT/msntauth.h Wed Dec 31 17:00:00 1969 --- squid-2.4.STABLE7/auth_modules/MSNT/msntauth.h Wed Jun 26 13:24:43 2002 *************** *** 0 **** --- 1,11 ---- + extern int OpenConfigFile(void); + extern int QueryServers(char *, char *); + extern void Checktimer(void); + extern void Check_forchange(int); + extern int Read_denyusers(void); + extern int Read_allowusers(void); + extern int Check_user(char *); + extern int QueryServers(char *, char *); + extern int Check_ifuserallowed(char *ConnectingUser); + extern void Check_forallowchange(void); + diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-common.h squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-common.h *** squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-common.h Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-common.h Wed Jun 26 13:24:43 2002 *************** *** 1,27 **** /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! ! Version 1.0 ! RFCNB Common Structures etc Defines ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #ifndef _RFCNB_COMMON_H_ #define _RFCNB_COMMON_H_ --- 1,27 ---- /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! * ! * Version 1.0 ! * RFCNB Common Structures etc Defines ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #ifndef _RFCNB_COMMON_H_ #define _RFCNB_COMMON_H_ *************** *** 30,38 **** typedef struct RFCNB_Pkt { ! char * data; /* The data in this portion */ ! int len; ! struct RFCNB_Pkt *next; } RFCNB_Pkt; --- 30,38 ---- typedef struct RFCNB_Pkt { ! char *data; /* The data in this portion */ ! int len; ! struct RFCNB_Pkt *next; } RFCNB_Pkt; diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-error.h squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-error.h *** squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-error.h Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-error.h Wed Jun 26 13:24:44 2002 *************** *** 1,57 **** /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! ! Version 1.0 ! RFCNB Error Response Defines ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #ifndef _RFCNB_ERROR_H_ #define _RFCNB_ERROR_H_ /* Error responses */ ! #define RFCNBE_Bad -1 /* Bad response */ #define RFCNBE_OK 0 ! /* these should follow the spec ... is there one ?*/ ! #define RFCNBE_NoSpace 1 /* Could not allocate space for a struct */ ! #define RFCNBE_BadName 2 /* Could not translate a name */ ! #define RFCNBE_BadRead 3 /* Read sys call failed */ ! #define RFCNBE_BadWrite 4 /* Write Sys call failed */ ! #define RFCNBE_ProtErr 5 /* Protocol Error */ ! #define RFCNBE_ConGone 6 /* Connection dropped */ ! #define RFCNBE_BadHandle 7 /* Handle passed was bad */ ! #define RFCNBE_BadSocket 8 /* Problems creating socket */ ! #define RFCNBE_ConnectFailed 9 /* Connect failed */ ! #define RFCNBE_CallRejNLOCN 10 /* Call rejected, not listening on CN */ ! #define RFCNBE_CallRejNLFCN 11 /* Call rejected, not listening for CN */ ! #define RFCNBE_CallRejCNNP 12 /* Call rejected, called name not present */ ! #define RFCNBE_CallRejInfRes 13/* Call rejetced, name ok, no resources */ ! #define RFCNBE_CallRejUnSpec 14/* Call rejected, unspecified error */ ! #define RFCNBE_BadParam 15/* Bad parameters passed ... */ ! #define RFCNBE_Timeout 16/* IO Timed out */ /* Text strings for the error responses */ ! extern char *RFCNB_Error_Strings[]; #endif /* _RFCNB_ERROR_H_ */ --- 1,57 ---- /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! * ! * Version 1.0 ! * RFCNB Error Response Defines ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #ifndef _RFCNB_ERROR_H_ #define _RFCNB_ERROR_H_ /* Error responses */ ! #define RFCNBE_Bad -1 /* Bad response */ #define RFCNBE_OK 0 ! /* these should follow the spec ... is there one ? */ ! #define RFCNBE_NoSpace 1 /* Could not allocate space for a struct */ ! #define RFCNBE_BadName 2 /* Could not translate a name */ ! #define RFCNBE_BadRead 3 /* Read sys call failed */ ! #define RFCNBE_BadWrite 4 /* Write Sys call failed */ ! #define RFCNBE_ProtErr 5 /* Protocol Error */ ! #define RFCNBE_ConGone 6 /* Connection dropped */ ! #define RFCNBE_BadHandle 7 /* Handle passed was bad */ ! #define RFCNBE_BadSocket 8 /* Problems creating socket */ ! #define RFCNBE_ConnectFailed 9 /* Connect failed */ ! #define RFCNBE_CallRejNLOCN 10 /* Call rejected, not listening on CN */ ! #define RFCNBE_CallRejNLFCN 11 /* Call rejected, not listening for CN */ ! #define RFCNBE_CallRejCNNP 12 /* Call rejected, called name not present */ ! #define RFCNBE_CallRejInfRes 13 /* Call rejetced, name ok, no resources */ ! #define RFCNBE_CallRejUnSpec 14 /* Call rejected, unspecified error */ ! #define RFCNBE_BadParam 15 /* Bad parameters passed ... */ ! #define RFCNBE_Timeout 16 /* IO Timed out */ /* Text strings for the error responses */ ! extern const char *RFCNB_Error_Strings[]; #endif /* _RFCNB_ERROR_H_ */ diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-io.c squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-io.c *** squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-io.c Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-io.c Wed Jun 26 13:24:44 2002 *************** *** 1,27 **** /* UNIX RFCNB (RFC1001/RFC1002) NEtBIOS implementation ! ! Version 1.0 ! RFCNB IO Routines ... ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ /* #include */ #include "std-includes.h" #include "rfcnb-priv.h" --- 1,27 ---- /* UNIX RFCNB (RFC1001/RFC1002) NEtBIOS implementation ! * ! * Version 1.0 ! * RFCNB IO Routines ... ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ /* #include */ #include "std-includes.h" #include "rfcnb-priv.h" *************** *** 29,423 **** #include "rfcnb-io.h" #include #include - int RFCNB_Timeout = 0; /* Timeout in seconds ... */ ! void rfcnb_alarm(int sig) { ! ! fprintf(stderr, "IO Timed out ...\n"); ! } /* Set timeout value and setup signal handling */ ! int RFCNB_Set_Timeout(int seconds) ! { ! #ifdef __GLIBC__ ! int temp; #endif ! /* If we are on a Bezerkeley system, use sigvec, else sigaction */ ! #ifndef SA_RESTART ! struct sigvec invec, outvec; #else ! struct sigaction inact, outact; ! #endif ! ! RFCNB_Timeout = seconds; ! ! if (RFCNB_Timeout > 0) { /* Set up handler to ignore but not restart */ ! ! #ifndef SA_RESTART ! invec.sv_handler = (void (*)())rfcnb_alarm; ! invec.sv_mask = 0; ! invec.sv_flags = SV_INTERRUPT; ! ! if (sigvec(SIGALRM, &invec, &outvec) < 0) ! return(-1); ! #else ! inact.sa_handler = (void (*)())rfcnb_alarm; ! #ifdef SOLARIS ! /* Solaris seems to have an array of vectors ... */ ! inact.sa_mask.__sigbits[0] = 0; ! inact.sa_mask.__sigbits[1] = 0; ! inact.sa_mask.__sigbits[2] = 0; ! inact.sa_mask.__sigbits[3] = 0; ! #else ! #ifdef __GLIBC__ ! for (temp = 0 ; temp < 32 ; temp ++) ! inact.sa_mask.__val[temp]=0; ! #else ! inact.sa_mask = 0; ! #endif ! #endif ! inact.sa_flags = 0; /* Don't restart */ ! ! if (sigaction(SIGALRM, &inact, &outact) < 0) ! return(-1); ! #endif ! ! } ! ! return(0); ! } - /* Discard the rest of an incoming packet as we do not have space for it - in the buffer we allocated or were passed ... */ ! int RFCNB_Discard_Rest(struct RFCNB_Con *con, int len) ! { char temp[100]; /* Read into here */ ! int rest, this_read, bytes_read; ! /* len is the amount we should read */ #ifdef RFCNB_DEBUG ! fprintf(stderr, "Discard_Rest called to discard: %i\n", len); #endif ! rest = len; ! while (rest > 0) { ! this_read = (rest > sizeof(temp)?sizeof(temp):rest); ! bytes_read = read(con -> fd, temp, this_read); ! if (bytes_read <= 0) { /* Error so return */ ! if (bytes_read < 0) ! RFCNB_errno = RFCNBE_BadRead; ! else ! RFCNB_errno = RFCNBE_ConGone; ! RFCNB_saved_errno = errno; ! return(RFCNBE_Bad); ! } ! ! rest = rest - bytes_read; ! } ! return(0); } /* Send an RFCNB packet to the connection. ! We just send each of the blocks linked together ... ! ! If we can, try to send it as one iovec ... ! ! */ ! ! int RFCNB_Put_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len) ! ! { int len_sent, tot_sent, this_len; ! struct RFCNB_Pkt *pkt_ptr; ! char *this_data; ! int i; ! struct iovec io_list[10]; /* We should never have more */ ! /* If we do, this will blow up ...*/ ! ! /* Try to send the data ... We only send as many bytes as len claims */ ! /* We should try to stuff it into an IOVEC and send as one write */ ! ! pkt_ptr = pkt; ! len_sent = tot_sent = 0; /* Nothing sent so far */ ! i = 0; ! while ((pkt_ptr != NULL) & (i < 10)) { /* Watch that magic number! */ ! this_len = pkt_ptr -> len; ! this_data = pkt_ptr -> data; ! if ((tot_sent + this_len) > len) ! this_len = len - tot_sent; /* Adjust so we don't send too much */ ! /* Now plug into the iovec ... */ ! io_list[i].iov_len = this_len; ! io_list[i].iov_base = this_data; ! i++; ! tot_sent += this_len; ! if (tot_sent == len) break; /* Let's not send too much */ ! pkt_ptr = pkt_ptr -> next; ! } #ifdef RFCNB_DEBUG ! fprintf(stderr, "Frags = %i, tot_sent = %i\n", i, tot_sent); #endif ! /* Set up an alarm if timeouts are set ... */ ! if (RFCNB_Timeout > 0) ! alarm(RFCNB_Timeout); ! if ((len_sent = writev(con -> fd, io_list, i)) < 0) { /* An error */ ! con -> rfc_errno = errno; ! if (errno == EINTR) /* We were interrupted ... */ ! RFCNB_errno = RFCNBE_Timeout; ! else ! RFCNB_errno = RFCNBE_BadWrite; ! RFCNB_saved_errno = errno; ! return(RFCNBE_Bad); ! ! } ! ! if (len_sent < tot_sent) { /* Less than we wanted */ ! if (errno == EINTR) /* We were interrupted */ ! RFCNB_errno = RFCNBE_Timeout; ! else ! RFCNB_errno = RFCNBE_BadWrite; ! RFCNB_saved_errno = errno; ! return(RFCNBE_Bad); ! } ! if (RFCNB_Timeout > 0) ! alarm(0); /* Reset that sucker */ #ifdef RFCNB_DEBUG ! fprintf(stderr, "Len sent = %i ...\n", len_sent); ! RFCNB_Print_Pkt(stderr, "sent", pkt, len_sent); /* Print what send ... */ #endif ! return(len_sent); } /* Read an RFCNB packet off the connection. - We read the first 4 bytes, that tells us the length, then read the - rest. We should implement a timeout, but we don't just yet - - */ ! int RFCNB_Get_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len) ! ! { int read_len, pkt_len; ! char hdr[RFCNB_Pkt_Hdr_Len]; /* Local space for the header */ ! struct RFCNB_Pkt *pkt_frag; ! int more, this_time, offset, frag_len, this_len; ! BOOL seen_keep_alive = TRUE; ! ! /* Read that header straight into the buffer */ ! if (len < RFCNB_Pkt_Hdr_Len) { /* What a bozo */ #ifdef RFCNB_DEBUG ! fprintf(stderr, "Trying to read less than a packet:"); ! perror(""); #endif ! RFCNB_errno = RFCNBE_BadParam; ! return(RFCNBE_Bad); ! ! } ! /* We discard keep alives here ... */ ! if (RFCNB_Timeout > 0) ! alarm(RFCNB_Timeout); ! while (seen_keep_alive) { ! if ((read_len = read(con -> fd, hdr, sizeof(hdr))) < 0) { /* Problems */ #ifdef RFCNB_DEBUG ! fprintf(stderr, "Reading the packet, we got:"); ! perror(""); #endif ! if (errno == EINTR) ! RFCNB_errno = RFCNBE_Timeout; ! else ! RFCNB_errno = RFCNBE_BadRead; ! RFCNB_saved_errno = errno; ! return(RFCNBE_Bad); ! ! } ! /* Now we check out what we got */ ! if (read_len == 0) { /* Connection closed, send back eof? */ #ifdef RFCNB_DEBUG ! fprintf(stderr, "Connection closed reading\n"); ! #endif ! ! if (errno == EINTR) ! RFCNB_errno = RFCNBE_Timeout; ! else ! RFCNB_errno = RFCNBE_ConGone; ! RFCNB_saved_errno = errno; ! return(RFCNBE_Bad); ! } ! if (RFCNB_Pkt_Type(hdr) == RFCNB_SESSION_KEEP_ALIVE) { #ifdef RFCNB_DEBUG ! fprintf(stderr, "RFCNB KEEP ALIVE received\n"); #endif ! ! } ! else { ! seen_keep_alive = FALSE; } ! } ! ! /* What if we got less than or equal to a hdr size in bytes? */ ! if (read_len < sizeof(hdr)) { /* We got a small packet */ ! /* Now we need to copy the hdr portion we got into the supplied packet */ ! memcpy(pkt -> data, hdr, read_len); /*Copy data */ #ifdef RFCNB_DEBUG ! RFCNB_Print_Pkt(stderr, "rcvd", pkt, read_len); #endif ! return(read_len); ! } ! ! /* Now, if we got at least a hdr size, alloc space for rest, if we need it */ ! pkt_len = RFCNB_Pkt_Len(hdr); #ifdef RFCNB_DEBUG ! fprintf(stderr, "Reading Pkt: Length = %i\n", pkt_len); ! #endif ! ! /* Now copy in the hdr */ ! memcpy(pkt -> data, hdr, sizeof(hdr)); ! /* Get the rest of the packet ... first figure out how big our buf is? */ ! /* And make sure that we handle the fragments properly ... Sure should */ ! /* use an iovec ... */ ! if (len < pkt_len) /* Only get as much as we have space for */ ! more = len - RFCNB_Pkt_Hdr_Len; ! else ! more = pkt_len; ! this_time = 0; ! /* We read for each fragment ... */ ! if (pkt -> len == read_len){ /* If this frag was exact size */ ! pkt_frag = pkt -> next; /* Stick next lot in next frag */ ! offset = 0; /* then we start at 0 in next */ ! } ! else { ! pkt_frag = pkt; /* Otherwise use rest of this frag */ ! offset = RFCNB_Pkt_Hdr_Len; /* Otherwise skip the header */ ! } ! frag_len = pkt_frag -> len; ! if (more <= frag_len) /* If len left to get less than frag space */ ! this_len = more; /* Get the rest ... */ ! else ! this_len = frag_len - offset; ! while (more > 0) { ! if ((this_time = read(con -> fd, (pkt_frag -> data) + offset, this_len)) <= 0) { /* Problems */ ! if (errno == EINTR) { ! RFCNB_errno = RFCNB_Timeout; ! } ! else { ! if (this_time < 0) ! RFCNB_errno = RFCNBE_BadRead; ! else ! RFCNB_errno = RFCNBE_ConGone; ! } ! RFCNB_saved_errno = errno; ! return(RFCNBE_Bad); ! } #ifdef RFCNB_DEBUG ! fprintf(stderr, "Frag_Len = %i, this_time = %i, this_len = %i, more = %i\n", frag_len, ! this_time, this_len, more); #endif ! read_len = read_len + this_time; /* How much have we read ... */ ! /* Now set up the next part */ ! if (pkt_frag -> next == NULL) break; /* That's it here */ ! pkt_frag = pkt_frag -> next; ! this_len = pkt_frag -> len; ! offset = 0; ! more = more - this_time; ! } #ifdef RFCNB_DEBUG ! fprintf(stderr,"Pkt Len = %i, read_len = %i\n", pkt_len, read_len); ! RFCNB_Print_Pkt(stderr, "rcvd", pkt, read_len + sizeof(hdr)); #endif ! if (read_len < (pkt_len + sizeof(hdr))) { /* Discard the rest */ ! return(RFCNB_Discard_Rest(con, (pkt_len + sizeof(hdr)) - read_len)); ! } ! ! if (RFCNB_Timeout > 0) ! alarm(0); /* Reset that sucker */ ! return(read_len + sizeof(RFCNB_Hdr)); } --- 29,397 ---- #include "rfcnb-io.h" #include #include + #include + #include + #include ! int RFCNB_Timeout = 0; /* Timeout in seconds ... */ + #ifdef NOT_USED + static void + rfcnb_alarm(int sig) { ! syslog(LOG_ERR, "%s:%d: IO Timed out ...\n", __FILE__, __LINE__); } + #endif /* Set timeout value and setup signal handling */ ! #ifdef NOT_USED ! static int ! RFCNB_Set_Timeout(int seconds) { ! #ifdef SA_RESTART ! struct sigaction sa; #endif ! int x; ! RFCNB_Timeout = seconds; ! if (RFCNB_Timeout <= 0) ! return 0; ! #ifdef SA_RESTART ! sa.sa_handler = rfcnb_alarm; ! sa.sa_flags = 0; ! sigemptyset(&sa.sa_mask); ! x = sigaction(SIGALRM, &sa, NULL); ! ; #else ! signal(SIGALRM, rfcnb_alarm); #endif ! if (x < 0) { ! syslog(LOG_ERR, "%s:%d: signal/sigaction: %s", __FILE__, __LINE__, strerror(errno)); ! return -1; ! } ! return 0; } + #endif ! /* ! * Discard the rest of an incoming packet as we do not have space for it ! * in the buffer we allocated or were passed ... ! */ ! static int ! RFCNB_Discard_Rest(struct RFCNB_Con *con, int len) ! { ! char temp[100]; /* Read into here */ ! int rest; ! int this_read; ! int bytes_read; ! /* len is the amount we should read */ #ifdef RFCNB_DEBUG ! fprintf(stderr, "Discard_Rest called to discard: %i\n", len); #endif ! rest = len; ! while (rest > 0) { ! this_read = (rest > sizeof(temp) ? sizeof(temp) : rest); ! bytes_read = read(con->fd, temp, this_read); ! if (bytes_read <= 0) { /* Error so return */ ! if (bytes_read < 0) ! RFCNB_errno = RFCNBE_BadRead; ! else ! RFCNB_errno = RFCNBE_ConGone; ! RFCNB_saved_errno = errno; ! return (RFCNBE_Bad); ! } ! rest = rest - bytes_read; ! } ! return (0); } /* Send an RFCNB packet to the connection. + * + * We just send each of the blocks linked together ... + * + * If we can, try to send it as one iovec ... + * + */ ! int ! RFCNB_Put_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len) ! { ! int len_sent = 0; ! int tot_sent = 0; ! int this_len; ! int i = 0; ! struct RFCNB_Pkt *pkt_ptr = pkt; ! char *this_data; ! struct iovec io_list[10]; /* We should never have more */ ! /* If we do, this will blow up ... */ ! /* Try to send the data ... We only send as many bytes as len claims */ ! /* We should try to stuff it into an IOVEC and send as one write */ ! while ((pkt_ptr != NULL) & (i < 10)) { /* Watch that magic number! */ ! this_len = pkt_ptr->len; ! this_data = pkt_ptr->data; ! if ((tot_sent + this_len) > len) ! this_len = len - tot_sent; /* Adjust so we don't send too much */ ! /* Now plug into the iovec ... */ ! io_list[i].iov_len = this_len; ! io_list[i].iov_base = this_data; ! i++; ! tot_sent += this_len; ! if (tot_sent == len) ! break; /* Let's not send too much */ ! pkt_ptr = pkt_ptr->next; ! } #ifdef RFCNB_DEBUG ! fprintf(stderr, "Frags = %i, tot_sent = %i\n", i, tot_sent); #endif ! /* Set up an alarm if timeouts are set ... */ ! if (RFCNB_Timeout > 0) ! alarm(RFCNB_Timeout); ! if ((len_sent = writev(con->fd, io_list, i)) < 0) { /* An error */ ! con->rfc_errno = errno; ! if (errno == EINTR) /* We were interrupted ... */ ! RFCNB_errno = RFCNBE_Timeout; ! else ! RFCNB_errno = RFCNBE_BadWrite; ! RFCNB_saved_errno = errno; ! return (RFCNBE_Bad); ! } ! if (len_sent < tot_sent) { /* Less than we wanted */ ! if (errno == EINTR) /* We were interrupted */ ! RFCNB_errno = RFCNBE_Timeout; ! else ! RFCNB_errno = RFCNBE_BadWrite; ! RFCNB_saved_errno = errno; ! return (RFCNBE_Bad); ! } ! if (RFCNB_Timeout > 0) ! alarm(0); /* Reset that sucker */ #ifdef RFCNB_DEBUG ! fprintf(stderr, "Len sent = %i ...\n", len_sent); ! RFCNB_Print_Pkt(stderr, "sent", pkt, len_sent); /* Print what send ... */ #endif ! return (len_sent); } /* Read an RFCNB packet off the connection. + * + * We read the first 4 bytes, that tells us the length, then read the + * rest. We should implement a timeout, but we don't just yet + * + */ + int + RFCNB_Get_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len) + { + int read_len, pkt_len; + char hdr[RFCNB_Pkt_Hdr_Len]; /* Local space for the header */ + struct RFCNB_Pkt *pkt_frag; + int more, this_time, offset, frag_len, this_len; + BOOL seen_keep_alive = TRUE; ! /* Read that header straight into the buffer */ ! if (len < RFCNB_Pkt_Hdr_Len) { /* What a bozo */ #ifdef RFCNB_DEBUG ! fprintf(stderr, "Trying to read less than a packet:"); ! perror(""); #endif ! RFCNB_errno = RFCNBE_BadParam; ! return (RFCNBE_Bad); ! } ! /* We discard keep alives here ... */ ! if (RFCNB_Timeout > 0) ! alarm(RFCNB_Timeout); ! while (seen_keep_alive) { ! if ((read_len = read(con->fd, hdr, sizeof(hdr))) < 0) { /* Problems */ #ifdef RFCNB_DEBUG ! fprintf(stderr, "Reading the packet, we got:"); ! perror(""); #endif ! if (errno == EINTR) ! RFCNB_errno = RFCNBE_Timeout; ! else ! RFCNB_errno = RFCNBE_BadRead; ! RFCNB_saved_errno = errno; ! return (RFCNBE_Bad); ! } ! /* Now we check out what we got */ ! if (read_len == 0) { /* Connection closed, send back eof? */ #ifdef RFCNB_DEBUG ! fprintf(stderr, "Connection closed reading\n"); ! #endif ! if (errno == EINTR) ! RFCNB_errno = RFCNBE_Timeout; ! else ! RFCNB_errno = RFCNBE_ConGone; ! RFCNB_saved_errno = errno; ! return (RFCNBE_Bad); ! } ! if (RFCNB_Pkt_Type(hdr) == RFCNB_SESSION_KEEP_ALIVE) { #ifdef RFCNB_DEBUG ! fprintf(stderr, "RFCNB KEEP ALIVE received\n"); #endif ! ! } else { ! seen_keep_alive = FALSE; ! } ! } ! /* What if we got less than or equal to a hdr size in bytes? */ ! if (read_len < sizeof(hdr)) { /* We got a small packet */ ! /* Now we need to copy the hdr portion we got into the supplied packet */ ! memcpy(pkt->data, hdr, read_len); /*Copy data */ #ifdef RFCNB_DEBUG ! RFCNB_Print_Pkt(stderr, "rcvd", pkt, read_len); #endif ! return (read_len); ! } ! /* Now, if we got at least a hdr size, alloc space for rest, if we need it */ ! pkt_len = RFCNB_Pkt_Len(hdr); #ifdef RFCNB_DEBUG ! fprintf(stderr, "Reading Pkt: Length = %i\n", pkt_len); ! #endif ! /* Now copy in the hdr */ ! memcpy(pkt->data, hdr, sizeof(hdr)); ! /* Get the rest of the packet ... first figure out how big our buf is? */ ! /* And make sure that we handle the fragments properly ... Sure should */ ! /* use an iovec ... */ ! if (len < pkt_len) /* Only get as much as we have space for */ ! more = len - RFCNB_Pkt_Hdr_Len; ! else ! more = pkt_len; ! this_time = 0; ! /* We read for each fragment ... */ ! if (pkt->len == read_len) { /* If this frag was exact size */ ! pkt_frag = pkt->next; /* Stick next lot in next frag */ ! offset = 0; /* then we start at 0 in next */ ! } else { ! pkt_frag = pkt; /* Otherwise use rest of this frag */ ! offset = RFCNB_Pkt_Hdr_Len; /* Otherwise skip the header */ ! } ! frag_len = pkt_frag->len; ! if (more <= frag_len) /* If len left to get less than frag space */ ! this_len = more; /* Get the rest ... */ ! else ! this_len = frag_len - offset; ! while (more > 0) { ! if ((this_time = read(con->fd, (pkt_frag->data) + offset, this_len)) <= 0) { /* Problems */ ! if (errno == EINTR) { ! RFCNB_errno = RFCNB_Timeout; ! } else { ! if (this_time < 0) ! RFCNB_errno = RFCNBE_BadRead; ! else ! RFCNB_errno = RFCNBE_ConGone; ! } ! RFCNB_saved_errno = errno; ! return (RFCNBE_Bad); + } #ifdef RFCNB_DEBUG ! fprintf(stderr, "Frag_Len = %i, this_time = %i, this_len = %i, more = %i\n", frag_len, ! this_time, this_len, more); #endif ! read_len = read_len + this_time; /* How much have we read ... */ ! /* Now set up the next part */ ! if (pkt_frag->next == NULL) ! break; /* That's it here */ ! pkt_frag = pkt_frag->next; ! this_len = pkt_frag->len; ! offset = 0; ! more = more - this_time; ! } #ifdef RFCNB_DEBUG ! fprintf(stderr, "Pkt Len = %i, read_len = %i\n", pkt_len, read_len); ! RFCNB_Print_Pkt(stderr, "rcvd", pkt, read_len + sizeof(hdr)); #endif ! if (read_len < (pkt_len + sizeof(hdr))) { /* Discard the rest */ ! return (RFCNB_Discard_Rest(con, (pkt_len + sizeof(hdr)) - read_len)); ! } ! if (RFCNB_Timeout > 0) ! alarm(0); /* Reset that sucker */ ! return (read_len + sizeof(RFCNB_Hdr)); } diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-io.h squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-io.h *** squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-io.h Wed Oct 20 12:50:43 1999 --- squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-io.h Wed Jun 26 13:24:44 2002 *************** *** 1,27 **** /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! ! Version 1.0 ! RFCNB IO Routines Defines ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ int RFCNB_Put_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len); --- 1,27 ---- /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! * ! * Version 1.0 ! * RFCNB IO Routines Defines ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ int RFCNB_Put_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len); diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-priv.h squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-priv.h *** squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-priv.h Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-priv.h Wed Jun 26 13:24:44 2002 *************** *** 1,27 **** /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! ! Version 1.0 ! RFCNB Defines ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ /* Defines we need */ --- 1,27 ---- /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! * ! * Version 1.0 ! * RFCNB Defines ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ /* Defines we need */ *************** *** 51,83 **** /* Structures */ ! typedef struct redirect_addr * redirect_ptr; struct redirect_addr { ! struct in_addr ip_addr; ! int port; ! redirect_ptr next; }; typedef struct RFCNB_Con { ! int fd; /* File descripter for TCP/IP connection */ ! int rfc_errno; /* last error */ ! int timeout; /* How many milli-secs before IO times out */ ! int redirects; /* How many times we were redirected */ ! struct redirect_addr *redirect_list; /* First is first address */ ! struct redirect_addr *last_addr; } RFCNB_Con; ! typedef char RFCNB_Hdr[4]; /* The header is 4 bytes long with */ ! /* char[0] as the type, char[1] the */ ! /* flags, and char[2..3] the length */ /* Macros to extract things from the header. These are for portability ! between architecture types where we are worried about byte order */ #define RFCNB_Pkt_Hdr_Len 4 #define RFCNB_Pkt_Sess_Len 72 --- 51,83 ---- /* Structures */ ! typedef struct redirect_addr *redirect_ptr; struct redirect_addr { ! struct in_addr ip_addr; ! int port; ! redirect_ptr next; }; typedef struct RFCNB_Con { ! int fd; /* File descripter for TCP/IP connection */ ! int rfc_errno; /* last error */ ! int timeout; /* How many milli-secs before IO times out */ ! int redirects; /* How many times we were redirected */ ! struct redirect_addr *redirect_list; /* First is first address */ ! struct redirect_addr *last_addr; } RFCNB_Con; ! typedef char RFCNB_Hdr[4]; /* The header is 4 bytes long with */ ! /* char[0] as the type, char[1] the */ ! /* flags, and char[2..3] the length */ /* Macros to extract things from the header. These are for portability ! * between architecture types where we are worried about byte order */ #define RFCNB_Pkt_Hdr_Len 4 #define RFCNB_Pkt_Sess_Len 72 *************** *** 85,91 **** #define RFCNB_Pkt_Nack_Len 5 #define RFCNB_Pkt_Type_Offset 0 #define RFCNB_Pkt_Flags_Offset 1 ! #define RFCNB_Pkt_Len_Offset 2 /* Length is 2 bytes plus a flag bit */ #define RFCNB_Pkt_N1Len_Offset 4 #define RFCNB_Pkt_Called_Offset 5 #define RFCNB_Pkt_N2Len_Offset 38 --- 85,91 ---- #define RFCNB_Pkt_Nack_Len 5 #define RFCNB_Pkt_Type_Offset 0 #define RFCNB_Pkt_Flags_Offset 1 ! #define RFCNB_Pkt_Len_Offset 2 /* Length is 2 bytes plus a flag bit */ #define RFCNB_Pkt_N1Len_Offset 4 #define RFCNB_Pkt_Called_Offset 5 #define RFCNB_Pkt_N2Len_Offset 38 *************** *** 95,101 **** #define RFCNB_Pkt_Port_Offset 8 /* The next macro isolates the length of a packet, including the bit in the ! flags */ #define RFCNB_Pkt_Len(p) (PVAL(p, 3) | (PVAL(p, 2) << 8) | \ ((PVAL(p, RFCNB_Pkt_Flags_Offset) & 0x01) << 16)) --- 95,101 ---- #define RFCNB_Pkt_Port_Offset 8 /* The next macro isolates the length of a packet, including the bit in the ! * flags */ #define RFCNB_Pkt_Len(p) (PVAL(p, 3) | (PVAL(p, 2) << 8) | \ ((PVAL(p, RFCNB_Pkt_Flags_Offset) & 0x01) << 16)) *************** *** 107,144 **** #define RFCNB_Pkt_Type(p) (CVAL(p, RFCNB_Pkt_Type_Offset)) /*typedef struct RFCNB_Hdr { ! ! unsigned char type; ! unsigned char flags; ! int16 len; ! ! } RFCNB_Hdr; ! ! typedef struct RFCNB_Sess_Pkt { ! unsigned char type; ! unsigned char flags; ! int16 length; ! unsigned char n1_len; ! char called_name[33]; ! unsigned char n2_len; ! char calling_name[33]; ! } RFCNB_Sess_Pkt; ! ! ! typedef struct RFCNB_Nack_Pkt { ! ! struct RFCNB_Hdr hdr; ! unsigned char error; ! ! } RFCNB_Nack_Pkt; ! ! typedef struct RFCNB_Retarget_Pkt { ! ! struct RFCNB_Hdr hdr; ! int dest_ip; ! unsigned char port; ! ! } RFCNB_Redir_Pkt; */ /* Static variables */ --- 107,144 ---- #define RFCNB_Pkt_Type(p) (CVAL(p, RFCNB_Pkt_Type_Offset)) /*typedef struct RFCNB_Hdr { ! * ! * unsigned char type; ! * unsigned char flags; ! * int16 len; ! * ! * } RFCNB_Hdr; ! * ! * typedef struct RFCNB_Sess_Pkt { ! * unsigned char type; ! * unsigned char flags; ! * int16 length; ! * unsigned char n1_len; ! * char called_name[33]; ! * unsigned char n2_len; ! * char calling_name[33]; ! * } RFCNB_Sess_Pkt; ! * ! * ! * typedef struct RFCNB_Nack_Pkt { ! * ! * struct RFCNB_Hdr hdr; ! * unsigned char error; ! * ! * } RFCNB_Nack_Pkt; ! * ! * typedef struct RFCNB_Retarget_Pkt { ! * ! * struct RFCNB_Hdr hdr; ! * int dest_ip; ! * unsigned char port; ! * ! * } RFCNB_Redir_Pkt; */ /* Static variables */ *************** *** 146,150 **** #ifndef RFCNB_ERRNO extern int RFCNB_errno; ! extern int RFCNB_saved_errno; /* Save this from point of error */ #endif --- 146,150 ---- #ifndef RFCNB_ERRNO extern int RFCNB_errno; ! extern int RFCNB_saved_errno; /* Save this from point of error */ #endif diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-util.c squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-util.c *** squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-util.c Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-util.c Wed Jun 26 13:24:44 2002 *************** *** 1,27 **** /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! ! Version 1.0 ! RFCNB Utility Routines ... ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #include "std-includes.h" #include "rfcnb-priv.h" --- 1,27 ---- /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! * ! * Version 1.0 ! * RFCNB Utility Routines ... ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #include "std-includes.h" #include "rfcnb-priv.h" *************** *** 36,562 **** #include #include ! char *RFCNB_Error_Strings[] = { ! "RFCNBE_OK: Routine completed successfully.", ! "RFCNBE_NoSpace: No space available for a malloc call.", ! "RFCNBE_BadName: NetBIOS name could not be translated to IP address.", ! "RFCNBE_BadRead: Read system call returned an error. Check errno.", ! "RFCNBE_BadWrite: Write system call returned an error. Check errno.", ! "RFCNBE_ProtErr: A protocol error has occurred.", ! "RFCNBE_ConGone: Connection dropped during a read or write system call.", ! "RFCNBE_BadHandle: Bad connection handle passed.", ! "RFCNBE_BadSocket: Problems creating socket.", ! "RFCNBE_ConnectFailed: Connection failed. See errno.", ! "RFCNBE_CallRejNLOCN: Call rejected. Not listening on called name.", ! "RFCNBE_CallRejNLFCN: Call rejected. Not listening for called name.", ! "RFCNBE_CallRejCNNP: Call rejected. Called name not present.", ! "RFCNBE_CallRejInfRes: Call rejected. Name present, but insufficient resources.", ! "RFCNBE_CallRejUnSpec: Call rejected. Unspecified error.", ! "RFCNBE_BadParam: Bad parameters passed to a routine.", ! "RFCNBE_Timeout: IO Operation timed out ..." }; ! extern void (*Prot_Print_Routine)(); /* Pointer to protocol print routine */ /* Convert name and pad to 16 chars as needed */ /* Name 1 is a C string with null termination, name 2 may not be */ /* If SysName is true, then put a <00> on end, else space> */ ! void RFCNB_CvtPad_Name(char *name1, char *name2) ! { char c, c1, c2; ! int i, len; ! len = strlen(name1); ! for (i = 0; i < 16; i++) { ! if (i >= len) { ! c1 = 'C'; c2 = 'A'; /* CA is a space */ ! ! } else { ! c = name1[i]; ! c1 = (char)((int)c/16 + (int)'A'); ! c2 = (char)((int)c%16 + (int)'A'); ! } ! name2[i*2] = c1; ! name2[i*2+1] = c2; ! } ! name2[32] = 0; /* Put in the nll ...*/ } /* Converts an Ascii NB Name (16 chars) to an RFCNB Name (32 chars) ! Uses the encoding in RFC1001. Each nibble of byte is added to 'A' ! to produce the next byte in the name. ! ! This routine assumes that AName is 16 bytes long and that NBName has ! space for 32 chars, so be careful ... ! */ ! ! void RFCNB_AName_To_NBName(char *AName, char *NBName) ! ! { char c, c1, c2; ! int i; ! for (i=0; i < 16; i++) { ! c = AName[i]; ! c1 = (char)((c >> 4) + 'A'); ! c2 = (char)((c & 0xF) + 'A'); ! NBName[i*2] = c1; ! NBName[i*2+1] = c2; ! } ! NBName[32] = 0; /* Put in a null */ } /* Do the reverse of the above ... */ ! void RFCNB_NBName_To_AName(char *NBName, char *AName) ! ! { char c, c1, c2; ! int i; ! for (i=0; i < 16; i++) { ! c1 = NBName[i*2]; ! c2 = NBName[i*2+1]; ! c = (char)(((int)c1 - (int)'A') * 16 + ((int)c2 - (int)'A')); ! AName[i] = c; ! } ! AName[i] = 0; /* Put a null on the end ... */ } /* Print a string of bytes in HEX etc */ ! void RFCNB_Print_Hex(FILE *fd, struct RFCNB_Pkt *pkt, int Offset, int Len) ! ! { char c1, c2, outbuf1[33]; ! unsigned char c; ! int i, j; ! struct RFCNB_Pkt *pkt_ptr = pkt; ! static char Hex_List[17] = "0123456789ABCDEF"; ! ! j = 0; ! ! /* We only want to print as much as sepcified in Len */ ! ! while (pkt_ptr != NULL) { ! for (i = 0; ! i < ((Len > (pkt_ptr -> len)?pkt_ptr -> len:Len) - Offset); ! i++) { ! c = pkt_ptr -> data[i + Offset]; ! c1 = Hex_List[c >> 4]; ! c2 = Hex_List[c & 0xF]; ! outbuf1[j++] = c1; outbuf1[j++] = c2; - if (j == 32){ /* Print and reset */ outbuf1[j] = 0; fprintf(fd, " %s\n", outbuf1); - j = 0; - } } ! ! Offset = 0; ! Len = Len - pkt_ptr -> len; /* Reduce amount by this much */ ! pkt_ptr = pkt_ptr -> next; ! ! } ! ! /* Print last lot in the buffer ... */ ! ! if (j > 0) { ! ! outbuf1[j] = 0; ! fprintf(fd, " %s\n", outbuf1); ! ! } ! ! fprintf(fd, "\n"); } /* Get a packet of size n */ ! struct RFCNB_Pkt *RFCNB_Alloc_Pkt(int n) ! ! { RFCNB_Pkt *pkt; ! ! if ((pkt = (struct RFCNB_Pkt *)malloc(sizeof(struct RFCNB_Pkt))) == NULL) { ! ! RFCNB_errno = RFCNBE_NoSpace; ! RFCNB_saved_errno = errno; ! return(NULL); ! ! } ! ! pkt -> next = NULL; ! pkt -> len = n; ! ! if (n == 0) return(pkt); ! ! if ((pkt -> data = (char *)malloc(n)) == NULL) { ! RFCNB_errno = RFCNBE_NoSpace; ! RFCNB_saved_errno = errno; ! free(pkt); ! return(NULL); ! } ! return(pkt); } /* Free up a packet */ ! void RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt) ! ! { struct RFCNB_Pkt *pkt_next; char *data_ptr; ! ! while (pkt != NULL) { ! pkt_next = pkt -> next; ! data_ptr = pkt -> data; ! if (data_ptr != NULL) ! free(data_ptr); ! free(pkt); ! pkt = pkt_next; ! } } /* Print an RFCNB packet */ ! void RFCNB_Print_Pkt(FILE *fd, char *dirn, struct RFCNB_Pkt *pkt, int len) ! ! { char lname[17]; ! /* We assume that the first fragment is the RFCNB Header */ ! /* We should loop through the fragments printing them out */ ! fprintf(fd, "RFCNB Pkt %s:", dirn); ! switch (RFCNB_Pkt_Type(pkt -> data)) { ! case RFCNB_SESSION_MESSAGE: ! fprintf(fd, "SESSION MESSAGE: Length = %i\n", RFCNB_Pkt_Len(pkt -> data)); ! RFCNB_Print_Hex(fd, pkt, RFCNB_Pkt_Hdr_Len, #ifdef RFCNB_PRINT_DATA ! RFCNB_Pkt_Len(pkt -> data) - RFCNB_Pkt_Hdr_Len); #else ! 40); #endif ! if (Prot_Print_Routine != 0) { /* Print the rest of the packet */ ! ! Prot_Print_Routine(fd, strcmp(dirn, "sent"), pkt, RFCNB_Pkt_Hdr_Len, ! RFCNB_Pkt_Len(pkt -> data) - RFCNB_Pkt_Hdr_Len); ! ! } ! break; ! case RFCNB_SESSION_REQUEST: ! fprintf(fd, "SESSION REQUEST: Length = %i\n", ! RFCNB_Pkt_Len(pkt -> data)); ! RFCNB_NBName_To_AName((char *)(pkt -> data + RFCNB_Pkt_Called_Offset), lname); ! fprintf(fd, " Called Name: %s\n", lname); ! RFCNB_NBName_To_AName((char *)(pkt -> data + RFCNB_Pkt_Calling_Offset), lname); ! fprintf(fd, " Calling Name: %s\n", lname); ! break; ! case RFCNB_SESSION_ACK: ! fprintf(fd, "RFCNB SESSION ACK: Length = %i\n", ! RFCNB_Pkt_Len(pkt -> data)); ! break; ! case RFCNB_SESSION_REJ: ! fprintf(fd, "RFCNB SESSION REJECT: Length = %i\n", ! RFCNB_Pkt_Len(pkt -> data)); ! if (RFCNB_Pkt_Len(pkt -> data) < 1) { ! fprintf(fd, " Protocol Error, short Reject packet!\n"); ! } ! else { ! fprintf(fd, " Error = %x\n", CVAL(pkt -> data, RFCNB_Pkt_Error_Offset)); ! } ! break; ! case RFCNB_SESSION_RETARGET: ! fprintf(fd, "RFCNB SESSION RETARGET: Length = %i\n", ! RFCNB_Pkt_Len(pkt -> data)); ! /* Print out the IP address etc and the port? */ ! break; ! case RFCNB_SESSION_KEEP_ALIVE: ! fprintf(fd, "RFCNB SESSION KEEP ALIVE: Length = %i\n", ! RFCNB_Pkt_Len(pkt -> data)); ! break; default: ! break; ! } } /* Resolve a name into an address */ ! int RFCNB_Name_To_IP(char *host, struct in_addr *Dest_IP) ! ! { int addr; /* Assumes IP4, 32 bit network addresses */ ! struct hostent *hp; ! /* Use inet_addr to try to convert the address */ ! if ((addr = inet_addr(host)) == INADDR_NONE) { /* Oh well, a good try :-) */ ! /* Now try a name look up with gethostbyname */ ! if ((hp = gethostbyname(host)) == NULL) { /* Not in DNS */ ! /* Try NetBIOS name lookup, how the hell do we do that? */ ! RFCNB_errno = RFCNBE_BadName; /* Is this right? */ ! RFCNB_saved_errno = errno; ! return(RFCNBE_Bad); ! } ! else { /* We got a name */ ! memcpy((void *)Dest_IP, (void *)hp -> h_addr_list[0], sizeof(struct in_addr)); ! } ! } ! else { /* It was an IP address */ ! memcpy((void *)Dest_IP, (void *)&addr, sizeof(struct in_addr)); ! } ! return 0; } /* Disconnect the TCP connection to the server */ ! int RFCNB_Close(int socket) ! { ! close(socket); ! /* If we want to do error recovery, here is where we put it */ ! return 0; } /* Connect to the server specified in the IP address. ! Not sure how to handle socket options etc. */ ! ! int RFCNB_IP_Connect(struct in_addr Dest_IP, int port) ! { struct sockaddr_in Socket; ! int fd; ! ! /* Create a socket */ ! if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { /* Handle the error */ ! RFCNB_errno = RFCNBE_BadSocket; ! RFCNB_saved_errno = errno; ! return(RFCNBE_Bad); ! } ! bzero((char *)&Socket, sizeof(Socket)); ! memcpy((char *)&Socket.sin_addr, (char *)&Dest_IP, sizeof(Dest_IP)); ! Socket.sin_port = htons(port); ! Socket.sin_family = PF_INET; ! /* Now connect to the destination */ ! if (connect(fd, (struct sockaddr *)&Socket, sizeof(Socket)) < 0) { /* Error */ ! close(fd); ! RFCNB_errno = RFCNBE_ConnectFailed; ! RFCNB_saved_errno = errno; ! return(RFCNBE_Bad); } ! ! return(fd); } /* handle the details of establishing the RFCNB session with remote ! end ! ! */ ! ! int RFCNB_Session_Req(struct RFCNB_Con *con, ! char *Called_Name, ! char *Calling_Name, ! BOOL *redirect, ! struct in_addr *Dest_IP, ! int * port) ! ! { char *sess_pkt; ! ! /* Response packet should be no more than 9 bytes, make 16 jic */ ! char resp[16]; ! int len; ! struct RFCNB_Pkt *pkt, res_pkt; ! /* We build and send the session request, then read the response */ ! pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Sess_Len); ! if (pkt == NULL) { ! return(RFCNBE_Bad); /* Leave the error that RFCNB_Alloc_Pkt gives) */ ! } ! sess_pkt = pkt -> data; /* Get pointer to packet proper */ ! sess_pkt[RFCNB_Pkt_Type_Offset] = RFCNB_SESSION_REQUEST; ! RFCNB_Put_Pkt_Len(sess_pkt, (RFCNB_Pkt_Sess_Len-RFCNB_Pkt_Hdr_Len)); ! sess_pkt[RFCNB_Pkt_N1Len_Offset] = 32; ! sess_pkt[RFCNB_Pkt_N2Len_Offset] = 32; ! RFCNB_CvtPad_Name(Called_Name, (sess_pkt + RFCNB_Pkt_Called_Offset)); ! RFCNB_CvtPad_Name(Calling_Name, (sess_pkt + RFCNB_Pkt_Calling_Offset)); ! /* Now send the packet */ #ifdef RFCNB_DEBUG ! fprintf(stderr, "Sending packet: "); ! #endif ! if ((len = RFCNB_Put_Pkt(con, pkt, RFCNB_Pkt_Sess_Len)) < 0) { ! return(RFCNBE_Bad); /* Should be able to write that lot ... */ } - #ifdef RFCNB_DEBUG ! fprintf(stderr, "Getting packet.\n"); #endif ! res_pkt.data = resp; ! res_pkt.len = sizeof(resp); ! res_pkt.next = NULL; ! if ((len = RFCNB_Get_Pkt(con, &res_pkt, sizeof(resp))) < 0) { ! return(RFCNBE_Bad); ! } ! /* Now analyze the packet ... */ ! switch (RFCNB_Pkt_Type(resp)) { ! case RFCNB_SESSION_REJ: /* Didnt like us ... too bad */ ! /* Why did we get rejected ? */ ! ! switch (CVAL(resp,RFCNB_Pkt_Error_Offset)) { ! case 0x80: ! RFCNB_errno = RFCNBE_CallRejNLOCN; ! break; ! case 0x81: ! RFCNB_errno = RFCNBE_CallRejNLFCN; ! break; ! case 0x82: ! RFCNB_errno = RFCNBE_CallRejCNNP; break; - case 0x83: - RFCNB_errno = RFCNBE_CallRejInfRes; - break; - case 0x8F: - RFCNB_errno = RFCNBE_CallRejUnSpec; - break; - default: - RFCNB_errno = RFCNBE_ProtErr; - break; - } - - return(RFCNBE_Bad); - break; ! case RFCNB_SESSION_ACK: /* Got what we wanted ... */ ! return(0); ! break; ! case RFCNB_SESSION_RETARGET: /* Go elsewhere */ ! *redirect = TRUE; /* Copy port and ip addr */ ! memcpy(Dest_IP, (resp + RFCNB_Pkt_IP_Offset), sizeof(struct in_addr)); ! *port = SVAL(resp, RFCNB_Pkt_Port_Offset); ! return(0); ! break; ! default: /* A protocol error */ ! RFCNB_errno = RFCNBE_ProtErr; ! return(RFCNBE_Bad); ! break; } } - - - - - - - - - --- 36,554 ---- #include #include ! const char *RFCNB_Error_Strings[] = ! { ! "RFCNBE_OK: Routine completed successfully.", ! "RFCNBE_NoSpace: No space available for a malloc call.", ! "RFCNBE_BadName: NetBIOS name could not be translated to IP address.", ! "RFCNBE_BadRead: Read system call returned an error. Check errno.", ! "RFCNBE_BadWrite: Write system call returned an error. Check errno.", ! "RFCNBE_ProtErr: A protocol error has occurred.", ! "RFCNBE_ConGone: Connection dropped during a read or write system call.", ! "RFCNBE_BadHandle: Bad connection handle passed.", ! "RFCNBE_BadSocket: Problems creating socket.", ! "RFCNBE_ConnectFailed: Connection failed. See errno.", ! "RFCNBE_CallRejNLOCN: Call rejected. Not listening on called name.", ! "RFCNBE_CallRejNLFCN: Call rejected. Not listening for called name.", ! "RFCNBE_CallRejCNNP: Call rejected. Called name not present.", ! "RFCNBE_CallRejInfRes: Call rejected. Name present, but insufficient resources.", ! "RFCNBE_CallRejUnSpec: Call rejected. Unspecified error.", ! "RFCNBE_BadParam: Bad parameters passed to a routine.", ! "RFCNBE_Timeout: IO Operation timed out ..." }; ! #ifdef RFCNB_DEBUG ! extern void (*Prot_Print_Routine) (); /* Pointer to protocol print routine */ ! #endif /* Convert name and pad to 16 chars as needed */ /* Name 1 is a C string with null termination, name 2 may not be */ /* If SysName is true, then put a <00> on end, else space> */ ! void ! RFCNB_CvtPad_Name(char *name1, char *name2) ! { ! char c, c1, c2; ! int i, len; ! len = strlen(name1); ! for (i = 0; i < 16; i++) { ! if (i >= len) { ! c1 = 'C'; ! c2 = 'A'; /* CA is a space */ ! } else { ! c = name1[i]; ! c1 = (char) ((int) c / 16 + (int) 'A'); ! c2 = (char) ((int) c % 16 + (int) 'A'); ! } ! name2[i * 2] = c1; ! name2[i * 2 + 1] = c2; ! } ! name2[32] = 0; /* Put in the nll ... */ } /* Converts an Ascii NB Name (16 chars) to an RFCNB Name (32 chars) ! * Uses the encoding in RFC1001. Each nibble of byte is added to 'A' ! * to produce the next byte in the name. ! * ! * This routine assumes that AName is 16 bytes long and that NBName has ! * space for 32 chars, so be careful ... ! * ! */ ! void ! RFCNB_AName_To_NBName(char *AName, char *NBName) ! { ! char c, c1, c2; ! int i; ! for (i = 0; i < 16; i++) { ! c = AName[i]; ! c1 = (char) ((c >> 4) + 'A'); ! c2 = (char) ((c & 0xF) + 'A'); ! NBName[i * 2] = c1; ! NBName[i * 2 + 1] = c2; ! } ! NBName[32] = 0; /* Put in a null */ } /* Do the reverse of the above ... */ ! void ! RFCNB_NBName_To_AName(char *NBName, char *AName) ! { ! char c, c1, c2; ! int i; ! for (i = 0; i < 16; i++) { ! c1 = NBName[i * 2]; ! c2 = NBName[i * 2 + 1]; ! c = (char) (((int) c1 - (int) 'A') * 16 + ((int) c2 - (int) 'A')); ! AName[i] = c; ! } ! AName[i] = 0; /* Put a null on the end ... */ } + #ifdef RFCNB_DEBUG /* Print a string of bytes in HEX etc */ ! void ! RFCNB_Print_Hex(FILE * fd, struct RFCNB_Pkt *pkt, int Offset, int Len) ! { ! char c1, c2, outbuf1[33]; ! unsigned char c; ! int i, j; ! struct RFCNB_Pkt *pkt_ptr = pkt; ! static char Hex_List[17] = "0123456789ABCDEF"; ! ! j = 0; ! ! /* We only want to print as much as sepcified in Len */ ! ! while (pkt_ptr != NULL) { ! ! for (i = 0; ! i < ((Len > (pkt_ptr->len) ? pkt_ptr->len : Len) - Offset); ! i++) { ! ! c = pkt_ptr->data[i + Offset]; ! c1 = Hex_List[c >> 4]; ! c2 = Hex_List[c & 0xF]; ! ! outbuf1[j++] = c1; ! outbuf1[j++] = c2; ! ! if (j == 32) { /* Print and reset */ ! outbuf1[j] = 0; ! fprintf(fd, " %s\n", outbuf1); ! j = 0; ! } ! } ! ! Offset = 0; ! Len = Len - pkt_ptr->len; /* Reduce amount by this much */ ! pkt_ptr = pkt_ptr->next; ! } ! /* Print last lot in the buffer ... */ ! if (j > 0) { outbuf1[j] = 0; fprintf(fd, " %s\n", outbuf1); } ! fprintf(fd, "\n"); } + #endif /* Get a packet of size n */ ! struct RFCNB_Pkt * ! RFCNB_Alloc_Pkt(int n) ! { ! RFCNB_Pkt *pkt; ! if ((pkt = malloc(sizeof(struct RFCNB_Pkt))) == NULL) { ! RFCNB_errno = RFCNBE_NoSpace; ! RFCNB_saved_errno = errno; ! return (NULL); ! } ! pkt->next = NULL; ! pkt->len = n; ! if (n == 0) ! return (pkt); ! if ((pkt->data = malloc(n)) == NULL) { ! RFCNB_errno = RFCNBE_NoSpace; ! RFCNB_saved_errno = errno; ! free(pkt); ! return (NULL); ! } ! return (pkt); } /* Free up a packet */ ! void ! RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt) ! { ! struct RFCNB_Pkt *pkt_next; ! while (pkt != NULL) { ! pkt_next = pkt->next; ! if (pkt->data != NULL) ! free(pkt->data); ! free(pkt); ! pkt = pkt_next; ! } } + #ifdef RFCNB_DEBUG /* Print an RFCNB packet */ ! void ! RFCNB_Print_Pkt(FILE * fd, char *dirn, struct RFCNB_Pkt *pkt, int len) ! { ! char lname[17]; ! /* We assume that the first fragment is the RFCNB Header */ ! /* We should loop through the fragments printing them out */ ! fprintf(fd, "RFCNB Pkt %s:", dirn); ! switch (RFCNB_Pkt_Type(pkt->data)) { ! case RFCNB_SESSION_MESSAGE: ! fprintf(fd, "SESSION MESSAGE: Length = %i\n", RFCNB_Pkt_Len(pkt->data)); ! RFCNB_Print_Hex(fd, pkt, RFCNB_Pkt_Hdr_Len, #ifdef RFCNB_PRINT_DATA ! RFCNB_Pkt_Len(pkt->data) - RFCNB_Pkt_Hdr_Len); #else ! 40); #endif ! if (Prot_Print_Routine != 0) { /* Print the rest of the packet */ ! Prot_Print_Routine(fd, strcmp(dirn, "sent"), pkt, RFCNB_Pkt_Hdr_Len, ! RFCNB_Pkt_Len(pkt->data) - RFCNB_Pkt_Hdr_Len); ! } ! break; ! case RFCNB_SESSION_REQUEST: ! fprintf(fd, "SESSION REQUEST: Length = %i\n", ! RFCNB_Pkt_Len(pkt->data)); ! RFCNB_NBName_To_AName((char *) (pkt->data + RFCNB_Pkt_Called_Offset), lname); ! fprintf(fd, " Called Name: %s\n", lname); ! RFCNB_NBName_To_AName((char *) (pkt->data + RFCNB_Pkt_Calling_Offset), lname); ! fprintf(fd, " Calling Name: %s\n", lname); ! break; ! case RFCNB_SESSION_ACK: ! fprintf(fd, "RFCNB SESSION ACK: Length = %i\n", ! RFCNB_Pkt_Len(pkt->data)); ! break; ! case RFCNB_SESSION_REJ: ! fprintf(fd, "RFCNB SESSION REJECT: Length = %i\n", ! RFCNB_Pkt_Len(pkt->data)); ! ! if (RFCNB_Pkt_Len(pkt->data) < 1) { ! fprintf(fd, " Protocol Error, short Reject packet!\n"); ! } else { ! fprintf(fd, " Error = %x\n", CVAL(pkt->data, RFCNB_Pkt_Error_Offset)); ! } ! break; ! case RFCNB_SESSION_RETARGET: ! fprintf(fd, "RFCNB SESSION RETARGET: Length = %i\n", ! RFCNB_Pkt_Len(pkt->data)); ! /* Print out the IP address etc and the port? */ ! break; ! case RFCNB_SESSION_KEEP_ALIVE: ! fprintf(fd, "RFCNB SESSION KEEP ALIVE: Length = %i\n", ! RFCNB_Pkt_Len(pkt->data)); ! break; default: ! break; ! } } + #endif /* Resolve a name into an address */ ! int ! RFCNB_Name_To_IP(char *host, struct in_addr *Dest_IP) ! { ! int addr; /* Assumes IP4, 32 bit network addresses */ ! struct hostent *hp; ! /* Use inet_addr to try to convert the address */ ! if ((addr = inet_addr(host)) == INADDR_NONE) { /* Oh well, a good try :-) */ ! /* Now try a name look up with gethostbyname */ ! if ((hp = gethostbyname(host)) == NULL) { /* Not in DNS */ ! /* Try NetBIOS name lookup, how the hell do we do that? */ ! RFCNB_errno = RFCNBE_BadName; /* Is this right? */ ! RFCNB_saved_errno = errno; ! return (RFCNBE_Bad); ! } else { /* We got a name */ ! memcpy((void *) Dest_IP, (void *) hp->h_addr_list[0], sizeof(struct in_addr)); ! } ! } else { /* It was an IP address */ ! memcpy((void *) Dest_IP, (void *) &addr, sizeof(struct in_addr)); ! } ! return 0; } /* Disconnect the TCP connection to the server */ ! int ! RFCNB_Close(int socket) { ! close(socket); ! /* If we want to do error recovery, here is where we put it */ ! return 0; } /* Connect to the server specified in the IP address. ! * Not sure how to handle socket options etc. */ ! int ! RFCNB_IP_Connect(struct in_addr Dest_IP, int port) ! { ! struct sockaddr_in Socket; ! int fd; ! /* Create a socket */ ! if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { /* Handle the error */ ! RFCNB_errno = RFCNBE_BadSocket; ! RFCNB_saved_errno = errno; ! return (RFCNBE_Bad); ! } ! bzero((char *) &Socket, sizeof(Socket)); ! memcpy((char *) &Socket.sin_addr, (char *) &Dest_IP, sizeof(Dest_IP)); ! Socket.sin_port = htons(port); ! Socket.sin_family = PF_INET; ! /* Now connect to the destination */ ! if (connect(fd, (struct sockaddr *) &Socket, sizeof(Socket)) < 0) { /* Error */ ! close(fd); ! RFCNB_errno = RFCNBE_ConnectFailed; ! RFCNB_saved_errno = errno; ! return (RFCNBE_Bad); } ! return (fd); } /* handle the details of establishing the RFCNB session with remote ! * end ! * ! */ ! ! int ! RFCNB_Session_Req(struct RFCNB_Con *con, ! char *Called_Name, ! char *Calling_Name, ! BOOL * redirect, ! struct in_addr *Dest_IP, ! int *port) ! { ! char *sess_pkt; ! /* Response packet should be no more than 9 bytes, make 16 jic */ ! char resp[16]; ! int len; ! struct RFCNB_Pkt *pkt, res_pkt; ! /* We build and send the session request, then read the response */ ! pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Sess_Len); ! if (pkt == NULL) { ! return (RFCNBE_Bad); /* Leave the error that RFCNB_Alloc_Pkt gives) */ ! } ! sess_pkt = pkt->data; /* Get pointer to packet proper */ ! sess_pkt[RFCNB_Pkt_Type_Offset] = RFCNB_SESSION_REQUEST; ! RFCNB_Put_Pkt_Len(sess_pkt, (RFCNB_Pkt_Sess_Len - RFCNB_Pkt_Hdr_Len)); ! sess_pkt[RFCNB_Pkt_N1Len_Offset] = 32; ! sess_pkt[RFCNB_Pkt_N2Len_Offset] = 32; ! RFCNB_CvtPad_Name(Called_Name, (sess_pkt + RFCNB_Pkt_Called_Offset)); ! RFCNB_CvtPad_Name(Calling_Name, (sess_pkt + RFCNB_Pkt_Calling_Offset)); ! /* Now send the packet */ #ifdef RFCNB_DEBUG ! fprintf(stderr, "Sending packet: "); ! #endif ! if ((len = RFCNB_Put_Pkt(con, pkt, RFCNB_Pkt_Sess_Len)) < 0) { ! return (RFCNBE_Bad); /* Should be able to write that lot ... */ } #ifdef RFCNB_DEBUG ! fprintf(stderr, "Getting packet.\n"); #endif ! res_pkt.data = resp; ! res_pkt.len = sizeof(resp); ! res_pkt.next = NULL; ! if ((len = RFCNB_Get_Pkt(con, &res_pkt, sizeof(resp))) < 0) { ! return (RFCNBE_Bad); ! } ! /* Now analyze the packet ... */ ! switch (RFCNB_Pkt_Type(resp)) { ! case RFCNB_SESSION_REJ: /* Didnt like us ... too bad */ ! /* Why did we get rejected ? */ ! switch (CVAL(resp, RFCNB_Pkt_Error_Offset)) { ! ! case 0x80: ! RFCNB_errno = RFCNBE_CallRejNLOCN; ! break; ! case 0x81: ! RFCNB_errno = RFCNBE_CallRejNLFCN; ! break; ! case 0x82: ! RFCNB_errno = RFCNBE_CallRejCNNP; ! break; ! case 0x83: ! RFCNB_errno = RFCNBE_CallRejInfRes; ! break; ! case 0x8F: ! RFCNB_errno = RFCNBE_CallRejUnSpec; ! break; ! default: ! RFCNB_errno = RFCNBE_ProtErr; ! break; ! } ! return (RFCNBE_Bad); break; ! case RFCNB_SESSION_ACK: /* Got what we wanted ... */ ! return (0); ! break; ! case RFCNB_SESSION_RETARGET: /* Go elsewhere */ ! *redirect = TRUE; /* Copy port and ip addr */ ! memcpy(Dest_IP, (resp + RFCNB_Pkt_IP_Offset), sizeof(struct in_addr)); ! *port = SVAL(resp, RFCNB_Pkt_Port_Offset); ! return (0); ! break; ! default: /* A protocol error */ ! RFCNB_errno = RFCNBE_ProtErr; ! return (RFCNBE_Bad); ! break; } } diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-util.h squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-util.h *** squid-2.4.STABLE6/auth_modules/MSNT/rfcnb-util.h Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/rfcnb-util.h Wed Jun 26 13:24:44 2002 *************** *** 1,27 **** /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! ! Version 1.0 ! RFCNB Utility Defines ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ void RFCNB_CvtPad_Name(char *name1, char *name2); --- 1,27 ---- /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! * ! * Version 1.0 ! * RFCNB Utility Defines ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ void RFCNB_CvtPad_Name(char *name1, char *name2); *************** *** 29,39 **** void RFCNB_NBName_To_AName(char *NBName, char *AName); ! void RFCNB_Print_Hex(FILE *fd, struct RFCNB_Pkt *pkt, int Offset, int Len); struct RFCNB_Pkt *RFCNB_Alloc_Pkt(int n); ! void RFCNB_Print_Pkt(FILE *fd, char *dirn, struct RFCNB_Pkt *pkt, int len); int RFCNB_Name_To_IP(char *host, struct in_addr *Dest_IP); --- 29,39 ---- void RFCNB_NBName_To_AName(char *NBName, char *AName); ! void RFCNB_Print_Hex(FILE * fd, struct RFCNB_Pkt *pkt, int Offset, int Len); struct RFCNB_Pkt *RFCNB_Alloc_Pkt(int n); ! void RFCNB_Print_Pkt(FILE * fd, char *dirn, struct RFCNB_Pkt *pkt, int len); int RFCNB_Name_To_IP(char *host, struct in_addr *Dest_IP); *************** *** 41,51 **** int RFCNB_IP_Connect(struct in_addr Dest_IP, int port); ! int RFCNB_Session_Req(RFCNB_Con *con, ! char *Called_Name, ! char *Calling_Name, ! BOOL *redirect, ! struct in_addr *Dest_IP, ! int * port); void RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt); --- 41,51 ---- int RFCNB_IP_Connect(struct in_addr Dest_IP, int port); ! int RFCNB_Session_Req(RFCNB_Con * con, ! char *Called_Name, ! char *Calling_Name, ! BOOL * redirect, ! struct in_addr *Dest_IP, ! int *port); void RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt); diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/rfcnb.h squid-2.4.STABLE7/auth_modules/MSNT/rfcnb.h *** squid-2.4.STABLE6/auth_modules/MSNT/rfcnb.h Wed Oct 20 12:50:45 1999 --- squid-2.4.STABLE7/auth_modules/MSNT/rfcnb.h Wed Jun 26 13:24:44 2002 *************** *** 1,27 **** /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! ! Version 1.0 ! RFCNB Defines ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ /* Error responses */ --- 1,27 ---- /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! * ! * Version 1.0 ! * RFCNB Defines ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ /* Error responses */ *************** *** 34,48 **** /* Definition of routines we define */ ! void *RFCNB_Call(char *Called_Name, char *Calling_Name, char *Called_Address, ! int port); ! int RFCNB_Send(void *Con_Handle, struct RFCNB_Pkt *Data, int Length); ! int RFCNB_Recv(void *Con_Handle, struct RFCNB_Pkt *Data, int Length); ! int RFCNB_Hangup(void *con_Handle); ! void *RFCNB_Listen(); void RFCNB_Get_Error(char *buffer, int buf_len); --- 34,52 ---- /* Definition of routines we define */ ! struct RFCNB_Con; ! void *RFCNB_Call(char *Called_Name, char *Calling_Name, char *Called_Address, ! int port); ! int RFCNB_Send(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *Data, int Length); ! int RFCNB_Recv(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *Data, int Length); ! int RFCNB_Hangup(struct RFCNB_Con *Con_Handle); void RFCNB_Get_Error(char *buffer, int buf_len); + int RFCNB_Get_Last_Error(void); + int RFCNB_Get_Last_Errno(void); + void RFCNB_Get_Error_Msg(int code, char *msg_buf, int len); + diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/session.c squid-2.4.STABLE7/auth_modules/MSNT/session.c *** squid-2.4.STABLE6/auth_modules/MSNT/session.c Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/session.c Wed Jun 26 13:24:44 2002 *************** *** 1,27 **** /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! ! Version 1.0 ! Session Routines ... ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ int RFCNB_errno = 0; int RFCNB_saved_errno = 0; --- 1,27 ---- /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation ! * ! * Version 1.0 ! * Session Routines ... ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ int RFCNB_errno = 0; int RFCNB_saved_errno = 0; *************** *** 32,37 **** --- 32,38 ---- #include "rfcnb-priv.h" #include "rfcnb-util.h" #include "rfcnb-io.h" + #include "rfcnb.h" #include #include *************** *** 39,370 **** int RFCNB_Stats[RFCNB_MAX_STATS]; ! void (*Prot_Print_Routine)() = NULL; /* Pointer to print routine */ /* Set up a session with a remote name. We are passed Called_Name as a ! string which we convert to a NetBIOS name, ie space terminated, up to ! 16 characters only if we need to. If Called_Address is not empty, then ! we use it to connect to the remote end, but put in Called_Name ... Called ! Address can be a DNS based name, or a TCP/IP address ... ! */ ! ! void *RFCNB_Call(char *Called_Name, char *Calling_Name, char *Called_Address, ! int port) ! ! { struct RFCNB_Con *con; ! struct in_addr Dest_IP; ! int Client; ! BOOL redirect; struct redirect_addr *redir_addr; ! char *Service_Address; ! /* Now, we really should look up the port in /etc/services ... */ ! if (port == 0) port = RFCNB_Default_Port; ! /* Create a connection structure first */ ! if ((con = (struct RFCNB_Con *)malloc(sizeof(struct RFCNB_Con))) == NULL) { /* Error in size */ ! RFCNB_errno = RFCNBE_NoSpace; ! RFCNB_saved_errno = errno; ! return(NULL); } ! ! con -> fd = -0; /* no descriptor yet */ ! con -> rfc_errno = 0; /* no error yet */ ! con -> timeout = 0; /* no timeout */ ! con -> redirects = 0; ! con -> redirect_list = NULL; /* Fix bug still in version 0.50 */ ! ! /* Resolve that name into an IP address */ ! ! Service_Address = Called_Name; ! if (strcmp(Called_Address, "") != 0) { /* If the Called Address = "" */ ! Service_Address = Called_Address; ! } ! ! if ((errno = RFCNB_Name_To_IP(Service_Address, &Dest_IP)) < 0) { /* Error */ ! /* No need to modify RFCNB_errno as it was done by RFCNB_Name_To_IP */ ! return(NULL); } ! /* Now connect to the remote end */ ! redirect = TRUE; /* Fudge this one so we go once through */ ! while (redirect) { /* Connect and get session info etc */ ! redirect = FALSE; /* Assume all OK */ ! /* Build the redirect info. First one is first addr called */ ! /* And tack it onto the list of addresses we called */ ! if ((redir_addr = (struct redirect_addr *)malloc(sizeof(struct redirect_addr))) == NULL) { /* Could not get space */ ! ! RFCNB_errno = RFCNBE_NoSpace; ! RFCNB_saved_errno = errno; ! return(NULL); ! } ! memcpy((char *)&(redir_addr -> ip_addr), (char *)&Dest_IP, sizeof(Dest_IP)); ! redir_addr -> port = port; ! redir_addr -> next = NULL; ! if (con -> redirect_list == NULL) { /* Stick on head */ ! con -> redirect_list = con -> last_addr = redir_addr; ! } else { ! con -> last_addr -> next = redir_addr; ! con -> last_addr = redir_addr; ! } ! /* Now, make that connection */ ! if ((Client = RFCNB_IP_Connect(Dest_IP, port)) < 0) { /* Error */ ! /* No need to modify RFCNB_errno as it was done by RFCNB_IP_Connect */ ! return(NULL); ! } ! con -> fd = Client; ! /* Now send and handle the RFCNB session request */ ! /* If we get a redirect, we will comeback with redirect true ! and a new IP address in DEST_IP */ ! if ((errno = RFCNB_Session_Req(con, ! Called_Name, ! Calling_Name, ! &redirect, &Dest_IP, &port)) < 0) { ! /* No need to modify RFCNB_errno as it was done by RFCNB_Session.. */ ! return(NULL); ! } ! if (redirect) { ! /* We have to close the connection, and then try again */ ! ! (con -> redirects)++; ! ! RFCNB_Close(con -> fd); /* Close it */ ! ! } } ! return(con); } /* We send a packet to the other end ... for the moment, we treat the ! data as a series of pointers to blocks of data ... we should check the ! length ... */ ! ! int RFCNB_Send(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *udata, int Length) ! { struct RFCNB_Pkt *pkt; char *hdr; ! int len; ! ! /* Plug in the header and send the data */ ! pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len); ! if (pkt == NULL) { ! RFCNB_errno = RFCNBE_NoSpace; ! RFCNB_saved_errno = errno; ! return(RFCNBE_Bad); ! } ! pkt -> next = udata; /* The user data we want to send */ ! hdr = pkt -> data; ! /* Following crap is for portability across multiple UNIX machines */ ! *(hdr + RFCNB_Pkt_Type_Offset) = RFCNB_SESSION_MESSAGE; ! RFCNB_Put_Pkt_Len(hdr, Length); #ifdef RFCNB_DEBUG ! fprintf(stderr, "Sending packet: "); ! #endif ! if ((len = RFCNB_Put_Pkt(Con_Handle, pkt, Length + RFCNB_Pkt_Hdr_Len)) < 0) { ! /* No need to change RFCNB_errno as it was done by put_pkt ... */ ! return(RFCNBE_Bad); /* Should be able to write that lot ... */ ! ! } ! /* Now we have sent that lot, let's get rid of the RFCNB Header and return */ ! pkt -> next = NULL; ! RFCNB_Free_Pkt(pkt); ! return(len); } /* We pick up a message from the internet ... We have to worry about ! non-message packets ... */ ! ! int RFCNB_Recv(void *con_Handle, struct RFCNB_Pkt *Data, int Length) ! ! { struct RFCNB_Pkt *pkt; ! int ret_len; ! if (con_Handle == NULL){ ! ! RFCNB_errno = RFCNBE_BadHandle; ! RFCNB_saved_errno = errno; ! return(RFCNBE_Bad); ! } ! /* Now get a packet from below. We allocate a header first */ ! /* Plug in the header and send the data */ ! pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len); ! if (pkt == NULL) { ! RFCNB_errno = RFCNBE_NoSpace; ! RFCNB_saved_errno = errno; ! return(RFCNBE_Bad); ! } ! pkt -> next = Data; /* Plug in the data portion */ ! if ((ret_len = RFCNB_Get_Pkt(con_Handle, pkt, Length + RFCNB_Pkt_Hdr_Len)) < 0) { #ifdef RFCNB_DEBUG ! fprintf(stderr, "Bad packet return in RFCNB_Recv... \n"); #endif ! return(RFCNBE_Bad); ! ! } ! /* We should check that we go a message and not a keep alive */ ! pkt -> next = NULL; ! RFCNB_Free_Pkt(pkt); ! return(ret_len); } /* We just disconnect from the other end, as there is nothing in the RFCNB */ /* protocol that specifies any exchange as far as I can see */ ! int RFCNB_Hangup(struct RFCNB_Con *con_Handle) ! { ! if (con_Handle != NULL) { ! RFCNB_Close(con_Handle -> fd); /* Could this fail? */ ! free(con_Handle); ! } ! ! return 0; ! ! ! } ! ! /* Set TCP_NODELAY on the socket */ ! ! int RFCNB_Set_Sock_NoDelay(struct RFCNB_Con *con_Handle, BOOL yn) ! ! { ! ! return(setsockopt(con_Handle -> fd, IPPROTO_TCP, TCP_NODELAY, ! (char *)&yn, sizeof(yn))); ! ! } ! ! ! /* Listen for a connection on a port???, when */ ! /* the connection comes in, we return with the connection */ - void RFCNB_Listen() - - { } /* Pick up the last error response as a string, hmmm, this routine should */ /* have been different ... */ ! void RFCNB_Get_Error(char *buffer, int buf_len) ! { ! if (RFCNB_saved_errno <= 0) { ! sprintf(buffer, "%s", RFCNB_Error_Strings[RFCNB_errno]); ! } ! else { ! sprintf(buffer, "%s\n\terrno:%s", RFCNB_Error_Strings[RFCNB_errno], strerror(RFCNB_saved_errno)); ! } } /* Pick up the last error response and returns as a code */ ! int RFCNB_Get_Last_Error() ! { ! return(RFCNB_errno); } /* Pick up saved errno as well */ ! int RFCNB_Get_Last_Errno() ! { ! return(RFCNB_saved_errno); } /* Pick up the last error response and return in string ... */ ! void RFCNB_Get_Error_Msg(int code, char *msg_buf, int len) ! { ! strncpy(msg_buf, RFCNB_Error_Strings[abs(code)], len); } /* Register a higher level protocol print routine */ ! void RFCNB_Register_Print_Routine(void (*fn)()) ! { ! Prot_Print_Routine = fn; } --- 40,347 ---- int RFCNB_Stats[RFCNB_MAX_STATS]; ! #ifdef RFCNB_DEBUG ! void (*Prot_Print_Routine) () = NULL; /* Pointer to print routine */ ! #endif /* Set up a session with a remote name. We are passed Called_Name as a ! * string which we convert to a NetBIOS name, ie space terminated, up to ! * 16 characters only if we need to. If Called_Address is not empty, then ! * we use it to connect to the remote end, but put in Called_Name ... Called ! * Address can be a DNS based name, or a TCP/IP address ... ! */ ! ! void * ! RFCNB_Call(char *Called_Name, char *Calling_Name, char *Called_Address, ! int port) ! { ! struct RFCNB_Con *con; ! struct in_addr Dest_IP; ! int Client; ! BOOL redirect; ! struct redirect_addr *redir_addr; ! char *Service_Address; ! /* Now, we really should look up the port in /etc/services ... */ ! if (port == 0) ! port = RFCNB_Default_Port; ! /* Create a connection structure first */ ! if ((con = (struct RFCNB_Con *) malloc(sizeof(struct RFCNB_Con))) == NULL) { /* Error in size */ ! RFCNB_errno = RFCNBE_NoSpace; ! RFCNB_saved_errno = errno; ! return (NULL); } ! con->fd = -0; /* no descriptor yet */ ! con->rfc_errno = 0; /* no error yet */ ! con->timeout = 0; /* no timeout */ ! con->redirects = 0; ! con->redirect_list = NULL; /* Fix bug still in version 0.50 */ ! ! /* Resolve that name into an IP address */ ! ! Service_Address = Called_Name; ! if (strcmp(Called_Address, "") != 0) { /* If the Called Address = "" */ ! Service_Address = Called_Address; ! } ! if ((errno = RFCNB_Name_To_IP(Service_Address, &Dest_IP)) < 0) { /* Error */ ! /* No need to modify RFCNB_errno as it was done by RFCNB_Name_To_IP */ ! return (NULL); } + /* Now connect to the remote end */ ! redirect = TRUE; /* Fudge this one so we go once through */ ! while (redirect) { /* Connect and get session info etc */ ! redirect = FALSE; /* Assume all OK */ ! /* Build the redirect info. First one is first addr called */ ! /* And tack it onto the list of addresses we called */ ! if ((redir_addr = (struct redirect_addr *) malloc(sizeof(struct redirect_addr))) == NULL) { /* Could not get space */ ! RFCNB_errno = RFCNBE_NoSpace; ! RFCNB_saved_errno = errno; ! return (NULL); ! } ! memcpy((char *) &(redir_addr->ip_addr), (char *) &Dest_IP, sizeof(Dest_IP)); ! redir_addr->port = port; ! redir_addr->next = NULL; ! if (con->redirect_list == NULL) { /* Stick on head */ ! con->redirect_list = con->last_addr = redir_addr; ! } else { ! con->last_addr->next = redir_addr; ! con->last_addr = redir_addr; ! } ! /* Now, make that connection */ ! if ((Client = RFCNB_IP_Connect(Dest_IP, port)) < 0) { /* Error */ ! /* No need to modify RFCNB_errno as it was done by RFCNB_IP_Connect */ ! return (NULL); ! } ! con->fd = Client; ! /* Now send and handle the RFCNB session request */ ! /* If we get a redirect, we will comeback with redirect true ! * and a new IP address in DEST_IP */ ! if ((errno = RFCNB_Session_Req(con, ! Called_Name, ! Calling_Name, ! &redirect, &Dest_IP, &port)) < 0) { ! /* No need to modify RFCNB_errno as it was done by RFCNB_Session.. */ ! return (NULL); ! } ! if (redirect) { ! /* We have to close the connection, and then try again */ ! (con->redirects)++; ! RFCNB_Close(con->fd); /* Close it */ ! } } ! return (con); } /* We send a packet to the other end ... for the moment, we treat the ! * data as a series of pointers to blocks of data ... we should check the ! * length ... */ ! int ! RFCNB_Send(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *udata, int Length) ! { ! struct RFCNB_Pkt *pkt; ! char *hdr; ! int len; ! /* Plug in the header and send the data */ ! pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len); ! if (pkt == NULL) { ! RFCNB_errno = RFCNBE_NoSpace; ! RFCNB_saved_errno = errno; ! return (RFCNBE_Bad); ! } ! pkt->next = udata; /* The user data we want to send */ ! hdr = pkt->data; ! /* Following crap is for portability across multiple UNIX machines */ ! *(hdr + RFCNB_Pkt_Type_Offset) = RFCNB_SESSION_MESSAGE; ! RFCNB_Put_Pkt_Len(hdr, Length); #ifdef RFCNB_DEBUG ! fprintf(stderr, "Sending packet: "); ! #endif ! if ((len = RFCNB_Put_Pkt(Con_Handle, pkt, Length + RFCNB_Pkt_Hdr_Len)) < 0) { ! /* No need to change RFCNB_errno as it was done by put_pkt ... */ ! return (RFCNBE_Bad); /* Should be able to write that lot ... */ ! } ! /* Now we have sent that lot, let's get rid of the RFCNB Header and return */ ! pkt->next = NULL; ! RFCNB_Free_Pkt(pkt); ! return (len); } /* We pick up a message from the internet ... We have to worry about ! * non-message packets ... */ ! int ! RFCNB_Recv(struct RFCNB_Con *con_Handle, struct RFCNB_Pkt *Data, int Length) ! { ! struct RFCNB_Pkt *pkt; ! int ret_len; ! if (con_Handle == NULL) { ! RFCNB_errno = RFCNBE_BadHandle; ! RFCNB_saved_errno = errno; ! return (RFCNBE_Bad); ! } ! /* Now get a packet from below. We allocate a header first */ ! /* Plug in the header and send the data */ ! pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len); ! if (pkt == NULL) { ! RFCNB_errno = RFCNBE_NoSpace; ! RFCNB_saved_errno = errno; ! return (RFCNBE_Bad); ! } ! pkt->next = Data; /* Plug in the data portion */ ! if ((ret_len = RFCNB_Get_Pkt(con_Handle, pkt, Length + RFCNB_Pkt_Hdr_Len)) < 0) { #ifdef RFCNB_DEBUG ! fprintf(stderr, "Bad packet return in RFCNB_Recv... \n"); #endif ! return (RFCNBE_Bad); ! } ! /* We should check that we go a message and not a keep alive */ ! pkt->next = NULL; ! RFCNB_Free_Pkt(pkt); ! return (ret_len); } /* We just disconnect from the other end, as there is nothing in the RFCNB */ /* protocol that specifies any exchange as far as I can see */ ! int ! RFCNB_Hangup(struct RFCNB_Con *con_Handle) { ! if (con_Handle != NULL) { ! RFCNB_Close(con_Handle->fd); /* Could this fail? */ ! free(con_Handle); ! } ! return 0; } /* Pick up the last error response as a string, hmmm, this routine should */ /* have been different ... */ ! void ! RFCNB_Get_Error(char *buffer, int buf_len) { ! if (RFCNB_saved_errno <= 0) { ! sprintf(buffer, "%s", RFCNB_Error_Strings[RFCNB_errno]); ! } else { ! sprintf(buffer, "%s\n\terrno:%s", RFCNB_Error_Strings[RFCNB_errno], strerror(RFCNB_saved_errno)); ! } } /* Pick up the last error response and returns as a code */ ! int ! RFCNB_Get_Last_Error(void) { ! return (RFCNB_errno); } /* Pick up saved errno as well */ ! int ! RFCNB_Get_Last_Errno(void) { ! return (RFCNB_saved_errno); } /* Pick up the last error response and return in string ... */ ! void ! RFCNB_Get_Error_Msg(int code, char *msg_buf, int len) { ! strncpy(msg_buf, RFCNB_Error_Strings[abs(code)], len); } /* Register a higher level protocol print routine */ ! #ifdef RFCNB_DEBUG ! void ! RFCNB_Register_Print_Routine(void (*fn) ()) { ! Prot_Print_Routine = fn; } + #endif diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/smbdes.c squid-2.4.STABLE7/auth_modules/MSNT/smbdes.c *** squid-2.4.STABLE6/auth_modules/MSNT/smbdes.c Wed Oct 20 12:50:47 1999 --- squid-2.4.STABLE7/auth_modules/MSNT/smbdes.c Wed Jun 26 13:24:44 2002 *************** *** 1,337 **** /* ! Unix SMB/Netbios implementation. ! Version 1.9. ! ! a partial implementation of DES designed for use in the ! SMB authentication protocol ! ! Copyright (C) Andrew Tridgell 1997 ! ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ /* NOTES: ! This code makes no attempt to be fast! In fact, it is a very ! slow implementation ! ! This code is NOT a complete DES implementation. It implements only ! the minimum necessary for SMB authentication, as used by all SMB ! products (including every copy of Microsoft Windows95 ever sold) ! ! In particular, it can only do a unchained forward DES pass. This ! means it is not possible to use this code for encryption/decryption ! of data, instead it is only useful as a "hash" algorithm. ! ! There is no entry point into this code that allows normal DES operation. ! ! I believe this means that this code does not come under ITAR ! regulations but this is NOT a legal opinion. If you are concerned ! about the applicability of ITAR regulations to this code then you ! should confirm it for yourself (and maybe let me know if you come ! up with a different answer to the one above) ! */ ! ! ! ! static int perm1[56] = {57, 49, 41, 33, 25, 17, 9, ! 1, 58, 50, 42, 34, 26, 18, ! 10, 2, 59, 51, 43, 35, 27, ! 19, 11, 3, 60, 52, 44, 36, ! 63, 55, 47, 39, 31, 23, 15, ! 7, 62, 54, 46, 38, 30, 22, ! 14, 6, 61, 53, 45, 37, 29, ! 21, 13, 5, 28, 20, 12, 4}; ! ! static int perm2[48] = {14, 17, 11, 24, 1, 5, ! 3, 28, 15, 6, 21, 10, ! 23, 19, 12, 4, 26, 8, ! 16, 7, 27, 20, 13, 2, ! 41, 52, 31, 37, 47, 55, ! 30, 40, 51, 45, 33, 48, ! 44, 49, 39, 56, 34, 53, ! 46, 42, 50, 36, 29, 32}; ! ! static int perm3[64] = {58, 50, 42, 34, 26, 18, 10, 2, ! 60, 52, 44, 36, 28, 20, 12, 4, ! 62, 54, 46, 38, 30, 22, 14, 6, ! 64, 56, 48, 40, 32, 24, 16, 8, ! 57, 49, 41, 33, 25, 17, 9, 1, ! 59, 51, 43, 35, 27, 19, 11, 3, ! 61, 53, 45, 37, 29, 21, 13, 5, ! 63, 55, 47, 39, 31, 23, 15, 7}; ! ! static int perm4[48] = { 32, 1, 2, 3, 4, 5, ! 4, 5, 6, 7, 8, 9, ! 8, 9, 10, 11, 12, 13, ! 12, 13, 14, 15, 16, 17, ! 16, 17, 18, 19, 20, 21, ! 20, 21, 22, 23, 24, 25, ! 24, 25, 26, 27, 28, 29, ! 28, 29, 30, 31, 32, 1}; ! ! static int perm5[32] = { 16, 7, 20, 21, ! 29, 12, 28, 17, ! 1, 15, 23, 26, ! 5, 18, 31, 10, ! 2, 8, 24, 14, ! 32, 27, 3, 9, ! 19, 13, 30, 6, ! 22, 11, 4, 25}; ! ! ! static int perm6[64] ={ 40, 8, 48, 16, 56, 24, 64, 32, ! 39, 7, 47, 15, 55, 23, 63, 31, ! 38, 6, 46, 14, 54, 22, 62, 30, ! 37, 5, 45, 13, 53, 21, 61, 29, ! 36, 4, 44, 12, 52, 20, 60, 28, ! 35, 3, 43, 11, 51, 19, 59, 27, ! 34, 2, 42, 10, 50, 18, 58, 26, ! 33, 1, 41, 9, 49, 17, 57, 25}; ! ! ! static int sc[16] = {1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1}; ! ! static int sbox[8][4][16] = { ! {{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7}, ! {0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8}, ! {4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0}, ! {15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}}, ! ! {{15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10}, ! {3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5}, ! {0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15}, ! {13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}}, ! ! {{10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8}, ! {13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1}, ! {13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7}, ! {1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}}, ! ! {{7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15}, ! {13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9}, ! {10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4}, ! {3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}}, ! ! {{2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9}, ! {14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6}, ! {4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14}, ! {11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}}, ! ! {{12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11}, ! {10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8}, ! {9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6}, ! {4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}}, ! ! {{4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1}, ! {13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6}, ! {1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2}, ! {6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}}, ! ! {{13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7}, ! {1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2}, ! {7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8}, ! {2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}}}; ! ! static void permute(char *out, char *in, int *p, int n) ! { ! int i; ! for (i=0;i>1; ! key[1] = ((str[0]&0x01)<<6) | (str[1]>>2); ! key[2] = ((str[1]&0x03)<<5) | (str[2]>>3); ! key[3] = ((str[2]&0x07)<<4) | (str[3]>>4); ! key[4] = ((str[3]&0x0F)<<3) | (str[4]>>5); ! key[5] = ((str[4]&0x1F)<<2) | (str[5]>>6); ! key[6] = ((str[5]&0x3F)<<1) | (str[6]>>7); ! key[7] = str[6]&0x7F; ! for (i=0;i<8;i++) { ! key[i] = (key[i]<<1); ! } } ! static void smbhash(unsigned char *out, unsigned char *in, unsigned char *key) { ! int i; ! char outb[64]; ! char inb[64]; ! char keyb[64]; ! unsigned char key2[8]; ! ! str_to_key(key, key2); ! ! for (i=0;i<64;i++) { ! inb[i] = (in[i/8] & (1<<(7-(i%8)))) ? 1 : 0; ! keyb[i] = (key2[i/8] & (1<<(7-(i%8)))) ? 1 : 0; ! outb[i] = 0; ! } ! dohash(outb, inb, keyb); ! for (i=0;i<8;i++) { ! out[i] = 0; ! } ! for (i=0;i<64;i++) { ! if (outb[i]) ! out[i/8] |= (1<<(7-(i%8))); ! } } ! void E_P16(unsigned char *p14,unsigned char *p16) { ! unsigned char sp8[8] = {0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25}; ! smbhash(p16, sp8, p14); ! smbhash(p16+8, sp8, p14+7); } ! void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24) { ! smbhash(p24, c8, p21); ! smbhash(p24+8, c8, p21+7); ! smbhash(p24+16, c8, p21+14); } ! void cred_hash1(unsigned char *out,unsigned char *in,unsigned char *key) { ! unsigned char buf[8]; ! smbhash(buf, in, key); ! smbhash(out, buf, key+9); } ! void cred_hash2(unsigned char *out,unsigned char *in,unsigned char *key) { ! unsigned char buf[8]; ! static unsigned char key2[8]; ! smbhash(buf, in, key); ! key2[0] = key[7]; ! smbhash(out, buf, key2); } - --- 1,364 ---- /* ! * Unix SMB/Netbios implementation. ! * Version 1.9. ! * ! * a partial implementation of DES designed for use in the ! * SMB authentication protocol ! * ! * Copyright (C) Andrew Tridgell 1997 ! * ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ /* NOTES: + * + * This code makes no attempt to be fast! In fact, it is a very + * slow implementation + * + * This code is NOT a complete DES implementation. It implements only + * the minimum necessary for SMB authentication, as used by all SMB + * products (including every copy of Microsoft Windows95 ever sold) + * + * In particular, it can only do a unchained forward DES pass. This + * means it is not possible to use this code for encryption/decryption + * of data, instead it is only useful as a "hash" algorithm. + * + * There is no entry point into this code that allows normal DES operation. + * + * I believe this means that this code does not come under ITAR + * regulations but this is NOT a legal opinion. If you are concerned + * about the applicability of ITAR regulations to this code then you + * should confirm it for yourself (and maybe let me know if you come + * up with a different answer to the one above) + */ + + #include "smbdes.h" + + static int perm1[56] = + {57, 49, 41, 33, 25, 17, 9, + 1, 58, 50, 42, 34, 26, 18, + 10, 2, 59, 51, 43, 35, 27, + 19, 11, 3, 60, 52, 44, 36, + 63, 55, 47, 39, 31, 23, 15, + 7, 62, 54, 46, 38, 30, 22, + 14, 6, 61, 53, 45, 37, 29, + 21, 13, 5, 28, 20, 12, 4}; + + static int perm2[48] = + {14, 17, 11, 24, 1, 5, + 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, + 16, 7, 27, 20, 13, 2, + 41, 52, 31, 37, 47, 55, + 30, 40, 51, 45, 33, 48, + 44, 49, 39, 56, 34, 53, + 46, 42, 50, 36, 29, 32}; + + static int perm3[64] = + {58, 50, 42, 34, 26, 18, 10, 2, + 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, + 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, + 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, + 63, 55, 47, 39, 31, 23, 15, 7}; + + static int perm4[48] = + {32, 1, 2, 3, 4, 5, + 4, 5, 6, 7, 8, 9, + 8, 9, 10, 11, 12, 13, + 12, 13, 14, 15, 16, 17, + 16, 17, 18, 19, 20, 21, + 20, 21, 22, 23, 24, 25, + 24, 25, 26, 27, 28, 29, + 28, 29, 30, 31, 32, 1}; + + static int perm5[32] = + {16, 7, 20, 21, + 29, 12, 28, 17, + 1, 15, 23, 26, + 5, 18, 31, 10, + 2, 8, 24, 14, + 32, 27, 3, 9, + 19, 13, 30, 6, + 22, 11, 4, 25}; + + + static int perm6[64] = + {40, 8, 48, 16, 56, 24, 64, 32, + 39, 7, 47, 15, 55, 23, 63, 31, + 38, 6, 46, 14, 54, 22, 62, 30, + 37, 5, 45, 13, 53, 21, 61, 29, + 36, 4, 44, 12, 52, 20, 60, 28, + 35, 3, 43, 11, 51, 19, 59, 27, + 34, 2, 42, 10, 50, 18, 58, 26, + 33, 1, 41, 9, 49, 17, 57, 25}; + + + static int sc[16] = + {1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1}; + + static int sbox[8][4][16] = + { + { + {14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7}, + {0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8}, + {4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0}, + {15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}}, + + { + {15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10}, + {3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5}, + {0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15}, + {13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}}, + + { + {10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8}, + {13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1}, + {13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7}, + {1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}}, + + { + {7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15}, + {13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9}, + {10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4}, + {3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}}, + + { + {2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9}, + {14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6}, + {4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14}, + {11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}}, + + { + {12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11}, + {10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8}, + {9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6}, + {4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}}, + + { + {4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1}, + {13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6}, + {1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2}, + {6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}}, + + { + {13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7}, + {1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2}, + {7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8}, + {2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}}}; + + static void + permute(char *out, char *in, int *p, int n) + { + int i; + for (i = 0; i < n; i++) + out[i] = in[p[i] - 1]; + } + + static void + lshift(char *d, int count, int n) + { + char out[64]; + int i; + for (i = 0; i < n; i++) + out[i] = d[(i + count) % n]; + for (i = 0; i < n; i++) + d[i] = out[i]; + } + + static void + concat(char *out, char *in1, char *in2, int l1, int l2) + { + while (l1--) + *out++ = *in1++; + while (l2--) + *out++ = *in2++; + } + + static void + xor(char *out, char *in1, char *in2, int n) + { + int i; + for (i = 0; i < n; i++) + out[i] = in1[i] ^ in2[i]; + } + + static void + dohash(char *out, char *in, char *key) + { + int i, j, k; + char pk1[56]; + char c[28]; + char d[28]; + char cd[56]; + char ki[16][48]; + char pd1[64]; + char l[32], r[32]; + char rl[64]; + + permute(pk1, key, perm1, 56); + + for (i = 0; i < 28; i++) + c[i] = pk1[i]; + for (i = 0; i < 28; i++) + d[i] = pk1[i + 28]; + + for (i = 0; i < 16; i++) { + lshift(c, sc[i], 28); + lshift(d, sc[i], 28); + + concat(cd, c, d, 28, 28); + permute(ki[i], cd, perm2, 48); + } + + permute(pd1, in, perm3, 64); + + for (j = 0; j < 32; j++) { + l[j] = pd1[j]; + r[j] = pd1[j + 32]; + } + + for (i = 0; i < 16; i++) { + char er[48]; + char erk[48]; + char b[8][6]; + char cb[32]; + char pcb[32]; + char r2[32]; + + permute(er, r, perm4, 48); + + xor(erk, er, ki[i], 48); + + for (j = 0; j < 8; j++) + for (k = 0; k < 6; k++) + b[j][k] = erk[j * 6 + k]; + + for (j = 0; j < 8; j++) { + int m, n; + m = (b[j][0] << 1) | b[j][5]; ! n = (b[j][1] << 3) | (b[j][2] << 2) | (b[j][3] << 1) | b[j][4]; ! for (k = 0; k < 4; k++) ! b[j][k] = (sbox[j][m][n] & (1 << (3 - k))) ? 1 : 0; } ! for (j = 0; j < 8; j++) ! for (k = 0; k < 4; k++) ! cb[j * 4 + k] = b[j][k]; ! permute(pcb, cb, perm5, 32); ! xor(r2, l, pcb, 32); ! for (j = 0; j < 32; j++) ! l[j] = r[j]; ! for (j = 0; j < 32; j++) ! r[j] = r2[j]; ! } ! concat(rl, r, l, 32, 32); ! permute(out, rl, perm6, 64); } ! static void ! str_to_key(unsigned char *str, unsigned char *key) { ! int i; ! key[0] = str[0] >> 1; ! key[1] = ((str[0] & 0x01) << 6) | (str[1] >> 2); ! key[2] = ((str[1] & 0x03) << 5) | (str[2] >> 3); ! key[3] = ((str[2] & 0x07) << 4) | (str[3] >> 4); ! key[4] = ((str[3] & 0x0F) << 3) | (str[4] >> 5); ! key[5] = ((str[4] & 0x1F) << 2) | (str[5] >> 6); ! key[6] = ((str[5] & 0x3F) << 1) | (str[6] >> 7); ! key[7] = str[6] & 0x7F; ! for (i = 0; i < 8; i++) { ! key[i] = (key[i] << 1); ! } } ! static void ! smbhash(unsigned char *out, unsigned char *in, unsigned char *key) { ! int i; ! char outb[64]; ! char inb[64]; ! char keyb[64]; ! unsigned char key2[8]; ! str_to_key(key, key2); ! for (i = 0; i < 64; i++) { ! inb[i] = (in[i / 8] & (1 << (7 - (i % 8)))) ? 1 : 0; ! keyb[i] = (key2[i / 8] & (1 << (7 - (i % 8)))) ? 1 : 0; ! outb[i] = 0; ! } ! dohash(outb, inb, keyb); ! ! for (i = 0; i < 8; i++) { ! out[i] = 0; ! } ! ! for (i = 0; i < 64; i++) { ! if (outb[i]) ! out[i / 8] |= (1 << (7 - (i % 8))); ! } } ! void ! E_P16(unsigned char *p14, unsigned char *p16) { ! unsigned char sp8[8] = ! {0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25}; ! smbhash(p16, sp8, p14); ! smbhash(p16 + 8, sp8, p14 + 7); } ! void ! E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24) { ! smbhash(p24, c8, p21); ! smbhash(p24 + 8, c8, p21 + 7); ! smbhash(p24 + 16, c8, p21 + 14); } ! void ! cred_hash1(unsigned char *out, unsigned char *in, unsigned char *key) { ! unsigned char buf[8]; ! smbhash(buf, in, key); ! smbhash(out, buf, key + 9); } ! void ! cred_hash2(unsigned char *out, unsigned char *in, unsigned char *key) { ! unsigned char buf[8]; ! static unsigned char key2[8]; ! smbhash(buf, in, key); ! key2[0] = key[7]; ! smbhash(out, buf, key2); } diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/smbdes.h squid-2.4.STABLE7/auth_modules/MSNT/smbdes.h *** squid-2.4.STABLE6/auth_modules/MSNT/smbdes.h Wed Dec 31 17:00:00 1969 --- squid-2.4.STABLE7/auth_modules/MSNT/smbdes.h Wed Jun 26 13:24:45 2002 *************** *** 0 **** --- 1,5 ---- + /* smbdes.c */ + void E_P16(unsigned char *p14, unsigned char *p16); + void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24); + void cred_hash1(unsigned char *out, unsigned char *in, unsigned char *key); + void cred_hash2(unsigned char *out, unsigned char *in, unsigned char *key); diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/smbencrypt.c squid-2.4.STABLE7/auth_modules/MSNT/smbencrypt.c *** squid-2.4.STABLE6/auth_modules/MSNT/smbencrypt.c Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/smbencrypt.c Wed Jun 26 13:24:45 2002 *************** *** 1,24 **** /* ! Unix SMB/Netbios implementation. ! Version 1.9. ! SMB parameters and setup ! Copyright (C) Andrew Tridgell 1992-1997 ! Modified by Jeremy Allison 1995. ! ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #include #include --- 1,24 ---- /* ! * Unix SMB/Netbios implementation. ! * Version 1.9. ! * SMB parameters and setup ! * Copyright (C) Andrew Tridgell 1992-1997 ! * Modified by Jeremy Allison 1995. ! * ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #include #include *************** *** 28,34 **** #include #include #include ! /* Antonino #include */ #include "smblib-priv.h" #define uchar unsigned char --- 28,38 ---- #include #include #include ! ! /* AI inclusion for Solaris filesystem */ ! #ifdef SOLARIS ! #include ! #endif #include "smblib-priv.h" #define uchar unsigned char *************** *** 36,72 **** #include "byteorder.h" ! char *StrnCpy(char *dest,char *src,int n); ! void strupper(char *s); ! extern void E_P16(unsigned char *,unsigned char *); ! extern void E_P24(unsigned char *, unsigned char *, unsigned char *); ! extern void mdfour(unsigned char *, unsigned char *, int); ! /* ! This implements the X/Open SMB password encryption ! It takes a password, a 8 byte "crypt key" and puts 24 bytes of ! encrypted password into p24 */ ! void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24) ! { ! uchar p14[15], p21[21]; ! ! memset(p21,'\0',21); ! memset(p14,'\0',14); ! StrnCpy((char *)p14,(char *)passwd,14); ! ! strupper((char *)p14); ! E_P16(p14, p21); ! E_P24(p21, c8, p24); } /* Routines for Windows NT MD4 Hash functions. */ ! static int _my_wcslen(int16 *str) { ! int len = 0; ! while(*str++ != 0) ! len++; ! return len; } /* --- 40,79 ---- #include "byteorder.h" ! #include "md4.h" ! #include "smbdes.h" ! #include "smbencrypt.h" ! ! static void E_md4hash(unsigned char *passwd, unsigned char *p16); ! static char *StrnCpy(char *dest, char *src, int n); ! static void strupper(char *s); /* ! * This implements the X/Open SMB password encryption ! * It takes a password, a 8 byte "crypt key" and puts 24 bytes of ! * encrypted password into p24 */ ! void ! SMBencrypt(uchar * passwd, uchar * c8, uchar * p24) ! { ! uchar p14[15], p21[21]; ! ! memset(p21, '\0', 21); ! memset(p14, '\0', 14); ! StrnCpy((char *) p14, (char *) passwd, 14); ! ! strupper((char *) p14); ! E_P16(p14, p21); ! E_P24(p21, c8, p24); } /* Routines for Windows NT MD4 Hash functions. */ ! static int ! _my_wcslen(int16 * str) { ! int len = 0; ! while (*str++ != 0) ! len++; ! return len; } /* *************** *** 75,203 **** * this must be in intel (little-endian) * format. */ ! ! static int _my_mbstowcs(int16 *dst, uchar *src, int len) { ! int i; ! int16 val; ! ! for(i = 0; i < len; i++) { ! val = *src; ! SSVAL(dst,0,val); ! dst++; ! src++; ! if(val == 0) ! break; ! } ! return i; } /* * Creates the MD4 Hash of the users password in NT UNICODE. */ ! ! void E_md4hash(uchar *passwd, uchar *p16) { ! int len; ! int16 wpwd[129]; ! ! /* Password cannot be longer than 128 characters */ ! len = strlen((char *)passwd); ! if(len > 128) ! len = 128; ! /* Password must be converted to NT unicode */ ! _my_mbstowcs(wpwd, passwd, len); ! wpwd[len] = 0; /* Ensure string is null terminated */ ! /* Calculate length in bytes */ ! len = _my_wcslen(wpwd) * sizeof(int16); ! mdfour(p16, (unsigned char *)wpwd, len); } /* Does the NT MD4 hash then des encryption. */ ! ! void SMBNTencrypt(uchar *passwd, uchar *c8, uchar *p24) { ! uchar p21[21]; ! ! memset(p21,'\0',21); ! ! E_md4hash(passwd, p21); ! E_P24(p21, c8, p24); } /* Does both the NT and LM owfs of a user's password */ ! void nt_lm_owf_gen(char *pwd, char *nt_p16, char *p16) { ! char passwd[130]; ! StrnCpy(passwd, pwd, sizeof(passwd)-1); ! /* Calculate the MD4 hash (NT compatible) of the password */ ! memset(nt_p16, '\0', 16); ! E_md4hash((uchar *)passwd, (uchar *)nt_p16); ! /* Mangle the passwords into Lanman format */ ! passwd[14] = '\0'; ! strupper(passwd); ! /* Calculate the SMB (lanman) hash functions of the password */ ! memset(p16, '\0', 16); ! E_P16((uchar *) passwd, (uchar *)p16); ! /* clear out local copy of user's password (just being paranoid). */ ! bzero(passwd, sizeof(passwd)); } /**************************************************************************** line strncpy but always null terminates. Make sure there is room! ****************************************************************************/ ! char *StrnCpy(char *dest,char *src,int n) { ! char *d = dest; ! if (!dest) return(NULL); ! if (!src) { ! *dest = 0; ! return(dest); ! } ! while (n-- && (*d++ = *src++)) ; ! *d = 0; ! return(dest); ! } ! ! void strupper(char *s) ! { ! while (*s) ! { ! /* ! #if !defined(KANJI_WIN95_COMPATIBILITY) ! if(lp_client_code_page() == KANJI_CODEPAGE) ! { ! ! if (is_shift_jis (*s)) ! { ! if (is_sj_lower (s[0], s[1])) ! s[1] = sj_toupper2 (s[1]); ! s += 2; ! } ! else if (is_kana (*s)) ! { ! s++; ! } ! else ! { ! if (islower(*s)) ! *s = toupper(*s); ! s++; ! } } ! else ! #endif */ /* KANJI_WIN95_COMPATIBILITY */ ! { ! if (islower(*s)) ! *s = toupper(*s); ! s++; } ! } ! } --- 82,210 ---- * this must be in intel (little-endian) * format. */ ! ! static int ! _my_mbstowcs(int16 * dst, uchar * src, int len) { ! int i; ! int16 val; ! ! for (i = 0; i < len; i++) { ! val = *src; ! SSVAL(dst, 0, val); ! dst++; ! src++; ! if (val == 0) ! break; ! } ! return i; } /* * Creates the MD4 Hash of the users password in NT UNICODE. */ ! ! void ! E_md4hash(uchar * passwd, uchar * p16) { ! int len; ! int16 wpwd[129]; ! /* Password cannot be longer than 128 characters */ ! len = strlen((char *) passwd); ! if (len > 128) ! len = 128; ! /* Password must be converted to NT unicode */ ! _my_mbstowcs(wpwd, passwd, len); ! wpwd[len] = 0; /* Ensure string is null terminated */ ! /* Calculate length in bytes */ ! len = _my_wcslen(wpwd) * sizeof(int16); ! ! mdfour(p16, (unsigned char *) wpwd, len); } /* Does the NT MD4 hash then des encryption. */ ! ! void ! SMBNTencrypt(uchar * passwd, uchar * c8, uchar * p24) { ! uchar p21[21]; ! ! memset(p21, '\0', 21); ! ! E_md4hash(passwd, p21); ! E_P24(p21, c8, p24); } /* Does both the NT and LM owfs of a user's password */ ! void ! nt_lm_owf_gen(char *pwd, char *nt_p16, char *p16) { ! char passwd[130]; ! StrnCpy(passwd, pwd, sizeof(passwd) - 1); ! /* Calculate the MD4 hash (NT compatible) of the password */ ! memset(nt_p16, '\0', 16); ! E_md4hash((uchar *) passwd, (uchar *) nt_p16); ! /* Mangle the passwords into Lanman format */ ! passwd[14] = '\0'; ! strupper(passwd); ! /* Calculate the SMB (lanman) hash functions of the password */ ! memset(p16, '\0', 16); ! E_P16((uchar *) passwd, (uchar *) p16); ! /* clear out local copy of user's password (just being paranoid). */ ! bzero(passwd, sizeof(passwd)); } /**************************************************************************** line strncpy but always null terminates. Make sure there is room! ****************************************************************************/ ! char * ! StrnCpy(char *dest, char *src, int n) { ! char *d = dest; ! if (!dest) ! return (NULL); ! if (!src) { ! *dest = 0; ! return (dest); } ! while (n-- && (*d++ = *src++)); ! *d = 0; ! return (dest); ! } ! ! void ! strupper(char *s) ! { ! while (*s) { ! #if UNUSED_CODE ! #if !defined(KANJI_WIN95_COMPATIBILITY) ! if (lp_client_code_page() == KANJI_CODEPAGE) { ! ! if (is_shift_jis(*s)) { ! if (is_sj_lower(s[0], s[1])) ! s[1] = sj_toupper2(s[1]); ! s += 2; ! } else if (is_kana(*s)) { ! s++; ! } else { ! if (islower(*s)) ! *s = toupper(*s); ! s++; ! } ! } else ! #endif /* KANJI_WIN95_COMPATIBILITY */ ! #endif /* UNUSED_CODE */ ! { ! if (islower(*s)) ! *s = toupper(*s); ! s++; ! } } ! } diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/smbencrypt.h squid-2.4.STABLE7/auth_modules/MSNT/smbencrypt.h *** squid-2.4.STABLE6/auth_modules/MSNT/smbencrypt.h Wed Dec 31 17:00:00 1969 --- squid-2.4.STABLE7/auth_modules/MSNT/smbencrypt.h Wed Jun 26 13:24:45 2002 *************** *** 0 **** --- 1,4 ---- + /* smbencrypt.c */ + void SMBencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24); + void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24); + void nt_lm_owf_gen(char *pwd, char *nt_p16, char *p16); diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/smblib-common.h squid-2.4.STABLE7/auth_modules/MSNT/smblib-common.h *** squid-2.4.STABLE6/auth_modules/MSNT/smblib-common.h Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/smblib-common.h Wed Jun 26 13:24:45 2002 *************** *** 1,27 **** /* UNIX SMBlib NetBIOS implementation ! ! Version 1.0 ! SMBlib Common Defines ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ /* To get the error class we want the first 8 bits */ /* Because we just grab 4bytes from the SMB header, we have to re-order */ --- 1,27 ---- /* UNIX SMBlib NetBIOS implementation ! * ! * Version 1.0 ! * SMBlib Common Defines ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ /* To get the error class we want the first 8 bits */ /* Because we just grab 4bytes from the SMB header, we have to re-order */ *************** *** 76,82 **** /* Server errors ... */ ! #define SMBV_error 0x01 /* Generic error */ #define SMBV_badpw 0x02 #define SMBV_badtype 0x03 #define SMBV_access 0x04 --- 76,82 ---- /* Server errors ... */ ! #define SMBV_error 0x01 /* Generic error */ #define SMBV_badpw 0x02 #define SMBV_badtype 0x03 #define SMBV_access 0x04 *************** *** 141,152 **** /* Define the protocol types ... */ ! #define SMB_P_Unknown -1 /* Hmmm, is this smart? */ #define SMB_P_Core 0 #define SMB_P_CorePlus 1 #define SMB_P_DOSLanMan1 2 #define SMB_P_LanMan1 3 ! #define SMB_P_DOSLanMan2 4 #define SMB_P_LanMan2 5 #define SMB_P_DOSLanMan2_1 6 #define SMB_P_LanMan2_1 7 --- 141,152 ---- /* Define the protocol types ... */ ! #define SMB_P_Unknown -1 /* Hmmm, is this smart? */ #define SMB_P_Core 0 #define SMB_P_CorePlus 1 #define SMB_P_DOSLanMan1 2 #define SMB_P_LanMan1 3 ! #define SMB_P_DOSLanMan2 4 #define SMB_P_LanMan2 5 #define SMB_P_DOSLanMan2_1 6 #define SMB_P_LanMan2_1 7 *************** *** 161,188 **** /* SMBlibE_ values >1 indicate local from SMBlib code errors? */ #define SMBlibE_Success 0 ! #define SMBlibE_Remote 1 /* Remote error, get more info from con */ #define SMBlibE_BAD -1 ! #define SMBlibE_LowerLayer 2 /* Lower layer error */ ! #define SMBlibE_NotImpl 3 /* Function not yet implemented */ ! #define SMBlibE_ProtLow 4 /* Protocol negotiated does not support req */ ! #define SMBlibE_NoSpace 5 /* No space to allocate a structure */ ! #define SMBlibE_BadParam 6 /* Bad parameters */ ! #define SMBlibE_NegNoProt 7 /* None of our protocols was liked */ ! #define SMBlibE_SendFailed 8 /* Sending an SMB failed */ ! #define SMBlibE_RecvFailed 9 /* Receiving an SMB failed */ ! #define SMBlibE_GuestOnly 10 /* Logged in as guest */ ! #define SMBlibE_CallFailed 11 /* Call remote end failed */ ! #define SMBlibE_ProtUnknown 12 /* Protocol unknown */ ! #define SMBlibE_NoSuchMsg 13 /* Keep this up to date */ ! ! typedef struct { /* A structure for a Dirent */ ! ! unsigned char resume_key[21]; /* Don't touch this */ ! unsigned char file_attributes; /* Attributes of file */ ! unsigned int date_time; /* date and time of last mod */ ! unsigned int size; ! char filename[13]; /* The name of the file */ } SMB_CP_dirent; --- 161,188 ---- /* SMBlibE_ values >1 indicate local from SMBlib code errors? */ #define SMBlibE_Success 0 ! #define SMBlibE_Remote 1 /* Remote error, get more info from con */ #define SMBlibE_BAD -1 ! #define SMBlibE_LowerLayer 2 /* Lower layer error */ ! #define SMBlibE_NotImpl 3 /* Function not yet implemented */ ! #define SMBlibE_ProtLow 4 /* Protocol negotiated does not support req */ ! #define SMBlibE_NoSpace 5 /* No space to allocate a structure */ ! #define SMBlibE_BadParam 6 /* Bad parameters */ ! #define SMBlibE_NegNoProt 7 /* None of our protocols was liked */ ! #define SMBlibE_SendFailed 8 /* Sending an SMB failed */ ! #define SMBlibE_RecvFailed 9 /* Receiving an SMB failed */ ! #define SMBlibE_GuestOnly 10 /* Logged in as guest */ ! #define SMBlibE_CallFailed 11 /* Call remote end failed */ ! #define SMBlibE_ProtUnknown 12 /* Protocol unknown */ ! #define SMBlibE_NoSuchMsg 13 /* Keep this up to date */ ! ! typedef struct { /* A structure for a Dirent */ ! ! unsigned char resume_key[21]; /* Don't touch this */ ! unsigned char file_attributes; /* Attributes of file */ ! unsigned int date_time; /* date and time of last mod */ ! unsigned int size; ! char filename[13]; /* The name of the file */ } SMB_CP_dirent; diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/smblib-priv.h squid-2.4.STABLE7/auth_modules/MSNT/smblib-priv.h *** squid-2.4.STABLE6/auth_modules/MSNT/smblib-priv.h Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/smblib-priv.h Wed Jun 26 13:24:45 2002 *************** *** 1,27 **** /* UNIX SMBlib NetBIOS implementation ! ! Version 1.0 ! SMBlib private Defines ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #ifndef _SMBLIB_PRIV_H_ #define _SMBLIB_PRIV_H_ --- 1,27 ---- /* UNIX SMBlib NetBIOS implementation ! * ! * Version 1.0 ! * SMBlib private Defines ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #ifndef _SMBLIB_PRIV_H_ #define _SMBLIB_PRIV_H_ *************** *** 31,134 **** #include #include ! #include "byteorder.h" /* Hmmm ... hot good */ #define max(a,b) (a < b ? b : a) ! #define SMB_DEF_IDF 0x424D53FF /* "\377SMB" */ ! /* Core protocol commands */ ! #define SMBmkdir 0x00 /* create directory */ ! #define SMBrmdir 0x01 /* delete directory */ ! #define SMBopen 0x02 /* open file */ ! #define SMBcreate 0x03 /* create file */ ! #define SMBclose 0x04 /* close file */ ! #define SMBflush 0x05 /* flush file */ ! #define SMBunlink 0x06 /* delete file */ ! #define SMBmv 0x07 /* rename file */ ! #define SMBgetatr 0x08 /* get file attributes */ ! #define SMBsetatr 0x09 /* set file attributes */ ! #define SMBread 0x0A /* read from file */ ! #define SMBwrite 0x0B /* write to file */ ! #define SMBlock 0x0C /* lock byte range */ ! #define SMBunlock 0x0D /* unlock byte range */ ! #define SMBctemp 0x0E /* create temporary file */ ! #define SMBmknew 0x0F /* make new file */ ! #define SMBchkpth 0x10 /* check directory path */ ! #define SMBexit 0x11 /* process exit */ ! #define SMBlseek 0x12 /* seek */ ! #define SMBtcon 0x70 /* tree connect */ ! #define SMBtdis 0x71 /* tree disconnect */ ! #define SMBnegprot 0x72 /* negotiate protocol */ ! #define SMBdskattr 0x80 /* get disk attributes */ ! #define SMBsearch 0x81 /* search directory */ ! #define SMBsplopen 0xC0 /* open print spool file */ ! #define SMBsplwr 0xC1 /* write to print spool file */ ! #define SMBsplclose 0xC2 /* close print spool file */ ! #define SMBsplretq 0xC3 /* return print queue */ ! #define SMBsends 0xD0 /* send single block message */ ! #define SMBsendb 0xD1 /* send broadcast message */ ! #define SMBfwdname 0xD2 /* forward user name */ ! #define SMBcancelf 0xD3 /* cancel forward */ ! #define SMBgetmac 0xD4 /* get machine name */ ! #define SMBsendstrt 0xD5 /* send start of multi-block message */ ! #define SMBsendend 0xD6 /* send end of multi-block message */ ! #define SMBsendtxt 0xD7 /* send text of multi-block message */ /* CorePlus protocol */ ! #define SMBlockread 0x13 /* Lock a range and read it */ ! #define SMBwriteunlock 0x14 /* Unlock a range and then write */ ! #define SMBreadbraw 0x1a /* read a block of data without smb header ohead*/ ! #define SMBwritebraw 0x1d /* write a block of data without smb header ohead*/ ! #define SMBwritec 0x20 /* secondary write request */ ! #define SMBwriteclose 0x2c /* write a file and then close it */ /* DOS Extended Protocol */ ! #define SMBreadBraw 0x1A /* read block raw */ ! #define SMBreadBmpx 0x1B /* read block multiplexed */ ! #define SMBreadBs 0x1C /* read block (secondary response) */ ! #define SMBwriteBraw 0x1D /* write block raw */ ! #define SMBwriteBmpx 0x1E /* write block multiplexed */ ! #define SMBwriteBs 0x1F /* write block (secondary request) */ ! #define SMBwriteC 0x20 /* write complete response */ ! #define SMBsetattrE 0x22 /* set file attributes expanded */ ! #define SMBgetattrE 0x23 /* get file attributes expanded */ ! #define SMBlockingX 0x24 /* lock/unlock byte ranges and X */ ! #define SMBtrans 0x25 /* transaction - name, bytes in/out */ ! #define SMBtranss 0x26 /* transaction (secondary request/response) */ ! #define SMBioctl 0x27 /* IOCTL */ ! #define SMBioctls 0x28 /* IOCTL (secondary request/response) */ ! #define SMBcopy 0x29 /* copy */ ! #define SMBmove 0x2A /* move */ ! #define SMBecho 0x2B /* echo */ ! #define SMBopenX 0x2D /* open and X */ ! #define SMBreadX 0x2E /* read and X */ ! #define SMBwriteX 0x2F /* write and X */ ! #define SMBsesssetupX 0x73 /* Session Set Up & X (including User Logon) */ ! #define SMBtconX 0x75 /* tree connect and X */ ! #define SMBffirst 0x82 /* find first */ ! #define SMBfunique 0x83 /* find unique */ ! #define SMBfclose 0x84 /* find close */ ! #define SMBinvalid 0xFE /* invalid command */ /* Any more ? */ ! #define SMBdatablockID 0x01 /* A data block identifier */ ! #define SMBdialectID 0x02 /* A dialect id */ ! #define SMBpathnameID 0x03 /* A pathname ID */ ! #define SMBasciiID 0x04 /* An ascii string ID */ ! #define SMBvariableblockID 0x05 /* A variable block ID */ /* some other defines we need */ /* Flags defines ... */ ! #define SMB_FLG2_NON_DOS 0x01 /* We know non dos names */ ! #define SMB_FLG2_EXT_ATR 0x02 /* We know about Extended Attributes */ ! #define SMB_FLG2_LNG_NAM 0x04 /* Long names ? */ typedef unsigned short WORD; typedef unsigned short UWORD; --- 31,134 ---- #include #include ! #include "byteorder.h" /* Hmmm ... hot good */ #define max(a,b) (a < b ? b : a) ! #define SMB_DEF_IDF 0x424D53FF /* "\377SMB" */ ! /* Core protocol commands */ ! #define SMBmkdir 0x00 /* create directory */ ! #define SMBrmdir 0x01 /* delete directory */ ! #define SMBopen 0x02 /* open file */ ! #define SMBcreate 0x03 /* create file */ ! #define SMBclose 0x04 /* close file */ ! #define SMBflush 0x05 /* flush file */ ! #define SMBunlink 0x06 /* delete file */ ! #define SMBmv 0x07 /* rename file */ ! #define SMBgetatr 0x08 /* get file attributes */ ! #define SMBsetatr 0x09 /* set file attributes */ ! #define SMBread 0x0A /* read from file */ ! #define SMBwrite 0x0B /* write to file */ ! #define SMBlock 0x0C /* lock byte range */ ! #define SMBunlock 0x0D /* unlock byte range */ ! #define SMBctemp 0x0E /* create temporary file */ ! #define SMBmknew 0x0F /* make new file */ ! #define SMBchkpth 0x10 /* check directory path */ ! #define SMBexit 0x11 /* process exit */ ! #define SMBlseek 0x12 /* seek */ ! #define SMBtcon 0x70 /* tree connect */ ! #define SMBtdis 0x71 /* tree disconnect */ ! #define SMBnegprot 0x72 /* negotiate protocol */ ! #define SMBdskattr 0x80 /* get disk attributes */ ! #define SMBsearch 0x81 /* search directory */ ! #define SMBsplopen 0xC0 /* open print spool file */ ! #define SMBsplwr 0xC1 /* write to print spool file */ ! #define SMBsplclose 0xC2 /* close print spool file */ ! #define SMBsplretq 0xC3 /* return print queue */ ! #define SMBsends 0xD0 /* send single block message */ ! #define SMBsendb 0xD1 /* send broadcast message */ ! #define SMBfwdname 0xD2 /* forward user name */ ! #define SMBcancelf 0xD3 /* cancel forward */ ! #define SMBgetmac 0xD4 /* get machine name */ ! #define SMBsendstrt 0xD5 /* send start of multi-block message */ ! #define SMBsendend 0xD6 /* send end of multi-block message */ ! #define SMBsendtxt 0xD7 /* send text of multi-block message */ /* CorePlus protocol */ ! #define SMBlockread 0x13 /* Lock a range and read it */ ! #define SMBwriteunlock 0x14 /* Unlock a range and then write */ ! #define SMBreadbraw 0x1a /* read a block of data without smb header ohead */ ! #define SMBwritebraw 0x1d /* write a block of data without smb header ohead */ ! #define SMBwritec 0x20 /* secondary write request */ ! #define SMBwriteclose 0x2c /* write a file and then close it */ /* DOS Extended Protocol */ ! #define SMBreadBraw 0x1A /* read block raw */ ! #define SMBreadBmpx 0x1B /* read block multiplexed */ ! #define SMBreadBs 0x1C /* read block (secondary response) */ ! #define SMBwriteBraw 0x1D /* write block raw */ ! #define SMBwriteBmpx 0x1E /* write block multiplexed */ ! #define SMBwriteBs 0x1F /* write block (secondary request) */ ! #define SMBwriteC 0x20 /* write complete response */ ! #define SMBsetattrE 0x22 /* set file attributes expanded */ ! #define SMBgetattrE 0x23 /* get file attributes expanded */ ! #define SMBlockingX 0x24 /* lock/unlock byte ranges and X */ ! #define SMBtrans 0x25 /* transaction - name, bytes in/out */ ! #define SMBtranss 0x26 /* transaction (secondary request/response) */ ! #define SMBioctl 0x27 /* IOCTL */ ! #define SMBioctls 0x28 /* IOCTL (secondary request/response) */ ! #define SMBcopy 0x29 /* copy */ ! #define SMBmove 0x2A /* move */ ! #define SMBecho 0x2B /* echo */ ! #define SMBopenX 0x2D /* open and X */ ! #define SMBreadX 0x2E /* read and X */ ! #define SMBwriteX 0x2F /* write and X */ ! #define SMBsesssetupX 0x73 /* Session Set Up & X (including User Logon) */ ! #define SMBtconX 0x75 /* tree connect and X */ ! #define SMBffirst 0x82 /* find first */ ! #define SMBfunique 0x83 /* find unique */ ! #define SMBfclose 0x84 /* find close */ ! #define SMBinvalid 0xFE /* invalid command */ /* Any more ? */ ! #define SMBdatablockID 0x01 /* A data block identifier */ ! #define SMBdialectID 0x02 /* A dialect id */ ! #define SMBpathnameID 0x03 /* A pathname ID */ ! #define SMBasciiID 0x04 /* An ascii string ID */ ! #define SMBvariableblockID 0x05 /* A variable block ID */ /* some other defines we need */ /* Flags defines ... */ ! #define SMB_FLG2_NON_DOS 0x01 /* We know non dos names */ ! #define SMB_FLG2_EXT_ATR 0x02 /* We know about Extended Attributes */ ! #define SMB_FLG2_LNG_NAM 0x04 /* Long names ? */ typedef unsigned short WORD; typedef unsigned short UWORD; *************** *** 162,178 **** /* the data that follows in the SMB packet, so the code will have to */ /* take that into account. */ ! #define SMB_hdr_idf_offset 0 /* 0xFF,'SMB' 0-3 */ ! #define SMB_hdr_com_offset 4 /* BYTE 4 */ ! #define SMB_hdr_rcls_offset 5 /* BYTE 5 */ ! #define SMB_hdr_reh_offset 6 /* BYTE 6 */ ! #define SMB_hdr_err_offset 7 /* WORD 7 */ ! #define SMB_hdr_reb_offset 9 /* BYTE 9 */ ! #define SMB_hdr_flg_offset 9 /* same as reb ...*/ ! #define SMB_hdr_res_offset 10 /* 7 WORDs 10 */ ! #define SMB_hdr_res0_offset 10 /* WORD 10 */ ! #define SMB_hdr_flg2_offset 10 /* WORD */ ! #define SMB_hdr_res1_offset 12 /* WORD 12 */ #define SMB_hdr_res2_offset 14 #define SMB_hdr_res3_offset 16 #define SMB_hdr_res4_offset 18 --- 162,178 ---- /* the data that follows in the SMB packet, so the code will have to */ /* take that into account. */ ! #define SMB_hdr_idf_offset 0 /* 0xFF,'SMB' 0-3 */ ! #define SMB_hdr_com_offset 4 /* BYTE 4 */ ! #define SMB_hdr_rcls_offset 5 /* BYTE 5 */ ! #define SMB_hdr_reh_offset 6 /* BYTE 6 */ ! #define SMB_hdr_err_offset 7 /* WORD 7 */ ! #define SMB_hdr_reb_offset 9 /* BYTE 9 */ ! #define SMB_hdr_flg_offset 9 /* same as reb ... */ ! #define SMB_hdr_res_offset 10 /* 7 WORDs 10 */ ! #define SMB_hdr_res0_offset 10 /* WORD 10 */ ! #define SMB_hdr_flg2_offset 10 /* WORD */ ! #define SMB_hdr_res1_offset 12 /* WORD 12 */ #define SMB_hdr_res2_offset 14 #define SMB_hdr_res3_offset 16 #define SMB_hdr_res4_offset 18 *************** *** 184,458 **** #define SMB_hdr_mid_offset 30 #define SMB_hdr_wct_offset 32 ! #define SMB_hdr_len 33 /* 33 byte header? */ ! #define SMB_hdr_axc_offset 33 /* AndX Command */ ! #define SMB_hdr_axr_offset 34 /* AndX Reserved */ ! #define SMB_hdr_axo_offset 35 /* Offset from start to WCT of AndX cmd */ /* Format of the Negotiate Protocol SMB */ #define SMB_negp_bcc_offset 33 ! #define SMB_negp_buf_offset 35 /* Where the buffer starts */ ! #define SMB_negp_len 35 /* plus the data */ /* Format of the Negotiate Response SMB, for CoreProtocol, LM1.2 and */ /* NT LM 0.12. wct will be 1 for CoreProtocol, 13 for LM 1.2, and 17 */ /* for NT LM 0.12 */ ! #define SMB_negrCP_idx_offset 33 /* Response to the neg req */ #define SMB_negrCP_bcc_offset 35 ! #define SMB_negrLM_idx_offset 33 /* dialect index */ ! #define SMB_negrLM_sec_offset 35 /* Security mode */ ! #define SMB_sec_user_mask 0x01 /* 0 = share, 1 = user */ ! #define SMB_sec_encrypt_mask 0x02 /* pick out encrypt */ ! #define SMB_negrLM_mbs_offset 37 /* max buffer size */ ! #define SMB_negrLM_mmc_offset 39 /* max mpx count */ ! #define SMB_negrLM_mnv_offset 41 /* max number of VCs */ ! #define SMB_negrLM_rm_offset 43 /* raw mode support bit vec*/ #define SMB_read_raw_mask 0x01 #define SMB_write_raw_mask 0x02 ! #define SMB_negrLM_sk_offset 45 /* session key, 32 bits */ ! #define SMB_negrLM_st_offset 49 /* Current server time */ ! #define SMB_negrLM_sd_offset 51 /* Current server date */ ! #define SMB_negrLM_stz_offset 53 /* Server Time Zone */ ! #define SMB_negrLM_ekl_offset 55 /* encryption key length */ ! #define SMB_negrLM_res_offset 57 /* reserved */ ! #define SMB_negrLM_bcc_offset 59 /* bcc */ ! #define SMB_negrLM_len 61 /* 61 bytes ? */ ! #define SMB_negrLM_buf_offset 61 /* Where the fun begins */ ! ! #define SMB_negrNTLM_idx_offset 33 /* Selected protocol */ ! #define SMB_negrNTLM_sec_offset 35 /* Security more */ ! #define SMB_negrNTLM_mmc_offset 36 /* Different format above */ ! #define SMB_negrNTLM_mnv_offset 38 /* Max VCs */ ! #define SMB_negrNTLM_mbs_offset 40 /* MBS now a long */ ! #define SMB_negrNTLM_mrs_offset 44 /* Max raw size */ ! #define SMB_negrNTLM_sk_offset 48 /* Session Key */ ! #define SMB_negrNTLM_cap_offset 52 /* Capabilities */ ! #define SMB_negrNTLM_stl_offset 56 /* Server time low */ ! #define SMB_negrNTLM_sth_offset 60 /* Server time high */ ! #define SMB_negrNTLM_stz_offset 64 /* Server time zone */ ! #define SMB_negrNTLM_ekl_offset 66 /* Encrypt key len */ ! #define SMB_negrNTLM_bcc_offset 67 /* Bcc */ #define SMB_negrNTLM_len 69 #define SMB_negrNTLM_buf_offset 69 /* Offsets related to Tree Connect */ #define SMB_tcon_bcc_offset 33 ! #define SMB_tcon_buf_offset 35 /* where the data is for tcon */ ! #define SMB_tcon_len 35 /* plus the data */ ! #define SMB_tconr_mbs_offset 33 /* max buffer size */ ! #define SMB_tconr_tid_offset 35 /* returned tree id */ ! #define SMB_tconr_bcc_offset 37 ! #define SMB_tconr_len 39 ! ! #define SMB_tconx_axc_offset 33 /* And X Command */ ! #define SMB_tconx_axr_offset 34 /* reserved */ ! #define SMB_tconx_axo_offset 35 /* Next command offset */ ! #define SMB_tconx_flg_offset 37 /* Flags, bit0=1 means disc TID */ ! #define SMB_tconx_pwl_offset 39 /* Password length */ ! #define SMB_tconx_bcc_offset 41 /* bcc */ ! #define SMB_tconx_buf_offset 43 /* buffer */ ! #define SMB_tconx_len 43 /* up to data ... */ ! ! #define SMB_tconxr_axc_offset 33 /* Where the AndX Command is */ ! #define SMB_tconxr_axr_offset 34 /* Reserved */ ! #define SMB_tconxr_axo_offset 35 /* AndX offset location */ /* Offsets related to tree_disconnect */ ! #define SMB_tdis_bcc_offset 33 /* bcc */ ! #define SMB_tdis_len 35 /* total len */ ! #define SMB_tdisr_bcc_offset 33 /* bcc */ #define SMB_tdisr_len 35 /* Offsets related to Open Request */ ! #define SMB_open_mod_offset 33 /* Mode to open with */ ! #define SMB_open_atr_offset 35 /* Attributes of file */ ! #define SMB_open_bcc_offset 37 /* bcc */ ! #define SMB_open_buf_offset 39 /* File name */ ! #define SMB_open_len 39 /* Plus the file name */ ! ! #define SMB_openx_axc_offset 33 /* Next command */ ! #define SMB_openx_axr_offset 34 /* Reserved */ ! #define SMB_openx_axo_offset 35 /* offset of next wct */ ! #define SMB_openx_flg_offset 37 /* Flags, bit0 = need more info */ ! /* bit1 = exclusive oplock */ ! /* bit2 = batch oplock */ ! #define SMB_openx_mod_offset 39 /* mode to open with */ ! #define SMB_openx_atr_offset 41 /* search attributes */ ! #define SMB_openx_fat_offset 43 /* File attributes */ ! #define SMB_openx_tim_offset 45 /* time and date of creat */ ! #define SMB_openx_ofn_offset 49 /* Open function */ ! #define SMB_openx_als_offset 51 /* Space to allocate on */ ! #define SMB_openx_res_offset 55 /* reserved */ ! #define SMB_openx_bcc_offset 63 /* bcc */ ! #define SMB_openx_buf_offset 65 /* Where file name goes */ #define SMB_openx_len 65 ! #define SMB_openr_fid_offset 33 /* FID returned */ ! #define SMB_openr_atr_offset 35 /* Attributes opened with */ ! #define SMB_openr_tim_offset 37 /* Last mod time of file */ ! #define SMB_openr_fsz_offset 41 /* File size 4 bytes */ ! #define SMB_openr_acc_offset 45 /* Access allowed */ #define SMB_openr_bcc_offset 47 #define SMB_openr_len 49 ! #define SMB_openxr_axc_offset 33 /* And X command */ ! #define SMB_openxr_axr_offset 34 /* reserved */ ! #define SMB_openxr_axo_offset 35 /* offset to next command */ ! #define SMB_openxr_fid_offset 37 /* FID returned */ ! #define SMB_openxr_fat_offset 39 /* File attributes returned*/ ! #define SMB_openxr_tim_offset 41 /* File creation date etc */ ! #define SMB_openxr_fsz_offset 45 /* Size of file */ ! #define SMB_openxr_acc_offset 49 /* Access granted */ ! ! #define SMB_clos_fid_offset 33 /* FID to close */ ! #define SMB_clos_tim_offset 35 /* Last mod time */ ! #define SMB_clos_bcc_offset 39 /* bcc */ #define SMB_clos_len 41 /* Offsets related to Write requests */ ! #define SMB_write_fid_offset 33 /* FID to write */ ! #define SMB_write_cnt_offset 35 /* bytes to write */ ! #define SMB_write_ofs_offset 37 /* location to write to */ ! #define SMB_write_clf_offset 41 /* advisory count left */ ! #define SMB_write_bcc_offset 43 /* bcc = data bytes + 3 */ ! #define SMB_write_buf_offset 45 /* Data=0x01, len, data */ ! #define SMB_write_len 45 /* plus the data ... */ ! #define SMB_writr_cnt_offset 33 /* Count of bytes written */ ! #define SMB_writr_bcc_offset 35 /* bcc */ #define SMB_writr_len 37 /* Offsets related to read requests */ ! #define SMB_read_fid_offset 33 /* FID of file to read */ ! #define SMB_read_cnt_offset 35 /* count of words to read */ ! #define SMB_read_ofs_offset 37 /* Where to read from */ ! #define SMB_read_clf_offset 41 /* Advisory count to go */ #define SMB_read_bcc_offset 43 #define SMB_read_len 45 ! #define SMB_readr_cnt_offset 33 /* Count of bytes returned */ ! #define SMB_readr_res_offset 35 /* 4 shorts reserved, 8 bytes */ ! #define SMB_readr_bcc_offset 43 /* bcc */ ! #define SMB_readr_bff_offset 45 /* buffer format char = 0x01 */ ! #define SMB_readr_len_offset 46 /* buffer len */ ! #define SMB_readr_len 45 /* length of the readr before data */ /* Offsets for Create file */ ! #define SMB_creat_atr_offset 33 /* Attributes of new file ... */ ! #define SMB_creat_tim_offset 35 /* Time of creation */ ! #define SMB_creat_dat_offset 37 /* 4004BCE :-) */ ! #define SMB_creat_bcc_offset 39 /* bcc */ #define SMB_creat_buf_offset 41 ! #define SMB_creat_len 41 /* Before the data */ ! #define SMB_creatr_fid_offset 33 /* FID of created file */ /* Offsets for Delete file */ ! #define SMB_delet_sat_offset 33 /* search attribites */ ! #define SMB_delet_bcc_offset 35 /* bcc */ #define SMB_delet_buf_offset 37 #define SMB_delet_len 37 /* Offsets for SESSION_SETUP_ANDX for both LM and NT LM protocols */ ! #define SMB_ssetpLM_mbs_offset 37 /* Max buffer Size, allow for AndX */ ! #define SMB_ssetpLM_mmc_offset 39 /* max multiplex count */ ! #define SMB_ssetpLM_vcn_offset 41 /* VC number if new VC */ ! #define SMB_ssetpLM_snk_offset 43 /* Session Key */ ! #define SMB_ssetpLM_pwl_offset 47 /* password length */ ! #define SMB_ssetpLM_res_offset 49 /* reserved */ ! #define SMB_ssetpLM_bcc_offset 53 /* bcc */ ! #define SMB_ssetpLM_len 55 /* before data ... */ #define SMB_ssetpLM_buf_offset 55 ! #define SMB_ssetpNTLM_mbs_offset 37 /* Max Buffer Size for NT LM 0.12 */ ! /* and above */ ! #define SMB_ssetpNTLM_mmc_offset 39 /* Max Multiplex count */ ! #define SMB_ssetpNTLM_vcn_offset 41 /* VC Number */ ! #define SMB_ssetpNTLM_snk_offset 43 /* Session key */ ! #define SMB_ssetpNTLM_cipl_offset 47 /* Case Insensitive PW Len */ ! #define SMB_ssetpNTLM_cspl_offset 49 /* Unicode pw len */ ! #define SMB_ssetpNTLM_res_offset 51 /* reserved */ ! #define SMB_ssetpNTLM_cap_offset 55 /* server capabilities */ ! #define SMB_ssetpNTLM_bcc_offset 59 /* bcc */ ! #define SMB_ssetpNTLM_len 61 /* before data */ #define SMB_ssetpNTLM_buf_offset 61 ! #define SMB_ssetpr_axo_offset 35 /* Offset of next response ... */ ! #define SMB_ssetpr_act_offset 37 /* action, bit 0 = 1 => guest */ ! #define SMB_ssetpr_bcc_offset 39 /* bcc */ ! #define SMB_ssetpr_buf_offset 41 /* Native OS etc */ /* Offsets for SMB create directory */ ! #define SMB_creatdir_bcc_offset 33 /* only a bcc here */ ! #define SMB_creatdir_buf_offset 35 /* Where things start */ #define SMB_creatdir_len 35 /* Offsets for SMB delete directory */ ! #define SMB_deletdir_bcc_offset 33 /* only a bcc here */ ! #define SMB_deletdir_buf_offset 35 /* where things start */ #define SMB_deletdir_len 35 /* Offsets for SMB check directory */ ! #define SMB_checkdir_bcc_offset 33 /* Only a bcc here */ ! #define SMB_checkdir_buf_offset 35 /* where things start */ #define SMB_checkdir_len 35 /* Offsets for SMB search */ ! #define SMB_search_mdc_offset 33 /* Max Dir ents to return */ ! #define SMB_search_atr_offset 35 /* Search attributes */ ! #define SMB_search_bcc_offset 37 /* bcc */ ! #define SMB_search_buf_offset 39 /* where the action is */ #define SMB_search_len 39 ! #define SMB_searchr_dec_offset 33 /* Dir ents returned */ ! #define SMB_searchr_bcc_offset 35 /* bcc */ ! #define SMB_searchr_buf_offset 37 /* Where the action starts */ ! #define SMB_searchr_len 37 /* before the dir ents */ ! #define SMB_searchr_dirent_len 43 /* 53 bytes */ /* Defines for SMB transact and transact2 calls */ ! #define SMB_trans_tpc_offset 33 /* Total param count */ ! #define SMB_trans_tdc_offset 35 /* total Data count */ ! #define SMB_trans_mpc_offset 37 /* Max params bytes to return */ ! #define SMB_trans_mdc_offset 39 /* Max data bytes to return */ ! #define SMB_trans_msc_offset 41 /* Max setup words to return */ ! #define SMB_trans_rs1_offset 42 /* Reserved byte */ ! #define SMB_trans_flg_offset 43 /* flags */ ! #define SMB_trans_tmo_offset 45 /* Timeout, long */ ! #define SMB_trans_rs2_offset 49 /* Next reserved */ ! #define SMB_trans_pbc_offset 51 /* Param Byte count in buf */ ! #define SMB_trans_pbo_offset 53 /* Offset to param bytes */ ! #define SMB_trans_dbc_offset 55 /* Data byte count in buf */ ! #define SMB_trans_dbo_offset 57 /* Data byte offset */ ! #define SMB_trans_suc_offset 59 /* Setup count - byte */ ! #define SMB_trans_rs3_offset 60 /* Reserved to pad ... */ ! #define SMB_trans_len 61 /* Up to setup, still need bcc */ ! #define SMB_transr_tpc_offset 33 /* Total param bytes returned */ #define SMB_transr_tdc_offset 35 #define SMB_transr_rs1_offset 37 #define SMB_transr_pbc_offset 39 #define SMB_transr_pbo_offset 41 ! #define SMB_transr_pdi_offset 43 /* parameter displacement */ #define SMB_transr_dbc_offset 45 #define SMB_transr_dbo_offset 47 #define SMB_transr_ddi_offset 49 --- 184,458 ---- #define SMB_hdr_mid_offset 30 #define SMB_hdr_wct_offset 32 ! #define SMB_hdr_len 33 /* 33 byte header? */ ! #define SMB_hdr_axc_offset 33 /* AndX Command */ ! #define SMB_hdr_axr_offset 34 /* AndX Reserved */ ! #define SMB_hdr_axo_offset 35 /* Offset from start to WCT of AndX cmd */ /* Format of the Negotiate Protocol SMB */ #define SMB_negp_bcc_offset 33 ! #define SMB_negp_buf_offset 35 /* Where the buffer starts */ ! #define SMB_negp_len 35 /* plus the data */ /* Format of the Negotiate Response SMB, for CoreProtocol, LM1.2 and */ /* NT LM 0.12. wct will be 1 for CoreProtocol, 13 for LM 1.2, and 17 */ /* for NT LM 0.12 */ ! #define SMB_negrCP_idx_offset 33 /* Response to the neg req */ #define SMB_negrCP_bcc_offset 35 ! #define SMB_negrLM_idx_offset 33 /* dialect index */ ! #define SMB_negrLM_sec_offset 35 /* Security mode */ ! #define SMB_sec_user_mask 0x01 /* 0 = share, 1 = user */ ! #define SMB_sec_encrypt_mask 0x02 /* pick out encrypt */ ! #define SMB_negrLM_mbs_offset 37 /* max buffer size */ ! #define SMB_negrLM_mmc_offset 39 /* max mpx count */ ! #define SMB_negrLM_mnv_offset 41 /* max number of VCs */ ! #define SMB_negrLM_rm_offset 43 /* raw mode support bit vec */ #define SMB_read_raw_mask 0x01 #define SMB_write_raw_mask 0x02 ! #define SMB_negrLM_sk_offset 45 /* session key, 32 bits */ ! #define SMB_negrLM_st_offset 49 /* Current server time */ ! #define SMB_negrLM_sd_offset 51 /* Current server date */ ! #define SMB_negrLM_stz_offset 53 /* Server Time Zone */ ! #define SMB_negrLM_ekl_offset 55 /* encryption key length */ ! #define SMB_negrLM_res_offset 57 /* reserved */ ! #define SMB_negrLM_bcc_offset 59 /* bcc */ ! #define SMB_negrLM_len 61 /* 61 bytes ? */ ! #define SMB_negrLM_buf_offset 61 /* Where the fun begins */ ! ! #define SMB_negrNTLM_idx_offset 33 /* Selected protocol */ ! #define SMB_negrNTLM_sec_offset 35 /* Security more */ ! #define SMB_negrNTLM_mmc_offset 36 /* Different format above */ ! #define SMB_negrNTLM_mnv_offset 38 /* Max VCs */ ! #define SMB_negrNTLM_mbs_offset 40 /* MBS now a long */ ! #define SMB_negrNTLM_mrs_offset 44 /* Max raw size */ ! #define SMB_negrNTLM_sk_offset 48 /* Session Key */ ! #define SMB_negrNTLM_cap_offset 52 /* Capabilities */ ! #define SMB_negrNTLM_stl_offset 56 /* Server time low */ ! #define SMB_negrNTLM_sth_offset 60 /* Server time high */ ! #define SMB_negrNTLM_stz_offset 64 /* Server time zone */ ! #define SMB_negrNTLM_ekl_offset 66 /* Encrypt key len */ ! #define SMB_negrNTLM_bcc_offset 67 /* Bcc */ #define SMB_negrNTLM_len 69 #define SMB_negrNTLM_buf_offset 69 /* Offsets related to Tree Connect */ #define SMB_tcon_bcc_offset 33 ! #define SMB_tcon_buf_offset 35 /* where the data is for tcon */ ! #define SMB_tcon_len 35 /* plus the data */ ! #define SMB_tconr_mbs_offset 33 /* max buffer size */ ! #define SMB_tconr_tid_offset 35 /* returned tree id */ ! #define SMB_tconr_bcc_offset 37 ! #define SMB_tconr_len 39 ! ! #define SMB_tconx_axc_offset 33 /* And X Command */ ! #define SMB_tconx_axr_offset 34 /* reserved */ ! #define SMB_tconx_axo_offset 35 /* Next command offset */ ! #define SMB_tconx_flg_offset 37 /* Flags, bit0=1 means disc TID */ ! #define SMB_tconx_pwl_offset 39 /* Password length */ ! #define SMB_tconx_bcc_offset 41 /* bcc */ ! #define SMB_tconx_buf_offset 43 /* buffer */ ! #define SMB_tconx_len 43 /* up to data ... */ ! ! #define SMB_tconxr_axc_offset 33 /* Where the AndX Command is */ ! #define SMB_tconxr_axr_offset 34 /* Reserved */ ! #define SMB_tconxr_axo_offset 35 /* AndX offset location */ /* Offsets related to tree_disconnect */ ! #define SMB_tdis_bcc_offset 33 /* bcc */ ! #define SMB_tdis_len 35 /* total len */ ! #define SMB_tdisr_bcc_offset 33 /* bcc */ #define SMB_tdisr_len 35 /* Offsets related to Open Request */ ! #define SMB_open_mod_offset 33 /* Mode to open with */ ! #define SMB_open_atr_offset 35 /* Attributes of file */ ! #define SMB_open_bcc_offset 37 /* bcc */ ! #define SMB_open_buf_offset 39 /* File name */ ! #define SMB_open_len 39 /* Plus the file name */ ! ! #define SMB_openx_axc_offset 33 /* Next command */ ! #define SMB_openx_axr_offset 34 /* Reserved */ ! #define SMB_openx_axo_offset 35 /* offset of next wct */ ! #define SMB_openx_flg_offset 37 /* Flags, bit0 = need more info */ ! /* bit1 = exclusive oplock */ ! /* bit2 = batch oplock */ ! #define SMB_openx_mod_offset 39 /* mode to open with */ ! #define SMB_openx_atr_offset 41 /* search attributes */ ! #define SMB_openx_fat_offset 43 /* File attributes */ ! #define SMB_openx_tim_offset 45 /* time and date of creat */ ! #define SMB_openx_ofn_offset 49 /* Open function */ ! #define SMB_openx_als_offset 51 /* Space to allocate on */ ! #define SMB_openx_res_offset 55 /* reserved */ ! #define SMB_openx_bcc_offset 63 /* bcc */ ! #define SMB_openx_buf_offset 65 /* Where file name goes */ #define SMB_openx_len 65 ! #define SMB_openr_fid_offset 33 /* FID returned */ ! #define SMB_openr_atr_offset 35 /* Attributes opened with */ ! #define SMB_openr_tim_offset 37 /* Last mod time of file */ ! #define SMB_openr_fsz_offset 41 /* File size 4 bytes */ ! #define SMB_openr_acc_offset 45 /* Access allowed */ #define SMB_openr_bcc_offset 47 #define SMB_openr_len 49 ! #define SMB_openxr_axc_offset 33 /* And X command */ ! #define SMB_openxr_axr_offset 34 /* reserved */ ! #define SMB_openxr_axo_offset 35 /* offset to next command */ ! #define SMB_openxr_fid_offset 37 /* FID returned */ ! #define SMB_openxr_fat_offset 39 /* File attributes returned */ ! #define SMB_openxr_tim_offset 41 /* File creation date etc */ ! #define SMB_openxr_fsz_offset 45 /* Size of file */ ! #define SMB_openxr_acc_offset 49 /* Access granted */ ! ! #define SMB_clos_fid_offset 33 /* FID to close */ ! #define SMB_clos_tim_offset 35 /* Last mod time */ ! #define SMB_clos_bcc_offset 39 /* bcc */ #define SMB_clos_len 41 /* Offsets related to Write requests */ ! #define SMB_write_fid_offset 33 /* FID to write */ ! #define SMB_write_cnt_offset 35 /* bytes to write */ ! #define SMB_write_ofs_offset 37 /* location to write to */ ! #define SMB_write_clf_offset 41 /* advisory count left */ ! #define SMB_write_bcc_offset 43 /* bcc = data bytes + 3 */ ! #define SMB_write_buf_offset 45 /* Data=0x01, len, data */ ! #define SMB_write_len 45 /* plus the data ... */ ! #define SMB_writr_cnt_offset 33 /* Count of bytes written */ ! #define SMB_writr_bcc_offset 35 /* bcc */ #define SMB_writr_len 37 /* Offsets related to read requests */ ! #define SMB_read_fid_offset 33 /* FID of file to read */ ! #define SMB_read_cnt_offset 35 /* count of words to read */ ! #define SMB_read_ofs_offset 37 /* Where to read from */ ! #define SMB_read_clf_offset 41 /* Advisory count to go */ #define SMB_read_bcc_offset 43 #define SMB_read_len 45 ! #define SMB_readr_cnt_offset 33 /* Count of bytes returned */ ! #define SMB_readr_res_offset 35 /* 4 shorts reserved, 8 bytes */ ! #define SMB_readr_bcc_offset 43 /* bcc */ ! #define SMB_readr_bff_offset 45 /* buffer format char = 0x01 */ ! #define SMB_readr_len_offset 46 /* buffer len */ ! #define SMB_readr_len 45 /* length of the readr before data */ /* Offsets for Create file */ ! #define SMB_creat_atr_offset 33 /* Attributes of new file ... */ ! #define SMB_creat_tim_offset 35 /* Time of creation */ ! #define SMB_creat_dat_offset 37 /* 4004BCE :-) */ ! #define SMB_creat_bcc_offset 39 /* bcc */ #define SMB_creat_buf_offset 41 ! #define SMB_creat_len 41 /* Before the data */ ! #define SMB_creatr_fid_offset 33 /* FID of created file */ /* Offsets for Delete file */ ! #define SMB_delet_sat_offset 33 /* search attribites */ ! #define SMB_delet_bcc_offset 35 /* bcc */ #define SMB_delet_buf_offset 37 #define SMB_delet_len 37 /* Offsets for SESSION_SETUP_ANDX for both LM and NT LM protocols */ ! #define SMB_ssetpLM_mbs_offset 37 /* Max buffer Size, allow for AndX */ ! #define SMB_ssetpLM_mmc_offset 39 /* max multiplex count */ ! #define SMB_ssetpLM_vcn_offset 41 /* VC number if new VC */ ! #define SMB_ssetpLM_snk_offset 43 /* Session Key */ ! #define SMB_ssetpLM_pwl_offset 47 /* password length */ ! #define SMB_ssetpLM_res_offset 49 /* reserved */ ! #define SMB_ssetpLM_bcc_offset 53 /* bcc */ ! #define SMB_ssetpLM_len 55 /* before data ... */ #define SMB_ssetpLM_buf_offset 55 ! #define SMB_ssetpNTLM_mbs_offset 37 /* Max Buffer Size for NT LM 0.12 */ ! /* and above */ ! #define SMB_ssetpNTLM_mmc_offset 39 /* Max Multiplex count */ ! #define SMB_ssetpNTLM_vcn_offset 41 /* VC Number */ ! #define SMB_ssetpNTLM_snk_offset 43 /* Session key */ ! #define SMB_ssetpNTLM_cipl_offset 47 /* Case Insensitive PW Len */ ! #define SMB_ssetpNTLM_cspl_offset 49 /* Unicode pw len */ ! #define SMB_ssetpNTLM_res_offset 51 /* reserved */ ! #define SMB_ssetpNTLM_cap_offset 55 /* server capabilities */ ! #define SMB_ssetpNTLM_bcc_offset 59 /* bcc */ ! #define SMB_ssetpNTLM_len 61 /* before data */ #define SMB_ssetpNTLM_buf_offset 61 ! #define SMB_ssetpr_axo_offset 35 /* Offset of next response ... */ ! #define SMB_ssetpr_act_offset 37 /* action, bit 0 = 1 => guest */ ! #define SMB_ssetpr_bcc_offset 39 /* bcc */ ! #define SMB_ssetpr_buf_offset 41 /* Native OS etc */ /* Offsets for SMB create directory */ ! #define SMB_creatdir_bcc_offset 33 /* only a bcc here */ ! #define SMB_creatdir_buf_offset 35 /* Where things start */ #define SMB_creatdir_len 35 /* Offsets for SMB delete directory */ ! #define SMB_deletdir_bcc_offset 33 /* only a bcc here */ ! #define SMB_deletdir_buf_offset 35 /* where things start */ #define SMB_deletdir_len 35 /* Offsets for SMB check directory */ ! #define SMB_checkdir_bcc_offset 33 /* Only a bcc here */ ! #define SMB_checkdir_buf_offset 35 /* where things start */ #define SMB_checkdir_len 35 /* Offsets for SMB search */ ! #define SMB_search_mdc_offset 33 /* Max Dir ents to return */ ! #define SMB_search_atr_offset 35 /* Search attributes */ ! #define SMB_search_bcc_offset 37 /* bcc */ ! #define SMB_search_buf_offset 39 /* where the action is */ #define SMB_search_len 39 ! #define SMB_searchr_dec_offset 33 /* Dir ents returned */ ! #define SMB_searchr_bcc_offset 35 /* bcc */ ! #define SMB_searchr_buf_offset 37 /* Where the action starts */ ! #define SMB_searchr_len 37 /* before the dir ents */ ! #define SMB_searchr_dirent_len 43 /* 53 bytes */ /* Defines for SMB transact and transact2 calls */ ! #define SMB_trans_tpc_offset 33 /* Total param count */ ! #define SMB_trans_tdc_offset 35 /* total Data count */ ! #define SMB_trans_mpc_offset 37 /* Max params bytes to return */ ! #define SMB_trans_mdc_offset 39 /* Max data bytes to return */ ! #define SMB_trans_msc_offset 41 /* Max setup words to return */ ! #define SMB_trans_rs1_offset 42 /* Reserved byte */ ! #define SMB_trans_flg_offset 43 /* flags */ ! #define SMB_trans_tmo_offset 45 /* Timeout, long */ ! #define SMB_trans_rs2_offset 49 /* Next reserved */ ! #define SMB_trans_pbc_offset 51 /* Param Byte count in buf */ ! #define SMB_trans_pbo_offset 53 /* Offset to param bytes */ ! #define SMB_trans_dbc_offset 55 /* Data byte count in buf */ ! #define SMB_trans_dbo_offset 57 /* Data byte offset */ ! #define SMB_trans_suc_offset 59 /* Setup count - byte */ ! #define SMB_trans_rs3_offset 60 /* Reserved to pad ... */ ! #define SMB_trans_len 61 /* Up to setup, still need bcc */ ! #define SMB_transr_tpc_offset 33 /* Total param bytes returned */ #define SMB_transr_tdc_offset 35 #define SMB_transr_rs1_offset 37 #define SMB_transr_pbc_offset 39 #define SMB_transr_pbo_offset 41 ! #define SMB_transr_pdi_offset 43 /* parameter displacement */ #define SMB_transr_dbc_offset 45 #define SMB_transr_dbo_offset 47 #define SMB_transr_ddi_offset 49 *************** *** 477,553 **** #define SMB_LMapi_SetUserInfo 0x0072 #define SMB_LMapi_UserPasswordSet 0x0073 ! /* Structures and defines we use in the client interface */ /* The protocols we might support. Perhaps a bit ambitious, as only RFCNB */ /* has any support so far 0(sometimes called NBT) */ ! typedef enum {SMB_RFCNB, SMB_IPXNB, SMB_NETBEUI, SMB_X25} SMB_Transport_Types; ! ! typedef enum {SMB_Con_FShare, SMB_Con_PShare, SMB_Con_IPC} SMB_Con_Types; ! ! typedef enum {SMB_State_NoState, SMB_State_Stopped, SMB_State_Started} SMB_State_Types; /* The following two arrays need to be in step! */ /* We must make it possible for callers to specify these ... */ ! extern char *SMB_Prots[]; extern int SMB_Types[]; typedef struct SMB_Status { ! union { ! struct { ! unsigned char ErrorClass; ! unsigned char Reserved; ! unsigned short Error; ! } DosError; ! unsigned int NtStatus; ! } status; } SMB_Status; ! typedef struct SMB_Tree_Structure * SMB_Tree_Handle; ! typedef struct SMB_Connect_Def * SMB_Handle_Type; struct SMB_Connect_Def { ! SMB_Handle_Type Next_Con, Prev_Con; /* Next and previous conn */ ! int protocol; /* What is the protocol */ ! int prot_IDX; /* And what is the index */ ! void *Trans_Connect; /* The connection */ ! ! /* All these strings should be malloc'd */ ! ! char service[80], username[80], password[80], desthost[80], sock_options[80]; ! char address[80], myname[80]; ! ! SMB_Tree_Handle first_tree, last_tree; /* List of trees on this server */ ! ! int gid; /* Group ID, do we need it? */ ! int mid; /* Multiplex ID? We might need one per con */ ! int pid; /* Process ID */ ! ! int uid; /* Authenticated user id. */ ! ! /* It is pretty clear that we need to bust some of */ ! /* these out into a per TCon record, as there may */ ! /* be multiple TCon's per server, etc ... later */ ! ! int port; /* port to use in case not default, this is a TCPism! */ ! ! int max_xmit; /* Max xmit permitted by server */ ! int Security; /* 0 = share, 1 = user */ ! int Raw_Support; /* bit 0 = 1 = Read Raw supported, 1 = 1 Write raw */ ! BOOL encrypt_passwords; /* FALSE = don't */ ! int MaxMPX, MaxVC, MaxRaw; ! unsigned int SessionKey, Capabilities; ! int SvrTZ; /* Server Time Zone */ ! int Encrypt_Key_Len; ! char Encrypt_Key[80], Domain[80], PDomain[80], OSName[80], LMType[40]; ! char Svr_OS[80], Svr_LMType[80], Svr_PDom[80]; }; --- 477,559 ---- #define SMB_LMapi_SetUserInfo 0x0072 #define SMB_LMapi_UserPasswordSet 0x0073 ! /* Structures and defines we use in the client interface */ /* The protocols we might support. Perhaps a bit ambitious, as only RFCNB */ /* has any support so far 0(sometimes called NBT) */ ! typedef enum { ! SMB_RFCNB, SMB_IPXNB, SMB_NETBEUI, SMB_X25 ! } SMB_Transport_Types; ! ! typedef enum { ! SMB_Con_FShare, SMB_Con_PShare, SMB_Con_IPC ! } SMB_Con_Types; ! ! typedef enum { ! SMB_State_NoState, SMB_State_Stopped, SMB_State_Started ! } SMB_State_Types; /* The following two arrays need to be in step! */ /* We must make it possible for callers to specify these ... */ ! extern const char *SMB_Prots[]; extern int SMB_Types[]; typedef struct SMB_Status { ! union { ! struct { ! unsigned char ErrorClass; ! unsigned char Reserved; ! unsigned short Error; ! } DosError; ! unsigned int NtStatus; ! } status; } SMB_Status; ! typedef struct SMB_Tree_Structure *SMB_Tree_Handle; ! typedef struct SMB_Connect_Def *SMB_Handle_Type; struct SMB_Connect_Def { ! SMB_Handle_Type Next_Con, Prev_Con; /* Next and previous conn */ ! int protocol; /* What is the protocol */ ! int prot_IDX; /* And what is the index */ ! void *Trans_Connect; /* The connection */ ! ! /* All these strings should be malloc'd */ ! ! char service[80], username[80], password[80], desthost[80], sock_options[80]; ! char address[80], myname[80]; ! ! SMB_Tree_Handle first_tree, last_tree; /* List of trees on this server */ ! ! int gid; /* Group ID, do we need it? */ ! int mid; /* Multiplex ID? We might need one per con */ ! int pid; /* Process ID */ ! ! int uid; /* Authenticated user id. */ ! ! /* It is pretty clear that we need to bust some of */ ! /* these out into a per TCon record, as there may */ ! /* be multiple TCon's per server, etc ... later */ ! ! int port; /* port to use in case not default, this is a TCPism! */ ! ! int max_xmit; /* Max xmit permitted by server */ ! int Security; /* 0 = share, 1 = user */ ! int Raw_Support; /* bit 0 = 1 = Read Raw supported, 1 = 1 Write raw */ ! BOOL encrypt_passwords; /* FALSE = don't */ ! int MaxMPX, MaxVC, MaxRaw; ! unsigned int SessionKey, Capabilities; ! int SvrTZ; /* Server Time Zone */ ! int Encrypt_Key_Len; ! char Encrypt_Key[80], Domain[80], PDomain[80], OSName[80], LMType[40]; ! char Svr_OS[80], Svr_LMType[80], Svr_PDom[80]; }; *************** *** 563,574 **** struct SMB_Tree_Structure { ! SMB_Tree_Handle next, prev; ! SMB_Handle_Type con; ! char path[129]; ! char device_type[20]; ! int mbs; /* Local MBS */ ! int tid; }; --- 569,580 ---- struct SMB_Tree_Structure { ! SMB_Tree_Handle next, prev; ! SMB_Handle_Type con; ! char path[129]; ! char device_type[20]; ! int mbs; /* Local MBS */ ! int tid; }; *************** *** 576,588 **** struct SMB_File_Def { ! SMB_Tree_Handle tree; ! char filename[256]; /* We should malloc this ... */ ! UWORD fid; ! unsigned int lastmod; ! unsigned int size; /* Could blow up if 64bit files supported */ ! UWORD access; ! off_t fileloc; }; --- 582,594 ---- struct SMB_File_Def { ! SMB_Tree_Handle tree; ! char filename[256]; /* We should malloc this ... */ ! UWORD fid; ! unsigned int lastmod; ! unsigned int size; /* Could blow up if 64bit files supported */ ! UWORD access; ! off_t fileloc; }; *************** *** 592,598 **** #ifndef SMBLIB_ERRNO extern int SMBlib_errno; ! extern int SMBlib_SMB_Error; /* last Error */ #endif #endif /* _SMBLIB_PRIV_H_ */ --- 598,604 ---- #ifndef SMBLIB_ERRNO extern int SMBlib_errno; ! extern int SMBlib_SMB_Error; /* last Error */ #endif #endif /* _SMBLIB_PRIV_H_ */ diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/smblib-util.c squid-2.4.STABLE7/auth_modules/MSNT/smblib-util.c *** squid-2.4.STABLE6/auth_modules/MSNT/smblib-util.c Sat Feb 17 03:18:30 2001 --- squid-2.4.STABLE7/auth_modules/MSNT/smblib-util.c Wed Jun 26 13:24:45 2002 *************** *** 1,225 **** /* UNIX SMBlib NetBIOS implementation ! ! Version 1.0 ! SMBlib Utility Routines ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #include "smblib-priv.h" #include "rfcnb.h" #include "rfcnb-priv.h" #include "rfcnb-util.h" #include - #include #include ! char *SMB_Prots[] = {"PC NETWORK PROGRAM 1.0", ! "MICROSOFT NETWORKS 1.03", ! "MICROSOFT NETWORKS 3.0", ! "DOS LANMAN1.0", ! "LANMAN1.0", ! "DOS LM1.2X002", ! "LM1.2X002", ! "DOS LANMAN2.1", ! "LANMAN2.1", ! "Samba", ! "NT LM 0.12", ! "NT LANMAN 1.0", ! NULL}; ! ! int SMB_Types[] = {SMB_P_Core, ! SMB_P_CorePlus, ! SMB_P_DOSLanMan1, ! SMB_P_DOSLanMan1, ! SMB_P_LanMan1, ! SMB_P_DOSLanMan2, ! SMB_P_LanMan2, ! SMB_P_LanMan2_1, ! SMB_P_LanMan2_1, ! SMB_P_NT1, ! SMB_P_NT1, ! SMB_P_NT1, ! -1}; ! ! /* Print out an SMB pkt in all its gory detail ... */ ! ! void SMB_Print_Pkt(FILE fd, RFCNB_Pkt *pkt, BOOL command, int Offset, int Len) ! ! { ! ! /* Well, just how do we do this ... print it I suppose */ ! ! /* Print out the SMB header ... */ ! ! /* Print the command */ ! ! /* Print the other bits in the header */ ! ! ! /* etc */ ! ! } ! ! /* Convert a DOS Date_Time to a local host type date time for printing */ ! ! char *SMB_DOSTimToStr(int DOS_time) ! ! { static char SMB_Time_Temp[48]; ! int DOS_sec, DOS_min, DOS_hour, DOS_day, DOS_month, DOS_year; ! ! SMB_Time_Temp[0] = 0; ! ! DOS_sec = (DOS_time & 0x001F) * 2; ! DOS_min = (DOS_time & 0x07E0) >> 5; ! DOS_hour = ((DOS_time & 0xF800) >> 11); ! ! DOS_day = (DOS_time & 0x001F0000) >> 16; ! DOS_month = (DOS_time & 0x01E00000) >> 21; ! DOS_year = ((DOS_time & 0xFE000000) >> 25) + 80; ! ! sprintf(SMB_Time_Temp, "%2d/%02d/%2d %2d:%02d:%02d", DOS_day, DOS_month, ! DOS_year, DOS_hour, DOS_min, DOS_sec); ! ! return(SMB_Time_Temp); ! ! } ! ! /* Convert an attribute byte/word etc to a string ... We return a pointer ! to a static string which we guarantee is long enough. If verbose is ! true, we print out long form of strings ... */ ! ! char *SMB_AtrToStr(int attribs, BOOL verbose) ! ! { static char SMB_Attrib_Temp[128]; ! ! SMB_Attrib_Temp[0] = 0; ! ! if (attribs & SMB_FA_ROF) ! strcat(SMB_Attrib_Temp, (verbose?"Read Only ":"R")); ! ! if (attribs & SMB_FA_HID) ! strcat(SMB_Attrib_Temp, (verbose?"Hidden ":"H")); ! ! if (attribs & SMB_FA_SYS) ! strcat(SMB_Attrib_Temp, (verbose?"System ":"S")); ! ! if (attribs & SMB_FA_VOL) ! strcat(SMB_Attrib_Temp, (verbose?"Volume ":"V")); ! ! if (attribs & SMB_FA_DIR) ! strcat(SMB_Attrib_Temp, (verbose?"Directory ":"D")); ! ! if (attribs & SMB_FA_ARC) ! strcat(SMB_Attrib_Temp, (verbose?"Archive ":"A")); ! ! return(SMB_Attrib_Temp); ! ! } ! ! /* Pick up the Max Buffer Size from the Tree Structure ... */ ! ! int SMB_Get_Tree_MBS(SMB_Tree_Handle tree) ! ! { ! if (tree != NULL) { ! return(tree -> mbs); ! } ! else { ! return(SMBlibE_BAD); ! } ! } ! ! /* Pick up the Max buffer size */ ! ! int SMB_Get_Max_Buf_Siz(SMB_Handle_Type Con_Handle) ! ! { ! if (Con_Handle != NULL) { ! return(Con_Handle -> max_xmit); ! } ! else { ! return(SMBlibE_BAD); ! } ! ! } ! /* Pickup the protocol index from the connection structure */ ! ! int SMB_Get_Protocol_IDX(SMB_Handle_Type Con_Handle) ! ! { ! if (Con_Handle != NULL) { ! return(Con_Handle -> prot_IDX); ! } ! else { ! return(0xFFFF); /* Invalid protocol */ ! } ! ! } ! ! /* Pick up the protocol from the connection structure */ ! ! int SMB_Get_Protocol(SMB_Handle_Type Con_Handle) ! ! { ! if (Con_Handle != NULL) { ! return(Con_Handle -> protocol); ! } ! else { ! return(0xFFFF); /* Invalid protocol */ ! } ! ! } /* Figure out what protocol was accepted, given the list of dialect strings */ /* We offered, and the index back from the server. We allow for a user */ /* supplied list, and assume that it is a subset of our list */ ! int SMB_Figure_Protocol(char *dialects[], int prot_index) ! ! { int i; ! ! if (dialects == SMB_Prots) { /* The jobs is easy, just index into table */ ! return(SMB_Types[prot_index]); ! } ! else { /* Search through SMB_Prots looking for a match */ ! for (i = 0; SMB_Prots[i] != NULL; i++) { ! if (strcmp(dialects[prot_index], SMB_Prots[i]) == 0) { /* A match */ ! return(SMB_Types[i]); ! } ! } ! /* If we got here, then we are in trouble, because the protocol was not */ ! /* One we understand ... */ ! return(SMB_P_Unknown); ! } } --- 1,98 ---- /* UNIX SMBlib NetBIOS implementation ! * ! * Version 1.0 ! * SMBlib Utility Routines ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #include "smblib-priv.h" + #include "smblib.h" #include "rfcnb.h" #include "rfcnb-priv.h" #include "rfcnb-util.h" #include #include + #include ! const char *SMB_Prots[] = ! {"PC NETWORK PROGRAM 1.0", ! "MICROSOFT NETWORKS 1.03", ! "MICROSOFT NETWORKS 3.0", ! "DOS LANMAN1.0", ! "LANMAN1.0", ! "DOS LM1.2X002", ! "LM1.2X002", ! "DOS LANMAN2.1", ! "LANMAN2.1", ! "Samba", ! "NT LM 0.12", ! "NT LANMAN 1.0", ! NULL}; ! ! int SMB_Types[] = ! {SMB_P_Core, ! SMB_P_CorePlus, ! SMB_P_DOSLanMan1, ! SMB_P_DOSLanMan1, ! SMB_P_LanMan1, ! SMB_P_DOSLanMan2, ! SMB_P_LanMan2, ! SMB_P_LanMan2_1, ! SMB_P_LanMan2_1, ! SMB_P_NT1, ! SMB_P_NT1, ! SMB_P_NT1, ! -1}; /* Figure out what protocol was accepted, given the list of dialect strings */ /* We offered, and the index back from the server. We allow for a user */ /* supplied list, and assume that it is a subset of our list */ ! static int ! SMB_Figure_Protocol(const char *dialects[], int prot_index) ! { ! int i; ! if (dialects == SMB_Prots) { /* The jobs is easy, just index into table */ ! return (SMB_Types[prot_index]); ! } else { /* Search through SMB_Prots looking for a match */ ! for (i = 0; SMB_Prots[i] != NULL; i++) { ! if (strcmp(dialects[prot_index], SMB_Prots[i]) == 0) { /* A match */ ! return (SMB_Types[i]); ! } ! } ! /* If we got here, then we are in trouble, because the protocol was not */ ! /* One we understand ... */ ! return (SMB_P_Unknown); ! } } *************** *** 228,763 **** /* we return the index of the accepted protocol in NegProt, -1 indicates */ /* none acceptible, and our return value is 0 if ok, <0 if problems */ ! int SMB_Negotiate(SMB_Handle_Type Con_Handle, char *Prots[]) { ! struct RFCNB_Pkt *pkt; ! int prots_len, i, pkt_len, prot, alloc_len; ! char *p; ! ! /* Figure out how long the prot list will be and allocate space for it */ ! prots_len = 0; ! for (i = 0; Prots[i] != NULL; i++) { ! prots_len = prots_len + strlen(Prots[i]) + 2; /* Account for null etc */ ! } ! /* The -1 accounts for the one byte smb_buf we have because some systems */ ! /* don't like char msg_buf[] */ ! pkt_len = SMB_negp_len + prots_len; ! /* Make sure that the pkt len is long enough for the max response ... */ ! /* Which is a problem, because the encryption key len eec may be long */ ! if (pkt_len < (SMB_hdr_wct_offset + (19 * 2) + 40)) { ! alloc_len = SMB_hdr_wct_offset + (19 * 2) + 40; ! } ! else { ! alloc_len = pkt_len; ! } ! pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(alloc_len); ! if (pkt == NULL) { ! SMBlib_errno = SMBlibE_NoSpace; ! return(SMBlibE_BAD); ! } ! /* Now plug in the bits we need */ ! bzero(SMB_Hdr(pkt), SMB_negp_len); ! SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */ ! *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBnegprot; ! SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle -> pid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle -> mid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle -> uid); ! *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 0; ! SSVAL(SMB_Hdr(pkt), SMB_negp_bcc_offset, prots_len); ! /* Now copy the prot strings in with the right stuff */ ! p = (char *)(SMB_Hdr(pkt) + SMB_negp_buf_offset); ! for (i = 0; Prots[i] != NULL; i++) { ! *p = SMBdialectID; ! strcpy(p + 1, Prots[i]); ! p = p + strlen(Prots[i]) + 2; /* Adjust len of p for null plus dialectID */ ! } ! /* Now send the packet and sit back ... */ ! if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0){ #ifdef DEBUG ! fprintf(stderr, "Error sending negotiate protocol\n"); #endif ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = -SMBlibE_SendFailed; /* Failed, check lower layer errno */ ! return(SMBlibE_BAD); ! } ! ! /* Now get the response ... */ ! if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, alloc_len) < 0) { #ifdef DEBUG ! fprintf(stderr, "Error receiving response to negotiate\n"); #endif ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = -SMBlibE_RecvFailed; /* Failed, check lower layer errno */ ! return(SMBlibE_BAD); ! ! } ! if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ #ifdef DEBUG ! fprintf(stderr, "SMB_Negotiate failed with errorclass = %i, Error Code = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset), SVAL(SMB_Hdr(pkt), SMB_hdr_err_offset)); #endif ! SMBlib_SMB_Error = IVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset); ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_Remote; ! return(SMBlibE_BAD); ! } ! ! if (SVAL(SMB_Hdr(pkt), SMB_negrCP_idx_offset) == 0xFFFF) { #ifdef DEBUG ! fprintf(stderr, "None of our protocols was accepted ... "); #endif ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_NegNoProt; ! return(SMBlibE_BAD); ! } ! /* Now, unpack the info from the response, if any and evaluate the proto */ ! /* selected. We must make sure it is one we like ... */ ! Con_Handle -> prot_IDX = prot = SVAL(SMB_Hdr(pkt), SMB_negrCP_idx_offset); ! Con_Handle -> protocol = SMB_Figure_Protocol(Prots, prot); ! if (Con_Handle -> protocol == SMB_P_Unknown) { /* No good ... */ ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_ProtUnknown; ! return(SMBlibE_BAD); ! } ! ! switch (CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)) { ! case 0x01: /* No more info ... */ ! break; ! case 13: /* Up to and including LanMan 2.1 */ ! Con_Handle -> Security = SVAL(SMB_Hdr(pkt), SMB_negrLM_sec_offset); ! Con_Handle -> encrypt_passwords = ((Con_Handle -> Security & SMB_sec_encrypt_mask) != 0x00); ! Con_Handle -> Security = Con_Handle -> Security & SMB_sec_user_mask; ! Con_Handle -> max_xmit = SVAL(SMB_Hdr(pkt), SMB_negrLM_mbs_offset); ! Con_Handle -> MaxMPX = SVAL(SMB_Hdr(pkt), SMB_negrLM_mmc_offset); ! Con_Handle -> MaxVC = SVAL(SMB_Hdr(pkt), SMB_negrLM_mnv_offset); ! Con_Handle -> Raw_Support = SVAL(SMB_Hdr(pkt), SMB_negrLM_rm_offset); ! Con_Handle -> SessionKey = IVAL(SMB_Hdr(pkt), SMB_negrLM_sk_offset); ! Con_Handle -> SvrTZ = SVAL(SMB_Hdr(pkt), SMB_negrLM_stz_offset); ! Con_Handle -> Encrypt_Key_Len = SVAL(SMB_Hdr(pkt), SMB_negrLM_ekl_offset); ! ! p = (SMB_Hdr(pkt) + SMB_negrLM_buf_offset); ! fprintf(stderr, "%d", (int)(SMB_Hdr(pkt) + SMB_negrLM_buf_offset)); ! memcpy(Con_Handle->Encrypt_Key, p, 8); ! p = (SMB_Hdr(pkt) + SMB_negrLM_buf_offset + Con_Handle -> Encrypt_Key_Len); ! strncpy(p, Con_Handle -> Svr_PDom, sizeof(Con_Handle -> Svr_PDom) - 1); ! break; ! case 17: /* NT LM 0.12 and LN LM 1.0 */ ! Con_Handle -> Security = SVAL(SMB_Hdr(pkt), SMB_negrNTLM_sec_offset); ! Con_Handle -> encrypt_passwords = ((Con_Handle -> Security & SMB_sec_encrypt_mask) != 0x00); ! Con_Handle -> Security = Con_Handle -> Security & SMB_sec_user_mask; ! Con_Handle -> max_xmit = IVAL(SMB_Hdr(pkt), SMB_negrNTLM_mbs_offset); ! Con_Handle -> MaxMPX = SVAL(SMB_Hdr(pkt), SMB_negrNTLM_mmc_offset); ! Con_Handle -> MaxVC = SVAL(SMB_Hdr(pkt), SMB_negrNTLM_mnv_offset); ! Con_Handle -> MaxRaw = IVAL(SMB_Hdr(pkt), SMB_negrNTLM_mrs_offset); ! Con_Handle -> SessionKey = IVAL(SMB_Hdr(pkt), SMB_negrNTLM_sk_offset); ! Con_Handle -> SvrTZ = SVAL(SMB_Hdr(pkt), SMB_negrNTLM_stz_offset); ! Con_Handle -> Encrypt_Key_Len = CVAL(SMB_Hdr(pkt), SMB_negrNTLM_ekl_offset); ! p = (SMB_Hdr(pkt) + SMB_negrNTLM_buf_offset ); ! memcpy(Con_Handle -> Encrypt_Key, p, 8); ! p = (SMB_Hdr(pkt) + SMB_negrNTLM_buf_offset + Con_Handle -> Encrypt_Key_Len); ! strncpy(p, Con_Handle -> Svr_PDom, sizeof(Con_Handle -> Svr_PDom) - 1); ! break; ! default: #ifdef DEBUG ! fprintf(stderr, "Unknown NegProt response format ... Ignored\n"); ! fprintf(stderr, " wct = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)); #endif ! break; ! } #ifdef DEBUG ! fprintf(stderr, "Protocol selected is: %i:%s\n", prot, Prots[prot]); #endif ! RFCNB_Free_Pkt(pkt); ! return(0); } /* Get our hostname */ ! void SMB_Get_My_Name(char *name, int len) ! { ! if (gethostname(name, len) < 0) { /* Error getting name */ ! strncpy(name, "unknown", len); ! /* Should check the error */ #ifdef DEBUG ! fprintf(stderr, "gethostname in SMB_Get_My_Name returned error:"); ! perror(""); #endif ! } ! ! /* only keep the portion up to the first "." */ } /* Send a TCON to the remote server ... */ ! SMB_Tree_Handle SMB_TreeConnect(SMB_Handle_Type Con_Handle, ! SMB_Tree_Handle Tree_Handle, ! char *path, ! char *password, ! char *device) ! ! { struct RFCNB_Pkt *pkt; ! int param_len, pkt_len; ! char *p; ! SMB_Tree_Handle tree; ! /* Figure out how much space is needed for path, password, dev ... */ ! if ((path == NULL) | (password == NULL) | (device == NULL)) { #ifdef DEBUG ! fprintf(stderr, "Bad parameter passed to SMB_TreeConnect\n"); #endif ! SMBlib_errno = SMBlibE_BadParam; ! return(NULL); ! } ! /* The + 2 is because of the \0 and the marker ... */ ! param_len = strlen(path) + 2 + strlen(password) + 2 + strlen(device) + 2; ! /* The -1 accounts for the one byte smb_buf we have because some systems */ ! /* don't like char msg_buf[] */ ! pkt_len = SMB_tcon_len + param_len; ! pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len); ! if (pkt == NULL) { ! SMBlib_errno = SMBlibE_NoSpace; ! return(NULL); /* Should handle the error */ ! } ! /* Now allocate a tree for this to go into ... */ ! if (Tree_Handle == NULL) { ! tree = (SMB_Tree_Handle)malloc(sizeof(struct SMB_Tree_Structure)); ! if (tree == NULL) { ! ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_NoSpace; ! return(NULL); ! ! } ! } ! else { ! tree = Tree_Handle; ! } ! tree -> next = tree -> prev = NULL; ! tree -> con = Con_Handle; ! strncpy(tree -> path, path, sizeof(tree -> path)); ! strncpy(tree -> device_type, device, sizeof(tree -> device_type)); ! /* Now plug in the values ... */ ! bzero(SMB_Hdr(pkt), SMB_tcon_len); ! SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */ ! *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBtcon; ! SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle -> pid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle -> mid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle -> uid); ! *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 0; ! SSVAL(SMB_Hdr(pkt), SMB_tcon_bcc_offset, param_len); ! /* Now copy the param strings in with the right stuff */ ! p = (char *)(SMB_Hdr(pkt) + SMB_tcon_buf_offset); ! *p = SMBasciiID; ! strcpy(p + 1, path); ! p = p + strlen(path) + 2; ! *p = SMBasciiID; ! strcpy(p + 1, password); ! p = p + strlen(password) + 2; ! *p = SMBasciiID; ! strcpy(p + 1, device); ! /* Now send the packet and sit back ... */ ! if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0){ #ifdef DEBUG ! fprintf(stderr, "Error sending TCon request\n"); #endif ! if (Tree_Handle == NULL) ! free(tree); ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = -SMBlibE_SendFailed; ! return(NULL); ! ! } ! /* Now get the response ... */ ! if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG ! fprintf(stderr, "Error receiving response to TCon\n"); #endif ! if (Tree_Handle == NULL) ! free(tree); ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = -SMBlibE_RecvFailed; ! return(NULL); ! ! } ! /* Check out the response type ... */ ! if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ #ifdef DEBUG ! fprintf(stderr, "SMB_TCon failed with errorclass = %i, Error Code = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset), SVAL(SMB_Hdr(pkt), SMB_hdr_err_offset)); #endif ! if (Tree_Handle == NULL) ! free(tree); ! SMBlib_SMB_Error = IVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset); ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_Remote; ! return(NULL); ! ! } ! ! tree -> tid = SVAL(SMB_Hdr(pkt), SMB_tconr_tid_offset); ! tree -> mbs = SVAL(SMB_Hdr(pkt), SMB_tconr_mbs_offset); ! ! #ifdef DEBUG ! fprintf(stderr, "TConn succeeded, with TID=%i, Max Xmit=%i\n", ! tree -> tid, tree -> mbs); ! #endif ! ! /* Now link the Tree to the Server Structure ... */ ! ! if (Con_Handle -> first_tree == NULL) { ! ! Con_Handle -> first_tree = tree; ! Con_Handle -> last_tree = tree; ! ! } ! else { ! ! Con_Handle -> last_tree -> next = tree; ! tree -> prev = Con_Handle -> last_tree; ! Con_Handle -> last_tree = tree; ! ! } ! ! RFCNB_Free_Pkt(pkt); ! return(tree); ! ! } ! ! int SMB_TreeDisconnect(SMB_Tree_Handle Tree_Handle, BOOL discard) ! ! { struct RFCNB_Pkt *pkt; ! int pkt_len; ! ! pkt_len = SMB_tdis_len; ! pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len); ! ! if (pkt == NULL) { ! ! SMBlib_errno = SMBlibE_NoSpace; ! return(SMBlibE_BAD); /* Should handle the error */ ! ! } ! ! /* Now plug in the values ... */ ! ! bzero(SMB_Hdr(pkt), SMB_tdis_len); ! SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */ ! *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBtdis; ! SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Tree_Handle -> con -> pid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Tree_Handle -> con -> mid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Tree_Handle -> con -> uid); ! *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 0; ! ! SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, Tree_Handle -> tid); ! SSVAL(SMB_Hdr(pkt), SMB_tcon_bcc_offset, 0); ! ! /* Now send the packet and sit back ... */ ! ! if (RFCNB_Send(Tree_Handle -> con -> Trans_Connect, pkt, pkt_len) < 0){ #ifdef DEBUG ! fprintf(stderr, "Error sending TDis request\n"); #endif ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = -SMBlibE_SendFailed; ! return(SMBlibE_BAD); ! ! } ! ! /* Now get the response ... */ ! ! if (RFCNB_Recv(Tree_Handle -> con -> Trans_Connect, pkt, pkt_len) < 0) { ! ! #ifdef DEBUG ! fprintf(stderr, "Error receiving response to TCon\n"); ! #endif ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = -SMBlibE_RecvFailed; ! return(SMBlibE_BAD); ! } ! /* Check out the response type ... */ ! if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ ! #ifdef DEBUG ! fprintf(stderr, "SMB_TDis failed with errorclass = %i, Error Code = %i\n", ! CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset), ! SVAL(SMB_Hdr(pkt), SMB_hdr_err_offset)); ! #endif - SMBlib_SMB_Error = IVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset); RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_Remote; ! return(SMBlibE_BAD); ! ! } ! ! Tree_Handle -> tid = 0xFFFF; /* Invalid TID */ ! Tree_Handle -> mbs = 0; /* Invalid */ ! ! #ifdef DEBUG ! ! fprintf(stderr, "Tree disconnect successful ...\n"); ! ! #endif ! ! /* What about the tree handle ? */ ! ! if (discard == TRUE) { /* Unlink it and free it ... */ ! ! if (Tree_Handle -> next == NULL) ! Tree_Handle -> con -> first_tree = Tree_Handle -> prev; ! else ! Tree_Handle -> next -> prev = Tree_Handle -> prev; ! ! if (Tree_Handle -> prev == NULL) ! Tree_Handle -> con -> last_tree = Tree_Handle -> next; ! else ! Tree_Handle -> prev -> next = Tree_Handle -> next; ! ! } ! ! RFCNB_Free_Pkt(pkt); ! return(0); } /* Pick up the last LMBlib error ... */ ! int SMB_Get_Last_Error() ! { ! return(SMBlib_errno); } /* Pick up the last error returned in an SMB packet */ /* We will need macros to extract error class and error code */ ! int SMB_Get_Last_SMB_Err() ! { ! return(SMBlib_SMB_Error); } --- 101,519 ---- /* we return the index of the accepted protocol in NegProt, -1 indicates */ /* none acceptible, and our return value is 0 if ok, <0 if problems */ ! int ! SMB_Negotiate(SMB_Handle_Type Con_Handle, const char *Prots[]) { ! struct RFCNB_Pkt *pkt; ! int prots_len, i, pkt_len, prot, alloc_len; ! char *p; ! /* Figure out how long the prot list will be and allocate space for it */ ! prots_len = 0; ! for (i = 0; Prots[i] != NULL; i++) { ! prots_len = prots_len + strlen(Prots[i]) + 2; /* Account for null etc */ ! } ! /* The -1 accounts for the one byte smb_buf we have because some systems */ ! /* don't like char msg_buf[] */ ! pkt_len = SMB_negp_len + prots_len; ! /* Make sure that the pkt len is long enough for the max response ... */ ! /* Which is a problem, because the encryption key len eec may be long */ ! if (pkt_len < (SMB_hdr_wct_offset + (19 * 2) + 40)) { ! alloc_len = SMB_hdr_wct_offset + (19 * 2) + 40; ! } else { ! alloc_len = pkt_len; ! } ! pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(alloc_len); ! if (pkt == NULL) { ! SMBlib_errno = SMBlibE_NoSpace; ! return (SMBlibE_BAD); ! } ! /* Now plug in the bits we need */ ! bzero(SMB_Hdr(pkt), SMB_negp_len); ! SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */ ! *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBnegprot; ! SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle->pid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle->mid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle->uid); ! *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 0; ! SSVAL(SMB_Hdr(pkt), SMB_negp_bcc_offset, prots_len); ! /* Now copy the prot strings in with the right stuff */ ! p = (char *) (SMB_Hdr(pkt) + SMB_negp_buf_offset); ! for (i = 0; Prots[i] != NULL; i++) { ! *p = SMBdialectID; ! strcpy(p + 1, Prots[i]); ! p = p + strlen(Prots[i]) + 2; /* Adjust len of p for null plus dialectID */ ! } ! /* Now send the packet and sit back ... */ ! if (RFCNB_Send(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG ! fprintf(stderr, "Error sending negotiate protocol\n"); #endif ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = -SMBlibE_SendFailed; /* Failed, check lower layer errno */ ! return (SMBlibE_BAD); ! } ! /* Now get the response ... */ ! if (RFCNB_Recv(Con_Handle->Trans_Connect, pkt, alloc_len) < 0) { #ifdef DEBUG ! fprintf(stderr, "Error receiving response to negotiate\n"); #endif ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = -SMBlibE_RecvFailed; /* Failed, check lower layer errno */ ! return (SMBlibE_BAD); ! } ! if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ #ifdef DEBUG ! fprintf(stderr, "SMB_Negotiate failed with errorclass = %i, Error Code = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset), SVAL(SMB_Hdr(pkt), SMB_hdr_err_offset)); #endif ! SMBlib_SMB_Error = IVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset); ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_Remote; ! return (SMBlibE_BAD); ! } ! if (SVAL(SMB_Hdr(pkt), SMB_negrCP_idx_offset) == 0xFFFF) { #ifdef DEBUG ! fprintf(stderr, "None of our protocols was accepted ... "); #endif ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_NegNoProt; ! return (SMBlibE_BAD); ! } ! /* Now, unpack the info from the response, if any and evaluate the proto */ ! /* selected. We must make sure it is one we like ... */ ! Con_Handle->prot_IDX = prot = SVAL(SMB_Hdr(pkt), SMB_negrCP_idx_offset); ! Con_Handle->protocol = SMB_Figure_Protocol(Prots, prot); ! if (Con_Handle->protocol == SMB_P_Unknown) { /* No good ... */ ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_ProtUnknown; ! return (SMBlibE_BAD); ! } ! switch (CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)) { ! case 0x01: /* No more info ... */ ! break; ! case 13: /* Up to and including LanMan 2.1 */ ! Con_Handle->Security = SVAL(SMB_Hdr(pkt), SMB_negrLM_sec_offset); ! Con_Handle->encrypt_passwords = ((Con_Handle->Security & SMB_sec_encrypt_mask) != 0x00); ! Con_Handle->Security = Con_Handle->Security & SMB_sec_user_mask; ! Con_Handle->max_xmit = SVAL(SMB_Hdr(pkt), SMB_negrLM_mbs_offset); ! Con_Handle->MaxMPX = SVAL(SMB_Hdr(pkt), SMB_negrLM_mmc_offset); ! Con_Handle->MaxVC = SVAL(SMB_Hdr(pkt), SMB_negrLM_mnv_offset); ! Con_Handle->Raw_Support = SVAL(SMB_Hdr(pkt), SMB_negrLM_rm_offset); ! Con_Handle->SessionKey = IVAL(SMB_Hdr(pkt), SMB_negrLM_sk_offset); ! Con_Handle->SvrTZ = SVAL(SMB_Hdr(pkt), SMB_negrLM_stz_offset); ! Con_Handle->Encrypt_Key_Len = SVAL(SMB_Hdr(pkt), SMB_negrLM_ekl_offset); ! p = (SMB_Hdr(pkt) + SMB_negrLM_buf_offset); ! fprintf(stderr, "%d", (int) (SMB_Hdr(pkt) + SMB_negrLM_buf_offset)); ! memcpy(Con_Handle->Encrypt_Key, p, 8); ! p = (SMB_Hdr(pkt) + SMB_negrLM_buf_offset + Con_Handle->Encrypt_Key_Len); ! strncpy(p, Con_Handle->Svr_PDom, sizeof(Con_Handle->Svr_PDom) - 1); ! break; ! case 17: /* NT LM 0.12 and LN LM 1.0 */ ! Con_Handle->Security = SVAL(SMB_Hdr(pkt), SMB_negrNTLM_sec_offset); ! Con_Handle->encrypt_passwords = ((Con_Handle->Security & SMB_sec_encrypt_mask) != 0x00); ! Con_Handle->Security = Con_Handle->Security & SMB_sec_user_mask; ! Con_Handle->max_xmit = IVAL(SMB_Hdr(pkt), SMB_negrNTLM_mbs_offset); ! Con_Handle->MaxMPX = SVAL(SMB_Hdr(pkt), SMB_negrNTLM_mmc_offset); ! Con_Handle->MaxVC = SVAL(SMB_Hdr(pkt), SMB_negrNTLM_mnv_offset); ! Con_Handle->MaxRaw = IVAL(SMB_Hdr(pkt), SMB_negrNTLM_mrs_offset); ! Con_Handle->SessionKey = IVAL(SMB_Hdr(pkt), SMB_negrNTLM_sk_offset); ! Con_Handle->SvrTZ = SVAL(SMB_Hdr(pkt), SMB_negrNTLM_stz_offset); ! Con_Handle->Encrypt_Key_Len = CVAL(SMB_Hdr(pkt), SMB_negrNTLM_ekl_offset); ! p = (SMB_Hdr(pkt) + SMB_negrNTLM_buf_offset); ! memcpy(Con_Handle->Encrypt_Key, p, 8); ! p = (SMB_Hdr(pkt) + SMB_negrNTLM_buf_offset + Con_Handle->Encrypt_Key_Len); ! strncpy(p, Con_Handle->Svr_PDom, sizeof(Con_Handle->Svr_PDom) - 1); ! break; ! default: #ifdef DEBUG ! fprintf(stderr, "Unknown NegProt response format ... Ignored\n"); ! fprintf(stderr, " wct = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)); #endif ! break; ! } #ifdef DEBUG ! fprintf(stderr, "Protocol selected is: %i:%s\n", prot, Prots[prot]); #endif ! RFCNB_Free_Pkt(pkt); ! return (0); } /* Get our hostname */ ! void ! SMB_Get_My_Name(char *name, int len) { ! if (gethostname(name, len) < 0) { /* Error getting name */ ! strncpy(name, "unknown", len); ! /* Should check the error */ #ifdef DEBUG ! fprintf(stderr, "gethostname in SMB_Get_My_Name returned error:"); ! perror(""); #endif ! } ! /* only keep the portion up to the first "." */ } /* Send a TCON to the remote server ... */ ! SMB_Tree_Handle ! SMB_TreeConnect(SMB_Handle_Type Con_Handle, ! SMB_Tree_Handle Tree_Handle, ! char *path, ! char *password, ! const char *device) ! { ! struct RFCNB_Pkt *pkt; ! int param_len, pkt_len; ! char *p; ! SMB_Tree_Handle tree; ! /* Figure out how much space is needed for path, password, dev ... */ ! if ((path == NULL) | (password == NULL) | (device == NULL)) { #ifdef DEBUG ! fprintf(stderr, "Bad parameter passed to SMB_TreeConnect\n"); #endif ! SMBlib_errno = SMBlibE_BadParam; ! return (NULL); ! } ! /* The + 2 is because of the \0 and the marker ... */ ! param_len = strlen(path) + 2 + strlen(password) + 2 + strlen(device) + 2; ! /* The -1 accounts for the one byte smb_buf we have because some systems */ ! /* don't like char msg_buf[] */ ! pkt_len = SMB_tcon_len + param_len; ! pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len); ! if (pkt == NULL) { ! SMBlib_errno = SMBlibE_NoSpace; ! return (NULL); /* Should handle the error */ ! } ! /* Now allocate a tree for this to go into ... */ ! if (Tree_Handle == NULL) { ! tree = (SMB_Tree_Handle) malloc(sizeof(struct SMB_Tree_Structure)); ! if (tree == NULL) { ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_NoSpace; ! return (NULL); ! } ! } else { ! tree = Tree_Handle; ! } ! tree->next = tree->prev = NULL; ! tree->con = Con_Handle; ! strncpy(tree->path, path, sizeof(tree->path)); ! strncpy(tree->device_type, device, sizeof(tree->device_type)); ! /* Now plug in the values ... */ ! bzero(SMB_Hdr(pkt), SMB_tcon_len); ! SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */ ! *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBtcon; ! SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle->pid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle->mid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle->uid); ! *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 0; ! SSVAL(SMB_Hdr(pkt), SMB_tcon_bcc_offset, param_len); ! /* Now copy the param strings in with the right stuff */ ! p = (char *) (SMB_Hdr(pkt) + SMB_tcon_buf_offset); ! *p = SMBasciiID; ! strcpy(p + 1, path); ! p = p + strlen(path) + 2; ! *p = SMBasciiID; ! strcpy(p + 1, password); ! p = p + strlen(password) + 2; ! *p = SMBasciiID; ! strcpy(p + 1, device); ! /* Now send the packet and sit back ... */ ! if (RFCNB_Send(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG ! fprintf(stderr, "Error sending TCon request\n"); #endif ! if (Tree_Handle == NULL) ! free(tree); ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = -SMBlibE_SendFailed; ! return (NULL); ! } ! /* Now get the response ... */ ! if (RFCNB_Recv(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG ! fprintf(stderr, "Error receiving response to TCon\n"); #endif ! if (Tree_Handle == NULL) ! free(tree); ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = -SMBlibE_RecvFailed; ! return (NULL); ! } ! /* Check out the response type ... */ ! if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ #ifdef DEBUG ! fprintf(stderr, "SMB_TCon failed with errorclass = %i, Error Code = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset), SVAL(SMB_Hdr(pkt), SMB_hdr_err_offset)); #endif ! if (Tree_Handle == NULL) ! free(tree); ! SMBlib_SMB_Error = IVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset); ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_Remote; ! return (NULL); ! } ! tree->tid = SVAL(SMB_Hdr(pkt), SMB_tconr_tid_offset); ! tree->mbs = SVAL(SMB_Hdr(pkt), SMB_tconr_mbs_offset); #ifdef DEBUG ! fprintf(stderr, "TConn succeeded, with TID=%i, Max Xmit=%i\n", ! tree->tid, tree->mbs); #endif ! /* Now link the Tree to the Server Structure ... */ ! if (Con_Handle->first_tree == NULL) { ! Con_Handle->first_tree = tree; ! Con_Handle->last_tree = tree; ! } else { ! Con_Handle->last_tree->next = tree; ! tree->prev = Con_Handle->last_tree; ! Con_Handle->last_tree = tree; ! } RFCNB_Free_Pkt(pkt); ! return (tree); } /* Pick up the last LMBlib error ... */ ! int ! SMB_Get_Last_Error() { ! return (SMBlib_errno); } /* Pick up the last error returned in an SMB packet */ /* We will need macros to extract error class and error code */ ! int ! SMB_Get_Last_SMB_Err() { ! return (SMBlib_SMB_Error); } *************** *** 765,821 **** /* Keep this table in sync with the message codes in smblib-common.h */ ! static char *SMBlib_Error_Messages[] = { ! "Request completed sucessfully.", ! "Server returned a non-zero SMB Error Class and Code.", ! "A lower layer protocol error occurred.", ! "Function not yet implemented.", ! "The protocol negotiated does not support the request.", ! "No space available for operation.", ! "One or more bad parameters passed.", ! "None of the protocols we offered were accepted.", ! "The attempt to send an SMB request failed. See protocol error info.", ! "The attempt to get an SMB response failed. See protocol error info.", ! "The logon request failed, but you were logged in as guest.", ! "The attempt to call the remote server failed. See protocol error info.", ! "The protocol dialect specified in a NegProt and accepted by the server is unknown.", /* This next one simplifies error handling */ ! "No such error code.", ! NULL}; ! ! void SMB_Get_Error_Msg(int msg, char *msgbuf, int len) { ! if (msg >= 0) { ! strncpy(msgbuf, ! SMBlib_Error_Messages[msg>SMBlibE_NoSuchMsg?SMBlibE_NoSuchMsg:msg], len - 1); ! msgbuf[len - 1] = 0; /* Make sure it is a string */ ! } ! else { /* Add the lower layer message ... */ ! char prot_msg[1024]; ! msg = -msg; /* Make it positive */ ! strncpy(msgbuf, ! SMBlib_Error_Messages[msg>SMBlibE_NoSuchMsg?SMBlibE_NoSuchMsg:msg], len - 1); ! msgbuf[len - 1] = 0; /* make sure it is a string */ ! if (strlen(msgbuf) < len) { /* If there is space, put rest in */ ! strncat(msgbuf, "\n\t", len - strlen(msgbuf)); ! RFCNB_Get_Error(prot_msg, sizeof(prot_msg) - 1); ! strncat(msgbuf, prot_msg, len - strlen(msgbuf)); } - } } --- 521,577 ---- /* Keep this table in sync with the message codes in smblib-common.h */ ! static const char *SMBlib_Error_Messages[] = ! { ! "Request completed sucessfully.", ! "Server returned a non-zero SMB Error Class and Code.", ! "A lower layer protocol error occurred.", ! "Function not yet implemented.", ! "The protocol negotiated does not support the request.", ! "No space available for operation.", ! "One or more bad parameters passed.", ! "None of the protocols we offered were accepted.", ! "The attempt to send an SMB request failed. See protocol error info.", ! "The attempt to get an SMB response failed. See protocol error info.", ! "The logon request failed, but you were logged in as guest.", ! "The attempt to call the remote server failed. See protocol error info.", ! "The protocol dialect specified in a NegProt and accepted by the server is unknown.", /* This next one simplifies error handling */ ! "No such error code.", ! NULL}; + void + SMB_Get_Error_Msg(int msg, char *msgbuf, int len) { ! if (msg >= 0) { ! strncpy(msgbuf, ! SMBlib_Error_Messages[msg > SMBlibE_NoSuchMsg ? SMBlibE_NoSuchMsg : msg], len - 1); ! msgbuf[len - 1] = 0; /* Make sure it is a string */ ! } else { /* Add the lower layer message ... */ ! char prot_msg[1024]; ! msg = -msg; /* Make it positive */ ! strncpy(msgbuf, ! SMBlib_Error_Messages[msg > SMBlibE_NoSuchMsg ? SMBlibE_NoSuchMsg : msg], len - 1); ! msgbuf[len - 1] = 0; /* make sure it is a string */ ! if (strlen(msgbuf) < len) { /* If there is space, put rest in */ ! strncat(msgbuf, "\n\t", len - strlen(msgbuf)); ! RFCNB_Get_Error(prot_msg, sizeof(prot_msg) - 1); ! strncat(msgbuf, prot_msg, len - strlen(msgbuf)); + } } } diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/smblib.c squid-2.4.STABLE7/auth_modules/MSNT/smblib.c *** squid-2.4.STABLE6/auth_modules/MSNT/smblib.c Sat Feb 17 03:18:31 2001 --- squid-2.4.STABLE7/auth_modules/MSNT/smblib.c Wed Jun 26 13:24:45 2002 *************** *** 1,27 **** /* UNIX SMBlib NetBIOS implementation ! ! Version 1.0 ! SMBlib Routines ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ int SMBlib_errno; int SMBlib_SMB_Error; --- 1,27 ---- /* UNIX SMBlib NetBIOS implementation ! * ! * Version 1.0 ! * SMBlib Routines ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ int SMBlib_errno; int SMBlib_SMB_Error; *************** *** 32,201 **** #include "rfcnb-priv.h" #include "rfcnb.h" #include "rfcnb-util.h" #include #include #include #include - #include SMB_State_Types SMBlib_State; - extern int RFCNB_Set_Sock_NoDelay(RFCNB_Con *, BOOL); - extern void SMB_Get_My_Name(char *, int); - /* Initialize the SMBlib package */ ! int SMB_Init() ! { ! SMBlib_State = SMB_State_Started; ! signal(SIGPIPE, SIG_IGN); /* Ignore these ... */ /* If SMBLIB_Instrument is defines, turn on the instrumentation stuff */ #ifdef SMBLIB_INSTRUMENT ! SMBlib_Instrument_Init(); ! ! #endif ! ! return 0; ! ! } ! ! int SMB_Term() ! ! { ! ! #ifdef SMBLIB_INSTRUMENT ! ! SMBlib_Instrument_Term(); /* Clean up and print results */ #endif ! return 0; } /* SMB_Create: Create a connection structure and return for later use */ /* We have other helper routines to set variables */ ! SMB_Handle_Type SMB_Create_Con_Handle(void) ! { ! SMBlib_errno = SMBlibE_NotImpl; ! return(NULL); ! ! } ! ! int SMBlib_Set_Sock_NoDelay(SMB_Handle_Type Con_Handle, BOOL yn) ! ! { ! ! ! if (RFCNB_Set_Sock_NoDelay(Con_Handle -> Trans_Connect, yn) < 0) { ! ! #ifdef DEBUG ! #endif ! ! fprintf(stderr, "Setting no-delay on TCP socket failed ...\n"); ! ! } ! ! return(0); } /* SMB_Connect_Server: Connect to a server, but don't negotiate protocol */ /* or anything else ... */ ! SMB_Handle_Type SMB_Connect_Server(SMB_Handle_Type Con_Handle, ! char *server, char *NTdomain) ! ! { SMB_Handle_Type con; ! char called[80], calling[80], *address; ! int i; ! /* Get a connection structure if one does not exist */ ! con = Con_Handle; ! if (Con_Handle == NULL) { ! if ((con = (struct SMB_Connect_Def *)malloc(sizeof(struct SMB_Connect_Def))) == NULL) { ! SMBlib_errno = SMBlibE_NoSpace; ! return NULL; } ! } ! ! /* Init some things ... */ ! strcpy(con -> service, ""); ! strcpy(con -> username, ""); ! strcpy(con -> password, ""); ! strcpy(con -> sock_options, ""); ! strcpy(con -> address, ""); ! strcpy(con -> desthost, server); ! strcpy(con -> PDomain, NTdomain); ! strcpy(con -> OSName, SMBLIB_DEFAULT_OSNAME); ! strcpy(con -> LMType, SMBLIB_DEFAULT_LMTYPE); ! con -> first_tree = con -> last_tree = NULL; ! SMB_Get_My_Name(con -> myname, sizeof(con -> myname)); ! con -> port = 0; /* No port selected */ ! /* Get some things we need for the SMB Header */ ! con -> pid = getpid(); ! con -> mid = con -> pid; /* This will do for now ... */ ! con -> uid = 0; /* Until we have done a logon, no uid ... */ ! con -> gid = getgid(); ! /* Now connect to the remote end, but first upper case the name of the ! service we are going to call, sine some servers want it in uppercase */ ! for (i=0; i < strlen(server); i++) ! called[i] = toupper(server[i]); ! ! called[strlen(server)] = 0; /* Make it a string */ ! for (i=0; i < strlen(con -> myname); i++) ! calling[i] = toupper(con -> myname[i]); ! ! calling[strlen(con -> myname)] = 0; /* Make it a string */ ! if (strcmp(con -> address, "") == 0) ! address = con -> desthost; ! else ! address = con -> address; ! con -> Trans_Connect = RFCNB_Call(called, ! calling, ! address, /* Protocol specific */ ! con -> port); ! /* Did we get one? */ ! if (con -> Trans_Connect == NULL) { ! if (Con_Handle == NULL) { ! Con_Handle = NULL; ! free(con); ! } ! SMBlib_errno = -SMBlibE_CallFailed; ! return NULL; ! } ! return(con); } --- 32,164 ---- #include "rfcnb-priv.h" #include "rfcnb.h" #include "rfcnb-util.h" + #include "smbencrypt.h" #include #include #include #include #include SMB_State_Types SMBlib_State; /* Initialize the SMBlib package */ ! int ! SMB_Init(void) { ! SMBlib_State = SMB_State_Started; ! signal(SIGPIPE, SIG_IGN); /* Ignore these ... */ /* If SMBLIB_Instrument is defines, turn on the instrumentation stuff */ #ifdef SMBLIB_INSTRUMENT ! SMBlib_Instrument_Init(); #endif ! return 0; } /* SMB_Create: Create a connection structure and return for later use */ /* We have other helper routines to set variables */ ! SMB_Handle_Type ! SMB_Create_Con_Handle(void) { ! SMBlib_errno = SMBlibE_NotImpl; ! return (NULL); } /* SMB_Connect_Server: Connect to a server, but don't negotiate protocol */ /* or anything else ... */ ! SMB_Handle_Type ! SMB_Connect_Server(SMB_Handle_Type Con_Handle, ! char *server, char *NTdomain) ! { ! SMB_Handle_Type con; ! char called[80], calling[80], *address; ! int i; ! /* Get a connection structure if one does not exist */ ! con = Con_Handle; ! if (Con_Handle == NULL) { ! if ((con = (struct SMB_Connect_Def *) malloc(sizeof(struct SMB_Connect_Def))) == NULL) { ! SMBlib_errno = SMBlibE_NoSpace; ! return NULL; ! } } + /* Init some things ... */ ! strcpy(con->service, ""); ! strcpy(con->username, ""); ! strcpy(con->password, ""); ! strcpy(con->sock_options, ""); ! strcpy(con->address, ""); ! strcpy(con->desthost, server); ! strcpy(con->PDomain, NTdomain); ! strcpy(con->OSName, SMBLIB_DEFAULT_OSNAME); ! strcpy(con->LMType, SMBLIB_DEFAULT_LMTYPE); ! con->first_tree = con->last_tree = NULL; ! SMB_Get_My_Name(con->myname, sizeof(con->myname)); ! con->port = 0; /* No port selected */ ! /* Get some things we need for the SMB Header */ ! con->pid = getpid(); ! con->mid = con->pid; /* This will do for now ... */ ! con->uid = 0; /* Until we have done a logon, no uid ... */ ! con->gid = getgid(); ! /* Now connect to the remote end, but first upper case the name of the ! * service we are going to call, sine some servers want it in uppercase */ ! for (i = 0; i < strlen(server); i++) ! called[i] = toupper(server[i]); ! called[strlen(server)] = 0; /* Make it a string */ ! for (i = 0; i < strlen(con->myname); i++) ! calling[i] = toupper(con->myname[i]); ! calling[strlen(con->myname)] = 0; /* Make it a string */ ! if (strcmp(con->address, "") == 0) ! address = con->desthost; ! else ! address = con->address; ! con->Trans_Connect = RFCNB_Call(called, ! calling, ! address, /* Protocol specific */ ! con->port); ! /* Did we get one? */ ! if (con->Trans_Connect == NULL) { ! if (Con_Handle == NULL) { ! Con_Handle = NULL; ! free(con); ! } ! SMBlib_errno = -SMBlibE_CallFailed; ! return NULL; ! } ! return (con); } *************** *** 203,569 **** /* If Con_Handle == NULL then create a handle and connect, otherwise */ /* use the handle passed */ ! char *SMB_Prots_Restrict[] = {"PC NETWORK PROGRAM 1.0", ! NULL}; ! SMB_Handle_Type SMB_Connect(SMB_Handle_Type Con_Handle, ! SMB_Tree_Handle *tree, ! char *service, ! char *username, ! char *password) ! ! { SMB_Handle_Type con; ! char *host, *address; ! char temp[80], called[80], calling[80]; ! int i; ! /* Get a connection structure if one does not exist */ ! con = Con_Handle; ! if (Con_Handle == NULL) { ! if ((con = (struct SMB_Connect_Def *)malloc(sizeof(struct SMB_Connect_Def))) == NULL) { ! SMBlib_errno = SMBlibE_NoSpace; ! return NULL; } ! } ! ! /* Init some things ... */ ! ! strcpy(con -> service, service); ! strcpy(con -> username, username); ! strcpy(con -> password, password); ! strcpy(con -> sock_options, ""); ! strcpy(con -> address, ""); ! strcpy(con -> PDomain, SMBLIB_DEFAULT_DOMAIN); ! strcpy(con -> OSName, SMBLIB_DEFAULT_OSNAME); ! strcpy(con -> LMType, SMBLIB_DEFAULT_LMTYPE); ! con -> first_tree = con -> last_tree = NULL; ! ! SMB_Get_My_Name(con -> myname, sizeof(con -> myname)); ! con -> port = 0; /* No port selected */ ! /* Get some things we need for the SMB Header */ ! con -> pid = getpid(); ! con -> mid = con -> pid; /* This will do for now ... */ ! con -> uid = 0; /* Until we have done a logon, no uid */ ! con -> gid = getgid(); ! /* Now figure out the host portion of the service */ ! strcpy(temp, service); ! /* AI - Added (char *) to stop compiler warnings */ ! host = (char *) strtok(temp, "/\\"); /* Separate host name portion */ ! strcpy(con -> desthost, host); ! /* Now connect to the remote end, but first upper case the name of the ! service we are going to call, sine some servers want it in uppercase */ ! for (i=0; i < strlen(host); i++) ! called[i] = toupper(host[i]); ! ! called[strlen(host)] = 0; /* Make it a string */ ! for (i=0; i < strlen(con -> myname); i++) ! calling[i] = toupper(con -> myname[i]); ! ! calling[strlen(con -> myname)] = 0; /* Make it a string */ ! if (strcmp(con -> address, "") == 0) ! address = con -> desthost; ! else ! address = con -> address; ! con -> Trans_Connect = RFCNB_Call(called, ! calling, ! address, /* Protocol specific */ ! con -> port); ! /* Did we get one? */ ! if (con -> Trans_Connect == NULL) { ! if (Con_Handle == NULL) { ! free(con); ! Con_Handle = NULL; ! } ! SMBlib_errno = -SMBlibE_CallFailed; ! return NULL; ! } ! /* Now, negotiate the protocol */ ! if (SMB_Negotiate(con, SMB_Prots_Restrict) < 0) { ! /* Hmmm what should we do here ... We have a connection, but could not ! negotiate ... */ ! return NULL; ! } ! /* Now connect to the service ... */ ! if ((*tree = SMB_TreeConnect(con, NULL, service, password, "A:")) == NULL) { ! return NULL; ! } ! return(con); } /* Logon to the server. That is, do a session setup if we can. We do not do */ /* Unicode yet! */ ! int SMB_Logon_Server(SMB_Handle_Type Con_Handle, char *UserName, ! char *PassWord) ! ! { struct RFCNB_Pkt *pkt; ! int param_len, pkt_len, pass_len; ! char *p, pword[128]; ! ! /* First we need a packet etc ... but we need to know what protocol has */ ! /* been negotiated to figure out if we can do it and what SMB format to */ ! /* use ... */ ! ! if (Con_Handle -> protocol < SMB_P_LanMan1) { ! SMBlib_errno = SMBlibE_ProtLow; ! return(SMBlibE_BAD); ! } ! strcpy(pword, PassWord); #ifdef PAM_SMB_ENC_PASS ! if (Con_Handle -> encrypt_passwords) ! { ! pass_len=24; ! SMBencrypt((uchar *) PassWord, (uchar *)Con_Handle -> Encrypt_Key,(uchar *)pword); ! } ! else #endif ! pass_len=strlen(pword); ! - /* Now build the correct structure */ ! if (Con_Handle -> protocol < SMB_P_NT1) { ! param_len = strlen(UserName) + 1 + pass_len + 1 + ! strlen(Con_Handle -> PDomain) + 1 + ! strlen(Con_Handle -> OSName) + 1; ! pkt_len = SMB_ssetpLM_len + param_len; ! pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len); ! if (pkt == NULL) { ! SMBlib_errno = SMBlibE_NoSpace; ! return(SMBlibE_BAD); /* Should handle the error */ ! } ! bzero(SMB_Hdr(pkt), SMB_ssetpLM_len); ! SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */ ! *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBsesssetupX; ! SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle -> pid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle -> mid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle -> uid); ! *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 10; ! *(SMB_Hdr(pkt) + SMB_hdr_axc_offset) = 0xFF; /* No extra command */ ! SSVAL(SMB_Hdr(pkt), SMB_hdr_axo_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_mbs_offset, SMBLIB_MAX_XMIT); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_mmc_offset, 2); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_vcn_offset, Con_Handle -> pid); ! SIVAL(SMB_Hdr(pkt), SMB_ssetpLM_snk_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_pwl_offset, pass_len + 1); ! SIVAL(SMB_Hdr(pkt), SMB_ssetpLM_res_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_bcc_offset, param_len); ! /* Now copy the param strings in with the right stuff */ ! p = (char *)(SMB_Hdr(pkt) + SMB_ssetpLM_buf_offset); ! /* Copy in password, then the rest. Password has a null at end */ ! memcpy(p, pword, pass_len); ! p = p + pass_len + 1; ! strcpy(p, UserName); ! p = p + strlen(UserName); ! *p = 0; ! p = p + 1; ! strcpy(p, Con_Handle -> PDomain); ! p = p + strlen(Con_Handle -> PDomain); ! *p = 0; ! p = p + 1; ! strcpy(p, Con_Handle -> OSName); ! p = p + strlen(Con_Handle -> OSName); ! *p = 0; ! } ! else { ! /* We don't admit to UNICODE support ... */ ! param_len = strlen(UserName) + 1 + pass_len + ! strlen(Con_Handle -> PDomain) + 1 + ! strlen(Con_Handle -> OSName) + 1 + ! strlen(Con_Handle -> LMType) + 1; ! pkt_len = SMB_ssetpNTLM_len + param_len; ! pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len); ! if (pkt == NULL) { ! SMBlib_errno = SMBlibE_NoSpace; ! return(-1); /* Should handle the error */ ! ! } ! bzero(SMB_Hdr(pkt), SMB_ssetpNTLM_len); ! SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */ ! *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBsesssetupX; ! SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle -> pid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle -> mid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle -> uid); ! *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 13; ! *(SMB_Hdr(pkt) + SMB_hdr_axc_offset) = 0xFF; /* No extra command */ ! SSVAL(SMB_Hdr(pkt), SMB_hdr_axo_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_mbs_offset, SMBLIB_MAX_XMIT); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_mmc_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_vcn_offset, 0); ! SIVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_snk_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cipl_offset, pass_len); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cspl_offset, 0); ! SIVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_res_offset, 0); ! SIVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cap_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_bcc_offset, param_len); ! /* Now copy the param strings in with the right stuff */ ! p = (char *)(SMB_Hdr(pkt) + SMB_ssetpNTLM_buf_offset); ! /* Copy in password, then the rest. Password has no null at end */ ! memcpy(p, pword, pass_len); ! p = p + pass_len; ! strcpy(p, UserName); ! p = p + strlen(UserName); ! *p = 0; ! p = p + 1; ! strcpy(p, Con_Handle -> PDomain); ! p = p + strlen(Con_Handle -> PDomain); ! *p = 0; ! p = p + 1; ! strcpy(p, Con_Handle -> OSName); ! p = p + strlen(Con_Handle -> OSName); ! *p = 0; ! p = p + 1; ! strcpy(p, Con_Handle -> LMType); ! p = p + strlen(Con_Handle -> LMType); ! *p = 0; ! } ! /* Now send it and get a response */ ! if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0){ #ifdef DEBUG ! fprintf(stderr, "Error sending SessSetupX request\n"); #endif ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_SendFailed; ! return(SMBlibE_BAD); ! ! } ! /* Now get the response ... */ ! if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG ! fprintf(stderr, "Error receiving response to SessSetupAndX\n"); #endif ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_RecvFailed; ! return(SMBlibE_BAD); ! ! } ! /* Check out the response type ... */ ! if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ #ifdef DEBUG ! fprintf(stderr, "SMB_SessSetupAndX failed with errorclass = %i, Error Code = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset), SVAL(SMB_Hdr(pkt), SMB_hdr_err_offset)); #endif ! SMBlib_SMB_Error = IVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset); ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_Remote; ! return(SMBlibE_BAD); ! ! } #ifdef DEBUG ! fprintf(stderr, "SessSetupAndX response. Action = %i\n", ! SVAL(SMB_Hdr(pkt), SMB_ssetpr_act_offset)); #endif ! /* Now pick up the UID for future reference ... */ ! Con_Handle -> uid = SVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset); ! RFCNB_Free_Pkt(pkt); ! return(0); } /* Disconnect from the server, and disconnect all tree connects */ ! int SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle) ! { ! /* We just disconnect the connection for now ... */ ! RFCNB_Hangup(Con_Handle -> Trans_Connect); ! if (!KeepHandle) ! free(Con_Handle); ! return(0); } --- 166,521 ---- /* If Con_Handle == NULL then create a handle and connect, otherwise */ /* use the handle passed */ ! const char *SMB_Prots_Restrict[] = ! {"PC NETWORK PROGRAM 1.0", ! NULL}; ! SMB_Handle_Type ! SMB_Connect(SMB_Handle_Type Con_Handle, ! SMB_Tree_Handle * tree, ! char *service, ! char *username, ! char *password) ! { ! SMB_Handle_Type con; ! char *host, *address; ! char temp[80], called[80], calling[80]; ! int i; ! /* Get a connection structure if one does not exist */ ! con = Con_Handle; ! if (Con_Handle == NULL) { ! if ((con = (struct SMB_Connect_Def *) malloc(sizeof(struct SMB_Connect_Def))) == NULL) { ! SMBlib_errno = SMBlibE_NoSpace; ! return NULL; ! } } + /* Init some things ... */ ! strcpy(con->service, service); ! strcpy(con->username, username); ! strcpy(con->password, password); ! strcpy(con->sock_options, ""); ! strcpy(con->address, ""); ! strcpy(con->PDomain, SMBLIB_DEFAULT_DOMAIN); ! strcpy(con->OSName, SMBLIB_DEFAULT_OSNAME); ! strcpy(con->LMType, SMBLIB_DEFAULT_LMTYPE); ! con->first_tree = con->last_tree = NULL; ! SMB_Get_My_Name(con->myname, sizeof(con->myname)); ! con->port = 0; /* No port selected */ ! /* Get some things we need for the SMB Header */ ! con->pid = getpid(); ! con->mid = con->pid; /* This will do for now ... */ ! con->uid = 0; /* Until we have done a logon, no uid */ ! con->gid = getgid(); ! /* Now figure out the host portion of the service */ ! strcpy(temp, service); ! /* AI - Added (char *) to stop compiler warnings */ ! host = (char *) strtok(temp, "/\\"); /* Separate host name portion */ ! strcpy(con->desthost, host); ! /* Now connect to the remote end, but first upper case the name of the ! * service we are going to call, sine some servers want it in uppercase */ ! for (i = 0; i < strlen(host); i++) ! called[i] = toupper(host[i]); ! called[strlen(host)] = 0; /* Make it a string */ ! for (i = 0; i < strlen(con->myname); i++) ! calling[i] = toupper(con->myname[i]); ! calling[strlen(con->myname)] = 0; /* Make it a string */ ! if (strcmp(con->address, "") == 0) ! address = con->desthost; ! else ! address = con->address; ! con->Trans_Connect = RFCNB_Call(called, ! calling, ! address, /* Protocol specific */ ! con->port); ! /* Did we get one? */ ! if (con->Trans_Connect == NULL) { ! if (Con_Handle == NULL) { ! free(con); ! Con_Handle = NULL; ! } ! SMBlib_errno = -SMBlibE_CallFailed; ! return NULL; ! } ! /* Now, negotiate the protocol */ ! if (SMB_Negotiate(con, SMB_Prots_Restrict) < 0) { ! /* Hmmm what should we do here ... We have a connection, but could not ! * negotiate ... */ ! return NULL; ! } ! /* Now connect to the service ... */ ! if ((*tree = SMB_TreeConnect(con, NULL, service, password, "A:")) == NULL) { ! return NULL; ! } ! return (con); } /* Logon to the server. That is, do a session setup if we can. We do not do */ /* Unicode yet! */ ! int ! SMB_Logon_Server(SMB_Handle_Type Con_Handle, char *UserName, ! char *PassWord) ! { ! struct RFCNB_Pkt *pkt; ! int param_len, pkt_len, pass_len; ! char *p, pword[128]; ! ! /* First we need a packet etc ... but we need to know what protocol has */ ! /* been negotiated to figure out if we can do it and what SMB format to */ ! /* use ... */ ! if (Con_Handle->protocol < SMB_P_LanMan1) { ! SMBlib_errno = SMBlibE_ProtLow; ! return (SMBlibE_BAD); ! } ! strcpy(pword, PassWord); #ifdef PAM_SMB_ENC_PASS ! if (Con_Handle->encrypt_passwords) { ! pass_len = 24; ! SMBencrypt((uchar *) PassWord, (uchar *) Con_Handle->Encrypt_Key, (uchar *) pword); ! } else #endif ! pass_len = strlen(pword); ! /* Now build the correct structure */ ! if (Con_Handle->protocol < SMB_P_NT1) { ! param_len = strlen(UserName) + 1 + pass_len + 1 + ! strlen(Con_Handle->PDomain) + 1 + ! strlen(Con_Handle->OSName) + 1; ! pkt_len = SMB_ssetpLM_len + param_len; ! pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len); ! if (pkt == NULL) { ! SMBlib_errno = SMBlibE_NoSpace; ! return (SMBlibE_BAD); /* Should handle the error */ ! } ! bzero(SMB_Hdr(pkt), SMB_ssetpLM_len); ! SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */ ! *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBsesssetupX; ! SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle->pid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle->mid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle->uid); ! *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 10; ! *(SMB_Hdr(pkt) + SMB_hdr_axc_offset) = 0xFF; /* No extra command */ ! SSVAL(SMB_Hdr(pkt), SMB_hdr_axo_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_mbs_offset, SMBLIB_MAX_XMIT); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_mmc_offset, 2); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_vcn_offset, Con_Handle->pid); ! SIVAL(SMB_Hdr(pkt), SMB_ssetpLM_snk_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_pwl_offset, pass_len + 1); ! SIVAL(SMB_Hdr(pkt), SMB_ssetpLM_res_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpLM_bcc_offset, param_len); ! /* Now copy the param strings in with the right stuff */ ! p = (char *) (SMB_Hdr(pkt) + SMB_ssetpLM_buf_offset); ! /* Copy in password, then the rest. Password has a null at end */ ! memcpy(p, pword, pass_len); ! p = p + pass_len + 1; ! strcpy(p, UserName); ! p = p + strlen(UserName); ! *p = 0; ! p = p + 1; ! strcpy(p, Con_Handle->PDomain); ! p = p + strlen(Con_Handle->PDomain); ! *p = 0; ! p = p + 1; ! strcpy(p, Con_Handle->OSName); ! p = p + strlen(Con_Handle->OSName); ! *p = 0; ! } else { ! /* We don't admit to UNICODE support ... */ ! param_len = strlen(UserName) + 1 + pass_len + ! strlen(Con_Handle->PDomain) + 1 + ! strlen(Con_Handle->OSName) + 1 + ! strlen(Con_Handle->LMType) + 1; ! pkt_len = SMB_ssetpNTLM_len + param_len; ! pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len); ! if (pkt == NULL) { ! SMBlib_errno = SMBlibE_NoSpace; ! return (-1); /* Should handle the error */ ! } ! bzero(SMB_Hdr(pkt), SMB_ssetpNTLM_len); ! SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */ ! *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBsesssetupX; ! SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle->pid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle->mid); ! SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle->uid); ! *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 13; ! *(SMB_Hdr(pkt) + SMB_hdr_axc_offset) = 0xFF; /* No extra command */ ! SSVAL(SMB_Hdr(pkt), SMB_hdr_axo_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_mbs_offset, SMBLIB_MAX_XMIT); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_mmc_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_vcn_offset, 0); ! SIVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_snk_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cipl_offset, pass_len); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cspl_offset, 0); ! SIVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_res_offset, 0); ! SIVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cap_offset, 0); ! SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_bcc_offset, param_len); ! /* Now copy the param strings in with the right stuff */ ! p = (char *) (SMB_Hdr(pkt) + SMB_ssetpNTLM_buf_offset); ! /* Copy in password, then the rest. Password has no null at end */ ! memcpy(p, pword, pass_len); ! p = p + pass_len; ! strcpy(p, UserName); ! p = p + strlen(UserName); ! *p = 0; ! p = p + 1; ! strcpy(p, Con_Handle->PDomain); ! p = p + strlen(Con_Handle->PDomain); ! *p = 0; ! p = p + 1; ! strcpy(p, Con_Handle->OSName); ! p = p + strlen(Con_Handle->OSName); ! *p = 0; ! p = p + 1; ! strcpy(p, Con_Handle->LMType); ! p = p + strlen(Con_Handle->LMType); ! *p = 0; ! } ! /* Now send it and get a response */ ! if (RFCNB_Send(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG ! fprintf(stderr, "Error sending SessSetupX request\n"); #endif ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_SendFailed; ! return (SMBlibE_BAD); ! } ! /* Now get the response ... */ ! if (RFCNB_Recv(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG ! fprintf(stderr, "Error receiving response to SessSetupAndX\n"); #endif ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_RecvFailed; ! return (SMBlibE_BAD); ! } ! /* Check out the response type ... */ ! if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ #ifdef DEBUG ! fprintf(stderr, "SMB_SessSetupAndX failed with errorclass = %i, Error Code = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset), SVAL(SMB_Hdr(pkt), SMB_hdr_err_offset)); #endif ! SMBlib_SMB_Error = IVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset); ! RFCNB_Free_Pkt(pkt); ! SMBlib_errno = SMBlibE_Remote; ! return (SMBlibE_BAD); + } #ifdef DEBUG ! fprintf(stderr, "SessSetupAndX response. Action = %i\n", ! SVAL(SMB_Hdr(pkt), SMB_ssetpr_act_offset)); #endif ! /* Now pick up the UID for future reference ... */ ! Con_Handle->uid = SVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset); ! RFCNB_Free_Pkt(pkt); ! return (0); } /* Disconnect from the server, and disconnect all tree connects */ ! int ! SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle) { ! /* We just disconnect the connection for now ... */ ! RFCNB_Hangup(Con_Handle->Trans_Connect); ! if (!KeepHandle) ! free(Con_Handle); ! return (0); } diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/smblib.h squid-2.4.STABLE7/auth_modules/MSNT/smblib.h *** squid-2.4.STABLE6/auth_modules/MSNT/smblib.h Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/smblib.h Wed Jun 26 13:24:45 2002 *************** *** 1,27 **** /* UNIX SMBlib NetBIOS implementation ! ! Version 1.0 ! SMBlib Defines ! ! Copyright (C) Richard Sharpe 1996 ! ! */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #include "std-defines.h" #include "smblib-common.h" --- 1,27 ---- /* UNIX SMBlib NetBIOS implementation ! * ! * Version 1.0 ! * SMBlib Defines ! * ! * Copyright (C) Richard Sharpe 1996 ! * ! */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #include "std-defines.h" #include "smblib-common.h" *************** *** 30,36 **** /* Create a handle to allow us to set/override some parameters ... */ ! SMB_Handle_Type SMB_Create_Con_Handle(); /* Connect to a server, but do not do a tree con etc ... */ --- 30,36 ---- /* Create a handle to allow us to set/override some parameters ... */ ! SMB_Handle_Type SMB_Create_Con_Handle(void); /* Connect to a server, but do not do a tree con etc ... */ *************** *** 40,58 **** /* The handle and populate it with defaults */ SMB_Handle_Type SMB_Connect(SMB_Handle_Type Con_Handle, ! SMB_Tree_Handle *tree, ! char *service, ! char *username, ! char *password); /* Negotiate a protocol */ ! int SMB_Negotiate(void *Con_Handle, char *Prots[]); /* Connect to a tree ... */ ! void *SMB_TreeConnect(void *con_handle, void *tree_handle, ! char *path, char *password, char *dev); /* Disconnect a tree ... */ --- 40,58 ---- /* The handle and populate it with defaults */ SMB_Handle_Type SMB_Connect(SMB_Handle_Type Con_Handle, ! SMB_Tree_Handle * tree, ! char *service, ! char *username, ! char *password); /* Negotiate a protocol */ ! int SMB_Negotiate(SMB_Handle_Type Con_Handle, const char *Prots[]); /* Connect to a tree ... */ ! SMB_Tree_Handle SMB_TreeConnect(SMB_Handle_Type con_handle, SMB_Tree_Handle tree_handle, ! char *path, char *password, const char *dev); /* Disconnect a tree ... */ *************** *** 61,70 **** /* Open a file */ void *SMB_Open(void *tree_handle, ! void *file_handle, ! char *file_name, ! unsigned short mode, ! unsigned short search); /* Close a file */ --- 61,70 ---- /* Open a file */ void *SMB_Open(void *tree_handle, ! void *file_handle, ! char *file_name, ! unsigned short mode, ! unsigned short search); /* Close a file */ *************** *** 76,84 **** int SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle); void *SMB_Create(void *Tree_Handle, ! void *File_Handle, ! char *file_name, ! short search); int SMB_Delete(void *tree, char *file_name, short search); --- 76,84 ---- int SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle); void *SMB_Create(void *Tree_Handle, ! void *File_Handle, ! char *file_name, ! short search); int SMB_Delete(void *tree, char *file_name, short search); *************** *** 88,98 **** int SMB_Check_Dir(void *tree, char *dir_name); ! int SMB_Get_Last_Error(); ! int SMB_Get_Last_SMB_Err(); ! int SMB_Get_Error_Msg(int msg, char *msgbuf, int len); void *SMB_Logon_And_TCon(void *con, void *tree, char *user, char *pass, ! char *service, char *st); --- 88,105 ---- int SMB_Check_Dir(void *tree, char *dir_name); ! int SMB_Get_Last_Error(void); ! int SMB_Get_Last_SMB_Err(void); ! void SMB_Get_Error_Msg(int msg, char *msgbuf, int len); void *SMB_Logon_And_TCon(void *con, void *tree, char *user, char *pass, ! char *service, char *st); ! ! void SMB_Get_My_Name(char *, int); ! ! int SMB_Init(void); ! ! extern int SMB_Logon_Server(SMB_Handle_Type, char *, char *); ! diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/std-defines.h squid-2.4.STABLE7/auth_modules/MSNT/std-defines.h *** squid-2.4.STABLE6/auth_modules/MSNT/std-defines.h Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/std-defines.h Wed Jun 26 13:24:45 2002 *************** *** 1,27 **** /* RFCNB Standard includes ... */ /* ! ! SMBlib Standard Includes ! ! Copyright (C) 1996, Richard Sharpe ! */ /* One day we will conditionalize these on OS types ... */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #ifndef _STD_DEFINES_H_ #define _STD_DEFINES_H_ --- 1,27 ---- /* RFCNB Standard includes ... */ /* ! * ! * SMBlib Standard Includes ! * ! * Copyright (C) 1996, Richard Sharpe ! */ /* One day we will conditionalize these on OS types ... */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #ifndef _STD_DEFINES_H_ #define _STD_DEFINES_H_ *************** *** 42,45 **** #define TRUE 1 #define FALSE 0 ! #endif _STD_DEFINES_H_ --- 42,45 ---- #define TRUE 1 #define FALSE 0 ! #endif /* _STD_DEFINES_H_ */ diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/std-includes.h squid-2.4.STABLE7/auth_modules/MSNT/std-includes.h *** squid-2.4.STABLE6/auth_modules/MSNT/std-includes.h Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/std-includes.h Wed Jun 26 13:24:46 2002 *************** *** 1,27 **** /* RFCNB Standard includes ... */ /* ! ! RFCNB Standard Includes ! ! Copyright (C) 1996, Richard Sharpe ! */ /* One day we will conditionalize these on OS types ... */ /* ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #define BOOL int typedef short int16; --- 1,27 ---- /* RFCNB Standard includes ... */ /* ! * ! * RFCNB Standard Includes ! * ! * Copyright (C) 1996, Richard Sharpe ! */ /* One day we will conditionalize these on OS types ... */ /* ! * 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! */ #define BOOL int typedef short int16; diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/usersfile.c squid-2.4.STABLE7/auth_modules/MSNT/usersfile.c *** squid-2.4.STABLE6/auth_modules/MSNT/usersfile.c Wed Dec 31 17:00:00 1969 --- squid-2.4.STABLE7/auth_modules/MSNT/usersfile.c Wed Jun 26 13:24:46 2002 *************** *** 0 **** --- 1,193 ---- + + /* + * usersfile.c + * (C) 2000 Antonino Iannella, Stellar-X Pty Ltd + * Released under GPL, see COPYING-2.0 for details. + * + * These routines are to allow users attempting to use the proxy which + * have been explicitly allowed by the system administrator. + * The code originated from denyusers.c. + */ + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + + #include "usersfile.h" + + #define NAMELEN 50 /* Maximum username length */ + + static int + name_cmp(const void *a, const void *b) + { + const char *A = a; + const char *B = b; + return strcasecmp(A, B); + } + + static void + free_names(usersfile * uf) + { + int i; + for (i = 0; i < uf->Inuse; i++) { + if (uf->names[i]) + free(uf->names[i]); + uf->names[i] = NULL; + } + uf->Inuse = 0; + } + + /* + * Reads a file of usernames and stuffs them into an array + * of strings. + * Returns 0 if the user list was successfully loaded, + * and 1 in case of error. + */ + + int + Read_usersfile(const char *path, usersfile * uf) + { + FILE *fp; + struct stat FileBuf; + char buf[1024]; + + free_names(uf); + + if (NULL == path) { + path = uf->path; + } else { + if (uf->path) + free(uf->path); + uf->path = strdup(path); + } + + /* Open the users file. Report any errors. */ + fp = fopen(path, "r"); + if (NULL == fp) { + uf->LMT = 0; + if (errno == ENOENT) + return 0; + syslog(LOG_ERR, "%s: %s", path, strerror(errno)); + return 1; + } + /* Stat the file. If it does not exist, save the size as zero. + * Clear the allowed user string. Return. */ + if (fstat(fileno(fp), &FileBuf) < 0) { + syslog(LOG_ERR, "%s: %s", path, strerror(errno)); + return 1; + } + /* If it exists, save the modification time and size */ + uf->LMT = FileBuf.st_mtime; + + /* Handle the special case of a zero length file */ + if (FileBuf.st_size == 0) + return 0; + + /* + * Read the file into memory + * XXX assumes one username per input line + */ + while (fgets(buf, 1024, fp) != NULL) { + /* ensure no names longer than our limit */ + buf[NAMELEN] = '\0'; + /* skip bad input lines */ + if (NULL == strtok(buf, "\r\n")) + continue; + /* grow the list if necessary */ + if (0 == uf->Alloc) { + uf->Alloc = 256; + uf->names = calloc(uf->Alloc, sizeof(*uf->names)); + } else if (uf->Inuse == uf->Alloc) { + uf->Alloc = uf->Alloc << 1; + uf->names = realloc(uf->names, uf->Alloc); + /* zero out the newly allocated memory */ + memset(uf->names[uf->Alloc >> 1], + '\0', + (uf->Alloc >> 1) * sizeof(*uf->names)); + } + uf->names[uf->Inuse] = strdup(buf); + uf->Inuse++; + } + fclose(fp); + fp = NULL; + + /* sort the names for searching */ + qsort(uf->names, uf->Inuse, sizeof(*uf->names), name_cmp); + + return 0; + } + + /* + * Check to see if the username provided by Squid appears in the + * user list. Returns 0 if the user was not found, and 1 if they were. + */ + + int + Check_userlist(usersfile * uf, char *User) + { + void *p; + + /* Empty users are always in the list */ + if (User[0] == '\0') + return 1; + + /* If allowed user list is empty, allow all users. + * If no users are supposed to be using the proxy, stop squid instead. */ + if (0 == uf->Inuse) + return 1; + + /* Check if username string is found in the allowed user list. + * If so, allow. If not, deny. Reconstruct the username + * to have whitespace, to avoid finding wrong string subsets. */ + + p = bsearch(User, + uf->names, + uf->Inuse, + sizeof(*uf->names), + name_cmp); + if (NULL == p) { + syslog(LOG_DEBUG, "User %s not found", User); + return 0; + } + syslog(LOG_DEBUG, "User %s found", User); + return 1; + } + + /* + * Checks if there has been a change in a users file. + * If the modification time has changed, then reload the user list. + */ + void + Check_forfilechange(usersfile * uf) + { + struct stat ChkBuf; /* Stat data buffer */ + + /* Stat the allowed users file. If it cannot be accessed, return. */ + + if (stat(uf->path, &ChkBuf) < 0) { + if (errno == ENOENT) { + uf->LMT = 0; + free_names(uf); + } else { /* Report error when accessing file */ + syslog(LOG_ERR, "%s: %s", uf->path, strerror(errno)); + } + return; + } + /* return if no change */ + if (ChkBuf.st_mtime == uf->LMT) + return; + + /* + * The file changed, so re-read it. + */ + syslog(LOG_INFO, "Check_forchange: Reloading user list."); + Read_usersfile(NULL, uf); + } diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/usersfile.h squid-2.4.STABLE7/auth_modules/MSNT/usersfile.h *** squid-2.4.STABLE6/auth_modules/MSNT/usersfile.h Wed Dec 31 17:00:00 1969 --- squid-2.4.STABLE7/auth_modules/MSNT/usersfile.h Wed Jun 26 13:24:46 2002 *************** *** 0 **** --- 1,15 ---- + + + typedef struct { + char *path; + char **names; + int Alloc; + int Inuse; + time_t LMT; + } usersfile; + + + + int Read_usersfile(const char *path, usersfile * uf); + int Check_userlist(usersfile * uf, char *User); + void Check_forfilechange(usersfile * uf); diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/valid.c squid-2.4.STABLE7/auth_modules/MSNT/valid.c *** squid-2.4.STABLE6/auth_modules/MSNT/valid.c Wed Jul 12 11:42:17 2000 --- squid-2.4.STABLE7/auth_modules/MSNT/valid.c Wed Jun 26 13:24:46 2002 *************** *** 5,44 **** #include "smblib.h" #include "valid.h" ! extern int SMB_Init(void); ! extern int SMB_Logon_Server(SMB_Handle_Type, char *, char *); ! ! ! int Valid_User(char *USERNAME,char *PASSWORD,char *SERVER,char *BACKUP, char *DOMAIN) { ! char *SMB_Prots[] = {"PC NETWORK PROGRAM 1.0", ! "MICROSOFT NETWORKS 1.03", ! "MICROSOFT NETWORKS 3.0", ! "LANMAN1.0", ! "LM1.2X002", ! "Samba", ! "NT LM 0.12", ! "NT LANMAN 1.0", ! NULL}; ! void *con; ! SMB_Init(); ! con = SMB_Connect_Server(NULL, SERVER, DOMAIN); ! if (con == NULL) { /* Error ... */ ! con = SMB_Connect_Server(NULL, BACKUP, DOMAIN); ! if (con == NULL) { ! return(NTV_SERVER_ERROR); ! } ! } ! if (SMB_Negotiate(con, SMB_Prots) < 0) { /* An error */ ! SMB_Discon(con,0); ! return(NTV_PROTOCOL_ERROR); ! } ! if (SMB_Logon_Server(con, USERNAME, PASSWORD) < 0) { ! SMB_Discon(con,0); ! return(NTV_LOGON_ERROR); ! } ! ! SMB_Discon(con,0); ! return(NTV_NO_ERROR); } --- 5,41 ---- #include "smblib.h" #include "valid.h" ! int ! Valid_User(char *USERNAME, char *PASSWORD, char *SERVER, char *BACKUP, char *DOMAIN) { ! const char *SMB_Prots[] = ! {"PC NETWORK PROGRAM 1.0", ! "MICROSOFT NETWORKS 1.03", ! "MICROSOFT NETWORKS 3.0", ! "LANMAN1.0", ! "LM1.2X002", ! "Samba", ! "NT LM 0.12", ! "NT LANMAN 1.0", ! NULL}; ! void *con; ! SMB_Init(); ! con = SMB_Connect_Server(NULL, SERVER, DOMAIN); ! if (con == NULL) { /* Error ... */ ! con = SMB_Connect_Server(NULL, BACKUP, DOMAIN); ! if (con == NULL) { ! return (NTV_SERVER_ERROR); ! } ! } ! if (SMB_Negotiate(con, SMB_Prots) < 0) { /* An error */ ! SMB_Discon(con, 0); ! return (NTV_PROTOCOL_ERROR); ! } ! if (SMB_Logon_Server(con, USERNAME, PASSWORD) < 0) { ! SMB_Discon(con, 0); ! return (NTV_LOGON_ERROR); ! } ! SMB_Discon(con, 0); ! return (NTV_NO_ERROR); } diff -Ncr squid-2.4.STABLE6/auth_modules/MSNT/valid.h squid-2.4.STABLE7/auth_modules/MSNT/valid.h *** squid-2.4.STABLE6/auth_modules/MSNT/valid.h Wed Oct 20 12:50:54 1999 --- squid-2.4.STABLE7/auth_modules/MSNT/valid.h Wed Jun 26 13:24:46 2002 *************** *** 7,12 **** #define NTV_PROTOCOL_ERROR 2 #define NTV_LOGON_ERROR 3 ! int Valid_User(char *USERNAME,char *PASSWORD,char *SERVER, char *BACKUP, char *DOMAIN); #endif --- 7,12 ---- #define NTV_PROTOCOL_ERROR 2 #define NTV_LOGON_ERROR 3 ! int Valid_User(char *USERNAME, char *PASSWORD, char *SERVER, char *BACKUP, char *DOMAIN); #endif diff -Ncr squid-2.4.STABLE6/cfgaux/config.guess squid-2.4.STABLE7/cfgaux/config.guess *** squid-2.4.STABLE6/cfgaux/config.guess Sun Oct 3 23:04:08 1999 --- squid-2.4.STABLE7/cfgaux/config.guess Thu May 23 11:58:46 2002 *************** *** 1,7 **** #! /bin/sh # Attempt to guess a canonical system name. ! # Copyright (C) 1992, 93, 94, 95, 1996 Free Software Foundation, Inc. ! # # This file 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 --- 1,10 ---- #! /bin/sh # Attempt to guess a canonical system name. ! # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, ! # 2000, 2001, 2002 Free Software Foundation, Inc. ! ! timestamp='2002-03-04' ! # This file 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 *************** *** 21,79 **** # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. ! # Written by Per Bothner . ! # The master version of this file is at the FSF in /home/gd/gnu/lib. # # This script attempts to guess a canonical system name similar to # config.sub. If it succeeds, it prints the system name on stdout, and # exits with 0. Otherwise, it exits with 1. # # The plan is that this can be called by configure scripts if you ! # don't specify an explicit system type (host/target name). ! # ! # Only a few systems have been added to this list; please add others ! # (but try to keep the structure clean). ! # # This is needed to find uname on a Pyramid OSx when run in the BSD universe. ! # (ghazi@noc.rutgers.edu 8/24/94.) if (test -f /.attbin/uname) >/dev/null 2>&1 ; then PATH=$PATH:/.attbin ; export PATH fi UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown ! UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown - trap 'rm -f dummy.c dummy.o dummy; exit 1' 1 2 15 - # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in alpha:OSF1:*:*) # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. ! echo alpha-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//'` exit 0 ;; 21064:Windows_NT:50:3) echo alpha-dec-winnt3.5 exit 0 ;; Amiga*:UNIX_System_V:4.0:*) ! echo m68k-cbm-sysv4 exit 0;; ! amiga:NetBSD:*:*) ! echo m68k-cbm-netbsd${UNAME_RELEASE} ! exit 0 ;; ! amiga:OpenBSD:*:*) ! echo m68k-cbm-openbsd${UNAME_RELEASE} ! exit 0 ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} exit 0;; ! Pyramid*:OSx*:*:*|MIS*:OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "`(/bin/universe) 2>/dev/null`" = att ; then echo pyramid-pyramid-sysv3 --- 24,308 ---- # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. ! # Originally written by Per Bothner . ! # Please send patches to . Submit a context ! # diff and a properly formatted ChangeLog entry. # # This script attempts to guess a canonical system name similar to # config.sub. If it succeeds, it prints the system name on stdout, and # exits with 0. Otherwise, it exits with 1. # # The plan is that this can be called by configure scripts if you ! # don't specify an explicit build system type. ! ! me=`echo "$0" | sed -e 's,.*/,,'` ! ! usage="\ ! Usage: $0 [OPTION] ! ! Output the configuration name of the system \`$me' is run on. ! ! Operation modes: ! -h, --help print this help, then exit ! -t, --time-stamp print date of last modification, then exit ! -v, --version print version number, then exit ! ! Report bugs and patches to ." ! ! version="\ ! GNU config.guess ($timestamp) ! ! Originally written by Per Bothner. ! Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 ! Free Software Foundation, Inc. ! ! This is free software; see the source for copying conditions. There is NO ! warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." ! ! help=" ! Try \`$me --help' for more information." ! ! # Parse command line ! while test $# -gt 0 ; do ! case $1 in ! --time-stamp | --time* | -t ) ! echo "$timestamp" ; exit 0 ;; ! --version | -v ) ! echo "$version" ; exit 0 ;; ! --help | --h* | -h ) ! echo "$usage"; exit 0 ;; ! -- ) # Stop option processing ! shift; break ;; ! - ) # Use stdin as input. ! break ;; ! -* ) ! echo "$me: invalid option $1$help" >&2 ! exit 1 ;; ! * ) ! break ;; ! esac ! done ! ! if test $# != 0; then ! echo "$me: too many arguments$help" >&2 ! exit 1 ! fi ! ! ! dummy=dummy-$$ ! trap 'rm -f $dummy.c $dummy.o $dummy.rel $dummy; exit 1' 1 2 15 ! ! # CC_FOR_BUILD -- compiler used by this script. ! # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still ! # use `HOST_CC' if defined, but it is deprecated. ! ! set_cc_for_build='case $CC_FOR_BUILD,$HOST_CC,$CC in ! ,,) echo "int dummy(){}" > $dummy.c ; ! for c in cc gcc c89 ; do ! ($c $dummy.c -c -o $dummy.o) >/dev/null 2>&1 ; ! if test $? = 0 ; then ! CC_FOR_BUILD="$c"; break ; ! fi ; ! done ; ! rm -f $dummy.c $dummy.o $dummy.rel ; ! if test x"$CC_FOR_BUILD" = x ; then ! CC_FOR_BUILD=no_compiler_found ; ! fi ! ;; ! ,,*) CC_FOR_BUILD=$CC ;; ! ,*,*) CC_FOR_BUILD=$HOST_CC ;; ! esac' # This is needed to find uname on a Pyramid OSx when run in the BSD universe. ! # (ghazi@noc.rutgers.edu 1994-08-24) if (test -f /.attbin/uname) >/dev/null 2>&1 ; then PATH=$PATH:/.attbin ; export PATH fi UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown ! UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + sysctl="sysctl -n hw.machine_arch" + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + case "${UNAME_MACHINE_ARCH}" in + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE_ARCH}" in + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit 0 ;; + amiga:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + arc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + hp300:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mac68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + macppc:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme88k:OpenBSD:*:*) + echo m88k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvmeppc:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + pmax:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sgi:OpenBSD:*:*) + echo mipseb-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sun3:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + wgrisc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + *:OpenBSD:*:*) + echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; alpha:OSF1:*:*) + if test $UNAME_RELEASE = "V4.0"; then + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + fi # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. ! cat <$dummy.s ! .data ! \$Lformat: ! .byte 37,100,45,37,120,10,0 # "%d-%x\n" ! ! .text ! .globl main ! .align 4 ! .ent main ! main: ! .frame \$30,16,\$26,0 ! ldgp \$29,0(\$27) ! .prologue 1 ! .long 0x47e03d80 # implver \$0 ! lda \$2,-1 ! .long 0x47e20c21 # amask \$2,\$1 ! lda \$16,\$Lformat ! mov \$0,\$17 ! not \$1,\$18 ! jsr \$26,printf ! ldgp \$29,0(\$26) ! mov 0,\$16 ! jsr \$26,exit ! .end main ! EOF ! eval $set_cc_for_build ! $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null ! if test "$?" = 0 ; then ! case `./$dummy` in ! 0-0) ! UNAME_MACHINE="alpha" ! ;; ! 1-0) ! UNAME_MACHINE="alphaev5" ! ;; ! 1-1) ! UNAME_MACHINE="alphaev56" ! ;; ! 1-101) ! UNAME_MACHINE="alphapca56" ! ;; ! 2-303) ! UNAME_MACHINE="alphaev6" ! ;; ! 2-307) ! UNAME_MACHINE="alphaev67" ! ;; ! 2-1307) ! UNAME_MACHINE="alphaev68" ! ;; ! esac ! fi ! rm -f $dummy.s $dummy ! echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` ! exit 0 ;; ! Alpha\ *:Windows_NT*:*) ! # How do we know it's Interix rather than the generic POSIX subsystem? ! # Should we change UNAME_MACHINE based on the output of uname instead ! # of the specific Alpha model? ! echo alpha-pc-interix exit 0 ;; 21064:Windows_NT:50:3) echo alpha-dec-winnt3.5 exit 0 ;; Amiga*:UNIX_System_V:4.0:*) ! echo m68k-unknown-sysv4 exit 0;; ! *:[Aa]miga[Oo][Ss]:*:*) ! echo ${UNAME_MACHINE}-unknown-amigaos ! exit 0 ;; ! *:[Mm]orph[Oo][Ss]:*:*) ! echo ${UNAME_MACHINE}-unknown-morphos ! exit 0 ;; ! *:OS/390:*:*) ! echo i370-ibm-openedition ! exit 0 ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} exit 0;; ! SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) ! echo hppa1.1-hitachi-hiuxmpp ! exit 0;; ! Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "`(/bin/universe) 2>/dev/null`" = att ; then echo pyramid-pyramid-sysv3 *************** *** 81,89 **** echo pyramid-pyramid-bsd fi exit 0 ;; ! NILE:*:*:dcosx) echo pyramid-pyramid-svr4 exit 0 ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit 0 ;; --- 310,321 ---- echo pyramid-pyramid-bsd fi exit 0 ;; ! NILE*:*:*:dcosx) echo pyramid-pyramid-svr4 exit 0 ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit 0 ;; *************** *** 108,134 **** sun3*:SunOS:*:*) echo m68k-sun-sunos${UNAME_RELEASE} exit 0 ;; aushp:SunOS:*:*) echo sparc-auspex-sunos${UNAME_RELEASE} exit 0 ;; ! atari*:NetBSD:*:*) ! echo m68k-atari-netbsd${UNAME_RELEASE} ! exit 0 ;; ! atari*:OpenBSD:*:*) ! echo m68k-atari-openbsd${UNAME_RELEASE} ! exit 0 ;; ! sun3*:NetBSD:*:*) ! echo m68k-sun-netbsd${UNAME_RELEASE} ! exit 0 ;; ! sun3*:OpenBSD:*:*) ! echo m68k-sun-openbsd${UNAME_RELEASE} exit 0 ;; ! mac68k:NetBSD:*:*) ! echo m68k-apple-netbsd${UNAME_RELEASE} ! exit 0 ;; ! mac68k:OpenBSD:*:*) ! echo m68k-apple-openbsd${UNAME_RELEASE} exit 0 ;; powerpc:machten:*:*) echo powerpc-apple-machten${UNAME_RELEASE} exit 0 ;; --- 340,386 ---- sun3*:SunOS:*:*) echo m68k-sun-sunos${UNAME_RELEASE} exit 0 ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit 0 ;; aushp:SunOS:*:*) echo sparc-auspex-sunos${UNAME_RELEASE} exit 0 ;; ! # The situation for MiNT is a little confusing. The machine name ! # can be virtually everything (everything which is not ! # "atarist" or "atariste" at least should have a processor ! # > m68000). The system name ranges from "MiNT" over "FreeMiNT" ! # to the lowercase version "mint" (or "freemint"). Finally ! # the system name "TOS" denotes a system which is actually not ! # MiNT. But MiNT is downward compatible to TOS, so this should ! # be no problem. ! atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) ! echo m68k-atari-mint${UNAME_RELEASE} exit 0 ;; ! atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) ! echo m68k-atari-mint${UNAME_RELEASE} ! exit 0 ;; ! *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) ! echo m68k-atari-mint${UNAME_RELEASE} exit 0 ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit 0 ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit 0 ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit 0 ;; powerpc:machten:*:*) echo powerpc-apple-machten${UNAME_RELEASE} exit 0 ;; *************** *** 141,149 **** VAX*:ULTRIX*:*:*) echo vax-dec-ultrix${UNAME_RELEASE} exit 0 ;; mips:*:*:UMIPS | mips:*:*:RISCos) ! sed 's/^ //' << EOF >dummy.c ! int main (argc, argv) int argc; char **argv; { #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); --- 393,410 ---- VAX*:ULTRIX*:*:*) echo vax-dec-ultrix${UNAME_RELEASE} exit 0 ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit 0 ;; mips:*:*:UMIPS | mips:*:*:RISCos) ! eval $set_cc_for_build ! sed 's/^ //' << EOF >$dummy.c ! #ifdef __cplusplus ! #include /* for printf() prototype */ ! int main (int argc, char *argv[]) { ! #else ! int main (argc, argv) int argc; char *argv[]; { ! #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); *************** *** 158,169 **** exit (-1); } EOF ! ${CC-cc} dummy.c -o dummy \ ! && ./dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ ! && rm dummy.c dummy && exit 0 ! rm -f dummy.c dummy echo mips-mips-riscos${UNAME_RELEASE} exit 0 ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix exit 0 ;; --- 419,433 ---- exit (-1); } EOF ! $CC_FOR_BUILD $dummy.c -o $dummy \ ! && ./$dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ ! && rm -f $dummy.c $dummy && exit 0 ! rm -f $dummy.c $dummy echo mips-mips-riscos${UNAME_RELEASE} exit 0 ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit 0 ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix exit 0 ;; *************** *** 179,193 **** AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` ! if [ $UNAME_PROCESSOR = mc88100 -o $UNAME_PROCESSOR = mc88110 ] ; then ! if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx \ ! -o ${TARGET_BINARY_INTERFACE}x = x ] ; then echo m88k-dg-dgux${UNAME_RELEASE} ! else echo m88k-dg-dguxbcs${UNAME_RELEASE} fi - else echo i586-dg-dgux${UNAME_RELEASE} - fi exit 0 ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 --- 443,460 ---- AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` ! if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] ! then ! if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ ! [ ${TARGET_BINARY_INTERFACE}x = x ] ! then echo m88k-dg-dgux${UNAME_RELEASE} ! else echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} fi exit 0 ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 *************** *** 208,219 **** ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' ! i?86:AIX:*:*) echo i386-ibm-aix exit 0 ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then ! sed 's/^ //' << EOF >dummy.c #include main() --- 475,495 ---- ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' ! i*86:AIX:*:*) echo i386-ibm-aix exit 0 ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit 0 ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then ! eval $set_cc_for_build ! sed 's/^ //' << EOF >$dummy.c #include main() *************** *** 224,231 **** exit(0); } EOF ! ${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0 ! rm -f dummy.c dummy echo rs6000-ibm-aix3.2.5 elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 --- 500,507 ---- exit(0); } EOF ! $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0 ! rm -f $dummy.c $dummy echo rs6000-ibm-aix3.2.5 elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 *************** *** 233,240 **** echo rs6000-ibm-aix3.2 fi exit 0 ;; ! *:AIX:*:4) ! if /usr/sbin/lsattr -EHl proc0 | grep POWER >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc --- 509,517 ---- echo rs6000-ibm-aix3.2 fi exit 0 ;; ! *:AIX:*:[45]) ! IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` ! if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc *************** *** 242,248 **** if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` else ! IBM_REV=4.${UNAME_RELEASE} fi echo ${IBM_ARCH}-ibm-aix${IBM_REV} exit 0 ;; --- 519,525 ---- if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` else ! IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${IBM_ARCH}-ibm-aix${IBM_REV} exit 0 ;; *************** *** 252,258 **** ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 exit 0 ;; ! ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC NetBSD and echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to exit 0 ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) --- 529,535 ---- ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 exit 0 ;; ! ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to exit 0 ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) *************** *** 267,284 **** hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) echo m68k-hp-bsd4.4 exit 0 ;; ! 9000/[3478]??:HP-UX:*:*) case "${UNAME_MACHINE}" in 9000/31? ) HP_ARCH=m68000 ;; 9000/[34]?? ) HP_ARCH=m68k ;; ! 9000/7?? | 9000/8?[1679] ) HP_ARCH=hppa1.1 ;; ! 9000/8?? ) HP_ARCH=hppa1.0 ;; esac - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` echo ${HP_ARCH}-hp-hpux${HPUX_REV} exit 0 ;; 3050*:HI-UX:*:*) ! sed 's/^ //' << EOF >dummy.c #include int main () --- 544,618 ---- hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) echo m68k-hp-bsd4.4 exit 0 ;; ! 9000/[34678]??:HP-UX:*:*) ! HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` case "${UNAME_MACHINE}" in 9000/31? ) HP_ARCH=m68000 ;; 9000/[34]?? ) HP_ARCH=m68k ;; ! 9000/[678][0-9][0-9]) ! if [ -x /usr/bin/getconf ]; then ! sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` ! sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` ! case "${sc_cpu_version}" in ! 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 ! 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 ! 532) # CPU_PA_RISC2_0 ! case "${sc_kernel_bits}" in ! 32) HP_ARCH="hppa2.0n" ;; ! 64) HP_ARCH="hppa2.0w" ;; ! '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 ! esac ;; ! esac ! fi ! if [ "${HP_ARCH}" = "" ]; then ! eval $set_cc_for_build ! sed 's/^ //' << EOF >$dummy.c ! ! #define _HPUX_SOURCE ! #include ! #include ! ! int main () ! { ! #if defined(_SC_KERNEL_BITS) ! long bits = sysconf(_SC_KERNEL_BITS); ! #endif ! long cpu = sysconf (_SC_CPU_VERSION); ! ! switch (cpu) ! { ! case CPU_PA_RISC1_0: puts ("hppa1.0"); break; ! case CPU_PA_RISC1_1: puts ("hppa1.1"); break; ! case CPU_PA_RISC2_0: ! #if defined(_SC_KERNEL_BITS) ! switch (bits) ! { ! case 64: puts ("hppa2.0w"); break; ! case 32: puts ("hppa2.0n"); break; ! default: puts ("hppa2.0"); break; ! } break; ! #else /* !defined(_SC_KERNEL_BITS) */ ! puts ("hppa2.0"); break; ! #endif ! default: puts ("hppa1.0"); break; ! } ! exit (0); ! } ! EOF ! (CCOPTS= $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null) && HP_ARCH=`./$dummy` ! if test -z "$HP_ARCH"; then HP_ARCH=hppa; fi ! rm -f $dummy.c $dummy ! fi ;; esac echo ${HP_ARCH}-hp-hpux${HPUX_REV} exit 0 ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit 0 ;; 3050*:HI-UX:*:*) ! eval $set_cc_for_build ! sed 's/^ //' << EOF >$dummy.c #include int main () *************** *** 303,310 **** exit (0); } EOF ! ${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0 ! rm -f dummy.c dummy echo unknown-hitachi-hiuxwe2 exit 0 ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) --- 637,644 ---- exit (0); } EOF ! $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0 ! rm -f $dummy.c $dummy echo unknown-hitachi-hiuxwe2 exit 0 ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) *************** *** 313,325 **** 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd exit 0 ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf exit 0 ;; hp8??:OSF1:*:*) echo hppa1.0-hp-osf exit 0 ;; ! i?86:OSF1:*:*) if [ -x /usr/sbin/sysversion ] ; then echo ${UNAME_MACHINE}-unknown-osf1mk else --- 647,662 ---- 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd exit 0 ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit 0 ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf exit 0 ;; hp8??:OSF1:*:*) echo hppa1.0-hp-osf exit 0 ;; ! i*86:OSF1:*:*) if [ -x /usr/sbin/sysversion ] ; then echo ${UNAME_MACHINE}-unknown-osf1mk else *************** *** 347,462 **** C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) echo c4-convex-bsd exit 0 ;; - CRAY*X-MP:*:*:*) - echo xmp-cray-unicos - exit 0 ;; CRAY*Y-MP:*:*:*) ! echo ymp-cray-unicos${UNAME_RELEASE} exit 0 ;; CRAY*[A-Z]90:*:*:*) echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ ! -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ exit 0 ;; CRAY*TS:*:*:*) ! echo t90-cray-unicos${UNAME_RELEASE} exit 0 ;; ! CRAY-2:*:*:*) ! echo cray2-cray-unicos ! exit 0 ;; ! F300:UNIX_System_V:*:*) ! FUJITSU_SYS=`uname -p | tr [A-Z] [a-z] | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` ! echo "f300-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit 0 ;; ! F301:UNIX_System_V:*:*) ! echo f301-fujitsu-uxpv`echo $UNAME_RELEASE | sed 's/ .*//'` ! exit 0 ;; ! hp3[0-9][05]:NetBSD:*:*) ! echo m68k-hp-netbsd${UNAME_RELEASE} exit 0 ;; ! hp3[0-9][05]:OpenBSD:*:*) ! echo m68k-hp-openbsd${UNAME_RELEASE} exit 0 ;; ! i?86:BSD/386:*:* | *:BSD/OS:*:*) ! echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} exit 0 ;; *:FreeBSD:*:*) echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` exit 0 ;; ! *:NetBSD:*:*) ! echo ${UNAME_MACHINE}-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` exit 0 ;; ! *:OpenBSD:*:*) ! echo ${UNAME_MACHINE}-unknown-openbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` exit 0 ;; ! i*:CYGWIN*:*) ! echo i386-pc-cygwin32 exit 0 ;; p*:CYGWIN*:*) ! echo powerpcle-unknown-cygwin32 exit 0 ;; prep*:SunOS:5.*:*) echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit 0 ;; *:GNU:*:*) ! echo `echo ${UNAME_MACHINE}|sed -e 's,/.*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` exit 0 ;; ! *:Linux:*:*) # The BFD linker knows what the default object file format is, so ! # first see if it will tell us. ! ld_help_string=`ld --help 2>&1` ! if echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: elf_i.86"; then ! echo "${UNAME_MACHINE}-pc-linux-gnu" ; exit 0 ! elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: i.86linux"; then ! echo "${UNAME_MACHINE}-pc-linux-gnuaout" ; exit 0 ! elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: i.86coff"; then ! echo "${UNAME_MACHINE}-pc-linux-gnucoff" ; exit 0 ! elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: m68kelf"; then ! echo "${UNAME_MACHINE}-unknown-linux-gnu" ; exit 0 ! elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: m68klinux"; then ! echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ! elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: elf32ppc"; then ! echo "powerpc-unknown-linux-gnu" ; exit 0 ! elif test "${UNAME_MACHINE}" = "alpha" ; then ! echo alpha-unknown-linux-gnu ; exit 0 ! elif test "${UNAME_MACHINE}" = "sparc" ; then ! echo sparc-unknown-linux-gnu ; exit 0 ! else ! # Either a pre-BFD a.out linker (linux-gnuoldld) or one that does not give us ! # useful --help. Gcc wants to distinguish between linux-gnuoldld and linux-gnuaout. ! test ! -d /usr/lib/ldscripts/. \ ! && echo "${UNAME_MACHINE}-pc-linux-gnuoldld" && exit 0 ! # Determine whether the default compiler is a.out or elf ! cat >dummy.c </dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0 ! rm -f dummy.c dummy ! fi ;; ! # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. earlier versions ! # are messed up and put the nodename in both sysname and nodename. ! i?86:DYNIX/ptx:4*:*) echo i386-sequent-sysv4 exit 0 ;; ! i?86:*:4.*:* | i?86:SYSTEM_V:4.*:*) if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then ! echo ${UNAME_MACHINE}-univel-sysv${UNAME_RELEASE} else ! echo ${UNAME_MACHINE}-pc-sysv${UNAME_RELEASE} fi exit 0 ;; ! i?86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' $dummy.c ! #undef CPU ! #undef mips ! #undef mipsel ! #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) ! CPU=mipsel ! #else ! #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) ! CPU=mips ! #else ! CPU= ! #endif ! #endif ! EOF ! eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` ! rm -f $dummy.c ! test x"${CPU}" != x && echo "${CPU}-pc-linux-gnu" && exit 0 ! ;; ! ppc:Linux:*:*) ! echo powerpc-unknown-linux-gnu ! exit 0 ;; ! ppc64:Linux:*:*) ! echo powerpc64-unknown-linux-gnu ! exit 0 ;; ! alpha:Linux:*:*) ! case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in ! EV5) UNAME_MACHINE=alphaev5 ;; ! EV56) UNAME_MACHINE=alphaev56 ;; ! PCA56) UNAME_MACHINE=alphapca56 ;; ! PCA57) UNAME_MACHINE=alphapca56 ;; ! EV6) UNAME_MACHINE=alphaev6 ;; ! EV67) UNAME_MACHINE=alphaev67 ;; ! EV68*) UNAME_MACHINE=alphaev68 ;; ! esac ! objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null ! if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi ! echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} ! exit 0 ;; ! parisc:Linux:*:* | hppa:Linux:*:*) ! # Look for CPU level ! case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in ! PA7*) echo hppa1.1-unknown-linux-gnu ;; ! PA8*) echo hppa2.0-unknown-linux-gnu ;; ! *) echo hppa-unknown-linux-gnu ;; ! esac exit 0 ;; ! parisc64:Linux:*:* | hppa64:Linux:*:*) ! echo hppa64-unknown-linux-gnu ! exit 0 ;; ! s390:Linux:*:* | s390x:Linux:*:*) ! echo ${UNAME_MACHINE}-ibm-linux ! exit 0 ;; ! sh*:Linux:*:*) ! echo ${UNAME_MACHINE}-unknown-linux-gnu ! exit 0 ;; ! sparc:Linux:*:* | sparc64:Linux:*:*) ! echo ${UNAME_MACHINE}-unknown-linux-gnu ! exit 0 ;; ! x86_64:Linux:*:*) ! echo x86_64-unknown-linux-gnu ! exit 0 ;; ! i*86:Linux:*:*) # The BFD linker knows what the default object file format is, so ! # first see if it will tell us. cd to the root directory to prevent ! # problems with other programs or directories called `ld' in the path. ! # Set LC_ALL=C to ensure ld outputs messages in English. ! ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ ! | sed -ne '/supported targets:/!d ! s/[ ][ ]*/ /g ! s/.*supported targets: *// ! s/ .*// ! p'` ! case "$ld_supported_targets" in ! elf32-i386) ! TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" ! ;; ! a.out-i386-linux) ! echo "${UNAME_MACHINE}-pc-linux-gnuaout" ! exit 0 ;; ! coff-i386) ! echo "${UNAME_MACHINE}-pc-linux-gnucoff" ! exit 0 ;; ! "") ! # Either a pre-BFD a.out linker (linux-gnuoldld) or ! # one that does not give us useful --help. ! echo "${UNAME_MACHINE}-pc-linux-gnuoldld" ! exit 0 ;; ! esac ! # Determine whether the default compiler is a.out or elf ! eval $set_cc_for_build ! sed 's/^ //' << EOF >$dummy.c ! #include ! #ifdef __ELF__ ! # ifdef __GLIBC__ ! # if __GLIBC__ >= 2 ! LIBC=gnu ! # else ! LIBC=gnulibc1 ! # endif ! # else ! LIBC=gnulibc1 ! # endif ! #else ! #ifdef __INTEL_COMPILER ! LIBC=gnu ! #else ! LIBC=gnuaout ! #endif ! #endif EOF ! eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` ! rm -f $dummy.c ! test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0 ! test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 ! ;; ! i*86:DYNIX/ptx:4*:*) ! # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. ! # earlier versions are messed up and put the nodename in both ! # sysname and nodename. echo i386-sequent-sysv4 exit 0 ;; ! i*86:UNIX_SV:4.2MP:2.*) ! # Unixware is an offshoot of SVR4, but it has its own version ! # number series starting with 2... ! # I am not positive that other SVR4 systems won't match this, ! # I just have to hope. -- rms. ! # Use sysv4.2uw... so that sysv4* matches it. ! echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} ! exit 0 ;; ! i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) ! UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then ! echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} else ! echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} fi exit 0 ;; ! i*86:*:5:[78]*) ! case `/bin/uname -X | grep "^Machine"` in ! *486*) UNAME_MACHINE=i486 ;; ! *Pentium) UNAME_MACHINE=i586 ;; ! *Pent*|*Celeron) UNAME_MACHINE=i686 ;; ! esac ! echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} ! exit 0 ;; ! i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null) && UNAME_MACHINE=i486 (/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \ && UNAME_MACHINE=i586 + (/bin/uname -X|egrep '^Machine.*Pent ?II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|egrep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 echo ${UNAME_MACHINE}-pc-sco$UNAME_REL else echo ${UNAME_MACHINE}-pc-sysv32 fi exit 0 ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit 0 ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i386. + echo i386-pc-msdosdjgpp + exit 0 ;; Intel:Mach:3*:*) echo i386-pc-mach3 exit 0 ;; *************** *** 489,495 **** exit 0 ;; M68*:*:R3V[567]*:*) test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; ! 3[34]??:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 4850:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` --- 958,964 ---- exit 0 ;; M68*:*:R3V[567]*:*) test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; ! 3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` *************** *** 500,523 **** 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && echo i486-ncr-sysv4 && exit 0 ;; ! m68*:LynxOS:2.*:*) echo m68k-unknown-lynxos${UNAME_RELEASE} exit 0 ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit 0 ;; ! i?86:LynxOS:2.*:*) echo i386-unknown-lynxos${UNAME_RELEASE} exit 0 ;; TSUNAMI:LynxOS:2.*:*) echo sparc-unknown-lynxos${UNAME_RELEASE} exit 0 ;; ! rs6000:LynxOS:2.*:* | PowerPC:LynxOS:2.*:*) echo rs6000-unknown-lynxos${UNAME_RELEASE} exit 0 ;; SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv${UNAME_RELEASE} exit 0 ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 exit 0 ;; --- 969,998 ---- 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && echo i486-ncr-sysv4 && exit 0 ;; ! m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) echo m68k-unknown-lynxos${UNAME_RELEASE} exit 0 ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit 0 ;; ! i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) echo i386-unknown-lynxos${UNAME_RELEASE} exit 0 ;; TSUNAMI:LynxOS:2.*:*) echo sparc-unknown-lynxos${UNAME_RELEASE} exit 0 ;; ! rs6000:LynxOS:2.*:*) echo rs6000-unknown-lynxos${UNAME_RELEASE} exit 0 ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv${UNAME_RELEASE} exit 0 ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit 0 ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 exit 0 ;; *************** *** 529,534 **** --- 1004,1013 ---- echo ns32k-sni-sysv fi exit 0 ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit 0 ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm *************** *** 538,572 **** # From seanf@swdc.stratus.com. echo i860-stratus-sysv4 exit 0 ;; mc68*:A/UX:*:*) echo m68k-apple-aux${UNAME_RELEASE} exit 0 ;; ! R3000:*System_V*:*:* | R4000:UNIX_SYSV:*:*) if [ -d /usr/nec ]; then echo mips-nec-sysv${UNAME_RELEASE} else echo mips-unknown-sysv${UNAME_RELEASE} fi exit 0 ;; ! PENTIUM:CPunix:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort ! # says ! echo i586-unisys-sysv4 ! exit 0 ;; ! news*:NEWS-OS:[56].*:*) ! echo mips-sony-newsos${UNAME_RELEASE} exit 0 ;; *:Rhapsody:*:*) ! echo `arch`-apple-rhapsody${UNAME_RELEASE} ! exit 0;; ! i?86:OS/2:*:*) ! echo ${UNAME_MACHINE}-ibm-os2 exit 0 ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 #echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 ! cat >dummy.c < # include --- 1017,1133 ---- # From seanf@swdc.stratus.com. echo i860-stratus-sysv4 exit 0 ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit 0 ;; mc68*:A/UX:*:*) echo m68k-apple-aux${UNAME_RELEASE} exit 0 ;; ! news*:NEWS-OS:6*:*) ! echo mips-sony-newsos6 ! exit 0 ;; ! R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then echo mips-nec-sysv${UNAME_RELEASE} else echo mips-unknown-sysv${UNAME_RELEASE} fi exit 0 ;; ! BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. ! echo powerpc-be-beos ! exit 0 ;; ! BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. ! echo powerpc-apple-beos ! exit 0 ;; ! BePC:BeOS:*:*) # BeOS running on Intel PC compatible. ! echo i586-pc-beos ! exit 0 ;; ! SX-4:SUPER-UX:*:*) ! echo sx4-nec-superux${UNAME_RELEASE} ! exit 0 ;; ! SX-5:SUPER-UX:*:*) ! echo sx5-nec-superux${UNAME_RELEASE} ! exit 0 ;; ! Power*:Rhapsody:*:*) ! echo powerpc-apple-rhapsody${UNAME_RELEASE} exit 0 ;; *:Rhapsody:*:*) ! echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} ! exit 0 ;; ! *:Darwin:*:*) ! echo `uname -p`-apple-darwin${UNAME_RELEASE} ! exit 0 ;; ! *:procnto*:*:* | *:QNX:[0123456789]*:*) ! if test "${UNAME_MACHINE}" = "x86pc"; then ! UNAME_MACHINE=pc ! echo i386-${UNAME_MACHINE}-nto-qnx ! else ! echo `uname -p`-${UNAME_MACHINE}-nto-qnx ! fi ! exit 0 ;; ! *:QNX:*:4*) ! echo i386-pc-qnx ! exit 0 ;; ! NSR-[GKLNPTVW]:NONSTOP_KERNEL:*:*) ! echo nsr-tandem-nsk${UNAME_RELEASE} ! exit 0 ;; ! *:NonStop-UX:*:*) ! echo mips-compaq-nonstopux ! exit 0 ;; ! BS2000:POSIX*:*:*) ! echo bs2000-siemens-sysv ! exit 0 ;; ! DS/*:UNIX_System_V:*:*) ! echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} ! exit 0 ;; ! *:Plan9:*:*) ! # "uname -m" is not consistent, so use $cputype instead. 386 ! # is converted to i386 for consistency with other x86 ! # operating systems. ! if test "$cputype" = "386"; then ! UNAME_MACHINE=i386 ! else ! UNAME_MACHINE="$cputype" ! fi ! echo ${UNAME_MACHINE}-unknown-plan9 ! exit 0 ;; ! i*86:OS/2:*:*) ! # If we were able to find `uname', then EMX Unix compatibility ! # is probably installed. ! echo ${UNAME_MACHINE}-pc-os2-emx ! exit 0 ;; ! *:TOPS-10:*:*) ! echo pdp10-unknown-tops10 ! exit 0 ;; ! *:TENEX:*:*) ! echo pdp10-unknown-tenex ! exit 0 ;; ! KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) ! echo pdp10-dec-tops20 ! exit 0 ;; ! XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) ! echo pdp10-xkl-tops20 ! exit 0 ;; ! *:TOPS-20:*:*) ! echo pdp10-unknown-tops20 ! exit 0 ;; ! *:ITS:*:*) ! echo pdp10-unknown-its ! exit 0 ;; ! i*86:XTS-300:*:STOP) ! echo ${UNAME_MACHINE}-unknown-stop ! exit 0 ;; ! i*86:atheos:*:*) ! echo ${UNAME_MACHINE}-unknown-atheos exit 0 ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 #echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 ! eval $set_cc_for_build ! cat >$dummy.c < # include *************** *** 604,610 **** #endif int version; version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; ! printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); exit (0); #endif --- 1165,1174 ---- #endif int version; version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; ! if (version < 4) ! printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); ! else ! printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); exit (0); #endif *************** *** 649,659 **** #endif #if defined (vax) ! #if !defined (ultrix) ! printf ("vax-dec-bsd\n"); exit (0); ! #else ! printf ("vax-dec-ultrix\n"); exit (0); ! #endif #endif #if defined (alliant) && defined (i860) --- 1213,1236 ---- #endif #if defined (vax) ! # if !defined (ultrix) ! # include ! # if defined (BSD) ! # if BSD == 43 ! printf ("vax-dec-bsd4.3\n"); exit (0); ! # else ! # if BSD == 199006 ! printf ("vax-dec-bsd4.3reno\n"); exit (0); ! # else ! printf ("vax-dec-bsd\n"); exit (0); ! # endif ! # endif ! # else ! printf ("vax-dec-bsd\n"); exit (0); ! # endif ! # else ! printf ("vax-dec-ultrix\n"); exit (0); ! # endif #endif #if defined (alliant) && defined (i860) *************** *** 664,671 **** } EOF ! ${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy && rm dummy.c dummy && exit 0 ! rm -f dummy.c dummy # Apollos put the system type in the environment. --- 1241,1248 ---- } EOF ! $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy && rm -f $dummy.c $dummy && exit 0 ! rm -f $dummy.c $dummy # Apollos put the system type in the environment. *************** *** 697,702 **** esac fi ! #echo '(Unable to guess system type)' 1>&2 exit 1 --- 1274,1321 ---- esac fi ! cat >&2 < in order to provide the needed ! information to handle your system. ! ! config.guess timestamp = $timestamp ! ! uname -m = `(uname -m) 2>/dev/null || echo unknown` ! uname -r = `(uname -r) 2>/dev/null || echo unknown` ! uname -s = `(uname -s) 2>/dev/null || echo unknown` ! uname -v = `(uname -v) 2>/dev/null || echo unknown` ! ! /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` ! /bin/uname -X = `(/bin/uname -X) 2>/dev/null` ! ! hostinfo = `(hostinfo) 2>/dev/null` ! /bin/universe = `(/bin/universe) 2>/dev/null` ! /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` ! /bin/arch = `(/bin/arch) 2>/dev/null` ! /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` ! /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` ! ! UNAME_MACHINE = ${UNAME_MACHINE} ! UNAME_RELEASE = ${UNAME_RELEASE} ! UNAME_SYSTEM = ${UNAME_SYSTEM} ! UNAME_VERSION = ${UNAME_VERSION} ! EOF exit 1 + + # Local variables: + # eval: (add-hook 'write-file-hooks 'time-stamp) + # time-stamp-start: "timestamp='" + # time-stamp-format: "%:y-%02m-%02d" + # time-stamp-end: "'" + # End: diff -Ncr squid-2.4.STABLE6/include/version.h squid-2.4.STABLE7/include/version.h *** squid-2.4.STABLE6/include/version.h Tue Mar 19 16:54:32 2002 --- squid-2.4.STABLE7/include/version.h Tue Jul 2 10:02:02 2002 *************** *** 1,12 **** /* ! * $Id: version.h,v 1.131.2.8 2002/03/19 23:52:12 wessels Exp $ * * SQUID_VERSION - String for version id of this distribution */ #ifndef SQUID_VERSION ! #define SQUID_VERSION "2.4.STABLE6" #endif #ifndef SQUID_RELEASE_TIME ! #define SQUID_RELEASE_TIME 1016582072 #endif --- 1,12 ---- /* ! * $Id: version.h,v 1.131.2.9 2002/07/02 15:49:48 wessels Exp $ * * SQUID_VERSION - String for version id of this distribution */ #ifndef SQUID_VERSION ! #define SQUID_VERSION "2.4.STABLE7" #endif #ifndef SQUID_RELEASE_TIME ! #define SQUID_RELEASE_TIME 1025625722 #endif diff -Ncr squid-2.4.STABLE6/src/HttpHeader.c squid-2.4.STABLE7/src/HttpHeader.c *** squid-2.4.STABLE6/src/HttpHeader.c Thu Jan 11 17:51:43 2001 --- squid-2.4.STABLE7/src/HttpHeader.c Mon Jun 24 00:10:51 2002 *************** *** 1,6 **** /* ! * $Id: HttpHeader.c,v 1.67.2.2 2001/01/12 00:51:43 wessels Exp $ * * DEBUG: section 55 HTTP Header * AUTHOR: Alex Rousskov --- 1,6 ---- /* ! * $Id: HttpHeader.c,v 1.67.2.3 2002/06/24 06:10:51 hno Exp $ * * DEBUG: section 55 HTTP Header * AUTHOR: Alex Rousskov *************** *** 112,117 **** --- 112,118 ---- {"Server", HDR_SERVER, ftStr}, {"Set-Cookie", HDR_SET_COOKIE, ftStr}, {"Title", HDR_TITLE, ftStr}, + {"Transfer-Encoding", HDR_TRANSFER_ENCODING, ftStr}, {"Upgrade", HDR_UPGRADE, ftStr}, /* for now */ {"User-Agent", HDR_USER_AGENT, ftStr}, {"Vary", HDR_VARY, ftStr}, /* for now */ *************** *** 145,151 **** HDR_IF_MATCH, HDR_IF_NONE_MATCH, HDR_LINK, HDR_PRAGMA, HDR_PROXY_CONNECTION, ! /* HDR_TRANSFER_ENCODING, */ HDR_UPGRADE, HDR_VARY, HDR_VIA, --- 146,152 ---- HDR_IF_MATCH, HDR_IF_NONE_MATCH, HDR_LINK, HDR_PRAGMA, HDR_PROXY_CONNECTION, ! HDR_TRANSFER_ENCODING, HDR_UPGRADE, HDR_VARY, HDR_VIA, *************** *** 161,167 **** static http_hdr_type GeneralHeadersArr[] = { HDR_CACHE_CONTROL, HDR_CONNECTION, HDR_DATE, HDR_PRAGMA, ! /* HDR_TRANSFER_ENCODING, */ HDR_UPGRADE, /* HDR_TRAILER, */ HDR_VIA --- 162,168 ---- static http_hdr_type GeneralHeadersArr[] = { HDR_CACHE_CONTROL, HDR_CONNECTION, HDR_DATE, HDR_PRAGMA, ! HDR_TRANSFER_ENCODING, HDR_UPGRADE, /* HDR_TRAILER, */ HDR_VIA diff -Ncr squid-2.4.STABLE6/src/acl.c squid-2.4.STABLE7/src/acl.c *** squid-2.4.STABLE6/src/acl.c Mon Aug 20 23:55:47 2001 --- squid-2.4.STABLE7/src/acl.c Thu Apr 11 10:47:58 2002 *************** *** 1,6 **** /* ! * $Id: acl.c,v 1.225.2.8 2001/08/21 05:55:47 wessels Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels --- 1,6 ---- /* ! * $Id: acl.c,v 1.225.2.10 2002/04/11 16:47:58 hno Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels diff -Ncr squid-2.4.STABLE6/src/asn.c squid-2.4.STABLE7/src/asn.c *** squid-2.4.STABLE6/src/asn.c Thu Jan 11 17:51:44 2001 --- squid-2.4.STABLE7/src/asn.c Wed Apr 17 17:52:17 2002 *************** *** 1,6 **** /* ! * $Id: asn.c,v 1.64.2.2 2001/01/12 00:51:44 wessels Exp $ * * DEBUG: section 53 AS Number handling * AUTHOR: Duane Wessels, Kostas Anagnostakis --- 1,6 ---- /* ! * $Id: asn.c,v 1.64.2.3 2002/04/17 23:52:17 wessels Exp $ * * DEBUG: section 53 AS Number handling * AUTHOR: Duane Wessels, Kostas Anagnostakis *************** *** 93,99 **** --- 93,101 ---- static void destroyRadixNodeInfo(as_info *); static OBJH asnStats; + #ifndef _SQUID_APPLE_ extern struct radix_node *rn_lookup(void *, void *, void *); + #endif /* PUBLIC */ diff -Ncr squid-2.4.STABLE6/src/cf.data.pre squid-2.4.STABLE7/src/cf.data.pre *** squid-2.4.STABLE6/src/cf.data.pre Wed Apr 4 01:01:12 2001 --- squid-2.4.STABLE7/src/cf.data.pre Sun Jun 23 14:10:16 2002 *************** *** 1,6 **** # ! # $Id: cf.data.pre,v 1.199.2.7 2001/04/04 07:01:12 adrian Exp $ # # # SQUID Web Proxy Cache http://www.squid-cache.org/ --- 1,6 ---- # ! # $Id: cf.data.pre,v 1.199.2.9 2002/06/23 20:10:16 hno Exp $ # # # SQUID Web Proxy Cache http://www.squid-cache.org/ *************** *** 468,478 **** DEFAULT: 8 MB LOC: Config.memMaxSize DOC_START ! NOTE: THIS PARAMETER DOES NOT SPECIFY THE MAXIMUM PROCESS ! SIZE. IT PLACES A LIMIT ON ONE ASPECT OF SQUID'S MEMORY ! USAGE. SQUID USES MEMORY FOR OTHER THINGS AS WELL. ! YOUR PROCESS WILL PROBABLY BECOME TWICE OR THREE TIMES ! BIGGER THAN THE VALUE YOU PUT HERE 'cache_mem' specifies the ideal amount of memory to be used for: --- 468,477 ---- DEFAULT: 8 MB LOC: Config.memMaxSize DOC_START ! NOTE: THIS PARAMETER DOES NOT SPECIFY THE MAXIMUM PROCESS SIZE. ! IT ONLY PLACES A LIMIT ON HOW MUCH ADDITIONAL MEMORY SQUID WILL ! USE AS A MEMORY CACHE OF OBJECTS. SQUID USES MEMORY FOR OTHER ! THINGS AS WELL. SEE THE SQUID FAQ SECTION 8 FOR DETAILS. 'cache_mem' specifies the ideal amount of memory to be used for: *************** *** 968,973 **** --- 967,984 ---- DOC_START If your firewall does not allow Squid to use passive connections, then turn off this option. + DOC_END + + NAME: ftp_sanitycheck + TYPE: onoff + DEFAULT: on + LOC: Config.Ftp.sanitycheck + DOC_START + For security and data integrity reasons Squid by default performs + sanity checks of the addresses of FTP data connections ensure the + data connection is to the requested server. If you need to allow + FTP connections to servers using another IP address for the data + connection then turn this off. DOC_END NAME: cache_dns_program diff -Ncr squid-2.4.STABLE6/src/client.c squid-2.4.STABLE7/src/client.c *** squid-2.4.STABLE6/src/client.c Thu Jan 11 17:51:45 2001 --- squid-2.4.STABLE7/src/client.c Tue Jun 25 15:13:46 2002 *************** *** 1,6 **** /* ! * $Id: client.c,v 1.89.2.2 2001/01/12 00:51:45 wessels Exp $ * * DEBUG: section 0 WWW Client * AUTHOR: Harvest Derived --- 1,6 ---- /* ! * $Id: client.c,v 1.89.2.3 2002/06/25 21:13:46 wessels Exp $ * * DEBUG: section 0 WWW Client * AUTHOR: Harvest Derived *************** *** 120,126 **** strcpy(url, argv[argc - 1]); if (url[0] == '-') usage(argv[0]); ! while ((c = getopt(argc, argv, "ah:l:P:i:km:p:rsvt:g:p:I:H:?")) != -1) switch (c) { case 'a': opt_noaccept = 1; --- 120,126 ---- strcpy(url, argv[argc - 1]); if (url[0] == '-') usage(argv[0]); ! while ((c = getopt(argc, argv, "ah:l:P:i:km:p:rsvt:g:p:I:H:T:?")) != -1) switch (c) { case 'a': opt_noaccept = 1; *************** *** 176,181 **** --- 176,184 ---- while ((t = strstr(extra_hdrs, "\\n"))) *t = '\r', *(t + 1) = '\n'; } + break; + case 'T': + io_timeout = atoi(optarg); break; case 'v': /* undocumented: may increase verb-level by giving more -v's */ diff -Ncr squid-2.4.STABLE6/src/client_side.c squid-2.4.STABLE7/src/client_side.c *** squid-2.4.STABLE6/src/client_side.c Fri Apr 20 17:21:41 2001 --- squid-2.4.STABLE7/src/client_side.c Mon Jun 24 00:10:51 2002 *************** *** 1,6 **** /* ! * $Id: client_side.c,v 1.512.2.10 2001/04/20 23:21:41 hno Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels --- 1,6 ---- /* ! * $Id: client_side.c,v 1.512.2.12 2002/06/24 06:10:51 hno Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels *************** *** 973,986 **** static int clientCachable(clientHttpRequest * http) { - const char *url = http->uri; request_t *req = http->request; method_t method = req->method; if (req->protocol == PROTO_HTTP) return httpCachable(method); /* FTP is always cachable */ if (req->protocol == PROTO_GOPHER) ! return gopherCachable(url); if (req->protocol == PROTO_WAIS) return 0; if (method == METHOD_CONNECT) --- 973,985 ---- static int clientCachable(clientHttpRequest * http) { request_t *req = http->request; method_t method = req->method; if (req->protocol == PROTO_HTTP) return httpCachable(method); /* FTP is always cachable */ if (req->protocol == PROTO_GOPHER) ! return gopherCachable(req); if (req->protocol == PROTO_WAIS) return 0; if (method == METHOD_CONNECT) *************** *** 1020,1026 **** if (request->protocol == PROTO_HTTP) return httpCachable(method); if (request->protocol == PROTO_GOPHER) ! return gopherCachable(url); if (request->protocol == PROTO_WAIS) return 0; if (request->protocol == PROTO_CACHEOBJ) --- 1019,1025 ---- if (request->protocol == PROTO_HTTP) return httpCachable(method); if (request->protocol == PROTO_GOPHER) ! return gopherCachable(request); if (request->protocol == PROTO_WAIS) return 0; if (request->protocol == PROTO_CACHEOBJ) *************** *** 2688,2694 **** request->my_addr = conn->me.sin_addr; request->my_port = ntohs(conn->me.sin_port); request->http_ver = http->http_ver; ! if (!urlCheckRequest(request)) { err = errorCon(ERR_UNSUP_REQ, HTTP_NOT_IMPLEMENTED); err->src_addr = conn->peer.sin_addr; err->request = requestLink(request); --- 2687,2694 ---- request->my_addr = conn->me.sin_addr; request->my_port = ntohs(conn->me.sin_port); request->http_ver = http->http_ver; ! if (!urlCheckRequest(request) || ! httpHeaderHas(&request->header, HDR_TRANSFER_ENCODING)) { err = errorCon(ERR_UNSUP_REQ, HTTP_NOT_IMPLEMENTED); err->src_addr = conn->peer.sin_addr; err->request = requestLink(request); diff -Ncr squid-2.4.STABLE6/src/enums.h squid-2.4.STABLE7/src/enums.h *** squid-2.4.STABLE6/src/enums.h Thu Jan 11 17:51:47 2001 --- squid-2.4.STABLE7/src/enums.h Mon Jun 24 00:10:51 2002 *************** *** 1,6 **** /* ! * $Id: enums.h,v 1.176.2.2 2001/01/12 00:51:47 wessels Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ --- 1,6 ---- /* ! * $Id: enums.h,v 1.176.2.3 2002/06/24 06:10:51 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ *************** *** 215,220 **** --- 215,221 ---- HDR_SERVER, HDR_SET_COOKIE, HDR_TITLE, + HDR_TRANSFER_ENCODING, HDR_UPGRADE, HDR_USER_AGENT, HDR_VARY, diff -Ncr squid-2.4.STABLE6/src/ftp.c squid-2.4.STABLE7/src/ftp.c *** squid-2.4.STABLE6/src/ftp.c Sat Feb 16 17:41:18 2002 --- squid-2.4.STABLE7/src/ftp.c Sun Jun 23 14:18:58 2002 *************** *** 1,6 **** /* ! * $Id: ftp.c,v 1.298.2.6 2002/02/17 00:41:18 hno Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived --- 1,6 ---- /* ! * $Id: ftp.c,v 1.298.2.8 2002/06/23 20:18:58 hno Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived *************** *** 461,471 **** #define MAX_TOKENS 64 - #define SCAN_FTP1 "%[0123456789]" - #define SCAN_FTP2 "%[0123456789:]" - #define SCAN_FTP3 "%[0123456789]-%[0123456789]-%[0123456789]" - #define SCAN_FTP4 "%[0123456789]:%[0123456789]%[AaPp]%[Mm]" - static ftpListParts * ftpListParseParts(const char *buf, struct _ftp_flags flags) { --- 461,466 ---- *************** *** 475,490 **** char *tokens[MAX_TOKENS]; int i; int n_tokens; ! static char sbuf[128]; char *xbuf = NULL; if (buf == NULL) return NULL; if (*buf == '\0') return NULL; p = xcalloc(1, sizeof(ftpListParts)); n_tokens = 0; ! for (i = 0; i < MAX_TOKENS; i++) ! tokens[i] = (char *) NULL; xbuf = xstrdup(buf); if (flags.tried_nlst) { /* Machine readable format, one name per line */ --- 470,497 ---- char *tokens[MAX_TOKENS]; int i; int n_tokens; ! static char tbuf[128]; char *xbuf = NULL; + static int scan_ftp_initialized = 0; + static regex_t scan_ftp_integer; + static regex_t scan_ftp_time; + static regex_t scan_ftp_dostime; + static regex_t scan_ftp_dosdate; + + if (!scan_ftp_initialized) { + scan_ftp_initialized = 1; + regcomp(&scan_ftp_integer, "^[0123456789]+$", REG_EXTENDED | REG_NOSUB); + regcomp(&scan_ftp_time, "^[0123456789:]+$", REG_EXTENDED | REG_NOSUB); + regcomp(&scan_ftp_dosdate, "^[0123456789]+-[0123456789]+-[0123456789]+$", REG_EXTENDED | REG_NOSUB); + regcomp(&scan_ftp_dostime, "^[0123456789]+:[0123456789]+[AP]M$", REG_EXTENDED | REG_NOSUB | REG_ICASE); + } if (buf == NULL) return NULL; if (*buf == '\0') return NULL; p = xcalloc(1, sizeof(ftpListParts)); n_tokens = 0; ! memset(tokens, 0, sizeof(tokens)); xbuf = xstrdup(buf); if (flags.tried_nlst) { /* Machine readable format, one name per line */ *************** *** 497,551 **** xfree(xbuf); /* locate the Month field */ for (i = 3; i < n_tokens - 2; i++) { ! if (!is_month(tokens[i])) /* Month */ continue; ! if (!sscanf(tokens[i - 1], SCAN_FTP1, sbuf)) /* Size */ continue; ! if (!sscanf(tokens[i + 1], SCAN_FTP1, sbuf)) /* Day */ continue; ! if (!sscanf(tokens[i + 2], SCAN_FTP2, sbuf)) /* Yr | hh:mm */ continue; ! p->type = *tokens[0]; ! p->size = atoi(tokens[i - 1]); ! snprintf(sbuf, 128, "%s %2s %5s", ! tokens[i], tokens[i + 1], tokens[i + 2]); ! if (!strstr(buf, sbuf)) ! snprintf(sbuf, 128, "%s %2s %-5s", ! tokens[i], tokens[i + 1], tokens[i + 2]); ! if ((t = strstr(buf, sbuf))) { ! p->date = xstrdup(sbuf); if (flags.skip_whitespace) { ! t += strlen(sbuf); while (strchr(w_space, *t)) t++; } else { /* XXX assumes a single space between date and filename * suggested by: Nathan.Bailey@cc.monash.edu.au and * Mike Battersby */ ! t += strlen(sbuf) + 1; } p->name = xstrdup(t); if ((t = strstr(p->name, " -> "))) { *t = '\0'; p->link = xstrdup(t + 4); } } break; } ! /* try it as a DOS listing */ ! if (n_tokens > 3 && p->name == NULL && ! sscanf(tokens[0], SCAN_FTP3, sbuf, sbuf, sbuf) == 3 && ! /* 04-05-70 */ ! sscanf(tokens[1], SCAN_FTP4, sbuf, sbuf, sbuf, sbuf) == 4) { ! /* 09:33PM */ if (!strcasecmp(tokens[2], "

    ")) { p->type = 'd'; } else { p->type = '-'; p->size = atoi(tokens[2]); } ! snprintf(sbuf, 128, "%s %s", tokens[0], tokens[1]); ! p->date = xstrdup(sbuf); if (p->type == 'd') { /* Directory.. name begins with first printable after */ ct = strstr(buf, tokens[2]); --- 504,561 ---- xfree(xbuf); /* locate the Month field */ for (i = 3; i < n_tokens - 2; i++) { ! char *size = tokens[i - 1]; ! char *month = tokens[i]; ! char *day = tokens[i + 1]; ! char *year = tokens[i + 2]; ! if (!is_month(month)) continue; ! if (regexec(&scan_ftp_integer, size, 0, NULL, 0) != 0) continue; ! if (regexec(&scan_ftp_integer, day, 0, NULL, 0) != 0) continue; ! if (regexec(&scan_ftp_time, day, 0, NULL, 0) != 0) /* Yr | hh:mm */ continue; ! snprintf(tbuf, 128, "%s %2s %5s", ! month, day, year); ! if (!strstr(buf, tbuf)) ! snprintf(tbuf, 128, "%s %2s %-5s", ! month, day, year); ! if ((t = strstr(buf, tbuf))) { ! p->type = *tokens[0]; ! p->size = atoi(size); ! p->date = xstrdup(tbuf); if (flags.skip_whitespace) { ! t += strlen(tbuf); while (strchr(w_space, *t)) t++; } else { /* XXX assumes a single space between date and filename * suggested by: Nathan.Bailey@cc.monash.edu.au and * Mike Battersby */ ! t += strlen(tbuf) + 1; } p->name = xstrdup(t); if ((t = strstr(p->name, " -> "))) { *t = '\0'; p->link = xstrdup(t + 4); } + goto found; } break; } ! /* try it as a DOS listing, 04-05-70 09:33PM ... */ ! if (n_tokens > 3 && ! regexec(&scan_ftp_dosdate, tokens[0], 0, NULL, 0) == 0 && ! regexec(&scan_ftp_dostime, tokens[1], 0, NULL, 0) == 0) { if (!strcasecmp(tokens[2], "")) { p->type = 'd'; } else { p->type = '-'; p->size = atoi(tokens[2]); } ! snprintf(tbuf, 128, "%s %s", tokens[0], tokens[1]); ! p->date = xstrdup(tbuf); if (p->type == 'd') { /* Directory.. name begins with first printable after */ ct = strstr(buf, tokens[2]); *************** *** 556,588 **** ct = NULL; } else { /* A file. Name begins after size, with a space in between */ ! snprintf(sbuf, 128, " %s %s", tokens[2], tokens[3]); ! ct = strstr(buf, sbuf); if (ct) { ct += strlen(tokens[2]) + 2; } } p->name = xstrdup(ct ? ct : tokens[3]); } /* Try EPLF format; carson@lehman.com */ ! if (p->name == NULL && buf[0] == '+') { ct = buf + 1; p->type = 0; while (ct && *ct) { - long lt; time_t t; switch (*ct) { case '\t': ! sscanf(ct + 1, "%[^,]", sbuf); ! p->name = xstrdup(sbuf); break; case 's': ! sscanf(ct + 1, "%d", &(p->size)); break; case 'm': ! if (1 != sscanf(ct + 1, "%ld", <)) ! break; ! t = lt; p->date = xstrdup(ctime(&t)); *(strstr(p->date, "\n")) = '\0'; break; --- 566,601 ---- ct = NULL; } else { /* A file. Name begins after size, with a space in between */ ! snprintf(tbuf, 128, " %s %s", tokens[2], tokens[3]); ! ct = strstr(buf, tbuf); if (ct) { ct += strlen(tokens[2]) + 2; } } p->name = xstrdup(ct ? ct : tokens[3]); + goto found; } /* Try EPLF format; carson@lehman.com */ ! if (buf[0] == '+') { ct = buf + 1; p->type = 0; while (ct && *ct) { time_t t; + int l = strcspn(ct + 1, ","); + char *tmp; + if (l < 1) + goto blank; switch (*ct) { case '\t': ! p->name = xstrndup(ct + 1, l + 1); break; case 's': ! p->size = atoi(ct + 1); break; case 'm': ! t = (time_t) strtol(ct + 1, &tmp, 0); ! if (*tmp || (tmp == ct + 1)) ! break; /* not a valid integer */ p->date = xstrdup(ctime(&t)); *(strstr(p->date, "\n")) = '\0'; break; *************** *** 597,602 **** --- 610,616 ---- default: break; } + blank: ct = strstr(ct, ","); if (ct) { ct++; *************** *** 605,615 **** if (p->type == 0) { p->type = '-'; } } for (i = 0; i < n_tokens; i++) xfree(tokens[i]); ! if (p->name == NULL) ! ftpListPartsFree(&p); return p; } --- 619,634 ---- if (p->type == 0) { p->type = '-'; } + if (p->name) + goto found; + else + safe_free(p->date); } + found: for (i = 0; i < n_tokens; i++) xfree(tokens[i]); ! if (!p->name) ! ftpListPartsFree(&p); /* cleanup */ return p; } *************** *** 712,718 **** snprintf(icon, 2048, "\"%-6s\"", mimeGetIconURL("internal-dir"), "[DIR]"); ! strncat(href, "/", 2048); break; case 'l': snprintf(icon, 2048, "\"%-6s\"", --- 731,737 ---- snprintf(icon, 2048, "\"%-6s\"", mimeGetIconURL("internal-dir"), "[DIR]"); ! strcat(href, "/"); /* margin is allocated above */ break; case 'l': snprintf(icon, 2048, "\"%-6s\"", *************** *** 954,964 **** ftpState->flags.authenticated = 1; orig_user = xstrdup(ftpState->user); ftpLoginParser(auth, ftpState, FTP_LOGIN_NOT_ESCAPED); ! if (!strcmp(orig_user, ftpState->user)) { xfree(orig_user); return 1; /* same username */ } ! strcpy(ftpState->user, orig_user); xfree(orig_user); return 0; /* different username */ } --- 973,983 ---- ftpState->flags.authenticated = 1; orig_user = xstrdup(ftpState->user); ftpLoginParser(auth, ftpState, FTP_LOGIN_NOT_ESCAPED); ! if (strcmp(orig_user, ftpState->user) == 0) { xfree(orig_user); return 1; /* same username */ } ! xstrncpy(ftpState->user, orig_user, sizeof(ftpState->user)); xfree(orig_user); return 0; /* different username */ } *************** *** 1020,1026 **** strCat(ftpState->base_href, rfc1738_escape_part(ftpState->password)); } strCat(ftpState->base_href, "@"); ! } strCat(ftpState->base_href, request->host); if (request->port != urlDefaultPort(PROTO_FTP)) { strCat(ftpState->base_href, ":"); --- 1039,1045 ---- strCat(ftpState->base_href, rfc1738_escape_part(ftpState->password)); } strCat(ftpState->base_href, "@"); ! } strCat(ftpState->base_href, request->host); if (request->port != urlDefaultPort(PROTO_FTP)) { strCat(ftpState->base_href, ":"); *************** *** 1720,1768 **** int n; u_short port; int fd = ftpState->data.fd; ! char *buf = ftpState->ctrl.last_reply; ! LOCAL_ARRAY(char, junk, 1024); debug(9, 3) ("This is ftpReadPasv\n"); if (code != 227) { debug(9, 3) ("PASV not supported by remote end\n"); ftpSendPort(ftpState); return; } ! if ((int) strlen(buf) > 1024) { ! debug(9, 1) ("ftpReadPasv: Avoiding potential buffer overflow\n"); ftpSendPort(ftpState); return; } ! /* 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2). */ ! /* ANSI sez [^0-9] is undefined, it breaks on Watcom cc */ ! debug(9, 5) ("scanning: %s\n", buf); ! n = sscanf(buf, "%[^0123456789]%d,%d,%d,%d,%d,%d", ! junk, &h1, &h2, &h3, &h4, &p1, &p2); ! if (n != 7 || p1 < 0 || p2 < 0 || p1 > 255 || p2 > 255) { ! debug(9, 3) ("Bad 227 reply\n"); ! debug(9, 3) ("n=%d, p1=%d, p2=%d\n", n, p1, p2); ftpSendPort(ftpState); return; } ! snprintf(junk, 1024, "%d.%d.%d.%d", h1, h2, h3, h4); ! if (!safe_inet_addr(junk, NULL)) { ! debug(9, 1) ("unsafe address (%s)\n", junk); ftpSendPort(ftpState); return; } port = ((p1 << 8) + p2); if (0 == port) { ! debug(9, 1) ("ftpReadPasv: Invalid PASV reply: %s\n", buf); ftpSendPort(ftpState); return; } ! debug(9, 5) ("ftpReadPasv: connecting to %s, port %d\n", junk, port); ftpState->data.port = port; ! ftpState->data.host = xstrdup(junk); safe_free(ftpState->ctrl.last_command); safe_free(ftpState->ctrl.last_reply); ftpState->ctrl.last_command = xstrdup("Connect to server data port"); ! commConnectStart(fd, junk, port, ftpPasvCallback, ftpState); } static void --- 1739,1799 ---- int n; u_short port; int fd = ftpState->data.fd; ! char *buf; ! LOCAL_ARRAY(char, ipaddr, 1024); debug(9, 3) ("This is ftpReadPasv\n"); if (code != 227) { debug(9, 3) ("PASV not supported by remote end\n"); ftpSendPort(ftpState); return; } ! /* 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2). */ ! /* ANSI sez [^0-9] is undefined, it breaks on Watcom cc */ ! debug(9, 5) ("scanning: %s\n", ftpState->ctrl.last_reply); ! buf = strstr(ftpState->ctrl.last_reply, "("); ! if (!buf) { ! debug(9, 1) ("Unsafe PASV reply from %s: '%s'\n", fd_table[ftpState->ctrl.fd].ipaddr, ftpState->ctrl.last_reply); ftpSendPort(ftpState); return; } ! buf++; /* skip ( */ ! n = sscanf(buf, "%d,%d,%d,%d,%d,%d", &h1, &h2, &h3, &h4, &p1, &p2); ! if (n != 6 || p1 < 0 || p2 < 0 || p1 > 255 || p2 > 255) { ! debug(9, 1) ("Unsafe PASV reply from %s: %s\n", fd_table[ftpState->ctrl.fd].ipaddr, ftpState->ctrl.last_reply); ftpSendPort(ftpState); return; } ! snprintf(ipaddr, 1024, "%d.%d.%d.%d", h1, h2, h3, h4); ! if (!safe_inet_addr(ipaddr, NULL)) { ! debug(9, 1) ("Unsafe PASV reply from %s: %s\n", fd_table[ftpState->ctrl.fd].ipaddr, ftpState->ctrl.last_reply); ftpSendPort(ftpState); return; } port = ((p1 << 8) + p2); if (0 == port) { ! debug(9, 1) ("Unsafe PASV reply from %s: %s\n", fd_table[ftpState->ctrl.fd].ipaddr, ftpState->ctrl.last_reply); ftpSendPort(ftpState); return; } ! if (Config.Ftp.sanitycheck) { ! if (strcmp(fd_table[ftpState->ctrl.fd].ipaddr, ipaddr) != 0) { ! debug(9, 1) ("Unsafe PASV reply from %s: %s\n", fd_table[ftpState->ctrl.fd].ipaddr, ftpState->ctrl.last_reply); ! ftpSendPort(ftpState); ! return; ! } ! if (port < 1024) { ! debug(9, 1) ("Unsafe PASV reply from %s: %s\n", fd_table[ftpState->ctrl.fd].ipaddr, ftpState->ctrl.last_reply); ! ftpSendPort(ftpState); ! return; ! } ! } ! debug(9, 5) ("ftpReadPasv: connecting to %s, port %d\n", ipaddr, port); ftpState->data.port = port; ! ftpState->data.host = xstrdup(ipaddr); safe_free(ftpState->ctrl.last_command); safe_free(ftpState->ctrl.last_reply); ftpState->ctrl.last_command = xstrdup("Connect to server data port"); ! commConnectStart(fd, ipaddr, port, ftpPasvCallback, ftpState); } static void *************** *** 1889,1894 **** --- 1920,1938 ---- return; } fd = comm_accept(fd, &my_peer, &me); + if (Config.Ftp.sanitycheck) { + char *ipaddr = inet_ntoa(my_peer.sin_addr); + if (strcmp(fd_table[ftpState->ctrl.fd].ipaddr, ipaddr) != 0) { + debug(9, 1) ("FTP data connection from unexpected server (%s:%d), expecting %s\n", ipaddr, (int) ntohs(my_peer.sin_port), fd_table[ftpState->ctrl.fd].ipaddr); + comm_close(fd); + commSetSelect(ftpState->data.fd, + COMM_SELECT_READ, + ftpAcceptDataConnection, + ftpState, + 0); + return; + } + } if (fd < 0) { debug(9, 1) ("ftpHandleDataAccept: comm_accept(%d): %s", fd, xstrerror()); /* XXX Need to set error message */ *************** *** 2560,2566 **** snprintf(portbuf, 32, ":%d", request->port); loginbuf[0] = '\0'; if ((int) strlen(request->login) > 0) { ! strcpy(loginbuf, request->login); if ((t = strchr(loginbuf, ':'))) *t = '\0'; strcat(loginbuf, "@"); --- 2604,2610 ---- snprintf(portbuf, 32, ":%d", request->port); loginbuf[0] = '\0'; if ((int) strlen(request->login) > 0) { ! xstrncpy(loginbuf, request->login, sizeof(loginbuf) - 2); if ((t = strchr(loginbuf, ':'))) *t = '\0'; strcat(loginbuf, "@"); diff -Ncr squid-2.4.STABLE6/src/gopher.c squid-2.4.STABLE7/src/gopher.c *** squid-2.4.STABLE6/src/gopher.c Thu Jan 11 17:51:48 2001 --- squid-2.4.STABLE7/src/gopher.c Sun Jun 23 14:01:03 2002 *************** *** 1,6 **** /* ! * $Id: gopher.c,v 1.156.2.2 2001/01/12 00:51:48 wessels Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived --- 1,6 ---- /* ! * $Id: gopher.c,v 1.156.2.3 2002/06/23 20:01:03 hno Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived *************** *** 68,74 **** typedef struct gopher_ds { StoreEntry *entry; - char host[SQUIDHOSTNAMELEN + 1]; enum { NORMAL, HTML_DIR, --- 68,73 ---- *************** *** 78,84 **** HTML_CSO_PAGE } conversion; int HTML_header_added; - int port; char type_id; char request[MAX_URL]; int data_in; --- 77,82 ---- *************** *** 86,100 **** int len; char *buf; /* pts to a 4k page */ int fd; FwdState *fwdState; } GopherStateData; static PF gopherStateFree; static void gopher_mime_content(MemBuf * mb, const char *name, const char *def); static void gopherMimeCreate(GopherStateData *); ! static int gopher_url_parser(const char *url, ! char *host, ! int *port, char *type_id, char *request); static void gopherEndHTML(GopherStateData *); --- 84,97 ---- int len; char *buf; /* pts to a 4k page */ int fd; + request_t *req; FwdState *fwdState; } GopherStateData; static PF gopherStateFree; static void gopher_mime_content(MemBuf * mb, const char *name, const char *def); static void gopherMimeCreate(GopherStateData *); ! static void gopher_request_parse(const request_t * req, char *type_id, char *request); static void gopherEndHTML(GopherStateData *); *************** *** 117,122 **** --- 114,122 ---- if (gopherState->entry) { storeUnlockObject(gopherState->entry); } + if (gopherState->req) { + requestUnlink(gopherState->req); + } memFree(gopherState->buf, MEM_4K_BUF); gopherState->buf = NULL; cbdataFree(gopherState); *************** *** 191,249 **** memBufClean(&mb); } ! /* Parse a gopher url into components. By Anawat. */ ! static int ! gopher_url_parser(const char *url, char *host, int *port, char *type_id, char *request) ! { ! LOCAL_ARRAY(char, proto, MAX_URL); ! LOCAL_ARRAY(char, hostbuf, MAX_URL); ! int t; ! ! proto[0] = hostbuf[0] = '\0'; ! host[0] = request[0] = '\0'; ! (*port) = 0; ! (*type_id) = 0; ! ! t = sscanf(url, ! #if defined(__QNX__) ! "%[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]://%[^/]/%c%s", ! #else ! "%[a-zA-Z]://%[^/]/%c%s", ! #endif ! proto, hostbuf, type_id, request); ! if ((t < 2) || strcasecmp(proto, "gopher")) { ! return -1; ! } else if (t == 2) { ! (*type_id) = GOPHER_DIRECTORY; ! request[0] = '\0'; ! } else if (t == 3) { request[0] = '\0'; ! } else { /* convert %xx to char */ url_convert_hex(request, 0); } - - host[0] = '\0'; - if (sscanf(hostbuf, "%[^:]:%d", host, port) < 2) - (*port) = GOPHER_PORT; - - return 0; } int ! gopherCachable(const char *url) { - GopherStateData *gopherState = NULL; int cachable = 1; ! /* use as temp data structure to parse gopher URL */ ! gopherState = CreateGopherStateData(); /* parse to see type */ ! gopher_url_parser(url, ! gopherState->host, ! &gopherState->port, ! &gopherState->type_id, ! gopherState->request); ! switch (gopherState->type_id) { case GOPHER_INDEX: case GOPHER_CSO: case GOPHER_TELNET: --- 191,231 ---- memBufClean(&mb); } ! /* Parse a gopher request into components. By Anawat. */ ! static void ! gopher_request_parse(const request_t * req, char *type_id, char *request) ! { ! const char *path = strBuf(req->urlpath); ! ! if (request) request[0] = '\0'; ! ! if (path && (*path == '/')) ! path++; ! ! if (!path || !*path) { ! *type_id = GOPHER_DIRECTORY; ! return; ! } ! *type_id = path[0]; ! ! if (request) { ! xstrncpy(request, path + 1, MAX_URL); /* convert %xx to char */ url_convert_hex(request, 0); } } int ! gopherCachable(const request_t * req) { int cachable = 1; ! char type_id; /* parse to see type */ ! gopher_request_parse(req, ! &type_id, ! NULL); ! switch (type_id) { case GOPHER_INDEX: case GOPHER_CSO: case GOPHER_TELNET: *************** *** 253,259 **** default: cachable = 1; } - gopherStateFree(-1, gopherState); return cachable; } --- 235,240 ---- *************** *** 277,283 **** char *tline = NULL; LOCAL_ARRAY(char, line, TEMP_BUF_SIZE); LOCAL_ARRAY(char, tmpbuf, TEMP_BUF_SIZE); ! LOCAL_ARRAY(char, outbuf, TEMP_BUF_SIZE << 4); char *name = NULL; char *selector = NULL; char *host = NULL; --- 258,264 ---- char *tline = NULL; LOCAL_ARRAY(char, line, TEMP_BUF_SIZE); LOCAL_ARRAY(char, tmpbuf, TEMP_BUF_SIZE); ! String outbuf = StringNull; char *name = NULL; char *selector = NULL; char *host = NULL; *************** *** 287,306 **** char gtype; StoreEntry *entry = NULL; - memset(outbuf, '\0', TEMP_BUF_SIZE << 4); memset(tmpbuf, '\0', TEMP_BUF_SIZE); memset(line, '\0', TEMP_BUF_SIZE); entry = gopherState->entry; if (gopherState->conversion == HTML_INDEX_PAGE) { storeAppendPrintf(entry, "Gopher Index %s\n" "

    %s
    Gopher Search

    \n" "

    This is a searchable Gopher index. Use the search\n" "function of your browser to enter search terms.\n" "\n", ! storeUrl(entry), storeUrl(entry)); /* now let start sending stuff to client */ storeBufferFlush(entry); gopherState->data_in = 1; --- 268,287 ---- char gtype; StoreEntry *entry = NULL; memset(tmpbuf, '\0', TEMP_BUF_SIZE); memset(line, '\0', TEMP_BUF_SIZE); entry = gopherState->entry; if (gopherState->conversion == HTML_INDEX_PAGE) { + char *html_url = html_quote(storeUrl(entry)); storeAppendPrintf(entry, "Gopher Index %s\n" "

    %s
    Gopher Search

    \n" "

    This is a searchable Gopher index. Use the search\n" "function of your browser to enter search terms.\n" "\n", ! html_url, html_url); /* now let start sending stuff to client */ storeBufferFlush(entry); gopherState->data_in = 1; *************** *** 308,320 **** return; } if (gopherState->conversion == HTML_CSO_PAGE) { storeAppendPrintf(entry, "CSO Search of %s\n" "

    %s
    CSO Search

    \n" "

    A CSO database usually contains a phonebook or\n" "directory. Use the search function of your browser to enter\n" "search terms.

    \n", ! storeUrl(entry), storeUrl(entry)); /* now let start sending stuff to client */ storeBufferFlush(entry); gopherState->data_in = 1; --- 289,302 ---- return; } if (gopherState->conversion == HTML_CSO_PAGE) { + char *html_url = html_quote(storeUrl(entry)); storeAppendPrintf(entry, "CSO Search of %s\n" "

    %s
    CSO Search

    \n" "

    A CSO database usually contains a phonebook or\n" "directory. Use the search function of your browser to enter\n" "search terms.

    \n", ! html_url, html_url); /* now let start sending stuff to client */ storeBufferFlush(entry); gopherState->data_in = 1; *************** *** 325,334 **** if (!gopherState->HTML_header_added) { if (gopherState->conversion == HTML_CSO_RESULT) ! strcat(outbuf, "CSO Searchs Result\n" ! "

    CSO Searchs Result

    \n
    \n");
      	else
    ! 	    strcat(outbuf, "Gopher Menu\n"
      		"

    Gopher Menu

    \n
    \n");
      	gopherState->HTML_header_added = 1;
          }
    --- 307,316 ----
      
          if (!gopherState->HTML_header_added) {
      	if (gopherState->conversion == HTML_CSO_RESULT)
    ! 	    strCat(outbuf, "CSO Search Result\n"
    ! 		"

    CSO Search Result

    \n
    \n");
      	else
    ! 	    strCat(outbuf, "Gopher Menu\n"
      		"

    Gopher Menu

    \n
    \n");
      	gopherState->HTML_header_added = 1;
          }
    ***************
    *** 336,342 ****
      
      	if (gopherState->len != 0) {
      	    /* there is something left from last tx. */
    ! 	    xstrncpy(line, gopherState->buf, gopherState->len);
      	    lpos = (char *) memccpy(line + gopherState->len, inbuf, '\n', len);
      	    if (lpos)
      		*lpos = '\0';
    --- 318,324 ----
      
      	if (gopherState->len != 0) {
      	    /* there is something left from last tx. */
    ! 	    xstrncpy(line, gopherState->buf, gopherState->len + 1);
      	    lpos = (char *) memccpy(line + gopherState->len, inbuf, '\n', len);
      	    if (lpos)
      		*lpos = '\0';
    ***************
    *** 435,440 ****
    --- 417,423 ----
      			case GOPHER_DIRECTORY:
      			    icon_url = mimeGetIconURL("internal-menu");
      			    break;
    + 			case GOPHER_HTML:
      			case GOPHER_FILE:
      			    icon_url = mimeGetIconURL("internal-text");
      			    break;
    ***************
    *** 464,469 ****
    --- 447,455 ----
      			case GOPHER_UUENCODED:
      			    icon_url = mimeGetIconURL("internal-binary");
      			    break;
    + 			case GOPHER_INFO:
    + 			    icon_url = NULL;
    + 			    break;
      			default:
      			    icon_url = mimeGetIconURL("internal-unknown");
      			    break;
    ***************
    *** 480,491 ****
      				    icon_url, rfc1738_escape_part(host), *port ? ":" : "",
      				    port, html_quote(name));
      
      			} else {
    ! 			    snprintf(tmpbuf, TEMP_BUF_SIZE, " %s\n",
    ! 				icon_url, host, gtype, escaped_selector, html_quote(name));
      			}
      			safe_free(escaped_selector);
    ! 			strcat(outbuf, tmpbuf);
      			gopherState->data_in = 1;
      		    } else {
      			memset(line, '\0', TEMP_BUF_SIZE);
    --- 466,486 ----
      				    icon_url, rfc1738_escape_part(host), *port ? ":" : "",
      				    port, html_quote(name));
      
    + 			} else if (gtype == GOPHER_INFO) {
    + 			    snprintf(tmpbuf, TEMP_BUF_SIZE, "\t%s\n", html_quote(name));
      			} else {
    ! 			    if (strncmp(selector, "GET /", 5) == 0) {
    ! 				/* WWW link */
    ! 				snprintf(tmpbuf, TEMP_BUF_SIZE, " %s\n",
    ! 				    icon_url, host, rfc1738_escape_unescaped(selector + 5), html_quote(name));
    ! 			    } else {
    ! 				/* Standard link */
    ! 				snprintf(tmpbuf, TEMP_BUF_SIZE, " %s\n",
    ! 				    icon_url, host, gtype, escaped_selector, html_quote(name));
    ! 			    }
      			}
      			safe_free(escaped_selector);
    ! 			strCat(outbuf, tmpbuf);
      			gopherState->data_in = 1;
      		    } else {
      			memset(line, '\0', TEMP_BUF_SIZE);
    ***************
    *** 500,517 ****
      
      
      	case HTML_CSO_RESULT:{
    ! 		int t;
    ! 		int code;
    ! 		int recno;
    ! 		LOCAL_ARRAY(char, result, MAX_CSO_RESULT);
      
    ! 		tline = line;
    ! 
    ! 		if (tline[0] == '-') {
    ! 		    t = sscanf(tline, "-%d:%d:%[^\n]", &code, &recno, result);
    ! 		    if (t < 3)
      			break;
      
      		    if (code != 200)
      			break;
      
    --- 495,514 ----
      
      
      	case HTML_CSO_RESULT:{
    ! 		if (line[0] == '-') {
    ! 		    int code, recno;
    ! 		    char *s_code, *s_recno, *result;
    ! 
    ! 		    s_code = strtok(line + 1, ":\n");
    ! 		    s_recno = strtok(NULL, ":\n");
    ! 		    result = strtok(NULL, "\n");
      
    ! 		    if (!result)
      			break;
      
    + 		    code = atoi(s_code);
    + 		    recno = atoi(s_recno);
    + 
      		    if (code != 200)
      			break;
      
    ***************
    *** 521,536 ****
      		    } else {
      			snprintf(tmpbuf, TEMP_BUF_SIZE, "%s\n", html_quote(result));
      		    }
    ! 		    strcat(outbuf, tmpbuf);
      		    gopherState->data_in = 1;
      		    break;
      		} else {
    ! 		    /* handle some error codes */
    ! 		    t = sscanf(tline, "%d:%[^\n]", &code, result);
      
    ! 		    if (t < 2)
      			break;
      
      		    switch (code) {
      
      		    case 200:{
    --- 518,537 ----
      		    } else {
      			snprintf(tmpbuf, TEMP_BUF_SIZE, "%s\n", html_quote(result));
      		    }
    ! 		    strCat(outbuf, tmpbuf);
      		    gopherState->data_in = 1;
      		    break;
      		} else {
    ! 		    int code;
    ! 		    char *s_code, *result;
      
    ! 		    s_code = strtok(line, ":");
    ! 		    result = strtok(NULL, "\n");
    ! 
    ! 		    if (!result)
      			break;
      
    + 		    code = atoi(s_code);
      		    switch (code) {
      
      		    case 200:{
    ***************
    *** 545,551 ****
      			{
      			    /* Print the message the server returns */
      			    snprintf(tmpbuf, TEMP_BUF_SIZE, "

    %s

    \n
    ", html_quote(result));
    ! 			    strcat(outbuf, tmpbuf);
      			    gopherState->data_in = 1;
      			    break;
      			}
    --- 546,552 ----
      			{
      			    /* Print the message the server returns */
      			    snprintf(tmpbuf, TEMP_BUF_SIZE, "

    %s

    \n
    ", html_quote(result));
    ! 			    strCat(outbuf, tmpbuf);
      			    gopherState->data_in = 1;
      			    break;
      			}
    ***************
    *** 562,572 ****
      
          }				/* while loop */
      
    !     if ((int) strlen(outbuf) > 0) {
    ! 	storeAppend(entry, outbuf, strlen(outbuf));
      	/* now let start sending stuff to client */
      	storeBufferFlush(entry);
          }
          return;
      }
      
    --- 563,574 ----
      
          }				/* while loop */
      
    !     if (strLen(outbuf) > 0) {
    ! 	storeAppend(entry, strBuf(outbuf), strLen(outbuf));
      	/* now let start sending stuff to client */
      	storeBufferFlush(entry);
          }
    +     stringClean(&outbuf);
          return;
      }
      
    ***************
    *** 692,699 ****
      	ErrorState *err;
      	err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE);
      	err->xerrno = errno;
    ! 	err->host = xstrdup(gopherState->host);
    ! 	err->port = gopherState->port;
      	err->url = xstrdup(storeUrl(entry));
      	errorAppendEntry(entry, err);
      	comm_close(fd);
    --- 694,701 ----
      	ErrorState *err;
      	err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE);
      	err->xerrno = errno;
    ! 	err->host = xstrdup(gopherState->req->host);
    ! 	err->port = gopherState->req->port;
      	err->url = xstrdup(storeUrl(entry));
      	errorAppendEntry(entry, err);
      	comm_close(fd);
    ***************
    *** 741,752 ****
      gopherSendRequest(int fd, void *data)
      {
          GopherStateData *gopherState = data;
    -     LOCAL_ARRAY(char, query, MAX_URL);
          char *buf = memAllocate(MEM_4K_BUF);
          char *t;
          if (gopherState->type_id == GOPHER_CSO) {
    ! 	sscanf(gopherState->request, "?%s", query);
    ! 	snprintf(buf, 4096, "query %s\r\nquit\r\n", query);
          } else if (gopherState->type_id == GOPHER_INDEX) {
      	if ((t = strchr(gopherState->request, '?')))
      	    *t = '\t';
    --- 743,757 ----
      gopherSendRequest(int fd, void *data)
      {
          GopherStateData *gopherState = data;
          char *buf = memAllocate(MEM_4K_BUF);
          char *t;
          if (gopherState->type_id == GOPHER_CSO) {
    ! 	t = strchr(gopherState->request, '?');
    ! 	if (t)
    ! 	    t++;
    ! 	else
    ! 	    t = "";
    ! 	snprintf(buf, 4096, "query %s\r\nquit\r\n", t);
          } else if (gopherState->type_id == GOPHER_INDEX) {
      	if ((t = strchr(gopherState->request, '?')))
      	    *t = '\t';
    ***************
    *** 773,784 ****
          GopherStateData *gopherState = CreateGopherStateData();
          storeLockObject(entry);
          gopherState->entry = entry;
          debug(10, 3) ("gopherStart: %s\n", storeUrl(entry));
          statCounter.server.all.requests++;
          statCounter.server.other.requests++;
          /* Parse url. */
    !     if (gopher_url_parser(storeUrl(entry), gopherState->host, &gopherState->port,
    ! 	    &gopherState->type_id, gopherState->request)) {
      	ErrorState *err;
      	err = errorCon(ERR_INVALID_URL, HTTP_BAD_REQUEST);
      	err->url = xstrdup(storeUrl(entry));
    --- 778,792 ----
          GopherStateData *gopherState = CreateGopherStateData();
          storeLockObject(entry);
          gopherState->entry = entry;
    +     gopherState->fwdState = fwdState;
          debug(10, 3) ("gopherStart: %s\n", storeUrl(entry));
          statCounter.server.all.requests++;
          statCounter.server.other.requests++;
          /* Parse url. */
    !     gopher_request_parse(fwdState->request,
    ! 	&gopherState->type_id, gopherState->request);
    ! #if OLD_PARSE_ERROR_CODE
    !     if (...) {
      	ErrorState *err;
      	err = errorCon(ERR_INVALID_URL, HTTP_BAD_REQUEST);
      	err->url = xstrdup(storeUrl(entry));
    ***************
    *** 786,791 ****
    --- 794,800 ----
      	gopherStateFree(-1, gopherState);
      	return;
          }
    + #endif
          comm_add_close_handler(fd, gopherStateFree, gopherState);
          if (((gopherState->type_id == GOPHER_INDEX) || (gopherState->type_id == GOPHER_CSO))
      	&& (strchr(gopherState->request, '?') == NULL)) {
    diff -Ncr squid-2.4.STABLE6/src/htcp.c squid-2.4.STABLE7/src/htcp.c
    *** squid-2.4.STABLE6/src/htcp.c	Sun Feb 17 17:31:31 2002
    --- squid-2.4.STABLE7/src/htcp.c	Mon May 13 14:13:48 2002
    ***************
    *** 1,6 ****
      
      /*
    !  * $Id: htcp.c,v 1.32.2.5 2002/02/18 00:31:31 hno Exp $
       *
       * DEBUG: section 31    Hypertext Caching Protocol
       * AUTHOR: Duane Wesssels
    --- 1,6 ----
      
      /*
    !  * $Id: htcp.c,v 1.32.2.6 2002/05/13 20:13:48 wessels Exp $
       *
       * DEBUG: section 31    Hypertext Caching Protocol
       * AUTHOR: Duane Wesssels
    ***************
    *** 843,856 ****
      void
      htcpInit(void)
      {
          if (Config.Port.htcp <= 0) {
      	/*
      	 *      Need to allocate a bit of memory anyway, otherwise
      	 *      mem.c::memCheckInit() will bail out.
      	 */
    ! 	memDataInit(MEM_HTCP_SPECIFIER, "htcpSpecifier",
      		sizeof(htcpSpecifier), 0);
    ! 	memDataInit(MEM_HTCP_DETAIL, "htcpDetail", sizeof(htcpDetail), 0);
      	htcpInSocket = -1;
      	debug(31, 1) ("HTCP Disabled.\n");
      	return;
    --- 843,859 ----
      void
      htcpInit(void)
      {
    +     static int calls = 0;
          if (Config.Port.htcp <= 0) {
      	/*
      	 *      Need to allocate a bit of memory anyway, otherwise
      	 *      mem.c::memCheckInit() will bail out.
      	 */
    ! 	if (0 == calls++) {
    ! 	    memDataInit(MEM_HTCP_SPECIFIER, "htcpSpecifier",
      		sizeof(htcpSpecifier), 0);
    ! 	    memDataInit(MEM_HTCP_DETAIL, "htcpDetail", sizeof(htcpDetail), 0);
    ! 	}
      	htcpInSocket = -1;
      	debug(31, 1) ("HTCP Disabled.\n");
      	return;
    ***************
    *** 886,893 ****
          } else {
      	htcpOutSocket = htcpInSocket;
          }
    !     memDataInit(MEM_HTCP_SPECIFIER, "htcpSpecifier", sizeof(htcpSpecifier), 0);
    !     memDataInit(MEM_HTCP_DETAIL, "htcpDetail", sizeof(htcpDetail), 0);
      }
      
      void
    --- 889,898 ----
          } else {
      	htcpOutSocket = htcpInSocket;
          }
    !     if (0 == calls++) {
    ! 	memDataInit(MEM_HTCP_SPECIFIER, "htcpSpecifier", sizeof(htcpSpecifier), 0);
    ! 	memDataInit(MEM_HTCP_DETAIL, "htcpDetail", sizeof(htcpDetail), 0);
    !     }
      }
      
      void
    diff -Ncr squid-2.4.STABLE6/src/http.c squid-2.4.STABLE7/src/http.c
    *** squid-2.4.STABLE6/src/http.c	Wed Jul 11 16:58:20 2001
    --- squid-2.4.STABLE7/src/http.c	Thu Jun 27 17:32:46 2002
    ***************
    *** 1,6 ****
      
      /*
    !  * $Id: http.c,v 1.371.2.2 2001/07/11 22:58:20 wessels Exp $
       *
       * DEBUG: section 11    Hypertext Transfer Protocol (HTTP)
       * AUTHOR: Harvest Derived
    --- 1,6 ----
      
      /*
    !  * $Id: http.c,v 1.371.2.3 2002/06/27 23:32:46 hno Exp $
       *
       * DEBUG: section 11    Hypertext Transfer Protocol (HTTP)
       * AUTHOR: Harvest Derived
    ***************
    *** 688,694 ****
      	switch (e->id) {
      	case HDR_PROXY_AUTHORIZATION:
      	    /* If we're not doing proxy auth, then it must be passed on */
    ! 	    if (!request->flags.used_proxy_auth)
      		httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e));
      	    break;
      	case HDR_AUTHORIZATION:
    --- 688,694 ----
      	switch (e->id) {
      	case HDR_PROXY_AUTHORIZATION:
      	    /* If we're not doing proxy auth, then it must be passed on */
    ! 	    if (request->flags.proxying && !request->flags.used_proxy_auth)
      		httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e));
      	    break;
      	case HDR_AUTHORIZATION:
    diff -Ncr squid-2.4.STABLE6/src/protos.h squid-2.4.STABLE7/src/protos.h
    *** squid-2.4.STABLE6/src/protos.h	Sat Feb 16 18:10:15 2002
    --- squid-2.4.STABLE7/src/protos.h	Sun Jun 23 14:01:03 2002
    ***************
    *** 1,6 ****
      
      /*
    !  * $Id: protos.h,v 1.387.2.9 2002/02/17 01:10:15 hno Exp $
       *
       *
       * SQUID Web Proxy Cache          http://www.squid-cache.org/
    --- 1,6 ----
      
      /*
    !  * $Id: protos.h,v 1.387.2.10 2002/06/23 20:01:03 hno Exp $
       *
       *
       * SQUID Web Proxy Cache          http://www.squid-cache.org/
    ***************
    *** 264,270 ****
      extern char *ftpUrlWith2f(const request_t *);
      
      extern void gopherStart(FwdState *);
    ! extern int gopherCachable(const char *);
      
      
      extern void whoisStart(FwdState *);
    --- 264,270 ----
      extern char *ftpUrlWith2f(const request_t *);
      
      extern void gopherStart(FwdState *);
    ! extern int gopherCachable(const request_t *);
      
      
      extern void whoisStart(FwdState *);
    diff -Ncr squid-2.4.STABLE6/src/squid.h squid-2.4.STABLE7/src/squid.h
    *** squid-2.4.STABLE6/src/squid.h	Thu Feb 22 14:39:14 2001
    --- squid-2.4.STABLE7/src/squid.h	Wed Apr 17 17:52:17 2002
    ***************
    *** 1,6 ****
      
      /*
    !  * $Id: squid.h,v 1.203.2.5 2001/02/22 21:39:14 wessels Exp $
       *
       * AUTHOR: Duane Wessels
       *
    --- 1,6 ----
      
      /*
    !  * $Id: squid.h,v 1.203.2.6 2002/04/17 23:52:17 wessels Exp $
       *
       * AUTHOR: Duane Wessels
       *
    ***************
    *** 378,387 ****
      
      /*
       * Mac OS X Server already has radix.h as a standard header, so
    !  * this causes conflicts.
       */
      #ifndef _SQUID_APPLE_
      #include "radix.h"
      #endif
      
      #if !HAVE_TEMPNAM
    --- 378,390 ----
      
      /*
       * Mac OS X Server already has radix.h as a standard header, so
    !  * this causes conflicts.  However, rn_walktree is our own thing,
    !  * and we must make sure to provide a prototype.
       */
      #ifndef _SQUID_APPLE_
      #include "radix.h"
    + #else
    + extern int rn_walktree __P((struct radix_node_head *, int (*)(), void *));
      #endif
      
      #if !HAVE_TEMPNAM
    diff -Ncr squid-2.4.STABLE6/src/structs.h squid-2.4.STABLE7/src/structs.h
    *** squid-2.4.STABLE6/src/structs.h	Mon Oct  8 09:22:03 2001
    --- squid-2.4.STABLE7/src/structs.h	Sun Jun 23 14:10:17 2002
    ***************
    *** 1,6 ****
      
      /*
    !  * $Id: structs.h,v 1.361.2.15 2001/10/08 15:22:03 hno Exp $
       *
       *
       * SQUID Web Proxy Cache          http://www.squid-cache.org/
    --- 1,6 ----
      
      /*
    !  * $Id: structs.h,v 1.361.2.16 2002/06/23 20:10:17 hno Exp $
       *
       *
       * SQUID Web Proxy Cache          http://www.squid-cache.org/
    ***************
    *** 459,464 ****
    --- 459,465 ----
      	int list_wrap;
      	char *anon_user;
      	int passive;
    + 	int sanitycheck;
          } Ftp;
          refresh_t *Refresh;
          struct _cacheSwap {