if ((len = res_search(service, ns_c_in, ns_t_srv, (u_char *) buffer, PACKETSZ_MULT * NS_PACKETSZ)) < 0) {
error((char *) "%s| %s: ERROR: Error while resolving service record %s with res_search\n", LogTime(), PROGRAM, service);
nsError(h_errno, service);
- goto cleanup;
+ goto finalise;
}
} else {
- goto cleanup;
+ goto finalise;
}
}
if (len > PACKETSZ_MULT * NS_PACKETSZ) {
if ((len = res_search(service, ns_c_in, ns_t_srv, (u_char *) buffer, len)) < 0) {
error((char *) "%s| %s: ERROR: Error while resolving service record %s with res_search\n", LogTime(), PROGRAM, service);
nsError(h_errno, service);
- goto cleanup;
+ goto finalise;
}
if (len > olen) {
error((char *) "%s| %s: ERROR: Reply to big: buffer: %d reply length: %d\n", LogTime(), PROGRAM, olen, len);
- goto cleanup;
+ goto finalise;
}
}
p = buffer;
p += 6 * NS_INT16SZ; /* Header(6*16bit) = id + flags + 4*section count */
if (p > buffer + len) {
error((char *) "%s| %s: ERROR: Message to small: %d < header size\n", LogTime(), PROGRAM, len);
- goto cleanup;
+ goto finalise;
}
if ((size = dn_expand(buffer, buffer + len, p, name, sysconf(_SC_HOST_NAME_MAX))) < 0) {
error((char *) "%s| %s: ERROR: Error while expanding query name with dn_expand: %s\n", LogTime(), PROGRAM, strerror(errno));
- goto cleanup;
+ goto finalise;
}
p += size; /* Query name */
p += 2 * NS_INT16SZ; /* Query type + class (2*16bit) */
if (p > buffer + len) {
error((char *) "%s| %s: ERROR: Message to small: %d < header + query name,type,class \n", LogTime(), PROGRAM, len);
- goto cleanup;
+ goto finalise;
}
while (p < buffer + len) {
if ((size = dn_expand(buffer, buffer + len, p, name, sysconf(_SC_HOST_NAME_MAX))) < 0) {
error((char *) "%s| %s: ERROR: Error while expanding answer name with dn_expand: %s\n", LogTime(), PROGRAM, strerror(errno));
- goto cleanup;
+ goto finalise;
}
p += size; /* Resource Record name */
if (p > buffer + len) {
error((char *) "%s| %s: ERROR: Message to small: %d < header + query name,type,class + answer name\n", LogTime(), PROGRAM, len);
- goto cleanup;
+ goto finalise;
}
NS_GET16(type, p); /* RR type (16bit) */
p += NS_INT16SZ + NS_INT32SZ; /* RR class + ttl (16bit+32bit) */
if (p > buffer + len) {
error((char *) "%s| %s: ERROR: Message to small: %d < header + query name,type,class + answer name + RR type,class,ttl\n", LogTime(), PROGRAM, len);
- goto cleanup;
+ goto finalise;
}
NS_GET16(rdlength, p); /* RR data length (16bit) */
if (type == ns_t_srv) { /* SRV record */
if (p > buffer + len) {
error((char *) "%s| %s: ERROR: Message to small: %d < header + query name,type,class + answer name + RR type,class,ttl + RR data length\n", LogTime(), PROGRAM, len);
- goto cleanup;
+ goto finalise;
}
NS_GET16(priority, p); /* Priority (16bit) */
if (p > buffer + len) {
error((char *) "%s| %s: ERROR: Message to small: %d < SRV RR + priority\n", LogTime(), PROGRAM, len);
- goto cleanup;
+ goto finalise;
}
NS_GET16(weight, p); /* Weight (16bit) */
if (p > buffer + len) {
error((char *) "%s| %s: ERROR: Message to small: %d < SRV RR + priority + weight\n", LogTime(), PROGRAM, len);
- goto cleanup;
+ goto finalise;
}
NS_GET16(port, p); /* Port (16bit) */
if (p > buffer + len) {
error((char *) "%s| %s: ERROR: Message to small: %d < SRV RR + priority + weight + port\n", LogTime(), PROGRAM, len);
- goto cleanup;
+ goto finalise;
}
if ((size = dn_expand(buffer, buffer + len, p, host, NS_MAXDNAME)) < 0) {
error((char *) "%s| %s: ERROR: Error while expanding SRV RR name with dn_expand: %s\n", LogTime(), PROGRAM, strerror(errno));
- goto cleanup;
+ goto finalise;
}
debug((char *) "%s| %s: DEBUG: Resolved SRV %s record to %s\n", LogTime(), PROGRAM, service, host);
hp = (struct hstruct *) xrealloc(hp, sizeof(struct hstruct) * (nh + 1));
}
if (p > buffer + len) {
error((char *) "%s| %s: ERROR: Message to small: %d < SRV RR + priority + weight + port + name\n", LogTime(), PROGRAM, len);
- goto cleanup;
+ goto finalise;
}
}
if (p != buffer + len) {
#else
error((char *) "%s| %s: ERROR: Inconsistence message length: %d!=0\n", LogTime(), PROGRAM, buffer + len - p);
#endif
- goto cleanup;
+ goto finalise;
}
-cleanup:
+finalise:
nhosts = get_hostname_list(margs, &hp, nh, domain);
debug("%s| %s: DEBUG: Adding %s to list\n", LogTime(), PROGRAM, domain);
hp[nhosts].weight = -2;
++nhosts;
+cleanup:
/* Remove duplicates */
for (i = 0; i < nhosts; ++i) {
for (j = i + 1; j < nhosts; ++j) {