ACLs broken in 0.13?

Bastien Nocera hadess@hadess.net
Thu, 02 Oct 2003 20:21:48 +0100


--=-+FqyzaxXMKl4elcCkfpU
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hey Havoc,

On Wed, 2003-10-01 at 23:01, Havoc Pennington wrote:
> On Wed, 2003-10-01 at 17:34, Bastien Nocera wrote:
> > I played this afternoon with d-bus, and had to let the whole thing
> > opened to be able to use it (ie. remove all the "block everything" bits
> > in the config file).
> 
> 0.13 has no changes from 0.12 in this area that I remember.

Fair enough. I didn't try with 0.12 I must say, but as nobody complained
about the problems before, I thought it was a regression.

> > Here a piece of my /etc/dbus-1/system.d/kudzu file:
> 
> It may be required to name your file something.conf, not just something.

Tried that. Not much more luck unfortunately.

> Re: your specific config file, you're probably opening up too much
> stuff. A change we need to make is to always allow METHOD_RETURN to a
> METHOD_CALL that was allowed; this will make it simpler to write the 
> hole-punching rules narrowly.

I couldn't find any way to make it work for me. I ended up opening
everything up. It's dirty but it works for now.

> Suggest compiling with --enable-verbose-mode and set DBUS_VERBOSE=1 for
> the bus, then see what's happening. You may have to create a bus config
> file with the listen socket of a session bus and the policy rules of the
> system bus, and start it with --print-address, rather than using the
> system bus in-place.

--enable-verbose-mode seems to depend on maintainer-mode being switched
on as well, I realised after a while.

If you, or anyone else for the matter, can come up with a configuration
that I could drop in /etc/dbus-1/system.d, I'd be grateful.

I attached my current patches. There are still a bunch of issues
(updfstab sends a message whatever, sends a message even if there's
nothing to mount, etc.), but I think that's going to do it for me right
now.

There's one patch to kudzu's updfstab that sends a message with a list
of strings (new mounts). The other patch is to magicdev to process those
messages and mount any new mounts that appeared in /etc/fstab.

My iPod and my disk-on-key now appear directly on the desktop when I
plug them in.

Cheers

---
Bastien Nocera <hadess@hadess.net> 
A problem shared is a problem halved, so is your problem really yours or
just half of someone else's?

--=-+FqyzaxXMKl4elcCkfpU
Content-Disposition: attachment; filename=kudzu-dbus-send-new-mounts.patch
Content-Type: text/x-patch; name=kudzu-dbus-send-new-mounts.patch; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

diff -ur kudzu-1.1.20/Makefile kudzu-1.1.20.new/Makefile
--- kudzu-1.1.20/Makefile	2003-08-01 20:50:53.000000000 +0100
+++ kudzu-1.1.20.new/Makefile	2003-10-01 19:00:14.000000000 +0100
@@ -19,6 +19,8 @@
 PYTHONVERS = $(shell ls -d /usr/include/python* | sed "s|/usr/include/||g")
 
 CFLAGS += -I. -DVERSION=\"$(VERSION)\"
+CFLAGS += `pkg-config --cflags dbus-1`
+CFLAGS += -DDBUS_API_SUBJECT_TO_CHANGE
 
 ARCH := $(patsubst ppc64,ppc,$(patsubst sparc64,sparc,$(patsubst i%86,i386,$(shell uname -m))))
 
@@ -85,7 +87,7 @@
 	$(CC) $(CFLAGS) $(LDFLAGS) $(KUDOBJS) -o kudzu -L. -lkudzu -L. -lpci -lnewt -lpopt
 
 updfstab: libkudzu.a updfstab.o po
-	$(CC) $(CFLAGS) $(LDFLAGS) updfstab.o -o updfstab -L. -lkudzu -lpci -lpopt
+	$(CC) $(CFLAGS) $(LDFLAGS) updfstab.o -o updfstab `pkg-config --libs dbus-1` -L. -lkudzu -lpci -lpopt
 
 module_upgrade: libkudzu.a module_upgrade.c
 	$(CC) $(CFLAGS) $(LDFLAGS) module_upgrade.c -o module_upgrade -L. -lkudzu -lpci
diff -ur kudzu-1.1.20/updfstab.c kudzu-1.1.20.new/updfstab.c
--- kudzu-1.1.20/updfstab.c	2003-10-02 20:13:10.000000000 +0100
+++ kudzu-1.1.20.new/updfstab.c	2003-10-02 20:07:56.000000000 +0100
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <dbus/dbus.h>
 
 #include "kudzu.h"
 
@@ -39,6 +40,8 @@
 
 #define CLASS_RESERVED_HACK 0
 
