Esempio n. 1
0
static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out) {
	char * ex_cmd = NULL;
	size_t ex_cmdlen;
	int ret;

	/* File descriptor "-j &3" */
	if (*cli_opts.proxycmd == '&') {
		char *p = cli_opts.proxycmd + 1;
		int sock = strtoul(p, &p, 10);
		/* must be a single number, and not stdin/stdout/stderr */
		if (sock > 2 && sock < 1024 && *p == '\0') {
			*sock_in = sock;
			*sock_out = sock;
			return;
		}
	}

	/* Normal proxycommand */

	/* So that spawn_command knows which shell to run */
	fill_passwd(cli_opts.own_user);

	ex_cmdlen = strlen(cli_opts.proxycmd) + 6; /* "exec " + command + '\0' */
	ex_cmd = m_malloc(ex_cmdlen);
	snprintf(ex_cmd, ex_cmdlen, "exec %s", cli_opts.proxycmd);

	ret = spawn_command(exec_proxy_cmd, ex_cmd,
			sock_out, sock_in, NULL, pid_out);
	m_free(ex_cmd);
	if (ret == DROPBEAR_FAILURE) {
		dropbear_exit("Failed running proxy command");
		*sock_in = *sock_out = -1;
	}
}
Esempio n. 2
0
static int
get_pwall (pwd_drv_t *drv)
{
  size_t pwd_count = 0;
  setpwent ();
  while (getpwent ())
    pwd_count++;
  endpwent ();

  size_t term_count = passwd_term_count ();
  size_t result_count = pwd_count * term_count;
  ErlDrvTermData *result = (ErlDrvTermData *) driver_alloc (sizeof (ErlDrvTermData) * (result_count + 3));
  if (!result)
    {
      fprintf (drv->log, "Couldn't allocate memory for result\n");
      fflush (drv->log);

      return send_error (drv, "error", "Couldn't allocate memory for result");
    }

  char **names = (char **) driver_alloc (sizeof (char *) * pwd_count);
  char **pwds  = (char **) driver_alloc (sizeof (char *) * pwd_count);

  setpwent ();

  size_t result_idx = 0;
  struct passwd *pwd = getpwent ();
  while (pwd)
    {
      fill_passwd (&result[result_idx * term_count], pwd, &names[result_idx], &pwds[result_idx]);
      result_idx++;

      pwd = getpwent ();
    }

  endpwent ();

  result[result_count++] = ERL_DRV_NIL;
  result[result_count++] = ERL_DRV_LIST;
  result[result_count++] = pwd_count + 1;

  int r = driver_output_term (drv->port,
                              result,
                              result_count);

  size_t i = 0;
  for (; i < pwd_count; ++i)
    {
      driver_free (pwds[i]);
      driver_free (names[i]);
    }

  driver_free (pwds);
  driver_free (names);
  driver_free (result);
  return r;
}
Esempio n. 3
0
static void cli_proxy_cmd(int *sock_in, int *sock_out) {
	int ret;

	fill_passwd(cli_opts.own_user);

	ret = spawn_command(exec_proxy_cmd, cli_opts.proxycmd,
			sock_out, sock_in, NULL, NULL);
	if (ret == DROPBEAR_FAILURE) {
		dropbear_exit("Failed running proxy command");
		*sock_in = *sock_out = -1;
	}
}
Esempio n. 4
0
static ErlDrvTermData *
make_passwd (pwd_drv_t *drv, struct passwd *pwd, size_t *count)
{
  *count = passwd_term_count ();
  ErlDrvTermData *result = (ErlDrvTermData *)driver_alloc (sizeof (ErlDrvTermData) * *count);
  if (!result)
    {
      fprintf (drv->log, "Couldn't allocate memory for result (size: %ld)\n", *count);
      fflush (drv->log);

      *count = 0;
      return 0;
    }

  fill_passwd (result, pwd, 0, 0);
  return result;
}
Esempio n. 5
0
static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out) {
	char * ex_cmd = NULL;
	size_t ex_cmdlen;
	int ret;

	fill_passwd(cli_opts.own_user);

	ex_cmdlen = strlen(cli_opts.proxycmd) + 6; /* "exec " + command + '\0' */
	ex_cmd = m_malloc(ex_cmdlen);
	snprintf(ex_cmd, ex_cmdlen, "exec %s", cli_opts.proxycmd);

	ret = spawn_command(exec_proxy_cmd, ex_cmd,
			sock_out, sock_in, NULL, pid_out);
	m_free(ex_cmd);
	if (ret == DROPBEAR_FAILURE) {
		dropbear_exit("Failed running proxy command");
		*sock_in = *sock_out = -1;
	}
}