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 60 60 @todo This thread loops infinitely, need a watchdog to verify that it is still running? 61 61 */ 62 62 void 63 thread_client_timeout_check( void *arg)63 thread_client_timeout_check(const void *arg) 64 64 { 65 65 pthread_cond_t cond = PTHREAD_COND_INITIALIZER; 66 66 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 56 56 void authenticate_client(request *); 57 57 58 58 /** @brief Periodically check if connections expired */ 59 void thread_client_timeout_check( void *arg);59 void thread_client_timeout_check(const void *arg); 60 60 61 61 #endif -
src/centralserver.c
diff --git a/src/centralserver.c b/src/centralserver.c index edfce4a..2e10e28 100644
a b 62 62 @param outgoing Current counter of the client's total outgoing traffic, in bytes 63 63 */ 64 64 t_authcode 65 auth_server_request(t_authresponse *authresponse, c har *request_type, char *ip, char *mac,char *token, unsigned long long int incoming, unsigned long long int outgoing)65 auth_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) 66 66 { 67 67 int sockfd; 68 size_t numbytes, totalbytes; 68 ssize_t numbytes; 69 size_t totalbytes; 69 70 char buf[MAX_BUF]; 70 71 char *tmp; 71 72 int done, nfds; -
src/centralserver.h
diff --git a/src/centralserver.h b/src/centralserver.h index fd3a4aa..36c9ca6 100644
a b 46 46 #define GATEWAY_MESSAGE_ACCOUNT_LOGGED_OUT "logged-out" 47 47 48 48 /** @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); 49 t_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); 50 56 51 57 /** @brief Tries really hard to connect to an auth server. Returns a connected file descriptor or -1 on error */ 52 58 int 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 77 77 * @return Pointer to the client we just created 78 78 */ 79 79 t_client * 80 client_list_append(c har *ip, char *mac,char *token)80 client_list_append(const char *ip, const char *mac, const char *token) 81 81 { 82 82 t_client *curclient, *prevclient; 83 83 … … 117 117 * @return Pointer to the client, or NULL if not found 118 118 */ 119 119 t_client * 120 client_list_find(c har *ip,char *mac)120 client_list_find(const char *ip, const char *mac) 121 121 { 122 122 t_client *ptr; 123 123 … … 138 138 * @return Pointer to the client, or NULL if not found 139 139 */ 140 140 t_client * 141 client_list_find_by_ip(c har *ip)141 client_list_find_by_ip(const char *ip) 142 142 { 143 143 t_client *ptr; 144 144 … … 159 159 * @return Pointer to the client, or NULL if not found 160 160 */ 161 161 t_client * 162 client_list_find_by_mac(c har *mac)162 client_list_find_by_mac(const char *mac) 163 163 { 164 164 t_client *ptr; 165 165 … … 178 178 * @return Pointer to the client, or NULL if not found 179 179 */ 180 180 t_client * 181 client_list_find_by_token(c har *token)181 client_list_find_by_token(const char *token) 182 182 { 183 183 t_client *ptr; 184 184 -
src/client_list.h
diff --git a/src/client_list.h b/src/client_list.h index fd860a8..bf6f8e6 100644
a b 61 61 void client_list_init(void); 62 62 63 63 /** @brief Adds a new client to the connections list */ 64 t_client *client_list_append(c har *ip, char *mac,char *token);64 t_client *client_list_append(const char *ip, const char *mac, const char *token); 65 65 66 66 /** @brief Finds a client by its IP and MAC */ 67 t_client *client_list_find(c har *ip,char *mac);67 t_client *client_list_find(const char *ip, const char *mac); 68 68 69 69 /** @brief Finds a client only by its IP */ 70 t_client *client_list_find_by_ip(c har *ip); /* needed by fw_iptables.c, auth.c70 t_client *client_list_find_by_ip(const char *ip); /* needed by fw_iptables.c, auth.c 71 71 * and wdctl_thread.c */ 72 72 73 73 /** @brief Finds a client only by its Mac */ 74 t_client *client_list_find_by_mac(c har *mac); /* needed by wdctl_thread.c */74 t_client *client_list_find_by_mac(const char *mac); /* needed by wdctl_thread.c */ 75 75 76 76 /** @brief Finds a client by its token */ 77 t_client *client_list_find_by_token(c har *token);77 t_client *client_list_find_by_token(const char *token); 78 78 79 79 /** @brief Deletes a client from the connections list and frees its memoery*/ 80 80 void 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 102 102 static const struct { 103 103 const char *name; 104 104 OpCodes opcode; 105 int required;106 105 } 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 }, 129 128 { "loginscriptpathfragment", oAuthServLoginScriptPathFragment }, 130 129 { "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 }, 139 138 }; 140 139 141 static void config_notnull( void *parm,char *parmname);140 static void config_notnull(const void *parm, const char *parmname); 142 141 static int parse_boolean_value(char *); 143 static void parse_auth_server(FILE *, c har *, int *);144 static int _parse_firewall_rule(c har *ruleset, char *leftover);145 static void parse_firewall_ruleset(c har *, FILE *,char *, int *);142 static void parse_auth_server(FILE *, const char *, int *); 143 static int _parse_firewall_rule(const char *ruleset, char *leftover); 144 static void parse_firewall_ruleset(const char *, FILE *, const char *, int *); 146 145 147 146 static OpCodes config_parse_token(const char *cp, const char *filename, int linenum); 148 147 … … 215 214 Parses auth server information 216 215 */ 217 216 static void 218 parse_auth_server(FILE *file, c har *filename, int *linenum)217 parse_auth_server(FILE *file, const char *filename, int *linenum) 219 218 { 220 219 char *host = NULL, 221 220 *path = NULL, … … 400 399 Parses firewall rule set information 401 400 */ 402 401 static void 403 parse_firewall_ruleset(c har *ruleset, FILE *file,char *filename, int *linenum)402 parse_firewall_ruleset(const char *ruleset, FILE *file, const char *filename, int *linenum) 404 403 { 405 404 char line[MAX_BUF], 406 405 *p1, … … 477 476 Helper for parse_firewall_ruleset. Parses a single rule in a ruleset 478 477 */ 479 478 static int 480 _parse_firewall_rule(c har *ruleset, char *leftover)479 _parse_firewall_rule(const char *ruleset, char *leftover) 481 480 { 482 481 int i; 483 482 int block_allow = 0; /**< 0 == block, 1 == allow */ … … 613 612 } 614 613 615 614 t_firewall_rule * 616 get_ruleset(c har *ruleset)615 get_ruleset(const char *ruleset) 617 616 { 618 617 t_firewall_ruleset *tmp; 619 618 … … 630 629 @param filename Full path of the configuration file to be read 631 630 */ 632 631 void 633 config_read(c har *filename)632 config_read(const char *filename) 634 633 { 635 634 FILE *fd; 636 635 char line[MAX_BUF], *s, *p1, *p2; … … 829 828 config_validate(void) 830 829 { 831 830 config_notnull(config.gw_interface, "GatewayInterface"); 832 config_notnull(config.auth_servers, "AuthServer");831 config_notnull(config.auth_servers, "AuthServer"); 833 832 834 833 if (missing_parms) { 835 834 debug(LOG_ERR, "Configuration is not complete, exiting..."); … … 841 840 Verifies that a required parameter is not a null pointer 842 841 */ 843 842 static void 844 config_notnull( void *parm,char *parmname)843 config_notnull(const void *parm, const char *parmname) 845 844 { 846 845 if (parm == NULL) { 847 846 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 165 165 void config_init_override(void); 166 166 167 167 /** @brief Reads the configuration file */ 168 void config_read(c har *filename);168 void config_read(const char *filename); 169 169 170 170 /** @brief Check that the configuration is valid */ 171 171 void config_validate(void); … … 177 177 void mark_auth_server_bad(t_auth_serv *); 178 178 179 179 /** @brief Fetch a firewall rule set. */ 180 t_firewall_rule *get_ruleset(c har *);180 t_firewall_rule *get_ruleset(const char *); 181 181 182 182 void parse_trusted_mac_list(char *); 183 183 -
src/fw_iptables.c
diff --git a/src/fw_iptables.c b/src/fw_iptables.c index 05501a0..1e25b4e 100644
a b 48 48 #include "util.h" 49 49 #include "client_list.h" 50 50 51 static int iptables_do_command(c har *format, ...);52 static char *iptables_compile(c har *, char *,t_firewall_rule *);53 static void iptables_load_ruleset(c har *, char *,char *);51 static int iptables_do_command(const char *format, ...); 52 static char *iptables_compile(const char *, const char *, const t_firewall_rule *); 53 static void iptables_load_ruleset(const char *, const char *, const char *); 54 54 55 55 extern pthread_mutex_t client_list_mutex; 56 56 extern pthread_mutex_t config_mutex; … … 62 62 /** @internal 63 63 * */ 64 64 static int 65 iptables_do_command(c har *format, ...)65 iptables_do_command(const char *format, ...) 66 66 { 67 67 va_list vlist; 68 68 char *fmt_cmd, … … 81 81 82 82 rc = execute(cmd, fw_quiet); 83 83 84 if (rc!=0) 85 debug(LOG_ERR, "iptables comand tailed: %s", cmd); 86 84 87 free(cmd); 85 88 86 89 return rc; … … 95 98 * @arg rule Definition of a rule into a struct, from conf.c. 96 99 */ 97 100 static char * 98 iptables_compile(c har * table, char *chain,t_firewall_rule *rule)101 iptables_compile(const char * table, const char *chain, const t_firewall_rule *rule) 99 102 { 100 103 char command[MAX_BUF], 101 104 *mode; … … 139 142 * @arg chain IPTables chain the rules go into 140 143 */ 141 144 static void 142 iptables_load_ruleset(c har * table, char *ruleset,char *chain)145 iptables_load_ruleset(const char * table, const char *ruleset, const char *chain) 143 146 { 144 147 t_firewall_rule *rule; 145 148 char *cmd; … … 166 169 void 167 170 iptables_fw_set_authservers(void) 168 171 { 169 s_config *config;172 const s_config *config; 170 173 t_auth_serv *auth_server; 171 174 172 175 config = config_get_config(); … … 185 188 int 186 189 iptables_fw_init(void) 187 190 { 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; 194 197 195 fw_quiet = 0;198 fw_quiet = 0; 196 199 197 200 LOCK_CONFIG(); 198 201 config = config_get_config(); … … 399 402 */ 400 403 int 401 404 iptables_fw_destroy_mention( 402 c har * table,403 c har * chain,404 c har * mention405 const char * table, 406 const char * chain, 407 const char * mention 405 408 ) { 406 409 FILE *p = NULL; 407 410 char *command = NULL; … … 450 453 451 454 /** Set if a specific client has access through the firewall */ 452 455 int 453 iptables_fw_access(fw_access_t type, c har *ip,char *mac, int tag)456 iptables_fw_access(fw_access_t type, const char *ip, const char *mac, int tag) 454 457 { 455 458 int rc; 456 459 -
src/fw_iptables.h
diff --git a/src/fw_iptables.h b/src/fw_iptables.h index 8604527..aaf5921 100644
a b 63 63 int iptables_fw_destroy(void); 64 64 65 65 /** @brief Helper function for iptables_fw_destroy */ 66 int iptables_fw_destroy_mention( c har * table, char * chain,char * mention);66 int iptables_fw_destroy_mention( const char * table, const char * chain, const char * mention); 67 67 68 68 /** @brief Define the access of a specific client */ 69 int iptables_fw_access(fw_access_t type, c har *ip,char *mac, int tag);69 int iptables_fw_access(fw_access_t type, const char *ip, const char *mac, int tag); 70 70 71 71 /** @brief All counters in the client list */ 72 72 int iptables_fw_counters_update(void); -
src/http.c
diff --git a/src/http.c b/src/http.c index f5391ed..a13a8fd 100644
a b 312 312 UNLOCK_CLIENT_LIST(); 313 313 debug(LOG_INFO, "Disconnect %s with incorrect token %s", mac->value, token->value); 314 314 httpdOutput(r, "Invalid token for MAC"); 315 return -1;315 return; 316 316 } 317 317 318 318 /* TODO: get current firewall counters */ … … 322 322 } else { 323 323 debug(LOG_INFO, "Disconnect called without both token and MAC given"); 324 324 httpdOutput(r, "Both the token and MAC need to be specified"); 325 return -1;325 return; 326 326 } 327 328 return 0;329 327 } 330 328 331 329 void send_http_page(request *r, const char *title, const char* message) 332 330 { 333 331 s_config *config = config_get_config(); 334 unsignedchar *buffer;332 char *buffer; 335 333 struct stat stat_info; 336 334 int fd; 337 335 ssize_t written; … … 348 346 return; 349 347 } 350 348 351 buffer=( unsignedchar*)safe_malloc(stat_info.st_size+1);349 buffer=(char*)safe_malloc(stat_info.st_size+1); 352 350 written=read(fd, buffer, stat_info.st_size); 353 351 if (written==-1) { 354 352 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 93 93 static void 94 94 ping(void) 95 95 { 96 size_t numbytes, 97 totalbytes;96 ssize_t numbytes; 97 size_t totalbytes; 98 98 int sockfd, nfds, done; 99 99 char request[MAX_BUF]; 100 100 fd_set readfds; -
src/util.c
diff --git a/src/util.c b/src/util.c index 0b1a6b3..737637f 100644
a b 40 40 #include <sys/unistd.h> 41 41 #include <netinet/in.h> 42 42 #include <sys/ioctl.h> 43 #include <sys/socket.h> 44 #include <arpa/inet.h> 43 45 44 46 #if defined(__NetBSD__) 45 #include <arpa/inet.h>46 #include <sys/socket.h>47 47 #include <ifaddrs.h> 48 48 #include <net/if.h> 49 49 #include <net/if_dl.h> … … 51 51 #endif 52 52 53 53 #ifdef __linux__ 54 #include <netinet/in.h> 54 55 #include <net/if.h> 55 56 #endif 56 57 … … 154 155 } 155 156 156 157 char * 157 get_iface_ip(c har *ifname)158 get_iface_ip(const char *ifname) 158 159 { 159 160 #if defined(__linux__) 160 161 struct ifreq if_data; … … 180 181 memcpy ((void *) &ip, (void *) &if_data.ifr_addr.sa_data + 2, 4); 181 182 in.s_addr = ip; 182 183 183 ip_str = (char *)inet_ntoa(in);184 ip_str = inet_ntoa(in); 184 185 close(sockd); 185 186 return safe_strdup(ip_str); 186 187 #elif defined(__NetBSD__) … … 212 213 } 213 214 214 215 char * 215 get_iface_mac(c har *ifname)216 get_iface_mac(const char *ifname) 216 217 { 217 218 #if defined(__linux__) 218 219 int r, s; -
src/util.h
diff --git a/src/util.h b/src/util.h index 154128e..a41a59f 100644
a b 35 35 struct in_addr *wd_gethostbyname(const char *name); 36 36 37 37 /* @brief Get IP address of an interface */ 38 char *get_iface_ip(c har *ifname);38 char *get_iface_ip(const char *ifname); 39 39 40 40 /* @brief Get MAC address of an interface */ 41 char *get_iface_mac(c har *ifname);41 char *get_iface_mac(const char *ifname); 42 42 43 43 /* @brief Get interface name of default gateway */ 44 44 char *get_ext_iface (void); -
src/wdctl.c
diff --git a/src/wdctl.c b/src/wdctl.c index 8b27a15..30ca3fd 100644
a b 46 46 static void init_config(void); 47 47 static void parse_commandline(int, char **); 48 48 static int connect_to_server(char *); 49 static int send_request(int, char *);49 static size_t send_request(int, char *); 50 50 static void wdctl_status(void); 51 51 static void wdctl_stop(void); 52 52 static void wdctl_reset(void); … … 166 166 return sock; 167 167 } 168 168 169 static int169 static size_t 170 170 send_request(int sock, char *request) 171 171 { 172 s size_t len,173 written;172 size_t len; 173 ssize_t written; 174 174 175 175 len = 0; 176 176 while (len != strlen(request)) { … … 183 183 len += written; 184 184 } 185 185 186 return ((int)len);186 return len; 187 187 } 188 188 189 189 static void … … 238 238 int sock; 239 239 char buffer[4096]; 240 240 char request[64]; 241 int len,242 rlen;241 size_t len; 242 int rlen; 243 243 244 244 sock = connect_to_server(config.socket); 245 245
