<p>Philip Prindeville has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19397">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_crypto: use ast_file_read_dirs() to iterate<br><br>ASTERISK-30213<br><br>Change-Id: I115f5f8942ffcfb23cd2559a55bac8a2eba081e0<br>---<br>M res/res_crypto.c<br>1 file changed, 29 insertions(+), 21 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/97/19397/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_crypto.c b/res/res_crypto.c</span><br><span>index bc66318..82014b6 100644</span><br><span>--- a/res/res_crypto.c</span><br><span>+++ b/res/res_crypto.c</span><br><span>@@ -51,6 +51,7 @@</span><br><span> #include "asterisk/options.h" /* for ast_opt_init_keys */</span><br><span> #include "asterisk/paths.h" /* for ast_config_AST_KEY_DIR */</span><br><span> #include "asterisk/utils.h" /* for ast_copy_string, ast_base64decode */</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/file.h" /* for ast_file_read_dirs */</span><br><span> </span><br><span> #define AST_API_MODULE</span><br><span> #include "asterisk/crypto.h" /* for AST_KEY_PUBLIC, AST_KEY_PRIVATE */</span><br><span>@@ -761,6 +762,20 @@</span><br><span> return res;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+struct crypto_load_on_file {</span><br><span style="color: hsl(120, 100%, 40%);">+ int ifd;</span><br><span style="color: hsl(120, 100%, 40%);">+ int ofd;</span><br><span style="color: hsl(120, 100%, 40%);">+ int note;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int crypto_load_cb(const char *directory, const char *file, void *obj)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct crypto_load_on_file *on_file = obj;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ try_load_key(directory, file, on_file->ifd, on_file->ofd, &on_file->note);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span> * \brief refresh RSA keys from file</span><br><span> * \param ifd file descriptor</span><br><span>@@ -769,9 +784,7 @@</span><br><span> static void crypto_load(int ifd, int ofd)</span><br><span> {</span><br><span> struct ast_key *key;</span><br><span style="color: hsl(0, 100%, 40%);">- DIR *dir = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- struct dirent *ent;</span><br><span style="color: hsl(0, 100%, 40%);">- int note = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct crypto_load_on_file on_file = { ifd, ofd, 0 };</span><br><span> </span><br><span> AST_RWLIST_WRLOCK(&keys);</span><br><span> </span><br><span>@@ -780,27 +793,11 @@</span><br><span> key->delme = 1;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- /* Load new keys */</span><br><span style="color: hsl(0, 100%, 40%);">- if ((dir = opendir(ast_config_AST_KEY_DIR))) {</span><br><span style="color: hsl(0, 100%, 40%);">- while ((ent = readdir(dir))) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) {</span><br><span style="color: hsl(0, 100%, 40%);">- continue;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if (ent->d_type == DT_DIR) {</span><br><span style="color: hsl(0, 100%, 40%);">- continue;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if (ent->d_type != DT_REG) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Non-regular file '%s' in keys directory\n", ent->d_name);</span><br><span style="color: hsl(0, 100%, 40%);">- continue;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- try_load_key(ast_config_AST_KEY_DIR, ent->d_name, ifd, ofd, ¬e);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- closedir(dir);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_file_read_dirs(ast_config_AST_KEY_DIR, crypto_load_cb, &on_file, 1) == -1) {</span><br><span> ast_log(LOG_WARNING, "Unable to open key directory '%s'\n", ast_config_AST_KEY_DIR);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (note) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (on_file.note) {</span><br><span> ast_log(LOG_NOTICE, "Please run the command 'keys init' to enter the passcodes for the keys\n");</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19397">change 19397</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/19397"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 20 </div>
<div style="display:none"> Gerrit-Change-Id: I115f5f8942ffcfb23cd2559a55bac8a2eba081e0 </div>
<div style="display:none"> Gerrit-Change-Number: 19397 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Philip Prindeville <philipp@redfish-solutions.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>