From: Garland, K. R <gar...@gm...> - 2007-03-19 18:21:57
|
I've sliced together a script to add users to ldap, which works great. however, now i'm implementing it into a webapp and having some issues. -------------------- Spyce exception File: /home/kgarland/downloads/spyce-2.1/www/newadd.spy Message: AttributeError: 'str' object has no attribute 'keys' Stack: /usr/lib/python2.4/site-packages/ldap/modlist.py:34, in addModlist: for attrtype in entry.keys(): newadd.spy:19, in passcheck: mymodlist = ldap.modlist.addModlist(entry) -------------------- My code causing the issue: -------------------- def passcheck(self, api, passwd, firstname, lastname, vamcdrop): import string, sys, ldap, crack, hashlib, base64 try: crack.VeryFascistCheck(passwd) except ValueError, reason: print("Please use a different password, %s." % reason) else: l=ldap.initialize("ldaps://null") l.bind_s('cn=removed,dc=removed,dc=removed', 'removed') y = hashlib.sha1(passwd).digest() base64encode = base64.encodestring(y) userpass = string.rstrip(base64encode) uid = firstname.lower() + "." + lastname.lower() mydn = "uid=" + uid + ",ou=VA,dc=pharmacy,dc=com" entry = "{'uid': ['" + uid + "'], 'objectClass': ['top', 'inetOrgPerson'], 'userPassword': ['" + '{SHA}' + userpass + "'], 'vamc': ['" + vamcdrop + "'], 'sn': ['" + lastname + "'], 'givenName': ['" + firstname + "'], 'cn': ['" + firstname + " " + lastname + "']}" mymodlist = ldap.modlist.addModlist(entry) l.add_s(mydn, mymodlist) print "Adding the following information into LDAP:" print "<br>" print entry -------------------- Looks like modlist is not happy with the string being presented to it. Printing the entry variable gives the same results for both the webapp and commandline. Web: {'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'], 'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'], 'givenName': ['null'], 'cn': ['null null']} Shell: {'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'], 'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'], 'givenName': ['null'], 'cn': ['null null']} |
From: Alain S. <asp...@gm...> - 2007-03-19 18:37:20
|
I didn't read your code, but I know ldap dont like python's unicode string. Convert any strings coming from your web interface into string, using str(). Hope this help On 3/19/07, Garland, Ken R <gar...@gm...> wrote: > > I've sliced together a script to add users to ldap, which works great. > however, now i'm implementing it into a webapp and having some issues. > > -------------------- > Spyce exception > File: /home/kgarland/downloads/spyce- 2.1/www/newadd.spy > Message: > > AttributeError: 'str' object has no attribute 'keys' > > Stack: /usr/lib/python2.4/site-packages/ldap/modlist.py:34, in > addModlist: > > for attrtype in entry.keys (): > > newadd.spy:19, in passcheck: > mymodlist = ldap.modlist.addModlist(entry) > -------------------- > > My code causing the issue: > > -------------------- > def passcheck(self, api, passwd, firstname, lastname, vamcdrop): > import string, sys, ldap, crack, hashlib, base64 > try: > crack.VeryFascistCheck(passwd) > except ValueError, reason: > print("Please use a different password, %s." % reason) > else: > l=ldap.initialize("ldaps://null") > l.bind_s('cn=removed,dc=removed,dc=removed', 'removed') > y = hashlib.sha1(passwd).digest() > base64encode = base64.encodestring(y) > userpass = string.rstrip(base64encode) > uid = firstname.lower() + "." + lastname.lower() > mydn = "uid=" + uid + ",ou=VA,dc=pharmacy,dc=com" > entry = "{'uid': ['" + uid + "'], 'objectClass': > ['top', 'inetOrgPerson'], 'userPassword': ['" + '{SHA}' + userpass + > "'], 'vamc': ['" + vamcdrop + "'], 'sn': ['" + lastname + "'], > 'givenName': ['" + firstname + "'], 'cn': ['" + firstname + " " + > lastname + "']}" > mymodlist = ldap.modlist.addModlist(entry) > l.add_s(mydn, mymodlist) > print "Adding the following information into LDAP:" > print "<br>" > print entry > -------------------- > > Looks like modlist is not happy with the string being presented to it. > Printing the entry variable gives the same results for both the webapp > and commandline. > > Web: > {'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'], > 'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'], > 'givenName': ['null'], 'cn': ['null null']} > > Shell: > {'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'], > 'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'], > 'givenName': ['null'], 'cn': ['null null']} > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Python-LDAP-dev mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/python-ldap-dev > -- -- Alain Spineux aspineux gmail com May the sources be with you -- -- Alain Spineux aspineux gmail com May the sources be with you |
From: Garland, K. R <gar...@gm...> - 2007-03-19 19:09:37
|
well i get the error still. but i made a mistake earlier and it looks like my string is not a true dictionary and modlist is unhappy with it. The shell version of my script is a bit different and doesn't have this issue. Traceback (most recent call last): File "./ldapadd.py", line 23, in ? mymodlist = ldap.modlist.addModlist(newentry) File "/usr/lib/python2.4/site-packages/ldap/modlist.py", line 34, in addModlist for attrtype in entry.keys(): AttributeError: 'str' object has no attribute 'keys' Now I'll dive into converting it into a dictionary. Thanks, looks like the error is on my part. On 3/19/07, Alain Spineux <asp...@gm...> wrote: > > I didn't read your code, but I know ldap dont like python's unicode string. > > Convert any strings coming from your web interface into string, using str(). > > Hope this help > > > > On 3/19/07, Garland, Ken R <gar...@gm...> wrote: > > I've sliced together a script to add users to ldap, which works great. > > however, now i'm implementing it into a webapp and having some issues. > > > > -------------------- > > Spyce exception > > File: /home/kgarland/downloads/spyce- 2.1/www/newadd.spy > > Message: > > > > AttributeError: 'str' object has no attribute 'keys' > > > > Stack: > /usr/lib/python2.4/site-packages/ldap/modlist.py:34, > in addModlist: > > > > for attrtype in entry.keys (): > > > > newadd.spy:19, in passcheck: > > mymodlist = ldap.modlist.addModlist(entry) > > -------------------- > > > > My code causing the issue: > > > > -------------------- > > def passcheck(self, api, passwd, firstname, lastname, vamcdrop): > > import string, sys, ldap, crack, hashlib, base64 > > try: > > crack.VeryFascistCheck(passwd) > > except ValueError, reason: > > print("Please use a different password, %s." % reason) > > else: > > l=ldap.initialize("ldaps://null") > > > l.bind_s('cn=removed,dc=removed,dc=removed', 'removed') > > y = hashlib.sha1(passwd).digest() > > base64encode = base64.encodestring(y) > > userpass = string.rstrip(base64encode) > > uid = firstname.lower() + "." + lastname.lower() > > mydn = "uid=" + uid + ",ou=VA,dc=pharmacy,dc=com" > > entry = "{'uid': ['" + uid + "'], 'objectClass': > > ['top', 'inetOrgPerson'], 'userPassword': ['" + '{SHA}' + userpass + > > "'], 'vamc': ['" + vamcdrop + "'], 'sn': ['" + lastname + "'], > > 'givenName': ['" + firstname + "'], 'cn': ['" + firstname + " " + > > lastname + "']}" > > mymodlist = ldap.modlist.addModlist(entry) > > l.add_s(mydn, mymodlist) > > print "Adding the following information into LDAP:" > > print "<br>" > > print entry > > -------------------- > > > > Looks like modlist is not happy with the string being presented to it. > > Printing the entry variable gives the same results for both the webapp > > and commandline. > > > > Web: > > {'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'], > > 'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'], > > 'givenName': ['null'], 'cn': ['null null']} > > > > Shell: > > {'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'], > > 'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'], > > 'givenName': ['null'], 'cn': ['null null']} > > > > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > > opinions on IT & business topics through brief surveys-and earn cash > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > _______________________________________________ > > Python-LDAP-dev mailing list > > Pyt...@li... > > > https://lists.sourceforge.net/lists/listinfo/python-ldap-dev > > > > > > -- > -- > Alain Spineux > aspineux gmail com > May the sources be with you > > > -- > -- > Alain Spineux > aspineux gmail com > May the sources be with you > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Python-LDAP-dev mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/python-ldap-dev > > |
From: Joao S. O. B. C. <gw...@mp...> - 2007-03-19 21:37:07
|
On Monday 19 March 2007 15:37, Alain Spineux wrote: > I didn't read your code, but I know ldap dont like python's unicode > string. > > Convert any strings coming from your web interface into string, > using str(). > better do your_unicode_string.encode("utf-8") - that way your application won't crash on non ASCII characters. > Hope this help > > On 3/19/07, Garland, Ken R <gar...@gm...> wrote: > > I've sliced together a script to add users to ldap, which works > > great. however, now i'm implementing it into a webapp and having > > some issues. > > > > -------------------- > > Spyce exception > > File: /home/kgarland/downloads/spyce- 2.1/www/newadd.spy > > Message: > > > > AttributeError: 'str' object has no attribute 'keys' > > > > Stack: /usr/lib/python2.4/site-packages/ldap/modlist.py:34, in > > addModlist: > > > > for attrtype in entry.keys (): > > > > newadd.spy:19, in passcheck: > > mymodlist = ldap.modlist.addModlist(entry) > > -------------------- > > > > My code causing the issue: > > > > -------------------- > > def passcheck(self, api, passwd, firstname, lastname, vamcdrop): > > import string, sys, ldap, crack, hashlib, base64 > > try: > > crack.VeryFascistCheck(passwd) > > except ValueError, reason: > > print("Please use a different password, %s." % > > reason) else: > > l=ldap.initialize("ldaps://null") > > l.bind_s('cn=removed,dc=removed,dc=removed', > > 'removed') y = hashlib.sha1(passwd).digest() > > base64encode = base64.encodestring(y) > > userpass = string.rstrip(base64encode) > > uid = firstname.lower() + "." + lastname.lower() > > mydn = "uid=" + uid + ",ou=VA,dc=pharmacy,dc=com" > > entry = "{'uid': ['" + uid + "'], 'objectClass': > > ['top', 'inetOrgPerson'], 'userPassword': ['" + '{SHA}' + > > userpass + "'], 'vamc': ['" + vamcdrop + "'], 'sn': ['" + > > lastname + "'], 'givenName': ['" + firstname + "'], 'cn': ['" + > > firstname + " " + lastname + "']}" > > mymodlist = ldap.modlist.addModlist(entry) > > l.add_s(mydn, mymodlist) > > print "Adding the following information into > > LDAP:" print "<br>" > > print entry > > -------------------- > > > > Looks like modlist is not happy with the string being presented > > to it. Printing the entry variable gives the same results for > > both the webapp and commandline. > > > > Web: > > {'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'], > > 'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'], > > 'givenName': ['null'], 'cn': ['null null']} > > > > Shell: > > {'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'], > > 'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'], > > 'givenName': ['null'], 'cn': ['null null']} > > > > ----------------------------------------------------------------- > >-------- Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to > > share your > > opinions on IT & business topics through brief surveys-and earn > > cash > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CI > >D=DEVDEV _______________________________________________ > > Python-LDAP-dev mailing list > > Pyt...@li... > > https://lists.sourceforge.net/lists/listinfo/python-ldap-dev > > -- > -- > Alain Spineux > aspineux gmail com > May the sources be with you |
From: Garland, K. R <gar...@gm...> - 2007-03-19 23:48:45
|
thanks, i think i was getting by with my own tests but i'm sure users will crash it with error. i've added your suggestion for encoding. On 3/19/07, Joao S. O. Bueno Calligaris <gw...@mp...> wrote: > On Monday 19 March 2007 15:37, Alain Spineux wrote: > > I didn't read your code, but I know ldap dont like python's unicode > > string. > > > > Convert any strings coming from your web interface into string, > > using str(). > > > > better do your_unicode_string.encode("utf-8") - that way your > application won't crash on non ASCII characters. > > > Hope this help > > > > On 3/19/07, Garland, Ken R <gar...@gm...> wrote: > > > I've sliced together a script to add users to ldap, which works > > > great. however, now i'm implementing it into a webapp and having > > > some issues. > > > > > > -------------------- > > > Spyce exception > > > File: /home/kgarland/downloads/spyce- 2.1/www/newadd.spy > > > Message: > > > > > > AttributeError: 'str' object has no attribute 'keys' > > > > > > Stack: /usr/lib/python2.4/site-packages/ldap/modlist.py:34, in > > > addModlist: > > > > > > for attrtype in entry.keys (): > > > > > > newadd.spy:19, in passcheck: > > > mymodlist = ldap.modlist.addModlist(entry) > > > -------------------- > > > > > > My code causing the issue: > > > > > > -------------------- > > > def passcheck(self, api, passwd, firstname, lastname, vamcdrop): > > > import string, sys, ldap, crack, hashlib, base64 > > > try: > > > crack.VeryFascistCheck(passwd) > > > except ValueError, reason: > > > print("Please use a different password, %s." % > > > reason) else: > > > l=ldap.initialize("ldaps://null") > > > l.bind_s('cn=removed,dc=removed,dc=removed', > > > 'removed') y = hashlib.sha1(passwd).digest() > > > base64encode = base64.encodestring(y) > > > userpass = string.rstrip(base64encode) > > > uid = firstname.lower() + "." + lastname.lower() > > > mydn = "uid=" + uid + ",ou=VA,dc=pharmacy,dc=com" > > > entry = "{'uid': ['" + uid + "'], 'objectClass': > > > ['top', 'inetOrgPerson'], 'userPassword': ['" + '{SHA}' + > > > userpass + "'], 'vamc': ['" + vamcdrop + "'], 'sn': ['" + > > > lastname + "'], 'givenName': ['" + firstname + "'], 'cn': ['" + > > > firstname + " " + lastname + "']}" > > > mymodlist = ldap.modlist.addModlist(entry) > > > l.add_s(mydn, mymodlist) > > > print "Adding the following information into > > > LDAP:" print "<br>" > > > print entry > > > -------------------- > > > > > > Looks like modlist is not happy with the string being presented > > > to it. Printing the entry variable gives the same results for > > > both the webapp and commandline. > > > > > > Web: > > > {'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'], > > > 'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'], > > > 'givenName': ['null'], 'cn': ['null null']} > > > > > > Shell: > > > {'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'], > > > 'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'], > > > 'givenName': ['null'], 'cn': ['null null']} > > > > > > ----------------------------------------------------------------- > > >-------- Take Surveys. Earn Cash. Influence the Future of IT > > > Join SourceForge.net's Techsay panel and you'll get the chance to > > > share your > > > opinions on IT & business topics through brief surveys-and earn > > > cash > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CI > > >D=DEVDEV _______________________________________________ > > > Python-LDAP-dev mailing list > > > Pyt...@li... > > > https://lists.sourceforge.net/lists/listinfo/python-ldap-dev > > > > -- > > -- > > Alain Spineux > > aspineux gmail com > > May the sources be with you > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Python-LDAP-dev mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/python-ldap-dev > |
From: <mi...@st...> - 2007-03-20 20:55:47
|
Garland, Ken R wrote: > entry = "{'uid': ['" + uid + "'], 'objectClass': > ['top', 'inetOrgPerson'], 'userPassword': ['" + '{SHA}' + userpass + > "'], 'vamc': ['" + vamcdrop + "'], 'sn': ['" + lastname + "'], > 'givenName': ['" + firstname + "'], 'cn': ['" + firstname + " " + > lastname + "']}" What made you think that you have to pass a string for parameter 'entry'? It MUST be a dictionary. As others noted all attribute values should be encoded to strings. This can either require .encode('utf-8') or .encode('ascii') according to the LDAP syntax defined for the various attributes. (One might argue that UTF-8 is a superset of ASCII but IMO it's better to catch syntax errors before sending anything to the server.) > {'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'], > 'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'], > 'givenName': ['null'], 'cn': ['null null']} BTW: Setting pseudo-null values is bad practice when adding LDAP entries. You may run into interop issues with other LDAP-enabled applications later. Ciao, Michael. |