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