backport base-files fix from whiterussian [2308],
[openwrt.git] / package / osiris / patches / mod_nvram.patch
1 --- osiris-4.1.8-orig/src/osirisd/modules/mod_nvram/Makefile 1970-01-01 01:00:00.000000000 +0100
2 +++ osiris-4.1.8-1/src/osirisd/modules/mod_nvram/Makefile 2005-04-22 23:11:32.000000000 +0200
3 @@ -0,0 +1,16 @@
4 +
5 +include ../Makefile
6 +
7 +SRCS=mod_nvram.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_nvram/README 1970-01-01 01:00:00.000000000 +0100
21 +++ osiris-4.1.8-1/src/osirisd/modules/mod_nvram/README 2005-04-22 23:11:32.000000000 +0200
22 @@ -0,0 +1,40 @@
23 +
24 +Module: mod_nvram
25 +Author: Brian Wotring (brian@shmoo.com)
26 +
27 +
28 +
29 +DESCRIPTION:
30 +
31 +The mod_nvram module reads the key=value pairs stored in nvram. This
32 +is primarily for Linksys routers, but could be modified to run on
33 +other systems if necessary. On the routers like the WRT54G, the
34 +nvram settings hold sensitive information that needs to be monitored.
35 +The format for the record structure is as follows:
36 +
37 + name:value
38 +
39 +USE:
40 +
41 +To use this module, all that is needed is to include it in the System
42 +block of a scan configuration, e.g.:
43 +
44 + <System>
45 + ...
46 + Include mod_nvram
47 + ...
48 + </System>
49 +
50 +
51 +PARAMETERS:
52 +
53 +There are no parameters for this module.
54 +
55 +PLATFORMS:
56 +
57 +Currently, only for the Linksys WRT54G and WRT54GS devices.
58 +
59 +NOTES:
60 +
61 +
62 +
63 --- osiris-4.1.8-orig/src/osirisd/modules/mod_nvram/mod_nvram.c 1970-01-01 01:00:00.000000000 +0100
64 +++ osiris-4.1.8-1/src/osirisd/modules/mod_nvram/mod_nvram.c 2005-04-22 23:11:32.000000000 +0200
65 @@ -0,0 +1,142 @@
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_users.c
85 +** Date: January 1, 2004
86 +**
87 +** Author: Brian Wotring
88 +** Purpose: platform specific methods for reading user file information.
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 +
101 +
102 +#define NVRAM_PATH "/usr/sbin/nvram"
103 +#define NVRAM_ARG "show"
104 +
105 +static const char *MODULE_NAME = "mod_nvram";
106 +
107 +
108 +void mod_nvram( SCANNER *scanner )
109 +{
110 + int pid;
111 + int pc[2];
112 + int cp[2];
113 + char temp_line[4096];
114 + FILE *file;
115 + SCAN_RECORD_TEXT_1 record;
116 +
117 + if( pipe(pc) < 0)
118 + {
119 + log_error( "mod_nvram: error creating pipe!" );
120 + return;
121 + }
122 +
123 + if( pipe(cp) < 0)
124 + {
125 + log_error( "mod_nvram: error creating pipe!" );
126 + return;
127 + }
128 +
129 + /* Create a child to run nvram command. */
130 +
131 + switch( pid = fork() )
132 + {
133 + case -1:
134 + log_error( "nvram: fork error!" );
135 + return;
136 +
137 + case 0:
138 +
139 + /* child */
140 +
141 + close(1);
142 + dup( cp[1]);
143 + close(0);
144 + close( pc[1]);
145 + close( cp[0]);
146 + execl( NVRAM_PATH, NVRAM_PATH, NVRAM_ARG, NULL );
147 + exit(0);
148 +
149 + default:
150 +
151 + /* parent */
152 +
153 + close(pc[1]);
154 + close(cp[1]);
155 +
156 + file = fdopen( cp[0], "r" );
157 +
158 + for(;;)
159 + {
160 + char *line;
161 + char *key_end;
162 +
163 + line = fgets( temp_line, sizeof( temp_line ), file );
164 +
165 + if( line == NULL)
166 + {
167 + break;
168 + }
169 +
170 + line = trim_white_space( line );
171 +
172 + /* skip commented and empty lines. */
173 +
174 + if( ( line == NULL ) || ( line[0] == '#' ) )
175 + {
176 + continue;
177 + }
178 +
179 + /* locate the username, this is the first item in the colon list. */
180 +
181 + if( ( key_end = strchr( line, '=' ) ) == NULL )
182 + {
183 + continue;
184 + }
185 +
186 + initialize_scan_record( (SCAN_RECORD *)&record,
187 + SCAN_RECORD_TYPE_TEXT_1 );
188 +
189 + osi_strlcpy( record.module_name, MODULE_NAME,
190 + sizeof( record.module_name ) );
191 +
192 + /* user the key as a key/path for this record. */
193 +
194 + (*key_end) = '\0';
195 + key_end++;
196 + osi_strlcpy( record.name, "nvram:", sizeof( record.name ) );
197 + osi_strlcat( record.name, line, sizeof( record.name ) );
198 +
199 + /* now copy in the value into the data portion. */
200 + /* and send this record on its way. */
201 +
202 + osi_strlcpy( record.data, key_end, sizeof( record.data ) );
203 + send_scan_data( scanner, (SCAN_RECORD *)&record );
204 + }
205 + }
206 +}
207 +
This page took 0.05483 seconds and 5 git commands to generate.