From 0e137110c7f3c543faf9ec4cc7917d6aa81f02a6 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Thu, 2 Oct 2008 16:12:19 -0600 Subject: Started on skeleton for xmlrcp client/server --- ipalib/plugins/b_xmlrpc.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 ipalib/plugins/b_xmlrpc.py (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py new file mode 100644 index 00000000..afe76505 --- /dev/null +++ b/ipalib/plugins/b_xmlrpc.py @@ -0,0 +1,39 @@ +# Authors: +# Jason Gerard DeRose +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +""" +XML-RPC client plugin. + +Lightwieght XML-RPC client using Python standard library xmlrpclib. +""" + +import xmlrpclib +from ipalib.backend import Backend +from ipalib import api + +class xmlrpc(Backend): + """ + Kerberos backend plugin. + """ + + 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) + +api.register(xmlrpc) -- cgit From 3ffbaac64cc3a9ab704c707112f59e041986576c Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Thu, 2 Oct 2008 19:42:06 -0600 Subject: Backend.xmlrpc and simple-server.py now use the xmlrpc_marshal() and xmlrpc_unmarshal() functions respectively --- ipalib/plugins/b_xmlrpc.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index afe76505..61935f01 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -25,6 +25,7 @@ Lightwieght XML-RPC client using Python standard library xmlrpclib. import xmlrpclib from ipalib.backend import Backend +from ipalib.util import xmlrpc_marshal from ipalib import api class xmlrpc(Backend): @@ -36,4 +37,13 @@ class xmlrpc(Backend): # FIXME: The server uri should come from self.api.env.server_uri return xmlrpclib.ServerProxy('http://localhost:8080', allow_none=True) + def forward_call(self, name, *args, **kw): + """ + Forward a call over XML-RPC to an IPA server. + """ + client = self.get_client() + command = getattr(client, name) + params = xmlrpc_marshal(*args, **kw) + return command(*params) + api.register(xmlrpc) -- cgit From 7e4b0a072e69351496010d7b2151c9b434c8fdb0 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Sat, 4 Oct 2008 01:50:59 -0400 Subject: 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 --- ipalib/plugins/b_xmlrpc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index 61935f01..f8dacf5d 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -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) -- cgit From 69bc5ad77adecaf7d8fde4a6578c3d2f3ef355df Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Tue, 7 Oct 2008 02:10:15 -0400 Subject: Add some more supporting functions Do a little bit more error handling and checking --- ipalib/plugins/b_xmlrpc.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index f8dacf5d..d7cbd856 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -24,6 +24,7 @@ Lightwieght XML-RPC client using Python standard library xmlrpclib. """ import xmlrpclib +import socket from ipalib.backend import Backend from ipalib.util import xmlrpc_marshal from ipalib import api @@ -44,7 +45,10 @@ class xmlrpc(Backend): client = self.get_client() command = getattr(client, name) params = xmlrpc_marshal(*args, **kw) - return command(*params) -# return command(*args, **kw) + try: + return command(*params) + except socket.error, e: + print e[1] + return False api.register(xmlrpc) -- cgit From b2b5b904bcc1ab96d5efb992d5630505022d0ecb Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 7 Oct 2008 20:07:16 -0600 Subject: Made package-level docstrings more consistent so they read better in generated documentation --- ipalib/plugins/b_xmlrpc.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index d7cbd856..feb87556 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -18,9 +18,10 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -XML-RPC client plugin. +Backend plugin for XML-RPC client. -Lightwieght XML-RPC client using Python standard library xmlrpclib. +This provides a lightwieght XML-RPC client using Python standard library +``xmlrpclib`` module. """ import xmlrpclib -- cgit From 83bb41faebc0a61269f2869e9123166254fff5b3 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Wed, 8 Oct 2008 23:31:49 -0400 Subject: Mechanism to convert from xmlrpclib.Fault to an IPAError exception Include slew of new exceptions, not all of which are used yet --- ipalib/plugins/b_xmlrpc.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index feb87556..442afebf 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -29,6 +29,7 @@ import socket from ipalib.backend import Backend from ipalib.util import xmlrpc_marshal from ipalib import api +from ipalib import errors class xmlrpc(Backend): """ @@ -51,5 +52,7 @@ class xmlrpc(Backend): except socket.error, e: print e[1] return False + except xmlrpclib.Fault, e: + raise errors.convertFault(e) api.register(xmlrpc) -- cgit From 8a97b3e8a8f437cd99cc7cabbc719368b0247983 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Thu, 9 Oct 2008 23:11:03 -0400 Subject: Implement group-del --- ipalib/plugins/b_xmlrpc.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index 442afebf..da76aa2b 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -51,8 +51,13 @@ class xmlrpc(Backend): return command(*params) except socket.error, e: print e[1] - return False except xmlrpclib.Fault, e: - raise errors.convertFault(e) + err = errors.convertFault(e) + code = getattr(err,'faultCode',None) + if code: + print "%s: %s" % (code, getattr(err,'__doc__','')) + else: + raise err + return False api.register(xmlrpc) -- cgit From 75bad44c27bff471c03ddc86283506f53f47520c Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Fri, 10 Oct 2008 05:23:00 -0400 Subject: Enable the verbose flag to pass thru xmlrpc --- ipalib/plugins/b_xmlrpc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index da76aa2b..618f8385 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -36,15 +36,15 @@ class xmlrpc(Backend): Kerberos backend plugin. """ - def get_client(self): + def get_client(self, verbose=False): # FIXME: The server uri should come from self.api.env.server_uri - return xmlrpclib.ServerProxy('http://localhost:8888', allow_none=True) + return xmlrpclib.ServerProxy('http://localhost:8888', verbose=verbose) def forward_call(self, name, *args, **kw): """ Forward a call over XML-RPC to an IPA server. """ - client = self.get_client() + client = self.get_client(verbose=api.env.get('verbose', False)) command = getattr(client, name) params = xmlrpc_marshal(*args, **kw) try: -- cgit From cfc8450efd92dc0fb6648e97b27416c67625adfb Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Tue, 14 Oct 2008 22:22:01 -0400 Subject: Port user-show to new CrudBackend framework --- ipalib/plugins/b_xmlrpc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index 618f8385..db2af1ab 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -58,6 +58,6 @@ class xmlrpc(Backend): print "%s: %s" % (code, getattr(err,'__doc__','')) else: raise err - return False + return {} api.register(xmlrpc) -- cgit From b045f220692e016a105f03af025d49f9a9cddc74 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Thu, 16 Oct 2008 23:33:44 -0400 Subject: Add mod_python-based XML-RPC server. Use -e kerberos on the command-line to use the mod_python server, otherwise it defaults to use the simple-server URL. --- ipalib/plugins/b_xmlrpc.py | 47 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index db2af1ab..9fe5b133 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -1,5 +1,6 @@ # Authors: # Jason Gerard DeRose +# Rob Crittenden # # Copyright (C) 2008 Red Hat # see file 'COPYING' for use and warranty information @@ -26,6 +27,8 @@ This provides a lightwieght XML-RPC client using Python standard library import xmlrpclib import socket +import httplib +import kerberos from ipalib.backend import Backend from ipalib.util import xmlrpc_marshal from ipalib import api @@ -38,7 +41,12 @@ class xmlrpc(Backend): def get_client(self, verbose=False): # FIXME: The server uri should come from self.api.env.server_uri - return xmlrpclib.ServerProxy('http://localhost:8888', verbose=verbose) + if api.env.get('kerberos'): + server = api.env.server.next() + if verbose: print "Connecting to %s" % server + return xmlrpclib.ServerProxy('https://%s/ipa/xml' % server, transport=KerbTransport(), verbose=verbose) + else: + return xmlrpclib.ServerProxy('http://localhost:8888', verbose=verbose) def forward_call(self, name, *args, **kw): """ @@ -54,10 +62,41 @@ class xmlrpc(Backend): except xmlrpclib.Fault, e: err = errors.convertFault(e) code = getattr(err,'faultCode',None) - if code: - print "%s: %s" % (code, getattr(err,'__doc__','')) - else: + faultString = getattr(err,'faultString',None) + if not code: raise err + if code < errors.IPA_ERROR_BASE: + print "%s: %s" % (code, faultString) + else: + print "%s: %s" % (code, getattr(err,'__doc__','')) return {} api.register(xmlrpc) + +class KerbTransport(xmlrpclib.SafeTransport): + """Handles Kerberos Negotiation authentication to an XML-RPC server.""" + + def get_host_info(self, host): + + host, extra_headers, x509 = xmlrpclib.Transport.get_host_info(self, host) + + # Set the remote host principal + h = host + hostinfo = h.split(':') + service = "HTTP@" + hostinfo[0] + + try: + rc, vc = kerberos.authGSSClientInit(service); + except kerberos.GSSError, e: + raise kerberos.GSSError(e) + + try: + kerberos.authGSSClientStep(vc, ""); + except kerberos.GSSError, e: + raise kerberos.GSSError(e) + + extra_headers = [ + ("Authorization", "negotiate %s" % kerberos.authGSSClientResponse(vc) ) + ] + + return host, extra_headers, x509 -- cgit From 1daf319a19f902d7c7bef37af065cac81be9189e Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Wed, 22 Oct 2008 17:54:04 -0400 Subject: Implement the host commands In order for this to work against a v1 database the update host.update needs to be applied --- ipalib/plugins/b_xmlrpc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index 9fe5b133..572a7511 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -69,7 +69,7 @@ class xmlrpc(Backend): print "%s: %s" % (code, faultString) else: print "%s: %s" % (code, getattr(err,'__doc__','')) - return {} + return api.register(xmlrpc) -- cgit From 2307d4ddd0409f00511c4d83ad7dab5e9d6d96df Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 27 Oct 2008 23:56:22 -0600 Subject: Fixed use of depreciated env.get() in b_xmlrpc.py module --- ipalib/plugins/b_xmlrpc.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index 572a7511..2c98fb8a 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -36,23 +36,26 @@ from ipalib import errors class xmlrpc(Backend): """ - Kerberos backend plugin. + XML-RPC client backend plugin. """ - def get_client(self, verbose=False): - # FIXME: The server uri should come from self.api.env.server_uri - if api.env.get('kerberos'): - server = api.env.server.next() - if verbose: print "Connecting to %s" % server - return xmlrpclib.ServerProxy('https://%s/ipa/xml' % server, transport=KerbTransport(), verbose=verbose) - else: - return xmlrpclib.ServerProxy('http://localhost:8888', verbose=verbose) + def get_client(self): + """ + Return an xmlrpclib.ServerProxy instance (the client). + """ + uri = self.api.env.xmlrpc_uri + if uri.startswith('https://'): + return xmlrpclib.ServerProxy(uri, + transport=KerbTransport(), + verbose=self.api.env.verbose, + ) + return xmlrpclib.ServerProxy(uri, verbose=self.api.env.verbose) def forward_call(self, name, *args, **kw): """ Forward a call over XML-RPC to an IPA server. """ - client = self.get_client(verbose=api.env.get('verbose', False)) + client = self.get_client() command = getattr(client, name) params = xmlrpc_marshal(*args, **kw) try: -- cgit From d53218a9321eb4def0bfeb484709323de74eef1a Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Mon, 3 Nov 2008 17:19:29 -0500 Subject: Handle exceptions in the command-line instead of in the XMLRPC client plugin --- ipalib/plugins/b_xmlrpc.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index 2c98fb8a..9c6af0a0 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -64,14 +64,7 @@ class xmlrpc(Backend): print e[1] except xmlrpclib.Fault, e: err = errors.convertFault(e) - code = getattr(err,'faultCode',None) - faultString = getattr(err,'faultString',None) - if not code: - raise err - if code < errors.IPA_ERROR_BASE: - print "%s: %s" % (code, faultString) - else: - print "%s: %s" % (code, getattr(err,'__doc__','')) + raise err return api.register(xmlrpc) -- cgit From f1314806434b9226f8a7722675b060bdf574c455 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Mon, 3 Nov 2008 17:38:05 -0500 Subject: Move socket errors from the XML-RPC plugin to the client --- ipalib/plugins/b_xmlrpc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index 9c6af0a0..87dc9505 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -61,7 +61,7 @@ class xmlrpc(Backend): try: return command(*params) except socket.error, e: - print e[1] + raise except xmlrpclib.Fault, e: err = errors.convertFault(e) raise err -- cgit From 09161e399a61e2a548e9efb3c3abb2c7b47d5520 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 12 Nov 2008 01:47:37 -0700 Subject: Command.get_default() will now fill-in None for all missing non-required params --- ipalib/plugins/b_xmlrpc.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index 87dc9505..22361b1b 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -43,6 +43,10 @@ class xmlrpc(Backend): """ Return an xmlrpclib.ServerProxy instance (the client). """ + # FIXME: Rob, is there any reason we can't use allow_none=True here? + # Are there any reasonably common XML-RPC client implementations + # that don't support the extension? + # See: http://docs.python.org/library/xmlrpclib.html uri = self.api.env.xmlrpc_uri if uri.startswith('https://'): return xmlrpclib.ServerProxy(uri, -- cgit From 2db738e8996528502293b8cc6861efedcba22c9a Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 24 Nov 2008 10:09:30 -0700 Subject: Some changes to make reading dubugging output easier --- ipalib/plugins/b_xmlrpc.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index 22361b1b..b6e113a5 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -51,14 +51,15 @@ class xmlrpc(Backend): if uri.startswith('https://'): return xmlrpclib.ServerProxy(uri, transport=KerbTransport(), - verbose=self.api.env.verbose, + #verbose=self.api.env.verbose, ) - return xmlrpclib.ServerProxy(uri, verbose=self.api.env.verbose) + return xmlrpclib.ServerProxy(uri) def forward_call(self, name, *args, **kw): """ Forward a call over XML-RPC to an IPA server. """ + self.info('Forwarding %r call to %r' % (name, self.env.xmlrpc_uri)) client = self.get_client() command = getattr(client, name) params = xmlrpc_marshal(*args, **kw) -- cgit From 237c16f0fd3998f4a2e69d9096997d10af2cf8c9 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 24 Nov 2008 12:51:03 -0700 Subject: Started moving xmlrpc-functions from ipalib.util to ipalib.rpc --- ipalib/plugins/b_xmlrpc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ipalib/plugins/b_xmlrpc.py') diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index b6e113a5..14f2a9be 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -47,11 +47,10 @@ class xmlrpc(Backend): # Are there any reasonably common XML-RPC client implementations # that don't support the extension? # See: http://docs.python.org/library/xmlrpclib.html - uri = self.api.env.xmlrpc_uri + uri = self.env.xmlrpc_uri if uri.startswith('https://'): return xmlrpclib.ServerProxy(uri, transport=KerbTransport(), - #verbose=self.api.env.verbose, ) return xmlrpclib.ServerProxy(uri) -- cgit