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;
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;
}
/*
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
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);
}
}
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
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 */
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;
}