2 of the Licence, or (at your option) any later version.
"""
+from exception import AFSArgumentError
+
def get_cell(switch, params):
from afs.lib.cell import cell
return cell(params[0])
# another value for the preceding argument.
#
###############################################################################
-def parse_arguments(args, available_arguments):
+def parse_arguments(args, available_arguments, argument_size_limits,
+ cant_combine_arguments):
result = {}
need_switch = False
i = 0 # Given arguments index
if len(args) == 0:
if len(available_arguments) > 0 and available_arguments[0][0] == "r":
- raise RuntimeError("Missing required parameters")
+ raise AFSArgumentError("Missing required parameters")
return result
# Process all the optional arguments or switch-based required arguments
if args[i][0] != "-":
# Deal with positional arguments
if need_switch:
- raise RuntimeError("Need switch before argument " + i)
+ raise AFSArgumentError("Need switch before argument " + i)
if av >= len(available_arguments):
- raise RuntimeError("Unexpected positional argument")
+ raise AFSArgumentError("Unexpected positional argument")
match = available_arguments[av]
pattern = match[2]
if pattern[0] == "f":
- raise RuntimeError("Unexpected positional argument")
+ raise AFSArgumentError("Unexpected positional argument")
av = av + 1
params.append(args[i])
i = i + 1
if switch == "help":
- raise RuntimeError("Print help message")
+ raise AFSArgumentError("Print help message")
if switch == "":
- raise RuntimeError("Missing switch name")
+ raise AFSArgumentError("Missing switch name")
# Look up the switch in the table of possible arguments and flags
for j in available_arguments:
break
if j[0].startswith(switch):
if match:
- raise RuntimeError("Ambiguous switch name abbreviation '-" + switch + "'")
+ raise AFSArgumentError("Ambiguous switch name abbreviation '-" + switch + "'")
match = j
if not match:
- raise RuntimeError("Unsupported switch '-" + switch + "'")
+ raise AFSArgumentError("Unsupported switch '-" + switch + "'")
# Reject repeat flags
if match[0] in result:
- raise RuntimeError("Duplicate switch '-" + switch + "' not permitted")
+ raise AFSArgumentError("Duplicate switch '-" + switch + "' not permitted")
# Arrange the parameters associated with the switch into a list
while i < len(args):
# Check that we have the number of arguments we're expecting
pattern = match[2]
if pattern[1] == "n" and len(params) != 0:
- raise RuntimeError("Switch '-" + switch + "' expects no arguments")
+ raise AFSArgumentError("Switch '-" + switch + "' expects no arguments")
if pattern[1] == "s" and len(params) != 1:
- raise RuntimeError("Switch '-" + switch + "' expects one argument")
+ raise AFSArgumentError("Switch '-" + switch + "' expects one argument")
if pattern[1] == "m" and len(params) < 1:
- raise RuntimeError("Switch '-" + switch + "' expects one or more arguments")
+ raise AFSArgumentError("Switch '-" + switch + "' expects one or more arguments")
+
+ # Check that none of the arguments are too big
+ if match[0] in argument_size_limits:
+ limit = argument_size_limits[match[0]]
+ for j in params:
+ if len(j) > limit:
+ raise AFSArgumentError("Switch '-" + switch + "' has an overlong argument")
# Call the syntax checker
syntax = match[1]
if j[2][0] != "r":
break
if switch not in result:
- raise RuntimeError("Missing '-" + switch + "' argument")
+ raise AFSArgumentError("Missing '-" + switch + "' argument")
+
+ # Check for invalid argument combinations
+ for i in cant_combine_arguments:
+ if i[0] in params and i[1] in params:
+ raise AFSArgumentError("Can't combine -" + i[0], "with -" + i[1], file=sys.stderr)
return result
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "host" : kafs.BOZO_BSSIZE,
+}
+
description = r"""
Add a database server machine to the CellServDB file
"""
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "user" : kafs.BOZO_BSSIZE,
+}
+
description = r"""
Add a privileged user to the UserList file
"""
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "instance" : kafs.BOZO_BSSIZE,
+ "type" : kafs.BOZO_BSSIZE,
+ "cmd" : kafs.BOZO_BSSIZE,
+ "notifier" : kafs.BOZO_BSSIZE,
+}
+
description = r"""
Define a new process in the BosConfig file and start it
"""
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "instance" : kafs.BOZO_BSSIZE,
+}
+
description = r"""
Delete a server process from the BosConfig file
"""
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "file" : kafs.BOZO_BSSIZE,
+ "dir" : kafs.BOZO_BSSIZE,
+}
+
description = r"""
Display the time stamps on an AFS binary file installed on the server.
"""
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "user" : kafs.BOZO_BSSIZE,
+}
+
description = r"""
Remove a privileged user from the UserList file
"""
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "name" : kafs.BOZO_BSSIZE,
+}
+
description = r"""
Display whether a bos server is restricted or not
"""
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "instance" : kafs.BOZO_BSSIZE,
+}
+
description = r"""
Stop a process without changing its status flag
"""
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "instance" : kafs.BOZO_BSSIZE,
+}
+
description = r"""
Start a process after setting its status flag
"""
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "instance" : kafs.BOZO_BSSIZE,
+}
+
description = r"""
Start a process without changing its status flag
"""
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "instance" : kafs.BOZO_BSSIZE,
+}
+
description = r"""
Display the status of server processes
"""
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "instance" : kafs.BOZO_BSSIZE,
+}
+
description = r"""
Stop a process after changing its status flag
"""
( "noauth", "localauth" ),
]
+argument_size_limits = {
+ "id" : kafs.VLDB_MAXNAMELEN,
+}
+
description = r"""
Show volume header and VLDB entry information for a volume
"""
( "name", "locked" ),
]
+argument_size_limits = {
+ "name" : kafs.VLDB_MAXNAMELEN,
+}
+
description = r"""
Displays a volume's VLDB entry
"""
class AFSException(Exception):
"""Base class for all AFS Toolkit exceptions."""
pass
+
+class AFSArgumentError(AFSException):
+ """Base class for all AFS Toolkit exceptions."""
+ pass
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
+from exception import AFSArgumentError
+
def part2id(name):
"""Convert a partition name or number string into a numeric ID"""
if name.isnumeric():
n = int(name)
else:
if name.startswith("/vicep"):
- name = name[6:]
+ a = name[6:]
elif name.startswith("vicep"):
- name = name[5:]
-
- if len(name) == 1 and name >= "a" and name <= "z":
- n = int(name, 36) - 10
- elif (len(name) == 2 and
- name[0] >= "a" and name[0] <= "z" and
- name[1] >= "a" and name[1] <= "z"):
- n = (int(name[0], 36) - 10) * 26 + (int(name[1], 36) - 10)
+ a = name[5:]
+ else:
+ a = name
+
+ if len(a) == 1 and a >= "a" and a <= "z":
+ n = int(a, 36) - 10
+ elif (len(a) == 2 and
+ a[0] >= "a" and a[0] <= "z" and
+ a[1] >= "a" and a[1] <= "z"):
+ n = (int(a[0], 36) - 10) * 26 + (int(a[1], 36) - 10)
n += 26
else:
- raise RuntimeError("Unparseable partition ID '" + params[0] + "'")
+ raise AFSArgumentError("Unparseable partition ID '" + name + "'")
if n < 0 or n > 255:
- raise RuntimeError("Partition ID '" + params[0] + "' out of range")
+ raise AFSArgumentError("Partition ID '" + name + "' out of range")
return n
def id2part(n):
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
+from exception import AFSArgumentError
+
def uuid2str(uuid):
"""Convert an afsUUID-class object into a UUID string"""
s = "{:08x}-{:04x}-{:04x}-{:02x}-{:02x}-".format(uuid.time_low,
s[18] != "-" or
s[21] != "-" or
s[24] != "-"):
- raise RuntimeError("Invalid UUID format")
+ raise AFSArgumentError("Invalid UUID format")
from kafs import afsUUID
uuid = afsUUID()
import afs.commands
from afs.lib.debug import debug, debugging_level
+from exception import AFSArgumentError
#
# The commands map
command = cmdsetmod.get_command(cmd)
#print("MOD:", command)
- # Parse the parameters
- params = afs.argparse.parse_arguments(sys.argv[1:], command.command_arguments)
+ if hasattr(command, "argument_size_limits"):
+ argument_size_limits = command.argument_size_limits
+ else:
+ argument_size_limits = {}
- for i in command.cant_combine_arguments:
- if i[0] in params and i[1] in params:
- print("Can't combine -" + i[0], "with -" + i[1], file=sys.stderr)
- sys.exit(2)
+ # Parse the parameters
+ try:
+ params = afs.argparse.parse_arguments(sys.argv[1:],
+ command.command_arguments,
+ argument_size_limits,
+ command.cant_combine_arguments)
+ except AFSArgumentError as e:
+ print(prog + ":", e, file=sys.stderr)
+ sys.exit(2)
# Stick in the default cell if there isn't one
if "cell" not in params: