1 --- osiris-4.1.8-orig/src/osirisd/modules/mod_uptime/Makefile 1970-01-01 01:00:00.000000000 +0100
2 +++ osiris-4.1.8-1/src/osirisd/modules/mod_uptime/Makefile 2005-04-22 23:11:32.000000000 +0200
10 +module: ${SRCS} ${OBJS}
12 +INCS=-I../.. -I../../../libosiris -I../../../libfileapi -I../../../..
14 +# meta-rule for compiling any "C" source file.
16 + $(CC) $(DEFS) $(DEFAULT_INCLUDES) ${INCLUDES} ${INCS} $(AM_CPPFLAGS) \
17 + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $(SRCS)
20 --- osiris-4.1.8-orig/src/osirisd/modules/mod_uptime/README 1970-01-01 01:00:00.000000000 +0100
21 +++ osiris-4.1.8-1/src/osirisd/modules/mod_uptime/README 2005-04-22 23:11:32.000000000 +0200
25 +Author: Brian Wotring (brian@shmoo.com)
31 +The mod_uptime module obtains the system boot time value for comparison
36 +To use this module, all that is needed is to include it in the System
37 +block of a scan configuration, e.g.:
48 +There are no parameters for this module.
52 +Currently, this module is implemented for FreeBSD, OpenBSD,
53 +Linux, Solaris, and Mac OS X.
59 --- osiris-4.1.8-orig/src/osirisd/modules/mod_uptime/mod_uptime.c 1970-01-01 01:00:00.000000000 +0100
60 +++ osiris-4.1.8-1/src/osirisd/modules/mod_uptime/mod_uptime.c 2005-04-22 23:11:32.000000000 +0200
63 +/******************************************************************************
65 +** This program is free software; you can redistribute it and/or
66 +** modify it, however, you cannot sell it.
68 +** This program is distributed in the hope that it will be useful,
69 +** but WITHOUT ANY WARRANTY; without even the implied warranty of
70 +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
72 +** You should have received a copy of the license attached to the
73 +** use of this software. If not, visit www.shmoo.com/osiris for
76 +******************************************************************************/
78 +/*****************************************************************************
80 +** File: mod_uptime.c
81 +** Date: March 22, 2004
83 +** Author: Brian Wotring
84 +** Purpose: platform specific methods for obtaining the system boot time.
86 +******************************************************************************/
88 +#include "libosiris.h"
89 +#include "libfileapi.h"
90 +#include "rootpriv.h"
98 +#ifdef HAVE_SYS_SYSCTL_H
99 +#include <sys/sysctl.h>
110 +#define PROC_FILE "/proc/uptime"
111 +#define OSI_WTMP_FILE "/var/log/wtmp"
113 +static const char *MODULE_NAME = "mod_uptime";
116 +void mod_uptime( SCANNER *scanner )
118 + SCAN_RECORD_TEXT_1 record;
122 + initialize_scan_record( (SCAN_RECORD *)&record,
123 + SCAN_RECORD_TYPE_TEXT_1 );
125 + osi_strlcpy( record.module_name, MODULE_NAME,
126 + sizeof( record.module_name ) );
128 +#if defined(SYSTEM_FREEBSD) || defined(SYSTEM_OPENBSD) || defined(SYSTEM_DARWIN)
131 + struct timeval result;
133 + int request[2] = { CTL_KERN, KERN_BOOTTIME };
134 + size_t result_len = sizeof(result);
136 + if( sysctl( request, 2, &result, &result_len, NULL, 0 ) < 0)
138 + log_error( "unable to obtain uptime value." );
143 + time = ctime( &t );
146 +#elif defined(SYSTEM_SUNOS)
148 + struct utmpx * ent;
151 + while( ( ent = getutxent() ) )
153 + if( !strcmp( "system boot", ent->ut_line ) )
155 + t = ent->ut_tv.tv_sec;
156 + time = ctime( &t );
161 +#elif defined(SYSTEM_LINUX)
173 + osi_strlcpy( buf, OSI_WTMP_FILE, sizeof( buf ) );
175 + if( filecount > 0 )
177 + osi_snprintf( buf2, sizeof(buf2), "%d", filecount );
178 + osi_strlcat( buf, buf2, sizeof(buf) );
181 + fp = osi_fopen( buf, "r", 0 );
185 + log_error( "unable to obtain uptime value." );
191 + int rc = fread( &ut, 1, sizeof(ut), fp );
193 + /* end of file, try next. */
203 + /* found restart event. */
205 + if( ( strcmp( ut.ut_name, "reboot" ) == 0 ) ||
206 + ( strcmp( ut.ut_name, "shutdown" ) == 0 ) )
210 + time = ctime( &t );
222 + log_error( "unable to obtain uptime value." );
226 + /* remove any trailing newline from the ctime() calls. */
228 + if( ( temp = strchr( time, '\n' ) ) )
233 + osi_strlcpy( record.name, "uptime", sizeof( record.name ) );
234 + osi_strlcpy( record.data, time, sizeof( record.data ) );
236 + send_scan_data( scanner, (SCAN_RECORD *)&record );