31#define STRSAFE_NO_DEPRECATE
33#include "dbus-internals.h"
35#include "dbus-sysdeps.h"
36#include "dbus-threads.h"
37#include "dbus-protocol.h"
38#include "dbus-string.h"
39#include "dbus-sysdeps.h"
40#include "dbus-sysdeps-win.h"
41#include "dbus-protocol.h"
43#include "dbus-sockets-win.h"
45#include "dbus-nonce.h"
46#include "dbus-credentials.h"
56extern BOOL WINAPI ConvertStringSidToSidA (LPCSTR StringSid, PSID *Sid);
57extern BOOL WINAPI ConvertSidToStringSidA (PSID Sid, LPSTR *StringSid);
81#ifndef PROCESS_QUERY_LIMITED_INFORMATION
83#define PROCESS_QUERY_LIMITED_INFORMATION (0x1000)
92_dbus_win_set_errno (
int err)
101static BOOL is_winxp_sp3_or_lower (
void);
107typedef MIB_TCPROW_OWNER_PID _MIB_TCPROW_EX;
108typedef MIB_TCPTABLE_OWNER_PID MIB_TCPTABLE_EX;
109typedef PMIB_TCPTABLE_OWNER_PID PMIB_TCPTABLE_EX;
110typedef DWORD (WINAPI *ProcAllocateAndGetTcpExtTableFromStack)(PMIB_TCPTABLE_EX*,BOOL,HANDLE,DWORD,DWORD);
115static ProcAllocateAndGetTcpExtTableFromStack lpfnAllocateAndGetTcpExTableFromStack =
NULL;
123load_ex_ip_helper_procedures(
void)
125 HMODULE hModule = LoadLibrary (
"iphlpapi.dll");
128 _dbus_verbose (
"could not load iphlpapi.dll\n");
132 lpfnAllocateAndGetTcpExTableFromStack = (ProcAllocateAndGetTcpExtTableFromStack) (
void (*)(void))GetProcAddress (hModule,
"AllocateAndGetTcpExTableFromStack");
133 if (lpfnAllocateAndGetTcpExTableFromStack ==
NULL)
135 _dbus_verbose (
"could not find function AllocateAndGetTcpExTableFromStack in iphlpapi.dll\n");
148get_pid_from_extended_tcp_table(
int peer_port)
151 DWORD errorCode, size = 0, i;
152 MIB_TCPTABLE_OWNER_PID *tcp_table;
155 GetExtendedTcpTable (
NULL, &size,
TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0)) == ERROR_INSUFFICIENT_BUFFER)
157 tcp_table = (MIB_TCPTABLE_OWNER_PID *)
dbus_malloc (size);
158 if (tcp_table ==
NULL)
160 _dbus_verbose (
"Error allocating memory\n");
166 _dbus_win_warn_win_error (
"unexpected error returned from GetExtendedTcpTable", errorCode);
170 if ((errorCode = GetExtendedTcpTable (tcp_table, &size,
TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0)) != NO_ERROR)
172 _dbus_verbose (
"Error fetching tcp table %d\n", (
int)errorCode);
178 for (i = 0; i < tcp_table->dwNumEntries; i++)
180 MIB_TCPROW_OWNER_PID *p = &tcp_table->table[i];
181 int local_address = ntohl (p->dwLocalAddr);
182 int local_port = ntohs (p->dwLocalPort);
183 if (p->dwState == MIB_TCP_STATE_ESTAB
184 && local_address == INADDR_LOOPBACK && local_port == peer_port)
185 result = p->dwOwningPid;
189 _dbus_verbose (
"got pid %lu\n", result);
201get_pid_from_tcp_ex_table(
int peer_port)
205 PMIB_TCPTABLE_EX tcp_table =
NULL;
207 if (!load_ex_ip_helper_procedures ())
210 (
"Error not been able to load iphelper procedures\n");
214 errorCode = lpfnAllocateAndGetTcpExTableFromStack (&tcp_table,
TRUE, GetProcessHeap(), 0, 2);
216 if (errorCode != NO_ERROR)
219 (
"Error not been able to call AllocateAndGetTcpExTableFromStack()\n");
224 for (i = 0; i < tcp_table->dwNumEntries; i++)
226 _MIB_TCPROW_EX *p = &tcp_table->table[i];
227 int local_port = ntohs (p->dwLocalPort);
228 int local_address = ntohl (p->dwLocalAddr);
229 if (local_address == INADDR_LOOPBACK && local_port == peer_port)
231 result = p->dwOwningPid;
236 HeapFree (GetProcessHeap(), 0, tcp_table);
237 _dbus_verbose (
"got pid %lu\n", result);
247_dbus_get_peer_pid_from_tcp_handle (
int handle)
249 struct sockaddr_storage addr;
250 socklen_t len =
sizeof (addr);
256 getpeername (handle, (
struct sockaddr *) &addr, &len);
258 if (addr.ss_family == AF_INET)
260 struct sockaddr_in *s = (
struct sockaddr_in *) &addr;
261 peer_port = ntohs (s->sin_port);
262 is_localhost = (ntohl (s->sin_addr.s_addr) == INADDR_LOOPBACK);
264 else if (addr.ss_family == AF_INET6)
266 _dbus_verbose (
"FIXME [61922]: IPV6 support not working on windows\n");
277 _dbus_verbose (
"no idea what address family %d is\n", addr.ss_family);
283 _dbus_verbose (
"could not fetch process id from remote process\n");
290 (
"Error not been able to fetch tcp peer port from connection\n");
294 _dbus_verbose (
"trying to get peer's pid\n");
296 result = get_pid_from_extended_tcp_table (peer_port);
299 result = get_pid_from_tcp_ex_table (peer_port);
305_dbus_win_error_from_last_error (
void)
307 switch (GetLastError())
312 case ERROR_NO_MORE_FILES:
313 case ERROR_TOO_MANY_OPEN_FILES:
316 case ERROR_ACCESS_DENIED:
317 case ERROR_CANNOT_MAKE:
320 case ERROR_NOT_ENOUGH_MEMORY:
323 case ERROR_FILE_EXISTS:
326 case ERROR_FILE_NOT_FOUND:
327 case ERROR_PATH_NOT_FOUND:
337_dbus_win_error_string (
int error_number)
341 FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
342 FORMAT_MESSAGE_IGNORE_INSERTS |
343 FORMAT_MESSAGE_FROM_SYSTEM,
344 NULL, error_number, 0,
345 (LPSTR) &msg, 0,
NULL);
347 if (msg[strlen (msg) - 1] ==
'\n')
348 msg[strlen (msg) - 1] =
'\0';
349 if (msg[strlen (msg) - 1] ==
'\r')
350 msg[strlen (msg) - 1] =
'\0';
356_dbus_win_free_error_string (
char *
string)
392 start = _dbus_string_get_length (buffer);
396 _dbus_win_set_errno (ENOMEM);
404 _dbus_verbose (
"recv: count=%d fd=%Iu\n", count, fd.sock);
405 bytes_read = recv (fd.sock, data, count, 0);
407 if (bytes_read == SOCKET_ERROR)
409 DBUS_SOCKET_SET_ERRNO();
410 _dbus_verbose (
"recv: failed: %s (%d)\n", _dbus_strerror (errno), errno);
414 _dbus_verbose (
"recv: = %d\n", bytes_read);
460 data = _dbus_string_get_const_data_len (buffer, start, len);
464 _dbus_verbose (
"send: len=%d fd=%Iu\n", len, fd.sock);
465 bytes_written = send (fd.sock, data, len, 0);
467 if (bytes_written == SOCKET_ERROR)
469 DBUS_SOCKET_SET_ERRNO();
474 _dbus_verbose (
"send: = %d\n", bytes_written);
476 if (bytes_written < 0 && errno == EINTR)
480 if (bytes_written > 0)
484 return bytes_written;
500 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
503 if (closesocket (fd->sock) == SOCKET_ERROR)
505 DBUS_SOCKET_SET_ERRNO ();
511 "Could not close socket: socket=%Iu, , %s",
513 _dbus_socket_invalidate (fd);
516 _dbus_verbose (
"socket=%Iu, \n", fd->sock);
518 _dbus_socket_invalidate (fd);
530_dbus_win_handle_set_close_on_exec (HANDLE handle)
532 if ( !SetHandleInformation( (HANDLE) handle,
533 HANDLE_FLAG_INHERIT | HANDLE_FLAG_PROTECT_FROM_CLOSE,
536 _dbus_win_warn_win_error (
"Disabling socket handle inheritance failed:", GetLastError());
553 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
555 if (ioctlsocket (handle.sock, FIONBIO, &one) == SOCKET_ERROR)
557 DBUS_SOCKET_SET_ERRNO ();
559 "Failed to set socket %Iu to nonblocking: %s",
610 data1 = _dbus_string_get_const_data_len (buffer1, start1, len1);
613 data2 = _dbus_string_get_const_data_len (buffer2, start2, len2);
621 vectors[0].buf = (
char*) data1;
622 vectors[0].len = len1;
623 vectors[1].buf = (
char*) data2;
624 vectors[1].len = len2;
628 _dbus_verbose (
"WSASend: len1+2=%d+%d fd=%Iu\n", len1, len2, fd.sock);
629 rc = WSASend (fd.sock,
637 if (rc == SOCKET_ERROR)
639 DBUS_SOCKET_SET_ERRNO ();
641 bytes_written = (DWORD) -1;
644 _dbus_verbose (
"WSASend: = %ld\n", bytes_written);
646 if (bytes_written == (DWORD) -1 && errno == EINTR)
649 return bytes_written;
663_dbus_connect_named_pipe (
const char *path,
675_dbus_win_startup_winsock (
void)
682 WORD wVersionRequested;
692 wVersionRequested = MAKEWORD (2, 0);
694 err = WSAStartup (wVersionRequested, &wsaData);
706 if (LOBYTE (wsaData.wVersion) != 2 ||
707 HIBYTE (wsaData.wVersion) != 0)
746 bufsize =
sizeof (buf);
747 va_copy (args_copy, args);
748 len = _vsnprintf (buf, bufsize - 1, format, args_copy);
757 p = malloc (bufsize);
762 va_copy (args_copy, args);
763 len = _vsnprintf (p, bufsize - 1, format, args_copy);
780_dbus_win_utf8_to_utf16 (
const char *str,
795 n = MultiByteToWideChar (CP_UTF8, 0, str, -1,
NULL, 0);
799 _dbus_win_set_error_from_win_error (error, GetLastError ());
807 _DBUS_SET_OOM (error);
811 if (MultiByteToWideChar (CP_UTF8, 0, str, -1, retval, n) != n)
829_dbus_win_utf16_to_utf8 (
const wchar_t *str,
835 n = WideCharToMultiByte (CP_UTF8, 0, str, -1,
NULL, 0,
NULL,
NULL);
839 _dbus_win_set_error_from_win_error (error, GetLastError ());
847 _DBUS_SET_OOM (error);
851 if (WideCharToMultiByte (CP_UTF8, 0, str, -1, retval, n,
NULL,
NULL) != n)
872_dbus_win_account_to_sid (
const wchar_t *waccount,
877 DWORD sid_length, wdomain_length;
885 if (!LookupAccountNameW (
NULL, waccount,
NULL, &sid_length,
886 NULL, &wdomain_length, &use) &&
887 GetLastError () != ERROR_INSUFFICIENT_BUFFER)
889 _dbus_win_set_error_from_win_error (error, GetLastError ());
896 _DBUS_SET_OOM (error);
900 wdomain =
dbus_new (
wchar_t, wdomain_length);
903 _DBUS_SET_OOM (error);
907 if (!LookupAccountNameW (
NULL, waccount, (PSID) *ppsid, &sid_length,
908 wdomain, &wdomain_length, &use))
910 _dbus_win_set_error_from_win_error (error, GetLastError ());
914 if (!IsValidSid ((PSID) *ppsid))
952is_winxp_sp3_or_lower (
void)
954 OSVERSIONINFOEX osvi;
955 DWORDLONG dwlConditionMask = 0;
956 int op=VER_LESS_EQUAL;
960 ZeroMemory(&osvi,
sizeof(OSVERSIONINFOEX));
961 osvi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFOEX);
962 osvi.dwMajorVersion = 5;
963 osvi.dwMinorVersion = 1;
964 osvi.wServicePackMajor = 3;
965 osvi.wServicePackMinor = 0;
969 VER_SET_CONDITION (dwlConditionMask, VER_MAJORVERSION, op);
970 VER_SET_CONDITION (dwlConditionMask, VER_MINORVERSION, op);
971 VER_SET_CONDITION (dwlConditionMask, VER_SERVICEPACKMAJOR, op);
972 VER_SET_CONDITION (dwlConditionMask, VER_SERVICEPACKMINOR, op);
976 return VerifyVersionInfo(
978 VER_MAJORVERSION | VER_MINORVERSION |
979 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
989_dbus_getsid(
char **sid,
dbus_pid_t process_id)
991 HANDLE process_token = INVALID_HANDLE_VALUE;
992 TOKEN_USER *token_user =
NULL;
997 HANDLE process_handle;
999 process_handle = GetCurrentProcess();
1000 else if (is_winxp_sp3_or_lower())
1001 process_handle = OpenProcess(PROCESS_QUERY_INFORMATION,
FALSE, process_id);
1003 process_handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,
FALSE, process_id);
1005 if (!OpenProcessToken (process_handle, TOKEN_QUERY, &process_token))
1007 _dbus_win_warn_win_error (
"OpenProcessToken failed", GetLastError ());
1010 if ((!GetTokenInformation (process_token, TokenUser,
NULL, 0, &n)
1011 && GetLastError () != ERROR_INSUFFICIENT_BUFFER)
1012 || (token_user = alloca (n)) ==
NULL
1013 || !GetTokenInformation (process_token, TokenUser, token_user, n, &n))
1015 _dbus_win_warn_win_error (
"GetTokenInformation failed", GetLastError ());
1018 psid = token_user->User.Sid;
1019 if (!IsValidSid (psid))
1021 _dbus_verbose(
"%s invalid sid\n",__FUNCTION__);
1024 if (!ConvertSidToStringSidA (psid, sid))
1026 _dbus_verbose(
"%s invalid sid\n",__FUNCTION__);
1033 CloseHandle (process_handle);
1034 if (process_token != INVALID_HANDLE_VALUE)
1035 CloseHandle (process_token);
1037 _dbus_verbose(
"_dbus_getsid() got '%s' and returns %d\n", *sid, retval);
1066 SOCKET temp, socket1 = -1, socket2 = -1;
1067 struct sockaddr_in saddr;
1071 if (!_dbus_win_startup_winsock ())
1073 _DBUS_SET_OOM (error);
1077 temp = socket (AF_INET, SOCK_STREAM, 0);
1078 if (temp == INVALID_SOCKET)
1080 DBUS_SOCKET_SET_ERRNO ();
1085 saddr.sin_family = AF_INET;
1087 saddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
1089 if (bind (temp, (
struct sockaddr *)&saddr,
sizeof (saddr)) == SOCKET_ERROR)
1091 DBUS_SOCKET_SET_ERRNO ();
1095 if (listen (temp, 1) == SOCKET_ERROR)
1097 DBUS_SOCKET_SET_ERRNO ();
1101 len =
sizeof (saddr);
1102 if (getsockname (temp, (
struct sockaddr *)&saddr, &len) == SOCKET_ERROR)
1104 DBUS_SOCKET_SET_ERRNO ();
1108 socket1 = socket (AF_INET, SOCK_STREAM, 0);
1109 if (socket1 == INVALID_SOCKET)
1111 DBUS_SOCKET_SET_ERRNO ();
1115 if (connect (socket1, (
struct sockaddr *)&saddr, len) == SOCKET_ERROR)
1117 DBUS_SOCKET_SET_ERRNO ();
1121 socket2 = accept (temp, (
struct sockaddr *) &saddr, &len);
1122 if (socket2 == INVALID_SOCKET)
1124 DBUS_SOCKET_SET_ERRNO ();
1131 if (ioctlsocket (socket1, FIONBIO, &arg) == SOCKET_ERROR)
1133 DBUS_SOCKET_SET_ERRNO ();
1138 if (ioctlsocket (socket2, FIONBIO, &arg) == SOCKET_ERROR)
1140 DBUS_SOCKET_SET_ERRNO ();
1145 fd1->sock = socket1;
1146 fd2->sock = socket2;
1148 _dbus_verbose (
"full-duplex pipe %Iu:%Iu <-> %Iu:%Iu\n",
1149 fd1->sock, socket1, fd2->sock, socket2);
1156 closesocket (socket2);
1158 closesocket (socket1);
1163 "Could not setup socket pair: %s",
1169#ifdef DBUS_ENABLE_VERBOSE_MODE
1171_dbus_dump_fd_events (
DBusPollFD *fds,
int n_fds)
1180 for (i = 0; i < n_fds; i++)
1198 _dbus_verbose (
"%s\n", _dbus_string_get_const_data (&msg));
1205#ifdef USE_CHRIS_IMPL
1207_dbus_dump_fd_revents (
DBusPollFD *fds,
int n_fds)
1216 for (i = 0; i < n_fds; i++)
1235 _dbus_verbose (
"%s\n", _dbus_string_get_const_data (&msg));
1243_dbus_dump_fdset (
DBusPollFD *fds,
int n_fds, fd_set *read_set, fd_set *write_set, fd_set *err_set)
1252 for (i = 0; i < n_fds; i++)
1259 if (FD_ISSET (fdp->
fd.sock, read_set) &&
1263 if (FD_ISSET (fdp->
fd.sock, write_set) &&
1267 if (FD_ISSET (fdp->
fd.sock, err_set) &&
1271 _dbus_verbose (
"%s\n", _dbus_string_get_const_data (&msg));
1280#ifdef USE_CHRIS_IMPL
1292 int timeout_milliseconds)
1298#define DBUS_STACK_WSAEVENTS 256
1299 WSAEVENT eventsOnStack[DBUS_STACK_WSAEVENTS];
1300 WSAEVENT *pEvents =
NULL;
1301 if (n_fds > DBUS_STACK_WSAEVENTS)
1302 pEvents = calloc(
sizeof(WSAEVENT), n_fds);
1304 pEvents = eventsOnStack;
1306 if (pEvents ==
NULL)
1308 _dbus_win_set_errno (ENOMEM);
1313#ifdef DBUS_ENABLE_VERBOSE_MODE
1314 _dbus_verbose (
"_dbus_poll: to=%d", timeout_milliseconds);
1315 if (!_dbus_dump_fd_events (fds, n_fds))
1317 _dbus_win_set_errno (ENOMEM);
1323 for (i = 0; i < n_fds; i++)
1324 pEvents[i] = WSA_INVALID_EVENT;
1326 for (i = 0; i < n_fds; i++)
1330 long lNetworkEvents = FD_OOB;
1332 ev = WSACreateEvent();
1335 lNetworkEvents |= FD_READ | FD_ACCEPT | FD_CLOSE;
1338 lNetworkEvents |= FD_WRITE | FD_CONNECT;
1340 WSAEventSelect (fdp->
fd.sock, ev, lNetworkEvents);
1345 ready = WSAWaitForMultipleEvents (n_fds, pEvents,
FALSE, timeout_milliseconds,
FALSE);
1347 if (ready == WSA_WAIT_FAILED)
1349 DBUS_SOCKET_SET_ERRNO ();
1350 if (errno != WSAEWOULDBLOCK)
1354 else if (ready == WSA_WAIT_TIMEOUT)
1356 _dbus_verbose (
"WSAWaitForMultipleEvents: WSA_WAIT_TIMEOUT\n");
1359 else if (ready < (WSA_WAIT_EVENT_0 + n_fds))
1361 for (i = 0; i < n_fds; i++)
1364 WSANETWORKEVENTS ne;
1368 WSAEnumNetworkEvents (fdp->
fd.sock, pEvents[i], &ne);
1370 if (ne.lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE))
1373 if (ne.lNetworkEvents & (FD_WRITE | FD_CONNECT))
1376 if (ne.lNetworkEvents & (FD_OOB))
1379 if(ne.lNetworkEvents)
1382 WSAEventSelect (fdp->
fd.sock, pEvents[i], 0);
1384#ifdef DBUS_ENABLE_VERBOSE_MODE
1385 _dbus_verbose (
"_dbus_poll: to=%d", timeout_milliseconds);
1386 if (!_dbus_dump_fd_revents (fds, n_fds))
1388 _dbus_win_set_errno (ENOMEM);
1396 _dbus_verbose (
"WSAWaitForMultipleEvents: failed for unknown reason!");
1401 if (pEvents !=
NULL)
1403 for (i = 0; i < n_fds; i++)
1405 if (pEvents[i] != WSA_INVALID_EVENT)
1406 WSACloseEvent (pEvents[i]);
1408 if (n_fds > DBUS_STACK_WSAEVENTS)
1426 int timeout_milliseconds)
1428 fd_set read_set, write_set, err_set;
1434 FD_ZERO (&read_set);
1435 FD_ZERO (&write_set);
1437#ifdef DBUS_ENABLE_VERBOSE_MODE
1438 _dbus_verbose(
"_dbus_poll: to=%d\n", timeout_milliseconds);
1439 if (!_dbus_dump_fd_events (fds, n_fds))
1443 for (i = 0; i < n_fds; i++)
1448 FD_SET (fdp->
fd.sock, &read_set);
1451 FD_SET (fdp->
fd.sock, &write_set);
1453 FD_SET (fdp->
fd.sock, &err_set);
1455 max_fd = MAX (max_fd, fdp->
fd.sock);
1459 tv.tv_sec = timeout_milliseconds < 0 ? 1 : timeout_milliseconds / 1000;
1460 tv.tv_usec = timeout_milliseconds < 0 ? 0 : (timeout_milliseconds % 1000) * 1000;
1462 ready = select (max_fd + 1, &read_set, &write_set, &err_set, &tv);
1464 if (DBUS_SOCKET_API_RETURNS_ERROR (ready))
1466 DBUS_SOCKET_SET_ERRNO ();
1467 if (errno != WSAEWOULDBLOCK)
1470 else if (ready == 0)
1471 _dbus_verbose (
"select: = 0\n");
1475#ifdef DBUS_ENABLE_VERBOSE_MODE
1476 _dbus_verbose (
"select: to=%d\n", ready);
1477 if (!_dbus_dump_fdset (fds, n_fds, &read_set, &write_set, &err_set))
1479 _dbus_win_set_errno (ENOMEM);
1483 for (i = 0; i < n_fds; i++)
1489 if (FD_ISSET (fdp->
fd.sock, &read_set))
1492 if (FD_ISSET (fdp->
fd.sock, &write_set))
1495 if (FD_ISSET (fdp->
fd.sock, &err_set))
1514 int timeout_milliseconds)
1516#ifdef USE_CHRIS_IMPL
1517 return _dbus_poll_events (fds, n_fds, timeout_milliseconds);
1519 return _dbus_poll_select (fds, n_fds, timeout_milliseconds);
1582 return _dbus_connect_tcp_socket_with_nonce (host, port, family, (
const char*)
NULL, error);
1586_dbus_connect_tcp_socket_with_nonce (
const char *host,
1589 const char *noncefile,
1592 int saved_errno = 0;
1596 struct addrinfo hints;
1597 struct addrinfo *ai =
NULL;
1598 const struct addrinfo *tmp;
1601 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1603 if (!_dbus_win_startup_winsock ())
1605 _DBUS_SET_OOM (error);
1606 return _dbus_socket_get_invalid ();
1612 hints.ai_family = AF_UNSPEC;
1613 else if (!strcmp(family,
"ipv4"))
1614 hints.ai_family = AF_INET;
1615 else if (!strcmp(family,
"ipv6"))
1616 hints.ai_family = AF_INET6;
1621 "Unknown address family %s", family);
1622 return _dbus_socket_get_invalid ();
1624 hints.ai_protocol = IPPROTO_TCP;
1625 hints.ai_socktype = SOCK_STREAM;
1627 hints.ai_flags = AI_ADDRCONFIG;
1632 if ((res = getaddrinfo(host, port, &hints, &ai)) != 0 || !ai)
1636 "Failed to lookup host/port: \"%s:%s\": %s (%d)",
1637 host, port, _dbus_strerror (res), res);
1644 if ((fd.sock = socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET)
1646 saved_errno = _dbus_get_low_level_socket_errno ();
1649 "Failed to open socket: %s",
1650 _dbus_strerror (saved_errno));
1654 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
1656 if (connect (fd.sock, (
struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) == SOCKET_ERROR)
1658 saved_errno = _dbus_get_low_level_socket_errno ();
1663 if (connect_error ==
NULL)
1665 _DBUS_SET_OOM (error);
1670 _dbus_set_error_with_inet_sockaddr (connect_error,
1671 tmp->ai_addr, tmp->ai_addrlen,
1672 "Failed to connect to socket",
1679 _DBUS_SET_OOM (error);
1690 if (!_dbus_socket_is_valid (fd))
1692 _dbus_combine_tcp_errors (&connect_errors,
"Failed to connect",
1697 if (noncefile !=
NULL)
1702 ret = _dbus_send_nonce (fd, &noncefileStr, error);
1712 _dbus_win_handle_set_close_on_exec ((HANDLE) fd.sock);
1753 const char **retfamily,
1758 int nlisten_fd = 0, res, i, port_num = -1;
1762 struct addrinfo hints;
1763 struct addrinfo *ai, *tmp;
1772 struct sockaddr Address;
1773 struct sockaddr_in AddressIn;
1774 struct sockaddr_in6 AddressIn6;
1778 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1780 if (!_dbus_win_startup_winsock ())
1782 _DBUS_SET_OOM (error);
1789 hints.ai_family = AF_UNSPEC;
1790 else if (!strcmp(family,
"ipv4"))
1791 hints.ai_family = AF_INET;
1792 else if (!strcmp(family,
"ipv6"))
1793 hints.ai_family = AF_INET6;
1798 "Unknown address family %s", family);
1802 hints.ai_protocol = IPPROTO_TCP;
1803 hints.ai_socktype = SOCK_STREAM;
1805 hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE;
1807 hints.ai_flags = AI_PASSIVE;
1810 redo_lookup_with_port:
1812 if ((res = getaddrinfo(host, port, &hints, &ai)) != 0 || !ai)
1816 "Failed to lookup host/port: \"%s:%s\": %s (%d)",
1817 host ? host :
"*", port, _dbus_strerror(res), res);
1824 const int reuseaddr = 1, tcp_nodelay_on = 1;
1825 DBusSocket fd = DBUS_SOCKET_INIT, *newlisten_fd;
1827 if ((fd.sock = socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET)
1829 saved_errno = _dbus_get_low_level_socket_errno ();
1832 "Failed to open socket: %s",
1833 _dbus_strerror (saved_errno));
1837 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
1839 if (setsockopt (fd.sock, SOL_SOCKET, SO_REUSEADDR, (
const char *)&reuseaddr,
sizeof(reuseaddr)) == SOCKET_ERROR)
1841 saved_errno = _dbus_get_low_level_socket_errno ();
1842 _dbus_warn (
"Failed to set socket option \"%s:%s\": %s",
1843 host ? host :
"*", port, _dbus_strerror (saved_errno));
1848 if (setsockopt (fd.sock, IPPROTO_TCP, TCP_NODELAY, (
const char *)&tcp_nodelay_on, sizeof (tcp_nodelay_on)) == SOCKET_ERROR)
1850 saved_errno = _dbus_get_low_level_socket_errno ();
1851 _dbus_warn (
"Failed to set TCP_NODELAY socket option \"%s:%s\": %s",
1852 host ? host :
"*", port, _dbus_strerror (saved_errno));
1855 if (bind (fd.sock, (
struct sockaddr *) tmp->ai_addr, tmp->ai_addrlen) == SOCKET_ERROR)
1857 saved_errno = _dbus_get_low_level_socket_errno ();
1858 closesocket (fd.sock);
1880 if (bind_error ==
NULL)
1882 _DBUS_SET_OOM (error);
1887 _dbus_set_error_with_inet_sockaddr (bind_error, tmp->ai_addr, tmp->ai_addrlen,
1888 "Failed to bind socket",
1895 _DBUS_SET_OOM (error);
1904 if (listen (fd.sock, 30 ) == SOCKET_ERROR)
1906 saved_errno = _dbus_get_low_level_socket_errno ();
1907 closesocket (fd.sock);
1908 _dbus_set_error_with_inet_sockaddr (error, tmp->ai_addr, tmp->ai_addrlen,
1909 "Failed to listen on socket",
1917 closesocket (fd.sock);
1919 "Failed to allocate file handle array");
1922 listen_fd = newlisten_fd;
1923 listen_fd[nlisten_fd] = fd;
1926 if (tmp->ai_addr->sa_family == AF_INET)
1928 else if (tmp->ai_addr->sa_family == AF_INET6)
1931 if (!_dbus_string_get_length(retport))
1937 if (!port || !strcmp(port,
"0"))
1939 mysockaddr_gen addr;
1940 socklen_t addrlen =
sizeof(addr);
1941 char portbuf[NI_MAXSERV];
1943 if (getsockname (fd.sock, &addr.Address, &addrlen) == SOCKET_ERROR ||
1944 (res = getnameinfo (&addr.Address, addrlen,
NULL, 0,
1945 portbuf,
sizeof(portbuf),
1946 NI_NUMERICSERV)) != 0)
1948 saved_errno = _dbus_get_low_level_socket_errno ();
1950 "Failed to resolve port \"%s:%s\": %s",
1951 host ? host :
"*", port, _dbus_strerror (saved_errno));
1961 port = _dbus_string_get_const_data(retport);
1963 goto redo_lookup_with_port;
1982 _dbus_combine_tcp_errors (&bind_errors,
"Failed to bind", host, port, error);
1986 if (have_ipv4 && !have_ipv6)
1987 *retfamily =
"ipv4";
1988 else if (!have_ipv4 && have_ipv6)
1989 *retfamily =
"ipv6";
1991 sscanf(_dbus_string_get_const_data(retport),
"%d", &port_num);
1993 for (i = 0 ; i < nlisten_fd ; i++)
1995 _dbus_win_handle_set_close_on_exec ((HANDLE) listen_fd[i].sock);
2016 for (i = 0 ; i < nlisten_fd ; i++)
2017 closesocket (listen_fd[i].sock);
2043 client_fd.sock = accept (listen_fd.sock,
NULL,
NULL);
2045 if (!_dbus_socket_is_valid (client_fd))
2047 DBUS_SOCKET_SET_ERRNO ();
2052 _dbus_verbose (
"client fd %Iu accepted\n", client_fd.sock);
2094 if (bytes_written < 0 && errno == EINTR)
2097 if (bytes_written < 0)
2100 "Failed to write credentials byte: %s",
2104 else if (bytes_written == 0)
2107 "wrote zero bytes writing credentials byte");
2113 _dbus_verbose (
"wrote 1 zero byte, credential sending isn't implemented yet\n");
2130 struct sockaddr_un saddr;
2133 len =
sizeof (saddr);
2134 if (getsockname (s.sock, (
struct sockaddr *)&saddr, &len) == SOCKET_ERROR)
2136 DBUS_SOCKET_SET_ERRNO ();
2138 "Failed to getsockname: %s",
2143 return saddr.sun_family == AF_UNIX;
2152_dbus_get_peer_pid_from_uds_handle (
int handle)
2156 if (WSAIoctl (handle, SIO_AF_UNIX_GETPEERPID,
2158 &pid,
sizeof (pid), &drc,
2161 _dbus_verbose (
"failed to get peer's pid\n");
2208 _dbus_verbose (
"got one zero byte from server\n");
2214 uds = _dbus_socket_is_af_unix (handle, error);
2219 pid = _dbus_get_peer_pid_from_uds_handle (handle.sock);
2222 pid = _dbus_get_peer_pid_from_tcp_handle (handle.sock);
2228 if (_dbus_getsid (&sid, pid))
2255 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2277 if (_dbus_string_get_length (dir) == 0 ||
2278 _dbus_string_get_length (next_component) == 0)
2282 (
'/' == _dbus_string_get_byte (dir, _dbus_string_get_length (dir) - 1) ||
2283 '\\' == _dbus_string_get_byte (dir, _dbus_string_get_length (dir) - 1));
2285 file_starts_with_slash =
2286 (
'/' == _dbus_string_get_byte (next_component, 0) ||
2287 '\\' == _dbus_string_get_byte (next_component, 0));
2289 if (dir_ends_in_slash && file_starts_with_slash)
2293 else if (!(dir_ends_in_slash || file_starts_with_slash))
2300 _dbus_string_get_length (dir));
2315 DBusCredentialsAddFlags flags,
2319 _dbus_string_get_const_data (username)))
2321 _DBUS_SET_OOM (error);
2396 return GetCurrentProcessId ();
2409#define NANOSECONDS_PER_SECOND 1000000000
2411#define MICROSECONDS_PER_SECOND 1000000
2413#define MILLISECONDS_PER_SECOND 1000
2415#define NANOSECONDS_PER_MILLISECOND 1000000
2417#define MICROSECONDS_PER_MILLISECOND 1000
2426 Sleep (milliseconds);
2444 GetSystemTimeAsFileTime (&ft);
2446 memcpy (&time64, &ft,
sizeof (time64));
2455 *tv_sec = time64 / 1000000;
2458 *tv_usec = time64 % 1000000;
2496 const char *filename_c;
2498 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2500 filename_c = _dbus_string_get_const_data (filename);
2502 if (!CreateDirectoryA (filename_c,
NULL))
2505 "Failed to create directory %s: %s\n",
2525 const char *filename_c;
2527 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2529 filename_c = _dbus_string_get_const_data (filename);
2531 if (!CreateDirectoryA (filename_c,
NULL))
2533 if (GetLastError () == ERROR_ALREADY_EXISTS)
2537 "Failed to create directory %s: %s\n",
2564 old_len = _dbus_string_get_length (str);
2568 _DBUS_SET_OOM (error);
2572 p = _dbus_string_get_udata_len (str, old_len, n_bytes);
2574 if (!CryptAcquireContext (&hprov,
NULL,
NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
2576 _DBUS_SET_OOM (error);
2580 if (!CryptGenRandom (hprov, n_bytes, p))
2582 _DBUS_SET_OOM (error);
2583 CryptReleaseContext (hprov, 0);
2587 CryptReleaseContext (hprov, 0);
2601 static const char* tmpdir =
NULL;
2602 static char buf[1000];
2609 unsigned char *last_slash;
2610 unsigned char *p = (
unsigned char *)buf;
2612 if (!GetTempPathA (
sizeof (buf), buf))
2619 last_slash = _mbsrchr (p,
'\\');
2620 if (last_slash > p && last_slash[1] ==
'\0')
2621 last_slash[0] =
'\0';
2622 last_slash = _mbsrchr (p,
'/');
2623 if (last_slash > p && last_slash[1] ==
'\0')
2624 last_slash[0] =
'\0';
2649 const char *filename_c;
2651 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2653 filename_c = _dbus_string_get_const_data (filename);
2655 if (DeleteFileA (filename_c) == 0)
2658 "Failed to delete file %s: %s\n",
2666#if !defined (DBUS_DISABLE_ASSERT) || defined(DBUS_ENABLE_EMBEDDED_TESTS)
2668#if defined(_MSC_VER) || defined(DBUS_WINCE)
2699#include <imagehlp.h>
2702#define DPRINTF(fmt, ...) fprintf (stderr, fmt, ##__VA_ARGS__)
2710static void dump_backtrace_for_thread (HANDLE hThread)
2712 ADDRESS old_address;
2718 SymSetOptions (SYMOPT_UNDNAME | SYMOPT_LOAD_LINES);
2719 SymInitialize (GetCurrentProcess (),
NULL,
TRUE);
2724 if (hThread == GetCurrentThread())
2727 DPRINTF (
"Backtrace:\n");
2731 context.ContextFlags = CONTEXT_FULL;
2733 SuspendThread (hThread);
2735 if (!GetThreadContext (hThread, &context))
2737 DPRINTF (
"Couldn't get thread context (error %ld)\n", GetLastError ());
2738 ResumeThread (hThread);
2745 dwImageType = IMAGE_FILE_MACHINE_I386;
2746 sf.AddrFrame.Offset = context.Ebp;
2747 sf.AddrFrame.Mode = AddrModeFlat;
2748 sf.AddrPC.Offset = context.Eip;
2749 sf.AddrPC.Mode = AddrModeFlat;
2750#elif defined(_M_X64)
2751 dwImageType = IMAGE_FILE_MACHINE_AMD64;
2752 sf.AddrPC.Offset = context.Rip;
2753 sf.AddrPC.Mode = AddrModeFlat;
2754 sf.AddrFrame.Offset = context.Rsp;
2755 sf.AddrFrame.Mode = AddrModeFlat;
2756 sf.AddrStack.Offset = context.Rsp;
2757 sf.AddrStack.Mode = AddrModeFlat;
2758#elif defined(_M_IA64)
2759 dwImageType = IMAGE_FILE_MACHINE_IA64;
2760 sf.AddrPC.Offset = context.StIIP;
2761 sf.AddrPC.Mode = AddrModeFlat;
2762 sf.AddrFrame.Offset = context.IntSp;
2763 sf.AddrFrame.Mode = AddrModeFlat;
2764 sf.AddrBStore.Offset= context.RsBSP;
2765 sf.AddrBStore.Mode = AddrModeFlat;
2766 sf.AddrStack.Offset = context.IntSp;
2767 sf.AddrStack.Mode = AddrModeFlat;
2769# error You need to fill in the STACKFRAME structure for your architecture
2778 while (StackWalk (dwImageType, GetCurrentProcess (),
2779 hThread, &sf, &context,
NULL, SymFunctionTableAccess,
2780 SymGetModuleBase,
NULL))
2782 char buffer[
sizeof(SYMBOL_INFO) + MAX_SYM_NAME *
sizeof(
char)];
2783 PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
2784 DWORD64 displacement;
2786 DWORD dwDisplacement;
2787 IMAGEHLP_MODULE moduleInfo;
2795 if (old_address.Offset == sf.AddrPC.Offset)
2801 pSymbol->SizeOfStruct =
sizeof(SYMBOL_INFO);
2802 pSymbol->MaxNameLen = MAX_SYM_NAME;
2804 if (SymFromAddr (GetCurrentProcess (), sf.AddrPC.Offset, &displacement, pSymbol))
2807 DPRINTF (
"%3d %s+0x%I64x", i++, pSymbol->Name, displacement);
2809 DPRINTF (
"%3d %s", i++, pSymbol->Name);
2812 DPRINTF (
"%3d 0x%Ix", i++, sf.AddrPC.Offset);
2814 line.SizeOfStruct =
sizeof(IMAGEHLP_LINE);
2815 if (SymGetLineFromAddr (GetCurrentProcess (), sf.AddrPC.Offset, &dwDisplacement, &line))
2817 DPRINTF (
" [%s:%ld]", line.FileName, line.LineNumber);
2820 moduleInfo.SizeOfStruct =
sizeof(moduleInfo);
2821 if (SymGetModuleInfo (GetCurrentProcess (), sf.AddrPC.Offset, &moduleInfo))
2823 DPRINTF (
" in %s", moduleInfo.ModuleName);
2826 old_address = sf.AddrPC;
2828 ResumeThread (hThread);
2831static DWORD WINAPI dump_thread_proc (LPVOID lpParameter)
2833 dump_backtrace_for_thread ((HANDLE) lpParameter);
2840dump_backtrace (
void)
2842 HANDLE hCurrentThread;
2845 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
2846 GetCurrentProcess (), &hCurrentThread,
2847 0,
FALSE, DUPLICATE_SAME_ACCESS);
2848 hThread = CreateThread (
NULL, 0, dump_thread_proc, (LPVOID)hCurrentThread,
2850 WaitForSingleObject (hThread, INFINITE);
2851 CloseHandle (hThread);
2852 CloseHandle (hCurrentThread);
2865 _dbus_verbose (
" D-Bus not compiled with backtrace support\n");
2871 if(ascii >=
'0' && ascii <=
'9')
2873 if(ascii >=
'A' && ascii <=
'F')
2874 return ascii -
'A' + 10;
2875 if(ascii >=
'a' && ascii <=
'f')
2876 return ascii -
'a' + 10;
2888 HW_PROFILE_INFOA info;
2889 char *lpc = &info.szHwProfileGuid[0];
2893 if(!GetCurrentHwProfileA(&info))
2902 u = ((fromAscii(lpc[0]) << 0) |
2903 (fromAscii(lpc[1]) << 4) |
2904 (fromAscii(lpc[2]) << 8) |
2905 (fromAscii(lpc[3]) << 12) |
2906 (fromAscii(lpc[4]) << 16) |
2907 (fromAscii(lpc[5]) << 20) |
2908 (fromAscii(lpc[6]) << 24) |
2909 (fromAscii(lpc[7]) << 28));
2914 u = ((fromAscii(lpc[0]) << 0) |
2915 (fromAscii(lpc[1]) << 4) |
2916 (fromAscii(lpc[2]) << 8) |
2917 (fromAscii(lpc[3]) << 12) |
2918 (fromAscii(lpc[5]) << 16) |
2919 (fromAscii(lpc[6]) << 20) |
2920 (fromAscii(lpc[7]) << 24) |
2921 (fromAscii(lpc[8]) << 28));
2926 u = ((fromAscii(lpc[0]) << 0) |
2927 (fromAscii(lpc[1]) << 4) |
2928 (fromAscii(lpc[2]) << 8) |
2929 (fromAscii(lpc[3]) << 12) |
2930 (fromAscii(lpc[5]) << 16) |
2931 (fromAscii(lpc[6]) << 20) |
2932 (fromAscii(lpc[7]) << 24) |
2933 (fromAscii(lpc[8]) << 28));
2938 u = ((fromAscii(lpc[0]) << 0) |
2939 (fromAscii(lpc[1]) << 4) |
2940 (fromAscii(lpc[2]) << 8) |
2941 (fromAscii(lpc[3]) << 12) |
2942 (fromAscii(lpc[4]) << 16) |
2943 (fromAscii(lpc[5]) << 20) |
2944 (fromAscii(lpc[6]) << 24) |
2945 (fromAscii(lpc[7]) << 28));
2952static HANDLE hDBusDaemonMutex =
NULL;
2953static HANDLE hDBusSharedMem =
NULL;
2955static const char *cUniqueDBusInitMutex =
"UniqueDBusInitMutex";
2957static const char *cDBusAutolaunchMutex =
"DBusAutolaunchMutex";
2959static const char *cDBusDaemonMutex =
"DBusDaemonMutex";
2961static const char *cDBusDaemonAddressInfo =
"DBusDaemonAddressInfo";
2964static const char *autolaunch_custom_command_line_parameter =
"";
2978void _dbus_test_win_autolaunch_set_command_line_parameter (
const char *path)
2980 autolaunch_custom_command_line_parameter = path;
2983static HANDLE *autolaunch_handle_location;
2996_dbus_test_win_set_autolaunch_handle_location (HANDLE *location)
2998 autolaunch_handle_location = location;
3012_dbus_get_install_root_as_hash (
DBusString *out)
3021 if (!_dbus_get_install_root (&install_path))
3025 if (_dbus_string_get_length (&install_path) == 0)
3063_dbus_get_address_string (
DBusString *out,
const char *basestring,
const char *scope)
3067 if (!scope || strlen (scope) == 0)
3071 else if (strcmp (scope,
"*install-path") == 0
3073 || strcmp (scope,
"install-path") == 0)
3081 if (!_dbus_get_install_root_as_hash (&temp))
3084 if (_dbus_string_get_length (&temp) == 0)
3099 else if (strcmp (scope,
"*user") == 0)
3128_dbus_get_shm_name (
DBusString *out,
const char *scope)
3130 return _dbus_get_address_string (out, cDBusDaemonAddressInfo, scope);
3143_dbus_get_mutex_name (
DBusString *out,
const char *scope)
3145 return _dbus_get_address_string (out, cDBusDaemonMutex, scope);
3149_dbus_daemon_is_session_bus_address_published (
const char *scope)
3157 _dbus_verbose (
"scope:%s\n", scope);
3158 if (!_dbus_get_mutex_name (&mutex_name, scope) ||
3160 _dbus_string_get_length (&mutex_name) == 0)
3166 if (hDBusDaemonMutex)
3168 _dbus_verbose (
"(scope:%s) -> yes\n", scope);
3171 lock = _dbus_win_rmutex_named_new (cUniqueDBusInitMutex);
3176 _dbus_platform_rmutex_lock (lock);
3180 hDBusDaemonMutex = CreateMutexA (
NULL,
FALSE, _dbus_string_get_const_data(&mutex_name));
3186 _dbus_platform_rmutex_unlock (lock);
3187 _dbus_platform_rmutex_free (lock);
3191 if (hDBusDaemonMutex ==
NULL)
3193 _dbus_verbose (
"(scope:%s) -> no\n", scope);
3196 if (GetLastError() == ERROR_ALREADY_EXISTS)
3198 CloseHandle(hDBusDaemonMutex);
3199 hDBusDaemonMutex =
NULL;
3200 _dbus_verbose (
"(scope:%s) -> yes\n", scope);
3206 _dbus_verbose (
"(scope:%s) -> no\n", scope);
3211_dbus_daemon_publish_session_bus_address (
const char* address,
const char *scope)
3214 char *shared_addr =
NULL;
3215 DBusString shm_name = _DBUS_STRING_INIT_INVALID;
3225 _dbus_verbose (
"address:%s scope:%s\n", address, scope);
3226 if (!_dbus_get_mutex_name (&mutex_name, scope) ||
3228 _dbus_string_get_length (&mutex_name) == 0)
3235 lock = _dbus_win_rmutex_named_new (cUniqueDBusInitMutex);
3242 _dbus_platform_rmutex_lock (lock);
3244 if (!hDBusDaemonMutex)
3246 hDBusDaemonMutex = CreateMutexA (
NULL,
FALSE, _dbus_string_get_const_data(&mutex_name));
3251 if (WaitForSingleObject (hDBusDaemonMutex, 10) != WAIT_OBJECT_0)
3253 CloseHandle (hDBusDaemonMutex);
3262 if (!_dbus_get_shm_name (&shm_name, scope) ||
3264 _dbus_string_get_length (&shm_name) == 0)
3270 len = strlen (address) + 1;
3272 hDBusSharedMem = CreateFileMappingA ( INVALID_HANDLE_VALUE,
NULL, PAGE_READWRITE,
3273 len >> 32, len & 0xffffffffu,
3274 _dbus_string_get_const_data (&shm_name) );
3277 shared_addr = MapViewOfFile (hDBusSharedMem, FILE_MAP_WRITE, 0, 0, 0);
3281 strcpy(shared_addr, address);
3284 UnmapViewOfFile (shared_addr);
3286 _dbus_verbose (
"published session bus address at %s\n",_dbus_string_get_const_data (&shm_name));
3290 _dbus_platform_rmutex_unlock (lock);
3291 _dbus_platform_rmutex_free (lock);
3318 _dbus_verbose (
"\n");
3320 lock = _dbus_win_rmutex_named_new (cUniqueDBusInitMutex);
3324 _dbus_platform_rmutex_lock (lock);
3326 CloseHandle (hDBusSharedMem);
3328 hDBusSharedMem =
NULL;
3330 ReleaseMutex (hDBusDaemonMutex);
3332 CloseHandle (hDBusDaemonMutex);
3334 hDBusDaemonMutex =
NULL;
3336 _dbus_platform_rmutex_unlock (lock);
3337 _dbus_platform_rmutex_free (lock);
3353 HANDLE sharedMem =
NULL;
3363 for (i = 0; i < max; ++i)
3366 sharedMem = OpenFileMappingA (FILE_MAP_READ,
FALSE, _dbus_string_get_const_data (shm_name));
3376 shared_addr = MapViewOfFile (sharedMem, FILE_MAP_READ, 0, 0, 0);
3383 UnmapViewOfFile (shared_addr);
3386 CloseHandle (sharedMem);
3401 if (!_dbus_get_mutex_name (&mutex_name, scope) ||
3403 _dbus_string_get_length (&mutex_name) == 0)
3410 lock = _dbus_win_rmutex_named_new (cUniqueDBusInitMutex);
3414 _dbus_platform_rmutex_lock (lock);
3417 daemon = CreateMutexA (
NULL,
FALSE, _dbus_string_get_const_data (&mutex_name));
3418 if (WaitForSingleObject (daemon, 10) != WAIT_TIMEOUT)
3420 ReleaseMutex (daemon);
3421 CloseHandle (daemon);
3426 retval = _dbus_get_autolaunch_shm (address, shm_name,
TRUE);
3429 CloseHandle (daemon);
3432 _dbus_platform_rmutex_unlock (lock);
3433 _dbus_platform_rmutex_free (lock);
3446 PROCESS_INFORMATION pi;
3449 char dbus_exe_path[MAX_PATH];
3450 DBusString dbus_args = _DBUS_STRING_INIT_INVALID;
3451 const char *daemon_name = DBUS_DAEMON_NAME
".exe";
3453 HANDLE ready_event_handle =
NULL;
3455 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
3459 _DBUS_SET_OOM (error);
3463 if (!_dbus_get_shm_name (&shm_name, scope) ||
3465 _dbus_string_get_length (&shm_name) == 0)
3471 lock = _dbus_win_rmutex_named_new (cDBusAutolaunchMutex);
3479 _dbus_platform_rmutex_lock (lock);
3481 if (_dbus_daemon_already_runs (address, &shm_name, scope))
3483 _dbus_verbose (
"found running dbus daemon for scope '%s' at %s\n",
3484 scope ? scope :
"", _dbus_string_get_const_data (&shm_name));
3489 if (!SearchPathA (
NULL, daemon_name,
NULL,
sizeof (dbus_exe_path), dbus_exe_path, &lpFile))
3493 char dbus_module_path[MAX_PATH];
3496 _dbus_verbose (
"did not found dbus daemon executable on default search path, "
3497 "trying path where dbus shared library is located");
3499 hmod = _dbus_win_get_dll_hmodule ();
3500 rc = GetModuleFileNameA (hmod, dbus_module_path,
sizeof (dbus_module_path));
3509 char *ext_idx = strrchr (dbus_module_path,
'\\');
3512 if (!SearchPathA (dbus_module_path, daemon_name,
NULL,
sizeof (dbus_exe_path), dbus_exe_path, &lpFile))
3515 "Could not find dbus-daemon executable. "
3516 "Please add the path to %s to your PATH "
3517 "environment variable or start the daemon manually",
3522 _dbus_verbose (
"found dbus daemon executable at %s", dbus_module_path);
3527 ZeroMemory (&si,
sizeof (si));
3528 si.cb =
sizeof (si);
3529 ZeroMemory (&pi,
sizeof (pi));
3539 autolaunch_custom_command_line_parameter ? autolaunch_custom_command_line_parameter :
"--session"))
3541 _DBUS_SET_OOM (error);
3546 ready_event_handle = _dbus_win_event_create_inheritable (error);
3547 if (ready_event_handle ==
NULL)
3550 _dbus_verbose (
"Creating connection readiness event: handle=%p\n", ready_event_handle);
3553 _DBUS_SET_OOM (error);
3557 _dbus_verbose (
"Starting dbus daemon with args: '%s'\n", _dbus_string_get_const_data (&dbus_args));
3558 if (CreateProcessA (dbus_exe_path, _dbus_string_get_data (&dbus_args),
NULL,
NULL,
TRUE, CREATE_NO_WINDOW,
NULL,
NULL, &si, &pi))
3563 CloseHandle (pi.hThread);
3565 _dbus_verbose (
"Wait until dbus-daemon is ready for connections (event handle %p)\n", ready_event_handle);
3567 events[0] = ready_event_handle;
3568 events[1] = pi.hProcess;
3569 status = WaitForMultipleObjects (2, events,
FALSE, 30000);
3578 case WAIT_OBJECT_0 + 1:
3584 _dbus_win_set_error_from_last_error (error,
"Unable to wait for server readiness (handle %p)", ready_event_handle);
3597 _dbus_verbose (
"Got signal that dbus-daemon with process id '%ld' is ready for connections\n", GetProcessId (pi.hProcess));
3599 if (autolaunch_handle_location !=
NULL)
3601 *autolaunch_handle_location = pi.hProcess;
3602 _dbus_verbose (
"Returning process handle of started server (handle=%p)\n", pi.hProcess);
3606 CloseHandle (pi.hProcess);
3610 retval = _dbus_get_autolaunch_shm (address, &shm_name,
FALSE);
3611 if (retval ==
FALSE)
3621 _DBUS_ASSERT_ERROR_XOR_BOOL (error, retval);
3622 _dbus_platform_rmutex_unlock (lock);
3623 _dbus_platform_rmutex_free (lock);
3626 if (ready_event_handle)
3627 _dbus_win_event_free (ready_event_handle,
NULL);
3629 _DBUS_ASSERT_ERROR_XOR_BOOL (error, retval);
3659 return InterlockedIncrement (&atomic->
value) - 1;
3674 return InterlockedDecrement (&atomic->
value) + 1;
3697 InterlockedExchange (&dummy, 1);
3699 return atomic->
value;
3710 InterlockedExchange (&atomic->
value, 0);
3721 InterlockedExchange (&atomic->
value, 1);
3745 return e == WSAEWOULDBLOCK;
3759 DWORD pathLength = MAX_PATH;
3760 unsigned char *lastSlash;
3761 unsigned char *prefix;
3773 pathLength = GetModuleFileNameA (_dbus_win_get_dll_hmodule (),
3774 _dbus_string_get_data (str), _dbus_string_get_length (str));
3776 if (pathLength == 0 || GetLastError () != 0)
3785 if (pathLength < (DWORD) _dbus_string_get_length (str))
3804 prefix = _dbus_string_get_udata (str);
3806 lastSlash = _mbsrchr (prefix,
'\\');
3807 if (lastSlash ==
NULL) {
3820 if (lastSlash - prefix >= 4 && _mbsnicmp (lastSlash - 4, (
const unsigned char *)
"\\bin", 4) == 0)
3822 else if (lastSlash - prefix >= 10 && _mbsnicmp (lastSlash - 10, (
const unsigned char *)
"\\bin\\debug", 10) == 0)
3824 else if (lastSlash - prefix >= 12 && _mbsnicmp (lastSlash - 12, (
const unsigned char *)
"\\bin\\release", 12) == 0)
3863 const char *homepath;
3864 const char *homedrive;
3873 if (homedrive !=
NULL && *homedrive !=
'\0')
3879 if (homepath !=
NULL && *homepath !=
'\0')
3884#ifdef DBUS_ENABLE_EMBEDDED_TESTS
3886 const char *
override;
3889 if (
override !=
NULL && *
override !=
'\0')
3895 _dbus_verbose (
"Using fake homedir for testing: %s\n",
3896 _dbus_string_get_const_data (&homedir));
3903 if (!already_warned)
3905 _dbus_warn (
"Using your real home directory for testing, set DBUS_TEST_HOMEDIR to avoid");
3906 already_warned =
TRUE;
3915#define KEYRING_DIR "dbus-keyrings"
3917#define KEYRING_DIR ".dbus-keyrings"
3926 directory, _dbus_string_get_length (directory))) {
3946 DWORD attributes = GetFileAttributesA (file);
3948 if (attributes != INVALID_FILE_ATTRIBUTES && GetLastError() != ERROR_PATH_NOT_FOUND)
3962_dbus_strerror (
int error_number)
3970 switch (error_number)
3973 return "Interrupted function call";
3975 return "Permission denied";
3977 return "Bad address";
3979 return "Invalid argument";
3981 return "Too many open files";
3982 case WSAEWOULDBLOCK:
3983 return "Resource temporarily unavailable";
3984 case WSAEINPROGRESS:
3985 return "Operation now in progress";
3987 return "Operation already in progress";
3989 return "Socket operation on nonsocket";
3990 case WSAEDESTADDRREQ:
3991 return "Destination address required";
3993 return "Message too long";
3995 return "Protocol wrong type for socket";
3996 case WSAENOPROTOOPT:
3997 return "Bad protocol option";
3998 case WSAEPROTONOSUPPORT:
3999 return "Protocol not supported";
4000 case WSAESOCKTNOSUPPORT:
4001 return "Socket type not supported";
4003 return "Operation not supported";
4004 case WSAEPFNOSUPPORT:
4005 return "Protocol family not supported";
4006 case WSAEAFNOSUPPORT:
4007 return "Address family not supported by protocol family";
4009 return "Address already in use";
4010 case WSAEADDRNOTAVAIL:
4011 return "Cannot assign requested address";
4013 return "Network is down";
4014 case WSAENETUNREACH:
4015 return "Network is unreachable";
4017 return "Network dropped connection on reset";
4018 case WSAECONNABORTED:
4019 return "Software caused connection abort";
4021 return "Connection reset by peer";
4023 return "No buffer space available";
4025 return "Socket is already connected";
4027 return "Socket is not connected";
4029 return "Cannot send after socket shutdown";
4031 return "Connection timed out";
4032 case WSAECONNREFUSED:
4033 return "Connection refused";
4035 return "Host is down";
4036 case WSAEHOSTUNREACH:
4037 return "No route to host";
4039 return "Too many processes";
4041 return "Graceful shutdown in progress";
4042 case WSATYPE_NOT_FOUND:
4043 return "Class type not found";
4044 case WSAHOST_NOT_FOUND:
4045 return "Host not found";
4047 return "Nonauthoritative host not found";
4048 case WSANO_RECOVERY:
4049 return "This is a nonrecoverable error";
4051 return "Valid name, no data record of requested type";
4052 case WSA_INVALID_HANDLE:
4053 return "Specified event object handle is invalid";
4054 case WSA_INVALID_PARAMETER:
4055 return "One or more parameters are invalid";
4056 case WSA_IO_INCOMPLETE:
4057 return "Overlapped I/O event object not in signaled state";
4058 case WSA_IO_PENDING:
4059 return "Overlapped operations will complete later";
4060 case WSA_NOT_ENOUGH_MEMORY:
4061 return "Insufficient memory available";
4062 case WSA_OPERATION_ABORTED:
4063 return "Overlapped operation aborted";
4064#ifdef WSAINVALIDPROCTABLE
4066 case WSAINVALIDPROCTABLE:
4067 return "Invalid procedure table from service provider";
4069#ifdef WSAINVALIDPROVIDER
4071 case WSAINVALIDPROVIDER:
4072 return "Invalid service provider version number";
4074#ifdef WSAPROVIDERFAILEDINIT
4076 case WSAPROVIDERFAILEDINIT:
4077 return "Unable to initialize a service provider";
4080 case WSASYSCALLFAILURE:
4081 return "System call failure";
4084 msg = strerror (error_number);
4102_dbus_win_set_error_from_win_error (
DBusError *error,
4108 FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
4109 FORMAT_MESSAGE_IGNORE_INSERTS |
4110 FORMAT_MESSAGE_FROM_SYSTEM,
4111 NULL, code, MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US),
4112 (LPSTR) &msg, 0,
NULL);
4119 dbus_set_error (error,
"win32.error",
"Unknown error code %d or FormatMessage failed", code);
4123_dbus_win_warn_win_error (
const char *message,
4129 _dbus_win_set_error_from_win_error (&error, code);
4145 const char *filename_c;
4147 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
4149 filename_c = _dbus_string_get_const_data (filename);
4151 if (RemoveDirectoryA (filename_c) == 0)
4153 char *emsg = _dbus_win_error_string (GetLastError ());
4155 "Failed to remove directory %s: %s",
4157 _dbus_win_free_error_string (emsg);
4173 if (_dbus_string_get_length (filename) > 0)
4174 return _dbus_string_get_byte (filename, 1) ==
':'
4175 || _dbus_string_get_byte (filename, 0) ==
'\\'
4176 || _dbus_string_get_byte (filename, 0) ==
'/';
4188_dbus_save_socket_errno (
void)
4194_dbus_restore_socket_errno (
int saved_errno)
4196 _dbus_win_set_errno (saved_errno);
4199static const char *log_tag =
"dbus";
4200static DBusLogFlags log_flags = DBUS_LOG_FLAGS_STDERR;
4218 (flags & (DBUS_LOG_FLAGS_STDERR | DBUS_LOG_FLAGS_SYSTEM_LOG)) != 0);
4241 case DBUS_SYSTEM_LOG_INFO: s =
"info";
break;
4242 case DBUS_SYSTEM_LOG_WARNING: s =
"warning";
break;
4243 case DBUS_SYSTEM_LOG_SECURITY: s =
"security";
break;
4244 case DBUS_SYSTEM_LOG_ERROR: s =
"error";
break;
4248 if (log_flags & DBUS_LOG_FLAGS_SYSTEM_LOG)
4251 const char *message =
NULL;
4252 va_copy (tmp, args);
4260 message = _dbus_string_get_const_data (&out);
4262 if (message !=
NULL)
4264 OutputDebugStringA (message);
4268 OutputDebugStringA (
"Out of memory while formatting message: '''");
4269 OutputDebugStringA (msg);
4270 OutputDebugStringA (
"'''");
4277 if (log_flags & DBUS_LOG_FLAGS_STDERR)
4279 va_copy (tmp, args);
4281 vfprintf (stderr, msg, tmp);
4282 fprintf (stderr,
"\n");
4296_dbus_get_low_level_socket_errno (
void)
4298 return WSAGetLastError ();
4302_dbus_win_set_error_from_last_error (
DBusError *error,
4307 char *message =
NULL;
4313 name = _dbus_win_error_from_last_error ();
4314 message = _dbus_win_error_string (GetLastError ());
4324 _DBUS_SET_OOM (error);
4328 va_start (args, format);
4333 _DBUS_SET_OOM (error);
4338 dbus_set_error (error, name,
"%s: %s", _dbus_string_get_const_data (&str), message);
4347 if (message !=
NULL)
4348 _dbus_win_free_error_string (message);
4350 _DBUS_ASSERT_ERROR_IS_SET (error);
4365_dbus_win_event_create_inheritable (
DBusError *error)
4372 _dbus_win_set_error_from_last_error (error,
"Could not create event");
4375 else if (GetLastError () == ERROR_ALREADY_EXISTS)
4377 _dbus_win_set_error_from_last_error (error,
"Event already exists");
4381 if (!SetHandleInformation (handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT))
4383 _dbus_win_set_error_from_last_error (error,
"Could not set inheritance for event %p", handle);
4384 CloseHandle (handle);
4398_dbus_win_event_set (HANDLE handle,
DBusError *error)
4402 if (!SetEvent (handle))
4404 _dbus_win_set_error_from_last_error (error,
"Could not trigger event (handle %p)", handle);
4421_dbus_win_event_wait (HANDLE handle,
int timeout,
DBusError *error)
4427 status = WaitForSingleObject (handle, timeout);
4435 _dbus_win_set_error_from_last_error (error,
"Unable to wait for event (handle %p)", handle);
4460_dbus_win_event_free (HANDLE handle,
DBusError *error)
4462 if (handle ==
NULL || handle == INVALID_HANDLE_VALUE)
4465 if (CloseHandle (handle))
4469 if (GetLastError () == ERROR_INVALID_HANDLE)
4472 _dbus_win_set_error_from_last_error (error,
"Could not close event (handle %p)", handle);
4478_dbus_open_socket (SOCKET *socket_p,
4484 if (!_dbus_win_startup_winsock ())
4486 _DBUS_SET_OOM (error);
4490 *socket_p = socket (domain, type, protocol);
4491 if (*socket_p == INVALID_SOCKET)
4493 DBUS_SOCKET_SET_ERRNO ();
4495 "Failed to open socket: %s",
4500 _dbus_win_handle_set_close_on_exec ((HANDLE) *socket_p);
4515_dbus_open_unix_socket (SOCKET *socket,
4518 return _dbus_open_socket (socket, AF_UNIX, SOCK_STREAM, 0, error);
4544 struct sockaddr_un addr;
4548 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
4550 _dbus_verbose (
"connecting to unix socket %s abstract=%d\n",
4556 "Failed to connect: UNIX abstract socket is not supported on this system");
4560 path_len = strlen (path);
4564 "Failed to connect: socket name too long");
4568 if (!_dbus_open_unix_socket (&s.sock, error))
4570 _DBUS_ASSERT_ERROR_IS_SET (error);
4573 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
4576 addr.sun_family = AF_UNIX;
4577 strncpy (addr.sun_path, path, sizeof (addr.sun_path) - 1);
4579 if (connect (s.sock, (
struct sockaddr *) &addr, _DBUS_STRUCT_OFFSET (
struct sockaddr_un, sun_path) + path_len) < 0)
4581 DBUS_SOCKET_SET_ERRNO ();
4584 "Failed to connect to socket %s: %s",
4585 path, _dbus_strerror (errno));
4596 "Failed to connect: UNIX socket is not supported with this build");
4624 struct sockaddr_un addr;
4628 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
4630 _dbus_verbose (
"listening on unix socket %s abstract=%d\n",
4636 "Failed to listen: UNIX abstract socket is not supported on this system");
4640 if (!_dbus_open_unix_socket (&s.sock, error))
4642 _DBUS_ASSERT_ERROR_IS_SET (error);
4645 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
4648 addr.sun_family = AF_UNIX;
4649 path_len = strlen (path);
4658 "Failed to listen: socket name too long");
4663 strncpy (addr.sun_path, path, sizeof (addr.sun_path) - 1);
4665 if (bind (s.sock, (
struct sockaddr *) &addr, _DBUS_STRUCT_OFFSET (
struct sockaddr_un, sun_path) + path_len) < 0)
4667 DBUS_SOCKET_SET_ERRNO ();
4669 "Failed to bind socket \"%s\": %s",
4670 path, _dbus_strerror (errno));
4675 if (listen (s.sock, SOMAXCONN ) < 0)
4677 DBUS_SOCKET_SET_ERRNO ();
4679 "Failed to listen on socket \"%s\": %s",
4680 path, _dbus_strerror (errno));
4687 _DBUS_ASSERT_ERROR_IS_SET (error);
4693 "Failed to listen: UNIX socket is not supported with this build");
dbus_bool_t _dbus_credentials_add_windows_sid(DBusCredentials *credentials, const char *windows_sid)
Add a Windows user SID to the credentials.
dbus_bool_t _dbus_credentials_add_pid(DBusCredentials *credentials, dbus_pid_t pid)
Add a UNIX process ID to the credentials.
dbus_bool_t _dbus_credentials_are_anonymous(DBusCredentials *credentials)
Checks whether a credentials object contains a user identity.
void dbus_set_error_const(DBusError *error, const char *name, const char *message)
Assigns an error name and message to a DBusError.
void dbus_error_init(DBusError *error)
Initializes a DBusError structure.
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
void dbus_error_free(DBusError *error)
Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_i...
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
dbus_bool_t _dbus_file_exists(const char *file)
Checks if a file exists.
dbus_bool_t _dbus_delete_file(const DBusString *filename, DBusError *error)
Deletes the given file.
dbus_bool_t _dbus_make_file_world_readable(const DBusString *filename, DBusError *error)
Makes the file readable by every user in the system.
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define _DBUS_UNLOCK(name)
Unlocks a global lock.
#define _DBUS_LOCK(name)
Locks a global lock, initializing it first if necessary.
const char * _dbus_error_from_errno(int error_number)
Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.
const char * _dbus_strerror_from_errno(void)
Get error message from errno.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
#define _DBUS_ZERO(object)
Sets all bits in an object to zero.
void * _dbus_list_pop_first(DBusList **list)
Removes the first value in the list and returns it.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
DBUS_PRIVATE_EXPORT void _dbus_verbose_bytes_of_string(const DBusString *str, int start, int len)
Dump the given part of the string to verbose log.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
void * dbus_realloc(void *memory, size_t bytes)
Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
#define dbus_new(type, count)
Safe macro for using dbus_malloc().
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
void * dbus_malloc(size_t bytes)
Allocates the given number of bytes, as with standard malloc().
#define DBUS_ERROR_TIMEOUT
Certain timeout errors, possibly ETIMEDOUT on a socket.
#define DBUS_ERROR_NOT_SUPPORTED
Requested operation isn't supported (like ENOSYS on UNIX).
#define DBUS_ERROR_BAD_ADDRESS
A D-Bus bus address was malformed.
#define DBUS_ERROR_IO_ERROR
Something went wrong reading or writing to a socket, for example.
#define DBUS_ERROR_SPAWN_CHILD_EXITED
While starting a new process, the child exited with a status code.
#define DBUS_ERROR_ACCESS_DENIED
Security restrictions don't allow doing what you're trying to do.
#define DBUS_ERROR_FILE_EXISTS
Existing file and the operation you're using does not silently overwrite.
#define DBUS_ERROR_LIMITS_EXCEEDED
Some limited resource is exhausted.
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define DBUS_ERROR_INVALID_ARGS
Invalid arguments passed to a method call.
#define DBUS_ERROR_FILE_NOT_FOUND
Missing file.
dbus_bool_t _dbus_sha_compute(const DBusString *data, DBusString *ascii_output)
Computes the ASCII hex-encoded shasum of the given data and appends it to the output string.
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
dbus_bool_t _dbus_string_copy(const DBusString *source, int start, DBusString *dest, int insert_at)
Like _dbus_string_move(), but does not delete the section of the source string that's copied to the d...
char * _dbus_string_get_data_len(DBusString *str, int start, int len)
Gets a sub-portion of the raw character buffer from the string.
dbus_bool_t _dbus_string_validate_utf8(const DBusString *str, int start, int len)
Checks that the given range of the string is valid UTF-8.
void _dbus_string_init_const_len(DBusString *str, const char *value, int len)
Initializes a constant string with a length.
void _dbus_string_tolower_ascii(const DBusString *str, int start, int len)
Converts the given range of the string to lower case.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as _DBUS_STRING_IN...
void _dbus_string_shorten(DBusString *str, int length_to_remove)
Makes a string shorter by the given number of bytes.
dbus_bool_t _dbus_string_append_printf_valist(DBusString *str, const char *format, va_list args)
Appends a printf-style formatted string to the DBusString.
dbus_bool_t _dbus_string_lengthen(DBusString *str, int additional_length)
Makes a string longer by the given number of bytes.
dbus_bool_t _dbus_string_append_byte(DBusString *str, unsigned char byte)
Appends a single byte to the string, returning FALSE if not enough memory.
dbus_bool_t _dbus_string_append_printf(DBusString *str, const char *format,...)
Appends a printf-style formatted string to the DBusString.
void _dbus_logv(DBusSystemLogSeverity severity, const char *msg, va_list args)
Log a message to the system log file (e.g.
dbus_bool_t _dbus_read_local_machine_uuid(DBusGUID *machine_id, dbus_bool_t create_if_not_found, DBusError *error)
Reads the uuid of the machine we're running on from the dbus configuration.
#define _DBUS_POLLOUT
Writing now will not block.
unsigned long dbus_uid_t
A user ID.
dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock(int e)
See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently for Winsock so is abstracted)
unsigned long _dbus_pid_for_log(void)
The only reason this is separate from _dbus_getpid() is to allow it on Windows for logging but not fo...
unsigned long dbus_pid_t
A process ID.
int _dbus_read_socket(DBusSocket fd, DBusString *buffer, int count)
Socket interface.
void _dbus_exit(int code)
Exit the process, returning the given value.
#define _DBUS_POLLERR
Error condition.
int _dbus_write_socket(DBusSocket fd, const DBusString *buffer, int start, int len)
Thin wrapper around the write() system call that writes a part of a DBusString and handles EINTR for ...
void _dbus_atomic_set_nonzero(DBusAtomic *atomic)
Atomically set the value of an integer to something nonzero.
dbus_bool_t _dbus_socketpair(DBusSocket *fd1, DBusSocket *fd2, dbus_bool_t blocking, DBusError *error)
Creates pair of connect sockets (as in socketpair()).
dbus_bool_t _dbus_append_keyring_directory_for_credentials(DBusString *directory, DBusCredentials *credentials)
Appends the directory in which a keyring for the given credentials should be stored.
#define DBUS_UID_UNSET
an invalid UID used to represent an uninitialized dbus_uid_t field
dbus_int32_t _dbus_atomic_dec(DBusAtomic *atomic)
Atomically decrement an integer.
dbus_bool_t _dbus_read_credentials_socket(DBusSocket handle, DBusCredentials *credentials, DBusError *error)
Reads a single byte which must be nul (an error occurs otherwise), and reads unix credentials if avai...
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
DBusSocket _dbus_listen_unix_socket(const char *path, dbus_bool_t abstract, DBusError *error)
Creates a socket and binds it to the given path, then listens on the socket.
dbus_pid_t _dbus_getpid(void)
Gets our process ID.
dbus_int32_t _dbus_atomic_get(DBusAtomic *atomic)
Atomically get the value of an integer.
dbus_bool_t _dbus_set_socket_nonblocking(DBusSocket handle, DBusError *error)
Sets a file descriptor to be nonblocking.
dbus_bool_t _dbus_lookup_session_address(dbus_bool_t *supported, DBusString *address, DBusError *error)
Determines the address of the session bus by querying a platform-specific method.
dbus_bool_t _dbus_credentials_add_from_user(DBusCredentials *credentials, const DBusString *username, DBusCredentialsAddFlags flags, DBusError *error)
Adds the credentials corresponding to the given username.
DBusSocket _dbus_connect_tcp_socket(const char *host, const char *port, const char *family, DBusError *error)
Creates a socket and connects to a socket at the given host and port.
void _dbus_disable_sigpipe(void)
signal (SIGPIPE, SIG_IGN);
dbus_bool_t _dbus_check_setuid(void)
NOTE: If you modify this function, please also consider making the corresponding change in GLib.
void _dbus_sleep_milliseconds(int milliseconds)
Sleeps the given number of milliseconds.
dbus_bool_t _dbus_check_dir_is_private_to_user(DBusString *dir, DBusError *error)
Checks to make sure the given directory is private to the user.
dbus_bool_t _dbus_daemon_unpublish_session_bus_address(void)
Clear the platform-specific centralized location where the session bus address is published.
#define _DBUS_POLLIN
There is data to read.
int _dbus_listen_tcp_socket(const char *host, const char *port, const char *family, DBusString *retport, const char **retfamily, DBusSocket **fds_p, DBusError *error)
Creates a socket and binds it to the given path, then listens on the socket.
dbus_bool_t _dbus_send_credentials_socket(DBusSocket handle, DBusError *error)
Sends a single nul byte with our UNIX credentials as ancillary data.
dbus_uid_t _dbus_getuid(void)
Gets our Unix UID.
dbus_bool_t _dbus_credentials_add_from_current_process(DBusCredentials *credentials)
Adds the credentials of the current process to the passed-in credentials object.
dbus_bool_t _dbus_close_socket(DBusSocket *fd, DBusError *error)
Closes a socket and invalidates it.
DBusSocket _dbus_connect_unix_socket(const char *path, dbus_bool_t abstract, DBusError *error)
Creates a socket and connects it to the UNIX domain socket at the given path.
void _dbus_atomic_set_zero(DBusAtomic *atomic)
Atomically set the value of an integer to 0.
dbus_int32_t _dbus_atomic_inc(DBusAtomic *atomic)
Atomically increments an integer.
dbus_bool_t _dbus_generate_random_bytes(DBusString *str, int n_bytes, DBusError *error)
Generates the given number of random bytes, using the best mechanism we can come up with.
int _dbus_printf_string_upper_bound(const char *format, va_list args)
Measure the message length without terminating nul.
void _dbus_get_monotonic_time(long *tv_sec, long *tv_usec)
Get current time, as in gettimeofday().
dbus_bool_t _dbus_delete_directory(const DBusString *filename, DBusError *error)
Removes a directory; Directory must be empty.
void _dbus_get_real_time(long *tv_sec, long *tv_usec)
Get current time, as in gettimeofday().
void _dbus_abort(void)
Aborts the program with SIGABRT (dumping core).
int _dbus_poll(DBusPollFD *fds, int n_fds, int timeout_milliseconds)
Wrapper for poll().
dbus_bool_t _dbus_get_autolaunch_address(const char *scope, DBusString *address, DBusError *error)
Returns the address of a new session bus.
int _dbus_write_socket_two(DBusSocket fd, const DBusString *buffer1, int start1, int len1, const DBusString *buffer2, int start2, int len2)
Like _dbus_write() but will use writev() if possible to write both buffers in sequence.
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
void _dbus_print_backtrace(void)
On GNU libc systems, print a crude backtrace to stderr.
void _dbus_init_system_log(const char *tag, DBusLogFlags flags)
Initialize the system log.
DBusSocket _dbus_accept(DBusSocket listen_fd)
Accepts a connection on a listening socket.
#define _DBUS_MAX_SUN_PATH_LENGTH
Maximum length of the path to a UNIX domain socket, sockaddr_un::sun_path member.
dbus_bool_t _dbus_append_user_from_current_process(DBusString *str)
Append to the string the identity we would like to have when we authenticate, on UNIX this is the cur...
void _dbus_flush_caches(void)
Called when the bus daemon is signaled to reload its configuration; any caches should be nuked.
const char * _dbus_get_tmpdir(void)
Gets the temporary files directory, using GetTempPath()
dbus_bool_t _dbus_ensure_directory(const DBusString *filename, DBusError *error)
Creates a directory; succeeds if the directory is created or already existed.
dbus_bool_t _dbus_path_is_absolute(const DBusString *filename)
Checks whether the filename is an absolute path.
dbus_bool_t _dbus_create_directory(const DBusString *filename, DBusError *error)
Creates a directory.
_DBUS_GNUC_EXTENSION typedef unsigned long dbus_uint64_t
A 64-bit unsigned integer.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
#define DBUS_INT64_CONSTANT(val)
Declare a 64-bit signed integer constant.
int dbus_int32_t
A 32-bit signed integer on all platforms.
unsigned int dbus_uint32_t
A 32-bit unsigned integer on all platforms.
An atomic integer safe to increment or decrement from multiple threads.
volatile dbus_int32_t value
Value of the atomic integer.
Object representing an exception.
const char * message
public error message field
short events
Events to poll for.
short revents
Events that occurred.
DBusPollable fd
File descriptor.
A globally unique ID ; we have one for each DBusServer, and also one for each machine with libdbus in...
dbus_uint32_t as_uint32s[DBUS_UUID_LENGTH_WORDS]
guid as four uint32 values