mkdir: support more objectclasses

Depending on the naming attribute given, support the objectclasses
'country' and 'organization' in addition to the default
'organizationalUnit'.

FossilOrigin-Name: 3e9d896cacfa7e1fe533c608a1f7fd7755591736c673d0c7e60e9a0cb0209a89
This commit is contained in:
peter@adpm.de 2011-03-06 13:53:38 +00:00
parent 96dbf0e215
commit 1f684aa21d

View file

@ -304,10 +304,16 @@ You can actually specify your own in your .shelldap.rc, like so:
=item B<mkdir> =item B<mkdir>
Creates a new 'organizationalUnit' entry. Creates a new entry. The type of object created depends on
the naming attribute given, and defaults to 'organizationalUnit'
if none is given.
Supported naming attributes and corresponding object classes are:
c - country
o - organization
ou - organizationalUnit
mkdir containername mkdir myNewOrgUnit
mkdir ou=whatever mkdir o=myNewOrg
=item B<move> =item B<move>
@ -1546,24 +1552,47 @@ sub run_mkdir
{ {
my $self = shift; my $self = shift;
my $dir = join ' ', @_; my $dir = join ' ', @_;
my %ClassMap = ( c => 'country',
o => 'organization',
ou => 'organizationalUnit' );
my %class;
unless ( $dir ) { unless ( $dir ) {
print "No 'directory' provided.\n"; print "No 'directory' provided.\n";
return; return;
} }
# normalize ou name, then pull uniq val back out. # ToDo: path_to_dn
$dir = "ou=$dir" unless $dir =~ /^ou=/i;
$self->rdn_to_dn( \$dir ); $self->rdn_to_dn( \$dir );
my $ou = $1 # normalize name, if it is not yet a legal DN
if $dir =~ /^[\.\w]+(?:\s+)?=(?:\s+)?([\.\-\s\w]+),?/; $dir = 'ou='.$dir if (!canonical_dn($dir));
# add # get RDN: naming attributes (lower-case) and their values
my $r = $self->ldap()->add( $dir, attr => [ my %rdn = %{ shift(@{ ldap_explode_dn($dir, casefold => 'lower') }) };
objectClass => [ 'top', 'organizationalUnit' ],
ou => $ou, # without RDN, return error
]); unless ( %rdn ) {
print "Illegal DN: $dir\n";
return;
}
# get objectclass from naming attributes
foreach my $attr (keys(%rdn)) {
map { $class{$ClassMap{$_}} = 1 if ($attr =~ /^\Q$_\E$/); }
keys(%ClassMap);
}
# fail if we did not get a unique objectclass
unless (scalar(keys(%class)) == 1) {
print "Unsupported DN: $dir\n";
return;
}
# create the new object
my $r = $self->ldap()->add($dir,
attr => [ objectClass => [ 'top', keys(%class) ],
%rdn ]);
print $r->error(), "\n"; print $r->error(), "\n";
$self->update_entries( clearcache => 1 ); $self->update_entries( clearcache => 1 );