+#define REQUEST_NAME "com.redhat.kudzu.NewMountableDevice"
+
 struct matchInfo {
     int type;
     const char * descPattern;
@@ -84,8 +87,14 @@
     int partition;
 };
 
+struct newMountableDevice {
+    char * mountPoint;
+    struct newMountableDevice * next;
+};
+
 static struct stat fstabsb;
 
+static void sendNewMountableDeviceMessage (struct newMountableDevice * newMountable);
 static int readMountTable(char * fileName, struct mountInfo ** mountListPtr);
 static int isWritable(char * path);
 static int getDeviceNum(char * path, dev_t * device);
@@ -150,6 +159,36 @@
     return makedev(maj, (min & ~mask));
 }
 
+static void sendNewMountableDeviceMessage (struct newMountableDevice * newMountableList) {
+	DBusConnection *connection;
+	DBusMessage *message;
+	DBusMessageIter iter;
+	struct newMountableDevice * newMountable;
+
+	if (!newMountable)
+		return;
+
+	connection = dbus_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (!connection) {
+		return;
+	}
+
+	message = dbus_message_new (REQUEST_NAME, DBUS_SERVICE_BROADCAST);
+	if (message == NULL) {
+		return;
+	}
+
+	dbus_message_append_iter_init (message, &iter);
+
+	for (newMountable = newMountableList; newMountable; newMountable = newMountable->next) {
+		dbus_message_iter_append_string (&iter, newMountable->mountPoint);
+	}
+	dbus_connection_send (connection, message, NULL);
+	dbus_connection_flush (connection);
+	dbus_message_unref (message);
+	dbus_connection_disconnect (connection);
+}
+
 static int isWritable(char *dev) {
     int fd, capability;
     char path[50];
@@ -563,6 +602,7 @@
     struct stat sb;
     char * deviceName;
     struct entryToAdd * addition;
+    struct newMountableDevice * newMountableList, * newMountable;
     char symlinkSource[PATH_MAX];
     pid_t pid;
     int status;
@@ -715,6 +755,8 @@
     if (!test)
 	fclose(revoke);
 
+    newMountableList = NULL;
+
     for (addition = addList; addition; addition = addition->next) {
 	if (!addition->symlink) {
 	    deviceName = addition->device->device;
@@ -749,7 +791,7 @@
 	}
 
 	/* CD-RW hack! */
-	if (!addition->device->type->noFstab)
+	if (!addition->device->type->noFstab) {
 	    fprintf(output, "%-23s %-23s %-7s %-15s %d %d\n",
 		    deviceName,
 		    addition->mountPoint,
@@ -762,6 +804,16 @@
 		      strcmp(addition->device->type->name, "cdrw")) ?
 		    "noauto,owner,kudzu,ro" : "noauto,owner,kudzu",
 		    0, 0);
+	    newMountable = malloc(sizeof(struct newMountableDevice));
+	    newMountable->mountPoint = strdup (addition->mountPoint);
+	    if (!newMountableList) {
+                newMountableList = newMountable;
+		newMountable->next = NULL;
+	    } else{
+                newMountable->next = newMountableList;
+                newMountableList = newMountable;
+	    }
+	}
     }
 
     if (!test) {
@@ -818,6 +870,8 @@
     }
     if (revokeFileName) unlink(revokeFileName);
 
+    sendNewMountableDeviceMessage (newMountableList);
+
     return 0;
 }
 

--=-+FqyzaxXMKl4elcCkfpU
Content-Disposition: attachment; filename=magicdev-dbus-automount.patch
Content-Type: text/x-patch; name=magicdev-dbus-automount.patch; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/magicdev/Makefile.am,v
retrieving revision 1.11
diff -u -r1.11 Makefile.am
--- Makefile.am	9 Jan 2003 20:50:57 -0000	1.11
+++ Makefile.am	2 Oct 2003 19:10:55 -0000
@@ -26,6 +26,8 @@
 
 INCLUDES = 					   \
 	$(CAPPLET_CFLAGS) 			   \
+	$(MAGICDEV_CFLAGS)			   \
+	-DDBUS_API_SUBJECT_TO_CHANGE		   \
 	-DBINDIR=\"$(bindir)\"			   \
 	-DMAGICDEVDIR=\"$(pkgdatadir)\"		   \
 	-DGNOMELOCALEDIR=\""$(datadir)/locale"\"   \
Index: configure.in
===================================================================
RCS file: /cvs/gnome/magicdev/configure.in,v
retrieving revision 1.56
diff -u -r1.56 configure.in
--- configure.in	6 Sep 2003 07:49:55 -0000	1.56
+++ configure.in	2 Oct 2003 19:10:56 -0000
@@ -23,18 +23,13 @@
 GETTEXT_PACKAGE=AC_PACKAGE_NAME
 AC_SUBST(GETTEXT_PACKAGE)
 
