Пример #1
0
int main()
{
  int pass;
  SshStream s1, s2;

  ssh_rand_seed((SshUInt32)ssh_time());

  ssh_event_loop_initialize();

  for (pass = 0; pass < 100; pass++)
    {
      ssh_stream_pair_create(&s1, &s2);
      break_test = ssh_rand() % 2;
      copy_data_test(s1, s2);

      ssh_stream_pair_create(&s1, &s2);
      break_test = ssh_rand() % 2;
      copy_data_test(s2, s1);
    }
  if (testdata)
    ssh_buffer_free(testdata);
  if (received_data)
    ssh_buffer_free(received_data);

  ssh_event_loop_uninitialize();
  ssh_util_uninit();
  return 0;
}
Пример #2
0
int
main(int argc, char *argv[])
{
  SshFSMStruct fsmstruct;
  SshFSMThread thread;
  SshFSM fsm = &fsmstruct;

  if (argc == 2)
    ssh_debug_set_level_string(argv[1]);

  ssh_event_loop_initialize();

  ssh_fsm_init(fsm, NULL);

  ssh_fsm_register_debug_names(fsm, state_array, num_states);

  /* Create a condition variable. */
  ssh_fsm_condition_init(fsm, &cond);

  thread = ssh_fsm_thread_create(fsm, main_start, NULL_FNPTR,
				 NULL_FNPTR, "main");
  ssh_fsm_set_thread_name(thread, "main");

  ssh_event_loop_run();

  ssh_fsm_uninit(fsm);

  ssh_event_loop_uninitialize();
  ssh_util_uninit();
  return errors;
}
Пример #3
0
int
main(int argc, char *argv[])
{
  SshFSM fsm;
  SshFSMThread thread;

  ssh_event_loop_initialize();

  /* Create a new FSM with NULL context data. */
  fsm = ssh_fsm_create(NULL);
  if (fsm == NULL)
    {
      fprintf(stderr, "Could not create FSM\n");
      goto error;
    }

  /* Start a thread.  The context data is the greeting to display to
     the user. */
  thread = ssh_fsm_thread_create(fsm, hello, NULL_FNPTR, NULL_FNPTR,
                                 "Hello, world!");
  if (thread == NULL)
    {
      fprintf(stderr, "Could not start thread\n");
      goto error;
    }

  /* Start event loop. */
  ssh_event_loop_run();

  /* Cleanup. */
  ssh_fsm_destroy(fsm);
  ssh_event_loop_uninitialize();

  return 0;

  /* Error handling. */

 error:
  if (fsm)
    ssh_fsm_destroy(fsm);

  ssh_event_loop_uninitialize();

  return 1;
}
Пример #4
0
int main(int ac, char **av)
{
  int i, j;
  int pass;
  unsigned char buf[1024];

  snprintf(lpath1, sizeof (lpath1), "/tmp/lstr1.%x", (unsigned)random());
  snprintf(lpath2, sizeof (lpath2), "/tmp/lstr2.%x", (unsigned)random());
  
  printf("Doing %d iterations of localstream test:", PASSES);

  for (pass = 0; pass < PASSES; pass++)
    {
      printf(" %d", pass);
      fflush(stdout);

      ssh_buffer_init(&send_buffer);
      ssh_buffer_init(&expect_buffer);
      
      for (i = 0; i < 100; i++)
	{
	  for (j = 0; j < sizeof(buf); j++)
	    buf[j] = random();
	  ssh_buffer_append(&send_buffer, buf, sizeof(buf));
	  ssh_buffer_append(&expect_buffer, buf, sizeof(buf));
	  send_count += sizeof(buf);
	}

      ssh_event_loop_initialize();

      remove(lpath1);
      listener1 = ssh_local_make_listener(lpath1, 
					  listener1_callback,
					  (void *)4);
      if (!listener1) {
	  ssh_fatal("cannot create listener1");
      }

      ssh_local_connect(lpath1, connect1_done, (void *)3);

      ssh_event_loop_run();

      ssh_event_loop_uninitialize();

      ssh_buffer_uninit(&send_buffer);
      ssh_buffer_uninit(&expect_buffer);
      
    }
  printf("\n");
  
  return 0;
}
Пример #5
0
int main()
{
  int pass;

  srandom(ssh_time());

  ssh_event_loop_initialize();
  
  random_state = ssh_random_allocate();
  create_server_keys(&hostkey, &serverkey, &hostkey_blob, &hostkey_blob_len);

  pingpong_success = FALSE;
  for (pass = 0; pass < 10; pass++)
    {
#ifdef DEBUG
      ssh_debug("========== iteration %d ==========", pass);
#endif
      disconnect_test();
      simple_password_test(NULL);
    }
  if (!pingpong_success)
    ssh_fatal("main: no successful pingpong");

  pingpong_success = FALSE;
  
  for (pass = 0; pass < 100; pass++)
    {
#ifdef DEBUG
      ssh_debug("========== iteration dual-%d ==========", pass);
#endif
      disconnect_test();
      simple_password_test(dual_policy);
    }

  if (!pingpong_success)
    ssh_fatal("main: no successful pingpong");
  
  ssh_private_key_free(hostkey);
  ssh_private_key_free(serverkey);
  ssh_xfree(hostkey_blob);
  ssh_random_free(random_state);

  ssh_event_loop_uninitialize();
  return 0;
}
/* The main. */
int main(int argc, char **argv)
{
  /* Parse arguments. */
  parse_arguments(argc, argv);

  /* Initialize the event loop. */
  ssh_event_loop_initialize();

  /* Allocate and initialize the externalkey interface. */
  test_ek_add();

  /* Start the event loop. This wont return, unless somebody 
     calls ssh_event_loop_abort(). */
  ssh_event_loop_run();

  /* Uninitialize the event loop. */
  ssh_event_loop_uninitialize();

  return 0;
}
Пример #7
0
int main(int argc, char* argv[])
{
  t_tcpc_context  pcontext = 0;
  SshGetOptData   pgetoptdata = 0;
  int                             i;

  SSH_TRACE(SSH_D_MY, ("%s", "main"));

  pcontext = ssh_xmalloc(sizeof (*pcontext));
  memset(pcontext, 0, sizeof (*pcontext));

  pgetoptdata = ssh_xmalloc(sizeof (*pgetoptdata));
  memset(pgetoptdata, 0, sizeof (*pgetoptdata));

  ssh_getopt_init_data(pgetoptdata);
  pcontext->pport_or_service = "23242";

  while ((i = ssh_getopt(argc, argv, "p:h:d:D:G:t:", pgetoptdata)) != -1)
    {
      switch (i)
        {
        case 'p':
          pcontext->pport_or_service = ssh_xstrdup(pgetoptdata->arg);
          break;
        case 'h':
          pcontext->phost_name_or_address = ssh_xstrdup(pgetoptdata->arg);
          break;
        case 'd':
          pcontext->pdata = ssh_xstrdup(pgetoptdata->arg);
          break;
        case 'D':
          ssh_debug_set_module_level(SSH_DEBUG_MODULE, atoi(pgetoptdata->arg));
          break;
        case 'G':
          ssh_debug_set_global_level(atoi(pgetoptdata->arg));
          break;
        case 't':
          pcontext->timeout = atoi(pgetoptdata->arg);
          break;
        default:
          SSH_NOTREACHED;
          break;
        }
    }

  ssh_xfree(pgetoptdata);

  ssh_event_loop_initialize();

  pcontext->pbuffer = ssh_buffer_allocate();

  if (pcontext->phost_name_or_address)
    {
      ssh_tcp_connect(pcontext->phost_name_or_address,
                      pcontext->pport_or_service,
                      NULL,
                      t_tcpc_tcp_callback,
                      pcontext);
    }
  else
    {
      pcontext->ptcplistener =
        ssh_tcp_make_listener(SSH_IPADDR_ANY_IPV4,
                              pcontext->pport_or_service,
                              NULL,
                              t_tcpc_tcp_callback,
                              pcontext);
    }

  ssh_event_loop_run();
  ssh_name_server_uninit();
  ssh_event_loop_uninitialize();

  ssh_buffer_free(pcontext->pbuffer);
  ssh_xfree(pcontext);
  ssh_util_uninit();
  return 0;
}
Пример #8
0
int
main(int argc, char *argv[])
{
  int c;
  const char *debug_string = "SshHttpFilterProxy=5";
  SshHttpServerParams params;
  SshHttpServerContext ctx;

  memset(&params, 0, sizeof(params));
  params.port = "8080";

#ifndef WIN32
  signal(SIGPIPE, SIG_IGN);
#endif /* not WIN32 */

  /* Remove the directory part from the program name. */
  program = strrchr(argv[0], '/');
  if (program == NULL)
    program = argv[0];
  else
    program++;

  /* Parse options. */
  while ((c = ssh_getopt(argc, argv, "d:hp:P:", NULL)) != EOF)
    {
      switch (c)
        {
        case 'd':
          debug_string = ssh_optarg;
          break;

        case 'h':
          usage();
          exit(0);
          break;

        case 'p':
          params.port = ssh_optarg;
          break;

        case 'P':
          proxy_url = ssh_optarg;
          break;
        }
    }

  if (ssh_optind < argc)
    {
      fprintf(stderr, "%s: garbage after options.\n\n", program);
      usage();
      exit(1);
    }

  ssh_debug_set_level_string(debug_string);
  ssh_event_loop_initialize();

  read_censor_list();

  SSH_DEBUG(SSH_D_HIGHSTART, ("running on %s", params.port));

  ctx = ssh_http_server_start(&params);

  if (ctx)
    {
      /* Set the URI handlers. */
      ssh_http_server_set_handler(ctx, "http://*", 0, proxy_handler, NULL);
      ssh_http_server_set_handler(ctx, "/catch*", 0, catch_handler, NULL);
      ssh_http_server_set_handler(ctx, "*", 10, authentication_handler, NULL);

      ssh_event_loop_run();
    }
  else
    fprintf(stderr, "%s: couldn't create listener\n", program);

  ssh_event_loop_uninitialize();

  return 0;
}
Пример #9
0
Файл: t-tr.c Проект: AnthraX1/rk
int main(int ac, char **av)
{
  char port[100];
  int i;
  TestCase *testcase;
  int pass;
  SshTime time_now;

  time_now = ssh_time();
  srandom(time_now);

  for (pass = 0; pass < PASSES; pass++)
    {
#ifdef DEBUG
      ssh_debug("pass %d", pass);
#endif
      random_state = ssh_random_allocate();

      /* randomize it a bit */
      ssh_random_add_noise(random_state, &time_now, sizeof(time_now));

      ssh_buffer_init(&testdata);
      for (i = 0; i < 100000; i++)
        buffer_put_char(&testdata, ssh_random_get_byte(random_state));

      ssh_event_loop_initialize();

      for (i = 0; tests[i].name; i++)
        {
          testcase = &tests[i];
          end_of_script_count = 0;

#ifdef DEBUG      
          ssh_debug("Running test %s", testcase->name);
#endif
          
          snprintf(port, sizeof(port), "%d", (int)(35000 + random() % 1000));
#ifdef DEBUG
          ssh_debug("Making listener, port %s...", port);
#endif
          listener = ssh_tcp_make_listener("127.0.0.1", port,
                                              listener_callback,
                                              (void *)testcase);
          if (!listener)
            ssh_fatal("making listener failed");
#ifdef DEBUG      
          ssh_debug("Making connect...");
#endif
          ssh_tcp_connect_with_socks("127.0.0.1", port, NULL, 2,
                             connect_callback, (void *)testcase);

#ifdef DEBUG      
          ssh_debug("Event loop running...");
#endif 
          ssh_event_loop_run();
#ifdef DEBUG
          ssh_debug("Event loop exited...");
#endif
          if (end_of_script_count != 2)
            ssh_fatal("end_of_script_count %d, script end not reached.",
                  end_of_script_count);
          /* Listener was destroyed in callback. */
        }
  
      ssh_event_loop_uninitialize();
      ssh_buffer_uninit(&testdata);
      ssh_random_free(random_state);
    }
#ifdef DEBUG
  ssh_debug("Exiting...");
#endif
  return 0;
}
Пример #10
0
int main(int ac, char **av)
{
  int opt, i;
  DIR *ssh2dir = NULL;
  char *ssh2dirname;
  Boolean dynamic_array = FALSE;
  struct dirent * cand;

  /* Save program name. */
  if (strchr(av[0], '/'))
    av0 = strrchr(av[0], '/') + 1;
  else
    av0 = av[0];

  user = ssh_user_initialize(NULL, FALSE);

#ifdef WITH_PGP
  pgp_keyring = ssh_xstrdup(SSH_PGP_SECRET_KEY_FILE);
#endif /* WITH_PGP */

  action = ADD;
  while ((opt = ssh_getopt(ac, av, "ldDput:f:F:1LUNPI", NULL)) != EOF)
    {
      if (!ssh_optval)
        {
          usage();
          exit(EXIT_STATUS_ERROR);
        }
      switch (opt)
        {
        case 'N':
#ifdef WITH_PGP
          pgp_mode = PGP_KEY_NAME;
#else /* WITH_PGP */
          fprintf(stderr, "%s: PGP keys not supported.\n", av0);
          exit(EXIT_STATUS_ERROR);
#endif /* WITH_PGP */
          break;

        case 'P':
#ifdef WITH_PGP
          pgp_mode = PGP_KEY_FINGERPRINT;
#else /* WITH_PGP */
          fprintf(stderr, "%s: PGP keys not supported.\n", av0);
          exit(EXIT_STATUS_ERROR);
#endif /* WITH_PGP */
          break;

        case 'I':
#ifdef WITH_PGP
          pgp_mode = PGP_KEY_ID;
#else /* WITH_PGP */
          fprintf(stderr, "%s: PGP keys not supported.\n", av0);
          exit(EXIT_STATUS_ERROR);
#endif /* WITH_PGP */
          break;

        case 'R':
#ifdef WITH_PGP
          ssh_xfree(pgp_keyring);
          pgp_keyring = ssh_xstrdup(ssh_optarg);
#else /* WITH_PGP */
          fprintf(stderr, "%s: PGP keys not supported.\n", av0);
          exit(EXIT_STATUS_ERROR);
#endif /* WITH_PGP */
          break;

        case 'l':
          action = LIST;
          break;

        case 'p':
          use_stdin = TRUE;
          break;

        case 'd':
          if (action == ADD_URL)
            action = DELETE_URL;
          else
            action = DELETE;
          break;

        case 'D':
          action = DELETE_ALL;
          break;

        case 't':
          if (ssh_optargnum)
            {
              key_timeout = (SshTime)(ssh_optargval * 60);
            }
          else
            {
              usage();
              exit(EXIT_STATUS_ERROR);
            }
          have_attrs = TRUE;
          break;

        case 'f':
          if (ssh_optargnum)
            {
              path_limit = (SshUInt32)ssh_optargval;
            }
          else
            {
              usage();
              exit(EXIT_STATUS_ERROR);
            }
          have_attrs = TRUE;
          break;

        case 'F':
          path_constraint = ssh_xstrdup(ssh_optarg);
          have_attrs = TRUE;
          break;

        case '1':
          forbid_compat = TRUE;
          have_attrs = TRUE;
          break;

        case 'u':
          if (action == DELETE)
            action = DELETE_URL;
          else
            action = ADD_URL;
          break;

        case 'L':
          action = LOCK;
          break;

        case 'U':
          action = UNLOCK;
          break;

        default:
          usage();
          exit(EXIT_STATUS_ERROR);
        }
    }

#ifdef WITH_PGP
  if (pgp_keyring[0] != '/')
    {
      char buf[1024];
      snprintf(buf, sizeof (buf), "%s/%s/%s", 
               ssh_user_dir(user), 
               SSH_USER_DIR,
               pgp_keyring);
      ssh_xfree(pgp_keyring);
      pgp_keyring = ssh_xstrdup(buf);
    }
#endif /* WITH_PGP */

  files = &av[ssh_optind];
  num_files = ac - ssh_optind;

  /* Fetch default from ~/.ssh2/id_* (the first that we happen to get) */

#define ID_PREFIX "id"
  
  if (num_files == 0 && action != LIST && action != DELETE_ALL &&
      action != LOCK && action != UNLOCK)
    {
#ifdef WITH_PGP
      if (pgp_mode != PGP_KEY_NONE)
        {
          fprintf(stderr, "%s: Nothing to do!\n",  av0);
          exit(EXIT_STATUS_ERROR);
        }
#endif /* WITH_PGP */
      ssh_dsprintf(&ssh2dirname, "%s/%s", ssh_user_dir(user), SSH_USER_DIR);
      ssh2dir = opendir(ssh2dirname);

      if (!ssh2dir)
        {
          fprintf(stderr, "%s: Can't open directory \"%s\"", av0, ssh2dirname);
          exit(EXIT_STATUS_ERROR);
        }
          
      while ((cand = readdir(ssh2dir)) != NULL)
        {
          if ((strlen(cand->d_name) > strlen(ID_PREFIX)) &&
              (strncmp(cand->d_name, ID_PREFIX, strlen(ID_PREFIX)) == 0) &&
              ((strlen(cand->d_name) < 4) ||
               (strcmp(cand->d_name + strlen(cand->d_name) - 4,
                       ".pub") != 0)) &&
              ((((cand->d_name)[strlen(ID_PREFIX)]) == '_') ||
               (((cand->d_name)[strlen(ID_PREFIX)]) == '-') ||
               (((cand->d_name)[strlen(ID_PREFIX)]) == '.') ||
               (((cand->d_name)[strlen(ID_PREFIX)]) == '(') ||
               (((cand->d_name)[strlen(ID_PREFIX)]) == '[') ||
               (((cand->d_name)[strlen(ID_PREFIX)]) == '<') ||
               (((cand->d_name)[strlen(ID_PREFIX)]) == '>')))
            {
              files = ssh_xcalloc(2, sizeof(char *));
              ssh_dsprintf(&files[0], "%s/%s", ssh2dirname, cand->d_name);
              ssh_xfree(ssh2dirname);
              num_files++;
              dynamic_array = TRUE;
              break;
            }
        }
      (void)closedir(ssh2dir);
    }
  
  signal(SIGPIPE, SIG_IGN);
  
  ssh_event_loop_initialize();
  
  ssh_agent_open(agent_open_callback, NULL);

  ssh_event_loop_run();
  ssh_event_loop_uninitialize();

  if (dynamic_array)
    {
      for(i = 0; i < num_files ; i++)
        {
          ssh_xfree(files[i]);
        }
      ssh_xfree(files);
    }
  
  ssh_user_free(user, FALSE);
  exit(EXIT_STATUS_OK);
}