/[monit]/monit/p.y
ViewVC logotype

Diff of /monit/p.y

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.139 by hauk, Tue Sep 30 16:03:13 2003 UTC revision 1.140 by chopp, Wed Oct 1 13:34:46 2003 UTC
# Line 217  Line 217 
217    static struct GidSet gidset= {0, ACTION_ALERT};    static struct GidSet gidset= {0, ACTION_ALERT};
218    static struct DeviceSet deviceset= {0, OPERATOR_EQUAL, -1, -1, ACTION_ALERT};    static struct DeviceSet deviceset= {0, OPERATOR_EQUAL, -1, -1, ACTION_ALERT};
219    static struct IcmpSet icmpset= {ICMP_ECHO, NET_TIMEOUT, ACTION_ALERT};    static struct IcmpSet icmpset= {ICMP_ECHO, NET_TIMEOUT, ACTION_ALERT};
220      static char * htpasswd_file= NULL;
221      
222    /* Private prototypes */    /* Private prototypes */
223    static void  initialize();    static void  initialize();
224    static void  postparse();    static void  postparse();
# Line 235  Line 236 
236    static void  addgeneric(struct PortSet *, char*, char*);    static void  addgeneric(struct PortSet *, char*, char*);
237    static void  addcommand(int);    static void  addcommand(int);
238    static void  addargument(char *);    static void  addargument(char *);
239      static int   addcredentials(char *, char *);
240      static void  addhtpasswdentry(char *, char *);
241    static uid_t get_uid(char *, uid_t);    static uid_t get_uid(char *, uid_t);
242    static gid_t get_gid(char *, gid_t);    static gid_t get_gid(char *, gid_t);
243    static void  addchecksum(struct ChecksumSet *);    static void  addchecksum(struct ChecksumSet *);
# Line 246  Line 249 
249    static void  setlogfile(char *);    static void  setlogfile(char *);
250    static void  setpidfile(char *);    static void  setpidfile(char *);
251    static void  setmailserver(char *);    static void  setmailserver(char *);
   static void  setuname(char *);  
   static void  setpasswd(char *);  
