Changeset 652

Show
Ignore:
Timestamp:
09/26/06 17:06:11 (2 years ago)
Author:
common
Message:

nepenthes

  • startup cleanup
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nepenthes/trunk/modules/log-irc/log-irc.hpp

    r550 r652  
    6868 
    6969                void log(uint32_t mask, const char *message); 
    70  
     70                bool setOwnership(int32_t uid, int32_t gid) { return true; } 
    7171 
    7272                bool doStart(); 
  • nepenthes/trunk/nepenthes-core/include/ConsoleLogger.hpp

    r321 r652  
    4545                virtual                 ~ConsoleLogger(); 
    4646                virtual void    log(uint32_t mask, const char *message); 
     47                virtual bool    setOwnership(int32_t uid, int32_t gid) { return true; } 
    4748        }; 
    4849 
  • nepenthes/trunk/nepenthes-core/include/FileLogger.hpp

    r336 r652  
    4646                virtual void    log(uint32_t mask, const char *message); 
    4747                virtual void    setLogFile(const char *filename); 
     48                virtual bool    setOwnership(int32_t uid, int32_t gid); 
    4849 
    4950        private: 
  • nepenthes/trunk/nepenthes-core/include/LogHandler.hpp

    r321 r652  
    4646                virtual                 ~LogHandler(); 
    4747                virtual void    log(uint32_t mask, const char *message) = 0; 
    48          
     48                virtual bool    setOwnership(int32_t uid, int32_t gid) = 0; 
     49 
    4950        protected: 
    5051                LogManager              *m_LogManager; 
  • nepenthes/trunk/nepenthes-core/include/LogManager.hpp

    r550 r652  
    6363                void                            setColor(bool setting); 
    6464                bool                            getColorSetting(); 
    65          
     65                bool                            setOwnership(int32_t uid, int32_t gid); 
     66 
    6667        private: 
    6768                bool                            m_useColor; 
  • nepenthes/trunk/nepenthes-core/include/Nepenthes.hpp

    r594 r652  
    4040 
    4141#include <stdint.h> 
     42#include <string> 
    4243 
    4344typedef unsigned char byte; 
     
    110111        class Message; 
    111112        class SQLManager; 
     113        struct Options; 
    112114 
    113115 
     
    140142 
    141143                virtual bool                            doLoop(); 
    142                 virtual int32_t                                run(int32_t argc, char **argv); 
     144                virtual int32_t                         run(int32_t argc, char **argv); 
    143145                virtual bool                            stop(); 
    144146                virtual bool                            reloadConfig(); 
     
    160162                 
    161163                 
    162                  
     164                virtual bool           parseArguments(int32_t argc, char **argv, Options *options); 
    163165 
    164166                bool                            m_running; 
     
    167169                gid_t                           m_GID; 
    168170        protected: 
    169                 bool fileCheckMain(char *filecheckarg,int32_t argc, int32_t opti, char **argv); 
     171                bool fileCheckMain(const char *filecheckarg,int32_t argc, int32_t opti, char **argv); 
    170172                uint8_t fileCheckPrinter(const char *filename, uint8_t options); 
    171173                int32_t fileCheck(const char *filename, Message **Msg); 
    172174 
    173                 bool changeUser(char *user); 
    174                 bool changeGroup(char *group); 
     175                bool changeUser(const char *user); 
     176                bool changeGroup(const char *group); 
    175177                bool changeUser(); 
    176178                bool changeGroup(); 
     
    178180                bool setCapabilties(); 
    179181 
    180                 bool changeRoot(char *path); 
    181     }; 
     182                bool changeRoot(const char *path); 
     183        }; 
     184 
     185 
     186        enum ColorSetting 
     187        { 
     188                colorAuto, colorAlways, colorNever 
     189        }; 
     190        enum RunMode 
     191        { 
     192                runNormal, runConfigCheck, runFileCheck 
     193        }; 
     194 
     195        struct Options 
     196        { 
     197                Options(); 
     198 
     199                RunMode         m_runMode; // runNormal, runConfigCheck, runFileCheck 
     200 
     201                bool                    m_daemonize; 
     202                bool            m_verbose; 
     203                bool            m_setCaps; 
     204                bool            m_ringLogger; 
     205                ColorSetting    m_color; 
     206 
     207                const char      *m_fileCheckArguments; 
     208                const char      *m_configPath; 
     209                const char      *m_workingDir; 
     210                const char      *m_changeUser; 
     211                const char      *m_changeGroup; 
     212                const char      *m_changeRoot; 
     213                const char      *m_diskTags; 
     214                const char      *m_consoleTags; 
     215 
     216                std::string     m_logFile; 
     217                std::string     m_ringLoggerFile; 
     218        }; 
     219 
    182220} 
    183221 
  • nepenthes/trunk/nepenthes-core/include/RingFileLogger.hpp

    r332 r652  
    4848                virtual void    setMaxFiles(uint8_t count); 
    4949                virtual void    setMaxSize(size_t size); 
     50                virtual bool    setOwnership(int32_t uid, int32_t gid); 
    5051 
    5152        private: 
  • nepenthes/trunk/nepenthes-core/src/FileLogger.cpp

    r336 r652  
    3535#include <stdio.h> 
    3636#include <string> 
     37#include <sys/types.h> 
     38#include <sys/stat.h> 
     39#include <unistd.h> 
     40#include <errno.h> 
     41#include <pwd.h> 
     42#include <grp.h> 
    3743#include "FileLogger.hpp" 
    3844#include "Nepenthes.hpp" 
     
    102108        fclose(f); 
    103109} 
     110 
     111 
     112bool FileLogger::setOwnership(int32_t uid, int32_t gid) 
     113{ 
     114#if !defined(CYGWIN) && !defined(CYGWIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) && !defined(WIN32) 
     115        if ( m_Filename == NULL ) 
     116                return true; 
     117 
     118        struct stat s; 
     119        int32_t filestat = stat(m_Filename, &s); 
     120 
     121        if ( filestat != 0 ) 
     122        { 
     123                if ( errno == ENOENT ) 
     124                { 
     125                        // TODO: create the file. 
     126                        logCrit("Logfile %s does not exist\n", m_Filename); 
     127                        return false; 
     128                } 
     129                else 
     130                { 
     131                        logCrit("Could not access logfile %s: %s\n", m_Filename, strerror(errno)); 
     132                        return false; 
     133                } 
     134        } 
     135 
     136        if ( chown(m_Filename, uid, gid) != 0 ) 
     137        { 
     138                logCrit("Failed to change ownership for file %s: %s\n", m_Filename, strerror(errno)); 
     139                return false; 
     140        } 
     141 
     142        logInfo("Logfile %s ownership is now %d:%d (%s:%s)\n", m_Filename, uid, gid, getpwuid(uid)->pw_name, 
     143                        getgrgid(gid)->gr_name); 
     144#endif 
     145 
     146        return true; 
     147} 
     148 
     149 
  • nepenthes/trunk/nepenthes-core/src/LogManager.cpp

    r558 r652  
    244244        return m_useColor; 
    245245} 
     246 
     247 
     248/** 
     249 * Ensure file ownership for all attached loggers. 
     250 * 
     251 * @param user The desired username. 
     252 * @param group The desired group. 
     253 * 
     254 * @return false if at least one logger failed, true otherwise. 
     255 */ 
     256bool LogManager::setOwnership(int32_t uid, int32_t gid) 
     257{ 
     258        list<LogHandlerEntry *>::iterator it; 
     259 
     260        for ( it = m_Loggers.begin(); it != m_Loggers.end(); it++ ) 
     261                if ( !(*it)->m_Lh->setOwnership(uid, gid) ) 
     262                        return false; 
     263 
     264        return true; 
     265} 
  • nepenthes/trunk/nepenthes-core/src/Nepenthes.cpp

    r651 r652  
    7878using namespace nepenthes; 
    7979 
    80 enum ColorSetting { colorAuto, colorAlways, colorNever }; 
     80 
    8181 
    8282Nepenthes *g_Nepenthes; 
     83 
     84 
     85Options::Options() 
     86{ 
     87        m_runMode = runNormal; 
     88        m_daemonize = false; 
     89        m_verbose = false; 
     90        m_setCaps = false;       
     91        m_ringLogger = false; 
     92        m_color = colorAuto; 
     93 
     94        m_fileCheckArguments = NULL; 
     95        m_configPath = SYSCONFDIR "/nepenthes/nepenthes.conf"; 
     96        m_workingDir = PREFIX; 
     97        m_changeUser = NULL; 
     98        m_changeGroup = NULL; 
     99        m_changeRoot = NULL; 
     100        m_diskTags = NULL; 
     101        m_consoleTags = NULL; 
     102} 
     103 
     104 
    83105/** 
    84106 * the constructor 
     
    166188 * @return 0 if the application was shut down poperly, non-null if an error occured. 
    167189 */ 
    168  
    169 int32_t Nepenthes::run(int32_t argc, char **argv) 
    170 
    171         bool run=true; 
    172         bool confcheck=false; 
    173         bool filecheck=false; 
    174         bool verbose=false; 
    175         bool daemonize=false; 
    176  
    177         char *filecheckarg =NULL; 
    178         char *confpath = SYSCONFDIR "/nepenthes/nepenthes.conf"; 
    179         char *basedir; 
    180         char *workingdir = PREFIX; 
    181         char *chUser = NULL; 
    182         char *chGroup = NULL; 
    183         char *chRoot = NULL; 
    184         const char *consoleTags = 0, *diskTags = 0; 
    185         bool forcesetcaps=false; 
    186  
    187  
    188         string flpath; 
    189  
    190         string rlpath;  // ringlogger path, gets read from config 
    191         bool ringlog = false; 
    192         ColorSetting col = colorAuto; 
    193  
    194 #ifdef WIN32 
    195  
    196 #else 
    197  
     190bool Nepenthes::parseArguments(int32_t argc, char **argv, Options *options) 
     191
    198192        while( 1 ) 
    199193        { 
     
    228222                { 
    229223 
    230                 case 'b': 
    231                         basedir = optarg; 
    232                         break; 
    233  
    234224                case 'C': 
    235                         forcesetcaps = true; 
     225 
     226                        options->m_setCaps = true; 
    236227                        break; 
    237228 
    238229 
    239230                case 'c': 
    240                         confpath = optarg; 
    241                         break; 
    242  
    243                 case 'd':      // FIXME set disk loglevel 
    244                         diskTags = optarg; 
    245                         break; 
    246  
    247                 case 'D':       
    248                         daemonize = true; 
    249                        break; 
     231                        options->m_configPath = optarg; 
     232                        break; 
     233 
     234                case 'd': 
     235                        options->m_diskTags = optarg; 
     236                        break; 
     237 
     238                case 'D': 
     239                        options->m_daemonize = true;    
     240            break; 
    250241 
    251242 
    252243                case 'f': 
    253 //                      fprintf(stderr,"filecheck\n"); 
    254                         filecheckarg = optarg; 
    255                         filecheck = true; 
    256                         run=false; 
     244                        options->m_fileCheckArguments = optarg; 
     245                        options->m_runMode = runFileCheck; 
    257246                        break; 
    258247 
    259248 
    260249                case 'g': 
    261                         chGroup=optarg; 
    262                         printf("Change Group to %s\n",chGroup); 
     250                        options->m_changeGroup = optarg; 
    263251            break; 
    264252 
    265253                case 'h': 
    266254                        show_help(false); 
    267                         run=false; 
     255                        return false; 
    268256                        break; 
    269257 
    270258                case 'H': 
    271259                        show_help(true); 
    272                         run=false; 
     260                        return false; 
    273261                        break; 
    274262 
    275263                case 'i': 
    276264                        show_info(); 
    277                         run=false; 
    278                         break; 
    279  
    280                 case 'l':      // FIXME set console loglevel 
    281                         consoleTags = optarg; 
     265                        return false; 
     266                        break; 
     267 
     268                case 'l': 
     269                        options->m_consoleTags = optarg; 
    282270                        break; 
    283271 
    284272                case 'L': 
    285273                        show_loghelp(); 
    286                         run=false; 
     274                        return false; 
    287275                        break; 
    288276 
    289277                case 'k': 
    290             run = false; 
    291                         confcheck = true; 
    292                         break; 
    293  
    294                 case 'o':       // FIXME set nocolor on console 
    295                         if( !strcmp(optarg, "never") ) 
    296                                 col = colorNever; 
    297                         else if( !strcmp(optarg, "always") ) 
    298                                 col = colorAlways; 
    299                         else if( !strcmp(optarg, "auto") ) 
    300                                 col = colorAuto; 
     278            options->m_runMode = runConfigCheck; 
     279            break; 
     280 
     281                case 'o': 
     282                        if ( !strcmp(optarg, "never") ) 
     283                                options->m_color = colorNever; 
     284                        else if ( !strcmp(optarg, "always") ) 
     285                                options->m_color = colorAlways; 
     286                        else if ( !strcmp(optarg, "auto") ) 
     287                                options->m_color = colorAuto; 
    301288                        else 
    302289                        { 
    303290                                fprintf(stdout, "Invalid argument for --color; must be one of\n" 
    304291                                                "`never', `always' or `auto'.\n"); 
    305                                 run = false; 
     292                                return false; 
    306293                        } 
    307  
    308294                        break; 
    309295 
    310296                case 'r': 
    311                         chRoot = optarg; 
    312                         printf("Change Root to %s \n",chRoot); 
     297                        options->m_changeRoot = optarg; 
    313298                        break; 
    314299 
    315300                case 'R': 
    316                         ringlog = true; 
    317                         printf("Using ringlogger instead of filelogger, rotating logfiles by myself\n"); 
     301                        options->m_ringLogger = true; 
    318302                        break; 
    319303 
    320304                case 'u': 
    321             chUser = optarg; 
    322                         printf("Change User to %s \n",chUser); 
     305            options->m_changeUser = optarg; 
    323306                        break; 
    324307 
    325308 
    326309                case 'v': 
    327                         printf("DOING VERBOSE\n"); 
    328                         verbose = true; 
     310                        options->m_verbose = true; 
    329311                        break; 
    330312 
    331313                case 'V': 
    332314                        show_version(); 
    333             run = false; 
    334                         break; 
    335  
    336               case 'w': 
    337                         workingdir = optarg; 
     315                       return false; 
     316                        break; 
     317  
     318              case 'w': 
     319                        options->m_workingDir = optarg; 
    338320                        break; 
    339321 
     
    348330        } 
    349331 
    350  
    351         if( workingdir && chdir(workingdir) ) 
    352         { 
    353                 logCrit("Cannot change working diretory to %s: %s.\n", workingdir, strerror(errno)); 
     332        return true; 
     333
     334 
     335 
     336/** 
     337 * start nepenthes, using command line arguments. 
     338 *  
     339 * @param argc   number of arguments. 
     340 * @param argv   vector containing arguments. 
     341 *  
     342 * @return 0 if the application was shut down poperly, non-null if an error occured. 
     343 */ 
     344 
     345int32_t Nepenthes::run(int32_t argc, char **argv) 
     346
     347        Options             opt; 
     348 
     349 
     350        if( !parseArguments(argc, argv, &opt) ) 
    354351                return -1; 
    355         } 
    356 #endif 
    357  
    358  
    359         // lookup the userid & groupid we have to switch to 
    360         if ( chUser != NULL ) 
    361         { 
    362                 if ( changeUser(chUser) == false ) 
    363                 { 
    364                         run=false; 
     352 
     353 
     354        if( opt.m_workingDir != NULL && chdir(opt.m_workingDir) ) 
     355        { 
     356                logCrit("Cannot change working diretory to %s: %s.\n", opt.m_workingDir, strerror(errno)); 
     357                return -1; 
     358        } 
     359 
     360        if( opt.m_changeUser != NULL && !changeUser(opt.m_changeUser) ) 
     361                return -1; 
     362 
     363        if( opt.m_changeGroup != NULL && !changeGroup(opt.m_changeGroup) ) 
     364                return -1; 
     365 
     366 
     367        show_logo(); 
     368        show_version(); 
     369 
     370 
     371 
     372        if ( opt.m_runMode != runFileCheck || opt.m_verbose ) 
     373        { 
     374                m_LogManager->registerTag(l_crit,   "crit"); 
     375                m_LogManager->registerTag(l_warn,   "warn"); 
     376                m_LogManager->registerTag(l_debug,  "debug"); 
     377                m_LogManager->registerTag(l_info,   "info"); 
     378                m_LogManager->registerTag(l_spam,   "spam"); 
     379                m_LogManager->registerTag(l_net,    "net"); 
     380                m_LogManager->registerTag(l_script, "script"); 
     381                m_LogManager->registerTag(l_shell,  "shell"); 
     382                m_LogManager->registerTag(l_mem,    "mem"); 
     383                m_LogManager->registerTag(l_sc,     "sc"); 
     384                m_LogManager->registerTag(l_dl,     "down"); 
     385                m_LogManager->registerTag(l_mgr,    "mgr"); 
     386                m_LogManager->registerTag(l_hlr,    "handler"); 
     387                m_LogManager->registerTag(l_dia,    "dia"); 
     388                m_LogManager->registerTag(l_sub,    "submit"); 
     389                m_LogManager->registerTag(l_ev,     "event"); 
     390                m_LogManager->registerTag(l_mod,    "module"); 
     391                m_LogManager->registerTag(l_stdtag, "fixme"); 
     392 
     393                if ( opt.m_consoleTags ) 
     394                        m_LogManager->addLogger(new ConsoleLogger(m_LogManager), m_LogManager->parseTagString(opt.m_consoleTags)); 
     395                else 
     396                        m_LogManager->addLogger(new ConsoleLogger(m_LogManager), l_all); 
     397        } 
     398 
     399 
     400        if ( opt.m_runMode == runNormal || opt.m_runMode == runFileCheck ) 
     401        { 
     402                m_DialogueFactoryManager = new DialogueFactoryManager(this); 
     403 
     404                m_DownloadManager   = new DownloadManager(this); 
     405                m_EventManager      = new EventManager(this); 
     406 
     407                //      m_Lua                           = new Lua 
     408                m_ModuleManager     = new ModuleManager(this); 
     409                m_ShellcodeManager  = new ShellcodeManager(this); 
     410                m_SocketManager     = new SocketManager(this); 
     411                m_SubmitManager     = new SubmitManager(this); 
     412                m_Utilities         = new Utilities(); 
     413                m_DNSManager        = new DNSManager(this); 
     414                m_SQLManager        = new SQLManager(this); 
     415        } 
     416 
     417 
     418 
     419        switch ( opt.m_color ) 
     420        { 
     421        case colorAuto: 
     422                if ( isatty(STDOUT_FILENO) ) 
     423                        m_LogManager->setColor(true); 
     424                else 
     425                        m_LogManager->setColor(false); 
     426                break; 
     427 
     428        case colorNever: 
     429                m_LogManager->setColor(false); 
     430                break; 
     431 
     432        case colorAlways: 
     433                m_LogManager->setColor(true); 
     434                break; 
     435        } 
     436 
     437 
     438 
     439        /* load configuration. */ 
     440        m_Config = new Config; 
     441        logSpam("Trying to load Nepenthes Configuration from %s \n", opt.m_configPath); 
     442        try 
     443        { 
     444                m_Config->load(opt.m_configPath); 
     445                logInfo("Loaded Nepenthes Configuration from \"%s\".\n", opt.m_configPath); 
     446        } 
     447        catch ( LoadError e ) 
     448        { 
     449                fprintf(stderr, "Unable to load configuration file \"%s\": %s\n", opt.m_configPath, e.getMessage()); 
     450                return -1; 
     451        } 
     452        catch ( ParseError e ) 
     453        { 
     454                fprintf(stderr, "Parse error in \"%s\" on line %d: %s\n", opt.m_configPath, e.getLine(), e.getMessage()); 
     455                return -1; 
     456        } 
     457 
     458        if ( opt.m_runMode == runConfigCheck ) // passed if we reach this 
     459                return 0; 
     460 
     461 
     462        if ( opt.m_ringLogger == true ) 
     463        { 
     464                string rlpath; 
     465                try 
     466                { 
     467                        rlpath = m_Config->getValString("nepenthes.logmanager.ring_logging_file"); 
    365468                } 
    366  
    367         } 
    368         if ( chGroup != NULL ) 
    369         { 
    370                 if ( changeGroup(chGroup) == false) 
    371                 { 
    372                         run=false; 
     469                catch ( ... ) 
     470                { 
     471                        logCrit("Could not find nepenthes.logmanager.ring_logging_file in Config\n"); 
     472                        return false; 
    373473                } 
    374         } 
    375  
    376  
    377  
    378         if(run == true || confcheck == true || filecheck == true) 
    379         { 
    380                 if (run == true) 
    381                 { 
    382             show_logo(); 
    383                         show_version(); 
     474 
     475 
     476                RingFileLogger *fl = new RingFileLogger(m_LogManager); 
     477 
     478                fl->setLogFileFormat((char *)rlpath.c_str()); 
     479                fl->setMaxFiles(5); 
     480                fl->setMaxSize(1024 * 1024); 
     481 
     482                if ( opt.m_diskTags ) 
     483                        m_LogManager->addLogger(fl, m_LogManager->parseTagString(opt.m_diskTags)); 
     484                else 
     485                        m_LogManager->addLogger(fl, l_all); 
     486 
     487        } 
     488        else 
     489        { 
     490                string flpath; 
     491                try 
     492                { 
     493                        flpath = m_Config->getValString("nepenthes.logmanager.file_logging_file"); 
    384494                } 
    385  
    386  
    387                 if (filecheck == false || verbose == true ) 
    388                 { 
    389                         m_LogManager->registerTag(l_crit,   "crit"); 
    390                         m_LogManager->registerTag(l_warn,   "warn"); 
    391                         m_LogManager->registerTag(l_debug,  "debug"); 
    392                         m_LogManager->registerTag(l_info,   "info"); 
    393                         m_LogManager->registerTag(l_spam,   "spam"); 
    394                         m_LogManager->registerTag(l_net,    "net"); 
    395                         m_LogManager->registerTag(l_script, "script"); 
    396                         m_LogManager->registerTag(l_shell,  "shell"); 
    397                         m_LogManager->registerTag(l_mem,    "mem"); 
    398                         m_LogManager->registerTag(l_sc,     "sc"); 
    399                         m_LogManager->registerTag(l_dl,     "down"); 
    400                         m_LogManager->registerTag(l_mgr,    "mgr"); 
    401                         m_LogManager->registerTag(l_hlr,    "handler"); 
    402                         m_LogManager->registerTag(l_dia,    "dia"); 
    403                         m_LogManager->registerTag(l_sub,    "submit"); 
    404                         m_LogManager->registerTag(l_ev,     "event"); 
    405                         m_LogManager->registerTag(l_mod,    "module"); 
    406                         m_LogManager->registerTag(l_stdtag, "fixme"); 
    407  
    408                         if( consoleTags ) 
    409                                 m_LogManager->addLogger(new ConsoleLogger(m_LogManager), m_LogManager->parseTagString(consoleTags)); 
    410                         else 
    411                                 m_LogManager->addLogger(new ConsoleLogger(m_LogManager), l_all); 
     495                catch ( ... ) 
     496                { 
     497                        logCrit("Could not find nepenthes.logmanager.file_logging_file in Config\n"); 
     498                        return false; 
    412499                } 
    413500 
    414  
    415                 if ( run == true || filecheck == true) 
    416                 { 
    417                 m_DialogueFactoryManager = new DialogueFactoryManager(this); 
    418  
    419                         m_DownloadManager   = new DownloadManager(this); 
    420                         m_EventManager      = new EventManager(this); 
    421  
    422                         //      m_Lua                           = new Lua 
    423                         m_ModuleManager     = new ModuleManager(this); 
    424                         m_ShellcodeManager  = new ShellcodeManager(this); 
    425                         m_SocketManager     = new SocketManager(this); 
    426                         m_SubmitManager     = new SubmitManager(this); 
    427                         m_Utilities         = new Utilities(); 
    428                         m_DNSManager        = new DNSManager(this); 
    429                         m_SQLManager            = new SQLManager(this); 
    430                 } 
    431         } 
    432  
    433  
    434         if ( run == true || confcheck == true || filecheck == true) 
    435         { 
    436                 switch( col ) 
    437                 { 
    438                         case colorAuto: 
    439                                 if( isatty(STDOUT_FILENO) ) 
    440                                         m_LogManager->setColor(true); 
    441                                 else 
    442                                         m_LogManager->setColor(false); 
    443                                 break; 
    444                         case colorNever: 
    445                                 m_LogManager->setColor(false); 
    446                                 break; 
    447                         case colorAlways: 
    448                                 m_LogManager->setColor(true); 
    449                                 break; 
    450                 } 
    451  
    452         m_Config = new Config; 
    453                 logSpam("Trying to load Nepenthes Configuration from %s \n",confpath); 
    454                 try 
    455                 { 
    456                         m_Config->load(confpath); 
    457                         logInfo("Loaded Nepenthes Configuration from \"%s\".\n",confpath); 
    458                 } catch ( LoadError e ) 
    459                 { 
    460                         printf("Unable to load configuration file \"%s\": %s\n", confpath, e.getMessage()); 
    461                         run = false; 
    462                 } catch ( ParseError e ) 
    463                 { 
    464                         printf("Parse error in \"%s\" on line %d: %s\n", confpath, e.getLine(), e.getMessage()); 
    465                         run = false; 
    466                 } 
    467                  
    468         } 
    469  
    470     if ( run == true ) 
    471     { 
    472                 if ( m_Config != NULL ) 
    473                 { 
    474                          
    475  
    476  
    477                         if (ringlog == true) 
    478                         { 
    479  
    480                                 try 
    481                                 { 
    482                                         rlpath = m_Config->getValString("nepenthes.logmanager.ring_logging_file"); 
    483                                 } catch ( ... ) 
    484                                 { 
    485                                         logCrit("Could not find nepenthes.logmanager.ring_logging_file in Config\n"); 
    486                                         run = false; 
    487                                 } 
    488  
    489  
    490                                 RingFileLogger *fl = new RingFileLogger(m_LogManager); 
    491  
    492                                 fl->setLogFileFormat((char *)rlpath.c_str()); 
    493                                 fl->setMaxFiles(5); 
    494                                 fl->setMaxSize(1024 * 1024); 
    495  
    496                                 if ( diskTags ) 
    497                                         m_LogManager->addLogger(fl, m_LogManager->parseTagString(diskTags)); 
    498                                 else 
    499                                         m_LogManager->addLogger(fl, l_all); 
    500  
    501                         }else 
    502                         { 
    503                                 try 
    504                                 { 
    505                                         flpath = m_Config->getValString("nepenthes.logmanager.file_logging_file"); 
    506                                 } catch ( ... ) 
    507                                 { 
    508                                         logCrit("Could not find nepenthes.logmanager.file_logging_file in Config\n"); 
    509                                         run = false; 
    510                                 } 
    511  
    512                                 FileLogger *fl = new FileLogger(m_LogManager); 
    513                                 fl->setLogFile(flpath.c_str()); 
    514                                 if ( diskTags ) 
    515                                         m_LogManager->addLogger(fl, m_LogManager->parseTagString(diskTags)); 
    516                                 else 
    517                                         m_LogManager->addLogger(fl, l_all); 
    518  
    519                         } 
    520                 } 
    521         } 
    522  
    523         if (run == true && daemonize == true) 
     501                FileLogger *fl = new FileLogger(m_LogManager); 
     502                fl->setLogFile(flpath.c_str()); 
     503                if ( opt.m_diskTags ) 
     504                        m_LogManager->addLogger(fl, m_LogManager->parseTagString(opt.m_diskTags)); 
     505                else 
     506                        m_LogManager->addLogger(fl, l_all); 
     507 
     508        } 
     509 
     510        if (opt.m_daemonize == true) 
    524511        { 
    525512                logInfo("running as daemon\n"); 
     
    529516 
    530517 
    531         if (run == true || filecheck == true) 
    532         { 
    533  
    534                 if (filecheck == true) 
    535                 { 
    536                         run = true;  
    537                 } 
     518        if (opt.m_runMode == runFileCheck || opt.m_runMode == runNormal ) 
     519        { 
    538520 
    539521        // socketManager will call WASStartup() 
    540                 run = m_SocketManager->Init(); 
     522                if ( m_SocketManager->Init() == false) 
     523                        return -1; 
    541524 
    542525                 
    543526 
    544                 if (run == true ) 
    545                 { 
    546                         run = m_ModuleManager->Init(); 
    547                         m_ModuleManager->doList(); 
    548                 } 
    549  
    550                 if (run == true ) 
    551                 { 
    552                         run = m_DNSManager->Init(); 
    553                         m_DNSManager->doList(); 
    554                 } 
    555  
    556                 if (run == true ) 
    557                 { 
    558                         run = m_DownloadManager->Init(); 
    559                         m_DownloadManager->doList(); 
    560                 } 
    561  
    562                 if (run == true ) 
    563                 { 
    564                         m_EventManager->doList(); 
    565                 } 
    566  
    567                 if (run == true ) 
    568                 { 
    569                         m_ShellcodeManager->doList(); 
    570                 } 
    571  
    572                 if (run == true ) 
    573                 { 
    574             m_SocketManager->doList(); 
    575                 } 
    576  
    577                 if (run == true ) 
    578                 { 
    579                         run = m_SubmitManager->Init(); 
     527                if ( m_ModuleManager->Init() == false ) 
     528                        return -1; 
     529 
     530                m_ModuleManager->doList(); 
     531                 
     532 
     533                if (m_DNSManager->Init() == false ) 
     534                        return -1; 
     535 
     536                m_DNSManager->doList(); 
     537                 
     538 
     539