aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/upas/smtp/rmtdns.c
blob: 54b679bb9249bdd7a34af2bafb2f53e6fd4441a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include	"common.h"
#include	<ndb.h>

int
rmtdns(char *net, char *path)
{

	int fd, n, r;
	char *domain, *cp, buf[1024];

	if(net == 0 || path == 0)
		return 0;

	domain = strdup(path);
	cp = strchr(domain, '!');
	if(cp){
		*cp = 0;
		n = cp-domain;
	} else
		n = strlen(domain);

	if(*domain == '[' && domain[n-1] == ']'){	/* accept [nnn.nnn.nnn.nnn] */
		domain[n-1] = 0;
		r = strcmp(ipattr(domain+1), "ip");
		domain[n-1] = ']';
	} else
		r = strcmp(ipattr(domain), "ip");	/* accept nnn.nnn.nnn.nnn */

	if(r == 0){
		free(domain);
		return 0;
	}

	snprint(buf, sizeof(buf), "%s/dns", net);

	fd = open(buf, ORDWR);			/* look up all others */
	if(fd < 0){				/* dns screw up - can't check */
		free(domain);
		return 0;
	}

	n = snprint(buf, sizeof(buf), "%s all", domain);
	free(domain);
	seek(fd, 0, 0);
	n = write(fd, buf, n);
	close(fd);
	if(n < 0){
		rerrstr(buf, sizeof(buf));
		if (strcmp(buf, "dns: name does not exist") == 0)
			return -1;
	}
	return 0;
}

/*
void main(int, char *argv[]){ print("return = %d\n", rmtdns("/net.alt/tcp/109", argv[1]));}

*/