source: freewrt/package/osiris/patches/mod_nvram.patch@ 9df7618

freewrt_1_0 freewrt_2_0
Last change on this file since 9df7618 was 475ad56, checked in by Waldemar Brodkorb <wbx@…>, 20 years ago

add OpenWrt trunk revision 3830.

git-svn-id: svn://www.freewrt.org/trunk/freewrt@1 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 5.7 KB
  • src/osirisd/modules/mod_nvram/Makefile

    Description: 	The mod_nvram module was developed specifically to monitor 
    		configuration settings stored in nvram on Linksys devices. 
    		In the future, this module could be used to monitor other 
    		attributes of similar devices.
    Version: 	0.1
    
    old new  
     1
     2include ../Makefile
     3
     4SRCS=mod_nvram.c
     5OBJS=$(SRCS:.c=.o)
     6
     7module: ${SRCS} ${OBJS}
     8
     9INCS=-I../.. -I../../../libosiris -I../../../libfileapi -I../../../..
     10
     11# meta-rule for compiling any "C" source file.
     12$(OBJS): $(SRCS)
     13        $(CC) $(DEFS) $(DEFAULT_INCLUDES) ${INCLUDES} ${INCS} $(AM_CPPFLAGS) \
     14        $(CPPFLAGS) $(AM_CFLAGS)  $(CFLAGS) -c $(SRCS)
     15        cp $@ ..
     16
  • src/osirisd/modules/mod_nvram/README

    old new  
     1
     2Module: mod_nvram
     3Author: Brian Wotring (brian@shmoo.com)
     4
     5
     6
     7DESCRIPTION:
     8
     9The mod_nvram module reads the key=value pairs stored in nvram.  This
     10is primarily for Linksys routers, but could be modified to run on
     11other systems if necessary.  On the routers like the WRT54G, the
     12nvram settings hold sensitive information that needs to be monitored.
     13The format for the record structure is as follows:
     14
     15    name:value
     16
     17USE:
     18
     19To use this module, all  that is needed is to include it in the System
     20block of a scan configuration, e.g.:
     21
     22    <System>
     23    ...
     24    Include mod_nvram
     25    ...
     26    </System>
     27
     28
     29PARAMETERS:
     30
     31There are no parameters for this module.
     32
     33PLATFORMS:
     34
     35Currently, only for the Linksys WRT54G and WRT54GS devices.   
     36
     37NOTES:
     38
     39
     40
  • src/osirisd/modules/mod_nvram/mod_nvram.c

    old new  
     1
     2/******************************************************************************
     3**
     4**  This program is free software; you can redistribute it and/or
     5**  modify it, however, you cannot sell it.
     6**
     7**  This program is distributed in the hope that it will be useful,
     8**  but WITHOUT ANY WARRANTY; without even the implied warranty of
     9**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     10**
     11**  You should have received a copy of the license attached to the
     12**  use of this software.  If not, visit www.shmoo.com/osiris for
     13**  details.
     14**
     15******************************************************************************/
     16
     17/*****************************************************************************
     18**
     19**  File:    mod_users.c
     20**  Date:    January 1, 2004
     21**
     22**  Author:  Brian Wotring
     23**  Purpose: platform specific methods for reading user file information.
     24**
     25******************************************************************************/
     26
     27#include "libosiris.h"
     28#include "libfileapi.h"
     29#include "rootpriv.h"
     30#include "common.h"
     31#include "version.h"
     32
     33#include "scanner.h"
     34#include "logging.h"
     35
     36
     37#define NVRAM_PATH "/usr/sbin/nvram"
     38#define NVRAM_ARG "show"
     39
     40static const char *MODULE_NAME = "mod_nvram";
     41
     42
     43void mod_nvram( SCANNER *scanner )
     44{
     45    int pid;
     46    int pc[2];
     47    int cp[2];
     48    char temp_line[4096];
     49    FILE *file;
     50    SCAN_RECORD_TEXT_1 record;
     51
     52    if( pipe(pc) < 0)
     53    {
     54        log_error( "mod_nvram: error creating pipe!" );
     55        return;
     56    }
     57
     58    if( pipe(cp) < 0)
     59    {
     60        log_error( "mod_nvram: error creating pipe!" );
     61        return;
     62    }
     63
     64    /* Create a child to run nvram command. */
     65
     66    switch( pid = fork() )
     67    {
     68        case -1:
     69            log_error( "nvram: fork error!" );
     70            return;
     71
     72        case 0:
     73
     74            /* child */
     75
     76            close(1);   
     77            dup( cp[1]);
     78            close(0);
     79            close( pc[1]);
     80            close( cp[0]);
     81            execl( NVRAM_PATH, NVRAM_PATH, NVRAM_ARG, NULL );
     82            exit(0);
     83
     84        default:
     85
     86            /* parent */
     87
     88            close(pc[1]);
     89            close(cp[1]);
     90
     91            file = fdopen( cp[0], "r" );
     92
     93            for(;;)
     94            {
     95                char *line;
     96                char *key_end;
     97
     98                line = fgets( temp_line, sizeof( temp_line ), file );
     99
     100                if( line == NULL)
     101                {
     102                    break;
     103                }
     104
     105                line = trim_white_space( line );
     106
     107                /* skip commented and empty lines. */
     108
     109                if( ( line == NULL ) || ( line[0] == '#' ) )
     110                {
     111                    continue;
     112                }
     113
     114                /* locate the username, this is the first item in the colon list. */
     115
     116                if( ( key_end = strchr( line, '=' ) ) == NULL )
     117                {
     118                    continue;
     119                }
     120
     121                initialize_scan_record( (SCAN_RECORD *)&record,
     122                                         SCAN_RECORD_TYPE_TEXT_1 );
     123
     124                osi_strlcpy( record.module_name, MODULE_NAME,
     125                             sizeof( record.module_name ) );
     126
     127                /* user the key as a key/path for this record. */
     128
     129                (*key_end) = '\0';
     130                key_end++;
     131                osi_strlcpy( record.name, "nvram:", sizeof( record.name ) );
     132                osi_strlcat( record.name, line, sizeof( record.name ) );
     133
     134                /* now copy in the value into the data portion. */
     135                /* and send this record on its way.             */
     136
     137                osi_strlcpy( record.data, key_end, sizeof( record.data ) );
     138                send_scan_data( scanner, (SCAN_RECORD *)&record );
     139            }
     140    }
     141}
     142
Note: See TracBrowser for help on using the repository browser.