[python-ldap] Read/Change public ssh key with ldap-python
John Theodore
JohnTheodore42 at gmail.com
Mon Aug 25 20:32:08 CEST 2014
So I setup python-ldapdb and have a little api that is working. I can query
and read from the ldap box using python-ldapdb and their models.
My project is here: https://github.com/JohnTheodore/django-ldapdb
The problem is I can't modify the ldap object (say change the sshPublicKey
attribute) and .save() it.
When I try to .save() I'm getting: NO_SUCH_OBJECT: {'matched':
'uid=john_theodore,ou=People,dc=mgmt,dc=mydomain,dc=net', 'desc': 'No such
object'}
My paste/gist which shows the log is here (I turned on debug mode):
https://gist.github.com/JohnTheodore/6d317fe1b337bd402ee3
Any ideas why I can't modify an entry? basically I want to rewrite the
sshkeys attribute and then save() it.
On Mon, Aug 18, 2014 at 11:15 AM, Raphaël Barrois <raphael.barrois at m4x.org>
wrote:
> On Mon, 18 Aug 2014 09:44:10 -0700
> John Theodore <JohnTheodore42 at gmail.com> wrote:
>
> > I'm trying to make a simple web app that can manage/change my public
> > ssh keys on ldap using python-ldap and django. I'm trying to
> > understand the ldap library better. I know I can query the ldap box
> > and get a list of attributes (including public ssh keys) by doing
> > this command:
> >
> > l=ldap.initialize("ldap://myldaphost.mydomain.com")
> > l.simple_bind_s("CN=ldapuser,CN=Users,DC=mydomain, DC=com","secret")
> > r = l.search_s(
> > "CN=ANYCOMPUTER,CN=Computers,DC=mydomain,DC=co m",
> > ldap.SCOPE_SUBTREE, # this is the default of ldapsearch
> > "(objectClass=*)"
> > )
> >
> > .
> > What I'm trying to figure out, is how can I delete or update an ssh
> > key for a specific account? The command I would be doing on
> > ldapmodify is this:
> >
> > ldapmodify -h localhost -D
> > "uid=user,ou=People,dc=mgmt,dc=symcpe,dc=net" -w $passwrd
> > -f /tmp/usertomod.ldif.
> >
> > How can I duplicate this command in python-ldap?
>
> Hi John,
>
> This would be done with modify() and delete():
> http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject.modify
> http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject.delete
>
> If you're using Django, you might also be interested in django-ldapdb (
> https://github.com/jlaine/django-ldapdb), which provides Django-like
> models backed on a LDAP database, i.e with a higher level API.
>
>
> --
> Raphaël
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20140825/56ed18a6/attachment-0001.html>
More information about the python-ldap
mailing list