I've added accessors to Group and User directives in httpd.conf, so that now you can get that info via:

  my $user_id  = Apache2::ServerUtil->user_id;
  my $group_id = Apache2::ServerUtil->group_id;

the patch is inlined and attached (due to long lines).

Please let me know if you are happy with this approach or you want it to be different. (including the test).

Another concern is windows - so if someone can try to build with this patch on windows that would be great.

Thank you.

Index: xs/maps/modperl_functions.map
===================================================================
--- xs/maps/modperl_functions.map       (revision 367390)
+++ xs/maps/modperl_functions.map       (working copy)
@@ -87,6 +87,8 @@

 MODULE=Apache2::ServerUtil   PACKAGE=Apache2::ServerUtil
  server_rec *:DEFINE_server | | SV *:classname=Nullsv
+ uid_t:DEFINE_user_id       | | SV *:classname=Nullsv
+ gid_t:DEFINE_group_id      | | SV *:classname=Nullsv

 MODULE=Apache2::Connection
  mpxs_Apache2__Connection_client_socket | | c, s=NULL
Index: xs/Apache2/ServerUtil/Apache2__ServerUtil.h
===================================================================
--- xs/Apache2/ServerUtil/Apache2__ServerUtil.h (revision 367390)
+++ xs/Apache2/ServerUtil/Apache2__ServerUtil.h (working copy)
@@ -13,6 +13,8 @@
  * limitations under the License.
  */

+#include "unixd.h"
+
 #define mpxs_Apache2__ServerUtil_restart_count modperl_restart_count

 #define mpxs_Apache2__ServerRec_method_register(s, methname)     \
@@ -151,6 +153,9 @@

#define mpxs_Apache2__ServerUtil_server(classname) modperl_global_get_server_rec()

+#define mpxs_Apache2__ServerUtil_user_id(classname) unixd_config.user_id
+#define mpxs_Apache2__ServerUtil_group_id(classname) unixd_config.group_id
+
 static MP_INLINE
 int mpxs_Apache2__ServerRec_is_perl_option_enabled(pTHX_ server_rec *s,
                                                const char *name)
Index: t/response/TestApache/daemon.pm
===================================================================
--- t/response/TestApache/daemon.pm     (revision 0)
+++ t/response/TestApache/daemon.pm     (revision 0)
@@ -0,0 +1,34 @@
+package TestApache::daemon;
+
+# Apache2::ServerUtil tests
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache2::ServerUtil ();
+
+use Apache::TestUtil;
+use Apache::Test;
+
+use Apache2::Const -compile => 'OK';
+
+sub handler {
+    my $r = shift;
+
+    plan $r, tests => 2;
+
+    my $user_id = Apache2::ServerUtil->user_id;
+    ok t_cmp $user_id, $<, "user id";
+
+    my $group_id = Apache2::ServerUtil->group_id;
+    my ($expected_gid) = ($( =~ /^(\d+)/);
+
+    ok t_cmp $group_id, $expected_gid, "group id";
+
+    Apache2::Const::OK;
+}
+
+1;
+
+__END__
+

--
_____________________________________________________________
Stas Bekman mailto:[EMAIL PROTECTED]  http://stason.org/
MailChannels: Assured Messaging(TM) http://mailchannels.com/
The "Practical mod_perl" book       http://modperlbook.org/
http://perl.apache.org/ http://perl.org/ http://logilune.com/

Index: xs/maps/modperl_functions.map
===================================================================
--- xs/maps/modperl_functions.map       (revision 367390)
+++ xs/maps/modperl_functions.map       (working copy)
@@ -87,6 +87,8 @@
 
 MODULE=Apache2::ServerUtil   PACKAGE=Apache2::ServerUtil
  server_rec *:DEFINE_server | | SV *:classname=Nullsv
+ uid_t:DEFINE_user_id       | | SV *:classname=Nullsv
+ gid_t:DEFINE_group_id      | | SV *:classname=Nullsv
 
 MODULE=Apache2::Connection
  mpxs_Apache2__Connection_client_socket | | c, s=NULL
Index: xs/Apache2/ServerUtil/Apache2__ServerUtil.h
===================================================================
--- xs/Apache2/ServerUtil/Apache2__ServerUtil.h (revision 367390)
+++ xs/Apache2/ServerUtil/Apache2__ServerUtil.h (working copy)
@@ -13,6 +13,8 @@
  * limitations under the License.
  */
 
+#include "unixd.h"
+
 #define mpxs_Apache2__ServerUtil_restart_count modperl_restart_count
 
 #define mpxs_Apache2__ServerRec_method_register(s, methname)     \
@@ -151,6 +153,9 @@
 
 #define mpxs_Apache2__ServerUtil_server(classname) 
modperl_global_get_server_rec()
 
+#define mpxs_Apache2__ServerUtil_user_id(classname) unixd_config.user_id
+#define mpxs_Apache2__ServerUtil_group_id(classname) unixd_config.group_id
+
 static MP_INLINE
 int mpxs_Apache2__ServerRec_is_perl_option_enabled(pTHX_ server_rec *s,
                                                const char *name)
Index: t/response/TestApache/daemon.pm
===================================================================
--- t/response/TestApache/daemon.pm     (revision 0)
+++ t/response/TestApache/daemon.pm     (revision 0)
@@ -0,0 +1,34 @@
+package TestApache::daemon;
+
+# Apache2::ServerUtil tests
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache2::ServerUtil ();
+
+use Apache::TestUtil;
+use Apache::Test;
+
+use Apache2::Const -compile => 'OK';
+
+sub handler {
+    my $r = shift;
+
+    plan $r, tests => 2;
+
+    my $user_id = Apache2::ServerUtil->user_id;
+    ok t_cmp $user_id, $<, "user id";
+
+    my $group_id = Apache2::ServerUtil->group_id;
+    my ($expected_gid) = ($( =~ /^(\d+)/);
+
+    ok t_cmp $group_id, $expected_gid, "group id";
+
+    Apache2::Const::OK;
+}
+
+1;
+
+__END__
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to