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