diff options
author | Andrew Bartlett <abartlet@samba.org> | 2006-03-11 04:03:12 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:56:58 -0500 |
commit | b7afac2b834674e20f303c3a03b4ac7bb283695e (patch) | |
tree | 4828afb0cf5bc89f0063d3225d0f15cc01cd2012 /source4/heimdal/lib/asn1 | |
parent | 64b619cefe99c833297f2a635db06bd186843481 (diff) | |
download | samba-b7afac2b834674e20f303c3a03b4ac7bb283695e.tar.gz samba-b7afac2b834674e20f303c3a03b4ac7bb283695e.tar.bz2 samba-b7afac2b834674e20f303c3a03b4ac7bb283695e.zip |
r14198: Update Samba4 to current lorikeet-heimdal.
Andrew Bartlett
(This used to be commit 97a0a0e2fa6784e5fc5278f7a15b385ddcb6a3b3)
Diffstat (limited to 'source4/heimdal/lib/asn1')
-rw-r--r-- | source4/heimdal/lib/asn1/asn1_gen.c | 10 | ||||
-rw-r--r-- | source4/heimdal/lib/asn1/der.h | 8 | ||||
-rwxr-xr-x | source4/heimdal/lib/asn1/der_cmp.c | 4 | ||||
-rw-r--r-- | source4/heimdal/lib/asn1/der_copy.c | 3 | ||||
-rw-r--r-- | source4/heimdal/lib/asn1/der_format.c | 105 | ||||
-rw-r--r-- | source4/heimdal/lib/asn1/der_get.c | 29 | ||||
-rw-r--r-- | source4/heimdal/lib/asn1/der_length.c | 4 | ||||
-rw-r--r-- | source4/heimdal/lib/asn1/extra.c | 26 | ||||
-rw-r--r-- | source4/heimdal/lib/asn1/parse.y | 79 |
9 files changed, 233 insertions, 35 deletions
diff --git a/source4/heimdal/lib/asn1/asn1_gen.c b/source4/heimdal/lib/asn1/asn1_gen.c index 95d670cbb1..5dc0ba2e2d 100644 --- a/source4/heimdal/lib/asn1/asn1_gen.c +++ b/source4/heimdal/lib/asn1/asn1_gen.c @@ -40,7 +40,7 @@ #include <hex.h> #include <err.h> -RCSID("$Id: asn1_gen.c,v 1.3 2005/08/11 10:44:43 lha Exp $"); +RCSID("$Id: asn1_gen.c,v 1.4 2006/01/30 15:06:03 lha Exp $"); static int doit(const char *fn) @@ -87,13 +87,13 @@ doit(const char *fn) ptr++; class = strtok_r(ptr, " \t\n", &foo); - if (class == NULL) errx(1, "class missing one line %lu", line); + if (class == NULL) errx(1, "class missing on line %lu", line); type = strtok_r(NULL, " \t\n", &foo); - if (type == NULL) errx(1, "type missing one line %lu", line); + if (type == NULL) errx(1, "type missing on line %lu", line); tag = strtok_r(NULL, " \t\n", &foo); - if (tag == NULL) errx(1, "tag missing one line %lu", line); + if (tag == NULL) errx(1, "tag missing on line %lu", line); length = strtok_r(NULL, " \t\n", &foo); - if (length == NULL) errx(1, "length missing one line %lu", line); + if (length == NULL) errx(1, "length missing on line %lu", line); data = strtok_r(NULL, " \t\n", &foo); c = der_get_class_num(class); diff --git a/source4/heimdal/lib/asn1/der.h b/source4/heimdal/lib/asn1/der.h index 1f89f875f5..b9c2b47079 100644 --- a/source4/heimdal/lib/asn1/der.h +++ b/source4/heimdal/lib/asn1/der.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. */ -/* $Id: der.h,v 1.30 2005/10/07 03:48:00 lha Exp $ */ +/* $Id: der.h,v 1.32 2006/01/30 15:25:25 lha Exp $ */ #ifndef __DER_H__ #define __DER_H__ @@ -65,8 +65,10 @@ enum { UT_IA5String = 22, UT_UTCTime = 23, UT_GeneralizedTime = 24, + UT_UniversalString = 25, UT_VisibleString = 26, UT_GeneralString = 27, + UT_BMPString = 30, /* unsupported types */ UT_ObjectDescriptor = 7, UT_External = 8, @@ -76,9 +78,7 @@ enum { UT_NumericString = 18, UT_TeletexString = 20, UT_VideotexString = 21, - UT_GraphicString = 25, - UT_UniversalString = 25, - UT_BMPString = 30, + UT_GraphicString = 25 }; #define ASN1_INDEFINITE 0xdce0deed diff --git a/source4/heimdal/lib/asn1/der_cmp.c b/source4/heimdal/lib/asn1/der_cmp.c index 306fcbdf57..2471312ba8 100755 --- a/source4/heimdal/lib/asn1/der_cmp.c +++ b/source4/heimdal/lib/asn1/der_cmp.c @@ -74,10 +74,10 @@ heim_bit_string_cmp(const heim_bit_string *p, const heim_bit_string *q) int heim_integer_cmp(const heim_integer *p, const heim_integer *q) { + if (p->negative != q->negative) + return q->negative - p->negative; if (p->length != q->length) return p->length - q->length; - if (p->negative != q->negative) - return p->negative - q->negative; return memcmp(p->data, q->data, p->length); } diff --git a/source4/heimdal/lib/asn1/der_copy.c b/source4/heimdal/lib/asn1/der_copy.c index a3c9026cbf..e0443eed39 100644 --- a/source4/heimdal/lib/asn1/der_copy.c +++ b/source4/heimdal/lib/asn1/der_copy.c @@ -33,7 +33,7 @@ #include "der_locl.h" -RCSID("$Id: der_copy.c,v 1.13 2005/07/12 06:27:20 lha Exp $"); +RCSID("$Id: der_copy.c,v 1.14 2006/01/04 23:41:29 lha Exp $"); int copy_general_string (const heim_general_string *from, heim_general_string *to) @@ -106,6 +106,7 @@ copy_heim_integer (const heim_integer *from, heim_integer *to) if(to->length != 0 && to->data == NULL) return ENOMEM; memcpy(to->data, from->data, to->length); + to->negative = from->negative; return 0; } diff --git a/source4/heimdal/lib/asn1/der_format.c b/source4/heimdal/lib/asn1/der_format.c new file mode 100644 index 0000000000..44e39b46c5 --- /dev/null +++ b/source4/heimdal/lib/asn1/der_format.c @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2005 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "der_locl.h" +#include <hex.h> + +RCSID("$Id: der_format.c,v 1.2 2006/01/16 23:01:11 lha Exp $"); + +int +der_parse_hex_heim_integer (const char *p, heim_integer *data) +{ + ssize_t len; + + data->length = 0; + data->negative = 0; + data->data = NULL; + + if (*p == '-') { + p++; + data->negative = 1; + } + + len = strlen(p); + if (len < 0) { + data->data = NULL; + data->length = 0; + return EINVAL; + } + + data->length = (len / 2) + 1; + data->data = malloc(data->length); + if (data->data == NULL) { + data->length = 0; + return ENOMEM; + } + + len = hex_decode(p, data->data, data->length); + if (len < 0) { + free(data->data); + data->data = NULL; + data->length = 0; + return EINVAL; + } + + { + unsigned char *p = data->data; + while(*p == 0 && len > 0) { + p++; + len--; + } + data->length = len; + memmove(data->data, p, len); + } + return 0; +} + +int +der_print_hex_heim_integer (const heim_integer *data, char **p) +{ + ssize_t len; + char *q; + + len = hex_encode(data->data, data->length, p); + if (len < 0) + return ENOMEM; + + if (data->negative) { + len = asprintf(&q, "-%s", *p); + free(*p); + if (len < 0) + return ENOMEM; + *p = q; + } + return 0; +} diff --git a/source4/heimdal/lib/asn1/der_get.c b/source4/heimdal/lib/asn1/der_get.c index 403f5ab1ba..a75ab15c09 100644 --- a/source4/heimdal/lib/asn1/der_get.c +++ b/source4/heimdal/lib/asn1/der_get.c @@ -33,7 +33,7 @@ #include "der_locl.h" -RCSID("$Id: der_get.c,v 1.44 2005/07/19 18:04:00 lha Exp $"); +RCSID("$Id: der_get.c,v 1.45 2006/01/20 10:03:50 lha Exp $"); #include <version.h> @@ -241,19 +241,40 @@ der_get_heim_integer (const unsigned char *p, size_t len, return 0; } if (p[0] & 0x80) { + unsigned char *q; + int carry = 1; data->negative = 1; - return ASN1_OVERRUN; + data->length = len; + + if (p[0] == 0xff) { + p++; + data->length--; + } + data->data = malloc(data->length); + if (data->data == NULL) { + data->length = 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; data->length = len; - if (p[0] == 0 && data->length != 1) { + if (p[0] == 0) { p++; data->length--; } data->data = malloc(data->length); - if (data->data == NULL) { + if (data->data == NULL && data->length != 0) { data->length = 0; return ENOMEM; } diff --git a/source4/heimdal/lib/asn1/der_length.c b/source4/heimdal/lib/asn1/der_length.c index e818267bf4..2c017ad84e 100644 --- a/source4/heimdal/lib/asn1/der_length.c +++ b/source4/heimdal/lib/asn1/der_length.c @@ -33,7 +33,7 @@ #include "der_locl.h" -RCSID("$Id: der_length.c,v 1.17 2005/07/12 06:27:22 lha Exp $"); +RCSID("$Id: der_length.c,v 1.18 2006/01/20 10:04:46 lha Exp $"); size_t _heim_len_unsigned (unsigned val) @@ -178,7 +178,7 @@ length_heim_integer (const heim_integer *k) if (k->length == 0) return 1; if (k->negative) - return k->length + ((((unsigned char *)k->data)[0] & 0x80) ? 0 : 1); + return k->length + (((~(((unsigned char *)k->data)[0])) & 0x80) ? 0 : 1); else return k->length + ((((unsigned char *)k->data)[0] & 0x80) ? 1 : 0); } diff --git a/source4/heimdal/lib/asn1/extra.c b/source4/heimdal/lib/asn1/extra.c index ba081e3a63..4f70f191df 100644 --- a/source4/heimdal/lib/asn1/extra.c +++ b/source4/heimdal/lib/asn1/extra.c @@ -34,7 +34,7 @@ #include "der_locl.h" #include "heim_asn1.h" -RCSID("$Id: extra.c,v 1.5 2005/07/19 18:05:16 lha Exp $"); +RCSID("$Id: extra.c,v 1.6 2006/01/31 09:44:54 lha Exp $"); int encode_heim_any(unsigned char *p, size_t len, @@ -59,10 +59,7 @@ decode_heim_any(const unsigned char *p, size_t len, unsigned int thistag; int e; - if (data == NULL && len == 0) { /* XXX tag less OPTIONAL */ - *size = 0; - return 0; - } + memset(data, 0, sizeof(*data)); e = der_get_tag (p, len, &thisclass, &thistype, &thistag, &l); if (e) return e; @@ -73,16 +70,15 @@ decode_heim_any(const unsigned char *p, size_t len, if (length + len_len + l > len) return ASN1_OVERFLOW; - if (data) { /* XXX hack to workaround tag less OPTIONAL data */ - memset(data, 0, sizeof(*data)); - - data->data = malloc(length + len_len + l); - if (data->data == NULL) - return ENOMEM; - data->length = length + len_len + l; - memcpy(data->data, p, length + len_len + l); - } - if (size) *size = length + len_len + l; + data->data = malloc(length + len_len + l); + if (data->data == NULL) + return ENOMEM; + data->length = length + len_len + l; + memcpy(data->data, p, length + len_len + l); + + if (size) + *size = length + len_len + l; + return 0; } diff --git a/source4/heimdal/lib/asn1/parse.y b/source4/heimdal/lib/asn1/parse.y index 51dc51ed88..2238478284 100644 --- a/source4/heimdal/lib/asn1/parse.y +++ b/source4/heimdal/lib/asn1/parse.y @@ -31,7 +31,7 @@ * SUCH DAMAGE. */ -/* $Id: parse.y,v 1.25 2005/08/23 10:52:31 lha Exp $ */ +/* $Id: parse.y,v 1.27 2005/12/14 09:44:36 lha Exp $ */ %{ #ifdef HAVE_CONFIG_H @@ -45,9 +45,10 @@ #include "gen_locl.h" #include "der.h" -RCSID("$Id: parse.y,v 1.25 2005/08/23 10:52:31 lha Exp $"); +RCSID("$Id: parse.y,v 1.27 2005/12/14 09:44:36 lha Exp $"); static Type *new_type (Typetype t); +static struct constraint_spec *new_constraint_spec(enum ctype); static Type *new_tag(int tagclass, int tagvalue, int tagenv, Type *oldtype); void yyerror (const char *); static struct objid *new_objid(const char *label, int value); @@ -73,6 +74,7 @@ struct string_list { struct string_list *sl; struct tagtype tag; struct memhead *members; + struct constraint_spec *constraint_spec; } %token kw_ABSENT @@ -183,6 +185,7 @@ struct string_list { %type <type> BitStringType %type <type> BooleanType %type <type> ChoiceType +%type <type> ConstrainedType %type <type> EnumeratedType %type <type> IntegerType %type <type> NullType @@ -215,6 +218,12 @@ struct string_list { %type <sl> referencenames +%type <constraint_spec> Constraint +%type <constraint_spec> ConstraintSpec +%type <constraint_spec> GeneralConstraint +%type <constraint_spec> ContentsConstraint +%type <constraint_spec> UserDefinedConstraint + %start ModuleDefinition %% @@ -300,6 +309,7 @@ TypeAssignment : IDENTIFIER EEQUAL Type Type : BuiltinType | ReferencedType + | ConstrainedType ; BuiltinType : BitStringType @@ -507,6 +517,63 @@ UsefulType : kw_GeneralizedTime } ; +ConstrainedType : Type Constraint + { + /* if (Constraint.type == contentConstrant) { + assert(Constraint.u.constraint.type == octetstring|bitstring-w/o-NamedBitList); // remember to check type reference too + if (Constraint.u.constraint.type) { + assert((Constraint.u.constraint.type.length % 8) == 0); + } + } + if (Constraint.u.constraint.encoding) { + type == der-oid|ber-oid + } + */ + } + ; + + +Constraint : '(' ConstraintSpec ')' + { + $$ = $2; + } + +ConstraintSpec : GeneralConstraint + +GeneralConstraint: ContentsConstraint + | UserDefinedConstraint + ; + +ContentsConstraint: kw_CONTAINING Type + { + $$ = new_constraint_spec(CT_CONTENTS); + $$->u.content.type = $2; + $$->u.content.encoding = NULL; + } + | kw_ENCODED kw_BY Value + { + if ($3->type != objectidentifiervalue) + error_message("Non-OID used in ENCODED BY constraint"); + $$ = new_constraint_spec(CT_CONTENTS); + $$->u.content.type = NULL; + $$->u.content.encoding = $3; + } + | kw_CONTAINING Type kw_ENCODED kw_BY Value + { + if ($5->type != objectidentifiervalue) + error_message("Non-OID used in ENCODED BY constraint"); + $$ = new_constraint_spec(CT_CONTENTS); + $$->u.content.type = $2; + $$->u.content.encoding = $5; + } + ; + +UserDefinedConstraint: kw_CONSTRAINED kw_BY '{' '}' + { + $$ = new_constraint_spec(CT_USER); + } + ; + TaggedType : Tag tagenv Type { $$ = new_type(TTag); @@ -861,6 +928,14 @@ new_type (Typetype tt) return t; } +static struct constraint_spec * +new_constraint_spec(enum ctype ct) +{ + struct constraint_spec *c = ecalloc(1, sizeof(*c)); + c->ctype = ct; + return c; +} + static void fix_labels2(Type *t, const char *prefix); static void fix_labels1(struct memhead *members, const char *prefix) { |