Commit 2965922b authored by Leigh Stoller's avatar Leigh Stoller

Finish up user deletion. The big visible change is that when a user is

deleted, they still remain in the user table with a status of
"archived", but since all the queries in the system now use uid_idx
instead of uid, it is safe to reuse a uid since they are no longer
ambiguous. 

The reason for not deleting users from the users table is so that the
stats records can refer to the original record (who was that person
named "mike"). This is very handy and worth the additional effort it
has taken.

There is no way to ressurect a user, but it would not be hard to add.
parent e90c9411
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2008 University of Utah and the Flux Group. # Copyright (c) 2000-2008, 2010 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
...@@ -243,7 +243,7 @@ foreach my $key (keys(%{ $xmlparse->{'attribute'} })) { ...@@ -243,7 +243,7 @@ foreach my $key (keys(%{ $xmlparse->{'attribute'} })) {
# #
if (exists($newuser_args{'uid'})) { if (exists($newuser_args{'uid'})) {
UserError("User already exists; pick another login name!") UserError("User already exists; pick another login name!")
if (User->LookupByUidAll($newuser_args{'uid'})); if (User->Lookup($newuser_args{'uid'}));
UserError("Reserved user name; pick another login name!") UserError("Reserved user name; pick another login name!")
if (getpwnam($newuser_args{'uid'})); if (getpwnam($newuser_args{'uid'}));
...@@ -367,13 +367,13 @@ if (TBGetSiteVar("general/firstinit/state", \$firstinitstate)) { ...@@ -367,13 +367,13 @@ if (TBGetSiteVar("general/firstinit/state", \$firstinitstate)) {
if ($firstinitstate eq "createproject") { if ($firstinitstate eq "createproject") {
DBQueryFatal("update users set ". DBQueryFatal("update users set ".
" admin=1,status='". $User::USERSTATUS_UNAPPROVED . "' " . " admin=1,status='". $User::USERSTATUS_UNAPPROVED . "' " .
"where uid='$new_uid'"); "where uid_idx='$usr_idx'");
DBQueryFatal("insert into unixgroup_membership set ". DBQueryFatal("insert into unixgroup_membership set ".
"uid='$new_uid', gid='wheel'"); "uid='$new_uid', uid_idx='$usr_idx', gid='wheel'");
DBQueryFatal("insert into unixgroup_membership set ". DBQueryFatal("insert into unixgroup_membership set ".
"uid='$new_uid', gid='$TBADMINGROUP'"); "uid='$new_uid', uid_idx='$usr_idx', gid='$TBADMINGROUP'");
# The web interface requires this line to be printed! # The web interface requires this line to be printed!
print "User $usr_uid/$usr_idx has been created\n"; print "User $usr_uid/$usr_idx has been created\n";
......
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2005, 2006 University of Utah and the Flux Group. # Copyright (c) 2005, 2006, 2010 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
...@@ -111,7 +111,7 @@ while (my ($pid) = $query_result->fetchrow_array()) { ...@@ -111,7 +111,7 @@ while (my ($pid) = $query_result->fetchrow_array()) {
$query_result = $query_result =
DBQueryFatal("select distinct g.uid ". DBQueryFatal("select distinct g.uid ".
" from group_membership as g ". " from group_membership as g ".
"left join users as u on u.uid=g.uid ". "left join users as u on u.uid_idx=g.uid_idx ".
"where u.status='active' and g.trust!='none' ". "where u.status='active' and g.trust!='none' ".
# " and (g.pid='testbed' or g.pid='emulab-ops' or ". # " and (g.pid='testbed' or g.pid='emulab-ops' or ".
# " g.pid='tbres' or g.pid='utahstud')" . # " g.pid='tbres' or g.pid='utahstud')" .
......
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group. # Copyright (c) 2005, 2010 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
...@@ -102,7 +102,7 @@ if (AuditStart(0)) { ...@@ -102,7 +102,7 @@ if (AuditStart(0)) {
$query_result = $query_result =
DBQueryFatal("select distinct u.uid ". DBQueryFatal("select distinct u.uid ".
" from group_membership as g ". " from group_membership as g ".
"left join users as u on u.uid=g.uid ". "left join users as u on u.uid_idx=g.uid_idx ".
"where u.status='active' ". "where u.status='active' ".
# " and (g.pid='testbed' or g.pid='emulab-ops' or ". # " and (g.pid='testbed' or g.pid='emulab-ops' or ".
# " g.pid='tbres' or g.pid='utahstud' or ". # " g.pid='tbres' or g.pid='utahstud' or ".
...@@ -165,7 +165,7 @@ while (my ($pid,$gid) = $query_result->fetchrow_array()) { ...@@ -165,7 +165,7 @@ while (my ($pid,$gid) = $query_result->fetchrow_array()) {
my $users_results = my $users_results =
DBQueryFatal("select g.uid from group_membership as g ". DBQueryFatal("select g.uid from group_membership as g ".
"left join users as u on u.uid=g.uid ". "left join users as u on u.uid_idx=g.uid_idx ".
"where g.pid='$pid' and g.gid='$gid' and ". "where g.pid='$pid' and g.gid='$gid' and ".
" u.status='active'"); " u.status='active'");
......
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2005, 2006, 2007 University of Utah and the Flux Group. # Copyright (c) 2005-2010 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
...@@ -90,18 +90,18 @@ my $optarg = ($debug ? "-d" : ""); ...@@ -90,18 +90,18 @@ my $optarg = ($debug ? "-d" : "");
# Initialize a mailman password for all users. # Initialize a mailman password for all users.
# #
my $query_result = my $query_result =
DBQueryFatal("select uid from users ". DBQueryFatal("select uid,uid_uid from users ".
"where mailman_password is NULL and status!='archived'"); "where mailman_password is NULL and status!='archived'");
while (my ($uid) = $query_result->fetchrow_array()) { while (my ($uid,$uid_idx) = $query_result->fetchrow_array()) {
print "Setting initial mailman password for $uid\n" print "Setting initial mailman password for $uid ($uid_idx)\n"
if ($debug); if ($debug);
my $password = TBGenSecretKey(); my $password = TBGenSecretKey();
$password = substr($password, 0, 10); $password = substr($password, 0, 10);
DBQueryFatal("update users set mailman_password='$password' ". DBQueryFatal("update users set mailman_password='$password' ".
"where uid='$uid'"); "where uid_idx='$uid_idx'");
} }
# #
...@@ -110,7 +110,7 @@ while (my ($uid) = $query_result->fetchrow_array()) { ...@@ -110,7 +110,7 @@ while (my ($uid) = $query_result->fetchrow_array()) {
$query_result = $query_result =
DBQueryFatal("select distinct g.uid,u.usr_email ". DBQueryFatal("select distinct g.uid,u.usr_email ".
" from group_membership as g ". " from group_membership as g ".
"left join users as u on u.uid=g.uid ". "left join users as u on u.uid_idx=g.uid_idx ".
"where u.status='active' or u.status='frozen' ". "where u.status='active' or u.status='frozen' ".
# " and (g.pid='testbed' or g.pid='emulab-ops' or ". # " and (g.pid='testbed' or g.pid='emulab-ops' or ".
# " g.pid='tbres' or g.pid='utahstud')" . # " g.pid='tbres' or g.pid='utahstud')" .
......
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2005-2009 University of Utah and the Flux Group. # Copyright (c) 2005-2010 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
package User; package User;
...@@ -600,15 +600,15 @@ sub Purge($) ...@@ -600,15 +600,15 @@ sub Purge($)
# #
DBQueryWarn("delete from login where uid_idx='$uid_idx'") DBQueryWarn("delete from login where uid_idx='$uid_idx'")
or return -1; or return -1;
DBQueryWarn("delete from nodeuidlastlogin where uid='$uid'") DBQueryWarn("delete from nodeuidlastlogin where uid='$uid_idx'")
or return -1; or return -1;
DBQueryWarn("delete from uidnodelastlogin where uid='$uid'") DBQueryWarn("delete from uidnodelastlogin where uid='$uid_idx'")
or return -1; or return -1;
DBQueryWarn("delete from unixgroup_membership where uid='$uid'") DBQueryWarn("delete from unixgroup_membership where uid='$uid_idx'")
or return -1; or return -1;
DBQueryWarn("delete from userslastlogin where uid='$uid'") DBQueryWarn("delete from userslastlogin where uid='$uid_idx'")
or return -1; or return -1;
DBQueryWarn("delete from user_policies where uid='$uid'") DBQueryWarn("delete from user_policies where uid='$uid_idx'")
or return -1; or return -1;
return 0; return 0;
...@@ -1419,13 +1419,13 @@ sub UnixGroupList($$) ...@@ -1419,13 +1419,13 @@ sub UnixGroupList($$)
return -1 return -1
if (! ref($self)); if (! ref($self));
my $user_uid = $self->uid(); my $uid_idx = $self->uid_idx();
my @glist = (); my @glist = ();
@$prval = (); @$prval = ();
my $query_result = my $query_result =
DBQueryWarn("select gid from unixgroup_membership ". DBQueryWarn("select gid from unixgroup_membership ".
"where uid='$user_uid'"); "where uid_idx='$uid_idx'");
return -1 return -1
if (!defined($query_result)); if (!defined($query_result));
return 0 return 0
......
...@@ -115,17 +115,17 @@ mysystem("$TB/sbin/mkproj -s $pid"); ...@@ -115,17 +115,17 @@ mysystem("$TB/sbin/mkproj -s $pid");
# groups are created (tbacct add does not do a setgroups). # groups are created (tbacct add does not do a setgroups).
# #
my $users_result = my $users_result =
DBQueryFatal("select distinct u.uid,u.admin,u.status ". DBQueryFatal("select distinct u.uid,u.uid_idx,u.admin,u.status ".
" from group_membership as m ". " from group_membership as m ".
"left join users as u on u.uid_idx=m.uid_idx "); "left join users as u on u.uid_idx=m.uid_idx ");
while (my ($uid,$admin,$status) = $users_result->fetchrow_array()) { while (my ($uid,$uid_idx,$admin,$status) = $users_result->fetchrow_array()) {
next next
if ($uid eq "elabman"); if ($uid eq "elabman");
if ($admin) { if ($admin) {
# Add admin users to group wheel for convenience. # Add admin users to group wheel for convenience.
DBQueryFatal("replace into unixgroup_membership ". DBQueryFatal("replace into unixgroup_membership ".
"values ('$uid','wheel')"); "values ('$uid','$uid_idx','wheel')");
} }
next next
if ($status ne USERSTATUS_ACTIVE()); if ($status ne USERSTATUS_ACTIVE());
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2007 University of Utah and the Flux Group. # Copyright (c) 2000-2010 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use Fcntl ':flock'; use Fcntl ':flock';
...@@ -300,7 +300,7 @@ sub ActiveUsers() ...@@ -300,7 +300,7 @@ sub ActiveUsers()
if (! ($query_result = if (! ($query_result =
DBQuery("SELECT DISTINCT u.usr_email from experiments as e ". DBQuery("SELECT DISTINCT u.usr_email from experiments as e ".
"left join group_membership as p ". "left join group_membership as p ".
" on e.pid=p.pid and p.pid=p.gid ". " on e.pid_idx=p.pid_idx and p.pid_idx=p.gid_idx ".
"left join users as u on u.uid_idx=p.uid_idx ". "left join users as u on u.uid_idx=p.uid_idx ".
"where u.status='active' and ". "where u.status='active' and ".
" e.state='active' ". " e.state='active' ".
...@@ -352,7 +352,7 @@ sub RecentProjects() ...@@ -352,7 +352,7 @@ sub RecentProjects()
if (! ($query_result = if (! ($query_result =
DBQuery("select distinct u.usr_email from project_stats as s ". DBQuery("select distinct u.usr_email from project_stats as s ".
"left join group_membership as g on ". "left join group_membership as g on ".
" g.pid=s.pid and g.gid=g.pid ". " g.pid_idx=s.pid_idx and g.gid_idx=g.pid_idx ".
"left join users as u on u.uid_idx=g.uid_idx ". "left join users as u on u.uid_idx=g.uid_idx ".
"where u.status='active' and ". "where u.status='active' and ".
" ((UNIX_TIMESTAMP(now()) - ". " ((UNIX_TIMESTAMP(now()) - ".
...@@ -379,9 +379,9 @@ sub RecentProjectLeaders() ...@@ -379,9 +379,9 @@ sub RecentProjectLeaders()
if (! ($query_result = if (! ($query_result =
DBQuery("select distinct u.usr_email from project_stats as s ". DBQuery("select distinct u.usr_email from project_stats as s ".
"left join group_membership as g on ". "left join group_membership as g on ".
" g.pid=s.pid and g.gid=g.pid ". " g.pid_idx=s.pid_idx and g.gid_idx=g.pid_idx ".
"left join users as u on u.uid_idx=g.uid_idx ". "left join users as u on u.uid_idx=g.uid_idx ".
"left join projects as p on u.uid=p.head_uid ". "left join projects as p on u.uid_idx=p.head_idx ".
"where u.status='active' and ". "where u.status='active' and ".
" ((UNIX_TIMESTAMP(now()) - ". " ((UNIX_TIMESTAMP(now()) - ".
" UNIX_TIMESTAMP(s.last_activity)) <= $limit) ". " UNIX_TIMESTAMP(s.last_activity)) <= $limit) ".
...@@ -424,7 +424,7 @@ sub WideAreaPeople() ...@@ -424,7 +424,7 @@ sub WideAreaPeople()
{ {
my $query_result = my $query_result =
DBQueryFatal("SELECT DISTINCT u.usr_email from projects as p ". DBQueryFatal("SELECT DISTINCT u.usr_email from projects as p ".
"left join group_membership as m on m.pid=p.pid ". "left join group_membership as m on m.pid_idx=p.pid_idx ".
"left join users as u on u.uid_idx=m.uid_idx ". "left join users as u on u.uid_idx=m.uid_idx ".
"where p.approved!=0 and p.pcremote_ok is not null ". "where p.approved!=0 and p.pcremote_ok is not null ".
" and m.trust!='none' and u.status='active' ". " and m.trust!='none' and u.status='active' ".
...@@ -465,7 +465,7 @@ sub ProjectLists($$) ...@@ -465,7 +465,7 @@ sub ProjectLists($$)
($MAILMANSUPPORT ? ($MAILMANSUPPORT ?
", u.uid ,u.usr_name, u.mailman_password " : "") . ", u.uid ,u.usr_name, u.mailman_password " : "") .
" from group_membership as p ". " from group_membership as p ".
"left join users as u on u.uid=p.uid ". "left join users as u on u.uid_idx=p.uid_idx ".
"where p.pid='$pid' and p.gid='$gid' and ". "where p.pid='$pid' and p.gid='$gid' and ".
" p.trust!='none' and u.status='active' ". " p.trust!='none' and u.status='active' ".
"order by u.usr_email"); "order by u.usr_email");
......
...@@ -2604,13 +2604,14 @@ sub TBNodeUpdateAccountsByUID($) ...@@ -2604,13 +2604,14 @@ sub TBNodeUpdateAccountsByUID($)
{ {
my ($uid) = @_; my ($uid) = @_;
DBQueryFatal("update users set usr_modified=now() where uid='$uid'"); DBQueryFatal("update users set usr_modified=now() ".
"where uid='$uid' and status!='archived'");
my $query_result = my $query_result =
DBQueryFatal("select p.pid,pcremote_ok from users as u ". DBQueryFatal("select p.pid,pcremote_ok from users as u ".
"left join group_membership as g on ". "left join group_membership as g on ".
" u.uid_idx=g.uid_idx and g.pid=g.gid ". " u.uid_idx=g.uid_idx and g.pid_idx=g.gid_idx ".
"left join projects as p on p.pid=g.pid ". "left join projects as p on p.pid_idx=g.pid_idx ".
"where u.uid='$uid' and u.status='active' and ". "where u.uid='$uid' and u.status='active' and ".
" p.pid is not null"); " p.pid is not null");
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group. # Copyright (c) 2000-2002, 2010 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
...@@ -19,6 +19,7 @@ sub checkGroup ($$); ...@@ -19,6 +19,7 @@ sub checkGroup ($$);
# #
use lib '@prefix@/lib'; use lib '@prefix@/lib';
use libdb; use libdb;
use User;
my $TB = "@prefix@"; my $TB = "@prefix@";
my $SETGROUPS = "$TB/sbin/setgroups"; my $SETGROUPS = "$TB/sbin/setgroups";
...@@ -41,13 +42,19 @@ if (($UID != 0) && (!TBAdmin($UID))) { ...@@ -41,13 +42,19 @@ if (($UID != 0) && (!TBAdmin($UID))) {
my %opt = (); my %opt = ();
getopts('rhpa',\%opt); getopts('rhpa',\%opt);
my ($uid, @gid); my ($uid, $uid_idx, @gid);
if ($opt{a} || $opt{r}) { if ($opt{a} || $opt{r}) {
if (@ARGV < 2) { if (@ARGV < 2) {
die "Not enough arguments - see '$0 -h' for help\n"; die "Not enough arguments - see '$0 -h' for help\n";
} }
$uid = shift @ARGV; $uid = shift @ARGV;
@gid = @ARGV; @gid = @ARGV;
my $target_user = User->Lookup($uid);
if (!defined($target_user)) {
die "No such active user $uid exists\n";
}
$uid_idx = $target_user->uid_idx();
} else { } else {
if (@ARGV != 0) { if (@ARGV != 0) {
die "Too many arguments - see '$0 -h' for help\n"; die "Too many arguments - see '$0 -h' for help\n";
...@@ -74,12 +81,12 @@ if ($opt{p}) { ...@@ -74,12 +81,12 @@ if ($opt{p}) {
# #
foreach my $gid (@gid) { foreach my $gid (@gid) {
print "Adding user $uid to group $gid in the database\n"; print "Adding user $uid to group $gid in the database\n";
if (checkGroup($uid,$gid)) { if (checkGroup($uid_idx,$gid)) {
warn "User $uid is already in group $gid, skipping ...\n"; warn "User $uid is already in group $gid, skipping ...\n";
next; next;
} else { } else {
DBQueryFatal("INSERT INTO unixgroup_membership SET uid='$uid', " . DBQueryFatal("INSERT INTO unixgroup_membership SET ".
"gid='$gid'"); " uid='$uid', uid_idx='$uid_idx', gid='$gid'");
} }
} }
...@@ -94,12 +101,12 @@ if ($opt{p}) { ...@@ -94,12 +101,12 @@ if ($opt{p}) {
# #
foreach my $gid (@gid) { foreach my $gid (@gid) {
print "Removing $uid from group $gid in the database\n"; print "Removing $uid from group $gid in the database\n";
if (!checkGroup($uid,$gid)) { if (!checkGroup($uid_idx,$gid)) {
warn "User $uid is not in group $gid, skipping ...\n"; warn "User $uid is not in group $gid, skipping ...\n";
next; next;
} else { } else {
DBQueryFatal("DELETE FROM unixgroup_membership WHERE uid='$uid' " . DBQueryFatal("DELETE FROM unixgroup_membership ".
"AND gid='$gid'"); "WHERE uid_idx='$uid_idx' AND gid='$gid'");
} }
} }
...@@ -126,8 +133,9 @@ if ($opt{p}) { ...@@ -126,8 +133,9 @@ if ($opt{p}) {
# if not. # if not.
# #
sub checkGroup ($$) { sub checkGroup ($$) {
my ($uid,$gid) = @_; my ($uid_idx,$gid) = @_;
my $result = DBQueryFatal("SELECT gid,uid FROM unixgroup_membership WHERE ". my $result = DBQueryFatal("SELECT gid,uid FROM unixgroup_membership WHERE ".
"uid='$uid' AND gid='$gid'"); "uid_idx='$uid_idx' AND gid='$gid'");
return ($result->num_rows() > 0); return ($result->num_rows() > 0);
} }
/* /*
* EMULAB-COPYRIGHT * EMULAB-COPYRIGHT
* Copyright (c) 2000-2003, 2006 University of Utah and the Flux Group. * Copyright (c) 2000-2010 University of Utah and the Flux Group.
* All rights reserved. * All rights reserved.
*/ */
...@@ -86,6 +86,12 @@ dbclose(void) ...@@ -86,6 +86,12 @@ dbclose(void)
mydb_disconnect(); mydb_disconnect();
} }
unsigned long
mydb_escape_string(char *to, const char *from, unsigned long length)
{
return mysql_real_escape_string(&db, to, from, length);
}
MYSQL_RES * MYSQL_RES *
mydb_query(char *query, int ncols, ...) mydb_query(char *query, int ncols, ...)
{ {
......
/* /*
* EMULAB-COPYRIGHT * EMULAB-COPYRIGHT
* Copyright (c) 2000-2003, 2006 University of Utah and the Flux Group. * Copyright (c) 2000-2010 University of Utah and the Flux Group.
* All rights reserved. * All rights reserved.
*/ */
...@@ -33,4 +33,6 @@ int mydb_seteventschedulerpid(char *pid, char *eid, int processid); ...@@ -33,4 +33,6 @@ int mydb_seteventschedulerpid(char *pid, char *eid, int processid);
*/ */
MYSQL_RES *mydb_query(char *query, int ncols, ...); MYSQL_RES *mydb_query(char *query, int ncols, ...);
int mydb_update(char *query, ...); int mydb_update(char *query, ...);
unsigned long mydb_escape_string(char *to, const char *from,
unsigned long length);
/* /*
* EMULAB-COPYRIGHT * EMULAB-COPYRIGHT
* Copyright (c) 2000-2003, 2006 University of Utah and the Flux Group. * Copyright (c) 2000-2003, 2006, 2010 University of Utah and the Flux Group.
* All rights reserved. * All rights reserved.
*/ */
...@@ -142,7 +142,8 @@ main(int argc, char **argv) ...@@ -142,7 +142,8 @@ main(int argc, char **argv)
USERNODE, hstrerror(h_errno)); USERNODE, hstrerror(h_errno));
exit(-1); exit(-1);
} }
strncpy(opshostname, he->h_name, strlen(opshostname)); strncpy(opshostname, he->h_name, sizeof(opshostname));
if (bp = strchr(opshostname, '.')) if (bp = strchr(opshostname, '.'))
*bp = 0; *bp = 0;
...@@ -194,10 +195,12 @@ doit(gzFile *infp) ...@@ -194,10 +195,12 @@ doit(gzFile *infp)
{ {
int i, skip = 0; int i, skip = 0;
time_t curtime, ll_time; time_t curtime, ll_time;
char *user, node[64], prog[128]; char *user, node[TBDB_FLEN_NODEID * 2], prog[128];
char buf[BUFSIZ], *bp; char buf[BUFSIZ], *bp, uid_idx[128], tmp[BUFSIZ];
struct tm tm; struct tm tm;
MYSQL_RES *dbres;
MYSQL_ROW dbrow;
while (1) { while (1) {
if (gzgets(infp, buf, BUFSIZ) == NULL) if (gzgets(infp, buf, BUFSIZ) == NULL)
break; break;
...@@ -315,31 +318,56 @@ doit(gzFile *infp) ...@@ -315,31 +318,56 @@ doit(gzFile *infp)
if (strcasecmp(user, "ROOT") == 0) if (strcasecmp(user, "ROOT") == 0)
continue; continue;
dbres = mydb_query("select uid_idx from users where uid='%s' ",
1, user);
if (!dbres) {
syslog(LOG_ERR, "DB error getting user %s", user);
continue;
}
if (!mysql_num_rows(dbres)) {
syslog(LOG_INFO, "No DB record for user %s", user);
mysql_free_result(dbres);
continue;
}
dbrow = mysql_fetch_row(dbres);
strncpy(uid_idx, dbrow[0], sizeof(uid_idx));
mysql_free_result(dbres);
/*
* Safety first.
*/
mydb_escape_string(tmp, uid_idx, strlen(uid_idx));
strcpy(uid_idx, tmp);
mydb_escape_string(tmp, node, strlen(node));
strcpy(node, tmp);
if (mydb_update("replace into uidnodelastlogin " if (mydb_update("replace into uidnodelastlogin "
"(uid, node_id, date, time) " "(uid, uid_idx, node_id, date, time) "
"values ('%s', '%s', " "values ('%s', '%s', '%s', "
" FROM_UNIXTIME(%ld, '%%Y-%%m-%%d'), " " FROM_UNIXTIME(%ld, '%%Y-%%m-%%d'), "
" FROM_UNIXTIME(%ld, '%%T')) ", " FROM_UNIXTIME(%ld, '%%T')) ",
user, node, ll_time, ll_time) == 0) user, uid_idx, node, ll_time, ll_time) == 0)
break; break;
if (strncmp(node, opshostname, strlen(node)) == 0 || if (strncmp(node, opshostname, strlen(node)) == 0 ||
strncmp(node, "ops", strlen(node)) == 0) { strncmp(node, "ops", strlen(node)) == 0) {
if (mydb_update("replace into userslastlogin " if (mydb_update("replace into userslastlogin "
"(uid, date, time) " "(uid, uid_idx, date, time) "
"values ('%s', " "values ('%s', '%s', "
" FROM_UNIXTIME(%ld, '%%Y-%%m-%%d'), " " FROM_UNIXTIME(%ld, '%%Y-%%m-%%d'), "
" FROM_UNIXTIME(%ld, '%%T')) ", " FROM_UNIXTIME(%ld, '%%T')) ",
user, ll_time, ll_time) == 0) user, uid_idx, ll_time, ll_time) == 0)
break; break;
} }
else { else {
if (mydb_update("replace into nodeuidlastlogin " if (mydb_update("replace into nodeuidlastlogin "
"(node_id, uid, date, time) " "(node_id, uid_idx, uid, date, time) "
"values ('%s', '%s', " "values ('%s', '%s', '%s', "
" FROM_UNIXTIME(%ld, '%%Y-%%m-%%d'), " " FROM_UNIXTIME(%ld, '%%Y-%%m-%%d'), "
" FROM_UNIXTIME(%ld, '%%T')) ", " FROM_UNIXTIME(%ld, '%%T')) ",
node, user, ll_time, ll_time) == 0) node, uid_idx, user, ll_time, ll_time) == 0)
break; break;
} }
} }
......
...@@ -2310,6 +2310,7 @@ DROP TABLE IF EXISTS `nodeuidlastlogin`; ...@@ -2310,6 +2310,7 @@ DROP TABLE IF EXISTS `nodeuidlastlogin`;
CREATE TABLE `nodeuidlastlogin` ( CREATE TABLE `nodeuidlastlogin` (
`node_id` varchar(32) NOT NULL default '', `node_id` varchar(32) NOT NULL default '',
`uid` varchar(10) NOT NULL default '', `uid` varchar(10) NOT NULL default '',
`uid_idx` mediumint(8) unsigned NOT NULL default '0',
`date` date default NULL, `date` date default NULL,
`time` time default NULL, `time` time default NULL,
PRIMARY KEY (`node_id`) PRIMARY KEY (`node_id`)
...@@ -3350,6 +3351,7 @@ CREATE TABLE `traces` ( ...@@ -3350,6 +3351,7 @@ CREATE TABLE `traces` (
DROP TABLE IF EXISTS `uidnodelastlogin`; DROP TABLE IF EXISTS `uidnodelastlogin`;
CREATE TABLE `uidnodelastlogin` ( CREATE TABLE `uidnodelastlogin` (
`uid` varchar(10) NOT NULL default '', `uid` varchar(10) NOT NULL default '',
`uid_idx` mediumint(8) unsigned NOT NULL default '0',
`node_id` varchar(32) NOT NULL default '', `node_id` varchar(32) NOT NULL default '',
`date` date default NULL, `date` date default NULL,
`time` time default NULL, `time` time default NULL,
...@@ -3363,6 +3365,7 @@ CREATE TABLE `uidnodelastlogin` ( ...@@ -3363,6 +3365,7 @@ CREATE TABLE `uidnodelastlogin` (
DROP TABLE IF EXISTS `unixgroup_membership`; DROP TABLE IF EXISTS `unixgroup_membership`;
CREATE TABLE `unixgroup_membership` ( CREATE TABLE `unixgroup_membership` (
`uid` varchar(8) NOT NULL default '', `uid` varchar(8) NOT NULL default '',
`uid_idx` mediumint(8) unsigned NOT NULL default '0',
`gid` varchar(16) NOT NULL default '', `gid` varchar(16) NOT NULL default '',
PRIMARY KEY (`uid`,`gid`) PRIMARY KEY (`uid`,`gid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
...@@ -3374,6 +3377,7 @@ CREATE TABLE `unixgroup_membership` ( ...@@ -3374,6 +3377,7 @@ CREATE TABLE `unixgroup_membership` (
DROP TABLE IF EXISTS `user_policies`; DROP TABLE IF EXISTS `user_policies`;
CREATE TABLE `user_policies` ( CREATE TABLE `user_policies` (
`uid` varchar(8) NOT NULL default '', `uid` varchar(8) NOT NULL default '',
`uid_idx` mediumint(8) unsigned NOT NULL default '0',
`policy` varchar(32) NOT NULL default '', `policy` varchar(32) NOT NULL default '',
`auxdata` varchar(64) NOT NULL default '', `auxdata` varchar(64) NOT NULL default '',
`count` int(10) NOT NULL default '0', `count` int(10) NOT NULL default '0',
...@@ -3519,7 +3523,7 @@ CREATE TABLE `users` ( ...@@ -3519,7 +3523,7 @@ CREATE TABLE `users` (
`wikionly` tinyint(1) default '0', `wikionly` tinyint(1) default '0',
`mailman_password` tinytext, `mailman_password` tinytext,
PRIMARY KEY (`uid_idx`), PRIMARY KEY (`uid_idx`),
UNIQUE KEY `uid` (`uid`),