Changeset 667
- Timestamp:
- 10/16/06 20:49:48 (2 years ago)
- Files:
-
- nepenthes/trunk/modules/submit-postgres/PGDownloadContext.cpp (modified) (9 diffs)
- nepenthes/trunk/modules/submit-postgres/PGDownloadContext.hpp (modified) (3 diffs)
- nepenthes/trunk/modules/submit-postgres/submit-postgres.conf.dist (modified) (1 diff)
- nepenthes/trunk/modules/submit-postgres/submit-postgres.cpp (modified) (8 diffs)
- nepenthes/trunk/modules/submit-postgres/submit-postgres.hpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nepenthes/trunk/modules/submit-postgres/PGDownloadContext.cpp
r666 r667 54 54 #include "Nepenthes.hpp" 55 55 #include "LogManager.hpp" 56 57 #include "submit-postgres.hpp" 56 58 57 59 extern "C" … … 218 220 char filepath[1024]; 219 221 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", 221 225 t.tm_year + 1900, 222 226 t.tm_mon + 1, … … 227 231 228 232 229 string fullpath = string("var/spool/submitpostgres/") + string(filepath);233 string fullpath = g_SubmitPostgres->getSpoolPath() + string(filepath); 230 234 struct stat s; 231 235 … … 233 237 while ( stat(fullpath.c_str(),&s) == 0 ) 234 238 { 235 snprintf(filepath,102 4,"%04d%02d%02d-%02d%02d%02d-%i",239 snprintf(filepath,1023,"%04d%02d%02d-%02d%02d%02d-%i", 236 240 t.tm_year + 1900, 237 241 t.tm_mon + 1, … … 242 246 i); 243 247 244 fullpath = string("var/spool/submitpostgres/") + string(filepath);248 fullpath = g_SubmitPostgres->getSpoolPath() + string(filepath); 245 249 i++; 246 250 } … … 251 255 { 252 256 logCrit("Could not open %s (%s)\n",fullpath.c_str(),strerror(errno)); 257 m_FilePath = ""; 253 258 return 0; 254 259 } … … 295 300 296 301 fclose(f); 302 logDebug("Wrote bencoded spoolfile %s (%i bytes)\n",m_FilePath.c_str(),benc.size()); 297 303 298 return 0;304 return benc.size(); 299 305 } 300 306 … … 307 313 bool PGDownloadContext::remove() 308 314 { 315 logPF(); 316 317 if (m_FilePath == "") 318 return false; 319 309 320 if (unlink(m_FilePath.c_str()) == 0) 310 321 return true; 322 311 323 logWarn("Could not remove %s (%s)\n",m_FilePath.c_str(),strerror(errno)); 312 324 return false; … … 358 370 m_State = s; 359 371 } 372 373 374 nepenthes/trunk/modules/submit-postgres/PGDownloadContext.hpp
r666 r667 28 28 /* $Id$ */ 29 29 30 #ifndef HAVE_PGDOWNLOADCONTEXT_HPP 31 #define HAVE_PGDOWNLOADCONTEXT_HPP 32 30 33 #include <string> 31 34 #include <stdint.h> … … 40 43 41 44 class SQLHandler; 42 43 45 44 46 typedef enum { … … 98 100 }; 99 101 } 102 103 #endif nepenthes/trunk/modules/submit-postgres/submit-postgres.conf.dist
r607 r667 6 6 db "mwcollect"; // which database to use 7 7 options ""; // not sure if options already work (ssl is an option) 8 9 spooldir "var/spool/submitpostgres/"; 8 10 }; 9 11 nepenthes/trunk/modules/submit-postgres/submit-postgres.cpp
r666 r667 52 52 */ 53 53 Nepenthes *g_Nepenthes; 54 54 SubmitPostgres *g_SubmitPostgres; 55 55 56 56 /** … … 75 75 m_SubmitterDescription = "submit files to a postgres database"; 76 76 77 m_SQLHandler = NULL; 78 77 79 g_Nepenthes = nepenthes; 80 g_SubmitPostgres = this; 78 81 } 79 82 … … 84 87 SubmitPostgres::~SubmitPostgres() 85 88 { 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 } 87 99 } 88 100 … … 97 109 { 98 110 111 // the config 99 112 if ( m_Config == NULL ) 100 113 { … … 110 123 m_DB = m_Config->getValString("submit-postgres.db"); 111 124 m_Options = m_Config->getValString("submit-postgres.options"); 112 113 114 125 } 115 126 catch (...) 116 127 { 128 logCrit("submit-postgres, missing config values\n"); 117 129 return false; 118 130 } 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 */ 119 161 120 162 m_ModuleManager = m_Nepenthes->getModuleMgr(); … … 138 180 139 181 140 string m_SpoolDir = "var/spool/submitpostgres"; 182 183 141 184 DIR *dir; 142 185 struct dirent *dent; … … 156 199 157 200 if(stat(filepath.c_str(), &s) != 0) 158 { 159 continue; 160 } 201 continue; 202 161 203 162 204 if(S_ISREG(s.st_mode) == 0) 163 { 164 continue; 165 } 205 continue; 206 166 207 167 208 PGDownloadContext *ctx = PGDownloadContext::unserialize(filepath.c_str()); … … 380 421 } 381 422 423 string SubmitPostgres::getSpoolPath() 424 { 425 return m_SpoolDir; 426 } 427 382 428 extern "C" int32_t module_init(int32_t version, Module **module, Nepenthes *nepenthes) 383 429 { nepenthes/trunk/modules/submit-postgres/submit-postgres.hpp
r666 r667 72 72 void sqlDisconnected(); 73 73 74 string getSpoolPath(); 75 76 74 77 private: 75 78 SQLHandler *m_SQLHandler; … … 82 85 string m_Pass; 83 86 string m_Options; 87 88 string m_SpoolDir; 84 89 }; 85 90 … … 87 92 88 93 extern nepenthes::Nepenthes *g_Nepenthes; 94 extern nepenthes::SubmitPostgres *g_SubmitPostgres;
