From 3dad36dab27403c047d9e30b62d4fed2807fcbd3 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Mon, 23 May 2016 13:23:00 +0200 Subject: [PATCH] mllib: make external_command echo the command executed Add an optional parameter to disable this behaviour, so the Curl module in v2v won't print user-sensible data (like passwords). --- builder/checksums.ml | 1 - builder/downloader.ml | 1 - builder/sigchecker.ml | 1 - mllib/common_utils.ml | 4 +++- mllib/common_utils.mli | 7 +++++-- v2v/curl.ml | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/builder/checksums.ml b/builder/checksums.ml index 95103e9c5..c8cdc9897 100644 --- a/builder/checksums.ml +++ b/builder/checksums.ml @@ -43,7 +43,6 @@ let verify_checksum csum filename = in let cmd = sprintf "%s %s" prog (quote filename) in - debug "%s" cmd; let lines = external_command cmd in match lines with | [] -> diff --git a/builder/downloader.ml b/builder/downloader.ml index e31748d39..7dc0a29dd 100644 --- a/builder/downloader.ml +++ b/builder/downloader.ml @@ -99,7 +99,6 @@ and download_to t ?(progress_bar = false) ~proxy uri filename = t.curl (if verbose () then "" else " -s -S") (quote uri) in - debug "%s" cmd; let lines = external_command cmd in if List.length lines < 1 then error (f_"unexpected output from curl command, enable debug and look at previous messages"); diff --git a/builder/sigchecker.ml b/builder/sigchecker.ml index 2b77193b9..39a27661f 100644 --- a/builder/sigchecker.ml +++ b/builder/sigchecker.ml @@ -69,7 +69,6 @@ let import_keyfile ~gpg ~gpghome ?(trust = true) keyfile = * fingerprint of the subkeys. *) let cmd = sprintf "%s --homedir %s --with-colons --with-fingerprint --with-fingerprint --list-keys %s" gpg gpghome !fingerprint in - debug "%s" cmd; let lines = external_command cmd in let current = ref None in let subkeys = ref [] in diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml index 0ffa92cd9..32071f4d4 100644 --- a/mllib/common_utils.ml +++ b/mllib/common_utils.ml @@ -649,7 +649,9 @@ let compare_lvm2_uuids uuid1 uuid2 = loop 0 0 (* Run an external command, slurp up the output as a list of lines. *) -let external_command cmd = +let external_command ?(echo_cmd = true) cmd = + if echo_cmd then + debug "%s" cmd; let chan = Unix.open_process_in cmd in let lines = ref [] in (try while true do lines := input_line chan :: !lines done diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli index 666e02337..c55e04cb9 100644 --- a/mllib/common_utils.mli +++ b/mllib/common_utils.mli @@ -239,8 +239,11 @@ val compare_version : string -> string -> int val compare_lvm2_uuids : string -> string -> int (** Compare two LVM2 UUIDs, ignoring '-' characters. *) -val external_command : string -> string list -(** Run an external command, slurp up the output as a list of lines. *) +val external_command : ?echo_cmd:bool -> string -> string list +(** Run an external command, slurp up the output as a list of lines. + + [echo_cmd] specifies whether to output the full command on verbose + mode, and it's on by default. *) val uuidgen : unit -> string (** Run uuidgen to return a random UUID. *) diff --git a/v2v/curl.ml b/v2v/curl.ml index 046cba245..f0af16042 100644 --- a/v2v/curl.ml +++ b/v2v/curl.ml @@ -48,7 +48,7 @@ let run curl_args = close_out chan; let cmd = sprintf "curl -q --config %s" (Filename.quote config_file) in - let lines = external_command cmd in + let lines = external_command ~echo_cmd:false cmd in Unix.unlink config_file; lines