LDAP Auth patch
"Jonathan Zuilkowski" <[email protected]> Sun, 21 Jul 2002 18:26:55 -0400
| Newsgroups | gmane.linux.suse.proxy-suite |
|---|---|
| Message-ID | <[email protected]> |
Hey guys, I didn't hear back from anyone, so I don't know if there's a lot
of interest or not.
I did get this to work.
I did away with the password comparison and substituted that with a bind.
Now you can use SHA1, or anything else for that matter.
Replace the entire ldap_auth function with this one.
Enjoy.
/* ------------------------------------------------------------ **
**
** Function......: ldap_auth
**
** Parameters....: ld Pointer to LDAP struct
** e Pointer to result buffer
** who Pointer to user name
** pwd Pointer to user pwd
**
** Return........: 0 on success
**
** Purpose.......: Preform LDAP userauth
**
** ------------------------------------------------------------ */
static int ldap_auth(LDAP *ld, LDAPMessage *e, char *who, char *pwd)
{
int luser;
char *auth_dn;
char *base = "ou=people,o=equifax.com";
char str[MAX_PATH_SIZE];
char *v, *p;
/* test server connection */
if (ld == NULL || e == NULL)
{
misc_die(FL, "ldap_checkauth: ?ld? ?e?");
}
/* dn=uid=<username>,<ldapbase> */
auth_dn=malloc(255);
strcpy(auth_dn,"uid=");
strcpy(auth_dn+4,who);
luser=strlen(who);
strcpy(auth_dn+4+luser,", ");
strcpy(auth_dn+6+luser,base);
/* attempt bind to server using found DN and provided password */
if (ldap_simple_bind_s(ld, auth_dn, pwd) == LDAP_SUCCESS) {
free(auth_dn);
ldap_unbind(ld);
/*
** check "user enabled" flag if present
*/
if( (p = config_str(NULL, "LDAPAuthOKFlag", NULL))) {
misc_strncpy(str, p, sizeof(str));
if( (v = strchr(str, '='))) {
*v++ = '\0';
} else {
v = 0;
}
if(v && strlen(v) && strlen(str)) {
if(0 != ldap_exists(ld, e, str, v, 0)) {
syslog_write(U_WRN,
"access denied for %s", NIL(who));
return -1;
} else {
syslog_write(T_DBG,
"LDAP auth ok-check: '%.256s'='%.256s' passed",
NIL(str), NIL(v));
}
} else {
errno = 0;
misc_die(FL, "ldap_auth: ?LDAPAuthOKFlag?");
}
} else {
syslog_write(T_DBG, "LDAP auth ok-check skipped");
}
return 0;
}
/* bind failed, password probably no good */
free(auth_dn);
ldap_unbind(ld);
return -1;
}
_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]