Code

SambaMungedDial is now automatically converted when editing samba settings.
authorjanw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 28 Nov 2006 11:32:11 +0000 (11:32 +0000)
committerjanw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 28 Nov 2006 11:32:11 +0000 (11:32 +0000)
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 [new file with mode: 0755]
include/class_sambaMungedDial.inc

diff --git a/contrib/fix_munged.php b/contrib/fix_munged.php
new file mode 100755 (executable)
index 0000000..1195fb3
--- /dev/null
@@ -0,0 +1,95 @@
+#!/usr/bin/php
+<?php
+require_once('../include/class_sambaMungedDial.inc');
+
+/*
+       * GOsa: fix_munged.php - Modify existings sambaMungedDial-Entries to work with latest Win2003SP1 
+       *
+       * Authors: Jan Wenzel    <jan.wenzel@GONICUS.de>
+       *
+       * 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);
+?>
+
index 0f387658196c4e705b6c7cdc5d1b21625ae31a3f..03a5b8c30f4528e4b334c824bcde186664d7c30e 100644 (file)
@@ -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);
        }
   }