[Libreoffice-commits] online.git: tools/Config.cpp

2019-08-16 Thread Ashod Nakashian (via logerrit)
 tools/Config.cpp |   30 ++
 1 file changed, 30 insertions(+)

New commits:
commit 159e6d0f7288cb44b81ab72c9f3c99dfb69f4f4c
Author: Ashod Nakashian 
AuthorDate: Mon Apr 1 00:13:03 2019 -0400
Commit: Ashod Nakashian 
CommitDate: Sat Aug 17 04:28:49 2019 +0200

looltool: support anonymizing strings

The user is able to override the salt,
or use the one from the config file.

Change-Id: Ida634374549fb490ec2437f557d46c44d4760c56
Reviewed-on: https://gerrit.libreoffice.org/70036
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 
Reviewed-on: https://gerrit.libreoffice.org/71094

diff --git a/tools/Config.cpp b/tools/Config.cpp
index 3bffb0ddc..2cf45ac3f 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -74,6 +74,8 @@ public:
 static std::string ConfigFile;
 static std::string SupportKeyString;
 static bool SupportKeyStringProvided;
+static std::uint64_t AnonymizationSalt;
+static bool AnonymizationSaltProvided;
 
 protected:
 void defineOptions(OptionSet&) override;
@@ -91,6 +93,8 @@ std::string Config::ConfigFile =
 
 std::string Config::SupportKeyString;
 bool Config::SupportKeyStringProvided = false;
+std::uint64_t Config::AnonymizationSalt = 0;
+bool Config::AnonymizationSaltProvided = false;
 
 void Config::displayHelp()
 {
@@ -107,6 +111,7 @@ void Config::displayHelp()
 // Command list
 std::cout << std::endl
   << "Commands: " << std::endl
+  << "anonymize [string-1]...[string-n]" << std::endl
   << "set-admin-password" << std::endl
 #if ENABLE_SUPPORT_KEY
   << "set-support-key" << std::endl
@@ -146,6 +151,11 @@ void Config::defineOptions(OptionSet& optionSet)
 .repeatable(false)
 .argument("key"));
 #endif
+
+optionSet.addOption(Option("anonymization-salt", "", "Anonymize strings 
with the given 64-bit salt instead of the one in the config file.")
+.required(false)
+.repeatable(false)
+.argument("salt"));
 }
 
 void Config::handleOption(const std::string& optionName, const std::string& 
optionValue)
@@ -195,6 +205,12 @@ void Config::handleOption(const std::string& optionName, 
const std::string& opti
 SupportKeyString = optionValue;
 SupportKeyStringProvided = true;
 }
+else if (optionName == "anonymization-salt")
+{
+AnonymizationSalt = std::stoull(optionValue);
+AnonymizationSaltProvided = true;
+std::cout << "Anonymization Salt: [" << AnonymizationSalt << "]." << 
std::endl;
+}
 }
 
 int Config::main(const std::vector& args)
@@ -354,6 +370,20 @@ int Config::main(const std::vector& args)
 if (retval != 0)
 std::cerr << "Error when executing command." << std::endl;
 }
