[krb5-auth-dialog] Send DBUS signals on ticket acquisition, expiery and renewal
- From: Guido Günther <guidog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [krb5-auth-dialog] Send DBUS signals on ticket acquisition, expiery and renewal
- Date: Fri, 2 Apr 2010 14:19:05 +0000 (UTC)
commit f5940e34ffa6e42065a50273c9967f3c6c77fc5e
Author: Guido Günther <agx sigxcpu org>
Date: Thu Mar 25 21:41:18 2010 +0100
Send DBUS signals on ticket acquisition, expiery and renewal
allows external helpers to perform actions like running aklog.
src/krb5-auth-applet-dbus.xml | 12 ++++++++++
src/krb5-auth-applet.c | 48 +++++++++++++++++++++++++++++++++++++++-
src/krb5-auth-applet.h | 10 ++++++++
src/krb5-auth-dialog.c | 32 +++++++++++++++++++++++++-
src/krb5-auth-dialog.h | 1 +
5 files changed, 99 insertions(+), 4 deletions(-)
---
diff --git a/src/krb5-auth-applet-dbus.xml b/src/krb5-auth-applet-dbus.xml
index c96126c..0908ec6 100644
--- a/src/krb5-auth-applet-dbus.xml
+++ b/src/krb5-auth-applet-dbus.xml
@@ -14,6 +14,18 @@
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<arg type="b" name="success" direction="out"/>
</method>
+ <signal name="krb_tgt_acquired">
+ <arg type="s" name="principal" direction ="out"/>
+ <arg type="u" name="expiry" direction ="out"/>
+ </signal>
+ <signal name="krb_tgt_renewed">
+ <arg type="s" name="principal" direction ="out"/>
+ <arg type="u" name="expiry" direction ="out"/>
+ </signal>
+ <signal name="krb_tgt_expired">
+ <arg type="s" name="principal" direction ="out"/>
+ <arg type="u" name="expiry" direction ="out"/>
+ </signal>
</interface>
</node>
diff --git a/src/krb5-auth-applet.c b/src/krb5-auth-applet.c
index 1d144e0..dd621a0 100644
--- a/src/krb5-auth-applet.c
+++ b/src/krb5-auth-applet.c
@@ -1,6 +1,6 @@
/* Krb5 Auth Applet -- Acquire and release kerberos tickets
*
- * (C) 2008,2009 Guido Guenther <agx sigxcpu org>
+ * (C) 2008,2009,2010 Guido Guenther <agx sigxcpu org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -61,6 +61,8 @@ struct _KaApplet {
struct _KaAppletClass {
GObjectClass parent;
+
+ guint signals [KA_SIGNAL_COUNT];
};
G_DEFINE_TYPE(KaApplet, ka_applet, G_TYPE_OBJECT);
@@ -251,6 +253,11 @@ ka_applet_class_init(KaAppletClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
GParamSpec *pspec;
+ const gchar *signalNames [ KA_SIGNAL_COUNT ] = {
+ "krb-tgt-acquired",
+ "krb-tgt-renewed",
+ "krb-tgt-expired"};
+ int i;
object_class->dispose = ka_applet_dispose;
object_class->finalize = ka_applet_finalize;
@@ -330,6 +337,23 @@ ka_applet_class_init(KaAppletClass *klass)
g_object_class_install_property (object_class,
KA_PROP_TGT_RENEWABLE,
pspec);
+
+ for (i = 0; i < KA_SIGNAL_COUNT ; i++) {
+ guint signalId;
+ signalId =
+ g_signal_new ( signalNames [i],
+ G_OBJECT_CLASS_TYPE ( klass ),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE,
+ 2, /* number of parameters */
+ G_TYPE_STRING,
+ G_TYPE_UINT);
+ klass->signals [i] = signalId ;
+ }
}
@@ -474,7 +498,10 @@ ka_send_event_notification (KaApplet *applet G_GNUC_UNUSED,
#endif /* ! HAVE_LIBNOTIFY */
-/* update the tray icon's tooltip and icon */
+/*
+ * update the tray icon's tooltip and icon
+ * and notify listeners about acquired/expiring tickets via signals
+ */
int
ka_applet_update_status(KaApplet* applet, krb5_timestamp expiry)
{
@@ -499,6 +526,7 @@ ka_applet_update_status(KaApplet* applet, krb5_timestamp expiry)
"krb-valid-ticket",
"dont-show-again");
}
+ ka_applet_signal_emit (applet, KA_SIGNAL_ACQUIRED_TGT, expiry);
expiry_notified = FALSE;
} else if (remaining < applet->priv->pw_prompt_secs && (now - last_warn) > NOTIFY_SECONDS &&
!applet->priv->renewable) {
@@ -528,6 +556,7 @@ ka_applet_update_status(KaApplet* applet, krb5_timestamp expiry)
"krb-no-valid-ticket",
"dont-show-again");
}
+ ka_applet_signal_emit (applet, KA_SIGNAL_EXPIRED_TGT, expiry);
expiry_notified = TRUE;
last_warn = 0;
}
@@ -835,6 +864,21 @@ ka_applet_get_pwdialog(const KaApplet* applet)
return applet->priv->pwdialog;
}
+void
+ka_applet_signal_emit (KaApplet* this, KaAppletSignalNumber signum,
+ krb5_timestamp expiry)
+{
+ KaAppletClass *klass = KA_APPLET_GET_CLASS (this);
+ char *princ;
+
+ princ = ka_unparse_name ();
+ if (!princ)
+ return;
+
+ g_signal_emit (this, klass->signals[signum], 0, princ, (guint32)expiry);
+ g_free (princ);
+}
+
/* create the tray icon applet */
KaApplet*
ka_applet_create()
diff --git a/src/krb5-auth-applet.h b/src/krb5-auth-applet.h
index 06e45f9..e0f32e4 100644
--- a/src/krb5-auth-applet.h
+++ b/src/krb5-auth-applet.h
@@ -50,12 +50,22 @@ typedef struct _KaAppletPrivate KaAppletPrivate;
GType ka_applet_get_type (void);
+/* signals emitted by KaApplet */
+typedef enum {
+ KA_SIGNAL_ACQUIRED_TGT, /* New TGT acquired */
+ KA_SIGNAL_RENEWED_TGT, /* TGT got renewed */
+ KA_SIGNAL_EXPIRED_TGT, /* TGT expired or ticket cache got destroyed */
+ KA_SIGNAL_COUNT
+} KaAppletSignalNumber;
+
/* public functions */
gboolean ka_applet_get_show_trayicon(const KaApplet* applet);
void ka_applet_set_tgt_renewable(KaApplet* applet, gboolean renewable);
gboolean ka_applet_get_tgt_renewable(const KaApplet* applet);
guint ka_applet_get_pw_prompt_secs(const KaApplet* applet);
KaPwDialog* ka_applet_get_pwdialog(const KaApplet* applet);
+void ka_applet_signal_emit(KaApplet* applet, KaAppletSignalNumber signum,
+ krb5_timestamp expiry);
/* create the applet */
KaApplet* ka_applet_create(void);
diff --git a/src/krb5-auth-dialog.c b/src/krb5-auth-dialog.c
index 5f6f2ec..7b2933b 100644
--- a/src/krb5-auth-dialog.c
+++ b/src/krb5-auth-dialog.c
@@ -2,7 +2,7 @@
* Copyright (C) 2004,2005,2006 Red Hat, Inc.
* Authored by Christopher Aillon <caillon redhat com>
*
- * Copyright (C) 2008,2009 Guido Guenther <agx sigxcpu org>
+ * Copyright (C) 2008,2009,2010 Guido Guenther <agx sigxcpu org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -229,7 +229,6 @@ credentials_expiring_real (KaApplet* applet)
}
krb5_free_cred_contents (kcontext, &my_creds);
-
out:
ka_applet_update_status(applet, creds_expiry);
return retval;
@@ -679,6 +678,32 @@ ka_parse_name(KaApplet* applet, krb5_context krbcontext, krb5_principal* kprinc)
}
+/*
+ * return current principal in text form
+ *
+ * caller needs to free the returned result using g_free();
+ */
+char*
+ka_unparse_name ()
+{
+ char *princ, *gprinc = NULL;
+ krb5_error_code err;
+
+ if (!kprincipal)
+ goto out;
+
+ if ((err = krb5_unparse_name (kcontext, kprincipal, &princ))) {
+ ka_log_error_message(__func__, kcontext, err);
+ goto out;
+ }
+
+ gprinc = g_strdup (princ);
+ free (princ);
+out:
+ return gprinc;
+}
+
+
static void
ccache_changed_cb (GFileMonitor *monitor G_GNUC_UNUSED,
GFile *file,
@@ -858,6 +883,8 @@ ka_renew_credentials (KaApplet* applet)
ka_log_error_message("krb5_cc_store_cred", kcontext, retval);
goto out;
}
+ ka_applet_signal_emit (applet, KA_SIGNAL_RENEWED_TGT,
+ my_creds.times.endtime);
}
out:
creds_expiry = my_creds.times.endtime;
@@ -1123,6 +1150,7 @@ main (int argc, char *argv[])
if (run_always && !run_auto) {
always_run = TRUE;
}
+
if (using_krb5 () || always_run) {
g_set_application_name (KA_NAME);
diff --git a/src/krb5-auth-dialog.h b/src/krb5-auth-dialog.h
index ae13159..48cd0b0 100644
--- a/src/krb5-auth-dialog.h
+++ b/src/krb5-auth-dialog.h
@@ -27,6 +27,7 @@ gboolean ka_destroy_ccache (KaApplet* applet);
gboolean ka_grab_credentials(KaApplet* applet);
gboolean ka_check_credentials (KaApplet *applet, const char* principal);
gboolean ka_get_service_tickets(GtkListStore *tickets);
+char* ka_unparse_name(void);
int ka_tgt_valid_seconds(void);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]