252    static void  reset_mailset();    static void  reset_mailset();
253    static void  reset_runmail();    static void  reset_runmail();
254    static void  reset_portset();    static void  reset_portset();
# Line 557  allowselfcert   : /* EMPTY */ { Line 558  allowselfcert   : /* EMPTY */ {
558                  ;                  ;
559    
560  allow           : ALLOW STRING':'STRING {  allow           : ALLOW STRING':'STRING {
561                     setuname($2);                     addcredentials($2,$4);
                    setpasswd($4);  
                    Run.Auth.defined= TRUE;  
562                   }                   }
563                    | ALLOW PATH { addhtpasswdentry($2, NULL); FREE($2); }
564                    | ALLOW PATH { htpasswd_file= $2;
565                                   /* $2 is alread xstrduped! */}
566                      allowuserlist { FREE(htpasswd_file);}
567                  | ALLOW STRING {                  | ALLOW STRING {
568                     if(!add_host_allow($2)) {                     if(!add_host_allow($2)) {
569                       log("%s: Hostname '%s' did not resolve at line %d\n",                       log("%s: Hostname '%s' did not resolve at line %d\n",
# Line 571  allow           : ALLOW STRING':'STRING Line 574  allow           : ALLOW STRING':'STRING
574                   }                   }
575                  ;                  ;
576    
577    allowuserlist   : allowuser
578                    | allowuserlist allowuser
579                    ;
580    
581    allowuser       : STRING { addhtpasswdentry(htpasswd_file, $1); FREE($1); }
582                    ;
583    
584  checkproc       : CHECKPROC SERVICENAME PIDFILE PATH {  checkproc       : CHECKPROC SERVICENAME PIDFILE PATH {
585                     check_name($<string>2);                     check_name($<string>2);
586                     createservice(TYPE_PROCESS, $<string>2, $4);                     createservice(TYPE_PROCESS, $<string>2, $4);
# Line 711  sendexpectlist  : sendexpect Line 721  sendexpectlist  : sendexpect
721                  | sendexpectlist sendexpect                  | sendexpectlist sendexpect
722                  ;                  ;
723    
724  sendexpect      : SEND STRING { addgeneric(&portset, $2, NULL);}  sendexpect      : SEND STRING { addgeneric(&portset, $2, NULL); FREE($2);}
725                  | EXPECT STRING { addgeneric(&portset, NULL, $2); }                  | EXPECT STRING { addgeneric(&portset, NULL, $2); FREE($2);}
726                  ;                  ;
727    
728  request         : /* EMPTY */  request         : /* EMPTY */
# Line 1118  static void initialize() { Line 1128  static void initialize() {
1128    Run.stopped= FALSE;    Run.stopped= FALSE;
1129    Run.dolog= FALSE;    Run.dolog= FALSE;
1130    Run.dohttpd= FALSE;    Run.dohttpd= FALSE;
1131    Run.Auth.defined= FALSE;    Run.credentials= NULL;
1132    Run.httpdssl= FALSE;    Run.httpdssl= FALSE;
1133    Run.servicessl= FALSE;    Run.servicessl= FALSE;
1134    Run.clientssl= FALSE;    Run.clientssl= FALSE;
# Line 1979  static void setmailserver(char *mailserv Line 1989  static void setmailserver(char *mailserv
1989    
1990  }  }
1991    
1992    static void addhtpasswdentry(char *filename, char *username) {
1993    
1994  /*    char *ht_username;
1995   * Set Basic Authentication username    char *ht_passwd;
1996   */    char buf[STRLEN];
1997  static void setuname(char *uname) {    FILE *handle;
1998      int credentials_added= 0;
1999      
2000      ASSERT(filename);
2001    
2002    ASSERT(uname);    handle=fopen(filename, "r");
2003    
2004    if(Run.Auth.uname) {    if ( handle==NULL ) {
2005    
2006        log("%s: Cannot read htpasswd %s at line %d\n",
2007            prog, filename, lineno-1);
2008            
2009      if(IS(Run.Auth.uname, uname)) {    }
2010      
2011      while (!feof(handle)) {
2012        char *collonindex;
2013        
2014        if (fgets(buf, STRLEN, handle)<=0) {
2015    
2016          continue;
2017                
2018        FREE(uname);      }
2019        return;  
2020        if ( NULL == (collonindex=strchr(buf, ':'))) {
2021    
2022          continue;
2023                
2024      } else {      }
2025    
2026        ht_passwd=xstrdup(collonindex+1);
2027        *collonindex='\0';
2028        ht_username=xstrdup(buf);
2029            
2030        if (username==NULL) {
2031          
2032          if (addcredentials(ht_username, ht_passwd)) {  
2033            credentials_added++;
2034          }
2035                
2036        FREE(Run.Auth.uname);      } else if (strcmp(username, ht_username) == 0)  {
2037                
2038          if (addcredentials(ht_username, ht_passwd)) {
2039            credentials_added++;
2040          }
2041          
2042        } else {
2043    
2044          FREE(ht_passwd);
2045          FREE(ht_username);
2046                
2047      }      }
2048    }    }
     
   Run.Auth.uname= uname;  
2049    
2050      if (credentials_added==0) {
2051    
2052        if ( username == NULL ) {
2053          
2054          log("%s: warning htpasswd file %s in line %i has had no usable"
2055              " credentials.\n",
2056              prog, filename, lineno);
2057    
2058        } else {
2059    
2060          log("%s: warning htpasswd file %s in line %i has had no usable"
2061              " credentials for user %s.\n",
2062              prog, filename, lineno, username);
2063    
2064        }
2065        
2066        
2067      }
2068    
2069      fclose(handle);
2070  }  }
2071    
   
2072  /*  /*
2073   * Set Basic Authentication password   * Set Basic Authentication credentials
2074   */   */
2075  static void setpasswd(char *passwd) {  static int addcredentials(char *uname, char *passwd) {
2076    
2077      ASSERT(uname);
2078    ASSERT(passwd);    ASSERT(passwd);
2079      Auth_T c;
2080    
2081    if(Run.Auth.passwd) {    if (Run.credentials == NULL) {
2082    
2083      if(IS(Run.Auth.passwd, passwd)) {      NEW(Run.credentials);
2084        c=Run.credentials;
2085        
2086      } else {
2087    
2088        if (get_user_credentials(uname) != NULL) {
2089    
2090          log("%s: warning user %s has already credentials, entry in line %i"
2091              " ignored.\n",
2092              prog, uname, lineno);
2093          FREE(uname);
2094        FREE(passwd);        FREE(passwd);
2095        return;        return FALSE;
2096          
2097        }
2098    
2099      } else {      c=Run.credentials;
2100    
2101        FREE(Run.Auth.passwd);      while ( c->next != NULL ) {
2102    
2103          c=c->next;
2104          
2105      }      }
   }  
2106    
2107    Run.Auth.passwd= passwd;      NEW(c->next);
2108        c=c->next;
2109            
2110      }
2111      
2112      c->next=NULL;
2113      c->uname=uname;
2114      c->passwd=passwd;
2115    
2116  }    DEBUG("%s: Adding credenitials for user '%s'.\n", prog, uname);
2117      
2118      return TRUE;
2119    }
2120    
2121    
2122  /*  /*

Legend:
Removed from v.1.139  
changed lines
  Added in v.1.140

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26