LCOV - code coverage report
Current view: top level - daemon/dbus - gkd-secret-lock.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 61.2 % 49 30
Test Date: 2024-04-08 13:24:42 Functions: 100.0 % 2 2

            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-lock.h"
      24              : #include "gkd-secret-service.h"
      25              : 
      26              : #include "egg/egg-error.h"
      27              : 
      28              : #include "pkcs11/pkcs11i.h"
      29              : 
      30              : #include <gck/gck.h>
      31              : 
      32              : gboolean
      33            4 : gkd_secret_lock (GckObject *collection,
      34              :                  GError **error_out)
      35              : {
      36            4 :         GckBuilder builder = GCK_BUILDER_INIT;
      37            4 :         GError *error = NULL;
      38              :         GList *objects, *l;
      39              :         GckSession *session;
      40              : 
      41            4 :         gck_builder_add_ulong (&builder, CKA_CLASS, CKO_G_CREDENTIAL);
      42            4 :         gck_builder_add_ulong (&builder, CKA_G_OBJECT, gck_object_get_handle (collection));
      43              : 
      44            4 :         session = gck_object_get_session (collection);
      45            4 :         g_return_val_if_fail (session, FALSE);
      46              : 
      47            4 :         objects = gck_session_find_objects (session, gck_builder_end (&builder), NULL, &error);
      48              : 
      49            4 :         g_object_unref (session);
      50              : 
      51            4 :         if (error != NULL) {
      52            0 :                 g_warning ("couldn't search for credential objects: %s", egg_error_message (error));
      53            0 :                 g_set_error_literal (error_out, G_DBUS_ERROR,
      54              :                                      G_DBUS_ERROR_FAILED,
      55              :                                      "Couldn't lock collection");
      56            0 :                 g_clear_error (&error);
      57            0 :                 return FALSE;
      58              :         }
      59              : 
      60            8 :         for (l = objects; l; l = g_list_next (l)) {
      61            4 :                 if (!gck_object_destroy (l->data, NULL, &error)) {
      62            0 :                         g_warning ("couldn't destroy credential object: %s", egg_error_message (error));
      63            0 :                         g_clear_error (&error);
      64              :                 }
      65              :         }
      66              : 
      67            4 :         gck_list_unref_free (objects);
      68            4 :         return TRUE;
      69              : }
      70              : 
      71              : gboolean
      72            1 : gkd_secret_lock_all (GckSession *session,
      73              :                      GError **error_out)
      74              : {
      75            1 :         GckBuilder builder = GCK_BUILDER_INIT;
      76            1 :         GError *error = NULL;
      77              :         GList *objects, *l;
      78              : 
      79              :         /* Lock all the main collections */
      80            1 :         gck_builder_add_ulong (&builder, CKA_CLASS, CKO_G_CREDENTIAL);
      81            1 :         gck_builder_add_boolean (&builder, CKA_GNOME_TRANSIENT, TRUE);
      82              : 
      83            1 :         objects = gck_session_find_objects (session, gck_builder_end (&builder), NULL, &error);
      84            1 :         if (error != NULL) {
      85            0 :                 g_warning ("couldn't search for credential objects: %s", egg_error_message (error));
      86            0 :                 g_set_error (error_out, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Couldn't lock service");
      87            0 :                 g_clear_error (&error);
      88            0 :                 return FALSE;
      89              :         }
      90              : 
      91            2 :         for (l = objects; l; l = g_list_next (l)) {
      92            1 :                 if (!gck_object_destroy (l->data, NULL, &error)) {
      93            0 :                         g_warning ("couldn't destroy credential object: %s", egg_error_message (error));
      94            0 :                         g_clear_error (&error);
      95              :                 }
      96              :         }
      97              : 
      98              :         /* Now delete all session objects */
      99            1 :         gck_builder_add_ulong (&builder, CKA_CLASS, CKO_SECRET_KEY);
     100            1 :         gck_builder_add_string (&builder, CKA_G_COLLECTION, "session");
     101              : 
     102            1 :         objects = gck_session_find_objects (session, gck_builder_end (&builder), NULL, &error);
     103            1 :         if (error != NULL) {
     104            0 :                 g_warning ("couldn't search for session items: %s", egg_error_message (error));
     105            0 :                 g_set_error (error_out, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Couldn't lock service");
     106            0 :                 g_clear_error (&error);
     107            0 :                 return FALSE;
     108              :         }
     109              : 
     110            1 :         for (l = objects; l; l = g_list_next (l)) {
     111            0 :                 if (!gck_object_destroy (l->data, NULL, &error)) {
     112            0 :                         g_warning ("couldn't destroy session item: %s", egg_error_message (error));
     113            0 :                         g_clear_error (&error);
     114              :                 }
     115              :         }
     116              : 
     117            1 :         gck_list_unref_free (objects);
     118            1 :         return TRUE;
     119              : }
        

Generated by: LCOV version 2.0-1