[patch] dbus privs improvements, detect photos callout and misc stuf

Sjoerd Simons sjoerd at spring.luon.net
Wed Oct 13 15:38:50 PDT 2004


Hi,

Various attached patches this time:
  hal-dbus-privs.patch:
    When hal is running with dropped priv's the callouts are currently too. So
    allow hal's euid. And fix a compile warning too.

  hal-detect-photos.patch:
    Callout to add the content.photos capability, because gnome-volume-manager
    can't anymore.   

  hal-lshal.patch:
    include <dbus/dbus-glib-lowlevel.h> so the compiler doesn't complain about
    dbus_connection_setup_with_g_main not being declared.

  hal-math.patch:
    Add -lm to hald_LDADD so it actually compiles on my debian system :)
    
  Sjoerd
-- 
A social scientist, studying the culture and traditions of a small North
African tribe, found a woman still practicing the ancient art of matchmaking.
Locally, she was known as the Moor, the marrier.
-------------- next part --------------
Index: hald/hald_dbus.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald_dbus.c,v
retrieving revision 1.15
diff -u -r1.15 hald_dbus.c
--- hald/hald_dbus.c	13 Oct 2004 13:50:08 -0000	1.15
+++ hald/hald_dbus.c	13 Oct 2004 22:01:59 -0000
@@ -30,6 +30,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
 
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib-lowlevel.h>
@@ -911,7 +913,7 @@
 
 
 static dbus_bool_t 
