anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

lae_common.c (2039B)


      1 /*
      2   This file is part of Anastasis
      3   Copyright (C) 2015-2020 Anastasis SARL
      4 
      5   Anastasis is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13   You should have received a copy of the GNU General Public License along with
     14   Anastasis; see the file COPYING.  If not, see
     15   <http://www.gnu.org/licenses/>
     16 */
     17 /**
     18  * @file libanastasiseufin/lae_common.c
     19  * @brief Common functions for the bank API
     20  * @author Christian Grothoff
     21  */
     22 #include "platform.h"
     23 #include "lae_common.h"
     24 
     25 
     26 /**
     27  * Set authentication data in @a easy from @a auth.
     28  * The API currently specifies the use of HTTP basic
     29  * authentication.
     30  *
     31  * @param easy curl handle to setup for authentication
     32  * @param auth authentication data to use
     33  * @return #GNUNET_OK in success
     34  */
     35 enum GNUNET_GenericReturnValue
     36 ANASTASIS_EUFIN_setup_auth_ (
     37   CURL *easy,
     38   const struct ANASTASIS_EUFIN_AuthenticationData *auth)
     39 {
     40   int ret;
     41 
     42   ret = GNUNET_OK;
     43   switch (auth->method)
     44   {
     45   case ANASTASIS_EUFIN_AUTH_NONE:
     46     return GNUNET_OK;
     47   case ANASTASIS_EUFIN_AUTH_BASIC:
     48     {
     49       char *up;
     50 
     51       GNUNET_asprintf (&up,
     52                        "%s:%s",
     53                        auth->details.basic.username,
     54                        auth->details.basic.password);
     55       if ( (CURLE_OK !=
     56             curl_easy_setopt (easy,
     57                               CURLOPT_HTTPAUTH,
     58                               CURLAUTH_BASIC)) ||
     59            (CURLE_OK !=
     60             curl_easy_setopt (easy,
     61                               CURLOPT_USERPWD,
     62                               up)) )
     63         ret = GNUNET_SYSERR;
     64       GNUNET_free (up);
     65       break;
     66     }
     67   }
     68   return ret;
     69 }
     70 
     71 
     72 /* end of lae_common.c */