Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2025 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or modify it under the
6 : terms of the GNU General Public License as published by the Free Software
7 : Foundation; either version 3, or (at your option) any later version.
8 :
9 : TALER is distributed in the hope that it will be useful, but WITHOUT ANY
10 : WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 : A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 :
13 : You should have received a copy of the GNU General Public License along with
14 : TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
15 : */
16 : /**
17 : * @file src/backenddb/do_solve_mfa_challenge.c
18 : * @brief Implementation of the do_solve_mfa_challenge function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "platform.h"
22 : #include <taler/taler_pq_lib.h>
23 : #include "taler/taler_merchant_util.h"
24 : #include "merchant-database/do_solve_mfa_challenge.h"
25 : #include "helper.h"
26 :
27 :
28 : enum GNUNET_DB_QueryStatus
29 16 : TALER_MERCHANTDB_do_solve_mfa_challenge (
30 : struct TALER_MERCHANTDB_PostgresContext *pg,
31 : uint64_t challenge_id,
32 : const struct TALER_MERCHANT_MFA_BodyHash *h_body,
33 : const char *solution,
34 : bool *solved,
35 : uint32_t *retry_counter)
36 : {
37 16 : struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
38 : bool no_match;
39 16 : struct GNUNET_PQ_QueryParam params[] = {
40 16 : GNUNET_PQ_query_param_uint64 (&challenge_id),
41 16 : GNUNET_PQ_query_param_auto_from_type (h_body),
42 16 : GNUNET_PQ_query_param_string (solution),
43 16 : GNUNET_PQ_query_param_absolute_time (&now),
44 : GNUNET_PQ_query_param_end
45 : };
46 16 : struct GNUNET_PQ_ResultSpec rs[] = {
47 16 : GNUNET_PQ_result_spec_bool ("out_solved",
48 : solved),
49 16 : GNUNET_PQ_result_spec_allow_null (
50 : GNUNET_PQ_result_spec_uint32 ("out_retry_counter",
51 : retry_counter),
52 : &no_match),
53 : GNUNET_PQ_result_spec_end
54 : };
55 : enum GNUNET_DB_QueryStatus qs;
56 :
57 : /* conservatively set security-relevant return values to
58 : safe values, even though these should not be used with qs <= 0 */
59 16 : *solved = false;
60 16 : *retry_counter = 0;
61 16 : TMH_PQ_prepare_anon (pg,
62 : "SELECT"
63 : " out_solved"
64 : " ,out_retry_counter"
65 : " FROM merchant.merchant_do_solve_mfa_challenge"
66 : " ($1, $2, $3, $4);");
67 16 : qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
68 : "",
69 : params,
70 : rs);
71 16 : if (qs <= 0)
72 0 : return qs;
73 16 : if (no_match)
74 : {
75 2 : GNUNET_PQ_cleanup_result (rs);
76 2 : return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
77 : }
78 14 : GNUNET_PQ_cleanup_result (rs);
79 14 : return qs;
80 : }
|