Python Apache Library (plus htaccess)
I’ve been working on switching over a bunch of my Apache web servers to run lighttpd and ran into a small problem with authentication. Lighttpd supports Apache style htpasswd files for authentication, but the catch is that it doesn’t come with any tool to manipulate them like Apache does. They do offer a Perl script on their site that will do basic htpasswd file manipulation but I’m no big fan of Perl and I’m always up for a challenge. So I set forth to write a Python clone of the htpasswd tool.
About half-way through writing my new htpasswd tool I got the bright idea to break out the functionality into a library called apachelib. Since I was striving for a feature-complete htpasswd clone I wanted to be sure to implement every function. Well, that’s fine and easy until I got to the MD5 hashing. Apache takes a, shall we say, “unique” approach to generating its MD5 hashes. Well after some quality time with the APR C code I’ve duplicated Apache’s MD5 hashing routine in Python. Check it out in my subversion repository. I’m still working on the front-end to htpasswd but all the back-end code is in there and complete. Just import apachelib.htpasswd or apachelib.md5.
I’m also considering writing a class wrapper for htpasswd files so that they can be easily manipulated in Python. I’ll probably do that at some time and incorporate it into apachelib. I can imagine how it would be useful to integrate a real user-manager into Trac, since it relies on the web server for authentication and the web server relies on htpasswd files. Anyhow, more on that later when it materializes.
So, quite honestly I googled my way to your blog, which is awesome because *surprise* you sit on the other side of my cubicle wall!
What I was really looking to do is manage not only htpasswd (which I had already figured out) but also the dbm used by apache (rather than a flat file). It’s wrapped up quite nicely in Perl via HTTP::UserAdmin, but I was hoping for an all-in-one much like it in Python because I love Python and Python loves me. I won’t go into details about our relationship, but I’m pretty sure I may have to move to Utah with my wife and take Python with us. I hear it’s legal to have multiple wives there.
So, anyhow, anydbm, gdbm, dumbdbm don’t seem to work with the ’sdbm’ format generated by apaches dbm tools.. I’m digging into it, but was hoping you might have some clues off the top of your head. I yelled over the wall, but you’re out getting lunch or playing ping pong or something. You’re probably drunk.
Benjamin W. Smith said this on December 16th, 2008 at 12:16 pm