aboutsummaryrefslogtreecommitdiffstats
path: root/openwrt/package/osiris/patches/mod_uptime.patch
blob: 2bfeec6b44d84bdc65d97953ee5e900ea60f6c6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
Description: 	The mod_uptime module obtains the system boot time value 
		for comparison with scans.
Version: 	0.2

--- osiris-4.1.8-orig/src/osirisd/modules/mod_uptime/Makefile	1970-01-01 01:00:00.000000000 +0100
+++ osiris-4.1.8-1/src/osirisd/modules/mod_uptime/Makefile	2005-04-22 23:11:32.000000000 +0200
@@ -0,0 +1,16 @@
+
+include ../Makefile
+
+SRCS=mod_uptime.c
+OBJS=$(SRCS:.c=.o)
+
+module: ${SRCS} ${OBJS}
+
+INCS=-I../.. -I../../../libosiris -I../../../libfileapi -I../../../..
+
+# meta-rule for compiling any "C" source file.
+$(OBJS): $(SRCS)
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) ${INCLUDES} ${INCS} $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS)  $(CFLAGS) -c $(SRCS)
+	cp $@ ..
+
--- osiris-4.1.8-orig/src/osirisd/modules/mod_uptime/README	1970-01-01 01:00:00.000000000 +0100
+++ osiris-4.1.8-1/src/osirisd/modules/mod_uptime/README	2005-04-22 23:11:32.000000000 +0200
@@ -0,0 +1,36 @@
+
+Module: mod_uptime
+Author: Brian Wotring (brian@shmoo.com)
+
+
+
+DESCRIPTION:
+
+The mod_uptime module obtains the system boot time value for comparison
+with scans.
+
+USE:
+
+To use this module, all  that is needed is to include it in the System
+block of a scan configuration, e.g.:
+
+    <System>
+    ...
+    Include mod_uptime
+    ...
+    </System>
+
+
+PARAMETERS:
+
+There are no parameters for this module.
+
+PLATFORMS:
+    
+Currently, this module is implemented for FreeBSD, OpenBSD,
+Linux, Solaris, and Mac OS X.
+
+NOTES:
+
+
+
--- osiris-4.1.8-orig/src/osirisd/modules/mod_uptime/mod_uptime.c	1970-01-01 01:00:00.000000000 +0100
+++ osiris-4.1.8-1/src/osirisd/modules/mod_uptime/mod_uptime.c	2005-04-22 23:11:32.000000000 +0200
@@ -0,0 +1,178 @@
+
+/******************************************************************************
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it, however, you cannot sell it.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+**
+**  You should have received a copy of the license attached to the
+**  use of this software.  If not, visit www.shmoo.com/osiris for
+**  details.
+**
+******************************************************************************/
+
+/*****************************************************************************
+**
+**  File:    mod_uptime.c
+**  Date:    March 22, 2004
+**
+**  Author:  Brian Wotring
+**  Purpose: platform specific methods for obtaining the system boot time.
+**
+******************************************************************************/
+
+#include "libosiris.h"
+#include "libfileapi.h"
+#include "rootpriv.h"
+#include "common.h"
+#include "version.h"
+
+#include "scanner.h"
+#include "logging.h"
+#include "config.h"
+
+#ifdef HAVE_SYS_SYSCTL_H
+#include <sys/sysctl.h>
+#endif
+
+#ifdef SYSTEM_SUNOS
+#include <utmpx.h>
+#endif
+
+#ifdef SYSTEM_LINUX
+#include <utmp.h>
+#endif
+
+#define PROC_FILE "/proc/uptime"
+#define OSI_WTMP_FILE "/var/log/wtmp"
+
+static const char *MODULE_NAME = "mod_uptime";
+
+
+void mod_uptime( SCANNER *scanner )
+{
+    SCAN_RECORD_TEXT_1 record;
+    char *time = NULL;
+    char *temp;
+
+    initialize_scan_record( (SCAN_RECORD *)&record,
+                             SCAN_RECORD_TYPE_TEXT_1 );
+
+    osi_strlcpy( record.module_name, MODULE_NAME,
+                 sizeof( record.module_name ) );
+
+#if defined(SYSTEM_FREEBSD) || defined(SYSTEM_OPENBSD) || defined(SYSTEM_DARWIN)
+    {
+        time_t t;
+        struct timeval result;
+
+        int request[2] = { CTL_KERN, KERN_BOOTTIME };
+        size_t result_len = sizeof(result);
+
+        if( sysctl( request, 2, &result, &result_len, NULL, 0 ) < 0)
+        {
+            log_error( "unable to obtain uptime value." );
+            return;
+        }
+
+        t = result.tv_sec;
+        time = ctime( &t );
+    }
+
+#elif defined(SYSTEM_SUNOS)
+    {
+        struct utmpx * ent;
+        time_t t;
+
+        while( ( ent = getutxent() ) )
+        {
+            if( !strcmp( "system boot", ent->ut_line ) )
+            {
+                t = ent->ut_tv.tv_sec;
+                time = ctime( &t );
+            }
+        }
+    }
+
+#elif defined(SYSTEM_LINUX)
+    {
+        FILE *fp;
+        time_t t;
+        struct utmp ut;
+
+        char buf[40];
+        char buf2[10];
+        int filecount = 0;
+
+next_file:
+
+        osi_strlcpy( buf, OSI_WTMP_FILE, sizeof( buf ) );
+
+        if( filecount > 0 )
+        {
+            osi_snprintf( buf2, sizeof(buf2), "%d", filecount );
+            osi_strlcat( buf, buf2, sizeof(buf) );
+        }
+
+        fp = osi_fopen( buf, "r", 0 );
+
+        if( fp == NULL )
+        {
+            log_error( "unable to obtain uptime value." );
+            return;
+        }
+
+        while(1)
+        {
+            int rc = fread( &ut, 1, sizeof(ut), fp );
+
+            /* end of file, try next. */
+
+            if( rc == 0 )
+            {
+                filecount++;                
+                fclose( fp );
+
+                goto next_file;
+            }
+
+            /* found restart event. */
+
+            if( ( strcmp( ut.ut_name, "reboot" ) == 0 ) ||
+                ( strcmp( ut.ut_name, "shutdown" ) == 0 ) )
+            {
+
+                t = ut.ut_time;
+                time = ctime( &t );
+
+                break;
+            }
+        }
+
+        fclose( fp );
+    }
+#endif
+
+    if( time == NULL )
+    {
+        log_error( "unable to obtain uptime value." );
+        return;
+    }
+
+    /* remove any trailing newline from the ctime() calls. */
+
+    if( ( temp = strchr( time, '\n' ) ) )
+    {
+        (*temp) = '\0';
+    }
+
+    osi_strlcpy( record.name, "uptime", sizeof( record.name ) );
+    osi_strlcpy( record.data, time, sizeof( record.data ) );
+
+    send_scan_data( scanner, (SCAN_RECORD *)&record );
+}
+
+