diff -ruN courier-authlib-0.57.orig/authpam.c courier-authlib-0.57/authpam.c --- courier-authlib-0.57.orig/authpam.c Sat Feb 19 21:41:20 2005 +++ courier-authlib-0.57/authpam.c Fri Dec 9 16:01:05 2005 @@ -156,6 +156,7 @@ a->clearpasswd=pam_password; s=strdup(a->sysusername); + pam_username=a->sysusername; if (!s) { perror("malloc"); diff -ruN courier-authlib-0.57.orig/preauthpam.c courier-authlib-0.57/preauthpam.c --- courier-authlib-0.57.orig/preauthpam.c Sat Feb 19 21:41:20 2005 +++ courier-authlib-0.57/preauthpam.c Fri Dec 9 16:01:05 2005 @@ -20,6 +20,50 @@ static const char rcsid[]="$Id: preauthpam.c,v 1.12 2005/02/20 04:41:20 mrsam Exp $"; +int check_local_domains (const char *domain) +{ + FILE * pFile; + char * buff; + + if (strlen(domain) > 255) + { + return (0); + } + + pFile = fopen("/var/qmail/control/locals","r"); + if (pFile != NULL) + { + if ((buff = malloc(sizeof(char) * 256)) == NULL) + { + fclose(pFile); + return (-1); + } + while ((!feof(pFile)) && (fgets(buff,255,pFile) != NULL)) + { + if (buff[strlen(buff)-1]=='\n') buff[strlen(buff)-1]='\0'; + if (strcmp(domain,buff) == 0) + { + DPRINTF("Domain is local\n"); + free(buff); + fclose(pFile); + return (1); + } + } + free(buff); + } + fclose(pFile); + return (0); +} + +char * strip_domain (const char *userid, char newuser[]) +{ + char * atpos = strchr(userid,'@'); + char * domain = atpos+1; + strncpy(newuser,userid,atpos-userid); + newuser[atpos-userid]='\0'; + return domain; +} + int auth_pam_pre(const char *userid, const char *service, int (*callback)(struct authinfo *, void *), void *arg) @@ -29,8 +73,20 @@ #if HAVE_GETSPENT struct spwd *spw; #endif + char * pch = NULL; + char * domain = NULL; + char newuser[256]; memset(&auth, 0, sizeof(auth)); + + DPRINTF("Username: %s",userid); + pch=strchr(userid,'@'); + if (pch != NULL) { + domain = strip_domain(userid, newuser); + if (check_local_domains(domain)==1) { + userid = newuser; + } + } if ((pw=getpwnam(userid)) == 0) {