Friday, 24 July 2015

PostgreSQL+OpenLDAP+CentOS

$ yum install postgresql-* openldap-servers-sql openldap-clients

$ su - postgres

$ initdb -D /var/lib/pgsql/data

$ postmaster -D /var/lib/pgsql/data &

$ exit

$ cat /etc/odbc.ini

[ODBC Data Sources]

PgSQL=PostgreSQL

[PgSQL]

Driver=/usr/lib/psqlodbc.so

Description=Connection to LDAP/Postgresql

Servername=localhost

Port=5432

Protocol=6.4

FetchBufferSiza=99

Username=test

Password=test

Database=pg_ldap

ReadOnly=no

Debug=1

CommLog=1

[ODBC]

InstallDir=/usr/lib/


$ cat /etc/odbcinst.ini

[PostgreSQL]

Description     = ODBC for PostgreSQL

Driver          = /usr/lib/psqlodbc.so

FileUsage       = 1


$ cd /usr/share/doc/openldap-servers-sql-2.3.43/rdbms_depend/pgsql


$ cp * /var/lib/pgsql/data 


$ cat /etc/openldap/slapd.conf

include         /etc/openldap/schema/core.schema

include         /etc/openldap/schema/cosine.schema

include         /etc/openldap/schema/inetorgperson.schema

include         /etc/openldap/schema/misc.schema

include         /etc/openldap/schema/nis.schema

include         /etc/openldap/schema/openldap.schema

include         /etc/openldap/schema/samba.schema

access to *

        by self write

        by * read

access to * by dn="cn=root,dc=example,dc=com" write         

pidfile         /var/run/openldap/slapd.pid

argsfile        /var/run/openldap/slapd.args

modulepath      /usr/lib/openldap

moduleload      back_sql.la                    

database        sql

suffix         "dc=example,dc=com"

rootdn         "cn=root,dc=example,dc=com"

rootpw          secret

dbname          PgSQL

dbuser          test

dbpasswd        test

insentry_query  "insert into ldap_entries (id,dn,oc_map_id,parent,keyval) values ((select max(id)+1 from ldap_entries),?,?,?,?)"

upper_func      "upper"

strcast_func    "text"

concat_pattern  "?||?"

has_ldapinfo_dn_ru      no         

lastmod off


$ su - postgres

$ cd /var/lib/pgsql/data

$ createdb pg_ldap

$ createuser --no-createdb --no-createrole --no-adduser --password test


$ psql -d pg_ldap < backsql_create.sql

$ psql -d pg_ldap < testdb_create.sql

$ psql -d pg_ldap < testdb_metadata.sql

$ psql -d pg_ldap < testdb_data.sql

$psql -d pg_ldap -c "GRANT ALL ON ldap_attr_mappings,ldap_entries,ldap_entry_objclasses,ldap_oc_mappings,referrals,certs TO test1;"

 $psql -d pg_ldap -c "GRANT ALL ON ldap_attr_mappings_id_seq,ldap_entries_id_seq,ldap_oc_mappings_id_seq,referrals_id_seq TO test1;"

$psql -d pg_ldap -c "GRANT ALL ON authors_docs,documents,institutes,persons,phones TO test1;"

$ psql -d pg_ldap -c "GRANT ALL ON documents_id_seq,institutes_id_seq,persons_id_seq,phones_id_seq TO test1;"

$ exit

$ /etc/init.d/ldap start

$ ldapsearch -x -h localhost -b "dc=example,dc=com" "(objectClass=*)"

$ echo ‘dn: cn=Test Entry,dc=example,dc=com

objectClass: inetOrgPerson

cn: Test Entry

sn: Entry

givenName: Test’>1.ldif

$ ldapadd -x -h localhost -D “cn=root,dc=example,dc=com” -w secret -f 1.ldif

No comments:

Post a Comment