int plugin_load_all(char *path) { int fail = 0; DIR *dp = opendir(path); struct dirent *entry; if (!dp) { _e("Failed, cannot open plugin directory %s: %s", path, strerror(errno)); return 1; } plugpath = path; while ((entry = readdir(dp))) { if (entry->d_name[0] == '.') continue; /* Skip . and .. directories */ // print_desc(" Loading plugin ", basename(plugin)); if (load_one(path, entry->d_name)) fail++; // print_result(result); } closedir(dp); init_plugins(); return fail; }
int plugin_init(uev_ctx_t *ctx, char *path) { int fail = 1; if (!load_plugins(path)) fail = init_plugins(ctx); if (!silent) print_result(fail); return fail; }
static void initlibltdl(void) { char buffer[2000]; if (!plugins_are_initialized()) { init_plugins(); if (getPfaEditDir(buffer)!=NULL ) { strcpy(buffer,getPfaEditDir(buffer)); strcat(buffer,"/plugins"); lt_dladdsearchdir(strdup(buffer)); } } }
static void initlibltdl(void) { char buffer[2000]; char *userConfigDir; if (!plugins_are_initialized()) { init_plugins(); userConfigDir = getFontForgeUserDir(Config); if ( userConfigDir != NULL ) { strcpy(buffer,userConfigDir); strcat(buffer,"/plugins"); free(userConfigDir); lt_dladdsearchdir(buffer); } } }
/* allocate the song, get the plugins ready */ void bossao_new (PyObject *cfgparser, gchar *filename) { bossao_thread_init (); static_semaphore_new (&produce_eof_sem, 0, &produce_eof_sem_mutex); static_semaphore_new (&consume_eof_sem, 0, &consume_eof_sem_mutex); init_plugins (cfgparser); output_plugin_open_all (cfgparser); //pause_mutex = g_mutex_new (); //prod_pause_sem = semaphore_new (0); //cons_pause_sem = semaphore_new (0); static_semaphore_new (&prod_pause_sem, 0, &prod_pause_sem_mutex); static_semaphore_new (&cons_pause_sem, 0, &cons_pause_sem_mutex); //produce_mutex = g_mutex_new (); //thbuf = thbuf_new (THBUF_SIZE); thbuf_static_new (&thbuf, THBUF_SIZE, &thbuf_mutex, &thbuf_empty_sem, &thbuf_empty_sem_mutex, &thbuf_full_sem, &thbuf_full_sem_mutex); //thbuf_set_free_callback (thbuf, buffer_free_callback); thbuf_static_set_free_callback (&thbuf, buffer_free_callback); if (filename != NULL) bossao_play (filename); producer = g_thread_create (producer_thread, NULL, TRUE, NULL); if (producer_thread == NULL) { LOG ("Problem creating producer thread"); exit (-1); } consumer = g_thread_create (consumer_thread, NULL, TRUE, NULL); if (consumer_thread == NULL) { LOG ("Problem creating consumer thread"); exit (-1); } return; }
int init(int bpp) { char wm_caption[20]; fprintf(stdout, "Epiar %s\n", epiar_version); fprintf(stdout, "http://www.epiar.net/\n"); fprintf(stdout, "\nPlease report all bugs at http://bugs.epiar.net/\n\n"); setup_video(screen_width, screen_height, bpp, fullscreen); init_colors(); /* basically sets up common Uint32s to avoid calls to SDL_MapRGB() */ /* load the main archive file (used throughout epiar) */ if ((epiar_eaf = eaf_open_file(apply_game_path("epiar.eaf"))) == NULL) printf("Couldn't open epiar.eaf file.\n"); if ((main_eaf = eaf_open_file(apply_game_path("main.eaf"))) == NULL) printf("Couldn't open epiar.eaf file.\n"); init_audio(); init_music(); SDL_ShowCursor(0); sprintf(wm_caption, "Epiar [%s]", epiar_version); SDL_WM_SetCaption(wm_caption, wm_caption); load_input_cfg(); init_trig(); init_playlist(); gui_init(); init_plugins(); srand(time(NULL)); return (0); }
/** * \ingroup nuclientAPI * \brief global initialisation function * * This function inits all library needed to initiate a connection to a nuauth server * * \param err A pointer to a ::nuclient_error_t which contains at exit the error * * \warning To be called only once. */ int nu_client_global_init(nuclient_error_t * err) { int ret; prg_cache_init(); if (nussl_init() != NUSSL_OK) { SET_ERROR(err, INTERNAL_ERROR, NUSSL_INIT_ERR); /* TODO: patch nussl to handle errors correctly in nussl_sock_init */ return 0; } /* initialize the sasl library */ ret = sasl_client_init(NULL); if (ret != SASL_OK) { SET_ERROR(err, SASL_ERROR, ret); return 0; } /* get local charset */ nu_locale_charset = nl_langinfo(CODESET); if (nu_locale_charset == NULL) { fprintf(stderr, "Can't get locale charset!\n"); return 0; } /* init capabilities string */ ret = snprintf(nu_capabilities, NU_CAPABILITIES_MAXLENGTH, "%s", NU_CAPABILITIES); if (ret <= 0) { return 0; } INIT_LLIST_HEAD(&nu_postauth_extproto_l); INIT_LLIST_HEAD(&nu_cruise_extproto_l); init_plugins(); return 1; }
static int demux_xmms_open(demuxer_t* demuxer) { InputPlugin* ip = NULL; sh_audio_t* sh_audio; WAVEFORMATEX* w; xmms_priv_t *priv; int i; if (xmms_priv) return 0; // as I said, it's not reentrant :) init_plugins(); for(i=0;i<no_plugins;i++){ if (input_plugins[i]->is_our_file(demuxer->stream->url)){ ip=input_plugins[i]; break; } } if(!ip) return 0; // no plugin to handle this... pthread_mutex_init(&xmms_mutex,NULL); xmms_priv=priv=malloc(sizeof(xmms_priv_t)); memset(priv,0,sizeof(xmms_priv_t)); priv->ip=ip; memset(xmms_audiobuffer,0,XMMS_PACKETSIZE); xmms_channels=0; sh_audio = new_sh_audio(demuxer,0); sh_audio->wf = w = malloc(sizeof(WAVEFORMATEX)); w->wFormatTag = sh_audio->format = format; demuxer->movi_start = 0; demuxer->movi_end = 100; demuxer->audio->id = 0; demuxer->audio->sh = sh_audio; demuxer->priv=priv; sh_audio->ds = demuxer->audio; xmms_output_plugin.init(); ip->output = &xmms_output_plugin; xmms_playing=1; ip->play_file(demuxer->stream->url); if (ip->get_song_info) ip->get_song_info(demuxer->stream->url,&xmms_title,&xmms_length); if (xmms_length<=0) demuxer->seekable=0; mp_msg(MSGT_DEMUX,MSGL_INFO,MSGTR_MPDEMUX_XMMS_WaitForStart, demuxer->stream->url); while (xmms_channels==0) { usleep(10000); if(ip->get_time()<0) return 0; } sh_audio->sample_format= xmms_afmt; switch (xmms_afmt) { case AF_FORMAT_S16_LE: case AF_FORMAT_S16_BE: case AF_FORMAT_U16_LE: case AF_FORMAT_U16_BE: sh_audio->samplesize = 2; break; default: sh_audio->samplesize = 1; } w->wBitsPerSample = sh_audio->samplesize*8; w->nChannels = sh_audio->channels = xmms_channels; w->nSamplesPerSec = sh_audio->samplerate = xmms_samplerate; xmms_byterate = w->nAvgBytesPerSec = xmms_samplerate*sh_audio->channels*sh_audio->samplesize; w->nBlockAlign = sh_audio->samplesize*sh_audio->channels; w->cbSize = 0; return DEMUXER_TYPE_XMMS; }
/** * OpenVPN's main init-run-cleanup loop. * @ingroup eventloop * * This function contains the two outer OpenVPN loops. Its structure is * as follows: * - Once-per-process initialization. * - Outer loop, run at startup and then once per \c SIGHUP: * - Level 1 initialization * - Inner loop, run at startup and then once per \c SIGUSR1: * - Call event loop function depending on client or server mode: * - \c tunnel_point_to_point() * - \c tunnel_server() * - Level 1 cleanup * - Once-per-process cleanup. * * @param argc - Commandline argument count. * @param argv - Commandline argument values. */ int main (int argc, char *argv[]) { struct context c; #if PEDANTIC fprintf (stderr, "Sorry, I was built with --enable-pedantic and I am incapable of doing any real work!\n"); return 1; #endif CLEAR (c); /* signify first time for components which can only be initialized once per program instantiation. */ c.first_time = true; /* initialize program-wide statics */ if (init_static ()) { /* * This loop is initially executed on startup and then * once per SIGHUP. */ do { /* enter pre-initialization mode with regard to signal handling */ pre_init_signal_catch (); /* zero context struct but leave first_time member alone */ context_clear_all_except_first_time (&c); /* static signal info object */ CLEAR (siginfo_static); c.sig = &siginfo_static; /* initialize garbage collector scoped to context object */ gc_init (&c.gc); /* initialize environmental variable store */ c.es = env_set_create (NULL); #ifdef WIN32 env_set_add_win32 (c.es); #endif #ifdef ENABLE_MANAGEMENT /* initialize management subsystem */ init_management (&c); #endif /* initialize options to default state */ init_options (&c.options, true); /* parse command line options, and read configuration file */ parse_argv (&c.options, argc, argv, M_USAGE, OPT_P_DEFAULT, NULL, c.es); #ifdef ENABLE_PLUGIN /* plugins may contribute options configuration */ init_verb_mute (&c, IVM_LEVEL_1); init_plugins (&c); open_plugins (&c, true, OPENVPN_PLUGIN_INIT_PRE_CONFIG_PARSE); #endif /* init verbosity and mute levels */ init_verb_mute (&c, IVM_LEVEL_1); /* set dev options */ init_options_dev (&c.options); /* openssl print info? */ if (print_openssl_info (&c.options)) break; /* --genkey mode? */ if (do_genkey (&c.options)) break; /* tun/tap persist command? */ if (do_persist_tuntap (&c.options)) break; /* sanity check on options */ options_postprocess (&c.options); /* show all option settings */ show_settings (&c.options); /* print version number */ msg (M_INFO, "%s", title_string); /* misc stuff */ pre_setup (&c.options); /* test crypto? */ if (do_test_crypto (&c.options)) break; #ifdef ENABLE_MANAGEMENT /* open management subsystem */ if (!open_management (&c)) break; #endif /* set certain options as environmental variables */ setenv_settings (c.es, &c.options); /* finish context init */ context_init_1 (&c); do { /* run tunnel depending on mode */ switch (c.options.mode) { case MODE_POINT_TO_POINT: tunnel_point_to_point (&c); break; #if P2MP_SERVER case MODE_SERVER: tunnel_server (&c); break; #endif default: ASSERT (0); } /* indicates first iteration -- has program-wide scope */ c.first_time = false; /* any signals received? */ if (IS_SIG (&c)) print_signal (c.sig, NULL, M_INFO); /* pass restart status to management subsystem */ signal_restart_status (c.sig); } while (c.sig->signal_received == SIGUSR1); uninit_options (&c.options); gc_reset (&c.gc); } while (c.sig->signal_received == SIGHUP); } context_gc_free (&c); env_set_destroy (c.es); #ifdef ENABLE_MANAGEMENT /* close management interface */ close_management (); #endif /* uninitialize program-wide statics */ uninit_static (); openvpn_exit (OPENVPN_EXIT_STATUS_GOOD); /* exit point */ return 0; /* NOTREACHED */ }
int main(int argc, char *argv[]) { if(getuid() != 0 || geteuid() != 0) { fprintf(stderr, "\n[!] You need root to run this tool\n"); /*return ERR; */ } #ifdef __linux__ /* QueMod is Linux only anyway */ setup_signal_handlers(); #endif int opt; int ret = 0; FILE *configuration_fd; char *conf_fd = "/opt/quemod/quemod.conf"; fprintf(stdout,"\n[ QueMod Framework ]\n"); if((configuration_fd = fopen(conf_fd, "r")) == NULL) { error("[!] Could not open the configuration file"); return ERR; } if((parse_configuration_file(configuration_fd)) == 0) { #ifdef DEBUG fprintf(stdout, "Parsed 0 lines in configuration file\n"); #endif } if(configuration_fd) { fclose(configuration_fd); } while((opt = getopt(argc, argv,"u:p:v:wd")) != ERR) { switch(opt) { case 'u': options.load_plugins = optarg; break; case 'p': options.plugin_dir = optarg; break; case 'v': options.ip_version = atol(optarg); break; case 'w': options.write_packets = YES; break; case 'd': options.write_packet_hdrs = YES; break; case '?': help(); break; } } ret = init_plugins(); if(ret == ERR) return ERR; memset(&stats, 0x0, sizeof(struct _stats)); ret = setup_nfq(); cleanup(); printf("\n"); return ret; }
/* Do all the work to set up the api finder and such */ void setup_apis(cionize_api* molfiles) { init_plugins(); molfiles->filetype[0]='\0'; molfiles->optflags = 0; }
void qt_init(QApplicationPrivate *priv, int type) { Q_UNUSED(type); qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); char *p; char **argv = priv->argv; int argc = priv->argc; if (argv && *argv) { //apparently, we allow people to pass 0 on the other platforms p = strrchr(argv[0], '/'); appName = QString::fromLocal8Bit(p ? p + 1 : argv[0]); } QList<QByteArray> pluginList; QString platformPluginPath = QLatin1String(qgetenv("QT_QPA_PLATFORM_PLUGIN_PATH")); QByteArray platformName; #ifdef QT_QPA_DEFAULT_PLATFORM_NAME platformName = QT_QPA_DEFAULT_PLATFORM_NAME; #endif QByteArray platformNameEnv = qgetenv("QT_QPA_PLATFORM"); if (!platformNameEnv.isEmpty()) { platformName = platformNameEnv; } // Get command line params int j = argc ? 1 : 0; for (int i=1; i<argc; i++) { if (argv[i] && *argv[i] != '-') { argv[j++] = argv[i]; continue; } QByteArray arg = argv[i]; if (arg == "-fn" || arg == "-font") { if (++i < argc) appFont = QString::fromLocal8Bit(argv[i]); } else if (arg == "-platformpluginpath") { if (++i < argc) platformPluginPath = QLatin1String(argv[i]); } else if (arg == "-platform") { if (++i < argc) platformName = argv[i]; } else if (arg == "-plugin") { if (++i < argc) pluginList << argv[i]; } else { argv[j++] = argv[i]; } } if (j < priv->argc) { priv->argv[j] = 0; priv->argc = j; } #if 0 QByteArray pluginEnv = qgetenv("QT_QPA_PLUGINS"); if (!pluginEnv.isEmpty()) { pluginList.append(pluginEnv.split(';')); } #endif init_platform(QLatin1String(platformName), platformPluginPath); init_plugins(pluginList); QColormap::initialize(); QFont::initialize(); #ifndef QT_NO_CURSOR // QCursorData::initialize(); #endif qApp->setObjectName(appName); #ifndef QT_NO_QWS_INPUTMETHODS qApp->setInputContext(new QDummyInputContext(qApp)); #endif }
int main(int argc, char **argv) { /* initial configuration, will be overridden by config file and command line options */ first_init = 1; running = 0; // will be set to != 0 once honeytrap set up itself /* save command line arguments */ arg_c = argc; arg_v = argv; /* the following are default values - change them in your configuration file */ daemonize = 1; // default is to daemonize #ifdef USE_PCAP_MON promisc_mode = 0; // no promisc mode pcap_offset = 0; // will be set after link type is determined #endif log_level = LOG_NOTICE; // default log level logfile_fd = STDOUT_FILENO;// default logfile, stdout will be replaced by logfile_fd u_id = 0; // root privileges per default g_id = 0; conn_timeout = 120; // 2 minutes connect timeout read_timeout = 1; // 1 second read timeout m_read_timeout = 60; // 1 minute read timeout for mirror connections read_limit = 0; // 0 means no read limit conffile_name = strdup("/etc/honeytrap/honeytrap.conf"); pidfile_name = strdup("/var/run/honeytrap.pid"); logfile_name = strdup("/var/log/honeytrap.log"); response_dir = strdup("/etc/honeytrap/responses"); plugin_dir = strdup("/etc/honeytrap/plugins"); #ifdef USE_PCAP_MON dev = NULL; // network device pointer packet_sniffer = NULL; // pcap device pointer #endif portconf_default = PORTCONF_NONE; eventlist = NULL; // list of timer-based events /* configure honeytrap */ configure(arg_c, arg_v); /* daemonize (detach from console) */ if (daemonize) do_daemonize(); /* now initialize plugins */ init_plugins(); /* create pid file */ create_pid_file(); /* create IPC pipe and queue for port infos */ if (pipe(portinfopipe) == -1) { logmsg(LOG_ERR, 0, " Error - Unable to create port info IPC pipe: %m.\n"); exit(EXIT_FAILURE); } if ((portinfoq = queue_new()) == NULL) { logmsg(LOG_ERR, 0, " Error - Unable to create port info IPC pipe: %m.\n"); exit(EXIT_FAILURE); } /* watch out for incoming connection requests */ if (start_connection_monitor() < 0) clean_exit(EXIT_SUCCESS); return(0); }
void TeXmacs_main (int argc, char** argv) { int i; bool flag= true; string the_default_font; for (i=1; i<argc; i++) if (argv[i][0] == '\0') argc= i; else if (((argv[i][0] == '-') || (argv[i][0] == '+')) && (argv[i][1] != '\0')) { string s= argv[i]; if ((N(s)>=2) && (s(0,2)=="--")) s= s (1, N(s)); if ((s == "-s") || (s == "-silent")) flag= false; else if ((s == "-V") || (s == "-verbose")) debug (DEBUG_FLAG_VERBOSE, true); else if ((s == "-d") || (s == "-debug")) debug (DEBUG_FLAG_STD, true); else if (s == "-debug-events") debug (DEBUG_FLAG_EVENTS, true); else if (s == "-debug-io") debug (DEBUG_FLAG_IO, true); else if (s == "-debug-bench") debug (DEBUG_FLAG_BENCH, true); else if (s == "-debug-history") debug (DEBUG_FLAG_HISTORY, true); else if (s == "-debug-qt") debug (DEBUG_FLAG_QT, true); else if (s == "-debug-qt-widgets") debug (DEBUG_FLAG_QT_WIDGETS, true); else if (s == "-debug-keyboard") debug (DEBUG_FLAG_KEYBOARD, true); else if (s == "-debug-packrat") debug (DEBUG_FLAG_PACKRAT, true); else if (s == "-debug-flatten") debug (DEBUG_FLAG_FLATTEN, true); else if (s == "-debug-correct") debug (DEBUG_FLAG_CORRECT, true); else if (s == "-debug-convert") debug (DEBUG_FLAG_CONVERT, true); else if (s == "-debug-all") { debug (DEBUG_FLAG_EVENTS, true); debug (DEBUG_FLAG_STD, true); debug (DEBUG_FLAG_IO, true); debug (DEBUG_FLAG_HISTORY, true); debug (DEBUG_FLAG_BENCH, true); debug (DEBUG_FLAG_QT, true); debug (DEBUG_FLAG_QT_WIDGETS, true); } else if (s == "-disable-error-recovery") disable_error_recovery= true; else if ((s == "-fn") || (s == "-font")) { i++; if (i<argc) the_default_font= argv[i]; } else if ((s == "-g") || (s == "-geometry")) { i++; if (i<argc) { string g= argv[i]; int j=0, j1, j2, j3; for (j=0; j<N(g); j++) if (g[j] == 'x') break; j1=j; if (j<N(g)) j++; for (; j<N(g); j++) if ((g[j] == '+') || (g[j] == '-')) break; j2=j; if (j<N(g)) j++; for (; j<N(g); j++) if ((g[j] == '+') || (g[j] == '-')) break; j3=j; if (j1<N(g)) { geometry_w= max (as_int (g (0, j1)), 320); geometry_h= max (as_int (g (j1+1, j2)), 200); } if (j3<N(g)) { if (g[j2] == '-') geometry_x= as_int (g (j2, j3)) - 1; else geometry_x= as_int (g (j2+1, j3)); if (g[j3] == '-') geometry_y= as_int (g (j3, N(g))) - 1; else geometry_y= as_int (g (j3+1, N(g))); } } } else if ((s == "-b") || (s == "-initialize-buffer")) { i++; if (i<argc) tm_init_buffer_file= url_system (argv[i]); } else if ((s == "-i") || (s == "-initialize")) { i++; if (i<argc) tm_init_file= url_system (argv[i]); } else if ((s == "-v") || (s == "-version")) { cout << "\n"; cout << "TeXmacs version " << TEXMACS_VERSION << "\n"; cout << TEXMACS_COPYRIGHT << "\n"; cout << "\n"; exit (0); } else if ((s == "-p") || (s == "-path")) { cout << get_env ("TEXMACS_PATH") << "\n"; exit (0); } else if ((s == "-bp") || (s == "-binpath")) { cout << get_env ("TEXMACS_BIN_PATH") << "\n"; exit (0); } else if ((s == "-q") || (s == "-quit")) my_init_cmds= my_init_cmds * " (quit-TeXmacs)"; else if ((s == "-r") || (s == "-reverse")) set_reverse_colors (true); else if (s == "-no-retina") { retina_manual= true; retina_factor= 1; retina_icons = 1; retina_scale = 1.0; } else if ((s == "-R") || (s == "-retina")) { retina_manual= true; retina_factor= 2; retina_icons = 2; retina_scale = 1.4; } else if (s == "-no-retina-icons") { retina_iman = true; retina_icons = 1; } else if (s == "-retina-icons") { retina_iman = true; retina_icons = 2; } else if ((s == "-c") || (s == "-convert")) { i+=2; if (i<argc) { url in ("$PWD", argv[i-1]); url out ("$PWD", argv[ i ]); my_init_cmds= my_init_cmds * " " * "(load-buffer " * scm_quote (as_string (in)) * " :strict) " * "(export-buffer " * scm_quote (as_string (out)) * ")"; } } else if ((s == "-x") || (s == "-execute")) { i++; if (i<argc) my_init_cmds= (my_init_cmds * " ") * argv[i]; } else if (s == "-server") start_server_flag= true; else if (s == "-log-file") i++; else if ((s == "-Oc") || (s == "-no-char-clipping")) char_clip= false; else if ((s == "+Oc") || (s == "-char-clipping")) char_clip= true; else if ((s == "-S") || (s == "-setup") || (s == "-delete-cache") || (s == "-delete-font-cache") || (s == "-delete-style-cache") || (s == "-delete-file-cache") || (s == "-delete-doc-cache") || (s == "-delete-plugin-cache") || (s == "-delete-server-data") || (s == "-delete-databases")); else if (starts (s, "-psn")); else { cout << "\n"; cout << "Options for TeXmacs:\n\n"; cout << " -b [file] Specify scheme buffers initialization file\n"; cout << " -c [i] [o] Convert file 'i' into file 'o'\n"; cout << " -d For debugging purposes\n"; cout << " -fn [font] Set the default TeX font\n"; cout << " -g [geom] Set geometry of window in pixels\n"; cout << " -h Display this help message\n"; cout << " -i [file] Specify scheme initialization file\n"; cout << " -p Get the TeXmacs path\n"; cout << " -q Shortcut for -x \"(quit-TeXmacs)\"\n"; cout << " -r Reverse video mode\n"; cout << " -s Suppress information messages\n"; cout << " -S Rerun TeXmacs setup program before starting\n"; cout << " -v Display current TeXmacs version\n"; cout << " -V Show some informative messages\n"; cout << " -x [cmd] Execute scheme command\n"; cout << " -Oc TeX characters bitmap clipping off\n"; cout << " +Oc TeX characters bitmap clipping on (default)\n"; cout << "\nPlease report bugs to <*****@*****.**>\n"; cout << "\n"; exit (0); } } if (flag) debug (DEBUG_FLAG_AUTO, true); // Further options via environment variables if (get_env ("TEXMACS_RETINA") == "off") { retina_manual= true; retina_factor= 1; retina_icons = 1; retina_scale = 1.0; } if (get_env ("TEXMACS_RETINA") == "on") { retina_manual= true; retina_factor= 2; retina_icons = 2; retina_scale = 1.4; } if (get_env ("TEXMACS_RETINA_ICONS") == "off") { retina_iman = true; retina_icons = 1; } if (get_env ("TEXMACS_RETINA_ICONS") == "on") { retina_iman = true; retina_icons = 2; } // End options via environment variables if (DEBUG_STD) debug_boot << "Installing internal plug-ins...\n"; bench_start ("initialize plugins"); init_plugins (); bench_cumul ("initialize plugins"); if (DEBUG_STD) debug_boot << "Opening display...\n"; #if defined(X11TEXMACS) && defined(MACOSX_EXTENSIONS) init_mac_application (); #endif gui_open (argc, argv); set_default_font (the_default_font); if (DEBUG_STD) debug_boot << "Starting server...\n"; { // opening scope for server sv server sv; // HACK: // Qt and Guile want to change the locale. // We need to force it to C to parse correctly the configuration files // (see as_double() in string.cpp) setlocale(LC_NUMERIC, "C"); string where= ""; for (i=1; i<argc; i++) { if (argv[i] == NULL) break; string s= argv[i]; if ((N(s)>=2) && (s(0,2)=="--")) s= s (1, N(s)); if ((s[0] != '-') && (s[0] != '+')) { if (DEBUG_STD) debug_boot << "Loading " << s << "...\n"; url u= url_system (s); if (!is_rooted (u)) u= resolve (url_pwd (), "") * u; string b= scm_quote (as_string (u)); string cmd= "(load-buffer " * b * " " * where * ")"; where= " :new-window"; exec_delayed (scheme_cmd (cmd)); } if ((s == "-c") || (s == "-convert")) i+=2; else if ((s == "-b") || (s == "-initialize-buffer") || (s == "-fn") || (s == "-font") || (s == "-i") || (s == "-initialize") || (s == "-g") || (s == "-geometry") || (s == "-x") || (s == "-execute") || (s == "-log-file")) i++; } if (install_status == 1) { if (DEBUG_STD) debug_boot << "Loading welcome message...\n"; url u= "tmfs://help/plain/tm/doc/about/welcome/first.en.tm"; string b= scm_quote (as_string (u)); string cmd= "(load-buffer " * b * " " * where * ")"; where= " :new-window"; exec_delayed (scheme_cmd (cmd)); } else if (install_status == 2) { if (DEBUG_STD) debug_boot << "Loading upgrade message...\n"; url u= "tmfs://help/plain/tm/doc/about/changes/changes-recent.en.tm"; string b= scm_quote (as_string (u)); string cmd= "(load-buffer " * b * " " * where * ")"; where= " :new-window"; exec_delayed (scheme_cmd (cmd)); } if (number_buffers () == 0) { if (DEBUG_STD) debug_boot << "Creating 'no name' buffer...\n"; open_window (); } bench_print (); bench_reset ("initialize texmacs"); bench_reset ("initialize plugins"); bench_reset ("initialize scheme"); if (DEBUG_STD) debug_boot << "Starting event loop...\n"; texmacs_started= true; if (!disable_error_recovery) signal (SIGSEGV, clean_exit_on_segfault); if (start_server_flag) server_start (); gui_start_loop (); if (DEBUG_STD) debug_boot << "Stopping server...\n"; } // ending scope for server sv if (DEBUG_STD) debug_boot << "Closing display...\n"; gui_close (); #if defined(X11TEXMACS) && defined(MACOSX_EXTENSIONS) finalize_mac_application (); #endif if (DEBUG_STD) debug_boot << "Good bye...\n"; }
/** * @brief openvassd. * @param argc Argument count. * @param argv Argument vector. */ int main (int argc, char *argv[]) { int exit_early = 0, scanner_port = 9391; pid_t handler_pid; char *myself; struct arglist *options = emalloc (sizeof (struct arglist)); struct addrinfo *mysaddr; struct addrinfo hints; struct addrinfo ai; struct sockaddr_in saddr; struct sockaddr_in6 s6addr; proctitle_init (argc, argv); gcrypt_init (); if ((myself = strrchr (*argv, '/')) == 0) myself = *argv; else myself++; static gboolean display_version = FALSE; static gboolean dont_fork = FALSE; static gchar *address = NULL; static gchar *port = NULL; static gchar *config_file = NULL; static gchar *gnutls_priorities = "NORMAL"; static gchar *dh_params = NULL; static gboolean print_specs = FALSE; static gboolean print_sysconfdir = FALSE; static gboolean only_cache = FALSE; GError *error = NULL; GOptionContext *option_context; static GOptionEntry entries[] = { {"version", 'V', 0, G_OPTION_ARG_NONE, &display_version, "Display version information", NULL}, {"foreground", 'f', 0, G_OPTION_ARG_NONE, &dont_fork, "Do not run in daemon mode but stay in foreground", NULL}, {"listen", 'a', 0, G_OPTION_ARG_STRING, &address, "Listen on <address>", "<address>"}, {"port", 'p', 0, G_OPTION_ARG_STRING, &port, "Use port number <number>", "<number>"}, {"config-file", 'c', 0, G_OPTION_ARG_FILENAME, &config_file, "Configuration file", "<.rcfile>"}, {"cfg-specs", 's', 0, G_OPTION_ARG_NONE, &print_specs, "Print configuration settings", NULL}, {"sysconfdir", 'y', 0, G_OPTION_ARG_NONE, &print_sysconfdir, "Print system configuration directory (set at compile time)", NULL}, {"only-cache", 'C', 0, G_OPTION_ARG_NONE, &only_cache, "Exit once the NVT cache has been initialized or updated", NULL}, {"gnutls-priorities", '\0', 0, G_OPTION_ARG_STRING, &gnutls_priorities, "GnuTLS priorities string", "<string>"}, {"dh-params", '\0', 0, G_OPTION_ARG_STRING, &dh_params, "Diffie-Hellman parameters file", "<string>"}, {NULL} }; option_context = g_option_context_new ("- Scanner of the Open Vulnerability Assessment System"); g_option_context_add_main_entries (option_context, entries, NULL); if (!g_option_context_parse (option_context, &argc, &argv, &error)) { g_print ("%s\n\n", error->message); exit (0); } g_option_context_free (option_context); if (print_sysconfdir) { g_print ("%s\n", SYSCONFDIR); exit (0); } /* Switch to UTC so that OTP times are always in UTC. */ if (setenv ("TZ", "utc 0", 1) == -1) { g_print ("%s\n\n", strerror (errno)); exit (0); } tzset (); if (print_specs) exit_early = 2; /* no cipher initialization */ if (address != NULL) { memset (&hints, 0, sizeof (hints)); hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; hints.ai_flags = AI_NUMERICHOST; if (getaddrinfo (address, NULL, &hints, &mysaddr)) { printf ("Invalid IP address.\n"); printf ("Please use %s --help for more information.\n", myself); exit (0); } /* deep copy */ ai.ai_family = mysaddr->ai_family; if (ai.ai_family == AF_INET) { memcpy (&saddr, mysaddr->ai_addr, mysaddr->ai_addrlen); ai.ai_addr = (struct sockaddr *) &saddr; } else { memcpy (&s6addr, mysaddr->ai_addr, mysaddr->ai_addrlen); ai.ai_addr = (struct sockaddr *) &s6addr; } ai.ai_family = mysaddr->ai_family; ai.ai_protocol = mysaddr->ai_protocol; ai.ai_socktype = mysaddr->ai_socktype; ai.ai_addrlen = mysaddr->ai_addrlen; freeaddrinfo (mysaddr); } else { /* Default to IPv4 */ /*Warning: Not filling all the fields */ saddr.sin_addr.s_addr = INADDR_ANY; saddr.sin_family = ai.ai_family = AF_INET; ai.ai_addrlen = sizeof (saddr); ai.ai_addr = (struct sockaddr *) &saddr; } if (port != NULL) { scanner_port = atoi (port); if ((scanner_port <= 0) || (scanner_port >= 65536)) { printf ("Invalid port specification.\n"); printf ("Please use %s --help for more information.\n", myself); exit (1); } } if (display_version) { printf ("OpenVAS Scanner %s\n", OPENVASSD_VERSION); printf ("Nessus origin: (C) 2004 Renaud Deraison <*****@*****.**>\n"); printf ("Most new code since OpenVAS: (C) 2013 Greenbone Networks GmbH\n"); printf ("License GPLv2: GNU GPL version 2\n"); printf ("This is free software: you are free to change and redistribute it.\n" "There is NO WARRANTY, to the extent permitted by law.\n\n"); exit (0); } if (config_file != NULL) arg_add_value (options, "acc_hint", ARG_INT, sizeof (int), (void *) 1); if (!config_file) { config_file = emalloc (strlen (OPENVASSD_CONF) + 1); strncpy (config_file, OPENVASSD_CONF, strlen (OPENVASSD_CONF)); } arg_add_value (options, "scanner_port", ARG_INT, sizeof (gpointer), GSIZE_TO_POINTER (scanner_port)); arg_add_value (options, "config_file", ARG_STRING, strlen (config_file), config_file); arg_add_value (options, "addr", ARG_PTR, -1, &ai); if (only_cache) { init_openvassd (options, 0, 1, dont_fork); init_plugins (options); exit (0); } init_openvassd (options, 1, exit_early, dont_fork); g_options = options; global_iana_socket = GPOINTER_TO_SIZE (arg_get_value (options, "isck")); global_plugins = arg_get_value (options, "plugins"); /* special treatment */ if (print_specs) dump_cfg_specs (global_preferences); if (exit_early) exit (0); init_ssl_ctx (gnutls_priorities, dh_params); // Daemon mode: if (dont_fork == FALSE) set_daemon_mode (); pidfile_create ("openvassd"); handler_pid = loading_handler_start (); init_plugins (options); loading_handler_stop (handler_pid); main_loop (); exit (0); }
int main(int argc, char **argv) { struct option long_options[] = { {"wordy", no_argument, NULL, 'w'}, {"help", no_argument, NULL, 'h'}, }; struct epoll_event events[10]; int epoll_fd = -1; struct itimerspec it; int ret; int status = EXIT_SUCCESS; if (argc > 0) progname = argv[0]; for (;;) { int c; c = getopt_long(argc, argv, "wh", long_options, NULL); if (c == -1) break; switch (c) { case 'w': wordy = true; break; case 'h': usage(false); default: usage(true); } } if (optind != argc) usage(true); dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr, "unable to open display '%s'\n", XDisplayName(NULL)); status = EXIT_FAILURE; goto out; } root = DefaultRootWindow(dpy); epoll_fd = epoll_create1(EPOLL_CLOEXEC); if (epoll_fd == -1) { perror("epoll_create1"); status = EXIT_FAILURE; goto out; } ret = signal_fd_init(epoll_fd); if (ret == -1) { status = EXIT_FAILURE; goto out; } ret = timer_fd_init(epoll_fd); if (ret == -1) { status = EXIT_FAILURE; goto out; } ret = ctl_fd_init(epoll_fd); if (ret == -1) { status = EXIT_FAILURE; goto out; } if (init_plugins()) { status = EXIT_FAILURE; goto out; } if (init_sections(epoll_fd, config, sizeof(config) / sizeof(*config))) { status = EXIT_FAILURE; goto out; } if (update_timer_sections()) { status = EXIT_FAILURE; goto out; } it.it_interval.tv_sec = 1; it.it_interval.tv_nsec = 0; it.it_value.tv_sec = 1; it.it_value.tv_nsec = 0; ret = timerfd_settime(timer_cb.fd, 0, &it, NULL); if (ret == -1) { perror("timerfd_settime"); status = EXIT_FAILURE; goto out; } while (!quit) { int i; update = false; ret = epoll_wait(epoll_fd, events, sizeof(events) / sizeof(events[0]), -1); if (ret == -1) { if (errno == EINTR) continue; perror("epoll_wait"); status = EXIT_FAILURE; goto out; } for (i = 0; i < ret; i++) { struct epoll_callback *cb = events[i].data.ptr; ret = cb->callback(cb->fd, cb->data, events[i].events); if (ret) { status = EXIT_FAILURE; goto out; } } if (update) { ret = update_statusbar(); if (ret) { status = EXIT_FAILURE; goto out; } } } status = EXIT_SUCCESS; out: if (epoll_fd != -1) close(epoll_fd); free_sections(); if (ctl_cb.fd != -1) { close(ctl_cb.fd); unlink(ctl_addr.sun_path); } if (timer_cb.fd != -1) close(timer_cb.fd); if (signal_cb.fd != -1) close(signal_cb.fd); str_free(&status_str); if (dpy) { XStoreName(dpy, root, ""); XFlush(dpy); XCloseDisplay(dpy); } return status; }