D-Bus 1.12.28
dbus-sysdeps-util-unix.c
1/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2/* dbus-sysdeps-util-unix.c Would be in dbus-sysdeps-unix.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#include "dbus-sysdeps.h"
27#include "dbus-sysdeps-unix.h"
28#include "dbus-internals.h"
29#include "dbus-list.h"
30#include "dbus-pipe.h"
31#include "dbus-protocol.h"
32#include "dbus-string.h"
33#define DBUS_USERDB_INCLUDES_PRIVATE 1
34#include "dbus-userdb.h"
35#include "dbus-test.h"
36
37#include <sys/types.h>
38#include <stdlib.h>
39#include <string.h>
40#include <signal.h>
41#include <unistd.h>
42#include <stdio.h>
43#include <errno.h>
44#include <fcntl.h>
45#include <sys/stat.h>
46#ifdef HAVE_SYS_RESOURCE_H
47#include <sys/resource.h>
48#endif
49#include <grp.h>
50#include <sys/socket.h>
51#include <dirent.h>
52#include <sys/un.h>
53
54#ifdef HAVE_SYS_SYSLIMITS_H
55#include <sys/syslimits.h>
56#endif
57
58#ifdef HAVE_SYSTEMD
59#include <systemd/sd-daemon.h>
60#endif
61
62#ifndef O_BINARY
63#define O_BINARY 0
64#endif
65
83 DBusPipe *print_pid_pipe,
84 DBusError *error,
85 dbus_bool_t keep_umask)
86{
87 const char *s;
88 pid_t child_pid;
89 DBusEnsureStandardFdsFlags flags;
90
91 _dbus_verbose ("Becoming a daemon...\n");
92
93 _dbus_verbose ("chdir to /\n");
94 if (chdir ("/") < 0)
95 {
97 "Could not chdir() to root directory");
98 return FALSE;
99 }
100
101 _dbus_verbose ("forking...\n");
102 switch ((child_pid = fork ()))
103 {
104 case -1:
105 _dbus_verbose ("fork failed\n");
107 "Failed to fork daemon: %s", _dbus_strerror (errno));
108 return FALSE;
109 break;
110
111 case 0:
112 _dbus_verbose ("in child, closing std file descriptors\n");
113
114 flags = DBUS_FORCE_STDIN_NULL | DBUS_FORCE_STDOUT_NULL;
115 s = _dbus_getenv ("DBUS_DEBUG_OUTPUT");
116
117 if (s == NULL || *s == '\0')
118 flags |= DBUS_FORCE_STDERR_NULL;
119 else
120 _dbus_verbose ("keeping stderr open due to DBUS_DEBUG_OUTPUT\n");
121
122 if (!_dbus_ensure_standard_fds (flags, &s))
123 {
124 _dbus_warn ("%s: %s", s, _dbus_strerror (errno));
125 _exit (1);
126 }
127
128 if (!keep_umask)
129 {
130 /* Get a predictable umask */
131 _dbus_verbose ("setting umask\n");
132 umask (022);
133 }
134
135 _dbus_verbose ("calling setsid()\n");
136 if (setsid () == -1)
137 _dbus_assert_not_reached ("setsid() failed");
138
139 break;
140
141 default:
142 if (!_dbus_write_pid_to_file_and_pipe (pidfile, print_pid_pipe,
143 child_pid, error))
144 {
145 _dbus_verbose ("pid file or pipe write failed: %s\n",
146 error->message);
147 kill (child_pid, SIGTERM);
148 return FALSE;
149 }
150
151 _dbus_verbose ("parent exiting\n");
152 _exit (0);
153 break;
154 }
155
156 return TRUE;
157}
158
159
168static dbus_bool_t
169_dbus_write_pid_file (const DBusString *filename,
170 unsigned long pid,
171 DBusError *error)
172{
173 const char *cfilename;
174 int fd;
175 FILE *f;
176
177 cfilename = _dbus_string_get_const_data (filename);
178
179 fd = open (cfilename, O_WRONLY|O_CREAT|O_EXCL|O_BINARY, 0644);
180
181 if (fd < 0)
182 {
184 "Failed to open \"%s\": %s", cfilename,
185 _dbus_strerror (errno));
186 return FALSE;
187 }
188
189 if ((f = fdopen (fd, "w")) == NULL)
190 {
192 "Failed to fdopen fd %d: %s", fd, _dbus_strerror (errno));
193 _dbus_close (fd, NULL);
194 return FALSE;
195 }
196
197 if (fprintf (f, "%lu\n", pid) < 0)
198 {
200 "Failed to write to \"%s\": %s", cfilename,
201 _dbus_strerror (errno));
202
203 fclose (f);
204 return FALSE;
205 }
206
207 if (fclose (f) == EOF)
208 {
210 "Failed to close \"%s\": %s", cfilename,
211 _dbus_strerror (errno));
212 return FALSE;
213 }
214
215 return TRUE;
216}
217
231 DBusPipe *print_pid_pipe,
232 dbus_pid_t pid_to_write,
233 DBusError *error)
234{
235 if (pidfile)
236 {
237 _dbus_verbose ("writing pid file %s\n", _dbus_string_get_const_data (pidfile));
238 if (!_dbus_write_pid_file (pidfile,
239 pid_to_write,
240 error))
241 {
242 _dbus_verbose ("pid file write failed\n");
243 _DBUS_ASSERT_ERROR_IS_SET(error);
244 return FALSE;
245 }
246 }
247 else
248 {
249 _dbus_verbose ("No pid file requested\n");
250 }
251
252 if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
253 {
254 DBusString pid;
255 int bytes;
256
257 _dbus_verbose ("writing our pid to pipe %d\n",
258 print_pid_pipe->fd);
259
260 if (!_dbus_string_init (&pid))
261 {
262 _DBUS_SET_OOM (error);
263 return FALSE;
264 }
265
266 if (!_dbus_string_append_int (&pid, pid_to_write) ||
267 !_dbus_string_append (&pid, "\n"))
268 {
269 _dbus_string_free (&pid);
270 _DBUS_SET_OOM (error);
271 return FALSE;
272 }
273
274 bytes = _dbus_string_get_length (&pid);
275 if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
276 {
277 /* _dbus_pipe_write sets error only on failure, not short write */
278 if (error != NULL && !dbus_error_is_set(error))
279 {
281 "Printing message bus PID: did not write enough bytes\n");
282 }
283 _dbus_string_free (&pid);
284 return FALSE;
285 }
286
287 _dbus_string_free (&pid);
288 }
289 else
290 {
291 _dbus_verbose ("No pid pipe to write to\n");
292 }
293
294 return TRUE;
295}
296
304_dbus_verify_daemon_user (const char *user)
305{
306 DBusString u;
307
308 _dbus_string_init_const (&u, user);
309
311}
312
313
314/* The HAVE_LIBAUDIT case lives in selinux.c */
315#ifndef HAVE_LIBAUDIT
325 DBusError *error)
326{
327 dbus_uid_t uid;
328 dbus_gid_t gid;
329 DBusString u;
330
331 _dbus_string_init_const (&u, user);
332
333 if (!_dbus_get_user_id_and_primary_group (&u, &uid, &gid))
334 {
336 "User '%s' does not appear to exist?",
337 user);
338 return FALSE;
339 }
340
341 /* setgroups() only works if we are a privileged process,
342 * so we don't return error on failure; the only possible
343 * failure is that we don't have perms to do it.
344 *
345 * not sure this is right, maybe if setuid()
346 * is going to work then setgroups() should also work.
347 */
348 if (setgroups (0, NULL) < 0)
349 _dbus_warn ("Failed to drop supplementary groups: %s",
350 _dbus_strerror (errno));
351
352 /* Set GID first, or the setuid may remove our permission
353 * to change the GID
354 */
355 if (setgid (gid) < 0)
356 {
358 "Failed to set GID to %lu: %s", gid,
359 _dbus_strerror (errno));
360 return FALSE;
361 }
362
363 if (setuid (uid) < 0)
364 {
366 "Failed to set UID to %lu: %s", uid,
367 _dbus_strerror (errno));
368 return FALSE;
369 }
370
371 return TRUE;
372}
373#endif /* !HAVE_LIBAUDIT */
374
375#ifdef HAVE_SETRLIMIT
376
377/* We assume that if we have setrlimit, we also have getrlimit and
378 * struct rlimit.
379 */
380
381struct DBusRLimit {
382 struct rlimit lim;
383};
384
385DBusRLimit *
386_dbus_rlimit_save_fd_limit (DBusError *error)
387{
388 DBusRLimit *self;
389
390 self = dbus_new0 (DBusRLimit, 1);
391
392 if (self == NULL)
393 {
394 _DBUS_SET_OOM (error);
395 return NULL;
396 }
397
398 if (getrlimit (RLIMIT_NOFILE, &self->lim) < 0)
399 {
401 "Failed to get fd limit: %s", _dbus_strerror (errno));
402 dbus_free (self);
403 return NULL;
404 }
405
406 return self;
407}
408
409/* Enough fds that we shouldn't run out, even if several uids work
410 * together to carry out a denial-of-service attack. This happens to be
411 * the same number that systemd < 234 would normally use. */
412#define ENOUGH_FDS 65536
413
415_dbus_rlimit_raise_fd_limit (DBusError *error)
416{
417 struct rlimit old, lim;
418
419 if (getrlimit (RLIMIT_NOFILE, &lim) < 0)
420 {
422 "Failed to get fd limit: %s", _dbus_strerror (errno));
423 return FALSE;
424 }
425
426 old = lim;
427
428 if (getuid () == 0)
429 {
430 /* We are privileged, so raise the soft limit to at least
431 * ENOUGH_FDS, and the hard limit to at least the desired soft
432 * limit. This assumes we can exercise CAP_SYS_RESOURCE on Linux,
433 * or other OSs' equivalents. */
434 if (lim.rlim_cur != RLIM_INFINITY &&
435 lim.rlim_cur < ENOUGH_FDS)
436 lim.rlim_cur = ENOUGH_FDS;
437
438 if (lim.rlim_max != RLIM_INFINITY &&
439 lim.rlim_max < lim.rlim_cur)
440 lim.rlim_max = lim.rlim_cur;
441 }
442
443 /* Raise the soft limit to match the hard limit, which we can do even
444 * if we are unprivileged. In particular, systemd >= 240 will normally
445 * set rlim_cur to 1024 and rlim_max to 512*1024, recent Debian
446 * versions end up setting rlim_cur to 1024 and rlim_max to 1024*1024,
447 * and older and non-systemd Linux systems would typically set rlim_cur
448 * to 1024 and rlim_max to 4096. */
449 if (lim.rlim_max == RLIM_INFINITY || lim.rlim_cur < lim.rlim_max)
450 {
451#if defined(__APPLE__) && defined(__MACH__)
452 /* macOS 10.5 and above no longer allows RLIM_INFINITY for rlim_cur */
453 lim.rlim_cur = MIN (OPEN_MAX, lim.rlim_max);
454#else
455 lim.rlim_cur = lim.rlim_max;
456#endif
457 }
458
459 /* Early-return if there is nothing to do. */
460 if (lim.rlim_max == old.rlim_max &&
461 lim.rlim_cur == old.rlim_cur)
462 return TRUE;
463
464 if (setrlimit (RLIMIT_NOFILE, &lim) < 0)
465 {
467 "Failed to set fd limit to %lu: %s",
468 (unsigned long) lim.rlim_cur,
469 _dbus_strerror (errno));
470 return FALSE;
471 }
472
473 return TRUE;
474}
475
477_dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
478 DBusError *error)
479{
480 if (setrlimit (RLIMIT_NOFILE, &saved->lim) < 0)
481 {
483 "Failed to restore old fd limit: %s",
484 _dbus_strerror (errno));
485 return FALSE;
486 }
487
488 return TRUE;
489}
490
491#else /* !HAVE_SETRLIMIT */
492
493static void
494fd_limit_not_supported (DBusError *error)
495{
497 "cannot change fd limit on this platform");
498}
499
500DBusRLimit *
501_dbus_rlimit_save_fd_limit (DBusError *error)
502{
503 fd_limit_not_supported (error);
504 return NULL;
505}
506
508_dbus_rlimit_raise_fd_limit (DBusError *error)
509{
510 fd_limit_not_supported (error);
511 return FALSE;
512}
513
515_dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
516 DBusError *error)
517{
518 fd_limit_not_supported (error);
519 return FALSE;
520}
521
522#endif
523
524void
525_dbus_rlimit_free (DBusRLimit *lim)
526{
527 dbus_free (lim);
528}
529
535void
537 DBusSignalHandler handler)
538{
539 struct sigaction act;
540 sigset_t empty_mask;
541
542 sigemptyset (&empty_mask);
543 act.sa_handler = handler;
544 act.sa_mask = empty_mask;
545 act.sa_flags = 0;
546 sigaction (sig, &act, NULL);
547}
548
555_dbus_file_exists (const char *file)
556{
557 return (access (file, F_OK) == 0);
558}
559
567_dbus_user_at_console (const char *username,
568 DBusError *error)
569{
570#ifdef DBUS_CONSOLE_AUTH_DIR
571 DBusString u, f;
572 dbus_bool_t result;
573
574 result = FALSE;
575 if (!_dbus_string_init (&f))
576 {
577 _DBUS_SET_OOM (error);
578 return FALSE;
579 }
580
581 if (!_dbus_string_append (&f, DBUS_CONSOLE_AUTH_DIR))
582 {
583 _DBUS_SET_OOM (error);
584 goto out;
585 }
586
587 _dbus_string_init_const (&u, username);
588
589 if (!_dbus_concat_dir_and_file (&f, &u))
590 {
591 _DBUS_SET_OOM (error);
592 goto out;
593 }
594
595 result = _dbus_file_exists (_dbus_string_get_const_data (&f));
596
597 out:
599
600 return result;
601#else
602 return FALSE;
603#endif
604}
605
606
615{
616 if (_dbus_string_get_length (filename) > 0)
617 return _dbus_string_get_byte (filename, 0) == '/';
618 else
619 return FALSE;
620}
621
631_dbus_stat (const DBusString *filename,
632 DBusStat *statbuf,
633 DBusError *error)
634{
635 const char *filename_c;
636 struct stat sb;
637
638 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
639
640 filename_c = _dbus_string_get_const_data (filename);
641
642 if (stat (filename_c, &sb) < 0)
643 {
645 "%s", _dbus_strerror (errno));
646 return FALSE;
647 }
648
649 statbuf->mode = sb.st_mode;
650 statbuf->nlink = sb.st_nlink;
651 statbuf->uid = sb.st_uid;
652 statbuf->gid = sb.st_gid;
653 statbuf->size = sb.st_size;
654 statbuf->atime = sb.st_atime;
655 statbuf->mtime = sb.st_mtime;
656 statbuf->ctime = sb.st_ctime;
657
658 return TRUE;
659}
660
661
666{
667 DIR *d;
669};
670
680 DBusError *error)
681{
682 DIR *d;
683 DBusDirIter *iter;
684 const char *filename_c;
685
686 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
687
688 filename_c = _dbus_string_get_const_data (filename);
689
690 d = opendir (filename_c);
691 if (d == NULL)
692 {
694 "Failed to read directory \"%s\": %s",
695 filename_c,
696 _dbus_strerror (errno));
697 return NULL;
698 }
699 iter = dbus_new0 (DBusDirIter, 1);
700 if (iter == NULL)
701 {
702 closedir (d);
704 "Could not allocate memory for directory iterator");
705 return NULL;
706 }
707
708 iter->d = d;
709
710 return iter;
711}
712
728 DBusString *filename,
729 DBusError *error)
730{
731 struct dirent *ent;
732 int err;
733
734 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
735
736 again:
737 errno = 0;
738 ent = readdir (iter->d);
739
740 if (!ent)
741 {
742 err = errno;
743
744 if (err != 0)
745 dbus_set_error (error,
747 "%s", _dbus_strerror (err));
748
749 return FALSE;
750 }
751 else if (ent->d_name[0] == '.' &&
752 (ent->d_name[1] == '\0' ||
753 (ent->d_name[1] == '.' && ent->d_name[2] == '\0')))
754 goto again;
755 else
756 {
757 _dbus_string_set_length (filename, 0);
758 if (!_dbus_string_append (filename, ent->d_name))
759 {
761 "No memory to read directory entry");
762 return FALSE;
763 }
764 else
765 {
766 return TRUE;
767 }
768 }
769}
770
774void
776{
777 closedir (iter->d);
778 dbus_free (iter);
779}
780
781static dbus_bool_t
782fill_user_info_from_group (struct group *g,
783 DBusGroupInfo *info,
784 DBusError *error)
785{
786 _dbus_assert (g->gr_name != NULL);
787
788 info->gid = g->gr_gid;
789 info->groupname = _dbus_strdup (g->gr_name);
790
791 /* info->members = dbus_strdupv (g->gr_mem) */
792
793 if (info->groupname == NULL)
794 {
796 return FALSE;
797 }
798
799 return TRUE;
800}
801
802static dbus_bool_t
803fill_group_info (DBusGroupInfo *info,
804 dbus_gid_t gid,
805 const DBusString *groupname,
806 DBusError *error)
807{
808 const char *group_c_str;
809
810 _dbus_assert (groupname != NULL || gid != DBUS_GID_UNSET);
811 _dbus_assert (groupname == NULL || gid == DBUS_GID_UNSET);
812
813 if (groupname)
814 group_c_str = _dbus_string_get_const_data (groupname);
815 else
816 group_c_str = NULL;
817
818 /* For now assuming that the getgrnam() and getgrgid() flavors
819 * always correspond to the pwnam flavors, if not we have
820 * to add more configure checks.
821 */
822
823#if defined (HAVE_POSIX_GETPWNAM_R) || defined (HAVE_NONPOSIX_GETPWNAM_R)
824 {
825 struct group *g;
826 int result;
827 size_t buflen;
828 char *buf;
829 struct group g_str;
830 dbus_bool_t b;
831
832 /* retrieve maximum needed size for buf */
833 buflen = sysconf (_SC_GETGR_R_SIZE_MAX);
834
835 /* sysconf actually returns a long, but everything else expects size_t,
836 * so just recast here.
837 * https://bugs.freedesktop.org/show_bug.cgi?id=17061
838 */
839 if ((long) buflen <= 0)
840 buflen = 1024;
841
842 result = -1;
843 while (1)
844 {
845 buf = dbus_malloc (buflen);
846 if (buf == NULL)
847 {
849 return FALSE;
850 }
851
852 g = NULL;
853#ifdef HAVE_POSIX_GETPWNAM_R
854 if (group_c_str)
855 result = getgrnam_r (group_c_str, &g_str, buf, buflen,
856 &g);
857 else
858 result = getgrgid_r (gid, &g_str, buf, buflen,
859 &g);
860#else
861 g = getgrnam_r (group_c_str, &g_str, buf, buflen);
862 result = 0;
863#endif /* !HAVE_POSIX_GETPWNAM_R */
864 /* Try a bigger buffer if ERANGE was returned:
865 https://bugs.freedesktop.org/show_bug.cgi?id=16727
866 */
867 if (result == ERANGE && buflen < 512 * 1024)
868 {
869 dbus_free (buf);
870 buflen *= 2;
871 }
872 else
873 {
874 break;
875 }
876 }
877
878 if (result == 0 && g == &g_str)
879 {
880 b = fill_user_info_from_group (g, info, error);
881 dbus_free (buf);
882 return b;
883 }
884 else
885 {
887 "Group %s unknown or failed to look it up\n",
888 group_c_str ? group_c_str : "???");
889 dbus_free (buf);
890 return FALSE;
891 }
892 }
893#else /* ! HAVE_GETPWNAM_R */
894 {
895 /* I guess we're screwed on thread safety here */
896 struct group *g;
897
898 g = getgrnam (group_c_str);
899
900 if (g != NULL)
901 {
902 return fill_user_info_from_group (g, info, error);
903 }
904 else
905 {
907 "Group %s unknown or failed to look it up\n",
908 group_c_str ? group_c_str : "???");
909 return FALSE;
910 }
911 }
912#endif /* ! HAVE_GETPWNAM_R */
913}
914
926 const DBusString *groupname,
927 DBusError *error)
928{
929 return fill_group_info (info, DBUS_GID_UNSET,
930 groupname, error);
931
932}
933
945 dbus_gid_t gid,
946 DBusError *error)
947{
948 return fill_group_info (info, gid, NULL, error);
949}
950
961 dbus_uid_t *uid_p)
962{
963 return _dbus_get_user_id (username, uid_p);
964
965}
966
977 dbus_gid_t *gid_p)
978{
979 return _dbus_get_group_id (groupname, gid_p);
980}
981
994 dbus_gid_t **group_ids,
995 int *n_group_ids)
996{
997 return _dbus_groups_from_uid (uid, group_ids, n_group_ids);
998}
999
1011 DBusError *error)
1012{
1013 return _dbus_is_console_user (uid, error);
1014
1015}
1016
1026{
1027 return uid == _dbus_geteuid ();
1028}
1029
1039{
1040 return FALSE;
1041}
1042 /* End of DBusInternalsUtils functions */
1044
1058 DBusString *dirname)
1059{
1060 int sep;
1061
1062 _dbus_assert (filename != dirname);
1063 _dbus_assert (filename != NULL);
1064 _dbus_assert (dirname != NULL);
1065
1066 /* Ignore any separators on the end */
1067 sep = _dbus_string_get_length (filename);
1068 if (sep == 0)
1069 return _dbus_string_append (dirname, "."); /* empty string passed in */
1070
1071 while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1072 --sep;
1073
1074 _dbus_assert (sep >= 0);
1075
1076 if (sep == 0)
1077 return _dbus_string_append (dirname, "/");
1078
1079 /* Now find the previous separator */
1080 _dbus_string_find_byte_backward (filename, sep, '/', &sep);
1081 if (sep < 0)
1082 return _dbus_string_append (dirname, ".");
1083
1084 /* skip multiple separators */
1085 while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1086 --sep;
1087
1088 _dbus_assert (sep >= 0);
1089
1090 if (sep == 0 &&
1091 _dbus_string_get_byte (filename, 0) == '/')
1092 return _dbus_string_append (dirname, "/");
1093 else
1094 return _dbus_string_copy_len (filename, 0, sep - 0,
1095 dirname, _dbus_string_get_length (dirname));
1096} /* DBusString stuff */
1098
1099static void
1100string_squash_nonprintable (DBusString *str)
1101{
1102 unsigned char *buf;
1103 int i, len;
1104
1105 buf = _dbus_string_get_udata (str);
1106 len = _dbus_string_get_length (str);
1107
1108 for (i = 0; i < len; i++)
1109 {
1110 unsigned char c = (unsigned char) buf[i];
1111 if (c == '\0')
1112 buf[i] = ' ';
1113 else if (c < 0x20 || c > 127)
1114 buf[i] = '?';
1115 }
1116}
1117
1133_dbus_command_for_pid (unsigned long pid,
1134 DBusString *str,
1135 int max_len,
1136 DBusError *error)
1137{
1138 /* This is all Linux-specific for now */
1139 DBusString path;
1140 DBusString cmdline;
1141 int fd;
1142
1143 if (!_dbus_string_init (&path))
1144 {
1145 _DBUS_SET_OOM (error);
1146 return FALSE;
1147 }
1148
1149 if (!_dbus_string_init (&cmdline))
1150 {
1151 _DBUS_SET_OOM (error);
1152 _dbus_string_free (&path);
1153 return FALSE;
1154 }
1155
1156 if (!_dbus_string_append_printf (&path, "/proc/%ld/cmdline", pid))
1157 goto oom;
1158
1159 fd = open (_dbus_string_get_const_data (&path), O_RDONLY);
1160 if (fd < 0)
1161 {
1162 dbus_set_error (error,
1163 _dbus_error_from_errno (errno),
1164 "Failed to open \"%s\": %s",
1165 _dbus_string_get_const_data (&path),
1166 _dbus_strerror (errno));
1167 goto fail;
1168 }
1169
1170 if (!_dbus_read (fd, &cmdline, max_len))
1171 {
1172 dbus_set_error (error,
1173 _dbus_error_from_errno (errno),
1174 "Failed to read from \"%s\": %s",
1175 _dbus_string_get_const_data (&path),
1176 _dbus_strerror (errno));
1177 _dbus_close (fd, NULL);
1178 goto fail;
1179 }
1180
1181 if (!_dbus_close (fd, error))
1182 goto fail;
1183
1184 string_squash_nonprintable (&cmdline);
1185
1186 if (!_dbus_string_copy (&cmdline, 0, str, _dbus_string_get_length (str)))
1187 goto oom;
1188
1189 _dbus_string_free (&cmdline);
1190 _dbus_string_free (&path);
1191 return TRUE;
1192oom:
1193 _DBUS_SET_OOM (error);
1194fail:
1195 _dbus_string_free (&cmdline);
1196 _dbus_string_free (&path);
1197 return FALSE;
1198}
1199
1210{
1211 return TRUE;
1212}
1213
1214static dbus_bool_t
1215ensure_owned_directory (const char *label,
1216 const DBusString *string,
1217 dbus_bool_t create,
1218 DBusError *error)
1219{
1220 const char *dir = _dbus_string_get_const_data (string);
1221 struct stat buf;
1222
1223 if (create && !_dbus_ensure_directory (string, error))
1224 return FALSE;
1225
1226 /*
1227 * The stat()-based checks in this function are to protect against
1228 * mistakes, not malice. We are working in a directory that is meant
1229 * to be trusted; but if a user has used `su` or similar to escalate
1230 * their privileges without correctly clearing the environment, the
1231 * XDG_RUNTIME_DIR in the environment might still be the user's
1232 * and not root's. We don't want to write root-owned files into that
1233 * directory, so just warn and don't provide support for transient
1234 * services in that case.
1235 *
1236 * In particular, we use stat() and not lstat() so that if we later
1237 * decide to use a different directory name for transient services,
1238 * we can drop in a compatibility symlink without breaking older
1239 * libdbus.
1240 */
1241
1242 if (stat (dir, &buf) != 0)
1243 {
1244 int saved_errno = errno;
1245
1246 dbus_set_error (error, _dbus_error_from_errno (saved_errno),
1247 "%s \"%s\" not available: %s", label, dir,
1248 _dbus_strerror (saved_errno));
1249 return FALSE;
1250 }
1251
1252 if (!S_ISDIR (buf.st_mode))
1253 {
1254 dbus_set_error (error, DBUS_ERROR_FAILED, "%s \"%s\" is not a directory",
1255 label, dir);
1256 return FALSE;
1257 }
1258
1259 if (buf.st_uid != geteuid ())
1260 {
1262 "%s \"%s\" is owned by uid %ld, not our uid %ld",
1263 label, dir, (long) buf.st_uid, (long) geteuid ());
1264 return FALSE;
1265 }
1266
1267 /* This is just because we have the stat() results already, so we might
1268 * as well check opportunistically. */
1269 if ((S_IWOTH | S_IWGRP) & buf.st_mode)
1270 {
1272 "%s \"%s\" can be written by others (mode 0%o)",
1273 label, dir, buf.st_mode);
1274 return FALSE;
1275 }
1276
1277 return TRUE;
1278}
1279
1280#define DBUS_UNIX_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
1281#define DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"
1282
1292 DBusError *error)
1293{
1294 const char *xdg_runtime_dir;
1295 DBusString services;
1296 DBusString dbus1;
1297 DBusString xrd;
1298 dbus_bool_t ret = FALSE;
1299 char *data = NULL;
1300
1301 if (!_dbus_string_init (&dbus1))
1302 {
1303 _DBUS_SET_OOM (error);
1304 return FALSE;
1305 }
1306
1307 if (!_dbus_string_init (&services))
1308 {
1309 _dbus_string_free (&dbus1);
1310 _DBUS_SET_OOM (error);
1311 return FALSE;
1312 }
1313
1314 if (!_dbus_string_init (&xrd))
1315 {
1316 _dbus_string_free (&dbus1);
1317 _dbus_string_free (&services);
1318 _DBUS_SET_OOM (error);
1319 return FALSE;
1320 }
1321
1322 xdg_runtime_dir = _dbus_getenv ("XDG_RUNTIME_DIR");
1323
1324 /* Not an error, we just can't have transient session services */
1325 if (xdg_runtime_dir == NULL)
1326 {
1327 _dbus_verbose ("XDG_RUNTIME_DIR is unset: transient session services "
1328 "not available here\n");
1329 ret = TRUE;
1330 goto out;
1331 }
1332
1333 if (!_dbus_string_append (&xrd, xdg_runtime_dir) ||
1334 !_dbus_string_append_printf (&dbus1, "%s/dbus-1",
1335 xdg_runtime_dir) ||
1336 !_dbus_string_append_printf (&services, "%s/dbus-1/services",
1337 xdg_runtime_dir))
1338 {
1339 _DBUS_SET_OOM (error);
1340 goto out;
1341 }
1342
1343 if (!ensure_owned_directory ("XDG_RUNTIME_DIR", &xrd, FALSE, error) ||
1344 !ensure_owned_directory ("XDG_RUNTIME_DIR subdirectory", &dbus1, TRUE,
1345 error) ||
1346 !ensure_owned_directory ("XDG_RUNTIME_DIR subdirectory", &services,
1347 TRUE, error))
1348 goto out;
1349
1350 if (!_dbus_string_steal_data (&services, &data) ||
1351 !_dbus_list_append (dirs, data))
1352 {
1353 _DBUS_SET_OOM (error);
1354 goto out;
1355 }
1356
1357 _dbus_verbose ("Transient service directory is %s\n", data);
1358 /* Ownership was transferred to @dirs */
1359 data = NULL;
1360 ret = TRUE;
1361
1362out:
1363 _dbus_string_free (&dbus1);
1364 _dbus_string_free (&services);
1365 _dbus_string_free (&xrd);
1366 dbus_free (data);
1367 return ret;
1368}
1369
1389{
1390 const char *xdg_data_home;
1391 const char *xdg_data_dirs;
1392 DBusString servicedir_path;
1393
1394 if (!_dbus_string_init (&servicedir_path))
1395 return FALSE;
1396
1397 xdg_data_home = _dbus_getenv ("XDG_DATA_HOME");
1398 xdg_data_dirs = _dbus_getenv ("XDG_DATA_DIRS");
1399
1400 if (xdg_data_home != NULL)
1401 {
1402 if (!_dbus_string_append (&servicedir_path, xdg_data_home))
1403 goto oom;
1404 }
1405 else
1406 {
1407 const DBusString *homedir;
1408 DBusString local_share;
1409
1410 if (!_dbus_homedir_from_current_process (&homedir))
1411 goto oom;
1412
1413 if (!_dbus_string_append (&servicedir_path, _dbus_string_get_const_data (homedir)))
1414 goto oom;
1415
1416 _dbus_string_init_const (&local_share, "/.local/share");
1417 if (!_dbus_concat_dir_and_file (&servicedir_path, &local_share))
1418 goto oom;
1419 }
1420
1421 if (!_dbus_string_append (&servicedir_path, ":"))
1422 goto oom;
1423
1424 if (xdg_data_dirs != NULL)
1425 {
1426 if (!_dbus_string_append (&servicedir_path, xdg_data_dirs))
1427 goto oom;
1428
1429 if (!_dbus_string_append (&servicedir_path, ":"))
1430 goto oom;
1431 }
1432 else
1433 {
1434 if (!_dbus_string_append (&servicedir_path, "/usr/local/share:/usr/share:"))
1435 goto oom;
1436 }
1437
1438 /*
1439 * add configured datadir to defaults
1440 * this may be the same as an xdg dir
1441 * however the config parser should take
1442 * care of duplicates
1443 */
1444 if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR))
1445 goto oom;
1446
1447 if (!_dbus_split_paths_and_append (&servicedir_path,
1448 DBUS_UNIX_STANDARD_SESSION_SERVICEDIR,
1449 dirs))
1450 goto oom;
1451
1452 _dbus_string_free (&servicedir_path);
1453 return TRUE;
1454
1455 oom:
1456 _dbus_string_free (&servicedir_path);
1457 return FALSE;
1458}
1459
1460
1481{
1482 /*
1483 * DBUS_DATADIR may be the same as one of the standard directories. However,
1484 * the config parser should take care of the duplicates.
1485 *
1486 * Also, append /lib as counterpart of /usr/share on the root
1487 * directory (the root directory does not know /share), in order to
1488 * facilitate early boot system bus activation where /usr might not
1489 * be available.
1490 */
1491 static const char standard_search_path[] =
1492 "/usr/local/share:"
1493 "/usr/share:"
1494 DBUS_DATADIR ":"
1495 "/lib";
1496 DBusString servicedir_path;
1497
1498 _dbus_string_init_const (&servicedir_path, standard_search_path);
1499
1500 return _dbus_split_paths_and_append (&servicedir_path,
1501 DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR,
1502 dirs);
1503}
1504
1515{
1516 _dbus_assert (_dbus_string_get_length (str) == 0);
1517
1518 return _dbus_string_append (str, DBUS_SYSTEM_CONFIG_FILE);
1519}
1520
1529{
1530 _dbus_assert (_dbus_string_get_length (str) == 0);
1531
1532 return _dbus_string_append (str, DBUS_SESSION_CONFIG_FILE);
1533}
1534
1535#ifdef DBUS_ENABLE_EMBEDDED_TESTS
1536
1537/*
1538 * Set uid to a machine-readable authentication identity (numeric Unix
1539 * uid or ConvertSidToStringSid-style Windows SID) that is likely to exist,
1540 * and differs from the identity of the current process.
1541 *
1542 * @param uid Populated with a machine-readable authentication identity
1543 * on success
1544 * @returns #FALSE if no memory
1545 */
1547_dbus_test_append_different_uid (DBusString *uid)
1548{
1549 if (geteuid () == 0)
1550 return _dbus_string_append (uid, "65534");
1551 else
1552 return _dbus_string_append (uid, "0");
1553}
1554
1555/*
1556 * Set uid to a human-readable authentication identity (login name)
1557 * that is likely to exist, and differs from the identity of the current
1558 * process. This function currently only exists on Unix platforms.
1559 *
1560 * @param uid Populated with a machine-readable authentication identity
1561 * on success
1562 * @returns #FALSE if no memory
1563 */
1565_dbus_test_append_different_username (DBusString *username)
1566{
1567 if (geteuid () == 0)
1568 return _dbus_string_append (username, "nobody");
1569 else
1570 return _dbus_string_append (username, "root");
1571}
1572
1573#endif
1574
1589_dbus_reset_oom_score_adj (const char **error_str_p)
1590{
1591#ifdef __linux__
1592 int fd = -1;
1593 dbus_bool_t ret = FALSE;
1594 int saved_errno = 0;
1595 const char *error_str = NULL;
1596
1597#ifdef O_CLOEXEC
1598 fd = open ("/proc/self/oom_score_adj", O_RDWR | O_CLOEXEC);
1599#endif
1600
1601 if (fd < 0)
1602 {
1603 fd = open ("/proc/self/oom_score_adj", O_RDWR);
1605 }
1606
1607 if (fd >= 0)
1608 {
1609 ssize_t read_result = -1;
1610 /* It doesn't actually matter whether we read the whole file,
1611 * as long as we get the presence or absence of the minus sign */
1612 char first_char = '\0';
1613
1614 read_result = read (fd, &first_char, 1);
1615
1616 if (read_result < 0)
1617 {
1618 /* This probably can't actually happen in practice: if we can
1619 * open it, then we can hopefully read from it */
1620 ret = FALSE;
1621 error_str = "failed to read from /proc/self/oom_score_adj";
1622 saved_errno = errno;
1623 goto out;
1624 }
1625
1626 /* If we are running with protection from the OOM killer
1627 * (typical for the system dbus-daemon under systemd), then
1628 * oom_score_adj will be negative. Drop that protection,
1629 * returning to oom_score_adj = 0.
1630 *
1631 * Conversely, if we are running with increased susceptibility
1632 * to the OOM killer (as user sessions typically do in
1633 * systemd >= 250), oom_score_adj will be strictly positive,
1634 * and we are not allowed to decrease it to 0 without privileges.
1635 *
1636 * If it's exactly 0 (typical for non-systemd systems, and
1637 * user processes on older systemd) then there's no need to
1638 * alter it.
1639 *
1640 * We shouldn't get an empty result, but if we do, assume it
1641 * means zero and don't try to change it. */
1642 if (read_result == 0 || first_char != '-')
1643 {
1644 /* Nothing needs to be done: the OOM score adjustment is
1645 * non-negative */
1646 ret = TRUE;
1647 goto out;
1648 }
1649
1650 if (pwrite (fd, "0", sizeof (char), 0) < 0)
1651 {
1652 ret = FALSE;
1653 error_str = "writing oom_score_adj error";
1654 saved_errno = errno;
1655 goto out;
1656 }
1657
1658 /* Success */
1659 ret = TRUE;
1660 }
1661 else if (errno == ENOENT)
1662 {
1663 /* If /proc/self/oom_score_adj doesn't exist, assume the kernel
1664 * doesn't support this feature and ignore it. */
1665 ret = TRUE;
1666 }
1667 else
1668 {
1669 ret = FALSE;
1670 error_str = "open(/proc/self/oom_score_adj)";
1671 saved_errno = errno;
1672 goto out;
1673 }
1674
1675out:
1676 if (fd >= 0)
1677 _dbus_close (fd, NULL);
1678
1679 if (error_str_p != NULL)
1680 *error_str_p = error_str;
1681
1682 errno = saved_errno;
1683 return ret;
1684#else
1685 /* nothing to do on this platform */
1686 return TRUE;
1687#endif
1688}
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
Definition: dbus-errors.c:354
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
Definition: dbus-errors.c:329
dbus_bool_t _dbus_stat(const DBusString *filename, DBusStat *statbuf, DBusError *error)
stat() wrapper.
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
dbus_bool_t _dbus_write_pid_to_file_and_pipe(const DBusString *pidfile, DBusPipe *print_pid_pipe, dbus_pid_t pid_to_write, DBusError *error)
Writes the given pid_to_write to a pidfile (if non-NULL) and/or to a pipe (if non-NULL).
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
dbus_bool_t _dbus_file_exists(const char *file)
Checks if a file exists.
dbus_bool_t _dbus_homedir_from_current_process(const DBusString **homedir)
Gets homedir of user owning current process.
Definition: dbus-userdb.c:432
void _dbus_directory_close(DBusDirIter *iter)
Closes a directory iteration.
dbus_bool_t _dbus_group_info_fill(DBusGroupInfo *info, const DBusString *groupname, DBusError *error)
Initializes the given DBusGroupInfo struct with information about the given group name.
dbus_bool_t _dbus_user_at_console(const char *username, DBusError *error)
Checks if user is at the console.
DBusDirIter * _dbus_directory_open(const DBusString *filename, DBusError *error)
Open a directory to iterate over.
dbus_bool_t _dbus_parse_unix_user_from_config(const DBusString *username, dbus_uid_t *uid_p)
Parse a UNIX user from the bus config file.
dbus_bool_t _dbus_verify_daemon_user(const char *user)
Verify that after the fork we can successfully change to this user.
const char * _dbus_error_from_errno(int error_number)
Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.
Definition: dbus-sysdeps.c:592
void _dbus_set_signal_handler(int sig, DBusSignalHandler handler)
Installs a UNIX signal handler.
dbus_bool_t _dbus_path_is_absolute(const DBusString *filename)
Checks whether the filename is an absolute path.
char * _dbus_strdup(const char *str)
Duplicates a string.
dbus_bool_t _dbus_unix_groups_from_uid(dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids)
Gets all groups corresponding to the given UNIX user ID.
dbus_bool_t _dbus_change_to_daemon_user(const char *user, DBusError *error)
Changes the user and group the bus is running as.
dbus_bool_t _dbus_unix_user_is_process_owner(dbus_uid_t uid)
Checks to see if the UNIX user ID matches the UID of the process.
dbus_bool_t _dbus_get_group_id(const DBusString *groupname, dbus_gid_t *gid)
Gets group ID given groupname.
dbus_bool_t _dbus_windows_user_is_process_owner(const char *windows_sid)
Checks to see if the Windows user SID matches the owner of the process.
dbus_bool_t _dbus_parse_unix_group_from_config(const DBusString *groupname, dbus_gid_t *gid_p)
Parse a UNIX group from the bus config file.
dbus_bool_t _dbus_is_console_user(dbus_uid_t uid, DBusError *error)
Checks to see if the UID sent in is the console user.
dbus_bool_t _dbus_directory_get_next_file(DBusDirIter *iter, DBusString *filename, DBusError *error)
Get next file in the directory.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
dbus_bool_t _dbus_get_user_id_and_primary_group(const DBusString *username, dbus_uid_t *uid_p, dbus_gid_t *gid_p)
Gets user ID and primary group given username.
dbus_bool_t _dbus_become_daemon(const DBusString *pidfile, DBusPipe *print_pid_pipe, DBusError *error, dbus_bool_t keep_umask)
Does the chdir, fork, setsid, etc.
dbus_bool_t _dbus_group_info_fill_gid(DBusGroupInfo *info, dbus_gid_t gid, DBusError *error)
Initializes the given DBusGroupInfo struct with information about the given group ID.
dbus_bool_t _dbus_groups_from_uid(dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids)
Gets all groups corresponding to the given UID.
dbus_bool_t _dbus_unix_user_is_at_console(dbus_uid_t uid, DBusError *error)
Checks to see if the UNIX user ID is at the console.
dbus_bool_t _dbus_get_user_id(const DBusString *username, dbus_uid_t *uid)
Gets user ID given username.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
Definition: dbus-list.c:270
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition: dbus-memory.c:702
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
Definition: dbus-memory.h:58
void * dbus_malloc(size_t bytes)
Allocates the given number of bytes, as with standard malloc().
Definition: dbus-memory.c:462
#define DBUS_ERROR_NOT_SUPPORTED
Requested operation isn't supported (like ENOSYS on UNIX).
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.
Definition: dbus-string.c:802
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
Definition: dbus-string.c:935
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:175
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:190
dbus_bool_t _dbus_string_copy(const DBusString *source, int start, DBusString *dest, int insert_at)
Like _dbus_string_move(), but does not delete the section of the source string that's copied to the d...
Definition: dbus-string.c:1283
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_string_append_int(DBusString *str, long value)
Appends an integer to a DBusString.
Definition: dbus-sysdeps.c:356
dbus_bool_t _dbus_string_steal_data(DBusString *str, char **data_return)
Like _dbus_string_get_data(), but removes the gotten data from the original string.
Definition: dbus-string.c:641
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
Definition: dbus-string.c:259
dbus_bool_t _dbus_string_find_byte_backward(const DBusString *str, int start, unsigned char byte, int *found)
Find the given byte scanning backward from the given start.
dbus_bool_t _dbus_string_append_printf(DBusString *str, const char *format,...)
Appends a printf-style formatted string to the DBusString.
Definition: dbus-string.c:1114
dbus_bool_t _dbus_string_copy_len(const DBusString *source, int start, int len, DBusString *dest, int insert_at)
Like _dbus_string_copy(), but can copy a segment from the middle of the source string.
Definition: dbus-string.c:1375
dbus_bool_t _dbus_string_get_dirname(const DBusString *filename, DBusString *dirname)
Get the directory name from a complete filename.
dbus_bool_t _dbus_reset_oom_score_adj(const char **error_str_p)
If the current process has been protected from the Linux OOM killer (the oom_score_adj process parame...
dbus_bool_t _dbus_close(int fd, DBusError *error)
Closes a file descriptor.
void(* DBusSignalHandler)(int sig)
A UNIX signal handler.
void _dbus_fd_set_close_on_exec(int fd)
Sets the file descriptor to be close on exec.
int _dbus_read(int fd, DBusString *buffer, int count)
Thin wrapper around the read() system call that appends the data it reads to the DBusString buffer.
dbus_bool_t _dbus_ensure_standard_fds(DBusEnsureStandardFdsFlags flags, const char **error_str_p)
Ensure that the standard file descriptors stdin, stdout and stderr are open, by opening /dev/null if ...
dbus_uid_t _dbus_geteuid(void)
Gets our effective UID.
dbus_bool_t _dbus_get_standard_session_servicedirs(DBusList **dirs)
Returns the standard directories for a session bus to look for service activation files.
unsigned long dbus_uid_t
A user ID.
Definition: dbus-sysdeps.h:134
dbus_bool_t _dbus_get_session_config_file(DBusString *str)
Get the absolute path of the session.conf file.
unsigned long dbus_pid_t
A process ID.
Definition: dbus-sysdeps.h:132
unsigned long dbus_gid_t
A group ID.
Definition: dbus-sysdeps.h:136
dbus_bool_t _dbus_command_for_pid(unsigned long pid, DBusString *str, int max_len, DBusError *error)
Get a printable string describing the command used to execute the process with pid.
dbus_bool_t _dbus_get_system_config_file(DBusString *str)
Get the absolute path of the system.conf file (there is no system bus on Windows so this can just ret...
dbus_bool_t _dbus_set_up_transient_session_servicedirs(DBusList **dirs, DBusError *error)
Returns the standard directories for a session bus to look for transient service activation files.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition: dbus-sysdeps.c:187
dbus_bool_t _dbus_get_standard_system_servicedirs(DBusList **dirs)
Returns the standard directories for a system bus to look for service activation files.
#define DBUS_GID_UNSET
an invalid GID used to represent an uninitialized dbus_gid_t field
Definition: dbus-sysdeps.h:143
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
dbus_bool_t _dbus_split_paths_and_append(DBusString *dirs, const char *suffix, DBusList **dir_list)
Split paths into a list of char strings.
Definition: dbus-sysdeps.c:228
dbus_bool_t _dbus_replace_install_prefix(DBusString *path)
Replace the DBUS_PREFIX in the given path, in-place, by the current D-Bus installation directory.
dbus_bool_t _dbus_ensure_directory(const DBusString *filename, DBusError *error)
Creates a directory; succeeds if the directory is created or already existed.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
Internals of directory iterator.
DIR * d
The DIR* from opendir()
Object representing an exception.
Definition: dbus-errors.h:49
const char * message
public error message field
Definition: dbus-errors.h:51
Information about a UNIX group.
dbus_gid_t gid
GID.
char * groupname
Group name.
A node in a linked list.
Definition: dbus-list.h:35
Portable struct with stat() results.
Definition: dbus-sysdeps.h:528
unsigned long nlink
Number of hard links.
Definition: dbus-sysdeps.h:530
unsigned long size
Size of file.
Definition: dbus-sysdeps.h:533
dbus_uid_t uid
User owning file.
Definition: dbus-sysdeps.h:531
unsigned long mode
File mode.
Definition: dbus-sysdeps.h:529
dbus_gid_t gid
Group owning file.
Definition: dbus-sysdeps.h:532
unsigned long atime
Access time.
Definition: dbus-sysdeps.h:534
unsigned long ctime
Creation time.
Definition: dbus-sysdeps.h:536
unsigned long mtime
Modify time.
Definition: dbus-sysdeps.h:535