diff options
author | Igor Sysoev <igor@sysoev.ru> | 2017-08-26 13:37:44 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2017-08-26 13:37:44 +0300 |
commit | 9aaa7d8c20e58ed380225cbbbd05248539d2f500 (patch) | |
tree | fdce2cc852667f0c93e14909093376adf3c1a473 /src | |
parent | e64494ba2cba9322f9594f26bcc69cb3a2441105 (diff) | |
download | unit-9aaa7d8c20e58ed380225cbbbd05248539d2f500.tar.gz unit-9aaa7d8c20e58ed380225cbbbd05248539d2f500.tar.bz2 |
Added configure option --user=USER and --group=GROUP.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_process.c | 30 | ||||
-rw-r--r-- | src/nxt_runtime.c | 12 |
2 files changed, 31 insertions, 11 deletions
diff --git a/src/nxt_process.c b/src/nxt_process.c index e6a6fa0c..81344b2d 100644 --- a/src/nxt_process.c +++ b/src/nxt_process.c @@ -364,23 +364,43 @@ nxt_user_cred_get(nxt_task_t *task, nxt_user_cred_t *uc, const char *group) struct group *grp; struct passwd *pwd; + nxt_errno = 0; + pwd = getpwnam(uc->user); if (nxt_slow_path(pwd == NULL)) { - nxt_log(task, NXT_LOG_CRIT, "getpwnam(%s) failed %E", - uc->user, nxt_errno); + + if (nxt_errno == 0) { + nxt_log(task, NXT_LOG_CRIT, + "getpwnam(\"%s\") failed, user \"%s\" not found", + uc->user, uc->user); + } else { + nxt_log(task, NXT_LOG_CRIT, "getpwnam(\"%s\") failed %E", + uc->user, nxt_errno); + } + return NXT_ERROR; } uc->uid = pwd->pw_uid; uc->base_gid = pwd->pw_gid; - if (group != NULL) { + if (group != NULL && group[0] != '\0') { + nxt_errno = 0; + grp = getgrnam(group); if (nxt_slow_path(grp == NULL)) { - nxt_log(task, NXT_LOG_CRIT, "getgrnam(%s) failed %E", - group, nxt_errno); + + if (nxt_errno == 0) { + nxt_log(task, NXT_LOG_CRIT, + "getgrnam(\"%s\") failed, group \"%s\" not found", + group, group); + } else { + nxt_log(task, NXT_LOG_CRIT, "getgrnam(\"%s\") failed %E", + group, nxt_errno); + } + return NXT_ERROR; } diff --git a/src/nxt_runtime.c b/src/nxt_runtime.c index 59b209aa..d6518fbe 100644 --- a/src/nxt_runtime.c +++ b/src/nxt_runtime.c @@ -699,8 +699,8 @@ nxt_runtime_conf_init(nxt_task_t *task, nxt_runtime_t *rt) rt->master_process = 1; rt->engine_connections = 256; rt->auxiliary_threads = 2; - rt->user_cred.user = "nobody"; - rt->group = NULL; + rt->user_cred.user = NXT_USER; + rt->group = NXT_GROUP; rt->pid = NXT_PID; rt->log = NXT_LOG; @@ -757,6 +757,8 @@ nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt) "nginext version: " NXT_VERSION "\n" "configured as ./configure" NXT_CONFIGURE_OPTIONS "\n"; + static const char no_user[] = "option \"--user\" requires username\n"; + static const char no_group[] = "option \"--group\" requires group name\n"; static const char no_pid[] = "option \"--pid\" requires filename\n"; static const char no_log[] = "option \"--log\" requires filename\n"; @@ -805,8 +807,7 @@ nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt) if (nxt_strcmp(p, "--user") == 0) { if (*argv == NULL) { - nxt_log(task, NXT_LOG_CRIT, - "no argument for option \"--user\""); + write(STDERR_FILENO, no_user, sizeof(no_user) - 1); return NXT_ERROR; } @@ -819,8 +820,7 @@ nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt) if (nxt_strcmp(p, "--group") == 0) { if (*argv == NULL) { - nxt_log(task, NXT_LOG_CRIT, - "no argument for option \"--group\""); + write(STDERR_FILENO, no_group, sizeof(no_group) - 1); return NXT_ERROR; } |