[Debconf-devel] Bug#477531: debconf: Patch to allow storing of templates in LDAP

Davor Ocelic docelic at mail.inet.hr
Wed Apr 23 19:00:53 UTC 2008


Package: debconf
Version: 1.5.21
Severity: wishlist
Tags: patch


Hello,

Attached is a patch allowing Debconf to store and read templates
from a LDAP database.

Davor Ocelic, <docelic at spinlocksolutions.com>

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: powerpc (ppc64)

Kernel: Linux 2.6.24-1-powerpc64 (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages debconf depends on:
ii  debconf-i18n                  1.5.20     full internationalization support 
ii  perl-base                     5.8.8-12   The Pathologically Eclectic Rubbis

Versions of packages debconf recommends:
ii  apt-utils                     0.7.11     APT utility programs

-- debconf information excluded
-------------- next part --------------
diff -ru debconf-1.5.21/Debconf/DbDriver/LDAP.pm debconf-1.5.21,ldap-templates/Debconf/DbDriver/LDAP.pm
--- debconf-1.5.21/Debconf/DbDriver/LDAP.pm	2008-04-11 18:14:39.000000000 +0200
+++ debconf-1.5.21,ldap-templates/Debconf/DbDriver/LDAP.pm	2008-04-23 20:55:34.000000000 +0200
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 # Copyright (C) 2002 Matthew Palmer.
-# Copyright (C) 2007 Davor Ocelic.
+# Copyright (C) 2007-2008 Davor Ocelic.
 
 =head1 NAME
 
@@ -79,7 +79,7 @@
 
 =cut
 
-use fields qw(server port basedn binddn bindpasswd exists keybykey ds);
+use fields qw(server port basedn binddn bindpasswd exists keybykey ds accept_attribute reject_attribute);
 
 =head1 METHODS
 
@@ -205,11 +205,30 @@
 				'objectclass' => 'debconfdbentry',
 				'cn' => $item
 		];
+
+		# Perform generic replacement in style of:
+		# extended_description -> extendedDescription
+		my @fields = keys %{$data{fields}};
+		foreach my $field (@fields) {
+			my $ldapname = $field;
+			if ( $ldapname =~ s/_(\w)/uc($1)/ge ) {
+				$data{fields}->{$ldapname} =  $data{fields}->{$field};
+				delete $data{fields}->{$field};
+			}
+		}
 		
 		foreach my $field (keys %{$data{fields}}) {
 			# skip empty fields exept value field
 			next if ($data{fields}->{$field} eq '' && 
 				 !($field eq 'value'));
+			if ((exists $this->{accept_attribute} &&
+				 $field !~ /$this->{accept_attribute}/) or
+				(exists $this->{reject_attribute} &&
+				 $field =~ /$this->{reject_attribute}/)) {
+				debug "db $item" => "reject $field";
+				next;
+			}
+
  			$modify_data{$field}=$data{fields}->{$field};
 			push(@{$add_data}, $field);
 			push(@{$add_data}, $data{fields}->{$field});
@@ -343,8 +362,13 @@
 			if ($attr eq 'objectclass') {
 				next;
 			}
-			debug "db $this->{name}" => "Setting data for $attr";
 			my $values = $entry->{$attr};
+
+			# Perform generic replacement in style of:
+			# extendedDescription -> extended_description
+			$attr =~ s/([a-z])([A-Z])/$1.'_'.lc($2)/ge;
+
+			debug "db $this->{name}" => "Setting data for $attr";
 			foreach my $val (@{$values}) {
 				debug "db $this->{name}" => "$attr = $val";
 				if ($attr eq 'owners') {
@@ -372,8 +396,7 @@
 
 Matthew Palmer <mpalmer at ieee.org>
 
-Davor Ocelic <debconf at spinlocksolutions.com> -
-Added KeyByKey support for http://infrastructures.spinlocksolutions.com/
+Davor Ocelic <docelic at spinlocksolutions.com>
 
 =cut
 
diff -ru debconf-1.5.21/doc/debconf.schema debconf-1.5.21,ldap-templates/doc/debconf.schema
--- debconf-1.5.21/doc/debconf.schema	2007-12-31 23:43:43.000000000 +0100
+++ debconf-1.5.21,ldap-templates/doc/debconf.schema	2008-04-23 20:37:38.000000000 +0200
@@ -52,6 +52,18 @@
 	EQUALITY octetStringMatch
 	SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
 
+attributetype ( 1.3.6.1.4.9586.1.2.1.9
+	NAME 'default'
+	DESC 'Default value'
+	EQUALITY octetStringMatch
+	SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
+
+attributetype ( 1.3.6.1.4.9586.1.2.1.10
+	NAME 'choices'
+	DESC 'Possible choices'
+	EQUALITY octetStringMatch
+	SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
+
 objectclass ( 1.3.6.1.4.9586.1.2.2.1
 	NAME 'debConfDbEntry'
 	MUST ( cn $ owners )
diff -ru debconf-1.5.21/doc/README.LDAP debconf-1.5.21,ldap-templates/doc/README.LDAP
--- debconf-1.5.21/doc/README.LDAP	2007-12-31 23:43:43.000000000 +0100
+++ debconf-1.5.21,ldap-templates/doc/README.LDAP	2008-04-23 20:56:42.000000000 +0200
@@ -6,10 +6,6 @@
 testing this module - the more eyes, the quicker the bugs get found and
 stomped.
 
-At present, it is not recommended that you use this module to store
-templates.  Multilingual templates will most certainly not work, and I
-haven't tested default templates either.  You Have Been Warned.
-
 To get this to work, you need to do the following:
 
 1) Get /usr/share/doc/debconf-doc/debconf.schema into your DS.
@@ -24,6 +20,16 @@
 
 4) Configure your packages as you see fit.
 
+
+Since Debconf 1.5.22, it is possible that you use this module to store
+templates as well. Multilingual templates will not work, so stick to the
+default English elements. To filter out multilingual parts of the templates,
+use the LDAP-specific Accept-Attribute and Reject-Attribute regex options.
+
 --
 Matthew Palmer
 <mpalmer at ieee.org>
+
+Davor Ocelic
+<docelic at spinlocksolutions.com>
+


More information about the Debconf-devel mailing list