--------------------- PatchSet 1154 Date: 2001/01/07 09:48:26 Author: hno Branch: auth_rewrite Tag: (none) Log: indent Members: ChangeLog:1.1.1.3.10.7.2.2->1.1.1.3.10.7.2.3 auth_modules/LDAP/squid_ldap_auth.c:1.1.1.1->1.1.1.1.26.1 auth_modules/MSNT/allowusers.c:1.1.4.1->1.1.4.1.2.1 auth_modules/MSNT/byteorder.h:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/confload.c:1.1.4.1->1.1.4.1.2.1 auth_modules/MSNT/denyusers.c:1.1.6.2->1.1.6.2.2.1 auth_modules/MSNT/md4.c:1.1.1.1->1.1.1.1.26.1 auth_modules/MSNT/msntauth.c:1.1.4.1->1.1.4.1.2.1 auth_modules/MSNT/rfcnb-common.h:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/rfcnb-error.h:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/rfcnb-io.c:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/rfcnb-io.h:1.1.1.1->1.1.1.1.26.1 auth_modules/MSNT/rfcnb-priv.h:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/rfcnb-util.c:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/rfcnb-util.h:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/rfcnb.h:1.1.1.1->1.1.1.1.26.1 auth_modules/MSNT/session.c:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/smbdes.c:1.1.1.1->1.1.1.1.26.1 auth_modules/MSNT/smbencrypt.c:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/smblib-common.h:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/smblib-priv.h:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/smblib-util.c:1.1.1.1.10.1.2.1->1.1.1.1.10.1.2.2 auth_modules/MSNT/smblib.c:1.1.1.1.10.2.2.1->1.1.1.1.10.2.2.2 auth_modules/MSNT/smblib.h:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/std-defines.h:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/std-includes.h:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/valid.c:1.1.1.1.10.1->1.1.1.1.10.1.2.1 auth_modules/MSNT/valid.h:1.1.1.1->1.1.1.1.26.1 auth_modules/NCSA/ncsa_auth.c:1.1.1.1->1.1.1.1.30.1 auth_modules/SMB/smb_auth.c:1.1.1.2.10.1->1.1.1.2.10.1.2.1 auth_modules/getpwnam/getpwnam_auth.c:1.1.1.1->1.1.1.1.30.1 include/Array.h:1.1.1.1->1.1.1.1.26.1 include/Stack.h:1.1.1.1->1.1.1.1.26.1 include/asn1.h:1.1.1.1->1.1.1.1.26.1 include/ntlmauth.h:1.1.4.2->1.1.4.3 include/radix.h:1.1.1.1->1.1.1.1.26.1 include/snmp_client.h:1.1.1.1->1.1.1.1.26.1 include/snmp_pdu.h:1.1.1.1->1.1.1.1.26.1 include/snmp_vars.h:1.1.1.2->1.1.1.2.22.1 lib/GNUregex.c:1.1.1.1->1.1.1.1.26.1 lib/base64.c:1.1.1.1.14.1->1.1.1.1.14.1.2.1 lib/dlmalloc.c:1.1.1.1->1.1.1.1.26.1 lib/ntlmauth.c:1.1.4.4->1.1.4.5 lib/util.c:1.1.1.3.10.5.2.1->1.1.1.3.10.5.2.2 lib/uudecode.c:1.1.1.1->1.1.1.1.26.1 ntlm_auth_modules/NTLMSSP/libntlmssp.c:1.1.2.12.2.7->1.1.2.12.2.8 ntlm_auth_modules/NTLMSSP/ntlm.h:1.1.2.12.2.7->1.1.2.12.2.8 ntlm_auth_modules/NTLMSSP/ntlm_auth.c:1.1.2.10.2.7->1.1.2.10.2.8 ntlm_auth_modules/NTLMSSP/smbval/byteorder.h:1.1.2.1.2.2->1.1.2.1.2.3 ntlm_auth_modules/NTLMSSP/smbval/md4.c:1.1.2.1.2.2->1.1.2.1.2.3 ntlm_auth_modules/NTLMSSP/smbval/rfcnb-common.h:1.1.2.1.2.2->1.1.2.1.2.3 ntlm_auth_modules/NTLMSSP/smbval/rfcnb-error.h:1.1.2.1.2.3->1.1.2.1.2.4 ntlm_auth_modules/NTLMSSP/smbval/rfcnb-io.c:1.1.2.1.2.3->1.1.2.1.2.4 ntlm_auth_modules/NTLMSSP/smbval/rfcnb-io.h:1.1.2.1.2.3->1.1.2.1.2.4 ntlm_auth_modules/NTLMSSP/smbval/rfcnb-priv.h:1.1.2.2.2.3->1.1.2.2.2.4 ntlm_auth_modules/NTLMSSP/smbval/rfcnb-util.c:1.1.2.1.2.4->1.1.2.1.2.5 ntlm_auth_modules/NTLMSSP/smbval/rfcnb-util.h:1.1.2.1.2.3->1.1.2.1.2.4 ntlm_auth_modules/NTLMSSP/smbval/rfcnb.h:1.1.2.1.2.3->1.1.2.1.2.4 ntlm_auth_modules/NTLMSSP/smbval/session.c:1.1.2.1.2.4->1.1.2.1.2.5 ntlm_auth_modules/NTLMSSP/smbval/smbdes.c:1.1.2.1.2.2->1.1.2.1.2.3 ntlm_auth_modules/NTLMSSP/smbval/smbdes.h:1.1.2.3->1.1.2.4 ntlm_auth_modules/NTLMSSP/smbval/smbencrypt.c:1.1.2.1.2.4->1.1.2.1.2.5 ntlm_auth_modules/NTLMSSP/smbval/smbencrypt.h:1.1.2.3->1.1.2.4 ntlm_auth_modules/NTLMSSP/smbval/smblib-common.h:1.1.2.2.2.2->1.1.2.2.2.3 ntlm_auth_modules/NTLMSSP/smbval/smblib-priv.h:1.1.2.2.2.4->1.1.2.2.2.5 ntlm_auth_modules/NTLMSSP/smbval/smblib-util.c:1.1.2.1.2.5->1.1.2.1.2.6 ntlm_auth_modules/NTLMSSP/smbval/smblib.c:1.1.2.6.2.5->1.1.2.6.2.6 ntlm_auth_modules/NTLMSSP/smbval/smblib.h:1.1.2.1.2.3->1.1.2.1.2.4 ntlm_auth_modules/NTLMSSP/smbval/std-defines.h:1.1.2.3.2.2->1.1.2.3.2.3 ntlm_auth_modules/NTLMSSP/smbval/std-includes.h:1.1.2.1.2.2->1.1.2.1.2.3 ntlm_auth_modules/NTLMSSP/smbval/valid.c:1.1.2.1.2.3->1.1.2.1.2.4 ntlm_auth_modules/NTLMSSP/smbval/valid.h:1.1.2.1.2.2->1.1.2.1.2.3 ntlm_auth_modules/fakeauth/fakeauth_auth.c:1.1.2.6.2.7->1.1.2.6.2.8 ntlm_auth_modules/fakeauth/ntlm.h:1.1.2.3.2.2->1.1.2.3.2.3 snmplib/coexistance.c:1.1.1.1->1.1.1.1.30.1 snmplib/mib.c:1.1.1.1->1.1.1.1.30.1 snmplib/snmp_api.c:1.1.1.1->1.1.1.1.30.1 snmplib/snmp_api_error.c:1.1.1.1->1.1.1.1.30.1 snmplib/snmp_msg.c:1.1.1.1->1.1.1.1.30.1 snmplib/snmp_pdu.c:1.1.1.1->1.1.1.1.30.1 src/HttpRequest.c:1.1.1.3.10.2.2.3->1.1.1.3.10.2.2.4 src/access_log.c:1.1.1.3.12.7.2.4->1.1.1.3.12.7.2.5 src/acl.c:1.1.1.3.12.26.2.22->1.1.1.3.12.26.2.23 src/authenticate.c:1.1.1.3.12.17.2.23->1.1.1.3.12.17.2.24 src/cache_cf.c:1.1.1.3.4.1.2.9.2.15->1.1.1.3.4.1.2.9.2.16 src/client_side.c:1.1.1.3.4.1.2.30.2.16->1.1.1.3.4.1.2.30.2.17 src/defines.h:1.1.1.3.12.9.2.4->1.1.1.3.12.9.2.5 src/enums.h:1.1.1.3.12.15.2.6->1.1.1.3.12.15.2.7 src/errorpage.c:1.1.1.3.10.9.2.8->1.1.1.3.10.9.2.9 src/ftp.c:1.1.1.3.4.1.2.8.2.3->1.1.1.3.4.1.2.8.2.4 src/globals.h:1.1.1.3.12.8.2.3->1.1.1.3.12.8.2.4 src/helper.c:1.1.1.3.12.13.2.6->1.1.1.3.12.13.2.7 src/http.c:1.1.1.3.4.1.2.10.2.5->1.1.1.3.4.1.2.10.2.6 src/main.c:1.1.1.3.4.1.2.12.2.5->1.1.1.3.4.1.2.12.2.6 src/mem.c:1.1.1.3.12.9.2.2->1.1.1.3.12.9.2.3 src/protos.h:1.1.1.3.12.17.2.20->1.1.1.3.12.17.2.21 src/redirect.c:1.1.1.3.4.1.2.2.2.3->1.1.1.3.4.1.2.2.2.4 src/structs.h:1.1.1.3.4.1.2.26.2.25->1.1.1.3.4.1.2.26.2.26 src/tools.c:1.1.1.3.10.7.2.5->1.1.1.3.10.7.2.6 src/typedefs.h:1.1.1.3.12.13.2.17->1.1.1.3.12.13.2.18 src/auth/basic/auth_basic.c:1.1.2.20->1.1.2.21 src/auth/basic/auth_basic.h:1.1.2.6->1.1.2.7 src/auth/ntlm/auth_ntlm.c:1.1.2.17->1.1.2.18 src/auth/ntlm/auth_ntlm.h:1.1.2.6->1.1.2.7 src/fs/ufs/store_dir_ufs.c:1.1.10.8.2.4->1.1.10.8.2.5 src/repl/lru/store_repl_lru.c:1.1.10.2.2.1->1.1.10.2.2.2 test-suite/hash.c:1.1.1.1->1.1.1.1.26.1 test-suite/hash.h:1.1.1.1->1.1.1.1.30.1 test-suite/membanger.c:1.1.1.1->1.1.1.1.30.1 test-suite/pconn-banger.c:1.1.1.1->1.1.1.1.30.1 test-suite/tcp-banger3.c:1.1.1.2->1.1.1.2.30.1 test-suite/waiter.c:1.1.1.1->1.1.1.1.30.1 Index: squid/ChangeLog =================================================================== RCS file: /cvsroot/squid-sf//squid/ChangeLog,v retrieving revision 1.1.1.3.10.7.2.2 retrieving revision 1.1.1.3.10.7.2.3 diff -u -r1.1.1.3.10.7.2.2 -r1.1.1.3.10.7.2.3 --- squid/ChangeLog 30 Dec 2000 22:48:18 -0000 1.1.1.3.10.7.2.2 +++ squid/ChangeLog 7 Jan 2001 09:48:26 -0000 1.1.1.3.10.7.2.3 @@ -1,5 +1,12 @@ Changes to squid-2.5 + - Major rewrite of proxy authentication to support other schemes + than basic. First in the line is NTLM support but others can + easily be added (digest is on the way). See Programmers Guide. + (Robert Collins & Chemolli Francesco) + - Reworked how request bodies are passed down to the protocols. + Now all client side processing is inside client_side.c, and + the pass and pump modules is no longer used. - Fixed forwarding/peer loop detection code (Brian Degenhardt) - now a peer is ignored if it turns out to be us, rather than committing suicide @@ -71,9 +78,6 @@ a more modular fashion. The object replacement and IO is now responsibility of the storage directory, and not of the storage manager. - - Reworked how request bodies are passed down to the protocols. - Now all client side processing is inside client_side.c, and - the pass and pump modules is no longer used. - Fixed a bogous MD5 mismatch warning sometimes seen when using aufs or diskd stores - Added --enable-stacktraces configure option to set PRINT_STACK_TRACE, Index: squid/auth_modules/LDAP/squid_ldap_auth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/LDAP/Attic/squid_ldap_auth.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/auth_modules/LDAP/squid_ldap_auth.c 26 Jan 2000 03:25:00 -0000 1.1.1.1 +++ squid/auth_modules/LDAP/squid_ldap_auth.c 7 Jan 2001 09:48:27 -0000 1.1.1.1.26.1 @@ -1,22 +1,22 @@ /* - - squid_ldap_auth: authentication via ldap for squid proxy server - - Author: Glen Newton - glen.newton@nrc.ca - Advanced Services - CISTI - National Research Council - - Usage: squid_ldap_auth - - Dependencies: You need to get the OpenLDAP libraries - from http://www.openldap.org - - License: squid_ldap_auth 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, - or (at your option) any later version. + * + * squid_ldap_auth: authentication via ldap for squid proxy server + * + * Author: Glen Newton + * glen.newton@nrc.ca + * Advanced Services + * CISTI + * National Research Council + * + * Usage: squid_ldap_auth + * + * Dependencies: You need to get the OpenLDAP libraries + * from http://www.openldap.org + * + * License: squid_ldap_auth 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, + * or (at your option) any later version. */ #include @@ -28,79 +28,70 @@ /* Change this to your search base */ #define SEARCHBASE "ou=people,o=nrc.ca" -int checkLDAP( LDAP *ld, char *userid, char *password); +int checkLDAP(LDAP * ld, char *userid, char *password); -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char buf[256]; - char *user, *passwd, *p; - char *ldapServer; - LDAP *ld; - LDAPMessage *result, *e; - - setbuf(stdout, NULL); - - if (argc != 2) - { - fprintf(stderr, "Usage: squid_ldap_auth ldap_server_name\n"); - exit(1); + char buf[256]; + char *user, *passwd, *p; + char *ldapServer; + LDAP *ld; + LDAPMessage *result, *e; + + setbuf(stdout, NULL); + + if (argc != 2) { + fprintf(stderr, "Usage: squid_ldap_auth ldap_server_name\n"); + exit(1); } + ldapServer = (char *) argv[1]; - ldapServer = (char*)argv[1]; - - while (fgets(buf, 256, stdin) != NULL) - { - /* You can put this ldap connect outside the loop, but i didn't want to - have the connection open too much. If you have a site which will - be doing >1 authentication per second, you should move this (and the - below ldap_unbind()) outside the loop. - */ - if( (ld = ldap_init(ldapServer, LDAP_PORT)) == NULL) - { - fprintf(stderr, "\nUnable to connect to LDAP server:%s port:%d\n", - ldapServer, LDAP_PORT); - exit(1); + while (fgets(buf, 256, stdin) != NULL) { + /* You can put this ldap connect outside the loop, but i didn't want to + * have the connection open too much. If you have a site which will + * be doing >1 authentication per second, you should move this (and the + * below ldap_unbind()) outside the loop. + */ + if ((ld = ldap_init(ldapServer, LDAP_PORT)) == NULL) { + fprintf(stderr, "\nUnable to connect to LDAP server:%s port:%d\n", + ldapServer, LDAP_PORT); + exit(1); } + if ((p = strchr(buf, '\n')) != NULL) + *p = '\0'; /* strip \n */ - if ((p = strchr(buf, '\n')) != NULL) - *p = '\0'; /* strip \n */ - - if ((user = strtok(buf, " ")) == NULL) - { - printf("ERR\n"); - continue; + if ((user = strtok(buf, " ")) == NULL) { + printf("ERR\n"); + continue; } - if ((passwd = strtok(NULL, "")) == NULL) - { - printf("ERR\n"); - continue; + if ((passwd = strtok(NULL, "")) == NULL) { + printf("ERR\n"); + continue; } - if(checkLDAP(ld, user, passwd) != 0) - { - printf("ERR\n"); - continue; + if (checkLDAP(ld, user, passwd) != 0) { + printf("ERR\n"); + continue; + } else { + printf("OK\n"); } - else - { - printf("OK\n"); - } - ldap_unbind(ld); + ldap_unbind(ld); } } -int checkLDAP( LDAP *ld, char *userid, char *password) +int +checkLDAP(LDAP * ld, char *userid, char *password) { - char str[256]; + char str[256]; + + /*sprintf(str,"uid=[%s][%s], %s",userid, password, SEARCHBASE); */ + sprintf(str, "uid=%s, %s", userid, SEARCHBASE); - /*sprintf(str,"uid=[%s][%s], %s",userid, password, SEARCHBASE); */ - sprintf(str,"uid=%s, %s",userid, SEARCHBASE); - - if(ldap_simple_bind_s(ld, str, password) != LDAP_SUCCESS) - { - /*fprintf(stderr, "\nUnable to bind\n");*/ - return 33; + if (ldap_simple_bind_s(ld, str, password) != LDAP_SUCCESS) { + /*fprintf(stderr, "\nUnable to bind\n"); */ + return 33; } - return 0; + return 0; } Index: squid/auth_modules/MSNT/allowusers.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/allowusers.c,v retrieving revision 1.1.4.1 retrieving revision 1.1.4.1.2.1 diff -u -r1.1.4.1 -r1.1.4.1.2.1 --- squid/auth_modules/MSNT/allowusers.c 5 Nov 2000 13:42:35 -0000 1.1.4.1 +++ squid/auth_modules/MSNT/allowusers.c 7 Jan 2001 09:48:27 -0000 1.1.4.1.2.1 @@ -1,13 +1,13 @@ /* - 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. -*/ + * 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 @@ -20,191 +20,173 @@ #include #include -#define NAMELEN 50 /* Maximum username length */ +#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 *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 */ +char Allowuserpath[MAXPATHLEN]; /* MAXPATHLEN defined in param.h */ /* Function declarations */ -int Read_allowusers(); -int Check_ifuserallowed(char *); +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() + * 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; + 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. -*/ + * 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) +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; - } + 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. -*/ + * 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() +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(); - } -} + 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(); + } +} Index: squid/auth_modules/MSNT/byteorder.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/byteorder.h,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/byteorder.h 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/byteorder.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,36 +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. -*/ + * 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 -*/ + * 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 */ + * byteorder */ #ifdef __i386__ #define CAREFUL_ALIGNMENT 0 #endif @@ -44,7 +44,7 @@ #define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val)) typedef unsigned short uint16; -typedef unsigned int uint32; +typedef unsigned int uint32; #if CAREFUL_ALIGNMENT #define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8) @@ -59,11 +59,11 @@ #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val))) #else /* this handles things for architectures like the 386 that can handle - alignment errors */ + * alignment errors */ /* - WARNING: This section is dependent on the length of int16 and int32 - being correct -*/ + * 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))) Index: squid/auth_modules/MSNT/confload.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/confload.c,v retrieving revision 1.1.4.1 retrieving revision 1.1.4.1.2.1 diff -u -r1.1.4.1 -r1.1.4.1.2.1 --- squid/auth_modules/MSNT/confload.c 5 Nov 2000 13:42:35 -0000 1.1.4.1 +++ squid/auth_modules/MSNT/confload.c 7 Jan 2001 09:48:27 -0000 1.1.4.1.2.1 @@ -1,14 +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. -*/ + * 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 @@ -17,234 +17,219 @@ #include #include -#define CONFIGFILE "/usr/local/squid/etc/msntauth.conf" /* Path to configuration file */ +#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 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 Denyuserpath[MAXPATHLEN]; /* MAXPATHLEN defined in param.h */ extern char Allowuserpath[MAXPATHLEN]; -typedef struct _ServerTuple -{ - char pdc[NTHOSTLEN]; - char bdc[NTHOSTLEN]; - char domain[NTHOSTLEN]; +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 */ +ServerTuple ServerArray[MAXSERVERS]; /* Array of servers to query */ +int Serversqueried = 0; /* Number of servers queried */ /* Declarations */ -int OpenConfigFile(); +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 *); +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 */ + * 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 */ - 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; - } + while (!feof(ConfigFile)) { + Confbuf[0] = '\0'; + fgets(Confbuf, 2049, ConfigFile); + ProcessLine(Confbuf); + } - fclose(ConfigFile); - return 0; + /* 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) +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); + 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'; + * 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; + * 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; + 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); - } + * 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; + return result; } /* Valid_User return codes - - - 0 - User authenticated successfully. - 1 - Server error. - 2 - Protocol error. - 3 - Logon error; Incorrect password or username given. -*/ - + * + * 0 - User authenticated successfully. + * 1 - Server error. + * 2 - Protocol error. + * 3 - Logon error; Incorrect password or username given. + */ Index: squid/auth_modules/MSNT/denyusers.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/denyusers.c,v retrieving revision 1.1.6.2 retrieving revision 1.1.6.2.2.1 diff -u -r1.1.6.2 -r1.1.6.2.2.1 --- squid/auth_modules/MSNT/denyusers.c 4 Nov 2000 00:30:04 -0000 1.1.6.2 +++ squid/auth_modules/MSNT/denyusers.c 7 Jan 2001 09:48:27 -0000 1.1.6.2.2.1 @@ -49,7 +49,7 @@ * Logs any messages to the syslog daemon. */ -int +int Read_denyusers() { FILE *DFile; /* Denied user file pointer */ @@ -123,7 +123,7 @@ * user list. Returns 0 if the user was not found, and 1 if they were. */ -int +int Check_ifuserdenied(char *ConnectingUser) { static char CUBuf[NAMELEN + 1]; @@ -163,7 +163,7 @@ * This function is called by the SIGHUP signal handler. */ -void +void Check_fordenychange() { struct stat ChkBuf; /* Stat data buffer */ @@ -200,7 +200,7 @@ * Else return 0. */ -int +int Check_user(char *ConnectingUser) { if (Check_ifuserdenied(ConnectingUser) == 1) @@ -218,7 +218,7 @@ * It is also run after every 60 seconds, at the next request. */ -void +void Check_forchange() { Check_fordenychange(); @@ -231,7 +231,7 @@ * denied user file. If longer than one minute hasn't passed, return. */ -void +void Checktimer() { static time_t Lasttime; /* The last time the timer was checked */ Index: squid/auth_modules/MSNT/md4.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/md4.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/auth_modules/MSNT/md4.c 26 Jan 2000 03:25:00 -0000 1.1.1.1 +++ squid/auth_modules/MSNT/md4.c 7 Jan 2001 09:48:27 -0000 1.1.1.1.26.1 @@ -1,53 +1,57 @@ /* - 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. -*/ + * 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 -*/ + * + * 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) +static uint32 +F(uint32 X, uint32 Y, uint32 Z) { - return (X&Y) | ((~X)&Z); + return (X & Y) | ((~X) & Z); } -static uint32 G(uint32 X, uint32 Y, uint32 Z) +static uint32 +G(uint32 X, uint32 Y, uint32 Z) { - return (X&Y) | (X&Z) | (Y&Z); + return (X & Y) | (X & Z) | (Y & Z); } -static uint32 H(uint32 X, uint32 Y, uint32 Z) +static uint32 +H(uint32 X, uint32 Y, uint32 Z) { - return X^Y^Z; + return X ^ Y ^ Z; } -static uint32 lshift(uint32 x, int s) +static uint32 +lshift(uint32 x, int s) { - x &= 0xFFFFFFFF; - return ((x<>(32-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,117 +59,151 @@ #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) +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; + 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) +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); - } + 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; - for (i=0;i<128;i++) - buf[i] = 0; + 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); - copy4(out, A); - copy4(out+4, B); - copy4(out+8, C); - copy4(out+12, D); - - A = B = C = D = 0; + A = B = C = D = 0; } - - Index: squid/auth_modules/MSNT/msntauth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/msntauth.c,v retrieving revision 1.1.4.1 retrieving revision 1.1.4.1.2.1 diff -u -r1.1.4.1 -r1.1.4.1.2.1 --- squid/auth_modules/MSNT/msntauth.c 5 Nov 2000 13:42:35 -0000 1.1.4.1 +++ squid/auth_modules/MSNT/msntauth.c 7 Jan 2001 09:48:27 -0000 1.1.4.1.2.1 @@ -1,121 +1,114 @@ /* - 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. -*/ + * 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 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 *); +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. -*/ + * Reads the denied user file. Sets alarm timer. + * Scans and checks for Squid input, and attempts to validate the user. + */ -int main() +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; + 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"); + } - 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); } - fflush(stdout); - } - - return 0; + return 0; } - Index: squid/auth_modules/MSNT/rfcnb-common.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/rfcnb-common.h,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/rfcnb-common.h 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/rfcnb-common.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB Common Structures etc Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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,9 +30,9 @@ typedef struct RFCNB_Pkt { - char * data; /* The data in this portion */ - int len; - struct RFCNB_Pkt *next; + char *data; /* The data in this portion */ + int len; + struct RFCNB_Pkt *next; } RFCNB_Pkt; Index: squid/auth_modules/MSNT/rfcnb-error.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/rfcnb-error.h,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/rfcnb-error.h 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/rfcnb-error.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,54 +1,54 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB Error Response Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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_Bad -1 /* Bad response */ #define RFCNBE_OK 0 -/* these should follow the spec ... is there one ?*/ +/* 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 */ +#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 */ Index: squid/auth_modules/MSNT/rfcnb-io.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/rfcnb-io.c,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/rfcnb-io.c 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/rfcnb-io.c 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NEtBIOS implementation - - Version 1.0 - RFCNB IO Routines ... - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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" @@ -30,394 +30,386 @@ #include #include -int RFCNB_Timeout = 0; /* Timeout in seconds ... */ - -void rfcnb_alarm(int sig) +int RFCNB_Timeout = 0; /* Timeout in seconds ... */ +void +rfcnb_alarm(int sig) { - fprintf(stderr, "IO Timed out ...\n"); + fprintf(stderr, "IO Timed out ...\n"); } /* Set timeout value and setup signal handling */ -int RFCNB_Set_Timeout(int seconds) - +int +RFCNB_Set_Timeout(int seconds) { #ifdef __GLIBC__ - int temp; + int temp; #endif - /* If we are on a Bezerkeley system, use sigvec, else sigaction */ + /* If we are on a Bezerkeley system, use sigvec, else sigaction */ #ifndef SA_RESTART - struct sigvec invec, outvec; + struct sigvec invec, outvec; #else - struct sigaction inact, outact; + struct sigaction inact, outact; #endif - RFCNB_Timeout = seconds; + RFCNB_Timeout = seconds; - if (RFCNB_Timeout > 0) { /* Set up handler to ignore but not restart */ + 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; + invec.sv_handler = (void (*)()) rfcnb_alarm; + invec.sv_mask = 0; + invec.sv_flags = SV_INTERRUPT; - if (sigvec(SIGALRM, &invec, &outvec) < 0) - return(-1); + if (sigvec(SIGALRM, &invec, &outvec) < 0) + return (-1); #else - inact.sa_handler = (void (*)())rfcnb_alarm; + 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; + /* 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; + for (temp = 0; temp < 32; temp++) + inact.sa_mask.__val[temp] = 0; #else - inact.sa_mask = 0; + inact.sa_mask = 0; #endif #endif - inact.sa_flags = 0; /* Don't restart */ + inact.sa_flags = 0; /* Don't restart */ - if (sigaction(SIGALRM, &inact, &outact) < 0) - return(-1); + if (sigaction(SIGALRM, &inact, &outact) < 0) + return (-1); #endif - } - - return(0); + } + 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 ... */ + * 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; +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 */ + /* len is the amount we should read */ #ifdef RFCNB_DEBUG - fprintf(stderr, "Discard_Rest called to discard: %i\n", len); + fprintf(stderr, "Discard_Rest called to discard: %i\n", len); #endif - rest = len; + rest = len; - while (rest > 0) { + while (rest > 0) { - this_read = (rest > sizeof(temp)?sizeof(temp):rest); + this_read = (rest > sizeof(temp) ? sizeof(temp) : rest); - bytes_read = read(con -> fd, temp, this_read); + bytes_read = read(con->fd, temp, this_read); - if (bytes_read <= 0) { /* Error so return */ + if (bytes_read <= 0) { /* Error so return */ - if (bytes_read < 0) - RFCNB_errno = RFCNBE_BadRead; - else - RFCNB_errno = RFCNBE_ConGone; + if (bytes_read < 0) + RFCNB_errno = RFCNBE_BadRead; + else + RFCNB_errno = RFCNBE_ConGone; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); + RFCNB_saved_errno = errno; + return (RFCNBE_Bad); - } - - rest = rest - bytes_read; + } + rest = rest - bytes_read; - } + } - return(0); + 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 ... + * + */ - 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 ...*/ +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 */ + /* 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; + pkt_ptr = pkt; + len_sent = tot_sent = 0; /* Nothing sent so far */ + i = 0; - while ((pkt_ptr != NULL) & (i < 10)) { /* Watch that magic number! */ + 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 */ + 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 ... */ + /* Now plug into the iovec ... */ - io_list[i].iov_len = this_len; - io_list[i].iov_base = this_data; - i++; + io_list[i].iov_len = this_len; + io_list[i].iov_base = this_data; + i++; - tot_sent += this_len; + tot_sent += this_len; - if (tot_sent == len) break; /* Let's not send too much */ + if (tot_sent == len) + break; /* Let's not send too much */ - pkt_ptr = pkt_ptr -> next; + pkt_ptr = pkt_ptr->next; - } + } #ifdef RFCNB_DEBUG - fprintf(stderr, "Frags = %i, tot_sent = %i\n", i, tot_sent); + fprintf(stderr, "Frags = %i, tot_sent = %i\n", i, tot_sent); #endif - /* Set up an alarm if timeouts are set ... */ + /* Set up an alarm if timeouts are set ... */ - if (RFCNB_Timeout > 0) - alarm(RFCNB_Timeout); + if (RFCNB_Timeout > 0) + alarm(RFCNB_Timeout); - if ((len_sent = writev(con -> fd, io_list, i)) < 0) { /* An error */ + 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); - } + 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 (RFCNB_Timeout > 0) - alarm(0); /* Reset that sucker */ + } + 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 ... */ + fprintf(stderr, "Len sent = %i ...\n", len_sent); + RFCNB_Print_Pkt(stderr, "sent", pkt, len_sent); /* Print what send ... */ #endif - return(len_sent); + 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 - -*/ + * + * 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; +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 */ + /* Read that header straight into the buffer */ - if (len < RFCNB_Pkt_Hdr_Len) { /* What a bozo */ + if (len < RFCNB_Pkt_Hdr_Len) { /* What a bozo */ #ifdef RFCNB_DEBUG - fprintf(stderr, "Trying to read less than a packet:"); - perror(""); + fprintf(stderr, "Trying to read less than a packet:"); + perror(""); #endif - RFCNB_errno = RFCNBE_BadParam; - return(RFCNBE_Bad); - - } + RFCNB_errno = RFCNBE_BadParam; + return (RFCNBE_Bad); - /* We discard keep alives here ... */ + } + /* We discard keep alives here ... */ - if (RFCNB_Timeout > 0) - alarm(RFCNB_Timeout); + if (RFCNB_Timeout > 0) + alarm(RFCNB_Timeout); - while (seen_keep_alive) { + while (seen_keep_alive) { - if ((read_len = read(con -> fd, hdr, sizeof(hdr))) < 0) { /* Problems */ + if ((read_len = read(con->fd, hdr, sizeof(hdr))) < 0) { /* Problems */ #ifdef RFCNB_DEBUG - fprintf(stderr, "Reading the packet, we got:"); - perror(""); + 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); - - } + 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 */ + } + /* Now we check out what we got */ - if (read_len == 0) { /* Connection closed, send back eof? */ + 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); + 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) { + } + if (RFCNB_Pkt_Type(hdr) == RFCNB_SESSION_KEEP_ALIVE) { #ifdef RFCNB_DEBUG - fprintf(stderr, "RFCNB KEEP ALIVE received\n"); + fprintf(stderr, "RFCNB KEEP ALIVE received\n"); #endif - - } - else { - seen_keep_alive = FALSE; + + } else { + seen_keep_alive = FALSE; + } + } - } - - /* What if we got less than or equal to a hdr size in bytes? */ + /* What if we got less than or equal to a hdr size in bytes? */ - if (read_len < sizeof(hdr)) { /* We got a small packet */ + if (read_len < sizeof(hdr)) { /* We got a small packet */ - /* Now we need to copy the hdr portion we got into the supplied packet */ + /* Now we need to copy the hdr portion we got into the supplied packet */ - memcpy(pkt -> data, hdr, read_len); /*Copy data */ + memcpy(pkt->data, hdr, read_len); /*Copy data */ #ifdef RFCNB_DEBUG - RFCNB_Print_Pkt(stderr, "rcvd", pkt, read_len); + RFCNB_Print_Pkt(stderr, "rcvd", pkt, read_len); #endif - return(read_len); + return (read_len); - } - - /* Now, if we got at least a hdr size, alloc space for rest, if we need it */ + } + /* Now, if we got at least a hdr size, alloc space for rest, if we need it */ - pkt_len = RFCNB_Pkt_Len(hdr); + pkt_len = RFCNB_Pkt_Len(hdr); #ifdef RFCNB_DEBUG - fprintf(stderr, "Reading Pkt: Length = %i\n", pkt_len); -#endif - - /* Now copy in the hdr */ + fprintf(stderr, "Reading Pkt: Length = %i\n", pkt_len); +#endif - memcpy(pkt -> data, hdr, sizeof(hdr)); + /* Now copy in the 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 ... */ + memcpy(pkt->data, hdr, sizeof(hdr)); - if (len < pkt_len) /* Only get as much as we have space for */ - more = len - RFCNB_Pkt_Hdr_Len; - else - more = pkt_len; + /* 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 ... */ - this_time = 0; + if (len < pkt_len) /* Only get as much as we have space for */ + more = len - RFCNB_Pkt_Hdr_Len; + else + more = pkt_len; - /* We read for each fragment ... */ + this_time = 0; - 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 */ - } + /* We read for each fragment ... */ - frag_len = pkt_frag -> len; + 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 */ + } - 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; + frag_len = pkt_frag->len; - while (more > 0) { + 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; - if ((this_time = read(con -> fd, (pkt_frag -> data) + offset, this_len)) <= 0) { /* Problems */ + while (more > 0) { - if (errno == EINTR) { + if ((this_time = read(con->fd, (pkt_frag->data) + offset, this_len)) <= 0) { /* Problems */ - RFCNB_errno = RFCNB_Timeout; + if (errno == EINTR) { - } - else { - if (this_time < 0) - RFCNB_errno = RFCNBE_BadRead; - else - RFCNB_errno = RFCNBE_ConGone; - } + RFCNB_errno = RFCNB_Timeout; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); + } 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); + 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 ... */ + read_len = read_len + this_time; /* How much have we read ... */ - /* Now set up the next part */ + /* Now set up the next part */ - if (pkt_frag -> next == NULL) break; /* That's it here */ + if (pkt_frag->next == NULL) + break; /* That's it here */ - pkt_frag = pkt_frag -> next; - this_len = pkt_frag -> len; - offset = 0; + pkt_frag = pkt_frag->next; + this_len = pkt_frag->len; + offset = 0; - more = more - this_time; + 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)); + 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 (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 */ + } + if (RFCNB_Timeout > 0) + alarm(0); /* Reset that sucker */ - return(read_len + sizeof(RFCNB_Hdr)); + return (read_len + sizeof(RFCNB_Hdr)); } Index: squid/auth_modules/MSNT/rfcnb-io.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/rfcnb-io.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/auth_modules/MSNT/rfcnb-io.h 26 Jan 2000 03:25:00 -0000 1.1.1.1 +++ squid/auth_modules/MSNT/rfcnb-io.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.26.1 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB IO Routines Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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); Index: squid/auth_modules/MSNT/rfcnb-priv.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/rfcnb-priv.h,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/rfcnb-priv.h 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/rfcnb-priv.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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,33 +51,33 @@ /* Structures */ -typedef struct redirect_addr * redirect_ptr; +typedef struct redirect_addr *redirect_ptr; struct redirect_addr { - struct in_addr ip_addr; - int port; - redirect_ptr next; + 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; + 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 */ +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 */ + * between architecture types where we are worried about byte order */ #define RFCNB_Pkt_Hdr_Len 4 #define RFCNB_Pkt_Sess_Len 72 @@ -85,7 +85,7 @@ #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_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,7 +95,7 @@ #define RFCNB_Pkt_Port_Offset 8 /* The next macro isolates the length of a packet, including the bit in the - flags */ + * flags */ #define RFCNB_Pkt_Len(p) (PVAL(p, 3) | (PVAL(p, 2) << 8) | \ ((PVAL(p, RFCNB_Pkt_Flags_Offset) & 0x01) << 16)) @@ -107,38 +107,38 @@ #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; */ + * + * 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,5 +146,5 @@ #ifndef RFCNB_ERRNO extern int RFCNB_errno; -extern int RFCNB_saved_errno; /* Save this from point of error */ +extern int RFCNB_saved_errno; /* Save this from point of error */ #endif Index: squid/auth_modules/MSNT/rfcnb-util.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/rfcnb-util.c,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/rfcnb-util.c 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/rfcnb-util.c 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB Utility Routines ... - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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,527 +36,520 @@ #include #include -char *RFCNB_Error_Strings[] = { +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 ..." + "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 */ +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) +void +RFCNB_CvtPad_Name(char *name1, char *name2) +{ + char c, c1, c2; + int i, len; -{ char c, c1, c2; - int i, len; + len = strlen(name1); - len = strlen(name1); + for (i = 0; i < 16; i++) { - for (i = 0; i < 16; i++) { + if (i >= len) { - if (i >= len) { + c1 = 'C'; + c2 = 'A'; /* CA is a space */ - c1 = 'C'; c2 = 'A'; /* CA is a space */ - - } else { + } else { - c = name1[i]; - c1 = (char)((int)c/16 + (int)'A'); - c2 = (char)((int)c%16 + (int)'A'); - } + 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[i * 2] = c1; + name2[i * 2 + 1] = c2; - } + } - name2[32] = 0; /* Put in the nll ...*/ + 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 ... - -*/ + * 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; +void +RFCNB_AName_To_NBName(char *AName, char *NBName) +{ + char c, c1, c2; + int i; - for (i=0; i < 16; i++) { + for (i = 0; i < 16; i++) { - c = AName[i]; + c = AName[i]; - c1 = (char)((c >> 4) + 'A'); - c2 = (char)((c & 0xF) + 'A'); + c1 = (char) ((c >> 4) + 'A'); + c2 = (char) ((c & 0xF) + 'A'); - NBName[i*2] = c1; - NBName[i*2+1] = c2; - } + NBName[i * 2] = c1; + NBName[i * 2 + 1] = c2; + } - NBName[32] = 0; /* Put in a null */ + 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; +void +RFCNB_NBName_To_AName(char *NBName, char *AName) +{ + char c, c1, c2; + int i; - for (i=0; i < 16; i++) { + for (i = 0; i < 16; i++) { - c1 = NBName[i*2]; - c2 = NBName[i*2+1]; + c1 = NBName[i * 2]; + c2 = NBName[i * 2 + 1]; - c = (char)(((int)c1 - (int)'A') * 16 + ((int)c2 - (int)'A')); + c = (char) (((int) c1 - (int) 'A') * 16 + ((int) c2 - (int) 'A')); - AName[i] = c; + AName[i] = c; - } + } - AName[i] = 0; /* Put a null on the end ... */ + 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) { +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; - 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]; + /* Print last lot in the buffer ... */ - outbuf1[j++] = c1; outbuf1[j++] = c2; + if (j > 0) { - 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"); + 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); +struct RFCNB_Pkt * +RFCNB_Alloc_Pkt(int n) +{ + RFCNB_Pkt *pkt; - } + if ((pkt = (struct RFCNB_Pkt *) malloc(sizeof(struct RFCNB_Pkt))) == NULL) { - pkt -> next = NULL; - pkt -> len = n; + RFCNB_errno = RFCNBE_NoSpace; + RFCNB_saved_errno = errno; + return (NULL); - if (n == 0) return(pkt); + } + pkt->next = NULL; + pkt->len = n; - if ((pkt -> data = (char *)malloc(n)) == NULL) { + if (n == 0) + return (pkt); - RFCNB_errno = RFCNBE_NoSpace; - RFCNB_saved_errno = errno; - free(pkt); - return(NULL); + if ((pkt->data = (char *) malloc(n)) == NULL) { - } + RFCNB_errno = RFCNBE_NoSpace; + RFCNB_saved_errno = errno; + free(pkt); + return (NULL); - return(pkt); + } + return (pkt); } /* Free up a packet */ -void RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt) - -{ struct RFCNB_Pkt *pkt_next; char *data_ptr; +void +RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt) +{ + struct RFCNB_Pkt *pkt_next; + char *data_ptr; - while (pkt != NULL) { + while (pkt != NULL) { - pkt_next = pkt -> next; + pkt_next = pkt->next; - data_ptr = pkt -> data; + data_ptr = pkt->data; - if (data_ptr != NULL) - free(data_ptr); + if (data_ptr != NULL) + free(data_ptr); - free(pkt); + free(pkt); - pkt = pkt_next; + pkt = pkt_next; - } + } } /* Print an RFCNB packet */ -void RFCNB_Print_Pkt(FILE *fd, char *dirn, struct RFCNB_Pkt *pkt, int len) - -{ char lname[17]; +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 */ + /* 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); + fprintf(fd, "RFCNB Pkt %s:", dirn); - switch (RFCNB_Pkt_Type(pkt -> data)) { + switch (RFCNB_Pkt_Type(pkt->data)) { - case RFCNB_SESSION_MESSAGE: + 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, + 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); + RFCNB_Pkt_Len(pkt->data) - RFCNB_Pkt_Hdr_Len); #else - 40); + 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); + 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: + } + break; - 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); + case RFCNB_SESSION_REQUEST: - break; + 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); - case RFCNB_SESSION_ACK: + break; - fprintf(fd, "RFCNB SESSION ACK: Length = %i\n", - RFCNB_Pkt_Len(pkt -> data)); + case RFCNB_SESSION_ACK: - break; + fprintf(fd, "RFCNB SESSION ACK: Length = %i\n", + RFCNB_Pkt_Len(pkt->data)); - case RFCNB_SESSION_REJ: - fprintf(fd, "RFCNB SESSION REJECT: Length = %i\n", - RFCNB_Pkt_Len(pkt -> data)); + break; - 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)); - } + 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; + break; - case RFCNB_SESSION_RETARGET: + case RFCNB_SESSION_RETARGET: - fprintf(fd, "RFCNB SESSION RETARGET: Length = %i\n", - RFCNB_Pkt_Len(pkt -> data)); + fprintf(fd, "RFCNB SESSION RETARGET: Length = %i\n", + RFCNB_Pkt_Len(pkt->data)); - /* Print out the IP address etc and the port? */ + /* Print out the IP address etc and the port? */ - break; + break; - case RFCNB_SESSION_KEEP_ALIVE: + case RFCNB_SESSION_KEEP_ALIVE: - fprintf(fd, "RFCNB SESSION KEEP ALIVE: Length = %i\n", - RFCNB_Pkt_Len(pkt -> data)); - break; + fprintf(fd, "RFCNB SESSION KEEP ALIVE: Length = %i\n", + RFCNB_Pkt_Len(pkt->data)); + break; default: - break; - } + break; + } } /* Resolve a name into an address */ -int RFCNB_Name_To_IP(char *host, struct in_addr *Dest_IP) +int +RFCNB_Name_To_IP(char *host, struct in_addr *Dest_IP) +{ + int addr; /* Assumes IP4, 32 bit network addresses */ + struct hostent *hp; -{ int addr; /* Assumes IP4, 32 bit network addresses */ - struct hostent *hp; + /* Use inet_addr to try to convert the address */ - /* Use inet_addr to try to convert the address */ + if ((addr = inet_addr(host)) == INADDR_NONE) { /* Oh well, a good try :-) */ - if ((addr = inet_addr(host)) == INADDR_NONE) { /* Oh well, a good try :-) */ + /* Now try a name look up with gethostbyname */ - /* Now try a name look up with gethostbyname */ + if ((hp = gethostbyname(host)) == NULL) { /* Not in DNS */ - if ((hp = gethostbyname(host)) == NULL) { /* Not in DNS */ + /* Try NetBIOS name lookup, how the hell do we do that? */ - /* 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); - RFCNB_errno = RFCNBE_BadName; /* Is this right? */ - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); + } else { /* We got a name */ - } - else { /* We got a name */ + memcpy((void *) Dest_IP, (void *) hp->h_addr_list[0], sizeof(struct in_addr)); - memcpy((void *)Dest_IP, (void *)hp -> h_addr_list[0], sizeof(struct in_addr)); + } + } else { /* It was an IP address */ - } - } - else { /* It was an IP address */ - - memcpy((void *)Dest_IP, (void *)&addr, sizeof(struct in_addr)); + memcpy((void *) Dest_IP, (void *) &addr, sizeof(struct in_addr)); - } + } - return 0; + return 0; } /* Disconnect the TCP connection to the server */ -int RFCNB_Close(int socket) - +int +RFCNB_Close(int socket) { - close(socket); + close(socket); - /* If we want to do error recovery, here is where we put it */ + /* If we want to do error recovery, here is where we put it */ - return 0; + 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) + * Not sure how to handle socket options etc. */ -{ struct sockaddr_in Socket; - int fd; - - /* Create a socket */ +int +RFCNB_IP_Connect(struct in_addr Dest_IP, int port) +{ + struct sockaddr_in Socket; + int fd; - if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { /* Handle the error */ + /* Create a socket */ - RFCNB_errno = RFCNBE_BadSocket; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); - } + if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { /* Handle the error */ - bzero((char *)&Socket, sizeof(Socket)); - memcpy((char *)&Socket.sin_addr, (char *)&Dest_IP, sizeof(Dest_IP)); + 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; + Socket.sin_port = htons(port); + Socket.sin_family = PF_INET; - /* Now connect to the destination */ + /* Now connect to the destination */ - if (connect(fd, (struct sockaddr *)&Socket, sizeof(Socket)) < 0) { /* Error */ + if (connect(fd, (struct sockaddr *) &Socket, sizeof(Socket)) < 0) { /* Error */ - close(fd); - RFCNB_errno = RFCNBE_ConnectFailed; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); + close(fd); + RFCNB_errno = RFCNBE_ConnectFailed; + RFCNB_saved_errno = errno; + return (RFCNBE_Bad); } - - return(fd); + 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 */ + * 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; - char resp[16]; - int len; - struct RFCNB_Pkt *pkt, res_pkt; + /* Response packet should be no more than 9 bytes, make 16 jic */ - /* We build and send the session request, then read the response */ + char resp[16]; + int len; + struct RFCNB_Pkt *pkt, res_pkt; - pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Sess_Len); + /* We build and send the session request, then read the response */ - if (pkt == NULL) { + pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Sess_Len); - return(RFCNBE_Bad); /* Leave the error that RFCNB_Alloc_Pkt gives) */ + 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 = 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; + 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)); + 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 */ + /* Now send the packet */ #ifdef RFCNB_DEBUG - fprintf(stderr, "Sending packet: "); - + fprintf(stderr, "Sending packet: "); + #endif - if ((len = RFCNB_Put_Pkt(con, pkt, RFCNB_Pkt_Sess_Len)) < 0) { + if ((len = RFCNB_Put_Pkt(con, pkt, RFCNB_Pkt_Sess_Len)) < 0) { - return(RFCNBE_Bad); /* Should be able to write that lot ... */ + return (RFCNBE_Bad); /* Should be able to write that lot ... */ } - #ifdef RFCNB_DEBUG - fprintf(stderr, "Getting packet.\n"); + fprintf(stderr, "Getting packet.\n"); #endif - res_pkt.data = resp; - res_pkt.len = sizeof(resp); - res_pkt.next = NULL; + res_pkt.data = resp; + res_pkt.len = sizeof(resp); + res_pkt.next = NULL; - if ((len = RFCNB_Get_Pkt(con, &res_pkt, sizeof(resp))) < 0) { + if ((len = RFCNB_Get_Pkt(con, &res_pkt, sizeof(resp))) < 0) { - return(RFCNBE_Bad); + return (RFCNBE_Bad); - } + } + /* Now analyze the packet ... */ - /* Now analyze the packet ... */ + switch (RFCNB_Pkt_Type(resp)) { - switch (RFCNB_Pkt_Type(resp)) { + case RFCNB_SESSION_REJ: /* Didnt like us ... too bad */ - case RFCNB_SESSION_REJ: /* Didnt like us ... too bad */ + /* Why did we get rejected ? */ - /* Why did we get rejected ? */ - - switch (CVAL(resp,RFCNB_Pkt_Error_Offset)) { + 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; + } - 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; + return (RFCNBE_Bad); break; - default: - RFCNB_errno = RFCNBE_ProtErr; - break; - } - - return(RFCNBE_Bad); - break; - case RFCNB_SESSION_ACK: /* Got what we wanted ... */ + case RFCNB_SESSION_ACK: /* Got what we wanted ... */ - return(0); - break; + return (0); + break; - case RFCNB_SESSION_RETARGET: /* Go elsewhere */ + case RFCNB_SESSION_RETARGET: /* Go elsewhere */ - *redirect = TRUE; /* Copy port and ip addr */ + *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); + memcpy(Dest_IP, (resp + RFCNB_Pkt_IP_Offset), sizeof(struct in_addr)); + *port = SVAL(resp, RFCNB_Pkt_Port_Offset); - return(0); - break; + return (0); + break; - default: /* A protocol error */ + default: /* A protocol error */ - RFCNB_errno = RFCNBE_ProtErr; - return(RFCNBE_Bad); - break; + RFCNB_errno = RFCNBE_ProtErr; + return (RFCNBE_Bad); + break; } } - - - - - - - - - Index: squid/auth_modules/MSNT/rfcnb-util.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/rfcnb-util.h,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/rfcnb-util.h 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/rfcnb-util.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB Utility Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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,11 +29,11 @@ void RFCNB_NBName_To_AName(char *NBName, char *AName); -void RFCNB_Print_Hex(FILE *fd, struct RFCNB_Pkt *pkt, int Offset, int Len); +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); +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,11 +41,11 @@ 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); +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); Index: squid/auth_modules/MSNT/rfcnb.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/rfcnb.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/auth_modules/MSNT/rfcnb.h 26 Jan 2000 03:25:00 -0000 1.1.1.1 +++ squid/auth_modules/MSNT/rfcnb.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.26.1 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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 */ @@ -35,7 +35,7 @@ /* Definition of routines we define */ void *RFCNB_Call(char *Called_Name, char *Calling_Name, char *Called_Address, - int port); + int port); int RFCNB_Send(void *Con_Handle, struct RFCNB_Pkt *Data, int Length); Index: squid/auth_modules/MSNT/session.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/session.c,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/session.c 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/session.c 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - Session Routines ... - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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; @@ -39,266 +39,260 @@ int RFCNB_Stats[RFCNB_MAX_STATS]; -void (*Prot_Print_Routine)() = NULL; /* Pointer to print routine */ +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; + * 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 ... */ + /* Now, we really should look up the port in /etc/services ... */ - if (port == 0) port = RFCNB_Default_Port; + if (port == 0) + port = RFCNB_Default_Port; - /* Create a connection structure first */ + /* Create a connection structure first */ - if ((con = (struct RFCNB_Con *)malloc(sizeof(struct RFCNB_Con))) == NULL) { /* Error in size */ + if ((con = (struct RFCNB_Con *) malloc(sizeof(struct RFCNB_Con))) == NULL) { /* Error in size */ - RFCNB_errno = RFCNBE_NoSpace; - RFCNB_saved_errno = errno; - return(NULL); + 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); - + 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 */ - /* Now connect to the remote end */ + /* No need to modify RFCNB_errno as it was done by RFCNB_Name_To_IP */ - redirect = TRUE; /* Fudge this one so we go once through */ + return (NULL); - while (redirect) { /* Connect and get session info etc */ + } + /* Now connect to the remote end */ - redirect = FALSE; /* Assume all OK */ + redirect = TRUE; /* Fudge this one so we go once through */ - /* Build the redirect info. First one is first addr called */ - /* And tack it onto the list of addresses we called */ + while (redirect) { /* Connect and get session info etc */ - 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); + 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 */ - memcpy((char *)&(redir_addr -> ip_addr), (char *)&Dest_IP, sizeof(Dest_IP)); - redir_addr -> port = port; - redir_addr -> next = NULL; + if ((redir_addr = (struct redirect_addr *) malloc(sizeof(struct redirect_addr))) == NULL) { /* Could not get space */ - if (con -> redirect_list == NULL) { /* Stick on head */ + RFCNB_errno = RFCNBE_NoSpace; + RFCNB_saved_errno = errno; + return (NULL); - con -> redirect_list = con -> last_addr = redir_addr; + } + memcpy((char *) &(redir_addr->ip_addr), (char *) &Dest_IP, sizeof(Dest_IP)); + redir_addr->port = port; + redir_addr->next = NULL; - } else { + if (con->redirect_list == NULL) { /* Stick on head */ - con -> last_addr -> next = redir_addr; - con -> last_addr = redir_addr; + con->redirect_list = con->last_addr = redir_addr; - } + } else { - /* Now, make that connection */ + con->last_addr->next = redir_addr; + con->last_addr = redir_addr; - if ((Client = RFCNB_IP_Connect(Dest_IP, port)) < 0) { /* Error */ + } - /* No need to modify RFCNB_errno as it was done by RFCNB_IP_Connect */ + /* Now, make that connection */ - return(NULL); + if ((Client = RFCNB_IP_Connect(Dest_IP, port)) < 0) { /* Error */ - } + /* No need to modify RFCNB_errno as it was done by RFCNB_IP_Connect */ - con -> fd = Client; + return (NULL); - /* 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 */ + } + con->fd = Client; - if ((errno = RFCNB_Session_Req(con, - Called_Name, - Calling_Name, - &redirect, &Dest_IP, &port)) < 0) { + /* 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 */ - /* No need to modify RFCNB_errno as it was done by RFCNB_Session.. */ + if ((errno = RFCNB_Session_Req(con, + Called_Name, + Calling_Name, + &redirect, &Dest_IP, &port)) < 0) { - return(NULL); + /* No need to modify RFCNB_errno as it was done by RFCNB_Session.. */ - } + return (NULL); - if (redirect) { + } + if (redirect) { - /* We have to close the connection, and then try again */ + /* We have to close the connection, and then try again */ - (con -> redirects)++; + (con->redirects)++; - RFCNB_Close(con -> fd); /* Close it */ + RFCNB_Close(con->fd); /* Close it */ - } + } } - return(con); + 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 ... */ + * 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 */ +int +RFCNB_Send(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *udata, int Length) +{ + struct RFCNB_Pkt *pkt; + char *hdr; + int len; - pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len); + /* Plug in the header and send the data */ - if (pkt == NULL) { + pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len); - RFCNB_errno = RFCNBE_NoSpace; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); + if (pkt == NULL) { - } + RFCNB_errno = RFCNBE_NoSpace; + RFCNB_saved_errno = errno; + return (RFCNBE_Bad); - pkt -> next = udata; /* The user data we want to send */ + } + pkt->next = udata; /* The user data we want to send */ - hdr = pkt -> data; + hdr = pkt->data; - /* Following crap is for portability across multiple UNIX machines */ + /* Following crap is for portability across multiple UNIX machines */ - *(hdr + RFCNB_Pkt_Type_Offset) = RFCNB_SESSION_MESSAGE; - RFCNB_Put_Pkt_Len(hdr, Length); + *(hdr + RFCNB_Pkt_Type_Offset) = RFCNB_SESSION_MESSAGE; + RFCNB_Put_Pkt_Len(hdr, Length); #ifdef RFCNB_DEBUG - fprintf(stderr, "Sending packet: "); - + fprintf(stderr, "Sending packet: "); + #endif - if ((len = RFCNB_Put_Pkt(Con_Handle, pkt, Length + RFCNB_Pkt_Hdr_Len)) < 0) { + 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 ... */ + /* No need to change RFCNB_errno as it was done by put_pkt ... */ - return(RFCNBE_Bad); /* Should be able to write that lot ... */ - - } + 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 */ + } + /* Now we have sent that lot, let's get rid of the RFCNB Header and return */ - pkt -> next = NULL; + pkt->next = NULL; - RFCNB_Free_Pkt(pkt); + RFCNB_Free_Pkt(pkt); - return(len); + 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; + * non-message packets ... */ - if (con_Handle == NULL){ - - RFCNB_errno = RFCNBE_BadHandle; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); +int +RFCNB_Recv(void *con_Handle, struct RFCNB_Pkt *Data, int Length) +{ + struct RFCNB_Pkt *pkt; + int ret_len; - } + if (con_Handle == NULL) { - /* Now get a packet from below. We allocate a header first */ + RFCNB_errno = RFCNBE_BadHandle; + RFCNB_saved_errno = errno; + return (RFCNBE_Bad); - /* Plug in the header and send the data */ + } + /* Now get a packet from below. We allocate a header first */ - pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len); + /* Plug in the header and send the data */ - if (pkt == NULL) { + pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len); - RFCNB_errno = RFCNBE_NoSpace; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); + if (pkt == NULL) { - } + RFCNB_errno = RFCNBE_NoSpace; + RFCNB_saved_errno = errno; + return (RFCNBE_Bad); - pkt -> next = Data; /* Plug in the data portion */ + } + pkt->next = Data; /* Plug in the data portion */ - if ((ret_len = RFCNB_Get_Pkt(con_Handle, pkt, Length + RFCNB_Pkt_Hdr_Len)) < 0) { + 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"); + fprintf(stderr, "Bad packet return in RFCNB_Recv... \n"); #endif - return(RFCNBE_Bad); - - } + return (RFCNBE_Bad); - /* We should check that we go a message and not a keep alive */ + } + /* We should check that we go a message and not a keep alive */ - pkt -> next = NULL; + pkt->next = NULL; - RFCNB_Free_Pkt(pkt); + RFCNB_Free_Pkt(pkt); - return(ret_len); + 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) - +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; + 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) - +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))); + return (setsockopt(con_Handle->fd, IPPROTO_TCP, TCP_NODELAY, + (char *) &yn, sizeof(yn))); } @@ -306,8 +300,8 @@ /* Listen for a connection on a port???, when */ /* the connection comes in, we return with the connection */ -void RFCNB_Listen() - +void +RFCNB_Listen() { } @@ -315,56 +309,55 @@ /* 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) - +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], + 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() - +int +RFCNB_Get_Last_Error() { - return(RFCNB_errno); + return (RFCNB_errno); } /* Pick up saved errno as well */ -int RFCNB_Get_Last_Errno() - +int +RFCNB_Get_Last_Errno() { - return(RFCNB_saved_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) - +void +RFCNB_Get_Error_Msg(int code, char *msg_buf, int len) { - strncpy(msg_buf, RFCNB_Error_Strings[abs(code)], len); + strncpy(msg_buf, RFCNB_Error_Strings[abs(code)], len); } /* Register a higher level protocol print routine */ -void RFCNB_Register_Print_Routine(void (*fn)()) - +void +RFCNB_Register_Print_Routine(void (*fn) ()) { - Prot_Print_Routine = fn; + Prot_Print_Routine = fn; } Index: squid/auth_modules/MSNT/smbdes.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/smbdes.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/auth_modules/MSNT/smbdes.c 26 Jan 2000 03:25:00 -0000 1.1.1.1 +++ squid/auth_modules/MSNT/smbdes.c 7 Jan 2001 09:48:27 -0000 1.1.1.1.26.1 @@ -1,337 +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. -*/ + * 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 < 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]; - 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); - } + 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) +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; - } + int i; + char outb[64]; + char inb[64]; + char keyb[64]; + unsigned char key2[8]; - dohash(outb, inb, keyb); + str_to_key(key, key2); - for (i=0;i<8;i++) { - out[i] = 0; - } + 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; + } - for (i=0;i<64;i++) { - if (outb[i]) - out[i/8] |= (1<<(7-(i%8))); - } + 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) +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); + 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) +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); + 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) +void +cred_hash1(unsigned char *out, unsigned char *in, unsigned char *key) { - unsigned char buf[8]; + unsigned char buf[8]; - smbhash(buf, in, key); - smbhash(out, buf, key+9); + smbhash(buf, in, key); + smbhash(out, buf, key + 9); } -void cred_hash2(unsigned char *out,unsigned char *in,unsigned char *key) +void +cred_hash2(unsigned char *out, unsigned char *in, unsigned char *key) { - unsigned char buf[8]; - static unsigned char key2[8]; + unsigned char buf[8]; + static unsigned char key2[8]; - smbhash(buf, in, key); - key2[0] = key[7]; - smbhash(out, buf, key2); + smbhash(buf, in, key); + key2[0] = key[7]; + smbhash(out, buf, key2); } - Index: squid/auth_modules/MSNT/smbencrypt.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/smbencrypt.c,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/smbencrypt.c 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/smbencrypt.c 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,24 +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. -*/ + * 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 @@ -36,37 +36,39 @@ #include "byteorder.h" -char *StrnCpy(char *dest,char *src,int n); +char *StrnCpy(char *dest, char *src, int n); void strupper(char *s); -extern void E_P16(unsigned char *,unsigned char *); +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); + * 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) +static int +_my_wcslen(int16 * str) { - int len = 0; - while(*str++ != 0) - len++; - return len; + int len = 0; + while (*str++ != 0) + len++; + return len; } /* @@ -75,129 +77,135 @@ * this must be in intel (little-endian) * format. */ - -static int _my_mbstowcs(int16 *dst, uchar *src, int len) + +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; + 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) + +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); + int len; + int16 wpwd[129]; - mdfour(p16, (unsigned char *)wpwd, len); + /* 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) + +void +SMBNTencrypt(uchar * passwd, uchar * c8, uchar * p24) { - uchar p21[21]; - - memset(p21,'\0',21); - - E_md4hash(passwd, p21); - E_P24(p21, c8, 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) +void +nt_lm_owf_gen(char *pwd, char *nt_p16, char *p16) { - char passwd[130]; - StrnCpy(passwd, pwd, sizeof(passwd)-1); + 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); + /* 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); + /* Mangle the passwords into Lanman format */ + passwd[14] = '\0'; + strupper(passwd); - /* Calculate the SMB (lanman) hash functions of the password */ + /* Calculate the SMB (lanman) hash functions of the password */ - memset(p16, '\0', 16); - E_P16((uchar *) passwd, (uchar *)p16); + 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)); + /* 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 * +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++; - } + char *d = dest; + if (!dest) + return (NULL); + if (!src) { + *dest = 0; + return (dest); } - else -#endif */ /* KANJI_WIN95_COMPATIBILITY */ - { - if (islower(*s)) - *s = toupper(*s); - s++; + 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++; + } } - } -} +} Index: squid/auth_modules/MSNT/smblib-common.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/smblib-common.h,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/smblib-common.h 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/smblib-common.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,27 +1,27 @@ /* UNIX SMBlib NetBIOS implementation - - Version 1.0 - SMBlib Common Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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,7 +76,7 @@ /* Server errors ... */ -#define SMBV_error 0x01 /* Generic error */ +#define SMBV_error 0x01 /* Generic error */ #define SMBV_badpw 0x02 #define SMBV_badtype 0x03 #define SMBV_access 0x04 @@ -141,12 +141,12 @@ /* Define the protocol types ... */ -#define SMB_P_Unknown -1 /* Hmmm, is this smart? */ +#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_DOSLanMan2 4 #define SMB_P_LanMan2 5 #define SMB_P_DOSLanMan2_1 6 #define SMB_P_LanMan2_1 7 @@ -161,28 +161,28 @@ /* 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_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 */ +#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; Index: squid/auth_modules/MSNT/smblib-priv.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/smblib-priv.h,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/smblib-priv.h 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/smblib-priv.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,27 +1,27 @@ /* UNIX SMBlib NetBIOS implementation - - Version 1.0 - SMBlib private Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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,104 +31,104 @@ #include #include -#include "byteorder.h" /* Hmmm ... hot good */ +#include "byteorder.h" /* Hmmm ... hot good */ #define max(a,b) (a < b ? b : a) -#define SMB_DEF_IDF 0x424D53FF /* "\377SMB" */ - +#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 */ +#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 */ +#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 */ +#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 */ +#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 ? */ +#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,17 +162,17 @@ /* 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_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,275 +184,275 @@ #define SMB_hdr_mid_offset 30 #define SMB_hdr_wct_offset 32 -#define SMB_hdr_len 33 /* 33 byte header? */ +#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 */ +#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 */ +#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_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_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_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_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 */ +#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_tdis_bcc_offset 33 /* bcc */ +#define SMB_tdis_len 35 /* total len */ -#define SMB_tdisr_bcc_offset 33 /* bcc */ +#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_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_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_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_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_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_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 */ +#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_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_creat_len 41 /* Before the data */ -#define SMB_creatr_fid_offset 33 /* FID of created file */ +#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_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_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_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 */ +#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_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_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_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_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_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 */ +#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_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_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_pdi_offset 43 /* parameter displacement */ #define SMB_transr_dbc_offset 45 #define SMB_transr_dbo_offset 47 #define SMB_transr_ddi_offset 49 @@ -477,17 +477,23 @@ #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; +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 ... */ @@ -498,56 +504,56 @@ typedef struct SMB_Status { - union { - struct { - unsigned char ErrorClass; - unsigned char Reserved; - unsigned short Error; - } DosError; - unsigned int NtStatus; - } 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_Tree_Structure *SMB_Tree_Handle; -typedef struct SMB_Connect_Def * SMB_Handle_Type; +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]; + 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,12 +569,12 @@ 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; + SMB_Tree_Handle next, prev; + SMB_Handle_Type con; + char path[129]; + char device_type[20]; + int mbs; /* Local MBS */ + int tid; }; @@ -576,13 +582,13 @@ 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; + 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,7 +598,7 @@ #ifndef SMBLIB_ERRNO extern int SMBlib_errno; -extern int SMBlib_SMB_Error; /* last Error */ +extern int SMBlib_SMB_Error; /* last Error */ #endif #endif /* _SMBLIB_PRIV_H_ */ Index: squid/auth_modules/MSNT/smblib-util.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/smblib-util.c,v retrieving revision 1.1.1.1.10.1.2.1 retrieving revision 1.1.1.1.10.1.2.2 diff -u -r1.1.1.1.10.1.2.1 -r1.1.1.1.10.1.2.2 --- squid/auth_modules/MSNT/smblib-util.c 7 Jan 2001 07:44:23 -0000 1.1.1.1.10.1.2.1 +++ squid/auth_modules/MSNT/smblib-util.c 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.2 @@ -1,27 +1,27 @@ /* UNIX SMBlib NetBIOS implementation - - Version 1.0 - SMBlib Utility Routines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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" @@ -33,160 +33,160 @@ #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}; +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) - +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 */ + /* Well, just how do we do this ... print it I suppose */ - /* Print out the SMB header ... */ + /* Print out the SMB header ... */ - /* Print the command */ + /* Print the command */ - /* Print the other bits in the header */ + /* Print the other bits in the header */ - /* etc */ + /* 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; +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; + SMB_Time_Temp[0] = 0; - DOS_sec = (DOS_time & 0x001F) * 2; - DOS_min = (DOS_time & 0x07E0) >> 5; - DOS_hour = ((DOS_time & 0xF800) >> 11); + 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; + 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); + 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); + 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) + * to a static string which we guarantee is long enough. If verbose is + * true, we print out long form of strings ... */ -{ static char SMB_Attrib_Temp[128]; +char * +SMB_AtrToStr(int attribs, BOOL verbose) +{ + static char SMB_Attrib_Temp[128]; - SMB_Attrib_Temp[0] = 0; + SMB_Attrib_Temp[0] = 0; - if (attribs & SMB_FA_ROF) - strcat(SMB_Attrib_Temp, (verbose?"Read Only ":"R")); + 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_HID) + strcat(SMB_Attrib_Temp, (verbose ? "Hidden " : "H")); - if (attribs & SMB_FA_SYS) - strcat(SMB_Attrib_Temp, (verbose?"System ":"S")); + 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_VOL) + strcat(SMB_Attrib_Temp, (verbose ? "Volume " : "V")); - if (attribs & SMB_FA_DIR) - strcat(SMB_Attrib_Temp, (verbose?"Directory ":"D")); + if (attribs & SMB_FA_DIR) + strcat(SMB_Attrib_Temp, (verbose ? "Directory " : "D")); - if (attribs & SMB_FA_ARC) - strcat(SMB_Attrib_Temp, (verbose?"Archive ":"A")); + if (attribs & SMB_FA_ARC) + strcat(SMB_Attrib_Temp, (verbose ? "Archive " : "A")); - return(SMB_Attrib_Temp); + return (SMB_Attrib_Temp); } /* Pick up the Max Buffer Size from the Tree Structure ... */ -int SMB_Get_Tree_MBS(SMB_Tree_Handle tree) - +int +SMB_Get_Tree_MBS(SMB_Tree_Handle tree) { - if (tree != NULL) { - return(tree -> mbs); - } - else { - return(SMBlibE_BAD); - } + 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) - +int +SMB_Get_Max_Buf_Siz(SMB_Handle_Type Con_Handle) { - if (Con_Handle != NULL) { - return(Con_Handle -> max_xmit); - } - else { - return(SMBlibE_BAD); - } + 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) - +int +SMB_Get_Protocol_IDX(SMB_Handle_Type Con_Handle) { - if (Con_Handle != NULL) { - return(Con_Handle -> prot_IDX); - } - else { - return(0xFFFF); /* Invalid protocol */ - } + 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) - +int +SMB_Get_Protocol(SMB_Handle_Type Con_Handle) { - if (Con_Handle != NULL) { - return(Con_Handle -> protocol); - } - else { - return(0xFFFF); /* Invalid protocol */ - } + if (Con_Handle != NULL) { + return (Con_Handle->protocol); + } else { + return (0xFFFF); /* Invalid protocol */ + } } @@ -194,32 +194,31 @@ /* 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 */ +int +SMB_Figure_Protocol(char *dialects[], int prot_index) +{ + int i; - return(SMB_Types[prot_index]); - } - else { /* Search through SMB_Prots looking for a match */ + if (dialects == SMB_Prots) { /* The jobs is easy, just index into table */ - for (i = 0; SMB_Prots[i] != NULL; i++) { + return (SMB_Types[prot_index]); + } else { /* Search through SMB_Prots looking for a match */ - if (strcmp(dialects[prot_index], SMB_Prots[i]) == 0) { /* A match */ + for (i = 0; SMB_Prots[i] != NULL; i++) { - return(SMB_Types[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 ... */ + /* If we got here, then we are in trouble, because the protocol was not */ + /* One we understand ... */ - return(SMB_P_Unknown); + return (SMB_P_Unknown); - } + } } @@ -228,536 +227,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, char *Prots[]) +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 */ + struct RFCNB_Pkt *pkt; + int prots_len, i, pkt_len, prot, alloc_len; + char *p; - prots_len = 0; + /* Figure out how long the prot list will be and allocate space for it */ - for (i = 0; Prots[i] != NULL; i++) { + prots_len = 0; - prots_len = prots_len + strlen(Prots[i]) + 2; /* Account for null etc */ + 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; + /* The -1 accounts for the one byte smb_buf we have because some systems */ + /* don't like char msg_buf[] */ - /* 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 */ + pkt_len = SMB_negp_len + prots_len; - if (pkt_len < (SMB_hdr_wct_offset + (19 * 2) + 40)) { + /* 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 */ - alloc_len = SMB_hdr_wct_offset + (19 * 2) + 40; + if (pkt_len < (SMB_hdr_wct_offset + (19 * 2) + 40)) { - } - else { + alloc_len = SMB_hdr_wct_offset + (19 * 2) + 40; - alloc_len = pkt_len; + } else { - } + alloc_len = pkt_len; - pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(alloc_len); + } - if (pkt == NULL) { + pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(alloc_len); - SMBlib_errno = SMBlibE_NoSpace; - return(SMBlibE_BAD); + if (pkt == NULL) { - } + SMBlib_errno = SMBlibE_NoSpace; + return (SMBlibE_BAD); - /* Now plug in the bits we need */ + } + /* 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; + 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); + SSVAL(SMB_Hdr(pkt), SMB_negp_bcc_offset, prots_len); - /* Now copy the prot strings in with the right stuff */ + /* Now copy the prot strings in with the right stuff */ - p = (char *)(SMB_Hdr(pkt) + SMB_negp_buf_offset); + p = (char *) (SMB_Hdr(pkt) + SMB_negp_buf_offset); - for (i = 0; Prots[i] != NULL; i++) { + 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 */ + *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 ... */ + /* Now send the packet and sit back ... */ - if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0){ + if (RFCNB_Send(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error sending negotiate protocol\n"); + fprintf(stderr, "Error sending negotiate protocol\n"); #endif - RFCNB_Free_Pkt(pkt); - SMBlib_errno = -SMBlibE_SendFailed; /* Failed, check lower layer errno */ - return(SMBlibE_BAD); - - } + RFCNB_Free_Pkt(pkt); + SMBlib_errno = -SMBlibE_SendFailed; /* Failed, check lower layer errno */ + return (SMBlibE_BAD); - /* Now get the response ... */ + } + /* Now get the response ... */ - if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, alloc_len) < 0) { + if (RFCNB_Recv(Con_Handle->Trans_Connect, pkt, alloc_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error receiving response to negotiate\n"); + 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); - - } + 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 */ + } + 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", + 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); + 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) { + } + if (SVAL(SMB_Hdr(pkt), SMB_negrCP_idx_offset) == 0xFFFF) { #ifdef DEBUG - fprintf(stderr, "None of our protocols was accepted ... "); + fprintf(stderr, "None of our protocols was accepted ... "); #endif - RFCNB_Free_Pkt(pkt); - SMBlib_errno = SMBlibE_NegNoProt; - return(SMBlibE_BAD); + 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 ... */ - /* 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); - 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 ... */ - if (Con_Handle -> protocol == SMB_P_Unknown) { /* No good ... */ + RFCNB_Free_Pkt(pkt); + SMBlib_errno = SMBlibE_ProtUnknown; + return (SMBlibE_BAD); - RFCNB_Free_Pkt(pkt); - SMBlib_errno = SMBlibE_ProtUnknown; - return(SMBlibE_BAD); + } + switch (CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)) { - } - - switch (CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)) { + case 0x01: /* No more info ... */ - case 0x01: /* No more info ... */ + break; - break; + case 13: /* Up to and including LanMan 2.1 */ - 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 -> 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); - 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); + 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); + 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); + strncpy(p, Con_Handle->Svr_PDom, sizeof(Con_Handle->Svr_PDom) - 1); - break; + break; - case 17: /* NT LM 0.12 and LN LM 1.0 */ + 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->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); + 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); + 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); + strncpy(p, Con_Handle->Svr_PDom, sizeof(Con_Handle->Svr_PDom) - 1); - break; + break; - default: + default: #ifdef DEBUG - fprintf(stderr, "Unknown NegProt response format ... Ignored\n"); - fprintf(stderr, " wct = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)); + fprintf(stderr, "Unknown NegProt response format ... Ignored\n"); + fprintf(stderr, " wct = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)); #endif - break; - } + break; + } #ifdef DEBUG - fprintf(stderr, "Protocol selected is: %i:%s\n", prot, Prots[prot]); + fprintf(stderr, "Protocol selected is: %i:%s\n", prot, Prots[prot]); #endif - RFCNB_Free_Pkt(pkt); - return(0); + RFCNB_Free_Pkt(pkt); + return (0); } /* Get our hostname */ -void SMB_Get_My_Name(char *name, int len) - +void +SMB_Get_My_Name(char *name, int len) { - if (gethostname(name, len) < 0) { /* Error getting name */ + if (gethostname(name, len) < 0) { /* Error getting name */ - strncpy(name, "unknown", len); + strncpy(name, "unknown", len); - /* Should check the error */ + /* Should check the error */ #ifdef DEBUG - fprintf(stderr, "gethostname in SMB_Get_My_Name returned error:"); - perror(""); + fprintf(stderr, "gethostname in SMB_Get_My_Name returned error:"); + perror(""); #endif - } - - /* only keep the portion up to the first "." */ + } + /* 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; +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 ... */ + /* Figure out how much space is needed for path, password, dev ... */ - if ((path == NULL) | (password == NULL) | (device == NULL)) { + if ((path == NULL) | (password == NULL) | (device == NULL)) { #ifdef DEBUG - fprintf(stderr, "Bad parameter passed to SMB_TreeConnect\n"); + fprintf(stderr, "Bad parameter passed to SMB_TreeConnect\n"); #endif - SMBlib_errno = SMBlibE_BadParam; - return(NULL); + SMBlib_errno = SMBlibE_BadParam; + return (NULL); - } + } + /* The + 2 is because of the \0 and the marker ... */ - /* The + 2 is because of the \0 and the marker ... */ + param_len = strlen(path) + 2 + strlen(password) + 2 + strlen(device) + 2; - 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[] */ - /* 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_len = SMB_tcon_len + param_len; + pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len); - pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len); + if (pkt == NULL) { - if (pkt == NULL) { + SMBlib_errno = SMBlibE_NoSpace; + return (NULL); /* Should handle the error */ - SMBlib_errno = SMBlibE_NoSpace; - return(NULL); /* Should handle the error */ + } + /* Now allocate a tree for this to go into ... */ - } + if (Tree_Handle == NULL) { - /* Now allocate a tree for this to go into ... */ + tree = (SMB_Tree_Handle) malloc(sizeof(struct SMB_Tree_Structure)); - if (Tree_Handle == NULL) { + if (tree == NULL) { - tree = (SMB_Tree_Handle)malloc(sizeof(struct SMB_Tree_Structure)); + RFCNB_Free_Pkt(pkt); + SMBlib_errno = SMBlibE_NoSpace; + return (NULL); - if (tree == NULL) { - - RFCNB_Free_Pkt(pkt); - SMBlib_errno = SMBlibE_NoSpace; - return(NULL); - - } - } - else { + } + } else { - tree = Tree_Handle; + 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)); + 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 ... */ + /* 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; + 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); + SSVAL(SMB_Hdr(pkt), SMB_tcon_bcc_offset, param_len); - /* Now copy the param strings in with the right stuff */ + /* 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); + 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 ... */ + /* Now send the packet and sit back ... */ - if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0){ + if (RFCNB_Send(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error sending TCon request\n"); + fprintf(stderr, "Error sending TCon request\n"); #endif - if (Tree_Handle == NULL) - free(tree); - RFCNB_Free_Pkt(pkt); - SMBlib_errno = -SMBlibE_SendFailed; - return(NULL); - - } + if (Tree_Handle == NULL) + free(tree); + RFCNB_Free_Pkt(pkt); + SMBlib_errno = -SMBlibE_SendFailed; + return (NULL); - /* Now get the response ... */ + } + /* Now get the response ... */ - if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) { + if (RFCNB_Recv(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error receiving response to TCon\n"); + 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); + if (Tree_Handle == NULL) + free(tree); + RFCNB_Free_Pkt(pkt); + SMBlib_errno = -SMBlibE_RecvFailed; + return (NULL); - } - - /* Check out the response type ... */ + } + /* Check out the response type ... */ - if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ + 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", + 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); - - } + 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); + } + 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); + fprintf(stderr, "TConn succeeded, with TID=%i, Max Xmit=%i\n", + tree->tid, tree->mbs); #endif - /* Now link the Tree to the Server Structure ... */ + /* Now link the Tree to the Server Structure ... */ - if (Con_Handle -> first_tree == NULL) { + if (Con_Handle->first_tree == NULL) { - Con_Handle -> first_tree = tree; - Con_Handle -> last_tree = tree; + Con_Handle->first_tree = tree; + Con_Handle->last_tree = tree; - } - else { + } else { - Con_Handle -> last_tree -> next = tree; - tree -> prev = Con_Handle -> last_tree; - Con_Handle -> last_tree = tree; + Con_Handle->last_tree->next = tree; + tree->prev = Con_Handle->last_tree; + Con_Handle->last_tree = tree; - } + } - RFCNB_Free_Pkt(pkt); - return(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; +int +SMB_TreeDisconnect(SMB_Tree_Handle Tree_Handle, BOOL discard) +{ + struct RFCNB_Pkt *pkt; + int pkt_len; - pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len); + pkt_len = SMB_tdis_len; - if (pkt == NULL) { + pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len); - SMBlib_errno = SMBlibE_NoSpace; - return(SMBlibE_BAD); /* Should handle the error */ + if (pkt == NULL) { - } + SMBlib_errno = SMBlibE_NoSpace; + return (SMBlibE_BAD); /* Should handle the error */ - /* Now plug in the values ... */ + } + /* 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; + 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); + 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 ... */ + /* Now send the packet and sit back ... */ - if (RFCNB_Send(Tree_Handle -> con -> Trans_Connect, pkt, pkt_len) < 0){ + if (RFCNB_Send(Tree_Handle->con->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error sending TDis request\n"); + fprintf(stderr, "Error sending TDis request\n"); #endif - RFCNB_Free_Pkt(pkt); - SMBlib_errno = -SMBlibE_SendFailed; - return(SMBlibE_BAD); - - } + RFCNB_Free_Pkt(pkt); + SMBlib_errno = -SMBlibE_SendFailed; + return (SMBlibE_BAD); - /* Now get the response ... */ + } + /* Now get the response ... */ - if (RFCNB_Recv(Tree_Handle -> con -> Trans_Connect, pkt, pkt_len) < 0) { + if (RFCNB_Recv(Tree_Handle->con->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error receiving response to TCon\n"); + fprintf(stderr, "Error receiving response to TCon\n"); #endif - RFCNB_Free_Pkt(pkt); - SMBlib_errno = -SMBlibE_RecvFailed; - return(SMBlibE_BAD); + RFCNB_Free_Pkt(pkt); + SMBlib_errno = -SMBlibE_RecvFailed; + return (SMBlibE_BAD); - } - - /* Check out the response type ... */ + } + /* Check out the response type ... */ - if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ + 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", + 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); - - } + 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 */ + } + Tree_Handle->tid = 0xFFFF; /* Invalid TID */ + Tree_Handle->mbs = 0; /* Invalid */ #ifdef DEBUG - fprintf(stderr, "Tree disconnect successful ...\n"); + fprintf(stderr, "Tree disconnect successful ...\n"); #endif - /* What about the tree handle ? */ + /* What about the tree handle ? */ - if (discard == TRUE) { /* Unlink it and free it ... */ + 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->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; + 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); + } + RFCNB_Free_Pkt(pkt); + return (0); } /* Pick up the last LMBlib error ... */ -int SMB_Get_Last_Error() - +int +SMB_Get_Last_Error() { - return(SMBlib_errno); + 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() - +int +SMB_Get_Last_SMB_Err() { - return(SMBlib_SMB_Error); + return (SMBlib_SMB_Error); } @@ -765,57 +747,57 @@ /* Keep this table in sync with the message codes in smblib-common.h */ -static char *SMBlib_Error_Messages[] = { +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.", + "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) + "No such error code.", + NULL}; +void +SMB_Get_Error_Msg(int msg, char *msgbuf, int len) { - if (msg >= 0) { + if (msg >= 0) { - strncpy(msgbuf, - SMBlib_Error_Messages[msg>SMBlibE_NoSuchMsg?SMBlibE_NoSuchMsg:msg], + 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 ... */ + msgbuf[len - 1] = 0; /* Make sure it is a string */ + } else { /* Add the lower layer message ... */ - char prot_msg[1024]; + char prot_msg[1024]; - msg = -msg; /* Make it positive */ + msg = -msg; /* Make it positive */ - strncpy(msgbuf, - SMBlib_Error_Messages[msg>SMBlibE_NoSuchMsg?SMBlibE_NoSuchMsg:msg], + strncpy(msgbuf, + SMBlib_Error_Messages[msg > SMBlibE_NoSuchMsg ? SMBlibE_NoSuchMsg : msg], len - 1); - msgbuf[len - 1] = 0; /* make sure it is a string */ + msgbuf[len - 1] = 0; /* make sure it is a string */ - if (strlen(msgbuf) < len) { /* If there is space, put rest in */ + if (strlen(msgbuf) < len) { /* If there is space, put rest in */ - strncat(msgbuf, "\n\t", len - strlen(msgbuf)); + strncat(msgbuf, "\n\t", len - strlen(msgbuf)); - RFCNB_Get_Error(prot_msg, sizeof(prot_msg) - 1); + RFCNB_Get_Error(prot_msg, sizeof(prot_msg) - 1); - strncat(msgbuf, prot_msg, len - strlen(msgbuf)); + strncat(msgbuf, prot_msg, len - strlen(msgbuf)); + } } - } } Index: squid/auth_modules/MSNT/smblib.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/smblib.c,v retrieving revision 1.1.1.1.10.2.2.1 retrieving revision 1.1.1.1.10.2.2.2 diff -u -r1.1.1.1.10.2.2.1 -r1.1.1.1.10.2.2.2 --- squid/auth_modules/MSNT/smblib.c 7 Jan 2001 07:44:23 -0000 1.1.1.1.10.2.2.1 +++ squid/auth_modules/MSNT/smblib.c 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.2.2.2 @@ -1,27 +1,27 @@ /* UNIX SMBlib NetBIOS implementation - - Version 1.0 - SMBlib Routines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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; @@ -47,155 +47,152 @@ /* Initialize the SMBlib package */ -int SMB_Init() - +int +SMB_Init() { - SMBlib_State = SMB_State_Started; + SMBlib_State = SMB_State_Started; - signal(SIGPIPE, SIG_IGN); /* Ignore these ... */ + signal(SIGPIPE, SIG_IGN); /* Ignore these ... */ /* If SMBLIB_Instrument is defines, turn on the instrumentation stuff */ #ifdef SMBLIB_INSTRUMENT - SMBlib_Instrument_Init(); + SMBlib_Instrument_Init(); #endif - return 0; + return 0; } -int SMB_Term() - +int +SMB_Term() { #ifdef SMBLIB_INSTRUMENT - SMBlib_Instrument_Term(); /* Clean up and print results */ + SMBlib_Instrument_Term(); /* Clean up and print results */ #endif - return 0; + 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) - +SMB_Handle_Type +SMB_Create_Con_Handle(void) { - SMBlib_errno = SMBlibE_NotImpl; - return(NULL); + SMBlib_errno = SMBlibE_NotImpl; + return (NULL); } -int SMBlib_Set_Sock_NoDelay(SMB_Handle_Type Con_Handle, BOOL yn) - +int +SMBlib_Set_Sock_NoDelay(SMB_Handle_Type Con_Handle, BOOL yn) { - if (RFCNB_Set_Sock_NoDelay(Con_Handle -> Trans_Connect, yn) < 0) { + if (RFCNB_Set_Sock_NoDelay(Con_Handle->Trans_Connect, yn) < 0) { #ifdef DEBUG #endif - fprintf(stderr, "Setting no-delay on TCP socket failed ...\n"); - - } + fprintf(stderr, "Setting no-delay on TCP socket failed ...\n"); - return(0); + } + 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; +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 */ + /* Get a connection structure if one does not exist */ - con = Con_Handle; + con = Con_Handle; - if (Con_Handle == NULL) { + if (Con_Handle == NULL) { - if ((con = (struct SMB_Connect_Def *)malloc(sizeof(struct SMB_Connect_Def))) == NULL) { + if ((con = (struct SMB_Connect_Def *) malloc(sizeof(struct SMB_Connect_Def))) == NULL) { - SMBlib_errno = SMBlibE_NoSpace; - return 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; - /* Init some things ... */ + SMB_Get_My_Name(con->myname, sizeof(con->myname)); - 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; + con->port = 0; /* No port selected */ - SMB_Get_My_Name(con -> myname, sizeof(con -> myname)); + /* Get some things we need for the SMB Header */ - con -> port = 0; /* No port selected */ + 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(); - /* Get some things we need for the SMB Header */ + /* 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 */ - 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(); + for (i = 0; i < strlen(server); i++) + called[i] = toupper(server[i]); - /* 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 */ + called[strlen(server)] = 0; /* Make it a string */ - 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]); - for (i=0; i < strlen(con -> myname); i++) - calling[i] = toupper(con -> myname[i]); - - calling[strlen(con -> myname)] = 0; /* Make it a string */ + calling[strlen(con->myname)] = 0; /* Make it a string */ - if (strcmp(con -> address, "") == 0) - address = con -> desthost; - else - address = con -> address; + if (strcmp(con->address, "") == 0) + address = con->desthost; + else + address = con->address; - con -> Trans_Connect = RFCNB_Call(called, - calling, - address, /* Protocol specific */ - con -> port); + con->Trans_Connect = RFCNB_Call(called, + calling, + address, /* Protocol specific */ + con->port); - /* Did we get one? */ + /* Did we get one? */ - if (con -> Trans_Connect == NULL) { + if (con->Trans_Connect == NULL) { - if (Con_Handle == NULL) { - Con_Handle = NULL; - free(con); - } - SMBlib_errno = -SMBlibE_CallFailed; - return NULL; - - } + if (Con_Handle == NULL) { + Con_Handle = NULL; + free(con); + } + SMBlib_errno = -SMBlibE_CallFailed; + return NULL; - return(con); + } + return (con); } @@ -203,367 +200,356 @@ /* 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}; - +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; +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 */ + /* Get a connection structure if one does not exist */ - con = Con_Handle; + con = Con_Handle; - if (Con_Handle == NULL) { + if (Con_Handle == NULL) { - if ((con = (struct SMB_Connect_Def *)malloc(sizeof(struct SMB_Connect_Def))) == NULL) { + if ((con = (struct SMB_Connect_Def *) malloc(sizeof(struct SMB_Connect_Def))) == NULL) { - SMBlib_errno = SMBlibE_NoSpace; - return NULL; + SMBlib_errno = SMBlibE_NoSpace; + return NULL; + } } + /* Init some things ... */ - } - - /* 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; + 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)); + SMB_Get_My_Name(con->myname, sizeof(con->myname)); - con -> port = 0; /* No port selected */ + con->port = 0; /* No port selected */ - /* Get some things we need for the SMB Header */ + /* 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(); + 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 */ + /* 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); + 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 */ + /* 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(host); i++) + called[i] = toupper(host[i]); - for (i=0; i < strlen(con -> myname); i++) - calling[i] = toupper(con -> myname[i]); - - calling[strlen(con -> myname)] = 0; /* Make it a string */ + called[strlen(host)] = 0; /* Make it a string */ - if (strcmp(con -> address, "") == 0) - address = con -> desthost; - else - address = con -> address; + for (i = 0; i < strlen(con->myname); i++) + calling[i] = toupper(con->myname[i]); - con -> Trans_Connect = RFCNB_Call(called, - calling, - address, /* Protocol specific */ - con -> port); + calling[strlen(con->myname)] = 0; /* Make it a string */ - /* Did we get one? */ + if (strcmp(con->address, "") == 0) + address = con->desthost; + else + address = con->address; - if (con -> Trans_Connect == NULL) { - - if (Con_Handle == NULL) { - free(con); - Con_Handle = NULL; - } - SMBlib_errno = -SMBlibE_CallFailed; - return NULL; + con->Trans_Connect = RFCNB_Call(called, + calling, + address, /* Protocol specific */ + con->port); - } + /* Did we get one? */ - /* Now, negotiate the protocol */ + if (con->Trans_Connect == NULL) { - if (SMB_Negotiate(con, SMB_Prots_Restrict) < 0) { + if (Con_Handle == NULL) { + free(con); + Con_Handle = NULL; + } + SMBlib_errno = -SMBlibE_CallFailed; + return NULL; - /* Hmmm what should we do here ... We have a connection, but could not - negotiate ... */ + } + /* Now, negotiate the protocol */ - return NULL; + if (SMB_Negotiate(con, SMB_Prots_Restrict) < 0) { - } + /* Hmmm what should we do here ... We have a connection, but could not + * negotiate ... */ - /* Now connect to the service ... */ + return NULL; - if ((*tree = SMB_TreeConnect(con, NULL, service, password, "A:")) == NULL) { + } + /* Now connect to the service ... */ - return NULL; + if ((*tree = SMB_TreeConnect(con, NULL, service, password, "A:")) == NULL) { - } + return NULL; - return(con); + } + 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) { +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 ... */ - SMBlib_errno = SMBlibE_ProtLow; - return(SMBlibE_BAD); + if (Con_Handle->protocol < SMB_P_LanMan1) { - } + SMBlib_errno = SMBlibE_ProtLow; + return (SMBlibE_BAD); - strcpy(pword, PassWord); + } + 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 + if (Con_Handle->encrypt_passwords) { + pass_len = 24; + SMBencrypt((uchar *) PassWord, (uchar *) Con_Handle->Encrypt_Key, (uchar *) pword); + } else #endif - pass_len=strlen(pword); - + pass_len = strlen(pword); - /* Now build the correct structure */ - if (Con_Handle -> protocol < SMB_P_NT1) { + /* Now build the correct structure */ - param_len = strlen(UserName) + 1 + pass_len + 1 + - strlen(Con_Handle -> PDomain) + 1 + - strlen(Con_Handle -> OSName) + 1; + if (Con_Handle->protocol < SMB_P_NT1) { - pkt_len = SMB_ssetpLM_len + param_len; + param_len = strlen(UserName) + 1 + pass_len + 1 + + strlen(Con_Handle->PDomain) + 1 + + strlen(Con_Handle->OSName) + 1; - pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len); + pkt_len = SMB_ssetpLM_len + param_len; - if (pkt == NULL) { + pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len); - SMBlib_errno = SMBlibE_NoSpace; - return(SMBlibE_BAD); /* Should handle the error */ + if (pkt == NULL) { - } - - 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); + SMBlib_errno = SMBlibE_NoSpace; + return (SMBlibE_BAD); /* Should handle the error */ - 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); + } + 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); - /* Now copy the param strings in with the right stuff */ + 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); - p = (char *)(SMB_Hdr(pkt) + SMB_ssetpLM_buf_offset); + /* Now copy the param strings in with the right stuff */ - /* Copy in password, then the rest. Password has a null at end */ + p = (char *) (SMB_Hdr(pkt) + SMB_ssetpLM_buf_offset); - memcpy(p, pword, pass_len); + /* Copy in password, then the rest. Password has a null at end */ - p = p + pass_len + 1; + memcpy(p, pword, pass_len); - strcpy(p, UserName); - p = p + strlen(UserName); - *p = 0; + p = p + pass_len + 1; - p = p + 1; + strcpy(p, UserName); + p = p + strlen(UserName); + *p = 0; - strcpy(p, Con_Handle -> PDomain); - p = p + strlen(Con_Handle -> PDomain); - *p = 0; - p = p + 1; + p = p + 1; - strcpy(p, Con_Handle -> OSName); - p = p + strlen(Con_Handle -> OSName); - *p = 0; + strcpy(p, Con_Handle->PDomain); + p = p + strlen(Con_Handle->PDomain); + *p = 0; + p = p + 1; - } - else { + strcpy(p, Con_Handle->OSName); + p = p + strlen(Con_Handle->OSName); + *p = 0; - /* We don't admit to UNICODE support ... */ + } else { - param_len = strlen(UserName) + 1 + pass_len + - strlen(Con_Handle -> PDomain) + 1 + - strlen(Con_Handle -> OSName) + 1 + - strlen(Con_Handle -> LMType) + 1; + /* We don't admit to UNICODE support ... */ - pkt_len = SMB_ssetpNTLM_len + param_len; + param_len = strlen(UserName) + 1 + pass_len + + strlen(Con_Handle->PDomain) + 1 + + strlen(Con_Handle->OSName) + 1 + + strlen(Con_Handle->LMType) + 1; - pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len); + pkt_len = SMB_ssetpNTLM_len + param_len; - if (pkt == NULL) { + pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len); - SMBlib_errno = SMBlibE_NoSpace; - return(-1); /* Should handle the error */ + 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); + } + 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); + 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 */ + /* Now copy the param strings in with the right stuff */ - p = (char *)(SMB_Hdr(pkt) + SMB_ssetpNTLM_buf_offset); + p = (char *) (SMB_Hdr(pkt) + SMB_ssetpNTLM_buf_offset); - /* Copy in password, then the rest. Password has no null at end */ + /* Copy in password, then the rest. Password has no null at end */ - memcpy(p, pword, pass_len); + memcpy(p, pword, pass_len); - p = p + pass_len; + p = p + pass_len; - strcpy(p, UserName); - p = p + strlen(UserName); - *p = 0; + strcpy(p, UserName); + p = p + strlen(UserName); + *p = 0; - p = p + 1; + p = p + 1; - strcpy(p, Con_Handle -> PDomain); - p = p + strlen(Con_Handle -> PDomain); - *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->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; + strcpy(p, Con_Handle->LMType); + p = p + strlen(Con_Handle->LMType); + *p = 0; - } + } - /* Now send it and get a response */ + /* Now send it and get a response */ - if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0){ + if (RFCNB_Send(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error sending SessSetupX request\n"); + fprintf(stderr, "Error sending SessSetupX request\n"); #endif - RFCNB_Free_Pkt(pkt); - SMBlib_errno = SMBlibE_SendFailed; - return(SMBlibE_BAD); - - } + RFCNB_Free_Pkt(pkt); + SMBlib_errno = SMBlibE_SendFailed; + return (SMBlibE_BAD); - /* Now get the response ... */ + } + /* Now get the response ... */ - if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) { + if (RFCNB_Recv(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error receiving response to SessSetupAndX\n"); + fprintf(stderr, "Error receiving response to SessSetupAndX\n"); #endif - RFCNB_Free_Pkt(pkt); - SMBlib_errno = SMBlibE_RecvFailed; - return(SMBlibE_BAD); - - } + RFCNB_Free_Pkt(pkt); + SMBlib_errno = SMBlibE_RecvFailed; + return (SMBlibE_BAD); - /* Check out the response type ... */ + } + /* Check out the response type ... */ - if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ + 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", + 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); - - } + 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)); + fprintf(stderr, "SessSetupAndX response. Action = %i\n", + SVAL(SMB_Hdr(pkt), SMB_ssetpr_act_offset)); #endif - /* Now pick up the UID for future reference ... */ + /* Now pick up the UID for future reference ... */ - Con_Handle -> uid = SVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset); - RFCNB_Free_Pkt(pkt); + Con_Handle->uid = SVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset); + RFCNB_Free_Pkt(pkt); - return(0); + return (0); } /* Disconnect from the server, and disconnect all tree connects */ -int SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle) - +int +SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle) { - /* We just disconnect the connection for now ... */ + /* We just disconnect the connection for now ... */ - RFCNB_Hangup(Con_Handle -> Trans_Connect); + RFCNB_Hangup(Con_Handle->Trans_Connect); - if (!KeepHandle) - free(Con_Handle); + if (!KeepHandle) + free(Con_Handle); - return(0); + return (0); } Index: squid/auth_modules/MSNT/smblib.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/smblib.h,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/smblib.h 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/smblib.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,27 +1,27 @@ /* UNIX SMBlib NetBIOS implementation - - Version 1.0 - SMBlib Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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" @@ -40,10 +40,10 @@ /* 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); + SMB_Tree_Handle * tree, + char *service, + char *username, + char *password); /* Negotiate a protocol */ @@ -51,8 +51,8 @@ /* Connect to a tree ... */ -void *SMB_TreeConnect(void *con_handle, void *tree_handle, - char *path, char *password, char *dev); +void *SMB_TreeConnect(void *con_handle, void *tree_handle, + char *path, char *password, char *dev); /* Disconnect a tree ... */ @@ -61,10 +61,10 @@ /* Open a file */ void *SMB_Open(void *tree_handle, - void *file_handle, - char *file_name, - unsigned short mode, - unsigned short search); + void *file_handle, + char *file_name, + unsigned short mode, + unsigned short search); /* Close a file */ @@ -76,9 +76,9 @@ int SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle); void *SMB_Create(void *Tree_Handle, - void *File_Handle, - char *file_name, - short search); + void *File_Handle, + char *file_name, + short search); int SMB_Delete(void *tree, char *file_name, short search); @@ -95,4 +95,4 @@ 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); + char *service, char *st); Index: squid/auth_modules/MSNT/std-defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/std-defines.h,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/std-defines.h 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/std-defines.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,27 +1,27 @@ /* RFCNB Standard includes ... */ /* - - SMBlib Standard Includes - - Copyright (C) 1996, Richard Sharpe -*/ + * + * 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. -*/ + * 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,4 +42,4 @@ #define TRUE 1 #define FALSE 0 -#endif _STD_DEFINES_H_ +#endif /* _STD_DEFINES_H_ */ Index: squid/auth_modules/MSNT/std-includes.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/std-includes.h,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/std-includes.h 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/std-includes.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -1,27 +1,27 @@ /* RFCNB Standard includes ... */ /* - - RFCNB Standard Includes - - Copyright (C) 1996, Richard Sharpe -*/ + * + * 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. -*/ + * 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; Index: squid/auth_modules/MSNT/valid.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/valid.c,v retrieving revision 1.1.1.1.10.1 retrieving revision 1.1.1.1.10.1.2.1 diff -u -r1.1.1.1.10.1 -r1.1.1.1.10.1.2.1 --- squid/auth_modules/MSNT/valid.c 12 Jul 2000 22:46:39 -0000 1.1.1.1.10.1 +++ squid/auth_modules/MSNT/valid.c 7 Jan 2001 09:48:27 -0000 1.1.1.1.10.1.2.1 @@ -9,36 +9,37 @@ extern int SMB_Logon_Server(SMB_Handle_Type, char *, char *); -int Valid_User(char *USERNAME,char *PASSWORD,char *SERVER,char *BACKUP, char *DOMAIN) +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; + 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); + 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); } Index: squid/auth_modules/MSNT/valid.h =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/MSNT/Attic/valid.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/auth_modules/MSNT/valid.h 26 Jan 2000 03:25:00 -0000 1.1.1.1 +++ squid/auth_modules/MSNT/valid.h 7 Jan 2001 09:48:27 -0000 1.1.1.1.26.1 @@ -7,6 +7,6 @@ #define NTV_PROTOCOL_ERROR 2 #define NTV_LOGON_ERROR 3 -int Valid_User(char *USERNAME,char *PASSWORD,char *SERVER, char *BACKUP, char *DOMAIN); +int Valid_User(char *USERNAME, char *PASSWORD, char *SERVER, char *BACKUP, char *DOMAIN); #endif Index: squid/auth_modules/NCSA/ncsa_auth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/NCSA/Attic/ncsa_auth.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.30.1 diff -u -r1.1.1.1 -r1.1.1.1.30.1 --- squid/auth_modules/NCSA/ncsa_auth.c 26 Jan 2000 03:21:46 -0000 1.1.1.1 +++ squid/auth_modules/NCSA/ncsa_auth.c 7 Jan 2001 09:48:27 -0000 1.1.1.1.30.1 @@ -123,12 +123,12 @@ } } if ((user = strtok(buf, " ")) == NULL) { - printf("ERR\n"); - continue; + printf("ERR\n"); + continue; } if ((passwd = strtok(NULL, "")) == NULL) { - printf("ERR\n"); - continue; + printf("ERR\n"); + continue; } u = hash_lookup(hash, user); if (u == NULL) { Index: squid/auth_modules/SMB/smb_auth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/SMB/Attic/smb_auth.c,v retrieving revision 1.1.1.2.10.1 retrieving revision 1.1.1.2.10.1.2.1 diff -u -r1.1.1.2.10.1 -r1.1.1.2.10.1.2.1 --- squid/auth_modules/SMB/smb_auth.c 17 Aug 2000 15:14:59 -0000 1.1.1.2.10.1 +++ squid/auth_modules/SMB/smb_auth.c 7 Jan 2001 09:48:28 -0000 1.1.1.2.10.1.2.1 @@ -25,16 +25,15 @@ #define NMB_UNICAST 1 #define NMB_BROADCAST 2 -struct SMBDOMAIN -{ - char *name; /* domain name */ - char *sname; /* match this with user input */ - char *passthrough; /* pass-through authentication */ - char *nmbaddr; /* name service address */ - int nmbcast; /* broadcast or unicast */ - char *authshare; /* share name of auth file */ - char *authfile; /* pathname of auth file */ - struct SMBDOMAIN *next; /* linked list */ +struct SMBDOMAIN { + char *name; /* domain name */ + char *sname; /* match this with user input */ + char *passthrough; /* pass-through authentication */ + char *nmbaddr; /* name service address */ + int nmbcast; /* broadcast or unicast */ + char *authshare; /* share name of auth file */ + char *authfile; /* pathname of auth file */ + struct SMBDOMAIN *next; /* linked list */ }; struct SMBDOMAIN *firstdom = NULL; @@ -45,218 +44,189 @@ * to the read command of the bourne shell. */ -void print_esc(FILE *p, char *s) +void +print_esc(FILE * p, char *s) { - char buf[256]; - char *t; - int i = 0; - - for (t = s; *t != '\0'; t++) - { - if (i > 250) - { - buf[i] = '\0'; - (void) fputs(buf, p); - i = 0; - } - - if (*t == '\\') - buf[i++] = '\\'; - - buf[i++] = *t; + char buf[256]; + char *t; + int i = 0; + + for (t = s; *t != '\0'; t++) { + if (i > 250) { + buf[i] = '\0'; + (void) fputs(buf, p); + i = 0; } + if (*t == '\\') + buf[i++] = '\\'; - if (i > 0) - { - buf[i] = '\0'; - (void) fputs(buf, p); - } + buf[i++] = *t; + } + + if (i > 0) { + buf[i] = '\0'; + (void) fputs(buf, p); + } } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - int i; - char buf[BUFSIZE]; - struct SMBDOMAIN *dom; - char *s; - char *user; - char *pass; - char *domname; - FILE *p; - int debug = 0; - char *shcmd; - - /* make standard output line buffered */ - if (setvbuf(stdout, NULL, _IOLBF, 0) != 0) - return 1; - - /* parse command line arguments */ - for (i = 1; i < argc; i++) - { - if (strcmp(argv[i], "-d") == 0) - { - debug = 1; - continue; - } - - /* the next options require an argument */ - if (i + 1 == argc) - break; - - if (strcmp(argv[i], "-W") == 0) - { - if ((dom = (struct SMBDOMAIN *) malloc(sizeof(struct SMBDOMAIN))) == NULL) - return 1; - - dom->name = dom->sname = argv[++i]; - dom->passthrough = ""; - dom->nmbaddr = ""; - dom->nmbcast = NMB_BROADCAST; - dom->authshare = "NETLOGON"; - dom->authfile = "proxyauth"; - dom->next = NULL; - - /* append to linked list */ - if (lastdom != NULL) - lastdom->next = dom; - else - firstdom = dom; - - lastdom = dom; - continue; - } - - if (strcmp(argv[i], "-w") == 0) - { - if (lastdom != NULL) - lastdom->sname = argv[++i]; - continue; - } - - if (strcmp(argv[i], "-P") == 0) - { - if (lastdom != NULL) - lastdom->passthrough = argv[++i]; - continue; - } - - if (strcmp(argv[i], "-B") == 0) - { - if (lastdom != NULL) - { - lastdom->nmbaddr = argv[++i]; - lastdom->nmbcast = NMB_BROADCAST; - } - continue; - } - - if (strcmp(argv[i], "-U") == 0) - { - if (lastdom != NULL) - { - lastdom->nmbaddr = argv[++i]; - lastdom->nmbcast = NMB_UNICAST; - } - continue; - } + int i; + char buf[BUFSIZE]; + struct SMBDOMAIN *dom; + char *s; + char *user; + char *pass; + char *domname; + FILE *p; + int debug = 0; + char *shcmd; + + /* make standard output line buffered */ + if (setvbuf(stdout, NULL, _IOLBF, 0) != 0) + return 1; + + /* parse command line arguments */ + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-d") == 0) { + debug = 1; + continue; + } + /* the next options require an argument */ + if (i + 1 == argc) + break; + + if (strcmp(argv[i], "-W") == 0) { + if ((dom = (struct SMBDOMAIN *) malloc(sizeof(struct SMBDOMAIN))) == NULL) + return 1; + + dom->name = dom->sname = argv[++i]; + dom->passthrough = ""; + dom->nmbaddr = ""; + dom->nmbcast = NMB_BROADCAST; + dom->authshare = "NETLOGON"; + dom->authfile = "proxyauth"; + dom->next = NULL; + + /* append to linked list */ + if (lastdom != NULL) + lastdom->next = dom; + else + firstdom = dom; - if (strcmp(argv[i], "-S") == 0) - { - if (lastdom != NULL) - { - if ((lastdom->authshare = strdup(argv[++i])) == NULL) - return 1; - - /* convert backslashes to forward slashes */ - for (s = lastdom->authshare; *s != '\0'; s++) - if (*s == '\\') - *s = '/'; - - /* strip leading forward slash from share name */ - if (*lastdom->authshare == '/') - lastdom->authshare++; - - if ((s = strchr(lastdom->authshare, '/')) != NULL) - { - *s = '\0'; - lastdom->authfile = s + 1; - } - } - continue; + lastdom = dom; + continue; + } + if (strcmp(argv[i], "-w") == 0) { + if (lastdom != NULL) + lastdom->sname = argv[++i]; + continue; + } + if (strcmp(argv[i], "-P") == 0) { + if (lastdom != NULL) + lastdom->passthrough = argv[++i]; + continue; + } + if (strcmp(argv[i], "-B") == 0) { + if (lastdom != NULL) { + lastdom->nmbaddr = argv[++i]; + lastdom->nmbcast = NMB_BROADCAST; + } + continue; + } + if (strcmp(argv[i], "-U") == 0) { + if (lastdom != NULL) { + lastdom->nmbaddr = argv[++i]; + lastdom->nmbcast = NMB_UNICAST; + } + continue; + } + if (strcmp(argv[i], "-S") == 0) { + if (lastdom != NULL) { + if ((lastdom->authshare = strdup(argv[++i])) == NULL) + return 1; + + /* convert backslashes to forward slashes */ + for (s = lastdom->authshare; *s != '\0'; s++) + if (*s == '\\') + *s = '/'; + + /* strip leading forward slash from share name */ + if (*lastdom->authshare == '/') + lastdom->authshare++; + + if ((s = strchr(lastdom->authshare, '/')) != NULL) { + *s = '\0'; + lastdom->authfile = s + 1; } + } + continue; } + } - shcmd = debug ? HELPERSCRIPT : HELPERSCRIPT " > /dev/null 2>&1"; + shcmd = debug ? HELPERSCRIPT : HELPERSCRIPT " > /dev/null 2>&1"; - /* pass to helper script */ + /* pass to helper script */ if (putenv("SAMBAPREFIX=" SAMBAPREFIX) != 0) - return 1; - - while (1) - { - if (fgets(buf, BUFSIZE, stdin) == NULL) - break; - - if ((s = strchr(buf, '\n')) == NULL) - continue; - *s = '\0'; - - if ((s = strchr(buf, ' ')) == NULL) - { - (void) printf("ERR\n"); - continue; - } - *s = '\0'; + return 1; - user = buf; - pass = s + 1; - domname = NULL; - - if ((s = strchr(user, '\\')) != NULL) - { - *s = '\0'; - domname = user; - user = s + 1; - } - - /* match domname with linked list */ - if (domname != NULL && strlen(domname) > 0) - { - for (dom = firstdom; dom != NULL; dom = dom->next) - if (strcasecmp(dom->sname, domname) == 0) - break; - } else - dom = firstdom; - - if (dom == NULL) - { - (void) printf("ERR\n"); - continue; - } - - if ((p = popen(shcmd, "w")) == NULL) - { - (void) printf("ERR\n"); - continue; - } + while (1) { + if (fgets(buf, BUFSIZE, stdin) == NULL) + break; + + if ((s = strchr(buf, '\n')) == NULL) + continue; + *s = '\0'; + + if ((s = strchr(buf, ' ')) == NULL) { + (void) printf("ERR\n"); + continue; + } + *s = '\0'; - (void) fprintf(p, "%s\n", dom->name); - (void) fprintf(p, "%s\n", dom->passthrough); - (void) fprintf(p, "%s\n", dom->nmbaddr); - (void) fprintf(p, "%d\n", dom->nmbcast); - (void) fprintf(p, "%s\n", dom->authshare); - (void) fprintf(p, "%s\n", dom->authfile); - (void) fprintf(p, "%s\n", user); - /* the password can contain special characters */ - print_esc(p, pass); - (void) fputc('\n', p); - (void) fflush(p); - - if (pclose(p) == 0) - (void) printf("OK\n"); - else - (void) printf("ERR\n"); + user = buf; + pass = s + 1; + domname = NULL; + + if ((s = strchr(user, '\\')) != NULL) { + *s = '\0'; + domname = user; + user = s + 1; + } + /* match domname with linked list */ + if (domname != NULL && strlen(domname) > 0) { + for (dom = firstdom; dom != NULL; dom = dom->next) + if (strcasecmp(dom->sname, domname) == 0) + break; + } else + dom = firstdom; + + if (dom == NULL) { + (void) printf("ERR\n"); + continue; + } + if ((p = popen(shcmd, "w")) == NULL) { + (void) printf("ERR\n"); + continue; + } + (void) fprintf(p, "%s\n", dom->name); + (void) fprintf(p, "%s\n", dom->passthrough); + (void) fprintf(p, "%s\n", dom->nmbaddr); + (void) fprintf(p, "%d\n", dom->nmbcast); + (void) fprintf(p, "%s\n", dom->authshare); + (void) fprintf(p, "%s\n", dom->authfile); + (void) fprintf(p, "%s\n", user); + /* the password can contain special characters */ + print_esc(p, pass); + (void) fputc('\n', p); + (void) fflush(p); + + if (pclose(p) == 0) + (void) printf("OK\n"); + else + (void) printf("ERR\n"); - } /* while (1) */ - return 0; + } /* while (1) */ + return 0; } Index: squid/auth_modules/getpwnam/getpwnam_auth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/auth_modules/getpwnam/Attic/getpwnam_auth.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.30.1 diff -u -r1.1.1.1 -r1.1.1.1.30.1 --- squid/auth_modules/getpwnam/getpwnam_auth.c 26 Jan 2000 03:23:09 -0000 1.1.1.1 +++ squid/auth_modules/getpwnam/getpwnam_auth.c 7 Jan 2001 09:48:28 -0000 1.1.1.1.30.1 @@ -44,7 +44,7 @@ #define ERR "ERR\n" #define OK "OK\n" -int +int main() { char buf[256]; Index: squid/include/Array.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/Array.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/include/Array.h 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/include/Array.h 7 Jan 2001 09:48:28 -0000 1.1.1.1.26.1 @@ -1,5 +1,5 @@ /* - * $Id: Array.h,v 1.1.1.1 2000/01/26 03:21:47 hno Exp $ + * $Id: Array.h,v 1.1.1.1.26.1 2001/01/07 09:48:28 hno Exp $ * * AUTHOR: Alex Rousskov * @@ -42,8 +42,8 @@ extern Array *arrayCreate(); extern void arrayInit(Array * s); extern void arrayClean(Array * s); -extern void arrayDestroy(Array *s); -extern void arrayAppend(Array *s, void *obj); +extern void arrayDestroy(Array * s); +extern void arrayAppend(Array * s, void *obj); extern void arrayPreAppend(Array * s, int app_count); Index: squid/include/Stack.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/Stack.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/include/Stack.h 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/include/Stack.h 7 Jan 2001 09:48:28 -0000 1.1.1.1.26.1 @@ -1,5 +1,5 @@ /* - * $Id: Stack.h,v 1.1.1.1 2000/01/26 03:21:47 hno Exp $ + * $Id: Stack.h,v 1.1.1.1.26.1 2001/01/07 09:48:28 hno Exp $ * * AUTHOR: Alex Rousskov * @@ -38,9 +38,9 @@ #define stackInit arrayInit #define stackClean arrayClean #define stackDestroy arrayDestroy -extern void *stackPop(Stack *s); +extern void *stackPop(Stack * s); #define stackPush arrayAppend #define stackPrePush arrayPreAppend -extern void *stackTop(Stack *s); +extern void *stackTop(Stack * s); #endif /* ndef _STACK_H_ */ Index: squid/include/asn1.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/asn1.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/include/asn1.h 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/include/asn1.h 7 Jan 2001 09:48:28 -0000 1.1.1.1.26.1 @@ -28,7 +28,7 @@ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. * - * $Id: asn1.h,v 1.1.1.1 2000/01/26 03:21:47 hno Exp $ + * $Id: asn1.h,v 1.1.1.1.26.1 2001/01/07 09:48:28 hno Exp $ * **********************************************************************/ @@ -96,6 +96,6 @@ #ifdef __cplusplus } -#endif +#endif #endif /* _SNMP_ASN1_H_ */ Index: squid/include/ntlmauth.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/ntlmauth.h,v retrieving revision 1.1.4.2 retrieving revision 1.1.4.3 diff -u -r1.1.4.2 -r1.1.4.3 --- squid/include/ntlmauth.h 7 Jan 2001 07:27:13 -0000 1.1.4.2 +++ squid/include/ntlmauth.h 7 Jan 2001 09:48:28 -0000 1.1.4.3 @@ -29,7 +29,7 @@ #ifndef _NTLMAUTH_H_ #define _NTLMAUTH_H_ -#include /* for *int32_t */ +#include /* for *int32_t */ /* All of this cruft is little endian */ #ifdef WORDS_BIGENDIAN @@ -41,8 +41,8 @@ #endif /* Used internally. Microsoft seems to think this is right, I believe them. - Right. */ -#define MAX_FIELD_LENGTH 300 /* max length of an NTLMSSP field */ + * Right. */ +#define MAX_FIELD_LENGTH 300 /* max length of an NTLMSSP field */ /* Here start the NTLMSSP definitions */ @@ -81,67 +81,67 @@ /* String header. String data resides at the end of the request */ -typedef struct _strhdr{ - int16_t len; /* Length in bytes */ - int16_t maxlen; /* Allocated space in bytes */ - int32_t offset; /* Offset from start of request */ +typedef struct _strhdr { + int16_t len; /* Length in bytes */ + int16_t maxlen; /* Allocated space in bytes */ + int32_t offset; /* Offset from start of request */ } strhdr; /* We use this to keep data/lenght couples. Only used internally. */ -typedef struct _lstring{ - int32_t l; /* length, -1 if empty */ - char *str; /* the string. NULL if not initialized */ +typedef struct _lstring { + int32_t l; /* length, -1 if empty */ + char *str; /* the string. NULL if not initialized */ } lstring; /* This is an header common to all signatures, it's used to discriminate - among the different signature types. */ + * among the different signature types. */ typedef struct _ntlmhdr { - char signature[8]; /* "NTLMSSP" */ - int32_t type; /* LSWAP(0x1) */ + char signature[8]; /* "NTLMSSP" */ + int32_t type; /* LSWAP(0x1) */ } ntlmhdr; /* Negotiation request sent by client */ typedef struct _ntlm_negotiate { - char signature[8]; /* "NTLMSSP" */ - int32_t type; /* LSWAP(0x1) */ - ntlmhdr hdr; /* NTLM header */ - u_int32_t flags; /* Request flags */ - strhdr domain; /* Domain we wish to authenticate in */ - strhdr workstation; /* Client workstation name */ - char payload[256]; /* String data */ + char signature[8]; /* "NTLMSSP" */ + int32_t type; /* LSWAP(0x1) */ + ntlmhdr hdr; /* NTLM header */ + u_int32_t flags; /* Request flags */ + strhdr domain; /* Domain we wish to authenticate in */ + strhdr workstation; /* Client workstation name */ + char payload[256]; /* String data */ } ntlm_negotiate; /* Challenge request sent by server. */ typedef struct _ntlm_challenge { - char signature[8]; /* "NTLMSSP" */ - int32_t type; /* LSWAP(0x2) */ - strhdr target; /* Authentication target (domain/server ...) */ - u_int32_t flags; /* Request flags */ - u_char challenge[NONCE_LEN]; /* Challenge string */ - u_int32_t context_low; /* LS part of the server context handle */ - u_int32_t context_high; /* MS part of the server context handle */ - char payload[256]; /* String data */ + char signature[8]; /* "NTLMSSP" */ + int32_t type; /* LSWAP(0x2) */ + strhdr target; /* Authentication target (domain/server ...) */ + u_int32_t flags; /* Request flags */ + u_char challenge[NONCE_LEN]; /* Challenge string */ + u_int32_t context_low; /* LS part of the server context handle */ + u_int32_t context_high; /* MS part of the server context handle */ + char payload[256]; /* String data */ } ntlm_challenge; /* Authentication request sent by client in response to challenge */ typedef struct _ntlm_authenticate { - char signature[8]; /* "NTLMSSP" */ - int32_t type; /* LSWAP(0x3) */ - strhdr lmresponse; /* LANMAN challenge response */ - strhdr ntresponse; /* NT challenge response */ - strhdr domain; /* Domain to authenticate against */ - strhdr user; /* Username */ - strhdr workstation; /* Workstation name */ - strhdr sessionkey; /* Session key for server's use */ - int32_t flags; /* Request flags */ - char payload[256*6]; /* String data */ + char signature[8]; /* "NTLMSSP" */ + int32_t type; /* LSWAP(0x3) */ + strhdr lmresponse; /* LANMAN challenge response */ + strhdr ntresponse; /* NT challenge response */ + strhdr domain; /* Domain to authenticate against */ + strhdr user; /* Username */ + strhdr workstation; /* Workstation name */ + strhdr sessionkey; /* Session key for server's use */ + int32_t flags; /* Request flags */ + char payload[256 * 6]; /* String data */ } ntlm_authenticate; -const char* ntlm_make_challenge(char *domain, char *domain_controller, - char *challenge_nonce, int challenge_nonce_len); -lstring ntlm_fetch_string (char * packet, int32_t length, strhdr *str); -void ntlm_add_to_payload (char *payload, int *payload_length, - strhdr *hdr, char *toadd, - int toadd_length, int base_offset); +const char *ntlm_make_challenge(char *domain, char *domain_controller, + char *challenge_nonce, int challenge_nonce_len); +lstring ntlm_fetch_string(char *packet, int32_t length, strhdr * str); +void ntlm_add_to_payload(char *payload, int *payload_length, + strhdr * hdr, char *toadd, + int toadd_length, int base_offset); #endif /* _NTLMAUTH_H_ */ Index: squid/include/radix.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/radix.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/include/radix.h 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/include/radix.h 7 Jan 2001 09:48:28 -0000 1.1.1.1.26.1 @@ -1,5 +1,5 @@ /* - * $Id: radix.h,v 1.1.1.1 2000/01/26 03:21:47 hno Exp $ + * $Id: radix.h,v 1.1.1.1.26.1 2001/01/07 09:48:28 hno Exp $ */ /* @@ -52,14 +52,14 @@ struct radix_node *rn_p; /* parent */ short rn_b; /* bit offset; -1-index(netmask) */ char rn_bmask; /* node: mask for bit test */ - unsigned char rn_flags; /* enumerated next */ + unsigned char rn_flags; /* enumerated next */ #define RNF_NORMAL 1 /* leaf contains normal route */ #define RNF_ROOT 2 /* leaf is root leaf for tree */ #define RNF_ACTIVE 4 /* This node is alive (for rtfree) */ union { struct { /* leaf only data: */ - char * rn_Key; /* object of search */ - char * rn_Mask; /* netmask, if present */ + char *rn_Key; /* object of search */ + char *rn_Mask; /* netmask, if present */ struct radix_node *rn_Dupedkey; } rn_leaf; struct { /* node only data: */ @@ -89,10 +89,10 @@ extern struct radix_mask { short rm_b; /* bit offset; -1-index(netmask) */ char rm_unused; /* cf. rn_bmask */ - unsigned char rm_flags; /* cf. rn_flags */ + unsigned char rm_flags; /* cf. rn_flags */ struct radix_mask *rm_mklist; /* more masks to try */ union { - char * rmu_mask; /* the mask */ + char *rmu_mask; /* the mask */ struct radix_node *rmu_leaf; /* for normal routes */ } rm_rmu; int rm_refs; /* # of references to this struct */ Index: squid/include/snmp_client.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/snmp_client.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/include/snmp_client.h 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/include/snmp_client.h 7 Jan 2001 09:48:28 -0000 1.1.1.1.26.1 @@ -1,5 +1,5 @@ /* - * $Id: snmp_client.h,v 1.1.1.1 2000/01/26 03:21:47 hno Exp $ + * $Id: snmp_client.h,v 1.1.1.1.26.1 2001/01/07 09:48:28 hno Exp $ */ #ifndef _SNMP_CLIENT_H_ @@ -30,7 +30,7 @@ SOFTWARE. ******************************************************************/ struct synch_state { - int waiting; + int waiting; int status; /* status codes */ #define STAT_SUCCESS 0 @@ -44,22 +44,21 @@ extern "C" { #endif -extern struct synch_state snmp_synch_state; + extern struct synch_state snmp_synch_state; /* Synchronize Input with Agent */ -int snmp_synch_input(int, struct snmp_session *, int, - struct snmp_pdu *, void *); + int snmp_synch_input(int, struct snmp_session *, int, + struct snmp_pdu *, void *); /* Synchronize Response with Agent */ -int snmp_synch_response(struct snmp_session *, struct snmp_pdu *, - struct snmp_pdu **); + int snmp_synch_response(struct snmp_session *, struct snmp_pdu *, + struct snmp_pdu **); /* Synchronize Setup */ -void snmp_synch_setup(struct snmp_session *); + void snmp_synch_setup(struct snmp_session *); #ifdef __cplusplus } -#endif - -#endif /* _SNMP_CLIENT_H_ */ +#endif +#endif /* _SNMP_CLIENT_H_ */ Index: squid/include/snmp_pdu.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/snmp_pdu.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/include/snmp_pdu.h 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/include/snmp_pdu.h 7 Jan 2001 09:48:28 -0000 1.1.1.1.26.1 @@ -27,7 +27,7 @@ * * Author: Ryan Troll * - * $Id: snmp_pdu.h,v 1.1.1.1 2000/01/26 03:21:47 hno Exp $ + * $Id: snmp_pdu.h,v 1.1.1.1.26.1 2001/01/07 09:48:28 hno Exp $ * **********************************************************************/ @@ -79,11 +79,11 @@ } #endif /* - * * RFC 1905: Protocol Operations for SNMPv2 - * * - * * RFC 1157: A Simple Network Management Protocol (SNMP) - * * - * * PDU Types + * * * * RFC 1905: Protocol Operations for SNMPv2 + * * * * + * * * * RFC 1157: A Simple Network Management Protocol (SNMP) + * * * * + * * * * PDU Types */ #define SNMP_PDU_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x0) #define SNMP_PDU_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x1) @@ -99,11 +99,11 @@ #define SNMP_DEFAULT_ERRINDEX -1 #define SNMP_DEFAULT_ADDRESS 0 #define SNMP_DEFAULT_REQID 0 /* - * * RFC 1907: Management Information Base for SNMPv2 - * * - * * RFC 1157: A Simple Network Management Protocol (SNMP) - * * - * * Trap Types + * * * * RFC 1907: Management Information Base for SNMPv2 + * * * * + * * * * RFC 1157: A Simple Network Management Protocol (SNMP) + * * * * + * * * * Trap Types */ #define SNMP_TRAP_COLDSTART (0x0) #define SNMP_TRAP_WARMSTART (0x1) Index: squid/include/snmp_vars.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/snmp_vars.h,v retrieving revision 1.1.1.2 retrieving revision 1.1.1.2.22.1 diff -u -r1.1.1.2 -r1.1.1.2.22.1 --- squid/include/snmp_vars.h 26 Jan 2000 03:25:00 -0000 1.1.1.2 +++ squid/include/snmp_vars.h 7 Jan 2001 09:48:28 -0000 1.1.1.2.22.1 @@ -26,7 +26,7 @@ * * Author: Ryan Troll * - * $Id: snmp_vars.h,v 1.1.1.2 2000/01/26 03:25:00 hno Exp $ + * $Id: snmp_vars.h,v 1.1.1.2.22.1 2001/01/07 09:48:28 hno Exp $ * **********************************************************************/ @@ -59,9 +59,7 @@ } #endif -#define MAX_NAME_LEN 64 /* number of subid's in a objid *//* *RFC 1902:Structure of Management Information for SNMPv2 * - *Defined Types -* +#define MAX_NAME_LEN 64 /* number of subid's in a objid *//* *RFC 1902:Structure of Management Information for SNMPv2 * *Defined Types * */ #define SMI_INTEGER ASN_INTEGER #define SMI_STRING ASN_OCTET_STR Index: squid/lib/GNUregex.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/GNUregex.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/lib/GNUregex.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/lib/GNUregex.c 7 Jan 2001 09:48:28 -0000 1.1.1.1.26.1 @@ -1,5 +1,6 @@ + /* - * $Id: GNUregex.c,v 1.1.1.1 2000/01/26 03:21:47 hno Exp $ + * $Id: GNUregex.c,v 1.1.1.1.26.1 2001/01/07 09:48:28 hno Exp $ */ /* Extended regular expression matching and search library, @@ -1576,7 +1577,6 @@ else return REG_ERPAREN; } - handle_close: if (fixup_alt_jump) { /* Push a dummy failure point at the end of the * alternative for a possible future @@ -1595,7 +1595,6 @@ else return REG_ERPAREN; } - /* Since we just checked for an empty stack above, this * ``can't happen''. */ assert(compile_stack.avail != 0); Index: squid/lib/base64.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/base64.c,v retrieving revision 1.1.1.1.14.1 retrieving revision 1.1.1.1.14.1.2.1 diff -u -r1.1.1.1.14.1 -r1.1.1.1.14.1.2.1 --- squid/lib/base64.c 5 Feb 2000 20:14:18 -0000 1.1.1.1.14.1 +++ squid/lib/base64.c 7 Jan 2001 09:48:29 -0000 1.1.1.1.14.1.2.1 @@ -1,5 +1,5 @@ /* - * $Id: base64.c,v 1.1.1.1.14.1 2000/02/05 20:14:18 hno Exp $ + * $Id: base64.c,v 1.1.1.1.14.1.2.1 2001/01/07 09:48:29 hno Exp $ */ #include "config.h" @@ -114,7 +114,7 @@ /* adopted from http://ftp.sunet.se/pub2/gnu/vm/base64-encode.c with adjustments */ const char * -base64_encode_bin(const char * data, int len) +base64_encode_bin(const char *data, int len) { static char result[BASE64_RESULT_SZ]; int bits = 0; @@ -129,7 +129,7 @@ base64_init(); while (len-- && out_cnt < sizeof(result) - 1) { - c = (unsigned char)*data++; + c = (unsigned char) *data++; bits += c; char_count++; if (char_count == 3) { Index: squid/lib/dlmalloc.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/dlmalloc.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/lib/dlmalloc.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/lib/dlmalloc.c 7 Jan 2001 09:48:29 -0000 1.1.1.1.26.1 @@ -1,3170 +1,182 @@ /* - * $Id: dlmalloc.c,v 1.1.1.1 2000/01/26 03:21:47 hno Exp $ + * $Id: dlmalloc.c,v 1.1.1.1.26.1 2001/01/07 09:48:29 hno Exp $ */ /* ---------- To make a malloc.h, start cutting here ------------ */ /* - A version of malloc/free/realloc written by Doug Lea and released to the - public domain. Send questions/comments/complaints/performance data - to dl@cs.oswego.edu - -* VERSION 2.6.4 Thu Nov 28 07:54:55 1996 Doug Lea (dl at gee) - - Note: There may be an updated version of this malloc obtainable at - ftp://g.oswego.edu/pub/misc/malloc.c - Check before installing! - -* Why use this malloc? - - This is not the fastest, most space-conserving, most portable, or - most tunable malloc ever written. However it is among the fastest - while also being among the most space-conserving, portable and tunable. - Consistent balance across these factors results in a good general-purpose - allocator. For a high-level description, see - http://g.oswego.edu/dl/html/malloc.html - -* Synopsis of public routines - - (Much fuller descriptions are contained in the program documentation below.) - - malloc(size_t n); - Return a pointer to a newly allocated chunk of at least n bytes, or null - if no space is available. - free(Void_t* p); - Release the chunk of memory pointed to by p, or no effect if p is null. - realloc(Void_t* p, size_t n); - Return a pointer to a chunk of size n that contains the same data - as does chunk p up to the minimum of (n, p's size) bytes, or null - if no space is available. The returned pointer may or may not be - the same as p. If p is null, equivalent to malloc. Unless the - #define REALLOC_ZERO_BYTES_FREES below is set, realloc with a - size argument of zero (re)allocates a minimum-sized chunk. - memalign(size_t alignment, size_t n); - Return a pointer to a newly allocated chunk of n bytes, aligned - in accord with the alignment argument, which must be a power of - two. - valloc(size_t n); - Equivalent to memalign(pagesize, n), where pagesize is the page - size of the system (or as near to this as can be figured out from - all the includes/defines below.) - pvalloc(size_t n); - Equivalent to valloc(minimum-page-that-holds(n)), that is, - round up n to nearest pagesize. - calloc(size_t unit, size_t quantity); - Returns a pointer to quantity * unit bytes, with all locations - set to zero. - cfree(Void_t* p); - Equivalent to free(p). - malloc_trim(size_t pad); - Release all but pad bytes of freed top-most memory back - to the system. Return 1 if successful, else 0. - malloc_usable_size(Void_t* p); - Report the number usable allocated bytes associated with allocated - chunk p. This may or may not report more bytes than were requested, - due to alignment and minimum size constraints. - malloc_stats(); - Prints brief summary statistics on stderr. - mallinfo() - Returns (by copy) a struct containing various summary statistics. - mallopt(int parameter_number, int parameter_value) - Changes one of the tunable parameters described below. Returns - 1 if successful in changing the parameter, else 0. - -* Vital statistics: - - Alignment: 8-byte - 8 byte alignment is currently hardwired into the design. This - seems to suffice for all current machines and C compilers. - - Assumed pointer representation: 4 or 8 bytes - Code for 8-byte pointers is untested by me but has worked - reliably by Wolfram Gloger, who contributed most of the - changes supporting this. - - Assumed size_t representation: 4 or 8 bytes - Note that size_t is allowed to be 4 bytes even if pointers are 8. - - Minimum overhead per allocated chunk: 4 or 8 bytes - Each malloced chunk has a hidden overhead of 4 bytes holding size - and status information. - - Minimum allocated size: 4-byte ptrs: 16 bytes (including 4 overhead) - 8-byte ptrs: 24/32 bytes (including, 4/8 overhead) - - When a chunk is freed, 12 (for 4byte ptrs) or 20 (for 8 byte - ptrs but 4 byte size) or 24 (for 8/8) additional bytes are - needed; 4 (8) for a trailing size field - and 8 (16) bytes for free list pointers. Thus, the minimum - allocatable size is 16/24/32 bytes. - - Even a request for zero bytes (i.e., malloc(0)) returns a - pointer to something of the minimum allocatable size. - - Maximum allocated size: 4-byte size_t: 2^31 - 8 bytes - 8-byte size_t: 2^63 - 16 bytes - - It is assumed that (possibly signed) size_t bit values suffice to - represent chunk sizes. `Possibly signed' is due to the fact - that `size_t' may be defined on a system as either a signed or - an unsigned type. To be conservative, values that would appear - as negative numbers are avoided. - Requests for sizes with a negative sign bit will return a - minimum-sized chunk. - - Maximum overhead wastage per allocated chunk: normally 15 bytes - - Alignnment demands, plus the minimum allocatable size restriction - make the normal worst-case wastage 15 bytes (i.e., up to 15 - more bytes will be allocated than were requested in malloc), with - two exceptions: - 1. Because requests for zero bytes allocate non-zero space, - the worst case wastage for a request of zero bytes is 24 bytes. - 2. For requests >= mmap_threshold that are serviced via - mmap(), the worst case wastage is 8 bytes plus the remainder - from a system page (the minimal mmap unit); typically 4096 bytes. - -* Limitations - - Here are some features that are NOT currently supported - - * No user-definable hooks for callbacks and the like. - * No automated mechanism for fully checking that all accesses - to malloced memory stay within their bounds. - * No support for compaction. - -* Synopsis of compile-time options: - - People have reported using previous versions of this malloc on all - versions of Unix, sometimes by tweaking some of the defines - below. It has been tested most extensively on Solaris and - Linux. It is also reported to work on WIN32 platforms. - People have also reported adapting this malloc for use in - stand-alone embedded systems. - - The implementation is in straight, hand-tuned ANSI C. Among other - consequences, it uses a lot of macros. Because of this, to be at - all usable, this code should be compiled using an optimizing compiler - (for example gcc -O2) that can simplify expressions and control - paths. - - __STD_C (default: derived from C compiler defines) - Nonzero if using ANSI-standard C compiler, a C++ compiler, or - a C compiler sufficiently close to ANSI to get away with it. - DEBUG (default: NOT defined) - Define to enable debugging. Adds fairly extensive assertion-based - checking to help track down memory errors, but noticeably slows down - execution. - REALLOC_ZERO_BYTES_FREES (default: NOT defined) - Define this if you think that realloc(p, 0) should be equivalent - to free(p). Otherwise, since malloc returns a unique pointer for - malloc(0), so does realloc(p, 0). - HAVE_MEMCPY (default: defined) - Define if you are not otherwise using ANSI STD C, but still - have memcpy and memset in your C library and want to use them. - Otherwise, simple internal versions are supplied. - USE_MEMCPY (default: 1 if HAVE_MEMCPY is defined, 0 otherwise) - Define as 1 if you want the C library versions of memset and - memcpy called in realloc and calloc (otherwise macro versions are used). - At least on some platforms, the simple macro versions usually - outperform libc versions. - HAVE_MMAP (default: defined as 1) - Define to non-zero to optionally make malloc() use mmap() to - allocate very large blocks. - HAVE_MREMAP (default: defined as 0 unless Linux libc set) - Define to non-zero to optionally make realloc() use mremap() to - reallocate very large blocks. - malloc_getpagesize (default: derived from system #includes) - Either a constant or routine call returning the system page size. - HAVE_USR_INCLUDE_MALLOC_H (default: NOT defined) - Optionally define if you are on a system with a /usr/include/malloc.h - that declares struct mallinfo. It is not at all necessary to - define this even if you do, but will ensure consistency. - INTERNAL_SIZE_T (default: size_t) - Define to a 32-bit type (probably `unsigned int') if you are on a - 64-bit machine, yet do not want or need to allow malloc requests of - greater than 2^31 to be handled. This saves space, especially for - very small chunks. - INTERNAL_LINUX_C_LIB (default: NOT defined) - Defined only when compiled as part of Linux libc. - Also note that there is some odd internal name-mangling via defines - (for example, internally, `malloc' is named `mALLOc') needed - when compiling in this case. These look funny but don't otherwise - affect anything. - WIN32 (default: undefined) - Define this on MS win (95, nt) platforms to compile in sbrk emulation. - LACKS_UNISTD_H (default: undefined) - Define this if your system does not have a . - MORECORE (default: sbrk) - The name of the routine to call to obtain more memory from the system. - MORECORE_FAILURE (default: -1) - The value returned upon failure of MORECORE. - MORECORE_CLEARS (default 1) - True (1) if the routine mapped to MORECORE zeroes out memory (which - holds for sbrk). - DEFAULT_TRIM_THRESHOLD - DEFAULT_TOP_PAD - DEFAULT_MMAP_THRESHOLD - DEFAULT_MMAP_MAX - Default values of tunable parameters (described in detail below) - controlling interaction with host system routines (sbrk, mmap, etc). - These values may also be changed dynamically via mallopt(). The - preset defaults are those that give best performance for typical - programs/systems. - - -*/ - - - - -/* Preliminaries */ - -#ifndef __STD_C -#ifdef __STDC__ -#define __STD_C 1 -#else -#if __cplusplus -#define __STD_C 1 -#else -#define __STD_C 0 -#endif /*__cplusplus*/ -#endif /*__STDC__*/ -#endif /*__STD_C*/ - -#ifndef Void_t -#if __STD_C -#define Void_t void -#else -#define Void_t char -#endif -#endif /*Void_t*/ - -#if __STD_C -#include /* for size_t */ -#else -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#include /* needed for malloc_stats */ - - -/* - Compile-time options -*/ - - -/* - Debugging: - - Because freed chunks may be overwritten with link fields, this - malloc will often die when freed memory is overwritten by user - programs. This can be very effective (albeit in an annoying way) - in helping track down dangling pointers. - - If you compile with -DDEBUG, a number of assertion checks are - enabled that will catch more memory errors. You probably won't be - able to make much sense of the actual assertion errors, but they - should help you locate incorrectly overwritten memory. The - checking is fairly extensive, and will slow down execution - noticeably. Calling malloc_stats or mallinfo with DEBUG set will - attempt to check every non-mmapped allocated and free chunk in the - course of computing the summmaries. (By nature, mmapped regions - cannot be checked very much automatically.) - - Setting DEBUG may also be helpful if you are trying to modify - this code. The assertions in the check routines spell out in more - detail the assumptions and invariants underlying the algorithms. - -*/ - -#if DEBUG -#include -#else -#define assert(x) ((void)0) -#endif - - -/* - INTERNAL_SIZE_T is the word-size used for internal bookkeeping - of chunk sizes. On a 64-bit machine, you can reduce malloc - overhead by defining INTERNAL_SIZE_T to be a 32 bit `unsigned int' - at the expense of not being able to handle requests greater than - 2^31. This limitation is hardly ever a concern; you are encouraged - to set this. However, the default version is the same as size_t. -*/ - -#ifndef INTERNAL_SIZE_T -#define INTERNAL_SIZE_T size_t -#endif - -/* - REALLOC_ZERO_BYTES_FREES should be set if a call to - realloc with zero bytes should be the same as a call to free. - Some people think it should. Otherwise, since this malloc - returns a unique pointer for malloc(0), so does realloc(p, 0). -*/ - - -/* #define REALLOC_ZERO_BYTES_FREES */ - - -/* - WIN32 causes an emulation of sbrk to be compiled in - mmap-based options are not currently supported in WIN32. -*/ - -/* #define WIN32 */ -#ifdef WIN32 -#define MORECORE wsbrk -#define HAVE_MMAP 0 -#endif - - -/* - HAVE_MEMCPY should be defined if you are not otherwise using - ANSI STD C, but still have memcpy and memset in your C library - and want to use them in calloc and realloc. Otherwise simple - macro versions are defined here. - - USE_MEMCPY should be defined as 1 if you actually want to - have memset and memcpy called. People report that the macro - versions are often enough faster than libc versions on many - systems that it is better to use them. - -*/ - -#define HAVE_MEMCPY - -#ifndef USE_MEMCPY -#ifdef HAVE_MEMCPY -#define USE_MEMCPY 1 -#else -#define USE_MEMCPY 0 -#endif -#endif - -#if (__STD_C || defined(HAVE_MEMCPY)) - -#if __STD_C -void* memset(void*, int, size_t); -void* memcpy(void*, const void*, size_t); -#else -Void_t* memset(); -Void_t* memcpy(); -#endif -#endif - -#if USE_MEMCPY - -/* The following macros are only invoked with (2n+1)-multiples of - INTERNAL_SIZE_T units, with a positive integer n. This is exploited - for fast inline execution when n is small. */ - -#define MALLOC_ZERO(charp, nbytes) \ -do { \ - INTERNAL_SIZE_T mzsz = (nbytes); \ - if(mzsz <= 9*sizeof(mzsz)) { \ - INTERNAL_SIZE_T* mz = (INTERNAL_SIZE_T*) (charp); \ - if(mzsz >= 5*sizeof(mzsz)) { *mz++ = 0; \ - *mz++ = 0; \ - if(mzsz >= 7*sizeof(mzsz)) { *mz++ = 0; \ - *mz++ = 0; \ - if(mzsz >= 9*sizeof(mzsz)) { *mz++ = 0; \ - *mz++ = 0; }}} \ - *mz++ = 0; \ - *mz++ = 0; \ - *mz = 0; \ - } else memset((charp), 0, mzsz); \ -} while(0) - -#define MALLOC_COPY(dest,src,nbytes) \ -do { \ - INTERNAL_SIZE_T mcsz = (nbytes); \ - if(mcsz <= 9*sizeof(mcsz)) { \ - INTERNAL_SIZE_T* mcsrc = (INTERNAL_SIZE_T*) (src); \ - INTERNAL_SIZE_T* mcdst = (INTERNAL_SIZE_T*) (dest); \ - if(mcsz >= 5*sizeof(mcsz)) { *mcdst++ = *mcsrc++; \ - *mcdst++ = *mcsrc++; \ - if(mcsz >= 7*sizeof(mcsz)) { *mcdst++ = *mcsrc++; \ - *mcdst++ = *mcsrc++; \ - if(mcsz >= 9*sizeof(mcsz)) { *mcdst++ = *mcsrc++; \ - *mcdst++ = *mcsrc++; }}} \ - *mcdst++ = *mcsrc++; \ - *mcdst++ = *mcsrc++; \ - *mcdst = *mcsrc ; \ - } else memcpy(dest, src, mcsz); \ -} while(0) - -#else /* !USE_MEMCPY */ - -/* Use Duff's device for good zeroing/copying performance. */ - -#define MALLOC_ZERO(charp, nbytes) \ -do { \ - INTERNAL_SIZE_T* mzp = (INTERNAL_SIZE_T*)(charp); \ - long mctmp = (nbytes)/sizeof(INTERNAL_SIZE_T), mcn; \ - if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp %= 8; } \ - switch (mctmp) { \ - case 0: for(;;) { *mzp++ = 0; \ - case 7: *mzp++ = 0; \ - case 6: *mzp++ = 0; \ - case 5: *mzp++ = 0; \ - case 4: *mzp++ = 0; \ - case 3: *mzp++ = 0; \ - case 2: *mzp++ = 0; \ - case 1: *mzp++ = 0; if(mcn <= 0) break; mcn--; } \ - } \ -} while(0) - -#define MALLOC_COPY(dest,src,nbytes) \ -do { \ - INTERNAL_SIZE_T* mcsrc = (INTERNAL_SIZE_T*) src; \ - INTERNAL_SIZE_T* mcdst = (INTERNAL_SIZE_T*) dest; \ - long mctmp = (nbytes)/sizeof(INTERNAL_SIZE_T), mcn; \ - if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp %= 8; } \ - switch (mctmp) { \ - case 0: for(;;) { *mcdst++ = *mcsrc++; \ - case 7: *mcdst++ = *mcsrc++; \ - case 6: *mcdst++ = *mcsrc++; \ - case 5: *mcdst++ = *mcsrc++; \ - case 4: *mcdst++ = *mcsrc++; \ - case 3: *mcdst++ = *mcsrc++; \ - case 2: *mcdst++ = *mcsrc++; \ - case 1: *mcdst++ = *mcsrc++; if(mcn <= 0) break; mcn--; } \ - } \ -} while(0) - -#endif - - -/* - Define HAVE_MMAP to optionally make malloc() use mmap() to - allocate very large blocks. These will be returned to the - operating system immediately after a free(). -*/ - -#ifndef HAVE_MMAP -#define HAVE_MMAP 1 -#endif - -/* - Define HAVE_MREMAP to make realloc() use mremap() to re-allocate - large blocks. This is currently only possible on Linux with - kernel versions newer than 1.3.77. -*/ - -#ifndef HAVE_MREMAP -#ifdef INTERNAL_LINUX_C_LIB -#define HAVE_MREMAP 1 -#else -#define HAVE_MREMAP 0 -#endif -#endif - -#if HAVE_MMAP - -#include -#include -#include - -#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) -#define MAP_ANONYMOUS MAP_ANON -#endif - -#endif /* HAVE_MMAP */ - -/* - Access to system page size. To the extent possible, this malloc - manages memory from the system in page-size units. - - The following mechanics for getpagesize were adapted from - bsd/gnu getpagesize.h -*/ - -#ifndef LACKS_UNISTD_H -# include -#endif - -#ifndef malloc_getpagesize -# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */ -# ifndef _SC_PAGE_SIZE -# define _SC_PAGE_SIZE _SC_PAGESIZE -# endif -# endif -# ifdef _SC_PAGE_SIZE -# define malloc_getpagesize sysconf(_SC_PAGE_SIZE) -# else -# if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE) - extern size_t getpagesize(); -# define malloc_getpagesize getpagesize() -# else -# include -# ifdef EXEC_PAGESIZE -# define malloc_getpagesize EXEC_PAGESIZE -# else -# ifdef NBPG -# ifndef CLSIZE -# define malloc_getpagesize NBPG -# else -# define malloc_getpagesize (NBPG * CLSIZE) -# endif -# else -# ifdef NBPC -# define malloc_getpagesize NBPC -# else -# ifdef PAGESIZE -# define malloc_getpagesize PAGESIZE -# else -# define malloc_getpagesize (4096) /* just guess */ -# endif -# endif -# endif -# endif -# endif -# endif -#endif - - - -/* - - This version of malloc supports the standard SVID/XPG mallinfo - routine that returns a struct containing the same kind of - information you can get from malloc_stats. It should work on - any SVID/XPG compliant system that has a /usr/include/malloc.h - defining struct mallinfo. (If you'd like to install such a thing - yourself, cut out the preliminary declarations as described above - and below and save them in a malloc.h file. But there's no - compelling reason to bother to do this.) - - The main declaration needed is the mallinfo struct that is returned - (by-copy) by mallinfo(). The SVID/XPG malloinfo struct contains a - bunch of fields, most of which are not even meaningful in this - version of malloc. Some of these fields are are instead filled by - mallinfo() with other numbers that might possibly be of interest. - - HAVE_USR_INCLUDE_MALLOC_H should be set if you have a - /usr/include/malloc.h file that includes a declaration of struct - mallinfo. If so, it is included; else an SVID2/XPG2 compliant - version is declared below. These must be precisely the same for - mallinfo() to work. - -*/ - -/* #define HAVE_USR_INCLUDE_MALLOC_H */ - -#if HAVE_USR_INCLUDE_MALLOC_H -#include "/usr/include/malloc.h" -#else - -/* SVID2/XPG mallinfo structure */ - -struct mallinfo { - int arena; /* total space allocated from system */ - int ordblks; /* number of non-inuse chunks */ - int smblks; /* unused -- always zero */ - int hblks; /* number of mmapped regions */ - int hblkhd; /* total space in mmapped regions */ - int usmblks; /* unused -- always zero */ - int fsmblks; /* unused -- always zero */ - int uordblks; /* total allocated space */ - int fordblks; /* total non-inuse space */ - int keepcost; /* top-most, releasable (via malloc_trim) space */ -}; - -/* SVID2/XPG mallopt options */ - -#define M_MXFAST 1 /* UNUSED in this malloc */ -#define M_NLBLKS 2 /* UNUSED in this malloc */ -#define M_GRAIN 3 /* UNUSED in this malloc */ -#define M_KEEP 4 /* UNUSED in this malloc */ - -#endif - -/* mallopt options that actually do something */ - -#define M_TRIM_THRESHOLD -1 -#define M_TOP_PAD -2 -#define M_MMAP_THRESHOLD -3 -#define M_MMAP_MAX -4 - - - -#ifndef DEFAULT_TRIM_THRESHOLD -#define DEFAULT_TRIM_THRESHOLD (128 * 1024) -#endif - -/* - M_TRIM_THRESHOLD is the maximum amount of unused top-most memory - to keep before releasing via malloc_trim in free(). - - Automatic trimming is mainly useful in long-lived programs. - Because trimming via sbrk can be slow on some systems, and can - sometimes be wasteful (in cases where programs immediately - afterward allocate more large chunks) the value should be high - enough so that your overall system performance would improve by - releasing. - - The trim threshold and the mmap control parameters (see below) - can be traded off with one another. Trimming and mmapping are - two different ways of releasing unused memory back to the - system. Between these two, it is often possible to keep - system-level demands of a long-lived program down to a bare - minimum. For example, in one test suite of sessions measuring - the XF86 X server on Linux, using a trim threshold of 128K and a - mmap threshold of 192K led to near-minimal long term resource - consumption. - - If you are using this malloc in a long-lived program, it should - pay to experiment with these values. As a rough guide, you - might set to a value close to the average size of a process - (program) running on your system. Releasing this much memory - would allow such a process to run in memory. Generally, it's - worth it to tune for trimming rather tham memory mapping when a - program undergoes phases where several large chunks are - allocated and released in ways that can reuse each other's - storage, perhaps mixed with phases where there are no such - chunks at all. And in well-behaved long-lived programs, - controlling release of large blocks via trimming versus mapping - is usually faster. - - However, in most programs, these parameters serve mainly as - protection against the system-level effects of carrying around - massive amounts of unneeded memory. Since frequent calls to - sbrk, mmap, and munmap otherwise degrade performance, the default - parameters are set to relatively high values that serve only as - safeguards. - - The default trim value is high enough to cause trimming only in - fairly extreme (by current memory consumption standards) cases. - It must be greater than page size to have any useful effect. To - disable trimming completely, you can set to (unsigned long)(-1); - - -*/ - - -#ifndef DEFAULT_TOP_PAD -#define DEFAULT_TOP_PAD (0) -#endif - -/* - M_TOP_PAD is the amount of extra `padding' space to allocate or - retain whenever sbrk is called. It is used in two ways internally: - - * When sbrk is called to extend the top of the arena to satisfy - a new malloc request, this much padding is added to the sbrk - request. - - * When malloc_trim is called automatically from free(), - it is used as the `pad' argument. - - In both cases, the actual amount of padding is rounded - so that the end of the arena is always a system page boundary. - - The main reason for using padding is to avoid calling sbrk so - often. Having even a small pad greatly reduces the likelihood - that nearly every malloc request during program start-up (or - after trimming) will invoke sbrk, which needlessly wastes - time. - - Automatic rounding-up to page-size units is normally sufficient - to avoid measurable overhead, so the default is 0. However, in - systems where sbrk is relatively slow, it can pay to increase - this value, at the expense of carrying around more memory than - the program needs. - -*/ - - -#ifndef DEFAULT_MMAP_THRESHOLD -#define DEFAULT_MMAP_THRESHOLD (128 * 1024) -#endif - -/* - - M_MMAP_THRESHOLD is the request size threshold for using mmap() - to service a request. Requests of at least this size that cannot - be allocated using already-existing space will be serviced via mmap. - (If enough normal freed space already exists it is used instead.) - - Using mmap segregates relatively large chunks of memory so that - they can be individually obtained and released from the host - system. A request serviced through mmap is never reused by any - other request (at least not directly; the system may just so - happen to remap successive requests to the same locations). - - Segregating space in this way has the benefit that mmapped space - can ALWAYS be individually released back to the system, which - helps keep the system level memory demands of a long-lived - program low. Mapped memory can never become `locked' between - other chunks, as can happen with normally allocated chunks, which - menas that even trimming via malloc_trim would not release them. - - However, it has the disadvantages that: - - 1. The space cannot be reclaimed, consolidated, and then - used to service later requests, as happens with normal chunks. - 2. It can lead to more wastage because of mmap page alignment - requirements - 3. It causes malloc performance to be more dependent on host - system memory management support routines which may vary in - implementation quality and may impose arbitrary - limitations. Generally, servicing a request via normal - malloc steps is faster than going through a system's mmap. - - All together, these considerations should lead you to use mmap - only for relatively large requests. - - -*/ - - - -#ifndef DEFAULT_MMAP_MAX -#if HAVE_MMAP -#define DEFAULT_MMAP_MAX (64) -#else -#define DEFAULT_MMAP_MAX (0) -#endif -#endif - -/* - M_MMAP_MAX is the maximum number of requests to simultaneously - service using mmap. This parameter exists because: - - 1. Some systems have a limited number of internal tables for - use by mmap. - 2. In most systems, overreliance on mmap can degrade overall - performance. - 3. If a program allocates many large regions, it is probably - better off using normal sbrk-based allocation routines that - can reclaim and reallocate normal heap memory. Using a - small value allows transition into this mode after the - first few allocations. - - Setting to 0 disables all use of mmap. If HAVE_MMAP is not set, - the default value is 0, and attempts to set it to non-zero values - in mallopt will fail. -*/ - - - - -/* - - Special defines for linux libc - - Except when compiled using these special defines for Linux libc - using weak aliases, this malloc is NOT designed to work in - multithreaded applications. No semaphores or other concurrency - control are provided to ensure that multiple malloc or free calls - don't run at the same time, which could be disasterous. A single - semaphore could be used across malloc, realloc, and free (which is - essentially the effect of the linux weak alias approach). It would - be hard to obtain finer granularity. - -*/ - - -#ifdef INTERNAL_LINUX_C_LIB - -#if __STD_C - -Void_t * __default_morecore_init (ptrdiff_t); -Void_t *(*__morecore)(ptrdiff_t) = __default_morecore_init; - -#else - -Void_t * __default_morecore_init (); -Void_t *(*__morecore)() = __default_morecore_init; - -#endif - -#define MORECORE (*__morecore) -#define MORECORE_FAILURE 0 -#define MORECORE_CLEARS 1 - -#else /* INTERNAL_LINUX_C_LIB */ - -#if __STD_C -extern Void_t* sbrk(ptrdiff_t); -#else -extern Void_t* sbrk(); -#endif - -#ifndef MORECORE -#define MORECORE sbrk -#endif - -#ifndef MORECORE_FAILURE -#define MORECORE_FAILURE -1 -#endif - -#ifndef MORECORE_CLEARS -#define MORECORE_CLEARS 1 -#endif - -#endif /* INTERNAL_LINUX_C_LIB */ - -#if defined(INTERNAL_LINUX_C_LIB) && defined(__ELF__) - -#define cALLOc __libc_calloc -#define fREe __libc_free -#define mALLOc __libc_malloc -#define mEMALIGn __libc_memalign -#define rEALLOc __libc_realloc -#define vALLOc __libc_valloc -#define pvALLOc __libc_pvalloc -#define mALLINFo __libc_mallinfo -#define mALLOPt __libc_mallopt - -#pragma weak calloc = __libc_calloc -#pragma weak free = __libc_free -#pragma weak cfree = __libc_free -#pragma weak malloc = __libc_malloc -#pragma weak memalign = __libc_memalign -#pragma weak realloc = __libc_realloc -#pragma weak valloc = __libc_valloc -#pragma weak pvalloc = __libc_pvalloc -#pragma weak mallinfo = __libc_mallinfo -#pragma weak mallopt = __libc_mallopt - -#else - - -#define cALLOc calloc -#define fREe free -#define mALLOc malloc -#define mEMALIGn memalign -#define rEALLOc realloc -#define vALLOc valloc -#define pvALLOc pvalloc -#define mALLINFo mallinfo -#define mALLOPt mallopt - -#endif - -/* Public routines */ - -#if __STD_C - -Void_t* mALLOc(size_t); -void fREe(Void_t*); -Void_t* rEALLOc(Void_t*, size_t); -Void_t* mEMALIGn(size_t, size_t); -Void_t* vALLOc(size_t); -Void_t* pvALLOc(size_t); -Void_t* cALLOc(size_t, size_t); -void cfree(Void_t*); -int malloc_trim(size_t); -size_t malloc_usable_size(Void_t*); -void malloc_stats(); -int mALLOPt(int, int); -struct mallinfo mALLINFo(void); -#else -Void_t* mALLOc(); -void fREe(); -Void_t* rEALLOc(); -Void_t* mEMALIGn(); -Void_t* vALLOc(); -Void_t* pvALLOc(); -Void_t* cALLOc(); -void cfree(); -int malloc_trim(); -size_t malloc_usable_size(); -void malloc_stats(); -int mALLOPt(); -struct mallinfo mALLINFo(); -#endif - - -#ifdef __cplusplus -}; /* end of extern "C" */ -#endif - -/* ---------- To make a malloc.h, end cutting here ------------ */ - - -/* - Emulation of sbrk for WIN32 - All code within the ifdef WIN32 is untested by me. -*/ - - -#ifdef WIN32 - -#define AlignPage(add) (((add) + (malloc_getpagesize-1)) & -~(malloc_getpagesize-1)) - -/* resrve 64MB to insure large contiguous space */ -#define RESERVED_SIZE (1024*1024*64) -#define NEXT_SIZE (2048*1024) -#define TOP_MEMORY ((unsigned long)2*1024*1024*1024) - -struct GmListElement; -typedef struct GmListElement GmListElement; - -struct GmListElement -{ - GmListElement* next; - void* base; -}; - -static GmListElement* head = 0; -static unsigned int gNextAddress = 0; -static unsigned int gAddressBase = 0; -static unsigned int gAllocatedSize = 0; - -static -GmListElement* makeGmListElement (void* bas) -{ - GmListElement* this; - this = (GmListElement*)(void*)LocalAlloc (0, sizeof (GmListElement)); - ASSERT (this); - if (this) - { - this->base = bas; - this->next = head; - head = this; - } - return this; -} - -void gcleanup () -{ - BOOL rval; - ASSERT ( (head == NULL) || (head->base == (void*)gAddressBase)); - if (gAddressBase && (gNextAddress - gAddressBase)) - { - rval = VirtualFree ((void*)gAddressBase, - gNextAddress - gAddressBase, - MEM_DECOMMIT); - ASSERT (rval); - } - while (head) - { - GmListElement* next = head->next; - rval = VirtualFree (head->base, 0, MEM_RELEASE); - ASSERT (rval); - LocalFree (head); - head = next; - } -} - -static -void* findRegion (void* start_address, unsigned long size) -{ - MEMORY_BASIC_INFORMATION info; - while ((unsigned long)start_address < TOP_MEMORY) - { - VirtualQuery (start_address, &info, sizeof (info)); - if (info.State != MEM_FREE) - start_address = (char*)info.BaseAddress + info.RegionSize; - else if (info.RegionSize >= size) - return start_address; - else - start_address = (char*)info.BaseAddress + info.RegionSize; - } - return NULL; - -} - - -void* wsbrk (long size) -{ - void* tmp; - if (size > 0) - { - if (gAddressBase == 0) - { - gAllocatedSize = max (RESERVED_SIZE, AlignPage (size)); - gNextAddress = gAddressBase = - (unsigned int)VirtualAlloc (NULL, gAllocatedSize, - MEM_RESERVE, PAGE_NOACCESS); - } else if (AlignPage (gNextAddress + size) > (gAddressBase + -gAllocatedSize)) - { - long new_size = max (NEXT_SIZE, AlignPage (size)); - void* new_address = (void*)(gAddressBase+gAllocatedSize); - do - { - new_address = findRegion (new_address, new_size); - - if (new_address == 0) - return (void*)-1; - - gAddressBase = gNextAddress = - (unsigned int)VirtualAlloc (new_address, new_size, - MEM_RESERVE, PAGE_NOACCESS); - // repeat in case of race condition - // The region that we found has been snagged - // by another thread - } - while (gAddressBase == 0); - - ASSERT (new_address == (void*)gAddressBase); - - gAllocatedSize = new_size; - - if (!makeGmListElement ((void*)gAddressBase)) - return (void*)-1; - } - if ((size + gNextAddress) > AlignPage (gNextAddress)) - { - void* res; - res = VirtualAlloc ((void*)AlignPage (gNextAddress), - (size + gNextAddress - - AlignPage (gNextAddress)), - MEM_COMMIT, PAGE_READWRITE); - if (res == 0) - return (void*)-1; - } - tmp = (void*)gNextAddress; - gNextAddress = (unsigned int)tmp + size; - return tmp; - } - else if (size < 0) - { - unsigned int alignedGoal = AlignPage (gNextAddress + size); - /* Trim by releasing the virtual memory */ - if (alignedGoal >= gAddressBase) - { - VirtualFree ((void*)alignedGoal, gNextAddress - alignedGoal, - MEM_DECOMMIT); - gNextAddress = gNextAddress + size; - return (void*)gNextAddress; - } - else - { - VirtualFree ((void*)gAddressBase, gNextAddress - gAddressBase, - MEM_DECOMMIT); - gNextAddress = gAddressBase; - return (void*)-1; - } - } - else - { - return (void*)gNextAddress; - } -} - -#endif - - - -/* - Type declarations -*/ - - -struct malloc_chunk -{ - INTERNAL_SIZE_T prev_size; /* Size of previous chunk (if free). */ - INTERNAL_SIZE_T size; /* Size in bytes, including overhead. */ - struct malloc_chunk* fd; /* double links -- used only if free. */ - struct malloc_chunk* bk; -}; - -typedef struct malloc_chunk* mchunkptr; - -/* - - malloc_chunk details: - - (The following includes lightly edited explanations by Colin Plumb.) - - Chunks of memory are maintained using a `boundary tag' method as - described in e.g., Knuth or Standish. (See the paper by Paul - Wilson ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps for a - survey of such techniques.) Sizes of free chunks are stored both - in the front of each chunk and at the end. This makes - consolidating fragmented chunks into bigger chunks very fast. The - size fields also hold bits representing whether chunks are free or - in use. - - An allocated chunk looks like this: - - - chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of previous chunk, if allocated | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of chunk, in bytes |P| - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | User data starts here... . - . . - . (malloc_usable_space() bytes) . - . | -nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - - Where "chunk" is the front of the chunk for the purpose of most of - the malloc code, but "mem" is the pointer that is returned to the - user. "Nextchunk" is the beginning of the next contiguous chunk. - - Chunks always begin on even word boundries, so the mem portion - (which is returned to the user) is also on an even word boundary, and - thus double-word aligned. - - Free chunks are stored in circular doubly-linked lists, and look like this: - - chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of previous chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - `head:' | Size of chunk, in bytes |P| - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Forward pointer to next chunk in list | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Back pointer to previous chunk in list | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Unused space (may be 0 bytes long) . - . . - . | -nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - `foot:' | Size of chunk, in bytes | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - The P (PREV_INUSE) bit, stored in the unused low-order bit of the - chunk size (which is always a multiple of two words), is an in-use - bit for the *previous* chunk. If that bit is *clear*, then the - word before the current chunk size contains the previous chunk - size, and can be used to find the front of the previous chunk. - (The very first chunk allocated always has this bit set, - preventing access to non-existent (or non-owned) memory.) - - Note that the `foot' of the current chunk is actually represented - as the prev_size of the NEXT chunk. (This makes it easier to - deal with alignments etc). - - The two exceptions to all this are - - 1. The special chunk `top', which doesn't bother using the - trailing size field since there is no - next contiguous chunk that would have to index off it. (After - initialization, `top' is forced to always exist. If it would - become less than MINSIZE bytes long, it is replenished via - malloc_extend_top.) - - 2. Chunks allocated via mmap, which have the second-lowest-order - bit (IS_MMAPPED) set in their size fields. Because they are - never merged or traversed from any other chunk, they have no - foot size or inuse information. - - Available chunks are kept in any of several places (all declared below): - - * `av': An array of chunks serving as bin headers for consolidated - chunks. Each bin is doubly linked. The bins are approximately - proportionally (log) spaced. There are a lot of these bins - (128). This may look excessive, but works very well in - practice. All procedures maintain the invariant that no - consolidated chunk physically borders another one. Chunks in - bins are kept in size order, with ties going to the - approximately least recently used chunk. - - The chunks in each bin are maintained in decreasing sorted order by - size. This is irrelevant for the small bins, which all contain - the same-sized chunks, but facilitates best-fit allocation for - larger chunks. (These lists are just sequential. Keeping them in - order almost never requires enough traversal to warrant using - fancier ordered data structures.) Chunks of the same size are - linked with the most recently freed at the front, and allocations - are taken from the back. This results in LRU or FIFO allocation - order, which tends to give each chunk an equal opportunity to be - consolidated with adjacent freed chunks, resulting in larger free - chunks and less fragmentation. - - * `top': The top-most available chunk (i.e., the one bordering the - end of available memory) is treated specially. It is never - included in any bin, is used only if no other chunk is - available, and is released back to the system if it is very - large (see M_TRIM_THRESHOLD). - - * `last_remainder': A bin holding only the remainder of the - most recently split (non-top) chunk. This bin is checked - before other non-fitting chunks, so as to provide better - locality for runs of sequentially allocated chunks. - - * Implicitly, through the host system's memory mapping tables. - If supported, requests greater than a threshold are usually - serviced via calls to mmap, and then later released via munmap. - -*/ - - - - - - -/* sizes, alignments */ - -#define SIZE_SZ (sizeof(INTERNAL_SIZE_T)) -#define MALLOC_ALIGNMENT (SIZE_SZ + SIZE_SZ) -#define MALLOC_ALIGN_MASK (MALLOC_ALIGNMENT - 1) -#define MINSIZE (sizeof(struct malloc_chunk)) - -/* conversion from malloc headers to user pointers, and back */ - -#define chunk2mem(p) ((Void_t*)((char*)(p) + 2*SIZE_SZ)) -#define mem2chunk(mem) ((mchunkptr)((char*)(mem) - 2*SIZE_SZ)) - -/* pad request bytes into a usable size */ - -#define request2size(req) \ - (((long)((req) + (SIZE_SZ + MALLOC_ALIGN_MASK)) < \ - (long)(MINSIZE + MALLOC_ALIGN_MASK)) ? MINSIZE : \ - (((req) + (SIZE_SZ + MALLOC_ALIGN_MASK)) & ~(MALLOC_ALIGN_MASK))) - -/* Check if m has acceptable alignment */ - -#define aligned_OK(m) (((unsigned long)((m)) & (MALLOC_ALIGN_MASK)) == 0) - - - - -/* - Physical chunk operations -*/ - - -/* size field is or'ed with PREV_INUSE when previous adjacent chunk in use */ - -#define PREV_INUSE 0x1 - -/* size field is or'ed with IS_MMAPPED if the chunk was obtained with mmap() */ - -#define IS_MMAPPED 0x2 - -/* Bits to mask off when extracting size */ - -#define SIZE_BITS (PREV_INUSE|IS_MMAPPED) - - -/* Ptr to next physical malloc_chunk. */ - -#define next_chunk(p) ((mchunkptr)( ((char*)(p)) + ((p)->size & ~PREV_INUSE) )) - -/* Ptr to previous physical malloc_chunk */ - -#define prev_chunk(p)\ - ((mchunkptr)( ((char*)(p)) - ((p)->prev_size) )) - - -/* Treat space at ptr + offset as a chunk */ - -#define chunk_at_offset(p, s) ((mchunkptr)(((char*)(p)) + (s))) - - - - -/* - Dealing with use bits -*/ - -/* extract p's inuse bit */ - -#define inuse(p)\ -((((mchunkptr)(((char*)(p))+((p)->size & ~PREV_INUSE)))->size) & PREV_INUSE) - -/* extract inuse bit of previous chunk */ - -#define prev_inuse(p) ((p)->size & PREV_INUSE) - -/* check for mmap()'ed chunk */ - -#define chunk_is_mmapped(p) ((p)->size & IS_MMAPPED) - -/* set/clear chunk as in use without otherwise disturbing */ - -#define set_inuse(p)\ -((mchunkptr)(((char*)(p)) + ((p)->size & ~PREV_INUSE)))->size |= PREV_INUSE - -#define clear_inuse(p)\ -((mchunkptr)(((char*)(p)) + ((p)->size & ~PREV_INUSE)))->size &= ~(PREV_INUSE) - -/* check/set/clear inuse bits in known places */ - -#define inuse_bit_at_offset(p, s)\ - (((mchunkptr)(((char*)(p)) + (s)))->size & PREV_INUSE) - -#define set_inuse_bit_at_offset(p, s)\ - (((mchunkptr)(((char*)(p)) + (s)))->size |= PREV_INUSE) - -#define clear_inuse_bit_at_offset(p, s)\ - (((mchunkptr)(((char*)(p)) + (s)))->size &= ~(PREV_INUSE)) - - - - -/* - Dealing with size fields -*/ - -/* Get size, ignoring use bits */ - -#define chunksize(p) ((p)->size & ~(SIZE_BITS)) - -/* Set size at head, without disturbing its use bit */ - -#define set_head_size(p, s) ((p)->size = (((p)->size & PREV_INUSE) | (s))) - -/* Set size/use ignoring previous bits in header */ - -#define set_head(p, s) ((p)->size = (s)) - -/* Set size at footer (only when chunk is not in use) */ - -#define set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_size = (s)) - - - - - -/* - Bins - - The bins, `av_' are an array of pairs of pointers serving as the - heads of (initially empty) doubly-linked lists of chunks, laid out - in a way so that each pair can be treated as if it were in a - malloc_chunk. (This way, the fd/bk offsets for linking bin heads - and chunks are the same). - - Bins for sizes < 512 bytes contain chunks of all the same size, spaced - 8 bytes apart. Larger bins are approximately logarithmically - spaced. (See the table below.) The `av_' array is never mentioned - directly in the code, but instead via bin access macros. - - Bin layout: - - 64 bins of size 8 - 32 bins of size 64 - 16 bins of size 512 - 8 bins of size 4096 - 4 bins of size 32768 - 2 bins of size 262144 - 1 bin of size what's left - - There is actually a little bit of slop in the numbers in bin_index - for the sake of speed. This makes no difference elsewhere. - - The special chunks `top' and `last_remainder' get their own bins, - (this is implemented via yet more trickery with the av_ array), - although `top' is never properly linked to its bin since it is - always handled specially. - -*/ - -#define NAV 128 /* number of bins */ - -typedef struct malloc_chunk* mbinptr; - -/* access macros */ - -#define bin_at(i) ((mbinptr)((char*)&(av_[2*(i) + 2]) - 2*SIZE_SZ)) -#define next_bin(b) ((mbinptr)((char*)(b) + 2 * sizeof(mbinptr))) -#define prev_bin(b) ((mbinptr)((char*)(b) - 2 * sizeof(mbinptr))) - -/* - The first 2 bins are never indexed. The corresponding av_ cells are instead - used for bookkeeping. This is not to save space, but to simplify - indexing, maintain locality, and avoid some initialization tests. -*/ - -#define top (bin_at(0)->fd) /* The topmost chunk */ -#define last_remainder (bin_at(1)) /* remainder from last split */ - - -/* - Because top initially points to its own bin with initial - zero size, thus forcing extension on the first malloc request, - we avoid having any special code in malloc to check whether - it even exists yet. But we still need to in malloc_extend_top. -*/ - -#define initial_top ((mchunkptr)(bin_at(0))) - -/* Helper macro to initialize bins */ - -#define IAV(i) bin_at(i), bin_at(i) - -static mbinptr av_[NAV * 2 + 2] = { - 0, 0, - IAV(0), IAV(1), IAV(2), IAV(3), IAV(4), IAV(5), IAV(6), IAV(7), - IAV(8), IAV(9), IAV(10), IAV(11), IAV(12), IAV(13), IAV(14), IAV(15), - IAV(16), IAV(17), IAV(18), IAV(19), IAV(20), IAV(21), IAV(22), IAV(23), - IAV(24), IAV(25), IAV(26), IAV(27), IAV(28), IAV(29), IAV(30), IAV(31), - IAV(32), IAV(33), IAV(34), IAV(35), IAV(36), IAV(37), IAV(38), IAV(39), - IAV(40), IAV(41), IAV(42), IAV(43), IAV(44), IAV(45), IAV(46), IAV(47), - IAV(48), IAV(49), IAV(50), IAV(51), IAV(52), IAV(53), IAV(54), IAV(55), - IAV(56), IAV(57), IAV(58), IAV(59), IAV(60), IAV(61), IAV(62), IAV(63), - IAV(64), IAV(65), IAV(66), IAV(67), IAV(68), IAV(69), IAV(70), IAV(71), - IAV(72), IAV(73), IAV(74), IAV(75), IAV(76), IAV(77), IAV(78), IAV(79), - IAV(80), IAV(81), IAV(82), IAV(83), IAV(84), IAV(85), IAV(86), IAV(87), - IAV(88), IAV(89), IAV(90), IAV(91), IAV(92), IAV(93), IAV(94), IAV(95), - IAV(96), IAV(97), IAV(98), IAV(99), IAV(100), IAV(101), IAV(102), IAV(103), - IAV(104), IAV(105), IAV(106), IAV(107), IAV(108), IAV(109), IAV(110), IAV(111), - IAV(112), IAV(113), IAV(114), IAV(115), IAV(116), IAV(117), IAV(118), IAV(119), - IAV(120), IAV(121), IAV(122), IAV(123), IAV(124), IAV(125), IAV(126), IAV(127) -}; - - - -/* field-extraction macros */ - -#define first(b) ((b)->fd) -#define last(b) ((b)->bk) - -/* - Indexing into bins -*/ - -#define bin_index(sz) \ -(((((unsigned long)(sz)) >> 9) == 0) ? (((unsigned long)(sz)) >> 3): \ - ((((unsigned long)(sz)) >> 9) <= 4) ? 56 + (((unsigned long)(sz)) >> 6): \ - ((((unsigned long)(sz)) >> 9) <= 20) ? 91 + (((unsigned long)(sz)) >> 9): \ - ((((unsigned long)(sz)) >> 9) <= 84) ? 110 + (((unsigned long)(sz)) >> 12): \ - ((((unsigned long)(sz)) >> 9) <= 340) ? 119 + (((unsigned long)(sz)) >> 15): \ - ((((unsigned long)(sz)) >> 9) <= 1364) ? 124 + (((unsigned long)(sz)) >> 18): \ - 126) -/* - bins for chunks < 512 are all spaced 8 bytes apart, and hold - identically sized chunks. This is exploited in malloc. -*/ - -#define MAX_SMALLBIN 63 -#define MAX_SMALLBIN_SIZE 512 -#define SMALLBIN_WIDTH 8 - -#define smallbin_index(sz) (((unsigned long)(sz)) >> 3) - -/* - Requests are `small' if both the corresponding and the next bin are small -*/ - -#define is_small_request(nb) (nb < MAX_SMALLBIN_SIZE - SMALLBIN_WIDTH) - - - -/* - To help compensate for the large number of bins, a one-level index - structure is used for bin-by-bin searching. `binblocks' is a - one-word bitvector recording whether groups of BINBLOCKWIDTH bins - have any (possibly) non-empty bins, so they can be skipped over - all at once during during traversals. The bits are NOT always - cleared as soon as all bins in a block are empty, but instead only - when all are noticed to be empty during traversal in malloc. -*/ - -#define BINBLOCKWIDTH 4 /* bins per block */ - -#define binblocks (bin_at(0)->size) /* bitvector of nonempty blocks */ - -/* bin<->block macros */ - -#define idx2binblock(ix) ((unsigned)1 << (ix / BINBLOCKWIDTH)) -#define mark_binblock(ii) (binblocks |= idx2binblock(ii)) -#define clear_binblock(ii) (binblocks &= ~(idx2binblock(ii))) - - - - - -/* Other static bookkeeping data */ - -/* variables holding tunable values */ - -static unsigned long trim_threshold = DEFAULT_TRIM_THRESHOLD; -static unsigned long top_pad = DEFAULT_TOP_PAD; -static unsigned int n_mmaps_max = DEFAULT_MMAP_MAX; -static unsigned long mmap_threshold = DEFAULT_MMAP_THRESHOLD; - -/* The first value returned from sbrk */ -static char* sbrk_base = (char*)(-1); - -/* The maximum memory obtained from system via sbrk */ -static unsigned long max_sbrked_mem = 0; - -/* The maximum via either sbrk or mmap */ -static unsigned long max_total_mem = 0; - -/* internal working copy of mallinfo */ -static struct mallinfo current_mallinfo = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -/* The total memory obtained from system via sbrk */ -#define sbrked_mem (current_mallinfo.arena) - -/* Tracking mmaps */ - -static unsigned int n_mmaps = 0; -static unsigned int max_n_mmaps = 0; -static unsigned long mmapped_mem = 0; -static unsigned long max_mmapped_mem = 0; - - - -/* - Debugging support -*/ - -#if DEBUG - - -/* - These routines make a number of assertions about the states - of data structures that should be true at all times. If any - are not true, it's very likely that a user program has somehow - trashed memory. (It's also possible that there is a coding error - in malloc. In which case, please report it!) -*/ - -#if __STD_C -static void do_check_chunk(mchunkptr p) -#else -static void do_check_chunk(p) mchunkptr p; -#endif -{ - INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE; - - /* No checkable chunk is mmapped */ - assert(!chunk_is_mmapped(p)); - - /* Check for legal address ... */ - assert((char*)p >= sbrk_base); - if (p != top) - assert((char*)p + sz <= (char*)top); - else - assert((char*)p + sz <= sbrk_base + sbrked_mem); - -} - - -#if __STD_C -static void do_check_free_chunk(mchunkptr p) -#else -static void do_check_free_chunk(p) mchunkptr p; -#endif -{ - INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE; - mchunkptr next = chunk_at_offset(p, sz); - - do_check_chunk(p); - - /* Check whether it claims to be free ... */ - assert(!inuse(p)); - - /* Unless a special marker, must have OK fields */ - if ((long)sz >= (long)MINSIZE) - { - assert((sz & MALLOC_ALIGN_MASK) == 0); - assert(aligned_OK(chunk2mem(p))); - /* ... matching footer field */ - assert(next->prev_size == sz); - /* ... and is fully consolidated */ - assert(prev_inuse(p)); - assert (next == top || inuse(next)); - - /* ... and has minimally sane links */ - assert(p->fd->bk == p); - assert(p->bk->fd == p); - } - else /* markers are always of size SIZE_SZ */ - assert(sz == SIZE_SZ); -} - -#if __STD_C -static void do_check_inuse_chunk(mchunkptr p) -#else -static void do_check_inuse_chunk(p) mchunkptr p; -#endif -{ - mchunkptr next = next_chunk(p); - do_check_chunk(p); - - /* Check whether it claims to be in use ... */ - assert(inuse(p)); - - /* ... and is surrounded by OK chunks. - Since more things can be checked with free chunks than inuse ones, - if an inuse chunk borders them and debug is on, it's worth doing them. - */ - if (!prev_inuse(p)) - { - mchunkptr prv = prev_chunk(p); - assert(next_chunk(prv) == p); - do_check_free_chunk(prv); - } - if (next == top) - { - assert(prev_inuse(next)); - assert(chunksize(next) >= MINSIZE); - } - else if (!inuse(next)) - do_check_free_chunk(next); - -} - -#if __STD_C -static void do_check_malloced_chunk(mchunkptr p, INTERNAL_SIZE_T s) -#else -static void do_check_malloced_chunk(p, s) mchunkptr p; INTERNAL_SIZE_T s; -#endif -{ - INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE; - long room = sz - s; - - do_check_inuse_chunk(p); - - /* Legal size ... */ - assert((long)sz >= (long)MINSIZE); - assert((sz & MALLOC_ALIGN_MASK) == 0); - assert(room >= 0); - assert(room < (long)MINSIZE); - - /* ... and alignment */ - assert(aligned_OK(chunk2mem(p))); - - - /* ... and was allocated at front of an available chunk */ - assert(prev_inuse(p)); - -} - - -#define check_free_chunk(P) do_check_free_chunk(P) -#define check_inuse_chunk(P) do_check_inuse_chunk(P) -#define check_chunk(P) do_check_chunk(P) -#define check_malloced_chunk(P,N) do_check_malloced_chunk(P,N) -#else -#define check_free_chunk(P) -#define check_inuse_chunk(P) -#define check_chunk(P) -#define check_malloced_chunk(P,N) -#endif - - - -/* - Macro-based internal utilities -*/ - - -/* - Linking chunks in bin lists. - Call these only with variables, not arbitrary expressions, as arguments. -*/ - -/* - Place chunk p of size s in its bin, in size order, - putting it ahead of others of same size. -*/ - - -#define frontlink(P, S, IDX, BK, FD) \ -{ \ - if (S < MAX_SMALLBIN_SIZE) \ - { \ - IDX = smallbin_index(S); \ - mark_binblock(IDX); \ - BK = bin_at(IDX); \ - FD = BK->fd; \ - P->bk = BK; \ - P->fd = FD; \ - FD->bk = BK->fd = P; \ - } \ - else \ - { \ - IDX = bin_index(S); \ - BK = bin_at(IDX); \ - FD = BK->fd; \ - if (FD == BK) mark_binblock(IDX); \ - else \ - { \ - while (FD != BK && S < chunksize(FD)) FD = FD->fd; \ - BK = FD->bk; \ - } \ - P->bk = BK; \ - P->fd = FD; \ - FD->bk = BK->fd = P; \ - } \ -} - - -/* take a chunk off a list */ - -#define unlink(P, BK, FD) \ -{ \ - BK = P->bk; \ - FD = P->fd; \ - FD->bk = BK; \ - BK->fd = FD; \ -} \ - -/* Place p as the last remainder */ - -#define link_last_remainder(P) \ -{ \ - last_remainder->fd = last_remainder->bk = P; \ - P->fd = P->bk = last_remainder; \ -} - -/* Clear the last_remainder bin */ - -#define clear_last_remainder \ - (last_remainder->fd = last_remainder->bk = last_remainder) - - - - - - -/* Routines dealing with mmap(). */ - -#if HAVE_MMAP - -#if __STD_C -static mchunkptr mmap_chunk(size_t size) -#else -static mchunkptr mmap_chunk(size) size_t size; -#endif -{ - size_t page_mask = malloc_getpagesize - 1; - mchunkptr p; - -#ifndef MAP_ANONYMOUS - static int fd = -1; -#endif - - if(n_mmaps >= n_mmaps_max) return 0; /* too many regions */ - - /* For mmapped chunks, the overhead is one SIZE_SZ unit larger, because - * there is no following chunk whose prev_size field could be used. - */ - size = (size + SIZE_SZ + page_mask) & ~page_mask; - -#ifdef MAP_ANONYMOUS - p = (mchunkptr)mmap(0, size, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); -#else /* !MAP_ANONYMOUS */ - if (fd < 0) - { - fd = open("/dev/zero", O_RDWR); - if(fd < 0) return 0; - } - p = (mchunkptr)mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); -#endif - - if(p == (mchunkptr)-1) return 0; - - n_mmaps++; - if (n_mmaps > max_n_mmaps) max_n_mmaps = n_mmaps; - - /* We demand that eight bytes into a page must be 8-byte aligned. */ - assert(aligned_OK(chunk2mem(p))); - - /* The offset to the start of the mmapped region is stored - * in the prev_size field of the chunk; normally it is zero, - * but that can be changed in memalign(). - */ - p->prev_size = 0; - set_head(p, size|IS_MMAPPED); - - mmapped_mem += size; - if ((unsigned long)mmapped_mem > (unsigned long)max_mmapped_mem) - max_mmapped_mem = mmapped_mem; - if ((unsigned long)(mmapped_mem + sbrked_mem) > (unsigned long)max_total_mem) - max_total_mem = mmapped_mem + sbrked_mem; - return p; -} - -#if __STD_C -static void munmap_chunk(mchunkptr p) -#else -static void munmap_chunk(p) mchunkptr p; -#endif -{ - INTERNAL_SIZE_T size = chunksize(p); - int ret; - - assert (chunk_is_mmapped(p)); - assert(! ((char*)p >= sbrk_base && (char*)p < sbrk_base + sbrked_mem)); - assert((n_mmaps > 0)); - assert(((p->prev_size + size) & (malloc_getpagesize-1)) == 0); - - n_mmaps--; - mmapped_mem -= (size + p->prev_size); - - ret = munmap((char *)p - p->prev_size, size + p->prev_size); - - /* munmap returns non-zero on failure */ - assert(ret == 0); -} - -#if HAVE_MREMAP - -#if __STD_C -static mchunkptr mremap_chunk(mchunkptr p, size_t new_size) -#else -static mchunkptr mremap_chunk(p, new_size) mchunkptr p; size_t new_size; -#endif -{ - size_t page_mask = malloc_getpagesize - 1; - INTERNAL_SIZE_T offset = p->prev_size; - INTERNAL_SIZE_T size = chunksize(p); - char *cp; - - assert (chunk_is_mmapped(p)); - assert(! ((char*)p >= sbrk_base && (char*)p < sbrk_base + sbrked_mem)); - assert((n_mmaps > 0)); - assert(((size + offset) & (malloc_getpagesize-1)) == 0); - - /* Note the extra SIZE_SZ overhead as in mmap_chunk(). */ - new_size = (new_size + offset + SIZE_SZ + page_mask) & ~page_mask; - - cp = (char *)mremap((char *)p - offset, size + offset, new_size, 1); - - if (cp == (char *)-1) return 0; - - p = (mchunkptr)(cp + offset); - - assert(aligned_OK(chunk2mem(p))); - - assert((p->prev_size == offset)); - set_head(p, (new_size - offset)|IS_MMAPPED); - - mmapped_mem -= size + offset; - mmapped_mem += new_size; - if ((unsigned long)mmapped_mem > (unsigned long)max_mmapped_mem) - max_mmapped_mem = mmapped_mem; - if ((unsigned long)(mmapped_mem + sbrked_mem) > (unsigned long)max_total_mem) - max_total_mem = mmapped_mem + sbrked_mem; - return p; -} - -#endif /* HAVE_MREMAP */ - -#endif /* HAVE_MMAP */ - - - - -/* - Extend the top-most chunk by obtaining memory from system. - Main interface to sbrk (but see also malloc_trim). -*/ - -#if __STD_C -static void malloc_extend_top(INTERNAL_SIZE_T nb) -#else -static void malloc_extend_top(nb) INTERNAL_SIZE_T nb; -#endif -{ - char* brk; /* return value from sbrk */ - INTERNAL_SIZE_T front_misalign; /* unusable bytes at front of sbrked space */ - INTERNAL_SIZE_T correction; /* bytes for 2nd sbrk call */ - char* new_brk; /* return of 2nd sbrk call */ - INTERNAL_SIZE_T top_size; /* new size of top chunk */ - - mchunkptr old_top = top; /* Record state of old top */ - INTERNAL_SIZE_T old_top_size = chunksize(old_top); - char* old_end = (char*)(chunk_at_offset(old_top, old_top_size)); - - /* Pad request with top_pad plus minimal overhead */ - - INTERNAL_SIZE_T sbrk_size = nb + top_pad + MINSIZE; - unsigned long pagesz = malloc_getpagesize; - - /* If not the first time through, round to preserve page boundary */ - /* Otherwise, we need to correct to a page size below anyway. */ - /* (We also correct below if an intervening foreign sbrk call.) */ - - if (sbrk_base != (char*)(-1)) - sbrk_size = (sbrk_size + (pagesz - 1)) & ~(pagesz - 1); - - brk = (char*)(MORECORE (sbrk_size)); - - /* Fail if sbrk failed or if a foreign sbrk call killed our space */ - if (brk == (char*)(MORECORE_FAILURE) || - (brk < old_end && old_top != initial_top)) - return; - - sbrked_mem += sbrk_size; - - if (brk == old_end) /* can just add bytes to current top */ - { - top_size = sbrk_size + old_top_size; - set_head(top, top_size | PREV_INUSE); - } - else - { - if (sbrk_base == (char*)(-1)) /* First time through. Record base */ - sbrk_base = brk; - else /* Someone else called sbrk(). Count those bytes as sbrked_mem. */ - sbrked_mem += brk - (char*)old_end; - - /* Guarantee alignment of first new chunk made from this space */ - front_misalign = (unsigned long)chunk2mem(brk) & MALLOC_ALIGN_MASK; - if (front_misalign > 0) - { - correction = (MALLOC_ALIGNMENT) - front_misalign; - brk += correction; - } - else - correction = 0; - - /* Guarantee the next brk will be at a page boundary */ - correction += pagesz - ((unsigned long)(brk + sbrk_size) & (pagesz - 1)); - - /* Allocate correction */ - new_brk = (char*)(MORECORE (correction)); - if (new_brk == (char*)(MORECORE_FAILURE)) return; - - sbrked_mem += correction; - - top = (mchunkptr)brk; - top_size = new_brk - brk + correction; - set_head(top, top_size | PREV_INUSE); - - if (old_top != initial_top) - { - - /* There must have been an intervening foreign sbrk call. */ - /* A double fencepost is necessary to prevent consolidation */ - - /* If not enough space to do this, then user did something very wrong */ - if (old_top_size < MINSIZE) - { - set_head(top, PREV_INUSE); /* will force null return from malloc */ - return; - } - - /* Also keep size a multiple of MALLOC_ALIGNMENT */ - old_top_size = (old_top_size - 3*SIZE_SZ) & ~MALLOC_ALIGN_MASK; - chunk_at_offset(old_top, old_top_size )->size = - SIZE_SZ|PREV_INUSE; - chunk_at_offset(old_top, old_top_size + SIZE_SZ)->size = - SIZE_SZ|PREV_INUSE; - set_head_size(old_top, old_top_size); - /* If possible, release the rest. */ - if (old_top_size >= MINSIZE) - fREe(chunk2mem(old_top)); - } - } - - if ((unsigned long)sbrked_mem > (unsigned long)max_sbrked_mem) - max_sbrked_mem = sbrked_mem; - if ((unsigned long)(mmapped_mem + sbrked_mem) > (unsigned long)max_total_mem) - max_total_mem = mmapped_mem + sbrked_mem; - - /* We always land on a page boundary */ - assert(((unsigned long)((char*)top + top_size) & (pagesz - 1)) == 0); -} - - - - -/* Main public routines */ - - -/* - Malloc Algorthim: - - The requested size is first converted into a usable form, `nb'. - This currently means to add 4 bytes overhead plus possibly more to - obtain 8-byte alignment and/or to obtain a size of at least - MINSIZE (currently 16 bytes), the smallest allocatable size. - (All fits are considered `exact' if they are within MINSIZE bytes.) - - From there, the first successful of the following steps is taken: - - 1. The bin corresponding to the request size is scanned, and if - a chunk of exactly the right size is found, it is taken. - - 2. The most recently remaindered chunk is used if it is big - enough. This is a form of (roving) first fit, used only in - the absence of exact fits. Runs of consecutive requests use - the remainder of the chunk used for the previous such request - whenever possible. This limited use of a first-fit style - allocation strategy tends to give contiguous chunks - coextensive lifetimes, which improves locality and can reduce - fragmentation in the long run. - - 3. Other bins are scanned in increasing size order, using a - chunk big enough to fulfill the request, and splitting off - any remainder. This search is strictly by best-fit; i.e., - the smallest (with ties going to approximately the least - recently used) chunk that fits is selected. - - 4. If large enough, the chunk bordering the end of memory - (`top') is split off. (This use of `top' is in accord with - the best-fit search rule. In effect, `top' is treated as - larger (and thus less well fitting) than any other available - chunk since it can be extended to be as large as necessary - (up to system limitations). - - 5. If the request size meets the mmap threshold and the - system supports mmap, and there are few enough currently - allocated mmapped regions, and a call to mmap succeeds, - the request is allocated via direct memory mapping. - - 6. Otherwise, the top of memory is extended by - obtaining more space from the system (normally using sbrk, - but definable to anything else via the MORECORE macro). - Memory is gathered from the system (in system page-sized - units) in a way that allows chunks obtained across different - sbrk calls to be consolidated, but does not require - contiguous memory. Thus, it should be safe to intersperse - mallocs with other sbrk calls. - - - All allocations are made from the the `lowest' part of any found - chunk. (The implementation invariant is that prev_inuse is - always true of any allocated chunk; i.e., that each allocated - chunk borders either a previously allocated and still in-use chunk, - or the base of its memory arena.) - -*/ - -#if __STD_C -Void_t* mALLOc(size_t bytes) -#else -Void_t* mALLOc(bytes) size_t bytes; -#endif -{ - mchunkptr victim; /* inspected/selected chunk */ - INTERNAL_SIZE_T victim_size; /* its size */ - int idx; /* index for bin traversal */ - mbinptr bin; /* associated bin */ - mchunkptr remainder; /* remainder from a split */ - long remainder_size; /* its size */ - int remainder_index; /* its bin index */ - unsigned long block; /* block traverser bit */ - int startidx; /* first bin of a traversed block */ - mchunkptr fwd; /* misc temp for linking */ - mchunkptr bck; /* misc temp for linking */ - mbinptr q; /* misc temp */ - - INTERNAL_SIZE_T nb = request2size(bytes); /* padded request size; */ - - /* Check for exact match in a bin */ - - if (is_small_request(nb)) /* Faster version for small requests */ - { - idx = smallbin_index(nb); - - /* No traversal or size check necessary for small bins. */ - - q = bin_at(idx); - victim = last(q); - - /* Also scan the next one, since it would have a remainder < MINSIZE */ - if (victim == q) - { - q = next_bin(q); - victim = last(q); - } - if (victim != q) - { - victim_size = chunksize(victim); - unlink(victim, bck, fwd); - set_inuse_bit_at_offset(victim, victim_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - idx += 2; /* Set for bin scan below. We've already scanned 2 bins. */ - - } - else - { - idx = bin_index(nb); - bin = bin_at(idx); - - for (victim = last(bin); victim != bin; victim = victim->bk) - { - victim_size = chunksize(victim); - remainder_size = victim_size - nb; - - if (remainder_size >= (long)MINSIZE) /* too big */ - { - --idx; /* adjust to rescan below after checking last remainder */ - break; - } - - else if (remainder_size >= 0) /* exact fit */ - { - unlink(victim, bck, fwd); - set_inuse_bit_at_offset(victim, victim_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - } - - ++idx; - - } - - /* Try to use the last split-off remainder */ - - if ( (victim = last_remainder->fd) != last_remainder) - { - victim_size = chunksize(victim); - remainder_size = victim_size - nb; - - if (remainder_size >= (long)MINSIZE) /* re-split */ - { - remainder = chunk_at_offset(victim, nb); - set_head(victim, nb | PREV_INUSE); - link_last_remainder(remainder); - set_head(remainder, remainder_size | PREV_INUSE); - set_foot(remainder, remainder_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - clear_last_remainder; - - if (remainder_size >= 0) /* exhaust */ - { - set_inuse_bit_at_offset(victim, victim_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - /* Else place in bin */ - - frontlink(victim, victim_size, remainder_index, bck, fwd); - } - - /* - If there are any possibly nonempty big-enough blocks, - search for best fitting chunk by scanning bins in blockwidth units. - */ - - if ( (block = idx2binblock(idx)) <= binblocks) - { - - /* Get to the first marked block */ - - if ( (block & binblocks) == 0) - { - /* force to an even block boundary */ - idx = (idx & ~(BINBLOCKWIDTH - 1)) + BINBLOCKWIDTH; - block <<= 1; - while ((block & binblocks) == 0) - { - idx += BINBLOCKWIDTH; - block <<= 1; - } - } - - /* For each possibly nonempty block ... */ - for (;;) - { - startidx = idx; /* (track incomplete blocks) */ - q = bin = bin_at(idx); - - /* For each bin in this block ... */ - do - { - /* Find and use first big enough chunk ... */ - - for (victim = last(bin); victim != bin; victim = victim->bk) - { - victim_size = chunksize(victim); - remainder_size = victim_size - nb; - - if (remainder_size >= (long)MINSIZE) /* split */ - { - remainder = chunk_at_offset(victim, nb); - set_head(victim, nb | PREV_INUSE); - unlink(victim, bck, fwd); - link_last_remainder(remainder); - set_head(remainder, remainder_size | PREV_INUSE); - set_foot(remainder, remainder_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - else if (remainder_size >= 0) /* take */ - { - set_inuse_bit_at_offset(victim, victim_size); - unlink(victim, bck, fwd); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - } - - bin = next_bin(bin); - - } while ((++idx & (BINBLOCKWIDTH - 1)) != 0); - - /* Clear out the block bit. */ - - do /* Possibly backtrack to try to clear a partial block */ - { - if ((startidx & (BINBLOCKWIDTH - 1)) == 0) - { - binblocks &= ~block; - break; - } - --startidx; - q = prev_bin(q); - } while (first(q) == q); - - /* Get to the next possibly nonempty block */ - - if ( (block <<= 1) <= binblocks && (block != 0) ) - { - while ((block & binblocks) == 0) - { - idx += BINBLOCKWIDTH; - block <<= 1; - } - } - else - break; - } - } - - - /* Try to use top chunk */ - - /* Require that there be a remainder, ensuring top always exists */ - if ( (remainder_size = chunksize(top) - nb) < (long)MINSIZE) - { - -#if HAVE_MMAP - /* If big and would otherwise need to extend, try to use mmap instead */ - if ((unsigned long)nb >= (unsigned long)mmap_threshold && - (victim = mmap_chunk(nb)) != 0) - return chunk2mem(victim); -#endif - - /* Try to extend */ - malloc_extend_top(nb); - if ( (remainder_size = chunksize(top) - nb) < (long)MINSIZE) - return 0; /* propagate failure */ - } - - victim = top; - set_head(victim, nb | PREV_INUSE); - top = chunk_at_offset(victim, nb); - set_head(top, remainder_size | PREV_INUSE); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - -} - - - - -/* - - free() algorithm : - - cases: - - 1. free(0) has no effect. - - 2. If the chunk was allocated via mmap, it is release via munmap(). - - 3. If a returned chunk borders the current high end of memory, - it is consolidated into the top, and if the total unused - topmost memory exceeds the trim threshold, malloc_trim is - called. - - 4. Other chunks are consolidated as they arrive, and - placed in corresponding bins. (This includes the case of - consolidating with the current `last_remainder'). - -*/ - - -#if __STD_C -void fREe(Void_t* mem) -#else -void fREe(mem) Void_t* mem; -#endif -{ - mchunkptr p; /* chunk corresponding to mem */ - INTERNAL_SIZE_T hd; /* its head field */ - INTERNAL_SIZE_T sz; /* its size */ - int idx; /* its bin index */ - mchunkptr next; /* next contiguous chunk */ - INTERNAL_SIZE_T nextsz; /* its size */ - INTERNAL_SIZE_T prevsz; /* size of previous contiguous chunk */ - mchunkptr bck; /* misc temp for linking */ - mchunkptr fwd; /* misc temp for linking */ - int islr; /* track whether merging with last_remainder */ - - if (mem == 0) /* free(0) has no effect */ - return; - - p = mem2chunk(mem); - hd = p->size; - -#if HAVE_MMAP - if (hd & IS_MMAPPED) /* release mmapped memory. */ - { - munmap_chunk(p); - return; - } -#endif - - check_inuse_chunk(p); - - sz = hd & ~PREV_INUSE; - next = chunk_at_offset(p, sz); - nextsz = chunksize(next); - - if (next == top) /* merge with top */ - { - sz += nextsz; - - if (!(hd & PREV_INUSE)) /* consolidate backward */ - { - prevsz = p->prev_size; - p = chunk_at_offset(p, -prevsz); - sz += prevsz; - unlink(p, bck, fwd); - } - - set_head(p, sz | PREV_INUSE); - top = p; - if ((unsigned long)(sz) >= (unsigned long)trim_threshold) - malloc_trim(top_pad); - return; - } - - set_head(next, nextsz); /* clear inuse bit */ - - islr = 0; - - if (!(hd & PREV_INUSE)) /* consolidate backward */ - { - prevsz = p->prev_size; - p = chunk_at_offset(p, -prevsz); - sz += prevsz; - - if (p->fd == last_remainder) /* keep as last_remainder */ - islr = 1; - else - unlink(p, bck, fwd); - } - - if (!(inuse_bit_at_offset(next, nextsz))) /* consolidate forward */ - { - sz += nextsz; - - if (!islr && next->fd == last_remainder) /* re-insert last_remainder */ - { - islr = 1; - link_last_remainder(p); - } - else - unlink(next, bck, fwd); - } - - - set_head(p, sz | PREV_INUSE); - set_foot(p, sz); - if (!islr) - frontlink(p, sz, idx, bck, fwd); -} - - - - - -/* - - Realloc algorithm: - - Chunks that were obtained via mmap cannot be extended or shrunk - unless HAVE_MREMAP is defined, in which case mremap is used. - Otherwise, if their reallocation is for additional space, they are - copied. If for less, they are just left alone. - - Otherwise, if the reallocation is for additional space, and the - chunk can be extended, it is, else a malloc-copy-free sequence is - taken. There are several different ways that a chunk could be - extended. All are tried: - - * Extending forward into following adjacent free chunk. - * Shifting backwards, joining preceding adjacent space - * Both shifting backwards and extending forward. - * Extending into newly sbrked space - - Unless the #define REALLOC_ZERO_BYTES_FREES is set, realloc with a - size argument of zero (re)allocates a minimum-sized chunk. - - If the reallocation is for less space, and the new request is for - a `small' (<512 bytes) size, then the newly unused space is lopped - off and freed. - - The old unix realloc convention of allowing the last-free'd chunk - to be used as an argument to realloc is no longer supported. - I don't know of any programs still relying on this feature, - and allowing it would also allow too many other incorrect - usages of realloc to be sensible. - - -*/ - - -#if __STD_C -Void_t* rEALLOc(Void_t* oldmem, size_t bytes) -#else -Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes; -#endif -{ - INTERNAL_SIZE_T nb; /* padded request size */ - - mchunkptr oldp; /* chunk corresponding to oldmem */ - INTERNAL_SIZE_T oldsize; /* its size */ - - mchunkptr newp; /* chunk to return */ - INTERNAL_SIZE_T newsize; /* its size */ - Void_t* newmem; /* corresponding user mem */ - - mchunkptr next; /* next contiguous chunk after oldp */ - INTERNAL_SIZE_T nextsize; /* its size */ - - mchunkptr prev; /* previous contiguous chunk before oldp */ - INTERNAL_SIZE_T prevsize; /* its size */ - - mchunkptr remainder; /* holds split off extra space from newp */ - INTERNAL_SIZE_T remainder_size; /* its size */ - - mchunkptr bck; /* misc temp for linking */ - mchunkptr fwd; /* misc temp for linking */ - -#ifdef REALLOC_ZERO_BYTES_FREES - if (bytes == 0) { fREe(oldmem); return 0; } -#endif - - - /* realloc of null is supposed to be same as malloc */ - if (oldmem == 0) return mALLOc(bytes); - - newp = oldp = mem2chunk(oldmem); - newsize = oldsize = chunksize(oldp); - - - nb = request2size(bytes); - -#if HAVE_MMAP - if (chunk_is_mmapped(oldp)) - { -#if HAVE_MREMAP - newp = mremap_chunk(oldp, nb); - if(newp) return chunk2mem(newp); -#endif - /* Note the extra SIZE_SZ overhead. */ - if(oldsize - SIZE_SZ >= nb) return oldmem; /* do nothing */ - /* Must alloc, copy, free. */ - newmem = mALLOc(bytes); - if (newmem == 0) return 0; /* propagate failure */ - MALLOC_COPY(newmem, oldmem, oldsize - 2*SIZE_SZ); - munmap_chunk(oldp); - return newmem; - } -#endif - - check_inuse_chunk(oldp); - - if ((long)(oldsize) < (long)(nb)) - { - - /* Try expanding forward */ - - next = chunk_at_offset(oldp, oldsize); - if (next == top || !inuse(next)) - { - nextsize = chunksize(next); - - /* Forward into top only if a remainder */ - if (next == top) - { - if ((long)(nextsize + newsize) >= (long)(nb + MINSIZE)) - { - newsize += nextsize; - top = chunk_at_offset(oldp, nb); - set_head(top, (newsize - nb) | PREV_INUSE); - set_head_size(oldp, nb); - return chunk2mem(oldp); - } - } - - /* Forward into next chunk */ - else if (((long)(nextsize + newsize) >= (long)(nb))) - { - unlink(next, bck, fwd); - newsize += nextsize; - goto split; - } - } - else - { - next = 0; - nextsize = 0; - } - - /* Try shifting backwards. */ - - if (!prev_inuse(oldp)) - { - prev = prev_chunk(oldp); - prevsize = chunksize(prev); - - /* try forward + backward first to save a later consolidation */ - - if (next != 0) - { - /* into top */ - if (next == top) - { - if ((long)(nextsize + prevsize + newsize) >= (long)(nb + MINSIZE)) - { - unlink(prev, bck, fwd); - newp = prev; - newsize += prevsize + nextsize; - newmem = chunk2mem(newp); - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - top = chunk_at_offset(newp, nb); - set_head(top, (newsize - nb) | PREV_INUSE); - set_head_size(newp, nb); - return newmem; - } - } - - /* into next chunk */ - else if (((long)(nextsize + prevsize + newsize) >= (long)(nb))) - { - unlink(next, bck, fwd); - unlink(prev, bck, fwd); - newp = prev; - newsize += nextsize + prevsize; - newmem = chunk2mem(newp); - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - goto split; - } - } - - /* backward only */ - if (prev != 0 && (long)(prevsize + newsize) >= (long)nb) - { - unlink(prev, bck, fwd); - newp = prev; - newsize += prevsize; - newmem = chunk2mem(newp); - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - goto split; - } - } - - /* Must allocate */ - - newmem = mALLOc (bytes); - - if (newmem == 0) /* propagate failure */ - return 0; - - /* Avoid copy if newp is next chunk after oldp. */ - /* (This can only happen when new chunk is sbrk'ed.) */ - - if ( (newp = mem2chunk(newmem)) == next_chunk(oldp)) - { - newsize += chunksize(newp); - newp = oldp; - goto split; - } - - /* Otherwise copy, free, and exit */ - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - fREe(oldmem); - return newmem; - } - - - split: /* split off extra room in old or expanded chunk */ - - if (newsize - nb >= MINSIZE) /* split off remainder */ - { - remainder = chunk_at_offset(newp, nb); - remainder_size = newsize - nb; - set_head_size(newp, nb); - set_head(remainder, remainder_size | PREV_INUSE); - set_inuse_bit_at_offset(remainder, remainder_size); - fREe(chunk2mem(remainder)); /* let free() deal with it */ - } - else - { - set_head_size(newp, newsize); - set_inuse_bit_at_offset(newp, newsize); - } - - check_inuse_chunk(newp); - return chunk2mem(newp); -} - - - - -/* - - memalign algorithm: - - memalign requests more than enough space from malloc, finds a spot - within that chunk that meets the alignment request, and then - possibly frees the leading and trailing space. - - The alignment argument must be a power of two. This property is not - checked by memalign, so misuse may result in random runtime errors. - - 8-byte alignment is guaranteed by normal malloc calls, so don't - bother calling memalign with an argument of 8 or less. - - Overreliance on memalign is a sure way to fragment space. - -*/ - - -#if __STD_C -Void_t* mEMALIGn(size_t alignment, size_t bytes) -#else -Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; -#endif -{ - INTERNAL_SIZE_T nb; /* padded request size */ - char* m; /* memory returned by malloc call */ - mchunkptr p; /* corresponding chunk */ - char* brk; /* alignment point within p */ - mchunkptr newp; /* chunk to return */ - INTERNAL_SIZE_T newsize; /* its size */ - INTERNAL_SIZE_T leadsize; /* leading space befor alignment point */ - mchunkptr remainder; /* spare room at end to split off */ - long remainder_size; /* its size */ - - /* If need less alignment than we give anyway, just relay to malloc */ - - if (alignment <= MALLOC_ALIGNMENT) return mALLOc(bytes); - - /* Otherwise, ensure that it is at least a minimum chunk size */ - - if (alignment < MINSIZE) alignment = MINSIZE; - - /* Call malloc with worst case padding to hit alignment. */ - - nb = request2size(bytes); - m = (char*)(mALLOc(nb + alignment + MINSIZE)); - - if (m == 0) return 0; /* propagate failure */ - - p = mem2chunk(m); - - if ((((unsigned long)(m)) % alignment) == 0) /* aligned */ - { -#if HAVE_MMAP - if(chunk_is_mmapped(p)) - return chunk2mem(p); /* nothing more to do */ -#endif - } - else /* misaligned */ - { - /* - Find an aligned spot inside chunk. - Since we need to give back leading space in a chunk of at - least MINSIZE, if the first calculation places us at - a spot with less than MINSIZE leader, we can move to the - next aligned spot -- we've allocated enough total room so that - this is always possible. - */ - - brk = (char*)mem2chunk(((unsigned long)(m + alignment - 1)) & -alignment); - if ((long)(brk - (char*)(p)) < MINSIZE) brk = brk + alignment; - - newp = (mchunkptr)brk; - leadsize = brk - (char*)(p); - newsize = chunksize(p) - leadsize; - -#if HAVE_MMAP - if(chunk_is_mmapped(p)) - { - newp->prev_size = p->prev_size + leadsize; - set_head(newp, newsize|IS_MMAPPED); - return chunk2mem(newp); - } -#endif - - /* give back leader, use the rest */ - - set_head(newp, newsize | PREV_INUSE); - set_inuse_bit_at_offset(newp, newsize); - set_head_size(p, leadsize); - fREe(chunk2mem(p)); - p = newp; - - assert (newsize >= nb && (((unsigned long)(chunk2mem(p))) % alignment) == 0); - } - - /* Also give back spare room at the end */ - - remainder_size = chunksize(p) - nb; - - if (remainder_size >= (long)MINSIZE) - { - remainder = chunk_at_offset(p, nb); - set_head(remainder, remainder_size | PREV_INUSE); - set_head_size(p, nb); - fREe(chunk2mem(remainder)); - } - - check_inuse_chunk(p); - return chunk2mem(p); - -} - - - - -/* - valloc just invokes memalign with alignment argument equal - to the page size of the system (or as near to this as can - be figured out from all the includes/defines above.) -*/ - -#if __STD_C -Void_t* vALLOc(size_t bytes) -#else -Void_t* vALLOc(bytes) size_t bytes; -#endif -{ - return mEMALIGn (malloc_getpagesize, bytes); -} - -/* - pvalloc just invokes valloc for the nearest pagesize - that will accommodate request -*/ - - -#if __STD_C -Void_t* pvALLOc(size_t bytes) -#else -Void_t* pvALLOc(bytes) size_t bytes; -#endif -{ - size_t pagesize = malloc_getpagesize; - return mEMALIGn (pagesize, (bytes + pagesize - 1) & ~(pagesize - 1)); -} - -/* - - calloc calls malloc, then zeroes out the allocated chunk. - -*/ - -#if __STD_C -Void_t* cALLOc(size_t n, size_t elem_size) -#else -Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size; -#endif -{ - mchunkptr p; - INTERNAL_SIZE_T csz; - - INTERNAL_SIZE_T sz = n * elem_size; - - /* check if expand_top called, in which case don't need to clear */ -#if MORECORE_CLEARS - mchunkptr oldtop = top; - INTERNAL_SIZE_T oldtopsize = chunksize(top); -#endif - Void_t* mem = mALLOc (sz); - - if (mem == 0) - return 0; - else - { - p = mem2chunk(mem); - - /* Two optional cases in which clearing not necessary */ - - -#if HAVE_MMAP - if (chunk_is_mmapped(p)) return mem; -#endif - - csz = chunksize(p); - -#if MORECORE_CLEARS - if (p == oldtop && csz > oldtopsize) - { - /* clear only the bytes from non-freshly-sbrked memory */ - csz = oldtopsize; - } -#endif - - MALLOC_ZERO(mem, csz - SIZE_SZ); - return mem; - } -} - -/* - - cfree just calls free. It is needed/defined on some systems - that pair it with calloc, presumably for odd historical reasons. - -*/ - -#if !defined(INTERNAL_LINUX_C_LIB) || !defined(__ELF__) -#if __STD_C -void cfree(Void_t *mem) -#else -void cfree(mem) Void_t *mem; -#endif -{ - free(mem); -} -#endif - - - -/* - - Malloc_trim gives memory back to the system (via negative - arguments to sbrk) if there is unused memory at the `high' end of - the malloc pool. You can call this after freeing large blocks of - memory to potentially reduce the system-level memory requirements - of a program. However, it cannot guarantee to reduce memory. Under - some allocation patterns, some large free blocks of memory will be - locked between two used chunks, so they cannot be given back to - the system. - - The `pad' argument to malloc_trim represents the amount of free - trailing space to leave untrimmed. If this argument is zero, - only the minimum amount of memory to maintain internal data - structures will be left (one page or less). Non-zero arguments - can be supplied to maintain enough trailing space to service - future expected allocations without having to re-obtain memory - from the system. - - Malloc_trim returns 1 if it actually released any memory, else 0. - -*/ - -#if __STD_C -int malloc_trim(size_t pad) -#else -int malloc_trim(pad) size_t pad; -#endif -{ - long top_size; /* Amount of top-most memory */ - long extra; /* Amount to release */ - char* current_brk; /* address returned by pre-check sbrk call */ - char* new_brk; /* address returned by negative sbrk call */ - - unsigned long pagesz = malloc_getpagesize; - - top_size = chunksize(top); - extra = ((top_size - pad - MINSIZE + (pagesz-1)) / pagesz - 1) * pagesz; - - if (extra < (long)pagesz) /* Not enough memory to release */ - return 0; - - else - { - /* Test to make sure no one else called sbrk */ - current_brk = (char*)(MORECORE (0)); - if (current_brk != (char*)(top) + top_size) - return 0; /* Apparently we don't own memory; must fail */ - - else - { - new_brk = (char*)(MORECORE (-extra)); - - if (new_brk == (char*)(MORECORE_FAILURE)) /* sbrk failed? */ - { - /* Try to figure out what we have */ - current_brk = (char*)(MORECORE (0)); - top_size = current_brk - (char*)top; - if (top_size >= (long)MINSIZE) /* if not, we are very very dead! */ - { - sbrked_mem = current_brk - sbrk_base; - set_head(top, top_size | PREV_INUSE); - } - check_chunk(top); - return 0; - } - - else - { - /* Success. Adjust top accordingly. */ - set_head(top, (top_size - extra) | PREV_INUSE); - sbrked_mem -= extra; - check_chunk(top); - return 1; - } - } - } -} - - - -/* - malloc_usable_size: - - This routine tells you how many bytes you can actually use in an - allocated chunk, which may be more than you requested (although - often not). You can use this many bytes without worrying about - overwriting other allocated objects. Not a particularly great - programming practice, but still sometimes useful. - -*/ - -#if __STD_C -size_t malloc_usable_size(Void_t* mem) -#else -size_t malloc_usable_size(mem) Void_t* mem; -#endif -{ - mchunkptr p; - if (mem == 0) - return 0; - else - { - p = mem2chunk(mem); - if(!chunk_is_mmapped(p)) - { - if (!inuse(p)) return 0; - check_inuse_chunk(p); - return chunksize(p) - SIZE_SZ; - } - return chunksize(p) - 2*SIZE_SZ; - } -} - - - - -/* Utility to update current_mallinfo for malloc_stats and mallinfo() */ - -static void malloc_update_mallinfo() -{ - int i; - mbinptr b; - mchunkptr p; -#if DEBUG - mchunkptr q; -#endif - - INTERNAL_SIZE_T avail = chunksize(top); - int navail = ((long)(avail) >= (long)MINSIZE)? 1 : 0; - - for (i = 1; i < NAV; ++i) - { - b = bin_at(i); - for (p = last(b); p != b; p = p->bk) - { -#if DEBUG - check_free_chunk(p); - for (q = next_chunk(p); - q < top && inuse(q) && (long)(chunksize(q)) >= (long)MINSIZE; - q = next_chunk(q)) - check_inuse_chunk(q); -#endif - avail += chunksize(p); - navail++; - } - } - - current_mallinfo.ordblks = navail; - current_mallinfo.uordblks = sbrked_mem - avail; - current_mallinfo.fordblks = avail; - current_mallinfo.hblks = n_mmaps; - current_mallinfo.hblkhd = mmapped_mem; - current_mallinfo.keepcost = chunksize(top); - -} - - - -/* - - malloc_stats: - - Prints on stderr the amount of space obtain from the system (both - via sbrk and mmap), the maximum amount (which may be more than - current if malloc_trim and/or munmap got called), the maximum - number of simultaneous mmap regions used, and the current number - of bytes allocated via malloc (or realloc, etc) but not yet - freed. (Note that this is the number of bytes allocated, not the - number requested. It will be larger than the number requested - because of alignment and bookkeeping overhead.) - -*/ - -void malloc_stats() -{ - malloc_update_mallinfo(); - fprintf(stderr, "max system bytes = %10u\n", - (unsigned int)(max_total_mem)); - fprintf(stderr, "system bytes = %10u\n", - (unsigned int)(sbrked_mem + mmapped_mem)); - fprintf(stderr, "in use bytes = %10u\n", - (unsigned int)(current_mallinfo.uordblks + mmapped_mem)); -#if HAVE_MMAP - fprintf(stderr, "max mmap regions = %10u\n", - (unsigned int)max_n_mmaps); -#endif -} - -/* - mallinfo returns a copy of updated current mallinfo. -*/ - -struct mallinfo mALLINFo() -{ - malloc_update_mallinfo(); - return current_mallinfo; -} - - - - -/* - mallopt: - - mallopt is the general SVID/XPG interface to tunable parameters. - The format is to provide a (parameter-number, parameter-value) pair. - mallopt then sets the corresponding parameter to the argument - value if it can (i.e., so long as the value is meaningful), - and returns 1 if successful else 0. - - See descriptions of tunable parameters above. - -*/ - -#if __STD_C -int mALLOPt(int param_number, int value) -#else -int mALLOPt(param_number, value) int param_number; int value; -#endif -{ - switch(param_number) - { - case M_TRIM_THRESHOLD: - trim_threshold = value; return 1; - case M_TOP_PAD: - top_pad = value; return 1; - case M_MMAP_THRESHOLD: - mmap_threshold = value; return 1; - case M_MMAP_MAX: -#if HAVE_MMAP - n_mmaps_max = value; return 1; -#else - if (value != 0) return 0; else n_mmaps_max = value; return 1; -#endif - - default: - return 0; - } -} - -/* - -History: - - V2.6.3 Sun May 19 08:17:58 1996 Doug Lea (dl at gee) - * Added pvalloc, as recommended by H.J. Liu - * Added 64bit pointer support mainly from Wolfram Gloger - * Added anonymously donated WIN32 sbrk emulation - * Malloc, calloc, getpagesize: add optimizations from Raymond Nijssen - * malloc_extend_top: fix mask error that caused wastage after - foreign sbrks - * Add linux mremap support code from HJ Liu - - V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee) - * Integrated most documentation with the code. - * Add support for mmap, with help from - Wolfram Gloger (Gloger@lrz.uni-muenchen.de). - * Use last_remainder in more cases. - * Pack bins using idea from colin@nyx10.cs.du.edu - * Use ordered bins instead of best-fit threshhold - * Eliminate block-local decls to simplify tracing and debugging. - * Support another case of realloc via move into top - * Fix error occuring when initial sbrk_base not word-aligned. - * Rely on page size for units instead of SBRK_UNIT to - avoid surprises about sbrk alignment conventions. - * Add mallinfo, mallopt. Thanks to Raymond Nijssen - (raymond@es.ele.tue.nl) for the suggestion. - * Add `pad' argument to malloc_trim and top_pad mallopt parameter. - * More precautions for cases where other routines call sbrk, - courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de). - * Added macros etc., allowing use in linux libc from - H.J. Lu (hjl@gnu.ai.mit.edu) - * Inverted this history list - - V2.6.1 Sat Dec 2 14:10:57 1995 Doug Lea (dl at gee) - * Re-tuned and fixed to behave more nicely with V2.6.0 changes. - * Removed all preallocation code since under current scheme - the work required to undo bad preallocations exceeds - the work saved in good cases for most test programs. - * No longer use return list or unconsolidated bins since - no scheme using them consistently outperforms those that don't - given above changes. - * Use best fit for very large chunks to prevent some worst-cases. - * Added some support for debugging - - V2.6.0 Sat Nov 4 07:05:23 1995 Doug Lea (dl at gee) - * Removed footers when chunks are in use. Thanks to - Paul Wilson (wilson@cs.texas.edu) for the suggestion. - - V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee) - * Added malloc_trim, with help from Wolfram Gloger - (wmglo@Dent.MED.Uni-Muenchen.DE). - - V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g) - - V2.5.2 Tue Apr 5 16:20:40 1994 Doug Lea (dl at g) - * realloc: try to expand in both directions - * malloc: swap order of clean-bin strategy; - * realloc: only conditionally expand backwards - * Try not to scavenge used bins - * Use bin counts as a guide to preallocation - * Occasionally bin return list chunks in first scan - * Add a few optimizations from colin@nyx10.cs.du.edu - - V2.5.1 Sat Aug 14 15:40:43 1993 Doug Lea (dl at g) - * faster bin computation & slightly different binning - * merged all consolidations to one part of malloc proper - (eliminating old malloc_find_space & malloc_clean_bin) - * Scan 2 returns chunks (not just 1) - * Propagate failure in realloc if malloc returns 0 - * Add stuff to allow compilation on non-ANSI compilers - from kpv@research.att.com - - V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu) - * removed potential for odd address access in prev_chunk - * removed dependency on getpagesize.h - * misc cosmetics and a bit more internal documentation - * anticosmetics: mangled names in macros to evade debugger strangeness - * tested on sparc, hp-700, dec-mips, rs6000 - with gcc & native cc (hp, dec only) allowing - Detlefs & Zorn comparison study (in SIGPLAN Notices.) - - Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu) - * Based loosely on libg++-1.2X malloc. (It retains some of the overall - structure of old version, but most details differ.) - -*/ - - + * A version of malloc/free/realloc written by Doug Lea and released to the + * public domain. Send questions/comments/complaints/performance data + * to dl@cs.oswego.edu + * + * * VERSION 2.6.4 Thu Nov 28 07:54:55 1996 Doug Lea (dl at gee) + * + * Note: There may be an updated version of this malloc obtainable at + * ftp://g.oswego.edu/pub/misc/malloc.c + * Check before installing! + * + * * Why use this malloc? + * + * This is not the fastest, most space-conserving, most portable, or + * most tunable malloc ever written. However it is among the fastest + * while also being among the most space-conserving, portable and tunable. + * Consistent balance across these factors results in a good general-purpose + * allocator. For a high-level description, see + * http://g.oswego.edu/dl/html/malloc.html + * + * * Synopsis of public routines + * + * (Much fuller descriptions are contained in the program documentation below.) + * + * malloc(size_t n); + * Return a pointer to a newly allocated chunk of at least n bytes, or null + * if no space is available. + * free(Void_t* p); + * Release the chunk of memory pointed to by p, or no effect if p is null. + * realloc(Void_t* p, size_t n); + * Return a pointer to a chunk of size n that contains the same data + * as does chunk p up to the minimum of (n, p's size) bytes, or null + * if no space is available. The returned pointer may or may not be + * the same as p. If p is null, equivalent to malloc. Unless the + * #define REALLOC_ZERO_BYTES_FREES below is set, realloc with a + * size argument of zero (re)allocates a minimum-sized chunk. + * memalign(size_t alignment, size_t n); + * Return a pointer to a newly allocated chunk of n bytes, aligned + * in accord with the alignment argument, which must be a power of + * two. + * valloc(size_t n); + * Equivalent to memalign(pagesize, n), where pagesize is the page + * size of the system (or as near to this as can be figured out from + * all the includes/defines below.) + * pvalloc(size_t n); + * Equivalent to valloc(minimum-page-that-holds(n)), that is, + * round up n to nearest pagesize. + * calloc(size_t unit, size_t quantity); + * Returns a pointer to quantity * unit bytes, with all locations + * set to zero. + * cfree(Void_t* p); + * Equivalent to free(p). + * malloc_trim(size_t pad); + * Release all but pad bytes of freed top-most memory back + * to the system. Return 1 if successful, else 0. + * malloc_usable_size(Void_t* p); + * Report the number usable allocated bytes associated with allocated + * chunk p. This may or may not report more bytes than were requested, + * due to alignment and minimum size constraints. + * malloc_stats(); + * Prints brief summary statistics on stderr. + * mallinfo() + * Returns (by copy) a struct containing various summary statistics. + * mallopt(int parameter_number, int parameter_value) + * Changes one of the tunable parameters described below. Returns + * 1 if successful in changing the parameter, else 0. + * + * * Vital statistics: + * + * Alignment: 8-byte + * 8 byte alignment is currently hardwired into the design. This + * seems to suffice for all current machines and C compilers. + * + * Assumed pointer representation: 4 or 8 bytes + * Code for 8-byte pointers is untested by me but has worked + * reliably by Wolfram Gloger, who contributed most of the + * changes supporting this. + * + * Assumed size_t representation: 4 or 8 bytes + * Note that size_t is allowed to be 4 bytes even if pointers are 8. + * + * Minimum overhead per allocated chunk: 4 or 8 bytes + * Each malloced chunk has a hidden overhead of 4 bytes holding size + * and status information. + * + * Minimum allocated size: 4-byte ptrs: 16 bytes (including 4 overhead) + * 8-byte ptrs: 24/32 bytes (including, 4/8 overhead) + * + * When a chunk is freed, 12 (for 4byte ptrs) or 20 (for 8 byte + * ptrs but 4 byte size) or 24 (for 8/8) additional bytes are + * needed; 4 (8) for a trailing size field + * and 8 (16) bytes for free list pointers. Thus, the minimum + * allocatable size is 16/24/32 bytes. + * + * Even a request for zero bytes (i.e., malloc(0)) returns a + * pointer to something of the minimum allocatable size. + * + * Maximum allocated size: 4-byte size_t: 2^31 - 8 bytes + * 8-byte size_t: 2^63 - 16 bytes + * + * It is assumed that (possibly signed) size_t bit values suffice to + * represent chunk sizes. `Possibly signed' is due to the fact + * that `size_t' may be defined on a system as either a signed or + * an unsigned type. To be conservative, values that would appear + * as negative numbers are avoided. + * Requests for sizes with a negative sign bit will return a + * minimum-sized chunk. + * + * Maximum overhead wastage per allocated chunk: normally 15 bytes + * + * Alignnment demands, plus the minimum allocatable size restriction + * make the normal worst-case wastage 15 bytes (i.e., up to 15 + * more bytes will be allocated than were requested in malloc), with + * two exceptions: + * 1. Because requests for zero bytes allocate non-zero space, + * the worst case wastage for a request of zero bytes is 24 bytes. + * 2. For requests >= mmap_threshold that are serviced via + * mmap(), the worst case wastage is 8 bytes plus the remainder + * from a system page (the minimal mmap unit); typically 4096 bytes. + * + * * Limitations + * + * Here are some features that are NOT currently supported + * + * * No user-definable hooks for callbacks and the like. + * * No automated mechanism for fully checking that all accesses + * to malloced memory stay within their bounds. + * * No support for compaction. + * + * * Synopsis of compile-time options: + * + * People have reported using previous versions of this malloc on all + * versions of Unix, sometimes by tweaking some of the defines + * below. It has been tested most extensively on Solaris and + * Linux. It is also reported to work on WIN32 platforms. + * People have also reported adapting this malloc for use in + * stand-alone embedded systems. + * + * The implementation is in straight, hand-tuned ANSI C. Among other + * consequences, it uses a lot of macros. Because of this, to be at + * all usable, this code should be compiled using an optimizing compiler + * (for example gcc -O2) that can simplify expressions and control + * paths. + * + * __STD_C (default: derived from C compiler defines) + * Nonzero if using ANSI-standard C compiler, a C++ compiler, or + * a C compiler sufficiently close to ANSI to get away with it. + * DEBUG (default: NOT defined) + * Define to enable debugging. Adds fairly extensive assertion-based + * checking to help track down memory errors, but noticeably slows down + * execution. + * REALLOC_ZERO_BYTES_FREES (default: NOT defined) + * Define this if you think that realloc(p, 0) should be equivalent + * to free(p). Otherwise, since malloc returns a unique pointer for + * malloc(0), so does realloc(p, 0). + * HAVE_MEMCPY (default: defined) + * Define if you are not otherwise using ANSI STD C, but still + * have memcpy and memset in your C library and want to use them. + * Otherwise, simple internal versions are supplied. + * USE_MEMCPY (default: 1 if HAVE_MEMCPY is defined, 0 otherwise) + * Define as 1 if you want the C library versions of memset and + * memcpy called in realloc and calloc (otherwise macro versions are used). + * At least on some platforms, the simple macro versions usually + * outperform libc versions. + * HAVE_MMAP (default: defined as 1) + * Define to non-zero to optionally make malloc() use mmap() to + * allocate very large blocks. + * HAVE_MREMAP (default: defined as 0 unless Linux libc set) + * Define to non-zero to optionally make realloc() use mremap() to + * reallocate very large blocks. + * malloc_getpagesize (default: derived from system #includes) + * Either a constant or routine call returning the system page size. + * HAVE_USR_INCLUDE_MALLOC_H (default: NOT defined) + * Optionally define if you are on a system with a /usr/include/malloc.h + * that declares struct mallinfo. It is not at all necessary to + * define this Index: squid/lib/ntlmauth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/ntlmauth.c,v retrieving revision 1.1.4.4 retrieving revision 1.1.4.5 diff -u -r1.1.4.4 -r1.1.4.5 --- squid/lib/ntlmauth.c 7 Jan 2001 07:27:13 -0000 1.1.4.4 +++ squid/lib/ntlmauth.c 7 Jan 2001 09:48:29 -0000 1.1.4.5 @@ -22,31 +22,33 @@ */ #include "ntlmauth.h" -#include "util.h" /* for base64-related stuff */ +#include "util.h" /* for base64-related stuff */ /* Dumps NTLM flags to standard error for debugging purposes */ -void ntlm_dump_ntlmssp_flags(u_int32_t flags) { - fprintf(stderr,"flags: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", - (flags&NEGOTIATE_UNICODE?"Unicode ":""), - (flags&NEGOTIATE_ASCII?"ASCII ":""), - (flags&NEGOTIATE_REQUEST_TARGET?"ReqTgt ":""), - (flags&NEGOTIATE_REQUEST_SIGN?"ReqSign ":""), - (flags&NEGOTIATE_REQUEST_SEAL?"ReqSeal ":""), - (flags&NEGOTIATE_DATAGRAM_STYLE?"Dgram ":""), - (flags&NEGOTIATE_USE_LM?"UseLM ":""), - (flags&NEGOTIATE_USE_NETWARE?"UseNW ":""), - (flags&NEGOTIATE_USE_NTLM?"UseNTLM ":""), - (flags&NEGOTIATE_DOMAIN_SUPPLIED?"HaveDomain ":""), - (flags&NEGOTIATE_WORKSTATION_SUPPLIED?"HaveWKS ":""), - (flags&NEGOTIATE_THIS_IS_LOCAL_CALL?"LocalCall ":""), - (flags&NEGOTIATE_ALWAYS_SIGN?"AlwaysSign ":""), - (flags&CHALLENGE_TARGET_IS_DOMAIN?"Tgt_is_domain":""), - (flags&CHALLENGE_TARGET_IS_SERVER?"Tgt_is_server ":""), - (flags&CHALLENGE_TARGET_IS_SHARE?"Tgt_is_share ":""), - (flags&REQUEST_INIT_RESPONSE?"Req_init_response ":""), - (flags&REQUEST_ACCEPT_RESPONSE?"Req_accept_response ":""), - (flags&REQUEST_NON_NT_SESSION_KEY?"Req_nonnt_sesskey ":"") - ); +void +ntlm_dump_ntlmssp_flags(u_int32_t flags) +{ + fprintf(stderr, "flags: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", + (flags & NEGOTIATE_UNICODE ? "Unicode " : ""), + (flags & NEGOTIATE_ASCII ? "ASCII " : ""), + (flags & NEGOTIATE_REQUEST_TARGET ? "ReqTgt " : ""), + (flags & NEGOTIATE_REQUEST_SIGN ? "ReqSign " : ""), + (flags & NEGOTIATE_REQUEST_SEAL ? "ReqSeal " : ""), + (flags & NEGOTIATE_DATAGRAM_STYLE ? "Dgram " : ""), + (flags & NEGOTIATE_USE_LM ? "UseLM " : ""), + (flags & NEGOTIATE_USE_NETWARE ? "UseNW " : ""), + (flags & NEGOTIATE_USE_NTLM ? "UseNTLM " : ""), + (flags & NEGOTIATE_DOMAIN_SUPPLIED ? "HaveDomain " : ""), + (flags & NEGOTIATE_WORKSTATION_SUPPLIED ? "HaveWKS " : ""), + (flags & NEGOTIATE_THIS_IS_LOCAL_CALL ? "LocalCall " : ""), + (flags & NEGOTIATE_ALWAYS_SIGN ? "AlwaysSign " : ""), + (flags & CHALLENGE_TARGET_IS_DOMAIN ? "Tgt_is_domain" : ""), + (flags & CHALLENGE_TARGET_IS_SERVER ? "Tgt_is_server " : ""), + (flags & CHALLENGE_TARGET_IS_SHARE ? "Tgt_is_share " : ""), + (flags & REQUEST_INIT_RESPONSE ? "Req_init_response " : ""), + (flags & REQUEST_ACCEPT_RESPONSE ? "Req_accept_response " : ""), + (flags & REQUEST_NON_NT_SESSION_KEY ? "Req_nonnt_sesskey " : "") + ); } #define lstring_zero(s) s.str=NULL; s.l=-1; @@ -57,26 +59,27 @@ * be used in any way that requires a tailing \0. (he can check whether the * value is there though, in that case lstring.length==-1). */ -lstring ntlm_fetch_string (char * packet, int32_t length, strhdr *str) { - int16_t l; /* length */ - int32_t o; /* offset */ - lstring rv; - - lstring_zero(rv); - - l = SSWAP(str->len); - o = WSWAP(str->offset); - /* debug("fetch_string(plength=%d,l=%d,o=%d)\n",length,l,o); */ - - if (l < 0 || l > MAX_FIELD_LENGTH || o+l > length || o==0) { - /* debug("ntlmssp: insane data (l: %d, o: %d)\n", l,o); */ - return rv; - } - - rv.str=packet+o; - rv.l=l; - +lstring +ntlm_fetch_string(char *packet, int32_t length, strhdr * str) +{ + int16_t l; /* length */ + int32_t o; /* offset */ + lstring rv; + + lstring_zero(rv); + + l = SSWAP(str->len); + o = WSWAP(str->offset); + /* debug("fetch_string(plength=%d,l=%d,o=%d)\n",length,l,o); */ + + if (l < 0 || l > MAX_FIELD_LENGTH || o + l > length || o == 0) { + /* debug("ntlmssp: insane data (l: %d, o: %d)\n", l,o); */ return rv; + } + rv.str = packet + o; + rv.l = l; + + return rv; } /* Adds something to the payload. The caller must guarrantee that @@ -85,17 +88,19 @@ * payload_length and hdr will be modified as a side-effect. * base_offset is the payload offset from the packet's beginning, and is */ -void ntlm_add_to_payload (char *payload, int *payload_length, - strhdr *hdr, char *toadd, - int toadd_length, int base_offset) { - - int l=(*payload_length); - memcpy(payload+l,toadd,toadd_length); - - hdr->len=toadd_length; - hdr->maxlen=toadd_length; - hdr->offset=l+base_offset; /* 48 is the base offset of the payload */ - (*payload_length)+=toadd_length; +void +ntlm_add_to_payload(char *payload, int *payload_length, + strhdr * hdr, char *toadd, + int toadd_length, int base_offset) +{ + + int l = (*payload_length); + memcpy(payload + l, toadd, toadd_length); + + hdr->len = toadd_length; + hdr->maxlen = toadd_length; + hdr->offset = l + base_offset; /* 48 is the base offset of the payload */ + (*payload_length) += toadd_length; } @@ -104,28 +109,30 @@ * note: the storage type for the returned value depends on * base64_encode_bin. Currently this means static storage. */ -const char* ntlm_make_challenge(char *domain, char *domain_controller, - char *challenge_nonce, int challenge_nonce_len) { - ntlm_challenge ch; - int pl=0; - const char * encoded; - memset(&ch, 0, sizeof(ntlm_challenge)); /* reset */ - memcpy(ch.signature, "NTLMSSP", 8); /* set the signature */ - ch.type = WSWAP(NTLM_CHALLENGE); /* this is a challenge */ - ntlm_add_to_payload(ch.payload, &pl, &ch.target, domain, strlen(domain), - NTLM_CHALLENGE_HEADER_OFFSET); - ch.flags=WSWAP( - REQUEST_NON_NT_SESSION_KEY | - CHALLENGE_TARGET_IS_DOMAIN | - NEGOTIATE_ALWAYS_SIGN | - NEGOTIATE_USE_NTLM | - NEGOTIATE_USE_LM | - NEGOTIATE_ASCII | - 0 - ); - ch.context_low=0; /* check this out */ - ch.context_high=0; - memcpy(ch.challenge,challenge_nonce,challenge_nonce_len); - encoded=base64_encode_bin((char *)&ch,NTLM_CHALLENGE_HEADER_OFFSET+pl); - return encoded; +const char * +ntlm_make_challenge(char *domain, char *domain_controller, + char *challenge_nonce, int challenge_nonce_len) +{ + ntlm_challenge ch; + int pl = 0; + const char *encoded; + memset(&ch, 0, sizeof(ntlm_challenge)); /* reset */ + memcpy(ch.signature, "NTLMSSP", 8); /* set the signature */ + ch.type = WSWAP(NTLM_CHALLENGE); /* this is a challenge */ + ntlm_add_to_payload(ch.payload, &pl, &ch.target, domain, strlen(domain), + NTLM_CHALLENGE_HEADER_OFFSET); + ch.flags = WSWAP( + REQUEST_NON_NT_SESSION_KEY | + CHALLENGE_TARGET_IS_DOMAIN | + NEGOTIATE_ALWAYS_SIGN | + NEGOTIATE_USE_NTLM | + NEGOTIATE_USE_LM | + NEGOTIATE_ASCII | + 0 + ); + ch.context_low = 0; /* check this out */ + ch.context_high = 0; + memcpy(ch.challenge, challenge_nonce, challenge_nonce_len); + encoded = base64_encode_bin((char *) &ch, NTLM_CHALLENGE_HEADER_OFFSET + pl); + return encoded; } Index: squid/lib/util.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/util.c,v retrieving revision 1.1.1.3.10.5.2.1 retrieving revision 1.1.1.3.10.5.2.2 diff -u -r1.1.1.3.10.5.2.1 -r1.1.1.3.10.5.2.2 --- squid/lib/util.c 30 Nov 2000 10:51:58 -0000 1.1.1.3.10.5.2.1 +++ squid/lib/util.c 7 Jan 2001 09:48:29 -0000 1.1.1.3.10.5.2.2 @@ -1,6 +1,6 @@ /* - * $Id: util.c,v 1.1.1.3.10.5.2.1 2000/11/30 10:51:58 rbcollins Exp $ + * $Id: util.c,v 1.1.1.3.10.5.2.2 2001/01/07 09:48:29 hno Exp $ * * DEBUG: * AUTHOR: Harvest Derived @@ -78,7 +78,7 @@ #if !defined(__CYGWIN__) extern int sys_nerr; #else - #define sys_nerr _sys_nerr +#define sys_nerr _sys_nerr #endif @@ -124,9 +124,9 @@ return DBG_MAXINDEX; if (sz <= DBG_SPLIT) - return (sz+DBG_GRAIN_SM-1)/DBG_GRAIN_SM; + return (sz + DBG_GRAIN_SM - 1) / DBG_GRAIN_SM; - return (sz+DBG_GRAIN-1)/DBG_GRAIN + DBG_OFFSET; + return (sz + DBG_GRAIN - 1) / DBG_GRAIN + DBG_OFFSET; } static void @@ -475,7 +475,7 @@ #if XMALLOC_DEBUG if (s != NULL) - check_free(s); + check_free(s); #endif if (s != NULL) free(s); @@ -632,7 +632,7 @@ if (errno < 0 || errno >= sys_nerr) snprintf(xstrerror_buf, BUFSIZ, "(%d) Unknown", errno); else - snprintf(xstrerror_buf, BUFSIZ, "(%d) %s", errno, strerror(errno)); + snprintf(xstrerror_buf, BUFSIZ, "(%d) %s", errno, strerror(errno)); return xstrerror_buf; } @@ -749,10 +749,10 @@ } /* A default failure notifier when the main program hasn't installed any */ -void default_failure_notify(const char *msg) +void +default_failure_notify(const char *msg) { write(2, msg, strlen(msg)); write(2, "\n", 1); abort(); } - Index: squid/lib/uudecode.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/uudecode.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/lib/uudecode.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/lib/uudecode.c 7 Jan 2001 09:48:29 -0000 1.1.1.1.26.1 @@ -1,5 +1,6 @@ + /* - * $Id: uudecode.c,v 1.1.1.1 2000/01/26 03:21:47 hno Exp $ + * $Id: uudecode.c,v 1.1.1.1.26.1 2001/01/07 09:48:29 hno Exp $ */ #include "config.h" Index: squid/ntlm_auth_modules/NTLMSSP/libntlmssp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/Attic/libntlmssp.c,v retrieving revision 1.1.2.12.2.7 retrieving revision 1.1.2.12.2.8 diff -u -r1.1.2.12.2.7 -r1.1.2.12.2.8 --- squid/ntlm_auth_modules/NTLMSSP/libntlmssp.c 7 Jan 2001 07:56:15 -0000 1.1.2.12.2.7 +++ squid/ntlm_auth_modules/NTLMSSP/libntlmssp.c 7 Jan 2001 09:48:29 -0000 1.1.2.12.2.8 @@ -15,7 +15,7 @@ #include "ntlm.h" -#include "util.h" /* from Squid */ +#include "util.h" /* from Squid */ #include "valid.h" #if HAVE_STRING_H @@ -28,112 +28,119 @@ #include #endif -#include "smblib-priv.h" /* for SMB_Handle_Type */ +#include "smblib-priv.h" /* for SMB_Handle_Type */ /* a few forward-declarations. Hackish, but I don't care right now */ SMB_Handle_Type SMB_Connect_Server(SMB_Handle_Type Con_Handle, - char *server, char *NTdomain); + char *server, char *NTdomain); /* this one is reallllly haackiish. We really should be using anything from smblib-priv.h */ -static 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}; +static 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}; #if 0 int SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle); int SMB_Negotiate(void *Con_Handle, char *Prots[]); -int SMB_Logon_Server(SMB_Handle_Type Con_Handle, char *UserName, - char *PassWord, char * Domain, int precrypted); +int SMB_Logon_Server(SMB_Handle_Type Con_Handle, char *UserName, + char *PassWord, char *Domain, int precrypted); #endif #ifdef DEBUG #define debug_dump_ntlmssp_flags dump_ntlmssp_flags -#else /* DEBUG */ -#define debug_dump_ntlmssp_flags(X) /* empty */ +#else /* DEBUG */ +#define debug_dump_ntlmssp_flags(X) /* empty */ #endif /* DEBUG */ static char challenge[NONCE_LEN]; -SMB_Handle_Type handle=NULL; +SMB_Handle_Type handle = NULL; /* Disconnects from the DC. A reconnection will be done upon the next request */ -void dc_disconnect() { - if (handle != NULL) - SMB_Discon(handle,0); - handle=NULL; +void +dc_disconnect() +{ + if (handle != NULL) + SMB_Discon(handle, 0); + handle = NULL; } -int connectedp() { - return (handle!=NULL); +int +connectedp() +{ + return (handle != NULL); } /* Tries to connect to a DC. Returns 0 on failure, 1 on OK */ -int is_dc_ok (char *domain, - char *domain_controller) { - SMB_Handle_Type h=SMB_Connect_Server(NULL,domain_controller,domain); - if (h==NULL) - return 0; - SMB_Discon(h,0); - return 1; +int +is_dc_ok(char *domain, + char *domain_controller) +{ + SMB_Handle_Type h = SMB_Connect_Server(NULL, domain_controller, domain); + if (h == NULL) + return 0; + SMB_Discon(h, 0); + return 1; } /* returns 0 on success, > 0 on failure */ -static int init_challenge(char* domain, char* domain_controller) { -int smberr; -char errstr[100]; - - if (handle != NULL) { - return 0; - } - - debug("Connecting to server %s domain %s\n",domain_controller,domain); - handle=SMB_Connect_Server(NULL,domain_controller,domain); - smberr=SMB_Get_Last_Error(); - SMB_Get_Error_Msg(smberr,errstr,100); - - - if (handle==NULL) { /* couldn't connect */ - debug("Couldn't connect to SMB Server. Error:%s\n",errstr); - return 1; - } - - if (SMB_Negotiate(handle, SMB_Prots) < 0) { /* An error */ - debug("Error negotiating protocol with SMB Server\n"); - SMB_Discon(handle,0); - handle=NULL; - return 2; - } - - if (handle -> Security == 0) { /* share-level security, unuseable */ - debug("SMB Server uses share-level security .. we need user sercurity.\n"); - SMB_Discon(handle,0); - handle=NULL; - return 3; - } - - memcpy(challenge, handle->Encrypt_Key, NONCE_LEN); +static int +init_challenge(char *domain, char *domain_controller) +{ + int smberr; + char errstr[100]; + + if (handle != NULL) { return 0; -} + } + debug("Connecting to server %s domain %s\n", domain_controller, domain); + handle = SMB_Connect_Server(NULL, domain_controller, domain); + smberr = SMB_Get_Last_Error(); + SMB_Get_Error_Msg(smberr, errstr, 100); -const char *make_challenge (char *domain, char *domain_controller) { - if (init_challenge(domain,domain_controller) > 0) - return NULL; - return ntlm_make_challenge(domain, domain_controller,challenge, - NONCE_LEN); + + if (handle == NULL) { /* couldn't connect */ + debug("Couldn't connect to SMB Server. Error:%s\n", errstr); + return 1; + } + if (SMB_Negotiate(handle, SMB_Prots) < 0) { /* An error */ + debug("Error negotiating protocol with SMB Server\n"); + SMB_Discon(handle, 0); + handle = NULL; + return 2; + } + if (handle->Security == 0) { /* share-level security, unuseable */ + debug("SMB Server uses share-level security .. we need user sercurity.\n"); + SMB_Discon(handle, 0); + handle = NULL; + return 3; + } + memcpy(challenge, handle->Encrypt_Key, NONCE_LEN); + return 0; +} + +const char * +make_challenge(char *domain, char *domain_controller) +{ + if (init_challenge(domain, domain_controller) > 0) + return NULL; + return ntlm_make_challenge(domain, domain_controller, challenge, + NONCE_LEN); } #define min(A,B) (Almresponse); - if (tmp.str==NULL) { - fprintf(stderr,"No auth at all. Returning no-auth\n"); - ntlm_errno=NTLM_LOGON_ERROR; - return NULL; - } - memcpy(pass,tmp.str,tmp.l); - pass[25]='\0'; - -/* debug("fetching domain\n"); */ - tmp=ntlm_fetch_string((char *)auth,auth_length,&auth->domain); - if (tmp.str==NULL) { - debug("No domain supplied. Returning no-auth\n"); - ntlm_errno=NTLM_LOGON_ERROR; - return NULL; - } - memcpy(domain,tmp.str,tmp.l); - user=domain+tmp.l; - *user++='\0'; - -/* debug("fetching user name\n"); */ - tmp=ntlm_fetch_string((char *)auth,auth_length,&auth->user); - if (tmp.str==NULL) { - debug("No username supplied. Returning no-auth\n"); - ntlm_errno=NTLM_LOGON_ERROR; - return NULL; - } - memcpy(user,tmp.str,tmp.l); - *(user+tmp.l)='\0'; - - debug("checking domain: '%s', user: '%s', pass='%s'\n",domain,user,pass); - - rv=SMB_Logon_Server(handle,user,pass,domain,1); - - while ( (rv == NTLM_BAD_PROTOCOL || rv==NTLM_SERVER_ERROR) - && retries < BAD_DC_RETRIES_NUMBER) { - retries++; - usleep ((unsigned long)100000); - rv=SMB_Logon_Server(handle,user,pass,domain,1); - } - - debug("\tresult is %d\n",rv); - - if (rv!=NTV_NO_ERROR){ /* failed */ - ntlm_errno=rv; - return NULL; - } - - *(user-1)='\\'; +char * +ntlm_check_auth(ntlm_authenticate * auth, int auth_length) +{ + int rv, retries = 0; + char pass[25]; + char *domain = credentials; + char *user; + lstring tmp; + + if (handle == NULL) { /*if null we aren't connected, but it shouldn't happen */ + debug("Weird, we've been disconnected\n"); + ntlm_errno = NTLM_NOT_CONNECTED; + return NULL; + } + /* Authenticating against the NT response doesn't seem to work... */ + tmp = ntlm_fetch_string((char *) auth, auth_length, &auth->lmresponse); + if (tmp.str == NULL) { + fprintf(stderr, "No auth at all. Returning no-auth\n"); + ntlm_errno = NTLM_LOGON_ERROR; + return NULL; + } + memcpy(pass, tmp.str, tmp.l); + pass[25] = '\0'; + +/* debug("fetching domain\n"); */ + tmp = ntlm_fetch_string((char *) auth, auth_length, &auth->domain); + if (tmp.str == NULL) { + debug("No domain supplied. Returning no-auth\n"); + ntlm_errno = NTLM_LOGON_ERROR; + return NULL; + } + memcpy(domain, tmp.str, tmp.l); + user = domain + tmp.l; + *user++ = '\0'; + +/* debug("fetching user name\n"); */ + tmp = ntlm_fetch_string((char *) auth, auth_length, &auth->user); + if (tmp.str == NULL) { + debug("No username supplied. Returning no-auth\n"); + ntlm_errno = NTLM_LOGON_ERROR; + return NULL; + } + memcpy(user, tmp.str, tmp.l); + *(user + tmp.l) = '\0'; + + debug("checking domain: '%s', user: '%s', pass='%s'\n", domain, user, pass); + + rv = SMB_Logon_Server(handle, user, pass, domain, 1); + + while ((rv == NTLM_BAD_PROTOCOL || rv == NTLM_SERVER_ERROR) + && retries < BAD_DC_RETRIES_NUMBER) { + retries++; + usleep((unsigned long) 100000); + rv = SMB_Logon_Server(handle, user, pass, domain, 1); + } + + debug("\tresult is %d\n", rv); + + if (rv != NTV_NO_ERROR) { /* failed */ + ntlm_errno = rv; + return NULL; + } + *(user - 1) = '\\'; - debug("credentials: %s\n",credentials); - return credentials; + debug("credentials: %s\n", credentials); + return credentials; } Index: squid/ntlm_auth_modules/NTLMSSP/ntlm.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/Attic/ntlm.h,v retrieving revision 1.1.2.12.2.7 retrieving revision 1.1.2.12.2.8 diff -u -r1.1.2.12.2.7 -r1.1.2.12.2.8 --- squid/ntlm_auth_modules/NTLMSSP/ntlm.h 7 Jan 2001 07:56:15 -0000 1.1.2.12.2.7 +++ squid/ntlm_auth_modules/NTLMSSP/ntlm.h 7 Jan 2001 09:48:29 -0000 1.1.2.12.2.8 @@ -47,19 +47,19 @@ /* Debugging stuff */ -#ifdef __GNUC__ /* this is really a gcc-ism */ +#ifdef __GNUC__ /* this is really a gcc-ism */ #ifdef DEBUG #include #include -static char* __foo; +static char *__foo; #define debug(X...) fprintf(stderr,"ntlm-auth[%d](%s:%d): ", getpid(), \ ((__foo=strrchr(__FILE__,'/'))==NULL?__FILE__:__foo+1),\ __LINE__);\ fprintf(stderr,X) -#else /* DEBUG */ -#define debug(X...) /* */ +#else /* DEBUG */ +#define debug(X...) /* */ #endif /* DEBUG */ -#else /* __GNUC__ */ +#else /* __GNUC__ */ #define debug(char *format, ...) {} /* Too lazy to write va_args stuff */ #endif @@ -78,11 +78,11 @@ #define NTLM_NOT_CONNECTED 10 -const char* make_challenge(char *domain, char *controller); -extern char* ntlm_check_auth(ntlm_authenticate *auth, int auth_length); +const char *make_challenge(char *domain, char *controller); +extern char *ntlm_check_auth(ntlm_authenticate * auth, int auth_length); void dc_disconnect(void); int connectedp(void); -int is_dc_ok (char *domain,char *domain_controller); +int is_dc_ok(char *domain, char *domain_controller); /* flags used for dc status */ #define DC_OK 0x0 @@ -90,10 +90,10 @@ typedef struct _dc dc; struct _dc { - char *domain; - char *controller; - unsigned char status; - dc *next; + char *domain; + char *controller; + unsigned char status; + dc *next; }; Index: squid/ntlm_auth_modules/NTLMSSP/ntlm_auth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/Attic/ntlm_auth.c,v retrieving revision 1.1.2.10.2.7 retrieving revision 1.1.2.10.2.8 diff -u -r1.1.2.10.2.7 -r1.1.2.10.2.8 --- squid/ntlm_auth_modules/NTLMSSP/ntlm_auth.c 7 Jan 2001 07:56:15 -0000 1.1.2.10.2.7 +++ squid/ntlm_auth_modules/NTLMSSP/ntlm_auth.c 7 Jan 2001 09:48:29 -0000 1.1.2.10.2.8 @@ -40,14 +40,14 @@ #define BUFFER_SIZE 10240 -#if HAVE_STDLIB_H -#include -#endif +#if HAVE_STDLIB_H +#include +#endif -#if HAVE_GETOPT_H -#include -#endif +#if HAVE_GETOPT_H +#include +#endif @@ -58,40 +58,46 @@ #include #endif -char load_balance=0, failover_enabled=0, protocol_pedantic=0; +char load_balance = 0, failover_enabled = 0, protocol_pedantic = 0; -dc *controllers=NULL; -int numcontrollers=0; +dc *controllers = NULL; +int numcontrollers = 0; dc *current_dc; /* housekeeping cycle and periodic operations */ -static unsigned char need_dc_resurrection=0; -static void resurrect_dead_dc () { - int j; - dc *c=controllers; - - need_dc_resurrection=0; - for (j=0;jstatus!=DC_OK && is_dc_ok(c->domain,c->controller)) - c->status=DC_OK; +static unsigned char need_dc_resurrection = 0; +static void +resurrect_dead_dc() +{ + int j; + dc *c = controllers; + + need_dc_resurrection = 0; + for (j = 0; j < numcontrollers; j++) + if (c->status != DC_OK && is_dc_ok(c->domain, c->controller)) + c->status = DC_OK; } /* makes a null-terminated string upper-case. Changes CONTENTS! */ -static void uc (char *string) { - char *p=string, c; - while ((c=*p)) { - *p=toupper(c); - p++; - } +static void +uc(char *string) +{ + char *p = string, c; + while ((c = *p)) { + *p = toupper(c); + p++; + } } /* makes a null-terminated string lower-case. Changes CONTENTS! */ -static void lc (char *string) { - char *p=string, c; - while ((c=*p)) { - *p=tolower(c); - p++; - } +static void +lc(char *string) +{ + char *p = string, c; + while ((c = *p)) { + *p = tolower(c); + p++; + } } /* @@ -100,228 +106,231 @@ * -f fail-over to another DC if DC connection fails. * domain\controller ... */ -void process_options (int argc, char *argv[]) { - int opt,j,had_error=0; - dc *new_dc=NULL, *last_dc=NULL; - while (-1!=(opt=getopt(argc,argv,"bf"))) { - switch(opt) { - case 'b': - load_balance=1; - break; - case 'f': - failover_enabled=1; - break; - default: - fprintf(stderr,"unknown option: -%c. Exiting\n",opt); - had_error=1; - } - } - if (had_error) - exit(1); - /* Okay, now begin filling controllers up */ - /* we can avoid memcpy-ing, and just reuse argv[] */ - for (j=optind;jdomain=d; - new_dc->controller=c; - new_dc->status=DC_OK; - if (controllers==NULL) { /* first controller */ - controllers=new_dc; - last_dc=new_dc; - } else { - last_dc->next=new_dc; /* can't be null */ - last_dc=new_dc; - } - } - if (numcontrollers==0) { - fprintf(stderr,"You must specify at least one domain-controller!\n"); - exit(1); - } - last_dc->next=controllers; /* close the queue, now it's circular */ +void +process_options(int argc, char *argv[]) +{ + int opt, j, had_error = 0; + dc *new_dc = NULL, *last_dc = NULL; + while (-1 != (opt = getopt(argc, argv, "bf"))) { + switch (opt) { + case 'b': + load_balance = 1; + break; + case 'f': + failover_enabled = 1; + break; + default: + fprintf(stderr, "unknown option: -%c. Exiting\n", opt); + had_error = 1; + } + } + if (had_error) + exit(1); + /* Okay, now begin filling controllers up */ + /* we can avoid memcpy-ing, and just reuse argv[] */ + for (j = optind; j < argc; j++) { + char *d, *c; + d = argv[j]; + if (NULL == (c = strchr(d, '\\')) && NULL == (c = strchr(d, '/'))) { + fprintf(stderr, "Couldn't grok domain-controller %s\n", d); + continue; + } + *c++ = '\0'; + new_dc = (dc *) malloc(sizeof(dc)); + if (!new_dc) { + fprintf(stderr, "Malloc error while parsing DC options\n"); + continue; + } + /* capitalize */ + uc(c); + uc(d); + numcontrollers++; + new_dc->domain = d; + new_dc->controller = c; + new_dc->status = DC_OK; + if (controllers == NULL) { /* first controller */ + controllers = new_dc; + last_dc = new_dc; + } else { + last_dc->next = new_dc; /* can't be null */ + last_dc = new_dc; + } + } + if (numcontrollers == 0) { + fprintf(stderr, "You must specify at least one domain-controller!\n"); + exit(1); + } + last_dc->next = controllers; /* close the queue, now it's circular */ } /* tries connecting to the domain controllers in the "controllers" ring, * with failover if the adequate option is specified. */ -const char *obtain_challenge() { - int j=0; - const char *ch; - for (j=0;jstatus == DC_OK) { - ch=make_challenge(current_dc->domain,current_dc->controller); - if (ch) - return ch; /* All went OK, returning */ - /* Huston, we've got a problem. Take this DC out of the loop */ - current_dc->status=DC_DEAD; - need_dc_resurrection=1; - } - if (failover_enabled==0) /* No failover. Just return */ - return NULL; - /* Try with the next */ - current_dc=current_dc->next; - } - return NULL; +const char * +obtain_challenge() +{ + int j = 0; + const char *ch; + for (j = 0; j < numcontrollers; j++) { + if (current_dc->status == DC_OK) { + ch = make_challenge(current_dc->domain, current_dc->controller); + if (ch) + return ch; /* All went OK, returning */ + /* Huston, we've got a problem. Take this DC out of the loop */ + current_dc->status = DC_DEAD; + need_dc_resurrection = 1; + } + if (failover_enabled == 0) /* No failover. Just return */ + return NULL; + /* Try with the next */ + current_dc = current_dc->next; + } + return NULL; } -void manage_request () { - ntlmhdr *fast_header; - char buf[10240]; - const char *ch; - char *ch2, *decoded, *cred; - int plen; - - if(fgets(buf, BUFFER_SIZE, stdin) == NULL) exit(0); /* BIIG buffer */ - ch2=memchr(buf,'\n', BUFFER_SIZE); /* safer against overrun than strchr */ - if (ch2) { - *ch2='\0'; /* terminate the string at newline. */ - ch = ch2; - } - debug("ntlm authenticator. Got '%s' from Squid\n",buf); - - if (memcmp(buf,"KK ",3)==0) { /* authenticate-request */ - /* figure out what we got */ - decoded=base64_decode(buf+3); - /* Note: we don't need to manage memory at this point, since - * base64_decode returns a pointer to static storage. - */ - - if (!decoded) { /* decoding failure, return error */ - SEND("NA Packet format error, couldn't base64-decode"); - return; - } - - /* fast-track-decode request type. */ - fast_header=(struct _ntlmhdr *)decoded; - - /* sanity-check: it IS a NTLMSSP packet, isn't it? */ - if (memcmp(fast_header->signature,"NTLMSSP",8) != 0) { - SEND("NA Broken authentication packet"); - return; - } - - switch (fast_header->type) { - case NTLM_NEGOTIATE: - SEND("NA Invalid negotiation request received"); - return; - /* notreached */ - case NTLM_CHALLENGE: - SEND("NA Got a challenge. We refuse to have our authority disputed"); - return; - /* notreached */ - case NTLM_AUTHENTICATE: - /* check against the DC */ - plen=strlen(buf)*3/4; /* we only need it here. Optimization */ - cred=ntlm_check_auth((ntlm_authenticate *)decoded, plen); - if (cred==NULL) { - switch (ntlm_errno) { - case NTLM_LOGON_ERROR: - SEND("NA authentication failure"); - dc_disconnect(); - current_dc=current_dc->next; - return; - case NTLM_SERVER_ERROR: - SEND("BH Domain Controller Error"); - dc_disconnect(); - current_dc=current_dc->next; - return; - case NTLM_PROTOCOL_ERROR: - SEND("BH Domain Controller communication error"); - dc_disconnect(); - current_dc=current_dc->next; - return; - case NTLM_NOT_CONNECTED: - SEND("BH Domain Controller (or network) died on us"); - dc_disconnect(); - current_dc=current_dc->next; - return; - case NTLM_BAD_PROTOCOL: - SEND("BH Domain controller failure"); - dc_disconnect(); - current_dc=current_dc->next; - return; - default: - SEND("BH Unhandled error while talking to Domain Controller"); - dc_disconnect(); - current_dc=current_dc->next; - return; - } - } - lc(cred); /* let's lowercase them for our convenience */ - SEND2("AF %s",cred); - return; +void +manage_request() +{ + ntlmhdr *fast_header; + char buf[10240]; + const char *ch; + char *ch2, *decoded, *cred; + int plen; + + if (fgets(buf, BUFFER_SIZE, stdin) == NULL) + exit(0); /* BIIG buffer */ + ch2 = memchr(buf, '\n', BUFFER_SIZE); /* safer against overrun than strchr */ + if (ch2) { + *ch2 = '\0'; /* terminate the string at newline. */ + ch = ch2; + } + debug("ntlm authenticator. Got '%s' from Squid\n", buf); + + if (memcmp(buf, "KK ", 3) == 0) { /* authenticate-request */ + /* figure out what we got */ + decoded = base64_decode(buf + 3); + /* Note: we don't need to manage memory at this point, since + * base64_decode returns a pointer to static storage. + */ + + if (!decoded) { /* decoding failure, return error */ + SEND("NA Packet format error, couldn't base64-decode"); + return; + } + /* fast-track-decode request type. */ + fast_header = (struct _ntlmhdr *) decoded; + + /* sanity-check: it IS a NTLMSSP packet, isn't it? */ + if (memcmp(fast_header->signature, "NTLMSSP", 8) != 0) { + SEND("NA Broken authentication packet"); + return; + } + switch (fast_header->type) { + case NTLM_NEGOTIATE: + SEND("NA Invalid negotiation request received"); + return; + /* notreached */ + case NTLM_CHALLENGE: + SEND("NA Got a challenge. We refuse to have our authority disputed"); + return; + /* notreached */ + case NTLM_AUTHENTICATE: + /* check against the DC */ + plen = strlen(buf) * 3 / 4; /* we only need it here. Optimization */ + cred = ntlm_check_auth((ntlm_authenticate *) decoded, plen); + if (cred == NULL) { + switch (ntlm_errno) { + case NTLM_LOGON_ERROR: + SEND("NA authentication failure"); + dc_disconnect(); + current_dc = current_dc->next; + return; + case NTLM_SERVER_ERROR: + SEND("BH Domain Controller Error"); + dc_disconnect(); + current_dc = current_dc->next; + return; + case NTLM_PROTOCOL_ERROR: + SEND("BH Domain Controller communication error"); + dc_disconnect(); + current_dc = current_dc->next; + return; + case NTLM_NOT_CONNECTED: + SEND("BH Domain Controller (or network) died on us"); + dc_disconnect(); + current_dc = current_dc->next; + return; + case NTLM_BAD_PROTOCOL: + SEND("BH Domain controller failure"); + dc_disconnect(); + current_dc = current_dc->next; + return; default: - SEND("BH unknown authentication packet type"); - return; + SEND("BH Unhandled error while talking to Domain Controller"); + dc_disconnect(); + current_dc = current_dc->next; + return; } - - - return; + } + lc(cred); /* let's lowercase them for our convenience */ + SEND2("AF %s", cred); + return; + default: + SEND("BH unknown authentication packet type"); + return; } - if (memcmp(buf,"YR",2)==0) { /* refresh-request */ - dc_disconnect(); - ch=obtain_challenge(); - while (ch==NULL) { - sleep(30); - ch=obtain_challenge(); - } - SEND2("TT %s",ch); - if (need_dc_resurrection) /* looks like a good moment... */ - resurrect_dead_dc(); - return; - } - SEND("BH Helper detected protocol error"); return; - /********* END ********/ - - -} + } + if (memcmp(buf, "YR", 2) == 0) { /* refresh-request */ + dc_disconnect(); + ch = obtain_challenge(); + while (ch == NULL) { + sleep(30); + ch = obtain_challenge(); + } + SEND2("TT %s", ch); + if (need_dc_resurrection) /* looks like a good moment... */ + resurrect_dead_dc(); + return; + } + SEND("BH Helper detected protocol error"); + return; +/********* END ********/ -int main(int argc, char *argv[]) { - debug("starting up...\n"); - - process_options(argc,argv); - - debug("options processed OK\n"); - - /* initialize FDescs */ - setbuf(stdout,NULL); - setbuf(stderr,NULL); - - /* select the first domain controller we're going to use */ - current_dc=controllers; - if (load_balance!=0 && numcontrollers > 1) { - int n; - pid_t pid=getpid(); - n=pid%numcontrollers; - debug("load balancing. Selected controller #%d\n",n); - while (n > 0) { - current_dc=current_dc->next; - n--; - } - } - - while (1) { - debug("managing request\n"); - manage_request(); - } - return 0; } +int +main(int argc, char *argv[]) +{ + + debug("starting up...\n"); + + process_options(argc, argv); + + debug("options processed OK\n"); + + /* initialize FDescs */ + setbuf(stdout, NULL); + setbuf(stderr, NULL); + + /* select the first domain controller we're going to use */ + current_dc = controllers; + if (load_balance != 0 && numcontrollers > 1) { + int n; + pid_t pid = getpid(); + n = pid % numcontrollers; + debug("load balancing. Selected controller #%d\n", n); + while (n > 0) { + current_dc = current_dc->next; + n--; + } + } + while (1) { + debug("managing request\n"); + manage_request(); + } + return 0; +} Index: squid/ntlm_auth_modules/NTLMSSP/smbval/byteorder.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/byteorder.h,v retrieving revision 1.1.2.1.2.2 retrieving revision 1.1.2.1.2.3 diff -u -r1.1.2.1.2.2 -r1.1.2.1.2.3 --- squid/ntlm_auth_modules/NTLMSSP/smbval/byteorder.h 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.2 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/byteorder.h 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.3 @@ -1,33 +1,33 @@ /* - 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. -*/ + * 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. + */ /* - This file implements macros for machine independent short and - int manipulation -*/ + * 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 */ + * byteorder */ #ifdef __i386__ #define CAREFUL_ALIGNMENT 0 #endif @@ -54,11 +54,11 @@ #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val))) #else /* this handles things for architectures like the 386 that can handle - alignment errors */ + * alignment errors */ /* - WARNING: This section is dependent on the length of int16 and int32 - being correct -*/ + * 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))) Index: squid/ntlm_auth_modules/NTLMSSP/smbval/md4.c =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/md4.c,v retrieving revision 1.1.2.1.2.2 retrieving revision 1.1.2.1.2.3 diff -u -r1.1.2.1.2.2 -r1.1.2.1.2.3 --- squid/ntlm_auth_modules/NTLMSSP/smbval/md4.c 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.2 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/md4.c 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.3 @@ -1,54 +1,58 @@ /* - 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. -*/ + * 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 -*/ + * + * It assumes that a int is at least 32 bits long + */ #include typedef unsigned int uint32; static uint32 A, B, C, D; -static uint32 F(uint32 X, uint32 Y, uint32 Z) +static uint32 +F(uint32 X, uint32 Y, uint32 Z) { - return (X&Y) | ((~X)&Z); + return (X & Y) | ((~X) & Z); } -static uint32 G(uint32 X, uint32 Y, uint32 Z) +static uint32 +G(uint32 X, uint32 Y, uint32 Z) { - return (X&Y) | (X&Z) | (Y&Z); + return (X & Y) | (X & Z) | (Y & Z); } -static uint32 H(uint32 X, uint32 Y, uint32 Z) +static uint32 +H(uint32 X, uint32 Y, uint32 Z) { - return X^Y^Z; + return X ^ Y ^ Z; } -static uint32 lshift(uint32 x, int s) +static uint32 +lshift(uint32 x, int s) { - x &= 0xFFFFFFFF; - return ((x<>(32-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) @@ -56,117 +60,151 @@ #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) +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; + 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) +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); - } + 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; - for (i=0;i<128;i++) - buf[i] = 0; + 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); - copy4(out, A); - copy4(out+4, B); - copy4(out+8, C); - copy4(out+12, D); - - A = B = C = D = 0; + A = B = C = D = 0; } - - Index: squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-common.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/rfcnb-common.h,v retrieving revision 1.1.2.1.2.2 retrieving revision 1.1.2.1.2.3 diff -u -r1.1.2.1.2.2 -r1.1.2.1.2.3 --- squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-common.h 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.2 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-common.h 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.3 @@ -1,36 +1,34 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB Common Structures etc Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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. + */ /* A data structure we need */ typedef struct RFCNB_Pkt { - char * data; /* The data in this portion */ - int len; - struct RFCNB_Pkt *next; + char *data; /* The data in this portion */ + int len; + struct RFCNB_Pkt *next; } RFCNB_Pkt; - - Index: squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-error.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/rfcnb-error.h,v retrieving revision 1.1.2.1.2.3 retrieving revision 1.1.2.1.2.4 diff -u -r1.1.2.1.2.3 -r1.1.2.1.2.4 --- squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-error.h 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.3 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-error.h 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.4 @@ -1,76 +1,74 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB Error Response Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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 */ -#define RFCNBE_Bad -1 /* Bad response */ +#define RFCNBE_Bad -1 /* Bad response */ #define RFCNBE_OK 0 -/* these should follow the spec ... is there one ?*/ +/* 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 */ +#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[]; /* -static 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 ..." - -}; -*/ - - + * static 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 ..." + * + * }; + */ Index: squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-io.c =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/rfcnb-io.c,v retrieving revision 1.1.2.1.2.3 retrieving revision 1.1.2.1.2.4 diff -u -r1.1.2.1.2.3 -r1.1.2.1.2.4 --- squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-io.c 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.3 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-io.c 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.4 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NEtBIOS implementation - - Version 1.0 - RFCNB IO Routines ... - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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 "config.h" #include "std-includes.h" @@ -32,377 +32,369 @@ #include #include -int RFCNB_Timeout = 0; /* Timeout in seconds ... */ - -void rfcnb_alarm(int sig) +int RFCNB_Timeout = 0; /* Timeout in seconds ... */ +void +rfcnb_alarm(int sig) { - fprintf(stderr, "IO Timed out ...\n"); + fprintf(stderr, "IO Timed out ...\n"); } /* Set timeout value and setup signal handling */ -int RFCNB_Set_Timeout(int seconds) - +int +RFCNB_Set_Timeout(int seconds) { - /* If we are on a Bezerkeley system, use sigvec, else sigaction */ + /* If we are on a Bezerkeley system, use sigvec, else sigaction */ #if HAVE_SIGACTION - struct sigaction inact, outact; + struct sigaction inact, outact; #else - struct sigvec invec, outvec; + struct sigvec invec, outvec; #endif - RFCNB_Timeout = seconds; + RFCNB_Timeout = seconds; - if (RFCNB_Timeout > 0) { /* Set up handler to ignore but not restart */ + if (RFCNB_Timeout > 0) { /* Set up handler to ignore but not restart */ #if HAVE_SIGACTION - inact.sa_handler = (void (*)())rfcnb_alarm; - sigemptyset(&inact.sa_mask); - inact.sa_flags = 0; /* Don't restart */ + inact.sa_handler = (void (*)()) rfcnb_alarm; + sigemptyset(&inact.sa_mask); + inact.sa_flags = 0; /* Don't restart */ - if (sigaction(SIGALRM, &inact, &outact) < 0) - return(-1); + if (sigaction(SIGALRM, &inact, &outact) < 0) + return (-1); #else - invec.sv_handler = (void (*)())rfcnb_alarm; - invec.sv_mask = 0; - invec.sv_flags = SV_INTERRUPT; + invec.sv_handler = (void (*)()) rfcnb_alarm; + invec.sv_mask = 0; + invec.sv_flags = SV_INTERRUPT; - if (sigvec(SIGALRM, &invec, &outvec) < 0) - return(-1); + if (sigvec(SIGALRM, &invec, &outvec) < 0) + return (-1); #endif - } - - return(0); + } + 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 ... */ + * 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; +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 */ + /* len is the amount we should read */ #ifdef RFCNB_DEBUG - fprintf(stderr, "Discard_Rest called to discard: %i\n", len); + fprintf(stderr, "Discard_Rest called to discard: %i\n", len); #endif - rest = len; + rest = len; - while (rest > 0) { + while (rest > 0) { - this_read = (rest > sizeof(temp)?sizeof(temp):rest); + this_read = (rest > sizeof(temp) ? sizeof(temp) : rest); - bytes_read = read(con -> fd, temp, this_read); + bytes_read = read(con->fd, temp, this_read); - if (bytes_read <= 0) { /* Error so return */ + if (bytes_read <= 0) { /* Error so return */ - if (bytes_read < 0) - RFCNB_errno = RFCNBE_BadRead; - else - RFCNB_errno = RFCNBE_ConGone; + if (bytes_read < 0) + RFCNB_errno = RFCNBE_BadRead; + else + RFCNB_errno = RFCNBE_ConGone; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); + RFCNB_saved_errno = errno; + return (RFCNBE_Bad); - } - - rest = rest - bytes_read; + } + rest = rest - bytes_read; - } + } - return(0); + 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 ... + * + */ - 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 ...*/ +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 */ + /* 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; + pkt_ptr = pkt; + len_sent = tot_sent = 0; /* Nothing sent so far */ + i = 0; - while ((pkt_ptr != NULL) & (i < 10)) { /* Watch that magic number! */ + 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 */ + 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 ... */ + /* Now plug into the iovec ... */ - io_list[i].iov_len = this_len; - io_list[i].iov_base = this_data; - i++; + io_list[i].iov_len = this_len; + io_list[i].iov_base = this_data; + i++; - tot_sent += this_len; + tot_sent += this_len; - if (tot_sent == len) break; /* Let's not send too much */ + if (tot_sent == len) + break; /* Let's not send too much */ - pkt_ptr = pkt_ptr -> next; + pkt_ptr = pkt_ptr->next; - } + } #ifdef RFCNB_DEBUG - fprintf(stderr, "Frags = %i, tot_sent = %i\n", i, tot_sent); + fprintf(stderr, "Frags = %i, tot_sent = %i\n", i, tot_sent); #endif - /* Set up an alarm if timeouts are set ... */ + /* Set up an alarm if timeouts are set ... */ - if (RFCNB_Timeout > 0) - alarm(RFCNB_Timeout); + if (RFCNB_Timeout > 0) + alarm(RFCNB_Timeout); - if ((len_sent = writev(con -> fd, io_list, i)) < 0) { /* An error */ + 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); - } + 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 (RFCNB_Timeout > 0) - alarm(0); /* Reset that sucker */ + } + 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 ... */ + fprintf(stderr, "Len sent = %i ...\n", len_sent); + RFCNB_Print_Pkt(stderr, "sent", pkt, len_sent); /* Print what send ... */ #endif - return(len_sent); + 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 - -*/ + * + * 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; +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 */ + /* Read that header straight into the buffer */ - if (len < RFCNB_Pkt_Hdr_Len) { /* What a bozo */ + if (len < RFCNB_Pkt_Hdr_Len) { /* What a bozo */ #ifdef RFCNB_DEBUG - fprintf(stderr, "Trying to read less than a packet:"); - perror(""); + fprintf(stderr, "Trying to read less than a packet:"); + perror(""); #endif - RFCNB_errno = RFCNBE_BadParam; - return(RFCNBE_Bad); - - } + RFCNB_errno = RFCNBE_BadParam; + return (RFCNBE_Bad); - /* We discard keep alives here ... */ + } + /* We discard keep alives here ... */ - if (RFCNB_Timeout > 0) - alarm(RFCNB_Timeout); + if (RFCNB_Timeout > 0) + alarm(RFCNB_Timeout); - while (seen_keep_alive) { + while (seen_keep_alive) { - if ((read_len = read(con -> fd, hdr, sizeof(hdr))) < 0) { /* Problems */ + if ((read_len = read(con->fd, hdr, sizeof(hdr))) < 0) { /* Problems */ #ifdef RFCNB_DEBUG - fprintf(stderr, "Reading the packet, we got:"); - perror(""); + 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); - - } + 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 */ + } + /* Now we check out what we got */ - if (read_len == 0) { /* Connection closed, send back eof? */ + 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); + 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) { + } + if (RFCNB_Pkt_Type(hdr) == RFCNB_SESSION_KEEP_ALIVE) { #ifdef RFCNB_DEBUG - fprintf(stderr, "RFCNB KEEP ALIVE received\n"); + fprintf(stderr, "RFCNB KEEP ALIVE received\n"); #endif - - } - else { - seen_keep_alive = FALSE; + + } else { + seen_keep_alive = FALSE; + } + } - } - - /* What if we got less than or equal to a hdr size in bytes? */ + /* What if we got less than or equal to a hdr size in bytes? */ - if (read_len < sizeof(hdr)) { /* We got a small packet */ + if (read_len < sizeof(hdr)) { /* We got a small packet */ - /* Now we need to copy the hdr portion we got into the supplied packet */ + /* Now we need to copy the hdr portion we got into the supplied packet */ - memcpy(pkt -> data, hdr, read_len); /*Copy data */ + memcpy(pkt->data, hdr, read_len); /*Copy data */ #ifdef RFCNB_DEBUG - RFCNB_Print_Pkt(stderr, "rcvd", pkt, read_len); + RFCNB_Print_Pkt(stderr, "rcvd", pkt, read_len); #endif - return(read_len); + return (read_len); - } - - /* Now, if we got at least a hdr size, alloc space for rest, if we need it */ + } + /* Now, if we got at least a hdr size, alloc space for rest, if we need it */ - pkt_len = RFCNB_Pkt_Len(hdr); + pkt_len = RFCNB_Pkt_Len(hdr); #ifdef RFCNB_DEBUG - fprintf(stderr, "Reading Pkt: Length = %i\n", pkt_len); -#endif - - /* Now copy in the hdr */ + fprintf(stderr, "Reading Pkt: Length = %i\n", pkt_len); +#endif - memcpy(pkt -> data, hdr, sizeof(hdr)); + /* Now copy in the 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 ... */ + memcpy(pkt->data, hdr, sizeof(hdr)); - if (len < pkt_len) /* Only get as much as we have space for */ - more = len - RFCNB_Pkt_Hdr_Len; - else - more = pkt_len; + /* 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 ... */ - this_time = 0; + if (len < pkt_len) /* Only get as much as we have space for */ + more = len - RFCNB_Pkt_Hdr_Len; + else + more = pkt_len; - /* We read for each fragment ... */ + this_time = 0; - 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 */ - } + /* We read for each fragment ... */ - frag_len = pkt_frag -> len; + 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 */ + } - 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; + frag_len = pkt_frag->len; - while (more > 0) { + 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; - if ((this_time = read(con -> fd, (pkt_frag -> data) + offset, this_len)) <= 0) { /* Problems */ + while (more > 0) { - if (errno == EINTR) { + if ((this_time = read(con->fd, (pkt_frag->data) + offset, this_len)) <= 0) { /* Problems */ - RFCNB_errno = RFCNB_Timeout; + if (errno == EINTR) { - } - else { - if (this_time < 0) - RFCNB_errno = RFCNBE_BadRead; - else - RFCNB_errno = RFCNBE_ConGone; - } + RFCNB_errno = RFCNB_Timeout; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); + } 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); + 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 ... */ + read_len = read_len + this_time; /* How much have we read ... */ - /* Now set up the next part */ + /* Now set up the next part */ - if (pkt_frag -> next == NULL) break; /* That's it here */ + if (pkt_frag->next == NULL) + break; /* That's it here */ - pkt_frag = pkt_frag -> next; - this_len = pkt_frag -> len; - offset = 0; + pkt_frag = pkt_frag->next; + this_len = pkt_frag->len; + offset = 0; - more = more - this_time; + 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)); + 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 (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 */ + } + if (RFCNB_Timeout > 0) + alarm(0); /* Reset that sucker */ - return(read_len + sizeof(RFCNB_Hdr)); + return (read_len + sizeof(RFCNB_Hdr)); } Index: squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-io.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/rfcnb-io.h,v retrieving revision 1.1.2.1.2.3 retrieving revision 1.1.2.1.2.4 diff -u -r1.1.2.1.2.3 -r1.1.2.1.2.4 --- squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-io.h 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.3 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-io.h 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.4 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB IO Routines Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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); Index: squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-priv.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/rfcnb-priv.h,v retrieving revision 1.1.2.2.2.3 retrieving revision 1.1.2.2.2.4 diff -u -r1.1.2.2.2.3 -r1.1.2.2.2.4 --- squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-priv.h 7 Jan 2001 02:49:32 -0000 1.1.2.2.2.3 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-priv.h 7 Jan 2001 09:48:29 -0000 1.1.2.2.2.4 @@ -2,29 +2,29 @@ #define __RFCNB_H__ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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 */ @@ -55,33 +55,33 @@ /* Structures */ -typedef struct redirect_addr * redirect_ptr; +typedef struct redirect_addr *redirect_ptr; struct redirect_addr { - struct in_addr ip_addr; - int port; - redirect_ptr next; + 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; + 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 */ +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 */ + * between architecture types where we are worried about byte order */ #define RFCNB_Pkt_Hdr_Len 4 #define RFCNB_Pkt_Sess_Len 72 @@ -89,7 +89,7 @@ #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_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 @@ -99,7 +99,7 @@ #define RFCNB_Pkt_Port_Offset 8 /* The next macro isolates the length of a packet, including the bit in the - flags */ + * flags */ #define RFCNB_Pkt_Len(p) (PVAL(p, 3) | (PVAL(p, 2) << 8) | \ ((PVAL(p, RFCNB_Pkt_Flags_Offset) & 0x01) << 16)) @@ -111,38 +111,38 @@ #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; */ + * + * 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 */ @@ -150,7 +150,7 @@ #ifndef RFCNB_ERRNO extern int RFCNB_errno; -extern int RFCNB_saved_errno; /* Save this from point of error */ +extern int RFCNB_saved_errno; /* Save this from point of error */ #endif #endif /* __RFCNB_H__ */ Index: squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-util.c =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/rfcnb-util.c,v retrieving revision 1.1.2.1.2.4 retrieving revision 1.1.2.1.2.5 diff -u -r1.1.2.1.2.4 -r1.1.2.1.2.5 --- squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-util.c 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.4 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-util.c 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.5 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB Utility Routines ... - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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 @@ -33,505 +33,497 @@ #include -extern void (*Prot_Print_Routine)(); /* Pointer to protocol print routine */ +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) +void +RFCNB_CvtPad_Name(char *name1, char *name2) +{ + char c, c1, c2; + int i, len; -{ char c, c1, c2; - int i, len; + len = strlen(name1); - len = strlen(name1); + for (i = 0; i < 16; i++) { - for (i = 0; i < 16; i++) { + if (i >= len) { - if (i >= len) { + c1 = 'C'; + c2 = 'A'; /* CA is a space */ - c1 = 'C'; c2 = 'A'; /* CA is a space */ - - } else { + } else { - c = name1[i]; - c1 = (char)((int)c/16 + (int)'A'); - c2 = (char)((int)c%16 + (int)'A'); - } + 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[i * 2] = c1; + name2[i * 2 + 1] = c2; - } + } - name2[32] = 0; /* Put in the nll ...*/ + 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. + * 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 ... + * + */ - 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; +void +RFCNB_AName_To_NBName(char *AName, char *NBName) +{ + char c, c1, c2; + int i; - for (i=0; i < 16; i++) { + for (i = 0; i < 16; i++) { - c = AName[i]; + c = AName[i]; - c1 = (char)((c >> 4) + 'A'); - c2 = (char)((c & 0xF) + 'A'); + c1 = (char) ((c >> 4) + 'A'); + c2 = (char) ((c & 0xF) + 'A'); - NBName[i*2] = c1; - NBName[i*2+1] = c2; - } + NBName[i * 2] = c1; + NBName[i * 2 + 1] = c2; + } - NBName[32] = 0; /* Put in a null */ + 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; +void +RFCNB_NBName_To_AName(char *NBName, char *AName) +{ + char c, c1, c2; + int i; - for (i=0; i < 16; i++) { + for (i = 0; i < 16; i++) { - c1 = NBName[i*2]; - c2 = NBName[i*2+1]; + c1 = NBName[i * 2]; + c2 = NBName[i * 2 + 1]; - c = (char)(((int)c1 - (int)'A') * 16 + ((int)c2 - (int)'A')); + c = (char) (((int) c1 - (int) 'A') * 16 + ((int) c2 - (int) 'A')); - AName[i] = c; + AName[i] = c; - } + } - AName[i] = 0; /* Put a null on the end ... */ + 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) { +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; - 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]; + /* Print last lot in the buffer ... */ - outbuf1[j++] = c1; outbuf1[j++] = c2; + if (j > 0) { - 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"); + 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); +struct RFCNB_Pkt * +RFCNB_Alloc_Pkt(int n) +{ + RFCNB_Pkt *pkt; - } + if ((pkt = (struct RFCNB_Pkt *) malloc(sizeof(struct RFCNB_Pkt))) == NULL) { - pkt -> next = NULL; - pkt -> len = n; + RFCNB_errno = RFCNBE_NoSpace; + RFCNB_saved_errno = errno; + return (NULL); - if (n == 0) return(pkt); + } + pkt->next = NULL; + pkt->len = n; - if ((pkt -> data = (char *)malloc(n)) == NULL) { + if (n == 0) + return (pkt); - RFCNB_errno = RFCNBE_NoSpace; - RFCNB_saved_errno = errno; - free(pkt); - return(NULL); + if ((pkt->data = (char *) malloc(n)) == NULL) { - } + RFCNB_errno = RFCNBE_NoSpace; + RFCNB_saved_errno = errno; + free(pkt); + return (NULL); - return(pkt); + } + return (pkt); } /* Free up a packet */ -void RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt) +void +RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt) +{ + struct RFCNB_Pkt *pkt_next; + char *data_ptr; -{ struct RFCNB_Pkt *pkt_next; char *data_ptr; + while (pkt != NULL) { - while (pkt != NULL) { + pkt_next = pkt->next; - pkt_next = pkt -> next; + data_ptr = pkt->data; - data_ptr = pkt -> data; + if (data_ptr != NULL) + free(data_ptr); - if (data_ptr != NULL) - free(data_ptr); + free(pkt); - free(pkt); + pkt = pkt_next; - pkt = pkt_next; + } - } - } /* Print an RFCNB packet */ -void RFCNB_Print_Pkt(FILE *fd, char *dirn, struct RFCNB_Pkt *pkt, int len) - -{ char lname[17]; +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 */ + /* 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); + fprintf(fd, "RFCNB Pkt %s:", dirn); - switch (RFCNB_Pkt_Type(pkt -> data)) { + switch (RFCNB_Pkt_Type(pkt->data)) { - case RFCNB_SESSION_MESSAGE: + 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, + 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); + RFCNB_Pkt_Len(pkt->data) - RFCNB_Pkt_Hdr_Len); #else - 40); + 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); - - } + if (Prot_Print_Routine != 0) { /* Print the rest of the packet */ - break; + Prot_Print_Routine(fd, strcmp(dirn, "sent"), pkt, RFCNB_Pkt_Hdr_Len, + RFCNB_Pkt_Len(pkt->data) - RFCNB_Pkt_Hdr_Len); - case RFCNB_SESSION_REQUEST: + } + break; - 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); + case RFCNB_SESSION_REQUEST: - break; + 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); - case RFCNB_SESSION_ACK: + break; - fprintf(fd, "RFCNB SESSION ACK: Length = %i\n", - RFCNB_Pkt_Len(pkt -> data)); + case RFCNB_SESSION_ACK: - break; + fprintf(fd, "RFCNB SESSION ACK: Length = %i\n", + RFCNB_Pkt_Len(pkt->data)); - case RFCNB_SESSION_REJ: - fprintf(fd, "RFCNB SESSION REJECT: Length = %i\n", - RFCNB_Pkt_Len(pkt -> data)); + break; - 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)); - } + 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; + break; - case RFCNB_SESSION_RETARGET: + case RFCNB_SESSION_RETARGET: - fprintf(fd, "RFCNB SESSION RETARGET: Length = %i\n", - RFCNB_Pkt_Len(pkt -> data)); + fprintf(fd, "RFCNB SESSION RETARGET: Length = %i\n", + RFCNB_Pkt_Len(pkt->data)); - /* Print out the IP address etc and the port? */ + /* Print out the IP address etc and the port? */ - break; + break; - case RFCNB_SESSION_KEEP_ALIVE: + case RFCNB_SESSION_KEEP_ALIVE: - fprintf(fd, "RFCNB SESSION KEEP ALIVE: Length = %i\n", - RFCNB_Pkt_Len(pkt -> data)); - break; + fprintf(fd, "RFCNB SESSION KEEP ALIVE: Length = %i\n", + RFCNB_Pkt_Len(pkt->data)); + break; default: - break; - } + break; + } } /* Resolve a name into an address */ -int RFCNB_Name_To_IP(char *host, struct in_addr *Dest_IP) +int +RFCNB_Name_To_IP(char *host, struct in_addr *Dest_IP) +{ + int addr; /* Assumes IP4, 32 bit network addresses */ + struct hostent *hp; -{ int addr; /* Assumes IP4, 32 bit network addresses */ - struct hostent *hp; + /* Use inet_addr to try to convert the address */ - /* Use inet_addr to try to convert the address */ + if ((addr = inet_addr(host)) == INADDR_NONE) { /* Oh well, a good try :-) */ - if ((addr = inet_addr(host)) == INADDR_NONE) { /* Oh well, a good try :-) */ + /* Now try a name look up with gethostbyname */ - /* Now try a name look up with gethostbyname */ + if ((hp = gethostbyname(host)) == NULL) { /* Not in DNS */ - if ((hp = gethostbyname(host)) == NULL) { /* Not in DNS */ + /* Try NetBIOS name lookup, how the hell do we do that? */ - /* 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); - RFCNB_errno = RFCNBE_BadName; /* Is this right? */ - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); + } else { /* We got a name */ - } - else { /* We got a name */ + memcpy((void *) Dest_IP, (void *) hp->h_addr_list[0], sizeof(struct in_addr)); - memcpy((void *)Dest_IP, (void *)hp -> h_addr_list[0], sizeof(struct in_addr)); + } + } else { /* It was an IP address */ - } - } - else { /* It was an IP address */ + memcpy((void *) Dest_IP, (void *) &addr, sizeof(struct in_addr)); - memcpy((void *)Dest_IP, (void *)&addr, sizeof(struct in_addr)); - - } + } - return 0; + return 0; } /* Disconnect the TCP connection to the server */ -int RFCNB_Close(int socket) - +int +RFCNB_Close(int socket) { - close(socket); + close(socket); - /* If we want to do error recovery, here is where we put it */ + /* If we want to do error recovery, here is where we put it */ - return 0; + 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; + * Not sure how to handle socket options etc. */ - /* Create a socket */ +int +RFCNB_IP_Connect(struct in_addr Dest_IP, int port) +{ + struct sockaddr_in Socket; + int fd; - if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { /* Handle the error */ + /* Create a socket */ - RFCNB_errno = RFCNBE_BadSocket; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); - } + if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { /* Handle the error */ - bzero((char *)&Socket, sizeof(Socket)); - memcpy((char *)&Socket.sin_addr, (char *)&Dest_IP, sizeof(Dest_IP)); + 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; + Socket.sin_port = htons(port); + Socket.sin_family = PF_INET; - /* Now connect to the destination */ + /* Now connect to the destination */ - if (connect(fd, (struct sockaddr *)&Socket, sizeof(Socket)) < 0) { /* Error */ + if (connect(fd, (struct sockaddr *) &Socket, sizeof(Socket)) < 0) { /* Error */ - close(fd); - RFCNB_errno = RFCNBE_ConnectFailed; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); + close(fd); + RFCNB_errno = RFCNBE_ConnectFailed; + RFCNB_saved_errno = errno; + return (RFCNBE_Bad); } - - return(fd); + 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 */ + * 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; - char resp[16]; - int len; - struct RFCNB_Pkt *pkt, res_pkt; + /* Response packet should be no more than 9 bytes, make 16 jic */ - /* We build and send the session request, then read the response */ + char resp[16]; + int len; + struct RFCNB_Pkt *pkt, res_pkt; - pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Sess_Len); + /* We build and send the session request, then read the response */ - if (pkt == NULL) { + pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Sess_Len); - return(RFCNBE_Bad); /* Leave the error that RFCNB_Alloc_Pkt gives) */ + 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 = 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; + 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)); + 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 */ + /* Now send the packet */ #ifdef RFCNB_DEBUG - fprintf(stderr, "Sending packet: "); - + fprintf(stderr, "Sending packet: "); + #endif - if ((len = RFCNB_Put_Pkt(con, pkt, RFCNB_Pkt_Sess_Len)) < 0) { + if ((len = RFCNB_Put_Pkt(con, pkt, RFCNB_Pkt_Sess_Len)) < 0) { - return(RFCNBE_Bad); /* Should be able to write that lot ... */ + return (RFCNBE_Bad); /* Should be able to write that lot ... */ } - #ifdef RFCNB_DEBUG - fprintf(stderr, "Getting packet.\n"); + fprintf(stderr, "Getting packet.\n"); #endif - res_pkt.data = resp; - res_pkt.len = sizeof(resp); - res_pkt.next = NULL; + res_pkt.data = resp; + res_pkt.len = sizeof(resp); + res_pkt.next = NULL; - if ((len = RFCNB_Get_Pkt(con, &res_pkt, sizeof(resp))) < 0) { + if ((len = RFCNB_Get_Pkt(con, &res_pkt, sizeof(resp))) < 0) { - return(RFCNBE_Bad); + return (RFCNBE_Bad); - } + } + /* Now analyze the packet ... */ - /* Now analyze the packet ... */ + switch (RFCNB_Pkt_Type(resp)) { - switch (RFCNB_Pkt_Type(resp)) { + case RFCNB_SESSION_REJ: /* Didnt like us ... too bad */ - case RFCNB_SESSION_REJ: /* Didnt like us ... too bad */ + /* Why did we get rejected ? */ - /* Why did we get rejected ? */ - - switch (CVAL(resp,RFCNB_Pkt_Error_Offset)) { + 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; + } - case 0x80: - RFCNB_errno = RFCNBE_CallRejNLOCN; - break; - case 0x81: - RFCNB_errno = RFCNBE_CallRejNLFCN; - break; - case 0x82: - RFCNB_errno = RFCNBE_CallRejCNNP; + return (RFCNBE_Bad); 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 ... */ + case RFCNB_SESSION_ACK: /* Got what we wanted ... */ - return(0); - break; + return (0); + break; - case RFCNB_SESSION_RETARGET: /* Go elsewhere */ + case RFCNB_SESSION_RETARGET: /* Go elsewhere */ - *redirect = TRUE; /* Copy port and ip addr */ + *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); + memcpy(Dest_IP, (resp + RFCNB_Pkt_IP_Offset), sizeof(struct in_addr)); + *port = SVAL(resp, RFCNB_Pkt_Port_Offset); - return(0); - break; + return (0); + break; - default: /* A protocol error */ + default: /* A protocol error */ - RFCNB_errno = RFCNBE_ProtErr; - return(RFCNBE_Bad); - break; + RFCNB_errno = RFCNBE_ProtErr; + return (RFCNBE_Bad); + break; } } - - - - - - - - - Index: squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-util.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/rfcnb-util.h,v retrieving revision 1.1.2.1.2.3 retrieving revision 1.1.2.1.2.4 diff -u -r1.1.2.1.2.3 -r1.1.2.1.2.4 --- squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-util.h 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.3 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb-util.h 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.4 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB Utility Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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); @@ -30,11 +30,11 @@ void RFCNB_NBName_To_AName(char *NBName, char *AName); -void RFCNB_Print_Hex(FILE *fd, struct RFCNB_Pkt *pkt, int Offset, int Len); +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); +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); @@ -42,11 +42,9 @@ int RFCNB_IP_Connect(struct in_addr Dest_IP, int port); -int RFCNB_Session_Req(struct RFCNB_Con *con, - char *Called_Name, - char *Calling_Name, - BOOL *redirect, - struct in_addr *Dest_IP, - int * port); - - +int RFCNB_Session_Req(struct RFCNB_Con *con, + char *Called_Name, + char *Calling_Name, + BOOL * redirect, + struct in_addr *Dest_IP, + int *port); Index: squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/rfcnb.h,v retrieving revision 1.1.2.1.2.3 retrieving revision 1.1.2.1.2.4 diff -u -r1.1.2.1.2.3 -r1.1.2.1.2.4 --- squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb.h 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.3 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/rfcnb.h 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.4 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - RFCNB Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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 */ @@ -36,7 +36,7 @@ /* Definition of routines we define */ void *RFCNB_Call(char *Called_Name, char *Calling_Name, char *Called_Address, - int port); + int port); int RFCNB_Send(void *Con_Handle, struct RFCNB_Pkt *Data, int Length); Index: squid/ntlm_auth_modules/NTLMSSP/smbval/session.c =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/session.c,v retrieving revision 1.1.2.1.2.4 retrieving revision 1.1.2.1.2.5 diff -u -r1.1.2.1.2.4 -r1.1.2.1.2.5 --- squid/ntlm_auth_modules/NTLMSSP/smbval/session.c 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.4 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/session.c 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.5 @@ -1,27 +1,27 @@ /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation - - Version 1.0 - Session Routines ... - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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 @@ -38,290 +38,285 @@ /* global data structures */ -static char *RFCNB_Error_Strings[] = { +static 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 ..." + "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 ..." }; int RFCNB_Stats[RFCNB_MAX_STATS]; -void (*Prot_Print_Routine)() = NULL; /* Pointer to print routine */ +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; + * 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 ... */ + /* Now, we really should look up the port in /etc/services ... */ - if (port == 0) port = RFCNB_Default_Port; + if (port == 0) + port = RFCNB_Default_Port; - /* Create a connection structure first */ + /* Create a connection structure first */ - if ((con = (struct RFCNB_Con *)malloc(sizeof(struct RFCNB_Con))) == NULL) { /* Error in size */ + if ((con = (struct RFCNB_Con *) malloc(sizeof(struct RFCNB_Con))) == NULL) { /* Error in size */ - RFCNB_errno = RFCNBE_NoSpace; - RFCNB_saved_errno = errno; - return(NULL); + 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); - + 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 */ - /* Now connect to the remote end */ + /* No need to modify RFCNB_errno as it was done by RFCNB_Name_To_IP */ - redirect = TRUE; /* Fudge this one so we go once through */ + return (NULL); - while (redirect) { /* Connect and get session info etc */ + } + /* Now connect to the remote end */ - redirect = FALSE; /* Assume all OK */ + redirect = TRUE; /* Fudge this one so we go once through */ - /* Build the redirect info. First one is first addr called */ - /* And tack it onto the list of addresses we called */ + while (redirect) { /* Connect and get session info etc */ - 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); + 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 */ - memcpy((char *)&(redir_addr -> ip_addr), (char *)&Dest_IP, sizeof(Dest_IP)); - redir_addr -> port = port; - redir_addr -> next = NULL; + if ((redir_addr = (struct redirect_addr *) malloc(sizeof(struct redirect_addr))) == NULL) { /* Could not get space */ - if (con -> redirect_list == NULL) { /* Stick on head */ + RFCNB_errno = RFCNBE_NoSpace; + RFCNB_saved_errno = errno; + return (NULL); - con -> redirect_list = con -> last_addr = redir_addr; + } + memcpy((char *) &(redir_addr->ip_addr), (char *) &Dest_IP, sizeof(Dest_IP)); + redir_addr->port = port; + redir_addr->next = NULL; - } else { + if (con->redirect_list == NULL) { /* Stick on head */ - con -> last_addr -> next = redir_addr; - con -> last_addr = redir_addr; + con->redirect_list = con->last_addr = redir_addr; - } + } else { - /* Now, make that connection */ + con->last_addr->next = redir_addr; + con->last_addr = redir_addr; - if ((Client = RFCNB_IP_Connect(Dest_IP, port)) < 0) { /* Error */ + } - /* No need to modify RFCNB_errno as it was done by RFCNB_IP_Connect */ + /* Now, make that connection */ - return(NULL); + if ((Client = RFCNB_IP_Connect(Dest_IP, port)) < 0) { /* Error */ - } + /* No need to modify RFCNB_errno as it was done by RFCNB_IP_Connect */ - con -> fd = Client; + return (NULL); - /* 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 */ + } + con->fd = Client; - if ((errno = RFCNB_Session_Req(con, - Called_Name, - Calling_Name, - &redirect, &Dest_IP, &port)) < 0) { + /* 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 */ - /* No need to modify RFCNB_errno as it was done by RFCNB_Session.. */ + if ((errno = RFCNB_Session_Req(con, + Called_Name, + Calling_Name, + &redirect, &Dest_IP, &port)) < 0) { - return(NULL); + /* No need to modify RFCNB_errno as it was done by RFCNB_Session.. */ - } + return (NULL); - if (redirect) { + } + if (redirect) { - /* We have to close the connection, and then try again */ + /* We have to close the connection, and then try again */ - (con -> redirects)++; + (con->redirects)++; - RFCNB_Close(con -> fd); /* Close it */ + RFCNB_Close(con->fd); /* Close it */ - } + } } - return(con); + 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 ... */ + * 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 */ +int +RFCNB_Send(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *udata, int Length) +{ + struct RFCNB_Pkt *pkt; + char *hdr; + int len; - pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len); + /* Plug in the header and send the data */ - if (pkt == NULL) { + pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len); - RFCNB_errno = RFCNBE_NoSpace; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); + if (pkt == NULL) { - } + RFCNB_errno = RFCNBE_NoSpace; + RFCNB_saved_errno = errno; + return (RFCNBE_Bad); - pkt -> next = udata; /* The user data we want to send */ + } + pkt->next = udata; /* The user data we want to send */ - hdr = pkt -> data; + hdr = pkt->data; - /* Following crap is for portability across multiple UNIX machines */ + /* Following crap is for portability across multiple UNIX machines */ - *(hdr + RFCNB_Pkt_Type_Offset) = RFCNB_SESSION_MESSAGE; - RFCNB_Put_Pkt_Len(hdr, Length); + *(hdr + RFCNB_Pkt_Type_Offset) = RFCNB_SESSION_MESSAGE; + RFCNB_Put_Pkt_Len(hdr, Length); #ifdef RFCNB_DEBUG - fprintf(stderr, "Sending packet: "); - + fprintf(stderr, "Sending packet: "); + #endif - if ((len = RFCNB_Put_Pkt(Con_Handle, pkt, Length + RFCNB_Pkt_Hdr_Len)) < 0) { + 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 ... */ + /* No need to change RFCNB_errno as it was done by put_pkt ... */ - return(RFCNBE_Bad); /* Should be able to write that lot ... */ - - } + 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 */ + } + /* Now we have sent that lot, let's get rid of the RFCNB Header and return */ - pkt -> next = NULL; + pkt->next = NULL; - RFCNB_Free_Pkt(pkt); + RFCNB_Free_Pkt(pkt); - return(len); + 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; + * non-message packets ... */ - if (con_Handle == NULL){ - - RFCNB_errno = RFCNBE_BadHandle; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); +int +RFCNB_Recv(void *con_Handle, struct RFCNB_Pkt *Data, int Length) +{ + struct RFCNB_Pkt *pkt; + int ret_len; - } + if (con_Handle == NULL) { - /* Now get a packet from below. We allocate a header first */ + RFCNB_errno = RFCNBE_BadHandle; + RFCNB_saved_errno = errno; + return (RFCNBE_Bad); - /* Plug in the header and send the data */ + } + /* Now get a packet from below. We allocate a header first */ - pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len); + /* Plug in the header and send the data */ - if (pkt == NULL) { + pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len); - RFCNB_errno = RFCNBE_NoSpace; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); + if (pkt == NULL) { - } + RFCNB_errno = RFCNBE_NoSpace; + RFCNB_saved_errno = errno; + return (RFCNBE_Bad); - pkt -> next = Data; /* Plug in the data portion */ + } + pkt->next = Data; /* Plug in the data portion */ - if ((ret_len = RFCNB_Get_Pkt(con_Handle, pkt, Length + RFCNB_Pkt_Hdr_Len)) < 0) { + 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"); + fprintf(stderr, "Bad packet return in RFCNB_Recv... \n"); #endif - return(RFCNBE_Bad); - - } + return (RFCNBE_Bad); - /* We should check that we go a message and not a keep alive */ + } + /* We should check that we go a message and not a keep alive */ - pkt -> next = NULL; + pkt->next = NULL; - RFCNB_Free_Pkt(pkt); + RFCNB_Free_Pkt(pkt); - return(ret_len); + 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) - +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; + 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) - +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))); + return (setsockopt(con_Handle->fd, IPPROTO_TCP, TCP_NODELAY, + (char *) &yn, sizeof(yn))); } @@ -329,66 +324,65 @@ /* Listen for a connection on a port???, when */ /* the connection comes in, we return with the connection */ -void *RFCNB_Listen() - +void * +RFCNB_Listen() { - fprintf(stderr,"RFCNB_Listen NOT IMPLEMENTED as yet!\n"); - return NULL; + fprintf(stderr, "RFCNB_Listen NOT IMPLEMENTED as yet!\n"); + return NULL; } /* 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) - +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], + 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() - +int +RFCNB_Get_Last_Error() { - return(RFCNB_errno); + return (RFCNB_errno); } /* Pick up saved errno as well */ -int RFCNB_Get_Last_Errno() - +int +RFCNB_Get_Last_Errno() { - return(RFCNB_saved_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) - +void +RFCNB_Get_Error_Msg(int code, char *msg_buf, int len) { - strncpy(msg_buf, RFCNB_Error_Strings[abs(code)], len); + strncpy(msg_buf, RFCNB_Error_Strings[abs(code)], len); } /* Register a higher level protocol print routine */ -void RFCNB_Register_Print_Routine(void (*fn)()) - +void +RFCNB_Register_Print_Routine(void (*fn) ()) { - Prot_Print_Routine = fn; + Prot_Print_Routine = fn; } Index: squid/ntlm_auth_modules/NTLMSSP/smbval/smbdes.c =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/smbdes.c,v retrieving revision 1.1.2.1.2.2 retrieving revision 1.1.2.1.2.3 diff -u -r1.1.2.1.2.2 -r1.1.2.1.2.3 --- squid/ntlm_auth_modules/NTLMSSP/smbval/smbdes.c 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.2 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/smbdes.c 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.3 @@ -1,337 +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. -*/ + * 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 < 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]; - 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); - } + 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) +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; - } + int i; + char outb[64]; + char inb[64]; + char keyb[64]; + unsigned char key2[8]; - dohash(outb, inb, keyb); + str_to_key(key, key2); - for (i=0;i<8;i++) { - out[i] = 0; - } + 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; + } - for (i=0;i<64;i++) { - if (outb[i]) - out[i/8] |= (1<<(7-(i%8))); - } + 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) +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); + 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) +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); + 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) +void +cred_hash1(unsigned char *out, unsigned char *in, unsigned char *key) { - unsigned char buf[8]; + unsigned char buf[8]; - smbhash(buf, in, key); - smbhash(out, buf, key+9); + smbhash(buf, in, key); + smbhash(out, buf, key + 9); } -void cred_hash2(unsigned char *out,unsigned char *in,unsigned char *key) +void +cred_hash2(unsigned char *out, unsigned char *in, unsigned char *key) { - unsigned char buf[8]; - static unsigned char key2[8]; + unsigned char buf[8]; + static unsigned char key2[8]; - smbhash(buf, in, key); - key2[0] = key[7]; - smbhash(out, buf, key2); + smbhash(buf, in, key); + key2[0] = key[7]; + smbhash(out, buf, key2); } - Index: squid/ntlm_auth_modules/NTLMSSP/smbval/smbdes.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/smbdes.h,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid/ntlm_auth_modules/NTLMSSP/smbval/smbdes.h 7 Jan 2001 02:49:32 -0000 1.1.2.3 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/smbdes.h 7 Jan 2001 09:48:29 -0000 1.1.2.4 @@ -1,2 +1,2 @@ -void E_P16(unsigned char *p14,unsigned char *p16); +void E_P16(unsigned char *p14, unsigned char *p16); void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24); Index: squid/ntlm_auth_modules/NTLMSSP/smbval/smbencrypt.c =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/smbencrypt.c,v retrieving revision 1.1.2.1.2.4 retrieving revision 1.1.2.1.2.5 diff -u -r1.1.2.1.2.4 -r1.1.2.1.2.5 --- squid/ntlm_auth_modules/NTLMSSP/smbval/smbencrypt.c 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.4 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/smbencrypt.c 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.5 @@ -1,24 +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. -*/ + * 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 @@ -37,33 +37,35 @@ #include "byteorder.h" -char *StrnCpy(char *dest,char *src,int n); +char *StrnCpy(char *dest, char *src, int n); 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); + * 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) +static int +_my_wcslen(int16 * str) { - int len = 0; - while(*str++ != 0) - len++; - return len; + int len = 0; + while (*str++ != 0) + len++; + return len; } /* @@ -72,129 +74,135 @@ * this must be in intel (little-endian) * format. */ - -static int _my_mbstowcs(int16 *dst, uchar *src, int len) + +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; + 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) + +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); + int len; + int16 wpwd[129]; - mdfour(p16, (unsigned char *)wpwd, len); + /* 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) + +void +SMBNTencrypt(uchar * passwd, uchar * c8, uchar * p24) { - uchar p21[21]; - - memset(p21,'\0',21); - - E_md4hash(passwd, p21); - E_P24(p21, c8, 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) +void +nt_lm_owf_gen(char *pwd, char *nt_p16, char *p16) { - char passwd[130]; - StrnCpy(passwd, pwd, sizeof(passwd)-1); + 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); + /* 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); + /* Mangle the passwords into Lanman format */ + passwd[14] = '\0'; + strupper(passwd); - /* Calculate the SMB (lanman) hash functions of the password */ + /* Calculate the SMB (lanman) hash functions of the password */ - memset(p16, '\0', 16); - E_P16((uchar *) passwd, (uchar *)p16); + 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)); + /* 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 * +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++; - } + char *d = dest; + if (!dest) + return (NULL); + if (!src) { + *dest = 0; + return (dest); } - else -#endif */ /* KANJI_WIN95_COMPATIBILITY */ - { - if (islower(*s)) - *s = toupper(*s); - s++; + 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++; + } } - } -} +} Index: squid/ntlm_auth_modules/NTLMSSP/smbval/smbencrypt.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/smbencrypt.h,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid/ntlm_auth_modules/NTLMSSP/smbval/smbencrypt.h 7 Jan 2001 02:49:32 -0000 1.1.2.3 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/smbencrypt.h 7 Jan 2001 09:48:29 -0000 1.1.2.4 @@ -1 +1 @@ -void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24); +void SMBencrypt(uchar * passwd, uchar * c8, uchar * p24); Index: squid/ntlm_auth_modules/NTLMSSP/smbval/smblib-common.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/smblib-common.h,v retrieving revision 1.1.2.2.2.2 retrieving revision 1.1.2.2.2.3 diff -u -r1.1.2.2.2.2 -r1.1.2.2.2.3 --- squid/ntlm_auth_modules/NTLMSSP/smbval/smblib-common.h 7 Jan 2001 02:49:32 -0000 1.1.2.2.2.2 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/smblib-common.h 7 Jan 2001 09:48:29 -0000 1.1.2.2.2.3 @@ -2,29 +2,29 @@ #define __SMBLIB_COMMON_H__ /* UNIX SMBlib NetBIOS implementation - - Version 1.0 - SMBlib Common Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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,7 +76,7 @@ /* Server errors ... */ -#define SMBV_error 0x01 /* Generic error */ +#define SMBV_error 0x01 /* Generic error */ #define SMBV_badpw 0x02 #define SMBV_badtype 0x03 #define SMBV_access 0x04 @@ -141,12 +141,12 @@ /* Define the protocol types ... */ -#define SMB_P_Unknown -1 /* Hmmm, is this smart? */ +#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_DOSLanMan2 4 #define SMB_P_LanMan2 5 #define SMB_P_DOSLanMan2_1 6 #define SMB_P_LanMan2_1 7 @@ -161,28 +161,28 @@ /* 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_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 */ +#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; Index: squid/ntlm_auth_modules/NTLMSSP/smbval/smblib-priv.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/smblib-priv.h,v retrieving revision 1.1.2.2.2.4 retrieving revision 1.1.2.2.2.5 diff -u -r1.1.2.2.2.4 -r1.1.2.2.2.5 --- squid/ntlm_auth_modules/NTLMSSP/smbval/smblib-priv.h 7 Jan 2001 02:49:32 -0000 1.1.2.2.2.4 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/smblib-priv.h 7 Jan 2001 09:48:29 -0000 1.1.2.2.2.5 @@ -2,29 +2,29 @@ #define __SMBLIB_PRIV_H__ /* UNIX SMBlib NetBIOS implementation - - Version 1.0 - SMBlib private Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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" @@ -32,106 +32,106 @@ #include typedef unsigned short uint16; -typedef unsigned int uint32; +typedef unsigned int uint32; -#include "byteorder.h" /* Hmmm ... hot good */ +#include "byteorder.h" /* Hmmm ... hot good */ #define max(a,b) (a < b ? b : a) -#define SMB_DEF_IDF 0x424D53FF /* "\377SMB" */ - +#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 */ +#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 */ +#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 */ +#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 */ +#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 ? */ +#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; @@ -165,17 +165,17 @@ /* 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_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 @@ -187,275 +187,275 @@ #define SMB_hdr_mid_offset 30 #define SMB_hdr_wct_offset 32 -#define SMB_hdr_len 33 /* 33 byte header? */ +#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 */ +#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 */ +#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_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_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_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_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 */ +#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_tdis_bcc_offset 33 /* bcc */ +#define SMB_tdis_len 35 /* total len */ -#define SMB_tdisr_bcc_offset 33 /* bcc */ +#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_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_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_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_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_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_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 */ +#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_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_creat_len 41 /* Before the data */ -#define SMB_creatr_fid_offset 33 /* FID of created file */ +#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_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_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_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 */ +#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_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_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_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_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_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 */ +#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_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_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_pdi_offset 43 /* parameter displacement */ #define SMB_transr_dbc_offset 45 #define SMB_transr_dbo_offset 47 #define SMB_transr_ddi_offset 49 @@ -480,17 +480,23 @@ #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; +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 ... */ @@ -499,89 +505,89 @@ extern char *SMB_Prots[]; /* -static 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}; -*/ + * static 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}; + */ extern int SMB_Types[]; /* -static 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}; -*/ + * static 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}; + */ typedef struct SMB_Status { - union { - struct { - unsigned char ErrorClass; - unsigned char Reserved; - unsigned short Error; - } DosError; - unsigned int NtStatus; - } 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_Tree_Structure *SMB_Tree_Handle; -typedef struct SMB_Connect_Def * SMB_Handle_Type; +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]; + 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]; }; @@ -599,12 +605,12 @@ 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; + SMB_Tree_Handle next, prev; + SMB_Handle_Type con; + char path[129]; + char device_type[20]; + int mbs; /* Local MBS */ + int tid; }; @@ -612,13 +618,13 @@ 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; + 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; }; @@ -628,11 +634,11 @@ #ifndef SMBLIB_ERRNO extern int SMBlib_errno; -extern int SMBlib_SMB_Error; /* last Error */ +extern int SMBlib_SMB_Error; /* last Error */ #endif SMB_Tree_Handle SMB_TreeConnect(SMB_Handle_Type con, SMB_Tree_Handle tree, - char *path, char *password, char *dev); + char *path, char *password, char *dev); int SMB_Init(); void SMB_Get_My_Name(char *name, int len); @@ -640,7 +646,7 @@ int SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle); int SMB_Logon_Server(SMB_Handle_Type Con_Handle, char *UserName, - char *PassWord, char *UserDomain, int precrypted); + char *PassWord, char *UserDomain, int precrypted); int SMB_Get_Error_Msg(int msg, char *msgbuf, int len); Index: squid/ntlm_auth_modules/NTLMSSP/smbval/smblib-util.c =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/smblib-util.c,v retrieving revision 1.1.2.1.2.5 retrieving revision 1.1.2.1.2.6 diff -u -r1.1.2.1.2.5 -r1.1.2.1.2.6 --- squid/ntlm_auth_modules/NTLMSSP/smbval/smblib-util.c 7 Jan 2001 07:54:38 -0000 1.1.2.1.2.5 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/smblib-util.c 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.6 @@ -1,27 +1,27 @@ /* UNIX SMBlib NetBIOS implementation - - Version 1.0 - SMBlib Utility Routines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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 @@ -31,160 +31,160 @@ /* global data structures */ -static 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}; - -static 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}; +static 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}; + +static 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}; /* 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) - +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 */ + /* Well, just how do we do this ... print it I suppose */ - /* Print out the SMB header ... */ + /* Print out the SMB header ... */ - /* Print the command */ + /* Print the command */ - /* Print the other bits in the header */ + /* Print the other bits in the header */ - /* etc */ + /* 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; +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; + SMB_Time_Temp[0] = 0; - DOS_sec = (DOS_time & 0x001F) * 2; - DOS_min = (DOS_time & 0x07E0) >> 5; - DOS_hour = ((DOS_time & 0xF800) >> 11); + 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; + 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); + 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); + 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 ... */ + * 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]; +char * +SMB_AtrToStr(int attribs, BOOL verbose) +{ + static char SMB_Attrib_Temp[128]; - SMB_Attrib_Temp[0] = 0; + SMB_Attrib_Temp[0] = 0; - if (attribs & SMB_FA_ROF) - strcat(SMB_Attrib_Temp, (verbose?"Read Only ":"R")); + 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_HID) + strcat(SMB_Attrib_Temp, (verbose ? "Hidden " : "H")); - if (attribs & SMB_FA_SYS) - strcat(SMB_Attrib_Temp, (verbose?"System ":"S")); + 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_VOL) + strcat(SMB_Attrib_Temp, (verbose ? "Volume " : "V")); - if (attribs & SMB_FA_DIR) - strcat(SMB_Attrib_Temp, (verbose?"Directory ":"D")); + if (attribs & SMB_FA_DIR) + strcat(SMB_Attrib_Temp, (verbose ? "Directory " : "D")); - if (attribs & SMB_FA_ARC) - strcat(SMB_Attrib_Temp, (verbose?"Archive ":"A")); + if (attribs & SMB_FA_ARC) + strcat(SMB_Attrib_Temp, (verbose ? "Archive " : "A")); - return(SMB_Attrib_Temp); + return (SMB_Attrib_Temp); } /* Pick up the Max Buffer Size from the Tree Structure ... */ -int SMB_Get_Tree_MBS(SMB_Tree_Handle tree) - +int +SMB_Get_Tree_MBS(SMB_Tree_Handle tree) { - if (tree != NULL) { - return(tree -> mbs); - } - else { - return(SMBlibE_BAD); - } + 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) - +int +SMB_Get_Max_Buf_Siz(SMB_Handle_Type Con_Handle) { - if (Con_Handle != NULL) { - return(Con_Handle -> max_xmit); - } - else { - return(SMBlibE_BAD); - } + 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) - +int +SMB_Get_Protocol_IDX(SMB_Handle_Type Con_Handle) { - if (Con_Handle != NULL) { - return(Con_Handle -> prot_IDX); - } - else { - return(0xFFFF); /* Invalid protocol */ - } + 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) - +int +SMB_Get_Protocol(SMB_Handle_Type Con_Handle) { - if (Con_Handle != NULL) { - return(Con_Handle -> protocol); - } - else { - return(0xFFFF); /* Invalid protocol */ - } + if (Con_Handle != NULL) { + return (Con_Handle->protocol); + } else { + return (0xFFFF); /* Invalid protocol */ + } } @@ -192,32 +192,31 @@ /* 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; +int +SMB_Figure_Protocol(char *dialects[], int prot_index) +{ + int i; - if (dialects == SMB_Prots) { /* The jobs is easy, just index into table */ + 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 */ + return (SMB_Types[prot_index]); + } else { /* Search through SMB_Prots looking for a match */ - for (i = 0; SMB_Prots[i] != NULL; i++) { + for (i = 0; SMB_Prots[i] != NULL; i++) { - if (strcmp(dialects[prot_index], SMB_Prots[i]) == 0) { /* A match */ + if (strcmp(dialects[prot_index], SMB_Prots[i]) == 0) { /* A match */ - return(SMB_Types[i]); + return (SMB_Types[i]); - } + } + } - } + /* If we got here, then we are in trouble, because the protocol was not */ + /* One we understand ... */ - /* If we got here, then we are in trouble, because the protocol was not */ - /* One we understand ... */ + return (SMB_P_Unknown); - return(SMB_P_Unknown); - - } + } } @@ -226,537 +225,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, char *Prots[]) - +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 */ + struct RFCNB_Pkt *pkt; + int prots_len, i, pkt_len, prot, alloc_len; + char *p; - prots_len = 0; + /* Figure out how long the prot list will be and allocate space for it */ - for (i = 0; Prots[i] != NULL; i++) { + prots_len = 0; - prots_len = prots_len + strlen(Prots[i]) + 2; /* Account for null etc */ + 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; + /* The -1 accounts for the one byte smb_buf we have because some systems */ + /* don't like char msg_buf[] */ - /* 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 */ + pkt_len = SMB_negp_len + prots_len; - if (pkt_len < (SMB_hdr_wct_offset + (19 * 2) + 40)) { + /* 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 */ - alloc_len = SMB_hdr_wct_offset + (19 * 2) + 40; + if (pkt_len < (SMB_hdr_wct_offset + (19 * 2) + 40)) { - } - else { + alloc_len = SMB_hdr_wct_offset + (19 * 2) + 40; - alloc_len = pkt_len; + } else { - } + alloc_len = pkt_len; - pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(alloc_len); + } - if (pkt == NULL) { + pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(alloc_len); - SMBlib_errno = SMBlibE_NoSpace; - return(SMBlibE_BAD); + if (pkt == NULL) { - } + SMBlib_errno = SMBlibE_NoSpace; + return (SMBlibE_BAD); - /* Now plug in the bits we need */ + } + /* 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; + 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); + SSVAL(SMB_Hdr(pkt), SMB_negp_bcc_offset, prots_len); - /* Now copy the prot strings in with the right stuff */ + /* Now copy the prot strings in with the right stuff */ - p = (char *)(SMB_Hdr(pkt) + SMB_negp_buf_offset); + p = (char *) (SMB_Hdr(pkt) + SMB_negp_buf_offset); - for (i = 0; Prots[i] != NULL; i++) { + 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 */ + *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 ... */ + /* Now send the packet and sit back ... */ - if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0){ + if (RFCNB_Send(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error sending negotiate protocol\n"); + fprintf(stderr, "Error sending negotiate protocol\n"); #endif - RFCNB_Free_Pkt(pkt); - SMBlib_errno = -SMBlibE_SendFailed; /* Failed, check lower layer errno */ - return(SMBlibE_BAD); - - } + RFCNB_Free_Pkt(pkt); + SMBlib_errno = -SMBlibE_SendFailed; /* Failed, check lower layer errno */ + return (SMBlibE_BAD); - /* Now get the response ... */ + } + /* Now get the response ... */ - if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, alloc_len) < 0) { + if (RFCNB_Recv(Con_Handle->Trans_Connect, pkt, alloc_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error receiving response to negotiate\n"); + 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); - - } + 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 */ + } + 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", + 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); + 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) { + } + if (SVAL(SMB_Hdr(pkt), SMB_negrCP_idx_offset) == 0xFFFF) { #ifdef DEBUG - fprintf(stderr, "None of our protocols was accepted ... "); + fprintf(stderr, "None of our protocols was accepted ... "); #endif - RFCNB_Free_Pkt(pkt); - SMBlib_errno = SMBlibE_NegNoProt; - return(SMBlibE_BAD); + 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 ... */ - /* 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); - 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 ... */ - if (Con_Handle -> protocol == SMB_P_Unknown) { /* No good ... */ + RFCNB_Free_Pkt(pkt); + SMBlib_errno = SMBlibE_ProtUnknown; + return (SMBlibE_BAD); - RFCNB_Free_Pkt(pkt); - SMBlib_errno = SMBlibE_ProtUnknown; - return(SMBlibE_BAD); + } + switch (CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)) { - } - - switch (CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)) { + case 0x01: /* No more info ... */ - case 0x01: /* No more info ... */ + break; - break; + case 13: /* Up to and including LanMan 2.1 */ - 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 -> 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); - 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, "%8s", (char *)(SMB_Hdr(pkt) + SMB_negrLM_buf_offset)); - memcpy(Con_Handle->Encrypt_Key, p, 8); + p = (SMB_Hdr(pkt) + SMB_negrLM_buf_offset); + fprintf(stderr, "%8s", (char *) (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); + 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); + strncpy(p, Con_Handle->Svr_PDom, sizeof(Con_Handle->Svr_PDom) - 1); - break; + break; - case 17: /* NT LM 0.12 and LN LM 1.0 */ + 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->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); + 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); + 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); + strncpy(p, Con_Handle->Svr_PDom, sizeof(Con_Handle->Svr_PDom) - 1); - break; + break; - default: + default: #ifdef DEBUG - fprintf(stderr, "Unknown NegProt response format ... Ignored\n"); - fprintf(stderr, " wct = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)); + fprintf(stderr, "Unknown NegProt response format ... Ignored\n"); + fprintf(stderr, " wct = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)); #endif - break; - } + break; + } #ifdef DEBUG - fprintf(stderr, "Protocol selected is: %i:%s\n", prot, Prots[prot]); + fprintf(stderr, "Protocol selected is: %i:%s\n", prot, Prots[prot]); #endif - RFCNB_Free_Pkt(pkt); - return(0); + RFCNB_Free_Pkt(pkt); + return (0); } /* Get our hostname */ -void SMB_Get_My_Name(char *name, int len) - -{ +void +SMB_Get_My_Name(char *name, int len) +{ - if (gethostname(name, len) < 0) { /* Error getting name */ + if (gethostname(name, len) < 0) { /* Error getting name */ - strncpy(name, "unknown", len); + strncpy(name, "unknown", len); - /* Should check the error */ + /* Should check the error */ #ifdef DEBUG - fprintf(stderr, "gethostname in SMB_Get_My_Name returned error:"); - perror(""); + fprintf(stderr, "gethostname in SMB_Get_My_Name returned error:"); + perror(""); #endif - } - - /* only keep the portion up to the first "." */ + } + /* 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; +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 ... */ + /* Figure out how much space is needed for path, password, dev ... */ - if ((path == NULL) || (password == NULL) || (device == NULL)) { + if ((path == NULL) || (password == NULL) || (device == NULL)) { #ifdef DEBUG - fprintf(stderr, "Bad parameter passed to SMB_TreeConnect\n"); + fprintf(stderr, "Bad parameter passed to SMB_TreeConnect\n"); #endif - SMBlib_errno = SMBlibE_BadParam; - return(NULL); + SMBlib_errno = SMBlibE_BadParam; + return (NULL); - } + } + /* The + 2 is because of the \0 and the marker ... */ - /* The + 2 is because of the \0 and the marker ... */ + param_len = strlen(path) + 2 + strlen(password) + 2 + strlen(device) + 2; - 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[] */ - /* 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_len = SMB_tcon_len + param_len; + pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len); - pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len); + if (pkt == NULL) { - if (pkt == NULL) { + SMBlib_errno = SMBlibE_NoSpace; + return (NULL); /* Should handle the error */ - SMBlib_errno = SMBlibE_NoSpace; - return(NULL); /* Should handle the error */ + } + /* Now allocate a tree for this to go into ... */ - } + if (Tree_Handle == NULL) { - /* Now allocate a tree for this to go into ... */ + tree = (SMB_Tree_Handle) malloc(sizeof(struct SMB_Tree_Structure)); - if (Tree_Handle == NULL) { + if (tree == NULL) { - tree = (SMB_Tree_Handle)malloc(sizeof(struct SMB_Tree_Structure)); + RFCNB_Free_Pkt(pkt); + SMBlib_errno = SMBlibE_NoSpace; + return (NULL); - if (tree == NULL) { - - RFCNB_Free_Pkt(pkt); - SMBlib_errno = SMBlibE_NoSpace; - return(NULL); - - } - } - else { + } + } else { - tree = Tree_Handle; + 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)); + 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 ... */ + /* 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; + 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); + SSVAL(SMB_Hdr(pkt), SMB_tcon_bcc_offset, param_len); - /* Now copy the param strings in with the right stuff */ + /* 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); + 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 ... */ + /* Now send the packet and sit back ... */ - if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0){ + if (RFCNB_Send(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error sending TCon request\n"); + fprintf(stderr, "Error sending TCon request\n"); #endif - if (Tree_Handle == NULL) - free(tree); - RFCNB_Free_Pkt(pkt); - SMBlib_errno = -SMBlibE_SendFailed; - return(NULL); + if (Tree_Handle == NULL) + free(tree); + RFCNB_Free_Pkt(pkt); + SMBlib_errno = -SMBlibE_SendFailed; + return (NULL); - } - - /* Now get the response ... */ + } + /* Now get the response ... */ - if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) { + if (RFCNB_Recv(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error receiving response to TCon\n"); + 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); + if (Tree_Handle == NULL) + free(tree); + RFCNB_Free_Pkt(pkt); + SMBlib_errno = -SMBlibE_RecvFailed; + return (NULL); - } - - /* Check out the response type ... */ + } + /* Check out the response type ... */ - if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ + 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", + 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); - - } + 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); + } + 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); + fprintf(stderr, "TConn succeeded, with TID=%i, Max Xmit=%i\n", + tree->tid, tree->mbs); #endif - /* Now link the Tree to the Server Structure ... */ + /* Now link the Tree to the Server Structure ... */ - if (Con_Handle -> first_tree == NULL) { + if (Con_Handle->first_tree == NULL) { - Con_Handle -> first_tree = tree; - Con_Handle -> last_tree = tree; + Con_Handle->first_tree = tree; + Con_Handle->last_tree = tree; - } - else { + } else { - Con_Handle -> last_tree -> next = tree; - tree -> prev = Con_Handle -> last_tree; - Con_Handle -> last_tree = tree; + Con_Handle->last_tree->next = tree; + tree->prev = Con_Handle->last_tree; + Con_Handle->last_tree = tree; - } + } - RFCNB_Free_Pkt(pkt); - return(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; +int +SMB_TreeDisconnect(SMB_Tree_Handle Tree_Handle, BOOL discard) +{ + struct RFCNB_Pkt *pkt; + int pkt_len; - pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len); + pkt_len = SMB_tdis_len; - if (pkt == NULL) { + pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len); - SMBlib_errno = SMBlibE_NoSpace; - return(SMBlibE_BAD); /* Should handle the error */ + if (pkt == NULL) { - } + SMBlib_errno = SMBlibE_NoSpace; + return (SMBlibE_BAD); /* Should handle the error */ - /* Now plug in the values ... */ + } + /* 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; + 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); + 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 ... */ + /* Now send the packet and sit back ... */ - if (RFCNB_Send(Tree_Handle -> con -> Trans_Connect, pkt, pkt_len) < 0){ + if (RFCNB_Send(Tree_Handle->con->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error sending TDis request\n"); + fprintf(stderr, "Error sending TDis request\n"); #endif - RFCNB_Free_Pkt(pkt); - SMBlib_errno = -SMBlibE_SendFailed; - return(SMBlibE_BAD); - - } + RFCNB_Free_Pkt(pkt); + SMBlib_errno = -SMBlibE_SendFailed; + return (SMBlibE_BAD); - /* Now get the response ... */ + } + /* Now get the response ... */ - if (RFCNB_Recv(Tree_Handle -> con -> Trans_Connect, pkt, pkt_len) < 0) { + if (RFCNB_Recv(Tree_Handle->con->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error receiving response to TCon\n"); + fprintf(stderr, "Error receiving response to TCon\n"); #endif - RFCNB_Free_Pkt(pkt); - SMBlib_errno = -SMBlibE_RecvFailed; - return(SMBlibE_BAD); + RFCNB_Free_Pkt(pkt); + SMBlib_errno = -SMBlibE_RecvFailed; + return (SMBlibE_BAD); - } - - /* Check out the response type ... */ + } + /* Check out the response type ... */ - if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ + 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", + 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); - - } + 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 */ + } + Tree_Handle->tid = 0xFFFF; /* Invalid TID */ + Tree_Handle->mbs = 0; /* Invalid */ #ifdef DEBUG - fprintf(stderr, "Tree disconnect successful ...\n"); + fprintf(stderr, "Tree disconnect successful ...\n"); #endif - /* What about the tree handle ? */ + /* What about the tree handle ? */ - if (discard == TRUE) { /* Unlink it and free it ... */ + 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->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; + 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); + } + RFCNB_Free_Pkt(pkt); + return (0); } /* Pick up the last LMBlib error ... */ -int SMB_Get_Last_Error() - +int +SMB_Get_Last_Error() { - return(SMBlib_errno); + 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() - +int +SMB_Get_Last_SMB_Err() { - return(SMBlib_SMB_Error); + return (SMBlib_SMB_Error); } @@ -764,57 +745,57 @@ /* Keep this table in sync with the message codes in smblib-common.h */ -static char *SMBlib_Error_Messages[] = { +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.", + "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}; - -int SMB_Get_Error_Msg(int msg, char *msgbuf, int len) + "No such error code.", + NULL}; +int +SMB_Get_Error_Msg(int msg, char *msgbuf, int len) { - if (msg >= 0) { + if (msg >= 0) { - strncpy(msgbuf, - SMBlib_Error_Messages[msg>SMBlibE_NoSuchMsg?SMBlibE_NoSuchMsg:msg], + 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 ... */ + msgbuf[len - 1] = 0; /* Make sure it is a string */ + } else { /* Add the lower layer message ... */ - char prot_msg[1024]; + char prot_msg[1024]; - msg = -msg; /* Make it positive */ + msg = -msg; /* Make it positive */ - strncpy(msgbuf, - SMBlib_Error_Messages[msg>SMBlibE_NoSuchMsg?SMBlibE_NoSuchMsg:msg], + strncpy(msgbuf, + SMBlib_Error_Messages[msg > SMBlibE_NoSuchMsg ? SMBlibE_NoSuchMsg : msg], len - 1); - msgbuf[len - 1] = 0; /* make sure it is a string */ + msgbuf[len - 1] = 0; /* make sure it is a string */ - if (strlen(msgbuf) < len) { /* If there is space, put rest in */ + if (strlen(msgbuf) < len) { /* If there is space, put rest in */ - strncat(msgbuf, "\n\t", len - strlen(msgbuf)); + strncat(msgbuf, "\n\t", len - strlen(msgbuf)); - RFCNB_Get_Error(prot_msg, sizeof(prot_msg) - 1); + RFCNB_Get_Error(prot_msg, sizeof(prot_msg) - 1); - strncat(msgbuf, prot_msg, len - strlen(msgbuf)); + strncat(msgbuf, prot_msg, len - strlen(msgbuf)); + } } - } - return 0; + return 0; } Index: squid/ntlm_auth_modules/NTLMSSP/smbval/smblib.c =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/smblib.c,v retrieving revision 1.1.2.6.2.5 retrieving revision 1.1.2.6.2.6 diff -u -r1.1.2.6.2.5 -r1.1.2.6.2.6 --- squid/ntlm_auth_modules/NTLMSSP/smbval/smblib.c 7 Jan 2001 07:54:38 -0000 1.1.2.6.2.5 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/smblib.c 7 Jan 2001 09:48:29 -0000 1.1.2.6.2.6 @@ -1,27 +1,27 @@ /* UNIX SMBlib NetBIOS implementation - - Version 1.0 - SMBlib Routines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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 "config.h" #include @@ -45,168 +45,163 @@ /* Initialize the SMBlib package */ -int SMB_Init() - +int +SMB_Init() { - SMBlib_State = SMB_State_Started; + SMBlib_State = SMB_State_Started; - signal(SIGPIPE, SIG_IGN); /* Ignore these ... */ + signal(SIGPIPE, SIG_IGN); /* Ignore these ... */ /* If SMBLIB_Instrument is defines, turn on the instrumentation stuff */ #ifdef SMBLIB_INSTRUMENT - SMBlib_Instrument_Init(); + SMBlib_Instrument_Init(); #endif - return 0; + return 0; } -int SMB_Term() - +int +SMB_Term() { #ifdef SMBLIB_INSTRUMENT - SMBlib_Instrument_Term(); /* Clean up and print results */ + SMBlib_Instrument_Term(); /* Clean up and print results */ #endif - return 0; + 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() - +SMB_Handle_Type +SMB_Create_Con_Handle() { - SMBlib_errno = SMBlibE_NotImpl; - return(NULL); + SMBlib_errno = SMBlibE_NotImpl; + return (NULL); } -int SMBlib_Set_Sock_NoDelay(SMB_Handle_Type Con_Handle, BOOL yn) - +int +SMBlib_Set_Sock_NoDelay(SMB_Handle_Type Con_Handle, BOOL yn) { - if (RFCNB_Set_Sock_NoDelay(Con_Handle -> Trans_Connect, yn) < 0) { + if (RFCNB_Set_Sock_NoDelay(Con_Handle->Trans_Connect, yn) < 0) { #ifdef DEBUG #endif - fprintf(stderr, "Setting no-delay on TCP socket failed ...\n"); + fprintf(stderr, "Setting no-delay on TCP socket failed ...\n"); - } - - return(0); + } + 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; +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 */ + /* Get a connection structure if one does not exist */ - con = Con_Handle; + con = Con_Handle; - if (Con_Handle == NULL) { + if (Con_Handle == NULL) { - if ((con = (struct SMB_Connect_Def *)malloc(sizeof(struct SMB_Connect_Def))) == NULL) { + if ((con = (struct SMB_Connect_Def *) malloc(sizeof(struct SMB_Connect_Def))) == NULL) { - SMBlib_errno = SMBlibE_NoSpace; - return NULL; + SMBlib_errno = SMBlibE_NoSpace; + return NULL; + } } + /* Init some things ... */ - } - - /* 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; - 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; - - /* ugh. This is horribly broken. */ + /* ugh. This is horribly broken. */ /* SMB_Get_My_Name(con -> myname, sizeof(con -> myname)); */ - /* hacked by Kinkie */ - i=gethostname(con->myname,sizeof(con->myname)); - if (i==-1) - { - strcpy(con->myname,"unknown"); - } - else { - if (NULL!=(address=strchr(con->myname,'.'))) { - *address='\0'; /* truncate at first '.' */ - } + /* hacked by Kinkie */ + i = gethostname(con->myname, sizeof(con->myname)); + if (i == -1) { + strcpy(con->myname, "unknown"); + } else { + if (NULL != (address = strchr(con->myname, '.'))) { + *address = '\0'; /* truncate at first '.' */ } - + } - con -> port = 0; /* No port selected */ - /* Get some things we need for the SMB Header */ + con->port = 0; /* No port selected */ - 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(); + /* Get some things we need for the SMB Header */ - /* 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 */ + 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(); - for (i=0; i < strlen(server); i++) - called[i] = toupper(server[i]); - - called[strlen(server)] = 0; /* Make it a string */ + /* 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(con -> myname); i++) - calling[i] = toupper(con -> myname[i]); - - calling[strlen(con -> myname)] = 0; /* Make it a string */ + for (i = 0; i < strlen(server); i++) + called[i] = toupper(server[i]); - if (strcmp(con -> address, "") == 0) - address = con -> desthost; - else - address = con -> address; + called[strlen(server)] = 0; /* Make it a string */ - con -> Trans_Connect = RFCNB_Call(called, - calling, - address, /* Protocol specific */ - con -> port); + for (i = 0; i < strlen(con->myname); i++) + calling[i] = toupper(con->myname[i]); - /* Did we get one? */ + calling[strlen(con->myname)] = 0; /* Make it a string */ - if (con -> Trans_Connect == NULL) { + if (strcmp(con->address, "") == 0) + address = con->desthost; + else + address = con->address; - if (Con_Handle == NULL) { - Con_Handle = NULL; - free(con); - } - SMBlib_errno = -SMBlibE_CallFailed; - return NULL; + con->Trans_Connect = RFCNB_Call(called, + calling, + address, /* Protocol specific */ + con->port); - } + /* Did we get one? */ - return(con); + if (con->Trans_Connect == NULL) { + + if (Con_Handle == NULL) { + Con_Handle = NULL; + free(con); + } + SMBlib_errno = -SMBlibE_CallFailed; + return NULL; + + } + return (con); } @@ -214,374 +209,366 @@ /* 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}; - +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; +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 */ + /* Get a connection structure if one does not exist */ - con = Con_Handle; + con = Con_Handle; - if (Con_Handle == NULL) { + if (Con_Handle == NULL) { - if ((con = (struct SMB_Connect_Def *)malloc(sizeof(struct SMB_Connect_Def))) == NULL) { + if ((con = (struct SMB_Connect_Def *) malloc(sizeof(struct SMB_Connect_Def))) == NULL) { - SMBlib_errno = SMBlibE_NoSpace; - return 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; - /* Init some things ... */ + SMB_Get_My_Name(con->myname, sizeof(con->myname)); - 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; + con->port = 0; /* No port selected */ - SMB_Get_My_Name(con -> myname, sizeof(con -> myname)); + /* Get some things we need for the SMB Header */ - con -> port = 0; /* No port selected */ + 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(); - /* Get some things we need for the SMB Header */ + /* Now figure out the host portion of the service */ - 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(); + strcpy(temp, service); + host = (char *) strtok(temp, "/\\"); /* Separate host name portion */ + strcpy(con->desthost, host); - /* Now figure out the host portion of the service */ + /* 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 */ - strcpy(temp, service); - host = (char *)strtok(temp, "/\\"); /* Separate host name portion */ - strcpy(con -> desthost, host); + for (i = 0; i < strlen(host); i++) + called[i] = toupper(host[i]); - /* 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 */ + called[strlen(host)] = 0; /* Make it a string */ - 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]); - for (i=0; i < strlen(con -> myname); i++) - calling[i] = toupper(con -> myname[i]); - - calling[strlen(con -> myname)] = 0; /* Make it a string */ + calling[strlen(con->myname)] = 0; /* Make it a string */ - if (strcmp(con -> address, "") == 0) - address = con -> desthost; - else - address = con -> address; + if (strcmp(con->address, "") == 0) + address = con->desthost; + else + address = con->address; - con -> Trans_Connect = RFCNB_Call(called, - calling, - address, /* Protocol specific */ - con -> port); + con->Trans_Connect = RFCNB_Call(called, + calling, + address, /* Protocol specific */ + con->port); - /* Did we get one? */ + /* Did we get one? */ - if (con -> Trans_Connect == NULL) { + 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) { + if (Con_Handle == NULL) { + free(con); + Con_Handle = NULL; + } + SMBlib_errno = -SMBlibE_CallFailed; + return NULL; - /* Hmmm what should we do here ... We have a connection, but could not - negotiate ... */ + } + /* Now, negotiate the protocol */ - return NULL; + if (SMB_Negotiate(con, SMB_Prots_Restrict) < 0) { - } + /* Hmmm what should we do here ... We have a connection, but could not + * negotiate ... */ - /* Now connect to the service ... */ + return NULL; - if ((*tree = SMB_TreeConnect(con, NULL, service, password, "A:")) == NULL) { + } + /* Now connect to the service ... */ - return NULL; + if ((*tree = SMB_TreeConnect(con, NULL, service, password, "A:")) == NULL) { - } + return NULL; - return(con); + } + 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, char *UserDomain, int precrypted) - -{ 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); - - } - - if (precrypted) { - pass_len=24; - memcpy(pword, PassWord, 24); - } else { - strcpy(pword, PassWord); - if (Con_Handle -> encrypt_passwords) - { - pass_len=24; - SMBencrypt((uchar *) PassWord, (uchar *)Con_Handle -> Encrypt_Key,(uchar *)pword); - } else 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(UserDomain) + 1 + - strlen(Con_Handle -> OSName) + 1; - - pkt_len = SMB_ssetpLM_len + param_len; +int +SMB_Logon_Server(SMB_Handle_Type Con_Handle, char *UserName, + char *PassWord, char *UserDomain, int precrypted) +{ + 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 ... */ - pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len); + if (Con_Handle->protocol < SMB_P_LanMan1) { - if (pkt == NULL) { + SMBlib_errno = SMBlibE_ProtLow; + return (SMBlibE_BAD); - SMBlib_errno = SMBlibE_NoSpace; - fprintf(stderr,"SMB_Logon_server: Couldn't allocate packet\n"); - return(SMBlibE_BAD); /* Should handle the error */ + } + if (precrypted) { + pass_len = 24; + memcpy(pword, PassWord, 24); + } else { + strcpy(pword, PassWord); + if (Con_Handle->encrypt_passwords) { + pass_len = 24; + SMBencrypt((uchar *) PassWord, (uchar *) Con_Handle->Encrypt_Key, (uchar *) pword); + } else + pass_len = strlen(pword); } - 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; + /* Now build the correct structure */ - strcpy(p, UserName); - p = p + strlen(UserName); - *p = 0; + if (Con_Handle->protocol < SMB_P_NT1) { - p = p + 1; + param_len = strlen(UserName) + 1 + pass_len + 1 + + strlen(UserDomain) + 1 + + strlen(Con_Handle->OSName) + 1; - strcpy(p, UserDomain); - p = p + strlen(UserDomain); - *p = 0; - p = p + 1; + pkt_len = SMB_ssetpLM_len + param_len; - strcpy(p, Con_Handle -> OSName); - p = p + strlen(Con_Handle -> OSName); - *p = 0; + pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len); - } - else { + if (pkt == NULL) { - /* We don't admit to UNICODE support ... */ + SMBlib_errno = SMBlibE_NoSpace; + fprintf(stderr, "SMB_Logon_server: Couldn't allocate packet\n"); + 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); - param_len = strlen(UserName) + 1 + pass_len + - strlen(UserDomain) + 1 + - strlen(Con_Handle -> OSName) + 1 + - strlen(Con_Handle -> LMType) + 1; + 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); - pkt_len = SMB_ssetpNTLM_len + param_len; + /* Now copy the param strings in with the right stuff */ - pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len); + p = (char *) (SMB_Hdr(pkt) + SMB_ssetpLM_buf_offset); - if (pkt == NULL) { + /* Copy in password, then the rest. Password has a null at end */ - SMBlib_errno = SMBlibE_NoSpace; - fprintf(stderr,"SMB_Logon_server: Couldn't allocate packet\n"); - return(-1); /* Should handle the error */ - } + memcpy(p, pword, pass_len); - 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); + p = p + pass_len + 1; - 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); + strcpy(p, UserName); + p = p + strlen(UserName); + *p = 0; - /* Now copy the param strings in with the right stuff */ + p = p + 1; - p = (char *)(SMB_Hdr(pkt) + SMB_ssetpNTLM_buf_offset); + strcpy(p, UserDomain); + p = p + strlen(UserDomain); + *p = 0; + p = p + 1; - /* Copy in password, then the rest. Password has no null at end */ + strcpy(p, Con_Handle->OSName); + p = p + strlen(Con_Handle->OSName); + *p = 0; - memcpy(p, pword, pass_len); + } else { - p = p + pass_len; + /* We don't admit to UNICODE support ... */ - strcpy(p, UserName); - p = p + strlen(UserName); - *p = 0; + param_len = strlen(UserName) + 1 + pass_len + + strlen(UserDomain) + 1 + + strlen(Con_Handle->OSName) + 1 + + strlen(Con_Handle->LMType) + 1; - p = p + 1; + pkt_len = SMB_ssetpNTLM_len + param_len; - strcpy(p, UserDomain); - p = p + strlen(UserDomain); - *p = 0; - p = p + 1; + pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len); - strcpy(p, Con_Handle -> OSName); - p = p + strlen(Con_Handle -> OSName); - *p = 0; - p = p + 1; + if (pkt == NULL) { - strcpy(p, Con_Handle -> LMType); - p = p + strlen(Con_Handle -> LMType); - *p = 0; + SMBlib_errno = SMBlibE_NoSpace; + fprintf(stderr, "SMB_Logon_server: Couldn't allocate packet\n"); + 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, UserDomain); + p = p + strlen(UserDomain); + *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 */ + /* Now send it and get a response */ - if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0){ + if (RFCNB_Send(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error sending SessSetupX request\n"); + fprintf(stderr, "Error sending SessSetupX request\n"); #endif - RFCNB_Free_Pkt(pkt); - SMBlib_errno = SMBlibE_SendFailed; - return(SMBlibE_BAD); - - } + RFCNB_Free_Pkt(pkt); + SMBlib_errno = SMBlibE_SendFailed; + return (SMBlibE_BAD); - /* Now get the response ... */ + } + /* Now get the response ... */ - if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) { + if (RFCNB_Recv(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { #ifdef DEBUG - fprintf(stderr, "Error receiving response to SessSetupAndX\n"); + fprintf(stderr, "Error receiving response to SessSetupAndX\n"); #endif - RFCNB_Free_Pkt(pkt); - SMBlib_errno = SMBlibE_RecvFailed; - return(SMBlibE_BAD); + RFCNB_Free_Pkt(pkt); + SMBlib_errno = SMBlibE_RecvFailed; + return (SMBlibE_BAD); - } - - /* Check out the response type ... */ + } + /* Check out the response type ... */ - if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ + 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", + 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); + SMBlib_SMB_Error = IVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset); + RFCNB_Free_Pkt(pkt); + SMBlib_errno = SMBlibE_Remote; + return (SMBlibE_BAD); - } + } /** @@@ mdz: check for guest login { **/ - if (SVAL(SMB_Hdr(pkt), SMB_ssetpr_act_offset) & 0x1) - { - /* do we allow guest login? NO! */ - return(SMBlibE_BAD); - - } - /** @@@ mdz: } **/ + if (SVAL(SMB_Hdr(pkt), SMB_ssetpr_act_offset) & 0x1) { + /* do we allow guest login? NO! */ + return (SMBlibE_BAD); + + } +/** @@@ mdz: } **/ #ifdef DEBUG - fprintf(stderr, "SessSetupAndX response. Action = %i\n", - SVAL(SMB_Hdr(pkt), SMB_ssetpr_act_offset)); + fprintf(stderr, "SessSetupAndX response. Action = %i\n", + SVAL(SMB_Hdr(pkt), SMB_ssetpr_act_offset)); #endif - /* Now pick up the UID for future reference ... */ + /* Now pick up the UID for future reference ... */ - Con_Handle -> uid = SVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset); - RFCNB_Free_Pkt(pkt); + Con_Handle->uid = SVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset); + RFCNB_Free_Pkt(pkt); - return(0); + return (0); } /* Disconnect from the server, and disconnect all tree connects */ -int SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle) - +int +SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle) { - /* We just disconnect the connection for now ... */ - if(Con_Handle!=NULL) RFCNB_Hangup(Con_Handle -> Trans_Connect); + /* We just disconnect the connection for now ... */ + if (Con_Handle != NULL) + RFCNB_Hangup(Con_Handle->Trans_Connect); - if (!KeepHandle) - free(Con_Handle); + if (!KeepHandle) + free(Con_Handle); - return(0); + return (0); } Index: squid/ntlm_auth_modules/NTLMSSP/smbval/smblib.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/smblib.h,v retrieving revision 1.1.2.1.2.3 retrieving revision 1.1.2.1.2.4 diff -u -r1.1.2.1.2.3 -r1.1.2.1.2.4 --- squid/ntlm_auth_modules/NTLMSSP/smbval/smblib.h 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.3 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/smblib.h 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.4 @@ -1,27 +1,27 @@ /* UNIX SMBlib NetBIOS implementation - - Version 1.0 - SMBlib Defines - - Copyright (C) Richard Sharpe 1996 - -*/ + * + * 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. -*/ + * 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" @@ -39,8 +39,8 @@ /* Connect to a server and give us back a handle. If Con == NULL, create */ /* The handle and populate it with defaults */ -void *SMB_Connect(void *Con, void **tree, - char *name, char *User, char *Password); +void *SMB_Connect(void *Con, void **tree, + char *name, char *User, char *Password); /* Negotiate a protocol */ @@ -48,8 +48,8 @@ /* Connect to a tree ... */ -void *SMB_TreeConnect(void *con_handle, void *tree_handle, - char *path, char *password, char *dev); +void *SMB_TreeConnect(void *con_handle, void *tree_handle, + char *path, char *password, char *dev); /* Disconnect a tree ... */ @@ -58,10 +58,10 @@ /* Open a file */ void *SMB_Open(void *tree_handle, - void *file_handle, - char *file_name, - unsigned short mode, - unsigned short search); + void *file_handle, + char *file_name, + unsigned short mode, + unsigned short search); /* Close a file */ @@ -73,9 +73,9 @@ int SMB_Discon(void *Con, BOOL KeepHandle); void *SMB_Create(void *Tree_Handle, - void *File_Handle, - char *file_name, - short search); + void *File_Handle, + char *file_name, + short search); int SMB_Delete(void *tree, char *file_name, short search); @@ -92,7 +92,7 @@ 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); + char *service, char *st); #define SMBLIB_DEFAULT_DOMAIN "anydom" Index: squid/ntlm_auth_modules/NTLMSSP/smbval/std-defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/std-defines.h,v retrieving revision 1.1.2.3.2.2 retrieving revision 1.1.2.3.2.3 diff -u -r1.1.2.3.2.2 -r1.1.2.3.2.3 --- squid/ntlm_auth_modules/NTLMSSP/smbval/std-defines.h 7 Jan 2001 02:49:32 -0000 1.1.2.3.2.2 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/std-defines.h 7 Jan 2001 09:48:29 -0000 1.1.2.3.2.3 @@ -3,28 +3,28 @@ /* RFCNB Standard includes ... */ /* - - SMBlib Standard Includes - - Copyright (C) 1996, Richard Sharpe - - One day we will conditionalize these on OS types ... */ + * + * 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. -*/ + * 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; Index: squid/ntlm_auth_modules/NTLMSSP/smbval/std-includes.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/std-includes.h,v retrieving revision 1.1.2.1.2.2 retrieving revision 1.1.2.1.2.3 diff -u -r1.1.2.1.2.2 -r1.1.2.1.2.3 --- squid/ntlm_auth_modules/NTLMSSP/smbval/std-includes.h 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.2 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/std-includes.h 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.3 @@ -1,27 +1,27 @@ /* RFCNB Standard includes ... */ /* - - RFCNB Standard Includes - - Copyright (C) 1996, Richard Sharpe - - One day we will conditionalize these on OS types ... */ + * + * 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. -*/ + * 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; Index: squid/ntlm_auth_modules/NTLMSSP/smbval/valid.c =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/valid.c,v retrieving revision 1.1.2.1.2.3 retrieving revision 1.1.2.1.2.4 diff -u -r1.1.2.1.2.3 -r1.1.2.1.2.4 --- squid/ntlm_auth_modules/NTLMSSP/smbval/valid.c 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.3 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/valid.c 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.4 @@ -6,99 +6,100 @@ SMB_Handle_Type SMB_Connect_Server(void *, char *, char *); -int Valid_User(char *USERNAME,char *PASSWORD,char *SERVER,char *BACKUP, char *DOMAIN) +int +Valid_User(char *USERNAME, char *PASSWORD, char *SERVER, char *BACKUP, char *DOMAIN) { - int pass_is_precrypted_p=0; - 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}; - SMB_Handle_Type 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); - } - /* Test for a server in share level mode do not authenticate against it */ - if (con -> Security == 0) + int pass_is_precrypted_p = 0; + char *SMB_Prots[] = { - SMB_Discon(con,0); - return(NTV_PROTOCOL_ERROR); +/* "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}; + SMB_Handle_Type 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_Logon_Server(con, USERNAME, PASSWORD, DOMAIN, pass_is_precrypted_p) < 0) { - SMB_Discon(con,0); - return(NTV_LOGON_ERROR); - } - - SMB_Discon(con,0); - return(NTV_NO_ERROR); + if (SMB_Negotiate(con, SMB_Prots) < 0) { /* An error */ + SMB_Discon(con, 0); + return (NTV_PROTOCOL_ERROR); + } + /* Test for a server in share level mode do not authenticate against it */ + if (con->Security == 0) { + SMB_Discon(con, 0); + return (NTV_PROTOCOL_ERROR); + } + if (SMB_Logon_Server(con, USERNAME, PASSWORD, DOMAIN, pass_is_precrypted_p) < 0) { + SMB_Discon(con, 0); + return (NTV_LOGON_ERROR); + } + SMB_Discon(con, 0); + return (NTV_NO_ERROR); } -void *NTLM_Connect(char *SERVER,char *BACKUP, char *DOMAIN, char *nonce) +void * +NTLM_Connect(char *SERVER, char *BACKUP, char *DOMAIN, char *nonce) { - 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}; - SMB_Handle_Type 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(NULL); - } - } - if (SMB_Negotiate(con, SMB_Prots) < 0) { /* An error */ - SMB_Discon(con,0); - return(NULL); - } - /* Test for a server in share level mode do not authenticate against it */ - if (con -> Security == 0) + char *SMB_Prots[] = { - SMB_Discon(con,0); - return(NULL); +/* "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}; + SMB_Handle_Type 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 (NULL); + } } + if (SMB_Negotiate(con, SMB_Prots) < 0) { /* An error */ + SMB_Discon(con, 0); + return (NULL); + } + /* Test for a server in share level mode do not authenticate against it */ + if (con->Security == 0) { + SMB_Discon(con, 0); + return (NULL); + } + memcpy(nonce, con->Encrypt_Key, 8); - memcpy(nonce, con -> Encrypt_Key, 8); - - return (con); + return (con); } -int NTLM_Auth(void *handle, char *USERNAME,char *PASSWORD,int flag) +int +NTLM_Auth(void *handle, char *USERNAME, char *PASSWORD, int flag) { - SMB_Handle_Type con = handle; + SMB_Handle_Type con = handle; - if (SMB_Logon_Server(con, USERNAME, PASSWORD, NULL, flag) < 0) { - return(NTV_LOGON_ERROR); - } - return(NTV_NO_ERROR); + if (SMB_Logon_Server(con, USERNAME, PASSWORD, NULL, flag) < 0) { + return (NTV_LOGON_ERROR); + } + return (NTV_NO_ERROR); } -void NTLM_Disconnect(void *handle) +void +NTLM_Disconnect(void *handle) { - SMB_Handle_Type con = handle; - SMB_Discon(con,0); + SMB_Handle_Type con = handle; + SMB_Discon(con, 0); } Index: squid/ntlm_auth_modules/NTLMSSP/smbval/valid.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/NTLMSSP/smbval/Attic/valid.h,v retrieving revision 1.1.2.1.2.2 retrieving revision 1.1.2.1.2.3 diff -u -r1.1.2.1.2.2 -r1.1.2.1.2.3 --- squid/ntlm_auth_modules/NTLMSSP/smbval/valid.h 7 Jan 2001 02:49:32 -0000 1.1.2.1.2.2 +++ squid/ntlm_auth_modules/NTLMSSP/smbval/valid.h 7 Jan 2001 09:48:29 -0000 1.1.2.1.2.3 @@ -7,9 +7,9 @@ #define NTV_PROTOCOL_ERROR 2 #define NTV_LOGON_ERROR 3 -int Valid_User(char *USERNAME,char *PASSWORD,char *SERVER, char *BACKUP, char *DOMAIN); +int Valid_User(char *USERNAME, char *PASSWORD, char *SERVER, char *BACKUP, char *DOMAIN); void *NTLM_Connect(char *SERVER, char *BACKUP, char *DOMAIN, char *nonce); -int NTLM_Auth(void *handle, char *USERNAME,char *PASSWORD, int flag); +int NTLM_Auth(void *handle, char *USERNAME, char *PASSWORD, int flag); void NTLM_Disconnect(void *handle); #endif Index: squid/ntlm_auth_modules/fakeauth/fakeauth_auth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/fakeauth/Attic/fakeauth_auth.c,v retrieving revision 1.1.2.6.2.7 retrieving revision 1.1.2.6.2.8 diff -u -r1.1.2.6.2.7 -r1.1.2.6.2.8 --- squid/ntlm_auth_modules/fakeauth/fakeauth_auth.c 7 Jan 2001 02:49:32 -0000 1.1.2.6.2.7 +++ squid/ntlm_auth_modules/fakeauth/fakeauth_auth.c 7 Jan 2001 09:48:29 -0000 1.1.2.6.2.8 @@ -51,13 +51,12 @@ /* makes a null-terminated string lower-case. Changes CONTENTS! */ static void -lc (char *string) +lc(char *string) { - char *p = string, c; - while ((c = *p)) - { - *p = tolower (c); - p++; + char *p = string, c; + while ((c = *p)) { + *p = tolower(c); + p++; } } @@ -67,45 +66,44 @@ * challenge strings can be guarenteed to be poor at best. */ void -ntlmMakeChallenge (struct ntlm_challenge *chal) +ntlmMakeChallenge(struct ntlm_challenge *chal) { #ifndef NTLM_STATIC_CHALLENGE - static unsigned hash; - int r; + static unsigned hash; + int r; #endif - char *d; - int i; + char *d; + int i; - memset (chal, 0, sizeof (*chal)); - memcpy (chal->hdr.signature, "NTLMSSP", 8); - chal->flags = WSWAP (0x00018206); - chal->hdr.type = WSWAP (NTLM_CHALLENGE); - chal->unknown[6] = SSWAP (0x003a); + memset(chal, 0, sizeof(*chal)); + memcpy(chal->hdr.signature, "NTLMSSP", 8); + chal->flags = WSWAP(0x00018206); + chal->hdr.type = WSWAP(NTLM_CHALLENGE); + chal->unknown[6] = SSWAP(0x003a); - d = (char *) chal + 48; - i = 0; + d = (char *) chal + 48; + i = 0; - if (authenticate_ntlm_domain != NULL) - while (authenticate_ntlm_domain[i++]); + if (authenticate_ntlm_domain != NULL) + while (authenticate_ntlm_domain[i++]); - chal->target.offset = WSWAP (48); - chal->target.maxlen = SSWAP (i); - chal->target.len = chal->target.maxlen; + chal->target.offset = WSWAP(48); + chal->target.maxlen = SSWAP(i); + chal->target.len = chal->target.maxlen; #ifdef NTLM_STATIC_CHALLENGE - memcpy (chal->challenge, NTLM_STATIC_CHALLENGE, 8); + memcpy(chal->challenge, NTLM_STATIC_CHALLENGE, 8); #else - r = (int) rand (); - r = (hash ^ r) + r; + r = (int) rand(); + r = (hash ^ r) + r; - for (i = 0; i < 8; i++) - { - chal->challenge[i] = r; - r = (r >> 2) ^ r; + for (i = 0; i < 8; i++) { + chal->challenge[i] = r; + r = (r >> 2) ^ r; } - hash = r; + hash = r; #endif } @@ -113,230 +111,200 @@ * Check the vailidity of a request header. Return -1 on error. */ int -ntlmCheckHeader (struct ntlmhdr *hdr, int type) +ntlmCheckHeader(struct ntlmhdr *hdr, int type) { - /* - * Must be the correct security package and request type. The - * 8 bytes compared includes the ASCII 'NUL'. - */ - if (memcmp (hdr->signature, "NTLMSSP", 8) != 0) - { - fprintf (stderr, "ntlmCheckHeader: bad header signature\n"); - return (-1); + /* + * Must be the correct security package and request type. The + * 8 bytes compared includes the ASCII 'NUL'. + */ + if (memcmp(hdr->signature, "NTLMSSP", 8) != 0) { + fprintf(stderr, "ntlmCheckHeader: bad header signature\n"); + return (-1); } + if (type == NTLM_ANY) + return 0; - if (type == NTLM_ANY) - return 0; - - if (WSWAP (hdr->type) != type) - { + if (WSWAP(hdr->type) != type) { /* don't report this error - it's ok as we do a if() around this function */ // fprintf(stderr, "ntlmCheckHeader: type is %d, wanted %d\n", -// WSWAP(hdr->type), type); - return (-1); + // WSWAP(hdr->type), type); + return (-1); } - - return (0); + return (0); } /* * Extract a string from an NTLM request and return as ASCII. */ char * -ntlmGetString (ntlmhdr * hdr, strhdr * str, int flags) +ntlmGetString(ntlmhdr * hdr, strhdr * str, int flags) { - static char buf[512]; - u_short *s, c; - char *d, *sc; - int l, o; - - l = SSWAP (str->len); - o = WSWAP (str->offset); - - /* Sanity checks. XXX values arbitrarialy chosen */ - if (l <= 0 || l >= 32 || o >= 256) - { - fprintf (stderr, "ntlmGetString: insane: l:%d o:%d\n", l, o); - return (NULL); + static char buf[512]; + u_short *s, c; + char *d, *sc; + int l, o; + + l = SSWAP(str->len); + o = WSWAP(str->offset); + + /* Sanity checks. XXX values arbitrarialy chosen */ + if (l <= 0 || l >= 32 || o >= 256) { + fprintf(stderr, "ntlmGetString: insane: l:%d o:%d\n", l, o); + return (NULL); } - - if ((flags & 2) == 0) - { - /* UNICODE string */ - s = (u_short *) ((char *) hdr + o); - d = buf; - - for (l >>= 1; l; s++, l--) - { - c = SSWAP (*s); - if (c > 254 || c == '\0' || !isprint (c)) - { - fprintf (stderr, "ntlmGetString: bad uni: %04x\n", c); - return (NULL); + if ((flags & 2) == 0) { + /* UNICODE string */ + s = (u_short *) ((char *) hdr + o); + d = buf; + + for (l >>= 1; l; s++, l--) { + c = SSWAP(*s); + if (c > 254 || c == '\0' || !isprint(c)) { + fprintf(stderr, "ntlmGetString: bad uni: %04x\n", c); + return (NULL); } - *d++ = c; - fprintf (stderr, "ntlmGetString: conv: '%c'\n", c); + *d++ = c; + fprintf(stderr, "ntlmGetString: conv: '%c'\n", c); } - *d = 0; - } - else - { - /* ASCII string */ - sc = (char *) hdr + o; - d = buf; - - for (; l; l--) - { - if (*sc == '\0' || !isprint (*sc)) - { - fprintf (stderr, "ntlmGetString: bad ascii: %04x\n", *sc); - return (NULL); + *d = 0; + } else { + /* ASCII string */ + sc = (char *) hdr + o; + d = buf; + + for (; l; l--) { + if (*sc == '\0' || !isprint(*sc)) { + fprintf(stderr, "ntlmGetString: bad ascii: %04x\n", *sc); + return (NULL); } - *d++ = *sc++; + *d++ = *sc++; } - *d = 0; + *d = 0; } - return (buf); + return (buf); } /* * Decode the strings in an NTLM authentication request */ int -ntlmDecodeAuth (struct ntlm_authenticate *auth, char *buf, size_t size) +ntlmDecodeAuth(struct ntlm_authenticate *auth, char *buf, size_t size) { - char *p, *origbuf; - int s; + char *p, *origbuf; + int s; - if (!buf) - { - return 1; + if (!buf) { + return 1; } - origbuf = buf; - if (ntlmCheckHeader (&auth->hdr, NTLM_AUTHENTICATE)) - { + origbuf = buf; + if (ntlmCheckHeader(&auth->hdr, NTLM_AUTHENTICATE)) { - fprintf (stderr, "ntlmDecodeAuth: header check fails\n"); - return -1; + fprintf(stderr, "ntlmDecodeAuth: header check fails\n"); + return -1; } /* only on when you need to debug - fprintf(stderr,"ntlmDecodeAuth: size of %d\n", size); - fprintf(stderr,"ntlmDecodeAuth: flg %08x\n", auth->flags); - fprintf(stderr,"ntlmDecodeAuth: usr o(%d) l(%d)\n", auth->user.offset, auth->user.len); -*/ - if ((p = ntlmGetString (&auth->hdr, &auth->domain, 2)) == NULL) - p = authenticate_ntlm_domain; + * fprintf(stderr,"ntlmDecodeAuth: size of %d\n", size); + * fprintf(stderr,"ntlmDecodeAuth: flg %08x\n", auth->flags); + * fprintf(stderr,"ntlmDecodeAuth: usr o(%d) l(%d)\n", auth->user.offset, auth->user.len); + */ + if ((p = ntlmGetString(&auth->hdr, &auth->domain, 2)) == NULL) + p = authenticate_ntlm_domain; // fprintf(stderr,"ntlmDecodeAuth: Domain '%s'.\n",p); - if ((s = strlen (p) + 1) >= size) - return 1; - strcpy (buf, p); + if ((s = strlen(p) + 1) >= size) + return 1; + strcpy(buf, p); // fprintf(stdout,"ntlmDecodeAuth: Domain '%s'.\n",buf); - size -= s; - buf += (s - 1); - *buf++ = '\\'; /* Using \ is more consistent with MS-proxy */ - - p = ntlmGetString (&auth->hdr, &auth->user, 2); - if ((s = strlen (p) + 1) >= size) - return 1; - while (*p) - *buf++ = (*p++); //tolower - *buf++ = '\0'; - size -= s; + size -= s; + buf += (s - 1); + *buf++ = '\\'; /* Using \ is more consistent with MS-proxy */ + + p = ntlmGetString(&auth->hdr, &auth->user, 2); + if ((s = strlen(p) + 1) >= size) + return 1; + while (*p) + *buf++ = (*p++); //tolower + + *buf++ = '\0'; + size -= s; // fprintf(stderr, "ntlmDecodeAuth: user: %s%s\n",origbuf, p); - return 0; + return 0; } int -main () +main() { - char buf[256]; - char user[256], *p, *cleartext; - struct ntlm_challenge chal; - int len; - char *data = NULL; - - setbuf (stdout, NULL); - while (fgets (buf, 256, stdin) != NULL) - { - user[0] = '\0'; /*no usercode */ + char buf[256]; + char user[256], *p, *cleartext; + struct ntlm_challenge chal; + int len; + char *data = NULL; + + setbuf(stdout, NULL); + while (fgets(buf, 256, stdin) != NULL) { + user[0] = '\0'; /*no usercode */ - if ((p = strchr (buf, '\n')) != NULL) - *p = '\0'; /* strip \n */ + if ((p = strchr(buf, '\n')) != NULL) + *p = '\0'; /* strip \n */ #if defined(NTLMHELPPROTOCOLV3) || !defined(NTLMHELPPROTOCOLV2) - if (strncasecmp (buf, "YR" ,2) == 0) - { - ntlmMakeChallenge (&chal); - len = - sizeof (chal) - sizeof (chal.pad) + - SSWAP (chal.target.maxlen); - data = (char *) base64_encode_bin ((char *) &chal, len); - printf ("TT %s\n", data); - } else if (strncasecmp (buf, "KK ",3) == 0) - { - cleartext = (char *) uudecode (buf+3); - if (!ntlmCheckHeader ((struct ntlmhdr *) cleartext, NTLM_AUTHENTICATE)) - { - if (!ntlmDecodeAuth((struct ntlm_authenticate *) cleartext, user, 256)) - { - lc (user); - printf ("AF %s\n", user); - } else { - lc (user); - printf ("NA invalid credentials%s\n", user); - } - } else { - lc (user); - printf ("BH wrong packet type!%s\n", user); - } - } + if (strncasecmp(buf, "YR", 2) == 0) { + ntlmMakeChallenge(&chal); + len = + sizeof(chal) - sizeof(chal.pad) + + SSWAP(chal.target.maxlen); + data = (char *) base64_encode_bin((char *) &chal, len); + printf("TT %s\n", data); + } else if (strncasecmp(buf, "KK ", 3) == 0) { + cleartext = (char *) uudecode(buf + 3); + if (!ntlmCheckHeader((struct ntlmhdr *) cleartext, NTLM_AUTHENTICATE)) { + if (!ntlmDecodeAuth((struct ntlm_authenticate *) cleartext, user, 256)) { + lc(user); + printf("AF %s\n", user); + } else { + lc(user); + printf("NA invalid credentials%s\n", user); + } + } else { + lc(user); + printf("BH wrong packet type!%s\n", user); + } + } #endif #ifdef NTLMHELPPROTOCOLV2 /* V2 of the protocol */ - if (strncasecmp (buf, "RESET", 5) == 0) - { - printf ("RESET OK\n"); - } - else - { - cleartext = (char *) uudecode (buf); - if (!ntlmCheckHeader ((struct ntlmhdr *) cleartext, NTLM_NEGOTIATE)) - { - ntlmMakeChallenge (&chal); - len = - sizeof (chal) - sizeof (chal.pad) + - SSWAP (chal.target.maxlen); - data = (char *) base64_encode_bin ((char *) &chal, len); - printf ("CH %s\n", data); - } - else - if (!ntlmCheckHeader - ((struct ntlmhdr *) cleartext, NTLM_AUTHENTICATE)) - { - if (!ntlmDecodeAuth - ((struct ntlm_authenticate *) cleartext, user, 256)) - { - lc (user); - printf ("OK %s\n", user); - } else - { - lc (user); - printf ("ERR %s\n", user); - } - } - else - { - lc (user); - printf ("ERR %s\n", user); + if (strncasecmp(buf, "RESET", 5) == 0) { + printf("RESET OK\n"); + } else { + cleartext = (char *) uudecode(buf); + if (!ntlmCheckHeader((struct ntlmhdr *) cleartext, NTLM_NEGOTIATE)) { + ntlmMakeChallenge(&chal); + len = + sizeof(chal) - sizeof(chal.pad) + + SSWAP(chal.target.maxlen); + data = (char *) base64_encode_bin((char *) &chal, len); + printf("CH %s\n", data); + } else if (!ntlmCheckHeader + ((struct ntlmhdr *) cleartext, NTLM_AUTHENTICATE)) { + if (!ntlmDecodeAuth + ((struct ntlm_authenticate *) cleartext, user, 256)) { + lc(user); + printf("OK %s\n", user); + } else { + lc(user); + printf("ERR %s\n", user); + } + } else { + lc(user); + printf("ERR %s\n", user); } } -#endif /*v2*/ +#endif /*v2 */ } - exit (0); + exit(0); } Index: squid/ntlm_auth_modules/fakeauth/ntlm.h =================================================================== RCS file: /cvsroot/squid-sf//squid/ntlm_auth_modules/fakeauth/Attic/ntlm.h,v retrieving revision 1.1.2.3.2.2 retrieving revision 1.1.2.3.2.3 diff -u -r1.1.2.3.2.2 -r1.1.2.3.2.3 --- squid/ntlm_auth_modules/fakeauth/ntlm.h 7 Jan 2001 02:49:32 -0000 1.1.2.3.2.2 +++ squid/ntlm_auth_modules/fakeauth/ntlm.h 7 Jan 2001 09:48:30 -0000 1.1.2.3.2.3 @@ -1,5 +1,5 @@ /* - * $Id: ntlm.h,v 1.1.2.3.2.2 2001/01/07 02:49:32 rbcollins Exp $ + * $Id: ntlm.h,v 1.1.2.3.2.3 2001/01/07 09:48:30 hno Exp $ * * AUTHOR: Andy Doran * @@ -53,53 +53,53 @@ /* Header proceeding each request */ typedef struct ntlmhdr { - char signature[8]; /* NTLMSSP */ - int32_t type; /* One of NTLM_* from above */ + char signature[8]; /* NTLMSSP */ + int32_t type; /* One of NTLM_* from above */ } ntlmhdr; /* String header. String data resides at the end of the request */ typedef struct strhdr { - int16_t len; /* Length in bytes */ - int16_t maxlen; /* Allocated space in bytes */ - int32_t offset; /* Offset from start of request */ + int16_t len; /* Length in bytes */ + int16_t maxlen; /* Allocated space in bytes */ + int32_t offset; /* Offset from start of request */ } strhdr; /* Negotiation request sent by client */ struct ntlm_negotiate { - ntlmhdr hdr; /* NTLM header */ - int32_t flags; /* Request flags */ - strhdr domain; /* Domain we wish to authenticate in */ - strhdr workstation; /* Client workstation name */ - char pad[256]; /* String data */ + ntlmhdr hdr; /* NTLM header */ + int32_t flags; /* Request flags */ + strhdr domain; /* Domain we wish to authenticate in */ + strhdr workstation; /* Client workstation name */ + char pad[256]; /* String data */ }; /* Challenge request sent by server. */ struct ntlm_challenge { - ntlmhdr hdr; /* NTLM header */ - strhdr target; /* Authentication target (domain/server ...) */ - int32_t flags; /* Request flags */ - u_char challenge[8]; /* Challenge string */ - int16_t unknown[8]; /* Some sort of context data */ - char pad[256]; /* String data */ + ntlmhdr hdr; /* NTLM header */ + strhdr target; /* Authentication target (domain/server ...) */ + int32_t flags; /* Request flags */ + u_char challenge[8]; /* Challenge string */ + int16_t unknown[8]; /* Some sort of context data */ + char pad[256]; /* String data */ }; /* Authentication request sent by client in response to challenge */ struct ntlm_authenticate { - ntlmhdr hdr; /* NTLM header */ - strhdr lmresponse; /* LANMAN challenge response */ - strhdr ntresponse; /* NT challenge response */ - strhdr domain; /* Domain to authenticate against */ - strhdr user; /* Username */ - strhdr workstation; /* Workstation name */ - strhdr sessionkey; /* Session key for server's use */ - int32_t flags; /* Request flags */ - char pad[256*6]; /* String data */ + ntlmhdr hdr; /* NTLM header */ + strhdr lmresponse; /* LANMAN challenge response */ + strhdr ntresponse; /* NT challenge response */ + strhdr domain; /* Domain to authenticate against */ + strhdr user; /* Username */ + strhdr workstation; /* Workstation name */ + strhdr sessionkey; /* Session key for server's use */ + int32_t flags; /* Request flags */ + char pad[256 * 6]; /* String data */ }; -char *ntlmGetString(ntlmhdr *hdr, strhdr *str, int flags); -void ntlmMakeChallenge(struct ntlm_challenge *chal); -int ntlmCheckHeader(struct ntlmhdr *hdr, int type); -int ntlmCheckNegotiation(struct ntlm_negotiate *neg); -int ntlmAuthenticate(struct ntlm_authenticate *neg); +char *ntlmGetString(ntlmhdr * hdr, strhdr * str, int flags); +void ntlmMakeChallenge(struct ntlm_challenge *chal); +int ntlmCheckHeader(struct ntlmhdr *hdr, int type); +int ntlmCheckNegotiation(struct ntlm_negotiate *neg); +int ntlmAuthenticate(struct ntlm_authenticate *neg); #endif /* _NTLM_H_ */ Index: squid/snmplib/coexistance.c =================================================================== RCS file: /cvsroot/squid-sf//squid/snmplib/coexistance.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.30.1 diff -u -r1.1.1.1 -r1.1.1.1.30.1 --- squid/snmplib/coexistance.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/snmplib/coexistance.c 7 Jan 2001 09:48:30 -0000 1.1.1.1.30.1 @@ -100,7 +100,7 @@ * valid V1 responses. (I think. XXXXX) * */ -int +int snmp_coexist_V2toV1(struct snmp_pdu *PDU) { /* Per 3.1.1: Index: squid/snmplib/mib.c =================================================================== RCS file: /cvsroot/squid-sf//squid/snmplib/mib.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.30.1 diff -u -r1.1.1.1 -r1.1.1.1.30.1 --- squid/snmplib/mib.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/snmplib/mib.c 7 Jan 2001 09:48:30 -0000 1.1.1.1.30.1 @@ -114,7 +114,7 @@ return buf; } -static void +static void sprint_hexstring(buf, cp, len) char *buf; u_char *cp; @@ -136,7 +136,7 @@ *buf = '\0'; } -static void +static void sprint_asciistring(buf, cp, len) char *buf; u_char *cp; @@ -531,7 +531,7 @@ } #endif -void +void init_mib(char *file) { if (Mib != NULL) @@ -674,7 +674,7 @@ return (++*out_len); } -int +int read_objid(input, output, out_len) char *input; oid *output; @@ -709,7 +709,7 @@ return (1); } -void +void print_objid(objid, objidlen) oid *objid; int objidlen; /* number of subidentifiers */ @@ -723,7 +723,7 @@ } -void +void sprint_objid(buf, objid, objidlen) char *buf; oid *objid; @@ -736,7 +736,7 @@ } #if 0 -void +void print_variable(objid, objidlen, pvariable) oid *objid; int objidlen; @@ -763,7 +763,7 @@ } -void +void sprint_variable(buf, objid, objidlen, pvariable) char *buf; oid *objid; @@ -790,7 +790,7 @@ strcat(buf, "\n"); } -void +void sprint_value(buf, objid, objidlen, pvariable) char *buf; oid *objid; @@ -808,7 +808,7 @@ } } -void +void print_value(objid, objidlen, pvariable) oid *objid; int objidlen; @@ -870,13 +870,13 @@ #if 0 -void +void print_variable_list(variable_list * V) { print_variable(V->name, V->name_length, V); } -void +void print_variable_list_value(variable_list * pvariable) { char buf[512]; @@ -895,7 +895,7 @@ } #endif -void +void print_type(variable_list * var) { switch (var->type) { @@ -932,7 +932,7 @@ } } -void +void print_oid_nums(oid * O, int len) { int x; Index: squid/snmplib/snmp_api.c =================================================================== RCS file: /cvsroot/squid-sf//squid/snmplib/snmp_api.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.30.1 diff -u -r1.1.1.1 -r1.1.1.1.30.1 --- squid/snmplib/snmp_api.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/snmplib/snmp_api.c 7 Jan 2001 09:48:30 -0000 1.1.1.1.30.1 @@ -128,7 +128,7 @@ */ static int Reqid = 0; -static void +static void init_snmp(void) { struct timeval tv; @@ -142,7 +142,7 @@ /* * Free each element in the input request list. */ -static void +static void free_request_list(rp) struct request_list *rp; { @@ -344,7 +344,7 @@ * dequeues any pending requests, and closes any sockets allocated for * the session. Returns 0 on error, 1 otherwise. */ -int +int snmp_close(struct snmp_session *session) { struct session_list *slp = NULL, *oslp = NULL; @@ -451,7 +451,7 @@ * The pdu is freed by snmp_send() unless a failure occured. */ #if 0 -int +int snmp_send(struct snmp_session *session, struct snmp_pdu *pdu) { struct session_list *slp; @@ -763,7 +763,7 @@ * from the pdu and is resent. If there are no more retries available, the * callback for the session is used to alert the user of the timeout. */ -void +void snmp_timeout(void) { struct session_list *slp; @@ -846,7 +846,7 @@ /* Print some API stats */ -void +void snmp_api_stats(void *outP) { struct session_list *slp; Index: squid/snmplib/snmp_api_error.c =================================================================== RCS file: /cvsroot/squid-sf//squid/snmplib/snmp_api_error.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.30.1 diff -u -r1.1.1.1 -r1.1.1.1.30.1 --- squid/snmplib/snmp_api_error.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/snmplib/snmp_api_error.c 7 Jan 2001 09:48:30 -0000 1.1.1.1.30.1 @@ -69,7 +69,7 @@ "Unknown Error" }; -void +void snmp_set_api_error(int x) { snmp_errno = x; @@ -86,7 +86,7 @@ return (api_errors[foo]); } -int +int snmp_api_errno(void) { return (snmp_errno); Index: squid/snmplib/snmp_msg.c =================================================================== RCS file: /cvsroot/squid-sf//squid/snmplib/snmp_msg.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.30.1 diff -u -r1.1.1.1 -r1.1.1.1.30.1 --- squid/snmplib/snmp_msg.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/snmplib/snmp_msg.c 7 Jan 2001 09:48:30 -0000 1.1.1.1.30.1 @@ -128,7 +128,7 @@ snmp_msg_Encode(u_char * Buffer, int *BufLenP, u_char * Community, int CommLen, int Version, - struct snmp_pdu * PDU) + struct snmp_pdu *PDU) { u_char *bufp, *tmp; u_char *PDUHeaderPtr, *VARHeaderPtr; Index: squid/snmplib/snmp_pdu.c =================================================================== RCS file: /cvsroot/squid-sf//squid/snmplib/snmp_pdu.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.30.1 diff -u -r1.1.1.1 -r1.1.1.1.30.1 --- squid/snmplib/snmp_pdu.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/snmplib/snmp_pdu.c 7 Jan 2001 09:48:30 -0000 1.1.1.1.30.1 @@ -270,7 +270,7 @@ /**********************************************************************/ -void +void snmp_pdu_free(struct snmp_pdu *pdu) { snmp_free_pdu(pdu); @@ -279,7 +279,7 @@ /* * Frees the pdu and any xmalloc'd data associated with it. */ -void +void snmp_free_pdu(struct snmp_pdu *pdu) { struct variable_list *vp, *ovp; @@ -670,7 +670,7 @@ * Add a null variable with the requested name to the end of the list of * variables for this pdu. */ -void +void snmp_add_null_var(struct snmp_pdu *pdu, oid * name, int name_length) { struct variable_list *vars; Index: squid/src/HttpRequest.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpRequest.c,v retrieving revision 1.1.1.3.10.2.2.3 retrieving revision 1.1.1.3.10.2.2.4 diff -u -r1.1.1.3.10.2.2.3 -r1.1.1.3.10.2.2.4 --- squid/src/HttpRequest.c 5 Jan 2001 05:36:01 -0000 1.1.1.3.10.2.2.3 +++ squid/src/HttpRequest.c 7 Jan 2001 09:48:30 -0000 1.1.1.3.10.2.2.4 @@ -1,6 +1,6 @@ /* - * $Id: HttpRequest.c,v 1.1.1.3.10.2.2.3 2001/01/05 05:36:01 rbcollins Exp $ + * $Id: HttpRequest.c,v 1.1.1.3.10.2.2.4 2001/01/07 09:48:30 hno Exp $ * * DEBUG: section 73 HTTP Request * AUTHOR: Duane Wessels @@ -58,7 +58,7 @@ if (req->body_connection) clientAbortBody(req); if (req->auth_user_request) - authenticateAuthUserRequestUnlock(req->auth_user_request); + authenticateAuthUserRequestUnlock(req->auth_user_request); safe_free(req->canonical); stringClean(&req->urlpath); httpHeaderClean(&req->header); Index: squid/src/access_log.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/access_log.c,v retrieving revision 1.1.1.3.12.7.2.4 retrieving revision 1.1.1.3.12.7.2.5 diff -u -r1.1.1.3.12.7.2.4 -r1.1.1.3.12.7.2.5 --- squid/src/access_log.c 6 Jan 2001 22:51:16 -0000 1.1.1.3.12.7.2.4 +++ squid/src/access_log.c 7 Jan 2001 09:48:30 -0000 1.1.1.3.12.7.2.5 @@ -1,6 +1,6 @@ /* - * $Id: access_log.c,v 1.1.1.3.12.7.2.4 2001/01/06 22:51:16 rbcollins Exp $ + * $Id: access_log.c,v 1.1.1.3.12.7.2.5 2001/01/07 09:48:30 hno Exp $ * * DEBUG: section 46 Access Log * AUTHOR: Duane Wessels @@ -191,9 +191,9 @@ char *buf; char *buf_cursor; if (header == NULL) { - buf = xcalloc(1, 1); - *buf = '\0'; - return buf; + buf = xcalloc(1, 1); + *buf = '\0'; + return buf; } buf = xcalloc((strlen(header) * 3) + 1, 1); buf_cursor = buf; @@ -202,23 +202,22 @@ * to prevent garbage in the logs. CR and LF are also there just in case. */ while ((c = *(const unsigned char *) header++) != '\0') { - if (c == '\r') { - *buf_cursor++ = '\\'; - *buf_cursor++ = 'r'; - } else if (c == '\n') { - *buf_cursor++ = '\\'; - *buf_cursor++ = 'n'; - } else - if (c <= 0x1F - || c >= 0x7F - || c == ' ') { - *buf_cursor++ = '%'; - i = c * 2; - *buf_cursor++ = c2x[i]; - *buf_cursor++ = c2x[i + 1]; - } else { - *buf_cursor++ = (char) c; - } + if (c == '\r') { + *buf_cursor++ = '\\'; + *buf_cursor++ = 'r'; + } else if (c == '\n') { + *buf_cursor++ = '\\'; + *buf_cursor++ = 'n'; + } else if (c <= 0x1F + || c >= 0x7F + || c == ' ') { + *buf_cursor++ = '%'; + i = c * 2; + *buf_cursor++ = c2x[i]; + *buf_cursor++ = c2x[i + 1]; + } else { + *buf_cursor++ = (char) c; + } } *buf_cursor = '\0'; return buf; @@ -228,7 +227,7 @@ accessLogFormatName(const char *name) { if (NULL == name) - return xcalloc(strlen(dash_str)+1,1); + return xcalloc(strlen(dash_str) + 1, 1); return username_quote(name); } @@ -236,7 +235,7 @@ accessLogSquid(AccessLogEntry * al) { const char *client = NULL; - char * user =NULL; + char *user = NULL; if (Config.onoff.log_fqdn) client = fqdncache_gethostbyaddr(al->cache.caddr, FQDN_LOOKUP_IF_MISS); if (client == NULL) @@ -251,8 +250,8 @@ al->cache.size, al->private.method_str, al->url, - (user=accessLogFormatName(al->cache.authuser ? - al->cache.authuser : al->cache.rfc931)), + (user = accessLogFormatName(al->cache.authuser ? + al->cache.authuser : al->cache.rfc931)), al->hier.ping.timedout ? "TIMEOUT_" : "", hier_strings[al->hier.code], al->hier.host, @@ -264,7 +263,7 @@ accessLogCommon(AccessLogEntry * al) { const char *client = NULL; - char * user =NULL; + char *user = NULL; if (Config.onoff.log_fqdn) client = fqdncache_gethostbyaddr(al->cache.caddr, 0); if (client == NULL) @@ -272,7 +271,7 @@ logfilePrintf(logfile, "%s %s %s [%s] \"%s %s HTTP/%d.%d\" %d %d %s:%s", client, accessLogFormatName(al->cache.rfc931), - (user=accessLogFormatName(al->cache.authuser)), + (user = accessLogFormatName(al->cache.authuser)), mkhttpdlogtime(&squid_curtime), al->private.method_str, al->url, Index: squid/src/acl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/acl.c,v retrieving revision 1.1.1.3.12.26.2.22 retrieving revision 1.1.1.3.12.26.2.23 diff -u -r1.1.1.3.12.26.2.22 -r1.1.1.3.12.26.2.23 --- squid/src/acl.c 7 Jan 2001 00:37:02 -0000 1.1.1.3.12.26.2.22 +++ squid/src/acl.c 7 Jan 2001 09:48:30 -0000 1.1.1.3.12.26.2.23 @@ -1,6 +1,6 @@ /* - * $Id: acl.c,v 1.1.1.3.12.26.2.22 2001/01/07 00:37:02 hno Exp $ + * $Id: acl.c,v 1.1.1.3.12.26.2.23 2001/01/07 09:48:30 hno Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -649,28 +649,29 @@ { /* This code currently non-functional */ /* - acl_proxy_auth_data *pad; - char *t = NULL; - - pad = memAllocate(MEM_ACL_PROXY_AUTH_DATA); - pad->names = NULL; - *(acl_proxy_auth_data **)curlist = pad; - t = strtokFile(); - - if (!strcmp(t, "basic")) - pad->type = AUTH_BASIC; - else if (!strcmp(t, "ntlm")) - pad->type = AUTH_NTLM; - else { - debug(28, 0) ("%s line %d: %s\n", - cfg_filename, config_lineno, config_input_line); - debug(28, 0) ("aclParseProxyAuthList: Invalid auth type '%s'\n", t); - return; - } - while ((t = strtokFile())) - wordlistAdd(&pad->names, t); -*/ + * acl_proxy_auth_data *pad; + * char *t = NULL; + * + * pad = memAllocate(MEM_ACL_PROXY_AUTH_DATA); + * pad->names = NULL; + * *(acl_proxy_auth_data **)curlist = pad; + * t = strtokFile(); + * + * if (!strcmp(t, "basic")) + * pad->type = AUTH_BASIC; + * else if (!strcmp(t, "ntlm")) + * pad->type = AUTH_NTLM; + * else { + * debug(28, 0) ("%s line %d: %s\n", + * cfg_filename, config_lineno, config_input_line); + * debug(28, 0) ("aclParseProxyAuthList: Invalid auth type '%s'\n", t); + * return; + * } + * while ((t = strtokFile())) + * wordlistAdd(&pad->names, t); + */ } + #endif /**********************/ @@ -784,30 +785,30 @@ aclParseMethodList(&A->data); break; case ACL_PROXY_AUTH: - if (authenticateSchemeCount()==0) { - debug(28,0) ("aclParseAclLine: IGNORING: Proxy Auth ACL '%s' \ -because no authentication schemes were compiled.\n",A->cfgline); - } else if (authenticateActiveSchemeCount()==0) { - debug(28,0) ("aclParseAclLine: IGNORING: Proxy Auth ACL '%s' \ -because no authentication schemes are fully configured.\n",A->cfgline); - } else { + if (authenticateSchemeCount() == 0) { + debug(28, 0) ("aclParseAclLine: IGNORING: Proxy Auth ACL '%s' \ +because no authentication schemes were compiled.\n", A->cfgline); + } else if (authenticateActiveSchemeCount() == 0) { + debug(28, 0) ("aclParseAclLine: IGNORING: Proxy Auth ACL '%s' \ +because no authentication schemes are fully configured.\n", A->cfgline); + } else { #if 0 - aclParseProxyAuthList(&A->data); + aclParseProxyAuthList(&A->data); #else - aclParseWordList(&A->data); + aclParseWordList(&A->data); #endif - } + } break; case ACL_PROXY_AUTH_REGEX: - if (authenticateSchemeCount()==0) { - debug(28,0) ("aclParseAclLine: IGNORING: Proxy Auth ACL '%s' \ -because no authentication schemes were compiled.\n",A->cfgline); - } else if (authenticateActiveSchemeCount()==0) { - debug(28,0) ("aclParseAclLine: IGNORING: Proxy Auth ACL '%s' \ -because no authentication schemes are fully configured.\n",A->cfgline); - } else { + if (authenticateSchemeCount() == 0) { + debug(28, 0) ("aclParseAclLine: IGNORING: Proxy Auth ACL '%s' \ +because no authentication schemes were compiled.\n", A->cfgline); + } else if (authenticateActiveSchemeCount() == 0) { + debug(28, 0) ("aclParseAclLine: IGNORING: Proxy Auth ACL '%s' \ +because no authentication schemes are fully configured.\n", A->cfgline); + } else { aclParseRegexList(&A->data); - } + } break; #if SQUID_SNMP case ACL_SNMP_COMMUNITY: @@ -1066,7 +1067,7 @@ while (data) { debug(28, 3) ("aclMatchUser: looking for '%s'\n", data->key); if (strcmp(data->key, "REQUIRED") == 0 && *user != '\0' - && strcmp(user, dash_str) != 0) + && strcmp(user, dash_str) != 0) return 1; if (strcmp(data->key, user) == 0) return 1; @@ -1117,8 +1118,8 @@ case ACL_PROXY_AUTH_REGEX: matchrv = aclMatchRegex(data, MatchParam); default: - /* This is a fatal to ensure that aclCacheMatchAcl calls are _only_ - * made for supported acl types */ + /* This is a fatal to ensure that aclCacheMatchAcl calls are _only_ + * made for supported acl types */ fatal("aclCacheMatchAcl: unknown or unexpected ACL type"); return 0; /* NOTREACHED */ } @@ -1130,16 +1131,17 @@ } void -aclCacheMatchFlush(dlink_list * cache) { +aclCacheMatchFlush(dlink_list * cache) +{ acl_proxy_auth_match_cache *auth_match; dlink_node *link, *tmplink; - link=cache->head; + link = cache->head; while (link) { - auth_match = link->data; - tmplink=link; - link=link->next; - dlinkDelete(tmplink, cache); - memFree(auth_match, MEM_ACL_PROXY_AUTH_MATCH); + auth_match = link->data; + tmplink = link; + link = link->next; + dlinkDelete(tmplink, cache); + memFree(auth_match, MEM_ACL_PROXY_AUTH_MATCH); } } @@ -1154,7 +1156,7 @@ auth_user_request_t * auth_user_request, aclCheck_t * checklist, squid_acl acltype) { /* checklist is used to register user name when identified, nothing else */ - const char * proxy_auth; + const char *proxy_auth; /* consistent parameters ? */ assert(auth_user_request == checklist->auth_user_request); @@ -1172,109 +1174,106 @@ debug(28, 1) ("aclMatchProxyAuth: no connection data, cannot process authentication\n"); /* * deny access: clientreadrequest requires conn data, and it is always - * compiled in so we should have it too. + * compiled in so we should have it too. */ return 0; } - if (((proxy_auth == NULL) && (checklist->conn->auth_type==AUTH_UNKNOWN)) || (checklist->conn->auth_type == AUTH_BROKEN)) { + if (((proxy_auth == NULL) && (checklist->conn->auth_type == AUTH_UNKNOWN)) || (checklist->conn->auth_type == AUTH_BROKEN)) { /* no header or authentication failed/got corrupted - restart */ checklist->conn->auth_type = AUTH_UNKNOWN; - debug(28,4) ("aclMatchProxyAuth: broken auth or no proxy_auth header. Requesting auth header.\n"); + debug(28, 4) ("aclMatchProxyAuth: broken auth or no proxy_auth header. Requesting auth header.\n"); /* something wrong with the AUTH credentials. Force a new attempt */ checklist->auth_user_request = NULL; - checklist->conn->auth_user_request = NULL; + checklist->conn->auth_user_request = NULL; if (auth_user_request) { - /* unlock the ACL lock */ - authenticateAuthUserRequestUnlock(auth_user_request); - } + /* unlock the ACL lock */ + authenticateAuthUserRequestUnlock(auth_user_request); + } return -2; } /* we have a proxy auth header and as far as we know this connection has * not had bungled connection oriented authentication happen on it. */ - debug(28,9) ("aclMatchProxyAuth: header %s.\n", proxy_auth); + debug(28, 9) ("aclMatchProxyAuth: header %s.\n", proxy_auth); if (auth_user_request == NULL) { - debug(28,9) ("aclMatchProxyAuth: This is a new request on FD:%d\n", checklist->conn->fd); - if ((!checklist->request->auth_user_request) && (checklist->conn->auth_type==AUTH_UNKNOWN )) { - /* beginning of a new request check */ - debug(28,4)("aclMatchProxyAuth: no connection authentication type\n"); - if (!authenticateValidateUser(auth_user_request=authenticateGetAuthUser(proxy_auth))) - { - /* the decode might have left a username for logging, or a message to - * the user */ - if (auth_user_request) - { - /* lock the user for the request structure link */ - authenticateAuthUserRequestLock(auth_user_request); - checklist->request->auth_user_request=auth_user_request; - /* unlock the ACL reference.*/ - authenticateAuthUserRequestUnlock(auth_user_request); - } - return -2; - } - /* the user_request comes prelocked for the caller to GetAuthUser (us) */ - } else if (checklist->request->auth_user_request) { - auth_user_request=checklist->request->auth_user_request; - /* lock the user request for this ACL processing */ - authenticateAuthUserRequestLock(auth_user_request); - } else { - if (checklist->conn->auth_user_request != NULL) { - auth_user_request=checklist->conn->auth_user_request; - /* lock the user request for this ACL processing */ - authenticateAuthUserRequestLock(auth_user_request); - } else { - /* failed connection based authentication */ - debug(28,4)("aclMatchProxyAuth: Aauth user request %d conn-auth user request %d conn type %d authentication failed.\n",auth_user_request, checklist->conn->auth_user_request,checklist->conn->auth_type); - return -2; - } - } + debug(28, 9) ("aclMatchProxyAuth: This is a new request on FD:%d\n", checklist->conn->fd); + if ((!checklist->request->auth_user_request) && (checklist->conn->auth_type == AUTH_UNKNOWN)) { + /* beginning of a new request check */ + debug(28, 4) ("aclMatchProxyAuth: no connection authentication type\n"); + if (!authenticateValidateUser(auth_user_request = authenticateGetAuthUser(proxy_auth))) { + /* the decode might have left a username for logging, or a message to + * the user */ + if (auth_user_request) { + /* lock the user for the request structure link */ + authenticateAuthUserRequestLock(auth_user_request); + checklist->request->auth_user_request = auth_user_request; + /* unlock the ACL reference. */ + authenticateAuthUserRequestUnlock(auth_user_request); + } + return -2; + } + /* the user_request comes prelocked for the caller to GetAuthUser (us) */ + } else if (checklist->request->auth_user_request) { + auth_user_request = checklist->request->auth_user_request; + /* lock the user request for this ACL processing */ + authenticateAuthUserRequestLock(auth_user_request); + } else { + if (checklist->conn->auth_user_request != NULL) { + auth_user_request = checklist->conn->auth_user_request; + /* lock the user request for this ACL processing */ + authenticateAuthUserRequestLock(auth_user_request); + } else { + /* failed connection based authentication */ + debug(28, 4) ("aclMatchProxyAuth: Aauth user request %d conn-auth user request %d conn type %d authentication failed.\n", auth_user_request, checklist->conn->auth_user_request, checklist->conn->auth_type); + return -2; + } + } } - /* Clear the reference in the checklist */ checklist->auth_user_request = NULL; - if (!authenticateUserAuthenticated(auth_user_request)){ - /* User not logged in. Log them in */ + if (!authenticateUserAuthenticated(auth_user_request)) { + /* User not logged in. Log them in */ #if 0 - /* if they have not got an IP already give them one */ - if (!auth_user->ipaddr.s_addr) - auth_user->ipaddr = checklist->src_addr; -#endif - authenticateAuthUserRequestSetIp(auth_user_request, checklist->src_addr); - authenticateAuthenticateUser(auth_user_request, checklist->request, checklist->conn,headertype); - switch (authenticateDirection(auth_user_request)) { - case 1: - /* this ACL check is finished. Unlock. */ - authenticateAuthUserRequestUnlock(auth_user_request); - return -2; - case -1: - /* we are partway through authentication within squid - * store the auth_user for the callback to here */ - checklist->auth_user_request=auth_user_request; - /* we will be called back here. Do not Unlock */ - return -1; - case -2: - /* this ACL check is finished. Unlock. */ - authenticateAuthUserRequestUnlock(auth_user_request); - return -2; - } /* on 0 the authentication is finished - fallthrough */ - /* See of user authentication failed for some reason */ - if (!authenticateUserAuthenticated(auth_user_request)) { - if ((!checklist->rfc931[0]) && - (authenticateUserRequestUsername(auth_user_request))) { - if (!checklist->request->auth_user_request) { - /* lock the user for the request structure link */ - authenticateAuthUserRequestLock(auth_user_request); - checklist->request->auth_user_request=auth_user_request; - } - } - /* this ACL check is finished. Unlock. */ - authenticateAuthUserRequestUnlock(auth_user_request); + /* if they have not got an IP already give them one */ + if (!auth_user->ipaddr.s_addr) + auth_user->ipaddr = checklist->src_addr; +#endif + authenticateAuthUserRequestSetIp(auth_user_request, checklist->src_addr); + authenticateAuthenticateUser(auth_user_request, checklist->request, checklist->conn, headertype); + switch (authenticateDirection(auth_user_request)) { + case 1: + /* this ACL check is finished. Unlock. */ + authenticateAuthUserRequestUnlock(auth_user_request); + return -2; + case -1: + /* we are partway through authentication within squid + * store the auth_user for the callback to here */ + checklist->auth_user_request = auth_user_request; + /* we will be called back here. Do not Unlock */ + return -1; + case -2: + /* this ACL check is finished. Unlock. */ + authenticateAuthUserRequestUnlock(auth_user_request); + return -2; + } /* on 0 the authentication is finished - fallthrough */ + /* See of user authentication failed for some reason */ + if (!authenticateUserAuthenticated(auth_user_request)) { + if ((!checklist->rfc931[0]) && + (authenticateUserRequestUsername(auth_user_request))) { + if (!checklist->request->auth_user_request) { + /* lock the user for the request structure link */ + authenticateAuthUserRequestLock(auth_user_request); + checklist->request->auth_user_request = auth_user_request; + } + } + /* this ACL check is finished. Unlock. */ + authenticateAuthUserRequestUnlock(auth_user_request); #if 0 - authenticateFreeProxyAuthUser(auth_user_request); + authenticateFreeProxyAuthUser(auth_user_request); #endif - return -2; - - } - } + return -2; + + } + } /* User authenticated ok */ assert(authenticateUserAuthenticated(auth_user_request)); #if 0 @@ -1283,59 +1282,58 @@ /* timeout checking on time_since_last_request is done by the auth framework * by not reusing the existing user during decode iff the interval is too long */ /* conn based auth can't time out during a connection */ - if ((checklist->conn->auth_user_request) || (auth_user_request->auth_user->expiretime + Config.authenticateTTL > current_time.tv_sec)) - { - auth_user_request->auth_user->expiretime = current_time.tv_sec; -#endif - - /* copy username to request for logging on client-side */ - /* the credentials are correct at this point */ - if (!checklist->request->auth_user_request) { - /* lock the user for the request structure link */ - authenticateAuthUserRequestLock(auth_user_request); - checklist->request->auth_user_request=auth_user_request; - } - if (authenticateCheckAuthUserIP(checklist->src_addr, auth_user_request)) { - /* Once the match is completed we have finished with the - * auth_user structure */ - /* this ACL check completed */ - authenticateAuthUserRequestUnlock(auth_user_request); - /* check to see if we have matched the user-acl before */ - return - aclCacheMatchAcl(&auth_user_request->auth_user->proxy_match_cache, - acltype, data, authenticateUserRequestUsername(auth_user_request)); - } - /* this acl check completed */ - authenticateAuthUserRequestUnlock(auth_user_request); - return 0; -#if 0 + if ((checklist->conn->auth_user_request) || (auth_user_request->auth_user->expiretime + Config.authenticateTTL > current_time.tv_sec)) { + auth_user_request->auth_user->expiretime = current_time.tv_sec; +#endif + + /* copy username to request for logging on client-side */ + /* the credentials are correct at this point */ + if (!checklist->request->auth_user_request) { + /* lock the user for the request structure link */ + authenticateAuthUserRequestLock(auth_user_request); + checklist->request->auth_user_request = auth_user_request; + } + if (authenticateCheckAuthUserIP(checklist->src_addr, auth_user_request)) { + /* Once the match is completed we have finished with the + * auth_user structure */ + /* this ACL check completed */ + authenticateAuthUserRequestUnlock(auth_user_request); + /* check to see if we have matched the user-acl before */ + return + aclCacheMatchAcl(&auth_user_request->auth_user->proxy_match_cache, + acltype, data, authenticateUserRequestUsername(auth_user_request)); + } + /* this acl check completed */ + authenticateAuthUserRequestUnlock(auth_user_request); + return 0; +#if 0 } else { - /* timeout */ - fatalf("user credentials not used for too long in acl.c - currently broken\n" - "the timeout values: expire:%d TTL %d expire+TTL %d now %d\n", - auth_user_request->auth_user->expiretime,Config.authenticateTTL, - auth_user_request->auth_user->expiretime+ Config.authenticateTTL, - current_time.tv_sec); - /* this is broken because it assumes we can retry authentication - for - digest/NTLM/kerberos we may not be able to. the Decode process should - catch timed out but not garbage collected users anyway - this code - _should_ be unreachable */ - debug(28, 4) ("aclMatchProxyAuth: user '%s' timeout\n", - authenticateUserRequestUsername(auth_user_request)); - /* reset the password check info */ - auth_user_request->auth_user->flags.credentials_ok = 0; - /* now give the checklist this auth_user_request */ - checklist->auth_user_request = auth_user_request; - /* update the TTL so we don't have an infinite loop */ - auth_user_request->auth_user->expiretime = current_time.tv_sec; - /* this ACL check completed */ - authenticateAuthUserRequestUnlock(auth_user_request); - /* and trigger the external helper in case the password is still ok */ - return -1; - } - /* unreachable code. Spit a debug info and fatal squid out of here */ -fatal("acl unreachable code!"); -return -2; + /* timeout */ + fatalf("user credentials not used for too long in acl.c - currently broken\n" + "the timeout values: expire:%d TTL %d expire+TTL %d now %d\n", + auth_user_request->auth_user->expiretime, Config.authenticateTTL, + auth_user_request->auth_user->expiretime + Config.authenticateTTL, + current_time.tv_sec); + /* this is broken because it assumes we can retry authentication - for + * digest/NTLM/kerberos we may not be able to. the Decode process should + * catch timed out but not garbage collected users anyway - this code + * _should_ be unreachable */ + debug(28, 4) ("aclMatchProxyAuth: user '%s' timeout\n", + authenticateUserRequestUsername(auth_user_request)); + /* reset the password check info */ + auth_user_request->auth_user->flags.credentials_ok = 0; + /* now give the checklist this auth_user_request */ + checklist->auth_user_request = auth_user_request; + /* update the TTL so we don't have an infinite loop */ + auth_user_request->auth_user->expiretime = current_time.tv_sec; + /* this ACL check completed */ + authenticateAuthUserRequestUnlock(auth_user_request); + /* and trigger the external helper in case the password is still ok */ + return -1; + } + /* unreachable code. Spit a debug info and fatal squid out of here */ + fatal("acl unreachable code!"); + return -2; #endif } @@ -1343,14 +1341,14 @@ aclLookupProxyAuthStart(aclCheck_t * checklist) { auth_user_request_t *auth_user_request; - assert(checklist->auth_user_request!=NULL); /* this is created for us */ + assert(checklist->auth_user_request != NULL); /* this is created for us */ auth_user_request = checklist->auth_user_request; assert(authenticateValidateUser(auth_user_request)); authenticateStart(auth_user_request, aclLookupProxyAuthDone, checklist); } - static int +static int aclMatchInteger(intlist * data, int i) { intlist *first, *prev; @@ -1609,60 +1607,40 @@ if (NULL == r) { return -1; } else if (!r->flags.accelerated) { -#if 0 /* Proxy authorization on proxy requests */ - header = - httpHeaderGetStr(&checklist->request->header, - HDR_PROXY_AUTHORIZATION);} else if (r->flags.internal) { + headertype = HDR_PROXY_AUTHORIZATION; + } else if (r->flags.internal) { /* WWW authorization on accelerated internal requests */ - header = - httpHeaderGetStr(&checklist->request->header, - HDR_AUTHORIZATION);} else { + headertype = HDR_AUTHORIZATION; + } else { #if AUTH_ON_ACCELERATION /* WWW authorization on accelerated requests */ - header = - httpHeaderGetStr(&checklist->request->header, - HDR_AUTHORIZATION); -#else - debug(28, 1) ("aclMatchAcl: proxy_auth %s not applicable on accelerated requests.\n", - ae->name); return -1; -#endif - } -#endif - /* Proxy authorization on proxy requests */ - headertype = HDR_PROXY_AUTHORIZATION; - } else if (r->flags.internal) { - /* WWW authorization on accelerated internal requests */ - headertype = HDR_AUTHORIZATION; - } else { -#if AUTH_ON_ACCELERATION - /* WWW authorization on accelerated requests */ - headertype = HDR_AUTHORIZATION; + headertype = HDR_AUTHORIZATION; #else - debug(28, 1) ("aclMatchAcl: proxy_auth %s not applicable on accelerated requests.\n", ae->name); + debug(28, 1) ("aclMatchAcl: proxy_auth %s not applicable on accelerated requests.\n", ae->name); return -1; #endif - } - /* Check the credentials */ + } + /* Check the credentials */ switch (aclMatchProxyAuth(ae->data, headertype, checklist->auth_user_request, checklist, ae->type)) { case 0: - debug(28, 4) ("aclMatchAcl: returning 0 user authenticated but not authorised.\n"); + debug(28, 4) ("aclMatchAcl: returning 0 user authenticated but not authorised.\n"); /* Authenticated but not Authorised for this ACL */ return 0; case 1: - debug(28, 4) ("aclMatchAcl: returning 1 user authenticated and authorised.\n"); + debug(28, 4) ("aclMatchAcl: returning 1 user authenticated and authorised.\n"); /* Authenticated and Authorised for this ACL */ return 1; case -2: - debug(28, 4) ("aclMatchAcl: returning 0 sending authentication challenge.\n"); + debug(28, 4) ("aclMatchAcl: returning 0 sending authentication challenge.\n"); /* Authentication credentials invalid or missing. */ - /* Or partway through NTLM handshake. A proxy_Authenticate header - * gets sent to the client. */ + /* Or partway through NTLM handshake. A proxy_Authenticate header + * gets sent to the client. */ checklist->state[ACL_PROXY_AUTH] = ACL_PROXY_AUTH_NEEDED; return 0; case -1: - debug(28, 4) ("aclMatchAcl: returning 0 sending credentials to helper.\n"); + debug(28, 4) ("aclMatchAcl: returning 0 sending credentials to helper.\n"); /* * we need to validate the password */ @@ -1793,15 +1771,13 @@ aclLookupDstFQDNDone, checklist); return; - } - else if (checklist->state[ACL_PROXY_AUTH] == ACL_LOOKUP_NEEDED) { + } else if (checklist->state[ACL_PROXY_AUTH] == ACL_LOOKUP_NEEDED) { debug(28, 3) ("aclCheck: checking password via authenticator\n"); aclLookupProxyAuthStart(checklist); checklist->state[ACL_PROXY_AUTH] = ACL_LOOKUP_PENDING; return; - } - else if (checklist->state[ACL_PROXY_AUTH] == ACL_PROXY_AUTH_NEEDED) { + } else if (checklist->state[ACL_PROXY_AUTH] == ACL_PROXY_AUTH_NEEDED) { /* Client is required to resend the request with correct authentication * credentials. (This may be part of a stateful auth protocol. * The request is denied. @@ -1941,20 +1917,19 @@ auth_user_request_t *auth_user_request; checklist->state[ACL_PROXY_AUTH] = ACL_LOOKUP_DONE; if (result != NULL) - fatal("AclLookupProxyAuthDone: Old code floating around somewhere.\nMake clean and if that doesn't work, report a bug to the squid developers.\n"); + fatal("AclLookupProxyAuthDone: Old code floating around somewhere.\nMake clean and if that doesn't work, report a bug to the squid developers.\n"); /* state info check */ assert(checklist->conn != NULL); auth_user_request = checklist->auth_user_request; - if (!authenticateValidateUser(auth_user_request)) - { - /* credentials could not be checked either way - * restart the whole process */ - checklist->conn->auth_user_request = NULL; - checklist->conn->auth_type = AUTH_BROKEN; - checklist->auth_user_request = NULL; - authenticateAuthUserRequestUnlock(auth_user_request); - aclCheck(checklist); - return; + if (!authenticateValidateUser(auth_user_request)) { + /* credentials could not be checked either way + * restart the whole process */ + checklist->conn->auth_user_request = NULL; + checklist->conn->auth_type = AUTH_BROKEN; + checklist->auth_user_request = NULL; + authenticateAuthUserRequestUnlock(auth_user_request); + aclCheck(checklist); + return; } aclCheck(checklist); } @@ -1966,11 +1941,11 @@ aclCheck_t *checklist = data; checklist->state[ACL_PROXY_AUTH] = ACL_LOOKUP_DONE; debug(28, 4) ("aclLookupProxyAuthDone: result = %s\n", - result ? result : "NULL"); + result ? result : "NULL"); if (result && (strncasecmp(result, "OK", 2) == 0)) - checklist->auth_user->flags.credentials_ok = 1; + checklist->auth_user->flags.credentials_ok = 1; else - checklist->auth_user->flags.credentials_ok = 2; + checklist->auth_user->flags.credentials_ok = 2; aclCheck(checklist); } #endif @@ -2685,7 +2660,8 @@ /* Return if match, otherwise continue to other interfaces */ if (0 == splayLastResult) { debug(28, 3) ("aclMatchArp: %s found on %s\n", - inet_ntoa(c), ifr->ifr_name); return 1; + inet_ntoa(c), ifr->ifr_name); + return 1; } /* * Should we stop looking here? Can the same IP address Index: squid/src/authenticate.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/authenticate.c,v retrieving revision 1.1.1.3.12.17.2.23 retrieving revision 1.1.1.3.12.17.2.24 diff -u -r1.1.1.3.12.17.2.23 -r1.1.1.3.12.17.2.24 --- squid/src/authenticate.c 6 Jan 2001 13:31:53 -0000 1.1.1.3.12.17.2.23 +++ squid/src/authenticate.c 7 Jan 2001 09:48:30 -0000 1.1.1.3.12.17.2.24 @@ -1,6 +1,6 @@ /* - * $Id: authenticate.c,v 1.1.1.3.12.17.2.23 2001/01/06 13:31:53 rbcollins Exp $ + * $Id: authenticate.c,v 1.1.1.3.12.17.2.24 2001/01/07 09:48:30 hno Exp $ * * DEBUG: section 29 Authenticator * AUTHOR: Duane Wessels @@ -34,15 +34,15 @@ */ /* The functions in this file handle authentication. - They DO NOT perform access control or auditing. - See acl.c for access control and client_side.c for auditing */ + * They DO NOT perform access control or auditing. + * See acl.c for access control and client_side.c for auditing */ #include "squid.h" static void -authenticateDecodeAuth(const char *proxy_auth, auth_user_request_t * auth_user_request); + authenticateDecodeAuth(const char *proxy_auth, auth_user_request_t * auth_user_request); /* * @@ -60,11 +60,10 @@ { authScheme *scheme; int i; - for (i = 0; i < Config.authConfig.n_configured; i++) - { - scheme=Config.authConfig.schemes+i; - if (strncasecmp(proxy_auth, scheme->typestr, strlen(scheme->typestr))==0) - return 1; + for (i = 0; i < Config.authConfig.n_configured; i++) { + scheme = Config.authConfig.schemes + i; + if (strncasecmp(proxy_auth, scheme->typestr, strlen(scheme->typestr)) == 0) + return 1; } return 0; } @@ -72,13 +71,11 @@ int authenticateAuthSchemeId(const char *typestr) { - int i=0; - for (i = 0; authscheme_list && authscheme_list[i].typestr; i++) - { - if (strncasecmp(typestr, authscheme_list[i].typestr, strlen(authscheme_list[i].typestr)) == 0) - { - return i; - } + int i = 0; + for (i = 0; authscheme_list && authscheme_list[i].typestr; i++) { + if (strncasecmp(typestr, authscheme_list[i].typestr, strlen(authscheme_list[i].typestr)) == 0) { + return i; + } } return -1; } @@ -88,50 +85,49 @@ { int i = 0; /* if (proxy_auth == NULL) - return 0; - */ + * return 0; + */ //checked by aclMatchProxy. assert(proxy_auth != NULL); - assert(auth_user_request != NULL); /* we need this created for us. */ + assert(auth_user_request != NULL); /* we need this created for us. */ debug(29, 9) ("authenticateDecodeAuth: header = '%s'\n", proxy_auth); - if (authenticateAuthSchemeConfigured(proxy_auth)) - { - /* we're configured to use this scheme - but is it active ? */ - if ((i=authenticateAuthSchemeId(proxy_auth))!=-1) - { - authscheme_list[i].decodeauth(auth_user_request, proxy_auth); - auth_user_request->auth_user->auth_module = i+1; - return; - } -#if 0 - for (i = 0; authscheme_list && authscheme_list[i].typestr; i++) { - if ((authscheme_list[i].Active()) &&(strncasecmp(proxy_auth, authscheme_list[i].typestr, strlen(authscheme_list[i].typestr)) == 0)) { - auth_user->auth_module = i+1; - authscheme_list[i].decodeauth(auth_user, proxy_auth); - return; - } - } + if (authenticateAuthSchemeConfigured(proxy_auth)) { + /* we're configured to use this scheme - but is it active ? */ + if ((i = authenticateAuthSchemeId(proxy_auth)) != -1) { + authscheme_list[i].decodeauth(auth_user_request, proxy_auth); + auth_user_request->auth_user->auth_module = i + 1; + return; + } +#if 0 + for (i = 0; authscheme_list && authscheme_list[i].typestr; i++) { + if ((authscheme_list[i].Active()) && (strncasecmp(proxy_auth, authscheme_list[i].typestr, strlen(authscheme_list[i].typestr)) == 0)) { + auth_user->auth_module = i + 1; + authscheme_list[i].decodeauth(auth_user, proxy_auth); + return; + } + } #endif } #if 0 auth_user_request->auth_type = AUTH_UNKNOWN; #endif debug(29, 1) - ("authenticateDecodeAuth: Unsupported or unconfigured proxy-auth scheme, '%s'\n", - proxy_auth); + ("authenticateDecodeAuth: Unsupported or unconfigured proxy-auth scheme, '%s'\n", + proxy_auth); return; } /* clear any connection related authentication details */ void -authenticateOnCloseConnection(ConnStateData *conn){ +authenticateOnCloseConnection(ConnStateData * conn) +{ auth_user_request_t *auth_user_request; assert(conn != NULL); - if (conn->auth_user_request !=NULL) { - auth_user_request = conn->auth_user_request; - if (authscheme_list[auth_user_request->auth_user->auth_module-1].oncloseconnection){ - authscheme_list[auth_user_request->auth_user->auth_module-1].oncloseconnection(conn); - } + if (conn->auth_user_request != NULL) { + auth_user_request = conn->auth_user_request; + if (authscheme_list[auth_user_request->auth_user->auth_module - 1].oncloseconnection) { + authscheme_list[auth_user_request->auth_user->auth_module - 1].oncloseconnection(conn); + } } } @@ -143,11 +139,11 @@ { assert(auth_user_request); assert(handler); - debug(29,9)("authenticateStart: auth_user_request '%d'\n", auth_user_request); - if (auth_user_request->auth_user->auth_module>0) - authscheme_list[auth_user_request->auth_user->auth_module-1].authStart(auth_user_request, handler, data); + debug(29, 9) ("authenticateStart: auth_user_request '%d'\n", auth_user_request); + if (auth_user_request->auth_user->auth_module > 0) + authscheme_list[auth_user_request->auth_user->auth_module - 1].authStart(auth_user_request, handler, data); else - handler(data,NULL); + handler(data, NULL); } /* @@ -155,31 +151,32 @@ * sensability. Broken or Unknown auth_types are not valid for use... */ -int -authenticateValidateUser(auth_user_request_t * auth_user_request) { - debug(29,9) ("authenticateValidateUser: Validating Auth_user request '%d'.\n",auth_user_request); +int +authenticateValidateUser(auth_user_request_t * auth_user_request) +{ + debug(29, 9) ("authenticateValidateUser: Validating Auth_user request '%d'.\n", auth_user_request); if (auth_user_request == NULL) { - debug(29,4) ("authenticateValidateUser: Auth_user_request was NULL!\n"); - return 0; + debug(29, 4) ("authenticateValidateUser: Auth_user_request was NULL!\n"); + return 0; } if (auth_user_request->auth_user == NULL) { - debug(29,4) ("authenticateValidateUser: No associated auth_user structure\n"); - return 0; + debug(29, 4) ("authenticateValidateUser: No associated auth_user structure\n"); + return 0; } if (auth_user_request->auth_user->auth_type == AUTH_UNKNOWN) { - debug(29,4) ("authenticateValidateUser: Auth_user '%d' uses unknown scheme.\n",auth_user_request->auth_user); - return 0; + debug(29, 4) ("authenticateValidateUser: Auth_user '%d' uses unknown scheme.\n", auth_user_request->auth_user); + return 0; } if (auth_user_request->auth_user->auth_type == AUTH_BROKEN) { - debug(29,4) ("authenticateValidateUser: Auth_user '%d' is broken for it's scheme.\n",auth_user_request->auth_user); - return 0; + debug(29, 4) ("authenticateValidateUser: Auth_user '%d' is broken for it's scheme.\n", auth_user_request->auth_user); + return 0; } /* any other sanity checks that we need in the future */ /* Thus should a module call to something like authValidate */ /* finally return ok */ - debug(29,4) ("authenticateValidateUser: Validated Auth_user request '%d'.\n",auth_user_request); + debug(29, 4) ("authenticateValidateUser: Validated Auth_user request '%d'.\n", auth_user_request); return 1; } @@ -187,12 +184,12 @@ auth_user_t * authenticateAuthUserNew(const char *scheme) { - auth_user_t* temp_auth; + auth_user_t *temp_auth; temp_auth = memAllocate(MEM_AUTH_USER_T); - assert (temp_auth != NULL); - temp_auth->auth_type=AUTH_UNKNOWN; - temp_auth->references=0; - temp_auth->auth_module=authenticateAuthSchemeId(scheme)+1; + assert(temp_auth != NULL); + temp_auth->auth_type = AUTH_UNKNOWN; + temp_auth->references = 0; + temp_auth->auth_module = authenticateAuthSchemeId(scheme) + 1; return temp_auth; } @@ -201,13 +198,13 @@ { auth_user_request_t *temp_request; if (!auth_user_request_pool) - auth_user_request_pool = memPoolCreate("Authenticate Request Data", sizeof(auth_user_request_t)); - temp_request=memPoolAlloc(auth_user_request_pool); - assert (temp_request != NULL); - temp_request->auth_user=NULL; - temp_request->message=NULL; - temp_request->scheme_data=NULL; - temp_request->references=0; + auth_user_request_pool = memPoolCreate("Authenticate Request Data", sizeof(auth_user_request_t)); + temp_request = memPoolAlloc(auth_user_request_pool); + assert(temp_request != NULL); + temp_request->auth_user = NULL; + temp_request->message = NULL; + temp_request->scheme_data = NULL; + temp_request->references = 0; return temp_request; } @@ -215,52 +212,49 @@ authenticateAuthUserRequestFree(auth_user_request_t * auth_user_request) { dlink_node *link; - debug(29,5)("authenticateAuthUserRequestFree: freeing request %d\n",auth_user_request); + debug(29, 5) ("authenticateAuthUserRequestFree: freeing request %d\n", auth_user_request); if (!auth_user_request) - return; - assert (auth_user_request->references==0); - if (auth_user_request->auth_user) - { - if (auth_user_request->scheme_data != NULL) - { - /* we MUST know the module */ - assert((auth_user_request->auth_user->auth_module>0)); - /* and the module MUST support requestFree if it has created scheme data */ - assert(authscheme_list[auth_user_request->auth_user->auth_module-1].requestFree != NULL); - authscheme_list[auth_user_request->auth_user->auth_module-1].requestFree(auth_user_request); - } - /* unlink from the auth_user struct */ - link = auth_user_request->auth_user->requests.head; - while (link && (link->data != auth_user_request)) - link=link->next; - assert (link!=NULL); - dlinkDelete(link, &auth_user_request->auth_user->requests); - dlinkNodeDelete(link); - - /* unlock the request structure's lock */ - authenticateAuthUserUnlock(auth_user_request->auth_user); - auth_user_request->auth_user= NULL; - } - else - assert (auth_user_request->scheme_data == NULL); + return; + assert(auth_user_request->references == 0); + if (auth_user_request->auth_user) { + if (auth_user_request->scheme_data != NULL) { + /* we MUST know the module */ + assert((auth_user_request->auth_user->auth_module > 0)); + /* and the module MUST support requestFree if it has created scheme data */ + assert(authscheme_list[auth_user_request->auth_user->auth_module - 1].requestFree != NULL); + authscheme_list[auth_user_request->auth_user->auth_module - 1].requestFree(auth_user_request); + } + /* unlink from the auth_user struct */ + link = auth_user_request->auth_user->requests.head; + while (link && (link->data != auth_user_request)) + link = link->next; + assert(link != NULL); + dlinkDelete(link, &auth_user_request->auth_user->requests); + dlinkNodeDelete(link); + + /* unlock the request structure's lock */ + authenticateAuthUserUnlock(auth_user_request->auth_user); + auth_user_request->auth_user = NULL; + } else + assert(auth_user_request->scheme_data == NULL); if (auth_user_request->message) - xfree(auth_user_request->message); + xfree(auth_user_request->message); } char * authenticateAuthUserRequestMessage(auth_user_request_t * auth_user_request) { if (auth_user_request) - return auth_user_request->message; + return auth_user_request->message; return NULL; } void -authenticateAuthUserRequestSetIp(auth_user_request_t *auth_user_request, struct in_addr ipaddr) +authenticateAuthUserRequestSetIp(auth_user_request_t * auth_user_request, struct in_addr ipaddr) { if (auth_user_request->auth_user) - if (!auth_user_request->auth_user->ipaddr.s_addr) - auth_user_request->auth_user->ipaddr=ipaddr; + if (!auth_user_request->auth_user->ipaddr.s_addr) + auth_user_request->auth_user->ipaddr = ipaddr; } /* Get Auth User: Return a filled out auth_user structure for the given @@ -268,7 +262,8 @@ * Unauthenticated structure. The structure is given an inital lock here. */ auth_user_request_t * -authenticateGetAuthUser(const char *proxy_auth) { +authenticateGetAuthUser(const char *proxy_auth) +{ #if 0 auth_user_hash_pointer *proxy_auth_hash = NULL; #endif @@ -278,29 +273,29 @@ authenticateDecodeAuth(proxy_auth, auth_user_request); #if 0 /* We don't look in the cache anymore because - a) only the basic scheme can benefit from that - b) digest/NTLM (and I suspect kerberos) will have unique headers each and every time - c) the benefits vs the decode time are marginal vsd the extra code overhead. */ + * a) only the basic scheme can benefit from that + * b) digest/NTLM (and I suspect kerberos) will have unique headers each and every time + * c) the benefits vs the decode time are marginal vsd the extra code overhead. */ /* see if we already know this user. Note that NTLM users will never be * found here: ntlm keys are not put in the hash table because the * negotiate phase is not unqiue. */ proxy_auth_hash = hash_lookup(proxy_auth_cache, proxy_auth); - if (!proxy_auth_hash) { /* not in the hash table */ - debug(29, 4) - ("authenticateGetAuthUser: proxy-auth cache miss. Decoding header details.\n"); + if (!proxy_auth_hash) { /* not in the hash table */ + debug(29, 4) + ("authenticateGetAuthUser: proxy-auth cache miss. Decoding header details.\n"); #if 0 - auth_user = memAllocate(MEM_AUTH_USER_T); + auth_user = memAllocate(MEM_AUTH_USER_T); #endif - auth_user_request = authenticateAuthUserRequestNew(); - authenticateDecodeAuth(proxy_auth, auth_user_request); + auth_user_request = authenticateAuthUserRequestNew(); + authenticateDecodeAuth(proxy_auth, auth_user_request); } else { - debug(29, 4) - ("authenticateGetAuthUser: proxy-auth cache hit.\n"); - /* create a new request structure */ - auth_user_request = authenticateAuthUserRequestNew(); - /* tie in the known user */ - auth_user_request->auth_user = proxy_auth_hash->auth_user; - /* decode to get request specific details */ + debug(29, 4) + ("authenticateGetAuthUser: proxy-auth cache hit.\n"); + /* create a new request structure */ + auth_user_request = authenticateAuthUserRequestNew(); + /* tie in the known user */ + auth_user_request->auth_user = proxy_auth_hash->auth_user; + /* decode to get request specific details */ } #endif return auth_user_request; @@ -310,17 +305,19 @@ * authenticateUserAuthenticated: is this auth_user structure logged in ? */ int -authenticateUserAuthenticated(auth_user_request_t *auth_user_request) { +authenticateUserAuthenticated(auth_user_request_t * auth_user_request) +{ assert(authenticateValidateUser(auth_user_request)); - if (auth_user_request->auth_user->auth_module>0) - return authscheme_list[auth_user_request->auth_user->auth_module-1].authenticated(auth_user_request); + if (auth_user_request->auth_user->auth_module > 0) + return authscheme_list[auth_user_request->auth_user->auth_module - 1].authenticated(auth_user_request); else - return 0; + return 0; #if 0 /* Scheme specific tests! naughty! - RBC */ /* if they are in the hash they must be authenticated */ - if (auth_user->usernamehash) return 1; - debug (29, 7) ("Couldn't find user in cache: assuming not logged in.\n"); + if (auth_user->usernamehash) + return 1; + debug(29, 7) ("Couldn't find user in cache: assuming not logged in.\n"); return 0; #endif } @@ -331,13 +328,14 @@ * This is basically a handle approach. */ void -authenticateAuthenticateUser(auth_user_request_t *auth_user_request, request_t *request, ConnStateData *conn, http_hdr_type type) { +authenticateAuthenticateUser(auth_user_request_t * auth_user_request, request_t * request, ConnStateData * conn, http_hdr_type type) +{ #if 0 - const char * proxy_auth; + const char *proxy_auth; #endif - assert(auth_user_request !=NULL); - if (auth_user_request->auth_user->auth_module>0) - authscheme_list[auth_user_request->auth_user->auth_module-1].authAuthenticate(auth_user_request, request, conn, type); + assert(auth_user_request != NULL); + if (auth_user_request->auth_user->auth_module > 0) + authscheme_list[auth_user_request->auth_user->auth_module - 1].authAuthenticate(auth_user_request, request, conn, type); #if 0 proxy_auth = httpHeaderGetStr(&request->header, type); @@ -346,49 +344,59 @@ /* authenticateUserUsername: return a pointer to the username in the */ char * -authenticateUserUsername(auth_user_t *auth_user) +authenticateUserUsername(auth_user_t * auth_user) { if (!auth_user) - return NULL; - if (auth_user->auth_module>0) - return authscheme_list[auth_user->auth_module-1].authUserUsername(auth_user); + return NULL; + if (auth_user->auth_module > 0) + return authscheme_list[auth_user->auth_module - 1].authUserUsername(auth_user); return NULL; } /* authenticateUserRequestUsername: return a pointer to the username in the */ char * -authenticateUserRequestUsername(auth_user_request_t *auth_user_request) { - assert (auth_user_request !=NULL); - return authenticateUserUsername(auth_user_request->auth_user); +authenticateUserRequestUsername(auth_user_request_t * auth_user_request) +{ + assert(auth_user_request != NULL); + return authenticateUserUsername(auth_user_request->auth_user); } /* returns -0: no output needed -1: send to client --1: send to helper --2: authenticate broken in some fashion -*/ + * 0: no output needed + * 1: send to client + * -1: send to helper + * -2: authenticate broken in some fashion + */ int -authenticateDirection(auth_user_request_t *auth_user_request) { - if (!auth_user_request) return -2; - if (authenticateUserAuthenticated(auth_user_request)) return 0; - if (auth_user_request->auth_user->auth_module>0) - return authscheme_list[auth_user_request->auth_user->auth_module-1].getdirection(auth_user_request); +authenticateDirection(auth_user_request_t * auth_user_request) +{ + if (!auth_user_request) + return -2; + if (authenticateUserAuthenticated(auth_user_request)) + return 0; + if (auth_user_request->auth_user->auth_module > 0) + return authscheme_list[auth_user_request->auth_user->auth_module - 1].getdirection(auth_user_request); return -2; } -int authenticateActiveSchemeCount() { - int i =0,rv =0; - for (i = 0; authscheme_list && authscheme_list[i].typestr; i++) - if (authscheme_list[i].Active()) rv++; - debug(29,9)("authenticateActiveSchemeCount: %d active.\n",rv); +int +authenticateActiveSchemeCount() +{ + int i = 0, rv = 0; + for (i = 0; authscheme_list && authscheme_list[i].typestr; i++) + if (authscheme_list[i].Active()) + rv++; + debug(29, 9) ("authenticateActiveSchemeCount: %d active.\n", rv); return rv; } -int authenticateSchemeCount() { - int i =0,rv =0; - for (i = 0; authscheme_list && authscheme_list[i].typestr; i++) rv++; - debug(29,9)("authenticateSchemeCount: %d active.\n",rv); +int +authenticateSchemeCount() +{ + int i = 0, rv = 0; + for (i = 0; authscheme_list && authscheme_list[i].typestr; i++) + rv++; + debug(29, 9) ("authenticateSchemeCount: %d active.\n", rv); return rv; } @@ -399,35 +407,33 @@ } void -authenticateInit(authConfig *config) +authenticateInit(authConfig * config) { int i; authScheme *scheme; - for (i = 0; i < config->n_configured; i++) - { - if (authscheme_list[i].init) - { - scheme=config->schemes+i; - authscheme_list[i].init(scheme); - } - } + for (i = 0; i < config->n_configured; i++) { + if (authscheme_list[i].init) { + scheme = config->schemes + i; + authscheme_list[i].init(scheme); + } + } if (!proxy_auth_username_cache) - authenticateInitUserCache(); + authenticateInitUserCache(); } void authenticateShutdown(void) { int i; - debug(29,2) ("authenticateShutdown: shutting down auth schemes\n"); + debug(29, 2) ("authenticateShutdown: shutting down auth schemes\n"); /* find the currently known authscheme types */ for (i = 0; authscheme_list && authscheme_list[i].typestr; i++) { - if (authscheme_list[i].donefunc !=NULL) - authscheme_list[i].donefunc(); - else - debug(29,2) ("authenticateShutdown: scheme %s has not registered a shutdown function.\n", authscheme_list[i].typestr); - authscheme_list[i].typestr=NULL; - } + if (authscheme_list[i].donefunc != NULL) + authscheme_list[i].donefunc(); + else + debug(29, 2) ("authenticateShutdown: scheme %s has not registered a shutdown function.\n", authscheme_list[i].typestr); + authscheme_list[i].typestr = NULL; + } } #if 0 @@ -436,156 +442,159 @@ /* send the auth types we are configured to support (and have compiled in!) */ { /* auth_type_t auth_type=err->auth_type; - auth_state_t auth_state=err->auth_state; - char *authchallenge=err->authchallenge; -*/ auth_user_request_t *auth_user_request=err->auth_user_request; + * auth_state_t auth_state=err->auth_state; + * char *authchallenge=err->authchallenge; + */ auth_user_request_t *auth_user_request = err->auth_user_request; int type; switch (err->http_status) { case HTTP_PROXY_AUTHENTICATION_REQUIRED: - /* Proxy authorisation needed */ - type= HDR_PROXY_AUTHENTICATE; - break; - case HTTP_UNAUTHORIZED: - /* WWW Authorisation needed */ - type=HDR_WWW_AUTHENTICATE; - break; - default: - /* Keep GCC happy */ - /* some other HTTP status */ + /* Proxy authorisation needed */ + type = HDR_PROXY_AUTHENTICATE; + break; + case HTTP_UNAUTHORIZED: + /* WWW Authorisation needed */ + type = HDR_WWW_AUTHENTICATE; + break; + default: + /* Keep GCC happy */ + /* some other HTTP status */ return; - break; - } - debug(29,9)("authenticateFixHeader: headertype:%d authuser:%d\n",type,auth_user_request); - if ((auth_user_request !=NULL) && (auth_user_request->auth_user->auth_module>0)) - authscheme_list[auth_user_request->auth_user->auth_module-1].authFixHeader(auth_user_request, rep, type, err->request); + break; + } + debug(29, 9) ("authenticateFixHeader: headertype:%d authuser:%d\n", type, auth_user_request); + if ((auth_user_request != NULL) && (auth_user_request->auth_user->auth_module > 0)) + authscheme_list[auth_user_request->auth_user->auth_module - 1].authFixHeader(auth_user_request, rep, type, err->request); else { - int i; - authScheme *scheme; - /* call each configured authscheme */ - for (i = 0; i < Config.authConfig.n_configured; i++) - { - scheme=Config.authConfig.schemes+i; - if (authscheme_list[scheme->Id].Active()) - authscheme_list[scheme->Id].authFixHeader(auth_user_request,rep,type, - err->request); - else - debug(29,8)("authenticateFixHeader: Configured scheme %s not Active\n",scheme->typestr); - } + int i; + authScheme *scheme; + /* call each configured authscheme */ + for (i = 0; i < Config.authConfig.n_configured; i++) { + scheme = Config.authConfig.schemes + i; + if (authscheme_list[scheme->Id].Active()) + authscheme_list[scheme->Id].authFixHeader(auth_user_request, rep, type, + err->request); + else + debug(29, 8) ("authenticateFixHeader: Configured scheme %s not Active\n", scheme->typestr); + } } } #endif void -authenticateFixHeader(HttpReply * rep, auth_user_request_t * auth_user_request, request_t* request, int accelerated) +authenticateFixHeader(HttpReply * rep, auth_user_request_t * auth_user_request, request_t * request, int accelerated) /* send the auth types we are configured to support (and have compiled in!) */ { /* auth_type_t auth_type=err->auth_type; - auth_state_t auth_state=err->auth_state; - char *authchallenge=err->authchallenge; - auth_user_request_t *auth_user_request=err->auth_user_request; -*/ - int type=0; + * auth_state_t auth_state=err->auth_state; + * char *authchallenge=err->authchallenge; + * auth_user_request_t *auth_user_request=err->auth_user_request; + */ + int type = 0; switch (rep->sline.status) { case HTTP_PROXY_AUTHENTICATION_REQUIRED: - /* Proxy authorisation needed */ - type= HDR_PROXY_AUTHENTICATE; - break; + /* Proxy authorisation needed */ + type = HDR_PROXY_AUTHENTICATE; + break; case HTTP_UNAUTHORIZED: - /* WWW Authorisation needed */ - type=HDR_WWW_AUTHENTICATE; - break; + /* WWW Authorisation needed */ + type = HDR_WWW_AUTHENTICATE; + break; default: - /* Keep GCC happy */ - /* some other HTTP status */ - break; - } - debug(29,9)("authenticateFixHeader: headertype:%d authuser:%d\n",type,auth_user_request); - if ((rep->sline.status==HTTP_PROXY_AUTHENTICATION_REQUIRED) - || (rep->sline.status==HTTP_UNAUTHORIZED)) - /* this is a authenticate-needed response */ + /* Keep GCC happy */ + /* some other HTTP status */ + break; + } + debug(29, 9) ("authenticateFixHeader: headertype:%d authuser:%d\n", type, auth_user_request); + if ((rep->sline.status == HTTP_PROXY_AUTHENTICATION_REQUIRED) + || (rep->sline.status == HTTP_UNAUTHORIZED)) + /* this is a authenticate-needed response */ { - if ((auth_user_request !=NULL) && (auth_user_request->auth_user->auth_module>0)) - authscheme_list[auth_user_request->auth_user->auth_module-1].authFixHeader(auth_user_request, rep, type, request); - else { - int i; - authScheme *scheme; - /* call each configured authscheme */ - for (i = 0; i < Config.authConfig.n_configured; i++) - { - scheme=Config.authConfig.schemes+i; - if (authscheme_list[scheme->Id].Active()) - authscheme_list[scheme->Id].authFixHeader(auth_user_request,rep,type, - request); - else - debug(29,4)("authenticateFixHeader: Configured scheme %s not Active\n",scheme->typestr); - } - } - } - if ((auth_user_request != NULL) && (auth_user_request->auth_user->auth_module>0) - && (authscheme_list[auth_user_request->auth_user->auth_module-1].AddHeader)) - authscheme_list[auth_user_request->auth_user->auth_module-1].AddHeader(auth_user_request, rep, accelerated); + if ((auth_user_request != NULL) && (auth_user_request->auth_user->auth_module > 0)) + authscheme_list[auth_user_request->auth_user->auth_module - 1].authFixHeader(auth_user_request, rep, type, request); + else { + int i; + authScheme *scheme; + /* call each configured authscheme */ + for (i = 0; i < Config.authConfig.n_configured; i++) { + scheme = Config.authConfig.schemes + i; + if (authscheme_list[scheme->Id].Active()) + authscheme_list[scheme->Id].authFixHeader(auth_user_request, rep, type, + request); + else + debug(29, 4) ("authenticateFixHeader: Configured scheme %s not Active\n", scheme->typestr); + } + } + } + if ((auth_user_request != NULL) && (auth_user_request->auth_user->auth_module > 0) + && (authscheme_list[auth_user_request->auth_user->auth_module - 1].AddHeader)) + authscheme_list[auth_user_request->auth_user->auth_module - 1].AddHeader(auth_user_request, rep, accelerated); } /* call the active auth module and allow it to add a trailer to the request */ void -authenticateAddTrailer(HttpReply * rep, auth_user_request_t * auth_user_request, request_t* request, int accelerated) +authenticateAddTrailer(HttpReply * rep, auth_user_request_t * auth_user_request, request_t * request, int accelerated) { - if ((auth_user_request != NULL) && (auth_user_request->auth_user->auth_module>0) - && (authscheme_list[auth_user_request->auth_user->auth_module-1].AddTrailer)) - authscheme_list[auth_user_request->auth_user->auth_module-1].AddTrailer(auth_user_request, rep, accelerated); + if ((auth_user_request != NULL) && (auth_user_request->auth_user->auth_module > 0) + && (authscheme_list[auth_user_request->auth_user->auth_module - 1].AddTrailer)) + authscheme_list[auth_user_request->auth_user->auth_module - 1].AddTrailer(auth_user_request, rep, accelerated); } -void authenticateAuthUserLock(auth_user_t *auth_user) +void +authenticateAuthUserLock(auth_user_t * auth_user) { - debug (29,9) ("authenticateAuthUserLock auth_user '%d'.\n",auth_user); - assert(auth_user!=NULL); - auth_user->references++; - debug (29,9) ("authenticateAuthUserLock auth_user '%d' now at '%d'.\n",auth_user, auth_user->references); + debug(29, 9) ("authenticateAuthUserLock auth_user '%d'.\n", auth_user); + assert(auth_user != NULL); + auth_user->references++; + debug(29, 9) ("authenticateAuthUserLock auth_user '%d' now at '%d'.\n", auth_user, auth_user->references); } -void authenticateAuthUserUnlock(auth_user_t *auth_user) +void +authenticateAuthUserUnlock(auth_user_t * auth_user) { - debug (29,9) ("authenticateAuthUserUnlock auth_user '%d'.\n",auth_user); - assert(auth_user!=NULL); - if (auth_user->references>0){ - auth_user->references--; + debug(29, 9) ("authenticateAuthUserUnlock auth_user '%d'.\n", auth_user); + assert(auth_user != NULL); + if (auth_user->references > 0) { + auth_user->references--; } else { - debug(29,1) ("Attempt to lower Auth User %d refcount below 0!\n",auth_user); + debug(29, 1) ("Attempt to lower Auth User %d refcount below 0!\n", auth_user); } - debug (29,9) ("authenticateAuthUserUnlock auth_user '%d' now at '%d'.\n",auth_user, auth_user->references); - if (auth_user->references==0) - authenticateFreeProxyAuthUser(auth_user); + debug(29, 9) ("authenticateAuthUserUnlock auth_user '%d' now at '%d'.\n", auth_user, auth_user->references); + if (auth_user->references == 0) + authenticateFreeProxyAuthUser(auth_user); } -void authenticateAuthUserRequestLock(auth_user_request_t *auth_user_request) +void +authenticateAuthUserRequestLock(auth_user_request_t * auth_user_request) { - debug (29,9) ("authenticateAuthUserRequestLock auth_user request '%d'.\n",auth_user_request); - assert(auth_user_request!=NULL); - auth_user_request->references++; - debug (29,9) ("authenticateAuthUserRequestLock auth_user request '%d' now at '%d'.\n",auth_user_request, auth_user_request->references); + debug(29, 9) ("authenticateAuthUserRequestLock auth_user request '%d'.\n", auth_user_request); + assert(auth_user_request != NULL); + auth_user_request->references++; + debug(29, 9) ("authenticateAuthUserRequestLock auth_user request '%d' now at '%d'.\n", auth_user_request, auth_user_request->references); } -void authenticateAuthUserRequestUnlock(auth_user_request_t *auth_user_request) +void +authenticateAuthUserRequestUnlock(auth_user_request_t * auth_user_request) { - debug (29,9) ("authenticateAuthUserRequestUnlock auth_user request '%d'.\n",auth_user_request); + debug(29, 9) ("authenticateAuthUserRequestUnlock auth_user request '%d'.\n", auth_user_request); assert(auth_user_request != NULL); - if (auth_user_request->references>0){ - auth_user_request->references--; + if (auth_user_request->references > 0) { + auth_user_request->references--; } else { - debug(29,1) ("Attempt to lower Auth User request %d refcount below 0!\n",auth_user_request); + debug(29, 1) ("Attempt to lower Auth User request %d refcount below 0!\n", auth_user_request); } - debug (29,9) ("authenticateAuthUserRequestUnlock auth_user_request '%d' now at '%d'.\n",auth_user_request, auth_user_request->references); - if (auth_user_request->references==0) { - /* not locked anymore */ - authenticateAuthUserRequestFree(auth_user_request); + debug(29, 9) ("authenticateAuthUserRequestUnlock auth_user_request '%d' now at '%d'.\n", auth_user_request, auth_user_request->references); + if (auth_user_request->references == 0) { + /* not locked anymore */ + authenticateAuthUserRequestFree(auth_user_request); } } -int authenticateAuthUserInuse(auth_user_t *auth_user) +int +authenticateAuthUserInuse(auth_user_t * auth_user) /* returns 0 for not in use */ { - assert(auth_user!=NULL); - return auth_user->references; + assert(auth_user != NULL); + return auth_user->references; } /* Combine two user structs. ONLY to be called from within a scheme module. @@ -593,25 +602,24 @@ * without invalidating all the request scheme data. * the scheme is also responsible for merging any user related scheme data itself. */ void -authenticateAuthUserMerge(auth_user_t *from, auth_user_t *to) +authenticateAuthUserMerge(auth_user_t * from, auth_user_t * to) { - dlink_node * link, *tmplink; - auth_user_request_t * auth_user_request; + dlink_node *link, *tmplink; + auth_user_request_t *auth_user_request; /* XXX combine two authuser structs. Incomplete: it should merge in hash references - too and ask the module to merge in scheme data*/ - debug (29,5) ("authenticateAuthUserMerge auth_user '%d' into auth_user '%d'.\n",from,to); + * too and ask the module to merge in scheme data */ + debug(29, 5) ("authenticateAuthUserMerge auth_user '%d' into auth_user '%d'.\n", from, to); link = from->requests.head; - while (link) - { - auth_user_request=link->data; - tmplink=link; - link=link->next; - dlinkDelete(tmplink, &from->requests); - dlinkAddTail(auth_user_request, tmplink, &to->requests); - auth_user_request->auth_user=to; + while (link) { + auth_user_request = link->data; + tmplink = link; + link = link->next; + dlinkDelete(tmplink, &from->requests); + dlinkAddTail(auth_user_request, tmplink, &to->requests); + auth_user_request->auth_user = to; } - to->references+=from->references; - from->references=0; + to->references += from->references; + from->references = 0; authenticateFreeProxyAuthUser(from); } @@ -624,69 +632,70 @@ auth_user_hash_pointer *proxy_auth_hash; #endif dlink_node *link, *tmplink; - assert(data !=NULL); - debug(29,5) ("authenticateFreeProxyAuthUser: Freeing auth_user '%d' with refcount '%d'.\n",u,u->references); - assert(u->references==0); + assert(data != NULL); + debug(29, 5) ("authenticateFreeProxyAuthUser: Freeing auth_user '%d' with refcount '%d'.\n", u, u->references); + assert(u->references == 0); /* were they linked in by username ? */ if (u->usernamehash) { - assert(u->usernamehash->auth_user == u); - debug(29,5) ("authenticateFreeProxyAuthUser: removing usernamehash entry '%d'\n",u->usernamehash); - hash_remove_link(proxy_auth_username_cache, - (hash_link *) u->usernamehash); - /* don't free the key as we use the same user string as the auth_user - * structure */ - memFree(u->usernamehash, MEM_AUTH_USER_HASH); + assert(u->usernamehash->auth_user == u); + debug(29, 5) ("authenticateFreeProxyAuthUser: removing usernamehash entry '%d'\n", u->usernamehash); + hash_remove_link(proxy_auth_username_cache, + (hash_link *) u->usernamehash); + /* don't free the key as we use the same user string as the auth_user + * structure */ + memFree(u->usernamehash, MEM_AUTH_USER_HASH); } #if 0 /* were they linked in by one or more proxy-authenticate headers */ link = u->proxy_auth_list.head; while (link) { - debug(29,6) ("authenticateFreeProxyAuthUser: removing proxy_auth hash entry '%d'\n",link->data); - proxy_auth_hash = link->data; - tmplink=link; - link=link->next; - dlinkDelete(tmplink, &u->proxy_auth_list); - hash_remove_link(proxy_auth_cache, (hash_link *) proxy_auth_hash); - /* free the key (usually the proxy_auth header) */ - xfree(proxy_auth_hash->key); - memFree(proxy_auth_hash, MEM_AUTH_USER_HASH); + debug(29, 6) ("authenticateFreeProxyAuthUser: removing proxy_auth hash entry '%d'\n", link->data); + proxy_auth_hash = link->data; + tmplink = link; + link = link->next; + dlinkDelete(tmplink, &u->proxy_auth_list); + hash_remove_link(proxy_auth_cache, (hash_link *) proxy_auth_hash); + /* free the key (usually the proxy_auth header) */ + xfree(proxy_auth_hash->key); + memFree(proxy_auth_hash, MEM_AUTH_USER_HASH); } #endif /* remove any outstanding requests */ link = u->requests.head; while (link) { - debug(29,5) ("authenticateFreeProxyAuthUser: removing request entry '%d'\n",link->data); - auth_user_request = link->data; - tmplink = link; - link=link->next; - dlinkDelete(tmplink, &u->requests); - dlinkNodeDelete(tmplink); - authenticateAuthUserRequestFree(auth_user_request); + debug(29, 5) ("authenticateFreeProxyAuthUser: removing request entry '%d'\n", link->data); + auth_user_request = link->data; + tmplink = link; + link = link->next; + dlinkDelete(tmplink, &u->requests); + dlinkNodeDelete(tmplink); + authenticateAuthUserRequestFree(auth_user_request); } /* free cached acl results */ aclCacheMatchFlush(&u->proxy_match_cache); - if (u->scheme_data && u->auth_module>0) - authscheme_list[u->auth_module-1].FreeUser(u); + if (u->scheme_data && u->auth_module > 0) + authscheme_list[u->auth_module - 1].FreeUser(u); /* prevent accidental reuse */ - u->auth_type=AUTH_UNKNOWN; + u->auth_type = AUTH_UNKNOWN; memFree(u, MEM_AUTH_USER_T); } void -authenticateInitUserCache(){ +authenticateInitUserCache() +{ if (!proxy_auth_username_cache) { - /* First time around, 7921 should be big enough */ - proxy_auth_username_cache = - hash_create((HASHCMP *) strcmp, 7921, hash_string); - assert(proxy_auth_username_cache); -#if 0 - /* First time around, 7921 should be big enough */ - proxy_auth_cache = - hash_create((HASHCMP *) strcmp, 7921, hash_string); - assert(proxy_auth_cache); + /* First time around, 7921 should be big enough */ + proxy_auth_username_cache = + hash_create((HASHCMP *) strcmp, 7921, hash_string); + assert(proxy_auth_username_cache); +#if 0 + /* First time around, 7921 should be big enough */ + proxy_auth_cache = + hash_create((HASHCMP *) strcmp, 7921, hash_string); + assert(proxy_auth_cache); #endif - eventAdd("User Cache Maintenance", authenticateProxyUserCacheCleanup, NULL, Config.authenticateGCInterval, 1); - } + eventAdd("User Cache Maintenance", authenticateProxyUserCacheCleanup, NULL, Config.authenticateGCInterval, 1); + } } void @@ -699,27 +708,27 @@ */ auth_user_hash_pointer *usernamehash; auth_user_t *auth_user; - char * username=NULL; - debug(29,3) ("authenticateProxyUserCacheCleanup: Cleaning the user cache now\n"); - debug(29,3) ("authenticateProxyUserCacheCleanup: Current time: %d\n", current_time.tv_sec); + char *username = NULL; + debug(29, 3) ("authenticateProxyUserCacheCleanup: Cleaning the user cache now\n"); + debug(29, 3) ("authenticateProxyUserCacheCleanup: Current time: %d\n", current_time.tv_sec); hash_first(proxy_auth_username_cache); - while ((usernamehash=((auth_user_hash_pointer *)hash_next(proxy_auth_username_cache)))) { - auth_user=usernamehash->auth_user; - username=authenticateUserUsername(auth_user); - - /* if we need to have inpedendent expiry clauses, insert a module call - * here */ - debug(29,4) ("authenticateProxyUserCacheCleanup: Cache entry:\n\tType: %d\n\tUsername: %s\n\texpires: %d\n\treferences: %d\n", auth_user->auth_type, username, auth_user->expiretime+ Config.authenticateTTL,auth_user->references); - if (auth_user->expiretime + Config.authenticateTTL <= current_time.tv_sec) { - debug(29,5)("authenticateProxyUserCacheCleanup: Removing user %s from cache due to timeout.\n",username); - /* the minus 1 accounts for the cache lock */ - if ((authenticateAuthUserInuse(auth_user)-1)) - debug(29,4)("authenticateProxyUserCacheCleanup: this cache entry has expired AND has a non-zero ref count.\n"); - else - authenticateAuthUserUnlock(auth_user); - } + while ((usernamehash = ((auth_user_hash_pointer *) hash_next(proxy_auth_username_cache)))) { + auth_user = usernamehash->auth_user; + username = authenticateUserUsername(auth_user); + + /* if we need to have inpedendent expiry clauses, insert a module call + * here */ + debug(29, 4) ("authenticateProxyUserCacheCleanup: Cache entry:\n\tType: %d\n\tUsername: %s\n\texpires: %d\n\treferences: %d\n", auth_user->auth_type, username, auth_user->expiretime + Config.authenticateTTL, auth_user->references); + if (auth_user->expiretime + Config.authenticateTTL <= current_time.tv_sec) { + debug(29, 5) ("authenticateProxyUserCacheCleanup: Removing user %s from cache due to timeout.\n", username); + /* the minus 1 accounts for the cache lock */ + if ((authenticateAuthUserInuse(auth_user) - 1)) + debug(29, 4) ("authenticateProxyUserCacheCleanup: this cache entry has expired AND has a non-zero ref count.\n"); + else + authenticateAuthUserUnlock(auth_user); + } } - debug(29,3) ("authenticateProxyUserCacheCleanup: Finished cleaning the user cache.\n"); + debug(29, 3) ("authenticateProxyUserCacheCleanup: Finished cleaning the user cache.\n"); eventAdd("User Cache Maintenance", authenticateProxyUserCacheCleanup, NULL, Config.authenticateGCInterval, 1); } @@ -729,17 +738,18 @@ */ void -authenticateUserCacheRestart(){ +authenticateUserCacheRestart() +{ auth_user_hash_pointer *usernamehash; auth_user_t *auth_user; - char * username=NULL; - debug(29,3) ("authenticateUserCacheRestart: Clearing config dependent cache data.\n"); + char *username = NULL; + debug(29, 3) ("authenticateUserCacheRestart: Clearing config dependent cache data.\n"); hash_first(proxy_auth_username_cache); - while ((usernamehash=((auth_user_hash_pointer *)hash_next(proxy_auth_username_cache)))) { - auth_user=usernamehash->auth_user; - username=authenticateUserUsername(auth_user); - debug(29,5) ("authenticateUserCacheRestat: Clearing cache ACL results for user: %s\n", username); - aclCacheMatchFlush(&auth_user->proxy_match_cache); + while ((usernamehash = ((auth_user_hash_pointer *) hash_next(proxy_auth_username_cache)))) { + auth_user = usernamehash->auth_user; + username = authenticateUserUsername(auth_user); + debug(29, 5) ("authenticateUserCacheRestat: Clearing cache ACL results for user: %s\n", username); + aclCacheMatchFlush(&auth_user->proxy_match_cache); } } @@ -747,16 +757,18 @@ #if 0 void -authenticateProxyAuthCacheAddLink(const char *key, auth_user_t *auth_user){ +authenticateProxyAuthCacheAddLink(const char *key, auth_user_t * auth_user) +{ auth_user_hash_pointer *proxy_auth_hash; proxy_auth_hash = - memAllocate(MEM_AUTH_USER_HASH); + memAllocate(MEM_AUTH_USER_HASH); proxy_auth_hash->key = xstrdup(key); proxy_auth_hash->auth_user = auth_user; dlinkAddTail(proxy_auth_hash, &proxy_auth_hash->link, - &proxy_auth_hash->auth_user->proxy_auth_list); + &proxy_auth_hash->auth_user->proxy_auth_list); hash_join(proxy_auth_cache, (hash_link *) proxy_auth_hash); } + #endif /* @@ -768,7 +780,7 @@ int i; /* find the number of currently known authscheme types */ for (i = 0; authscheme_list && authscheme_list[i].typestr; i++) { - assert(strcmp(authscheme_list[i].typestr, type) != 0); + assert(strcmp(authscheme_list[i].typestr, type) != 0); } /* add the new type */ authscheme_list = xrealloc(authscheme_list, (i + 2) * sizeof(authscheme_entry_t)); @@ -780,9 +792,10 @@ -/* UserNameCacheAdd: add a auth_user structure to the username cache */ +/* UserNameCacheAdd: add a auth_user structure to the username cache */ void -authenticateUserNameCacheAdd(auth_user_t *auth_user){ +authenticateUserNameCacheAdd(auth_user_t * auth_user) +{ auth_user_hash_pointer *usernamehash; usernamehash = memAllocate(MEM_AUTH_USER_HASH); usernamehash->key = authenticateUserUsername(auth_user); @@ -805,34 +818,34 @@ int authenticateCheckAuthUserIP(struct in_addr request_src_addr, auth_user_request_t * auth_user_request) { - char *username=NULL; - if (request_src_addr.s_addr == auth_user_request->auth_user->ipaddr.s_addr || auth_user_request->auth_user->ip_expiretime+ Config.authenticateIpTTL <= squid_curtime) { - /* user has not moved ip or had the ip timeout expire */ - if ((auth_user_request->auth_user->auth_type==AUTH_UNKNOWN) || - (auth_user_request->auth_user->auth_type==AUTH_BROKEN)) { - debug(29, 1) - ("authenticateCheckProxyAuthIP: broken or unknown auth type %d.\n", auth_user_request->auth_user->auth_type); - return 0; - } - username=authenticateUserRequestUsername(auth_user_request); - /* Update IP ttl */ - auth_user_request->auth_user->ip_expiretime = squid_curtime; - auth_user_request->auth_user->ipaddr = request_src_addr; - return 1; + char *username = NULL; + if (request_src_addr.s_addr == auth_user_request->auth_user->ipaddr.s_addr || auth_user_request->auth_user->ip_expiretime + Config.authenticateIpTTL <= squid_curtime) { + /* user has not moved ip or had the ip timeout expire */ + if ((auth_user_request->auth_user->auth_type == AUTH_UNKNOWN) || + (auth_user_request->auth_user->auth_type == AUTH_BROKEN)) { + debug(29, 1) + ("authenticateCheckProxyAuthIP: broken or unknown auth type %d.\n", auth_user_request->auth_user->auth_type); + return 0; + } + username = authenticateUserRequestUsername(auth_user_request); + /* Update IP ttl */ + auth_user_request->auth_user->ip_expiretime = squid_curtime; + auth_user_request->auth_user->ipaddr = request_src_addr; + return 1; } /* we are missing a check: expired IP time is actually ok. let it through * and update. */ else { - if (Config.onoff.authenticateIpTTLStrict) { - /* Access from some other IP address than the one owning - * this user ID. Deny access - */ + if (Config.onoff.authenticateIpTTLStrict) { + /* Access from some other IP address than the one owning + * this user ID. Deny access + */ /* debug(29, 1)("aclMatchProxyAuth: user '%s' tries to use multiple IP -addresses ! \n ", username); */ - return 0; - } else { - return 1; /* config.onoff.authenticateTTLStrict */ - } + * addresses ! \n ", username); */ + return 0; + } else { + return 1; /* config.onoff.authenticateTTLStrict */ + } /* the logic below is bad: if a user logs in twice we will be forcing an * external check on the username/password every single time. If a replay * attack is being used we will still allow the user through though: so why @@ -840,18 +853,18 @@ * prevent users being at more than one location, consider the TTL strict option */ /* with the separate keys for auth lookups, we could add the ip to the key and t -hen allow users on different ips to be cached and handled separately. */ + * hen allow users on different ips to be cached and handled separately. */ // else { -// /* user has switched to another IP addr */ -// debug(29, 1) -// ("aclMatchProxyAuth: user '%s' has changed IP address \n ", -// user); -// /* remove this user from the hash, making him unknown */ -// hash_remove_link(proxy_auth_cache, -// (hash_link *) auth_user); -// aclFreeProxyAuthUser(auth_user); -// /* require the user to reauthenticate */ -// return -2; -// } + // /* user has switched to another IP addr */ + // debug(29, 1) + // ("aclMatchProxyAuth: user '%s' has changed IP address \n ", + // user); + // /* remove this user from the hash, making him unknown */ + // hash_remove_link(proxy_auth_cache, + // (hash_link *) auth_user); + // aclFreeProxyAuthUser(auth_user); + // /* require the user to reauthenticate */ + // return -2; + // } } } Index: squid/src/cache_cf.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cache_cf.c,v retrieving revision 1.1.1.3.4.1.2.9.2.15 retrieving revision 1.1.1.3.4.1.2.9.2.16 diff -u -r1.1.1.3.4.1.2.9.2.15 -r1.1.1.3.4.1.2.9.2.16 --- squid/src/cache_cf.c 7 Jan 2001 00:37:02 -0000 1.1.1.3.4.1.2.9.2.15 +++ squid/src/cache_cf.c 7 Jan 2001 09:48:30 -0000 1.1.1.3.4.1.2.9.2.16 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.c,v 1.1.1.3.4.1.2.9.2.15 2001/01/07 00:37:02 hno Exp $ + * $Id: cache_cf.c,v 1.1.1.3.4.1.2.9.2.16 2001/01/07 09:48:30 hno Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -931,16 +931,16 @@ allocate_new_authScheme(authConfig * cfg) { if (cfg->schemes == NULL) { - cfg->n_allocated = 4; - cfg->schemes = xcalloc(cfg->n_allocated, sizeof(authScheme)); + cfg->n_allocated = 4; + cfg->schemes = xcalloc(cfg->n_allocated, sizeof(authScheme)); } if (cfg->n_allocated == cfg->n_configured) { - authScheme *tmp; - cfg->n_allocated <<= 1; - tmp = xcalloc(cfg->n_allocated, sizeof(authScheme)); - xmemcpy(tmp, cfg->schemes, cfg->n_configured * sizeof(authScheme)); - xfree(cfg->schemes); - cfg->schemes = tmp; + authScheme *tmp; + cfg->n_allocated <<= 1; + tmp = xcalloc(cfg->n_allocated, sizeof(authScheme)); + xmemcpy(tmp, cfg->schemes, cfg->n_configured * sizeof(authScheme)); + xfree(cfg->schemes); + cfg->schemes = tmp; } } @@ -949,36 +949,32 @@ { char *type_str; char *param_str; - authScheme *scheme=NULL; - int type,i; - + authScheme *scheme = NULL; + int type, i; + if ((type_str = strtok(NULL, w_space)) == NULL) - self_destruct(); + self_destruct(); if ((param_str = strtok(NULL, w_space)) == NULL) - self_destruct(); + self_destruct(); - if ((type=authenticateAuthSchemeId(type_str))==-1) - { - debug(3,0) ("Parsing Config File: Unknown authentication scheme '%s'.\n",type_str); - return; + if ((type = authenticateAuthSchemeId(type_str)) == -1) { + debug(3, 0) ("Parsing Config File: Unknown authentication scheme '%s'.\n", type_str); + return; } - for (i = 0; i < config->n_configured; i++) { - if (config->schemes[i].Id==type) { - scheme=config->schemes + i; - } + if (config->schemes[i].Id == type) { + scheme = config->schemes + i; + } } - if (scheme==NULL) - { - allocate_new_authScheme(config); - scheme=config->schemes + config->n_configured; - config->n_configured++; - scheme->Id=type; - scheme->typestr=authscheme_list[type].typestr; + if (scheme == NULL) { + allocate_new_authScheme(config); + scheme = config->schemes + config->n_configured; + config->n_configured++; + scheme->Id = type; + scheme->typestr = authscheme_list[type].typestr; } - authscheme_list[type].parse(scheme, config->n_configured, param_str); } @@ -989,10 +985,10 @@ int i; /* DON'T FREE THESE FOR RECONFIGURE */ if (reconfiguring) - return; + return; for (i = 0; i < cfg->n_configured; i++) { - scheme = cfg->schemes + i; - authscheme_list[scheme->Id].freeconfig(scheme); + scheme = cfg->schemes + i; + authscheme_list[scheme->Id].freeconfig(scheme); } safe_free(cfg->schemes); cfg->schemes = NULL; @@ -1006,8 +1002,8 @@ authScheme *scheme; int i; for (i = 0; i < cfg.n_configured; i++) { - scheme = cfg.schemes + i; - authscheme_list[scheme->Id].dump(entry, name, scheme); + scheme = cfg.schemes + i; + authscheme_list[scheme->Id].dump(entry, name, scheme); } } @@ -1015,16 +1011,16 @@ allocate_new_swapdir(cacheSwap * swap) { if (swap->swapDirs == NULL) { - swap->n_allocated = 4; - swap->swapDirs = xcalloc(swap->n_allocated, sizeof(SwapDir)); + swap->n_allocated = 4; + swap->swapDirs = xcalloc(swap->n_allocated, sizeof(SwapDir)); } if (swap->n_allocated == swap->n_configured) { - SwapDir *tmp; - swap->n_allocated <<= 1; - tmp = xcalloc(swap->n_allocated, sizeof(SwapDir)); - xmemcpy(tmp, swap->swapDirs, swap->n_configured * sizeof(SwapDir)); - xfree(swap->swapDirs); - swap->swapDirs = tmp; + SwapDir *tmp; + swap->n_allocated <<= 1; + tmp = xcalloc(swap->n_allocated, sizeof(SwapDir)); + xmemcpy(tmp, swap->swapDirs, swap->n_configured * sizeof(SwapDir)); + xfree(swap->swapDirs); + swap->swapDirs = tmp; } } @@ -1033,9 +1029,9 @@ { int i; for (i = 0; storefs_list[i].typestr != NULL; i++) { - if (strcasecmp(type, storefs_list[i].typestr) == 0) { - return i; - } + if (strcasecmp(type, storefs_list[i].typestr) == 0) { + return i; + } } return (-1); } Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.1.1.3.4.1.2.30.2.16 retrieving revision 1.1.1.3.4.1.2.30.2.17 diff -u -r1.1.1.3.4.1.2.30.2.16 -r1.1.1.3.4.1.2.30.2.17 --- squid/src/client_side.c 6 Jan 2001 23:56:28 -0000 1.1.1.3.4.1.2.30.2.16 +++ squid/src/client_side.c 7 Jan 2001 09:48:31 -0000 1.1.1.3.4.1.2.30.2.17 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.1.1.3.4.1.2.30.2.16 2001/01/06 23:56:28 rbcollins Exp $ + * $Id: client_side.c,v 1.1.1.3.4.1.2.30.2.17 2001/01/07 09:48:31 hno Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -116,7 +116,7 @@ static log_type clientProcessRequest2(clientHttpRequest * http); static int clientReplyBodyTooLarge(int clen); static int clientRequestBodyTooLarge(int clen); -static void clientProcessBody(ConnStateData *conn); +static void clientProcessBody(ConnStateData * conn); static int checkAccelOnly(clientHttpRequest * http) @@ -141,6 +141,7 @@ ConnStateData *conn = data; xstrncpy(conn->rfc931, ident ? ident : dash_str, USER_IDENT_SZ); } + #endif static aclCheck_t * @@ -156,7 +157,7 @@ * hack for ident ACL. It needs to get full addresses, and a * place to store the ident result on persistent connections... */ - /* connection oriented auth also needs these two lines for it's operation.*/ + /* connection oriented auth also needs these two lines for it's operation. */ ch->conn = conn; cbdataLock(ch->conn); @@ -222,7 +223,7 @@ RequestMethodStr[http->request->method], http->uri, answer == ACCESS_ALLOWED ? "ALLOWED" : "DENIED", AclMatchedName ? AclMatchedName : "NO ACL's"); - proxy_auth_msg = authenticateAuthUserRequestMessage(http->conn->auth_user_request? http->conn->auth_user_request : http->request->auth_user_request); + proxy_auth_msg = authenticateAuthUserRequestMessage(http->conn->auth_user_request ? http->conn->auth_user_request : http->request->auth_user_request); http->acl_checklist = NULL; if (answer == ACCESS_ALLOWED) { safe_free(http->uri); @@ -264,13 +265,13 @@ err = errorCon(page_id, status); err->request = requestLink(http->request); err->src_addr = http->conn->peer.sin_addr; - if (http->conn->auth_user_request) - err->auth_user_request=http->conn->auth_user_request; - else if (http->request->auth_user_request) - err->auth_user_request=http->request->auth_user_request; - /* lock for the error state */ - if (err->auth_user_request) - authenticateAuthUserRequestLock(err->auth_user_request); + if (http->conn->auth_user_request) + err->auth_user_request = http->conn->auth_user_request; + else if (http->request->auth_user_request) + err->auth_user_request = http->request->auth_user_request; + /* lock for the error state */ + if (err->auth_user_request) + authenticateAuthUserRequestLock(err->auth_user_request); err->callback_data = NULL; errorAppendEntry(http->entry, err); } @@ -309,7 +310,7 @@ new_request->my_addr = old_request->my_addr; new_request->my_port = old_request->my_port; new_request->flags.redirected = 1; - new_request->auth_user_request=old_request->auth_user_request; + new_request->auth_user_request = old_request->auth_user_request; #if 0 if (old_request->authuser[0]) xstrncpy(new_request->authuser, old_request->authuser, @@ -713,7 +714,7 @@ debug(33, 3) ("httpRequestFree: %s\n", storeUrl(http->entry)); if (!clientCheckTransferDone(http)) { if (request && request->body_connection) - clientAbortBody(request); /* abort body transter */ + clientAbortBody(request); /* abort body transter */ #if MYSTERIOUS_CODE /* * DW: this seems odd here, is it really needed? It causes @@ -754,17 +755,16 @@ http->al.http.version = request->http_ver; http->al.headers.request = xstrdup(mb.buf); http->al.hier = request->hier; - if (request->auth_user_request) - { - http->al.cache.authuser = xstrdup(authenticateUserRequestUsername(request->auth_user_request)); - authenticateAuthUserRequestUnlock(request->auth_user_request); - request->auth_user_request= NULL; - } + if (request->auth_user_request) { + http->al.cache.authuser = xstrdup(authenticateUserRequestUsername(request->auth_user_request)); + authenticateAuthUserRequestUnlock(request->auth_user_request); + request->auth_user_request = NULL; + } #if 0 if (request->authuser[0]) http->al.cache.authuser = request->authuser; #endif - if (conn->rfc931[0]) + if (conn->rfc931[0]) http->al.cache.rfc931 = conn->rfc931; packerClean(&p); memBufClean(&mb); @@ -1014,7 +1014,7 @@ if (method == METHOD_PUT) return 0; if (method == METHOD_POST) - return 0; /* XXX POST may be cached sometimes.. ignored for now */ + return 0; /* XXX POST may be cached sometimes.. ignored for now */ if (req->protocol == PROTO_GOPHER) return gopherCachable(url); if (req->protocol == PROTO_CACHEOBJ) @@ -1297,7 +1297,7 @@ } /* Handle authentication headers */ if (request->auth_user_request) - authenticateFixHeader(rep, request->auth_user_request, request,http->flags.accel); + authenticateFixHeader(rep, request->auth_user_request, request, http->flags.accel); /* Append X-Cache */ httpHeaderPutStrf(hdr, HDR_X_CACHE, "%s from %s", is_hit ? "HIT" : "MISS", getMyHostname()); @@ -2323,7 +2323,6 @@ debug(33, 1) ("parseHttpRequest: Requestheader contains NULL characters\n"); return parseHttpRequestAbort(conn, "error:invalid-request"); } - /* Look for request method */ if ((mstr = strtok(inbuf, "\t ")) == NULL) { debug(33, 1) ("parseHttpRequest: Can't get request method\n"); @@ -2629,7 +2628,7 @@ } conn->in.buf[conn->in.offset] = '\0'; /* Terminate the string */ if (nrequests == 0) - fd_note(conn->fd,"Reading next request"); + fd_note(conn->fd, "Reading next request"); /* Process request */ http = parseHttpRequest(conn, &method, @@ -2750,7 +2749,7 @@ } } clientAccessCheck(http); - continue; /* while offset > 0 && body.size_left == 0 */ + continue; /* while offset > 0 && body.size_left == 0 */ } else if (parser_return_code == 0) { /* * Partial request received; reschedule until parseHttpRequest() @@ -2789,10 +2788,10 @@ } break; } - } /* while offset > 0 && conn->body.size_left == 0 */ + } /* while offset > 0 && conn->body.size_left == 0 */ /* Check if a half-closed connection was aborted in the middle */ if (F->flags.socket_eof) { - if (conn->in.offset != conn->body.size_left) { /* != 0 when no request body */ + if (conn->in.offset != conn->body.size_left) { /* != 0 when no request body */ /* Partial request received. Abort client connection! */ debug(33, 3) ("clientReadRequest: FD %d aborted\n", fd); comm_close(fd); @@ -2803,12 +2802,12 @@ /* file_read like function, for reading body content */ void -clientReadBody( request_t *request, char *buf, size_t size, CBCB *callback, void *cbdata) +clientReadBody(request_t * request, char *buf, size_t size, CBCB * callback, void *cbdata) { ConnStateData *conn = request->body_connection; if (!conn) { - debug(33, 5) ("clientReadBody: no body to read, request=%p\n",request); - callback(buf,0,cbdata); /* Signal end of body */ + debug(33, 5) ("clientReadBody: no body to read, request=%p\n", request); + callback(buf, 0, cbdata); /* Signal end of body */ return; } debug(33, 2) ("clientReadBody: start fd=%d body_size=%d in.offset=%d cb=%p req=%p\n", conn->fd, conn->body.size_left, conn->in.offset, callback, request); @@ -2827,7 +2826,7 @@ /* Called by clientReadRequest to process body content */ static void -clientProcessBody(ConnStateData *conn) +clientProcessBody(ConnStateData * conn) { int size; char *buf = conn->body.buf; @@ -2843,9 +2842,9 @@ assert(buf != NULL); /* How much do we have to process? */ size = conn->in.offset; - if (size > conn->body.size_left) /* only process the body part */ + if (size > conn->body.size_left) /* only process the body part */ size = conn->body.size_left; - if (size > conn->body.bufsize) /* don't copy more than requested */ + if (size > conn->body.bufsize) /* don't copy more than requested */ size = conn->body.bufsize; xmemcpy(buf, conn->in.buf, size); conn->body.size_left -= size; @@ -2857,7 +2856,7 @@ * clientReadRequest automatically continues to process next request */ if (conn->body.size_left <= 0 && request != NULL) request->body_connection = NULL; - /* Remove clientReadBody arguments (the call is completed)*/ + /* Remove clientReadBody arguments (the call is completed) */ conn->body.request = NULL; conn->body.callback = NULL; conn->body.buf = NULL; @@ -2868,7 +2867,7 @@ /* Invoke callback function */ callback(buf, size, cbdata); if (request != NULL) - requestUnlink(request); /* Linked in clientReadBody */ + requestUnlink(request); /* Linked in clientReadBody */ debug(33, 2) ("clientProcessBody: end fd=%d size=%d body_size=%d in.offset=%d cb=%p req=%p\n", conn->fd, size, conn->body.size_left, conn->in.offset, callback, request); return; } @@ -2878,7 +2877,7 @@ void clientReadBodyAbortHandler(char *buf, size_t size, void *data) { - ConnStateData *conn = (ConnStateData *)data; + ConnStateData *conn = (ConnStateData *) data; debug(33, 2) ("clientReadBodyAbortHandler: fd=%d body_size=%d in.offset=%d\n", conn->fd, conn->body.size_left, conn->in.offset); if (size != 0 && conn->body.size_left != 0) { debug(33, 3) ("clientReadBodyAbortHandler: fd=%d shedule next read\n", conn->fd); @@ -2888,10 +2887,10 @@ conn->body.cbdata = data; } } - + /* Abort a body request */ int -clientAbortBody(request_t *request) +clientAbortBody(request_t * request) { ConnStateData *conn = request->body_connection; char *buf; @@ -2899,7 +2898,7 @@ void *cbdata; request->body_connection = NULL; if (!conn || conn->body.size_left <= 0) - return 0; /* No body to abort */ + return 0; /* No body to abort */ if (conn->body.callback != NULL) { buf = conn->body.buf; callback = conn->body.callback; @@ -2909,12 +2908,12 @@ conn->body.callback = NULL; conn->body.cbdata = NULL; conn->body.request = NULL; - callback(buf, -1, cbdata); /* Signal abort to clientReadBody caller */ + callback(buf, -1, cbdata); /* Signal abort to clientReadBody caller */ requestUnlink(request); } - clientReadBodyAbortHandler(NULL, -1, conn); /* Install abort handler */ + clientReadBodyAbortHandler(NULL, -1, conn); /* Install abort handler */ /* clientProcessBody() */ - return 1; /* Aborted */ + return 1; /* Aborted */ } /* general lifetime handler for HTTP requests */ Index: squid/src/defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/defines.h,v retrieving revision 1.1.1.3.12.9.2.4 retrieving revision 1.1.1.3.12.9.2.5 diff -u -r1.1.1.3.12.9.2.4 -r1.1.1.3.12.9.2.5 --- squid/src/defines.h 7 Jan 2001 00:34:20 -0000 1.1.1.3.12.9.2.4 +++ squid/src/defines.h 7 Jan 2001 09:48:31 -0000 1.1.1.3.12.9.2.5 @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.1.1.3.12.9.2.4 2001/01/07 00:34:20 rbcollins Exp $ + * $Id: defines.h,v 1.1.1.3.12.9.2.5 2001/01/07 09:48:31 hno Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -134,7 +134,7 @@ #define AUTHENTICATE_AV_FACTOR 1000 /* AUTHENTICATION */ -#define NTLM_CHALLENGE_SZ 300 +#define NTLM_CHALLENGE_SZ 300 #define CONNECT_PORT 443 Index: squid/src/enums.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/enums.h,v retrieving revision 1.1.1.3.12.15.2.6 retrieving revision 1.1.1.3.12.15.2.7 diff -u -r1.1.1.3.12.15.2.6 -r1.1.1.3.12.15.2.7 --- squid/src/enums.h 7 Jan 2001 00:34:20 -0000 1.1.1.3.12.15.2.6 +++ squid/src/enums.h 7 Jan 2001 09:48:31 -0000 1.1.1.3.12.15.2.7 @@ -1,6 +1,6 @@ /* - * $Id: enums.h,v 1.1.1.3.12.15.2.6 2001/01/07 00:34:20 rbcollins Exp $ + * $Id: enums.h,v 1.1.1.3.12.15.2.7 2001/01/07 09:48:31 hno Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -498,10 +498,10 @@ } allow_t; typedef enum { - AUTH_UNKNOWN, /* default */ + AUTH_UNKNOWN, /* default */ AUTH_BASIC, AUTH_NTLM, - AUTH_BROKEN /* known type, but broken data */ + AUTH_BROKEN /* known type, but broken data */ } auth_type_t; typedef enum { @@ -510,7 +510,7 @@ AUTHENTICATE_STATE_CHALLENGE, AUTHENTICATE_STATE_RESPONSE, AUTHENTICATE_STATE_DONE -} auth_state_t; /* connection level auth state */ +} auth_state_t; /* connection level auth state */ /* stateful helper callback response codes */ typedef enum { @@ -522,9 +522,9 @@ /* stateful helper reservation info */ typedef enum { - S_HELPER_FREE, /* available for requests */ - S_HELPER_RESERVED, /* in a reserved state - no active request, but state data in the helper shouldn't be disturbed */ - S_HELPER_DEFERRED /* available for requests, and at least one more will come from a previous caller with the server pointer */ + S_HELPER_FREE, /* available for requests */ + S_HELPER_RESERVED, /* in a reserved state - no active request, but state data in the helper shouldn't be disturbed */ + S_HELPER_DEFERRED /* available for requests, and at least one more will come from a previous caller with the server pointer */ } stateful_helper_reserve_t; Index: squid/src/errorpage.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/errorpage.c,v retrieving revision 1.1.1.3.10.9.2.8 retrieving revision 1.1.1.3.10.9.2.9 diff -u -r1.1.1.3.10.9.2.8 -r1.1.1.3.10.9.2.9 --- squid/src/errorpage.c 5 Jan 2001 22:45:27 -0000 1.1.1.3.10.9.2.8 +++ squid/src/errorpage.c 7 Jan 2001 09:48:31 -0000 1.1.1.3.10.9.2.9 @@ -1,6 +1,6 @@ /* - * $Id: errorpage.c,v 1.1.1.3.10.9.2.8 2001/01/05 22:45:27 rbcollins Exp $ + * $Id: errorpage.c,v 1.1.1.3.10.9.2.9 2001/01/07 09:48:31 hno Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -372,7 +372,7 @@ safe_free(err->ftp.request); safe_free(err->ftp.reply); if (err->auth_user_request) - authenticateAuthUserRequestUnlock(err->auth_user_request); + authenticateAuthUserRequestUnlock(err->auth_user_request); cbdataFree(err); } Index: squid/src/ftp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ftp.c,v retrieving revision 1.1.1.3.4.1.2.8.2.3 retrieving revision 1.1.1.3.4.1.2.8.2.4 diff -u -r1.1.1.3.4.1.2.8.2.3 -r1.1.1.3.4.1.2.8.2.4 --- squid/src/ftp.c 7 Jan 2001 07:32:44 -0000 1.1.1.3.4.1.2.8.2.3 +++ squid/src/ftp.c 7 Jan 2001 09:48:31 -0000 1.1.1.3.4.1.2.8.2.4 @@ -1,6 +1,6 @@ /* - * $Id: ftp.c,v 1.1.1.3.4.1.2.8.2.3 2001/01/07 07:32:44 hno Exp $ + * $Id: ftp.c,v 1.1.1.3.4.1.2.8.2.4 2001/01/07 09:48:31 hno Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -1967,7 +1967,7 @@ */ commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL); commSetTimeout(ftpState->data.fd, Config.Timeout.read, ftpTimeout, - ftpState); + ftpState); ftpState->state = WRITING_DATA; debug(9, 3) ("ftpReadStor: writing data channel\n"); } else if (code == 150) { @@ -2180,8 +2180,8 @@ static void ftpRequestBody(char *buf, size_t size, void *data) { - FtpStateData *ftpState = (FtpStateData *)data; - debug(9, 3) ("ftpRequestBody: buf=%p size=%d ftpState=%p\n",buf,size,data); + FtpStateData *ftpState = (FtpStateData *) data; + debug(9, 3) ("ftpRequestBody: buf=%p size=%d ftpState=%p\n", buf, size, data); ftpState->data.offset = size; if (size > 0) { /* DataWrite */ @@ -2200,7 +2200,7 @@ static void ftpDataWriteCallback(int fd, char *buf, size_t size, int err, void *data) { - FtpStateData *ftpState = (FtpStateData *)data; + FtpStateData *ftpState = (FtpStateData *) data; if (!err) { /* Shedule the rest of the request */ clientReadBody(ftpState->request, ftpState->data.buf, ftpState->data.size, ftpRequestBody, ftpState); @@ -2213,7 +2213,7 @@ static void ftpDataWrite(int ftp, void *data) { - FtpStateData * ftpState = (FtpStateData *)data; + FtpStateData *ftpState = (FtpStateData *) data; debug(9, 3) ("ftpDataWrite\n"); /* This starts the body transfer */ clientReadBody(ftpState->request, ftpState->data.buf, ftpState->data.size, ftpRequestBody, ftpState); @@ -2230,7 +2230,7 @@ ftpFailed(ftpState, ERR_FTP_PUT_ERROR); return; } - storeTimestampsSet(ftpState->entry); /* XXX Is this needed? */ + storeTimestampsSet(ftpState->entry); /* XXX Is this needed? */ ftpSendReply(ftpState); } Index: squid/src/globals.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/globals.h,v retrieving revision 1.1.1.3.12.8.2.3 retrieving revision 1.1.1.3.12.8.2.4 diff -u -r1.1.1.3.12.8.2.3 -r1.1.1.3.12.8.2.4 --- squid/src/globals.h 2 Jan 2001 10:57:02 -0000 1.1.1.3.12.8.2.3 +++ squid/src/globals.h 7 Jan 2001 09:48:31 -0000 1.1.1.3.12.8.2.4 @@ -1,6 +1,6 @@ /* - * $Id: globals.h,v 1.1.1.3.12.8.2.3 2001/01/02 10:57:02 rbcollins Exp $ + * $Id: globals.h,v 1.1.1.3.12.8.2.4 2001/01/07 09:48:31 hno Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -145,7 +145,7 @@ extern request_flags null_request_flags; extern int store_open_disk_fd; /* 0 */ extern const char *SwapDirType[]; -extern authscheme_entry_t *authscheme_list; /* NULL */ +extern authscheme_entry_t *authscheme_list; /* NULL */ extern storefs_entry_t *storefs_list; /* NULL */ extern storerepl_entry_t *storerepl_list; /* NULL */ extern int store_swap_low; /* 0 */ @@ -153,4 +153,4 @@ extern int store_pages_max; /* 0 */ extern ssize_t store_maxobjsize; /* -1 */ extern RemovalPolicy *mem_policy; -extern hash_table *proxy_auth_username_cache; /* NULL */ +extern hash_table *proxy_auth_username_cache; /* NULL */ Index: squid/src/helper.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/helper.c,v retrieving revision 1.1.1.3.12.13.2.6 retrieving revision 1.1.1.3.12.13.2.7 diff -u -r1.1.1.3.12.13.2.6 -r1.1.1.3.12.13.2.7 --- squid/src/helper.c 5 Jan 2001 23:43:58 -0000 1.1.1.3.12.13.2.6 +++ squid/src/helper.c 7 Jan 2001 09:48:31 -0000 1.1.1.3.12.13.2.7 @@ -1,6 +1,6 @@ /* - * $Id: helper.c,v 1.1.1.3.12.13.2.6 2001/01/05 23:43:58 rbcollins Exp $ + * $Id: helper.c,v 1.1.1.3.12.13.2.7 2001/01/07 09:48:31 hno Exp $ * * DEBUG: section 29 Helper process maintenance * AUTHOR: Harvest Derived? @@ -53,7 +53,7 @@ static void helperRequestFree(helper_request * r); static void helperStatefulRequestFree(helper_stateful_request * r); static void StatefulEnqueue(statefulhelper * hlp, helper_stateful_request * r); -static helper_stateful_request * StatefulServerDequeue(helper_stateful_server * srv); +static helper_stateful_request *StatefulServerDequeue(helper_stateful_server * srv); static void StatefulServerEnqueue(helper_stateful_server * srv, helper_stateful_request * r); static void helperStatefulServerKickQueue(helper_stateful_server * srv); @@ -179,10 +179,10 @@ continue; } hlp->n_running++; - srv = CBDATA_ALLOC(helper_stateful_server, NULL); + srv = CBDATA_ALLOC(helper_stateful_server, NULL); srv->flags.alive = 1; - srv->flags.reserved = S_HELPER_FREE; - srv->deferred_requests=0; + srv->flags.reserved = S_HELPER_FREE; + srv->deferred_requests = 0; srv->index = k; srv->rfd = rfd; srv->wfd = wfd; @@ -190,8 +190,8 @@ srv->buf_sz = 8192; srv->offset = 0; srv->parent = hlp; - if (hlp->datapool != NULL) - srv->data = memPoolAlloc(hlp->datapool); + if (hlp->datapool != NULL) + srv->data = memPoolAlloc(hlp->datapool); cbdataLock(hlp); /* lock because of the parent backlink */ dlinkAddTail(srv, &srv->link, &hlp->servers); if (rfd == wfd) { @@ -232,7 +232,7 @@ helperDispatch(srv, r); else Enqueue(hlp, r); - debug(29,9) ("helperSubmit: %s\n",buf); + debug(29, 9) ("helperSubmit: %s\n", buf); } void @@ -242,134 +242,126 @@ helper_stateful_server *srv; if (hlp == NULL) { debug(29, 3) ("helperStatefulSubmit: hlp == NULL\n"); - callback(data,0, NULL); + callback(data, 0, NULL); return; } r->callback = callback; r->data = data; - if (buf != NULL) - r->buf = xstrdup(buf); + if (buf != NULL) + r->buf = xstrdup(buf); else - r->placeholder=1; + r->placeholder = 1; cbdataLock(r->data); - if ((buf != NULL) && lastserver){ - debug(29,5)("StatefulSubmit with lastserver %d\n",lastserver); - if (lastserver->flags.reserved!=S_HELPER_RESERVED) - lastserver->deferred_requests--; - if (!(lastserver->request)) { - debug(29,5)("StatefulSubmit dispatching\n"); - helperStatefulDispatch(lastserver, r); - } else { - debug(29,5)("StatefulSubmit queuing\n"); - StatefulServerEnqueue(lastserver, r); - } - } - else - { - if ((srv = StatefulGetFirstAvailable(hlp))){ - helperStatefulDispatch(srv, r); - } - else - StatefulEnqueue(hlp, r); + if ((buf != NULL) && lastserver) { + debug(29, 5) ("StatefulSubmit with lastserver %d\n", lastserver); + if (lastserver->flags.reserved != S_HELPER_RESERVED) + lastserver->deferred_requests--; + if (!(lastserver->request)) { + debug(29, 5) ("StatefulSubmit dispatching\n"); + helperStatefulDispatch(lastserver, r); + } else { + debug(29, 5) ("StatefulSubmit queuing\n"); + StatefulServerEnqueue(lastserver, r); + } + } else { + if ((srv = StatefulGetFirstAvailable(hlp))) { + helperStatefulDispatch(srv, r); + } else + StatefulEnqueue(hlp, r); } - debug(29,9) ("helperStatefulSubmit: placeholder: '%d', buf '%s'.\n",r->placeholder,buf); + debug(29, 9) ("helperStatefulSubmit: placeholder: '%d', buf '%s'.\n", r->placeholder, buf); } helper_stateful_server * -helperStatefulDefer(statefulhelper *hlp) +helperStatefulDefer(statefulhelper * hlp) /* find and add a deferred request to a server */ { dlink_node *n; helper_stateful_server *srv = NULL, *rv = NULL; if (hlp == NULL) { - debug(29, 3) ("helperStatefulReserve: hlp == NULL\n"); - return NULL; + debug(29, 3) ("helperStatefulReserve: hlp == NULL\n"); + return NULL; } - debug(29,5)("helperStatefulDefer: Running servers %d.\n",hlp->n_running); - if (hlp->n_running == 0) - { - debug(29,1)("helperStatefulDefer: No running servers!. \n"); - return NULL; + debug(29, 5) ("helperStatefulDefer: Running servers %d.\n", hlp->n_running); + if (hlp->n_running == 0) { + debug(29, 1) ("helperStatefulDefer: No running servers!. \n"); + return NULL; } - srv = StatefulGetFirstAvailable(hlp); /* all currently busy:loop through servers and find server with the shortest queue */ rv = srv; if (rv == NULL) - for (n = hlp->servers.head; n != NULL; n = n->next) { - srv = n->data; - if (srv->flags.reserved==S_HELPER_RESERVED) - continue; - if (!srv->flags.alive) - continue; - if ((hlp->IsAvailable != NULL) && (srv->data != NULL) && - !(hlp->IsAvailable(srv->data))) - continue; - if ((rv != NULL) && (rv->deferred_requestsdeferred_requests)) - continue; - rv = srv; - } - if (rv == NULL) - { - debug(29,1)("helperStatefulDefer: None available.\n"); - return NULL; + for (n = hlp->servers.head; n != NULL; n = n->next) { + srv = n->data; + if (srv->flags.reserved == S_HELPER_RESERVED) + continue; + if (!srv->flags.alive) + continue; + if ((hlp->IsAvailable != NULL) && (srv->data != NULL) && + !(hlp->IsAvailable(srv->data))) + continue; + if ((rv != NULL) && (rv->deferred_requests < srv->deferred_requests)) + continue; + rv = srv; + } + if (rv == NULL) { + debug(29, 1) ("helperStatefulDefer: None available.\n"); + return NULL; } - - rv->flags.reserved=S_HELPER_DEFERRED; + rv->flags.reserved = S_HELPER_DEFERRED; rv->deferred_requests++; return rv; } -void +void helperStatefulReset(helper_stateful_server * srv) /* puts this helper back in the queue. the calling app is required to * manage the state in the helper. */ { - statefulhelper * hlp = srv->parent; - helper_stateful_request * r; + statefulhelper *hlp = srv->parent; + helper_stateful_request *r; r = srv->request; if (r != NULL) { - /* reset attempt DURING an outstaning request */ - debug(29, 1) ("helperStatefulReset: RESET During request %s \n", - hlp->id_name); - srv->flags.busy = 0; - srv->offset = 0; - helperStatefulRequestFree(r); - srv->request = NULL; - } - debug(29,1)("helperStatefulReset reset helper %s #%d\n",hlp->id_name,srv->index+1); + /* reset attempt DURING an outstaning request */ + debug(29, 1) ("helperStatefulReset: RESET During request %s \n", + hlp->id_name); + srv->flags.busy = 0; + srv->offset = 0; + helperStatefulRequestFree(r); + srv->request = NULL; + } + debug(29, 1) ("helperStatefulReset reset helper %s #%d\n", hlp->id_name, srv->index + 1); srv->flags.busy = 0; - if (srv->queue.head){ - srv->flags.reserved=S_HELPER_DEFERRED; - helperStatefulServerKickQueue(srv); - }else{ - srv->flags.reserved=S_HELPER_FREE; - if ((srv->parent->OnEmptyQueue != NULL) && (srv->data)) - srv->parent->OnEmptyQueue(srv->data); - helperStatefulKickQueue(hlp); + if (srv->queue.head) { + srv->flags.reserved = S_HELPER_DEFERRED; + helperStatefulServerKickQueue(srv); + } else { + srv->flags.reserved = S_HELPER_FREE; + if ((srv->parent->OnEmptyQueue != NULL) && (srv->data)) + srv->parent->OnEmptyQueue(srv->data); + helperStatefulKickQueue(hlp); } } void helperStatefulReleaseServer(helper_stateful_server * srv) -/*decrease the number of 'waiting' clients that set the helper to be DEFERRED*/ +/*decrease the number of 'waiting' clients that set the helper to be DEFERRED */ { - if (srv->deferred_requests>0) - srv->deferred_requests--; - if (!(srv->deferred_requests) && (srv->flags.reserved==S_HELPER_DEFERRED) && !(srv->queue.head)) - { - srv->flags.reserved=S_HELPER_FREE; - if ((srv->parent->OnEmptyQueue != NULL) && (srv->data)) - srv->parent->OnEmptyQueue(srv->data); - } + if (srv->deferred_requests > 0) + srv->deferred_requests--; + if (!(srv->deferred_requests) && (srv->flags.reserved == S_HELPER_DEFERRED) && !(srv->queue.head)) { + srv->flags.reserved = S_HELPER_FREE; + if ((srv->parent->OnEmptyQueue != NULL) && (srv->data)) + srv->parent->OnEmptyQueue(srv->data); + } } void * helperStatefulServerGetData(helper_stateful_server * srv) /* return a pointer to the stateful routines data area */ { - return srv->data; + return srv->data; } void @@ -426,41 +418,41 @@ dlink_node *link; double tt; storeAppendPrintf(sentry, "number running: %d of %d\n", - hlp->n_running, hlp->n_to_start); + hlp->n_running, hlp->n_to_start); storeAppendPrintf(sentry, "requests sent: %d\n", - hlp->stats.requests); + hlp->stats.requests); storeAppendPrintf(sentry, "replies received: %d\n", - hlp->stats.replies); + hlp->stats.replies); storeAppendPrintf(sentry, "queue length: %d\n", - hlp->stats.queue_size); + hlp->stats.queue_size); storeAppendPrintf(sentry, "avg service time: %d msec\n", - hlp->stats.avg_svc_time); + hlp->stats.avg_svc_time); storeAppendPrintf(sentry, "\n"); storeAppendPrintf(sentry, "%7s\t%7s\t%11s\t%s\t%7s\t%7s\t%7s\n", - "#", - "FD", - "# Requests", - "# Deferred Requests", - "Flags", - "Time", - "Offset", - "Request"); + "#", + "FD", + "# Requests", + "# Deferred Requests", + "Flags", + "Time", + "Offset", + "Request"); for (link = hlp->servers.head; link; link = link->next) { - srv = link->data; - tt = 0.001 * tvSubMsec(srv->dispatch_time, current_time); - storeAppendPrintf(sentry, "%7d\t%7d\t%11d\t%11d\t%c%c%c%c%c\t%7.3f\t%7d\t%s\n", - srv->index + 1, - srv->rfd, - srv->stats.uses, - srv->deferred_requests, - srv->flags.alive ? 'A' : ' ', - srv->flags.busy ? 'B' : ' ', - srv->flags.closing ? 'C' : ' ', - srv->flags.reserved!=S_HELPER_FREE ? 'R': ' ', - srv->flags.shutdown ? 'S' : ' ', - tt < 0.0 ? 0.0 : tt, - (int) srv->offset, - srv->request ? log_quote(srv->request->buf) : "(none)"); + srv = link->data; + tt = 0.001 * tvSubMsec(srv->dispatch_time, current_time); + storeAppendPrintf(sentry, "%7d\t%7d\t%11d\t%11d\t%c%c%c%c%c\t%7.3f\t%7d\t%s\n", + srv->index + 1, + srv->rfd, + srv->stats.uses, + srv->deferred_requests, + srv->flags.alive ? 'A' : ' ', + srv->flags.busy ? 'B' : ' ', + srv->flags.closing ? 'C' : ' ', + srv->flags.reserved != S_HELPER_FREE ? 'R' : ' ', + srv->flags.shutdown ? 'S' : ' ', + tt < 0.0 ? 0.0 : tt, + (int) srv->offset, + srv->request ? log_quote(srv->request->buf) : "(none)"); } storeAppendPrintf(sentry, "\nFlags key:\n\n"); storeAppendPrintf(sentry, " A = ALIVE\n"); @@ -524,16 +516,16 @@ hlp->id_name, srv->index + 1); continue; } - if (srv->flags.reserved!=S_HELPER_FREE) { - debug(34, 3) ("helperStatefulShutdown: %s #%d is RESERVED.\n", - hlp->id_name, srv->index + 1); - continue; - } - if (srv->deferred_requests) { - debug(34, 3) ("helperStatefulShutdown: %s #%d has DEFERRED requests.\n", - hlp->id_name, srv->index + 1); - continue; - } + if (srv->flags.reserved != S_HELPER_FREE) { + debug(34, 3) ("helperStatefulShutdown: %s #%d is RESERVED.\n", + hlp->id_name, srv->index + 1); + continue; + } + if (srv->deferred_requests) { + debug(34, 3) ("helperStatefulShutdown: %s #%d has DEFERRED requests.\n", + hlp->id_name, srv->index + 1); + continue; + } srv->flags.closing = 1; comm_close(srv->wfd); srv->wfd = -1; @@ -630,7 +622,7 @@ } if ((r = srv->request)) { if (cbdataValid(r->data)) - r->callback(r->data, srv,srv->buf); + r->callback(r->data, srv, srv->buf); helperStatefulRequestFree(r); srv->request = NULL; } @@ -646,7 +638,7 @@ fatalf("Too few %s processes are running", hlp->id_name); } if (srv->data != NULL) - memPoolFree(hlp->datapool,srv->data); + memPoolFree(hlp->datapool, srv->data); cbdataUnlock(srv->parent); cbdataFree(srv); } @@ -739,46 +731,46 @@ /* end of reply found */ debug(29, 3) ("helperStatefulHandleRead: end of reply found\n"); *t = '\0'; - if (cbdataValid(r->data)){ - switch((r->callback(r->data,srv, srv->buf))){ /*if non-zero reserve helper */ - case S_HELPER_UNKNOWN: - fatal("helperStatefulHandleRead: either a non-state aware callback was give to the stateful helper routines, or an uninitialised callback response was recieved.\n"); - break; - case S_HELPER_RELEASE: /* helper finished with */ - if (!srv->queue.head){ - srv->flags.reserved = S_HELPER_FREE; - if ((srv->parent->OnEmptyQueue != NULL) && (srv->data)) - srv->parent->OnEmptyQueue(srv->data); - debug(29, 5)("StatefulHandleRead: releasing %s #%d\n",hlp->id_name, srv->index+1); - }else{ - srv->flags.reserved = S_HELPER_DEFERRED; - debug(29, 5)("StatefulHandleRead: outstanding deferred requests on %s #%d. reserving for deferred requests.\n",hlp->id_name, srv->index+1); - } - break; - case S_HELPER_RESERVE: /* 'pin' this helper for the caller */ - if (!srv->queue.head){ - srv->flags.reserved = S_HELPER_RESERVED; - debug(29, 5)("StatefulHandleRead: reserving %s #%d\n",hlp->id_name, srv->index+1); - }else{ - fatal("StatefulHandleRead: Callback routine attempted to reserve a stateful helper with deferred requests. This can lead to deadlock.\n"); - } - break; - case S_HELPER_DEFER: - /* the helper is still needed, but can - * be used for other requests in the meantime. - */ - srv->flags.reserved = S_HELPER_DEFERRED; - srv->deferred_requests++; - debug(29, 5)("StatefulHandleRead: reserving %s #%d for deferred requests.\n",hlp->id_name, srv->index+1); - break; - default: - fatal("helperStatefulHandleRead: unknown stateful helper callback result.\n"); - } - - } - else - {debug(29,1)("StatefulHandleRead: no callback data registered\n");} - srv->flags.busy = 0; + if (cbdataValid(r->data)) { + switch ((r->callback(r->data, srv, srv->buf))) { /*if non-zero reserve helper */ + case S_HELPER_UNKNOWN: + fatal("helperStatefulHandleRead: either a non-state aware callback was give to the stateful helper routines, or an uninitialised callback response was recieved.\n"); + break; + case S_HELPER_RELEASE: /* helper finished with */ + if (!srv->queue.head) { + srv->flags.reserved = S_HELPER_FREE; + if ((srv->parent->OnEmptyQueue != NULL) && (srv->data)) + srv->parent->OnEmptyQueue(srv->data); + debug(29, 5) ("StatefulHandleRead: releasing %s #%d\n", hlp->id_name, srv->index + 1); + } else { + srv->flags.reserved = S_HELPER_DEFERRED; + debug(29, 5) ("StatefulHandleRead: outstanding deferred requests on %s #%d. reserving for deferred requests.\n", hlp->id_name, srv->index + 1); + } + break; + case S_HELPER_RESERVE: /* 'pin' this helper for the caller */ + if (!srv->queue.head) { + srv->flags.reserved = S_HELPER_RESERVED; + debug(29, 5) ("StatefulHandleRead: reserving %s #%d\n", hlp->id_name, srv->index + 1); + } else { + fatal("StatefulHandleRead: Callback routine attempted to reserve a stateful helper with deferred requests. This can lead to deadlock.\n"); + } + break; + case S_HELPER_DEFER: + /* the helper is still needed, but can + * be used for other requests in the meantime. + */ + srv->flags.reserved = S_HELPER_DEFERRED; + srv->deferred_requests++; + debug(29, 5) ("StatefulHandleRead: reserving %s #%d for deferred requests.\n", hlp->id_name, srv->index + 1); + break; + default: + fatal("helperStatefulHandleRead: unknown stateful helper callback result.\n"); + } + + } else { + debug(29, 1) ("StatefulHandleRead: no callback data registered\n"); + } + srv->flags.busy = 0; srv->offset = 0; helperStatefulRequestFree(r); srv->request = NULL; @@ -791,11 +783,11 @@ comm_close(srv->wfd); srv->wfd = -1; } else { - if (srv->queue.head) - helperStatefulServerKickQueue(srv); - else - helperStatefulKickQueue(hlp); - } + if (srv->queue.head) + helperStatefulServerKickQueue(srv); + else + helperStatefulKickQueue(hlp); + } } else { commSetSelect(srv->rfd, COMM_SELECT_READ, helperStatefulHandleRead, srv, 0); } @@ -841,24 +833,24 @@ debug(14, 1) ("Consider increasing the number of %s processes in your config file.\n", hlp->id_name); } -static void +static void StatefulServerEnqueue(helper_stateful_server * srv, helper_stateful_request * r) { dlink_node *link = memAllocate(MEM_DLINK_NODE); dlinkAddTail(r, link, &srv->queue); /* hlp->stats.queue_size++; - if (hlp->stats.queue_size < hlp->n_running) - return; - if (squid_curtime - hlp->last_queue_warn < 600) - return; - if (shutting_down || reconfiguring) - return; - hlp->last_queue_warn = squid_curtime; - debug(14, 0) ("WARNING: All %s processes are busy.\n", hlp->id_name); - debug(14, 0) ("WARNING: %d pending requests queued\n", hlp->stats.queue_size); - if (hlp->stats.queue_size > hlp->n_running * 2) - fatalf("Too many queued %s requests", hlp->id_name); - debug(14, 1) ("Consider increasing the number of %s processes in your config file.\n", hlp->id_name); */ + * if (hlp->stats.queue_size < hlp->n_running) + * return; + * if (squid_curtime - hlp->last_queue_warn < 600) + * return; + * if (shutting_down || reconfiguring) + * return; + * hlp->last_queue_warn = squid_curtime; + * debug(14, 0) ("WARNING: All %s processes are busy.\n", hlp->id_name); + * debug(14, 0) ("WARNING: %d pending requests queued\n", hlp->stats.queue_size); + * if (hlp->stats.queue_size > hlp->n_running * 2) + * fatalf("Too many queued %s requests", hlp->id_name); + * debug(14, 1) ("Consider increasing the number of %s processes in your config file.\n", hlp->id_name); */ } @@ -885,7 +877,7 @@ r = link->data; dlinkDelete(link, &srv->queue); memFree(link, MEM_DLINK_NODE); -// hlp->stats.queue_size--; +// hlp->stats.queue_size--; } return r; } @@ -896,10 +888,10 @@ dlink_node *link; helper_stateful_request *r = NULL; if ((link = hlp->queue.head)) { - r = link->data; - dlinkDelete(link, &hlp->queue); - memFree(link, MEM_DLINK_NODE); - hlp->stats.queue_size--; + r = link->data; + dlinkDelete(link, &hlp->queue); + memFree(link, MEM_DLINK_NODE); + hlp->stats.queue_size--; } return r; } @@ -927,22 +919,22 @@ { dlink_node *n; helper_stateful_server *srv = NULL; - debug(29,5)("StatefulGetFirstAvailable: Running servers %d.\n",hlp->n_running); + debug(29, 5) ("StatefulGetFirstAvailable: Running servers %d.\n", hlp->n_running); if (hlp->n_running == 0) return NULL; for (n = hlp->servers.head; n != NULL; n = n->next) { srv = n->data; if (srv->flags.busy) continue; - if (srv->flags.reserved==S_HELPER_RESERVED) - continue; + if (srv->flags.reserved == S_HELPER_RESERVED) + continue; if (!srv->flags.alive) continue; - if ((hlp->IsAvailable != NULL) && (srv->data != NULL) && !(hlp->IsAvailable(srv->data))) - continue; - return srv; + if ((hlp->IsAvailable != NULL) && (srv->data != NULL) && !(hlp->IsAvailable(srv->data))) + continue; + return srv; } - debug(29,5)("StatefulGetFirstAvailable: None available.\n"); + debug(29, 5) ("StatefulGetFirstAvailable: None available.\n"); return NULL; } @@ -980,40 +972,35 @@ helperStatefulDispatch(helper_stateful_server * srv, helper_stateful_request * r) { statefulhelper *hlp = srv->parent; - if (!cbdataValid(r->data)) { + if (!cbdataValid(r->data)) { debug(29, 1) ("helperStatefulDispatch: invalid callback data\n"); helperStatefulRequestFree(r); return; } - debug(29,9)("helperStatefulDispatch busying helper %s #%d\n",hlp->id_name,srv->index+1); - if (r->placeholder==1) - { - /* a callback is needed before this request can _use_ a helper. */ - if (cbdataValid(r->data)){ - /* we don't care about releasing/deferring this helper. The request NEVER - * gets to the helper. So we throw away the return code */ - r->callback(r->data, srv, NULL); - /* throw away the placeholder */ - helperStatefulRequestFree(r); - /* and push the queue. Note that the callback may have call submit again - - * which is why we test for the request*/ - if (srv->request == NULL) - { - if (srv->flags.shutdown) - { - comm_close(srv->wfd); - srv->wfd = -1; - } - else - { - if (srv->queue.head) - helperStatefulServerKickQueue(srv); - else - helperStatefulKickQueue(hlp); - } - } - } - return; + debug(29, 9) ("helperStatefulDispatch busying helper %s #%d\n", hlp->id_name, srv->index + 1); + if (r->placeholder == 1) { + /* a callback is needed before this request can _use_ a helper. */ + if (cbdataValid(r->data)) { + /* we don't care about releasing/deferring this helper. The request NEVER + * gets to the helper. So we throw away the return code */ + r->callback(r->data, srv, NULL); + /* throw away the placeholder */ + helperStatefulRequestFree(r); + /* and push the queue. Note that the callback may have call submit again - + * which is why we test for the request*/ + if (srv->request == NULL) { + if (srv->flags.shutdown) { + comm_close(srv->wfd); + srv->wfd = -1; + } else { + if (srv->queue.head) + helperStatefulServerKickQueue(srv); + else + helperStatefulKickQueue(hlp); + } + } + } + return; } srv->flags.busy = 1; srv->request = r; @@ -1058,7 +1045,7 @@ { helper_stateful_request *r; if ((r = StatefulServerDequeue(srv))) - helperStatefulDispatch(srv, r); + helperStatefulDispatch(srv, r); } static void Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.1.1.3.4.1.2.10.2.5 retrieving revision 1.1.1.3.4.1.2.10.2.6 diff -u -r1.1.1.3.4.1.2.10.2.5 -r1.1.1.3.4.1.2.10.2.6 --- squid/src/http.c 7 Jan 2001 00:37:02 -0000 1.1.1.3.4.1.2.10.2.5 +++ squid/src/http.c 7 Jan 2001 09:48:31 -0000 1.1.1.3.4.1.2.10.2.6 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.1.1.3.4.1.2.10.2.5 2001/01/07 00:37:02 hno Exp $ + * $Id: http.c,v 1.1.1.3.4.1.2.10.2.6 2001/01/07 09:48:31 hno Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -693,7 +693,7 @@ * authentication forwarding is explicitly enabled */ if (request->flags.proxying && orig_request->peer_login && - strcmp(orig_request->peer_login, "PASS") == 0) { + strcmp(orig_request->peer_login, "PASS") == 0) { httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); } break; @@ -791,7 +791,7 @@ /* append Proxy-Authorization if configured for peer, and proxying */ if (!httpHeaderHas(hdr_out, HDR_PROXY_AUTHORIZATION)) { if (request->flags.proxying && orig_request->peer_login && - strcmp(orig_request->peer_login, "PASS") != 0) { + strcmp(orig_request->peer_login, "PASS") != 0) { httpHeaderPutStrf(hdr_out, HDR_PROXY_AUTHORIZATION, "Basic %s", base64_encode(orig_request->peer_login)); } @@ -879,7 +879,7 @@ cfd = entry->mem_obj->fd; assert(-1 == cfd || FD_SOCKET == fd_table[cfd].type); if (p != NULL) - httpState->flags.proxying = (p != NULL); + httpState->flags.proxying = (p != NULL); /* * Is keep-alive okay for all request methods? */ @@ -987,8 +987,8 @@ static void httpRequestBodyHandler(char *buf, size_t size, void *data) { - HttpStateData *httpState = (HttpStateData *)data; - if ( size > 0 ) { + HttpStateData *httpState = (HttpStateData *) data; + if (size > 0) { comm_write(httpState->fd, buf, size, httpSendRequestEntry, data, memFree8K); } else if (size == 0) { /* End of body */ Index: squid/src/main.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/main.c,v retrieving revision 1.1.1.3.4.1.2.12.2.5 retrieving revision 1.1.1.3.4.1.2.12.2.6 diff -u -r1.1.1.3.4.1.2.12.2.5 -r1.1.1.3.4.1.2.12.2.6 --- squid/src/main.c 5 Jan 2001 22:45:27 -0000 1.1.1.3.4.1.2.12.2.5 +++ squid/src/main.c 7 Jan 2001 09:48:31 -0000 1.1.1.3.4.1.2.12.2.6 @@ -1,6 +1,6 @@ /* - * $Id: main.c,v 1.1.1.3.4.1.2.12.2.5 2001/01/05 22:45:27 rbcollins Exp $ + * $Id: main.c,v 1.1.1.3.4.1.2.12.2.6 2001/01/07 09:48:31 hno Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -349,7 +349,7 @@ parseConfigFile(ConfigFile); _db_init(Config.Log.log, Config.debugOptions); ipcache_restart(); /* clear stuck entries */ - authenticateUserCacheRestart(); /* clear stuck ACL entries */ + authenticateUserCacheRestart(); /* clear stuck ACL entries */ fqdncache_restart(); /* sigh, fqdncache too */ parseEtcHosts(); errorInitialize(); /* reload error pages */ @@ -633,7 +633,7 @@ cbdataInit(); eventInit(); /* eventInit() is required for config parsing */ storeFsInit(); /* required for config parsing */ - authenticateSchemeInit(); /* required for config parsign */ + authenticateSchemeInit(); /* required for config parsign */ parse_err = parseConfigFile(ConfigFile); if (opt_parse_cfg_only) Index: squid/src/mem.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/mem.c,v retrieving revision 1.1.1.3.12.9.2.2 retrieving revision 1.1.1.3.12.9.2.3 diff -u -r1.1.1.3.12.9.2.2 -r1.1.1.3.12.9.2.3 --- squid/src/mem.c 7 Jan 2001 00:24:26 -0000 1.1.1.3.12.9.2.2 +++ squid/src/mem.c 7 Jan 2001 09:48:31 -0000 1.1.1.3.12.9.2.3 @@ -1,6 +1,6 @@ /* - * $Id: mem.c,v 1.1.1.3.12.9.2.2 2001/01/07 00:24:26 rbcollins Exp $ + * $Id: mem.c,v 1.1.1.3.12.9.2.3 2001/01/07 09:48:31 hno Exp $ * * DEBUG: section 13 High Level Memory Pool Management * AUTHOR: Harvest Derived @@ -211,9 +211,9 @@ sizeof(acl_proxy_auth_data), 0); #endif memDataInit(MEM_AUTH_USER_HASH, "auth_user_hash_pointer", - sizeof(auth_user_hash_pointer),0); + sizeof(auth_user_hash_pointer), 0); memDataInit(MEM_ACL_PROXY_AUTH_MATCH, "acl_proxy_auth_match_cache", - sizeof(acl_proxy_auth_match_cache),0); + sizeof(acl_proxy_auth_match_cache), 0); memDataInit(MEM_CACHEMGR_PASSWD, "cachemgr_passwd", sizeof(cachemgr_passwd), 0); #if USE_CACHE_DIGESTS Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.1.1.3.12.17.2.20 retrieving revision 1.1.1.3.12.17.2.21 diff -u -r1.1.1.3.12.17.2.20 -r1.1.1.3.12.17.2.21 --- squid/src/protos.h 5 Jan 2001 22:45:28 -0000 1.1.1.3.12.17.2.20 +++ squid/src/protos.h 7 Jan 2001 09:48:31 -0000 1.1.1.3.12.17.2.21 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.1.1.3.12.17.2.20 2001/01/05 22:45:28 rbcollins Exp $ + * $Id: protos.h,v 1.1.1.3.12.17.2.21 2001/01/07 09:48:31 hno Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -131,8 +131,8 @@ extern void clientHttpConnectionsClose(void); extern StoreEntry *clientCreateStoreEntry(clientHttpRequest *, method_t, request_flags); extern int isTcpHit(log_type); -extern void clientReadBody(request_t *req, char *buf, size_t size, CBCB *callback, void *data); -extern int clientAbortBody(request_t *req); +extern void clientReadBody(request_t * req, char *buf, size_t size, CBCB * callback, void *data); +extern int clientAbortBody(request_t * req); extern int commSetNonBlocking(int fd); extern int commUnsetNonBlocking(int fd); @@ -723,7 +723,7 @@ /* authenticate.c */ extern void authenticateAuthUserMerge(auth_user_t *, auth_user_t *); extern auth_user_t *authenticateAuthUserNew(const char *); -extern int authenticateAuthSchemeId(const char *typestr); +extern int authenticateAuthSchemeId(const char *typestr); extern void authenticateStart(auth_user_request_t *, RH *, void *); extern void authenticateSchemeInit(void); extern void authenticateInit(authConfig *); @@ -732,32 +732,32 @@ extern void authenticateAddTrailer(HttpReply *, auth_user_request_t *, request_t *, int); extern auth_user_request_t *authenticateGetAuthUser(const char *proxy_auth); extern void authenticateAuthenticateUser(auth_user_request_t *, request_t *, ConnStateData *, http_hdr_type); -extern void authenticateAuthUserUnlock(auth_user_t *auth_user); -extern void authenticateAuthUserLock(auth_user_t *auth_user); -extern void authenticateAuthUserRequestUnlock(auth_user_request_t *); -extern void authenticateAuthUserRequestLock(auth_user_request_t *); +extern void authenticateAuthUserUnlock(auth_user_t * auth_user); +extern void authenticateAuthUserLock(auth_user_t * auth_user); +extern void authenticateAuthUserRequestUnlock(auth_user_request_t *); +extern void authenticateAuthUserRequestLock(auth_user_request_t *); extern char *authenticateAuthUserRequestMessage(auth_user_request_t *); -extern int authenticateAuthUserInuse(auth_user_t *auth_user); -extern void authenticateAuthUserRequestSetIp(auth_user_request_t *, struct in_addr); -extern int authenticateDirection(auth_user_request_t *); -extern FREE authenticateFreeProxyAuthUser; -extern void authenticateFreeProxyAuthUserACLResults(void *data); -extern void authenticateProxyUserCacheCleanup(void *); -extern void authenticateInitUserCache(); +extern int authenticateAuthUserInuse(auth_user_t * auth_user); +extern void authenticateAuthUserRequestSetIp(auth_user_request_t *, struct in_addr); +extern int authenticateDirection(auth_user_request_t *); +extern FREE authenticateFreeProxyAuthUser; +extern void authenticateFreeProxyAuthUserACLResults(void *data); +extern void authenticateProxyUserCacheCleanup(void *); +extern void authenticateInitUserCache(); #if 0 -extern void authenticateProxyAuthCacheAddLink(const char *key, auth_user_t *); +extern void authenticateProxyAuthCacheAddLink(const char *key, auth_user_t *); #endif -extern int authenticateActiveSchemeCount(); -extern int authenticateSchemeCount(); -extern void authenticateUserNameCacheAdd(auth_user_t *auth_user); -extern int authenticateCheckAuthUserIP(struct in_addr request_src_addr, auth_user_request_t * auth_user); -extern int authenticateUserAuthenticated(auth_user_request_t *); -extern void authenticateUserCacheRestart(); +extern int authenticateActiveSchemeCount(); +extern int authenticateSchemeCount(); +extern void authenticateUserNameCacheAdd(auth_user_t * auth_user); +extern int authenticateCheckAuthUserIP(struct in_addr request_src_addr, auth_user_request_t * auth_user); +extern int authenticateUserAuthenticated(auth_user_request_t *); +extern void authenticateUserCacheRestart(); extern char *authenticateUserUsername(auth_user_t *); extern char *authenticateUserRequestUsername(auth_user_request_t *); -extern int authenticateValidateUser(auth_user_request_t *); -extern void authenticateOnCloseConnection(ConnStateData *conn); -extern void authSchemeAdd(char *type, AUTHSSETUP * setup); +extern int authenticateValidateUser(auth_user_request_t *); +extern void authenticateOnCloseConnection(ConnStateData * conn); +extern void authSchemeAdd(char *type, AUTHSSETUP * setup); extern void refreshAddToList(const char *, int, time_t, int, time_t); extern int refreshIsCachable(const StoreEntry *); Index: squid/src/redirect.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/redirect.c,v retrieving revision 1.1.1.3.4.1.2.2.2.3 retrieving revision 1.1.1.3.4.1.2.2.2.4 diff -u -r1.1.1.3.4.1.2.2.2.3 -r1.1.1.3.4.1.2.2.2.4 --- squid/src/redirect.c 5 Jan 2001 22:45:28 -0000 1.1.1.3.4.1.2.2.2.3 +++ squid/src/redirect.c 7 Jan 2001 09:48:31 -0000 1.1.1.3.4.1.2.2.2.4 @@ -1,6 +1,6 @@ /* - * $Id: redirect.c,v 1.1.1.3.4.1.2.2.2.3 2001/01/05 22:45:28 rbcollins Exp $ + * $Id: redirect.c,v 1.1.1.3.4.1.2.2.2.4 2001/01/07 09:48:31 hno Exp $ * * DEBUG: section 29 Redirector * AUTHOR: Duane Wessels @@ -131,8 +131,8 @@ r->client_ident = http->request->authuser; #endif if (http->request->auth_user_request) - r->client_ident = authenticateUserRequestUsername(http->request->auth_user_request); - else if (conn->rfc931[0]) { + r->client_ident = authenticateUserRequestUsername(http->request->auth_user_request); + else if (conn->rfc931[0]) { r->client_ident = conn->rfc931; } else { r->client_ident = dash_str; Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.1.1.3.4.1.2.26.2.25 retrieving revision 1.1.1.3.4.1.2.26.2.26 diff -u -r1.1.1.3.4.1.2.26.2.25 -r1.1.1.3.4.1.2.26.2.26 --- squid/src/structs.h 7 Jan 2001 00:37:02 -0000 1.1.1.3.4.1.2.26.2.25 +++ squid/src/structs.h 7 Jan 2001 09:48:31 -0000 1.1.1.3.4.1.2.26.2.26 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.1.1.3.4.1.2.26.2.25 2001/01/07 00:37:02 hno Exp $ + * $Id: structs.h,v 1.1.1.3.4.1.2.26.2.26 2001/01/07 09:48:31 hno Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -61,6 +61,7 @@ auth_type_t type; wordlist *names; }; + #endif struct _acl_name_list { @@ -79,7 +80,7 @@ char *key; auth_user_hash_pointer *next; auth_user_t *auth_user; - dlink_node link; /* other hash entries that point to the same auth_user */ + dlink_node link; /* other hash entries that point to the same auth_user */ }; struct _auth_user_t { @@ -87,20 +88,20 @@ /* this determines what scheme owns the user data. */ auth_type_t auth_type; /* the index +1 in the authscheme_list to the authscheme entry */ - int auth_module; + int auth_module; /* we only have one username associated with a given auth_user struct */ auth_user_hash_pointer *usernamehash; - /* we may have many proxy-authenticate strings that decode to the same user*/ + /* we may have many proxy-authenticate strings that decode to the same user */ dlink_list proxy_auth_list; dlink_list proxy_match_cache; struct { - unsigned int credentials_ok:2; /*0=unchecked,1=ok,2=failed*/ + unsigned int credentials_ok:2; /*0=unchecked,1=ok,2=failed */ } flags; long expiretime; /* IP addr this user authenticated from */ struct in_addr ipaddr; time_t ip_expiretime; - /* how many references are outstanding to this instance*/ + /* how many references are outstanding to this instance */ size_t references; /* the auth scheme has it's own private data area */ void *scheme_data; @@ -129,25 +130,25 @@ struct _authscheme_entry { char *typestr; - AUTHSACTIVE *Active; + AUTHSACTIVE *Active; AUTHSADDHEADER *AddHeader; AUTHSADDTRAILER *AddTrailer; - AUTHSAUTHED *authenticated; + AUTHSAUTHED *authenticated; AUTHSAUTHUSER *authAuthenticate; - AUTHSDUMP *dump; - AUTHSFIXERR *authFixHeader; - AUTHSFREE *FreeUser; + AUTHSDUMP *dump; + AUTHSFIXERR *authFixHeader; + AUTHSFREE *FreeUser; AUTHSFREECONFIG *freeconfig; AUTHSUSERNAME *authUserUsername; - AUTHSONCLOSEC *oncloseconnection; /*optional*/ - AUTHSDECODE *decodeauth; + AUTHSONCLOSEC *oncloseconnection; /*optional */ + AUTHSDECODE *decodeauth; AUTHSDIRECTION *getdirection; - AUTHSPARSE *parse; - AUTHSINIT *init; - AUTHSREQFREE *requestFree; + AUTHSPARSE *parse; + AUTHSINIT *init; + AUTHSREQFREE *requestFree; AUTHSSHUTDOWN *donefunc; - AUTHSSTART *authStart; - AUTHSSTATS *authStats; + AUTHSSTART *authStart; + AUTHSSTATS *authStats; }; /* @@ -241,7 +242,7 @@ struct in_addr my_addr; unsigned short my_port; request_t *request; - ConnStateData *conn; /* hack for ident and NTLM*/ + ConnStateData *conn; /* hack for ident and NTLM */ char rfc931[USER_IDENT_SZ]; auth_user_request_t *auth_user_request; acl_lookup_state state[ACL_ENUM_MAX]; @@ -549,10 +550,10 @@ } accessList; acl_deny_info_list *denyInfoList; struct _authConfig { - authScheme *schemes; - int n_allocated; - int n_configured; - } authConfig; + authScheme *schemes; + int n_allocated; + int n_configured; + } authConfig; struct { size_t list_width; int list_wrap; @@ -959,7 +960,7 @@ log_type code; int msec; const char *rfc931; - const char *authuser; + const char *authuser; } cache; struct { char *request; @@ -1016,15 +1017,15 @@ size_t size; } in; struct { - size_t size_left; /* How much body left to process */ - request_t *request; /* Parameters passed to clientReadBody */ + size_t size_left; /* How much body left to process */ + request_t *request; /* Parameters passed to clientReadBody */ char *buf; size_t bufsize; CBCB *callback; void *cbdata; } body; - auth_type_t auth_type; /* Is this connection based authentication ? if so - * what type it is. */ + auth_type_t auth_type; /* Is this connection based authentication ? if so + * what type it is. */ /* note this is ONLY connection based because NTLM is against HTTP spec */ /* the user details for connection based authentication */ auth_user_request_t *auth_user_request; @@ -1576,7 +1577,7 @@ struct in_addr my_addr; unsigned short my_port; HttpHeader header; - ConnStateData *body_connection; /* used by clientReadBody() */ + ConnStateData *body_connection; /* used by clientReadBody() */ int content_length; HierarchyLogEntry hier; err_type err_type; @@ -1621,7 +1622,7 @@ err_type type; int page_id; http_status http_status; - auth_user_request_t * auth_user_request; + auth_user_request_t *auth_user_request; request_t *request; char *url; int xerrno; @@ -1916,8 +1917,8 @@ struct _helper_stateful_request { char *buf; HLPSCB *callback; - int placeholder; /* if 1, this is a dummy request waiting for a stateful helper - * to become available for deferred requests.*/ + int placeholder; /* if 1, this is a dummy request waiting for a stateful helper + * to become available for deferred requests.*/ void *data; }; @@ -1952,10 +1953,10 @@ HLPSONEQ *OnEmptyQueue; time_t last_queue_warn; struct { - int requests; - int replies; - int queue_size; - int avg_svc_time; + int requests; + int replies; + int queue_size; + int avg_svc_time; } stats; }; @@ -1997,17 +1998,17 @@ statefulhelper *parent; helper_stateful_request *request; struct _helper_stateful_flags { - unsigned int alive:1; - unsigned int busy:1; - unsigned int closing:1; - unsigned int shutdown:1; - stateful_helper_reserve_t reserved:2; + unsigned int alive:1; + unsigned int busy:1; + unsigned int closing:1; + unsigned int shutdown:1; + stateful_helper_reserve_t reserved:2; } flags; struct { int uses; } stats; - size_t deferred_requests; /* current number of deferred requests */ - void *data; /* State data used by the calling routines */ + size_t deferred_requests; /* current number of deferred requests */ + void *data; /* State data used by the calling routines */ }; /* Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.1.1.3.10.7.2.5 retrieving revision 1.1.1.3.10.7.2.6 diff -u -r1.1.1.3.10.7.2.5 -r1.1.1.3.10.7.2.6 --- squid/src/tools.c 4 Jan 2001 10:45:31 -0000 1.1.1.3.10.7.2.5 +++ squid/src/tools.c 7 Jan 2001 09:48:31 -0000 1.1.1.3.10.7.2.6 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.1.1.3.10.7.2.5 2001/01/04 10:45:31 rbcollins Exp $ + * $Id: tools.c,v 1.1.1.3.10.7.2.6 2001/01/07 09:48:31 hno Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -767,8 +767,8 @@ dlink_node * dlinkNodeNew() { - if (dlink_node_pool==NULL) - dlink_node_pool = memPoolCreate("Dlink list nodes", sizeof(dlink_node)); + if (dlink_node_pool == NULL) + dlink_node_pool = memPoolCreate("Dlink list nodes", sizeof(dlink_node)); /* where should we call memPoolDestroy(dlink_node_pool); */ return memPoolAlloc(dlink_node_pool); } @@ -777,8 +777,8 @@ void dlinkNodeDelete(dlink_node * m) { - if (m==NULL) - return; + if (m == NULL) + return; memPoolFree(dlink_node_pool, m); } Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.1.1.3.12.13.2.17 retrieving revision 1.1.1.3.12.13.2.18 diff -u -r1.1.1.3.12.13.2.17 -r1.1.1.3.12.13.2.18 --- squid/src/typedefs.h 7 Jan 2001 00:24:26 -0000 1.1.1.3.12.13.2.17 +++ squid/src/typedefs.h 7 Jan 2001 09:48:31 -0000 1.1.1.3.12.13.2.18 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.1.1.3.12.13.2.17 2001/01/07 00:24:26 rbcollins Exp $ + * $Id: typedefs.h,v 1.1.1.3.12.13.2.18 2001/01/07 09:48:31 hno Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -230,7 +230,7 @@ typedef void PSC(FwdServer *, void *); typedef void RH(void *data, char *); #if 0 -typedef void SRH(void *data, void * lastserver, char *); +typedef void SRH(void *data, void *lastserver, char *); #endif typedef void UH(void *data, wordlist *); typedef int DEFER(int fd, void *data); @@ -249,8 +249,8 @@ typedef void SIGHDLR(int sig); typedef void STVLDCB(void *, int, int); typedef void HLPCB(void *, char *buf); -typedef stateful_helper_callback_t HLPSCB(void *, void * lastserver, char *buf); -typedef int HLPSAVAIL(void *); +typedef stateful_helper_callback_t HLPSCB(void *, void *lastserver, char *buf); +typedef int HLPSAVAIL(void *); typedef void HLPSONEQ(void *); typedef void HLPCMDOPTS(int *argc, char **argv); typedef void IDNSCB(void *, rfc1035_rr *, int); @@ -296,26 +296,26 @@ typedef void StatHistBinDumper(StoreEntry *, int idx, double val, double size, int count); /* authenticate.c authenticate scheme routines typedefs */ -typedef int AUTHSACTIVE(); -typedef int AUTHSAUTHED(auth_user_request_t *); -typedef void AUTHSAUTHUSER(auth_user_request_t *, request_t *, ConnStateData *, http_hdr_type); -typedef void AUTHSDECODE(auth_user_request_t *, const char *); -typedef int AUTHSDIRECTION(auth_user_request_t *); -typedef void AUTHSDUMP(StoreEntry *, const char *, authScheme *); -typedef void AUTHSFIXERR(auth_user_request_t *, HttpReply *, http_hdr_type, request_t *); -typedef void AUTHSADDHEADER(auth_user_request_t *, HttpReply *, int); -typedef void AUTHSADDTRAILER(auth_user_request_t *, HttpReply *, int); -typedef void AUTHSFREE(auth_user_t *); -typedef void AUTHSFREECONFIG(authScheme *); +typedef int AUTHSACTIVE(); +typedef int AUTHSAUTHED(auth_user_request_t *); +typedef void AUTHSAUTHUSER(auth_user_request_t *, request_t *, ConnStateData *, http_hdr_type); +typedef void AUTHSDECODE(auth_user_request_t *, const char *); +typedef int AUTHSDIRECTION(auth_user_request_t *); +typedef void AUTHSDUMP(StoreEntry *, const char *, authScheme *); +typedef void AUTHSFIXERR(auth_user_request_t *, HttpReply *, http_hdr_type, request_t *); +typedef void AUTHSADDHEADER(auth_user_request_t *, HttpReply *, int); +typedef void AUTHSADDTRAILER(auth_user_request_t *, HttpReply *, int); +typedef void AUTHSFREE(auth_user_t *); +typedef void AUTHSFREECONFIG(authScheme *); typedef char *AUTHSUSERNAME(auth_user_t *); -typedef void AUTHSONCLOSEC(ConnStateData *); -typedef void AUTHSPARSE(authScheme *, int, char *); -typedef void AUTHSINIT(authScheme *); -typedef void AUTHSREQFREE(auth_user_request_t *); -typedef void AUTHSSETUP(authscheme_entry_t *); -typedef void AUTHSSHUTDOWN(void); -typedef void AUTHSSTART(auth_user_request_t * , RH * , void *); -typedef void AUTHSSTATS(StoreEntry *); +typedef void AUTHSONCLOSEC(ConnStateData *); +typedef void AUTHSPARSE(authScheme *, int, char *); +typedef void AUTHSINIT(authScheme *); +typedef void AUTHSREQFREE(auth_user_request_t *); +typedef void AUTHSSETUP(authscheme_entry_t *); +typedef void AUTHSSHUTDOWN(void); +typedef void AUTHSSTART(auth_user_request_t *, RH *, void *); +typedef void AUTHSSTATS(StoreEntry *); /* append/vprintf's for Packer */ typedef void (*append_f) (void *, const char *buf, int size); Index: squid/src/auth/basic/auth_basic.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/auth/basic/auth_basic.c,v retrieving revision 1.1.2.20 retrieving revision 1.1.2.21 diff -u -r1.1.2.20 -r1.1.2.21 --- squid/src/auth/basic/auth_basic.c 6 Jan 2001 13:35:08 -0000 1.1.2.20 +++ squid/src/auth/basic/auth_basic.c 7 Jan 2001 09:48:32 -0000 1.1.2.21 @@ -34,8 +34,8 @@ */ /* The functions in this file handle authentication. - They DO NOT perform access control or auditing. - See acl.c for access control and client_side.c for auditing */ + * They DO NOT perform access control or auditing. + * See acl.c for access control and client_side.c for auditing */ #include "squid.h" @@ -50,19 +50,19 @@ /* Basic Scheme */ static HLPCB authenticateBasicHandleReply; -static AUTHSACTIVE authenticateBasicActive; -static AUTHSAUTHED authenticateBasicAuthenticated; -static AUTHSAUTHUSER authenticateBasicAuthenticateUser; +static AUTHSACTIVE authenticateBasicActive; +static AUTHSAUTHED authenticateBasicAuthenticated; +static AUTHSAUTHUSER authenticateBasicAuthenticateUser; static AUTHSDIRECTION authenticateBasicDirection; -static AUTHSDECODE authenticateBasicDecodeAuth; -static AUTHSDUMP authBasicCfgDump; -static AUTHSFIXERR authenticateBasicFixErrorHeader; -static AUTHSFREE authenticateBasicFreeUser; +static AUTHSDECODE authenticateBasicDecodeAuth; +static AUTHSDUMP authBasicCfgDump; +static AUTHSFIXERR authenticateBasicFixErrorHeader; +static AUTHSFREE authenticateBasicFreeUser; static AUTHSFREECONFIG authBasicFreeConfig; -static AUTHSPARSE authBasicParse; -static AUTHSINIT authBasicInit; -static AUTHSSTART authenticateBasicStart; -static AUTHSSTATS authenticateBasicStats; +static AUTHSPARSE authBasicParse; +static AUTHSINIT authBasicInit; +static AUTHSSTART authenticateBasicStart; +static AUTHSSTATS authenticateBasicStats; static AUTHSUSERNAME authenticateBasicUsername; static AUTHSSHUTDOWN authBasicDone; @@ -83,95 +83,98 @@ authBasicDone(void) { // memPoolDestroy(ufs_state_pool); - if (basicauthenticators) - helperShutdown(basicauthenticators); + if (basicauthenticators) + helperShutdown(basicauthenticators); authbasic_initialised = 0; if (!shutting_down) - return; + return; helperFree(basicauthenticators); basicauthenticators = NULL; memPoolDestroy(basic_data_pool); } -void -authSchemeSetup_basic(authscheme_entry_t *authscheme) { +void +authSchemeSetup_basic(authscheme_entry_t * authscheme) +{ assert(!authbasic_initialised); - authscheme->Active =authenticateBasicActive; - authscheme->parse =authBasicParse; - authscheme->dump =authBasicCfgDump; - authscheme->init =authBasicInit; + authscheme->Active = authenticateBasicActive; + authscheme->parse = authBasicParse; + authscheme->dump = authBasicCfgDump; + authscheme->init = authBasicInit; authscheme->authAuthenticate = authenticateBasicAuthenticateUser; - authscheme->authenticated= authenticateBasicAuthenticated; - authscheme->authFixHeader=authenticateBasicFixErrorHeader; - authscheme->FreeUser =authenticateBasicFreeUser; - authscheme->freeconfig =authBasicFreeConfig; - authscheme->authStart =authenticateBasicStart; - authscheme->authStats =authenticateBasicStats; + authscheme->authenticated = authenticateBasicAuthenticated; + authscheme->authFixHeader = authenticateBasicFixErrorHeader; + authscheme->FreeUser = authenticateBasicFreeUser; + authscheme->freeconfig = authBasicFreeConfig; + authscheme->authStart = authenticateBasicStart; + authscheme->authStats = authenticateBasicStats; authscheme->authUserUsername = authenticateBasicUsername; - authscheme->getdirection=authenticateBasicDirection; - authscheme->oncloseconnection=NULL; - authscheme->decodeauth =authenticateBasicDecodeAuth; + authscheme->getdirection = authenticateBasicDirection; + authscheme->oncloseconnection = NULL; + authscheme->decodeauth = authenticateBasicDecodeAuth; authscheme->donefunc = authBasicDone; } int -authenticateBasicActive(){ +authenticateBasicActive() +{ #if 0 - if (authbasic_initialised) - return 1; - else - return 0; + if (authbasic_initialised) + return 1; + else + return 0; #endif - if ((basicConfig!= NULL) && (basicConfig->authenticate!=NULL) && - (basicConfig->authenticateChildren!=0) &&(basicConfig->basicAuthRealm != NULL)) - return 1; + if ((basicConfig != NULL) && (basicConfig->authenticate != NULL) && + (basicConfig->authenticateChildren != 0) && (basicConfig->basicAuthRealm != NULL)) + return 1; return 0; } -int +int authenticateBasicAuthenticated(auth_user_request_t * auth_user_request) { - basic_data *basic_auth=auth_user_request->auth_user->scheme_data; - if ((auth_user_request->auth_user->flags.credentials_ok==1) && (basic_auth->credentials_checkedtime+basicConfig->credentialsTTL > squid_curtime)) - return 1; - debug (29, 4) ("User not authenticated or credentials need rechecking.\n"); + basic_data *basic_auth = auth_user_request->auth_user->scheme_data; + if ((auth_user_request->auth_user->flags.credentials_ok == 1) && (basic_auth->credentials_checkedtime + basicConfig->credentialsTTL > squid_curtime)) + return 1; + debug(29, 4) ("User not authenticated or credentials need rechecking.\n"); return 0; } -int authenticateBasiccmpUsername(basic_data * u1, basic_data *u2) +int +authenticateBasiccmpUsername(basic_data * u1, basic_data * u2) { - return strcmp(u1->username,u2->username); + return strcmp(u1->username, u2->username); } /* log a basic user in */ static void -authenticateBasicAuthenticateUser(auth_user_request_t *auth_user_request, request_t *request, ConnStateData *conn, http_hdr_type type) { +authenticateBasicAuthenticateUser(auth_user_request_t * auth_user_request, request_t * request, ConnStateData * conn, http_hdr_type type) +{ #if 0 - auth_user_hash_pointer *usernamehash, *proxy_auth_hash=NULL; + auth_user_hash_pointer *usernamehash, *proxy_auth_hash = NULL; #endif auth_user_t *auth_user; - basic_data * basic_auth; + basic_data *basic_auth; #if 0 //, *temp_auth; - const char * proxy_auth; + const char *proxy_auth; #endif - - assert (auth_user_request->auth_user != NULL); - auth_user=auth_user_request->auth_user; + + assert(auth_user_request->auth_user != NULL); + auth_user = auth_user_request->auth_user; /* if the password is not ok, do an identity */ - if (auth_user->flags.credentials_ok!=1) - return; + if (auth_user->flags.credentials_ok != 1) + return; assert(auth_user->scheme_data != NULL); - basic_auth = auth_user->scheme_data; + basic_auth = auth_user->scheme_data; /* are we about to recheck the credentials externally? */ - if ((basic_auth->credentials_checkedtime+basicConfig->credentialsTTL)<=squid_curtime) - { - debug(29,4)("authBasicAuthenticate: credentials expired - rechecking\n"); - return; + if ((basic_auth->credentials_checkedtime + basicConfig->credentialsTTL) <= squid_curtime) { + debug(29, 4) ("authBasicAuthenticate: credentials expired - rechecking\n"); + return; } #if 0 /* get the header. */ @@ -180,103 +183,106 @@ /* we have been through the external helper, and the credentials haven't expired */ debug(29, 9) ("authenticateBasicAuthenticateuser: user '%s' authenticated\n", - basic_auth->username); + basic_auth->username); /* Decode now takes care of finding the auth_user struct in the cache */ #if 0 /* see if this is an existing user with a different proxy_auth string */ if ((usernamehash = hash_lookup(proxy_auth_username_cache, - basic_auth->username))) { - while ((usernamehash->auth_user->auth_type != auth_user->auth_type) && - (usernamehash->next) && - !authenticateBasiccmpUsername(usernamehash->auth_user->scheme_data,basic_auth)) - usernamehash=usernamehash->next; - if (usernamehash->auth_user->auth_type==auth_user->auth_type) { - /* - * add another link from the new proxy_auth to the - * auth_user structure and update the information */ - assert(proxy_auth_hash == NULL); - authenticateProxyAuthCacheAddLink(proxy_auth, usernamehash->auth_user); - /* maybe the p/w changed. update in the old structure */ - temp_auth=usernamehash->auth_user->scheme_data; - xfree(temp_auth->passwd); - temp_auth->passwd = basic_auth->passwd; - basic_auth->passwd = NULL; - /* and remove the temporary structure */ - authenticateAuthUserUnlock(auth_user); + basic_auth->username))) { + while ((usernamehash->auth_user->auth_type != auth_user->auth_type) && + (usernamehash->next) && + !authenticateBasiccmpUsername(usernamehash->auth_user->scheme_data, basic_auth)) + usernamehash = usernamehash->next; + if (usernamehash->auth_user->auth_type == auth_user->auth_type) { + /* + * add another link from the new proxy_auth to the + * auth_user structure and update the information */ + assert(proxy_auth_hash == NULL); + authenticateProxyAuthCacheAddLink(proxy_auth, usernamehash->auth_user); + /* maybe the p/w changed. update in the old structure */ + temp_auth = usernamehash->auth_user->scheme_data; + xfree(temp_auth->passwd); + temp_auth->passwd = basic_auth->passwd; + basic_auth->passwd = NULL; + /* and remove the temporary structure */ + authenticateAuthUserUnlock(auth_user); #if 0 - authenticateFreeProxyAuthUser(auth_user); + authenticateFreeProxyAuthUser(auth_user); #endif - auth_user = usernamehash->auth_user; - /* and reference the existing basic data structure */ - basic_auth = auth_user->scheme_data; - /* lock the structure for this request */ - authenticateAuthUserLock(auth_user); - } + auth_user = usernamehash->auth_user; + /* and reference the existing basic data structure */ + basic_auth = auth_user->scheme_data; + /* lock the structure for this request */ + authenticateAuthUserLock(auth_user); + } } else { - /* store user in hash's */ - authenticateUserNameCacheAdd(auth_user); - authenticateProxyAuthCacheAddLink(proxy_auth, auth_user); + /* store user in hash's */ + authenticateUserNameCacheAdd(auth_user); + authenticateProxyAuthCacheAddLink(proxy_auth, auth_user); } /* auth_user is now linked, we reset these values */ #endif /* after external auth occurs anyway */ - auth_user->expiretime = current_time.tv_sec; + auth_user->expiretime = current_time.tv_sec; auth_user->ip_expiretime = squid_curtime; - return; + return; } -int authenticateBasicDirection(auth_user_request_t *auth_user_request) { +int +authenticateBasicDirection(auth_user_request_t * auth_user_request) +{ /* null auth_user is checked for by authenticateDirection */ - auth_user_t * auth_user = auth_user_request->auth_user; - basic_data *basic_auth=auth_user->scheme_data; + auth_user_t *auth_user = auth_user_request->auth_user; + basic_data *basic_auth = auth_user->scheme_data; switch (auth_user->flags.credentials_ok) { - case 0: /* not checked */ - return -1; - case 1: /* checked & ok */ - if (basic_auth->credentials_checkedtime+basicConfig->credentialsTTL<=squid_curtime) - return -1; - return 0; - case 2: /* paused while waiting for a username:password check on another request*/ - return -1; - case 3: /* authentication process failed. */ - return -2; + case 0: /* not checked */ + return -1; + case 1: /* checked & ok */ + if (basic_auth->credentials_checkedtime + basicConfig->credentialsTTL <= squid_curtime) + return -1; + return 0; + case 2: /* paused while waiting for a username:password check on another request */ + return -1; + case 3: /* authentication process failed. */ + return -2; } return -2; } void -authenticateBasicFixErrorHeader(auth_user_request_t *auth_user_request, HttpReply *rep, http_hdr_type type, request_t * request){ - if (basicConfig->authenticate) - { - debug(29, 9) ("authenticateFixErrorHeader: Sending type:%d header: 'Basic realm=\"%s\"'\n",type,basicConfig->basicAuthRealm); - httpHeaderPutStrf(&rep->header, type, "Basic realm=\"%s\"", basicConfig->basicAuthRealm); +authenticateBasicFixErrorHeader(auth_user_request_t * auth_user_request, HttpReply * rep, http_hdr_type type, request_t * request) +{ + if (basicConfig->authenticate) { + debug(29, 9) ("authenticateFixErrorHeader: Sending type:%d header: 'Basic realm=\"%s\"'\n", type, basicConfig->basicAuthRealm); + httpHeaderPutStrf(&rep->header, type, "Basic realm=\"%s\"", basicConfig->basicAuthRealm); } } /* free any allocated configuration details */ void -authBasicFreeConfig(authScheme *scheme) +authBasicFreeConfig(authScheme * scheme) { - if (basicConfig==NULL) - return; - assert(basicConfig==scheme->scheme_data); + if (basicConfig == NULL) + return; + assert(basicConfig == scheme->scheme_data); if (basicConfig->authenticate) - wordlistDestroy(&basicConfig->authenticate); + wordlistDestroy(&basicConfig->authenticate); if (basicConfig->basicAuthRealm) - safe_free(basicConfig->basicAuthRealm); - xfree(basicConfig); - basicConfig=NULL; + safe_free(basicConfig->basicAuthRealm); + xfree(basicConfig); + basicConfig = NULL; } void -authenticateBasicFreeUser(auth_user_t *auth_user) { - basic_data * basic_auth = auth_user->scheme_data; - debug(29,5) ("authenticateBasicFreeUser: Clearing Basic scheme data\n"); +authenticateBasicFreeUser(auth_user_t * auth_user) +{ + basic_data *basic_auth = auth_user->scheme_data; + debug(29, 5) ("authenticateBasicFreeUser: Clearing Basic scheme data\n"); if (basic_auth->username) - xfree(basic_auth->username); + xfree(basic_auth->username); if (basic_auth->passwd) - xfree(basic_auth->passwd); + xfree(basic_auth->passwd); memPoolFree(basic_data_pool, auth_user->scheme_data); auth_user->scheme_data = NULL; } @@ -287,7 +293,7 @@ authenticateStateData *r = data; auth_user_t *auth_user; basic_data *basic_auth; - auth_basic_queue_node *node,*tmpnode; + auth_basic_queue_node *node, *tmpnode; int valid; char *t = NULL; debug(29, 9) ("authenticateBasicHandleReply: {%s}\n", reply ? reply : ""); @@ -299,86 +305,74 @@ } assert(r->auth_user_request != NULL); assert(r->auth_user_request->auth_user->auth_type == AUTH_BASIC); - auth_user=r->auth_user_request->auth_user; - basic_auth=auth_user->scheme_data; + auth_user = r->auth_user_request->auth_user; + basic_auth = auth_user->scheme_data; if (reply && (strncasecmp(reply, "OK", 2) == 0)) - auth_user->flags.credentials_ok = 1; + auth_user->flags.credentials_ok = 1; else - auth_user->flags.credentials_ok = 3; - basic_auth->credentials_checkedtime=squid_curtime; + auth_user->flags.credentials_ok = 3; + basic_auth->credentials_checkedtime = squid_curtime; valid = cbdataValid(r->data); cbdataUnlock(r->data); if (valid) r->handler(r->data, NULL); - node=basic_auth->auth_queue; - while (node) - { - tmpnode=node->next; - valid = cbdataValid(node->data); - cbdataUnlock(node->data); - if (valid) - node->handler(node->data, NULL); - xfree(node); - node=tmpnode; + node = basic_auth->auth_queue; + while (node) { + tmpnode = node->next; + valid = cbdataValid(node->data); + cbdataUnlock(node->data); + if (valid) + node->handler(node->data, NULL); + xfree(node); + node = tmpnode; } #if 0 if (valid) - r->handler(r->data, reply); + r->handler(r->data, reply); #endif authenticateStateFree(r); } static void -authBasicCfgDump(StoreEntry *entry, const char * name, authScheme *scheme) +authBasicCfgDump(StoreEntry * entry, const char *name, authScheme * scheme) { - auth_basic_config *config=scheme->scheme_data; - wordlist *list=config->authenticate; - storeAppendPrintf(entry, "%s %s", name, "basic"); - while (list !=NULL) - { - storeAppendPrintf(entry, " %s", list->key); - list = list->next; - } - storeAppendPrintf(entry, "\n%s %s realm %s\n%s %s children %d\n%s %s credentialsttl %d seconds\n", - name, "basic", config->basicAuthRealm, - name, "basic", config->authenticateChildren, - name, "basic", config->credentialsTTL); - + auth_basic_config *config = scheme->scheme_data; + wordlist *list = config->authenticate; + storeAppendPrintf(entry, "%s %s", name, "basic"); + while (list != NULL) { + storeAppendPrintf(entry, " %s", list->key); + list = list->next; + } + storeAppendPrintf(entry, "\n%s %s realm %s\n%s %s children %d\n%s %s credentialsttl %d seconds\n", + name, "basic", config->basicAuthRealm, + name, "basic", config->authenticateChildren, + name, "basic", config->credentialsTTL); + } static void -authBasicParse(authScheme *scheme, int n_configured, char *param_str) +authBasicParse(authScheme * scheme, int n_configured, char *param_str) { - if (scheme->scheme_data==NULL) - { - assert (basicConfig==NULL); - /* this is the first param to be found */ - scheme->scheme_data=xmalloc(sizeof(auth_basic_config)); - memset(scheme->scheme_data, 0, sizeof(auth_basic_config)); - basicConfig=scheme->scheme_data; - basicConfig->authenticateChildren=5; - } - basicConfig=scheme->scheme_data; - if (strcasecmp(param_str,"program")==0) - { - parse_wordlist(&basicConfig->authenticate); - requirePathnameExists("authparam basic program",basicConfig->authenticate->key); - } - else if (strcasecmp(param_str,"children")==0) - { - parse_int(&basicConfig->authenticateChildren); - } - else if (strcasecmp(param_str,"realm")==0) - { - parse_eol(&basicConfig->basicAuthRealm); - } - else if (strcasecmp(param_str,"credentialsttl")==0) - { - parse_time_t(&basicConfig->credentialsTTL); - } - else - { - debug(28,0)("unrecognised basic auth scheme parameter '%s'\n",param_str); + if (scheme->scheme_data == NULL) { + assert(basicConfig == NULL); + /* this is the first param to be found */ + scheme->scheme_data = xmalloc(sizeof(auth_basic_config)); + memset(scheme->scheme_data, 0, sizeof(auth_basic_config)); + basicConfig = scheme->scheme_data; + basicConfig->authenticateChildren = 5; + } + basicConfig = scheme->scheme_data; + if (strcasecmp(param_str, "program") == 0) { + parse_wordlist(&basicConfig->authenticate); + requirePathnameExists("authparam basic program", basicConfig->authenticate->key); + } else if (strcasecmp(param_str, "children") == 0) { + parse_int(&basicConfig->authenticateChildren); + } else if (strcasecmp(param_str, "realm") == 0) { + parse_eol(&basicConfig->basicAuthRealm); + } else if (strcasecmp(param_str, "credentialsttl") == 0) { + parse_time_t(&basicConfig->credentialsTTL); + } else { + debug(28, 0) ("unrecognised basic auth scheme parameter '%s'\n", param_str); } } @@ -393,10 +387,11 @@ /* authenticateBasicUsername: return a pointer to the username in the */ char * -authenticateBasicUsername(auth_user_t *auth_user) { - basic_data * basic_auth = auth_user->scheme_data; +authenticateBasicUsername(auth_user_t * auth_user) +{ + basic_data *basic_auth = auth_user->scheme_data; if (basic_auth) - return basic_auth->username; + return basic_auth->username; return NULL; } @@ -404,36 +399,34 @@ authBasicDataNew() { basic_data *temp; - temp=memPoolAlloc(basic_data_pool); - assert(temp!=NULL); - temp->username=NULL; - temp->passwd=NULL; - temp->auth_queue=NULL; + temp = memPoolAlloc(basic_data_pool); + assert(temp != NULL); + temp->username = NULL; + temp->passwd = NULL; + temp->auth_queue = NULL; return temp; } void -authBasicDataFree(basic_data *basic_auth) +authBasicDataFree(basic_data * basic_auth) { } auth_user_t * -authBasicAuthUserFindUsername(const char * username) +authBasicAuthUserFindUsername(const char *username) { auth_user_hash_pointer *usernamehash; - auth_user_t * auth_user; - debug(29,9)("authBasicAuthUserFindUsername: Looking for user '%s'\n",username); - if (username && (usernamehash = hash_lookup(proxy_auth_username_cache, username))) - { - while ((usernamehash->auth_user->auth_type != AUTH_BASIC) && - (usernamehash->next)) - usernamehash=usernamehash->next; - auth_user=NULL; - if (usernamehash->auth_user->auth_type==AUTH_BASIC) - { - auth_user=usernamehash->auth_user; - } - return auth_user; + auth_user_t *auth_user; + debug(29, 9) ("authBasicAuthUserFindUsername: Looking for user '%s'\n", username); + if (username && (usernamehash = hash_lookup(proxy_auth_username_cache, username))) { + while ((usernamehash->auth_user->auth_type != AUTH_BASIC) && + (usernamehash->next)) + usernamehash = usernamehash->next; + auth_user = NULL; + if (usernamehash->auth_user->auth_type == AUTH_BASIC) { + auth_user = usernamehash->auth_user; + } + return auth_user; } return NULL; } @@ -448,23 +441,24 @@ */ static void -authenticateBasicDecodeAuth(auth_user_request_t *auth_user_request, const char * proxy_auth) { +authenticateBasicDecodeAuth(auth_user_request_t * auth_user_request, const char *proxy_auth) +{ char *sent_auth; char *cleartext; - basic_data * basic_auth, local_basic; - auth_user_t * auth_user; - dlink_node * node; + basic_data *basic_auth, local_basic; + auth_user_t *auth_user; + dlink_node *node; /* decode the username */ /* trim BASIC from string */ while (!xisspace(*proxy_auth)) - proxy_auth++; + proxy_auth++; - local_basic.passwd=NULL; + local_basic.passwd = NULL; /* Trim leading whitespace before decoding */ while (xisspace(*proxy_auth)) - proxy_auth++; + proxy_auth++; /* username and password */ sent_auth = xstrdup(proxy_auth); /* Trim trailing \n before decoding */ @@ -480,104 +474,96 @@ local_basic.username = xstrndup(cleartext, USER_IDENT_SZ); xfree(cleartext); if ((cleartext = strchr(local_basic.username, ':')) != NULL) - *(cleartext)++ = '\0'; - local_basic.passwd=cleartext; + *(cleartext)++ = '\0'; + local_basic.passwd = cleartext; if (cleartext == NULL) { - debug(29, 4) ("authenticateBasicDecodeAuth: no password in proxy authorization header '%s'\n", - proxy_auth); - local_basic.passwd=NULL; - auth_user_request->message=xstrdup("no password was present in the HTTP [proxy-]authorization header. This is most likely a browser bug"); - } - else if (*cleartext == '\0') { - debug(29, 4) ("authenticateBasicDecodeAuth: Disallowing empty password," - "user is '%s'\n", local_basic.username); - local_basic.passwd=NULL; - auth_user_request->message=xstrdup("Request denied because you provided an empty password. Users MUST have a password."); - } + debug(29, 4) ("authenticateBasicDecodeAuth: no password in proxy authorization header '%s'\n", + proxy_auth); + local_basic.passwd = NULL; + auth_user_request->message = xstrdup("no password was present in the HTTP [proxy-]authorization header. This is most likely a browser bug"); + } else if (*cleartext == '\0') { + debug(29, 4) ("authenticateBasicDecodeAuth: Disallowing empty password," + "user is '%s'\n", local_basic.username); + local_basic.passwd = NULL; + auth_user_request->message = xstrdup("Request denied because you provided an empty password. Users MUST have a password."); + } /* special case: we have to free the strings for user and password * if we are not returning a filled out structure */ - if (local_basic.passwd==NULL) - { - if (local_basic.username) - { - /* log the username */ - debug(29,9)("authBasicDecodeAuth: Creating new user for logging '%s'\n",local_basic.username); - /* new auth_user */ - auth_user=authenticateAuthUserNew("basic"); - /* new scheme data */ - basic_auth=authBasicDataNew(); - /* save the credentials */ - basic_auth->username=local_basic.username; - /* link the scheme data in */ - auth_user->scheme_data=basic_auth; - /* set the auth_user type */ - auth_user->auth_type=AUTH_BROKEN; - /* link the request to the user */ - auth_user_request->auth_user=auth_user; - /* lock for the auth_user_request link */ - authenticateAuthUserLock(auth_user); - node=dlinkNodeNew(); - dlinkAdd(auth_user_request, node, &auth_user->requests); + if (local_basic.passwd == NULL) { + if (local_basic.username) { + /* log the username */ + debug(29, 9) ("authBasicDecodeAuth: Creating new user for logging '%s'\n", local_basic.username); + /* new auth_user */ + auth_user = authenticateAuthUserNew("basic"); + /* new scheme data */ + basic_auth = authBasicDataNew(); + /* save the credentials */ + basic_auth->username = local_basic.username; + /* link the scheme data in */ + auth_user->scheme_data = basic_auth; + /* set the auth_user type */ + auth_user->auth_type = AUTH_BROKEN; + /* link the request to the user */ + auth_user_request->auth_user = auth_user; + /* lock for the auth_user_request link */ + authenticateAuthUserLock(auth_user); + node = dlinkNodeNew(); + dlinkAdd(auth_user_request, node, &auth_user->requests); #if 0 - xfree(local_basic.username); + xfree(local_basic.username); #endif - } + } #if 0 - memPoolFree(basic_data_pool, basic_auth); - auth_user->scheme_data = NULL; + memPoolFree(basic_data_pool, basic_auth); + auth_user->scheme_data = NULL; #endif - return; + return; } else { - local_basic.passwd = xstrndup(cleartext, USER_IDENT_SZ); + local_basic.passwd = xstrndup(cleartext, USER_IDENT_SZ); } /* now lookup and see if we have a matching auth_user structure in memory. */ - if ((auth_user=authBasicAuthUserFindUsername(local_basic.username))== NULL) - { - /* the user doesn't exist in the username cache yet */ - debug(29,9)("authBasicDecodeAuth: Creating new user '%s'\n",local_basic.username); - /* new auth_user */ - auth_user=authenticateAuthUserNew("basic"); - /* new scheme data */ - basic_auth=authBasicDataNew(); - /* save the credentials */ - basic_auth->username=local_basic.username; - basic_auth->passwd=local_basic.passwd; - /* link the scheme data in */ - auth_user->scheme_data=basic_auth; - /* set the auth_user type */ - auth_user->auth_type=AUTH_BASIC; - /* current time for timeouts */ - auth_user->expiretime = current_time.tv_sec; - auth_user->ip_expiretime = squid_curtime; - - /* this auth_user struct is the 'lucky one' to get added to the username cache */ - /* the requests after this link to the auth_user */ - /* store user in hash */ - authenticateUserNameCacheAdd(auth_user); - } - else - { - debug(29,9)("authBasicDecodeAuth: Found user '%s' in the user cache as '%d'\n",local_basic.username,auth_user); - xfree(local_basic.username); - basic_auth=auth_user->scheme_data; - if (strcmp(local_basic.passwd,basic_auth->passwd)) - { - debug(29,4)("authBasicDecodeAuth: new password found. Updating in user master record and resetting auth state to unchecked\n"); - auth_user->flags.credentials_ok=0; - xfree(basic_auth->passwd); - basic_auth->passwd=local_basic.passwd; - } - else - xfree(local_basic.passwd); + if ((auth_user = authBasicAuthUserFindUsername(local_basic.username)) == NULL) { + /* the user doesn't exist in the username cache yet */ + debug(29, 9) ("authBasicDecodeAuth: Creating new user '%s'\n", local_basic.username); + /* new auth_user */ + auth_user = authenticateAuthUserNew("basic"); + /* new scheme data */ + basic_auth = authBasicDataNew(); + /* save the credentials */ + basic_auth->username = local_basic.username; + basic_auth->passwd = local_basic.passwd; + /* link the scheme data in */ + auth_user->scheme_data = basic_auth; + /* set the auth_user type */ + auth_user->auth_type = AUTH_BASIC; + /* current time for timeouts */ + auth_user->expiretime = current_time.tv_sec; + auth_user->ip_expiretime = squid_curtime; + + /* this auth_user struct is the 'lucky one' to get added to the username cache */ + /* the requests after this link to the auth_user */ + /* store user in hash */ + authenticateUserNameCacheAdd(auth_user); + } else { + debug(29, 9) ("authBasicDecodeAuth: Found user '%s' in the user cache as '%d'\n", local_basic.username, auth_user); + xfree(local_basic.username); + basic_auth = auth_user->scheme_data; + if (strcmp(local_basic.passwd, basic_auth->passwd)) { + debug(29, 4) ("authBasicDecodeAuth: new password found. Updating in user master record and resetting auth state to unchecked\n"); + auth_user->flags.credentials_ok = 0; + xfree(basic_auth->passwd); + basic_auth->passwd = local_basic.passwd; + } else + xfree(local_basic.passwd); } /* link the request to the user */ - auth_user_request->auth_user=auth_user; + auth_user_request->auth_user = auth_user; /* lock for the auth_user_request link */ authenticateAuthUserLock(auth_user); - node=dlinkNodeNew(); + node = dlinkNodeNew(); dlinkAdd(auth_user_request, node, &auth_user->requests); return; } @@ -585,27 +571,27 @@ /* Initialize helpers and the like for this auth scheme. Called AFTER parsing the * config file */ static void -authBasicInit(authScheme *scheme) +authBasicInit(authScheme * scheme) { static int init = 0; - if (basicConfig->authenticate){ - if (!basic_data_pool) - basic_data_pool = memPoolCreate("Basic Scheme User Data", sizeof(basic_data)); - authbasic_initialised = 1; - if (basicauthenticators == NULL) - basicauthenticators = helperCreate("basicauthenticator"); - basicauthenticators->cmdline = basicConfig->authenticate; - basicauthenticators->n_to_start = basicConfig->authenticateChildren; - basicauthenticators->ipc_type = IPC_TCP_SOCKET; - helperOpenServers(basicauthenticators); - if (!init) { - cachemgrRegister("basicauthenticator", - "User Authenticator Stats", - authenticateBasicStats, 0, 1); - init++; - } - CBDATA_INIT_TYPE(authenticateStateData); - } + if (basicConfig->authenticate) { + if (!basic_data_pool) + basic_data_pool = memPoolCreate("Basic Scheme User Data", sizeof(basic_data)); + authbasic_initialised = 1; + if (basicauthenticators == NULL) + basicauthenticators = helperCreate("basicauthenticator"); + basicauthenticators->cmdline = basicConfig->authenticate; + basicauthenticators->n_to_start = basicConfig->authenticateChildren; + basicauthenticators->ipc_type = IPC_TCP_SOCKET; + helperOpenServers(basicauthenticators); + if (!init) { + cachemgrRegister("basicauthenticator", + "User Authenticator Stats", + authenticateBasicStats, 0, 1); + init++; + } + CBDATA_INIT_TYPE(authenticateStateData); + } } /* send the initial data to a basic authenticator module */ @@ -614,44 +600,41 @@ { authenticateStateData *r = NULL; char buf[8192]; - basic_data * basic_auth; + basic_data *basic_auth; assert(auth_user_request); assert(handler); - assert(auth_user_request->auth_user->auth_type==AUTH_BASIC); + assert(auth_user_request->auth_user->auth_type == AUTH_BASIC); assert(auth_user_request->auth_user->scheme_data != NULL); basic_auth = auth_user_request->auth_user->scheme_data; debug(29, 9) ("authenticateStart: '%s:%s'\n", basic_auth->username, - basic_auth->passwd); + basic_auth->passwd); if (basicConfig->authenticate == NULL) { - handler(data, NULL); - return; + handler(data, NULL); + return; } /* check to see if the auth_user already has a request outstanding */ - if (auth_user_request->auth_user->flags.credentials_ok==2) - { - /* there is a request with the same credentials already being verified */ - auth_basic_queue_node *node; - node=xmalloc(sizeof(auth_basic_queue_node)); - assert(node); - /* save the details */ - node->next=basic_auth->auth_queue; - basic_auth->auth_queue=node; - node->auth_user_request=auth_user_request; - node->handler=handler; - node->data=data; - cbdataLock(data); - return; - } - else - { - r = CBDATA_ALLOC(authenticateStateData, NULL); - r->handler = handler; - cbdataLock(data); - r->data = data; - r->auth_user_request = auth_user_request; - /* mark the user as haveing verification in progress */ - auth_user_request->auth_user->flags.credentials_ok=2; - snprintf(buf, 8192, "%s %s\n", basic_auth->username, basic_auth->passwd); - helperSubmit(basicauthenticators, buf, authenticateBasicHandleReply, r); + if (auth_user_request->auth_user->flags.credentials_ok == 2) { + /* there is a request with the same credentials already being verified */ + auth_basic_queue_node *node; + node = xmalloc(sizeof(auth_basic_queue_node)); + assert(node); + /* save the details */ + node->next = basic_auth->auth_queue; + basic_auth->auth_queue = node; + node->auth_user_request = auth_user_request; + node->handler = handler; + node->data = data; + cbdataLock(data); + return; + } else { + r = CBDATA_ALLOC(authenticateStateData, NULL); + r->handler = handler; + cbdataLock(data); + r->data = data; + r->auth_user_request = auth_user_request; + /* mark the user as haveing verification in progress */ + auth_user_request->auth_user->flags.credentials_ok = 2; + snprintf(buf, 8192, "%s %s\n", basic_auth->username, basic_auth->passwd); + helperSubmit(basicauthenticators, buf, authenticateBasicHandleReply, r); } } Index: squid/src/auth/basic/auth_basic.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/auth/basic/auth_basic.h,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- squid/src/auth/basic/auth_basic.h 6 Jan 2001 23:56:28 -0000 1.1.2.6 +++ squid/src/auth/basic/auth_basic.h 7 Jan 2001 09:48:32 -0000 1.1.2.7 @@ -7,7 +7,7 @@ #define __AUTH_BASIC_H__ -#define DefaultAuthenticateChildrenMax 32 /* 32 processes */ +#define DefaultAuthenticateChildrenMax 32 /* 32 processes */ /* Generic */ typedef struct { @@ -21,8 +21,8 @@ /* queue of auth requests waiting for verification to occur */ struct _auth_basic_queue_node { auth_basic_queue_node *next; - auth_user_request_t * auth_user_request; - RH * handler; + auth_user_request_t *auth_user_request; + RH *handler; void *data; }; @@ -30,7 +30,7 @@ char *username; char *passwd; time_t credentials_checkedtime; - auth_basic_queue_node *auth_queue; + auth_basic_queue_node *auth_queue; }; /* configuration runtime data */ Index: squid/src/auth/ntlm/auth_ntlm.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/auth/ntlm/auth_ntlm.c,v retrieving revision 1.1.2.17 retrieving revision 1.1.2.18 diff -u -r1.1.2.17 -r1.1.2.18 --- squid/src/auth/ntlm/auth_ntlm.c 7 Jan 2001 02:49:32 -0000 1.1.2.17 +++ squid/src/auth/ntlm/auth_ntlm.c 7 Jan 2001 09:48:32 -0000 1.1.2.18 @@ -34,8 +34,8 @@ */ /* The functions in this file handle authentication. - They DO NOT perform access control or auditing. - See acl.c for access control and client_side.c for auditing */ + * They DO NOT perform access control or auditing. + * See acl.c for access control and client_side.c for auditing */ #include "squid.h" @@ -50,27 +50,27 @@ /* NTLM Scheme */ static HLPSCB authenticateNTLMHandleReply; static HLPSCB authenticateNTLMHandleplaceholder; -static AUTHSACTIVE authenticateNTLMActive; -static AUTHSAUTHED authNTLMAuthenticated; -static AUTHSAUTHUSER authenticateNTLMAuthenticateUser; -static AUTHSFIXERR authenticateNTLMFixErrorHeader; -static AUTHSFREE authenticateNTLMFreeUser; +static AUTHSACTIVE authenticateNTLMActive; +static AUTHSAUTHED authNTLMAuthenticated; +static AUTHSAUTHUSER authenticateNTLMAuthenticateUser; +static AUTHSFIXERR authenticateNTLMFixErrorHeader; +static AUTHSFREE authenticateNTLMFreeUser; static AUTHSDIRECTION authenticateNTLMDirection; static AUTHSDECODE authenticateDecodeNTLMAuth; -static AUTHSDUMP authNTLMCfgDump; +static AUTHSDUMP authNTLMCfgDump; static AUTHSFREECONFIG authNTLMFreeConfig; -static AUTHSINIT authNTLMInit; +static AUTHSINIT authNTLMInit; static AUTHSONCLOSEC authenticateNTLMOnCloseConnection; static AUTHSUSERNAME authenticateNTLMUsername; -static AUTHSREQFREE authNTLMAURequestFree; -static AUTHSPARSE authNTLMParse; -static AUTHSSTART authenticateNTLMStart; -static AUTHSSTATS authenticateNTLMStats; +static AUTHSREQFREE authNTLMAURequestFree; +static AUTHSPARSE authNTLMParse; +static AUTHSSTART authenticateNTLMStart; +static AUTHSSTATS authenticateNTLMStats; static AUTHSSHUTDOWN authNTLMDone; /* helper callbacks to handle per server state data */ -static HLPSAVAIL authenticateNTLMHelperServerAvailable; -static HLPSONEQ authenticateNTLMHelperServerOnEmpty; +static HLPSAVAIL authenticateNTLMHelperServerAvailable; +static HLPSONEQ authenticateNTLMHelperServerOnEmpty; static statefulhelper *ntlmauthenticators = NULL; @@ -81,7 +81,7 @@ MemPool *ntlm_helper_state_pool = NULL; MemPool *ntlm_user_pool = NULL; MemPool *ntlm_request_pool = NULL; -static auth_ntlm_config * ntlmConfig = NULL; +static auth_ntlm_config *ntlmConfig = NULL; static hash_table *proxy_auth_cache = NULL; @@ -97,109 +97,99 @@ // memPoolDestroy(ufs_state_pool); if (ntlmauthenticators) - helperStatefulShutdown(ntlmauthenticators); + helperStatefulShutdown(ntlmauthenticators); authntlm_initialised = 0; if (!shutting_down) - return; + return; helperStatefulFree(ntlmauthenticators); ntlmauthenticators = NULL; memPoolDestroy(ntlm_helper_state_pool); memPoolDestroy(ntlm_request_pool); memPoolDestroy(ntlm_user_pool); - + } /* free any allocated configuration details */ void -authNTLMFreeConfig(authScheme *scheme) +authNTLMFreeConfig(authScheme * scheme) { - if (ntlmConfig==NULL) - return; - assert(ntlmConfig==scheme->scheme_data); + if (ntlmConfig == NULL) + return; + assert(ntlmConfig == scheme->scheme_data); if (ntlmConfig->authenticate) - wordlistDestroy(&ntlmConfig->authenticate); - xfree(ntlmConfig); - ntlmConfig=NULL; + wordlistDestroy(&ntlmConfig->authenticate); + xfree(ntlmConfig); + ntlmConfig = NULL; } static void -authNTLMCfgDump(StoreEntry *entry, const char * name, authScheme *scheme) +authNTLMCfgDump(StoreEntry * entry, const char *name, authScheme * scheme) { - auth_ntlm_config *config=scheme->scheme_data; - wordlist *list=config->authenticate; - storeAppendPrintf(entry, "%s %s", name, "ntlm"); - while (list !=NULL) - { - storeAppendPrintf(entry, " %s", list->key); - list = list->next; - } - storeAppendPrintf(entry, "\n%s %s children %d\n%s %s max_challenge_reuses %d\n%s %s max_challenge_lifetime %d seconds\n", - name, "ntlm", config->authenticateChildren, - name, "ntlm", config->challengeuses, - name, "ntlm", config->challengelifetime); + auth_ntlm_config *config = scheme->scheme_data; + wordlist *list = config->authenticate; + storeAppendPrintf(entry, "%s %s", name, "ntlm"); + while (list != NULL) { + storeAppendPrintf(entry, " %s", list->key); + list = list->next; + } + storeAppendPrintf(entry, "\n%s %s children %d\n%s %s max_challenge_reuses %d\n%s %s max_challenge_lifetime %d seconds\n", + name, "ntlm", config->authenticateChildren, + name, "ntlm", config->challengeuses, + name, "ntlm", config->challengelifetime); } static void -authNTLMParse(authScheme *scheme, int n_configured, char *param_str) +authNTLMParse(authScheme * scheme, int n_configured, char *param_str) { - if (scheme->scheme_data==NULL) - { - assert (ntlmConfig==NULL); - /* this is the first param to be found */ - scheme->scheme_data=xmalloc(sizeof(auth_ntlm_config)); - memset(scheme->scheme_data, 0, sizeof(auth_ntlm_config)); - ntlmConfig=scheme->scheme_data; - ntlmConfig->authenticateChildren=5; - ntlmConfig->challengeuses=0; - ntlmConfig->challengelifetime=60; - } - ntlmConfig=scheme->scheme_data; - if (strcasecmp(param_str,"program")==0) - { - parse_wordlist(&ntlmConfig->authenticate); - requirePathnameExists("authparam ntlm program",ntlmConfig->authenticate->key); - } - else if (strcasecmp(param_str,"children")==0) - { - parse_int(&ntlmConfig->authenticateChildren); - } - else if (strcasecmp(param_str,"max_challenge_reuses")==0) - { - parse_int(&ntlmConfig->challengeuses); - } - else if (strcasecmp(param_str,"max_challenge_lifetime")==0) - { - parse_time_t(&ntlmConfig->challengelifetime); - } - else - { - debug(28,0)("unrecognised ntlm auth scheme parameter '%s'\n",param_str); + if (scheme->scheme_data == NULL) { + assert(ntlmConfig == NULL); + /* this is the first param to be found */ + scheme->scheme_data = xmalloc(sizeof(auth_ntlm_config)); + memset(scheme->scheme_data, 0, sizeof(auth_ntlm_config)); + ntlmConfig = scheme->scheme_data; + ntlmConfig->authenticateChildren = 5; + ntlmConfig->challengeuses = 0; + ntlmConfig->challengelifetime = 60; + } + ntlmConfig = scheme->scheme_data; + if (strcasecmp(param_str, "program") == 0) { + parse_wordlist(&ntlmConfig->authenticate); + requirePathnameExists("authparam ntlm program", ntlmConfig->authenticate->key); + } else if (strcasecmp(param_str, "children") == 0) { + parse_int(&ntlmConfig->authenticateChildren); + } else if (strcasecmp(param_str, "max_challenge_reuses") == 0) { + parse_int(&ntlmConfig->challengeuses); + } else if (strcasecmp(param_str, "max_challenge_lifetime") == 0) { + parse_time_t(&ntlmConfig->challengelifetime); + } else { + debug(28, 0) ("unrecognised ntlm auth scheme parameter '%s'\n", param_str); } } void -authSchemeSetup_ntlm(authscheme_entry_t *authscheme) { +authSchemeSetup_ntlm(authscheme_entry_t * authscheme) +{ #if 0 -static int ntlminit = 0; + static int ntlminit = 0; #endif assert(!authntlm_initialised); - authscheme->Active =authenticateNTLMActive; - authscheme->parse =authNTLMParse; - authscheme->dump =authNTLMCfgDump; - authscheme->requestFree =authNTLMAURequestFree; - authscheme->freeconfig =authNTLMFreeConfig; - authscheme->init =authNTLMInit; + authscheme->Active = authenticateNTLMActive; + authscheme->parse = authNTLMParse; + authscheme->dump = authNTLMCfgDump; + authscheme->requestFree = authNTLMAURequestFree; + authscheme->freeconfig = authNTLMFreeConfig; + authscheme->init = authNTLMInit; authscheme->authAuthenticate = authenticateNTLMAuthenticateUser; - authscheme->authenticated = authNTLMAuthenticated; - authscheme->authFixHeader=authenticateNTLMFixErrorHeader; - authscheme->FreeUser =authenticateNTLMFreeUser; - authscheme->authStart =authenticateNTLMStart; - authscheme->authStats =authenticateNTLMStats; + authscheme->authenticated = authNTLMAuthenticated; + authscheme->authFixHeader = authenticateNTLMFixErrorHeader; + authscheme->FreeUser = authenticateNTLMFreeUser; + authscheme->authStart = authenticateNTLMStart; + authscheme->authStats = authenticateNTLMStats; authscheme->authUserUsername = authenticateNTLMUsername; - authscheme->getdirection=authenticateNTLMDirection; - authscheme->decodeauth =authenticateDecodeNTLMAuth; + authscheme->getdirection = authenticateNTLMDirection; + authscheme->decodeauth = authenticateDecodeNTLMAuth; authscheme->donefunc = authNTLMDone; authscheme->oncloseconnection = authenticateNTLMOnCloseConnection; } @@ -207,67 +197,68 @@ /* Initialize helpers and the like for this auth scheme. Called AFTER parsing the * config file */ static void -authNTLMInit(authScheme *scheme) +authNTLMInit(authScheme * scheme) { static int ntlminit = 0; - if (ntlmConfig->authenticate) - { - if (!ntlm_helper_state_pool) - ntlm_helper_state_pool = memPoolCreate("NTLM Helper State data", sizeof(ntlm_helper_state_t)); - if (!ntlm_user_pool) - ntlm_user_pool = memPoolCreate("NTLM Scheme User Data", sizeof(ntlm_user_t)); - if (!ntlm_request_pool) - ntlm_request_pool = memPoolCreate("NTLM Scheme Request Data", sizeof(ntlm_request_t)); - authntlm_initialised = 1; - if (ntlmauthenticators == NULL) - ntlmauthenticators = helperStatefulCreate("ntlmauthenticator"); - if (!proxy_auth_cache) - proxy_auth_cache = hash_create((HASHCMP *) strcmp, 7921, hash_string); - assert(proxy_auth_cache); - ntlmauthenticators->cmdline = ntlmConfig->authenticate; - ntlmauthenticators->n_to_start = ntlmConfig->authenticateChildren; - ntlmauthenticators->ipc_type = IPC_TCP_SOCKET; - ntlmauthenticators->datapool=ntlm_helper_state_pool; - ntlmauthenticators->IsAvailable=authenticateNTLMHelperServerAvailable; - ntlmauthenticators->OnEmptyQueue=authenticateNTLMHelperServerOnEmpty; - helperStatefulOpenServers(ntlmauthenticators); - /* TODO: In here send the initial YR to preinitialise the challenge cache */ - /* Think about this... currently we ask when the challenge is needed. Better?*/ - if (!ntlminit) - { - cachemgrRegister("ntlmauthenticator", - "User NTLM Authenticator Stats", - authenticateNTLMStats, 0, 1); - ntlminit++; - } - CBDATA_INIT_TYPE(authenticateStateData); + if (ntlmConfig->authenticate) { + if (!ntlm_helper_state_pool) + ntlm_helper_state_pool = memPoolCreate("NTLM Helper State data", sizeof(ntlm_helper_state_t)); + if (!ntlm_user_pool) + ntlm_user_pool = memPoolCreate("NTLM Scheme User Data", sizeof(ntlm_user_t)); + if (!ntlm_request_pool) + ntlm_request_pool = memPoolCreate("NTLM Scheme Request Data", sizeof(ntlm_request_t)); + authntlm_initialised = 1; + if (ntlmauthenticators == NULL) + ntlmauthenticators = helperStatefulCreate("ntlmauthenticator"); + if (!proxy_auth_cache) + proxy_auth_cache = hash_create((HASHCMP *) strcmp, 7921, hash_string); + assert(proxy_auth_cache); + ntlmauthenticators->cmdline = ntlmConfig->authenticate; + ntlmauthenticators->n_to_start = ntlmConfig->authenticateChildren; + ntlmauthenticators->ipc_type = IPC_TCP_SOCKET; + ntlmauthenticators->datapool = ntlm_helper_state_pool; + ntlmauthenticators->IsAvailable = authenticateNTLMHelperServerAvailable; + ntlmauthenticators->OnEmptyQueue = authenticateNTLMHelperServerOnEmpty; + helperStatefulOpenServers(ntlmauthenticators); + /* TODO: In here send the initial YR to preinitialise the challenge cache */ + /* Think about this... currently we ask when the challenge is needed. Better? */ + if (!ntlminit) { + cachemgrRegister("ntlmauthenticator", + "User NTLM Authenticator Stats", + authenticateNTLMStats, 0, 1); + ntlminit++; + } + CBDATA_INIT_TYPE(authenticateStateData); } } int -authenticateNTLMActive(){ +authenticateNTLMActive() +{ if (authntlm_initialised) - return 1; + return 1; else - return 0; + return 0; } /* NTLM Scheme */ -int authenticateNTLMDirection(auth_user_request_t *auth_user_request) { - ntlm_request_t * ntlm_request = auth_user_request->scheme_data; +int +authenticateNTLMDirection(auth_user_request_t * auth_user_request) +{ + ntlm_request_t *ntlm_request = auth_user_request->scheme_data; /* null auth_user is checked for by authenticateDirection */ switch (ntlm_request->auth_state) { - case AUTHENTICATE_STATE_NONE: /* no progress at all.*/ - debug(28,1) ("authenticateNTLMDirection: called before NTLM Authenticate!. Report a bug to squid-dev.\n"); - return -2; - case AUTHENTICATE_STATE_NEGOTIATE: /* send to helper */ - case AUTHENTICATE_STATE_RESPONSE: /*send to helper */ - return -1; - case AUTHENTICATE_STATE_CHALLENGE: /* send to client */ - return 1; - case AUTHENTICATE_STATE_DONE: /* do nothing.. */ - return 0; + case AUTHENTICATE_STATE_NONE: /* no progress at all. */ + debug(28, 1) ("authenticateNTLMDirection: called before NTLM Authenticate!. Report a bug to squid-dev.\n"); + return -2; + case AUTHENTICATE_STATE_NEGOTIATE: /* send to helper */ + case AUTHENTICATE_STATE_RESPONSE: /*send to helper */ + return -1; + case AUTHENTICATE_STATE_CHALLENGE: /* send to client */ + return 1; + case AUTHENTICATE_STATE_DONE: /* do nothing.. */ + return 0; } return -2; } @@ -278,41 +269,42 @@ * else. */ void -authenticateNTLMFixErrorHeader(auth_user_request_t *auth_user_request, HttpReply *rep, http_hdr_type type, request_t * request){ - ntlm_request_t * ntlm_request; - if (ntlmConfig->authenticate){ - /* New request, no user details */ - if (auth_user_request == NULL) { - debug(29, 9) ("authenticateNTLMFixErrorHeader: Sending type:%d header: 'NTLM'\n",type); - httpHeaderPutStrf(&rep->header, type, "NTLM"); - /* drop the connection */ - httpHeaderDelByName(&rep->header, "keep-alive"); - /* NTLM has problems if the initial connection is not dropped - I haven't checked the RFC compliance of this hack - RBCollins*/ - request->flags.proxy_keepalive = 0; - } else { - ntlm_request=auth_user_request->scheme_data; - switch (ntlm_request->auth_state){ - case AUTHENTICATE_STATE_NONE: - debug(29, 9) ("authenticateNTLMFixErrorHeader: Sending type:%d header: 'NTLM'\n",type); - httpHeaderPutStrf(&rep->header, type, "NTLM"); - /* drop the connection */ - httpHeaderDelByName(&rep->header, "keep-alive"); - /* NTLM has problems if the initial connection is not dropped - I haven't checked the RFC compliance of this hack - RBCollins*/ - request->flags.proxy_keepalive = 0; - break; - case AUTHENTICATE_STATE_CHALLENGE: - /* we are 'waiting' for a response */ - /* pass the challenge to the client */ - debug(29, 9) ("authenticateNTLMFixErrorHeader: Sending type:%d header: 'NTLM %s'\n",type,ntlm_request->authchallenge); - httpHeaderPutStrf(&rep->header, type, "NTLM %s", ntlm_request->authchallenge); - break; - default: - debug(29,0)("authenticateNTLMFixErrorHeader: state %d.\n",ntlm_request->auth_state); - fatal("unexpected state in AuthenticateNTLMFixErrorHeader.\n"); - } - } +authenticateNTLMFixErrorHeader(auth_user_request_t * auth_user_request, HttpReply * rep, http_hdr_type type, request_t * request) +{ + ntlm_request_t *ntlm_request; + if (ntlmConfig->authenticate) { + /* New request, no user details */ + if (auth_user_request == NULL) { + debug(29, 9) ("authenticateNTLMFixErrorHeader: Sending type:%d header: 'NTLM'\n", type); + httpHeaderPutStrf(&rep->header, type, "NTLM"); + /* drop the connection */ + httpHeaderDelByName(&rep->header, "keep-alive"); + /* NTLM has problems if the initial connection is not dropped + * I haven't checked the RFC compliance of this hack - RBCollins */ + request->flags.proxy_keepalive = 0; + } else { + ntlm_request = auth_user_request->scheme_data; + switch (ntlm_request->auth_state) { + case AUTHENTICATE_STATE_NONE: + debug(29, 9) ("authenticateNTLMFixErrorHeader: Sending type:%d header: 'NTLM'\n", type); + httpHeaderPutStrf(&rep->header, type, "NTLM"); + /* drop the connection */ + httpHeaderDelByName(&rep->header, "keep-alive"); + /* NTLM has problems if the initial connection is not dropped + * I haven't checked the RFC compliance of this hack - RBCollins */ + request->flags.proxy_keepalive = 0; + break; + case AUTHENTICATE_STATE_CHALLENGE: + /* we are 'waiting' for a response */ + /* pass the challenge to the client */ + debug(29, 9) ("authenticateNTLMFixErrorHeader: Sending type:%d header: 'NTLM %s'\n", type, ntlm_request->authchallenge); + httpHeaderPutStrf(&rep->header, type, "NTLM %s", ntlm_request->authchallenge); + break; + default: + debug(29, 0) ("authenticateNTLMFixErrorHeader: state %d.\n", ntlm_request->auth_state); + fatal("unexpected state in AuthenticateNTLMFixErrorHeader.\n"); + } + } } } @@ -320,13 +312,13 @@ authNTLMRequestFree(ntlm_request_t * ntlm_request) { if (!ntlm_request) - return; + return; if (ntlm_request->ntlmnegotiate) - xfree(ntlm_request->ntlmnegotiate); + xfree(ntlm_request->ntlmnegotiate); if (ntlm_request->authchallenge) - xfree(ntlm_request->authchallenge); + xfree(ntlm_request->authchallenge); if (ntlm_request->ntlmauthenticate) - xfree(ntlm_request->ntlmauthenticate); + xfree(ntlm_request->ntlmauthenticate); memPoolFree(ntlm_request_pool, ntlm_request); } @@ -334,68 +326,68 @@ authNTLMAURequestFree(auth_user_request_t * auth_user_request) { if (auth_user_request->scheme_data) - authNTLMRequestFree((ntlm_request_t *)auth_user_request->scheme_data); - auth_user_request->scheme_data=NULL; + authNTLMRequestFree((ntlm_request_t *) auth_user_request->scheme_data); + auth_user_request->scheme_data = NULL; } void -authenticateNTLMFreeUser(auth_user_t *auth_user) { +authenticateNTLMFreeUser(auth_user_t * auth_user) +{ dlink_node *link, *tmplink; - ntlm_user_t * ntlm_user = auth_user->scheme_data; + ntlm_user_t *ntlm_user = auth_user->scheme_data; auth_user_hash_pointer *proxy_auth_hash; - - debug(29,5) ("authenticateNTLMFreeUser: Clearing NTLM scheme data\n"); + + debug(29, 5) ("authenticateNTLMFreeUser: Clearing NTLM scheme data\n"); if (ntlm_user->username) - xfree(ntlm_user->username); + xfree(ntlm_user->username); /* were they linked in by one or more proxy-authenticate headers */ link = ntlm_user->proxy_auth_list.head; while (link) { - debug(29,9) ("authenticateFreeProxyAuthUser: removing proxy_auth hash entry '%d'\n -",link->data); - proxy_auth_hash = link->data; - tmplink=link; - link=link->next; - dlinkDelete(tmplink, &ntlm_user->proxy_auth_list); - hash_remove_link(proxy_auth_cache, (hash_link *) proxy_auth_hash); - /* free the key (usually the proxy_auth header) */ - xfree(proxy_auth_hash->key); - memFree(proxy_auth_hash, MEM_AUTH_USER_HASH); + debug(29, 9) ("authenticateFreeProxyAuthUser: removing proxy_auth hash entry '%d'\n", link->data); + proxy_auth_hash = link->data; + tmplink = link; + link = link->next; + dlinkDelete(tmplink, &ntlm_user->proxy_auth_list); + hash_remove_link(proxy_auth_cache, (hash_link *) proxy_auth_hash); + /* free the key (usually the proxy_auth header) */ + xfree(proxy_auth_hash->key); + memFree(proxy_auth_hash, MEM_AUTH_USER_HASH); } memPoolFree(ntlm_user_pool, ntlm_user); - auth_user->scheme_data = NULL; + auth_user->scheme_data = NULL; } static stateful_helper_callback_t -authenticateNTLMHandleplaceholder(void *data, void * lastserver, char *reply) +authenticateNTLMHandleplaceholder(void *data, void *lastserver, char *reply) { authenticateStateData *r = data; stateful_helper_callback_t result = S_HELPER_UNKNOWN; int valid; /* we should only be called for placeholder requests - which have no reply string */ - assert (reply == NULL); - assert (r->auth_user_request); + assert(reply == NULL); + assert(r->auth_user_request); /* standard callback stuff */ valid = cbdataValid(r->data); cbdataUnlock(r->data); /* call authenticateNTLMStart to retry this request */ - debug(29,9)("authenticateNTLMHandleplaceholder: calling authenticateNTLMStart\n"); - authenticateNTLMStart(r->auth_user_request, r->handler, r->data); + debug(29, 9) ("authenticateNTLMHandleplaceholder: calling authenticateNTLMStart\n"); + authenticateNTLMStart(r->auth_user_request, r->handler, r->data); authenticateStateFree(r); return result; } static stateful_helper_callback_t -authenticateNTLMHandleReply(void *data, void * lastserver, char *reply) +authenticateNTLMHandleReply(void *data, void *lastserver, char *reply) { #if 0 authenticateStatefulStateData *r = data; #endif authenticateStateData *r = data; - ntlm_helper_state_t * helperstate; + ntlm_helper_state_t *helperstate; int valid; stateful_helper_callback_t result = S_HELPER_UNKNOWN; #if 0 - void *nextserver=NULL; + void *nextserver = NULL; #endif char *t = NULL; auth_user_request_t *auth_user_request; @@ -406,144 +398,139 @@ valid = cbdataValid(r->data); cbdataUnlock(r->data); if (valid) { - if (reply) { - /* seperate out the useful data */ - if (strncasecmp(reply, "TT ", 3) == 0) { - reply += 3; - /* we have been given a Challenge */ - /* we should check we weren't given an empty challenge */ + if (reply) { + /* seperate out the useful data */ + if (strncasecmp(reply, "TT ", 3) == 0) { + reply += 3; + /* we have been given a Challenge */ + /* we should check we weren't given an empty challenge */ #if 0 - result=S_HELPER_RESERVE; + result = S_HELPER_RESERVE; #endif - /* copy the challenge to the state data */ - helperstate=helperStatefulServerGetData(lastserver); - if (helperstate == NULL) fatal ("lost NTLm helper state! quitting\n"); - helperstate->challenge=xstrndup(reply, NTLM_CHALLENGE_SZ+5); - helperstate->challengeuses=0; - helperstate->renewed=squid_curtime; - /* and we satisfy the request that happended on the refresh boundary */ - /* note this code is now in two places FIXME */ - assert(r->auth_user_request != NULL); - assert(r->auth_user_request->auth_user->auth_type == AUTH_NTLM); - auth_user_request=r->auth_user_request; - ntlm_request=auth_user_request->scheme_data; - assert(ntlm_request != NULL); - result=S_HELPER_DEFER; + /* copy the challenge to the state data */ + helperstate = helperStatefulServerGetData(lastserver); + if (helperstate == NULL) + fatal("lost NTLm helper state! quitting\n"); + helperstate->challenge = xstrndup(reply, NTLM_CHALLENGE_SZ + 5); + helperstate->challengeuses = 0; + helperstate->renewed = squid_curtime; + /* and we satisfy the request that happended on the refresh boundary */ + /* note this code is now in two places FIXME */ + assert(r->auth_user_request != NULL); + assert(r->auth_user_request->auth_user->auth_type == AUTH_NTLM); + auth_user_request = r->auth_user_request; + ntlm_request = auth_user_request->scheme_data; + assert(ntlm_request != NULL); + result = S_HELPER_DEFER; #if 0 - nextserver=lastserver; + nextserver = lastserver; #endif - debug(29,9)("authenticateNTLMHandleReply: helper '%d'\n",lastserver); - assert(ntlm_request->auth_state == AUTHENTICATE_STATE_NEGOTIATE); + debug(29, 9) ("authenticateNTLMHandleReply: helper '%d'\n", lastserver); + assert(ntlm_request->auth_state == AUTHENTICATE_STATE_NEGOTIATE); // auth_user->auth_data.ntlm_auth.auth_state = AUTHENTICATE_STATE_CHALLENGE; - ntlm_request->authhelper = lastserver; - ntlm_request->authchallenge = xstrndup(reply, NTLM_CHALLENGE_SZ+5); - } - else if (strncasecmp(reply, "AF ", 3) == 0) { - /* we're finished, release the helper*/ - reply+=3; - assert(r->auth_user_request != NULL); - assert(r->auth_user_request->auth_user->auth_type == AUTH_NTLM); - auth_user_request=r->auth_user_request; - assert(auth_user_request->scheme_data != NULL); - ntlm_request = auth_user_request->scheme_data; - auth_user = auth_user_request->auth_user; - ntlm_user = auth_user_request->auth_user->scheme_data; - assert(ntlm_user != NULL); - result=S_HELPER_RELEASE; - /* we only expect OK when finishing the handshake */ - assert(ntlm_request->auth_state == AUTHENTICATE_STATE_RESPONSE); - ntlm_user->username = xstrndup(reply, MAX_LOGIN_SZ); - ntlm_request->authhelper = NULL; - auth_user->flags.credentials_ok = 1; /* login ok */ - } - else if (strncasecmp(reply, "NA ", 3) == 0) { - /* TODO: only work with auth_user here if it exists */ - assert(r->auth_user_request != NULL); - assert(r->auth_user_request->auth_user->auth_type == AUTH_NTLM); - auth_user_request=r->auth_user_request; - auth_user = auth_user_request->auth_user; - assert(auth_user != NULL); - ntlm_user = auth_user->scheme_data; - ntlm_request = auth_user_request->scheme_data; - assert ((ntlm_user != NULL ) && (ntlm_request != NULL)); - /* todo: action of Negotiate state on error */ - result=S_HELPER_RELEASE; /*some error has occured. no more requests */ - ntlm_request->authhelper = NULL; - auth_user->flags.credentials_ok = 2; /* Login/Usercode failed */ - debug(29, 4) ("authenticateNTLMHandleReply: Error validating user via NTLM.\n"); - ntlm_request->auth_state = AUTHENTICATE_STATE_NONE; - if ((t = strchr(reply, ' ')))/* strip after a space */ + ntlm_request->authhelper = lastserver; + ntlm_request->authchallenge = xstrndup(reply, NTLM_CHALLENGE_SZ + 5); + } else if (strncasecmp(reply, "AF ", 3) == 0) { + /* we're finished, release the helper */ + reply += 3; + assert(r->auth_user_request != NULL); + assert(r->auth_user_request->auth_user->auth_type == AUTH_NTLM); + auth_user_request = r->auth_user_request; + assert(auth_user_request->scheme_data != NULL); + ntlm_request = auth_user_request->scheme_data; + auth_user = auth_user_request->auth_user; + ntlm_user = auth_user_request->auth_user->scheme_data; + assert(ntlm_user != NULL); + result = S_HELPER_RELEASE; + /* we only expect OK when finishing the handshake */ + assert(ntlm_request->auth_state == AUTHENTICATE_STATE_RESPONSE); + ntlm_user->username = xstrndup(reply, MAX_LOGIN_SZ); + ntlm_request->authhelper = NULL; + auth_user->flags.credentials_ok = 1; /* login ok */ + } else if (strncasecmp(reply, "NA ", 3) == 0) { + /* TODO: only work with auth_user here if it exists */ + assert(r->auth_user_request != NULL); + assert(r->auth_user_request->auth_user->auth_type == AUTH_NTLM); + auth_user_request = r->auth_user_request; + auth_user = auth_user_request->auth_user; + assert(auth_user != NULL); + ntlm_user = auth_user->scheme_data; + ntlm_request = auth_user_request->scheme_data; + assert((ntlm_user != NULL) && (ntlm_request != NULL)); + /* todo: action of Negotiate state on error */ + result = S_HELPER_RELEASE; /*some error has occured. no more requests */ + ntlm_request->authhelper = NULL; + auth_user->flags.credentials_ok = 2; /* Login/Usercode failed */ + debug(29, 4) ("authenticateNTLMHandleReply: Error validating user via NTLM.\n"); + ntlm_request->auth_state = AUTHENTICATE_STATE_NONE; + if ((t = strchr(reply, ' '))) /* strip after a space */ *t = '\0'; - } - else if (strncasecmp(reply, "BH ", 3) == 0) { - /* TODO kick off a refresh process. This can occur after a YR or after - a KK. If after a YR release the helper and resubmit the request via - Authenticate NTLM start. - If after a KK deny the user's request w/ 407 and mark the helper as - Needing YR.*/ - assert(r->auth_user_request != NULL); - assert(r->auth_user_request->auth_user->auth_type == AUTH_NTLM); - auth_user_request=r->auth_user_request; - auth_user = auth_user_request->auth_user; - assert(auth_user != NULL); - ntlm_user = auth_user->scheme_data; - ntlm_request = auth_user_request->scheme_data; - assert ((ntlm_user != NULL ) && (ntlm_request != NULL)); - result=S_HELPER_RELEASE; /*some error has occured. no more requests for - this helper */ - helperstate=helperStatefulServerGetData(ntlm_request->authhelper); - ntlm_request->authhelper = NULL; - if (ntlm_request->auth_state == AUTHENTICATE_STATE_NEGOTIATE) - { - /* The helper broke on YR. It automatically - * resets */ - auth_user->flags.credentials_ok = 3; /* cannot process */ - debug(29, 1) ("authenticateNTLMHandleReply: Error obtaining challenge from helper: %d.\n", lastserver); - /* mark it for starving */ - helperstate->starve=1; - /* resubmit the request. This helper is currently busy, so we will get - * a different one. */ - authenticateNTLMStart(auth_user_request, r->handler, r->data); - } else - { - /* the helper broke on a KK */ - /* first the standard KK stuff */ - auth_user->flags.credentials_ok = 2; /* Login/Usercode failed */ - debug(29, 4) ("authenticateNTLMHandleReply: Error validating user via NTLM.\n"); - ntlm_request->auth_state = AUTHENTICATE_STATE_NONE; - if ((t = strchr(reply, ' ')))/* strip after a space */ - *t = '\0'; - /* now we mark the helper for resetting. */ - helperstate->starve=1; - } - ntlm_request->auth_state = AUTHENTICATE_STATE_NONE; - } - else { - /* TODO: only work with auth_user here if it exists */ - assert(r->auth_user_request != NULL); - assert(r->auth_user_request->auth_user->auth_type == AUTH_NTLM); - auth_user_request=r->auth_user_request; - auth_user = auth_user_request->auth_user; - assert(auth_user != NULL); - ntlm_user = auth_user->scheme_data; - ntlm_request = auth_user_request->scheme_data; - assert ((ntlm_user != NULL ) && (ntlm_request != NULL)); - debug(29, 1) ("authenticateNTLMHandleReply: Unsupported helper response, '%s'\n", reply); - /* restart the authentication process */ - ntlm_request->auth_state = AUTHENTICATE_STATE_NONE; - auth_user->flags.credentials_ok = 3; /* cannot process */ - ntlm_request->authhelper = NULL; + } else if (strncasecmp(reply, "BH ", 3) == 0) { + /* TODO kick off a refresh process. This can occur after a YR or after + * a KK. If after a YR release the helper and resubmit the request via + * Authenticate NTLM start. + * If after a KK deny the user's request w/ 407 and mark the helper as + * Needing YR. */ + assert(r->auth_user_request != NULL); + assert(r->auth_user_request->auth_user->auth_type == AUTH_NTLM); + auth_user_request = r->auth_user_request; + auth_user = auth_user_request->auth_user; + assert(auth_user != NULL); + ntlm_user = auth_user->scheme_data; + ntlm_request = auth_user_request->scheme_data; + assert((ntlm_user != NULL) && (ntlm_request != NULL)); + result = S_HELPER_RELEASE; /*some error has occured. no more requests for + * this helper */ + helperstate = helperStatefulServerGetData(ntlm_request->authhelper); + ntlm_request->authhelper = NULL; + if (ntlm_request->auth_state == AUTHENTICATE_STATE_NEGOTIATE) { + /* The helper broke on YR. It automatically + * resets */ + auth_user->flags.credentials_ok = 3; /* cannot process */ + debug(29, 1) ("authenticateNTLMHandleReply: Error obtaining challenge from helper: %d.\n", lastserver); + /* mark it for starving */ + helperstate->starve = 1; + /* resubmit the request. This helper is currently busy, so we will get + * a different one. */ + authenticateNTLMStart(auth_user_request, r->handler, r->data); + } else { + /* the helper broke on a KK */ + /* first the standard KK stuff */ + auth_user->flags.credentials_ok = 2; /* Login/Usercode failed */ + debug(29, 4) ("authenticateNTLMHandleReply: Error validating user via NTLM.\n"); + ntlm_request->auth_state = AUTHENTICATE_STATE_NONE; + if ((t = strchr(reply, ' '))) /* strip after a space */ + *t = '\0'; + /* now we mark the helper for resetting. */ + helperstate->starve = 1; + } + ntlm_request->auth_state = AUTHENTICATE_STATE_NONE; + } else { + /* TODO: only work with auth_user here if it exists */ + assert(r->auth_user_request != NULL); + assert(r->auth_user_request->auth_user->auth_type == AUTH_NTLM); + auth_user_request = r->auth_user_request; + auth_user = auth_user_request->auth_user; + assert(auth_user != NULL); + ntlm_user = auth_user->scheme_data; + ntlm_request = auth_user_request->scheme_data; + assert((ntlm_user != NULL) && (ntlm_request != NULL)); + debug(29, 1) ("authenticateNTLMHandleReply: Unsupported helper response, '%s'\n", reply); + /* restart the authentication process */ + ntlm_request->auth_state = AUTHENTICATE_STATE_NONE; + auth_user->flags.credentials_ok = 3; /* cannot process */ + ntlm_request->authhelper = NULL; } - } else { - fatal("authenticateNTLMHandleReply: called with no result string\n"); - } - r->handler(r->data, NULL); + } else { + fatal("authenticateNTLMHandleReply: called with no result string\n"); + } + r->handler(r->data, NULL); } else { - debug(29,1) ("AuthenticateNTLMHandleReply: invalid callback data. Releasing helper '%d'.\n",lastserver); - result=S_HELPER_RELEASE; + debug(29, 1) ("AuthenticateNTLMHandleReply: invalid callback data. Releasing helper '%d'.\n", lastserver); + result = S_HELPER_RELEASE; } authenticateStateFree(r); - debug(29,9)("NTLM HandleReply, telling stateful helper : %d\n",result); + debug(29, 9) ("NTLM HandleReply, telling stateful helper : %d\n", result); return result; } @@ -553,6 +540,7 @@ { cbdataFree(r); } + #endif static void @@ -564,21 +552,24 @@ /* is a particular challenge still valid ? */ int -authenticateNTLMValidChallenge(ntlm_helper_state_t *helperstate) +authenticateNTLMValidChallenge(ntlm_helper_state_t * helperstate) { - if (helperstate->challenge == NULL) return 0; + if (helperstate->challenge == NULL) + return 0; return 1; } /* does our policy call for changing the challenge now? */ int -authenticateNTLMChangeChallenge(ntlm_helper_state_t *helperstate) +authenticateNTLMChangeChallenge(ntlm_helper_state_t * helperstate) { /* don't check for invalid challenges just for expiry choices */ /* this is needed because we have to starve the helper until all old * requests have been satisfied */ - if (helperstate->challengeuses>ntlmConfig->challengeuses) return 1; - if (helperstate->renewed+ntlmConfig->challengelifetime>=squid_curtime) return 1; + if (helperstate->challengeuses > ntlmConfig->challengeuses) + return 1; + if (helperstate->renewed + ntlmConfig->challengelifetime >= squid_curtime) + return 1; return 0; } @@ -593,46 +584,46 @@ helper_stateful_server *server; ntlm_helper_state_t *helperstate; char buf[8192]; - char *sent_string=NULL; - ntlm_user_t * ntlm_user; - ntlm_request_t * ntlm_request; - auth_user_t * auth_user; + char *sent_string = NULL; + ntlm_user_t *ntlm_user; + ntlm_request_t *ntlm_request; + auth_user_t *auth_user; assert(auth_user_request); - auth_user=auth_user_request->auth_user; - ntlm_user=auth_user->scheme_data; - ntlm_request=auth_user_request->scheme_data; + auth_user = auth_user_request->auth_user; + ntlm_user = auth_user->scheme_data; + ntlm_request = auth_user_request->scheme_data; assert(ntlm_user); assert(ntlm_request); assert(handler); assert(data); - assert(auth_user->auth_type=AUTH_NTLM); - debug(29,9)("authenticateNTLMStart: auth state '%d'\n",ntlm_request->auth_state); - switch(ntlm_request->auth_state) { - case AUTHENTICATE_STATE_NEGOTIATE: - sent_string = xstrdup(ntlm_request->ntlmnegotiate); - break; - case AUTHENTICATE_STATE_RESPONSE: - sent_string = xstrdup(ntlm_request->ntlmauthenticate); - assert(ntlm_request->authhelper); - debug(29, 9) ("authenticateNTLMStart: Asking NTLMauthenticator '%d'.\n", ntlm_request->authhelper); - break; - default: - fatal("Invalid authenticate state for NTLMStart"); + assert(auth_user->auth_type = AUTH_NTLM); + debug(29, 9) ("authenticateNTLMStart: auth state '%d'\n", ntlm_request->auth_state); + switch (ntlm_request->auth_state) { + case AUTHENTICATE_STATE_NEGOTIATE: + sent_string = xstrdup(ntlm_request->ntlmnegotiate); + break; + case AUTHENTICATE_STATE_RESPONSE: + sent_string = xstrdup(ntlm_request->ntlmauthenticate); + assert(ntlm_request->authhelper); + debug(29, 9) ("authenticateNTLMStart: Asking NTLMauthenticator '%d'.\n", ntlm_request->authhelper); + break; + default: + fatal("Invalid authenticate state for NTLMStart"); } - while (!xisspace(*sent_string)) /*trim NTLM */ - sent_string++; + while (!xisspace(*sent_string)) /*trim NTLM */ + sent_string++; - while (xisspace(*sent_string)) /*trim leading spaces */ - sent_string++; + while (xisspace(*sent_string)) /*trim leading spaces */ + sent_string++; debug(29, 9) ("authenticateNTLMStart: state '%d'\n", ntlm_request->auth_state); debug(29, 9) ("authenticateNTLMStart: '%s'\n", sent_string); if (ntlmConfig->authenticate == NULL) { - debug(29, 0) ("authenticateNTLMStart: no NTLM program specified:'%s'\n", sent_string); -// handler(data,0, NULL); - handler(data, NULL); + debug(29, 0) ("authenticateNTLMStart: no NTLM program specified:'%s'\n", sent_string); +// handler(data,0, NULL); + handler(data, NULL); return; } #ifdef NTLMHELPPROTOCOLV2 @@ -643,76 +634,72 @@ r->auth_user_request = auth_user_request; snprintf(buf, 8192, "%s\n", sent_string); helperStatefulSubmit(ntlmauthenticators, buf, authenticateNTLMHandleReply, r, ntlm_request->authhelper); - debug(29,9)("authenticateNTLMstart: finished\n"); + debug(29, 9) ("authenticateNTLMstart: finished\n"); #else /* this is ugly TODO: move the challenge generation routines to their own function and * tidy the logic up to make use of the efficiency we now have */ - switch(ntlm_request->auth_state) { - case AUTHENTICATE_STATE_NEGOTIATE: - /* - * 1: get a helper server - * 2: does it have a challenge? - * 3: tell it to get a challenge, or give ntlmauthdone the challenge - */ - server=helperStatefulDefer(ntlmauthenticators); - helperstate=server ? helperStatefulServerGetData(server): NULL ; - while ((server !=NULL) && - authenticateNTLMChangeChallenge(helperstate)) - { - /* flag this helper for challenge changing */ - helperstate->starve=1; - /* and release the deferred request */ - helperStatefulReleaseServer(server); - server=helperStatefulDefer(ntlmauthenticators); - if (server != NULL) - helperstate=helperStatefulServerGetData(server); - } - if (server==NULL) debug(29,9) ("unable to get a deferred ntlm helper... all helpers are refreshing challenges. Queuing as a placeholder request.\n"); - - ntlm_request->authhelper=server; - /* tell the log what helper we have been given */ - debug(29,9)("authenticateNTLMStart: helper '%d' assigned\n",server); - /* valid challenge? */ - if((server == NULL) || !authenticateNTLMValidChallenge(helperstate)) - { - r = CBDATA_ALLOC(authenticateStateData, NULL); - r->handler = handler; - cbdataLock(data); - r->data = data; - r->auth_user_request = auth_user_request; - if (server == NULL) - { - helperStatefulSubmit(ntlmauthenticators, NULL, authenticateNTLMHandleplaceholder, r, ntlm_request->authhelper); - } - else - { - snprintf(buf, 8192, "YR\n"); - helperStatefulSubmit(ntlmauthenticators, buf, authenticateNTLMHandleReply, r, ntlm_request->authhelper); - } - } else { - /* we have a valid challenge */ - /* TODO: turn the below into a function and call from here and handlereply */ - /* increment the challenge uses */ - helperstate->challengeuses++; - /* assign the challenge */ - ntlm_request->authchallenge = - xstrndup(helperstate->challenge, NTLM_CHALLENGE_SZ+5); - handler(data, NULL); - } - - break; - case AUTHENTICATE_STATE_RESPONSE: - r = CBDATA_ALLOC(authenticateStateData, NULL); - r->handler = handler; - cbdataLock(data); - r->data = data; - r->auth_user_request = auth_user_request; - snprintf(buf, 8192, "KK %s\n", sent_string); - helperStatefulSubmit(ntlmauthenticators, buf, authenticateNTLMHandleReply, r, ntlm_request->authhelper); - debug(29,9)("authenticateNTLMstart: finished\n"); - break; - default: - fatal("Invalid authenticate state for NTLMStart"); + switch (ntlm_request->auth_state) { + case AUTHENTICATE_STATE_NEGOTIATE: + /* + * 1: get a helper server + * 2: does it have a challenge? + * 3: tell it to get a challenge, or give ntlmauthdone the challenge + */ + server = helperStatefulDefer(ntlmauthenticators); + helperstate = server ? helperStatefulServerGetData(server) : NULL; + while ((server != NULL) && + authenticateNTLMChangeChallenge(helperstate)) { + /* flag this helper for challenge changing */ + helperstate->starve = 1; + /* and release the deferred request */ + helperStatefulReleaseServer(server); + server = helperStatefulDefer(ntlmauthenticators); + if (server != NULL) + helperstate = helperStatefulServerGetData(server); + } + if (server == NULL) + debug(29, 9) ("unable to get a deferred ntlm helper... all helpers are refreshing challenges. Queuing as a placeholder request.\n"); + + ntlm_request->authhelper = server; + /* tell the log what helper we have been given */ + debug(29, 9) ("authenticateNTLMStart: helper '%d' assigned\n", server); + /* valid challenge? */ + if ((server == NULL) || !authenticateNTLMValidChallenge(helperstate)) { + r = CBDATA_ALLOC(authenticateStateData, NULL); + r->handler = handler; + cbdataLock(data); + r->data = data; + r->auth_user_request = auth_user_request; + if (server == NULL) { + helperStatefulSubmit(ntlmauthenticators, NULL, authenticateNTLMHandleplaceholder, r, ntlm_request->authhelper); + } else { + snprintf(buf, 8192, "YR\n"); + helperStatefulSubmit(ntlmauthenticators, buf, authenticateNTLMHandleReply, r, ntlm_request->authhelper); + } + } else { + /* we have a valid challenge */ + /* TODO: turn the below into a function and call from here and handlereply */ + /* increment the challenge uses */ + helperstate->challengeuses++; + /* assign the challenge */ + ntlm_request->authchallenge = + xstrndup(helperstate->challenge, NTLM_CHALLENGE_SZ + 5); + handler(data, NULL); + } + + break; + case AUTHENTICATE_STATE_RESPONSE: + r = CBDATA_ALLOC(authenticateStateData, NULL); + r->handler = handler; + cbdataLock(data); + r->data = data; + r->auth_user_request = auth_user_request; + snprintf(buf, 8192, "KK %s\n", sent_string); + helperStatefulSubmit(ntlmauthenticators, buf, authenticateNTLMHandleReply, r, ntlm_request->authhelper); + debug(29, 9) ("authenticateNTLMstart: finished\n"); + break; + default: + fatal("Invalid authenticate state for NTLMStart"); } #endif } @@ -721,77 +708,76 @@ int authenticateNTLMHelperServerAvailable(void *data) { - ntlm_helper_state_t *statedata=data; - if (statedata != NULL) - { - if (statedata->starve) - { - debug(29,4)("authenticateNTLMHelperServerAvailable: starving - returning 0\n"); - return 0; - } - else - { - debug(29,4)("authenticateNTLMHelperServerAvailable: not startving - returning 1\n"); - return 1; - } + ntlm_helper_state_t *statedata = data; + if (statedata != NULL) { + if (statedata->starve) { + debug(29, 4) ("authenticateNTLMHelperServerAvailable: starving - returning 0\n"); + return 0; + } else { + debug(29, 4) ("authenticateNTLMHelperServerAvailable: not startving - returning 1\n"); + return 1; + } } - debug(29,4)("authenticateNTLMHelperServerAvailable: no state data - returning 0\n"); + debug(29, 4) ("authenticateNTLMHelperServerAvailable: no state data - returning 0\n"); return 0; } void authenticateNTLMHelperServerOnEmpty(void *data) { - ntlm_helper_state_t *statedata=data; - if (statedata == NULL) return; - if (statedata->starve) - { - /* we have been starving the helper */ - debug(29,9)("authenticateNTLMHelperServerOnEmpty: resetting challenge details\n"); - statedata->starve=0; - statedata->challengeuses=0; - statedata->renewed=0; - xfree(statedata->challenge); - statedata->challenge=NULL; + ntlm_helper_state_t *statedata = data; + if (statedata == NULL) + return; + if (statedata->starve) { + /* we have been starving the helper */ + debug(29, 9) ("authenticateNTLMHelperServerOnEmpty: resetting challenge details\n"); + statedata->starve = 0; + statedata->challengeuses = 0; + statedata->renewed = 0; + xfree(statedata->challenge); + statedata->challenge = NULL; } } /* clear the NTLM helper of being reserved for future requests */ void -authenticateNTLMReleasehelper(auth_user_request_t *auth_user_request){ - ntlm_request_t * ntlm_request; - assert(auth_user_request->auth_user->auth_type==AUTH_NTLM); +authenticateNTLMReleasehelper(auth_user_request_t * auth_user_request) +{ + ntlm_request_t *ntlm_request; + assert(auth_user_request->auth_user->auth_type == AUTH_NTLM); assert(auth_user_request->scheme_data != NULL); ntlm_request = auth_user_request->scheme_data; - debug(29,9) ("authenticateNTLMReleasehelper: releasing helper '%d'\n",ntlm_request->authhelper); + debug(29, 9) ("authenticateNTLMReleasehelper: releasing helper '%d'\n", ntlm_request->authhelper); helperStatefulReleaseServer(ntlm_request->authhelper); - ntlm_request->authhelper=NULL; + ntlm_request->authhelper = NULL; } /* clear any connection related authentication details */ void -authenticateNTLMOnCloseConnection(ConnStateData *conn) { - ntlm_request_t * ntlm_request; - assert(conn !=NULL); +authenticateNTLMOnCloseConnection(ConnStateData * conn) +{ + ntlm_request_t *ntlm_request; + assert(conn != NULL); if (conn->auth_user_request != NULL) { - assert(conn->auth_user_request->scheme_data != NULL); - ntlm_request = conn->auth_user_request->scheme_data; - if (ntlm_request->authhelper != NULL) - authenticateNTLMReleasehelper(conn->auth_user_request); - /* unlock the connection based lock */ - debug (29,9)("authenticateNTLMOnCloseConnection: Unlocking auth_user from the connection.\n"); - authenticateAuthUserRequestUnlock(conn->auth_user_request); - conn->auth_user_request = NULL; + assert(conn->auth_user_request->scheme_data != NULL); + ntlm_request = conn->auth_user_request->scheme_data; + if (ntlm_request->authhelper != NULL) + authenticateNTLMReleasehelper(conn->auth_user_request); + /* unlock the connection based lock */ + debug(29, 9) ("authenticateNTLMOnCloseConnection: Unlocking auth_user from the connection.\n"); + authenticateAuthUserRequestUnlock(conn->auth_user_request); + conn->auth_user_request = NULL; } } /* authenticateUserUsername: return a pointer to the username in the */ char * -authenticateNTLMUsername(auth_user_t *auth_user) { - ntlm_user_t * ntlm_user=auth_user->scheme_data; - if(ntlm_user) - return ntlm_user->username; +authenticateNTLMUsername(auth_user_t * auth_user) +{ + ntlm_user_t *ntlm_user = auth_user->scheme_data; + if (ntlm_user) + return ntlm_user->username; return NULL; } @@ -802,41 +788,42 @@ */ void -authenticateDecodeNTLMAuth(auth_user_request_t *auth_user_request, const char * proxy_auth) +authenticateDecodeNTLMAuth(auth_user_request_t * auth_user_request, const char *proxy_auth) { - dlink_node * node; + dlink_node *node; assert(auth_user_request->auth_user == NULL); - auth_user_request->auth_user=authenticateAuthUserNew("ntlm"); + auth_user_request->auth_user = authenticateAuthUserNew("ntlm"); auth_user_request->auth_user->auth_type = AUTH_NTLM; auth_user_request->auth_user->scheme_data = memPoolAlloc(ntlm_user_pool); auth_user_request->scheme_data = memPoolAlloc(ntlm_request_pool); /* lock for the auth_user_request link */ authenticateAuthUserLock(auth_user_request->auth_user); - node=dlinkNodeNew(); + node = dlinkNodeNew(); dlinkAdd(auth_user_request, node, &auth_user_request->auth_user->requests); - + /* all we have to do is identify that it's NTLM - the helper does the rest */ debug(29, 9) ("authenticateDecodeNTLMAuth: NTLM authentication\n"); return; } -int authenticateNTLMcmpUsername(ntlm_user_t *u1, ntlm_user_t *u2) +int +authenticateNTLMcmpUsername(ntlm_user_t * u1, ntlm_user_t * u2) { return strcmp(u1->username, u2->username); } void -authenticateProxyAuthCacheAddLink(const char *key, auth_user_t *auth_user) +authenticateProxyAuthCacheAddLink(const char *key, auth_user_t * auth_user) { auth_user_hash_pointer *proxy_auth_hash; - ntlm_user_t * ntlm_user; + ntlm_user_t *ntlm_user; proxy_auth_hash = - memAllocate(MEM_AUTH_USER_HASH); + memAllocate(MEM_AUTH_USER_HASH); proxy_auth_hash->key = xstrdup(key); proxy_auth_hash->auth_user = auth_user; - ntlm_user=auth_user->scheme_data; + ntlm_user = auth_user->scheme_data; dlinkAddTail(proxy_auth_hash, &proxy_auth_hash->link, - &ntlm_user->proxy_auth_list); + &ntlm_user->proxy_auth_list); hash_join(proxy_auth_cache, (hash_link *) proxy_auth_hash); } @@ -845,190 +832,184 @@ authNTLMAuthenticated(auth_user_request_t * auth_user_request) { ntlm_request_t *ntlm_request = auth_user_request->scheme_data; - if (ntlm_request->auth_state==AUTHENTICATE_STATE_DONE) - return 1; - debug (29, 9) ("User not fully authenticated.\n"); + if (ntlm_request->auth_state == AUTHENTICATE_STATE_DONE) + return 1; + debug(29, 9) ("User not fully authenticated.\n"); return 0; } #if 0 static acl_proxy_auth_user * -authenticateNTLMAuthenticateUser(void *data, const char * proxy_auth, ConnStateData *conn) { -#endif +authenticateNTLMAuthenticateUser(void *data, const char *proxy_auth, ConnStateData * conn) +#else static void -authenticateNTLMAuthenticateUser(auth_user_request_t *auth_user_request, request_t *request, ConnStateData *conn, http_hdr_type type) { - const char * proxy_auth; - auth_user_hash_pointer *usernamehash, *proxy_auth_hash=NULL; - auth_user_t * auth_user; - ntlm_request_t * ntlm_request; - ntlm_user_t * ntlm_user; +authenticateNTLMAuthenticateUser(auth_user_request_t * auth_user_request, request_t * request, ConnStateData * conn, http_hdr_type type) +#endif +{ + const char *proxy_auth; + auth_user_hash_pointer *usernamehash, *proxy_auth_hash = NULL; + auth_user_t *auth_user; + ntlm_request_t *ntlm_request; + ntlm_user_t *ntlm_user; LOCAL_ARRAY(char, ntlmhash, NTLM_CHALLENGE_SZ * 2); /* get header */ proxy_auth = httpHeaderGetStr(&request->header, type); - - auth_user=auth_user_request->auth_user; + + auth_user = auth_user_request->auth_user; assert(auth_user); - assert(auth_user->auth_type==AUTH_NTLM); + assert(auth_user->auth_type == AUTH_NTLM); assert(auth_user->scheme_data != NULL); assert(auth_user_request->scheme_data != NULL); - ntlm_user=auth_user->scheme_data; - ntlm_request=auth_user_request->scheme_data; + ntlm_user = auth_user->scheme_data; + ntlm_request = auth_user_request->scheme_data; switch (ntlm_request->auth_state) { - case AUTHENTICATE_STATE_NONE: - /* we've recieved a negotiate request. pass to a helper */ - debug(29, 9) ("authenticateNTLMAuthenticateUser: auth state ntlm none. %s\n", - proxy_auth); - ntlm_request->auth_state = AUTHENTICATE_STATE_NEGOTIATE; - ntlm_request->ntlmnegotiate=xstrndup(proxy_auth, NTLM_CHALLENGE_SZ+5); - conn->auth_type=AUTH_NTLM; - conn->auth_user_request=auth_user_request; - /* and lock for the connection duration */ - debug (29,9)("authenticateNTLMAuthenticateUser: Locking auth_user from the connection.\n"); - authenticateAuthUserRequestLock(auth_user_request); - return; - break; - case AUTHENTICATE_STATE_NEGOTIATE: - ntlm_request->auth_state = AUTHENTICATE_STATE_CHALLENGE; - return; - break; - case AUTHENTICATE_STATE_CHALLENGE: - /* we should have recieved a NTLM challenge. pass it to the same - * helper process */ - debug(29,9) ("authenticateNTLMAuthenticateUser: auth state challenge with header %s.\n", proxy_auth); - /* do a cache lookup here. If it matches it's a successful ntlm - * challenge - release the helper and use the existing auth_user - * details. */ - if (strncmp("NTLM ", proxy_auth, 5) == 0) { - ntlm_request->ntlmauthenticate = xstrdup(proxy_auth); - } else { - fatal("Incorrect scheme in auth header\n"); - /* TODO: more fault tolerance.. reset the auth scheme here */ - } - /* cache entries have authenticateauthheaderchallengestring */ - snprintf(ntlmhash, sizeof(ntlmhash) - 1, "%s%s", - ntlm_request->ntlmauthenticate, - ntlm_request->authchallenge); - /* see if we already know this user's authenticate */ - debug(29,9)("aclMatchProxyAuth: cache lookup with key '%s'\n",ntlmhash); - assert(proxy_auth_cache!=NULL); - proxy_auth_hash = hash_lookup(proxy_auth_cache, ntlmhash); - if (!proxy_auth_hash) { /* not in the hash table */ - debug(29,4)("authenticateNTLMAuthenticateUser: proxy-auth cache miss.\n"); - ntlm_request->auth_state = AUTHENTICATE_STATE_RESPONSE; - /* verify with the ntlm helper */ - } else { - debug(29,4)("authenticateNTLMAuthenticateUser: ntlm proxy-auth cache hit\n"); - /* throw away the temporary entry */ - authenticateNTLMReleasehelper(auth_user_request); - authenticateAuthUserMerge(auth_user,proxy_auth_hash->auth_user); - auth_user = proxy_auth_hash->auth_user; - auth_user_request->auth_user=auth_user; - ntlm_request->auth_state=AUTHENTICATE_STATE_DONE; - /* we found one */ - debug(29, 9) ("found matching cache entry\n"); - assert(auth_user->auth_type == AUTH_NTLM); - /* get the existing entries details */ - ntlm_user = auth_user->scheme_data; - debug(29, 9) ("Username to be used is %s\n", - ntlm_user->username); - auth_user->flags.credentials_ok = 1; /* authenticated ok */ - /* on ntlm auth we do not unlock the auth_user until the - * connection is dropped. Thank MS for this quirk */ - auth_user->expiretime = current_time.tv_sec ; - auth_user->ip_expiretime = squid_curtime; - } - return; - break; - case AUTHENTICATE_STATE_RESPONSE: - /* auth-challenge pair cache miss. We've just got the response */ - /*add to cache and let them through */ - ntlm_request->auth_state = AUTHENTICATE_STATE_DONE; - /* this connection is authenticated */ - debug(29, 4) ("authenticated\nch %s\nauth %s\nauthuser %s\n", - ntlm_request->authchallenge, - ntlm_request->ntlmauthenticate, - ntlm_user->username); - /* cache entries have authenticateauthheaderchallengestring */ - snprintf(ntlmhash, sizeof(ntlmhash) - 1, "%s%s", - ntlm_request->ntlmauthenticate, - ntlm_request->authchallenge); - /* see if this is an existing user with a different proxy_auth - * string */ - if ((usernamehash = hash_lookup(proxy_auth_username_cache, - ntlm_user->username))) { - while ((usernamehash->auth_user->auth_type != - auth_user->auth_type) && (usernamehash->next) && - !authenticateNTLMcmpUsername(usernamehash->auth_user->scheme_data, ntlm_user) ) - usernamehash=usernamehash->next; - if (usernamehash->auth_user->auth_type==auth_user->auth_type) { - /* - * add another link from the new proxy_auth to the - * auth_user structure and update the information */ - assert(proxy_auth_hash == NULL); - authenticateProxyAuthCacheAddLink(ntlmhash, usernamehash->auth_user); - /* we can't seamlessly recheck the username due to the - * challenge nature of the protocol. Just free the - * temporary auth_user */ - authenticateAuthUserMerge(auth_user,usernamehash->auth_user); - auth_user = usernamehash->auth_user; - auth_user_request->auth_user=auth_user; + case AUTHENTICATE_STATE_NONE: + /* we've recieved a negotiate request. pass to a helper */ + debug(29, 9) ("authenticateNTLMAuthenticateUser: auth state ntlm none. %s\n", + proxy_auth); + ntlm_request->auth_state = AUTHENTICATE_STATE_NEGOTIATE; + ntlm_request->ntlmnegotiate = xstrndup(proxy_auth, NTLM_CHALLENGE_SZ + 5); + conn->auth_type = AUTH_NTLM; + conn->auth_user_request = auth_user_request; + /* and lock for the connection duration */ + debug(29, 9) ("authenticateNTLMAuthenticateUser: Locking auth_user from the connection.\n"); + authenticateAuthUserRequestLock(auth_user_request); + return; + break; + case AUTHENTICATE_STATE_NEGOTIATE: + ntlm_request->auth_state = AUTHENTICATE_STATE_CHALLENGE; + return; + break; + case AUTHENTICATE_STATE_CHALLENGE: + /* we should have recieved a NTLM challenge. pass it to the same + * helper process */ + debug(29, 9) ("authenticateNTLMAuthenticateUser: auth state challenge with header %s.\n", proxy_auth); + /* do a cache lookup here. If it matches it's a successful ntlm + * challenge - release the helper and use the existing auth_user + * details. */ + if (strncmp("NTLM ", proxy_auth, 5) == 0) { + ntlm_request->ntlmauthenticate = xstrdup(proxy_auth); + } else { + fatal("Incorrect scheme in auth header\n"); + /* TODO: more fault tolerance.. reset the auth scheme here */ + } + /* cache entries have authenticateauthheaderchallengestring */ + snprintf(ntlmhash, sizeof(ntlmhash) - 1, "%s%s", + ntlm_request->ntlmauthenticate, + ntlm_request->authchallenge); + /* see if we already know this user's authenticate */ + debug(29, 9) ("aclMatchProxyAuth: cache lookup with key '%s'\n", ntlmhash); + assert(proxy_auth_cache != NULL); + proxy_auth_hash = hash_lookup(proxy_auth_cache, ntlmhash); + if (!proxy_auth_hash) { /* not in the hash table */ + debug(29, 4) ("authenticateNTLMAuthenticateUser: proxy-auth cache miss.\n"); + ntlm_request->auth_state = AUTHENTICATE_STATE_RESPONSE; + /* verify with the ntlm helper */ + } else { + debug(29, 4) ("authenticateNTLMAuthenticateUser: ntlm proxy-auth cache hit\n"); + /* throw away the temporary entry */ + authenticateNTLMReleasehelper(auth_user_request); + authenticateAuthUserMerge(auth_user, proxy_auth_hash->auth_user); + auth_user = proxy_auth_hash->auth_user; + auth_user_request->auth_user = auth_user; + ntlm_request->auth_state = AUTHENTICATE_STATE_DONE; + /* we found one */ + debug(29, 9) ("found matching cache entry\n"); + assert(auth_user->auth_type == AUTH_NTLM); + /* get the existing entries details */ + ntlm_user = auth_user->scheme_data; + debug(29, 9) ("Username to be used is %s\n", + ntlm_user->username); + auth_user->flags.credentials_ok = 1; /* authenticated ok */ + /* on ntlm auth we do not unlock the auth_user until the + * connection is dropped. Thank MS for this quirk */ + auth_user->expiretime = current_time.tv_sec; + auth_user->ip_expiretime = squid_curtime; + } + return; + break; + case AUTHENTICATE_STATE_RESPONSE: + /* auth-challenge pair cache miss. We've just got the response */ + /*add to cache and let them through */ + ntlm_request->auth_state = AUTHENTICATE_STATE_DONE; + /* this connection is authenticated */ + debug(29, 4) ("authenticated\nch %s\nauth %s\nauthuser %s\n", + ntlm_request->authchallenge, + ntlm_request->ntlmauthenticate, + ntlm_user->username); + /* cache entries have authenticateauthheaderchallengestring */ + snprintf(ntlmhash, sizeof(ntlmhash) - 1, "%s%s", + ntlm_request->ntlmauthenticate, + ntlm_request->authchallenge); + /* see if this is an existing user with a different proxy_auth + * string */ + if ((usernamehash = hash_lookup(proxy_auth_username_cache, + ntlm_user->username))) { + while ((usernamehash->auth_user->auth_type != + auth_user->auth_type) && (usernamehash->next) && + !authenticateNTLMcmpUsername(usernamehash->auth_user->scheme_data, ntlm_user)) + usernamehash = usernamehash->next; + if (usernamehash->auth_user->auth_type == auth_user->auth_type) { + /* + * add another link from the new proxy_auth to the + * auth_user structure and update the information */ + assert(proxy_auth_hash == NULL); + authenticateProxyAuthCacheAddLink(ntlmhash, usernamehash->auth_user); + /* we can't seamlessly recheck the username due to the + * challenge nature of the protocol. Just free the + * temporary auth_user */ + authenticateAuthUserMerge(auth_user, usernamehash->auth_user); + auth_user = usernamehash->auth_user; + auth_user_request->auth_user = auth_user; #if 0 - conn->auth_user=auth_user; + conn->auth_user = auth_user; #endif - } - } else { - /* store user in hash's */ - authenticateUserNameCacheAdd(auth_user); - authenticateProxyAuthCacheAddLink(ntlmhash, auth_user); - } - /* set these to now because this is either a new login from an - * existing user or a new user */ - auth_user->expiretime = current_time.tv_sec ; - auth_user->ip_expiretime = squid_curtime; - auth_user->flags.credentials_ok=1; /*authenticated ok */ - return; - break; + } + } else { + /* store user in hash's */ + authenticateUserNameCacheAdd(auth_user); + authenticateProxyAuthCacheAddLink(ntlmhash, auth_user); + } + /* set these to now because this is either a new login from an + * existing user or a new user */ + auth_user->expiretime = current_time.tv_sec; + auth_user->ip_expiretime = squid_curtime; + auth_user->flags.credentials_ok = 1; /*authenticated ok */ + return; + break; case AUTHENTICATE_STATE_DONE: - fatal("authenticateNTLMAuthenticateUser: unexpect auth state DONE! Report a bug to the squid developers.\n"); -#if 0 -done in acl.c + fatal("authenticateNTLMAuthenticateUser: unexpect auth state DONE! Report a bug to the squid developers.\n"); +#if 0 /* done in acl.c */ case AUTHENTICATE_STATE_DONE: - debug(28, 5) ("aclMatchProxyAuth: connection in state Done. using connec -tion credentials for the request.\n"); - /* is it working right? */ - assert(checklist->auth_user == NULL); - assert(checklist->conn->auth_user != NULL); - /* we have a valid username. */ - auth_user = checklist->conn->auth_user; - /* store the username in the request for logging */ - xstrncpy(checklist->request->authuser, - auth_user->auth_data.ntlm_auth.username, - USER_IDENT_SZ); - if (auth_user->expiretime + Config.authenticateTTL > current_time.tv_sec -) - { - auth_user->expiretime = current_time.tv_sec; - } - else{ - //user passed externa; authentication in every case to get here. f. -Let it through - } - - /* we don't unlock the auth_user until the connection is dropped. Thank - * MS for this quirk. */ - if (authenticateCheckAuthUserIP(checklist->src_addr, auth_user)){ - /* Once the match is completed we have finished with the - * auth_user structure */ - /* check to see if we have matched the user-acl before */ - return aclCacheMatchAcl(&auth_user->proxy_match_cache, acltype, - data, auth_user->auth_data.ntlm_auth.username); - } else { - return 0; - } - break; + debug(28, 5) ("aclMatchProxyAuth: connection in state Done. using connection credentials for the request. \n"); + /* is it working right? */ + assert(checklist->auth_user == NULL); + assert(checklist->conn->auth_user != NULL); + /* we have a valid username. */ + auth_user = checklist->conn->auth_user; + /* store the username in the request for logging */ + xstrncpy(checklist->request->authuser, + auth_user->auth_data.ntlm_auth.username, + USER_IDENT_SZ); + if (auth_user->expiretime + Config.authenticateTTL > current_time.tv_sec + ) { + auth_user->expiretime = current_time.tv_sec; + } else { + //user passed externa; authentication in every case to get here. f. + Let it through + } /* we don't unlock the auth_user until the connection is dropped. Thank + * MS for this quirk. */ if (authenticateCheckAuthUserIP(checklist->src_addr, auth_user)) { + /* Once the match is completed we have finished with the + * auth_user structure */ + /* check to see if we have matched the user-acl before */ + return aclCacheMatchAcl(&auth_user->proxy_match_cache, acltype, + data, auth_user->auth_data.ntlm_auth.username); + } else { + return 0; + } + break; #endif } return; } - Index: squid/src/auth/ntlm/auth_ntlm.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/auth/ntlm/auth_ntlm.h,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- squid/src/auth/ntlm/auth_ntlm.h 7 Jan 2001 02:49:32 -0000 1.1.2.6 +++ squid/src/auth/ntlm/auth_ntlm.h 7 Jan 2001 09:48:32 -0000 1.1.2.7 @@ -6,7 +6,7 @@ #ifndef __AUTH_NTLM_H__ #define __AUTH_NTLM_H__ -#define DefaultAuthenticateChildrenMax 32 /* 32 processes */ +#define DefaultAuthenticateChildrenMax 32 /* 32 processes */ /* Generic */ typedef struct { @@ -28,16 +28,16 @@ char *authchallenge; /* what authenticate string did we get? */ char *ntlmauthenticate; - /*we need to store the NTLM helper between requests*/ - helper_stateful_server * authhelper; + /*we need to store the NTLM helper between requests */ + helper_stateful_server *authhelper; /* how far through the authentication process are we? */ auth_state_t auth_state; }; struct _ntlm_helper_state_t { - char *challenge; /* the challenge to use with this helper */ - int starve; /* 0= normal operation. 1=don't hand out any more challenges */ - int challengeuses; /* the number of times this challenge has been issued */ + char *challenge; /* the challenge to use with this helper */ + int starve; /* 0= normal operation. 1=don't hand out any more challenges */ + int challengeuses; /* the number of times this challenge has been issued */ time_t renewed; }; Index: squid/src/fs/ufs/store_dir_ufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/ufs/store_dir_ufs.c,v retrieving revision 1.1.10.8.2.4 retrieving revision 1.1.10.8.2.5 diff -u -r1.1.10.8.2.4 -r1.1.10.8.2.5 --- squid/src/fs/ufs/store_dir_ufs.c 5 Jan 2001 22:45:29 -0000 1.1.10.8.2.4 +++ squid/src/fs/ufs/store_dir_ufs.c 7 Jan 2001 09:48:32 -0000 1.1.10.8.2.5 @@ -348,9 +348,9 @@ { static int started_clean_event = 0; static const char *errmsg = - "\tFailed to verify one of the swap directories, Check cache.log\n" - "\tfor details. Run 'squid -z' to create swap directories\n" - "\tif needed, or if running Squid for the first time."; + "\tFailed to verify one of the swap directories, Check cache.log\n" + "\tfor details. Run 'squid -z' to create swap directories\n" + "\tif needed, or if running Squid for the first time."; storeUfsDirInitBitmap(sd); if (storeUfsDirVerifyCacheDirs(sd) < 0) fatal(errmsg); Index: squid/src/repl/lru/store_repl_lru.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/repl/lru/store_repl_lru.c,v retrieving revision 1.1.10.2.2.1 retrieving revision 1.1.10.2.2.2 diff -u -r1.1.10.2.2.1 -r1.1.10.2.2.2 --- squid/src/repl/lru/store_repl_lru.c 5 Jan 2001 22:45:29 -0000 1.1.10.2.2.1 +++ squid/src/repl/lru/store_repl_lru.c 7 Jan 2001 09:48:33 -0000 1.1.10.2.2.2 @@ -162,7 +162,7 @@ RemovalPolicyWalker *walker; LruWalkData *lru_walk; lru->nwalkers += 1; - walker=CBDATA_ALLOC(RemovalPolicyWalker, NULL); + walker = CBDATA_ALLOC(RemovalPolicyWalker, NULL); lru_walk = xcalloc(1, sizeof(*lru_walk)); walker->_policy = policy; walker->_data = lru_walk; @@ -231,7 +231,7 @@ RemovalPurgeWalker *walker; LruPurgeData *lru_walk; lru->nwalkers += 1; - walker=CBDATA_ALLOC(RemovalPurgeWalker, NULL); + walker = CBDATA_ALLOC(RemovalPurgeWalker, NULL); lru_walk = xcalloc(1, sizeof(*lru_walk)); walker->_policy = policy; walker->_data = lru_walk; @@ -268,7 +268,7 @@ lru_node_pool = memPoolCreate("LRU policy node", sizeof(LruNode)); /* Allocate the needed structures */ lru_data = xcalloc(1, sizeof(*lru_data)); - policy=CBDATA_ALLOC(RemovalPolicy, NULL); + policy = CBDATA_ALLOC(RemovalPolicy, NULL); /* Initialize the URL data */ lru_data->policy = policy; /* Populate the policy structure */ Index: squid/test-suite/hash.c =================================================================== RCS file: /cvsroot/squid-sf//squid/test-suite/hash.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.26.1 diff -u -r1.1.1.1 -r1.1.1.1.26.1 --- squid/test-suite/hash.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/test-suite/hash.c 7 Jan 2001 09:48:33 -0000 1.1.1.1.26.1 @@ -1,6 +1,6 @@ /* - * $Id: hash.c,v 1.1.1.1 2000/01/26 03:21:47 hno Exp $ + * $Id: hash.c,v 1.1.1.1.26.1 2001/01/07 09:48:33 hno Exp $ * * DEBUG: section 0 Hash Tables * AUTHOR: Harvest Derived @@ -39,7 +39,7 @@ #include #include "hash.h" #undef free -extern void my_free(char *, int , void *); +extern void my_free(char *, int, void *); #define free(a) my_free(__FILE__, __LINE__, a) @@ -176,7 +176,7 @@ /* Add to the given hash table 'hid' */ new = calloc(1, sizeof(hash_link)); if (!new) { - fprintf(stderr,"calloc failed!\n"); + fprintf(stderr, "calloc failed!\n"); print_stats(); exit(1); } @@ -298,7 +298,7 @@ hid->current_ptr = walker->next; if (FreeLink) { if (walker) { - free(walker); + free(walker); } } return 0; @@ -337,10 +337,10 @@ void hashFreeMemory(hash_table * hid) { - if (hid->buckets); + if (hid->buckets); free(hid->buckets); - if (hid) - free(hid); + if (hid) + free(hid); } @@ -402,4 +402,3 @@ exit(0); } #endif - Index: squid/test-suite/hash.h =================================================================== RCS file: /cvsroot/squid-sf//squid/test-suite/hash.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.30.1 diff -u -r1.1.1.1 -r1.1.1.1.30.1 --- squid/test-suite/hash.h 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/test-suite/hash.h 7 Jan 2001 09:48:33 -0000 1.1.1.1.30.1 @@ -1,6 +1,6 @@ -#define DEFAULT_HASH_SIZE 7951 +#define DEFAULT_HASH_SIZE 7951 typedef unsigned int HASHHASH(const void *, unsigned int); -struct _hash_link { +struct _hash_link { char *key; struct _hash_link *next; void *item; @@ -17,17 +17,17 @@ unsigned int size; unsigned int current_slot; hash_link *current_ptr; -}; +}; typedef struct _hash_table hash_table; extern int hash_links_allocated; -extern int store_hash_buckets; /* 0 */ -extern hash_table *store_table; /* NULL */ +extern int store_hash_buckets; /* 0 */ +extern hash_table *store_table; /* NULL */ extern hash_table *hash_create(HASHCMP *, int, HASHHASH *); extern void hash_insert(hash_table *, const char *, void *); extern int hash_delete(hash_table *, const char *); int hash_delete_link(hash_table *, hash_link *); -int hash_unlink(hash_table *,hash_link *, int); +int hash_unlink(hash_table *, hash_link *, int); void hash_join(hash_table *, hash_link *); int hash_remove_link(hash_table *, hash_link *); hash_link *hash_lookup(hash_table *, const void *); Index: squid/test-suite/membanger.c =================================================================== RCS file: /cvsroot/squid-sf//squid/test-suite/membanger.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.30.1 diff -u -r1.1.1.1 -r1.1.1.1.30.1 --- squid/test-suite/membanger.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/test-suite/membanger.c 7 Jan 2001 09:48:33 -0000 1.1.1.1.30.1 @@ -39,7 +39,7 @@ int i; int a; -int run_stats=0; +int run_stats = 0; void *my_xmalloc(size_t); void *my_xcalloc(int, size_t); int my_xfree(void *); @@ -49,163 +49,172 @@ #define xfree my_xfree int *size2id_array[2]; -int size2id_len=0; -int size2id_alloc=0; +int size2id_len = 0; +int size2id_alloc = 0; typedef struct { - char orig_ptr[32]; - void *my_ptr; + char orig_ptr[32]; + void *my_ptr; #ifdef WITH_LIB - MemPool *pool; + MemPool *pool; #endif - int size; + int size; } memitem; struct { - int mallocs,frees,callocs,reallocs; + int mallocs, frees, callocs, reallocs; } mstat; memitem *mi; void size2id(size_t, memitem *); void badformat(); void init_stats(), print_stats(); -void my_hash_insert(hash_table *h, const char *k, memitem *item); -static void *xmemAlloc(memitem *item); -static void xmemFree(memitem *item); +void my_hash_insert(hash_table * h, const char *k, memitem * item); +static void *xmemAlloc(memitem * item); +static void xmemFree(memitem * item); -int -ptrcmp(const void *a,const void *b) +int +ptrcmp(const void *a, const void *b) { - return (strcmp(a,b)); + return (strcmp(a, b)); } -main(int argc,char **argv) +main(int argc, char **argv) { char c; - extern char *optarg; + extern char *optarg; malloc_options = "A"; - a=0; + a = 0; while ((c = getopt(argc, argv, "f:i:M:l:m:r:N")) != -1) { - switch (c) { + switch (c) { case 'N': - mem_pools_on=0; - break; + mem_pools_on = 0; + break; case 'r': - run_stats=atoi(optarg); - break; + run_stats = atoi(optarg); + break; case 'f': - fn=strdup(optarg); - fp=fopen(fn,"r"); - break; + fn = strdup(optarg); + fp = fopen(fn, "r"); + break; case 'i': - initsiz=atoi(optarg); - break; + initsiz = atoi(optarg); + break; case 'l': - mem_max_size = atoi(optarg)*1024*1024; - break; + mem_max_size = atoi(optarg) * 1024 * 1024; + break; case 'M': - maxsiz=atoi(optarg); - break; + maxsiz = atoi(optarg); + break; case 'm': - minchunk=atoi(optarg); - break; + minchunk = atoi(optarg); + break; default: - fprintf(stderr, - "Usage: %s -f file -M maxsiz -i initsiz -m minchunk",argv[0]); - exit(1); - } - + fprintf(stderr, + "Usage: %s -f file -M maxsiz -i initsiz -m minchunk", argv[0]); + exit(1); + } + } if (!fp) { fprintf(stderr, - "%s pummels %s\n%s . o O ( You't supply a valid tracefile.)\n", - argv[0], getenv("USER"), argv[0]); + "%s pummels %s\n%s . o O ( You't supply a valid tracefile.)\n", + argv[0], getenv("USER"), argv[0]); exit(1); } #ifdef WITH_LIB sizeToPoolInit(); #endif - mem_table = hash_create(ptrcmp, 229, hash4); /* small hash table */ + mem_table = hash_create(ptrcmp, 229, hash4); /* small hash table */ init_stats(); - while (fgets(mbuf, 256, fp)!=NULL) { - if (run_stats>0 && (++a)%run_stats==0) print_stats(); - p=NULL; - switch(mbuf[0]) { - case 'm': /* malloc */ - p=strtok(&mbuf[2],":"); - if (!p) badformat(); - size=atoi(p); - p=strtok(NULL,"\n"); - if (!p) badformat(); - mi=malloc(sizeof(memitem)); - strcpy(mi->orig_ptr,p); - mi->size=size; - size2id(size,mi); - mi->my_ptr = xmemAlloc(mi); /* (void *)xmalloc(size); */ - assert(mi->my_ptr); - my_hash_insert(mem_table, mi->orig_ptr, mi); - mstat.mallocs++; - break; - case 'c': /* calloc */ - p=strtok(&mbuf[2],":"); - if (!p) badformat(); - amt=atoi(p); - p=strtok(NULL,":"); - if (!p) badformat(); - size=atoi(p); - p=strtok(NULL,"\n"); - if (!p) badformat(); - mi=malloc(sizeof(memitem)); - strcpy(mi->orig_ptr,p); - size2id(size,mi); - mi->size=amt*size; - mi->my_ptr= xmemAlloc(mi); /*(void *)xmalloc(amt*size);*/ - assert(mi->my_ptr); - my_hash_insert(mem_table, mi->orig_ptr, mi); - mstat.callocs++; - break; + while (fgets(mbuf, 256, fp) != NULL) { + if (run_stats > 0 && (++a) % run_stats == 0) + print_stats(); + p = NULL; + switch (mbuf[0]) { + case 'm': /* malloc */ + p = strtok(&mbuf[2], ":"); + if (!p) + badformat(); + size = atoi(p); + p = strtok(NULL, "\n"); + if (!p) + badformat(); + mi = malloc(sizeof(memitem)); + strcpy(mi->orig_ptr, p); + mi->size = size; + size2id(size, mi); + mi->my_ptr = xmemAlloc(mi); /* (void *)xmalloc(size); */ + assert(mi->my_ptr); + my_hash_insert(mem_table, mi->orig_ptr, mi); + mstat.mallocs++; + break; + case 'c': /* calloc */ + p = strtok(&mbuf[2], ":"); + if (!p) + badformat(); + amt = atoi(p); + p = strtok(NULL, ":"); + if (!p) + badformat(); + size = atoi(p); + p = strtok(NULL, "\n"); + if (!p) + badformat(); + mi = malloc(sizeof(memitem)); + strcpy(mi->orig_ptr, p); + size2id(size, mi); + mi->size = amt * size; + mi->my_ptr = xmemAlloc(mi); /*(void *)xmalloc(amt*size); */ + assert(mi->my_ptr); + my_hash_insert(mem_table, mi->orig_ptr, mi); + mstat.callocs++; + break; case 'r': - p=strtok(&mbuf[2],":"); - if (!p) badformat(); - strcpy(abuf,p); - p=strtok(NULL,":"); - if (!p) badformat(); - mem_entry=hash_lookup(mem_table, p); - if (mem_entry==NULL) { - fprintf(stderr,"invalid realloc (%s)!\n",p); + p = strtok(&mbuf[2], ":"); + if (!p) + badformat(); + strcpy(abuf, p); + p = strtok(NULL, ":"); + if (!p) + badformat(); + mem_entry = hash_lookup(mem_table, p); + if (mem_entry == NULL) { + fprintf(stderr, "invalid realloc (%s)!\n", p); break; - } - mi=(memitem *)(mem_entry->item); - assert(mi->pool); - assert(mi->my_ptr); - xmemFree(mi); /* xfree(mi->my_ptr); */ - size2id(atoi(p),mi); /* we don't need it here I guess? */ - strcpy(mi->orig_ptr,abuf); - p=strtok(NULL,"\n"); - if (!p) badformat(); - mi->my_ptr= xmemAlloc(mi); /* (char *)xmalloc(atoi(p)); */ - assert(mi->my_ptr); - mstat.reallocs++; - break; + } + mi = (memitem *) (mem_entry->item); + assert(mi->pool); + assert(mi->my_ptr); + xmemFree(mi); /* xfree(mi->my_ptr); */ + size2id(atoi(p), mi); /* we don't need it here I guess? */ + strcpy(mi->orig_ptr, abuf); + p = strtok(NULL, "\n"); + if (!p) + badformat(); + mi->my_ptr = xmemAlloc(mi); /* (char *)xmalloc(atoi(p)); */ + assert(mi->my_ptr); + mstat.reallocs++; + break; case 'f': - p=strtok(&mbuf[2],"\n"); - mem_entry=hash_lookup(mem_table, p); - if (mem_entry==NULL) { - if (p[0]!='0') - fprintf(stderr,"invalid free (%s) at line %d!\n",p,a); + p = strtok(&mbuf[2], "\n"); + mem_entry = hash_lookup(mem_table, p); + if (mem_entry == NULL) { + if (p[0] != '0') + fprintf(stderr, "invalid free (%s) at line %d!\n", p, a); break; - } - mi=(memitem *)(mem_entry->item); - assert(mi->pool); - assert(mi->my_ptr); - xmemFree(mi); /* xfree(mi->my_ptr); */ - hash_unlink(mem_table, mem_entry, 1); - free(mi); - mstat.frees++; - break; + } + mi = (memitem *) (mem_entry->item); + assert(mi->pool); + assert(mi->my_ptr); + xmemFree(mi); /* xfree(mi->my_ptr); */ + hash_unlink(mem_table, mem_entry, 1); + free(mi); + mstat.frees++; + break; default: - fprintf(stderr,"%s pummels %s.bad.format\n", argv[0],fn); - exit(1); + fprintf(stderr, "%s pummels %s.bad.format\n", argv[0], fn); + exit(1); } } @@ -216,19 +225,19 @@ void * my_xmalloc(size_t a) { - return NULL; + return NULL; } void * my_xcalloc(int a, size_t b) { - return NULL; + return NULL; } int my_xfree(void *p) { - return 0; + return 0; } void init_stats() @@ -240,36 +249,36 @@ print_stats() { #ifdef WITH_LIB - memReport(stdout); + memReport(stdout); #endif - getrusage(RUSAGE_SELF, &myusage); - printf("m/c/f/r=%d/%d/%d/%d\n",mstat.mallocs,mstat.callocs, - mstat.frees, mstat.reallocs); + getrusage(RUSAGE_SELF, &myusage); + printf("m/c/f/r=%d/%d/%d/%d\n", mstat.mallocs, mstat.callocs, + mstat.frees, mstat.reallocs); #if 0 - printf("types : %d\n",size2id_len); + printf("types : %d\n", size2id_len); #endif - printf("user time used : %d.%d\n", (int)myusage.ru_utime.tv_sec, - (int)myusage.ru_utime.tv_usec); - printf("system time used : %d.%d\n", (int)myusage.ru_stime.tv_sec, - (int)myusage.ru_stime.tv_usec); - printf("max resident set size : %d\n",(int)myusage.ru_maxrss); - printf("page faults : %d\n", (int)myusage.ru_majflt); + printf("user time used : %d.%d\n", (int) myusage.ru_utime.tv_sec, + (int) myusage.ru_utime.tv_usec); + printf("system time used : %d.%d\n", (int) myusage.ru_stime.tv_sec, + (int) myusage.ru_stime.tv_usec); + printf("max resident set size : %d\n", (int) myusage.ru_maxrss); + printf("page faults : %d\n", (int) myusage.ru_majflt); } void -size2id(size_t sz,memitem *mi) +size2id(size_t sz, memitem * mi) { #ifdef WITH_LIB - mi->pool = sizeToPool(sz); - assert(mi->pool); + mi->pool = sizeToPool(sz); + assert(mi->pool); #endif - return; + return; } void badformat() { - fprintf(stderr,"pummel.bad.format\n"); + fprintf(stderr, "pummel.bad.format\n"); exit(1); } @@ -277,22 +286,22 @@ const char * make_nam(int id, int size) { - const char *buf = malloc(30); /* argh */ - sprintf((char *)buf, "pl:%d/%d", id, size); + const char *buf = malloc(30); /* argh */ + sprintf((char *) buf, "pl:%d/%d", id, size); return buf; } void -my_hash_insert(hash_table *h, const char *k, memitem *item) -{ - memitem *l; - assert( item->pool); - assert( item->my_ptr); - hash_insert(h,k,item); +my_hash_insert(hash_table * h, const char *k, memitem * item) +{ + memitem *l; + assert(item->pool); + assert(item->my_ptr); + hash_insert(h, k, item); } static void * -xmemAlloc(memitem *item) +xmemAlloc(memitem * item) { extern MemPool *StringPool; assert(item && item->pool); @@ -303,23 +312,24 @@ } static void -xmemFree(memitem *item) +xmemFree(memitem * item) { extern MemPool *StringPool; assert(item && item->pool); if (StringPool == item->pool) - return memStringFree(item->pool, item->my_ptr, item->size); + return memStringFree(item->pool, item->my_ptr, item->size); else - return memFree(item->pool, item->my_ptr); + return memFree(item->pool, item->my_ptr); } -void my_free(char *file, int line, void *ptr) +void +my_free(char *file, int line, void *ptr) { #if 0 -fprintf(stderr,"{%s:%d:%p",file,line,ptr); + fprintf(stderr, "{%s:%d:%p", file, line, ptr); #endif -free(ptr); -#if 0 -fprintf(stderr,"}\n"); + free(ptr); +#if 0 + fprintf(stderr, "}\n"); #endif } Index: squid/test-suite/pconn-banger.c =================================================================== RCS file: /cvsroot/squid-sf//squid/test-suite/pconn-banger.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.30.1 diff -u -r1.1.1.1 -r1.1.1.1.30.1 --- squid/test-suite/pconn-banger.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/test-suite/pconn-banger.c 7 Jan 2001 09:48:33 -0000 1.1.1.1.30.1 @@ -167,7 +167,6 @@ } int - open_http_socket(void) { int s; @@ -191,7 +190,7 @@ int send_request(int fd, const char *data) { - char msg[4096],buf[4096]; + char msg[4096], buf[4096]; int len; time_t w; struct _r *r; @@ -200,24 +199,24 @@ char *tmp = strdup(data); struct stat st; int file_fd = -1; - method=strtok(tmp, " "); - url=strtok(NULL, " "); - file=strtok(NULL, " "); - size=strtok(NULL, " "); - checksum=strtok(NULL, " "); + method = strtok(tmp, " "); + url = strtok(NULL, " "); + file = strtok(NULL, " "); + size = strtok(NULL, " "); + checksum = strtok(NULL, " "); if (!url) { - url=method; - method="GET"; + url = method; + method = "GET"; } - if (file && strcmp(file,"-")==0) - file=NULL; - if (size && strcmp(size,"-")==0) - size=NULL; - if (checksum && strcmp(checksum,"-")==0) - checksum=NULL; + if (file && strcmp(file, "-") == 0) + file = NULL; + if (size && strcmp(size, "-") == 0) + size = NULL; + if (checksum && strcmp(checksum, "-") == 0) + checksum = NULL; msg[0] = '\0'; sprintf(buf, "%s %s HTTP/1.0\r\n", method, url); - strcat(msg,buf); + strcat(msg, buf); strcat(msg, "Accept: */*\r\n"); strcat(msg, "Proxy-Connection: Keep-Alive\r\n"); if (opt_ims && (lrand48() & 0x03) == 0) { @@ -226,11 +225,11 @@ strcat(msg, buf); } if (file) { - if ( (file_fd = open(file,O_RDONLY)) < 0) { + if ((file_fd = open(file, O_RDONLY)) < 0) { perror("open"); return -1; } - if ( fstat(file_fd, &st) ) { + if (fstat(file_fd, &st)) { perror("fstat"); close(file_fd); return -1; @@ -247,7 +246,7 @@ return -1; } if (file) { - while((len=read(file_fd, buf, sizeof buf)) > 0) { + while ((len = read(file_fd, buf, sizeof buf)) > 0) { if (write(fd, buf, len) < 0) { close(fd); perror("body write"); @@ -302,8 +301,8 @@ t += strlen(hdr); while (isspace(*t)) t++; - strcpy(result,""); - strncat(result,t,strcspn(t, crlf)); + strcpy(result, ""); + strncat(result, t, strcspn(t, crlf)); return result; } } @@ -315,9 +314,9 @@ { #if 0 fprintf(stderr, "DONE: %s, (%d+%d)\n", - r->url, - r->hdr_length, - r->content_length); + r->url, + r->hdr_length, + r->content_length); #endif if (r->content_length != r->bytes_read) fprintf(stderr, "ERROR! Short reply, expected %d bytes got %d\n", @@ -325,10 +324,10 @@ else if (r->validsize >= 0) { if (r->validsize != r->bytes_read) fprintf(stderr, "WARNING: %s Object size mismatch, expected %d got %d\n", - r->url, r->validsize, r->bytes_read); + r->url, r->validsize, r->bytes_read); else if (opt_checksum && r->sum != r->validsum) fprintf(stderr, "WARNING: %s Checksum error. Expected %d got %d\n", - r->url, r->validsum, r->sum); + r->url, r->validsum, r->sum); } } int @@ -338,19 +337,19 @@ const char *end; const char *url; static char buf[READ_BUF_SZ]; - int hlen,blen; - if (len < 0 ) { + int hlen, blen; + if (len < 0) { perror("read"); Requests = r->next; request_done(r); free(r); noutstanding--; if (trace_fd >= 0) - write(trace_fd,"\n[CLOSED]\n",10); + write(trace_fd, "\n[CLOSED]\n", 10); return -1; } total_bytes_read += len; - xmemcpy(buf,inbuf,len); + xmemcpy(buf, inbuf, len); if (len == 0) { fprintf(stderr, "WARNING: %s, server closed socket after %d+%d bytes\n", r->url, r->hdr_offset, r->bytes_read); /* XXX, If no data was received and it isn't the first request on this @@ -379,11 +378,12 @@ /* Process headers */ if (r->hdr_length == 0 && (end = mime_headers_end(r->reply_hdrs)) != NULL) { #if 0 - fprintf(stderr, "FOUND EOH FOR %s\n", r->url); */ + fprintf(stderr, "FOUND EOH FOR %s\n", r->url); + */ #endif - r->hdr_length = end - r->reply_hdrs; + r->hdr_length = end - r->reply_hdrs; #if 0 - fprintf(stderr, "HDR_LENGTH = %d\n", r->hdr_length); + fprintf(stderr, "HDR_LENGTH = %d\n", r->hdr_length); #endif /* "unread" any body contents received */ blen = r->hdr_offset - r->hdr_length; @@ -393,20 +393,20 @@ xmemcpy(buf, r->reply_hdrs + r->hdr_length, blen); len += blen; } - r->reply_hdrs[r->hdr_length]='\0'; /* Null terminate headers */ + r->reply_hdrs[r->hdr_length] = '\0'; /* Null terminate headers */ /* Parse headers */ r->content_length = get_header_int_value("content-length:", r->reply_hdrs, end); -/* fprintf(stderr, "CONTENT_LENGTH = %d\n", r->content_length); */ +/* fprintf(stderr, "CONTENT_LENGTH = %d\n", r->content_length); */ url = get_header_string_value("X-Request-URI:", r->reply_hdrs, end); if (url != NULL && strcmp(r->url, url) != 0) fprintf(stderr, "WARNING: %s got reply %s\n", r->url, url); #if XREQUESTURI || 0 - fprintf(stderr, "LOCATION = %s\n", get_header_string_value("X-Request-URI:", r->reply_hdrs, end)); + fprintf(stderr, "LOCATION = %s\n", get_header_string_value("X-Request-URI:", r->reply_hdrs, end)); #endif } - if ( !(len==0 || r->hdr_length > 0) ) { + if (!(len == 0 || r->hdr_length > 0)) { fprintf(stderr, "ERROR!!!\n"); - assert((len==0 || r->hdr_length > 0)); + assert((len == 0 || r->hdr_length > 0)); } /* Process body */ if (r->hdr_length != 0) { @@ -415,14 +415,14 @@ if (r->content_length >= 0) { bytes_left = r->content_length - r->bytes_read; assert(bytes_left >= 0); - bytes_used = len < bytes_left ? len : bytes_left; + bytes_used = len < bytes_left ? len : bytes_left; } else { - bytes_left = len + 1; /* Unknown end... */ + bytes_left = len + 1; /* Unknown end... */ bytes_used = len; } if (opt_checksum) { - for(i=0; isum += (int)buf[i] & 0xFF; + for (i = 0; i < bytes_used; i++) + r->sum += (int) buf[i] & 0xFF; } r->bytes_read += bytes_used; len -= bytes_used; @@ -462,7 +462,7 @@ static int pconn_fd = -1; static char buf[8192]; struct timeval to; - struct timeval now,last,start; + struct timeval now, last, start; fd_set R; struct _r *r; struct _r *nextr; @@ -480,10 +480,10 @@ } while (!done_reading_urls || noutstanding) { if (!opt_reopen && pconn_fd < 0) { - fprintf(stderr,"TERMINATED: Connection closed\n"); + fprintf(stderr, "TERMINATED: Connection closed\n"); break; } - if (pconn_fd<0) { + if (pconn_fd < 0) { pconn_fd = open_http_socket(); if (pconn_fd < 0) { perror("socket"); @@ -491,14 +491,14 @@ } nextr = Requests; Requests = NULL; - noutstanding=0; + noutstanding = 0; while ((r = nextr) != NULL) { nextr = r->next; if (send_request(pconn_fd, r->url) != 0) { close(pconn_fd); - pconn_fd=-1; + pconn_fd = -1; nextr = r; - for (r = Requests; r!=NULL && r->next; r=r->next); + for (r = Requests; r != NULL && r->next; r = r->next); if (r != NULL) r->next = nextr; else @@ -508,7 +508,7 @@ free(r); } timeouts = 0; - if (pconn_fd <0) + if (pconn_fd < 0) continue; } if (timeouts == 200) { @@ -520,7 +520,7 @@ free(r); noutstanding--; } - if (pconn_fd>=0 && noutstanding < max_outstanding && !done_reading_urls) { + if (pconn_fd >= 0 && noutstanding < max_outstanding && !done_reading_urls) { char *t; if (fgets(buf, 8191, stdin) == NULL) { fprintf(stderr, "Done Reading URLS\n"); @@ -532,7 +532,7 @@ *t = '\0'; if (send_request(pconn_fd, buf) != 0) { close(pconn_fd); - pconn_fd=-1; + pconn_fd = -1; continue; } nrequests++; @@ -560,21 +560,22 @@ pconn_fd = -1; } gettimeofday(&now, NULL); - if (now.tv_sec > last.tv_sec) { + if (now.tv_sec > last.tv_sec) { int dt; int nreq; last = now; dt = (int) (now.tv_sec - start.tv_sec); - nreq=0; - for (r=Requests; r ; r=r->next) nreq++; + nreq = 0; + for (r = Requests; r; r = r->next) + nreq++; printf("T+ %6d: %9d req (%+4d), %4d pend, %3d/sec avg, %dmb, %dkb/sec avg\n", - dt, - nrequests, - reqpersec, - nreq, - (int) (nrequests / dt), - (int)total_bytes_read / 1024 / 1024, - (int)total_bytes_read / 1024 / dt); + dt, + nrequests, + reqpersec, + nreq, + (int) (nrequests / dt), + (int) total_bytes_read / 1024 / 1024, + (int) total_bytes_read / 1024 / dt); reqpersec = 0; } } @@ -616,7 +617,7 @@ lifetime = (time_t) atoi(optarg); break; case 't': - trace_fd = open(optarg,O_WRONLY|O_CREAT|O_TRUNC,0666); + trace_fd = open(optarg, O_WRONLY | O_CREAT | O_TRUNC, 0666); break; case 'r': opt_reopen = !opt_reopen; Index: squid/test-suite/tcp-banger3.c =================================================================== RCS file: /cvsroot/squid-sf//squid/test-suite/tcp-banger3.c,v retrieving revision 1.1.1.2 retrieving revision 1.1.1.2.30.1 diff -u -r1.1.1.2 -r1.1.1.2.30.1 --- squid/test-suite/tcp-banger3.c 26 Jan 2000 03:23:10 -0000 1.1.1.2 +++ squid/test-suite/tcp-banger3.c 7 Jan 2001 09:48:33 -0000 1.1.1.2.30.1 @@ -382,7 +382,7 @@ signal(SIGCHLD, sig_child); create_children(argv); parent_main_loop(); - for (i=3;i<=maxfd; i++) + for (i = 3; i <= maxfd; i++) close(i); sleep(1); } Index: squid/test-suite/waiter.c =================================================================== RCS file: /cvsroot/squid-sf//squid/test-suite/waiter.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.30.1 diff -u -r1.1.1.1 -r1.1.1.1.30.1 --- squid/test-suite/waiter.c 26 Jan 2000 03:21:47 -0000 1.1.1.1 +++ squid/test-suite/waiter.c 7 Jan 2001 09:48:33 -0000 1.1.1.1.30.1 @@ -4,21 +4,21 @@ int main(int argc, char *argv[]) { - int i; - struct timeval now; - struct timeval alarm; - struct timeval to; - assert(argc == 2); - i = atoi(argv[1]); - gettimeofday(&now, NULL); - alarm.tv_sec = now.tv_sec + i + (now.tv_sec % i); - alarm.tv_usec = 0; - to.tv_sec = alarm.tv_sec - now.tv_sec; - to.tv_usec = alarm.tv_usec - now.tv_usec; - if (to.tv_usec < 0) { - to.tv_usec += 1000000; - to.tv_sec -= 1; - } - select(1, NULL, NULL, NULL, &to); - return 0; + int i; + struct timeval now; + struct timeval alarm; + struct timeval to; + assert(argc == 2); + i = atoi(argv[1]); + gettimeofday(&now, NULL); + alarm.tv_sec = now.tv_sec + i + (now.tv_sec % i); + alarm.tv_usec = 0; + to.tv_sec = alarm.tv_sec - now.tv_sec; + to.tv_usec = alarm.tv_usec - now.tv_usec; + if (to.tv_usec < 0) { + to.tv_usec += 1000000; + to.tv_sec -= 1; + } + select(1, NULL, NULL, NULL, &to); + return 0; }