Skip to content

Commit f7c7a30

Browse files
author
Felipe Zimmerle
committed
Uses our own version of ap_find_command
Keep compatibility among different versions of Apache is not a simple task, in this case it can be avoided by the creation of our own version of ap_find_command, that is now used by msc_remote_rules.
1 parent 462308b commit f7c7a30

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

apache2/msc_remote_rules.c

+33-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,35 @@
3434
#define AP_MAX_ARGC 64
3535
#endif
3636

37+
/**
38+
* @brief Find command in a list.
39+
*
40+
* This is a duplicate of `ap_find_command', which is part of the standalone module.
41+
* Apache versions does not include the standalone, thus, this is necessary for
42+
* the Apache versions. Once it is here it may not be necessary to be part of
43+
* the standalone module, but, for this version both function will co-exist
44+
* avoiding problems with 3rd parties that are extending the standalone module.
45+
*
46+
* @note Prefer this function instead of `ap_finc_command` which is part of the
47+
* standalone module.
48+
*
49+
* @param parms char pointer, function name.
50+
* @param cmds pointer to command_rec[].
51+
* @retval NULL if command was not found.
52+
*
53+
*/
54+
const command_rec *msc_remote_find_command(const char *name, const command_rec *cmds)
55+
{
56+
while (cmds->name) {
57+
if (!strcasecmp(name, cmds->name))
58+
return cmds;
59+
60+
++cmds;
61+
}
62+
63+
return NULL;
64+
}
65+
3766

3867
/**
3968
* @brief Insert a new SecRule to be processed by ModSecurity
@@ -686,9 +715,10 @@ int msc_remote_add_rules_from_uri(cmd_parms *orig_parms,
686715
{
687716
const char *rule = NULL;
688717
int tmp = len;
689-
char *cmd_name;
690-
char *word;
718+
char *cmd_name = NULL;
719+
char *word = NULL;
691720
const command_rec *cmd;
721+
692722
ap_directive_t *newdir;
693723
cmd_parms *parms = apr_pcalloc(mp, sizeof (cmd_parms));
694724

@@ -704,7 +734,7 @@ int msc_remote_add_rules_from_uri(cmd_parms *orig_parms,
704734
}
705735

706736
cmd_name = ap_getword_conf(mp, &rule);
707-
cmd = ap_find_command(cmd_name, security2_module.cmds);
737+
cmd = msc_remote_find_command(cmd_name, security2_module.cmds);
708738

709739
if (cmd == NULL)
710740
{

0 commit comments

Comments
 (0)