/********************************************/
/* This module will (hopefully) check to see*/
/* if loadable modules are enabled in the   */
/* kernel...for a really secure system, this*/
/* should be disabled and they should be    */
/* static in the kernel. 		    */
/*                                          */ 
/* This will (obviously) not work under     */
/* Solaris or AIX...			    */
/* Note I will check in lsatmain.c to see   */
/* if we are on a linux distro before we    */
/* run this. I think this will save some    */
/* cpu cycles instead of coming here to do  */
/* this check...		   	    */
/* 					    */
/* See lsatmain.c for more details.         */
/********************************************/
 
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

int checkmodules(filename, distribution, verbose, html)
const char *const filename;
int verbose;
int distribution;
int html;
{
    const char * header   =NULL;
    const char * tempfile =NULL;
    const char * shellcode=NULL;
  
    if (verbose >= 0)
    {
        printf(" Running checkmodules module...\n");
    }


    if ((system("cat /proc/modules 1>/dev/null 2>/dev/null >/dev/null")) == 0 )
    {

        if ((system("grep module /proc/ksyms 1>/dev/null 2>/dev/null >/dev/null")) == 0)
        {

		if (system("/sbin/lsmod 2>&1|grep -e QM_MODULES") == 0)
		{
			tempfile = "/tmp/lsat1.lsat";
			header = "Modules appear to be enabled in the kernel.\nList of modules loaded:\n"; 
			shellcode = "/usr/bin/strings -an1 /proc/modules 2>&1>/tmp/lsat1.lsat";
				if ((dostuff(tempfile, filename, shellcode, header, html)) < 0)
				{
				/* rhut-rho...something bad happened */
				perror(" Creation of list failed.");
				return(-1);
				}
		} else { 
			tempfile = "/tmp/lsat1.lsat";
			header = "Modules appear to be enabled in the kernel.\nList of modules loaded:\n";
			shellcode = "/sbin/lsmod 2>&1>/tmp/lsat1.lsat";
				if ((dostuff(tempfile, filename, shellcode, header, html)) < 0)
				{
				/* rhut-rho...something bad happened */
				perror(" Creation of list failed.");
				return(-1);
				}

		}
	}
      }



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

    return(0);
}

