From 78b4186921c29ee5e12727198770cc8645e3d127 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 30 Aug 2013 14:53:38 +0100 Subject: [PATCH] better usage --- fyvzl | 46 +++++++++++++++++++++++++++++++++------------- fyvzl.service | 2 +- slimy-rot13-mail | 5 +++++ 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/fyvzl b/fyvzl index 3ccae97..4fa8fbd 100755 --- a/fyvzl +++ b/fyvzl @@ -1,17 +1,21 @@ #!/usr/bin/perl -w -# -# usage: ../fyvzl [-lLENGTH] [-mMAXPERUSER] [-dDOM] [-qQUALDOM] DATABASE-FILE ACTION ARG -# actions -# create [REDIRECT-TO] -# update LOCAL-PART REDIRECT-TO -# reject LOCAL-PART -# show LOCAL-PART -# list -# privileged actions -# list-user USER -# insert-exact LOCAL-PART USER REDIRECT -# donate LOCAL-PART USER -# enable-user|disable-user USER +our $usage1 = <<'END'; +usage: ../fyvzl [-lLENGTH] [-mMAXPERUSER] [-dDOM] [-qQUALDOM] DATABASE-FILE ACTION ARG +END +our $usage2 = <<'END'; +actions + create [REDIRECT-TO] + update LOCAL-PART REDIRECT-TO + reject LOCAL-PART + show LOCAL-PART + list + list-actions +privileged actions + list-user USER + insert-exact LOCAL-PART USER REDIRECT + donate LOCAL-PART USER + enable-user|disable-user USER +END use strict; @@ -98,6 +102,11 @@ sub action_create { $redirect = qualify $redirect; open R, "/dev/urandom" or die $!; binmode R; + my $countq = $dbh->prepare("SELECT count(*) FROM addrs WHERE user=?"); + $countq->execute($user); + my ($count) = $countq->fetchrow_array(); + die unless defined $count; + die "too many aliases for this user\n" if $count >= $maxperuser; my $q = $dbh->prepare("SELECT localpart FROM addrs WHERE localpart=?"); my $s; for (;;) { @@ -211,6 +220,10 @@ sub action_disable_user { $dbh->commit; } +sub action_list_actions { + print $usage2 or die $!; +} + while (@ARGV) { last unless $ARGV[0] =~ m/^-/; $_ = shift @ARGV; @@ -223,6 +236,8 @@ while (@ARGV) { $dom = $1; } elsif (m/^-q(\S+)$/) { $qualdom = $1; + } elsif (m/^-h$/) { + print $usage1.$usage2 or die $!; } else { die "unknown option \`$_'\n"; } @@ -238,6 +253,11 @@ if (defined $ENV{'USERV_USER'}) { $user = ((getpwuid $<)[0]) or die; } +$usage2 .= "LOCAL-PART is implicitly qualified with \@$dom\n" + if defined $qualdom; +$usage2 .= "REDIRECT is implicitly qualified with \@$qualdom if it has no \@\n" + if defined $qualdom; + $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","", { PrintError => 0, AutoCommit => 0, RaiseError => 1 }) or die "$dbfile $!"; diff --git a/fyvzl.service b/fyvzl.service index e9d1921..b8079b0 100644 --- a/fyvzl.service +++ b/fyvzl.service @@ -7,5 +7,5 @@ if ( grep calling-user-shell /etc/shells no-disconnect-hup no-suppress-args execute /usr/local/lib/fyvzl/fyvzl -dfyvzl.net \ - -qchiark.greenend.org.uk /var/lib/mail/fyvzl.db + -qchiark.greenend.org.uk /var/lib/fyvzl/fyvzl.db fi diff --git a/slimy-rot13-mail b/slimy-rot13-mail index b1c06f0..c7ec9f9 100755 --- a/slimy-rot13-mail +++ b/slimy-rot13-mail @@ -1,3 +1,8 @@ #!/bin/sh set -e +case "$#.$1" in +0.|1.-h) + echo "usage: slimy-rot13-mail ACTION ARG..." + set list-actions +esac exec userv mail fyvzl "$@" -- 2.30.2