Author: nkinder
Update of /cvs/dirsec/mod_admserv
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv11357
Modified Files:
mod_admserv.c
Log Message:
Resolves: 400341
Summary: Be sure to only change admin user's password in change-sie-password.
Index: mod_admserv.c
===================================================================
RCS file: /cvs/dirsec/mod_admserv/mod_admserv.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- mod_admserv.c 6 Jul 2007 18:06:19 -0000 1.32
+++ mod_admserv.c 29 Nov 2007 23:22:18 -0000 1.33
@@ -701,6 +701,9 @@
return admserv_ldap_auth_userdn_password(server, data->bindDN, data->bindPW, &ignored);
}
+/* The returned string is allocated from a pool in APR. Attempting to free this string
+ * will result in a crash. APR will deal with the cleanup itself when it cleans up the
+ * entire pool. */
static char *
formLdapURL(LdapServerData *data, apr_pool_t *p)
{
@@ -1196,19 +1199,44 @@
const char* bindpw, request_rec *r)
{
LDAP *ld;
+ AdmldapInfo ldapInfo;
int ldapError;
char *ldapURL = NULL;
const char *userDN = NULL;
+ char *adminDN = NULL;
LDAPMod mod, *mods[2];
char *vals[2];
char *attrs[2];
int rval = 0;
+ int error;
- /* update password for uid */
+ /* We need ldapInfo to fetch the adminDN */
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
+ "task_update_registry_server_bindpw: getting ldap info for [%s]",
+ configdir);
+ ldapInfo = admldapBuildInfo(configdir, &error);
+
+ if (!ldapInfo) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
+ "task_update_registry_server_bindpw: Could not build ldap info for config in [%s]: %d",
+ configdir, error);
+ goto bailout;
+ }
+
+ /* get the admin user DN */
+ adminDN = admldapGetUserDN(ldapInfo, NULL);
+
+ if (!adminDN) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
+ "failed to retreive admin user DN");
+ goto bailout;
+ }
+
+ /* update password for adminDN */
if (!(ld = openLDAPConnection(®istryServer))) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
"task_update_registry_server_bindpw(): cannot connect to the Configuration Directory Server");
- return rval;
+ goto bailout;
}
userDN = apr_table_get(r->notes, RQ_NOTES_USERDN);
@@ -1246,21 +1274,33 @@
mod.mod_values = vals;
mods[0] = &mod;
mods[1] = NULL;
- if (LDAP_SUCCESS != (ldapError = ldap_modify_s(ld, userDN, mods))) {
+ if (LDAP_SUCCESS != (ldapError = ldap_modify_s(ld, adminDN, mods))) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
"task_update_registry_server_bindpw(): ldap_modify for %s failed: %s",
- userDN, ldap_err2string(ldapError));
+ adminDN, ldap_err2string(ldapError));
goto bailout;
}
- /* update the auth_users cache */
+
+ /* we don't want to free this since APR allocates it from a pool. APR will take care of it */
ldapURL = formLdapURL(®istryServer, r->pool);
- create_auth_users_cache_entry(uid, (char *)userDN, password, ldapURL);
+
+ /* update the auth_users cache */
+ create_auth_users_cache_entry(uid, adminDN, password, ldapURL);
+
+ /* We only want to reset the pwd in the request if RQ_NOTES_USERDN is the admin user */
+ if(strcasecmp(adminDN, userDN) == 0) {
+ apr_table_set(r->notes, RQ_NOTES_USERPW, password);
+ }
rval = 1;
+
bailout:
- closeLDAPConnection(ld);
- if (NULL != ldapURL)
- free(ldapURL);
+ if (ld) {
+ closeLDAPConnection(ld);
+ }
+ if (ldapInfo) {
+ destroyAdmldap(ldapInfo);
+ }
return rval;
}
@@ -1271,12 +1311,12 @@
change_sie_password(const char *name, char *query, void* arg, request_rec *r)
{
FILE *f;
- char *uid=NULL ,*pw=NULL, *col=NULL;
+ char *uid=NULL ,*pw=NULL, *col=NULL, *origpw_hash=NULL;
char *newpw=query;
char filename[BIG_LINE];
char inbuf[BIG_LINE];
char outbuf[64]; /* needs at least 36 bytes */
- char *origpw = (char *)apr_table_get(r->notes, RQ_NOTES_USERPW);
+ char *bindpw = (char *)apr_table_get(r->notes, RQ_NOTES_USERPW);
int admpwd_done = 0;
apr_snprintf(filename, sizeof(filename), "%s/admpw", configdir);
@@ -1307,7 +1347,7 @@
return 0;
}
- uid = inbuf; *col=0; pw=col+1;
+ uid = inbuf; *col=0; origpw_hash=col+1;
apr_sha1_base64(newpw, strlen(newpw), outbuf);
if (!update_admpwd(configdir, uid, outbuf)) {
@@ -1317,18 +1357,17 @@
}
admpwd_done = 1;
- if (!task_update_registry_server_bindpw(uid, strdup(newpw), origpw, r)) {
+ if (!task_update_registry_server_bindpw(uid, strdup(newpw), bindpw, r)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
"failed to update server bindpw");
goto recover;
}
- apr_table_set(r->notes, RQ_NOTES_USERPW, newpw);
+
return 1;
recover:
if (admpwd_done) {
- apr_sha1_base64(origpw, strlen(origpw), outbuf);
- update_admpwd(configdir, uid, outbuf);
+ update_admpwd(configdir, uid, origpw_hash);
}
return 0;
}