* cmake/ConfigureChecks.cmake,cmake/config.h.cmake: added check for HAVE_ERRNO_H

* cmake/dbus/CMakeLists.txt: added missing files
* dbus/dbus-transport-win.c/.h: new files
* dbus/dbus-sysdeps-win.c,.h: added required _unix functions to make dbus compilable on win32
* dbus/dbus-sysdeps-win-utils.c,.h: moved some functions to dbus-sysdeps-win.c
* dbus-win.patch: removed applied or obsolate patches
Note: dbus-win32 is now compilable, no guarantee that it runs without any problems
This commit is contained in:
Ralf Habacker 2007-06-15 21:04:43 +00:00
parent b62633b919
commit d9b9b45554
9 changed files with 551 additions and 484 deletions

View file

@ -13,6 +13,7 @@ check_include_file(time.h HAVE_TIME_H) # dbus-sysdeps-win.c
check_include_file(unistd.h HAVE_UNISTD_H) # dbus-sysdeps-util-win.c
check_include_file(stdio.h HAVE_STDIO_H) # dbus-sysdeps.h
check_include_file(sys/syslimits.h HAVE_SYS_SYSLIMITS_H) # dbus-sysdeps-unix.c
check_include_file(errno.h HAVE_ERRNO_H) # dbus-sysdeps.c
check_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE) # dbus-sysdeps.c, dbus-sysdeps-win.c
check_symbol_exists(getgrouplist "grp.h" HAVE_GETGROUPLIST) # dbus-sysdeps.c

View file

@ -85,6 +85,9 @@
/* Define to 1 if you have unistd.h */
#cmakedefine HAVE_UNISTD_H 1
/* Define to 1 if you have errno.h */
#cmakedefine HAVE_ERRNO_H 1
/* Define to 1 if you have stdio.h */
#cmakedefine HAVE_STDIO_H 1

View file

