Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include	"common.h"
2
#include	"smtp.h"
3
#include	<ndb.h>
4
 
5
int
6
rmtdns(char *net, char *path)
7
{
8
	int fd, n, nb, r;
9
	char *domain, *cp, buf[Maxdomain + 5];
10
 
11
	if(net == 0 || path == 0)
12
		return 0;
13
 
14
	domain = strdup(path);
15
	cp = strchr(domain, '!');
16
	if(cp){
17
		*cp = 0;
18
		n = cp-domain;
19
	} else
20
		n = strlen(domain);
21
 
22
	if(*domain == '[' && domain[n-1] == ']'){ /* accept [nnn.nnn.nnn.nnn] */
23
		domain[n-1] = 0;
24
		r = strcmp(ipattr(domain+1), "ip");
25
		domain[n-1] = ']';
26
	} else
27
		r = strcmp(ipattr(domain), "ip"); /* accept nnn.nnn.nnn.nnn */
28
	if(r == 0){
29
		free(domain);
30
		return 0;
31
	}
32
 
33
	snprint(buf, sizeof buf, "%s/dns", net);
34
	fd = open(buf, ORDWR);			/* look up all others */
35
	if(fd < 0){				/* dns screw up - can't check */
36
		free(domain);
37
		return 0;
38
	}
39
 
40
	n = snprint(buf, sizeof buf, "%s all", domain);
41
	free(domain);
42
	seek(fd, 0, 0);
43
	nb = write(fd, buf, n);
44
	close(fd);
45
	if(nb != n){
46
		rerrstr(buf, sizeof buf);
47
		if (strcmp(buf, "dns: name does not exist") == 0)
48
			return -1;
49
	}
50
	return 0;
51
}
52
 
53
/*
54
void
55
main(int, char *argv[])
56
{
57
	print("return = %d\n", rmtdns("/net.alt", argv[1]));
58
	exits(0);
59
}
60
*/