You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jk...@apache.org on 2015/03/06 10:14:07 UTC

svn commit: r1664565 - in /httpd/httpd/trunk: CHANGES docs/manual/rewrite/rewritemap.xml modules/mappers/mod_rewrite.c

Author: jkaluza
Date: Fri Mar  6 09:14:07 2015
New Revision: 1664565

URL: http://svn.apache.org/r1664565
Log:
*) mod_rewrite: Add support for starting External Rewriting Programs
   as non-root user on UNIX systems by specifying username and group name
   as third argument of RewriteMap directive.

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/manual/rewrite/rewritemap.xml
    httpd/httpd/trunk/modules/mappers/mod_rewrite.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1664565&r1=1664564&r2=1664565&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Fri Mar  6 09:14:07 2015
@@ -6,6 +6,10 @@ Changes with Apache 2.5.0
      to a local URL-path with the INCLUDES filter active, introduced
      in 2.4.11. PR 57531. [Yann Ylavic]
 
+  *) mod_rewrite: Add support for starting External Rewriting Programs
+     as non-root user on UNIX systems by specifying username and group name
+     as third argument of RewriteMap directive. [Jan Kaluza]
+
   *) core: If explicitly configured, use the KeepaliveTimeout value of the
      virtual host which handled the latest request on the connection, or by
      default the one of the first virtual host bound to the same IP:port.

Modified: httpd/httpd/trunk/docs/manual/rewrite/rewritemap.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/rewrite/rewritemap.xml?rev=1664565&r1=1664564&r2=1664565&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/rewrite/rewritemap.xml (original)
+++ httpd/httpd/trunk/docs/manual/rewrite/rewritemap.xml Fri Mar  6 09:14:07 2015
@@ -349,6 +349,11 @@ by many requests.
     module="mod_rewrite">RewriteEngine</directive> set to
     <code>on</code>.</p>
 
+    <p>By default, external rewriting programs are started as root.
+    This can be changed on UNIX systems by passing user name and
+    group name as third argument to <directive module="mod_rewrite">
+    RewriteMap</directive> in the <code>username:groupname</code> format.</p>
+
     <p>This feature utilizes the <code>rewrite-map</code> mutex,
     which is required for reliable communication with the program.
     The mutex mechanism and lock file can be configured with the
@@ -360,7 +365,7 @@ by many requests.
 <p><strong>Rewrite configuration</strong></p>
     <highlight language="config">
 
-RewriteMap d2u prg:/www/bin/dash2under.pl<br />
+RewriteMap d2u prg:/www/bin/dash2under.pl apache:apache<br />
 RewriteRule - ${d2u:%{REQUEST_URI}}
     </highlight>
 

Modified: httpd/httpd/trunk/modules/mappers/mod_rewrite.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mappers/mod_rewrite.c?rev=1664565&r1=1664564&r2=1664565&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mappers/mod_rewrite.c (original)
+++ httpd/httpd/trunk/modules/mappers/mod_rewrite.c Fri Mar  6 09:14:07 2015
@@ -267,6 +267,8 @@ typedef struct {
     const char *dbdq;              /* SQL SELECT statement for rewritemap */
     const char *checkfile2;        /* filename to check for map existence
                                       NULL if only one file               */
+    const char *user;              /* run RewriteMap program as this user */
+    const char *group;             /* run RewriteMap program as this group */
 } rewritemap_entry;
 
 /* special pattern types for RewriteCond */
@@ -1171,6 +1173,7 @@ static void rewrite_child_errfn(apr_pool
 
 static apr_status_t rewritemap_program_child(apr_pool_t *p,
                                              const char *progname, char **argv,
+                                             const char *user, const char *group,
                                              apr_file_t **fpout,
                                              apr_file_t **fpin)
 {
@@ -1183,6 +1186,8 @@ static apr_status_t rewritemap_program_c
                                                   APR_FULL_BLOCK, APR_NO_PIPE))
         && APR_SUCCESS == (rc=apr_procattr_dir_set(procattr,
                                              ap_make_dirstr_parent(p, argv[0])))
+        && (!user || APR_SUCCESS == (rc=apr_procattr_user_set(procattr, user, "")))
+        && (!group || APR_SUCCESS == (rc=apr_procattr_group_set(procattr, group)))
         && APR_SUCCESS == (rc=apr_procattr_cmdtype_set(procattr, APR_PROGRAM))
         && APR_SUCCESS == (rc=apr_procattr_child_errfn_set(procattr,
                                                            rewrite_child_errfn))
