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