in reply to Running Perl program via Sendmail
The problem as you originally stated it was:
My suggestion was to either have an alias that piped the message into a script, which stored the message in a temporary file, parsed the /etc/passwd file, and then sent the message back to Sendmail, and delete the temporary file
or
Roll your own useradd
Now, the reason your solution didn't work is because you didn't let the script re-initiate Sendmail - and because one of the other security concerns I raised (you still have Sendmail's default user set to daemon).
Here is some pseudo code to help you get started
1. Read in the message piped to the script line by line 2. Append the data to a temporary file 3. Do not write the "from" line or the "to" line to file 4. Save the "from" off into a variable 5. Parse the /etc/passwd to build a "recipient" list 6. system (cat $tmp|sendmail -bm -f"$from" "$recip");
You also want to consider the following security precautions:
The code might look something like:
#/usr/bin/perl -w use strict; open (TMPOUT,">/tmp/somefile"); my $from; my @recipients; while (<>) { print TMPOUT unless (/^From: /i || /^To: /i); ($from = $_) =~ /Some regex to get from/ if (/^From: /i); } close (TMPOUT); open (PASSWD,"/etc/passwd"); while (<PASSWD>) { my @fields = split ":" , $_; push @recip , $fields[0] unless (#system account); } system (cat /tmp/somefile|sendmail -bm -f"$from" "@recips"); unlink "/tmp/somefile";
This is just to give you an IDEA of how to do it
Cheers - L~R
Update: Per jaques's request, I included sample code to go along with the pseudo code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Running Perl program via Sendmail
by jacques (Priest) on Feb 17, 2003 at 20:31 UTC |