Skip to content

PetitVerglas/ldap4pl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ldap4pl

This package provides Prolog bindings for OpenLDAP API.

Most APIs have been implemented and the names are aligned with OpenLDAP API, so for detailed description please check here.

Verified with OpenLDAP 2.4.x.

Installation

Using SWI-Prolog 7 or later.

?- pack_install('https://github.com/EricssonResearch/ldap4pl.git').

Compilation on Mac OS X and GNU Linux has been verified, not on Windows.

Source code available and pull requests accepted here.

@author Hongxin Liang [email protected]

@license Apache License Version 2.0

Examples

To search asynchrously:

:- use_module(library(ldap4pl)).
:- use_module(library(ldap4pl_util)).

search :-
    ldap_initialize(LDAP, 'ldap://example.org'),
    ldap_set_option(LDAP, ldap_opt_protocol_version, 3),
    ldap_simple_bind_s(LDAP, 'cn=...,dc=...,dc=...,dc=...', passwd),
    ldap_search(LDAP,
        query(
            base('dc=...,dc=...,dc=...'),
            scope(ldap_scope_onelevel),
            filter('(objectClass=*)'),
            attrs([objectClass, sambaDomainName]),
            attrsonly(false)
        ),
        MsgID),
    ldap_result(LDAP, MsgID, true, Result),
    ldap_parse_result(LDAP, Result, _, _, _, _, _, false),
    ldap_parse_search_result(LDAP, Result, List),
    print_term(List, []),
    ldap_msgfree(Result),
    ldap_unbind(LDAP).

To do a simple auth:

:- use_module(library(ldap4pl)).
:- use_module(library(ldap4pl_util)).

auth :-
    ldap_simple_auth('ldap://example.org',
        'cn=...,dc=...,dc=...,dc=...',
        passwd).

To add a new entry:

:- use_module(library(ldap4pl)).
:- use_module(library(ldap4pl_util)).

add :-
    ldap_initialize(LDAP, 'ldap://example.org'),
    ldap_set_option(LDAP, ldap_opt_protocol_version, 3),
    ldap_simple_bind_s(LDAP, 'cn=...,dc=...,dc=...,dc=...', passwd),
    DN = 'cn=...,ou=groups,dc=...,dc=...,dc=...',
    ldap_add_s2(LDAP, DN, _{objectClass:[posixGroup, top], cn:test, gidNumber:'20000', description:hello}),
    ldap_unbind(LDAP).

For more examples, please check source code under examples directory.

License

Copyright 2015 Ericsson

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 72.7%
  • Prolog 27.0%
  • Makefile 0.3%