18c2aff776a775d34a4c9893a4c72e0434d68e36artem/***************************************************************************
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * hal-storage-closetray.c : CloseTray method handler
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Copyright (C) 2006 David Zeuthen, <david@fubar.dk>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Copyright (C) 2006 Sun Microsystems, Inc.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This program is free software; you can redistribute it and/or modify
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * it under the terms of the GNU General Public License as published by
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the Free Software Foundation; either version 2 of the License, or
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * (at your option) any later version.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This program is distributed in the hope that it will be useful,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * but WITHOUT ANY WARRANTY; without even the implied warranty of
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * GNU General Public License for more details.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * You should have received a copy of the GNU General Public License
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * along with this program; if not, write to the Free Software
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18c2aff776a775d34a4c9893a4c72e0434d68e36artem **************************************************************************/
18c2aff776a775d34a4c9893a4c72e0434d68e36artem fprintf (stderr, "This program should only be started by hald.\n");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem fprintf (stderr, "org.freedesktop.Hal.Device.Storage.UnknownFailure\n");
18c2aff776a775d34a4c9893a4c72e0434d68e36arteminvalid_closetray_option (const char *option, const char *uid)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem fprintf (stderr, "org.freedesktop.Hal.Device.Storage.InvalidCloseTrayOption\n");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem fprintf (stderr, "The option '%s' is not allowed for uid=%s\n", option, uid);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem invoked_by_uid = getenv ("HAL_METHOD_INVOKED_BY_UID");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem invoked_by_syscon_name = getenv ("HAL_METHOD_INVOKED_BY_SYSTEMBUS_CONNECTION_NAME");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if ((hal_ctx = libhal_ctx_init_direct (&error)) == NULL) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem unknown_closetray_error ("Cannot get libpolkit context");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* read from stdin */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (strlen (fgets (closetray_options, sizeof (closetray_options), stdin)) > 0)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem closetray_options [strlen (closetray_options) - 1] = '\0';
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* validate that input from stdin is UTF-8 */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem unknown_closetray_error ("Error validating closetray_options as UTF-8");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem printf ("closetray_options = '%s'\n", closetray_options);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* delete any trailing whitespace options from splitting the string */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem given_options = g_strsplit (closetray_options, "\t", 0);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (i = g_strv_length (given_options) - 1; i >= 0; --i) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check options */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* none supported right now */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* should be storage */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if ((drive = libhal_drive_from_udi (hal_ctx, udi)) == NULL) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* use handle_eject() with the closetray option */