source:
freewrt/package/osiris/patches/mod_uptime.patch@
9df7618
| Last change on this file since 9df7618 was 475ad56, checked in by , 20 years ago | |
|---|---|
|
|
| File size: 5.8 KB | |
-
src/osirisd/modules/mod_uptime/Makefile
Description: The mod_uptime module obtains the system boot time value for comparison with scans. Version: 0.2
old new 1 2 include ../Makefile 3 4 SRCS=mod_uptime.c 5 OBJS=$(SRCS:.c=.o) 6 7 module: ${SRCS} ${OBJS} 8 9 INCS=-I../.. -I../../../libosiris -I../../../libfileapi -I../../../.. 10 11 # meta-rule for compiling any "C" source file. 12 $(OBJS): $(SRCS) 13 $(CC) $(DEFS) $(DEFAULT_INCLUDES) ${INCLUDES} ${INCS} $(AM_CPPFLAGS) \ 14 $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $(SRCS) 15 cp $@ .. 16 -
src/osirisd/modules/mod_uptime/README
old new 1 2 Module: mod_uptime 3 Author: Brian Wotring (brian@shmoo.com) 4 5 6 7 DESCRIPTION: 8 9 The mod_uptime module obtains the system boot time value for comparison 10 with scans. 11 12 USE: 13 14 To use this module, all that is needed is to include it in the System 15 block of a scan configuration, e.g.: 16 17 <System> 18 ... 19 Include mod_uptime 20 ... 21 </System> 22 23 24 PARAMETERS: 25 26 There are no parameters for this module. 27 28 PLATFORMS: 29 30 Currently, this module is implemented for FreeBSD, OpenBSD, 31 Linux, Solaris, and Mac OS X. 32 33 NOTES: 34 35 36 -
src/osirisd/modules/mod_uptime/mod_uptime.c
old new 1 2 /****************************************************************************** 3 ** 4 ** This program is free software; you can redistribute it and/or 5 ** modify it, however, you cannot sell it. 6 ** 7 ** This program is distributed in the hope that it will be useful, 8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 ** 11 ** You should have received a copy of the license attached to the 12 ** use of this software. If not, visit www.shmoo.com/osiris for 13 ** details. 14 ** 15 ******************************************************************************/ 16 17 /***************************************************************************** 18 ** 19 ** File: mod_uptime.c 20 ** Date: March 22, 2004 21 ** 22 ** Author: Brian Wotring 23 ** Purpose: platform specific methods for obtaining the system boot time. 24 ** 25 ******************************************************************************/ 26 27 #include "libosiris.h" 28 #include "libfileapi.h" 29 #include "rootpriv.h" 30 #include "common.h" 31 #include "version.h" 32 33 #include "scanner.h" 34 #include "logging.h" 35 #include "config.h" 36 37 #ifdef HAVE_SYS_SYSCTL_H 38 #include <sys/sysctl.h> 39 #endif 40 41 #ifdef SYSTEM_SUNOS 42 #include <utmpx.h> 43 #endif 44 45 #ifdef SYSTEM_LINUX 46 #include <utmp.h> 47 #endif 48 49 #define PROC_FILE "/proc/uptime" 50 #define OSI_WTMP_FILE "/var/log/wtmp" 51 52 static const char *MODULE_NAME = "mod_uptime"; 53 54 55 void mod_uptime( SCANNER *scanner ) 56 { 57 SCAN_RECORD_TEXT_1 record; 58 char *time = NULL; 59 char *temp; 60 61 initialize_scan_record( (SCAN_RECORD *)&record, 62 SCAN_RECORD_TYPE_TEXT_1 ); 63 64 osi_strlcpy( record.module_name, MODULE_NAME, 65 sizeof( record.module_name ) ); 66 67 #if defined(SYSTEM_FREEBSD) || defined(SYSTEM_OPENBSD) || defined(SYSTEM_DARWIN) 68 { 69 time_t t; 70 struct timeval result; 71 72 int request[2] = { CTL_KERN, KERN_BOOTTIME }; 73 size_t result_len = sizeof(result); 74 75 if( sysctl( request, 2, &result, &result_len, NULL, 0 ) < 0) 76 { 77 log_error( "unable to obtain uptime value." ); 78 return; 79 } 80 81 t = result.tv_sec; 82 time = ctime( &t ); 83 } 84 85 #elif defined(SYSTEM_SUNOS) 86 { 87 struct utmpx * ent; 88 time_t t; 89 90 while( ( ent = getutxent() ) ) 91 { 92 if( !strcmp( "system boot", ent->ut_line ) ) 93 { 94 t = ent->ut_tv.tv_sec; 95 time = ctime( &t ); 96 } 97 } 98 } 99 100 #elif defined(SYSTEM_LINUX) 101 { 102 FILE *fp; 103 time_t t; 104 struct utmp ut; 105 106 char buf[40]; 107 char buf2[10]; 108 int filecount = 0; 109 110 next_file: 111 112 osi_strlcpy( buf, OSI_WTMP_FILE, sizeof( buf ) ); 113 114 if( filecount > 0 ) 115 { 116 osi_snprintf( buf2, sizeof(buf2), "%d", filecount ); 117 osi_strlcat( buf, buf2, sizeof(buf) ); 118 } 119 120 fp = osi_fopen( buf, "r", 0 ); 121 122 if( fp == NULL ) 123 { 124 log_error( "unable to obtain uptime value." ); 125 return; 126 } 127 128 while(1) 129 { 130 int rc = fread( &ut, 1, sizeof(ut), fp ); 131 132 /* end of file, try next. */ 133 134 if( rc == 0 ) 135 { 136 filecount++; 137 fclose( fp ); 138 139 goto next_file; 140 } 141 142 /* found restart event. */ 143 144 if( ( strcmp( ut.ut_name, "reboot" ) == 0 ) || 145 ( strcmp( ut.ut_name, "shutdown" ) == 0 ) ) 146 { 147 148 t = ut.ut_time; 149 time = ctime( &t ); 150 151 break; 152 } 153 } 154 155 fclose( fp ); 156 } 157 #endif 158 159 if( time == NULL ) 160 { 161 log_error( "unable to obtain uptime value." ); 162 return; 163 } 164 165 /* remove any trailing newline from the ctime() calls. */ 166 167 if( ( temp = strchr( time, '\n' ) ) ) 168 { 169 (*temp) = '\0'; 170 } 171 172 osi_strlcpy( record.name, "uptime", sizeof( record.name ) ); 173 osi_strlcpy( record.data, time, sizeof( record.data ) ); 174 175 send_scan_data( scanner, (SCAN_RECORD *)&record ); 176 } 177 178
Note:
See TracBrowser
for help on using the repository browser.
