Bug 430181

Summary: denyhosts doesn't run, says "Could not find environment variable: HOSTNAME"
Product: [Fedora] Fedora Reporter: Neal Becker <ndbecker2>
Component: denyhostsAssignee: Jason Tibbitts <j>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: medium    
Version: 8CC: dennis
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-01-26 18:32:48 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Neal Becker 2008-01-25 02:16:42 UTC
Description of problem:
No idea what's causing this.  It's running in daemon mode, but if I try to run 
from command line (to see why entries in my /var/log/secure don't seem to be 
in hosts.deny), it doesn't run:


python  /usr/bin/denyhosts.py --debug -c /etc/denyhosts.conf --file /var/log/secure
Could not find environment variable: HOSTNAME

echo $HOSTNAME
nbecker

Version-Release number of selected component (if applicable):
denyhosts-2.6-7.fc8

How reproducible:


Steps to Reproduce:
1.
2.
3.
  
Actual results:


Expected results:


Additional info:

Comment 1 Jason Tibbitts 2008-01-25 02:48:20 UTC
That output doesn't look like it comes from the currently shipping initscript. 
Are you sure your package is installed correctly?  Try rpm -V denyhosts.

The initscript sets HOSTNAME explicitly and very early:

# Make sure HOSTNAME is in the environment so denyhosts can
# use it in report subjects
HOSTNAME=$(hostname)
export HOSTNAME

so unless you don't have a /bin/hostname binary I don't see how it could
possibly not be set.

Comment 2 Jason Tibbitts 2008-01-25 02:50:14 UTC
And it looks like I can't read, sorry; someone else had reported a problem that
the initscript didn't get updated properly and it had exactly the same symptoms.

Honestly, the only think I can think of is that HOSTNAME isn't exported from
your environment.  I can't see anything there that looks like a bug in denyhosts.

Comment 3 Neal Becker 2008-01-25 10:44:01 UTC
And what about the fact that I can't run it from the command line, and as I 
showed, HOSTNAME _is_ set?

Comment 4 Jason Tibbitts 2008-01-25 15:47:55 UTC
You showed that it's set, bou didn't show that it's exported from your
environment.  My apologies if I assumed in error that you would know what that
meant; perhaps this will illustrate:

> echo $B

> B=blah
> echo $B
blah
> sh -c 'echo $B'

> export B
> sh -c 'echo $B'
blah

See, it is possible to have a variable which is set for your current shell but
not passed on to programs which are run from that shell.  So try typing "export
HOSTNAME" and then trying.

All denyhosts is doing is trying to expand the environment variables so that it
can fill in SMTP_SUBJECT, and all it does is this:
  env = os.environ.get(name)
  if not env:
      die("Could not find environment variable: %s" % name)
and that's simple enough that I can't see how HOSTNAME could be exported from
your environment and yet not accessible to that code.  If that still doesn't
work, though, you can change /etc/denyhosts.conf and remove the "$[HOSTNAME]"
bit from SMTP_SUBJECT and see if it will start without it.

One other thing which comes to mind, although I can't imagine why it would
matter, is that you can just run /usr/bin/denyhosts.py directly and not call it
with python.  I guess it's possible for python to have some kind of environment
cleansing feature, although I can't imagine why it would do so.

Comment 5 Jason Tibbitts 2008-01-25 23:30:25 UTC
So I've tried some more, and I simply can't come up with any situation where
you'd see what you're seeing except the one where HOSTNAME is set but not exported:

[root@temp2 ~]# unset HOSTNAME
[root@temp2 ~]# echo $HOSTNAME

[root@temp2 ~]# python  /usr/bin/denyhosts.py --debug -c /etc/denyhosts.conf
--file /var/log/secure
Could not find environment variable: HOSTNAME
[root@temp2 ~]# HOSTNAME=temp2.math.uh.edu
[root@temp2 ~]# python  /usr/bin/denyhosts.py --debug -c /etc/denyhosts.conf
--file /var/log/secure
Could not find environment variable: HOSTNAME
[root@temp2 ~]# export HOSTNAME
[root@temp2 ~]# python  /usr/bin/denyhosts.py --debug -c /etc/denyhosts.conf
--file /var/log/secure
Debug mode enabled.
DenyHosts configuration settings:
   ADMIN_EMAIL: [root]
   AGE_RESET_INVALID: [864000]
...

Comment 6 Neal Becker 2008-01-25 23:39:21 UTC
I was originally trying to find out why I had entries in /var/log/secure that 
weren't being added to hosts.deny.  I am getting (lots) of entries via the net 
download.

I guess close for now, I'll look again later and see if there is still an 
issue.  Thanks for your help.