"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "oci-authenticator/flatpak-oci-authenticator.c" between
flatpak-1.15.1.tar.xz and flatpak-1.15.2.tar.xz

About: Flatpak is a Linux application sandboxing and distribution framework. Pre-release.

flatpak-oci-authenticator.c  (flatpak-1.15.1.tar.xz):flatpak-oci-authenticator.c  (flatpak-1.15.2.tar.xz)
skipping to change at line 43 skipping to change at line 43
static GMainLoop *main_loop = NULL; static GMainLoop *main_loop = NULL;
static guint name_owner_id = 0; static guint name_owner_id = 0;
static gboolean no_idle_exit = FALSE; static gboolean no_idle_exit = FALSE;
static FlatpakHttpSession *http_session = NULL; static FlatpakHttpSession *http_session = NULL;
#define IDLE_TIMEOUT_SECS 10 * 60 #define IDLE_TIMEOUT_SECS 10 * 60
static void static void
skeleton_died_cb (gpointer data) skeleton_died_cb (gpointer data)
{ {
g_debug ("skeleton finalized, exiting"); g_info ("skeleton finalized, exiting");
g_main_loop_quit (main_loop); g_main_loop_quit (main_loop);
} }
static gboolean static gboolean
unref_skeleton_in_timeout_cb (gpointer user_data) unref_skeleton_in_timeout_cb (gpointer user_data)
{ {
static gboolean unreffed = FALSE; static gboolean unreffed = FALSE;
g_debug ("unreffing authenticator main ref"); g_info ("unreffing authenticator main ref");
if (!unreffed) if (!unreffed)
{ {
g_object_unref (authenticator); g_object_unref (authenticator);
unreffed = TRUE; unreffed = TRUE;
} }
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
static void static void
skipping to change at line 82 skipping to change at line 82
execution of them. We do the unref on a timeout to make sure execution of them. We do the unref on a timeout to make sure
we're completely draining the queue of (stale) requests. */ we're completely draining the queue of (stale) requests. */
g_timeout_add (500, unref_skeleton_in_timeout_cb, NULL); g_timeout_add (500, unref_skeleton_in_timeout_cb, NULL);
} }
static gboolean static gboolean
idle_timeout_cb (gpointer user_data) idle_timeout_cb (gpointer user_data)
{ {
if (name_owner_id) if (name_owner_id)
{ {
g_debug ("Idle - unowning name"); g_info ("Idle - unowning name");
unref_skeleton_in_timeout (); unref_skeleton_in_timeout ();
} }
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
static void static void
schedule_idle_callback (void) schedule_idle_callback (void)
{ {
static guint idle_timeout_id = 0; static guint idle_timeout_id = 0;
skipping to change at line 132 skipping to change at line 132
g_mutex_unlock (&auth->mutex); g_mutex_unlock (&auth->mutex);
} }
static gboolean static gboolean
handle_request_ref_tokens_close (FlatpakAuthenticatorRequest *object, handle_request_ref_tokens_close (FlatpakAuthenticatorRequest *object,
GDBusMethodInvocation *invocation, GDBusMethodInvocation *invocation,
gpointer user_data) gpointer user_data)
{ {
BasicAuthData *auth = user_data; BasicAuthData *auth = user_data;
g_debug ("handlling Request.Close"); g_info ("handlling Request.Close");
flatpak_authenticator_request_complete_close (object, invocation); flatpak_authenticator_request_complete_close (object, invocation);
cancel_basic_auth (auth); cancel_basic_auth (auth);
return G_DBUS_METHOD_INVOCATION_HANDLED; return G_DBUS_METHOD_INVOCATION_HANDLED;
} }
static void static void
add_auth_for_peer (const char *sender, add_auth_for_peer (const char *sender,
skipping to change at line 183 skipping to change at line 183
peer_died (const char *name) peer_died (const char *name)
{ {
G_LOCK (active_auth); G_LOCK (active_auth);
if (active_auth) if (active_auth)
{ {
GList *active = g_hash_table_lookup (active_auth, name); GList *active = g_hash_table_lookup (active_auth, name);
if (active) if (active)
{ {
for (GList *l = active; l != NULL; l = l->next) for (GList *l = active; l != NULL; l = l->next)
{ {
g_debug ("Cancelling auth operation for dying peer %s", name); g_info ("Cancelling auth operation for dying peer %s", name);
cancel_basic_auth (l->data); cancel_basic_auth (l->data);
} }
g_list_free (active); g_list_free (active);
g_hash_table_remove (active_auth, name); g_hash_table_remove (active_auth, name);
} }
} }
G_UNLOCK (active_auth); G_UNLOCK (active_auth);
return NULL; return NULL;
} }
static gboolean static gboolean
handle_request_ref_tokens_basic_auth_reply (FlatpakAuthenticatorRequest *object, handle_request_ref_tokens_basic_auth_reply (FlatpakAuthenticatorRequest *object,
GDBusMethodInvocation *invocation, GDBusMethodInvocation *invocation,
const gchar *arg_user, const gchar *arg_user,
const gchar *arg_password, const gchar *arg_password,
GVariant *options, GVariant *options,
gpointer user_data) gpointer user_data)
{ {
BasicAuthData *auth = user_data; BasicAuthData *auth = user_data;
g_debug ("handlling Request.BasicAuthReply %s %s", arg_user, arg_password); g_info ("handlling Request.BasicAuthReply %s %s", arg_user, arg_password);
flatpak_authenticator_request_complete_basic_auth_reply (object, invocation); flatpak_authenticator_request_complete_basic_auth_reply (object, invocation);
g_mutex_lock (&auth->mutex); g_mutex_lock (&auth->mutex);
if (!auth->done) if (!auth->done)
{ {
auth->done = TRUE; auth->done = TRUE;
auth->user = g_strdup (arg_user); auth->user = g_strdup (arg_user);
auth->password = g_strdup (arg_password); auth->password = g_strdup (arg_password);
g_cond_signal (&auth->cond); g_cond_signal (&auth->cond);
skipping to change at line 466 skipping to change at line 466
gboolean have_auth; gboolean have_auth;
const char *oci_registry_uri = NULL; const char *oci_registry_uri = NULL;
gsize n_refs, i; gsize n_refs, i;
gboolean no_interaction = FALSE; gboolean no_interaction = FALSE;
g_autoptr(FlatpakOciRegistry) registry = NULL; g_autoptr(FlatpakOciRegistry) registry = NULL;
g_autofree char *first_token = NULL; g_autofree char *first_token = NULL;
GVariantBuilder tokens; GVariantBuilder tokens;
GVariantBuilder results; GVariantBuilder results;
g_autofree char *sender = g_strdup (g_dbus_method_invocation_get_sender (invoc ation)); g_autofree char *sender = g_strdup (g_dbus_method_invocation_get_sender (invoc ation));
g_debug ("handling Authenticator.RequestRefTokens"); g_info ("handling Authenticator.RequestRefTokens");
g_variant_lookup (arg_authenticator_options, "auth", "&s", &auth); g_variant_lookup (arg_authenticator_options, "auth", "&s", &auth);
have_auth = auth != NULL; have_auth = auth != NULL;
if (!g_variant_lookup (arg_options, "xa.oci-registry-uri", "&s", &oci_registry _uri)) if (!g_variant_lookup (arg_options, "xa.oci-registry-uri", "&s", &oci_registry _uri))
{ {
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_INVALID_ARGS, G_DBUS_ERROR_INVALID_ARGS,
_("Not a OCI remote")); _("Not a OCI remote"));
return G_DBUS_METHOD_INVOCATION_HANDLED; return G_DBUS_METHOD_INVOCATION_HANDLED;
skipping to change at line 509 skipping to change at line 509
flatpak_authenticator_complete_request_ref_tokens (f_authenticator, invocation , request_path); flatpak_authenticator_complete_request_ref_tokens (f_authenticator, invocation , request_path);
registry = flatpak_oci_registry_new (oci_registry_uri, FALSE, -1, NULL, &error ); registry = flatpak_oci_registry_new (oci_registry_uri, FALSE, -1, NULL, &error );
if (registry == NULL) if (registry == NULL)
return error_request (request, sender, error); return error_request (request, sender, error);
/* Look up credentials in config files */ /* Look up credentials in config files */
if (!have_auth) if (!have_auth)
{ {
g_debug ("Looking for %s in auth info", oci_registry_uri); g_info ("Looking for %s in auth info", oci_registry_uri);
auth = lookup_auth_from_config (oci_registry_uri); auth = lookup_auth_from_config (oci_registry_uri);
have_auth = auth != NULL; have_auth = auth != NULL;
} }
/* Try to see if we can get a token without presenting credentials */ /* Try to see if we can get a token without presenting credentials */
n_refs = g_variant_n_children (arg_refs); n_refs = g_variant_n_children (arg_refs);
if (!have_auth && n_refs > 0) if (!have_auth && n_refs > 0)
{ {
g_autoptr(GVariant) ref_data = g_variant_get_child_value (arg_refs, 0); g_autoptr(GVariant) ref_data = g_variant_get_child_value (arg_refs, 0);
g_debug ("Trying anonymous authentication"); g_info ("Trying anonymous authentication");
first_token = get_token_for_ref (registry, ref_data, NULL, &anon_error); first_token = get_token_for_ref (registry, ref_data, NULL, &anon_error);
if (first_token != NULL) if (first_token != NULL)
have_auth = TRUE; have_auth = TRUE;
else else
{ {
if (g_error_matches (anon_error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_AUTH ORIZED)) if (g_error_matches (anon_error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_AUTH ORIZED))
{ {
g_debug ("Anonymous authentication failed: %s", anon_error->messag e); g_info ("Anonymous authentication failed: %s", anon_error->message );
/* Continue trying with authentication below */ /* Continue trying with authentication below */
} }
else else
{ {
/* We failed with some weird reason (network issue maybe?) and it is unlikely /* We failed with some weird reason (network issue maybe?) and it is unlikely
* that adding some authentication will fix it. It will just cause a bad UX like * that adding some authentication will fix it. It will just cause a bad UX like
* described in #3753, so just return the error early. * described in #3753, so just return the error early.
*/ */
return error_request (request, sender, anon_error); return error_request (request, sender, anon_error);
skipping to change at line 551 skipping to change at line 551
} }
} }
/* Prompt the user for credentials */ /* Prompt the user for credentials */
n_refs = g_variant_n_children (arg_refs); n_refs = g_variant_n_children (arg_refs);
if (!have_auth && n_refs > 0 && if (!have_auth && n_refs > 0 &&
!no_interaction) !no_interaction)
{ {
g_autoptr(GVariant) ref_data = g_variant_get_child_value (arg_refs, 0); g_autoptr(GVariant) ref_data = g_variant_get_child_value (arg_refs, 0);
g_debug ("Trying user/password based authentication"); g_info ("Trying user/password based authentication");
while (auth == NULL) while (auth == NULL)
{ {
g_autofree char *test_auth = NULL; g_autofree char *test_auth = NULL;
test_auth = run_basic_auth (request, sender, oci_registry_uri, error ? error->message : NULL); test_auth = run_basic_auth (request, sender, oci_registry_uri, error ? error->message : NULL);
if (test_auth == NULL) if (test_auth == NULL)
return cancel_request (request, sender); return cancel_request (request, sender);
skipping to change at line 576 skipping to change at line 576
{ {
auth = g_steal_pointer (&test_auth); auth = g_steal_pointer (&test_auth);
have_auth = TRUE; have_auth = TRUE;
} }
else else
{ {
if (!g_error_matches (error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_AUTH ORIZED)) if (!g_error_matches (error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_AUTH ORIZED))
return error_request (request, sender, error); return error_request (request, sender, error);
else else
{ {
g_debug ("Auth failed getting token: %s", error->message); g_info ("Auth failed getting token: %s", error->message);
/* Keep error for reporting below, or clear on next iteration start */ /* Keep error for reporting below, or clear on next iteration start */
} }
} }
} }
} }
if (!have_auth && n_refs > 0) if (!have_auth && n_refs > 0)
return error_request (request, sender, error ? error : anon_error); return error_request (request, sender, error ? error : anon_error);
g_variant_builder_init (&tokens, G_VARIANT_TYPE ("a{sas}")); g_variant_builder_init (&tokens, G_VARIANT_TYPE ("a{sas}"));
skipping to change at line 612 skipping to change at line 612
return error_request (request, sender, error); return error_request (request, sender, error);
} }
g_variant_get_child (ref_data, 0, "&s", &for_refs_strv[0]); g_variant_get_child (ref_data, 0, "&s", &for_refs_strv[0]);
g_variant_builder_add (&tokens, "{s^as}", token, for_refs_strv); g_variant_builder_add (&tokens, "{s^as}", token, for_refs_strv);
} }
g_variant_builder_init (&results, G_VARIANT_TYPE ("a{sv}")); g_variant_builder_init (&results, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&results, "{sv}", "tokens", g_variant_builder_end (&tok ens)); g_variant_builder_add (&results, "{sv}", "tokens", g_variant_builder_end (&tok ens));
g_debug ("emitting OK response"); g_info ("emitting OK response");
flatpak_authenticator_request_emit_response (request, flatpak_authenticator_request_emit_response (request,
FLATPAK_AUTH_RESPONSE_OK, FLATPAK_AUTH_RESPONSE_OK,
g_variant_builder_end (&results)) ; g_variant_builder_end (&results)) ;
return G_DBUS_METHOD_INVOCATION_HANDLED; return G_DBUS_METHOD_INVOCATION_HANDLED;
} }
static gboolean static gboolean
flatpak_authorize_method_handler (GDBusInterfaceSkeleton *interface, flatpak_authorize_method_handler (GDBusInterfaceSkeleton *interface,
GDBusMethodInvocation *invocation, GDBusMethodInvocation *invocation,
skipping to change at line 639 skipping to change at line 639
return TRUE; return TRUE;
} }
static void static void
on_bus_acquired (GDBusConnection *connection, on_bus_acquired (GDBusConnection *connection,
const gchar *name, const gchar *name,
gpointer user_data) gpointer user_data)
{ {
GError *error = NULL; GError *error = NULL;
g_debug ("Bus acquired, creating skeleton"); g_info ("Bus acquired, creating skeleton");
g_dbus_connection_set_exit_on_close (connection, FALSE); g_dbus_connection_set_exit_on_close (connection, FALSE);
authenticator = flatpak_authenticator_skeleton_new (); authenticator = flatpak_authenticator_skeleton_new ();
flatpak_authenticator_set_version (authenticator, 0); flatpak_authenticator_set_version (authenticator, 0);
g_object_set_data_full (G_OBJECT (authenticator), "track-alive", GINT_TO_POINT ER (42), skeleton_died_cb); g_object_set_data_full (G_OBJECT (authenticator), "track-alive", GINT_TO_POINT ER (42), skeleton_died_cb);
g_signal_connect (authenticator, "handle-request-ref-tokens", G_CALLBACK (hand le_request_ref_tokens), NULL); g_signal_connect (authenticator, "handle-request-ref-tokens", G_CALLBACK (hand le_request_ref_tokens), NULL);
skipping to change at line 673 skipping to change at line 673
g_warning ("error: %s", error->message); g_warning ("error: %s", error->message);
g_error_free (error); g_error_free (error);
} }
} }
static void static void
on_name_acquired (GDBusConnection *connection, on_name_acquired (GDBusConnection *connection,
const gchar *name, const gchar *name,
gpointer user_data) gpointer user_data)
{ {
g_debug ("Name acquired"); g_info ("Name acquired");
} }
static void static void
on_name_lost (GDBusConnection *connection, on_name_lost (GDBusConnection *connection,
const gchar *name, const gchar *name,
gpointer user_data) gpointer user_data)
{ {
g_debug ("Name lost"); g_info ("Name lost");
} }
static void static void
message_handler (const gchar *log_domain, message_handler (const gchar *log_domain,
GLogLevelFlags log_level, GLogLevelFlags log_level,
const gchar *message, const gchar *message,
gpointer user_data) gpointer user_data)
{ {
/* Make this look like normal console output */ /* Make this look like normal console output */
if (log_level & G_LOG_LEVEL_DEBUG) if (log_level & (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO))
g_printerr ("F: %s\n", message); g_printerr ("F: %s\n", message);
else else
g_printerr ("%s: %s\n", g_get_prgname (), message); g_printerr ("%s: %s\n", g_get_prgname (), message);
} }
static void static void
name_owner_changed (GDBusConnection *connection, name_owner_changed (GDBusConnection *connection,
const gchar *sender_name, const gchar *sender_name,
const gchar *object_path, const gchar *object_path,
const gchar *interface_name, const gchar *interface_name,
skipping to change at line 763 skipping to change at line 763
g_printerr ("%s: %s", g_get_application_name (), error->message); g_printerr ("%s: %s", g_get_application_name (), error->message);
g_printerr ("\n"); g_printerr ("\n");
g_printerr ("Try \"%s --help\" for more information.", g_printerr ("Try \"%s --help\" for more information.",
g_get_prgname ()); g_get_prgname ());
g_printerr ("\n"); g_printerr ("\n");
g_option_context_free (context); g_option_context_free (context);
return 1; return 1;
} }
if (opt_verbose) if (opt_verbose)
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, message_handler, NULL); g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, message_handler, NULL);
g_debug ("Started flatpak-authenticator"); g_info ("Started flatpak-authenticator");
http_session = flatpak_create_http_session (PACKAGE_STRING); http_session = flatpak_create_http_session (PACKAGE_STRING);
session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (session_bus == NULL) if (session_bus == NULL)
{ {
g_printerr ("Can't find bus: %s\n", error->message); g_printerr ("Can't find bus: %s\n", error->message);
return 1; return 1;
} }
 End of changes. 19 change blocks. 
19 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)