예제 #1
0
/** @internal
 * @brief Calculates the RTT of the host with SSH channel operations, and
 * returns the average of the calculated RTT.
 * @param[in] session active SSH session to test.
 * @param[out] average average RTT in milliseconds.
 * @returns 0 on success, -1 if there is an error.
 */
int benchmarks_ssh_latency(ssh_session session, float *average){
  float times[3];
  struct timestamp_struct ts;
  int i;
  ssh_channel channel;
  channel=ssh_channel_new(session);
  if(channel==NULL)
    goto error;
  if(ssh_channel_open_session(channel)==SSH_ERROR)
    goto error;

  for(i=0;i<3;++i){
    timestamp_init(&ts);
    if(ssh_channel_request_env(channel,"TEST","test")==SSH_ERROR &&
        ssh_get_error_code(session)==SSH_FATAL)
      goto error;
    times[i]=elapsed_time(&ts);
  }
  ssh_channel_close(channel);
  ssh_channel_free(channel);
  channel=NULL;
  printf("Times : %f ms ; %f ms ; %f ms\n", times[0], times[1], times[2]);
  *average=(times[0]+times[1]+times[2])/3;
  return 0;
error:
  fprintf(stderr,"Error calculating SSH latency : %s\n",ssh_get_error(session));
  if(channel)
    ssh_channel_free(channel);
  return -1;
}
예제 #2
0
static void torture_request_env(void **state)
{
    struct torture_state *s = *state;
    ssh_session session = s->ssh.session;
    ssh_channel c;
    char buffer[4096] = {0};
    int nbytes;
    int rc;
    int lang_found = 0;

    c = ssh_channel_new(session);
    assert_non_null(c);

    rc = ssh_channel_open_session(c);
    assert_ssh_return_code(session, rc);

    rc = ssh_channel_request_env(c, "LC_LIBSSH", "LIBSSH_EXPORTED_VARIABLE");
    assert_ssh_return_code(session, rc);

    rc = ssh_channel_request_exec(c, "echo $LC_LIBSSH");
    assert_ssh_return_code(session, rc);

    nbytes = ssh_channel_read(c, buffer, sizeof(buffer) - 1, 0);
    printf("nbytes=%d\n", nbytes);
    while (nbytes > 0) {
#if 1
        rc = fwrite(buffer, 1, nbytes, stdout);
        assert_int_equal(rc, nbytes);
#endif
        buffer[nbytes]='\0';
        if (strstr(buffer, "LIBSSH_EXPORTED_VARIABLE")) {
            lang_found = 1;
            break;
        }

        nbytes = ssh_channel_read(c, buffer, sizeof(buffer), 0);
    }
    assert_int_equal(lang_found, 1);

    ssh_channel_close(c);
}
예제 #3
0
static void torture_request_env(void **state)
{
    ssh_session session = *state;
    ssh_channel c;
    char buffer[4096] = {0};
    int nbytes;
    int rc;
    int lang_found = 0;

    c = ssh_channel_new(session);
    assert_non_null(c);

    rc = ssh_channel_open_session(c);
    assert_int_equal(rc, SSH_OK);

    rc = ssh_channel_request_env(c, "LC_LIBSSH", "LIBSSH");
    assert_int_equal(rc, SSH_OK);

    rc = ssh_channel_request_exec(c, "bash -c export");
    assert_int_equal(rc, SSH_OK);

    nbytes = ssh_channel_read(c, buffer, sizeof(buffer) - 1, 0);
    while (nbytes > 0) {
#if 0
        rc = fwrite(buffer, 1, nbytes, stdout);
        assert_int_equal(rc, nbytes);
#endif
        buffer[nbytes]='\0';
        if (strstr(buffer, "LC_LIBSSH=\"LIBSSH\"")) {
            lang_found = 1;
            break;
        }

        nbytes = ssh_channel_read(c, buffer, sizeof(buffer), 0);
    }
    assert_int_equal(lang_found, 1);

    ssh_channel_close(c);
}
예제 #4
0
파일: legacy.c 프로젝트: rofl0r/libssh
int channel_request_env(ssh_channel channel, const char *name, const char *value){
  return ssh_channel_request_env(channel, name, value);
}