bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen#include "lib.h"
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen#include "auth-master.h"
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen#include "replicator-queue.h"
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen#define REPLICATOR_AUTH_SERVICE_NAME "replicator"
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainenvoid replicator_queue_add_auth_users(struct replicator_queue *queue,
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen const char *auth_socket_path,
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen const char *usermask, time_t last_update)
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen{
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen struct auth_master_connection *auth_conn;
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen struct auth_master_user_list_ctx *ctx;
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen struct auth_user_info user_info;
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen struct replicator_user *user;
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen const char *username;
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen auth_conn = auth_master_init(auth_socket_path,
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen AUTH_MASTER_FLAG_NO_IDLE_TIMEOUT);
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch i_zero(&user_info);
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen user_info.service = REPLICATOR_AUTH_SERVICE_NAME;
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen /* add all users into replication queue, so that we can start doing
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen full syncs for everyone whose state can't be found */
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen ctx = auth_master_user_list_init(auth_conn, usermask, &user_info);
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen while ((username = auth_master_user_list_next(ctx)) != NULL) {
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen user = replicator_queue_add(queue, username,
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen REPLICATION_PRIORITY_NONE);
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen user->last_update = last_update;
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen }
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen if (auth_master_user_list_deinit(&ctx) < 0)
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen i_error("listing users failed, can't replicate existing data");
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen auth_master_deinit(&auth_conn);
f59c16625dc8fb1b734fddbba58012ec42cf945dTimo Sirainen}