brian       96/05/27 12:57:43

  Modified:    src       mod_auth_anon.c
  Log:
  Submitted by:  Brian Behlendorf
  Obtained from:  Dirk vanGulik
  - more docs
  - check for a 'real' email address
  - multiple userIDs accepted, i.e. 'anonymous' 'guest' etc
  - copes with ', " and \ escapes
  - can switch logging on/off
  - can be authorative.
  DW.
  
  Revision  Changes    Path
  1.3       +125 -29   apache/src/mod_auth_anon.c
  
  Index: mod_auth_anon.c
  ===================================================================
  RCS file: /export/home/cvs/apache/src/mod_auth_anon.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -C3 -r1.2 -r1.3
  *** mod_auth_anon.c   1996/03/17 18:27:03     1.2
  --- mod_auth_anon.c   1996/05/27 19:57:42     1.3
  ***************
  *** 59,65 ****
     * 
     * Adapted to Shambhala by rst.
     *
  !  * Version 0.3 Feb 1996
     *
     * Brutally raped by [EMAIL PROTECTED] to
     * 
  --- 59,65 ----
     * 
     * Adapted to Shambhala by rst.
     *
  !  * Version 0.5 May 1996
     *
     * Brutally raped by [EMAIL PROTECTED] to
     * 
  ***************
  *** 69,87 ****
     *
     * Just add the following tokes to your <directory> setup:
     * 
  !  * Anonymous                        'magic-user-id'
     *
  !  * Anonymous_MustGiveEmail  [on | off]
  !  * Anonymous_NoUserId               [on | off]
     *
     * The magic user id is something like 'anonymous', it is NOT case 
sensitive. 
  !  *
     * The MustGiveEmail flag can be used to force users to enter something
  !  * in the password field (like an email address).
     *
     * Furthermore the 'NoUserID' flag can be set to allow completely empty
     * usernames in as well; this can be is convenient as a single return
  !  * in broken GUIs like W95 is often given by the user.
     *
     * [EMAIL PROTECTED]; http://ewse.ceo.org; http://me-www.jrc.it/~dirkx
     * 
  --- 69,90 ----
     *
     * Just add the following tokes to your <directory> setup:
     * 
  !  * Anonymous                        magic-user-id [magic-user-id]...
     *
  !  * Anonymous_MustGiveEmail  [ on | off ] default = off
  !  * Anonymous_LogEmail               [ on | off ] default = on
  !  * Anonymous_VerifyEmail    [ on | off ] default = off
  !  * Anonymous_NoUserId               [ on | off ] default = off
  !  * Anonymous_Authorative        [ on | off ] default = off
     *
     * The magic user id is something like 'anonymous', it is NOT case 
