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

« back to all changes in this revision

Viewing changes to src/windows/identity/sample/templates/credprov/plugin.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) 2006 Secure Endpoints Inc.
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
 
#include "credprov.h"
28
 
#include<assert.h>
29
 
 
30
 
/* This file provides the message processing function and the support
31
 
   routines for implementing our plugin.  Note that some of the
32
 
   message processing routines have been moved to other source files
33
 
   based on their use.
34
 
*/
35
 
 
36
 
khm_int32 credtype_id = KCDB_CREDTYPE_INVALID;
37
 
khm_handle g_credset = NULL;
38
 
 
39
 
/* Handler for system messages.  The only two we handle are
40
 
   KMSG_SYSTEM_INIT and KMSG_SYSTEM_EXIT. */
41
 
khm_int32 KHMAPI
42
 
handle_kmsg_system(khm_int32 msg_type,
43
 
                   khm_int32 msg_subtype,
44
 
                   khm_ui_4  uparam,
45
 
                   void *    vparam) {
46
 
    khm_int32 rv = KHM_ERROR_SUCCESS;
47
 
 
48
 
    switch (msg_subtype) {
49
 
 
50
 
        /* This is the first message that will be received by a
51
 
           plugin.  We use it to perform initialization operations
52
 
           such as registering any credential types, data types and
53
 
           attributes. */
54
 
    case KMSG_SYSTEM_INIT:
55
 
        {
56
 
            kcdb_credtype ct;
57
 
            wchar_t short_desc[KCDB_MAXCCH_SHORT_DESC];
58
 
            wchar_t long_desc[KCDB_MAXCCH_LONG_DESC];
59
 
            khui_config_node cnode;
60
 
            khui_config_node_reg creg;
61
 
 
62
 
            /* First and foremost, we need to register a credential
63
 
               type. */
64
 
            ZeroMemory(&ct, sizeof(ct));
65
 
            ct.id = KCDB_CREDTYPE_AUTO;
66
 
            ct.name = MYCREDTYPE_NAMEW;
67
 
 
68
 
            short_desc[0] = L'\0';
69
 
            LoadString(hResModule, IDS_CT_SHORT_DESC,
70
 
                       short_desc, ARRAYLENGTH(short_desc));
71
 
 
72
 
            long_desc[0] = L'\0';
73
 
            LoadString(hResModule, IDS_CT_LONG_DESC,
74
 
                       long_desc, ARRAYLENGTH(long_desc));
75
 
 
76
 
            ct.icon = NULL;     /* We skip the icon for now, but you
77
 
                                   can assign a handle to an icon
78
 
                                   here.  The icon will be used to
79
 
                                   represent the credentials type.*/
80
 
 
81
 
            kmq_create_subscription(plugin_msg_proc, &ct.sub);
82
 
 
83
 
            ct.is_equal = cred_is_equal;
84
 
 
85
 
            rv = kcdb_credtype_register(&ct, &credtype_id);
86
 
 
87
 
            /* We create a global credential set that we use in the
88
 
               plug-in thread.  This alleviates the need to create one
89
 
               everytime we need one. Keep in mind that this should
90
 
               only be used in the plug-in thread and should not be
91
 
               touched from the UI thread or any other thread. */
92
 
            kcdb_credset_create(&g_credset);
93
 
 
94
 
            /* TODO: Perform additional initialization operations. */
95
 
 
96
 
            /* TODO: Also list out the credentials of this type that
97
 
               already exist. */
98
 
 
99
 
            /* Now we register our configuration panels. */
100
 
 
101
 
 
102
 
            /* This configuration panel is the one that controls
103
 
               general options.  We leave the identity specific and
104
 
               identity defaults for other configuration panels. */
105
 
 
106
 
            ZeroMemory(&creg, sizeof(creg));
107
 
 
108
 
            short_desc[0] = L'\0';
109
 
 
110
 
            LoadString(hResModule, IDS_CFG_SHORT_DESC,
111
 
                       short_desc, ARRAYLENGTH(short_desc));
112
 
 
113
 
            long_desc[0] = L'\0';
114
 
 
115
 
            LoadString(hResModule, IDS_CFG_LONG_DESC,
116
 
                       long_desc, ARRAYLENGTH(long_desc));
117
 
 
118
 
            creg.name = CONFIGNODE_MAIN;
119
 
            creg.short_desc = short_desc;
120
 
            creg.long_desc = long_desc;
121
 
            creg.h_module = hResModule;
122
 
            creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG);
123
 
            creg.dlg_proc = config_dlgproc;
124
 
            creg.flags = 0;
125
 
 
126
 
            khui_cfg_register(NULL, &creg);
127
 
 
128
 
            /* Now we do the identity specific and identity default
129
 
               configuration panels. "KhmIdentities" is a predefined
130
 
               configuration node under which all the identity spcific
131
 
               configuration is managed. */
132
 
 
133
 
            if (KHM_FAILED(khui_cfg_open(NULL, L"KhmIdentities", &cnode))) {
134
 
                /* this should always work */
135
 
                assert(FALSE);
136
 
                rv = KHM_ERROR_NOT_FOUND;
137
 
                break;
138
 
            }
139
 
 
140
 
            /* First the tab panel for defaults for all identities */
141
 
 
142
 
            ZeroMemory(&creg, sizeof(creg));
143
 
 
144
 
            short_desc[0] = L'\0';
145
 
            LoadString(hResModule, IDS_CFG_IDS_SHORT_DESC,
146
 
                       short_desc, ARRAYLENGTH(short_desc));
147
 
            long_desc[0] = L'\0';
148
 
            LoadString(hResModule, IDS_CFG_IDS_LONG_DESC,
149
 
                       long_desc, ARRAYLENGTH(long_desc));
150
 
 
151
 
            creg.name = CONFIGNODE_ALL_ID;
152
 
            creg.short_desc = short_desc;
153
 
            creg.long_desc = long_desc;
154
 
            creg.h_module = hResModule;
155
 
            creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG_IDS);
156
 
            creg.dlg_proc = config_ids_dlgproc;
157
 
            creg.flags = KHUI_CNFLAG_SUBPANEL;
158
 
 
159
 
            khui_cfg_register(cnode, &creg);
160
 
 
161
 
            /* Now the panel for per identity configuration */
162
 
 
163
 
            ZeroMemory(&creg, sizeof(creg));
164
 
 
165
 
            short_desc[0] = L'\0';
166
 
            LoadString(hResModule, IDS_CFG_ID_SHORT_DESC,
167
 
                       short_desc, ARRAYLENGTH(short_desc));
168
 
            long_desc[0] = L'\0';
169
 
            LoadString(hResModule, IDS_CFG_ID_LONG_DESC,
170
 
                       long_desc, ARRAYLENGTH(long_desc));
171
 
 
172
 
            creg.name = CONFIGNODE_PER_ID;
173
 
            creg.short_desc = short_desc;
174
 
            creg.long_desc = long_desc;
175
 
            creg.h_module = hResModule;
176
 
            creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG_ID);
