--------------------- PatchSet 3540 Date: 2002/01/06 10:17:44 Author: serassio Branch: nt-2_3 Tag: (none) Log: Added external configuration file to LDAP dll Authenticator, some indent fixes Members: auth_modules/LDAP/squid_ldap_auth.c:1.1.1.1.56.2->1.1.1.1.56.3 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.56.2 retrieving revision 1.1.1.1.56.3 diff -u -r1.1.1.1.56.2 -r1.1.1.1.56.3 --- squid/auth_modules/LDAP/squid_ldap_auth.c 16 Sep 2001 08:59:53 -0000 1.1.1.1.56.2 +++ squid/auth_modules/LDAP/squid_ldap_auth.c 6 Jan 2002 10:17:44 -0000 1.1.1.1.56.3 @@ -30,22 +30,20 @@ #include #endif -typedef struct { - void *data; - acl_proxy_auth_user *auth_user; - RH *handler; -} authenticateStateData; - - /* Change this to your search base */ #define SEARCHBASE "ou=people,o=nrc.ca" int checkLDAP(LDAP *ld, char *userid, char *password); #ifdef _SQUID_MSWIN_ - static char *ldapServer=NULL; +static char ldapsearchstring[8192]; +typedef struct { + void *data; + acl_proxy_auth_user *auth_user; + RH *handler; +} authenticateStateData; BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved /* Not used. */ ); @@ -53,128 +51,134 @@ __declspec (dllexport) int Authenticate(char *username, char *password, authenticateStateData *data, HLPCB callback) { - LDAP *ld; + LDAP *ld; #else int main(int argc, char **argv) { - char buf[256]; - char *username, *password, *p; - char *ldapServer; - LDAP *ld; + char buf[256]; + char *username, *password, *p; + char *ldapServer; + LDAP *ld; - setbuf(stdout, NULL); + setbuf(stdout, NULL); - if (argc != 2) + if (argc != 2) { - fprintf(stderr, "Usage: squid_ldap_auth ldap_server_name\n"); - exit(1); + 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) + 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. - */ + /* 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. + */ #endif - if ((ld = ldap_init(ldapServer, LDAP_PORT)) == NULL) - { + if ((ld = ldap_init(ldapServer, LDAP_PORT)) == NULL) { #ifndef _SQUID_MSWIN_ - fprintf(stderr, "\nUnable to connect to LDAP server:%s port:%d\n", - ldapServer, LDAP_PORT); - exit(1); + fprintf(stderr, "\nUnable to connect to LDAP server:%s port:%d\n", + ldapServer, LDAP_PORT); + exit(1); #else - (callback)(data,"ERR"); - return 0; + (callback)(data,"ERR"); + return 0; #endif - } + } #ifndef _SQUID_MSWIN_ - if ((p = strchr(buf, '\n')) != NULL) - *p = '\0'; /* strip \n */ + if ((p = strchr(buf, '\n')) != NULL) + *p = '\0'; /* strip \n */ - if ((username = strtok(buf, " ")) == NULL) - { - printf("ERR\n"); - continue; - } - if ((password = strtok(NULL, "")) == NULL) - { - printf("ERR\n"); - continue; - } + if ((username = strtok(buf, " ")) == NULL) { + printf("ERR\n"); + continue; + } + if ((password = strtok(NULL, "")) == NULL) { + printf("ERR\n"); + continue; + } #endif - if(checkLDAP(ld, username, password) != 0) - { + if(checkLDAP(ld, username, password) != 0) { #ifndef _SQUID_MSWIN_ - printf("ERR\n"); - continue; + printf("ERR\n"); + continue; #else - ldap_unbind(ld); - (callback)(data,"ERR"); - return 0; + ldap_unbind(ld); + (callback)(data,"ERR"); + return 0; #endif - } else { + } else { #ifndef _SQUID_MSWIN_ - printf("OK\n"); - } - ldap_unbind(ld); - } + printf("OK\n"); + } + ldap_unbind(ld); + } #else - ldap_unbind(ld); - (callback)(data,"OK"); - return 0; - } + ldap_unbind(ld); + (callback)(data,"OK"); + return 0; + } #endif } int checkLDAP(LDAP *ld, char *userid, char *password) { - char buffer[256]; + char buffer[256]; - sprintf (buffer, "uid=%s, %s", userid, SEARCHBASE); - - if(ldap_simple_bind_s(ld, buffer, password) != LDAP_SUCCESS) - return 1; - return 0; +#ifdef _SQUID_MSWIN_ + sprintf (buffer, ldapsearchstring, userid); +#else + sprintf (buffer, "uid=%s, %s", userid, SEARCHBASE); +#endif + if(ldap_simple_bind_s(ld, buffer, password) != LDAP_SUCCESS) + return 1; + return 0; } #ifdef _SQUID_MSWIN_ - __declspec (dllexport) int Init(char *Server) { - if (ldapServer) - xfree(ldapServer); - ldapServer = xstrdup(Server); - return 0; + char path[FILENAME_MAX]; + char target_file[FILENAME_MAX]=""; + char drive[_MAX_DRIVE]=""; + char fname[_MAX_FNAME]=""; + char dir[_MAX_DIR]=""; + char ext[_MAX_EXT]=""; + + GetModuleFileName(NULL, path, FILENAME_MAX); + _splitpath(path,drive,dir,fname,ext); + _makepath(target_file, drive, dir, fname,"ini"); + + if (ldapServer) + xfree(ldapServer); + ldapServer = xstrdup(Server); + + if (GetPrivateProfileString(ldapServer, "SearchString", SEARCHBASE, ldapsearchstring, sizeof(ldapsearchstring), target_file) == 0) + return 1; + return 0; } - BOOL APIENTRY DllMain ( HINSTANCE hInst /* Library instance handle. */ , DWORD reason /* Reason this function is being called. */ , LPVOID reserved /* Not used. */ ) { - - switch (reason) - { - 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