Link to home
Start Free TrialLog in
Avatar of steph84
steph84

asked on

mail ok in command line, not in scripts

I set up tcpwrapper on a linux machine.
It works fine (non-authorized hosts are banned), but in the deny file, I put the shell command (echo "sthing" | mail me@home.com). I know that this command line is executed with sh shell, which works fine on the linux machine.
If someone is banned I must receive the mail (It works perfectly on IRIX 6.3, exactly with the same shell command) and I receive nothing.
If I enter echo "sthing" | mail me@home.com under command line mode, I receive the mail.
Any suggestion?? Thanks.
Avatar of ozo
ozo
Flag of United States of America image

Is mail in your PATH?  What if you give an absolute path name?
Avatar of Tuff
Tuff

I'm still kinda new to UNIX but in a perl script when you put in an email address it has to be written as such

anyname\@yourdomain.com

could this be possible?


It doesn't have to be written as such.  It could also be written as
q(anyname@yourdomain.com)
But it sounds like steph84 is talking about a script for sh, not perl.
What ozo suggests is probably correct.  Give the absolute path to the mail program (/bin/mail or /usr/bin/Mail).  System shell scripts should have a very restricted PATH set up so that there's minimal opportunity for a trojan horse to slip in.

Avatar of steph84

ASKER

I could try it today, it sounded nice but unfortunately, it didn't work....
Quite strange.
Lets see the script.
What shell is it, tcsh or csh ?
Avatar of steph84

ASKER

(echo "client info: " %c "\nserver info: " %s "\ndate: " `date`) | /usr/bin/mail security@imaginet.fr

The %c and %s values are obtained by the wrapper and work fine.
According tcpwrapper man page, the shell command is interpreted by sh....

How about using thr full path to `date`?

Avatar of steph84

ASKER

just as before,arghh!!!!
It's not very very very important if it doesn't work, but I'd like to understand...
I've increase to 150!

How about:
(/usr/bin/echo "client info: " %c; /usr/bin/echo "server info: " %s ; /usr/bin/echo "date: "; /usr/bin/date) | /usr/bin/mailsecurity@imaginet.fr

Do you get any error messages?
Avatar of steph84

ASKER

I tried! Nothing, no mail,no error message, nothing.
I even tried (/usr/bin/echo "foo")|/usr/bin/mail security@imaginet.fr
I'm tired of this....
I'm going to make two possible answers for this:
1) Are your permissions set on your mail program properly (i.e.  world executable)?
TCP Wrappers run shell commands as nobody, so that could cause a problem

2) Did you use the proper syntax if you're using the extended options?    
Tcp Wrappers can be compiled to use either the standard options or a much more flexible extended options.  If the second case is true, the following is an example hosts.deny:
ALL:ALL: twist echo "sthing" | mail  root@localhost

That will cause that command to be executed in place of the service daemon. I tried this example on my machine, and it worked fine.

Hope this helps.
Matt Zito
I had tried the following script and work just fine in a SUN Solaris 2.5.1.

#!/bin/sh

echo "sthing" | mail antonio@leia

I had tried the following script and work just fine in a SUN Solaris 2.5.1.

#!/bin/sh

echo "sthing" | mail me@machine

That may even be an answer to the original question if you can get your tcpwrapper to call the script.
Avatar of steph84

ASKER

Sorry but this script work fine, even on my Irix 6.3, but not under tcpwrapper on the linux machine, That's my problem!
I've not enough time right now to try other things.....

Avatar of steph84

ASKER

Try others things recently, nothing worked.
mail work correctly, tried with whole path, with just echo "smthing" | mail, all rights are ok, ans exactly the same commans works under Irix.
Perhaps a bug from tcpwrapper under my version of linux.....

if you are not sure if tcpwrapper call the script at all, try to do something what 100% does not need tty in the script (cp something_existing /tmp). If the file appears in /tmp, the script was called.

BTW, I do not know tcpwrapper, but if it runs under "nobody", what are permissions on the script you want to be run ??
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial