php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #62947
Patch php_fpm_user_group_warning.patch revision 2012-08-27 12:38 UTC by rainer-phpbugs at 7val dot com

Patch php_fpm_user_group_warning.patch for FPM related Bug #62947

Patch version 2012-08-27 12:38 UTC

Return to Bug #62947 | Download this patch
Patch Revisions:

Developer: rainer-phpbugs@7val.com

--- sapi/fpm/fpm/fpm_unix.c	2012-08-15 19:05:42.000000000 +0200
+++ sapi/fpm/fpm/fpm_unix.c	2012-08-27 14:20:29.112192136 +0200
@@ -117,18 +117,46 @@
 			if (wp->set_uid == 0 || wp->set_gid == 0) {
 				zlog(ZLOG_ERROR, "[pool %s] please specify user and group other than root", wp->config->name);
 				return -1;
 			}
 		}
 	} else { /* not root */
 		if (wp->config->user && *wp->config->user) {
-			zlog(ZLOG_WARNING, "[pool %s] 'user' directive is ignored when FPM is not running as root", wp->config->name);
+			int uid = 0;
+
+			if (strlen(wp->config->user) == strspn(wp->config->user, "0123456789")) {
+				uid = strtoul(wp->config->user, 0, 10);
+			} else {
+				struct passwd *pwd;
+
+				pwd = getpwnam(wp->config->user);
+				if (pwd) {
+					uid = pwd->pw_uid;
+				}
+			}
+			if (geteuid() != uid) {
+				zlog(ZLOG_WARNING, "[pool %s] 'user' directive is ignored when FPM is not running as root", wp->config->name);
+			}
 		}
 		if (wp->config->group && *wp->config->group) {
-			zlog(ZLOG_WARNING, "[pool %s] 'group' directive is ignored when FPM is not running as root", wp->config->name);
+			int gid = 0;
+
+			if (strlen(wp->config->group) == strspn(wp->config->group, "0123456789")) {
+				gid = strtoul(wp->config->group, 0, 10);
+			} else {
+				struct group *grp;
+
+				grp = getgrnam(wp->config->group);
+				if (grp) {
+					gid = grp->gr_gid;
+				}
+			}
+			if (getegid() != gid) {
+				zlog(ZLOG_WARNING, "[pool %s] 'group' directive is ignored when FPM is not running as root", wp->config->name);
+			}
 		}
 		if (wp->config->chroot && *wp->config->chroot) {
 			zlog(ZLOG_WARNING, "[pool %s] 'chroot' directive is ignored when FPM is not running as root", wp->config->name);
 		}
 		if (wp->config->process_priority != 64) {
 			zlog(ZLOG_WARNING, "[pool %s] 'process.priority' directive is ignored when FPM is not running as root", wp->config->name);
 		}
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 18:01:55 2014 UTC