How to unbind when you lose Net::LDAP object

Greg Zartman <[email protected]> Mon, 22 Dec 2014 00:57:22 -0800
Newsgroups gmane.comp.lang.perl.modules.ldap
Message-ID <CADp5nUYR+mba8=TUNQXauHyHNREfr08wm1CzjJDcGOqkfBGUeg@mail.gmail.com>
--e89a8f3bad45568741050aca400d
Content-Type: text/plain; charset=UTF-8

I'm working on an API for the Koozali SME Server to use Samba 4, Active
Directory.   One of the things I'm trying to do is abstract quite alot of
the Net::LDAP syntax so that SME Server admins can just ask the API for
various pieces of data from the active directory and the API will return
them.

I've spent the last couple months working on this and have a pretty good
set of methods to provide the functions we need.

One things I'm not doing a very good job at is unbinding from the active
directory (LDAP).  As I go back through my code, I'm running into a problem
where my class is essentially hiding the Net::LDAP object, so I'm not sure
how to unbind.

Here's the scenario.   I have a method that binds to the active directory
called "connect()" and returns an Net::LDAP object.  I then have another
method that does the queries I need and returns a Net::LDAP::Search object
called "query()."  query() calls the connect() method so that a user can
simply do this:

use esmith::AD;  #my class

$ad = esmith:AD->new();

@users = $ad->query(#some query parameters);

Problem is, once I return from the query() method, its seems I've lost the
Net::LDAP object, so I can't unbind.

One solution would be to not call the "connect()" method in my "query()"
method, but instead pass it as a parameter so that the calling method never
loses it.  The problem with this is that I would then seem to be repeating
alot of code over and over in each my methods.  Another option would be to
cache the connection in the class as key to the anonymous hash reference
for the class.

I hope this makes sense.  I tried to include enough detail, while not
having to paste in my entire 800 line perl module.

Thanks!

Greg Zartman

--e89a8f3bad45568741050aca400d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I&#39;m working on an API for the Koozali SME Server to us=
e Samba 4, Active Directory. =C2=A0 One of the things I&#39;m trying to do =
is abstract quite alot of the Net::LDAP syntax so that SME Server admins ca=
n just ask the API for various pieces of data from the active directory and=
 the API will return them.
<div><br></div><div>I&#39;ve spent the last couple months working on this a=
nd have a pretty good set of methods to provide the functions we need.</div=
><div><br></div><div>One things I&#39;m not doing a very good job at is unb=
inding from the active directory (LDAP).=C2=A0 As I go back through my code=
, I&#39;m running into a problem where my class is essentially hiding the N=
et::LDAP object, so I&#39;m not sure how to unbind. =C2=A0</div><div><br></=
div><div>Here&#39;s the scenario. =C2=A0 I have a method that binds to the =
active directory called &quot;connect()&quot; and returns an Net::LDAP obje=
ct.=C2=A0 I then have another method that does the queries I need and retur=
ns a Net::LDAP::Search object called &quot;query().&quot; =C2=A0query() cal=
ls the connect() method so that a user can simply do this:<br><br>use esmit=
h::AD; =C2=A0#my class</div><div><br></div><div>$ad =3D esmith:AD-&gt;new()=
;<br><br>@users =3D $ad-&gt;query(#some query parameters); =C2=A0=C2=A0</di=
v><div><br></div><div>Problem is, once I return from the query() method, it=
s seems I&#39;ve lost the Net::LDAP object, so I can&#39;t unbind. =C2=A0</=
div><div><br></div><div>One solution would be to not call the &quot;connect=
()&quot; method in my &quot;query()&quot; method, but instead pass it as a =
parameter so that the calling method never loses it.=C2=A0 The problem with=
 this is that I would then seem to be repeating alot of code over and over =
in each my methods.=C2=A0 Another option would be to cache the connection i=
n the class as key to the anonymous hash reference for the class.=C2=A0</di=
v><div><br></div><div>I hope this makes sense.=C2=A0 I tried to include eno=
ugh detail, while not having to paste in my entire 800 line perl module.</d=
iv><div><br></div><div>Thanks!</div><div><br></div><div>Greg Zartman</div><=
div><br></div></div>

--e89a8f3bad45568741050aca400d--