asn1: Make asn1_peek_full_tag return 0/errno
authorVolker Lendecke <vl@samba.org>
Mon, 21 Dec 2015 09:41:39 +0000 (10:41 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 5 Jan 2016 23:54:17 +0000 (00:54 +0100)
We don't need the full power of NTSTATUS here. This was the only
NTSTATUS in asn1.h, so I think it's worth removing it.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
auth/gensec/spnego.c
lib/util/asn1.c
lib/util/asn1.h
libcli/ldap/ldap_message.c

index 73c76eb7dfc551bb68711796cdad9e0e1057c58c..079a2bc79e366b4f482337bacd877f996e63a19c 100644 (file)
@@ -1095,26 +1095,24 @@ static NTSTATUS gensec_spnego_update_in(struct gensec_security *gensec_security,
 {
        struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
        size_t expected;
-       NTSTATUS status;
        bool ok;
 
        *full_in = data_blob_null;
 
        if (spnego_state->in_needed == 0) {
                size_t size = 0;
+               int ret;
 
                /*
                 * try to work out the size of the full
                 * input token, it might be fragmented
                 */
-               status = asn1_peek_full_tag(in,  ASN1_APPLICATION(0), &size);
-               if (!NT_STATUS_IS_OK(status) &&
-                   !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
-                       status = asn1_peek_full_tag(in, ASN1_CONTEXT(1), &size);
+               ret = asn1_peek_full_tag(in,  ASN1_APPLICATION(0), &size);
+               if ((ret != 0) && (ret != EAGAIN)) {
+                       ret = asn1_peek_full_tag(in, ASN1_CONTEXT(1), &size);
                }
 
-               if (NT_STATUS_IS_OK(status) ||
-                   NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
+               if ((ret == 0) || (ret == EAGAIN)) {
                        spnego_state->in_needed = size;
                } else {
                        /*
index 68935eba517941113e620b7e080d8a2eb02f7eb0..98cd41c47ce012dc773de1ddf8186eb811bbe6ee 100644 (file)
@@ -996,7 +996,7 @@ void asn1_load_nocopy(struct asn1_data *data, uint8_t *buf, size_t len)
        data->length = len;
 }
 
-NTSTATUS asn1_peek_full_tag(DATA_BLOB blob, uint8_t tag, size_t *packet_size)
+int asn1_peek_full_tag(DATA_BLOB blob, uint8_t tag, size_t *packet_size)
 {
        struct asn1_data asn1;
        size_t size;
@@ -1008,14 +1008,14 @@ NTSTATUS asn1_peek_full_tag(DATA_BLOB blob, uint8_t tag, size_t *packet_size)
 
        ok = asn1_peek_tag_needed_size(&asn1, tag, &size);
        if (!ok) {
-               return NT_STATUS_INVALID_BUFFER_SIZE;
+               return EMSGSIZE;
        }
 
        if (size > blob.length) {
                *packet_size = size;
-               return STATUS_MORE_ENTRIES;
+               return EAGAIN;
        }               
 
        *packet_size = size;
-       return NT_STATUS_OK;
+       return 0;
 }
index d15787e89c43dd5671d2993ebc414c1edab13ae4..0cf5fbc69d266cd2143b0f22db6f449dbaea851e 100644 (file)
@@ -100,6 +100,6 @@ bool asn1_check_enumerated(struct asn1_data *data, int v);
 bool asn1_write_enumerated(struct asn1_data *data, uint8_t v);
 bool asn1_blob(const struct asn1_data *asn1, DATA_BLOB *blob);
 void asn1_load_nocopy(struct asn1_data *data, uint8_t *buf, size_t len);
-NTSTATUS asn1_peek_full_tag(DATA_BLOB blob, uint8_t tag, size_t *packet_size);
+int asn1_peek_full_tag(DATA_BLOB blob, uint8_t tag, size_t *packet_size);
 
 #endif /* _ASN_1_H */
index bf836271de9012e431e2ec761bba839517737a83..491f96053cbc3e4c8aa5a9c25b678b6c37888fb9 100644 (file)
@@ -1635,6 +1635,8 @@ _PUBLIC_ NTSTATUS ldap_decode(struct asn1_data *data,
 */
 NTSTATUS ldap_full_packet(void *private_data, DATA_BLOB blob, size_t *packet_size)
 {
+       int ret;
+
        if (blob.length < 6) {
                /*
                 * We need at least 6 bytes to workout the length
@@ -1642,5 +1644,10 @@ NTSTATUS ldap_full_packet(void *private_data, DATA_BLOB blob, size_t *packet_siz
                 */
                return STATUS_MORE_ENTRIES;
        }
-       return asn1_peek_full_tag(blob, ASN1_SEQUENCE(0), packet_size);
+
+       ret = asn1_peek_full_tag(blob, ASN1_SEQUENCE(0), packet_size);
+       if (ret != 0) {
+               return map_nt_error_from_unix_common(ret);
+       }
+       return NT_STATUS_OK;
 }