~ubuntu-branches/ubuntu/precise/krb5/precise-updates

« back to all changes in this revision

Viewing changes to src/windows/identity/uilib/propsheet.c

  • Committer: Package Import Robot
  • Author(s): Sam Hartman
  • Date: 2011-12-01 19:34:41 UTC
  • mfrom: (28.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20111201193441-9tipg3aru1jsidyv
Tags: 1.10+dfsg~alpha1-6
* Fix segfault with unknown hostnames in krb5_sname_to_principal,
  Closes: #650671
* Indicate that this library breaks libsmbclient versions that depend on
  krb5_locate_kdc, Closes: #650603, #650611

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2005 Massachusetts Institute of Technology
3
 
 *
4
 
 * Permission is hereby granted, free of charge, to any person
5
 
 * obtaining a copy of this software and associated documentation
6
 
 * files (the "Software"), to deal in the Software without
7
 
 * restriction, including without limitation the rights to use, copy,
8
 
 * modify, merge, publish, distribute, sublicense, and/or sell copies
9
 
 * of the Software, and to permit persons to whom the Software is
10
 
 * furnished to do so, subject to the following conditions:
11
 
 *
12
 
 * The above copyright notice and this permission notice shall be
13
 
 * included in all copies or substantial portions of the Software.
14
 
 *
15
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
 
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
 
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
 
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 
 * SOFTWARE.
23
 
 */
24
 
 
25
 
/* $Id$ */
26
 
 
27
 
#define _NIMLIB_
28
 
 
29
 
#include<khuidefs.h>
30
 
#include<utils.h>
31
 
#ifdef DEBUG
32
 
#include<assert.h>
33
 
#endif
34
 
 
35
 
CRITICAL_SECTION cs_props;
36
 
 
37
 
void
38
 
ps_init(void) {
39
 
    InitializeCriticalSection(&cs_props);
40
 
}
41
 
 
42
 
void
43
 
ps_exit(void) {
44
 
    DeleteCriticalSection(&cs_props);
45
 
}
46
 
 
47
 
KHMEXP khm_int32 KHMAPI
48
 
khui_ps_create_sheet(khui_property_sheet ** sheet)
49
 
{
50
 
    khui_property_sheet * ps;
51
 
 
52
 
    ps = PMALLOC(sizeof(*ps));
53
 
    ZeroMemory(ps, sizeof(*ps));
54
 
 
55
 
    ps->header.dwSize = sizeof(ps->header);
56
 
    ps->header.dwFlags = PSH_MODELESS | PSH_PROPTITLE;
57
 
    ps->status = KHUI_PS_STATUS_NONE;
58
 
 
59
 
    *sheet = ps;
60
 
 
61
 
    return KHM_ERROR_SUCCESS;
62
 
}
63
 
 
64
 
KHMEXP khm_int32 KHMAPI
65
 
khui_ps_add_page(khui_property_sheet * sheet,
66
 
                 khm_int32 credtype,
67
 
                 khm_int32 ordinal,
68
 
                 LPPROPSHEETPAGE ppage,
69
 
                 khui_property_page ** page)
70
 
{
71
 
    khui_property_page * p;
72
 
 
73
 
    p = PMALLOC(sizeof(*p));
74
 
    ZeroMemory(p, sizeof(*p));
75
 
 
76
 
    p->credtype = credtype;
77
 
    p->ordinal = ordinal;
78
 
    p->p_page = ppage;
79
 
 
80
 
    EnterCriticalSection(&cs_props);
81
 
    QPUT(sheet, p);
82
 
    sheet->n_pages++;
83
 
    LeaveCriticalSection(&cs_props);
84
 
 
85
 
    if(page)
86
 
        *page = p;
87
 
 
88
 
    return KHM_ERROR_SUCCESS;
89
 
}
90
 
 
91
 
KHMEXP khm_int32 KHMAPI
92
 
khui_ps_find_page(khui_property_sheet * sheet,
93
 
                  khm_int32 credtype,
94
 
                  khui_property_page ** page)
95
 
{
96
 
    khui_property_page * p;
97
 
 
98
 
    EnterCriticalSection(&cs_props);
99
 
    p = QTOP(sheet);
100
 
 
101
 
    while(p) {
102
 
        if(p->credtype == credtype)
103
 
            break;
104
 
        p = QNEXT(p);
105
 
    }
106
 
    LeaveCriticalSection(&cs_props);
107
 
 
108
 
    if(p) {
109
 
        *page = p;
110
 
        return KHM_ERROR_SUCCESS;
111
 
    } else {
112
 
        *page = NULL;
113
 
        return KHM_ERROR_NOT_FOUND;
114
 
    }
115
 
}
116
 
 
117
 
int __cdecl
118
 
ps_order_func(const void *l, const void * r) {
119
 
    khui_property_page * lp;
120
 
    khui_property_page * rp;
121
 
 
122
 
    lp = *(khui_property_page **)l;
123
 
    rp = *(khui_property_page **)r;
124
 
 
125
 
    if (lp->ordinal == rp->ordinal)
126
 
        return lp->credtype - rp->credtype;
127
 
    else
128
 
        return lp->ordinal - rp->ordinal;
129
 
}
130
 
 
131
 
KHMEXP HWND KHMAPI
132
 
khui_ps_show_sheet(HWND parent, khui_property_sheet * s)
133
 
{
134
 
    khui_property_page * p;
135
 
    HPROPSHEETPAGE phpsp[KHUI_PS_MAX_PSP];
136
 
    khui_property_page * ppgs[KHUI_PS_MAX_PSP];
137
 
    int i;
138
 
    INT_PTR prv;
139
 
    HWND hw;
140
 
 
141
 
    EnterCriticalSection(&cs_props);
142
 
 
143
 
    s->header.hwndParent = parent;
144
 
    s->header.nPages = s->n_pages;
145
 
 
146
 
    p = QTOP(s);
147
 
    i = 0;
148
 
    while(p) {
149
 
        p->h_page = CreatePropertySheetPage(p->p_page);
150
 
#ifdef DEBUG
151
 
        assert(p->h_page);
152
 
#endif
153
 
        ppgs[i++] = p;
154
 
        p = QNEXT(p);
155
 
    }
156
 
 
157
 
#ifdef DEBUG
158
 
    assert(i == s->n_pages);
159
 
#endif
160
 
 
161
 
    qsort(ppgs, s->n_pages, sizeof(ppgs[0]), ps_order_func);
162
 
 
163
 
    for (i=0; i < s->n_pages; i++) {
164
 
        phpsp[i] = ppgs[i]->h_page;
165
 
    }
166
 
 
167
 
    s->header.phpage = phpsp;
168
 
 
169
 
    prv = PropertySheet(&s->header);
170
 
 
171
 
    s->header.phpage = NULL;
172
 
 
173
 
    if(prv <= 0) {
174
 
#ifdef DEBUG
175
 
        assert(FALSE);
176
 
#endif
177
 
        /*TODO: better handling for this */
178
 
        hw = NULL;
179
 
    } else {
180
 
        s->status = KHUI_PS_STATUS_RUNNING;
181
 
 
182
 
        hw = (HWND) prv;
183
 
        s->hwnd = hw;
184
 
        s->hwnd_page = PropSheet_GetCurrentPageHwnd(hw);
185
 
    }
186
 
    LeaveCriticalSection(&cs_props);
187
 
 
188
 
    return hw;
189
 
}
190
 
 
191
 
KHMEXP LRESULT KHMAPI
192
 
khui_ps_check_message(khui_property_sheet * sheet,
193
 
                      PMSG pmsg)
194
 
{
195
 
    LRESULT lr;
196
 
 
197
 
    if(sheet->hwnd == NULL)
198
 
        return FALSE;
199
 
 
200
 
    lr = PropSheet_IsDialogMessage(sheet->hwnd, pmsg);
201
 
    if(lr) {
202
 
        sheet->hwnd_page = PropSheet_GetCurrentPageHwnd(sheet->hwnd);
203
 
        if(sheet->hwnd_page == NULL &&
204
 
           sheet->status == KHUI_PS_STATUS_RUNNING)
205
 
 
206
 
            sheet->status = KHUI_PS_STATUS_DONE;
207
 
    }
208
 
 
209
 
    return lr;
210
 
}
211
 
 
212
 
KHMEXP khm_int32 KHMAPI
213
 
khui_ps_destroy_sheet(khui_property_sheet * sheet)
214
 
{
215
 
    khui_property_page * p;
216
 
 
217
 
    EnterCriticalSection(&cs_props);
218
 
 
219
 
    DestroyWindow(sheet->hwnd);
220
 
    sheet->hwnd = NULL;
221
 
 
222
 
    QGET(sheet, &p);
223
 
    while(p) {
224
 
        PFREE(p);
225
 
        QGET(sheet, &p);
226
 
    }
227
 
    PFREE(sheet);
228
 
 
229
 
    LeaveCriticalSection(&cs_props);
230
 
 
231
 
    return KHM_ERROR_SUCCESS;
232
 
}