svn commit: samba r20258 - in branches/SAMBA_4_0/source:
auth/gensec libcli/util
metze at samba.org
metze at samba.org
Tue Dec 19 19:25:49 GMT 2006
Author: metze
Date: 2006-12-19 19:25:49 +0000 (Tue, 19 Dec 2006)
New Revision: 20258
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=20258
Log:
add functions to read and write asn1 encoded OID strings without leading tag
metze
Modified:
branches/SAMBA_4_0/source/auth/gensec/gensec.h
branches/SAMBA_4_0/source/libcli/util/asn1.c
Changeset:
Modified: branches/SAMBA_4_0/source/auth/gensec/gensec.h
===================================================================
--- branches/SAMBA_4_0/source/auth/gensec/gensec.h 2006-12-19 18:08:51 UTC (rev 20257)
+++ branches/SAMBA_4_0/source/auth/gensec/gensec.h 2006-12-19 19:25:49 UTC (rev 20258)
@@ -26,11 +26,11 @@
#include "core.h"
-#define GENSEC_OID_NTLMSSP "1 3 6 1 4 1 311 2 2 10"
-#define GENSEC_OID_SPNEGO "1 3 6 1 5 5 2"
-#define GENSEC_OID_KERBEROS5 "1 2 840 113554 1 2 2"
-#define GENSEC_OID_KERBEROS5_OLD "1 2 840 48018 1 2 2"
-#define GENSEC_OID_KERBEROS5_USER2USER "1 2 840 113554 1 2 2 3"
+#define GENSEC_OID_NTLMSSP "1.3.6.1.4.1.311.2.2.10"
+#define GENSEC_OID_SPNEGO "1.3.6.1.5.5.2"
+#define GENSEC_OID_KERBEROS5 "1.2.840.113554.1.2.2"
+#define GENSEC_OID_KERBEROS5_OLD "1.2.840.48018.1.2.2"
+#define GENSEC_OID_KERBEROS5_USER2USER "1.2.840.113554.1.2.2.3"
enum gensec_priority {
GENSEC_SPNEGO = 90,
Modified: branches/SAMBA_4_0/source/libcli/util/asn1.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/util/asn1.c 2006-12-19 18:08:51 UTC (rev 20257)
+++ branches/SAMBA_4_0/source/libcli/util/asn1.c 2006-12-19 19:25:49 UTC (rev 20258)
@@ -185,25 +185,37 @@
return asn1_pop_tag(data);
}
-/* write an object ID to a ASN1 buffer */
-BOOL asn1_write_OID(struct asn1_data *data, const char *OID)
+BOOL asn1_write_OID_String(struct asn1_data *data, const char *OID)
{
uint_t v, v2;
const char *p = (const char *)OID;
char *newp;
- if (!asn1_push_tag(data, ASN1_OID))
+ v = strtoul(p, &newp, 10);
+ if (newp[0] != '.') {
+ data->has_error = True;
return False;
- v = strtol(p, &newp, 10);
- p = newp;
- v2 = strtol(p, &newp, 10);
- p = newp;
+ }
+ p = newp + 1;
+ v2 = strtoul(p, &newp, 10);
+ if (newp[0] != '.') {
+ data->has_error = True;
+ return False;
+ }
+ p = newp + 1;
if (!asn1_write_uint8(data, 40*v + v2))
return False;
while (*p) {
- v = strtol(p, &newp, 10);
- p = newp;
+ v = strtoul(p, &newp, 10);
+ if (newp[0] == '.') {
+ p = newp + 1;
+ } else if (newp[0] == '\0') {
+ p = newp;
+ } else {
+ data->has_error = True;
+ return False;
+ }
if (v >= (1<<28)) asn1_write_uint8(data, 0x80 | ((v>>28)&0xff));
if (v >= (1<<21)) asn1_write_uint8(data, 0x80 | ((v>>21)&0xff));
if (v >= (1<<14)) asn1_write_uint8(data, 0x80 | ((v>>14)&0xff));
@@ -211,6 +223,15 @@
if (!asn1_write_uint8(data, v&0x7f))
return False;
}
+
+ return !data->has_error;
+}
+
+/* write an object ID to a ASN1 buffer */
+BOOL asn1_write_OID(struct asn1_data *data, const char *OID)
+{
+ if (!asn1_push_tag(data, ASN1_OID)) return False;
+ if (!asn1_write_OID_String(data, OID)) return False;
return asn1_pop_tag(data);
}
@@ -447,16 +468,17 @@
}
/* read an object ID from a ASN1 buffer */
-BOOL asn1_read_OID(struct asn1_data *data, const char **OID)
+BOOL asn1_read_OID_String(struct asn1_data *data, const char **OID)
{
uint8_t b;
char *tmp_oid = NULL;
- if (!asn1_start_tag(data, ASN1_OID)) return False;
- asn1_read_uint8(data, &b);
+ if (!asn1_read_uint8(data, &b)) return False;
tmp_oid = talloc_asprintf(NULL, "%u", b/40);
- tmp_oid = talloc_asprintf_append(tmp_oid, " %u", b%40);
+ if (!tmp_oid) goto nomem;
+ tmp_oid = talloc_asprintf_append(tmp_oid, ".%u", b%40);
+ if (!tmp_oid) goto nomem;
while (!data->has_error && asn1_tag_remaining(data) > 0) {
uint_t v = 0;
@@ -464,15 +486,34 @@
asn1_read_uint8(data, &b);
v = (v<<7) | (b&0x7f);
} while (!data->has_error && (b & 0x80));
- tmp_oid = talloc_asprintf_append(tmp_oid, " %u", v);
+ tmp_oid = talloc_asprintf_append(tmp_oid, ".%u", v);
+ if (!tmp_oid) goto nomem;
}
- asn1_end_tag(data);
+ if (!data->has_error) {
+ *OID = talloc_strdup(NULL, tmp_oid);
+ if (!*OID) goto nomem;
+ }
- *OID = talloc_strdup(NULL, tmp_oid);
talloc_free(tmp_oid);
+ return !data->has_error;
+nomem:
+ talloc_free(tmp_oid);
+ data->has_error = True;
+ return False;
+}
- return (*OID && !data->has_error);
+/* read an object ID from a ASN1 buffer */
+BOOL asn1_read_OID(struct asn1_data *data, const char **OID)
+{
+ if (!asn1_start_tag(data, ASN1_OID)) return False;
+ if (!asn1_read_OID_String(data, OID)) return False;
+ if (!asn1_end_tag(data)) {
+ talloc_free(discard_const(*OID));
+ *OID = NULL;
+ return False;
+ }
+ return True;
}
/* check that the next object ID is correct */
More information about the samba-cvs
mailing list