--------------------- PatchSet 4410 Date: 2002/06/29 13:21:44 Author: serassio Branch: nt-2_5 Tag: (none) Log: Added NT group external_acl helper Members: helpers/basic_auth/LDAP/squid_ldap_auth.c:1.2.8.1->1.2.8.2 helpers/external_acl/win32_group/.cvsignore:1.1->1.1.2.1 helpers/external_acl/win32_group/Makefile.am:1.1->1.1.8.1 helpers/external_acl/win32_group/readme.txt:1.1->1.1.8.1 helpers/external_acl/win32_group/win32_check_group.c:1.1->1.1.8.1 port/win32/win32_check_group/.cvsignore:1.1->1.1.2.1 port/win32/win32_check_group/win32_check_group.dsp:1.1->1.1.4.1 Index: squid/helpers/basic_auth/LDAP/squid_ldap_auth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/helpers/basic_auth/LDAP/squid_ldap_auth.c,v retrieving revision 1.2.8.1 retrieving revision 1.2.8.2 diff -u -r1.2.8.1 -r1.2.8.2 --- squid/helpers/basic_auth/LDAP/squid_ldap_auth.c 29 Jun 2002 11:05:59 -0000 1.2.8.1 +++ squid/helpers/basic_auth/LDAP/squid_ldap_auth.c 29 Jun 2002 13:21:44 -0000 1.2.8.2 @@ -50,8 +50,21 @@ #include #include #include +#ifdef _WIN32 +#define snprintf _snprintf +#include +#include +#define LDAP_OPT_SUCCESS LDAP_SUCCESS +#undef ldap_start_tls_s +#if LDAP_UNICODE +#define ldap_start_tls_s(l,s,c) ldap_start_tls_sW(l,NULL,NULL,s,c) +#else +#define ldap_start_tls_s(l,s,c) ldap_start_tls_sA(l,NULL,NULL,s,c) +#endif +#else #include #include +#endif /* Change this to your search base */ static char *basedn; --- /dev/null Wed Feb 14 00:59:35 2007 +++ squid/helpers/external_acl/win32_group/.cvsignore Wed Feb 14 00:59:45 2007 @@ -0,0 +1,2 @@ +.cvsignore +Makefile.in --- /dev/null Wed Feb 14 00:59:35 2007 +++ squid/helpers/external_acl/win32_group/Makefile.am Wed Feb 14 00:59:45 2007 @@ -0,0 +1,14 @@ +# +# Makefile for the Squid Object Cache server +# +# $Id: Makefile.am,v 1.1.8.1 2002/06/29 13:21:45 serassio Exp $ +# +# Uncomment and customize the following to suit your needs: +# + + +libexec_PROGRAMS = win32_check_group + +win32_check_group_SOURCES = win32_check_group.c + +LDADD = -lnetapi32 --- /dev/null Wed Feb 14 00:59:35 2007 +++ squid/helpers/external_acl/win32_group/readme.txt Wed Feb 14 00:59:45 2007 @@ -0,0 +1,15 @@ +$Id: readme.txt,v 1.1.8.1 2002/06/29 13:21:45 serassio Exp $ + +This is the readme.txt file for win32_check_group, an external +helper fo the External ACL Scheme for Squid. + +More information about the External ACL scheme may +be found at http://devel.squid-cache.org/external_acl/ + +This program reads one new line terminated argument in the +standard input (the username and group) and tries to match. + +-- +Serassio Guido +squidnt@serassio.it + --- /dev/null Wed Feb 14 00:59:35 2007 +++ squid/helpers/external_acl/win32_group/win32_check_group.c Wed Feb 14 00:59:45 2007 @@ -0,0 +1,160 @@ +/* + * $Id: win32_check_group.c,v 1.1.8.1 2002/06/29 13:21:45 serassio Exp $ + * + * This is a helper for the external ACL interface for Squid Cache + * Copyright (C) 2002 Guido Serassio + * Based on previous work of Rodrigo Albani de Campos + * + * It reads STDIN looking for a username that matches a specified group + * Returns `OK' if the user belongs to the group or `ERR' otherwise, as + * described on http://devel.squid-cache.org/external_acl/config.html + * To compile this program, use: + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + * Change Log: + * $Log: win32_check_group.c,v $ + * Revision 1.1.8.1 2002/06/29 13:21:45 serassio + * Added NT group external_acl helper + * + */ + +#include +#if defined(_SQUID_CYGWIN_) +#include +#endif +#include +#include +#include +#include +#include + +#define BUFSIZE 8192 /* the stdin buffer size */ + +/* returns 1 on success, 0 on failure */ +int +Valid_Group(char *UserName, char *Group) +{ + int result = 0; + 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])); + + /* + * 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 = 0; + break; + } + if (wcscmp(pTmpBuf->lgrui0_name, wszGroup) == 0) { + result = 1; + break; + } + pTmpBuf++; + dwTotalCount++; + } + } + } else + result = 0; +/* + * Free the allocated memory. + */ + if (pBuf != NULL) + NetApiBufferFree(pBuf); + return result; +} + +static void +usage (char *program) +{ + fprintf (stderr, "Usage: %s\n\n", program); +} + + +int +main (int argc, char *argv[]) +{ + char *p; + char buf[BUFSIZE]; + char username[BUFSIZE]; + char group[BUFSIZE]; + + /* make standard output line buffered */ + setvbuf (stdout, NULL, _IOLBF, 0); + + /* Check Command Line */ + if (argc != 1) { + usage (argv[0]); + exit (1); + } + + /* Main Loop */ + while (fgets (buf, BUFSIZE, stdin)) + { + + if ((p = strchr(buf, '\n')) != NULL) + *p = '\0'; /* strip \n */ + if ((p = strchr(buf, '\r')) != NULL) + *p = '\0'; /* strip \r */ + + /* Clear any current settings */ + username[0] = '\0'; + group[0] = '\0'; + sscanf(buf, "%s %s", username, group); /* Extract parameters */ + + if (Valid_Group(username, group)) { + printf ("OK\n"); + } else { + printf ("ERR\n"); + } + } + return 0; +} --- /dev/null Wed Feb 14 00:59:35 2007 +++ squid/port/win32/win32_check_group/.cvsignore Wed Feb 14 00:59:45 2007 @@ -0,0 +1,3 @@ +.cvsignore +Debug +Release --- /dev/null Wed Feb 14 00:59:35 2007 +++ squid/port/win32/win32_check_group/win32_check_group.dsp Wed Feb 14 00:59:45 2007 @@ -0,0 +1,102 @@ +# Microsoft Developer Studio Project File - Name="win32_check_group" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=win32_check_group - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "win32_check_group.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "win32_check_group.mak" CFG="win32_check_group - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "win32_check_group - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "win32_check_group - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "win32_check_group - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /G6 /W3 /GX /O2 /I "../../../include" /I "../../../src" /I "../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x410 /d "NDEBUG" +# ADD RSC /l 0x410 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 netapi32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "win32_check_group - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /G6 /W3 /Gm /GX /ZI /Od /I "../../../include" /I "../../../src" /I "../include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD BASE RSC /l 0x410 /d "_DEBUG" +# ADD RSC /l 0x410 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 netapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "win32_check_group - Win32 Release" +# Name "win32_check_group - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\..\helpers\external_acl\win32_group\WIN32_check_group.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project