예제 #1
0
/**
 * Called by the thread handler to join clients that have
 * completed.
 */
void reap_done_clients(client_t **client)
{
  // If there aren't any just return
  if (*client == NULL) { return; } // There aren't any clients!

  // Iterate over the clients
  for ( ;*client; client = &(*client)->next) {
    client_t *entry = *client;
    // If this client is done join with it, remove it from out list
    // and deallocate it.
    if (entry->done) {
      int rc = 0;
      //This is one of the threads we're looking for!
      //So kill it!
      rc = pthread_join(entry->thread, NULL);
      if (rc) {
        fprintf(stderr, "ERROR: pthread_join returned %d", rc);
      }
      fprintf(stdout, "Client %i has exited!\n", entry->id); 
      // Deallocate everything
      *client = entry->next;
      client_cleanup(entry);
      break;
    } 
  }
}
예제 #2
0
int main(int argc, char* argv[]) {
    EchoApp_Echo echo_service = CORBA_OBJECT_NIL;
    CosNaming_NamingContext name_service = CORBA_OBJECT_NIL;

    gchar *id[] = {"EchoApp", "Echo", NULL};

    CORBA_Environment ev[1];
    CORBA_exception_init(ev);

    client_init(&argc, argv, &global_orb, ev);
    etk_abort_if_exception(ev, "init failed");

    g_print("Resolving service reference from name-service with id\"%s\"\n", id[0]);

    name_service = etk_get_name_service(global_orb, ev);
    etk_abort_if_exception(ev, "failed resolving name-service");

    echo_service = (EchoApp_Echo)etk_name_service_resolve(name_service, id, ev);
    etk_abort_if_exception(ev, "failed resolving name service at name-service");

    client_run(echo_service, ev);
    etk_abort_if_exception(ev, "service not reachable");

    client_cleanup(global_orb, echo_service, ev);
    etk_abort_if_exception(ev, "cleanup failed");

    exit(0);
}
예제 #3
0
/*
 * main 
 */
int
main(int argc, char* argv[])
         
{
        CORBA_char        filename[] = "account.ref";
        CORBA_long        amount=0;

	Account service = CORBA_OBJECT_NIL;

        CORBA_Environment ev[1];
        CORBA_exception_init(ev);

	client_init (&argc, argv, &global_orb, ev);
	etk_abort_if_exception(ev, "init failed");

        if (argc<2) g_error ("usage: %s <amount>", argv[0]);

        amount  = atoi(argv[1]);

	g_print ("Reading service reference from file \"%s\"\n", filename);

	service = (Account) etk_import_object_from_file (global_orb,
							 filename,
							 ev);
        etk_abort_if_exception(ev, "import service failed");

	client_run (service, amount, ev);
        etk_abort_if_exception(ev, "service not reachable");
 
	client_cleanup (global_orb, service, ev);
        etk_abort_if_exception(ev, "cleanup failed");
 
        exit (0);
}
예제 #4
0
int main(int argc, char *argv[])
{
    context_t c;

    mrp_clear(&c);

    if (!parse_cmdline(&c, argc, argv))
        exit(1);

    mrp_log_set_mask(c.log_mask);
    mrp_log_set_target(c.log_target);

    if (c.server)
        mrp_log_info("Running as server, using D-BUS '%s'...", c.busaddr);
    else
        mrp_log_info("Running as client, using D-BUS '%s'...", c.busaddr);

    c.ml = mrp_mainloop_create();
    mrp_add_sighandler(c.ml, SIGINT , signal_handler, &c);

    if (c.server)
        server_setup(&c);
    else
        client_setup(&c);

    mrp_mainloop_run(c.ml);

    if (c.server)
        server_cleanup(&c);
    else
        client_cleanup(&c);

    return 0;
}
예제 #5
0
int
main(int argc, char* argv[])
{
	CORBA_char filename[] = "/tmp/test-atspi.ior";
        Accessibility_Role data;
	int i;
        struct timeval start, end;
        long d_secs;
        long d_usec;
        
	Accessibility_Accessible service = CORBA_OBJECT_NIL;

        CORBA_Environment ev[1];
        CORBA_exception_init(ev);

	client_init (&argc, argv, &global_orb, ev);
	etk_abort_if_exception(ev, "init failed");

	g_print ("Reading service reference from file \"%s\"\n", filename);

	service = (Accessibility_Accessible) etk_import_object_from_file (global_orb,
							   filename,
							   ev);
        etk_abort_if_exception(ev, "import service failed");


        gettimeofday(&start, NULL);
	for (i=0; i<NUM_CALLS; i++)
	  {
            data = Accessibility_Accessible_getRole(service, ev);
	  }
        gettimeofday(&end, NULL);
        d_secs = end.tv_sec - start.tv_sec;
        d_usec = end.tv_usec - start.tv_usec;
        printf("\nGetRole : %f\n", (float) d_secs + ((float) d_usec / 1000000.0));
 
	client_cleanup (global_orb, service, ev);
        etk_abort_if_exception(ev, "cleanup failed");
 
        exit (0);
}
예제 #6
0
/***********************************************
 Method:
	p2p_client_parse_op
 
 Description:
	Perform the specified operation dictated
	by op_char
 
 ***********************************************/