-PKG_CHECK_MODULES(MAGICDEV, libgnomeui-2.0)
+PKG_CHECK_MODULES(MAGICDEV, libgnomeui-2.0 dbus-glib-1 >= 0.13)
 AC_SUBST(MAGICDEV_CFLAGS)
 AC_SUBST(MAGICDEV_LIBS)
 
 PKG_CHECK_MODULES(CAPPLET, libgnomeui-2.0 >= 2.1.5 libglade-2.0)
 AC_SUBST(CAPPLET_CFLAGS)
 AC_SUBST(CAPPLET_LIBS)
-
-PKG_CHECK_MODULES(MAGICPLUG, gtk+-2.0 libglade-2.0 gconf-2.0)
-AC_SUBST(MAGICPLUG_CFLAGS)
-AC_SUBST(MAGICPLUG_LIBS)
-
 
 AC_PATH_PROG(GCONFTOOL, gconftool-2)
 AM_GCONF_SOURCE_2
Index: daemon.c
===================================================================
RCS file: /cvs/gnome/magicdev/daemon.c,v
retrieving revision 1.31
diff -u -r1.31 daemon.c
--- daemon.c	11 Sep 2003 15:02:29 -0000	1.31
+++ daemon.c	2 Oct 2003 19:10:58 -0000
@@ -23,6 +23,9 @@
 
 #include <gdk/gdkx.h>
 
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+
 #undef MD_DEBUG
 #define MNTTYPE_ISO9660 "iso9660"
 #define MNTOPT_USER "user"
@@ -231,6 +234,85 @@
         return result;
 }
 
+#define SERVICE_NAME "com.redhat.kudzu"
+#define REQUEST_NAME "com.redhat.kudzu.NewMountableDevice"
+#define WRONG_ARGS_ERROR "com.redhat.kudzu.Error.WrongArgs"
+
+void
+magicdev_handle_dbus_request (DBusConnection *connection,
+		DBusMessage *message,
+		AppInfo *ai)
+{
+	DBusMessageIter iter;
+	DBusError error;
+	const char *string;
+	int type;
+	char *argv[3];
+
+	if (ai->do_automount == FALSE)
+		return;
+
+	dbus_error_init (&error);
+	dbus_message_iter_init (message, &iter);
+
+	type = dbus_message_iter_get_arg_type (&iter);
+	while (type == DBUS_TYPE_STRING) {
+		string = dbus_message_iter_get_string (&iter);
+
+		argv[0] = "/bin/mount";
+		argv[1] = (char *)string;
+		argv[2] = NULL;
+		gnome_execute_async (g_get_home_dir (), 2, argv);
+
+		if (!dbus_message_iter_next (&iter))
+			break;
+		type = dbus_message_iter_get_arg_type (&iter);
+	}
+}
+
+static DBusHandlerResult
+handler_func (DBusMessageHandler *handler,
+		DBusConnection *connection,
+		DBusMessage *message,
+		void *user_data)
+{
+	AppInfo *ai = (AppInfo *) user_data;
+
+	if (dbus_message_has_name (message, REQUEST_NAME))
+		magicdev_handle_dbus_request (connection, message, ai);
+
+	return DBUS_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
+}
+
+static void
+magicdev_dbus_server_run (AppInfo *ai)
+{
+	DBusConnection *connection;
+	DBusError error;
+	DBusMessageHandler *handler;
+
+	dbus_error_init (&error);
+	connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+	if (connection == NULL) {
+		g_message ("Could not connect to the system bus: %s", error.message);
+		dbus_error_free (&error);
+		return;
+	}
+
+	dbus_connection_setup_with_g_main (connection, NULL);
+
+	handler = dbus_message_handler_new (handler_func, ai, NULL);
+	dbus_connection_add_filter (connection, handler);
+
+	dbus_bus_acquire_service (connection, SERVICE_NAME, 0, &error);
+	if (dbus_error_is_set (&error))
+	{
+		g_message ("Could not create service %s : %s", SERVICE_NAME, error.message);
+		dbus_error_free (&error);
+		return;
+	}
+}
+
 static void
 load_config (AppInfo *ai)
 {
@@ -338,6 +420,8 @@
         retval = g_new0 (AppInfo, 1);
 
         retval->devs_by_fsname = g_hash_table_new (g_str_hash, g_str_equal);
+
+	magicdev_dbus_server_run (retval);
 
         return retval;
 }

--=-+FqyzaxXMKl4elcCkfpU--