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