<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13370">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
George Joseph: Looks good to me, approved
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">ACL: ast_apply_acl_nolog - identical to ast_apply_acl but without logging.<br><br>Due to use in res_rtp_asterisk there is a need to be able to apply an<br>ACL without logging any invalid/denies. It's probably sensible to at<br>least validate the ACL once directly after load and report invalid ACLs.<br><br>Change-Id: I256169229d945ca7c1bbf228fc492d91df345843<br>Signed-off-by: Jaco Kroon <jaco@uls.co.za><br>---<br>M include/asterisk/acl.h<br>M main/acl.c<br>2 files changed, 34 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/acl.h b/include/asterisk/acl.h</span><br><span>index bda1c76..b8a4f72 100644</span><br><span>--- a/include/asterisk/acl.h</span><br><span>+++ b/include/asterisk/acl.h</span><br><span>@@ -213,6 +213,20 @@</span><br><span> enum ast_acl_sense ast_apply_acl(struct ast_acl_list *acl_list, const struct ast_sockaddr *addr, const char *purpose);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Apply a set of rules to a given IP address, don't log failure.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \details</span><br><span style="color: hsl(120, 100%, 40%);">+ * Exactly like ast_apply_acl, except that it will never log anything.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param acl_list The head of the list of ACLs to evaluate</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param addr An ast_sockaddr whose address is considered when matching rules</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval AST_SENSE_ALLOW The IP address passes our ACLs</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval AST_SENSE_DENY The IP address fails our ACLs</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+enum ast_acl_sense ast_apply_acl_nolog(struct ast_acl_list *acl_list, const struct ast_sockaddr *addr);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Get the IP address given a hostname</span><br><span> *</span><br><span> * \details</span><br><span>diff --git a/main/acl.c b/main/acl.c</span><br><span>index 1d628e6..5028587 100644</span><br><span>--- a/main/acl.c</span><br><span>+++ b/main/acl.c</span><br><span>@@ -725,7 +725,7 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-enum ast_acl_sense ast_apply_acl(struct ast_acl_list *acl_list, const struct ast_sockaddr *addr, const char *purpose)</span><br><span style="color: hsl(120, 100%, 40%);">+static enum ast_acl_sense ast_apply_acl_internal(struct ast_acl_list *acl_list, const struct ast_sockaddr *addr, const char *log_prefix)</span><br><span> {</span><br><span> struct ast_acl *acl;</span><br><span> </span><br><span>@@ -739,16 +739,22 @@</span><br><span> AST_LIST_TRAVERSE(acl_list, acl, list) {</span><br><span> if (acl->is_invalid) {</span><br><span> /* In this case, the baseline ACL shouldn't ever trigger this, but if that somehow happens, it'll still be shown. */</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "%sRejecting '%s' due to use of an invalid ACL '%s'.\n", purpose ? purpose : "", ast_sockaddr_stringify_addr(addr),</span><br><span style="color: hsl(0, 100%, 40%);">- ast_strlen_zero(acl->name) ? "(BASELINE)" : acl->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (log_prefix) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "%sRejecting '%s' due to use of an invalid ACL '%s'.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_prefix, ast_sockaddr_stringify_addr(addr),</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_strlen_zero(acl->name) ? "(BASELINE)" : acl->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> AST_LIST_UNLOCK(acl_list);</span><br><span> return AST_SENSE_DENY;</span><br><span> }</span><br><span> </span><br><span> if (acl->acl) {</span><br><span> if (ast_apply_ha(acl->acl, addr) == AST_SENSE_DENY) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_NOTICE, "%sRejecting '%s' due to a failure to pass ACL '%s'\n", purpose ? purpose : "", ast_sockaddr_stringify_addr(addr),</span><br><span style="color: hsl(0, 100%, 40%);">- ast_strlen_zero(acl->name) ? "(BASELINE)" : acl->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (log_prefix) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_NOTICE, "%sRejecting '%s' due to a failure to pass ACL '%s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_prefix, ast_sockaddr_stringify_addr(addr),</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_strlen_zero(acl->name) ? "(BASELINE)" : acl->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> AST_LIST_UNLOCK(acl_list);</span><br><span> return AST_SENSE_DENY;</span><br><span> }</span><br><span>@@ -760,6 +766,15 @@</span><br><span> return AST_SENSE_ALLOW;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+enum ast_acl_sense ast_apply_acl(struct ast_acl_list *acl_list, const struct ast_sockaddr *addr, const char *purpose) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_apply_acl_internal(acl_list, addr, purpose ?: "");</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%);">+enum ast_acl_sense ast_apply_acl_nolog(struct ast_acl_list *acl_list, const struct ast_sockaddr *addr) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_apply_acl_internal(acl_list, addr, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> enum ast_acl_sense ast_apply_ha(const struct ast_ha *ha, const struct ast_sockaddr *addr)</span><br><span> {</span><br><span> /* Start optimistic */</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13370">change 13370</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/+/13370"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I256169229d945ca7c1bbf228fc492d91df345843 </div>
<div style="display:none"> Gerrit-Change-Number: 13370 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Jaco Kroon <jaco@uls.co.za> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>