コード例 #1
0
/*
 * Thread to lookup the hostname of the client IP address and update
 * the umtp table at login.
 *
 * This is done in a separate thread as it can sometimes take a number
 * of seconds to complete and there's no need to hold up the login for it.
 */
static void *log_utmp_host(void *arg)
{
	char *hostname;
	char host[NI_MAXHOST] = "\0";
	struct addrinfo hints;
	struct addrinfo *res;
	struct utmp_info *ui = (struct utmp_info *)arg;
	MYSQL *db;

	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = AF_UNSPEC;
	getaddrinfo(ui->ip, NULL, &hints, &res);
	getnameinfo(res->ai_addr, res->ai_addrlen, host, NI_MAXHOST, NULL, 0,
			0);

	db = db_conn();
	hostname = make_mysql_safe_string(host);
	sql_query("UPDATE utmp SET hostname = '%s' WHERE sid = %llu",
			hostname, ui->sid);
	mysql_close(db);
	free(hostname);
	free(ui);
	freeaddrinfo(res);

	return NULL;
}
コード例 #2
0
grt::StringRef Db_plugin::apply_script_to_db(grt::GRT *grt)
{
  sql::ConnectionWrapper conn= db_conn()->get_dbc_connection();
  std::auto_ptr<sql::Statement> stmt(conn->createStatement());

  grt->send_info(_("Executing SQL script in server"));
  
  std::list<std::string> statements;
  SqlFacade::Ref sql_splitter= SqlFacade::instance_for_rdbms(selected_rdbms());
  sql_splitter->splitSqlScript(_sql_script, statements);

  sql::SqlBatchExec sql_batch_exec;

  sql_batch_exec.error_cb(boost::bind(&Db_plugin::process_sql_script_error, this, _1, _2, _3));
  sql_batch_exec.batch_exec_progress_cb(boost::bind(&Db_plugin::process_sql_script_progress, this, _1));
  sql_batch_exec.batch_exec_stat_cb(boost::bind(&Db_plugin::process_sql_script_statistics, this, _1, _2));

  sql_batch_exec(stmt.get(), statements);

  return grt::StringRef(_("The SQL script was successfully applied to server"));
}
コード例 #3
0
ファイル: url_handlers.c プロジェクト: ac000/compositus
/*
 * Main application. This is where the requests come in and routed.
 */
void handle_request(void)
{
	bool logged_in = false;
	char *request_uri;
	struct timespec stp;
	struct timespec etp;

	clock_gettime(CLOCK_REALTIME, &stp);

	qvars = NULL;
	avars = NULL;
	u_files = NULL;

	set_env_vars();
	set_vars();
	request_uri = strdupa(env_vars.request_uri);

	/* Initialise the database connection */
	conn = db_conn();
	if (!conn)
		goto out2;

	/*
	 * Some routes need to come before the login / session stuff as
	 * they can't be logged in and have no session.
	 */
	if (match_uri(request_uri, "//")) {
		/* function call goes here */
		goto out2;
	}

	if (match_uri(request_uri, "/login/")) {
		login();
		goto out2;
	}

	logged_in = is_logged_in();
	if (!logged_in) {
		printf("Location: /login/\r\n\r\n");
		goto out2;
	}

	/* Logged in, set-up the user_session structure */
	set_user_session();

	/* Add new url handlers after here */

	if (match_uri(request_uri, "/logout/")) {
		logout();
		goto out;
	}

	/* Default location */
	printf("Location: /login/\r\n\r\n");

out:
	free_user_session();

out2:
	free_vars(qvars);
	free_avars();
	free_u_files();
	clock_gettime(CLOCK_REALTIME, &etp);
	d_fprintf(access_log, "Got request from %s for %s (%s), %ums\n",
			env_vars.remote_addr, request_uri,
			env_vars.request_method,
			(unsigned int)((etp.tv_sec * 1000 +
					etp.tv_nsec / NS_MSEC) -
				(stp.tv_sec * 1000 + stp.tv_nsec / NS_MSEC)));
	free_env_vars();
	mysql_close(conn);
}
コード例 #4
0
ファイル: mmcd_main.c プロジェクト: lanian09/mysource
/**
 *	Implement func.
 */
