[PATCH] Freeradius and C++

Pascal Séguy freeradius-devel@lists.cistron.nl
Wed, 3 Sep 2003 11:14:14 +0200


Hello,

This is a patch at the top of the CVS head that allows to write rlm modules
in C++.

The affected files are:

- Many .h in src/include.
  Added a :
        #if defined(__cplusplus)
            extern "C" {
        #endif
  at the top and a
        #if defined(__cplusplus)
             }
        #endif
  at the tail.

  Also done some stuff to override the use of the reserved C++ keyword
'operator' in libradius.h

- src/modules/rules.mak
    Added rules for .C and .cpp extensions


Pascal Séguy



--- /home/pascal/j/freeradius.orig/radiusd/src/include/conffile.h Tue Oct 29
23:55:25 2002
+++ conffile.h Tue Sep  2 15:29:05 2003
@@ -11,6 +11,10 @@
 #include <stddef.h>
 #include "token.h"

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 /*
  * Export the minimum amount of information about these structs
  */
@@ -73,4 +77,9 @@
 CONF_SECTION *cf_itemtosection(CONF_ITEM *item);
 CONF_ITEM *cf_pairtoitem(CONF_PAIR *cp);
 CONF_ITEM *cf_sectiontoitem(CONF_SECTION *cs);
+
+#if defined(__cplusplus)
+ }
+#endif
+
 #endif /* _CONFFILE_H */

--- /home/pascal/j/freeradius.orig/radiusd/src/include/libradius.h Wed Sep
3 10:14:53 2003
+++ libradius.h Wed Sep  3 10:16:45 2003
@@ -59,6 +59,11 @@
 #include <sha1.h>
 #include <md4.h>

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
+
 #define EAP_START               2

 #define AUTH_VECTOR_LEN  16
@@ -127,7 +132,12 @@
  int   type;
  int   length; /* of strvalue */
  uint32_t  lvalue;
+#if defined(__cplusplus)
+ // `operator' is a reserved keyword in C++
+ LRAD_TOKEN  vpoperator;
+#else
  LRAD_TOKEN  operator;
+#endif
  uint8_t   strvalue[MAX_STRING_LEN];
         ATTR_FLAGS              flags;
  struct value_pair *next;
@@ -228,7 +238,7 @@
 void  pairmove(VALUE_PAIR **to, VALUE_PAIR **from);
 void  pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, int attr);
 VALUE_PAIR *pairparsevalue(VALUE_PAIR *vp, const char *value);
-VALUE_PAIR *pairmake(const char *attribute, const char *value, int
operator);
+VALUE_PAIR *pairmake(const char *attribute, const char *value, int
vpoperator);
 VALUE_PAIR *pairread(char **ptr, LRAD_TOKEN *eol);
 LRAD_TOKEN userparse(char *buffer, VALUE_PAIR **first_pair);

@@ -300,5 +310,9 @@

 /* crypt wrapper from crypt.c */
 int lrad_crypt_check(const char *key, const char *salt);
+
+#if defined(__cplusplus)
+ }
+#endif

 #endif /*LIBRADIUS_H*/

--- /home/pascal/j/freeradius.orig/radiusd/src/include/md4.h Wed Sep  3
10:14:53 2003
+++ md4.h Wed Sep  3 10:16:45 2003
@@ -25,6 +25,10 @@
 #include <stdint.h>
 #endif

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 /* GLOBAL.H - RSAREF types and constants
  */

@@ -102,5 +106,9 @@
 void MD4Update PROTO_LIST
   ((MD4_CTX *, const unsigned char *, unsigned int));
 void MD4Final PROTO_LIST ((unsigned char [16], MD4_CTX *));
+
+#if defined(__cplusplus)
+ }
+#endif

 #endif /* _LRAD_MD4_H */

--- /home/pascal/j/freeradius.orig/radiusd/src/include/md5.h Wed Aug 20
21:22:06 2003
+++ md5.h Tue Sep  2 15:29:05 2003
@@ -17,6 +17,10 @@
 #include <stdint.h>
 #endif

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 /* GLOBAL.H - RSAREF types and constants
  */

@@ -95,4 +99,9 @@
 void MD5Update PROTO_LIST
   ((MD5_CTX *, const unsigned char *, unsigned int));
 void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
+
+#if defined(__cplusplus)
+ }
+#endif
+
 #endif /* _LRAD_MD5_H */

--- /home/pascal/j/freeradius.orig/radiusd/src/include/missing.h Fri Feb  1
20:39:58 2002
+++ missing.h Tue Sep  2 15:29:05 2003
@@ -8,6 +8,11 @@
  * Version: $Id: missing.h,v 1.20 2002/02/01 19:39:58 aland Exp $
  *
  */
+
+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 #ifndef HAVE_STRNCASECMP
 extern int strncasecmp(char *s1, char *s2, int n);
 #endif
@@ -79,6 +84,10 @@

 #ifndef INADDR_NONE
 #define INADDR_NONE     ((uint32_t) 0xffffffff)