+else if (args[0] == "anonymize")
+{
+if (!AnonymizationSaltProvided)
+{
+const std::string val = 
_loolConfig.getString("logging.anonymize.anonymization_salt");
+AnonymizationSalt = std::stoull(val);
+std::cout << "Anonymization Salt: [" << AnonymizationSalt << "]." 
<< std::endl;
+}
+
+for (std::size_t i = 1; i < args.size(); ++i)
+{
+std::cout << "[" << args[i] << "]: " << 
Util::anonymizeUrl(args[i], AnonymizationSalt) << std::endl;
+}
+}
 else
 {
 std::cerr << "No such command, \"" << args[0]  << "\"" << std::endl;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: tools/Config.cpp

2019-01-16 Thread Libreoffice Gerrit user
 tools/Config.cpp |   39 ---
 1 file changed, 24 insertions(+), 15 deletions(-)

New commits:
commit e1adc6ff17f21a452218e102dbe6ac468c29e885
Author: Miklos Vajna 
AuthorDate: Wed Jan 16 08:59:45 2019 +0100
Commit: Miklos Vajna 
CommitDate: Wed Jan 16 08:59:45 2019 +0100

tools: make members private in Config

Change-Id: I3127d0d1f460ea535295fbf8dc2bb1856b1c2ff8

diff --git a/tools/Config.cpp b/tools/Config.cpp
index 2c257c601..faff5e550 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -46,9 +46,18 @@ public:
 
 struct AdminConfig
 {
-unsigned pwdSaltLength = 128;
-unsigned pwdIterations = 1;
-unsigned pwdHashLength = 128;
+protected:
+unsigned _pwdSaltLength = 128;
+unsigned _pwdIterations = 1;
+unsigned _pwdHashLength = 128;
+public:
+
+void setPwdSaltLength(unsigned pwdSaltLength) { _pwdSaltLength = 
pwdSaltLength; }
+unsigned getPwdSaltLength() const { return _pwdSaltLength; }
+void setPwdIterations(unsigned pwdIterations) { _pwdIterations = 
pwdIterations; }
+unsigned getPwdIterations() const { return _pwdIterations; }
+void setPwdHashLength(unsigned pwdHashLength) { _pwdHashLength = 
pwdHashLength; }
+unsigned getPwdHashLength() const { return _pwdHashLength; }
 };
 
 // Config tool to change loolwsd configuration (loolwsd.xml)
@@ -159,7 +168,7 @@ void Config::handleOption(const std::string& optionName, 
const std::string& opti
 len = MIN_PWD_SALT_LENGTH;
 std::cout << "Password salt length adjusted to minimum " << len << 
std::endl;
 }
-_adminConfig.pwdSaltLength = len;
+_adminConfig.setPwdSaltLength(len);
 }
 else if (optionName == "pwd-iterations")
 {
@@ -169,7 +178,7 @@ void Config::handleOption(const std::string& optionName, 
const std::string& opti
 len = MIN_PWD_ITERATIONS;
 std::cout << "Password iteration adjusted to minimum " << len << 
std::endl;
 }
-_adminConfig.pwdIterations = len;
+_adminConfig.setPwdIterations(len);
 }
 else if (optionName == "pwd-hash-length")
 {
@@ -179,7 +188,7 @@ void Config::handleOption(const std::string& optionName, 
const std::string& opti
 len = MIN_PWD_HASH_LENGTH;
 std::cout << "Password hash length adjusted to minimum " << len << 
std::endl;
 }
-_adminConfig.pwdHashLength = len;
+_adminConfig.setPwdHashLength(len);
 }
 else if (optionName == "support-key")
 {
@@ -204,9 +213,9 @@ int Config::main(const std::vector& args)
 if (args[0] == "set-admin-password")
 {
 #if HAVE_PKCS5_PBKDF2_HMAC
-unsigned char pwdhash[_adminConfig.pwdHashLength];
-unsigned char salt[_adminConfig.pwdSaltLength];
-RAND_bytes(salt, _adminConfig.pwdSaltLength);
+unsigned char pwdhash[_adminConfig.getPwdHashLength()];
+unsigned char salt[_adminConfig.getPwdSaltLength()];
+RAND_bytes(salt, _adminConfig.getPwdSaltLength());
 std::stringstream stream;
 
 // Ask for admin username
@@ -242,13 +251,13 @@ int Config::main(const std::vector& args)
 
 // Do the magic !
 PKCS5_PBKDF2_HMAC(adminPwd.c_str(), -1,
-  salt, _adminConfig.pwdSaltLength,
-  _adminConfig.pwdIterations,
+  salt, _adminConfig.getPwdSaltLength(),
+  _adminConfig.getPwdIterations(),
   EVP_sha512(),
-  _adminConfig.pwdHashLength, pwdhash);
+  _adminConfig.getPwdHashLength(), pwdhash);
 
 // Make salt randomness readable
-for (unsigned j = 0; j < _adminConfig.pwdSaltLength; ++j)
+for (unsigned j = 0; j < _adminConfig.getPwdSaltLength(); ++j)
 stream << std::hex << std::setw(2) << std::setfill('0') << 
static_cast(salt[j]);
 const std::string saltHash = stream.str();
 
@@ -257,12 +266,12 @@ int Config::main(const std::vector& args)
 stream.clear();
 
 // Make the hashed password readable
-for (unsigned j = 0; j < _adminConfig.pwdHashLength; ++j)
+for (unsigned j = 0; j < _adminConfig.getPwdHashLength(); ++j)
 stream << std::hex << std::setw(2) << std::setfill('0') << 
static_cast(pwdhash[j]);
 const std::string passwordHash = stream.str();
 
 std::stringstream pwdConfigValue("pbkdf2.sha512.", std::ios_base::in | 
std::ios_base::out | std::ios_base::ate);
-pwdConfigValue << std::to_string(_adminConfig.pwdIterations) << ".";
+pwdConfigValue << std::to_string(_adminConfig.getPwdIterations()) << 
".";
 pwdConfigValue << saltHash << "." << passwordHash;
 _loolConfig.setString("admin_console.username", adminUser);
 _loolConfig.setString("admin_console.secure_password[@desc]",
___
Libreoffice-commits 

[Libreoffice-commits] online.git: tools/Config.cpp

2019-01-09 Thread Libreoffice Gerrit user
 tools/Config.cpp |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

New commits:
commit c377ca3fb2d1e28646bf64b38a641bc07ffb6bc4
Author: Samuel Mehrbrodt 
AuthorDate: Wed Jan 9 10:28:25 2019 +0100
Commit: Samuel Mehrbrodt 
CommitDate: Wed Jan 9 10:45:06 2019 +0100

loolconfig: Only show "config updated" message when something was changed

Change-Id: I2d2b1e4b57cccbbe6f5608f0468bc9dfed3fd120
Reviewed-on: https://gerrit.libreoffice.org/65997
Reviewed-by: Samuel Mehrbrodt 
Tested-by: Samuel Mehrbrodt 

diff --git a/tools/Config.cpp b/tools/Config.cpp
index 0e2505283..2c257c601 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -300,6 +300,7 @@ int Config::main(const std::vector& args)
 {
 std::cerr << "Valid for " << validDays << " days - setting 
to config\n";
 _loolConfig.setString("support_key", supportKeyString);
+changed = true;
 }
 }
 }
