mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
clean up attribute names
clean up command line args in ipa-delradiusclient
This commit is contained in:
@@ -36,8 +36,8 @@ import ldap
|
|||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
attrs = radius_util.client_name_to_ldap_attr.keys()
|
radius_attrs = radius_util.radius_client_attr_to_ldap_attr.keys()
|
||||||
mandatory_attrs = ['Client-IP-Address', 'Secret']
|
mandatory_radius_attrs = ['Client-IP-Address', 'Secret']
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -45,10 +45,10 @@ def help_option_callback(option, opt_str, value, parser, *args, **kwargs):
|
|||||||
parser.print_help()
|
parser.print_help()
|
||||||
print
|
print
|
||||||
print "Valid interative attributes are:"
|
print "Valid interative attributes are:"
|
||||||
print ipautil.format_list(attrs, quote='"')
|
print ipautil.format_list(radius_attrs, quote='"')
|
||||||
print
|
print
|
||||||
print "Required attributes are:"
|
print "Required attributes are:"
|
||||||
print ipautil.format_list(mandatory_attrs, quote='"')
|
print ipautil.format_list(mandatory_radius_attrs, quote='"')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -78,11 +78,16 @@ def main():
|
|||||||
opt_parser.add_option("-v", "--verbose", dest="verbose", action='store_true',
|
opt_parser.add_option("-v", "--verbose", dest="verbose", action='store_true',
|
||||||
help="print information")
|
help="print information")
|
||||||
|
|
||||||
#opt_parser.set_usage("Usage: %s [options] %s" % (os.path.basename(sys.argv[0]), ' '.join(mandatory_attrs)))
|
opt_parser.set_usage("Usage: %s [options] Client-IP-Address" % (os.path.basename(sys.argv[0])))
|
||||||
|
|
||||||
args = ipa.config.init_config(sys.argv)
|
args = ipa.config.init_config(sys.argv)
|
||||||
options, args = opt_parser.parse_args(args)
|
options, args = opt_parser.parse_args(args)
|
||||||
|
|
||||||
|
if len(args) < 2:
|
||||||
|
opt_parser.error("missing Client-IP-Address")
|
||||||
|
|
||||||
|
ip_addr = args[1]
|
||||||
|
|
||||||
# Get pairs from a file or stdin
|
# Get pairs from a file or stdin
|
||||||
if options.pair_file:
|
if options.pair_file:
|
||||||
try:
|
try:
|
||||||
@@ -107,13 +112,13 @@ def main():
|
|||||||
# Get pairs interactively
|
# Get pairs interactively
|
||||||
if options.interactive:
|
if options.interactive:
|
||||||
# Remove any mandatory attriubtes which have been previously specified
|
# Remove any mandatory attriubtes which have been previously specified
|
||||||
interactive_mandatory_attrs = copy.copy(mandatory_attrs)
|
interactive_mandatory_attrs = copy.copy(mandatory_radius_attrs)
|
||||||
for attr in pairs.keys():
|
for attr in pairs.keys():
|
||||||
try:
|
try:
|
||||||
interactive_mandatory_attrs.remove(attr)
|
interactive_mandatory_attrs.remove(attr)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
c = ipautil.AttributeValueCompleter(attrs, pairs)
|
c = ipautil.AttributeValueCompleter(radius_attrs, pairs)
|
||||||
c.open()
|
c.open()
|
||||||
av = c.get_pairs("Enter: ", interactive_mandatory_attrs, validate)
|
av = c.get_pairs("Enter: ", interactive_mandatory_attrs, validate)
|
||||||
pairs.update(av)
|
pairs.update(av)
|
||||||
@@ -122,8 +127,14 @@ def main():
|
|||||||
# FIXME: validation should be moved to xmlrpc server
|
# FIXME: validation should be moved to xmlrpc server
|
||||||
|
|
||||||
# Data collection done, assure mandatory data has been specified
|
# Data collection done, assure mandatory data has been specified
|
||||||
|
|
||||||
|
if pairs.has_key('Client-IP-Address') and pairs['Client-IP-Address'] != ip_addr:
|
||||||
|
print "ERROR, Client-IP-Address specified on command line (%s) does not match value found in pairs (%s)" % \
|
||||||
|
(ip_addr, pairs['Client-IP-Address'])
|
||||||
|
return 1
|
||||||
|
|
||||||
valid = True
|
valid = True
|
||||||
for attr in mandatory_attrs:
|
for attr in mandatory_radius_attrs:
|
||||||
if not pairs.has_key(attr):
|
if not pairs.has_key(attr):
|
||||||
valid = False
|
valid = False
|
||||||
print "ERROR, %s is mandatory, but has not been specified" % (attr)
|
print "ERROR, %s is mandatory, but has not been specified" % (attr)
|
||||||
@@ -133,12 +144,12 @@ def main():
|
|||||||
# Make sure each attribute is a member of the set of valid attributes
|
# Make sure each attribute is a member of the set of valid attributes
|
||||||
valid = True
|
valid = True
|
||||||
for attr,value in pairs.items():
|
for attr,value in pairs.items():
|
||||||
if attr not in attrs:
|
if attr not in radius_attrs:
|
||||||
valid = False
|
valid = False
|
||||||
print "ERROR, %s is not a valid attribute" % (attr)
|
print "ERROR, %s is not a valid attribute" % (attr)
|
||||||
if not valid:
|
if not valid:
|
||||||
print "Valid attributes are:"
|
print "Valid attributes are:"
|
||||||
print ipautil.format_list(attrs, quote='"')
|
print ipautil.format_list(radius_attrs, quote='"')
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# Makse sure each value is valid
|
# Makse sure each value is valid
|
||||||
@@ -157,7 +168,7 @@ def main():
|
|||||||
|
|
||||||
radius_client = ipa.radius_client.RadiusClient()
|
radius_client = ipa.radius_client.RadiusClient()
|
||||||
for attr,value in pairs.items():
|
for attr,value in pairs.items():
|
||||||
radius_client.setValue(radius_util.client_name_to_ldap_attr[attr], value)
|
radius_client.setValue(radius_util.radius_client_attr_to_ldap_attr[attr], value)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ipa_client = ipaclient.IPAClient()
|
ipa_client = ipaclient.IPAClient()
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import ipa.ipaclient as ipaclient
|
|||||||
import ipa.ipavalidate as ipavalidate
|
import ipa.ipavalidate as ipavalidate
|
||||||
import ipa.config
|
import ipa.config
|
||||||
import ipa.ipaerror
|
import ipa.ipaerror
|
||||||
|
import ipa.radius_util as radius_util
|
||||||
|
|
||||||
import xmlrpclib
|
import xmlrpclib
|
||||||
import kerberos
|
import kerberos
|
||||||
@@ -33,33 +34,23 @@ import ldap
|
|||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
def parse_options():
|
def help_option_callback(option, opt_str, value, parser, *args, **kwargs):
|
||||||
parser = OptionParser()
|
parser.print_help()
|
||||||
parser.add_option("--usage", action="store_true",
|
sys.exit(0)
|
||||||
help="Program usage")
|
|
||||||
args = ipa.config.init_config(sys.argv)
|
|
||||||
options, args = parser.parse_args(args)
|
|
||||||
|
|
||||||
return options, args
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# FIXME
|
|
||||||
def usage():
|
|
||||||
print "ipa-delradiusclient ip_addr"
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
ip_addr = None
|
opt_parser = OptionParser(add_help_option=False)
|
||||||
secret = None
|
|
||||||
name = None
|
|
||||||
nastype = None
|
|
||||||
desc = None
|
|
||||||
|
|
||||||
options, args = parse_options()
|
opt_parser.add_option("-h", "--help", action="callback", callback=help_option_callback,
|
||||||
|
help="detailed help information")
|
||||||
|
opt_parser.set_usage("Usage: %s [options] Client-IP-Address" % (os.path.basename(sys.argv[0])))
|
||||||
|
|
||||||
if len(args) != 2:
|
args = ipa.config.init_config(sys.argv)
|
||||||
usage()
|
options, args = opt_parser.parse_args(args)
|
||||||
|
|
||||||
|
if len(args) < 2:
|
||||||
|
opt_parser.error("missing Client-IP-Address")
|
||||||
|
|
||||||
ip_addr = args[1]
|
ip_addr = args[1]
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import ldap
|
|||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
attrs = radius_util.client_ldap_attr_to_name.keys()
|
attrs = radius_util.radius_client_ldap_attr_to_radius_attr.keys()
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -81,10 +81,10 @@ def main():
|
|||||||
client_attrs = radius_client.attrList()
|
client_attrs = radius_client.attrList()
|
||||||
client_attrs.sort()
|
client_attrs.sort()
|
||||||
|
|
||||||
print "%s:" % radius_client.getValues(radius_util.client_name_to_ldap_attr['Client-IP-Address'])
|
print "%s:" % radius_client.getValues(radius_util.radius_client_attr_to_ldap_attr['Client-IP-Address'])
|
||||||
for attr in client_attrs:
|
for attr in client_attrs:
|
||||||
value = radius_client.getValues(attr)
|
value = radius_client.getValues(attr)
|
||||||
print "\t%s = %s" % (radius_util.client_ldap_attr_to_name[attr], value)
|
print "\t%s = %s" % (radius_util.radius_client_ldap_attr_to_radius_attr[attr], value)
|
||||||
|
|
||||||
except xmlrpclib.Fault, f:
|
except xmlrpclib.Fault, f:
|
||||||
print f.faultString
|
print f.faultString
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ import ldap
|
|||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
attrs = radius_util.client_name_to_ldap_attr.keys()
|
radius_attrs = radius_util.radius_client_attr_to_ldap_attr.keys()
|
||||||
mandatory_attrs = ['Client-IP-Address']
|
mandatory_radius_attrs = ['Client-IP-Address']
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -45,10 +45,10 @@ def help_option_callback(option, opt_str, value, parser, *args, **kwargs):
|
|||||||
parser.print_help()
|
parser.print_help()
|
||||||
print
|
print
|
||||||
print "Valid interative attributes are:"
|
print "Valid interative attributes are:"
|
||||||
print ipautil.format_list(attrs, quote='"')
|
print ipautil.format_list(radius_attrs, quote='"')
|
||||||
print
|
print
|
||||||
print "Required attributes are:"
|
print "Required attributes are:"
|
||||||
print ipautil.format_list(mandatory_attrs, quote='"')
|
print ipautil.format_list(mandatory_radius_attrs, quote='"')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -105,8 +105,8 @@ def main():
|
|||||||
|
|
||||||
# Populate the pair list with pre-existing values
|
# Populate the pair list with pre-existing values
|
||||||
prev_attrs = radius_client.attrList()
|
prev_attrs = radius_client.attrList()
|
||||||
for attr in attrs:
|
for attr in radius_attrs:
|
||||||
pairs[attr] = radius_client.getValues(radius_util.client_name_to_ldap_attr[attr])
|
pairs[attr] = radius_client.getValues(radius_util.radius_client_attr_to_ldap_attr[attr])
|
||||||
|
|
||||||
# Get pairs from a file or stdin
|
# Get pairs from a file or stdin
|
||||||
if options.pair_file:
|
if options.pair_file:
|
||||||
@@ -132,13 +132,13 @@ def main():
|
|||||||
# Get pairs interactively
|
# Get pairs interactively
|
||||||
if options.interactive:
|
if options.interactive:
|
||||||
# Remove any mandatory attriubtes which have been previously specified
|
# Remove any mandatory attriubtes which have been previously specified
|
||||||
interactive_mandatory_attrs = copy.copy(mandatory_attrs)
|
interactive_mandatory_attrs = copy.copy(mandatory_radius_attrs)
|
||||||
for attr in pairs.keys():
|
for attr in pairs.keys():
|
||||||
try:
|
try:
|
||||||
interactive_mandatory_attrs.remove(attr)
|
interactive_mandatory_attrs.remove(attr)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
c = ipautil.AttributeValueCompleter(attrs, pairs)
|
c = ipautil.AttributeValueCompleter(radius_attrs, pairs)
|
||||||
c.open()
|
c.open()
|
||||||
av = c.get_pairs("Enter: ", interactive_mandatory_attrs, validate)
|
av = c.get_pairs("Enter: ", interactive_mandatory_attrs, validate)
|
||||||
pairs.update(av)
|
pairs.update(av)
|
||||||
@@ -154,7 +154,7 @@ def main():
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
valid = True
|
valid = True
|
||||||
for attr in mandatory_attrs:
|
for attr in mandatory_radius_attrs:
|
||||||
if not pairs.has_key(attr):
|
if not pairs.has_key(attr):
|
||||||
valid = False
|
valid = False
|
||||||
print "ERROR, %s is mandatory, but has not been specified" % (attr)
|
print "ERROR, %s is mandatory, but has not been specified" % (attr)
|
||||||
@@ -164,12 +164,12 @@ def main():
|
|||||||
# Make sure each attribute is a member of the set of valid attributes
|
# Make sure each attribute is a member of the set of valid attributes
|
||||||
valid = True
|
valid = True
|
||||||
for attr,value in pairs.items():
|
for attr,value in pairs.items():
|
||||||
if attr not in attrs:
|
if attr not in radius_attrs:
|
||||||
valid = False
|
valid = False
|
||||||
print "ERROR, %s is not a valid attribute" % (attr)
|
print "ERROR, %s is not a valid attribute" % (attr)
|
||||||
if not valid:
|
if not valid:
|
||||||
print "Valid attributes are:"
|
print "Valid attributes are:"
|
||||||
print ipautil.format_list(attrs, quote='"')
|
print ipautil.format_list(radius_attrs, quote='"')
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# Makse sure each value is valid
|
# Makse sure each value is valid
|
||||||
@@ -188,7 +188,7 @@ def main():
|
|||||||
|
|
||||||
radius_client = ipa.radius_client.RadiusClient()
|
radius_client = ipa.radius_client.RadiusClient()
|
||||||
for attr,value in pairs.items():
|
for attr,value in pairs.items():
|
||||||
radius_client.setValue(radius_util.client_name_to_ldap_attr[attr], value)
|
radius_client.setValue(radius_util.radius_client_attr_to_ldap_attr[attr], value)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ipa_client.update_radius_client(radius_client)
|
ipa_client.update_radius_client(radius_client)
|
||||||
|
|||||||
@@ -47,8 +47,11 @@ __all__ = [
|
|||||||
'radius_profile_filter',
|
'radius_profile_filter',
|
||||||
'radius_profile_dn',
|
'radius_profile_dn',
|
||||||
|
|
||||||
'client_ldap_attr_to_name',
|
'radius_client_ldap_attr_to_radius_attr',
|
||||||
'client_name_to_ldap_attr',
|
'radius_client_attr_to_ldap_attr',
|
||||||
|
|
||||||
|
'radius_profile_ldap_attr_to_radius_attr',
|
||||||
|
'radius_profile_attr_to_ldap_attr',
|
||||||
|
|
||||||
'read_pairs_file',
|
'read_pairs_file',
|
||||||
]
|
]
|
||||||
@@ -82,7 +85,7 @@ def reverse_map_dict(src_dict):
|
|||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
client_ldap_attr_to_name = ipautil.CIDict({
|
radius_client_ldap_attr_to_radius_attr = ipautil.CIDict({
|
||||||
'radiusClientIPAddress' : 'Client-IP-Address',
|
'radiusClientIPAddress' : 'Client-IP-Address',
|
||||||
'radiusClientSecret' : 'Secret',
|
'radiusClientSecret' : 'Secret',
|
||||||
'radiusClientNASType' : 'NAS-Type',
|
'radiusClientNASType' : 'NAS-Type',
|
||||||
@@ -90,11 +93,11 @@ client_ldap_attr_to_name = ipautil.CIDict({
|
|||||||
'description' : 'Description',
|
'description' : 'Description',
|
||||||
})
|
})
|
||||||
|
|
||||||
client_name_to_ldap_attr = reverse_map_dict(client_ldap_attr_to_name)
|
radius_client_attr_to_ldap_attr = reverse_map_dict(radius_client_ldap_attr_to_radius_attr)
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
profile_ldap_attr_to_name = {
|
radius_profile_ldap_attr_to_radius_attr = {
|
||||||
'radiusArapFeatures' : 'Arap-Features',
|
'radiusArapFeatures' : 'Arap-Features',
|
||||||
'radiusArapSecurity' : 'Arap-Security',
|
'radiusArapSecurity' : 'Arap-Security',
|
||||||
'radiusArapZoneAccess' : 'Arap-Zone-Access',
|
'radiusArapZoneAccess' : 'Arap-Zone-Access',
|
||||||
@@ -156,7 +159,7 @@ profile_ldap_attr_to_name = {
|
|||||||
'radiusVSA' : 'VSA',
|
'radiusVSA' : 'VSA',
|
||||||
}
|
}
|
||||||
|
|
||||||
profile_name_to_ldap_attr = reverse_map_dict(profile_ldap_attr_to_name)
|
radius_profile_attr_to_ldap_attr = reverse_map_dict(radius_profile_ldap_attr_to_radius_attr)
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user