~ubuntu-branches/ubuntu/vivid/curl/vivid

« back to all changes in this revision

Viewing changes to lib/curl_sspi.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *                                  _   _ ____  _
 
3
 *  Project                     ___| | | |  _ \| |
 
4
 *                             / __| | | | |_) | |
 
5
 *                            | (__| |_| |  _ <| |___
 
6
 *                             \___|\___/|_| \_\_____|
 
7
 *
 
8
 * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
 
9
 *
 
10
 * This software is licensed as described in the file COPYING, which
 
11
 * you should have received as part of this distribution. The terms
 
12
 * are also available at http://curl.haxx.se/docs/copyright.html.
 
13
 *
 
14
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
 
15
 * copies of the Software, and permit persons to whom the Software is
 
16
 * furnished to do so, under the terms of the COPYING file.
 
17
 *
 
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 
19
 * KIND, either express or implied.
 
20
 *
 
21
 * $Id: curl_sspi.c,v 1.2 2009-01-30 01:54:22 yangtse Exp $
 
22
 ***************************************************************************/
 
23
 
 
24
#include "setup.h"
 
25
 
 
26
#ifdef USE_WINDOWS_SSPI
 
27
 
 
28
#include <curl/curl.h>
 
29
 
 
30
#include "curl_sspi.h"
 
31
 
 
32
#define _MPRINTF_REPLACE /* use our functions only */
 
33
#include <curl/mprintf.h>
 
34
 
 
35
#include "memory.h"
 
36
/* The last #include file should be: */
 
37
#include "memdebug.h"
 
38
 
 
39
 
 
40
/* Handle of security.dll or secur32.dll, depending on Windows version */
 
41
HMODULE s_hSecDll = NULL;
 
42
 
 
43
/* Pointer to SSPI dispatch table */
 
44
PSecurityFunctionTableA s_pSecFn = NULL;
 
45
 
 
46
 
 
47
/*
 
48
 * Curl_sspi_global_init()
 
49
 *
 
50
 * This is used to load the Security Service Provider Interface (SSPI)
 
51
 * dynamic link library portably across all Windows versions, without
 
52
 * the need to directly link libcurl, nor the application using it, at
 
53
 * build time.
 
54
 *
 
55
 * Once this function has been executed, Windows SSPI functions can be
 
56
 * called through the Security Service Provider Interface dispatch table.
 
57
 */
 
58
 
 
59
CURLcode
 
60
Curl_sspi_global_init(void)
 
61
{
 
62
  OSVERSIONINFO osver;
 
63
  INIT_SECURITY_INTERFACE_A pInitSecurityInterface;
 
64
 
 
65
  /* If security interface is not yet initialized try to do this */
 
66
  if(s_hSecDll == NULL) {
 
67
 
 
68
    /* Find out Windows version */
 
69
    memset(&osver, 0, sizeof(osver));
 
70
    osver.dwOSVersionInfoSize = sizeof(osver);
 
71
    if(! GetVersionEx(&osver))
 
72
      return CURLE_FAILED_INIT;
 
73
 
 
74
    /* Security Service Provider Interface (SSPI) functions are located in
 
75
     * security.dll on WinNT 4.0 and in secur32.dll on Win9x. Win2K and XP
 
76
     * have both these DLLs (security.dll forwards calls to secur32.dll) */
 
77
 
 
78
    /* Load SSPI dll into the address space of the calling process */
 
79
    if(osver.dwPlatformId == VER_PLATFORM_WIN32_NT
 
80
      && osver.dwMajorVersion == 4)
 
81
      s_hSecDll = LoadLibrary("security.dll");
 
82
    else
 
83
      s_hSecDll = LoadLibrary("secur32.dll");
 
84
    if(! s_hSecDll)
 
85
      return CURLE_FAILED_INIT;
 
86
 
 
87
    /* Get address of the InitSecurityInterfaceA function from the SSPI dll */
 
88
    pInitSecurityInterface = (INIT_SECURITY_INTERFACE_A)
 
89
      GetProcAddress(s_hSecDll, "InitSecurityInterfaceA");
 
90
    if(! pInitSecurityInterface)
 
91
      return CURLE_FAILED_INIT;
 
92
 
 
93
    /* Get pointer to Security Service Provider Interface dispatch table */
 
94
    s_pSecFn = pInitSecurityInterface();
 
95
    if(! s_pSecFn)
 
96
      return CURLE_FAILED_INIT;
 
97
 
 
98
  }
 
99
  return CURLE_OK;
 
100
}
 
101
 
 
102
 
 
103
/*
 
104
 * Curl_sspi_global_cleanup()
 
105
 *
 
106
 * This deinitializes the Security Service Provider Interface from libcurl.
 
107
 */
 
108
 
 
109
void
 
110
Curl_sspi_global_cleanup(void)
 
111
{
 
112
  if(s_hSecDll) {
 
113
    FreeLibrary(s_hSecDll);
 
114
    s_hSecDll = NULL;
 
115
    s_pSecFn = NULL;
 
116
  }
 
117
}
 
118
 
 
119
#endif /* USE_WINDOWS_SSPI */