diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-03-06 11:27:24 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-03-09 10:46:11 +0000 |
commit | f1d8615a328e2e7361445bcc91d96d2d42cddbb8 (patch) | |
tree | 809fe90c779d9e9818dbc0e9ad28dfe5273fcbf7 /src | |
parent | 369d9c23902ce6c8350884b8e5fbb5138d0340af (diff) | |
download | rspamd-f1d8615a328e2e7361445bcc91d96d2d42cddbb8.tar.gz rspamd-f1d8615a328e2e7361445bcc91d96d2d42cddbb8.zip |
[Rework] Rework URL structure: user field
Diffstat (limited to 'src')
-rw-r--r-- | src/libserver/protocol.c | 5 | ||||
-rw-r--r-- | src/libserver/re_cache.c | 2 | ||||
-rw-r--r-- | src/libserver/url.c | 23 | ||||
-rw-r--r-- | src/libserver/url.h | 8 | ||||
-rw-r--r-- | src/lua/lua_url.c | 11 |
5 files changed, 28 insertions, 21 deletions
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index ee5cc1f4d..4c1a94d99 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -994,9 +994,8 @@ emails_protocol_cb (gpointer key, gpointer value, gpointer ud) struct rspamd_url *url = value; ucl_object_t *obj; - if (url->userlen > 0 && url->hostlen > 0 && - url->host == url->user + url->userlen + 1) { - obj = ucl_object_fromlstring (url->user, + if (url->userlen > 0 && url->hostlen > 0) { + obj = ucl_object_fromlstring (rspamd_url_user_unsafe (url), url->userlen + url->hostlen + 1); ucl_array_append (cb->top, obj); } diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index 862ffc351..995af8ddf 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -1223,7 +1223,7 @@ rspamd_re_cache_exec_re (struct rspamd_task *task, continue; } - in = url->user; + in = rspamd_url_user_unsafe (url); len = url->userlen + 1 + url->hostlen; scvec[i] = (guchar *) in; lenvec[i++] = len; diff --git a/src/libserver/url.c b/src/libserver/url.c index f4c5783ab..a2a9d852f 100644 --- a/src/libserver/url.c +++ b/src/libserver/url.c @@ -1874,7 +1874,7 @@ rspamd_url_shift (struct rspamd_url *uri, gsize nlen, switch (field) { case UF_SCHEMA: if (uri->userlen > 0) { - uri->user -= shift; + uri->usershift -= shift; } if (uri->hostlen > 0) { uri->host -= shift; @@ -2038,7 +2038,7 @@ rspamd_url_parse (struct rspamd_url *uri, uri->fragmentlen = complen; break; case UF_USERINFO: - uri->user = comp; + uri->usershift = u.field_data[i].off; uri->userlen = complen; break; default: @@ -3382,7 +3382,7 @@ rspamd_email_hash (gconstpointer u) } if (url->userlen > 0) { - rspamd_cryptobox_fast_hash_update (&st, url->user, url->userlen); + rspamd_cryptobox_fast_hash_update (&st, rspamd_url_user_unsafe(url), url->userlen); } return (guint)rspamd_cryptobox_fast_hash_final (&st); @@ -3404,8 +3404,9 @@ rspamd_emails_cmp (gconstpointer a, gconstpointer b) return FALSE; } else { - return rspamd_lc_cmp (u1->user, u2->user, u1->userlen) == - 0; + return (rspamd_lc_cmp (rspamd_url_user_unsafe(u1), + rspamd_url_user_unsafe(u2), + u1->userlen) == 0); } } else { @@ -3606,7 +3607,7 @@ static const unsigned char rspamd_url_encoding_classes[256] = { #define CHECK_URL_COMPONENT(beg, len, flags) do { \ for (i = 0; i < (len); i ++) { \ - if ((rspamd_url_encoding_classes[(beg)[i]] & (flags)) == 0) { \ + if ((rspamd_url_encoding_classes[(guchar)(beg)[i]] & (flags)) == 0) { \ dlen += 2; \ } \ } \ @@ -3614,10 +3615,10 @@ static const unsigned char rspamd_url_encoding_classes[256] = { #define ENCODE_URL_COMPONENT(beg, len, flags) do { \ for (i = 0; i < (len) && dend > d; i ++) { \ - if ((rspamd_url_encoding_classes[(beg)[i]] & (flags)) == 0) { \ + if ((rspamd_url_encoding_classes[(guchar)(beg)[i]] & (flags)) == 0) { \ *d++ = '%'; \ - *d++ = hexdigests[((beg)[i] >> 4) & 0xf]; \ - *d++ = hexdigests[(beg)[i] & 0xf]; \ + *d++ = hexdigests[(guchar)((beg)[i] >> 4) & 0xf]; \ + *d++ = hexdigests[(guchar)(beg)[i] & 0xf]; \ } \ else { \ *d++ = (beg)[i]; \ @@ -3638,7 +3639,7 @@ rspamd_url_encode (struct rspamd_url *url, gsize *pdlen, CHECK_URL_COMPONENT ((guchar *)url->host, url->hostlen, RSPAMD_URL_FLAGS_HOSTSAFE); - CHECK_URL_COMPONENT ((guchar *)url->user, url->userlen, + CHECK_URL_COMPONENT (rspamd_url_user_unsafe(url), url->userlen, RSPAMD_URL_FLAGS_USERSAFE); CHECK_URL_COMPONENT ((guchar *)url->data, url->datalen, RSPAMD_URL_FLAGS_PATHSAFE); @@ -3677,7 +3678,7 @@ rspamd_url_encode (struct rspamd_url *url, gsize *pdlen, } if (url->userlen > 0) { - ENCODE_URL_COMPONENT ((guchar *)url->user, url->userlen, + ENCODE_URL_COMPONENT (rspamd_url_user_unsafe (url), url->userlen, RSPAMD_URL_FLAGS_USERSAFE); *d++ = ':'; } diff --git a/src/libserver/url.h b/src/libserver/url.h index 53c4abbeb..78330d814 100644 --- a/src/libserver/url.h +++ b/src/libserver/url.h @@ -47,7 +47,9 @@ struct rspamd_url { guint protocol; guint port; - gchar *user; + guint usershift; + guint userlen; + gchar *host; gchar *data; gchar *query; @@ -58,7 +60,6 @@ struct rspamd_url { struct rspamd_url *phished_url; guint protocollen; - guint userlen; guint hostlen; guint datalen; guint querylen; @@ -71,6 +72,9 @@ struct rspamd_url { guint count; }; +#define rspamd_url_user(u) ((u)->userlen > 0 ? (u)->string + (u)->usershift : NULL) +#define rspamd_url_user_unsafe(u) ((u)->string + (u)->usershift) + enum uri_errno { URI_ERRNO_OK = 0, /* Parsing went well */ URI_ERRNO_EMPTY, /* The URI string was empty */ diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c index 0bd4f1c7e..7b0dee89b 100644 --- a/src/lua/lua_url.c +++ b/src/lua/lua_url.c @@ -198,8 +198,8 @@ lua_url_get_user (lua_State *L) LUA_TRACE_POINT; struct rspamd_lua_url *url = lua_check_url (L, 1); - if (url != NULL && url->url->user != NULL) { - lua_pushlstring (L, url->url->user, url->url->userlen); + if (url != NULL && rspamd_url_user (url->url) != NULL) { + lua_pushlstring (L, rspamd_url_user (url->url), url->url->userlen); } else { lua_pushnil (L); @@ -307,7 +307,10 @@ lua_url_tostring (lua_State *L) if (url->url->protocol == PROTOCOL_MAILTO) { gchar *tmp = g_malloc (url->url->userlen + 1 + url->url->hostlen); - memcpy (tmp, url->url->user, url->url->userlen); + if (url->url->userlen) { + memcpy (tmp, url->url->string + url->url->usershift, url->url->userlen); + } + tmp[url->url->userlen] = '@'; memcpy (tmp + url->url->userlen + 1, url->url->host, url->url->hostlen); @@ -675,7 +678,7 @@ lua_url_to_table (lua_State *L) if (u->userlen > 0) { lua_pushstring (L, "user"); - lua_pushlstring (L, u->user, u->userlen); + lua_pushlstring (L, rspamd_url_user (u), u->userlen); lua_settable (L, -3); } |