Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00034 #include "config.h"
00035 #include "shared/allocator.h"
00036 #include "shared/file.h"
00037 #include "shared/log.h"
00038 #include "shared/util.h"
00039 #include "signer/rrsigs.h"
00040 #include "signer/keys.h"
00041
00042 #include <ldns/ldns.h>
00043
00044 static const char* rrsigs_str = "rrsig";
00045
00046
00051 rrsigs_type*
00052 rrsigs_create(void)
00053 {
00054 allocator_type* allocator = NULL;
00055 rrsigs_type* rrsigs = NULL;
00056
00057 allocator = allocator_create(malloc, free);
00058 if (!allocator) {
00059 ods_log_error("[%s] unable to create RRSIGs: create allocator "
00060 "failed", rrsigs_str);
00061 return NULL;
00062 }
00063 ods_log_assert(allocator);
00064
00065 rrsigs = (rrsigs_type*) allocator_alloc(allocator, sizeof(rrsigs_type));
00066 if (!rrsigs) {
00067 ods_log_error("[%s] unable to create RRSIGs: allocator failed",
00068 rrsigs_str);
00069 allocator_cleanup(allocator);
00070 return NULL;
00071 }
00072 ods_log_assert(rrsigs);
00073
00074 rrsigs->allocator = allocator;
00075 rrsigs->rr = NULL;
00076 rrsigs->key_locator = NULL;
00077 rrsigs->key_flags = 0;
00078 rrsigs->next = NULL;
00079 return rrsigs;
00080 }
00081
00082
00087 ods_status
00088 rrsigs_add_sig(rrsigs_type* rrsigs, ldns_rr* rr, const char* l, uint32_t f)
00089 {
00090 int cmp;
00091 rrsigs_type* new_rrsigs = NULL;
00092 ldns_status status = LDNS_STATUS_OK;
00093
00094 if (!rrsigs) {
00095 ods_log_error("[%s] unable to add RRSIG: no storage", rrsigs_str);
00096 return ODS_STATUS_ASSERT_ERR;
00097 }
00098 ods_log_assert(rrsigs);
00099
00100 if (!rr) {
00101 ods_log_error("[%s] unable to add RRSIG: no RRSIG RR", rrsigs_str);
00102 return ODS_STATUS_ASSERT_ERR;
00103 }
00104 ods_log_assert(rr);
00105
00106 if (!rrsigs->rr) {
00107 rrsigs->rr = rr;
00108 if (l) {
00109 rrsigs->key_locator = allocator_strdup(rrsigs->allocator, l);
00110 }
00111 rrsigs->key_flags = f;
00112 return ODS_STATUS_OK;
00113 }
00114
00115 status = util_dnssec_rrs_compare(rrsigs->rr, rr, &cmp);
00116 if (status != LDNS_STATUS_OK) {
00117 return ODS_STATUS_ERR;
00118 }
00119 if (cmp < 0) {
00120 if (rrsigs->next) {
00121 return rrsigs_add_sig(rrsigs->next, rr, l, f);
00122 } else {
00123 new_rrsigs = rrsigs_create();
00124 new_rrsigs->rr = rr;
00125 if (l) {
00126 new_rrsigs->key_locator = allocator_strdup(
00127 rrsigs->allocator, l);
00128 }
00129 new_rrsigs->key_flags = f;
00130 rrsigs->next = new_rrsigs;
00131 return ODS_STATUS_OK;
00132 }
00133 } else if (cmp > 0) {
00134
00135
00136 new_rrsigs = rrsigs_create();
00137 new_rrsigs->rr = rrsigs->rr;
00138 new_rrsigs->key_locator = rrsigs->key_locator;
00139 new_rrsigs->key_flags = rrsigs->key_flags;
00140 new_rrsigs->next = rrsigs->next;
00141
00142 rrsigs->rr = rr;
00143 rrsigs->next = new_rrsigs;
00144 if (l) {
00145 rrsigs->key_locator = allocator_strdup(rrsigs->allocator, l);
00146 }
00147 rrsigs->key_flags = f;
00148 return ODS_STATUS_OK;
00149 } else {
00150
00151 ods_log_warning("[%s] adding duplicate RRSIG?", rrsigs_str);
00152 return ODS_STATUS_UNCHANGED;
00153 }
00154
00155 return ODS_STATUS_ERR;
00156 }
00157
00158
00163 void
00164 rrsigs_cleanup(rrsigs_type* rrsigs)
00165 {
00166 allocator_type* allocator;
00167 if (!rrsigs) {
00168 return;
00169 }
00170 if (rrsigs->next) {
00171 rrsigs_cleanup(rrsigs->next);
00172 rrsigs->next = NULL;
00173 }
00174 if (rrsigs->rr) {
00175 ldns_rr_free(rrsigs->rr);
00176 rrsigs->rr = NULL;
00177 }
00178 allocator = rrsigs->allocator;
00179 allocator_deallocate(allocator, (void*) rrsigs->key_locator);
00180 allocator_deallocate(allocator, (void*) rrsigs);
00181 allocator_cleanup(allocator);
00182 return;
00183 }
00184
00185
00190 void
00191 rrsigs_print(FILE* fd, rrsigs_type* rrsigs, int print_key)
00192 {
00193 rrsigs_type* print = NULL;
00194
00195 if (!fd) {
00196 ods_log_error("[%s] unable to print: no fd", rrsigs_str);
00197 return;
00198 }
00199 ods_log_assert(fd);
00200
00201 print = rrsigs;
00202 while (print) {
00203 if (print_key) {
00204 fprintf(fd, ";;RRSIG %s %u\n",
00205 rrsigs->key_locator?rrsigs->key_locator:"(null)",
00206 rrsigs->key_flags);
00207 }
00208 if (print->rr) {
00209 ldns_rr_print(fd, print->rr);
00210 }
00211 print = print->next;
00212 }
00213 return;
00214 }