Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 43c7937

Browse files
committed
Allow LDAP lookups from pg_service.conf.
Albe Laurenz
1 parent b517e65 commit 43c7937

File tree

5 files changed

+600
-5
lines changed

5 files changed

+600
-5
lines changed

configure

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17314,6 +17314,91 @@ _ACEOF
1731417314
fi
1731517315

1731617316

17317+
# this will link libpq against libldap_r
17318+
if test "$with_ldap" = yes ; then
17319+
if test "$PORTNAME" != "win32"; then
17320+
17321+
echo "$as_me:$LINENO: checking for ldap_simple_bind in -lldap_r" >&5
17322+
echo $ECHO_N "checking for ldap_simple_bind in -lldap_r... $ECHO_C" >&6
17323+
if test "${ac_cv_lib_ldap_r_ldap_simple_bind+set}" = set; then
17324+
echo $ECHO_N "(cached) $ECHO_C" >&6
17325+
else
17326+
ac_check_lib_save_LIBS=$LIBS
17327+
LIBS="-lldap_r $LIBS"
17328+
cat >conftest.$ac_ext <<_ACEOF
17329+
/* confdefs.h. */
17330+
_ACEOF
17331+
cat confdefs.h >>conftest.$ac_ext
17332+
cat >>conftest.$ac_ext <<_ACEOF
17333+
/* end confdefs.h. */
17334+
17335+
/* Override any gcc2 internal prototype to avoid an error. */
17336+
#ifdef __cplusplus
17337+
extern "C"
17338+
#endif
17339+
/* We use char because int might match the return type of a gcc2
17340+
builtin and then its argument prototype would still apply. */
17341+
char ldap_simple_bind ();
17342+
int
17343+
main ()
17344+
{
17345+
ldap_simple_bind ();
17346+
;
17347+
return 0;
17348+
}
17349+
_ACEOF
17350+
rm -f conftest.$ac_objext conftest$ac_exeext
17351+
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
17352+
(eval $ac_link) 2>conftest.er1
17353+
ac_status=$?
17354+
grep -v '^ *+' conftest.er1 >conftest.err
17355+
rm -f conftest.er1
17356+
cat conftest.err >&5
17357+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
17358+
(exit $ac_status); } &&
17359+
{ ac_try='test -z "$ac_c_werror_flag"
17360+
|| test ! -s conftest.err'
17361+
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
17362+
(eval $ac_try) 2>&5
17363+
ac_status=$?
17364+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
17365+
(exit $ac_status); }; } &&
17366+
{ ac_try='test -s conftest$ac_exeext'
17367+
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
17368+
(eval $ac_try) 2>&5
17369+
ac_status=$?
17370+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
17371+
(exit $ac_status); }; }; then
17372+
ac_cv_lib_ldap_r_ldap_simple_bind=yes
17373+
else
17374+
echo "$as_me: failed program was:" >&5
17375+
sed 's/^/| /' conftest.$ac_ext >&5
17376+
17377+
ac_cv_lib_ldap_r_ldap_simple_bind=no
17378+
fi
17379+
rm -f conftest.err conftest.$ac_objext \
17380+
conftest$ac_exeext conftest.$ac_ext
17381+
LIBS=$ac_check_lib_save_LIBS
17382+
fi
17383+
echo "$as_me:$LINENO: result: $ac_cv_lib_ldap_r_ldap_simple_bind" >&5
17384+
echo "${ECHO_T}$ac_cv_lib_ldap_r_ldap_simple_bind" >&6
17385+
if test $ac_cv_lib_ldap_r_ldap_simple_bind = yes; then
17386+
cat >>confdefs.h <<_ACEOF
17387+
#define HAVE_LIBLDAP_R 1
17388+
_ACEOF
17389+
17390+
LIBS="-lldap_r $LIBS"
17391+
17392+
else
17393+
{ { echo "$as_me:$LINENO: error: library 'ldap_r' is required for LDAP" >&5
17394+
echo "$as_me: error: library 'ldap_r' is required for LDAP" >&2;}
17395+
{ (exit 1); exit 1; }; }
17396+
fi
17397+
17398+
PTHREAD_LIBS="$PTHREAD_LIBS -lldap_r"
17399+
fi
17400+
fi
17401+
1731717402
CFLAGS="$_CFLAGS"
1731817403
LIBS="$_LIBS"
1731917404

configure.in

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.469 2006/07/24 16:32:44 petere Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.470 2006/07/27 13:20:24 momjian Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -1106,6 +1106,14 @@ AC_CHECK_FUNCS([strerror_r getpwuid_r gethostbyname_r])
11061106
PGAC_FUNC_GETPWUID_R_5ARG
11071107
PGAC_FUNC_STRERROR_R_INT
11081108