@@ -1240,6 +1245,7 @@ static apr_status_t run_rewritemap_progr
         }
 
         rc = rewritemap_program_child(p, map->argv[0], map->argv,
+                                      map->user, map->group,
                                       &fpout, &fpin);
         if (rc != APR_SUCCESS || fpin == NULL || fpout == NULL) {
             ap_log_error(APLOG_MARK, APLOG_ERR, rc, s, APLOGNO(00654)
@@ -3018,7 +3024,7 @@ static const char *cmd_rewriteoptions(cm
 }
 
 static const char *cmd_rewritemap(cmd_parms *cmd, void *dconf, const char *a1,
-                                  const char *a2)
+                                  const char *a2, const char *a3)
 {
     rewrite_server_conf *sconf;
     rewritemap_entry *newmap;
@@ -3124,6 +3130,11 @@ static const char *cmd_rewritemap(cmd_pa
 
         newmap->type      = MAPTYPE_PRG;
         newmap->checkfile = newmap->argv[0];
+        if (a3) {
+            char *tok_cntx;
+            newmap->user = apr_strtok(apr_pstrdup(cmd->pool, a3), ":", &tok_cntx);
+            newmap->group = apr_strtok(NULL, ":", &tok_cntx);
+        }
     }
     else if (strncasecmp(a2, "int:", 4) == 0) {
         newmap->type      = MAPTYPE_INT;
@@ -5205,8 +5216,8 @@ static const command_rec command_table[]
                      "an input string and a to be applied regexp-pattern"),
     AP_INIT_RAW_ARGS("RewriteRule",     cmd_rewriterule,     NULL, OR_FILEINFO,
                      "an URL-applied regexp-pattern and a substitution URL"),
-    AP_INIT_TAKE2(   "RewriteMap",      cmd_rewritemap,      NULL, RSRC_CONF,
-                     "a mapname and a filename"),
+    AP_INIT_TAKE23(   "RewriteMap",      cmd_rewritemap,      NULL, RSRC_CONF,
+                     "a mapname and a filename and options"),
     { NULL }
 };
 



Re: svn commit: r1664565 - in /httpd/httpd/trunk: CHANGES docs/manual/rewrite/rewritemap.xml modules/mappers/mod_rewrite.c

Posted by Yann Ylavic <yl...@gmail.com>.
Hi Jan,

On Fri, Mar 6, 2015 at 10:14 AM,  <jk...@apache.org> wrote:
> Author: jkaluza
> Date: Fri Mar  6 09:14:07 2015
> New Revision: 1664565
>
> URL: http://svn.apache.org/r1664565
> Log:
> *) mod_rewrite: Add support for starting External Rewriting Programs
>    as non-root user on UNIX systems by specifying username and group name
>    as third argument of RewriteMap directive.
>
> Modified:
>     httpd/httpd/trunk/CHANGES
>     httpd/httpd/trunk/docs/manual/rewrite/rewritemap.xml
>     httpd/httpd/trunk/modules/mappers/mod_rewrite.c
>
[]
> Modified: httpd/httpd/trunk/docs/manual/rewrite/rewritemap.xml
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/rewrite/rewritemap.xml?rev=1664565&r1=1664564&r2=1664565&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/docs/manual/rewrite/rewritemap.xml (original)
> +++ httpd/httpd/trunk/docs/manual/rewrite/rewritemap.xml Fri Mar  6 09:14:07 2015
> @@ -349,6 +349,11 @@ by many requests.
>      module="mod_rewrite">RewriteEngine</directive> set to
>      <code>on</code>.</p>
>
> +    <p>By default, external rewriting programs are started as root.

s/started as root/run as the user:group who started httpd/ ?

> +    This can be changed on UNIX systems by passing user name and
> +    group name as third argument to <directive module="mod_rewrite">
> +    RewriteMap</directive> in the <code>username:groupname</code> format.</p>
> +
>      <p>This feature utilizes the <code>rewrite-map</code> mutex,
>      which is required for reliable communication with the program.
>      The mutex mechanism and lock file can be configured with the
> @@ -360,7 +365,7 @@ by many requests.
>  <p><strong>Rewrite configuration</strong></p>
>      <highlight language="config">
>
> -RewriteMap d2u prg:/www/bin/dash2under.pl<br />
> +RewriteMap d2u prg:/www/bin/dash2under.pl apache:apache<br />
>  RewriteRule - ${d2u:%{REQUEST_URI}}
>      </highlight>
>
>

Could you please also modify Syntax (and describe a bit) in
mod_rewrite.html#rewritemap (docs/manual/mod/mod_rewrite.xml) too?

Regards,
Yann.