9858513
#!/usr/bin/perl -w
9858513
9858513
# Brian Masney <masneyb@ntelos.net>
9858513
# To use this script, set your base DN below. Then run 
9858513
# ./dhcpd-conf-to-ldap.pl < /path-to-dhcpd-conf/dhcpd.conf > output-file
9858513
# The output of this script will generate entries in LDIF format. You can use
9858513
# the slapadd command to add these entries into your LDAP server. You will
9858513
# definately want to double check that your LDAP entries are correct before
9858513
# you load them into LDAP.
9858513
9858513
# This script does not do much error checking. Make sure before you run this
9858513
# that the DHCP server doesn't give any errors about your config file
9858513
9858513
# FailOver notes:
9858513
#   Failover is disabled by default, since it may need manually intervention.
9858513
#   You can try the '--use=failover' option to see what happens :-)
9858513
#
9858513
#   If enabled, the failover pool references will be written to LDIF output.
9858513
#   The failover configs itself will be added to the dhcpServer statements
9858513
#   and not to the dhcpService object (since this script uses only one and
9858513
#   it may be usefull to have multiple service containers in failover mode).
9858513
#   Further, this script does not check if primary or secondary makes sense,
9858513
#   it simply converts what it gets...
9858513
9858513
use Net::Domain qw(hostname hostfqdn hostdomain);
9858513
use Getopt::Long;
9858513
9858513
my $domain = hostdomain();           # your.domain
9858513
my $basedn = "dc=".$domain;
9858513
   $basedn =~ s/\./,dc=/g;           # dc=your,dc=domain
