Ejemplo n.º 1
0
void MSG_db1_data::close( )
{
  if (dirname) { free(dirname); dirname = 0; }
  if (AoI) { iniparser_free(AoI); AoI = 0; }
  if (INFO) { iniparser_free(INFO); INFO = 0; }
  if (Calibration) { iniparser_free(Calibration); Calibration = 0; }
  if (rawdata) { delete [ ] rawdata; rawdata = 0; }
  if (cal_values) { delete [ ] cal_values; cal_values = 0; }
  chnum = 0;
  ncalval = -1;
}
Ejemplo n.º 2
0
static void destroy(void)
{
	/* ldap_unbind */
	free_ld_sessions();

	/* free config file memory */
	iniparser_free(config_vals);
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
  int err, result = 0;
  lua_State *L;
  setup_signal_handler();
  parse_config(inifile);
  log_open(logfile);

  err = parse_args(argc, argv, &result);
  if (err) {
    return result;
  }

  locale_init();

#ifdef CRTDBG
  init_crtdbg();
#endif

    L = lua_init();
  game_init();
  register_races();
  register_borders();
  register_spells();
  bind_monsters(L);
  err = eressea_run(L, luafile);
  if (err) {
    log_error("server execution failed with code %d\n", err);
    return err;
  }
#ifdef MSPACES
  malloc_stats();
#endif

  game_done();
  lua_done(L);
  log_close();
  if (global.inifile) {
    iniparser_free(global.inifile);
  }
  return 0;
}
Ejemplo n.º 4
0
Archivo: nowd.c Proyecto: 5bruce/sbase
int main(int argc, char **argv)
{
    pid_t pid;
    char *conf = NULL, *p = NULL, ch = 0;
    int is_daemon = 0;

    /* get configure file */
    while((ch = getopt(argc, argv, "c:d")) != (char)-1)
    {
        if(ch == 'c') conf = optarg;
        else if(ch == 'd') is_daemon = 1;
    }
    if(conf == NULL)
    {
        fprintf(stderr, "Usage:%s -d -c config_file\n", argv[0]);
        _exit(-1);
    }
    /* locale */
    setlocale(LC_ALL, "C");
    /* signal */
    signal(SIGTERM, &nowd_stop);
    signal(SIGINT,  &nowd_stop);
    signal(SIGHUP,  SIG_IGN);
    signal(SIGPIPE, SIG_IGN);
    //daemon
    if(is_daemon)
    {
        pid = fork();
        switch (pid) {
            case -1:
                perror("fork()");
                exit(EXIT_FAILURE);
                break;
            case 0: //child
                if(setsid() == -1)
                    exit(EXIT_FAILURE);
                break;
            default://parent
                _exit(EXIT_SUCCESS);
                break;
        }
    }
    setrlimiter("RLIMIT_NOFILE", RLIMIT_NOFILE, 10240);
    if((sbase = sbase_init()) == NULL)
    {
        exit(EXIT_FAILURE);
        return -1;
    }
    fprintf(stdout, "Initializing from configure file:%s\n", conf);
    /* Initialize sbase */
    if(sbase_initialize(sbase, conf) != 0 )
    {
        fprintf(stderr, "Initialize from configure file failed\n");
        exit(EXIT_FAILURE);
        return -1;
    }
    fprintf(stdout, "Initialized successed\n");
    sbase->running(sbase, 0);
    //sbase->running(sbase, 60000000); sbase->stop(sbase);
    //sbase->running(sbase, 90000000);sbase->stop(sbase);
    sbase->clean(sbase);
    if(dict)iniparser_free(dict);
    return 0;
}
Ejemplo n.º 5
0
static void *
init_curl_transport(WsManClient *cl)
{
	CURL *curl;
	CURLcode r = CURLE_OK;
        char *sslhack;
        long sslversion;
        dictionary *ini = iniparser_new(wsmc_get_conffile(cl));

#define curl_err(str)  debug("Error = %d (%s); %s", \
		r, curl_easy_strerror(r), str);
	curl = curl_easy_init();
	if (curl == NULL) {
		r = CURLE_FAILED_INIT;
		debug("Could not init easy curl");
		goto DONE;
	}
        // client:curlopt_nosignal
        if (ini) {
          int nosignal = iniparser_getint(ini, "client:curlopt_nosignal", 0);
          r = curl_easy_setopt(curl, CURLOPT_NOSIGNAL, nosignal);
          if (r != 0) {
            curl_err("curl_easy_setopt(CURLOPT_NOSIGNAL) failed");
            goto DONE;
          }
        }
	debug("cl->authentication.verify_peer: %d", cl->authentication.verify_peer );
	// verify peer
	r = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, wsman_transport_get_verify_peer(cl)?1:0);
	if (r != 0) {
		curl_err("curl_easy_setopt(CURLOPT_SSL_VERIFYPEER) failed");
		goto DONE;
	}

	// verify host
	r = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, wsman_transport_get_verify_host(cl)?2:0);
	if (r != 0) {
		curl_err("curl_easy_setopt(CURLOPT_SSL_VERIFYHOST) failed");
		goto DONE;
	}

	r = curl_easy_setopt(curl, CURLOPT_PROXY, cl->proxy_data.proxy);
	if (r != 0) {
		curl_err("Could notcurl_easy_setopt(curl, CURLOPT_PROXY, ...)");
		goto DONE;
	}
	r = curl_easy_setopt(curl, CURLOPT_TIMEOUT, cl->transport_timeout);
	if (r != 0) {
		curl_err("Could notcurl_easy_setopt(curl, CURLOPT_TIMEOUT, ...)");
		goto DONE;
	}

	r = curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, cl->proxy_data.proxy_auth);
	if (r != 0) {
		curl_err("Could notcurl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, ...)");
		goto DONE;
	}
	
	if (0 != cl->authentication.verify_peer && 0 != cl->authentication.crl_check)
	{		
		if (cl->authentication.crl_file == NULL)
		{
			if (ini != NULL)
			{
			        char *crlfile = iniparser_getstr(ini, "client:crlfile");
				wsman_transport_set_crlfile(cl, crlfile);
			}
		}
		if (cl->authentication.crl_file != NULL)
		{
			debug("wsman-curl-client-transport.c: init_curl_transport() : CRL file = %s\n",cl->authentication.crl_file);
			r = curl_easy_setopt(curl, CURLOPT_CRLFILE, cl->authentication.crl_file);		
		}
		
	}

	if (cl->authentication.capath) {
		r = curl_easy_setopt(curl, CURLOPT_CAPATH, cl->authentication.capath);
		if (r != 0) {
			curl_err("Could not curl_easy_setopt(curl, CURLOPT_CAPATH, ..)");
			goto DONE;
		}
	}
	// cainfo
	if (cl->authentication.cainfo) {
		r = curl_easy_setopt(curl, CURLOPT_CAINFO, cl->authentication.cainfo);
		if (r != 0) {
			curl_err("Could not curl_easy_setopt(curl, CURLOPT_CAINFO, ..)");
			goto DONE;
		}
	}
	// certificate thumbprint
