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