summaryrefslogtreecommitdiff
path: root/src/lib/pol/cacep_simple_auth.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-02-21 08:02:37 +0100
committerdimitri staessens <dimitri.staessens@ugent.be>2017-02-21 11:55:36 +0100
commitadc6766221327f99ab484d66f6f92050ec9e62d7 (patch)
treecd0facb94108552b0b9e75619af4e42d77be1a17 /src/lib/pol/cacep_simple_auth.c
parent354554c76cc2f9f30c7fd8edaeb2e3cc91c85332 (diff)
downloadouroboros-adc6766221327f99ab484d66f6f92050ec9e62d7.tar.gz
ouroboros-adc6766221327f99ab484d66f6f92050ec9e62d7.zip
lib: Exchange protocol info during CACEP
This exchanges a protocol name, a protocol version and concrete syntax for the protocol upon CACEP. For CDAP, only version 1 and GPB are supported. No lists for other supported versions or syntaxes are exchanged (but the proto file supports it). CACEP fails if there is a mismatch between the protocol names, version and syntax specified by the communicating parties.
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;
}