home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _de5506e5abaaf09318db66f26170fa56 < prev    next >
Text File  |  2000-03-23  |  28KB  |  582 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Mozilla::LDAP::Conn - Object Oriented API for the LDAP SDK.</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> Mozilla::LDAP::Conn - Object Oriented API for the LDAP SDK.</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#abstract">ABSTRACT</A></LI>
  25.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  26.     <LI><A HREF="#some perldap/oo basics">SOME PERLDAP/OO BASICS</A></LI>
  27.     <LI><A HREF="#creating a new object instance">CREATING A NEW OBJECT INSTANCE</A></LI>
  28.     <LI><A HREF="#performing ldap searches">PERFORMING LDAP SEARCHES</A></LI>
  29.     <LI><A HREF="#modifying and creating new ldap entries">MODIFYING AND CREATING NEW LDAP ENTRIES</A></LI>
  30.     <UL>
  31.  
  32.         <LI><A HREF="#searching and updating entries">Searching and updating entries</A></LI>
  33.         <LI><A HREF="#other methods">Other methods</A></LI>
  34.     </UL>
  35.  
  36.     <LI><A HREF="#examples">EXAMPLES</A></LI>
  37.     <LI><A HREF="#installation">INSTALLATION</A></LI>
  38.     <LI><A HREF="#availability">AVAILABILITY</A></LI>
  39.     <LI><A HREF="#credits">CREDITS</A></LI>
  40.     <LI><A HREF="#bugs">BUGS</A></LI>
  41.     <LI><A HREF="#see also">SEE ALSO</A></LI>
  42. </UL>
  43. <!-- INDEX END -->
  44.  
  45. <HR>
  46. <P>
  47. <H1><A NAME="name">NAME</A></H1>
  48. <PRE>
  49.   Mozilla::LDAP::Conn - Object Oriented API for the LDAP SDK.</PRE>
  50. <P>
  51. <HR>
  52. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  53. <UL>
  54. <LI>Windows</LI>
  55. </UL>
  56. <HR>
  57. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  58. <PRE>
  59.   use Mozilla::LDAP::Conn;
  60.   use Mozilla::LDAP::Utils;</PRE>
  61. <P>
  62. <HR>
  63. <H1><A NAME="abstract">ABSTRACT</A></H1>
  64. <P>This package is the main API for using our Perl Object Oriented LDAP
  65. module. Even though it's certainly possible, and sometimes even necessary,
  66. to call the native LDAP C SDK functions, we strongly recommend you use
  67. these object classes.</P>
  68. <P>It's not required to use our Mozilla::LDAP::Utils.pm package, but it's
  69. convenient and good for portability if you use as much as you can from
  70. that package as well. This implies using the LdapConf package as well,
  71. even though you usually don't need to use it directly.</P>
  72. <P>You should read this document in combination with the Mozilla::LDAP::Entry
  73. document. Both modules depend on each other heavily.</P>
  74. <P>
  75. <HR>
  76. <H1><A NAME="description">DESCRIPTION</A></H1>
  77. <P>First, this is not ment to be a crash course in how LDAP works, if you
  78. have no experience with LDAP, I suggest you read some of the literature
  79. that's available out there. The LDAP Deployment Book from Netscape, or the
  80. LDAP C SDK documentation are good starting points.</P>
  81. <P>This object class basically tracks and manages the LDAP connection, it's
  82. current status, and the current search operation (if any). Every time you
  83. call the <STRONG>search</STRONG> method of an object instance, you'll reset it's
  84. internal state. It depends heavily on the ::Entry class, which are used to
  85. retrieve, modify and update a single entry.</P>
  86. <P>The <STRONG>search</STRONG> and <STRONG>nextEntry</STRONG> methods returns Mozilla::LDAP::Entry
  87. objects, naturally. You also have to instantiate (and modify) a new
  88. ::Entry object when you want to add new entries to an LDAP
  89. server. Alternatively, the <A HREF="#item_add"><CODE>add()</CODE></A> method will also take a hash array as
  90. argument, to make it easy to create new LDAP entries.</P>
  91. <P>To assure that changes to an entry are updated properly, we strongly
  92. recommend you use the native methods of the ::Entry object class. Even
  93. though you can modify certain elements directly, it could cause changes
  94. not to be committed to the LDAP server. If there's something missing from
  95. the API, please let us know, or even fix it yourself.</P>
  96. <P>
  97. <HR>
  98. <H1><A NAME="some perldap/oo basics">SOME PERLDAP/OO BASICS</A></H1>
  99. <P>An entry consist of a DN, and a hash array of pointers to attribute
  100. values. Each attribute value (except the DN) is an array, but you have to
  101. remember the hash array in the entry stores pointers to the array, not the
  102. array. So, to access the first CN value of an entry, you'd do</P>
  103. <PRE>
  104.     $cn = $entry->{cn}[0];</PRE>
  105. <P>To set the CN attribute to a completely new array of values, you'd do</P>
  106. <PRE>
  107.     $entry->{cn} = [ "Leif Hedstrom", "The Swede" ];</PRE>
  108. <P>As long as you remember this, and try to use native Mozilla::LDAP::Entry
  109. methods, this package will take care of most the work. Once you master
  110. this, working with LDAP in Perl is surprisingly easy.</P>
  111. <P>We already mentioned DN, which stands for Distinguished Name. Every entry
  112. on an LDAP server must have a DN, and it's always guaranteed to be unique
  113. within your database. Some typical DNs are</P>
  114. <PRE>
  115.     uid=leif,ou=people,o=netscape.com
  116.     cn=gene-staff,ou=mailGroup,o=netscape.com
  117.     dc=data,dc=netscape,dc=com</PRE>
  118. <P>There's also a term called RDN, which stands for Relative Distinguished
  119. Name. In the above examples, <CODE>uid=leif</CODE>, <CODE>cn=gene-staff</CODE> and <CODE>dc=data</CODE>
  120. are all RDNs. One particular property for a RDN is that they must be
  121. unique within it's sub-tree. Hence, there can only be one user with
  122. <CODE>uid=leif</CODE> within the <CODE>ou=people</CODE> tree, there can never be a name
  123. conflict.</P>
  124. <P>
  125. <HR>
  126. <H1><A NAME="creating a new object instance">CREATING A NEW OBJECT INSTANCE</A></H1>
  127. <P>Before you can do anything with PerLDAP, you'll need to instantiate at
  128. least one Mozilla::LDAP::Conn object, and connect it to an LDAP server. As
  129. you probably guessed already, this is done with the <STRONG>new</STRONG> method:</P>
  130. <PRE>
  131.     $conn = new Mozilla::LDAP::Conn("ldap", "389", $bind, $pswd, $cert);
  132.     die "Couldn't connect to LDAP server ldap" unless  $conn;</PRE>
  133. <P>The arguments are: Host name, port number, and optionally a bind-DN, it's
  134. password, and a certificate. If there is no bind-DN, the connection will
  135. be bound as the anonymous user. If the certificate file is specified, the
  136. connection will be over SSL, and you should then probably connect to port
  137. 636. You have to check that the object was created properly, and take
  138. proper actions if you couldn't get a connection.</P>
  139. <P>There's one convenient alternative call method to this function. Instead of
  140. providing each individual argument, you can provide one hash array
  141. (actually, a pointer to a hash). For example:</P>
  142. <PRE>
  143.     %ld = Mozilla::LDAP::Utils::ldapArgs();
  144.     $conn = new Mozilla::LDAP::Conn(\%ld);</PRE>
  145. <P>The components of the hash are:</P>
  146. <PRE>
  147.     $ld->{"host"}
  148.     $ld->{"port"}
  149.     $ld->{"base"}
  150.     $ld->{"bind"}
  151.     $ld->{"pswd"}
  152.     $ld->{"cert"}</PRE>
  153. <P>and (not used in the <STRONG>new</STRONG> method)</P>
  154. <PRE>
  155.     $ld->{"scope"}</PRE>
  156. <P>Once a connection is established, the package will take care of the
  157. rest. If for some reason the connection is lost, the object should
  158. reconnect on it's own, automatically. [Note: This doesn't work
  159. now... ]. You can use the Mozilla::LDAP:Conn object for any number of
  160. operations, but since everything is currently done synchronously, you can
  161. only have one operation active at any single time. You can of course have
  162. multiple Mozilla::LDAP::Conn instanced active at the same time.</P>
  163. <P>
  164. <HR>
  165. <H1><A NAME="performing ldap searches">PERFORMING LDAP SEARCHES</A></H1>
  166. <P>We assume that you are familiar with the LDAP filter syntax already, all
  167. searches performed by this object class uses these filters. You should
  168. also be familiar with LDAP URLs, and LDAP object classes. There are some
  169. of the few things you actually must know about LDAP. Perhaps the simples
  170. filter is</P>
  171. <PRE>
  172.     (uid=leif)</PRE>
  173. <P>This matches all entries with the UID set to ``leif''. Normally that
  174. would only match one entry, but there is no guarantee for that. To find
  175. everyone with the name ``leif'', you'd instead do</P>
  176. <PRE>
  177.     (cn=*leif*)</PRE>
  178. <P>A more complicated search involves logic operators. To find all mail
  179. groups owned by ``leif'' (or actually his DN), you could do</P>
  180. <PRE>
  181.     (&(objectclass=mailGroup)(owner=uid=leif,ou=people,o=netscape))</PRE>
  182. <P>The <EM>owner</EM> attribute is what's called a DN attribute, so to match on it
  183. we have to specify the entire DN in the filter above. We could of course
  184. also do a sub string ``wild card'' match, but it's less efficient, and
  185. requires indexes to perform reasonably well.</P>
  186. <P>Ok, now we are prepared to actually do a real search on the LDAP server:</P>
  187. <PRE>
  188.     $base = "o=netscape.com";
  189.     $conn = new Mozilla::LDAP::Conn("ldap", "389", "", ""); die "No LDAP
  190.     connection" unless $conn;</PRE>
  191. <PRE>
  192.     $entry = $conn->search($base, "subtree", "(uid=leif)");
  193.     if (! $entry)
  194.       { # handle this event, no entries found, dude!
  195.       }
  196.     else
  197.       {
  198.         while ($entry)
  199.           {
  200.             $entry->printLDIF();
  201.             $entry = $conn->nextEntry();
  202.           }
  203.       }</PRE>
  204. <P>This is in fact a poor mans implementation of the <EM>ldapsearch</EM> command
  205. line utility. The <STRONG>search</STRONG> method returns an Mozilla::LDAP::Entry object,
  206. which holds the first entry from the search, if any. To get the second and
  207. subsequent entries you call the <STRONG>entry</STRONG> method, until there are no more
  208. entries. The <STRONG>printLDIF</STRONG> method is a convenient function, requesting the
  209. entry to print itself on STDOUT, in LDIF format.</P>
  210. <P>The arguments to the <STRONG>search</STRONG> methods are the <EM>LDAP Base-DN</EM>, the
  211. <EM>scope</EM> of the search (``base'', ``one'' or ``sub''), and the actual LDAP
  212. <EM>filter</EM>. The entry return contains the DN, and all attribute values. To
  213. access a specific attribute value, you just have to use the hash array:</P>
  214. <PRE>
  215.     $cn = $entry->{cn}[0];</PRE>
  216. <P>Since many LDAP attributes can have more than one value, value of the hash
  217. array is another array (or actually a pointer to an array). In many cases
  218. you can just assume the value is in the first slot (indexed by [0]), but
  219. for some attributes you have to support multiple values. To find out how
  220. many values a specific attribute has, you'd call the <STRONG>size</STRONG> method:</P>
  221. <PRE>
  222.     $numVals = $entry->size("objectclass");</PRE>
  223. <P>One caveat: Many LDAP attributes are case insensitive, but the methods in
  224. the Mozilla::LDAP::Entry package are not aware of this. Hence, if you
  225. compare values with case sensitivity, you can experience weird
  226. behavior. If you know an attribute is CIS (Case Insensitive), make sure
  227. you do case insensitive string comparisons.</P>
  228. <P>Unfortunately some methods in this package can't do this, and by default
  229. will do case sensitive comparisons. We are working on this, and in a
  230. future release some of the methods will handle this more gracefully. As an
  231. extension (for LDAP v3.0) we could also use schema discovery for handling
  232. this even better.</P>
  233. <P>There is an alternative search method, to use LDAP URLs instead of a
  234. filter string. This can be used to easily parse and process URLs, which is
  235. a compact way of storing a ``link'' to some specific LDAP information. To
  236. process such a search, you use the <STRONG>searchURL</STRONG> method:</P>
  237. <PRE>
  238.     $entry->searchURL("ldap:///o=netscape.com??sub?(uid=leif");</PRE>
  239. <P>As it turns out, the <STRONG>search</STRONG> method also supports LDAP URL searches. If
  240. the search filter looks like a proper URL, we will actually do an URL
  241. search instead. This is for backward compatibility, and for ease of use.</P>
  242. <P>To achieve better performance and use less memory, you can limit your
  243. search to only retrieve certain attributes. With the LDAP URLs you specify
  244. this as an optional parameter, and with the <STRONG>search</STRONG> method you add two
  245. more options, like</P>
  246. <PRE>
  247.     $entry = $conn->search($base, "sub", $filter, 0, ("mail", "cn");</PRE>
  248. <P>The last argument specifies an array of attributes to retrieve, the fewer
  249. the attributes, the faster the search will be. The second to last argument
  250. is a boolean value indicating if we should retrieve only the attribute
  251. names (and no values). In most cases you want this to be FALSE, to
  252. retrieve both the attribute names, and all their values. To do this with
  253. the <STRONG>searchURL</STRONG> method, add a second argument, which should be 0 or 1.</P>
  254. <P>
  255. <HR>
  256. <H1><A NAME="modifying and creating new ldap entries">MODIFYING AND CREATING NEW LDAP ENTRIES</A></H1>
  257. <P>Once you have an LDAP entry, either from a search, or created directly to
  258. get a new empty object, you are ready to modify it. If you are creating a
  259. new entry, the first thing to set it it's DN, like</P>
  260. <PRE>
  261.     $entry = $conn->newEntry();
  262.     $entry->setDN("uid=leif,ou=people,o=netscape.com");</PRE>
  263. <P>alternatively you can still use the <STRONG>new</STRONG> method on the Entry class, like</P>
  264. <PRE>
  265.     $entry = new Mozilla::LDAP::Entry;</PRE>
  266. <P>You should not do this for an existing LDAP entry, changing the RDN (or
  267. DN) for such an entry must be done with <STRONG>modifyRDN</STRONG>. To populate (or
  268. modify) some other attributes, we can do</P>
  269. <PRE>
  270.     $entry->{objectclass} = [ "top", "person", "inetOrgPerson" ];
  271.     $entry->{cn} = [ "Leif Hedstrom" ];
  272.     $entry->{mail} = [ "leif@netscape.com" ];</PRE>
  273. <P>Once you are done modifying your LDAP entry, call the <STRONG>update</STRONG> method
  274. from the Mozilla::LDAP::Conn object instance:</P>
  275. <PRE>
  276.     $conn->update($entry);</PRE>
  277. <P>Or, if you are creating an entirely new LDAP entry, you must call the
  278. <STRONG>add</STRONG> method:</P>
  279. <PRE>
  280.     $conn->add($entry);</PRE>
  281. <P>If all comes to worse, and you have to remove an entry again from the LDAP
  282. server, just call the <STRONG>delete</STRONG> method, like</P>
  283. <PRE>
  284.     $conn->delete($entry->getDN());</PRE>
  285. <P>You can't use native Perl functions like <A HREF="../../../../lib/Pod/perlfunc.html#item_push"><CODE>push()</CODE></A> and <A HREF="../../../../lib/Pod/perlfunc.html#item_splice"><CODE>splice()</CODE></A> on attribute
  286. values, since they won't update the ::Entry instance state properly.
  287. Instead use one of the methods provided by the Mozilla::LDAP::Entry
  288. object class, for instance</P>
  289. <PRE>
  290.     $entry->addValue("cn", "The Swede");
  291.     $entry->removeValue("mailAlternateAddress", "leif@mcom.com");
  292.     $entry->remove("seeAlso");</PRE>
  293. <P>These methods return a TRUE or FALSE value, depending on the outcome
  294. of the operation. If there was no value to remove, or a value already
  295. exists, we return FALSE, otherwise TRUE. To check if an attribute has a
  296. certain value, use the <STRONG>hasValue</STRONG> method, like</P>
  297. <PRE>
  298.     if ($entry->hasValue("mail", "leif@netscape.com")) {
  299.         # Do something
  300.     }</PRE>
  301. <P>There is a similar method, <STRONG>matchValue</STRONG>, which takes a regular
  302. expression to match against, instead of the entire string. For more
  303. information this and other methods in the Entry class, see below.
  304. </P>
  305. <PRE>
  306.  
  307. =head1 OBJECT CLASS METHODS</PRE>
  308. <P>We have already described the fundamentals of this class earlier. This is
  309. a summary of all available methods which you can use. Be careful not to
  310. use any undocumented features or heaviour, since the internals in this
  311. module is likely to change.</P>
  312. <P>
  313. <H2><A NAME="searching and updating entries">Searching and updating entries</A></H2>
  314. <DL>
  315. <DT><STRONG><A NAME="item_add"><STRONG>add</STRONG></A></STRONG><BR>
  316. <DD>
  317. Add a new entry to the LDAP server. Make sure you use the <STRONG>new</STRONG> method
  318. for the Mozilla::LDAP::Entry object, to create a proper entry.
  319. <P></P>
  320. <DT><STRONG><A NAME="item_browse"><STRONG>browse</STRONG></A></STRONG><BR>
  321. <DD>
  322. Searches for an LDAP entry, but sets some default values to begin with,
  323. such as scope=BASE, filter=(objectclass=*) and so on.  Much like <STRONG>search</STRONG>
  324. except for these defaults.  Requires a DN value
  325. as an argument. An optional second argument is an array of which
  326. attributes to return from the entry.  Note that this does not support the
  327. ``attributesOnly'' flag.
  328. <PRE>
  329.     $secondEntry = $conn->browse($entry->getDN());</PRE>
  330. <P></P>
  331. <DT><STRONG><A NAME="item_close"><STRONG>close</STRONG></A></STRONG><BR>
  332. <DD>
  333. Close the LDAP connection, and clean up the object. If you don't call this
  334. directly, the destructor for the object instance will do the job for you.
  335. <P></P>
  336. <DT><STRONG><A NAME="item_compare"><STRONG>compare</STRONG></A></STRONG><BR>
  337. <DD>
  338. Compares an attribute and value to a given DN without first doing a
  339. search.  Requires three arguments: a DN, the attribute name, and the value
  340. of the attribute. Returns TRUE if the attribute/value compared ok.
  341. <PRE>
  342.     print "not" unless $conn->compare($entry->getDN(), "cn", "Big Swede");
  343.     print "ok";</PRE>
  344. <P></P>
  345. <DT><STRONG><A NAME="item_delete"><STRONG>delete</STRONG></A></STRONG><BR>
  346. <DD>
  347. This will delete the current entry, or possibly an entry as specified with
  348. the optional argument. You can use this function to delete any entry you
  349. like, by passing it an explicit DN. If you don't pass it this argument,
  350. <STRONG>delete</STRONG> defaults to delete the current entry, from the last call to
  351. <STRONG>search</STRONG> or <STRONG>entry</STRONG>. I'd recommend doing a delete with the explicit DN,
  352. like
  353. <PRE>
  354.     $conn->delete($entry->getDN());</PRE>
  355. <P></P>
  356. <DT><STRONG><A NAME="item_modifyRDN"><STRONG>modifyRDN</STRONG></A></STRONG><BR>
  357. <DD>
  358. This will rename the specified LDAP entry, by modifying it's RDN. For
  359. example, assuming you have a DN of
  360. <PRE>
  361.     uid=leif, ou=people, dc=netscape, dc=com</PRE>
  362. <P>and you wish to rename to</P>
  363. <PRE>
  364.     uid=fiel, ou=people, dc=netscape, dc=com</PRE>
  365. <P>you'd do something like</P>
  366. <PRE>
  367.     $rdn = "uid=fiel";
  368.     $conn->modifyRDN($rdn, $entry->getDN());</PRE>
  369. <P>Note that this can only be done on the RDN, you could not change say
  370. <CODE>ou=people</CODE> to be <CODE>ou=hackers</CODE> in the example above. To do that, you have
  371. to add a new entry (a copy of the old one), and then remove the old
  372. entry.</P>
  373. <P>The last argument is a boolean (0 or 1), which indicates if the old RDN
  374. value should be removed from the entry. The default is TRUE (``1'').</P>
  375. <P></P>
  376. <DT><STRONG><A NAME="item_new"><STRONG>new</STRONG></A></STRONG><BR>
  377. <DD>
  378. This creates and initialized a new LDAP connection and object. The
  379. required arguments are host name, port number, bind DN and the bind
  380. password. An optional argument is a certificate (public key), which causes
  381. the LDAP connection to be established over an SSL channel. Currently we do
  382. not support Client Authentication, so you still have to use the simple
  383. authentication method (i.e. with a password).
  384. <P>A typical usage could be something like</P>
  385. <PRE>
  386.     %ld = Mozilla::LDAP::Utils::ldapArgs();
  387.     $conn = new Mozilla::LDAP::Conn(\%ld);</PRE>
  388. <P>Also, remember that if you use SSL, the port is (usually) 636.</P>
  389. <P></P>
  390. <DT><STRONG><A NAME="item_newEntry"><STRONG>newEntry</STRONG></A></STRONG><BR>
  391. <DD>
  392. This will create an empty Mozilla::LDAP::Entry object, which is properly
  393. tied into the appropriate objectclass. Use this method instead of manually
  394. creating new Entry objects, or at least make sure that you use the ``tie''
  395. function when creating the entry. This function takes no arguments, and
  396. returns a pointer to an ::Entry object. For instance
  397. <PRE>
  398.     $entry = $conn->newEntry();</PRE>
  399. <P>or</P>
  400. <PRE>
  401.     $entry = Mozilla::LDAP::Conn->newEntry();</PRE>
  402. <P></P>
  403. <DT><STRONG><A NAME="item_nextEntry"><STRONG>nextEntry</STRONG></A></STRONG><BR>
  404. <DD>
  405. This method will return the next entry from the search result, and can
  406. therefore only be called after a succesful search has been initiated. If
  407. there are no more entries to retrieve, it returns nothing (empty string).
  408. <P></P>
  409. <DT><STRONG><A NAME="item_search"><STRONG>search</STRONG></A></STRONG><BR>
  410. <DD>
  411. The <STRONG>search</STRONG> method is the main entry point into this module. It requires
  412. at least three arguments: The Base DN, the scope, and the search
  413. strings. Two more optional arguments can be given, the first specifies if
  414. only attribute names should be returned (TRUE or FALSE). The second
  415. argument is a list (array) of attributes to return.
  416. <P>The last option is very important for performance. If you are only
  417. interested in say the ``mail'' and ``mailHost'' attributes, specifying this in
  418. the search will signficantly reduce the search time. An example of an
  419. efficient search is</P>
  420. <PRE>
  421.     @attr = ("cn", "uid", "mail");
  422.     $filter = "(uid=*)";
  423.     $entry = $conn->search($base, $scope, $filter, 0, @attr);
  424.     while ($entry) {
  425.         # do something
  426.         $entry = $conn->nextEntry();
  427.     }</PRE>
  428. <P></P>
  429. <DT><STRONG><A NAME="item_searchURL"><STRONG>searchURL</STRONG></A></STRONG><BR>
  430. <DD>
  431. This is almost identical to <STRONG>search</STRONG>, except this function takes only two
  432. arguments, an LDAP URL and an optional flag to specify if we only want the
  433. attribute names to be returned (and no values). This function isn't very
  434. useful, since the <STRONG>search</STRONG> method will actually honor properly formed
  435. LDAP URL's, and use it if appropriate.
  436. <P></P>
  437. <DT><STRONG><A NAME="item_simpleAuth"><STRONG>simpleAuth</STRONG></A></STRONG><BR>
  438. <DD>
  439. This method will rebind the LDAP connection using new credentials (i.e. a
  440. new user-DN and password). To rebind ``anonymously'', just don't pass a DN
  441. and password, and it will default to binding as the unprivleged user. For
  442. example:
  443. <PRE>
  444.     $user = "leif";
  445.     $password = "secret";
  446.     $conn = new Mozilla::LDAP::Conn($host, $port);      # Anonymous bind
  447.     die "Could't connect to LDAP server $host" unless $conn;</PRE>
  448. <PRE>
  449.     $entry = $conn->search($base, $scope, "(uid=$user)", 0, (uid));
  450.     exit (-1) unless $entry;</PRE>
  451. <PRE>
  452.     $ret = $conn->simpleAuth($entry->getDN(), $password);
  453.     exit (-1) unless $ret;</PRE>
  454. <PRE>
  455.     $ret = $conn->simpleAuth();         # Bind as anon again.</PRE>
  456. <P></P>
  457. <DT><STRONG><A NAME="item_update"><STRONG>update</STRONG></A></STRONG><BR>
  458. <DD>
  459. After modifying an Ldap::Entry entry (see below), use the <STRONG>update</STRONG>
  460. method to commit changes to the LDAP server. Only attributes that has been
  461. changed will be updated, assuming you have used the appropriate methods in
  462. the Entry object. For instance, do not use <STRONG>push</STRONG> or <STRONG>splice</STRONG> to
  463. modify an entry, the <STRONG>update</STRONG> will not recognize such changes.
  464. <P>To change the CN value for an entry, you could do</P>
  465. <PRE>
  466.     $entry->{cn} = ["Leif Hedstrom"];
  467.     $conn->update($entry);</PRE>
  468. <P></P></DL>
  469. <P>
  470. <H2><A NAME="other methods">Other methods</A></H2>
  471. <DL>
  472. <DT><STRONG><A NAME="item_getErrorCode"><STRONG>getErrorCode</STRONG></A></STRONG><BR>
  473. <DD>
  474. Return the error code (numeric) from the last LDAP API function
  475. call. Remember that this can only be called <EM>after</EM> the successful
  476. creation of a new :Conn object instance. A typical usage could be
  477. <PRE>
  478.     if (! $opt_n) {
  479.         $conn->modifyRDN($rdn, $entry->getDN());
  480.         $conn->printError() if $conn->getErrorCode();
  481.     }</PRE>
  482. <P>Which will report any error message as generated by the call to
  483. <STRONG>modifyRDN</STRONG>. Some LDAP functions return extra error information, which
  484. can be retrieved like:</P>
  485. <PRE>
  486.    $err = getErrorCode(\$matched, \$string);</PRE>
  487. <P>$matched will then contain the portion of the matched DN (if applicable to
  488. the error code), and $string will contain any additional error string
  489. returned by the LDAP server.</P>
  490. <P></P>
  491. <DT><STRONG><A NAME="item_getErrorString"><STRONG>getErrorString</STRONG></A></STRONG><BR>
  492. <DD>
  493. Very much like <STRONG>getErrorCode</STRONG>, but return a string with a human readable
  494. error message. This can then be used to print a good error message on the
  495. console.
  496. <P></P>
  497. <DT><STRONG><A NAME="item_getLD"><STRONG>getLD</STRONG></A></STRONG><BR>
  498. <DD>
  499. Return the (internal) LDAP* connection handle, which you can use
  500. (carefully) to call the native LDAP API functions. You shouldn't have to
  501. use this in most cases, unless of course our OO layer is seriously flawed.
  502. <P></P>
  503. <DT><STRONG><A NAME="item_getRes"><STRONG>getRes</STRONG></A></STRONG><BR>
  504. <DD>
  505. Just like <STRONG>getLD</STRONG>, except it returns the internal LDAP return message
  506. structure. Again, use this very carefully, and be aware that this might
  507. break in future releases of PerLDAP. These two methods can be used to call
  508. some useful API functions, like
  509. <PRE>
  510.     $cld = $conn->getLD();
  511.     $res = $conn->getRes();
  512.     $count = Mozilla::LDAP::API::ldap_count_entries($cld, $res);</PRE>
  513. <P></P>
  514. <DT><STRONG><A NAME="item_isURL"><STRONG>isURL</STRONG></A></STRONG><BR>
  515. <DD>
  516. Returns TRUE or FALSE if the given argument is a properly formed URL.
  517. <P></P>
  518. <DT><STRONG><A NAME="item_printError"><STRONG>printError</STRONG></A></STRONG><BR>
  519. <DD>
  520. Print the last error message on standard output.
  521. <P></P>
  522. <DT><STRONG><A NAME="item_setRebindProc"><STRONG>setRebindProc</STRONG></A></STRONG><BR>
  523. <DD>
  524. Tell the LDAP SDK to call the provided Perl function when it has to follow
  525. referrals. The Perl function should return an array of three elements, the
  526. new Bind DN, password and authentication method. A typical usage is
  527. <PRE>
  528.     sub rebindProc {
  529.         return ("uid=ldapadmin", "secret", LDAP_AUTH_SIMPLE);
  530.     }</PRE>
  531. <PRE>
  532.     $ld->setRebindProc(\&rebindProc);</PRE>
  533. <P></P>
  534. <DT><STRONG><A NAME="item_setDefaultRebindProc"><STRONG>setDefaultRebindProc</STRONG></A></STRONG><BR>
  535. <DD>
  536. This is very much like the previous function, except instead of specifying
  537. the function to use, you give it the DN, password and Auth method. Then
  538. we'll use a default rebind procedure (internal in C) to handle the rebind
  539. credentials. This was a solution for the Windows/NT problem/bugs we have
  540. with rebind procedures written in Perl.
  541. <P></P></DL>
  542. <P>
  543. <HR>
  544. <H1><A NAME="examples">EXAMPLES</A></H1>
  545. <P>There are plenty of examples to look at, in the examples directory. We are
  546. adding more examples every day (almost).</P>
  547. <P>
  548. <HR>
  549. <H1><A NAME="installation">INSTALLATION</A></H1>
  550. <P>Installing this package is part of the Makefile supplied in the
  551. package. See the installation procedures which are part of this package.</P>
  552. <P>
  553. <HR>
  554. <H1><A NAME="availability">AVAILABILITY</A></H1>
  555. <P>This package can be retrieved from a number of places, including:</P>
  556. <PRE>
  557.     <A HREF="http://www.mozilla.org/directory/">http://www.mozilla.org/directory/</A>
  558.     Your local CPAN server</PRE>
  559. <P>
  560. <HR>
  561. <H1><A NAME="credits">CREDITS</A></H1>
  562. <P>Most of this code was developed by Leif Hedstrom, Netscape Communications
  563. Corporation.</P>
  564. <P>
  565. <HR>
  566. <H1><A NAME="bugs">BUGS</A></H1>
  567. <P>None. :)</P>
  568. <P>
  569. <HR>
  570. <H1><A NAME="see also">SEE ALSO</A></H1>
  571. <P><A HREF="../../../../site/lib/Mozilla/LDAP/Entry.html">the Mozilla::LDAP::Entry manpage</A>, <A HREF="../../../../LDAP/Mozilla:Utils.html">the LDAP::Mozilla:Utils manpage</A> <A HREF="../../../../LDAP/Mozilla:API.html">the LDAP::Mozilla:API manpage</A> and
  572. of course <EM>Perl</EM>.</P>
  573. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  574. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  575. <STRONG><P CLASS=block> Mozilla::LDAP::Conn - Object Oriented API for the LDAP SDK.</P></STRONG>
  576. </TD></TR>
  577. </TABLE>
  578.  
  579. </BODY>
  580.  
  581. </HTML>
  582.