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/policy.erl |
Initial commit
Diffstat (limited to 'priv/policy.erl')
-rw-r--r-- | priv/policy.erl | 39 |
1 files changed, 39 insertions, 0 deletions
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. + |