r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[abartlet/samba.git/.git] / source3 / libads / ads_struct.c
index d8676d050dd18b761e114369e434759e32d30a6b..b01e0879ef9cab970a7537b33064abd87656ccb7 100644 (file)
@@ -6,7 +6,7 @@
    
    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 2 of the License, or
+   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,
@@ -15,8 +15,7 @@
    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, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -42,22 +41,24 @@ char *ads_build_path(const char *realm, const char *sep, const char *field, int
 
        len = (numbits+1)*(strlen(field)+1) + strlen(r) + 1;
 
-       ret = SMB_MALLOC(len);
+       ret = (char *)SMB_MALLOC(len);
        if (!ret)
                return NULL;
 
        strlcpy(ret,field, len);
        p=strtok(r,sep); 
-       strlcat(ret, p, len);
-
-       while ((p=strtok(NULL,sep))) {
-               char *s;
-               if (reverse)
-                       asprintf(&s, "%s%s,%s", field, p, ret);
-               else
-                       asprintf(&s, "%s,%s%s", ret, field, p);
-               free(ret);
-               ret = s;
+       if (p) {
+               strlcat(ret, p, len);
+       
+               while ((p=strtok(NULL,sep))) {
+                       char *s;
+                       if (reverse)
+                               asprintf(&s, "%s%s,%s", field, p, ret);
+                       else
+                               asprintf(&s, "%s,%s%s", ret, field, p);
+                       free(ret);
+                       ret = s;
+               }
        }
 
        free(r);
@@ -73,6 +74,28 @@ char *ads_build_dn(const char *realm)
        return ads_build_path(realm, ".", "dc=", 0);
 }
 
+/* return a DNS name in the for aa.bb.cc from the DN  
+   "dc=AA,dc=BB,dc=CC".  caller must free
+*/
+char *ads_build_domain(const char *dn)
+{
+       char *dnsdomain = NULL;
+       
+       /* result should always be shorter than the DN */
+
+       if ( (dnsdomain = SMB_STRDUP( dn )) == NULL ) {
+               DEBUG(0,("ads_build_domain: malloc() failed!\n"));              
+               return NULL;            
+       }       
+
+       strlower_m( dnsdomain );        
+       all_string_sub( dnsdomain, "dc=", "", 0);
+       all_string_sub( dnsdomain, ",", ".", 0 );
+
+       return dnsdomain;       
+}
+
+
 
 #ifndef LDAP_PORT
 #define LDAP_PORT 389
@@ -118,12 +141,13 @@ void ads_destroy(ADS_STRUCT **ads)
 
                is_mine = (*ads)->is_mine;
 #if HAVE_LDAP
-               if ((*ads)->ld) ldap_unbind((*ads)->ld);
+               if ((*ads)->ld) {
+                       ldap_unbind((*ads)->ld);
+               }
 #endif
                SAFE_FREE((*ads)->server.realm);
                SAFE_FREE((*ads)->server.workgroup);
                SAFE_FREE((*ads)->server.ldap_server);
-               SAFE_FREE((*ads)->server.ldap_uri);
 
                SAFE_FREE((*ads)->auth.realm);
                SAFE_FREE((*ads)->auth.password);
@@ -132,13 +156,9 @@ void ads_destroy(ADS_STRUCT **ads)
 
                SAFE_FREE((*ads)->config.realm);
                SAFE_FREE((*ads)->config.bind_path);
-               SAFE_FREE((*ads)->config.schema_path);
                SAFE_FREE((*ads)->config.ldap_server_name);
-               
-               SAFE_FREE((*ads)->schema.sfu_uidnumber_attr);
-               SAFE_FREE((*ads)->schema.sfu_gidnumber_attr);
-               SAFE_FREE((*ads)->schema.sfu_shell_attr);
-               SAFE_FREE((*ads)->schema.sfu_homedir_attr);
+               SAFE_FREE((*ads)->config.server_site_name);
+               SAFE_FREE((*ads)->config.client_site_name);
                
                ZERO_STRUCTP(*ads);