Merge branch 'libradsec-add-avp-2' into libradsec
authorLinus Nordberg <linus@nordberg.se>
Fri, 17 May 2013 08:50:11 +0000 (10:50 +0200)
committerLinus Nordberg <linus@nordberg.se>
Fri, 17 May 2013 08:50:11 +0000 (10:50 +0200)
Conflicts:
lib/Makefile.am

1  2 
lib/Makefile.am
lib/include/radsec/radsec.h
lib/packet.c

diff --combined lib/Makefile.am
@@@ -3,22 -3,21 +3,22 @@@ ACLOCAL_AMFLAGS = -I m
  
  # Shared library interface version, i.e. -version-info to Libtool,
  # expressed as three integers CURRENT:REVISION:AGE.
 -
 -# CURRENT is the version number of the current interface.  Increment
 -#       CURRENT when the library interface changes.
 -
 +#
 +# CURRENT is the version number of the current interface. Increment
 +# CURRENT when the library interface has changed or has been extended.
 +#
  # REVISION is the version number of the _implementation_ of the
 -#          CURRENT interface.  Set REVISION to 0 when CURRENT changes,
 -#          else increment.
 -
 +# CURRENT interface. Set REVISION to 0 when CURRENT changes, else
 +# increment.
 +#
  # AGE is the number of interfaces this library implements, i.e. how
 -#     many versions before CURRENT that are supported.  Increment AGE
 -#     when the library interface is _extended_.  Set AGE to 0 when the
 -#     library interface is _changed_.
 +# many versions before CURRENT that are supported. Increment AGE when
 +# the library interface is _extended_. Set AGE to 0 when the library
 +# interface is _changed_.
  
  
  SUBDIRS = radius radsecproxy include . examples
 +DIST_SUBDIRS = $(SUBDIRS) tests
  
  INCLUDES = -I$(srcdir)/include
  AM_CFLAGS = -Wall -Werror -g
@@@ -48,24 -47,8 +48,24 @@@ els
  libradsec_la_SOURCES += md5.c
  endif
  
 -EXTRA_DIST = HACKING LICENSE
 +libradsec_la_SOURCES += \
 +      compat.h \
 +      conn.h \
 +      debug.h \
 +      err.h \
 +      event.h \
 +      md5.h \
 +      packet.h \
 +      peer.h \
 +      radsec.h \
 +      tcp.h \
 +      tls.h \
 +      udp.h \
 +      util.h
 +
 +EXTRA_DIST = HACKING LICENSE libradsec.spec radsec.sym
 +AM_DISTCHECK_CONFIGURE_FLAGS = --enable-tls --enable-tls-psk
  
  libradsec_la_LIBADD = radsecproxy/libradsec-radsecproxy.la radius/libradsec-radius.la
- libradsec_la_LDFLAGS = -version-info 0:0:0 -export-symbols $(srcdir)/radsec.sym
 -libradsec_la_LDFLAGS = -version-info 1:0:1 -export-symbols radsec.sym
++libradsec_la_LDFLAGS = -version-info 1:0:1 -export-symbols $(srcdir)/radsec.sym
  libradsec_la_CFLAGS = $(AM_CFLAGS) -DHAVE_CONFIG_H -Werror # -DDEBUG -DDEBUG_LEVENT 
@@@ -1,8 -1,7 +1,8 @@@
  /** \file radsec.h
      \brief Public interface for libradsec.  */
  
 -/* See LICENSE for licensing information.  */
 +/* Copyright 2010-2013 NORDUnet A/S. All rights reserved.
 +   See LICENSE for licensing information. */
  
  #ifndef _RADSEC_RADSEC_H_
  #define _RADSEC_RADSEC_H_ 1
@@@ -322,7 -321,17 +322,17 @@@ int rs_packet_create_authn_request(stru
                                   const char *user_name,
                                   const char *user_pw);
  
