コード例 #1
0
ファイル: cockpitauth.c プロジェクト: pdonlon/cockpit
static CockpitAuthenticated *
authenticated_for_headers (CockpitAuth *self,
                           GHashTable *in_headers)
{
  gs_unref_hashtable GHashTable *cookies = NULL;
  gs_free gchar *cookie = NULL;
  const char *prefix = "v=2;k=";

  g_return_val_if_fail (self != NULL, FALSE);
  g_return_val_if_fail (in_headers != NULL, FALSE);

  if (!cockpit_web_server_parse_cookies (in_headers, &cookies, NULL))
    return NULL;

  cookie = base64_decode_string (g_hash_table_lookup (cookies, "CockpitAuth"));
  if (cookie == NULL)
    return NULL;

  if (!g_str_has_prefix (cookie, prefix))
    {
      g_debug ("invalid or unsupported cookie: %s", cookie);
      return NULL;
    }

  return g_hash_table_lookup (self->authenticated, cookie);
}
コード例 #2
0
ファイル: cockpitauth.c プロジェクト: nphilipp/cockpit
CockpitCreds *
cockpit_auth_check_cookie (CockpitAuth *auth,
                           GHashTable *in_headers)
{
  gs_unref_hashtable GHashTable *cookies = NULL;
  gs_free gchar *auth_cookie = NULL;

  g_return_val_if_fail (auth != NULL, FALSE);
  g_return_val_if_fail (in_headers != NULL, FALSE);

  if (!cockpit_web_server_parse_cookies (in_headers, &cookies, NULL))
    return NULL;

  auth_cookie = base64_decode_string (g_hash_table_lookup (cookies, "CockpitAuth"));
  if (auth_cookie == NULL)
    return NULL;

  return cookie_to_creds (auth, auth_cookie);
}
コード例 #3
0
ファイル: cockpitauth.c プロジェクト: magcius/cockpit
gboolean
cockpit_auth_check_headers (CockpitAuth *auth,
                            GHashTable *headers,
                            char **out_user,
                            char **out_password)
{
  gs_unref_hashtable GHashTable *cookies = NULL;
  gs_free gchar *auth_cookie = NULL;
  const char *prefix = "v=2;k=";

  if (out_user)
    *out_user = NULL;
  if (out_password)
    *out_password = NULL;

  if (auth == NULL)
    {
      *out_user = g_strdup (g_get_user_name ());
      *out_password = g_strdup ("<noauth>");
      return TRUE;
    }

  if (!cockpit_web_server_parse_cookies (headers, &cookies, NULL))
    return FALSE;

  auth_cookie = base64_decode_string (g_hash_table_lookup (cookies, "CockpitAuth"));
  if (auth_cookie == NULL)
    return FALSE;

  if (!g_str_has_prefix (auth_cookie, prefix))
    {
      g_debug ("invalid or unsupported cookie: %s", auth_cookie);
      return FALSE;
    }

  return authenticated_id_to_user (auth, auth_cookie + strlen (prefix),
                                   out_user, out_password);
}