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