177
 
            creg.dlg_proc = config_id_dlgproc;
178
 
            creg.flags = KHUI_CNFLAG_SUBPANEL | KHUI_CNFLAG_PLURAL;
179
 
 
180
 
            khui_cfg_register(cnode, &creg);
181
 
 
182
 
            khui_cfg_release(cnode);
183
 
        }
184
 
        break;
185
 
 
186
 
        /* This is the last message that will be received by the
187
 
           plugin. */
188
 
    case KMSG_SYSTEM_EXIT:
189
 
        {
190
 
            khui_config_node cnode;
191
 
            khui_config_node cn_idents;
192
 
 
193
 
            /* It should not be assumed that initialization of the
194
 
               plugin went well at this point since we receive a
195
 
               KMSG_SYSTEM_EXIT even if the initialization failed. */
196
 
 
197
 
            if (credtype_id != KCDB_CREDTYPE_INVALID) {
198
 
                kcdb_credtype_unregister(credtype_id);
199
 
                credtype_id = KCDB_CREDTYPE_INVALID;
200
 
            }
201
 
 
202
 
            if (g_credset) {
203
 
                kcdb_credset_delete(g_credset);
204
 
                g_credset = NULL;
205
 
            }
206
 
 
207
 
            /* Now unregister any configuration nodes we registered. */
208
 
 
209
 
            if (KHM_SUCCEEDED(khui_cfg_open(NULL, CONFIGNODE_MAIN, &cnode))) {
210
 
                khui_cfg_remove(cnode);
211
 
                khui_cfg_release(cnode);
212
 
            }
213
 
 
214
 
            if (KHM_SUCCEEDED(khui_cfg_open(NULL, L"KhmIdentities", &cn_idents))) {
215
 
                if (KHM_SUCCEEDED(khui_cfg_open(cn_idents,
216
 
                                                CONFIGNODE_ALL_ID,
217
 
                                                &cnode))) {
218
 
                    khui_cfg_remove(cnode);
219
 
                    khui_cfg_release(cnode);
220
 
                }
221
 
 
222
 
                if (KHM_SUCCEEDED(khui_cfg_open(cn_idents,
223
 
                                                CONFIGNODE_PER_ID,
224
 
                                                &cnode))) {
225
 
                    khui_cfg_remove(cnode);
226
 
                    khui_cfg_release(cnode);
227
 
                }
228
 
 
229
 
                khui_cfg_release(cn_idents);
230
 
            }
231
 
 
232
 
            /* TODO: Perform additional uninitialization
233
 
               operations. */
234
 
        }
