curl_sasl.h
Go to the documentation of this file.
00001 #ifndef HEADER_CURL_SASL_H
00002 #define HEADER_CURL_SASL_H
00003 /***************************************************************************
00004  *                                  _   _ ____  _
00005  *  Project                     ___| | | |  _ \| |
00006  *                             / __| | | | |_) | |
00007  *                            | (__| |_| |  _ <| |___
00008  *                             \___|\___/|_| \_\_____|
00009  *
00010  * Copyright (C) 2012 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00011  *
00012  * This software is licensed as described in the file COPYING, which
00013  * you should have received as part of this distribution. The terms
00014  * are also available at https://curl.haxx.se/docs/copyright.html.
00015  *
00016  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00017  * copies of the Software, and permit persons to whom the Software is
00018  * furnished to do so, under the terms of the COPYING file.
00019  *
00020  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00021  * KIND, either express or implied.
00022  *
00023  ***************************************************************************/
00024 
00025 #include <curl/curl.h>
00026 
00027 struct Curl_easy;
00028 struct connectdata;
00029 
00030 /* Authentication mechanism flags */
00031 #define SASL_MECH_LOGIN             (1 << 0)
00032 #define SASL_MECH_PLAIN             (1 << 1)
00033 #define SASL_MECH_CRAM_MD5          (1 << 2)
00034 #define SASL_MECH_DIGEST_MD5        (1 << 3)
00035 #define SASL_MECH_GSSAPI            (1 << 4)
00036 #define SASL_MECH_EXTERNAL          (1 << 5)
00037 #define SASL_MECH_NTLM              (1 << 6)
00038 #define SASL_MECH_XOAUTH2           (1 << 7)
00039 #define SASL_MECH_OAUTHBEARER       (1 << 8)
00040 
00041 /* Authentication mechanism values */
00042 #define SASL_AUTH_NONE          0
00043 #define SASL_AUTH_ANY           ~0U
00044 #define SASL_AUTH_DEFAULT       (SASL_AUTH_ANY & ~SASL_MECH_EXTERNAL)
00045 
00046 /* Authentication mechanism strings */
00047 #define SASL_MECH_STRING_LOGIN        "LOGIN"
00048 #define SASL_MECH_STRING_PLAIN        "PLAIN"
00049 #define SASL_MECH_STRING_CRAM_MD5     "CRAM-MD5"
00050 #define SASL_MECH_STRING_DIGEST_MD5   "DIGEST-MD5"
00051 #define SASL_MECH_STRING_GSSAPI       "GSSAPI"
00052 #define SASL_MECH_STRING_EXTERNAL     "EXTERNAL"
00053 #define SASL_MECH_STRING_NTLM         "NTLM"
00054 #define SASL_MECH_STRING_XOAUTH2      "XOAUTH2"
00055 #define SASL_MECH_STRING_OAUTHBEARER  "OAUTHBEARER"
00056 
00057 /* SASL machine states */
00058 typedef enum {
00059   SASL_STOP,
00060   SASL_PLAIN,
00061   SASL_LOGIN,
00062   SASL_LOGIN_PASSWD,
00063   SASL_EXTERNAL,
00064   SASL_CRAMMD5,
00065   SASL_DIGESTMD5,
00066   SASL_DIGESTMD5_RESP,
00067   SASL_NTLM,
00068   SASL_NTLM_TYPE2MSG,
00069   SASL_GSSAPI,
00070   SASL_GSSAPI_TOKEN,
00071   SASL_GSSAPI_NO_DATA,
00072   SASL_OAUTH2,
00073   SASL_OAUTH2_RESP,
00074   SASL_CANCEL,
00075   SASL_FINAL
00076 } saslstate;
00077 
00078 /* Progress indicator */
00079 typedef enum {
00080   SASL_IDLE,
00081   SASL_INPROGRESS,
00082   SASL_DONE
00083 } saslprogress;
00084 
00085 /* Protocol dependent SASL parameters */
00086 struct SASLproto {
00087   const char *service;     /* The service name */
00088   int contcode;            /* Code to receive when continuation is expected */
00089   int finalcode;           /* Code to receive upon authentication success */
00090   size_t maxirlen;         /* Maximum initial response length */
00091   CURLcode (*sendauth)(struct connectdata *conn,
00092                        const char *mech, const char *ir);
00093                            /* Send authentication command */
00094   CURLcode (*sendcont)(struct connectdata *conn, const char *contauth);
00095                            /* Send authentication continuation */
00096   void (*getmessage)(char *buffer, char **outptr);
00097                            /* Get SASL response message */
00098 };
00099 
00100 /* Per-connection parameters */
00101 struct SASL {
00102   const struct SASLproto *params; /* Protocol dependent parameters */
00103   saslstate state;         /* Current machine state */
00104   unsigned int authmechs;  /* Accepted authentication mechanisms */
00105   unsigned int prefmech;   /* Preferred authentication mechanism */
00106   unsigned int authused;   /* Auth mechanism used for the connection */
00107   bool resetprefs;         /* For URL auth option parsing. */
00108   bool mutual_auth;        /* Mutual authentication enabled (GSSAPI only) */
00109   bool force_ir;           /* Protocol always supports initial response */
00110 };
00111 
00112 /* This is used to test whether the line starts with the given mechanism */
00113 #define sasl_mech_equal(line, wordlen, mech) \
00114   (wordlen == (sizeof(mech) - 1) / sizeof(char) && \
00115    !memcmp(line, mech, wordlen))
00116 
00117 /* This is used to cleanup any libraries or curl modules used by the sasl
00118    functions */
00119 void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused);
00120 
00121 /* Convert a mechanism name to a token */
00122 unsigned int Curl_sasl_decode_mech(const char *ptr,
00123                                    size_t maxlen, size_t *len);
00124 
00125 /* Parse the URL login options */
00126 CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
00127                                          const char *value, size_t len);
00128 
00129 /* Initializes an SASL structure */
00130 void Curl_sasl_init(struct SASL *sasl, const struct SASLproto *params);
00131 
00132 /* Check if we have enough auth data and capabilities to authenticate */
00133 bool Curl_sasl_can_authenticate(struct SASL *sasl, struct connectdata *conn);
00134 
00135 /* Calculate the required login details for SASL authentication  */
00136 CURLcode Curl_sasl_start(struct SASL *sasl, struct connectdata *conn,
00137                          bool force_ir, saslprogress *progress);
00138 
00139 /* Continue an SASL authentication  */
00140 CURLcode Curl_sasl_continue(struct SASL *sasl, struct connectdata *conn,
00141                             int code, saslprogress *progress);
00142 
00143 #endif /* HEADER_CURL_SASL_H */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:02