summaryrefslogtreecommitdiff
path: root/source4/libcli
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2004-08-17 11:22:44 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:58:02 -0500
commitc074e30e2eacaacebb95efd755ad7de74a0970e8 (patch)
tree1f822f1482e34902b96f39e8ea5f0416753e054c /source4/libcli
parenta4b2f077e05469f76b8fe4a7f1e097c9e3495871 (diff)
downloadsamba-c074e30e2eacaacebb95efd755ad7de74a0970e8.tar.gz
samba-c074e30e2eacaacebb95efd755ad7de74a0970e8.tar.bz2
samba-c074e30e2eacaacebb95efd755ad7de74a0970e8.zip
r1856: - move asn1 functions to asn1.c
- merge some stuff from trunk metze (This used to be commit 267edf1c0bb1ed73f1ba19148e6412b9a1c41979)
Diffstat (limited to 'source4/libcli')
-rw-r--r--source4/libcli/ldap/ldap.c90
-rw-r--r--source4/libcli/util/asn1.c24
2 files changed, 71 insertions, 43 deletions
diff --git a/source4/libcli/ldap/ldap.c b/source4/libcli/ldap/ldap.c
index b6272f694e..b319299b1e 100644
--- a/source4/libcli/ldap/ldap.c
+++ b/source4/libcli/ldap/ldap.c
@@ -971,7 +971,8 @@ BOOL ldap_encode(struct ldap_message *msg, DATA_BLOB *result)
break;
}
case LDAP_TAG_ModifyDNResponse: {
-/* struct ldap_Result *r = &msg->r.ModifyDNResponse; */
+ struct ldap_Result *r = &msg->r.ModifyDNResponse;
+ ldap_encode_response(msg->type, r, &data);
break;
}
case LDAP_TAG_CompareRequest: {
@@ -1061,46 +1062,12 @@ static void ldap_decode_response(TALLOC_CTX *mem_ctx,
asn1_read_enumerated(data, &result->resultcode);
asn1_read_OctetString_talloc(mem_ctx, data, &result->dn);
asn1_read_OctetString_talloc(mem_ctx, data, &result->errormessage);
- if (asn1_peek_tag(data, ASN1_OCTET_STRING))
+ if (asn1_peek_tag(data, ASN1_CONTEXT(3))) {
+ asn1_start_tag(data, ASN1_CONTEXT(3));
asn1_read_OctetString_talloc(mem_ctx, data, &result->referral);
- else
- result->referral = NULL;
- asn1_end_tag(data);
-}
-
-/* read a octet string blob */
-static BOOL asn1_read_ContextSimple(ASN1_DATA *data, uint8_t num, DATA_BLOB *blob)
-{
- int len;
- ZERO_STRUCTP(blob);
- if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(num))) return False;
- len = asn1_tag_remaining(data);
- if (len < 0) {
- data->has_error = True;
- return False;
- }
- *blob = data_blob(NULL, len);
- asn1_read(data, blob->data, len);
- asn1_end_tag(data);
- return !data->has_error;
-}
-
-static void ldap_decode_BindResponse(TALLOC_CTX *mem_ctx,
- ASN1_DATA *data,
- enum ldap_request_tag tag,
- struct ldap_BindResponse *BindResp)
-{
- asn1_start_tag(data, ASN1_APPLICATION(tag));
- asn1_read_enumerated(data, &BindResp->response.resultcode);
- asn1_read_OctetString_talloc(mem_ctx, data, &BindResp->response.dn);
- asn1_read_OctetString_talloc(mem_ctx, data, &BindResp->response.errormessage);
- if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(7))) {
- DATA_BLOB tmp_blob = data_blob(NULL, 0);
- asn1_read_ContextSimple(data, 7, &tmp_blob);
- BindResp->SASL.secblob = data_blob_talloc(mem_ctx, tmp_blob.data, tmp_blob.length);
- data_blob_free(&tmp_blob);
+ asn1_end_tag(data);
} else {
- BindResp->SASL.secblob = data_blob(NULL, 0);
+ result->referral = NULL;
}
asn1_end_tag(data);
}
@@ -1300,9 +1267,26 @@ BOOL ldap_decode(ASN1_DATA *data, struct ldap_message *msg)
case ASN1_APPLICATION(LDAP_TAG_BindResponse): {
struct ldap_BindResponse *r = &msg->r.BindResponse;
msg->type = LDAP_TAG_BindResponse;
- ldap_decode_BindResponse(msg->mem_ctx,
- data, LDAP_TAG_BindResponse,
- r);
+ asn1_start_tag(data, ASN1_APPLICATION(LDAP_TAG_BindResponse));
+ asn1_read_enumerated(data, &r->response.resultcode);
+ asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->response.dn);
+ asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->response.errormessage);
+ if (asn1_peek_tag(data, ASN1_CONTEXT(3))) {
+ asn1_start_tag(data, ASN1_CONTEXT(3));
+ asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->response.referral);
+ asn1_end_tag(data);
+ } else {
+ r->response.referral = NULL;
+ }
+ if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(7))) {
+ DATA_BLOB tmp_blob = data_blob(NULL, 0);
+ asn1_read_ContextSimple(data, 7, &tmp_blob);
+ r->SASL.secblob = data_blob_talloc(msg->mem_ctx, tmp_blob.data, tmp_blob.length);
+ data_blob_free(&tmp_blob);
+ } else {
+ r->SASL.secblob = data_blob(NULL, 0);
+ }
+ asn1_end_tag(data);
break;
}
@@ -1460,8 +1444,28 @@ BOOL ldap_decode(ASN1_DATA *data, struct ldap_message *msg)
}
case ASN1_APPLICATION(LDAP_TAG_ModifyDNRequest): {
-/* struct ldap_ModifyDNRequest *r = &msg->r.ModifyDNRequest; */
+ struct ldap_ModifyDNRequest *r = &msg->r.ModifyDNRequest;
msg->type = LDAP_TAG_ModifyDNRequest;
+ asn1_start_tag(data,
+ ASN1_APPLICATION(LDAP_TAG_ModifyDNRequest));
+ asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->dn);
+ asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->newrdn);
+ asn1_read_BOOLEAN2(data, &r->deleteolddn);
+ r->newsuperior = NULL;
+ if (asn1_tag_remaining(data) > 0) {
+ int len;
+ char *newsup;
+ asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(0));
+ len = asn1_tag_remaining(data);
+ newsup = talloc(msg->mem_ctx, len+1);
+ if (newsup == NULL)
+ break;
+ asn1_read(data, newsup, len);
+ newsup[len] = '\0';
+ r->newsuperior = newsup;
+ asn1_end_tag(data);
+ }
+ asn1_end_tag(data);
break;
}
diff --git a/source4/libcli/util/asn1.c b/source4/libcli/util/asn1.c
index e7c38b2803..1f04e1fe46 100644
--- a/source4/libcli/util/asn1.c
+++ b/source4/libcli/util/asn1.c
@@ -166,6 +166,14 @@ BOOL asn1_write_GeneralString(ASN1_DATA *data, const char *s)
return !data->has_error;
}
+BOOL asn1_write_ContextSimple(ASN1_DATA *data, uint8_t num, DATA_BLOB *blob)
+{
+ asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(num));
+ asn1_write(data, blob->data, blob->length);
+ asn1_pop_tag(data);
+ return !data->has_error;
+}
+
/* write a BOOLEAN */
BOOL asn1_write_BOOLEAN(ASN1_DATA *data, BOOL v)
{
@@ -518,6 +526,22 @@ BOOL asn1_read_OctetString(ASN1_DATA *data, DATA_BLOB *blob)
return !data->has_error;
}
+BOOL asn1_read_ContextSimple(ASN1_DATA *data, uint8_t num, DATA_BLOB *blob)
+{
+ int len;
+ ZERO_STRUCTP(blob);
+ if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(num))) return False;
+ len = asn1_tag_remaining(data);
+ if (len < 0) {
+ data->has_error = True;
+ return False;
+ }
+ *blob = data_blob(NULL, len);
+ asn1_read(data, blob->data, len);
+ asn1_end_tag(data);
+ return !data->has_error;
+}
+
/* read an interger */
BOOL asn1_read_Integer(ASN1_DATA *data, int *i)
{