From: James Troup Date: Wed, 14 Aug 2002 00:40:19 +0000 (+0000) Subject: julia now gets the passwords via getpwall() rather than trying to read a passwd file. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2c442c5a39e20adb1be634b7bfcd0b875cbb2aa;p=dak julia now gets the passwords via getpwall() rather than trying to read a passwd file. --- diff --git a/TODO b/TODO index d1e1c845..837405b1 100644 --- a/TODO +++ b/TODO @@ -103,6 +103,8 @@ More Urgent Less Urgent ----------- + o Accept "," as a seperator in -a, -s etc. args + o change utils.copy to try rename() first o [hard, long term] unchecked -> accepted should go into the db, not diff --git a/cron.hourly b/cron.hourly index 6ef4d5a9..89d125e3 100644 --- a/cron.hourly +++ b/cron.hourly @@ -7,4 +7,4 @@ export SCRIPTVARS=/org/ftp.debian.org/katie/vars . $SCRIPTVARS cd $masterdir -julia /var/lib/misc/auric.debian.org/passwd +julia diff --git a/cron.hourly-non-US b/cron.hourly-non-US index 0ad9da74..70999c6c 100644 --- a/cron.hourly-non-US +++ b/cron.hourly-non-US @@ -7,4 +7,4 @@ export SCRIPTVARS=/org/non-us.debian.org/katie/vars-non-US . $SCRIPTVARS cd $masterdir -julia /var/lib/misc/pandora.debian.org/passwd +julia diff --git a/docs/julia.1.sgml b/docs/julia.1.sgml index 268ea690..ca35fa68 100644 --- a/docs/julia.1.sgml +++ b/docs/julia.1.sgml @@ -17,7 +17,7 @@ julia - Utility to sync PostgreSQL with a (LDAP-generated) passwd file + Utility to sync PostgreSQL users with system users @@ -25,19 +25,24 @@ julia - passwd file Description</> <para> - <command>julia</command> is a utility to sync PostgreSQL's user database with a passwd file. It is designed to allow the use of 'peer sameuser' authentication. It simply adds any users in the password file into PostgreSQL's pg_user table if they are already not there. It will also warn you about users who are in the pg_user table but not in the password file. + <command>julia</command> is a utility to sync PostgreSQL's user database with the system's users. It is designed to allow the use of 'peer sameuser' authentication. It simply adds any users in the password file into PostgreSQL's pg_user table if they are already not there. It will also warn you about users who are in the pg_user table but not in the password file. </PARA> </REFSECT1> <RefSect1><Title>Options</> <VariableList> + <VarListEntry><term><option>-n/--no-action<replaceable></replaceable></option></> + <ListItem> + <Para>Don't actually do anything.</PARA> + </LISTITEM> + </VarListEntry> + <VarListEntry><term><option>-q/--quiet<replaceable></replaceable></option></> <ListItem> <Para>Be quiet, i.e. display as little output as possible.</PARA> diff --git a/julia b/julia index 07e43672..e7dff3bc 100755 --- a/julia +++ b/julia @@ -1,8 +1,8 @@ #!/usr/bin/env python -# Sync PostgreSQL with (LDAP-generated) passwd file +# Sync PostgreSQL users with system users # Copyright (C) 2001, 2002 James Troup <james@nocrew.org> -# $Id: julia,v 1.6 2002-05-03 16:06:45 troup Exp $ +# $Id: julia,v 1.7 2002-08-14 00:40:19 troup Exp $ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,7 +30,7 @@ ################################################################################ -import pg, string, sys; +import pg, pwd, string, sys; import utils; import apt_pkg; @@ -44,6 +44,7 @@ def usage (exit_code=0): print """Usage: julia [OPTION]... PASSWD_FILE Sync PostgreSQL's pg_user with PASSWD_FILE. + -n, --no-action don't do anything -q, --quiet be quiet about what is being done -v, --verbose explain what is being done -h, --help show this help and exit""" @@ -56,10 +57,11 @@ def main (): Cnf = utils.get_conf() - Arguments = [('q',"quiet","Julia::Options::Quiet"), - ('v',"verbose","Julia::Options::Verbose"), - ('h',"help","Julia::Options::Help")]; - for i in ["quiet", "verbose", "help" ]: + Arguments = [('n', "no-action", "Julia::Options::No-Action"), + ('q', "quiet", "Julia::Options::Quiet"), + ('v', "verbose", "Julia::Options::Verbose"), + ('h', "help", "Julia::Options::Help")]; + for i in [ "no-action", "quiet", "verbose", "help" ]: if not Cnf.has_key("Julia::Options::%s" % (i)): Cnf["Julia::Options::%s" % (i)] = ""; @@ -68,23 +70,17 @@ def main (): if Options["Help"]: usage(); - if not arguments: - utils.warn("julia needs the name of the passwd file to sync with as an argument."); - usage(1); - elif len(arguments) > 1: - utils.warn("julia only takes one non-option argument, the passwd file to sync with."); + elif arguments: + utils.warn("julia takes no non-option arguments."); usage(1); - passwd = arguments[0]; projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); - valid_gid = Cnf.get("Julia::ValidGID",""); + valid_gid = int(Cnf.get("Julia::ValidGID","")); passwd_unames = {}; - passwd_file = utils.open_file(passwd); - for line in passwd_file.readlines(): - split = string.split(line, ':'); - uname = split[0]; - gid = split[3]; + for entry in pwd.getpwall(): + uname = entry[0]; + gid = entry[3]; if valid_gid and gid != valid_gid: if Options["Verbose"]: print "Skipping %s (GID %s != Valid GID %s)." % (uname, gid, valid_gid); @@ -115,7 +111,8 @@ def main (): if not postgres_unames.has_key(uname): if not Options["Quiet"]: print "Creating %s user in Postgres." % (uname); - q = projectB.query('CREATE USER "%s"' % (uname)); + if not Options["No-Action"]: + q = projectB.query('CREATE USER "%s"' % (uname)); #######################################################################################