Merge branch 'master' of ssh://rhabacker@git.freedesktop.org/git/dbus/dbus
[platform/upstream/dbus.git] / dbus / 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
38 #include <io.h>
39 #include <sys/stat.h>
40 #include <aclapi.h>
41 #include <winsock2.h>
42
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <fcntl.h>
46 #if HAVE_ERRNO_H
47 #include <errno.h>
48 #endif
49 #include <winsock2.h>   // WSA error codes
50
51 /**
52  * Does the chdir, fork, setsid, etc. to become a daemon process.
53  *
54  * @param pidfile #NULL, or pidfile to create
55  * @param print_pid_fd file descriptor to print daemon's pid to, or -1 for none
56  * @param error return location for errors
57  * @param keep_umask #TRUE to keep the original umask
58  * @returns #FALSE on failure
59  */
60 dbus_bool_t
61 _dbus_become_daemon (const DBusString *pidfile,
62                      DBusPipe         *print_pid_pipe,
63                      DBusError        *error,
64                      dbus_bool_t       keep_umask)
65 {
66   return TRUE;
67 }
68
69 /**
70  * Creates a file containing the process ID.
71  *
72  * @param filename the filename to write to
73  * @param pid our process ID
74  * @param error return location for errors
75  * @returns #FALSE on failure
76  */
77 static dbus_bool_t
78 _dbus_write_pid_file (const DBusString *filename,
79                       unsigned long     pid,
80                       DBusError        *error)
81 {
82   const char *cfilename;
83   HANDLE hnd;
84   char pidstr[20];
85   int total;
86   int bytes_to_write;
87
88   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
89
90   cfilename = _dbus_string_get_const_data (filename);
91
92   hnd = CreateFileA (cfilename, GENERIC_WRITE,
93                      FILE_SHARE_READ | FILE_SHARE_WRITE,
94                      NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,
95                      INVALID_HANDLE_VALUE);
96   if (hnd == INVALID_HANDLE_VALUE)
97     {
98       char *emsg = _dbus_win_error_string (GetLastError ());
99       dbus_set_error (error, _dbus_win_error_from_last_error (),
100                       "Could not create PID file %s: %s",
101                       cfilename, emsg);
102       _dbus_win_free_error_string (emsg);
103       return FALSE;
104     }
105
106   if (snprintf (pidstr, sizeof (pidstr), "%lu\n", pid) < 0)
107     {
108       dbus_set_error (error, _dbus_error_from_system_errno (),
109                       "Failed to format PID for \"%s\": %s", cfilename,
110                       _dbus_strerror_from_errno ());
111       CloseHandle (hnd);
112       return FALSE;
113     }
114
115   total = 0;
116   bytes_to_write = strlen (pidstr);;
117
118   while (total < bytes_to_write)
119     {
120       DWORD bytes_written;
121       BOOL res;
122
123       res = WriteFile (hnd, pidstr + total, bytes_to_write - total,
124                        &bytes_written, NULL);
125
126       if (res == 0 || bytes_written <= 0)
127         {
128           char *emsg = _dbus_win_error_string (GetLastError ());
129           dbus_set_error (error, _dbus_win_error_from_last_error (),
130                            "Could not write to %s: %s", cfilename, emsg);
131           _dbus_win_free_error_string (emsg);
132           CloseHandle (hnd);
133           return FALSE;
134         }
135
136       total += bytes_written;
137     }
138
139   if (CloseHandle (hnd) == 0)
140     {
141       char *emsg = _dbus_win_error_string (GetLastError ());
142       dbus_set_error (error, _dbus_win_error_from_last_error (),
143                        "Could not close file %s: %s",
144                       cfilename, emsg);
145       _dbus_win_free_error_string (emsg);
146
147       return FALSE;
148     }
149
150   return TRUE;
151 }
152
153 /**
154  * Writes the given pid_to_write to a pidfile (if non-NULL) and/or to a
155  * pipe (if non-NULL). Does nothing if pidfile and print_pid_pipe are both
156  * NULL.
157  *
158  * @param pidfile the file to write to or #NULL
159  * @param print_pid_pipe the pipe to write to or #NULL
160  * @param pid_to_write the pid to write out
161  * @param error error on failure
162  * @returns FALSE if error is set
163  */
164 dbus_bool_t
165 _dbus_write_pid_to_file_and_pipe (const DBusString *pidfile,
166                                   DBusPipe         *print_pid_pipe,
167                                   dbus_pid_t        pid_to_write,
168                                   DBusError        *error)
169 {
170   if (pidfile)
171     {
172       _dbus_verbose ("writing pid file %s\n", _dbus_string_get_const_data (pidfile));
173       if (!_dbus_write_pid_file (pidfile,
174                                  pid_to_write,
175                                  error))
176         {
177           _dbus_verbose ("pid file write failed\n");
178           _DBUS_ASSERT_ERROR_IS_SET(error);
179           return FALSE;
180         }
181     }
182   else
183     {
184       _dbus_verbose ("No pid file requested\n");
185     }
186
187   if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
188     {
189       DBusString pid;
190       int bytes;
191
192       _dbus_verbose ("writing our pid to pipe %d\n", print_pid_pipe->fd_or_handle);
193
194       if (!_dbus_string_init (&pid))
195         {
196           _DBUS_SET_OOM (error);
197           return FALSE;
198         }
199
200       if (!_dbus_string_append_int (&pid, pid_to_write) ||
201           !_dbus_string_append (&pid, "\n"))
202         {
203           _dbus_string_free (&pid);
204           _DBUS_SET_OOM (error);
205           return FALSE;
206         }
207
208       bytes = _dbus_string_get_length (&pid);
209       if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
210         {
211           /* _dbus_pipe_write sets error only on failure, not short write */
212           if (error != NULL && !dbus_error_is_set(error))
213             {
214               dbus_set_error (error, DBUS_ERROR_FAILED,
215                               "Printing message bus PID: did not write enough bytes\n");
216             }
217           _dbus_string_free (&pid);
218           return FALSE;
219         }
220
221       _dbus_string_free (&pid);
222     }
223   else
224     {
225       _dbus_verbose ("No pid pipe to write to\n");
226     }
227
228   return TRUE;
229 }
230
231 /**
232  * Verify that after the fork we can successfully change to this user.
233  *
234  * @param user the username given in the daemon configuration
235  * @returns #TRUE if username is valid
236  */
237 dbus_bool_t
238 _dbus_verify_daemon_user (const char *user)
239 {
240   return TRUE;
241 }
242
243 /**
244  * Changes the user and group the bus is running as.
245  *
246  * @param user the user to become
247  * @param error return location for errors
248  * @returns #FALSE on failure
249  */
250 dbus_bool_t
251 _dbus_change_to_daemon_user  (const char    *user,
252                               DBusError     *error)
253 {
254   return TRUE;
255 }
256
257 void
258 _dbus_init_system_log (void)
259 {
260     // FIXME!
261 }
262
263 /**
264  * Log a message to the system log file (e.g. syslog on Unix).
265  *
266  * @param severity a severity value
267  * @param msg a printf-style format string
268  * @param args arguments for the format string
269  *
270  */
271 void
272 _dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...)
273 {
274   va_list args;
275
276   va_start (args, msg);
277
278   _dbus_system_logv (severity, msg, args);
279
280   va_end (args);
281 }
282
283 /**
284  * Log a message to the system log file (e.g. syslog on Unix).
285  *
286  * @param severity a severity value
287  * @param msg a printf-style format string
288  * @param args arguments for the format string
289  *
290  * If the FATAL severity is given, this function will terminate the program
291  * with an error code.
292  */
293 void
294 _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
295 {
296     // FIXME!
297 }
298
299 /** Installs a signal handler
300  *
301  * @param sig the signal to handle
302  * @param handler the handler
303  */
304 void
305 _dbus_set_signal_handler (int               sig,
306                           DBusSignalHandler handler)
307 {
308   _dbus_verbose ("_dbus_set_signal_handler() has to be implemented\n");
309 }
310
311 /**
312  * stat() wrapper.
313  *
314  * @param filename the filename to stat
315  * @param statbuf the stat info to fill in
316  * @param error return location for error
317  * @returns #FALSE if error was set
318  */
319 dbus_bool_t
320 _dbus_stat(const DBusString *filename,
321            DBusStat         *statbuf,
322            DBusError        *error)
323 {
324   const char *filename_c;
325   WIN32_FILE_ATTRIBUTE_DATA wfad;
326   char *lastdot;
327   DWORD rc;
328
329   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
330
331   filename_c = _dbus_string_get_const_data (filename);
332
333   if (!GetFileAttributesExA (filename_c, GetFileExInfoStandard, &wfad))
334     {
335       _dbus_win_set_error_from_win_error (error, GetLastError ());
336       return FALSE;
337     }
338
339   if (wfad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
340     statbuf->mode = _S_IFDIR;
341   else
342     statbuf->mode = _S_IFREG;
343
344   statbuf->mode |= _S_IREAD;
345   if (wfad.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
346     statbuf->mode |= _S_IWRITE;
347
348   lastdot = strrchr (filename_c, '.');
349   if (lastdot && stricmp (lastdot, ".exe") == 0)
350     statbuf->mode |= _S_IEXEC;
351
352   statbuf->mode |= (statbuf->mode & 0700) >> 3;
353   statbuf->mode |= (statbuf->mode & 0700) >> 6;
354
355   statbuf->nlink = 1;
356
357 #ifdef ENABLE_UID_TO_SID
358   {
359     PSID owner_sid, group_sid;
360     PSECURITY_DESCRIPTOR sd;
361
362     sd = NULL;
363     rc = GetNamedSecurityInfo ((char *) filename_c, SE_FILE_OBJECT,
364                                OWNER_SECURITY_INFORMATION |
365                                GROUP_SECURITY_INFORMATION,
366                                &owner_sid, &group_sid,
367                                NULL, NULL,
368                                &sd);
369     if (rc != ERROR_SUCCESS)
370       {
371         _dbus_win_set_error_from_win_error (error, rc);
372         if (sd != NULL)
373           LocalFree (sd);
374         return FALSE;
375       }
376     
377     /* FIXME */
378     statbuf->uid = _dbus_win_sid_to_uid_t (owner_sid);
379     statbuf->gid = _dbus_win_sid_to_uid_t (group_sid);
380
381     LocalFree (sd);
382   }
383 #else
384   statbuf->uid = DBUS_UID_UNSET;
385   statbuf->gid = DBUS_GID_UNSET;
386 #endif
387
388   statbuf->size = ((dbus_int64_t) wfad.nFileSizeHigh << 32) + wfad.nFileSizeLow;
389
390   statbuf->atime =
391     (((dbus_int64_t) wfad.ftLastAccessTime.dwHighDateTime << 32) +
392      wfad.ftLastAccessTime.dwLowDateTime) / 10000000 - DBUS_INT64_CONSTANT (116444736000000000);
393
394   statbuf->mtime =
395     (((dbus_int64_t) wfad.ftLastWriteTime.dwHighDateTime << 32) +
396      wfad.ftLastWriteTime.dwLowDateTime) / 10000000 - DBUS_INT64_CONSTANT (116444736000000000);
397
398   statbuf->ctime =
399     (((dbus_int64_t) wfad.ftCreationTime.dwHighDateTime << 32) +
400      wfad.ftCreationTime.dwLowDateTime) / 10000000 - DBUS_INT64_CONSTANT (116444736000000000);
401
402   return TRUE;
403 }
404
405
406 /* This file is part of the KDE project
407 Copyright (C) 2000 Werner Almesberger
408
409 libc/sys/linux/sys/dirent.h - Directory entry as returned by readdir
410
411 This program is free software; you can redistribute it and/or
412 modify it under the terms of the GNU Library General Public
413 License as published by the Free Software Foundation; either
414 version 2 of the License, or (at your option) any later version.
415
416 This program is distributed in the hope that it will be useful,
417 but WITHOUT ANY WARRANTY; without even the implied warranty of
418 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
419 Library General Public License for more details.
420
421 You should have received a copy of the GNU Library General Public License
422 along with this program; see the file COPYING.  If not, write to
423 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
424 Boston, MA 02110-1301, USA.
425 */
426 #define HAVE_NO_D_NAMLEN        /* no struct dirent->d_namlen */
427 #define HAVE_DD_LOCK            /* have locking mechanism */
428
429 #define MAXNAMLEN 255           /* sizeof(struct dirent.d_name)-1 */
430
431 #define __dirfd(dir) (dir)->dd_fd
432
433 /* struct dirent - same as Unix */
434 struct dirent
435   {
436     long d_ino;                    /* inode (always 1 in WIN32) */
437     off_t d_off;                /* offset to this dirent */
438     unsigned short d_reclen;    /* length of d_name */
439     char d_name[_MAX_FNAME+1];    /* filename (null terminated) */
440   };
441
442 /* typedef DIR - not the same as Unix */
443 typedef struct
444   {
445     HANDLE handle;              /* FindFirst/FindNext handle */
446     short offset;               /* offset into directory */
447     short finished;             /* 1 if there are not more files */
448     WIN32_FIND_DATAA fileinfo;  /* from FindFirst/FindNext */
449     char *dir;                  /* the dir we are reading */
450     struct dirent dent;         /* the dirent to return */
451   }
452 DIR;
453
454 /**********************************************************************
455 * Implement dirent-style opendir/readdir/closedir on Window 95/NT
456 *
457 * Functions defined are opendir(), readdir() and closedir() with the
458 * same prototypes as the normal dirent.h implementation.
459 *
460 * Does not implement telldir(), seekdir(), rewinddir() or scandir().
461 * The dirent struct is compatible with Unix, except that d_ino is
462 * always 1 and d_off is made up as we go along.
463 *
464 * Error codes are not available with errno but GetLastError.
465 *
466 * The DIR typedef is not compatible with Unix.
467 **********************************************************************/
468
469 static DIR * _dbus_opendir(const char *dir)
470 {
471   DIR *dp;
472   char *filespec;
473   HANDLE handle;
474   int index;
475
476   filespec = malloc(strlen(dir) + 2 + 1);
477   strcpy(filespec, dir);
478   index = strlen(filespec) - 1;
479   if (index >= 0 && (filespec[index] == '/' || filespec[index] == '\\'))
480     filespec[index] = '\0';
481   strcat(filespec, "\\*");
482
483   dp = (DIR *)malloc(sizeof(DIR));
484   dp->offset = 0;
485   dp->finished = 0;
486   dp->dir = strdup(dir);
487
488   handle = FindFirstFileA(filespec, &(dp->fileinfo));
489   if (handle == INVALID_HANDLE_VALUE)
490     {
491       if (GetLastError() == ERROR_NO_MORE_FILES)
492         dp->finished = 1;
493       else
494         return NULL;
495     }
496
497   dp->handle = handle;
498   free(filespec);
499
500   return dp;
501 }
502
503 static struct dirent * _dbus_readdir(DIR *dp)
504 {
505   int saved_err = GetLastError();
506
507   if (!dp || dp->finished)
508     return NULL;
509
510   if (dp->offset != 0)
511     {
512       if (FindNextFileA(dp->handle, &(dp->fileinfo)) == 0)
513         {
514           if (GetLastError() == ERROR_NO_MORE_FILES)
515             {
516               SetLastError(saved_err);
517               dp->finished = 1;
518             }
519           return NULL;
520         }
521     }
522   dp->offset++;
523   
524   strncpy(dp->dent.d_name, dp->fileinfo.cFileName, _MAX_FNAME);
525   dp->dent.d_ino = 1;
526   dp->dent.d_reclen = strlen(dp->dent.d_name);
527   dp->dent.d_off = dp->offset;
528   
529   return &(dp->dent);
530 }
531
532
533 static int _dbus_closedir(DIR *dp)
534 {
535   if (!dp)
536     return 0;
537   FindClose(dp->handle);
538   if (dp->dir)
539     free(dp->dir);
540   if (dp)
541     free(dp);
542
543   return 0;
544 }
545
546
547 /**
548  * Internals of directory iterator
549  */
550 struct DBusDirIter
551   {
552     DIR *d; /**< The DIR* from opendir() */
553
554   };
555
556 /**
557  * Open a directory to iterate over.
558  *
559  * @param filename the directory name
560  * @param error exception return object or #NULL
561  * @returns new iterator, or #NULL on error
562  */
563 DBusDirIter*
564 _dbus_directory_open (const DBusString *filename,
565                       DBusError        *error)
566 {
567   DIR *d;
568   DBusDirIter *iter;
569   const char *filename_c;
570
571   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
572
573   filename_c = _dbus_string_get_const_data (filename);
574
575   d = _dbus_opendir (filename_c);
576   if (d == NULL)
577     {
578       char *emsg = _dbus_win_error_string (GetLastError ());
579       dbus_set_error (error, _dbus_win_error_from_last_error (),
580                       "Failed to read directory \"%s\": %s",
581                       filename_c, emsg);
582       _dbus_win_free_error_string (emsg);
583       return NULL;
584     }
585   iter = dbus_new0 (DBusDirIter, 1);
586   if (iter == NULL)
587     {
588       _dbus_closedir (d);
589       dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
590                       "Could not allocate memory for directory iterator");
591       return NULL;
592     }
593
594   iter->d = d;
595
596   return iter;
597 }
598
599 /**
600  * Get next file in the directory. Will not return "." or ".."  on
601  * UNIX. If an error occurs, the contents of "filename" are
602  * undefined. The error is never set if the function succeeds.
603  *
604  * @todo for thread safety, I think we have to use
605  * readdir_r(). (GLib has the same issue, should file a bug.)
606  *
607  * @param iter the iterator
608  * @param filename string to be set to the next file in the dir
609  * @param error return location for error
610  * @returns #TRUE if filename was filled in with a new filename
611  */
612 dbus_bool_t
613 _dbus_directory_get_next_file (DBusDirIter      *iter,
614                                DBusString       *filename,
615                                DBusError        *error)
616 {
617   struct dirent *ent;
618
619   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
620
621 again:
622   SetLastError (0);
623   ent = _dbus_readdir (iter->d);
624   if (ent == NULL)
625     {
626       if (GetLastError() != 0)
627         {
628           char *emsg = _dbus_win_error_string (GetLastError ());
629           dbus_set_error (error, _dbus_win_error_from_last_error (),
630                           "Failed to get next in directory: %s", emsg);
631           _dbus_win_free_error_string (emsg);
632         }
633       return FALSE;
634     }
635   else if (ent->d_name[0] == '.' &&
636            (ent->d_name[1] == '\0' ||
637             (ent->d_name[1] == '.' && ent->d_name[2] == '\0')))
638     goto again;
639   else
640     {
641       _dbus_string_set_length (filename, 0);
642       if (!_dbus_string_append (filename, ent->d_name))
643         {
644           dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
645                           "No memory to read directory entry");
646           return FALSE;
647         }
648       else
649         return TRUE;
650     }
651 }
652
653 /**
654  * Closes a directory iteration.
655  */
656 void
657 _dbus_directory_close (DBusDirIter *iter)
658 {
659   _dbus_closedir (iter->d);
660   dbus_free (iter);
661 }
662
663 /**
664  * Checks whether the filename is an absolute path
665  *
666  * @param filename the filename
667  * @returns #TRUE if an absolute path
668  */
669 dbus_bool_t
670 _dbus_path_is_absolute (const DBusString *filename)
671 {
672   if (_dbus_string_get_length (filename) > 0)
673     return _dbus_string_get_byte (filename, 1) == ':'
674            || _dbus_string_get_byte (filename, 0) == '\\'
675            || _dbus_string_get_byte (filename, 0) == '/';
676   else
677     return FALSE;
678 }
679
680 /** @} */ /* End of DBusInternalsUtils functions */
681
682 /**
683  * @addtogroup DBusString
684  *
685  * @{
686  */
687 /**
688  * Get the directory name from a complete filename
689  * @param filename the filename
690  * @param dirname string to append directory name to
691  * @returns #FALSE if no memory
692  */
693 dbus_bool_t
694 _dbus_string_get_dirname(const DBusString *filename,
695                          DBusString       *dirname)
696 {
697   int sep;
698
699   _dbus_assert (filename != dirname);
700   _dbus_assert (filename != NULL);
701   _dbus_assert (dirname != NULL);
702
703   /* Ignore any separators on the end */
704   sep = _dbus_string_get_length (filename);
705   if (sep == 0)
706     return _dbus_string_append (dirname, "."); /* empty string passed in */
707
708   while (sep > 0 &&
709          (_dbus_string_get_byte (filename, sep - 1) == '/' ||
710           _dbus_string_get_byte (filename, sep - 1) == '\\'))
711     --sep;
712
713   _dbus_assert (sep >= 0);
714
715   if (sep == 0 ||
716       (sep == 2 &&
717        _dbus_string_get_byte (filename, 1) == ':' &&
718        isalpha (_dbus_string_get_byte (filename, 0))))
719     return _dbus_string_copy_len (filename, 0, sep + 1,
720                                   dirname, _dbus_string_get_length (dirname));
721
722   {
723     int sep1, sep2;
724     _dbus_string_find_byte_backward (filename, sep, '/', &sep1);
725     _dbus_string_find_byte_backward (filename, sep, '\\', &sep2);
726
727     sep = MAX (sep1, sep2);
728   }
729   if (sep < 0)
730     return _dbus_string_append (dirname, ".");
731
732   while (sep > 0 &&
733          (_dbus_string_get_byte (filename, sep - 1) == '/' ||
734           _dbus_string_get_byte (filename, sep - 1) == '\\'))
735     --sep;
736
737   _dbus_assert (sep >= 0);
738
739   if ((sep == 0 ||
740        (sep == 2 &&
741         _dbus_string_get_byte (filename, 1) == ':' &&
742         isalpha (_dbus_string_get_byte (filename, 0))))
743       &&
744       (_dbus_string_get_byte (filename, sep) == '/' ||
745        _dbus_string_get_byte (filename, sep) == '\\'))
746     return _dbus_string_copy_len (filename, 0, sep + 1,
747                                   dirname, _dbus_string_get_length (dirname));
748   else
749     return _dbus_string_copy_len (filename, 0, sep - 0,
750                                   dirname, _dbus_string_get_length (dirname));
751 }
752
753
754 /**
755  * Checks to see if the UNIX user ID matches the UID of
756  * the process. Should always return #FALSE on Windows.
757  *
758  * @param uid the UNIX user ID
759  * @returns #TRUE if this uid owns the process.
760  */
761 dbus_bool_t
762 _dbus_unix_user_is_process_owner (dbus_uid_t uid)
763 {
764   return FALSE;
765 }
766
767 dbus_bool_t _dbus_windows_user_is_process_owner (const char *windows_sid)
768 {
769   return TRUE;
770 }
771
772 /*=====================================================================
773   unix emulation functions - should be removed sometime in the future
774  =====================================================================*/
775
776 /**
777  * Checks to see if the UNIX user ID is at the console.
778  * Should always fail on Windows (set the error to
779  * #DBUS_ERROR_NOT_SUPPORTED).
780  *
781  * @param uid UID of person to check 
782  * @param error return location for errors
783  * @returns #TRUE if the UID is the same as the console user and there are no errors
784  */
785 dbus_bool_t
786 _dbus_unix_user_is_at_console (dbus_uid_t         uid,
787                                DBusError         *error)
788 {
789   dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
790                   "UNIX user IDs not supported on Windows\n");
791   return FALSE;
792 }
793
794
795 /**
796  * Parse a UNIX group from the bus config file. On Windows, this should
797  * simply always fail (just return #FALSE).
798  *
799  * @param groupname the groupname text
800  * @param gid_p place to return the gid
801  * @returns #TRUE on success
802  */
803 dbus_bool_t
804 _dbus_parse_unix_group_from_config (const DBusString  *groupname,
805                                     dbus_gid_t        *gid_p)
806 {
807   return FALSE;
808 }
809
810 /**
811  * Parse a UNIX user from the bus config file. On Windows, this should
812  * simply always fail (just return #FALSE).
813  *
814  * @param username the username text
815  * @param uid_p place to return the uid
816  * @returns #TRUE on success
817  */
818 dbus_bool_t
819 _dbus_parse_unix_user_from_config (const DBusString  *username,
820                                    dbus_uid_t        *uid_p)
821 {
822   return FALSE;
823 }
824
825
826 /**
827  * Gets all groups corresponding to the given UNIX user ID. On UNIX,
828  * just calls _dbus_groups_from_uid(). On Windows, should always
829  * fail since we don't know any UNIX groups.
830  *
831  * @param uid the UID
832  * @param group_ids return location for array of group IDs
833  * @param n_group_ids return location for length of returned array
834  * @returns #TRUE if the UID existed and we got some credentials
835  */
836 dbus_bool_t
837 _dbus_unix_groups_from_uid (dbus_uid_t            uid,
838                             dbus_gid_t          **group_ids,
839                             int                  *n_group_ids)
840 {
841   return FALSE;
842 }
843
844
845
846 /** @} */ /* DBusString stuff */
847
848 /************************************************************************
849  
850  error handling
851  
852  ************************************************************************/
853
854
855
856
857
858 /* lan manager error codes */
859 const char*
860 _dbus_lm_strerror(int error_number)
861 {
862 #ifdef DBUS_WINCE
863   // TODO
864   return "unknown";
865 #else
866   const char *msg;
867   switch (error_number)
868     {
869     case NERR_NetNotStarted:
870       return "The workstation driver is not installed.";
871     case NERR_UnknownServer:
872       return "The server could not be located.";
873     case NERR_ShareMem:
874       return "An internal error occurred. The network cannot access a shared memory segment.";
875     case NERR_NoNetworkResource:
876       return "A network resource shortage occurred.";
877     case NERR_RemoteOnly:
878       return "This operation is not supported on workstations.";
879     case NERR_DevNotRedirected:
880       return "The device is not connected.";
881     case NERR_ServerNotStarted:
882       return "The Server service is not started.";
883     case NERR_ItemNotFound:
884       return "The queue is empty.";
885     case NERR_UnknownDevDir:
886       return "The device or directory does not exist.";
887     case NERR_RedirectedPath:
888       return "The operation is invalid on a redirected resource.";
889     case NERR_DuplicateShare:
890       return "The name has already been shared.";
891     case NERR_NoRoom:
892       return "The server is currently out of the requested resource.";
893     case NERR_TooManyItems:
894       return "Requested addition of items exceeds the maximum allowed.";
895     case NERR_InvalidMaxUsers:
896       return "The Peer service supports only two simultaneous users.";
897     case NERR_BufTooSmall:
898       return "The API return buffer is too small.";
899     case NERR_RemoteErr:
900       return "A remote API error occurred.";
901     case NERR_LanmanIniError:
902       return "An error occurred when opening or reading the configuration file.";
903     case NERR_NetworkError:
904       return "A general network error occurred.";
905     case NERR_WkstaInconsistentState:
906       return "The Workstation service is in an inconsistent state. Restart the computer before restarting the Workstation service.";
907     case NERR_WkstaNotStarted:
908       return "The Workstation service has not been started.";
909     case NERR_BrowserNotStarted:
910       return "The requested information is not available.";
911     case NERR_InternalError:
912       return "An internal error occurred.";
913     case NERR_BadTransactConfig:
914       return "The server is not configured for transactions.";
915     case NERR_InvalidAPI:
916       return "The requested API is not supported on the remote server.";
917     case NERR_BadEventName:
918       return "The event name is invalid.";
919     case NERR_DupNameReboot:
920       return "The computer name already exists on the network. Change it and restart the computer.";
921     case NERR_CfgCompNotFound:
922       return "The specified component could not be found in the configuration information.";
923     case NERR_CfgParamNotFound:
924       return "The specified parameter could not be found in the configuration information.";
925     case NERR_LineTooLong:
926       return "A line in the configuration file is too long.";
927     case NERR_QNotFound:
928       return "The printer does not exist.";
929     case NERR_JobNotFound:
930       return "The print job does not exist.";
931     case NERR_DestNotFound:
932       return "The printer destination cannot be found.";
933     case NERR_DestExists:
934       return "The printer destination already exists.";
935     case NERR_QExists:
936       return "The printer queue already exists.";
937     case NERR_QNoRoom:
938       return "No more printers can be added.";
939     case NERR_JobNoRoom:
940       return "No more print jobs can be added.";
941     case NERR_DestNoRoom:
942       return "No more printer destinations can be added.";
943     case NERR_DestIdle:
944       return "This printer destination is idle and cannot accept control operations.";
945     case NERR_DestInvalidOp:
946       return "This printer destination request contains an invalid control function.";
947     case NERR_ProcNoRespond:
948       return "The print processor is not responding.";
949     case NERR_SpoolerNotLoaded:
950       return "The spooler is not running.";
951     case NERR_DestInvalidState:
952       return "This operation cannot be performed on the print destination in its current state.";
953     case NERR_QInvalidState:
954       return "This operation cannot be performed on the printer queue in its current state.";
955     case NERR_JobInvalidState:
956       return "This operation cannot be performed on the print job in its current state.";
957     case NERR_SpoolNoMemory:
958       return "A spooler memory allocation failure occurred.";
959     case NERR_DriverNotFound:
960       return "The device driver does not exist.";
961     case NERR_DataTypeInvalid:
962       return "The data type is not supported by the print processor.";
963     case NERR_ProcNotFound:
964       return "The print processor is not installed.";
965     case NERR_ServiceTableLocked:
966       return "The service database is locked.";
967     case NERR_ServiceTableFull:
968       return "The service table is full.";
969     case NERR_ServiceInstalled:
970       return "The requested service has already been started.";
971     case NERR_ServiceEntryLocked:
972       return "The service does not respond to control actions.";
973     case NERR_ServiceNotInstalled:
974       return "The service has not been started.";
975     case NERR_BadServiceName:
976       return "The service name is invalid.";
977     case NERR_ServiceCtlTimeout:
978       return "The service is not responding to the control function.";
979     case NERR_ServiceCtlBusy:
980       return "The service control is busy.";
981     case NERR_BadServiceProgName:
982       return "The configuration file contains an invalid service program name.";
983     case NERR_ServiceNotCtrl:
984       return "The service could not be controlled in its present state.";
985     case NERR_ServiceKillProc:
986       return "The service ended abnormally.";
987     case NERR_ServiceCtlNotValid:
988       return "The requested pause or stop is not valid for this service.";
989     case NERR_NotInDispatchTbl:
990       return "The service control dispatcher could not find the service name in the dispatch table.";
991     case NERR_BadControlRecv:
992       return "The service control dispatcher pipe read failed.";
993     case NERR_ServiceNotStarting:
994       return "A thread for the new service could not be created.";
995     case NERR_AlreadyLoggedOn:
996       return "This workstation is already logged on to the local-area network.";
997     case NERR_NotLoggedOn:
998       return "The workstation is not logged on to the local-area network.";
999     case NERR_BadUsername:
1000       return "The user name or group name parameter is invalid.";
1001     case NERR_BadPassword:
1002       return "The password parameter is invalid.";
1003     case NERR_UnableToAddName_W:
1004       return "@W The logon processor did not add the message alias.";
1005     case NERR_UnableToAddName_F:
1006       return "The logon processor did not add the message alias.";
1007     case NERR_UnableToDelName_W:
1008       return "@W The logoff processor did not delete the message alias.";
1009     case NERR_UnableToDelName_F:
1010       return "The logoff processor did not delete the message alias.";
1011     case NERR_LogonsPaused:
1012       return "Network logons are paused.";
1013     case NERR_LogonServerConflict:
1014       return "A centralized logon-server conflict occurred.";
1015     case NERR_LogonNoUserPath:
1016       return "The server is configured without a valid user path.";
1017     case NERR_LogonScriptError:
1018       return "An error occurred while loading or running the logon script.";
1019     case NERR_StandaloneLogon:
1020       return "The logon server was not specified. Your computer will be logged on as STANDALONE.";
1021     case NERR_LogonServerNotFound:
1022       return "The logon server could not be found.";
1023     case NERR_LogonDomainExists:
1024       return "There is already a logon domain for this computer.";
1025     case NERR_NonValidatedLogon:
1026       return "The logon server could not validate the logon.";
1027     case NERR_ACFNotFound:
1028       return "The security database could not be found.";
1029     case NERR_GroupNotFound:
1030       return "The group name could not be found.";
1031     case NERR_UserNotFound:
1032       return "The user name could not be found.";
1033     case NERR_ResourceNotFound:
1034       return "The resource name could not be found.";
1035     case NERR_GroupExists:
1036       return "The group already exists.";
1037     case NERR_UserExists:
1038       return "The user account already exists.";
1039     case NERR_ResourceExists:
1040       return "The resource permission list already exists.";
1041     case NERR_NotPrimary:
1042       return "This operation is only allowed on the primary domain controller of the domain.";
1043     case NERR_ACFNotLoaded:
1044       return "The security database has not been started.";
1045     case NERR_ACFNoRoom:
1046       return "There are too many names in the user accounts database.";
1047     case NERR_ACFFileIOFail:
1048       return "A disk I/O failure occurred.";
1049     case NERR_ACFTooManyLists:
1050       return "The limit of 64 entries per resource was exceeded.";
1051     case NERR_UserLogon:
1052       return "Deleting a user with a session is not allowed.";
1053     case NERR_ACFNoParent:
1054       return "The parent directory could not be located.";
1055     case NERR_CanNotGrowSegment:
1056       return "Unable to add to the security database session cache segment.";
1057     case NERR_SpeGroupOp:
1058       return "This operation is not allowed on this special group.";
1059     case NERR_NotInCache:
1060       return "This user is not cached in user accounts database session cache.";
1061     case NERR_UserInGroup:
1062       return "The user already belongs to this group.";
1063     case NERR_UserNotInGroup:
1064       return "The user does not belong to this group.";
1065     case NERR_AccountUndefined:
1066       return "This user account is undefined.";
1067     case NERR_AccountExpired:
1068       return "This user account has expired.";
1069     case NERR_InvalidWorkstation:
1070       return "The user is not allowed to log on from this workstation.";
1071     case NERR_InvalidLogonHours:
1072       return "The user is not allowed to log on at this time.";
1073     case NERR_PasswordExpired:
1074       return "The password of this user has expired.";
1075     case NERR_PasswordCantChange:
1076       return "The password of this user cannot change.";
1077     case NERR_PasswordHistConflict:
1078       return "This password cannot be used now.";
1079     case NERR_PasswordTooShort:
1080       return "The password does not meet the password policy requirements. Check the minimum password length, password complexity and password history requirements.";
1081     case NERR_PasswordTooRecent:
1082       return "The password of this user is too recent to change.";
1083     case NERR_InvalidDatabase:
1084       return "The security database is corrupted.";
1085     case NERR_DatabaseUpToDate:
1086       return "No updates are necessary to this replicant network/local security database.";
1087     case NERR_SyncRequired:
1088       return "This replicant database is outdated; synchronization is required.";
1089     case NERR_UseNotFound:
1090       return "The network connection could not be found.";
1091     case NERR_BadAsgType:
1092       return "This asg_type is invalid.";
1093     case NERR_DeviceIsShared:
1094       return "This device is currently being shared.";
1095     case NERR_NoComputerName:
1096       return "The computer name could not be added as a message alias. The name may already exist on the network.";
1097     case NERR_MsgAlreadyStarted:
1098       return "The Messenger service is already started.";
1099     case NERR_MsgInitFailed:
1100       return "The Messenger service failed to start.";
1101     case NERR_NameNotFound:
1102       return "The message alias could not be found on the network.";
1103     case NERR_AlreadyForwarded:
1104       return "This message alias has already been forwarded.";
1105     case NERR_AddForwarded:
1106       return "This message alias has been added but is still forwarded.";
1107     case NERR_AlreadyExists:
1108       return "This message alias already exists locally.";
1109     case NERR_TooManyNames:
1110       return "The maximum number of added message aliases has been exceeded.";
1111     case NERR_DelComputerName:
1112       return "The computer name could not be deleted.";
1113     case NERR_LocalForward:
1114       return "Messages cannot be forwarded back to the same workstation.";
1115     case NERR_GrpMsgProcessor:
1116       return "An error occurred in the domain message processor.";
1117     case NERR_PausedRemote:
1118       return "The message was sent, but the recipient has paused the Messenger service.";
1119     case NERR_BadReceive:
1120       return "The message was sent but not received.";
1121     case NERR_NameInUse:
1122       return "The message alias is currently in use. Try again later.";
1123     case NERR_MsgNotStarted:
1124       return "The Messenger service has not been started.";
1125     case NERR_NotLocalName:
1126       return "The name is not on the local computer.";
1127     case NERR_NoForwardName:
1128       return "The forwarded message alias could not be found on the network.";
1129     case NERR_RemoteFull:
1130       return "The message alias table on the remote station is full.";
1131     case NERR_NameNotForwarded:
1132       return "Messages for this alias are not currently being forwarded.";
1133     case NERR_TruncatedBroadcast:
1134       return "The broadcast message was truncated.";
1135     case NERR_InvalidDevice:
1136       return "This is an invalid device name.";
1137     case NERR_WriteFault:
1138       return "A write fault occurred.";
1139     case NERR_DuplicateName:
1140       return "A duplicate message alias exists on the network.";
1141     case NERR_DeleteLater:
1142       return "@W This message alias will be deleted later.";
1143     case NERR_IncompleteDel:
1144       return "The message alias was not successfully deleted from all networks.";
1145     case NERR_MultipleNets:
1146       return "This operation is not supported on computers with multiple networks.";
1147     case NERR_NetNameNotFound:
1148       return "This shared resource does not exist.";
1149     case NERR_DeviceNotShared:
1150       return "This device is not shared.";
1151     case NERR_ClientNameNotFound:
1152       return "A session does not exist with that computer name.";
1153     case NERR_FileIdNotFound:
1154       return "There is not an open file with that identification number.";
1155     case NERR_ExecFailure:
1156       return "A failure occurred when executing a remote administration command.";
1157     case NERR_TmpFile:
1158       return "A failure occurred when opening a remote temporary file.";
1159     case NERR_TooMuchData:
1160       return "The data returned from a remote administration command has been truncated to 64K.";
1161     case NERR_DeviceShareConflict:
1162       return "This device cannot be shared as both a spooled and a non-spooled resource.";
1163     case NERR_BrowserTableIncomplete:
1164       return "The information in the list of servers may be incorrect.";
1165     case NERR_NotLocalDomain:
1166       return "The computer is not active in this domain.";
1167 #ifdef NERR_IsDfsShare
1168
1169     case NERR_IsDfsShare:
1170       return "The share must be removed from the Distributed File System before it can be deleted.";
1171 #endif
1172
1173     case NERR_DevInvalidOpCode:
1174       return "The operation is invalid for this device.";
1175     case NERR_DevNotFound:
1176       return "This device cannot be shared.";
1177     case NERR_DevNotOpen:
1178       return "This device was not open.";
1179     case NERR_BadQueueDevString:
1180       return "This device name list is invalid.";
1181     case NERR_BadQueuePriority:
1182       return "The queue priority is invalid.";
1183     case NERR_NoCommDevs:
1184       return "There are no shared communication devices.";
1185     case NERR_QueueNotFound:
1186       return "The queue you specified does not exist.";
1187     case NERR_BadDevString:
1188       return "This list of devices is invalid.";
1189     case NERR_BadDev:
1190       return "The requested device is invalid.";
1191     case NERR_InUseBySpooler:
1192       return "This device is already in use by the spooler.";
1193     case NERR_CommDevInUse:
1194       return "This device is already in use as a communication device.";
1195     case NERR_InvalidComputer:
1196       return "This computer name is invalid.";
1197     case NERR_MaxLenExceeded:
1198       return "The string and prefix specified are too long.";
1199     case NERR_BadComponent:
1200       return "This path component is invalid.";
1201     case NERR_CantType:
1202       return "Could not determine the type of input.";
1203     case NERR_TooManyEntries:
1204       return "The buffer for types is not big enough.";
1205     case NERR_ProfileFileTooBig:
1206       return "Profile files cannot exceed 64K.";
1207     case NERR_ProfileOffset:
1208       return "The start offset is out of range.";
1209     case NERR_ProfileCleanup:
1210       return "The system cannot delete current connections to network resources.";
1211     case NERR_ProfileUnknownCmd:
1212       return "The system was unable to parse the command line in this file.";
1213     case NERR_ProfileLoadErr:
1214       return "An error occurred while loading the profile file.";
1215     case NERR_ProfileSaveErr:
1216       return "@W Errors occurred while saving the profile file. The profile was partially saved.";
1217     case NERR_LogOverflow:
1218       return "Log file %1 is full.";
1219     case NERR_LogFileChanged:
1220       return "This log file has changed between reads.";
1221     case NERR_LogFileCorrupt:
1222       return "Log file %1 is corrupt.";
1223     case NERR_SourceIsDir:
1224       return "The source path cannot be a directory.";
1225     case NERR_BadSource:
1226       return "The source path is illegal.";
1227     case NERR_BadDest:
1228       return "The destination path is illegal.";
1229     case NERR_DifferentServers:
1230       return "The source and destination paths are on different servers.";
1231     case NERR_RunSrvPaused:
1232       return "The Run server you requested is paused.";
1233     case NERR_ErrCommRunSrv:
1234       return "An error occurred when communicating with a Run server.";
1235     case NERR_ErrorExecingGhost:
1236       return "An error occurred when starting a background process.";
1237     case NERR_ShareNotFound:
1238       return "The shared resource you are connected to could not be found.";
1239     case NERR_InvalidLana:
1240       return "The LAN adapter number is invalid.";
1241     case NERR_OpenFiles:
1242       return "There are open files on the connection.";
1243     case NERR_ActiveConns:
1244       return "Active connections still exist.";
1245     case NERR_BadPasswordCore:
1246       return "This share name or password is invalid.";
1247     case NERR_DevInUse:
1248       return "The device is being accessed by an active process.";
1249     case NERR_LocalDrive:
1250       return "The drive letter is in use locally.";
1251     case NERR_AlertExists:
1252       return "The specified client is already registered for the specified event.";
1253     case NERR_TooManyAlerts:
1254       return "The alert table is full.";
1255     case NERR_NoSuchAlert:
1256       return "An invalid or nonexistent alert name was raised.";
1257     case NERR_BadRecipient:
1258       return "The alert recipient is invalid.";
1259     case NERR_AcctLimitExceeded:
1260       return "A user's session with this server has been deleted.";
1261     case NERR_InvalidLogSeek:
1262       return "The log file does not contain the requested record number.";
1263     case NERR_BadUasConfig:
1264       return "The user accounts database is not configured correctly.";
1265     case NERR_InvalidUASOp:
1266       return "This operation is not permitted when the Netlogon service is running.";
1267     case NERR_LastAdmin:
1268       return "This operation is not allowed on the last administrative account.";
1269     case NERR_DCNotFound:
1270       return "Could not find domain controller for this domain.";
1271     case NERR_LogonTrackingError:
1272       return "Could not set logon information for this user.";
1273     case NERR_NetlogonNotStarted:
1274       return "The Netlogon service has not been started.";
1275     case NERR_CanNotGrowUASFile:
1276       return "Unable to add to the user accounts database.";
1277     case NERR_TimeDiffAtDC:
1278       return "This server's clock is not synchronized with the primary domain controller's clock.";
1279     case NERR_PasswordMismatch:
1280       return "A password mismatch has been detected.";
1281     case NERR_NoSuchServer:
1282       return "The server identification does not specify a valid server.";
1283     case NERR_NoSuchSession:
1284       return "The session identification does not specify a valid session.";
1285     case NERR_NoSuchConnection:
1286       return "The connection identification does not specify a valid connection.";
1287     case NERR_TooManyServers:
1288       return "There is no space for another entry in the table of available servers.";
1289     case NERR_TooManySessions:
1290       return "The server has reached the maximum number of sessions it supports.";
1291     case NERR_TooManyConnections:
1292       return "The server has reached the maximum number of connections it supports.";
1293     case NERR_TooManyFiles:
1294       return "The server cannot open more files because it has reached its maximum number.";
1295     case NERR_NoAlternateServers:
1296       return "There are no alternate servers registered on this server.";
1297     case NERR_TryDownLevel:
1298       return "Try down-level (remote admin protocol) version of API instead.";
1299     case NERR_UPSDriverNotStarted:
1300       return "The UPS driver could not be accessed by the UPS service.";
1301     case NERR_UPSInvalidConfig:
1302       return "The UPS service is not configured correctly.";
1303     case NERR_UPSInvalidCommPort:
1304       return "The UPS service could not access the specified Comm Port.";
1305     case NERR_UPSSignalAsserted:
1306       return "The UPS indicated a line fail or low battery situation. Service not started.";
1307     case NERR_UPSShutdownFailed:
1308       return "The UPS service failed to perform a system shut down.";
1309     case NERR_BadDosRetCode:
1310       return "The program below returned an MS-DOS error code:";
1311     case NERR_ProgNeedsExtraMem:
1312       return "The program below needs more memory:";
1313     case NERR_BadDosFunction:
1314       return "The program below called an unsupported MS-DOS function:";
1315     case NERR_RemoteBootFailed:
1316       return "The workstation failed to boot.";
1317     case NERR_BadFileCheckSum:
1318       return "The file below is corrupt.";
1319     case NERR_NoRplBootSystem:
1320       return "No loader is specified in the boot-block definition file.";
1321     case NERR_RplLoadrNetBiosErr:
1322       return "NetBIOS returned an error:      The NCB and SMB are dumped above.";
1323     case NERR_RplLoadrDiskErr:
1324       return "A disk I/O error occurred.";
1325     case NERR_ImageParamErr:
1326       return "Image parameter substitution failed.";
1327     case NERR_TooManyImageParams:
1328       return "Too many image parameters cross disk sector boundaries.";
1329     case NERR_NonDosFloppyUsed:
1330       return "The image was not generated from an MS-DOS diskette formatted with /S.";
1331     case NERR_RplBootRestart:
1332       return "Remote boot will be restarted later.";
1333     case NERR_RplSrvrCallFailed:
1334       return "The call to the Remoteboot server failed.";
1335     case NERR_CantConnectRplSrvr:
1336       return "Cannot connect to the Remoteboot server.";
1337     case NERR_CantOpenImageFile:
1338       return "Cannot open image file on the Remoteboot server.";
1339     case NERR_CallingRplSrvr:
1340       return "Connecting to the Remoteboot server...";
1341     case NERR_StartingRplBoot:
1342       return "Connecting to the Remoteboot server...";
1343     case NERR_RplBootServiceTerm:
1344       return "Remote boot service was stopped; check the error log for the cause of the problem.";
1345     case NERR_RplBootStartFailed:
1346       return "Remote boot startup failed; check the error log for the cause of the problem.";
1347     case NERR_RPL_CONNECTED:
1348       return "A second connection to a Remoteboot resource is not allowed.";
1349     case NERR_BrowserConfiguredToNotRun:
1350       return "The browser service was configured with MaintainServerList=No.";
1351     case NERR_RplNoAdaptersStarted:
1352       return "Service failed to start since none of the network adapters started with this service.";
1353     case NERR_RplBadRegistry:
1354       return "Service failed to start due to bad startup information in the registry.";
1355     case NERR_RplBadDatabase:
1356       return "Service failed to start because its database is absent or corrupt.";
1357     case NERR_RplRplfilesShare:
1358       return "Service failed to start because RPLFILES share is absent.";
1359     case NERR_RplNotRplServer:
1360       return "Service failed to start because RPLUSER group is absent.";
1361     case NERR_RplCannotEnum:
1362       return "Cannot enumerate service records.";
1363     case NERR_RplWkstaInfoCorrupted:
1364       return "Workstation record information has been corrupted.";
1365     case NERR_RplWkstaNotFound:
1366       return "Workstation record was not found.";
1367     case NERR_RplWkstaNameUnavailable:
1368       return "Workstation name is in use by some other workstation.";
1369     case NERR_RplProfileInfoCorrupted:
1370       return "Profile record information has been corrupted.";
1371     case NERR_RplProfileNotFound:
1372       return "Profile record was not found.";
1373     case NERR_RplProfileNameUnavailable:
1374       return "Profile name is in use by some other profile.";
1375     case NERR_RplProfileNotEmpty:
1376       return "There are workstations using this profile.";
1377     case NERR_RplConfigInfoCorrupted:
1378       return "Configuration record information has been corrupted.";
1379     case NERR_RplConfigNotFound:
1380       return "Configuration record was not found.";
1381     case NERR_RplAdapterInfoCorrupted:
1382       return "Adapter ID record information has been corrupted.";
1383     case NERR_RplInternal:
1384       return "An internal service error has occurred.";
1385     case NERR_RplVendorInfoCorrupted:
1386       return "Vendor ID record information has been corrupted.";
1387     case NERR_RplBootInfoCorrupted:
1388       return "Boot block record information has been corrupted.";
1389     case NERR_RplWkstaNeedsUserAcct:
1390       return "The user account for this workstation record is missing.";
1391     case NERR_RplNeedsRPLUSERAcct:
1392       return "The RPLUSER local group could not be found.";
1393     case NERR_RplBootNotFound:
1394       return "Boot block record was not found.";
1395     case NERR_RplIncompatibleProfile:
1396       return "Chosen profile is incompatible with this workstation.";
1397     case NERR_RplAdapterNameUnavailable:
1398       return "Chosen network adapter ID is in use by some other workstation.";
1399     case NERR_RplConfigNotEmpty:
1400       return "There are profiles using this configuration.";
1401     case NERR_RplBootInUse:
1402       return "There are workstations, profiles, or configurations using this boot block.";
1403     case NERR_RplBackupDatabase:
1404       return "Service failed to backup Remoteboot database.";
1405     case NERR_RplAdapterNotFound:
1406       return "Adapter record was not found.";
1407     case NERR_RplVendorNotFound:
1408       return "Vendor record was not found.";
1409     case NERR_RplVendorNameUnavailable:
1410       return "Vendor name is in use by some other vendor record.";
1411     case NERR_RplBootNameUnavailable:
1412       return "(boot name, vendor ID) is in use by some other boot block record.";
1413     case NERR_RplConfigNameUnavailable:
1414       return "Configuration name is in use by some other configuration.";
1415     case NERR_DfsInternalCorruption:
1416       return "The internal database maintained by the Dfs service is corrupt.";
1417     case NERR_DfsVolumeDataCorrupt:
1418       return "One of the records in the internal Dfs database is corrupt.";
1419     case NERR_DfsNoSuchVolume:
1420       return "There is no DFS name whose entry path matches the input Entry Path.";
1421     case NERR_DfsVolumeAlreadyExists:
1422       return "A root or link with the given name already exists.";
1423     case NERR_DfsAlreadyShared:
1424       return "The server share specified is already shared in the Dfs.";
1425     case NERR_DfsNoSuchShare:
1426       return "The indicated server share does not support the indicated DFS namespace.";
1427     case NERR_DfsNotALeafVolume:
1428       return "The operation is not valid on this portion of the namespace.";
1429     case NERR_DfsLeafVolume:
1430       return "The operation is not valid on this portion of the namespace.";
1431     case NERR_DfsVolumeHasMultipleServers:
1432       return "The operation is ambiguous because the link has multiple servers.";
1433     case NERR_DfsCantCreateJunctionPoint:
1434       return "Unable to create a link.";
1435     case NERR_DfsServerNotDfsAware:
1436       return "The server is not Dfs Aware.";
1437     case NERR_DfsBadRenamePath:
1438       return "The specified rename target path is invalid.";
1439     case NERR_DfsVolumeIsOffline:
1440       return "The specified DFS link is offline.";
1441     case NERR_DfsNoSuchServer:
1442       return "The specified server is not a server for this link.";
1443     case NERR_DfsCyclicalName:
1444       return "A cycle in the Dfs name was detected.";
1445     case NERR_DfsNotSupportedInServerDfs:
1446       return "The operation is not supported on a server-based Dfs.";
1447     case NERR_DfsDuplicateService:
1448       return "This link is already supported by the specified server-share.";
1449     case NERR_DfsCantRemoveLastServerShare:
1450       return "Can't remove the last server-share supporting this root or link.";
1451     case NERR_DfsVolumeIsInterDfs:
1452       return "The operation is not supported for an Inter-DFS link.";
1453     case NERR_DfsInconsistent:
1454       return "The internal state of the Dfs Service has become inconsistent.";
1455     case NERR_DfsServerUpgraded:
1456       return "The Dfs Service has been installed on the specified server.";
1457     case NERR_DfsDataIsIdentical:
1458       return "The Dfs data being reconciled is identical.";
1459     case NERR_DfsCantRemoveDfsRoot:
1460       return "The DFS root cannot be deleted. Uninstall DFS if required.";
1461     case NERR_DfsChildOrParentInDfs:
1462       return "A child or parent directory of the share is already in a Dfs.";
1463     case NERR_DfsInternalError:
1464       return "Dfs internal error.";
1465       /* the following are not defined in mingw */
1466 #if 0
1467
1468     case NERR_SetupAlreadyJoined:
1469       return "This machine is already joined to a domain.";
1470     case NERR_SetupNotJoined:
1471       return "This machine is not currently joined to a domain.";
1472     case NERR_SetupDomainController:
1473       return "This machine is a domain controller and cannot be unjoined from a domain.";
1474     case NERR_DefaultJoinRequired:
1475       return "The destination domain controller does not support creating machine accounts in OUs.";
1476     case NERR_InvalidWorkgroupName:
1477       return "The specified workgroup name is invalid.";
1478     case NERR_NameUsesIncompatibleCodePage:
1479       return "The specified computer name is incompatible with the default language used on the domain controller.";
1480     case NERR_ComputerAccountNotFound:
1481       return "The specified computer account could not be found.";
1482     case NERR_PersonalSku:
1483       return "This version of Windows cannot be joined to a domain.";
1484     case NERR_PasswordMustChange:
1485       return "The password must change at the next logon.";
1486     case NERR_AccountLockedOut:
1487       return "The account is locked out.";
1488     case NERR_PasswordTooLong:
1489       return "The password is too long.";
1490     case NERR_PasswordNotComplexEnough:
1491       return "The password does not meet the complexity policy.";
1492     case NERR_PasswordFilterError:
1493       return "The password does not meet the requirements of the password filter DLLs.";
1494 #endif
1495
1496     }
1497   msg = strerror (error_number);
1498   if (msg == NULL)
1499     msg = "unknown";
1500
1501   return msg;
1502 #endif //DBUS_WINCE
1503 }
1504
1505 /**
1506  * Get a printable string describing the command used to execute
1507  * the process with pid.  This string should only be used for
1508  * informative purposes such as logging; it may not be trusted.
1509  *
1510  * The command is guaranteed to be printable ASCII and no longer
1511  * than max_len.
1512  *
1513  * @param pid Process id
1514  * @param str Append command to this string
1515  * @param max_len Maximum length of returned command
1516  * @param error return location for errors
1517  * @returns #FALSE on error
1518  */
1519 dbus_bool_t
1520 _dbus_command_for_pid (unsigned long  pid,
1521                        DBusString    *str,
1522                        int            max_len,
1523                        DBusError     *error)
1524 {
1525   // FIXME
1526   return FALSE;
1527 }