1109+
# this will link libpq against libldap_r
1110+
if test "$with_ldap" = yes ; then
1111+
if test "$PORTNAME" != "win32"; then
1112+
AC_CHECK_LIB(ldap_r, ldap_simple_bind, [], [AC_MSG_ERROR([library 'ldap_r' is required for LDAP])])
1113+
PTHREAD_LIBS="$PTHREAD_LIBS -lldap_r"
1114+
fi
1115+
fi
1116+
11091117
CFLAGS="$_CFLAGS"
11101118
LIBS="$_LIBS"
11111119

doc/src/sgml/libpq.sgml

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.213 2006/07/04 13:22:15 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.214 2006/07/27 13:20:24 momjian Exp $ -->
22

33
<chapter id="libpq">
44
<title><application>libpq</application> - C Library</title>
@@ -4126,6 +4126,72 @@ installs too. The file's location can also be specified by the
41264126
</sect1>
41274127

41284128

4129+
<sect1 id="libpq-ldap">
4130+
<title>LDAP Lookup of Connection Parameters</title>
4131+
4132+
<indexterm zone="libpq-ldap">
4133+
<primary>LDAP connection parameter lookup</primary>
4134+
</indexterm>
4135+
4136+
<para>
4137+
If <application>libpq</application> has been compiled with LDAP support (option
4138+
<literal><option>--with-ldap</option></literal> for <command>configure</command>)
4139+
it is possible to retrieve connection options like <literal>host</literal>
4140+
or <literal>dbname</literal> via LDAP from a central server.
4141+
The advantage is that if the connection parameters for a database change,
4142+
the connection information doesn't have to be updated on all client machines.
4143+
</para>
4144+
4145+
<para>
4146+
LDAP connection parameter lookup uses the connection service file
4147+
<filename>pg_service.conf</filename> (see <xref linkend="libpq-pgservice">).
4148+
A line in a <filename>pg_service.conf</filename> stanza that starts with
4149+
<literal>ldap://</literal> will be recognized as an LDAP URL and an LDAP
4150+
query will be performed. The result must be a list of <literal>keyword =
4151+
value</literal> pairs which will be used to set connection options.
4152+
The URL must conform to RFC 1959 and be of the form
4153+
<synopsis>
4154+
ldap://[<replaceable>hostname</replaceable>[:<replaceable>port</replaceable>]]/<replaceable>search_base</replaceable>?<replaceable>attribute</replaceable>?<replaceable>search_scope</replaceable>?<replaceable>filter</replaceable>
4155+
</synopsis>
4156+
where <replaceable>hostname</replaceable>
4157+
defaults to <literal>localhost</literal> and
4158+
<replaceable>port</replaceable> defaults to 389.
4159+
</para>
4160+
4161+
<para>
4162+
Processing of <filename>pg_service.conf</filename> is terminated after
4163+
a successful LDAP lookup, but is continued if the LDAP server cannot be
4164+
contacted. This is to provide a fallback with
4165+
further LDAP URL lines that point to different LDAP
4166+
servers, classical <literal>keyword = value</literal> pairs, or
4167+
default connection options.
4168+
If you would rather get an error message in this case, add a
4169+
syntactically incorrect line after the LDAP URL.
4170+
</para>
4171+
4172+
<para>
4173+
A sample LDAP entry that has been created with the LDIF file
4174+
<synopsis>
4175+
version:1
4176+
dn:cn=mydatabase,dc=mycompany,dc=com
4177+
changetype:add
4178+
objectclass:top
4179+
objectclass:groupOfUniqueNames
4180+
cn:mydatabase
4181+
uniqueMember:host=dbserver.mycompany.com
4182+
uniqueMember:port=5439
4183+
uniqueMember:dbname=mydb
4184+
uniqueMember:user=mydb_user
4185+
uniqueMember:sslmode=require
4186+
</synopsis>
4187+
might be queried with the following LDAP URL:
4188+
<synopsis>
4189+
ldap://ldap.mycompany.com/dc=mycompany,dc=com?uniqueMember?one?(cn=mydatabase)
4190+
</synopsis>
4191+
</para>
4192+
</sect1>
4193+
4194+
41294195
<sect1 id="libpq-ssl">
41304196
<title>SSL Support</title>
41314197

src/interfaces/libpq/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.146 2006/07/18 22:18:08 momjian Exp $
8+
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.147 2006/07/27 13:20:24 momjian Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -62,7 +62,7 @@ else
6262
SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl $(PTHREAD_LIBS), $(LIBS))
6363
endif
6464
ifeq ($(PORTNAME), win32)
65-
SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32, $(LIBS))
65+
SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32 -lwldap32, $(LIBS))
6666
endif
6767

6868

0 commit comments

Comments
 (0)