D-Bus  1.10.24
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 
65  const char *working_dir,
66  DBusPipe *print_pid_pipe,
67  DBusError *error,
68  dbus_bool_t keep_umask)
69 {
71  "Cannot daemonize on Windows");
72  return FALSE;
73 }
74 
83 static dbus_bool_t
84 _dbus_write_pid_file (const DBusString *filename,
85  unsigned long pid,
86  DBusError *error)
87 {
88  const char *cfilename;
89  HANDLE hnd;
90  char pidstr[20];
91  int total;
92  int bytes_to_write;
93 
94  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
95 
96  cfilename = _dbus_string_get_const_data (filename);
97 
98  hnd = CreateFileA (cfilename, GENERIC_WRITE,
99  FILE_SHARE_READ | FILE_SHARE_WRITE,
100  NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,
101  INVALID_HANDLE_VALUE);
102  if (hnd == INVALID_HANDLE_VALUE)
103  {
104  char *emsg = _dbus_win_error_string (GetLastError ());
105  dbus_set_error (error, _dbus_win_error_from_last_error (),
106  "Could not create PID file %s: %s",
107  cfilename, emsg);
108  _dbus_win_free_error_string (emsg);
109  return FALSE;
110  }
111 
112  if (snprintf (pidstr, sizeof (pidstr), "%lu\n", pid) < 0)
113  {
115  "Failed to format PID for \"%s\": %s", cfilename,
117  CloseHandle (hnd);
118  return FALSE;
119  }
120 
121  total = 0;
122  bytes_to_write = strlen (pidstr);;
123 
124  while (total < bytes_to_write)
125  {
126  DWORD bytes_written;
127  BOOL res;
128 
129  res = WriteFile (hnd, pidstr + total, bytes_to_write - total,
130  &bytes_written, NULL);
131 
132  if (res == 0 || bytes_written <= 0)
133  {
134  char *emsg = _dbus_win_error_string (GetLastError ());
135  dbus_set_error (error, _dbus_win_error_from_last_error (),
136  "Could not write to %s: %s", cfilename, emsg);
137  _dbus_win_free_error_string (emsg);
138  CloseHandle (hnd);
139  return FALSE;
140  }
141 
142  total += bytes_written;
143  }
144 
145  if (CloseHandle (hnd) == 0)
146  {
147  char *emsg = _dbus_win_error_string (GetLastError ());
148  dbus_set_error (error, _dbus_win_error_from_last_error (),
149  "Could not close file %s: %s",
150  cfilename, emsg);
151  _dbus_win_free_error_string (emsg);
152 
153  return FALSE;
154  }
155 
156  return TRUE;
157 }
158 
172  DBusPipe *print_pid_pipe,
173  dbus_pid_t pid_to_write,
174  DBusError *error)
175 {
176  if (pidfile)
177  {
178  _dbus_verbose ("writing pid file %s\n", _dbus_string_get_const_data (pidfile));
179  if (!_dbus_write_pid_file (pidfile,
180  pid_to_write,
181  error))
182  {
183  _dbus_verbose ("pid file write failed\n");
184  _DBUS_ASSERT_ERROR_IS_SET(error);
185  return FALSE;
186  }
187  }
188  else
189  {
190  _dbus_verbose ("No pid file requested\n");
191  }
192 
193  if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
194  {
195  DBusString pid;
196  int bytes;
197 
198  _dbus_verbose ("writing our pid to pipe %d\n", print_pid_pipe->fd);
199 
200  if (!_dbus_string_init (&pid))
201  {
202  _DBUS_SET_OOM (error);
203  return FALSE;
204  }
205 
206  if (!_dbus_string_append_int (&pid, pid_to_write) ||
207  !_dbus_string_append (&pid, "\n"))
208  {
209  _dbus_string_free (&pid);
210  _DBUS_SET_OOM (error);
211  return FALSE;
212  }
213 
214  bytes = _dbus_string_get_length (&pid);
215  if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
216  {
217  /* _dbus_pipe_write sets error only on failure, not short write */
218  if (error != NULL && !dbus_error_is_set(error))
219  {
221  "Printing message bus PID: did not write enough bytes\n");
222  }
223  _dbus_string_free (&pid);
224  return FALSE;
225  }
226 
227  _dbus_string_free (&pid);
228  }
229  else
230  {
231  _dbus_verbose ("No pid pipe to write to\n");
232  }
233 
234  return TRUE;
235 }
236 
244 _dbus_verify_daemon_user (const char *user)
245 {
246  return TRUE;
247 }
248 
257 _dbus_change_to_daemon_user (const char *user,
258  DBusError *error)
259 {
260  return TRUE;
261 }
262 
263 static void
264 fd_limit_not_supported (DBusError *error)
265 {
267  "cannot change fd limit on this platform");
268 }
269 
270 DBusRLimit *
271 _dbus_rlimit_save_fd_limit (DBusError *error)
272 {
273  fd_limit_not_supported (error);
274  return NULL;
275 }
276 
278 _dbus_rlimit_raise_fd_limit_if_privileged (unsigned int desired,
279  DBusError *error)
280 {
281  fd_limit_not_supported (error);
282  return FALSE;
283 }
284 
286 _dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
287  DBusError *error)
288 {
289  fd_limit_not_supported (error);
290  return FALSE;
291 }
292 
293 void
294 _dbus_rlimit_free (DBusRLimit *lim)
295 {
296  /* _dbus_rlimit_save_fd_limit() cannot return non-NULL on Windows
297  * so there cannot be anything to free */
298  _dbus_assert (lim == NULL);
299 }
300 
301 void
302 _dbus_init_system_log (dbus_bool_t is_daemon)
303 {
304  /* OutputDebugStringA doesn't need any special initialization, do nothing */
305 }
306 
313 void
314 _dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...)
315 {
316  va_list args;
317 
318  va_start (args, msg);
319 
320  _dbus_system_logv (severity, msg, args);
321 
322  va_end (args);
323 }
324 
335 void
336 _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
337 {
338  char *s = "";
339  char buf[1024];
340  char format[1024];
341 
342  switch(severity)
343  {
344  case DBUS_SYSTEM_LOG_INFO: s = "info"; break;
345  case DBUS_SYSTEM_LOG_WARNING: s = "warning"; break;
346  case DBUS_SYSTEM_LOG_SECURITY: s = "security"; break;
347  case DBUS_SYSTEM_LOG_FATAL: s = "fatal"; break;
348  }
349 
350  snprintf(format, sizeof(format), "%s%s", s ,msg);
351  vsnprintf(buf, sizeof(buf), format, args);
352  OutputDebugStringA(buf);
353 
354  if (severity == DBUS_SYSTEM_LOG_FATAL)
355  exit (1);
356 }
357 
363 void
365  DBusSignalHandler handler)
366 {
367  _dbus_verbose ("_dbus_set_signal_handler() has to be implemented\n");
368 }
369 
379 _dbus_stat(const DBusString *filename,
380  DBusStat *statbuf,
381  DBusError *error)
382 {
383  const char *filename_c;
384  WIN32_FILE_ATTRIBUTE_DATA wfad;
385  char *lastdot;
386 
387  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
388 
389  filename_c = _dbus_string_get_const_data (filename);
390 
391  if (!GetFileAttributesExA (filename_c, GetFileExInfoStandard, &wfad))
392  {
393  _dbus_win_set_error_from_win_error (error, GetLastError ());
394  return FALSE;
395  }
396 
397  if (wfad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
398  statbuf->mode = _S_IFDIR;
399  else
400  statbuf->mode = _S_IFREG;
401 
402  statbuf->mode |= _S_IREAD;
403  if (wfad.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
404  statbuf->mode |= _S_IWRITE;
405 
406  lastdot = strrchr (filename_c, '.');
407  if (lastdot && stricmp (lastdot, ".exe") == 0)
408  statbuf->mode |= _S_IEXEC;
409 
410  statbuf->mode |= (statbuf->mode & 0700) >> 3;
411  statbuf->mode |= (statbuf->mode & 0700) >> 6;
412 
413  statbuf->nlink = 1;
414 
415 #ifdef ENABLE_UID_TO_SID
416  {
417  PSID owner_sid, group_sid;
418  PSECURITY_DESCRIPTOR sd;
419 
420  sd = NULL;
421  rc = GetNamedSecurityInfo ((char *) filename_c, SE_FILE_OBJECT,
422  OWNER_SECURITY_INFORMATION |
423  GROUP_SECURITY_INFORMATION,
424  &owner_sid, &group_sid,
425  NULL, NULL,
426  &sd);
427  if (rc != ERROR_SUCCESS)
428  {
429  _dbus_win_set_error_from_win_error (error, rc);
430  if (sd != NULL)
431  LocalFree (sd);
432  return FALSE;
433  }
434 
435  /* FIXME */
436  statbuf->uid = _dbus_win_sid_to_uid_t (owner_sid);
437  statbuf->gid = _dbus_win_sid_to_uid_t (group_sid);
438 
439  LocalFree (sd);
440  }
441 #else
442  statbuf->uid = DBUS_UID_UNSET;
443  statbuf->gid = DBUS_GID_UNSET;
444 #endif
445 
446  statbuf->size = ((dbus_int64_t) wfad.nFileSizeHigh << 32) + wfad.nFileSizeLow;
447 
448  statbuf->atime =
449  (((dbus_int64_t) wfad.ftLastAccessTime.dwHighDateTime << 32) +
450  wfad.ftLastAccessTime.dwLowDateTime) / 10000000 - DBUS_INT64_CONSTANT (116444736000000000);
451 
452  statbuf->mtime =
453  (((dbus_int64_t) wfad.ftLastWriteTime.dwHighDateTime << 32) +
454  wfad.ftLastWriteTime.dwLowDateTime) / 10000000 - DBUS_INT64_CONSTANT (116444736000000000);
455 
456  statbuf->ctime =
457  (((dbus_int64_t) wfad.ftCreationTime.dwHighDateTime << 32) +
458  wfad.ftCreationTime.dwLowDateTime) / 10000000 - DBUS_INT64_CONSTANT (116444736000000000);
459 
460  return TRUE;
461 }
462 
466 struct DBusDirIter
467  {
468  HANDLE handle;
469  WIN32_FIND_DATAA fileinfo; /* from FindFirst/FindNext */
470  dbus_bool_t finished; /* true if there are no more entries */
471  int offset;
472  };
473 
483  DBusError *error)
484 {
485  DBusDirIter *iter;
486  DBusString filespec;
487 
488  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
489 
490  if (!_dbus_string_init_from_string (&filespec, filename))
491  {
493  "Could not allocate memory for directory filename copy");
494  return NULL;
495  }
496 
497  if (_dbus_string_ends_with_c_str (&filespec, "/") || _dbus_string_ends_with_c_str (&filespec, "\\") )
498  {
499  if (!_dbus_string_append (&filespec, "*"))
500  {
502  "Could not append filename wildcard");
503  return NULL;
504  }
505  }
506  else if (!_dbus_string_ends_with_c_str (&filespec, "*"))
507  {
508  if (!_dbus_string_append (&filespec, "\\*"))
509  {
511  "Could not append filename wildcard 2");
512  return NULL;
513  }
514  }
515 
516  iter = dbus_new0 (DBusDirIter, 1);
517  if (iter == NULL)
518  {
519  _dbus_string_free (&filespec);
521  "Could not allocate memory for directory iterator");
522  return NULL;
523  }
524 
525  iter->finished = FALSE;
526  iter->offset = 0;
527  iter->handle = FindFirstFileA (_dbus_string_get_const_data (&filespec), &(iter->fileinfo));
528  if (iter->handle == INVALID_HANDLE_VALUE)
529  {
530  if (GetLastError () == ERROR_NO_MORE_FILES)
531  iter->finished = TRUE;
532  else
533  {
534  char *emsg = _dbus_win_error_string (GetLastError ());
535  dbus_set_error (error, _dbus_win_error_from_last_error (),
536  "Failed to read directory \"%s\": %s",
537  _dbus_string_get_const_data (filename), emsg);
538  _dbus_win_free_error_string (emsg);
539  dbus_free ( iter );
540  _dbus_string_free (&filespec);
541  return NULL;
542  }
543  }
544  _dbus_string_free (&filespec);
545  return iter;
546 }
547 
560  DBusString *filename,
561  DBusError *error)
562 {
563  int saved_err = GetLastError();
564 
565  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
566 
567 again:
568  SetLastError (0);
569 
570  if (!iter || iter->finished)
571  return FALSE;
572 
573  if (iter->offset > 0)
574  {
575  if (FindNextFileA (iter->handle, &(iter->fileinfo)) == 0)
576  {
577  if (GetLastError() == ERROR_NO_MORE_FILES)
578  {
579  SetLastError(saved_err);
580  iter->finished = 1;
581  }
582  else
583  {
584  char *emsg = _dbus_win_error_string (GetLastError ());
585  dbus_set_error (error, _dbus_win_error_from_last_error (),
586  "Failed to get next in directory: %s", emsg);
587  _dbus_win_free_error_string (emsg);
588  return FALSE;
589  }
590  }
591  }
592 
593  iter->offset++;
594 
595  if (iter->finished)
596  return FALSE;
597 
598  if (iter->fileinfo.cFileName[0] == '.' &&
599  (iter->fileinfo.cFileName[1] == '\0' ||
600  (iter->fileinfo.cFileName[1] == '.' && iter->fileinfo.cFileName[2] == '\0')))
601  goto again;
602 
603  _dbus_string_set_length (filename, 0);
604  if (!_dbus_string_append (filename, iter->fileinfo.cFileName))
605  {
607  "No memory to read directory entry");
608  return FALSE;
609  }
610 
611  return TRUE;
612 }
613 
617 void
619 {
620  if (!iter)
621  return;
622  FindClose(iter->handle);
623  dbus_free (iter);
624 }
625  /* End of DBusInternalsUtils functions */
627 
640 _dbus_string_get_dirname(const DBusString *filename,
641  DBusString *dirname)
642 {
643  int sep;
644 
645  _dbus_assert (filename != dirname);
646  _dbus_assert (filename != NULL);
647  _dbus_assert (dirname != NULL);
648 
649  /* Ignore any separators on the end */
650  sep = _dbus_string_get_length (filename);
651  if (sep == 0)
652  return _dbus_string_append (dirname, "."); /* empty string passed in */
653 
654  while (sep > 0 &&
655  (_dbus_string_get_byte (filename, sep - 1) == '/' ||
656  _dbus_string_get_byte (filename, sep - 1) == '\\'))
657  --sep;
658 
659  _dbus_assert (sep >= 0);
660 
661  if (sep == 0 ||
662  (sep == 2 &&
663  _dbus_string_get_byte (filename, 1) == ':' &&
664  isalpha (_dbus_string_get_byte (filename, 0))))
665  return _dbus_string_copy_len (filename, 0, sep + 1,
666  dirname, _dbus_string_get_length (dirname));
667 
668  {
669  int sep1, sep2;
670  _dbus_string_find_byte_backward (filename, sep, '/', &sep1);
671  _dbus_string_find_byte_backward (filename, sep, '\\', &sep2);
672 
673  sep = MAX (sep1, sep2);
674  }
675  if (sep < 0)
676  return _dbus_string_append (dirname, ".");
677 
678  while (sep > 0 &&
679  (_dbus_string_get_byte (filename, sep - 1) == '/' ||
680  _dbus_string_get_byte (filename, sep - 1) == '\\'))
681  --sep;
682 
683  _dbus_assert (sep >= 0);
684 
685  if ((sep == 0 ||
686  (sep == 2 &&
687  _dbus_string_get_byte (filename, 1) == ':' &&
688  isalpha (_dbus_string_get_byte (filename, 0))))
689  &&
690  (_dbus_string_get_byte (filename, sep) == '/' ||
691  _dbus_string_get_byte (filename, sep) == '\\'))
692  return _dbus_string_copy_len (filename, 0, sep + 1,
693  dirname, _dbus_string_get_length (dirname));
694  else
695  return _dbus_string_copy_len (filename, 0, sep - 0,
696  dirname, _dbus_string_get_length (dirname));
697 }
698 
699 
709 {
710  return FALSE;
711 }
712 
714 {
715  return TRUE;
716 }
717 
718 /*=====================================================================
719  unix emulation functions - should be removed sometime in the future
720  =====================================================================*/
721 
733  DBusError *error)
734 {
736  "UNIX user IDs not supported on Windows\n");
737  return FALSE;
738 }
739 
740 
751  dbus_gid_t *gid_p)
752 {
753  return FALSE;
754 }
755 
766  dbus_uid_t *uid_p)
767 {
768  return FALSE;
769 }
770 
771 
784  dbus_gid_t **group_ids,
785  int *n_group_ids)
786 {
787  return FALSE;
788 }
789 
790 
791  /* DBusString stuff */
793 
794 /************************************************************************
795 
796  error handling
797 
798  ************************************************************************/
799 
800 
801 
802 
803 
804 /* lan manager error codes */
805 const char*
806 _dbus_lm_strerror(int error_number)
807 {
808 #ifdef DBUS_WINCE
809  // TODO
810  return "unknown";
811 #else
812  const char *msg;
813  switch (error_number)
814  {
815  case NERR_NetNotStarted:
816  return "The workstation driver is not installed.";
817  case NERR_UnknownServer:
818  return "The server could not be located.";
819  case NERR_ShareMem:
820  return "An internal error occurred. The network cannot access a shared memory segment.";
821  case NERR_NoNetworkResource:
822  return "A network resource shortage occurred.";
823  case NERR_RemoteOnly:
824  return "This operation is not supported on workstations.";
825  case NERR_DevNotRedirected:
826  return "The device is not connected.";
827  case NERR_ServerNotStarted:
828  return "The Server service is not started.";
829  case NERR_ItemNotFound:
830  return "The queue is empty.";
831  case NERR_UnknownDevDir:
832  return "The device or directory does not exist.";
833  case NERR_RedirectedPath:
834  return "The operation is invalid on a redirected resource.";
835  case NERR_DuplicateShare:
836  return "The name has already been shared.";
837  case NERR_NoRoom:
838  return "The server is currently out of the requested resource.";
839  case NERR_TooManyItems:
840  return "Requested addition of items exceeds the maximum allowed.";
841  case NERR_InvalidMaxUsers:
842  return "The Peer service supports only two simultaneous users.";
843  case NERR_BufTooSmall:
844  return "The API return buffer is too small.";
845  case NERR_RemoteErr:
846  return "A remote API error occurred.";
847  case NERR_LanmanIniError:
848  return "An error occurred when opening or reading the configuration file.";
849  case NERR_NetworkError:
850  return "A general network error occurred.";
851  case NERR_WkstaInconsistentState:
852  return "The Workstation service is in an inconsistent state. Restart the computer before restarting the Workstation service.";
853  case NERR_WkstaNotStarted:
854  return "The Workstation service has not been started.";
855  case NERR_BrowserNotStarted:
856  return "The requested information is not available.";
857  case NERR_InternalError:
858  return "An internal error occurred.";
859  case NERR_BadTransactConfig:
860  return "The server is not configured for transactions.";
861  case NERR_InvalidAPI:
862  return "The requested API is not supported on the remote server.";
863  case NERR_BadEventName:
864  return "The event name is invalid.";
865  case NERR_DupNameReboot:
866  return "The computer name already exists on the network. Change it and restart the computer.";
867  case NERR_CfgCompNotFound:
868  return "The specified component could not be found in the configuration information.";
869  case NERR_CfgParamNotFound:
870  return "The specified parameter could not be found in the configuration information.";
871  case NERR_LineTooLong:
872  return "A line in the configuration file is too long.";
873  case NERR_QNotFound:
874  return "The printer does not exist.";
875  case NERR_JobNotFound:
876  return "The print job does not exist.";
877  case NERR_DestNotFound:
878  return "The printer destination cannot be found.";
879  case NERR_DestExists:
880  return "The printer destination already exists.";
881  case NERR_QExists:
882  return "The printer queue already exists.";
883  case NERR_QNoRoom:
884  return "No more printers can be added.";
885  case NERR_JobNoRoom:
886  return "No more print jobs can be added.";
887  case NERR_DestNoRoom:
888  return "No more printer destinations can be added.";
889  case NERR_DestIdle:
890  return "This printer destination is idle and cannot accept control operations.";
891  case NERR_DestInvalidOp:
892  return "This printer destination request contains an invalid control function.";
893  case NERR_ProcNoRespond:
894  return "The print processor is not responding.";
895  case NERR_SpoolerNotLoaded:
896  return "The spooler is not running.";
897  case NERR_DestInvalidState:
898  return "This operation cannot be performed on the print destination in its current state.";
899  case NERR_QInvalidState:
900  return "This operation cannot be performed on the printer queue in its current state.";
901  case NERR_JobInvalidState:
902  return "This operation cannot be performed on the print job in its current state.";
903  case NERR_SpoolNoMemory:
904  return "A spooler memory allocation failure occurred.";
905  case NERR_DriverNotFound:
906  return "The device driver does not exist.";
907  case NERR_DataTypeInvalid:
908  return "The data type is not supported by the print processor.";
909  case NERR_ProcNotFound:
910  return "The print processor is not installed.";
911  case NERR_ServiceTableLocked:
912  return "The service database is locked.";
913  case NERR_ServiceTableFull:
914  return "The service table is full.";
915  case NERR_ServiceInstalled:
916  return "The requested service has already been started.";
917  case NERR_ServiceEntryLocked:
918  return "The service does not respond to control actions.";
919  case NERR_ServiceNotInstalled:
920  return "The service has not been started.";
921  case NERR_BadServiceName:
922  return "The service name is invalid.";
923  case NERR_ServiceCtlTimeout:
924  return "The service is not responding to the control function.";
925  case NERR_ServiceCtlBusy:
926  return "The service control is busy.";
927  case NERR_BadServiceProgName:
928  return "The configuration file contains an invalid service program name.";
929  case NERR_ServiceNotCtrl:
930  return "The service could not be controlled in its present state.";
931  case NERR_ServiceKillProc:
932  return "The service ended abnormally.";
933  case NERR_ServiceCtlNotValid:
934  return "The requested pause or stop is not valid for this service.";
935  case NERR_NotInDispatchTbl:
936  return "The service control dispatcher could not find the service name in the dispatch table.";
937  case NERR_BadControlRecv:
938  return "The service control dispatcher pipe read failed.";
939  case NERR_ServiceNotStarting:
940  return "A thread for the new service could not be created.";
941  case NERR_AlreadyLoggedOn:
942  return "This workstation is already logged on to the local-area network.";
943  case NERR_NotLoggedOn:
944  return "The workstation is not logged on to the local-area network.";
945  case NERR_BadUsername:
946  return "The user name or group name parameter is invalid.";
947  case NERR_BadPassword:
948  return "The password parameter is invalid.";
949  case NERR_UnableToAddName_W:
950  return "@W The logon processor did not add the message alias.";
951  case NERR_UnableToAddName_F:
952  return "The logon processor did not add the message alias.";
953  case NERR_UnableToDelName_W:
954  return "@W The logoff processor did not delete the message alias.";
955  case NERR_UnableToDelName_F:
956  return "The logoff processor did not delete the message alias.";
957  case NERR_LogonsPaused:
958  return "Network logons are paused.";
959  case NERR_LogonServerConflict:
960  return "A centralized logon-server conflict occurred.";
961  case NERR_LogonNoUserPath:
962  return "The server is configured without a valid user path.";
963  case NERR_LogonScriptError:
964  return "An error occurred while loading or running the logon script.";
965  case NERR_StandaloneLogon:
966  return "The logon server was not specified. Your computer will be logged on as STANDALONE.";
967  case NERR_LogonServerNotFound:
968  return "The logon server could not be found.";
969  case NERR_LogonDomainExists:
970  return "There is already a logon domain for this computer.";
971  case NERR_NonValidatedLogon:
972  return "The logon server could not validate the logon.";
973  case NERR_ACFNotFound:
974  return "The security database could not be found.";
975  case NERR_GroupNotFound:
976  return "The group name could not be found.";
977  case NERR_UserNotFound:
978  return "The user name could not be found.";
979  case NERR_ResourceNotFound:
980  return "The resource name could not be found.";
981  case NERR_GroupExists:
982  return "The group already exists.";
983  case NERR_UserExists:
984  return "The user account already exists.";
985  case NERR_ResourceExists:
986  return "The resource permission list already exists.";
987  case NERR_NotPrimary:
988  return "This operation is only allowed on the primary domain controller of the domain.";
989  case NERR_ACFNotLoaded:
990  return "The security database has not been started.";
991  case NERR_ACFNoRoom:
992  return "There are too many names in the user accounts database.";
993  case NERR_ACFFileIOFail:
994  return "A disk I/O failure occurred.";
995  case NERR_ACFTooManyLists:
996  return "The limit of 64 entries per resource was exceeded.";
997  case NERR_UserLogon:
998  return "Deleting a user with a session is not allowed.";
999  case NERR_ACFNoParent:
1000  return "The parent directory could not be located.";
1001  case NERR_CanNotGrowSegment:
1002  return "Unable to add to the security database session cache segment.";
1003  case NERR_SpeGroupOp:
1004  return "This operation is not allowed on this special group.";
1005  case NERR_NotInCache:
1006  return "This user is not cached in user accounts database session cache.";
1007  case NERR_UserInGroup:
1008  return "The user already belongs to this group.";
1009  case NERR_UserNotInGroup:
1010  return "The user does not belong to this group.";
1011  case NERR_AccountUndefined:
1012  return "This user account is undefined.";
1013  case NERR_AccountExpired:
1014  return "This user account has expired.";
1015  case NERR_InvalidWorkstation:
1016  return "The user is not allowed to log on from this workstation.";
1017  case NERR_InvalidLogonHours:
1018  return "The user is not allowed to log on at this time.";
1019  case NERR_PasswordExpired:
1020  return "The password of this user has expired.";
1021  case NERR_PasswordCantChange:
1022  return "The password of this user cannot change.";
1023  case NERR_PasswordHistConflict:
1024  return "This password cannot be used now.";
1025  case NERR_PasswordTooShort:
1026  return "The password does not meet the password policy requirements. Check the minimum password length, password complexity and password history requirements.";
1027  case NERR_PasswordTooRecent:
1028  return "The password of this user is too recent to change.";
1029  case NERR_InvalidDatabase:
1030  return "The security database is corrupted.";
1031  case NERR_DatabaseUpToDate:
1032  return "No updates are necessary to this replicant network/local security database.";
1033  case NERR_SyncRequired:
1034  return "This replicant database is outdated; synchronization is required.";
1035  case NERR_UseNotFound:
1036  return "The network connection could not be found.";
1037  case NERR_BadAsgType:
1038  return "This asg_type is invalid.";
1039  case NERR_DeviceIsShared:
1040  return "This device is currently being shared.";
1041  case NERR_NoComputerName:
1042  return "The computer name could not be added as a message alias. The name may already exist on the network.";
1043  case NERR_MsgAlreadyStarted:
1044  return "The Messenger service is already started.";
1045  case NERR_MsgInitFailed:
1046  return "The Messenger service failed to start.";
1047  case NERR_NameNotFound:
1048  return "The message alias could not be found on the network.";
1049  case NERR_AlreadyForwarded:
1050  return "This message alias has already been forwarded.";
1051  case NERR_AddForwarded:
1052  return "This message alias has been added but is still forwarded.";
1053  case NERR_AlreadyExists:
1054  return "This message alias already exists locally.";
1055  case NERR_TooManyNames:
1056  return "The maximum number of added message aliases has been exceeded.";
1057  case NERR_DelComputerName:
1058  return "The computer name could not be deleted.";
1059  case NERR_LocalForward:
1060  return "Messages cannot be forwarded back to the same workstation.";
1061  case NERR_GrpMsgProcessor:
1062  return "An error occurred in the domain message processor.";
1063  case NERR_PausedRemote:
1064  return "The message was sent, but the recipient has paused the Messenger service.";
1065  case NERR_BadReceive:
1066  return "The message was sent but not received.";
1067  case NERR_NameInUse:
1068  return "The message alias is currently in use. Try again later.";
1069  case NERR_MsgNotStarted:
1070  return "The Messenger service has not been started.";
1071  case NERR_NotLocalName:
1072  return "The name is not on the local computer.";
1073  case NERR_NoForwardName:
1074  return "The forwarded message alias could not be found on the network.";
1075  case NERR_RemoteFull:
1076  return "The message alias table on the remote station is full.";
1077  case NERR_NameNotForwarded:
1078  return "Messages for this alias are not currently being forwarded.";
1079  case NERR_TruncatedBroadcast:
1080  return "The broadcast message was truncated.";
1081  case NERR_InvalidDevice:
1082  return "This is an invalid device name.";
1083  case NERR_WriteFault:
1084  return "A write fault occurred.";
1085  case NERR_DuplicateName:
1086  return "A duplicate message alias exists on the network.";
1087  case NERR_DeleteLater:
1088  return "@W This message alias will be deleted later.";
1089  case NERR_IncompleteDel:
1090  return "The message alias was not successfully deleted from all networks.";
1091  case NERR_MultipleNets:
1092  return "This operation is not supported on computers with multiple networks.";
1093  case NERR_NetNameNotFound:
1094  return "This shared resource does not exist.";
1095  case NERR_DeviceNotShared:
1096  return "This device is not shared.";
1097  case NERR_ClientNameNotFound:
1098  return "A session does not exist with that computer name.";
1099  case NERR_FileIdNotFound:
1100  return "There is not an open file with that identification number.";
1101  case NERR_ExecFailure:
1102  return "A failure occurred when executing a remote administration command.";
1103  case NERR_TmpFile:
1104  return "A failure occurred when opening a remote temporary file.";
1105  case NERR_TooMuchData:
1106  return "The data returned from a remote administration command has been truncated to 64K.";
1107  case NERR_DeviceShareConflict:
1108  return "This device cannot be shared as both a spooled and a non-spooled resource.";
1109  case NERR_BrowserTableIncomplete:
1110  return "The information in the list of servers may be incorrect.";
1111  case NERR_NotLocalDomain:
1112  return "The computer is not active in this domain.";
1113 #ifdef NERR_IsDfsShare
1114 
1115  case NERR_IsDfsShare:
1116  return "The share must be removed from the Distributed File System before it can be deleted.";
1117 #endif
1118 
1119  case NERR_DevInvalidOpCode:
1120  return "The operation is invalid for this device.";
1121  case NERR_DevNotFound:
1122  return "This device cannot be shared.";
1123  case NERR_DevNotOpen:
1124  return "This device was not open.";
1125  case NERR_BadQueueDevString:
1126  return "This device name list is invalid.";
1127  case NERR_BadQueuePriority:
1128  return "The queue priority is invalid.";
1129  case NERR_NoCommDevs:
1130  return "There are no shared communication devices.";
1131  case NERR_QueueNotFound:
1132  return "The queue you specified does not exist.";
1133  case NERR_BadDevString:
1134  return "This list of devices is invalid.";
1135  case NERR_BadDev:
1136  return "The requested device is invalid.";
1137  case NERR_InUseBySpooler:
1138  return "This device is already in use by the spooler.";
1139  case NERR_CommDevInUse:
1140  return "This device is already in use as a communication device.";
1141  case NERR_InvalidComputer:
1142  return "This computer name is invalid.";
1143  case NERR_MaxLenExceeded:
1144  return "The string and prefix specified are too long.";
1145  case NERR_BadComponent:
1146  return "This path component is invalid.";
1147  case NERR_CantType:
1148  return "Could not determine the type of input.";
1149  case NERR_TooManyEntries:
1150  return "The buffer for types is not big enough.";
1151  case NERR_ProfileFileTooBig:
1152  return "Profile files cannot exceed 64K.";
1153  case NERR_ProfileOffset:
1154  return "The start offset is out of range.";
1155  case NERR_ProfileCleanup:
1156  return "The system cannot delete current connections to network resources.";
1157  case NERR_ProfileUnknownCmd:
1158  return "The system was unable to parse the command line in this file.";
1159  case NERR_ProfileLoadErr:
1160  return "An error occurred while loading the profile file.";
1161  case NERR_ProfileSaveErr:
1162  return "@W Errors occurred while saving the profile file. The profile was partially saved.";
1163  case NERR_LogOverflow:
1164  return "Log file %1 is full.";
1165  case NERR_LogFileChanged:
1166  return "This log file has changed between reads.";
1167  case NERR_LogFileCorrupt:
1168  return "Log file %1 is corrupt.";
1169  case NERR_SourceIsDir:
1170  return "The source path cannot be a directory.";
1171  case NERR_BadSource:
1172  return "The source path is illegal.";
1173  case NERR_BadDest:
1174  return "The destination path is illegal.";
1175  case NERR_DifferentServers:
1176  return "The source and destination paths are on different servers.";
1177  case NERR_RunSrvPaused:
1178  return "The Run server you requested is paused.";
1179  case NERR_ErrCommRunSrv:
1180  return "An error occurred when communicating with a Run server.";
1181  case NERR_ErrorExecingGhost:
1182  return "An error occurred when starting a background process.";
1183  case NERR_ShareNotFound:
1184  return "The shared resource you are connected to could not be found.";
1185  case NERR_InvalidLana:
1186  return "The LAN adapter number is invalid.";
1187  case NERR_OpenFiles:
1188  return "There are open files on the connection.";
1189  case NERR_ActiveConns:
1190  return "Active connections still exist.";
1191  case NERR_BadPasswordCore:
1192  return "This share name or password is invalid.";
1193  case NERR_DevInUse:
1194  return "The device is being accessed by an active process.";
1195  case NERR_LocalDrive:
1196  return "The drive letter is in use locally.";
1197  case NERR_AlertExists:
1198  return "The specified client is already registered for the specified event.";
1199  case NERR_TooManyAlerts:
1200  return "The alert table is full.";
1201  case NERR_NoSuchAlert:
1202  return "An invalid or nonexistent alert name was raised.";
1203  case NERR_BadRecipient:
1204  return "The alert recipient is invalid.";
1205  case NERR_AcctLimitExceeded:
1206  return "A user's session with this server has been deleted.";
1207  case NERR_InvalidLogSeek:
1208  return "The log file does not contain the requested record number.";
1209  case NERR_BadUasConfig:
1210  return "The user accounts database is not configured correctly.";
1211  case NERR_InvalidUASOp:
1212  return "This operation is not permitted when the Netlogon service is running.";
1213  case NERR_LastAdmin:
1214  return "This operation is not allowed on the last administrative account.";
1215  case NERR_DCNotFound:
1216  return "Could not find domain controller for this domain.";
1217  case NERR_LogonTrackingError:
1218  return "Could not set logon information for this user.";
1219  case NERR_NetlogonNotStarted:
1220  return "The Netlogon service has not been started.";
1221  case NERR_CanNotGrowUASFile:
1222  return "Unable to add to the user accounts database.";
1223  case NERR_TimeDiffAtDC:
1224  return "This server's clock is not synchronized with the primary domain controller's clock.";
1225  case NERR_PasswordMismatch:
1226  return "A password mismatch has been detected.";
1227  case NERR_NoSuchServer:
1228  return "The server identification does not specify a valid server.";
1229  case NERR_NoSuchSession:
1230  return "The session identification does not specify a valid session.";
1231  case NERR_NoSuchConnection:
1232  return "The connection identification does not specify a valid connection.";
1233  case NERR_TooManyServers:
1234  return "There is no space for another entry in the table of available servers.";
1235  case NERR_TooManySessions:
1236  return "The server has reached the maximum number of sessions it supports.";
1237  case NERR_TooManyConnections:
1238  return "The server has reached the maximum number of connections it supports.";
1239  case NERR_TooManyFiles:
1240  return "The server cannot open more files because it has reached its maximum number.";
1241  case NERR_NoAlternateServers:
1242  return "There are no alternate servers registered on this server.";
1243  case NERR_TryDownLevel:
1244  return "Try down-level (remote admin protocol) version of API instead.";
1245  case NERR_UPSDriverNotStarted:
1246  return "The UPS driver could not be accessed by the UPS service.";
1247  case NERR_UPSInvalidConfig:
1248  return "The UPS service is not configured correctly.";
1249  case NERR_UPSInvalidCommPort:
1250  return "The UPS service could not access the specified Comm Port.";
1251  case NERR_UPSSignalAsserted:
1252  return "The UPS indicated a line fail or low battery situation. Service not started.";
1253  case NERR_UPSShutdownFailed:
1254  return "The UPS service failed to perform a system shut down.";
1255  case NERR_BadDosRetCode:
1256  return "The program below returned an MS-DOS error code:";
1257  case NERR_ProgNeedsExtraMem:
1258  return "The program below needs more memory:";
1259  case NERR_BadDosFunction:
1260  return "The program below called an unsupported MS-DOS function:";
1261  case NERR_RemoteBootFailed:
1262  return "The workstation failed to boot.";
1263  case NERR_BadFileCheckSum:
1264  return "The file below is corrupt.";
1265  case NERR_NoRplBootSystem:
1266  return "No loader is specified in the boot-block definition file.";
1267  case NERR_RplLoadrNetBiosErr:
1268  return "NetBIOS returned an error: The NCB and SMB are dumped above.";
1269  case NERR_RplLoadrDiskErr:
1270  return "A disk I/O error occurred.";
1271  case NERR_ImageParamErr:
1272  return "Image parameter substitution failed.";
1273  case NERR_TooManyImageParams:
1274  return "Too many image parameters cross disk sector boundaries.";
1275  case NERR_NonDosFloppyUsed:
1276  return "The image was not generated from an MS-DOS diskette formatted with /S.";
1277  case NERR_RplBootRestart:
1278  return "Remote boot will be restarted later.";
1279  case NERR_RplSrvrCallFailed:
1280  return "The call to the Remoteboot server failed.";
1281  case NERR_CantConnectRplSrvr:
1282  return "Cannot connect to the Remoteboot server.";
1283  case NERR_CantOpenImageFile:
1284  return "Cannot open image file on the Remoteboot server.";
1285  case NERR_CallingRplSrvr:
1286  return "Connecting to the Remoteboot server...";
1287  case NERR_StartingRplBoot:
1288  return "Connecting to the Remoteboot server...";
1289  case NERR_RplBootServiceTerm:
1290  return "Remote boot service was stopped; check the error log for the cause of the problem.";
1291  case NERR_RplBootStartFailed:
1292  return "Remote boot startup failed; check the error log for the cause of the problem.";
1293  case NERR_RPL_CONNECTED:
1294  return "A second connection to a Remoteboot resource is not allowed.";
1295  case NERR_BrowserConfiguredToNotRun:
1296  return "The browser service was configured with MaintainServerList=No.";
1297  case NERR_RplNoAdaptersStarted:
1298  return "Service failed to start since none of the network adapters started with this service.";
1299  case NERR_RplBadRegistry:
1300  return "Service failed to start due to bad startup information in the registry.";
1301  case NERR_RplBadDatabase:
1302  return "Service failed to start because its database is absent or corrupt.";
1303  case NERR_RplRplfilesShare:
1304  return "Service failed to start because RPLFILES share is absent.";
1305  case NERR_RplNotRplServer:
1306  return "Service failed to start because RPLUSER group is absent.";
1307  case NERR_RplCannotEnum:
1308  return "Cannot enumerate service records.";
1309  case NERR_RplWkstaInfoCorrupted:
1310  return "Workstation record information has been corrupted.";
1311  case NERR_RplWkstaNotFound:
1312  return "Workstation record was not found.";
1313  case NERR_RplWkstaNameUnavailable:
1314  return "Workstation name is in use by some other workstation.";
1315  case NERR_RplProfileInfoCorrupted:
1316  return "Profile record information has been corrupted.";
1317  case NERR_RplProfileNotFound:
1318  return "Profile record was not found.";
1319  case NERR_RplProfileNameUnavailable:
1320  return "Profile name is in use by some other profile.";
1321  case NERR_RplProfileNotEmpty:
1322  return "There are workstations using this profile.";
1323  case NERR_RplConfigInfoCorrupted:
1324  return "Configuration record information has been corrupted.";
1325  case NERR_RplConfigNotFound:
1326  return "Configuration record was not found.";
1327  case NERR_RplAdapterInfoCorrupted:
1328  return "Adapter ID record information has been corrupted.";
1329  case NERR_RplInternal:
1330  return "An internal service error has occurred.";
1331  case NERR_RplVendorInfoCorrupted:
1332  return "Vendor ID record information has been corrupted.";
1333  case NERR_RplBootInfoCorrupted:
1334  return "Boot block record information has been corrupted.";
1335  case NERR_RplWkstaNeedsUserAcct:
1336  return "The user account for this workstation record is missing.";
1337  case NERR_RplNeedsRPLUSERAcct:
1338  return "The RPLUSER local group could not be found.";
1339  case NERR_RplBootNotFound:
1340  return "Boot block record was not found.";
1341  case NERR_RplIncompatibleProfile:
1342  return "Chosen profile is incompatible with this workstation.";
1343  case NERR_RplAdapterNameUnavailable:
1344  return "Chosen network adapter ID is in use by some other workstation.";
1345  case NERR_RplConfigNotEmpty:
1346  return "There are profiles using this configuration.";
1347  case NERR_RplBootInUse:
1348  return "There are workstations, profiles, or configurations using this boot block.";
1349  case NERR_RplBackupDatabase:
1350  return "Service failed to backup Remoteboot database.";
1351  case NERR_RplAdapterNotFound:
1352  return "Adapter record was not found.";
1353  case NERR_RplVendorNotFound:
1354  return "Vendor record was not found.";
1355  case NERR_RplVendorNameUnavailable:
1356  return "Vendor name is in use by some other vendor record.";
1357  case NERR_RplBootNameUnavailable:
1358  return "(boot name, vendor ID) is in use by some other boot block record.";
1359  case NERR_RplConfigNameUnavailable:
1360  return "Configuration name is in use by some other configuration.";
1361  case NERR_DfsInternalCorruption:
1362  return "The internal database maintained by the Dfs service is corrupt.";
1363  case NERR_DfsVolumeDataCorrupt:
1364  return "One of the records in the internal Dfs database is corrupt.";
1365  case NERR_DfsNoSuchVolume:
1366  return "There is no DFS name whose entry path matches the input Entry Path.";
1367  case NERR_DfsVolumeAlreadyExists:
1368  return "A root or link with the given name already exists.";
1369  case NERR_DfsAlreadyShared:
1370  return "The server share specified is already shared in the Dfs.";
1371  case NERR_DfsNoSuchShare:
1372  return "The indicated server share does not support the indicated DFS namespace.";
1373  case NERR_DfsNotALeafVolume:
1374  return "The operation is not valid on this portion of the namespace.";
1375  case NERR_DfsLeafVolume:
1376  return "The operation is not valid on this portion of the namespace.";
1377  case NERR_DfsVolumeHasMultipleServers:
1378  return "The operation is ambiguous because the link has multiple servers.";
1379  case NERR_DfsCantCreateJunctionPoint:
1380  return "Unable to create a link.";
1381  case NERR_DfsServerNotDfsAware:
1382  return "The server is not Dfs Aware.";
1383  case NERR_DfsBadRenamePath:
1384  return "The specified rename target path is invalid.";
1385  case NERR_DfsVolumeIsOffline:
1386  return "The specified DFS link is offline.";
1387  case NERR_DfsNoSuchServer:
1388  return "The specified server is not a server for this link.";
1389  case NERR_DfsCyclicalName:
1390  return "A cycle in the Dfs name was detected.";
1391  case NERR_DfsNotSupportedInServerDfs:
1392  return "The operation is not supported on a server-based Dfs.";
1393  case NERR_DfsDuplicateService:
1394  return "This link is already supported by the specified server-share.";
1395  case NERR_DfsCantRemoveLastServerShare:
1396  return "Can't remove the last server-share supporting this root or link.";
1397  case NERR_DfsVolumeIsInterDfs:
1398  return "The operation is not supported for an Inter-DFS link.";
1399  case NERR_DfsInconsistent:
1400  return "The internal state of the Dfs Service has become inconsistent.";
1401  case NERR_DfsServerUpgraded:
1402  return "The Dfs Service has been installed on the specified server.";
1403  case NERR_DfsDataIsIdentical:
1404  return "The Dfs data being reconciled is identical.";
1405  case NERR_DfsCantRemoveDfsRoot:
1406  return "The DFS root cannot be deleted. Uninstall DFS if required.";
1407  case NERR_DfsChildOrParentInDfs:
1408  return "A child or parent directory of the share is already in a Dfs.";
1409  case NERR_DfsInternalError:
1410  return "Dfs internal error.";
1411  /* the following are not defined in mingw */
1412 #if 0
1413 
1414  case NERR_SetupAlreadyJoined:
1415  return "This machine is already joined to a domain.";
1416  case NERR_SetupNotJoined:
1417  return "This machine is not currently joined to a domain.";
1418  case NERR_SetupDomainController:
1419  return "This machine is a domain controller and cannot be unjoined from a domain.";
1420  case NERR_DefaultJoinRequired:
1421  return "The destination domain controller does not support creating machine accounts in OUs.";
1422  case NERR_InvalidWorkgroupName:
1423  return "The specified workgroup name is invalid.";
1424  case NERR_NameUsesIncompatibleCodePage:
1425  return "The specified computer name is incompatible with the default language used on the domain controller.";
1426  case NERR_ComputerAccountNotFound:
1427  return "The specified computer account could not be found.";
1428  case NERR_PersonalSku:
1429  return "This version of Windows cannot be joined to a domain.";
1430  case NERR_PasswordMustChange:
1431  return "The password must change at the next logon.";
1432  case NERR_AccountLockedOut:
1433  return "The account is locked out.";
1434  case NERR_PasswordTooLong:
1435  return "The password is too long.";
1436  case NERR_PasswordNotComplexEnough:
1437  return "The password does not meet the complexity policy.";
1438  case NERR_PasswordFilterError:
1439  return "The password does not meet the requirements of the password filter DLLs.";
1440 #endif
1441 
1442  }
1443  msg = strerror (error_number);
1444  if (msg == NULL)
1445  msg = "unknown";
1446 
1447  return msg;
1448 #endif //DBUS_WINCE
1449 }
1450 
1466 _dbus_command_for_pid (unsigned long pid,
1467  DBusString *str,
1468  int max_len,
1469  DBusError *error)
1470 {
1471  // FIXME
1472  return FALSE;
1473 }
1474 
1475 /*
1476  * replaces the term DBUS_PREFIX in configure_time_path by the
1477  * current dbus installation directory. On unix this function is a noop
1478  *
1479  * @param configure_time_path
1480  * @return real path
1481  */
1482 const char *
1483 _dbus_replace_install_prefix (const char *configure_time_path)
1484 {
1485 #ifndef DBUS_PREFIX
1486  return configure_time_path;
1487 #else
1488  static char retval[1000];
1489  static char runtime_prefix[1000];
1490  int len = 1000;
1491  int i;
1492 
1493  if (!configure_time_path)
1494  return NULL;
1495 
1496  if ((!_dbus_get_install_root(runtime_prefix, len) ||
1497  strncmp (configure_time_path, DBUS_PREFIX "/",
1498  strlen (DBUS_PREFIX) + 1))) {
1499  strncpy (retval, configure_time_path, sizeof (retval) - 1);
1500  /* strncpy does not guarantee to 0-terminate the string */
1501  retval[sizeof (retval) - 1] = '\0';
1502  } else {
1503  size_t remaining;
1504 
1505  strncpy (retval, runtime_prefix, sizeof (retval) - 1);
1506  retval[sizeof (retval) - 1] = '\0';
1507  remaining = sizeof (retval) - 1 - strlen (retval);
1508  strncat (retval,
1509  configure_time_path + strlen (DBUS_PREFIX) + 1,
1510  remaining);
1511  }
1512 
1513  /* Somehow, in some situations, backslashes get collapsed in the string.
1514  * Since windows C library accepts both forward and backslashes as
1515  * path separators, convert all backslashes to forward slashes.
1516  */
1517 
1518  for(i = 0; retval[i] != '\0'; i++) {
1519  if(retval[i] == '\\')
1520  retval[i] = '/';
1521  }
1522  return retval;
1523 #endif
1524 }
1525 
1532 static const char *
1533 _dbus_windows_get_datadir (void)
1534 {
1535  return _dbus_replace_install_prefix(DBUS_DATADIR);
1536 }
1537 
1538 #undef DBUS_DATADIR
1539 #define DBUS_DATADIR _dbus_windows_get_datadir ()
1540 
1541 
1542 #define DBUS_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
1543 #define DBUS_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"
1544 
1563 {
1564  const char *common_progs;
1565  DBusString servicedir_path;
1566 
1567  if (!_dbus_string_init (&servicedir_path))
1568  return FALSE;
1569 
1570 #ifdef DBUS_WINCE
1571  {
1572  /* On Windows CE, we adjust datadir dynamically to installation location. */
1573  const char *data_dir = _dbus_getenv ("DBUS_DATADIR");
1574 
1575  if (data_dir != NULL)
1576  {
1577  if (!_dbus_string_append (&servicedir_path, data_dir))
1578  goto oom;
1579 
1580  if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
1581  goto oom;
1582  }
1583  }
1584 #else
1585 /*
1586  the code for accessing services requires absolute base pathes
1587  in case DBUS_DATADIR is relative make it absolute
1588 */
1589 #ifdef DBUS_WIN
1590  {
1591  DBusString p;
1592 
1593  _dbus_string_init_const (&p, DBUS_DATADIR);
1594 
1595  if (!_dbus_path_is_absolute (&p))
1596  {
1597  char install_root[1000];
1598  if (_dbus_get_install_root (install_root, sizeof(install_root)))
1599  if (!_dbus_string_append (&servicedir_path, install_root))
1600  goto oom;
1601  }
1602  }
1603 #endif
1604  if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR))
1605  goto oom;
1606 
1607  if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
1608  goto oom;
1609 #endif
1610 
1611  common_progs = _dbus_getenv ("CommonProgramFiles");
1612 
1613  if (common_progs != NULL)
1614  {
1615  if (!_dbus_string_append (&servicedir_path, common_progs))
1616  goto oom;
1617 
1618  if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
1619  goto oom;
1620  }
1621 
1622  if (!_dbus_split_paths_and_append (&servicedir_path,
1623  DBUS_STANDARD_SESSION_SERVICEDIR,
1624  dirs))
1625  goto oom;
1626 
1627  _dbus_string_free (&servicedir_path);
1628  return TRUE;
1629 
1630  oom:
1631  _dbus_string_free (&servicedir_path);
1632  return FALSE;
1633 }
1634 
1655 {
1656  *dirs = NULL;
1657  return TRUE;
1658 }
1659 
1660 static dbus_bool_t
1661 _dbus_get_config_file_name (DBusString *str,
1662  const char *basename)
1663 {
1664  DBusString tmp;
1665 
1666  if (!_dbus_string_append (str, _dbus_windows_get_datadir ()))
1667  return FALSE;
1668 
1669  _dbus_string_init_const (&tmp, "dbus-1");
1670 
1671  if (!_dbus_concat_dir_and_file (str, &tmp))
1672  return FALSE;
1673 
1674  _dbus_string_init_const (&tmp, basename);
1675 
1676  if (!_dbus_concat_dir_and_file (str, &tmp))
1677  return FALSE;
1678 
1679  return TRUE;
1680 }
1681 
1692 {
1693  return _dbus_get_config_file_name(str, "system.conf");
1694 }
1695 
1704 {
1705  return _dbus_get_config_file_name(str, "session.conf");
1706 }
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:935
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:226
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_bool_t _dbus_append_system_config_file(DBusString *str)
Append the absolute path of the system.conf file (there is no system bus on Windows so this can just ...
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.
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:701
dbus_bool_t _dbus_path_is_absolute(const DBusString *filename)
Checks whether the filename is an absolute path.
void _dbus_system_log(DBusSystemLogSeverity severity, const char *msg,...)
Log a message to the system log file (e.g.
Portable struct with stat() results.
Definition: dbus-sysdeps.h:504
#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:354
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.
void _dbus_directory_close(DBusDirIter *iter)
Closes a directory iteration.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
dbus_bool_t _dbus_directory_get_next_file(DBusDirIter *iter, DBusString *filename, DBusError *error)
Get next file in the directory.
unsigned long atime
Access time.
Definition: dbus-sysdeps.h:511
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.
DBusDirIter * _dbus_directory_open(const DBusString *filename, DBusError *error)
Open a directory to iterate over.
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_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:114
Internals of directory iterator.
unsigned long mode
File mode.
Definition: dbus-sysdeps.h:506
unsigned long dbus_pid_t
A process ID.
Definition: dbus-sysdeps.h:105
dbus_bool_t _dbus_change_to_daemon_user(const char *user, DBusError *error)
Changes the user and group the bus is running as.
dbus_gid_t gid
Group owning file.
Definition: dbus-sysdeps.h:509
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
Definition: dbus-memory.h:59
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_become_daemon(const DBusString *pidfile, const char *working_dir, DBusPipe *print_pid_pipe, DBusError *error, dbus_bool_t keep_umask)
Does the chdir, fork, setsid, etc.
void(* DBusSignalHandler)(int sig)
A UNIX signal handler.
Definition: dbus-sysdeps.h:548
Object representing an exception.
Definition: dbus-errors.h:48
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
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.
unsigned long ctime
Creation time.
Definition: dbus-sysdeps.h:513
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().
Definition: dbus-string.c:259
#define DBUS_GID_UNSET
an invalid GID used to represent an uninitialized dbus_gid_t field
Definition: dbus-sysdeps.h:116
#define TRUE
Expands to &quot;1&quot;.
unsigned long nlink
Number of hard links.
Definition: dbus-sysdeps.h:507
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_uid_t uid
User owning file.
Definition: dbus-sysdeps.h:508
void _dbus_system_logv(DBusSystemLogSeverity severity, const char *msg, va_list args)
Log a message to the system log file (e.g.
#define DBUS_ERROR_FAILED
A generic error; &quot;something went wrong&quot; - see the error message for more.
dbus_bool_t _dbus_verify_daemon_user(const char *user)
Verify that after the fork we can successfully change to this user.
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_stat(const DBusString *filename, DBusStat *statbuf, DBusError *error)
stat() wrapper.
const char * _dbus_strerror_from_errno(void)
Get error message from errno.
Definition: dbus-sysdeps.c:749
const char * _dbus_error_from_system_errno(void)
Converts the current system errno value into a DBusError name.
Definition: dbus-sysdeps.c:682
void _dbus_set_signal_handler(int sig, DBusSignalHandler handler)
Installs a UNIX signal handler.
A node in a linked list.
Definition: dbus-list.h:34
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_windows_user_is_process_owner(const char *windows_sid)
Checks to see if the Windows user SID matches the owner of the process.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define FALSE
Expands to &quot;0&quot;.
unsigned long mtime
Modify time.
Definition: dbus-sysdeps.h:512
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.
Definition: dbus-string.c:802
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:1375
unsigned long dbus_gid_t
A group ID.
Definition: dbus-sysdeps.h:109
unsigned long size
Size of file.
Definition: dbus-sysdeps.h:510
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.
dbus_bool_t _dbus_append_session_config_file(DBusString *str)
Append the absolute path of the session.conf file.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition: dbus-sysdeps.c:185
unsigned long dbus_uid_t
A user ID.
Definition: dbus-sysdeps.h:107
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_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
Definition: dbus-errors.c:329