LCOV - code coverage report
Current view: top level - lib/krb5 - name.c (source / functions) Hit Total Coverage
Test: GNU Generic Security Service Lines: 13 62 21.0 %
Date: 2010-05-20 Functions: 1 2 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 32 18.8 %

           Branch data     Line data    Source code
       1                 :            : /* krb5/name.c --- Implementation of Kerberos 5 GSS-API Name functions.
       2                 :            :  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 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                 :            : /* Get specification. */
      24                 :            : #include "k5internal.h"
      25                 :            : 
      26                 :            : OM_uint32
      27                 :          4 : gss_krb5_canonicalize_name (OM_uint32 * minor_status,
      28                 :            :                             const gss_name_t input_name,
      29                 :            :                             const gss_OID mech_type, gss_name_t * output_name)
      30                 :            : {
      31                 :            :   OM_uint32 maj_stat;
      32                 :            : 
      33         [ +  - ]:          4 :   if (minor_status)
      34                 :          4 :     *minor_status = 0;
      35                 :            : 
      36                 :            :   /* We consider (a zero terminated) GSS_KRB5_NT_PRINCIPAL_NAME the
      37                 :            :      canonical mechanism name type.  Convert everything into it.  */
      38                 :            : 
      39         [ -  + ]:          4 :   if (gss_oid_equal (input_name->type, GSS_C_NT_EXPORT_NAME))
      40                 :            :     {
      41         [ #  # ]:          0 :       if (input_name->length > 15)
      42                 :            :         {
      43                 :          0 :           *output_name = malloc (sizeof (**output_name));
      44         [ #  # ]:          0 :           if (!*output_name)
      45                 :            :             {
      46         [ #  # ]:          0 :               if (minor_status)
      47                 :          0 :                 *minor_status = ENOMEM;
      48                 :          0 :               return GSS_S_FAILURE;
      49                 :            :             }
      50                 :          0 :           (*output_name)->type = GSS_KRB5_NT_PRINCIPAL_NAME;
      51                 :          0 :           (*output_name)->length = input_name->length - 15;
      52                 :          0 :           (*output_name)->value = malloc ((*output_name)->length + 1);
      53         [ #  # ]:          0 :           if (!(*output_name)->value)
      54                 :            :             {
      55                 :          0 :               free (*output_name);
      56         [ #  # ]:          0 :               if (minor_status)
      57                 :          0 :                 *minor_status = ENOMEM;
      58                 :          0 :               return GSS_S_FAILURE;
      59                 :            :             }
      60                 :          0 :           memcpy ((*output_name)->value, input_name->value + 15,
      61                 :          0 :                   (*output_name)->length);
      62                 :          0 :           (*output_name)->value[(*output_name)->length] = '\0';
      63                 :            :         }
      64                 :            :       else
      65                 :            :         {
      66                 :          0 :           return GSS_S_BAD_NAME;
      67                 :            :         }
      68                 :            :     }
      69         [ +  - ]:          4 :   else if (gss_oid_equal (input_name->type, GSS_C_NT_HOSTBASED_SERVICE))
      70                 :            :     {
      71                 :            :       char *p;
      72                 :            : 
      73                 :            :       /* We don't support service-names without hostname part because
      74                 :            :          we can't compute a canonicalized name of the local host.
      75                 :            :          Calling gethostname does not give a canonicalized name. */
      76         [ -  + ]:          4 :       if (!memchr (input_name->value, '@', input_name->length))
      77                 :            :         {
      78                 :          0 :           *minor_status = GSS_KRB5_S_G_BAD_SERVICE_NAME;
      79                 :          0 :           return GSS_S_COMPLETE;
      80                 :            :         }
      81                 :            : 
      82                 :            :       /* We don't do DNS name canoncalization since that is
      83                 :            :          insecure. */
      84                 :            : 
      85                 :          4 :       maj_stat = gss_duplicate_name (minor_status, input_name, output_name);
      86         [ -  + ]:          4 :       if (GSS_ERROR (maj_stat))
      87                 :          0 :         return maj_stat;
      88                 :            : 
      89                 :          4 :       (*output_name)->type = GSS_KRB5_NT_PRINCIPAL_NAME;
      90                 :            : 
      91                 :          4 :       p = memchr ((*output_name)->value, '@', (*output_name)->length);
      92         [ +  - ]:          4 :       if (p)
      93                 :          4 :         *p = '/';
      94                 :            :     }
      95         [ #  # ]:          0 :   else if (gss_oid_equal (input_name->type, GSS_KRB5_NT_PRINCIPAL_NAME))
      96                 :            :     {
      97                 :          0 :       maj_stat = gss_duplicate_name (minor_status, input_name, output_name);
      98         [ #  # ]:          0 :       if (GSS_ERROR (maj_stat))
      99                 :          0 :         return maj_stat;
     100                 :            :     }
     101                 :            :   else
     102                 :            :     {
     103                 :          0 :       *output_name = GSS_C_NO_NAME;
     104                 :          0 :       return GSS_S_BAD_NAMETYPE;
     105                 :            :     }
     106                 :            : 
     107                 :          4 :   return GSS_S_COMPLETE;
     108                 :            : }
     109                 :            : 
     110                 :            : #define TOK_LEN 2
     111                 :            : #define MECH_OID_LEN_LEN 2
     112                 :            : #define MECH_OID_ASN1_LEN_LEN 2
     113                 :            : #define NAME_LEN_LEN 4
     114                 :            : 
     115                 :            : OM_uint32
     116                 :          0 : gss_krb5_export_name (OM_uint32 * minor_status,
     117                 :            :                       const gss_name_t input_name, gss_buffer_t exported_name)
     118                 :            : {
     119                 :          0 :   size_t msglen = input_name->length & 0xFFFFFFFF;
     120                 :          0 :   size_t len = TOK_LEN +
     121                 :          0 :     MECH_OID_LEN_LEN + MECH_OID_ASN1_LEN_LEN + GSS_KRB5->length +
     122                 :          0 :     NAME_LEN_LEN + msglen;
     123                 :            :   char *p;
     124                 :            : 
     125                 :          0 :   exported_name->length = len;
     126                 :          0 :   p = exported_name->value = malloc (len);
     127         [ #  # ]:          0 :   if (!p)
     128                 :            :     {
     129         [ #  # ]:          0 :       if (minor_status)
     130                 :          0 :         *minor_status = ENOMEM;
     131                 :          0 :       return GSS_S_FAILURE;
     132                 :            :     }
     133                 :            : 
     134                 :          0 :   sprintf (p, "\x04\x01\x01\x0B\x06\x09%s", (char *) GSS_KRB5->elements);
     135                 :          0 :   p[2] = '\0';
     136                 :          0 :   p += 15;
     137                 :          0 :   *p++ = (msglen >> 24) & 0xFF;
     138                 :          0 :   *p++ = (msglen >> 16) & 0xFF;
     139                 :          0 :   *p++ = (msglen >> 8) & 0xFF;
     140                 :          0 :   *p++ = msglen & 0xFF;
     141                 :          0 :   memcpy (p, input_name->value, msglen);
     142                 :            : 
     143         [ #  # ]:          0 :   if (minor_status)
     144                 :          0 :     *minor_status = 0;
     145                 :          0 :   return GSS_S_COMPLETE;
     146                 :            : }

Generated by: LCOV version 1.8