codekingpro/portable-devtools
114k
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>34.18. LDAP Lookup of Connection Parameters</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="libpq-pgservice.html" title="34.17. The Connection Service File" /><link rel="next" href="libpq-ssl.html" title="34.19. SSL Support" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">34.18. LDAP Lookup of Connection Parameters</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="libpq-pgservice.html" title="34.17. The Connection Service File">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="libpq.html" title="Chapter 34. libpq — C Library">Up</a></td><th width="60%" align="center">Chapter 34. <span class="application">libpq</span> — C Library</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="libpq-ssl.html" title="34.19. SSL Support">Next</a></td></tr></table><hr /></div><div class="sect1" id="LIBPQ-LDAP"><div class="titlepage"><div><div><h2 class="title" style="clear: both">34.18. LDAP Lookup of Connection Parameters <a href="#LIBPQ-LDAP" class="id_link">#</a></h2></div></div></div><a id="id-1.7.3.25.2" class="indexterm"></a><p>3 If <span class="application">libpq</span> has been compiled with LDAP support (option4 <code class="literal"><code class="option">--with-ldap</code></code> for <code class="command">configure</code>)5 it is possible to retrieve connection options like <code class="literal">host</code>6 or <code class="literal">dbname</code> via LDAP from a central server.7 The advantage is that if the connection parameters for a database change,8 the connection information doesn't have to be updated on all client machines.9 </p><p>10 LDAP connection parameter lookup uses the connection service file11 <code class="filename">pg_service.conf</code> (see <a class="xref" href="libpq-pgservice.html" title="34.17. The Connection Service File">Section 34.17</a>). A line in a12 <code class="filename">pg_service.conf</code> stanza that starts with13 <code class="literal">ldap://</code> will be recognized as an LDAP URL and an14 LDAP query will be performed. The result must be a list of15 <code class="literal">keyword = value</code> pairs which will be used to set16 connection options. The URL must conform to17 <a class="ulink" href="https://datatracker.ietf.org/doc/html/rfc1959" target="_top">RFC 1959</a>18 and be of the form19</p><pre class="synopsis">20ldap://[<em class="replaceable"><code>hostname</code></em>[:<em class="replaceable"><code>port</code></em>]]/<em class="replaceable"><code>search_base</code></em>?<em class="replaceable"><code>attribute</code></em>?<em class="replaceable"><code>search_scope</code></em>?<em class="replaceable"><code>filter</code></em>21</pre><p>22 where <em class="replaceable"><code>hostname</code></em> defaults to23 <code class="literal">localhost</code> and <em class="replaceable"><code>port</code></em>24 defaults to 389.25 </p><p>26 Processing of <code class="filename">pg_service.conf</code> is terminated after27 a successful LDAP lookup, but is continued if the LDAP server cannot28 be contacted. This is to provide a fallback with further LDAP URL29 lines that point to different LDAP servers, classical <code class="literal">keyword30 = value</code> pairs, or default connection options. If you would31 rather get an error message in this case, add a syntactically incorrect32 line after the LDAP URL.33 </p><p>34 A sample LDAP entry that has been created with the LDIF file35</p><pre class="programlisting">36version:137dn:cn=mydatabase,dc=mycompany,dc=com38changetype:add39objectclass:top40objectclass:device41cn:mydatabase42description:host=dbserver.mycompany.com43description:port=543944description:dbname=mydb45description:user=mydb_user46description:sslmode=require47</pre><p>48 might be queried with the following LDAP URL:49</p><pre class="programlisting">50ldap://ldap.mycompany.com/dc=mycompany,dc=com?description?one?(cn=mydatabase)51</pre><p>52 </p><p>53 You can also mix regular service file entries with LDAP lookups.54 A complete example for a stanza in <code class="filename">pg_service.conf</code>55 would be:56</p><pre class="programlisting">57# only host and port are stored in LDAP, specify dbname and user explicitly58[customerdb]59dbname=customer60user=appuser61ldap://ldap.acme.com/cn=dbserver,cn=hosts?pgconnectinfo?base?(objectclass=*)62</pre><p>63 </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="libpq-pgservice.html" title="34.17. The Connection Service File">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="libpq.html" title="Chapter 34. libpq — C Library">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="libpq-ssl.html" title="34.19. SSL Support">Next</a></td></tr><tr><td width="40%" align="left" valign="top">34.17. The Connection Service File </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 34.19. SSL Support</td></tr></table></div></body></html>