Skip to content

Commit 6dfd920

Browse files
committed
MB-43453: mcctl: Use passwd from env or stdin
Use a password stored in CB_PASSWORD if no password is provided on the command line. If '-' is specified as the password it'll read password from standard input. Make sure that the other command line utilities use the same order to fetch password from standard input or environment variable. (Cherry-pick of f01365b to alice branch.) Change-Id: I0f4a093de8b00a038a031c1f2e90872a8fa3ee1f Reviewed-on: http://review.couchbase.org/c/kv_engine/+/142926 Reviewed-by: James Harrison <[email protected]> Reviewed-by: Trond Norbye <[email protected]> Well-Formed: Build Bot <[email protected]> Tested-by: Trond Norbye <[email protected]>
1 parent b7d5bd3 commit 6dfd920

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

programs/mcctl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ADD_EXECUTABLE(mcctl mcctl.cc)
22
TARGET_LINK_LIBRARIES(mcctl
3+
getpass
34
mc_client_connection
45
mcd_util
56
mcutils

programs/mcctl/mcctl.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
#include <memcached/util.h>
2828
#include <platform/cb_malloc.h>
2929
#include <platform/platform.h>
30+
#include <programs/getpass.h>
3031
#include <programs/hostname_utils.h>
3132
#include <protocol/connection/client_connection.h>
3233
#include <protocol/connection/client_mcbp_commands.h>
3334
#include <utilities/protocol2text.h>
3435
#include <utilities/terminate_handler.h>
3536

37+
#include <cstdio>
38+
#include <cstdlib>
3639
#include <iostream>
37-
#include <stdio.h>
38-
#include <stdlib.h>
39-
#include <strings.h>
4040

4141
/**
4242
* Get the verbosity level on the server.
@@ -187,6 +187,15 @@ int main(int argc, char** argv) {
187187
}
188188
}
189189

190+
if (password == "-") {
191+
password.assign(getpass());
192+
} else if (password.empty()) {
193+
const char* env_password = std::getenv("CB_PASSWORD");
194+
if (env_password) {
195+
password = env_password;
196+
}
197+
}
198+
190199
if (optind + 1 >= argc) {
191200
usage();
192201
}

programs/mctimings/mctimings.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,17 +506,15 @@ int main(int argc, char** argv) {
506506
}
507507
}
508508

509-
if (password.empty()) {
509+
if (password == "-") {
510+
password.assign(getpass());
511+
} else if (password.empty()) {
510512
const char* env_password = std::getenv("CB_PASSWORD");
511513
if (env_password) {
512514
password = env_password;
513515
}
514516
}
515517

516-
if (password == "-") {
517-
password.assign(getpass());
518-
}
519-
520518
try {
521519
in_port_t in_port;
522520
sa_family_t fam;

0 commit comments

Comments
 (0)