LCOV - code coverage report
Current view: top level - util/crypto/nss - nss_util.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 18 77.8 %
Date: 2016-06-29 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :    SSSD
       3             : 
       4             :    NSS crypto wrappers
       5             : 
       6             :    Authors:
       7             :         Sumit Bose <sbose@redhat.com>
       8             :         Jakub Hrozek <jhrozek@redhat.com>
       9             : 
      10             :    Copyright (C) Red Hat, Inc 2010
      11             : 
      12             :    This program is free software; you can redistribute it and/or modify
      13             :    it under the terms of the GNU General Public License as published by
      14             :    the Free Software Foundation; either version 3 of the License, or
      15             :    (at your option) any later version.
      16             : 
      17             :    This program is distributed in the hope that it will be useful,
      18             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      19             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      20             :    GNU General Public License for more details.
      21             : 
      22             :    You should have received a copy of the GNU General Public License
      23             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      24             : */
      25             : 
      26             : #include "config.h"
      27             : 
      28             : #include <prinit.h>
      29             : #include <prerror.h>
      30             : #include <nss.h>
      31             : #include <pk11func.h>
      32             : 
      33             : #include "util/util.h"
      34             : #include "util/crypto/nss/nss_util.h"
      35             : 
      36             : static int nspr_nss_init_done = 0;
      37             : 
      38         135 : int nspr_nss_init(void)
      39             : {
      40             :     SECStatus sret;
      41             : 
      42             :     /* nothing to do */
      43         135 :     if (nspr_nss_init_done == 1) return SECSuccess;
      44             : 
      45          28 :     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
      46             : 
      47          28 :     sret = NSS_NoDB_Init(NULL);
      48          28 :     if (sret != SECSuccess) {
      49           0 :         DEBUG(SSSDBG_CRIT_FAILURE,
      50             :               "Error initializing connection to NSS [%d]\n",
      51             :                   PR_GetError());
      52           0 :         return EIO;
      53             :     }
      54             : 
      55          28 :     nspr_nss_init_done = 1;
      56          28 :     return EOK;
      57             : }
      58             : 
      59          11 : int nspr_nss_cleanup(void)
      60             : {
      61             :     SECStatus sret;
      62             : 
      63             :     /* nothing to do */
      64          11 :     if (nspr_nss_init_done == 0) return SECSuccess;
      65             : 
      66          11 :     sret = NSS_Shutdown();
      67          11 :     if (sret != SECSuccess) {
      68           0 :         DEBUG(SSSDBG_CRIT_FAILURE,
      69             :               "Error shutting down connection to NSS [%d]\n",
      70             :                   PR_GetError());
      71           0 :         return EIO;
      72             :     }
      73             : 
      74          11 :     PR_Cleanup();
      75          11 :     nspr_nss_init_done = 0;
      76          11 :     return EOK;
      77             : }

Generated by: LCOV version 1.10