Пример #1
0
void dll_func2()
{
	int i=numdlls;
	char* dir=NULL;

	n_externs=0;
	
	for(i=0;i<numdlls;i++)
		nuevo_orden[i]=i;

	for(numdlls=0;numdlls<i;numdlls++) {
		if((dlls[numdlls].prioridad>P_NUNCA) && (dlls[numdlls].usado || dlls[numdlls].prioridad>=P_SIEMPRE)) {
			#ifdef _DEBUG
				printf("dbg: Se requiere %s (id=%d)\n",dlls[numdlls].nombre,numdlls);
			#endif
			#ifdef _WIN32
				if(ini) dir=iniparser_getstr(ini,"dll:windll");
				if(!dir) dir="dll";
				sprintf(fichdll,"%s\\%s.dll",dir,dlls[numdlls].nombre);
			#else
				if(ini) dir=iniparser_getstr(ini,"dll:nixdll");
				if(!dir) dir="so";
				sprintf(fichdll,"%s/%s.so",dir,dlls[numdlls].nombre);
			#endif

			if(leedll()) {
				printf(translate(45),dlls[numdlls].nombre); /* error al cargar libreria */
				exit(1);
			}
		}
	}
}
Пример #2
0
int DDE::EnumFileAssocations(dictionary* ini, bool isRegister, int (*CallbackFunc)(DDEInfo&))
{
	// For the moment just register all
	char key[MAX_PATH];
	int res = 0;
	for(int i = 1;; i++) {
		DDEInfo info;
		info.ini = ini;

		sprintf(key, "FileAssociations:file.%d.extension", i);
		info.extension = iniparser_getstr(ini, key);
		if(info.extension == NULL) break;

		Log::Info(isRegister ? "Registering %s" : "Unregistering %s", info.extension);

		sprintf(key, "FileAssociations:file.%d.name", i);
		info.name = iniparser_getstr(ini, key);
		if(info.name == NULL) {
			Log::Error("Name not specified for extension: %s", info.extension);
			return 1;
		}

		sprintf(key, "FileAssociations:file.%d.description", i);
		info.description = iniparser_getstr(ini, key);
		if(info.description == NULL) {
			Log::Warning("Description not specified for extension: %s", info.extension);
		}

		if(res = CallbackFunc(info))
			return res;
	}

	return res;
}
Пример #3
0
void set_config( void *self, dictionary *config )
{
  debug("reading configuration file options");
  if (config) {
    cim_namespace = iniparser_getstr (config, "cim:default_cim_namespace");
    char *namespaces = iniparser_getstr (config, "cim:vendor_namespaces");
    cim_host = iniparser_getstring(config, "cim:host", "localhost");
    cim_client_frontend = iniparser_getstring(config, "cim:cim_client_frontend", "XML");
    cim_port = iniparser_getstring(config, "cim:port", DEFAULT_HTTP_CIMOM_PORT);
    server_port = iniparser_getstring(config, "server:port", server_port);
    cim_ssl = iniparser_getboolean(config, "cim:ssl", 0);
    cim_trust_store = iniparser_getstring(config, "cim:trust_store", "/etc/ssl/certs");
    cim_verify = iniparser_getboolean(config, "cim:verify_cert", 0);
    omit_schema_optional = iniparser_getboolean(config, "cim:omit_schema_optional", 0);
    indication_profile_implementation_ns = iniparser_getstring(config, "cim:indication_profile_implementation_ns", "root/interop");
    debug("vendor namespaces: %s", namespaces);
    if (namespaces) {
      hash_t * t = u_parse_query(namespaces);
      if (t) {
        vendor_namespaces = t;
      }
      else
        vendor_namespaces = NULL;
    }
    debug("cim namespace: %s", cim_namespace);
  }
  return;
}
Пример #4
0
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
	if(fdwReason == DLL_PROCESS_ATTACH) {
		// Store reference to handle for later use
		g_hinstance = hinstDLL;

		// Initialise the logger using std streams
		Log::Init(hinstDLL, NULL, NULL, NULL);

		// Load our (optional) ini file
		g_ini = INI::LoadIniFile(hinstDLL);

		// Init error message
		g_errorMessage.xltype = xltypeStr;
		g_errorMessage.val.str = XLUtil::MakeExcelString("#Unknown function");

		// Read config
		g_sendCallerInfo = iniparser_getboolean(g_ini, FS_SEND_CALLER_INFO, 0) != 0;

		// Initialise the log
		Log::Init(hinstDLL, iniparser_getstr(g_ini, LOG_FILE), iniparser_getstr(g_ini, LOG_LEVEL), g_ini);
		g_debugLogging = Log::GetLevel() == debug;

		// Initialise timeout feature
		Timeout::Initialise(hinstDLL, g_ini);
	} 

	// OK
	return TRUE;
}
Пример #5
0
__declspec(dllexport) LPXLOPER WINAPI xlAddInManagerInfo(LPXLOPER xAction)
{
	static XLOPER xInfo, xIntAction, xIntType;
	xIntType.xltype = xltypeInt;
	xIntType.val.w = xltypeInt;
	xInfo.xltype = xltypeErr;
	xInfo.val.err = xlerrValue;

	Excel4(xlCoerce, &xIntAction, 2, xAction, &xIntType);

	// Set addin name
	if(xIntAction.val.w == 1) {
		LPXLOPER x = (LPXLOPER) malloc(sizeof(XLOPER));
		x->xltype = xltypeStr | xlbitDLLFree;
		char* addinName = iniparser_getstr(g_ini, FS_ADDIN_NAME);
		if(addinName == NULL) {
			char filename[MAX_PATH];
			char name[MAX_PATH];
			GetModuleFileName(g_hinstance, filename, MAX_PATH);
			GetFileNameSansExtension(filename, name);
#ifdef DEBUG_LOG
			strcat(name, " (Debug)");
#endif
			addinName = XLUtil::MakeExcelString(name);
		} else {
			addinName = XLUtil::MakeExcelString(addinName);
		}
		x->val.str = addinName;
		return x;
	} 

	return (LPXLOPER) &xInfo;
}
Пример #6
0
/*
 * Sends a message to the server to indicate a new session has been created
 */