sensitive. 
  !  * 
     * The MustGiveEmail flag can be used to force users to enter something
  !  * in the password field (like an email address). Default is off.
     *
     * Furthermore the 'NoUserID' flag can be set to allow completely empty
     * usernames in as well; this can be is convenient as a single return
  !  * in broken GUIs like W95 is often given by the user. The Default is off.
     *
     * [EMAIL PROTECTED]; http://ewse.ceo.org; http://me-www.jrc.it/~dirkx
     * 
  ***************
  *** 93,129 ****
    #include "http_log.h"
    #include "http_protocol.h"
    
    typedef struct  {
    
  !     char *auth_anon;
        int   auth_anon_nouserid;
        int   auth_anon_mustemail;
    
    } anon_auth_config_rec;
    
    void *create_anon_auth_dir_config (pool *p, char *d)
    {
  !     return pcalloc (p, sizeof(anon_auth_config_rec));
    }
    
  ! char *anon_set_passwd_flag (cmd_parms *cmd, anon_auth_config_rec *sec, int 
arg) {
        sec->auth_anon_mustemail=arg;
        return NULL;
    }
    
  ! char *anon_set_userid_flag (cmd_parms *cmd, anon_auth_config_rec *sec, int 
arg) {
        sec->auth_anon_nouserid=arg;
        return NULL;
    }
    
    command_rec anon_auth_cmds[] = {
  ! { "Anonymous", set_string_slot,
  !     (void*)XtOffsetOf(anon_auth_config_rec, auth_anon),
  !     OR_AUTHCFG, TAKE1, NULL },
    { "Anonymous_MustGiveEmail", anon_set_passwd_flag, NULL, OR_AUTHCFG, FLAG, 
        "Limited to 'on' or 'off'" },
    { "Anonymous_NoUserId", anon_set_userid_flag, NULL, OR_AUTHCFG, FLAG, 
        "Limited to 'on' or 'off'" },
    
    { NULL }
    };
  --- 96,197 ----
    #include "http_log.h"
    #include "http_protocol.h"
    
  + typedef struct auth_anon {
  +     char *password;
  +     struct auth_anon * next;
  +     } auth_anon;
  + 
    typedef struct  {
    
  !     auth_anon *auth_anon_passwords;
        int   auth_anon_nouserid;
  +     int   auth_anon_logemail;
  +     int   auth_anon_verifyemail;
        int   auth_anon_mustemail;
  +     int   auth_anon_authorative;
    
    } anon_auth_config_rec;
    
    void *create_anon_auth_dir_config (pool *p, char *d)
    {
  !     anon_auth_config_rec * sec = (anon_auth_config_rec *) 
  !     pcalloc (p, sizeof(anon_auth_config_rec));
  ! 
  !     if (!sec) return NULL; /* no memory... */
  ! 
  !     /* just to illustrate the defaults really. */
  !     sec -> auth_anon_passwords              =NULL;
  ! 
  !     sec -> auth_anon_nouserid               =0;
  !     sec -> auth_anon_logemail               =1;
  !     sec -> auth_anon_verifyemail    =0;
  !     sec -> auth_anon_mustemail              =1;
  !     sec -> auth_anon_authorative        =0;
  !     return sec;
    }
    
  ! char *anon_set_passwd_flag (cmd_parms *cmd, 
  !     anon_auth_config_rec *sec, int arg) {
        sec->auth_anon_mustemail=arg;
        return NULL;
    }
    
  ! char *anon_set_userid_flag (cmd_parms *cmd, 
  !     anon_auth_config_rec *sec, int arg) {
        sec->auth_anon_nouserid=arg;
        return NULL;
    }
  + char *anon_set_logemail_flag (cmd_parms *cmd, 
  +     anon_auth_config_rec *sec, int arg) {
  +     sec->auth_anon_logemail=arg;
  +     return NULL;
  + }
  + char *anon_set_verifyemail_flag (cmd_parms *cmd, 
  +     anon_auth_config_rec *sec, int arg) {
  +     sec->auth_anon_verifyemail=arg;
  +     return NULL;
  + }
  + char *anon_set_authorative_flag (cmd_parms *cmd, 
  +     anon_auth_config_rec *sec, int arg) {
  +     sec->auth_anon_authorative=arg;
  +     return NULL;
  + }
  + 
  + char *anon_set_string_slots (cmd_parms *cmd, 
  +     anon_auth_config_rec *sec, char *arg) {
  +   
  +     auth_anon       * first;
  + 
  +     if (!(*arg))
  +       return "Anonymous string cannot be empty, use Anonymous_NoUserId 
instead";
  + 
  +     /* squeeze in a record */
  +     first = sec->auth_anon_passwords;
  +        
  +     if (
  +     (!(sec->auth_anon_passwords=(auth_anon *) palloc(cmd -> pool, 
sizeof(auth_anon)))) ||
  +     (!(sec->auth_anon_passwords->password = pstrdup(cmd -> pool, arg)))
  +        ) return "Failed to claim memory for an anonymous password...";
  + 
  +     /* and repair the next */
  +     sec->auth_anon_passwords->next = first;
  + 
  +     return NULL;
  + }
    
    command_rec anon_auth_cmds[] = {
  ! { "Anonymous", anon_set_string_slots,
  !     NULL,OR_AUTHCFG, ITERATE, NULL },
    { "Anonymous_MustGiveEmail", anon_set_passwd_flag, NULL, OR_AUTHCFG, FLAG, 
        "Limited to 'on' or 'off'" },
    { "Anonymous_NoUserId", anon_set_userid_flag, NULL, OR_AUTHCFG, FLAG, 
        "Limited to 'on' or 'off'" },
  + { "Anonymous_VerifyEmail", anon_set_verifyemail_flag, NULL, OR_AUTHCFG, 
FLAG, 
  +     "Limited to 'on' or 'off'" },
  + { "Anonymous_LogEmail", anon_set_logemail_flag, NULL, OR_AUTHCFG, FLAG, 
  +     "Limited to 'on' or 'off'" },
  + { "Anonymous_Authorative", anon_set_authorative_flag, NULL, OR_AUTHCFG, 
FLAG, 
  +     "Limited to 'on' or 'off'" },
    
    { NULL }
    };
  ***************
  *** 138,164 ****
        conn_rec *c = r->connection;
        char *send_pw;
        char errstr[MAX_STRING_LEN];
  !     int res;
        
        if ((res=get_basic_auth_pw (r,&send_pw)))
        return res;
    
        /* Ignore if we are not configured */
  !     if (!sec->auth_anon) return DECLINED;
    
        /* Do we allow an empty userID and/or is it the magic one
         */
  !     
  !     if ( (!strcasecmp(c->user,sec->auth_anon)) || 
  !     ( (!(c->user[0])) && (sec->auth_anon_nouserid))) {
  ! 
  !     /* Do we *insist* in a password of some flavour ? */
  !     if ((!sec->auth_anon_mustemail) || strlen(send_pw)) {
  !             sprintf(errstr,"Anonymous: Passwd <%s> Accepted", send_pw ? 
send_pw : "\'none\'");
  !             log_error (errstr, r->server );
  !             return OK;
  !             };
        };
         
    
       return DECLINED;
  --- 206,261 ----
        conn_rec *c = r->connection;
        char *send_pw;
        char errstr[MAX_STRING_LEN];
  !     int res=DECLINED;
        
  + 
        if ((res=get_basic_auth_pw (r,&send_pw)))
        return res;
    
        /* Ignore if we are not configured */
  !     if (!sec->auth_anon_passwords) return DECLINED;
    
        /* Do we allow an empty userID and/or is it the magic one
         */
  !     
  !     if ( (!(c->user[0])) && (sec->auth_anon_nouserid) ) {
  !       res=OK;
  !     } else {
  !       auth_anon *p=sec->auth_anon_passwords;
  !       res=DECLINED;
  !       while ((res == DECLINED) && (p !=NULL)) {
  !     if (!(strcasecmp(c->user,p->password)))
  !       res=OK;
  !     p=p->next;
  !       };
  !     };
  !     if (
  !     /* username is OK */
  !     (res == OK) &&
  !     /* password been filled out ? */ 
  !     ( (!sec->auth_anon_mustemail) || strlen(send_pw)  ) &&
  !     /* does the password look like an email address ? */
  !     ( (!sec->auth_anon_verifyemail) || 
  !          (strpbrk("@",send_pw) != NULL) || 
  !          (strpbrk(".",send_pw) != NULL) 
  !       ) 
  !     ) {
  !       if (sec->auth_anon_logemail) {
  !     sprintf(errstr,"Anonymous: Passwd <%s> Accepted", 
  !                     send_pw ? send_pw : "\'none\'");
  !     log_error (errstr, r->server );
  !       };
  !       return OK;
  !     } else {
  !         if (sec->auth_anon_authorative) {
  !     sprintf(errstr,"Anonymous: Authorative, Passwd <%s> not accepted",
  !             send_pw ? send_pw : "\'none\'");
  !     log_error(errstr,r->server);
  !     return AUTH_REQUIRED;
        };
  + 
  +     return DECLINED;
  +     };
         
    
       return DECLINED;
  ***************
  *** 166,185 ****
        
    int check_anon_access (request_rec *r) {
    
  - #ifdef notyet
        conn_rec *c = r->connection;
        anon_auth_config_rec *sec =
          (anon_auth_config_rec *)get_module_config (r->per_dir_config,
                                                &anon_auth_module);
        
        if (!sec->auth_anon) return DECLINED;
    
        if ( strcasecmp(r->connection->user,sec->auth_anon ))
                return DECLINED;
    
       return OK;
  ! #endif
  ! 
       return DECLINED;
    }
     
  --- 263,281 ----
        
    int check_anon_access (request_rec *r) {
    
        conn_rec *c = r->connection;
        anon_auth_config_rec *sec =
          (anon_auth_config_rec *)get_module_config (r->per_dir_config,
                                                &anon_auth_module);
        
  + /*
        if (!sec->auth_anon) return DECLINED;
    
        if ( strcasecmp(r->connection->user,sec->auth_anon ))
                return DECLINED;
    
       return OK;
  ! */
       return DECLINED;
    }
     
  
  
  

Reply via email to