version 1.1.1.2, 2014/06/15 20:20:06
|
version 1.1.1.3, 2016/11/02 10:35:00
|
Line 1
|
Line 1
|
|
#include "first.h" |
|
|
#include "base.h" |
#include "base.h" |
#include "log.h" |
#include "log.h" |
#include "buffer.h" |
#include "buffer.h" |
Line 48 FREE_FUNC(mod_usertrack_free) {
|
Line 50 FREE_FUNC(mod_usertrack_free) {
|
for (i = 0; i < srv->config_context->used; i++) { |
for (i = 0; i < srv->config_context->used; i++) { |
plugin_config *s = p->config_storage[i]; |
plugin_config *s = p->config_storage[i]; |
|
|
|
if (NULL == s) continue; |
|
|
buffer_free(s->cookie_name); |
buffer_free(s->cookie_name); |
buffer_free(s->cookie_domain); |
buffer_free(s->cookie_domain); |
|
|
Line 72 SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
|
Line 76 SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
|
{ "usertrack.cookie-max-age", NULL, T_CONFIG_INT, T_CONFIG_SCOPE_CONNECTION }, /* 1 */ |
{ "usertrack.cookie-max-age", NULL, T_CONFIG_INT, T_CONFIG_SCOPE_CONNECTION }, /* 1 */ |
{ "usertrack.cookie-domain", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 2 */ |
{ "usertrack.cookie-domain", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 2 */ |
|
|
{ "usertrack.cookiename", NULL, T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_CONNECTION }, |
|
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } |
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } |
}; |
}; |
|
|
Line 81 SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
|
Line 84 SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
|
p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *)); |
p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *)); |
|
|
for (i = 0; i < srv->config_context->used; i++) { |
for (i = 0; i < srv->config_context->used; i++) { |
|
data_config const* config = (data_config const*)srv->config_context->data[i]; |
plugin_config *s; |
plugin_config *s; |
|
|
s = calloc(1, sizeof(plugin_config)); |
s = calloc(1, sizeof(plugin_config)); |
Line 94 SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
|
Line 98 SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
|
|
|
p->config_storage[i] = s; |
p->config_storage[i] = s; |
|
|
if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) { | if (0 != config_insert_values_global(srv, config->value, cv, i == 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION)) { |
return HANDLER_ERROR; |
return HANDLER_ERROR; |
} |
} |
|
|
if (buffer_is_empty(s->cookie_name)) { | if (buffer_string_is_empty(s->cookie_name)) { |
buffer_copy_string_len(s->cookie_name, CONST_STR_LEN("TRACKID")); |
buffer_copy_string_len(s->cookie_name, CONST_STR_LEN("TRACKID")); |
} else { |
} else { |
size_t j; | size_t j, len = buffer_string_length(s->cookie_name); |
for (j = 0; j < s->cookie_name->used - 1; j++) { | for (j = 0; j < len; j++) { |
char c = s->cookie_name->ptr[j] | 32; |
char c = s->cookie_name->ptr[j] | 32; |
if (c < 'a' || c > 'z') { |
if (c < 'a' || c > 'z') { |
log_error_write(srv, __FILE__, __LINE__, "sb", |
log_error_write(srv, __FILE__, __LINE__, "sb", |
Line 114 SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
|
Line 118 SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
|
} |
} |
} |
} |
|
|
if (!buffer_is_empty(s->cookie_domain)) { | if (!buffer_string_is_empty(s->cookie_domain)) { |
size_t j; | size_t j, len = buffer_string_length(s->cookie_domain); |
for (j = 0; j < s->cookie_domain->used - 1; j++) { | for (j = 0; j < len; j++) { |
char c = s->cookie_domain->ptr[j]; |
char c = s->cookie_domain->ptr[j]; |
if (c <= 32 || c >= 127 || c == '"' || c == '\\') { |
if (c <= 32 || c >= 127 || c == '"' || c == '\\') { |
log_error_write(srv, __FILE__, __LINE__, "sb", |
log_error_write(srv, __FILE__, __LINE__, "sb", |
Line 173 URIHANDLER_FUNC(mod_usertrack_uri_handler) {
|
Line 177 URIHANDLER_FUNC(mod_usertrack_uri_handler) {
|
data_string *ds; |
data_string *ds; |
unsigned char h[16]; |
unsigned char h[16]; |
li_MD5_CTX Md5Ctx; |
li_MD5_CTX Md5Ctx; |
char hh[32]; | char hh[LI_ITOSTRING_LENGTH]; |
|
|
if (con->uri.path->used == 0) return HANDLER_GO_ON; | if (buffer_is_empty(con->uri.path)) return HANDLER_GO_ON; |
|
|
mod_usertrack_patch_connection(srv, con, p); |
mod_usertrack_patch_connection(srv, con, p); |
|
|
Line 193 URIHANDLER_FUNC(mod_usertrack_uri_handler) {
|
Line 197 URIHANDLER_FUNC(mod_usertrack_uri_handler) {
|
char *nc; |
char *nc; |
|
|
/* skip WS */ |
/* skip WS */ |
for (nc = g + p->conf.cookie_name->used-1; *nc == ' ' || *nc == '\t'; nc++); | for (nc = g + buffer_string_length(p->conf.cookie_name); *nc == ' ' || *nc == '\t'; nc++); |
|
|
if (*nc == '=') { |
if (*nc == '=') { |
/* ok, found the key of our own cookie */ |
/* ok, found the key of our own cookie */ |
Line 211 URIHANDLER_FUNC(mod_usertrack_uri_handler) {
|
Line 215 URIHANDLER_FUNC(mod_usertrack_uri_handler) {
|
ds = data_response_init(); |
ds = data_response_init(); |
} |
} |
buffer_copy_string_len(ds->key, CONST_STR_LEN("Set-Cookie")); |
buffer_copy_string_len(ds->key, CONST_STR_LEN("Set-Cookie")); |
buffer_copy_string_buffer(ds->value, p->conf.cookie_name); | buffer_copy_buffer(ds->value, p->conf.cookie_name); |
buffer_append_string_len(ds->value, CONST_STR_LEN("=")); |
buffer_append_string_len(ds->value, CONST_STR_LEN("=")); |
|
|
|
|
Line 219 URIHANDLER_FUNC(mod_usertrack_uri_handler) {
|
Line 223 URIHANDLER_FUNC(mod_usertrack_uri_handler) {
|
|
|
/* generate shared-secret */ |
/* generate shared-secret */ |
li_MD5_Init(&Md5Ctx); |
li_MD5_Init(&Md5Ctx); |
li_MD5_Update(&Md5Ctx, (unsigned char *)con->uri.path->ptr, con->uri.path->used - 1); | li_MD5_Update(&Md5Ctx, CONST_BUF_LEN(con->uri.path)); |
li_MD5_Update(&Md5Ctx, (unsigned char *)"+", 1); | li_MD5_Update(&Md5Ctx, CONST_STR_LEN("+")); |
|
|
/* we assume sizeof(time_t) == 4 here, but if not it ain't a problem at all */ |
/* we assume sizeof(time_t) == 4 here, but if not it ain't a problem at all */ |
LI_ltostr(hh, srv->cur_ts); | li_itostrn(hh, sizeof(hh), srv->cur_ts); |
li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh)); |
li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh)); |
li_MD5_Update(&Md5Ctx, (unsigned char *)srv->entropy, sizeof(srv->entropy)); |
li_MD5_Update(&Md5Ctx, (unsigned char *)srv->entropy, sizeof(srv->entropy)); |
LI_ltostr(hh, rand()); | li_itostrn(hh, sizeof(hh), rand()); |
li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh)); |
li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh)); |
|
|
li_MD5_Final(h, &Md5Ctx); |
li_MD5_Final(h, &Md5Ctx); |
Line 235 URIHANDLER_FUNC(mod_usertrack_uri_handler) {
|
Line 239 URIHANDLER_FUNC(mod_usertrack_uri_handler) {
|
buffer_append_string_len(ds->value, CONST_STR_LEN("; Path=/")); |
buffer_append_string_len(ds->value, CONST_STR_LEN("; Path=/")); |
buffer_append_string_len(ds->value, CONST_STR_LEN("; Version=1")); |
buffer_append_string_len(ds->value, CONST_STR_LEN("; Version=1")); |
|
|
if (!buffer_is_empty(p->conf.cookie_domain)) { | if (!buffer_string_is_empty(p->conf.cookie_domain)) { |
buffer_append_string_len(ds->value, CONST_STR_LEN("; Domain=")); |
buffer_append_string_len(ds->value, CONST_STR_LEN("; Domain=")); |
buffer_append_string_encoded(ds->value, CONST_BUF_LEN(p->conf.cookie_domain), ENCODING_REL_URI); |
buffer_append_string_encoded(ds->value, CONST_BUF_LEN(p->conf.cookie_domain), ENCODING_REL_URI); |
} |
} |
|
|
if (p->conf.cookie_max_age) { |
if (p->conf.cookie_max_age) { |
buffer_append_string_len(ds->value, CONST_STR_LEN("; max-age=")); |
buffer_append_string_len(ds->value, CONST_STR_LEN("; max-age=")); |
buffer_append_long(ds->value, p->conf.cookie_max_age); | buffer_append_int(ds->value, p->conf.cookie_max_age); |
} |
} |
|
|
array_insert_unique(con->response.headers, (data_unset *)ds); |
array_insert_unique(con->response.headers, (data_unset *)ds); |