challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

pg_challenge_set_address_and_pin.c (4172B)


      1 /*
      2    This file is part of Challenger
      3    Copyright (C) 2023 Taler Systems SA
      4 
      5    Challenger 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    Challenger 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    Challenger; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 /**
     17  * @file challengerdb/pg_challenge_set_address_and_pin.c
     18  * @brief Implementation of the challenge_set_address_and_pin function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_error_codes.h>
     23 #include <taler/taler_dbevents.h>
     24 #include <taler/taler_pq_lib.h>
     25 #include "pg_challenge_set_address_and_pin.h"
     26 #include "pg_helper.h"
     27 
     28 
     29 enum GNUNET_DB_QueryStatus
     30 CH_PG_challenge_set_address_and_pin (
     31   void *cls,
     32   const struct CHALLENGER_ValidationNonceP *nonce,
     33   const json_t *address,
     34   struct GNUNET_TIME_Relative validation_duration,
     35   uint32_t *tan,
     36   char **state,
     37   struct GNUNET_TIME_Absolute *last_tx_time,
     38   uint32_t *auth_attempts_left,
     39   bool *pin_transmit,
     40   char **client_redirect_uri,
     41   bool *address_refused,
     42   bool *solved)
     43 {
     44   struct PostgresClosure *pg = cls;
     45   struct GNUNET_TIME_Absolute now
     46     = GNUNET_TIME_absolute_get ();
     47   struct GNUNET_TIME_Absolute next_tx_time
     48     = GNUNET_TIME_absolute_subtract (now,
     49                                      validation_duration);
     50   struct GNUNET_PQ_QueryParam params[] = {
     51     GNUNET_PQ_query_param_auto_from_type (nonce),
     52     TALER_PQ_query_param_json (address),
     53     GNUNET_PQ_query_param_absolute_time (&next_tx_time),
     54     GNUNET_PQ_query_param_absolute_time (&now),
     55     GNUNET_PQ_query_param_uint32 (tan),
     56     GNUNET_PQ_query_param_end
     57   };
     58   bool not_found;
     59   struct GNUNET_PQ_ResultSpec rs[] = {
     60     GNUNET_PQ_result_spec_bool ("not_found",
     61                                 &not_found),
     62     GNUNET_PQ_result_spec_absolute_time ("last_tx_time",
     63                                          last_tx_time),
     64     GNUNET_PQ_result_spec_uint32 ("last_pin",
     65                                   tan),
     66     GNUNET_PQ_result_spec_bool ("pin_transmit",
     67                                 pin_transmit),
     68     GNUNET_PQ_result_spec_uint32 ("auth_attempts_left",
     69                                   auth_attempts_left),
     70     GNUNET_PQ_result_spec_allow_null (
     71       GNUNET_PQ_result_spec_string ("client_redirect_uri",
     72                                     client_redirect_uri),
     73       NULL),
     74     GNUNET_PQ_result_spec_allow_null (
     75       GNUNET_PQ_result_spec_string ("state",
     76                                     state),
     77       NULL),
     78     GNUNET_PQ_result_spec_bool ("address_refused",
     79                                 address_refused),
     80     GNUNET_PQ_result_spec_bool ("solved",
     81                                 solved),
     82     GNUNET_PQ_result_spec_end
     83   };
     84   enum GNUNET_DB_QueryStatus qs;
     85 
     86   *client_redirect_uri = NULL;
     87   PREPARE (pg,
     88            "do_challenge_set_address_and_pin",
     89            "SELECT "
     90            " out_not_found AS not_found"
     91            ",out_last_tx_time AS last_tx_time"
     92            ",out_pin_transmit AS pin_transmit"
     93            ",out_last_pin AS last_pin"
     94            ",out_state AS state"
     95            ",out_auth_attempts_left AS auth_attempts_left"
     96            ",out_client_redirect_uri AS client_redirect_uri"
     97            ",out_address_refused AS address_refused"
     98            ",out_solved AS solved"
     99            " FROM challenger_do_challenge_set_address_and_pin"
    100            " ($1,$2,$3,$4,$5);");
    101   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
    102                                                  "do_challenge_set_address_and_pin",
    103                                                  params,
    104                                                  rs);
    105   if (qs <= 0)
    106     return qs;
    107   if (not_found)
    108     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
    109   return qs;
    110 }