#include <stdlib.h>
#include <string.h>
+#include "gioerror.h"
#include "gdbusutils.h"
#include "gdbusaddress.h"
#include "gdbuserror.h"
#include "gioenumtypes.h"
+#include "gnetworkaddress.h"
+#include "gsocketclient.h"
+#include "giostream.h"
+#include "gasyncresult.h"
+#include "gsimpleasyncresult.h"
#include "gdbusprivate.h"
#ifdef G_OS_UNIX
#include "config.h"
-#include <sys/types.h>
-#include <sys/socket.h>
-
#include "gdbusauth.h"
#include "gdbusauthmechanismanon.h"
#include "gioenumtypes.h"
#include "gcredentials.h"
#include "gdbusprivate.h"
+#include "giostream.h"
+#include "gdatainputstream.h"
+#include "gdataoutputstream.h"
#ifdef G_OS_UNIX
+#include <sys/types.h>
+#include <sys/socket.h>
#include "gunixconnection.h"
#include "gunixcredentialsmessage.h"
#endif
#if defined(G_OS_UNIX)
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.
+#warning Dont know how to send credentials on this OS. The EXTERNAL D-Bus authentication mechanism will not work.
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_REJECTED;
#endif
return initial_response;
#include "gdbuserror.h"
#include "gioenumtypes.h"
#include "gioerror.h"
+#include "gdbusprivate.h"
#include "glibintl.h"
#include "gioalias.h"
goto out;
}
#else
-#error Please implement permission checking on non-UNIX platforms
+#warning Please implement permission checking on this non-UNIX platform
#endif
}
goto out;
ret = FALSE;
lock = g_strdup_printf ("%s.lock", path);
- if (g_unlink (lock) != 0)
+ if (close (lock_fd) != 0)
{
g_set_error (error,
G_IO_ERROR,
g_io_error_from_errno (errno),
- _("Error unlinking lock-file `%s': %s"),
+ _("Error closing (unlinked) lock-file `%s': %s"),
lock,
strerror (errno));
goto out;
}
- if (close (lock_fd) != 0)
+ if (g_unlink (lock) != 0)
{
g_set_error (error,
G_IO_ERROR,
g_io_error_from_errno (errno),
- _("Error closing (unlinked) lock-file `%s': %s"),
+ _("Error unlinking lock-file `%s': %s"),
lock,
strerror (errno));
goto out;
}
}
#elif defined(G_OS_WIN32)
- GCredentials *credentials;
- credentials = g_credentials_new_for_process ();
- if (g_strcmp0 (g_credentials_get_windows_user (credentials), initial_response) == 0)
+ gchar *sid;
+ sid = _g_dbus_win32_get_user_sid ();
+ if (g_strcmp0 (initial_response, sid) == 0)
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_HAVE_DATA_TO_SEND;
- g_object_unref (credentials);
+ g_free (sid);
#else
#error Please implement for your OS
#endif
#ifdef G_OS_UNIX
initial_response = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) getuid ());
#elif defined (G_OS_WIN32)
- {
- GCredentials *credentials;
- credentials = g_credentials_new_for_process ();
- initial_response = g_strdup (g_credentials_get_windows_user (credentials));
- g_object_unref (credentials);
- }
+initial_response = _g_dbus_win32_get_user_sid ();
#else
+#error Please implement for your OS
#endif
g_assert (initial_response != NULL);
//g_debug ("haz unix fd passing powers: %d", connection->priv->capabilities & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING);
+#ifdef G_OS_UNIX
/* Hack used until
*
* https://bugzilla.gnome.org/show_bug.cgi?id=616458
{
g_socket_set_blocking (g_socket_connection_get_socket (G_SOCKET_CONNECTION (connection->priv->stream)), FALSE);
}
+#endif
connection->priv->worker = _g_dbus_worker_new (connection->priv->stream,
connection->priv->capabilities,
* g_dbus_message_new_method_call:
* @name: A valid D-Bus name or %NULL.
* @path: A valid object path.
- * @interface: A valid D-Bus interface name or %NULL.
+ * @interface_: A valid D-Bus interface name or %NULL.
* @method: A valid method name.
*
* Creates a new #GDBusMessage for a method call.
GDBusMessage *
g_dbus_message_new_method_call (const gchar *name,
const gchar *path,
- const gchar *interface,
+ const gchar *interface_,
const gchar *method)
{
GDBusMessage *message;
g_return_val_if_fail (name == NULL || g_dbus_is_name (name), NULL);
g_return_val_if_fail (g_variant_is_object_path (path), NULL);
g_return_val_if_fail (g_dbus_is_member_name (method), NULL);
- g_return_val_if_fail (interface == NULL || g_dbus_is_interface_name (interface), NULL);
+ g_return_val_if_fail (interface_ == NULL || g_dbus_is_interface_name (interface_), NULL);
message = g_dbus_message_new ();
message->priv->type = G_DBUS_MESSAGE_TYPE_METHOD_CALL;
g_dbus_message_set_destination (message, name);
g_dbus_message_set_path (message, path);
g_dbus_message_set_member (message, method);
- if (interface != NULL)
- g_dbus_message_set_interface (message, interface);
+ if (interface_ != NULL)
+ g_dbus_message_set_interface (message, interface_);
return message;
}
/**
* g_dbus_message_new_signal:
* @path: A valid object path.
- * @interface: A valid D-Bus interface name or %NULL.
+ * @interface_: A valid D-Bus interface name or %NULL.
* @signal: A valid signal name.
*
* Creates a new #GDBusMessage for a signal emission.
*/
GDBusMessage *
g_dbus_message_new_signal (const gchar *path,
- const gchar *interface,
+ const gchar *interface_,
const gchar *signal)
{
GDBusMessage *message;
g_return_val_if_fail (g_variant_is_object_path (path), NULL);
g_return_val_if_fail (g_dbus_is_member_name (signal), NULL);
- g_return_val_if_fail (interface == NULL || g_dbus_is_interface_name (interface), NULL);
+ g_return_val_if_fail (interface_ == NULL || g_dbus_is_interface_name (interface_), NULL);
message = g_dbus_message_new ();
message->priv->type = G_DBUS_MESSAGE_TYPE_SIGNAL;
g_dbus_message_set_path (message, path);
g_dbus_message_set_member (message, signal);
- if (interface != NULL)
- g_dbus_message_set_interface (message, interface);
+ if (interface_ != NULL)
+ g_dbus_message_set_interface (message, interface_);
return message;
}
GType g_dbus_message_get_type (void) G_GNUC_CONST;
GDBusMessage *g_dbus_message_new (void);
GDBusMessage *g_dbus_message_new_signal (const gchar *path,
- const gchar *interface,
+ const gchar *interface_,
const gchar *signal);
GDBusMessage *g_dbus_message_new_method_call (const gchar *name,
const gchar *path,
- const gchar *interface,
+ const gchar *interface_,
const gchar *method);
GDBusMessage *g_dbus_message_new_method_reply (GDBusMessage *method_call_message);
GDBusMessage *g_dbus_message_new_method_error (GDBusMessage *method_call_message,
#include "ginputstream.h"
#include "giostream.h"
#include "gsocketcontrolmessage.h"
+#include "gsocketconnection.h"
#ifdef G_OS_UNIX
#include "gunixfdmessage.h"
#include "gunixcredentialsmessage.h"
#endif
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
#include "glibintl.h"
#include "gioalias.h"
goto out;
}
+#ifdef G_OS_UNIX
if (worker->read_fd_list != NULL)
{
g_dbus_message_set_unix_fd_list (message, worker->read_fd_list);
worker->read_fd_list = NULL;
}
+#endif
if (G_UNLIKELY (_g_dbus_debug_message ()))
{
return g_string_free (s, FALSE);
}
+/* ---------------------------------------------------------------------------------------------------- */
+
+#ifdef G_OS_WIN32
+
+extern BOOL WINAPI ConvertSidToStringSidA (PSID Sid, LPSTR *StringSid);
+
+gchar *
+_g_dbus_win32_get_user_sid (void)
+{
+ HANDLE h;
+ TOKEN_USER *user;
+ DWORD token_information_len;
+ PSID psid;
+ gchar *sid;
+ gchar *ret;
+
+ ret = NULL;
+ user = NULL;
+ h = INVALID_HANDLE_VALUE;
+
+ if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &h))
+ {
+ g_warning ("OpenProcessToken failed with error code %d", (gint) GetLastError ());
+ goto out;
+ }
+
+ /* Get length of buffer */
+ token_information_len = 0;
+ if (!GetTokenInformation (h, TokenUser, NULL, 0, &token_information_len))
+ {
+ if (GetLastError () != ERROR_INSUFFICIENT_BUFFER)
+ {
+ g_warning ("GetTokenInformation() failed with error code %d", (gint) GetLastError ());
+ goto out;
+ }
+ }
+ user = g_malloc (token_information_len);
+ if (!GetTokenInformation (h, TokenUser, user, token_information_len, &token_information_len))
+ {
+ g_warning ("GetTokenInformation() failed with error code %d", (gint) GetLastError ());
+ goto out;
+ }
+
+ psid = user->User.Sid;
+ if (!IsValidSid (psid))
+ {
+ g_warning ("Invalid SID");
+ goto out;
+ }
+
+ if (!ConvertSidToStringSidA (psid, &sid))
+ {
+ g_warning ("Invalid SID");
+ goto out;
+ }
+
+ ret = g_strdup (sid);
+ LocalFree (sid);
+
+out:
+ g_free (user);
+ if (h != INVALID_HANDLE_VALUE)
+ CloseHandle (h);
+ return ret;
+}
+#endif
+
+/* ---------------------------------------------------------------------------------------------------- */
+
#define __G_DBUS_PRIVATE_C__
#include "gioaliasdef.c"
/* ---------------------------------------------------------------------------------------------------- */
+#ifdef G_OS_WIN32
+gchar *_g_dbus_win32_get_user_sid (void);
+#endif
+
G_END_DECLS
#endif /* __G_DBUS_PRIVATE_H__ */
#endif
#include "giotypes.h"
+#include "gioerror.h"
#include "gdbusaddress.h"
#include "gdbusutils.h"
#include "gdbusconnection.h"
#include "gio-marshal.h"
#include "ginitable.h"
#include "gsocketservice.h"
+#include "gthreadedsocketservice.h"
+#include "gresolver.h"
+#include "ginetaddress.h"
+#include "ginetsocketaddress.h"
+#include "ginputstream.h"
+#include "giostream.h"
#ifdef G_OS_UNIX
#include "gunixsocketaddress.h"
#if IN_HEADER(__G_FILE_DESCRIPTOR_BASED_H__)
#if IN_FILE(__G_FILE_DESCRIPTOR_BASED_C__)
+#ifdef G_OS_UNIX
g_file_descriptor_based_get_type G_GNUC_CONST
g_file_descriptor_based_get_fd
#endif
#endif
+#endif
#if IN_HEADER(__G_SETTINGS_BACKEND_H__)
#if IN_FILE(__G_KEYFILE_SETTINGS_BACKEND_C__)
g_credentials_get_native
g_credentials_set_native
g_credentials_is_same_user
+#ifdef G_OS_UNIX
g_credentials_get_unix_user
g_credentials_set_unix_user
#endif
#endif
+#endif
#if IN_HEADER(__G_DBUS_ADDRESS_H__)
#if IN_FILE(__G_DBUS_ADDRESS_C__)
g_dbus_message_get_serial
g_dbus_message_get_signature
g_dbus_message_get_message_type
-g_dbus_message_get_unix_fd_list
g_dbus_message_print
g_dbus_message_set_body
g_dbus_message_set_destination
g_dbus_message_set_serial
g_dbus_message_set_signature
g_dbus_message_set_message_type
-g_dbus_message_set_unix_fd_list
g_dbus_message_to_blob
g_dbus_message_to_gerror
+#ifdef G_OS_UNIX
+g_dbus_message_get_unix_fd_list
+g_dbus_message_set_unix_fd_list
+#endif
#endif
#endif
#if IN_HEADER(__G_UNIX_CREDENTIALS_MESSAGE_H__)
#if IN_FILE(__G_UNIX_CREDENTIALS_MESSAGE_C__)
+#ifdef G_OS_UNIX
g_unix_credentials_message_get_type G_GNUC_CONST
g_unix_credentials_message_new
g_unix_credentials_message_new_with_credentials
g_unix_credentials_message_is_supported
#endif
#endif
+#endif
#include <glib.h>
#include <glib/gstdio.h>
#include "gcancellable.h"
-#include "gfiledescriptorbased.h"
#include "gioerror.h"
#include "glocalfileinputstream.h"
#include "glocalfileinfo.h"
#include "glibintl.h"
+#ifdef G_OS_UNIX
+#include "gfiledescriptorbased.h"
+#endif
+
#ifdef G_OS_WIN32
#include <io.h>
#endif
#include "gioalias.h"
+#ifdef G_OS_UNIX
static void g_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface);
+#endif
+
#define g_local_file_input_stream_get_type _g_local_file_input_stream_get_type
G_DEFINE_TYPE_WITH_CODE (GLocalFileInputStream, g_local_file_input_stream, G_TYPE_FILE_INPUT_STREAM,
+#ifdef G_OS_UNIX
G_IMPLEMENT_INTERFACE (G_TYPE_FILE_DESCRIPTOR_BASED,
- g_file_descriptor_based_iface_init));
+ g_file_descriptor_based_iface_init)
+#endif
+);
struct _GLocalFileInputStreamPrivate {
int fd;
const char *attributes,
GCancellable *cancellable,
GError **error);
+#ifdef G_OS_UNIX
static int g_local_file_input_stream_get_fd (GFileDescriptorBased *stream);
+#endif
static void
g_local_file_input_stream_finalize (GObject *object)
file_stream_class->query_info = g_local_file_input_stream_query_info;
}
+#ifdef G_OS_UNIX
static void
g_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface)
{
iface->get_fd = g_local_file_input_stream_get_fd;
}
+#endif
static void
g_local_file_input_stream_init (GLocalFileInputStream *info)
error);
}
+#ifdef G_OS_UNIX
static int
g_local_file_input_stream_get_fd (GFileDescriptorBased *fd_based)
{
GLocalFileInputStream *stream = G_LOCAL_FILE_INPUT_STREAM (fd_based);
return stream->priv->fd;
}
-
+#endif
#include "glibintl.h"
#include "gioerror.h"
#include "gcancellable.h"
-#include "gfiledescriptorbased.h"
#include "glocalfileiostream.h"
#include "glocalfileinputstream.h"
#include "glocalfileinfo.h"
+#ifdef G_OS_UNIX
+#include "gfiledescriptorbased.h"
+#endif
+
#include "gioalias.h"
#define g_local_file_io_stream_get_type _g_local_file_io_stream_get_type
stream = g_object_new (G_TYPE_LOCAL_FILE_IO_STREAM, NULL);
stream->output_stream = g_object_ref (output_stream);
_g_local_file_output_stream_set_do_close (output_stream, FALSE);
- fd = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (output_stream));
+ fd = _g_local_file_output_stream_get_fd (output_stream);
stream->input_stream = (GInputStream *)_g_local_file_input_stream_new (fd);
+
_g_local_file_input_stream_set_do_close (G_LOCAL_FILE_INPUT_STREAM (stream->input_stream),
FALSE);
#include "glibintl.h"
#include "gioerror.h"
#include "gcancellable.h"
-#include "gfiledescriptorbased.h"
#include "glocalfileoutputstream.h"
#include "glocalfileinfo.h"
+#ifdef G_OS_UNIX
+#include "gfiledescriptorbased.h"
+#endif
+
#ifdef G_OS_WIN32
#include <io.h>
#ifndef S_ISDIR
#include "gioalias.h"
+#ifdef G_OS_UNIX
static void g_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface);
+#endif
+
#define g_local_file_output_stream_get_type _g_local_file_output_stream_get_type
G_DEFINE_TYPE_WITH_CODE (GLocalFileOutputStream, g_local_file_output_stream, G_TYPE_FILE_OUTPUT_STREAM,
+#ifdef G_OS_UNIX
G_IMPLEMENT_INTERFACE (G_TYPE_FILE_DESCRIPTOR_BASED,
- g_file_descriptor_based_iface_init));
+ g_file_descriptor_based_iface_init)
+#endif
+ );
/* Some of the file replacement code was based on the code from gedit,
goffset size,
GCancellable *cancellable,
GError **error);
+#ifdef G_OS_UNIX
static int g_local_file_output_stream_get_fd (GFileDescriptorBased *stream);
+#endif
static void
g_local_file_output_stream_finalize (GObject *object)
file_stream_class->truncate_fn = g_local_file_output_stream_truncate;
}
+#ifdef G_OS_UNIX
static void
g_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface)
{
iface->get_fd = g_local_file_output_stream_get_fd;
}
+#endif
static void
g_local_file_output_stream_init (GLocalFileOutputStream *stream)
return G_FILE_OUTPUT_STREAM (stream);
}
+gint
+_g_local_file_output_stream_get_fd (GLocalFileOutputStream *stream)
+{
+ g_return_val_if_fail (G_IS_LOCAL_FILE_OUTPUT_STREAM (stream), -1);
+ return stream->priv->fd;
+}
+
+#ifdef G_OS_UNIX
static int
g_local_file_output_stream_get_fd (GFileDescriptorBased *fd_based)
{
GLocalFileOutputStream *stream = G_LOCAL_FILE_OUTPUT_STREAM (fd_based);
-
- return stream->priv->fd;
+ return _g_local_file_output_stream_get_fd (stream);
}
-
+#endif
GCancellable *cancellable,
GError **error);
+/* Hack to get the fd since GFileDescriptorBased (which is how you
+ * _should_ get the fd) is only available on UNIX but things like
+ * win32 needs this as well
+ */
+gint _g_local_file_output_stream_get_fd (GLocalFileOutputStream *output_stream);
+
G_END_DECLS
#endif /* __G_LOCAL_FILE_OUTPUT_STREAM_H__ */
gdbus_error_SOURCES = gdbus-error.c gdbus-sessionbus.c gdbus-sessionbus.h gdbus-tests.h gdbus-tests.c
gdbus_error_LDADD = $(progs_ldadd)
-gdbus_peer_SOURCES = gdbus-peer.c gdbus-sessionbus.c gdbus-sessionbus.h gdbus-tests.h gdbus-tests.c
+gdbus_peer_SOURCES = gdbus-peer.c gdbus-tests.h gdbus-tests.c
gdbus_peer_LDADD = $(progs_ldadd)
gdbus_exit_on_close_SOURCES = gdbus-exit-on-close.c gdbus-sessionbus.c gdbus-sessionbus.h gdbus-tests.h gdbus-tests.c
}
else if (g_strcmp0 (method_name, "OpenFile") == 0)
{
+#ifdef G_OS_UNIX
const gchar *path;
GDBusMessage *reply;
GError *error;
&error);
g_assert_no_error (error);
g_object_unref (reply);
+#else
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ "org.gtk.GDBus.NotOnUnix",
+ "Your OS does not support file descriptor passing");
+#endif
}
else
{
g_assert_cmpstr (buf, ==, buf2);
g_free (buf2);
}
+#else
+ error = NULL;
+ result = g_dbus_proxy_call_sync (proxy,
+ "OpenFile",
+ g_variant_new ("(s)", "boo"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL, /* GCancellable */
+ &error);
+ g_assert_error (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR);
+ g_assert (result == NULL);
+ g_error_free (error);
#endif /* G_OS_UNIX */