This file is indexed.

/usr/share/gosa/plugins/admin/fai/class_FAI.inc is in gosa-plugin-fai 2.7.4+reloaded1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
<?php

define("DEBUG_FAI_FUNC",FALSE);


class FAI
{

  /* TEST PHASE .... */

  static function get_all_objects_for_given_object($dn,$filter,$detailed = false)
  {
    $res  = FAI::get_all_objects_for_given_base($dn,$filter,$detailed);
    $name = preg_replace("/,ou=.*$/","",$dn);
    $entries = array();
    foreach($res as $entry_dn => $data){
      if(!preg_match("/,".$name.",/",$entry_dn)) continue;
      $entries[$entry_dn] = $data; 
    }
    return($entries);
  }




  /* Returns all object for the given release.
     This function resolves the releases  
     from base up to the given dn.
   */
  static function get_all_objects_for_given_base($Current_DN,$filter,$detailed = false)
  {
    global $config;
    $ldap = $config->get_ldap_link();
    $ldap->cd($config->current['BASE']);
    $res = array();
    $tmp = array();

    if(!FAI::is_release_department($Current_DN)) {
#      return($res);
    }

    /* Collect some basic informations and initialize some variables */ 
    $base_release       = FAI::get_release_dn($Current_DN);
    $previous_releases  = array_reverse(FAI::get_previous_releases_of_this_release($base_release,true));

    $ldap->cat($base_release);
    $attrs = $ldap->fetch();
    $FAIstate = "branch";
    if(isset($attrs['FAIstate'][0])){
      $FAIstate = $attrs['FAIstate'][0];
    }

    /* We must also include the given release dn */
    $previous_releases[] = $base_release;

    /* Walk through all releases */
    foreach($previous_releases as $release){

      /* Get fai departments */
      $deps_to_search = FAI::get_FAI_departments($release); 

      /* For every single department  (ou=hoos,ou ..) */
      foreach($deps_to_search as $fai_base){

        /* Ldap search for fai classes specified in this release */
        $attributes  = array("dn","objectClass","FAIstate","cn","FAIdiskType","FAIlvmDevice","FAIdiskOption");
        $res_tmp = get_list($filter,"fai",$fai_base,$attributes,GL_SUBSEARCH);

        /* check the returned objects, and add/replace them in our return variable */
        foreach($res_tmp as $attr){

          $buffer = array();
          $name = preg_replace("/".preg_quote($release, '/')."/i","",$attr['dn']);

          if(isset($attr['FAIstate'][0])){
            if(preg_match("/removed$/",$attr['FAIstate'][0])){
              if(isset($res[$name])){
                unset($res[$name]);
              }
              continue;
            }
          }

          /* Seems to be an inherited class, apply current FAIstate to this classes 
           */
          if(!preg_match("/".preg_quote($base_release, '/')."$/i",$attr['dn'])){
            $buffer['FAIstate'] = $FAIstate; 
          }else{

            /* Seems to be created within this release department.
               This indicates - it can't be of state "freeze"
             */             
            if(isset($attr['FAIstate'])){
              $buffer['FAIstate'] = $attr['FAIstate'][0];
            }else{
              $buffer['FAIstate'] = "branch"; 
            }
          }

          if(isset($attr['FAIdiskType'])){
            $buffer['FAIdiskType'] = $attr['FAIdiskType'][0];
          } else {
            $buffer['FAIdiskType'] = "old";
          }

          if(isset($attr['FAIdiskOption'])){
            $buffer['FAIdiskOption'] = $attr['FAIdiskOption'];
          } else {
            $buffer['FAIdiskOption'] = null;
          }
          if(isset($attr['FAIlvmDevice'])){
            $buffer['FAIlvmDevice'] = $attr['FAIlvmDevice'];
          }

          /* In detailed mode are some additonal informations visible */
          if($detailed){

            /* Create list of parents */
            if(isset($res[$name])){
              $buffer = $res[$name];
              $buffer['parents'][] = $res[$name]['dn'];
            }else{
              $buffer['parents'] = array();
            }

            /* Append objectClass to resulsts */
            foreach($attributes as $val){
              if(isset($attr[$val])){
                $buffer[$val] = $attr[$val];
              }
            }
            unset($buffer['objectClass']['count']);
          }

          /* Add this object to our list */
          $buffer['dn']           = $attr['dn'];
          $res[$name] = $buffer;
        }
      }
    }
    return($res);
  }


  /* Return all relevant FAI departments */
  static function get_FAI_departments($suffix = "")
  {
    global $config;
    $arr = array(
        get_ou('faiScript', 'faiScriptRDN'),
        get_ou('faiHook', 'faiHookRDN'),
        get_ou('faiTemplate', 'faiTemplateRDN'),
        get_ou('faiVariable', 'faiVariableRDN'),
        get_ou('faiProfile', 'faiProfileRDN'),
        get_ou('faiPartitionTable', 'faiPartitionRDN'),
        get_ou('faiPackage', 'faiPackageRDN')
        );

    $tmp = array();
    if(preg_match("/^,/",$suffix)){
      $suffix = preg_replace("/^,/","",$suffix);
    }
    foreach($arr as $name){
      if(empty($suffix)){
        $tmp[$name] = $name;
      }else{
        $tmp[$name] = $name.$suffix;
      }
    }
    return($tmp);
  }


