mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Implement user-find and user-add backend functions so they work over XML-RPC
Change port to 8880 to not conflict with a running IPA v1 instance Encode incoming values from unicode as utf-8 before sending to LDAP
This commit is contained in:
@@ -35,7 +35,7 @@ class xmlrpc(Backend):
|
||||
|
||||
def get_client(self):
|
||||
# FIXME: The server uri should come from self.api.env.server_uri
|
||||
return xmlrpclib.ServerProxy('http://localhost:8080', allow_none=True)
|
||||
return xmlrpclib.ServerProxy('http://localhost:8888', allow_none=True)
|
||||
|
||||
def forward_call(self, name, *args, **kw):
|
||||
"""
|
||||
@@ -45,5 +45,6 @@ class xmlrpc(Backend):
|
||||
command = getattr(client, name)
|
||||
params = xmlrpc_marshal(*args, **kw)
|
||||
return command(*params)
|
||||
# return command(*args, **kw)
|
||||
|
||||
api.register(xmlrpc)
|
||||
|
||||
@@ -25,7 +25,10 @@ from ipalib import frontend
|
||||
from ipalib import crud
|
||||
from ipalib.frontend import Param
|
||||
from ipalib import api
|
||||
|
||||
from ipa_server import servercore
|
||||
from ipa_server import ipaldap
|
||||
import ldap
|
||||
from ipa_server.context import context
|
||||
|
||||
# Command to get the idea how plugins will interact with api.env
|
||||
class envtest(frontend.Command):
|
||||
@@ -71,7 +74,79 @@ api.register(user)
|
||||
class user_add(crud.Add):
|
||||
'Add a new user.'
|
||||
def execute(self, *args, **kw):
|
||||
return 1
|
||||
"""args[0] = uid of the user to add
|
||||
kw{container} is the location in the DIT to add the user, not
|
||||
required
|
||||
kw otherwise contains all the attributes
|
||||
"""
|
||||
# FIXME: ug, really?
|
||||
if not kw.get('container'):
|
||||
user_container = servercore.DefaultUserContainer
|
||||
else:
|
||||
user_container = kw['container']
|
||||
del kw['container']
|
||||
|
||||
user = kw
|
||||
|
||||
if not isinstance(user, dict):
|
||||
# FIXME, need proper error
|
||||
raise SyntaxError
|
||||
|
||||
user['uid'] = args[0]
|
||||
|
||||
# dn is set here, not by the user
|
||||
try:
|
||||
del user['dn']
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
# No need to set empty fields, and they can cause issues when they
|
||||
# get to LDAP, like:
|
||||
# TypeError: ('expected a string in the list', None)
|
||||
for k in user.keys():
|
||||
if not user[k] or len(user[k]) == 0 or (isinstance(user[k],list) and len(user[k]) == 1 and '' in user[k]):
|
||||
del user[k]
|
||||
|
||||
dn="uid=%s,%s,%s" % (ldap.dn.escape_dn_chars(user['uid']),
|
||||
user_container,servercore.basedn)
|
||||
|
||||
entry = ipaldap.Entry(dn)
|
||||
|
||||
# Let us add in some missing attributes
|
||||
# FIXME, get config
|
||||
# if user.get('homedirectory') is None:
|
||||
# user['homedirectory'] = '%s/%s' % (config.get('ipahomesrootdir'), user.get('uid'))
|
||||
# user['homedirectory'] = user['homedirectory'].replace('//', '/')
|
||||
# user['homedirectory'] = user['homedirectory'].rstrip('/')
|
||||
# if user.get('loginshell') is None:
|
||||
# user['loginshell'] = config.get('ipadefaultloginshell')
|
||||
if user.get('gecos') is None:
|
||||
user['gecos'] = user['uid']
|
||||
|
||||
# FIXME: add to default group
|
||||
user['gidNumber'] = "500"
|
||||
|
||||
if user.get('krbprincipalname') is None:
|
||||
user['krbprincipalname'] = "%s@%s" % (user.get('uid'), self.realm)
|
||||
|
||||
# FIXME. This is a hack so we can request separate First and Last
|
||||
# name in the GUI.
|
||||
if user.get('cn') is None:
|
||||
user['cn'] = "%s %s" % (user.get('givenname'),
|
||||
user.get('sn'))
|
||||
|
||||
# some required objectclasses
|
||||
# FIXME
|
||||
# entry.setValues('objectClass', (config.get('ipauserobjectclasses')))
|
||||
entry.setValues('objectClass', ['top', 'person', 'organizationalPerson', 'inetOrgPerson', 'inetUser', 'posixAccount', 'krbPrincipalAux'])
|
||||
|
||||
# fill in our new entry with everything sent by the user
|
||||
for u in user:
|
||||
entry.setValues(u, user[u])
|
||||
|
||||
result = context.conn.getConn().addEntry(entry)
|
||||
return result
|
||||
|
||||
api.register(user_add)
|
||||
|
||||
|
||||
@@ -87,10 +162,14 @@ api.register(user_mod)
|
||||
|
||||
class user_find(crud.Find):
|
||||
'Search the users.'
|
||||
# def execute(self, *args, **kw):
|
||||
# uid=args[0]
|
||||
# result = servercore.get_sub_entry(servercore.basedn, "uid=%s" % uid, ["*"])
|
||||
# return result
|
||||
def execute(self, *args, **kw):
|
||||
uid=args[0]
|
||||
result = servercore.get_sub_entry(servercore.basedn, "uid=%s" % uid, ["*"])
|
||||
return result
|
||||
def forward(self, *args, **kw):
|
||||
result = super(crud.Find, self).forward(*args, **kw)
|
||||
for a in result:
|
||||
print a, ": ", res[a]
|
||||
api.register(user_find)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user