本文整理汇总了C++中read_config_file函数的典型用法代码示例。如果您正苦于以下问题:C++ read_config_file函数的具体用法?C++ read_config_file怎么用?C++ read_config_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_config_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vmi_init_private
static status_t
vmi_init_private(
vmi_instance_t *vmi,
uint32_t flags,
unsigned long id,
char *name,
vmi_config_t *config)
{
uint32_t access_mode = flags & 0x0000FFFF;
uint32_t init_mode = flags & 0x00FF0000;
uint32_t config_mode = flags & 0xFF000000;
status_t status = VMI_FAILURE;
/* allocate memory for instance structure */
*vmi = (vmi_instance_t) safe_malloc(sizeof(struct vmi_instance));
memset(*vmi, 0, sizeof(struct vmi_instance));
/* initialize instance struct to default values */
dbprint("LibVMI Version 0.9_alpha\n"); //TODO change this with each release
/* save the flags and init mode */
(*vmi)->flags = flags;
(*vmi)->init_mode = init_mode;
(*vmi)->config = config;
(*vmi)->config_mode = config_mode;
/* setup the caches */
pid_cache_init(*vmi);
sym_cache_init(*vmi);
rva_cache_init(*vmi);
v2p_cache_init(*vmi);
/* connecting to xen, kvm, file, etc */
if (VMI_FAILURE == set_driver_type(*vmi, access_mode, id, name)) {
goto error_exit;
}
/* resolve the id and name */
if (VMI_FAILURE == set_id_and_name(*vmi, access_mode, id, name)) {
goto error_exit;
}
/* driver-specific initilization */
if (VMI_FAILURE == driver_init(*vmi)) {
goto error_exit;
}
dbprint("--completed driver init.\n");
/* we check VMI_INIT_COMPLETE first as
VMI_INIT_PARTIAL is not exclusive */
if (init_mode & VMI_INIT_COMPLETE) {
/* init_complete requires configuration */
if(VMI_CONFIG_NONE & (*vmi)->config_mode) {
/* falling back to VMI_CONFIG_GLOBAL_FILE_ENTRY is unsafe here
as the config pointer is probably NULL */
goto error_exit;
}
/* read and parse the config file */
else if ( (VMI_CONFIG_STRING & (*vmi)->config_mode || VMI_CONFIG_GLOBAL_FILE_ENTRY & (*vmi)->config_mode)
&& VMI_FAILURE == read_config_file(*vmi)) {
goto error_exit;
}
/* read and parse the ghashtable */
else if (VMI_CONFIG_GHASHTABLE & (*vmi)->config_mode
&& VMI_FAILURE == read_config_ghashtable(*vmi)) {
dbprint("--failed to parse ghashtable\n");
goto error_exit;
}
/* setup the correct page offset size for the target OS */
if (VMI_FAILURE == init_page_offset(*vmi)) {
goto error_exit;
}
/* get the memory size */
if (driver_get_memsize(*vmi, &(*vmi)->size) == VMI_FAILURE) {
errprint("Failed to get memory size.\n");
goto error_exit;
}
dbprint("**set size = %"PRIu64" [0x%"PRIx64"]\n", (*vmi)->size,
(*vmi)->size);
/* determine the page sizes and layout for target OS */
// Find the memory layout. If this fails, then proceed with the
// OS-specific heuristic techniques.
(*vmi)->pae = (*vmi)->pse = (*vmi)->lme = (*vmi)->cr3 = 0;
(*vmi)->page_mode = VMI_PM_UNKNOWN;
status = get_memory_layout(*vmi,
&((*vmi)->page_mode),
&((*vmi)->cr3),
&((*vmi)->pae),
&((*vmi)->pse),
&((*vmi)->lme));
if (VMI_FAILURE == status) {
dbprint
("**Failed to get memory layout for VM. Trying heuristic method.\n");
//.........这里部分代码省略.........
示例2: main
int main( int argc, char **argv )
{
/* Print copyright notice */
fprintf( stderr,
"Tux Rider World Challenge -- http://www.barlow-server.com\n"
"a fork from:\n"
"Tux Racer " VERSION " -- a Sunspire Studios Production "
"(http://www.sunspirestudios.com)\n"
"(c) 1999-2000 Jasmin F. Patry "
"<[email protected]>\n"
"\"Tux Racer\" is a trademark of Jasmin F. Patry\n"
"Tux Rider World Challenge comes with ABSOLUTELY NO WARRANTY. "
"This is free software,\nand you are welcome to redistribute "
"it under certain conditions.\n"
"See http://www.gnu.org/copyleft/gpl.html for details.\n\n" );
/* Init the game clock */
g_game.secs_since_start = 0;
/* Seed the random number generator */
srand( time(NULL) );
/*
* Set up the game configuration
*/
/* Don't support multiplayer, yet... */
g_game.num_players = 2;
/* Create a Tcl interpreter */
g_game.tcl_interp = Tcl_CreateInterp();
if ( g_game.tcl_interp == NULL ) {
handle_error( 1, "cannot create Tcl interpreter" );
}
/* Setup the configuration variables and read the ~/.tuxracer/options file */
init_game_configuration();
read_config_file();
/* Set up the debugging modes */
init_debug();
/* Setup diagnostic log if requested */
if ( getparam_write_diagnostic_log() ) {
setup_diagnostic_log();
}
/*
* Setup Tcl stdout and stderr channels to point to C stdout and stderr
* streams
*/
setup_tcl_std_channels();
/*
* Initialize rendering context, create window
*/
winsys_init( &argc, argv, WINDOW_TITLE, WINDOW_TITLE );
/* Ingore key-repeat messages */
winsys_enable_key_repeat(0);
/* Set up a function to clean up when program exits */
winsys_atexit( cleanup );
/*
* Initial OpenGL settings
*/
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
init_opengl_extensions();
/* Print OpenGL debugging information if requested */
if ( debug_mode_is_active( DEBUG_GL_INFO ) ) {
print_debug( DEBUG_GL_INFO,
"OpenGL information:" );
print_gl_info();
}
/*
* Load the game data and initialize game state
*/
register_game_config_callbacks( g_game.tcl_interp );
register_course_load_tcl_callbacks( g_game.tcl_interp );
register_key_frame_callbacks( g_game.tcl_interp );
register_fog_callbacks( g_game.tcl_interp );
register_course_light_callbacks( g_game.tcl_interp );
register_particle_callbacks( g_game.tcl_interp );
register_texture_callbacks( g_game.tcl_interp );
register_font_callbacks( g_game.tcl_interp );
register_sound_tcl_callbacks( g_game.tcl_interp );
register_sound_data_tcl_callbacks( g_game.tcl_interp );
register_course_manager_callbacks( g_game.tcl_interp );
//.........这里部分代码省略.........
示例3: check_password
int
check_password (char *pPasswd, char **ppErrStr, Entry *pEntry)
{
char *szErrStr = (char *) ber_memalloc(MEM_INIT_SZ);
int mem_len = MEM_INIT_SZ;
int nLen;
int nLower = 0;
int nUpper = 0;
int nDigit = 0;
int nPunct = 0;
int min_lower = 0;
int min_upper = 0;
int min_digit = 0;
int min_punct = 0;
int max_consecutive_per_class = 0;
int nQuality = 0;
int i;
/* Set a sensible default to keep original behaviour. */
int min_quality = DEFAULT_QUALITY;
int use_cracklib = DEFAULT_CRACKLIB;
nLen = strlen (pPasswd);
if (read_config_file() == -1) {
syslog(LOG_ERR, "Warning: Could not read values from config file %s. Using defaults.", CONFIG_FILE);
#if defined(LDEBUG)
printf("Error: Could not read values from config file %s\n", CONFIG_FILE);
#endif
}
#if defined(LDEBUG) || defined(DEBUG)
print_config_entries();
#endif
min_quality = get_config_entry_int("min_points");
use_cracklib = get_config_entry_int("use_cracklib");
min_upper = get_config_entry_int("min_upper");
min_lower = get_config_entry_int("min_lower");
min_digit = get_config_entry_int("min_digit");
min_punct = get_config_entry_int("min_punct");
max_consecutive_per_class = get_config_entry_int("max_consecutive_per_class");
/* Check Max Consecutive Per Class first since this has the most likelihood
* of being wrong.
*/
if ( max_consecutive_per_class != 0 ) {
char prev_type = '\0';
char this_type = ' ';
i = 0;
int consec_chars = 0;
for ( i = 0; i < nLen; i++ ) {
if ( islower(pPasswd[i]) ) {
this_type = 'l';
}
else if ( isupper(pPasswd[i]) ) {
this_type = 'u';
}
else if ( isdigit(pPasswd[i]) ) {
this_type = 'd';
}
else if ( ispunct(pPasswd[i]) ) {
this_type = 'p';
}
else {
this_type = ' ';
}
if (this_type == prev_type) {
++consec_chars;
} else if (i > 0) {
consec_chars = 0;
}
prev_type = this_type;
if ( consec_chars >= max_consecutive_per_class ) {
mem_len = realloc_error_message(&szErrStr, mem_len,
strlen(CONSEC_FAIL_SZ) +
strlen(pEntry->e_name.bv_val));
sprintf (szErrStr, CONSEC_FAIL_SZ, pEntry->e_name.bv_val);
goto fail;
}
}
}
/** The password must have at least min_quality strength points with one
* point for the first occurrance of a lower, upper, digit and
* punctuation character
*/
for ( i = 0; i < nLen; i++ ) {
//if ( nQuality >= min_quality ) break;
if ( islower (pPasswd[i]) ) {
min_lower--;
if ( !nLower && (min_lower < 1)) {
nLower = 1; nQuality++;
#if defined(DEBUG)
//.........这里部分代码省略.........
示例4: main
int main(int argc, char**argv)
{
GMainLoop *loop;
DBusError error;
int godaemon = 1;
/*
* Signal the kernel that we're not timing critical
*/
#ifdef PR_SET_TIMERSLACK
prctl(PR_SET_TIMERSLACK,1000*1000*1000, 0, 0, 0);
#endif
read_config_file("/etc/kerneloops.conf");
if (argc > 1 && strstr(argv[1], "--nodaemon"))
godaemon = 0;
if (argc > 1 && strstr(argv[1], "--debug")) {
printf("Starting kerneloops in debug mode\n");
godaemon = 0;
testmode = 1;
opted_in = 2;
}
if (!opted_in && !testmode) {
fprintf(stderr, " [Inactive by user preference]");
return EXIT_SUCCESS;
}
/*
* the curl docs say that we "should" call curl_global_init early,
* even though it'll be called later on via curl_easy_init().
* We ignore this advice, since 99.99% of the time this program
* will not use http at all, but the curl code does consume
* memory.
*/
/*
curl_global_init(CURL_GLOBAL_ALL);
*/
if (godaemon && daemon(0, 0)) {
printf("kerneloops failed to daemonize.. exiting \n");
return EXIT_FAILURE;
}
sched_yield();
loop = g_main_loop_new(NULL, FALSE);
dbus_error_init(&error);
bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
if (bus) {
dbus_connection_setup_with_g_main(bus, NULL);
dbus_bus_add_match(bus, "type='signal',interface='org.kerneloops.submit.ping'", &error);
dbus_bus_add_match(bus, "type='signal',interface='org.kerneloops.submit.permission'", &error);
dbus_connection_add_filter(bus, got_message, NULL, NULL);
}
/* we scan dmesg before /var/log/messages; dmesg is a more accurate source normally */
scan_dmesg(NULL);
/* during boot... don't go too fast and slow the system down */
if (!testmode)
sleep(10);
scan_filename(log_file, 1);
if (argc > 2 && strstr(argv[1], "--file"))
scan_filename(argv[2], 1);
if (testmode && argc > 2) {
int q;
for (q = 2; q < argc; q++) {
printf("Scanning %s\n", argv[q]);
scan_filename(argv[q], 0);
}
}
if (testmode) {
g_main_loop_unref(loop);
dbus_bus_remove_match(bus, "type='signal',interface='org.kerneloops.submit.ping'", &error);
dbus_bus_remove_match(bus, "type='signal',interface='org.kerneloops.submit.permission'", &error);
free(submit_url);
return EXIT_SUCCESS;
}
/* now, start polling for oopses to occur */
g_timeout_add_seconds(10, scan_dmesg, NULL);
g_main_loop_run(loop);
dbus_bus_remove_match(bus, "type='signal',interface='org.kerneloops.submit.ping'", &error);
dbus_bus_remove_match(bus, "type='signal',interface='org.kerneloops.submit.permission'", &error);
g_main_loop_unref(loop);
free(submit_url);
return EXIT_SUCCESS;
}
示例5: main
void main(int argc, char **argv)
{
bool running = TRUE;
/*---------------------------------------------------*/
/* parse command line arguments and initialize stuff */
/*---------------------------------------------------*/
parse_args( argc, argv );
log_file.init_log(TRUE,TRUE,2,NULL);
read_config_file();
init_socket();
command.list_commands();
command.prompt();
do
{
command.get_input();
switch( command.input[0] )
{
case 'd':
server_list.ListServers();
break;
case 'b':
banned_list.ListServers();
break;
case 'r':
read_config_file();
break;
case 'g':
query_game();
// wait_for_response( GAMESVR_REPLY );
break;
case 'q':
case 'Q':
running = FALSE;
break;
case 'l':
enable_log = !enable_log;
log_file.set_log(enable_log);
cout << "Log file is " << (enable_log?"on.":"off.") << endl;
break;
case 'e':
enable_echo = !enable_echo;
log_file.set_echo(enable_echo);
cout << "Log echo is " << (enable_echo?"on.":"off.") << endl;
break;
case '?':
case 'h':
command.list_commands();
break;
default:
case 'x':
server_list.DeleteList();
break;
}
if( GetTickCount() > next_reload_time )
{
read_config_file();
next_reload_time = GetTickCount() + reload_interval;
}
command.prompt();
}
while( running );
}
示例6: read_config_file
cChannelMap::cChannelMap (string conffile)
{
chanmap.clear ();
read_config_file(conffile);
}
示例7: main
//.........这里部分代码省略.........
!no_shell_flag)
fatal("Cannot fork into background without a command "
"to execute.");
/* Allocate a tty by default if no command specified. */
if (buffer_len(&command) == 0)
tty_flag = options.request_tty != REQUEST_TTY_NO;
/* Force no tty */
if (options.request_tty == REQUEST_TTY_NO || muxclient_command != 0)
tty_flag = 0;
/* Do not allocate a tty if stdin is not a tty. */
if ((!isatty(fileno(stdin)) || stdin_null_flag) &&
options.request_tty != REQUEST_TTY_FORCE) {
if (tty_flag && options.log_level != SYSLOG_LEVEL_QUIET)
logit("Pseudo-terminal will not be allocated because "
"stdin is not a terminal.");
tty_flag = 0;
}
/*
* Initialize "log" output. Since we are the client all output
* actually goes to stderr.
*/
log_init(argv0,
options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level,
SYSLOG_FACILITY_USER, !use_syslog);
/*
* Read per-user configuration file. Ignore the system wide config
* file if the user specifies a config file on the command line.
*/
if (config != NULL) {
if (!read_config_file(config, host, &options, 0))
fatal("Can't open user config file %.100s: "
"%.100s", config, strerror(errno));
} else {
r = snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir,
_PATH_SSH_USER_CONFFILE);
if (r > 0 && (size_t)r < sizeof(buf))
(void)read_config_file(buf, host, &options, 1);
/* Read systemwide configuration file after user config. */
(void)read_config_file(_PATH_HOST_CONFIG_FILE, host,
&options, 0);
}
/* Fill configuration defaults. */
fill_default_options(&options);
channel_set_af(options.address_family);
/* reinit */
log_init(argv0, options.log_level, SYSLOG_FACILITY_USER, !use_syslog);
seed_rng();
if (options.user == NULL)
options.user = xstrdup(pw->pw_name);
/* Get default port if port has not been set. */
if (options.port == 0) {
sp = getservbyname(SSH_SERVICE_NAME, "tcp");
options.port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
}
示例8: Timidity_Init
// not used
int Timidity_Init(int rate, int format, int channels, int samples)
{
if (read_config_file(CONFIG_FILE)<0) {
return(-1);
}
/* Set play mode parameters */
play_mode->rate = rate;
play_mode->encoding = 0;
if ( (format&0xFF) == 16 ) {
play_mode->encoding |= PE_16BIT;
}
if ( (format&0x8000) ) {
play_mode->encoding |= PE_SIGNED;
}
if ( channels == 1 ) {
play_mode->encoding |= PE_MONO;
}
switch (format) {
case AUDIO_S8:
s32tobuf = s32tos8;
break;
case AUDIO_U8:
s32tobuf = s32tou8;
break;
case AUDIO_S16LSB:
s32tobuf = s32tos16l;
break;
case AUDIO_S16MSB:
s32tobuf = s32tos16b;
break;
case AUDIO_U16LSB:
s32tobuf = s32tou16l;
break;
case AUDIO_U16MSB:
s32tobuf = s32tou16b;
break;
default:
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Unsupported audio format");
return(-1);
}
AUDIO_BUFFER_SIZE = samples;
/* Allocate memory for mixing (WARNING: Memory leak!) */
resample_buffer = safe_Malloc<sample_t>(AUDIO_BUFFER_SIZE);
common_buffer = safe_Malloc<sint32>(AUDIO_BUFFER_SIZE*2);
init_tables();
if (ctl->open(0, 0)) {
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Couldn't open %s\n", ctl->id_name);
return(-1);
}
if (!control_ratio) {
control_ratio = play_mode->rate / CONTROLS_PER_SECOND;
if(control_ratio<1)
control_ratio=1;
else if (control_ratio > MAX_CONTROL_RATIO)
control_ratio=MAX_CONTROL_RATIO;
}
if (*def_instr_name)
set_default_instrument(def_instr_name);
return(0);
}
示例9: Timidity_Init_Simple
int Timidity_Init_Simple(int rate, int samples, sint32 encoding)
{
std::string configfile;
/* see if the pentagram config file specifies an alternate timidity.cfg */
#ifndef PENTAGRAM_IN_EXULT
SettingManager* settings = SettingManager::get_instance();
if (!settings->get("timiditycfg", configfile))
configfile = CONFIG_FILE;
#else
config->value("config/audio/midi/timiditycfg", configfile, CONFIG_FILE);
#endif
if (read_config_file(configfile.c_str())<0) {
return(-1);
}
/* Check to see if the encoding is 'valid' */
// Only 16 bit can be byte swapped
if ((encoding & PE_BYTESWAP) && !(encoding & PE_16BIT))
return(-1);
// u-Law can only be mono or stereo
if ((encoding & PE_ULAW) && (encoding & ~(PE_ULAW|PE_MONO)))
return(-1);
/* Set play mode parameters */
play_mode->rate = rate;
play_mode->encoding = encoding;
switch (play_mode->encoding) {
case 0:
case PE_MONO:
s32tobuf = s32tou8;
break;
case PE_SIGNED:
case PE_SIGNED|PE_MONO:
s32tobuf = s32tos8;
break;
case PE_ULAW:
case PE_ULAW|PE_MONO:
s32tobuf = s32toulaw;
break;
case PE_16BIT:
case PE_16BIT|PE_MONO:
s32tobuf = s32tou16;
break;
case PE_16BIT|PE_SIGNED:
case PE_16BIT|PE_SIGNED|PE_MONO:
s32tobuf = s32tos16;
break;
case PE_BYTESWAP|PE_16BIT:
case PE_BYTESWAP|PE_16BIT|PE_MONO:
s32tobuf = s32tou16x;
break;
case PE_BYTESWAP|PE_16BIT|PE_SIGNED:
case PE_BYTESWAP|PE_16BIT|PE_SIGNED|PE_MONO:
s32tobuf = s32tos16x;
break;
default:
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Unsupported audio format");
return(-1);
}
AUDIO_BUFFER_SIZE = samples;
/* Allocate memory for mixing (WARNING: Memory leak!) */
resample_buffer = safe_Malloc<sample_t>(AUDIO_BUFFER_SIZE);
common_buffer = safe_Malloc<sint32>(AUDIO_BUFFER_SIZE*2);
init_tables();
if (ctl->open(0, 0)) {
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Couldn't open %s\n", ctl->id_name);
return(-1);
}
if (!control_ratio) {
control_ratio = play_mode->rate / CONTROLS_PER_SECOND;
if(control_ratio<1)
control_ratio=1;
else if (control_ratio > MAX_CONTROL_RATIO)
control_ratio=MAX_CONTROL_RATIO;
}
if (*def_instr_name)
set_default_instrument(def_instr_name);
return(0);
}
示例10: process_arg
int process_arg(int option, const char *name, const char *val, priority_t precedence, arg_pass_t pass)
{
int count = 0;
(void) precedence; /* suppress compiler warning */
(void) pass; /* suppress compiler warning */
switch (option) {
case '?':
fprintf(stderr, "Unknown option '%s'.\n", name);
break;
case 'd':
flag = M_DUMP;
count += 1;
ds_file = val;
break;
case O_CONFIG_FILE:
read_config_file(val, false, false, PR_COMMAND, longopts_bogoutil);
/*@[email protected]*/
/* fall through to suppress reading config files */
case 'C':
suppress_config_file = true;
break;
case 'k':
db_cachesize=(uint) atoi(val);
break;
case 'l':
flag = M_LOAD;
count += 1;
ds_file = val;
break;
case 'm':
flag = M_MAINTAIN;
count += 1;
ds_file = val;
break;
case 'p':
prob = true;
/*@[email protected]*/
case 'w':
flag = M_WORD;
count += 1;
ds_file = val;
break;
case O_DB_PRINT_LEAFPAGE_COUNT:
flag = M_LEAFPAGES;
count += 1;
ds_file = val;
break;
case O_DB_PRINT_PAGESIZE:
flag = M_PAGESIZE;
count += 1;
ds_file = val;
break;
case 'r':
onlyprint = true;
case 'R':
flag = M_ROBX;
count += 1;
ds_file = val;
break;
case 'u':
upgrade_wordlist_version = true;
flag = M_MAINTAIN;
count += 1;
ds_file = val;
break;
case 'v':
verbose++;
break;
case ':':
fprintf(stderr, "Option %s requires an argument.\n", name);
exit(EX_ERROR);
case 'h':
help(stdout);
exit(EX_OK);
case 'H':
flag = M_HIST;
count += 1;
ds_file = val;
break;
case 'V':
print_version();
//.........这里部分代码省略.........
示例11: main
int main(int argc, char **argv){
int result=OK;
int x;
char buffer[MAX_INPUT_BUFFER];
#ifdef HAVE_SSL
DH *dh;
#endif
result=process_arguments(argc,argv);
if(result!=OK || show_help==TRUE || show_license==TRUE || show_version==TRUE){
printf("\n");
printf("NRPE - Nagios Remote Plugin Executor\n");
printf("Copyright (c) 1999-2003 Ethan Galstad ([email protected])\n");
printf("Version: %s\n",PROGRAM_VERSION);
printf("Last Modified: %s\n",MODIFICATION_DATE);
printf("License: GPL with exemptions (-l for more info)\n");
#ifdef HAVE_SSL
printf("SSL/TLS Available: Anonymous DH Mode, OpenSSL 0.9.6 or higher required\n");
#endif
printf("\n");
#ifdef ENABLE_COMMAND_ARGUMENTS
printf("***************************************************************\n");
printf("** POSSIBLE SECURITY RISK - COMMAND ARGUMENTS ARE SUPPORTED! **\n");
printf("** Read the NRPE SECURITY file for more information **\n");
printf("***************************************************************\n");
printf("\n");
#endif
}
if(show_license==TRUE)
display_license();
else if(result!=OK || show_help==TRUE){
printf("Usage: nrpe -c <config_file> <mode>\n");
printf("\n");
printf("Options:\n");
printf(" <config_file> = Name of config file to use\n");
printf(" <mode> = One of the following two operating modes:\n");
printf(" -i = Run as a service under inetd or xinetd\n");
printf(" -d = Run as a standalone daemon\n");
printf("\n");
printf("Notes:\n");
printf("This program is designed to process requests from the check_nrpe\n");
printf("plugin on the host(s) running Nagios. It can run as a service\n");
printf("under inetd or xinetd (read the docs for info on this), or as a\n");
printf("standalone daemon. Once a request is received from an authorized\n");
printf("host, NRPE will execute the command/plugin (as defined in the\n");
printf("config file) and return the plugin output and return code to the\n");
printf("check_nrpe plugin.\n");
printf("\n");
}
if(result!=OK || show_help==TRUE || show_license==TRUE || show_version==TRUE)
exit(STATE_UNKNOWN);
/* open a connection to the syslog facility */
openlog("nrpe",LOG_PID,LOG_DAEMON);
/* read the config file */
result=read_config_file(config_file);
/* exit if there are errors... */
if(result==ERROR){
syslog(LOG_ERR,"Config file '%s' contained errors, bailing out...",config_file);
return STATE_CRITICAL;
}
/* initialize macros */
for(x=0;x<MAX_COMMAND_ARGUMENTS;x++)
macro_argv[x]=NULL;
/* generate the CRC 32 table */
generate_crc32_table();
#ifdef HAVE_SSL
/* initialize SSL */
if(use_ssl==TRUE){
SSL_library_init();
SSLeay_add_ssl_algorithms();
meth=SSLv23_server_method();
SSL_load_error_strings();
if((ctx=SSL_CTX_new(meth))==NULL){
syslog(LOG_ERR,"Error: could not create SSL context.\n");
exit(STATE_CRITICAL);
}
/*SSL_CTX_set_cipher_list(ctx,"ALL");*/
SSL_CTX_set_cipher_list(ctx,"ADH");
dh=get_dh512();
SSL_CTX_set_tmp_dh(ctx,dh);
DH_free(dh);
if(debug==TRUE)
syslog(LOG_INFO,"INFO: SSL/TLS initialized. All network traffic will be encrypted.");
}
else{
if(debug==TRUE)
syslog(LOG_INFO,"INFO: SSL/TLS NOT initialized. Network encryption DISABLED.");
//.........这里部分代码省略.........
示例12: read_config_dir
/* process all config files in a specific config directory (with directory recursion) */
int read_config_dir(char *dirname){
char config_file[MAX_FILENAME_LENGTH];
DIR *dirp;
struct dirent *dirfile;
int result=OK;
int x;
/* open the directory for reading */
dirp=opendir(dirname);
if(dirp==NULL){
syslog(LOG_ERR,"Could not open config directory '%s' for reading.\n",dirname);
return ERROR;
}
/* process all files in the directory... */
while((dirfile=readdir(dirp))!=NULL){
/* process this if it's a config file... */
x=strlen(dirfile->d_name);
if(x>4 && !strcmp(dirfile->d_name+(x-4),".cfg")){
#ifdef _DIRENT_HAVE_D_TYPE
/* only process normal files */
if(dirfile->d_type!=DT_REG)
continue;
#endif
/* create the full path to the config file */
snprintf(config_file,sizeof(config_file)-1,"%s/%s",dirname,dirfile->d_name);
config_file[sizeof(config_file)-1]='\x0';
/* process the config file */
result=read_config_file(config_file);
/* break out if we encountered an error */
if(result==ERROR)
break;
}
#ifdef _DIRENT_HAVE_D_TYPE
/* recurse into subdirectories... */
if(dirfile->d_type==DT_DIR){
/* ignore current, parent and hidden directory entries */
if(dirfile->d_name[0]=='.')
continue;
/* create the full path to the config directory */
snprintf(config_file,sizeof(config_file)-1,"%s/%s",dirname,dirfile->d_name);
config_file[sizeof(config_file)-1]='\x0';
/* process the config directory */
result=read_config_dir(config_file);
/* break out if we encountered an error */
if(result==ERROR)
break;
}
#endif
}
closedir(dirp);
return result;
}
示例13: read_config_file
/* read in the configuration file */
int read_config_file(char *filename){
FILE *fp;
char config_file[MAX_FILENAME_LENGTH];
char input_buffer[MAX_INPUT_BUFFER];
char *temp_buffer;
char *varname;
char *varvalue;
int line;
/* open the config file for reading */
fp=fopen(filename,"r");
/* exit if we couldn't open the config file */
if(fp==NULL){
syslog(LOG_ERR,"Unable to open config file '%s' for reading\n",filename);
return ERROR;
}
line=0;
while(fgets(input_buffer,MAX_INPUT_BUFFER-1,fp)){
line++;
/* skip comments and blank lines */
if(input_buffer[0]=='#')
continue;
if(input_buffer[0]=='\x0')
continue;
if(input_buffer[0]=='\n')
continue;
/* get the variable name */
varname=strtok(input_buffer,"=");
if(varname==NULL){
syslog(LOG_ERR,"No variable name specified in config file '%s' - Line %d\n",filename,line);
return ERROR;
}
/* get the variable value */
varvalue=strtok(NULL,"\n");
if(varvalue==NULL){
syslog(LOG_ERR,"No variable value specified in config file '%s' - Line %d\n",filename,line);
return ERROR;
}
/* allow users to specify directories to recurse into for config files */
else if(!strcmp(varname,"include_dir")){
strncpy(config_file,varvalue,sizeof(config_file)-1);
config_file[sizeof(config_file)-1]='\x0';
/* strip trailing / if necessary */
if(config_file[strlen(config_file)-1]=='/')
config_file[strlen(config_file)-1]='\x0';
/* process the config directory... */
if(read_config_dir(config_file)==ERROR)
break;
}
/* allow users to specify individual config files to include */
else if(!strcmp(varname,"include") || !strcmp(varname,"include_file")){
/* process the config file... */
if(read_config_file(varvalue)==ERROR)
break;
}
else if(!strcmp(varname,"server_port")){
server_port=atoi(varvalue);
if(server_port<1024){
syslog(LOG_ERR,"Invalid port number specified in config file '%s' - Line %d\n",filename,line);
return ERROR;
}
}
else if(!strcmp(varname,"server_address")){
strncpy(server_address,varvalue,sizeof(server_address) - 1);
server_address[sizeof(server_address)-1]='\0';
}
else if(!strcmp(varname,"allowed_hosts")){
if(strlen(input_buffer)>sizeof(allowed_hosts)){
syslog(LOG_ERR,"Allowed hosts list too long in config file '%s' - Line %d\n",filename,line);
return ERROR;
}
strncpy(allowed_hosts,varvalue,sizeof(allowed_hosts));
allowed_hosts[sizeof(allowed_hosts)-1]='\x0';
}
else if(strstr(input_buffer,"command[")){
temp_buffer=strtok(varname,"[");
temp_buffer=strtok(NULL,"]");
if(temp_buffer==NULL){
syslog(LOG_ERR,"Invalid command specified in config file '%s' - Line %d\n",filename,line);
return ERROR;
}
add_command(temp_buffer,varvalue);
//.........这里部分代码省略.........
示例14: main
//.........这里部分代码省略.........
pptp_ptimeout = atoi(optarg);
break;
case 'k': /* --keep */
keep_connections = 1;
break;
case 'c': /* --conf */
{
FILE *f;
if (!(f = fopen(optarg, "r"))) {
syslog(LOG_ERR, "MGR: Config file not found!");
return 1;
}
fclose(f);
if(configFile) free(configFile);
configFile = strdup(optarg);
break;
}
default:
showusage(argv[0]);
return 1;
}
}
/* Now that we have all the command line args.. lets open the
* conf file and add anything else (remembering not to override
* anything since the command line has more privilages :-)
*/
if (!configFile)
configFile = strdup(PPTPD_CONFIG_FILE_DEFAULT);
if (read_config_file(configFile, CONNECTIONS_KEYWORD, tmp) > 0) {
pptp_connections = atoi(tmp);
if (pptp_connections <= 0)
pptp_connections = CONNECTIONS_DEFAULT;
}
slot_init(pptp_connections);
if (!pptp_debug && read_config_file(configFile, DEBUG_KEYWORD, tmp) > 0)
pptp_debug = TRUE;
#ifdef BCRELAY
if (!bcrelay && read_config_file(configFile, BCRELAY_KEYWORD, tmp) > 0)
bcrelay = strdup(tmp);
#endif
if (!pptp_stimeout && read_config_file(configFile, STIMEOUT_KEYWORD, tmp) > 0) {
pptp_stimeout = atoi(tmp);
if (pptp_stimeout <= 0)
pptp_stimeout = STIMEOUT_DEFAULT;
}
if (!pptp_ptimeout && read_config_file(configFile, PTIMEOUT_KEYWORD, tmp) > 0) {
pptp_ptimeout = atoi(tmp);
if (pptp_ptimeout <= 0)
pptp_ptimeout = PTIMEOUT_DEFAULT;
}
if (!pptp_noipparam && read_config_file(configFile, NOIPPARAM_KEYWORD, tmp) > 0) {
pptp_noipparam = TRUE;
}
if (!bindaddr && read_config_file(configFile, LISTEN_KEYWORD, tmp) > 0) {
示例15: read_config_file
static int read_config_file(const char *name)
{
FILE *fp;
char tmp[1024], *w[MAXWORDS], *cp;
ToneBank *bank=0;
int i, j, k, line=0, words;
static int rcf_count=0;
if (rcf_count>50)
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
"Probable source loop in configuration files");
return (-1);
}
if (!(fp=open_file(name, 1, OF_VERBOSE)))
return -1;
while (fgets(tmp, sizeof(tmp), fp))
{
line++;
w[words=0]=strtok(tmp, " \t\r\n\240");
if (!w[0] || (*w[0]=='#')) continue;
while (w[words] && (words < MAXWORDS))
w[++words]=strtok(0," \t\r\n\240");
if (!strcmp(w[0], "dir"))
{
if (words < 2)
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
"%s: line %d: No directory given\n", name, line);
return -2;
}
for (i=1; i<words; i++)
add_to_pathlist(w[i]);
}
else if (!strcmp(w[0], "source"))
{
if (words < 2)
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
"%s: line %d: No file name given\n", name, line);
return -2;
}
for (i=1; i<words; i++)
{
rcf_count++;
read_config_file(w[i]);
rcf_count--;
}
}
else if (!strcmp(w[0], "default"))
{
if (words != 2)
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
"%s: line %d: Must specify exactly one patch name\n",
name, line);
return -2;
}
strncpy(def_instr_name, w[1], 255);
def_instr_name[255]='\0';
}
else if (!strcmp(w[0], "drumset"))
{
if (words < 2)
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
"%s: line %d: No drum set number given\n",
name, line);
return -2;
}
i=atoi(w[1]);
if (i<0 || i>127)
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
"%s: line %d: Drum set must be between 0 and 127\n",
name, line);
return -2;
}
if (!drumset[i])
{
drumset[i]=safe_Malloc<ToneBank>();
memset(drumset[i], 0, sizeof(ToneBank));
}
bank=drumset[i];
}
else if (!strcmp(w[0], "bank"))
{
if (words < 2)
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
"%s: line %d: No bank number given\n",
name, line);
return -2;
}
i=atoi(w[1]);
if (i<0 || i>127)
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
//.........这里部分代码省略.........