#include "hex-binary.h"
#include "ioloop.h"
#include "ostream.h"
+#include "wildcard-match.h"
#include "ipwd.h"
#include "master-service.h"
#include "userdb.h"
return 1;
}
+static int match_user(const char *user, struct auth_request *request, bool *match_r)
+{
+ struct auth_userdb *db = request->userdb;
+ const char *mask = request->fields.user;
+
+ if (*db->auth_set->username_format != '\0') {
+ /* normalize requested mask to match userdb */
+ string_t *dest = t_str_new(32);
+ const char *error;
+ if (auth_request_var_expand(dest, db->auth_set->username_format,
+ request, NULL, &error) < 0) {
+ e_error(authdb_event(request), "Iteration failed: %s",
+ error);
+ return -1;
+ }
+ mask = str_c(dest);
+ }
+
+ *match_r = wildcard_match_icase(user, mask);
+ return 0;
+}
+
static void master_input_list_callback(const char *user, void *context)
{
struct master_list_iter_ctx *ctx = context;
struct auth_userdb *userdb = ctx->auth_request->userdb;
- int ret;
+ int ret = 0;
- if (user == NULL) {
+ if (user == NULL || ctx->failed) {
if (userdb_blocking_iter_deinit(&ctx->iter) < 0)
ctx->failed = TRUE;
userdb = userdb->next;
} while (userdb != NULL &&
userdb->userdb->iface->iterate_init == NULL);
- if (userdb == NULL) {
+ if (userdb == NULL || ctx->failed) {
/* iteration is finished */
const char *str;
T_BEGIN {
const char *str;
-
- str = t_strdup_printf("LIST\t%u\t%s\n", ctx->auth_request->id,
- str_tabescape(user));
- ret = o_stream_send_str(ctx->conn->conn.output, str);
+ bool match;
+ if (match_user(user, ctx->auth_request, &match) < 0)
+ ctx->failed = TRUE;
+ else if (match) {
+ str = t_strdup_printf("LIST\t%u\t%s\n", ctx->auth_request->id,
+ str_tabescape(user));
+ ret = o_stream_send_str(ctx->conn->conn.output, str);
+ }
} T_END;
if (o_stream_get_buffer_used_size(ctx->conn->conn.output) >= MAX_OUTBUF_SIZE)
ret = o_stream_flush(ctx->conn->conn.output);
#include "str.h"
#include "strescape.h"
#include "var-expand.h"
-#include "wildcard-match.h"
#include "dsasl-client.h"
#include "settings-parser.h"
#include "master-service.h"
ctx = auth_master_user_list_init(conn, user_mask, &input->info);
while ((username = auth_master_user_list_next(ctx)) != NULL) {
- for (i = 0; users[i] != NULL; i++) {
- if (wildcard_match_icase(username, users[i]))
- break;
- }
- if (users[i] != NULL)
+ for (i = 0; users[i] != NULL; i++)
printf("%s\n", username);
}
if (auth_master_user_list_deinit(&ctx) < 0)