Okay, so here's what I'm trying to accomplish: I'm trying to configure /etc/mail/access so that it rejects mail to unknown users in order to prevent backscatter spam. I've gotten it all set up, but now I'm trying to write a script which will update the /etc/mail/access file with new email addresses. Here's what I have so far:
1) I grab the current users from /etc/features
cut -d *.* -f1 /etc/features > /etc/features.tmp
Here's an example of what the /etc/features file holds.
before:
root:mail=0,ftp=0,description=root
ftp:mail=-1,ftp=-1,description=Anonymous FTP
office:mail=10,ftp=-1,description=Company - Receptionist
msmith:mail=40,ftp=-1,description=Company - Mark Smith
johnson:mail=25,ftp=-1,description=Michael Johnson
...
after:
root
ftp
office
msmith
johnson
Next, I need to add aliases to this list.
praliases | egrep -v "(^#.*|^$)"
I later found out that the target server I'm running this on doesn't have egrep and I can't install software on it accept a subset of applications that the hosting provider supplies. I need a new way to do this (perhaps just with grep)
Next, I run this list through sort and uniq.
The last step is the one I'm having the most trouble with. I am trying to add these usernames to the /etc/mail/access file while conforming to the file's structure.
Here's the file now:
# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package.
#
# by default we allow relaying from localhost...
localhost.localdomain RELAY
localhost RELAY
127.0.0.1 RELAY
#To:mydomain.com RELAY
To:mydomain.com error:5.1.1: "550 User unknown"
Connect:mydomain.com RELAY
...and here's what it should be:
# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package.
#
# by default we allow relaying from localhost...
localhost.localdomain RELAY
localhost RELAY
127.0.0.1 RELAY
#To:mydomain.com RELAY
To:mydomain.com error:5.1.1: "550 User unknown"
To:root@mydomain.com RELAY
To:ftp@mydomain.com RELAY
To
ffice@mydomain.com RELAY
To:msmith@mydomain.com RELAY
To:johnson@mydomain.com RELAY
Connect:mydomain.com RELAY
I don't know if the Connect:mydomain.com has to be the last line in the config file or not, but if not, I imagine we could just append new entries to the bottom of the list. That would make things simple. My thoughts are:
grep out usernames and aliases, sort them, remove duplicates, compare them to the current list of usernames/aliases and put any of the new ones in the access file (appending "To:" and "@mydomain.com RELAY" of course.)