From 6585e5ad764ee2414d9b01f30784b6549bc8f58e Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Mon, 30 Jul 2007 19:37:53 +0000 Subject: added keyexchange --- keyexchange/isakmpd-20041012/attribute.c | 112 +++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 keyexchange/isakmpd-20041012/attribute.c (limited to 'keyexchange/isakmpd-20041012/attribute.c') diff --git a/keyexchange/isakmpd-20041012/attribute.c b/keyexchange/isakmpd-20041012/attribute.c new file mode 100644 index 0000000..362805b --- /dev/null +++ b/keyexchange/isakmpd-20041012/attribute.c @@ -0,0 +1,112 @@ +/* $OpenBSD: attribute.c,v 1.11 2004/05/14 08:42:56 hshoexer Exp $ */ +/* $EOM: attribute.c,v 1.10 2000/02/20 19:58:36 niklas Exp $ */ + +/* + * Copyright (c) 1998, 1999 Niklas Hallqvist. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +/* + * This code was written under funding by Ericsson Radio Systems. + */ + +#include +#include + +#include "sysdep.h" + +#include "attribute.h" +#include "conf.h" +#include "log.h" +#include "isakmp.h" +#include "util.h" + +u_int8_t * +attribute_set_basic(u_int8_t *buf, u_int16_t type, u_int16_t value) +{ + SET_ISAKMP_ATTR_TYPE(buf, ISAKMP_ATTR_MAKE(1, type)); + SET_ISAKMP_ATTR_LENGTH_VALUE(buf, value); + return buf + ISAKMP_ATTR_VALUE_OFF; +} + +u_int8_t * +attribute_set_var(u_int8_t *buf, u_int16_t type, u_int8_t *value, + u_int16_t len) +{ + SET_ISAKMP_ATTR_TYPE(buf, ISAKMP_ATTR_MAKE(0, type)); + SET_ISAKMP_ATTR_LENGTH_VALUE(buf, len); + memcpy(buf + ISAKMP_ATTR_VALUE_OFF, value, len); + return buf + ISAKMP_ATTR_VALUE_OFF + len; +} + +/* + * Execute a function FUNC taking an attribute type, value, length and ARG + * as arguments for each attribute in the area of ISAKMP attributes located + * at BUF, sized SZ. If any invocation fails, the processing aborts with a + * -1 return value. If all goes well return zero. + */ +int +attribute_map(u_int8_t *buf, size_t sz, int (*func)(u_int16_t, u_int8_t *, + u_int16_t, void *), void *arg) +{ + u_int8_t *attr; + int fmt; + u_int16_t type; + u_int8_t *value; + u_int16_t len; + + for (attr = buf; attr < buf + sz; attr = value + len) { + if (attr + ISAKMP_ATTR_VALUE_OFF > buf + sz) + return -1; + type = GET_ISAKMP_ATTR_TYPE(attr); + fmt = ISAKMP_ATTR_FORMAT(type); + type = ISAKMP_ATTR_TYPE(type); + value = attr + (fmt ? ISAKMP_ATTR_LENGTH_VALUE_OFF + : ISAKMP_ATTR_VALUE_OFF); + len = (fmt ? ISAKMP_ATTR_LENGTH_VALUE_LEN + : GET_ISAKMP_ATTR_LENGTH_VALUE(attr)); + if (value + len > buf + sz) + return -1; + if (func(type, value, len, arg)) + return -1; + } + return 0; +} + +int +attribute_set_constant(char *section, char *tag, struct constant_map *map, + int attr_class, u_int8_t **attr) +{ + char *name; + int value; + + name = conf_get_str(section, tag); + if (!name) { + LOG_DBG((LOG_MISC, 70, + "attribute_set_constant: no %s in the %s section", tag, + section)); + return -1; + } + value = constant_value(map, name); + *attr = attribute_set_basic(*attr, attr_class, value); + return 0; +} -- cgit v1.2.3