--- /dev/null
+# -*- 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')
--- /dev/null
+#
+# 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
self.__vlserver_names = dict()
self.__vlservers = []
self.__vlconn = None
+ self.__ptservers = None
def __repr__(self):
return "<" + "AFS:" + self.__name + ">"
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