[Python Wpg] It's 2:10 AM, do you know where LdapFS is?

Scott Balneaves sbalneav at legalaid.mb.ca
Fri Apr 14 03:15:13 EDT 2006


Man, I need to get a life.

#!/usr/bin/python

#
# Fools rush in...
#

from fuse import Fuse
from errno import *
from stat import *
import ldap

class LdapFS(Fuse):

    def __init__(self, *args, **kw):
    
        Fuse.__init__(self, *args, **kw)

        # 
        # Open our LDAP connection for use later.
        #

        self.path   = 'dc=legalaid,dc=mb,dc=ca'
        self.host   = 'localhost'
        self.passwd = 'oogabooga'
        
        try:
            self.ldap_handle = ldap.open(self.host);
            self.ldap_handle.simple_bind('cn=ldapadmin,' + self.path, \
                                         self.passwd)
        except ldap.LDAPError, error:
            print 'Problem with ldap:', error

    def getattr(self, path):
        """
        Ick.  So broken it's not even funny.
        """
        mode =
S_IFDIR|S_IRUSR|S_IXUSR|S_IWUSR|S_IRGRP|S_IXGRP|S_IXOTH|S_IROTH
        ino  = 1
        dev  = 8193L
        link = 2
        uid  = 0
        gid  = 0
        size = 4096L
        atime = 0
        mtime = 0
        ctime = 0
        
        return (mode, ino, dev, link, uid, gid, size, atime, mtime,
ctime)

    def getdir(self, path):
        mydir = [('.', 0), ('..', 0)]
        try:
            result = self.ldap_handle.search_s(self.path, \
                                               ldap.SCOPE_SUBTREE,
'(ou=*)')
        except ldap.LDAPError, error:
            print 'Problem with ldap:', error

        ous = []
        for ou in result:
            ous.append(ou[0])
            
        mydir.extend(map(lambda x: (x,0), ous))
        return mydir

if __name__ == '__main__':

        server = LdapFS()
        server.multithreaded = 1;
        server.main()


-------

sbalneav at phobos:~$ ./LdapFS.py ~/foo

(in another window)

sbalneav at phobos:~$ ls -la ~/foo
total 24
drwxr-xr-x   2 root     root     4096 Dec 31  1969 .
drwxr-xr-x  89 sbalneav sbalneav 8192 Apr 14 01:05 ..
drwxr-xr-x   2 root     root     4096 Dec 31  1969 ou=groups,dc=legalaid,dc=mb,dc=ca
drwxr-xr-x   2 root     root     4096 Dec 31  1969 ou=phpgwgroups,dc=legalaid,dc=mb,dc=ca
drwxr-xr-x   2 root     root     4096 Dec 31  1969 ou=users,dc=legalaid,dc=mb,dc=ca
sbalneav at phobos:~$ fusermount -u ~/foo

Well, it's something.

Scott

-- 
Scott L. Balneaves | "Looking beyond the embers of bridges glowing behind us
Systems Department |  To a glimpse of how green it was on the other side..."
Legal Aid Manitoba |    -- Pink Floyd "High Hopes"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/winnipeg/attachments/20060414/6d76e9c8/attachment.sig>


More information about the Winnipeg mailing list