Author: jerry Date: 2006-02-21 14:03:15 +0000 (Tue, 21 Feb 2006) New Revision: 13589
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=13589 Log: Make sure we only try to close the tdbsam file in endsampwent() when we have a valid pwent list from a setsampwent(). Fixes a bug with the reference count on the open tdb. Modified: branches/SAMBA_3_0/source/passdb/pdb_tdb.c trunk/source/passdb/pdb_tdb.c Changeset: Modified: branches/SAMBA_3_0/source/passdb/pdb_tdb.c =================================================================== --- branches/SAMBA_3_0/source/passdb/pdb_tdb.c 2006-02-21 03:29:02 UTC (rev 13588) +++ branches/SAMBA_3_0/source/passdb/pdb_tdb.c 2006-02-21 14:03:15 UTC (rev 13589) @@ -50,6 +50,7 @@ TDB_DATA key; }; static struct pwent_list *tdbsam_pwent_list; +static BOOL pwent_initialized; /* GLOBAL TDB SAM CONTEXT */ @@ -292,6 +293,7 @@ } tdb_traverse( tdbsam, tdbsam_traverse_setpwent, NULL ); + pwent_initialized = True; return NT_STATUS_OK; } @@ -305,6 +307,13 @@ { struct pwent_list *ptr, *ptr_next; + /* close the tdb only if we have a valid pwent state */ + + if ( pwent_initialized ) { + DEBUG(7, ("endtdbpwent: closed sam database.\n")); + tdbsam_close(); + } + /* clear out any remaining entries in the list */ for ( ptr=tdbsam_pwent_list; ptr; ptr = ptr_next ) { @@ -312,11 +321,9 @@ DLIST_REMOVE( tdbsam_pwent_list, ptr ); SAFE_FREE( ptr->key.dptr); SAFE_FREE( ptr ); - } + } - DEBUG(7, ("endtdbpwent: closed sam database.\n")); - - tdbsam_close(); + pwent_initialized = False; } /***************************************************************** Modified: trunk/source/passdb/pdb_tdb.c =================================================================== --- trunk/source/passdb/pdb_tdb.c 2006-02-21 03:29:02 UTC (rev 13588) +++ trunk/source/passdb/pdb_tdb.c 2006-02-21 14:03:15 UTC (rev 13589) @@ -50,6 +50,7 @@ TDB_DATA key; }; static struct pwent_list *tdbsam_pwent_list; +static BOOL pwent_initialized; /* GLOBAL TDB SAM CONTEXT */ @@ -292,6 +293,7 @@ } tdb_traverse( tdbsam, tdbsam_traverse_setpwent, NULL ); + pwent_initialized = True; return NT_STATUS_OK; } @@ -305,6 +307,13 @@ { struct pwent_list *ptr, *ptr_next; + /* close the tdb only if we have a valid pwent state */ + + if ( pwent_initialized ) { + DEBUG(7, ("endtdbpwent: closed sam database.\n")); + tdbsam_close(); + } + /* clear out any remaining entries in the list */ for ( ptr=tdbsam_pwent_list; ptr; ptr = ptr_next ) { @@ -312,11 +321,9 @@ DLIST_REMOVE( tdbsam_pwent_list, ptr ); SAFE_FREE( ptr->key.dptr); SAFE_FREE( ptr ); - } + } - DEBUG(7, ("endtdbpwent: closed sam database.\n")); - - tdbsam_close(); + pwent_initialized = False; } /*****************************************************************
