Skip to content

Commit

Permalink
ldap search
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Jul 23, 2023
1 parent c534e54 commit 96a371b
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions lib/ldap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ defmodule LDAP.TCP do
def match({:or, list}), do: "(" <> join(list, 'or') <> ")"
def match({:not, x}), do: "(not(" <> match(x) <> "))"

def sel(name, filter) do
{:ok, db} = open(name)
scope = :singleLevel
dn = "dc=synrc,dc=com"
select([], [], db, filter, scope, dn)
end

def select(socket, no, db, filter, scope, dn) do
{:ok, st} = prepare(db, query(scope, filter, dn))
case step(db,st) do
Expand All @@ -86,7 +79,7 @@ defmodule LDAP.TCP do

def start() do
instance = code()
:erlang.spawn(fn -> listen(1489,instance) end)
:erlang.spawn(fn -> listen(:application.get_env(:ldap,:port,1489),instance) end)
end

def initDB(path) do
Expand All @@ -106,7 +99,7 @@ defmodule LDAP.TCP do
createDN(conn, "ou=schema", [attr("ou",["schema"]),attr("objectClass",["top","domain"])])
createDN(conn, "cn=tonpa,dc=synrc,dc=com", [attr("cn",["tonpa"]),attr("uid",["1000"]),attr("objectClass",["inetOrgPerson","posixAccount"])])
createDN(conn, "cn=rocco,dc=synrc,dc=com", [attr("cn",["rocco"]),attr("uid",["1001"]),attr("objectClass",["inetOrgPerson","posixAccount"])])
createDN(conn, "cn=admin,dc=synrc,dc=com", [attr("rootpw",["secret"]),attr("cn",["admin"])])
createDN(conn, "cn=admin,dc=synrc,dc=com", [attr("rootpw",["secret"]),attr("cn",["admin"]),attr("objectClass",["inetOrgPerson"])])
{:ok, socket} = :gen_tcp.listen(port,
[:binary, {:packet, 0}, {:active, false}, {:reuseaddr, true}])
accept(socket,conn)
Expand Down Expand Up @@ -253,7 +246,6 @@ defmodule LDAP.TCP do
message = LDAP."LDAPMessage"(messageID: no, protocolOp: {op, response})
{:ok, bytes} = :'LDAP'.encode(:'LDAPMessage', message)
send = :gen_tcp.send(socket, :erlang.iolist_to_binary(bytes))
:io.format 'SEND: ~p ~p ~p ~p~n', [send, no, op, response]
end

def appendNotEmpty([]), do: []
Expand Down

0 comments on commit 96a371b

Please sign in to comment.