Ticket #21: nhns.diff

File nhns.diff, 2.3 KB (added by eagle, 14 years ago)

Patch from 2000

  • getmodaddr.c

    old new  
    1111#include "macros.h"
    1212#include "nntp.h"
    1313
     14#define WITH_NHNS
     15#ifdef WITH_NHNS
     16#include <netinet/in.h>
     17#include <arpa/nameser.h>
     18#include <resolv.h>
     19#endif
    1420
    1521STATIC char     GMApathname[256];
    1622STATIC FILE     *GMAfp = NULL;
     
    8288    return NULL;
    8389}
    8490
     91#ifdef WITH_NHNS
     92/*
     93**  Query the DNS to find a moderator in the NHNS domain.
     94*/
     95Query_NHNS(const char *group, char *address)
     96{
     97    int n, qdcount, ancount;
     98    char answer[PACKETSZ];
     99    HEADER *hp;
     100    char *rgroup, *oldp, *p, *cp, *end;
     101
     102    p = oldp = COPY(group);
     103    rgroup = NEW(char, strlen(group) + 1);
     104    *rgroup = '\0';
     105    while (1) {
     106        p = strrchr(group, '.');
     107        if (p == NULL) {
     108            strcat(rgroup, group);
     109            break;
     110        }
     111        strcat(rgroup, p + 1);
     112        strcat(rgroup, ".");
     113        *p = '\0';
     114    }
     115    DISPOSE(oldp);
     116
     117    n = res_querydomain(rgroup, "usenet.nhns.net",
     118            C_IN, T_RP, answer, sizeof(answer));
     119    DISPOSE(rgroup);
     120    if (n < 0) {
     121        printf("res_query err (%d)\n", n);
     122        return -1;
     123    }
     124    if (n > sizeof(answer))
     125        n = sizeof(answer);
     126
     127    hp = (HEADER *)answer;
     128    cp = answer + HFIXEDSZ;
     129    end = answer + n;
     130
     131    for (qdcount = ntohs(hp->qdcount); qdcount-- > 0; cp += n + QFIXEDSZ)
     132        if ((n = dn_skipname(cp, end)) < 0)
     133            return -1;
     134
     135    /* this code may be broken. Only the first record found is returned. */
     136    for (ancount = ntohs(hp->ancount); ancount-- > 0 && cp < end; ) {
     137        if ((n = dn_expand(answer, end, cp, address, SMBUF)) < 0)
     138            return -1;
     139        cp += n + RRFIXEDSZ;
     140        if ((n = dn_expand(answer, end, cp, address, SMBUF)) < 0)
     141            return -1;
     142        break;
     143    }
     144
     145    for (p = address; *p != '\0'; p++) {
     146        if (*p == '.') {
     147            *p = '@';
     148            break;
     149        }
     150    }
     151
     152    return 0;
     153}
     154#endif
     155
    85156/*
    86157**  Read the moderators file, looking for a moderator.
    87158*/
     
    135206            if (wildmat(name, buff)) {
    136207                for (save = p; ISWHITE(*save); save++)
    137208                    continue;
     209#ifdef WITH_NHNS
     210                printf("buff: %s p: %s save: %s\n", buff, p, save);
     211                if (strcmp(save, "NHNS") == 0) {
     212                    if (Query_NHNS(name, address) < 0)
     213                    {
     214                        continue;
     215                        puts("FAILED"); exit(0);
     216                    }
     217                    return address;
     218                }
     219#endif
    138220                for (p = name; *p; p++)
    139221                    if (*p == '.')
    140222                        *p = '-';