Просмотр исходного кода

PATH and other environment variables not set with numeric nrpe_user

Fix for issue #96
John C. Frickson 9 лет назад
Родитель
Сommit
acda648d6c
2 измененных файлов с 14 добавлено и 6 удалено
  1. 1 0
      Changelog
  2. 13 6
      src/utils.c

+ 1 - 0
Changelog

@@ -36,6 +36,7 @@ FIXES
 - Return UNKNOWN when check_nrpe cannot communicate with nrpe and -u set (John Frickson)
 - xinetd.d parameter causes many messages in log file (John Frickson)
 - Fixes for openssl 1.1.x (Stephen Smoogen / John Frickson)
+- PATH and other environment variables not set with numeric nrpe_user (John Frickson)
 
 
 3.0.1 - 2016-09-08

+ 13 - 6
src/utils.c

@@ -318,17 +318,24 @@ int clean_environ(const char *keep_env_vars, const char *nrpe_user)
 	free(keep);
 	free(kept);
 
-	pw = (struct passwd *)getpwnam(nrpe_user);
-	if (pw == NULL)
-		return OK;
-
 	setenv("PATH", path, 1);
 	setenv("IFS", " \t\n", 1);
-	setenv("HOME", pw->pw_dir, 0);
-	setenv("SHELL", pw->pw_shell, 0);
 	setenv("LOGNAME", nrpe_user, 0);
 	setenv("USER", nrpe_user, 0);
 
+	pw = (struct passwd *)getpwnam(nrpe_user);
+	if (pw == NULL) {
+		char	*end = NULL;
+		uid_t	uid = strtol(nrpe_user, &end, 10);
+		if (uid > 0)
+			pw = (struct passwd *)getpwuid(uid);
+		if (pw == NULL || *end != '\0')
+			return OK;
+	}
+
+	setenv("HOME", pw->pw_dir, 0);
+	setenv("SHELL", pw->pw_shell, 0);
+
 	return OK;
 }