From 609b8e601b7cf471dd8c40745fa826ff43b49db1 Mon Sep 17 00:00:00 2001 From: David Howells Date: Thu, 15 May 2014 11:28:59 +0100 Subject: [PATCH] Implement "pts adduser" and "pts removeuser" Signed-off-by: David Howells --- suite/commands/pts/adduser.py | 86 ++++++++++++++++++++++++++++++++ suite/commands/pts/removeuser.py | 86 ++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 suite/commands/pts/adduser.py create mode 100644 suite/commands/pts/removeuser.py diff --git a/suite/commands/pts/adduser.py b/suite/commands/pts/adduser.py new file mode 100644 index 0000000..cb82a8d --- /dev/null +++ b/suite/commands/pts/adduser.py @@ -0,0 +1,86 @@ +# +# AFS Server management toolkit: Add a user to a group +# -*- 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 + +help = "Add a user or machine to a Protection Database group" + +command_arguments = [ + [ "user", get_strings, "rm", "+" ], + [ "group", get_strings, "rm", "+" ], + [ "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""" +Add a user or machine to a Protection Database group +""" + +def main(params): + cell = params["cell"] + prcache = cell.get_prcache(params) + + ignored = "" + if "force" in params: + ignored = " (ignored)" + + for user in params["user"]: + prcache.precache_name_or_id(user) + + for group in params["group"]: + prcache.precache_name_or_id(group) + + for user in params["user"]: + uid = prcache.name_or_id_to_id(user) + + for group in params["group"]: + gid = prcache.name_or_id_to_id(group) + + if uid == None or gid == None: + error("User or group doesn't exist ; unable to add user ", user, " to group ", group, ignored, "\n") + if "force" not in params: + return + else: + continue + + try: + ret = cell.call_pt_server(params, kafs.PR_AddToGroup, uid, gid) + except kafs.AbortPRIDEXIST: + error("Entry for id already exists ; unable to add user ", user, " to group ", group, ignored, "\n") + if "force" not in params: + return diff --git a/suite/commands/pts/removeuser.py b/suite/commands/pts/removeuser.py new file mode 100644 index 0000000..204240f --- /dev/null +++ b/suite/commands/pts/removeuser.py @@ -0,0 +1,86 @@ +# +# AFS Server management toolkit: Remove a user from a group +# -*- 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 + +help = "Remove a user from a Protection Database group" + +command_arguments = [ + [ "user", get_strings, "rm", "+" ], + [ "group", get_strings, "rm", "+" ], + [ "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""" +Remove a user from a Protection Database group +""" + +def main(params): + cell = params["cell"] + prcache = cell.get_prcache(params) + + ignored = "" + if "force" in params: + ignored = " (ignored)" + + for user in params["user"]: + prcache.precache_name_or_id(user) + + for group in params["group"]: + prcache.precache_name_or_id(group) + + for user in params["user"]: + uid = prcache.name_or_id_to_id(user) + + for group in params["group"]: + gid = prcache.name_or_id_to_id(group) + + if uid == None or gid == None: + error("User or group doesn't exist ; unable to remove user ", user, " from group ", group, ignored, "\n") + if "force" not in params: + return + else: + continue + + try: + ret = cell.call_pt_server(params, kafs.PR_RemoveFromGroup, uid, gid) + except kafs.AbortPRNOENT: + error("User or group doesn't exist ; unable to remove user ", user, " from group ", group, ignored, "\n") + if "force" not in params: + return -- 2.49.0