mail_user->auth_user = p_strdup(mail_user->pool, user->auth_user);
mail_user->session_id =
p_strdup(mail_user->pool, user->input.session_id);
+ mail_user->userdb_fields = user->input.userdb_fields == NULL ? NULL :
+ p_strarray_dup(mail_user->pool, user->input.userdb_fields);
mail_set = mail_user_set_get_storage_set(mail_user);
i_set_failure_prefix("%s", ctx->default_log_prefix);
}
+static const char *
+mail_storage_service_input_var_userdb(const char *data, void *context)
+{
+ struct mail_storage_service_user *user = context;
+ const char *field_name = data;
+ unsigned int i, field_name_len;
+
+ if (user == NULL || user->input.userdb_fields == NULL)
+ return NULL;
+
+ field_name_len = strlen(field_name);
+ for (i = 0; user->input.userdb_fields[i] != NULL; i++) {
+ if (strncmp(user->input.userdb_fields[i], field_name,
+ field_name_len) == 0 &&
+ user->input.userdb_fields[i][field_name_len] == '=')
+ return user->input.userdb_fields[i] + field_name_len+1;
+ }
+ return NULL;
+}
+
+static void
+mail_storage_service_var_expand(struct mail_storage_service_ctx *ctx,
+ string_t *str, const char *format,
+ struct mail_storage_service_user *user,
+ const struct mail_storage_service_input *input,
+ const struct mail_storage_service_privileges *priv)
+{
+ static const struct var_expand_func_table func_table[] = {
+ { "userdb", mail_storage_service_input_var_userdb },
+ { NULL, NULL }
+ };
+ var_expand_with_funcs(str, format,
+ get_var_expand_table(ctx->service, user, input, priv),
+ func_table, user);
+}
+
static void
mail_storage_service_init_log(struct mail_storage_service_ctx *ctx,
struct mail_storage_service_user *user,
string_t *str;
str = t_str_new(256);
- var_expand(str, user->user_set->mail_log_prefix,
- get_var_expand_table(ctx->service, user, &user->input, priv));
+ mail_storage_service_var_expand(ctx, str,
+ user->user_set->mail_log_prefix,
+ user, &user->input, priv);
user->log_prefix = p_strdup(user->pool, str_c(str));
} T_END;
string_t *str;
str = t_str_new(256);
- var_expand(str, user_set->mail_log_prefix,
- get_var_expand_table(ctx->service, user, input, priv));
+ mail_storage_service_var_expand(ctx, str, user_set->mail_log_prefix,
+ user, input, priv);
i_set_failure_prefix("%s", str_c(str));
}
user->service_ctx = ctx;
user->pool = user_pool;
user->input = *input;
- user->input.userdb_fields = NULL;
+ user->input.userdb_fields = userdb_fields == NULL ? NULL :
+ p_strarray_dup(user_pool, userdb_fields);
user->input.username = p_strdup(user_pool, username);
user->input.session_id = p_strdup(user_pool, input->session_id);
if (user->input.session_id == NULL) {
return;
}
str_truncate(str, 0);
- var_expand(str, envs[i+1], mail_user_var_expand_table(user));
+ var_expand_with_funcs(str, envs[i+1],
+ mail_user_var_expand_table(user),
+ mail_user_var_expand_func_table, user);
envs[i+1] = p_strdup(user->pool, str_c(str));
}
}
'h', "home", &key, &value);
/* expand mail_home setting before calling mail_user_get_home() */
- settings_var_expand(user->set_info, user->set,
- user->pool, mail_user_var_expand_table(user));
+ settings_var_expand_with_funcs(user->set_info, user->set,
+ user->pool, mail_user_var_expand_table(user),
+ mail_user_var_expand_func_table, user);
if (need_home_dir && mail_user_get_home(user, &home) <= 0) {
user->error = p_strdup_printf(user->pool,
return user->var_expand_table;
}
+static const char *
+mail_user_var_expand_func_userdb(const char *data, void *context)
+{
+ struct mail_user *user = context;
+ const char *field_name = data;
+ unsigned int i, field_name_len;
+
+ if (user->userdb_fields == NULL)
+ return NULL;
+
+ field_name_len = strlen(field_name);
+ for (i = 0; user->userdb_fields[i] != NULL; i++) {
+ if (strncmp(user->userdb_fields[i], field_name,
+ field_name_len) == 0 &&
+ user->userdb_fields[i][field_name_len] == '=')
+ return user->userdb_fields[i] + field_name_len+1;
+ }
+ return NULL;
+}
+
void mail_user_set_home(struct mail_user *user, const char *home)
{
user->_home = p_strdup(user->pool, home);
{
user->v.stats_fill(user, stats);
}
+
+static const struct var_expand_func_table mail_user_var_expand_func_table_arr[] = {
+ { "userdb", mail_user_var_expand_func_userdb },
+ { NULL, NULL }
+};
+const struct var_expand_func_table *mail_user_var_expand_func_table =
+ mail_user_var_expand_func_table_arr;
const char *session_id;
struct ip_addr *local_ip, *remote_ip;
const char *auth_token, *auth_user;
+ const char *const *userdb_fields;
const struct var_expand_table *var_expand_table;
/* If non-NULL, fail the user initialization with this error.
};
extern struct mail_user_module_register mail_user_module_register;
extern struct auth_master_connection *mail_user_auth_master_conn;
+extern const struct var_expand_func_table *mail_user_var_expand_func_table;
struct mail_user *mail_user_alloc(const char *username,
const struct setting_parser_info *set_info,