-sender_has_superuser_privileges (DBusConnection *connection, DBusMessage *message)
+sender_has_privileges (DBusConnection *connection, DBusMessage *message)
 {
 	DBusError error;
 	unsigned long user_uid;
@@ -926,15 +928,16 @@
 	HAL_DEBUG (("base_svc = %s", user_base_svc));
 
 	dbus_error_init (&error);
-	if ((user_uid = dbus_bus_get_unix_user (connection, user_base_svc, &error)) == -1) {
+	if ((user_uid = dbus_bus_get_unix_user (connection, user_base_svc, &error)) 
+       == (unsigned long) -1) {
 		HAL_WARNING (("Could not get uid for connection"));
 		return FALSE;
 	}
 
 	HAL_INFO (("uid for caller is %ld", user_uid));
 
-	if (user_uid != 0) {
-		HAL_WARNING (("uid %d is not superuser", user_uid));
+	if (user_uid != 0 && user_uid != geteuid()) {
+		HAL_WARNING (("uid %d is doesn't have the right priviledges", user_uid));
 		return FALSE;
 	}
 
@@ -982,7 +985,7 @@
 	}
 	key = dbus_message_iter_get_string (&iter);
 
-	if (!sender_has_superuser_privileges (connection, message)) {
+	if (!sender_has_privileges (connection, message)) {
 		raise_permission_denied (connection, message, "SetProperty: not privileged");
 		return DBUS_HANDLER_RESULT_HANDLED;
 	}
@@ -1101,7 +1104,7 @@
 
 	HAL_TRACE (("entering"));
 
-	if (!sender_has_superuser_privileges (connection, message)) {
+	if (!sender_has_privileges (connection, message)) {
 		raise_permission_denied (connection, message, "AddCapability: not privileged");
 		return DBUS_HANDLER_RESULT_HANDLED;
 	}
@@ -1181,7 +1184,7 @@
 
 	udi = dbus_message_get_path (message);
 
-	if (!sender_has_superuser_privileges (connection, message)) {
+	if (!sender_has_privileges (connection, message)) {
 		raise_permission_denied (connection, message, "RemoveProperty: not privileged");
 		return DBUS_HANDLER_RESULT_HANDLED;
 	}
-------------- next part --------------
Index: configure.in
===================================================================
RCS file: /cvs/hal/hal/configure.in,v
retrieving revision 1.48
diff -u -a -u -r1.48 configure.in
--- configure.in	12 Oct 2004 20:17:07 -0000	1.48
+++ configure.in	13 Oct 2004 22:11:37 -0000
@@ -440,6 +440,7 @@
 libhal-storage/Makefile
 tools/Makefile
 tools/linux/Makefile
+tools/callouts/Makefile
 tools/device-manager/Makefile
 tools/device-manager/Const.py
 fdi/Makefile
Index: tools/Makefile.am
===================================================================
RCS file: /cvs/hal/hal/tools/Makefile.am,v
retrieving revision 1.10
diff -u -a -u -r1.10 Makefile.am
--- tools/Makefile.am	29 Aug 2004 22:31:39 -0000	1.10
+++ tools/Makefile.am	13 Oct 2004 22:11:37 -0000
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 
-SUBDIRS =  linux device-manager
+SUBDIRS = linux device-manager callouts
 
 INCLUDES = \
 	-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
--- /dev/null	2004-10-13 20:26:42.000000000 +0200
+++ tools/callouts/Makefile.am	2004-10-13 23:28:52.000000000 +0200
@@ -0,0 +1,18 @@
+libexec_PROGRAMS = hal-detect-photos
+
+INCLUDES = \
+  -DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \
+	-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+	-DPACKAGE_BIN_DIR=\""$(bindir)"\" \
+	-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+	-DPACKAGE_LOCALSTATEDIR=\""$(localstatedir)"\" \
+	-I$(top_srcdir) \
+	@PACKAGE_CFLAGS@
+
+hal_detect_photos_SOURCES = hal_detect_photos.c
+hal_detect_photos_LDADD = @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la
+
+install-data-local:
+	$(mkinstalldirs) $(DESTDIR)$(SYSCONFDIR)/hal/device.d
+	- cd $(DESTDIR)$(SYSCONFDIR)/hal/property.d && \
+	$(LN_S) $(libexecdir)/hal_detect_photos 40-hal-detect_photos.hal
--- /dev/null	2004-10-13 20:26:42.000000000 +0200
+++ tools/callouts/hal_detect_photos.c	2004-10-14 00:30:58.000000000 +0200
@@ -0,0 +1,57 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include "libhal/libhal.h"
+
+static int
+getenv_boolean(char *key) {
+  char *value;
+  value = getenv(key);
+  if (value == NULL) return 0;
+
+  return !strcasecmp(value, "true");
+}
+
+int
+main(int argc, char **argv) {
+  char *udi;
+  char *mountpoint;
+  char *path;
+  char *p;
+  LibHalContext *hal_context = NULL;
+  int len;
+  struct stat st;
+
+  udi = getenv("UDI");
+  /* Act when the device is mounted and the mountpoint is set */
+  if (udi == NULL 
+      || !getenv_boolean("HAL_PROP_VOLUME_IS_MOUNTED")
+      || (p = getenv("PROPERTY")) == NULL
+      || strcmp("volume.mount_point",p)
+      || (mountpoint = getenv("VALUE")) == NULL) {
+    return 0;
+  }
+
+  /* /dcim is 5 chars and one extra for '\0' */
+  len = strlen(mountpoint + 6);
+  path = malloc(len); 
+  snprintf(path, len, "%s/dcim", mountpoint);
+
+  if (stat(path, &st) != 0 || !S_ISDIR(st.st_mode)) {
+    return 0;
+  }
+
+  hal_context = hal_initialize(NULL, 0);
+  if (hal_context == NULL)
+    return 0;
+  hal_device_add_capability(hal_context, udi, "content.photos");
+  hal_shutdown(hal_context);
+  return 0;
+}
-------------- next part --------------
Index: tools/lshal.c
===================================================================
RCS file: /cvs/hal/hal/tools/lshal.c,v
retrieving revision 1.8
diff -u -r1.8 lshal.c
--- tools/lshal.c	1 Sep 2004 17:38:59 -0000	1.8
+++ tools/lshal.c	13 Oct 2004 22:15:52 -0000
@@ -35,6 +35,7 @@
 #include <getopt.h>
 
 #include <glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
 #include <dbus/dbus-glib.h>
 
 #include <libhal/libhal.h>
-------------- next part --------------
Index: hald/Makefile.am
===================================================================
RCS file: /cvs/hal/hal/hald/Makefile.am,v
retrieving revision 1.37
diff -u -r1.37 Makefile.am
--- hald/Makefile.am	12 Oct 2004 20:17:08 -0000	1.37
+++ hald/Makefile.am	13 Oct 2004 22:21:42 -0000
@@ -78,7 +78,7 @@
 	linux/drive_id/drive_id_logging.h				\
 	linux/drive_id/drive_id.h	linux/drive_id/drive_id.c
 
-hald_LDADD = @PACKAGE_LIBS@ -lcap @EXPAT_LIB@
+hald_LDADD = @PACKAGE_LIBS@ -lm -lcap @EXPAT_LIB@
 
 if HAVE_SELINUX
 hald_LDADD += -lselinux
-------------- next part --------------
_______________________________________________
hal mailing list
hal at freedesktop.org
http://freedesktop.org/mailman/listinfo/hal


More information about the Hal mailing list