Changeset 667

Show
Ignore:
Timestamp:
10/16/06 20:49:48 (2 years ago)
Author:
common
Message:

nepenthes

  • submit-postgres
    • use a config var for the spools path
    • don't try to remove files which are not written and therefore lack a valid name/path
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nepenthes/trunk/modules/submit-postgres/PGDownloadContext.cpp

    r666 r667  
    5454#include "Nepenthes.hpp" 
    5555#include "LogManager.hpp" 
     56 
     57#include "submit-postgres.hpp" 
    5658 
    5759extern "C" 
     
    218220        char filepath[1024]; 
    219221 
    220         snprintf(filepath,1024,"%04d%02d%02d-%02d%02d%02d-0",  
     222        memset(filepath,0,1024); 
     223 
     224        snprintf(filepath,1023,"%04d%02d%02d-%02d%02d%02d-0",  
    221225                         t.tm_year + 1900,  
    222226                         t.tm_mon + 1,  
     
    227231 
    228232 
    229         string fullpath = string("var/spool/submitpostgres/") + string(filepath); 
     233        string fullpath = g_SubmitPostgres->getSpoolPath() + string(filepath); 
    230234        struct stat s; 
    231235 
     
    233237        while ( stat(fullpath.c_str(),&s) == 0 ) 
    234238        { 
    235                 snprintf(filepath,1024,"%04d%02d%02d-%02d%02d%02d-%i",  
     239                snprintf(filepath,1023,"%04d%02d%02d-%02d%02d%02d-%i",  
    236240                                 t.tm_year + 1900,  
    237241                                 t.tm_mon + 1,  
     
    242246                                 i); 
    243247 
    244                 fullpath = string("var/spool/submitpostgres/") + string(filepath); 
     248                fullpath = g_SubmitPostgres->getSpoolPath() + string(filepath); 
    245249                i++; 
    246250        } 
     
    251255        { 
    252256                logCrit("Could not open %s (%s)\n",fullpath.c_str(),strerror(errno)); 
     257                m_FilePath = ""; 
    253258                return 0; 
    254259        } 
     
    295300 
    296301        fclose(f); 
     302        logDebug("Wrote bencoded spoolfile %s (%i bytes)\n",m_FilePath.c_str(),benc.size()); 
    297303         
    298         return 0
     304        return benc.size()
    299305} 
    300306 
     
    307313bool PGDownloadContext::remove() 
    308314{ 
     315        logPF(); 
     316 
     317        if (m_FilePath == "") 
     318                return false; 
     319 
    309320        if (unlink(m_FilePath.c_str()) == 0) 
    310321                return true; 
     322 
    311323        logWarn("Could not remove %s (%s)\n",m_FilePath.c_str(),strerror(errno)); 
    312324        return false; 
     
    358370        m_State = s; 
    359371} 
     372 
     373 
     374 
  • nepenthes/trunk/modules/submit-postgres/PGDownloadContext.hpp

    r666 r667  
    2828 /* $Id$ */ 
    2929 
     30#ifndef HAVE_PGDOWNLOADCONTEXT_HPP 
     31#define HAVE_PGDOWNLOADCONTEXT_HPP 
     32 
    3033#include <string> 
    3134#include <stdint.h> 
     
    4043 
    4144        class SQLHandler; 
    42  
    4345 
    4446        typedef enum { 
     
    98100        }; 
    99101} 
     102 
     103#endif 
  • nepenthes/trunk/modules/submit-postgres/submit-postgres.conf.dist

    r607 r667  
    66        db      "mwcollect";    // which database to use 
    77        options "";             // not sure if options already work (ssl is an option) 
     8         
     9        spooldir "var/spool/submitpostgres/"; 
    810}; 
    911         
  • nepenthes/trunk/modules/submit-postgres/submit-postgres.cpp

    r666 r667  
    5252 */ 
    5353Nepenthes *g_Nepenthes; 
    54  
     54SubmitPostgres *g_SubmitPostgres; 
    5555 
    5656/** 
     
    7575        m_SubmitterDescription = "submit files to a postgres database"; 
    7676 
     77        m_SQLHandler = NULL; 
     78 
    7779        g_Nepenthes = nepenthes; 
     80        g_SubmitPostgres = this; 
    7881} 
    7982 
     
    8487SubmitPostgres::~SubmitPostgres() 
    8588{ 
    86  
     89        if (m_SQLHandler != NULL) 
     90        { 
     91                delete m_SQLHandler; 
     92        } 
     93 
     94        while (m_OutstandingQueries.size() > 0) 
     95        { 
     96                delete m_OutstandingQueries.front(); 
     97                m_OutstandingQueries.pop_front(); 
     98        } 
    8799} 
    88100 
     
    97109{ 
    98110 
     111        // the config 
    99112        if ( m_Config == NULL ) 
    100113        { 
     
    110123                m_DB = m_Config->getValString("submit-postgres.db"); 
    111124                m_Options = m_Config->getValString("submit-postgres.options"); 
    112  
    113                  
    114125        } 
    115126        catch (...) 
    116127        { 
     128                logCrit("submit-postgres, missing config values\n"); 
    117129                return false; 
    118130        } 
     131 
     132 
     133        // the spool dir 
     134        try  
     135        { 
     136                m_SpoolDir = m_Config->getValString("submit-postgres.spooldir"); 
     137        } 
     138        catch (...) 
     139        { 
     140                m_SpoolDir = "var/spool/submitpostgres/"; 
     141                logWarn("submit-postgres, no spooldir set in config file submit-postgres.conf, using %s as default\n",m_SpoolDir.c_str()); 
     142        } 
     143 
     144        // verify existance 
     145        struct stat s; 
     146         
     147        if(stat(m_SpoolDir.c_str(), &s) != 0) 
     148        { 
     149                logCrit("Can not access spooldir %s\n",m_SpoolDir.c_str()); 
     150                return false; 
     151        } 
     152 
     153/*      // this is useless when changing uid, as the user is changed after this 
     154        // therefore commented code with a FIXME in mind 
     155        if (access(m_SpoolDir.c_str(),R_OK|W_OK) != 0) 
     156        { 
     157                logCrit("read/write on %s failed (%s)\n",m_SpoolDir.c_str(),strerror(errno)); 
     158                return false; 
     159        } 
     160*/ 
    119161 
    120162        m_ModuleManager = m_Nepenthes->getModuleMgr(); 
     
    138180 
    139181 
    140         string m_SpoolDir = "var/spool/submitpostgres"; 
     182         
     183 
    141184        DIR *dir; 
    142185        struct dirent *dent; 
     
    156199                 
    157200                if(stat(filepath.c_str(), &s) != 0) 
    158                 { 
    159                         continue; 
    160                 } 
     201                continue; 
     202                 
    161203                 
    162204                if(S_ISREG(s.st_mode) == 0) 
    163                 { 
    164                         continue; 
    165                 } 
     205                continue; 
     206                 
    166207                 
    167208                PGDownloadContext *ctx = PGDownloadContext::unserialize(filepath.c_str()); 
     
    380421} 
    381422 
     423string SubmitPostgres::getSpoolPath() 
     424{ 
     425        return m_SpoolDir; 
     426} 
     427 
    382428extern "C" int32_t module_init(int32_t version, Module **module, Nepenthes *nepenthes) 
    383429{ 
  • nepenthes/trunk/modules/submit-postgres/submit-postgres.hpp

    r666 r667  
    7272                void sqlDisconnected(); 
    7373 
     74                string getSpoolPath(); 
     75 
     76 
    7477        private: 
    7578                SQLHandler                      *m_SQLHandler; 
     
    8285                string m_Pass; 
    8386                string m_Options; 
     87 
     88                string m_SpoolDir; 
    8489        }; 
    8590 
     
    8792 
    8893extern nepenthes::Nepenthes *g_Nepenthes; 
     94extern nepenthes::SubmitPostgres *g_SubmitPostgres;