You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Rodent of Unusual Size <co...@decus.org> on 1997/06/17 01:22:14 UTC

[PATCH] to add "UserDir disabled user ..."

    This was originally generated against the HEAD pre-NT import;
    redone.  Two files involved, src/mod_userdir.c (first patch) and
    htdocs/manual/mod/mod_userdir.html (second patch).

    Extends UserDir to allow "UserDir <pattern>", "UserDir disabled"
    (disables *all* userdir translations), and the new form:
    "UserDir disabled user1 user2 ...", which disables translations for
    only those usernames.

    #ken    :-)}

Index: mod_userdir.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_userdir.c,v
retrieving revision 1.15
diff -c -r1.15 mod_userdir.c
*** mod_userdir.c	1997/06/15 19:22:32	1.15
--- mod_userdir.c	1997/06/16 23:49:29
***************
*** 76,81 ****
--- 76,87 ----
   *
   * UserDir public_html /usr/web http://www.xyz.com/users
   *
+  * Modified by Ken Coar to provide for the following:
+  *
+  * UserDir disabled root user1
+  *
+  * If "disabled" has no other arguments, *all* ~<username> references are
+  * disabled.
   */
  
  #include "httpd.h"
***************
*** 83,121 ****
  
  module userdir_module;
  
  /*
!  * Sever config for this module is a little unconventional...
!  * It's just one string anyway, so why pretend?
   */
  
