shelldap
changeset 29 bd95c3aea253
parent 28 d42bd1b087a1
child 30 e4b4b0968107
equal deleted inserted replaced
28:d42bd1b087a1 29:bd95c3aea253
   302         ipHost: ipHostNumber
   302         ipHost: ipHostNumber
   303         puppetClient: puppetclass
   303         puppetClient: puppetclass
   304 
   304 
   305 =item B<mkdir>
   305 =item B<mkdir>
   306 
   306 
   307 Creates a new 'organizationalUnit' entry.
   307 Creates a new entry. The type of object created depends on
   308 
   308 the naming attribute given, and defaults to 'organizationalUnit'
   309     mkdir containername
   309 if none is given.
   310     mkdir ou=whatever
   310 Supported naming attributes and corresponding object classes are:
       
   311     c	- country
       
   312     o	- organization
       
   313     ou	- organizationalUnit
       
   314 
       
   315     mkdir myNewOrgUnit
       
   316     mkdir o=myNewOrg
   311 
   317 
   312 =item B<move>
   318 =item B<move>
   313 
   319 
   314 Move an entry to a different dn path.  Usage is identical to B<copy>.
   320 Move an entry to a different dn path.  Usage is identical to B<copy>.
   315 
   321 
  1544 
  1550 
  1545 sub run_mkdir
  1551 sub run_mkdir
  1546 {
  1552 {
  1547 	my $self = shift;
  1553 	my $self = shift;
  1548 	my $dir  = join ' ', @_;
  1554 	my $dir  = join ' ', @_;
       
  1555 	my %ClassMap = ( c => 'country',
       
  1556 			 o => 'organization',
       
  1557 			 ou => 'organizationalUnit' );
       
  1558 	my %class;
  1549 
  1559 
  1550 	unless ( $dir ) {
  1560 	unless ( $dir ) {
  1551 		print "No 'directory' provided.\n";
  1561 		print "No 'directory' provided.\n";
  1552 		return;
  1562 		return;
  1553 	}
  1563 	}
  1554 
  1564 
  1555 	# normalize ou name, then pull uniq val back out.
  1565 	# ToDo: path_to_dn
  1556 	$dir = "ou=$dir" unless $dir =~ /^ou=/i;
       
  1557 	$self->rdn_to_dn( \$dir );
  1566 	$self->rdn_to_dn( \$dir );
  1558 
  1567 
  1559 	my $ou = $1
  1568 	# normalize name, if it is not yet a legal DN
  1560 	  if $dir =~ /^[\.\w]+(?:\s+)?=(?:\s+)?([\.\-\s\w]+),?/;
  1569 	$dir = 'ou='.$dir  if (!canonical_dn($dir));
  1561 
  1570 
  1562 	# add
  1571 	# get RDN: naming attributes (lower-case) and their values
  1563 	my $r = $self->ldap()->add( $dir, attr => [
  1572         my %rdn = %{ shift(@{ ldap_explode_dn($dir, casefold => 'lower') }) };
  1564 		objectClass => [ 'top', 'organizationalUnit' ],
  1573 
  1565 		ou		  => $ou,
  1574 	# without RDN, return error
  1566 	]);
  1575 	unless ( %rdn ) {
       
  1576 		print "Illegal DN: $dir\n";
       
  1577 		return;
       
  1578 	}
       
  1579 
       
  1580 	# get objectclass from naming attributes
       
  1581 	foreach my $attr (keys(%rdn)) {
       
  1582 		map { $class{$ClassMap{$_}} = 1  if ($attr =~ /^\Q$_\E$/); }
       
  1583 		    keys(%ClassMap);
       
  1584 	}
       
  1585 
       
  1586 	# fail if we did not get a unique objectclass
       
  1587 	unless (scalar(keys(%class)) == 1) {
       
  1588 		print "Unsupported DN: $dir\n";
       
  1589 		return;
       
  1590 	}
       
  1591 
       
  1592 	# create the new object
       
  1593 	my $r = $self->ldap()->add($dir,
       
  1594 				   attr => [ objectClass => [ 'top', keys(%class) ],
       
  1595 					     %rdn ]);
  1567 
  1596 
  1568 	print $r->error(), "\n";
  1597 	print $r->error(), "\n";
  1569 	$self->update_entries( clearcache => 1 );
  1598 	$self->update_entries( clearcache => 1 );
  1570 	return;
  1599 	return;
  1571 }
  1600 }