From bca85674a83f94b9cfae0ebdc129bbaf645c8f7d Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Sun, 3 Oct 2010 11:53:10 +0200 Subject: [PATCH] Signed / unsigned fixes and function prototypes This reduces the number of warnings on compile. --- src/include/libradius.h | 16 +++---- src/include/radiusd.h | 15 +++--- src/lib/valuepair.c | 12 ++--- src/main/command.c | 3 -- src/main/listen.c | 2 +- src/main/radconf2xml.c | 2 +- src/main/radiusd.c | 2 +- src/main/radmin.c | 2 +- src/main/radwho.c | 2 +- src/main/realms.c | 56 ++++++++++++---------- src/main/valuepair.c | 16 +++---- src/main/xlat.c | 4 +- src/modules/rlm_eap/radeapclient.c | 11 +++-- src/modules/rlm_eap/types/rlm_eap_peap/peap.c | 4 +- .../rlm_eap/types/rlm_eap_tls/rlm_eap_tls.c | 8 ++-- src/modules/rlm_jradius/rlm_jradius.c | 4 +- src/tests/runtests.sh | 0 17 files changed, 85 insertions(+), 74 deletions(-) mode change 100644 => 100755 src/tests/runtests.sh diff --git a/src/include/libradius.h b/src/include/libradius.h index e7cdbc6..bbf5e79 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -137,9 +137,9 @@ typedef struct dict_value { typedef struct dict_vendor { int vendorpec; - int type; /* length of type data */ - int length; /* length of length data */ - int flags; + size_t type; /* length of type data */ + size_t length; /* length of length data */ + size_t flags; char name[1]; } DICT_VENDOR; @@ -161,7 +161,7 @@ typedef union value_pair_data { typedef struct value_pair { const char *name; unsigned int attribute; - int vendor; + unsigned int vendor; int type; size_t length; /* of data */ FR_TOKEN operator; @@ -337,16 +337,16 @@ VALUE_PAIR *paircreate_raw(int attr, int vendor, int type, VALUE_PAIR *); VALUE_PAIR *paircreate(int attr, int vendor, int type); void pairfree(VALUE_PAIR **); void pairbasicfree(VALUE_PAIR *pair); -VALUE_PAIR *pairfind(VALUE_PAIR *, int attr, int vendor); -void pairdelete(VALUE_PAIR **, int attr, int vendor); +VALUE_PAIR *pairfind(VALUE_PAIR *, unsigned int attr, unsigned int vendor); +void pairdelete(VALUE_PAIR **, unsigned int attr, unsigned int vendor); void pairadd(VALUE_PAIR **, VALUE_PAIR *); void pairreplace(VALUE_PAIR **first, VALUE_PAIR *add); int paircmp(VALUE_PAIR *check, VALUE_PAIR *data); VALUE_PAIR *paircopyvp(const VALUE_PAIR *vp); VALUE_PAIR *paircopy(VALUE_PAIR *vp); -VALUE_PAIR *paircopy2(VALUE_PAIR *vp, int attr, int vendor); +VALUE_PAIR *paircopy2(VALUE_PAIR *vp, unsigned int attr, unsigned int vendor); void pairmove(VALUE_PAIR **to, VALUE_PAIR **from); -void pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, int attr, int vendor); +void pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, unsigned int attr, unsigned int vendor); VALUE_PAIR *pairparsevalue(VALUE_PAIR *vp, const char *value); VALUE_PAIR *pairmake(const char *attribute, const char *value, int operator); VALUE_PAIR *pairread(const char **ptr, FR_TOKEN *eol); diff --git a/src/include/radiusd.h b/src/include/radiusd.h index 0c625b0..e26af57 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -498,7 +498,7 @@ extern int debug_flag; extern const char *radacct_dir; extern const char *radlog_dir; extern const char *radlib_dir; -extern const char *radius_dir; +extern char *radius_dir; extern const char *radius_libdir; extern uint32_t expiration_seconds; extern int log_stripped_names; @@ -618,10 +618,10 @@ int radius_exec_program(const char *, REQUEST *, int, int timestr_match(char *, time_t); /* valuepair.c */ -int paircompare_register(int attr, int otherattr, +int paircompare_register(unsigned int attr, int otherattr, RAD_COMPARE_FUNC func, void *instance); -void paircompare_unregister(int attr, RAD_COMPARE_FUNC func); +void paircompare_unregister(unsigned int attr, RAD_COMPARE_FUNC func); int paircompare(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check, VALUE_PAIR **reply); void pairxlatmove(REQUEST *, VALUE_PAIR **to, VALUE_PAIR **from); @@ -629,9 +629,9 @@ int radius_compare_vps(REQUEST *request, VALUE_PAIR *check, VALUE_PAIR *vp); int radius_callback_compare(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check, VALUE_PAIR *check_pairs, VALUE_PAIR **reply_pairs); -int radius_find_compare(int attribute); +int radius_find_compare(unsigned int attribute); VALUE_PAIR *radius_paircreate(REQUEST *request, VALUE_PAIR **vps, - int attribute, int vendor, int type); + unsigned int attribute, unsigned int vendor, int type); VALUE_PAIR *radius_pairmake(REQUEST *request, VALUE_PAIR **vps, const char *attribute, const char *value, int operator); @@ -677,7 +677,7 @@ void fr_suid_down_permanent(void); void listen_free(rad_listen_t **head); int listen_init(CONF_SECTION *cs, rad_listen_t **head); int proxy_new_listener(home_server *home, int src_port); -RADCLIENT *client_listener_find(const rad_listen_t *listener, +RADCLIENT *client_listener_find(rad_listen_t *listener, const fr_ipaddr_t *ipaddr, int src_port); #ifdef WITH_STATS @@ -696,6 +696,8 @@ int received_request(rad_listen_t *listener, RADCLIENT *client); REQUEST *received_proxy_response(RADIUS_PACKET *packet); int event_new_fd(rad_listen_t *listener); +void revive_home_server(void *ctx); +void mark_home_server_dead(home_server *home, struct timeval *when); /* evaluate.c */ int radius_evaluate_condition(REQUEST *request, int modreturn, int depth, @@ -703,4 +705,5 @@ int radius_evaluate_condition(REQUEST *request, int modreturn, int depth, int radius_update_attrlist(REQUEST *request, CONF_SECTION *cs, VALUE_PAIR *input_vps, const char *name); void radius_pairmove(REQUEST *request, VALUE_PAIR **to, VALUE_PAIR *from); +int radius_get_vp(REQUEST *request, const char *name, VALUE_PAIR **vp_p); #endif /*RADIUSD_H*/ diff --git a/src/lib/valuepair.c b/src/lib/valuepair.c index 15514ac..57fe9a2 100644 --- a/src/lib/valuepair.c +++ b/src/lib/valuepair.c @@ -222,7 +222,7 @@ void pairfree(VALUE_PAIR **pair_ptr) /* * Find the pair with the matching attribute */ -VALUE_PAIR * pairfind(VALUE_PAIR *first, int attr, int vendor) +VALUE_PAIR * pairfind(VALUE_PAIR *first, unsigned int attr, unsigned int vendor) { while (first) { if ((first->attribute == attr) && (first->vendor == vendor)) { @@ -238,7 +238,7 @@ VALUE_PAIR * pairfind(VALUE_PAIR *first, int attr, int vendor) /* * Delete the pair(s) with the matching attribute */ -void pairdelete(VALUE_PAIR **first, int attr, int vendor) +void pairdelete(VALUE_PAIR **first, unsigned int attr, unsigned int vendor) { VALUE_PAIR *i, *next; VALUE_PAIR **last = first; @@ -364,7 +364,7 @@ VALUE_PAIR *paircopyvp(const VALUE_PAIR *vp) /* * Copy just a certain type of pairs. */ -VALUE_PAIR *paircopy2(VALUE_PAIR *vp, int attr, int vendor) +VALUE_PAIR *paircopy2(VALUE_PAIR *vp, unsigned int attr, unsigned int vendor) { VALUE_PAIR *first, *n, **last; @@ -372,7 +372,7 @@ VALUE_PAIR *paircopy2(VALUE_PAIR *vp, int attr, int vendor) last = &first; while (vp) { - if ((attr >= 0) && + if ((attr > 0) && !((vp->attribute == attr) && (vp->vendor == vendor))) { vp = vp->next; continue; @@ -393,7 +393,7 @@ VALUE_PAIR *paircopy2(VALUE_PAIR *vp, int attr, int vendor) */ VALUE_PAIR *paircopy(VALUE_PAIR *vp) { - return paircopy2(vp, -1, 0); + return paircopy2(vp, 0, 0); } @@ -621,7 +621,7 @@ void pairmove(VALUE_PAIR **to, VALUE_PAIR **from) /* * Move one kind of attributes from one list to the other */ -void pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, int attr, int vendor) +void pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, unsigned int attr, unsigned int vendor) { VALUE_PAIR *to_tail, *i, *next; VALUE_PAIR *iprev = NULL; diff --git a/src/main/command.c b/src/main/command.c index 351d1e6..1eecdee 100644 --- a/src/main/command.c +++ b/src/main/command.c @@ -944,9 +944,6 @@ static int command_show_home_server_config(rad_listen_t *listener, int argc, cha return 1; } -extern void revive_home_server(void *ctx); -extern void mark_home_server_dead(home_server *home, struct timeval *when); - static int command_set_home_server_state(rad_listen_t *listener, int argc, char *argv[]) { int last; diff --git a/src/main/listen.c b/src/main/listen.c index 1f40ead..57c9607 100644 --- a/src/main/listen.c +++ b/src/main/listen.c @@ -84,7 +84,7 @@ static rad_listen_t *listen_alloc(RAD_LISTEN_TYPE type); /* * Find a per-socket client. */ -RADCLIENT *client_listener_find(const rad_listen_t *listener, +RADCLIENT *client_listener_find(rad_listen_t *listener, const fr_ipaddr_t *ipaddr, int src_port) { #ifdef WITH_DYNAMIC_CLIENTS diff --git a/src/main/radconf2xml.c b/src/main/radconf2xml.c index 8b20255..7e06c14 100644 --- a/src/main/radconf2xml.c +++ b/src/main/radconf2xml.c @@ -34,7 +34,7 @@ RCSID("$Id$") /* * For configuration file stuff. */ -const char *radius_dir = RADDBDIR; +char *radius_dir = RADDBDIR; const char *progname = "radconf2xml"; /* diff --git a/src/main/radiusd.c b/src/main/radiusd.c index 6815e43..cffb826 100644 --- a/src/main/radiusd.c +++ b/src/main/radiusd.c @@ -57,7 +57,7 @@ RCSID("$Id$") * Global variables. */ const char *progname = NULL; -const char *radius_dir = NULL; +char *radius_dir = NULL; const char *radacct_dir = NULL; const char *radlog_dir = NULL; const char *radlib_dir = NULL; diff --git a/src/main/radmin.c b/src/main/radmin.c index 8874d97..d67f50d 100644 --- a/src/main/radmin.c +++ b/src/main/radmin.c @@ -72,7 +72,7 @@ RCSID("$Id$") /* * For configuration file stuff. */ -const char *radius_dir = RADDBDIR; +char *radius_dir = RADDBDIR; const char *progname = "radmin"; /* diff --git a/src/main/radwho.c b/src/main/radwho.c index b90f2ac..fec34c9 100644 --- a/src/main/radwho.c +++ b/src/main/radwho.c @@ -67,7 +67,7 @@ const char *progname = "radwho"; const char *radlog_dir = NULL; const char *radutmp_file = NULL; -const char *radius_dir = NULL; +char *radius_dir = NULL; const char *radacct_dir = NULL; const char *radlib_dir = NULL; uint32_t myip = INADDR_ANY; diff --git a/src/main/realms.c b/src/main/realms.c index 7abf7f0..37ceb48 100644 --- a/src/main/realms.c +++ b/src/main/realms.c @@ -182,6 +182,36 @@ static int home_pool_name_cmp(const void *one, const void *two) } +static size_t xlat_cs(CONF_SECTION *cs, char *fmt, char *out, size_t outlen) + +{ + const char *value = NULL; + + /* + * Instance name + */ + if (strcmp(fmt, "instance") == 0) { + value = cf_section_name2(cs); + if (!value) { + *out = '\0'; + return 0; + } + } else { + CONF_PAIR *cp; + + cp = cf_pair_find(cs, fmt); + if (!cp || !(value = cf_pair_value(cp))) { + *out = '\0'; + return 0; + } + } + + strlcpy(out, value, outlen); + + return strlen(out); +} + + /* * Xlat for %{home_server:foo} */ @@ -189,9 +219,6 @@ static size_t xlat_home_server(UNUSED void *instance, REQUEST *request, char *fmt, char *out, size_t outlen, UNUSED RADIUS_ESCAPE_STRING func) { - const char *value = NULL; - CONF_PAIR *cp; - if (!fmt || !out || (outlen < 1)) return 0; if (!request || !request->home_server) { @@ -199,15 +226,7 @@ static size_t xlat_home_server(UNUSED void *instance, REQUEST *request, return 0; } - cp = cf_pair_find(request->home_server->cs, fmt); - if (!cp || !(value = cf_pair_value(cp))) { - *out = '\0'; - return 0; - } - - strlcpy(out, value, outlen); - - return strlen(out); + return xlat_cs(request->home_server->cs, fmt, out, outlen); } @@ -218,9 +237,6 @@ static size_t xlat_server_pool(UNUSED void *instance, REQUEST *request, char *fmt, char *out, size_t outlen, UNUSED RADIUS_ESCAPE_STRING func) { - const char *value = NULL; - CONF_PAIR *cp; - if (!fmt || !out || (outlen < 1)) return 0; if (!request || !request->home_pool) { @@ -228,15 +244,7 @@ static size_t xlat_server_pool(UNUSED void *instance, REQUEST *request, return 0; } - cp = cf_pair_find(request->home_pool->cs, fmt); - if (!cp || !(value = cf_pair_value(cp))) { - *out = '\0'; - return 0; - } - - strlcpy(out, value, outlen); - - return strlen(out); + return xlat_cs(request->home_pool->cs, fmt, out, outlen); } #endif diff --git a/src/main/valuepair.c b/src/main/valuepair.c index 843589f..50f4cb6 100644 --- a/src/main/valuepair.c +++ b/src/main/valuepair.c @@ -46,8 +46,8 @@ RCSID("$Id$") #endif struct cmp { - int attribute; - int otherattr; + unsigned int attribute; + unsigned int otherattr; void *instance; /* module instance */ RAD_COMPARE_FUNC compare; struct cmp *next; @@ -281,7 +281,7 @@ int radius_callback_compare(REQUEST *req, VALUE_PAIR *request, /* * Find a comparison function for two attributes. */ -int radius_find_compare(int attribute) +int radius_find_compare(unsigned int attribute) { struct cmp *c; @@ -298,7 +298,7 @@ int radius_find_compare(int attribute) /* * See what attribute we want to compare with. */ -static int otherattr(int attr) +static int otherattr(unsigned int attr) { struct cmp *c; @@ -323,7 +323,7 @@ static int otherattr(int attr) * For example, PW_GROUP in a check item needs to be compared * with PW_USER_NAME in the incoming request. */ -int paircompare_register(int attr, int compare_attr, RAD_COMPARE_FUNC fun, void *instance) +int paircompare_register(unsigned int attr, int compare_attr, RAD_COMPARE_FUNC fun, void *instance) { struct cmp *c; @@ -344,7 +344,7 @@ int paircompare_register(int attr, int compare_attr, RAD_COMPARE_FUNC fun, void /* * Unregister a function. */ -void paircompare_unregister(int attr, RAD_COMPARE_FUNC fun) +void paircompare_unregister(unsigned int attr, RAD_COMPARE_FUNC fun) { struct cmp *c, *last; @@ -435,7 +435,7 @@ int paircompare(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check, VALUE_PAIR try_again: if (other >= 0) { for (; auth_item != NULL; auth_item = auth_item->next) { - if (auth_item->attribute == other || other == 0) + if (auth_item->attribute == (unsigned int) other || other == 0) break; } } @@ -694,7 +694,7 @@ void pairxlatmove(REQUEST *req, VALUE_PAIR **to, VALUE_PAIR **from) * it causes the server to exit! */ VALUE_PAIR *radius_paircreate(REQUEST *request, VALUE_PAIR **vps, - int attribute, int vendor, int type) + unsigned int attribute, unsigned int vendor, int type) { VALUE_PAIR *vp; diff --git a/src/main/xlat.c b/src/main/xlat.c index e53300a..e60129c 100644 --- a/src/main/xlat.c +++ b/src/main/xlat.c @@ -56,7 +56,7 @@ static const char * const internal_xlat[] = {"check", #if REQUEST_MAX_REGEX > 8 #error Please fix the following line #endif -static const int xlat_inst[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; /* up to 8 for regex */ +static int xlat_inst[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; /* up to 8 for regex */ /* @@ -843,7 +843,7 @@ static int decode_attribute(const char **from, char **to, int freespace, expand2 = TRUE; } else if ((p[0] == '"') || p[0] == '\'') { - getstring(&p, l, strlen(l)); + getstring((const char **) &p, l, strlen(l)); } else { l = p; diff --git a/src/modules/rlm_eap/radeapclient.c b/src/modules/rlm_eap/radeapclient.c index 4581feb..9bcd20e 100644 --- a/src/modules/rlm_eap/radeapclient.c +++ b/src/modules/rlm_eap/radeapclient.c @@ -51,7 +51,7 @@ static int filedone = 0; static int totalapp = 0; static int totaldeny = 0; static char filesecret[256]; -const char *radius_dir = RADDBDIR; +char *radius_dir = NULL; const char *progname = "radeapclient"; /* fr_randctx randctx; */ @@ -179,13 +179,13 @@ static void debug_packet(RADIUS_PACKET *packet, int direction) printf("%s %s packet %s host %s port %d, id=%d, length=%d\n", received, fr_packet_codes[packet->code], from, inet_ntop(ip->af, &ip->ipaddr, buffer, sizeof(buffer)), - port, packet->id, packet->data_len); + port, packet->id, (int) packet->data_len); } else { printf("%s packet %s host %s port %d code=%d, id=%d, length=%d\n", received, from, inet_ntop(ip->af, &ip->ipaddr, buffer, sizeof(buffer)), port, - packet->code, packet->id, packet->data_len); + packet->code, packet->id, (int) packet->data_len); } for (vp = packet->vps; vp != NULL; vp = vp->next) { @@ -989,7 +989,7 @@ int main(int argc, char **argv) count = atoi(optarg); break; case 'd': - radius_dir = optarg; + radius_dir = strdup(optarg); break; case 'f': filename = optarg; @@ -1077,6 +1077,8 @@ int main(int argc, char **argv) usage(); } + if (!radius_dir) radius_dir = strdup(RADDBDIR); + if (dict_init(radius_dir, RADIUS_DICTIONARY) < 0) { fr_perror("radclient"); return 1; @@ -1192,6 +1194,7 @@ int main(int argc, char **argv) sendrecv_eap(req); } + free(radius_dir); if(do_summary) { printf("\n\t Total approved auths: %d\n", totalapp); printf("\t Total denied auths: %d\n", totaldeny); diff --git a/src/modules/rlm_eap/types/rlm_eap_peap/peap.c b/src/modules/rlm_eap/types/rlm_eap_peap/peap.c index 982c8a8..9ef8836 100644 --- a/src/modules/rlm_eap/types/rlm_eap_peap/peap.c +++ b/src/modules/rlm_eap/types/rlm_eap_peap/peap.c @@ -612,13 +612,13 @@ static const char *peap_state(peap_tunnel_t *t) return "?"; } -static void print_tunneled_data(uint8_t *data, size_t data_len) +static void print_tunneled_data(const uint8_t *data, size_t data_len) { size_t i; if ((debug_flag > 2) && fr_log_fp) { for (i = 0; i < data_len; i++) { - if ((i & 0x0f) == 0) fprintf(fr_log_fp, " PEAP tunnel data in %04x: ", i); + if ((i & 0x0f) == 0) fprintf(fr_log_fp, " PEAP tunnel data in %02x: ", (int) i); fprintf(fr_log_fp, "%02x ", data[i]); diff --git a/src/modules/rlm_eap/types/rlm_eap_tls/rlm_eap_tls.c b/src/modules/rlm_eap/types/rlm_eap_tls/rlm_eap_tls.c index e041c4c..8f49899 100644 --- a/src/modules/rlm_eap/types/rlm_eap_tls/rlm_eap_tls.c +++ b/src/modules/rlm_eap/types/rlm_eap_tls/rlm_eap_tls.c @@ -808,17 +808,17 @@ static SSL_CTX *init_tls_ctx(EAP_TLS_CONF *conf) * information. */ if (eaptls_handle_idx < 0) { - eaptls_handle_idx = SSL_get_ex_new_index(0, "eaptls_handle_idx", - NULL, NULL, NULL); + eaptls_handle_idx = SSL_get_ex_new_index(0, &eaptls_handle_idx, + NULL, NULL, NULL); } if (eaptls_conf_idx < 0) { - eaptls_conf_idx = SSL_get_ex_new_index(0, "eaptls_conf_idx", + eaptls_conf_idx = SSL_get_ex_new_index(0, &eaptls_conf_idx, NULL, NULL, NULL); } if (eaptls_session_idx < 0) { - eaptls_session_idx = SSL_get_ex_new_index(0, "eaptls_session_idx", + eaptls_session_idx = SSL_get_ex_new_index(0, &eaptls_session_idx, NULL, NULL, eaptls_session_free); } diff --git a/src/modules/rlm_jradius/rlm_jradius.c b/src/modules/rlm_jradius/rlm_jradius.c index bd8179e..67acc30 100644 --- a/src/modules/rlm_jradius/rlm_jradius.c +++ b/src/modules/rlm_jradius/rlm_jradius.c @@ -170,7 +170,7 @@ sock_read(JRADIUS * inst, JRSOCK *jrsock, uint8_t *b, size_t blen) { } static int -sock_write(JRADIUS * inst, JRSOCK *jrsock, char *b, size_t blen) { +sock_write(JRADIUS * inst, JRSOCK *jrsock, uint8_t *b, size_t blen) { int fd = jrsock->con.sock; int timeout = inst->write_timeout; struct timeval tv; @@ -636,7 +636,7 @@ static int pack_vps(byte_array * ba, VALUE_PAIR * vps) for (vp = vps; vp != NULL; vp = vp->next) { - radlog(L_DBG, LOG_PREFIX "packing attribute %s (type: %d; len: %d)", vp->name, vp->attribute, vp->length); + radlog(L_DBG, LOG_PREFIX "packing attribute %s (type: %d; len: %u)", vp->name, vp->attribute, (unsigned int) vp->length); i = vp->attribute; /* element is int, not uint32_t */ if (pack_uint32(ba, i) == -1) return -1; diff --git a/src/tests/runtests.sh b/src/tests/runtests.sh old mode 100644 new mode 100755 -- 2.1.4