files.c File Reference

Utilities used for managing files used by monit. More...

Go to the source code of this file.

Functions

void init_files ()
 Initialize the programs file variables.

void finalize_files ()
 Remove temporary files.

time_t get_timestamp (char *object, mode_t type)
 Get a object's last modified timestamp.

char * find_rcfile ()
 Search the system for the monit control file.

int create_pidfile (char *pidfile)
 Create a program's pidfile - Such a file is created when in daemon mode.

int is_rcfile_changed ()
 Test the monit control file for changes.

int check_rcfile (char *rcfile)
 Secure check the monitrc file.

int isreg_file (char *file)
 Check if the file is a regular file.

int exist_file (char *file)
int check_file (char *filename, char *description, int permmask)
 Security check for files.


Detailed Description

Utilities used for managing files used by monit.

Author:
Jan-Henrik Haukeland, <hauk@tildeslash.com> , Christian Hopp, <chopp@iei.tu-clausthal.de> , Martin Pala, <martin.pala@hq.iol.cz>
Version:
$Id: files.c,v 1.22 2002/12/21 01:45:22 hauk Exp $

Definition in file files.c.


Function Documentation

int check_file char *    filename,
char *    description,
int    permmask
 

Security check for files.

The files must have the same uid as the REAL uid of this process, it must have permissions no greater than "maxpermission" and it must not be a symbolic link. We check these conditions here.

Parameters:
filename  The filename of the checked file
description  The description of the checked file
permmask  The permission mask for the file
Returns:
TRUE if the test passed otherwise FALSE

Definition at line 284 of file files.c.

References ASSERT, log(), prog, and STRERROR.

Referenced by check_rcfile().

int check_rcfile char *    rcfile
 

Secure check the monitrc file.

The run control file must have the same uid as the REAL uid of this process, it must have permissions no greater than 700 and it must not be a symbolic link. We check these conditions here.

Parameters:
rcfile  The monitrc file
Returns:
TRUE if the test passed otherwise FALSE

Definition at line 233 of file files.c.

References ASSERT, and check_file().

int create_pidfile char *    pidfile
 

Create a program's pidfile - Such a file is created when in daemon mode.

The file is created with mask = PIDMASK (usually 644).

Parameters:
pidfile  The name of the pidfile to create
Returns:
TRUE if the file was created, otherwise FALSE.

Definition at line 188 of file files.c.

References ASSERT, log(), PIDMASK, prog, and STRERROR.

int exist_file char *    file
 

Definition at line 263 of file files.c.

References ASSERT.

Referenced by find_rcfile(), and get_pid().

void finalize_files  
 

Remove temporary files.

Definition at line 98 of file files.c.

References myrun::pidfile, and Run.

char* find_rcfile  
 

Search the system for the monit control file.

Try first ~/.monitrc, if that fails try ./monitrc and finally /etc/monitrc. Exit the application if the control file is not found.

Returns:
The location of monits control file (monitrc)

Definition at line 147 of file files.c.

References myrun::myenvironment::cwd, myrun::Env, exist_file(), myrun::myenvironment::home, log(), MONITRC, prog, Run, and xmalloc().

time_t get_timestamp char *    object,
mode_t    type
 

Get a object's last modified timestamp.

Parameters:
object  A object to stat
type  Requested object's type
Returns:
Max of either st_mtime or st_ctime or FALSE if not found or different type of object

Definition at line 112 of file files.c.

References ASSERT, log(), MAXIMUM, and prog.

Referenced by get_process_uptime(), init_files(), and is_rcfile_changed().

void init_files  
 

Initialize the programs file variables.

Definition at line 68 of file files.c.

References myrun::controlfile, myrun::Env, get_timestamp(), myrun::myenvironment::home, MYPIDDIR, MYPIDFILE, myrun::pidfile, Run, myrun::timestamp, and xstrdup().

int is_rcfile_changed  
 

Test the monit control file for changes.

Returns:
TRUE if the Runtime control file was changed, otherwise FALSE

Definition at line 218 of file files.c.

References myrun::controlfile, get_timestamp(), Run, and myrun::timestamp.

int isreg_file char *    file
 

Check if the file is a regular file.

Parameters:
file  A path to the file to check
Returns:
TRUE if file exist and is a regular file, otherwise FALSE

Definition at line 247 of file files.c.

References ASSERT.

Referenced by get_md5sum(), and get_pid().