Beispiel #1
0
        def cbLoggedIn(e, config):
            mail = only(e, config.getLDAPAttributeMailbox())
            username = mail.split('@', 1)[0]
            hostname = mail.split('@', 1)[1]

            username = quot(username)
            hostname = quot(hostname)

            userpad = (username+'__')[:2]

            mailhost = only(e, config.getLDAPAttributeMailHost())

            userdir = os.path.join(
                config.getSpool(),
                hostname,
                mailhost,
                userpad)

            switchUID(uid=pwd.getpwnam('scalemail')[2],
                      gid=grp.getgrnam('scalemail')[2])

            if not os.path.isdir(userdir):
                os.mkdir(userdir, 0700)
            os.chdir(userdir)

            if not os.path.isdir(username):
                initializeMaildir(username)
            os.chdir(username)

            os.execlp(sys.argv[1], *sys.argv[1:])
            print >>sys.stderr, "scalemail-courier-login: Cannot exec command."
            sys.exit(2)
Beispiel #2
0
def cbLoggedIn(e, config, env):
    mail = only(e, config.getLDAPAttributeMailbox())
    username = mail.split('@', 1)[0]
    hostname = mail.split('@', 1)[1]

    username = quot(username)
    hostname = quot(hostname)

    userpad = (username+'__')[:2]

    mailhost = only(e, config.getLDAPAttributeMailHost())

    userdir = os.path.join(config.getSpool(),
                           hostname,
                           mailhost,
                           userpad)

    env['MAILDIR'] = '.'
    env['AUTHENTICATED'] = mail
    return (userdir, username)
Beispiel #3
0
def main(config, argv, env, service, authtype, authdata):
    if not argv[1:]:
        raise UsageError, "Need to provide some arguments."
    if env.get('AUTHENTICATED'):
        raise AlreadyAuthenticated

    if authtype != 'login':
        raise UnsupportedAuthenticationType, authtype

    l = authdata.splitlines()
    if len(l) == 3 and l[-1] == '':
        # authlib(7) says the empty line shouldn't be there. Nice.
        del l[-1]
    if len(l) != 2:
        raise BadAuthData
    userid, password = l

    userid = userid.replace('%', '@')
    if '@' not in userid:
        raise UserIdMustContainAtSign, userid

    hostname = userid.split('@', 1)[1]
    ldapcfg = ldapconfig.LDAPConfig(
        baseDN=config.getDNForDomain(hostname),
        serviceLocationOverrides=config.getServiceLocationOverride(),
        identitySearch='(%s=%%(name)s)' % config.getLDAPAttributeMailbox())
    checker = checkers.LDAPBindingChecker(ldapcfg)

    d = defer.maybeDeferred(checker.requestAvatarId,
                            credentials.UsernamePassword(userid, password))

    def fetchAttributes(e, *attrs):
        return e.fetch(*attrs)
    d.addCallback(fetchAttributes,
                  config.getLDAPAttributeMailbox(),
                  config.getLDAPAttributeMailHost(),
                  )
    d.addCallback(cbLoggedIn, config, env)
    return d
Beispiel #4
0
 def fetchAttributes(e, config):
     return e.fetch(
         config.getLDAPAttributeMailbox(),
         config.getLDAPAttributeMailHost(),
         )