Ejemplo n.º 1
0
static enum passdb_result
passdb_dict_lookup_key(struct auth_request *auth_request,
                       struct dict_passdb_module *module)
{
    struct db_dict_value_iter *iter;
    int ret;

    ret = db_dict_value_iter_init(module->conn, auth_request,
    &module->conn->set.passdb_fields,
    &module->conn->set.parsed_passdb_objects,
    &iter);
    if (ret < 0)
        return PASSDB_RESULT_INTERNAL_FAILURE;
    else if (ret == 0) {
        auth_request_log_unknown_user(auth_request, AUTH_SUBSYS_DB);
        return PASSDB_RESULT_USER_UNKNOWN;
    } else {
        if (dict_query_save_results(auth_request, module->conn, iter) < 0)
            return PASSDB_RESULT_INTERNAL_FAILURE;

        if (auth_request->passdb_password == NULL &&
        !auth_fields_exists(auth_request->extra_fields, "nopassword")) {
            auth_request_log_info(auth_request, AUTH_SUBSYS_DB,
            "No password returned (and no nopassword)");
            return PASSDB_RESULT_PASSWORD_MISMATCH;
        } else {
            return PASSDB_RESULT_OK;
        }
    }
}
Ejemplo n.º 2
0
static void userdb_dict_lookup(struct auth_request *auth_request,
			       userdb_callback_t *callback)
{
	struct userdb_module *_module = auth_request->userdb->userdb;
	struct dict_userdb_module *module =
		(struct dict_userdb_module *)_module;
	struct db_dict_value_iter *iter;
	enum userdb_result userdb_result;
	int ret;

	if (array_count(&module->conn->set.userdb_fields) == 0 &&
	    array_count(&module->conn->set.parsed_userdb_objects) == 0) {
		auth_request_log_error(auth_request, AUTH_SUBSYS_DB,
			"No userdb_objects or userdb_fields specified");
		callback(USERDB_RESULT_INTERNAL_FAILURE, auth_request);
		return;
	}

	ret = db_dict_value_iter_init(module->conn, auth_request,
				      &module->conn->set.userdb_fields,
				      &module->conn->set.parsed_userdb_objects,
				      &iter);
	if (ret < 0)
		userdb_result = USERDB_RESULT_INTERNAL_FAILURE;
	else if (ret == 0) {
		auth_request_log_unknown_user(auth_request, AUTH_SUBSYS_DB);
		userdb_result = USERDB_RESULT_USER_UNKNOWN;
	} else {
		if (dict_query_save_results(auth_request, iter) < 0)
			userdb_result = USERDB_RESULT_INTERNAL_FAILURE;
		else
			userdb_result = USERDB_RESULT_OK;
 	}
	callback(userdb_result, auth_request);
}
Ejemplo n.º 3
0
static int
dict_query_save_results(struct auth_request *auth_request,
			struct dict_connection *conn, const char *result)
{
	struct db_dict_value_iter *iter;
	const char *key, *value, *error;

	iter = db_dict_value_iter_init(conn, result);
	while (db_dict_value_iter_next(iter, &key, &value)) {
		if (value != NULL) {
			auth_request_set_field(auth_request, key, value,
					       conn->set.default_pass_scheme);
		}
	}
	if (db_dict_value_iter_deinit(&iter, &error) < 0) {
		auth_request_log_error(auth_request, "dict",
			"Value '%s' not in valid %s format: %s",
			result, conn->set.value_format, error);
		return -1;
	}
	return 0;
}