+#endif
+
+#if defined(__cplusplus)
+ }
 #endif

 #endif /* _FR_MISSING_H */

--- /home/pascal/j/freeradius.orig/radiusd/src/include/modcall.h Sun Jul  1
21:18:18 2001
+++ modcall.h Tue Sep  2 15:29:05 2003
@@ -6,6 +6,10 @@

 #include "conffile.h" /* Need CONF_* definitions */

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 /*
  * For each authorize/authtype/etc, we have an ordered
  * tree of instances to call.  This data structure keeps track
@@ -32,3 +36,7 @@

 /* Free a tree returned by compile_modgroup or compile_modsingle */
 void modcallable_free(modcallable **pc);
+
+#if defined(__cplusplus)
+ }
+#endif

--- /home/pascal/j/freeradius.orig/radiusd/src/include/modpriv.h Thu Dec 21
07:31:21 2000
+++ modpriv.h Tue Sep  2 15:29:05 2003
@@ -6,6 +6,10 @@
 #include "modules.h"
 #include "ltdl.h"

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 /*
  * Keep track of which modules we've loaded.
  */
@@ -32,3 +36,7 @@
 } module_instance_t;

 module_instance_t *find_module_instance(const char *instname);
+
+#if defined(__cplusplus)
+ }
+#endif

--- /home/pascal/j/freeradius.orig/radiusd/src/include/modules.h Fri Jul  4
21:11:07 2003
+++ modules.h Tue Sep  2 15:29:05 2003
@@ -9,6 +9,10 @@
 #define RADIUS_MODULES_H
 #include "conffile.h"

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 typedef int (*packetmethod)(void *instance, REQUEST *request);

 enum {
@@ -61,5 +65,9 @@
 int module_pre_proxy(REQUEST *request);
 int module_post_proxy(REQUEST *request);
 int module_post_auth(int type, REQUEST *request);
+
+#if defined(__cplusplus)
+ }
+#endif

 #endif /* RADIUS_MODULES_H */

--- /home/pascal/j/freeradius.orig/radiusd/src/include/rad_assert.h Fri Aug
17 21:45:25 2001
+++ rad_assert.h Tue Sep  2 15:29:05 2003
@@ -22,6 +22,10 @@
  * Copyright 2000,2001  The FreeRADIUS server project
  */

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 extern void rad_assert_fail (const char *file, unsigned int line);

 #ifdef NDEBUG
@@ -30,6 +34,10 @@
  #define rad_assert(expr) \
   ((void) ((expr) ? 0 : \
    rad_assert_fail (__FILE__, __LINE__)))
+#endif
+
+#if defined(__cplusplus)
+ }
 #endif

 #endif

--- /home/pascal/j/freeradius.orig/radiusd/src/include/radius_snmp.h Fri Aug
16 22:15:22 2002
+++ radius_snmp.h Tue Sep  2 15:29:05 2003
@@ -17,6 +17,10 @@

 #include        "smux.h"

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 extern void radius_snmp_init(void);
 extern int smux_connect(void);
 extern int smux_read(void);
@@ -85,4 +89,7 @@

 extern rad_snmp_t rad_snmp;

+#if defined(__cplusplus)
+ }
+#endif
 #endif /* _RADIUS_SNMP_H */

--- /home/pascal/j/freeradius.orig/radiusd/src/include/radiusd.h Sun Aug 31
18:10:41 2003
+++ radiusd.h Tue Sep  2 15:29:05 2003
@@ -19,6 +19,10 @@
 #include <unistd.h>
 #endif

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 #if HAVE_PTHREAD_H
 #include <pthread.h>
 typedef pthread_t child_pid_t;
@@ -367,4 +371,8 @@
 int read_mainconfig(int reload);
 int free_mainconfig(void);
 CONF_SECTION *read_radius_conf_file(void); /* for radwho and friends. */
+
+#if defined(__cplusplus)
+ }
+#endif
 #endif /*RADIUSD_H*/

--- /home/pascal/j/freeradius.orig/radiusd/src/include/radutmp.h Fri Jun 20
19:50:10 2003
+++ radutmp.h Tue Sep  2 15:29:05 2003
@@ -7,6 +7,10 @@
 #ifndef _RADUTMP_H
 #define _RADUTMP_H

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 /*
  *      Types of connection.
  */
@@ -52,4 +56,7 @@
 #define RUT_NAMESIZE sizeof(((struct radutmp *) NULL)->login)
 #define RUT_SESSSIZE sizeof(((struct radutmp *) NULL)->session_id)

+#if defined(__cplusplus)
+ }
+#endif
 #endif /* _RADUTMP_H */

--- /home/pascal/j/freeradius.orig/radiusd/src/include/request_list.h Mon
Nov 20 22:51:47 2000
+++ request_list.h Tue Sep  2 15:29:06 2003
@@ -8,6 +8,10 @@
  *
  */

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 extern int rl_init(void);
 extern void rl_delete(REQUEST *request);
 extern void rl_add(REQUEST *request);
