From 61847451cf50daf61c234ffd5cdb262f93afaf84 Mon Sep 17 00:00:00 2001 From: David Howells Date: Mon, 12 May 2014 13:03:07 +0100 Subject: [PATCH] Implement "pts createuser" Signed-off-by: David Howells --- rpc-api/pts.xg | 3 +- rpc-api/ubik.xg | 4 ++ suite/commands/pts/__init__.py | 62 ++++++++++++++++++++ suite/commands/pts/createuser.py | 99 ++++++++++++++++++++++++++++++++ suite/commands/pts/cu.py | 1 + suite/lib/cell.py | 21 +++++++ 6 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 suite/commands/pts/__init__.py create mode 100644 suite/commands/pts/createuser.py create mode 100644 suite/commands/pts/cu.py diff --git a/rpc-api/pts.xg b/rpc-api/pts.xg index 84059e5..67009d9 100644 --- a/rpc-api/pts.xg +++ b/rpc-api/pts.xg @@ -37,6 +37,8 @@ package PR_ +const PR_PORT = 7002; /* Protection service port */ +const PR_SERVICE = 73; /* RxRPC service ID for the Protection service */ /* Opcodes */ const PRINEWUSER = 500; @@ -66,7 +68,6 @@ const PR_MAXGROUPS = 5000; const PR_MAXLIST = 5000; const PRSIZE = 10; const COSIZE = 39; -const PRSRV = 73; const ENTRYSIZE = 192; const PRDBVERSION = 0; diff --git a/rpc-api/ubik.xg b/rpc-api/ubik.xg index 317d8a2..7cae679 100644 --- a/rpc-api/ubik.xg +++ b/rpc-api/ubik.xg @@ -35,6 +35,10 @@ package Ubik_ +const UBIK_VOTE_SERVICE = 50; /* RxRPC service ID for the Ubik Vote/Quorum service */ +const UBIK_DISK_SERVICE = 51; /* RxRPC service ID for the Ubik Disk I/O service */ +const UBIK_APP_SERVICE = 52; /* RxRPC service ID for the Ubik Application service */ + struct net_tid { uint32_t epoch; uint32_t counter; diff --git a/suite/commands/pts/__init__.py b/suite/commands/pts/__init__.py new file mode 100644 index 0000000..b1801d0 --- /dev/null +++ b/suite/commands/pts/__init__.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- + +__copyright__ = """ +Copyright (C) 2014 Red Hat, Inc. All Rights Reserved. +Written by David Howells (dhowells@redhat.com) + +Derived from StGIT: + +Copyright (C) 2005, Catalin Marinas +Copyright (C) 2008, Karl Hasselström + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public Licence version 2 as +published by the Free Software Foundation. + +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 Licence for more details. + +You should have received a copy of the GNU General Public Licence +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" + +import os + +def get_command(mod): + """Import and return the given command module.""" + return __import__(__name__ + '.' + mod, globals(), locals(), ['*']) + +def get_command_list(): + commands = [] + for p in __path__: + for fn in os.listdir(p): + if not fn.startswith("_") and fn.endswith('.py'): + commands.append(fn[:-3]) + return commands + +def py_commands(commands, f): + f.write('command_list = {\n') + for key, val in sorted(commands.iteritems()): + f.write(' %r: %r,\n' % (key, val)) + f.write(' }\n') + +#def _command_list(commands): +# for cmd, (mod, help) in commands.iteritems(): + +def pretty_command_list(commands, f): + cmd_len = max(len(cmd) for cmd in commands.iterkeys()) + for cmd, help in cmds: + f.write(' %*s %s\n' % (-cmd_len, cmd, help)) + +def _write_underlined(s, u, f): + f.write(s + '\n') + f.write(u*len(s) + '\n') + +def asciidoc_command_list(commands, f): + for cmd, help in commands: + f.write('linkstgsub:%s[]::\n' % cmd) + f.write(' %s\n' % help) + f.write('\n') diff --git a/suite/commands/pts/createuser.py b/suite/commands/pts/createuser.py new file mode 100644 index 0000000..2c8cc14 --- /dev/null +++ b/suite/commands/pts/createuser.py @@ -0,0 +1,99 @@ +# +# AFS Server management toolkit: Create a user record +# -*- coding: utf-8 -*- +# + +__copyright__ = """ +Copyright (C) 2014 Red Hat, Inc. All Rights Reserved. +Written by David Howells (dhowells@redhat.com) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public Licence version 2 as +published by the Free Software Foundation. + +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 Licence for more details. + +You should have received a copy of the GNU General Public Licence +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" + +from afs.argparse import * +from afs.lib.output import * +import kafs +import sys + +help = "Create a user or machine entry in the Protection Database" + +command_arguments = [ + [ "name", get_strings, "rm", "+" ], + [ "id", get_strings, "om", "+" ], + [ "cell", get_cell, "os", "" ], + [ "noauth", get_auth, "fn" ], + [ "localauth", get_auth, "fn" ], + [ "verbose", get_verbose, "fn" ], + [ "encrypt", get_dummy, "fn" ], + [ "force", get_dummy, "fn" ], +] + +cant_combine_arguments = [ + ( "cell", "localauth" ), + ( "noauth", "localauth" ), +] + +argument_size_limits = { + "name" : kafs.PR_MAXNAMELEN, +} + +description = r""" +Create a user or machine entry in the Protection Database +""" + +def main(params): + exitcode = 0 + cell = params["cell"] + pt_conn = cell.open_pt_server(params) + + names = params["name"] + if "id" in params: + ids = params["id"] + else: + ids = [] + for i in range(0, len(names)): + try: + name = names[i] + verbose("Adding user ", name, "\n") + if i < len(ids): + new_id = int(ids[i]) + ret = kafs.PR_INewEntry(pt_conn, name, new_id, 0) + else: + ret = kafs.PR_NewEntry(pt_conn, name, 0, 0) + new_id = ret.id + output("User ", name, " has id ", new_id, "\n") + except ConnectionRefusedError: + # Move on to the next server + verbose("Connection refused\n"); + pt_conn = cell.open_pt_server(params) + continue + except kafs.AbortUNOTSYNC: + verbose("Server is not synchronised\n"); + pt_conn = cell.open_pt_server(params) + continue + except kafs.AbortPREXIST: + error("Entry for name already exists ; unable to create user ", name, "\n") + if "force" not in params: + break + except kafs.AbortPRIDEXIST: + error("Entry for id already exists ; unable to create user ", name, " with id ", new_id, "\n") + if "force" not in params: + break + except kafs.RemoteAbort as e: + if str(e) == "Aborted 17": + error("failed to add user ", i, " (File exists)\n") + exitcode = 1 + else: + raise + return exitcode diff --git a/suite/commands/pts/cu.py b/suite/commands/pts/cu.py new file mode 100644 index 0000000..c55bb29 --- /dev/null +++ b/suite/commands/pts/cu.py @@ -0,0 +1 @@ +alias = "createuser" diff --git a/suite/lib/cell.py b/suite/lib/cell.py index 57b4e24..ca9d154 100644 --- a/suite/lib/cell.py +++ b/suite/lib/cell.py @@ -51,6 +51,7 @@ class cell: self.__vlserver_names = dict() self.__vlservers = [] self.__vlconn = None + self.__ptservers = None def __repr__(self): return "<" + "AFS:" + self.__name + ">" @@ -209,3 +210,23 @@ class cell: kafs.BOSSERVICE_ID, key, security) return bos_conn + + # Open a Protection Server connection + def open_pt_server(self, params=None): + if self.__ptservers == None: + self.__ptservers = self.query_vl_addrs() + + if len(self.__ptservers) == 0: + raise CellError("Couldn't connect to a PT server") + server = self.__ptservers[0] + self.__ptservers[0] = self.__ptservers[1:] + + key, security = self.determine_security(params) + + verbose("Trying ptserver ", server, "\n") + + pt_conn = kafs.rx_new_connection(str(server), + kafs.PR_PORT, + kafs.PR_SERVICE, + key, security) + return pt_conn -- 2.49.0