235
 
        break;
236
 
    }
237
 
 
238
 
    return rv;
239
 
}
240
 
 
241
 
/* Handler for credentials the refresh message. */
242
 
khm_int32
243
 
handle_kmsg_cred_refresh(void) {
244
 
    /* TODO: Re-enumerate the credentials of our credentials type */
245
 
 
246
 
    /*
247
 
      Re-enumerating credentials would look something like this:
248
 
 
249
 
      - flush all credentials from g_credset (kcdb_credset_flush())
250
 
 
251
 
      - list out the credentials and add them to g_credset
252
 
 
253
 
      - collect the credentials from g_credset to the root credentials
254
 
        set. (kcdb_credset_collect())
255
 
 
256
 
      Note that when listing credentials, each credential must be
257
 
      populated with enough information to locate the actual
258
 
      credential at a later time.
259
 
     */
260
 
 
261
 
    return KHM_ERROR_SUCCESS;
262
 
}
263
 
 
264
 
/* Handler for destroying credentials */
265
 
khm_int32
266
 
handle_kmsg_cred_destroy_creds(khui_action_context * ctx) {
267
 
    /* TODO: Destroy credentials of our type as specified by the
268
 
       action context passed in through vparam. */
269
 
 
270
 
    /* The credential set in ctx->credset contains the credentials
271
 
       that are to be destroyed. */
272
 
 
273
 
    return KHM_ERROR_SUCCESS;
274
 
}
275
 
 
276
 
/* Begin a property sheet */
277
 
khm_int32
278
 
handle_kmsg_cred_pp_begin(khui_property_sheet * ps) {
279
 
 
280
 
    /* TODO: Provide the information necessary to show a property
281
 
       page for a credentials belonging to our credential type. */
282
 
 
283
 
    PROPSHEETPAGE *p;
284
 
 
285
 
    if (ps->credtype == credtype_id &&
286
 
        ps->cred) {
287
 
        /* We have been requested to show a property sheet for one of
288
 
           our credentials. */
289
 
        p = malloc(sizeof(*p));
290
 
        ZeroMemory(p, sizeof(*p));
291
 
 
292
 
        p->dwSize = sizeof(*p);
293
 
        p->dwFlags = 0;
294
 
        p->hInstance = hResModule;
295
 
        p->pszTemplate = MAKEINTRESOURCE(IDD_PP_CRED);
296
 
        p->pfnDlgProc = pp_cred_dlg_proc;
297
 
        p->lParam = (LPARAM) ps;
298
 
        khui_ps_add_page(ps, credtype_id, 0, p, NULL);
299
 
    }
300
 
 
301
 
    return KHM_ERROR_SUCCESS;
302
 
}
303
 
 
304
 
