LCOV - code coverage report
Current view: top level - tests - simple.c (source / functions) Hit Total Coverage
Test: GNU SASL Lines: 122 157 77.7 %
Date: 2010-09-27 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 93 142 65.5 %

           Branch data     Line data    Source code
       1                 :            : /* simple.c --- Test the simple SASL mechanisms.
       2                 :            :  * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010  Simon Josefsson
       3                 :            :  *
       4                 :            :  * This file is part of GNU SASL.
       5                 :            :  *
       6                 :            :  * This program is free software: you can redistribute it and/or modify
       7                 :            :  * it 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                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but 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 this program.  If not, see <http://www.gnu.org/licenses/>.
      18                 :            :  *
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifdef HAVE_CONFIG_H
      22                 :            : # include "config.h"
      23                 :            : #endif
      24                 :            : 
      25                 :            : #include <stdio.h>
      26                 :            : #include <stdarg.h>
      27                 :            : #include <stdlib.h>
      28                 :            : #include <string.h>
      29                 :            : #include <gsasl.h>
      30                 :            : 
      31                 :            : #include "utils.h"
      32                 :            : 
      33                 :            : #define MAXSTEP 50
      34                 :            : #define CLIENT 1
      35                 :            : #define SERVER 0
      36                 :            : #define UTF8_a "\xC2\xAA"
      37                 :            : 
      38                 :            : struct sasltv
      39                 :            : {
      40                 :            :   int clientp;
      41                 :            :   const char *mech;
      42                 :            :   const char *step[MAXSTEP];
      43                 :            :   const char *password;
      44                 :            :   const char *authzid;
      45                 :            :   const char *authid;
      46                 :            :   const char *service;
      47                 :            :   const char *hostname;
      48                 :            :   const char *servicename;
      49                 :            :   const char *anonymous;
      50                 :            :   const char *passcode;
      51                 :            :   const char *suggestpin;
      52                 :            :   const char *pin;
      53                 :            :   int securidrc;
      54                 :            : };
      55                 :            : static struct sasltv sasltv[] = {
      56                 :            :   {CLIENT, "EXTERNAL", {"", NULL}},
      57                 :            :   {SERVER, "EXTERNAL", {"", NULL}},
      58                 :            :   {CLIENT, "ANONYMOUS", {"", "Zm9vQGJhci5jb20=", NULL, NULL}, NULL, NULL,
      59                 :            :    NULL, NULL, NULL, NULL, "foo@bar.com"},
      60                 :            :   {SERVER, "ANONYMOUS", {"Zm9vQGJhci5jb20=", NULL, NULL}, NULL, NULL, NULL,
      61                 :            :    NULL, NULL, NULL, "foo@bar.com"},
      62                 :            :   {CLIENT, "NTLM",
      63                 :            :    {"Kw==", "TlRMTVNTUAABAAAAB7IAAAYABgAgAAAAAAAAACYAAABhdXRoaWQ=",
      64                 :            :     "TlRMTVNTUAAAAAAAAAAAAAAAAAAAAGFiY2RlZmdoMDEyMzQ1Njc4ODY2NDQwMTIz",
      65                 :            :     "TlRMTVNTUAADAAAAGAAYAFgAAAAYABgAcAAAAAAAAABAAAAADAAMAEAAAAAMAAwATAAAA"
      66                 :            :     "AAAAACIAAAAAABhYmEAdQB0AGgAaQBkAGEAdQB0AGgAaQBkABeBBp9xJad9eYo3oh1k55"
      67                 :            :     "GNFDIui8H8Qz4CfWYVVToBhVzFFbzyzqAZN5Wl59K/Fg==",
      68                 :            :     NULL, NULL}, "password", "authzid", "authid"},
      69                 :            :   {CLIENT, "PLAIN",
      70                 :            :    {"", "YXV0aHppZABhdXRoaWQAcGFzc3dvcmQ=", NULL, NULL}, "password",
      71                 :            :    "authzid", "authid"},
      72                 :            :   {CLIENT, "PLAIN",
      73                 :            :    {"", "YQBhAGE=", NULL, NULL}, "a", "a", "a"},
      74                 :            :   {CLIENT, "PLAIN",
      75                 :            :    {"", "wqoAwqoAwqo=", NULL, NULL}, UTF8_a, UTF8_a, UTF8_a},
      76                 :            :   {SERVER, "PLAIN",
      77                 :            :    {"YXV0aHppZABhdXRoaWQAcGFzc3dvcmQ=", NULL, NULL}, "password", "authzid",
      78                 :            :    "authid"},
      79                 :            :   {SERVER, "PLAIN",
      80                 :            :    {"", "", "YXV0aHppZABhdXRoaWQAcGFzc3dvcmQ=", NULL, NULL}, "password",
      81                 :            :    "authzid", "authid"},
      82                 :            :   {CLIENT, "LOGIN",
      83                 :            :    {"VXNlciBOYW1l", "YXV0aGlk", "UGFzc3dvcmQ=", "cGFzc3dvcmQ=", NULL,
      84                 :            :     NULL}, "password", NULL, "authid"},
      85                 :            :   {CLIENT, "LOGIN",
      86                 :            :    {"VXNlciBOYW1l", "YXV0aGlk", "UGFzc3dvcmQ=", "YQ==", NULL, NULL}, "a",
      87                 :            :    NULL,
      88                 :            :    "authid"},
      89                 :            :   {CLIENT, "LOGIN",
      90                 :            :    {"VXNlciBOYW1l", "YXV0aGlk", "UGFzc3dvcmQ=", "wqo=", NULL, NULL}, UTF8_a,
      91                 :            :    NULL, "authid"},
      92                 :            :   {SERVER, "LOGIN",
      93                 :            :    {"", "VXNlciBOYW1l", "YXV0aGlk", "UGFzc3dvcmQ=", "cGFzc3dvcmQ=",
      94                 :            :     NULL, NULL}, "password", NULL, "authid"},
      95                 :            :   {CLIENT, "CRAM-MD5",
      96                 :            :    {"PGNiNmQ5YTQ5ZDA3ZjEwY2MubGliZ3Nhc2xAbG9jYWxob3N0Pg==",
      97                 :            :     "YXV0aGlkIGZkNjRmMjYxZWYxYjBjYjg0ZmZjNGVmYzgwZDk3NjFj", NULL, NULL},
      98                 :            :    "password", "authzid", "authid"},
      99                 :            :   {CLIENT, "SECURID",
     100                 :            :    {"", "YXV0aHppZABhdXRoaWQANDcxMQA=", NULL, NULL}, NULL, "authzid",
     101                 :            :    "authid", NULL, NULL, NULL, NULL, "4711"},
     102                 :            :   {CLIENT, "SECURID",
     103                 :            :    {"", "YXV0aHppZABhdXRoaWQANDcxMQA=", "cGFzc2NvZGU=",
     104                 :            :     "YXV0aHppZABhdXRoaWQANDcxMQA=", NULL, NULL}, NULL, "authzid", "authid",
     105                 :            :    NULL, NULL, NULL, NULL, "4711"},
     106                 :            :   {CLIENT, "SECURID",
     107                 :            :    {"", "YXV0aHppZABhdXRoaWQANDcxMQA=", "cGlu",
     108                 :            :     "YXV0aHppZABhdXRoaWQANDcxMQA0MgA=", NULL, NULL}, NULL, "authzid",
     109                 :            :    "authid", NULL, NULL, NULL, NULL, "4711", NULL, "42"},
     110                 :            :   {CLIENT, "SECURID",
     111                 :            :    {"", "YXV0aHppZABhdXRoaWQANDcxMQA=", "cGluMjM=",
     112                 :            :     "YXV0aHppZABhdXRoaWQANDcxMQA0MgA=", NULL, NULL}, NULL, "authzid",
     113                 :            :    "authid", NULL, NULL, NULL, NULL, "4711", "23", "42"},
     114                 :            :   {CLIENT, "SECURID",
     115                 :            :    {"", "YXV0aHppZABhdXRoaWQANDcxMQA=", "cGluMjM=",
     116                 :            :     "YXV0aHppZABhdXRoaWQANDcxMQA0MgA=", "cGFzc2NvZGU=",
     117                 :            :     "YXV0aHppZABhdXRoaWQANDcxMQA=", NULL, NULL}, NULL, "authzid", "authid",
     118                 :            :    NULL, NULL, NULL, NULL, "4711", "23", "42"},
     119                 :            :   {SERVER, "SECURID",
     120                 :            :    {"YXV0aHppZABhdXRoaWQANDcxMQA=", "", NULL, NULL}, NULL, "authzid",
     121                 :            :    "authid", NULL, NULL, NULL, NULL, "4711"},
     122                 :            :   {SERVER, "SECURID",
     123                 :            :    {"YXV0aHppZABhdXRoaWQANDcxMQA=", "", NULL, NULL}, NULL, "authzid",
     124                 :            :    "authid", NULL, NULL, NULL, NULL, "4711"},
     125                 :            : #if 0
     126                 :            :   {SERVER, "SECURID",
     127                 :            :    {"YXV0aHppZABhdXRoaWQANDcxMQA=", "cGlu",
     128                 :            :     "YXV0aHppZABhdXRoaWQANDcxMQA0MgA=", "", NULL, NULL}, NULL, "authzid",
     129                 :            :    "authid", NULL, NULL, NULL, NULL, "4711", NULL, "42",
     130                 :            :    GSASL_SECURID_SERVER_NEED_NEW_PIN},
     131                 :            : #endif
     132                 :            :   {SERVER, "SECURID",
     133                 :            :    {"YXV0aHppZABhdXRoaWQANDcxMQA=", "cGluMTc=",
     134                 :            :     "YXV0aHppZABhdXRoaWQANDcxMQAyMwA=", "", NULL, NULL}, NULL, "authzid",
     135                 :            :    "authid", NULL, NULL, NULL, NULL, "4711", "17", "23",
     136                 :            :    GSASL_SECURID_SERVER_NEED_NEW_PIN},
     137                 :            :   {SERVER, "SECURID",
     138                 :            :    {"YXV0aHppZABhdXRoaWQANDcxMQA=", "cGFzc2NvZGU=",
     139                 :            :     "YXV0aHppZABhdXRoaWQANDcxMQA=", NULL, NULL}, NULL, "authzid", "authid",
     140                 :            :    NULL, NULL, NULL, NULL, "4711", NULL, NULL,
     141                 :            :    GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE}
     142                 :            : };
     143                 :            : 
     144                 :            : static int
     145                 :         58 : cb (Gsasl * ctx, Gsasl_session * sctx, Gsasl_property prop)
     146                 :            : {
     147                 :         58 :   int rc = GSASL_NO_CALLBACK;
     148                 :         58 :   int i = 0, j = 0;
     149                 :            : 
     150         [ +  + ]:         58 :   if (gsasl_callback_hook_get (ctx))
     151                 :         55 :     i = *(int *) gsasl_callback_hook_get (ctx);
     152         [ +  + ]:         58 :   if (gsasl_session_hook_get (sctx))
     153                 :         55 :     j = *(int *) gsasl_session_hook_get (sctx);
     154                 :            : 
     155 [ +  - ][ -  + ]:         58 :   if (j < 0 || j > 5)
     156                 :          0 :     fail ("j out of bounds: %d\n", j);
     157                 :            : 
     158 [ +  +  +  +  + :         58 :   switch (prop)
          +  +  +  +  +  
                   +  + ]
     159                 :            :     {
     160                 :            :     case GSASL_AUTHID:
     161                 :         13 :       gsasl_property_set (sctx, prop, sasltv[i].authid);
     162                 :         13 :       rc = GSASL_OK;
     163                 :         13 :       break;
     164                 :            : 
     165                 :            :     case GSASL_AUTHZID:
     166                 :          9 :       gsasl_property_set (sctx, prop, sasltv[i].authzid);
     167                 :          9 :       rc = GSASL_OK;
     168                 :          9 :       break;
     169                 :            : 
     170                 :            :     case GSASL_PASSWORD:
     171                 :         11 :       gsasl_property_set (sctx, prop, sasltv[i].password);
     172                 :         11 :       rc = GSASL_OK;
     173                 :         11 :       break;
     174                 :            : 
     175                 :            :     case GSASL_ANONYMOUS_TOKEN:
     176                 :          1 :       gsasl_property_set (sctx, prop, sasltv[i].anonymous);
     177                 :          1 :       rc = GSASL_OK;
     178                 :          1 :       break;
     179                 :            : 
     180                 :            :     case GSASL_SERVICE:
     181                 :          2 :       rc = GSASL_OK;
     182                 :          2 :       break;
     183                 :            : 
     184                 :            :     case GSASL_PASSCODE:
     185                 :          5 :       gsasl_property_set (sctx, prop, sasltv[i].passcode);
     186                 :          5 :       rc = GSASL_OK;
     187                 :          5 :       break;
     188                 :            : 
     189                 :            :     case GSASL_SUGGESTED_PIN:
     190                 :            :     case GSASL_PIN:
     191                 :            :       {
     192                 :          3 :         const char *suggestion = gsasl_property_fast (sctx, GSASL_SUGGESTED_PIN);
     193   [ +  +  +  - ]:          3 :         if (suggestion && sasltv[i].suggestpin
                 [ -  + ]
     194                 :          4 :             && strcmp (suggestion, sasltv[i].suggestpin) != 0)
     195                 :          0 :           return GSASL_AUTHENTICATION_ERROR;
     196                 :            : 
     197 [ +  + ][ +  - ]:          3 :         if ((suggestion == NULL && sasltv[i].suggestpin != NULL) ||
         [ +  + ][ -  + ]
     198                 :          2 :             (suggestion != NULL && sasltv[i].suggestpin == NULL))
     199                 :          0 :           return GSASL_AUTHENTICATION_ERROR;
     200                 :            : 
     201                 :          3 :         gsasl_property_set (sctx, prop, sasltv[i].pin);
     202                 :          3 :         rc = GSASL_OK;
     203                 :            :       }
     204                 :            : 
     205                 :            :     case GSASL_REALM:
     206                 :          5 :       break;
     207                 :            : 
     208                 :            :     case GSASL_VALIDATE_EXTERNAL:
     209                 :          1 :       rc = GSASL_OK;
     210                 :          1 :       break;
     211                 :            : 
     212                 :            :     case GSASL_VALIDATE_ANONYMOUS:
     213         [ +  - ]:          1 :       if (strcmp (sasltv[i].anonymous,
     214                 :            :                   gsasl_property_fast (sctx, GSASL_ANONYMOUS_TOKEN)) == 0)
     215                 :          1 :         rc = GSASL_OK;
     216                 :            :       else
     217                 :          0 :         rc = GSASL_AUTHENTICATION_ERROR;
     218                 :          1 :       break;
     219                 :            : 
     220                 :            :     case GSASL_VALIDATE_SECURID:
     221                 :            :       {
     222                 :          6 :         const char *passcode = gsasl_property_fast (sctx, GSASL_PASSCODE);
     223                 :          6 :         const char *pin = gsasl_property_fast (sctx, GSASL_PIN);
     224                 :            : 
     225         [ -  + ]:          6 :         if (strcmp (passcode, sasltv[i].passcode) != 0)
     226                 :          0 :           return GSASL_AUTHENTICATION_ERROR;
     227                 :            : 
     228         [ +  + ]:          6 :         if (sasltv[i].securidrc == GSASL_SECURID_SERVER_NEED_NEW_PIN)
     229                 :            :           {
     230                 :          1 :             rc = sasltv[i].securidrc;
     231                 :          1 :             sasltv[i].securidrc = GSASL_OK;
     232                 :            : 
     233         [ +  - ]:          1 :             if (sasltv[i].suggestpin)
     234                 :            :               {
     235                 :          1 :                 gsasl_property_set (sctx, GSASL_SUGGESTED_PIN,
     236                 :            :                                     sasltv[i].suggestpin);
     237                 :            :               }
     238                 :            :           }
     239         [ +  + ]:          5 :         else if (sasltv[i].securidrc ==
     240                 :            :                  GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE)
     241                 :            :           {
     242                 :          1 :             rc = sasltv[i].securidrc;
     243                 :          1 :             sasltv[i].securidrc = GSASL_OK;
     244                 :            :           }
     245                 :            :         else
     246                 :            :           {
     247                 :          4 :             rc = sasltv[i].securidrc;
     248                 :            : 
     249 [ +  + ][ +  - ]:          4 :             if (pin && sasltv[i].pin && strcmp (pin, sasltv[i].pin) != 0)
                 [ -  + ]
     250                 :          0 :               return GSASL_AUTHENTICATION_ERROR;
     251                 :            : 
     252 [ +  + ][ +  - ]:          4 :             if ((pin == NULL && sasltv[i].pin != NULL) ||
         [ +  + ][ -  + ]
     253                 :          1 :                 (pin != NULL && sasltv[i].pin == NULL))
     254                 :          0 :               return GSASL_AUTHENTICATION_ERROR;
     255                 :            :           }
     256                 :            :       }
     257                 :          6 :       break;
     258                 :            : 
     259                 :            :     default:
     260                 :          4 :       printf ("Unknown property %d\n", prop);
     261                 :            :       break;
     262                 :            :     }
     263                 :            : 
     264                 :         58 :   return rc;
     265                 :            : }
     266                 :            : 
     267                 :            : void
     268                 :          1 : doit (void)
     269                 :            : {
     270                 :          1 :   Gsasl *ctx = NULL;
     271                 :          1 :   Gsasl_session *sctx = NULL;
     272                 :          1 :   char *out = NULL;
     273                 :            :   size_t i, j;
     274                 :            :   int res;
     275                 :            : 
     276         [ -  + ]:          1 :   if (!gsasl_check_version (GSASL_VERSION))
     277                 :          0 :     fail ("gsasl_check_version failure");
     278                 :            : 
     279                 :          1 :   success ("Header version %s library version %s\n",
     280                 :            :            GSASL_VERSION, gsasl_check_version (NULL));
     281                 :            : 
     282                 :          1 :   res = gsasl_init (&ctx);
     283         [ -  + ]:          1 :   if (res != GSASL_OK)
     284                 :            :     {
     285                 :          0 :       fail ("gsasl_init() failed (%d):\n%s\n", res, gsasl_strerror (res));
     286                 :          0 :       return;
     287                 :            :     }
     288                 :            : 
     289                 :          1 :   gsasl_callback_set (ctx, cb);
     290                 :            : 
     291                 :          1 :   res = gsasl_client_mechlist (ctx, &out);
     292         [ -  + ]:          1 :   if (res != GSASL_OK)
     293                 :          0 :     fail ("gsasl_client_mechlist() failed (%d):\n%s\n",
     294                 :            :           res, gsasl_strerror (res));
     295                 :          1 :   success("client_mechlist: %s\n", out);
     296                 :          1 :   gsasl_free (out); out = NULL;
     297                 :            : 
     298                 :          1 :   res = gsasl_server_mechlist (ctx, &out);
     299         [ -  + ]:          1 :   if (res != GSASL_OK)
     300                 :          0 :     fail ("gsasl_server_mechlist() failed (%d):\n%s\n",
     301                 :            :           res, gsasl_strerror (res));
     302                 :          1 :   success("server_mechlist: %s\n", out);
     303                 :          1 :   gsasl_free (out); out = NULL;
     304                 :            : 
     305         [ +  + ]:         25 :   for (i = 0; i < sizeof (sasltv) / sizeof (sasltv[0]); i++)
     306                 :            :     {
     307                 :         24 :       gsasl_callback_hook_set (ctx, &i);
     308                 :            : 
     309         [ +  - ]:         24 :       if (debug)
     310         [ +  + ]:         24 :         printf ("Entry %d %s mechanism %s:\n",
     311                 :         24 :                 i, sasltv[i].clientp ? "client" : "server", sasltv[i].mech);
     312                 :            : 
     313         [ +  + ]:         24 :       if (sasltv[i].clientp)
     314                 :         15 :         res = gsasl_client_support_p (ctx, sasltv[i].mech);
     315                 :            :       else
     316                 :          9 :         res = gsasl_server_support_p (ctx, sasltv[i].mech);
     317         [ -  + ]:         24 :       if (!res)
     318                 :          0 :         continue;
     319                 :            : 
     320         [ +  + ]:         24 :       if (sasltv[i].clientp)
     321                 :         15 :         res = gsasl_client_start (ctx, sasltv[i].mech, &sctx);
     322                 :            :       else
     323                 :          9 :         res = gsasl_server_start (ctx, sasltv[i].mech, &sctx);
     324         [ -  + ]:         24 :       if (res != GSASL_OK)
     325                 :            :         {
     326         [ #  # ]:          0 :           fail ("SASL %s start for mechanism %s failed (%d):\n%s\n",
     327                 :          0 :                 sasltv[i].clientp ? "client" : "server",
     328                 :            :                 sasltv[i].mech, res, gsasl_strerror (res));
     329                 :          0 :           continue;
     330                 :            :         }
     331                 :            : 
     332         [ +  + ]:         47 :       for (j = 0; sasltv[i].step[j]; j += 2)
     333                 :            :         {
     334                 :         38 :           gsasl_session_hook_set (sctx, &j);
     335                 :            : 
     336         [ +  - ]:         38 :           if (debug)
     337         [ +  - ]:         38 :             printf ("Input : %s\n",
     338                 :         76 :                     sasltv[i].step[j] ? sasltv[i].step[j] : "");
     339                 :            : 
     340                 :         38 :           res = gsasl_step64 (sctx, sasltv[i].step[j], &out);
     341                 :            : 
     342         [ +  - ]:         38 :           if (debug)
     343         [ +  - ]:         38 :             printf ("Output: %s\n", out ? out : "(null)");
     344                 :            : 
     345 [ +  + ][ -  + ]:         38 :           if (res != GSASL_OK && res != GSASL_NEEDS_MORE)
     346                 :            :             {
     347                 :          0 :               fail ("gsasl_step64 failed (%d): %s", res, gsasl_strerror (res));
     348                 :          0 :               break;
     349                 :            :             }
     350                 :            : 
     351 [ +  + ][ -  + ]:         38 :           if (strlen (out) !=
     352                 :         69 :               strlen (sasltv[i].step[j + 1] ? sasltv[i].step[j + 1] : ""))
     353                 :            :             {
     354         [ #  # ]:          0 :               printf ("Expected: %s\n", sasltv[i].step[j + 1] ?
     355                 :          0 :                       sasltv[i].step[j + 1] : "");
     356                 :          0 :               fail
     357                 :            :                 ("SASL entry %d mechanism %s client step %d length error\n",
     358                 :            :                  i, sasltv[i].mech, j);
     359                 :          0 :               j = (size_t) -1;
     360                 :          0 :               break;
     361                 :            :             }
     362                 :            : 
     363 [ +  + ][ -  + ]:         38 :           if (strcmp (out, sasltv[i].step[j + 1] ?
     364                 :         31 :                       sasltv[i].step[j + 1] : "") != 0)
     365                 :            :             {
     366         [ #  # ]:          0 :               printf ("Expected: %s\n", sasltv[i].step[j + 1] ?
     367                 :          0 :                       sasltv[i].step[j + 1] : "");
     368                 :          0 :               fail ("SASL entry %d mechanism %s client step %d data error\n",
     369                 :            :                     i, sasltv[i].mech, j);
     370                 :          0 :               j = (size_t) -1;
     371                 :          0 :               break;
     372                 :            :             }
     373                 :            : 
     374                 :         38 :           gsasl_free (out); out = NULL;
     375                 :            : 
     376   [ +  +  +  + ]:         38 :           if (strcmp (sasltv[i].mech, "SECURID") != 0 && res == GSASL_OK)
     377                 :         15 :             break;
     378                 :            :         }
     379                 :            : 
     380 [ +  - ][ +  - ]:         24 :       if (j != (size_t) -1 && res == GSASL_OK && sasltv[i].step[j + 2])
                 [ -  + ]
     381                 :          0 :         fail ("SASL entry %d mechanism %s step %d code ended prematurely\n",
     382                 :            :               i, sasltv[i].mech, j);
     383 [ +  - ][ -  + ]:         24 :       else if (j != (size_t) -1 && res == GSASL_NEEDS_MORE)
     384                 :          0 :         fail ("SASL entry %d mechanism %s step %d table ended prematurely\n",
     385                 :            :               i, sasltv[i].mech, j);
     386 [ +  - ][ -  + ]:         24 :       else if (j != (size_t) -1 && res != GSASL_OK)
     387                 :          0 :         fail ("SASL entry %d mechanism %s step %d failed (%d):\n%s\n",
     388                 :            :               i, sasltv[i].mech, j, res, gsasl_strerror (res));
     389                 :            :       else
     390         [ +  + ]:         24 :         printf ("PASS: simple %s %s %d\n", sasltv[i].mech,
     391                 :         24 :                 sasltv[i].clientp ? "client" : "server", i);
     392                 :            : 
     393                 :            :       {
     394                 :            :         size_t outlen;
     395                 :            : 
     396                 :         24 :         res = gsasl_encode (sctx, "foo", 3, &out, &outlen);
     397         [ -  + ]:         24 :         if (res != GSASL_OK)
     398                 :          0 :           fail ("gsasl_encode %d: %s\n", res, gsasl_strerror (res));
     399 [ -  + ][ #  # ]:         24 :         if (outlen != 3 && memcmp (out, "foo", outlen) != 0)
     400                 :          0 :           fail ("gsasl_encode memcmp: %.*s\n", outlen, out);
     401                 :         24 :         gsasl_free (out); out = NULL;
     402                 :            : 
     403                 :         24 :         res = gsasl_decode (sctx, "foo", 3, &out, &outlen);
     404         [ -  + ]:         24 :         if (res != GSASL_OK)
     405                 :          0 :           fail ("gsasl_decode %d: %s\n", res, gsasl_strerror (res));
     406 [ -  + ][ #  # ]:         24 :         if (outlen != 3 && memcmp (out, "foo", outlen) != 0)
     407                 :          0 :           fail ("gsasl_decode memcmp: %.*s\n", outlen, out);
     408                 :         24 :         gsasl_free (out); out = NULL;
     409                 :            :       }
     410                 :            : 
     411                 :         24 :       gsasl_finish (sctx);
     412                 :            : 
     413         [ +  - ]:         24 :       if (debug)
     414                 :         24 :         printf ("\n");
     415                 :            :     }
     416                 :            : 
     417                 :          1 :   gsasl_done (ctx);
     418                 :            : 
     419                 :            :   /* Sanity check interfaces. */
     420                 :          1 :   gsasl_finish (NULL);
     421                 :          1 :   gsasl_done (NULL);
     422                 :            : }

Generated by: LCOV version 1.8