77 require "util.datamanager".set_data_path(data_path); |
77 require "util.datamanager".set_data_path(data_path); |
78 |
78 |
79 -- Switch away from root and into the prosody user -- |
79 -- Switch away from root and into the prosody user -- |
80 local switched_user, current_uid; |
80 local switched_user, current_uid; |
81 |
81 |
82 local want_pposix_version = "0.3.3"; |
82 local want_pposix_version = "0.3.4"; |
83 local ok, pposix = pcall(require, "util.pposix"); |
83 local ok, pposix = pcall(require, "util.pposix"); |
84 |
84 |
85 if ok and pposix then |
85 if ok and pposix then |
86 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 |
86 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 |
87 current_uid = pposix.getuid(); |
87 current_uid = pposix.getuid(); |
88 if current_uid == 0 then |
88 if current_uid == 0 then |
89 -- We haz root! |
89 -- We haz root! |
90 local desired_user = config.get("*", "core", "prosody_user") or "prosody"; |
90 local desired_user = config.get("*", "core", "prosody_user") or "prosody"; |
91 local desired_group = config.get("*", "core", "prosody_group") or desired_user; |
91 local desired_group = config.get("*", "core", "prosody_group") or desired_user; |
92 local ok, err = pposix.setgid(desired_group); |
92 local ok, err = pposix.setgid(desired_group); |
|
93 if ok then |
|
94 ok, err = pposix.initgroups(desired_user); |
|
95 end |
93 if ok then |
96 if ok then |
94 ok, err = pposix.setuid(desired_user); |
97 ok, err = pposix.setuid(desired_user); |
95 if ok then |
98 if ok then |
96 -- Yay! |
99 -- Yay! |
97 switched_user = true; |
100 switched_user = true; |