Permalink
Browse files

initial commit with a working version

  • Loading branch information...
guedes committed Jul 31, 2011
0 parents commit 683d0c80fe863c37cdf893bb06676117a5903cc7
Showing with 715 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +24 −0 META.json
  3. +24 −0 Makefile
  4. +96 −0 README.md
  5. +60 −0 doc/ldap_fdw.md
  6. +5 −0 ldap_fdw.control
  7. +24 −0 sql/ldap_fdw.sql
  8. 0 sql/uninstall_ldap_fdw.sql
  9. +470 −0 src/ldap_fdw.c
  10. +2 −0 test/expected/base.out
  11. +8 −0 test/sql/base.sql
@@ -0,0 +1,2 @@
+*.sw?
+tags
@@ -0,0 +1,24 @@
+{
+ "name": "ldap_fdw",
+ "abstract": "LDAP Foreign Data Wrapper",
+ "description": "LDAP Foreign Data Wrapper",
+ "version": "0.0.1",
+ "maintainer": "Dickson S. Guedes <guedes@guedesoft.net>",
+ "license": "postgresql",
+ "provides": {
+ "ldap_fdw": {
+ "abstract": "LDAP FDW",
+ "file": "sql/ldap_fdw.sql",
+ "docfile": "doc/ldap_fdw.md",
+ "version": "0.0.1"
+ }
+ },
+ "release_status": "unstable",
+
+ "generated_by": "Dickson S. Guedes <guedes@guedesoft.net>",
+
+ "meta-spec": {
+ "version": "1.0.0",
+ "url": "http://pgxn.org/meta/spec.txt"
+ }
+}
@@ -0,0 +1,24 @@
+EXTENSION = ldap_fdw
+EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
+
+DATA = $(filter-out $(wildcard sql/*--*.sql),$(wildcard sql/*.sql))
+DOCS = $(wildcard doc/*.md)
+TESTS = $(wildcard test/sql/*.sql)
+REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
+REGRESS_OPTS = --inputdir=test --load-language=plpgsql
+MODULES = $(patsubst %.c,%,$(wildcard src/*.c))
+PG_CONFIG = /srv/postgres/master/bin/pg_config
+PG91 = $(shell $(PG_CONFIG) --version | grep -qE " 8\.| 9\.0" && echo no || echo yes)
+
+ifeq ($(PG91),yes)
+all: sql/$(EXTENSION)--$(EXTVERSION).sql
+
+sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql
+ cp $< $@
+
+DATA = $(wildcard sql/*--*.sql) sql/$(EXTENSION)--$(EXTVERSION).sql
+EXTRA_CLEAN = sql/$(EXTENSION)--$(EXTVERSION).sql
+endif
+
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
@@ -0,0 +1,96 @@
+LDAP Foreign Data Wrapper for PostgreSQL 9.2
+============================================
+
+
+This is a very very very experimental PostgreSQL's extension
+thats implements a Foreign Data Wrapper (FDW) for the LDAP.
+
+I'm using this code to learn FDW internals, and it is a prof of concept.
+
+By all means use it, but do so entirely at your own risk! You have been
+warned!
+
+Do you like to use it in production? You are crazy, please **DO NOT USE IT ON PRODUCTION**. Well, not yet!
+
+Do you like to help to improve it and turn it production-ready? Cool! You are
+welcome! ":)
+
+Building
+--------
+
+To build it, just do this:
+
+ make
+ make installcheck
+ make install
+
+If you encounter an error such as:
+
+ "Makefile", line 8: Need an operator
+
+You need to use GNU make, which may well be installed on your system as
+`gmake`:
+
+ gmake
+ gmake install
+ gmake installcheck
+
+If you encounter an error such as:
+
+ make: pg_config: Command not found
+
+Be sure that you have `pg_config` installed and in your path. If you used a
+package management system such as RPM to install PostgreSQL, be sure that the
+`-devel` package is also installed. If necessary tell the build process where
+to find it:
+
+ env PG_CONFIG=/path/to/pg_config make && make installcheck && make install
+
+And finally, if all that fails (and if you're on PostgreSQL 8.1 or lower, it
+likely will), copy the entire distribution directory to the `contrib/`
+subdirectory of the PostgreSQL source tree and try it there without
+`pg_config`:
+
+ env NO_PGXS=1 make && make installcheck && make install
+
+If you encounter an error such as:
+
+ ERROR: must be owner of database regression
+
+You need to run the test suite using a super user, such as the default
+"postgres" super user:
+
+ make installcheck PGUSER=postgres
+
+Once ldap_fdw is installed, you can add it to a database. If you're running
+PostgreSQL 9.1.0 or greater, it's a simple as connecting to a database as a
+super user and running:
+
+ CREATE EXTENSION ldap_fdw;
+
+If you've upgraded your cluster to PostgreSQL 9.1 and already had ldap_fdw
+installed, you can upgrade it to a properly packaged extension with:
+
+ CREATE EXTENSION ldap_fdw FROM unpackaged;
+
+For versions of PostgreSQL less than 9.1.0, you'll need to run the
+installation script:
+
+ psql -d mydb -f /path/to/pgsql/share/contrib/ldap_fdw.sql
+
+If you want to install ldap_fdw and all of its supporting objects into a specific
+schema, use the `PGOPTIONS` environment variable to specify the schema, like
+so:
+
+ PGOPTIONS=--search_path=extensions psql -d mydb -f ldap_fdw.sql
+
+Dependencies
+------------
+The `ldap_fdw` FDW has the follow dependencies other than PostgreSQL:
+
+* LDAP
+
+Copyright and License
+---------------------
+
+Copyright (c) 2011 Dickson S. Guedes.
@@ -0,0 +1,60 @@
+LDAP Foreign Data Wrapper for PostgreSQL 9.2
+============================================
+
+Synopsis
+--------
+
+A very very very experimental PostgreSQL's extension that implements a Foreign Data Wrapper (FDW) for LDAP.
+
+**DO NOT USE IT ON PRODUCTION**
+
+Description
+-----------
+
+LDAP Foreign Data Wrapper for PostgreSQL 9.2
+
+Usage
+-----
+
+Create the extension:
+
+ CREATE EXTENSION ldap_fdw;
+
+For default ldap_fdw extension installs local server `ldap_local_service` that points to `localhost:389`. But you can create as many as you can with:
+
+ CREATE SERVER ldap_my_server_service
+ FOREIGN DATA WRAPPER ldap_fdw
+ OPTIONS ( address 'my_ldap_server', port '1234');
+
+Then create user mapping:
+
+ CREATE USER MAPPPING FOR current_user
+ SERVER ldap_my_server_service
+ OPTIONS (user_dn 'cn=the_ldap_user,dc=example,dc=com', password 'the_ldap_user_password');
+
+Finally create a foreign table with a base DN for some OU:
+
+ CREATE FOREIGN TABLE ldap_people (
+ uid text,
+ displayname text,
+ mail text
+ )
+ SERVER ldap_my_server_service
+ OPTIONS (base_dn 'OU=people,DC=example,DC=com');
+
+
+Support
+-------
+
+* [github](http://github.net/guedes/ldap_fdw)
+
+Author
+------
+
+[Dickson S. Guedes](http://github.net/guedes)
+
+Copyright and License
+---------------------
+
+Copyright (c) 2011 Dickson S. Guedes.
+
@@ -0,0 +1,5 @@
+# ldap_fdw extension
+comment = 'LDAP Foreign Data Wrapper'
+default_version = '0.0.1'
+module_pathname = '$libdir/ldap_fdw'
+relocatable = true
@@ -0,0 +1,24 @@
+/*
+ * Author: Dickson S. Guedes
+ * Created at: 2011-07-30 13:35:30 -0300
+ *
+ */
+
+-- create wrapper with validator and handler
+CREATE OR REPLACE FUNCTION ldap_fdw_validator (text[], oid)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT;
+
+CREATE OR REPLACE FUNCTION ldap_fdw_handler ()
+RETURNS fdw_handler
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT;
+
+CREATE FOREIGN DATA WRAPPER ldap_fdw
+VALIDATOR ldap_fdw_validator HANDLER ldap_fdw_handler;
+
+CREATE SERVER ldap_local_service
+FOREIGN DATA WRAPPER ldap_fdw
+OPTIONS ( address 'localhost', port '389');
+
No changes.
Oops, something went wrong.

0 comments on commit 683d0c8

Please sign in to comment.