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