lib: Make sid_parse return the parsed length
[samba.git] / source3 / libads / ldap.c
index f9463043cc8f2deb53e71bee0dbdf93b39758043..8e0ecb87569ef6780ca8ea0a6f2d26a3472a4b19 100644 (file)
@@ -31,6 +31,7 @@
 #include "../libcli/security/security.h"
 #include "../librpc/gen_ndr/netlogon.h"
 #include "lib/param/loadparm.h"
+#include "libsmb/namequery.h"
 
 #ifdef HAVE_LDAP
 
@@ -2228,8 +2229,9 @@ done:
 */
 static void dump_binary(ADS_STRUCT *ads, const char *field, struct berval **values)
 {
-       int i, j;
+       size_t i;
        for (i=0; values[i]; i++) {
+               ber_len_t j;
                printf("%s: ", field);
                for (j=0; j<values[i]->bv_len; j++) {
                        printf("%02X", (unsigned char)values[i]->bv_val[j]);
@@ -2262,13 +2264,15 @@ static void dump_sid(ADS_STRUCT *ads, const char *field, struct berval **values)
 {
        int i;
        for (i=0; values[i]; i++) {
+               struct sid_parse_ret ret;
                struct dom_sid sid;
-               fstring tmp;
-               if (!sid_parse((const uint8_t *)values[i]->bv_val,
-                              values[i]->bv_len, &sid)) {
+               struct dom_sid_buf tmp;
+               ret = sid_parse((const uint8_t *)values[i]->bv_val,
+                               values[i]->bv_len, &sid);
+               if (ret.len == -1) {
                        return;
                }
-               printf("%s: %s\n", field, sid_to_fstring(tmp, &sid));
+               printf("%s: %s\n", field, dom_sid_str_buf(&sid, &tmp));
        }
 }
 
@@ -2539,8 +2543,7 @@ int ads_count_replies(ADS_STRUCT *ads, void *res)
 {
        char **values;
        char **ret = NULL;
-       int i;
-       size_t converted_size;
+       size_t i, converted_size;
 
        values = ldap_get_values(ads->ldap.ld, msg, field);
        if (!values)
@@ -2772,7 +2775,6 @@ int ads_count_replies(ADS_STRUCT *ads, void *res)
                   LDAPMessage *msg, const char *field, struct dom_sid **sids)
 {
        struct berval **values;
-       bool ret;
        int count, i;
 
        values = ldap_get_values_len(ads->ldap.ld, msg, field);
@@ -2795,11 +2797,13 @@ int ads_count_replies(ADS_STRUCT *ads, void *res)
 
        count = 0;
        for (i=0; values[i]; i++) {
+               struct sid_parse_ret ret;
                ret = sid_parse((const uint8_t *)values[i]->bv_val,
                                values[i]->bv_len, &(*sids)[count]);
-               if (ret) {
-                       DEBUG(10, ("pulling SID: %s\n",
-                                  sid_string_dbg(&(*sids)[count])));
+               if (ret.len != -1) {
+                       struct dom_sid_buf buf;
+                       DBG_DEBUG("pulling SID: %s\n",
+                                 dom_sid_str_buf(&(*sids)[count], &buf));
                        count++;
                }
        }
@@ -3354,6 +3358,7 @@ ADS_STATUS ads_get_sid_from_extended_dn(TALLOC_CTX *mem_ctx,
                }
                break;
        case ADS_EXTENDED_DN_HEX_STRING: {
+               struct sid_parse_ret ret;
                fstring buf;
                size_t buf_len;
 
@@ -3362,7 +3367,8 @@ ADS_STATUS ads_get_sid_from_extended_dn(TALLOC_CTX *mem_ctx,
                        return ADS_ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                }
 
-               if (!sid_parse((const uint8_t *)buf, buf_len, sid)) {
+               ret = sid_parse((const uint8_t *)buf, buf_len, sid);
+               if (ret.len == -1) {
                        DEBUG(10,("failed to parse sid\n"));
                        return ADS_ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                }
@@ -3453,18 +3459,18 @@ bool ads_has_samaccountname( ADS_STRUCT *ads, TALLOC_CTX *ctx, const char *machi
 
        status = ads_find_machine_acct(ads, &res, machine_name);
        if (!ADS_ERR_OK(status)) {
-               DEBUG(0,("ads_get_dnshostname: Failed to find account for %s\n",
+               DEBUG(0,("ads_has_samaccountname: Failed to find account for %s\n",
                        lp_netbios_name()));
                goto out;
        }
 
        if ( (count = ads_count_replies(ads, res)) != 1 ) {
-               DEBUG(1,("ads_get_dnshostname: %d entries returned!\n", count));
+               DEBUG(1,("ads_has_samaccountname: %d entries returned!\n", count));
                goto out;
        }
 
        if ( (name = ads_pull_string(ads, ctx, res, "sAMAccountName")) == NULL ) {
-               DEBUG(0,("ads_get_dnshostname: No sAMAccountName attribute!\n"));
+               DEBUG(0,("ads_has_samaccountname: No sAMAccountName attribute!\n"));
        }
 
 out: