From 26e3790620d0150734fb39cd4b2438e96197a994 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 11 Jul 2006 01:49:06 +0000 Subject: [PATCH] script to migrate to the rfc2307bis schema from nis --- phpgwapi/doc/ldap/README | 23 ++++-- phpgwapi/doc/ldap/nis2rfc2307bis.php | 117 +++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 6 deletions(-) create mode 100755 phpgwapi/doc/ldap/nis2rfc2307bis.php diff --git a/phpgwapi/doc/ldap/README b/phpgwapi/doc/ldap/README index 122ea0de2e..30a4ca1a3b 100644 --- a/phpgwapi/doc/ldap/README +++ b/phpgwapi/doc/ldap/README @@ -14,16 +14,27 @@ Newer SuSE distributions use a rfc2307bis schema, which can be used on other dis To change to the rfc2307bis.schema (not needed with newer SuSE distros!): ---------------------------------- -- create an ldif from your ldap: slapcat > my.ldif +1. create an ldif from your ldap: slapcat > my.ldif +2. run: ./nis2rfc2307bis.php my.ldif > new.ldif +or alternativly edit my.ldif by hand: - add objectclass groupOfNames to every group (only the groups!) - change every occurence of "structuralObjectClass: posixGroup" to "structuralObjectClass: groupOfNames" -- edit your slapd.conf: +- add the required (by groupOfNames) member attributes, by using the information from memberUid, + eg. memberUid: hugo --> member: uid=hugo,ou=account,o=egw,dc=domain,dc=com +--> easier: use the provided script +3. edit your slapd.conf: + remove the include of the nis.schema + include the rfc2307bis.schema in this dir -- stoping ldap -- empty the ldap database (eg. by removing the content of /var/lib/ldap) -- add the edited ldif file -- start ldap again +4. stoping ldap +5. empty the ldap database (eg. by removing the content of /var/lib/ldap) +6. add the edited ldif file: slapadd -f new.ldif +7. start ldap again + +Please note: +----------- +You can use nis2rfc2307bis.php on newer SuSE distros too, to get groupOfNames and the member +attributes set, without editing & saving each group in Admin >> Manage groups. + eGroupWare detects if it can use groupOfNames together with posixGroup and fills the member attribute, if you edit the group or changes the members. diff --git a/phpgwapi/doc/ldap/nis2rfc2307bis.php b/phpgwapi/doc/ldap/nis2rfc2307bis.php new file mode 100755 index 0000000000..f8878ad2bb --- /dev/null +++ b/phpgwapi/doc/ldap/nis2rfc2307bis.php @@ -0,0 +1,117 @@ +#!/usr/bin/php -qC + new.ldif + * + * @link http://www.egroupware.org + * @author Ralf Becker complete rewrite in 6/2006 and earlier modifications + * + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage accounts + * @access public + * @version $Id: class.accounts.inc.php 22048 2006-07-08 21:41:42Z ralfbecker $ + */ + +if ($argc <= 1 || in_array($argv[1],array('-v','--help')) || $argv[1] == '--accounts-dn' && $argc <= 3|| + !is_readable($file = $argv[$argc-1])) +{ + if ($file) + { + echo "'$file' does NOT exist!!!\n"; + } + die("Usage: nis2rfc2307bis.php [--group2account-dn /cn=[^,]+,ou=groups/ou=accounts/] old.ldif > new.ldif\n"); +} + +$lines = file($file); +foreach($lines as $l => $line) +{ + $lines[$l] = trim($line); +} + +$group2account = '/cn=[^,]+,ou=groups/ou=accounts/'; +if ($argv[1] == '--group2account-dn' && $argc > 3) +{ + $group2account = $argv[2]; +} +$parts = explode('/',$group2account); +if (count($parts) != 4) +{ + die("Wrong format for --group2accounts-dn, use something like '/cn=[^,]+,ou=groups/ou=accounts/'\n"); +} +$replace_with = $parts[2]; unset($parts[2]); +$replace = implode('/',$parts); + +$block = array(); +$i = 0; +$lines[] = ''; // extra empty line, if none is behind the last block +foreach($lines as $l => $line) +{ + if ($line) + { + @list($attr,$value) = explode(': ',$line,2); + switch($attr) + { + case 'dn': + $dn = $value; + break; + case 'objectClass': + $objectclasses[] = $value; + break; + case 'structuralObjectClass': + $structural = $value; + break; + case 'memberUid': + $member_dn = 'uid='.$value.','.preg_replace($replace,$replace_with,$dn); + if (!in_array('dn: '.$member_dn,$lines)) continue; // member does not exist --> ignore him! + $members[] = 'member: '.$member_dn; + // fall-through + default: + $data[] = $line; + break; + } + $block[] = $line; + continue; + } + if (!$block) continue; + + // got a complete block + if (in_array('posixGroup',$objectclasses)) + { + switch($structural) + { + case 'namedObject': // regular SuSE + unset($objectclasses[array_search('namedObject',$objectclasses)]); + // fall-through + case 'posixGroup': // nis + $objectclasses[] = $structural = 'groupOfNames'; + if (!$members) $members[] = 'member: '.$dn; // member is a required attribute! + $data = array_merge($members,$data); + break; + case 'groupOfNames': // ok, already what we want + break; + default: + die("\nposixGroup dn: $dn has as structrualObjectClass $structural, not posixGroup, namedObject or groupOfNames!\n"); + } + $block = array('dn: '.$dn,); + foreach($objectclasses as $class) + { + $block[] = 'objectClass: '.$class; + } + $block[] = 'structuralObjectClass: '.$class; + $block = array_merge($block,$data); + } + echo implode("\n",$block)."\n\n"; + + // process next block + $block = $objectclasses = $members = $data = array(); + $dn = $structural = null; +} \ No newline at end of file