delete_client.c (3208B)
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 src/challengerdb/delete_client.c 18 * @brief Implementation of the delete_client 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 "delete_client.h" 26 #include "pg_helper.h" 27 28 29 enum GNUNET_DB_QueryStatus 30 CHALLENGERDB_delete_client (struct CHALLENGERDB_PostgresContext *ctx, 31 const char *client_redirect_uri, 32 uint64_t *validations_deleted) 33 { 34 struct GNUNET_PQ_QueryParam params[] = { 35 GNUNET_PQ_query_param_string (client_redirect_uri), 36 GNUNET_PQ_query_param_end 37 }; 38 bool deleted; 39 struct GNUNET_PQ_ResultSpec rs[] = { 40 GNUNET_PQ_result_spec_uint64 ("validations_deleted", 41 validations_deleted), 42 GNUNET_PQ_result_spec_bool ("deleted", 43 &deleted), 44 GNUNET_PQ_result_spec_end 45 }; 46 enum GNUNET_DB_QueryStatus qs; 47 48 *validations_deleted = 0; 49 /* validations_client_serial_id_fkey is ON DELETE CASCADE, so deleting a 50 client silently discards all of its validations -- KYC processes that 51 are in flight right now. Delete them here explicitly instead, so that 52 we can tell the operator how many were lost. Note that access tokens 53 already issued are *not* affected: 'tokens' has no client reference at 54 all and thus cannot be revoked per client. */ 55 PREPARE (ctx, 56 "delete_client", 57 "WITH victim AS (" 58 " SELECT client_serial_id" 59 " FROM clients" 60 " WHERE uri=$1" 61 "), dv AS (" 62 " DELETE FROM validations" 63 " WHERE client_serial_id IN" 64 " (SELECT client_serial_id FROM victim)" 65 " RETURNING validation_serial_id" 66 "), dc AS (" 67 " DELETE FROM clients" 68 " WHERE uri=$1" 69 " RETURNING client_serial_id" 70 ") SELECT" 71 " (SELECT COUNT(*) FROM dv) AS validations_deleted" 72 " ,EXISTS (SELECT 1 FROM dc) AS deleted;"); 73 qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, 74 "delete_client", 75 params, 76 rs); 77 if (0 >= qs) 78 return qs; 79 return deleted 80 ? GNUNET_DB_STATUS_SUCCESS_ONE_RESULT 81 : GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 82 }