[vhffs-dev] [669] Added options --force-homedir and --force-shell to nss-mirror. pl to use in conjunction with vhffsfs.

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 669
Author:   beuss
Date:     2007-07-05 20:46:45 +0000 (Thu, 05 Jul 2007)

Log Message:
-----------
Added options --force-homedir and --force-shell to nss-mirror.pl to use in conjunction with vhffsfs.

Modified Paths:
--------------
    trunk/vhffs-backend/src/mirror/nss-mirror.pl


Modified: trunk/vhffs-backend/src/mirror/nss-mirror.pl
===================================================================
--- trunk/vhffs-backend/src/mirror/nss-mirror.pl	2007-07-05 18:55:56 UTC (rev 668)
+++ trunk/vhffs-backend/src/mirror/nss-mirror.pl	2007-07-05 20:46:45 UTC (rev 669)
@@ -32,6 +32,7 @@
 
 # **** WARNING ***** This file should be owned by root and chmoded 500
 use DBI;
+use Getopt::Long;
 
 # TODO Set us!
 my $PG_DB_HOST = 'localhost';           # Host running pg
@@ -41,6 +42,31 @@
 my $PG_DB_PASS = 'vhffs';               # VHFFS' database password
 my $ST_DB_FILE = '/var/db/auth.sqlite'; # SQLite shadow database
 
+my $shell;
+my $homedir;
+my $showhelp;
+
+sub usage() {
+    print <<EOF;
+nss-mirror.pl: Replicates users information for libnss-sqlite\n
+    --help                      this help\n
+    --force-shell shell_path   force 'shell' field value to shell_path\n
+    --force-homedir home_path   tforce 'homedir' field value to home_path\n
+EOF
+    exit(0);
+}
+
+if(!GetOptions( 'force-homedir=s'   => \$homedir,
+            'force-shell=s'     => \$shell,
+            'help'              => \$showhelp
+          )) {
+    exit(-1);
+}
+
+if($showhelp) {
+    usage();
+}
+
 # Let's open pg connection
 my $pg_dbh = DBI->connect("DBI:Pg:dbname=$PG_DB_NAME;host=$PG_DB_HOST;port=$PG_DB_PORT", $PG_DB_USER, $PG_DB_PASS) 
     or die("Unable to open pg connection\n");
@@ -63,14 +89,19 @@
 $st_dbh->do(q{CREATE TEMP TABLE tmp_user_group(uid INTEGER, gid INTEGER, CONSTRAINT pk_user_groups PRIMARY KEY(uid, gid))})
     or die("Unable to create temporary user_group table\n");
 
-my $ssth = $pg_dbh->prepare(q{SELECT u.uid, u.gid, u.username, u.passwd, u.shell, u.homedir FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE o.state = 6}) or die("Unable to prepare users SELECT statement\n");
+my $select = q{SELECT u.uid, u.gid, u.username, u.passwd %s %s FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE o.state = 6};
+
+
+my $ssth = $pg_dbh->prepare(sprintf( $select, ($homedir ? '' : ', u.homedir'), ($shell ? '' : ', u.shell') )) 
+    or die("Unable to prepare users SELECT statement\n");
 my $sth = $st_dbh->prepare(q{INSERT INTO tmp_shadow(uid, gid, username, passwd, shell, homedir) VALUES(?, ?, ?, ?, ?, ?)})
     or die("Unable to prepare shadow insert statement\n");;
 
 $ssth->execute() or die("Unable to execute users SELECT statement\n");
 
 while(my $row = $ssth->fetchrow_hashref()) {
-    $sth->execute($row->{uid}, $row->{gid}, $row->{username}, $row->{passwd}, $row->{shell}, $row->{homedir})
+    $sth->execute($row->{uid}, $row->{gid}, $row->{username}, $row->{passwd}, 
+        ($shell ? $shell : $row->{shell}), ($homedir ? $homedir : $row->{homedir}))
         or die("Unable to insert shadow\n");
 }
 $sth->finish();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/