From 5ce98ecf13a81da432fd7b6fa61184ebc338347c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 19 Apr 2017 12:40:03 +0100 Subject: prosodyctl: Don't switch user if we are root and run_as_root is enabled --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index efdc214c..c8accd82 100755 --- a/prosodyctl +++ b/prosodyctl @@ -141,7 +141,7 @@ local ok, pposix = pcall(require, "util.pposix"); if ok and pposix then if pposix._VERSION ~= want_pposix_version then print(string.format("Unknown version (%s) of binary pposix module, expected %s", tostring(pposix._VERSION), want_pposix_version)); return; end current_uid = pposix.getuid(); - if current_uid == 0 then + if current_uid == 0 and config.get("*", "run_as_root") ~= true then -- We haz root! local desired_user = config.get("*", "prosody_user") or "prosody"; local desired_group = config.get("*", "prosody_group") or desired_user; -- cgit v1.2.3 From a3522c0f2d4a751b6c2809a82e431dc88190f657 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 19 Apr 2017 19:31:46 +0200 Subject: prosodyctl: Allow continuing to run as root (fixes #893) --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index c8accd82..90e59991 100755 --- a/prosodyctl +++ b/prosodyctl @@ -141,7 +141,7 @@ local ok, pposix = pcall(require, "util.pposix"); if ok and pposix then if pposix._VERSION ~= want_pposix_version then print(string.format("Unknown version (%s) of binary pposix module, expected %s", tostring(pposix._VERSION), want_pposix_version)); return; end current_uid = pposix.getuid(); - if current_uid == 0 and config.get("*", "run_as_root") ~= true then + if current_uid == 0 and config.get("*", "run_as_root") ~= true and arg[1] ~= "--root" then -- We haz root! local desired_user = config.get("*", "prosody_user") or "prosody"; local desired_group = config.get("*", "prosody_group") or desired_user; -- cgit v1.2.3 From 1584f132bfc93e111548948e916cb1f2f6aa6587 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 19 Apr 2017 20:26:09 +0200 Subject: prosodyctl: Remove --root from arg array --- prosodyctl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 90e59991..63fd6485 100755 --- a/prosodyctl +++ b/prosodyctl @@ -141,7 +141,9 @@ local ok, pposix = pcall(require, "util.pposix"); if ok and pposix then if pposix._VERSION ~= want_pposix_version then print(string.format("Unknown version (%s) of binary pposix module, expected %s", tostring(pposix._VERSION), want_pposix_version)); return; end current_uid = pposix.getuid(); - if current_uid == 0 and config.get("*", "run_as_root") ~= true and arg[1] ~= "--root" then + local arg_root = arg[1] == "--root"; + if arg_root then table.remove(arg, 1); end + if current_uid == 0 and config.get("*", "run_as_root") ~= true and not arg_root then -- We haz root! local desired_user = config.get("*", "prosody_user") or "prosody"; local desired_group = config.get("*", "prosody_group") or desired_user; -- cgit v1.2.3 From 28473a6452348dcab6aa9c81dcdce1a6f3288af1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 19 Apr 2017 20:38:55 +0200 Subject: prosodyctl: Rename variable for soft-require success to improve readability --- prosodyctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 63fd6485..1949edcc 100755 --- a/prosodyctl +++ b/prosodyctl @@ -136,9 +136,9 @@ dependencies.log_warnings(); local switched_user, current_uid; local want_pposix_version = "0.4.0"; -local ok, pposix = pcall(require, "util.pposix"); +local have_pposix, pposix = pcall(require, "util.pposix"); -if ok and pposix then +if have_pposix and pposix then if pposix._VERSION ~= want_pposix_version then print(string.format("Unknown version (%s) of binary pposix module, expected %s", tostring(pposix._VERSION), want_pposix_version)); return; end current_uid = pposix.getuid(); local arg_root = arg[1] == "--root"; -- cgit v1.2.3 From 256ab5259da1de5e24691493c0f6a26595e17208 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 19 Apr 2017 20:39:47 +0200 Subject: prosodyctl cert: If running as root, write certificate files to config directory (fixes #530) --- prosodyctl | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 1949edcc..219c3522 100755 --- a/prosodyctl +++ b/prosodyctl @@ -697,9 +697,16 @@ local function use_existing(filename) end end +local cert_basedir = CFG_DATADIR or "./certs"; +if have_pposix and pposix.getuid() == 0 then + -- FIXME should be enough to check if this directory is writable + local cert_dir = config.get("*", "certificates") or "certs"; + cert_basedir = config.resolve_relative_path(config.paths.certs, cert_dir); +end + function cert_commands.config(arg) if #arg >= 1 and arg[1] ~= "--help" then - local conf_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".cnf"; + local conf_filename = cert_basedir .. "/" .. arg[1] .. ".cnf"; if use_existing(conf_filename) then return nil, conf_filename; end @@ -760,7 +767,7 @@ end function cert_commands.key(arg) if #arg >= 1 and arg[1] ~= "--help" then - local key_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".key"; + local key_filename = cert_basedir .. "/" .. arg[1] .. ".key"; if use_existing(key_filename) then return nil, key_filename; end @@ -782,7 +789,7 @@ end function cert_commands.request(arg) if #arg >= 1 and arg[1] ~= "--help" then - local req_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".req"; + local req_filename = cert_basedir .. "/" .. arg[1] .. ".req"; if use_existing(req_filename) then return nil, req_filename; end @@ -800,7 +807,7 @@ end function cert_commands.generate(arg) if #arg >= 1 and arg[1] ~= "--help" then - local cert_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".crt"; + local cert_filename = cert_basedir .. "/" .. arg[1] .. ".crt"; if use_existing(cert_filename) then return nil, cert_filename; end -- cgit v1.2.3