You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Robert S. Thau" <rs...@ai.mit.edu> on 1995/10/26 00:51:08 UTC

Another patch for groups with multiple lines in .htgroup

Here's a substantially simpler patch for the .htgroups problem.  It
reuses the existing code wherever possible, and introduces relatively
little entirely new stuff.

This patch cuts back dramatically on consing for .htgroups reading
(only allocating enough memory for a single line).  For simplicity's
sake, it retains the 8K restriction on the length of single lines in
the .htgroups file; this is at least backwards compatible with
everybody, and I don't expect it to pose a serious problem for anyone
in practice.

From: rst@ai.mit.edu
Subject: Fix problem with multiple lines in htgroup for same group
Affects: mod_auth.c
ChangeLog: Fixes problem with multiple lines in htgroup for same group

*** mod_auth.c.old	Tue Oct 10 18:00:29 1995
--- mod_auth.c	Wed Oct 25 17:07:27 1995
***************
*** 110,149 ****
      return NULL;
  }
  
! table *init_group(pool *p, char *grpfile) {
      FILE *f;
      table *grps = make_table (p, 15);
      char l[MAX_STRING_LEN];
!     char *name, *ll;
  
      if(!(f=pfopen(p, grpfile, "r")))
          return NULL;
  
      while(!(cfg_getline(l,MAX_STRING_LEN,f))) {
          if((l[0] == '#') || (!l[0])) continue;
  	ll = l;
!         name = getword(p, &ll, ':');
! 	table_set (grps, name, ll);
      }
      pfclose(p, f);
      return grps;
  }
  
- int in_group(pool *p, char *user, char *group, table *grps) {
-     char *l = table_get (grps, group);
-     char *w;
- 
-     if (!l) return 0;
- 
-     while(l[0]) {
-         w = getword_conf (p, &l);
- 	if(!strcmp(w,user))
- 	    return 1;
-     }
-     
-     return 0;
- }
- 
  /* These functions return 0 if client is OK, and proper error status
   * if not... either AUTH_REQUIRED, if we made a check, and it failed, or
   * SERVER_ERROR, if things are so totally confused that we couldn't
--- 110,147 ----
      return NULL;
  }
  
! table *groups_for_user (pool *p, char *user, char *grpfile) {
      FILE *f;
      table *grps = make_table (p, 15);
+     pool *sp;
      char l[MAX_STRING_LEN];
!     char *group_name, *ll, *w;
  
      if(!(f=pfopen(p, grpfile, "r")))
          return NULL;
  
+     sp = make_sub_pool (p);
+     
      while(!(cfg_getline(l,MAX_STRING_LEN,f))) {
          if((l[0] == '#') || (!l[0])) continue;
  	ll = l;
! 	clear_pool (sp);
! 	
!         group_name = getword(sp, &ll, ':');
! 
! 	while(ll[0]) {
! 	    w = getword_conf (sp, &ll);
! 	    if(!strcmp(w,user)) {
! 		table_set (grps, group_name, "in");
! 		break;
! 	    }
! 	}
      }
      pfclose(p, f);
+     destroy_pool (sp);
      return grps;
  }
  
  /* These functions return 0 if client is OK, and proper error status
   * if not... either AUTH_REQUIRED, if we made a check, and it failed, or
   * SERVER_ERROR, if things are so totally confused that we couldn't
***************
*** 204,210 ****
      table *grpstatus;
      
      if(sec->auth_grpfile)
!         grpstatus = init_group(r->pool, sec->auth_grpfile);
      else
          grpstatus = NULL;
  
--- 202,208 ----
      table *grpstatus;
      
      if(sec->auth_grpfile)
!         grpstatus = groups_for_user (r->pool, user, sec->auth_grpfile);
      else
          grpstatus = NULL;
  
***************
*** 229,235 ****
  	    
              while(t[0]) {
                  w = getword_conf(r->pool, &t);
!                 if(in_group(r->pool, user, w, grpstatus))
  		    return OK;
              }
          }
--- 227,233 ----
  	    
              while(t[0]) {
                  w = getword_conf(r->pool, &t);
!                 if(table_get (grpstatus, w))
  		    return OK;
              }
          }