]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Implement "pts createuser"
authorDavid Howells <dhowells@redhat.com>
Mon, 12 May 2014 12:03:07 +0000 (13:03 +0100)
committerDavid Howells <dhowells@redhat.com>
Tue, 13 May 2014 16:37:01 +0000 (17:37 +0100)
Signed-off-by: David Howells <dhowells@redhat.com>
rpc-api/pts.xg
rpc-api/ubik.xg
suite/commands/pts/__init__.py [new file with mode: 0644]
suite/commands/pts/createuser.py [new file with mode: 0644]
suite/commands/pts/cu.py [new file with mode: 0644]
suite/lib/cell.py

index 84059e5c30930270afff12c21ece80702bdbd6b0..67009d9c35a97bf0de3fd372c383feb05d3814d6 100644 (file)
@@ -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;
index 317d8a2c559c3c1377381dc5241b8cf2e2934997..7cae679b279427dfa41f66af063aaaffd54df453 100644 (file)
 
 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 (file)
index 0000000..b1801d0
--- /dev/null
@@ -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 <catalin.marinas@gmail.com>
+Copyright (C) 2008, Karl Hasselström <kha@treskal.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
+"""
+
+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 (file)
index 0000000..2c8cc14
--- /dev/null
@@ -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",         "<user name>+" ],
+    [ "id",             get_strings,            "om",         "<user id>+" ],
+    [ "cell",           get_cell,               "os",         "<cell name>" ],
+    [ "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 (file)
index 0000000..c55bb29
--- /dev/null
@@ -0,0 +1 @@
+alias = "createuser"
index 57b4e24464009ca00b451111d1f89592110016dc..ca9d1543fb56baa62018b0d146f16cfb47b9397b 100644 (file)
@@ -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