From 18e6a1883e6eb739d448e60b9028334c83e0f4d6 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 10 Mar 2007 10:38:05 +0100 Subject: [PATCH] exec plugin: Replace `getpwnam' with `getpwnam_r'. --- src/exec.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/exec.c b/src/exec.c index ee8f8bf9..63401bec 100644 --- a/src/exec.c +++ b/src/exec.c @@ -166,20 +166,28 @@ static void submit_gauge (const char *type_instance, gauge_t value) static void exec_child (program_list_t *pl) { - struct passwd *sp; int status; int uid; char *arg0; - /* FIXME: Not thread safe! */ - sp = getpwnam (pl->user); - if (sp == NULL) + struct passwd *sp_ptr; + struct passwd sp; + char pwnambuf[2048]; + + sp_ptr = NULL; + status = getpwnam_r (pl->user, &sp, pwnambuf, sizeof (pwnambuf), &sp_ptr); + if (status != 0) + { + syslog (LOG_ERR, "exec plugin: getpwnam_r failed: %s", strerror (status)); + exit (-1); + } + if (sp_ptr == NULL) { - syslog (LOG_ERR, "exec plugin: getpwnam failed: %s", strerror (errno)); + syslog (LOG_ERR, "exec plugin: No such user: `%s'", pl->user); exit (-1); } - uid = sp->pw_uid; + uid = sp.pw_uid; if (uid == 0) { syslog (LOG_ERR, "exec plugin: Cowardly refusing to exec program as root."); -- 2.11.0