diff options
author | Guido Günther <agx@sigxcpu.org> | 2016-08-21 17:34:00 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2016-11-07 19:49:55 +0100 |
commit | 3b5f2a40a4d57934825896ba31a1d929ebf02603 (patch) | |
tree | d075f730ee69d82f3fa2a0f9c914ff2753330554 /priv |
Initial commit
Diffstat (limited to 'priv')
-rw-r--r-- | priv/ldapsp.conf | 7 | ||||
-rw-r--r-- | priv/ldapsp.service | 14 | ||||
-rw-r--r-- | priv/policy.erl | 39 |
3 files changed, 60 insertions, 0 deletions
diff --git a/priv/ldapsp.conf b/priv/ldapsp.conf new file mode 100644 index 0000000..0f67bfd --- /dev/null +++ b/priv/ldapsp.conf @@ -0,0 +1,7 @@ +%% coding: utf-8 +%% -*- mode: erlang -*- +{connection, + [{server, "192.168.122.172"}, + {user, "cn=admin,dc=example,dc=com"}, + {password, "r00tme"}]}. + diff --git a/priv/ldapsp.service b/priv/ldapsp.service new file mode 100644 index 0000000..241d1bd --- /dev/null +++ b/priv/ldapsp.service @@ -0,0 +1,14 @@ +[Unit] +Description=Foreman LDAP SmartProxy +After=syslog.target network.target + +[Service] +Type=simple +User=ldapsp +ExecStart=/opt/ldapsp/bin/ldapsp foreground +ExecStop=/opt/ldapsp/bin/ldapsp stop +Environment=CODE_LOADING_MODE=interactive ERL_LIBS=/opt/ldapsp + +[Install] +WantedBy=multi-user.target + diff --git a/priv/policy.erl b/priv/policy.erl new file mode 100644 index 0000000..bca21da --- /dev/null +++ b/priv/policy.erl @@ -0,0 +1,39 @@ +%%%------------------------------------------------------------------- +%%% @copyright (C) 2016, Guido Günther +%%% @doc +%%% +%%% @end +%%%------------------------------------------------------------------- +-module(policy). + +-export([add_host/3, + del_host/2 + ]). + +% -> data to return +add_host(Hostname, Class, Realm) -> + Dn = host2dn(Hostname, Realm), + Attrs = class2attr(Hostname, Class, Realm), + ok = ldapsp_ldap:add(Dn, Attrs), + [{dn, list_to_binary(Dn)}, + {randompassword, <<"UNSET">>}]. + +% -> true, false +del_host(Hostname, Realm) -> + Dn = host2dn(Hostname, Realm), + del_result(ldapsp_ldap:delete(Dn)). + +%% Private functions +host2dn(Host, Realm) -> + Base = string:join([ "dc=" ++ C || C <- string:tokens(Realm, ".")], ", "), + "cn=" ++ hd(string:tokens(Host, ".")) ++ ", " ++ Base. + +class2attr(Host, _Class, Realm) -> + [{"objectclass", ["top", "groupOfUniqueNames"]}, + {"cn", [Host]}, + {"uniqueMember", [host2dn(Host, Realm)]}]. + +del_result({error,noSuchObject}) -> true; +del_result(ok) -> true; +del_result(_) -> false. + |