From dfd74623a6de553d04b69c80320bd0efdc8b5813 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Sat, 19 Sep 2009 08:09:12 +0000 Subject: [PATCH] #77, get password from env variable --- CHANGELOG | 2 ++ man/iodine.8 | 16 ++++++++++++++++ src/iodine.c | 10 ++++++++-- src/iodined.c | 10 ++++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 633400d..af5d070 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -21,6 +21,8 @@ CHANGES: - Do not overwrite users CC/CFLAGS/LDFLAGS, only add to them. - Added -F option to write pidfile, based on patch from misc at mandriva.org. Fixes #70. + - Allow password to be set via environment variable, fixes #77. + Based on patch by logix. 2009-06-01: 0.5.2 "WifiFree" - Fixed client segfault on OS X, #57 diff --git a/man/iodine.8 b/man/iodine.8 index ccd5085..a8d1af6 100644 --- a/man/iodine.8 +++ b/man/iodine.8 @@ -254,6 +254,22 @@ dig \-t NS foo123.tunnel.com .B MTU issues: These issues should be solved now, with automatic fragmentation of downstream packets. There should be no need to set the MTU explicitly on the server. +.SH ENVIRONMENT +.SS IODINE_PASS +If the environment variable +.B IODINE_PASS +is set, iodine will use the value it is set to as password instead of asking +for one. The +.B -P +option still has preference. +.SS IODINED_PASS +If the environment variable +.B IODINED_PASS +is set, iodined will use the value it is set to as password instead of asking +for one. The +.B -P +option still has preference. +.El .SH BUGS File bugs at http://dev.kryo.se/iodine/ .SH AUTHORS diff --git a/src/iodine.c b/src/iodine.c index c6e7797..27aaf46 100644 --- a/src/iodine.c +++ b/src/iodine.c @@ -48,6 +48,8 @@ WSADATA wsa_data; static char *__progname; #endif +#define PASSWORD_ENV_VAR "IODINE_PASS" + static void sighandler(int sig) { @@ -260,8 +262,12 @@ main(int argc, char **argv) #endif } - if (strlen(password) == 0) - read_password(password, sizeof(password)); + if (strlen(password) == 0) { + if (NULL != getenv(PASSWORD_ENV_VAR)) + snprintf(password, sizeof(password), "%s", getenv(PASSWORD_ENV_VAR)); + else + read_password(password, sizeof(password)); + } client_set_password(password); diff --git a/src/iodined.c b/src/iodined.c index 8e3b9d7..98aed88 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -65,6 +65,8 @@ WORD req_version = MAKEWORD(2, 2); WSADATA wsa_data; #endif +#define PASSWORD_ENV_VAR "IODINED_PASS" + static int running = 1; static char *topdomain; static char password[33]; @@ -1344,8 +1346,12 @@ main(int argc, char **argv) usage(); } - if (strlen(password) == 0) - read_password(password, sizeof(password)); + if (strlen(password) == 0) { + if (NULL != getenv(PASSWORD_ENV_VAR)) + snprintf(password, sizeof(password), "%s", getenv(PASSWORD_ENV_VAR)); + else + read_password(password, sizeof(password)); + } if ((tun_fd = open_tun(device)) == -1) { retval = 1;