LCOV - code coverage report
Current view: top level - daemon/dbus - gkd-secret-error.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 16.7 % 18 3
Test Date: 2024-04-08 13:24:42 Functions: 33.3 % 3 1

            Line data    Source code
       1              : /*
       2              :  * gnome-keyring
       3              :  *
       4              :  * Copyright (C) 2008 Stefan Walter
       5              :  *
       6              :  * This program is free software; you can redistribute it and/or modify
       7              :  * it under the terms of the GNU Lesser General Public License as
       8              :  * published by the Free Software Foundation; either version 2.1 of
       9              :  * the License, or (at your option) any later version.
      10              :  *
      11              :  * This program is distributed in the hope that it will be useful, but
      12              :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14              :  * Lesser General Public License for more details.
      15              :  *
      16              :  * You should have received a copy of the GNU Lesser General Public
      17              :  * License along with this program; if not, see
      18              :  * <http://www.gnu.org/licenses/>.
      19              :  */
      20              : 
      21              : #include "config.h"
      22              : 
      23              : #include "gkd-secret-error.h"
      24              : 
      25              : #include "egg/egg-error.h"
      26              : 
      27              : #include <gck/gck.h>
      28              : 
      29              : #include <glib.h>
      30              : 
      31              : static const GDBusErrorEntry gkd_secret_error_entries[] = {
      32              :         { GKD_SECRET_ERROR_ALREADY_EXISTS, SECRET_INTERFACE_PREFIX "Error.AlreadyExists" },
      33              :         { GKD_SECRET_ERROR_IS_LOCKED, SECRET_INTERFACE_PREFIX "Error.IsLocked" },
      34              :         { GKD_SECRET_ERROR_NO_SESSION, SECRET_INTERFACE_PREFIX "Error.NoSession" },
      35              :         { GKD_SECRET_ERROR_NO_SUCH_OBJECT, SECRET_INTERFACE_PREFIX "Error.NoSuchObject" }
      36              : };
      37              : 
      38              : GQuark
      39            0 : gkd_secret_error_quark (void)
      40              : {
      41              :         static gsize quark = 0;
      42              : 
      43            0 :         g_dbus_error_register_error_domain ("gkd_secret_error",
      44              :                                             &quark,
      45              :                                             gkd_secret_error_entries,
      46              :                                             G_N_ELEMENTS (gkd_secret_error_entries));
      47            0 :         return quark;
      48              : }
      49              : 
      50              : static const GDBusErrorEntry gkd_secret_daemon_error_entries[] = {
      51              :         { GKD_SECRET_DAEMON_ERROR_DENIED, "org.gnome.keyring.Error.Denied" }
      52              : };
      53              : 
      54              : GQuark
      55            1 : gkd_secret_daemon_error_quark (void)
      56              : {
      57              :         static gsize quark = 0;
      58              : 
      59            1 :         g_dbus_error_register_error_domain ("gkd_secret_daemon_error",
      60              :                                             &quark,
      61              :                                             gkd_secret_daemon_error_entries,
      62              :                                             G_N_ELEMENTS (gkd_secret_daemon_error_entries));
      63            1 :         return quark;
      64              : }
      65              : 
      66              : void
      67            0 : gkd_secret_propagate_error (GDBusMethodInvocation *invocation,
      68              :                             const gchar *description,
      69              :                             GError *error)
      70              : {
      71            0 :         g_return_if_fail (error != NULL);
      72              : 
      73            0 :         if (g_error_matches (error, GCK_ERROR, CKR_USER_NOT_LOGGED_IN) ||
      74            0 :             g_error_matches (error, GCK_ERROR, CKR_PIN_INCORRECT)) {
      75            0 :                 g_dbus_method_invocation_return_error_literal (invocation,
      76              :                                                                GKD_SECRET_DAEMON_ERROR,
      77              :                                                                GKD_SECRET_DAEMON_ERROR_DENIED,
      78              :                                                                "The password was invalid");
      79            0 :         } else if (g_error_matches (error, GCK_ERROR, CKR_WRAPPED_KEY_INVALID) ||
      80            0 :                    g_error_matches (error, GCK_ERROR, CKR_WRAPPED_KEY_LEN_RANGE) ||
      81            0 :                    g_error_matches (error, GCK_ERROR, CKR_MECHANISM_PARAM_INVALID)) {
      82            0 :                 g_dbus_method_invocation_return_error_literal (invocation,
      83              :                                                                G_DBUS_ERROR,
      84              :                                                                G_DBUS_ERROR_INVALID_ARGS,
      85              :                                                                "The secret was transferred or encrypted in an invalid way.");
      86              :         } else {
      87            0 :                 g_warning ("%s: %s", description, egg_error_message (error));
      88            0 :                 g_dbus_method_invocation_return_error_literal (invocation,
      89              :                                                                G_DBUS_ERROR,
      90              :                                                                G_DBUS_ERROR_FAILED,
      91              :                                                                description);
      92              :         }
      93              : 
      94            0 :         g_error_free (error);
      95              : }
        

Generated by: LCOV version 2.0-1