shelldap
changeset 38 12f279ef4f9d
parent 37 7a8855e7cfb8
child 40 c6a3abc56c74
equal deleted inserted replaced
37:7a8855e7cfb8 38:12f279ef4f9d
   309         posixGroup: gidNumber
   309         posixGroup: gidNumber
   310         ipHost: ipHostNumber
   310         ipHost: ipHostNumber
   311 
   311 
   312 =item B<mkdir>
   312 =item B<mkdir>
   313 
   313 
   314 Creates a new entry. The type of object created depends on
   314 Creates a new 'organizationalUnit' entry.
   315 the naming attribute given, and defaults to 'organizationalUnit'
   315 
   316 if none is given.
   316     mkdir containername
   317 Supported naming attributes and corresponding object classes are:
   317     mkdir ou=whatever
   318     c	- country
       
   319     o	- organization
       
   320     ou	- organizationalUnit
       
   321 
       
   322     mkdir myNewOrgUnit
       
   323     mkdir o=myNewOrg
       
   324 
   318 
   325 =item B<move>
   319 =item B<move>
   326 
   320 
   327 Move an entry to a different dn path.  Usage is identical to B<copy>.
   321 Move an entry to a different dn path.  Usage is identical to B<copy>.
   328 
   322 
  1574 
  1568 
  1575 sub run_mkdir
  1569 sub run_mkdir
  1576 {
  1570 {
  1577 	my $self = shift;
  1571 	my $self = shift;
  1578 	my $dir  = join ' ', @_;
  1572 	my $dir  = join ' ', @_;
  1579 	my %ClassMap = ( c => 'country',
       
  1580 			 o => 'organization',
       
  1581 			 ou => 'organizationalUnit' );
       
  1582 	my %class;
       
  1583 
  1573 
  1584 	unless ( $dir ) {
  1574 	unless ( $dir ) {
  1585 		print "No 'directory' provided.\n";
  1575 		print "No 'directory' provided.\n";
  1586 		return;
  1576 		return;
  1587 	}
  1577 	}
  1588 
  1578 
  1589 	# convert given path to DN
  1579 	# normalize name, if it is not yet a legal DN
       
  1580 	$dir = 'ou=' . $dir unless canonical_dn( $dir );
       
  1581 
       
  1582 	# convert given path to full DN
  1590 	$dir = $self->path_to_dn( $dir );
  1583 	$dir = $self->path_to_dn( $dir );
  1591 
  1584 
  1592 	# normalize name, if it is not yet a legal DN
       
  1593 	$dir = 'ou='.$dir  if (!canonical_dn($dir));
       
  1594 
       
  1595 	# get RDN: naming attributes (lower-case) and their values
  1585 	# get RDN: naming attributes (lower-case) and their values
  1596         my %rdn = %{ shift(@{ ldap_explode_dn($dir, casefold => 'lower') }) };
  1586 	my %rdn = %{ shift(@{ ldap_explode_dn($dir, casefold => 'lower') }) };
  1597 
  1587 
  1598 	# without RDN, return error
  1588 	# add
  1599 	unless ( %rdn ) {
  1589 	my $r = $self->ldap()->add( $dir, attr => [
  1600 		print "Illegal DN: $dir\n";
  1590 		objectClass => [ 'top', 'organizationalUnit' ], %rdn
  1601 		return;
  1591 	]);
  1602 	}
       
  1603 
       
  1604 	# get objectclass from naming attributes
       
  1605 	foreach my $attr (keys(%rdn)) {
       
  1606 		map { $class{$ClassMap{$_}} = 1  if ($attr =~ /^\Q$_\E$/); }
       
  1607 		    keys(%ClassMap);
       
  1608 	}
       
  1609 
       
  1610 	# fail if we did not get a unique objectclass
       
  1611 	unless (scalar(keys(%class)) == 1) {
       
  1612 		print "Unsupported DN: $dir\n";
       
  1613 		return;
       
  1614 	}
       
  1615 
       
  1616 	# create the new object
       
  1617 	my $r = $self->ldap()->add($dir,
       
  1618 				   attr => [ objectClass => [ 'top', keys(%class) ],
       
  1619 					     %rdn ]);
       
  1620 
  1592 
  1621 	print $r->error(), "\n";
  1593 	print $r->error(), "\n";
  1622 	$self->update_entries( clearcache => 1 );
  1594 	$self->update_entries( clearcache => 1 );
  1623 	return;
  1595 	return;
  1624 }
  1596 }