summaryrefslogtreecommitdiff
path: root/sbin/iked
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2010-12-22 17:53:55 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2010-12-22 17:53:55 +0000
commit2b0560695a4bc38017d76389cf8cedfc76a18b77 (patch)
treef08b87221fdb2513f230094ecffc5c1e04e3ed89 /sbin/iked
parentaf5cc54da27a9bfaf0facfe8695378904a6f1dda (diff)
move and rename util.c:print_id() to ikev2.c:ikev2_print_id() because
it is too specific to be in util.c. This will allow to link util.c into ikectl later without all the other dependencies of pritn_id().
Diffstat (limited to 'sbin/iked')
-rw-r--r--sbin/iked/ca.c8
-rw-r--r--sbin/iked/iked.h4
-rw-r--r--sbin/iked/ikev2.c97
-rw-r--r--sbin/iked/ikev2_pld.c4
-rw-r--r--sbin/iked/pfkey.c4
-rw-r--r--sbin/iked/util.c92
6 files changed, 105 insertions, 104 deletions
diff --git a/sbin/iked/ca.c b/sbin/iked/ca.c
index 29bafc7ed66..7d64f5b7c87 100644
--- a/sbin/iked/ca.c
+++ b/sbin/iked/ca.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ca.c,v 1.11 2010/09/30 14:25:54 mikeb Exp $ */
+/* $OpenBSD: ca.c,v 1.12 2010/12/22 17:53:54 reyk Exp $ */
/* $vantronix: ca.c,v 1.29 2010/06/02 12:22:58 reyk Exp $ */
/*
@@ -846,7 +846,7 @@ ca_validate_pubkey(struct iked *env, struct iked_static_id *id,
idp.id_type = id->id_type;
idp.id_offset = id->id_offset;
- if (print_id(&idp, idstr, sizeof(idstr)) == -1)
+ if (ikev2_print_id(&idp, idstr, sizeof(idstr)) == -1)
goto done;
if (len == 0) {
@@ -1014,7 +1014,7 @@ ca_x509_subjectaltname_cmp(X509 *cert, struct iked_static_id *id)
if (ca_x509_subjectaltname(cert, &sanid) != 0)
return (-1);
- print_id(&sanid, idstr, sizeof(idstr));
+ ikev2_print_id(&sanid, idstr, sizeof(idstr));
/* Compare id types, length and data */
if ((id->id_type != sanid.id_type) ||
@@ -1098,7 +1098,7 @@ ca_x509_subjectaltname(X509 *cert, struct iked_id *id)
}
id->id_offset = 0;
- print_id(id, idstr, sizeof(idstr));
+ ikev2_print_id(id, idstr, sizeof(idstr));
log_debug("%s: %s", __func__, idstr);
return (0);
diff --git a/sbin/iked/iked.h b/sbin/iked/iked.h
index c555ccb1823..b0fd72052c2 100644
--- a/sbin/iked/iked.h
+++ b/sbin/iked/iked.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: iked.h,v 1.24 2010/12/22 17:43:10 reyk Exp $ */
+/* $OpenBSD: iked.h,v 1.25 2010/12/22 17:53:54 reyk Exp $ */
/* $vantronix: iked.h,v 1.61 2010/06/03 07:57:33 reyk Exp $ */
/*
@@ -640,6 +640,7 @@ int ikev2_next_payload(struct ikev2_payload *, size_t,
void ikev2_disable_rekeying(struct iked *, struct iked_sa *);
void ikev2_rekey_sa(struct iked *, struct iked_spi *);
void ikev2_drop_sa(struct iked *, struct iked_spi *);
+int ikev2_print_id(struct iked_id *, char *, size_t);
/* ikev2_msg.c */
void ikev2_msg_cb(int, short, void *);
@@ -745,7 +746,6 @@ u_int32_t
const char *
print_host(struct sockaddr_storage *, char *, size_t);
char *get_string(u_int8_t *, size_t);
-int print_id(struct iked_id *, char *, size_t);
const char *
print_proto(u_int8_t);
int expand_string(char *, size_t, const char *, const char *);
diff --git a/sbin/iked/ikev2.c b/sbin/iked/ikev2.c
index bb568885f39..7cda085070e 100644
--- a/sbin/iked/ikev2.c
+++ b/sbin/iked/ikev2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ikev2.c,v 1.27 2010/12/22 16:22:27 mikeb Exp $ */
+/* $OpenBSD: ikev2.c,v 1.28 2010/12/22 17:53:54 reyk Exp $ */
/* $vantronix: ikev2.c,v 1.101 2010/06/03 07:57:33 reyk Exp $ */
/*
@@ -1001,7 +1001,7 @@ ikev2_policy2id(struct iked_static_id *polid, struct iked_id *id, int srcid)
break;
}
- if (print_id(id, idstr, sizeof(idstr)) == -1)
+ if (ikev2_print_id(id, idstr, sizeof(idstr)) == -1)
return (-1);
log_debug("%s: %s %s length %d", __func__,
@@ -3265,7 +3265,7 @@ ikev2_sa_tag(struct iked_sa *sa, struct iked_id *id)
goto fail;
}
- if (print_id(id, idstr, sizeof(idstr)) == -1) {
+ if (ikev2_print_id(id, idstr, sizeof(idstr)) == -1) {
log_debug("%s: invalid id", __func__);
goto fail;
}
@@ -3850,3 +3850,94 @@ done:
ibuf_release(buf);
return;
}
+
+int
+ikev2_print_id(struct iked_id *id, char *idstr, size_t idstrlen)
+{
+ u_int8_t buf[BUFSIZ], *ptr;
+ struct sockaddr_in *s4;
+ struct sockaddr_in6 *s6;
+ char *str;
+ ssize_t len;
+ int i;
+ const char *type;
+
+ bzero(buf, sizeof(buf));
+ bzero(idstr, idstrlen);
+
+ if (id->id_buf == NULL)
+ return (-1);
+
+ len = ibuf_size(id->id_buf);
+ ptr = ibuf_data(id->id_buf);
+
+ if (len <= id->id_offset)
+ return (-1);
+
+ len -= id->id_offset;
+ ptr += id->id_offset;
+
+ type = print_map(id->id_type, ikev2_id_map);
+
+ if (strlcpy(idstr, type, idstrlen) >= idstrlen ||
+ strlcat(idstr, "/", idstrlen) >= idstrlen)
+ return (-1);
+
+ idstr += strlen(idstr);
+ idstrlen -= strlen(idstr);
+
+ switch (id->id_type) {
+ case IKEV2_ID_IPV4:
+ s4 = (struct sockaddr_in *)buf;
+ s4->sin_family = AF_INET;
+ s4->sin_len = sizeof(*s4);
+ memcpy(&s4->sin_addr.s_addr, ptr, len);
+
+ if (print_host((struct sockaddr_storage *)s4,
+ idstr, idstrlen) == NULL)
+ return (-1);
+ break;
+ case IKEV2_ID_FQDN:
+ case IKEV2_ID_UFQDN:
+ if (len >= (ssize_t)sizeof(buf))
+ return (-1);
+
+ if ((str = get_string(ptr, len)) == NULL)
+ return (-1);
+
+ if (strlcpy(idstr, str, idstrlen) >= idstrlen) {
+ free(str);
+ return (-1);
+ }
+ free(str);
+ break;
+ case IKEV2_ID_IPV6:
+ s6 = (struct sockaddr_in6 *)buf;
+ s6->sin6_family = AF_INET6;
+ s6->sin6_len = sizeof(*s6);
+ memcpy(&s6->sin6_addr, ptr, len);
+
+ if (print_host((struct sockaddr_storage *)s6,
+ idstr, idstrlen) == NULL)
+ return (-1);
+ break;
+ case IKEV2_ID_ASN1_DN:
+ if ((str = ca_asn1_name(ptr, len)) == NULL)
+ return (-1);
+ if (strlcpy(idstr, str, idstrlen) >= idstrlen) {
+ free(str);
+ return (-1);
+ }
+ free(str);
+ break;
+ default:
+ /* XXX test */
+ for (i = 0; i < ((ssize_t)idstrlen - 1) && i < len; i++)
+ snprintf(idstr + i, idstrlen - i,
+ "%02x", ptr[i]);
+ break;
+ }
+
+ return (0);
+}
+
diff --git a/sbin/iked/ikev2_pld.c b/sbin/iked/ikev2_pld.c
index 316f016f7e1..0cff2f8af22 100644
--- a/sbin/iked/ikev2_pld.c
+++ b/sbin/iked/ikev2_pld.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ikev2_pld.c,v 1.17 2010/12/22 16:22:27 mikeb Exp $ */
+/* $OpenBSD: ikev2_pld.c,v 1.18 2010/12/22 17:53:54 reyk Exp $ */
/* $vantronix: ikev2.c,v 1.101 2010/06/03 07:57:33 reyk Exp $ */
/*
@@ -450,7 +450,7 @@ ikev2_pld_id(struct iked *env, struct ikev2_payload *pld,
if ((idb.id_buf = ibuf_new(ptr, len)) == NULL)
return (-1);
- if (print_id(&idb, idstr, sizeof(idstr)) == -1) {
+ if (ikev2_print_id(&idb, idstr, sizeof(idstr)) == -1) {
log_debug("%s: malformed id", __func__);
return (-1);
}
diff --git a/sbin/iked/pfkey.c b/sbin/iked/pfkey.c
index 7e90ea148bd..8eab69885e1 100644
--- a/sbin/iked/pfkey.c
+++ b/sbin/iked/pfkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkey.c,v 1.9 2010/12/22 16:22:27 mikeb Exp $ */
+/* $OpenBSD: pfkey.c,v 1.10 2010/12/22 17:53:54 reyk Exp $ */
/* $vantronix: pfkey.c,v 1.11 2010/06/03 07:57:33 reyk Exp $ */
/*
@@ -1160,7 +1160,7 @@ pfkey_id2ident(struct iked_id *id, u_int exttype)
bzero(&idstr, sizeof(idstr));
- if (print_id(id, idstr, sizeof(idstr)) == -1)
+ if (ikev2_print_id(id, idstr, sizeof(idstr)) == -1)
return (NULL);
len = ROUNDUP(strlen(idstr) + 1) + sizeof(*sa_id);
diff --git a/sbin/iked/util.c b/sbin/iked/util.c
index bb8d61ab028..863692ae0dd 100644
--- a/sbin/iked/util.c
+++ b/sbin/iked/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.9 2010/12/22 17:43:10 reyk Exp $ */
+/* $OpenBSD: util.c,v 1.10 2010/12/22 17:53:54 reyk Exp $ */
/* $vantronix: util.c,v 1.39 2010/06/02 12:22:58 reyk Exp $ */
/*
@@ -566,96 +566,6 @@ get_string(u_int8_t *ptr, size_t len)
return (str);
}
-int
-print_id(struct iked_id *id, char *idstr, size_t idstrlen)
-{
- u_int8_t buf[BUFSIZ], *ptr;
- struct sockaddr_in *s4;
- struct sockaddr_in6 *s6;
- char *str;
- ssize_t len;
- int i;
- const char *type;
-
- bzero(buf, sizeof(buf));
- bzero(idstr, idstrlen);
-
- if (id->id_buf == NULL)
- return (-1);
-
- len = ibuf_size(id->id_buf);
- ptr = ibuf_data(id->id_buf);
-
- if (len <= id->id_offset)
- return (-1);
-
- len -= id->id_offset;
- ptr += id->id_offset;
-
- type = print_map(id->id_type, ikev2_id_map);
-
- if (strlcpy(idstr, type, idstrlen) >= idstrlen ||
- strlcat(idstr, "/", idstrlen) >= idstrlen)
- return (-1);
-
- idstr += strlen(idstr);
- idstrlen -= strlen(idstr);
-
- switch (id->id_type) {
- case IKEV2_ID_IPV4:
- s4 = (struct sockaddr_in *)buf;
- s4->sin_family = AF_INET;
- s4->sin_len = sizeof(*s4);
- memcpy(&s4->sin_addr.s_addr, ptr, len);
-
- if (print_host((struct sockaddr_storage *)s4,
- idstr, idstrlen) == NULL)
- return (-1);
- break;
- case IKEV2_ID_FQDN:
- case IKEV2_ID_UFQDN:
- if (len >= (ssize_t)sizeof(buf))
- return (-1);
-
- if ((str = get_string(ptr, len)) == NULL)
- return (-1);
-
- if (strlcpy(idstr, str, idstrlen) >= idstrlen) {
- free(str);
- return (-1);
- }
- free(str);
- break;
- case IKEV2_ID_IPV6:
- s6 = (struct sockaddr_in6 *)buf;
- s6->sin6_family = AF_INET6;
- s6->sin6_len = sizeof(*s6);
- memcpy(&s6->sin6_addr, ptr, len);
-
- if (print_host((struct sockaddr_storage *)s6,
- idstr, idstrlen) == NULL)
- return (-1);
- break;
- case IKEV2_ID_ASN1_DN:
- if ((str = ca_asn1_name(ptr, len)) == NULL)
- return (-1);
- if (strlcpy(idstr, str, idstrlen) >= idstrlen) {
- free(str);
- return (-1);
- }
- free(str);
- break;
- default:
- /* XXX test */
- for (i = 0; i < ((ssize_t)idstrlen - 1) && i < len; i++)
- snprintf(idstr + i, idstrlen - i,
- "%02x", ptr[i]);
- break;
- }
-
- return (0);
-}
-
const char *
print_proto(u_int8_t proto)
{