@@ -307,8 +308,8 @@ int Config::main(const std::vector& args)
 {
 std::cerr << "Removing empty support key\n";
 _loolConfig.remove("support_key");
+changed = true;
 }
-changed = true;
 }
 #endif
 else if (args[0] == "set")
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: tools/Config.cpp

2018-11-13 Thread Libreoffice Gerrit user
 tools/Config.cpp |   10 ++
 1 file changed, 10 insertions(+)

New commits:
commit 96760c5e4312e924cbce550bced14384dfce940b
Author: Andras Timar 
AuthorDate: Tue Nov 13 14:32:37 2018 +0100
Commit: Andras Timar 
CommitDate: Tue Nov 13 14:32:37 2018 +0100

ask for username (default to 'admin' if nothing set) with 'loolconfig 
set-admin-password'

Change-Id: I04bf3d225e4149ed69bc55e14d1ced1dd3f8f7ea

diff --git a/tools/Config.cpp b/tools/Config.cpp
index cb35a6fde..0e2505283 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -209,6 +209,15 @@ int Config::main(const std::vector& args)
 RAND_bytes(salt, _adminConfig.pwdSaltLength);
 std::stringstream stream;
 
+// Ask for admin username
+std::string adminUser;
+std::cout << "Enter admin username [admin]: ";
+std::getline(std::cin, adminUser);
+if (adminUser.empty())
+{
+adminUser = "admin";
+}
+
 // Ask for user password
 termios oldTermios;
 tcgetattr(STDIN_FILENO, );
