s3-talloc Change TALLOC_P() to talloc()
[nivanova/samba-autobuild/.git] / source3 / libads / ldap_schema.c
index b5d2d35889e17d5c4402bdcee995c7c90de8ad14..7368be830fb24e55bfd5dd72a9075812706f79d9 100644 (file)
 */
 
 #include "includes.h"
+#include "ads.h"
+#include "libads/ldap_schema.h"
+#include "../libcli/ldap/ldap_ndr.h"
 
 #ifdef HAVE_LDAP
 
-ADS_STATUS ads_get_attrnames_by_oids(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx,
-                                    const char *schema_path,
-                                    const char **OIDs, size_t num_OIDs, 
-                                    char ***OIDs_out, char ***names, size_t *count)
+static ADS_STATUS ads_get_attrnames_by_oids(ADS_STRUCT *ads,
+                                           TALLOC_CTX *mem_ctx,
+                                           const char *schema_path,
+                                           const char **OIDs,
+                                           size_t num_OIDs,
+                                           char ***OIDs_out, char ***names,
+                                           size_t *count)
 {
        ADS_STATUS status;
        LDAPMessage *res = NULL;
@@ -70,11 +76,11 @@ ADS_STATUS ads_get_attrnames_by_oids(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx,
                goto out;
        }
 
-       if (((*names) = TALLOC_ARRAY(mem_ctx, char *, *count)) == NULL) {
+       if (((*names) = talloc_array(mem_ctx, char *, *count)) == NULL) {
                status = ADS_ERROR(LDAP_NO_MEMORY);
                goto out;
        }
-       if (((*OIDs_out) = TALLOC_ARRAY(mem_ctx, char *, *count)) == NULL) {
+       if (((*OIDs_out) = talloc_array(mem_ctx, char *, *count)) == NULL) {
                status = ADS_ERROR(LDAP_NO_MEMORY);
                goto out;
        }
@@ -122,7 +128,7 @@ const char *ads_get_attrname_by_guid(ADS_STRUCT *ads,
                goto done;
        }
 
-       guid_bin = guid_binstring(schema_guid);
+       guid_bin = ldap_encode_ndr_GUID(mem_ctx, schema_guid);
        if (!guid_bin) {
                goto done;
        }
@@ -145,53 +151,12 @@ const char *ads_get_attrname_by_guid(ADS_STRUCT *ads,
        result = ads_pull_string(ads, mem_ctx, res, "lDAPDisplayName");
 
  done:
-       SAFE_FREE(guid_bin);
+       TALLOC_FREE(guid_bin);
        ads_msgfree(ads, res);
        return result;
        
 }
 
-const char *ads_get_attrname_by_oid(ADS_STRUCT *ads, const char *schema_path, TALLOC_CTX *mem_ctx, const char * OID)
-{
-       ADS_STATUS rc;
-       int count = 0;
-       LDAPMessage *res = NULL;
-       char *expr = NULL;
-       const char *attrs[] = { "lDAPDisplayName", NULL };
-       char *result;
-
-       if (ads == NULL || mem_ctx == NULL || OID == NULL) {
-               goto failed;
-       }
-
-       expr = talloc_asprintf(mem_ctx, "(attributeId=%s)", OID);
-       if (expr == NULL) {
-               goto failed;
-       }
-
-       rc = ads_do_search_retry(ads, schema_path, LDAP_SCOPE_SUBTREE, 
-               expr, attrs, &res);
-       if (!ADS_ERR_OK(rc)) {
-               goto failed;
-       }
-
-       count = ads_count_replies(ads, res);
-       if (count == 0 || !res) {
-               goto failed;
-       }
-
-       result = ads_pull_string(ads, mem_ctx, res, "lDAPDisplayName");
-       ads_msgfree(ads, res);
-
-       return result;
-       
-failed:
-       DEBUG(0,("ads_get_attrname_by_oid: failed to retrieve name for oid: %s\n", 
-               OID));
-       
-       ads_msgfree(ads, res);
-       return NULL;
-}
 /*********************************************************************
 *********************************************************************/
 
@@ -287,7 +252,7 @@ ADS_STATUS ads_check_posix_schema_mapping(TALLOC_CTX *mem_ctx,
                return ADS_ERROR(LDAP_NO_MEMORY);
        }
 
-       if ( (schema = TALLOC_P(mem_ctx, struct posix_schema)) == NULL ) {
+       if ( (schema = talloc(mem_ctx, struct posix_schema)) == NULL ) {
                TALLOC_FREE( ctx );
                return ADS_ERROR(LDAP_NO_MEMORY);
        }