D-Bus  1.13.7
dbus-sysdeps-util-win.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-sysdeps-util.c Would be in dbus-sysdeps.c, but not used in libdbus
3  *
4  * Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
5  * Copyright (C) 2003 CodeFactory AB
6  *
7  * Licensed under the Academic Free License version 2.1
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #include <config.h>
26 
27 #define STRSAFE_NO_DEPRECATE
28 
29 #include "dbus-sysdeps.h"
30 #include "dbus-internals.h"
31 #include "dbus-protocol.h"
32 #include "dbus-string.h"
33 #include "dbus-sysdeps.h"
34 #include "dbus-sysdeps-win.h"
35 #include "dbus-sockets-win.h"
36 #include "dbus-memory.h"
37 #include "dbus-pipe.h"
38 
39 #include <stdio.h>
40 #include <stdlib.h>
41 #if HAVE_ERRNO_H
42 #include <errno.h>
43 #endif
44 #include <winsock2.h> // WSA error codes
45 
46 #ifndef DBUS_WINCE
47 #include <io.h>
48 #include <lm.h>
49 #include <sys/stat.h>
50 #endif
51 
52 
64  DBusPipe *print_pid_pipe,
65  DBusError *error,
66  dbus_bool_t keep_umask)
67 {
69  "Cannot daemonize on Windows");
70  return FALSE;
71 }
72 
81 static dbus_bool_t
82 _dbus_write_pid_file (const DBusString *filename,
83  unsigned long pid,
84  DBusError *error)
85 {
86  const char *cfilename;
87  HANDLE hnd;
88  char pidstr[20];
89  int total;
90  int bytes_to_write;
91 
92  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
93 
94  cfilename = _dbus_string_get_const_data (filename);
95 
96  hnd = CreateFileA (cfilename, GENERIC_WRITE,
97  FILE_SHARE_READ | FILE_SHARE_WRITE,
98  NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,
99  INVALID_HANDLE_VALUE);
100  if (hnd == INVALID_HANDLE_VALUE)
101  {
102  char *emsg = _dbus_win_error_string (GetLastError ());
103  dbus_set_error (error, _dbus_win_error_from_last_error (),
104  "Could not create PID file %s: %s",
105  cfilename, emsg);
106  _dbus_win_free_error_string (emsg);
107  return FALSE;
108  }
109 
110  if (snprintf (pidstr, sizeof (pidstr), "%lu\n", pid) < 0)
111  {
113  "Failed to format PID for \"%s\": %s", cfilename,
115  CloseHandle (hnd);
116  return FALSE;
117  }
118 
119  total = 0;
120  bytes_to_write = strlen (pidstr);;
121 
122  while (total < bytes_to_write)
123  {
124  DWORD bytes_written;
125  BOOL res;
126 
127  res = WriteFile (hnd, pidstr + total, bytes_to_write - total,
128  &bytes_written, NULL);
129 
130  if (res == 0 || bytes_written <= 0)
131  {
132  char *emsg = _dbus_win_error_string (GetLastError ());
133  dbus_set_error (error, _dbus_win_error_from_last_error (),
134  "Could not write to %s: %s", cfilename, emsg);
135  _dbus_win_free_error_string (emsg);
136  CloseHandle (hnd);
137  return FALSE;
138  }
139 
140  total += bytes_written;
141  }
142 
143  if (CloseHandle (hnd) == 0)
144  {
145  char *emsg = _dbus_win_error_string (GetLastError ());
146  dbus_set_error (error, _dbus_win_error_from_last_error (),
147  "Could not close file %s: %s",
148  cfilename, emsg);
149  _dbus_win_free_error_string (emsg);
150 
151  return FALSE;
152  }
153 
154  return TRUE;
155 }
156 
170  DBusPipe *print_pid_pipe,
171  dbus_pid_t pid_to_write,
172  DBusError *error)
173 {
174  if (pidfile)
175  {
176  _dbus_verbose ("writing pid file %s\n", _dbus_string_get_const_data (pidfile));
177  if (!_dbus_write_pid_file (pidfile,
178  pid_to_write,
179  error))
180  {
181  _dbus_verbose ("pid file write failed\n");
182  _DBUS_ASSERT_ERROR_IS_SET(error);
183  return FALSE;
184  }
185  }
186  else
187  {
188  _dbus_verbose ("No pid file requested\n");
189  }
190 
191  if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
192  {
193  DBusString pid;
194  int bytes;
195 
196  _dbus_verbose ("writing our pid to pipe %d\n", print_pid_pipe->fd);
197 
198  if (!_dbus_string_init (&pid))
199  {
200  _DBUS_SET_OOM (error);
201  return FALSE;
202  }
203 
204  if (!_dbus_string_append_int (&pid, pid_to_write) ||
205  !_dbus_string_append (&pid, "\n"))
206  {
207  _dbus_string_free (&pid);
208  _DBUS_SET_OOM (error);
209  return FALSE;
210  }
211 
212  bytes = _dbus_string_get_length (&pid);
213  if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
214  {
215  /* _dbus_pipe_write sets error only on failure, not short write */
216  if (error != NULL && !dbus_error_is_set(error))
217  {
219  "Printing message bus PID: did not write enough bytes\n");
220  }
221  _dbus_string_free (&pid);
222  return FALSE;
223  }
224 
225  _dbus_string_free (&pid);
226  }
227  else
228  {
229  _dbus_verbose ("No pid pipe to write to\n");
230  }
231 
232  return TRUE;
233 }
234 
242 _dbus_verify_daemon_user (const char *user)
243 {
244  return TRUE;
245 }
246 
255 _dbus_change_to_daemon_user (const char *user,
256  DBusError *error)
257 {
258  return TRUE;
259 }
260 
261 static void
262 fd_limit_not_supported (DBusError *error)
263 {
265  "cannot change fd limit on this platform");
266 }
267 
268 DBusRLimit *
269 _dbus_rlimit_save_fd_limit (DBusError *error)
270 {
271  fd_limit_not_supported (error);
272  return NULL;
273 }
274 
276 _dbus_rlimit_raise_fd_limit_if_privileged (unsigned int desired,
277  DBusError *error)
278 {
279  fd_limit_not_supported (error);
280  return FALSE;
281 }
282 
284 _dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
285  DBusError *error)
286 {
287  fd_limit_not_supported (error);
288  return FALSE;
289 }
290 
291 void
292 _dbus_rlimit_free (DBusRLimit *lim)
293 {
294  /* _dbus_rlimit_save_fd_limit() cannot return non-NULL on Windows
295  * so there cannot be anything to free */
296  _dbus_assert (lim == NULL);
297 }
298 
308 _dbus_stat(const DBusString *filename,
309  DBusStat *statbuf,
310  DBusError *error)
311 {
312  const char *filename_c;
313  WIN32_FILE_ATTRIBUTE_DATA wfad;
314  char *lastdot;
315 
316  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
317 
318  filename_c = _dbus_string_get_const_data (filename);
319 
320  if (!GetFileAttributesExA (filename_c, GetFileExInfoStandard, &wfad))
321  {
322  _dbus_win_set_error_from_win_error (error, GetLastError ());
323  return FALSE;
324  }
325 
326  if (wfad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
327  statbuf->mode = _S_IFDIR;
328  else
329  statbuf->mode = _S_IFREG;
330 
331  statbuf->mode |= _S_IREAD;
332  if (wfad.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
333  statbuf->mode |= _S_IWRITE;
334 
335  lastdot = strrchr (filename_c, '.');
336  if (lastdot && stricmp (lastdot, ".exe") == 0)
337  statbuf->mode |= _S_IEXEC;
338 
339  statbuf->mode |= (statbuf->mode & 0700) >> 3;
340  statbuf->mode |= (statbuf->mode & 0700) >> 6;
341 
342  statbuf->nlink = 1;
343 
344 #ifdef ENABLE_UID_TO_SID
345  {
346  PSID owner_sid, group_sid;
347  PSECURITY_DESCRIPTOR sd;
348 
349  sd = NULL;
350  rc = GetNamedSecurityInfo ((char *) filename_c, SE_FILE_OBJECT,
351  OWNER_SECURITY_INFORMATION |
352  GROUP_SECURITY_INFORMATION,
353  &owner_sid, &group_sid,
354  NULL, NULL,
355  &sd);
356  if (rc != ERROR_SUCCESS)
357  {
358  _dbus_win_set_error_from_win_error (error, rc);
359  if (sd != NULL)
360  LocalFree (sd);
361  return FALSE;
362  }
363 
364  /* FIXME */
365  statbuf->uid = _dbus_win_sid_to_uid_t (owner_sid);
366  statbuf->gid = _dbus_win_sid_to_uid_t (group_sid);
367 
368  LocalFree (sd);
369  }
370 #else
371  statbuf->uid = DBUS_UID_UNSET;
372  statbuf->gid = DBUS_GID_UNSET;
373 #endif
374 
375  statbuf->size = ((dbus_int64_t) wfad.nFileSizeHigh << 32) + wfad.nFileSizeLow;
376 
377  statbuf->atime =
378  (((dbus_int64_t) wfad.ftLastAccessTime.dwHighDateTime << 32) +
379  wfad.ftLastAccessTime.dwLowDateTime) / 10000000 - DBUS_INT64_CONSTANT (116444736000000000);
380 
381  statbuf->mtime =
382  (((dbus_int64_t) wfad.ftLastWriteTime.dwHighDateTime << 32) +
383  wfad.ftLastWriteTime.dwLowDateTime) / 10000000 - DBUS_INT64_CONSTANT (116444736000000000);
384 
385  statbuf->ctime =
386  (((dbus_int64_t) wfad.ftCreationTime.dwHighDateTime << 32) +
387  wfad.ftCreationTime.dwLowDateTime) / 10000000 - DBUS_INT64_CONSTANT (116444736000000000);
388 
389  return TRUE;
390 }
391 
395 struct DBusDirIter
396  {
397  HANDLE handle;
398  WIN32_FIND_DATAA fileinfo; /* from FindFirst/FindNext */
399  dbus_bool_t finished; /* true if there are no more entries */
400  int offset;
401  };
402 
412  DBusError *error)
413 {
414  DBusDirIter *iter;
415  DBusString filespec;
416 
417  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
418 
419  if (!_dbus_string_init_from_string (&filespec, filename))
420  {
422  "Could not allocate memory for directory filename copy");
423  return NULL;
424  }
425 
426  if (_dbus_string_ends_with_c_str (&filespec, "/") || _dbus_string_ends_with_c_str (&filespec, "\\") )
427  {
428  if (!_dbus_string_append (&filespec, "*"))
429  {
431  "Could not append filename wildcard");
432  return NULL;
433  }
434  }
435  else if (!_dbus_string_ends_with_c_str (&filespec, "*"))
436  {
437  if (!_dbus_string_append (&filespec, "\\*"))
438  {
440  "Could not append filename wildcard 2");
441  return NULL;
442  }
443  }
444 
445  iter = dbus_new0 (DBusDirIter, 1);
446  if (iter == NULL)
447  {
448  _dbus_string_free (&filespec);
450  "Could not allocate memory for directory iterator");
451  return NULL;
452  }
453 
454  iter->finished = FALSE;
455  iter->offset = 0;
456  iter->handle = FindFirstFileA (_dbus_string_get_const_data (&filespec), &(iter->fileinfo));
457  if (iter->handle == INVALID_HANDLE_VALUE)
458  {
459  if (GetLastError () == ERROR_NO_MORE_FILES)
460  iter->finished = TRUE;
461  else
462  {
463  char *emsg = _dbus_win_error_string (GetLastError ());
464  dbus_set_error (error, _dbus_win_error_from_last_error (),
465  "Failed to read directory \"%s\": %s",
466  _dbus_string_get_const_data (filename), emsg);
467  _dbus_win_free_error_string (emsg);
468  dbus_free ( iter );
469  _dbus_string_free (&filespec);
470  return NULL;
471  }
472  }
473  _dbus_string_free (&filespec);
474  return iter;
475 }
476 
489  DBusString *filename,
490  DBusError *error)
491 {
492  int saved_err = GetLastError();
493 
494  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
495 
496 again:
497  SetLastError (0);
498 
499  if (!iter || iter->finished)
500  return FALSE;
501 
502  if (iter->offset > 0)
503  {
504  if (FindNextFileA (iter->handle, &(iter->fileinfo)) == 0)
505  {
506  if (GetLastError() == ERROR_NO_MORE_FILES)
507  {
508  SetLastError(saved_err);
509  iter->finished = 1;
510  }
511  else
512  {
513  char *emsg = _dbus_win_error_string (GetLastError ());
514  dbus_set_error (error, _dbus_win_error_from_last_error (),
515  "Failed to get next in directory: %s", emsg);
516  _dbus_win_free_error_string (emsg);
517  return FALSE;
518  }
519  }
520  }
521 
522  iter->offset++;
523 
524  if (iter->finished)
525  return FALSE;
526 
527  if (iter->fileinfo.cFileName[0] == '.' &&
528  (iter->fileinfo.cFileName[1] == '\0' ||
529  (iter->fileinfo.cFileName[1] == '.' && iter->fileinfo.cFileName[2] == '\0')))
530  goto again;
531 
532  _dbus_string_set_length (filename, 0);
533  if (!_dbus_string_append (filename, iter->fileinfo.cFileName))
534  {
536  "No memory to read directory entry");
537  return FALSE;
538  }
539 
540  return TRUE;
541 }
542 
546 void
548 {
549  if (!iter)
550  return;
551  FindClose(iter->handle);
552  dbus_free (iter);
553 }
554  /* End of DBusInternalsUtils functions */
556 
569 _dbus_string_get_dirname(const DBusString *filename,
570  DBusString *dirname)
571 {
572  int sep;
573 
574  _dbus_assert (filename != dirname);
575  _dbus_assert (filename != NULL);
576  _dbus_assert (dirname != NULL);
577 
578  /* Ignore any separators on the end */
579  sep = _dbus_string_get_length (filename);
580  if (sep == 0)
581  return _dbus_string_append (dirname, "."); /* empty string passed in */
582 
583  while (sep > 0 &&
584  (_dbus_string_get_byte (filename, sep - 1) == '/' ||
585  _dbus_string_get_byte (filename, sep - 1) == '\\'))
586  --sep;
587 
588  _dbus_assert (sep >= 0);
589 
590  if (sep == 0 ||
591  (sep == 2 &&
592  _dbus_string_get_byte (filename, 1) == ':' &&
593  isalpha (_dbus_string_get_byte (filename, 0))))
594  return _dbus_string_copy_len (filename, 0, sep + 1,
595  dirname, _dbus_string_get_length (dirname));
596 
597  {
598  int sep1, sep2;
599  _dbus_string_find_byte_backward (filename, sep, '/', &sep1);
600  _dbus_string_find_byte_backward (filename, sep, '\\', &sep2);
601 
602  sep = MAX (sep1, sep2);
603  }
604  if (sep < 0)
605  return _dbus_string_append (dirname, ".");
606 
607  while (sep > 0 &&
608  (_dbus_string_get_byte (filename, sep - 1) == '/' ||
609  _dbus_string_get_byte (filename, sep - 1) == '\\'))
610  --sep;
611 
612  _dbus_assert (sep >= 0);
613 
614  if ((sep == 0 ||
615  (sep == 2 &&
616  _dbus_string_get_byte (filename, 1) == ':' &&
617  isalpha (_dbus_string_get_byte (filename, 0))))
618  &&
619  (_dbus_string_get_byte (filename, sep) == '/' ||
620  _dbus_string_get_byte (filename, sep) == '\\'))
621  return _dbus_string_copy_len (filename, 0, sep + 1,
622  dirname, _dbus_string_get_length (dirname));
623  else
624  return _dbus_string_copy_len (filename, 0, sep - 0,
625  dirname, _dbus_string_get_length (dirname));
626 }
627 
628 
638 {
639  return FALSE;
640 }
641 
643 {
644  return TRUE;
645 }
646 
647 /*=====================================================================
648  unix emulation functions - should be removed sometime in the future
649  =====================================================================*/
650 
662  DBusError *error)
663 {
665  "UNIX user IDs not supported on Windows\n");
666  return FALSE;
667 }
668 
669 
680  dbus_gid_t *gid_p)
681 {
682  return FALSE;
683 }
684 
695  dbus_uid_t *uid_p)
696 {
697  return FALSE;
698 }
699 
700 
713  dbus_gid_t **group_ids,
714  int *n_group_ids)
715 {
716  return FALSE;
717 }
718 
719 
720  /* DBusString stuff */
722 
723 /************************************************************************
724 
725  error handling
726 
727  ************************************************************************/
728 
729 
730 
731 
732 
733 /* lan manager error codes */
734 const char*
735 _dbus_lm_strerror(int error_number)
736 {
737 #ifdef DBUS_WINCE
738  // TODO
739  return "unknown";
740 #else
741  const char *msg;
742  switch (error_number)
743  {
744  case NERR_NetNotStarted:
745  return "The workstation driver is not installed.";
746  case NERR_UnknownServer:
747  return "The server could not be located.";
748  case NERR_ShareMem:
749  return "An internal error occurred. The network cannot access a shared memory segment.";
750  case NERR_NoNetworkResource:
751  return "A network resource shortage occurred.";
752  case NERR_RemoteOnly:
753  return "This operation is not supported on workstations.";
754  case NERR_DevNotRedirected:
755  return "The device is not connected.";
756  case NERR_ServerNotStarted:
757  return "The Server service is not started.";
758  case NERR_ItemNotFound:
759  return "The queue is empty.";
760  case NERR_UnknownDevDir:
761  return "The device or directory does not exist.";
762  case NERR_RedirectedPath:
763  return "The operation is invalid on a redirected resource.";
764  case NERR_DuplicateShare:
765  return "The name has already been shared.";
766  case NERR_NoRoom:
767  return "The server is currently out of the requested resource.";
768  case NERR_TooManyItems:
769  return "Requested addition of items exceeds the maximum allowed.";
770  case NERR_InvalidMaxUsers:
771  return "The Peer service supports only two simultaneous users.";
772  case NERR_BufTooSmall:
773  return "The API return buffer is too small.";
774  case NERR_RemoteErr:
775  return "A remote API error occurred.";
776  case NERR_LanmanIniError:
777  return "An error occurred when opening or reading the configuration file.";
778  case NERR_NetworkError:
779  return "A general network error occurred.";
780  case NERR_WkstaInconsistentState:
781  return "The Workstation service is in an inconsistent state. Restart the computer before restarting the Workstation service.";
782  case NERR_WkstaNotStarted:
783  return "The Workstation service has not been started.";
784  case NERR_BrowserNotStarted:
785  return "The requested information is not available.";
786  case NERR_InternalError:
787  return "An internal error occurred.";
788  case NERR_BadTransactConfig:
789  return "The server is not configured for transactions.";
790  case NERR_InvalidAPI:
791  return "The requested API is not supported on the remote server.";
792  case NERR_BadEventName:
793  return "The event name is invalid.";
794  case NERR_DupNameReboot:
795  return "The computer name already exists on the network. Change it and restart the computer.";
796  case NERR_CfgCompNotFound:
797  return "The specified component could not be found in the configuration information.";
798  case NERR_CfgParamNotFound:
799  return "The specified parameter could not be found in the configuration information.";
800  case NERR_LineTooLong:
801  return "A line in the configuration file is too long.";
802  case NERR_QNotFound:
803  return "The printer does not exist.";
804  case NERR_JobNotFound:
805  return "The print job does not exist.";
806  case NERR_DestNotFound:
807  return "The printer destination cannot be found.";
808  case NERR_DestExists:
809  return "The printer destination already exists.";
810  case NERR_QExists:
811  return "The printer queue already exists.";
812  case NERR_QNoRoom:
813  return "No more printers can be added.";
814  case NERR_JobNoRoom:
815  return "No more print jobs can be added.";
816  case NERR_DestNoRoom:
817  return "No more printer destinations can be added.";
818  case NERR_DestIdle:
819  return "This printer destination is idle and cannot accept control operations.";
820  case NERR_DestInvalidOp:
821  return "This printer destination request contains an invalid control function.";
822  case NERR_ProcNoRespond:
823  return "The print processor is not responding.";
824  case NERR_SpoolerNotLoaded:
825  return "The spooler is not running.";
826  case NERR_DestInvalidState:
827  return "This operation cannot be performed on the print destination in its current state.";
828  case NERR_QInvalidState:
829  return "This operation cannot be performed on the printer queue in its current state.";
830  case NERR_JobInvalidState:
831  return "This operation cannot be performed on the print job in its current state.";
832  case NERR_SpoolNoMemory:
833  return "A spooler memory allocation failure occurred.";
834  case NERR_DriverNotFound:
835  return "The device driver does not exist.";
836  case NERR_DataTypeInvalid:
837  return "The data type is not supported by the print processor.";
838  case NERR_ProcNotFound:
839  return "The print processor is not installed.";
840  case NERR_ServiceTableLocked:
841  return "The service database is locked.";
842  case NERR_ServiceTableFull:
843  return "The service table is full.";
844  case NERR_ServiceInstalled:
845  return "The requested service has already been started.";
846  case NERR_ServiceEntryLocked:
847  return "The service does not respond to control actions.";
848  case NERR_ServiceNotInstalled:
849  return "The service has not been started.";
850  case NERR_BadServiceName:
851  return "The service name is invalid.";
852  case NERR_ServiceCtlTimeout:
853  return "The service is not responding to the control function.";
854  case NERR_ServiceCtlBusy:
855  return "The service control is busy.";
856  case NERR_BadServiceProgName:
857  return "The configuration file contains an invalid service program name.";
858  case NERR_ServiceNotCtrl:
859  return "The service could not be controlled in its present state.";
860  case NERR_ServiceKillProc:
861  return "The service ended abnormally.";
862  case NERR_ServiceCtlNotValid:
863  return "The requested pause or stop is not valid for this service.";
864  case NERR_NotInDispatchTbl:
865  return "The service control dispatcher could not find the service name in the dispatch table.";
866  case NERR_BadControlRecv:
867  return "The service control dispatcher pipe read failed.";
868  case NERR_ServiceNotStarting:
869  return "A thread for the new service could not be created.";
870  case NERR_AlreadyLoggedOn:
871  return "This workstation is already logged on to the local-area network.";
872  case NERR_NotLoggedOn:
873  return "The workstation is not logged on to the local-area network.";
874  case NERR_BadUsername:
875  return "The user name or group name parameter is invalid.";
876  case NERR_BadPassword:
877  return "The password parameter is invalid.";
878  case NERR_UnableToAddName_W:
879  return "@W The logon processor did not add the message alias.";
880  case NERR_UnableToAddName_F:
881  return "The logon processor did not add the message alias.";
882  case NERR_UnableToDelName_W:
883  return "@W The logoff processor did not delete the message alias.";
884  case NERR_UnableToDelName_F:
885  return "The logoff processor did not delete the message alias.";
886  case NERR_LogonsPaused:
887  return "Network logons are paused.";
888  case NERR_LogonServerConflict:
889  return "A centralized logon-server conflict occurred.";
890  case NERR_LogonNoUserPath:
891  return "The server is configured without a valid user path.";
892  case NERR_LogonScriptError:
893  return "An error occurred while loading or running the logon script.";
894  case NERR_StandaloneLogon:
895  return "The logon server was not specified. Your computer will be logged on as STANDALONE.";
896  case NERR_LogonServerNotFound:
897  return "The logon server could not be found.";
898  case NERR_LogonDomainExists:
899  return "There is already a logon domain for this computer.";
900  case NERR_NonValidatedLogon:
901  return "The logon server could not validate the logon.";
902  case NERR_ACFNotFound:
903  return "The security database could not be found.";
904  case NERR_GroupNotFound:
905  return "The group name could not be found.";
906  case NERR_UserNotFound:
907  return "The user name could not be found.";
908  case NERR_ResourceNotFound:
909  return "The resource name could not be found.";
910  case NERR_GroupExists:
911  return "The group already exists.";
912  case NERR_UserExists:
913  return "The user account already exists.";
914  case NERR_ResourceExists:
915  return "The resource permission list already exists.";
916  case NERR_NotPrimary:
917  return "This operation is only allowed on the primary domain controller of the domain.";
918  case NERR_ACFNotLoaded:
919  return "The security database has not been started.";
920  case NERR_ACFNoRoom:
921  return "There are too many names in the user accounts database.";
922  case NERR_ACFFileIOFail:
923  return "A disk I/O failure occurred.";
924  case NERR_ACFTooManyLists:
925  return "The limit of 64 entries per resource was exceeded.";
926  case NERR_UserLogon:
927  return "Deleting a user with a session is not allowed.";
928  case NERR_ACFNoParent:
929  return "The parent directory could not be located.";
930  case NERR_CanNotGrowSegment:
931  return "Unable to add to the security database session cache segment.";
932  case NERR_SpeGroupOp:
933  return "This operation is not allowed on this special group.";
934  case NERR_NotInCache:
935  return "This user is not cached in user accounts database session cache.";
936  case NERR_UserInGroup:
937  return "The user already belongs to this group.";
938  case NERR_UserNotInGroup:
939  return "The user does not belong to this group.";
940  case NERR_AccountUndefined:
941  return "This user account is undefined.";
942  case NERR_AccountExpired:
943  return "This user account has expired.";
944  case NERR_InvalidWorkstation:
945  return "The user is not allowed to log on from this workstation.";
946  case NERR_InvalidLogonHours:
947  return "The user is not allowed to log on at this time.";
948  case NERR_PasswordExpired:
949  return "The password of this user has expired.";
950  case NERR_PasswordCantChange:
951  return "The password of this user cannot change.";
952  case NERR_PasswordHistConflict:
953  return "This password cannot be used now.";
954  case NERR_PasswordTooShort:
955  return "The password does not meet the password policy requirements. Check the minimum password length, password complexity and password history requirements.";
956  case NERR_PasswordTooRecent:
957  return "The password of this user is too recent to change.";
958  case NERR_InvalidDatabase:
959  return "The security database is corrupted.";
960  case NERR_DatabaseUpToDate:
961  return "No updates are necessary to this replicant network/local security database.";
962  case NERR_SyncRequired:
963  return "This replicant database is outdated; synchronization is required.";
964  case NERR_UseNotFound:
965  return "The network connection could not be found.";
966  case NERR_BadAsgType:
967  return "This asg_type is invalid.";
968  case NERR_DeviceIsShared:
969  return "This device is currently being shared.";
970  case NERR_NoComputerName:
971  return "The computer name could not be added as a message alias. The name may already exist on the network.";
972  case NERR_MsgAlreadyStarted:
973  return "The Messenger service is already started.";
974  case NERR_MsgInitFailed:
975  return "The Messenger service failed to start.";
976  case NERR_NameNotFound:
977  return "The message alias could not be found on the network.";
978  case NERR_AlreadyForwarded:
979  return "This message alias has already been forwarded.";
980  case NERR_AddForwarded:
981  return "This message alias has been added but is still forwarded.";
982  case NERR_AlreadyExists:
983  return "This message alias already exists locally.";
984  case NERR_TooManyNames:
985  return "The maximum number of added message aliases has been exceeded.";
986  case NERR_DelComputerName:
987  return "The computer name could not be deleted.";
988  case NERR_LocalForward:
989  return "Messages cannot be forwarded back to the same workstation.";
990  case NERR_GrpMsgProcessor:
991  return "An error occurred in the domain message processor.";
992  case NERR_PausedRemote:
993  return "The message was sent, but the recipient has paused the Messenger service.";
994  case NERR_BadReceive:
995  return "The message was sent but not received.";
996  case NERR_NameInUse:
997  return "The message alias is currently in use. Try again later.";
998  case NERR_MsgNotStarted:
999  return "The Messenger service has not been started.";
1000  case NERR_NotLocalName:
1001  return "The name is not on the local computer.";
1002  case NERR_NoForwardName:
1003  return "The forwarded message alias could not be found on the network.";
1004  case NERR_RemoteFull:
1005  return "The message alias table on the remote station is full.";
1006  case NERR_NameNotForwarded:
1007  return "Messages for this alias are not currently being forwarded.";
1008  case NERR_TruncatedBroadcast:
1009  return "The broadcast message was truncated.";
1010  case NERR_InvalidDevice:
1011  return "This is an invalid device name.";
1012  case NERR_WriteFault:
1013  return "A write fault occurred.";
1014  case NERR_DuplicateName:
1015  return "A duplicate message alias exists on the network.";
1016  case NERR_DeleteLater:
1017  return "@W This message alias will be deleted later.";
1018  case NERR_IncompleteDel:
1019  return "The message alias was not successfully deleted from all networks.";
1020  case NERR_MultipleNets:
1021  return "This operation is not supported on computers with multiple networks.";
1022  case NERR_NetNameNotFound:
1023  return "This shared resource does not exist.";
1024  case NERR_DeviceNotShared:
1025  return "This device is not shared.";
1026  case NERR_ClientNameNotFound:
1027  return "A session does not exist with that computer name.";
1028  case NERR_FileIdNotFound:
1029  return "There is not an open file with that identification number.";
1030  case NERR_ExecFailure:
1031  return "A failure occurred when executing a remote administration command.";
1032  case NERR_TmpFile:
1033  return "A failure occurred when opening a remote temporary file.";
1034  case NERR_TooMuchData:
1035  return "The data returned from a remote administration command has been truncated to 64K.";
1036  case NERR_DeviceShareConflict:
1037  return "This device cannot be shared as both a spooled and a non-spooled resource.";
1038  case NERR_BrowserTableIncomplete:
1039  return "The information in the list of servers may be incorrect.";
1040  case NERR_NotLocalDomain:
1041  return "The computer is not active in this domain.";
1042 #ifdef NERR_IsDfsShare
1043 
1044  case NERR_IsDfsShare:
1045  return "The share must be removed from the Distributed File System before it can be deleted.";
1046 #endif
1047 
1048  case NERR_DevInvalidOpCode:
1049  return "The operation is invalid for this device.";
1050  case NERR_DevNotFound:
1051  return "This device cannot be shared.";
1052  case NERR_DevNotOpen:
1053  return "This device was not open.";
1054  case NERR_BadQueueDevString:
1055  return "This device name list is invalid.";
1056  case NERR_BadQueuePriority:
1057  return "The queue priority is invalid.";
1058  case NERR_NoCommDevs:
1059  return "There are no shared communication devices.";
1060  case NERR_QueueNotFound:
1061  return "The queue you specified does not exist.";
1062  case NERR_BadDevString:
1063  return "This list of devices is invalid.";
1064  case NERR_BadDev:
1065  return "The requested device is invalid.";
1066  case NERR_InUseBySpooler:
1067  return "This device is already in use by the spooler.";
1068  case NERR_CommDevInUse:
1069  return "This device is already in use as a communication device.";
1070  case NERR_InvalidComputer:
1071  return "This computer name is invalid.";
1072  case NERR_MaxLenExceeded:
1073  return "The string and prefix specified are too long.";
1074  case NERR_BadComponent:
1075  return "This path component is invalid.";
1076  case NERR_CantType:
1077  return "Could not determine the type of input.";
1078  case NERR_TooManyEntries:
1079  return "The buffer for types is not big enough.";
1080  case NERR_ProfileFileTooBig:
1081  return "Profile files cannot exceed 64K.";
1082  case NERR_ProfileOffset:
1083  return "The start offset is out of range.";
1084  case NERR_ProfileCleanup:
1085  return "The system cannot delete current connections to network resources.";
1086  case NERR_ProfileUnknownCmd:
1087  return "The system was unable to parse the command line in this file.";
1088  case NERR_ProfileLoadErr:
1089  return "An error occurred while loading the profile file.";
1090  case NERR_ProfileSaveErr:
1091  return "@W Errors occurred while saving the profile file. The profile was partially saved.";
1092  case NERR_LogOverflow:
1093  return "Log file %1 is full.";
1094  case NERR_LogFileChanged:
1095  return "This log file has changed between reads.";
1096  case NERR_LogFileCorrupt:
1097  return "Log file %1 is corrupt.";
1098  case NERR_SourceIsDir:
1099  return "The source path cannot be a directory.";
1100  case NERR_BadSource:
1101  return "The source path is illegal.";
1102  case NERR_BadDest:
1103  return "The destination path is illegal.";
1104  case NERR_DifferentServers:
1105  return "The source and destination paths are on different servers.";
1106  case NERR_RunSrvPaused:
1107  return "The Run server you requested is paused.";
1108  case NERR_ErrCommRunSrv:
1109  return "An error occurred when communicating with a Run server.";
1110  case NERR_ErrorExecingGhost:
1111  return "An error occurred when starting a background process.";
1112  case NERR_ShareNotFound:
1113  return "The shared resource you are connected to could not be found.";
1114  case NERR_InvalidLana:
1115  return "The LAN adapter number is invalid.";
1116  case NERR_OpenFiles:
1117  return "There are open files on the connection.";
1118  case NERR_ActiveConns:
1119  return "Active connections still exist.";
1120  case NERR_BadPasswordCore:
1121  return "This share name or password is invalid.";
1122  case NERR_DevInUse:
1123  return "The device is being accessed by an active process.";
1124  case NERR_LocalDrive:
1125  return "The drive letter is in use locally.";
1126  case NERR_AlertExists:
1127  return "The specified client is already registered for the specified event.";
1128  case NERR_TooManyAlerts:
1129  return "The alert table is full.";
1130  case NERR_NoSuchAlert:
1131  return "An invalid or nonexistent alert name was raised.";
1132  case NERR_BadRecipient:
1133  return "The alert recipient is invalid.";
1134  case NERR_AcctLimitExceeded:
1135  return "A user's session with this server has been deleted.";
1136  case NERR_InvalidLogSeek:
1137  return "The log file does not contain the requested record number.";
1138  case NERR_BadUasConfig:
1139  return "The user accounts database is not configured correctly.";
1140  case NERR_InvalidUASOp:
1141  return "This operation is not permitted when the Netlogon service is running.";
1142  case NERR_LastAdmin:
1143  return "This operation is not allowed on the last administrative account.";
1144  case NERR_DCNotFound:
1145  return "Could not find domain controller for this domain.";
1146  case NERR_LogonTrackingError:
1147  return "Could not set logon information for this user.";
1148  case NERR_NetlogonNotStarted:
1149  return "The Netlogon service has not been started.";
1150  case NERR_CanNotGrowUASFile:
1151  return "Unable to add to the user accounts database.";
1152  case NERR_TimeDiffAtDC:
1153  return "This server's clock is not synchronized with the primary domain controller's clock.";
1154  case NERR_PasswordMismatch:
1155  return "A password mismatch has been detected.";
1156  case NERR_NoSuchServer:
1157  return "The server identification does not specify a valid server.";
1158  case NERR_NoSuchSession:
1159  return "The session identification does not specify a valid session.";
1160  case NERR_NoSuchConnection:
1161  return "The connection identification does not specify a valid connection.";
1162  case NERR_TooManyServers:
1163  return "There is no space for another entry in the table of available servers.";
1164  case NERR_TooManySessions:
1165  return "The server has reached the maximum number of sessions it supports.";
1166  case NERR_TooManyConnections:
1167  return "The server has reached the maximum number of connections it supports.";
1168  case NERR_TooManyFiles:
1169  return "The server cannot open more files because it has reached its maximum number.";
1170  case NERR_NoAlternateServers:
1171  return "There are no alternate servers registered on this server.";
1172  case NERR_TryDownLevel:
1173  return "Try down-level (remote admin protocol) version of API instead.";
1174  case NERR_UPSDriverNotStarted:
1175  return "The UPS driver could not be accessed by the UPS service.";
1176  case NERR_UPSInvalidConfig:
1177  return "The UPS service is not configured correctly.";
1178  case NERR_UPSInvalidCommPort:
1179  return "The UPS service could not access the specified Comm Port.";
1180  case NERR_UPSSignalAsserted:
1181  return "The UPS indicated a line fail or low battery situation. Service not started.";
1182  case NERR_UPSShutdownFailed:
1183  return "The UPS service failed to perform a system shut down.";
1184  case NERR_BadDosRetCode:
1185  return "The program below returned an MS-DOS error code:";
1186  case NERR_ProgNeedsExtraMem:
1187  return "The program below needs more memory:";
1188  case NERR_BadDosFunction:
1189  return "The program below called an unsupported MS-DOS function:";
1190  case NERR_RemoteBootFailed:
1191  return "The workstation failed to boot.";
1192  case NERR_BadFileCheckSum:
1193  return "The file below is corrupt.";
1194  case NERR_NoRplBootSystem:
1195  return "No loader is specified in the boot-block definition file.";
1196  case NERR_RplLoadrNetBiosErr:
1197  return "NetBIOS returned an error: The NCB and SMB are dumped above.";
1198  case NERR_RplLoadrDiskErr:
1199  return "A disk I/O error occurred.";
1200  case NERR_ImageParamErr:
1201  return "Image parameter substitution failed.";
1202  case NERR_TooManyImageParams:
1203  return "Too many image parameters cross disk sector boundaries.";
1204  case NERR_NonDosFloppyUsed:
1205  return "The image was not generated from an MS-DOS diskette formatted with /S.";
1206  case NERR_RplBootRestart:
1207  return "Remote boot will be restarted later.";
1208  case NERR_RplSrvrCallFailed:
1209  return "The call to the Remoteboot server failed.";
1210  case NERR_CantConnectRplSrvr:
1211  return "Cannot connect to the Remoteboot server.";
1212  case NERR_CantOpenImageFile:
1213  return "Cannot open image file on the Remoteboot server.";
1214  case NERR_CallingRplSrvr:
1215  return "Connecting to the Remoteboot server...";
1216  case NERR_StartingRplBoot:
1217  return "Connecting to the Remoteboot server...";
1218  case NERR_RplBootServiceTerm:
1219  return "Remote boot service was stopped; check the error log for the cause of the problem.";
1220  case NERR_RplBootStartFailed:
1221  return "Remote boot startup failed; check the error log for the cause of the problem.";
1222  case NERR_RPL_CONNECTED:
1223  return "A second connection to a Remoteboot resource is not allowed.";
1224  case NERR_BrowserConfiguredToNotRun:
1225  return "The browser service was configured with MaintainServerList=No.";
1226  case NERR_RplNoAdaptersStarted:
1227  return "Service failed to start since none of the network adapters started with this service.";
1228  case NERR_RplBadRegistry:
1229  return "Service failed to start due to bad startup information in the registry.";
1230  case NERR_RplBadDatabase:
1231  return "Service failed to start because its database is absent or corrupt.";
1232  case NERR_RplRplfilesShare:
1233  return "Service failed to start because RPLFILES share is absent.";
1234  case NERR_RplNotRplServer:
1235  return "Service failed to start because RPLUSER group is absent.";
1236  case NERR_RplCannotEnum:
1237  return "Cannot enumerate service records.";
1238  case NERR_RplWkstaInfoCorrupted:
1239  return "Workstation record information has been corrupted.";
1240  case NERR_RplWkstaNotFound:
1241  return "Workstation record was not found.";
1242  case NERR_RplWkstaNameUnavailable:
1243  return "Workstation name is in use by some other workstation.";
1244  case NERR_RplProfileInfoCorrupted:
1245  return "Profile record information has been corrupted.";
1246  case NERR_RplProfileNotFound:
1247  return "Profile record was not found.";
1248  case NERR_RplProfileNameUnavailable:
1249  return "Profile name is in use by some other profile.";
1250  case NERR_RplProfileNotEmpty:
1251  return "There are workstations using this profile.";
1252  case NERR_RplConfigInfoCorrupted:
1253  return "Configuration record information has been corrupted.";
1254  case NERR_RplConfigNotFound:
1255  return "Configuration record was not found.";
1256  case NERR_RplAdapterInfoCorrupted:
1257  return "Adapter ID record information has been corrupted.";
1258  case NERR_RplInternal:
1259  return "An internal service error has occurred.";
1260  case NERR_RplVendorInfoCorrupted:
1261  return "Vendor ID record information has been corrupted.";
1262  case NERR_RplBootInfoCorrupted:
1263  return "Boot block record information has been corrupted.";
1264  case NERR_RplWkstaNeedsUserAcct:
1265  return "The user account for this workstation record is missing.";
1266  case NERR_RplNeedsRPLUSERAcct:
1267  return "The RPLUSER local group could not be found.";
1268  case NERR_RplBootNotFound:
1269  return "Boot block record was not found.";
1270  case NERR_RplIncompatibleProfile:
1271  return "Chosen profile is incompatible with this workstation.";
1272  case NERR_RplAdapterNameUnavailable:
1273  return "Chosen network adapter ID is in use by some other workstation.";
1274  case NERR_RplConfigNotEmpty:
1275  return "There are profiles using this configuration.";
1276  case NERR_RplBootInUse:
1277  return "There are workstations, profiles, or configurations using this boot block.";
1278  case NERR_RplBackupDatabase:
1279  return "Service failed to backup Remoteboot database.";
1280  case NERR_RplAdapterNotFound:
1281  return "Adapter record was not found.";
1282  case NERR_RplVendorNotFound:
1283  return "Vendor record was not found.";
1284  case NERR_RplVendorNameUnavailable:
1285  return "Vendor name is in use by some other vendor record.";
1286  case NERR_RplBootNameUnavailable:
1287  return "(boot name, vendor ID) is in use by some other boot block record.";
1288  case NERR_RplConfigNameUnavailable:
1289  return "Configuration name is in use by some other configuration.";
1290  case NERR_DfsInternalCorruption:
1291  return "The internal database maintained by the Dfs service is corrupt.";
1292  case NERR_DfsVolumeDataCorrupt:
1293  return "One of the records in the internal Dfs database is corrupt.";
1294  case NERR_DfsNoSuchVolume:
1295  return "There is no DFS name whose entry path matches the input Entry Path.";
1296  case NERR_DfsVolumeAlreadyExists:
1297  return "A root or link with the given name already exists.";
1298  case NERR_DfsAlreadyShared:
1299  return "The server share specified is already shared in the Dfs.";
1300  case NERR_DfsNoSuchShare:
1301  return "The indicated server share does not support the indicated DFS namespace.";
1302  case NERR_DfsNotALeafVolume:
1303  return "The operation is not valid on this portion of the namespace.";
1304  case NERR_DfsLeafVolume:
1305  return "The operation is not valid on this portion of the namespace.";
1306  case NERR_DfsVolumeHasMultipleServers:
1307  return "The operation is ambiguous because the link has multiple servers.";
1308  case NERR_DfsCantCreateJunctionPoint:
1309  return "Unable to create a link.";
1310  case NERR_DfsServerNotDfsAware:
1311  return "The server is not Dfs Aware.";
1312  case NERR_DfsBadRenamePath:
1313  return "The specified rename target path is invalid.";
1314  case NERR_DfsVolumeIsOffline:
1315  return "The specified DFS link is offline.";
1316  case NERR_DfsNoSuchServer:
1317  return "The specified server is not a server for this link.";
1318  case NERR_DfsCyclicalName:
1319  return "A cycle in the Dfs name was detected.";
1320  case NERR_DfsNotSupportedInServerDfs:
1321  return "The operation is not supported on a server-based Dfs.";
1322  case NERR_DfsDuplicateService:
1323  return "This link is already supported by the specified server-share.";
1324  case NERR_DfsCantRemoveLastServerShare:
1325  return "Can't remove the last server-share supporting this root or link.";
1326  case NERR_DfsVolumeIsInterDfs:
1327  return "The operation is not supported for an Inter-DFS link.";
1328  case NERR_DfsInconsistent:
1329  return "The internal state of the Dfs Service has become inconsistent.";
1330  case NERR_DfsServerUpgraded:
1331  return "The Dfs Service has been installed on the specified server.";
1332  case NERR_DfsDataIsIdentical:
1333  return "The Dfs data being reconciled is identical.";
1334  case NERR_DfsCantRemoveDfsRoot:
1335  return "The DFS root cannot be deleted. Uninstall DFS if required.";
1336  case NERR_DfsChildOrParentInDfs:
1337  return "A child or parent directory of the share is already in a Dfs.";
1338  case NERR_DfsInternalError:
1339  return "Dfs internal error.";
1340  /* the following are not defined in mingw */
1341 #if 0
1342 
1343  case NERR_SetupAlreadyJoined:
1344  return "This machine is already joined to a domain.";
1345  case NERR_SetupNotJoined:
1346  return "This machine is not currently joined to a domain.";
1347  case NERR_SetupDomainController:
1348  return "This machine is a domain controller and cannot be unjoined from a domain.";
1349  case NERR_DefaultJoinRequired:
1350  return "The destination domain controller does not support creating machine accounts in OUs.";
1351  case NERR_InvalidWorkgroupName:
1352  return "The specified workgroup name is invalid.";
1353  case NERR_NameUsesIncompatibleCodePage:
1354  return "The specified computer name is incompatible with the default language used on the domain controller.";
1355  case NERR_ComputerAccountNotFound:
1356  return "The specified computer account could not be found.";
1357  case NERR_PersonalSku:
1358  return "This version of Windows cannot be joined to a domain.";
1359  case NERR_PasswordMustChange:
1360  return "The password must change at the next logon.";
1361  case NERR_AccountLockedOut:
1362  return "The account is locked out.";
1363  case NERR_PasswordTooLong:
1364  return "The password is too long.";
1365  case NERR_PasswordNotComplexEnough:
1366  return "The password does not meet the complexity policy.";
1367  case NERR_PasswordFilterError:
1368  return "The password does not meet the requirements of the password filter DLLs.";
1369 #endif
1370 
1371  default:
1372  msg = strerror (error_number);
1373 
1374  if (msg == NULL)
1375  msg = "unknown";
1376 
1377  return msg;
1378  }
1379 #endif //DBUS_WINCE
1380 }
1381 
1397 _dbus_command_for_pid (unsigned long pid,
1398  DBusString *str,
1399  int max_len,
1400  DBusError *error)
1401 {
1403  "_dbus_command_for_pid() not implemented on Windows");
1404  return FALSE;
1405 }
1406 
1417 {
1418 #ifndef DBUS_PREFIX
1419  /* leave path unchanged */
1420  return TRUE;
1421 #else
1422  DBusString runtime_prefix;
1423  int i;
1424 
1425  if (!_dbus_string_init (&runtime_prefix))
1426  return FALSE;
1427 
1428  if (!_dbus_get_install_root (&runtime_prefix))
1429  {
1430  _dbus_string_free (&runtime_prefix);
1431  return FALSE;
1432  }
1433 
1434  if (_dbus_string_get_length (&runtime_prefix) == 0)
1435  {
1436  /* cannot determine install root, leave path unchanged */
1437  _dbus_string_free (&runtime_prefix);
1438  return TRUE;
1439  }
1440 
1441  if (_dbus_string_starts_with_c_str (path, DBUS_PREFIX "/"))
1442  {
1443  /* Replace DBUS_PREFIX "/" with runtime_prefix.
1444  * Note unusual calling convention: source is first, then dest */
1446  &runtime_prefix, 0, _dbus_string_get_length (&runtime_prefix),
1447  path, 0, strlen (DBUS_PREFIX) + 1))
1448  {
1449  _dbus_string_free (&runtime_prefix);
1450  return FALSE;
1451  }
1452  }
1453 
1454  /* Somehow, in some situations, backslashes get collapsed in the string.
1455  * Since windows C library accepts both forward and backslashes as
1456  * path separators, convert all backslashes to forward slashes.
1457  */
1458 
1459  for (i = 0; i < _dbus_string_get_length (path); i++)
1460  {
1461  if (_dbus_string_get_byte (path, i) == '\\')
1462  _dbus_string_set_byte (path, i, '/');
1463  }
1464 
1465  _dbus_string_free (&runtime_prefix);
1466  return TRUE;
1467 #endif
1468 }
1469 
1470 #define DBUS_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
1471 #define DBUS_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"
1472 
1482  DBusError *error)
1483 {
1484  /* Not an error, we just don't have transient session services on Windows */
1485  return TRUE;
1486 }
1487 
1506 {
1507  const char *common_progs;
1508  DBusString servicedir_path;
1509 
1510  if (!_dbus_string_init (&servicedir_path))
1511  return FALSE;
1512 
1513 #ifdef DBUS_WINCE
1514  {
1515  /* On Windows CE, we adjust datadir dynamically to installation location. */
1516  const char *data_dir = _dbus_getenv ("DBUS_DATADIR");
1517 
1518  if (data_dir != NULL)
1519  {
1520  if (!_dbus_string_append (&servicedir_path, data_dir))
1521  goto oom;
1522 
1523  if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
1524  goto oom;
1525  }
1526  }
1527 #else
1528  {
1529  DBusString p;
1530 
1531  if (!_dbus_string_init (&p))
1532  goto oom;
1533 
1534  /* DBUS_DATADIR is assumed to be absolute; the build systems should
1535  * ensure that. */
1536  if (!_dbus_string_append (&p, DBUS_DATADIR) ||
1538  {
1539  _dbus_string_free (&p);
1540  goto oom;
1541  }
1542 
1543  if (!_dbus_string_append (&servicedir_path,
1544  _dbus_string_get_const_data (&p)))
1545  {
1546  _dbus_string_free (&p);
1547  goto oom;
1548  }
1549 
1550  _dbus_string_free (&p);
1551  }
1552 
1553  if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
1554  goto oom;
1555 #endif
1556 
1557  common_progs = _dbus_getenv ("CommonProgramFiles");
1558 
1559  if (common_progs != NULL)
1560  {
1561  if (!_dbus_string_append (&servicedir_path, common_progs))
1562  goto oom;
1563 
1564  if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
1565  goto oom;
1566  }
1567 
1568  if (!_dbus_split_paths_and_append (&servicedir_path,
1569  DBUS_STANDARD_SESSION_SERVICEDIR,
1570  dirs))
1571  goto oom;
1572 
1573  _dbus_string_free (&servicedir_path);
1574  return TRUE;
1575 
1576  oom:
1577  _dbus_string_free (&servicedir_path);
1578  return FALSE;
1579 }
1580 
1601 {
1602  *dirs = NULL;
1603  return TRUE;
1604 }
1605 
1606 static dbus_bool_t
1607 _dbus_get_config_file_name (DBusString *str,
1608  const char *basename)
1609 {
1610  DBusString tmp;
1611 
1612  if (!_dbus_string_append (str, DBUS_DATADIR) ||
1614  return FALSE;
1615 
1616  _dbus_string_init_const (&tmp, "dbus-1");
1617 
1618  if (!_dbus_concat_dir_and_file (str, &tmp))
1619  return FALSE;
1620 
1621  _dbus_string_init_const (&tmp, basename);
1622 
1623  if (!_dbus_concat_dir_and_file (str, &tmp))
1624  return FALSE;
1625 
1626  return TRUE;
1627 }
1628 
1639 {
1640  _dbus_assert (_dbus_string_get_length (str) == 0);
1641 
1642  return _dbus_get_config_file_name(str, "system.conf");
1643 }
1644 
1653 {
1654  _dbus_assert (_dbus_string_get_length (str) == 0);
1655 
1656  return _dbus_get_config_file_name(str, "session.conf");
1657 }
1658 
1659 void
1661 {
1662 }
1663 
1664 void
1666 {
1667 }
1668 
1669 void
1671 {
1672 }
1673 
1674 void
1676 {
1677 }
1678 
1679 void
1680 _dbus_win_stderr_win_error (const char *app,
1681  const char *message,
1682  unsigned long code)
1683 {
1684  DBusError error;
1685 
1686  dbus_error_init (&error);
1687  _dbus_win_set_error_from_win_error (&error, code);
1688  fprintf (stderr, "%s: %s: %s\n", app, message, error.message);
1689  dbus_error_free (&error);
1690 }
1691 
1692 static int exception_handler (LPEXCEPTION_POINTERS p) _DBUS_GNUC_NORETURN;
1693 
1694 static int
1695 exception_handler (LPEXCEPTION_POINTERS p)
1696 {
1697  ExitProcess (0xc0000005);
1698 }
1699 
1703 void
1705 {
1706  /* Disable Windows popup dialog when an app crashes so that app quits
1707  * immediately with error code instead of waiting for user to dismiss
1708  * the dialog. */
1709  DWORD dwMode = SetErrorMode (SEM_NOGPFAULTERRORBOX);
1710 
1711  SetErrorMode (dwMode | SEM_NOGPFAULTERRORBOX);
1712  /* Disable "just in time" debugger */
1713  SetUnhandledExceptionFilter ((LPTOP_LEVEL_EXCEPTION_FILTER) &exception_handler);
1714 }
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
Definition: dbus-string.c:952
dbus_bool_t _dbus_split_paths_and_append(DBusString *dirs, const char *suffix, DBusList **dir_list)
Split paths into a list of char strings.
Definition: dbus-sysdeps.c:236
const char * message
public error message field
Definition: dbus-errors.h:51
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_bool_t _dbus_string_get_dirname(const DBusString *filename, DBusString *dirname)
Get the directory name from a complete filename.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition: dbus-memory.c:703
Portable struct with stat() results.
Definition: dbus-sysdeps.h:546
#define DBUS_ERROR_NOT_SUPPORTED
Requested operation isn&#39;t supported (like ENOSYS on UNIX).
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_string_append_int(DBusString *str, long value)
Appends an integer to a DBusString.
Definition: dbus-sysdeps.c:363
dbus_bool_t _dbus_string_starts_with_c_str(const DBusString *a, const char *c_str)
Checks whether a string starts with the given C string.
Definition: dbus-string.c:2205
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
unsigned long atime
Access time.
Definition: dbus-sysdeps.h:553
void dbus_error_free(DBusError *error)
Frees an error that&#39;s been set (or just initialized), then reinitializes the error as in dbus_error_i...
Definition: dbus-errors.c:211
dbus_bool_t _dbus_get_standard_session_servicedirs(DBusList **dirs)
Returns the standard directories for a session bus to look for service activation files...
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:175
dbus_bool_t _dbus_command_for_pid(unsigned long pid, DBusString *str, int max_len, DBusError *error)
Get a printable string describing the command used to execute the process with pid.
dbus_bool_t _dbus_get_system_config_file(DBusString *str)
Get the absolute path of the system.conf file (there is no system bus on Windows so this can just ret...
dbus_bool_t _dbus_unix_user_is_process_owner(dbus_uid_t uid)
Checks to see if the UNIX user ID matches the UID of the process.
dbus_bool_t _dbus_string_ends_with_c_str(const DBusString *a, const char *c_str)
Returns whether a string ends with the given suffix.
#define DBUS_UID_UNSET
an invalid UID used to represent an uninitialized dbus_uid_t field
Definition: dbus-sysdeps.h:141
dbus_bool_t _dbus_parse_unix_user_from_config(const DBusString *username, dbus_uid_t *uid_p)
Parse a UNIX user from the bus config file.
Internals of directory iterator.
unsigned long mode
File mode.
Definition: dbus-sysdeps.h:548
unsigned long dbus_pid_t
A process ID.
Definition: dbus-sysdeps.h:132
dbus_gid_t gid
Group owning file.
Definition: dbus-sysdeps.h:551
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
Definition: dbus-memory.h:58
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:190
dbus_bool_t _dbus_windows_user_is_process_owner(const char *windows_sid)
Checks to see if the Windows user SID matches the owner of the process.
dbus_bool_t _dbus_get_session_config_file(DBusString *str)
Get the absolute path of the session.conf file.
void _dbus_daemon_report_stopping(void)
Report to a service manager that the daemon calling this function is shutting down.
dbus_bool_t _dbus_string_replace_len(const DBusString *source, int start, int len, DBusString *dest, int replace_at, int replace_len)
Replaces a segment of dest string with a segment of source string.
Definition: dbus-string.c:1421
dbus_bool_t _dbus_write_pid_to_file_and_pipe(const DBusString *pidfile, DBusPipe *print_pid_pipe, dbus_pid_t pid_to_write, DBusError *error)
Writes the given pid_to_write to a pidfile (if non-NULL) and/or to a pipe (if non-NULL).
dbus_bool_t _dbus_change_to_daemon_user(const char *user, DBusError *error)
Changes the user and group the bus is running as.
dbus_bool_t _dbus_verify_daemon_user(const char *user)
Verify that after the fork we can successfully change to this user.
Object representing an exception.
Definition: dbus-errors.h:48
dbus_bool_t _dbus_stat(const DBusString *filename, DBusStat *statbuf, DBusError *error)
stat() wrapper.
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
Definition: dbus-errors.c:354
unsigned long ctime
Creation time.
Definition: dbus-sysdeps.h:555
dbus_bool_t _dbus_string_init_from_string(DBusString *str, const DBusString *from)
Initializes a string from another string.
Definition: dbus-string.c:245
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
Definition: dbus-string.c:264
#define DBUS_GID_UNSET
an invalid GID used to represent an uninitialized dbus_gid_t field
Definition: dbus-sysdeps.h:143
#define TRUE
Expands to "1".
unsigned long nlink
Number of hard links.
Definition: dbus-sysdeps.h:549
dbus_bool_t _dbus_parse_unix_group_from_config(const DBusString *groupname, dbus_gid_t *gid_p)
Parse a UNIX group from the bus config file.
dbus_uid_t uid
User owning file.
Definition: dbus-sysdeps.h:550
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
dbus_bool_t _dbus_string_find_byte_backward(const DBusString *str, int start, unsigned char byte, int *found)
Find the given byte scanning backward from the given start.
dbus_bool_t _dbus_become_daemon(const DBusString *pidfile, DBusPipe *print_pid_pipe, DBusError *error, dbus_bool_t keep_umask)
Does the chdir, fork, setsid, etc.
const char * _dbus_strerror_from_errno(void)
Get error message from errno.
Definition: dbus-sysdeps.c:758
const char * _dbus_error_from_system_errno(void)
Converts the current system errno value into a DBusError name.
Definition: dbus-sysdeps.c:691
void _dbus_directory_close(DBusDirIter *iter)
Closes a directory iteration.
void dbus_error_init(DBusError *error)
Initializes a DBusError structure.
Definition: dbus-errors.c:188
A node in a linked list.
Definition: dbus-list.h:34
void _dbus_daemon_report_ready(void)
Report to a service manager that the daemon calling this function is ready for use.
dbus_bool_t _dbus_replace_install_prefix(DBusString *path)
Replace the DBUS_PREFIX in the given path, in-place, by the current D-Bus installation directory...
void _dbus_daemon_report_reloaded(void)
Report to a service manager that the daemon calling this function is reloading configuration.
dbus_bool_t _dbus_set_up_transient_session_servicedirs(DBusList **dirs, DBusError *error)
Returns the standard directories for a session bus to look for transient service activation files...
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define FALSE
Expands to "0".
unsigned long mtime
Modify time.
Definition: dbus-sysdeps.h:554
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.
Definition: dbus-string.c:819
void _dbus_daemon_report_reloading(void)
Report to a service manager that the daemon calling this function is reloading configuration.
DBusDirIter * _dbus_directory_open(const DBusString *filename, DBusError *error)
Open a directory to iterate over.
dbus_bool_t _dbus_string_copy_len(const DBusString *source, int start, int len, DBusString *dest, int insert_at)
Like _dbus_string_copy(), but can copy a segment from the middle of the source string.
Definition: dbus-string.c:1392
unsigned long dbus_gid_t
A group ID.
Definition: dbus-sysdeps.h:136
unsigned long size
Size of file.
Definition: dbus-sysdeps.h:552
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition: dbus-sysdeps.c:195
unsigned long dbus_uid_t
A user ID.
Definition: dbus-sysdeps.h:134
dbus_bool_t _dbus_unix_groups_from_uid(dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids)
Gets all groups corresponding to the given UNIX user ID.
dbus_bool_t _dbus_get_standard_system_servicedirs(DBusList **dirs)
Returns the standard directories for a system bus to look for service activation files.
dbus_bool_t _dbus_directory_get_next_file(DBusDirIter *iter, DBusString *filename, DBusError *error)
Get next file in the directory.
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
Definition: dbus-errors.c:329
void _dbus_disable_crash_handling(void)
Try to disable core dumps and similar special crash handling.
dbus_bool_t _dbus_unix_user_is_at_console(dbus_uid_t uid, DBusError *error)
Checks to see if the UNIX user ID is at the console.