@@ -255,6 +264,7 @@ int Config::main(const std::vector& args)
 std::stringstream pwdConfigValue("pbkdf2.sha512.", std::ios_base::in | 
std::ios_base::out | std::ios_base::ate);
 pwdConfigValue << std::to_string(_adminConfig.pwdIterations) << ".";
 pwdConfigValue << saltHash << "." << passwordHash;
+_loolConfig.setString("admin_console.username", adminUser);
 _loolConfig.setString("admin_console.secure_password[@desc]",
   "Salt and password hash combination generated 
using PBKDF2 with SHA512 digest.");
 _loolConfig.setString("admin_console.secure_password", 
pwdConfigValue.str());
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: tools/Config.cpp

2018-03-28 Thread Aron Budea
 tools/Config.cpp |3 +++
 1 file changed, 3 insertions(+)

New commits:
commit c20c51d8a5ed70d1b11e75f5b837be6439945d50
Author: Aron Budea 
Date:   Tue Mar 27 14:35:19 2018 +0200

Fix unused-result warning.

Change-Id: I31fa4edd68e8a5ba973c159599e71e74406b8e6e
Reviewed-on: https://gerrit.libreoffice.org/51947
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/tools/Config.cpp b/tools/Config.cpp
index aaa06e2c6..cb35a6fde 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -329,7 +329,10 @@ int Config::main(const std::vector& args)
 const char command[] = "su lool --shell=/bin/sh -c 
'loolwsd-systemplate-setup /opt/lool/systemplate " LO_PATH " >/dev/null 2>&1'";
 std::cout << "Running the following command:" << std::endl
   << command << std::endl;
+
 retval = system(command);
+if (retval != 0)
+std::cerr << "Error when executing command." << std::endl;
 }
 else
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: tools/Config.cpp

2018-03-28 Thread Jan Holesovsky
 tools/Config.cpp |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

New commits:
commit 3304e909359040607f0a08a51dce852e4e6f7009
Author: Jan Holesovsky 
Date:   Wed Mar 28 09:26:56 2018 +0200

The return value of system() shouldn't be ignored.

Change-Id: I7422bfb3997c205333a8558884c65f2ff3795e38

diff --git a/tools/Config.cpp b/tools/Config.cpp
index 0f4914180..aaa06e2c6 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -197,6 +197,7 @@ int Config::main(const std::vector& args)
 return Application::EXIT_NOINPUT;
 }
 
+int retval = Application::EXIT_OK;
 bool changed = false;
 _loolConfig.load(ConfigFile);
 
@@ -328,7 +329,7 @@ int Config::main(const std::vector& args)
 const char command[] = "su lool --shell=/bin/sh -c 
'loolwsd-systemplate-setup /opt/lool/systemplate " LO_PATH " >/dev/null 2>&1'";
 std::cout << "Running the following command:" << std::endl
   << command << std::endl;
-system(command);
+retval = system(command);
 }
 else
 {
@@ -343,8 +344,7 @@ int Config::main(const std::vector& args)
 std::cout << "Saved" << std::endl;
 }
 
-// This tool only handles options, nothing to do here
-return Application::EXIT_OK;
+return retval;
 }
 
 POCO_APP_MAIN(Config);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: tools/Config.cpp

2018-03-26 Thread Jan Holesovsky
 tools/Config.cpp |   14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

New commits:
commit aaf76a13ba81ccf23a0e43032af3cc604fcce865
Author: Jan Holesovsky 
Date:   Thu Mar 15 10:39:09 2018 +0100

loolconfig: Create a shortcut for running the systemplate update.

Change-Id: I082cf6e3f560a9c1880f0680ad4d2876d055dbc4
Reviewed-on: https://gerrit.libreoffice.org/51315
Reviewed-by: Andras Timar 
Tested-by: Andras Timar 

diff --git a/tools/Config.cpp b/tools/Config.cpp
index b5c815afe..0f4914180 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -98,11 +98,12 @@ void Config::displayHelp()
 // Command list
 std::cout << std::endl
   << "Commands: " << std::endl
