hal-storage-shared.c revision 7b1f4223d0637b428ed4e46b5bc295f7a949e670
/***************************************************************************
* CVSID: $Id: hal-storage-mount.c,v 1.7 2006/06/21 00:44:03 david Exp $
*
* hal-storage-mount.c : Mount wrapper
*
* Copyright (C) 2006 David Zeuthen, <david@fubar.dk>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
**************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#ifdef __FreeBSD__
#include <fstab.h>
#include <limits.h>
#include <pwd.h>
#include <fcntl.h>
#include <bsm/adt_event.h>
#else
#include <mntent.h>
#endif
#include <unistd.h>
#include <errno.h>
#include <syslog.h>
#include "hal-storage-shared.h"
#ifdef __FreeBSD__
struct mtab_handle
{
int n_mounts;
int iter;
};
#endif
{
#ifdef __FreeBSD__
struct mtab_handle *mtab;
return FALSE;
}
return TRUE;
#else
#endif
}
char *
{
#ifdef __FreeBSD__
else
return NULL;
if (mount_point != NULL) {
}
return mnt.mnt_special;
} else {
return NULL;
}
#else
if (mount_point != NULL) {
}
return mnt->mnt_fsname;
} else {
return NULL;
}
#endif
}
void
{
#ifdef __FreeBSD__
#else
#endif
}
{
#ifdef __FreeBSD__
return setfsent () == 1;
#else
#endif
}
char *
{
#ifdef __FreeBSD__
/* TODO: fill out mount_point */
}
static struct vfstab v;
#else
}
#endif
}
void
{
#ifdef __FreeBSD__
endfsent ();
#else
#endif
}
#ifdef __FreeBSD__
#else
#endif
void
unknown_error (const char *detail)
{
exit (1);
}
static void
device_busy (const char *detail)
{
exit (1);
}
static void
not_mounted (const char *detail)
{
exit (1);
}
static void
not_mounted_by_hal (const char *detail)
{
exit (1);
}
static void
{
exit (1);
}
static void
permission_denied_volume_ignore (const char *device)
{
exit (1);
}
void
#ifdef HAVE_POLKIT
#endif
const char *udi,
const char *invoked_by_uid, const char *invoked_by_syscon_name,
{
int i, j;
int exit_status;
char *args[10];
int na;
int hal_mtab_orig_len;
int num_read;
char *hal_mtab_buf;
char **lines;
char *mount_point_to_unmount;
#ifdef sun
#endif
#ifdef DEBUG
#endif
dbus_error_init (&error);
dbus_error_is_set (&error)) {
if (dbus_error_is_set (&error)) {
}
/*
* When device allocation is enabled (bsmconv or TX), we
* set volume.ignore on all volumes, but still want
* Mount() to succeed when called from the euid=0
* device allocation program.
*/
if (atol (invoked_by_uid) != 0) {
}
}
if (!libhal_volume_is_mounted (volume)) {
not_mounted ("According to HAL, the volume is not mounted");
}
}
/* check hal's mtab file to verify the device to unmount is actually mounted by hal */
if (hal_mtab_orig == NULL) {
unknown_error ("Cannot open /media/.hal-mtab");
}
unknown_error ("Cannot seek to end of /media/.hal-mtab");
}
if (hal_mtab_orig_len < 0) {
unknown_error ("Cannot determine size of /media/.hal-mtab");
}
if (num_read != hal_mtab_orig_len) {
unknown_error ("Cannot read from /media/.hal-mtab");
}
#ifdef DEBUG
#endif
/* find the entry we're going to unmount */
char **line_elements;
#ifdef DEBUG
#endif
if ((lines[i])[0] == '#')
continue;
#ifdef DEBUG
#endif
char *line_to_free;
}
#ifdef sun
/*
* Owner is allowed to take over. Before we have real
* ownership in HAL, assume it's the console owner.
*/
}
#endif /* sun */
line_to_free = lines[i];
}
goto line_found;
}
}
}
if (mount_point_to_unmount == NULL) {
not_mounted_by_hal ("Device to unmount is not in /media/.hal-mtab so it is not mounted by HAL");
}
/* bail out, unless if we got the "hal-storage-can-unmount-volumes-mounted-by-others" privilege only
* if mounted_by_other_uid==TRUE
*
* We allow uid 0 to actually ensure that Unmount(options=["lazy"], "/dev/blah") works from addon-storage.
*/
/* TODO: actually check for privilege "hal-storage-can-unmount-volumes-mounted-by-others" */
}
/* create new .hal-mtab~ file without the entry we're going to unmount */
if (hal_mtab_new == NULL) {
unknown_error ("Cannot create /media/.hal-mtab~");
}
if (i > 0) {
unknown_error ("Cannot write to /media/.hal-mtab~");
}
}
unknown_error ("Cannot write to /media/.hal-mtab~");
}
}
g_strfreev (lines);
na = 0;
if (option_lazy)
if (option_force)
#ifdef DEBUG
printf ("will umount %s (mounted at '%s'), mounted_by_other_uid=%d\n",
#endif
if (!g_spawn_sync ("/",
args,
NULL,
0,
NULL,
NULL,
&sout,
&serr,
&err)) {
unlink ("/media/.hal-mtab~");
}
/* check if unmount was succesful */
if (exit_status != 0) {
unlink ("/media/.hal-mtab~");
device_busy (serr);
} else {
unlink ("/media/.hal-mtab~");
}
}
#ifdef sun
"solaris.device.mount.removable",
}
#endif
/* unmount was succesful, remove directory we created in Mount() */
#ifdef sun
#endif
if (g_rmdir (mount_point_to_unmount) != 0) {
unlink ("/media/.hal-mtab~");
unknown_error ("Cannot remove directory");
}
/* set new .hal-mtab file */
unlink ("/media/.hal-mtab~");
unknown_error ("Cannot rename /media/.hal-mtab~ to /media/.hal-mtab");
}
#ifdef DEBUG
printf ("done unmounting\n");
#endif
syslog (LOG_INFO, "unmounted %s from '%s' on behalf of uid %s", device, mount_point_to_unmount, invoked_by_uid);
closelog ();
}
void
#ifdef HAVE_POLKIT
#endif
const char *udi,
const char *invoked_by_uid, const char *invoked_by_syscon_name,
{
int exit_status;
char *args[10];
int na;
#ifdef sun
#endif
/* TODO: should we require privileges here? */
#ifdef DEBUG
#endif
na = 0;
if (closetray) {
}
#ifdef sun
putenv("EJECT_DIRECT=1");
#endif
#ifdef DEBUG
#endif
/* invoke eject command */
if (!g_spawn_sync ("/",
args,
NULL,
0,
NULL,
NULL,
&sout,
&serr,
&err)) {
}
#ifdef sun
/*
* Solaris eject returns 4 for manually ejectable media like floppy.
* Consider it success.
*/
exit_status = 0;
}
}
#endif /* sun */
/* check if eject was succesful */
if (exit_status != 0) {
}
/* eject was succesful... */
#ifdef DEBUG
printf ("done ejecting\n");
#endif
}
static int lock_mtab_fd = -1;
lock_hal_mtab (void)
{
if (lock_mtab_fd >= 0)
return TRUE;
if (lock_mtab_fd < 0)
return FALSE;
#if sun
#else
#endif
goto tryagain;
return FALSE;
}
return TRUE;
}
void
unlock_hal_mtab (void)
{
#if sun
#else
#endif
lock_mtab_fd = -1;
}
#if sun
/* map PolicyKit privilege to RBAC authorization */
char *
auth_from_privilege(const char *privilege)
{
char *authname;
int i;
} else {
/* replace '-' with '.' */
if (authname[i] == '-') {
authname[i] = '.';
}
}
}
return (authname);
}
void
{
return;
}
return;
}
switch (event_id) {
case ADT_attach:
break;
case ADT_detach:
break;
case ADT_remove:
break;
default:
goto out;
}
if (result == 0) {
}
} else {
}
}
out:
(void) adt_end_session(ah);
}
#endif /* sun */