Exemplo n.º 1
0
/**
 * @param policy
 * @param keyval
 * @param dstat
 * @return DSTAT_OK for success, otherwise status code that indicates error.
 * @error DSTAT_PERMFAIL_TAG_SYNTAX_VIOLATION tag-value syntax violation
 * @error DSTAT_PERMFAIL_MISSING_REQUIRED_TAG missing required tag
 * @error DSTAT_PERMFAIL_TAG_DUPLICATED multiple identical tags are found
 * @error DSTAT_SYSERR_IMPLERROR obvious implementation error
 * @error DSTAT_SYSERR_NORESOURCE memory allocation error
 */
DkimAdsp *
DkimAdsp_build(const DkimPolicyBase *policy, const char *keyval, DkimStatus *dstat)
{
    assert(NULL != keyval);

    DkimAdsp *self = (DkimAdsp *) malloc(sizeof(DkimAdsp));
    if (NULL == self) {
        DkimLogNoResource(policy);
        SETDEREF(dstat, DSTAT_SYSERR_NORESOURCE);
        return NULL;
    }   // end if
    memset(self, 0, sizeof(DkimAdsp));
    self->policy = policy;
    self->ftbl = dkim_adsp_field_table;

    /*
     * [RFC5617] 4.1.
     * Note:   ADSP changes the "Tag=Value List" syntax from [RFC4871] to
     *         use WSP rather than FWS in its DNS records.
     */
    DkimStatus build_stat =
        DkimTagListObject_build((DkimTagListObject *) self, keyval, STRTAIL(keyval), true);
    if (DSTAT_OK != build_stat) {
        SETDEREF(dstat, build_stat);
        DkimAdsp_free(self);
        return NULL;
    }   // end if

    SETDEREF(dstat, DSTAT_OK);
    return self;
}   // end function: DkimAdsp_build
Exemplo n.º 2
0
static YenmaStatsFormat
YenmaCtrl_parseRequestURL(const char *param)
{
    if (NULL == param) {
        return YENMA_STATS_FORMAT_NULL;
    }   // end if

    const char *param_tail = STRTAIL(param);
    if ('/' == *(param_tail - 1)) { // trim trailing '/'
        --param_tail;
    }   // end if

    if ('/' == *param) { // trim leading '/'
        ++param;
    }   // end if

    if (param_tail <= param) {
        return YENMA_STATS_FORMAT_NULL;
    }   // end if

    return KeywordMap_lookupByCaseStringSlice(stats_url_tbl, param, param_tail);
}   // end function: YenmaCtrl_parseRequestURL
Exemplo n.º 3
0
int
main(int argc, char **argv)
{
    int af = AF_UNSPEC;
    int ai_flags = 0;
    SidfRecordScope scope = SIDF_RECORD_SCOPE_SPF1;

    int c;
    while (-1 != (c = getopt(argc, argv, "46mnpshv"))) {
        switch (c) {
        case '4':  // IPv4
            af = AF_INET;
            break;
        case '6':  // IPv6
            af = AF_INET6;
            break;
        case 'm':  // SIDF/mfrom
            scope = SIDF_RECORD_SCOPE_SPF2_MFROM;
            break;
        case 'n':  // to prevent DNS-querying at getaddrinfo()
            ai_flags |= AI_NUMERICHOST;
            break;
        case 'p':  // SIDF/pra
            scope = SIDF_RECORD_SCOPE_SPF2_PRA;
            break;
        case 's':  // SPF
            scope = SIDF_RECORD_SCOPE_SPF1;
            break;
        case 'h':
            usage(stdout);
            break;
        case 'v':
            g_verbose_mode = true;
            break;
        default:
            fprintf(stdout, "[Error] illegal option: -%c\n", c);
            usage(stdout);
            break;
        }   // end switch
    }   // end while

    argc -= optind;
    argv += optind;

    if (argc < 2) {
        usage(stdout);
    }   // end if

    DnsResolver *resolver = DnsResolver_new();
    if (NULL == resolver) {
        fprintf(stdout, "[Error] resolver initialization failed: error=%s\n", strerror(errno));
        exit(EX_OSERR);
    }   // end if

    const char *mailbox = argv[0];

    SidfPolicy *policy = SidfPolicy_new();
    if (NULL == policy) {
        fprintf(stdout, "[Error] SidfPolicy_new failed: error=%s\n", strerror(errno));
        exit(EX_OSERR);
    }   // end if
    SidfPolicy_setSpfRRLookup(policy, true);
    SidfPolicy_setLogger(policy, stdout_logger);

    SidfRequest *request = SidfRequest_new(policy, resolver);
    if (NULL == request) {
        fprintf(stdout, "[Error] SidfRequest_new failed: error=%s\n", strerror(errno));
        exit(EX_OSERR);
    }   // end if

    const char *dummy;
    InetMailbox *envfrom = InetMailbox_build2822Mailbox(mailbox, STRTAIL(mailbox), &dummy, NULL);
    if (NULL == envfrom) {
        fprintf(stdout, "[Error] mailbox is not RFC2822 compliant: mailbox=%s\n", mailbox);
        usage(stdout);
    }   // end if

    struct addrinfo ai_hints, *ai_result, *ai_current;
    memset(&ai_hints, 0, sizeof(struct addrinfo));
    ai_hints.ai_flags |= ai_flags;
    ai_hints.ai_family = af;
    ai_hints.ai_socktype = SOCK_STREAM;

    for (int i = 1; i < argc; ++i) {
        int gai_error = getaddrinfo(argv[i], NULL, &ai_hints, &ai_result);
        if (0 != gai_error) {
            fprintf(stdout, "[Error] invalid IP address: ip-address=%s, error=%s\n", argv[i],
                    gai_strerror(gai_error));
            if (EAI_NONAME == gai_error) {
                continue;
#ifdef EAI_NODATA
            } else if (EAI_NODATA == gai_error) {
                // some platforms have EAI_NODATA as a return code of getaddrinfo()
                continue;
#endif  // EAI_NODATA
            } else {
                exit(EX_OSERR);
            }   // end if
        }   // end if

        for (ai_current = ai_result; NULL != ai_current; ai_current = ai_current->ai_next) {
            if (AF_INET != ai_current->ai_family && AF_INET6 != ai_current->ai_family) {
                continue;
            }   // end if

            char addr_string[INET6_ADDRSTRLEN];
            if (AF_INET == ai_current->ai_family) {
                (void) inet_ntop(AF_INET, &((struct sockaddr_in *) ai_current->ai_addr)->sin_addr,
                                 addr_string, sizeof(addr_string));
            } else {
                (void) inet_ntop(AF_INET6,
                                 &((struct sockaddr_in6 *) ai_current->ai_addr)->sin6_addr,
                                 addr_string, sizeof(addr_string));
            }   // end if

            SidfRequest_reset(request);
            if (!SidfRequest_setIpAddr(request, ai_current->ai_family, ai_current->ai_addr)) {
                fprintf(stdout, "[Error] SidfRequest_setIpAddr failed: address_family=0x%x\n",
                        ai_current->ai_family);
                usage(stdout);
            }   // end if

            SidfRequest_setSender(request, envfrom);
            SidfRequest_setHeloDomain(request, InetMailbox_getDomain(envfrom));

            // SPF/Sender ID evaluation
            SidfScore score = SidfRequest_eval(request, scope);
            const char *spfresultexp = SidfEnum_lookupScoreByValue(score);
            fprintf(stdout, "%s %s %s\n", mailbox, addr_string, spfresultexp);
        }   //end for

        freeaddrinfo(ai_result);
    }   // end for

    // clean up
    InetMailbox_free(envfrom);
    SidfRequest_free(request);
    SidfPolicy_free(policy);
    DnsResolver_free(resolver);

    exit(EX_OK);
}   // end function : main