libcli/security: fix sid_type_lookup().
[kai/samba.git] / libcli / ldap / ldap_message.c
index 9b00d0188d1ca0cb92071e0b2d1f8bcac2b79899..7756e731b247fd08796c0303d228dd5eaf098d22 100644 (file)
@@ -167,6 +167,12 @@ static bool ldap_encode_control(void *mem_ctx, struct asn1_data *data,
        }
 
        for (i = 0; handlers[i].oid != NULL; i++) {
+               if (!ctrl->oid) {
+                       /* not encoding this control, the OID has been
+                        * set to NULL indicating it isn't really
+                        * here */
+                       return true;
+               }
                if (strcmp(handlers[i].oid, ctrl->oid) == 0) {
                        if (!handlers[i].encode) {
                                if (ctrl->critical) {
@@ -434,6 +440,8 @@ _PUBLIC_ bool ldap_encode(struct ldap_message *msg,
        }
        case LDAP_TAG_UnbindRequest: {
 /*             struct ldap_UnbindRequest *r = &msg->r.UnbindRequest; */
+               asn1_push_tag(data, ASN1_APPLICATION_SIMPLE(msg->type));
+               asn1_pop_tag(data);
                break;
        }
        case LDAP_TAG_SearchRequest: {
@@ -668,6 +676,8 @@ _PUBLIC_ bool ldap_encode(struct ldap_message *msg,
                        if (!ldap_encode_control(mem_ctx, data,
                                                 control_handlers,
                                                 msg->controls[i])) {
+                               DEBUG(1,("Unable to encode control %s\n",
+                                        msg->controls[i]->oid));
                                return false;
                        }
                }
@@ -1230,8 +1240,8 @@ _PUBLIC_ NTSTATUS ldap_decode(struct asn1_data *data,
                msg->type = LDAP_TAG_SearchRequest;
                asn1_start_tag(data, tag);
                asn1_read_OctetString_talloc(msg, data, &r->basedn);
-               asn1_read_enumerated(data, (int *)&(r->scope));
-               asn1_read_enumerated(data, (int *)&(r->deref));
+               asn1_read_enumerated(data, (int *)(void *)&(r->scope));
+               asn1_read_enumerated(data, (int *)(void *)&(r->deref));
                asn1_read_Integer(data, &sizelimit);
                r->sizelimit = sizelimit;
                asn1_read_Integer(data, &timelimit);
@@ -1607,5 +1617,12 @@ _PUBLIC_ NTSTATUS ldap_decode(struct asn1_data *data,
 */
 NTSTATUS ldap_full_packet(void *private_data, DATA_BLOB blob, size_t *packet_size)
 {
-       return asn1_full_tag(blob, ASN1_SEQUENCE(0), packet_size);
+       if (blob.length < 6) {
+               /*
+                * We need at least 6 bytes to workout the length
+                * of the pdu.
+                */
+               return STATUS_MORE_ENTRIES;
+       }
+       return asn1_peek_full_tag(blob, ASN1_SEQUENCE(0), packet_size);
 }