/[monit]/monit/files.c
ViewVC logotype

Diff of /monit/files.c

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

revision 1.7 by chopp, Thu Sep 12 16:08:39 2002 UTC revision 1.8 by hauk, Thu Sep 12 16:46:07 2002 UTC
# Line 72  void init_files() { Line 72  void init_files() {
72    char pidfile[STRLEN];    char pidfile[STRLEN];
73    
74    /* Set the location of this programs pidfile */    /* Set the location of this programs pidfile */
75    if( !getuid() ) {    if( !geteuid() ) {
76            
77      snprintf(pidfile, STRLEN, "%s/%s", MYPIDDIR, MYPIDFILE);      snprintf(pidfile, STRLEN, "%s/%s", MYPIDDIR, MYPIDFILE);
78            
# Line 234  time_t file_changedtime(char *file) { Line 234  time_t file_changedtime(char *file) {
234    
235  }  }
236    
237    
238  /**  /**
239   * Test the monit control file for its permissions.   * Secure check the monitrc file. The run control file must have the
240   * @return TRUE if the Runtime control file is just accessible by the owner,   * same uid as the REAL uid of this process, it must have permissions
241   * otherwise FALSE   * no greater than 700 and it must not be a symbolic link.  We check
242     * these conditions here. (Inspired by code from fetchmail)
243     * @param rcfile The monitrc file
244     * @return TRUE if the test passed otherwise FALSE
245   */   */
246    int rcfile_check(char *rcfile) {
 int check_rcfile_permissions(void) {  
247    
248    struct stat buf;    struct stat buf;
249      errno= 0;
250    
251    if ( !stat(Run.controlfile, &buf) ) {    if(lstat(rcfile, &buf) < 0) {
252            
253      if(( buf.st_mode & 077 ) > 0 ) {      error("%s: Cannot stat the control file '%s' -- %s\n",
254              prog, rcfile, STRERROR);
255    
256        return FALSE;      return FALSE;
257        
258      }
259    
260      } else {    if(!S_ISREG(buf.st_mode)) {
261        
262        error("%s: The control file '%s' is not a regular file.\n", prog, rcfile);
263        
264        return FALSE;
265    
266        return TRUE;    }
267        
268      if(S_ISLNK(buf.st_mode)) {
269        
270        error("%s: The control file' %s' must not be a symbolic link.\n",
271              prog, rcfile);
272        
273        return(FALSE);
274        
275      }
276    
277      }    if(buf.st_uid != geteuid())  {
278        
279        error("%s: The control file %s must be owned by you.\n", prog, rcfile);
280              
281        return FALSE;
282            
283    }    }
     
   return FALSE;  
284    
285  }    if(buf.st_mode & ~(S_IFREG | S_IREAD | S_IWRITE | S_IEXEC)) {
286        
287        error("%s: The control file '%s' must have no more than -rwx------ "
288              "(0700) permissions.\n", prog, rcfile);
289        
290        return FALSE;
291            
292      }
293    
294  /**    return TRUE;
  * Test the monit control file for its owner.  
  * @return TRUE if the Runtime control file is owned by the starting user,  
  * otherwise FALSE  
  */  
295    
296    }
297    
 int check_rcfile_owner(void) {  
298    
299    /**
300     * Check if the file is a regular file
301     * @param file A path to the file to check
302     * @return TRUE if file exist and is a regular file, otherwise FALSE
303     */
304    int isreg_file(char *file) {
305      
306    struct stat buf;    struct stat buf;
307      
308      return (stat(file, &buf) == 0 && S_ISREG(buf.st_mode));
309      
310    }
311    
   if ( !stat(Run.controlfile, &buf) ) {  
       
     if( buf.st_uid != geteuid() ) {  
   
       return FALSE;  
   
     } else {  
   
       return TRUE;  
312    
313      }  /**
314         * Check if the file exist on the system
315    }   * @file A path to the file to check
316     * @return TRUE if file exist otherwise FALSE
317     */
318    int exist_file(char *file) {
319      
320      struct stat buf;
321      
322      return (stat(file, &buf) == 0);
323        
   return FALSE;  
   
324  }  }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

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