vauth.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 2014 - 2016, Steve Holme, <steve_holme@hotmail.com>.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 
00023 #include "curl_setup.h"
00024 
00025 #include <curl/curl.h>
00026 
00027 #include "vauth.h"
00028 #include "curl_multibyte.h"
00029 #include "curl_printf.h"
00030 
00031 /* The last #include files should be: */
00032 #include "curl_memory.h"
00033 #include "memdebug.h"
00034 
00035 /*
00036  * Curl_auth_build_spn()
00037  *
00038  * This is used to build a SPN string in the following formats:
00039  *
00040  * service/host@realm (Not currently used)
00041  * service/host       (Not used by GSS-API)
00042  * service@realm      (Not used by Windows SSPI)
00043  *
00044  * Parameters:
00045  *
00046  * service  [in] - The service type such as http, smtp, pop or imap.
00047  * host     [in] - The host name.
00048  * realm    [in] - The realm.
00049  *
00050  * Returns a pointer to the newly allocated SPN.
00051  */
00052 #if !defined(USE_WINDOWS_SSPI)
00053 char *Curl_auth_build_spn(const char *service, const char *host,
00054                           const char *realm)
00055 {
00056   char *spn = NULL;
00057 
00058   /* Generate our SPN */
00059   if(host && realm)
00060     spn = aprintf("%s/%s@%s", service, host, realm);
00061   else if(host)
00062     spn = aprintf("%s/%s", service, host);
00063   else if(realm)
00064     spn = aprintf("%s@%s", service, realm);
00065 
00066   /* Return our newly allocated SPN */
00067   return spn;
00068 }
00069 #else
00070 TCHAR *Curl_auth_build_spn(const char *service, const char *host,
00071                            const char *realm)
00072 {
00073   char *utf8_spn = NULL;
00074   TCHAR *tchar_spn = NULL;
00075 
00076   (void) realm;
00077 
00078   /* Note: We could use DsMakeSPN() or DsClientMakeSpnForTargetServer() rather
00079      than doing this ourselves but the first is only available in Windows XP
00080      and Windows Server 2003 and the latter is only available in Windows 2000
00081      but not Windows95/98/ME or Windows NT4.0 unless the Active Directory
00082      Client Extensions are installed. As such it is far simpler for us to
00083      formulate the SPN instead. */
00084 
00085   /* Generate our UTF8 based SPN */
00086   utf8_spn = aprintf("%s/%s", service, host);
00087   if(!utf8_spn) {
00088     return NULL;
00089   }
00090 
00091   /* Allocate our TCHAR based SPN */
00092   tchar_spn = Curl_convert_UTF8_to_tchar(utf8_spn);
00093   if(!tchar_spn) {
00094     free(utf8_spn);
00095 
00096     return NULL;
00097   }
00098 
00099   /* Release the UTF8 variant when operating with Unicode */
00100   Curl_unicodefree(utf8_spn);
00101 
00102   /* Return our newly allocated SPN */
00103   return tchar_spn;
00104 }
00105 #endif /* USE_WINDOWS_SSPI */
00106 
00107 /*
00108 * Curl_auth_user_contains_domain()
00109 *
00110 * This is used to test if the specified user contains a Windows domain name as
00111 * follows:
00112 *
00113 * User\Domain (Down-level Logon Name)
00114 * User/Domain (curl Down-level format - for compatibility with existing code)
00115 * User@Domain (User Principal Name)
00116 *
00117 * Note: The user name may be empty when using a GSS-API library or Windows SSPI
00118 * as the user and domain are either obtained from the credientals cache when
00119 * using GSS-API or via the currently logged in user's credientals when using
00120 * Windows SSPI.
00121 *
00122 * Parameters:
00123 *
00124 * user  [in] - The user name.
00125 *
00126 * Returns TRUE on success; otherwise FALSE.
00127 */
00128 bool Curl_auth_user_contains_domain(const char *user)
00129 {
00130   bool valid = FALSE;
00131 
00132   if(user && *user) {
00133     /* Check we have a domain name or UPN present */
00134     char *p = strpbrk(user, "\\/@");
00135 
00136     valid = (p != NULL && p > user && p < user + strlen(user) - 1 ? TRUE :
00137                                                                     FALSE);
00138   }
00139 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
00140   else
00141     /* User and domain are obtained from the GSS-API credientials cache or the
00142        currently logged in user from Windows */
00143     valid = TRUE;
00144 #endif
00145 
00146   return valid;
00147 }


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