#50 added syslog logging for version and login packets. no-op on windows

This commit is contained in:
Erik Ekman 2009-02-15 18:24:12 +00:00
parent e5582b39f4
commit f741e3d551
2 changed files with 39 additions and 0 deletions

View File

@ -7,6 +7,9 @@ CHANGES:
2009-xx-yy: x.y.z "Boringo" 2009-xx-yy: x.y.z "Boringo"
- Added initial Windows support, fixes #43. - Added initial Windows support, fixes #43.
- Added length check of autoprobe responses
- Refactored and added unit tests
- Added syslog logging for iodined on version and login packets
2009-01-23: 0.5.0 "iPassed" 2009-01-23: 0.5.0 "iPassed"
- Fixed segfault in server when sending version reject. - Fixed segfault in server when sending version reject.

View File

@ -46,6 +46,7 @@
#include <sys/uio.h> #include <sys/uio.h>
#include <pwd.h> #include <pwd.h>
#include <netdb.h> #include <netdb.h>
#include <syslog.h>
#endif #endif
#include "common.h" #include "common.h"
@ -93,6 +94,23 @@ sigint(int sig)
running = 0; running = 0;
} }
#ifdef WINDOWS32
#define LOG_EMERG 0
#define LOG_ALERT 1
#define LOG_CRIT 2
#define LOG_ERR 3
#define LOG_WARNING 4
#define LOG_NOTICE 5
#define LOG_INFO 6
#define LOG_DEBUG 7
static void
syslog(int a, const char *str, ...)
{
/* TODO: implement (add to event log), move to common.c */
;
}
#endif
static int static int
check_user_and_ip(int userid, struct query *q) check_user_and_ip(int userid, struct query *q)
{ {
@ -318,13 +336,19 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
memcpy(&(users[userid].q), q, sizeof(struct query)); memcpy(&(users[userid].q), q, sizeof(struct query));
users[userid].encoder = get_base32_encoder(); users[userid].encoder = get_base32_encoder();
send_version_response(dns_fd, VERSION_ACK, users[userid].seed, userid, q); send_version_response(dns_fd, VERSION_ACK, users[userid].seed, userid, q);
syslog(LOG_INFO, "accepted version for user #%d from %s",
userid, inet_ntoa(tempin->sin_addr));
users[userid].q.id = 0; users[userid].q.id = 0;
} else { } else {
/* No space for another user */ /* No space for another user */
send_version_response(dns_fd, VERSION_FULL, created_users, 0, q); send_version_response(dns_fd, VERSION_FULL, created_users, 0, q);
syslog(LOG_INFO, "dropped user from %s, server full",
inet_ntoa(((struct sockaddr_in *) &q->from)->sin_addr));
} }
} else { } else {
send_version_response(dns_fd, VERSION_NACK, VERSION, 0, q); send_version_response(dns_fd, VERSION_NACK, VERSION, 0, q);
syslog(LOG_INFO, "dropped user from %s, sent bad version %08X",
inet_ntoa(((struct sockaddr_in *) &q->from)->sin_addr), version);
} }
return; return;
} else if(in[0] == 'L' || in[0] == 'l') { } else if(in[0] == 'L' || in[0] == 'l') {
@ -334,6 +358,8 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
if (check_user_and_ip(userid, q) != 0) { if (check_user_and_ip(userid, q) != 0) {
write_dns(dns_fd, q, "BADIP", 5); write_dns(dns_fd, q, "BADIP", 5);
syslog(LOG_WARNING, "dropped login request from user #%d from unexpected source %s",
userid, inet_ntoa(((struct sockaddr_in *) &q->from)->sin_addr));
return; return;
} else { } else {
users[userid].last_pkt = time(NULL); users[userid].last_pkt = time(NULL);
@ -352,11 +378,14 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
write_dns(dns_fd, q, out, read); write_dns(dns_fd, q, out, read);
q->id = 0; q->id = 0;
syslog(LOG_NOTICE, "accepted password from user #%d, given IP %s", userid, tmp[1]);
free(tmp[1]); free(tmp[1]);
free(tmp[0]); free(tmp[0]);
} else { } else {
write_dns(dns_fd, q, "LNAK", 4); write_dns(dns_fd, q, "LNAK", 4);
syslog(LOG_WARNING, "rejected login request from user #%d from %s, bad password",
userid, inet_ntoa(((struct sockaddr_in *) &q->from)->sin_addr));
} }
} }
return; return;
@ -911,6 +940,7 @@ version() {
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
extern char *__progname;
in_addr_t listen_ip; in_addr_t listen_ip;
#ifndef WINDOWS32 #ifndef WINDOWS32
struct passwd *pw; struct passwd *pw;
@ -1152,9 +1182,15 @@ main(int argc, char **argv)
} }
#endif #endif
} }
#ifndef WINDOWS32
openlog(__progname, LOG_NOWAIT, LOG_DAEMON);
#endif
syslog(LOG_INFO, "started, listening on port %d", port);
tunnel(tun_fd, dnsd_fd, bind_fd); tunnel(tun_fd, dnsd_fd, bind_fd);
syslog(LOG_INFO, "stopping");
cleanup3: cleanup3:
close_dns(bind_fd); close_dns(bind_fd);
cleanup2: cleanup2: