D-Bus 1.15.2
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 <stdio.h>
39#include <stdlib.h>
40#include <string.h>
41#include <signal.h>
42#include <unistd.h>
43#include <stdio.h>
44#include <errno.h>
45#include <fcntl.h>
46#include <limits.h>
47#include <sys/stat.h>
48#ifdef HAVE_SYS_RESOURCE_H
49#include <sys/resource.h>
50#endif
51#include <grp.h>
52#include <sys/socket.h>
53#include <dirent.h>
54#include <sys/un.h>
55
56#ifdef HAVE_SYS_PRCTL_H
57#include <sys/prctl.h>
58#endif
59
60#ifdef HAVE_SYSTEMD
61#include <systemd/sd-daemon.h>
62#endif
63
64#ifndef O_BINARY
65#define O_BINARY 0
66#endif
67
85 DBusPipe *print_pid_pipe,
86 DBusError *error,
87 dbus_bool_t keep_umask)
88{
89 const char *s;
90 pid_t child_pid;
91 DBusEnsureStandardFdsFlags flags;
92
93 _dbus_verbose ("Becoming a daemon...\n");
94
95 _dbus_verbose ("chdir to /\n");
96 if (chdir ("/") < 0)
97 {
99 "Could not chdir() to root directory");
100 return FALSE;
101 }
102
103 _dbus_verbose ("forking...\n");
104
105 /* Make sure our output buffers aren't redundantly printed by both the
106 * parent and the child */
107 fflush (stdout);
108 fflush (stderr);
109
110 switch ((child_pid = fork ()))
111 {
112 case -1:
113 _dbus_verbose ("fork failed\n");
115 "Failed to fork daemon: %s", _dbus_strerror (errno));
116 return FALSE;
117 break;
118
119 case 0:
120 _dbus_verbose ("in child, closing std file descriptors\n");
121
122 flags = DBUS_FORCE_STDIN_NULL | DBUS_FORCE_STDOUT_NULL;
123 s = _dbus_getenv ("DBUS_DEBUG_OUTPUT");
124
125 if (s == NULL || *s == '\0')
126 flags |= DBUS_FORCE_STDERR_NULL;
127 else
128 _dbus_verbose ("keeping stderr open due to DBUS_DEBUG_OUTPUT\n");
129
130 if (!_dbus_ensure_standard_fds (flags, &s))
131 {
132 _dbus_warn ("%s: %s", s, _dbus_strerror (errno));
133 _exit (1);
134 }
135
136 if (!keep_umask)
137 {
138 /* Get a predictable umask */
139 _dbus_verbose ("setting umask\n");
140 umask (022);
141 }
142
143 _dbus_verbose ("calling setsid()\n");
144 if (setsid () == -1)
145 _dbus_assert_not_reached ("setsid() failed");
146
147 break;
148
149 default:
150 if (!_dbus_write_pid_to_file_and_pipe (pidfile, print_pid_pipe,
151 child_pid, error))
152 {
153 _dbus_verbose ("pid file or pipe write failed: %s\n",
154 error->message);
155 kill (child_pid, SIGTERM);
156 return FALSE;
157 }
158
159 _dbus_verbose ("parent exiting\n");
160 _exit (0);
161 break;
162 }
163
164 return TRUE;
165}
166
167
176static dbus_bool_t
177_dbus_write_pid_file (const DBusString *filename,
178 unsigned long pid,
179 DBusError *error)
180{
181 const char *cfilename;
182 int fd;
183 FILE *f;
184
185 cfilename = _dbus_string_get_const_data (filename);
186
187 fd = open (cfilename, O_WRONLY|O_CREAT|O_EXCL|O_BINARY, 0644);
188
189 if (fd < 0)
190 {
192 "Failed to open \"%s\": %s", cfilename,
193 _dbus_strerror (errno));
194 return FALSE;
195 }
196
197 if ((f = fdopen (fd, "w")) == NULL)
198 {
200 "Failed to fdopen fd %d: %s", fd, _dbus_strerror (errno));
201 _dbus_close (fd, NULL);
202 return FALSE;
203 }
204
205 if (fprintf (f, "%lu\n", pid) < 0)
206 {
208 "Failed to write to \"%s\": %s", cfilename,
209 _dbus_strerror (errno));
210
211 fclose (f);
212 return FALSE;
213 }
214
215 if (fclose (f) == EOF)
216 {
218 "Failed to close \"%s\": %s", cfilename,
219 _dbus_strerror (errno));
220 return FALSE;
221 }
222
223 return TRUE;
224}
225
239 DBusPipe *print_pid_pipe,
240 dbus_pid_t pid_to_write,
241 DBusError *error)
242{
243 if (pidfile)
244 {
245 _dbus_verbose ("writing pid file %s\n", _dbus_string_get_const_data (pidfile));
246 if (!_dbus_write_pid_file (pidfile,
247 pid_to_write,
248 error))
249 {
250 _dbus_verbose ("pid file write failed\n");
251 _DBUS_ASSERT_ERROR_IS_SET(error);
252 return FALSE;
253 }
254 }
255 else
256 {
257 _dbus_verbose ("No pid file requested\n");
258 }
259
260 if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
261 {
262 DBusString pid;
263 int bytes;
264
265 _dbus_verbose ("writing our pid to pipe %d\n",
266 print_pid_pipe->fd);
267
268 if (!_dbus_string_init (&pid))
269 {
270 _DBUS_SET_OOM (error);
271 return FALSE;
272 }
273
274 if (!_dbus_string_append_int (&pid, pid_to_write) ||
275 !_dbus_string_append (&pid, "\n"))
276 {
277 _dbus_string_free (&pid);
278 _DBUS_SET_OOM (error);
279 return FALSE;
280 }
281
282 bytes = _dbus_string_get_length (&pid);
283 if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
284 {
285 /* _dbus_pipe_write sets error only on failure, not short write */
286 if (error != NULL && !dbus_error_is_set(error))
287 {
289 "Printing message bus PID: did not write enough bytes\n");
290 }
291 _dbus_string_free (&pid);
292 return FALSE;
293 }
294
295 _dbus_string_free (&pid);
296 }
297 else
298 {
299 _dbus_verbose ("No pid pipe to write to\n");
300 }
301
302 return TRUE;
303}
304
312_dbus_verify_daemon_user (const char *user)
313{
314 DBusString u;
315
316 _dbus_string_init_const (&u, user);
317
319}
320
321
322/* The HAVE_LIBAUDIT case lives in selinux.c */
323#ifndef HAVE_LIBAUDIT
333 DBusError *error)
334{
335 dbus_uid_t uid;
336 dbus_gid_t gid;
337 DBusString u;
338
339 _dbus_string_init_const (&u, user);
340
341 if (!_dbus_get_user_id_and_primary_group (&u, &uid, &gid))
342 {
344 "User '%s' does not appear to exist?",
345 user);
346 return FALSE;
347 }
348
349 /* setgroups() only works if we are a privileged process,
350 * so we don't return error on failure; the only possible
351 * failure is that we don't have perms to do it.
352 *
353 * not sure this is right, maybe if setuid()
354 * is going to work then setgroups() should also work.
355 */
356 if (setgroups (0, NULL) < 0)
357 _dbus_warn ("Failed to drop supplementary groups: %s",
358 _dbus_strerror (errno));
359
360 /* Set GID first, or the setuid may remove our permission
361 * to change the GID
362 */
363 if (setgid (gid) < 0)
364 {
366 "Failed to set GID to %lu: %s", gid,
367 _dbus_strerror (errno));
368 return FALSE;
369 }
370
371 if (setuid (uid) < 0)
372 {
374 "Failed to set UID to %lu: %s", uid,
375 _dbus_strerror (errno));
376 return FALSE;
377 }
378
379 return TRUE;
380}
381#endif /* !HAVE_LIBAUDIT */
382
383#ifdef HAVE_SETRLIMIT
384
385/* We assume that if we have setrlimit, we also have getrlimit and
386 * struct rlimit.
387 */
388
389struct DBusRLimit {
390 struct rlimit lim;
391};
392
393DBusRLimit *
394_dbus_rlimit_save_fd_limit (DBusError *error)
395{
396 DBusRLimit *self;
397
398 self = dbus_new0 (DBusRLimit, 1);
399
400 if (self == NULL)
401 {
402 _DBUS_SET_OOM (error);
403 return NULL;
404 }
405
406 if (getrlimit (RLIMIT_NOFILE, &self->lim) < 0)
407 {
409 "Failed to get fd limit: %s", _dbus_strerror (errno));
410 dbus_free (self);
411 return NULL;
412 }
413
414 return self;
415}
416
417/* Enough fds that we shouldn't run out, even if several uids work
418 * together to carry out a denial-of-service attack. This happens to be
419 * the same number that systemd < 234 would normally use. */
420#define ENOUGH_FDS 65536
421
423_dbus_rlimit_raise_fd_limit (DBusError *error)
424{
425 struct rlimit old, lim;
426
427 if (getrlimit (RLIMIT_NOFILE, &lim) < 0)
428 {
430 "Failed to get fd limit: %s", _dbus_strerror (errno));
431 return FALSE;
432 }
433
434 old = lim;
435
436 if (getuid () == 0)
437 {
438 /* We are privileged, so raise the soft limit to at least
439 * ENOUGH_FDS, and the hard limit to at least the desired soft
440 * limit. This assumes we can exercise CAP_SYS_RESOURCE on Linux,
441 * or other OSs' equivalents. */
442 if (lim.rlim_cur != RLIM_INFINITY &&
443 lim.rlim_cur < ENOUGH_FDS)
444 lim.rlim_cur = ENOUGH_FDS;
445
446 if (lim.rlim_max != RLIM_INFINITY &&
447 lim.rlim_max < lim.rlim_cur)
448 lim.rlim_max = lim.rlim_cur;
449 }
450
451 /* Raise the soft limit to match the hard limit, which we can do even
452 * if we are unprivileged. In particular, systemd >= 240 will normally
453 * set rlim_cur to 1024 and rlim_max to 512*1024, recent Debian
454 * versions end up setting rlim_cur to 1024 and rlim_max to 1024*1024,
455 * and older and non-systemd Linux systems would typically set rlim_cur
456 * to 1024 and rlim_max to 4096. */
457 if (lim.rlim_max == RLIM_INFINITY || lim.rlim_cur < lim.rlim_max)
458 {
459#if defined(__APPLE__) && defined(__MACH__)
460 /* macOS 10.5 and above no longer allows RLIM_INFINITY for rlim_cur */
461 lim.rlim_cur = MIN (OPEN_MAX, lim.rlim_max);
462#else
463 lim.rlim_cur = lim.rlim_max;
464#endif
465 }
466
467 /* Early-return if there is nothing to do. */
468 if (lim.rlim_max == old.rlim_max &&
469 lim.rlim_cur == old.rlim_cur)
470 return TRUE;
471
472 if (setrlimit (RLIMIT_NOFILE, &lim) < 0)
473 {
475 "Failed to set fd limit to %lu: %s",
476 (unsigned long) lim.rlim_cur,
477 _dbus_strerror (errno));
478 return FALSE;
479 }
480
481 return TRUE;
482}
483
485_dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
486 DBusError *error)
487{
488 if (setrlimit (RLIMIT_NOFILE, &saved->lim) < 0)
489 {
491 "Failed to restore old fd limit: %s",
492 _dbus_strerror (errno));
493 return FALSE;
494 }
495
496 return TRUE;
497}
498
499#else /* !HAVE_SETRLIMIT */
500
501static void
502fd_limit_not_supported (DBusError *error)
503{
505 "cannot change fd limit on this platform");
506}
507
508DBusRLimit *
509_dbus_rlimit_save_fd_limit (DBusError *error)
510{
511 fd_limit_not_supported (error);
512 return NULL;
513}
514
516_dbus_rlimit_raise_fd_limit (DBusError *error)
517{
518 fd_limit_not_supported (error);
519 return FALSE;
520}
521
523_dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
524 DBusError *error)
525{
526 fd_limit_not_supported (error);
527 return FALSE;
528}
529
530#endif
531
532void
533_dbus_rlimit_free (DBusRLimit *lim)
534{
535 dbus_free (lim);
536}
537
543void
545 DBusSignalHandler handler)
546{
547 struct sigaction act;
548 sigset_t empty_mask;
549
550 sigemptyset (&empty_mask);
551 act.sa_handler = handler;
552 act.sa_mask = empty_mask;
553 act.sa_flags = 0;
554 sigaction (sig, &act, NULL);
555}
556
563_dbus_file_exists (const char *file)
564{
565 return (access (file, F_OK) == 0);
566}
567
576{
577 if (_dbus_string_get_length (filename) > 0)
578 return _dbus_string_get_byte (filename, 0) == '/';
579 else
580 return FALSE;
581}
582
592_dbus_stat (const DBusString *filename,
593 DBusStat *statbuf,
594 DBusError *error)
595{
596 const char *filename_c;
597 struct stat sb;
598
599 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
600
601 filename_c = _dbus_string_get_const_data (filename);
602
603 if (stat (filename_c, &sb) < 0)
604 {
606 "%s", _dbus_strerror (errno));
607 return FALSE;
608 }
609
610 statbuf->mode = sb.st_mode;
611 statbuf->nlink = sb.st_nlink;
612 statbuf->uid = sb.st_uid;
613 statbuf->gid = sb.st_gid;
614 statbuf->size = sb.st_size;
615 statbuf->atime = sb.st_atime;
616 statbuf->mtime = sb.st_mtime;
617 statbuf->ctime = sb.st_ctime;
618
619 return TRUE;
620}
621
622
627{
628 DIR *d;
630};
631
641 DBusError *error)
642{
643 DIR *d;
644 DBusDirIter *iter;
645 const char *filename_c;
646
647 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
648
649 filename_c = _dbus_string_get_const_data (filename);
650
651 d = opendir (filename_c);
652 if (d == NULL)
653 {
655 "Failed to read directory \"%s\": %s",
656 filename_c,
657 _dbus_strerror (errno));
658 return NULL;
659 }
660 iter = dbus_new0 (DBusDirIter, 1);
661 if (iter == NULL)
662 {
663 closedir (d);
665 "Could not allocate memory for directory iterator");
666 return NULL;
667 }
668
669 iter->d = d;
670
671 return iter;
672}
673
689 DBusString *filename,
690 DBusError *error)
691{
692 struct dirent *ent;
693 int err;
694
695 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
696
697 again:
698 errno = 0;
699 ent = readdir (iter->d);
700
701 if (!ent)
702 {
703 err = errno;
704
705 if (err != 0)
706 dbus_set_error (error,
708 "%s", _dbus_strerror (err));
709
710 return FALSE;
711 }
712 else if (ent->d_name[0] == '.' &&
713 (ent->d_name[1] == '\0' ||
714 (ent->d_name[1] == '.' && ent->d_name[2] == '\0')))
715 goto again;
716 else
717 {
718 _dbus_string_set_length (filename, 0);
719 if (!_dbus_string_append (filename, ent->d_name))
720 {
722 "No memory to read directory entry");
723 return FALSE;
724 }
725 else
726 {
727 return TRUE;
728 }
729 }
730}
731
735void
737{
738 closedir (iter->d);
739 dbus_free (iter);
740}
741
742static dbus_bool_t
743fill_user_info_from_group (struct group *g,
744 DBusGroupInfo *info,
745 DBusError *error)
746{
747 _dbus_assert (g->gr_name != NULL);
748
749 info->gid = g->gr_gid;
750 info->groupname = _dbus_strdup (g->gr_name);
751
752 /* info->members = dbus_strdupv (g->gr_mem) */
753
754 if (info->groupname == NULL)
755 {
757 return FALSE;
758 }
759
760 return TRUE;
761}
762
763static dbus_bool_t
764fill_group_info (DBusGroupInfo *info,
765 dbus_gid_t gid,
766 const DBusString *groupname,
767 DBusError *error)
768{
769 const char *group_c_str;
770
771 _dbus_assert (groupname != NULL || gid != DBUS_GID_UNSET);
772 _dbus_assert (groupname == NULL || gid == DBUS_GID_UNSET);
773
774 if (groupname)
775 group_c_str = _dbus_string_get_const_data (groupname);
776 else
777 group_c_str = NULL;
778
779 /* For now assuming that the getgrnam() and getgrgid() flavors
780 * always correspond to the pwnam flavors, if not we have
781 * to add more configure checks.
782 */
783
784#ifdef HAVE_GETPWNAM_R
785 {
786 struct group *g;
787 int result;
788 size_t buflen;
789 char *buf;
790 struct group g_str;
791 dbus_bool_t b;
792
793 /* retrieve maximum needed size for buf */
794 buflen = sysconf (_SC_GETGR_R_SIZE_MAX);
795
796 /* sysconf actually returns a long, but everything else expects size_t,
797 * so just recast here.
798 * https://bugs.freedesktop.org/show_bug.cgi?id=17061
799 */
800 if ((long) buflen <= 0)
801 buflen = 1024;
802
803 result = -1;
804 while (1)
805 {
806 buf = dbus_malloc (buflen);
807 if (buf == NULL)
808 {
810 return FALSE;
811 }
812
813 g = NULL;
814 if (group_c_str)
815 result = getgrnam_r (group_c_str, &g_str, buf, buflen,
816 &g);
817 else
818 result = getgrgid_r (gid, &g_str, buf, buflen,
819 &g);
820 /* Try a bigger buffer if ERANGE was returned:
821 https://bugs.freedesktop.org/show_bug.cgi?id=16727
822 */
823 if (result == ERANGE && buflen < 512 * 1024)
824 {
825 dbus_free (buf);
826 buflen *= 2;
827 }
828 else
829 {
830 break;
831 }
832 }
833
834 if (result == 0 && g == &g_str)
835 {
836 b = fill_user_info_from_group (g, info, error);
837 dbus_free (buf);
838 return b;
839 }
840 else
841 {
843 "Group %s unknown or failed to look it up\n",
844 group_c_str ? group_c_str : "???");
845 dbus_free (buf);
846 return FALSE;
847 }
848 }
849#else /* ! HAVE_GETPWNAM_R */
850 {
851 /* I guess we're screwed on thread safety here */
852 struct group *g;
853
854#warning getpwnam_r() not available, please report this to the dbus maintainers with details of your OS
855
856 g = getgrnam (group_c_str);
857
858 if (g != NULL)
859 {
860 return fill_user_info_from_group (g, info, error);
861 }
862 else
863 {
865 "Group %s unknown or failed to look it up\n",
866 group_c_str ? group_c_str : "???");
867 return FALSE;
868 }
869 }
870#endif /* ! HAVE_GETPWNAM_R */
871}
872
884 const DBusString *groupname,
885 DBusError *error)
886{
887 return fill_group_info (info, DBUS_GID_UNSET,
888 groupname, error);
889
890}
891
903 dbus_gid_t gid,
904 DBusError *error)
905{
906 return fill_group_info (info, gid, NULL, error);
907}
908
919 dbus_uid_t *uid_p)
920{
921 return _dbus_get_user_id (username, uid_p);
922
923}
924
935 dbus_gid_t *gid_p)
936{
937 return _dbus_get_group_id (groupname, gid_p);
938}
939
952 dbus_gid_t **group_ids,
953 int *n_group_ids)
954{
955 return _dbus_groups_from_uid (uid, group_ids, n_group_ids);
956}
957
969 DBusError *error)
970{
971 return _dbus_is_console_user (uid, error);
972
973}
974
984{
985 return uid == _dbus_geteuid ();
986}
987
996_dbus_windows_user_is_process_owner (const char *windows_sid)
997{
998 return FALSE;
999}
1000 /* End of DBusInternalsUtils functions */
1002
1016 DBusString *dirname)
1017{
1018 int sep;
1019
1020 _dbus_assert (filename != dirname);
1021 _dbus_assert (filename != NULL);
1022 _dbus_assert (dirname != NULL);
1023
1024 /* Ignore any separators on the end */
1025 sep = _dbus_string_get_length (filename);
1026 if (sep == 0)
1027 return _dbus_string_append (dirname, "."); /* empty string passed in */
1028
1029 while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1030 --sep;
1031
1032 _dbus_assert (sep >= 0);
1033
1034 if (sep == 0)
1035 return _dbus_string_append (dirname, "/");
1036
1037 /* Now find the previous separator */
1038 _dbus_string_find_byte_backward (filename, sep, '/', &sep);
1039 if (sep < 0)
1040 return _dbus_string_append (dirname, ".");
1041
1042 /* skip multiple separators */
1043 while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1044 --sep;
1045
1046 _dbus_assert (sep >= 0);
1047
1048 if (sep == 0 &&
1049 _dbus_string_get_byte (filename, 0) == '/')
1050 return _dbus_string_append (dirname, "/");
1051 else
1052 return _dbus_string_copy_len (filename, 0, sep - 0,
1053 dirname, _dbus_string_get_length (dirname));
1054} /* DBusString stuff */
1056
1057static void
1058string_squash_nonprintable (DBusString *str)
1059{
1060 unsigned char *buf;
1061 int i, len;
1062
1063 buf = _dbus_string_get_udata (str);
1064 len = _dbus_string_get_length (str);
1065
1066 /* /proc/$pid/cmdline is a sequence of \0-terminated words, but we
1067 * want a sequence of space-separated words, with no extra trailing
1068 * space:
1069 * "/bin/sleep" "\0" "60" "\0"
1070 * -> "/bin/sleep" "\0" "60"
1071 * -> "/bin/sleep" " " "60"
1072 *
1073 * so chop off the trailing NUL before cleaning up unprintable
1074 * characters. */
1075 if (len > 0 && buf[len - 1] == '\0')
1076 {
1077 _dbus_string_shorten (str, 1);
1078 len--;
1079 }
1080
1081 for (i = 0; i < len; i++)
1082 {
1083 unsigned char c = (unsigned char) buf[i];
1084 if (c == '\0')
1085 buf[i] = ' ';
1086 else if (c < 0x20 || c > 127)
1087 buf[i] = '?';
1088 }
1089}
1090
1106_dbus_command_for_pid (unsigned long pid,
1107 DBusString *str,
1108 int max_len,
1109 DBusError *error)
1110{
1111 /* This is all Linux-specific for now */
1112 DBusString path;
1113 DBusString cmdline;
1114 int fd;
1115
1116 if (!_dbus_string_init (&path))
1117 {
1118 _DBUS_SET_OOM (error);
1119 return FALSE;
1120 }
1121
1122 if (!_dbus_string_init (&cmdline))
1123 {
1124 _DBUS_SET_OOM (error);
1125 _dbus_string_free (&path);
1126 return FALSE;
1127 }
1128
1129 if (!_dbus_string_append_printf (&path, "/proc/%ld/cmdline", pid))
1130 goto oom;
1131
1132 fd = open (_dbus_string_get_const_data (&path), O_RDONLY);
1133 if (fd < 0)
1134 {
1135 dbus_set_error (error,
1136 _dbus_error_from_errno (errno),
1137 "Failed to open \"%s\": %s",
1138 _dbus_string_get_const_data (&path),
1139 _dbus_strerror (errno));
1140 goto fail;
1141 }
1142
1143 if (!_dbus_read (fd, &cmdline, max_len))
1144 {
1145 dbus_set_error (error,
1146 _dbus_error_from_errno (errno),
1147 "Failed to read from \"%s\": %s",
1148 _dbus_string_get_const_data (&path),
1149 _dbus_strerror (errno));
1150 _dbus_close (fd, NULL);
1151 goto fail;
1152 }
1153
1154 if (!_dbus_close (fd, error))
1155 goto fail;
1156
1157 string_squash_nonprintable (&cmdline);
1158
1159 if (!_dbus_string_copy (&cmdline, 0, str, _dbus_string_get_length (str)))
1160 goto oom;
1161
1162 _dbus_string_free (&cmdline);
1163 _dbus_string_free (&path);
1164 return TRUE;
1165oom:
1166 _DBUS_SET_OOM (error);
1167fail:
1168 _dbus_string_free (&cmdline);
1169 _dbus_string_free (&path);
1170 return FALSE;
1171}
1172
1183{
1184 return TRUE;
1185}
1186
1187static dbus_bool_t
1188ensure_owned_directory (const char *label,
1189 const DBusString *string,
1190 dbus_bool_t create,
1191 DBusError *error)
1192{
1193 const char *dir = _dbus_string_get_const_data (string);
1194 struct stat buf;
1195
1196 if (create && !_dbus_ensure_directory (string, error))
1197 return FALSE;
1198
1199 /*
1200 * The stat()-based checks in this function are to protect against
1201 * mistakes, not malice. We are working in a directory that is meant
1202 * to be trusted; but if a user has used `su` or similar to escalate
1203 * their privileges without correctly clearing the environment, the
1204 * XDG_RUNTIME_DIR in the environment might still be the user's
1205 * and not root's. We don't want to write root-owned files into that
1206 * directory, so just warn and don't provide support for transient
1207 * services in that case.
1208 *
1209 * In particular, we use stat() and not lstat() so that if we later
1210 * decide to use a different directory name for transient services,
1211 * we can drop in a compatibility symlink without breaking older
1212 * libdbus.
1213 */
1214
1215 if (stat (dir, &buf) != 0)
1216 {
1217 int saved_errno = errno;
1218
1219 dbus_set_error (error, _dbus_error_from_errno (saved_errno),
1220 "%s \"%s\" not available: %s", label, dir,
1221 _dbus_strerror (saved_errno));
1222 return FALSE;
1223 }
1224
1225 if (!S_ISDIR (buf.st_mode))
1226 {
1227 dbus_set_error (error, DBUS_ERROR_FAILED, "%s \"%s\" is not a directory",
1228 label, dir);
1229 return FALSE;
1230 }
1231
1232 if (buf.st_uid != geteuid ())
1233 {
1235 "%s \"%s\" is owned by uid %ld, not our uid %ld",
1236 label, dir, (long) buf.st_uid, (long) geteuid ());
1237 return FALSE;
1238 }
1239
1240 /* This is just because we have the stat() results already, so we might
1241 * as well check opportunistically. */
1242 if ((S_IWOTH | S_IWGRP) & buf.st_mode)
1243 {
1245 "%s \"%s\" can be written by others (mode 0%o)",
1246 label, dir, buf.st_mode);
1247 return FALSE;
1248 }
1249
1250 return TRUE;
1251}
1252
1253#define DBUS_UNIX_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
1254#define DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"
1255
1265 DBusError *error)
1266{
1267 const char *xdg_runtime_dir;
1268 DBusString services;
1269 DBusString dbus1;
1270 DBusString xrd;
1271 dbus_bool_t ret = FALSE;
1272 char *data = NULL;
1273
1274 if (!_dbus_string_init (&dbus1))
1275 {
1276 _DBUS_SET_OOM (error);
1277 return FALSE;
1278 }
1279
1280 if (!_dbus_string_init (&services))
1281 {
1282 _dbus_string_free (&dbus1);
1283 _DBUS_SET_OOM (error);
1284 return FALSE;
1285 }
1286
1287 if (!_dbus_string_init (&xrd))
1288 {
1289 _dbus_string_free (&dbus1);
1290 _dbus_string_free (&services);
1291 _DBUS_SET_OOM (error);
1292 return FALSE;
1293 }
1294
1295 xdg_runtime_dir = _dbus_getenv ("XDG_RUNTIME_DIR");
1296
1297 /* Not an error, we just can't have transient session services */
1298 if (xdg_runtime_dir == NULL)
1299 {
1300 _dbus_verbose ("XDG_RUNTIME_DIR is unset: transient session services "
1301 "not available here\n");
1302 ret = TRUE;
1303 goto out;
1304 }
1305
1306 if (!_dbus_string_append (&xrd, xdg_runtime_dir) ||
1307 !_dbus_string_append_printf (&dbus1, "%s/dbus-1",
1308 xdg_runtime_dir) ||
1309 !_dbus_string_append_printf (&services, "%s/dbus-1/services",
1310 xdg_runtime_dir))
1311 {
1312 _DBUS_SET_OOM (error);
1313 goto out;
1314 }
1315
1316 if (!ensure_owned_directory ("XDG_RUNTIME_DIR", &xrd, FALSE, error) ||
1317 !ensure_owned_directory ("XDG_RUNTIME_DIR subdirectory", &dbus1, TRUE,
1318 error) ||
1319 !ensure_owned_directory ("XDG_RUNTIME_DIR subdirectory", &services,
1320 TRUE, error))
1321 goto out;
1322
1323 if (!_dbus_string_steal_data (&services, &data) ||
1324 !_dbus_list_append (dirs, data))
1325 {
1326 _DBUS_SET_OOM (error);
1327 goto out;
1328 }
1329
1330 _dbus_verbose ("Transient service directory is %s\n", data);
1331 /* Ownership was transferred to @dirs */
1332 data = NULL;
1333 ret = TRUE;
1334
1335out:
1336 _dbus_string_free (&dbus1);
1337 _dbus_string_free (&services);
1338 _dbus_string_free (&xrd);
1339 dbus_free (data);
1340 return ret;
1341}
1342
1362{
1363 const char *xdg_data_home;
1364 const char *xdg_data_dirs;
1365 DBusString servicedir_path;
1366
1367 if (!_dbus_string_init (&servicedir_path))
1368 return FALSE;
1369
1370 xdg_data_home = _dbus_getenv ("XDG_DATA_HOME");
1371 xdg_data_dirs = _dbus_getenv ("XDG_DATA_DIRS");
1372
1373 if (xdg_data_home != NULL)
1374 {
1375 if (!_dbus_string_append (&servicedir_path, xdg_data_home))
1376 goto oom;
1377 }
1378 else
1379 {
1380 const DBusString *homedir;
1381 DBusString local_share;
1382
1383 if (!_dbus_homedir_from_current_process (&homedir))
1384 goto oom;
1385
1386 if (!_dbus_string_append (&servicedir_path, _dbus_string_get_const_data (homedir)))
1387 goto oom;
1388
1389 _dbus_string_init_const (&local_share, "/.local/share");
1390 if (!_dbus_concat_dir_and_file (&servicedir_path, &local_share))
1391 goto oom;
1392 }
1393
1394 if (!_dbus_string_append (&servicedir_path, ":"))
1395 goto oom;
1396
1397 if (xdg_data_dirs != NULL)
1398 {
1399 if (!_dbus_string_append (&servicedir_path, xdg_data_dirs))
1400 goto oom;
1401
1402 if (!_dbus_string_append (&servicedir_path, ":"))
1403 goto oom;
1404 }
1405 else
1406 {
1407 if (!_dbus_string_append (&servicedir_path, "/usr/local/share:/usr/share:"))
1408 goto oom;
1409 }
1410
1411 /*
1412 * add configured datadir to defaults
1413 * this may be the same as an xdg dir
1414 * however the config parser should take
1415 * care of duplicates
1416 */
1417 if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR))
1418 goto oom;
1419
1420 if (!_dbus_split_paths_and_append (&servicedir_path,
1421 DBUS_UNIX_STANDARD_SESSION_SERVICEDIR,
1422 dirs))
1423 goto oom;
1424
1425 _dbus_string_free (&servicedir_path);
1426 return TRUE;
1427
1428 oom:
1429 _dbus_string_free (&servicedir_path);
1430 return FALSE;
1431}
1432
1433
1454{
1455 /*
1456 * DBUS_DATADIR may be the same as one of the standard directories. However,
1457 * the config parser should take care of the duplicates.
1458 *
1459 * Also, append /lib as counterpart of /usr/share on the root
1460 * directory (the root directory does not know /share), in order to
1461 * facilitate early boot system bus activation where /usr might not
1462 * be available.
1463 */
1464 static const char standard_search_path[] =
1465 "/usr/local/share:"
1466 "/usr/share:"
1467 DBUS_DATADIR ":"
1468 "/lib";
1469 DBusString servicedir_path;
1470
1471 _dbus_string_init_const (&servicedir_path, standard_search_path);
1472
1473 return _dbus_split_paths_and_append (&servicedir_path,
1474 DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR,
1475 dirs);
1476}
1477
1488{
1489 _dbus_assert (_dbus_string_get_length (str) == 0);
1490
1491 return _dbus_string_append (str, DBUS_SYSTEM_CONFIG_FILE);
1492}
1493
1502{
1503 _dbus_assert (_dbus_string_get_length (str) == 0);
1504
1505 return _dbus_string_append (str, DBUS_SESSION_CONFIG_FILE);
1506}
1507
1512void
1514{
1515#ifdef HAVE_SYSTEMD
1516 sd_notify (0, "READY=1");
1517#endif
1518}
1519
1524void
1526{
1527#ifdef HAVE_SYSTEMD
1528 sd_notify (0, "RELOADING=1");
1529#endif
1530}
1531
1536void
1538{
1539#ifdef HAVE_SYSTEMD
1540 /* For systemd, this is the same code */
1542#endif
1543}
1544
1549void
1551{
1552#ifdef HAVE_SYSTEMD
1553 sd_notify (0, "STOPPING=1");
1554#endif
1555}
1556
1571_dbus_reset_oom_score_adj (const char **error_str_p)
1572{
1573#ifdef __linux__
1574 int fd = -1;
1575 dbus_bool_t ret = FALSE;
1576 int saved_errno = 0;
1577 const char *error_str = NULL;
1578
1579#ifdef O_CLOEXEC
1580 fd = open ("/proc/self/oom_score_adj", O_RDONLY | O_CLOEXEC);
1581#endif
1582
1583 if (fd < 0)
1584 {
1585 fd = open ("/proc/self/oom_score_adj", O_RDONLY);
1586 if (fd >= 0)
1588 }
1589
1590 if (fd >= 0)
1591 {
1592 ssize_t read_result = -1;
1593 /* It doesn't actually matter whether we read the whole file,
1594 * as long as we get the presence or absence of the minus sign */
1595 char first_char = '\0';
1596
1597 read_result = read (fd, &first_char, 1);
1598
1599 if (read_result < 0)
1600 {
1601 /* This probably can't actually happen in practice: if we can
1602 * open it, then we can hopefully read from it */
1603 ret = FALSE;
1604 error_str = "failed to read from /proc/self/oom_score_adj";
1605 saved_errno = errno;
1606 goto out;
1607 }
1608
1609 /* If we are running with protection from the OOM killer
1610 * (typical for the system dbus-daemon under systemd), then
1611 * oom_score_adj will be negative. Drop that protection,
1612 * returning to oom_score_adj = 0.
1613 *
1614 * Conversely, if we are running with increased susceptibility
1615 * to the OOM killer (as user sessions typically do in
1616 * systemd >= 250), oom_score_adj will be strictly positive,
1617 * and we are not allowed to decrease it to 0 without privileges.
1618 *
1619 * If it's exactly 0 (typical for non-systemd systems, and
1620 * user processes on older systemd) then there's no need to
1621 * alter it.
1622 *
1623 * We shouldn't get an empty result, but if we do, assume it
1624 * means zero and don't try to change it. */
1625 if (read_result == 0 || first_char != '-')
1626 {
1627 /* Nothing needs to be done: the OOM score adjustment is
1628 * non-negative */
1629 ret = TRUE;
1630 goto out;
1631 }
1632
1633 close (fd);
1634#ifdef O_CLOEXEC
1635 fd = open ("/proc/self/oom_score_adj", O_WRONLY | O_CLOEXEC);
1636
1637 if (fd < 0)
1638#endif
1639 {
1640 fd = open ("/proc/self/oom_score_adj", O_WRONLY);
1641 if (fd >= 0)
1643 }
1644
1645 if (fd < 0)
1646 {
1647 ret = FALSE;
1648 error_str = "open(/proc/self/oom_score_adj) for writing";
1649 saved_errno = errno;
1650 goto out;
1651 }
1652
1653 if (pwrite (fd, "0", sizeof (char), 0) < 0)
1654 {
1655 ret = FALSE;
1656 error_str = "writing oom_score_adj error";
1657 saved_errno = errno;
1658 goto out;
1659 }
1660
1661 /* Success */
1662 ret = TRUE;
1663 }
1664 else if (errno == ENOENT)
1665 {
1666 /* If /proc/self/oom_score_adj doesn't exist, assume the kernel
1667 * doesn't support this feature and ignore it. */
1668 ret = TRUE;
1669 }
1670 else
1671 {
1672 ret = FALSE;
1673 error_str = "open(/proc/self/oom_score_adj) for reading";
1674 saved_errno = errno;
1675 goto out;
1676 }
1677
1678out:
1679 if (fd >= 0)
1680 _dbus_close (fd, NULL);
1681
1682 if (error_str_p != NULL)
1683 *error_str_p = error_str;
1684
1685 errno = saved_errno;
1686 return ret;
1687#else
1688 /* nothing to do on this platform */
1689 return TRUE;
1690#endif
1691}
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:440
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.
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:599
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:271
#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:692
#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:452
#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:845
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:978
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:180
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:195
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:1343
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_string_append_int(DBusString *str, long value)
Appends an integer to a DBusString.
Definition: dbus-sysdeps.c:363
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:684
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as _DBUS_STRING_IN...
Definition: dbus-string.c:276
void _dbus_string_shorten(DBusString *str, int length_to_remove)
Makes a string shorter by the given number of bytes.
Definition: dbus-string.c:823
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:1145
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:1435
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.
void _dbus_daemon_report_ready(void)
Report to a service manager that the daemon calling this function is ready for use.
unsigned long dbus_uid_t
A user ID.
Definition: dbus-sysdeps.h:135
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:133
void _dbus_daemon_report_reloading(void)
Report to a service manager that the daemon calling this function is reloading configuration.
unsigned long dbus_gid_t
A group ID.
Definition: dbus-sysdeps.h:137
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:195
dbus_bool_t _dbus_get_standard_system_servicedirs(DBusList **dirs)
Returns the standard directories for a system bus to look for service activation files.
void _dbus_daemon_report_reloaded(void)
Report to a service manager that the daemon calling this function is reloading configuration.
#define DBUS_GID_UNSET
an invalid GID used to represent an uninitialized dbus_gid_t field
Definition: dbus-sysdeps.h:144
void _dbus_daemon_report_stopping(void)
Report to a service manager that the daemon calling this function is shutting down.
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:236
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:548
unsigned long nlink
Number of hard links.
Definition: dbus-sysdeps.h:550
unsigned long size
Size of file.
Definition: dbus-sysdeps.h:553
dbus_uid_t uid
User owning file.
Definition: dbus-sysdeps.h:551
unsigned long mode
File mode.
Definition: dbus-sysdeps.h:549
dbus_gid_t gid
Group owning file.
Definition: dbus-sysdeps.h:552
unsigned long atime
Access time.
Definition: dbus-sysdeps.h:554
unsigned long ctime
Creation time.
Definition: dbus-sysdeps.h:556
unsigned long mtime
Modify time.
Definition: dbus-sysdeps.h:555