lib: Make sid_parse return the parsed length
[samba.git] / source3 / lib / tldap_util.c
index 89f812b97e07f04b62fd9416582bfde4b96b8746..efc37e48e7c52f44840a6b88d78388aeff2f8995 100644 (file)
@@ -22,8 +22,6 @@
 #include "tldap_util.h"
 #include "../libcli/security/security.h"
 #include "../lib/util/asn1.h"
-#include "../librpc/ndr/libndr.h"
-#include "lib/util/base64.h"
 
 bool tldap_entry_values(struct tldap_message *msg, const char *attribute,
                        DATA_BLOB **values, int *num_values)
@@ -90,11 +88,13 @@ bool tldap_pull_binsid(struct tldap_message *msg, const char *attribute,
                       struct dom_sid *sid)
 {
        DATA_BLOB val;
+       struct sid_parse_ret ret;
 
        if (!tldap_get_single_valueblob(msg, attribute, &val)) {
                return false;
        }
-       return sid_parse(val.data, val.length, sid);
+       ret = sid_parse(val.data, val.length, sid);
+       return (ret.len != -1);
 }
 
 bool tldap_pull_guid(struct tldap_message *msg, const char *attribute,
@@ -391,13 +391,22 @@ bool tldap_pull_uint64(struct tldap_message *msg, const char *attr,
 {
        char *str;
        uint64_t result;
+       int error = 0;
 
        str = tldap_talloc_single_attribute(msg, attr, talloc_tos());
        if (str == NULL) {
                DEBUG(10, ("Could not find attribute %s\n", attr));
                return false;
        }
-       result = strtoull(str, NULL, 10);
+
+       result = strtoull_err(str, NULL, 10, &error);
+       if (error != 0) {
+               DBG_DEBUG("Attribute conversion failed (%s)\n",
+                         strerror(error));
+               TALLOC_FREE(str);
+               return false;
+       }
+
        TALLOC_FREE(str);
        *presult = result;
        return true;
@@ -459,7 +468,6 @@ static void tldap_fetch_rootdse_done(struct tevent_req *subreq)
 
        rc = tldap_search_recv(subreq, state, &msg);
        if (tevent_req_ldap_error(req, rc)) {
-               TALLOC_FREE(subreq);
                return;
        }
 
@@ -741,7 +749,6 @@ static void tldap_search_paged_done(struct tevent_req *subreq)
 
        rc = tldap_search_recv(subreq, state, &state->result);
        if (tevent_req_ldap_error(req, rc)) {
-               TALLOC_FREE(subreq);
                return;
        }