int main(int argc, char *argv[])
{
	int			dRet, i, loopCnt;
	int			dNmsIndex;
	//st_MsgQ  	stMsg;
	pst_MsgQ	pstMsg;				/* msgq ==> gifo */
	pst_MsgQSub pstMsgQSub;
	int			dWarnOutCnt = 0;	/* 20040923,poopee */
	char		szCommand[64];
    time_t		tCurTime, tCheckTime, tClientCheck, tLastPingMySQL;
	OFFSET		offset;

	SetUpSignal();

	gdStopFlag = 1;
	gdNumfds = 0;
	gdNumWfds = 0;

	log_init(S_SSHM_LOG_LEVEL, getpid(), SEQ_PROC_MMCD, LOG_PATH"/MMCD", "MMCD");

	/*
	AppLogInit(getpid(), SEQ_PROC_MMCD, MMCD_LOG, "MMCD");
	dRet = dInitLogShm();
	if( dRet < 0 )
		exit(dRet);

	dRet = Init_shm_common();
    if(dRet < 0)
    {
        log_print( LOGN_CRI,"MAIN : Failed in Init_shm_common dRet[%d][%s]", dRet, strerror(errno));
        exit(1);

	*/

	if((dRet = get_db_conf(FILE_MYSQL_CONF, szIP, szName, szPass, szAlias)) < 0)
	{
		log_print(LOGN_CRI, "F=%s:%s.%d: ERROR IN get_db_conf() dRet[%d]", __FILE__, __FUNCTION__, __LINE__, dRet);
		exit(-5);
	}

	if((dRet = db_conn(&stMySQL, szIP, szName, szPass, szAlias)) < 0)
	{
			log_print(LOGN_CRI, "F=%s:%s.%d: ERROR IN db_conn() dRet[%d]", __FILE__, __FUNCTION__, __LINE__, dRet);
		exit(-6);
	}

	/*
	if( (dRet = dInitialMysqlEnvironment(&stConnInfo)) < 0)
	{
		log_print(LOGN_CRI, "F=%s:%s.%d: ERROR IN dInitialMysqlEnvironment() dRet[%d]",
			__FILE__, __FUNCTION__, __LINE__, dRet);
		exit(-2);
	}

	if( (dRet = dConnectMySQL(&stMySQL, &stConnInfo)) < 0)
	{
		log_print(LOGN_CRI, "F=%s:%s.%d: ERROR IN dConnectMySQL() dRet[%d]",
			__FILE__, __FUNCTION__, __LINE__, dRet);
		exit(-3);
	}
	*/

	/*
	* INITIALIZE FOR MMC COMMAND
	*/
	dRet = init_mmc_server();
	if( dRet < 0 ) {
		log_print(LOGN_CRI, "[ERROR] INIT_MMC_SERVER RET[%d]\n", dRet );
		FinishProgram();
		exit(0);
	}
	/*
	* INITIALIZE FOR SHARED MEMORY FIDB
	*/
/*
	dRet = Init_Fidb();
    if( dRet < 0 ) {
        log_print(LOGN_CRI,"[ERROR] FIDB INIT [%d]\n", dRet );
        FinishProgram();
        exit(0);
    }
*/

	/*
	* INITIALIZE SOCKET
	*/
	dRet = dTcpSvrModeInit();
	if( dRet < 0 ) {
		FinishProgram();
		exit(0);
	}

	/*
	* INITIALIZE FOR SOCKET CONNECTION TABLE
	*/
	for( i = 0 ; i < MAX_FDSET2	; i++ ) {
		stConTbl[i].dSfd = -1;
		stConTbl[i].uiCliIP = 0;
		stConTbl[i].dBufLen = 0;
        stConTbl[i].szSendBuffer[0] = 0;
        stConTbl[i].cSockBlock = 0x00;
		gstMsgBuf[i].dWidx = 0;
		gstMsgBuf[i].dRidx = 0;
		memset( gstMsgBuf[i].szBuf, 0x00, sizeof(MAX_MNG_PKT_BUFSIZE) );
	}

	/*
	* GET MESSAGE QUEUE ID USING IN MMCD
	*/
    dRet = dInitIPCs();
	if( dRet < 0 ) {
		log_print(LOGN_CRI,"[ERROR] MyQid GET RET[%d]", dRet );
		FinishProgram();
		exit(0);
	}

	/* moved from init_mmc_server() */
	/* CLEAN UP ALL WARN-OUT DATA */
	for(;;) 
	{

/* msgq ==> gifo */
#if 0
		dRet = msgrcv(gdMyQid, &stMsg, sizeof(st_MsgQ) - sizeof(long int), 0, IPC_NOWAIT | MSG_NOERROR);
		if( dRet <= 0) break;
		else dWarnOutCnt++;
#endif
		offset = gifo_read(gpRECVMEMS, pCIFO, SEQ_PROC_MMCD);
		if(offset <= 0)
		{
			usleep(0);
			break;
		}
		else
		{
			dWarnOutCnt++;
			//pstMsg = (pst_MsgQ)nifo_get_value(gpRECVMEMS, DEF_MSGQ_NUM, offset);
			nifo_node_delete(gpRECVMEMS, nifo_ptr(gpRECVMEMS, offset));
		}	
	}
	log_print(LOGN_INFO, "INITIAL MESSAGE QUEUE WARN-OUT COUNT : [%d]", dWarnOutCnt );

	gdIndex = 0;
	dNmsIndex = GetUserInfo("ntasnms", 1 );

	time(&tCurTime);
	tClientCheck = tCheckTime = tCurTime;

	if( (dRet = set_version(S_SSHM_VERSION, SEQ_PROC_MMCD, vERSION)) < 0)
	{
		log_print(LOGN_WARN, "set_version error(ret=%d,idx=%d,ver=%s)\n", dRet, SEQ_PROC_MMCD, vERSION);
	}
	log_print(LOGN_CRI, "MMCD %s Started", vERSION);

	/*
	* MAIN WHILE LOOP
	*/
	while(gdStopFlag)
	{

		loopCnt = 0;
		while(1)
		{
			/* msgq ==> gifo */
			if( (dRet = dIsRcvedMessage(&pstMsg)) > 0)
			{
				pstMsgQSub	= (pst_MsgQSub)&pstMsg->llMType;
				log_print(LOGN_INFO, "RECEIVED MSGQ: Type[%d] SvcID[%d] MsgID[%d] usBodyLen[%d]", pstMsgQSub->usType, pstMsgQSub->usSvcID, pstMsgQSub->usMsgID, pstMsg->usBodyLen);
				if( (pstMsgQSub->usSvcID == SID_PATCH) && (pstMsgQSub->usMsgID == MID_SMNG_START))
				{
					sprintf(szCommand, "/WNTAMAPP/BIN/StartMC -b S_MNG");
					system(szCommand);
					log_print(LOGN_INFO, "S_MNG START MESSAGE GET");
					continue;
				}
				SendToOMP( (dbm_msg_t*)&pstMsg->szBody[0], pstMsg->usBodyLen);
				
				// TODO 제대로 된 코드인지 확인 필요
				nifo_node_delete(gpRECVMEMS, nifo_ptr(gpRECVMEMS, nifo_get_offset_node(gpRECVMEMS, (U8*)pstMsg)));
			}
			else
			{
				usleep(0);
				loopCnt++;
				if( loopCnt > 100 ){
					break;
				}
			}

#if 0
			memset(&stMsg, 0x00, sizeof(st_MsgQ));
			if( (dRet = dIsRcvedMessage(&stMsg)) > 0)
			{
				pstMsgQSub	= (pst_MsgQSub)&stMsg.llMType;
				log_print(LOGN_INFO, "RECEIVED MSGQ: Type[%d] SvcID[%d] MsgID[%d] usBodyLen[%d]", pstMsgQSub->usType, pstMsgQSub->usSvcID, pstMsgQSub->usMsgID, stMsg.usBodyLen);
				if( (pstMsgQSub->usSvcID == SID_PATCH) && (pstMsgQSub->usMsgID == MID_SMNG_START))
				{
					sprintf(szCommand, "/WNTAMAPP/BIN/StartMC -b S_MNG");
					system(szCommand);
					log_print(LOGN_INFO, "S_MNG START MESSAGE GET");
					continue;
				}
				SendToOMP( (dbm_msg_t*)&stMsg.szBody[0], stMsg.usBodyLen);

				
				
				nifo_node_delete(gpRECVMEMS, nifo_ptr(gpRECVMEMS, offset));
			}
			else if(dRet < 0)
			{
				log_print(LOGN_CRI, "[ERROR] dIsRcvedMessage PROGRAM FINISHED");
				exit(0);
			}
			else
				break;
#endif

		}

		/*
		* MAIN SOCKET CHECK
		*/
		dRet = dSocketCheck();

		/*
		* CHECK COMMAND TIMEOUT
		*/
		time(&tCurTime);

		if(abs(tCurTime-tCheckTime) >= 1)
		{
			Timer(tCurTime);
			tCheckTime = tCurTime;
		}

		/*
		* CHECK CLIENT FOR UNUSUAL CLOSE : CLIENT_CHECK_TIME(10)
		*/
		if(abs(tCurTime-tClientCheck) > CLIENT_CHECK_TIME)
		{
			CheckClient(0);
			tClientCheck = tCurTime;
		}

		if( (tCurTime - tLastPingMySQL) > SEC_OF_HOUR)
		{
			//if( (dRet = dPingMySQL(&stMySQL)) < 0)
			if((dRet = db_check_alive(&stMySQL)) < 0)
			{
				log_print(LOGN_CRI,"F=%s:%s.%d: ERROR IN dPingMySQL() dRet[%d]", __FILE__, __FUNCTION__, __LINE__, dRet);
				return -16;
			}
			tLastPingMySQL = tCurTime;
		}
	}
	FinishProgram();
	log_print(LOGN_CRI, "[EXIT] PROGRAM END !!!\n");

	return 0;
}