Skip to content

Commit 25f3e75

Browse files
committed
minor setuid/setgid improvements
1 parent f5cfdcf commit 25f3e75

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

bin/server.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ vhost=10.0.10.86,acme.local
33
port=8080
44
diskpath=./htdocs
55

6-
# Optional - uid/gid to "drop" to with setuid/setgid after bind() so the program doesn't have to run as root
6+
# Optional - uid/gid to "drop" to with setuid/setgid after bind() so the program doesn't have to remain as root
77
# Default 0 because dropping to root makes no sense
88
drop_uid=0
99
drop_gid=0

src/HTTPServer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ bool HTTPServer::start() {
110110
}
111111

112112
// Optionally drop uid/gid if specified
113-
if (dropUid != 0 && dropGid != 0) {
114-
if (setgid(dropGid) == -1) {
113+
if (dropUid > 0 && dropGid > 0) {
114+
if (setgid(dropGid) != 0) {
115115
std::cout << "setgid to " << dropGid << " failed!" << std::endl;
116116
return false;
117117
}
118118

119-
if (setuid(dropUid) == -1) {
119+
if (setuid(dropUid) != 0) {
120120
std::cout << "setuid to " << dropUid << " failed!" << std::endl;
121121
return false;
122122
}

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int main (int argc, const char * argv[])
8989
drop_uid = atoi(config["drop_uid"].c_str());
9090
drop_gid = atoi(config["drop_gid"].c_str());
9191

92-
if (drop_uid == 0 || drop_gid == 0) {
92+
if (drop_uid <= 0 || drop_gid <= 0) {
9393
// Both must be set, otherwise set back to 0 so we dont use
9494
drop_uid = drop_gid = 0;
9595
}
@@ -103,7 +103,7 @@ int main (int argc, const char * argv[])
103103
signal(SIGINT, &handleTermSig);
104104
signal(SIGTERM, &handleTermSig);
105105

106-
// Instance and start the server
106+
// Instantiate and start the server
107107
svr = new HTTPServer(vhosts, atoi(config["port"].c_str()), config["diskpath"], drop_uid, drop_gid);
108108
if (!svr->start()) {
109109
svr->stop();

0 commit comments

Comments
 (0)