Comparison

prosodyctl @ 1580:5be6dc582df3

prosodyctl: Also switch group when we switch user
author Matthew Wild <mwild1@gmail.com>
date Thu, 23 Jul 2009 03:58:14 +0100
parent 1523:841d61be198f
child 2020:24f54340a670
comparison
equal deleted inserted replaced
1579:95698f021c5d 1580:5be6dc582df3
64 local data_path = config.get("*", "core", "data_path") or CFG_DATADIR or "data"; 64 local data_path = config.get("*", "core", "data_path") or CFG_DATADIR or "data";
65 require "util.datamanager".set_data_path(data_path); 65 require "util.datamanager".set_data_path(data_path);
66 66
67 -- Switch away from root and into the prosody user -- 67 -- Switch away from root and into the prosody user --
68 local switched_user, current_uid; 68 local switched_user, current_uid;
69
70 local want_pposix_version = "0.3.1";
69 local ok, pposix = pcall(require, "util.pposix"); 71 local ok, pposix = pcall(require, "util.pposix");
72
70 if ok and pposix then 73 if ok and pposix then
74 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
71 current_uid = pposix.getuid(); 75 current_uid = pposix.getuid();
72 if current_uid == 0 then 76 if current_uid == 0 then
73 -- We haz root! 77 -- We haz root!
74 local desired_user = config.get("*", "core", "prosody_user") or "prosody"; 78 local desired_user = config.get("*", "core", "prosody_user") or "prosody";
75 local ok, err = pposix.setuid(desired_user); 79 local desired_group = config.get("*", "core", "prosody_group") or desired_user;
80 local ok, err = pposix.setgid(desired_group);
76 if ok then 81 if ok then
77 -- Yay! 82 ok, err = pposix.setuid(desired_user);
78 switched_user = true; 83 if ok then
79 else 84 -- Yay!
85 switched_user = true;
86 end
87 end
88 if not switched_user then
80 -- Boo! 89 -- Boo!
81 print("Warning: Couldn't switch to Prosody user '"..tostring(desired_user).."': "..tostring(err)); 90 print("Warning: Couldn't switch to Prosody user/group '"..tostring(desired_user).."'/'"..tostring(desired_group).."': "..tostring(err));
82 end 91 end
83 end 92 end
84 else 93 else
85 print("Error: Unable to load pposix module. Check that Prosody is installed correctly.") 94 print("Error: Unable to load pposix module. Check that Prosody is installed correctly.")
86 print("For more help send the below error to us through http://prosody.im/discuss"); 95 print("For more help send the below error to us through http://prosody.im/discuss");