<commit_before>/* Copyright (c) 2005-2013 Dovecot authors, see the included COPYING file */

#include "auth-common.h"
#include "str.h"
#include "auth-worker-server.h"
#include "userdb.h"
#include "userdb-blocking.h"

#include <stdlib.h>

struct blocking_userdb_iterate_context {
	struct userdb_iterate_context ctx;
	struct auth_worker_connection *conn;
	bool next;
	bool destroyed;
};

static bool user_callback(const char *reply, void *context)
{
	struct auth_request *request = context;
	enum userdb_result result;
	const char *args;

	if (strncmp(reply, "FAIL\t", 5) == 0) {
		result = USERDB_RESULT_INTERNAL_FAILURE;
		args = reply + 5;
	} else if (strncmp(reply, "NOTFOUND\t", 9) == 0) {
		result = USERDB_RESULT_USER_UNKNOWN;
		args = reply + 9;
	} else if (strncmp(reply, "OK\t", 3) == 0) {
		result = USERDB_RESULT_OK;
		args = reply + 3;
	} else {
		result = USERDB_RESULT_INTERNAL_FAILURE;
		i_error("BUG: auth-worker sent invalid user reply");
		args = "";
	}

	if (*args != '\0') {
		request->userdb_reply = auth_fields_init(request->pool);
		auth_fields_import(request->userdb_reply, args, 0);
		if (auth_fields_exists(request->userdb_reply, "tempfail"))
			request->userdb_lookup_failed = TRUE;
	}

        auth_request_userdb_callback(result, request);
	auth_request_unref(&request);
	return TRUE;
}

void userdb_blocking_lookup(struct auth_request *request)
{
	string_t *str;<commit_msg>auth: If blocking userdb returns no fields, don't crash when trying to cache the result.<commit_after>/* Copyright (c) 2005-2013 Dovecot authors, see the included COPYING file */

#include "auth-common.h"
#include "str.h"
#include "auth-worker-server.h"
#include "userdb.h"
#include "userdb-blocking.h"

#include <stdlib.h>

struct blocking_userdb_iterate_context {
	struct userdb_iterate_context ctx;
	struct auth_worker_connection *conn;
	bool next;
	bool destroyed;
};

static bool user_callback(const char *reply, void *context)
{
	struct auth_request *request = context;
	enum userdb_result result;
	const char *args;

	if (strncmp(reply, "FAIL\t", 5) == 0) {
		result = USERDB_RESULT_INTERNAL_FAILURE;
		args = reply + 5;
	} else if (strncmp(reply, "NOTFOUND\t", 9) == 0) {
		result = USERDB_RESULT_USER_UNKNOWN;
		args = reply + 9;
	} else if (strncmp(reply, "OK\t", 3) == 0) {
		result = USERDB_RESULT_OK;
		args = reply + 3;
	} else {
		result = USERDB_RESULT_INTERNAL_FAILURE;
		i_error("BUG: auth-worker sent invalid user reply");
		args = "";
	}

	request->userdb_reply = auth_fields_init(request->pool);
	if (*args != '\0') {
		auth_fields_import(request->userdb_reply, args, 0);
		if (auth_fields_exists(request->userdb_reply, "tempfail"))
			request->userdb_lookup_failed = TRUE;
	}

        auth_request_userdb_callback(result, request);
	auth_request_unref(&request);
	return TRUE;
}

void userdb_blocking_lookup(struct auth_request *request)
{
	string_t *str;
{'fraction_non_alphanumeric': 0.12777777777777777, 'fraction_numerical': 0.013194444444444444, 'mean_word_length': 4.9402061855670105, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6116180', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1029, 'n_words': 249}