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