Changeset 90
- Timestamp:
- 04/20/04 20:03:24 (9 years ago)
- Location:
- trunk/wifidog
- Files:
-
- 14 modified
-
ChangeLog (modified) (1 diff)
-
src/auth.c (modified) (4 diffs)
-
src/centralserver.c (modified) (5 diffs)
-
src/commandline.c (modified) (3 diffs)
-
src/common.h (modified) (1 diff)
-
src/conf.c (modified) (14 diffs)
-
src/conf.h (modified) (2 diffs)
-
src/debug.c (modified) (1 diff)
-
src/debug.h (modified) (1 diff)
-
src/firewall.c (modified) (12 diffs)
-
src/gateway.c (modified) (12 diffs)
-
src/http.c (modified) (4 diffs)
-
src/userclasses.c (modified) (1 diff)
-
wifidog.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog/ChangeLog
r89 r90 1 1 # $Header$ 2 2004-04-19 Philippe April <papril777@yahoo.com> 3 * A lot of changes regarding debugging facilities and added logging 4 to syslog 5 2 6 2004-04-19 Philippe April <papril777@yahoo.com> 3 7 * Changed some debugging severity -
trunk/wifidog/src/auth.c
r89 r90 105 105 if (profile == -1) { 106 106 // Error talking to central server 107 debug( D_LOG_ERR, "Got %d from central server authenticating "107 debug(LOG_ERR, "Got %d from central server authenticating " 108 108 "token %s from %s at %s", profile, node->token, 109 109 node->ip, node->mac); … … 124 124 /* If we get here, we've got a profile > 0 */ 125 125 126 debug( D_LOG_INFO, "Node %s with mac %s and profile "126 debug(LOG_INFO, "Node %s with mac %s and profile " 127 127 "%d validated", node->ip, node->mac, profile); 128 128 … … 130 130 131 131 if (tmp_uc == NULL) { 132 debug( D_LOG_WARNING, "Profile %d undefined", profile);132 debug(LOG_WARNING, "Profile %d undefined", profile); 133 133 _http_output(node->fd, "User Class not defined"); 134 134 node->fd = 0; … … 136 136 return; 137 137 } else { 138 debug( D_LOG_INFO, "Profile %d UserClasses retrieved", profile);138 debug(LOG_INFO, "Profile %d UserClasses retrieved", profile); 139 139 } 140 140 -
trunk/wifidog/src/centralserver.c
r89 r90 41 41 42 42 if ((he = gethostbyname(config.authserv_hostname)) == NULL) { 43 debug( D_LOG_ERR, "Failed to resolve %s via gethostbyname(): "43 debug(LOG_ERR, "Failed to resolve %s via gethostbyname(): " 44 44 "%s", config.authserv_hostname, strerror(errno)); 45 45 return(-1); … … 47 47 48 48 if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { 49 debug( D_LOG_ERR, "socket(): %s", strerror(errno));49 debug(LOG_ERR, "socket(): %s", strerror(errno)); 50 50 exit(1); 51 51 } … … 56 56 memset(&(their_addr.sin_zero), '\0', 8); 57 57 58 debug( D_LOG_INFO, "Connecting to auth server %s on port %d",58 debug(LOG_INFO, "Connecting to auth server %s on port %d", 59 59 config.authserv_hostname, config.authserv_port); 60 60 61 61 if (connect(sockfd, (struct sockaddr *)&their_addr, 62 62 sizeof(struct sockaddr)) == -1) { 63 debug( D_LOG_ERR, "connect(): %s", strerror(errno));63 debug(LOG_ERR, "connect(): %s", strerror(errno)); 64 64 return(-1); /* non-fatal */ 65 65 } … … 69 69 send(sockfd, buf, strlen(buf), 0); 70 70 71 debug( D_LOG_DEBUG, "Sending HTTP request:\n#####\n%s\n#####", buf);71 debug(LOG_DEBUG, "Sending HTTP request:\n#####\n%s\n#####", buf); 72 72 73 73 if ((numbytes = recv(sockfd, buf, MAX_BUF - 1, 0)) == -1) { 74 debug( D_LOG_ERR, "recv(): %s", strerror(errno));74 debug(LOG_ERR, "recv(): %s", strerror(errno)); 75 75 exit(1); 76 76 } … … 82 82 if ((p1 = strstr(buf, "Profile: "))) { 83 83 if (sscanf(p1, "Profile: %d", &profile) == 1) { 84 debug( D_LOG_INFO, "Auth server returned profile %d",84 debug(LOG_INFO, "Auth server returned profile %d", 85 85 profile); 86 86 return(profile); 87 87 } else { 88 debug( D_LOG_WARNING, "Auth server did not return "88 debug(LOG_WARNING, "Auth server did not return " 89 89 "expected information"); 90 90 return(-1); -
trunk/wifidog/src/commandline.c
r78 r90 41 41 printf("\n"); 42 42 printf(" -c [filename] Use this config file\n"); 43 printf(" -f Do not fork into background\n");43 printf(" -f Run in foreground\n"); 44 44 printf(" -p TCP port to listen on\n"); 45 printf(" -v Debug level\n"); 45 printf(" -d <level> Debug level\n"); 46 printf(" -s Log to syslog\n"); 46 47 printf(" -h Print usage\n"); 47 48 printf("\n"); … … 58 59 int c; 59 60 60 while (-1 != (c = getopt(argc, argv, "c:hfp: v:"))) {61 while (-1 != (c = getopt(argc, argv, "c:hfp:d:s"))) { 61 62 switch(c) { 62 63 case 'h': … … 81 82 break; 82 83 83 case ' v':84 case 'd': 84 85 if (optarg) { 85 86 config.debuglevel = atoi(optarg); 86 87 } 88 break; 89 90 case 's': 91 config.log_syslog = 1; 87 92 break; 88 93 -
trunk/wifidog/src/common.h
r88 r90 45 45 #include <errno.h> 46 46 47 #include <syslog.h> 47 48 #include <pthread.h> 48 49 -
trunk/wifidog/src/conf.c
r82 r90 28 28 29 29 #define DEFAULT_CONFIGFILE "/etc/wifidog.conf" 30 #define DEFAULT_DEBUGLEVEL D_LOG_DEBUG 30 #define DEFAULT_DAEMON 1 31 #define DEFAULT_DEBUGLEVEL LOG_INFO 31 32 #define DEFAULT_HTTPDMAXCONN 10 32 33 #define DEFAULT_GATEWAYID "default" … … 38 39 #define DEFAULT_FWSCRIPTS_PATH "." 39 40 #define DEFAULT_FWTYPE "." 41 #define DEFAULT_LOG_SYSLOG 0 42 #define DEFAULT_SYSLOG_FACILITY LOG_DAEMON 40 43 41 44 s_config config; … … 61 64 oFWType, 62 65 oUserClass, 66 oSyslogFacility, 63 67 } OpCodes; 64 68 … … 84 88 { "fwscriptspath", oFWScriptsPath }, 85 89 { "fwtype", oFWType }, 86 { "userclass", oUserClass }, 90 { "userclass", oUserClass }, 91 { "syslogfacility", oSyslogFacility }, 87 92 { NULL, oBadOption }, 88 93 }; … … 91 96 config_init(void) 92 97 { 93 debug( D_LOG_DEBUG, "Setting default config parameters");98 debug(LOG_DEBUG, "Setting default config parameters"); 94 99 config.configfile = (char *)malloc(255); 95 100 strcpy(config.configfile, DEFAULT_CONFIGFILE); 96 config.daemon = 1;97 101 config.debuglevel = DEFAULT_DEBUGLEVEL; 98 102 config.httpdmaxconn = DEFAULT_HTTPDMAXCONN; … … 112 116 config.userclasses = (char **)malloc(sizeof(char *) * 256); 113 117 memset(config.userclasses, 0, sizeof(char *) * 256); 118 config.syslog_facility = DEFAULT_SYSLOG_FACILITY; 119 config.daemon = -1; 120 config.log_syslog = DEFAULT_LOG_SYSLOG; 121 } 122 123 /** 124 * @brief Initialize the variables we override with the command line 125 * 126 * 127 * Initialize the variables we override with the command line after the config has been read 128 * if they haven't been initialized by the configuration file 129 */ 130 void 131 config_init_override(void) 132 { 133 if (!config.daemon) config.daemon = DEFAULT_DAEMON; 114 134 } 115 135 … … 123 143 return keywords[i].opcode; 124 144 125 debug( D_LOG_ERR, "%s: line %d: Bad configuration option: %s",145 debug(LOG_ERR, "%s: line %d: Bad configuration option: %s", 126 146 filename, linenum, cp); 127 147 return oBadOption; … … 135 155 int linenum = 0, opcode, value; 136 156 137 debug( D_LOG_INFO, "Reading configuration file '%s'", filename);157 debug(LOG_INFO, "Reading configuration file '%s'", filename); 138 158 139 159 if (!(fd = fopen(filename, "r"))) { 140 debug( D_LOG_ERR, "Could not open configuration file '%s', "160 debug(LOG_ERR, "Could not open configuration file '%s', " 141 161 "exiting...", filename); 142 162 exit(1); … … 172 192 173 193 if ((strncmp(s, "#", 1)) != 0) { 174 debug( D_LOG_DEBUG, "Parsing token: %s, "194 debug(LOG_DEBUG, "Parsing token: %s, " 175 195 "value: %s", s, p1); 176 196 opcode = parse_token(s, filename, linenum); … … 182 202 break; 183 203 case oDaemon: 184 if ( ((value = parse_value(p1)) != -1)) {204 if (config.daemon == -1 && ((value = parse_value(p1)) != -1)) { 185 205 config.daemon = value; 186 206 } … … 216 236 break; 217 237 case oBadOption: 238 debug(LOG_ERR, "Exiting..."); 218 239 exit(-1); 219 240 break; … … 229 250 case oFWType: 230 251 config.fwtype = get_string(p1); 252 break; 253 case oSyslogFacility: 254 sscanf(p1, "%d", &config.syslog_facility); 231 255 break; 232 256 } … … 295 319 296 320 if (missing_parms) { 297 debug( D_LOG_ERR, "Configuration is not complete, exiting...");321 debug(LOG_ERR, "Configuration is not complete, exiting..."); 298 322 exit(-1); 299 323 } … … 304 328 { 305 329 if (parm == NULL) { 306 debug( D_LOG_ERR, "%s is not set", parmname);330 debug(LOG_ERR, "%s is not set", parmname); 307 331 missing_parms = 1; 308 332 } -
trunk/wifidog/src/conf.h
r43 r90 29 29 30 30 void config_init(void); 31 void config_init_override(void); 31 32 void config_read(char *filename); 32 33 void config_validate(void); … … 55 56 char *fwtype; 56 57 char **userclasses; 58 int log_syslog; 59 int syslog_facility; 57 60 } s_config; 58 61 -
trunk/wifidog/src/debug.c
r42 r90 26 26 */ 27 27 28 #define SYSLOG_NAMES 28 29 #include "common.h" 29 30 30 31 extern s_config config; 32 //extern CODE prioritynames[]; 31 33 32 34 void 33 35 debug(int level, char *format, ...) 34 36 { 37 int i; 35 38 va_list vlist; 36 39 37 40 if (config.debuglevel >= level) { 38 41 va_start(vlist, format); 39 fprintf(stderr, "[debug %d] ", level); 40 vfprintf(stderr, format, vlist); 41 fputc('\n', stderr); 42 fflush(stderr); 42 43 if (level <= LOG_WARNING) { 44 fprintf(stderr, "[debug %d] ", level); 45 vfprintf(stderr, format, vlist); 46 fputc('\n', stderr); 47 fflush(stderr); 48 } else if (!config.daemon) { 49 fprintf(stdout, "[debug %d] ", level); 50 vfprintf(stdout, format, vlist); 51 fputc('\n', stdout); 52 fflush(stdout); 53 } 54 55 if (config.log_syslog) { 56 openlog("wifidog", LOG_PID, config.syslog_facility); 57 vsyslog(level, format, vlist); 58 closelog(); 59 } 43 60 } 44 61 } -
trunk/wifidog/src/debug.h
r9 r90 28 28 #define _DEBUG_H_ 29 29 30 #define D_LOG_ERR 031 #define D_LOG_WARNING 132 #define D_LOG_NOTICE 233 #define D_LOG_INFO 334 #define D_LOG_DEBUG 435 36 30 void debug(int level, char *format, ...); 37 31 -
trunk/wifidog/src/firewall.c
r89 r90 55 55 56 56 if (-1 == (stat(script, &st))) { 57 debug( D_LOG_ERR, "Could not find %s: %s", script,57 debug(LOG_ERR, "Could not find %s: %s", script, 58 58 strerror(errno)); 59 59 return(1); … … 83 83 84 84 if (-1 == (stat(script, &st))) { 85 debug( D_LOG_ERR, "Could not find %s: %s", script,85 debug(LOG_ERR, "Could not find %s: %s", script, 86 86 strerror(errno)); 87 87 return(1); … … 102 102 int pid, status, rc; 103 103 104 debug( D_LOG_DEBUG, "Executing '%s'", argv[0]);104 debug(LOG_DEBUG, "Executing '%s'", argv[0]); 105 105 106 106 if ((pid = fork()) < 0) { /* fork a child process */ 107 debug( D_LOG_ERR, "fork(): %s", strerror(errno));107 debug(LOG_ERR, "fork(): %s", strerror(errno)); 108 108 exit(1); 109 109 } else if (pid == 0) { /* for the child process: */ 110 110 if (execvp(*argv, argv) < 0) { /* execute the command */ 111 debug( D_LOG_ERR, "fork(): %s", strerror(errno));111 debug(LOG_ERR, "fork(): %s", strerror(errno)); 112 112 exit(1); 113 113 } … … 175 175 176 176 if (-1 == (stat(script, &st))) { 177 debug( D_LOG_ERR, "Could not find %s: %s", script,177 debug(LOG_ERR, "Could not find %s: %s", script, 178 178 strerror(errno)); 179 debug( D_LOG_ERR, "Exiting...");179 debug(LOG_ERR, "Exiting..."); 180 180 exit(1); 181 181 } 182 182 183 debug( D_LOG_NOTICE, "Setting firewall rules");183 debug(LOG_NOTICE, "Setting firewall rules"); 184 184 185 185 if ((rc = execute(command)) != 0) { 186 debug( D_LOG_ERR, "Could not setup firewall, exiting...");186 debug(LOG_ERR, "Could not setup firewall, exiting..."); 187 187 exit(1); 188 188 } … … 208 208 209 209 if (-1 == (stat(script, &st))) { 210 debug( D_LOG_ERR, "Could not find %s: %s", script,210 debug(LOG_ERR, "Could not find %s: %s", script, 211 211 strerror(errno)); 212 212 return(1); 213 213 } 214 214 215 debug( D_LOG_NOTICE, "Flushing firewall rules");215 debug(LOG_NOTICE, "Flushing firewall rules"); 216 216 217 217 return(execute(command)); … … 235 235 236 236 if (!(output = popen(script, "r"))) { 237 debug( D_LOG_ERR, "popen(): %s", strerror(errno));237 debug(LOG_ERR, "popen(): %s", strerror(errno)); 238 238 } else { 239 239 while (!(feof(output)) && output) { … … 248 248 if (p1->counter == counter) { 249 249 /* expire clients for inactivity */ 250 debug( D_LOG_INFO, "Client %s was "250 debug(LOG_INFO, "Client %s was " 251 251 "inactive", ip); 252 252 fw_deny(p1->ip, p1->mac, … … 277 277 278 278 if (p1 == NULL) { 279 debug( D_LOG_DEBUG, "Node was "279 debug(LOG_DEBUG, "Node was " 280 280 "freed while being " 281 281 "re-validated!"); 282 282 } else if (profile <= 0) { 283 283 /* failed */ 284 debug( D_LOG_NOTICE, "Auth "284 debug(LOG_NOTICE, "Auth " 285 285 "failed for client %s", 286 286 ip); … … 290 290 } else { 291 291 /* successful */ 292 debug( D_LOG_INFO, "Updated "292 debug(LOG_INFO, "Updated " 293 293 "client %s counter to " 294 294 "%ld bytes", ip, … … 342 342 343 343 if (curnode == NULL) { 344 debug( D_LOG_ERR, "Out of memory");344 debug(LOG_ERR, "Out of memory"); 345 345 exit(-1); 346 346 } … … 360 360 } 361 361 362 debug( D_LOG_INFO, "Added a new node to linked list: IP: %s Token: %s",362 debug(LOG_INFO, "Added a new node to linked list: IP: %s Token: %s", 363 363 ip, token); 364 364 … … 465 465 { 466 466 if (node->rights->end_time <= time(NULL)) { 467 debug( D_LOG_INFO, "Connection %s has expired", node->ip);467 debug(LOG_INFO, "Connection %s has expired", node->ip); 468 468 return 0; 469 469 } -
trunk/wifidog/src/gateway.c
r89 r90 45 45 46 46 // Initialize the web server 47 debug( D_LOG_NOTICE, "Creating web server on %s:%d",47 debug(LOG_NOTICE, "Creating web server on %s:%d", 48 48 config.gw_address, config.gw_port); 49 49 webserver = httpdCreate(config.gw_address, config.gw_port); 50 50 if (webserver == NULL) { 51 debug( D_LOG_ERR, "Could not create web server");52 exit(1); 53 } 54 debug( D_LOG_DEBUG, "Assigning callbacks to web server");51 debug(LOG_ERR, "Could not create web server"); 52 exit(1); 53 } 54 debug(LOG_DEBUG, "Assigning callbacks to web server"); 55 55 httpdAddCContent(webserver, "/wifidog", "about", 0, NULL, 56 56 http_callback_about); … … 69 69 pthread_detach(tid); 70 70 71 debug( D_LOG_NOTICE, "Waiting for connections");71 debug(LOG_NOTICE, "Waiting for connections"); 72 72 while(1) { 73 73 tv.tv_sec = config.checkinterval; … … 83 83 * reboot the device ? 84 84 */ 85 debug( D_LOG_ERR, "httpdGetConnection returned %d",85 debug(LOG_ERR, "httpdGetConnection returned %d", 86 86 result); 87 87 fw_destroy(); … … 91 91 * We got a connection 92 92 */ 93 debug( D_LOG_INFO, "Received connection from %s",93 debug(LOG_INFO, "Received connection from %s", 94 94 webserver->clientAddr); 95 95 if (httpdReadRequest(webserver) >=0) { … … 97 97 * We read the request fine 98 98 */ 99 debug( D_LOG_DEBUG, "Processing request from "99 debug(LOG_DEBUG, "Processing request from " 100 100 "%s", webserver->clientAddr); 101 101 httpdProcessRequest(webserver); 102 102 } 103 103 else { 104 debug( D_LOG_ERR, "No valid request received "104 debug(LOG_ERR, "No valid request received " 105 105 "from %s", webserver->clientAddr); 106 106 } 107 debug( D_LOG_DEBUG, "Closing connection with %s",107 debug(LOG_DEBUG, "Closing connection with %s", 108 108 webserver->clientAddr); 109 109 httpdEndRequest(webserver); … … 129 129 int childPid; 130 130 131 debug( D_LOG_INFO, "Forking into background");131 debug(LOG_INFO, "Forking into background"); 132 132 133 133 switch((childPid = fork())) { 134 134 case -1: /* error */ 135 debug( D_LOG_ERR, "fork(): %s", strerror(errno));135 debug(LOG_ERR, "fork(): %s", strerror(errno)); 136 136 exit(1); 137 137 break; … … 169 169 fw_destroy(); 170 170 171 debug( D_LOG_WARNING, "Exiting...");171 debug(LOG_WARNING, "Exiting..."); 172 172 exit(0); 173 173 } … … 178 178 struct sigaction sa; 179 179 180 debug( D_LOG_DEBUG, "Initializing signal handlers");180 debug(LOG_DEBUG, "Initializing signal handlers"); 181 181 182 182 sa.sa_handler = sigchld_handler; … … 184 184 sa.sa_flags = SA_RESTART; 185 185 if (sigaction(SIGCHLD, &sa, NULL) == -1) { 186 debug( D_LOG_ERR, "sigaction(): %s", strerror(errno));186 debug(LOG_ERR, "sigaction(): %s", strerror(errno)); 187 187 exit(1); 188 188 } … … 194 194 /* Trap SIGTERM */ 195 195 if (sigaction(SIGTERM, &sa, NULL) == -1) { 196 debug( D_LOG_ERR, "sigaction(): %s", strerror(errno));196 debug(LOG_ERR, "sigaction(): %s", strerror(errno)); 197 197 exit(1); 198 198 } … … 200 200 /* Trap SIGQUIT */ 201 201 if (sigaction(SIGQUIT, &sa, NULL) == -1) { 202 debug( D_LOG_ERR, "sigaction(): %s", strerror(errno));202 debug(LOG_ERR, "sigaction(): %s", strerror(errno)); 203 203 exit(1); 204 204 } … … 206 206 /* Trap SIGINT */ 207 207 if (sigaction(SIGINT, &sa, NULL) == -1) { 208 debug( D_LOG_ERR, "sigaction(): %s", strerror(errno));209 exit(1); 210 } 211 } 212 208 debug(LOG_ERR, "sigaction(): %s", strerror(errno)); 209 exit(1); 210 } 211 } 212 -
trunk/wifidog/src/http.c
r72 r90 41 41 config.gw_address, config.gw_port, 42 42 config.gw_id) == -1) { 43 debug( D_LOG_ERR, "Failed to asprintf newlocation");43 debug(LOG_ERR, "Failed to asprintf newlocation"); 44 44 httpdOutput(webserver, "Internal error occurred"); 45 45 } else { … … 52 52 config.authserv_loginurl, config.gw_address, 53 53 config.gw_port, config.gw_id); 54 debug( D_LOG_INFO, "Captured %s and re-directed them to login "54 debug(LOG_INFO, "Captured %s and re-directed them to login " 55 55 "page", webserver->clientAddr); 56 56 free(newlocation); … … 86 86 if (!(mac = arp_get(webserver->clientAddr))) { 87 87 // We could not get their MAC address 88 debug( D_LOG_ERR, "Failed to retrieve MAC address for "88 debug(LOG_ERR, "Failed to retrieve MAC address for " 89 89 "ip %s", webserver->clientAddr); 90 90 httpdOutput(webserver, "Failed to retrieve your MAC " … … 97 97 if ((node = node_find_by_ip(webserver->clientAddr)) 98 98 == NULL) { 99 debug( D_LOG_DEBUG, "New node for %s",99 debug(LOG_DEBUG, "New node for %s", 100 100 webserver->clientAddr); 101 101 node_add(webserver->clientAddr, mac, 102 102 token->value, 0, 0); 103 103 } else { 104 debug( D_LOG_DEBUG, "Node for %s already "104 debug(LOG_DEBUG, "Node for %s already " 105 105 "exists", node->ip); 106 106 if (node->rights != NULL) { 107 107 /* log off if logged in */ 108 debug( D_LOG_DEBUG, "Logging off %s "108 debug(LOG_DEBUG, "Logging off %s " 109 109 "because they tried a new " 110 110 "token", node->ip); -
trunk/wifidog/src/userclasses.c
r65 r90 252 252 insert_userclasses(tmp_uc); 253 253 254 debug( D_LOG_DEBUG, "Rule #%d: timeout %d active %d",254 debug(LOG_DEBUG, "Rule #%d: timeout %d active %d", 255 255 i, timeout, active); 256 256 } -
trunk/wifidog/wifidog.conf
r52 r90 91 91 ClientTimeout 5 92 92 93 # Parm: FWScriptsPath 94 # Default: . 95 # 96 FWScriptsPath . 97 98 # Parm: FWType 99 # Default: . 100 # 101 FWType . 102 93 103 # Parm: UserClass 94 104 # Default: UserClass 0, no rights.
