Download | Plain Text | No Line Numbers


  1. --- pinba.cc 2010-11-26 10:05:25.000000000 +0100
  2. +++ pinba.cc 2011-03-18 14:27:34.000000000 +0100
  3. @@ -103,6 +103,7 @@
  4.  
  5. #define timeval_cvt(a, b) do { (a)->tv_sec = (b)->tv_sec; (a)->tv_usec = (b)->tv_usec; } while (0);
  6. #define timeval_to_float(t) (float)(t).tv_sec + (float)(t).tv_usec / 1000000.0
  7. +#define min(a, b) (a < b ? a : b)
  8.  
  9. /* {{{ internal funcs */
  10.  
  11. @@ -1255,7 +1256,7 @@
  12. PHP_FE(pinba_timer_get_info, NULL)
  13. PHP_FE(pinba_timers_stop, NULL)
  14. PHP_FE(pinba_script_name_set, NULL)
  15. - PHP_FE(pinba_hostname_set, NULL)
  16. + //PHP_FE(pinba_hostname_set, NULL)
  17. {NULL, NULL, NULL}
  18. };
  19. /* }}} */
  20. @@ -1396,6 +1397,17 @@
  21. zval **tmp;
  22. struct timeval t;
  23. struct rusage u;
  24. + zval suexec_user;
  25. + uid_t euid;
  26. + int user_len;
  27. + struct passwd *pw = NULL;
  28. +#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWUID_R)
  29. + struct passwd _pw;
  30. + struct passwd *retpwptr = NULL;
  31. + long pwbuflen;
  32. + char *pwbuf = NULL;
  33. + int ret;
  34. +#endif
  35.  
  36. PINBA_G(timers_stopped) = 0;
  37.  
  38. @@ -1420,13 +1432,45 @@
  39. PINBA_G(server_name) = NULL;
  40. PINBA_G(script_name) = NULL;
  41.  
  42. - gethostname(PINBA_G(host_name), sizeof(PINBA_G(host_name)));
  43. - PINBA_G(host_name)[sizeof(PINBA_G(host_name))] = '\0';
  44. -
  45. #if PHP_MAJOR_VERSION >= 5
  46. zend_is_auto_global("_SERVER", sizeof("_SERVER") - 1 TSRMLS_CC);
  47. #endif
  48.  
  49. + PINBA_G(host_name)[0] = '\0';
  50. + if (zend_get_constant("SUEXEC_USER", sizeof("SUEXEC_USER") - 1, &suexec_user TSRMLS_CC)) {
  51. + if (Z_TYPE(suexec_user) == IS_STRING && Z_STRLEN(suexec_user) != 0) {
  52. + user_len = min(Z_STRLEN(suexec_user), sizeof(PINBA_G(host_name)));
  53. + memcpy(PINBA_G(host_name), Z_STRVAL(suexec_user), user_len);
  54. + PINBA_G(host_name)[user_len] = '\0';
  55. + }
  56. + zval_dtor(&suexec_user);
  57. + }
  58. + if (PINBA_G(host_name)[0] == '\0') {
  59. + euid = geteuid();
  60. +#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWUID_R)
  61. + pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
  62. + if (pwbuflen > 1) {
  63. + pwbuf = (char *)emalloc(pwbuflen);
  64. + ret = getpwuid_r(euid, &_pw, pwbuf, pwbuflen, &retpwptr);
  65. + if (ret == 0 && retpwptr != NULL) {
  66. + pw = &_pw;
  67. + }
  68. + }
  69. +#else
  70. + pw = getpwuid(euid);
  71. +#endif
  72. + if (pw != NULL) {
  73. + user_len = (pw->pw_name == NULL) ? 0 : min(strlen(pw->pw_name), sizeof(PINBA_G(host_name)));
  74. + memcpy(PINBA_G(host_name), pw->pw_name, user_len);
  75. + PINBA_G(host_name)[user_len] = '\0';
  76. + }
  77. +#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWUID_R)
  78. + if (pwbuf != NULL) {
  79. + efree(pwbuf);
  80. + }
  81. +#endif
  82. + }
  83. +
  84. if (PG(http_globals)[TRACK_VARS_SERVER] && zend_hash_find(HASH_OF(PG(http_globals)[TRACK_VARS_SERVER]), "SCRIPT_NAME", sizeof("SCRIPT_NAME"), (void **) &tmp) != FAILURE && Z_TYPE_PP(tmp) == IS_STRING && Z_STRLEN_PP(tmp) > 0) {
  85. PINBA_G(script_name) = estrndup(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
  86. }
  87.