From 5cd58210fe3bdfb0895c9f12fbf4f4155d63c9a3 Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Tue, 20 Sep 2011 03:59:02 +0000 Subject: [PATCH] MM4_Forward.RES fix --- mbuni/ChangeLog | 2 ++ mbuni/mmlib/mms_util.c | 36 ++++++++++++++++++++++++++++++++++ mbuni/mmlib/mms_util.h | 3 +++ mbuni/mmsbox/bearerbox.c | 41 ++++----------------------------------- mbuni/mmsc/mmsfromemail.c | 5 +++-- 5 files changed, 48 insertions(+), 39 deletions(-) diff --git a/mbuni/ChangeLog b/mbuni/ChangeLog index af87ad4..8d87b9b 100644 --- a/mbuni/ChangeLog +++ b/mbuni/ChangeLog @@ -1,3 +1,5 @@ +2011-09-20 P. A. Bagyenda + * Fix: MM4_Forward.RES should include original msg ID (thanks to Franz Schwartau (franz@eletromail.org) 2011-09-08 P. A. Bagyenda * Exposed more functions in lib (get_stripped_param_value) * Minor changes to mms_msg module diff --git a/mbuni/mmlib/mms_util.c b/mbuni/mmlib/mms_util.c index 0659abf..7baf082 100644 --- a/mbuni/mmlib/mms_util.c +++ b/mbuni/mmlib/mms_util.c @@ -2641,3 +2641,39 @@ Octstr *get_keyword_from_mime(MIMEEntity *me) return keyword; } + +int http_auth_check(char *user, char *pass, List *headers, int *has_auth_hdr) +{ + int i, res = -1; + Octstr *v = http_header_value(headers, octstr_imm("Authorization")); + Octstr *p = NULL, *q = NULL; + + *has_auth_hdr = (v != NULL); + if (user == NULL || user[0] == 0) { + res = 0; + goto done; + } + + if (!v || + octstr_search(v, octstr_imm("Basic "), 0) != 0) + goto done; + p = octstr_copy(v, sizeof "Basic", octstr_len(v)); + octstr_base64_to_binary(p); + + i = octstr_search_char(p, ':', 0); + q = octstr_copy(p, i+1, octstr_len(p)); + octstr_delete(p, i, octstr_len(p)); + + /* p = user, q = pass. */ + + if (octstr_str_compare(p,user) != 0 || + octstr_str_compare(q,pass) != 0) + res = -1; + else + res = 0; +done: + octstr_destroy(v); + octstr_destroy(p); + octstr_destroy(q); + return res; +} diff --git a/mbuni/mmlib/mms_util.h b/mbuni/mmlib/mms_util.h index a58bf65..2be29c2 100644 --- a/mbuni/mmlib/mms_util.h +++ b/mbuni/mmlib/mms_util.h @@ -264,6 +264,9 @@ Octstr *parse_rfc2047_text(Octstr *in, int *mibenum); /* Utility func */ void mygw_free(void *); +/* Authenticate using HTTP Basic auth */ +int http_auth_check(char *user, char *pass, List *headers, int *has_auth_hdr); + /* Get (copy of) keyword from mime thingie */ Octstr *get_keyword_from_mime(MIMEEntity *me); #define US_ASCII_MIB_VAL 3 diff --git a/mbuni/mmsbox/bearerbox.c b/mbuni/mmsbox/bearerbox.c index bc1cacb..2de4c18 100644 --- a/mbuni/mmsbox/bearerbox.c +++ b/mbuni/mmsbox/bearerbox.c @@ -40,41 +40,6 @@ } while(0) -static int auth_check(Octstr *user, Octstr *pass, List *headers, int *has_auth_hdr) -{ - int i, res = -1; - Octstr *v = http_header_value(headers, octstr_imm("Authorization")); - Octstr *p = NULL, *q = NULL; - - *has_auth_hdr = (v != NULL); - if (octstr_len(user) == 0) { - res = 0; - goto done; - } - - if (!v || - octstr_search(v, octstr_imm("Basic "), 0) != 0) - goto done; - p = octstr_copy(v, sizeof "Basic", octstr_len(v)); - octstr_base64_to_binary(p); - - i = octstr_search_char(p, ':', 0); - q = octstr_copy(p, i+1, octstr_len(p)); - octstr_delete(p, i, octstr_len(p)); - - /* p = user, q = pass. */ - - if (octstr_compare(user, p) != 0 || - octstr_compare(pass, q) != 0) - res = -1; - else - res = 0; -done: - octstr_destroy(v); - octstr_destroy(p); - octstr_destroy(q); - return res; -} static Octstr *get_dlr_notify_url(Octstr *msgid, char *report_type, Octstr *mmc_gid, Octstr *mmc_id, Octstr *status, @@ -1027,10 +992,12 @@ static void dispatch_mm7_recv(List *rl) /* hmon->register_thread( "dispatch_mm7" ); */ while ((h = gwlist_consume(rl)) != NULL) { MmscGrp *m = h->m; + char *user = m->incoming.user ? octstr_get_cstr(m->incoming.user) : NULL; + char *pass = m->incoming.pass ? octstr_get_cstr(m->incoming.pass) : NULL; int ret = -1, has_auth = (m->type != MM1_MMSC); /* We dont authenticate mm1. right? */ - if (!has_auth && auth_check(m->incoming.user, - m->incoming.pass, + if (!has_auth && http_auth_check(user, + pass, h->headers, &has_auth) != 0) { /* Ask it to authenticate... */ List *hh = http_create_empty_headers(); http_header_add(hh, "WWW-Authenticate", diff --git a/mbuni/mmsc/mmsfromemail.c b/mbuni/mmsc/mmsfromemail.c index 1e0c6f7..bb2328b 100644 --- a/mbuni/mmsc/mmsfromemail.c +++ b/mbuni/mmsc/mmsfromemail.c @@ -274,8 +274,9 @@ int main(int argc, char *argv[]) mm4_type ? "MM4" : "MM3", settings->host_alias); if (qf) { - newmsgid = mms_make_msgid(octstr_get_cstr(qf), - settings->host_alias); + newmsgid = msgid ? octstr_duplicate(msgid) : + mms_make_msgid(octstr_get_cstr(qf), + settings->host_alias); mms_info(0, "mmsfromemail", NULL, "%s Queued message to %s from %s (via %s) => %s", mm4_type ? "MM4 Incoming" : "Email2MMS", octstr_get_cstr(xto), octstr_get_cstr(xfrom),