@ -14,6 +14,7 @@ set (dbusinclude_HEADERS
${DBUS_DIR}/dbus-address.h
${DBUS_DIR}/dbus-bus.h
${DBUS_DIR}/dbus-connection.h
${DBUS_DIR}/dbus-credentials.h
${DBUS_DIR}/dbus-errors.h
${DBUS_DIR}/dbus-macros.h
${DBUS_DIR}/dbus-memory.h
@ -37,6 +38,7 @@ set (DBUS_LIB_SOURCES
${DBUS_DIR}/dbus-auth-script.c
${DBUS_DIR}/dbus-bus.c
${DBUS_DIR}/dbus-connection.c
${DBUS_DIR}/dbus-credentials.c
${DBUS_DIR}/dbus-errors.c
${DBUS_DIR}/dbus-keyring.c
${DBUS_DIR}/dbus-marshal-header.c
@ -64,14 +66,14 @@ set (DBUS_LIB_SOURCES
# and move code to a *-win.c file
)
if(UNIX)
set (DBUS_LIB_SOURCES ${DBUS_LIB_SOURCES}
${DBUS_DIR}/dbus-transport-unix.c
${DBUS_DIR}/dbus-server-unix.c
set (DBUS_LIB_SOURCES ${DBUS_LIB_SOURCES}
${DBUS_DIR}/dbus-transport-unix.c
${DBUS_DIR}/dbus-server-unix.c
)
else(UNIX)
set (DBUS_LIB_SOURCES ${DBUS_LIB_SOURCES}
# ${DBUS_DIR}/dbus-transport-win.c
${DBUS_DIR}/dbus-server-win.c
set (DBUS_LIB_SOURCES ${DBUS_LIB_SOURCES}
${DBUS_DIR}/dbus-transport-win.c
${DBUS_DIR}/dbus-server-win.c
)
endif(UNIX)
@ -99,11 +101,21 @@ set (DBUS_LIB_HEADERS
${DBUS_DIR}/dbus-threads-internal.h
${DBUS_DIR}/dbus-transport.h
${DBUS_DIR}/dbus-transport-protected.h
${DBUS_DIR}/dbus-transport-unix.h
${DBUS_DIR}/dbus-watch.h
${CMAKE_BINARY_DIR}/config.h
##dbus-md5.h
)
if(UNIX)
set (DBUS_LIB_HEADERS ${DBUS_LIB_HEADERS}
${DBUS_DIR}/dbus-transport-unix.h
)
else(UNIX)
set (DBUS_LIB_HEADERS ${DBUS_LIB_HEADERS}
${DBUS_DIR}/dbus-transport-win.h
)
endif(UNIX)
### source code that goes in the installed client library
### AND is generic utility functionality used by the
### daemon or test programs (all symbols in here should
@ -119,8 +131,8 @@ set (DBUS_SHARED_SOURCES
${DBUS_DIR}/dbus-string.c
${DBUS_DIR}/dbus-sysdeps.c
${DBUS_DIR}/dbus-sysdeps-util.c
${DBUS_DIR}/dbus-userdb.c
)
# ${DBUS_DIR}/dbus-userdb.c
set (DBUS_SHARED_HEADERS
${DBUS_DIR}/dbus-dataslot.h
@ -142,6 +154,7 @@ set (DBUS_SHARED_HEADERS
### to be unless they move to DBUS_SHARED_SOURCES later)
set (DBUS_UTIL_SOURCES
${DBUS_DIR}/dbus-auth-util.c
${DBUS_DIR}/dbus-credentials-util.c
${DBUS_DIR}/dbus-mainloop.c
${DBUS_DIR}/dbus-marshal-byteswap-util.c
${DBUS_DIR}/dbus-marshal-recursive-util.c
@ -150,8 +163,8 @@ set (DBUS_UTIL_SOURCES
${DBUS_DIR}/dbus-message-util.c
${DBUS_DIR}/dbus-shell.c
${DBUS_DIR}/dbus-string-util.c
${DBUS_DIR}/dbus-userdb-util.c
)
#${DBUS_DIR}/dbus-userdb-util.c
if (DBUS_BUILD_TESTS)
set (DBUS_UTIL_SOURCES
@ -177,9 +190,9 @@ if (WIN32)
${DBUS_DIR}/dbus-spawn-win.c
)
set (DBUS_SHARED_HEADERS ${DBUS_SHARED_HEADERS}
${DBUS_DIR}/dbus-sockets-win.h
${DBUS_DIR}/dbus-sysdeps-win.h
)
${DBUS_DIR}/dbus-sockets-win.h
${DBUS_DIR}/dbus-sysdeps-win.h
)
set (LIBS ${LIBS} ws2_32 advapi32 netapi32)
else (WIN32)
@ -190,10 +203,10 @@ else (WIN32)
${DBUS_DIR}/dbus-spawn.c
)
set (DBUS_SHARED_HEADERS ${DBUS_SHARED_HEADERS}
${DBUS_DIR}/dbus-server-unix.h
${DBUS_DIR}/dbus-transport-unix.h
${DBUS_DIR}/dbus-sysdeps-unix.h
)
${DBUS_DIR}/dbus-server-unix.h
${DBUS_DIR}/dbus-transport-unix.h
${DBUS_DIR}/dbus-sysdeps-unix.h
)
endif (WIN32)
set(libdbus_SOURCES

View file

@ -1,92 +1,3 @@
Index: bus/config-loader-expat.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/config-loader-expat.c,v
retrieving revision 1.10
diff -u -r1.10 config-loader-expat.c
--- bus/config-loader-expat.c 10 Aug 2004 03:06:59 -0000 1.10
+++ bus/config-loader-expat.c 8 Mar 2007 20:25:42 -0000
@@ -161,6 +161,9 @@
}
}
+#ifdef DBUS_WIN
+DBusString *_dbus_get_working_dir(void);
+#endif
BusConfigParser*
bus_config_load (const DBusString *file,
@@ -171,6 +174,9 @@
XML_Parser expat;
const char *filename;
BusConfigParser *parser;
+#ifdef DBUS_WIN
+ DBusString *dbusdir;
+#endif
ExpatParseContext context;
DBusString dirname;
@@ -209,6 +215,12 @@
goto failed;
}
+#ifdef DBUS_WIN
+ dbusdir = _dbus_get_working_dir();
+ if (dbusdir)
+ parser = bus_config_parser_new (dbusdir, is_toplevel, parent);
+ else
+#endif
parser = bus_config_parser_new (&dirname, is_toplevel, parent);
if (parser == NULL)
{
Index: bus/config-loader-libxml.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/config-loader-libxml.c,v
retrieving revision 1.8
diff -u -r1.8 config-loader-libxml.c
--- bus/config-loader-libxml.c 10 Aug 2004 03:06:59 -0000 1.8
+++ bus/config-loader-libxml.c 8 Mar 2007 20:25:40 -0000
@@ -134,6 +134,9 @@
}
}
+#ifdef DBUS_WIN
+ DBusString *_dbus_get_working_dir(void);
+#endif
BusConfigParser*
bus_config_load (const DBusString *file,
@@ -147,7 +150,9 @@
DBusString dirname, data;
DBusError tmp_error;
int ret;
-
+#ifdef DBUS_WIN
+ DBusString *dbusdir;
+#endif
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
parser = NULL;
@@ -177,13 +182,19 @@
xmlSetGenericErrorFunc (NULL, xml_shut_up);
}
+#ifdef DBUS_WIN
+ dbusdir = _dbus_get_working_dir();
+ if (dbusdir)
+ parser = bus_config_parser_new (dbusdir, is_toplevel, parent);
+ else
+#endif
if (!_dbus_string_get_dirname (file, &dirname))
{
_DBUS_SET_OOM (error);
goto failed;
}
-
parser = bus_config_parser_new (&dirname, is_toplevel, parent);
+
if (parser == NULL)
{
_DBUS_SET_OOM (error);
Index: bus/dispatch.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/dispatch.c,v
@ -94,15 +5,6 @@ retrieving revision 1.79
diff -u -r1.79 dispatch.c
--- bus/dispatch.c 8 Mar 2007 08:30:17 -0000 1.79
+++ bus/dispatch.c 8 Mar 2007 20:25:42 -0000
@@ -34,7 +34,7 @@
#include "test.h"
#include <dbus/dbus-internals.h>
#include <string.h>
-
+
static dbus_bool_t
send_one_message (DBusConnection *connection,
BusContext *context,
@@ -428,6 +428,11 @@
}
}
@ -148,15 +50,6 @@ diff -u -r1.79 dispatch.c
}
}
else
@@ -2812,7 +2833,7 @@
return retval;
}
#endif
-
+
#define TEST_ECHO_MESSAGE "Test echo message"
#define TEST_RUN_HELLO_FROM_SELF_MESSAGE "Test sending message to self"
@@ -4064,29 +4085,36 @@
_dbus_assert_not_reached ("initial connection setup failed");
}
@ -223,26 +116,6 @@ diff -u -r1.79 dispatch.c
kill_client_connection_unchecked (foo);
Index: bus/main.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/main.c,v
retrieving revision 1.36
diff -u -r1.36 main.c
--- bus/main.c 20 Dec 2006 06:18:19 -0000 1.36
+++ bus/main.c 8 Mar 2007 20:25:40 -0000
@@ -254,6 +254,12 @@
dbus_bool_t print_pid;
int force_fork;
+#ifdef _WIN32
+ extern int _dbus_init_working_dir(char *s);
+ if (!_dbus_init_working_dir(argv[0]))
+ return 1;
+#endif
+
if (!_dbus_string_init (&config_file))
return 1;
Index: dbus/dbus-bus.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-bus.c,v
@ -468,24 +341,6 @@ diff -u -r1.36 dbus-threads.c
}
#endif /* DBUS_BUILD_TESTS */
Index: dbus/dbus-transport-socket.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport-socket.h,v
retrieving revision 1.2
diff -u -r1.2 dbus-transport-socket.h
--- dbus/dbus-transport-socket.h 16 Sep 2006 19:24:08 -0000 1.2
+++ dbus/dbus-transport-socket.h 8 Mar 2007 20:25:42 -0000
@@ -25,6 +25,10 @@
#include <dbus/dbus-transport-protected.h>
+#if defined(DBUS_WIN)
+#include <dbus/dbus-sockets-win.h>
+#endif
+
DBUS_BEGIN_DECLS
DBusTransport* _dbus_transport_new_for_socket (int fd,
Index: dbus/dbus-transport.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport.c,v
@ -493,21 +348,6 @@ retrieving revision 1.54
diff -u -r1.54 dbus-transport.c
--- dbus/dbus-transport.c 17 Oct 2006 20:52:13 -0000 1.54
+++ dbus/dbus-transport.c 8 Mar 2007 20:25:42 -0000
@@ -310,9 +310,11 @@
DBusTransport **transport_p,
DBusError *error);
} open_funcs[] = {
- { _dbus_transport_open_socket },
- { _dbus_transport_open_platform_specific },
- { _dbus_transport_open_autolaunch }
+ { _dbus_transport_open_socket }
+#ifndef DBUS_WIN
+ , { _dbus_transport_open_platform_specific }
+#endif
+ , { _dbus_transport_open_autolaunch }
#ifdef DBUS_BUILD_TESTS
, { _dbus_transport_open_debug_pipe }
#endif
@@ -674,7 +676,7 @@
if (transport->disconnected)
return TRUE;

View file

@ -50,6 +50,7 @@ typedef struct {
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#ifdef __MINGW32__
/* save string functions version
@ -72,80 +73,6 @@ errno_t strcpy_s(char *dest, int size, char *src)
}
#endif
/**
* return the absolute path of the dbus installation
*
* @param s buffer for installation path
* @param len length of buffer
* @returns #FALSE on failure
*/
dbus_bool_t
_dbus_get_install_root(char *s, int len)
{
char *p = NULL;
int ret = GetModuleFileName(NULL,s,len);
if ( ret == 0
|| ret == len && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
*s = '\0';
return FALSE;
}
else if ((p = strstr(s,"\\bin\\")))
{
*(p+1)= '\0';
return TRUE;
}
else
{
*s = '\0';
return FALSE;
}
}
/*
find session.conf either from installation or build root according to
the following path layout
install-root/
bin/dbus-daemon[d].exe
etc/session.conf
build-root/
bin/dbus-daemon[d].exe
bus/session.conf
*/
dbus_bool_t
_dbus_get_config_file_name(DBusString *config_file, char *s)
{
char path[MAX_PATH*2];
int path_size = sizeof(path);
if (!_dbus_get_install_root(path,path_size))
return FALSE;
strcat_s(path,path_size,"etc\\");
strcat_s(path,path_size,s);
if (_dbus_file_exists(path))
{
// find path from executable
if (!_dbus_string_append (config_file, path))
return FALSE;
}
else
{
if (!_dbus_get_install_root(path,path_size))
return FALSE;
strcat_s(path,path_size,"bus\\");
strcat_s(path,path_size,s);
if (_dbus_file_exists(path))
{
if (!_dbus_string_append (config_file, path))
return FALSE;
}
}
return TRUE;
}
/**
* Does the chdir, fork, setsid, etc. to become a daemon process.
*
@ -976,5 +903,91 @@ _dbus_string_get_dirname(const DBusString *filename,
dirname, _dbus_string_get_length (dirname));
}
/**
* Checks to see if the UNIX user ID matches the UID of
* the process. Should always return #FALSE on Windows.
*
* @param uid the UNIX user ID
* @returns #TRUE if this uid owns the process.
*/
dbus_bool_t
_dbus_unix_user_is_process_owner (dbus_uid_t uid)
{
return FALSE;
}
/*=====================================================================
unix emulation functions - should be removed sometime in the future
=====================================================================*/
/**
* Checks to see if the UNIX user ID is at the console.
* Should always fail on Windows (set the error to
* #DBUS_ERROR_NOT_SUPPORTED).
*
* @param uid UID of person to check
* @param error return location for errors
* @returns #TRUE if the UID is the same as the console user and there are no errors
*/
dbus_bool_t
_dbus_unix_user_is_at_console (dbus_uid_t uid,
DBusError *error)
{
return FALSE;
}
/**
* Parse a UNIX group from the bus config file. On Windows, this should
* simply always fail (just return #FALSE).
*
* @param groupname the groupname text
* @param gid_p place to return the gid
* @returns #TRUE on success
*/
dbus_bool_t
_dbus_parse_unix_group_from_config (const DBusString *groupname,
dbus_gid_t *gid_p)
{
return FALSE;
}
/**
* Parse a UNIX user from the bus config file. On Windows, this should
* simply always fail (just return #FALSE).
*
* @param username the username text
* @param uid_p place to return the uid
* @returns #TRUE on success
*/
dbus_bool_t
_dbus_parse_unix_user_from_config (const DBusString *username,
dbus_uid_t *uid_p)
{
return FALSE;
}
/**
* Gets all groups corresponding to the given UNIX user ID. On UNIX,
* just calls _dbus_groups_from_uid(). On Windows, should always
* fail since we don't know any UNIX groups.
*
* @param uid the UID
* @param group_ids return location for array of group IDs
* @param n_group_ids return location for length of returned array
* @returns #TRUE if the UID existed and we got some credentials
*/
dbus_bool_t
_dbus_unix_groups_from_uid (dbus_uid_t uid,
dbus_gid_t **group_ids,
int *n_group_ids)
{
return FALSE;
}
/** @} */ /* DBusString stuff */

View file

@ -52,6 +52,7 @@ typedef struct DBusCredentials{
#include "dbus-hash.h"
#include "dbus-sockets-win.h"
#include "dbus-list.h"
#include "dbus-credentials.h"
#include <windows.h>
#include <fcntl.h>
@ -874,228 +875,6 @@ _dbus_write_socket_two (int handle,
return 0;
}
#if 0
/**
* @def _DBUS_MAX_SUN_PATH_LENGTH
*
* Maximum length of the path to a UNIX domain socket,
* sockaddr_un::sun_path member. POSIX requires that all systems
* support at least 100 bytes here, including the nul termination.
* We use 99 for the max value to allow for the nul.
*
* We could probably also do sizeof (addr.sun_path)
* but this way we are the same on all platforms
* which is probably a good idea.
*/
/**
* Creates a socket and connects it to the UNIX domain socket at the
* given path. The connection fd is returned, and is set up as
* nonblocking.
*
* On Windows there are no UNIX domain sockets. Instead, connects to a
* localhost-bound TCP socket, whose port number is stored in a file
* at the given path.
*
* Uses abstract sockets instead of filesystem-linked sockets if
* requested (it's possible only on Linux; see "man 7 unix" on Linux).
* On non-Linux abstract socket usage always fails.
*
* @param path the path to UNIX domain socket
* @param abstract #TRUE to use abstract namespace
* @param error return location for error code
* @returns connection file descriptor or -1 on error
*/
int
_dbus_connect_unix_socket (const char *path,
dbus_bool_t abstract,
DBusError *error)
{
#ifdef DBUS_WINCE
return -1;
#else
int fd, n, port;
char buf[7];
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_verbose ("connecting to pseudo-unix socket at %s\n",
path);
if (abstract)
{
dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
"Implementation does not support abstract socket namespace\n");
return -1;
}
fd = _sopen (path, O_RDONLY, SH_DENYNO);
if (fd == -1)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to open file %s: %s",
path, _dbus_strerror (errno));
return -1;
}
n = read (fd, buf, sizeof (buf) - 1);
close (fd);
if (n == 0)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Failed to read port number from file %s",
path);
return -1;
}
buf[n] = '\0';
port = atoi (buf);
if (port <= 0 || port > 0xFFFF)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Invalid port numer in file %s",
path);
return -1;
}
return _dbus_connect_tcp_socket (NULL, port, error);
#endif //DBUS_WINCE
}
/**
* Creates a socket and binds it to the given path,
* then listens on the socket. The socket is
* set to be nonblocking.
*
* Uses abstract sockets instead of filesystem-linked
* sockets if requested (it's possible only on Linux;
* see "man 7 unix" on Linux).
* On non-Linux abstract socket usage always fails.
*
* @param path the socket name
* @param abstract #TRUE to use abstract namespace
* @param error return location for errors
* @returns the listening file descriptor or -1 on error
*/
int
_dbus_listen_unix_socket (const char *path,
dbus_bool_t abstract,
DBusError *error)
{
#ifdef DBUS_WINCE
return -1;
#else
DBusSocket *s;
int listen_handle;
struct sockaddr sa;
int addr_len;
int filefd;
int n, l;
DBusString portstr;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_verbose ("listening on pseudo-unix socket at %s\n",
path);
if (abstract)
{
dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
"Implementation does not support abstract socket namespace\n");
return -1;
}
listen_handle = _dbus_listen_tcp_socket (NULL, 0, error);
if (listen_handle == -1)
return -1;
_dbus_handle_to_socket(listen_handle, &s);
addr_len = sizeof (sa);
if (getsockname (s->fd, &sa, &addr_len) == SOCKET_ERROR)
{
DBUS_SOCKET_SET_ERRNO ();
dbus_set_error (error, _dbus_error_from_errno (errno),
"getsockname failed: %s",
_dbus_strerror (errno));
_dbus_close_socket (listen_handle, NULL);
return -1;
}
_dbus_assert (((struct sockaddr_in*) &sa)->sin_family == AF_INET);
filefd = _sopen (path, O_CREAT|O_WRONLY|_O_SHORT_LIVED, SH_DENYWR, 0666);
if (filefd == -1)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to create pseudo-unix socket port number file %s: %s",
path, _dbus_strerror (errno));
_dbus_close_socket (listen_handle, NULL);
return -1;
}
_dbus_lock_sockets();
_dbus_handle_to_socket_unlocked(listen_handle, &s);
s->port_file_fd = filefd;
_dbus_unlock_sockets();
/* Use strdup() to avoid memory leak in dbus-test */
path = strdup (path);
if (!path)
{
_DBUS_SET_OOM (error);
_dbus_close_socket (listen_handle, NULL);
return -1;
}
_dbus_string_init_const (&s->port_file, path);
if (!_dbus_string_init (&portstr))
{
_DBUS_SET_OOM (error);
_dbus_close_socket (listen_handle, NULL);
return -1;
}
if (!_dbus_string_append_int (&portstr, ntohs (((struct sockaddr_in*) &sa)->sin_port)))
{
_DBUS_SET_OOM (error);
_dbus_close_socket (listen_handle, NULL);
return -1;
}
l = _dbus_string_get_length (&portstr);
n = write (filefd, _dbus_string_get_const_data (&portstr), l);
_dbus_string_free (&portstr);
if (n == -1)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to write port number to file %s: %s",
path, _dbus_strerror (errno));
_dbus_close_socket (listen_handle, NULL);
return -1;
}
else if (n < l)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to write port number to file %s",
path);
_dbus_close_socket (listen_handle, NULL);
return -1;
}
return listen_handle;
#endif //DBUS_WINCE
}
#endif
#if 0
/**
@ -1116,6 +895,7 @@ _dbus_connect_named_pipe (const char *path,
#endif
#ifdef ENABLE_DBUSUSERINFO
dbus_bool_t
_dbus_account_to_win_sid (const wchar_t *waccount,
void **ppsid,
@ -1179,7 +959,6 @@ out1:
return retval;
}
#ifdef ENABLE_DBUSUSERINFO
dbus_bool_t
fill_win_user_info_name_and_groups (wchar_t *wname,
wchar_t *wdomain,
@ -3516,6 +3295,7 @@ _dbus_daemon_init(const char *host, dbus_uint32_t port);
int
_dbus_listen_tcp_socket (const char *host,
dbus_uint32_t *port,
dbus_bool_t inaddr_any,
DBusError *error)
{
DBusSocket slisten;
@ -3912,6 +3692,155 @@ _dbus_concat_dir_and_file (DBusString *dir,
_dbus_string_get_length (dir));
}
/**
* Adds the credentials of the current process to the
* passed-in credentials object.
*
* @param credentials credentials to add to
* @returns #FALSE if no memory; does not properly roll back on failure, so only some credentials may have been added
*/
dbus_bool_t
_dbus_credentials_add_from_current_process (DBusCredentials *credentials)
{
credentials->pid = _dbus_getpid();
credentials->uid = _dbus_getuid();
return TRUE;
}
/**
* Gets a UID from a UID string.
*
* @param uid_str the UID in string form
* @param uid UID to fill in
* @returns #TRUE if successfully filled in UID
*/
dbus_bool_t
_dbus_parse_uid (const DBusString *uid_str,
dbus_uid_t *uid)
{
int end;
long val;
if (_dbus_string_get_length (uid_str) == 0)
{
_dbus_verbose ("UID string was zero length\n");
return FALSE;
}
val = -1;
end = 0;
if (!_dbus_string_parse_int (uid_str, 0, &val,
&end))
{
_dbus_verbose ("could not parse string as a UID\n");
return FALSE;
}
if (end != _dbus_string_get_length (uid_str))
{
_dbus_verbose ("string contained trailing stuff after UID\n");
return FALSE;
}
*uid = val;
return TRUE;
}
/**
* Parses a desired identity provided from a client in the auth protocol.
* On UNIX this means parsing a UID.
*
* @todo this is broken because it treats OOM and parse error
* the same way. Needs a #DBusError.
*
* @param credentials the credentials to add what we parse to
* @param desired_identity the string to parse
* @returns #TRUE if we successfully parsed something
*/
dbus_bool_t
_dbus_credentials_parse_and_add_desired (DBusCredentials *credentials,
const DBusString *desired_identity)
{
dbus_uid_t uid;
if (!_dbus_parse_uid (desired_identity, &uid))
return FALSE;
if (!_dbus_credentials_add_unix_uid (credentials, uid))
return FALSE;
return TRUE;
}
/**
* Adds the credentials corresponding to the given username.
*
* @param credentials credentials to fill in
* @param username the username
* @returns #TRUE if the username existed and we got some credentials
*/
dbus_bool_t
_dbus_credentials_add_from_user (DBusCredentials *credentials,
const DBusString *username)
{
_dbus_verbose("_dbus_credentials_add_from_user is not implemented");
return FALSE;
}
/**
* Append to the string the identity we would like to have when we
* authenticate, on UNIX this is the current process UID and on
* Windows something else, probably a Windows SID string. No escaping
* is required, that is done in dbus-auth.c. The username here
* need not be anything human-readable, it can be the machine-readable
* form i.e. a user id.
*
* @param str the string to append to
* @returns #FALSE on no memory
*/
dbus_bool_t
_dbus_append_user_from_current_process (DBusString *str)
{
return _dbus_string_append_uint (str,
_dbus_getuid ());
}
/**
* Gets the home directory for the given user.
*
* @param username the username
* @param homedir string to append home directory to
* @returns #TRUE if user existed and we appended their homedir
*/
dbus_bool_t
_dbus_homedir_from_username (const DBusString *username,
DBusString *homedir)
{
_dbus_string_append (homedir, "/");
return TRUE;
}
/**
* Gets homedir of user owning current process. The returned string
* is valid until dbus_shutdown() is called.
*
* @param homedir place to store pointer to homedir
* @returns #FALSE if no memory
*/
dbus_bool_t
_dbus_homedir_from_current_process (const DBusString **homedir)
{
char *s = getenv("HOMEPATH");
DBusString *dir=0;
_dbus_string_init(dir);
_dbus_string_append (dir, s);
*homedir = dir;
return TRUE;
}
/**
* Append to the string the identity we would like to have when we authenticate,
* on UNIX this is the current process UID and on Windows something else.
@ -5168,6 +5097,195 @@ dbus_bool_t _dbus_windows_user_is_process_owner (const char *windows_sid)
return TRUE;
}
/**
* See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently
* for Winsock so is abstracted)
*
* @returns #TRUE if errno == EAGAIN or errno == EWOULDBLOCK
*/
dbus_bool_t
_dbus_get_is_errno_eagain_or_ewouldblock (void)
{
return errno == EAGAIN || errno == EWOULDBLOCK;
}
/**
* return the absolute path of the dbus installation
*
* @param s buffer for installation path
* @param len length of buffer
* @returns #FALSE on failure
*/
dbus_bool_t
_dbus_get_install_root(char *s, int len)
{
char *p = NULL;
int ret = GetModuleFileName(NULL,s,len);
if ( ret == 0
|| ret == len && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
*s = '\0';
return FALSE;
}
else if ((p = strstr(s,"\\bin\\")))
{
*(p+1)= '\0';
return TRUE;
}
else
{
*s = '\0';
return FALSE;
}
}
/**
find config file either from installation or build root according to
the following path layout
install-root/
bin/dbus-daemon[d].exe
etc/<config-file>.conf
build-root/
bin/dbus-daemon[d].exe
bus/<config-file>.conf
*/
dbus_bool_t
_dbus_get_config_file_name(DBusString *config_file, char *s)
{
char path[MAX_PATH*2];
int path_size = sizeof(path);
if (!_dbus_get_install_root(path,path_size))
return FALSE;
strcat_s(path,path_size,"etc\\");
strcat_s(path,path_size,s);
if (_dbus_file_exists(path))
{
// find path from executable
if (!_dbus_string_append (config_file, path))
return FALSE;
}
else
{
if (!_dbus_get_install_root(path,path_size))
return FALSE;
strcat_s(path,path_size,"bus\\");
strcat_s(path,path_size,s);
if (_dbus_file_exists(path))
{
if (!_dbus_string_append (config_file, path))
return FALSE;
}
}
return TRUE;
}
/**
* Append the absolute path of the system.conf file
* (there is no system bus on Windows so this can just
* return FALSE and print a warning or something)
*
* @param str the string to append to
* @returns #FALSE if no memory
*/
dbus_bool_t
_dbus_append_system_config_file (DBusString *str)
{
return _dbus_get_config_file_name(str, "system.conf");
}
/**
* Append the absolute path of the session.conf file.
*
* @param str the string to append to
* @returns #FALSE if no memory
*/
dbus_bool_t
_dbus_append_session_config_file (DBusString *str)
{
return _dbus_get_config_file_name(str, "session.conf");
}
/**
* Appends the directory in which a keyring for the given credentials
* should be stored. The credentials should have either a Windows or
* UNIX user in them. The directory should be an absolute path.
*
* On UNIX the directory is ~/.dbus-keyrings while on Windows it should probably
* be something else, since the dotfile convention is not normal on Windows.
*
* @param directory string to append directory to
* @param credentials credentials the directory should be for
*
* @returns #FALSE on no memory
*/
dbus_bool_t
_dbus_append_keyring_directory_for_credentials (DBusString *directory,
DBusCredentials *credentials)
{
DBusString homedir;
DBusString dotdir;
dbus_uid_t uid;
const char *homepath;
_dbus_assert (credentials != NULL);
_dbus_assert (!_dbus_credentials_are_anonymous (credentials));
if (!_dbus_string_init (&homedir))
return FALSE;
homepath = _dbus_getenv("HOMEPATH");
if (homepath != NULL && *homepath != '\0')
{
_dbus_string_append(&homedir,homepath);
}
#ifdef DBUS_BUILD_TESTS
{
const char *override;
override = _dbus_getenv ("DBUS_TEST_HOMEDIR");
if (override != NULL && *override != '\0')
{
_dbus_string_set_length (&homedir, 0);
if (!_dbus_string_append (&homedir, override))
goto failed;
_dbus_verbose ("Using fake homedir for testing: %s\n",
_dbus_string_get_const_data (&homedir));
}
else
{
static dbus_bool_t already_warned = FALSE;
if (!already_warned)
{
_dbus_warn ("Using your real home directory for testing, set DBUS_TEST_HOMEDIR to avoid\n");
already_warned = TRUE;
}
}
}
#endif
_dbus_string_init_const (&dotdir, ".dbus-keyrings");
if (!_dbus_concat_dir_and_file (&homedir,
&dotdir))
goto failed;
if (!_dbus_string_copy (&homedir, 0,
directory, _dbus_string_get_length (directory))) {
goto failed;
}
_dbus_string_free (&homedir);
return TRUE;
failed:
_dbus_string_free (&homedir);
return FALSE;
}
/** @} end of sysdeps-win */
/* tests in dbus-sysdeps-util.c */

