mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-12 16:50:21 +00:00
Respecting -run_as_user
This commit is contained in:
1 parent
473e2a1cb2
commit
f5865886b2
1 file changed
+14
-2
+14
-2
@@ -84,11 +84,12 @@ typedef struct _stati64 file_stat_t;
|
|||||||
#define __func__ __FILE__ ":" STR(__LINE__)
|
#define __func__ __FILE__ ":" STR(__LINE__)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <inttypes.h>
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <inttypes.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <arpa/inet.h> // For inet_pton() when USE_IPV6 is defined
|
#include <arpa/inet.h> // For inet_pton() when USE_IPV6 is defined
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@@ -3298,6 +3299,17 @@ const char *mg_set_option(struct mg_server *server, const char *name,
|
|||||||
} else {
|
} else {
|
||||||
set_non_blocking_mode(server->listening_sock);
|
set_non_blocking_mode(server->listening_sock);
|
||||||
}
|
}
|
||||||
|
} else if (ind == RUN_AS_USER) {
|
||||||
|
#ifndef _WIN32
|
||||||
|
struct passwd *pw;
|
||||||
|
if ((pw = getpwnam(value)) == NULL) {
|
||||||
|
error_msg = "Unknown user";
|
||||||
|
} else if (setgid(pw->pw_gid) != 0) {
|
||||||
|
error_msg = "setgid() failed";
|
||||||
|
} else if (setuid(pw->pw_uid) != 0) {
|
||||||
|
error_msg = "setuid() failed";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user