fr_strerror -> fr_strerror()
authorAlan T. DeKok <aland@freeradius.org>
Tue, 26 Aug 2008 09:16:37 +0000 (11:16 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 26 Aug 2008 09:16:37 +0000 (11:16 +0200)
This is in preparation for (perhaps) making the logging
functions thread-safe.

28 files changed:
src/include/libradius.h
src/lib/dhcp.c
src/lib/dict.c
src/lib/log.c
src/lib/valuepair.c
src/main/client.c
src/main/dhcpd.c
src/main/evaluate.c
src/main/event.c
src/main/files.c
src/main/listen.c
src/main/mainconfig.c
src/main/modcall.c
src/main/modules.c
src/main/radclient.c
src/main/radsniff.c
src/main/vmps.c
src/modules/rlm_acct_unique/rlm_acct_unique.c
src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c
src/modules/rlm_eap/libeap/mppe_keys.c
src/modules/rlm_eap/types/rlm_eap_ikev2/rlm_eap_ikev2.c
src/modules/rlm_eap/types/rlm_eap_sim/rlm_eap_sim.c
src/modules/rlm_ldap/rlm_ldap.c
src/modules/rlm_mschap/rlm_mschap.c
src/modules/rlm_policy/evaluate.c
src/modules/rlm_sql/rlm_sql.c
src/modules/rlm_sql/sql.c
src/modules/rlm_sql_log/rlm_sql_log.c

index 24b95a4..2cebfb0 100644 (file)
@@ -354,7 +354,7 @@ void                fr_perror(const char *, ...)
                __attribute__ ((format (printf, 1, 2)))
 #endif
 ;
-extern char    fr_strerror[];
+extern const char *fr_strerror(void);
 extern int     fr_dns_lookups; /* 0 = no dns lookups */
 extern int     fr_debug_flag;  /* 0 = no debugging information */
 extern int     fr_max_attributes; /* per incoming packet */
index 3e9141c..c96b24d 100644 (file)
@@ -330,7 +330,7 @@ int fr_dhcp_decode(RADIUS_PACKET *packet)
        for (i = 0; i < 14; i++) {
                vp = pairmake(dhcp_header_names[i], NULL, T_OP_EQ);
                if (!vp) {
-                       fprintf(stderr, "Parse error %s\n", fr_strerror);
+                       fprintf(stderr, "Parse error %s\n", fr_strerror());
                        pairfree(&head);
                        return -1;
                }
@@ -487,7 +487,7 @@ int fr_dhcp_decode(RADIUS_PACKET *packet)
                        vp = pairmake(da->name, NULL, T_OP_EQ);
                        if (!vp) {
                                fprintf(stderr, "Cannot build attribute %s\n",
-                                       fr_strerror);
+                                       fr_strerror());
                                pairfree(&head);
                                return -1;
                        }
@@ -529,7 +529,7 @@ int fr_dhcp_decode(RADIUS_PACKET *packet)
                                raw:
                                        vp = pairmake(da->name, NULL, T_OP_EQ);
                                        if (!vp) {
-                                               fprintf(stderr, "Cannot build attribute %s\n", fr_strerror);
+                                               fprintf(stderr, "Cannot build attribute %s\n", fr_strerror());
                                                pairfree(&head);
                                                return -1;
                                        }
@@ -897,7 +897,7 @@ int fr_dhcp_encode(RADIUS_PACKET *packet, RADIUS_PACKET *original)
                for (i = 0; i < 14; i++) {
                        vp = pairmake(dhcp_header_names[i], NULL, T_OP_EQ);
                        if (!vp) {
-                               fprintf(stderr, "Parse error %s\n", fr_strerror);
+                               fprintf(stderr, "Parse error %s\n", fr_strerror());
                                return -1;
                        }
                        
index 54eef6a..dd5eb80 100644 (file)
@@ -1008,7 +1008,7 @@ static int process_attribute(const char* fn, const int line,
         */
        if (dict_addattr(argv[0], vendor, type, value, flags) < 0) {
                fr_strerror_printf("dict_init: %s[%d]: %s",
-                          fn, line, fr_strerror);
+                          fn, line, fr_strerror());
                return -1;
        }
 
@@ -1046,7 +1046,7 @@ static int process_value(const char* fn, const int line, char **argv,
 
        if (dict_addvalue(argv[1], argv[0], value) < 0) {
                fr_strerror_printf("dict_init: %s[%d]: %s",
-                          fn, line, fr_strerror);
+                          fn, line, fr_strerror());
                return -1;
        }
 
@@ -1166,7 +1166,7 @@ static int process_vendor(const char* fn, const int line, char **argv,
        /* Create a new VENDOR entry for the list */
        if (dict_addvendor(argv[0], value) < 0) {
                fr_strerror_printf("dict_init: %s[%d]: %s",
-                          fn, line, fr_strerror);
+                          fn, line, fr_strerror());
                return -1;
        }
 
index bc7b561..8e8afa9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * log.c       Functions in the library call radlib_log() which
- *             sets a global error string "char *fr_strerror".
+ *             does internal logging.
  *
  * Version:    $Id$
  *
@@ -26,7 +26,11 @@ RCSID("$Id$")
 
 #include <freeradius-devel/libradius.h>
 
-char fr_strerror[1024];
+
+#define FR_STRERROR_BUFSIZE (1024)
+
+static char fr_strerror_buffer[FR_STRERROR_BUFSIZE];
+
 
 /*
  *  Do logging to a static buffer.  Note that we MIGHT be asked
@@ -38,14 +42,16 @@ char fr_strerror[1024];
 void fr_strerror_printf(const char *fmt, ...)
 {
        va_list ap;
-       char my_errstr[sizeof(fr_strerror)];
-
        va_start(ap, fmt);
-       vsnprintf(my_errstr, sizeof(my_errstr), fmt, ap);
-       strcpy(fr_strerror, my_errstr);
+       vsnprintf(fr_strerror_buffer, sizeof(fr_strerror_buffer), fmt, ap);
        va_end(ap);
 }
 
+const char *fr_strerror(void)
+{
+       return fr_strerror_buffer;
+}
+
 void fr_perror(const char *fmt, ...)
 {
        va_list ap;
@@ -54,6 +60,6 @@ void fr_perror(const char *fmt, ...)
        vfprintf(stderr, fmt, ap);
        if (strchr(fmt, ':') == NULL)
                fprintf(stderr, ": ");
-       fprintf(stderr, "%s\n", fr_strerror);
+       fprintf(stderr, "%s\n", fr_strerror());
        va_end(ap);
 }
index c790845..da9432f 100644 (file)
@@ -1049,7 +1049,7 @@ VALUE_PAIR *pairparsevalue(VALUE_PAIR *vp, const char *value)
 
                        if (ascend_parse_filter(vp) < 0 ) {
                                fr_strerror_printf("failed to parse Ascend binary attribute: %s",
-                                          fr_strerror);
+                                          fr_strerror());
                                return NULL;
                        }
                        break;
index a7defce..1f2a5be 100644 (file)
@@ -522,7 +522,7 @@ static RADCLIENT *client_parse(CONF_SECTION *cs, int in_server)
                        client_free(c);
                        cf_log_err(cf_sectiontoitem(cs),
                                   "Failed to look up hostname %s: %s",
-                                  name2, fr_strerror);
+                                  name2, fr_strerror());
                        return NULL;
                }
 
index 5a5ad83..8d78b2c 100644 (file)
@@ -121,7 +121,7 @@ static int dhcp_socket_recv(rad_listen_t *listener,
 
        packet = fr_dhcp_recv(listener->fd);
        if (!packet) {
-               radlog(L_ERR, "%s", fr_strerror);
+               radlog(L_ERR, "%s", fr_strerror());
                return 0;
        }
 
index af4273f..85d3b8c 100644 (file)
@@ -350,7 +350,7 @@ static int radius_do_cmp(REQUEST *request, int *presult,
                        memcpy(&myvp, vp, sizeof(myvp));
                        if (!pairparsevalue(&myvp, pright)) {
                                RDEBUG2("Failed parsing \"%s\": %s",
-                                      pright, fr_strerror);
+                                      pright, fr_strerror());
                                return FALSE;
                        }
 
@@ -1217,7 +1217,7 @@ int radius_update_attrlist(REQUEST *request, CONF_SECTION *cs,
 
                        if (!pairparsevalue(vp, value)) {
                                RDEBUG2("ERROR: Failed parsing value \"%s\" for attribute %s: %s",
-                                      value, vp->name, fr_strerror);
+                                      value, vp->name, fr_strerror());
                                pairfree(&newlist);
                                return RLM_MODULE_FAIL;
                        }
index cceaf40..abd95eb 100644 (file)
@@ -1117,7 +1117,7 @@ static int request_pre_handler(REQUEST *request)
        }
 
        if (rcode < 0) {
-               radlog(L_ERR, "%s Dropping packet without response.", fr_strerror);
+               radlog(L_ERR, "%s Dropping packet without response.", fr_strerror());
                request->child_state = REQUEST_DONE;
                return 0;
        }
index 5e39e49..a0ee249 100644 (file)
@@ -194,7 +194,7 @@ parse_again:
                                pairlist_free(&pl);
                                radlog(L_ERR|L_CONS,
                                "%s[%d]: Parse error (check) for entry %s: %s",
-                                       file, lineno, entry, fr_strerror);
+                                       file, lineno, entry, fr_strerror());
                                fclose(fp);
                                return -1;
                        } else if (parsecode == T_COMMA) {
@@ -226,7 +226,7 @@ parse_again:
                                        pairlist_free(&pl);
                                        radlog(L_ERR|L_CONS,
                                               "%s[%d]: Parse error (reply) for entry %s: %s",
-                                              file, lineno, entry, fr_strerror);
+                                              file, lineno, entry, fr_strerror());
                                        fclose(fp);
                                        return -1;
                                }
index 7d63550..094477e 100644 (file)
@@ -689,7 +689,7 @@ static int stats_socket_recv(rad_listen_t *listener,
        packet = rad_recv(listener->fd, 1); /* require message authenticator */
        if (!packet) {
                RAD_STATS_TYPE_INC(listener, total_malformed_requests);
-               DEBUG("%s", fr_strerror);
+               DEBUG("%s", fr_strerror());
                return 0;
        }
 
@@ -794,7 +794,7 @@ static int auth_socket_recv(rad_listen_t *listener,
        packet = rad_recv(listener->fd, client->message_authenticator);
        if (!packet) {
                RAD_STATS_TYPE_INC(listener, total_malformed_requests);
-               DEBUG("%s", fr_strerror);
+               DEBUG("%s", fr_strerror());
                return 0;
        }
 
@@ -896,7 +896,7 @@ static int acct_socket_recv(rad_listen_t *listener,
        packet = rad_recv(listener->fd, 0);
        if (!packet) {
                RAD_STATS_TYPE_INC(listener, total_malformed_requests);
-               radlog(L_ERR, "%s", fr_strerror);
+               radlog(L_ERR, "%s", fr_strerror());
                return 0;
        }
 
@@ -929,7 +929,7 @@ static int proxy_socket_recv(rad_listen_t *listener,
 
        packet = rad_recv(listener->fd, 0);
        if (!packet) {
-               radlog(L_ERR, "%s", fr_strerror);
+               radlog(L_ERR, "%s", fr_strerror());
                return 0;
        }
 
index aec1551..c5b4b5e 100644 (file)
@@ -731,7 +731,7 @@ int read_mainconfig(int reload)
        DEBUG2("including dictionary file %s/%s", p, RADIUS_DICTIONARY);
        if (dict_init(p, RADIUS_DICTIONARY) != 0) {
                radlog(L_ERR, "Errors reading dictionary: %s",
-                               fr_strerror);
+                               fr_strerror());
                return -1;
        }
 
index 0c8f20e..6be5652 100644 (file)
@@ -1224,7 +1224,7 @@ static modcallable *do_compile_modupdate(modcallable *parent,
                vp = cf_pairtovp(cp);
                if (!vp) {
                        pairfree(&head);
-                       cf_log_err(ci, "ERROR: %s", fr_strerror);
+                       cf_log_err(ci, "ERROR: %s", fr_strerror());
                        return NULL;
                }
 
index 2a97c2c..d229a99 100644 (file)
@@ -589,7 +589,7 @@ static int define_type(const DICT_ATTR *dattr, const char *name)
        } while (dict_valbyattr(dattr->attr, value));
 
        if (dict_addvalue(name, dattr->name, value) < 0) {
-               radlog(L_ERR, "%s", fr_strerror);
+               radlog(L_ERR, "%s", fr_strerror());
                return 0;
        }
 
index f486508..0899fed 100644 (file)
@@ -680,7 +680,7 @@ static int send_one_packet(radclient_t *radclient)
         */
        if (rad_send(radclient->request, NULL, secret) < 0) {
                fprintf(stderr, "radclient: Failed to send packet for ID %d: %s\n",
-                       radclient->request->id, fr_strerror);
+                       radclient->request->id, fr_strerror());
        }
 
        if (fr_debug_flag > 2) print_hex(radclient->request);
@@ -725,7 +725,7 @@ static int recv_one_packet(int wait_time)
        reply = fr_packet_list_recv(pl, &set);
        if (!reply) {
                fprintf(stderr, "radclient: received bad packet: %s\n",
-                       fr_strerror);
+                       fr_strerror());
                return -1;      /* bad packet */
        }
 
@@ -1073,7 +1073,7 @@ int main(int argc, char **argv)
        }
        sockfd = fr_socket(&client_ipaddr, client_port);
        if (sockfd < 0) {
-               fprintf(stderr, "radclient: socket: %s\n", fr_strerror);
+               fprintf(stderr, "radclient: socket: %s\n", fr_strerror());
                exit(1);
        }
 
index 81348d4..db7dc27 100644 (file)
@@ -287,7 +287,7 @@ int main(int argc, char *argv[])
        if (radius_filter) {
                parsecode = userparse(radius_filter, &filter_vps);
                if (parsecode == T_OP_INVALID) {
-                       fprintf(stderr, "radsniff: Invalid RADIUS filter \"%s\": %s\n", radius_filter, fr_strerror);
+                       fprintf(stderr, "radsniff: Invalid RADIUS filter \"%s\": %s\n", radius_filter, fr_strerror());
                        exit(1);
                }
                if (!filter_vps) {
index 3fd4e6c..f968e98 100644 (file)
@@ -47,7 +47,7 @@ int vqp_socket_recv(rad_listen_t *listener,
 
        packet = vqp_recv(listener->fd);
        if (!packet) {
-               radlog(L_ERR, "%s", fr_strerror);
+               radlog(L_ERR, "%s", fr_strerror());
                return 0;
        }
 
@@ -87,7 +87,7 @@ int vqp_socket_send(rad_listen_t *listener, REQUEST *request)
        rad_assert(listener->send == vqp_socket_send);
 
        if (vqp_encode(request->reply, request->packet) < 0) {
-               DEBUG2("Failed encoding packet: %s\n", fr_strerror);
+               DEBUG2("Failed encoding packet: %s\n", fr_strerror());
                return -1;
        }
 
index 7f394c9..c2f0524 100644 (file)
@@ -242,7 +242,7 @@ static int add_unique_id(void *instance, REQUEST *request)
 
        vp = pairmake("Acct-Unique-Session-Id", buffer, 0);
        if (!vp) {
-               radlog(L_ERR, "%s", fr_strerror);
+               radlog(L_ERR, "%s", fr_strerror());
                return RLM_MODULE_FAIL;
        }
 
index 1710382..fdf0121 100644 (file)
@@ -395,7 +395,7 @@ do_again:
                DEBUG2("%s: Changed value for attribute %s from '%s' to '%s'", data->name,
                                data->attribute, attr_vp->vp_strvalue, new_str);
                if (pairparsevalue(attr_vp, new_str) == NULL) {
-                       DEBUG2("%s: Could not write value '%s' into attribute %s: %s", data->name, new_str, data->attribute, fr_strerror);
+                       DEBUG2("%s: Could not write value '%s' into attribute %s: %s", data->name, new_str, data->attribute, fr_strerror());
                        return ret;
                }
 
index 2590bfa..4c0b841 100644 (file)
@@ -39,7 +39,7 @@ static void add_reply(VALUE_PAIR** vp,
        if (!reply_attr) {
                DEBUG("rlm_eap_tls: "
                      "add_reply failed to create attribute %s: %s\n",
-                     name, fr_strerror);
+                     name, fr_strerror());
                return;
        }
 
index fbd9f13..f347016 100644 (file)
@@ -60,7 +60,7 @@ static void add_reply(VALUE_PAIR** vp,
        VALUE_PAIR *reply_attr;
        reply_attr = pairmake(name, "", T_OP_EQ);
        if (!reply_attr) {
-               radlog(L_INFO, IKEv2_LOG_PREFIX "add_reply failed to create attribute %s: %s", name, fr_strerror);
+               radlog(L_INFO, IKEv2_LOG_PREFIX "add_reply failed to create attribute %s: %s", name, fr_strerror());
                return;
        }
 
index 08be321..908d5b2 100644 (file)
@@ -56,7 +56,7 @@ static void add_reply(VALUE_PAIR** vp,
        if (!reply_attr) {
                DEBUG("rlm_eap_sim: "
                      "add_reply failed to create attribute %s: %s\n",
-                     name, fr_strerror);
+                     name, fr_strerror());
                return;
        }
 
index 52abaa5..c87c6ae 100644 (file)
@@ -2650,7 +2650,7 @@ static VALUE_PAIR *ldap_pairget(LDAP *ld, LDAPMessage *entry,
                                                   do_xlat ? NULL : value,
                                                   operator);
                                if (newpair == NULL) {
-                                       radlog(L_ERR, "rlm_ldap: Failed to create the pair: %s", fr_strerror);
+                                       radlog(L_ERR, "rlm_ldap: Failed to create the pair: %s", fr_strerror());
                                        continue;
                                }
 
index b969483..fd710f6 100644 (file)
@@ -698,7 +698,7 @@ void mschap_add_reply(REQUEST *request, VALUE_PAIR** vp, unsigned char ident,
        VALUE_PAIR *reply_attr;
        reply_attr = pairmake(name, "", T_OP_EQ);
        if (!reply_attr) {
-               RDEBUG("Failed to create attribute %s: %s\n", name, fr_strerror);
+               RDEBUG("Failed to create attribute %s: %s\n", name, fr_strerror());
                return;
        }
 
@@ -717,7 +717,7 @@ static void mppe_add_reply(REQUEST *request,
        VALUE_PAIR *vp;
        vp = radius_pairmake(request, &request->reply->vps, name, "", T_OP_EQ);
        if (!vp) {
-              RDEBUG("rlm_mschap: mppe_add_reply failed to create attribute %s: %s\n", name, fr_strerror);
+              RDEBUG("rlm_mschap: mppe_add_reply failed to create attribute %s: %s\n", name, fr_strerror());
               return;
        }
 
index 2d0500c..cfaa3f7 100644 (file)
@@ -852,7 +852,7 @@ static VALUE_PAIR *assign2vp(REQUEST *request,
 
        vp = pairmake(assign->lhs, value, operator);
        if (!vp) {
-               fprintf(stderr, "Failed creating pair: %s %s\n", value, fr_strerror);
+               fprintf(stderr, "Failed creating pair: %s %s\n", value, fr_strerror());
        }
 
        return vp;
index 22c5ab4..79e8615 100644 (file)
@@ -303,7 +303,7 @@ static int generate_sql_clients(SQL_INST *inst)
                if (ip_hton(row[1], AF_UNSPEC, &c->ipaddr) < 0) {
                        radlog(L_CONS|L_ERR, "rlm_sql (%s): Failed to look up hostname %s: %s",
                               inst->config->xlat_name,
-                              row[1], fr_strerror);
+                              row[1], fr_strerror());
                        free(c);
                        continue;
                } else {
@@ -433,7 +433,7 @@ int sql_set_user(SQL_INST *inst, REQUEST *request, char *sqlusername, const char
        vp = radius_pairmake(request, &request->packet->vps,
                             "SQL-User-Name", NULL, 0);
        if (!vp) {
-               radlog(L_ERR, "%s", fr_strerror);
+               radlog(L_ERR, "%s", fr_strerror());
                return -1;
        }
 
index a892aa5..ce00d83 100644 (file)
@@ -404,7 +404,7 @@ int sql_userparse(VALUE_PAIR ** first_pair, SQL_ROW row)
         */
        pair = pairmake(row[2], value, operator);
        if (pair == NULL) {
-               radlog(L_ERR, "rlm_sql: Failed to create the pair: %s", fr_strerror);
+               radlog(L_ERR, "rlm_sql: Failed to create the pair: %s", fr_strerror());
                return -1;
        }
        if (do_xlat) {
index 931e3c3..d77e9b0 100644 (file)
@@ -221,7 +221,7 @@ static int sql_set_user(rlm_sql_log_t *inst, REQUEST *request, char *sqlusername
                RDEBUG2("sql_set_user escaped user --> '%s'", sqlusername);
                vp = pairmake("SQL-User-Name", sqlusername, 0);
                if (vp == NULL) {
-                       radlog(L_ERR, "%s", fr_strerror);
+                       radlog(L_ERR, "%s", fr_strerror());
                        return -1;
                }