1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>WiredTiger: ex_encrypt.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="wiredtiger.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><a href="http://wiredtiger.com/"><img alt="Logo" src="LogoFinal-header.png" alt="WiredTiger" /></a></td>
<td style="padding-left: 0.5em;">
<div id="projectname">
 <span id="projectnumber">Version 3.2.1</span>
</div>
<div id="projectbrief"><!-- 3.2.1 --></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="banner">
<a href="https://github.com/wiredtiger/wiredtiger">Fork me on GitHub</a>
<a class="last" href="http://groups.google.com/group/wiredtiger-users">Join my user group</a>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',false,false,'search.php','Search');
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('ex_encrypt_8c-example.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">ex_encrypt.c</div> </div>
</div><!--header-->
<div class="contents">
<p>Shows how to extend WiredTiger with a simple encryption algorithm.</p>
<div class="fragment"><div class="line"><span class="comment">/*-</span></div><div class="line"><span class="comment"> * Public Domain 2014-2019 MongoDB, Inc.</span></div><div class="line"><span class="comment"> * Public Domain 2008-2014 WiredTiger, Inc.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This is free and unencumbered software released into the public domain.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Anyone is free to copy, modify, publish, use, compile, sell, or</span></div><div class="line"><span class="comment"> * distribute this software, either in source code form or as a compiled</span></div><div class="line"><span class="comment"> * binary, for any purpose, commercial or non-commercial, and by any</span></div><div class="line"><span class="comment"> * means.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * In jurisdictions that recognize copyright laws, the author or authors</span></div><div class="line"><span class="comment"> * of this software dedicate any and all copyright interest in the</span></div><div class="line"><span class="comment"> * software to the public domain. We make this dedication for the benefit</span></div><div class="line"><span class="comment"> * of the public at large and to the detriment of our heirs and</span></div><div class="line"><span class="comment"> * successors. We intend this dedication to be an overt act of</span></div><div class="line"><span class="comment"> * relinquishment in perpetuity of all present and future rights to this</span></div><div class="line"><span class="comment"> * software under copyright law.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,</span></div><div class="line"><span class="comment"> * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF</span></div><div class="line"><span class="comment"> * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.</span></div><div class="line"><span class="comment"> * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR</span></div><div class="line"><span class="comment"> * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,</span></div><div class="line"><span class="comment"> * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR</span></div><div class="line"><span class="comment"> * OTHER DEALINGS IN THE SOFTWARE.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * ex_encrypt.c</span></div><div class="line"><span class="comment"> * demonstrates how to use the encryption API.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="preprocessor">#include <test_util.h></span></div><div class="line"></div><div class="line"><span class="preprocessor">#ifdef _WIN32</span></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Explicitly export this function so it is visible when loading extensions.</span></div><div class="line"><span class="comment"> */</span></div><div class="line">__declspec(dllexport)</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"> <span class="keywordtype">int</span> add_my_encryptors(<a name="_a0"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html">WT_CONNECTION</a> *connection);</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *home;</div><div class="line"></div><div class="line"><span class="preprocessor">#define SYS_KEYID "system"</span></div><div class="line"><span class="preprocessor">#define SYS_PW "system_password"</span></div><div class="line"><span class="preprocessor">#define USER1_KEYID "user1"</span></div><div class="line"><span class="preprocessor">#define USER2_KEYID "user2"</span></div><div class="line"><span class="preprocessor">#define USERBAD_KEYID "userbad"</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define ITEM_MATCHES(config_item, s) \</span></div><div class="line"><span class="preprocessor"> (strlen(s) == (config_item).len && strncmp((config_item).str, s, (config_item).len) == 0)</span></div><div class="line"></div><div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div><div class="line"> <a name="_a1"></a><a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> encryptor; <span class="comment">/* Must come first */</span></div><div class="line"> <span class="keywordtype">int</span> rot_N; <span class="comment">/* rotN value */</span></div><div class="line"> uint32_t num_calls; <span class="comment">/* Count of calls */</span></div><div class="line"> <span class="keywordtype">char</span> *keyid; <span class="comment">/* Saved keyid */</span></div><div class="line"> <span class="keywordtype">char</span> *password; <span class="comment">/* Saved password */</span></div><div class="line">} MY_CRYPTO;</div><div class="line"></div><div class="line"><span class="preprocessor">#define CHKSUM_LEN 4</span></div><div class="line"><span class="preprocessor">#define IV_LEN 16</span></div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * make_checksum --</span></div><div class="line"><span class="comment"> * This is where one would call a checksum function on the encrypted buffer. Here we just put a</span></div><div class="line"><span class="comment"> * constant value in it.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">make_checksum(uint8_t *dst)</div><div class="line">{</div><div class="line"> <span class="keywordtype">int</span> i;</div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Assume array is big enough for the checksum.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> <span class="keywordflow">for</span> (i = 0; i < CHKSUM_LEN; i++)</div><div class="line"> dst[i] = <span class="charliteral">'C'</span>;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * make_iv --</span></div><div class="line"><span class="comment"> * This is where one would generate the initialization vector. Here we just put a constant value</span></div><div class="line"><span class="comment"> * in it.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">make_iv(uint8_t *dst)</div><div class="line">{</div><div class="line"> <span class="keywordtype">int</span> i;</div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Assume array is big enough for the initialization vector.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> <span class="keywordflow">for</span> (i = 0; i < IV_LEN; i++)</div><div class="line"> dst[i] = <span class="charliteral">'I'</span>;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Rotate encryption functions.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * do_rotate --</span></div><div class="line"><span class="comment"> * Perform rot-N on the buffer given.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">do_rotate(<span class="keywordtype">char</span> *buf, <span class="keywordtype">size_t</span> len, <span class="keywordtype">int</span> rotn)</div><div class="line">{</div><div class="line"> uint32_t i;</div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Now rotate</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> <span class="keywordflow">for</span> (i = 0; i < len; i++)</div><div class="line"> <span class="keywordflow">if</span> (isalpha((<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>)buf[i])) {</div><div class="line"> <span class="keywordflow">if</span> (islower((<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>)buf[i]))</div><div class="line"> buf[i] = ((buf[i] - <span class="charliteral">'a'</span>) + rotn) % 26 + <span class="charliteral">'a'</span>;</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> buf[i] = ((buf[i] - <span class="charliteral">'A'</span>) + rotn) % 26 + <span class="charliteral">'A'</span>;</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * rotate_decrypt --</span></div><div class="line"><span class="comment"> * A simple rotate decryption.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">rotate_decrypt(<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *encryptor, <a name="_a2"></a><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, uint8_t *src, <span class="keywordtype">size_t</span> src_len,</div><div class="line"> uint8_t *dst, <span class="keywordtype">size_t</span> dst_len, <span class="keywordtype">size_t</span> *result_lenp)</div><div class="line">{</div><div class="line"> MY_CRYPTO *my_crypto = (MY_CRYPTO *)encryptor;</div><div class="line"> <span class="keywordtype">size_t</span> mylen;</div><div class="line"> uint32_t i;</div><div class="line"></div><div class="line"> (void)session; <span class="comment">/* Unused */</span></div><div class="line"> ++my_crypto->num_calls;</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (src == NULL)</div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Make sure it is big enough.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> mylen = src_len - (CHKSUM_LEN + IV_LEN);</div><div class="line"> <span class="keywordflow">if</span> (dst_len < mylen) {</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Rotate: ENOMEM ERROR: dst_len %zu src_len %zu\n"</span>, dst_len, src_len);</div><div class="line"> <span class="keywordflow">return</span> (ENOMEM);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * !!! Most implementations would verify any needed</span></div><div class="line"><span class="comment"> * checksum and initialize the IV here.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Copy the encrypted data to the destination buffer and then decrypt the destination buffer in</span></div><div class="line"><span class="comment"> * place.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> i = CHKSUM_LEN + IV_LEN;</div><div class="line"> memcpy(&dst[0], &src[i], mylen);</div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Call common rotate function on the text portion of the buffer. Send in dst_len as the length</span></div><div class="line"><span class="comment"> * of the text.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * !!! Most implementations would need the IV too.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> do_rotate((<span class="keywordtype">char</span> *)dst, mylen, 26 - my_crypto->rot_N);</div><div class="line"> *result_lenp = mylen;</div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * rotate_encrypt --</span></div><div class="line"><span class="comment"> * A simple rotate encryption.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">rotate_encrypt(<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *encryptor, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, uint8_t *src, <span class="keywordtype">size_t</span> src_len,</div><div class="line"> uint8_t *dst, <span class="keywordtype">size_t</span> dst_len, <span class="keywordtype">size_t</span> *result_lenp)</div><div class="line">{</div><div class="line"> MY_CRYPTO *my_crypto = (MY_CRYPTO *)encryptor;</div><div class="line"> uint32_t i;</div><div class="line"></div><div class="line"> (void)session; <span class="comment">/* Unused */</span></div><div class="line"> ++my_crypto->num_calls;</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (src == NULL)</div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line"> <span class="keywordflow">if</span> (dst_len < src_len + CHKSUM_LEN + IV_LEN)</div><div class="line"> <span class="keywordflow">return</span> (ENOMEM);</div><div class="line"></div><div class="line"> i = CHKSUM_LEN + IV_LEN;</div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Skip over space reserved for checksum and initialization vector. Copy text into destination</span></div><div class="line"><span class="comment"> * buffer then encrypt in place.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> memcpy(&dst[i], &src[0], src_len);</div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Call common rotate function on the text portion of the destination buffer. Send in src_len as</span></div><div class="line"><span class="comment"> * the length of the text.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> do_rotate((<span class="keywordtype">char</span> *)dst + i, src_len, my_crypto->rot_N);</div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Checksum the encrypted buffer and add the IV.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> i = 0;</div><div class="line"> make_checksum(&dst[i]);</div><div class="line"> i += CHKSUM_LEN;</div><div class="line"> make_iv(&dst[i]);</div><div class="line"> *result_lenp = dst_len;</div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * rotate_sizing --</span></div><div class="line"><span class="comment"> * A sizing example that returns the header size needed.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">rotate_sizing(<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *encryptor, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, <span class="keywordtype">size_t</span> *expansion_constantp)</div><div class="line">{</div><div class="line"> MY_CRYPTO *my_crypto = (MY_CRYPTO *)encryptor;</div><div class="line"></div><div class="line"> (void)session; <span class="comment">/* Unused parameters */</span></div><div class="line"></div><div class="line"> ++my_crypto->num_calls; <span class="comment">/* Call count */</span></div><div class="line"></div><div class="line"> *expansion_constantp = CHKSUM_LEN + IV_LEN;</div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * rotate_customize --</span></div><div class="line"><span class="comment"> * The customize function creates a customized encryptor</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">rotate_customize(<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *encryptor, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, <a class="code" href="group__wt__ext.html#ga6fa5797cf581d18dc843e07333a497e4">WT_CONFIG_ARG</a> *encrypt_config,</div><div class="line"> <a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> **customp)</div><div class="line">{</div><div class="line"> MY_CRYPTO *my_crypto;</div><div class="line"> <a name="_a3"></a><a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html">WT_CONFIG_ITEM</a> keyid, secret;</div><div class="line"> <a name="_a4"></a><a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html">WT_EXTENSION_API</a> *extapi;</div><div class="line"> <span class="keywordtype">int</span> ret;</div><div class="line"> <span class="keyword">const</span> MY_CRYPTO *orig_crypto;</div><div class="line"></div><div class="line"> extapi = session-><a name="a5"></a><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#a28a33717c138b4c481019947e230f8f6">connection</a>-><a name="a6"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#a99df5b3a17564eb5b3e4ec076590133d">get_extension_api</a>(session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#a28a33717c138b4c481019947e230f8f6">connection</a>);</div><div class="line"></div><div class="line"> orig_crypto = (<span class="keyword">const</span> MY_CRYPTO *)encryptor;</div><div class="line"> <span class="keywordflow">if</span> ((my_crypto = calloc(1, <span class="keyword">sizeof</span>(MY_CRYPTO))) == NULL) {</div><div class="line"> ret = errno;</div><div class="line"> <span class="keywordflow">goto</span> err;</div><div class="line"> }</div><div class="line"> *my_crypto = *orig_crypto;</div><div class="line"> my_crypto->keyid = my_crypto->password = NULL;</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Stash the keyid and the (optional) secret key from the configuration string.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> error_check(extapi-><a name="a7"></a><a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a0d3aae2ceac28f7b45188bcfa4306d45">config_get</a>(extapi, session, encrypt_config, <span class="stringliteral">"keyid"</span>, &keyid));</div><div class="line"> <span class="keywordflow">if</span> (keyid.<a name="a8"></a><a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a> != 0) {</div><div class="line"> <span class="keywordflow">if</span> ((my_crypto->keyid = malloc(keyid.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a> + 1)) == NULL) {</div><div class="line"> ret = errno;</div><div class="line"> <span class="keywordflow">goto</span> err;</div><div class="line"> }</div><div class="line"> strncpy(my_crypto->keyid, keyid.<a name="a9"></a><a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#aa0ce7d30a32600e16824966c638ee45f">str</a>, keyid.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a> + 1);</div><div class="line"> my_crypto->keyid[keyid.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a>] = <span class="charliteral">'\0'</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> ret = extapi-><a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a0d3aae2ceac28f7b45188bcfa4306d45">config_get</a>(extapi, session, encrypt_config, <span class="stringliteral">"secretkey"</span>, &secret);</div><div class="line"> <span class="keywordflow">if</span> (ret == 0 && secret.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a> != 0) {</div><div class="line"> <span class="keywordflow">if</span> ((my_crypto->password = malloc(secret.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a> + 1)) == NULL) {</div><div class="line"> ret = errno;</div><div class="line"> <span class="keywordflow">goto</span> err;</div><div class="line"> }</div><div class="line"> strncpy(my_crypto->password, secret.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#aa0ce7d30a32600e16824966c638ee45f">str</a>, secret.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a> + 1);</div><div class="line"> my_crypto->password[secret.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a>] = <span class="charliteral">'\0'</span>;</div><div class="line"> }</div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Presumably we'd have some sophisticated key management here that maps the id onto a secret</span></div><div class="line"><span class="comment"> * key.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> <span class="keywordflow">if</span> (ITEM_MATCHES(keyid, <span class="stringliteral">"system"</span>)) {</div><div class="line"> <span class="keywordflow">if</span> (my_crypto->password == NULL || strcmp(my_crypto->password, SYS_PW) != 0) {</div><div class="line"> ret = EPERM;</div><div class="line"> <span class="keywordflow">goto</span> err;</div><div class="line"> }</div><div class="line"> my_crypto->rot_N = 13;</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ITEM_MATCHES(keyid, USER1_KEYID))</div><div class="line"> my_crypto->rot_N = 4;</div><div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ITEM_MATCHES(keyid, USER2_KEYID))</div><div class="line"> my_crypto->rot_N = 19;</div><div class="line"> <span class="keywordflow">else</span> {</div><div class="line"> ret = EINVAL;</div><div class="line"> <span class="keywordflow">goto</span> err;</div><div class="line"> }</div><div class="line"></div><div class="line"> ++my_crypto->num_calls; <span class="comment">/* Call count */</span></div><div class="line"></div><div class="line"> *customp = (<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *)my_crypto;</div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line"></div><div class="line">err:</div><div class="line"> free(my_crypto->keyid);</div><div class="line"> free(my_crypto->password);</div><div class="line"> free(my_crypto);</div><div class="line"> <span class="keywordflow">return</span> (ret);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * rotate_terminate --</span></div><div class="line"><span class="comment"> * WiredTiger rotate encryption termination.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">rotate_terminate(<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *encryptor, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session)</div><div class="line">{</div><div class="line"> MY_CRYPTO *my_crypto = (MY_CRYPTO *)encryptor;</div><div class="line"></div><div class="line"> (void)session; <span class="comment">/* Unused parameters */</span></div><div class="line"></div><div class="line"> ++my_crypto->num_calls; <span class="comment">/* Call count */</span></div><div class="line"></div><div class="line"> <span class="comment">/* Free the allocated memory. */</span></div><div class="line"> free(my_crypto->password);</div><div class="line"> my_crypto->password = NULL;</div><div class="line"></div><div class="line"> free(my_crypto->keyid);</div><div class="line"> my_crypto->keyid = NULL;</div><div class="line"></div><div class="line"> free(encryptor);</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * add_my_encryptors --</span></div><div class="line"><span class="comment"> * A simple example of adding encryption callbacks.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keywordtype">int</span></div><div class="line">add_my_encryptors(<a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html">WT_CONNECTION</a> *connection)</div><div class="line">{</div><div class="line"> MY_CRYPTO *m;</div><div class="line"> <a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *wt;</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Initialize our top level encryptor.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> <span class="keywordflow">if</span> ((m = calloc(1, <span class="keyword">sizeof</span>(MY_CRYPTO))) == NULL)</div><div class="line"> <span class="keywordflow">return</span> (errno);</div><div class="line"> wt = (<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *)&m->encryptor;</div><div class="line"> wt-><a name="a10"></a><a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html#a0f0f363b689363d36ffce7fdf8a337ac">encrypt</a> = rotate_encrypt;</div><div class="line"> wt-><a name="a11"></a><a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html#abad5447ebeb99d06b9024df435cffc26">decrypt</a> = rotate_decrypt;</div><div class="line"> wt-><a name="a12"></a><a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html#ac965990f0d81b99fc10ec0b13b9df162">sizing</a> = rotate_sizing;</div><div class="line"> wt-><a name="a13"></a><a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html#a947e253ec628a29b62e4b6656eb7b92a">customize</a> = rotate_customize;</div><div class="line"> wt-><a name="a14"></a><a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html#ad9337c89e540be05d207995c33bbe993">terminate</a> = rotate_terminate;</div><div class="line"> m->num_calls = 0;</div><div class="line"> error_check(connection-><a name="a15"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#a59d203f4474780ca34bd3e07b8064949">add_encryptor</a>(connection, <span class="stringliteral">"rotn"</span>, (<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *)m, NULL));</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * simple_walk_log --</span></div><div class="line"><span class="comment"> * A simple walk of the write-ahead log. We wrote text messages into the log. Print them. This</span></div><div class="line"><span class="comment"> * verifies we're decrypting properly.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">simple_walk_log(<a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session)</div><div class="line">{</div><div class="line"> <a name="_a16"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html">WT_CURSOR</a> *cursor;</div><div class="line"> <a name="_a17"></a><a class="code" href="group__wt.html#struct_w_t___i_t_e_m">WT_ITEM</a> logrec_key, logrec_value;</div><div class="line"> uint64_t txnid;</div><div class="line"> uint32_t fileid, log_file, log_offset, opcount, optype, rectype;</div><div class="line"> <span class="keywordtype">int</span> found, ret;</div><div class="line"></div><div class="line"> error_check(session-><a name="a18"></a><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session, <span class="stringliteral">"log:"</span>, NULL, NULL, &cursor));</div><div class="line"></div><div class="line"> found = 0;</div><div class="line"> <span class="keywordflow">while</span> ((ret = cursor-><a name="a19"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#a0503f16bd8f3d05aa3552f229b3a8e1b">next</a>(cursor)) == 0) {</div><div class="line"> error_check(cursor-><a name="a20"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af19f6f9d9c7fc248ab38879032620b2f">get_key</a>(cursor, &log_file, &log_offset, &opcount));</div><div class="line"> error_check(cursor-><a name="a21"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af85364a5af50b95bbc46c82e72f75c01">get_value</a>(</div><div class="line"> cursor, &txnid, &rectype, &optype, &fileid, &logrec_key, &logrec_value));</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (rectype == <a name="a22"></a><a class="code" href="group__wt.html#ga8cf04a003979e7852209079d4093d783">WT_LOGREC_MESSAGE</a>) {</div><div class="line"> found = 1;</div><div class="line"> printf(<span class="stringliteral">"Application Log Record: %s\n"</span>, (<span class="keywordtype">char</span> *)logrec_value.<a name="a23"></a><a class="code" href="group__wt.html#a57f5e62aa968275d7e398cfa70e49450">data</a>);</div><div class="line"> }</div><div class="line"> }</div><div class="line"> scan_end_check(ret == <a name="a24"></a><a class="code" href="group__wt.html#ga3c9e1b494d95cf34404ab7a974af6bf8">WT_NOTFOUND</a>);</div><div class="line"></div><div class="line"> error_check(cursor-><a name="a25"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#aeea071f192cab12245a50fbe71c3460b">close</a>(cursor));</div><div class="line"> <span class="keywordflow">if</span> (found == 0) {</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Did not find log messages.\n"</span>);</div><div class="line"> exit(EXIT_FAILURE);</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="preprocessor">#define MAX_KEYS 20</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define EXTENSION_NAME "local=(entry=add_my_encryptors)"</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define WT_OPEN_CONFIG_COMMON \</span></div><div class="line"><span class="preprocessor"> "create,cache_size=100MB,extensions=[" EXTENSION_NAME \</span></div><div class="line"><span class="preprocessor"> "]," \</span></div><div class="line"><span class="preprocessor"> "log=(archive=false,enabled=true),"</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define WT_OPEN_CONFIG_GOOD \</span></div><div class="line"><span class="preprocessor"> WT_OPEN_CONFIG_COMMON \</span></div><div class="line"><span class="preprocessor"> "encryption=(name=rotn,keyid=" SYS_KEYID ",secretkey=" SYS_PW ")"</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define COMP_A "AAAAAAAAAAAAAAAAAA"</span></div><div class="line"><span class="preprocessor">#define COMP_B "BBBBBBBBBBBBBBBBBB"</span></div><div class="line"><span class="preprocessor">#define COMP_C "CCCCCCCCCCCCCCCCCC"</span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span></div><div class="line">main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div><div class="line">{</div><div class="line"> <a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html">WT_CONNECTION</a> *conn;</div><div class="line"> <a class="code" href="struct_w_t___c_u_r_s_o_r.html">WT_CURSOR</a> *c1, *c2, *nc;</div><div class="line"> <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session;</div><div class="line"> <span class="keywordtype">int</span> i, ret;</div><div class="line"> <span class="keywordtype">char</span> keybuf[32], valbuf[32];</div><div class="line"> <span class="keywordtype">char</span> *key1, *key2, *key3, *val1, *val2, *val3;</div><div class="line"></div><div class="line"> home = example_setup(argc, argv);</div><div class="line"></div><div class="line"> error_check(<a name="a26"></a><a class="code" href="group__wt.html#gacbe8d118f978f5bfc8ccb4c77c9e8813">wiredtiger_open</a>(home, NULL, WT_OPEN_CONFIG_GOOD, &conn));</div><div class="line"> error_check(conn-><a name="a27"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#adad5965cd4a60f65b5ac01f7ca6d1fc0">open_session</a>(conn, NULL, NULL, &session));</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Write a log record that is larger than the base 128 bytes and also should compress well.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> error_check(session-><a name="a28"></a><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#ac85541ca42d7596857d9f50e03c78eb5">log_printf</a>(session,</div><div class="line"> COMP_A COMP_B COMP_C COMP_A COMP_B COMP_C COMP_A COMP_B COMP_C COMP_A COMP_B COMP_C</div><div class="line"> <span class="stringliteral">"The quick brown fox jumps over the lazy dog "</span>));</div><div class="line"> simple_walk_log(session);</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Create and open some encrypted and not encrypted tables. Also use column store and</span></div><div class="line"><span class="comment"> * compression for some tables.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> error_check(</div><div class="line"> session-><a name="a29"></a><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb">create</a>(session, <span class="stringliteral">"table:crypto1"</span>, <span class="stringliteral">"encryption=(name=rotn,keyid="</span> USER1_KEYID <span class="stringliteral">"),"</span></div><div class="line"> <span class="stringliteral">"columns=(key0,value0),"</span></div><div class="line"> <span class="stringliteral">"key_format=S,value_format=S"</span>));</div><div class="line"> error_check(session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb">create</a>(session,</div><div class="line"> <span class="stringliteral">"index:crypto1:byvalue"</span>, <span class="stringliteral">"encryption=(name=rotn,keyid="</span> USER1_KEYID <span class="stringliteral">"),"</span></div><div class="line"> <span class="stringliteral">"columns=(value0,key0)"</span>));</div><div class="line"> error_check(</div><div class="line"> session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb">create</a>(session, <span class="stringliteral">"table:crypto2"</span>, <span class="stringliteral">"encryption=(name=rotn,keyid="</span> USER2_KEYID <span class="stringliteral">"),"</span></div><div class="line"> <span class="stringliteral">"key_format=S,value_format=S"</span>));</div><div class="line"> error_check(session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb">create</a>(session, <span class="stringliteral">"table:nocrypto"</span>, <span class="stringliteral">"key_format=S,value_format=S"</span>));</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Send in an unknown keyid. WiredTiger will try to add in the new keyid, but the customize</span></div><div class="line"><span class="comment"> * function above will return an error since it is unrecognized.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> ret = session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb">create</a>(session, <span class="stringliteral">"table:cryptobad"</span>, <span class="stringliteral">"encryption=(name=rotn,keyid="</span> USERBAD_KEYID</div><div class="line"> <span class="stringliteral">"),"</span></div><div class="line"> <span class="stringliteral">"key_format=S,value_format=S"</span>);</div><div class="line"> <span class="keywordflow">if</span> (ret == 0) {</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Did not detect bad/unknown keyid error\n"</span>);</div><div class="line"> exit(EXIT_FAILURE);</div><div class="line"> }</div><div class="line"></div><div class="line"> error_check(session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session, <span class="stringliteral">"table:crypto1"</span>, NULL, NULL, &c1));</div><div class="line"> error_check(session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session, <span class="stringliteral">"table:crypto2"</span>, NULL, NULL, &c2));</div><div class="line"> error_check(session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session, <span class="stringliteral">"table:nocrypto"</span>, NULL, NULL, &nc));</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Insert a set of keys and values. Insert the same data into all tables so that we can verify</span></div><div class="line"><span class="comment"> * they're all the same after we decrypt on read.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> <span class="keywordflow">for</span> (i = 0; i < MAX_KEYS; i++) {</div><div class="line"> (void)snprintf(keybuf, <span class="keyword">sizeof</span>(keybuf), <span class="stringliteral">"key%d"</span>, i);</div><div class="line"> c1-><a name="a30"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#ad1088d719df40babc1f57d086691ebdc">set_key</a>(c1, keybuf);</div><div class="line"> c2-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#ad1088d719df40babc1f57d086691ebdc">set_key</a>(c2, keybuf);</div><div class="line"> nc-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#ad1088d719df40babc1f57d086691ebdc">set_key</a>(nc, keybuf);</div><div class="line"></div><div class="line"> (void)snprintf(valbuf, <span class="keyword">sizeof</span>(valbuf), <span class="stringliteral">"value%d"</span>, i);</div><div class="line"> c1-><a name="a31"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#a27f7cbd0cd3e561f6a145704813ad64c">set_value</a>(c1, valbuf);</div><div class="line"> c2-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#a27f7cbd0cd3e561f6a145704813ad64c">set_value</a>(c2, valbuf);</div><div class="line"> nc-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#a27f7cbd0cd3e561f6a145704813ad64c">set_value</a>(nc, valbuf);</div><div class="line"></div><div class="line"> error_check(c1-><a name="a32"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#aac90d9fbcc031570f924db55f8a1cee3">insert</a>(c1));</div><div class="line"> error_check(c2-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#aac90d9fbcc031570f924db55f8a1cee3">insert</a>(c2));</div><div class="line"> error_check(nc-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#aac90d9fbcc031570f924db55f8a1cee3">insert</a>(nc));</div><div class="line"> <span class="keywordflow">if</span> (i % 5 == 0)</div><div class="line"> error_check(session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#ac85541ca42d7596857d9f50e03c78eb5">log_printf</a>(session, <span class="stringliteral">"Wrote %d records"</span>, i));</div><div class="line"> }</div><div class="line"> error_check(session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#ac85541ca42d7596857d9f50e03c78eb5">log_printf</a>(session, <span class="stringliteral">"Done. Wrote %d total records"</span>, i));</div><div class="line"></div><div class="line"> <span class="keywordflow">while</span> (c1-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#a0503f16bd8f3d05aa3552f229b3a8e1b">next</a>(c1) == 0) {</div><div class="line"> error_check(c1-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af19f6f9d9c7fc248ab38879032620b2f">get_key</a>(c1, &key1));</div><div class="line"> error_check(c1-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af85364a5af50b95bbc46c82e72f75c01">get_value</a>(c1, &val1));</div><div class="line"></div><div class="line"> printf(<span class="stringliteral">"Read key %s; value %s\n"</span>, key1, val1);</div><div class="line"> }</div><div class="line"> simple_walk_log(session);</div><div class="line"> printf(<span class="stringliteral">"CLOSE\n"</span>);</div><div class="line"> error_check(conn-><a name="a33"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#af535c517df851eeac8ebf3594d40b545">close</a>(conn, NULL));</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * We want to close and reopen so that we recreate the cache by reading the data from disk,</span></div><div class="line"><span class="comment"> * forcing decryption.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> printf(<span class="stringliteral">"REOPEN and VERIFY encrypted data\n"</span>);</div><div class="line"></div><div class="line"> error_check(<a class="code" href="group__wt.html#gacbe8d118f978f5bfc8ccb4c77c9e8813">wiredtiger_open</a>(home, NULL, WT_OPEN_CONFIG_GOOD, &conn));</div><div class="line"></div><div class="line"> error_check(conn-><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#adad5965cd4a60f65b5ac01f7ca6d1fc0">open_session</a>(conn, NULL, NULL, &session));</div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Verify we can read the encrypted log after restart.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> simple_walk_log(session);</div><div class="line"> error_check(session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session, <span class="stringliteral">"table:crypto1"</span>, NULL, NULL, &c1));</div><div class="line"> error_check(session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session, <span class="stringliteral">"table:crypto2"</span>, NULL, NULL, &c2));</div><div class="line"> error_check(session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session, <span class="stringliteral">"table:nocrypto"</span>, NULL, NULL, &nc));</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Read the same data from each cursor. All should be identical.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> <span class="keywordflow">while</span> (c1-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#a0503f16bd8f3d05aa3552f229b3a8e1b">next</a>(c1) == 0) {</div><div class="line"> error_check(c2-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#a0503f16bd8f3d05aa3552f229b3a8e1b">next</a>(c2));</div><div class="line"> error_check(nc-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#a0503f16bd8f3d05aa3552f229b3a8e1b">next</a>(nc));</div><div class="line"> error_check(c1-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af19f6f9d9c7fc248ab38879032620b2f">get_key</a>(c1, &key1));</div><div class="line"> error_check(c1-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af85364a5af50b95bbc46c82e72f75c01">get_value</a>(c1, &val1));</div><div class="line"> error_check(c2-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af19f6f9d9c7fc248ab38879032620b2f">get_key</a>(c2, &key2));</div><div class="line"> error_check(c2-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af85364a5af50b95bbc46c82e72f75c01">get_value</a>(c2, &val2));</div><div class="line"> error_check(nc-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af19f6f9d9c7fc248ab38879032620b2f">get_key</a>(nc, &key3));</div><div class="line"> error_check(nc-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af85364a5af50b95bbc46c82e72f75c01">get_value</a>(nc, &val3));</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (strcmp(key1, key2) != 0)</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Key1 %s and Key2 %s do not match\n"</span>, key1, key2);</div><div class="line"> <span class="keywordflow">if</span> (strcmp(key1, key3) != 0)</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Key1 %s and Key3 %s do not match\n"</span>, key1, key3);</div><div class="line"> <span class="keywordflow">if</span> (strcmp(key2, key3) != 0)</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Key2 %s and Key3 %s do not match\n"</span>, key2, key3);</div><div class="line"> <span class="keywordflow">if</span> (strcmp(val1, val2) != 0)</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Val1 %s and Val2 %s do not match\n"</span>, val1, val2);</div><div class="line"> <span class="keywordflow">if</span> (strcmp(val1, val3) != 0)</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Val1 %s and Val3 %s do not match\n"</span>, val1, val3);</div><div class="line"> <span class="keywordflow">if</span> (strcmp(val2, val3) != 0)</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Val2 %s and Val3 %s do not match\n"</span>, val2, val3);</div><div class="line"></div><div class="line"> printf(<span class="stringliteral">"Verified key %s; value %s\n"</span>, key1, val1);</div><div class="line"> }</div><div class="line"></div><div class="line"> error_check(conn-><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#af535c517df851eeac8ebf3594d40b545">close</a>(conn, NULL));</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> (EXIT_SUCCESS);</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Copyright (c) 2008-2019 MongoDB, Inc. All rights reserved. Contact <a href="mailto:info@wiredtiger.com">info@wiredtiger.com</a> for more information.</li>
</ul>
</div>
</body>
</html>
|