1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* activation-helper-bin.c Setuid helper for launching programs as a custom
3 * user. This file is security sensitive.
5 * Copyright (C) 2007 Red Hat, Inc.
7 * Licensed under the Academic Free License version 2.1
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.
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.
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
28 #include "activation-helper.h"
29 #include "activation-exit-codes.h"
36 convert_error_to_exit_code (DBusError *error)
38 if (dbus_error_has_name (error, DBUS_ERROR_NO_MEMORY))
39 return BUS_SPAWN_EXIT_CODE_NO_MEMORY;
41 if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_CONFIG_INVALID))
42 return BUS_SPAWN_EXIT_CODE_CONFIG_INVALID;
44 if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_SETUP_FAILED))
45 return BUS_SPAWN_EXIT_CODE_SETUP_FAILED;
47 if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_SERVICE_INVALID))
48 return BUS_SPAWN_EXIT_CODE_SERVICE_NOT_FOUND;
50 if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID))
51 return BUS_SPAWN_EXIT_CODE_PERMISSIONS_INVALID;
53 if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_FILE_INVALID))
54 return BUS_SPAWN_EXIT_CODE_FILE_INVALID;
56 if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_EXEC_FAILED))
57 return BUS_SPAWN_EXIT_CODE_EXEC_FAILED;
59 if (dbus_error_has_name (error, DBUS_ERROR_INVALID_ARGS))
60 return BUS_SPAWN_EXIT_CODE_INVALID_ARGS;
62 if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_CHILD_SIGNALED))
63 return BUS_SPAWN_EXIT_CODE_CHILD_SIGNALED;
65 /* should we assert? */
66 fprintf(stderr, "%s: %s\n", error->name, error->message);
68 return BUS_SPAWN_EXIT_CODE_SETUP_FAILED;
72 main (int argc, char **argv)
77 /* default is all okay */
80 /* have we used a help option or not specified the correct arguments? */
82 strcmp (argv[1], "--help") == 0 ||
83 strcmp (argv[1], "-h") == 0 ||
84 strcmp (argv[1], "-?") == 0)
86 fprintf (stderr, "dbus-daemon-activation-helper service.to.activate\n");
90 dbus_error_init (&error);
91 if (!run_launch_helper (argv[1], &error))
93 /* convert error to an exit code */
94 retval = convert_error_to_exit_code (&error);
95 dbus_error_free (&error);