]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Implement "pts creategroup"
authorDavid Howells <dhowells@redhat.com>
Thu, 15 May 2014 11:07:42 +0000 (12:07 +0100)
committerDavid Howells <dhowells@redhat.com>
Thu, 15 May 2014 11:07:42 +0000 (12:07 +0100)
Signed-off-by: David Howells <dhowells@redhat.com>
suite/argparse.py
suite/commands/pts/cg.py [new file with mode: 0644]
suite/commands/pts/creategroup.py [new file with mode: 0644]
suite/commands/pts/createuser.py

index 07745b9487311bdc162a42198d4028aa9b14835f..cfef3ba2776380349f27b4dc8082363f14758e5c 100644 (file)
@@ -87,6 +87,54 @@ def get_verbose(switch, params):
     set_verbosity()
     return params
 
+def do_get_id(i):
+    if i == "":
+        raise AFSArgumentError("UID/GID identifier is empty string")
+    if not i.isnumeric() and (i[0] != "-" or not i[1:].isnumeric()):
+        raise AFSArgumentError("UID/GID identifier is not numeric")
+    return int(i)
+
+def get_id(switch, params):
+    return do_get_id(params[0])
+
+def get_ids(switch, params):
+    ids = []
+    for i in params:
+        ids.append(do_get_id(i))
+    return ids
+
+def do_get_uid(i):
+    if i == "":
+        raise AFSArgumentError("UID identifier is empty string")
+    if not i.isnumeric():
+        raise AFSArgumentError("UID identifier is a positive integer")
+    return int(i)
+
+def get_uid(switch, params):
+    return do_get_uid(params[0])
+
+def get_uids(switch, params):
+    ids = []
+    for i in params:
+        ids.append(do_get_uid(i))
+    return ids
+
+def do_get_gid(i):
+    if i == "":
+        raise AFSArgumentError("GID identifier is empty string")
+    if i[0] != "-" or not i[1:].isnumeric():
+        raise AFSArgumentError("GID identifier is a positive integer")
+    return int(i)
+
+def get_gid(switch, params):
+    return do_get_gid(params[0])
+
+def get_gids(switch, params):
+    ids = []
+    for i in params:
+        ids.append(do_get_gid(i))
+    return ids
+
 ###############################################################################
 #
 # Parse an argument list according to a defined set of switches.
diff --git a/suite/commands/pts/cg.py b/suite/commands/pts/cg.py
new file mode 100644 (file)
index 0000000..1d7b456
--- /dev/null
@@ -0,0 +1 @@
+alias = "creategroup"
diff --git a/suite/commands/pts/creategroup.py b/suite/commands/pts/creategroup.py
new file mode 100644 (file)
index 0000000..ae9aada
--- /dev/null
@@ -0,0 +1,90 @@
+#
+# AFS Server management toolkit: Create groups
+# -*- 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 an (empty) Protection Database group entry"
+
+command_arguments = [
+    [ "name",           get_strings,            "rm",         "<group name>+" ],
+    [ "owner",          get_string,             "os"          "<owner of the group>" ],
+    [ "id",             get_gids,               "om",         "<id (negated) for the group>+" ],
+    [ "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 an (empty) Protection Database group entry
+"""
+
+def main(params):
+    exitcode = 0
+    cell = params["cell"]
+    prcache = cell.get_prcache(params)
+
+    oid = 0
+    if "owner" in params:
+        oid = prcache.name_or_id_to_id(params["owner"])
+
+    names = params["name"]
+    if "id" in params:
+        ids = params["id"]
+    else:
+        ids = []
+
+    for i in range(0, len(names)):
+        name = names[i]
+        try:
+            verbose("Adding group ", name, "\n")
+            if i < len(ids):
+                new_id = int(ids[i])
+                ret = cell.call_pt_server(params, kafs.PR_INewEntry, name, new_id, oid)
+            else:
+                ret = cell.call_pt_server(params, kafs.PR_NewEntry, name, kafs.PRGRP, oid)
+                new_id = ret.id
+            output("Group ", name, " has id ", new_id, "\n")
+        except kafs.AbortPREXIST:
+            error("Entry for name already exists ; unable to create group ", name, "\n")
+            if "force" not in params:
+                break
+        except kafs.AbortPRIDEXIST:
+            error("Entry for id already exists ; unable to create group ", name, " with id ", new_id, "\n")
+            if "force" not in params:
+                break
+    return exitcode
index b8e8f200720ce00f572173113e286f30b6c84188..065f65b11c70176844b59de23d6b216f24ad346f 100644 (file)
@@ -30,7 +30,7 @@ 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>+" ],
+    [ "id",             get_uids,               "om",         "<user id>+" ],
     [ "cell",           get_cell,               "os",         "<cell name>" ],
     [ "noauth",         get_auth,               "fn" ],
     [ "localauth",      get_auth,               "fn" ],