! void *create_userdir_config (pool *dummy, server_rec *s) { 
!     return (void*)DEFAULT_USER_DIR; 
  }
  
  const char *set_user_dir (cmd_parms *cmd, void *dummy, char *arg)
  {
!     void *server_conf = cmd->server->module_config;
!     
!     set_module_config (server_conf, &userdir_module, pstrdup (cmd->pool, arg));
      return NULL;
  }
  
  command_rec userdir_cmds[] = {
  { "UserDir", set_user_dir, NULL, RSRC_CONF, RAW_ARGS,
!     "the public subdirectory in users' home directories, or 'disabled'" },
  { NULL }
  };
  
  int translate_userdir (request_rec *r)
  {
      void *server_conf = r->server->module_config;
!     const char *userdirs = (char *)get_module_config(server_conf,
! 						     &userdir_module);
      char *name = r->uri;
      const char *w, *dname, *redirect;
      char *x = NULL;
  
!     if (userdirs == NULL || !strcasecmp(userdirs, "disabled") ||
          (name[0] != '/') || (name[1] != '~')) {
        return DECLINED;
      }
--- 89,179 ----
  
  module userdir_module;
  
+ typedef struct userdir_config {
+     int	    globally_disabled;
+     char    *userdir;
+     table   *disabled_users;
+ } userdir_config;
+ 
  /*
!  * Server config for this module: global disablement flag, a list of usernames
!  * ineligible for UserDir access, and the replacement string for all others.
   */
  
! void *create_userdir_config (pool *p, server_rec *s) { 
!     userdir_config
! 	    *newcfg = (userdir_config *) pcalloc (p, sizeof(userdir_config));
! 
!     newcfg->globally_disabled = 0;
!     newcfg->userdir = DEFAULT_USER_DIR;
!     newcfg->disabled_users = make_table (p, 4);
!     return (void *) newcfg; 
  }
  
  const char *set_user_dir (cmd_parms *cmd, void *dummy, char *arg)
  {
!     userdir_config
! 	    *s_cfg = (userdir_config *) get_module_config (cmd->server->module_config, &userdir_module); 
!     char    *username;
!     const char
! 	    *args = pstrdup (cmd->pool, arg);
! 
!     /*
!      * Don't even bother doing anything if we've already processed a global
!      * disable. 
!      * We *could* return an error message about the occlusion, but that would
!      * be considered a fatal configuration error and the server wouldn't
!      * start.  If we log an error to the server's error log instead, it'll
!      * show up on stderr during initial startup.
!      */
!     if (s_cfg->globally_disabled) {
! 	return NULL;
!     }
!     /*
!      * If the first word isn't "disabled", this is a simple matter - just copy
!      * what we were given into the userdir string.
!      */
!     if (strncasecmp (arg, "disabled", 8)) {
! 	s_cfg->userdir = pstrdup (cmd->pool, arg);
! 	return NULL;
!     }
!     /*
!      * If the entire argument is the single word "disabled", we're doing a
!      * global disablement.
!      */
!     if ((! strcasecmp (arg, "disabled"))  && (strlen (arg) == 8)) {
! 	s_cfg->globally_disabled = 1;
! 	return NULL;
!     }
!     /*
!      * All right, we have a list of usernames to disable.  Let's do it.. but
!      * throw away the "disabled" keyword first.
!      */
!     username = getword_conf (cmd->pool, &args);
!     while (*args) {
! 	username = getword_conf (cmd->pool, &args);
! 	table_set (s_cfg->disabled_users, username, "disabled");
!     }
      return NULL;
  }
  
  command_rec userdir_cmds[] = {
  { "UserDir", set_user_dir, NULL, RSRC_CONF, RAW_ARGS,
!     "the public subdirectory in users' home directories, or 'disabled', or 'disabled username username...'" },
  { NULL }
  };
  
  int translate_userdir (request_rec *r)
  {
      void *server_conf = r->server->module_config;
!     const userdir_config *s_cfg =
! 	    (userdir_config *) get_module_config (server_conf, &userdir_module);
      char *name = r->uri;
+     const char *userdirs = pstrdup (r->pool, s_cfg->userdir);
      const char *w, *dname, *redirect;
      char *x = NULL;
  
!     if (s_cfg->userdir == NULL || s_cfg->globally_disabled ||
          (name[0] != '/') || (name[1] != '~')) {
        return DECLINED;
      }
***************
*** 182,194 ****
            return DECLINED;
  #else /* WIN32 */
  	struct passwd *pw;
! 	if((pw=getpwnam(w)))
  #ifdef __EMX__
! 	  /* Need to manually add user name for OS/2 */
! 	  filename = pstrcat (r->pool, pw->pw_dir, w, "/", userdir, NULL);
  #else
! 	  filename = pstrcat (r->pool, pw->pw_dir, "/", userdir, NULL);
  #endif
  #endif /* WIN32 */
        }
  
--- 240,254 ----
            return DECLINED;
  #else /* WIN32 */
  	struct passwd *pw;
! 	if ((pw = getpwnam(w)))
! 	    if (table_get (s_cfg->disabled_users, pw->pw_name) == NULL) {
  #ifdef __EMX__
! 		/* Need to manually add user name for OS/2 */
! 		filename = pstrcat (r->pool, pw->pw_dir, w, "/", userdir, NULL);
  #else
! 		filename = pstrcat (r->pool, pw->pw_dir, "/", userdir, NULL);
  #endif
+ 	    }
  #endif /* WIN32 */
        }
  
Index: mod_userdir.html
===================================================================
RCS file: /export/home/cvs/apache/htdocs/manual/mod/mod_userdir.html,v
retrieving revision 1.7
diff -c -r1.7 mod_userdir.html
*** mod_userdir.html	1997/06/04 16:14:24	1.7
--- mod_userdir.html	1997/06/16 23:50:14
***************
*** 37,44 ****
  
  The UserDir directive sets the real directory in a user's home directory
  to use when a request for a document for a user is received.
! <em>Directory</em> is either <code>disabled</code>, to disable this feature,
!  or the name of a directory, following one of the following
  patterns. If not disabled, then a request for
  <code>http://www.foo.com/~bob/one/two.html</code> will be translated to:
  <pre>
--- 37,46 ----
  
  The UserDir directive sets the real directory in a user's home directory
  to use when a request for a document for a user is received.
! <em>Directory</em> is either the keyword <code>disabled</code> to disable this
! feature server-wide, the keyword <SAMP>disabled</SAMP> followed by a
! space-separated list of usernames to disable the feature for only those
! usernames, or the name of a directory, following one of the following
  patterns. If not disabled, then a request for
  <code>http://www.foo.com/~bob/one/two.html</code> will be translated to:
  <pre>