D-Bus 1.14.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 * 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#ifdef HAVE_PDPLINUX
65#include <sys/capability.h>
66#endif
67
68#ifndef O_BINARY
69#define O_BINARY 0
70#endif
71
89 DBusPipe *print_pid_pipe,
90 DBusError *error,
91 dbus_bool_t keep_umask)
92{
93 const char *s;
94 pid_t child_pid;
95 DBusEnsureStandardFdsFlags flags;
96
97 _dbus_verbose ("Becoming a daemon...\n");
98
99 _dbus_verbose ("chdir to /\n");
100 if (chdir ("/") < 0)
101 {
103 "Could not chdir() to root directory");
104 return FALSE;
105 }
106
107 _dbus_verbose ("forking...\n");
108
109 /* Make sure our output buffers aren't redundantly printed by both the
110 * parent and the child */
111 fflush (stdout);
112 fflush (stderr);
113
114 switch ((child_pid = fork ()))
115 {
116 case -1:
117 _dbus_verbose ("fork failed\n");
119 "Failed to fork daemon: %s", _dbus_strerror (errno));
120 return FALSE;
121 break;
122
123 case 0:
124 _dbus_verbose ("in child, closing std file descriptors\n");
125
126 flags = DBUS_FORCE_STDIN_NULL | DBUS_FORCE_STDOUT_NULL;
127 s = _dbus_getenv ("DBUS_DEBUG_OUTPUT");
128
129 if (s == NULL || *s == '\0')
130 flags |= DBUS_FORCE_STDERR_NULL;
131 else
132 _dbus_verbose ("keeping stderr open due to DBUS_DEBUG_OUTPUT\n");
133
134 if (!_dbus_ensure_standard_fds (flags, &s))
135 {
136 _dbus_warn ("%s: %s", s, _dbus_strerror (errno));
137 _exit (1);
138 }
139
140 if (!keep_umask)
141 {
142 /* Get a predictable umask */
143 _dbus_verbose ("setting umask\n");
144 umask (022);
145 }
146
147 _dbus_verbose ("calling setsid()\n");
148 if (setsid () == -1)
149 _dbus_assert_not_reached ("setsid() failed");
150
151 break;
152
153 default:
154 if (!_dbus_write_pid_to_file_and_pipe (pidfile, print_pid_pipe,
155 child_pid, error))
156 {
157 _dbus_verbose ("pid file or pipe write failed: %s\n",
158 error->message);
159 kill (child_pid, SIGTERM);
160 return FALSE;
161 }
162
163 _dbus_verbose ("parent exiting\n");
164 _exit (0);
165 break;
166 }
167
168 return TRUE;
169}
170
171
180static dbus_bool_t
181_dbus_write_pid_file (const DBusString *filename,
182 unsigned long pid,
183 DBusError *error)
184{
185 const char *cfilename;
186 int fd;
187 FILE *f;
188
189 cfilename = _dbus_string_get_const_data (filename);
190
191 fd = open (cfilename, O_WRONLY|O_CREAT|O_EXCL|O_BINARY, 0644);
192
193 if (fd < 0)
194 {
196 "Failed to open \"%s\": %s", cfilename,
197 _dbus_strerror (errno));
198 return FALSE;
199 }
200
201 if ((f = fdopen (fd, "w")) == NULL)
202 {
204 "Failed to fdopen fd %d: %s", fd, _dbus_strerror (errno));
205 _dbus_close (fd, NULL);
206 return FALSE;
207 }
208
209 if (fprintf (f, "%lu\n", pid) < 0)
210 {
212 "Failed to write to \"%s\": %s", cfilename,
213 _dbus_strerror (errno));
214
215 fclose (f);
216 return FALSE;
217 }
218
219 if (fclose (f) == EOF)
220 {
222 "Failed to close \"%s\": %s", cfilename,
223 _dbus_strerror (errno));
224 return FALSE;
225 }
226
227 return TRUE;
228}
229
243 DBusPipe *print_pid_pipe,
244 dbus_pid_t pid_to_write,
245 DBusError *error)
246{
247 if (pidfile)
248 {
249 _dbus_verbose ("writing pid file %s\n", _dbus_string_get_const_data (pidfile));
250 if (!_dbus_write_pid_file (pidfile,
251 pid_to_write,
252 error))
253 {
254 _dbus_verbose ("pid file write failed\n");
255 _DBUS_ASSERT_ERROR_IS_SET(error);
256 return FALSE;
257 }
258 }
259 else
260 {
261 _dbus_verbose ("No pid file requested\n");
262 }
263
264 if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
265 {
266 DBusString pid;
267 int bytes;
268
269 _dbus_verbose ("writing our pid to pipe %d\n",
270 print_pid_pipe->fd);
271
272 if (!_dbus_string_init (&pid))
273 {
274 _DBUS_SET_OOM (error);
275 return FALSE;
276 }
277
278 if (!_dbus_string_append_int (&pid, pid_to_write) ||
279 !_dbus_string_append (&pid, "\n"))
280 {
281 _dbus_string_free (&pid);
282 _DBUS_SET_OOM (error);
283 return FALSE;
284 }
285
286 bytes = _dbus_string_get_length (&pid);
287 if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
288 {
289 /* _dbus_pipe_write sets error only on failure, not short write */
290 if (error != NULL && !dbus_error_is_set(error))
291 {
293 "Printing message bus PID: did not write enough bytes\n");
294 }
295 _dbus_string_free (&pid);
296 return FALSE;
297 }
298
299 _dbus_string_free (&pid);
300 }
301 else
302 {
303 _dbus_verbose ("No pid pipe to write to\n");
304 }
305
306 return TRUE;
307}
308
316_dbus_verify_daemon_user (const char *user)
317{
318 DBusString u;
319
320 _dbus_string_init_const (&u, user);
321
323}
324
325
326/* The HAVE_LIBAUDIT case lives in selinux.c */
327#ifndef HAVE_LIBAUDIT
337 DBusError *error)
338{
339 dbus_uid_t uid;
340 dbus_gid_t gid;
341 DBusString u;
342
343 _dbus_string_init_const (&u, user);
344
345 if (!_dbus_get_user_id_and_primary_group (&u, &uid, &gid))
346 {
348 "User '%s' does not appear to exist?",
349 user);
350 return FALSE;
351 }
352
353 /* setgroups() only works if we are a privileged process,
354 * so we don't return error on failure; the only possible
355 * failure is that we don't have perms to do it.
356 *
357 * not sure this is right, maybe if setuid()
358 * is going to work then setgroups() should also work.
359 */
360 if (setgroups (0, NULL) < 0)
361 _dbus_warn ("Failed to drop supplementary groups: %s",
362 _dbus_strerror (errno));
363
364 /* Set GID first, or the setuid may remove our permission
365 * to change the GID
366 */
367 if (setgid (gid) < 0)
368 {
370 "Failed to set GID to %lu: %s", gid,
371 _dbus_strerror (errno));
372 return FALSE;
373 }
374
375 if (setuid (uid) < 0)
376 {
378 "Failed to set UID to %lu: %s", uid,
379 _dbus_strerror (errno));
380 return FALSE;
381 }
382
383#ifdef HAVE_PDPLINUX
384 if (uid == 0){
385 /* Add special capabilities to read /proc for process name detection
386 * when Not enabled HAVE_LIBAUDIT and started by root.
387 */
388 cap_t capsproc=NULL;
389 cap_value_t cap_val=0;
390 capsproc=cap_get_proc();
391
392 // Set all caps from CAP_INHERITABLE but needed only CAP_SYS_ADMIN CAP_DAC_OVERRIDE CAP_SYS_PTRACE
393 // Set all CAP_INHERITABLE caps (which setted by systemd daemon) to CAP_EFFECTIVE
394
395 while (cap_val<=CAP_LAST_CAP){
396 cap_flag_value_t val;
397
398 if (0==cap_get_flag(capsproc,
399 cap_val,
400 CAP_INHERITABLE,
401 &val)){
402 cap_set_flag(capsproc, CAP_EFFECTIVE, 1, &cap_val, val);
403 }
404
405 cap_val++;
406 }
407
408 cap_set_proc(capsproc);
409
410 if (capsproc) cap_free(capsproc);
411 }
412#endif
413
414 return TRUE;
415}
416#endif /* !HAVE_LIBAUDIT */
417
418#ifdef HAVE_SETRLIMIT
419
420/* We assume that if we have setrlimit, we also have getrlimit and
421 * struct rlimit.
422 */
423
424struct DBusRLimit {
425 struct rlimit lim;
426};
427
428DBusRLimit *
429_dbus_rlimit_save_fd_limit (DBusError *error)
430{
431 DBusRLimit *self;
432
433 self = dbus_new0 (DBusRLimit, 1);
434
435 if (self == NULL)
436 {
437 _DBUS_SET_OOM (error);
438 return NULL;
439 }
440
441 if (getrlimit (RLIMIT_NOFILE, &self->lim) < 0)
442 {
444 "Failed to get fd limit: %s", _dbus_strerror (errno));
445 dbus_free (self);
446 return NULL;
447 }
448
449 return self;
450}
451
452/* Enough fds that we shouldn't run out, even if several uids work
453 * together to carry out a denial-of-service attack. This happens to be
454 * the same number that systemd < 234 would normally use. */
455#define ENOUGH_FDS 65536
456
458_dbus_rlimit_raise_fd_limit (DBusError *error)
459{
460 struct rlimit old, lim;
461
462 if (getrlimit (RLIMIT_NOFILE, &lim) < 0)
463 {
465 "Failed to get fd limit: %s", _dbus_strerror (errno));
466 return FALSE;
467 }
468
469 old = lim;
470
471 if (getuid () == 0)
472 {
473 /* We are privileged, so raise the soft limit to at least
474 * ENOUGH_FDS, and the hard limit to at least the desired soft
475 * limit. This assumes we can exercise CAP_SYS_RESOURCE on Linux,
476 * or other OSs' equivalents. */
477 if (lim.rlim_cur != RLIM_INFINITY &&
478 lim.rlim_cur < ENOUGH_FDS)
479 lim.rlim_cur = ENOUGH_FDS;
480
481 if (lim.rlim_max != RLIM_INFINITY &&
482 lim.rlim_max < lim.rlim_cur)
483 lim.rlim_max = lim.rlim_cur;
484 }
485
486 /* Raise the soft limit to match the hard limit, which we can do even
487 * if we are unprivileged. In particular, systemd >= 240 will normally
488 * set rlim_cur to 1024 and rlim_max to 512*1024, recent Debian
489 * versions end up setting rlim_cur to 1024 and rlim_max to 1024*1024,
490 * and older and non-systemd Linux systems would typically set rlim_cur
491 * to 1024 and rlim_max to 4096. */
492 if (lim.rlim_max == RLIM_INFINITY || lim.rlim_cur < lim.rlim_max)
493 {
494#if defined(__APPLE__) && defined(__MACH__)
495 /* macOS 10.5 and above no longer allows RLIM_INFINITY for rlim_cur */
496 lim.rlim_cur = MIN (OPEN_MAX, lim.rlim_max);
497#else
498 lim.rlim_cur = lim.rlim_max;
499#endif
500 }
501
502 /* Early-return if there is nothing to do. */
503 if (lim.rlim_max == old.rlim_max &&
504 lim.rlim_cur == old.rlim_cur)
505 return TRUE;
506
507 if (setrlimit (RLIMIT_NOFILE, &lim) < 0)
508 {
510 "Failed to set fd limit to %lu: %s",
511 (unsigned long) lim.rlim_cur,
512 _dbus_strerror (errno));
513 return FALSE;
514 }
515
516 return TRUE;
517}
518
520_dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
521 DBusError *error)
522{
523 if (setrlimit (RLIMIT_NOFILE, &saved->lim) < 0)
524 {
526 "Failed to restore old fd limit: %s",
527 _dbus_strerror (errno));
528 return FALSE;
529 }
530
531 return TRUE;
532}
533
534#else /* !HAVE_SETRLIMIT */
535
536static void
537fd_limit_not_supported (DBusError *error)
538{
540 "cannot change fd limit on this platform");
541}
542
543DBusRLimit *
544_dbus_rlimit_save_fd_limit (DBusError *error)
545{
546 fd_limit_not_supported (error);
547 return NULL;
548}
549
551_dbus_rlimit_raise_fd_limit (DBusError *error)
552{
553 fd_limit_not_supported (error);
554 return FALSE;
555}
556
558_dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
559 DBusError *error)
560{
561 fd_limit_not_supported (error);
562 return FALSE;
563}
564
565#endif
566
567void
568_dbus_rlimit_free (DBusRLimit *lim)
569{
570 dbus_free (lim);
571}
572
578void
580 DBusSignalHandler handler)
581{
582 struct sigaction act;
583 sigset_t empty_mask;
584
585 sigemptyset (&empty_mask);
586 act.sa_handler = handler;
587 act.sa_mask = empty_mask;
588 act.sa_flags = 0;
589 sigaction (sig, &act, NULL);
590}
591
598_dbus_file_exists (const char *file)
599{
600 return (access (file, F_OK) == 0);
601}
602
610_dbus_user_at_console (const char *username,
611 DBusError *error)
612{
613#ifdef DBUS_CONSOLE_AUTH_DIR
614 DBusString u, f;
615 dbus_bool_t result;
616
617 result = FALSE;
618 if (!_dbus_string_init (&f))
619 {
620 _DBUS_SET_OOM (error);
621 return FALSE;
622 }
623
624 if (!_dbus_string_append (&f, DBUS_CONSOLE_AUTH_DIR))
625 {
626 _DBUS_SET_OOM (error);
627 goto out;
628 }
629
630 _dbus_string_init_const (&u, username);
631
632 if (!_dbus_concat_dir_and_file (&f, &u))
633 {
634 _DBUS_SET_OOM (error);
635 goto out;
636 }
637
638 result = _dbus_file_exists (_dbus_string_get_const_data (&f));
639
640 out:
642
643 return result;
644#else
645 return FALSE;
646#endif
647}
648
649
658{
659 if (_dbus_string_get_length (filename) > 0)
660 return _dbus_string_get_byte (filename, 0) == '/';
661 else
662 return FALSE;
663}
664
674_dbus_stat (const DBusString *filename,
675 DBusStat *statbuf,
676 DBusError *error)
677{
678 const char *filename_c;
679 struct stat sb;
680
681 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
682
683 filename_c = _dbus_string_get_const_data (filename);
684
685 if (stat (filename_c, &sb) < 0)
686 {
688 "%s", _dbus_strerror (errno));
689 return FALSE;
690 }
691
692 statbuf->mode = sb.st_mode;
693 statbuf->nlink = sb.st_nlink;
694 statbuf->uid = sb.st_uid;
695 statbuf->gid = sb.st_gid;
696 statbuf->size = sb.st_size;
697 statbuf->atime = sb.st_atime;
698 statbuf->mtime = sb.st_mtime;
699 statbuf->ctime = sb.st_ctime;
700
701 return TRUE;
702}
703
704
709{
710 DIR *d;
712};
713
723 DBusError *error)
724{
725 DIR *d;
726 DBusDirIter *iter;
727 const char *filename_c;
728
729 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
730
731 filename_c = _dbus_string_get_const_data (filename);
732
733 d = opendir (filename_c);
734 if (d == NULL)
735 {
737 "Failed to read directory \"%s\": %s",
738 filename_c,
739 _dbus_strerror (errno));
740 return NULL;
741 }
742 iter = dbus_new0 (DBusDirIter, 1);
743 if (iter == NULL)
744 {
745 closedir (d);
747 "Could not allocate memory for directory iterator");
748 return NULL;
749 }
750
751 iter->d = d;
752
753 return iter;
754}
755
771 DBusString *filename,
772 DBusError *error)
773{
774 struct dirent *ent;
775 int err;
776
777 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
778
779 again:
780 errno = 0;
781 ent = readdir (iter->d);
782
783 if (!ent)
784 {
785 err = errno;
786
787 if (err != 0)
788 dbus_set_error (error,
790 "%s", _dbus_strerror (err));
791
792 return FALSE;
793 }
794 else if (ent->d_name[0] == '.' &&
795 (ent->d_name[1] == '\0' ||
796 (ent->d_name[1] == '.' && ent->d_name[2] == '\0')))
797 goto again;
798 else
799 {
800 _dbus_string_set_length (filename, 0);
801 if (!_dbus_string_append (filename, ent->d_name))
802 {
804 "No memory to read directory entry");
805 return FALSE;
806 }
807 else
808 {
809 return TRUE;
810 }
811 }
812}
813
817void
819{
820 closedir (iter->d);
821 dbus_free (iter);
822}
823
824static dbus_bool_t
825fill_user_info_from_group (struct group *g,
826 DBusGroupInfo *info,
827 DBusError *error)
828{
829 _dbus_assert (g->gr_name != NULL);
830
831 info->gid = g->gr_gid;
832 info->groupname = _dbus_strdup (g->gr_name);
833
834 /* info->members = dbus_strdupv (g->gr_mem) */
835
836 if (info->groupname == NULL)
837 {
839 return FALSE;
840 }
841
842 return TRUE;
843}
844
845static dbus_bool_t
846fill_group_info (DBusGroupInfo *info,
847 dbus_gid_t gid,
848 const DBusString *groupname,
849 DBusError *error)
850{
851 const char *group_c_str;
852
853 _dbus_assert (groupname != NULL || gid != DBUS_GID_UNSET);
854 _dbus_assert (groupname == NULL || gid == DBUS_GID_UNSET);
855
856 if (groupname)
857 group_c_str = _dbus_string_get_const_data (groupname);
858 else
859 group_c_str = NULL;
860
861 /* For now assuming that the getgrnam() and getgrgid() flavors
862 * always correspond to the pwnam flavors, if not we have
863 * to add more configure checks.
864 */
865
866#ifdef HAVE_GETPWNAM_R
867 {
868 struct group *g;
869 int result;
870 size_t buflen;
871 char *buf;
872 struct group g_str;
873 dbus_bool_t b;
874
875 /* retrieve maximum needed size for buf */
876 buflen = sysconf (_SC_GETGR_R_SIZE_MAX);
877
878 /* sysconf actually returns a long, but everything else expects size_t,
879 * so just recast here.
880 * https://bugs.freedesktop.org/show_bug.cgi?id=17061
881 */
882 if ((long) buflen <= 0)
883 buflen = 1024;
884
885 result = -1;
886 while (1)
887 {
888 buf = dbus_malloc (buflen);
889 if (buf == NULL)
890 {
892 return FALSE;
893 }
894
895 g = NULL;
896 if (group_c_str)
897 result = getgrnam_r (group_c_str, &g_str, buf, buflen,
898 &g);
899 else
900 result = getgrgid_r (gid, &g_str, buf, buflen,
901 &g);
902 /* Try a bigger buffer if ERANGE was returned:
903 https://bugs.freedesktop.org/show_bug.cgi?id=16727
904 */
905 if (result == ERANGE && buflen < 512 * 1024)
906 {
907 dbus_free (buf);
908 buflen *= 2;
909 }
910 else
911 {
912 break;
913 }
914 }
915
916 if (result == 0 && g == &g_str)
917 {
918 b = fill_user_info_from_group (g, info, error);
919 dbus_free (buf);
920 return b;
921 }
922 else
923 {
925 "Group %s unknown or failed to look it up\n",
926 group_c_str ? group_c_str : "???");
927 dbus_free (buf);
928 return FALSE;
929 }
930 }
931#else /* ! HAVE_GETPWNAM_R */
932 {
933 /* I guess we're screwed on thread safety here */
934 struct group *g;
935
936#warning getpwnam_r() not available, please report this to the dbus maintainers with details of your OS
937
938 g = getgrnam (group_c_str);
939
940 if (g != NULL)
941 {
942 return fill_user_info_from_group (g, info, error);
943 }
944 else
945 {
947 "Group %s unknown or failed to look it up\n",
948 group_c_str ? group_c_str : "???");
949 return FALSE;
950 }
951 }
952#endif /* ! HAVE_GETPWNAM_R */
953}
954
966 const DBusString *groupname,
967 DBusError *error)
968{
969 return fill_group_info (info, DBUS_GID_UNSET,
970 groupname, error);
971
972}
973
985 dbus_gid_t gid,
986 DBusError *error)
987{
988 return fill_group_info (info, gid, NULL, error);
989}
990
1001 dbus_uid_t *uid_p)
1002{
1003 return _dbus_get_user_id (username, uid_p);
1004
1005}
1006
1017 dbus_gid_t *gid_p)
1018{
1019 return _dbus_get_group_id (groupname, gid_p);
1020}
1021
1034 dbus_gid_t **group_ids,
1035 int *n_group_ids)
1036{
1037 return _dbus_groups_from_uid (uid, group_ids, n_group_ids);
1038}
1039
1051 DBusError *error)
1052{
1053 return _dbus_is_console_user (uid, error);
1054
1055}
1056
1066{
1067 return uid == _dbus_geteuid ();
1068}
1069
1079{
1080 return FALSE;
1081}
1082 /* End of DBusInternalsUtils functions */
1084
1098 DBusString *dirname)
1099{
1100 int sep;
1101
1102 _dbus_assert (filename != dirname);
1103 _dbus_assert (filename != NULL);
1104 _dbus_assert (dirname != NULL);
1105
1106 /* Ignore any separators on the end */
1107 sep = _dbus_string_get_length (filename);
1108 if (sep == 0)
1109 return _dbus_string_append (dirname, "."); /* empty string passed in */
1110
1111 while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1112 --sep;
1113
1114 _dbus_assert (sep >= 0);
1115
1116 if (sep == 0)
1117 return _dbus_string_append (dirname, "/");
1118
1119 /* Now find the previous separator */
1120 _dbus_string_find_byte_backward (filename, sep, '/', &sep);
1121 if (sep < 0)
1122 return _dbus_string_append (dirname, ".");
1123
1124 /* skip multiple separators */
1125 while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1126 --sep;
1127
1128 _dbus_assert (sep >= 0);
1129
1130 if (sep == 0 &&
1131 _dbus_string_get_byte (filename, 0) == '/')
1132 return _dbus_string_append (dirname, "/");
1133 else
1134 return _dbus_string_copy_len (filename, 0, sep - 0,
1135 dirname, _dbus_string_get_length (dirname));
1136} /* DBusString stuff */
1138
1139static void
1140string_squash_nonprintable (DBusString *str)
1141{
1142 unsigned char *buf;
1143 int i, len;
1144
1145 buf = _dbus_string_get_udata (str);
1146 len = _dbus_string_get_length (str);
1147
1148 /* /proc/$pid/cmdline is a sequence of \0-terminated words, but we
1149 * want a sequence of space-separated words, with no extra trailing
1150 * space:
1151 * "/bin/sleep" "\0" "60" "\0"
1152 * -> "/bin/sleep" "\0" "60"
1153 * -> "/bin/sleep" " " "60"
1154 *
1155 * so chop off the trailing NUL before cleaning up unprintable
1156 * characters. */
1157 if (len > 0 && buf[len - 1] == '\0')
1158 {
1159 _dbus_string_shorten (str, 1);
1160 len--;
1161 }
1162
1163 for (i = 0; i < len; i++)
1164 {
1165 unsigned char c = (unsigned char) buf[i];
1166 if (c == '\0')
1167 buf[i] = ' ';
1168 else if (c < 0x20 || c > 127)
1169 buf[i] = '?';
1170 }
1171}
1172
1188_dbus_command_for_pid (unsigned long pid,
1189 DBusString *str,
1190 int max_len,
1191 DBusError *error)
1192{
1193 /* This is all Linux-specific for now */
1194 DBusString path;
1195 DBusString cmdline;
1196 int fd;
1197
1198 if (!_dbus_string_init (&path))
1199 {
1200 _DBUS_SET_OOM (error);
1201 return FALSE;
1202 }
1203
1204 if (!_dbus_string_init (&cmdline))
1205 {
1206 _DBUS_SET_OOM (error);
1207 _dbus_string_free (&path);
1208 return FALSE;
1209 }
1210
1211 if (!_dbus_string_append_printf (&path, "/proc/%ld/cmdline", pid))
1212 goto oom;
1213
1214 fd = open (_dbus_string_get_const_data (&path), O_RDONLY);
1215 if (fd < 0)
1216 {
1217 dbus_set_error (error,
1218 _dbus_error_from_errno (errno),
1219 "Failed to open \"%s\": %s",
1220 _dbus_string_get_const_data (&path),
1221 _dbus_strerror (errno));
1222 goto fail;
1223 }
1224
1225 if (!_dbus_read (fd, &cmdline, max_len))
1226 {
1227 dbus_set_error (error,
1228 _dbus_error_from_errno (errno),
1229 "Failed to read from \"%s\": %s",
1230 _dbus_string_get_const_data (&path),
1231 _dbus_strerror (errno));
1232 _dbus_close (fd, NULL);
1233 goto fail;
1234 }
1235
1236 if (!_dbus_close (fd, error))
1237 goto fail;
1238
1239 string_squash_nonprintable (&cmdline);
1240
1241 if (!_dbus_string_copy (&cmdline, 0, str, _dbus_string_get_length (str)))
1242 goto oom;
1243
1244 _dbus_string_free (&cmdline);
1245 _dbus_string_free (&path);
1246 return TRUE;
1247oom:
1248 _DBUS_SET_OOM (error);
1249fail:
1250 _dbus_string_free (&cmdline);
1251 _dbus_string_free (&path);
1252 return FALSE;
1253}
1254
1265{
1266 return TRUE;
1267}
1268
1269static dbus_bool_t
1270ensure_owned_directory (const char *label,
1271 const DBusString *string,
1272 dbus_bool_t create,
1273 DBusError *error)
1274{
1275 const char *dir = _dbus_string_get_const_data (string);
1276 struct stat buf;
1277
1278 if (create && !_dbus_ensure_directory (string, error))
1279 return FALSE;
1280
1281 /*
1282 * The stat()-based checks in this function are to protect against
1283 * mistakes, not malice. We are working in a directory that is meant
1284 * to be trusted; but if a user has used `su` or similar to escalate
1285 * their privileges without correctly clearing the environment, the
1286 * XDG_RUNTIME_DIR in the environment might still be the user's
1287 * and not root's. We don't want to write root-owned files into that
1288 * directory, so just warn and don't provide support for transient
1289 * services in that case.
1290 *
1291 * In particular, we use stat() and not lstat() so that if we later
1292 * decide to use a different directory name for transient services,
1293 * we can drop in a compatibility symlink without breaking older
1294 * libdbus.
1295 */
1296
1297 if (stat (dir, &buf) != 0)
1298 {
1299 int saved_errno = errno;
1300
1301 dbus_set_error (error, _dbus_error_from_errno (saved_errno),
1302 "%s \"%s\" not available: %s", label, dir,
1303 _dbus_strerror (saved_errno));
1304 return FALSE;
1305 }
1306
1307 if (!S_ISDIR (buf.st_mode))
1308 {
1309 dbus_set_error (error, DBUS_ERROR_FAILED, "%s \"%s\" is not a directory",
1310 label, dir);
1311 return FALSE;
1312 }
1313
1314 if (buf.st_uid != geteuid ())
1315 {
1317 "%s \"%s\" is owned by uid %ld, not our uid %ld",
1318 label, dir, (long) buf.st_uid, (long) geteuid ());
1319 return FALSE;
1320 }
1321
1322 /* This is just because we have the stat() results already, so we might
1323 * as well check opportunistically. */
1324 if ((S_IWOTH | S_IWGRP) & buf.st_mode)
1325 {
1327 "%s \"%s\" can be written by others (mode 0%o)",
1328 label, dir, buf.st_mode);
1329 return FALSE;
1330 }
1331
1332 return TRUE;
1333}
1334
1335#define DBUS_UNIX_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
1336#define DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"
1337
1347 DBusError *error)
1348{
1349 const char *xdg_runtime_dir;
1350 DBusString services;
1351 DBusString dbus1;
1352 DBusString xrd;
1353 dbus_bool_t ret = FALSE;
1354 char *data = NULL;
1355
1356 if (!_dbus_string_init (&dbus1))
1357 {
1358 _DBUS_SET_OOM (error);
1359 return FALSE;
1360 }
1361
1362 if (!_dbus_string_init (&services))
1363 {
1364 _dbus_string_free (&dbus1);
1365 _DBUS_SET_OOM (error);
1366 return FALSE;
1367 }
1368
1369 if (!_dbus_string_init (&xrd))
1370 {
1371 _dbus_string_free (&dbus1);
1372 _dbus_string_free (&services);
1373 _DBUS_SET_OOM (error);
1374 return FALSE;
1375 }
1376
1377 xdg_runtime_dir = _dbus_getenv ("XDG_RUNTIME_DIR");
1378
1379 /* Not an error, we just can't have transient session services */
1380 if (xdg_runtime_dir == NULL)
1381 {
1382 _dbus_verbose ("XDG_RUNTIME_DIR is unset: transient session services "
1383 "not available here\n");
1384 ret = TRUE;
1385 goto out;
1386 }
1387
1388 if (!_dbus_string_append (&xrd, xdg_runtime_dir) ||
1389 !_dbus_string_append_printf (&dbus1, "%s/dbus-1",
1390 xdg_runtime_dir) ||
1391 !_dbus_string_append_printf (&services, "%s/dbus-1/services",
1392 xdg_runtime_dir))
1393 {
1394 _DBUS_SET_OOM (error);
1395 goto out;
1396 }
1397
1398 if (!ensure_owned_directory ("XDG_RUNTIME_DIR", &xrd, FALSE, error) ||
1399 !ensure_owned_directory ("XDG_RUNTIME_DIR subdirectory", &dbus1, TRUE,
1400 error) ||
1401 !ensure_owned_directory ("XDG_RUNTIME_DIR subdirectory", &services,
1402 TRUE, error))
1403 goto out;
1404
1405 if (!_dbus_string_steal_data (&services, &data) ||
1406 !_dbus_list_append (dirs, data))
1407 {
1408 _DBUS_SET_OOM (error);
1409 goto out;
1410 }
1411
1412 _dbus_verbose ("Transient service directory is %s\n", data);
1413 /* Ownership was transferred to @dirs */
1414 data = NULL;
1415 ret = TRUE;
1416
1417out:
1418 _dbus_string_free (&dbus1);
1419 _dbus_string_free (&services);
1420 _dbus_string_free (&xrd);
1421 dbus_free (data);
1422 return ret;
1423}
1424
1444{
1445 const char *xdg_data_home;
1446 const char *xdg_data_dirs;
1447 DBusString servicedir_path;
1448
1449 if (!_dbus_string_init (&servicedir_path))
1450 return FALSE;
1451
1452 xdg_data_home = _dbus_getenv ("XDG_DATA_HOME");
1453 xdg_data_dirs = _dbus_getenv ("XDG_DATA_DIRS");
1454
1455 if (xdg_data_home != NULL)
1456 {
1457 if (!_dbus_string_append (&servicedir_path, xdg_data_home))
1458 goto oom;
1459 }
1460 else
1461 {
1462 const DBusString *homedir;
1463 DBusString local_share;
1464
1465 if (!_dbus_homedir_from_current_process (&homedir))
1466 goto oom;
1467
1468 if (!_dbus_string_append (&servicedir_path, _dbus_string_get_const_data (homedir)))
1469 goto oom;
1470
1471 _dbus_string_init_const (&local_share, "/.local/share");
1472 if (!_dbus_concat_dir_and_file (&servicedir_path, &local_share))
1473 goto oom;
1474 }
1475
1476 if (!_dbus_string_append (&servicedir_path, ":"))
1477 goto oom;
1478
1479 if (xdg_data_dirs != NULL)
1480 {
1481 if (!_dbus_string_append (&servicedir_path, xdg_data_dirs))
1482 goto oom;
1483
1484 if (!_dbus_string_append (&servicedir_path, ":"))
1485 goto oom;
1486 }
1487 else
1488 {
1489 if (!_dbus_string_append (&servicedir_path, "/usr/local/share:/usr/share:"))
1490 goto oom;
1491 }
1492
1493 /*
1494 * add configured datadir to defaults
1495 * this may be the same as an xdg dir
1496 * however the config parser should take
1497 * care of duplicates
1498 */
1499 if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR))
1500 goto oom;
1501
1502 if (!_dbus_split_paths_and_append (&servicedir_path,
1503 DBUS_UNIX_STANDARD_SESSION_SERVICEDIR,
1504 dirs))
1505 goto oom;
1506
1507 _dbus_string_free (&servicedir_path);
1508 return TRUE;
1509
1510 oom:
1511 _dbus_string_free (&servicedir_path);
1512 return FALSE;
1513}
1514
1515
1536{
1537 /*
1538 * DBUS_DATADIR may be the same as one of the standard directories. However,
1539 * the config parser should take care of the duplicates.
1540 *
1541 * Also, append /lib as counterpart of /usr/share on the root
1542 * directory (the root directory does not know /share), in order to
1543 * facilitate early boot system bus activation where /usr might not
1544 * be available.
1545 */
1546 static const char standard_search_path[] =
1547 "/usr/local/share:"
1548 "/usr/share:"
1549 DBUS_DATADIR ":"
1550 "/lib";
1551 DBusString servicedir_path;
1552
1553 _dbus_string_init_const (&servicedir_path, standard_search_path);
1554
1555 return _dbus_split_paths_and_append (&servicedir_path,
1556 DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR,
1557 dirs);
1558}
1559
1570{
1571 _dbus_assert (_dbus_string_get_length (str) == 0);
1572
1573 return _dbus_string_append (str, DBUS_SYSTEM_CONFIG_FILE);
1574}
1575
1584{
1585 _dbus_assert (_dbus_string_get_length (str) == 0);
1586
1587 return _dbus_string_append (str, DBUS_SESSION_CONFIG_FILE);
1588}
1589
1594void
1596{
1597#ifdef HAVE_SYSTEMD
1598 sd_notify (0, "READY=1");
1599#endif
1600}
1601
1606void
1608{
1609#ifdef HAVE_SYSTEMD
1610 sd_notify (0, "RELOADING=1");
1611#endif
1612}
1613
1618void
1620{
1621#ifdef HAVE_SYSTEMD
1622 /* For systemd, this is the same code */
1624#endif
1625}
1626
1631void
1633{
1634#ifdef HAVE_SYSTEMD
1635 sd_notify (0, "STOPPING=1");
1636#endif
1637}
1638
1653_dbus_reset_oom_score_adj (const char **error_str_p)
1654{
1655#ifdef __linux__
1656 int fd = -1;
1657 dbus_bool_t ret = FALSE;
1658 int saved_errno = 0;
1659 const char *error_str = NULL;
1660
1661#ifdef O_CLOEXEC
1662 fd = open ("/proc/self/oom_score_adj", O_RDONLY | O_CLOEXEC);
1663#endif
1664
1665 if (fd < 0)
1666 {
1667 fd = open ("/proc/self/oom_score_adj", O_RDONLY);
1668 if (fd >= 0)
1670 }
1671
1672 if (fd >= 0)
1673 {
1674 ssize_t read_result = -1;
1675 /* It doesn't actually matter whether we read the whole file,
1676 * as long as we get the presence or absence of the minus sign */
1677 char first_char = '\0';
1678
1679 read_result = read (fd, &first_char, 1);
1680
1681 if (read_result < 0)
1682 {
1683 /* This probably can't actually happen in practice: if we can
1684 * open it, then we can hopefully read from it */
1685 ret = FALSE;
1686 error_str = "failed to read from /proc/self/oom_score_adj";
1687 saved_errno = errno;
1688 goto out;
1689 }
1690
1691 /* If we are running with protection from the OOM killer
1692 * (typical for the system dbus-daemon under systemd), then
1693 * oom_score_adj will be negative. Drop that protection,
1694 * returning to oom_score_adj = 0.
1695 *
1696 * Conversely, if we are running with increased susceptibility
1697 * to the OOM killer (as user sessions typically do in
1698 * systemd >= 250), oom_score_adj will be strictly positive,
1699 * and we are not allowed to decrease it to 0 without privileges.
1700 *
1701 * If it's exactly 0 (typical for non-systemd systems, and
1702 * user processes on older systemd) then there's no need to
1703 * alter it.
1704 *
1705 * We shouldn't get an empty result, but if we do, assume it
1706 * means zero and don't try to change it. */
1707 if (read_result == 0 || first_char != '-')
1708 {
1709 /* Nothing needs to be done: the OOM score adjustment is
1710 * non-negative */
1711 ret = TRUE;
1712 goto out;
1713 }
1714
1715 close (fd);
1716#ifdef O_CLOEXEC
1717 fd = open ("/proc/self/oom_score_adj", O_WRONLY | O_CLOEXEC);
1718
1719 if (fd < 0)
1720#endif
1721 {
1722 fd = open ("/proc/self/oom_score_adj", O_WRONLY);
1723 if (fd >= 0)
1725 }
1726
1727 if (fd < 0)
1728 {
1729 ret = FALSE;
1730 error_str = "open(/proc/self/oom_score_adj) for writing";
1731 saved_errno = errno;
1732 goto out;
1733 }
1734
1735 if (pwrite (fd, "0", sizeof (char), 0) < 0)
1736 {
1737 ret = FALSE;
1738 error_str = "writing oom_score_adj error";
1739 saved_errno = errno;
1740 goto out;
1741 }
1742
1743 /* Success */
1744 ret = TRUE;
1745 }
1746 else if (errno == ENOENT)
1747 {
1748 /* If /proc/self/oom_score_adj doesn't exist, assume the kernel
1749 * doesn't support this feature and ignore it. */
1750 ret = TRUE;
1751 }
1752 else
1753 {
1754 ret = FALSE;
1755 error_str = "open(/proc/self/oom_score_adj) for reading";
1756 saved_errno = errno;
1757 goto out;
1758 }
1759
1760out:
1761 if (fd >= 0)
1762 _dbus_close (fd, NULL);
1763
1764 if (error_str_p != NULL)
1765 *error_str_p = error_str;
1766
1767 errno = saved_errno;
1768 return ret;
1769#else
1770 /* nothing to do on this platform */
1771 return TRUE;
1772#endif
1773}
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:455
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: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:833
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:966
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: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:672
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:811
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:137
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:135
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:139
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:146
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:556
unsigned long nlink
Number of hard links.
Definition: dbus-sysdeps.h:558
unsigned long size
Size of file.
Definition: dbus-sysdeps.h:561
dbus_uid_t uid
User owning file.
Definition: dbus-sysdeps.h:559
unsigned long mode
File mode.
Definition: dbus-sysdeps.h:557
dbus_gid_t gid
Group owning file.
Definition: dbus-sysdeps.h:560
unsigned long atime
Access time.
Definition: dbus-sysdeps.h:562
unsigned long ctime
Creation time.
Definition: dbus-sysdeps.h:564
unsigned long mtime
Modify time.
Definition: dbus-sysdeps.h:563