update snort to 2.4.4 (thanks to Richard Nadeau)
[openwrt.git] / package / osiris / patches / mod_uptime.patch
1 Description: The mod_uptime module obtains the system boot time value
2 for comparison with scans.
3 Version: 0.2
4
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
7 @@ -0,0 +1,16 @@
8 +
9 +include ../Makefile
10 +
11 +SRCS=mod_uptime.c
12 +OBJS=$(SRCS:.c=.o)
13 +
14 +module: ${SRCS} ${OBJS}
15 +
16 +INCS=-I../.. -I../../../libosiris -I../../../libfileapi -I../../../..
17 +
18 +# meta-rule for compiling any "C" source file.
19 +$(OBJS): $(SRCS)
20 + $(CC) $(DEFS) $(DEFAULT_INCLUDES) ${INCLUDES} ${INCS} $(AM_CPPFLAGS) \
21 + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $(SRCS)
22 + cp $@ ..
23 +
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
26 @@ -0,0 +1,36 @@
27 +
28 +Module: mod_uptime
29 +Author: Brian Wotring (brian@shmoo.com)
30 +
31 +
32 +
33 +DESCRIPTION:
34 +
35 +The mod_uptime module obtains the system boot time value for comparison
36 +with scans.
37 +
38 +USE:
39 +
40 +To use this module, all that is needed is to include it in the System
41 +block of a scan configuration, e.g.:
42 +
43 + <System>
44 + ...
45 + Include mod_uptime
46 + ...
47 + </System>
48 +
49 +
50 +PARAMETERS:
51 +
52 +There are no parameters for this module.
53 +
54 +PLATFORMS:
55 +
56 +Currently, this module is implemented for FreeBSD, OpenBSD,
57 +Linux, Solaris, and Mac OS X.
58 +
59 +NOTES:
60 +
61 +
62 +
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
65 @@ -0,0 +1,178 @@
66 +
67 +/******************************************************************************
68 +**
69 +** This program is free software; you can redistribute it and/or
70 +** modify it, however, you cannot sell it.
71 +**
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.
75 +**
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
78 +** details.
79 +**
80 +******************************************************************************/
81 +
82 +/*****************************************************************************
83 +**
84 +** File: mod_uptime.c
85 +** Date: March 22, 2004
86 +**
87 +** Author: Brian Wotring
88 +** Purpose: platform specific methods for obtaining the system boot time.
89 +**
90 +******************************************************************************/
91 +
92 +#include "libosiris.h"
93 +#include "libfileapi.h"
94 +#include "rootpriv.h"
95 +#include "common.h"
96 +#include "version.h"
97 +
98 +#include "scanner.h"
99 +#include "logging.h"
100 +#include "config.h"
101 +
102 +#ifdef HAVE_SYS_SYSCTL_H
103 +#include <sys/sysctl.h>
104 +#endif
105 +
106 +#ifdef SYSTEM_SUNOS
107 +#include <utmpx.h>
108 +#endif
109 +
110 +#ifdef SYSTEM_LINUX
111 +#include <utmp.h>
112 +#endif
113 +
114 +#define PROC_FILE "/proc/uptime"
115 +#define OSI_WTMP_FILE "/var/log/wtmp"
116 +
117 +static const char *MODULE_NAME = "mod_uptime";
118 +
119 +
120 +void mod_uptime( SCANNER *scanner )
121 +{
122 + SCAN_RECORD_TEXT_1 record;
123 + char *time = NULL;
124 + char *temp;
125 +
126 + initialize_scan_record( (SCAN_RECORD *)&record,
127 + SCAN_RECORD_TYPE_TEXT_1 );
128 +
129 + osi_strlcpy( record.module_name, MODULE_NAME,
130 + sizeof( record.module_name ) );
131 +
132 +#if defined(SYSTEM_FREEBSD) || defined(SYSTEM_OPENBSD) || defined(SYSTEM_DARWIN)
133 + {
134 + time_t t;
135 + struct timeval result;
136 +
137 + int request[2] = { CTL_KERN, KERN_BOOTTIME };
138 + size_t result_len = sizeof(result);
139 +
140 + if( sysctl( request, 2, &result, &result_len, NULL, 0 ) < 0)
141 + {
142 + log_error( "unable to obtain uptime value." );
143 + return;
144 + }
145 +
146 + t = result.tv_sec;
147 + time = ctime( &t );
148 + }
149 +
150 +#elif defined(SYSTEM_SUNOS)
151 + {
152 + struct utmpx * ent;
153 + time_t t;
154 +
155 + while( ( ent = getutxent() ) )
156 + {
157 + if( !strcmp( "system boot", ent->ut_line ) )
158 + {
159 + t = ent->ut_tv.tv_sec;
160 + time = ctime( &t );
161 + }
162 + }
163 + }
164 +
165 +#elif defined(SYSTEM_LINUX)
166 + {
167 + FILE *fp;
168 + time_t t;
169 + struct utmp ut;
170 +
171 + char buf[40];
172 + char buf2[10];
173 + int filecount = 0;
174 +
175 +next_file:
176 +
177 + osi_strlcpy( buf, OSI_WTMP_FILE, sizeof( buf ) );
178 +
179 + if( filecount > 0 )
180 + {
181 + osi_snprintf( buf2, sizeof(buf2), "%d", filecount );
182 + osi_strlcat( buf, buf2, sizeof(buf) );
183 + }
184 +
185 + fp = osi_fopen( buf, "r", 0 );
186 +
187 + if( fp == NULL )
188 + {
189 + log_error( "unable to obtain uptime value." );
190 + return;
191 + }
192 +
193 + while(1)
194 + {
195 + int rc = fread( &ut, 1, sizeof(ut), fp );
196 +
197 + /* end of file, try next. */
198 +
199 + if( rc == 0 )
200 + {
201 + filecount++;
202 + fclose( fp );
203 +
204 + goto next_file;
205 + }
206 +
207 + /* found restart event. */
208 +
209 + if( ( strcmp( ut.ut_name, "reboot" ) == 0 ) ||
210 + ( strcmp( ut.ut_name, "shutdown" ) == 0 ) )
211 + {
212 +
213 + t = ut.ut_time;
214 + time = ctime( &t );
215 +
216 + break;
217 + }
218 + }
219 +
220 + fclose( fp );
221 + }
222 +#endif
223 +
224 + if( time == NULL )
225 + {
226 + log_error( "unable to obtain uptime value." );
227 + return;
228 + }
229 +
230 + /* remove any trailing newline from the ctime() calls. */
231 +
232 + if( ( temp = strchr( time, '\n' ) ) )
233 + {
234 + (*temp) = '\0';
235 + }
236 +
237 + osi_strlcpy( record.name, "uptime", sizeof( record.name ) );
238 + osi_strlcpy( record.data, time, sizeof( record.data ) );
239 +
240 + send_scan_data( scanner, (SCAN_RECORD *)&record );
241 +}
242 +
243 +
This page took 0.056461 seconds and 5 git commands to generate.