From fadcda7cad2a040a1f4ed2d666f2b0d1594ba9b8 Mon Sep 17 00:00:00 2001 From: janw Date: Tue, 28 Nov 2006 11:32:11 +0000 Subject: [PATCH] SambaMungedDial is now automatically converted when editing samba settings. Added convert script to automate this step (BEWARE: Only locally tested). git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5234 594d385d-05f5-0310-b6e9-bd551577e9d8 --- contrib/fix_munged.php | 95 +++++++++++++++++++++++++++++++ include/class_sambaMungedDial.inc | 33 ++++++++++- 2 files changed, 125 insertions(+), 3 deletions(-) create mode 100755 contrib/fix_munged.php diff --git a/contrib/fix_munged.php b/contrib/fix_munged.php new file mode 100755 index 000000000..1195fb305 --- /dev/null +++ b/contrib/fix_munged.php @@ -0,0 +1,95 @@ +#!/usr/bin/php + + * + * Copyright (C) 2006 GONICUS GmbH + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * Contact information: GONICUS GmbH + * Moehnestrasse 11-17 + * D-59755 Arnsberg + * Germany + * tel: ++49 2932 916 0 + * fax: ++49 2932 916 230 + * email: info@GONICUS.de + * http://www.GONICUS.de + * */ + +/* Modify these settings to your needs */ +$ldap_host= "localhost"; +$ldap_port= "389"; +$ldap_base= "dc=gonicus,dc=de"; +$ldap_admin= "cn=ldapadmin,".$ldap_base; +$ldap_password= "tester"; + +/* Internal Settings */ +$ldap_protocol= "3"; +$filter= "(objectClass=sambaSamAccount)"; +$attributes= array("dn","sambaMungedDial"); + +print("This script will try to convert all ldap entries that have the sambaMungedDial-Attribute set, into the new \n". + "format that win2003sp1 and later requires. If an entry is already in the new format, it is not touched. \n". + "BEWARE: This script is not widely tested yet, so use it at your own risk! Be sure to backup your complete LDAP \n". + "before running.\n". + "Do you want to continue (y/n)?\n"); + +$handle= fopen("/dev/stdin","r"); +$input=(fgets($handle,16)); +fclose($handle); +if(substr(strtolower($input),0,1)!="y") { + exit(1); +} +/* Connect to server */ +ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $ldap_protocol); +$connection= ldap_connect($ldap_host,$ldap_port) + or die ('Could not connect to server '.$ldap_host.'!'); +ldap_bind($connection,$ldap_admin,$ldap_password) + or die ('Could not bind to server '.$ldap_host.'!'); + +$results= ldap_get_entries($connection, ldap_search($connection, $ldap_base, $filter, $attributes)); + +$count= 0; + +if(array_key_exists('count', $results)) { + $count= $results['count']; +} + +if($count > 0) { + print('We found '.$count.' matching '.(($count==1)?'entry':'entries').".\n"); +} + +for($i=0; $i<$count; $i++) { + $entry= $results[$i]; + print('Converting '.$entry['dn'].'...'); + $mungedDial = new sambaMungedDial(); + $mungedDial->load($entry['sambamungeddial'][0]); + $modify['sambaMungedDial'][0]= $mungedDial->getMunged(); + if(ldap_modify($connection,$entry['dn'],$modify)) { + print('done.'); + } else { + print('failed.'); + } +} + +ldap_close($connection); +?> + diff --git a/include/class_sambaMungedDial.inc b/include/class_sambaMungedDial.inc index 0f3876581..03a5b8c30 100644 --- a/include/class_sambaMungedDial.inc +++ b/include/class_sambaMungedDial.inc @@ -28,6 +28,15 @@ define ("FILEHEADER", "20002000200020002000200020002000". "20002000200020002000200020002000". "5000"); +/* This is the old header, it is needed to automatically convert old mungedDials to new ones */ +define ("FILEHEADER_OLD", + "6d000800200020002000200020002000". + "20002000200020002000200020002000". + "20002000200020002000200064000100". + "20002000200020002000200020002000". + "20002000200020002000200020002000". + "20002000200020002000200020002000". + "50001000"); class sambaMungedDial { @@ -66,6 +75,7 @@ class sambaMungedDial /* These parameters are treated as time values and get converted */ var $timeParams= array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"); + var $old_behavior= false; function strhex($string) { @@ -221,9 +231,18 @@ class sambaMungedDial /* * Remove base64 encoding and skip FILEHEADER. * The '4' is added, because the FILEHEADER has been stripped by 4 chars. - * These is the number of attributes follow - we don't need this now - only when writing. + * This is the number of attributes following - we don't need this at read time, only when writing. */ - $ctxField= substr(base64_decode($munge), (strlen(FILEHEADER)+4) / 2); + if(substr(base64_decode($munge),0,2)=="6d") { + $this->old_behavior=true; + } + + $ctxField=""; + if($this->old_behavior==true) { + $ctxField= substr(base64_decode($munge), (strlen(FILEHEADER_OLD)) / 2); + } else { + $ctxField= substr(base64_decode($munge), (strlen(FILEHEADER)+4) / 2); + } /* Decode parameters */ while ($ctxField!=""){ @@ -422,7 +441,11 @@ class sambaMungedDial */ function getShadow () { - $result= substr($this->ctx['CtxShadow'], 1, 1); + if($this->old_behavior==true) { + $result= substr($this->ctx['CtxCfgFlags1'], 1, 1); + } else { + $result= substr($this->ctx['CtxShadow'], 1, 1); + } return $result; } @@ -430,6 +453,10 @@ class sambaMungedDial function setShadow ($checked, $value) { if ($checked) { + if($this->old_behavior==true) { + // We need to reset the old setting + $this->ctx['CtxCfgFlags1'][1]= sprintf('%1X', $value); + } $this->ctx['CtxShadow'][1]= sprintf('%1x', $value); } } -- 2.30.2