Bacula's 'bsmtp' Thinks Jail's FQDN is "localhost"

Status
Not open for further replies.

ewhac

Contributor
Joined
Aug 20, 2013
Messages
177
I successfully set up (for generous definitions of "successful") a Bacula director and storage daemon inside an iocage jail; it happily backs up my main PC every night. When it does this, it fires off an email to report success/failure. It uses its own tool to do this: bsmtp.

Problem: bsmtp connects to my Postfix server and says, "HELO localhost". By default, Postfix wants an FQDN following HELO, and rejects the message. After looking at the source code for bsmtp, it looks like it's getting the hostname via gethostname(3):

Code:
   /*
	*  Find out my own host name for HELO;
	*  if possible, get the FQDN - fully qualified domain name
	*/
   if (gethostname(my_hostname, sizeof(my_hostname) - 1) < 0) {
	 Pmsg1(0, _("Fatal gethostname error: ERR=%s\n"), strerror(errno));
	 exit(1);
   }
#ifdef HAVE_GETADDRINFO
   memset(&hints, 0, sizeof(struct addrinfo));
   hints.ai_family = AF_UNSPEC;
   hints.ai_socktype = 0;
   hints.ai_protocol = 0;
   hints.ai_flags = AI_CANONNAME;

   if ((res = getaddrinfo(my_hostname, NULL, &hints, &ai)) != 0) {
	 Pmsg2(0, _("Fatal getaddrinfo for myself failed \"%s\": ERR=%s\n"),
		   my_hostname, gai_strerror(res));
	 exit(1);
   }
   bstrncpy(my_hostname, ai->ai_canonname, sizeof(my_hostname));
   freeaddrinfo(ai);
#else
   if ((hp = gethostbyname(my_hostname)) == NULL) {
	 Pmsg2(0, _("Fatal gethostbyname for myself failed \"%s\": ERR=%s\n"),
		   my_hostname, strerror(errno));
	 exit(1);
   }
   bstrncpy(my_hostname, hp->h_name, sizeof(my_hostname));
#endif
   Dmsg1(20, "My hostname is: %s\n", my_hostname);

Running with debugging turned on, this code coughs up "My hostname is: localhost".

The system commands hostname and domainname return the correct values, so something else is wrong. My current theory is that /etc/hosts is messed up, but not sure how/why. All hints gratefully accepted.
 
Status
Not open for further replies.
Top