-  << "set-admin-password\n"
+  << "set-admin-password" << std::endl
 #if ENABLE_SUPPORT_KEY
-  << "set-support-key\n"
+  << "set-support-key" << std::endl
 #endif
-  << "set  " << std::endl;
+  << "set  " << std::endl
+  << "update-system-template" << std::endl << std::endl;
 }
 
 void Config::defineOptions(OptionSet& optionSet)
@@ -322,6 +323,13 @@ int Config::main(const std::vector& args)
   << "set logging.level trace" << std::endl;
 
 }
+else if (args[0] == "update-system-template")
+{
+const char command[] = "su lool --shell=/bin/sh -c 
'loolwsd-systemplate-setup /opt/lool/systemplate " LO_PATH " >/dev/null 2>&1'";
+std::cout << "Running the following command:" << std::endl
+  << command << std::endl;
+system(command);
+}
 else
 {
 std::cerr << "No such command, \"" << args[0]  << "\"" << std::endl;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: tools/Config.cpp

2018-02-12 Thread Pranav Kant
 tools/Config.cpp |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 463fc6044021b94440701bd80fb7a9a7ee0ae2d0
Author: Pranav Kant 
Date:   Tue Feb 13 12:33:01 2018 +0530

loolconfig: set-raw-config -> set

Change-Id: I7821bcf7bf8a6b8247e824d18b1d9f29b8db8851

diff --git a/tools/Config.cpp b/tools/Config.cpp
index 79f4398b..b5c815af 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -102,7 +102,7 @@ void Config::displayHelp()
 #if ENABLE_SUPPORT_KEY
   << "set-support-key\n"
 #endif
-  << "set-raw-config  " << std::endl;
+  << "set  " << std::endl;
 }
 
 void Config::defineOptions(OptionSet& optionSet)
@@ -299,7 +299,7 @@ int Config::main(const std::vector& args)
 changed = true;
 }
 #endif
-else if (args[0] == "set-raw-config")
+else if (args[0] == "set")
 {
 if (args.size() == 3)
 {
@@ -317,9 +317,9 @@ int Config::main(const std::vector& args)
 std::cerr << "No property, \"" << args[1] << "\"," << " found 
in config file." << std::endl;
 }
 else
-std::cerr << "set-raw-config expects a key and value as arguments" 
<< std::endl
+std::cerr << "set expects a key and value as arguments" << 
std::endl
   << "Eg: " << std::endl
-  << "set-raw-config logging.level trace" << std::endl;
+  << "set logging.level trace" << std::endl;
 
 }
 else
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: tools/Config.cpp

2018-01-26 Thread Pranav Kant
 tools/Config.cpp |  234 +++
 1 file changed, 136 insertions(+), 98 deletions(-)

New commits:
commit f942e5a29ecb7aecdc0b085f8bafa7ac6a5d6f86
Author: Pranav Kant 
Date:   Fri Jan 26 18:29:12 2018 +0530

loolconfig: Allow changing loolwsd.xml

eg: `loolconfig set-raw-config admin_console.password admin`

And while at it, stop processing all the arguments given to the command.
Regard the first argument (without any "--") as command and let the
specific-command handling routine handle the remaining arguments the way
it wants.

Change-Id: I6cc406c56701dba2b99e0a3c4a98c505df70ee60

diff --git a/tools/Config.cpp b/tools/Config.cpp
index e12bbf4e..79f4398b 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -72,7 +72,14 @@ protected:
 int main(const std::vector&) override;
 };
 
-std::string Config::ConfigFile = LOOLWSD_CONFIGDIR "/loolwsd.xml";
+std::string Config::ConfigFile =
+#if ENABLE_DEBUG
+DEBUG_ABSSRCDIR
+#else
+LOOLWSD_CONFIGDIR
+#endif
+"/loolwsd.xml";
+
 std::string Config::SupportKeyString;
 bool Config::SupportKeyStringProvided = false;
 