View file

@ -161,18 +161,7 @@ struct DBusFile
void _dbus_handle_to_socket (int handle,
DBusSocket **socket);
int _dbus_socket_to_handle (DBusSocket *socket);
#if 0
// replace with a windows version
dbus_bool_t _dbus_open_unix_socket (int *fd,
DBusError *error);
int _dbus_connect_unix_socket (const char *path,
dbus_bool_t abstract,
DBusError *error);
int _dbus_listen_unix_socket (const char *path,
dbus_bool_t abstract,
DBusError *error);
#endif
dbus_bool_t _dbus_get_config_file_name(DBusString *config_file,
char *s);

57
dbus/dbus-transport-win.c Normal file
View file

@ -0,0 +1,57 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-transport-win.c Windows socket subclasses of DBusTransport
*
* Copyright (C) 2002, 2003, 2004 Red Hat Inc.
* Copyright (C) 2007 Ralf Habacker <ralf.habacker@freenet.de>
*
* Licensed under the Academic Free License version 2.1
*
* 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 of the License, 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 "dbus-internals.h"
#include "dbus-connection-internal.h"
#include "dbus-transport-socket.h"
#include "dbus-transport-protected.h"
#include "dbus-watch.h"
#include "dbus-sysdeps-win.h"
/**
* @defgroup DBusTransportUnix DBusTransport implementations for UNIX
* @ingroup DBusInternals
* @brief Implementation details of DBusTransport on UNIX
*
* @{
*/
/**
* Opens platform specific transport types.
*
* @param entry the address entry to try opening
* @param transport_p return location for the opened transport
* @param error error to be set
* @returns result of the attempt
*/
DBusTransportOpenResult
_dbus_transport_open_platform_specific (DBusAddressEntry *entry,
DBusTransport **transport_p,
DBusError *error)
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
}
/** @} */

33
dbus/dbus-transport-win.h Normal file
View file

@ -0,0 +1,33 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-transport-win.h Windows socket subclasses of DBusTransport
*
* Copyright (C) 2002 Red Hat Inc.
* Copyright (C) 2007 Ralf Habacker <ralf.habacker@freenet.de>
*
* Licensed under the Academic Free License version 2.1
*
* 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 of the License, 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 DBUS_TRANSPORT_WIN_H
#define DBUS_TRANSPORT_WIN_H
#include <dbus/dbus-transport.h>
DBUS_BEGIN_DECLS
DBUS_END_DECLS
#endif /* DBUS_TRANSPORT_WIN_H */