From: Ian Jackson Date: Fri, 30 Aug 2013 14:46:50 +0000 (+0100) Subject: fixes for comments X-Git-Tag: test~44 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?p=d.git;a=commitdiff_plain;h=a44df87d9f60a771d23ce4b89080ff02b4d3bf2f fixes for comments --- diff --git a/fyvzl b/fyvzl index 24ad9ae..8fe4e73 100755 --- a/fyvzl +++ b/fyvzl @@ -11,12 +11,14 @@ options END our $usage2 = <<'END'; actions - create [REDIRECT-TO] [#comment] - update LOCAL-PART [REDIRECT-TO] [#comment] - reject LOCAL-PART + create [REDIRECT] [#COMMENT] + update LOCAL-PART [REDIRECT] [#COMMENT] show LOCAL-PART list list-actions +empty value for REDIRECT means reject +END +our $usage3 = <<'END'; privileged actions list-user USER insert-exact LOCAL-PART USER REDIRECT COMMENT @@ -68,7 +70,7 @@ sub prow ($) { } my $pa = $row->{'localpart'}; $pa .= '@'.$dom if defined $dom; - if (defined $row->{'redirect'}) { + if (length $row->{'redirect'}) { print "$pa: $row->{'redirect'}" or die $!; } else { print "# reject $pa" or die $!; @@ -94,7 +96,10 @@ sub goodrand ($) { sub qualify (\$) { my ($ref) = @_; - if (defined $$ref && $$ref !~ m/\@/) { + if (defined $$ref && $$ref =~ m/[^\041-\177]/) { + die "bad characters in redirection target\n"; + } + if (defined $$ref && length $$ref && $$ref !~ m/\@/) { die "unqualified redirection target\n" unless defined $qualdom; $$ref .= '@'.$qualdom; } @@ -187,15 +192,6 @@ sub action_update { prow($row); } -sub action_reject { - my $localpart = nextarg; - nomoreargs; - begin_row($localpart); - $dbh->do("UPDATE addrs SET redirect=NULL WHERE localpart=?", - {}, $localpart); - $dbh->commit; -} - sub action_show { my $localpart = nextarg; nomoreargs; @@ -222,11 +218,12 @@ sub action_list_user { sub action_insert_exact { die unless $priv; - my $localpart = nextarg; - $user = nextarg; - my $redirect = nextarg; + my $row = { }; + $row->{'localpart'} = nextarg; + $row->{'user'} = $user = nextarg; + $row->{'redirect'} = nextarg; + $row->{'comment'} = nextarg; nomoreargs; - my $row = {'localpart'=>$localpart, 'user'=>$user, 'redirect'=>$redirect}; insertrow($row); $dbh->commit; } @@ -279,7 +276,7 @@ while (@ARGV) { } elsif (s/^-C/-/) { $showcomment = 1; } elsif (s/^-h/-/) { - print $usage1.$usage2 or die $!; + print $usage1.$usage2.$usage3 or die $!; exit 0; } else { die "unknown option \`$_'\n"; diff --git a/schema b/schema index 58c8ece..a137f2b 100644 --- a/schema +++ b/schema @@ -1,7 +1,7 @@ CREATE TABLE addrs ( localpart STRING PRIMARY KEY, user STRING NOT NULL, - redirect STRING, + redirect STRING NOT NULL, comment STRING NOT NULL ); CREATE TABLE disabled_users (