aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-02-19 16:18:19 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-02-19 16:18:19 +0000
commit2463fdb0904079ca25187cc2a3c47ad451641ef9 (patch)
tree8504849f909bef6ef5ba8294867fe54093b24542 /apps
parented1eaca277281ec60c1b3adb41fd683420a31fe4 (diff)
Add checking capability to MD5 (bug #3619)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5053 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rwxr-xr-xapps/app_md5.c73
1 files changed, 66 insertions, 7 deletions
diff --git a/apps/app_md5.c b/apps/app_md5.c
index 1be840aed..a481393df 100755
--- a/apps/app_md5.c
+++ b/apps/app_md5.c
@@ -12,6 +12,7 @@
#include <asterisk/file.h>
#include <asterisk/logger.h>
#include <asterisk/utils.h>
+#include <asterisk/options.h>
#include <asterisk/channel.h>
#include <asterisk/pbx.h>
#include <asterisk/module.h>
@@ -20,16 +21,25 @@
#include <unistd.h>
#include <string.h>
-static char *tdesc = "MD5 checksum application";
-static char *app_md5 = "md5";
-static char *synopsis =
-" md5(<var>=<string>): Calculates a MD5 checksum on <string>.\n"
+static char *tdesc_md5 = "MD5 checksum application";
+static char *app_md5 = "MD5";
+static char *synopsis_md5 =
+" MD5(<var>=<string>): Calculates a MD5 checksum on <string>.\n"
"Returns hash value in a channel variable. Always return 0\n";
+static char *tdesc_md5check = "MD5 checksum verification application";
+static char *app_md5check = "MD5Check";
+static char *synopsis_md5check =
+" MD5Check(<md5hash>,<string>): Calculates a MD5 checksum on <string>\n"
+"and compares it with the hash. Returns 0 if <md5hash> is correct for <string>.\n"
+"Jumps to priority+101 if incorrect.\n";
+
STANDARD_LOCAL_USER;
LOCAL_USER_DECL;
+/*--- md5_exec: Calculate MD5 checksum (hash) on given string and
+ return it in channel variable ---*/
static int md5_exec(struct ast_channel *chan, void *data)
{
int res=0;
@@ -57,20 +67,69 @@ static int md5_exec(struct ast_channel *chan, void *data)
return res;
}
+/*--- md5check_exec: Calculate MD5 checksum and compare it with
+ existing checksum. ---*/
+static int md5check_exec(struct ast_channel *chan, void *data)
+{
+ int res=0;
+ struct localuser *u;
+ char *hash= NULL; /* Hash to compare with */
+ char *string = NULL; /* String to calculate on */
+ char newhash[50]; /* Return value */
+
+ if (!data) {
+ ast_log(LOG_WARNING, "Syntax: MD5Check(<md5hash>,<string>) - missing argument!\n");
+ return -1;
+ }
+ LOCAL_USER_ADD(u);
+ memset(newhash,0, sizeof(newhash));
+
+ string = ast_strdupa(data);
+ hash = strsep(&string,"|");
+ if (ast_strlen_zero(hash)) {
+ ast_log(LOG_WARNING, "Syntax: MD5Check(<md5hash>,<string>) - missing argument!\n");
+ LOCAL_USER_REMOVE(u);
+ return -1;
+ }
+ ast_md5_hash(newhash, string);
+ if (!strcmp(newhash, hash)) { /* Verification ok */
+ if (option_debug > 2)
+ ast_log(LOG_DEBUG, "MD5 verified ok: %s -- %s\n", hash, string);
+ LOCAL_USER_REMOVE(u);
+ return 0;
+ }
+ if (option_debug > 2)
+ ast_log(LOG_DEBUG, "ERROR: MD5 not verified: %s -- %s\n", hash, string);
+ if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num))
+ chan->priority += 100;
+ else if (option_debug > 2)
+ ast_log(LOG_DEBUG, "ERROR: Can't jump to exten+101 (e%s,p%d), sorry\n", chan->exten,chan->priority+101);
+ LOCAL_USER_REMOVE(u);
+ return res;
+}
+
int unload_module(void)
{
+ int res;
+
STANDARD_HANGUP_LOCALUSERS;
- return ast_unregister_application(app_md5);
+ res =ast_unregister_application(app_md5);
+ res |= ast_unregister_application(app_md5check);
+ return res;
}
int load_module(void)
{
- return ast_register_application(app_md5, md5_exec, synopsis, tdesc);
+ int res;
+
+ res = ast_register_application(app_md5check, md5check_exec, synopsis_md5check, tdesc_md5check);
+ res |= ast_register_application(app_md5, md5_exec, synopsis_md5, tdesc_md5);
+ return res;
}
char *description(void)
{
- return tdesc;
+ return tdesc_md5;
}
int usecount(void)