void InitializeSession(int index)
{
	bool sendUserInfo = iniparser_getboolean(g_ini, FS_SEND_USER_INFO, 1) != 0;
	if(sendUserInfo) {
		char username[MAX_PATH];
		DWORD usize= MAX_PATH;
		GetUserName(username, &usize);
		LPXLOPER uname = XLUtil::MakeExcelString2(username);
		gethostname(username, MAX_PATH);
		LPXLOPER hostname = XLUtil::MakeExcelString2(username);
		char* userKey = iniparser_getstr(g_ini, FS_USER_KEY);
		if(userKey) {
			LPXLOPER ukey = XLUtil::MakeExcelString2(userKey);
			g_protocol[index]->execute(AF_INITIALIZE, false, 3, uname, hostname, ukey);
			XLUtil::FreeContents(ukey);
			free(ukey);
		} else {
			g_protocol[index]->execute(AF_INITIALIZE, false, 2, uname, hostname);
		}
		XLUtil::FreeContents(uname);
		XLUtil::FreeContents(hostname);
		free(uname);
		free(hostname);
	}
}
Пример #7
0
DWORD WINAPI DdeWindowThreadProc(LPVOID lpParam)
{
	// Register Window
	DDE::RegisterWindow((HINSTANCE) lpParam);

	bool initDde = DDE::RegisterDDE();
	if(!initDde)
		return 1;

	char* clsName = iniparser_getstr(g_ini, DDE_WINDOW_CLASS);

	// Create window
	g_hWnd = CreateWindowEx(
		0,
		clsName == NULL ? "WinRun4J.DDEWndClass" : clsName,
		"WinRun4J.DDEWindow",
		0,
		0, 0,
		0, 0,
		NULL, NULL, NULL, NULL);

	// Listen for messages
	MSG msg;
	while (GetMessage (&msg, NULL, 0, 0))
	{
		TranslateMessage (&msg);
		DispatchMessage (&msg);
	}

	return 0;
}
Пример #8
0
bool DDE::RegisterNatives(JNIEnv* env, dictionary* ini)
{
	char* ddeClassName = iniparser_getstr(ini, DDE_CLASS);
	if(ddeClassName != NULL) {
		int strl = strlen(ddeClassName);
		for(int i = 0; i < strl; i++) {
			if(ddeClassName[i] == '.')
				ddeClassName[i] = '/';
		}
		g_class = JNI::FindClass(env, ddeClassName);
	} else {
		g_class = JNI::FindClass(env, "org/boris/winrun4j/DDE");
	}
	if(g_class == NULL) {
		Log::Error("Could not find DDE class.");
		if(env->ExceptionCheck()) env->ExceptionClear();
		return false;
	}
	// Global ref in case of garbage collection
	g_class = (jclass) env->NewGlobalRef(g_class);

	g_executeMethodID = env->GetStaticMethodID(g_class, "execute", "(Ljava/lang/String;)V");
	if(g_executeMethodID == NULL) {
		Log::Error("Could not find execute method");
		if(env->ExceptionCheck()) env->ExceptionClear();
		return false;
	}

	g_activateMethodID = env->GetStaticMethodID(g_class, "activate", "(Ljava/lang/String;)V");
	if(env->ExceptionCheck()) {
		env->ExceptionClear();
	}

	return true;
}
Пример #9
0
void WinRun4J::SetProcessPriority(dictionary* ini)
{
	char* priority = iniparser_getstr(ini, PROCESS_PRIORITY);
	if(!priority) 
		return;

	int p = -1;
	if(strcmp("idle", priority) == 0) {
		p = IDLE_PRIORITY_CLASS;
	} else if(strcmp("below_normal", priority) == 0) {
		p = BELOW_NORMAL_PRIORITY_CLASS;
	} else if(strcmp("normal", priority) == 0) {
		p = NORMAL_PRIORITY_CLASS;
	} else if(strcmp("above_normal", priority) == 0) {
		p = ABOVE_NORMAL_PRIORITY_CLASS;
	} else if(strcmp("high", priority) == 0) {
		p = HIGH_PRIORITY_CLASS;
	} else if(strcmp("realtime", priority) == 0) {
		p = REALTIME_PRIORITY_CLASS;
	} else {
		Log::Warning("Invalid process priority class: %s", priority);
	}

	if(p != -1) {
		SetPriorityClass(GetCurrentProcess(), p);
	}
}
Пример #10
0
// We expect the commandline to be "--WinRun4J:UnregisterService"
int Service::Unregister(dictionary* ini)
{
	Log::Info("Unregistering Service...");

	const char* serviceId = iniparser_getstr(ini, SERVICE_ID);
	if (serviceId == NULL) {
		Log::Error("Service ID not specified");
		return 1;
	}

	SC_HANDLE h = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
	if (!h) {
		DWORD error = GetLastError();
		Log::Error("Could not access service manager: %d", error);
		return error;
	}
	SC_HANDLE s = OpenService(h, serviceId, SC_MANAGER_ALL_ACCESS);
	if (!s) {
		DWORD error = GetLastError();
		Log::Error("Could not open service: %d", error);
		return error;
	}

	return DeleteService(s) == 0;
}
Пример #11
0
double iniparser_getdouble(dictionary * d, char * key, double notfound)
{
	char	*	str ;

	str = iniparser_getstr(d, key);
	if (str==NULL) return notfound ;
	return atof(str);
}
Пример #12
0
int iniparser_getint(dictionary * d, char * key, int notfound)
{
	char	*	str ;

	str = iniparser_getstr(d, key);
	if (str==NULL) return notfound ;
	return atoi(str);
}
Пример #13
0
int wsmand_read_config(dictionary * ini)
{
	if (!iniparser_find_entry(ini, "server")) {
		return 0;
	}

	server_port = iniparser_getint(ini, "server:port", 5985);
	server_ssl_port = iniparser_getint(ini, "server:ssl_port", 5986);
	debug_level = iniparser_getint(ini, "server:debug_level", 0);
	enumIdleTimeout =
	    (unsigned long) iniparser_getint(ini,
					     "server:enum_idle_timeout",
					     100);
	service_path =
	    iniparser_getstring(ini, "server:service_path", "/wsman");
	ssl_key_file = iniparser_getstr(ini, "server:ssl_key_file");
	ssl_cert_file = iniparser_getstr(ini, "server:ssl_cert_file");
	use_ipv4 = iniparser_getboolean(ini, "server:ipv4", 1);
#ifdef ENABLE_IPV6
        use_ipv6 = iniparser_getboolean(ini, "server:ipv6", 1);
        if (! (use_ipv4 || use_ipv6)) {
		fprintf(stderr, "Neither ipv4 nor ipv6 is enabled in openwsman.conf !\n");
		exit(1);
	}
#endif
	use_digest = iniparser_getboolean(ini, "server:use_digest", 0);
	digest_password_file = iniparser_getstr(ini,
						"server:digest_password_file");
	basic_password_file =
	    iniparser_getstr(ini, "server:basic_password_file");
	custom_identify_file =
	    iniparser_getstr(ini, "server:identify_file");
	custom_anon_identify_file =
	    iniparser_getstr(ini, "server:anon_identify_file");
	basic_authenticator =
	    iniparser_getstr(ini, "server:basic_authenticator");
	basic_authenticator_arg =
	    iniparser_getstr(ini, "server:basic_authenticator_arg");
	log_location = iniparser_getstr(ini, "server:log_location");
	min_threads = iniparser_getint(ini, "server:min_threads", 1);
	max_threads = iniparser_getint(ini, "server:max_threads", 0);
	uri_subscription_repository = iniparser_getstring(ini, "server:subs_repository", DEFAULT_SUBSCRIPTION_REPOSITORY);
        max_connections_per_thread = iniparser_getint(ini, "server:max_connextions_per_thread", 20);
        thread_stack_size = iniparser_getstring(ini, "server:thread_stack_size", "0");
#ifdef ENABLE_EVENTING_SUPPORT
	wsman_server_set_subscription_repos(uri_subscription_repository);
#endif
	return 1;
}
Пример #14
0
bool DDE::RegisterDDE()
{
	// Startup DDE library
	UINT result = DdeInitialize(&g_pidInst, (PFNCALLBACK) &DdeCallback, 0, 0);
	if(result != DMLERR_NO_ERROR) {
		Log::Error("Unable to initialize DDE: %d", result);
		return false;
	}

	// Check for app/topic override
	char* appName = iniparser_getstr(g_ini, DDE_SERVER_NAME);
	char* topic = iniparser_getstr(g_ini, DDE_TOPIC);

	g_serverName = DdeCreateStringHandle(g_pidInst, appName == NULL ? "WinRun4J" : appName, CP_WINANSI);
	g_topic = DdeCreateStringHandle(g_pidInst, topic == NULL ? "system" : topic, CP_WINANSI);

	// Register the server
	DdeNameService(g_pidInst, g_serverName, NULL, DNS_REGISTER);
	return true;
}
Пример #15
0
void WinRun4J::SetWorkingDirectory(dictionary* ini)
{
	if(workingDirectorySet) 
		return;
	char* dir = iniparser_getstr(ini, WORKING_DIR);
	if(dir != NULL) {
		// First set the current directory to the module (or ini) directory
		SetCurrentDirectory(iniparser_getstr(ini, INI_DIR));

		// Now set working directory to specified (this allows for a relative working directory)
		SetCurrentDirectory(dir);

		// Inform the user of the absolute path
		if(Log::GetLevel() == info) {
			char temp[MAX_PATH];
			GetCurrentDirectory(MAX_PATH, temp);
			Log::Info("Working directory set to: %s", temp);
		}
	} 
	workingDirectorySet = true;
}
Пример #16
0
void network_print_init(debugger_t *debugger)
{
#define MAX_NETWORK_INIT_BUF_LEN 20
	int sd;
	struct sockaddr_in *raddr;
	debug_network_prive_t *net_priv = &debugger->priv.net;
	dictionary *d = debugger->d;;
	char *ip;
	uint32_t default_dbg_port = 10276;
	char buf[MAX_NETWORK_INIT_BUF_LEN];
	char default_dbg_ip[] = "127.0.0.1";

	net_priv->port = iniparser_getint(d, (char *)"network:debug_port",default_dbg_port);
	ip = iniparser_getstr(d, (char *)"network:debug_ip");
	if(ip == NULL){
		/*
		 *memcpy(debug_ip,get_ipaddr(),strlen(get_ipaddr()));
		 */
		dbg_str(DBG_ERROR,"iniparser_getstr err");
		memcpy(net_priv->ip_str,default_dbg_ip,strlen(default_dbg_ip));
		iniparser_setstr(d, (char *)"network", NULL); 
		debug_string_itoa(default_dbg_port,buf,10);
		iniparser_setstr(d, (char *)"network:debug_port",buf);
		iniparser_setstr(d, (char *)"network:debug_ip", net_priv->ip_str);

		FILE *f = fopen(debugger->ini_file_name, "w");
		iniparser_dump_ini(d, f);
		fclose(f);
	}
	else 
		memcpy(net_priv->ip_str,ip,strlen(ip));

	sd = socket(AF_INET,SOCK_DGRAM,0);
	if(sd <0){
		printf("create socket\n");
		exit(1);
	}   
	int val=1;
	if(setsockopt(sd,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(val))<0){
		printf("setsocgketopt error\n");
		exit(1);
	}      
	pthread_mutex_init(&debugger->priv.net.send_dgram_lock,NULL);
	debugger->priv.net.sd = sd;

	raddr = &debugger->priv.net.raddr;
	raddr->sin_family = AF_INET;
	raddr->sin_port = htons(net_priv->port);
	inet_pton(AF_INET,net_priv->ip_str,&raddr->sin_addr);
#undef MAX_NETWORK_INIT_BUF_LEN 
}
Пример #17
0
/* Initialize from ini file */
int sbase_initialize(SBASE *sbase, char *conf)
{
	char *p = NULL, *cacert_file = NULL, *privkey_file = NULL;

	if((dict = iniparser_new(conf)) == NULL)
	{
		fprintf(stderr, "Initializing conf:%s failed, %s\n", conf, strerror(errno));
		_exit(-1);
	}
	/* SBASE */
	sbase->nchilds = iniparser_getint(dict, "SBASE:nchilds", 0);
	sbase->connections_limit = iniparser_getint(dict, "SBASE:connections_limit", SB_CONN_MAX);
	sbase->usec_sleep = iniparser_getint(dict, "SBASE:usec_sleep", SB_USEC_SLEEP);
	sbase->set_log(sbase, iniparser_getstr(dict, "SBASE:logfile"));
	sbase->set_log_level(sbase, iniparser_getint(dict, "SBASE:log_level", 2));
	sbase->set_evlog(sbase, iniparser_getstr(dict, "SBASE:evlogfile"));
	/* NOWD */
	if((nowd = service_init()) == NULL)
	{
		fprintf(stderr, "Initialize service failed, %s", strerror(errno));
		_exit(-1);
	}
	nowd->family = iniparser_getint(dict, "NOWD:inet_family", AF_INET);
	nowd->sock_type = iniparser_getint(dict, "NOWD:socket_type", SOCK_STREAM);
	nowd->ip = iniparser_getstr(dict, "NOWD:service_ip");
	nowd->port = iniparser_getint(dict, "NOWD:service_port", 80);
	nowd->working_mode = iniparser_getint(dict, "NOWD:working_mode", WORKING_PROC);
	nowd->service_type = iniparser_getint(dict, "NOWD:service_type", S_SERVICE);
	nowd->service_name = iniparser_getstr(dict, "NOWD:service_name");
	nowd->nprocthreads = iniparser_getint(dict, "NOWD:nprocthreads", 8);
	nowd->niodaemons = iniparser_getint(dict, "NOWD:niodaemons", 1);
	nowd->ndaemons = iniparser_getint(dict, "NOWD:ndaemons", 0);
	nowd->session.packet_type=iniparser_getint(dict, "NOWD:packet_type", PACKET_PROXY);
	nowd->session.buffer_size = iniparser_getint(dict, "NOWD:buffer_size", SB_BUF_SIZE);
	nowd->session.welcome_handler = &nowd_welcome_handler;
	nowd->session.exchange_handler = &nowd_exchange_handler;
	cacert_file = iniparser_getstr(dict, "NOWD:cacert_file");
	privkey_file = iniparser_getstr(dict, "NOWD:privkey_file");
	if(cacert_file && privkey_file && iniparser_getint(dict, "NOWD:is_use_SSL", 0))
	{
		nowd->is_use_SSL = 1;
		nowd->cacert_file = cacert_file;
		nowd->privkey_file = privkey_file;
	}
	if((p = iniparser_getstr(dict, "NOWD:logfile")))
	{
		nowd->set_log(nowd, p);
		nowd->set_log_level(nowd, iniparser_getint(dict, "NOWD:log_level", 0));
	}
	/* server */
	fprintf(stdout, "Parsing for server...\n");
	return sbase->add_service(sbase, nowd);
}
Пример #18
0
bool DDE::NotifySingleInstance(dictionary* ini)
{
	g_ini = ini;

	// Startup DDE library
	UINT result = DdeInitialize(&g_pidInst, (PFNCALLBACK) &DdeCallback, 0, 0);
	if(result != DMLERR_NO_ERROR) {
		Log::Error("Unable to initialize DDE: %d", result);
		return false;
	}

	// Check for app/topic override
	char* appName = iniparser_getstr(g_ini, DDE_SERVER_NAME);
	char* topic = iniparser_getstr(g_ini, DDE_TOPIC);

	g_serverName = DdeCreateStringHandle(g_pidInst, appName == NULL ? "WinRun4J" : appName, CP_WINANSI);
	g_topic = DdeCreateStringHandle(g_pidInst, topic == NULL ? "system" : topic, CP_WINANSI);

	HCONV conv = DdeConnect(g_pidInst, g_serverName, g_topic, NULL);
	if (conv != NULL) {
		LPSTR cmdline = StripArg0(GetCommandLine());
		char* activate = (char*) malloc(strlen(DDE_EXECUTE_ACTIVATE) + strlen(cmdline) + 2);
		strcpy(activate, DDE_EXECUTE_ACTIVATE);
		strcat(activate, " ");
		strcat(activate, cmdline);
		HDDEDATA result = DdeClientTransaction((LPBYTE)activate, strlen(activate) + 1, conv, NULL, 0, XTYP_EXECUTE, TIMEOUT_ASYNC, NULL);
		if (result == 0) {
			Log::Error("Failed to send DDE single instance notification");
			return false;
		}
	} else{
		Log::Error("Unable to create DDE conversation");
	}

	DDE::Uninitialize();
	return true;
}
Пример #19
0
bool LauncherSettings::load()
{
	dictionary *ini = iniparser_load(const_cast<char*>(INI_MAIN));
	if (ini == NULL)
		return false;

	iniparser_dump(ini, stderr);

	// read ini variables
	char *exe_filepath = iniparser_getstr(ini, "launcher:exe_filepath");
	char *active_mod = iniparser_getstr(ini, "launcher:active_mod");
	bool showed_pilot_warning = (iniparser_getboolean(ini, "launcher:showed_pilot_warning", 0) != 0);

	if (exe_filepath == NULL || active_mod == NULL)
		return false;

	// atomically assign all ini variables
	set_exe_filepath(exe_filepath);
	set_active_mod(active_mod);
	m_showed_pilot_warning = showed_pilot_warning;

	iniparser_freedict(ini);
	return true;
}
Пример #20
0
int iniparser_getboolean(dictionary * d, char * key, int notfound)
{
	char	*	c ;
	int			ret ;

	c = iniparser_getstr(d, key);
	if (c==NULL) return notfound ;
    if (c[0]=='y' || c[0]=='Y' || c[0]=='1' || c[0]=='t' || c[0]=='T') {
        ret = 1 ;
    } else if (c[0]=='n' || c[0]=='N' || c[0]=='0' || c[0]=='f' || c[0]=='F') {
        ret = 0 ;
    } else {
        ret = notfound ;
    }
    return ret;
}
Пример #21
0
void INI::GetNumberedKeysFromIni(dictionary* ini, TCHAR* keyName, TCHAR** entries, UINT& index)
{
	UINT i = 0;
	TCHAR entryName[MAX_PATH];
	while(true) {
		sprintf(entryName, "%s.%d", keyName, i+1);
		TCHAR* entry = iniparser_getstr(ini, entryName);
		if(entry != NULL) {
			entries[index++] = _strdup(entry);
		}
		i++;
		if(i > 10 && entry == NULL) {
			break;
		}
	}
	entries[index] = NULL;
}
Пример #22
0
bool DDE::Initialize(HINSTANCE hInstance, JNIEnv* env, dictionary* ini)
{
	// Check for enabled flag
	char* ddeEnabled = iniparser_getstr(ini, DDE_ENABLED);
	if(ddeEnabled == NULL || strcmp("true", ddeEnabled) != 0)
		return false;

	// Store ini file reference
	Log::Info("Initializing DDE");
	g_ini = ini;

	// Attach JNI methods
	if (!RegisterNatives(env, ini))
		return false;

	// Create Thread to manage the window
	CreateThread(0, 0, DdeWindowThreadProc, (LPVOID) hInstance, 0, 0);
	return true;
}
Пример #23
0
void DDE::RegisterWindow(HINSTANCE hInstance)
{
	// Create window class for DDE
	WNDCLASSEX wcx;
	wcx.cbSize = sizeof(wcx);
	wcx.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW;
	wcx.lpfnWndProc = DdeMainWndProc;
	wcx.cbClsExtra = 0;
	wcx.cbWndExtra = DLGWINDOWEXTRA;
	wcx.hInstance = hInstance;
	wcx.hIcon = 0;
	wcx.hCursor = LoadCursor(NULL, IDC_WAIT);
	wcx.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
	wcx.lpszMenuName = 0;
	char* clsName = iniparser_getstr(g_ini, DDE_WINDOW_CLASS);
	wcx.lpszClassName = clsName == NULL ? "WinRun4J.DDEWndClass" : clsName;
	wcx.hIconSm = 0;

	if(!RegisterClassEx(&wcx)) {
		Log::Error("Could not register DDE window class");
		return;
	}
}
Пример #24
0
/*init socket*/
void log_print_init(debugger_t *debugger)
{
	debug_log_prive_t *log_priv = &debugger->priv.log;
	FILE *fp;
	dictionary *d = debugger->d;;
	char *file_name;
	char default_log_name[] = "dbg_log.txt";

	printf("debug log init\n");
	file_name = iniparser_getstr(d, (char *)"log:log_file_name");
	if(file_name){
		memcpy(log_priv->log_file_name,file_name,strlen(file_name));
	}else{
		memcpy(log_priv->log_file_name,default_log_name,strlen(default_log_name));
		iniparser_setstr(d, (char *)"Log", NULL); 
		iniparser_setstr(d, (char *)"Log:log_file_name",log_priv->log_file_name);

		FILE *f = fopen(debugger->ini_file_name, "w");
		iniparser_dump_ini(d, f);
		fclose(f);
	}

	fp = fopen(log_priv->log_file_name,"ab+");
	if(fp == NULL)
	{
		perror("log file fopen()");
		exit(1);
	}
	log_priv->fp = fp;

	/*
	 *pthread_mutex_init(&log_priv->log_file_lock,NULL);
	 */
	printf("run at here.\n");
	sync_lock_init(&log_priv->log_file_lock,debugger->lock_type);
	printf("debug log init end\n");
}
Пример #25
0
bool ModSettings::load_user_fso()
{
	char ini_name[MAX_PATH];
	sprintf(ini_name, "%s\\%s\\%s", LauncherSettings::get_exe_pathonly(), LauncherSettings::get_active_mod(), const_cast<char*>(INI_MOD_CUSTOM));

	dictionary *ini = iniparser_load(ini_name);
	if (ini == NULL)
		return false;

	iniparser_dump(ini, stderr);

	// read ini variables
	char *standard_params = iniparser_getstr(ini, "settings:flags");

	if (standard_params == NULL)
		return false;

	// atomically assign all ini variables
	strcpy(m_standard_params, standard_params);
	strcpy(m_custom_params, "");

	iniparser_freedict(ini);
	return true;
}
Пример #26
0
int Shell::CheckSingleInstance(dictionary* ini)
{
	char* singleInstance = iniparser_getstr(ini, SINGLE_INSTANCE_OPTION);
	if(singleInstance == NULL) {
		return 0;
	}

	// Check for single instance mode
	bool processOnly = true;
	bool dde = false;

	if(strcmp(singleInstance, "window") == 0)
		processOnly = false;
	else if (strcmp(singleInstance, "dde") == 0) {
		processOnly = false;
		dde = true;
	} else if(strcmp(singleInstance, "process") != 0) {		
		Log::Warning("Invalid single instance mode: %s", singleInstance);
		return 0;
	}

	char thisModule[MAX_PATH];
	DWORD thisProcessId = GetCurrentProcessId();
	GetModuleFileName(0, thisModule, MAX_PATH);
	HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	PROCESSENTRY32 e;
	e.dwSize = sizeof(PROCESSENTRY32);
	char otherModule[MAX_PATH];

	if(Process32First(h, &e)) {
		HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,	FALSE, e.th32ProcessID);
		GetModuleFileNameEx(hProcess, 0, otherModule, MAX_PATH);
		CloseHandle(hProcess);
		if(thisProcessId != e.th32ProcessID && strcmp(thisModule, otherModule) == 0) {
			if (dde && DDE::NotifySingleInstance(ini)) {
				Log::Warning("Single Instance Shutdown");
				return 1;
			}
			if(processOnly) {
				Log::Warning("Single Instance Shutdown");
				return 1;
			}
			return !EnumWindows(EnumWindowsProcSingleInstance, e.th32ProcessID);
		}
		while(Process32Next(h, &e)) {
			HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, e.th32ProcessID);
			GetModuleFileNameEx(hProcess, 0, otherModule, MAX_PATH);
			CloseHandle(hProcess);
			if(thisProcessId != e.th32ProcessID && strcmp(thisModule, otherModule) == 0) {
				if (dde && DDE::NotifySingleInstance(ini)) {
					Log::Warning("Single Instance Shutdown");
					return 1;
				}
				if(processOnly) {
					Log::Warning("Single Instance Shutdown");
					return 1;
				}
				return !EnumWindows(EnumWindowsProcSingleInstance, e.th32ProcessID);
			}
		}
	} 

	return 0;
}
Пример #27
0
dictionary* INI::LoadIniFile(HINSTANCE hInstance, LPSTR inifile)
{
	dictionary* ini = NULL;

	// First attempt to load INI from exe
	HRSRC hi = FindResource(hInstance, MAKEINTRESOURCE(1), RT_INI_FILE);
	if(hi) {
		HGLOBAL hg = LoadResource(hInstance, hi);
		PBYTE pb = (PBYTE) LockResource(hg);
		DWORD* pd = (DWORD*) pb;
		if(*pd == INI_RES_MAGIC) {
			ini = iniparser_load((char *) &pb[RES_MAGIC_SIZE], true);	
			if(!ini) {
				Log::Warning("Could not load embedded INI file");
			}
		}
	}

	// Check if we have already loaded an embedded INI file - if so 
	// then we only need to load and merge the INI file (if present)
	if(ini && iniparser_getboolean(ini, ALLOW_INI_OVERRIDE, 1)) {
		dictionary* ini2 = iniparser_load(inifile);
		if(ini2) {
			for(int i = 0; i < ini2->n; i++) {
				char* key = ini2->key[i];
				char* value = ini2->val[i];
				iniparser_setstr(ini, key, value);
			}		
			iniparser_freedict(ini2);
		}
	} else if(!ini) {
		ini = iniparser_load(inifile);
		if(ini == NULL) {
			Log::Error("Could not load INI file: %s", inifile);
			return NULL;
		}
	}

	// Expand environment variables
	ExpandVariables(ini);

	// Now check if we have an external file to load
	char* iniFileLocation = iniparser_getstr(ini, INI_FILE_LOCATION);
	if(iniFileLocation) {
		Log::Info("Loading INI keys from file location: %s", iniFileLocation);
		dictionary* ini3 = iniparser_load(iniFileLocation);
		if(ini3) {
			for(int i = 0; i < ini3->n; i++) {
				char* key = ini3->key[i];
				char* value = ini3->val[i];
				iniparser_setstr(ini, key, value);
			}		
			iniparser_freedict(ini3);
		} else {
			Log::Warning("Could not load INI keys from file: %s", iniFileLocation);
		}
	}

	// Attempt to parse registry location to include keys if present
	ParseRegistryKeys(ini);

	iniparser_setstr(ini, MODULE_INI, inifile);

	// Add module name to ini
	TCHAR filename[MAX_PATH], filedir[MAX_PATH];
	GetModuleFileName(hInstance, filename, MAX_PATH);
	iniparser_setstr(ini, MODULE_NAME, filename);

	// strip off filename to get module directory
	GetFileDirectory(filename, filedir);
	iniparser_setstr(ini, MODULE_DIR, filedir);

	// stip off filename to get ini directory
	GetFileDirectory(inifile, filedir);
	iniparser_setstr(ini, INI_DIR, filedir);

	// Log init
	Log::Init(hInstance, iniparser_getstr(ini, LOG_FILE), iniparser_getstr(ini, LOG_LEVEL), ini);
	Log::Info("Module Name: %s", filename);
	Log::Info("Module INI: %s", inifile);
	Log::Info("Module Dir: %s", filedir);
	Log::Info("INI Dir: %s", filedir);

	// Store a reference to be used by JNI functions
	g_ini = ini;

	return ini;
}
Пример #28
0
extern "C" __declspec(dllexport) const char* __cdecl INI_GetProperty(const char* key)
{
	return iniparser_getstr(g_ini, key);
}
Пример #29
0
void INI::ParseRegistryKeys(dictionary* ini)
{
	// Now check if we have a registry location to load from
	char* iniRegistryLocation = iniparser_getstr(ini, INI_REGISTRY_LOCATION);
	if(!iniRegistryLocation) {
		return;
	}

	Log::Info("Loading INI keys from registry: %s", iniRegistryLocation);

	// find root key
	int len = strlen(iniRegistryLocation);
	int slash = 0;
	while(slash < len && iniRegistryLocation[slash] != '\\')
		slash++;

	if(slash == len) {
		Log::Warning("Unable to parse registry location (%s) - keys not included", iniRegistryLocation);
		return;
	}

	HKEY hKey = 0;
	char* rootKey = strdup(iniRegistryLocation);
	rootKey[slash] = 0;
	if(strcmp(rootKey, "HKEY_LOCAL_MACHINE") == 0) {
		hKey = HKEY_LOCAL_MACHINE;
	} else if(strcmp(rootKey, "HKEY_CURRENT_USER") == 0) {
		hKey = HKEY_CURRENT_USER;
	} else if(strcmp(rootKey, "HKEY_CLASSES_ROOT") == 0) {
		hKey = HKEY_CLASSES_ROOT;
	} else {
		Log::Warning("Unrecognized registry root key: %s", rootKey);
		free(rootKey);
		return;
	}
	free(rootKey);

	HKEY subKey;
	if(RegOpenKeyEx(hKey, &iniRegistryLocation[slash+1], 0, KEY_READ, &subKey) != ERROR_SUCCESS) {
		Log::Warning("Unable to open registry location (%s)", iniRegistryLocation);
		return;
	}

	DWORD index = 0;
	char name[MAX_PATH + 2];
	char data[4096];
	DWORD type;
	DWORD nameLen = MAX_PATH;
	DWORD dataLen = 4096;
	name[0] = ':';
	while(RegEnumValue(subKey, index, &name[1], &nameLen, NULL, &type, (LPBYTE) data, &dataLen) == ERROR_SUCCESS) {
		bool hasNamespace = StrContains(&name[1], ':');
		char* key = hasNamespace ? &name[1] : name;
		if(type == REG_DWORD) {
			DWORD val = *((LPDWORD)data);
			sprintf(data, "%d", val);
			iniparser_setstr(ini, key, data);
		} else if(type == REG_SZ && dataLen > 1) {
			iniparser_setstr(ini, key, data);
		}
		nameLen = MAX_PATH;
		dataLen = 4096;
		index++;
	}
}
Пример #30
0
// We expect the commandline to be "--WinRun4J:RegisterService"
int Service::Register(dictionary* ini)
{
	Log::Info("Registering Service...");

	g_serviceId = iniparser_getstr(ini, SERVICE_ID);
	if (g_serviceId == NULL) {
		Log::Error("Service ID not specified");
		return 1;
	}

	// Grab service name
	char* name = iniparser_getstr(ini, SERVICE_NAME);
	if (!name) {
		Log::Error("Service name not specified");
		return 1;
	}

	// Grab service description
	char* description = iniparser_getstr(ini, SERVICE_DESCRIPTION);
	if (!description) {
		Log::Error("Service description not specified");
		return 1;
	}

	// Check for startup mode override
	DWORD startupMode = SERVICE_DEMAND_START;
	char* startup = iniparser_getstr(ini, SERVICE_STARTUP);
	if (startup != NULL) {
		if (strcmp(startup, "auto") == 0) {
			startupMode = SERVICE_AUTO_START;
			Log::Info("Service startup mode: SERVICE_AUTO_START");
		}
		else if (strcmp(startup, "boot") == 0) {
			startupMode = SERVICE_BOOT_START;
			Log::Info("Service startup mode: SERVICE_BOOT_START");
		}
		else if (strcmp(startup, "demand") == 0) {
			startupMode = SERVICE_DEMAND_START;
			Log::Info("Service startup mode: SERVICE_DEMAND_START");
		}
		else if (strcmp(startup, "disabled") == 0) {
			startupMode = SERVICE_DISABLED;
			Log::Info("Service startup mode: SERVICE_DISABLED");
		}
		else if (strcmp(startup, "system") == 0) {
			startupMode = SERVICE_SYSTEM_START;
			Log::Info("Service startup mode: SERVICE_SYSTEM_START");
		}
		else {
			Log::Warning("Unrecognized service startup mode: %s", startup);
		}
	}

	// Check for dependencies
	TCHAR* dependencies[MAX_PATH];
	UINT depCount = 0;
	INI::GetNumberedKeysFromIni(ini, SERVICE_DEPENDENCY, dependencies, depCount);

	// Make dependency list
	TCHAR* depList = NULL;
	int depListSize = 0;
	for (int i = 0; i < depCount; i++) {
		depListSize += strlen(dependencies[i]) + 1;
	}
	depListSize++;

	if (depListSize > 0) {
		depList = (TCHAR*)malloc(depListSize);
		if (depList == 0) {
			Log::Error("Could not create dependency list");
			return 1;
		}

		TCHAR* depPointer = depList;
		for (int i = 0; i < depCount; i++) {
			strcpy(depPointer, dependencies[i]);
			depPointer += strlen(dependencies[i]) + 1;
		}

		// Add extra NULL at the end of the list
		depPointer[0] = 0;
	}

	char* loadOrderGroup = iniparser_getstr(ini, SERVICE_LOAD_ORDER_GROUP);

	// Check for user account
	char* user = iniparser_getstr(ini, SERVICE_USER);
	char* pwd = iniparser_getstr(ini, SERVICE_PWD);

	TCHAR path[MAX_PATH];
	TCHAR quotePath[MAX_PATH];
	quotePath[0] = '\"';
	quotePath[1] = 0;
	GetModuleFileName(NULL, path, MAX_PATH);
	strcat(quotePath, path);
	strcat(quotePath, "\"");
	SC_HANDLE h = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
	if (!h) {
		DWORD error = GetLastError();
		Log::Error("Could not access service manager: %d", error);
		return error;
	}
	SC_HANDLE s = CreateService(h, g_serviceId, name, SERVICE_ALL_ACCESS,
		SERVICE_WIN32_OWN_PROCESS, startupMode,
		SERVICE_ERROR_NORMAL, quotePath, loadOrderGroup, NULL, (LPCTSTR)depList, user, pwd);
	if (!s) {
		DWORD error = GetLastError();
		if (error == ERROR_SERVICE_EXISTS) {
			Log::Warning("Service already exists");
		}
		else {
			Log::Error("Could not create service: %d", error);
		}
		return error;
	}
	CloseServiceHandle(s);
	CloseServiceHandle(h);

	// Add description 
	strcpy(path, "System\\CurrentControlSet\\Services\\");
	strcat(path, g_serviceId);
	HKEY key;
	RegOpenKey(HKEY_LOCAL_MACHINE, path, &key);
	RegSetValueEx(key, "Description", 0, REG_SZ, (BYTE*)description, strlen(description));

	return 0;
}