diff --git a/sm5/smartd.c b/sm5/smartd.c index 2650316bf4708c6bf8bd2545f8ed89dfe4d78298..6d48a9cca6bb7bc3d79ce45a4dfca893b2ce16c8 100644 --- a/sm5/smartd.c +++ b/sm5/smartd.c @@ -98,7 +98,7 @@ int getdomainname(char *, int); /* no declaration in header files! */ extern const char *atacmdnames_c_cvsid, *atacmds_c_cvsid, *ataprint_c_cvsid, *escalade_c_cvsid, *knowndrives_c_cvsid, *os_XXXX_c_cvsid, *scsicmds_c_cvsid, *utility_c_cvsid; -static const char *filenameandversion="$Id: smartd.c,v 1.306 2004/04/07 17:49:21 ballen4705 Exp $"; +static const char *filenameandversion="$Id: smartd.c,v 1.307 2004/04/07 19:27:33 ballen4705 Exp $"; #ifdef NEED_SOLARIS_ATA_CODE extern const char *os_solaris_ata_s_cvsid; #endif @@ -109,7 +109,7 @@ extern const char *syslog_win32_c_cvsid; extern const char *int64_vc6_c_cvsid; #endif #endif -const char *smartd_c_cvsid="$Id: smartd.c,v 1.306 2004/04/07 17:49:21 ballen4705 Exp $" +const char *smartd_c_cvsid="$Id: smartd.c,v 1.307 2004/04/07 19:27:33 ballen4705 Exp $" ATACMDS_H_CVSID ATAPRINT_H_CVSID CONFIG_H_CVSID EXTERN_H_CVSID INT64_H_CVSID KNOWNDRIVES_H_CVSID SCSICMDS_H_CVSID SMARTD_H_CVSID #ifdef SYSLOG_H_CVSID @@ -446,6 +446,8 @@ char* dnsdomain(const char* hostname) { struct hostent *hp; if ((hp = gethostbyname(hostname))) { + // Does this work if gethostbyname() returns an IPv6 name in + // colon/dot notation? [BA] if ((p = strchr(hp->h_name, '.'))) p++; // skip "." } @@ -547,7 +549,7 @@ void MailWarning(cfgfile *cfg, int which, char *fmt, ...){ char *p=NULL; hostname[255]='\0'; p = dnsdomain(hostname); - if (p) { + if (p && *p) { strncpy(domainname, p, 255); domainname[255]='\0'; } else @@ -648,19 +650,16 @@ void MailWarning(cfgfile *cfg, int which, char *fmt, ...){ if (address) snprintf(command, 2048, "$SMARTD_MAILER -s '%s' %s 2>&1 << \"ENDMAIL\"\n" - "This email was generated by the smartd daemon running on host:\n" - "%s\n" - "in the DNS domain:\n" - "%s\n" - "in the NIS domain:\n" - "%s\n" - "The following warning/error was logged by the smartd daemon:\n" - "%s\n\n" - "For details see the SYSLOG (default: /var/log/messages) for host:\n" + "This email was generated by the smartd daemon running on:\n\n" + " host name: %s\n" + " DNS domain: %s\n" + " NIS domain: %s\n\n" + "The following warning/error was logged by the smartd daemon:\n\n" "%s\n\n" + "For details see host's SYSLOG (default: /var/log/messages).\n\n" "%s%s%s" "ENDMAIL\n", - subject, address, hostname, domainname, nisdomain, message, hostname, further, original, additional); + subject, address, hostname, domainname, nisdomain, message, further, original, additional); else snprintf(command, 2048, "%s 2>&1", executable); diff --git a/sm5/smartd.cpp b/sm5/smartd.cpp index 1079580fbca2812304b3d927a366f436ae657562..fccb06ed1daa1c17cb7e4a38ee7634f1a4f6530b 100644 --- a/sm5/smartd.cpp +++ b/sm5/smartd.cpp @@ -98,7 +98,7 @@ int getdomainname(char *, int); /* no declaration in header files! */ extern const char *atacmdnames_c_cvsid, *atacmds_c_cvsid, *ataprint_c_cvsid, *escalade_c_cvsid, *knowndrives_c_cvsid, *os_XXXX_c_cvsid, *scsicmds_c_cvsid, *utility_c_cvsid; -static const char *filenameandversion="$Id: smartd.cpp,v 1.306 2004/04/07 17:49:21 ballen4705 Exp $"; +static const char *filenameandversion="$Id: smartd.cpp,v 1.307 2004/04/07 19:27:33 ballen4705 Exp $"; #ifdef NEED_SOLARIS_ATA_CODE extern const char *os_solaris_ata_s_cvsid; #endif @@ -109,7 +109,7 @@ extern const char *syslog_win32_c_cvsid; extern const char *int64_vc6_c_cvsid; #endif #endif -const char *smartd_c_cvsid="$Id: smartd.cpp,v 1.306 2004/04/07 17:49:21 ballen4705 Exp $" +const char *smartd_c_cvsid="$Id: smartd.cpp,v 1.307 2004/04/07 19:27:33 ballen4705 Exp $" ATACMDS_H_CVSID ATAPRINT_H_CVSID CONFIG_H_CVSID EXTERN_H_CVSID INT64_H_CVSID KNOWNDRIVES_H_CVSID SCSICMDS_H_CVSID SMARTD_H_CVSID #ifdef SYSLOG_H_CVSID @@ -446,6 +446,8 @@ char* dnsdomain(const char* hostname) { struct hostent *hp; if ((hp = gethostbyname(hostname))) { + // Does this work if gethostbyname() returns an IPv6 name in + // colon/dot notation? [BA] if ((p = strchr(hp->h_name, '.'))) p++; // skip "." } @@ -547,7 +549,7 @@ void MailWarning(cfgfile *cfg, int which, char *fmt, ...){ char *p=NULL; hostname[255]='\0'; p = dnsdomain(hostname); - if (p) { + if (p && *p) { strncpy(domainname, p, 255); domainname[255]='\0'; } else @@ -648,19 +650,16 @@ void MailWarning(cfgfile *cfg, int which, char *fmt, ...){ if (address) snprintf(command, 2048, "$SMARTD_MAILER -s '%s' %s 2>&1 << \"ENDMAIL\"\n" - "This email was generated by the smartd daemon running on host:\n" - "%s\n" - "in the DNS domain:\n" - "%s\n" - "in the NIS domain:\n" - "%s\n" - "The following warning/error was logged by the smartd daemon:\n" - "%s\n\n" - "For details see the SYSLOG (default: /var/log/messages) for host:\n" + "This email was generated by the smartd daemon running on:\n\n" + " host name: %s\n" + " DNS domain: %s\n" + " NIS domain: %s\n\n" + "The following warning/error was logged by the smartd daemon:\n\n" "%s\n\n" + "For details see host's SYSLOG (default: /var/log/messages).\n\n" "%s%s%s" "ENDMAIL\n", - subject, address, hostname, domainname, nisdomain, message, hostname, further, original, additional); + subject, address, hostname, domainname, nisdomain, message, further, original, additional); else snprintf(command, 2048, "%s 2>&1", executable);