Patch: back-passwd needs pwent mutex (ITS#1794) ================ Written by Hallvard B. Furuseth and placed into the public domain. This software is not subject to any license of the University of Oslo. ================ back-passwd uses getpwent() and setpwfile(), which use static data. It needs a mutex to make sure these operations can complete without interference from another back-passwd call. Here is a patch. Hallvard B. Furuseth , May 2002. diff -N -u2 -r servers/slapd/back-passwd/back-passwd.h~ servers/slapd/back-passwd/back-passwd.h --- servers/slapd/back-passwd/back-passwd.h~ Thu Jan 1 01:00:00 1970 +++ servers/slapd/back-passwd/back-passwd.h Fri May 3 15:38:57 2002 @@ -0,0 +1,13 @@ +/* $OpenLDAP$ */ +#ifndef _BACK_PASSWD_H +#define _BACK_PASSWD_H + +#include "external.h" + +LDAP_BEGIN_DECL + +extern ldap_pvt_thread_mutex_t passwd_mutex; + +LDAP_END_DECL + +#endif /* _BACK_PASSWD_H */ diff -N -u2 -r servers/slapd/back-passwd/external.h~ servers/slapd/back-passwd/external.h --- servers/slapd/back-passwd/external.h~ Wed Dec 26 08:47:04 2001 +++ servers/slapd/back-passwd/external.h Fri May 3 15:31:08 2002 @@ -6,4 +6,5 @@ extern BI_init passwd_back_initialize; +extern BI_destroy passwd_back_destroy; extern BI_op_search passwd_back_search; diff -N -u2 -r servers/slapd/back-passwd/init.c~ servers/slapd/back-passwd/init.c --- servers/slapd/back-passwd/init.c~ Wed Dec 26 08:32:08 2001 +++ servers/slapd/back-passwd/init.c Fri May 3 15:39:14 2002 @@ -9,5 +9,7 @@ #include "slap.h" -#include "external.h" +#include "back-passwd.h" + +ldap_pvt_thread_mutex_t passwd_mutex; #ifdef SLAPD_PASSWD_DYNAMIC @@ -31,8 +33,10 @@ ) { + ldap_pvt_thread_mutex_init( &passwd_mutex ); + bi->bi_open = 0; bi->bi_config = 0; bi->bi_close = 0; - bi->bi_destroy = 0; + bi->bi_destroy = passwd_back_destroy; bi->bi_db_init = 0; @@ -61,4 +65,13 @@ bi->bi_connection_destroy = 0; + return 0; +} + +int +passwd_back_destroy( + BackendInfo *bi +) +{ + ldap_pvt_thread_mutex_destroy( &passwd_mutex ); return 0; } diff -N -u2 -r servers/slapd/back-passwd/search.c~ servers/slapd/back-passwd/search.c --- servers/slapd/back-passwd/search.c~ Thu May 2 10:36:36 2002 +++ servers/slapd/back-passwd/search.c Fri May 3 15:39:23 2002 @@ -14,7 +14,9 @@ #include "slap.h" -#include "external.h" +#include "back-passwd.h" #include +stativ void pw_start( Backend *be ); + static Entry *pw2entry( Backend *be, @@ -60,12 +62,4 @@ : slimit; - endpwent(); - -#ifdef HAVE_SETPWFILE - if ( be->be_private != NULL ) { - (void) setpwfile( (char *) be->be_private ); - } -#endif /* HAVE_SETPWFILE */ - /* Handle a query for the base of this backend */ if ( be_issuffix( be, nbase ) ) { @@ -131,8 +125,11 @@ /* check all our "children" */ + ldap_pvt_thread_mutex_lock( &passwd_mutex ); + pw_start( be ); for ( pw = getpwent(); pw != NULL; pw = getpwent() ) { /* check for abandon */ if ( op->o_abandon ) { endpwent(); + ldap_pvt_thread_mutex_unlock( &passwd_mutex ); return( -1 ); } @@ -143,4 +140,5 @@ NULL, NULL, NULL, NULL ); endpwent(); + ldap_pvt_thread_mutex_unlock( &passwd_mutex ); return( 0 ); } @@ -149,4 +147,5 @@ err = LDAP_OPERATIONS_ERROR; endpwent(); + ldap_pvt_thread_mutex_unlock( &passwd_mutex ); goto done; } @@ -158,4 +157,5 @@ NULL, NULL, NULL, NULL ); endpwent(); + ldap_pvt_thread_mutex_unlock( &passwd_mutex ); return( 0 ); } @@ -169,4 +169,5 @@ } endpwent(); + ldap_pvt_thread_mutex_unlock( &passwd_mutex ); } @@ -202,11 +203,16 @@ } + ldap_pvt_thread_mutex_lock( &passwd_mutex ); + pw_start( be ); if ( (pw = getpwnam( rdn[0][0]->la_value.bv_val )) == NULL ) { matched = parent.bv_val; err = LDAP_NO_SUCH_OBJECT; + ldap_pvt_thread_mutex_unlock( &passwd_mutex ); goto done; } - if ( !(e = pw2entry( be, pw, &text )) ) { + e = pw2entry( be, pw, &text ); + ldap_pvt_thread_mutex_unlock( &passwd_mutex ); + if ( !e ) { err = LDAP_OPERATIONS_ERROR; goto done; @@ -230,4 +236,18 @@ return( 0 ); +} + +static void +pw_start( + Backend *be +) +{ + endpwent(); + +#ifdef HAVE_SETPWFILE + if ( be->be_private != NULL ) { + (void) setpwfile( (char *) be->be_private ); + } +#endif /* HAVE_SETPWFILE */ }