let ipkg fail when a package file to be installed is not found
[openwrt.git] / openwrt / package / osiris / patches / mod_nvram.patch
1 Description:    The mod_nvram module was developed specifically to monitor 
2                 configuration settings stored in nvram on Linksys devices. 
3                 In the future, this module could be used to monitor other 
4                 attributes of similar devices.
5 Version:        0.1
6
7 --- osiris-4.1.8-orig/src/osirisd/modules/mod_nvram/Makefile    1970-01-01 01:00:00.000000000 +0100
8 +++ osiris-4.1.8-1/src/osirisd/modules/mod_nvram/Makefile       2005-04-22 23:11:32.000000000 +0200
9 @@ -0,0 +1,16 @@
10 +
11 +include ../Makefile
12 +
13 +SRCS=mod_nvram.c
14 +OBJS=$(SRCS:.c=.o)
15 +
16 +module: ${SRCS} ${OBJS}
17 +
18 +INCS=-I../.. -I../../../libosiris -I../../../libfileapi -I../../../..
19 +
20 +# meta-rule for compiling any "C" source file.
21 +$(OBJS): $(SRCS)
22 +       $(CC) $(DEFS) $(DEFAULT_INCLUDES) ${INCLUDES} ${INCS} $(AM_CPPFLAGS) \
23 +       $(CPPFLAGS) $(AM_CFLAGS)  $(CFLAGS) -c $(SRCS)
24 +       cp $@ ..
25 +
26 --- osiris-4.1.8-orig/src/osirisd/modules/mod_nvram/README      1970-01-01 01:00:00.000000000 +0100
27 +++ osiris-4.1.8-1/src/osirisd/modules/mod_nvram/README 2005-04-22 23:11:32.000000000 +0200
28 @@ -0,0 +1,40 @@
29 +
30 +Module: mod_nvram
31 +Author: Brian Wotring (brian@shmoo.com)
32 +
33 +
34 +
35 +DESCRIPTION:
36 +
37 +The mod_nvram module reads the key=value pairs stored in nvram.  This
38 +is primarily for Linksys routers, but could be modified to run on
39 +other systems if necessary.  On the routers like the WRT54G, the 
40 +nvram settings hold sensitive information that needs to be monitored.
41 +The format for the record structure is as follows:
42 +
43 +    name:value
44 +
45 +USE:
46 +
47 +To use this module, all  that is needed is to include it in the System
48 +block of a scan configuration, e.g.:
49 +
50 +    <System>
51 +    ...
52 +    Include mod_nvram
53 +    ...
54 +    </System>
55 +
56 +
57 +PARAMETERS:
58 +
59 +There are no parameters for this module.
60 +
61 +PLATFORMS:
62 +
63 +Currently, only for the Linksys WRT54G and WRT54GS devices.    
64 +
65 +NOTES:
66 +
67 +
68 +
69 --- osiris-4.1.8-orig/src/osirisd/modules/mod_nvram/mod_nvram.c 1970-01-01 01:00:00.000000000 +0100
70 +++ osiris-4.1.8-1/src/osirisd/modules/mod_nvram/mod_nvram.c    2005-04-22 23:11:32.000000000 +0200
71 @@ -0,0 +1,142 @@
72 +
73 +/******************************************************************************
74 +**
75 +**  This program is free software; you can redistribute it and/or
76 +**  modify it, however, you cannot sell it.
77 +**
78 +**  This program is distributed in the hope that it will be useful,
79 +**  but WITHOUT ANY WARRANTY; without even the implied warranty of
80 +**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
81 +**
82 +**  You should have received a copy of the license attached to the
83 +**  use of this software.  If not, visit www.shmoo.com/osiris for
84 +**  details.
85 +**
86 +******************************************************************************/
87 +
88 +/*****************************************************************************
89 +**
90 +**  File:    mod_users.c
91 +**  Date:    January 1, 2004
92 +**
93 +**  Author:  Brian Wotring
94 +**  Purpose: platform specific methods for reading user file information.
95 +**
96 +******************************************************************************/
97 +
98 +#include "libosiris.h"
99 +#include "libfileapi.h"
100 +#include "rootpriv.h"
101 +#include "common.h"
102 +#include "version.h"
103 +
104 +#include "scanner.h"
105 +#include "logging.h"
106 +
107 +
108 +#define NVRAM_PATH "/usr/sbin/nvram"
109 +#define NVRAM_ARG "show"
110 +
111 +static const char *MODULE_NAME = "mod_nvram";
112 +
113 +
114 +void mod_nvram( SCANNER *scanner )
115 +{
116 +    int pid;
117 +    int pc[2];
118 +    int cp[2];
119 +    char temp_line[4096];
120 +    FILE *file;
121 +    SCAN_RECORD_TEXT_1 record;
122 +
123 +    if( pipe(pc) < 0)
124 +    {
125 +        log_error( "mod_nvram: error creating pipe!" );
126 +        return;
127 +    }
128 +
129 +    if( pipe(cp) < 0)
130 +    {
131 +        log_error( "mod_nvram: error creating pipe!" );
132 +        return;
133 +    }
134 +
135 +    /* Create a child to run nvram command. */
136 +
137 +    switch( pid = fork() )
138 +    {
139 +        case -1:
140 +            log_error( "nvram: fork error!" );
141 +            return;
142 +
143 +        case 0:
144 +
145 +            /* child */
146 +
147 +            close(1);    
148 +            dup( cp[1]); 
149 +            close(0); 
150 +            close( pc[1]);
151 +            close( cp[0]);
152 +            execl( NVRAM_PATH, NVRAM_PATH, NVRAM_ARG, NULL );
153 +            exit(0);
154 +
155 +        default:
156 +
157 +            /* parent */
158 +
159 +            close(pc[1]);
160 +            close(cp[1]);
161 +
162 +            file = fdopen( cp[0], "r" );
163 +
164 +            for(;;)
165 +            {
166 +                char *line;
167 +                char *key_end;
168 +
169 +                line = fgets( temp_line, sizeof( temp_line ), file );
170 +
171 +                if( line == NULL)
172 +                {
173 +                    break;
174 +                }
175 +
176 +                line = trim_white_space( line );
177 +
178 +                /* skip commented and empty lines. */
179 +
180 +                if( ( line == NULL ) || ( line[0] == '#' ) )
181 +                {
182 +                    continue;
183 +                }
184 +
185 +                /* locate the username, this is the first item in the colon list. */
186 +
187 +                if( ( key_end = strchr( line, '=' ) ) == NULL )
188 +                {
189 +                    continue;
190 +                }
191 +
192 +                initialize_scan_record( (SCAN_RECORD *)&record,
193 +                                         SCAN_RECORD_TYPE_TEXT_1 );
194 +
195 +                osi_strlcpy( record.module_name, MODULE_NAME,
196 +                             sizeof( record.module_name ) );
197 +
198 +                /* user the key as a key/path for this record. */
199 +
200 +                (*key_end) = '\0';
201 +                key_end++;
202 +                osi_strlcpy( record.name, "nvram:", sizeof( record.name ) );
203 +                osi_strlcat( record.name, line, sizeof( record.name ) );
204 +
205 +                /* now copy in the value into the data portion. */
206 +                /* and send this record on its way.             */
207 +
208 +                osi_strlcpy( record.data, key_end, sizeof( record.data ) );
209 +                send_scan_data( scanner, (SCAN_RECORD *)&record );
210 +            }
211 +    }
212 +}
213 +