/********************************************/
/* 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 )
    {
        /* we think that modules are enabled.*/
        /* lets kindof make sure...          */

        /* I am not 100% on this one. Anyone?*/
        /* Bueller? Bueller? Anyone?         */

        if ((system("grep module /proc/ksyms 1>/dev/null 2>/dev/null >/dev/null")) == 0)
        {
            /* we really think, sortof, that modules are enabled...
            header = "Modules appear to be enabled in the kernel.\nFor the paranoid, consider recompiling as static.\n"; */


		if (system("/sbin/lsmod 2>&1|grep -e QM_MODULES") == 0)
		{
			header = "Modules appear to be enabled in the kernel,\nbut lsmod refuses to show it.\nFor the paranoid, consider recompiling as static,\nor run lcap.\n"; 
				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.\nFor the paranoid, consider recompiling as static,\nor run lcap.\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);
}

