[kdbus] Update kdbus interface header (commit: b620b72c9127) 14/10/16
[platform/upstream/glib.git] / gio / gdbusauthmechanismexternal.c
index 3307e85..c456ce2 100644 (file)
@@ -1,6 +1,6 @@
 /* GDBus - GLib D-Bus Library
  *
- * Copyright (C) 2008-2009 Red Hat, Inc.
+ * Copyright (C) 2008-2010 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -13,9 +13,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  * Author: David Zeuthen <davidz@redhat.com>
  */
 #include "gdbuserror.h"
 #include "gioenumtypes.h"
 
-#ifdef G_OS_UNIX
-#include <sys/types.h>
-#include <unistd.h>
-#endif
-
 #include "glibintl.h"
 
 struct _GDBusAuthMechanismExternalPrivate
@@ -78,7 +71,7 @@ static void                     mechanism_client_shutdown           (GDBusAuthMe
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-G_DEFINE_TYPE (GDBusAuthMechanismExternal, _g_dbus_auth_mechanism_external, G_TYPE_DBUS_AUTH_MECHANISM);
+G_DEFINE_TYPE_WITH_PRIVATE (GDBusAuthMechanismExternal, _g_dbus_auth_mechanism_external, G_TYPE_DBUS_AUTH_MECHANISM)
 
 /* ---------------------------------------------------------------------------------------------------- */
 
@@ -97,8 +90,6 @@ _g_dbus_auth_mechanism_external_class_init (GDBusAuthMechanismExternalClass *kla
   GObjectClass *gobject_class;
   GDBusAuthMechanismClass *mechanism_class;
 
-  g_type_class_add_private (klass, sizeof (GDBusAuthMechanismExternalPrivate));
-
   gobject_class = G_OBJECT_CLASS (klass);
   gobject_class->finalize = _g_dbus_auth_mechanism_external_finalize;
 
@@ -124,9 +115,7 @@ _g_dbus_auth_mechanism_external_class_init (GDBusAuthMechanismExternalClass *kla
 static void
 _g_dbus_auth_mechanism_external_init (GDBusAuthMechanismExternal *mechanism)
 {
-  mechanism->priv = G_TYPE_INSTANCE_GET_PRIVATE (mechanism,
-                                                 G_TYPE_DBUS_AUTH_MECHANISM_EXTERNAL,
-                                                 GDBusAuthMechanismExternalPrivate);
+  mechanism->priv = _g_dbus_auth_mechanism_external_get_instance_private (mechanism);
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -210,27 +199,14 @@ data_matches_credentials (const gchar *data,
     alleged_uid = g_ascii_strtoll (data, &endp, 10);
     if (*endp == '\0')
       {
-        if (g_credentials_has_unix_user (credentials) &&
-            g_credentials_get_unix_user (credentials) == alleged_uid)
+        if (g_credentials_get_unix_user (credentials, NULL) == alleged_uid)
           {
             match = TRUE;
           }
       }
   }
-#elif defined(G_OS_WIN32)
-  {
-    const gchar *alleged_sid;
-
-    /* on Win32, this is the User SID */
-    alleged_sid = data;
-    if (g_credentials_has_windows_user (credentials) &&
-        g_strcmp0 (g_credentials_get_windows_user (credentials), alleged_sid) == 0)
-      {
-        match = TRUE;
-      }
-  }
 #else
-#error Dont know how to read credentials on this OS. Please implement.
+  /* TODO: Dont know how to compare credentials on this OS. Please implement. */
 #endif
 
  out:
@@ -347,7 +323,7 @@ mechanism_client_initiate (GDBusAuthMechanism   *mechanism,
                            gsize                *out_initial_response_len)
 {
   GDBusAuthMechanismExternal *m = G_DBUS_AUTH_MECHANISM_EXTERNAL (mechanism);
-  gchar *initial_response;
+  gchar *initial_response = NULL;
   GCredentials *credentials;
 
   g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM_EXTERNAL (mechanism), NULL);
@@ -363,11 +339,11 @@ mechanism_client_initiate (GDBusAuthMechanism   *mechanism,
 
   /* return the uid */
 #if defined(G_OS_UNIX)
-  initial_response = g_strdup_printf ("%" G_GINT64_FORMAT, g_credentials_get_unix_user (credentials));
+  initial_response = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) g_credentials_get_unix_user (credentials, NULL));
 #elif defined(G_OS_WIN32)
-  initial_response = g_strdup_printf ("%s", g_credentials_get_windows_user ());
-#else
-#warning Dont know how to send credentials on this OS. Please implement.
+#ifdef __GNUC__
+#warning Dont know how to send credentials on this OS. The EXTERNAL D-Bus authentication mechanism will not work.
+#endif
   m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_REJECTED;
 #endif
   return initial_response;