summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/libsmb/asn1.c44
-rw-r--r--source3/libsmb/clikrb5.c10
2 files changed, 42 insertions, 12 deletions
diff --git a/source3/libsmb/asn1.c b/source3/libsmb/asn1.c
index 5735f372ca..e4c2d3af80 100644
--- a/source3/libsmb/asn1.c
+++ b/source3/libsmb/asn1.c
@@ -21,17 +21,13 @@
#include "includes.h"
+/* free an asn1 structure */
void asn1_free(ASN1_DATA *data)
{
- free(data->data);
-}
-
-BOOL asn1_check_empty(ASN1_DATA *data)
-{
- if (data->nesting) return False;
- return True;
+ SAFE_FREE(data->data);
}
+/* write to the ASN1 buffer, advancing the buffer pointer */
BOOL asn1_write(ASN1_DATA *data, const void *p, int len)
{
if (data->length < data->ofs+len) {
@@ -44,11 +40,13 @@ BOOL asn1_write(ASN1_DATA *data, const void *p, int len)
return True;
}
+/* useful fn for writing a uint8 */
BOOL asn1_write_uint8(ASN1_DATA *data, uint8 v)
{
return asn1_write(data, &v, 1);
}
+/* push a tag onto the asn1 data buffer. Used for nested structures */
BOOL asn1_push_tag(ASN1_DATA *data, uint8 tag)
{
struct nesting *nesting;
@@ -64,6 +62,7 @@ BOOL asn1_push_tag(ASN1_DATA *data, uint8 tag)
return True;
}
+/* pop a tag */
BOOL asn1_pop_tag(ASN1_DATA *data)
{
struct nesting *nesting;
@@ -75,6 +74,9 @@ BOOL asn1_pop_tag(ASN1_DATA *data)
return False;
}
len = data->ofs - (nesting->start+1);
+ /* yes, this is ugly. We don't know in advance how many bytes the length
+ of a tag will take, so we assumed 1 byte. If we were wrong then we
+ need to correct our mistake */
if (len > 127) {
data->data[nesting->start] = 0x82;
asn1_write_uint8(data, 0);
@@ -91,7 +93,7 @@ BOOL asn1_pop_tag(ASN1_DATA *data)
return True;
}
-
+/* write an object ID to a ASN1 buffer */
BOOL asn1_write_OID(ASN1_DATA *data, const char *OID)
{
unsigned v, v2;
@@ -114,6 +116,7 @@ BOOL asn1_write_OID(ASN1_DATA *data, const char *OID)
return True;
}
+/* write an octet string */
BOOL asn1_write_OctetString(ASN1_DATA *data, const void *p, size_t length)
{
asn1_push_tag(data, ASN1_OCTET_STRING);
@@ -122,6 +125,7 @@ BOOL asn1_write_OctetString(ASN1_DATA *data, const void *p, size_t length)
return True;
}
+/* write a general string */
BOOL asn1_write_GeneralString(ASN1_DATA *data, const char *s)
{
asn1_push_tag(data, ASN1_GENERAL_STRING);
@@ -130,6 +134,7 @@ BOOL asn1_write_GeneralString(ASN1_DATA *data, const char *s)
return True;
}
+/* write a BOOLEAN */
BOOL asn1_write_BOOLEAN(ASN1_DATA *data, BOOL v)
{
asn1_write_uint8(data, ASN1_BOOLEAN);
@@ -137,3 +142,26 @@ BOOL asn1_write_BOOLEAN(ASN1_DATA *data, BOOL v)
return True;
}
+
+/* load a ASN1_DATA structure with a lump of data, ready to be parsed */
+BOOL asn1_load(ASN1_DATA *data, void *p, size_t length)
+{
+ ZERO_STRUCTP(data);
+ data->data = memdup(p, length);
+ if (!data->data) return False;
+ data->length = length;
+ return True;
+}
+
+/* read from a ASN1 buffer, advancing the buffer pointer */
+BOOL asn1_read(ASN1_DATA *data, void *p, int len)
+{
+ if (data->ofs + len > data->length) {
+ return False;
+ }
+ memcpy(p, data->data + data->ofs, len);
+ data->ofs += len;
+ return True;
+}
+
+
diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c
index cd64dc8444..0e049c14a1 100644
--- a/source3/libsmb/clikrb5.c
+++ b/source3/libsmb/clikrb5.c
@@ -27,6 +27,9 @@
#define OID_SPNEGO "1 3 6 1 5 5 2"
#define OID_KERBEROS5 "1 2 840 113554 1 2 2"
+/*
+ we can't use krb5_mk_req because w2k wants the service to be in a particular format
+*/
static krb5_error_code krb5_mk_req2(krb5_context context,
krb5_auth_context *auth_context,
const krb5_flags ap_req_options,
@@ -113,11 +116,12 @@ static DATA_BLOB krb5_get_ticket(char *service)
}
ret = data_blob(packet.data, packet.length);
- /* XXX need to free up a bunch of krb5 stuff here */
-
+ krb5_free_data_contents(context, &packet);
+ krb5_free_context(context);
return ret;
failed:
+ krb5_free_context(context);
return data_blob(NULL, 0);
}
@@ -162,7 +166,6 @@ ASN1_DATA spnego_gen_negTokenInit(uint8 guid[16],
asn1_pop_tag(&data);
- asn1_check_empty(&data);
return data;
}
@@ -199,7 +202,6 @@ static ASN1_DATA gen_negTokenTarg(const char *OIDs[], ASN1_DATA blob)
asn1_pop_tag(&data);
- asn1_check_empty(&data);
return data;
}