@@ -80,17 +87,22 @@ void Config::displayHelp()
 {
 HelpFormatter helpFormatter(options());
 helpFormatter.setCommand(commandName());
-
-std::string usage = "set-admin-password";
-#if ENABLE_SUPPORT_KEY
-usage = "(set-admin-password|set-support-key)";
-#endif
-
-helpFormatter.setUsage(usage + " OPTIONS");
+helpFormatter.setUsage("COMMAND [OPTIONS]");
 helpFormatter.setHeader("loolconfig - Configuration tool for LibreOffice 
Online.\n"
 "\n"
-"Some options make sense only with a concrete 
command, in that case the command name is specified in brackets.");
+"Some options make sense only with a specific 
command.\n\n"
+"Options:");
+
 helpFormatter.format(std::cout);
+
+// Command list
+std::cout << std::endl
+  << "Commands: " << std::endl
+  << "set-admin-password\n"
+#if ENABLE_SUPPORT_KEY
+  << "set-support-key\n"
+#endif
+  << "set-raw-config  " << std::endl;
 }
 
 void Config::defineOptions(OptionSet& optionSet)
@@ -187,109 +199,135 @@ int Config::main(const std::vector& args)
 bool changed = false;
 _loolConfig.load(ConfigFile);
 
-for (unsigned long i = 0; i < args.size(); i++)
+if (args[0] == "set-admin-password")
 {
-if (args[i] == "set-admin-password")
-{
 #if HAVE_PKCS5_PBKDF2_HMAC
-unsigned char pwdhash[_adminConfig.pwdHashLength];
-unsigned char salt[_adminConfig.pwdSaltLength];
-RAND_bytes(salt, _adminConfig.pwdSaltLength);
-std::stringstream stream;
-
-// Ask for user password
-termios oldTermios;
-tcgetattr(STDIN_FILENO, );
-termios newTermios = oldTermios;
-// Disable user input mirroring on console for password input
-newTermios.c_lflag &= ~ECHO;
-tcsetattr(STDIN_FILENO, TCSANOW, );
-std::string adminPwd;
-std::cout << "Enter admin password: ";
-std::getline(std::cin, adminPwd);
-std::string reAdminPwd;
-std::cout << std::endl << "Confirm admin password: ";
-std::getline(std::cin, reAdminPwd);
-std::cout << std::endl;
-// Set the termios to old state
-tcsetattr(STDIN_FILENO, TCSANOW, );
-if (adminPwd != reAdminPwd)
-{
-std::cout << "Password mismatch." << std::endl;
-return Application::EXIT_DATAERR;
-}
+unsigned char pwdhash[_adminConfig.pwdHashLength];
+unsigned char salt[_adminConfig.pwdSaltLength];
+RAND_bytes(salt, _adminConfig.pwdSaltLength);
+std::stringstream stream;
+
+// Ask for user password
+termios oldTermios;
+tcgetattr(STDIN_FILENO, );
+termios newTermios = oldTermios;
+// Disable user input mirroring on console for password input
+newTermios.c_lflag &= ~ECHO;
+tcsetattr(STDIN_FILENO, TCSANOW, );
+std::string adminPwd;
+std::cout << "Enter admin password: ";
+std::getline(std::cin, adminPwd);
+std::string reAdminPwd;
+std::cout << std::endl << "Confirm admin password: ";
+std::getline(std::cin, reAdminPwd);
+std::cout << std::endl;
+// Set the termios to old state
+tcsetattr(STDIN_FILENO, TCSANOW, );
+if (adminPwd != reAdminPwd)
+{
+std::cout << "Password mismatch." << std::endl;
+return Application::EXIT_DATAERR;
+}
 
-// Do the magic !
-PKCS5_PBKDF2_HMAC(adminPwd.c_str(), -1,
-  salt, 

[Libreoffice-commits] online.git: tools/Config.cpp

2017-10-17 Thread Miklos Vajna
 tools/Config.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 409be28c8b57fe1eaa64c974428a1752f52feb51
Author: Miklos Vajna 
Date:   Tue Oct 17 09:04:04 2017 +0200

Config: avoid redundant string initialization

Change-Id: Ia90aae804c3656f54e8f36ca5ef1fd52a99e05c9

diff --git a/tools/Config.cpp b/tools/Config.cpp
index dcf3d07a..143cde02 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -73,7 +73,7 @@ protected:
 };
 
 std::string Config::ConfigFile = LOOLWSD_CONFIGDIR "/loolwsd.xml";
-std::string Config::SupportKeyString = "";
+std::string Config::SupportKeyString;
 bool Config::SupportKeyStringProvided = false;
 
 void Config::displayHelp()
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: tools/Config.cpp

2017-10-12 Thread Andras Timar
 tools/Config.cpp |2 ++
 1 file changed, 2 insertions(+)

New commits:
commit 11ad1b4ab98706e73ad208c79da2e52d9857cc19
Author: Andras Timar 
Date:   Thu Oct 12 21:40:55 2017 +0200

loolconfig: don't show option for set-support-key, it it's not compiled in

Change-Id: Ie3baeee860e5ef0a797a3061373e266f40b41809

diff --git a/tools/Config.cpp b/tools/Config.cpp
index 6de6597f..dcf3d07a 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -118,10 +118,12 @@ void Config::defineOptions(OptionSet& optionSet)
 .repeatable(false)
 .argument("number"));
 
+#if ENABLE_SUPPORT_KEY
 optionSet.addOption(Option("support-key", "", "Specify the support key 
[set-support-key].")
 .required(false)
 .repeatable(false)
 .argument("key"));
+#endif
 }
 
 void Config::handleOption(const std::string& optionName, const std::string& 
optionValue)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: tools/Config.cpp

2017-08-31 Thread Pranav Kant
 tools/Config.cpp |   29 -
 1 file changed, 20 insertions(+), 9 deletions(-)

New commits:
commit 67bf4dc212aa384e4ccbc4b48afdd62964f9a2a9
Author: Pranav Kant 
Date:   Thu Aug 31 09:24:05 2017 +0530

loolconfig: print help information from option set

Change-Id: Ifbc5ca72d17444b8fdefb7093744cbead1922a31

diff --git a/tools/Config.cpp b/tools/Config.cpp
index 40bbddd1..bf8c1e28 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -19,6 +19,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -26,6 +27,7 @@
 #include "Util.hpp"
 
 using Poco::Util::Application;
+using Poco::Util::HelpFormatter;
 using Poco::Util::Option;
 using Poco::Util::OptionSet;
 using Poco::Util::XMLConfiguration;
@@ -71,7 +73,12 @@ std::string Config::ConfigFile = LOOLWSD_CONFIGDIR 
"/loolwsd.xml";
 
 void Config::displayHelp()
 {
-std::cout << "loolconfig - Configuration tool for LibreOffice Online." << 
std::endl
+HelpFormatter helpFormatter(options());
+helpFormatter.setCommand(commandName());
+helpFormatter.setHeader("Configuration tool for LibreOffice Online.");
+helpFormatter.setUsage("OPTIONS COMMAND");
+helpFormatter.format(std::cout);
+std::cout << std::endl
   << "Commands:" << std::endl
   << "  set-admin-password" << std::endl;
 }
@@ -80,25 +87,29 @@ void Config::defineOptions(OptionSet& optionSet)
 {
 Application::defineOptions(optionSet);
 
-optionSet.addOption(Option("help", "", "Config helper tool to set loolwsd 
configuration")
+// global options
+optionSet.addOption(Option("help", "", "Prints help information")
 .required(false)
 .repeatable(false));
-optionSet.addOption(Option("pwd-salt-length", "", "Length of the salt to 
use to hash password")
+optionSet.addOption(Option("config-file", "", "Specify configuration file 
path manually.")
+.required(false)
+.repeatable(false)
+.argument("path"));
+
+// Command specific option
+optionSet.addOption(Option("pwd-salt-length", "", "Length of the salt to 
use to hash password. To be used with set-admin-password command.")
 .required(false)
 .repeatable(false).
 argument("number"));
-optionSet.addOption(Option("pwd-iterations", "", "Number of iterations to 
do in PKDBF2 password hashing")
+optionSet.addOption(Option("pwd-iterations", "", "Number of iterations to 
do in PKDBF2 password hashing. To be used with set-admin-password command.")
 .required(false)
 .repeatable(false)
 .argument("number"));
-optionSet.addOption(Option("pwd-hash-length", "", "Length of password hash 
to generate")
+optionSet.addOption(Option("pwd-hash-length", "", "Length of password hash 
to generate. To be used with set-admin-password command.")
 .required(false)
 .repeatable(false)
 .argument("number"));
-optionSet.addOption(Option("config-file", "", "Specify configuration file 
path manually.")
-.required(false)
-.repeatable(false)
-.argument("path"));
+
 }
 
 void Config::handleOption(const std::string& optionName, const std::string& 
optionValue)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: tools/Config.cpp

2017-08-30 Thread Pranav Kant
 tools/Config.cpp |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

New commits:
commit 08efd75e3154bb8c00aeffe20311a0e0c5557bc7
Author: Pranav Kant 
Date:   Wed Aug 30 17:19:50 2017 +0530

wsd: fix incorrect password hash format written to config file

Regression from 9a75040bf02e215135ca3f5366c171561eee69ea

Change-Id: I82cd3db17a18702a046973cfe863fdda750b363b

diff --git a/tools/Config.cpp b/tools/Config.cpp
index 72808920..40bbddd1 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -11,6 +11,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -207,7 +208,7 @@ int Config::main(const std::vector& args)
 stream << std::hex << std::setw(2) << std::setfill('0') << 
static_cast(pwdhash[j]);
 const std::string passwordHash = stream.str();
 
-std::stringstream pwdConfigValue("pbkdf2.sha512.");
+std::stringstream pwdConfigValue("pbkdf2.sha512.", 
std::ios_base::in | std::ios_base::out | std::ios_base::ate);
 pwdConfigValue << std::to_string(_adminConfig.pwdIterations) << 
".";
 pwdConfigValue << saltHash << "." << passwordHash;
 _loolConfig.setString("admin_console.secure_password[@desc]",
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: tools/Config.cpp

2017-07-03 Thread Miklos Vajna
 tools/Config.cpp |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 9a75040bf02e215135ca3f5366c171561eee69ea
Author: Miklos Vajna 
Date:   Mon Jul 3 08:08:19 2017 +0200

tools: avoid string concatenation resulting in allocation of unnecessary 
temporary strings

By using std::stringstream instead.

Change-Id: I6fe12afd4adc13166746b1d98bf8ea75a28208e5

diff --git a/tools/Config.cpp b/tools/Config.cpp
index 54b95d69..232cc569 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -206,12 +206,12 @@ int Config::main(const std::vector& args)
 stream << std::hex << std::setw(2) << std::setfill('0') << 
static_cast(pwdhash[j]);
 const std::string passwordHash = stream.str();
 
-const std::string pwdConfigValue = "pbkdf2.sha512." +
-
std::to_string(_adminConfig.pwdIterations) + "." +
-saltHash + "." + passwordHash;
+std::stringstream pwdConfigValue("pbkdf2.sha512.");
+pwdConfigValue << std::to_string(_adminConfig.pwdIterations) << 
".";
+pwdConfigValue << saltHash << "." << passwordHash;
 _loolConfig.setString("admin_console.secure_password[@desc]",
   "Salt and password hash combination 
generated using PBKDF2 with SHA512 digest.");
-_loolConfig.setString("admin_console.secure_password", 
pwdConfigValue);
+_loolConfig.setString("admin_console.secure_password", 
pwdConfigValue.str());
 
 std::cout << "Saving configuration to : " << ConfigFile << " ..." 
<< std::endl;
 _loolConfig.save(ConfigFile);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits