/****************************************/
/* This is the cheklogging module for   */
/* LSAT. It merely checks that log auth */
/* and log authpriv facilities are being*/
/* used. 				*/
/*					*/
/* See lsatmain.c for more details.	*/
/****************************************/

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

int checklogging(filename, distribution, verbose, html)
const char *const filename;
int distribution;
int verbose;
int html;
{
    const char * header = NULL;

    if (verbose >= 0)
    {
        printf(" Running checklogging module...\n");
    }

    /* if we are not on redhat or derivative, do not do this... */
    /* we shall append to this later for Solaris and Mac OSX    */

    /* check for the auth facility... */
    if (distribution != 5)
    {
    	/* we are not on Mac OSX */
        if ((system("grep auth\\. /etc/syslog.conf  1>/dev/null 2>/dev/null >/dev/null") == 0))
	{
	    /* match, they are logging auth */
	    header = "_Looks_ like you are using the auth log facility\nin syslog. Good.";
	}
	else
	{
            /* no match. they are not logging auth */
	    header = "Consider placing: auth.*\t\t\t\t/var/log/secure\n in your /etc/syslog.conf file.\n";
 	}
    }
	
    /* ok, call dostuff to print out the header */
    /* to the output file... 			*/
    if ((dostuff(0, filename, 0, header, html)) < 0)
    {
        /* something went wrong */
	perror(" Creation of list failed.");
	return (-1);
    }

    /* now check for authpriv facility... */
    if (distribution != 5)
    {
        /* we are not on Mac OSX */
        if ((system("grep authpriv\\. /etc/syslog.conf  1>/dev/null 2>/dev/null >/dev/null") == 0))
        {
            /* match, they are logging authpriv */
            header = "_Looks_ like you are using the authpriv log facility\nin syslog. Good.";
        }
        else
        {
            /* no match. they are not logging authpriv */
            header = "Consider placing: authpriv.*\t\t\t\t/var/log/secure\n in your /etc/syslog.conf file.\n";
        }
    }
    
    /* ok, call dostuff to print out the header */
    /* to the output file...                    */
    if ((dostuff(0, filename, 0, header, html)) < 0)
    {
        /* something went wrong */
        perror(" Creation of list failed.");
        return (-1);
    }


    if (verbose > 0)
    {
        printf(" Finished in checklogging module.\n");
    }

    return(0);
}
