summaryrefslogtreecommitdiff
path: root/radmsg.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2013-08-28 13:48:49 +0200
committerLinus Nordberg <linus@nordberg.se>2013-09-05 15:26:11 +0200
commit506b4eea8641e69ccf1ad35c185346299019afda (patch)
tree67e16baca9188012049e829fe6ba8e74d721ad9b /radmsg.c
parentb1a17ab16492b1ebb13e2d696b2f121a85fa71ba (diff)
Keep Proxy-State attributes in all replies to clients.
Closes RADSECPROXY-52.
Diffstat (limited to 'radmsg.c')
-rw-r--r--radmsg.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/radmsg.c b/radmsg.c
index 0a46e71..e422f90 100644
--- a/radmsg.c
+++ b/radmsg.c
@@ -62,6 +62,30 @@ int radmsg_add(struct radmsg *msg, struct tlv *attr) {
return list_push(msg->attrs, attr);
}
+/** Return a new list with all tlv's in \a msg of type \a type. The
+ * caller is responsible for freeing the list by calling \a
+ * list_free(). */
+struct list *
+radmsg_getalltype(const struct radmsg *msg, uint8_t type)
+{
+ struct list *list = NULL;
+ struct list_node *node = NULL;
+
+ if (!msg || !msg->attrs)
+ return NULL;
+ list = list_create();
+ if (!list)
+ return NULL;
+
+ for (node = list_first(msg->attrs); node; node = list_next(node))
+ if (((struct tlv *) node->data)->t == type)
+ if (list_push(list, node->data) != 1) {
+ list_free(list);
+ return NULL;
+ }
+ return list;
+}
+
/* returns first tlv of the given type */
struct tlv *radmsg_gettype(struct radmsg *msg, uint8_t type) {
struct list_node *node;
@@ -77,6 +101,33 @@ struct tlv *radmsg_gettype(struct radmsg *msg, uint8_t type) {
return NULL;
}
+/** Copy all attributes of type \a type from \a src to \a dst.
+ *
+ * If all attributes were copied successfully, the number of
+ * attributes copied is returned.
+ *
+ * If copying failed, a negative number is returned. The number
+ * returned is 0 minus the number of attributes successfully copied
+ * before the failure. */
+int radmsg_copy_attrs(struct radmsg *dst,
+ const struct radmsg *src,
+ uint8_t type)
+{
+ struct list_node *node = NULL;
+ struct list *list = radmsg_getalltype(src, type);
+ int n = 0;
+
+ for (node = list_first(list); node; node = list_next(node)) {
+ if (radmsg_add(dst, (struct tlv *) node->data) != 1) {
+ n = -n;
+ break;
+ }
+ n++;
+ }
+ list_free(list);
+ return n;
+}
+
int _checkmsgauth(unsigned char *rad, uint8_t *authattr, uint8_t *secret) {
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
static unsigned char first = 1;