diff -upr -x .deps -x .libs -x '*.la' -x '*.lo' dbus-1.8.0.old/dbus/Makefile.am dbus-1.8.0/dbus/Makefile.am --- dbus-1.8.0.old/dbus/Makefile.am 2014-09-26 17:35:03 +0000 +++ dbus-1.8.0/dbus/Makefile.am 2014-09-05 22:19:40 +0000 @@ -304,8 +304,8 @@ if DBUS_WIN # this code is used, we don't actually need libstdc++. noinst_LTLIBRARIES += libdbus-init-win.la libdbus_init_win_la_SOURCES = dbus-init-win.cpp -libdbus_1_la_LIBADD += libdbus-init-win.la -libdbus_internal_la_LIBADD += libdbus-init-win.la +libdbus_1_la_LIBADD += libdbus-init-win.la -lole32 +libdbus_internal_la_LIBADD += libdbus-init-win.la -lole32 endif noinst_PROGRAMS = diff -upr -x .deps -x .libs -x '*.la' -x '*.lo' dbus-1.8.0.old/dbus/dbus-sysdeps-win.c dbus-1.8.0/dbus/dbus-sysdeps-win.c --- dbus-1.8.0.old/dbus/dbus-sysdeps-win.c 2014-09-26 17:35:03 +0000 +++ dbus-1.8.0/dbus/dbus-sysdeps-win.c 2014-09-26 17:27:21 +0000 @@ -55,6 +55,7 @@ #include #include #include +#include /* Declarations missing in mingw's and windows sdk 7.0 headers */ extern BOOL WINAPI ConvertStringSidToSidA (LPCSTR StringSid, PSID *Sid); @@ -3379,6 +3380,90 @@ _dbus_lookup_session_address (dbus_bool_ return TRUE; } +static dbus_bool_t +_dbus_set_user_home (DBusString *homedir) +{ + const char *env; + char path[MAX_PATH + 1]; + int len; + + _dbus_string_set_length (homedir, 0); + + env = _dbus_getenv("HOME"); + + /* Only believe HOME if it is an absolute path and exists. + * + * We only do this check on Windows for a couple of reasons. + * Historically, we only did it there because we used to ignore $HOME + * on UNIX. There are concerns about enabling it now on UNIX because + * of things like autofs. In short, if the user has a bogus value in + * $HOME then they get what they pay for... + */ + if (env) + { + len = strlen (env); + if (len < MAX_PATH) + { + char *p; + strncpy(path, env, len); + /* In case HOME is Unix-style (it happens), convert it to Windows style. */ + while ((p = strchr(path, '/')) != NULL) + { + *p = '\\'; + } + + if ((path[0] == '\\' || (((path[0] >= 'a' && path[0] <= 'z') || (path[0] >= 'A' && path[0] <= 'Z')) && path[1] == ':')) && + GetFileAttributesA (path) != INVALID_FILE_ATTRIBUTES && + (GetFileAttributesA (path) & FILE_ATTRIBUTE_DIRECTORY) != 0) + { + _dbus_string_append (homedir, path); + } + } + } + + if (_dbus_string_get_length (homedir) == 0) + { + /* USERPROFILE is probably the closest equivalent to $HOME? */ + env = _dbus_getenv("USERPROFILE"); + if (env != NULL) + _dbus_string_append (homedir, env); + } + + if (_dbus_string_get_length (homedir) == 0 && + SHGetSpecialFolderPathA(NULL, path, CSIDL_PROFILE, FALSE)) + { + _dbus_string_append (homedir, path); + } + + path[0] = 0; + if (_dbus_string_get_length (homedir) == 0 && + GetWindowsDirectory (path, MAX_PATH)) + { + _dbus_string_append (homedir, path); + } + + return _dbus_string_get_length (homedir) != 0; +} + +static void +_dbus_set_homedir_from_drive_and_path_env(DBusString *homedir) +{ + const char *homepath; + const char *homedrive; + + homedrive = _dbus_getenv("HOMEDRIVE"); + if (homedrive != NULL && *homedrive != '\0') + { + _dbus_string_append(homedir,homedrive); + } + + homepath = _dbus_getenv("HOMEPATH"); + if (homepath != NULL && *homepath != '\0') + { + _dbus_string_append(homedir,homepath); + } +} + /** * Appends the directory in which a keyring for the given credentials * should be stored. The credentials should have either a Windows or @@ -3398,8 +3483,6 @@ _dbus_append_keyring_directory_for_crede { DBusString homedir; DBusString dotdir; - const char *homepath; - const char *homedrive; _dbus_assert (credentials != NULL); _dbus_assert (!_dbus_credentials_are_anonymous (credentials)); @@ -3407,18 +3490,16 @@ _dbus_append_keyring_directory_for_crede if (!_dbus_string_init (&homedir)) return FALSE; - homedrive = _dbus_getenv("HOMEDRIVE"); - if (homedrive != NULL && *homedrive != '\0') + _dbus_string_set_length(&homedir, 0); + if (!_dbus_set_user_home(&homedir)) { - _dbus_string_append(&homedir,homedrive); + _dbus_set_homedir_from_drive_and_path_env(&homedir); } - homepath = _dbus_getenv("HOMEPATH"); - if (homepath != NULL && *homepath != '\0') - { - _dbus_string_append(&homedir,homepath); - } - + /* Should not happen, but just in case */ + if (_dbus_string_get_length(&homedir) == 0) + _dbus_string_append (&homedir, "C:\\"); + #ifdef DBUS_ENABLE_EMBEDDED_TESTS { const char *override;