implement providing password via environment variable (#815)
diff --git a/docs/invoking.rst b/docs/invoking.rst
index 79d6b95..3767742 100644
--- a/docs/invoking.rst
+++ b/docs/invoking.rst
@@ -380,8 +380,11 @@
--username username
username to use for authentication to the iperf server (if built
with OpenSSL support). The password will be prompted for inter-
- actively when the test is run.
-
+ actively when the test is run. Note, the password to use can
+ also be specified via the IPERF3_PASSWORD environment variable.
+ If this variable is present, the password prompt will be
+ skipped.
+
--rsa-public-key-path file
path to the RSA public key used to encrypt authentication cre-
dentials (if built with OpenSSL support)
diff --git a/src/iperf3.1 b/src/iperf3.1
index b9085e4..4a6d7d7 100644
--- a/src/iperf3.1
+++ b/src/iperf3.1
@@ -370,7 +370,9 @@
.BR --username " \fIusername\fR"
username to use for authentication to the iperf server (if built with
OpenSSL support).
-The password will be prompted for interactively when the test is run.
+The password will be prompted for interactively when the test is run. Note,
+the password to use can also be specified via the IPERF3_PASSWORD environment
+variable. If this variable is present, the password prompt will be skipped.
.TP
.BR --rsa-public-key-path " \fIfile\fR"
path to the RSA public key used to encrypt authentication credentials
diff --git a/src/iperf_api.c b/src/iperf_api.c
index db6fae0..999c8e1 100755
--- a/src/iperf_api.c
+++ b/src/iperf_api.c
@@ -1225,7 +1225,8 @@
char *client_password = NULL;
size_t s;
- if (iperf_getpass(&client_password, &s, stdin) < 0){
+ if ((client_password = getenv("IPERF3_PASSWORD")) == NULL &&
+ iperf_getpass(&client_password, &s, stdin) < 0){
return -1;
}