~ubuntu-branches/ubuntu/oneiric/likewise-open/oneiric

« back to all changes in this revision

Viewing changes to krb5/src/lib/krb5/ccache/ccapi/winccld.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Salley
  • Date: 2010-11-22 12:06:00 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20101122120600-8lba1fpceot71wlb
Tags: 6.0.0.53010-1
Likewise Open 6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if defined(_WIN32)
 
2
/*
 
3
 * winccld.c --- routine for dynamically loading the ccache DLL if
 
4
 * it's present.
 
5
 */
 
6
 
 
7
#include <windows.h>
 
8
#include <stdio.h>
 
9
#include "k5-int.h"
 
10
#include "stdcc.h"
 
11
 
 
12
/* from fcc-proto.h */
 
13
extern const krb5_cc_ops krb5_fcc_ops;
 
14
 
 
15
#define KRB5_WINCCLD_C_
 
16
#include "winccld.h"
 
17
 
 
18
static int krb5_win_ccdll_loaded = 0;
 
19
 
 
20
extern void krb5_win_ccdll_load();
 
21
extern int krb5_is_ccdll_loaded();
 
22
 
 
23
/*
 
24
 * return codes
 
25
 */
 
26
#define LF_OK           0
 
27
#define LF_NODLL        1
 
28
#define LF_NOFUNC       2
 
29
 
 
30
#ifdef _WIN64
 
31
#define KRBCC_DLL      "krbcc64.dll"
 
32
#else
 
33
#define KRBCC_DLL      "krbcc32.dll"
 
34
#endif
 
35
 
 
36
static int LoadFuncs(const char* dll_name, FUNC_INFO fi[],
 
37
                     HINSTANCE* ph, int debug);
 
38
 
 
39
static int LoadFuncs(const char* dll_name, FUNC_INFO fi[],
 
40
                     HINSTANCE* ph, int debug)
 
41
{
 
42
    HINSTANCE h;
 
43
    int i, n;
 
44
    int error = 0;
 
45
 
 
46
    if (ph) *ph = 0;
 
47
 
 
48
    for (n = 0; fi[n].func_ptr_var; n++) {
 
49
        *(fi[n].func_ptr_var) = 0;
 
50
    }
 
51
 
 
52
    if (!(h = LoadLibrary(dll_name))) {
 
53
        /* Get error for source debugging purposes. */
 
54
        error = (int)GetLastError();
 
55
        return LF_NODLL;
 
56
    }
 
57
 
 
58
    if (debug)
 
59
        printf("Loaded %s\n", dll_name);
 
60
    for (i = 0; !error && (i < n); i++) {
 
61
        void* p = (void*)GetProcAddress(h, fi[i].func_name);
 
62
        if (!p) {
 
63
            if (debug)
 
64
                printf("Could not get function: %s\n", fi[i].func_name);
 
65
            error = 1;
 
66
        } else {
 
67
            *(fi[i].func_ptr_var) = p;
 
68
            if (debug)
 
69
                printf("Loaded function %s at 0x%08X\n", fi[i].func_name, p);
 
70
        }
 
71
    }
 
72
    if (error) {
 
73
        for (i = 0; i < n; i++) {
 
74
            *(fi[i].func_ptr_var) = 0;
 
75
        }
 
76
        FreeLibrary(h);
 
77
        return LF_NOFUNC;
 
78
    }
 
79
    if (ph) *ph = h;
 
80
    return LF_OK;
 
81
}
 
82
 
 
83
void krb5_win_ccdll_load(context)
 
84
        krb5_context    context;
 
85
{
 
86
        krb5_cc_register(context, &krb5_fcc_ops, 0);
 
87
        if (krb5_win_ccdll_loaded)
 
88
                return;
 
89
        if (LoadFuncs(KRBCC_DLL, krbcc_fi, 0, 0))
 
90
                return;         /* Error, give up */
 
91
        krb5_win_ccdll_loaded = 1;
 
92
        krb5_cc_dfl_ops = &krb5_cc_stdcc_ops; /* Use stdcc! */
 
93
}
 
94
 
 
95
int krb5_is_ccdll_loaded()
 
96
{
 
97
        return krb5_win_ccdll_loaded;
 
98
}
 
99
 
 
100
#endif  /* Windows */