summaryrefslogtreecommitdiff
path: root/src/lib/pol/cacep_simple_auth.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-21 10:56:35 +0000
committerSander Vrijders <sander.vrijders@intec.ugent.be>2017-02-21 10:56:35 +0000
commit91091367210ee204c4082a0da05eea3336674f19 (patch)
treecd0facb94108552b0b9e75619af4e42d77be1a17 /src/lib/pol/cacep_simple_auth.c
parentbf27d8fec3c8051f0518420b4b0ef2957147a887 (diff)
parentadc6766221327f99ab484d66f6f92050ec9e62d7 (diff)
downloadouroboros-91091367210ee204c4082a0da05eea3336674f19.tar.gz
ouroboros-91091367210ee204c4082a0da05eea3336674f19.zip
Merged in dstaesse/ouroboros/be-cacep (pull request #383)
lib: Exchange protocol info during CACEP
Diffstat (limited to 'src/lib/pol/cacep_simple_auth.c')
-rw-r--r--src/lib/pol/cacep_simple_auth.c52
1 files changed, 47 insertions, 5 deletions
diff --git a/src/lib/pol/cacep_simple_auth.c b/src/lib/pol/cacep_simple_auth.c
index 1e052f3d..b24a818b 100644
--- a/src/lib/pol/cacep_simple_auth.c
+++ b/src/lib/pol/cacep_simple_auth.c
@@ -26,6 +26,7 @@
#include <ouroboros/dev.h>
#include <ouroboros/errno.h>
+#include "cacep_proto.h"
#include "cacep_simple_auth.h"
#include <stdlib.h>
@@ -33,6 +34,7 @@
#include "cacep_simple_auth.pb-c.h"
typedef CacepSimpleAuthMsg cacep_simple_auth_msg_t;
+typedef CacepProtoMsg cacep_proto_msg_t;
#define BUF_SIZE 2048
@@ -65,6 +67,24 @@ static struct cacep_info * read_msg(int fd)
return NULL;
}
+ tmp->proto.protocol = strdup(msg->proto->protocol);
+ if (tmp->proto.protocol == NULL) {
+ free(tmp->name);
+ free(tmp);
+ cacep_simple_auth_msg__free_unpacked(msg, NULL);
+ return NULL;
+ }
+
+ tmp->proto.pref_version = msg->proto->pref_version;
+ tmp->proto.pref_syntax = code_to_syntax(msg->proto->pref_syntax);
+ if (tmp->proto.pref_syntax < 0) {
+ free(tmp->proto.protocol);
+ free(tmp->name);
+ free(tmp);
+ cacep_simple_auth_msg__free_unpacked(msg, NULL);
+ return NULL;
+ }
+
cacep_simple_auth_msg__free_unpacked(msg, NULL);
return tmp;
@@ -73,13 +93,21 @@ static struct cacep_info * read_msg(int fd)
static int send_msg(int fd,
const struct cacep_info * info)
{
- cacep_simple_auth_msg_t msg = CACEP_SIMPLE_AUTH_MSG__INIT;
- int ret = 0;
+ cacep_simple_auth_msg_t msg = CACEP_SIMPLE_AUTH_MSG__INIT;
+ cacep_proto_msg_t cmsg = CACEP_PROTO_MSG__INIT;
+ int ret = 0;
uint8_t * data = NULL;
- size_t len = 0;
+ size_t len = 0;
- msg.name = info->name;
- msg.addr = info->addr;
+ cmsg.protocol = info->proto.protocol;
+ cmsg.pref_version = info->proto.pref_version;
+ cmsg.pref_syntax = syntax_to_code(info->proto.pref_syntax);
+ if (cmsg.pref_syntax < 0)
+ return -1;
+
+ msg.proto = &cmsg;
+ msg.name = info->name;
+ msg.addr = info->addr;
len = cacep_simple_auth_msg__get_packed_size(&msg);
if (len == 0)
@@ -113,6 +141,13 @@ struct cacep_info * cacep_simple_auth_auth(int fd,
if (tmp == NULL)
return NULL;
+ if (strcmp(info->proto.protocol, tmp->proto.protocol) ||
+ info->proto.pref_version != tmp->proto.pref_version ||
+ info->proto.pref_syntax != tmp->proto.pref_syntax) {
+ free(tmp);
+ return NULL;
+ }
+
return tmp;
}
@@ -133,5 +168,12 @@ struct cacep_info * cacep_simple_auth_auth_wait(int fd,
return NULL;
}
+ if (strcmp(info->proto.protocol, tmp->proto.protocol) ||
+ info->proto.pref_version != tmp->proto.pref_version ||
+ info->proto.pref_syntax != tmp->proto.pref_syntax) {
+ free(tmp);
+ return NULL;
+ }
+
return tmp;
}