1 Description: The mod_uptime module obtains the system boot time value
2 for comparison with scans.
5 --- osiris-4.1.8-orig/src/osirisd/modules/mod_uptime/Makefile 1970-01-01 01:00:00.000000000 +0100
6 +++ osiris-4.1.8-1/src/osirisd/modules/mod_uptime/Makefile 2005-04-22 23:11:32.000000000 +0200
14 +module: ${SRCS} ${OBJS}
16 +INCS=-I../.. -I../../../libosiris -I../../../libfileapi -I../../../..
18 +# meta-rule for compiling any "C" source file.
20 + $(CC) $(DEFS) $(DEFAULT_INCLUDES) ${INCLUDES} ${INCS} $(AM_CPPFLAGS) \
21 + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $(SRCS)
24 --- osiris-4.1.8-orig/src/osirisd/modules/mod_uptime/README 1970-01-01 01:00:00.000000000 +0100
25 +++ osiris-4.1.8-1/src/osirisd/modules/mod_uptime/README 2005-04-22 23:11:32.000000000 +0200
29 +Author: Brian Wotring (brian@shmoo.com)
35 +The mod_uptime module obtains the system boot time value for comparison
40 +To use this module, all that is needed is to include it in the System
41 +block of a scan configuration, e.g.:
52 +There are no parameters for this module.
56 +Currently, this module is implemented for FreeBSD, OpenBSD,
57 +Linux, Solaris, and Mac OS X.
63 --- osiris-4.1.8-orig/src/osirisd/modules/mod_uptime/mod_uptime.c 1970-01-01 01:00:00.000000000 +0100
64 +++ osiris-4.1.8-1/src/osirisd/modules/mod_uptime/mod_uptime.c 2005-04-22 23:11:32.000000000 +0200
67 +/******************************************************************************
69 +** This program is free software; you can redistribute it and/or
70 +** modify it, however, you cannot sell it.
72 +** This program is distributed in the hope that it will be useful,
73 +** but WITHOUT ANY WARRANTY; without even the implied warranty of
74 +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
76 +** You should have received a copy of the license attached to the
77 +** use of this software. If not, visit www.shmoo.com/osiris for
80 +******************************************************************************/
82 +/*****************************************************************************
84 +** File: mod_uptime.c
85 +** Date: March 22, 2004
87 +** Author: Brian Wotring
88 +** Purpose: platform specific methods for obtaining the system boot time.
90 +******************************************************************************/
92 +#include "libosiris.h"
93 +#include "libfileapi.h"
94 +#include "rootpriv.h"
102 +#ifdef HAVE_SYS_SYSCTL_H
103 +#include <sys/sysctl.h>
114 +#define PROC_FILE "/proc/uptime"
115 +#define OSI_WTMP_FILE "/var/log/wtmp"
117 +static const char *MODULE_NAME = "mod_uptime";
120 +void mod_uptime( SCANNER *scanner )
122 + SCAN_RECORD_TEXT_1 record;
126 + initialize_scan_record( (SCAN_RECORD *)&record,
127 + SCAN_RECORD_TYPE_TEXT_1 );
129 + osi_strlcpy( record.module_name, MODULE_NAME,
130 + sizeof( record.module_name ) );
132 +#if defined(SYSTEM_FREEBSD) || defined(SYSTEM_OPENBSD) || defined(SYSTEM_DARWIN)
135 + struct timeval result;
137 + int request[2] = { CTL_KERN, KERN_BOOTTIME };
138 + size_t result_len = sizeof(result);
140 + if( sysctl( request, 2, &result, &result_len, NULL, 0 ) < 0)
142 + log_error( "unable to obtain uptime value." );
147 + time = ctime( &t );
150 +#elif defined(SYSTEM_SUNOS)
152 + struct utmpx * ent;
155 + while( ( ent = getutxent() ) )
157 + if( !strcmp( "system boot", ent->ut_line ) )
159 + t = ent->ut_tv.tv_sec;
160 + time = ctime( &t );
165 +#elif defined(SYSTEM_LINUX)
177 + osi_strlcpy( buf, OSI_WTMP_FILE, sizeof( buf ) );
179 + if( filecount > 0 )
181 + osi_snprintf( buf2, sizeof(buf2), "%d", filecount );
182 + osi_strlcat( buf, buf2, sizeof(buf) );
185 + fp = osi_fopen( buf, "r", 0 );
189 + log_error( "unable to obtain uptime value." );
195 + int rc = fread( &ut, 1, sizeof(ut), fp );
197 + /* end of file, try next. */
207 + /* found restart event. */
209 + if( ( strcmp( ut.ut_name, "reboot" ) == 0 ) ||
210 + ( strcmp( ut.ut_name, "shutdown" ) == 0 ) )
214 + time = ctime( &t );
226 + log_error( "unable to obtain uptime value." );
230 + /* remove any trailing newline from the ctime() calls. */
232 + if( ( temp = strchr( time, '\n' ) ) )
237 + osi_strlcpy( record.name, "uptime", sizeof( record.name ) );
238 + osi_strlcpy( record.data, time, sizeof( record.data ) );
240 + send_scan_data( scanner, (SCAN_RECORD *)&record );