ADSI DirectoryEntry.CopyTo NotImplementedException

ADSI DirectoryEntry.CopyTo NotImplementedException

Post by Q2hyaXN0b2 » Fri, 24 Mar 2006 18:46:28


When using the DirectoryEntry.CopyTo method I get a NotImplementedException
exception with Active Directory Application Mode (ADAM) as an LDAP backend.

I suppose this means I have to implement a copy function myself.

What I want to do is to use a DirectoryEntry as a template for other
directory entries. A deep copy - meaning a copy of all children and
attributes should - should result in a new, similar entry but with a
different distinguishedName.

At first this does not seem to be such a great challange but recursively
walking the tree and making copies of attributes and children has proven to
be quite difficult. At least if one is to assume no knowledge of the schema
of the copied nodes.

Some attributes cannot be copied since these are COM-objects. Just skipping
attributes that are not ValueTypes or implement the IClonable interface seems
like a good idea but this is not enough since some attributes depend on
others (notably distinguishedName). I quickly arrived at solution where I
simply filtered out all attributes that are not easily copied but I still
have a problem with the local part of the distinguished name - how do I know
if the object requires a cn or an ou or something else? Of course this
information should be possible to extract from the schema DirectoryEntry but
that requires quite a lot of work or I can look at the original's
distinguished name (easier). Allt this might be doable, but seems like an
awful lot of work for something that the API indicates should be possible
with just one method call.

In short - making a copy of a DirectoryEntry object has proven to quite a
challenge.

Any suggestions?

Sincerely,

Christoffer Soop
 
 
 

ADSI DirectoryEntry.CopyTo NotImplementedException

Post by Q2hyaXN0b2 » Fri, 24 Mar 2006 18:50:27

I forgot to mention that I am using Visual C# in .NET framework 1.1.4322.SP1.

/Christoffer

 
 
 

ADSI DirectoryEntry.CopyTo NotImplementedException

Post by MVP for I » Fri, 24 Mar 2006 22:30:00


I don't think this method, has been meant to do shallow copies. It is meant
to copy 1 object. The same applies to the COM method IADs::CopyHere()

Why? Because if you make a copy, you need to provide some info -per object-
to keep it unique (for instance, the email, if it applies).
 
 
 

ADSI DirectoryEntry.CopyTo NotImplementedException

Post by Q2hyaXN0b2 » Fri, 24 Mar 2006 23:30:29

Thanks for your input, much apreciated!


You mean that it is not meant to do deep copies, I think.

Well yes, I see the point. But the only unique properties that matter would
be distinguishedNames and SIDs. Since the SID is created automatically when
creating an object and you do copy the object to a new place in the hiearchy
the distinguished name and SID will be unique.

I have not tried to make a copy of an object that has no children since that
does not solve my problem. Given time I will probably test it sometime
soon...
 
 
 

ADSI DirectoryEntry.CopyTo NotImplementedException

Post by MVP - AD » Sat, 25 Mar 2006 00:36:21

CopyTo is only intended for use with the NDS provider from what I
understand. No LDAP.

You should implement a copy function yourself. I think this will be better
anyway as you'll get to control the semantics of how that works.

Joe K.
 
 
 

ADSI DirectoryEntry.CopyTo NotImplementedException

Post by Marc Scheu » Sat, 25 Mar 2006 06:33:15

Hi Christoffer,


Alas, that's the way it is, yes - I would have *loved* to have this
function as a basis for a "use this user as a template" functionality
myself.


Yes.


Ahem - Children? Of a user account? What do you mean by that.... only
containers (like OU's) can contain child objects, AFAIK.


Well, not really - you need to a) create a new user, and then b) walk
through all the attributes for the existing "template" user and just
copy those over - shouldn't be too hard, really. Yes - some of the
stuff is surfaced as COM - but tht can be handled, too.

Marc
 
 
 

ADSI DirectoryEntry.CopyTo NotImplementedException

Post by Q2hyaXN0b2 » Sat, 25 Mar 2006 17:57:03

> Ahem - Children? Of a user account? What do you mean by that.... only
Well, I am not attempting to copy a user object. I copying a
organizationalUnit with four subcontainers that in turn have non-container
objects.

Well, copying a class that you know the scehma of at design time is no
trouble at all. Then you know exactly what properties to copy and what
properties not to copy. (This is not a problem if the parent is different
from the parent of the object you attempt to copy.) If you attempt to copy
an organizationalUnit you know that the name of the object is the ou
attribute so you don't copy that.

But what if you don't know the class at design time? Should you skip ou,
cn, dc or... ? In order to find out what properties to copy or not you need
to parse the schemaEntry.

The above is not a problem if the parent is different from the parent of the
object you attempt to copy since the distinguishedName will reflect the
parent and you can keep the name of the original.

Some properties depend on each other, like the name of the object and the
distinguishedName. This one is simple but although I can't think of an
example I believe there are other attributes that are automatically managed
by ADSI, ADAM or AD. Like SIDs and GUIDs.

I probably find this difficult because I lack a deep understanding of the
ADSI implementation and AD/ADAM. But getting a NotImplemented exception from
ADSI tells me that maybe even MS found a generic CopyTo method a tad
difficult. What I don't understand is why they just didn't leave out the
method altogether to avoid confusion. Could it be that ADSI uses som
directory-dependent implementation beneath the surface and som directory
services actually support this operation?

/Christoffer
 
 
 

ADSI DirectoryEntry.CopyTo NotImplementedException

Post by Q2hyaXN0b2 » Sat, 25 Mar 2006 17:59:04

> CopyTo is only intended for use with the NDS provider from what I
NDS being Novell Directory Server? That would explain it.

Wonder why the ADSI-documentation doesn't say anything about the metod being
dependent on the directory service implementation and in particular that it
does not work for AD...

/Christoffer
 
 
 

ADSI DirectoryEntry.CopyTo NotImplementedException

Post by MVP - AD » Sat, 25 Mar 2006 23:45:30

This is what the documentation in my MSDN says:

"For the providers supplied with ADSI, only the NDS provider supports an
implementation of this method. Other providers simply return the E_NOTIMPL
error message."

What's not clear about that?

Joe K.
 
 
 

ADSI DirectoryEntry.CopyTo NotImplementedException

Post by Q2hyaXN0b2 » Tue, 28 Mar 2006 07:49:44

I see.

When (re) checking the documentation I only find:

"Creates a copy of this entry, as a child of the specified parent, with the
specified new name."

This is found in the .Net Framework class documentation in Visual Studio
2003. I admit to not being entirely clear on the difference between the
C#.NET System.DirectoryServices name space and ADSI - I thought these were
the same. Evidently not and the lesson learned is to check in more than one
place.

Thanks for making things clearer!

/Christoffer
 
 
 

ADSI DirectoryEntry.CopyTo NotImplementedException

Post by MVP - AD » Tue, 28 Mar 2006 09:21:12

Yeah, unfortunately, to get the real story on .NET Directory Services
programming, you really have to read 4 different references (framework SDK
docs, AD SDK, ADSI SDK, SDS SDK docs). It sucks.

I'm hopeful that our upcoming book will help with this stuff.

Joe K.