LCOV - code coverage report
Current view: top level - lib - saslname.c (source / functions) Hit Total Coverage
Test: GNU Generic Security Service Lines: 37 49 75.5 %
Date: 2010-05-20 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 22 38 57.9 %

           Branch data     Line data    Source code
       1                 :            : /* saslname.c --- Implementation of the SASL GS2 interfaces.
       2                 :            :  * Copyright (C) 2010  Simon Josefsson
       3                 :            :  *
       4                 :            :  * This file is part of the Generic Security Service (GSS).
       5                 :            :  *
       6                 :            :  * GSS 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                 :            :  * GSS is distributed in the hope that it will be useful, but WITHOUT
      12                 :            :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
      13                 :            :  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
      14                 :            :  * License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with GSS; if not, see http://www.gnu.org/licenses or write to
      18                 :            :  * 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                 :            : /* _gss_find_mech* */
      26                 :            : #include "meta.h"
      27                 :            : 
      28                 :            : static OM_uint32
      29                 :         12 : dup_data (OM_uint32 * minor_status,
      30                 :            :           gss_buffer_t out, const char *str, int translate)
      31                 :            : {
      32         [ +  + ]:         12 :   if (!out)
      33                 :          9 :     return GSS_S_COMPLETE;
      34                 :            : 
      35         [ +  + ]:          3 :   if (translate)
      36                 :          1 :     out->value = strdup (_(str));
      37                 :            :   else
      38                 :          2 :     out->value = strdup (str);
      39         [ -  + ]:          3 :   if (!out->value)
      40                 :            :     {
      41         [ #  # ]:          0 :       if (minor_status)
      42                 :          0 :         *minor_status = ENOMEM;
      43                 :          0 :       return GSS_S_FAILURE;
      44                 :            :     }
      45                 :          3 :   out->length = strlen (str);
      46                 :            : 
      47                 :         12 :   return GSS_S_COMPLETE;
      48                 :            : }
      49                 :            : 
      50                 :            : /**
      51                 :            :  * gss_inquire_saslname_for_mech:
      52                 :            :  * @minor_status: (Integer, modify) Mechanism specific status code.
      53                 :            :  * @desired_mech: (OID, read) Identifies the GSS-API mechanism to query.
      54                 :            :  * @sasl_mech_name: (buffer, character-string, modify, optional)
      55                 :            :  *   Buffer to receive SASL mechanism name.  The application must free
      56                 :            :  *   storage associated with this name after use with a call to
      57                 :            :  *   gss_release_buffer().
      58                 :            :  * @mech_name: (buffer, character-string, modify, optional) Buffer to
      59                 :            :  *   receive human readable mechanism name.  The application must free
      60                 :            :  *   storage associated with this name after use with a call to
      61                 :            :  *   gss_release_buffer().
      62                 :            :  * @mech_description: (buffer, character-string, modify, optional)
      63                 :            :  *   Buffer to receive description of mechanism.  The application must
      64                 :            :  *   free storage associated with this name after use with a call to
      65                 :            :  *   gss_release_buffer().
      66                 :            :  *
      67                 :            :  * Output the SASL mechanism name of a GSS-API mechanism.  It also
      68                 :            :  * returns a name and description of the mechanism in a user friendly
      69                 :            :  * form.
      70                 :            :  *
      71                 :            :  * Returns:
      72                 :            :  *
      73                 :            :  * `GSS_S_COMPLETE`: Successful completion.
      74                 :            :  *
      75                 :            :  * `GSS_S_BAD_MECH`: The @desired_mech OID is unsupported.
      76                 :            :  **/
      77                 :            : OM_uint32
      78                 :          6 : gss_inquire_saslname_for_mech (OM_uint32 * minor_status,
      79                 :            :                                const gss_OID desired_mech,
      80                 :            :                                gss_buffer_t sasl_mech_name,
      81                 :            :                                gss_buffer_t mech_name,
      82                 :            :                                gss_buffer_t mech_description)
      83                 :            : {
      84                 :            :   _gss_mech_api_t m;
      85                 :            : 
      86         [ +  + ]:          6 :   if (!desired_mech)
      87                 :            :     {
      88         [ +  - ]:          1 :       if (minor_status)
      89                 :          1 :         *minor_status = 0;
      90                 :          1 :       return GSS_S_CALL_INACCESSIBLE_READ;
      91                 :            :     }
      92                 :            : 
      93                 :          5 :   m = _gss_find_mech_no_default (desired_mech);
      94         [ +  + ]:          5 :   if (!m)
      95                 :            :     {
      96         [ +  - ]:          1 :       if (minor_status)
      97                 :          1 :         *minor_status = 0;
      98                 :          1 :       return GSS_S_BAD_MECH;
      99                 :            :     }
     100                 :            : 
     101                 :          4 :   bindtextdomain (PACKAGE PO_SUFFIX, LOCALEDIR);
     102                 :            : 
     103         [ -  + ]:          4 :   if (dup_data (minor_status, sasl_mech_name,
     104                 :            :                 m->sasl_name, 0) != GSS_S_COMPLETE)
     105                 :          0 :     return GSS_S_FAILURE;
     106         [ -  + ]:          4 :   if (dup_data (minor_status, mech_name, m->mech_name, 0) != GSS_S_COMPLETE)
     107                 :            :     {
     108         [ #  # ]:          0 :       if (sasl_mech_name)
     109                 :          0 :         free (sasl_mech_name->value);
     110                 :          0 :       return GSS_S_FAILURE;
     111                 :            :     }
     112         [ -  + ]:          4 :   if (dup_data (minor_status, mech_description,
     113                 :            :                 m->mech_description, 1) != GSS_S_COMPLETE)
     114                 :            :     {
     115         [ #  # ]:          0 :       if (sasl_mech_name)
     116                 :          0 :         free (sasl_mech_name->value);
     117         [ #  # ]:          0 :       if (mech_name)
     118                 :          0 :         free (mech_name->value);
     119                 :          0 :       return GSS_S_FAILURE;
     120                 :            :     }
     121                 :            : 
     122                 :          6 :   return GSS_S_COMPLETE;
     123                 :            : }
     124                 :            : 
     125                 :            : /**
     126                 :            :  * gss_inquire_mech_for_saslname:
     127                 :            :  * @minor_status: (Integer, modify) Mechanism specific status code.
     128                 :            :  * @sasl_mech_name: (buffer, character-string, read) Buffer with SASL
     129                 :            :  *   mechanism name.
     130                 :            :  * @mech_type: (OID, modify, optional) Actual mechanism used.  The OID
     131                 :            :  *   returned via this parameter will be a pointer to static storage
     132                 :            :  *   that should be treated as read-only; In particular the
     133                 :            :  *   application should not attempt to free it.  Specify NULL if not
     134                 :            :  *   required.
     135                 :            :  *
     136                 :            :  * Output GSS-API mechanism OID of mechanism associated with given
     137                 :            :  * @sasl_mech_name.
     138                 :            :  *
     139                 :            :  * Returns:
     140                 :            :  *
     141                 :            :  * `GSS_S_COMPLETE`: Successful completion.
     142                 :            :  *
     143                 :            :  * `GSS_S_BAD_MECH`: There is no GSS-API mechanism known as @sasl_mech_name.
     144                 :            :  **/
     145                 :            : OM_uint32
     146                 :          4 : gss_inquire_mech_for_saslname (OM_uint32 * minor_status,
     147                 :            :                                const gss_buffer_t sasl_mech_name,
     148                 :            :                                gss_OID * mech_type)
     149                 :            : {
     150                 :            :   _gss_mech_api_t m;
     151                 :            : 
     152         [ +  + ]:          4 :   if (!sasl_mech_name)
     153                 :            :     {
     154         [ +  - ]:          1 :       if (minor_status)
     155                 :          1 :         *minor_status = 0;
     156                 :          1 :       return GSS_S_CALL_INACCESSIBLE_READ;
     157                 :            :     }
     158                 :            : 
     159                 :          3 :   m = _gss_find_mech_by_saslname (sasl_mech_name);
     160         [ +  + ]:          3 :   if (!m)
     161                 :            :     {
     162         [ +  - ]:          1 :       if (minor_status)
     163                 :          1 :         *minor_status = 0;
     164                 :          1 :       return GSS_S_BAD_MECH;
     165                 :            :     }
     166                 :            : 
     167         [ +  + ]:          2 :   if (mech_type)
     168                 :          1 :     *mech_type = m->mech;
     169                 :            : 
     170                 :          4 :   return GSS_S_COMPLETE;
     171                 :            : }

Generated by: LCOV version 1.8