diff --git a/CHANGELOG b/CHANGELOG index 82ec035..cce25f7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ CHANGES: Debian bug #477692 by Vincent Bernat, controlled by -s switch - Applied a security patch from Andrew Griffiths, use setgroups() to limit the groups of the user + - Applied a patch to make iodine work on (Open)Solaris, from Albert Lee 2007-11-30: 0.4.1 "Tea Online" - Introduced encoding API diff --git a/src/common.c b/src/common.c index 52f917f..d8434d9 100644 --- a/src/common.c +++ b/src/common.c @@ -1,4 +1,5 @@ /* Copyright (c) 2006-2007 Bjorn Andersson , Erik Ekman + * Copyright (c) 2007 Albert Lee . * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -21,6 +22,8 @@ #endif #include #include +#include +#include #include #include #include @@ -29,10 +32,48 @@ #include #include #include +#include #include #include "common.h" +/* daemon(3) exists only in 4.4BSD or later, and in GNU libc */ +#if !(defined(BSD) && (BSD >= 199306)) && !defined(__GLIBC__) +static int daemon(int nochdir, int noclose) +{ + int fd, i; + + switch (fork()) { + case 0: + break; + case -1: + return -1; + default: + _exit(0); + } + + if (!nochdir) { + chdir("/"); + } + + if (setsid() < 0) { + return -1; + } + + if (!noclose) { + if (fd = open("/dev/null", O_RDWR) >= 0) { + for (i = 0; i < 3; i++) { + dup2(fd, i); + } + if (fd > 2) { + close(fd); + } + } + } + return 0; +} +#endif + int open_dns(int localport, in_addr_t listen_ip) { diff --git a/src/iodine.c b/src/iodine.c index ff4502f..c7a3c66 100644 --- a/src/iodine.c +++ b/src/iodine.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -77,6 +78,10 @@ static struct encoder *dataenc; /* result of case preservation check done after login */ static int case_preserved; +#if !defined(BSD) && !defined(__GLIBC__) +static char *__progname; +#endif + static void sighandler(int sig) { @@ -634,6 +639,14 @@ main(int argc, char **argv) b32 = get_base32_encoder(); dataenc = get_base32_encoder(); +#if !defined(BSD) && !defined(__GLIBC__) + __progname = strrchr(argv[0], '/'); + if (__progname == NULL) + __progname = argv[0]; + else + __progname++; +#endif + while ((choice = getopt(argc, argv, "vfhu:t:d:P:")) != -1) { switch(choice) { case 'v': diff --git a/src/iodined.c b/src/iodined.c index 2be01c5..1a9f466 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,10 @@ static struct encoder *b32; static int my_mtu; static in_addr_t my_ip; +#if !defined(BSD) && !defined(__GLIBC__) +static char *__progname; +#endif + static int read_dns(int, struct query *, char *, int); static void write_dns(int, struct query *, char *, int); @@ -462,6 +467,14 @@ main(int argc, char **argv) b32 = get_base32_encoder(); +#if !defined(BSD) && !defined(__GLIBC__) + __progname = strrchr(argv[0], '/'); + if (__progname == NULL) + __progname = argv[0]; + else + __progname++; +#endif + memset(password, 0, sizeof(password)); srand(time(NULL));