  /* Return all releases within the given base */
  static function get_all_releases_from_base($dn,$appendedName=false)
  {
    global $config;

    if(!preg_match("/".preg_quote(get_ou("faiManagement", "faiBaseRDN"), '/')."/i",$dn)){
      $base = get_ou("faiManagement", "faiBaseRDN").$dn;
    }else{
      $base = $dn;
    }
    $res = array();  

    $ldap = $config->get_ldap_link();
    $ldap->cd($base);
    $ldap->search("(objectClass=FAIbranch)",array("ou","dn"));
    while($attrs = $ldap->fetch()){
      if($appendedName){
        $res[$attrs['dn']] = convert_department_dn(preg_replace("/,".preg_quote(get_ou("faiManagement", "faiBaseRDN"), '/').".*$/i","",$attrs['dn']));
      }else{
        $res[$attrs['dn']] = $attrs['ou'][0];
      }
    }
    return($res);
  }


  /* Add this object to list of objects, that must be checked for release saving */
  static function prepare_to_save_FAI_object($Current_DN,$objectAttrs,$removed = false)
  {
    /* Get ldap object */  
    global $config;
    $addObj['Current_DN'] = $Current_DN;
    $addObj['objectAttrs']= $objectAttrs;
    $addObj['removed']    = $removed;
    $addObj['diff']       = TRUE;

    if(!$removed){
      $ldap = $config->get_ldap_link();
      $ldap->cd($config->current['BASE']);

      /* Get some basic informations */
      $parent_obj   = FAI::get_parent_release_object($Current_DN);
      if(!empty($parent_obj)){
        $ldap->cat($parent_obj,array("*"));
        $attrs = FAI::                           prepare_ldap_fetch_to_be_saved($ldap->fetch());

        if(!FAI::array_diff_FAI( $attrs,$objectAttrs)){
          $addObj['diff'] = FALSE;
        }
      } 
    }else{

      /* If this is the last CLASS of a specific name (e.g. DEPOTSERVER)
          we have to remove this name from all profiles in this release.
      */
      $ldap = $config->get_ldap_link();
      $ldap->cd($config->current['BASE']);
      $obj_dn = FAI::get_parent_release_object($Current_DN,TRUE);

      /* Dont't try to modify non FAIclasses  
       */
      if(!preg_match("/[^,]+,".preg_quote(get_ou("faiManagement", "faiBaseRDN"), '/')."/i",$obj_dn)){
        trigger_error("PLEASE check fai class handling in ".__LINE__." -> ".__FILE__);        
        echo "<br>-->".$Current_DN."<br>";
        echo "<br>-->".$obj_dn."<br>";
      }else{

        /* Get source object and check if it is a base FAIclass
         */
        $ldap->cat($obj_dn);
        $attrs = $ldap->fetch();
        $classes = array("FAIprofile","FAIscript","FAIpackageList","FAIpartitionTable","FAIHook","FAIvariable","FAItemplate");
        if(count(array_intersect($classes,$attrs['objectClass']))){
          $cn    = $attrs['cn'][0];

          /* Check if this is the last with this name in the current release.
              In this case we have to remove the package name 
              from all profiles in this release.
           */
          $classes = FAI::get_all_objects_for_given_base(FAI::get_release_dn($Current_DN),
              "(&(objectClass=FAIclass)(cn=".$cn."))"); 

          /* Check if this is the last class with this name */
          if(count($classes) == 1){

            /* Get all FAI Profiles 
             */
            $profiles = FAI::get_all_objects_for_given_base(FAI::get_release_dn($Current_DN),
                "(&(objectClass=FAIprofile)(FAIclass=*))"); 

            /* Walk though all profiles and remove the source class name
             */
            foreach($profiles as $dn){
              $ldap->cat($dn['dn']);
              $attrs = $ldap->fetch();

              $attrs = array('FAIclass' => $attrs['FAIclass'][0]);

              /* Check if this Profile uses the source class ($cn)
               */
              $classlist = split(" ", $attrs['FAIclass']);
              $new_classlist = "";
              foreach($classlist as $class){
                  if($class != $cn){
                      $new_classlist = $new_classlist." ".$class;
                  }
              } 
              $attrs['FAIclass'] = $new_classlist;
              if(empty($attrs['FAIclass'])){
                  $attrs['FAIclass'] = array();
              }
              $ldap->cd($dn['dn']);
              $ldap->modify($attrs);
              if (!$ldap->success()){
                  msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
              }
            }
          }
        }
      }
    }



    $FAI_objects_to_save = session::get('FAI_objects_to_save') ;
    $FAI_objects_to_save[$Current_DN] =  $addObj;
    session::set('FAI_objects_to_save',$FAI_objects_to_save);
  }


