chiark / gitweb /
fixes for comments
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 30 Aug 2013 14:46:50 +0000 (15:46 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 30 Aug 2013 14:46:50 +0000 (15:46 +0100)
fyvzl
schema

diff --git a/fyvzl b/fyvzl
index 24ad9ae7775572040396425a0e50862247acb56e..8fe4e73c429548124cafbe0a0149ff41817655e7 100755 (executable)
--- 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 58c8ecea22c0589a750208e14fe02b1b3cef8d03..a137f2b6639b409b1d40cb7410d431871e514932 100644 (file)
--- 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 (