/*
* By John G. Myers, jgm+@cmu.edu
* Version 1.2
*
* Process a BITNET "internet.listing" file, producing output
* suitable for input to makemap.
*
* The input file can be obtained via anonymous FTP to bitnic.educom.edu.
* Change directory to "netinfo" and get the file internet.listing
* The file is updated monthly.
*
* Feed the output of this program to "makemap hash /etc/mail/bitdomain.db"
* to create the table used by the "FEATURE(bitdomain)" config file macro.
* If your sendmail does not have the db library compiled in, you can instead
*
* The bitdomain table should be rebuilt monthly.
*/
#include <stdio.h>
#include <errno.h>
#include <resolv.h>
#include <netdb.h>
#include <ctype.h>
#include <string.h>
/* don't use sizeof because sizeof(long) is different on 64-bit machines */
typedef union
{
} querybuf;
extern int h_errno;
extern char *malloc();
extern char *optarg;
extern int optind;
char *lookup();
int argc;
char **argv;
{
int opt;
switch (opt) {
case 'o':
exit(1);
}
break;
default:
argv[0]);
exit(1);
}
}
exit(1);
}
}
finish();
exit(0);
}
/*
* Parse and process an input file
*/
{
if (!*p) {
skippingheader = 0;
continue;
}
if (skippingheader) continue;
node = p;
for (; *p && !isspace(*p); p++) {
}
if (!*p) {
continue;
}
*p++ = '\0';
for (; *p && isspace(*p); p++) ;
if (!*p) {
continue;
}
hostname = p;
for (; *p && !isspace(*p); p++) {
}
*p = '\0';
/* Chop off any trailing .bitnet */
}
}
}
/*
* Process a single entry in the input file.
* The entry tells us that "node" expands to "domain".
* "domain" can either be a domain name or a bitnet node name
* The buffer pointed to by "domain" may be overwritten--it
* is of size "domainlen".
*/
char *node;
char *domain;
char *domainlen;
{
/* See if we have any remembered information about this node */
/* We already have a domain for this node */
/*
* This entry is an Eric Thomas FOO.BITNET kludge.
* He doesn't want LISTSERV to do transitive closures, so we
* do them instead. Give the the domain expansion for "node"
* (which is in "otherdomian") to FOO (which is in "domain")
* if "domain" doesn't have a domain expansion already.
*/
}
}
else {
if (otherdomain) {
/*
* We previously mapped the node "node" to the node
* "otherdomain". If "otherdomain" doesn't already
* have a domain expansion, give it the expansion "domain".
*/
p = lookup(otherdomain);
}
}
else {
switch (h_errno) {
case HOST_NOT_FOUND:
err = "not registered in DNS";
break;
case TRY_AGAIN:
err = "temporary DNS lookup failure";
break;
case NO_RECOVERY:
err = "non-recoverable nameserver error";
break;
case NO_DATA:
err = "registered in DNS, but not mailable";
break;
default:
err = "unknown nameserver error";
break;
}
}
}
}
/*
* Validate whether the mail domain "host" is registered in the DNS.
* If "host" is a CNAME, it is expanded in-place if the expansion fits
* into the buffer of size "hbsize". Returns nonzero if it is, zero
* if it is not. A BIND error code is left in h_errno.
*/
int
char *host;
int hbsize;
{
register int n;
int ret;
int type;
int qtype;
return (0);
for (;;) {
if (ret <= 0)
{
{
/* the name server seems to be down */
return 0;
}
if (h_errno != HOST_NOT_FOUND)
{
/* might have another type of interest */
{
continue;
}
{
continue;
}
}
/* otherwise, no record */
return 0;
}
/*
** This might be a bogus match. Search for A, MX, or
** CNAME records.
*/
/* skip question part of response -- we know what we asked */
{
{
return 0; /* ???XXX??? */
}
}
{
if (n < 0)
break;
ap += n;
switch (type)
{
case T_MX:
case T_A:
return 1;
case T_CNAME:
/* value points at name */
break;
}
return 1;
default:
/* not a record of interest */
continue;
}
}
/*
** If this was a T_ANY query, we may have the info but
** need an explicit query. Try T_A, then T_MX.
*/
else
return 0;
}
}
struct entry {
char *node;
char *domain;
};
/*
* Find any remembered information about "node"
*/
char *node;
{
struct entry *p;
for (p = firstentry; p; p = p->next) {
return p->domain;
}
}
return 0;
}
/*
* Mark the node "node" as equivalent to "domain". "domain" can either
* be a bitnet node or a domain name--if it is the latter, the mapping
* will be written to stdout.
*/
char *node;
char *domain;
{
struct entry *p;
}
for (p = firstentry; p; p = p->next) {
if (!p->domain) {
goto outofmemory;
}
return;
}
}
if (!p) goto outofmemory;
p->next = firstentry;
firstentry = p;
return;
exit(1);
}
/*
* Walk through the database, looking for any cases where we know
* node FOO is equivalent to node BAR and node BAR has a domain name.
* For those cases, give FOO the same domain name as BAR.
*/
finish()
{
struct entry *p;
char *domain;
for (p = firstentry; p; p = p->next) {
}
}
}