4 Add a user to to the uid/maintainer/fingerprint table and
5 add his key to the GPGKeyring
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2004, 2009 Joerg Jaspert <joerg@ganneff.de>
9 @license: GNU General Public License version 2 or later
12 ################################################################################
13 # <elmo> wow, sounds like it'll be a big step up.. configuring dak on a
14 # new machine even scares me :)
15 ################################################################################
17 # You don't want to read this script if you know python.
18 # I know what I say. I dont know python and I wrote it. So go and read some other stuff.
24 from daklib import utils
25 from daklib.dbconn import DBConn, get_or_set_uid, get_active_keyring_paths
26 from daklib.regexes import re_gpg_fingerprint_colon, re_user_address, re_user_mails, re_user_name
28 ################################################################################
33 ################################################################################
35 def usage(exit_code=0):
36 print """Usage: add-user [OPTION]...
37 Adds a new user to the dak databases and keyrings
39 -k, --key keyid of the User
40 -u, --user userid of the User
41 -h, --help show this help and exit."""
44 ################################################################################
50 Cnf = utils.get_conf()
52 Arguments = [('h',"help","Add-User::Options::Help"),
53 ('k',"key","Add-User::Options::Key", "HasArg"),
54 ('u',"user","Add-User::Options::User", "HasArg"),
58 if not Cnf.has_key("Add-User::Options::%s" % (i)):
59 Cnf["Add-User::Options::%s" % (i)] = ""
61 apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
63 Options = Cnf.subtree("Add-User::Options")
67 session = DBConn().session()
70 keyrings = get_active_keyring_paths()
72 cmd = "gpg --with-colons --no-secmem-warning --no-auto-check-trustdb --no-default-keyring %s --with-fingerprint --list-key %s" \
73 % (utils.gpg_keyring_args(keyrings),
74 Cnf["Add-User::Options::Key"])
75 (result, output) = commands.getstatusoutput(cmd)
76 m = re_gpg_fingerprint_colon.search(output)
79 utils.fubar("0x%s: (1) No fingerprint found in gpg output but it returned 0?\n%s" \
80 % (Cnf["Add-User::Options::Key"], utils.prefix_multi_line_string(output, \
82 primary_key = m.group(1)
83 primary_key = primary_key.replace(" ","")
86 if Cnf.has_key("Add-User::Options::User") and Cnf["Add-User::Options::User"]:
87 uid = Cnf["Add-User::Options::User"]
88 name = Cnf["Add-User::Options::User"]
90 u = re_user_address.search(output)
93 utils.fubar("0x%s: (2) No userid found in gpg output but it returned 0?\n%s" \
94 % (Cnf["Add-User::Options::Key"], utils.prefix_multi_line_string(output, " [GPG output:] ")))
96 n = re_user_name.search(output)
99 # Look for all email addresses on the key.
101 for line in output.split('\n'):
102 e = re_user_mails.search(line)
105 emails.append(e.group(2))
107 print "0x%s -> %s <%s> -> %s -> %s" % (Cnf["Add-User::Options::Key"], name, emails[0], uid, primary_key)
109 prompt = "Add user %s with above data (y/N) ? " % (uid)
110 yn = utils.our_raw_input(prompt).lower()
113 # Create an account for the user?
116 # Now add user to the database.
117 # Note that we provide a session, so we're responsible for committing
118 uidobj = get_or_set_uid(uid, session=session)
119 uid_id = uidobj.uid_id
122 # Lets add user to the email-whitelist file if its configured.
123 if Cnf.has_key("Dinstall::MailWhiteList") and Cnf["Dinstall::MailWhiteList"] != "":
124 f = utils.open_file(Cnf["Dinstall::MailWhiteList"], "a")
129 print "Added:\nUid:\t %s (ID: %s)\nMaint:\t %s\nFP:\t %s" % (uid, uid_id, \
132 # Should we send mail to the newly added user?
133 if Cnf.find_b("Add-User::SendEmail"):
134 mail = name + "<" + emails[0] +">"
136 Subst["__NEW_MAINTAINER__"] = mail
137 Subst["__UID__"] = uid
138 Subst["__KEYID__"] = Cnf["Add-User::Options::Key"]
139 Subst["__PRIMARY_KEY__"] = primary_key
140 Subst["__FROM_ADDRESS__"] = Cnf["Dinstall::MyEmailAddress"]
141 Subst["__ADMIN_ADDRESS__"] = Cnf["Dinstall::MyAdminAddress"]
142 Subst["__HOSTNAME__"] = Cnf["Dinstall::MyHost"]
143 Subst["__DISTRO__"] = Cnf["Dinstall::MyDistribution"]
144 Subst["__SUMMARY__"] = summary
145 new_add_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/add-user.added")
146 utils.send_mail(new_add_message)
151 #######################################################################################
153 if __name__ == '__main__':