From 07b6e82910238b8abff8124d067634df0a00dd9d Mon Sep 17 00:00:00 2001 From: guidog Date: Sat, 10 Jan 2009 13:25:26 +0000 Subject: move dbus handling into a separate file git-svn-id: http://svn.gnome.org/svn/krb5-auth-dialog/trunk@102 517b70f8-ed25-0410-8bf6-f5db08f7b76e --- ChangeLog | 7 +++++ src/Makefile.am | 2 ++ src/krb5-auth-dbus.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/krb5-auth-dbus.h | 28 ++++++++++++++++++ src/krb5-auth-dialog.c | 49 ++++--------------------------- 5 files changed, 121 insertions(+), 43 deletions(-) create mode 100644 src/krb5-auth-dbus.c create mode 100644 src/krb5-auth-dbus.h diff --git a/ChangeLog b/ChangeLog index 005e023..c88d2af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sun Jan 4 14:48:14 CET 2009 Guido Günther + + move dbus handling into a separate file + * src/krb5-auth-dbus.[ch]: new file + * src/krb5-auth-dialog.c: remove dbus related code + * src/Makefile.am (krb5_auth_dialog_SOURCES): add krb5-auth-dbus.[ch] + Sun Jan 4 14:39:16 CET 2009 Guido Günther add gtksecentry/secmem from gpg pinentry diff --git a/src/Makefile.am b/src/Makefile.am index cff044e..e447bb0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,6 +19,8 @@ krb5_auth_dialog_SOURCES = \ krb5-auth-gconf.h \ krb5-auth-notify.c \ krb5-auth-notify.h \ + krb5-auth-dbus.c \ + krb5-auth-dbus.h \ dummy-strings.c krb5_auth_dialog_LDADD = \ diff --git a/src/krb5-auth-dbus.c b/src/krb5-auth-dbus.c new file mode 100644 index 0000000..f658c8d --- /dev/null +++ b/src/krb5-auth-dbus.c @@ -0,0 +1,78 @@ +/* Krb5 Auth Applet -- Acquire and release kerberos tickets + * + * (C) 2008 Guido Guenther + * + * 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 + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include "krb5-auth-applet.h" +#include "krb5-auth-dbus.h" + +gboolean +ka_dbus_connect(unsigned int* status) +{ + guint request_name_reply; + unsigned int flags; + DBusGConnection *session; + DBusGProxy *bus_proxy; + GError* error = NULL; + + /* Connect to the session bus so we get exit-on-disconnect semantics. */ + session = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (session == NULL) { + g_error ("couldn't connect to session bus: %s", (error) ? error->message : "(null)"); + *status = 1; + return FALSE; + } + flags = DBUS_NAME_FLAG_DO_NOT_QUEUE; + bus_proxy = dbus_g_proxy_new_for_name (session, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus"); + + if (!dbus_g_proxy_call (bus_proxy, + "RequestName", + &error, + G_TYPE_STRING, + "org.gnome.KrbAuthDialog", + G_TYPE_UINT, + flags, + G_TYPE_INVALID, + G_TYPE_UINT, + &request_name_reply, + G_TYPE_INVALID)) { + g_warning ("Failed to invoke RequestName: %s", + error->message); + } + g_clear_error (&error); + g_object_unref (bus_proxy); + + if (request_name_reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER + || request_name_reply == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER) + ; + else if (request_name_reply == DBUS_REQUEST_NAME_REPLY_EXISTS + || request_name_reply == DBUS_REQUEST_NAME_REPLY_IN_QUEUE) { + *status = 0; + return FALSE; + } else { + g_assert_not_reached(); + } + return TRUE; +} + diff --git a/src/krb5-auth-dbus.h b/src/krb5-auth-dbus.h new file mode 100644 index 0000000..6ef0bf0 --- /dev/null +++ b/src/krb5-auth-dbus.h @@ -0,0 +1,28 @@ +/* Krb5 Auth Applet -- Acquire and release kerberos tickets + * + * (C) 2008 Guido Guenther + * + * 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 + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef KRB5_AUTH_DBUS_H +#define KRB5_AUTH_DBUS_H + +#include + +gboolean ka_dbus_connect(unsigned int* status); + +#endif /* KRB5_AUTH_DBUS_H */ diff --git a/src/krb5-auth-dialog.c b/src/krb5-auth-dialog.c index 9942d35..a140e99 100644 --- a/src/krb5-auth-dialog.c +++ b/src/krb5-auth-dialog.c @@ -29,11 +29,11 @@ #include #include #include -#include #include "krb5-auth-dialog.h" #include "krb5-auth-applet.h" #include "krb5-auth-gconf.h" +#include "krb5-auth-dbus.h" #ifdef ENABLE_NETWORK_MANAGER #include @@ -663,11 +663,10 @@ main (int argc, char *argv[]) Krb5AuthApplet *applet; GOptionContext *context; GError *error = NULL; - DBusGConnection *session; - DBusGProxy *bus_proxy; - guint request_name_reply; - unsigned int flags; + + guint status = 0; gboolean run_auto = FALSE, run_always = FALSE; + const char *help_msg = "Run '" PACKAGE " --help' to see a full list of available command line options"; const GOptionEntry options [] = { {"auto", 'a', 0, G_OPTION_ARG_NONE, &run_auto, @@ -696,44 +695,8 @@ main (int argc, char *argv[]) bind_textdomain_codeset (PACKAGE, "UTF-8"); bindtextdomain (PACKAGE, LOCALE_DIR); - /* Connect to the session bus so we get exit-on-disconnect semantics. */ - session = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (session == NULL) { - g_error ("couldn't connect to session bus: %s", (error) ? error->message : "(null)"); - exit(1); - } - flags = DBUS_NAME_FLAG_DO_NOT_QUEUE; - bus_proxy = dbus_g_proxy_new_for_name (session, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus"); - - if (!dbus_g_proxy_call (bus_proxy, - "RequestName", - &error, - G_TYPE_STRING, - "org.gnome.KrbAuthDialog", - G_TYPE_UINT, - flags, - G_TYPE_INVALID, - G_TYPE_UINT, - &request_name_reply, - G_TYPE_INVALID)) { - g_warning ("Failed to invoke RequestName: %s", - error->message); - } - g_clear_error (&error); - g_object_unref (bus_proxy); - - if (request_name_reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER - || request_name_reply == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER) - ; - else if (request_name_reply == DBUS_REQUEST_NAME_REPLY_EXISTS - || request_name_reply == DBUS_REQUEST_NAME_REPLY_IN_QUEUE) - exit(0); - else { - g_assert_not_reached(); - } + if (!ka_dbus_connect (&status)) + exit(status); if (run_always && !run_auto) { always_run = TRUE; -- cgit v1.2.3