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