#ifdef ENABLE_EVENTING_SUPPORT
/*  Bug in e.g. Fedora: [ curl-Bugs-1924441 ] SSL callback option with NSS-linked libcurl */
#ifndef NO_SSL_CALLBACK
	else if (strlen((char *)cl->authentication.certificatethumbprint) > 0 && 0 != cl->authentication.verify_peer) {
		r = curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun);
		if(r != 0) {
			curl_err("Could not curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION)");
			goto DONE;
		}
		r = curl_easy_setopt(curl, CURLOPT_SSL_CTX_DATA, (void *)cl->authentication.certificatethumbprint);
		if(r != 0) {
			curl_err("Could not curl_easy_setopt(curl, CURLOPT_SSL_CTX_DATA)");
			goto DONE;
		}
	}
#endif
#endif
	// sslkey
	r = curl_easy_setopt(curl, CURLOPT_SSLKEY, cl->authentication.sslkey);
	if (r != 0) {
		curl_err("Could not curl_easy_setopt(curl, CURLOPT_SSLKEY, ..)");
		goto DONE;
	}
	// sslcert
	r = curl_easy_setopt(curl, CURLOPT_SSLCERT, cl->authentication.sslcert );
	if (r != 0) {
		curl_err("Could not curl_easy_setopt(curl, CURLOPT_SSLCERT, ..)");
		goto DONE;
	}

        /* enforce specific ssl version if requested */
        sslhack = getenv("OPENWSMAN_CURL_TRANSPORT_SSLVERSION");
        if (sslhack == NULL) {
          sslversion = CURL_SSLVERSION_DEFAULT;
        } else if (!strcmp(sslhack,"tlsv1")) {
          sslversion = CURL_SSLVERSION_TLSv1;
        } else if (!strcmp(sslhack,"sslv2")) {
          sslversion = CURL_SSLVERSION_SSLv2;
        } else if (!strcmp(sslhack,"sslv3")) {
          sslversion = CURL_SSLVERSION_SSLv3;
#if LIBCURL_VERSION_NUM >= 0x072200
        } else if (!strcmp(sslhack,"tlsv1.0")) {
          sslversion = CURL_SSLVERSION_TLSv1_0;
        } else if (!strcmp(sslhack,"tlsv1.1")) {
          sslversion = CURL_SSLVERSION_TLSv1_1;
        } else if (!strcmp(sslhack,"tlsv1.2")) {
          sslversion = CURL_SSLVERSION_TLSv1_2;
#endif
        }
        else {
          sslversion = CURL_SSLVERSION_DEFAULT;
        }
        r = curl_easy_setopt(curl, CURLOPT_SSLVERSION, sslversion );
        if (r != 0) {
          curl_err("Could not curl_easy_setopt(curl, CURLOPT_SSLVERSION, ..)");
          goto DONE;
        }

        iniparser_free(ini);
	return (void *)curl;
 DONE:
	cl->last_error = convert_to_last_error(r);
	curl_easy_cleanup(curl);
        iniparser_free(ini);
	return NULL;
