ads_struct
[metze/samba/wip.git] / source3 / libads / ads_struct.c
index 7794952387e0a65c94703eb906df9dd833e172c7..1c269fbc69fe8fdf72ffd400766c3b4667b6f788 100644 (file)
@@ -3,17 +3,17 @@
    ads (active directory) utility library
    Copyright (C) Andrew Tridgell 2001
    Copyright (C) Andrew Bartlett 2001
-   
+
    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
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -52,11 +52,20 @@ char *ads_build_path(const char *realm, const char *sep, const char *field, int
                return NULL;
        }
 
-       strlcpy(ret,field, len);
+       if (strlcpy(ret,field, len) >= len) {
+               /* Truncate ! */
+               free(r);
+               free(ret);
+               return NULL;
+       }
        p=strtok_r(r, sep, &saveptr);
        if (p) {
-               strlcat(ret, p, len);
-       
+               if (strlcat(ret, p, len) >= len) {
+                       free(r);
+                       free(ret);
+                       return NULL;
+               }
+
                while ((p=strtok_r(NULL, sep, &saveptr)) != NULL) {
                        int retval;
                        char *s = NULL;
@@ -93,7 +102,7 @@ char *ads_build_dn(const char *realm)
 char *ads_build_domain(const char *dn)
 {
        char *dnsdomain = NULL;
-       
+
        /* result should always be shorter than the DN */
 
        if ( (dnsdomain = SMB_STRDUP( dn )) == NULL ) {
@@ -101,7 +110,11 @@ char *ads_build_domain(const char *dn)
                return NULL;            
        }       
 
-       strlower_m( dnsdomain );        
+       if (!strlower_m( dnsdomain )) {
+               SAFE_FREE(dnsdomain);
+               return NULL;
+       }
+
        all_string_sub( dnsdomain, "dc=", "", 0);
        all_string_sub( dnsdomain, ",", ".", 0 );
 
@@ -123,22 +136,14 @@ ADS_STRUCT *ads_init(const char *realm,
 {
        ADS_STRUCT *ads;
        int wrap_flags;
-       
+
        ads = SMB_XMALLOC_P(ADS_STRUCT);
        ZERO_STRUCTP(ads);
-       
+
        ads->server.realm = realm? SMB_STRDUP(realm) : NULL;
        ads->server.workgroup = workgroup ? SMB_STRDUP(workgroup) : NULL;
        ads->server.ldap_server = ldap_server? SMB_STRDUP(ldap_server) : NULL;
 
-       /* we need to know if this is a foreign realm */
-       if (realm && *realm && !strequal(lp_realm(), realm)) {
-               ads->server.foreign = 1;
-       }
-       if (workgroup && *workgroup && !strequal(lp_workgroup(), workgroup)) {
-               ads->server.foreign = 1;
-       }
-
        /* the caller will own the memory by default */
        ads->is_mine = 1;
 
@@ -149,6 +154,10 @@ ADS_STRUCT *ads_init(const char *realm,
 
        ads->auth.flags = wrap_flags;
 
+       /* Start with the configured page size when the connection is new,
+        * we will drop it by half we get a timeout.   */
+       ads->config.ldap_page_size     = lp_ldap_page_size();
+
        return ads;
 }
 
@@ -175,17 +184,18 @@ void ads_destroy(ADS_STRUCT **ads)
                bool is_mine;
 
                is_mine = (*ads)->is_mine;
-#if HAVE_LDAP
+#ifdef HAVE_LDAP
                ads_disconnect(*ads);
 #endif
                SAFE_FREE((*ads)->server.realm);
                SAFE_FREE((*ads)->server.workgroup);
                SAFE_FREE((*ads)->server.ldap_server);
 
-               SAFE_FREE((*ads)->auth.realm);
-               SAFE_FREE((*ads)->auth.password);
-               SAFE_FREE((*ads)->auth.user_name);
+               SAFE_FREE((*ads)->auth._realm);
+               SAFE_FREE((*ads)->auth._password);
+               SAFE_FREE((*ads)->auth._user_name);
                SAFE_FREE((*ads)->auth.kdc_server);
+               SAFE_FREE((*ads)->auth._ccache_name);
 
                SAFE_FREE((*ads)->config.realm);
                SAFE_FREE((*ads)->config.bind_path);
@@ -194,7 +204,7 @@ void ads_destroy(ADS_STRUCT **ads)
                SAFE_FREE((*ads)->config.client_site_name);
                SAFE_FREE((*ads)->config.schema_path);
                SAFE_FREE((*ads)->config.config_path);
-               
+
                ZERO_STRUCTP(*ads);
 
                if ( is_mine )