/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "array.h"
#include "askpass.h"
#include "base64.h"
#include "hex-binary.h"
#include "str.h"
#include "var-expand.h"
#include "wildcard-match.h"
#include "settings-parser.h"
#include "master-service.h"
#include "master-service-settings.h"
#include "auth-client.h"
#include "auth-master.h"
#include "auth-server-connection.h"
#include "master-auth.h"
#include "master-login-auth.h"
#include "mail-storage-service.h"
#include "mail-user.h"
#include "doveadm.h"
#include "doveadm-print.h"
#include <stdio.h>
#include <unistd.h>
struct authtest_input {
const char *username;
const char *master_user;
const char *password;
bool success;
unsigned int auth_id;
unsigned int auth_pid;
const char *auth_cookie;
};
static struct auth_master_connection *
{
if (doveadm_debug)
}
static int
const struct authtest_input *input,
const char *show_field, bool userdb)
{
int ret;
if (userdb) {
} else {
}
if (ret < 0) {
else {
}
ret = -1;
} else if (ret == 0) {
"%s: user %s doesn't exist\n", lookup_name,
} else if (show_field != NULL) {
}
} else {
if (updated_username != NULL)
if (p == NULL)
else {
printf(" %-10s: %s\n",
}
}
}
return ret;
}
static void
enum auth_request_status status,
const char *data_base64 ATTR_UNUSED,
{
if (!io_loop_is_running(current_ioloop))
return;
if (status == 0)
i_fatal("passdb expects SASL continuation");
switch (status) {
i_unreached();
case AUTH_REQUEST_STATUS_FAIL:
break;
printf("passdb: %s auth unexpectedly requested continuation\n",
break;
case AUTH_REQUEST_STATUS_OK:
break;
}
printf("extra fields:\n");
}
}
{
if (!connected)
i_fatal("Couldn't connect to auth socket");
else
if (doveadm_settings->auth_debug)
}
static void
{
if (auth_socket_path == NULL) {
"/auth-client", NULL);
}
}
{
i_fatal("lip: Invalid ip");
i_fatal("rip: Invalid ip");
i_fatal("lport: Invalid port number");
i_fatal("rport: Invalid port number");
} else {
}
}
static void
const struct authtest_input *input,
char *const *users)
{
unsigned int i;
break;
}
}
if (auth_master_user_list_deinit(&ctx) < 0)
i_fatal("user listing failed");
}
{
unsigned int count;
int c;
switch (c) {
case 'a':
break;
default:
}
}
if (master_socket_path == NULL) {
"/auth-master", NULL);
}
i_error("Cache flush failed");
} else {
}
}
{
}
{
int c;
switch (c) {
case 'a':
break;
case 'M':
break;
case 'x':
break;
default:
}
}
t_askpass("Password: ");
}
static void
{
unsigned int i;
return;
}
printf("userdb extra fields:\n");
}
static void
struct authtest_input *input)
{
sizeof(master_auth_req.cookie));
}
{
int c;
"/auth-login", NULL);
"/auth-master", NULL);
switch (c) {
case 'a':
break;
case 'm':
break;
case 'M':
break;
case 'x':
break;
default:
}
}
t_askpass("Password: ");
/* authenticate */
/* finish login with userdb lookup */
}
{
int c, ret;
switch (c) {
case 'a':
break;
case 'f':
show_field = optarg;
break;
case 'x':
break;
default:
}
}
if (first)
else
putchar('\n');
switch (ret) {
case -1:
break;
case 0:
break;
}
}
}
const char *show_field)
{
if (show_field == NULL) {
}
}
static void
const char *const *userdb_fields,
const char *show_field)
{
unsigned int i;
if (userdb_fields != NULL) {
for (i = 0; userdb_fields[i] != NULL; i++) {
else {
key = userdb_fields[i];
value = "";
}
}
}
}
static int
const struct authtest_input *input,
const char *show_field, const char *expand_field)
{
int ret;
&service_user, &user,
&error)) <= 0) {
pool_unref(&pool);
if (ret < 0)
return -1;
"\nuserdb lookup: user %s doesn't exist\n",
return 0;
}
if (expand_field == NULL)
else {
&error) <= 0) {
} else {
}
}
pool_unref(&pool);
return 1;
}
{
unsigned int i;
int c, ret;
switch (c) {
case 'a':
break;
case 'e':
break;
case 'f':
show_field = optarg;
break;
case 'u':
userdb_only = TRUE;
break;
case 'x':
break;
default:
}
}
i_error("-e can't be used with -u");
return;
}
i_error("-e can't be used with -f");
return;
}
break;
}
}
if (have_wildcards) {
return;
}
if (!userdb_only) {
doveadm_print_header_simple("field");
doveadm_print_header_simple("value");
}
}
if (first)
else
putchar('\n');
ret = !userdb_only ?
switch (ret) {
case -1:
break;
case 0:
break;
}
}
if (storage_service != NULL)
}
{ cmd_auth_test, "auth test",
"[-a <auth socket path>] [-x <auth info>] [-M <master user>] <user> [<password>]" },
{ cmd_auth_login, "auth login",
"[-a <auth-login socket path>] [-m <auth-master socket path>] [-x <auth info>] [-M <master user>] <user> [<password>]" },
{ cmd_auth_lookup, "auth lookup",
"[-a <userdb socket path>] [-x <auth info>] [-f field] <user> [...]" },
{ cmd_auth_cache_flush, "auth cache flush",
"[-a <master socket path>] [<user> [...]]" },
{ cmd_user, "user",
"[-a <userdb socket path>] [-x <auth info>] [-f field] [-e <value>] [-u] <user mask> [...]" }
};
{
unsigned int i;
for (i = 0; i < N_ELEMENTS(doveadm_cmd_auth); i++) {
help(&doveadm_cmd_auth[i]);
}
i_unreached();
}
void doveadm_register_auth_commands(void)
{
unsigned int i;
for (i = 0; i < N_ELEMENTS(doveadm_cmd_auth); i++)
}