summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2008-10-22 19:23:49 +0200
committerGünther Deschner <gd@samba.org>2008-10-22 21:37:36 +0200
commitc0cf457c85a1fb89d72c2088c103a51af9341de4 (patch)
treee54cf0bd51946a8aec1ea2b718488726ae331abb
parent527d79747642cf83c89a8931e4fe86df1fec454b (diff)
downloadsamba-c0cf457c85a1fb89d72c2088c103a51af9341de4.tar.gz
samba-c0cf457c85a1fb89d72c2088c103a51af9341de4.tar.bz2
samba-c0cf457c85a1fb89d72c2088c103a51af9341de4.zip
s3-asn1: make all of s3 asn1 code do a proper asn1_init() first.
Guenther
-rw-r--r--source3/libads/cldap.c147
-rw-r--r--source3/libads/krb5_setpw.c59
-rw-r--r--source3/libsmb/clikrb5.c62
-rw-r--r--source3/libsmb/clispnego.c529
-rw-r--r--source3/libsmb/spnego.c54
-rw-r--r--source3/smbd/sesssetup.c29
-rw-r--r--source3/torture/t_asn1.c22
7 files changed, 494 insertions, 408 deletions
diff --git a/source3/libads/cldap.c b/source3/libads/cldap.c
index 7180464d47..8f9a8ff213 100644
--- a/source3/libads/cldap.c
+++ b/source3/libads/cldap.c
@@ -24,10 +24,10 @@
/*
do a cldap netlogon query
*/
-static int send_cldap_netlogon(int sock, const char *domain,
+static int send_cldap_netlogon(TALLOC_CTX *mem_ctx, int sock, const char *domain,
const char *hostname, unsigned ntversion)
{
- ASN1_DATA data;
+ ASN1_DATA *data;
char ntver[4];
#ifdef CLDAP_USER_QUERY
char aac[4];
@@ -36,69 +36,72 @@ static int send_cldap_netlogon(int sock, const char *domain,
#endif
SIVAL(ntver, 0, ntversion);
- memset(&data, 0, sizeof(data));
+ data = asn1_init(mem_ctx);
+ if (data == NULL) {
+ return -1;
+ }
- asn1_push_tag(&data,ASN1_SEQUENCE(0));
- asn1_write_Integer(&data, 4);
- asn1_push_tag(&data, ASN1_APPLICATION(3));
- asn1_write_OctetString(&data, NULL, 0);
- asn1_write_enumerated(&data, 0);
- asn1_write_enumerated(&data, 0);
- asn1_write_Integer(&data, 0);
- asn1_write_Integer(&data, 0);
- asn1_write_BOOLEAN(&data, False);
- asn1_push_tag(&data, ASN1_CONTEXT(0));
+ asn1_push_tag(data,ASN1_SEQUENCE(0));
+ asn1_write_Integer(data, 4);
+ asn1_push_tag(data, ASN1_APPLICATION(3));
+ asn1_write_OctetString(data, NULL, 0);
+ asn1_write_enumerated(data, 0);
+ asn1_write_enumerated(data, 0);
+ asn1_write_Integer(data, 0);
+ asn1_write_Integer(data, 0);
+ asn1_write_BOOLEAN(data, False);
+ asn1_push_tag(data, ASN1_CONTEXT(0));
if (domain) {
- asn1_push_tag(&data, ASN1_CONTEXT(3));
- asn1_write_OctetString(&data, "DnsDomain", 9);
- asn1_write_OctetString(&data, domain, strlen(domain));
- asn1_pop_tag(&data);
+ asn1_push_tag(data, ASN1_CONTEXT(3));
+ asn1_write_OctetString(data, "DnsDomain", 9);
+ asn1_write_OctetString(data, domain, strlen(domain));
+ asn1_pop_tag(data);
}
- asn1_push_tag(&data, ASN1_CONTEXT(3));
- asn1_write_OctetString(&data, "Host", 4);
- asn1_write_OctetString(&data, hostname, strlen(hostname));
- asn1_pop_tag(&data);
+ asn1_push_tag(data, ASN1_CONTEXT(3));
+ asn1_write_OctetString(data, "Host", 4);
+ asn1_write_OctetString(data, hostname, strlen(hostname));
+ asn1_pop_tag(data);
#ifdef CLDAP_USER_QUERY
- asn1_push_tag(&data, ASN1_CONTEXT(3));
- asn1_write_OctetString(&data, "User", 4);
- asn1_write_OctetString(&data, "SAMBA$", 6);
- asn1_pop_tag(&data);
-
- asn1_push_tag(&data, ASN1_CONTEXT(3));
- asn1_write_OctetString(&data, "AAC", 4);
- asn1_write_OctetString(&data, aac, 4);
- asn1_pop_tag(&data);
+ asn1_push_tag(data, ASN1_CONTEXT(3));
+ asn1_write_OctetString(data, "User", 4);
+ asn1_write_OctetString(data, "SAMBA$", 6);
+ asn1_pop_tag(data);
+
+ asn1_push_tag(data, ASN1_CONTEXT(3));
+ asn1_write_OctetString(data, "AAC", 4);
+ asn1_write_OctetString(data, aac, 4);
+ asn1_pop_tag(data);
#endif
- asn1_push_tag(&data, ASN1_CONTEXT(3));
- asn1_write_OctetString(&data, "NtVer", 5);
- asn1_write_OctetString(&data, ntver, 4);
- asn1_pop_tag(&data);
+ asn1_push_tag(data, ASN1_CONTEXT(3));
+ asn1_write_OctetString(data, "NtVer", 5);
+ asn1_write_OctetString(data, ntver, 4);
+ asn1_pop_tag(data);
- asn1_pop_tag(&data);
+ asn1_pop_tag(data);
- asn1_push_tag(&data,ASN1_SEQUENCE(0));
- asn1_write_OctetString(&data, "NetLogon", 8);
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
+ asn1_push_tag(data,ASN1_SEQUENCE(0));
+ asn1_write_OctetString(data, "NetLogon", 8);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
- if (data.has_error) {
- DEBUG(2,("Failed to build cldap netlogon at offset %d\n", (int)data.ofs));
- asn1_free(&data);
+ if (data->has_error) {
+ DEBUG(2,("Failed to build cldap netlogon at offset %d\n", (int)data->ofs));
+ asn1_free(data);
return -1;
}
- if (write(sock, data.data, data.length) != (ssize_t)data.length) {
+ if (write(sock, data->data, data->length) != (ssize_t)data->length) {
DEBUG(2,("failed to send cldap query (%s)\n", strerror(errno)));
- asn1_free(&data);
+ asn1_free(data);
return -1;
}
- asn1_free(&data);
+ asn1_free(data);
return 0;
}
@@ -123,7 +126,7 @@ static int recv_cldap_netlogon(TALLOC_CTX *mem_ctx,
struct netlogon_samlogon_response **reply)
{
int ret;
- ASN1_DATA data;
+ ASN1_DATA *data;
DATA_BLOB blob = data_blob_null;
DATA_BLOB os1 = data_blob_null;
DATA_BLOB os2 = data_blob_null;
@@ -160,28 +163,34 @@ static int recv_cldap_netlogon(TALLOC_CTX *mem_ctx,
}
blob.length = ret;
- asn1_load(&data, blob);
- asn1_start_tag(&data, ASN1_SEQUENCE(0));
- asn1_read_Integer(&data, &i1);
- asn1_start_tag(&data, ASN1_APPLICATION(4));
- asn1_read_OctetString(&data, NULL, &os1);
- asn1_start_tag(&data, ASN1_SEQUENCE(0));
- asn1_start_tag(&data, ASN1_SEQUENCE(0));
- asn1_read_OctetString(&data, NULL, &os2);
- asn1_start_tag(&data, ASN1_SET);
- asn1_read_OctetString(&data, NULL, &os3);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
-
- if (data.has_error) {
+ data = asn1_init(mem_ctx);
+ if (data == NULL) {
+ data_blob_free(&blob);
+ return -1;
+ }
+
+ asn1_load(data, blob);
+ asn1_start_tag(data, ASN1_SEQUENCE(0));
+ asn1_read_Integer(data, &i1);
+ asn1_start_tag(data, ASN1_APPLICATION(4));
+ asn1_read_OctetString(data, NULL, &os1);
+ asn1_start_tag(data, ASN1_SEQUENCE(0));
+ asn1_start_tag(data, ASN1_SEQUENCE(0));
+ asn1_read_OctetString(data, NULL, &os2);
+ asn1_start_tag(data, ASN1_SET);
+ asn1_read_OctetString(data, NULL, &os3);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
+
+ if (data->has_error) {
data_blob_free(&blob);
data_blob_free(&os1);
data_blob_free(&os2);
data_blob_free(&os3);
- asn1_free(&data);
+ asn1_free(data);
DEBUG(1,("Failed to parse cldap reply\n"));
return -1;
}
@@ -193,6 +202,7 @@ static int recv_cldap_netlogon(TALLOC_CTX *mem_ctx,
data_blob_free(&os2);
data_blob_free(&os3);
data_blob_free(&blob);
+ asn1_free(data);
return -1;
}
@@ -202,6 +212,7 @@ static int recv_cldap_netlogon(TALLOC_CTX *mem_ctx,
data_blob_free(&os2);
data_blob_free(&os3);
data_blob_free(&blob);
+ asn1_free(data);
TALLOC_FREE(r);
return -1;
}
@@ -212,8 +223,8 @@ static int recv_cldap_netlogon(TALLOC_CTX *mem_ctx,
data_blob_free(&os2);
data_blob_free(&os3);
data_blob_free(&blob);
-
- asn1_free(&data);
+
+ asn1_free(data);
if (reply) {
*reply = r;
@@ -244,7 +255,7 @@ bool ads_cldap_netlogon(TALLOC_CTX *mem_ctx,
return False;
}
- ret = send_cldap_netlogon(sock, realm, global_myname(), nt_version);
+ ret = send_cldap_netlogon(mem_ctx, sock, realm, global_myname(), nt_version);
if (ret != 0) {
close(sock);
return False;
diff --git a/source3/libads/krb5_setpw.c b/source3/libads/krb5_setpw.c
index 0ff9f2ba32..04ee6ee62a 100644
--- a/source3/libads/krb5_setpw.c
+++ b/source3/libads/krb5_setpw.c
@@ -65,7 +65,7 @@ static DATA_BLOB encode_krb5_setpw(const char *principal, const char *password)
char* c;
char* princ;
- ASN1_DATA req;
+ ASN1_DATA *req;
DATA_BLOB ret;
@@ -90,40 +90,43 @@ static DATA_BLOB encode_krb5_setpw(const char *principal, const char *password)
return data_blob_null;
}
- memset(&req, 0, sizeof(req));
-
- asn1_push_tag(&req, ASN1_SEQUENCE(0));
- asn1_push_tag(&req, ASN1_CONTEXT(0));
- asn1_write_OctetString(&req, password, strlen(password));
- asn1_pop_tag(&req);
+ req = asn1_init(talloc_tos());
+ if (req == NULL) {
+ return data_blob_null;
+ }
- asn1_push_tag(&req, ASN1_CONTEXT(1));
- asn1_push_tag(&req, ASN1_SEQUENCE(0));
+ asn1_push_tag(req, ASN1_SEQUENCE(0));
+ asn1_push_tag(req, ASN1_CONTEXT(0));
+ asn1_write_OctetString(req, password, strlen(password));
+ asn1_pop_tag(req);
- asn1_push_tag(&req, ASN1_CONTEXT(0));
- asn1_write_Integer(&req, 1);
- asn1_pop_tag(&req);
+ asn1_push_tag(req, ASN1_CONTEXT(1));
+ asn1_push_tag(req, ASN1_SEQUENCE(0));
- asn1_push_tag(&req, ASN1_CONTEXT(1));
- asn1_push_tag(&req, ASN1_SEQUENCE(0));
+ asn1_push_tag(req, ASN1_CONTEXT(0));
+ asn1_write_Integer(req, 1);
+ asn1_pop_tag(req);
+
+ asn1_push_tag(req, ASN1_CONTEXT(1));
+ asn1_push_tag(req, ASN1_SEQUENCE(0));
if (princ_part1) {
- asn1_write_GeneralString(&req, princ_part1);
+ asn1_write_GeneralString(req, princ_part1);
}
- asn1_write_GeneralString(&req, princ_part2);
- asn1_pop_tag(&req);
- asn1_pop_tag(&req);
- asn1_pop_tag(&req);
- asn1_pop_tag(&req);
-
- asn1_push_tag(&req, ASN1_CONTEXT(2));
- asn1_write_GeneralString(&req, realm);
- asn1_pop_tag(&req);
- asn1_pop_tag(&req);
-
- ret = data_blob(req.data, req.length);
- asn1_free(&req);
+ asn1_write_GeneralString(req, princ_part2);
+ asn1_pop_tag(req);
+ asn1_pop_tag(req);
+ asn1_pop_tag(req);
+ asn1_pop_tag(req);
+
+ asn1_push_tag(req, ASN1_CONTEXT(2));
+ asn1_write_GeneralString(req, realm);
+ asn1_pop_tag(req);
+ asn1_pop_tag(req);
+
+ ret = data_blob(req->data, req->length);
+ asn1_free(req);
free(princ);
diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c
index 5bcc678847..9f86b8b2f8 100644
--- a/source3/libsmb/clikrb5.c
+++ b/source3/libsmb/clikrb5.c
@@ -320,31 +320,36 @@ bool unwrap_edata_ntstatus(TALLOC_CTX *mem_ctx,
DATA_BLOB *edata_out)
{
DATA_BLOB edata_contents;
- ASN1_DATA data;
+ ASN1_DATA *data;
int edata_type;
if (!edata->length) {
return False;
}
- asn1_load(&data, *edata);
- asn1_start_tag(&data, ASN1_SEQUENCE(0));
- asn1_start_tag(&data, ASN1_CONTEXT(1));
- asn1_read_Integer(&data, &edata_type);
+ data = asn1_init(mem_ctx);
+ if (data == NULL) {
+ return false;
+ }
+
+ asn1_load(data, *edata);
+ asn1_start_tag(data, ASN1_SEQUENCE(0));
+ asn1_start_tag(data, ASN1_CONTEXT(1));
+ asn1_read_Integer(data, &edata_type);
if (edata_type != KRB5_PADATA_PW_SALT) {
DEBUG(0,("edata is not of required type %d but of type %d\n",
KRB5_PADATA_PW_SALT, edata_type));
- asn1_free(&data);
+ asn1_free(data);
return False;
}
- asn1_start_tag(&data, ASN1_CONTEXT(2));
- asn1_read_OctetString(&data, NULL, &edata_contents);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
- asn1_free(&data);
+ asn1_start_tag(data, ASN1_CONTEXT(2));
+ asn1_read_OctetString(data, NULL, &edata_contents);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
+ asn1_free(data);
*edata_out = data_blob_talloc(mem_ctx, edata_contents.data, edata_contents.length);
@@ -357,32 +362,37 @@ bool unwrap_edata_ntstatus(TALLOC_CTX *mem_ctx,
bool unwrap_pac(TALLOC_CTX *mem_ctx, DATA_BLOB *auth_data, DATA_BLOB *unwrapped_pac_data)
{
DATA_BLOB pac_contents;
- ASN1_DATA data;
+ ASN1_DATA *data;
int data_type;
if (!auth_data->length) {
return False;
}
- asn1_load(&data, *auth_data);
- asn1_start_tag(&data, ASN1_SEQUENCE(0));
- asn1_start_tag(&data, ASN1_SEQUENCE(0));
- asn1_start_tag(&data, ASN1_CONTEXT(0));
- asn1_read_Integer(&data, &data_type);
+ data = asn1_init(mem_ctx);
+ if (data == NULL) {
+ return false;
+ }
+
+ asn1_load(data, *auth_data);
+ asn1_start_tag(data, ASN1_SEQUENCE(0));
+ asn1_start_tag(data, ASN1_SEQUENCE(0));
+ asn1_start_tag(data, ASN1_CONTEXT(0));
+ asn1_read_Integer(data, &data_type);
if (data_type != KRB5_AUTHDATA_WIN2K_PAC ) {
DEBUG(10,("authorization data is not a Windows PAC (type: %d)\n", data_type));
- asn1_free(&data);
+ asn1_free(data);
return False;
}
- asn1_end_tag(&data);
- asn1_start_tag(&data, ASN1_CONTEXT(1));
- asn1_read_OctetString(&data, NULL, &pac_contents);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
- asn1_free(&data);
+ asn1_end_tag(data);
+ asn1_start_tag(data, ASN1_CONTEXT(1));
+ asn1_read_OctetString(data, NULL, &pac_contents);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
+ asn1_free(data);
*unwrapped_pac_data = data_blob_talloc(mem_ctx, pac_contents.data, pac_contents.length);
diff --git a/source3/libsmb/clispnego.c b/source3/libsmb/clispnego.c
index d45213cd9e..fd312a4c0a 100644
--- a/source3/libsmb/clispnego.c
+++ b/source3/libsmb/clispnego.c
@@ -30,45 +30,47 @@ DATA_BLOB spnego_gen_negTokenInit(char guid[16],
const char *principal)
{
int i;
- ASN1_DATA data;
+ ASN1_DATA *data;
DATA_BLOB ret;
- memset(&data, 0, sizeof(data));
+ data = asn1_init(talloc_tos());
+ if (data == NULL) {
+ return data_blob_null;
+ }
- asn1_write(&data, guid, 16);
- asn1_push_tag(&data,ASN1_APPLICATION(0));
- asn1_write_OID(&data,OID_SPNEGO);
- asn1_push_tag(&data,ASN1_CONTEXT(0));
- asn1_push_tag(&data,ASN1_SEQUENCE(0));
+ asn1_write(data, guid, 16);
+ asn1_push_tag(data,ASN1_APPLICATION(0));
+ asn1_write_OID(data,OID_SPNEGO);
+ asn1_push_tag(data,ASN1_CONTEXT(0));
+ asn1_push_tag(data,ASN1_SEQUENCE(0));
- asn1_push_tag(&data,ASN1_CONTEXT(0));
- asn1_push_tag(&data,ASN1_SEQUENCE(0));
+ asn1_push_tag(data,ASN1_CONTEXT(0));
+ asn1_push_tag(data,ASN1_SEQUENCE(0));
for (i=0; OIDs[i]; i++) {
- asn1_write_OID(&data,OIDs[i]);
+ asn1_write_OID(data,OIDs[i]);
}
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
- asn1_push_tag(&data, ASN1_CONTEXT(3));
- asn1_push_tag(&data, ASN1_SEQUENCE(0));
- asn1_push_tag(&data, ASN1_CONTEXT(0));
- asn1_write_GeneralString(&data,principal);
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
+ asn1_push_tag(data, ASN1_CONTEXT(3));
+ asn1_push_tag(data, ASN1_SEQUENCE(0));
+ asn1_push_tag(data, ASN1_CONTEXT(0));
+ asn1_write_GeneralString(data,principal);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
- asn1_pop_tag(&data);
+ asn1_pop_tag(data);
- if (data.has_error) {
- DEBUG(1,("Failed to build negTokenInit at offset %d\n", (int)data.ofs));
- asn1_free(&data);
+ if (data->has_error) {
+ DEBUG(1,("Failed to build negTokenInit at offset %d\n", (int)data->ofs));
}
- ret = data_blob(data.data, data.length);
- asn1_free(&data);
+ ret = data_blob(data->data, data->length);
+ asn1_free(data);
return ret;
}
@@ -82,38 +84,40 @@ DATA_BLOB spnego_gen_negTokenInit(char guid[16],
*/
DATA_BLOB gen_negTokenInit(const char *OID, DATA_BLOB blob)
{
- ASN1_DATA data;
+ ASN1_DATA *data;
DATA_BLOB ret;
- memset(&data, 0, sizeof(data));
+ data = asn1_init(talloc_tos());
+ if (data == NULL) {
+ return data_blob_null;
+ }
- asn1_push_tag(&data, ASN1_APPLICATION(0));
- asn1_write_OID(&data,OID_SPNEGO);
- asn1_push_tag(&data, ASN1_CONTEXT(0));
- asn1_push_tag(&data, ASN1_SEQUENCE(0));
+ asn1_push_tag(data, ASN1_APPLICATION(0));
+ asn1_write_OID(data,OID_SPNEGO);
+ asn1_push_tag(data, ASN1_CONTEXT(0));
+ asn1_push_tag(data, ASN1_SEQUENCE(0));
- asn1_push_tag(&data, ASN1_CONTEXT(0));
- asn1_push_tag(&data, ASN1_SEQUENCE(0));
- asn1_write_OID(&data, OID);
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
+ asn1_push_tag(data, ASN1_CONTEXT(0));
+ asn1_push_tag(data, ASN1_SEQUENCE(0));
+ asn1_write_OID(data, OID);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
- asn1_push_tag(&data, ASN1_CONTEXT(2));
- asn1_write_OctetString(&data,blob.data,blob.length);
- asn1_pop_tag(&data);
+ asn1_push_tag(data, ASN1_CONTEXT(2));
+ asn1_write_OctetString(data,blob.data,blob.length);
+ asn1_pop_tag(data);
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
- asn1_pop_tag(&data);
+ asn1_pop_tag(data);
- if (data.has_error) {
- DEBUG(1,("Failed to build negTokenInit at offset %d\n", (int)data.ofs));
- asn1_free(&data);
+ if (data->has_error) {
+ DEBUG(1,("Failed to build negTokenInit at offset %d\n", (int)data->ofs));
}
- ret = data_blob(data.data, data.length);
- asn1_free(&data);
+ ret = data_blob(data->data, data->length);
+ asn1_free(data);
return ret;
}
@@ -128,44 +132,50 @@ bool spnego_parse_negTokenInit(DATA_BLOB blob,
{
int i;
bool ret;
- ASN1_DATA data;
+ ASN1_DATA *data;
+
+ data = asn1_init(talloc_tos());
+ if (data == NULL) {
+ return false;
+ }
+
+ asn1_load(data, blob);
- asn1_load(&data, blob);
+ asn1_start_tag(data,ASN1_APPLICATION(0));
- asn1_start_tag(&data,ASN1_APPLICATION(0));
- asn1_check_OID(&data,OID_SPNEGO);
- asn1_start_tag(&data,ASN1_CONTEXT(0));
- asn1_start_tag(&data,ASN1_SEQUENCE(0));
+ asn1_check_OID(data,OID_SPNEGO);
+ asn1_start_tag(data,ASN1_CONTEXT(0));
+ asn1_start_tag(data,ASN1_SEQUENCE(0));
- asn1_start_tag(&data,ASN1_CONTEXT(0));
- asn1_start_tag(&data,ASN1_SEQUENCE(0));
- for (i=0; asn1_tag_remaining(&data) > 0 && i < ASN1_MAX_OIDS-1; i++) {
+ asn1_start_tag(data,ASN1_CONTEXT(0));
+ asn1_start_tag(data,ASN1_SEQUENCE(0));
+ for (i=0; asn1_tag_remaining(data) > 0 && i < ASN1_MAX_OIDS-1; i++) {
const char *oid_str = NULL;
- asn1_read_OID(&data,NULL,&oid_str);
+ asn1_read_OID(data,NULL,&oid_str);
OIDs[i] = oid_str;
}
OIDs[i] = NULL;
- asn1_end_tag(&data);
- asn1_end_tag(&data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
*principal = NULL;
- if (asn1_tag_remaining(&data) > 0) {
- asn1_start_tag(&data, ASN1_CONTEXT(3));
- asn1_start_tag(&data, ASN1_SEQUENCE(0));
- asn1_start_tag(&data, ASN1_CONTEXT(0));
- asn1_read_GeneralString(&data,NULL,principal);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
+ if (asn1_tag_remaining(data) > 0) {
+ asn1_start_tag(data, ASN1_CONTEXT(3));
+ asn1_start_tag(data, ASN1_SEQUENCE(0));
+ asn1_start_tag(data, ASN1_CONTEXT(0));
+ asn1_read_GeneralString(data,NULL,principal);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
}
- asn1_end_tag(&data);
- asn1_end_tag(&data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
- asn1_end_tag(&data);
+ asn1_end_tag(data);
- ret = !data.has_error;
- if (data.has_error) {
+ ret = !data->has_error;
+ if (data->has_error) {
int j;
TALLOC_FREE(*principal);
for(j = 0; j < i && j < ASN1_MAX_OIDS-1; j++) {
@@ -173,7 +183,7 @@ bool spnego_parse_negTokenInit(DATA_BLOB blob,
}
}
- asn1_free(&data);
+ asn1_free(data);
return ret;
}
@@ -183,40 +193,42 @@ bool spnego_parse_negTokenInit(DATA_BLOB blob,
DATA_BLOB gen_negTokenTarg(const char *OIDs[], DATA_BLOB blob)
{
int i;
- ASN1_DATA data;
+ ASN1_DATA *data;
DATA_BLOB ret;
- memset(&data, 0, sizeof(data));
+ data = asn1_init(talloc_tos());
+ if (data == NULL) {
+ return data_blob_null;
+ }
- asn1_push_tag(&data, ASN1_APPLICATION(0));
- asn1_write_OID(&data,OID_SPNEGO);
- asn1_push_tag(&data, ASN1_CONTEXT(0));
- asn1_push_tag(&data, ASN1_SEQUENCE(0));
+ asn1_push_tag(data, ASN1_APPLICATION(0));
+ asn1_write_OID(data,OID_SPNEGO);
+ asn1_push_tag(data, ASN1_CONTEXT(0));
+ asn1_push_tag(data, ASN1_SEQUENCE(0));
- asn1_push_tag(&data, ASN1_CONTEXT(0));
- asn1_push_tag(&data, ASN1_SEQUENCE(0));
+ asn1_push_tag(data, ASN1_CONTEXT(0));
+ asn1_push_tag(data, ASN1_SEQUENCE(0));
for (i=0; OIDs[i]; i++) {
- asn1_write_OID(&data,OIDs[i]);
+ asn1_write_OID(data,OIDs[i]);
}
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
- asn1_push_tag(&data, ASN1_CONTEXT(2));
- asn1_write_OctetString(&data,blob.data,blob.length);
- asn1_pop_tag(&data);
+ asn1_push_tag(data, ASN1_CONTEXT(2));
+ asn1_write_OctetString(data,blob.data,blob.length);
+ asn1_pop_tag(data);
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
- asn1_pop_tag(&data);
+ asn1_pop_tag(data);
- if (data.has_error) {
- DEBUG(1,("Failed to build negTokenTarg at offset %d\n", (int)data.ofs));
- asn1_free(&data);
+ if (data->has_error) {
+ DEBUG(1,("Failed to build negTokenTarg at offset %d\n", (int)data->ofs));
}
- ret = data_blob(data.data, data.length);
- asn1_free(&data);
+ ret = data_blob(data->data, data->length);
+ asn1_free(data);
return ret;
}
@@ -224,61 +236,66 @@ DATA_BLOB gen_negTokenTarg(const char *OIDs[], DATA_BLOB blob)
/*
parse a negTokenTarg packet giving a list of OIDs and a security blob
*/
-bool parse_negTokenTarg(DATA_BLOB blob, const char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *secblob)
+bool parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *secblob)
{
int i;
- ASN1_DATA data;
+ ASN1_DATA *data;
+
+ data = asn1_init(talloc_tos());
+ if (data == NULL) {
+ return false;
+ }
- asn1_load(&data, blob);
- asn1_start_tag(&data, ASN1_APPLICATION(0));
- asn1_check_OID(&data,OID_SPNEGO);
- asn1_start_tag(&data, ASN1_CONTEXT(0));
- asn1_start_tag(&data, ASN1_SEQUENCE(0));
+ asn1_load(data, blob);
+ asn1_start_tag(data, ASN1_APPLICATION(0));
+ asn1_check_OID(data,OID_SPNEGO);
+ asn1_start_tag(data, ASN1_CONTEXT(0));
+ asn1_start_tag(data, ASN1_SEQUENCE(0));
- asn1_start_tag(&data, ASN1_CONTEXT(0));
- asn1_start_tag(&data, ASN1_SEQUENCE(0));
- for (i=0; asn1_tag_remaining(&data) > 0 && i < ASN1_MAX_OIDS-1; i++) {
+ asn1_start_tag(data, ASN1_CONTEXT(0));
+ asn1_start_tag(data, ASN1_SEQUENCE(0));
+ for (i=0; asn1_tag_remaining(data) > 0 && i < ASN1_MAX_OIDS-1; i++) {
const char *oid_str = NULL;
- asn1_read_OID(&data,NULL,&oid_str);
+ asn1_read_OID(data,NULL,&oid_str);
OIDs[i] = oid_str;
}
OIDs[i] = NULL;
- asn1_end_tag(&data);
- asn1_end_tag(&data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
/* Skip any optional req_flags that are sent per RFC 4178 */
- if (asn1_peek_tag(&data, ASN1_CONTEXT(1))) {
+ if (asn1_peek_tag(data, ASN1_CONTEXT(1))) {
uint8 flags;
- asn1_start_tag(&data, ASN1_CONTEXT(1));
- asn1_start_tag(&data, ASN1_BITFIELD);
- while (asn1_tag_remaining(&data) > 0)
- asn1_read_uint8(&data, &flags);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
+ asn1_start_tag(data, ASN1_CONTEXT(1));
+ asn1_start_tag(data, ASN1_BITFIELD);
+ while (asn1_tag_remaining(data) > 0)
+ asn1_read_uint8(data, &flags);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
}
- asn1_start_tag(&data, ASN1_CONTEXT(2));
- asn1_read_OctetString(&data,NULL,secblob);
- asn1_end_tag(&data);
+ asn1_start_tag(data, ASN1_CONTEXT(2));
+ asn1_read_OctetString(data,NULL,secblob);
+ asn1_end_tag(data);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
- asn1_end_tag(&data);
+ asn1_end_tag(data);
- if (data.has_error) {
+ if (data->has_error) {
int j;
data_blob_free(secblob);
for(j = 0; j < i && j < ASN1_MAX_OIDS-1; j++) {
TALLOC_FREE(OIDs[j]);
}
- DEBUG(1,("Failed to parse negTokenTarg at offset %d\n", (int)data.ofs));
- asn1_free(&data);
+ DEBUG(1,("Failed to parse negTokenTarg at offset %d\n", (int)data->ofs));
+ asn1_free(data);
return False;
}
- asn1_free(&data);
+ asn1_free(data);
return True;
}
@@ -287,25 +304,27 @@ bool parse_negTokenTarg(DATA_BLOB blob, const char *OIDs[ASN1_MAX_OIDS], DATA_BL
*/
DATA_BLOB spnego_gen_krb5_wrap(const DATA_BLOB ticket, const uint8 tok_id[2])
{
- ASN1_DATA data;
+ ASN1_DATA *data;
DATA_BLOB ret;
- memset(&data, 0, sizeof(data));
+ data = asn1_init(talloc_tos());
+ if (data == NULL) {
+ return data_blob_null;
+ }
- asn1_push_tag(&data, ASN1_APPLICATION(0));
- asn1_write_OID(&data, OID_KERBEROS5);
+ asn1_push_tag(data, ASN1_APPLICATION(0));
+ asn1_write_OID(data, OID_KERBEROS5);
- asn1_write(&data, tok_id, 2);
- asn1_write(&data, ticket.data, ticket.length);
- asn1_pop_tag(&data);
+ asn1_write(data, tok_id, 2);
+ asn1_write(data, ticket.data, ticket.length);
+ asn1_pop_tag(data);
- if (data.has_error) {
- DEBUG(1,("Failed to build krb5 wrapper at offset %d\n", (int)data.ofs));
- asn1_free(&data);
+ if (data->has_error) {
+ DEBUG(1,("Failed to build krb5 wrapper at offset %d\n", (int)data->ofs));
}
- ret = data_blob(data.data, data.length);
- asn1_free(&data);
+ ret = data_blob(data->data, data->length);
+ asn1_free(data);
return ret;
}
@@ -316,33 +335,38 @@ DATA_BLOB spnego_gen_krb5_wrap(const DATA_BLOB ticket, const uint8 tok_id[2])
bool spnego_parse_krb5_wrap(DATA_BLOB blob, DATA_BLOB *ticket, uint8 tok_id[2])
{
bool ret;
- ASN1_DATA data;
+ ASN1_DATA *data;
int data_remaining;
- asn1_load(&data, blob);
- asn1_start_tag(&data, ASN1_APPLICATION(0));
- asn1_check_OID(&data, OID_KERBEROS5);
+ data = asn1_init(talloc_tos());
+ if (data == NULL) {
+ return false;
+ }
+
+ asn1_load(data, blob);
+ asn1_start_tag(data, ASN1_APPLICATION(0));
+ asn1_check_OID(data, OID_KERBEROS5);
- data_remaining = asn1_tag_remaining(&data);
+ data_remaining = asn1_tag_remaining(data);
if (data_remaining < 3) {
- data.has_error = True;
+ data->has_error = True;
} else {
- asn1_read(&data, tok_id, 2);
+ asn1_read(data, tok_id, 2);
data_remaining -= 2;
*ticket = data_blob(NULL, data_remaining);
- asn1_read(&data, ticket->data, ticket->length);
+ asn1_read(data, ticket->data, ticket->length);
}
- asn1_end_tag(&data);
+ asn1_end_tag(data);
- ret = !data.has_error;
+ ret = !data->has_error;
- if (data.has_error) {
+ if (data->has_error) {
data_blob_free(ticket);
}
- asn1_free(&data);
+ asn1_free(data);
return ret;
}
@@ -389,45 +413,50 @@ bool spnego_parse_challenge(const DATA_BLOB blob,
DATA_BLOB *chal1, DATA_BLOB *chal2)
{
bool ret;
- ASN1_DATA data;
+ ASN1_DATA *data;
ZERO_STRUCTP(chal1);
ZERO_STRUCTP(chal2);
- asn1_load(&data, blob);
- asn1_start_tag(&data,ASN1_CONTEXT(1));
- asn1_start_tag(&data,ASN1_SEQUENCE(0));
+ data = asn1_init(talloc_tos());
+ if (data == NULL) {
+ return false;
+ }
+
+ asn1_load(data, blob);
+ asn1_start_tag(data,ASN1_CONTEXT(1));
+ asn1_start_tag(data,ASN1_SEQUENCE(0));
- asn1_start_tag(&data,ASN1_CONTEXT(0));
- asn1_check_enumerated(&data,1);
- asn1_end_tag(&data);
+ asn1_start_tag(data,ASN1_CONTEXT(0));
+ asn1_check_enumerated(data,1);
+ asn1_end_tag(data);
- asn1_start_tag(&data,ASN1_CONTEXT(1));
- asn1_check_OID(&data, OID_NTLMSSP);
- asn1_end_tag(&data);
+ asn1_start_tag(data,ASN1_CONTEXT(1));
+ asn1_check_OID(data, OID_NTLMSSP);
+ asn1_end_tag(data);
- asn1_start_tag(&data,ASN1_CONTEXT(2));
- asn1_read_OctetString(&data, NULL, chal1);
- asn1_end_tag(&data);
+ asn1_start_tag(data,ASN1_CONTEXT(2));
+ asn1_read_OctetString(data, NULL, chal1);
+ asn1_end_tag(data);
/* the second challenge is optional (XP doesn't send it) */
- if (asn1_tag_remaining(&data)) {
- asn1_start_tag(&data,ASN1_CONTEXT(3));
- asn1_read_OctetString(&data, NULL, chal2);
- asn1_end_tag(&data);
+ if (asn1_tag_remaining(data)) {
+ asn1_start_tag(data,ASN1_CONTEXT(3));
+ asn1_read_OctetString(data, NULL, chal2);
+ asn1_end_tag(data);
}
- asn1_end_tag(&data);
- asn1_end_tag(&data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
- ret = !data.has_error;
+ ret = !data->has_error;
- if (data.has_error) {
+ if (data->has_error) {
data_blob_free(chal1);
data_blob_free(chal2);
}
- asn1_free(&data);
+ asn1_free(data);
return ret;
}
@@ -437,22 +466,25 @@ bool spnego_parse_challenge(const DATA_BLOB blob,
*/
DATA_BLOB spnego_gen_auth(DATA_BLOB blob)
{
- ASN1_DATA data;
+ ASN1_DATA *data;
DATA_BLOB ret;
- memset(&data, 0, sizeof(data));
+ data = asn1_init(talloc_tos());
+ if (data == NULL) {
+ return data_blob_null;
+ }
- asn1_push_tag(&data, ASN1_CONTEXT(1));
- asn1_push_tag(&data, ASN1_SEQUENCE(0));
- asn1_push_tag(&data, ASN1_CONTEXT(2));
- asn1_write_OctetString(&data,blob.data,blob.length);
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
+ asn1_push_tag(data, ASN1_CONTEXT(1));
+ asn1_push_tag(data, ASN1_SEQUENCE(0));
+ asn1_push_tag(data, ASN1_CONTEXT(2));
+ asn1_write_OctetString(data,blob.data,blob.length);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
- ret = data_blob(data.data, data.length);
+ ret = data_blob(data->data, data->length);
- asn1_free(&data);
+ asn1_free(data);
return ret;
}
@@ -462,25 +494,30 @@ DATA_BLOB spnego_gen_auth(DATA_BLOB blob)
*/
bool spnego_parse_auth(DATA_BLOB blob, DATA_BLOB *auth)
{
- ASN1_DATA data;
-
- asn1_load(&data, blob);
- asn1_start_tag(&data, ASN1_CONTEXT(1));
- asn1_start_tag(&data, ASN1_SEQUENCE(0));
- asn1_start_tag(&data, ASN1_CONTEXT(2));
- asn1_read_OctetString(&data, NULL, auth);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
- asn1_end_tag(&data);
-
- if (data.has_error) {
- DEBUG(3,("spnego_parse_auth failed at %d\n", (int)data.ofs));
+ ASN1_DATA *data;
+
+ data = asn1_init(talloc_tos());
+ if (data == NULL) {
+ return false;
+ }
+
+ asn1_load(data, blob);
+ asn1_start_tag(data, ASN1_CONTEXT(1));
+ asn1_start_tag(data, ASN1_SEQUENCE(0));
+ asn1_start_tag(data, ASN1_CONTEXT(2));
+ asn1_read_OctetString(data, NULL, auth);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
+
+ if (data->has_error) {
+ DEBUG(3,("spnego_parse_auth failed at %d\n", (int)data->ofs));
data_blob_free(auth);
- asn1_free(&data);
+ asn1_free(data);
return False;
}
- asn1_free(&data);
+ asn1_free(data);
return True;
}
@@ -490,7 +527,7 @@ bool spnego_parse_auth(DATA_BLOB blob, DATA_BLOB *auth)
DATA_BLOB spnego_gen_auth_response(DATA_BLOB *reply, NTSTATUS nt_status,
const char *mechOID)
{
- ASN1_DATA data;
+ ASN1_DATA *data;
DATA_BLOB ret;
uint8 negResult;
@@ -502,31 +539,34 @@ DATA_BLOB spnego_gen_auth_response(DATA_BLOB *reply, NTSTATUS nt_status,
negResult = SPNEGO_NEG_RESULT_REJECT;
}
- ZERO_STRUCT(data);
+ data = asn1_init(talloc_tos());
+ if (data == NULL) {
+ return data_blob_null;
+ }
- asn1_push_tag(&data, ASN1_CONTEXT(1));
- asn1_push_tag(&data, ASN1_SEQUENCE(0));
- asn1_push_tag(&data, ASN1_CONTEXT(0));
- asn1_write_enumerated(&data, negResult);
- asn1_pop_tag(&data);
+ asn1_push_tag(data, ASN1_CONTEXT(1));
+ asn1_push_tag(data, ASN1_SEQUENCE(0));
+ asn1_push_tag(data, ASN1_CONTEXT(0));
+ asn1_write_enumerated(data, negResult);
+ asn1_pop_tag(data);
if (mechOID) {
- asn1_push_tag(&data,ASN1_CONTEXT(1));
- asn1_write_OID(&data, mechOID);
- asn1_pop_tag(&data);
+ asn1_push_tag(data,ASN1_CONTEXT(1));
+ asn1_write_OID(data, mechOID);
+ asn1_pop_tag(data);
}
if (reply && reply->data != NULL) {
- asn1_push_tag(&data,ASN1_CONTEXT(2));
- asn1_write_OctetString(&data, reply->data, reply->length);
- asn1_pop_tag(&data);
+ asn1_push_tag(data,ASN1_CONTEXT(2));
+ asn1_write_OctetString(data, reply->data, reply->length);
+ asn1_pop_tag(data);
}
- asn1_pop_tag(&data);
- asn1_pop_tag(&data);
+ asn1_pop_tag(data);
+ asn1_pop_tag(data);
- ret = data_blob(data.data, data.length);
- asn1_free(&data);
+ ret = data_blob(data->data, data->length);
+ asn1_free(data);
return ret;
}
@@ -537,7 +577,7 @@ bool spnego_parse_auth_response(DATA_BLOB blob, NTSTATUS nt_status,
const char *mechOID,
DATA_BLOB *auth)
{
- ASN1_DATA data;
+ ASN1_DATA *data;
uint8 negResult;
if (NT_STATUS_IS_OK(nt_status)) {
@@ -548,53 +588,58 @@ bool spnego_parse_auth_response(DATA_BLOB blob, NTSTATUS nt_status,
negResult = SPNEGO_NEG_RESULT_REJECT;
}
- asn1_load(&data, blob);
- asn1_start_tag(&data, ASN1_CONTEXT(1));
- asn1_start_tag(&data, ASN1_SEQUENCE(0));
- asn1_start_tag(&data, ASN1_CONTEXT(0));
- asn1_check_enumerated(&data, negResult);
- asn1_end_tag(&data);
+ data = asn1_init(talloc_tos());
+ if (data == NULL) {
+ return false;
+ }
+
+ asn1_load(data, blob);
+ asn1_start_tag(data, ASN1_CONTEXT(1));
+ asn1_start_tag(data, ASN1_SEQUENCE(0));
+ asn1_start_tag(data, ASN1_CONTEXT(0));
+ asn1_check_enumerated(data, negResult);
+ asn1_end_tag(data);
*auth = data_blob_null;
- if (asn1_tag_remaining(&data)) {
- asn1_start_tag(&data,ASN1_CONTEXT(1));
- asn1_check_OID(&data, mechOID);
- asn1_end_tag(&data);
+ if (asn1_tag_remaining(data)) {
+ asn1_start_tag(data,ASN1_CONTEXT(1));
+ asn1_check_OID(data, mechOID);
+ asn1_end_tag(data);
- if (asn1_tag_remaining(&data)) {
- asn1_start_tag(&data,ASN1_CONTEXT(2));
- asn1_read_OctetString(&data, NULL, auth);
- asn1_end_tag(&data);
+ if (asn1_tag_remaining(data)) {
+ asn1_start_tag(data,ASN1_CONTEXT(2));
+ asn1_read_OctetString(data, NULL, auth);
+ asn1_end_tag(data);
}
} else if (negResult == SPNEGO_NEG_RESULT_INCOMPLETE) {
- data.has_error = 1;
+ data->has_error = 1;
}
/* Binding against Win2K DC returns a duplicate of the responseToken in
* the optional mechListMIC field. This is a bug in Win2K. We ignore
* this field if it exists. Win2K8 may return a proper mechListMIC at
* which point we need to implement the integrity checking. */
- if (asn1_tag_remaining(&data)) {
+ if (asn1_tag_remaining(data)) {
DATA_BLOB mechList = data_blob_null;
- asn1_start_tag(&data, ASN1_CONTEXT(3));
- asn1_read_OctetString(&data, NULL, &mechList);
- asn1_end_tag(&data);
+ asn1_start_tag(data, ASN1_CONTEXT(3));
+ asn1_read_OctetString(data, NULL, &mechList);
+ asn1_end_tag(data);
data_blob_free(&mechList);
DEBUG(5,("spnego_parse_auth_response received mechListMIC, "
"ignoring.\n"));
}
- asn1_end_tag(&data);
- asn1_end_tag(&data);
+ asn1_end_tag(data);
+ asn1_end_tag(data);
- if (data.has_error) {
- DEBUG(3,("spnego_parse_auth_response failed at %d\n", (int)data.ofs));
- asn1_free(&data);
+ if (data->has_error) {
+ DEBUG(3,("spnego_parse_auth_response failed at %d\n", (int)data->ofs));
+ asn1_free(data);
data_blob_free(auth);
return False;
}
- asn1_free(&data);
+ asn1_free(data);
return True;
}
diff --git a/source3/libsmb/spnego.c b/source3/libsmb/spnego.c
index 70fd441c9e..b2197eb71b 100644
--- a/source3/libsmb/spnego.c
+++ b/source3/libsmb/spnego.c
@@ -249,24 +249,29 @@ static bool write_negTokenTarg(ASN1_DATA *asn1, negTokenTarg_t *token)
ssize_t read_spnego_data(DATA_BLOB data, SPNEGO_DATA *token)
{
- ASN1_DATA asn1;
+ ASN1_DATA *asn1;
ssize_t ret = -1;
ZERO_STRUCTP(token);
- ZERO_STRUCT(asn1);
- asn1_load(&asn1, data);
- switch (asn1.data[asn1.ofs]) {
+ asn1 = asn1_init(talloc_tos());
+ if (asn1 == NULL) {
+ return -1;
+ }
+
+ asn1_load(asn1, data);
+
+ switch (asn1->data[asn1->ofs]) {
case ASN1_APPLICATION(0):
- asn1_start_tag(&asn1, ASN1_APPLICATION(0));
- asn1_check_OID(&asn1, OID_SPNEGO);
- if (read_negTokenInit(&asn1, &token->negTokenInit)) {
+ asn1_start_tag(asn1, ASN1_APPLICATION(0));
+ asn1_check_OID(asn1, OID_SPNEGO);
+ if (read_negTokenInit(asn1, &token->negTokenInit)) {
token->type = SPNEGO_NEG_TOKEN_INIT;
}
- asn1_end_tag(&asn1);
+ asn1_end_tag(asn1);
break;
case ASN1_CONTEXT(1):
- if (read_negTokenTarg(&asn1, &token->negTokenTarg)) {
+ if (read_negTokenTarg(asn1, &token->negTokenTarg)) {
token->type = SPNEGO_NEG_TOKEN_TARG;
}
break;
@@ -274,39 +279,42 @@ ssize_t read_spnego_data(DATA_BLOB data, SPNEGO_DATA *token)
break;
}
- if (!asn1.has_error) ret = asn1.ofs;
- asn1_free(&asn1);
+ if (!asn1->has_error) ret = asn1->ofs;
+ asn1_free(asn1);
return ret;
}
ssize_t write_spnego_data(DATA_BLOB *blob, SPNEGO_DATA *spnego)
{
- ASN1_DATA asn1;
+ ASN1_DATA *asn1;
ssize_t ret = -1;
- ZERO_STRUCT(asn1);
+ asn1 = asn1_init(talloc_tos());
+ if (asn1 == NULL) {
+ return -1;
+ }
switch (spnego->type) {
case SPNEGO_NEG_TOKEN_INIT:
- asn1_push_tag(&asn1, ASN1_APPLICATION(0));
- asn1_write_OID(&asn1, OID_SPNEGO);
- write_negTokenInit(&asn1, &spnego->negTokenInit);
- asn1_pop_tag(&asn1);
+ asn1_push_tag(asn1, ASN1_APPLICATION(0));
+ asn1_write_OID(asn1, OID_SPNEGO);
+ write_negTokenInit(asn1, &spnego->negTokenInit);
+ asn1_pop_tag(asn1);
break;
case SPNEGO_NEG_TOKEN_TARG:
- write_negTokenTarg(&asn1, &spnego->negTokenTarg);
+ write_negTokenTarg(asn1, &spnego->negTokenTarg);
break;
default:
- asn1.has_error = True;
+ asn1->has_error = True;
break;
}
- if (!asn1.has_error) {
- *blob = data_blob(asn1.data, asn1.length);
- ret = asn1.ofs;
+ if (!asn1->has_error) {
+ *blob = data_blob(asn1->data, asn1->length);
+ ret = asn1->ofs;
}
- asn1_free(&asn1);
+ asn1_free(asn1);
return ret;
}
diff --git a/source3/smbd/sesssetup.c b/source3/smbd/sesssetup.c
index c0a4696754..a482b3398a 100644
--- a/source3/smbd/sesssetup.c
+++ b/source3/smbd/sesssetup.c
@@ -998,7 +998,7 @@ static NTSTATUS check_spnego_blob_complete(uint16 smbpid, uint16 vuid,
DATA_BLOB *pblob)
{
struct pending_auth_data *pad = NULL;
- ASN1_DATA data;
+ ASN1_DATA *data;
size_t needed_len = 0;
pad = get_pending_auth_data(smbpid);
@@ -1085,34 +1085,39 @@ static NTSTATUS check_spnego_blob_complete(uint16 smbpid, uint16 vuid,
* the data given in this blob is enough.
*/
- asn1_load(&data, *pblob);
- asn1_start_tag(&data, pblob->data[0]);
- if (data.has_error || data.nesting == NULL) {
- asn1_free(&data);
+ data = asn1_init(NULL);
+ if (data == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ asn1_load(data, *pblob);
+ asn1_start_tag(data, pblob->data[0]);
+ if (data->has_error || data->nesting == NULL) {
+ asn1_free(data);
/* Let caller catch. */
return NT_STATUS_OK;
}
/* Integer wrap paranoia.... */
- if (data.nesting->taglen + data.nesting->start < data.nesting->taglen ||
- data.nesting->taglen + data.nesting->start < data.nesting->start) {
+ if (data->nesting->taglen + data->nesting->start < data->nesting->taglen ||
+ data->nesting->taglen + data->nesting->start < data->nesting->start) {
DEBUG(2,("check_spnego_blob_complete: integer wrap "
"data.nesting->taglen = %u, "
"data.nesting->start = %u\n",
- (unsigned int)data.nesting->taglen,
- (unsigned int)data.nesting->start ));
+ (unsigned int)data->nesting->taglen,
+ (unsigned int)data->nesting->start ));
- asn1_free(&data);
+ asn1_free(data);
return NT_STATUS_INVALID_PARAMETER;
}
/* Total length of the needed asn1 is the tag length
* plus the current offset. */
- needed_len = data.nesting->taglen + data.nesting->start;
- asn1_free(&data);
+ needed_len = data->nesting->taglen + data->nesting->start;
+ asn1_free(data);
DEBUG(10,("check_spnego_blob_complete: needed_len = %u, "
"pblob->length = %u\n",
diff --git a/source3/torture/t_asn1.c b/source3/torture/t_asn1.c
index 5862742bc1..0ccd97b6d5 100644
--- a/source3/torture/t_asn1.c
+++ b/source3/torture/t_asn1.c
@@ -31,22 +31,26 @@ int main(void)
bool ok = True;
for (i=0; tests[i].data != NULL; i++) {
- ASN1_DATA data;
+ ASN1_DATA *data;
DATA_BLOB blob;
- ZERO_STRUCT(data);
- asn1_write_Integer(&data, values[i]);
+ data = asn1_init(talloc_tos());
+ if (!data) {
+ return -1;
+ }
+
+ asn1_write_Integer(data, values[i]);
- if ((data.length != tests[i].length) ||
- (memcmp(data.data, tests[i].data, data.length) != 0)) {
+ if ((data->length != tests[i].length) ||
+ (memcmp(data>data, tests[i].data, data->length) != 0)) {
printf("Test for %d failed\n", values[i]);
ok = False;
}
- blob.data = data.data;
- blob.length = data.length;
- asn1_load(&data, blob);
- if (!asn1_read_Integer(&data, &val)) {
+ blob.data = data->data;
+ blob.length = data->length;
+ asn1_load(data, blob);
+ if (!asn1_read_Integer(data, &val)) {
printf("Could not read our own Integer for %d\n",
values[i]);
ok = False;