示例#1
0
文件: tcl_cmd.c 项目: koodaamo/yadifa
static int
tcl_writezone(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
{
    ya_result return_code;
    zdb_zone* zone;
    char* path;

    int argi = 1;

    if(FAIL(read_zone(argv, argc, &argi, &zone)))
    {
	return -1;
    }

    if(FAIL(read_string(argv, argc, &argi, &path)))
    {
	return -2;
    }

    if(FAIL(return_code = zdb_zone_write_text(zone, path)))
    {
	fprintf(stdout, ERROR_CODE_HEX_DEC, return_code, return_code);
	fflush(stdout);

	return -3;
    }

    return TCL_OK;
}
示例#2
0
文件: tcl_cmd.c 项目: koodaamo/yadifa
static int
tcl_updatesigs(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
{
    ya_result return_code;
    zdb_zone* zone;
    int argi = 1;

    if(FAIL(read_zone(argv, argc, &argi, &zone)))
    {
        return -1;
    }

    zdb_update_zone_signatures(zone, FALSE);

    if(FAIL(return_code))
    {
        fprintf(stdout, ERROR_CODE_HEX_DEC, return_code, return_code);
        fflush(stdout);

        return -1;
    }


    return TCL_OK;
}
示例#3
0
文件: tcl_cmd.c 项目: koodaamo/yadifa
static int
tcl_addnsec3param(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
{
    ya_result return_code;
    zdb_zone* zone;

    int argi = 1;

    if(FAIL(read_zone(argv, argc, &argi, &zone)))
    {
        return -1;
    }

    return_code = nsec3_add_nsec3param(zone, 1, 0, 1, 0, NULL);

    if(FAIL(return_code))
    {
        fprintf(stdout, ERROR_CODE_HEX_DEC, return_code, return_code);
        fflush(stdout);

        return -1;
    }

    return TCL_OK;
}
示例#4
0
static rrset_type *
read_rrset(namedb_type *db,
           uint32_t domain_count, domain_type **domains,
           uint32_t zone_count, zone_type **zones)
{
    rrset_type *rrset;
    int i, j;
    domain_type *owner;
    uint16_t type;
    uint16_t klass;
    uint32_t soa_minimum;

    owner = read_domain(db, domain_count, domains);
    if (!owner)
        return NULL;

    rrset = (rrset_type *) region_alloc(db->region, sizeof(rrset_type));

    rrset->zone = read_zone(db, zone_count, zones);
    if (!rrset->zone)
        return NULL;

    if (fread(&type, sizeof(type), 1, db->fd) != 1)
        return NULL;
    type = ntohs(type);

    if (fread(&klass, sizeof(klass), 1, db->fd) != 1)
        return NULL;
    klass = ntohs(klass);

    if (fread(&rrset->rr_count, sizeof(rrset->rr_count), 1, db->fd) != 1)
        return NULL;
    rrset->rr_count = ntohs(rrset->rr_count);
    rrset->rrs = (rr_type *) region_alloc(
                     db->region, rrset->rr_count * sizeof(rr_type));

    assert(rrset->rr_count > 0);

    for (i = 0; i < rrset->rr_count; ++i) {
        rr_type *rr = &rrset->rrs[i];

        rr->owner = owner;
        rr->type = type;
        rr->klass = klass;

        if (fread(&rr->rdata_count, sizeof(rr->rdata_count), 1, db->fd) != 1)
            return NULL;
        rr->rdata_count = ntohs(rr->rdata_count);
        rr->rdatas = (rdata_atom_type *) region_alloc(
                         db->region, rr->rdata_count * sizeof(rdata_atom_type));

        if (fread(&rr->ttl, sizeof(rr->ttl), 1, db->fd) != 1)
            return NULL;
        rr->ttl = ntohl(rr->ttl);

        for (j = 0; j < rr->rdata_count; ++j) {
            if (!read_rdata_atom(db, rr->type, j, domain_count, domains, &rr->rdatas[j]))
                return NULL;
        }
    }

    domain_add_rrset(owner, rrset);

    if (rrset_rrtype(rrset) == TYPE_SOA) {
        assert(owner == rrset->zone->apex);
        rrset->zone->soa_rrset = rrset;

        /* BUG #103 add another soa with a tweaked ttl */
        rrset->zone->soa_nx_rrset = region_alloc(db->region, sizeof(rrset_type));
        rrset->zone->soa_nx_rrset->rrs =
            region_alloc(db->region, rrset->rr_count * sizeof(rr_type));

        memcpy(rrset->zone->soa_nx_rrset->rrs, rrset->rrs, sizeof(rr_type));
        rrset->zone->soa_nx_rrset->rr_count = 1;
        rrset->zone->soa_nx_rrset->next = 0;

        /* also add a link to the zone */
        rrset->zone->soa_nx_rrset->zone = rrset->zone;

        /* check the ttl and MINIMUM value and set accordinly */
        memcpy(&soa_minimum, rdata_atom_data(rrset->rrs->rdatas[6]),
               rdata_atom_size(rrset->rrs->rdatas[6]));
        if (rrset->rrs->ttl > ntohl(soa_minimum)) {
            rrset->zone->soa_nx_rrset->rrs[0].ttl = ntohl(soa_minimum);
        }
        owner->has_SOA = 1;

    } else if (owner == rrset->zone->apex
               && rrset_rrtype(rrset) == TYPE_NS)
    {
        rrset->zone->ns_rrset = rrset;
    }
#ifdef NSEC3
#ifndef FULL_PREHASH
    else if (type == TYPE_NSEC3) {
        if (0 != namedb_add_nsec3_domain(db, owner, rrset->zone)) {
            return NULL;
        }
    }
#endif /* !FULL_PREHASH */
#endif /* NSEC3 */
    if (rrset_rrtype(rrset) == TYPE_RRSIG && owner == rrset->zone->apex) {
        for (i = 0; i < rrset->rr_count; ++i) {
            if (rr_rrsig_type_covered(&rrset->rrs[i]) == TYPE_DNSKEY) {
                rrset->zone->is_secure = 1;
                break;
            }
        }
    }
    return rrset;
}
示例#5
0
文件: tcl_cmd.c 项目: koodaamo/yadifa
static int
tcl_addkey(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
{
    ya_result return_code;
    zdb_zone* zone;
    dnssec_key* key;
    u32 key_size;
    int argi = 1;
    u16 key_flags;

    if(FAIL(read_zone(argv, argc, &argi, &zone)))
    {
	return -1;
    }

    if(FAIL(read_u32(argv, argc, &argi, &key_size)))
    {
	return -2;
    }

    if(FAIL(read_u16(argv, argc, &argi, &key_flags)))
    {
	return -3;
    }

    /* argv[1] is always the origin */

    key = dnssec_key_createnew(DNSKEY_ALGORITHM_RSASHA1_NSEC3, key_size, key_flags, argv[1]);

    if(key == NULL)
    {
	fprintf(stdout, "Key generation error\n");
	fflush(stdout);
	return -4;
    }

    return_code = dnssec_key_store_private(key);

    if(FAIL(return_code))
    {
	fprintf(stdout, ERROR_CODE_HEX_DEC, return_code, return_code);
	fflush(stdout);

	dnssec_key_free(key);

	return -5;
    }

    return_code = dnssec_key_store_dnskey(key);

    if(FAIL(return_code))
    {
	fprintf(stdout, ERROR_CODE_HEX_DEC, return_code, return_code);
	fflush(stdout);

	dnssec_key_free(key);

	return -6;
    }

    dnssec_key_addrecord(zone, key);

    return TCL_OK;
}