More work on making user-add use Backend.ldap

This commit is contained in:
Jason Gerard DeRose 2008-10-14 02:23:56 -06:00
parent 1480224724
commit 9788800aa4
2 changed files with 29 additions and 20 deletions

View File

@ -25,10 +25,10 @@ This wraps the python-ldap bindings.
import ldap as _ldap
from ipalib import api
from ipalib.backend import Backend
from ipalib.crud import CrudBackend
class ldap(Backend):
class ldap(CrudBackend):
"""
LDAP backend plugin.
"""
@ -45,4 +45,7 @@ class ldap(Backend):
self.api.env.basedn,
)
def create(self, **kw):
return kw
api.register(ldap)

View File

@ -55,20 +55,36 @@ class user(frontend.Object):
User object.
"""
takes_params = (
Param('givenname', cli_name='firstname'),
Param('sn', cli_name='lastname'),
Param('givenname',
cli_name='first',
doc='User first name',
),
Param('sn',
cli_name='last',
doc='User last name',
),
Param('uid',
cli_name='user',
primary_key=True,
default_from=lambda givenname, sn: givenname[0] + sn,
normalize=lambda value: value.lower(),
),
Param('krbprincipalname',
default_from=lambda uid: '%s@EXAMPLE.COM' % uid,
Param('gecos',
doc='GECOS field',
default_from=lambda uid: uid,
),
Param('homedirectory',
cli_name='home',
doc='Path of user home directory',
default_from=lambda uid: '/home/%s' % uid,
)
),
Param('shell',
default=u'/bin/sh',
doc='Login shell',
),
Param('krbprincipalname?', cli_name='principal',
default_from=lambda uid: '%s@EXAMPLE.COM' % uid,
),
)
api.register(user)
@ -90,21 +106,11 @@ class user_add(crud.Add):
"""
assert 'uid' not in kw
assert 'dn' not in kw
ldap = self.api.Backend.ldap
kw['uid'] = uid
kw['dn'] = self.api.Backend.ldap.get_user_dn(uid)
kw['dn'] = ldap.get_user_dn(uid)
return ldap.create(**kw)
return kw
# FIXME: ug, really?
if not kw.get('container'):
user_container = servercore.DefaultUserContainer
else:
user_container = kw['container']
del kw['container']
user = kw
user['uid'] = args[0]
if servercore.user_exists(user['uid']):
raise errors.Duplicate("user already exists")