コード例 #1
0
ファイル: sshurl.c プロジェクト: AnthraX1/rk
/*
 * Parses url given in format
 * [<scheme>:][//[<user>[:<password>]@]<host>[:<port>]]/[<path>]
 * Returns true if the url is syntactically valid, false otherwise.
 * If the incorrect url format "www.ssh.fi" is given then returns FALSE and
 * sets host to contain whole url. If some piece of url is not given it is
 * set to NULL. If some of the pieces are not needed they can be NULL and
 * those pieces will be skipped. This version also decodeds url %-codings.
 */
Boolean ssh_url_parse_and_decode(const char *url, char **scheme, char **host,
                                 char **port, char **username, char **password,
                                 char **path)
{
  Boolean ok;

  ok = ssh_url_parse(url, scheme, host, port, username, password, path);

  if (scheme && *scheme)
    if (!ssh_url_decode(*scheme, NULL))
      ok = FALSE;
  if (host && *host)
    if (!ssh_url_decode(*host, NULL))
      ok = FALSE;
  if (port && *port)
    if (!ssh_url_decode(*port, NULL))
      ok = FALSE;
  if (username && *username)
    if (!ssh_url_decode(*username, NULL))
      ok = FALSE;
  if (password && *password)
    if (!ssh_url_decode(*password, NULL))
      ok = FALSE;
  if (path && *path)
    if (!ssh_url_decode(*path, NULL))
      ok = FALSE;

  return ok;
}
コード例 #2
0
SshRadiusUrlStatus
ssh_radius_url_add_server(SshRadiusClientServerInfo s_info, unsigned char *url)
{
  unsigned char *scheme, *host, *port, *username, *password, *path;
  const unsigned char *real_port, *real_secret;
  Boolean res;

  SSH_PRECOND(url != NULL);

  real_port = NULL;
  scheme = host = port = username = password = path = NULL;

  res = ssh_url_parse(url, &scheme, &host, &port, &username,
                      &password, &path);

  if (res == FALSE)
    goto fail;

  res = FALSE;

  if (scheme == NULL)
    goto fail;

  if (ssh_usstrcmp(scheme, "radius") != 0)
    goto fail;

  if (host == NULL)
    goto fail;

  real_port =   (real_port !=  NULL ? port : (unsigned char *)"1812");
  real_secret = (password != NULL ? password : (unsigned char *)"");

  res = ssh_radius_client_server_info_add_server(s_info,
                                                 host,
                                                 real_port,
                                                 real_port,
                                                 real_secret,
                                                 ssh_ustrlen(real_secret));

 fail:
  if (scheme != NULL)
    ssh_free(scheme);

  if (host != NULL)
    ssh_free(host);

  if (port != NULL)
    ssh_free(port);

  if (username != NULL)
    ssh_free(username);

  if (password != NULL)
    ssh_free(password);

  if (path != NULL)
    ssh_free(path);

  return res;
}
コード例 #3
0
static unsigned char*
ssh_radius_get_url_path(const unsigned char *url)
{
  Boolean res;
  unsigned char *path;

  res = ssh_url_parse(url, NULL, NULL, NULL, NULL, NULL, &path);
  if (res == FALSE)
    return NULL;

  if (path == NULL)
    return NULL;

  return path;
}
コード例 #4
0
static SshRadiusUrlStatus
ssh_radius_url_parse_nas_id(unsigned char *url, unsigned char **result)
{
  Boolean res;
  SshRadiusUrlStatus url_status;
  unsigned char *scheme, *name;

  SSH_PRECOND(url != NULL);

  /* Note that we can not detect if this failed due
     to an out of memory error! If we could, then we
     would provide more than an equivalent of FALSE/TRUE
     in the return code. */

  res = ssh_url_parse(url, &scheme, NULL, NULL, &name, NULL, NULL);

  if (res == FALSE)
    return SSH_RADIUS_URL_MALFORMED;

  url_status = SSH_RADIUS_URL_INVALID_SCHEME;

  if (scheme == NULL)
    goto fail;

  if (ssh_usstrcmp(scheme, "radius") != 0)
    goto fail;

  ssh_free(scheme);
  *result = name;

  if (name == NULL)
    return SSH_RADIUS_URL_EXPECTING_NAS_ID;

  return SSH_RADIUS_URL_STATUS_SUCCESS;

 fail:
  if (scheme != NULL)
    ssh_free(scheme);

  if (name != NULL)
    ssh_free(name);

  *result = NULL;

  return url_status;
}