LCOV - code coverage report
Current view: top level - tests - saslname.c (source / functions) Hit Total Coverage
Test: GNU Generic Security Service Lines: 60 79 75.9 %
Date: 2010-05-20 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 24 48 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* saslname.c --- Test of new SASL GS2 related GSS-API functions
       2                 :            :  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 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                 :            : #include "config.h"
      24                 :            : 
      25                 :            : #include <stdio.h>
      26                 :            : #include <stdlib.h>
      27                 :            : #include <stdarg.h>
      28                 :            : #include <ctype.h>
      29                 :            : #include <string.h>
      30                 :            : 
      31                 :            : /* Get GSS prototypes. */
      32                 :            : #include <gss.h>
      33                 :            : 
      34                 :            : #include "utils.c"
      35                 :            : 
      36                 :            : int
      37                 :          1 : main (int argc, char *argv[])
      38                 :            : {
      39                 :            :   gss_uint32 maj_stat, min_stat;
      40                 :            :   gss_buffer_desc bufdesc;
      41                 :            :   gss_OID oid;
      42                 :            : 
      43                 :            :   do
      44 [ +  - ][ -  + ]:          1 :     if (strcmp (argv[argc - 1], "-v") == 0 ||
      45                 :          1 :         strcmp (argv[argc - 1], "--verbose") == 0)
      46                 :          0 :       debug = 1;
      47 [ +  - ][ -  + ]:          1 :     else if (strcmp (argv[argc - 1], "-b") == 0 ||
      48                 :          1 :              strcmp (argv[argc - 1], "--break-on-error") == 0)
      49                 :          0 :       break_on_error = 1;
      50 [ +  - ][ +  - ]:          1 :     else if (strcmp (argv[argc - 1], "-h") == 0 ||
                 [ -  + ]
      51                 :          1 :              strcmp (argv[argc - 1], "-?") == 0 ||
      52                 :          1 :              strcmp (argv[argc - 1], "--help") == 0)
      53                 :            :       {
      54                 :          0 :         printf ("Usage: %s [-vbh?] [--verbose] [--break-on-error] [--help]\n",
      55                 :            :                 argv[0]);
      56                 :          0 :         return 1;
      57                 :            :       }
      58         [ -  + ]:          1 :   while (argc-- > 1);
      59                 :            : 
      60                 :          1 :   maj_stat = gss_inquire_mech_for_saslname (&min_stat, NULL, NULL);
      61         [ +  - ]:          1 :   if (maj_stat == GSS_S_CALL_INACCESSIBLE_READ)
      62                 :          1 :     success ("gss_inquire_mech_for_saslname (NULL, NULL) success\n");
      63                 :            :   else
      64                 :          0 :     fail ("gss_inquire_mech_for_saslname (NULL, NULL) failed (%d,%d)\n",
      65                 :            :           maj_stat, min_stat);
      66                 :            : 
      67                 :          1 :   bufdesc.value = NULL;
      68                 :          1 :   bufdesc.length = 0;
      69                 :            : 
      70                 :          1 :   maj_stat = gss_inquire_mech_for_saslname (&min_stat, &bufdesc, NULL);
      71         [ +  - ]:          1 :   if (maj_stat == GSS_S_BAD_MECH)
      72                 :          1 :     success ("gss_inquire_mech_for_saslname (EMPTY, NULL) success\n");
      73                 :            :   else
      74                 :          0 :     fail ("gss_inquire_mech_for_saslname (EMPTY, NULL) failed (%d,%d)\n",
      75                 :            :           maj_stat, min_stat);
      76                 :            : 
      77                 :            : #ifdef USE_KERBEROS5
      78                 :          1 :   bufdesc.length = 8;
      79                 :          1 :   bufdesc.value = malloc (bufdesc.length);
      80                 :          1 :   memcpy (bufdesc.value, "GS2-KRB5", bufdesc.length);
      81                 :            : 
      82                 :          1 :   maj_stat = gss_inquire_mech_for_saslname (&min_stat, &bufdesc, NULL);
      83         [ +  - ]:          1 :   if (maj_stat == GSS_S_COMPLETE)
      84                 :          1 :     success ("gss_inquire_mech_for_saslname (GS2-KRB5, NULL) success\n");
      85                 :            :   else
      86                 :          0 :     fail ("gss_inquire_mech_for_saslname (GS2-KRB5, NULL) failed (%d,%d)\n",
      87                 :            :           maj_stat, min_stat);
      88                 :            : 
      89                 :          1 :   maj_stat = gss_inquire_mech_for_saslname (&min_stat, &bufdesc, &oid);
      90         [ +  - ]:          1 :   if (maj_stat == GSS_S_COMPLETE)
      91                 :          1 :     success ("gss_inquire_mech_for_saslname (GS2-KRB5, OID) success\n");
      92                 :            :   else
      93                 :          0 :     fail ("gss_inquire_mech_for_saslname (GS2-KRB5, OID) failed (%d,%d)\n",
      94                 :            :           maj_stat, min_stat);
      95                 :            : 
      96 [ +  - ][ -  + ]:          1 :   if (oid != GSS_KRB5 || !gss_oid_equal (oid, GSS_KRB5))
      97                 :          0 :     fail ("GS2-OID not Krb5?!\n");
      98                 :            : 
      99                 :          1 :   free (bufdesc.value);
     100                 :            : #endif
     101                 :            : 
     102                 :          1 :   maj_stat =
     103                 :          1 :     gss_inquire_saslname_for_mech (&min_stat, NULL, NULL, NULL, NULL);
     104         [ +  - ]:          1 :   if (maj_stat == GSS_S_CALL_INACCESSIBLE_READ)
     105                 :          1 :     success ("gss_inquire_saslname_for_mech (NULL) success\n");
     106                 :            :   else
     107                 :          0 :     fail ("gss_inquire_saslname_for_mech (NULL) failed (%d,%d)\n",
     108                 :            :           maj_stat, min_stat);
     109                 :            : 
     110                 :          1 :   maj_stat = gss_inquire_saslname_for_mech (&min_stat, GSS_C_NT_USER_NAME,
     111                 :            :                                             NULL, NULL, NULL);
     112         [ +  - ]:          1 :   if (maj_stat == GSS_S_BAD_MECH)
     113                 :          1 :     success ("gss_inquire_saslname_for_mech (NT_USER_NAME) success\n");
     114                 :            :   else
     115                 :          0 :     fail ("gss_inquire_saslname_for_mech (NT_USER_NAME) failed (%d,%d)\n",
     116                 :            :           maj_stat, min_stat);
     117                 :            : 
     118                 :            : #ifdef USE_KERBEROS5
     119                 :          1 :   maj_stat = gss_inquire_saslname_for_mech (&min_stat, GSS_KRB5,
     120                 :            :                                             NULL, NULL, NULL);
     121         [ +  - ]:          1 :   if (maj_stat == GSS_S_COMPLETE)
     122                 :          1 :     success ("gss_inquire_saslname_for_mech (GSS-KRB5) success\n");
     123                 :            :   else
     124                 :          0 :     fail ("gss_inquire_saslname_for_mech (GSS-KRB5) failed (%d,%d)\n",
     125                 :            :           maj_stat, min_stat);
     126                 :            : 
     127                 :          1 :   bufdesc.value = NULL;
     128                 :          1 :   bufdesc.length = 0;
     129                 :            : 
     130                 :          1 :   maj_stat = gss_inquire_saslname_for_mech (&min_stat, GSS_KRB5,
     131                 :            :                                             &bufdesc, NULL, NULL);
     132         [ +  - ]:          1 :   if (maj_stat == GSS_S_COMPLETE)
     133                 :          1 :     success ("gss_inquire_saslname_for_mech (GSS-KRB5) success: %.*s\n",
     134                 :            :              bufdesc.length, (char *) bufdesc.value);
     135                 :            :   else
     136                 :          0 :     fail ("gss_inquire_saslname_for_mech (GSS-KRB5) failed (%d,%d)\n",
     137                 :            :           maj_stat, min_stat);
     138                 :            : 
     139                 :          1 :   maj_stat = gss_release_buffer (&min_stat, &bufdesc);
     140         [ +  - ]:          1 :   if (maj_stat == GSS_S_COMPLETE)
     141                 :          1 :     success ("gss_release_buffer() OK\n");
     142                 :            :   else
     143                 :          0 :     fail ("gss_release_buffer() failed (%d,%d)\n", maj_stat, min_stat);
     144                 :            : 
     145                 :          1 :   maj_stat = gss_inquire_saslname_for_mech (&min_stat, GSS_KRB5,
     146                 :            :                                             NULL, &bufdesc, NULL);
     147         [ +  - ]:          1 :   if (maj_stat == GSS_S_COMPLETE)
     148                 :          1 :     success ("gss_inquire_saslname_for_mech (GSS-KRB5-2) success: %.*s\n",
     149                 :            :              bufdesc.length, (char *) bufdesc.value);
     150                 :            :   else
     151                 :          0 :     fail ("gss_inquire_saslname_for_mech (GSS-KRB5-2) failed (%d,%d)\n",
     152                 :            :           maj_stat, min_stat);
     153                 :            : 
     154                 :          1 :   maj_stat = gss_release_buffer (&min_stat, &bufdesc);
     155         [ +  - ]:          1 :   if (maj_stat == GSS_S_COMPLETE)
     156                 :          1 :     success ("gss_release_buffer() OK\n");
     157                 :            :   else
     158                 :          0 :     fail ("gss_release_buffer() failed (%d,%d)\n", maj_stat, min_stat);
     159                 :            : 
     160                 :          1 :   maj_stat = gss_inquire_saslname_for_mech (&min_stat, GSS_KRB5,
     161                 :            :                                             NULL, NULL, &bufdesc);
     162         [ +  - ]:          1 :   if (maj_stat == GSS_S_COMPLETE)
     163                 :          1 :     success ("gss_inquire_saslname_for_mech (GSS-KRB5-3) success: %.*s\n",
     164                 :            :              bufdesc.length, (char *) bufdesc.value);
     165                 :            :   else
     166                 :          0 :     fail ("gss_inquire_saslname_for_mech (GSS-KRB5-3) failed (%d,%d)\n",
     167                 :            :           maj_stat, min_stat);
     168                 :            : 
     169                 :          1 :   maj_stat = gss_release_buffer (&min_stat, &bufdesc);
     170         [ +  - ]:          1 :   if (maj_stat == GSS_S_COMPLETE)
     171                 :          1 :     success ("gss_release_buffer() OK\n");
     172                 :            :   else
     173                 :          0 :     fail ("gss_release_buffer() failed (%d,%d)\n", maj_stat, min_stat);
     174                 :            : #endif
     175                 :            : 
     176         [ -  + ]:          1 :   if (debug)
     177                 :          0 :     printf ("Basic self tests done with %d errors\n", error_count);
     178                 :            : 
     179                 :          1 :   return error_count ? 1 : 0;
     180                 :            : }

Generated by: LCOV version 1.8