summaryrefslogtreecommitdiff
path: root/source4/heimdal/lib/asn1
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2010-01-12 18:16:45 +1100
committerAndrew Bartlett <abartlet@samba.org>2010-03-27 11:51:27 +1100
commit89eaef025376339ef25d07cdc4748920fceaa968 (patch)
treef514f4632c9d54a372a7f1f0ca845a0c3a488fbf /source4/heimdal/lib/asn1
parentfac8ca52ade6e490eea3cf3d0fc98287da321c13 (diff)
downloadsamba-89eaef025376339ef25d07cdc4748920fceaa968.tar.gz
samba-89eaef025376339ef25d07cdc4748920fceaa968.tar.bz2
samba-89eaef025376339ef25d07cdc4748920fceaa968.zip
s4:heimdal: import lorikeet-heimdal-201001120029 (commit a5e675fed7c5db8a7370b77ed0bfa724196aa84d)
Diffstat (limited to 'source4/heimdal/lib/asn1')
-rw-r--r--source4/heimdal/lib/asn1/asn1-common.h1
-rw-r--r--source4/heimdal/lib/asn1/asn1_err.et2
-rw-r--r--source4/heimdal/lib/asn1/asn1parse.y15
-rw-r--r--source4/heimdal/lib/asn1/cms.asn12
-rw-r--r--source4/heimdal/lib/asn1/der.h2
-rw-r--r--source4/heimdal/lib/asn1/der_copy.c30
-rw-r--r--source4/heimdal/lib/asn1/der_free.c27
-rw-r--r--source4/heimdal/lib/asn1/der_get.c34
-rw-r--r--source4/heimdal/lib/asn1/der_length.c16
-rw-r--r--source4/heimdal/lib/asn1/der_locl.h2
-rw-r--r--source4/heimdal/lib/asn1/digest.asn115
-rw-r--r--source4/heimdal/lib/asn1/extra.c42
-rw-r--r--source4/heimdal/lib/asn1/gen.c267
-rw-r--r--source4/heimdal/lib/asn1/gen_copy.c4
-rw-r--r--source4/heimdal/lib/asn1/gen_decode.c36
-rw-r--r--source4/heimdal/lib/asn1/gen_encode.c5
-rw-r--r--source4/heimdal/lib/asn1/gen_free.c22
-rw-r--r--source4/heimdal/lib/asn1/gen_glue.c34
-rw-r--r--source4/heimdal/lib/asn1/gen_length.c5
-rw-r--r--source4/heimdal/lib/asn1/gen_locl.h11
-rw-r--r--source4/heimdal/lib/asn1/krb5.asn176
-rw-r--r--source4/heimdal/lib/asn1/main.c2
-rw-r--r--source4/heimdal/lib/asn1/symbol.c4
-rw-r--r--source4/heimdal/lib/asn1/test.asn142
24 files changed, 531 insertions, 165 deletions
diff --git a/source4/heimdal/lib/asn1/asn1-common.h b/source4/heimdal/lib/asn1/asn1-common.h
index 4c6af8b45e..8ab97761db 100644
--- a/source4/heimdal/lib/asn1/asn1-common.h
+++ b/source4/heimdal/lib/asn1/asn1-common.h
@@ -2,6 +2,7 @@
#include <stddef.h>
#include <time.h>
+#include <krb5-types.h>
#ifndef __asn1_common_definitions__
#define __asn1_common_definitions__
diff --git a/source4/heimdal/lib/asn1/asn1_err.et b/source4/heimdal/lib/asn1/asn1_err.et
index f1a653b1f9..ac7a9ebaa5 100644
--- a/source4/heimdal/lib/asn1/asn1_err.et
+++ b/source4/heimdal/lib/asn1/asn1_err.et
@@ -24,4 +24,6 @@ error_code MAX_CONSTRAINT, "ASN.1 too many elements"
error_code EXACT_CONSTRAINT, "ASN.1 wrong number of elements"
error_code INDEF_OVERRUN, "ASN.1 BER indefinte encoding overrun"
error_code INDEF_UNDERRUN, "ASN.1 BER indefinte encoding underun"
+error_code GOT_BER, "ASN.1 got BER encoded when expected DER"
+error_code INDEF_EXTRA_DATA, "ASN.1 EoC tag contained data"
end
diff --git a/source4/heimdal/lib/asn1/asn1parse.y b/source4/heimdal/lib/asn1/asn1parse.y
index 3835744bbd..13b86b17c1 100644
--- a/source4/heimdal/lib/asn1/asn1parse.y
+++ b/source4/heimdal/lib/asn1/asn1parse.y
@@ -3,6 +3,8 @@
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
+ * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -250,7 +252,7 @@ ExtensionDefault: kw_EXTENSIBILITY kw_IMPLIED
| /* empty */
;
-ModuleBody : /* Exports */ Imports AssignmentList
+ModuleBody : Exports Imports AssignmentList
| /* empty */
;
@@ -272,11 +274,22 @@ SymbolsFromModule: referencenames kw_FROM IDENTIFIER objid_opt
for(sl = $1; sl != NULL; sl = sl->next) {
Symbol *s = addsym(sl->string);
s->stype = Stype;
+ gen_template_import(s);
}
add_import($3);
}
;
+Exports : kw_EXPORTS referencenames ';'
+ {
+ struct string_list *sl;
+ for(sl = $2; sl != NULL; sl = sl->next)
+ add_export(sl->string);
+ }
+ | kw_EXPORTS kw_ALL
+ | /* empty */
+ ;
+
AssignmentList : Assignment
| Assignment AssignmentList
;
diff --git a/source4/heimdal/lib/asn1/cms.asn1 b/source4/heimdal/lib/asn1/cms.asn1
index 1c13d5f387..ccbe683838 100644
--- a/source4/heimdal/lib/asn1/cms.asn1
+++ b/source4/heimdal/lib/asn1/cms.asn1
@@ -4,7 +4,7 @@
CMS DEFINITIONS ::= BEGIN
IMPORTS CertificateSerialNumber, AlgorithmIdentifier, Name,
- Attribute, Certificate, Name, SubjectKeyIdentifier FROM rfc2459
+ Attribute, Certificate, SubjectKeyIdentifier FROM rfc2459
heim_any, heim_any_set FROM heim;
id-pkcs7 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
diff --git a/source4/heimdal/lib/asn1/der.h b/source4/heimdal/lib/asn1/der.h
index 5b24b917d8..f20cdb83ca 100644
--- a/source4/heimdal/lib/asn1/der.h
+++ b/source4/heimdal/lib/asn1/der.h
@@ -94,6 +94,8 @@ typedef struct heim_ber_time_t {
int bt_zone;
} heim_ber_time_t;
+struct asn1_template;
+
#include <der-protos.h>
int _heim_fix_dce(size_t reallen, size_t *len);
diff --git a/source4/heimdal/lib/asn1/der_copy.c b/source4/heimdal/lib/asn1/der_copy.c
index 51a2a03300..a80c851f96 100644
--- a/source4/heimdal/lib/asn1/der_copy.c
+++ b/source4/heimdal/lib/asn1/der_copy.c
@@ -3,6 +3,8 @@
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
+ * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -46,6 +48,34 @@ der_copy_general_string (const heim_general_string *from,
}
int
+der_copy_integer (const int *from, int *to)
+{
+ *to = *from;
+ return 0;
+}
+
+int
+der_copy_unsigned (const unsigned *from, unsigned *to)
+{
+ *to = *from;
+ return 0;
+}
+
+int
+der_copy_generalized_time (const time_t *from, time_t *to)
+{
+ *to = *from;
+ return 0;
+}
+
+int
+der_copy_utctime (const time_t *from, time_t *to)
+{
+ *to = *from;
+ return 0;
+}
+
+int
der_copy_utf8string (const heim_utf8_string *from, heim_utf8_string *to)
{
return der_copy_general_string(from, to);
diff --git a/source4/heimdal/lib/asn1/der_free.c b/source4/heimdal/lib/asn1/der_free.c
index 743bb6c466..a16ddaed1c 100644
--- a/source4/heimdal/lib/asn1/der_free.c
+++ b/source4/heimdal/lib/asn1/der_free.c
@@ -3,6 +3,8 @@
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
+ * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -43,6 +45,31 @@ der_free_general_string (heim_general_string *str)
}
void
+der_free_integer (int *i)
+{
+ *i = 0;
+}
+
+void
+der_free_unsigned (unsigned *u)
+{
+ *u = 0;
+}
+
+void
+der_free_generalized_time(time_t *t)
+{
+ *t = 0;
+}
+
+void
+der_free_utctime(time_t *t)
+{
+ *t = 0;
+}
+
+
+void
der_free_utf8string (heim_utf8_string *str)
{
free(*str);
diff --git a/source4/heimdal/lib/asn1/der_get.c b/source4/heimdal/lib/asn1/der_get.c
index 5a062fb339..aee565040f 100644
--- a/source4/heimdal/lib/asn1/der_get.c
+++ b/source4/heimdal/lib/asn1/der_get.c
@@ -305,7 +305,7 @@ der_get_octet_string_ber (const unsigned char *p, size_t len,
void *ptr;
ptr = realloc(data->data, data->length + datalen);
- if (ptr == NULL && data->length + datalen != 0) {
+ if (ptr == NULL) {
e = ENOMEM;
goto out;
}
@@ -354,23 +354,21 @@ der_get_heim_integer (const unsigned char *p, size_t len,
p++;
data->length--;
}
- if (data->length) {
- data->data = malloc(data->length);
- if (data->data == NULL) {
- data->length = 0;
- if (size)
- *size = 0;
- return ENOMEM;
- }
- q = &((unsigned char*)data->data)[data->length - 1];
- p += data->length - 1;
- while (q >= (unsigned char*)data->data) {
- *q = *p ^ 0xff;
- if (carry)
- carry = !++*q;
- p--;
- q--;
- }
+ data->data = malloc(data->length);
+ if (data->data == NULL) {
+ data->length = 0;
+ if (size)
+ *size = 0;
+ return ENOMEM;
+ }
+ q = &((unsigned char*)data->data)[data->length - 1];
+ p += data->length - 1;
+ while (q >= (unsigned char*)data->data) {
+ *q = *p ^ 0xff;
+ if (carry)
+ carry = !++*q;
+ p--;
+ q--;
}
} else {
data->negative = 0;
diff --git a/source4/heimdal/lib/asn1/der_length.c b/source4/heimdal/lib/asn1/der_length.c
index 5ea3a84845..688e6ba817 100644
--- a/source4/heimdal/lib/asn1/der_length.c
+++ b/source4/heimdal/lib/asn1/der_length.c
@@ -3,6 +3,8 @@
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
+ * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -113,6 +115,20 @@ der_length_len (size_t len)
}
size_t
+der_length_tag(unsigned int tag)
+{
+ size_t len = 0;
+
+ if(tag <= 30)
+ return 1;
+ while(tag) {
+ tag /= 128;
+ len++;
+ }
+ return len + 1;
+}
+
+size_t
der_length_integer (const int *data)
{
return _heim_len_int (*data);
diff --git a/source4/heimdal/lib/asn1/der_locl.h b/source4/heimdal/lib/asn1/der_locl.h
index 1f27e72903..0f65c50a22 100644
--- a/source4/heimdal/lib/asn1/der_locl.h
+++ b/source4/heimdal/lib/asn1/der_locl.h
@@ -52,6 +52,8 @@
#include <asn1-common.h>
#include <asn1_err.h>
#include <der.h>
+#include <der-private.h>
+#include "asn1-template.h"
time_t _der_timegm (struct tm *);
size_t _heim_len_unsigned (unsigned);
diff --git a/source4/heimdal/lib/asn1/digest.asn1 b/source4/heimdal/lib/asn1/digest.asn1
index 5ee5bd4a99..027402f1ef 100644
--- a/source4/heimdal/lib/asn1/digest.asn1
+++ b/source4/heimdal/lib/asn1/digest.asn1
@@ -100,6 +100,21 @@ NTLMResponse ::= SEQUENCE {
tickets [3] SEQUENCE OF OCTET STRING OPTIONAL
}
+NTLMRequest2 ::= SEQUENCE {
+ loginUserName [0] UTF8String,
+ loginDomainName [1] UTF8String,
+ flags [2] INTEGER (0..4294967295),
+ lmchallenge [3] OCTET STRING SIZE (8),
+ ntChallengeResponce [4] OCTET STRING,
+ lmChallengeResponce [5] OCTET STRING
+}
+
+NTLMReply ::= SEQUENCE {
+ success [0] BOOLEAN,
+ flags [1] INTEGER (0..4294967295),
+ sessionkey [2] OCTET STRING OPTIONAL
+}
+
DigestReqInner ::= CHOICE {
init [0] DigestInit,
digestRequest [1] DigestRequest,
diff --git a/source4/heimdal/lib/asn1/extra.c b/source4/heimdal/lib/asn1/extra.c
index b244dbb52a..95780a7898 100644
--- a/source4/heimdal/lib/asn1/extra.c
+++ b/source4/heimdal/lib/asn1/extra.c
@@ -3,6 +3,8 @@
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
+ * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -40,13 +42,7 @@ int
encode_heim_any(unsigned char *p, size_t len,
const heim_any *data, size_t *size)
{
- if (data->length > len)
- return ASN1_OVERFLOW;
- p -= data->length;
- len -= data->length;
- memcpy (p+1, data->data, data->length);
- *size = data->length;
- return 0;
+ return der_put_octet_string (p, len, data, size);
}
int
@@ -91,8 +87,7 @@ decode_heim_any(const unsigned char *p, size_t len,
void
free_heim_any(heim_any *data)
{
- free(data->data);
- data->data = NULL;
+ der_free_octet_string(data);
}
size_t
@@ -104,58 +99,43 @@ length_heim_any(const heim_any *data)
int
copy_heim_any(const heim_any *from, heim_any *to)
{
- to->data = malloc(from->length);
- if (to->data == NULL && from->length != 0)
- return ENOMEM;
- memcpy(to->data, from->data, from->length);
- to->length = from->length;
- return 0;
+ return der_copy_octet_string(from, to);
}
int
encode_heim_any_set(unsigned char *p, size_t len,
const heim_any_set *data, size_t *size)
{
- return encode_heim_any(p, len, data, size);
+ return der_put_octet_string (p, len, data, size);
}
-
int
decode_heim_any_set(const unsigned char *p, size_t len,
heim_any_set *data, size_t *size)
{
- memset(data, 0, sizeof(*data));
- data->data = malloc(len);
- if (data->data == NULL && len != 0)
- return ENOMEM;
- data->length = len;
- memcpy(data->data, p, len);
- if (size) *size = len;
- return 0;
+ return der_get_octet_string(p, len, data, size);
}
void
free_heim_any_set(heim_any_set *data)
{
- free_heim_any(data);
+ der_free_octet_string(data);
}
size_t
length_heim_any_set(const heim_any *data)
{
- return length_heim_any(data);
+ return data->length;
}
int
copy_heim_any_set(const heim_any_set *from, heim_any_set *to)
{
- return copy_heim_any(from, to);
+ return der_copy_octet_string(from, to);
}
int
heim_any_cmp(const heim_any_set *p, const heim_any_set *q)
{
- if (p->length != q->length)
- return p->length - q->length;
- return memcmp(p->data, q->data, p->length);
+ return der_heim_octet_string_cmp(p, q);
}
diff --git a/source4/heimdal/lib/asn1/gen.c b/source4/heimdal/lib/asn1/gen.c
index 780c18b36f..8c13434203 100644
--- a/source4/heimdal/lib/asn1/gen.c
+++ b/source4/heimdal/lib/asn1/gen.c
@@ -3,6 +3,8 @@
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
+ * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -35,12 +37,12 @@
RCSID("$Id$");
-FILE *headerfile, *codefile, *logfile;
+FILE *privheaderfile, *headerfile, *codefile, *logfile, *templatefile;
#define STEM "asn1"
static const char *orig_filename;
-static char *header;
+static char *privheader, *header, *template;
static const char *headerbase = STEM;
/*
@@ -66,6 +68,45 @@ add_import (const char *module)
fprintf (headerfile, "#include <%s_asn1.h>\n", module);
}
+/*
+ * List of all exported symbols
+ */
+
+struct sexport {
+ const char *name;
+ int defined;
+ struct sexport *next;
+};
+
+static struct sexport *exports = NULL;
+
+void
+add_export (const char *name)
+{
+ struct sexport *tmp = emalloc (sizeof(*tmp));
+
+ tmp->name = name;
+ tmp->next = exports;
+ exports = tmp;
+}
+
+int
+is_export(const char *name)
+{
+ struct sexport *tmp;
+
+ if (exports == NULL) /* no export list, all exported */
+ return 1;
+
+ for (tmp = exports; tmp != NULL; tmp = tmp->next) {
+ if (strcmp(tmp->name, name) == 0) {
+ tmp->defined = 1;
+ return 1;
+ }
+ }
+ return 0;
+}
+
const char *
get_filename (void)
{
@@ -96,6 +137,23 @@ init_generate (const char *filename, const char *base)
err (1, "open %s", fn);
free(fn);
+ /* private header file */
+ asprintf(&privheader, "%s-priv.h", headerbase);
+ if (privheader == NULL)
+ errx(1, "malloc");
+ asprintf(&fn, "%s-priv.hx", headerbase);
+ if (fn == NULL)
+ errx(1, "malloc");
+ privheaderfile = fopen (fn, "w");
+ if (privheaderfile == NULL)
+ err (1, "open %s", fn);
+ free(fn);
+
+ /* template file */
+ asprintf(&template, "%s-template.c", headerbase);
+ if (template == NULL)
+ errx(1, "malloc");
+
fprintf (headerfile,
"/* Generated from %s */\n"
"/* Do not edit */\n\n",
@@ -182,6 +240,36 @@ init_generate (const char *filename, const char *base)
logfile = fopen(fn, "w");
if (logfile == NULL)
err (1, "open %s", fn);
+
+ /* if one code file, write into the one codefile */
+ if (one_code_file)
+ return;
+
+ templatefile = fopen (template, "w");
+ if (templatefile == NULL)
+ err (1, "open %s", template);
+
+ fprintf (templatefile,
+ "/* Generated from %s */\n"
+ "/* Do not edit */\n\n"
+ "#include <stdio.h>\n"
+ "#include <stdlib.h>\n"
+ "#include <time.h>\n"
+ "#include <string.h>\n"
+ "#include <errno.h>\n"
+ "#include <limits.h>\n"
+ "#include <krb5-types.h>\n",
+ filename);
+
+ fprintf (templatefile,
+ "#include <%s>\n"
+ "#include <%s>\n"
+ "#include <der.h>\n"
+ "#include <der-private.h>\n"
+ "#include <asn1-template.h>\n",
+ header, privheader);
+
+
}
void
@@ -189,9 +277,15 @@ close_generate (void)
{
fprintf (headerfile, "#endif /* __%s_h__ */\n", headerbase);
- fclose (headerfile);
- fprintf (logfile, "\n");
- fclose (logfile);
+ if (headerfile)
+ fclose (headerfile);
+ if (privheaderfile)
+ fclose (privheaderfile);
+ if (templatefile)
+ fclose (templatefile);
+ if (logfile)
+ fprintf (logfile, "\n");
+ fclose (logfile);
}
void
@@ -265,11 +359,14 @@ generate_header_of_codefile(const char *name)
orig_filename);
fprintf (codefile,
- "#include <%s.h>\n",
- headerbase);
+ "#include <%s>\n"
+ "#include <%s>\n",
+ header, privheader);
fprintf (codefile,
"#include <asn1_err.h>\n"
"#include <der.h>\n"
+ "#include <der-private.h>\n"
+ "#include <asn1-template.h>\n"
"#include <parse_units.h>\n\n");
}
@@ -328,8 +425,6 @@ generate_constant (const Symbol *s)
}
fprintf (headerfile, "} */\n");
- fprintf (headerfile, "const heim_oid *oid_%s(void);\n",
- s->gen_name);
fprintf (headerfile,
"extern const heim_oid asn1_oid_%s;\n\n",
s->gen_name);
@@ -346,12 +441,6 @@ generate_constant (const Symbol *s)
"{ %d, oid_%s_variable_num };\n\n",
s->gen_name, len, s->gen_name);
- fprintf (codefile, "const heim_oid *oid_%s(void)\n"
- "{\n"
- "return &asn1_oid_%s;\n"
- "}\n\n",
- s->gen_name, s->gen_name);
-
free(list);
if (!one_code_file)
@@ -364,6 +453,33 @@ generate_constant (const Symbol *s)
}
}
+int
+is_primitive_type(int type)
+{
+ switch(type) {
+ case TInteger:
+ case TBoolean:
+ case TOctetString:
+ case TBitString:
+ case TEnumerated:
+ case TGeneralizedTime:
+ case TGeneralString:
+ case TTeletexString:
+ case TOID:
+ case TUTCTime:
+ case TUTF8String:
+ case TPrintableString:
+ case TIA5String:
+ case TBMPString:
+ case TUniversalString:
+ case TVisibleString:
+ case TNull:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
static void
space(int level)
{
@@ -550,8 +666,24 @@ define_asn1 (int level, Type *t)
}
static void
-define_type (int level, const char *name, Type *t, int typedefp, int preservep)
+getnewbasename(char **newbasename, int typedefp, const char *basename, const char *name)
+{
+ if (typedefp)
+ *newbasename = strdup(name);
+ else {
+ if (name[0] == '*')
+ name++;
+ asprintf(newbasename, "%s_%s", basename, name);
+ }
+ if (*newbasename == NULL)
+ err(1, "malloc");
+}
+
+static void
+define_type (int level, const char *name, const char *basename, Type *t, int typedefp, int preservep)
{
+ char *newbasename = NULL;
+
switch (t->type) {
case TType:
space(level);
@@ -602,16 +734,37 @@ define_type (int level, const char *name, Type *t, int typedefp, int preservep)
if(ASN1_TAILQ_EMPTY(t->members))
fprintf (headerfile, "heim_bit_string %s;\n", name);
else {
- fprintf (headerfile, "struct %s {\n", typedefp ? name : "");
+ int pos = 0;
+ getnewbasename(&newbasename, typedefp, basename, name);
+
+ fprintf (headerfile, "struct %s {\n", newbasename);
ASN1_TAILQ_FOREACH(m, t->members, members) {
char *n;
+ /* pad unused */
+ while (pos < m->val) {
+ asprintf (&n, "_unused%d:1", pos);
+ define_type (level + 1, n, newbasename, &i, FALSE, FALSE);
+ free(n);
+ pos++;
+ }
+
asprintf (&n, "%s:1", m->gen_name);
if (n == NULL)
errx(1, "malloc");
- define_type (level + 1, n, &i, FALSE, FALSE);
+ define_type (level + 1, n, newbasename, &i, FALSE, FALSE);
free (n);
+ pos++;
+ }
+ /* pad to 32 elements */
+ while (pos < 32) {
+ char *n;
+ asprintf (&n, "_unused%d:1", pos);
+ define_type (level + 1, n, newbasename, &i, FALSE, FALSE);
+ free(n);
+ pos++;
}
+
space(level);
fprintf (headerfile, "} %s;\n\n", name);
}
@@ -638,8 +791,10 @@ define_type (int level, const char *name, Type *t, int typedefp, int preservep)
case TSequence: {
Member *m;
+ getnewbasename(&newbasename, typedefp, basename, name);
+
space(level);
- fprintf (headerfile, "struct %s {\n", typedefp ? name : "");
+ fprintf (headerfile, "struct %s {\n", newbasename);
if (t->type == TSequence && preservep) {
space(level + 1);
fprintf(headerfile, "heim_octet_string _save;\n");
@@ -653,10 +808,10 @@ define_type (int level, const char *name, Type *t, int typedefp, int preservep)
asprintf (&n, "*%s", m->gen_name);
if (n == NULL)
errx(1, "malloc");
- define_type (level + 1, n, m->type, FALSE, FALSE);
+ define_type (level + 1, n, newbasename, m->type, FALSE, FALSE);
free (n);
} else
- define_type (level + 1, m->gen_name, m->type, FALSE, FALSE);
+ define_type (level + 1, m->gen_name, newbasename, m->type, FALSE, FALSE);
}
space(level);
fprintf (headerfile, "} %s;\n", name);
@@ -667,15 +822,17 @@ define_type (int level, const char *name, Type *t, int typedefp, int preservep)
Type i;
struct range range = { 0, INT_MAX };
+ getnewbasename(&newbasename, typedefp, basename, name);
+
i.type = TInteger;
i.range = &range;
i.members = NULL;
i.constraint = NULL;
space(level);
- fprintf (headerfile, "struct %s {\n", typedefp ? name : "");
- define_type (level + 1, "len", &i, FALSE, FALSE);
- define_type (level + 1, "*val", t->subtype, FALSE, FALSE);
+ fprintf (headerfile, "struct %s {\n", newbasename);
+ define_type (level + 1, "len", newbasename, &i, FALSE, FALSE);
+ define_type (level + 1, "*val", newbasename, t->subtype, FALSE, FALSE);
space(level);
fprintf (headerfile, "} %s;\n", name);
break;
@@ -693,14 +850,16 @@ define_type (int level, const char *name, Type *t, int typedefp, int preservep)
fprintf (headerfile, "heim_general_string %s;\n", name);
break;
case TTag:
- define_type (level, name, t->subtype, typedefp, preservep);
+ define_type (level, name, basename, t->subtype, typedefp, preservep);
break;
case TChoice: {
int first = 1;
Member *m;
+ getnewbasename(&newbasename, typedefp, basename, name);
+
space(level);
- fprintf (headerfile, "struct %s {\n", typedefp ? name : "");
+ fprintf (headerfile, "struct %s {\n", newbasename);
if (preservep) {
space(level + 1);
fprintf(headerfile, "heim_octet_string _save;\n");
@@ -737,10 +896,10 @@ define_type (int level, const char *name, Type *t, int typedefp, int preservep)
asprintf (&n, "*%s", m->gen_name);
if (n == NULL)
errx(1, "malloc");
- define_type (level + 2, n, m->type, FALSE, FALSE);
+ define_type (level + 2, n, newbasename, m->type, FALSE, FALSE);
free (n);
} else
- define_type (level + 2, m->gen_name, m->type, FALSE, FALSE);
+ define_type (level + 2, m->gen_name, newbasename, m->type, FALSE, FALSE);
}
space(level + 1);
fprintf (headerfile, "} u;\n");
@@ -787,6 +946,8 @@ define_type (int level, const char *name, Type *t, int typedefp, int preservep)
default:
abort ();
}
+ if (newbasename)
+ free(newbasename);
}
static void
@@ -800,27 +961,61 @@ generate_type_header (const Symbol *s)
fprintf (headerfile, "\n*/\n\n");
fprintf (headerfile, "typedef ");
- define_type (0, s->gen_name, s->type, TRUE, preservep);
+ define_type (0, s->gen_name, s->gen_name, s->type, TRUE, preservep);
fprintf (headerfile, "\n");
}
-
void
generate_type (const Symbol *s)
{
+ FILE *h;
+
if (!one_code_file)
generate_header_of_codefile(s->gen_name);
generate_type_header (s);
- generate_type_encode (s);
- generate_type_decode (s);
- generate_type_free (s);
- generate_type_length (s);
- generate_type_copy (s);
+
+ if (template_flag)
+ generate_template(s);
+
+ if (template_flag == 0 || is_template_compat(s) == 0) {
+ generate_type_encode (s);
+ generate_type_decode (s);
+ generate_type_free (s);
+ generate_type_length (s);
+ generate_type_copy (s);
+ }
generate_type_seq (s);
generate_glue (s->type, s->gen_name);
- fprintf(headerfile, "\n\n");
+
+ /* generate prototypes */
+
+ if (is_export(s->name))
+ h = headerfile;
+ else
+ h = privheaderfile;
+
+ fprintf (h,
+ "int "
+ "decode_%s(const unsigned char *, size_t, %s *, size_t *);\n",
+ s->gen_name, s->gen_name);
+ fprintf (h,
+ "int "
+ "encode_%s(unsigned char *, size_t, const %s *, size_t *);\n",
+ s->gen_name, s->gen_name);
+ fprintf (h,
+ "size_t length_%s(const %s *);\n",
+ s->gen_name, s->gen_name);
+ fprintf (h,
+ "int copy_%s (const %s *, %s *);\n",
+ s->gen_name, s->gen_name, s->gen_name);
+ fprintf (h,
+ "void free_%s (%s *);\n",
+ s->gen_name, s->gen_name);
+
+
+ fprintf(h, "\n\n");
if (!one_code_file) {
fprintf(codefile, "\n\n");
diff --git a/source4/heimdal/lib/asn1/gen_copy.c b/source4/heimdal/lib/asn1/gen_copy.c
index f28647d19a..5e228d0e64 100644
--- a/source4/heimdal/lib/asn1/gen_copy.c
+++ b/source4/heimdal/lib/asn1/gen_copy.c
@@ -228,10 +228,6 @@ generate_type_copy (const Symbol *s)
used_fail = 0;
- fprintf (headerfile,
- "int copy_%s (const %s *, %s *);\n",
- s->gen_name, s->gen_name, s->gen_name);
-
fprintf (codefile, "int\n"
"copy_%s(const %s *from, %s *to)\n"
"{\n"
diff --git a/source4/heimdal/lib/asn1/gen_decode.c b/source4/heimdal/lib/asn1/gen_decode.c
index 327de4c98c..043cfac2db 100644
--- a/source4/heimdal/lib/asn1/gen_decode.c
+++ b/source4/heimdal/lib/asn1/gen_decode.c
@@ -56,33 +56,6 @@ decode_primitive (const char *typename, const char *name, const char *forwstr)
#endif
}
-static int
-is_primitive_type(int type)
-{
- switch(type) {
- case TInteger:
- case TBoolean:
- case TOctetString:
- case TBitString:
- case TEnumerated:
- case TGeneralizedTime:
- case TGeneralString:
- case TTeletexString:
- case TOID:
- case TUTCTime:
- case TUTF8String:
- case TPrintableString:
- case TIA5String:
- case TBMPString:
- case TUniversalString:
- case TVisibleString:
- case TNull:
- return 1;
- default:
- return 0;
- }
-}
-
static void
find_tag (const Type *t,
Der_class *cl, Der_type *ty, unsigned *tag)
@@ -630,7 +603,7 @@ decode_type (const char *name, const Type *t, int optional,
fprintf(codefile,
"else {\n"
"(%s)->u.%s.data = calloc(1, len);\n"
- "if ((%s)->u.%s.data == NULL && len != 0) {\n"
+ "if ((%s)->u.%s.data == NULL) {\n"
"e = ENOMEM; %s;\n"
"}\n"
"(%s)->u.%s.length = len;\n"
@@ -694,11 +667,6 @@ generate_type_decode (const Symbol *s)
{
int preserve = preserve_type(s->name) ? TRUE : FALSE;
- fprintf (headerfile,
- "int "
- "decode_%s(const unsigned char *, size_t, %s *, size_t *);\n",
- s->gen_name, s->gen_name);
-
fprintf (codefile, "int\n"
"decode_%s(const unsigned char *p,"
" size_t len, %s *data, size_t *size)\n"
@@ -744,7 +712,7 @@ generate_type_decode (const Symbol *s)
if (preserve)
fprintf (codefile,
"data->_save.data = calloc(1, ret);\n"
- "if (data->_save.data == NULL && ret != 0) { \n"
+ "if (data->_save.data == NULL) { \n"
"e = ENOMEM; goto fail; \n"
"}\n"
"data->_save.length = ret;\n"
diff --git a/source4/heimdal/lib/asn1/gen_encode.c b/source4/heimdal/lib/asn1/gen_encode.c
index 012d4677f4..e9b4e7cd12 100644
--- a/source4/heimdal/lib/asn1/gen_encode.c
+++ b/source4/heimdal/lib/asn1/gen_encode.c
@@ -508,11 +508,6 @@ encode_type (const char *name, const Type *t, const char *tmpstr)
void
generate_type_encode (const Symbol *s)
{
- fprintf (headerfile,
- "int "
- "encode_%s(unsigned char *, size_t, const %s *, size_t *);\n",
- s->gen_name, s->gen_name);
-
fprintf (codefile, "int\n"
"encode_%s(unsigned char *p, size_t len,"
" const %s *data, size_t *size)\n"
diff --git a/source4/heimdal/lib/asn1/gen_free.c b/source4/heimdal/lib/asn1/gen_free.c
index 48fe8cd787..dc612074a3 100644
--- a/source4/heimdal/lib/asn1/gen_free.c
+++ b/source4/heimdal/lib/asn1/gen_free.c
@@ -180,18 +180,14 @@ free_type (const char *name, const Type *t, int preserve)
void
generate_type_free (const Symbol *s)
{
- int preserve = preserve_type(s->name) ? TRUE : FALSE;
-
- fprintf (headerfile,
- "void free_%s (%s *);\n",
- s->gen_name, s->gen_name);
-
- fprintf (codefile, "void\n"
- "free_%s(%s *data)\n"
- "{\n",
- s->gen_name, s->gen_name);
-
- free_type ("data", s->type, preserve);
- fprintf (codefile, "}\n\n");
+ int preserve = preserve_type(s->name) ? TRUE : FALSE;
+
+ fprintf (codefile, "void\n"
+ "free_%s(%s *data)\n"
+ "{\n",
+ s->gen_name, s->gen_name);
+
+ free_type ("data", s->type, preserve);
+ fprintf (codefile, "}\n\n");
}
diff --git a/source4/heimdal/lib/asn1/gen_glue.c b/source4/heimdal/lib/asn1/gen_glue.c
index 9f7eca45eb..32680cef41 100644
--- a/source4/heimdal/lib/asn1/gen_glue.c
+++ b/source4/heimdal/lib/asn1/gen_glue.c
@@ -3,6 +3,8 @@
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
+ * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -70,7 +72,8 @@ generate_int2 (const Type *t, const char *gen_name)
fprintf (codefile,
"%s int2%s(unsigned n)\n"
"{\n"
- "\t%s flags;\n\n",
+ "\t%s flags;\n\n"
+ "\tmemset(&flags, 0, sizeof(flags));\n\n",
gen_name, gen_name, gen_name);
if(t->members) {
@@ -92,9 +95,17 @@ generate_units (const Type *t, const char *gen_name)
{
Member *m;
- fprintf (headerfile,
- "const struct units * asn1_%s_units(void);",
- gen_name);
+ if (template_flag) {
+ fprintf (headerfile,
+ "extern const struct units *asn1_%s_table_units;\n",
+ gen_name);
+ fprintf (headerfile, "#define asn1_%s_units() (asn1_%s_table_units)\n",
+ gen_name, gen_name);
+ } else {
+ fprintf (headerfile,
+ "const struct units * asn1_%s_units(void);",
+ gen_name);
+ }
fprintf (codefile,
"static struct units %s_units[] = {\n",
@@ -111,11 +122,16 @@ generate_units (const Type *t, const char *gen_name)
"\t{NULL,\t0}\n"
"};\n\n");
- fprintf (codefile,
- "const struct units * asn1_%s_units(void){\n"
- "return %s_units;\n"
- "}\n\n",
- gen_name, gen_name);
+ if (template_flag)
+ fprintf (codefile,
+ "const struct units * asn1_%s_table_units = %s_units;\n",
+ gen_name, gen_name);
+ else
+ fprintf (codefile,
+ "const struct units * asn1_%s_units(void){\n"
+ "return %s_units;\n"
+ "}\n\n",
+ gen_name, gen_name);
}
diff --git a/source4/heimdal/lib/asn1/gen_length.c b/source4/heimdal/lib/asn1/gen_length.c
index e1f045c4c5..da6d26e373 100644
--- a/source4/heimdal/lib/asn1/gen_length.c
+++ b/source4/heimdal/lib/asn1/gen_length.c
@@ -43,6 +43,7 @@ length_primitive (const char *typename,
fprintf (codefile, "%s += der_length_%s(%s);\n", variable, typename, name);
}
+/* XXX same as der_length_tag */
static size_t
length_tag(unsigned int tag)
{
@@ -269,10 +270,6 @@ length_type (const char *name, const Type *t,
void
generate_type_length (const Symbol *s)
{
- fprintf (headerfile,
- "size_t length_%s(const %s *);\n",
- s->gen_name, s->gen_name);
-
fprintf (codefile,
"size_t\n"
"length_%s(const %s *data)\n"
diff --git a/source4/heimdal/lib/asn1/gen_locl.h b/source4/heimdal/lib/asn1/gen_locl.h
index 2bb64b5a38..9e87b0c578 100644
--- a/source4/heimdal/lib/asn1/gen_locl.h
+++ b/source4/heimdal/lib/asn1/gen_locl.h
@@ -52,6 +52,7 @@
#include "symbol.h"
#include "asn1-common.h"
#include "der.h"
+#include "der-private.h"
void generate_type (const Symbol *);
void generate_constant (const Symbol *);
@@ -74,7 +75,10 @@ void init_generate (const char *, const char *);
const char *get_filename (void);
void close_generate(void);
void add_import(const char *);
+void add_export(const char *);
+int is_export(const char *);
int yyparse(void);
+int is_primitive_type(int);
int preserve_type(const char *);
int seq_type(const char *);
@@ -82,9 +86,14 @@ int seq_type(const char *);
void generate_header_of_codefile(const char *);
void close_codefile(void);
+int is_template_compat (const Symbol *);
+void generate_template(const Symbol *);
+void gen_template_import(const Symbol *);
-extern FILE *headerfile, *codefile, *logfile;
+
+extern FILE *privheaderfile, *headerfile, *codefile, *logfile, *templatefile;
extern int support_ber;
+extern int template_flag;
extern int rfc1510_bitstring;
extern int one_code_file;
diff --git a/source4/heimdal/lib/asn1/krb5.asn1 b/source4/heimdal/lib/asn1/krb5.asn1
index adc09ac680..ed663fcf5f 100644
--- a/source4/heimdal/lib/asn1/krb5.asn1
+++ b/source4/heimdal/lib/asn1/krb5.asn1
@@ -2,6 +2,78 @@
KERBEROS5 DEFINITIONS ::=
BEGIN
+EXPORTS
+ AD-AND-OR,
+ AD-IF-RELEVANT,
+ AD-KDCIssued,
+ AD-LoginAlias,
+ AP-REP,
+ AP-REQ,
+ AS-REP,
+ AS-REQ,
+ AUTHDATA-TYPE,
+ Authenticator,
+ AuthorizationData,
+ AuthorizationDataElement,
+ CKSUMTYPE,
+ ChangePasswdDataMS,
+ Checksum,
+ ENCTYPE,
+ ETYPE-INFO,
+ ETYPE-INFO-ENTRY,
+ ETYPE-INFO2,
+ ETYPE-INFO2-ENTRY,
+ EncAPRepPart,
+ EncASRepPart,
+ EncKDCRepPart,
+ EncKrbCredPart,
+ EncKrbPrivPart,
+ EncTGSRepPart,
+ EncTicketPart,
+ EncryptedData,
+ EncryptionKey,
+ EtypeList,
+ HostAddress,
+ HostAddresses,
+ KDC-REQ-BODY,
+ KDCOptions,
+ KDC-REP,
+ KRB-CRED,
+ KRB-ERROR,
+ KRB-PRIV,
+ KRB-SAFE,
+ KRB-SAFE-BODY,
+ KRB5SignedPath,
+ KRB5SignedPathData,
+ KRB5SignedPathPrincipals,
+ KerberosString,
+ KerberosTime,
+ KrbCredInfo,
+ LR-TYPE,
+ LastReq,
+ METHOD-DATA,
+ NAME-TYPE,
+ PA-ClientCanonicalized,
+ PA-ClientCanonicalizedNames,
+ PA-DATA,
+ PA-ENC-TS-ENC,
+ PA-PAC-REQUEST,
+ PA-S4U2Self,
+ PA-SERVER-REFERRAL-DATA,
+ PA-ServerReferralData,
+ PA-SvrReferralData,
+ PADATA-TYPE,
+ Principal,
+ PrincipalName,
+ Principals,
+ Realm,
+ TGS-REP,
+ TGS-REQ,
+ Ticket,
+ TicketFlags,
+ TransitedEncoding,
+ TypedData
+ ;
NAME-TYPE ::= INTEGER {
KRB5_NT_UNKNOWN(0), -- Name type not known
@@ -256,11 +328,7 @@ KDCOptions ::= BIT STRING {
proxy(4),
allow-postdate(5),
postdated(6),
- unused7(7),
renewable(8),
- unused9(9),
- unused10(10),
- unused11(11),
request-anonymous(14),
canonicalize(15),
constrained-delegation(16), -- ms extension
diff --git a/source4/heimdal/lib/asn1/main.c b/source4/heimdal/lib/asn1/main.c
index 5cef970d78..a99e69d0f9 100644
--- a/source4/heimdal/lib/asn1/main.c
+++ b/source4/heimdal/lib/asn1/main.c
@@ -63,12 +63,14 @@ seq_type(const char *p)
}
int support_ber;
+int template_flag;
int rfc1510_bitstring;
int one_code_file;
char *option_file;
int version_flag;
int help_flag;
struct getargs args[] = {
+ { "template", 0, arg_flag, &template_flag },
{ "encode-rfc1510-bit-string", 0, arg_flag, &rfc1510_bitstring },
{ "decode-dce-ber", 0, arg_flag, &support_ber },
{ "support-ber", 0, arg_flag, &support_ber },
diff --git a/source4/heimdal/lib/asn1/symbol.c b/source4/heimdal/lib/asn1/symbol.c
index ac00bdc6cb..e65876a032 100644
--- a/source4/heimdal/lib/asn1/symbol.c
+++ b/source4/heimdal/lib/asn1/symbol.c
@@ -34,8 +34,6 @@
#include "gen_locl.h"
#include "lex.h"
-RCSID("$Id$");
-
static Hashtab *htab;
static int
@@ -68,7 +66,7 @@ output_name(char *s)
char *p;
for (p = s; *p; ++p)
- if (*p == '-')
+ if (*p == '-' || *p == '.')
*p = '_';
}
diff --git a/source4/heimdal/lib/asn1/test.asn1 b/source4/heimdal/lib/asn1/test.asn1
index f6237b85b8..e3c72ac76e 100644
--- a/source4/heimdal/lib/asn1/test.asn1
+++ b/source4/heimdal/lib/asn1/test.asn1
@@ -6,8 +6,11 @@ BEGIN
IMPORTS heim_any FROM heim;
+TESTuint32 ::= INTEGER (0..4294967295)
+
TESTLargeTag ::= SEQUENCE {
- foo[127] INTEGER (-2147483648..2147483647)
+ foo[127] INTEGER (-2147483648..2147483647),
+ bar[128] INTEGER (-2147483648..2147483647)
}
TESTSeq ::= SEQUENCE {
@@ -57,6 +60,11 @@ TESTAlloc ::= SEQUENCE {
tagless2 heim_any OPTIONAL
}
+TESTOptional ::= SEQUENCE {
+ zero [0] INTEGER (-2147483648..2147483647) OPTIONAL,
+ one [1] INTEGER (-2147483648..2147483647) OPTIONAL
+}
+
TESTCONTAINING ::= OCTET STRING ( CONTAINING INTEGER )
TESTENCODEDBY ::= OCTET STRING ( ENCODED BY
@@ -92,4 +100,36 @@ TESTSeqSizeOf4 ::= SEQUENCE SIZE (MIN..2) OF TESTInteger
TESTOSSize1 ::= OCTET STRING SIZE (1..2)
+TESTSeqOfSeq ::= SEQUENCE OF SEQUENCE {
+ zero [0] TESTInteger
+}
+
+TESTSeqOfSeq2 ::= SEQUENCE OF SEQUENCE {
+ string [0] GeneralString
+}
+
+TESTSeqOfSeq3 ::= SEQUENCE OF SEQUENCE {
+ zero [0] TESTInteger,
+ string [0] GeneralString
+}
+
+TESTSeqOf2 ::= SEQUENCE {
+ strings SEQUENCE OF GeneralString
+}
+
+TESTSeqOf3 ::= SEQUENCE {
+ strings SEQUENCE OF GeneralString OPTIONAL
+}
+
+TESTPreserve ::= SEQUENCE {
+ zero [0] TESTInteger,
+ one [1] TESTInteger
+}
+
+TESTBitString ::= BIT STRING {
+ zero(0),
+ eight(8),
+ thirtyone(31)
+}
+
END