/* End a property sheet */
305
 
khm_int32
306
 
handle_kmsg_cred_pp_end(khui_property_sheet * ps) {
307
 
    /* TODO: Handle the end of a property sheet. */
308
 
 
309
 
    khui_property_page * p = NULL;
310
 
 
311
 
    khui_ps_find_page(ps, credtype_id, &p);
312
 
    if (p) {
313
 
        if (p->p_page)
314
 
            free(p->p_page);
315
 
        p->p_page = NULL;
316
 
    }
317
 
 
318
 
    return KHM_ERROR_SUCCESS;
319
 
}
320
 
 
321
 
/* IP address change notification */
322
 
khm_int32
323
 
handle_kmsg_cred_addr_change(void) {
324
 
    /* TODO: Handle this message. */
325
 
 
326
 
    return KHM_ERROR_SUCCESS;
327
 
}
328
 
 
329
 
/* Message dispatcher for credentials messages. */
330
 
khm_int32 KHMAPI
331
 
handle_kmsg_cred(khm_int32 msg_type,
332
 
                 khm_int32 msg_subtype,
333
 
                 khm_ui_4  uparam,
334
 
                 void *    vparam) {
335
 
    khm_int32 rv = KHM_ERROR_SUCCESS;
336
 
 
337
 
    switch(msg_subtype) {
338
 
    case KMSG_CRED_REFRESH:
339
 
        return handle_kmsg_cred_refresh();
340
 
 
341
 
    case KMSG_CRED_DESTROY_CREDS:
342
 
        return handle_kmsg_cred_destroy_creds((khui_action_context *) vparam);
343
 
 
344
 
    case KMSG_CRED_PP_BEGIN:
345
 
        return handle_kmsg_cred_pp_begin((khui_property_sheet *) vparam);
346
 
 
347
 
    case KMSG_CRED_PP_END:
348
 
        return handle_kmsg_cred_pp_end((khui_property_sheet *) vparam);
349
 
 
350
 
    case KMSG_CRED_ADDR_CHANGE:
351
 
        return handle_kmsg_cred_addr_change();
352
 
 
353
 
    default:
354
 
        /* Credentials acquisition messages are all handled in a
355
 
           different source file. */
356
 
        if (IS_CRED_ACQ_MSG(msg_subtype))
357
 
            return handle_cred_acq_msg(msg_type, msg_subtype,
358
 
                                       uparam, vparam);
359
 
    }
360
 
 
361
 
    return rv;
362
 
}
363
 
 
364
 
 
365
 
/* This is the main message handler for our plugin.  All the plugin
366
 
   messages end up here where we either handle it directly or dispatch
367
 
   it to other handlers. */
368
 
khm_int32 KHMAPI plugin_msg_proc(khm_int32 msg_type,
369
 
                                 khm_int32 msg_subtype,
370
 
                                 khm_ui_4  uparam,
371
 
                                 void * vparam) {
372
 
 
373
 
    switch(msg_type) {
374
 
    case KMSG_SYSTEM:
375
 
        return handle_kmsg_system(msg_type, msg_subtype, uparam, vparam);
376
 
 
377
 
    case KMSG_CRED:
378
 
        return handle_kmsg_cred(msg_type, msg_subtype, uparam, vparam);
379
 
    }
380
 
 
381
 
    return KHM_ERROR_SUCCESS;
382
 
}