summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2004-03-22 22:49:40 +0000
committerGerald Carter <jerry@samba.org>2004-03-22 22:49:40 +0000
commit14dd75d181293fa5335184d2d836834a42edcbb4 (patch)
tree2c26a8a1dc66ac9c755b08937c7d64954289a544 /source3
parentf58e6a997750c16e0c1ffccabbbf69469eb280c2 (diff)
downloadsamba-14dd75d181293fa5335184d2d836834a42edcbb4.tar.gz
samba-14dd75d181293fa5335184d2d836834a42edcbb4.tar.bz2
samba-14dd75d181293fa5335184d2d836834a42edcbb4.zip
bug 1195: add flag to ADS_STRUCT so we know who owns the main structure's memory (not the members though)
(This used to be commit 4449e0e251190b741f51348819669453f0758f36)
Diffstat (limited to 'source3')
-rw-r--r--source3/include/ads.h2
-rw-r--r--source3/libads/ads_struct.c19
-rw-r--r--source3/nsswitch/winbindd_ads.c23
3 files changed, 35 insertions, 9 deletions
diff --git a/source3/include/ads.h b/source3/include/ads.h
index 65a5ade556..5ae577efe7 100644
--- a/source3/include/ads.h
+++ b/source3/include/ads.h
@@ -10,6 +10,8 @@ typedef struct {
time_t last_attempt; /* last attempt to reconnect */
int ldap_port;
+ int is_mine; /* do I own this structure's memory? */
+
/* info needed to find the server */
struct {
char *realm;
diff --git a/source3/libads/ads_struct.c b/source3/libads/ads_struct.c
index 9774968e12..92f37093f4 100644
--- a/source3/libads/ads_struct.c
+++ b/source3/libads/ads_struct.c
@@ -102,13 +102,10 @@ ADS_STRUCT *ads_init(const char *realm,
ads->server.foreign = 1;
}
- return ads;
-}
+ /* the caller will own the memory by default */
+ ads->is_mine = 1;
-/* a simpler ads_init() interface using all defaults */
-ADS_STRUCT *ads_init_simple(void)
-{
- return ads_init(NULL, NULL, NULL);
+ return ads;
}
/*
@@ -117,6 +114,9 @@ ADS_STRUCT *ads_init_simple(void)
void ads_destroy(ADS_STRUCT **ads)
{
if (ads && *ads) {
+ BOOL is_mine;
+
+ is_mine = (*ads)->is_mine;
#if HAVE_LDAP
if ((*ads)->ld) ldap_unbind((*ads)->ld);
#endif
@@ -133,8 +133,11 @@ void ads_destroy(ADS_STRUCT **ads)
SAFE_FREE((*ads)->config.realm);
SAFE_FREE((*ads)->config.bind_path);
SAFE_FREE((*ads)->config.ldap_server_name);
-
+
+
ZERO_STRUCTP(*ads);
- SAFE_FREE(*ads);
+
+ if ( is_mine )
+ SAFE_FREE(*ads);
}
}
diff --git a/source3/nsswitch/winbindd_ads.c b/source3/nsswitch/winbindd_ads.c
index e6b857f406..8bec04f1f1 100644
--- a/source3/nsswitch/winbindd_ads.c
+++ b/source3/nsswitch/winbindd_ads.c
@@ -5,6 +5,7 @@
Copyright (C) Andrew Tridgell 2001
Copyright (C) Andrew Bartlett <abartlet@samba.org> 2003
+ Copyright (C) Gerald (Jerry) Carter 2004
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -39,7 +40,21 @@ static ADS_STRUCT *ads_cached_connection(struct winbindd_domain *domain)
ADS_STATUS status;
if (domain->private) {
- return (ADS_STRUCT *)domain->private;
+ ads = (ADS_STRUCT *)domain->private;
+
+ /* check for a valid structure */
+ if ( ads->config.realm ) {
+ return ads;
+ }
+ else {
+ /* we own this ADS_STRUCT so make sure it goes away */
+ ads->is_mine = True;
+ ads_destroy( &ads );
+
+ /* we should always be NULL here */
+ SMB_ASSERT( ads == NULL );
+ }
+
}
/* we don't want this to affect the users ccache */
@@ -79,6 +94,12 @@ static ADS_STRUCT *ads_cached_connection(struct winbindd_domain *domain)
return NULL;
}
+ /* set the flag that says we don't own the memory even
+ though we do so that ads_destroy() won't destroy the
+ structure we pass back by reference */
+
+ ads->is_mine = False;
+
domain->private = (void *)ads;
return ads;
}