--------------------- PatchSet 2133 Date: 2001/04/27 22:06:42 Author: serassio Branch: cygwin Tag: (none) Log: Final code cleaning Members: src/auth/basic/helpers/NT/NT_auth.c:1.1.2.1->1.1.2.2 src/auth/basic/helpers/NT/valid.c:1.1.2.1->1.1.2.2 Index: squid/src/auth/basic/helpers/NT/NT_auth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/auth/basic/helpers/NT/Attic/NT_auth.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/auth/basic/helpers/NT/NT_auth.c 16 Apr 2001 15:30:47 -0000 1.1.2.1 +++ squid/src/auth/basic/helpers/NT/NT_auth.c 27 Apr 2001 22:06:42 -0000 1.1.2.2 @@ -1,4 +1,3 @@ - /* NT_auth - Version 1.1 @@ -36,94 +35,86 @@ #include "squid.h" #include "valid.h" - - /* Main program for simple authentication. Scans and checks for Squid input, and attempts to validate the user. */ - - #ifdef _SQUID_CYGWIN_ static char NTGroup[256]; -int main(int argc, char **argv) +int +main(int argc, char **argv) { #else -typedef struct { +typedef struct +{ void *data; acl_proxy_auth_user *auth_user; RH *handler; -} authenticateStateData; - -static char *NTGroup=NULL; -BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, - LPVOID reserved /* Not used. */ ); +} +authenticateStateData; -__declspec (dllexport) int -Authenticate(char *username, char *password, authenticateStateData *data, HLPCB callback) +static char *NTGroup = NULL; +BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, + LPVOID reserved /* Not used. */ ); + +__declspec(dllexport) + int Authenticate(char *username, char *password, + authenticateStateData * data, HLPCB callback) { #endif #ifdef _SQUID_CYGWIN_ - char wstr[256]; - char username[256]; - char password[256]; - char *p; - - if (argc != 2) - { - fprintf(stderr, "Usage: NT_auth \n"); - exit(1); - } - strcpy(NTGroup, argv[1]); - - while (1) - { - /* Read whole line from standard input. Terminate on break. */ - if (fgets(wstr, 255, stdin) == NULL) - break; - if ((p = strchr(wstr, '\n')) != NULL) - *p = '\0'; /* strip \n */ - if ((p = strchr(wstr, '\r')) != NULL) - *p = '\0'; /* strip \r */ - - /* Clear any current settings */ - username[0] = '\0'; - password[0] = '\0'; - sscanf(wstr, "%s %s", username, password); /* Extract parameters */ -#endif - - /* Check for invalid or blank entries */ - if ((username[0] == '\0') || (password[0] == '\0')) - { + char wstr[256]; + char username[256]; + char password[256]; + char *p; + + if (argc != 2) { + fprintf(stderr, "Usage: NT_auth \n"); + exit(1); + } + strcpy(NTGroup, argv[1]); + while (1) { + /* Read whole line from standard input. Terminate on break. */ + if (fgets(wstr, 255, stdin) == NULL) + break; + if ((p = strchr(wstr, '\n')) != NULL) + *p = '\0'; /* strip \n */ + if ((p = strchr(wstr, '\r')) != NULL) + *p = '\0'; /* strip \r */ + /* Clear any current settings */ + username[0] = '\0'; + password[0] = '\0'; + sscanf(wstr, "%s %s", username, password); /* Extract parameters */ +#endif + /* Check for invalid or blank entries */ + if ((username[0] == '\0') || (password[0] == '\0')) { #ifdef _SQUID_CYGWIN_ - puts("ERR"); - fflush(stdout); - continue; + puts("ERR"); + fflush(stdout); + continue; #else - (callback)(data,"ERR"); - return 0; + (callback) (data, "ERR"); + return 0; #endif - } - - if (Valid_User(username, password, NTGroup) == NTV_NO_ERROR) + } + if (Valid_User(username, password, NTGroup) == NTV_NO_ERROR) #ifdef _SQUID_CYGWIN_ - puts("OK"); + puts("OK"); #else - (callback)(data,"OK"); + (callback) (data, "OK"); #endif - else + else #ifdef _SQUID_CYGWIN_ - puts("ERR"); - - fflush(stdout); - } + puts("ERR"); + fflush(stdout); + } #else - (callback)(data,"ERR"); + (callback) (data, "ERR"); #endif return 0; -} + } /* Valid_User return codes - @@ -135,37 +126,27 @@ #ifndef _SQUID_CYGWIN_ -__declspec (dllexport) int Init(char *Group) -{ + __declspec(dllexport) int Init(char *Group) + { if (NTGroup) - xfree(NTGroup); + xfree(NTGroup); NTGroup = xstrdup(Group); return 0; -} - - -BOOL APIENTRY -DllMain ( - HINSTANCE hInst /* Library instance handle. */ , - DWORD reason /* Reason this function is being called. */ , - LPVOID reserved /* Not used. */ ) -{ - - switch (reason) + } + BOOL APIENTRY DllMain(HINSTANCE hInst /* Library instance handle. */ , + DWORD reason /* Reason this function is being called. */ , + LPVOID reserved /* Not used. */ ) { - case DLL_PROCESS_ATTACH: - break; - - case DLL_PROCESS_DETACH: - break; - - case DLL_THREAD_ATTACH: - break; - - case DLL_THREAD_DETACH: - break; + switch (reason) { + case DLL_PROCESS_ATTACH: + break; + case DLL_PROCESS_DETACH: + break; + case DLL_THREAD_ATTACH: + break; + case DLL_THREAD_DETACH: + break; + } + return TRUE; } - return TRUE; -} - -#endif \ No newline at end of file +#endif Index: squid/src/auth/basic/helpers/NT/valid.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/auth/basic/helpers/NT/Attic/valid.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/auth/basic/helpers/NT/valid.c 16 Apr 2001 15:30:47 -0000 1.1.2.1 +++ squid/src/auth/basic/helpers/NT/valid.c 27 Apr 2001 22:06:42 -0000 1.1.2.2 @@ -5,121 +5,93 @@ #include #include "valid.h" -int Valid_User(char * UserName, char * Password, char * Group) +int +Valid_User(char *UserName, char *Password, char *Group) { - HANDLE hToken; - int result=NTV_LOGON_ERROR; - int error; - char NTDomain[256]; - char * domain_qualify; - char DomainUser[256]; - WCHAR wszUserName[256]; // Unicode user name - WCHAR wszGroup[256]; // Unicode Group - - LPLOCALGROUP_USERS_INFO_0 pBuf = NULL; - LPLOCALGROUP_USERS_INFO_0 pTmpBuf; - DWORD dwLevel = 0; - DWORD dwFlags = LG_INCLUDE_INDIRECT ; - DWORD dwPrefMaxLen = -1; - DWORD dwEntriesRead = 0; - DWORD dwTotalEntries = 0; - NET_API_STATUS nStatus; - DWORD i; - DWORD dwTotalCount = 0; + HANDLE hToken; + int result = NTV_LOGON_ERROR; + int error; + char NTDomain[256]; + char *domain_qualify; + char DomainUser[256]; + WCHAR wszUserName[256]; // Unicode user name + WCHAR wszGroup[256]; // Unicode Group + + LPLOCALGROUP_USERS_INFO_0 pBuf = NULL; + LPLOCALGROUP_USERS_INFO_0 pTmpBuf; + DWORD dwLevel = 0; + DWORD dwFlags = LG_INCLUDE_INDIRECT; + DWORD dwPrefMaxLen = -1; + DWORD dwEntriesRead = 0; + DWORD dwTotalEntries = 0; + NET_API_STATUS nStatus; + DWORD i; + DWORD dwTotalCount = 0; /* Convert ANSI User Name and Group to Unicode */ - MultiByteToWideChar( CP_ACP, 0, UserName, - strlen(UserName)+1, wszUserName, - sizeof(wszUserName)/sizeof(wszUserName[0]) ); - - MultiByteToWideChar( CP_ACP, 0, Group, - strlen(Group)+1, wszGroup, - sizeof(wszGroup)/sizeof(wszGroup[0]) ); - - if ((domain_qualify=strchr(UserName,'\\')) == NULL) - { - strcpy(DomainUser, UserName); - strcpy(NTDomain, "."); - } - else - { - strcpy(DomainUser, domain_qualify+1); - domain_qualify[0]='\0'; - strcpy(NTDomain, UserName); - } - - /* Log the client on to the local computer. */ - - if (!LogonUser( - DomainUser, - NTDomain, - Password, - LOGON32_LOGON_NETWORK, - LOGON32_PROVIDER_DEFAULT, - &hToken) ) - { - result=NTV_LOGON_ERROR; - error=GetLastError(); - } - else - { - /* - Call the NetUserGetLocalGroups function - specifying information level 0. - - The LG_INCLUDE_INDIRECT flag specifies that the - function should also return the names of the local - groups in which the user is indirectly a member. - */ - nStatus = NetUserGetLocalGroups(NULL, - wszUserName, - dwLevel, - dwFlags, - (LPBYTE *) &pBuf, - dwPrefMaxLen, - &dwEntriesRead, - &dwTotalEntries); - - - /* - If the call succeeds, - */ - if (nStatus == NERR_Success) - { - - if ((pTmpBuf = pBuf) != NULL) - { - for (i = 0; i < dwEntriesRead; i++) - { - assert(pTmpBuf != NULL); - - if (pTmpBuf == NULL) - { - result = NTV_SERVER_ERROR; - break; - } - if (wcscmp(pTmpBuf->lgrui0_name, wszGroup) == 0) - { - result=NTV_NO_ERROR; - break; - } - pTmpBuf++; - dwTotalCount++; - } - } - } - else + MultiByteToWideChar(CP_ACP, 0, UserName, + strlen(UserName) + 1, wszUserName, + sizeof(wszUserName) / sizeof(wszUserName[0])); + MultiByteToWideChar(CP_ACP, 0, Group, + strlen(Group) + 1, wszGroup, sizeof(wszGroup) / sizeof(wszGroup[0])); + if ((domain_qualify = strchr(UserName, '\\')) == NULL) { + strcpy(DomainUser, UserName); + strcpy(NTDomain, "."); + } else { + strcpy(DomainUser, domain_qualify + 1); + domain_qualify[0] = '\0'; + strcpy(NTDomain, UserName); + } + /* Log the client on to the local computer. */ + if (!LogonUser(DomainUser, + NTDomain, + Password, + LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &hToken)) { + result = NTV_LOGON_ERROR; + error = GetLastError(); + } else { + /* + * Call the NetUserGetLocalGroups function + * specifying information level 0. + * + * The LG_INCLUDE_INDIRECT flag specifies that the + * function should also return the names of the local + * groups in which the user is indirectly a member. + */ + nStatus = NetUserGetLocalGroups(NULL, + wszUserName, + dwLevel, + dwFlags, + (LPBYTE *) & pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries); + /* + * If the call succeeds, + */ + if (nStatus == NERR_Success) { + if ((pTmpBuf = pBuf) != NULL) { + for (i = 0; i < dwEntriesRead; i++) { + assert(pTmpBuf != NULL); + if (pTmpBuf == NULL) { result = NTV_SERVER_ERROR; - - /* - Free the allocated memory. - */ - if (pBuf != NULL) - NetApiBufferFree(pBuf); - } - if (hToken != INVALID_HANDLE_VALUE) - CloseHandle(hToken); - return result; + break; + } + if (wcscmp(pTmpBuf->lgrui0_name, wszGroup) == 0) { + result = NTV_NO_ERROR; + break; + } + pTmpBuf++; + dwTotalCount++; + } + } + } else + result = NTV_SERVER_ERROR; + /* + * Free the allocated memory. + */ + if (pBuf != NULL) + NetApiBufferFree(pBuf); + } + if (hToken != INVALID_HANDLE_VALUE) + CloseHandle(hToken); + return result; } -