allow changing uid as root

This commit is contained in:
Jeff Becker 2020-09-08 13:22:22 -04:00 committed by Jason Rhinelander
parent 0c9eeeea43
commit 0938e1fc53
2 changed files with 6 additions and 3 deletions

View File

@ -269,6 +269,9 @@ public:
/** The gid that owns any sockets when constructed (same as umask) /** The gid that owns any sockets when constructed (same as umask)
*/ */
int SOCKET_GID = -1; int SOCKET_GID = -1;
/** The uid that owns any sockets when constructed (same as umask but requires root)
*/
int SOCKET_UID = -1;
/// A special TaggedThreadID value that always refers to the proxy thread; the main use of this is /// A special TaggedThreadID value that always refers to the proxy thread; the main use of this is
/// to direct very simple batch completion jobs to be executed directly in the proxy thread. /// to direct very simple batch completion jobs to be executed directly in the proxy thread.

View File

@ -387,12 +387,12 @@ void LokiMQ::proxy_loop() {
if (saved_umask != -1) if (saved_umask != -1)
umask(saved_umask); umask(saved_umask);
// set socket gid if it is provided // set socket gid / uid if it is provided
if (SOCKET_GID != -1) { if (SOCKET_GID != -1 or SOCKET_UID != -1) {
for(size_t i = 0; i < bind.size(); i++) { for(size_t i = 0; i < bind.size(); i++) {
const address addr(bind[i].first); const address addr(bind[i].first);
if(addr.ipc()) { if(addr.ipc()) {
if(chown(addr.socket.c_str(), -1, SOCKET_GID) == -1) { if(chown(addr.socket.c_str(), SOCKET_UID, SOCKET_GID) == -1) {
throw std::runtime_error("cannot set group on " + addr.socket + ": " + strerror(errno)); throw std::runtime_error("cannot set group on " + addr.socket + ": " + strerror(errno));
} }
} }