  /* Detect differences in attribute arrays  */
  static function array_diff_FAI($ar1,$ar2)
  {

    if((!isset($ar1['description'])) || (isset($ar1['description']) && (count($ar1['description']) == 0))){
      $ar1['description'] = "";
    }
    if((!isset($ar2['description'])) || (isset($ar2['description']) && (count($ar2['description']) == 0))){
      $ar2['description'] = "";
    }

    if(count($ar1) != count($ar2)) {
      return (true);
    }

    foreach($ar1 as $key1 => $val1){

      if((is_array($val1)) && (count($val1)==1)){
        $ar1[$key1] = $val1[0];
      }

      if(isset($ar2[$key1])&&  (is_array($ar2[$key1])) && (count($ar2[$key1])==1)){
        $val1 = $val1[0];
        $ar2[$key1] = $ar2[$key1][0];
      }
    }
    ksort($ar1);
    ksort($ar2);
    if(count( array_diff($ar1,$ar2)) || FAI::arr_diff($ar1,$ar2)){
      return(true);
    }else{
      return(false);
    }
  }


  static function arr_diff($ar1,$ar2)
  {
    foreach($ar1 as $ak1 => $av1){
      if(!isset($ar2[$ak1]) || (!($av1 === $ar2[$ak1]))){
        return(TRUE);    
      }elseif(is_array($av1)){
        $ret = (FAI::arr_diff($av1,$ar2[$ak1]));
        if($ret) {
          return(TRUE);
        }
      }
    }
    return(FALSE);
  }




