示例#1
0
/*ケース:切断*/
inline void case_action_dis_connect(CONNECTION_DATA* con){
	REQUEST* req = &con->request;
	FILE* log_file;
	int code;
	USER_INFO* info = req->info;
	//ログオフ
	if((code = logoff_user(info,req->pass,req->session_id,con->ip)) != USER_LOGOFF_SUCCESS){
		log_file = lock_log_file();
		time_output();
		ip_output(con->ip);
		fprintf(log_file,"(%s)Logoff Error:%d\n",info->name,code);
		unlock_log_file();
		//KICKED
		connection_return_req_data_header(con,CONNECTION_ACTION_KICKED);
		return;
	}
	//成功
	log_file = lock_log_file();
	time_output();
	ip_output(con->ip);
	fprintf(log_file,"(%s)Logoff Success\n",info->name);
	unlock_log_file();
	connection_return_req_data_header(con,CONNECTION_ACTION_DISCONNECT);
	initCrypt(&info->crypt);//この時点で暗号処理の初期化。
}
示例#2
0
static int
doDecrypt(FILE *logfp, FILE *eifp, FILE *outfp)
{
	off64_t blkEnd;
	off64_t currOffs = 0;
	int r = 1;
	int fd;
        struct stat buf;

	while(1) {
		/* process block */
		if(initCrypt(eifp) != 0)
			goto done;
		/* set blkEnd to size of logfp and proceed. */
                if((fd = fileno(logfp)) == -1) {
                        r = -1;
                        goto done;
                }
                if((r = fstat(fd, &buf)) != 0) goto done;
                blkEnd = buf.st_size;
                r = eiGetEND(eifp, &blkEnd);
                if(r != 0 && r != 1) goto done;
		decryptBlock(logfp, outfp, blkEnd, &currOffs);
		gcry_cipher_close(gcry_chd);
	}
	r = 0;
done:	return r;
}
示例#3
0
文件: Pkwincli.c 项目: Thomas717/cmc
void 
main( int argc, char **argv )
{
    SOCKET	sock;
    int		arg;
    char	*host = DEFAULT_HOST;
    u_short	port = (u_short)DEFAULT_PORT;

    for( arg = 1; arg < argc; arg++ )
    {
	if ( argv[ arg ][0] != '-' )
	{
	    fprintf( stderr, "Invalid command line argument: %s\n", argv[ arg ] );
	    exit(1);
	}

	switch( argv[ arg ][1] )
	{
	case 'h':
	    printf( "-t <host>\tTarget host name (default 'localhost')\n" );
	    printf( "-p <port>\tTarget port number (default 16903)\n" );
	    printf( "-e\t\tAES Mode ECB\n" );
	    printf( "-v\t\tVerbose\n" );
	    exit(0);

	case 't' :  host = argv[ ++arg ];		break;
	case 'p' :  port = atoi( argv[ ++arg ] );	break;
	case 'e' :  sessKeyMode = CRYPT_MODE_ECB;	break;
	case 'v' :  verbose = TRUE;			break;

	default:
	    fprintf( stderr, "Invalid command line flag: %s\n", argv[ arg ] );
	    exit(1);
	}
    }

    if ( ! initCrypt() )  exit(1);
    sock = tcpConnect( host, port );
    if ( ! initSession( sock ) )  exit(1);
    if ( ! clientRequest( sock, host, port ) )  exit(1);
    shutdown( sock, 2 );
    closesocket( sock );

    if ( WSACleanup() == SOCKET_ERROR )
	fprintf( stderr, "Problem with socket cleanup\n" );

    termCrypt();

    exit(0);
}
示例#4
0
文件: rscryutil.c 项目: Xat59/rsyslog
static int
doDecrypt(FILE *logfp, FILE *eifp, FILE *outfp)
{
	off64_t blkEnd;
	off64_t currOffs = 0;
	int r;

	while(1) {
		/* process block */
		if(initCrypt(eifp) != 0)
			goto done;
		if((r = eiGetEND(eifp, &blkEnd)) != 0) goto done;
		decryptBlock(logfp, outfp, blkEnd, &currOffs);
		gcry_cipher_close(gcry_chd);
	}
	r = 0;
done:	return r;
}
示例#5
0
/*ケース:接続*/
inline void case_action_connect(CONNECTION_DATA* con){
	REQUEST* req = &con->request;
	FILE* log_file;
	int code;
	USER_INFO* info = req->info;
	//ログイン
	code = login_user(info,req->pass,req->session_id,con->ip);
	if(code == USER_LOGOFF_SUCCESS){//時間切れでログオフ
		log_file = lock_log_file();
		time_output();
		ip_output(con->ip);
		fprintf(log_file,"(%s)Login Error:Time out and Loggoff\n",info->name);
		unlock_log_file();
		//KICK
		connection_return_req_data_header(con,CONNECTION_ACTION_DISCONNECT);
		initCrypt(&info->crypt);//この時点で暗号処理の初期化。
		return;
	}else if(code != USER_LOGIN_SUCCESS){//それ以外でエラー
		log_file = lock_log_file();
		time_output();
		ip_output(con->ip);
		fprintf(log_file,"(%s)Login Error:%d\n",info->name,code);
		unlock_log_file();
		//KICK
		connection_return_req_data_header(con,CONNECTION_ACTION_KICKED);
		return;
	}
	//成功
	log_file = lock_log_file();
	time_output();
	ip_output(con->ip);
	fprintf(log_file,"(%s)Login Success\n",info->name);
	unlock_log_file();
	connection_return_req_data_header(con,CONNECTION_ACTION_ACCEPT);
	//次のストリームへ
	nextStream(&info->crypt);
}
示例#6
0
/*ケース:HTTPリクエストの処理*/
inline void case_action_request(CONNECTION_DATA* con){
	REQUEST* req = &con->request;
	FILE* log_file;
	int code;
	USER_INFO* info = req->info;

	//チェック
	code = check_user(info,req->pass,req->session_id,con->ip);
	if(code == USER_LOGOFF_SUCCESS){//時間切れでログオフ
		log_file = lock_log_file();
		time_output();
		ip_output(con->ip);
		fprintf(log_file,"(%s)Request Error:Time out and Loggoff\n",info->name);
		unlock_log_file();
		//KICK
		connection_return_req_data_header(con,CONNECTION_ACTION_DISCONNECT);
		initCrypt(&info->crypt);//この時点で暗号処理の初期化。
		return;
	}else if(code != USER_CHECK_SUCCESS){//それ以外のエラー
		log_file = lock_log_file();
		time_output();
		ip_output(con->ip);
		fprintf(log_file,"(%s)Request Error:%d\n",info->name,code);
		unlock_log_file();
		//KICK
		connection_return_req_data_header(con,CONNECTION_ACTION_KICKED);
		return;
	}

	//送信
	if(connect_request(req) && send_request(req)){
		TCPsocket* s_sock = request_get_sock(req);
		char data[4096];
		int total_size = 0;
		int size;
		//ヘッダを返す
		connection_return_req_data_header(con,CONNECTION_ACTION_RESULT);
		//データ
		while((size = SDLNet_TCP_Recv(*s_sock,data,4096)) > 0){
			total_size+=size;
			if(connection_return_req_data(con,data,size) < size){
				{//接続リセット
				char* request_str = connection_get_req_url(req->data,req->data_size);
				log_file = lock_log_file();
				time_output();
				fprintf(log_file,"(%s)<%s:%d>%s Connection reset.\n",info->name,req->host,req->host_port,request_str);
				unlock_log_file();
				free(request_str);
				}
				//次のストリームへ
				nextStream(&info->crypt);
				request_close_connection(req);
				return;
			}
		}
		{//データ送信終了
		char* request_str = connection_get_req_url(req->data,req->data_size);
		log_file = lock_log_file();
		time_output();
		fprintf(log_file,"(%s)<%s:%d>%s %dbytes\n",info->name,req->host,req->host_port,request_str,total_size);
		unlock_log_file();
		free(request_str);
		}
	}else{//エラー
		{
		char* request_str = connection_get_req_url(req->data,req->data_size);
		log_file = lock_log_file();
		time_output();
		fprintf(log_file,"(%s)<%s:%d>%s ConnectionError\n",info->name,req->host,req->host_port,request_str);
		unlock_log_file();
		free(request_str);
		}
		connection_return_req_data_header(con,CONNECTION_ACTION_KICKED);
	}
	//次のストリームへ
	nextStream(&info->crypt);
	request_close_connection(req);
}