- /*** Append \a tail to packet \a pkt.  */
+ /** Add a new attribute-value pair to \a pkt. */
+ int rs_packet_add_avp(struct rs_packet *pkt,
+                       unsigned int attr, unsigned int vendor,
+                       const void *data, size_t data_len);
+ /** Append a new attribute to packet \a pkt. Note that this function
+     encodes the attribute and therefore might require the secret
+     shared with the thought recipient to be set in pkt->rpkt. Note
+     also that this function marks \a pkt as already encoded and can
+     not be used on packets with non-encoded value-pairs already
+     added. */
  int
  rs_packet_append_avp(struct rs_packet *pkt,
                     unsigned int attribute, unsigned int vendor,
diff --combined lib/packet.c
@@@ -1,11 -1,10 +1,11 @@@
 -/* Copyright 2010, 2011 NORDUnet A/S. All rights reserved.
 -   See LICENSE for licensing information.  */
 +/* Copyright 2010-2013 NORDUnet A/S. All rights reserved.
 +   See LICENSE for licensing information. */
  
  #if defined HAVE_CONFIG_H
  #include <config.h>
  #endif
  
 +#include <stdlib.h>
  #include <assert.h>
  #include <radius/client.h>
  #include <event2/bufferevent.h>
@@@ -173,14 -172,16 +173,16 @@@ rs_packet_create_authn_request (struct 
  
    if (user_name)
      {
-       err = rs_packet_append_avp (pkt, PW_USER_NAME, 0, user_name, 0);
+       err = rs_packet_add_avp (pkt, PW_USER_NAME, 0, user_name,
+                                strlen (user_name));
        if (err)
        return err;
      }
  
    if (user_pw)
      {
-       err = rs_packet_append_avp (pkt, PW_USER_PASSWORD, 0, user_pw, 0);
+       err = rs_packet_add_avp (pkt, PW_USER_PASSWORD, 0, user_pw,
+                                strlen (user_pw));
        if (err)
        return err;
      }
@@@ -201,6 -202,45 +203,45 @@@ rs_packet_destroy (struct rs_packet *pk
  }
  
  int
+ rs_packet_add_avp (struct rs_packet *pkt,
+                    unsigned int attr, unsigned int vendor,
+                    const void *data, size_t data_len)
+ {
+   const DICT_ATTR *da;
+   VALUE_PAIR *vp;
+   int err;
+   assert (pkt);
+   assert (pkt->conn);
+   assert (pkt->conn->ctx);
+   da = nr_dict_attr_byvalue (attr, vendor);
+   if (da == NULL)
+     return rs_err_conn_push (pkt->conn, RSE_ATTR_TYPE_UNKNOWN,
+                              "nr_dict_attr_byvalue");
+   vp = rs_malloc (pkt->conn->ctx, sizeof(*vp));
+   if (vp == NULL)
+     return rs_err_conn_push (pkt->conn, RSE_NOMEM, NULL);
+   if (nr_vp_init (vp, da) == NULL)
+     {
+       nr_vp_free (&vp);
+       return rs_err_conn_push (pkt->conn, RSE_INTERNAL, NULL);
+     }
+   err = nr_vp_set_data (vp, data, data_len);
+   if (err < 0)
+     {
+       nr_vp_free (&vp);
+       return rs_err_conn_push (pkt->conn, -err, "nr_vp_set_data");
+     }
+   nr_vps_append (&pkt->rpkt->vps, vp);
+   return RSE_OK;
+ }
+ /* TODO: Rename rs_packet_append_avp, indicating that encoding is
+    being done. */
+ int
  rs_packet_append_avp (struct rs_packet *pkt,
                        unsigned int attr, unsigned int vendor,
                        const void *data, size_t data_len)
  
    da = nr_dict_attr_byvalue (attr, vendor);
    if (da == NULL)
 -    return RSE_ATTR_TYPE_UNKNOWN;
 +    return rs_err_conn_push (pkt->conn, RSE_ATTR_TYPE_UNKNOWN, __func__);
  
    err = nr_packet_attr_append (pkt->rpkt, NULL, da, data, data_len);
    if (err < 0)