Ticket #466: 0001-Cleanup-fix-compiler-warnings.patch

File 0001-Cleanup-fix-compiler-warnings.patch, 20.2 KB (added by wichert@…, 4 years ago)
  • src/auth.c

    From 4d38dff9396d6ae56aa61ea403242462b2e1df35 Mon Sep 17 00:00:00 2001
    From: Wichert Akkerman <wichert@wiggy.net>
    Date: Mon, 5 May 2008 12:24:02 +0200
    Subject: [PATCH] Cleanup / fix compiler warnings
    
    Fix signed/unsigned comparisons
    Add const in API defininitions.
    Fixed a return-value check which was broken due to signed/unsigned comparison.
    ---
     src/auth.c          |    2 +-
     src/auth.h          |    2 +-
     src/centralserver.c |    5 ++-
     src/centralserver.h |    8 ++++-
     src/client_list.c   |   10 +++---
     src/client_list.h   |   10 +++---
     src/conf.c          |   83 +++++++++++++++++++++++++--------------------------
     src/conf.h          |    4 +-
     src/fw_iptables.c   |   39 +++++++++++++-----------
     src/fw_iptables.h   |    4 +-
     src/http.c          |   10 ++----
     src/ping_thread.c   |    4 +-
     src/util.c          |   11 ++++---
     src/util.h          |    4 +-
     src/wdctl.c         |   14 ++++----
     15 files changed, 109 insertions(+), 101 deletions(-)
    
    diff --git a/src/auth.c b/src/auth.c
    index 99c349d..230d933 100644
    a b  
    6060@todo This thread loops infinitely, need a watchdog to verify that it is still running? 
    6161*/   
    6262void 
    63 thread_client_timeout_check(void *arg) 
     63thread_client_timeout_check(const void *arg) 
    6464{ 
    6565        pthread_cond_t          cond = PTHREAD_COND_INITIALIZER; 
    6666        pthread_mutex_t         cond_mutex = PTHREAD_MUTEX_INITIALIZER; 
  • src/auth.h

    diff --git a/src/auth.h b/src/auth.h
    index 25ae422..89de88c 100644
    a b  
    5656void authenticate_client(request *); 
    5757 
    5858/** @brief Periodically check if connections expired */ 
    59 void thread_client_timeout_check(void *arg); 
     59void thread_client_timeout_check(const void *arg); 
    6060 
    6161#endif 
  • src/centralserver.c

    diff --git a/src/centralserver.c b/src/centralserver.c
    index edfce4a..2e10e28 100644
    a b  
    6262@param outgoing Current counter of the client's total outgoing traffic, in bytes  
    6363*/ 
    6464t_authcode 
    65 auth_server_request(t_authresponse *authresponse, char *request_type, char *ip, char *mac, char *token, unsigned long long int incoming, unsigned long long int outgoing) 
     65auth_server_request(t_authresponse *authresponse, const char *request_type, const char *ip, const char *mac, const char *token, unsigned long long int incoming, unsigned long long int outgoing) 
    6666{ 
    6767        int sockfd; 
    68         size_t  numbytes, totalbytes; 
     68        ssize_t numbytes; 
     69        size_t totalbytes; 
    6970        char buf[MAX_BUF]; 
    7071        char *tmp; 
    7172        int done, nfds; 
  • src/centralserver.h

    diff --git a/src/centralserver.h b/src/centralserver.h
    index fd3a4aa..36c9ca6 100644
    a b  
    4646#define GATEWAY_MESSAGE_ACCOUNT_LOGGED_OUT     "logged-out" 
    4747 
    4848/** @brief Initiates a transaction with the auth server */ 
    49 t_authcode auth_server_request(t_authresponse *authresponse, char *request_type, char *ip, char *mac, char *token, unsigned long long int incoming, unsigned long long int outgoing); 
     49t_authcode auth_server_request(t_authresponse *authresponse, 
     50                        const char *request_type, 
     51                        const char *ip, 
     52                        const char *mac, 
     53                        const char *token, 
     54                        unsigned long long int incoming, 
     55                        unsigned long long int outgoing); 
    5056 
    5157/** @brief Tries really hard to connect to an auth server.  Returns a connected file descriptor or -1 on error */ 
    5258int connect_auth_server(); 
  • src/client_list.c

    diff --git a/src/client_list.c b/src/client_list.c
    index de51975..d4e2703 100644
    a b  
    7777 * @return Pointer to the client we just created 
    7878 */ 
    7979t_client         * 
    80 client_list_append(char *ip, char *mac, char *token) 
     80client_list_append(const char *ip, const char *mac, const char *token) 
    8181{ 
    8282    t_client         *curclient, *prevclient; 
    8383 
     
    117117 * @return Pointer to the client, or NULL if not found 
    118118 */ 
    119119t_client         * 
    120 client_list_find(char *ip, char *mac) 
     120client_list_find(const char *ip, const char *mac) 
    121121{ 
    122122    t_client         *ptr; 
    123123 
     
    138138 * @return Pointer to the client, or NULL if not found 
    139139 */ 
    140140t_client         * 
    141 client_list_find_by_ip(char *ip) 
     141client_list_find_by_ip(const char *ip) 
    142142{ 
    143143    t_client         *ptr; 
    144144 
     
    159159 * @return Pointer to the client, or NULL if not found 
    160160 */ 
    161161t_client         * 
    162 client_list_find_by_mac(char *mac) 
     162client_list_find_by_mac(const char *mac) 
    163163{ 
    164164    t_client         *ptr; 
    165165 
     
    178178 * @return Pointer to the client, or NULL if not found 
    179179 */ 
    180180t_client * 
    181 client_list_find_by_token(char *token) 
     181client_list_find_by_token(const char *token) 
    182182{ 
    183183    t_client         *ptr; 
    184184 
  • src/client_list.h

    diff --git a/src/client_list.h b/src/client_list.h
    index fd860a8..bf6f8e6 100644
    a b  
    6161void client_list_init(void); 
    6262 
    6363/** @brief Adds a new client to the connections list */ 
    64 t_client *client_list_append(char *ip, char *mac, char *token); 
     64t_client *client_list_append(const char *ip, const char *mac, const char *token); 
    6565 
    6666/** @brief Finds a client by its IP and MAC */ 
    67 t_client *client_list_find(char *ip, char *mac); 
     67t_client *client_list_find(const char *ip, const char *mac); 
    6868 
    6969/** @brief Finds a client only by its IP */ 
    70 t_client *client_list_find_by_ip(char *ip); /* needed by fw_iptables.c, auth.c  
     70t_client *client_list_find_by_ip(const char *ip); /* needed by fw_iptables.c, auth.c  
    7171                                             * and wdctl_thread.c */ 
    7272 
    7373/** @brief Finds a client only by its Mac */ 
    74 t_client *client_list_find_by_mac(char *mac); /* needed by wdctl_thread.c */ 
     74t_client *client_list_find_by_mac(const char *mac); /* needed by wdctl_thread.c */ 
    7575 
    7676/** @brief Finds a client by its token */ 
    77 t_client *client_list_find_by_token(char *token); 
     77t_client *client_list_find_by_token(const char *token); 
    7878 
    7979/** @brief Deletes a client from the connections list and frees its memoery*/ 
    8080void client_list_delete(t_client *client); 
  • src/conf.c

    diff --git a/src/conf.c b/src/conf.c
    index 617ba42..4fdc413 100644
    a b  
    102102static const struct { 
    103103        const char *name; 
    104104        OpCodes opcode; 
    105         int required; 
    106105} keywords[] = { 
    107         { "daemon",             oDaemon }, 
    108         { "debuglevel",         oDebugLevel }, 
    109         { "externalinterface",  oExternalInterface }, 
    110         { "gatewayid",          oGatewayID }, 
    111         { "gatewayinterface",   oGatewayInterface }, 
    112         { "gatewayaddress",     oGatewayAddress }, 
    113         { "gatewayport",        oGatewayPort }, 
    114         { "authserver",         oAuthServer }, 
    115         { "httpdmaxconn",       oHTTPDMaxConn }, 
    116         { "httpdname",          oHTTPDName }, 
    117         { "httpdrealm",         oHTTPDRealm }, 
    118         { "httpdusername",      oHTTPDUsername }, 
    119         { "httpdpassword",      oHTTPDPassword }, 
    120         { "clienttimeout",      oClientTimeout }, 
    121         { "checkinterval",      oCheckInterval }, 
    122         { "syslogfacility",     oSyslogFacility }, 
    123         { "wdctlsocket",            oWdctlSocket }, 
    124         { "hostname",               oAuthServHostname }, 
    125         { "sslavailable",           oAuthServSSLAvailable }, 
    126         { "sslport",                oAuthServSSLPort }, 
    127         { "httpport",               oAuthServHTTPPort }, 
    128         { "path",                       oAuthServPath }, 
     106        { "daemon",                     oDaemon }, 
     107        { "debuglevel",                 oDebugLevel }, 
     108        { "externalinterface",          oExternalInterface }, 
     109        { "gatewayid",                  oGatewayID }, 
     110        { "gatewayinterface",           oGatewayInterface }, 
     111        { "gatewayaddress",             oGatewayAddress }, 
     112        { "gatewayport",                oGatewayPort }, 
     113        { "authserver",                 oAuthServer }, 
     114        { "httpdmaxconn",               oHTTPDMaxConn }, 
     115        { "httpdname",                  oHTTPDName }, 
     116        { "httpdrealm",                 oHTTPDRealm }, 
     117        { "httpdusername",              oHTTPDUsername }, 
     118        { "httpdpassword",              oHTTPDPassword }, 
     119        { "clienttimeout",              oClientTimeout }, 
     120        { "checkinterval",              oCheckInterval }, 
     121        { "syslogfacility",             oSyslogFacility }, 
     122        { "wdctlsocket",                oWdctlSocket }, 
     123        { "hostname",                   oAuthServHostname }, 
     124        { "sslavailable",               oAuthServSSLAvailable }, 
     125        { "sslport",                    oAuthServSSLPort }, 
     126        { "httpport",                   oAuthServHTTPPort }, 
     127        { "path",                       oAuthServPath }, 
    129128        { "loginscriptpathfragment",    oAuthServLoginScriptPathFragment }, 
    130129        { "portalscriptpathfragment",   oAuthServPortalScriptPathFragment }, 
    131         { "msgscriptpathfragment",              oAuthServMsgScriptPathFragment }, 
    132         { "pingscriptpathfragment",             oAuthServPingScriptPathFragment }, 
    133         { "authscriptpathfragment",             oAuthServAuthScriptPathFragment }, 
    134         { "firewallruleset",    oFirewallRuleSet }, 
    135         { "firewallrule",           oFirewallRule }, 
    136         { "trustedmaclist",         oTrustedMACList }, 
    137         { "htmlmessagefile",    oHtmlMessageFile }, 
    138         { NULL,                 oBadOption }, 
     130        { "msgscriptpathfragment",      oAuthServMsgScriptPathFragment }, 
     131        { "pingscriptpathfragment",     oAuthServPingScriptPathFragment }, 
     132        { "authscriptpathfragment",     oAuthServAuthScriptPathFragment }, 
     133        { "firewallruleset",            oFirewallRuleSet }, 
     134        { "firewallrule",               oFirewallRule }, 
     135        { "trustedmaclist",             oTrustedMACList }, 
     136        { "htmlmessagefile",            oHtmlMessageFile }, 
     137        { NULL,                         oBadOption }, 
    139138}; 
    140139 
    141 static void config_notnull(void *parm, char *parmname); 
     140static void config_notnull(const void *parm, const char *parmname); 
    142141static int parse_boolean_value(char *); 
    143 static void parse_auth_server(FILE *, char *, int *); 
    144 static int _parse_firewall_rule(char *ruleset, char *leftover); 
    145 static void parse_firewall_ruleset(char *, FILE *, char *, int *); 
     142static void parse_auth_server(FILE *, const char *, int *); 
     143static int _parse_firewall_rule(const char *ruleset, char *leftover); 
     144static void parse_firewall_ruleset(const char *, FILE *, const char *, int *); 
    146145 
    147146static OpCodes config_parse_token(const char *cp, const char *filename, int linenum); 
    148147 
     
    215214Parses auth server information 
    216215*/ 
    217216static void 
    218 parse_auth_server(FILE *file, char *filename, int *linenum) 
     217parse_auth_server(FILE *file, const char *filename, int *linenum) 
    219218{ 
    220219        char            *host = NULL, 
    221220                        *path = NULL, 
     
    400399Parses firewall rule set information 
    401400*/ 
    402401static void 
    403 parse_firewall_ruleset(char *ruleset, FILE *file, char *filename, int *linenum) 
     402parse_firewall_ruleset(const char *ruleset, FILE *file, const char *filename, int *linenum) 
    404403{ 
    405404        char            line[MAX_BUF], 
    406405                        *p1, 
     
    477476Helper for parse_firewall_ruleset.  Parses a single rule in a ruleset 
    478477*/ 
    479478static int 
    480 _parse_firewall_rule(char *ruleset, char *leftover) 
     479_parse_firewall_rule(const char *ruleset, char *leftover) 
    481480{ 
    482481        int i; 
    483482        int block_allow = 0; /**< 0 == block, 1 == allow */ 
     
    613612} 
    614613 
    615614t_firewall_rule * 
    616 get_ruleset(char *ruleset) 
     615get_ruleset(const char *ruleset) 
    617616{ 
    618617        t_firewall_ruleset      *tmp; 
    619618 
     
    630629@param filename Full path of the configuration file to be read  
    631630*/ 
    632631void 
    633 config_read(char *filename) 
     632config_read(const char *filename) 
    634633{ 
    635634        FILE *fd; 
    636635        char line[MAX_BUF], *s, *p1, *p2; 
     
    829828config_validate(void) 
    830829{ 
    831830        config_notnull(config.gw_interface, "GatewayInterface"); 
    832     config_notnull(config.auth_servers, "AuthServer"); 
     831        config_notnull(config.auth_servers, "AuthServer"); 
    833832 
    834833        if (missing_parms) { 
    835834                debug(LOG_ERR, "Configuration is not complete, exiting..."); 
     
    841840    Verifies that a required parameter is not a null pointer 
    842841*/ 
    843842static void 
    844 config_notnull(void *parm, char *parmname) 
     843config_notnull(const void *parm, const char *parmname) 
    845844{ 
    846845        if (parm == NULL) { 
    847846                debug(LOG_ERR, "%s is not set", parmname); 
  • src/conf.h

    diff --git a/src/conf.h b/src/conf.h
    index 53a8b79..6b09987 100644
    a b  
    165165void config_init_override(void); 
    166166 
    167167/** @brief Reads the configuration file */ 
    168 void config_read(char *filename); 
     168void config_read(const char *filename); 
    169169 
    170170/** @brief Check that the configuration is valid */ 
    171171void config_validate(void); 
     
    177177void mark_auth_server_bad(t_auth_serv *); 
    178178 
    179179/** @brief Fetch a firewall rule set. */ 
    180 t_firewall_rule *get_ruleset(char *); 
     180t_firewall_rule *get_ruleset(const char *); 
    181181 
    182182void parse_trusted_mac_list(char *); 
    183183 
  • src/fw_iptables.c

    diff --git a/src/fw_iptables.c b/src/fw_iptables.c
    index 05501a0..1e25b4e 100644
    a b  
    4848#include "util.h" 
    4949#include "client_list.h" 
    5050 
    51 static int iptables_do_command(char *format, ...); 
    52 static char *iptables_compile(char *, char *, t_firewall_rule *); 
    53 static void iptables_load_ruleset(char *, char *, char *); 
     51static int iptables_do_command(const char *format, ...); 
     52static char *iptables_compile(const char *, const char *, const t_firewall_rule *); 
     53static void iptables_load_ruleset(const char *, const char *, const char *); 
    5454 
    5555extern pthread_mutex_t  client_list_mutex; 
    5656extern pthread_mutex_t  config_mutex; 
     
    6262/** @internal  
    6363 * */ 
    6464static int 
    65 iptables_do_command(char *format, ...) 
     65iptables_do_command(const char *format, ...) 
    6666{ 
    6767    va_list vlist; 
    6868    char *fmt_cmd, 
     
    8181         
    8282    rc = execute(cmd, fw_quiet); 
    8383 
     84    if (rc!=0) 
     85        debug(LOG_ERR, "iptables comand tailed: %s", cmd); 
     86 
    8487    free(cmd); 
    8588 
    8689    return rc; 
     
    9598 * @arg rule Definition of a rule into a struct, from conf.c. 
    9699 */ 
    97100static char * 
    98 iptables_compile(char * table, char *chain, t_firewall_rule *rule) 
     101iptables_compile(const char * table, const char *chain, const t_firewall_rule *rule) 
    99102{ 
    100103    char        command[MAX_BUF], 
    101104                *mode; 
     
    139142 * @arg chain IPTables chain the rules go into 
    140143 */ 
    141144static void 
    142 iptables_load_ruleset(char * table, char *ruleset, char *chain) 
     145iptables_load_ruleset(const char * table, const char *ruleset, const char *chain) 
    143146{ 
    144147        t_firewall_rule         *rule; 
    145148        char                    *cmd; 
     
    166169void 
    167170iptables_fw_set_authservers(void) 
    168171{ 
    169     s_config *config; 
     172    const s_config *config; 
    170173    t_auth_serv *auth_server; 
    171174    
    172175    config = config_get_config(); 
     
    185188int 
    186189iptables_fw_init(void) 
    187190{ 
    188     s_config *config; 
    189          char * gw_interface = NULL; 
    190          char * gw_address = NULL; 
    191          char * ext_interface = NULL; 
    192          int gw_port = 0; 
    193      t_trusted_mac *p; 
     191        const s_config *config; 
     192        char * gw_interface = NULL; 
     193        char * gw_address = NULL; 
     194        char * ext_interface = NULL; 
     195        int gw_port = 0; 
     196        t_trusted_mac *p; 
    194197    
    195     fw_quiet = 0; 
     198        fw_quiet = 0; 
    196199 
    197200         LOCK_CONFIG(); 
    198201    config = config_get_config(); 
     
    399402 */ 
    400403int 
    401404iptables_fw_destroy_mention( 
    402                 char * table, 
    403                 char * chain, 
    404                 char * mention 
     405                const char * table, 
     406                const char * chain, 
     407                const char * mention 
    405408) { 
    406409        FILE *p = NULL; 
    407410        char *command = NULL; 
     
    450453 
    451454/** Set if a specific client has access through the firewall */ 
    452455int 
    453 iptables_fw_access(fw_access_t type, char *ip, char *mac, int tag) 
     456iptables_fw_access(fw_access_t type, const char *ip, const char *mac, int tag) 
    454457{ 
    455458    int rc; 
    456459 
  • src/fw_iptables.h

    diff --git a/src/fw_iptables.h b/src/fw_iptables.h
    index 8604527..aaf5921 100644
    a b  
    6363int iptables_fw_destroy(void); 
    6464 
    6565/** @brief Helper function for iptables_fw_destroy */ 
    66 int iptables_fw_destroy_mention( char * table, char * chain, char * mention); 
     66int iptables_fw_destroy_mention( const char * table, const char * chain, const char * mention); 
    6767 
    6868/** @brief Define the access of a specific client */ 
    69 int iptables_fw_access(fw_access_t type, char *ip, char *mac, int tag); 
     69int iptables_fw_access(fw_access_t type, const char *ip, const char *mac, int tag); 
    7070 
    7171/** @brief All counters in the client list */ 
    7272int iptables_fw_counters_update(void); 
  • src/http.c

    diff --git a/src/http.c b/src/http.c
    index f5391ed..a13a8fd 100644
    a b  
    312312                        UNLOCK_CLIENT_LIST(); 
    313313                        debug(LOG_INFO, "Disconnect %s with incorrect token %s", mac->value, token->value); 
    314314                        httpdOutput(r, "Invalid token for MAC"); 
    315                         return -1; 
     315                        return; 
    316316                } 
    317317 
    318318                /* TODO: get current firewall counters */ 
     
    322322        } else { 
    323323                debug(LOG_INFO, "Disconnect called without both token and MAC given"); 
    324324                httpdOutput(r, "Both the token and MAC need to be specified");  
    325                 return -1; 
     325                return; 
    326326        } 
    327  
    328         return 0; 
    329327} 
    330328 
    331329void send_http_page(request *r, const char *title, const char* message) 
    332330{ 
    333331    s_config    *config = config_get_config(); 
    334     unsigned char *buffer; 
     332    char *buffer; 
    335333    struct stat stat_info; 
    336334    int fd; 
    337335    ssize_t written; 
     
    348346        return; 
    349347    } 
    350348 
    351     buffer=(unsigned char*)safe_malloc(stat_info.st_size+1); 
     349    buffer=(char*)safe_malloc(stat_info.st_size+1); 
    352350    written=read(fd, buffer, stat_info.st_size); 
    353351    if (written==-1) { 
    354352        debug(LOG_CRIT, "Failed to read HTML message file: %s", strerror(errno)); 
  • src/ping_thread.c

    diff --git a/src/ping_thread.c b/src/ping_thread.c
    index cad3e26..cf1a6ef 100644
    a b  
    9393static void 
    9494ping(void) 
    9595{ 
    96         size_t                  numbytes, 
    97                                 totalbytes; 
     96        ssize_t                 numbytes; 
     97        size_t                  totalbytes; 
    9898        int                     sockfd, nfds, done; 
    9999        char                    request[MAX_BUF]; 
    100100        fd_set                  readfds; 
  • src/util.c

    diff --git a/src/util.c b/src/util.c
    index 0b1a6b3..737637f 100644
    a b  
    4040#include <sys/unistd.h> 
    4141#include <netinet/in.h> 
    4242#include <sys/ioctl.h> 
     43#include <sys/socket.h> 
     44#include <arpa/inet.h> 
    4345 
    4446#if defined(__NetBSD__) 
    45 #include <arpa/inet.h> 
    46 #include <sys/socket.h> 
    4747#include <ifaddrs.h> 
    4848#include <net/if.h> 
    4949#include <net/if_dl.h> 
     
    5151#endif 
    5252 
    5353#ifdef __linux__ 
     54#include <netinet/in.h> 
    5455#include <net/if.h> 
    5556#endif 
    5657 
     
    154155} 
    155156 
    156157char * 
    157 get_iface_ip(char *ifname) 
     158get_iface_ip(const char *ifname) 
    158159{ 
    159160#if defined(__linux__) 
    160161        struct ifreq if_data; 
     
    180181        memcpy ((void *) &ip, (void *) &if_data.ifr_addr.sa_data + 2, 4); 
    181182        in.s_addr = ip; 
    182183 
    183         ip_str = (char *)inet_ntoa(in); 
     184        ip_str = inet_ntoa(in); 
    184185        close(sockd); 
    185186        return safe_strdup(ip_str); 
    186187#elif defined(__NetBSD__) 
     
    212213} 
    213214 
    214215char * 
    215 get_iface_mac(char *ifname) 
     216get_iface_mac(const char *ifname) 
    216217{ 
    217218#if defined(__linux__) 
    218219    int r, s; 
  • src/util.h

    diff --git a/src/util.h b/src/util.h
    index 154128e..a41a59f 100644
    a b  
    3535struct in_addr *wd_gethostbyname(const char *name); 
    3636 
    3737/* @brief Get IP address of an interface */ 
    38 char *get_iface_ip(char *ifname); 
     38char *get_iface_ip(const char *ifname); 
    3939 
    4040/* @brief Get MAC address of an interface */ 
    41 char *get_iface_mac(char *ifname); 
     41char *get_iface_mac(const char *ifname); 
    4242 
    4343/* @brief Get interface name of default gateway */ 
    4444char *get_ext_iface (void); 
  • src/wdctl.c

    diff --git a/src/wdctl.c b/src/wdctl.c
    index 8b27a15..30ca3fd 100644
    a b  
    4646static void init_config(void); 
    4747static void parse_commandline(int, char **); 
    4848static int connect_to_server(char *); 
    49 static int send_request(int, char *); 
     49static size_t send_request(int, char *); 
    5050static void wdctl_status(void); 
    5151static void wdctl_stop(void); 
    5252static void wdctl_reset(void); 
     
    166166        return sock; 
    167167} 
    168168 
    169 static int 
     169static size_t 
    170170send_request(int sock, char *request) 
    171171{ 
    172         ssize_t len, 
    173                 written; 
     172        size_t  len; 
     173        ssize_t written; 
    174174                 
    175175        len = 0; 
    176176        while (len != strlen(request)) { 
     
    183183                len += written; 
    184184        } 
    185185 
    186         return((int)len); 
     186        return len; 
    187187} 
    188188 
    189189static void 
     
    238238        int     sock; 
    239239        char    buffer[4096]; 
    240240        char    request[64]; 
    241         int     len, 
    242                 rlen; 
     241        size_t  len; 
     242        int     rlen; 
    243243 
    244244        sock = connect_to_server(config.socket); 
    245245