  /* check which objects must be saved, and save them */
  static function save_release_changes_now()
  {
    global $config;
    /* Variable init*/
    $to_save = array();
    
    $reload_fai_classes = FALSE;

    /* check which objects must be saved */
    if(!session::is_set('FAI_objects_to_save')){
      return;
    }
    $FAI_objects_to_save = session::get('FAI_objects_to_save');
    if(!is_array($FAI_objects_to_save)) {
      print_a(array(session::get('FAI_objects_to_save')));
      trigger_error("Can't save FAI objects, no array given.");
      return;
    }
  
    foreach($FAI_objects_to_save as $Current_DN => $object){
      if($object['diff']){
        $sub_name = $Current_DN;
        while(isset($FAI_objects_to_save[$sub_name])){
          $to_save[strlen($sub_name)][$sub_name] = $FAI_objects_to_save[$sub_name]; 
          unset($FAI_objects_to_save[$sub_name]);
          $sub_name = preg_replace('/^[^,]+,/', '', $sub_name);
        }
      }
    }
    session::set('FAI_objects_to_save',$FAI_objects_to_save);

    /* Sort list of objects that must be saved, and ensure that 
       container   objects are safed, before their childs are saved */
    ksort($to_save);
    $tmp = array();
    foreach($to_save as $SubObjects){
      foreach($SubObjects as $object){
        $tmp[] = $object;
      }
    }
    $to_save = $tmp;


    /* Save objects and manage the correct release behavior*/
    foreach($to_save as $save){

      $Current_DN = $save['Current_DN'];
      $removed    = $save['removed'];
      $objectAttrs= $save['objectAttrs'];

      /* Get ldap object */ 
      $ldap = $config->get_ldap_link();
      $ldap->cd($config->current['BASE']);

      /* Get some basic informations */
      $base_release       = FAI::get_release_dn($Current_DN);
      $sub_releases       = FAI::get_sub_releases_of_this_release($base_release,true);
      $parent_obj         = FAI::get_parent_release_object($Current_DN);
      $following_releases = $sub_releases;

      /* Check if given dn exists or if is a new entry */
      $ldap->cat($Current_DN);
      if(!$ldap->count()){
        $is_new = true;
      }else{
        $is_new = false;
      }

      /* if parameter removed is true, we have to add FAIstate to the current attrs 
         FAIstate should end with ...|removed after this operation */  
      if($removed ){
        $ldap->cat($Current_DN);

        /* Get current object, because we must add the FAIstate ...|removed */
        if((!$ldap->count()) && !empty($parent_obj)){
          $ldap->cat($parent_obj);
        }

        /* Check if we have found a suiteable object */ 
        if(!$ldap->count()){
          echo "Error can't remove this object ".$Current_DN;
          return;
        }else{

          /* Set FAIstate to current objectAttrs */
          $objectAttrs = FAI::                           prepare_ldap_fetch_to_be_saved($ldap->fetch());
          if(isset($objectAttrs['FAIstate'][0])){
            if(!preg_match("/removed$/",$objectAttrs['FAIstate'][0])){
              $objectAttrs['FAIstate'][0] .= "|removed";
            }
          }else{
            $objectAttrs['FAIstate'][0] = "|removed";
          }

          /* Force reload of FAI classes */
          $classes = array("FAIprofile","FAIscript","FAIpackageList","FAIpartitionTable","FAIHook","FAIvariable","FAItemplate");
          if(count(array_intersect($classes,$objectAttrs['objectClass']))){
            $reload_fai_classes = TRUE;
          }
        }
      }

      /* Check if this a leaf release or not */ 
      if(count($following_releases) == 0 ){

        /* This is a leaf object. It isn't inherited by any other object */    
        if(DEBUG_FAI_FUNC) { 
          echo "<b>Saving directly, is a leaf object</b><br> ".$Current_DN;
          print_a($objectAttrs);
        }
        FAI::save_FAI_object($Current_DN,$objectAttrs);

        /* Force reload of FAI classes */
        $classes = array("FAIprofile","FAIscript","FAIpackageList","FAIpartitionTable","FAIHook","FAIvariable","FAItemplate");
        if(count(array_intersect($classes,$objectAttrs['objectClass']))){
          $reload_fai_classes = TRUE;
        }

      }else{

        /* This object is inherited by some sub releases */  

        /* Get all releases, that inherit this object */ 
        $r = FAI::get_following_releases_that_inherit_this_object($Current_DN);

        /* Get parent object */
        $ldap->cat($parent_obj);
        $parent_attrs = FAI::prepare_ldap_fetch_to_be_saved($ldap->fetch());

        /* New objects require special handling */
        if($is_new){

          /* Force reload of FAI classes */
          $classes = array("FAIprofile","FAIscript","FAIpackageList","FAIpartitionTable","FAIHook","FAIvariable","FAItemplate");
          if(count(array_intersect($classes,$objectAttrs['objectClass']))){
            $reload_fai_classes = TRUE;
          }

          /* check if there is already an entry named like this,
             in one of our parent releases */
          if(!empty($parent_obj)){
            if(DEBUG_FAI_FUNC) { 
              echo "There is already an entry named like this.</b><br>";

              echo "<b>Saving main object</b>".$Current_DN;
              print_a($objectAttrs);
            }    
            FAI::save_FAI_object($Current_DN,$objectAttrs);

            foreach($r as $key){
              if(DEBUG_FAI_FUNC) { 
                echo "<b>Saving parent to following release</b> ".$key;
                print_a($parent_attrs);
              }
              FAI::save_FAI_object($key,$parent_attrs);
            }
          }else{

            if(DEBUG_FAI_FUNC) { 
              echo "<b>Saving main object</b>".$Current_DN;
              print_a($objectAttrs);
            }
            FAI::save_FAI_object($Current_DN,$objectAttrs);

            if(isset($objectAttrs['FAIstate'])){
              $objectAttrs['FAIstate'] .= "|removed"; 
            }else{
              $objectAttrs['FAIstate'] = "|removed";
            }

            foreach($r as $key ){
              if(DEBUG_FAI_FUNC) { 
                echo "<b>Create an empty placeholder in follwing release</b> ".$key; 
                print_a($objectAttrs);
              }
              FAI::save_FAI_object($key,$objectAttrs);
            }
          }
        }else{

          /* check if we must patch the follwing release */
          if(!empty($r)){

            foreach($r as $key ){
              if(DEBUG_FAI_FUNC) { 
                echo "<b>Copy current objects original attributes to next release</b> ".$key;
                print_a($parent_attrs);
              }
             
              /* Append FAIstate tag to ensure that freezed objects stay freezed
               */ 
              $rTag = FAI::get_release_tag(FAI::get_release_dn($key));
              $parent_attrs['FAIstate'] = $rTag;

              /* FAItemplateFile can be binary, therefore it needs to be fetched with
               * $ldap->get_attribute */
              if (isset($parent_attrs['FAItemplateFile'])) {
                $parent_attrs['FAItemplateFile'] = $ldap->get_attribute($parent_obj, 'FAItemplateFile');
              }

              FAI::save_FAI_object($key,$parent_attrs);
            }
          }

          if(DEBUG_FAI_FUNC) { 
            echo "<b>Saving current object</b>".$parent_obj;
            print_a($objectAttrs);
          }
          FAI::save_FAI_object($parent_obj,$objectAttrs);

          if(($parent_obj != $Current_DN)){
            msg_dialog::display(_("Error"), sprintf(_("Error, following objects should be equal '%s' and '%s'"),$parent_obj,$Current_DN), ERROR_DIALOG);
          }
        }
      }
    }

    /* Reload GOsa si FAI DB/cache
     */
    if($reload_fai_classes){
      if( class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
        $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);        
        if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
          $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db']; 
          $tmp = new $evt['CLASS_NAME']($config);
          $tmp->set_type(TRIGGERED_EVENT);
          $tmp->add_targets(array("GOSA"));
          $o_queue = new gosaSupportDaemon();
          if(!$o_queue->append($tmp)){
            msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
          }
        }
      }
    }

    session::set('FAI_objects_to_save',array());
  }


  /* this function will remove all unused (deleted) objects,
     that have no parent object */
  static function clean_up_releases($Current_DN)
  {
    global $config;
    $ldap = $config->get_ldap_link();
    $ldap->cd($config->current['BASE']);

    /* Collect some basic informations and initialize some variables */ 
    $base_release       = FAI::get_release_dn($Current_DN);
    $previous_releases  = array_reverse(FAI::             get_previous_releases_of_this_release($base_release,true));
    $Kill = array();
    $Skip = array();

    /* We must also include the given release dn */
    $previous_releases[] = $base_release;

    /* Walk through all releases */
    foreach($previous_releases as $release){

      /* Get fai departments */
      $deps_to_search = FAI::get_FAI_departments($release); 

      /* For every single department  (ou=hoos,ou ..) */
      foreach($deps_to_search as $fai_base){

        /* Ldap search for fai classes specified in this release */
        $ldap->cd($fai_base);
        $ldap->search("(objectClass=FAIclass)",array("dn","objectClass","FAIstate"));

        /* check the returned objects, and add/replace them in our return variable */
        while($attr = $ldap->fetch()){

          $buffer = array();
#        $name = str_ireplace($release,"",$attr['dn']);
          $name = preg_replace("/".preg_quote($release, '/')."/i","",$attr['dn']);

          if(isset($attr['FAIstate'][0])&&(preg_match("/removed$/",$attr['FAIstate'][0]))){

            /* Check if this object is required somehow */    
            if(!isset($Skip[$name])){
              $Kill[$attr['dn']] = $attr['dn'];
            }
          }else{

            /* This object is required (not removed), so do not 
               delete any following sub releases of this object */
            $Skip[$name] = $attr['dn'];
          }
        }
      }
    }
    return($Kill);
  }


  /* Remove numeric index and 'count' from ldap->fetch result */
  static function prepare_ldap_fetch_to_be_saved($attrs)
  {
    foreach($attrs as $key => $value){
      if(is_numeric($key) || ($key == "count") || ($key == "dn")){
        unset($attrs[$key]);
      }
      if(is_array($value) && isset($value['count'])){
        unset($attrs[$key]['count']);
      }
    }
    return($attrs);
  }


  /* Save given attrs to specified dn*/
  static function save_FAI_object($dn,$attrs)
  {
    global $config;
    $ldap = $config->get_ldap_link();
    $ldap->cd($config->current['BASE']);
    $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dn));
    $ldap->cd($dn);

    $ldap->cat($dn,array("dn"));
    if($ldap->count()){

      /* Remove FAIstate*/
      if(!isset($attrs['FAIstate'])){
        $attrs['FAIstate'] = array();
      }

      $ldap->modify($attrs);
    }else{

      /* Unset description if empty  */
      if(empty($attrs['description'])){
        unset($attrs['description']);
      }    

      $ldap->add($attrs);
    }
    if (!$ldap->success()){
      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, 0, get_class()));
    }
  }


  /* Return FAIstate freeze branch or "" for specified release department */
  static function get_release_tag($dn)
  {
    global $config;
    $ldap = $config->get_ldap_link();
    $ldap->cd($dn);
    $ldap->cat($dn,array("FAIstate"));

    if($ldap->count()){

      $attr = $ldap->fetch();
      if(isset($attr['FAIstate'][0])){
        if(preg_match("/freeze/",$attr['FAIstate'][0])){
          return("freeze");
        }elseif(preg_match("/branch/",$attr['FAIstate'][0])){
          return("branch");
        }
      }
    }
    return("");
  }


  static function get_following_releases_that_inherit_this_object($dn)
  {
    global $config;
    $ldap = $config->get_ldap_link();
    $ldap->cd($config->current['BASE']);

    $ret = array();

    /* Get base release */
    $base_release = FAI::get_release_dn($dn);

    /* Get previous release dns */
    $sub_releases = FAI::                       get_sub_releases_of_this_release($base_release);

    /* Get dn suffix. Example  "FAIvairableEntry=keksdose,FAIvariable=Keksregal," */
#  $dn_suffix = str_ireplace($base_release,"",$dn);
    $dn_suffix = preg_replace("/".preg_quote($base_release, '/')."/i","",$dn);

    /* Check if given object also exists whitin one of these releases */
    foreach($sub_releases as $p_release => $name){

      $check_dn = $dn_suffix.$p_release;

      $ldap->cat($check_dn,array("dn","objectClass"));

      if($ldap->count()){
        //return($ret);
      }else{
        $ret[$check_dn]=$check_dn;
      }
    }
    return($ret);
  }


  /* Get previous version of the object dn */
  static function get_parent_release_object($dn,$include_myself=true)
  {
    global $config;
    $ldap = $config->get_ldap_link();
    $ldap->cd($config->current['BASE']);
    $previous_releases= array();

    /* Get base release */
    $base_release = FAI::get_release_dn($dn);
    if($include_myself){
      $previous_releases[] = $base_release;  
    }

    /* Get previous release dns */
    $tmp = FAI::             get_previous_releases_of_this_release($base_release,true);
    foreach($tmp as $release){
      $previous_releases[] = $release;
    }

    /* Get dn suffix. Example  "FAIvairableEntry=keksdose,FAIvariable=Keksregal," */
#  $dn_suffix = str_ireplace($base_release,"",$dn);
    $dn_suffix = preg_replace("/".preg_quote($base_release, '/')."/i","",$dn);

    /* Check if given object also exists whitin one of these releases */
    foreach($previous_releases as $p_release){
      $check_dn = $dn_suffix.$p_release;
      $ldap->cat($check_dn,array("dn","objectClass"));

      if($ldap->count()){
        return($check_dn);
      }
    }
    return("");
  }


  /* return release names of all parent releases */
  static function get_previous_releases_of_this_release($dn,$flat)
  {
    global $config;
    $ldap = $config->get_ldap_link();
    $ldap->cd($config->current['BASE']);
    $ret = array();

    /* Explode dns into pieces, to be able to build parent dns */
    $dns_to_check = gosa_ldap_explode_dn(preg_replace("/".preg_quote(",".$config->current['BASE'], '/')."/i","",$dn));

    if(!is_array($dns_to_check)){
      return;  
    }

    /* Unset first entry which represents the given dn */
    unset($dns_to_check['count']); 
    unset($dns_to_check[key($dns_to_check)]);

    /* Create dns addresses and check if this dn is a release dn */
    $id = 0;
    while(count($dns_to_check)){

      /* build parent dn */
      $new_dn = "";
      foreach($dns_to_check as $part){
        $new_dn .= $part.",";
      }
      $new_dn .= $config->current['BASE'];

      /* check if this dn is a release */
      if(FAI::is_release_department($new_dn)){
        if($flat){
          $ret[$id] = $new_dn; 
        }else{
          $ret = array($new_dn=>$ret); 
        }
        $id ++;
      }else{
        return($ret);
      }
      reset($dns_to_check);
      unset($dns_to_check[key($dns_to_check)]);
    }
    return($ret);
  } 


  /* This function returns all sub release names, recursivly  */
  static function get_sub_releases_of_this_release($dn,$flat = false)
  {
    global $config;
    $res  = array();
    $ldap = $config->get_ldap_link();
    $ldap->cd($config->current['BASE']);
    $ldap->ls("(objectClass=FAIbranch)",$dn,array("objectClass","dn","ou"));
    while($attr = $ldap->fetch()){

      /* Append department name */
      if($flat){
        $res[$attr['dn']] = $attr['ou'][0];
      }else{
        $res[$attr['dn']] = array();
      }

      /* Get sub release departments of this department */
      if(in_array_strict("FAIbranch",$attr['objectClass'])) {
        if($flat){
          $tmp = FAI::                       get_sub_releases_of_this_release($attr['dn'],$flat);
          foreach($tmp as $dn => $value){
            $res[$dn]=$value;
          }
        }else{
          $res[$attr['dn']] = FAI::                       get_sub_releases_of_this_release($attr['dn']);
        }
      }
    }
    return($res);
  }


  /* Check if the given department is a release department */
  static function is_release_department($dn)
  {
    global $config;
    $ldap = $config->get_ldap_link();
    $ldap->cd($config->current['BASE']);
    $ldap->cat($dn,array("objectClass","ou"));

    /* Check objectClasses and name to check if this is a release department */
    if($ldap->count()){
      $attrs = $ldap->fetch();

      $ou = "";
      if(isset($attrs['ou'][0])){
        $ou = $attrs['ou'][0];	
      }

      if((in_array_strict("FAIbranch",$attrs['objectClass'])) || ($ou == "fai")){
        return($attrs['dn']);
      }
    }
    return(false);
  }


  static function copy_FAI_group_releases($source_release , $destination_name, $type ="" )
  {
    global $config;
    $start = microtime(TRUE);
    $source_release = trim($source_release,"/");

    echo "<h3>".sprintf(_("Creating group application release for %s"),$destination_name)."</h3>";

    $sub_releases = array();
    $source_dn = "";
    
    $tmp = explode("/",$source_release);
    foreach($tmp as $part){
      if(empty($part)){
        continue;
      }
      $source_dn            = "ou=".$part.",".$source_dn;
      $sub_releases[$part]  = $source_dn;
    }

    /* Get all groups */
    $ldap =$config->get_ldap_link();
    $ldap->cd($config->current['BASE']);
    $ldap->search("(objectClass=posixGroup)",array("dn"));
    $groups = array();
    while($attrs = $ldap->fetch()){
      $groups[$attrs['dn']] = $attrs;
    }

    /* Get all FAI releases, to be able to create missing group application releases 
        with the correct type of release (FAIstate=freeze/branch).
     */
    $f_releases = array();
    $ldap->cd ($config->current['BASE']);
    $ldap->search("(objectClass=FAIbranch)",array("ou","FAIstate"));
    while($attrs = $ldap->fetch()){
      foreach($sub_releases as $sub_rel){
        if(preg_match("/^".preg_quote($sub_rel.get_ou("faiManagement", "faiBaseRDN"), '/')."/i",$attrs['dn'])){
          $f_releases[$sub_rel.get_ou("faiManagement", "faiBaseRDN")] = $attrs;
        }
      }
    }

    /* Get all group releases */
    $g_releases = array();
    foreach($groups as $dn => $data){
      $ldap->cd($dn);
      $ldap->search("(objectClass=FAIbranch)",array("ou","FAIstate"));
      while($attrs = $ldap->fetch()){
        $g_releases[$attrs['dn']] = $attrs;
      }
    }

    /* Check if base releases exists.
       If they do not exist, create them and adapt FAIstate attribute from FAI releases. 
     */
    foreach($sub_releases as $name => $sub_rel){

      $FAIstate = "";
      if(isset($f_releases[$sub_rel.get_ou("faiManagement", "faiBaseRDN")]) && isset($f_releases[$sub_rel.get_ou("faiManagement", "faiBaseRDN")]['FAIstate'])){
        $FAIstate = $f_releases[$sub_rel.get_ou("faiManagement", "faiBaseRDN")]['FAIstate'][0];
      }

      foreach($groups as $dn => $data){
        if(!isset($g_releases[$sub_rel.$dn])){
          $ldap->cd($dn);
          $r_data = array();
          $r_data['ou'] = $name;
          $r_data['objectClass'] = array("top","organizationalUnit","FAIbranch");
          if(!empty($FAIstate)) {
            $r_data['FAIstate'] = $FAIstate;
          }
 
          $ldap->cd($sub_rel.$dn) ;
          $ldap->add($r_data);
          echo "&nbsp;<b>"._("Object").":</b> ";
          echo sprintf(_("Adding missing group application release container %s."),substr(LDAP::fix($sub_rel.$dn),0,96))."<br>";
          flush();
        }
      }
    } 
 
    /* Create new release container in each group.
     */
    $n_data = array();
    $n_data = array();
    $n_data['ou'] = $destination_name;
    $n_data['objectClass'] = array("top","organizationalUnit","FAIbranch");
    if(!empty($type)){
      $n_data['FAIstate'] = $type."/cow";
    }

    foreach($groups as $dn => $att){
      $n_dn = "ou=".$destination_name.",".$source_dn.$dn;
      if(!isset($g_releases[$n_dn])){
        $ldap->cd ($n_dn);
        $ldap->add($n_data);
        echo "&nbsp;<b>"._("Object").":</b> ";
        echo sprintf(_("Adding group application release container %s."),substr(LDAP::fix($n_dn),0,96))."<br>";
        flush();
      }
    }

    /* If the source release is empty, then create a new release by copying 
        all group application menus into a new ou=$destination_name release container.
      
       If the source release is not empty. 
         We detect all releases which match the source release dn and copy the contents.
     */
    if(empty($source_release)){
      $source_dns = $groups;
    }else{
      $source_dns = array();
      foreach($g_releases as $dn => $data){
        if(preg_match("/^".preg_quote($source_dn, '/')."/",$dn)){
          $source_dns[$dn] = $data; 
        }
      }
    }

    /* Detect all menu object we have to copy 
     */
    $to_copy = array();
    foreach($source_dns as $dn => $attrs){
      $ldap->cd($dn);
      $ldap->ls("(|(objectClass=gotoSubmenuEntry)(objectClass=gotoMenuEntry))",$dn,array("dn"));
      while($attrs = $ldap->fetch()){
        $destination = preg_replace("/".preg_quote($dn, '/')."$/","ou=".$destination_name.",".$dn,$attrs['dn']);
        $to_copy[$attrs['dn']] = $destination;
      }
    }
   
    /* At least create the menu objects object */
    $plug = new plugin($config);
    foreach($to_copy as $source => $destination){
      $ldap->cat($destination);
      if($ldap->count()){
        echo "&nbsp;<b>"._("Object").":</b> ";
        echo sprintf(_("Could not create menu entry %s. (Already exists)."),substr(LDAP::fix($destination),0,96))."<br>";
        flush();
      }else{
        $plug->copy($source,$destination);
        echo "&nbsp;<b>"._("Object").":</b> ";
        echo sprintf(_("Created group application menu entry for %s."),substr(LDAP::fix($destination),0,96))."<br>";
        flush();
      }
    }
  }


  /*! \brief Create a new FAI branch.
   *  @param $sourcedn          String  The source release dn
   *  @param $destinationdn     String  The destination dn
   *  @param $destinationName   String  The name of the new release
   *  @param $type              String  The release type (freeze/branch)
   *  @param $is_first          Boolean Use to identify the first func. call when recursivly called.
   *  @param $depth             Integer Current depth of recursion.
   */
  static function copy_FAI_resource_recursive($sourcedn,$destinationdn,$destinationName,$type="branch",$is_first = true,$depth=0)
  {
    global $config;
    error_reporting(E_ALL | E_STRICT);
    $ldap     = $config->get_ldap_link();
    $basedn   = $config->current['BASE'];
    $delarray = array();

    /* The following code will output a status string
     *  for each handled object, in a seperate iframe.
     */


    /* Display current action information.
     */
    if($is_first){
      echo "<h3>".sprintf(_("Creating copy of %s"),"<i>".LDAP::fix($sourcedn)."</i>")."</h3>";
    }else{
      if(preg_match("/^ou=/",$sourcedn)){
        echo "<h3>"._("Processing")." <i>".LDAP::fix($destinationdn)."</i></h3>";
      }else{
        $tmp = explode(",",$sourcedn);
        echo "&nbsp;<b>"._("Object").":</b> ";
        $deststr = LDAP::fix($destinationdn);
        if(strlen($deststr) > 96){
          $deststr = substr($deststr,0,96)."...";
        }
        echo $deststr."<br>";
      }
    }
    /* .. immediately display infos */
    flush();

    /* Check if destination entry already exists
     */
    $ldap->cat($destinationdn);
    if($ldap->count()){
      echo _("Could not create new release, the destination DN is already in use.");
      return;
    }else{

      $ldap->clearResult();

      /* Get source entry
       *  if it does not exist, abort here.
       */
      $ldap->cd($basedn);
      $ldap->cat($sourcedn);
      $attr = $ldap->fetch();
      if((!$attr) || (count($attr)) ==0) {
        echo _("Error while fetching source DN - aborted!");
        return;
      }

      /* The current object we want to create is an department.
       * Create the department and add the FAIbranch tag.
       */
      if(in_array_strict("organizationalUnit",$attr['objectClass'])){
        $attr['dn'] = LDAP::convert($destinationdn);
        $ldap->cd($basedn);
        $ldap->create_missing_trees($destinationdn);
        $ldap->cd($destinationdn);

        /* If is first entry, append FAIbranch to department entry */
        if($is_first){
          $ldap->cat($destinationdn);
          $attr= $ldap->fetch();
          /* Filter unneeded informations */
          foreach($attr as $key => $value){
            if(is_numeric($key)) unset($attr[$key]);
            if(isset($attr[$key]['count'])){
              if(is_array($attr[$key])){
                unset($attr[$key]['count']);
              }
            }
          }

          unset($attr['count']);
          unset($attr['dn']);

          /* Add marking attribute */
          $attr['objectClass'][] = "FAIbranch";
          $attr['FAIstate'] = $type;

          /* Add this entry */
          $ldap->modify($attr);
        }
      }else{

        /* Replicate all relevant FAI objects here.
         * FAI objects, Apps and Mimetypes.
         * Get all attributes as binary value, to ensure that Icon, File template aso
         *  are created correctly.
         */
        foreach($attr as $key => $value){

          if(in_array_strict($key ,array("gotoLogonScript", "gosaApplicationIcon","gotoMimeIcon"))){
            $sr= ldap_read($ldap->cid, LDAP::fix($sourcedn), "$key=*", array($key));
            $ei= ldap_first_entry($ldap->cid, $sr);
            if ($tmp= @ldap_get_values_len($ldap->cid, $ei,$key)){
              $attr[$key] = $tmp;
            }
          }

          if(is_numeric($key)) unset($attr[$key]);
          if(isset($attr[$key]['count'])){
            if(is_array($attr[$key])){
              unset($attr[$key]['count']);
            }
          }
        }
        unset($attr['count']);
        unset($attr['dn']);
        if(!in_array_strict("FAIobject",$attr['objectClass'])){
          $attr['objectClass'][] = "FAIobject";
        }
        $attr['FAIstate'] = $type;

        /* Add entry
         */
        $ldap->cd($destinationdn);
        $ldap->cat($destinationdn);

        $a = $ldap->fetch();
        if(!count($a)){
          $ldap->add($attr);
        }

        if(!$ldap->success()){

          /* Some error occurred */
          msg_dialog::display(_("Fatal error"),
              sprintf(_("Release creation failed due to LDAP errors: %s"),
                $ldap->get_error()."<br>".$sourcedn."<br>".$destinationdn."<br>"),FATAL_ERROR_DIALOG);
          exit();
        }
      }
    }

    echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;

    /* Prepare for recursive copy.
     * Get all object within the source dn and
     *  call the recursive copy for each.
     */
    $ldap->ls ("(objectClass=*)",$sourcedn);
    while ($ldap->fetch()){
      $deldn= $ldap->getDN();
      $delarray[$deldn]= strlen($deldn);
    }
    asort ($delarray);
    reset ($delarray);
    $depth ++;
    foreach($delarray as $dn => $bla){
      if($dn != $destinationdn){
        $ldap->cd($basedn);
        $item = $ldap->fetch($ldap->cat($dn));
        if(!in_array_strict("FAIbranch",$item['objectClass'])){
          FAI::copy_FAI_resource_recursive($dn,str_replace($sourcedn,$destinationdn,$dn),$destinationName,$type,false,$depth);
        }
      }
    }
    if($is_first){
      echo "<hr>";
    }
  }



  /* This function returns the dn of the object release */
  static function get_release_dn($Current_DN)
  {
    global $config;
    $ldap = $config->get_ldap_link();
    $ldap->cd($config->current['BASE']);

    /* Split dn into pices */ 
    $dns_to_check = gosa_ldap_explode_dn(preg_replace("/".preg_quote(",".$config->current['BASE'], '/')."/i","",$Current_DN));

    if(!is_array($dns_to_check)){
      return;  
    }

    /* Use dn pieces, to create sub dns like 
       ou=test,ou=1,ou=0...
       ou=1,ou=0...
       ou=0... 
       To check which dn is our release container.
     */
    unset($dns_to_check['count']); 
    while(count($dns_to_check)){

      /* Create dn */
      $new_dn = "";
      foreach($dns_to_check as $part){
        $new_dn .= $part.",";
      }
      $new_dn .= $config->current['BASE'];

      /* Check if this dn is a release dn */
      if(FAI::is_release_department($new_dn)){
        return($new_dn);
      }

      /* Remove first element of dn pieces */
      reset($dns_to_check);
      unset($dns_to_check[key($dns_to_check)]);
    }
    return("");
  }
}




// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>