Skip to content

Commit

Permalink
lib-storage: Moved connection information in struct mail_user into se…
Browse files Browse the repository at this point in the history
…parate struct mail_user_connection_data.
  • Loading branch information
stephanbosch authored and sirainen committed Dec 11, 2017
1 parent 2ded32b commit 6067018
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/imap/cmd-idle.c
Expand Up @@ -169,7 +169,7 @@ static void idle_add_keepalive_timeout(struct cmd_idle_context *ctx)
return;

interval = imap_keepalive_interval_msecs(client->user->username,
client->user->remote_ip,
client->user->conn.remote_ip,
interval);

timeout_remove(&ctx->keepalive_to);
Expand Down
8 changes: 4 additions & 4 deletions src/imap/imap-client-hibernate.c
Expand Up @@ -69,10 +69,10 @@ static void imap_hibernate_write_cmd(struct client *client, string_t *cmd,
str_printfa(cmd, "\tsession_created=%s",
dec2str(user->session_create_time));
}
if (user->local_ip != NULL)
str_printfa(cmd, "\tlip=%s", net_ip2addr(user->local_ip));
if (user->remote_ip != NULL)
str_printfa(cmd, "\trip=%s", net_ip2addr(user->remote_ip));
if (user->conn.local_ip != NULL)
str_printfa(cmd, "\tlip=%s", net_ip2addr(user->conn.local_ip));
if (user->conn.remote_ip != NULL)
str_printfa(cmd, "\trip=%s", net_ip2addr(user->conn.remote_ip));
if (client->userdb_fields != NULL) {
string_t *userdb_fields = t_str_new(256);
unsigned int i;
Expand Down
5 changes: 3 additions & 2 deletions src/imap/main.c
Expand Up @@ -66,9 +66,10 @@ void imap_refresh_proctitle(void)
case 1:
client = imap_clients;
str_append(title, client->user->username);
if (client->user->remote_ip != NULL) {
if (client->user->conn.remote_ip != NULL) {
str_append_c(title, ' ');
str_append(title, net_ip2addr(client->user->remote_ip));
str_append(title,
net_ip2addr(client->user->conn.remote_ip));
}
wait_output = FALSE;
for (cmd = client->command_queue; cmd != NULL; cmd = cmd->next) {
Expand Down
30 changes: 15 additions & 15 deletions src/lib-storage/mail-user.c
Expand Up @@ -235,12 +235,12 @@ void mail_user_set_vars(struct mail_user *user, const char *service,

user->service = p_strdup(user->pool, service);
if (local_ip != NULL && local_ip->family != 0) {
user->local_ip = p_new(user->pool, struct ip_addr, 1);
*user->local_ip = *local_ip;
user->conn.local_ip = p_new(user->pool, struct ip_addr, 1);
*user->conn.local_ip = *local_ip;
}
if (remote_ip != NULL && remote_ip->family != 0) {
user->remote_ip = p_new(user->pool, struct ip_addr, 1);
*user->remote_ip = *remote_ip;
user->conn.remote_ip = p_new(user->pool, struct ip_addr, 1);
*user->conn.remote_ip = *remote_ip;
}
}

Expand All @@ -255,10 +255,10 @@ mail_user_var_expand_table(struct mail_user *user)
const char *username =
p_strdup(user->pool, t_strcut(user->username, '@'));
const char *domain = i_strchr_to_next(user->username, '@');
const char *local_ip = user->local_ip == NULL ? NULL :
p_strdup(user->pool, net_ip2addr(user->local_ip));
const char *remote_ip = user->remote_ip == NULL ? NULL :
p_strdup(user->pool, net_ip2addr(user->remote_ip));
const char *local_ip = user->conn.local_ip == NULL ? NULL :
p_strdup(user->pool, net_ip2addr(user->conn.local_ip));
const char *remote_ip = user->conn.remote_ip == NULL ? NULL :
p_strdup(user->pool, net_ip2addr(user->conn.remote_ip));

const char *auth_user, *auth_username, *auth_domain;
if (user->auth_user == NULL) {
Expand Down Expand Up @@ -376,10 +376,10 @@ static int mail_user_userdb_lookup_home(struct mail_user *user)

i_zero(&info);
info.service = user->service;
if (user->local_ip != NULL)
info.local_ip = *user->local_ip;
if (user->remote_ip != NULL)
info.remote_ip = *user->remote_ip;
if (user->conn.local_ip != NULL)
info.local_ip = *user->conn.local_ip;
if (user->conn.remote_ip != NULL)
info.remote_ip = *user->conn.remote_ip;

userdb_pool = pool_alloconly_create("userdb lookup", 2048);
ret = auth_master_user_lookup(mail_user_auth_master_conn,
Expand Down Expand Up @@ -586,9 +586,9 @@ int mail_user_lock_file_create(struct mail_user *user, const char *lock_fname,

const char *mail_user_get_anvil_userip_ident(struct mail_user *user)
{
if (user->remote_ip == NULL)
if (user->conn.remote_ip == NULL)
return NULL;
return t_strconcat(net_ip2addr(user->remote_ip), "/",
return t_strconcat(net_ip2addr(user->conn.remote_ip), "/",
str_tabescape(user->username), NULL);
}

Expand Down Expand Up @@ -658,7 +658,7 @@ struct mail_user *mail_user_dup(struct mail_user *user)
if (user->_home != NULL)
mail_user_set_home(user2, user->_home);
mail_user_set_vars(user2, user->service,
user->local_ip, user->remote_ip);
user->conn.local_ip, user->conn.remote_ip);
user2->uid = user->uid;
user2->gid = user->gid;
user2->anonymous = user->anonymous;
Expand Down
7 changes: 6 additions & 1 deletion src/lib-storage/mail-user.h
@@ -1,6 +1,7 @@
#ifndef MAIL_USER_H
#define MAIL_USER_H

#include "net.h"
#include "unichar.h"
#include "mail-storage-settings.h"

Expand All @@ -16,6 +17,10 @@ struct mail_user_vfuncs {
void (*stats_fill)(struct mail_user *user, struct stats *stats);
};

struct mail_user_connection_data {
struct ip_addr *local_ip, *remote_ip;
};

struct mail_user {
pool_t pool;
struct mail_user_vfuncs v, *vlast;
Expand All @@ -35,7 +40,7 @@ struct mail_user {
gid_t gid;
const char *service;
const char *session_id;
struct ip_addr *local_ip, *remote_ip;
struct mail_user_connection_data conn;
const char *auth_token, *auth_user;
const char *const *userdb_fields;
/* Timestamp when this session was initially created. Most importantly
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/stats/mail-stats-connection.c
Expand Up @@ -27,13 +27,13 @@ int mail_stats_connection_connect(struct stats_connection *conn,
str_printfa(str, "\t%s", my_pid);

/* optional fields */
if (user->local_ip != NULL) {
if (user->conn.local_ip != NULL) {
str_append(str, "\tlip=");
str_append(str, net_ip2addr(user->local_ip));
str_append(str, net_ip2addr(user->conn.local_ip));
}
if (user->remote_ip != NULL) {
if (user->conn.remote_ip != NULL) {
str_append(str, "\trip=");
str_append(str, net_ip2addr(user->remote_ip));
str_append(str, net_ip2addr(user->conn.remote_ip));
}
str_append_c(str, '\n');
return stats_connection_send(conn, str);
Expand Down
5 changes: 3 additions & 2 deletions src/pop3/main.c
Expand Up @@ -57,9 +57,10 @@ void pop3_refresh_proctitle(void)
case 1:
client = pop3_clients;
str_append(title, client->user->username);
if (client->user->remote_ip != NULL) {
if (client->user->conn.remote_ip != NULL) {
str_append_c(title, ' ');
str_append(title, net_ip2addr(client->user->remote_ip));
str_append(title,
net_ip2addr(client->user->conn.remote_ip));
}
if (client->destroyed)
str_append(title, " (deinit)");
Expand Down

0 comments on commit 6067018

Please sign in to comment.