*
*/
+#include <config.h>
+
#define STRSAFE_NO_DEPRECATE
#include "dbus-sysdeps.h"
* @param error return location for errors
* @returns #FALSE on failure
*/
-dbus_bool_t
+static dbus_bool_t
_dbus_write_pid_file (const DBusString *filename,
unsigned long pid,
DBusError *error)
return TRUE;
}
-/**
- * Changes the user and group the bus is running as.
- *
- * @param uid the new user ID
- * @param gid the new group ID
- * @param error return location for errors
- * @returns #FALSE on failure
- */
-dbus_bool_t
-_dbus_change_identity (dbus_uid_t uid,
- dbus_gid_t gid,
- DBusError *error)
-{
- return TRUE;
-}
-
-/** Checks if user is at the console
-*
-* @param username user to check
-* @param error return location for errors
-* @returns #TRUE is the user is at the consolei and there are no errors
-*/
-dbus_bool_t
-_dbus_user_at_console(const char *username,
- DBusError *error)
-{
-#ifdef DBUS_WINCE
- return TRUE;
-#else
- dbus_bool_t retval = FALSE;
- wchar_t *wusername;
- DWORD sid_length;
- PSID user_sid, console_user_sid;
- HWINSTA winsta;
-
- wusername = _dbus_win_utf8_to_utf16 (username, error);
- if (!wusername)
- return FALSE;
-
- // TODO remove
- if (!_dbus_win_account_to_sid (wusername, &user_sid, error))
- goto out0;
-
- /* Now we have the SID for username. Get the SID of the
- * user at the "console" (window station WinSta0)
- */
- if (!(winsta = OpenWindowStation ("WinSta0", FALSE, READ_CONTROL)))
- {
- _dbus_win_set_error_from_win_error (error, GetLastError ());
- goto out2;
- }
-
- sid_length = 0;
- GetUserObjectInformation (winsta, UOI_USER_SID,
- NULL, 0, &sid_length);
- if (sid_length == 0)
- {
- /* Nobody is logged on */
- goto out2;
- }
-
- if (sid_length < 0 || sid_length > 1000)
- {
- dbus_set_error_const (error, DBUS_ERROR_FAILED, "Invalid SID length");
- goto out3;
- }
-
- console_user_sid = dbus_malloc (sid_length);
- if (!console_user_sid)
- {
- _DBUS_SET_OOM (error);
- goto out3;
- }
-
- if (!GetUserObjectInformation (winsta, UOI_USER_SID,
- console_user_sid, sid_length, &sid_length))
- {
- _dbus_win_set_error_from_win_error (error, GetLastError ());
- goto out4;
- }
-
- if (!IsValidSid (console_user_sid))
- {
- dbus_set_error_const (error, DBUS_ERROR_FAILED, "Invalid SID");
- goto out4;
- }
-
- retval = EqualSid (user_sid, console_user_sid);
-
-out4:
- dbus_free (console_user_sid);
-out3:
- CloseWindowStation (winsta);
-out2:
- dbus_free (user_sid);
-out0:
- dbus_free (wusername);
-
- return retval;
-#endif //DBUS_WINCE
-}
-
-/**
- * Removes a directory; Directory must be empty
- *
- * @param filename directory filename
- * @param error initialized error object
- * @returns #TRUE on success
- */
-dbus_bool_t
-_dbus_delete_directory (const DBusString *filename,
- DBusError *error)
-{
- const char *filename_c;
-
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- filename_c = _dbus_string_get_const_data (filename);
-
- if (_rmdir (filename_c) != 0)
- {
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Failed to remove directory %s: %s\n",
- filename_c, strerror (errno));
- return FALSE;
- }
-
- return TRUE;
-}
-
void
_dbus_init_system_log (void)
{
}
/**
- * Log an informative message. Intended for use primarily by
- * the system bus.
+ * Log a message to the system log file (e.g. syslog on Unix).
*
+ * @param severity a severity value
* @param msg a printf-style format string
* @param args arguments for the format string
+ *
*/
void
-_dbus_log_info (const char *msg, va_list args)
+_dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...)
{
- // FIXME!
+ va_list args;
+
+ va_start (args, msg);
+
+ _dbus_system_logv (severity, msg, args);
+
+ va_end (args);
}
/**
- * Log a security-related message. Intended for use primarily by
- * the system bus.
+ * Log a message to the system log file (e.g. syslog on Unix).
*
+ * @param severity a severity value
* @param msg a printf-style format string
* @param args arguments for the format string
+ *
+ * If the FATAL severity is given, this function will terminate the program
+ * with an error code.
*/
void
-_dbus_log_security (const char *msg, va_list args)
+_dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
{
// FIXME!
}
_dbus_verbose ("_dbus_set_signal_handler() has to be implemented\n");
}
-/** Checks if a file exists
-*
-* @param file full path to the file
-* @returns #TRUE if file exists
-*/
-dbus_bool_t
-_dbus_file_exists (const char *file)
-{
- DWORD attributes = GetFileAttributes (file);
-
- if (attributes != INVALID_FILE_ATTRIBUTES && GetLastError() != ERROR_PATH_NOT_FOUND)
- return TRUE;
- else
- return FALSE;
-}
-
/**
* stat() wrapper.
*
* The DIR typedef is not compatible with Unix.
**********************************************************************/
-DIR * _dbus_opendir(const char *dir)
+static DIR * _dbus_opendir(const char *dir)
{
DIR *dp;
char *filespec;
return dp;
}
-struct dirent * _dbus_readdir(DIR *dp)
+static struct dirent * _dbus_readdir(DIR *dp)
{
if (!dp || dp->finished)
return NULL;
}
-int _dbus_closedir(DIR *dp)
+static int _dbus_closedir(DIR *dp)
{
if (!dp)
return 0;
return FALSE;
}
+dbus_bool_t _dbus_windows_user_is_process_owner (const char *windows_sid)
+{
+ return TRUE;
+}
+
/*=====================================================================
unix emulation functions - should be removed sometime in the future
=====================================================================*/
_dbus_unix_user_is_at_console (dbus_uid_t uid,
DBusError *error)
{
+ dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
+ "UNIX user IDs not supported on Windows\n");
return FALSE;
}
************************************************************************/
-/**
- * Assigns an error name and message corresponding to a Win32 error
- * code to a DBusError. Does nothing if error is #NULL.
- *
- * @param error the error.
- * @param code the Win32 error code
- */
-void
-_dbus_win_set_error_from_win_error (DBusError *error,
- int code)
-{
- char *msg;
-
- /* As we want the English message, use the A API */
- FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_IGNORE_INSERTS |
- FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, code, MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US),
- (LPTSTR) &msg, 0, NULL);
- if (msg)
- {
- char *msg_copy;
-
- msg_copy = dbus_malloc (strlen (msg));
- strcpy (msg_copy, msg);
- LocalFree (msg);
-
- dbus_set_error (error, "win32.error", "%s", msg_copy);
- }
- else
- dbus_set_error (error, "win32.error", "Unknown error code %d or FormatMessage failed", code);
-}
-
-void
-_dbus_win_warn_win_error (const char *message,
- int code)
-{
- DBusError error;
-
- dbus_error_init (&error);
- _dbus_win_set_error_from_win_error (&error, code);
- _dbus_warn ("%s: %s\n", message, error.message);
- dbus_error_free (&error);
-}
-
-/**
- * A wrapper around strerror() because some platforms
- * may be lame and not have strerror().
- *
- * @param error_number errno.
- * @returns error description.
- */
-const char*
-_dbus_strerror (int error_number)
-{
-#ifdef DBUS_WINCE
- // TODO
- return "unknown";
-#else
- const char *msg;
-
- switch (error_number)
- {
- case WSAEINTR:
- return "Interrupted function call";
- case WSAEACCES:
- return "Permission denied";
- case WSAEFAULT:
- return "Bad address";
- case WSAEINVAL:
- return "Invalid argument";
- case WSAEMFILE:
- return "Too many open files";
- case WSAEWOULDBLOCK:
- return "Resource temporarily unavailable";
- case WSAEINPROGRESS:
- return "Operation now in progress";
- case WSAEALREADY:
- return "Operation already in progress";
- case WSAENOTSOCK:
- return "Socket operation on nonsocket";
- case WSAEDESTADDRREQ:
- return "Destination address required";
- case WSAEMSGSIZE:
- return "Message too long";
- case WSAEPROTOTYPE:
- return "Protocol wrong type for socket";
- case WSAENOPROTOOPT:
- return "Bad protocol option";
- case WSAEPROTONOSUPPORT:
- return "Protocol not supported";
- case WSAESOCKTNOSUPPORT:
- return "Socket type not supported";
- case WSAEOPNOTSUPP:
- return "Operation not supported";
- case WSAEPFNOSUPPORT:
- return "Protocol family not supported";
- case WSAEAFNOSUPPORT:
- return "Address family not supported by protocol family";
- case WSAEADDRINUSE:
- return "Address already in use";
- case WSAEADDRNOTAVAIL:
- return "Cannot assign requested address";
- case WSAENETDOWN:
- return "Network is down";
- case WSAENETUNREACH:
- return "Network is unreachable";
- case WSAENETRESET:
- return "Network dropped connection on reset";
- case WSAECONNABORTED:
- return "Software caused connection abort";
- case WSAECONNRESET:
- return "Connection reset by peer";
- case WSAENOBUFS:
- return "No buffer space available";
- case WSAEISCONN:
- return "Socket is already connected";
- case WSAENOTCONN:
- return "Socket is not connected";
- case WSAESHUTDOWN:
- return "Cannot send after socket shutdown";
- case WSAETIMEDOUT:
- return "Connection timed out";
- case WSAECONNREFUSED:
- return "Connection refused";
- case WSAEHOSTDOWN:
- return "Host is down";
- case WSAEHOSTUNREACH:
- return "No route to host";
- case WSAEPROCLIM:
- return "Too many processes";
- case WSAEDISCON:
- return "Graceful shutdown in progress";
- case WSATYPE_NOT_FOUND:
- return "Class type not found";
- case WSAHOST_NOT_FOUND:
- return "Host not found";
- case WSATRY_AGAIN:
- return "Nonauthoritative host not found";
- case WSANO_RECOVERY:
- return "This is a nonrecoverable error";
- case WSANO_DATA:
- return "Valid name, no data record of requested type";
- case WSA_INVALID_HANDLE:
- return "Specified event object handle is invalid";
- case WSA_INVALID_PARAMETER:
- return "One or more parameters are invalid";
- case WSA_IO_INCOMPLETE:
- return "Overlapped I/O event object not in signaled state";
- case WSA_IO_PENDING:
- return "Overlapped operations will complete later";
- case WSA_NOT_ENOUGH_MEMORY:
- return "Insufficient memory available";
- case WSA_OPERATION_ABORTED:
- return "Overlapped operation aborted";
-#ifdef WSAINVALIDPROCTABLE
-
- case WSAINVALIDPROCTABLE:
- return "Invalid procedure table from service provider";
-#endif
-#ifdef WSAINVALIDPROVIDER
-
- case WSAINVALIDPROVIDER:
- return "Invalid service provider version number";
-#endif
-#ifdef WSAPROVIDERFAILEDINIT
-
- case WSAPROVIDERFAILEDINIT:
- return "Unable to initialize a service provider";
-#endif
-
- case WSASYSCALLFAILURE:
- return "System call failure";
- }
- msg = strerror (error_number);
- if (msg == NULL)
- msg = "unknown";
-
- return msg;
-#endif //DBUS_WINCE
-}