void p2p_client_parse_op
(
	char op_char
	)
{
int op_code;

/*----------------------------------------
 Op codes are integer based, convert the char
 ----------------------------------------*/
op_code = GET_OP_FROM_CHAR( op_char );

/*----------------------------------------
 Perform work for user
 ----------------------------------------*/
switch( op_code )
	{
	case CLIENT_MENU_OP_ID_INFORM:
		p2p_client_dir_op_inform();
		break;

	case CLIENT_MENU_OP_ID_QUERY:
		p2p_client_dir_op_query();
		break;

	case CLIENT_MENU_OP_ID_GET_FILE:
		p2p_client_dir_op_get_file();
		break;

	case CLIENT_MENU_OP_ID_EXIT_APP:
		p2p_client_dir_op_exit();
		client_cleanup();
		break;

	default:
		printf("Unrecognized op command < %c >.\n", op_char);
		break;
	}
    
}
예제 #7
0
int main(int argc, char *argv[])
{
	if (argc != 2 || !strlen(argv[1]))
	{
	fprintf(stderr, "%s [client name]\n", argv[0]);
	return 1;
	}

	if (!set_program_name(argv[0]) || !initialize_client())
	{
	fprintf(stderr, "%s: could not initialize client\n", argv[0]);
	client_cleanup();
	return 1;
	}

	load_internal_plugins();

	if (!start_message_queue())
	{
	fprintf(stderr, "%s: could not start message queue\n", argv[0]);
	client_cleanup();
	return 1;
	}

	if (!register_resource_client(NULL))
	{
	fprintf(stderr, "%s: could not register client\n", argv[0]);
	stop_message_queue();
	client_cleanup();
	return 1;
	}

	command_handle new_service = register_service(argv[1], PARAM_ECHO_TYPE);
	command_reference service_status = 0;

	if ( !new_service || !(service_status = send_command(new_service)) ||
	     !(wait_command_event(service_status, event_complete, local_default_timeout()) & event_complete) )
	{
	fprintf(stderr, "%s: could not register service\n", argv[0]);
	if (new_service)    destroy_command(new_service);
	if (service_status) clear_command_status(service_status);
	stop_message_queue();
	client_cleanup();
	return 1;
	}

	destroy_command(new_service);
	clear_command_status(service_status);

	set_log_client_name(argv[1]);

	if (!stop_message_queue())
	{
	client_cleanup();
	return 1;
	}

	set_queue_event_hook(&message_queue_hook);

	result outcome = inline_message_queue();
	client_cleanup();
	return outcome? 0 : 1;
}
예제 #8
0
int main(int argc, char *argv[])
{
	if (argc < 3 || !strlen(argv[1]))
	{
	fprintf(stderr, "%s [client name] [config file] (...)\n", argv[0]);
	return 1;
	}

	if (!set_program_name(argv[0]) || !initialize_client())
	{
	fprintf(stderr, "%s: could not initialize client\n", argv[0]);
	client_cleanup();
	return 1;
	}

	block_messages();

	if (!start_message_queue())
	{
	fprintf(stderr, "%s: could not start message queue\n", argv[0]);
	client_cleanup();
	return 1;
	}

	if (!register_admin_client(argv[1]))
	{
	fprintf(stderr, "%s: could not register client\n", argv[0]);
	stop_message_queue();
	client_cleanup();
	return 1;
	}

	command_handle new_monitor = set_monitor_flags(monitor_attached_clients);
	command_reference monitor_status = 0;

	if ( !new_monitor || !(monitor_status = send_command(new_monitor)) ||
	     !(wait_command_event(monitor_status, event_complete, local_default_timeout()) & event_complete) )
	{
	fprintf(stderr, "%s: could not monitor server\n", argv[0]);
	if (new_monitor)    destroy_command(new_monitor);
	if (monitor_status) clear_command_status(monitor_status);
	stop_message_queue();
	client_cleanup();
	return 1;
	}

	destroy_command(new_monitor);
	clear_command_status(monitor_status);


	int outcome = 0, I;

	for (I = 2; I < argc && outcome >= 0; I++)
	{
	int protocol_pid = -1;

	int config_fd = open_protocol_file(argv[I], &protocol_pid);
	if (config_fd < 0)
	 {
	if (config_fd == RSERVR_FILE_ERROR)
	fprintf(stderr, "%s: can't open configuration file '%s': %s\n", argv[0], argv[I], strerror(errno));
	if (config_fd == RSERVR_PROTOCOL_ERROR)
	/*TODO: get rid of hard-coded message*/
	fprintf(stderr, "%s: can't open configuration file '%s': %s\n", argv[0], argv[I], "protocol error");
	if (config_fd == RSERVR_BAD_PROTOCOL)
	/*TODO: get rid of hard-coded message*/
	fprintf(stderr, "%s: can't open configuration file '%s': %s\n", argv[0], argv[I], "bad protocol");

	stop_message_queue();
	client_cleanup();
	return 1;
	 }

	FILE *next_file = fdopen(config_fd, "r");

	if (!next_file)
	 {
	fprintf(stderr, "%s: can't open configuration file '%s': %s\n", argv[0], argv[I], strerror(errno));
	if (protocol_pid >= 0) close_protocol_process(protocol_pid);
	stop_message_queue();
	client_cleanup();
	return 1;
	 }

	else
	 {
	char *directory = try_protocol_filename(argv[I]);

	if ( (outcome = parse_file(next_file, argv[0],
	    directory? dirname(directory) : NULL)) < 0 )
	  {
	fprintf(stderr, "%s: parsing error in configuration file '%s'\n", argv[0], argv[I]);
	fclose(next_file);
	if (protocol_pid >= 0) close_protocol_process(protocol_pid);
	if (directory) free(directory);
	stop_message_queue();
	client_cleanup();
	return 1;
	  }

	fclose(next_file);
	if (directory) free(directory);

	if (protocol_pid >= 0)
	  {
	if (close_protocol_process(protocol_pid) == RSERVR_PROTOCOL_ERROR)
	   {
	/*TODO: get rid of hard-coded message*/
	fprintf(stderr, "%s: can't open configuration file '%s': %s\n", argv[0], argv[I], "protocol error");
	stop_message_queue();
	client_cleanup();
	return 1;
	   }
	  }
	 }
	}

	if (outcome == 1)
	fprintf(stderr, "%s: missing continuation\n", argv[0]);

	set_queue_event_hook(&message_queue_hook);

	while (block_for_respawn());
	if (message_queue_status()) stop_message_queue();

	client_cleanup();
	return 0;
}
예제 #9
0
파일: main.c 프로젝트: lucasg/Cryptopals
int main(int argc, char *argv[])
{
	size_t i;
	unsigned int password_found;
	struct SRP_mitm_t mitm;
	struct server_t s;
	struct client_t c;
	mpz_t N, g, k, u, useless_u, x;
	mpz_t tmp_base, tmp_e, S;
	
	uint8_t buf[SHA256_HASH_SIZE];
	struct sha256nfo ctx;
	char *c_salt_str, *s_salt_str, *email, *candidate_p;
	
	mpz_init_set_str(N, NIST_N, 16 );
	mpz_init_set_str(g, NIST_g, 0 );
	mpz_init_set_str(k, NIST_k, 0 );

	// Init server
	server_init(&s, N, g, k, 1);
	server_add_entry(&s, "*****@*****.**", 16, "password123", 11);

	// Init client
	client_init(&c, N, g, k);

	// Init MITM
	server_init(&(mitm.s), N, g, k, 1);
	server_add_entry(&(mitm.s), "*****@*****.**", 16, "uselesspass", 11);
	client_init(&(mitm.c), N, g, k);

	/*
	 * MITM client pubkey interception	
	 *
	 *  S <--A--  MITM <--A--  C  
	 *     --u--> MITM  --u--> C 
	 */
	email = "*****@*****.**";
	c_salt_str = mitm_server_init_shared(&(mitm.s), email, strlen(email), c.srp.pubkey, &u);
	s_salt_str = server_init_shared(&s, email, strlen(email), mitm.c.srp.pubkey, &useless_u);
	
	if (NULL != c_salt_str)
	{
		c.salt_str = malloc(strlen(c_salt_str)*sizeof(char));
		if (NULL != c.salt_str)
		{
			/* 
			 * The MITM attacker does not know the client private DH key 'a'.
			 * However sending B == g cirumvent this unknown, since :
			 *   S = B**(a + ux) % n <==> S = (g**a).(g**ux) %n
			 * 						 <==> S =   A.g**ux %n
			 */
			c.salt_len = strlen(c_salt_str);
			memcpy(c.salt_str, c_salt_str, strlen(c_salt_str));
			client_init_shared(&c, "password123", strlen("password123") , mitm.s.srp.pubkey , u);


			/*
	 		 * MITM offline dictionnary attack
	 		 */
			i = 0x00;			
			password_found = 0x00;
			candidate_p = weak_passwords[0];

			while (NULL != candidate_p && !password_found)
			{
				srp_utils_gen_x(&x, candidate_p, strlen(candidate_p),c_salt_str, strlen(c_salt_str));

				// g**(u.x)
				mpz_init(tmp_base);
				mpz_init_set(tmp_e, u);
				mpz_mul(tmp_e, tmp_e, x );
				mpz_powm(tmp_base, g, tmp_e, N);

				mpz_init(S);
				mpz_mul(S, mitm.c.srp.pubkey, tmp_base );
				mpz_mod(S, S, N);

				srp_utils_gen_shared_key(mitm.c.K, S);

				mpz_clear(tmp_base);
				mpz_clear(tmp_e);
				mpz_clear(S);
				mpz_clear(x);
				
				if (!memcmp(mitm.c.K, c.K, sizeof(c.K)))
				{
					printf("Password successfully infered : %s !\n", candidate_p);
					password_found = 0x01;
				}
				else
				{
					i++;
					candidate_p = weak_passwords[i];
				}
			}

			/*
			 * Final server validation
			 */
			if (password_found)
			{
				mitm.c.salt_len = strlen(s_salt_str);
				mitm.c.salt_str = malloc(strlen(s_salt_str)*sizeof(char));
				if (NULL == mitm.c.salt_str)
					return 0x01;
				
				memcpy(mitm.c.salt_str, s_salt_str, strlen(s_salt_str));
				client_init_shared(&(mitm.c), candidate_p, strlen(candidate_p) , s.srp.pubkey, useless_u);


				sha256_init_Hmac(&ctx, mitm.c.K, SHA256_HASH_SIZE);
				sha256_write(&ctx, (uint8_t*) mitm.c.salt_str, mitm.c.salt_len);
				sha256_result_Hmac(&ctx, buf);

				if (server_check_password(&s, email, strlen(email),  buf))
					printf("We have a valid user : %s !\n", email);
				else
					printf("The following user is not registered : %s !\n", email);
			}
			else
				printf("The following user is not registered : %s !\n", email);
		}
	}
	else
		printf("The following user is not registered : %s !\n", email);

	client_cleanup(&c);
	server_cleanup(&s);
	server_cleanup(&(mitm.s));
	client_cleanup(&(mitm.c));

	mpz_clear(N);
	mpz_clear(g);
	mpz_clear(k);
	

	return 0x00;
}