Subject: Re: Help for a procmail newbie? (or: how to make an ftpemail server)

From: Adam Shostack <[email-masked]>
Date: Wed, 10 Aug 94 16:22:29 EDT

I've been mucking with the idea of a fileserver in email for a
little while, to support ftp via true anonymity servers. (Julf's
server in finland, cypherpunk remailers, etc.)

	There are a number of issues.  First is to ensure that the
remote user can only do what you ok.  This rules out their use of the
characters outside the set '[-_/A-Za-z].  (other characters may have
evil meta-meanings.)

	A procmail rule like the following (untested) one should do
most of what you want.  The regexp (regular expression) +$ means one
or more matches on the preceeding one character regexp, followed by
eol.  anything in [] is a one character regexp.  Thus, they can't
request ../../../../../../../etc/passwd, can't request SEND FILE foo;
rm -rf $HOME, or do any other nasty things that might happen if you
let random characters in.  I think letting a space in is ok, but I'm
not sure.

	Having files called help, list, and index simplify what needs
to be done in procmail.  A small makefile could create each of those
files.

 :0 D			# Without D, sed recipie will fail.
 * ^Subject: SEND FILE [-_/A-Za-z]+$
 * !^FROM_DAEMON
 {
    FILE=`formail -x Subject: | sed 's/SEND FILE//'`

    :
    (formail -r -A"Precedence: junk";\
       cat $HOME/.outbound/$FILE;\
    ) | $SENDMAIL -t

    :
    $HOME/.outbound/.log
 }

	Put and replace are problematic.  SMTP is easily forged.  If I
know what your authorization lists look like, I can place whatever
files I want in your site.  Consider requiring put/replace commands to
be PGP signed.  A put recepie could pipe to a small sed script which
would delete header lines until 'Begin PGP Signed Message'  (Is there
a tail replacement that will print everything following a regexp?)
The message would then be checked by PGP and reacted to.

You wrote:

| I'd like to allow any to send a command embedded in a Subject line to
| one id which would have access to a specific set of directories. While
| the information is already available via ftp, gopher, and WWW, a
| significant number of people who would like to access it only have
| email, and the ftpemail servers I know about don't meet my needs.
| 
| The one id would have update access to all my files. This way, I don't
| have to directly give dozens of people update access, and the bill for
| using the filespace goes to only one id.
| 
| I only need to support ASCII files at this point.
| 
| I'd like to allow the following commands in the Subject line:
| help  - return a specific help file
| get /filepath - this filepath would always be appended onto
|  /ftp/nonprofits/dance  so it can only be used to access my information.
|  (Eventually, I'd like to make this keyword oriented for easier use.
|   For instance, 'get dancing-usa-mag 01/94' would look up a table to
|   find what filepath to use for this magazine and then return all the
|   files with that date. (The naming convention of magazine files would
|   include a four digit date (yymm) ...) )
| 
| Perhaps also:
| ls /filepath - to return directory
| 
| I'd also like to allow files to be put into the ftp directories using
| two commands:
| put /filepath - same as get except the body of the email would contain
|   whatever is to be put into file to be stored. Should also do a chmod
|   to make file available via ftp.
|   I'd like to have a lookup authorization table, so not everybody could
|   store whatever files they wanted, but I'm not sure how specific the
|   authorization should get (ie some people might be able to update an
|   entire directory while others could only update 1 file.)
| 
| repl /filepath - same as put except instead of adding a new file,
|   replaces one already there. In some cases, authorization may only
|   allow repl, but not put.
| 
| I'd probably want to log all put and repl attempts and return error
| messages to the sender if the put/repl failed for some reason.
| Put and repl should strip off all headers except From:, Date: and
| Subject:.
| 
| Can anyone point me to sample files that do this sort of thing? Even
| partial implementations would be very helpful.

-- 
Adam Shostack 				       [email-masked]

Politics.  From the greek "poly," meaning many, and ticks, a small,
annoying bloodsucker.