aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authormatteo <matteo@f38db490-d61c-443f-a65b-d21fe96a405b>2003-03-10 20:39:12 +0000
committermatteo <matteo@f38db490-d61c-443f-a65b-d21fe96a405b>2003-03-10 20:39:12 +0000
commitba9c4be35b5818f98f60508a2458b5bd78ccea3f (patch)
treebef8ba28b15990e870de59e2ea4e0cc8d486d5ac /utils
parentb8ed719ad6acba6f213f737749c9823af2836708 (diff)
lun mar 10 21:39:02 CET 2003
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@638 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'utils')
-rwxr-xr-xutils/astman.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/utils/astman.c b/utils/astman.c
index 6bda4ff9c..6fa6b8118 100755
--- a/utils/astman.c
+++ b/utils/astman.c
@@ -20,6 +20,7 @@
#include <unistd.h>
#include <stdlib.h>
+#include <asterisk/md5.h>
#include <asterisk/manager.h>
#define MAX_HEADERS 80
@@ -609,18 +610,49 @@ static int login(char *hostname)
if (es.u.co == login) {
snprintf(tmp, sizeof(tmp), "Logging in '%s'...", user);
show_doing("Logging in", tmp);
- manager_action("Login",
- "Username: %s\r\n"
- "Secret: %s\r\n",
- user, pass);
+ /* Check to see if the remote host supports MD5 Authentication */
+ manager_action("Challenge", "AuthType: MD5\r\n");
m = wait_for_response(10000);
- hide_doing();
- if (m) {
+ if (m && !strcasecmp(get_header(m, "Response"), "Success")) {
+ char *challenge = get_header(m, "Challenge");
+ int x;
+ int len = 0;
+ char md5key[256] = "";
+ struct MD5Context md5;
+ unsigned char digest[16];
+ MD5Init(&md5);
+ MD5Update(&md5, challenge, strlen(challenge));
+ MD5Update(&md5, pass, strlen(pass));
+ MD5Final(digest, &md5);
+ for (x=0; x<16; x++)
+ len += sprintf(md5key + len, "%2.2x", digest[x]);
+ manager_action("Login",
+ "AuthType: MD5\r\n"
+ "Username: %s\r\n"
+ "Key: %s\r\n",
+ user, md5key);
+ m = wait_for_response(10000);
+ hide_doing();
if (!strcasecmp(get_header(m, "Response"), "Success")) {
res = 0;
} else {
show_message("Login Failed", get_header(m, "Message"));
}
+ } else {
+ memset(m, 0, sizeof(m));
+ manager_action("Login",
+ "Username: %s\r\n"
+ "Secret: %s\r\n",
+ user, pass);
+ m = wait_for_response(10000);
+ hide_doing();
+ if (m) {
+ if (!strcasecmp(get_header(m, "Response"), "Success")) {
+ res = 0;
+ } else {
+ show_message("Login Failed", get_header(m, "Message"));
+ }
+ }
}
}
}