hal/hald hald.conf, NONE, 1.1 Makefile.am, 1.25, 1.26 hald.c, 1.7, 1.8 hald_conf.c, 1.1, 1.2 hald_conf.h, 1.1, 1.2

David Zeuthen david at pdx.freedesktop.org
Tue Jun 1 14:10:04 PDT 2004


Update of /cvs/hal/hal/hald
In directory pdx:/tmp/cvs-serv2593/hald

Modified Files:
	Makefile.am hald.c hald_conf.c hald_conf.h 
Added Files:
	hald.conf 
Log Message:
2004-06-01  David Zeuthen  <david at fubar.dk>

	* hald/hald.conf: New file, policy for hal daemon

	* hald/Makefile.am: Install hald.conf into $sysconfdir/hal

	* hald/hald_conf.c (hald_read_conf_file): New function
	(cdata): New function
	(end): New function
	(start): New function
	(parsing_abort): New function

	* hald/hald.c (main): Call hald_read_conf_file to read the 
	configuration file

	* hald/hald_conf.h (hald_read_conf_file): Added hald_read_conf_file
	prototype

	* hald/linux/block_class_device.c (block_class_pre_process): add
	storage.cdrom capability if device is a cdrom



--- NEW FILE: hald.conf ---
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- -*- SGML -*- --> 

<!-- This configuration file controls the Hardware Abstraction Layer
     daemon - it is meant that OS vendors customize this file to reflect
     their desired policy.
  -->

<haldconfig>

  <!-- Default value for storage.media_check_enabled for devices of
       capability storage - this can be overridden by .fdi files.

       Setting this to true results a whitelist policy, e.g. media
       check is only enabled for storage devices with a .fdi file
       saying so.

       Conversely, setting it to TRUE results in a blacklist policy
       where media check is enabled by default but may be overridden
       by a .fdi for devices causing trouble. 
  -->
  <storage_media_check_enabled>true</storage_media_check_enabled>


  <!-- Default value for storage.automount_enabled for devices of
       capability storage - this can be overridden by .fdi files.
	 
       Setting this to FALSE results a whitelist policy, e.g. policy
       agents should only automount storage devices with a .fdi file
       saying so.
	 
       Conversely, setting it to TRUE results in a blacklist policy
       where policy agents should always automount unless this is
       explicitly overridden by .fdi for devices causing trouble.
  -->
  <storage_automount_enabled>true</storage_automount_enabled>


  <!-- Default value for storage.cdrom.eject_check_enabled for devices
       of capability storage.cdrom - this can be overridden by .fdi
       files.
	 
       Setting this to FALSE results a whitelist policy, e.g. the
       eject button is only checked if this property is overridden in
       a .fdi file.
	 
       Conversely, setting it to TRUE results in a blacklist policy
       where the eject button is always checked unless this is
       explicitly overridden by .fdi file for devices causing trouble.
  -->
  <storage_cdrom_eject_check_enabled>true</storage_cdrom_eject_check_enabled>

</haldconfig>

Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/hald/Makefile.am,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- a/Makefile.am	1 Jun 2004 18:47:23 -0000	1.25
+++ b/Makefile.am	1 Jun 2004 21:10:02 -0000	1.26
@@ -103,6 +103,10 @@
 	rm -f *~
 	rm -f hald_marshal.c hald_marshal.h
 
+confdir = $(sysconfdir)/hal
+
+dist_conf_DATA = hald.conf
+
 install-data-local :
 	$(mkinstalldirs) $(DESTDIR)$(SYSCONFDIR)/hal/device.d
 	$(mkinstalldirs) $(DESTDIR)$(SYSCONFDIR)/hal/capability.d

Index: hald.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- a/hald.c	1 Jun 2004 18:47:23 -0000	1.7
+++ b/hald.c	1 Jun 2004 21:10:02 -0000	1.8
@@ -49,6 +49,7 @@
 #include "device_info.h"
 #include "osspec.h"
 #include "hald_dbus.h"
