mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-04 12:41:38 +00:00
jail-friendly setuid()/setgid()
This commit is contained in:
@@ -288,6 +288,25 @@ void uwsgi_as_root() {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (uwsgi.gidname) {
|
||||
struct group *ugroup = getgrnam(uwsgi.gidname);
|
||||
if (ugroup) {
|
||||
uwsgi.gid = ugroup->gr_gid;
|
||||
} else {
|
||||
uwsgi_log("group %s not found.\n", uwsgi.gidname);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (uwsgi.uidname) {
|
||||
struct passwd *upasswd = getpwnam(uwsgi.uidname);
|
||||
if (upasswd) {
|
||||
uwsgi.uid = upasswd->pw_uid;
|
||||
} else {
|
||||
uwsgi_log("user %s not found.\n", uwsgi.uidname);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (uwsgi.gid) {
|
||||
uwsgi_log("setgid() to %d\n", uwsgi.gid);
|
||||
if (setgid(uwsgi.gid)) {
|
||||
|
||||
@@ -717,8 +717,14 @@ int uwsgi_start(void *v_argv) {
|
||||
|
||||
#ifdef __linux__
|
||||
if (uwsgi.ns && getpid() == 1) {
|
||||
if (sethostname("uwsgifakehost", strlen("uwsgifakehost"))) {
|
||||
uwsgi_error("sethostname()");
|
||||
|
||||
char *ns_hostname = strchr(uwsgi.ns, ':');
|
||||
if (ns_hostname) {
|
||||
ns_hostname[0] = 0;
|
||||
ns_hostname++;
|
||||
if (sethostname(ns_hostname, strlen(ns_hostname))) {
|
||||
uwsgi_error("sethostname()");
|
||||
}
|
||||
}
|
||||
|
||||
FILE *procmounts;
|
||||
@@ -1769,25 +1775,13 @@ end:
|
||||
case LONG_ARGS_GID:
|
||||
uwsgi.gid = atoi(optarg);
|
||||
if (!uwsgi.gid) {
|
||||
struct group *ugroup = getgrnam(optarg);
|
||||
if (ugroup) {
|
||||
uwsgi.gid = ugroup->gr_gid;
|
||||
} else {
|
||||
uwsgi_log("group %s not found.\n", optarg);
|
||||
exit(1);
|
||||
}
|
||||
uwsgi.gidname = optarg;
|
||||
}
|
||||
return 1;
|
||||
case LONG_ARGS_UID:
|
||||
uwsgi.uid = atoi(optarg);
|
||||
if (!uwsgi.uid) {
|
||||
struct passwd *upasswd = getpwnam(optarg);
|
||||
if (upasswd) {
|
||||
uwsgi.uid = upasswd->pw_uid;
|
||||
} else {
|
||||
uwsgi_log("user %s not found.\n", optarg);
|
||||
exit(1);
|
||||
}
|
||||
uwsgi.uidname = optarg;
|
||||
}
|
||||
return 1;
|
||||
case LONG_ARGS_BINARY_PATH:
|
||||
|
||||
Reference in New Issue
Block a user