challenger

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

pg_client_check.c (3316B)


      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_client_check.c
     18  * @brief Implementation of the client_check 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_client_check.h"
     26 #include "pg_helper.h"
     27 
     28 
     29 enum GNUNET_DB_QueryStatus
     30 CH_PG_client_check (void *cls,
     31                     uint64_t client_id,
     32                     const char *client_secret,
     33                     uint32_t counter_increment,
     34                     char **client_redirect_uri)
     35 {
     36   struct PostgresClosure *pg = cls;
     37   struct GNUNET_PQ_QueryParam params[] = {
     38     GNUNET_PQ_query_param_uint64 (&client_id),
     39     GNUNET_PQ_query_param_string (client_secret),
     40     GNUNET_PQ_query_param_uint32 (&counter_increment),
     41     GNUNET_PQ_query_param_end
     42   };
     43   struct GNUNET_PQ_ResultSpec rs[] = {
     44     GNUNET_PQ_result_spec_allow_null (
     45       GNUNET_PQ_result_spec_string ("uri",
     46                                     client_redirect_uri),
     47       NULL),
     48     GNUNET_PQ_result_spec_end
     49   };
     50 
     51   *client_redirect_uri = NULL;
     52   PREPARE (pg,
     53            "client_check",
     54            "UPDATE clients SET"
     55            " validation_counter=validation_counter+CAST($3::INT4 AS INT8)"
     56            " WHERE client_serial_id=$1"
     57            "   AND client_secret=$2"
     58            " RETURNING uri;");
     59   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     60                                                    "client_check",
     61                                                    params,
     62                                                    rs);
     63 }
     64 
     65 
     66 enum GNUNET_DB_QueryStatus
     67 CH_PG_client_check2 (void *cls,
     68                      const char *client_uri,
     69                      const char *client_secret,
     70                      uint64_t *client_id)
     71 {
     72   struct PostgresClosure *pg = cls;
     73   struct GNUNET_PQ_QueryParam params[] = {
     74     GNUNET_PQ_query_param_string (client_uri),
     75     GNUNET_PQ_query_param_string (client_secret),
     76     GNUNET_PQ_query_param_end
     77   };
     78   struct GNUNET_PQ_ResultSpec rs[] = {
     79     GNUNET_PQ_result_spec_uint64 ("client_serial_id",
     80                                   client_id),
     81     GNUNET_PQ_result_spec_end
     82   };
     83 
     84   PREPARE (pg,
     85            "client_check2",
     86            "SELECT client_serial_id"
     87            " FROM clients"
     88            " WHERE uri=$1"
     89            "   AND client_secret=$2;");
     90   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     91                                                    "client_check2",
     92                                                    params,
     93                                                    rs);
     94 }