+#include "hald_conf.h"
 
 /**
  * @defgroup HalDaemon HAL daemon
@@ -173,9 +174,6 @@
 	DBusConnection *dbus_connection;
 	GMainLoop *loop;
 
-	/* We require root to sniff mii registers */
-	/*opt_run_as = HAL_USER; */
-
 	while (1) {
 		int c;
 		int option_index = 0;
@@ -222,6 +220,8 @@
 
 	HAL_DEBUG (("opt_become_daemon = %d", opt_become_daemon));
 
+	hald_read_conf_file ();
+
 	if (opt_become_daemon) {
 		int child_pid;
 		int dev_null_fd;

Index: hald_conf.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald_conf.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- a/hald_conf.c	1 Jun 2004 18:47:23 -0000	1.1
+++ b/hald_conf.c	1 Jun 2004 21:10:02 -0000	1.2
@@ -1,9 +1,9 @@
 /***************************************************************************
  * CVSID: $Id$
  *
- * device_store.c : Search for .fdi files and merge on match
+ * hald_conf.c : Global configuration for hal daemon
  *
- * Copyright (C) 2003 David Zeuthen, <david at fubar.dk>
+ * Copyright (C) 2004 David Zeuthen, <david at fubar.dk>
  *
  * Licensed under the Academic Free License version 2.0
  *
@@ -35,6 +35,9 @@
 #include <assert.h>
 
 #include "hald_conf.h"
+#include "logger.h"
+
+#define HALD_CONF_FILE PACKAGE_SYSCONF_DIR "/hal/hald.conf"
 
 static HaldConf hald_conf = {
 	TRUE, /* storage.media_check_enabled */
@@ -42,8 +45,174 @@
 	TRUE  /* storage.cdrom.eject_check_enabled */
 };
 
-HaldConf* 
+HaldConf *
 hald_get_conf (void)
 {
 	return &hald_conf;
 }
+
+/* @todo this code is one big HACK - please rewrite it properly */
+
+/** Maximum amount of CDATA */
+#define CDATA_BUF_SIZE  1024
+
+/** Max length of property key */
+#define ELEM_BUF_SIZE  256
+
+typedef struct {
+	XML_Parser parser;
+
+	dbus_bool_t failed;
+
+	char elem[ELEM_BUF_SIZE];
+
+	char cdata_buf[CDATA_BUF_SIZE];
+
+	int cdata_buf_len;
+
+} ParsingContext;
+
+
+static void
+parsing_abort (ParsingContext * pc)
+{
+	/* Grr, expat can't abort parsing */
+	HAL_ERROR (("Aborting parsing of document"));
+	pc->failed = TRUE;
+}
+
+static void
+start (ParsingContext * pc, const char *el, const char **attr)
+{
+	if (pc->failed)
+		return;
+
+	strncpy (pc->elem, el, ELEM_BUF_SIZE);
+
+	pc->cdata_buf_len = 0;
+}
+
+static void
+end (ParsingContext * pc, const char *el)
+{
+	char *key;
+	char *value;
+	if (pc->failed)
+		return;
+
+	pc->cdata_buf[pc->cdata_buf_len] = '\0';
+
+	key = pc->elem;
+	value = pc->cdata_buf;
+
+	if ((strcmp (key, "storage_media_check_enabled") == 0) &&
+	    (strcmp (value, "false") == 0)) {
+		hald_conf.storage_media_check_enabled = FALSE;
+	} else if ((strcmp (key, "storage_automount_enabled") == 0) &&
+		   (strcmp (value, "false") == 0)) {
+		hald_conf.storage_automount_enabled = FALSE;
+	} else if ((strcmp (key, "storage_cdrom_eject_check_enabled") == 0) &&
+		   (strcmp (value, "false") == 0)) {
+		hald_conf.storage_cdrom_eject_check_enabled = FALSE;
+	}
+
+	pc->elem[0] = '\0';
+	pc->cdata_buf[0] = '\0';
+	pc->cdata_buf_len = 0;
+}
+
+static void
+cdata (ParsingContext * pc, const char *s, int len)
+{
+	int bytes_left;
+	int bytes_to_copy;
+
+	if (pc->failed)
+		return;
+
+	bytes_left = CDATA_BUF_SIZE - pc->cdata_buf_len;
+	if (len > bytes_left) {
+		HAL_ERROR (("CDATA in element larger than %d",
+			    CDATA_BUF_SIZE));
+		parsing_abort (pc);
+		return;
+	}
+
+	bytes_to_copy = len;
+	if (bytes_to_copy > bytes_left)
+		bytes_to_copy = bytes_left;
+
+	if (bytes_to_copy > 0)
+		memcpy (pc->cdata_buf + pc->cdata_buf_len, s,
+			bytes_to_copy);
+
+	pc->cdata_buf_len += bytes_to_copy;
+}
+
+
+void
+hald_read_conf_file (void)
+{
+	int rc;
+	FILE *file;
+	int filesize;
+	char *filebuf;
+	XML_Parser parser;
+	ParsingContext *parsing_context;
+
+	/*HAL_INFO(("analysing file %s", buf)); */
+
+	/* open file and read it into a buffer; it's a small file... */
+	file = fopen (HALD_CONF_FILE, "r");
+	if (file == NULL) {
+		HAL_INFO (("Couldn't open " HALD_CONF_FILE));
+		goto out;;
+	}
+
+	fseek (file, 0L, SEEK_END);
+	filesize = (int) ftell (file);
+	rewind (file);
+	filebuf = (char *) malloc (filesize);
+	if (filebuf == NULL) {
+		perror ("malloc");
+		goto out1;
+	}
+	fread (filebuf, sizeof (char), filesize, file);
+
+	parser = XML_ParserCreate (NULL);
+
+	/* initialize parsing context */
+	parsing_context =
+	    (ParsingContext *) malloc (sizeof (ParsingContext));
+	if (parsing_context == NULL) {
+		perror ("malloc");
+		goto out2;
+	}
+	parsing_context->failed = FALSE;
+	parsing_context->cdata_buf_len = 0;
+
+	XML_SetElementHandler (parser,
+			       (XML_StartElementHandler) start,
+			       (XML_EndElementHandler) end);
+	XML_SetCharacterDataHandler (parser,
+				     (XML_CharacterDataHandler) cdata);
+	XML_SetUserData (parser, parsing_context);
+
+	rc = XML_Parse (parser, filebuf, filesize, 1);
+
+	if (rc == 0) {
+		/* error parsing document */
+		HAL_ERROR (("Error parsing XML document " HALD_CONF_FILE " at line %d, "
+			    "column %d : %s", 
+			    XML_GetCurrentLineNumber (parser), 
+			    XML_GetCurrentColumnNumber (parser), 
+			    XML_ErrorString (XML_GetErrorCode (parser))));
+	}
+
+	free (parsing_context);
+out2:
+	free (filebuf);
+out1:
+	fclose (file);
+out:
+}

Index: hald_conf.h
===================================================================
RCS file: /cvs/hal/hal/hald/hald_conf.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- a/hald_conf.h	1 Jun 2004 18:47:23 -0000	1.1
+++ b/hald_conf.h	1 Jun 2004 21:10:02 -0000	1.2
@@ -68,7 +68,7 @@
 	dbus_bool_t storage_automount_enabled;
 
 	/** Default value for storage.cdrom.eject_check_enabled for
-	 *  devices of capability storage - this can be overridden by
+	 *  devices of capability storage.cdrom - this can be overridden by
 	 *  .fdi files.
 	 *
 	 *  Setting this to FALSE results a whitelist policy,
@@ -85,6 +85,8 @@
 	dbus_bool_t storage_cdrom_eject_check_enabled;
 };
 
-HaldConf* hald_get_conf (void);
+HaldConf *hald_get_conf (void);
+
+void hald_read_conf_file (void);
 
 #endif  /* HALD_CONF_H */





More information about the hal-commit mailing list