From 68dac1b6c65cbf67d036af89247ffe0e59586df8 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 19 Nov 2016 09:43:39 -0500 Subject: [PATCH] CmdDiagnostics: Made sure file existence is checked before readability --- src/commands/CmdDiagnostics.cpp | 69 ++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/src/commands/CmdDiagnostics.cpp b/src/commands/CmdDiagnostics.cpp index 3ed6a99bc..9e0a50fd3 100644 --- a/src/commands/CmdDiagnostics.cpp +++ b/src/commands/CmdDiagnostics.cpp @@ -234,13 +234,53 @@ int CmdDiagnostics::execute (std::string& output) << context.config.get ("taskd.server") << '\n'; - if (context.config.get ("taskd.ca") != "") - out << " CA: " - << context.config.get ("taskd.ca") - << (File (context.config.get ("taskd.ca")).readable () - ? ", readable, " : ", not readable, ") - << File (context.config.get ("taskd.ca")).size () - << " bytes\n"; + std::string ca_pem = context.config.get ("taskd.ca"); + out << " CA: "; + if (ca_pem != "") + { + File file_ca (ca_pem); + if (file_ca.exists ()) + out << ca_pem + << (file_ca.readable () ? ", readable, " : ", not readable, ") + << file_ca.size () + << " bytes\n"; + else + out << "not found\n"; + } + else + out << "-\n"; + + std::string cert_pem = context.config.get ("taskd.certificate"); + out << "Certificate: "; + if (cert_pem != "") + { + File file_cert (cert_pem); + if (file_cert.exists ()) + out << cert_pem + << (file_cert.readable () ? ", readable, " : ", not readable, ") + << file_cert.size () + << " bytes\n"; + else + out << "not found\n"; + } + else + out << "-\n"; + + std::string key_pem = context.config.get ("taskd.key"); + out << " Key: "; + if (key_pem != "") + { + File file_key (key_pem); + if (file_key.exists ()) + out << key_pem + << (file_key.readable () ? ", readable, " : ", not readable, ") + << file_key.size () + << " bytes\n"; + else + out << "not found\n"; + } + else + out << "-\n"; std::string trust_value = context.config.get ("taskd.trust"); if (trust_value == "strict" || @@ -250,20 +290,6 @@ int CmdDiagnostics::execute (std::string& output) else out << " Trust: Bad value - see 'man taskrc'\n"; - out << "Certificate: " - << context.config.get ("taskd.certificate") - << (File (context.config.get ("taskd.certificate")).readable () - ? ", readable, " : ", not readable, ") - << File (context.config.get ("taskd.certificate")).size () - << " bytes\n"; - - out << " Key: " - << context.config.get ("taskd.key") - << (File (context.config.get ("taskd.key")).readable () - ? ", readable, " : ", not readable, ") - << File (context.config.get ("taskd.key")).size () - << " bytes\n"; - out << " Ciphers: " << context.config.get ("taskd.ciphers") << '\n'; @@ -412,7 +438,6 @@ int CmdDiagnostics::execute (std::string& output) << '\n'; } - // Check all the UUID references bool noBrokenRefs = true;