0000-12-31 18:09:24 -05:50
|
|
|
# Authors: Rob Crittenden <rcritten@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 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
|
2008-02-04 14:15:52 -06:00
|
|
|
# published by the Free Software Foundation; version 2 only
|
0000-12-31 18:09:24 -05:50
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
|
|
|
import xmlrpclib
|
|
|
|
import socket
|
0000-12-31 18:09:24 -05:50
|
|
|
import config
|
2008-02-22 13:47:15 -06:00
|
|
|
import errno
|
2007-08-06 09:05:53 -05:00
|
|
|
from krbtransport import KerbTransport
|
|
|
|
from kerberos import GSSError
|
0000-12-31 18:09:24 -05:50
|
|
|
from ipa import ipaerror, ipautil
|
2007-12-11 16:34:15 -06:00
|
|
|
from ipa import config
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
# Some errors to catch
|
|
|
|
# http://cvs.fedora.redhat.com/viewcvs/ldapserver/ldap/servers/plugins/pam_passthru/README?root=dirsec&rev=1.6&view=auto
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2007-08-06 09:05:53 -05:00
|
|
|
class RPCClient:
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-04-24 09:25:30 -05:00
|
|
|
def __init__(self, verbose=False):
|
2008-02-22 13:47:15 -06:00
|
|
|
self.server = None
|
2008-04-24 09:25:30 -05:00
|
|
|
self.verbose = verbose
|
2007-12-11 16:34:15 -06:00
|
|
|
config.init_config()
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-02-22 13:47:15 -06:00
|
|
|
def server_url(self, server):
|
2007-08-17 09:03:33 -05:00
|
|
|
"""Build the XML-RPC server URL from our configuration"""
|
2008-05-07 08:33:00 -05:00
|
|
|
url = "https://" + server + "/ipa/xml"
|
2008-04-24 09:25:30 -05:00
|
|
|
if self.verbose:
|
|
|
|
print "Connecting to IPA server: %s" % url
|
|
|
|
return url
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2007-08-06 09:05:53 -05:00
|
|
|
def setup_server(self):
|
2007-08-17 09:03:33 -05:00
|
|
|
"""Create our XML-RPC server connection using kerberos
|
|
|
|
authentication"""
|
2008-02-22 13:47:15 -06:00
|
|
|
if not self.server:
|
|
|
|
serverlist = config.config.get_server()
|
|
|
|
|
|
|
|
# Try each server until we succeed or run out of servers to try
|
|
|
|
# Guaranteed by ipa.config to have at least 1 in the list
|
|
|
|
for s in serverlist:
|
|
|
|
try:
|
|
|
|
self.server = s
|
|
|
|
remote = xmlrpclib.ServerProxy(self.server_url(s), KerbTransport())
|
|
|
|
result = remote.ping()
|
|
|
|
break
|
|
|
|
except socket.error, e:
|
|
|
|
if (e[0] == errno.ECONNREFUSED) or (e[0] == errno.ECONNREFUSED) or (e[0] == errno.EHOSTDOWN) or (e[0] == errno.EHOSTUNREACH):
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
raise e
|
2008-09-09 08:49:28 -05:00
|
|
|
except GSSError:
|
|
|
|
continue
|
2008-02-22 13:47:15 -06:00
|
|
|
|
2008-04-24 09:25:30 -05:00
|
|
|
return xmlrpclib.ServerProxy(self.server_url(self.server), KerbTransport(), verbose=self.verbose)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2007-10-12 17:11:55 -05:00
|
|
|
# Higher-level API
|
|
|
|
|
|
|
|
def get_aci_entry(self, sattrs=None):
|
|
|
|
"""Returns the entry containing access control ACIs."""
|
|
|
|
server = self.setup_server()
|
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
|
|
|
try:
|
|
|
|
result = server.get_aci_entry(sattrs)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
|
|
|
|
2007-10-09 11:26:16 -05:00
|
|
|
# General searches
|
|
|
|
|
|
|
|
def get_entry_by_dn(self,dn,sattrs=None):
|
|
|
|
"""Get a specific entry. If sattrs is not None then only those
|
2007-08-24 14:42:56 -05:00
|
|
|
attributes will be returned, otherwise all available
|
|
|
|
attributes are returned. The result is a dict."""
|
2007-08-06 09:05:53 -05:00
|
|
|
server = self.setup_server()
|
2007-08-23 08:44:00 -05:00
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
2007-08-06 09:05:53 -05:00
|
|
|
try:
|
2007-10-09 11:26:16 -05:00
|
|
|
result = server.get_entry_by_dn(dn, sattrs)
|
2007-08-23 08:44:00 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-10-09 11:26:16 -05:00
|
|
|
|
|
|
|
def get_entry_by_cn(self,cn,sattrs=None):
|
|
|
|
"""Get a specific entry by cn. If sattrs is not None then only those
|
|
|
|
attributes will be returned, otherwise all available
|
|
|
|
attributes are returned. The result is a dict."""
|
|
|
|
server = self.setup_server()
|
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
|
|
|
try:
|
|
|
|
result = server.get_entry_by_cn(cn, sattrs)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-10-15 11:04:13 -05:00
|
|
|
def update_entry(self,oldentry,newentry):
|
|
|
|
"""Update an existing entry. oldentry and newentry are dicts of attributes"""
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = server.update_entry(ipautil.wrap_binary_data(oldentry),
|
|
|
|
ipautil.wrap_binary_data(newentry))
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-10-09 11:26:16 -05:00
|
|
|
|
|
|
|
# User support
|
|
|
|
|
|
|
|
def get_user_by_uid(self,uid,sattrs=None):
|
2007-08-23 08:44:00 -05:00
|
|
|
"""Get a specific user. If sattrs is not None then only those
|
2007-08-24 14:42:56 -05:00
|
|
|
attributes will be returned, otherwise all available
|
|
|
|
attributes are returned. The result is a dict."""
|
2007-08-23 08:44:00 -05:00
|
|
|
server = self.setup_server()
|
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
|
|
|
try:
|
2007-10-09 11:26:16 -05:00
|
|
|
result = server.get_user_by_uid(uid, sattrs)
|
2007-08-06 09:05:53 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
2007-08-22 12:30:51 -05:00
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
2007-08-06 09:05:53 -05:00
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-08-14 16:22:05 -05:00
|
|
|
|
2007-10-01 16:33:16 -05:00
|
|
|
def get_user_by_principal(self,principal,sattrs=None):
|
|
|
|
"""Get a specific user. If sattrs is not None then only those
|
|
|
|
attributes will be returned, otherwise all available
|
|
|
|
attributes are returned. The result is a dict."""
|
|
|
|
server = self.setup_server()
|
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
|
|
|
try:
|
|
|
|
result = server.get_user_by_principal(principal, sattrs)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-10-18 16:33:55 -05:00
|
|
|
|
|
|
|
def get_user_by_email(self,email,sattrs=None):
|
|
|
|
"""Get a specific user's entry. Return as a dict of values.
|
2007-12-11 16:34:15 -06:00
|
|
|
Multi-valued fields are represented as lists. The result is a
|
|
|
|
dict.
|
2007-10-18 16:33:55 -05:00
|
|
|
"""
|
|
|
|
server = self.setup_server()
|
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
|
|
|
try:
|
|
|
|
result = server.get_user_by_email(email, sattrs)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-09-25 17:44:49 -05:00
|
|
|
def get_users_by_manager(self,manager_dn,sattrs=None):
|
|
|
|
"""Gets the users that report to a manager.
|
|
|
|
If sattrs is not None then only those
|
|
|
|
attributes will be returned, otherwise all available
|
|
|
|
attributes are returned. The result is a list of dicts."""
|
|
|
|
server = self.setup_server()
|
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
|
|
|
try:
|
|
|
|
result = server.get_users_by_manager(manager_dn, sattrs)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-08-23 08:44:00 -05:00
|
|
|
def add_user(self,user,user_container=None):
|
2007-08-17 09:03:33 -05:00
|
|
|
"""Add a new user. Takes as input a dict where the key is the
|
|
|
|
attribute name and the value is either a string or in the case
|
|
|
|
of a multi-valued field a list of values"""
|
2007-08-06 09:05:53 -05:00
|
|
|
server = self.setup_server()
|
2007-08-23 08:44:00 -05:00
|
|
|
|
|
|
|
if user_container is None:
|
|
|
|
user_container = "__NONE__"
|
2007-08-06 09:05:53 -05:00
|
|
|
|
|
|
|
try:
|
0000-12-31 18:09:24 -05:50
|
|
|
result = server.add_user(ipautil.wrap_binary_data(user),
|
|
|
|
user_container)
|
2007-08-06 09:05:53 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
2007-08-22 12:30:51 -05:00
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
2007-08-06 09:05:53 -05:00
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-08-06 09:05:53 -05:00
|
|
|
|
2007-11-16 11:59:32 -06:00
|
|
|
def get_custom_fields(self):
|
|
|
|
"""Get custom user fields."""
|
2007-08-06 09:05:53 -05:00
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
2007-11-16 11:59:32 -06:00
|
|
|
result = server.get_custom_fields()
|
2007-08-06 09:05:53 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
2007-08-22 12:30:51 -05:00
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
2007-08-06 09:05:53 -05:00
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-11-16 11:59:32 -06:00
|
|
|
|
|
|
|
def set_custom_fields(self, schema):
|
|
|
|
"""Set custom user fields."""
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = server.set_custom_fields(schema)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-08-06 09:05:53 -05:00
|
|
|
def get_all_users (self):
|
2007-12-11 16:34:15 -06:00
|
|
|
"""Return a list containing a dict for each existing user."""
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2007-08-06 09:05:53 -05:00
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
|
|
|
result = server.get_all_users()
|
|
|
|
except xmlrpclib.Fault, fault:
|
2007-08-22 12:30:51 -05:00
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
2007-08-06 09:05:53 -05:00
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-08-13 15:41:38 -05:00
|
|
|
|
2008-04-25 12:33:01 -05:00
|
|
|
def find_users (self, criteria, sattrs=None, sizelimit=-1, timelimit=-1):
|
2007-12-11 16:34:15 -06:00
|
|
|
"""Return a list: counter followed by a dict for each user that
|
2007-08-28 18:01:07 -05:00
|
|
|
matches the criteria. If the results are truncated, counter will
|
|
|
|
be set to -1"""
|
2007-08-13 15:41:38 -05:00
|
|
|
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
2007-08-23 08:44:00 -05:00
|
|
|
# None values are not allowed in XML-RPC
|
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
2008-04-25 12:33:01 -05:00
|
|
|
result = server.find_users(criteria, sattrs, sizelimit, timelimit)
|
2007-08-13 15:41:38 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
2007-08-22 12:30:51 -05:00
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
2007-08-13 15:41:38 -05:00
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-08-14 16:22:05 -05:00
|
|
|
|
|
|
|
def update_user(self,olduser,newuser):
|
|
|
|
"""Update an existing user. olduser and newuser are dicts of attributes"""
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
0000-12-31 18:09:24 -05:50
|
|
|
result = server.update_user(ipautil.wrap_binary_data(olduser),
|
|
|
|
ipautil.wrap_binary_data(newuser))
|
2007-08-14 16:22:05 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
2007-08-22 12:30:51 -05:00
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
2007-08-14 16:22:05 -05:00
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-08-17 09:03:33 -05:00
|
|
|
|
2007-08-28 12:52:08 -05:00
|
|
|
def delete_user(self,uid):
|
|
|
|
"""Delete a user. uid is the uid of the user to delete."""
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = server.delete_user(uid)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2007-10-01 16:33:16 -05:00
|
|
|
def modifyPassword(self,principal,oldpass,newpass):
|
2007-09-11 01:48:53 -05:00
|
|
|
"""Modify a user's password"""
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
if oldpass is None:
|
|
|
|
oldpass = "__NONE__"
|
|
|
|
|
|
|
|
try:
|
2007-10-01 16:33:16 -05:00
|
|
|
result = server.modifyPassword(principal,oldpass,newpass)
|
2007-09-11 01:48:53 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2007-11-20 21:45:29 -06:00
|
|
|
def mark_user_active(self,uid):
|
|
|
|
"""Mark a user as active"""
|
2007-08-17 09:03:33 -05:00
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
2007-11-20 21:45:29 -06:00
|
|
|
result = server.mark_user_active(uid)
|
2007-08-17 09:03:33 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
2007-08-22 12:30:51 -05:00
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
2007-08-17 09:03:33 -05:00
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-08-24 14:42:56 -05:00
|
|
|
|
2007-11-20 21:45:29 -06:00
|
|
|
def mark_user_inactive(self,uid):
|
|
|
|
"""Mark a user as inactive"""
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = server.mark_user_inactive(uid)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
|
|
|
|
2007-08-24 14:42:56 -05:00
|
|
|
# Group support
|
|
|
|
|
2007-09-25 15:35:43 -05:00
|
|
|
def get_groups_by_member(self,member_dn,sattrs=None):
|
|
|
|
"""Gets the groups that member_dn belongs to.
|
|
|
|
If sattrs is not None then only those
|
|
|
|
attributes will be returned, otherwise all available
|
|
|
|
attributes are returned. The result is a list of dicts."""
|
|
|
|
server = self.setup_server()
|
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
|
|
|
try:
|
|
|
|
result = server.get_groups_by_member(member_dn, sattrs)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-08-24 14:42:56 -05:00
|
|
|
def add_group(self,group,group_container=None):
|
|
|
|
"""Add a new group. Takes as input a dict where the key is the
|
|
|
|
attribute name and the value is either a string or in the case
|
|
|
|
of a multi-valued field a list of values"""
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
if group_container is None:
|
|
|
|
group_container = "__NONE__"
|
|
|
|
|
|
|
|
try:
|
0000-12-31 18:09:24 -05:50
|
|
|
result = server.add_group(ipautil.wrap_binary_data(group),
|
|
|
|
group_container)
|
2007-08-24 14:42:56 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
2007-12-11 16:34:15 -06:00
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2008-04-25 12:33:01 -05:00
|
|
|
def find_groups (self, criteria, sattrs=None, sizelimit=-1, timelimit=-1):
|
2007-08-24 14:42:56 -05:00
|
|
|
"""Return a list containing a Group object for each group that matches
|
|
|
|
the criteria."""
|
|
|
|
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
|
|
|
# None values are not allowed in XML-RPC
|
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
2008-04-25 12:33:01 -05:00
|
|
|
result = server.find_groups(criteria, sattrs, sizelimit, timelimit)
|
2007-08-24 14:42:56 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-08-24 14:42:56 -05:00
|
|
|
|
2007-10-03 20:21:41 -05:00
|
|
|
def add_member_to_group(self, member_dn, group_dn):
|
2007-09-26 17:47:34 -05:00
|
|
|
"""Add a new member to an existing group.
|
|
|
|
"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
2007-10-03 20:21:41 -05:00
|
|
|
result = server.add_member_to_group(member_dn, group_dn)
|
2007-09-26 17:47:34 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-10-03 20:21:41 -05:00
|
|
|
def add_members_to_group(self, member_dns, group_dn):
|
2007-09-26 17:47:34 -05:00
|
|
|
"""Add several members to an existing group.
|
|
|
|
member_dns is a list of the dns to add
|
|
|
|
|
|
|
|
Returns a list of the dns that were not added.
|
|
|
|
"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
2007-10-03 20:21:41 -05:00
|
|
|
result = server.add_members_to_group(member_dns, group_dn)
|
2007-09-26 17:47:34 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-10-03 20:21:41 -05:00
|
|
|
def remove_member_from_group(self, member_dn, group_dn):
|
2007-09-26 17:47:34 -05:00
|
|
|
"""Remove a member from an existing group.
|
|
|
|
"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
2007-10-03 20:21:41 -05:00
|
|
|
result = server.remove_member_from_group(member_dn, group_dn)
|
2007-09-26 17:47:34 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-10-03 20:21:41 -05:00
|
|
|
def remove_members_from_group(self, member_dns, group_dn):
|
2007-09-26 17:47:34 -05:00
|
|
|
"""Remove several members from an existing group.
|
|
|
|
|
|
|
|
Returns a list of the dns that were not removed.
|
|
|
|
"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
2007-10-03 20:21:41 -05:00
|
|
|
result = server.remove_members_from_group(member_dns, group_dn)
|
2007-09-26 17:47:34 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-10-03 20:21:41 -05:00
|
|
|
def add_user_to_group(self, user_uid, group_dn):
|
2007-08-24 14:42:56 -05:00
|
|
|
"""Add a user to an existing group.
|
|
|
|
"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
2007-10-03 20:21:41 -05:00
|
|
|
result = server.add_user_to_group(user_uid, group_dn)
|
2007-08-24 14:42:56 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
2007-09-26 17:47:34 -05:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-08-24 14:42:56 -05:00
|
|
|
|
2007-10-03 20:21:41 -05:00
|
|
|
def add_users_to_group(self, user_uids, group_dn):
|
2007-08-24 14:42:56 -05:00
|
|
|
"""Add several users to an existing group.
|
2007-09-26 17:47:34 -05:00
|
|
|
user_uids is a list of the uids of the users to add
|
2007-08-24 14:42:56 -05:00
|
|
|
|
2007-09-26 17:47:34 -05:00
|
|
|
Returns a list of the user uids that were not added.
|
2007-08-24 14:42:56 -05:00
|
|
|
"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
2007-10-03 20:21:41 -05:00
|
|
|
result = server.add_users_to_group(user_uids, group_dn)
|
2007-08-24 14:42:56 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
2007-09-26 17:47:34 -05:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-08-24 14:42:56 -05:00
|
|
|
|
2007-10-03 20:21:41 -05:00
|
|
|
def remove_user_from_group(self, user_uid, group_dn):
|
2007-08-24 14:42:56 -05:00
|
|
|
"""Remove a user from an existing group.
|
|
|
|
"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
2007-10-03 20:21:41 -05:00
|
|
|
result = server.remove_user_from_group(user_uid, group_dn)
|
2007-08-24 14:42:56 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-08-24 14:42:56 -05:00
|
|
|
|
2007-10-03 20:21:41 -05:00
|
|
|
def remove_users_from_group(self, user_uids, group_dn):
|
2007-08-24 14:42:56 -05:00
|
|
|
"""Remove several users from an existing group.
|
2007-09-26 17:47:34 -05:00
|
|
|
user_uids is a list of the uids of the users to remove
|
2007-08-24 14:42:56 -05:00
|
|
|
|
2007-09-26 17:47:34 -05:00
|
|
|
Returns a list of the user uids that were not removed.
|
2007-08-24 14:42:56 -05:00
|
|
|
"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
2007-10-03 20:21:41 -05:00
|
|
|
result = server.remove_users_from_group(user_uids, group_dn)
|
2007-08-24 14:42:56 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-08-24 14:42:56 -05:00
|
|
|
|
2007-09-28 18:01:42 -05:00
|
|
|
def add_groups_to_user(self, group_dns, user_dn):
|
|
|
|
"""Given a list of group dn's add them to the user.
|
|
|
|
|
|
|
|
Returns a list of the group dns that were not added.
|
|
|
|
"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
|
|
|
result = server.add_groups_to_user(group_dns, user_dn)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
|
|
|
def remove_groups_from_user(self, group_dns, user_dn):
|
|
|
|
"""Given a list of group dn's remove them from the user.
|
|
|
|
|
|
|
|
Returns a list of the group dns that were not removed.
|
|
|
|
"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
|
|
|
result = server.remove_groups_from_user(group_dns, user_dn)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-08-24 14:42:56 -05:00
|
|
|
def update_group(self,oldgroup,newgroup):
|
|
|
|
"""Update an existing group. oldgroup and newgroup are dicts of attributes"""
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
0000-12-31 18:09:24 -05:50
|
|
|
result = server.update_group(ipautil.wrap_binary_data(oldgroup),
|
|
|
|
ipautil.wrap_binary_data(newgroup))
|
2007-08-24 14:42:56 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-08-28 12:52:08 -05:00
|
|
|
|
2007-10-23 18:46:50 -05:00
|
|
|
def delete_group(self,group_dn):
|
|
|
|
"""Delete a group. group_dn is the dn of the group to be deleted."""
|
2007-08-28 12:52:08 -05:00
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
2007-10-23 18:46:50 -05:00
|
|
|
result = server.delete_group(group_dn)
|
2007-08-28 12:52:08 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
|
|
|
def add_group_to_group(self, group_cn, tgroup_cn):
|
|
|
|
"""Add a group to an existing group.
|
|
|
|
group_cn is a cn of the group to add
|
|
|
|
tgroup_cn is the cn of the group to be added to
|
|
|
|
"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
|
|
|
result = server.add_group_to_group(group_cn, tgroup_cn)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-10-22 16:06:52 -05:00
|
|
|
|
|
|
|
def attrs_to_labels(self,attrs):
|
|
|
|
"""Convert a list of LDAP attributes into a more readable form."""
|
|
|
|
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
|
|
|
result = server.attrs_to_labels(attrs)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-10-30 14:07:02 -05:00
|
|
|
|
2008-01-18 15:20:36 -06:00
|
|
|
def get_all_attrs(self):
|
2008-01-04 15:39:41 -06:00
|
|
|
"""We have a list of hardcoded attributes -> readable labels. Return
|
|
|
|
that complete list if someone wants it.
|
|
|
|
"""
|
|
|
|
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
|
|
|
result = server.get_all_attrs()
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2008-03-27 08:54:41 -05:00
|
|
|
def group_members(self, groupdn, attr_list=None, memberstype=0):
|
2007-10-30 14:07:02 -05:00
|
|
|
"""Do a memberOf search of groupdn and return the attributes in
|
|
|
|
attr_list (an empty list returns everything)."""
|
|
|
|
|
|
|
|
if attr_list is None:
|
|
|
|
attr_list = "__NONE__"
|
|
|
|
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
2008-03-27 08:54:41 -05:00
|
|
|
result = server.group_members(groupdn, attr_list, memberstype)
|
2007-10-30 14:07:02 -05:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-11-13 19:05:02 -06:00
|
|
|
|
2007-11-20 21:45:29 -06:00
|
|
|
def mark_group_active(self,cn):
|
|
|
|
"""Mark a group as active"""
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = server.mark_group_active(cn)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
|
|
|
def mark_group_inactive(self,cn):
|
|
|
|
"""Mark a group as inactive"""
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = server.mark_group_inactive(cn)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
|
|
|
# Configuration support
|
|
|
|
|
2007-11-16 11:59:32 -06:00
|
|
|
def get_ipa_config(self):
|
|
|
|
"""Get the IPA configuration"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
|
|
|
result = server.get_ipa_config()
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
|
|
|
def update_ipa_config(self, oldconfig, newconfig):
|
|
|
|
"""Update the IPA configuration"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
2008-08-15 12:08:29 -05:00
|
|
|
result = server.update_ipa_config(ipautil.wrap_binary_data(oldconfig), ipautil.wrap_binary_data(newconfig))
|
2007-11-16 11:59:32 -06:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
|
|
|
def get_password_policy(self):
|
|
|
|
"""Get the IPA password policy"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
|
|
|
result = server.get_password_policy()
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
|
|
|
def update_password_policy(self, oldpolicy, newpolicy):
|
|
|
|
"""Update the IPA password policy"""
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
2008-02-25 12:11:15 -06:00
|
|
|
result = server.update_password_policy(ipautil.wrap_binary_data(oldpolicy), ipautil.wrap_binary_data(newpolicy))
|
2007-11-16 11:59:32 -06:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-02-26 12:51:56 -06:00
|
|
|
def add_service_principal(self, princ_name, force):
|
0000-12-31 18:09:24 -05:50
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
2008-02-26 12:51:56 -06:00
|
|
|
result = server.add_service_principal(princ_name, force)
|
0000-12-31 18:09:24 -05:50
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2008-01-11 10:44:23 -06:00
|
|
|
def delete_service_principal(self, principal_dn):
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = server.delete_service_principal(principal_dn)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2008-04-25 12:33:01 -05:00
|
|
|
def find_service_principal (self, criteria, sattrs=None, sizelimit=-1, timelimit=-1):
|
2007-12-05 14:17:11 -06:00
|
|
|
"""Return a list: counter followed by a Entity object for each host that
|
|
|
|
matches the criteria. If the results are truncated, counter will
|
|
|
|
be set to -1"""
|
|
|
|
|
|
|
|
server = self.setup_server()
|
|
|
|
try:
|
|
|
|
# None values are not allowed in XML-RPC
|
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
2008-04-25 12:33:01 -05:00
|
|
|
result = server.find_service_principal(criteria, sattrs, sizelimit, timelimit)
|
2007-12-05 14:17:11 -06:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
def get_keytab(self, princ_name):
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = server.get_keytab(princ_name)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-11-28 06:49:07 -06:00
|
|
|
|
2007-11-13 23:04:19 -06:00
|
|
|
# radius support
|
|
|
|
|
2007-11-26 18:30:33 -06:00
|
|
|
def get_radius_client_by_ip_addr(self, ip_addr, container, sattrs=None):
|
2007-11-13 23:04:19 -06:00
|
|
|
server = self.setup_server()
|
Add radius profile implementations:
get_radius_profile_by_uid
add_radius_profile
update_radius_profile
delete_radius_profile
find_radius_profiles
Rewrite command line arg handling, now support pair entry, interactive
mode with auto completion, reading pairs from a file, better handling
of mandatory values, better help, long arg names now match attribute
name in pairs
Establish mappings for all attributes and names used in clients and
profiles
Add notion of containers to radius clients and profiles in LDAP
Move common code, variables, constants, and strings into the files
radius_client.py, radius_util.py, ipautil.py to eliminate redundant
elements which could get out of sync if modified and to provide access
to other code which might benefit from using these items in the
future.
Add utility functions:
format_list()
parse_key_value_pairs()
Add utility class:
AttributeValueCompleter
Unify attribute usage in radius ldap schema
2007-11-21 12:11:10 -06:00
|
|
|
if container is None: container = "__NONE__"
|
|
|
|
if sattrs is None: sattrs = "__NONE__"
|
2007-11-13 23:04:19 -06:00
|
|
|
try:
|
Add radius profile implementations:
get_radius_profile_by_uid
add_radius_profile
update_radius_profile
delete_radius_profile
find_radius_profiles
Rewrite command line arg handling, now support pair entry, interactive
mode with auto completion, reading pairs from a file, better handling
of mandatory values, better help, long arg names now match attribute
name in pairs
Establish mappings for all attributes and names used in clients and
profiles
Add notion of containers to radius clients and profiles in LDAP
Move common code, variables, constants, and strings into the files
radius_client.py, radius_util.py, ipautil.py to eliminate redundant
elements which could get out of sync if modified and to provide access
to other code which might benefit from using these items in the
future.
Add utility functions:
format_list()
parse_key_value_pairs()
Add utility class:
AttributeValueCompleter
Unify attribute usage in radius ldap schema
2007-11-21 12:11:10 -06:00
|
|
|
result = server.get_radius_client_by_ip_addr(ip_addr, container, sattrs)
|
2007-11-13 23:04:19 -06:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-11-26 18:30:33 -06:00
|
|
|
def add_radius_client(self, client, container=None):
|
2007-11-13 19:05:02 -06:00
|
|
|
server = self.setup_server()
|
|
|
|
|
Add radius profile implementations:
get_radius_profile_by_uid
add_radius_profile
update_radius_profile
delete_radius_profile
find_radius_profiles
Rewrite command line arg handling, now support pair entry, interactive
mode with auto completion, reading pairs from a file, better handling
of mandatory values, better help, long arg names now match attribute
name in pairs
Establish mappings for all attributes and names used in clients and
profiles
Add notion of containers to radius clients and profiles in LDAP
Move common code, variables, constants, and strings into the files
radius_client.py, radius_util.py, ipautil.py to eliminate redundant
elements which could get out of sync if modified and to provide access
to other code which might benefit from using these items in the
future.
Add utility functions:
format_list()
parse_key_value_pairs()
Add utility class:
AttributeValueCompleter
Unify attribute usage in radius ldap schema
2007-11-21 12:11:10 -06:00
|
|
|
if container is None: container = "__NONE__"
|
|
|
|
|
2007-11-13 19:05:02 -06:00
|
|
|
try:
|
Add radius profile implementations:
get_radius_profile_by_uid
add_radius_profile
update_radius_profile
delete_radius_profile
find_radius_profiles
Rewrite command line arg handling, now support pair entry, interactive
mode with auto completion, reading pairs from a file, better handling
of mandatory values, better help, long arg names now match attribute
name in pairs
Establish mappings for all attributes and names used in clients and
profiles
Add notion of containers to radius clients and profiles in LDAP
Move common code, variables, constants, and strings into the files
radius_client.py, radius_util.py, ipautil.py to eliminate redundant
elements which could get out of sync if modified and to provide access
to other code which might benefit from using these items in the
future.
Add utility functions:
format_list()
parse_key_value_pairs()
Add utility class:
AttributeValueCompleter
Unify attribute usage in radius ldap schema
2007-11-21 12:11:10 -06:00
|
|
|
result = server.add_radius_client(ipautil.wrap_binary_data(client), container)
|
2007-11-13 19:05:02 -06:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
2007-11-13 23:04:19 -06:00
|
|
|
|
2007-11-26 18:30:33 -06:00
|
|
|
def update_radius_client(self, oldclient, newclient):
|
2007-11-13 23:04:19 -06:00
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = server.update_radius_client(ipautil.wrap_binary_data(oldclient),
|
|
|
|
ipautil.wrap_binary_data(newclient))
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-11-13 19:05:02 -06:00
|
|
|
|
2007-11-26 18:30:33 -06:00
|
|
|
def delete_radius_client(self, ip_addr, container=None):
|
2007-11-13 23:04:19 -06:00
|
|
|
server = self.setup_server()
|
Add radius profile implementations:
get_radius_profile_by_uid
add_radius_profile
update_radius_profile
delete_radius_profile
find_radius_profiles
Rewrite command line arg handling, now support pair entry, interactive
mode with auto completion, reading pairs from a file, better handling
of mandatory values, better help, long arg names now match attribute
name in pairs
Establish mappings for all attributes and names used in clients and
profiles
Add notion of containers to radius clients and profiles in LDAP
Move common code, variables, constants, and strings into the files
radius_client.py, radius_util.py, ipautil.py to eliminate redundant
elements which could get out of sync if modified and to provide access
to other code which might benefit from using these items in the
future.
Add utility functions:
format_list()
parse_key_value_pairs()
Add utility class:
AttributeValueCompleter
Unify attribute usage in radius ldap schema
2007-11-21 12:11:10 -06:00
|
|
|
if container is None: container = "__NONE__"
|
2007-11-13 23:04:19 -06:00
|
|
|
|
|
|
|
try:
|
Add radius profile implementations:
get_radius_profile_by_uid
add_radius_profile
update_radius_profile
delete_radius_profile
find_radius_profiles
Rewrite command line arg handling, now support pair entry, interactive
mode with auto completion, reading pairs from a file, better handling
of mandatory values, better help, long arg names now match attribute
name in pairs
Establish mappings for all attributes and names used in clients and
profiles
Add notion of containers to radius clients and profiles in LDAP
Move common code, variables, constants, and strings into the files
radius_client.py, radius_util.py, ipautil.py to eliminate redundant
elements which could get out of sync if modified and to provide access
to other code which might benefit from using these items in the
future.
Add utility functions:
format_list()
parse_key_value_pairs()
Add utility class:
AttributeValueCompleter
Unify attribute usage in radius ldap schema
2007-11-21 12:11:10 -06:00
|
|
|
result = server.delete_radius_client(ip_addr, container)
|
2007-11-13 23:04:19 -06:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2008-04-25 12:33:01 -05:00
|
|
|
def find_radius_clients(self, criteria, container=None, sattrs=None, sizelimit=-1, timelimit=-1):
|
2007-11-14 14:32:08 -06:00
|
|
|
server = self.setup_server()
|
Add radius profile implementations:
get_radius_profile_by_uid
add_radius_profile
update_radius_profile
delete_radius_profile
find_radius_profiles
Rewrite command line arg handling, now support pair entry, interactive
mode with auto completion, reading pairs from a file, better handling
of mandatory values, better help, long arg names now match attribute
name in pairs
Establish mappings for all attributes and names used in clients and
profiles
Add notion of containers to radius clients and profiles in LDAP
Move common code, variables, constants, and strings into the files
radius_client.py, radius_util.py, ipautil.py to eliminate redundant
elements which could get out of sync if modified and to provide access
to other code which might benefit from using these items in the
future.
Add utility functions:
format_list()
parse_key_value_pairs()
Add utility class:
AttributeValueCompleter
Unify attribute usage in radius ldap schema
2007-11-21 12:11:10 -06:00
|
|
|
if container is None: container = "__NONE__"
|
2007-11-14 14:32:08 -06:00
|
|
|
try:
|
|
|
|
# None values are not allowed in XML-RPC
|
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
2008-04-25 12:33:01 -05:00
|
|
|
result = server.find_radius_clients(criteria, container, sattrs, sizelimit, timelimit)
|
2007-11-14 14:32:08 -06:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2007-11-26 18:30:33 -06:00
|
|
|
def get_radius_profile_by_uid(self, ip_addr, user_profile, sattrs=None):
|
|
|
|
server = self.setup_server()
|
|
|
|
if user_profile is None: user_profile = "__NONE__"
|
|
|
|
if sattrs is None: sattrs = "__NONE__"
|
|
|
|
try:
|
|
|
|
result = server.get_radius_profile_by_uid(ip_addr, user_profile, sattrs)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
|
|
|
def add_radius_profile(self, profile, user_profile=None):
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
if user_profile is None: user_profile = "__NONE__"
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = server.add_radius_profile(ipautil.wrap_binary_data(profile), user_profile)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
|
|
|
def update_radius_profile(self, oldprofile, newprofile):
|
|
|
|
server = self.setup_server()
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = server.update_radius_profile(ipautil.wrap_binary_data(oldprofile),
|
|
|
|
ipautil.wrap_binary_data(newprofile))
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
|
|
|
|
|
|
|
def delete_radius_profile(self, ip_addr, user_profile=None):
|
|
|
|
server = self.setup_server()
|
|
|
|
if user_profile is None: user_profile = "__NONE__"
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = server.delete_radius_profile(ip_addr, user_profile)
|
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|
2008-04-25 12:33:01 -05:00
|
|
|
def find_radius_profiles(self, criteria, user_profile=None, sattrs=None, sizelimit=-1, timelimit=-1):
|
2007-11-26 18:30:33 -06:00
|
|
|
server = self.setup_server()
|
|
|
|
if user_profile is None: user_profile = "__NONE__"
|
|
|
|
try:
|
|
|
|
# None values are not allowed in XML-RPC
|
|
|
|
if sattrs is None:
|
|
|
|
sattrs = "__NONE__"
|
2008-04-25 12:33:01 -05:00
|
|
|
result = server.find_radius_profiles(criteria, user_profile, sattrs, sizelimit, timelimit)
|
2007-11-26 18:30:33 -06:00
|
|
|
except xmlrpclib.Fault, fault:
|
|
|
|
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
|
|
|
except socket.error, (value, msg):
|
|
|
|
raise xmlrpclib.Fault(value, msg)
|
|
|
|
|
|
|
|
return ipautil.unwrap_binary_data(result)
|
|
|
|
|