LCOV - code coverage report
Current view: top level - shishi/lib - hostkeys.c (source / functions) Hit Total Coverage
Test: GNU Shishi Lines: 0 21 0.0 %
Date: 2010-05-20 Functions: 0 6 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 6 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* hostkeys.c --- Functions for managing hostkeys stored in files.
       2                 :            :  * Copyright (C) 2002, 2003, 2004, 2007, 2010  Simon Josefsson
       3                 :            :  *
       4                 :            :  * This file is part of Shishi.
       5                 :            :  *
       6                 :            :  * Shishi is free software; you can redistribute it and/or modify it
       7                 :            :  * under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation; either version 3 of the License, or
       9                 :            :  * (at your option) any later version.
      10                 :            :  *
      11                 :            :  * Shishi 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
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with Shishi; if not, see http://www.gnu.org/licenses or write
      18                 :            :  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
      19                 :            :  * Floor, Boston, MA 02110-1301, USA
      20                 :            :  *
      21                 :            :  */
      22                 :            : 
      23                 :            : #include "internal.h"
      24                 :            : 
      25                 :            : /**
      26                 :            :  * shishi_hostkeys_default_file:
      27                 :            :  * @handle: Shishi library handle create by shishi_init().
      28                 :            :  *
      29                 :            :  * Get file name of default host key file.
      30                 :            :  *
      31                 :            :  * Return value: Returns the default host key filename used in the
      32                 :            :  * library.  (Not a copy of it, so don't modify or deallocate it.)
      33                 :            :  **/
      34                 :            : const char *
      35                 :          0 : shishi_hostkeys_default_file (Shishi * handle)
      36                 :            : {
      37                 :            :   char *envfile;
      38                 :            : 
      39                 :          0 :   envfile = getenv ("SHISHI_KEYS");
      40         [ #  # ]:          0 :   if (envfile)
      41                 :          0 :     shishi_hostkeys_default_file_set (handle, envfile);
      42                 :            : 
      43         [ #  # ]:          0 :   if (!handle->hostkeysdefaultfile)
      44                 :          0 :     handle->hostkeysdefaultfile = xstrdup (HOSTKEYSFILE);
      45                 :            : 
      46                 :          0 :   return handle->hostkeysdefaultfile;
      47                 :            : }
      48                 :            : 
      49                 :            : /**
      50                 :            :  * shishi_hostkeys_default_file_set:
      51                 :            :  * @handle: Shishi library handle create by shishi_init().
      52                 :            :  * @hostkeysfile: string with new default hostkeys file name, or
      53                 :            :  *                NULL to reset to default.
      54                 :            :  *
      55                 :            :  * Set the default host key filename used in the library.  The
      56                 :            :  * string is copied into the library, so you can dispose of the
      57                 :            :  * variable immediately after calling this function.
      58                 :            :  **/
      59                 :            : void
      60                 :          0 : shishi_hostkeys_default_file_set (Shishi * handle, const char *hostkeysfile)
      61                 :            : {
      62                 :          0 :   free (handle->hostkeysdefaultfile);
      63         [ #  # ]:          0 :   if (hostkeysfile)
      64                 :          0 :     handle->hostkeysdefaultfile = xstrdup (hostkeysfile);
      65                 :            :   else
      66                 :          0 :     handle->hostkeysdefaultfile = NULL;
      67                 :          0 : }
      68                 :            : 
      69                 :            : /**
      70                 :            :  * shishi_hostkeys_for_server
      71                 :            :  * @handle: Shishi library handle create by shishi_init().
      72                 :            :  * @server: server name to get key for
      73                 :            :  *
      74                 :            :  * Get host key for @server.
      75                 :            :  *
      76                 :            :  * Return value: Returns the key for specific server, read from the
      77                 :            :  * default host keys file (see shishi_hostkeys_default_file()), or
      78                 :            :  * NULL if no key could be found or an error encountered.
      79                 :            :  **/
      80                 :            : Shishi_key *
      81                 :          0 : shishi_hostkeys_for_server (Shishi * handle, const char *server)
      82                 :            : {
      83                 :          0 :   return shishi_keys_for_server_in_file (handle,
      84                 :            :                                          shishi_hostkeys_default_file
      85                 :            :                                          (handle), server);
      86                 :            : }
      87                 :            : 
      88                 :            : /**
      89                 :            :  * shishi_hostkeys_for_serverrealm
      90                 :            :  * @handle: Shishi library handle create by shishi_init().
      91                 :            :  * @server: server name to get key for
      92                 :            :  * @realm: realm of server to get key for.
      93                 :            :  *
      94                 :            :  * Get host key for @server in @realm.
      95                 :            :  *
      96                 :            :  * Return value: Returns the key for specific server and realm, read
      97                 :            :  * from the default host keys file (see
      98                 :            :  * shishi_hostkeys_default_file()), or NULL if no key could be found
      99                 :            :  * or an error encountered.
     100                 :            :  **/
     101                 :            : Shishi_key *
     102                 :          0 : shishi_hostkeys_for_serverrealm (Shishi * handle,
     103                 :            :                                  const char *server, const char *realm)
     104                 :            : {
     105                 :          0 :   return shishi_keys_for_serverrealm_in_file
     106                 :            :     (handle, shishi_hostkeys_default_file (handle), server, realm);
     107                 :            : }
     108                 :            : 
     109                 :            : /**
     110                 :            :  * shishi_hostkeys_for_localservicerealm
     111                 :            :  * @handle: Shishi library handle create by shishi_init().
     112                 :            :  * @service: service to get key for.
     113                 :            :  * @realm: realm of server to get key for, or NULL for default realm.
     114                 :            :  *
     115                 :            :  * Get host key for @service on current host in @realm.
     116                 :            :  *
     117                 :            :  * Return value: Returns the key for the server
     118                 :            :  * "SERVICE/HOSTNAME@REALM" (where HOSTNAME is the current system's
     119                 :            :  * hostname), read from the default host keys file (see
     120                 :            :  * shishi_hostkeys_default_file()), or NULL if no key could be found
     121                 :            :  * or an error encountered.
     122                 :            :  **/
     123                 :            : Shishi_key *
     124                 :          0 : shishi_hostkeys_for_localservicerealm (Shishi * handle,
     125                 :            :                                        const char *service, const char *realm)
     126                 :            : {
     127                 :          0 :   return shishi_keys_for_localservicerealm_in_file
     128                 :            :     (handle, shishi_hostkeys_default_file (handle), service, realm);
     129                 :            : }
     130                 :            : 
     131                 :            : /**
     132                 :            :  * shishi_hostkeys_for_localservice
     133                 :            :  * @handle: Shishi library handle create by shishi_init().
     134                 :            :  * @service: service to get key for.
     135                 :            :  *
     136                 :            :  * Get host key for @service on current host in default realm.
     137                 :            :  *
     138                 :            :  * Return value: Returns the key for the server "SERVICE/HOSTNAME"
     139                 :            :  * (where HOSTNAME is the current system's hostname), read from the
     140                 :            :  * default host keys file (see shishi_hostkeys_default_file()), or
     141                 :            :  * NULL if no key could be found or an error encountered.
     142                 :            :  **/
     143                 :            : Shishi_key *
     144                 :          0 : shishi_hostkeys_for_localservice (Shishi * handle, const char *service)
     145                 :            : {
     146                 :          0 :   return shishi_hostkeys_for_localservicerealm (handle, service, NULL);
     147                 :            : }

Generated by: LCOV version 1.8