mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-24 17:19:20 +02:00
add -F option for writing pid file. Patch from misc@mandriva.org #70
This commit is contained in:
parent
2482a42d01
commit
7efdd01ae2
|
@ -21,6 +21,8 @@ iodine, iodined \- tunnel IPv4 over DNS
|
||||||
.I fragsize
|
.I fragsize
|
||||||
.B ] [-z
|
.B ] [-z
|
||||||
.I context
|
.I context
|
||||||
|
.B ] [-F
|
||||||
|
.I pidfile
|
||||||
.B ]
|
.B ]
|
||||||
.B [
|
.B [
|
||||||
.I nameserver
|
.I nameserver
|
||||||
|
@ -51,6 +53,8 @@ iodine, iodined \- tunnel IPv4 over DNS
|
||||||
.I password
|
.I password
|
||||||
.B ] [-z
|
.B ] [-z
|
||||||
.I context
|
.I context
|
||||||
|
.B ] [-F
|
||||||
|
.I pidfile
|
||||||
.B ]
|
.B ]
|
||||||
.I tunnel_ip
|
.I tunnel_ip
|
||||||
.B [
|
.B [
|
||||||
|
@ -96,6 +100,9 @@ will be used as input. Only the first 32 characters will be used.
|
||||||
.TP
|
.TP
|
||||||
.B -z context
|
.B -z context
|
||||||
Apply SELinux 'context' after initialization.
|
Apply SELinux 'context' after initialization.
|
||||||
|
.TP
|
||||||
|
.B -F pidfile
|
||||||
|
Create 'pidfile' and write process id in it.
|
||||||
.SS Client Options:
|
.SS Client Options:
|
||||||
.TP
|
.TP
|
||||||
.B -m fragsize
|
.B -m fragsize
|
||||||
|
|
20
src/common.c
20
src/common.c
|
@ -26,6 +26,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#ifdef WINDOWS32
|
#ifdef WINDOWS32
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
@ -39,6 +40,7 @@
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <syslog.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SETCON
|
#ifdef HAVE_SETCON
|
||||||
|
@ -182,6 +184,24 @@ do_setcon(char *context)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
do_pidfile(char *pidfile)
|
||||||
|
{
|
||||||
|
#ifndef WINDOWS32
|
||||||
|
FILE *file;
|
||||||
|
|
||||||
|
if ((file = fopen(pidfile, "w")) == NULL) {
|
||||||
|
syslog(LOG_ERR, "Cannot write pidfile to %s, exiting", pidfile);
|
||||||
|
err(1, "do_pidfile: Can not write pidfile to %s", pidfile);
|
||||||
|
} else {
|
||||||
|
fprintf(file, "%d\n", (int)getpid());
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "Windows version does not support pid file\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
do_detach()
|
do_detach()
|
||||||
{
|
{
|
||||||
|
|
|
@ -104,6 +104,7 @@ void close_dns(int);
|
||||||
void do_chroot(char *);
|
void do_chroot(char *);
|
||||||
void do_setcon(char *);
|
void do_setcon(char *);
|
||||||
void do_detach();
|
void do_detach();
|
||||||
|
void do_pidfile(char *);
|
||||||
|
|
||||||
void read_password(char*, size_t);
|
void read_password(char*, size_t);
|
||||||
|
|
||||||
|
|
19
src/iodine.c
19
src/iodine.c
|
@ -1158,7 +1158,8 @@ usage() {
|
||||||
extern char *__progname;
|
extern char *__progname;
|
||||||
|
|
||||||
fprintf(stderr, "Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] "
|
fprintf(stderr, "Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] "
|
||||||
"[-P password] [-m maxfragsize] [-z context] [nameserver] topdomain\n", __progname);
|
"[-P password] [-m maxfragsize] [-z context] [-F pidfile] "
|
||||||
|
"[nameserver] topdomain\n", __progname);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1168,7 +1169,8 @@ help() {
|
||||||
|
|
||||||
fprintf(stderr, "iodine IP over DNS tunneling client\n");
|
fprintf(stderr, "iodine IP over DNS tunneling client\n");
|
||||||
fprintf(stderr, "Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] "
|
fprintf(stderr, "Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] "
|
||||||
"[-P password] [-m maxfragsize] [-z context] [nameserver] topdomain\n", __progname);
|
"[-P password] [-m maxfragsize] [-z context] [-F pidfile] "
|
||||||
|
"[nameserver] topdomain\n", __progname);
|
||||||
fprintf(stderr, " -v to print version info and exit\n");
|
fprintf(stderr, " -v to print version info and exit\n");
|
||||||
fprintf(stderr, " -h to print this help and exit\n");
|
fprintf(stderr, " -h to print this help and exit\n");
|
||||||
fprintf(stderr, " -f to keep running in foreground\n");
|
fprintf(stderr, " -f to keep running in foreground\n");
|
||||||
|
@ -1178,6 +1180,7 @@ help() {
|
||||||
fprintf(stderr, " -P password used for authentication (max 32 chars will be used)\n");
|
fprintf(stderr, " -P password used for authentication (max 32 chars will be used)\n");
|
||||||
fprintf(stderr, " -m maxfragsize, to limit size of downstream packets\n");
|
fprintf(stderr, " -m maxfragsize, to limit size of downstream packets\n");
|
||||||
fprintf(stderr, " -z context, to apply specified SELinux context after initialization\n");
|
fprintf(stderr, " -z context, to apply specified SELinux context after initialization\n");
|
||||||
|
fprintf(stderr, " -F pidfile to write pid to a file\n");
|
||||||
fprintf(stderr, "nameserver is the IP number of the relaying nameserver, if absent /etc/resolv.conf is used\n");
|
fprintf(stderr, "nameserver is the IP number of the relaying nameserver, if absent /etc/resolv.conf is used\n");
|
||||||
fprintf(stderr, "topdomain is the FQDN that is delegated to the tunnel endpoint.\n");
|
fprintf(stderr, "topdomain is the FQDN that is delegated to the tunnel endpoint.\n");
|
||||||
|
|
||||||
|
@ -1208,6 +1211,7 @@ main(int argc, char **argv)
|
||||||
char *newroot;
|
char *newroot;
|
||||||
char *context;
|
char *context;
|
||||||
char *device;
|
char *device;
|
||||||
|
char *pidfile;
|
||||||
int choice;
|
int choice;
|
||||||
int tun_fd;
|
int tun_fd;
|
||||||
int dns_fd;
|
int dns_fd;
|
||||||
|
@ -1227,6 +1231,7 @@ main(int argc, char **argv)
|
||||||
context = NULL;
|
context = NULL;
|
||||||
device = NULL;
|
device = NULL;
|
||||||
chunkid = 0;
|
chunkid = 0;
|
||||||
|
pidfile = NULL;
|
||||||
|
|
||||||
outpkt.seqno = 0;
|
outpkt.seqno = 0;
|
||||||
inpkt.len = 0;
|
inpkt.len = 0;
|
||||||
|
@ -1256,7 +1261,7 @@ main(int argc, char **argv)
|
||||||
__progname++;
|
__progname++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while ((choice = getopt(argc, argv, "vfhru:t:d:P:m:")) != -1) {
|
while ((choice = getopt(argc, argv, "vfhru:t:d:P:m:F:")) != -1) {
|
||||||
switch(choice) {
|
switch(choice) {
|
||||||
case 'v':
|
case 'v':
|
||||||
version();
|
version();
|
||||||
|
@ -1294,6 +1299,9 @@ main(int argc, char **argv)
|
||||||
case 'z':
|
case 'z':
|
||||||
context = optarg;
|
context = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'F':
|
||||||
|
pidfile = optarg;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
|
@ -1382,6 +1390,9 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (foreground == 0)
|
if (foreground == 0)
|
||||||
do_detach();
|
do_detach();
|
||||||
|
|
||||||
|
if (pidfile != NULL)
|
||||||
|
do_pidfile(pidfile);
|
||||||
|
|
||||||
if (newroot != NULL)
|
if (newroot != NULL)
|
||||||
do_chroot(newroot);
|
do_chroot(newroot);
|
||||||
|
@ -1400,7 +1411,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (context != NULL)
|
if (context != NULL)
|
||||||
do_setcon(context);
|
do_setcon(context);
|
||||||
|
|
||||||
downstream_seqno = 0;
|
downstream_seqno = 0;
|
||||||
downstream_fragment = 0;
|
downstream_fragment = 0;
|
||||||
down_ack_seqno = 0;
|
down_ack_seqno = 0;
|
||||||
|
|
|
@ -1068,8 +1068,9 @@ usage() {
|
||||||
|
|
||||||
fprintf(stderr, "Usage: %s [-v] [-h] [-c] [-s] [-f] [-D] [-u user] "
|
fprintf(stderr, "Usage: %s [-v] [-h] [-c] [-s] [-f] [-D] [-u user] "
|
||||||
"[-t chrootdir] [-d device] [-m mtu] [-z context] "
|
"[-t chrootdir] [-d device] [-m mtu] [-z context] "
|
||||||
"[-l ip address to listen on] [-p port] [-n external ip] [-b dnsport] [-P password]"
|
"[-l ip address to listen on] [-p port] [-n external ip] "
|
||||||
" tunnel_ip[/netmask] topdomain\n", __progname);
|
"[-b dnsport] [-P password] [-F pidfile] "
|
||||||
|
"tunnel_ip[/netmask] topdomain\n", __progname);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1080,8 +1081,8 @@ help() {
|
||||||
fprintf(stderr, "iodine IP over DNS tunneling server\n");
|
fprintf(stderr, "iodine IP over DNS tunneling server\n");
|
||||||
fprintf(stderr, "Usage: %s [-v] [-h] [-c] [-s] [-f] [-D] [-u user] "
|
fprintf(stderr, "Usage: %s [-v] [-h] [-c] [-s] [-f] [-D] [-u user] "
|
||||||
"[-t chrootdir] [-d device] [-m mtu] [-z context] "
|
"[-t chrootdir] [-d device] [-m mtu] [-z context] "
|
||||||
"[-l ip address to listen on] [-p port] [-n external ip] [-b dnsport] [-P password]"
|
"[-l ip address to listen on] [-p port] [-n external ip] [-b dnsport] [-P password] "
|
||||||
" tunnel_ip[/netmask] topdomain\n", __progname);
|
"[-F pidfile] tunnel_ip[/netmask] topdomain\n", __progname);
|
||||||
fprintf(stderr, " -v to print version info and exit\n");
|
fprintf(stderr, " -v to print version info and exit\n");
|
||||||
fprintf(stderr, " -h to print this help and exit\n");
|
fprintf(stderr, " -h to print this help and exit\n");
|
||||||
fprintf(stderr, " -c to disable check of client IP/port on each request\n");
|
fprintf(stderr, " -c to disable check of client IP/port on each request\n");
|
||||||
|
@ -1100,6 +1101,7 @@ help() {
|
||||||
fprintf(stderr, " -n ip to respond with to NS queries\n");
|
fprintf(stderr, " -n ip to respond with to NS queries\n");
|
||||||
fprintf(stderr, " -b port to forward normal DNS queries to (on localhost)\n");
|
fprintf(stderr, " -b port to forward normal DNS queries to (on localhost)\n");
|
||||||
fprintf(stderr, " -P password used for authentication (max 32 chars will be used)\n");
|
fprintf(stderr, " -P password used for authentication (max 32 chars will be used)\n");
|
||||||
|
fprintf(stderr, " -F pidfile to write pid to a file\n");
|
||||||
fprintf(stderr, "tunnel_ip is the IP number of the local tunnel interface.\n");
|
fprintf(stderr, "tunnel_ip is the IP number of the local tunnel interface.\n");
|
||||||
fprintf(stderr, " /netmask sets the size of the tunnel network.\n");
|
fprintf(stderr, " /netmask sets the size of the tunnel network.\n");
|
||||||
fprintf(stderr, "topdomain is the FQDN that is delegated to this server.\n");
|
fprintf(stderr, "topdomain is the FQDN that is delegated to this server.\n");
|
||||||
|
@ -1128,6 +1130,7 @@ main(int argc, char **argv)
|
||||||
char *newroot;
|
char *newroot;
|
||||||
char *context;
|
char *context;
|
||||||
char *device;
|
char *device;
|
||||||
|
char *pidfile;
|
||||||
int dnsd_fd;
|
int dnsd_fd;
|
||||||
int tun_fd;
|
int tun_fd;
|
||||||
|
|
||||||
|
@ -1161,6 +1164,7 @@ main(int argc, char **argv)
|
||||||
skipipconfig = 0;
|
skipipconfig = 0;
|
||||||
debug = 0;
|
debug = 0;
|
||||||
netmask = 27;
|
netmask = 27;
|
||||||
|
pidfile = NULL;
|
||||||
|
|
||||||
b32 = get_base32_encoder();
|
b32 = get_base32_encoder();
|
||||||
|
|
||||||
|
@ -1182,7 +1186,7 @@ main(int argc, char **argv)
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
fw_query_init();
|
fw_query_init();
|
||||||
|
|
||||||
while ((choice = getopt(argc, argv, "vcsfhDu:t:d:m:l:p:n:b:P:z:")) != -1) {
|
while ((choice = getopt(argc, argv, "vcsfhDu:t:d:m:l:p:n:b:P:z:F:")) != -1) {
|
||||||
switch(choice) {
|
switch(choice) {
|
||||||
case 'v':
|
case 'v':
|
||||||
version();
|
version();
|
||||||
|
@ -1227,6 +1231,9 @@ main(int argc, char **argv)
|
||||||
bind_enable = 1;
|
bind_enable = 1;
|
||||||
bind_port = atoi(optarg);
|
bind_port = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'F':
|
||||||
|
pidfile = optarg;
|
||||||
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
strncpy(password, optarg, sizeof(password));
|
strncpy(password, optarg, sizeof(password));
|
||||||
password[sizeof(password)-1] = 0;
|
password[sizeof(password)-1] = 0;
|
||||||
|
@ -1374,6 +1381,9 @@ main(int argc, char **argv)
|
||||||
if (foreground == 0)
|
if (foreground == 0)
|
||||||
do_detach();
|
do_detach();
|
||||||
|
|
||||||
|
if (pidfile != NULL)
|
||||||
|
do_pidfile(pidfile);
|
||||||
|
|
||||||
if (newroot != NULL)
|
if (newroot != NULL)
|
||||||
do_chroot(newroot);
|
do_chroot(newroot);
|
||||||
|
|
||||||
|
@ -1392,9 +1402,6 @@ main(int argc, char **argv)
|
||||||
if (context != NULL)
|
if (context != NULL)
|
||||||
do_setcon(context);
|
do_setcon(context);
|
||||||
|
|
||||||
#ifndef WINDOWS32
|
|
||||||
openlog(__progname, LOG_NOWAIT, LOG_DAEMON);
|
|
||||||
#endif
|
|
||||||
syslog(LOG_INFO, "started, listening on port %d", port);
|
syslog(LOG_INFO, "started, listening on port %d", port);
|
||||||
|
|
||||||
tunnel(tun_fd, dnsd_fd, bind_fd);
|
tunnel(tun_fd, dnsd_fd, bind_fd);
|
||||||
|
|
Loading…
Reference in New Issue