@@ -4609,14 +4609,15 @@ static int accel_finish_startup(void)
4609
4609
return SUCCESS ;
4610
4610
}
4611
4611
4612
- if (geteuid () == 0 ) {
4612
+ uid_t euid = geteuid ();
4613
+ if (euid == 0 ) {
4613
4614
pid_t pid ;
4614
4615
struct passwd * pw ;
4615
4616
4616
4617
if (!ZCG (accel_directives ).preload_user
4617
4618
|| !* ZCG (accel_directives ).preload_user ) {
4618
4619
zend_shared_alloc_unlock ();
4619
- zend_accel_error_noreturn (ACCEL_LOG_FATAL , "\"opcache.preload_user\" has not been defined " );
4620
+ zend_accel_error_noreturn (ACCEL_LOG_FATAL , "\"opcache.preload\" requires \"opcache. preload_user\" when running under uid 0 " );
4620
4621
return FAILURE ;
4621
4622
}
4622
4623
@@ -4627,43 +4628,45 @@ static int accel_finish_startup(void)
4627
4628
return FAILURE ;
4628
4629
}
4629
4630
4630
- pid = fork ();
4631
- if (pid == -1 ) {
4632
- zend_shared_alloc_unlock ();
4633
- zend_accel_error_noreturn (ACCEL_LOG_FATAL , "Preloading failed to fork()" );
4634
- return FAILURE ;
4635
- } else if (pid == 0 ) { /* children */
4636
- if (setgid (pw -> pw_gid ) < 0 ) {
4637
- zend_accel_error (ACCEL_LOG_WARNING , "Preloading failed to setgid(%d)" , pw -> pw_gid );
4638
- exit (1 );
4639
- }
4640
- if (initgroups (pw -> pw_name , pw -> pw_gid ) < 0 ) {
4641
- zend_accel_error (ACCEL_LOG_WARNING , "Preloading failed to initgroups(\"%s\", %d)" , pw -> pw_name , pw -> pw_uid );
4642
- exit (1 );
4643
- }
4644
- if (setuid (pw -> pw_uid ) < 0 ) {
4645
- zend_accel_error (ACCEL_LOG_WARNING , "Preloading failed to setuid(%d)" , pw -> pw_uid );
4646
- exit (1 );
4647
- }
4648
- in_child = true;
4649
- } else { /* parent */
4650
- int status ;
4651
-
4652
- if (waitpid (pid , & status , 0 ) < 0 ) {
4631
+ if (pw -> pw_uid != euid ) {
4632
+ pid = fork ();
4633
+ if (pid == -1 ) {
4653
4634
zend_shared_alloc_unlock ();
4654
- zend_accel_error_noreturn (ACCEL_LOG_FATAL , "Preloading failed to waitpid(%d)" , pid );
4635
+ zend_accel_error_noreturn (ACCEL_LOG_FATAL , "Preloading failed to fork()" );
4655
4636
return FAILURE ;
4656
- }
4637
+ } else if (pid == 0 ) { /* children */
4638
+ if (setgid (pw -> pw_gid ) < 0 ) {
4639
+ zend_accel_error (ACCEL_LOG_WARNING , "Preloading failed to setgid(%d)" , pw -> pw_gid );
4640
+ exit (1 );
4641
+ }
4642
+ if (initgroups (pw -> pw_name , pw -> pw_gid ) < 0 ) {
4643
+ zend_accel_error (ACCEL_LOG_WARNING , "Preloading failed to initgroups(\"%s\", %d)" , pw -> pw_name , pw -> pw_uid );
4644
+ exit (1 );
4645
+ }
4646
+ if (setuid (pw -> pw_uid ) < 0 ) {
4647
+ zend_accel_error (ACCEL_LOG_WARNING , "Preloading failed to setuid(%d)" , pw -> pw_uid );
4648
+ exit (1 );
4649
+ }
4650
+ in_child = true;
4651
+ } else { /* parent */
4652
+ int status ;
4657
4653
4658
- if (ZCSG (preload_script )) {
4659
- preload_load ();
4660
- }
4654
+ if (waitpid (pid , & status , 0 ) < 0 ) {
4655
+ zend_shared_alloc_unlock ();
4656
+ zend_accel_error_noreturn (ACCEL_LOG_FATAL , "Preloading failed to waitpid(%d)" , pid );
4657
+ return FAILURE ;
4658
+ }
4661
4659
4662
- zend_shared_alloc_unlock ();
4663
- if (WIFEXITED (status ) && WEXITSTATUS (status ) == 0 ) {
4664
- return SUCCESS ;
4665
- } else {
4666
- return FAILURE ;
4660
+ if (ZCSG (preload_script )) {
4661
+ preload_load ();
4662
+ }
4663
+
4664
+ zend_shared_alloc_unlock ();
4665
+ if (WIFEXITED (status ) && WEXITSTATUS (status ) == 0 ) {
4666
+ return SUCCESS ;
4667
+ } else {
4668
+ return FAILURE ;
4669
+ }
4667
4670
}
4668
4671
}
4669
4672
} else {
0 commit comments