libcli/security: fix sid_type_lookup().
[kai/samba.git] / libcli / ldap / ldap_message.c
index 8b0f8a2ea1560f36f6f9e96dfd57fc31f9528f0b..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;
                        }
                }
@@ -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);
 }