Commit 46ed20e6 authored by Leigh Stoller's avatar Leigh Stoller

Change the user_pubkeys to not use the comment field as an index.

Bad idea. Use an auto_incrementing idx field instead.
parent 16107959
......@@ -25,7 +25,7 @@ sub usage()
print " -i Initialize mode; generate initial key for user\n";
exit(-1);
}
my $optlist = "knaiw";
my $optlist = "kniw";
my $iskey = 0;
my $verify = 0;
my $initmode = 0;
......@@ -279,7 +279,7 @@ sub ParseKey($) {
}
#
# Make up a comment field for the DB index. Need something.
# Make up a comment field for the DB.
#
if (!defined($comment)) {
$comment = "$type-${user_email}";
......@@ -287,7 +287,7 @@ sub ParseKey($) {
$key = "$key $comment";
DBQueryFatal("replace into user_pubkeys ".
"values ('$user', '$comment', '$key', now())");
"values ('$user', 0, '$key', now(), '$comment')");
#
# Mark user record as modified so nodes are updated.
......
......@@ -1063,10 +1063,11 @@ CREATE TABLE unixgroup_membership (
CREATE TABLE user_pubkeys (
uid varchar(8) NOT NULL default '',
comment varchar(128) NOT NULL default '',
idx int(10) unsigned NOT NULL auto_increment,
pubkey text,
stamp datetime default NULL,
PRIMARY KEY (uid,comment)
comment varchar(128) NOT NULL default '',
PRIMARY KEY (uid,idx)
) TYPE=MyISAM;
--
......
......@@ -82,4 +82,25 @@ last_net_act,last_cpu_act,last_ext_act);
alter table virt_lans add nobwshaping tinyint(4) default '0' \
after uselinkdelay;
Nothing special needs to be done.
\ No newline at end of file
Nothing special needs to be done.
1.119: Change user_pubkeys to use an idx for its unique index instead
of the comment field in the key (a really dumb idea I had).
However, adding an auto_increment field is always a pain. So:
CREATE TABLE user_pubkeys_new (
uid varchar(8) NOT NULL default '',
idx int(10) unsigned NOT NULL auto_increment,
pubkey text,
stamp datetime default NULL,
comment varchar(128) NOT NULL default '',
PRIMARY KEY (uid,idx)
) TYPE=MyISAM;
insert into user_pubkeys_new (uid, idx, pubkey, stamp, comment)
select uid, 0, pubkey, stamp, comment from
user_pubkeys;
rename table user_pubkeys to user_pubkeys_old,
user_pubkeys_new to user_pubkeys;
drop table user_pubkeys_old;
......@@ -1333,7 +1333,7 @@ COMMAND_PROTOTYPE(doaccounts)
/*
* Need a list of keys for this user.
*/
pubkeys_res = mydb_query("select comment,pubkey "
pubkeys_res = mydb_query("select idx,pubkey "
" from user_pubkeys "
"where uid='%s'",
2, row[0]);
......@@ -1354,7 +1354,7 @@ COMMAND_PROTOTYPE(doaccounts)
client_writeback(sock, buf, strlen(buf), tcp);
pubkeys_nrows--;
info("ACCOUNTS: PUBKEY LOGIN=%s COMMENT=%s\n",
info("ACCOUNTS: PUBKEY LOGIN=%s IDX=%s\n",
row[0], pubkey_row[0]);
}
}
......
......@@ -54,10 +54,10 @@ if (!$isadmin &&
#
$query_result =
DBQueryFatal("select * from user_pubkeys ".
"where uid='$target_uid' and comment='$key'");
"where uid='$target_uid' and idx='$key'");
if (! mysql_num_rows($query_result)) {
USERERROR("Public Key '$key' for user '$target_uid' does not exist!", 1);
USERERROR("Public Key for user '$target_uid' does not exist!", 1);
}
$row = mysql_fetch_array($query_result);
......@@ -130,7 +130,7 @@ TBMAIL("$targuid_name <$targuid_email>",
"Errors-To: $TBMAIL_WWW");
DBQueryFatal("delete from user_pubkeys ".
"where uid='$target_uid' and comment='$key'");
"where uid='$target_uid' and idx='$key'");
#
# update authkeys files and nodes.
......
......@@ -77,6 +77,7 @@ function SPITFORM($formfields, $errors)
$comment = $row[comment];
$pubkey = $row[pubkey];
$date = $row[stamp];
$idx = $row[idx];
$fnote = "";
if (strstr($comment, $BOSSNODE)) {
......@@ -87,7 +88,7 @@ function SPITFORM($formfields, $errors)
echo "<tr>
<td align=center>
<A href='deletepubkey.php3?target_uid=$target_uid" .
"&key=$comment'><img alt=X src=redball.gif></A>
"&key=$idx'><img alt=X src=redball.gif></A>
</td>
<td>$chunky</td>
</tr>\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment