Skip to content

Commit

Permalink
Merge pull request #29 from s0i37/vital_commands
Browse files Browse the repository at this point in the history
added vital commands: cd, ls, cat, modify
  • Loading branch information
skelsec authored Dec 29, 2022
2 parents f60ba50 + 08938d1 commit c346874
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions msldap/examples/msldapclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ async def do_login(self, url = None):
logger.debug(self.conn_url.get_credential())
logger.debug(self.conn_url.get_target())


self.connection = self.conn_url.get_client()
_, err = await self.connection.connect()
if err is not None:
raise err
print('BIND OK!')
self.prompt = self.connection._tree + ' > '

return True
except:
Expand Down Expand Up @@ -171,7 +171,49 @@ async def do_dump(self):
traceback.print_exc()
return False

async def do_query(self, query, attributes = None):
async def do_cd(self, path):
"""Change current work directory"""
self.connection._tree = path
self.prompt = self.connection._tree + ' > '
return True

async def do_ls(self):
"""Print objects in current work directory"""
tree_data = await self.connection.get_tree_plot(self.connection._tree, level=1)
root = list(tree_data.keys())[0]
for dn in tree_data[root].keys():
print(dn)
return True

async def do_cat(self, dn, attributes="*"):
"""Print attributes of object"""
attributes = attributes.split(",")
async for entry, err in self.connection.pagedsearch(query="(distinguishedName=%s)"%dn, attributes=attributes):
if err is not None:
raise err
for attr in entry["attributes"]:
if type(entry["attributes"][attr]) == list:
for val in entry["attributes"][attr]:
print("%s: %s" % (attr, val))
else:
val = entry["attributes"][attr]
print("%s: %s" % (attr, val))
return True

async def do_modify(self, dn, attribute, value):
"""Modify an attribute of object"""
changes = {
attribute : [('replace', [value.encode()])]
}

_, err = await self.connection.modify(dn, changes)
if err is not None:
raise err

print('Modify OK!')
return True

async def do_query(self, query, attributes = "-"):
"""Performs a raw LDAP query against the server. Secondary parameter is the requested attributes SEPARATED WITH COMMA (,)"""
try:
await self.do_ldapinfo(False)
Expand Down

0 comments on commit c346874

Please sign in to comment.