Skip to content

Commit

Permalink
search sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Jul 22, 2023
1 parent 5a531b5 commit a412e3b
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions lib/ldap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ defmodule LDAP.TCP do
def collect(db,st,:done, acc), do: acc
def collect(db,st,{:row,x}, acc), do: collect(db,st,step(db,st),[:erlang.list_to_tuple(x)|acc])

#09:12:30.882 [info] SEARCH Filter: {:and,
# [
# or: [
# equalityMatch: {:AttributeValueAssertion, "objectClass", "top"},
# substrings: {:SubstringFilter, "cn", [final: "a"]},
# present: "objectClass"
# ],
# substrings: {:SubstringFilter, "objectClass", [any: "a"]}
# ]}

def query(name) do
{:ok, db} = open(name)
{:ok, st} = prepare(db, "select * from ldap where rdn in (select rdn from ldap where " <>
" (att = 'objectClass' and val like '%a%') " <>
" and " <>
" ((att = 'objectClass') or " <>
"(att = 'cn' and val like '%a%') or" <>
"(att = 'objectClass' and val='top')))" )
res = step(db,st)
collect(db,st,res,[])
end

def list(name) do
{:ok, db} = open(name)
{:ok, st} = prepare(db, "select * from ldap")
Expand Down Expand Up @@ -132,7 +154,7 @@ defmodule LDAP.TCP do
attr("objectClass",['inetOrgPerson','posixAccount'])])]

:lists.map(fn response -> answer(response,no,:searchResEntry,socket) end,

case scope do
:baseObject -> synrc
:singleLevel -> users
Expand All @@ -159,7 +181,7 @@ defmodule LDAP.TCP do


:lists.map(fn response -> answer(response,no,:searchResEntry,socket) end,

case scope do
:wholeSubtree -> schema
:baseObject -> schema
Expand Down Expand Up @@ -199,7 +221,7 @@ defmodule LDAP.TCP do
"cn=admin,dc=synrc,dc=com" -> admin
end
_ -> []

end

)
Expand All @@ -208,20 +230,6 @@ defmodule LDAP.TCP do
answer(resp, no, :searchResDone,socket)
end

def message(no, socket, {:searchRequest, {_,bindDN,scope,_,limit,_,_,filter,attributes}}, db) do
:logger.info 'SEARCH DN: ~p', [bindDN]
:logger.info 'SEARCH Scope: ~p', [scope]
:logger.info 'SEARCH Filter: ~p', [filter]
:logger.info 'SEARCH Attr: ~p', [attributes]

:lists.map(fn response -> answer(response,no,:searchResEntry,socket) end,
[
])

resp = LDAP.'LDAPResult'(resultCode: :success, matchedDN: "", diagnosticMessage: 'OK')
answer(resp, no, :searchResDone,socket)
end

def message(no, socket, {:modDNRequest, {_,dn,rdn,old,_}}, db) do
:logger.info 'MOD RDN DN: ~p', [dn]
:logger.info 'MOD RDN newRDN: ~p', [rdn]
Expand Down

0 comments on commit a412e3b

Please sign in to comment.