Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > e3a718fcad37ff363f65d6a6e994e272 > files > 185

ldns-devel-1.6.12-1.fc15.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type"
content="text/html;charset=iso-8859-1">
<title>ldns documentation</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<div class="logo">
<img src="LogoInGradientBar2-y100.png"/>
</div>
<!-- Generated by Doxygen 1.7.4 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="dir_20c14e699119abd60cb7b016b4381923.html">examples</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">ldns-signzone.c</div>  </div>
</div>
<div class="contents">
<a href="ldns-signzone_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * ldns-signzone signs a zone file</span>
<a name="l00003"></a>00003 <span class="comment"> * </span>
<a name="l00004"></a>00004 <span class="comment"> * (c) NLnet Labs, 2005 - 2008</span>
<a name="l00005"></a>00005 <span class="comment"> * See the file LICENSE for the license</span>
<a name="l00006"></a>00006 <span class="comment"> */</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="preprocessor">#include &quot;config.h&quot;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00013"></a>00013 
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;<a class="code" href="ldns_8h.html" title="Including this file will include all ldns files, and define some lookup tables.">ldns/ldns.h</a>&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;<a class="code" href="keys_8h.html" title="Addendum to dnssec.h, this module contains key and algorithm definitions and functions.">ldns/keys.h</a>&gt;</span>
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="preprocessor">#ifdef HAVE_SSL</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#include &lt;openssl/conf.h&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;openssl/engine.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#endif </span><span class="comment">/* HAVE_SSL */</span>
<a name="l00023"></a>00023 
<a name="l00024"></a><a class="code" href="ldns-signzone_8c.html#acc9794f655f61a3246ba3fd5c9c67e14">00024</a> <span class="preprocessor">#define MAX_FILENAME_LEN 250</span>
<a name="l00025"></a><a class="code" href="ldns-signzone_8c.html#a1bdcfae3209cbd96db35a2ae356fa15e">00025</a> <span class="preprocessor"></span><span class="keywordtype">int</span> <a class="code" href="ldns-signzone_8c.html#a1bdcfae3209cbd96db35a2ae356fa15e">verbosity</a> = 1;
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_SSL</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#include &lt;openssl/err.h&gt;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00031"></a>00031 usage(FILE *fp, <span class="keyword">const</span> <span class="keywordtype">char</span> *prog) {
<a name="l00032"></a>00032         fprintf(fp, <span class="stringliteral">&quot;%s [OPTIONS] zonefile key [key [key]]\n&quot;</span>, prog);
<a name="l00033"></a>00033         fprintf(fp, <span class="stringliteral">&quot;  signs the zone with the given key(s)\n&quot;</span>);
<a name="l00034"></a>00034         fprintf(fp, <span class="stringliteral">&quot;  -b\t\tuse layout in signed zone and print comments DNSSEC records\n&quot;</span>);
<a name="l00035"></a>00035         fprintf(fp, <span class="stringliteral">&quot;  -d\t\tused keys are not added to the zone\n&quot;</span>);
<a name="l00036"></a>00036         fprintf(fp, <span class="stringliteral">&quot;  -e &lt;date&gt;\texpiration date\n&quot;</span>);
<a name="l00037"></a>00037         fprintf(fp, <span class="stringliteral">&quot;  -f &lt;file&gt;\toutput zone to file (default &lt;name&gt;.signed)\n&quot;</span>);
<a name="l00038"></a>00038         fprintf(fp, <span class="stringliteral">&quot;  -i &lt;date&gt;\tinception date\n&quot;</span>);
<a name="l00039"></a>00039         fprintf(fp, <span class="stringliteral">&quot;  -l\t\tLeave old DNSSEC RRSIGS and NSEC(3) records intact\n&quot;</span>);
<a name="l00040"></a>00040         fprintf(fp, <span class="stringliteral">&quot;  -o &lt;domain&gt;\torigin for the zone\n&quot;</span>);
<a name="l00041"></a>00041         fprintf(fp, <span class="stringliteral">&quot;  -v\t\tprint version and exit\n&quot;</span>);
<a name="l00042"></a>00042         fprintf(fp, <span class="stringliteral">&quot;  -A\t\tsign DNSKEY with all keys instead of minimal\n&quot;</span>);
<a name="l00043"></a>00043         fprintf(fp, <span class="stringliteral">&quot;  -E &lt;name&gt;\tuse &lt;name&gt; as the crypto engine for signing\n&quot;</span>);
<a name="l00044"></a>00044         fprintf(fp, <span class="stringliteral">&quot;           \tThis can have a lot of extra options, see the manual page for more info\n&quot;</span>);
<a name="l00045"></a>00045         fprintf(fp, <span class="stringliteral">&quot;  -k &lt;id&gt;,&lt;int&gt;\tuse key id with algorithm int from engine\n&quot;</span>);
<a name="l00046"></a>00046         fprintf(fp, <span class="stringliteral">&quot;  -K &lt;id&gt;,&lt;int&gt;\tuse key id with algorithm int from engine as KSK\n&quot;</span>);
<a name="l00047"></a>00047         fprintf(fp, <span class="stringliteral">&quot;\t\tif no key is given (but an external one is used through the engine support, it might be necessary to provide the right algorithm number.\n&quot;</span>);
<a name="l00048"></a>00048         fprintf(fp, <span class="stringliteral">&quot;  -n\t\tuse NSEC3 instead of NSEC.\n&quot;</span>);
<a name="l00049"></a>00049         fprintf(fp, <span class="stringliteral">&quot;\t\tIf you use NSEC3, you can specify the following extra options:\n&quot;</span>);
<a name="l00050"></a>00050         fprintf(fp, <span class="stringliteral">&quot;\t\t-a [algorithm] hashing algorithm\n&quot;</span>);
<a name="l00051"></a>00051         fprintf(fp, <span class="stringliteral">&quot;\t\t-t [number] number of hash iterations\n&quot;</span>);
<a name="l00052"></a>00052         fprintf(fp, <span class="stringliteral">&quot;\t\t-s [string] salt\n&quot;</span>);
<a name="l00053"></a>00053         fprintf(fp, <span class="stringliteral">&quot;\t\t-p set the opt-out flag on all nsec3 rrs\n&quot;</span>);
<a name="l00054"></a>00054         fprintf(fp, <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00055"></a>00055         fprintf(fp, <span class="stringliteral">&quot;  keys must be specified by their base name (usually K&lt;name&gt;+&lt;alg&gt;+&lt;id&gt;),\n&quot;</span>);
<a name="l00056"></a>00056         fprintf(fp, <span class="stringliteral">&quot;  i.e. WITHOUT the .private extension.\n&quot;</span>);
<a name="l00057"></a>00057         fprintf(fp, <span class="stringliteral">&quot;  If the public part of the key is not present in the zone, the DNSKEY RR\n&quot;</span>);
<a name="l00058"></a>00058         fprintf(fp, <span class="stringliteral">&quot;  will be read from the file called &lt;base name&gt;.key. If that does not exist,\n&quot;</span>);
<a name="l00059"></a>00059         fprintf(fp, <span class="stringliteral">&quot;  a default DNSKEY will be generated from the private key and added to the zone.\n&quot;</span>);
<a name="l00060"></a>00060         fprintf(fp, <span class="stringliteral">&quot;  A date can be a timestamp (seconds since the epoch), or of\n  the form &lt;YYYYMMdd[hhmmss]&gt;\n&quot;</span>);
<a name="l00061"></a>00061 }
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 <span class="keywordtype">void</span>
<a name="l00064"></a><a class="code" href="ldns-signzone_8c.html#a1f9a113bad24d71e4ea5832e6f2ecf49">00064</a> <a class="code" href="ldns-signzone_8c.html#a1f9a113bad24d71e4ea5832e6f2ecf49">usage_openssl</a>(FILE *fp, <span class="keyword">const</span> <span class="keywordtype">char</span> *prog) {
<a name="l00065"></a>00065         fprintf(fp, <span class="stringliteral">&quot;Special commands for openssl engines:\n&quot;</span>);
<a name="l00066"></a>00066         fprintf(fp, <span class="stringliteral">&quot;-c &lt;file&gt;\tOpenSSL config file\n&quot;</span>);
<a name="l00067"></a>00067 }
<a name="l00068"></a>00068 
<a name="l00069"></a>00069 <span class="keyword">static</span> <span class="keywordtype">void</span> check_tm(<span class="keyword">struct</span> tm tm)
<a name="l00070"></a>00070 {
<a name="l00071"></a>00071         <span class="keywordflow">if</span> (tm.tm_year &lt; 70) {
<a name="l00072"></a>00072                 fprintf(stderr, <span class="stringliteral">&quot;You cannot specify dates before 1970\n&quot;</span>);
<a name="l00073"></a>00073                 exit(EXIT_FAILURE);
<a name="l00074"></a>00074         }
<a name="l00075"></a>00075         <span class="keywordflow">if</span> (tm.tm_mon &lt; 0 || tm.tm_mon &gt; 11) {
<a name="l00076"></a>00076                 fprintf(stderr, <span class="stringliteral">&quot;The month must be in the range 1 to 12\n&quot;</span>);
<a name="l00077"></a>00077                 exit(EXIT_FAILURE);
<a name="l00078"></a>00078         }
<a name="l00079"></a>00079         <span class="keywordflow">if</span> (tm.tm_mday &lt; 1 || tm.tm_mday &gt; 31) {
<a name="l00080"></a>00080                 fprintf(stderr, <span class="stringliteral">&quot;The day must be in the range 1 to 31\n&quot;</span>);
<a name="l00081"></a>00081                 exit(EXIT_FAILURE);
<a name="l00082"></a>00082         }
<a name="l00083"></a>00083         
<a name="l00084"></a>00084         <span class="keywordflow">if</span> (tm.tm_hour &lt; 0 || tm.tm_hour &gt; 23) {
<a name="l00085"></a>00085                 fprintf(stderr, <span class="stringliteral">&quot;The hour must be in the range 0-23\n&quot;</span>);
<a name="l00086"></a>00086                 exit(EXIT_FAILURE);
<a name="l00087"></a>00087         }
<a name="l00088"></a>00088 
<a name="l00089"></a>00089         <span class="keywordflow">if</span> (tm.tm_min &lt; 0 || tm.tm_min &gt; 59) {
<a name="l00090"></a>00090                 fprintf(stderr, <span class="stringliteral">&quot;The minute must be in the range 0-59\n&quot;</span>);
<a name="l00091"></a>00091                 exit(EXIT_FAILURE);
<a name="l00092"></a>00092         }
<a name="l00093"></a>00093 
<a name="l00094"></a>00094         <span class="keywordflow">if</span> (tm.tm_sec &lt; 0 || tm.tm_sec &gt; 59) {
<a name="l00095"></a>00095                 fprintf(stderr, <span class="stringliteral">&quot;The second must be in the range 0-59\n&quot;</span>);
<a name="l00096"></a>00096                 exit(EXIT_FAILURE);
<a name="l00097"></a>00097         }
<a name="l00098"></a>00098 
<a name="l00099"></a>00099 }
<a name="l00100"></a>00100 
<a name="l00101"></a>00101 <span class="comment">/*</span>
<a name="l00102"></a>00102 <span class="comment"> * if the ttls are different, make them equal</span>
<a name="l00103"></a>00103 <span class="comment"> * if one of the ttls equals LDNS_DEFAULT_TTL, that one is changed</span>
<a name="l00104"></a>00104 <span class="comment"> * otherwise, rr2 will get the ttl of rr1</span>
<a name="l00105"></a>00105 <span class="comment"> * </span>
<a name="l00106"></a>00106 <span class="comment"> * prints a warning if a non-default TTL is changed</span>
<a name="l00107"></a>00107 <span class="comment"> */</span>
<a name="l00108"></a>00108 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00109"></a>00109 equalize_ttls(<a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *rr1, <a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *rr2, uint32_t default_ttl)
<a name="l00110"></a>00110 {
<a name="l00111"></a>00111         uint32_t ttl1, ttl2;
<a name="l00112"></a>00112         
<a name="l00113"></a>00113         ttl1 = <a class="code" href="rr_8c.html#a144e619c75e8cef52fa5a1de7d74c695" title="returns the ttl of an rr structure.">ldns_rr_ttl</a>(rr1);
<a name="l00114"></a>00114         ttl2 = <a class="code" href="rr_8c.html#a144e619c75e8cef52fa5a1de7d74c695" title="returns the ttl of an rr structure.">ldns_rr_ttl</a>(rr2);
<a name="l00115"></a>00115         
<a name="l00116"></a>00116         <span class="keywordflow">if</span> (ttl1 != ttl2) {
<a name="l00117"></a>00117                 <span class="keywordflow">if</span> (ttl1 == default_ttl) {
<a name="l00118"></a>00118                         <a class="code" href="rr_8c.html#a84a12460eb7ffe5c5fd3d84e9efbe3cf" title="sets the ttl in the rr structure.">ldns_rr_set_ttl</a>(rr1, ttl2);
<a name="l00119"></a>00119                 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ttl2 == default_ttl) {
<a name="l00120"></a>00120                         <a class="code" href="rr_8c.html#a84a12460eb7ffe5c5fd3d84e9efbe3cf" title="sets the ttl in the rr structure.">ldns_rr_set_ttl</a>(rr2, ttl1);
<a name="l00121"></a>00121                 } <span class="keywordflow">else</span> {
<a name="l00122"></a>00122                         <a class="code" href="rr_8c.html#a84a12460eb7ffe5c5fd3d84e9efbe3cf" title="sets the ttl in the rr structure.">ldns_rr_set_ttl</a>(rr2, ttl1);
<a name="l00123"></a>00123                         fprintf(stderr, 
<a name="l00124"></a>00124                                 <span class="stringliteral">&quot;warning: changing non-default TTL %u to %u\n&quot;</span>,
<a name="l00125"></a>00125                                 (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>) ttl2, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)  ttl1);
<a name="l00126"></a>00126                 }
<a name="l00127"></a>00127         }
<a name="l00128"></a>00128 }
<a name="l00129"></a>00129 
<a name="l00130"></a>00130 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00131"></a>00131 equalize_ttls_rr_list(<a class="code" href="structldns__struct__rr__list.html" title="List or Set of Resource Records.">ldns_rr_list</a> *rr_list, <a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *rr, uint32_t default_ttl)
<a name="l00132"></a>00132 {
<a name="l00133"></a>00133         <span class="keywordtype">size_t</span> i;
<a name="l00134"></a>00134         <a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *cur_rr;
<a name="l00135"></a>00135         
<a name="l00136"></a>00136         <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code" href="rr_8c.html#a7ac3192fe79ba66e47579bb2b267ce05" title="returns the number of rr&#39;s in an rr_list.">ldns_rr_list_rr_count</a>(rr_list); i++) {
<a name="l00137"></a>00137                 cur_rr = <a class="code" href="rr_8c.html#a07b1ccea9f2694b8b88904c543e16783" title="returns a specific rr of an rrlist.">ldns_rr_list_rr</a>(rr_list, i);
<a name="l00138"></a>00138                 <span class="keywordflow">if</span> (<a class="code" href="rr_8c.html#a95b72e9e49320b29d34739a069b31899" title="compares two rrs, up to the rdata.">ldns_rr_compare_no_rdata</a>(cur_rr, rr) == 0) {
<a name="l00139"></a>00139                         equalize_ttls(cur_rr, rr, default_ttl);
<a name="l00140"></a>00140                 }
<a name="l00141"></a>00141         }
<a name="l00142"></a>00142 }
<a name="l00143"></a>00143 
<a name="l00144"></a>00144 <span class="keyword">static</span> <a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *
<a name="l00145"></a>00145 find_key_in_zone(<a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *pubkey_gen, <a class="code" href="structldns__struct__zone.html" title="DNS Zone.">ldns_zone</a> *zone) {
<a name="l00146"></a>00146         <span class="keywordtype">size_t</span> key_i;
<a name="l00147"></a>00147         <a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *pubkey;
<a name="l00148"></a>00148         
<a name="l00149"></a>00149         <span class="keywordflow">for</span> (key_i = 0;
<a name="l00150"></a>00150                 key_i &lt; <a class="code" href="rr_8c.html#a7ac3192fe79ba66e47579bb2b267ce05" title="returns the number of rr&#39;s in an rr_list.">ldns_rr_list_rr_count</a>(<a class="code" href="zone_8c.html#a5a75b7744ea0d91770d579730a84bbf9" title="Get a list of a zone&#39;s content.">ldns_zone_rrs</a>(zone));
<a name="l00151"></a>00151                 key_i++) {
<a name="l00152"></a>00152                 pubkey = <a class="code" href="rr_8c.html#a07b1ccea9f2694b8b88904c543e16783" title="returns a specific rr of an rrlist.">ldns_rr_list_rr</a>(<a class="code" href="zone_8c.html#a5a75b7744ea0d91770d579730a84bbf9" title="Get a list of a zone&#39;s content.">ldns_zone_rrs</a>(zone), key_i);
<a name="l00153"></a>00153                 <span class="keywordflow">if</span> (<a class="code" href="rr_8c.html#a849c616b8e8d87b8c047a8b41be21228" title="returns the type of the rr.">ldns_rr_get_type</a>(pubkey) == <a class="code" href="rr_8h.html#a640100112b0009efe3d61bbf799b33daa316efb0ac15f31b6891fa6fba833eae8">LDNS_RR_TYPE_DNSKEY</a> &amp;&amp;
<a name="l00154"></a>00154                         (<a class="code" href="dnssec_8c.html#a7cf8c4687caff6153a61052c5523e7ab" title="calculates a keytag of a key for use in DNSSEC.">ldns_calc_keytag</a>(pubkey)
<a name="l00155"></a>00155                                 ==
<a name="l00156"></a>00156                                 <a class="code" href="dnssec_8c.html#a7cf8c4687caff6153a61052c5523e7ab" title="calculates a keytag of a key for use in DNSSEC.">ldns_calc_keytag</a>(pubkey_gen) ||
<a name="l00157"></a>00157                                          <span class="comment">/* KSK has gen-keytag + 1 */</span>
<a name="l00158"></a>00158                                          <a class="code" href="dnssec_8c.html#a7cf8c4687caff6153a61052c5523e7ab" title="calculates a keytag of a key for use in DNSSEC.">ldns_calc_keytag</a>(pubkey)
<a name="l00159"></a>00159                                          ==
<a name="l00160"></a>00160                                          <a class="code" href="dnssec_8c.html#a7cf8c4687caff6153a61052c5523e7ab" title="calculates a keytag of a key for use in DNSSEC.">ldns_calc_keytag</a>(pubkey_gen) + 1) 
<a name="l00161"></a>00161                            ) {
<a name="l00162"></a>00162                                 <span class="keywordflow">if</span> (<a class="code" href="ldns-signzone_8c.html#a1bdcfae3209cbd96db35a2ae356fa15e">verbosity</a> &gt;= 2) {
<a name="l00163"></a>00163                                         fprintf(stderr, <span class="stringliteral">&quot;Found it in the zone!\n&quot;</span>);
<a name="l00164"></a>00164                                 }
<a name="l00165"></a>00165                                 <span class="keywordflow">return</span> pubkey;
<a name="l00166"></a>00166                 }
<a name="l00167"></a>00167         }
<a name="l00168"></a>00168         <span class="keywordflow">return</span> NULL;
<a name="l00169"></a>00169 }
<a name="l00170"></a>00170 
<a name="l00171"></a>00171 <span class="keyword">static</span> <a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *
<a name="l00172"></a>00172 find_key_in_file(<span class="keyword">const</span> <span class="keywordtype">char</span> *keyfile_name_base, <a class="code" href="structldns__struct__key.html" title="General key structure, can contain all types of keys that are used in DNSSEC.">ldns_key</a> *key, uint32_t zone_ttl)
<a name="l00173"></a>00173 {
<a name="l00174"></a>00174         <span class="keywordtype">char</span> *keyfile_name;
<a name="l00175"></a>00175         FILE *keyfile;
<a name="l00176"></a>00176         <span class="keywordtype">int</span> line_nr;
<a name="l00177"></a>00177         uint32_t default_ttl = zone_ttl;
<a name="l00178"></a>00178 
<a name="l00179"></a>00179         <a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *pubkey = NULL;
<a name="l00180"></a>00180         keyfile_name = <a class="code" href="util_8h.html#aaad6949daea3c6cefd01d19300f6e21a">LDNS_XMALLOC</a>(<span class="keywordtype">char</span>,
<a name="l00181"></a>00181                                     strlen(keyfile_name_base) + 5);
<a name="l00182"></a>00182         <a class="code" href="config_8h.html#acc2509f3dc1aeb186437c3fd8412e69a">snprintf</a>(keyfile_name,
<a name="l00183"></a>00183                  strlen(keyfile_name_base) + 5,
<a name="l00184"></a>00184                  <span class="stringliteral">&quot;%s.key&quot;</span>,
<a name="l00185"></a>00185                  keyfile_name_base);
<a name="l00186"></a>00186         <span class="keywordflow">if</span> (<a class="code" href="ldns-signzone_8c.html#a1bdcfae3209cbd96db35a2ae356fa15e">verbosity</a> &gt;= 2) {
<a name="l00187"></a>00187                 fprintf(stderr, <span class="stringliteral">&quot;Trying to read %s\n&quot;</span>, keyfile_name);
<a name="l00188"></a>00188         }
<a name="l00189"></a>00189         keyfile = fopen(keyfile_name, <span class="stringliteral">&quot;r&quot;</span>);
<a name="l00190"></a>00190         line_nr = 0;
<a name="l00191"></a>00191         <span class="keywordflow">if</span> (keyfile) {
<a name="l00192"></a>00192                 <span class="keywordflow">if</span> (<a class="code" href="rr_8c.html#a21ee1c464cecb3c05046fbcb207a7f95" title="creates a new rr from a file containing a string.">ldns_rr_new_frm_fp_l</a>(&amp;pubkey,
<a name="l00193"></a>00193                                          keyfile,
<a name="l00194"></a>00194                                          &amp;default_ttl,
<a name="l00195"></a>00195                                          NULL,
<a name="l00196"></a>00196                                          NULL,
<a name="l00197"></a>00197                                          &amp;line_nr) ==
<a name="l00198"></a>00198                     <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) {
<a name="l00199"></a>00199                         <span class="keywordflow">if</span> (<a class="code" href="ldns-signzone_8c.html#a1bdcfae3209cbd96db35a2ae356fa15e">verbosity</a> &gt;= 2) {
<a name="l00200"></a>00200                                 printf(<span class="stringliteral">&quot;Key found in file: %s\n&quot;</span>, keyfile_name);
<a name="l00201"></a>00201                         }
<a name="l00202"></a>00202                 }
<a name="l00203"></a>00203                 fclose(keyfile);
<a name="l00204"></a>00204         }
<a name="l00205"></a>00205         <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(keyfile_name);
<a name="l00206"></a>00206         <span class="keywordflow">return</span> pubkey;
<a name="l00207"></a>00207 }
<a name="l00208"></a>00208 
<a name="l00209"></a>00209 <span class="comment">/* this function tries to find the specified keys either in the zone that</span>
<a name="l00210"></a>00210 <span class="comment"> * has been read, or in a &lt;basename&gt;.key file. If the key is not found,</span>
<a name="l00211"></a>00211 <span class="comment"> * a public key is generated, and it is assumed the key is a ZSK</span>
<a name="l00212"></a>00212 <span class="comment"> * </span>
<a name="l00213"></a>00213 <span class="comment"> * if add_keys is true; the DNSKEYs are added to the zone prior to signing</span>
<a name="l00214"></a>00214 <span class="comment"> * if it is false, they are not added.</span>
<a name="l00215"></a>00215 <span class="comment"> * Even if keys are not added, the function is still needed, to check</span>
<a name="l00216"></a>00216 <span class="comment"> * whether keys of which we only have key data are KSKs or ZSKS</span>
<a name="l00217"></a>00217 <span class="comment"> */</span>
<a name="l00218"></a>00218 <span class="keyword">static</span> <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a>
<a name="l00219"></a>00219 find_or_create_pubkey(<span class="keyword">const</span> <span class="keywordtype">char</span> *keyfile_name_base, <a class="code" href="structldns__struct__key.html" title="General key structure, can contain all types of keys that are used in DNSSEC.">ldns_key</a> *key, <a class="code" href="structldns__struct__zone.html" title="DNS Zone.">ldns_zone</a> *orig_zone, <span class="keywordtype">bool</span> add_keys, uint32_t default_ttl) {
<a name="l00220"></a>00220         <a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *pubkey_gen, *pubkey;
<a name="l00221"></a>00221         <span class="keywordtype">int</span> key_in_zone;
<a name="l00222"></a>00222         
<a name="l00223"></a>00223         <span class="keywordflow">if</span> (default_ttl == <a class="code" href="ldns_8h.html#a2bdd8bfa0eb61ccf7719d5ffcd1ac79e">LDNS_DEFAULT_TTL</a>) {
<a name="l00224"></a>00224                 default_ttl = <a class="code" href="rr_8c.html#a144e619c75e8cef52fa5a1de7d74c695" title="returns the ttl of an rr structure.">ldns_rr_ttl</a>(<a class="code" href="zone_8c.html#aae16d59c27e1f2292f8bd87604517e0c" title="Return the soa record of a zone.">ldns_zone_soa</a>(orig_zone));
<a name="l00225"></a>00225         }
<a name="l00226"></a>00226 
<a name="l00227"></a>00227         <span class="keywordflow">if</span> (!<a class="code" href="keys_8c.html#ab8c7cbd30af086afa9046f059bc245c9" title="return the public key&#39;s owner">ldns_key_pubkey_owner</a>(key)) {
<a name="l00228"></a>00228                 <a class="code" href="keys_8c.html#a4c0b77f2579a2a6ce4355aa29de237e5" title="Set the key&#39;s pubkey owner.">ldns_key_set_pubkey_owner</a>(key, <a class="code" href="rdata_8c.html#af9a39f2f8b749efa6a20ba91cb696961" title="clones a rdf structure.">ldns_rdf_clone</a>(<a class="code" href="rr_8c.html#a1d254bd0deb5d18e34d84ebc10496c5d" title="returns the owner name of an rr structure.">ldns_rr_owner</a>(<a class="code" href="zone_8c.html#aae16d59c27e1f2292f8bd87604517e0c" title="Return the soa record of a zone.">ldns_zone_soa</a>(orig_zone))));
<a name="l00229"></a>00229         }
<a name="l00230"></a>00230 
<a name="l00231"></a>00231         <span class="comment">/* find the public key in the zone, or in a</span>
<a name="l00232"></a>00232 <span class="comment">         * seperate file</span>
<a name="l00233"></a>00233 <span class="comment">         * we &#39;generate&#39; one anyway, </span>
<a name="l00234"></a>00234 <span class="comment">         * then match that to any present in the zone,</span>
<a name="l00235"></a>00235 <span class="comment">         * if it matches, we drop our own. If not,</span>
<a name="l00236"></a>00236 <span class="comment">         * we try to see if there is a .key file present.</span>
<a name="l00237"></a>00237 <span class="comment">         * If not, we use our own generated one, with</span>
<a name="l00238"></a>00238 <span class="comment">         * some default values </span>
<a name="l00239"></a>00239 <span class="comment">         *</span>
<a name="l00240"></a>00240 <span class="comment">         * Even if -d (do-not-add-keys) is specified, </span>
<a name="l00241"></a>00241 <span class="comment">         * we still need to do this, because we need</span>
<a name="l00242"></a>00242 <span class="comment">         * to have any key flags that are set this way</span>
<a name="l00243"></a>00243 <span class="comment">         */</span>
<a name="l00244"></a>00244         pubkey_gen = <a class="code" href="keys_8c.html#a45bdcdbe6aac4764bff1ad12a86a6541" title="converts a ldns_key to a public key rr If the key data exists at an external point, the corresponding rdata field must still be added with ldns_rr_rdf_push() to the result rr of this function">ldns_key2rr</a>(key);
<a name="l00245"></a>00245         <a class="code" href="rr_8c.html#a84a12460eb7ffe5c5fd3d84e9efbe3cf" title="sets the ttl in the rr structure.">ldns_rr_set_ttl</a>(pubkey_gen, default_ttl);
<a name="l00246"></a>00246 
<a name="l00247"></a>00247         <span class="keywordflow">if</span> (<a class="code" href="ldns-signzone_8c.html#a1bdcfae3209cbd96db35a2ae356fa15e">verbosity</a> &gt;= 2) {
<a name="l00248"></a>00248                 fprintf(stderr,
<a name="l00249"></a>00249                            <span class="stringliteral">&quot;Looking for key with keytag %u or %u\n&quot;</span>,
<a name="l00250"></a>00250                            (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>) <a class="code" href="dnssec_8c.html#a7cf8c4687caff6153a61052c5523e7ab" title="calculates a keytag of a key for use in DNSSEC.">ldns_calc_keytag</a>(pubkey_gen),
<a name="l00251"></a>00251                            (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>) <a class="code" href="dnssec_8c.html#a7cf8c4687caff6153a61052c5523e7ab" title="calculates a keytag of a key for use in DNSSEC.">ldns_calc_keytag</a>(pubkey_gen)+1
<a name="l00252"></a>00252                            );
<a name="l00253"></a>00253         }
<a name="l00254"></a>00254 
<a name="l00255"></a>00255         pubkey = find_key_in_zone(pubkey_gen, orig_zone);
<a name="l00256"></a>00256         key_in_zone = 1;
<a name="l00257"></a>00257         <span class="keywordflow">if</span> (!pubkey) {
<a name="l00258"></a>00258                 key_in_zone = 0;
<a name="l00259"></a>00259                 <span class="comment">/* it was not in the zone, try to read a .key file */</span>
<a name="l00260"></a>00260                 pubkey = find_key_in_file(keyfile_name_base, key, default_ttl);
<a name="l00261"></a>00261                 <span class="keywordflow">if</span> (!pubkey &amp;&amp; !(<a class="code" href="keys_8c.html#ad4359824295f24c7cef57b616288947d" title="return the flag of the key">ldns_key_flags</a>(key) &amp; <a class="code" href="keys_8h.html#a32c73f4b55d4cd43d7303b1351baa84c">LDNS_KEY_SEP_KEY</a>)) {
<a name="l00262"></a>00262                         <span class="comment">/* maybe it is a ksk? */</span>
<a name="l00263"></a>00263                         <a class="code" href="keys_8c.html#a9bdf435dfcf6a6a603c3284054a8126c" title="Set the key&#39;s key tag.">ldns_key_set_keytag</a>(key, <a class="code" href="keys_8c.html#a8cf2ca2fc8d72b28076157beb791b347" title="return the keytag">ldns_key_keytag</a>(key) + 1);
<a name="l00264"></a>00264                         pubkey = find_key_in_file(keyfile_name_base, key, default_ttl);
<a name="l00265"></a>00265                         <span class="keywordflow">if</span> (!pubkey) {
<a name="l00266"></a>00266                                 <span class="comment">/* ok, no file, set back to ZSK */</span>
<a name="l00267"></a>00267                                 <a class="code" href="keys_8c.html#a9bdf435dfcf6a6a603c3284054a8126c" title="Set the key&#39;s key tag.">ldns_key_set_keytag</a>(key, <a class="code" href="keys_8c.html#a8cf2ca2fc8d72b28076157beb791b347" title="return the keytag">ldns_key_keytag</a>(key) - 1);
<a name="l00268"></a>00268                         }
<a name="l00269"></a>00269                 }
<a name="l00270"></a>00270                 <span class="keywordflow">if</span>(pubkey &amp;&amp; <a class="code" href="dname_8c.html#a6faaee00444aad0fde1c672216e5a8b7" title="Compares the two dname rdf&#39;s according to the algorithm for ordering in RFC4034 Section 6...">ldns_dname_compare</a>(<a class="code" href="rr_8c.html#a1d254bd0deb5d18e34d84ebc10496c5d" title="returns the owner name of an rr structure.">ldns_rr_owner</a>(pubkey), <a class="code" href="rr_8c.html#a1d254bd0deb5d18e34d84ebc10496c5d" title="returns the owner name of an rr structure.">ldns_rr_owner</a>(<a class="code" href="zone_8c.html#aae16d59c27e1f2292f8bd87604517e0c" title="Return the soa record of a zone.">ldns_zone_soa</a>(orig_zone))) != 0) {
<a name="l00271"></a>00271                         fprintf(stderr, <span class="stringliteral">&quot;Error %s.key has wrong name: %s\n&quot;</span>,
<a name="l00272"></a>00272                                 keyfile_name_base, <a class="code" href="host2str_8c.html#ae404881f2bc2bd31588e32e250f2c46b" title="Converts the data in the rdata field to presentation format and returns that as a char *...">ldns_rdf2str</a>(<a class="code" href="rr_8c.html#a1d254bd0deb5d18e34d84ebc10496c5d" title="returns the owner name of an rr structure.">ldns_rr_owner</a>(pubkey)));
<a name="l00273"></a>00273                         exit(EXIT_FAILURE); <span class="comment">/* leak rdf2str, but we exit */</span>
<a name="l00274"></a>00274                 }
<a name="l00275"></a>00275         }
<a name="l00276"></a>00276         
<a name="l00277"></a>00277         <span class="keywordflow">if</span> (!pubkey) {
<a name="l00278"></a>00278                 <span class="comment">/* okay, no public key found,</span>
<a name="l00279"></a>00279 <span class="comment">                   just use our generated one */</span>
<a name="l00280"></a>00280                 pubkey = pubkey_gen;
<a name="l00281"></a>00281                 <span class="keywordflow">if</span> (<a class="code" href="ldns-signzone_8c.html#a1bdcfae3209cbd96db35a2ae356fa15e">verbosity</a> &gt;= 2) {
<a name="l00282"></a>00282                         fprintf(stderr, <span class="stringliteral">&quot;Not in zone, no .key file, generating ZSK DNSKEY from private key data\n&quot;</span>);
<a name="l00283"></a>00283                 }
<a name="l00284"></a>00284         } <span class="keywordflow">else</span> {
<a name="l00285"></a>00285                 <a class="code" href="rr_8c.html#a277ccb85853d3c527ff3bc963cdde505" title="frees an RR structure">ldns_rr_free</a>(pubkey_gen);
<a name="l00286"></a>00286         }
<a name="l00287"></a>00287         <a class="code" href="keys_8c.html#aea3bc851574cf6ccc40d850deaea348f" title="Set the key&#39;s flags.">ldns_key_set_flags</a>(key, <a class="code" href="rdata_8c.html#a5906b621eda1380a2993255fa649c21d" title="returns the native uint16_t representation from the rdf.">ldns_rdf2native_int16</a>(<a class="code" href="rr_8c.html#aed836e7b90f7c11993d92a4569d7e29b" title="returns the rdata field member counter.">ldns_rr_rdf</a>(pubkey, 0)));
<a name="l00288"></a>00288         <a class="code" href="keys_8c.html#a9bdf435dfcf6a6a603c3284054a8126c" title="Set the key&#39;s key tag.">ldns_key_set_keytag</a>(key, <a class="code" href="dnssec_8c.html#a7cf8c4687caff6153a61052c5523e7ab" title="calculates a keytag of a key for use in DNSSEC.">ldns_calc_keytag</a>(pubkey));
<a name="l00289"></a>00289         
<a name="l00290"></a>00290         <span class="keywordflow">if</span> (add_keys &amp;&amp; !key_in_zone) {
<a name="l00291"></a>00291                 equalize_ttls_rr_list(<a class="code" href="zone_8c.html#a5a75b7744ea0d91770d579730a84bbf9" title="Get a list of a zone&#39;s content.">ldns_zone_rrs</a>(orig_zone), pubkey, default_ttl);
<a name="l00292"></a>00292                 <a class="code" href="zone_8c.html#aa292fe9d4d934d13780d0a56de21ebe2" title="push an single rr to a zone structure.">ldns_zone_push_rr</a>(orig_zone, pubkey);
<a name="l00293"></a>00293         }
<a name="l00294"></a>00294         <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>;
<a name="l00295"></a>00295 }
<a name="l00296"></a>00296 
<a name="l00297"></a>00297 <span class="keywordtype">void</span>
<a name="l00298"></a><a class="code" href="ldns-signzone_8c.html#a87f821d26773e5699840987980d1ce31">00298</a> <a class="code" href="ldns-signzone_8c.html#a87f821d26773e5699840987980d1ce31">strip_dnssec_records</a>(<a class="code" href="structldns__struct__zone.html" title="DNS Zone.">ldns_zone</a> *zone)
<a name="l00299"></a>00299 {
<a name="l00300"></a>00300         <a class="code" href="structldns__struct__rr__list.html" title="List or Set of Resource Records.">ldns_rr_list</a> *new_list;
<a name="l00301"></a>00301         <a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *cur_rr;
<a name="l00302"></a>00302         
<a name="l00303"></a>00303         new_list = <a class="code" href="rr_8c.html#aa7405c3451df02516f62f6197ff06268" title="creates a new rr_list structure.">ldns_rr_list_new</a>();
<a name="l00304"></a>00304         
<a name="l00305"></a>00305         <span class="keywordflow">while</span> ((cur_rr = <a class="code" href="rr_8c.html#a09395bafcd69ac1267639c3fa81e8b0f" title="pops the last rr from an rrlist.">ldns_rr_list_pop_rr</a>(<a class="code" href="zone_8c.html#a5a75b7744ea0d91770d579730a84bbf9" title="Get a list of a zone&#39;s content.">ldns_zone_rrs</a>(zone)))) {
<a name="l00306"></a>00306                 <span class="keywordflow">if</span> (<a class="code" href="rr_8c.html#a849c616b8e8d87b8c047a8b41be21228" title="returns the type of the rr.">ldns_rr_get_type</a>(cur_rr) == <a class="code" href="rr_8h.html#a640100112b0009efe3d61bbf799b33daa0dae8d9f8f4684e63ac7665a2a489b4d" title="draft-ietf-dnsext-dnssec-25">LDNS_RR_TYPE_RRSIG</a> ||
<a name="l00307"></a>00307                     <a class="code" href="rr_8c.html#a849c616b8e8d87b8c047a8b41be21228" title="returns the type of the rr.">ldns_rr_get_type</a>(cur_rr) == <a class="code" href="rr_8h.html#a640100112b0009efe3d61bbf799b33daa5413827ac0392a4d65d53b1b7d04f989">LDNS_RR_TYPE_NSEC</a> ||
<a name="l00308"></a>00308                     <a class="code" href="rr_8c.html#a849c616b8e8d87b8c047a8b41be21228" title="returns the type of the rr.">ldns_rr_get_type</a>(cur_rr) == <a class="code" href="rr_8h.html#a640100112b0009efe3d61bbf799b33daa79a5eacdaa6defd52d97a6b205f102f9">LDNS_RR_TYPE_NSEC3</a>
<a name="l00309"></a>00309                    ) {
<a name="l00310"></a>00310                         
<a name="l00311"></a>00311                         <a class="code" href="rr_8c.html#a277ccb85853d3c527ff3bc963cdde505" title="frees an RR structure">ldns_rr_free</a>(cur_rr);
<a name="l00312"></a>00312                 } <span class="keywordflow">else</span> {
<a name="l00313"></a>00313                         <a class="code" href="rr_8c.html#a8bdc038678e7492ae3facf83283f8d04" title="pushes an rr to an rrlist.">ldns_rr_list_push_rr</a>(new_list, cur_rr);
<a name="l00314"></a>00314                 }
<a name="l00315"></a>00315         }
<a name="l00316"></a>00316         <a class="code" href="rr_8c.html#a00ae3d3571b0dba3014269b617992492" title="frees an rr_list structure.">ldns_rr_list_free</a>(<a class="code" href="zone_8c.html#a5a75b7744ea0d91770d579730a84bbf9" title="Get a list of a zone&#39;s content.">ldns_zone_rrs</a>(zone));
<a name="l00317"></a>00317         <a class="code" href="zone_8c.html#a23fd3cc25ccd0ebc76f44746c56480f0" title="Set the zone&#39;s contents.">ldns_zone_set_rrs</a>(zone, new_list);
<a name="l00318"></a>00318 }
<a name="l00319"></a>00319 
<a name="l00320"></a>00320 <span class="keywordtype">int</span>
<a name="l00321"></a><a class="code" href="ldns-signzone_8c.html#a0ddf1224851353fc92bfbff6f499fa97">00321</a> <a class="code" href="linktest_8c.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
<a name="l00322"></a>00322 {
<a name="l00323"></a>00323         <span class="keyword">const</span> <span class="keywordtype">char</span> *zonefile_name;
<a name="l00324"></a>00324         FILE *zonefile = NULL;
<a name="l00325"></a>00325         <span class="keywordtype">int</span> line_nr = 0;
<a name="l00326"></a>00326         <span class="keywordtype">int</span> c;
<a name="l00327"></a>00327         <span class="keywordtype">int</span> argi;
<a name="l00328"></a>00328         ENGINE *engine = NULL;
<a name="l00329"></a>00329 
<a name="l00330"></a>00330         <a class="code" href="structldns__struct__zone.html" title="DNS Zone.">ldns_zone</a> *orig_zone;
<a name="l00331"></a>00331         <a class="code" href="structldns__struct__rr__list.html" title="List or Set of Resource Records.">ldns_rr_list</a> *orig_rrs = NULL;
<a name="l00332"></a>00332         <a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *orig_soa = NULL;
<a name="l00333"></a>00333         <a class="code" href="structldns__struct__dnssec__zone.html" title="Structure containing a dnssec zone.">ldns_dnssec_zone</a> *signed_zone;
<a name="l00334"></a>00334 
<a name="l00335"></a>00335         <span class="keywordtype">char</span> *keyfile_name_base;
<a name="l00336"></a>00336         <span class="keywordtype">char</span> *keyfile_name = NULL;
<a name="l00337"></a>00337         FILE *keyfile = NULL;
<a name="l00338"></a>00338         <a class="code" href="structldns__struct__key.html" title="General key structure, can contain all types of keys that are used in DNSSEC.">ldns_key</a> *key = NULL;
<a name="l00339"></a>00339         <a class="code" href="structldns__struct__key__list.html" title="Same as rr_list, but now for keys.">ldns_key_list</a> *keys;
<a name="l00340"></a>00340         <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> s;
<a name="l00341"></a>00341         <span class="keywordtype">size_t</span> i;
<a name="l00342"></a>00342         <a class="code" href="structldns__struct__rr__list.html" title="List or Set of Resource Records.">ldns_rr_list</a> *added_rrs;
<a name="l00343"></a>00343         <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> status;
<a name="l00344"></a>00344 
<a name="l00345"></a>00345         <span class="keywordtype">bool</span> leave_old_dnssec_data = <span class="keyword">false</span>;
<a name="l00346"></a>00346 
<a name="l00347"></a>00347         <span class="keywordtype">char</span> *outputfile_name = NULL;
<a name="l00348"></a>00348         FILE *outputfile;
<a name="l00349"></a>00349         
<a name="l00350"></a>00350         <span class="comment">/* tmp vars for engine keys */</span>
<a name="l00351"></a>00351         <span class="keywordtype">char</span> *eng_key_l;
<a name="l00352"></a>00352         <span class="keywordtype">size_t</span> eng_key_id_len;
<a name="l00353"></a>00353         <span class="keywordtype">char</span> *eng_key_id;
<a name="l00354"></a>00354         <span class="keywordtype">int</span> eng_key_algo;
<a name="l00355"></a>00355         
<a name="l00356"></a>00356         <span class="keywordtype">bool</span> use_nsec3 = <span class="keyword">false</span>;
<a name="l00357"></a>00357         <span class="keywordtype">int</span> signflags = 0;
<a name="l00358"></a>00358 
<a name="l00359"></a>00359         <span class="comment">/* Add the given keys to the zone if they are not yet present */</span>
<a name="l00360"></a>00360         <span class="keywordtype">bool</span> add_keys = <span class="keyword">true</span>;
<a name="l00361"></a>00361         uint8_t nsec3_algorithm = 1;
<a name="l00362"></a>00362         uint8_t nsec3_flags = 0;
<a name="l00363"></a>00363         <span class="keywordtype">size_t</span> nsec3_iterations_cmd = 1;
<a name="l00364"></a>00364         uint16_t nsec3_iterations = 1;
<a name="l00365"></a>00365         uint8_t nsec3_salt_length = 0;
<a name="l00366"></a>00366         uint8_t *nsec3_salt = NULL;
<a name="l00367"></a>00367         
<a name="l00368"></a>00368         <span class="comment">/* we need to know the origin before reading ksk&#39;s,</span>
<a name="l00369"></a>00369 <span class="comment">         * so keep an array of filenames until we know it</span>
<a name="l00370"></a>00370 <span class="comment">         */</span>
<a name="l00371"></a>00371         <span class="keyword">struct </span>tm tm;
<a name="l00372"></a>00372         uint32_t inception;
<a name="l00373"></a>00373         uint32_t expiration;
<a name="l00374"></a>00374         <a class="code" href="structldns__struct__rdf.html" title="Resource record data field.">ldns_rdf</a> *origin = NULL;
<a name="l00375"></a>00375         uint32_t ttl = <a class="code" href="ldns_8h.html#a2bdd8bfa0eb61ccf7719d5ffcd1ac79e">LDNS_DEFAULT_TTL</a>;
<a name="l00376"></a>00376         <a class="code" href="rr_8h.html#aa11e99c7e7c630e03373f2a2cafc4ee9">ldns_rr_class</a> <span class="keyword">class </span>= <a class="code" href="rr_8h.html#adc72070b39f210fae670577de8136600a2ad89c0befc939420e3b1157c07a8b46" title="the Internet">LDNS_RR_CLASS_IN</a>; 
<a name="l00377"></a>00377         
<a name="l00378"></a>00378         <span class="keywordtype">char</span> *prog = strdup(argv[0]);
<a name="l00379"></a>00379         <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> result;
<a name="l00380"></a>00380 
<a name="l00381"></a>00381         <a class="code" href="structldns__struct__output__format.html" title="Output format specifier.">ldns_output_format</a> fmt = { <a class="code" href="host2str_8c.html#ace100b58a7e8d928102c3bac613b7338" title="The default output format record.">ldns_output_format_default</a>-&gt;<a class="code" href="structldns__struct__output__format.html#aab2900137801ec209e02e79c7b61307c" title="Specification of how RR&#39;s should be formatted in text.">flags</a>, NULL };
<a name="l00382"></a>00382         <a class="code" href="structldns__rbtree__t.html" title="definition for tree struct">ldns_rbtree_t</a> **hashmap = NULL;
<a name="l00383"></a>00383 
<a name="l00384"></a>00384         
<a name="l00385"></a>00385         inception = 0;
<a name="l00386"></a>00386         expiration = 0;
<a name="l00387"></a>00387         
<a name="l00388"></a>00388         keys = <a class="code" href="keys_8c.html#a311eb372cb3180df25cdef98751adb27" title="Creates a new empty key list.">ldns_key_list_new</a>();
<a name="l00389"></a>00389 
<a name="l00390"></a>00390         OPENSSL_config(NULL);
<a name="l00391"></a>00391 
<a name="l00392"></a>00392         <span class="keywordflow">while</span> ((c = getopt(argc, argv, <span class="stringliteral">&quot;a:bde:f:i:k:lno:ps:t:vAE:K:&quot;</span>)) != -1) {
<a name="l00393"></a>00393                 <span class="keywordflow">switch</span> (c) {
<a name="l00394"></a>00394                 <span class="keywordflow">case</span> <span class="charliteral">&#39;a&#39;</span>:
<a name="l00395"></a>00395                         nsec3_algorithm = (uint8_t) atoi(optarg);
<a name="l00396"></a>00396                         <span class="keywordflow">if</span> (nsec3_algorithm != 1) {
<a name="l00397"></a>00397                                 fprintf(stderr, <span class="stringliteral">&quot;Bad NSEC3 algorithm, only RSASHA1 allowed\n&quot;</span>);
<a name="l00398"></a>00398                                 exit(EXIT_FAILURE);
<a name="l00399"></a>00399                         }
<a name="l00400"></a>00400                         <span class="keywordflow">break</span>;
<a name="l00401"></a>00401                 <span class="keywordflow">case</span> <span class="charliteral">&#39;b&#39;</span>:
<a name="l00402"></a>00402                         fmt.<a class="code" href="structldns__struct__output__format.html#aab2900137801ec209e02e79c7b61307c" title="Specification of how RR&#39;s should be formatted in text.">flags</a> |= <a class="code" href="host2str_8h.html#a570b39e63c0389a97f70d464300973af" title="Provide bubblebabble representation for DS RR&#39;s as comment.">LDNS_COMMENT_BUBBLEBABBLE</a>;
<a name="l00403"></a>00403                         fmt.<a class="code" href="structldns__struct__output__format.html#aab2900137801ec209e02e79c7b61307c" title="Specification of how RR&#39;s should be formatted in text.">flags</a> |= <a class="code" href="host2str_8h.html#a89bba5c47a912ee39f6296a9a02b71f5" title="Show when a NSEC3 RR has the optout flag set as comment.">LDNS_COMMENT_FLAGS</a>;
<a name="l00404"></a>00404                         fmt.<a class="code" href="structldns__struct__output__format.html#aab2900137801ec209e02e79c7b61307c" title="Specification of how RR&#39;s should be formatted in text.">flags</a> |= <a class="code" href="host2str_8h.html#aef83316db61cf578ee15a09c6ce9e725" title="Show the unhashed owner and next owner names for NSEC3 RR&#39;s as comment.">LDNS_COMMENT_NSEC3_CHAIN</a>;
<a name="l00405"></a>00405                         fmt.<a class="code" href="structldns__struct__output__format.html#aab2900137801ec209e02e79c7b61307c" title="Specification of how RR&#39;s should be formatted in text.">flags</a> |= <a class="code" href="host2str_8h.html#aff467c28f6eeae4b3b360c2074748f9b" title="Print mark up.">LDNS_COMMENT_LAYOUT</a>;
<a name="l00406"></a>00406                         hashmap = (<a class="code" href="structldns__rbtree__t.html" title="definition for tree struct">ldns_rbtree_t</a> **)&amp;fmt.<a class="code" href="structldns__struct__output__format.html#af053a3d978670ac4a46bf7af7243376c" title="Potential extra data to be used with formatting RR&#39;s in text.">data</a>;
<a name="l00407"></a>00407                         <span class="keywordflow">break</span>;
<a name="l00408"></a>00408                 <span class="keywordflow">case</span> <span class="charliteral">&#39;d&#39;</span>:
<a name="l00409"></a>00409                         add_keys = <span class="keyword">false</span>;
<a name="l00410"></a>00410                         <span class="keywordflow">break</span>;
<a name="l00411"></a>00411                 <span class="keywordflow">case</span> <span class="charliteral">&#39;e&#39;</span>:
<a name="l00412"></a>00412                         <span class="comment">/* try to parse YYYYMMDD first,</span>
<a name="l00413"></a>00413 <span class="comment">                         * if that doesn&#39;t work, it</span>
<a name="l00414"></a>00414 <span class="comment">                         * should be a timestamp (seconds since epoch)</span>
<a name="l00415"></a>00415 <span class="comment">                         */</span>
<a name="l00416"></a>00416                         memset(&amp;tm, 0, <span class="keyword">sizeof</span>(tm));
<a name="l00417"></a>00417 
<a name="l00418"></a>00418                         <span class="keywordflow">if</span> (strlen(optarg) == 8 &amp;&amp;
<a name="l00419"></a>00419                             sscanf(optarg, <span class="stringliteral">&quot;%4d%2d%2d&quot;</span>, &amp;tm.tm_year, &amp;tm.tm_mon, &amp;tm.tm_mday)
<a name="l00420"></a>00420                             ) {
<a name="l00421"></a>00421                                 tm.tm_year -= 1900;
<a name="l00422"></a>00422                                 tm.tm_mon--;
<a name="l00423"></a>00423                                 check_tm(tm);
<a name="l00424"></a>00424                                 expiration = (uint32_t) <a class="code" href="util_8c.html#ad4a71c049ae1e0b4849a64040a7360fa" title="Convert TM to seconds since epoch (midnight, January 1st, 1970).">mktime_from_utc</a>(&amp;tm);
<a name="l00425"></a>00425                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strlen(optarg) == 14 &amp;&amp;
<a name="l00426"></a>00426                                          sscanf(optarg, <span class="stringliteral">&quot;%4d%2d%2d%2d%2d%2d&quot;</span>, &amp;tm.tm_year, &amp;tm.tm_mon, &amp;tm.tm_mday, &amp;tm.tm_hour, &amp;tm.tm_min, &amp;tm.tm_sec)
<a name="l00427"></a>00427                                          ) {
<a name="l00428"></a>00428                                 tm.tm_year -= 1900;
<a name="l00429"></a>00429                                 tm.tm_mon--;
<a name="l00430"></a>00430                                 check_tm(tm);
<a name="l00431"></a>00431                                 expiration = (uint32_t) <a class="code" href="util_8c.html#ad4a71c049ae1e0b4849a64040a7360fa" title="Convert TM to seconds since epoch (midnight, January 1st, 1970).">mktime_from_utc</a>(&amp;tm);
<a name="l00432"></a>00432                         } <span class="keywordflow">else</span> {
<a name="l00433"></a>00433                                 expiration = (uint32_t) atol(optarg);
<a name="l00434"></a>00434                         }
<a name="l00435"></a>00435                         <span class="keywordflow">break</span>;
<a name="l00436"></a>00436                 <span class="keywordflow">case</span> <span class="charliteral">&#39;f&#39;</span>:
<a name="l00437"></a>00437                         outputfile_name = <a class="code" href="util_8h.html#aaad6949daea3c6cefd01d19300f6e21a">LDNS_XMALLOC</a>(<span class="keywordtype">char</span>, <a class="code" href="ldns-signzone_8c.html#acc9794f655f61a3246ba3fd5c9c67e14">MAX_FILENAME_LEN</a>);
<a name="l00438"></a>00438                         strncpy(outputfile_name, optarg, <a class="code" href="ldns-signzone_8c.html#acc9794f655f61a3246ba3fd5c9c67e14">MAX_FILENAME_LEN</a>);
<a name="l00439"></a>00439                         <span class="keywordflow">break</span>;
<a name="l00440"></a>00440                 <span class="keywordflow">case</span> <span class="charliteral">&#39;i&#39;</span>:
<a name="l00441"></a>00441                         memset(&amp;tm, 0, <span class="keyword">sizeof</span>(tm));
<a name="l00442"></a>00442 
<a name="l00443"></a>00443                         <span class="keywordflow">if</span> (strlen(optarg) == 8 &amp;&amp;
<a name="l00444"></a>00444                             sscanf(optarg, <span class="stringliteral">&quot;%4d%2d%2d&quot;</span>, &amp;tm.tm_year, &amp;tm.tm_mon, &amp;tm.tm_mday)
<a name="l00445"></a>00445                             ) {
<a name="l00446"></a>00446                                 tm.tm_year -= 1900;
<a name="l00447"></a>00447                                 tm.tm_mon--;
<a name="l00448"></a>00448                                 check_tm(tm);
<a name="l00449"></a>00449                                 inception = (uint32_t) <a class="code" href="util_8c.html#ad4a71c049ae1e0b4849a64040a7360fa" title="Convert TM to seconds since epoch (midnight, January 1st, 1970).">mktime_from_utc</a>(&amp;tm);
<a name="l00450"></a>00450                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strlen(optarg) == 14 &amp;&amp;
<a name="l00451"></a>00451                                          sscanf(optarg, <span class="stringliteral">&quot;%4d%2d%2d%2d%2d%2d&quot;</span>, &amp;tm.tm_year, &amp;tm.tm_mon, &amp;tm.tm_mday, &amp;tm.tm_hour, &amp;tm.tm_min, &amp;tm.tm_sec)
<a name="l00452"></a>00452                                          ) {
<a name="l00453"></a>00453                                 tm.tm_year -= 1900;
<a name="l00454"></a>00454                                 tm.tm_mon--;
<a name="l00455"></a>00455                                 check_tm(tm);
<a name="l00456"></a>00456                                 inception = (uint32_t) <a class="code" href="util_8c.html#ad4a71c049ae1e0b4849a64040a7360fa" title="Convert TM to seconds since epoch (midnight, January 1st, 1970).">mktime_from_utc</a>(&amp;tm);
<a name="l00457"></a>00457                         } <span class="keywordflow">else</span> {
<a name="l00458"></a>00458                                 inception = (uint32_t) atol(optarg);
<a name="l00459"></a>00459                         }
<a name="l00460"></a>00460                         <span class="keywordflow">break</span>;
<a name="l00461"></a>00461                 <span class="keywordflow">case</span> <span class="charliteral">&#39;l&#39;</span>:
<a name="l00462"></a>00462                         leave_old_dnssec_data = <span class="keyword">true</span>;
<a name="l00463"></a>00463                         <span class="keywordflow">break</span>;
<a name="l00464"></a>00464                 <span class="keywordflow">case</span> <span class="charliteral">&#39;n&#39;</span>:
<a name="l00465"></a>00465                         use_nsec3 = <span class="keyword">true</span>;
<a name="l00466"></a>00466                         <span class="keywordflow">break</span>;
<a name="l00467"></a>00467                 <span class="keywordflow">case</span> <span class="charliteral">&#39;o&#39;</span>:
<a name="l00468"></a>00468                         <span class="keywordflow">if</span> (<a class="code" href="str2host_8c.html#a8bf01656c7b60c305b47b1e1346749d3" title="convert a dname string into wireformat">ldns_str2rdf_dname</a>(&amp;origin, optarg) != <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) {
<a name="l00469"></a>00469                                 fprintf(stderr, <span class="stringliteral">&quot;Bad origin, not a correct domain name\n&quot;</span>);
<a name="l00470"></a>00470                                 usage(stderr, prog);
<a name="l00471"></a>00471                                 exit(EXIT_FAILURE);
<a name="l00472"></a>00472                         }
<a name="l00473"></a>00473                         <span class="keywordflow">break</span>;
<a name="l00474"></a>00474                 <span class="keywordflow">case</span> <span class="charliteral">&#39;p&#39;</span>:
<a name="l00475"></a>00475                         nsec3_flags = nsec3_flags | <a class="code" href="rdata_8h.html#aee5a8cca68de1b7296e27195bf9fdda8">LDNS_NSEC3_VARS_OPTOUT_MASK</a>;
<a name="l00476"></a>00476                         <span class="keywordflow">break</span>;
<a name="l00477"></a>00477                 <span class="keywordflow">case</span> <span class="charliteral">&#39;v&#39;</span>:
<a name="l00478"></a>00478                         printf(<span class="stringliteral">&quot;zone signer version %s (ldns version %s)\n&quot;</span>, <a class="code" href="util_8h.html#a991dc2d5a646a3f66f91ba6b62c93615">LDNS_VERSION</a>, <a class="code" href="util_8c.html#acfa02e74a31c812d2e4ecf40915b418f" title="Show the internal library version.">ldns_version</a>());
<a name="l00479"></a>00479                         exit(EXIT_SUCCESS);
<a name="l00480"></a>00480                         <span class="keywordflow">break</span>;
<a name="l00481"></a>00481                 <span class="keywordflow">case</span> <span class="charliteral">&#39;A&#39;</span>:
<a name="l00482"></a>00482                         signflags |= <a class="code" href="dnssec__sign_8h.html#a8f8735648270a4f13583624b37f935fb" title="dnssec_verify">LDNS_SIGN_DNSKEY_WITH_ZSK</a>;
<a name="l00483"></a>00483                         <span class="keywordflow">break</span>;
<a name="l00484"></a>00484                 <span class="keywordflow">case</span> <span class="charliteral">&#39;E&#39;</span>:
<a name="l00485"></a>00485                         ENGINE_load_builtin_engines();
<a name="l00486"></a>00486                         ENGINE_load_dynamic();
<a name="l00487"></a>00487                         ENGINE_load_cryptodev();
<a name="l00488"></a>00488                         engine = ENGINE_by_id(optarg);
<a name="l00489"></a>00489                         <span class="keywordflow">if</span> (!engine) {
<a name="l00490"></a>00490                                 printf(<span class="stringliteral">&quot;No such engine: %s\n&quot;</span>, optarg);
<a name="l00491"></a>00491                                 engine = ENGINE_get_first();
<a name="l00492"></a>00492                                 printf(<span class="stringliteral">&quot;Available engines:\n&quot;</span>);
<a name="l00493"></a>00493                                 <span class="keywordflow">while</span> (engine) {
<a name="l00494"></a>00494                                         printf(<span class="stringliteral">&quot;%s\n&quot;</span>, ENGINE_get_id(engine));
<a name="l00495"></a>00495                                         engine = ENGINE_get_next(engine);
<a name="l00496"></a>00496                                 }
<a name="l00497"></a>00497                                 exit(EXIT_FAILURE);
<a name="l00498"></a>00498                         } <span class="keywordflow">else</span> {
<a name="l00499"></a>00499                                 <span class="keywordflow">if</span> (!ENGINE_init(engine)) {
<a name="l00500"></a>00500                                         printf(<span class="stringliteral">&quot;The engine couldn&#39;t initialize\n&quot;</span>);
<a name="l00501"></a>00501                                         exit(EXIT_FAILURE);
<a name="l00502"></a>00502                                 }
<a name="l00503"></a>00503                                 ENGINE_set_default_RSA(engine);
<a name="l00504"></a>00504                                 ENGINE_set_default_DSA(engine);
<a name="l00505"></a>00505                                 ENGINE_set_default(engine, 0);
<a name="l00506"></a>00506                         }
<a name="l00507"></a>00507                         <span class="keywordflow">break</span>;
<a name="l00508"></a>00508                 <span class="keywordflow">case</span> <span class="charliteral">&#39;k&#39;</span>:
<a name="l00509"></a>00509                         eng_key_l = strchr(optarg, <span class="charliteral">&#39;,&#39;</span>);
<a name="l00510"></a>00510                         <span class="keywordflow">if</span> (eng_key_l &amp;&amp; strlen(eng_key_l) &gt; 1) {
<a name="l00511"></a>00511                                 <span class="keywordflow">if</span> (eng_key_l &gt; optarg) {
<a name="l00512"></a>00512                                         eng_key_id_len = (size_t) (eng_key_l - optarg);
<a name="l00513"></a>00513                                         eng_key_id = malloc(eng_key_id_len + 1);
<a name="l00514"></a>00514                                         memcpy(eng_key_id, optarg, eng_key_id_len);
<a name="l00515"></a>00515                                         eng_key_id[eng_key_id_len] = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l00516"></a>00516                                 } <span class="keywordflow">else</span> {
<a name="l00517"></a>00517                                         <span class="comment">/* no id given, use default from engine */</span>
<a name="l00518"></a>00518                                         eng_key_id = NULL;
<a name="l00519"></a>00519                                 }
<a name="l00520"></a>00520 
<a name="l00521"></a>00521                                 eng_key_algo = atoi(eng_key_l + 1);
<a name="l00522"></a>00522 
<a name="l00523"></a>00523                                 printf(<span class="stringliteral">&quot;Engine key id: %s, algo %d\n&quot;</span>, eng_key_id, eng_key_algo);
<a name="l00524"></a>00524 
<a name="l00525"></a>00525                                 <span class="keywordflow">if</span> (expiration != 0) {
<a name="l00526"></a>00526                                         <a class="code" href="keys_8c.html#a25f9483844dbd83abca56d725923c591" title="Set the key&#39;s expiration date (seconds after epoch)">ldns_key_set_expiration</a>(key, expiration);
<a name="l00527"></a>00527                                 }
<a name="l00528"></a>00528                                 <span class="keywordflow">if</span> (inception != 0) {
<a name="l00529"></a>00529                                         <a class="code" href="keys_8c.html#af1521b6b3c0e84a629d09bf237f40308" title="Set the key&#39;s inception date (seconds after epoch)">ldns_key_set_inception</a>(key, inception);
<a name="l00530"></a>00530                                 }
<a name="l00531"></a>00531 
<a name="l00532"></a>00532                                 s = <a class="code" href="keys_8c.html#ac73013d7e683e0b4d8e9a32c3036da44" title="Read the key with the given id from the given engine and store it in the given ldns_key structure...">ldns_key_new_frm_engine</a>(&amp;key, engine, eng_key_id, eng_key_algo);
<a name="l00533"></a>00533                                 <span class="keywordflow">if</span> (s == <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) {
<a name="l00534"></a>00534                                         <span class="comment">/* must be dnssec key */</span>
<a name="l00535"></a>00535                                         <span class="keywordflow">switch</span> (<a class="code" href="keys_8c.html#a906b7cc79acd016fb1f400aff16b9f1c" title="return the signing alg of the key">ldns_key_algorithm</a>(key)) {
<a name="l00536"></a>00536                                         <span class="keywordflow">case</span> <a class="code" href="keys_8h.html#aa9c34fead27309e4540a2c4cee3db664a92e7ccac219c462f054e00c8e6c8321b">LDNS_SIGN_RSAMD5</a>:
<a name="l00537"></a>00537                                         <span class="keywordflow">case</span> <a class="code" href="keys_8h.html#aa9c34fead27309e4540a2c4cee3db664a062ab8c29c8f73b28bbb552597975dbc">LDNS_SIGN_RSASHA1</a>:
<a name="l00538"></a>00538                                         <span class="keywordflow">case</span> <a class="code" href="keys_8h.html#aa9c34fead27309e4540a2c4cee3db664a7a8b2b416cc65f7637108b6ba35cad69">LDNS_SIGN_RSASHA1_NSEC3</a>:
<a name="l00539"></a>00539                                         <span class="keywordflow">case</span> <a class="code" href="keys_8h.html#aa9c34fead27309e4540a2c4cee3db664a9f88342b4f9ce95700a72154b6d30269">LDNS_SIGN_RSASHA256</a>:
<a name="l00540"></a>00540                                         <span class="keywordflow">case</span> <a class="code" href="keys_8h.html#aa9c34fead27309e4540a2c4cee3db664a93fc09210171fbecee85ed84ebfc7dbd">LDNS_SIGN_RSASHA512</a>:
<a name="l00541"></a>00541                                         <span class="keywordflow">case</span> <a class="code" href="keys_8h.html#aa9c34fead27309e4540a2c4cee3db664a98ae68498fea31062b1d03a861846aa5">LDNS_SIGN_DSA</a>:
<a name="l00542"></a>00542                                         <span class="keywordflow">case</span> <a class="code" href="keys_8h.html#aa9c34fead27309e4540a2c4cee3db664a28624a25c45025703d05de9984c4ee4a">LDNS_SIGN_DSA_NSEC3</a>:
<a name="l00543"></a>00543                                         <span class="keywordflow">case</span> <a class="code" href="keys_8h.html#aa9c34fead27309e4540a2c4cee3db664a2f5cc1330edd5c11be92509543402f98">LDNS_SIGN_ECC_GOST</a>:
<a name="l00544"></a>00544 <span class="preprocessor">#ifdef USE_ECDSA</span>
<a name="l00545"></a>00545 <span class="preprocessor"></span>                                        <span class="keywordflow">case</span> LDNS_SIGN_ECDSAP256SHA256:
<a name="l00546"></a>00546                                         <span class="keywordflow">case</span> LDNS_SIGN_ECDSAP384SHA384:
<a name="l00547"></a>00547 <span class="preprocessor">#endif</span>
<a name="l00548"></a>00548 <span class="preprocessor"></span>                                                <a class="code" href="keys_8c.html#a221251701900a1de52cfe2613a9e6e9d" title="pushes a key to a keylist">ldns_key_list_push_key</a>(keys, key);
<a name="l00549"></a>00549                                                 <span class="comment">/*printf(&quot;Added key at %p:\n&quot;, key);*/</span>
<a name="l00550"></a>00550                                                 <span class="comment">/*ldns_key_print(stdout, key);*/</span>
<a name="l00551"></a>00551                                                 <span class="keywordflow">break</span>;
<a name="l00552"></a>00552                                         <span class="keywordflow">default</span>:
<a name="l00553"></a>00553                                                 fprintf(stderr, <span class="stringliteral">&quot;Warning, key not suitable for signing, ignoring key with algorithm %u\n&quot;</span>, <a class="code" href="keys_8c.html#a906b7cc79acd016fb1f400aff16b9f1c" title="return the signing alg of the key">ldns_key_algorithm</a>(key));
<a name="l00554"></a>00554                                                 <span class="keywordflow">break</span>;
<a name="l00555"></a>00555                                         }
<a name="l00556"></a>00556                                 } <span class="keywordflow">else</span> {
<a name="l00557"></a>00557                                         printf(<span class="stringliteral">&quot;Error reading key &#39;%s&#39; from engine: %s\n&quot;</span>, eng_key_id, <a class="code" href="error_8c.html#a4005bb78082a40de485f947470fa5017" title="look up a descriptive text by each error.">ldns_get_errorstr_by_id</a>(s));
<a name="l00558"></a>00558 <span class="preprocessor">                                        #ifdef HAVE_SSL</span>
<a name="l00559"></a>00559 <span class="preprocessor"></span>                                                        <span class="keywordflow">if</span> (ERR_peek_error()) {
<a name="l00560"></a>00560                                                                 ERR_load_crypto_strings();
<a name="l00561"></a>00561                                                                 ERR_print_errors_fp(stderr);
<a name="l00562"></a>00562                                                                 ERR_free_strings();
<a name="l00563"></a>00563                                                         }
<a name="l00564"></a>00564 <span class="preprocessor">                                        #endif</span>
<a name="l00565"></a>00565 <span class="preprocessor"></span>                                        exit(EXIT_FAILURE);
<a name="l00566"></a>00566                                 }
<a name="l00567"></a>00567 
<a name="l00568"></a>00568                                 <span class="keywordflow">if</span> (eng_key_id) {
<a name="l00569"></a>00569                                         free(eng_key_id);
<a name="l00570"></a>00570                                 }
<a name="l00571"></a>00571                         } <span class="keywordflow">else</span> {
<a name="l00572"></a>00572                                 printf(<span class="stringliteral">&quot;Error: bad engine key specification (should be: -k &lt;id&gt;,&lt;algorithm&gt;)).\n&quot;</span>);
<a name="l00573"></a>00573                                 exit(EXIT_FAILURE);
<a name="l00574"></a>00574                         }
<a name="l00575"></a>00575                         <span class="keywordflow">break</span>;
<a name="l00576"></a>00576                 <span class="keywordflow">case</span> <span class="charliteral">&#39;K&#39;</span>:
<a name="l00577"></a>00577                         printf(<span class="stringliteral">&quot;Not implemented yet\n&quot;</span>);
<a name="l00578"></a>00578                         exit(EXIT_FAILURE);
<a name="l00579"></a>00579                         <span class="keywordflow">break</span>;
<a name="l00580"></a>00580                 <span class="keywordflow">case</span> <span class="charliteral">&#39;s&#39;</span>:
<a name="l00581"></a>00581                         <span class="keywordflow">if</span> (strlen(optarg) % 2 != 0) {
<a name="l00582"></a>00582                                 fprintf(stderr, <span class="stringliteral">&quot;Salt value is not valid hex data, not a multiple of 2 characters\n&quot;</span>);
<a name="l00583"></a>00583                                 exit(EXIT_FAILURE);
<a name="l00584"></a>00584                         }
<a name="l00585"></a>00585                         nsec3_salt_length = (uint8_t) strlen(optarg) / 2;
<a name="l00586"></a>00586                         nsec3_salt = <a class="code" href="util_8h.html#aaad6949daea3c6cefd01d19300f6e21a">LDNS_XMALLOC</a>(uint8_t, nsec3_salt_length);
<a name="l00587"></a>00587                         <span class="keywordflow">for</span> (c = 0; c &lt; (int) strlen(optarg); c += 2) {
<a name="l00588"></a>00588                                 <span class="keywordflow">if</span> (isxdigit((<span class="keywordtype">int</span>) optarg[c]) &amp;&amp; isxdigit((<span class="keywordtype">int</span>) optarg[c+1])) {
<a name="l00589"></a>00589                                         nsec3_salt[c/2] = (uint8_t) <a class="code" href="util_8c.html#a04593d78f06d288151bba4719704fa99" title="Returns the int value of the given (hex) digit.">ldns_hexdigit_to_int</a>(optarg[c]) * 16 +
<a name="l00590"></a>00590                                                 <a class="code" href="util_8c.html#a04593d78f06d288151bba4719704fa99" title="Returns the int value of the given (hex) digit.">ldns_hexdigit_to_int</a>(optarg[c+1]);
<a name="l00591"></a>00591                                 } <span class="keywordflow">else</span> {
<a name="l00592"></a>00592                                         fprintf(stderr, <span class="stringliteral">&quot;Salt value is not valid hex data.\n&quot;</span>);
<a name="l00593"></a>00593                                         exit(EXIT_FAILURE);
<a name="l00594"></a>00594                                 }
<a name="l00595"></a>00595                         }
<a name="l00596"></a>00596 
<a name="l00597"></a>00597                         <span class="keywordflow">break</span>;
<a name="l00598"></a>00598                 <span class="keywordflow">case</span> <span class="charliteral">&#39;t&#39;</span>:
<a name="l00599"></a>00599                         nsec3_iterations_cmd = (size_t) atol(optarg);
<a name="l00600"></a>00600                         <span class="keywordflow">if</span> (nsec3_iterations_cmd &gt; <a class="code" href="dnssec_8h.html#a375f02cd5dcc78bcfbd402be5aec085e">LDNS_NSEC3_MAX_ITERATIONS</a>) {
<a name="l00601"></a>00601                                 fprintf(stderr, <span class="stringliteral">&quot;Iterations count can not exceed %u, quitting\n&quot;</span>, <a class="code" href="dnssec_8h.html#a375f02cd5dcc78bcfbd402be5aec085e">LDNS_NSEC3_MAX_ITERATIONS</a>);
<a name="l00602"></a>00602                                 exit(EXIT_FAILURE);
<a name="l00603"></a>00603                         }
<a name="l00604"></a>00604                         nsec3_iterations = (uint16_t) nsec3_iterations_cmd;
<a name="l00605"></a>00605                         <span class="keywordflow">break</span>;
<a name="l00606"></a>00606                 <span class="keywordflow">default</span>:
<a name="l00607"></a>00607                         usage(stderr, prog);
<a name="l00608"></a>00608                         exit(EXIT_SUCCESS);
<a name="l00609"></a>00609                 }
<a name="l00610"></a>00610         }
<a name="l00611"></a>00611         
<a name="l00612"></a>00612         argc -= optind;
<a name="l00613"></a>00613         argv += optind;
<a name="l00614"></a>00614 
<a name="l00615"></a>00615         <span class="keywordflow">if</span> (argc &lt; 1) {
<a name="l00616"></a>00616                 printf(<span class="stringliteral">&quot;Error: not enough arguments\n&quot;</span>);
<a name="l00617"></a>00617                 usage(stdout, prog);
<a name="l00618"></a>00618                 exit(EXIT_FAILURE);
<a name="l00619"></a>00619         } <span class="keywordflow">else</span> {
<a name="l00620"></a>00620                 zonefile_name = argv[0];
<a name="l00621"></a>00621         }
<a name="l00622"></a>00622 
<a name="l00623"></a>00623         <span class="comment">/* read zonefile first to find origin if not specified */</span>
<a name="l00624"></a>00624         
<a name="l00625"></a>00625         <span class="keywordflow">if</span> (strncmp(zonefile_name, <span class="stringliteral">&quot;-&quot;</span>, 2) == 0) {
<a name="l00626"></a>00626                 s = <a class="code" href="zone_8c.html#accd66901157e00acd3b4b571aa7092b8">ldns_zone_new_frm_fp_l</a>(&amp;orig_zone,
<a name="l00627"></a>00627                                            stdin,
<a name="l00628"></a>00628                                            origin,
<a name="l00629"></a>00629                                            ttl,
<a name="l00630"></a>00630                                            <span class="keyword">class</span>,
<a name="l00631"></a>00631                                            &amp;line_nr);
<a name="l00632"></a>00632                         <span class="keywordflow">if</span> (s != <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) {
<a name="l00633"></a>00633                                 fprintf(stderr, <span class="stringliteral">&quot;Zone not read, error: %s at stdin line %d\n&quot;</span>, 
<a name="l00634"></a>00634                                            <a class="code" href="error_8c.html#a4005bb78082a40de485f947470fa5017" title="look up a descriptive text by each error.">ldns_get_errorstr_by_id</a>(s),
<a name="l00635"></a>00635                                            line_nr);
<a name="l00636"></a>00636                                 exit(EXIT_FAILURE);
<a name="l00637"></a>00637                         } <span class="keywordflow">else</span> {
<a name="l00638"></a>00638                                 orig_soa = <a class="code" href="zone_8c.html#aae16d59c27e1f2292f8bd87604517e0c" title="Return the soa record of a zone.">ldns_zone_soa</a>(orig_zone);
<a name="l00639"></a>00639                                 <span class="keywordflow">if</span> (!orig_soa) {
<a name="l00640"></a>00640                                         fprintf(stderr,
<a name="l00641"></a>00641                                                    <span class="stringliteral">&quot;Error reading zonefile: missing SOA record\n&quot;</span>);
<a name="l00642"></a>00642                                         exit(EXIT_FAILURE);
<a name="l00643"></a>00643                                 }
<a name="l00644"></a>00644                                 orig_rrs = <a class="code" href="zone_8c.html#a5a75b7744ea0d91770d579730a84bbf9" title="Get a list of a zone&#39;s content.">ldns_zone_rrs</a>(orig_zone);
<a name="l00645"></a>00645                                 <span class="keywordflow">if</span> (!orig_rrs) {
<a name="l00646"></a>00646                                         fprintf(stderr,
<a name="l00647"></a>00647                                                    <span class="stringliteral">&quot;Error reading zonefile: no resource records\n&quot;</span>);
<a name="l00648"></a>00648                                         exit(EXIT_FAILURE);
<a name="l00649"></a>00649                                 }
<a name="l00650"></a>00650                         }
<a name="l00651"></a>00651         } <span class="keywordflow">else</span> {
<a name="l00652"></a>00652                 zonefile = fopen(zonefile_name, <span class="stringliteral">&quot;r&quot;</span>);
<a name="l00653"></a>00653                 
<a name="l00654"></a>00654                 <span class="keywordflow">if</span> (!zonefile) {
<a name="l00655"></a>00655                         fprintf(stderr,
<a name="l00656"></a>00656                                    <span class="stringliteral">&quot;Error: unable to read %s (%s)\n&quot;</span>,
<a name="l00657"></a>00657                                    zonefile_name,
<a name="l00658"></a>00658                                    strerror(errno));
<a name="l00659"></a>00659                         exit(EXIT_FAILURE);
<a name="l00660"></a>00660                 } <span class="keywordflow">else</span> {
<a name="l00661"></a>00661                         s = <a class="code" href="zone_8c.html#accd66901157e00acd3b4b571aa7092b8">ldns_zone_new_frm_fp_l</a>(&amp;orig_zone,
<a name="l00662"></a>00662                                                    zonefile,
<a name="l00663"></a>00663                                                    origin,
<a name="l00664"></a>00664                                                    ttl,
<a name="l00665"></a>00665                                                    <span class="keyword">class</span>,
<a name="l00666"></a>00666                                                    &amp;line_nr);
<a name="l00667"></a>00667                         <span class="keywordflow">if</span> (s != <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) {
<a name="l00668"></a>00668                                 fprintf(stderr, <span class="stringliteral">&quot;Zone not read, error: %s at %s line %d\n&quot;</span>, 
<a name="l00669"></a>00669                                            <a class="code" href="error_8c.html#a4005bb78082a40de485f947470fa5017" title="look up a descriptive text by each error.">ldns_get_errorstr_by_id</a>(s), 
<a name="l00670"></a>00670                                            zonefile_name, line_nr);
<a name="l00671"></a>00671                                 exit(EXIT_FAILURE);
<a name="l00672"></a>00672                         } <span class="keywordflow">else</span> {
<a name="l00673"></a>00673                                 orig_soa = <a class="code" href="zone_8c.html#aae16d59c27e1f2292f8bd87604517e0c" title="Return the soa record of a zone.">ldns_zone_soa</a>(orig_zone);
<a name="l00674"></a>00674                                 <span class="keywordflow">if</span> (!orig_soa) {
<a name="l00675"></a>00675                                         fprintf(stderr,
<a name="l00676"></a>00676                                                    <span class="stringliteral">&quot;Error reading zonefile: missing SOA record\n&quot;</span>);
<a name="l00677"></a>00677                                         exit(EXIT_FAILURE);
<a name="l00678"></a>00678                                 }
<a name="l00679"></a>00679                                 orig_rrs = <a class="code" href="zone_8c.html#a5a75b7744ea0d91770d579730a84bbf9" title="Get a list of a zone&#39;s content.">ldns_zone_rrs</a>(orig_zone);
<a name="l00680"></a>00680                                 <span class="keywordflow">if</span> (!orig_rrs) {
<a name="l00681"></a>00681                                         fprintf(stderr,
<a name="l00682"></a>00682                                                    <span class="stringliteral">&quot;Error reading zonefile: no resource records\n&quot;</span>);
<a name="l00683"></a>00683                                         exit(EXIT_FAILURE);
<a name="l00684"></a>00684                                 }
<a name="l00685"></a>00685                         }
<a name="l00686"></a>00686                         fclose(zonefile);
<a name="l00687"></a>00687                 }
<a name="l00688"></a>00688         }
<a name="l00689"></a>00689 
<a name="l00690"></a>00690         <span class="keywordflow">if</span> (!origin) {
<a name="l00691"></a>00691                 origin = <a class="code" href="rr_8c.html#a1d254bd0deb5d18e34d84ebc10496c5d" title="returns the owner name of an rr structure.">ldns_rr_owner</a>(orig_soa);
<a name="l00692"></a>00692         }
<a name="l00693"></a>00693         
<a name="l00694"></a>00694         <span class="comment">/* read the ZSKs */</span>
<a name="l00695"></a>00695         argi = 1;
<a name="l00696"></a>00696         <span class="keywordflow">while</span> (argi &lt; argc) {
<a name="l00697"></a>00697                 keyfile_name_base = argv[argi];
<a name="l00698"></a>00698                 keyfile_name = <a class="code" href="util_8h.html#aaad6949daea3c6cefd01d19300f6e21a">LDNS_XMALLOC</a>(<span class="keywordtype">char</span>, strlen(keyfile_name_base) + 9);
<a name="l00699"></a>00699                 <a class="code" href="config_8h.html#acc2509f3dc1aeb186437c3fd8412e69a">snprintf</a>(keyfile_name,
<a name="l00700"></a>00700                             strlen(keyfile_name_base) + 9,
<a name="l00701"></a>00701                             <span class="stringliteral">&quot;%s.private&quot;</span>,
<a name="l00702"></a>00702                             keyfile_name_base);
<a name="l00703"></a>00703                 keyfile = fopen(keyfile_name, <span class="stringliteral">&quot;r&quot;</span>);
<a name="l00704"></a>00704                 line_nr = 0;
<a name="l00705"></a>00705                 <span class="keywordflow">if</span> (!keyfile) {
<a name="l00706"></a>00706                         fprintf(stderr,
<a name="l00707"></a>00707                                    <span class="stringliteral">&quot;Error: unable to read %s: %s\n&quot;</span>,
<a name="l00708"></a>00708                                    keyfile_name,
<a name="l00709"></a>00709                                    strerror(errno));
<a name="l00710"></a>00710                 } <span class="keywordflow">else</span> {
<a name="l00711"></a>00711                         s = <a class="code" href="keys_8c.html#a0197f9dd65bae3a3cb408c19683d3db8" title="Creates a new private key based on the contents of the file pointed by fp.">ldns_key_new_frm_fp_l</a>(&amp;key, keyfile, &amp;line_nr);
<a name="l00712"></a>00712                         fclose(keyfile);
<a name="l00713"></a>00713                         <span class="keywordflow">if</span> (s == <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) {
<a name="l00714"></a>00714                                 <span class="comment">/* set times in key? they will end up</span>
<a name="l00715"></a>00715 <span class="comment">                                   in the rrsigs</span>
<a name="l00716"></a>00716 <span class="comment">                                */</span>
<a name="l00717"></a>00717                                 <span class="keywordflow">if</span> (expiration != 0) {
<a name="l00718"></a>00718                                         <a class="code" href="keys_8c.html#a25f9483844dbd83abca56d725923c591" title="Set the key&#39;s expiration date (seconds after epoch)">ldns_key_set_expiration</a>(key, expiration);
<a name="l00719"></a>00719                                 }
<a name="l00720"></a>00720                                 <span class="keywordflow">if</span> (inception != 0) {
<a name="l00721"></a>00721                                         <a class="code" href="keys_8c.html#af1521b6b3c0e84a629d09bf237f40308" title="Set the key&#39;s inception date (seconds after epoch)">ldns_key_set_inception</a>(key, inception);
<a name="l00722"></a>00722                                 }
<a name="l00723"></a>00723 
<a name="l00724"></a>00724                                 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(keyfile_name);
<a name="l00725"></a>00725                                 
<a name="l00726"></a>00726                                 <a class="code" href="keys_8c.html#a221251701900a1de52cfe2613a9e6e9d" title="pushes a key to a keylist">ldns_key_list_push_key</a>(keys, key);
<a name="l00727"></a>00727                         } <span class="keywordflow">else</span> {
<a name="l00728"></a>00728                                 fprintf(stderr, <span class="stringliteral">&quot;Error reading key from %s at line %d: %s\n&quot;</span>, argv[argi], line_nr, <a class="code" href="error_8c.html#a4005bb78082a40de485f947470fa5017" title="look up a descriptive text by each error.">ldns_get_errorstr_by_id</a>(s));
<a name="l00729"></a>00729                         }
<a name="l00730"></a>00730                 }
<a name="l00731"></a>00731                 <span class="comment">/* and, if not unset by -p, find or create the corresponding DNSKEY record */</span>
<a name="l00732"></a>00732                 <span class="keywordflow">if</span> (key) {
<a name="l00733"></a>00733                         status = find_or_create_pubkey(keyfile_name_base,
<a name="l00734"></a>00734                                                        key, orig_zone,
<a name="l00735"></a>00735                                                        add_keys, ttl);
<a name="l00736"></a>00736                 }
<a name="l00737"></a>00737                 argi++;
<a name="l00738"></a>00738         }
<a name="l00739"></a>00739         
<a name="l00740"></a>00740         <span class="keywordflow">if</span> (<a class="code" href="keys_8c.html#ae89bbcf27c4ff67cda1369b583dec02f" title="returns the number of keys in the key list">ldns_key_list_key_count</a>(keys) &lt; 1) {
<a name="l00741"></a>00741                 fprintf(stderr, <span class="stringliteral">&quot;Error: no keys to sign with. Aborting.\n\n&quot;</span>);
<a name="l00742"></a>00742                 usage(stderr, prog);
<a name="l00743"></a>00743                 exit(EXIT_FAILURE);
<a name="l00744"></a>00744         }
<a name="l00745"></a>00745 
<a name="l00746"></a>00746         signed_zone = <a class="code" href="dnssec__zone_8c.html#a980d3d3a4c36b3cab999f85d1d312ee4" title="Creates a new dnssec_zone structure.">ldns_dnssec_zone_new</a>();
<a name="l00747"></a>00747         <span class="keywordflow">if</span> (<a class="code" href="dnssec__zone_8c.html#a82eddabbee6ef7441a8c3d723c23bdc2" title="Adds the given RR to the zone.">ldns_dnssec_zone_add_rr</a>(signed_zone, <a class="code" href="zone_8c.html#aae16d59c27e1f2292f8bd87604517e0c" title="Return the soa record of a zone.">ldns_zone_soa</a>(orig_zone)) !=
<a name="l00748"></a>00748             <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) {
<a name="l00749"></a>00749                 fprintf(stderr,
<a name="l00750"></a>00750                   <span class="stringliteral">&quot;Error adding SOA to dnssec zone, skipping record\n&quot;</span>);
<a name="l00751"></a>00751         }
<a name="l00752"></a>00752         
<a name="l00753"></a>00753         <span class="keywordflow">for</span> (i = 0;
<a name="l00754"></a>00754              i &lt; <a class="code" href="rr_8c.html#a7ac3192fe79ba66e47579bb2b267ce05" title="returns the number of rr&#39;s in an rr_list.">ldns_rr_list_rr_count</a>(<a class="code" href="zone_8c.html#a5a75b7744ea0d91770d579730a84bbf9" title="Get a list of a zone&#39;s content.">ldns_zone_rrs</a>(orig_zone));
<a name="l00755"></a>00755              i++) {
<a name="l00756"></a>00756                 <span class="keywordflow">if</span> (<a class="code" href="dnssec__zone_8c.html#a82eddabbee6ef7441a8c3d723c23bdc2" title="Adds the given RR to the zone.">ldns_dnssec_zone_add_rr</a>(signed_zone, 
<a name="l00757"></a>00757                          <a class="code" href="rr_8c.html#a07b1ccea9f2694b8b88904c543e16783" title="returns a specific rr of an rrlist.">ldns_rr_list_rr</a>(<a class="code" href="zone_8c.html#a5a75b7744ea0d91770d579730a84bbf9" title="Get a list of a zone&#39;s content.">ldns_zone_rrs</a>(orig_zone), 
<a name="l00758"></a>00758                          i)) !=
<a name="l00759"></a>00759                     <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) {
<a name="l00760"></a>00760                         fprintf(stderr,
<a name="l00761"></a>00761                                 <span class="stringliteral">&quot;Error adding RR to dnssec zone&quot;</span>);
<a name="l00762"></a>00762                         fprintf(stderr, <span class="stringliteral">&quot;, skipping record:\n&quot;</span>);
<a name="l00763"></a>00763                         <a class="code" href="host2str_8c.html#a87a151b267dc6acf6feaaa048d943cb8" title="Prints the data in the resource record to the given file stream (in presentation format)">ldns_rr_print</a>(stderr, 
<a name="l00764"></a>00764                           <a class="code" href="rr_8c.html#a07b1ccea9f2694b8b88904c543e16783" title="returns a specific rr of an rrlist.">ldns_rr_list_rr</a>(<a class="code" href="zone_8c.html#a5a75b7744ea0d91770d579730a84bbf9" title="Get a list of a zone&#39;s content.">ldns_zone_rrs</a>(orig_zone), i));
<a name="l00765"></a>00765                 }
<a name="l00766"></a>00766         }
<a name="l00767"></a>00767 
<a name="l00768"></a>00768         <span class="comment">/* list to store newly created rrs, so we can free them later */</span>
<a name="l00769"></a>00769         added_rrs = <a class="code" href="rr_8c.html#aa7405c3451df02516f62f6197ff06268" title="creates a new rr_list structure.">ldns_rr_list_new</a>();
<a name="l00770"></a>00770 
<a name="l00771"></a>00771         <span class="keywordflow">if</span> (use_nsec3) {
<a name="l00772"></a>00772                 result = <a class="code" href="dnssec__sign_8c.html#aa332464b3fd3d57c68a75fdc8e9b8c69" title="signs the given zone with the given new zone, with NSEC3">ldns_dnssec_zone_sign_nsec3_flg_mkmap</a>(signed_zone,
<a name="l00773"></a>00773                         added_rrs,
<a name="l00774"></a>00774                         keys,
<a name="l00775"></a>00775                         <a class="code" href="dnssec_8c.html#aa20001e7098d4be9f24baf56a8761410" title="Default callback function to always leave present signatures, and add new ones.">ldns_dnssec_default_replace_signatures</a>,
<a name="l00776"></a>00776                         NULL,
<a name="l00777"></a>00777                         nsec3_algorithm,
<a name="l00778"></a>00778                         nsec3_flags,
<a name="l00779"></a>00779                         nsec3_iterations,
<a name="l00780"></a>00780                         nsec3_salt_length,
<a name="l00781"></a>00781                         nsec3_salt,
<a name="l00782"></a>00782                         signflags,
<a name="l00783"></a>00783                         hashmap);
<a name="l00784"></a>00784         } <span class="keywordflow">else</span> {
<a name="l00785"></a>00785                 result = <a class="code" href="dnssec__sign_8c.html#abba5342158af42e5a15d5623bdf684c5" title="signs the given zone with the given keys">ldns_dnssec_zone_sign_flg</a>(signed_zone,
<a name="l00786"></a>00786                                 added_rrs,
<a name="l00787"></a>00787                                 keys,
<a name="l00788"></a>00788                                 <a class="code" href="dnssec_8c.html#aa20001e7098d4be9f24baf56a8761410" title="Default callback function to always leave present signatures, and add new ones.">ldns_dnssec_default_replace_signatures</a>,
<a name="l00789"></a>00789                                 NULL,
<a name="l00790"></a>00790                                 signflags);
<a name="l00791"></a>00791         }
<a name="l00792"></a>00792         <span class="keywordflow">if</span> (result != <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) {
<a name="l00793"></a>00793                 fprintf(stderr, <span class="stringliteral">&quot;Error signing zone: %s\n&quot;</span>,
<a name="l00794"></a>00794                            <a class="code" href="error_8c.html#a4005bb78082a40de485f947470fa5017" title="look up a descriptive text by each error.">ldns_get_errorstr_by_id</a>(result));
<a name="l00795"></a>00795         }
<a name="l00796"></a>00796 
<a name="l00797"></a>00797         <span class="keywordflow">if</span> (!outputfile_name) {
<a name="l00798"></a>00798                 outputfile_name = <a class="code" href="util_8h.html#aaad6949daea3c6cefd01d19300f6e21a">LDNS_XMALLOC</a>(<span class="keywordtype">char</span>, <a class="code" href="ldns-signzone_8c.html#acc9794f655f61a3246ba3fd5c9c67e14">MAX_FILENAME_LEN</a>);
<a name="l00799"></a>00799                 <a class="code" href="config_8h.html#acc2509f3dc1aeb186437c3fd8412e69a">snprintf</a>(outputfile_name, <a class="code" href="ldns-signzone_8c.html#acc9794f655f61a3246ba3fd5c9c67e14">MAX_FILENAME_LEN</a>, <span class="stringliteral">&quot;%s.signed&quot;</span>, zonefile_name);
<a name="l00800"></a>00800         }
<a name="l00801"></a>00801 
<a name="l00802"></a>00802         <span class="keywordflow">if</span> (signed_zone) {
<a name="l00803"></a>00803                 <span class="keywordflow">if</span> (strncmp(outputfile_name, <span class="stringliteral">&quot;-&quot;</span>, 2) == 0) {
<a name="l00804"></a>00804                         <a class="code" href="dnssec__zone_8c.html#ab02961fe68ca3a1598343eb6152e87fd" title="Prints the complete zone to the given file descriptor.">ldns_dnssec_zone_print</a>(stdout, signed_zone);
<a name="l00805"></a>00805                 } <span class="keywordflow">else</span> {
<a name="l00806"></a>00806                         outputfile = fopen(outputfile_name, <span class="stringliteral">&quot;w&quot;</span>);
<a name="l00807"></a>00807                         <span class="keywordflow">if</span> (!outputfile) {
<a name="l00808"></a>00808                                 fprintf(stderr, <span class="stringliteral">&quot;Unable to open %s for writing: %s\n&quot;</span>,
<a name="l00809"></a>00809                                            outputfile_name, strerror(errno));
<a name="l00810"></a>00810                         } <span class="keywordflow">else</span> {
<a name="l00811"></a>00811                                 <a class="code" href="dnssec__zone_8c.html#a9ad716324c7a4badf21dd1c18219c5f8" title="Prints the complete zone to the given file descriptor.">ldns_dnssec_zone_print_fmt</a>(
<a name="l00812"></a>00812                                                 outputfile, &amp;fmt, signed_zone);
<a name="l00813"></a>00813                                 fclose(outputfile);
<a name="l00814"></a>00814                         }
<a name="l00815"></a>00815                 }
<a name="l00816"></a>00816         } <span class="keywordflow">else</span> {
<a name="l00817"></a>00817                 fprintf(stderr, <span class="stringliteral">&quot;Error signing zone.\n&quot;</span>);
<a name="l00818"></a>00818 
<a name="l00819"></a>00819 <span class="preprocessor">#ifdef HAVE_SSL</span>
<a name="l00820"></a>00820 <span class="preprocessor"></span>                <span class="keywordflow">if</span> (ERR_peek_error()) {
<a name="l00821"></a>00821                         ERR_load_crypto_strings();
<a name="l00822"></a>00822                         ERR_print_errors_fp(stderr);
<a name="l00823"></a>00823                         ERR_free_strings();
<a name="l00824"></a>00824                 }
<a name="l00825"></a>00825 <span class="preprocessor">#endif</span>
<a name="l00826"></a>00826 <span class="preprocessor"></span>                exit(EXIT_FAILURE);
<a name="l00827"></a>00827         }
<a name="l00828"></a>00828         
<a name="l00829"></a>00829         <a class="code" href="keys_8c.html#a11dd420fbf4a79250f1261754fbd139e" title="Frees a key list structure.">ldns_key_list_free</a>(keys);
<a name="l00830"></a>00830         <span class="comment">/* since the ldns_rr records are pointed to in both the ldns_zone</span>
<a name="l00831"></a>00831 <span class="comment">         * and the ldns_dnssec_zone, we can either deep_free the</span>
<a name="l00832"></a>00832 <span class="comment">         * dnssec_zone and &#39;shallow&#39; free the original zone and added</span>
<a name="l00833"></a>00833 <span class="comment">         * records, or the other way around</span>
<a name="l00834"></a>00834 <span class="comment">         */</span>
<a name="l00835"></a>00835         <a class="code" href="dnssec__zone_8c.html#a9ff1744a3e694570150698880ede6e42" title="Frees the given zone structure, and its rbtree of dnssec_names Individual ldns_rr RRs within those na...">ldns_dnssec_zone_free</a>(signed_zone);
<a name="l00836"></a>00836         <a class="code" href="zone_8c.html#a84e80b82e10bbc6939ecdfd556674c1a" title="Frees the allocated memory for the zone, the soa rr in it, and the rr_list structure in it...">ldns_zone_deep_free</a>(orig_zone);
<a name="l00837"></a>00837         <a class="code" href="rr_8c.html#a25181bd133a53f132abce4eefd8e33af" title="frees an rr_list structure and all rrs contained therein.">ldns_rr_list_deep_free</a>(added_rrs);
<a name="l00838"></a>00838         
<a name="l00839"></a>00839         <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(outputfile_name);
<a name="l00840"></a>00840         
<a name="l00841"></a>00841         CRYPTO_cleanup_all_ex_data();
<a name="l00842"></a>00842 
<a name="l00843"></a>00843         free(prog);
<a name="l00844"></a>00844         exit(EXIT_SUCCESS);
<a name="l00845"></a>00845 }
<a name="l00846"></a>00846 <span class="preprocessor">#else</span>
<a name="l00847"></a>00847 <span class="preprocessor"></span><span class="keywordtype">int</span>
<a name="l00848"></a>00848 <a class="code" href="linktest_8c.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
<a name="l00849"></a>00849 {
<a name="l00850"></a>00850         fprintf(stderr, <span class="stringliteral">&quot;ldns-signzone needs OpenSSL support, which has not been compiled in\n&quot;</span>);
<a name="l00851"></a>00851         <span class="keywordflow">return</span> 1;
<a name="l00852"></a>00852 }
<a name="l00853"></a>00853 <span class="preprocessor">#endif </span><span class="comment">/* HAVE_SSL */</span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Jan 11 2012 for ldns by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>