@@ -23,4 +27,7 @@

 extern int rl_walk(RL_WALK_FUNC walker, void *data);

+#if defined(__cplusplus)
+ }
+#endif
 #endif /* _REQUEST_LIST_H */

--- /home/pascal/j/freeradius.orig/radiusd/src/include/sha1.h Tue Jul  9
17:32:53 2002
+++ sha1.h Tue Sep  2 15:29:06 2003
@@ -5,6 +5,11 @@
  *  FreeRADIUS defines to ensure globally unique SHA1 function names,
  *  so that we don't pick up vendor-specific broken SHA1 libraries.
  */
+
+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 #define SHA1_CTX  librad_SHA1_CTX
 #define SHA1Transform  librad_SHA1Transform
 #define SHA1Init  librad_SHA1Init
@@ -22,4 +27,7 @@
 void SHA1Update(SHA1_CTX* context, const unsigned char* data, unsigned int
len);
 void SHA1Final(unsigned char digest[20], SHA1_CTX* context);

+#if defined(__cplusplus)
+ }
+#endif
 #endif /* _LRAD_SHA1_H */

--- /home/pascal/j/freeradius.orig/radiusd/src/include/smux.h Fri Dec  1
19:58:10 2000
+++ smux.h Tue Sep  2 15:29:06 2003
@@ -11,6 +11,10 @@
 #ifndef _SMUX_H
 #define _SMUX_H

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 #define SMUX_PORT_DEFAULT 199

 #define SMUXMAXPKTSIZE    1500
@@ -134,5 +138,9 @@
 int smux_str2oid (char *str, oid *my_oid, size_t *oid_len);
 oid *smux_oid_dup (oid *objid, size_t objid_len);
 int smux_register(void);
+
+#if defined(__cplusplus)
+ }
+#endif

 #endif /* _SMUX_H */

--- /home/pascal/j/freeradius.orig/radiusd/src/include/sysutmp.h Fri Jan 17
17:47:36 2003
+++ sysutmp.h Tue Sep  2 15:29:06 2003
@@ -82,6 +82,10 @@
 #define UTMP_FILE "/var/run/utmp"
 #define ut_name  ut_user

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 struct utmp {
  short ut_type;
  int ut_pid;
@@ -92,6 +96,9 @@
  char ut_host[UT_HOSTSIZE];
  long ut_addr;
 };
+#if defined(__cplusplus)
+ }
+#endif

 #endif /* HAVE_UTMP_H */


--- /home/pascal/j/freeradius.orig/radiusd/src/include/token.h Thu Nov 21
18:37:16 2002
+++ token.h Tue Sep  2 15:29:06 2003
@@ -23,6 +23,10 @@
  * Copyright 2001  The FreeRADIUS server project
  */

+#if defined(__cplusplus)
+ extern "C" {
+#endif
+
 typedef enum lrad_token_t {
   T_INVALID = 0,  /* invalid token */
   T_EOL,   /* end of line */
@@ -71,5 +75,9 @@
 int  getword (char **ptr, char *buf, int buflen);
 int  getbareword (char **ptr, char *buf, int buflen);
 LRAD_TOKEN gettoken(char **ptr, char *buf, int buflen);
+
+#if defined(__cplusplus)
+ }
+#endif

 #endif /* LRAD_TOKEN_H */

--- /home/pascal/j/freeradius.orig/radiusd/src/modules/rules.mak Tue Aug  6
18:11:39 2002
+++ rules.mak Tue Sep  2 15:09:30 2003
@@ -38,7 +38,11 @@
 #
 #######################################################################
 STATIC_OBJS += $(SRCS:.c=.o)
+STATIC_OBJS += $(SRCS:.C=.o)
+STATIC_OBJS += $(SRCS:.cpp=.o)
 DYNAMIC_OBJS += $(SRCS:.c=.lo)
+DYNAMIC_OBJS += $(SRCS:.C=.lo)
+DYNAMIC_OBJS += $(SRCS:.cpp=.lo)
 CFLAGS  += -I$(RLM_DIR)../../include

 #######################################################################
@@ -59,9 +63,21 @@
 %.o : %.c
  $(CC) $(CFLAGS) $(RLM_CFLAGS) -c $< -o $@

+%.o : %.C
+ g++ $(CFLAGS) $(RLM_CFLAGS) -c $< -o $@
+
+%.o : %.cpp
+ g++ $(CFLAGS) $(RLM_CFLAGS) -c $< -o $@
+
 %.lo : %.c
  $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) $(RLM_CFLAGS) -c $<

+%.lo : %.C
+ $(LIBTOOL) --mode=compile g++ $(CFLAGS) $(RLM_CFLAGS) -c $<
+
+%.lo : %.cpp
+ $(LIBTOOL) --mode=compile g++ $(CFLAGS) $(RLM_CFLAGS) -c $<
+
 ifneq ($(TARGET),)
 #######################################################################
 #