9858513
my $server = hostname();             # hostname (nodename)
9858513
my $dhcpcn = 'DHCP Config';          # CN of DHCP config tree
9858513
my $dhcpdn = "cn=$dhcpcn, $basedn";  # DHCP config tree DN
9858513
my $second = '';                     # secondary server DN / hostname
9858513
my $i_conf = '';                     # dhcp.conf file to read or stdin
9858513
my $o_ldif = '';                     # output ldif file name or stdout
9858513
my @use    = ();                     # extended flags (failover)
9858513
9858513
sub usage($;$)
9858513
{
9858513
  my $rc = shift;
9858513
  my $err= shift;
9858513
9858513
  print STDERR "Error: $err\n\n" if(defined $err);
9858513
  print STDERR <<__EOF_USAGE__;
9858513
usage: 
9858513
  $0 [options] < dhcpd.conf > dhcpd.ldif
9858513
9858513
options:
9858513
9858513
  --basedn  "dc=your,dc=domain"        ("$basedn")
9858513
9858513
  --dhcpdn  "dhcp config DN"           ("$dhcpdn")
9858513
9858513
  --server  "dhcp server name"         ("$server")
9858513
9858513
  --second  "secondary server or DN"   ("$second")
9858513
9858513
  --conf    "/path/to/dhcpd.conf"      (default is stdin)
9858513
  --ldif    "/path/to/output.ldif"     (default is stdout)
9858513
9858513
  --use     "extended features"        (see source comments)
9858513
__EOF_USAGE__
9858513
  exit($rc);
9858513
}
9858513
9858513
9858513
sub next_token
9858513
{
9858513
  local ($lowercase) = @_;
9858513
  local ($token, $newline);
9858513
9858513
  do 
9858513
    {
9858513
      if (!defined ($line) || length ($line) == 0)
9858513
        {
9858513
          $line = <>;
9858513
          return undef if !defined ($line);
9858513
          chop $line;
9858513
          $line_number++;
9858513
          $token_number = 0;
9858513
        }
9858513
9858513
      $line =~ s/#.*//;
9858513
      $line =~ s/^\s+//;
9858513
      $line =~ s/\s+$//;
9858513
    }
9858513
  while (length ($line) == 0);
9858513
9858513
  if (($token, $newline) = $line =~ /^(.*?)\s+(.*)/)
9858513
    {
9858513
      if ($token =~ /^"/) {
9858513
       #handle quoted token
9858513
       if ($token !~ /"\s*$/)
9858513
       {
9858513
         ($tok, $newline)  = $newline =~ /([^"]+")(.*)/;
9858513
         $token .= " $tok";
9858513
        }
9858513
      }
9858513
      $line = $newline;
9858513
    }
9858513
  else
9858513
    {
9858513
      $token = $line;
9858513
      $line = '';
9858513
    }
9858513
  $token_number++;
9858513
9858513
  $token =~ y/[A-Z]/[a-z]/ if $lowercase;
9858513
9858513
  return ($token);
9858513
}
9858513
9858513
9858513
sub remaining_line
9858513
{
9858513
  local ($block) = shift || 0;
9858513
  local ($tmp, $str);
9858513
9858513
  $str = "";
9858513
  while (defined($tmp = next_token (0)))
9858513
    {
9858513
      $str .= ' ' if !($str eq "");
9858513
      $str .= $tmp;
9858513
      last if $tmp =~ /;\s*$/;
9858513
      last if($block and $tmp =~ /\s*[}{]\s*$/);
9858513
    }
9858513
9858513
  $str =~ s/;$//;
9858513
  return ($str);
9858513
}
9858513
9858513
9858513
sub
9858513
add_dn_to_stack
9858513
{
9858513
  local ($dn) = @_;
9858513
9858513
  $current_dn = "$dn, $current_dn";
9858513
}
9858513
9858513
9858513
sub
9858513
remove_dn_from_stack
9858513
{
9858513
  $current_dn =~ s/^.*?,\s*//;
9858513
}
9858513
9858513
9858513
sub
9858513
parse_error
9858513
{
9858513
  print "Parse error on line number $line_number at token number $token_number\n";
9858513
  exit (1);
9858513
}
9858513
9858513
9858513
sub
9858513
print_entry
9858513
{
9858513
  return if (scalar keys %curentry == 0);
9858513
9858513
  if (!defined ($curentry{'type'}))
9858513
    {
9858513
      $hostdn = "cn=$server, $basedn";
9858513
      print "dn: $hostdn\n";
9858513
      print "cn: $server\n";
9858513
      print "objectClass: top\n";
9858513
      print "objectClass: dhcpServer\n";
9858513
      print "dhcpServiceDN: $current_dn\n";
9858513
      if(grep(/FaIlOvEr/i, @use))
9858513
        {
9858513
          foreach my $fo_peer (keys %failover)
9858513
            {
9858513
              next if(scalar(@{$failover{$fo_peer}}) <= 1);
9858513
              print "dhcpStatements: failover peer $fo_peer { ",
9858513
                    join('; ', @{$failover{$fo_peer}}), "; }\n";
9858513
            }
9858513
        }
9858513
      print "\n";
9858513
9858513
      print "dn: $current_dn\n";
9858513
      print "cn: $dhcpcn\n";
9858513
      print "objectClass: top\n";
9858513
      print "objectClass: dhcpService\n";
9858513
      if (defined ($curentry{'options'}))
9858513
        {
9858513
          print "objectClass: dhcpOptions\n";
9858513
        }
9858513
      print "dhcpPrimaryDN: $hostdn\n";
9858513
      if(grep(/FaIlOvEr/i, @use) and ($second ne ''))
9858513
        {
9858513
          print "dhcpSecondaryDN: $second\n";
9858513
        }
9858513
    }
9858513
  elsif ($curentry{'type'} eq 'subnet')
9858513
    {
9858513
      print "dn: $current_dn\n";
9858513
      print "cn: " . $curentry{'ip'} . "\n";
9858513
      print "objectClass: top\n";
9858513
      print "objectClass: dhcpSubnet\n";
9858513
      if (defined ($curentry{'options'}))
9858513
        {
9858513
          print "objectClass: dhcpOptions\n";
9858513
        }
9858513
      
9858513
      print "dhcpNetMask: " . $curentry{'netmask'} . "\n";
9858513
      if (defined ($curentry{'ranges'}))
9858513
        {
9858513
          foreach $statement (@{$curentry{'ranges'}})
9858513
            {
9858513
              print "dhcpRange: $statement\n";
9858513
            }
9858513
        }
9858513
    }
9858513
  elsif ($curentry{'type'} eq 'shared-network')
9858513
    {
9858513
      print "dn: $current_dn\n";
9858513
      print "cn: " . $curentry{'descr'} . "\n";
9858513
      print "objectClass: top\n";
9858513
      print "objectClass: dhcpSharedNetwork\n";
9858513
      if (defined ($curentry{'options'}))
9858513
        {
9858513
          print "objectClass: dhcpOptions\n";
9858513
        }
9858513
    }
9858513
  elsif ($curentry{'type'} eq 'group')
9858513
    {
9858513
      print "dn: $current_dn\n";
9858513
      print "cn: group", $curentry{'idx'}, "\n";
9858513
      print "objectClass: top\n";
9858513
      print "objectClass: dhcpGroup\n";
9858513
      if (defined ($curentry{'options'}))
9858513
        {
9858513
          print "objectClass: dhcpOptions\n";
9858513
        }
9858513
    }
9858513
  elsif ($curentry{'type'} eq 'host')
9858513
    {
9858513
      print "dn: $current_dn\n";
9858513
      print "cn: " . $curentry{'host'} . "\n";
9858513
      print "objectClass: top\n";
9858513
      print "objectClass: dhcpHost\n";
9858513
      if (defined ($curentry{'options'}))
9858513
        {
9858513
          print "objectClass: dhcpOptions\n";
9858513
        }
9858513
9858513
      if (defined ($curentry{'hwaddress'}))
9858513
        {
9858513
          $curentry{'hwaddress'} =~ y/[A-Z]/[a-z]/;
9858513
          print "dhcpHWAddress: " . $curentry{'hwaddress'} . "\n";
9858513
        }
9858513
    }
9858513
  elsif ($curentry{'type'} eq 'pool')
9858513
    {
9858513
      print "dn: $current_dn\n";
9858513
      print "cn: pool", $curentry{'idx'}, "\n";
9858513
      print "objectClass: top\n";
9858513
      print "objectClass: dhcpPool\n";
9858513
      if (defined ($curentry{'options'}))
9858513
        {
9858513
          print "objectClass: dhcpOptions\n";
9858513
        }
9858513
9858513
      if (defined ($curentry{'ranges'}))
9858513
        {
9858513
          foreach $statement (@{$curentry{'ranges'}})
9858513
            {
9858513
              print "dhcpRange: $statement\n";
9858513
            }
9858513
        }
9858513
    }
9858513
  elsif ($curentry{'type'} eq 'class')
9858513
    {
9858513
      print "dn: $current_dn\n";
9858513
      print "cn: " . $curentry{'class'} . "\n";
9858513
      print "objectClass: top\n";
9858513
      print "objectClass: dhcpClass\n";
9858513
      if (defined ($curentry{'options'}))
9858513
        {
9858513
          print "objectClass: dhcpOptions\n";
9858513
        }
9858513
    }
9858513
  elsif ($curentry{'type'} eq 'subclass')
9858513
    {
9858513
      print "dn: $current_dn\n";
9858513
      print "cn: " . $curentry{'subclass'} . "\n";
9858513
      print "objectClass: top\n";
9858513
      print "objectClass: dhcpSubClass\n";
9858513
      if (defined ($curentry{'options'}))
9858513
        {
9858513
          print "objectClass: dhcpOptions\n";
9858513
        }
9858513
      print "dhcpClassData: " . $curentry{'class'} . "\n";
9858513
    }
9858513
9858513
  if (defined ($curentry{'statements'}))
9858513
    {
9858513
      foreach $statement (@{$curentry{'statements'}})
9858513
        {
9858513
          print "dhcpStatements: $statement\n";
9858513
        }
9858513
    }
9858513
9858513
  if (defined ($curentry{'options'}))
9858513
    {
9858513
      foreach $statement (@{$curentry{'options'}})
9858513
        {
9858513
          print "dhcpOption: $statement\n";
9858513
        }
9858513
    }
9858513
9858513
  print "\n";
9858513
  undef (%curentry);
9858513
}
9858513
9858513
9858513
sub parse_netmask
9858513
{
9858513
  local ($netmask) = @_;
9858513
  local ($i);
9858513
9858513
  if ((($a, $b, $c, $d) = $netmask =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) != 4)
9858513
    {
9858513
      parse_error ();
9858513
    }
9858513
9858513
  $num = (($a & 0xff) << 24) |
9858513
         (($b & 0xff) << 16) |
9858513
         (($c & 0xff) << 8) |
9858513
          ($d & 0xff);
9858513
9858513
  for ($i=1; $i<=32 && $num & (1 << (32 - $i)); $i++)
9858513
    {
9858513
    }
9858513
  $i--;
9858513
9858513
  return ($i);
9858513
}
9858513
9858513
9858513
sub parse_subnet
9858513
{
9858513
  local ($ip, $tmp, $netmask);
9858513
9858513
  print_entry () if %curentry;
9858513
    
9858513
  $ip = next_token (0);
9858513
  parse_error () if !defined ($ip);
9858513
9858513
  $tmp = next_token (1);
9858513
  parse_error () if !defined ($tmp);
9858513
  parse_error () if !($tmp eq 'netmask');
9858513
9858513
  $tmp = next_token (0);
9858513
  parse_error () if !defined ($tmp);
9858513
  $netmask = parse_netmask ($tmp);
9858513
9858513
  $tmp = next_token (0);
9858513
  parse_error () if !defined ($tmp);
9858513
  parse_error () if !($tmp eq '{');
9858513
9858513
  add_dn_to_stack ("cn=$ip");
9858513
  $curentry{'type'} = 'subnet';
9858513
  $curentry{'ip'} = $ip;
9858513
  $curentry{'netmask'} = $netmask;
9858513
  $cursubnet = $ip;
9858513
  $curcounter{$ip} = { pool  => 0, group => 0 };
9858513
}
9858513
9858513
9858513
sub parse_shared_network
9858513
{
9858513
  local ($descr, $tmp);
9858513
9858513
  print_entry () if %curentry;
9858513
9858513
  $descr = next_token (0);
9858513
  parse_error () if !defined ($descr);
9858513
9858513
  $tmp = next_token (0);
9858513
  parse_error () if !defined ($tmp);
9858513
  parse_error () if !($tmp eq '{');
9858513
9858513
  add_dn_to_stack ("cn=$descr");
9858513
  $curentry{'type'} = 'shared-network';
9858513
  $curentry{'descr'} = $descr;
9858513
}
9858513
9858513
9858513
sub parse_host
9858513
{
9858513
  local ($descr, $tmp);
9858513
9858513
  print_entry () if %curentry;
9858513
9858513
  $host = next_token (0);
9858513
  parse_error () if !defined ($host);
9858513
9858513
  $tmp = next_token (0);
9858513
  parse_error () if !defined ($tmp);
9858513
  parse_error () if !($tmp eq '{');
9858513
9858513
  add_dn_to_stack ("cn=$host");
9858513
  $curentry{'type'} = 'host';
9858513
  $curentry{'host'} = $host;
9858513
}
9858513
9858513
9858513
sub parse_group
9858513
{
9858513
  local ($descr, $tmp);
9858513
9858513
  print_entry () if %curentry;
9858513
9858513
  $tmp = next_token (0);
9858513
  parse_error () if !defined ($tmp);
9858513
  parse_error () if !($tmp eq '{');
9858513
9858513
  my $idx;
9858513
  if(exists($curcounter{$cursubnet})) {
9858513
    $idx = ++$curcounter{$cursubnet}->{'group'};
9858513
  } else {
9858513
    $idx = ++$curcounter{''}->{'group'};
9858513
  }
9858513
9858513
  add_dn_to_stack ("cn=group".$idx);
9858513
  $curentry{'type'} = 'group';
9858513
  $curentry{'idx'} = $idx;
9858513
}
9858513
9858513
9858513
sub parse_pool
9858513
{
9858513
  local ($descr, $tmp);
9858513
9858513
  print_entry () if %curentry;
9858513
9858513
  $tmp = next_token (0);
9858513
  parse_error () if !defined ($tmp);
9858513
  parse_error () if !($tmp eq '{');
9858513
9858513
  my $idx;
9858513
  if(exists($curcounter{$cursubnet})) {
9858513
    $idx = ++$curcounter{$cursubnet}->{'pool'};
9858513
  } else {
9858513
    $idx = ++$curcounter{''}->{'pool'};
9858513
  }
9858513
9858513
  add_dn_to_stack ("cn=pool".$idx);
9858513
  $curentry{'type'} = 'pool';
9858513
  $curentry{'idx'} = $idx;
9858513
}
9858513
9858513
9858513
sub parse_class
9858513
{
9858513
  local ($descr, $tmp);
9858513
9858513
  print_entry () if %curentry;
9858513
9858513
  $class = next_token (0);
9858513
  parse_error () if !defined ($class);
9858513
9858513
  $tmp = next_token (0);
9858513
  parse_error () if !defined ($tmp);
9858513
  parse_error () if !($tmp eq '{');
9858513
9858513
  $class =~ s/\"//g;
9858513
  add_dn_to_stack ("cn=$class");
9858513
  $curentry{'type'} = 'class';
9858513
  $curentry{'class'} = $class;
9858513
}
9858513
9858513
9858513
sub parse_subclass
9858513
{
9858513
  local ($descr, $tmp);
9858513
9858513
  print_entry () if %curentry;
9858513
9858513
  $class = next_token (0);
9858513
  parse_error () if !defined ($class);
9858513
9858513
  $subclass = next_token (0);
9858513
  parse_error () if !defined ($subclass);
9858513
9858513
  $tmp = next_token (0);
9858513
  parse_error () if !defined ($tmp);
9858513
  parse_error () if !($tmp eq '{');
9858513
9858513
  add_dn_to_stack ("cn=$subclass");
9858513
  $curentry{'type'} = 'subclass';
9858513
  $curentry{'class'} = $class;
9858513
  $curentry{'subclass'} = $subclass;
9858513
}
9858513
9858513
9858513
sub parse_hwaddress
9858513
{
9858513
  local ($type, $hw, $tmp);
9858513
9858513
  $type = next_token (1);
9858513
  parse_error () if !defined ($type);
9858513
9858513
  $hw = next_token (1);
9858513
  parse_error () if !defined ($hw);
9858513
  $hw =~ s/;$//;
9858513
9858513
  $curentry{'hwaddress'} = "$type $hw";
9858513
}
9858513
9858513
    
9858513
sub parse_range
9858513
{
9858513
  local ($tmp, $str);
9858513
9858513
  $str = remaining_line ();
9858513
9858513
  if (!($str eq ''))
9858513
    {
9858513
      $str =~ s/;$//;
9858513
      push (@{$curentry{'ranges'}}, $str);
9858513
    }
9858513
}
9858513
9858513
9858513
sub parse_statement
9858513
{
9858513
  local ($token) = shift;
9858513
  local ($str);
9858513
9858513
  if ($token eq 'option')
9858513
    {
9858513
      $str = remaining_line ();
9858513
      push (@{$curentry{'options'}}, $str);
9858513
    }
9858513
  elsif($token eq 'failover')
9858513
    {
9858513
      $str = remaining_line (1); # take care on block
9858513
      if($str =~ /[{]/)
9858513
        {
9858513
          my ($peername, @statements);
9858513
9858513
          parse_error() if($str !~ /^\s*peer\s+(.+?)\s+[{]\s*$/);
9858513
          parse_error() if(($peername = $1) !~ /^\"?[^\"]+\"?$/);
9858513
9858513
          #
9858513
          # failover config block found:
9858513
          # e.g. 'failover peer "some-name" {'
9858513
          #
9858513
          if(not grep(/FaIlOvEr/i, @use))
9858513
            {
9858513
              print STDERR "Warning: Failover config 'peer $peername' found!\n";
9858513
              print STDERR "         Skipping it, since failover disabled!\n";
9858513
              print STDERR "         You may try out --use=failover option.\n";
9858513
            }
9858513
9858513
          until($str =~ /[}]/ or $str eq "")
9858513
            {
9858513
                $str = remaining_line (1);
9858513
                # collect all statements, except ending '}'
9858513
                push(@statements, $str) if($str !~ /[}]/);
9858513
            }
9858513
          $failover{$peername} = [@statements];
9858513
        }
9858513
      else
9858513
        {
9858513
          #
9858513
          # pool reference to failover config is fine
9858513
          # e.g. 'failover peer "some-name";'
9858513
          #
9858513
          if(not grep(/FaIlOvEr/i, @use))
9858513
            {
9858513
              print STDERR "Warning: Failover reference '$str' found!\n";
9858513
              print STDERR "         Skipping it, since failover disabled!\n";
9858513
              print STDERR "         You may try out --use=failover option.\n";
9858513
            }
9858513
          else
9858513
            {
9858513
              push (@{$curentry{'statements'}}, $token. " " . $str);
9858513
            }
9858513
        }
9858513
    }
9858513
  elsif($token eq 'zone')
9858513
    {
9858513
      $str = $token;
9858513
      while($str !~ /}$/) {
9858513
        $str .= ' ' . next_token (0);
9858513
      }
9858513
      push (@{$curentry{'statements'}}, $str);
9858513
    }
9858513
  elsif($token =~ /^(authoritative)[;]*$/)
9858513
    {
9858513
      push (@{$curentry{'statements'}}, $1);
9858513
    }
9858513
  else
9858513
    {
9858513
      $str = $token . " " . remaining_line ();
9858513
      push (@{$curentry{'statements'}}, $str);
9858513
    }
9858513
}
9858513
9858513
9858513
my $ok = GetOptions(
9858513
    'basedn=s'      => \$basedn,
9858513
    'dhcpdn=s'      => \$dhcpdn,
9858513
    'server=s'      => \$server,
9858513
    'second=s'      => \$second,
9858513
    'conf=s'        => \$i_conf,
9858513
    'ldif=s'        => \$o_ldif,
9858513
    'use=s'         => \@use,
9858513
    'h|help|usage'  => sub { usage(0); },
9858513
);
9858513
9858513
unless($server =~ /^\w+/)
9858513
  {
9858513
    usage(1, "invalid server name '$server'");
9858513
  }
9858513
unless($basedn =~ /^\w+=[^,]+/)
9858513
  {
9858513
    usage(1, "invalid base dn '$basedn'");
9858513
  }
9858513
9858513
if($dhcpdn =~ /^cn=([^,]+)/i)
9858513
  {
9858513
    $dhcpcn = "$1";
9858513
  }
9858513
$second = '' if not defined $second;
9858513
unless($second eq '' or $second =~ /^cn=[^,]+\s*,\s*\w+=[^,]+/i)
9858513
  {
9858513
    if($second =~ /^cn=[^,]+$/i)
9858513
      {
9858513
        # relative DN 'cn=name'
9858513
        $second = "$second, $basedn";
9858513
      }
9858513
    elsif($second =~ /^\w+/)
9858513
      {
9858513
        # assume hostname only
9858513
        $second = "cn=$second, $basedn";
9858513
      }
9858513
    else
9858513
      {
9858513
        usage(1, "invalid secondary '$second'")
9858513
      }
9858513
  }
9858513
9858513
usage(1) unless($ok);
9858513
9858513
if($i_conf ne "" and -f $i_conf)
9858513
  {
9858513
    if(not open(STDIN, '<', $i_conf))
9858513
      {
9858513
        print STDERR "Error: can't open conf file '$i_conf': $!\n";
9858513
        exit(1);
9858513
      }
9858513
  }
9858513
if($o_ldif ne "")
9858513
  {
9858513
    if(-e $o_ldif)
9858513
      {
9858513
        print STDERR "Error: output ldif name '$o_ldif' already exists!\n";
9858513
        exit(1);
9858513
      }
9858513
    if(not open(STDOUT, '>', $o_ldif))
9858513
      {
9858513
        print STDERR "Error: can't open ldif file '$o_ldif': $!\n";
9858513
        exit(1);
9858513
      }
9858513
  }
9858513
9858513
9858513
print STDERR "Creating LDAP Configuration with the following options:\n";
9858513
print STDERR "\tBase DN: $basedn\n";
9858513
print STDERR "\tDHCP DN: $dhcpdn\n";
9858513
print STDERR "\tServer DN: cn=$server, $basedn\n";
9858513
print STDERR "\tSecondary DN: $second\n"
9858513
             if(grep(/FaIlOvEr/i, @use) and $second ne '');
9858513
print STDERR "\n";
9858513
9858513
my $token;
9858513
my $token_number = 0;
9858513
my $line_number = 0;
9858513
my %curentry;
9858513
my $cursubnet = '';
9858513
my %curcounter = ( '' => { pool => 0, group => 0 } );
9858513
9858513
$current_dn = "$dhcpdn";
9858513
$curentry{'descr'} = $dhcpcn;
9858513
$line = '';
9858513
%failover = ();
9858513
9858513
while (($token = next_token (1)))
9858513
  {
9858513
    if ($token eq '}')
9858513
      {
9858513
        print_entry () if %curentry;
9858513
        if($current_dn =~ /.+?,\s*${dhcpdn}$/) {
9858513
          # don't go below dhcpdn ...
9858513
          remove_dn_from_stack ();
9858513
        }
9858513
      }
9858513
    elsif ($token eq 'subnet')
9858513
      {
9858513
        parse_subnet ();
9858513
        next;
9858513
      }
9858513
    elsif ($token eq 'shared-network')
9858513
      {
9858513
        parse_shared_network ();
9858513
        next;
9858513
      }
9858513
    elsif ($token eq 'class')
9858513
      {
9858513
        parse_class ();
9858513
        next;
9858513
      }
9858513
    elsif ($token eq 'subclass')
9858513
      {
9858513
        parse_subclass ();
9858513
        next;
9858513
      }
9858513
    elsif ($token eq 'pool')
9858513
      {
9858513
        parse_pool ();
9858513
        next;
9858513
      }
9858513
    elsif ($token eq 'group')
9858513
      {
9858513
        parse_group ();
9858513
        next;
9858513
      }
9858513
    elsif ($token eq 'host')
9858513
      {
9858513
        parse_host ();
9858513
        next;
9858513
      }
9858513
    elsif ($token eq 'hardware')
9858513
      {
9858513
        parse_hwaddress ();
9858513
        next;
9858513
      }
9858513
    elsif ($token eq 'range')
9858513
      {
9858513
        parse_range ();
9858513
        next;
9858513
      }
9858513
    else
9858513
      {
9858513
        parse_statement ($token);
9858513
        next;
9858513
      }
9858513
  }
9858513
9858513
close(STDIN)  if($i_conf);
9858513
close(STDOUT) if($o_ldif);
9858513
9858513
print STDERR "Done.\n";
9858513