#undef curl_err
}
Ejemplo n.º 6
0
int GetConfig(char * ini_name)
{
	//char *_MxAdress,*_MxPort,*_GradFile,*_CLPath;
	int i;
	char eventname[MAXSTRSIZE];
	int debug;
	dictionary	*	ini ;
	ini = iniparser_new(ini_name);
	if (ini==NULL)
	{
		Log(LOG_ERR, "cannot parse file [%s]\n", ini_name);
		return(1) ;
	}
	/* Main Section*/
	DEAMON=iniparser_getboolean(ini, "Main:Daemon", DEAMON);
	debug=iniparser_getint(ini, "Main:Log", debuglevel);
	switch (debug)
	{
		case 3:debuglevel=LOG_DEBUG;break;
		case 2:debuglevel=LOG_INFO;break;
		case 1:debuglevel=LOG_WARNING;break;
		case 0:debuglevel=LOG_ERR;break;
		default:debuglevel=LOG_WARNING;break;
	}

	/* Db section */
	strncpy(DBHOST,iniparser_getstring(ini,"Db:DbHost" ,""),sizeof(DBHOST));
	strncpy(DB,iniparser_getstring(ini,"Db:DbName" ,""),sizeof(DB));
	strncpy(USER,iniparser_getstring(ini,"Db:DbUserName" ,""),sizeof(USER));
	strncpy(PASS,iniparser_getstring(ini,"Db:DbPassword" ,""),sizeof(PASS));


	/* Measurex section */
	strncpy(MXNAME,iniparser_getstring(ini,"Measurex:MxId" ,""),sizeof(MXNAME));
	strncpy(MXADDRESS,iniparser_getstring(ini,"Measurex:MxAdress" ,""),sizeof(MXADDRESS));
	strncpy(MXPORT,iniparser_getstring(ini,"Measurex:MxPort" ,""),sizeof(MXPORT));

	/* PLC Section */
	CLPath=strdup(iniparser_getstring(ini,"PLC:CLPath" ,NULL));
	plc=GetPlc(CLPath);

	/* Variables Section*/
	AB_VARCOUNT=0;
	for(i=0;i<ini->n;i++)
	{
		char *section=iniparser_getsectionname(ini,i);
		if (strcasecmp("Variables",section)==0)
		{
			char *key=iniparser_getkeyname(ini,i);
			if (key!=NULL)
			{
				AB_VARCOUNT++;
				TAG *var=malloc(sizeof(TAG));
				AddListe(&variables,var);
				memset(var,0,sizeof(TAG));
				strncpy((char *)(var->TagName),key,MAXALIASSIZE);
				strncpy((char *)(var->Value_Address),ini->val[i],MAXALIASSIZE);
				snprintf(eventname,MAXSTRSIZE-1,"Events:%s",var->TagName);
				char *temp=iniparser_getstring(ini,eventname,NULL);
				if (temp!=NULL)	strncpy((char *)(var->Reset_Address),temp,MAXALIASSIZE);
				free(key);
			}
		}
		free(section);
	}
	iniparser_free(ini);
	return(0);
}
Ejemplo n.º 7
0
bool readIniFile(char *iniFilePathAndName)
{
    dictionary *dict;
    int ii;
    char tmpBuf[MY_TMP_BUF_LEN];
    char tmpBuf2[MY_TMP_BUF_LEN];
    
    dict = iniparser_new(iniFilePathAndName);
    
    if (dict != NULL) {        
        //General settings
        //General settings
        viewerPort = iniparser_getint(dict, "general:viewerport", 5900);    
        serverPort = iniparser_getint(dict, "general:serverport", 5500);    

        maxSessions = iniparser_getint(dict, "general:maxsessions", MAX_SESSIONS_DEFAULT);
        if (maxSessions > MAX_SESSIONS_MAX)
            maxSessions = MAX_SESSIONS_DEFAULT;
        if (maxSessions < MAX_SESSIONS_MIN)
            maxSessions = MAX_SESSIONS_DEFAULT;

        allowedModes = iniparser_getint(dict, "general:allowedmodes", (CONN_MODE1 | CONN_MODE2));     
        
        strlcpy(ownIpAddress, iniparser_getstring(dict, "general:ownipaddress", "0.0.0.0"), MY_TMP_BUF_LEN);
        
        loggingLevel = iniparser_getint(dict, "general:logginglevel", DEFAULT_LOGGING_LEVEL);     
        if (loggingLevel > LEVEL_3)
            loggingLevel = DEFAULT_LOGGING_LEVEL;
        if (loggingLevel < LEVEL_0)
            loggingLevel = DEFAULT_LOGGING_LEVEL;

        
        //Mode 1 settings
        allowedMode1ServerPort = iniparser_getint(dict, "mode1:allowedmode1serverport", 0);        
        requireListedServer = iniparser_getint(dict, "mode1:requirelistedserver", 0);        
        if (requireListedServer == 1) {
            //Allowed servers
            for(ii = 0; ii < SERVERS_LIST_SIZE; ii++) {
                snprintf(tmpBuf, MY_TMP_BUF_LEN, "%s%d", "mode1:srvListAllow", ii);
                
                strlcpy(tmpBuf2, iniparser_getstring(dict, tmpBuf, "255.255.255.255"), MY_TMP_BUF_LEN);
                
                srvListAllow[ii] = getAddrPartsFromString(tmpBuf2);
            }


            //Denied servers
            for(ii = 0; ii < SERVERS_LIST_SIZE; ii++) {
                snprintf(tmpBuf, MY_TMP_BUF_LEN, "%s%d", "mode1:srvListDeny", ii);
                
                strlcpy(tmpBuf2, iniparser_getstring(dict, tmpBuf, "255.255.255.255"), MY_TMP_BUF_LEN);
                
                srvListDeny[ii] = getAddrPartsFromString(tmpBuf2);
            }
        }
        
        
        //Mode 2 settings
        requireListedId = iniparser_getint(dict, "mode2:requirelistedid", 0);        
        if (requireListedId == 1) {
            for(ii = 0; ii < ID_LIST_SIZE; ii++) {
                snprintf(tmpBuf, MY_TMP_BUF_LEN, "%s%d", "mode2:idlist", ii);
                idList[ii] = iniparser_getint(dict, tmpBuf, 0);
            }
        }
       
        iniparser_free(dict);
        return true;           
    }
    else 
        return false;
        
    return true;
}
Ejemplo n.º 8
0
void
ccsIniClose (IniDictionary *dictionary)
{
    iniparser_free (dictionary);
}
Ejemplo n.º 9
0
ConfigObject::~ConfigObject()
{
	iniparser_free(d);
}
Ejemplo n.º 10
0
bool readIniFile(char *iniFilePathAndName)
{
    dictionary *dict;
    int ii;
    char tmpBuf[MY_TMP_BUF_LEN];
    char tmpBuf2[MY_TMP_BUF_LEN];

    /* initialize Allow/Deny lists */
    memset(srvListDeny, 255, sizeof(srvListDeny));
    memset(srvListAllow, 255, sizeof(srvListAllow));

    dict = iniparser_new(iniFilePathAndName);

    if (dict != NULL) {
        /* General settings */
        /* General settings */
        viewerPort = iniparser_getint(dict, "general:viewerport", 5900);
        serverPort = iniparser_getint(dict, "general:serverport", 5500);

        maxSessions = iniparser_getint(dict, "general:maxsessions", MAX_SESSIONS_DEFAULT);
        if (maxSessions > MAX_SESSIONS_MAX)
            maxSessions = MAX_SESSIONS_DEFAULT;
        if (maxSessions < MAX_SESSIONS_MIN)
            maxSessions = MAX_SESSIONS_DEFAULT;

        allowedModes = iniparser_getint(dict, "general:allowedmodes", (CONN_MODE1 | CONN_MODE2));

        strlcpy(ownIpAddress, iniparser_getstring(dict, "general:ownipaddress", "0.0.0.0"), MY_TMP_BUF_LEN);

        strlcpy(runAsUser, iniparser_getstring(dict, "general:runasuser", "uvncrep"), MY_TMP_BUF_LEN);

        loggingLevel = iniparser_getint(dict, "general:logginglevel", DEFAULT_LOGGING_LEVEL);
        if (loggingLevel > LEVEL_3)
            loggingLevel = DEFAULT_LOGGING_LEVEL;
        if (loggingLevel < LEVEL_0)
            loggingLevel = DEFAULT_LOGGING_LEVEL;


        /* Mode 1 settings */
        /* Mode 1 settings */
        allowedMode1ServerPort = iniparser_getint(dict, "mode1:allowedmode1serverport", 0);
        requireListedServer = iniparser_getint(dict, "mode1:requirelistedserver", 0);
        if (requireListedServer == 1) {
            /* Allowed servers */
            for(ii = 0; ii < SERVERS_LIST_SIZE; ii++) {
                snprintf(tmpBuf, MY_TMP_BUF_LEN, "%s%d", "mode1:srvListAllow", ii);

                strlcpy(tmpBuf2, iniparser_getstring(dict, tmpBuf, "255.255.255.255"), MY_TMP_BUF_LEN);

                inet46_pton(tmpBuf2, &srvListAllow[ii]);
            }


            /* Denied servers */
            for(ii = 0; ii < SERVERS_LIST_SIZE; ii++) {
                snprintf(tmpBuf, MY_TMP_BUF_LEN, "%s%d", "mode1:srvListDeny", ii);

                strlcpy(tmpBuf2, iniparser_getstring(dict, tmpBuf, "255.255.255.255"), MY_TMP_BUF_LEN);

                inet46_pton(tmpBuf2, &srvListDeny[ii]);
            }
        }


        /* Mode 2 settings */
        /* Mode 2 settings */
        requireListedId = iniparser_getint(dict, "mode2:requirelistedid", 0);
        if (requireListedId == 1) {
            for(ii = 0; ii < ID_LIST_SIZE; ii++) {
                snprintf(tmpBuf, MY_TMP_BUF_LEN, "%s%d", "mode2:idlist", ii);
                idList[ii] = iniparser_getint(dict, tmpBuf, 0);
            }
        }

        /* Event interface settings */
        /* Event interface settings */
        useEventInterface = (bool) iniparser_getboolean(dict, "eventinterface:useeventinterface", 0);

        strlcpy(eventListenerHost, iniparser_getstring(dict,
            "eventinterface:eventlistenerhost", "localhost"), MY_TMP_BUF_LEN);

        eventListenerPort = iniparser_getint(dict, "eventinterface:eventlistenerport", 2002);

        useHttpForEventListener = (bool) iniparser_getboolean(dict,"eventinterface:usehttp", 0);

        iniparser_free(dict);
        return true;
    }
    else
        return false;

    return true;
}