Example #1
0
void k4_write_identity_data(k4_dlg_data * d) {
    khm_handle csp_ident = NULL;
    khm_handle csp_k4 = NULL;
    khm_handle identity = NULL;

    if (KHM_SUCCEEDED(khui_cw_get_primary_id(d->nc, &identity)) &&
        KHM_SUCCEEDED(kcdb_identity_get_config(identity,
                                               KHM_FLAG_CREATE,
                                               &csp_ident))) {
        khc_open_space(csp_ident, CSNAME_KRB4CRED,
                       KHM_FLAG_CREATE | KCONF_FLAG_WRITEIFMOD,
                       &csp_k4);

        if (csp_k4) {
            khc_write_int32(csp_k4, L"Krb4NewCreds", !!d->k4_enabled);
            khc_write_int32(csp_k4, L"Krb4Method", d->method);

            khc_close_space(csp_k4);
        }

        khc_close_space(csp_ident);
    }

    if (identity)
        kcdb_identity_release(identity);
}
Example #2
0
static khm_int32 KHMAPI
collect_kca_cert_names(khm_handle cred, void * rock)
{
    wchar_t *str = (wchar_t *) rock;
    wchar_t cert_name[KCDB_MAXCCH_NAME] = L"";
    FILETIME ft_now;
    FILETIME ft_expire;
    khm_size cb;

    cb = sizeof(ft_expire);
    if (KHM_FAILED(kcdb_cred_get_attr(cred, KCDB_ATTR_EXPIRE, NULL, &ft_expire, &cb)))
        return KHM_ERROR_SUCCESS;

    GetSystemTimeAsFileTime(&ft_now);
    if (CompareFileTime(&ft_now, &ft_expire) >= 0)
        return KHM_ERROR_SUCCESS;

    cb = sizeof(cert_name);

    if (KHM_SUCCEEDED(kcdb_cred_get_attr(cred, attr_id_auth_realm, NULL, cert_name, &cb)) &&
        cert_name[0] != L'\0') {
        StringCchCat(str, COLLECT_STR_LEN, cert_name);
        StringCchCat(str, COLLECT_STR_LEN, L"\n");
    } else if ((cb = sizeof(cert_name)) &&
               KHM_SUCCEEDED(kcdb_cred_get_attr(cred, attr_id_subj_email, NULL, cert_name, &cb))
               && cert_name[0] != L'\0') {
        StringCchCat(str, COLLECT_STR_LEN, cert_name);
        StringCchCat(str, COLLECT_STR_LEN, L"\n");
    }

    return KHM_ERROR_SUCCESS;
}
Example #3
0
void
khm_hide_main_window(void) {
    khm_handle csp_notices = NULL;
    khm_int32 show_warning = FALSE;

    if (khm_nCmdShow != SW_MINIMIZE &&
        KHM_SUCCEEDED(khc_open_space(NULL, L"CredWindow\\Notices",
                                     KHM_PERM_WRITE, &csp_notices)) &&
        KHM_SUCCEEDED(khc_read_int32(csp_notices, L"MinimizeWarning",
                                     &show_warning)) &&
        show_warning != 0) {

        khui_alert * alert;
        wchar_t title[KHUI_MAXCCH_TITLE];
        wchar_t msg[KHUI_MAXCCH_MESSAGE];

        LoadString(khm_hInstance, IDS_WARN_WM_TITLE,
                   title, ARRAYLENGTH(title));
        LoadString(khm_hInstance, IDS_WARN_WM_MSG,
                   msg, ARRAYLENGTH(msg));

        khui_alert_create_simple(title, msg, KHERR_INFO, &alert);
        khui_alert_set_flags(alert, KHUI_ALERT_FLAG_REQUEST_BALLOON,
                             KHUI_ALERT_FLAG_REQUEST_BALLOON);

        khui_alert_show(alert);

        khc_write_int32(csp_notices, L"MinimizeWarning", 0);
    }

    if (csp_notices != NULL)
        khc_close_space(csp_notices);

    ShowWindow(khm_hwnd_main, SW_HIDE);
}
Example #4
0
static HWND
cfgui_create_config_node_window(HWND hwnd, khui_config_node node) {
    khui_config_node_reg reg;
    khm_int32 rv;
    HWND hw_new;

    khui_config_node parent;

    if (KHM_SUCCEEDED(khui_cfg_get_parent(node, &parent))) {
        HWND hwp;

        hwp = khui_cfg_get_hwnd(parent);

        if (hwp == NULL)
            cfgui_create_config_node_window(hwnd, parent);

        khui_cfg_release(parent);
    }

    rv = khui_cfg_get_reg(node, &reg);
#ifdef DEBUG
    assert(KHM_SUCCEEDED(rv));
#endif
    hw_new = CreateDialogParam(reg.h_module,
                               reg.dlg_template,
                               hwnd,
                               reg.dlg_proc,
                               (LPARAM) node);
#ifdef DEBUG
    assert(hw_new);
#endif
    khui_cfg_set_hwnd(node, hw_new);

    return hw_new;
}
Example #5
0
void
khm_close_main_window(void) {
    khm_handle csp_cw;
    BOOL keep_running = FALSE;

    if (KHM_SUCCEEDED(khc_open_space(NULL, L"CredWindow",
                                     KHM_PERM_READ, &csp_cw))) {
        khm_int32 t;

        if (KHM_SUCCEEDED(khc_read_int32(csp_cw, L"KeepRunning",
                                         &t))) {
            keep_running = t;
        } else {
#ifdef DEBUG
            assert(FALSE);
#endif
        }

        khc_close_space(csp_cw);
    } else {
#ifdef DEBUG
        assert(FALSE);
#endif
    }

    if (keep_running)
        khm_hide_main_window();
    else
        DestroyWindow(khm_hwnd_main);
}
Example #6
0
khm_int32
handle_kmsg_system_exit(void)
{
    khui_config_node cnode;
    khui_config_node cn_idents;

    /* It should not be assumed that initialization of the plugin went
       well at this point since we receive a KMSG_SYSTEM_EXIT even if
       the initialization failed. */

    if (credtype_id != KCDB_CREDTYPE_INVALID) {
        kcdb_credtype_unregister(credtype_id);
        credtype_id = KCDB_CREDTYPE_INVALID;
    }

    if (g_credset) {
        kcdb_credset_delete(g_credset);
        g_credset = NULL;
    }

    /* Now unregister any configuration nodes we registered. */

    if (KHM_SUCCEEDED(khui_cfg_open(NULL, CONFIGNODE_MAIN, &cnode))) {
        khui_cfg_remove(cnode);
        khui_cfg_release(cnode);
    }

    if (KHM_SUCCEEDED(khui_cfg_open(NULL, L"KhmIdentities", &cn_idents))) {
        if (KHM_SUCCEEDED(khui_cfg_open(cn_idents,
                                        CONFIGNODE_ALL_ID,
                                        &cnode))) {
            khui_cfg_remove(cnode);
            khui_cfg_release(cnode);
        }

        if (KHM_SUCCEEDED(khui_cfg_open(cn_idents,
                                        CONFIGNODE_PER_ID,
                                        &cnode))) {
            khui_cfg_remove(cnode);
            khui_cfg_release(cnode);
        }

        khui_cfg_release(cn_idents);
    }

    if (h_idprov_event != NULL) {
	CloseHandle(h_idprov_event);
	h_idprov_event = NULL;
    }

    /* TODO: Perform additional uninitialization operations. */

    return KHM_ERROR_SUCCESS;
}
Example #7
0
void
khm_create_main_window(void) {
    wchar_t buf[1024];
    khm_handle csp_cw = NULL;
    RECT r;

    LoadString(khm_hInstance, IDS_MAIN_WINDOW_TITLE,
               buf, ARRAYLENGTH(buf));

    khm_hwnd_null =
        CreateWindow(MAKEINTATOM(khm_null_window_class),
                     buf,
                     0,         /* Style */
                     0, 0,      /* x, y */
                     100, 100,  /* width, height */
                     NULL,      /* parent */
                     NULL,      /* menu */
                     NULL,      /* HINSTANCE */
                     0);        /* lparam */

    if (!khm_hwnd_null)
        return;

    if (KHM_SUCCEEDED(khc_open_space(NULL, L"CredWindow",
                                     KHM_PERM_READ,
                                     &csp_cw))) {
        khm_int32 t;

        if (KHM_SUCCEEDED(khc_read_int32(csp_cw, L"DefaultWindowMode", &t))) {
            khm_set_main_window_mode(t);
        }

        khc_close_space(csp_cw);
    }

    khm_get_main_window_rect(&r);

    khm_hwnd_main =
        CreateWindowEx(WS_EX_OVERLAPPEDWINDOW | WS_EX_APPWINDOW,
                       MAKEINTATOM(khm_main_window_class),
                       buf,
                       WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN |
                       WS_CLIPSIBLINGS,
                       r.left, r.top,
                       r.right - r.left,
                       r.bottom - r.top,
                       khm_hwnd_null,
                       NULL,
                       NULL,
                       NULL);

    khui_set_main_window(khm_hwnd_main);
}
Example #8
0
khm_boolean k4_should_identity_get_k4(khm_handle ident) {
    khm_int32 idflags = 0;
    khm_int32 t = TRUE;
    khm_handle csp_ident = NULL;
    khm_handle csp_k4 = NULL;
    khm_boolean get_k4 = TRUE;
    khm_boolean id_spec = FALSE;

    if (KHM_FAILED(kcdb_identity_get_flags(ident, &idflags)))
        return FALSE;

    if (!(idflags & KCDB_IDENT_FLAG_DEFAULT)) {
        /* we only support k4 for one identity, and that is the
           default identity.  If we are trying to get tickets for a
           non-default identity, then we start off as disabled unless
           there is no default identity. */

        khm_handle defident = NULL;

        if (KHM_SUCCEEDED(kcdb_identity_get_default(&defident))) {
            kcdb_identity_release(defident);

            return FALSE;
        }
    }

    if (KHM_SUCCEEDED(kcdb_identity_get_config(ident, 0, &csp_ident))) {
        if (KHM_SUCCEEDED(khc_open_space(csp_ident, CSNAME_KRB4CRED, 0,
                                         &csp_k4))) {
            khm_int32 t = 0;

            if (KHM_SUCCEEDED(khc_read_int32(csp_k4, L"Krb4NewCreds", &t))) {
                get_k4 = !!t;
                id_spec = TRUE;
            }

            khc_close_space(csp_k4);
        }
        khc_close_space(csp_ident);
    }

    /* if there was a value specified for the identity, then that
       takes precedence. */
    if (id_spec || !get_k4)
        return get_k4;

    if (KHM_SUCCEEDED(khc_read_int32(csp_params, L"Krb4NewCreds", &t)) &&
        !t)
        return FALSE;

    return TRUE;
}
Example #9
0
/*! \internal
    \note Obtains ::cs_kmq_msg
    */
KHMEXP LRESULT KHMAPI kmq_wm_dispatch(LPARAM lparm, kmq_callback_t cb) {
    kmq_message *m;
    khm_int32 rv;

    m = (kmq_message *) lparm;

    if (m->err_ctx)
        kherr_push_context(m->err_ctx);

    rv = cb(m->type, m->subtype, m->uparam, m->vparam);

    if (m->err_ctx)
        kherr_pop_context();

    EnterCriticalSection(&cs_kmq_msg);

    m->refcount--;
    if(KHM_SUCCEEDED(rv))
        m->nCompleted++;
    else
        m->nFailed++;

    if(m->nCompleted + m->nFailed == m->nSent) {
        kmqint_put_message(m);
    }
    LeaveCriticalSection(&cs_kmq_msg);

    return TRUE;
}
Example #10
0
void
HttpRequest::FetchFaviconForDomain()
{
    HANDLE hFile = INVALID_HANDLE_VALUE;
    wchar_t domain[MAX_PATH];
    const wchar_t * domain_ptr = domain;

    {
        URL_COMPONENTS uc;

        memset(&uc, 0, sizeof(uc));
        uc.dwStructSize = sizeof(uc);
        uc.lpszHostName = domain;
        uc.dwHostNameLength = ARRAYLENGTH(domain);

        if (!WinHttpCrackUrl(m_target.c_str(), 0, 0, &uc))
            StringCchCopy(domain, ARRAYLENGTH(domain), m_target.c_str());
    }

    MuteReports();

    do {
        khm_int32 rv;

        rv = FetchResource(domain_ptr, L"/favicon.ico", icon_mimetypes);
        if (KHM_SUCCEEDED(rv) || rv != KHM_ERROR_NOT_FOUND)
            break;

        {
            wchar_t wwwdomain[MAX_PATH];

            if (SUCCEEDED(StringCbPrintf(wwwdomain, sizeof(wwwdomain), L"www.%s", domain_ptr)) &&
                (KHM_SUCCEEDED(FetchResource(wwwdomain, L"/favicon.ico", icon_mimetypes))))
                break;
        }

        domain_ptr = wcschr(domain_ptr, L'.');
        if (domain_ptr)
            domain_ptr++;
    } while(domain_ptr != NULL && *domain_ptr != L'\0');

    MuteReports(false);
    ReportComplete(false);
}
Example #11
0
static void
main_wnd_save_sizepos() {
    RECT r;
    khm_handle csp_cw;
    khm_handle csp_mw;
    const wchar_t * wconfig;

    KillTimer(khm_hwnd_main, MW_RESIZE_TIMER);

    if (khm_main_wnd_mode == KHM_MAIN_WND_MINI)
        wconfig = L"Windows\\MainMini";
    else
        wconfig = L"Windows\\Main";

    GetWindowRect(khm_hwnd_main, &r);

    if (KHM_SUCCEEDED(khc_open_space(NULL,
                                     L"CredWindow",
                                     KHM_PERM_WRITE,
                                     &csp_cw))) {
        if (KHM_SUCCEEDED(khc_open_space(csp_cw,
                                        wconfig,
                                        KHM_PERM_WRITE,
                                        &csp_mw))) {
            khm_int32 t;

            khc_write_int32(csp_mw, L"XPos", r.left);
            khc_write_int32(csp_mw, L"YPos", r.top);
            khc_write_int32(csp_mw, L"Width", r.right - r.left);
            khc_write_int32(csp_mw, L"Height", r.bottom - r.top);

            if (KHM_SUCCEEDED(khc_read_int32(csp_mw, L"Dock", &t)) &&
                t != KHM_DOCK_NONE) {
                khc_write_int32(csp_mw, L"Dock", KHM_DOCK_AUTO);
            }

            khc_close_space(csp_mw);
        }

        khc_close_space(csp_cw);
    }
}
Example #12
0
void
k4_id_read_params(k4_id_data * d) {
    khm_handle ident = NULL;
    khm_handle csp_ident = NULL;
    khm_handle csp_idk4 = NULL;
    khm_int32 flags = 0;
    khm_int32 t;

    khc_read_int32(csp_params, L"Krb4NewCreds", &d->gettix);

    ident = khui_cfg_get_data(d->cfg.ctx_node);

    if (ident == NULL) {
        d->gettix = 0;
        goto done;
    }

    kcdb_identity_get_flags(ident, &flags);

    if (!(flags & KCDB_IDENT_FLAG_DEFAULT)) {
        d->gettix = 0;
        goto done;
    }

    d->is_default_ident = TRUE;

    if (d->gettix == 0)
        goto done;

    if (KHM_FAILED(kcdb_identity_get_config(ident, 0, &csp_ident)))
        goto done;

    if (KHM_FAILED(khc_open_space(csp_ident, CSNAME_KRB4CRED,
                                  0, &csp_idk4)))
        goto close_config;

    if (KHM_SUCCEEDED(khc_read_int32(csp_idk4, L"Krb4NewCreds", &t)) &&
        !t)
        d->gettix = 1;

 close_config:
    if (csp_ident)
        khc_close_space(csp_ident);

    if (csp_idk4)
        khc_close_space(csp_idk4);

 done:
    if (ident)
        kcdb_identity_release(ident);

    return;
}
Example #13
0
/*******************************************************************
   init_module
   *****************************************************************

   This is the entry point for the module.  Each module can provide
   multiple plugins and each plugin will need a separate entry point.
   Generally, the module entry point will set up localized resources
   and register the plugins.

*/
KHMEXP khm_int32 KHMAPI init_module(kmm_module h_module) {

    khm_int32 rv = KHM_ERROR_SUCCESS;
    kmm_plugin_reg pi;
    wchar_t description[KMM_MAXCCH_DESC];
    int t;

    h_khModule = h_module;

    rv = kmm_set_locale_info(h_module, locales, n_locales);
    if(KHM_SUCCEEDED(rv)) {
        /* if the call succeeded, then NetIDMgr has picked a localized
           resource DLL for us to use. */
        hResModule = kmm_get_resource_hmodule(h_module);
    } else
        goto _exit;

    /* TODO: Perform any other required initialization operations. */

    /* register our plugin */
    ZeroMemory(&pi, sizeof(pi));

    pi.name = MYPLUGIN_NAMEW;
    pi.type = KHM_PITYPE_MISC;

    /* An icon is optional, but we provide one anyway. */
    pi.icon = LoadImage(hResModule, MAKEINTRESOURCE(IDI_PLUGIN),
                        IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
    pi.flags = 0;
    pi.msg_proc = plugin_msg_proc;
    pi.description = description;
    pi.dependencies = L"AfsCred\0";
    t = LoadString(hResModule, IDS_PLUGIN_DESC,
                   description, ARRAYLENGTH(description));
    if (!t)
        description[0] = L'\0';
    else
        description[ARRAYLENGTH(description) - 1] = L'\0';

    rv = kmm_provide_plugin(h_module, &pi);

    /* TODO: register any additional plugins */

    /* Returning a successful code (KHM_ERROR_SUCCESS) will cause the
       plugins to be initialized.  If no plugin is successfully
       registered while processing init_module or if a code other than
       KHM_ERROR_SUCCESS is returned, the module will be immediately
       unloaded. */

 _exit:
    return rv;
}
Example #14
0
void k4_read_identity_data(k4_dlg_data * d) {
    khm_handle csp_ident = NULL;
    khm_handle csp_k4 = NULL;
    khm_handle identity = NULL;

    khm_int32 idflags = 0;
    khm_int32 t;

    if (KHM_SUCCEEDED(khc_read_int32(csp_params, L"Krb4NewCreds", &t)))
        d->k4_enabled = !!t;
    else
        d->k4_enabled = TRUE;

    if (KHM_SUCCEEDED(khc_read_int32(csp_params, L"Krb4Method", &t)))
        d->method = t;
    else
        d->method = K4_METHOD_AUTO;

    if (KHM_SUCCEEDED(khc_read_int32(csp_params, L"DefaultLifetime", &t)))
        d->lifetime = t;
    else
        d->lifetime = 10 * 60 * 60; /* 10 hours */

    if (KHM_SUCCEEDED(khui_cw_get_primary_id(d->nc, &identity))) {

        if (KHM_SUCCEEDED(kcdb_identity_get_config(identity, 0,
                                                   &csp_ident))) {

            khc_open_space(csp_ident, CSNAME_KRB4CRED, 0, &csp_k4);

            if (csp_k4) {
                if (KHM_SUCCEEDED(khc_read_int32(csp_k4, L"Krb4NewCreds", &t)))
                    d->k4_enabled = !!t;
                if (KHM_SUCCEEDED(khc_read_int32(csp_k4, L"Krb4Method", &t)))
                    d->method = t;
                khc_close_space(csp_k4);
            }

            khc_close_space(csp_ident);
        }

        if (d->k4_enabled) {
            d->k4_enabled = k4_should_identity_get_k4(identity);
        }
    } else {
        d->k4_enabled = FALSE;
    }

    if (d->method < 0 || d->method > K4_METHOD_K524)
        d->method = K4_METHOD_AUTO;

    if (identity)
        kcdb_identity_release(identity);
}
Example #15
0
/* called with cs_identpro held */
static void
identpro_check_and_set_default_provider(void)
{
    wchar_t * p_order = NULL;
    khm_size cb;
    khm_handle csp_kcdb = NULL;
    khm_int32 rv;
    kcdb_identpro_i * p = NULL;
    wchar_t * e;

    if (KHM_SUCCEEDED(khc_open_space(NULL, L"KCDB", KHM_PERM_READ, &csp_kcdb))) {
        rv = khc_read_multi_string(csp_kcdb, L"IdentityProviderOrder", NULL, &cb);
        if (rv == KHM_ERROR_TOO_LONG && cb > sizeof(wchar_t) * 2) {
            p_order = PMALLOC(cb);
            rv = khc_read_multi_string(csp_kcdb, L"IdentityProviderOrder", p_order, &cb);
            if (KHM_FAILED(rv)) {
                PFREE(p_order);
                p_order = NULL;
            }
        }

        khc_close_space(csp_kcdb);
        csp_kcdb = NULL;
    }

    for (e = p_order;
         e && e[0];
         e = multi_string_next(e)) {

        p = identpro_find_by_name(e);
        if (p)
            break;
    }

    if (p != NULL) {
        if (DEFAULT_PROVIDER != p) {
            QDEL(&id_providers, p);
            QPUSH(&id_providers, p);
#ifdef DEBUG
            assert(DEFAULT_PROVIDER == p);
#endif
            kcdbint_identpro_post_message(KCDB_OP_NEW_DEFAULT, DEFAULT_PROVIDER);
        }
    }

    if (p)
        identpro_release(p);
    if (p_order)
        PFREE(p_order);
}
Example #16
0
void
khm_set_main_window_mode(int mode) {

    RECT r;
    khm_handle csp_cw;

    if (mode == khm_main_wnd_mode)
        return;

    khui_check_action(KHUI_ACTION_LAYOUT_MINI,
                      ((mode == KHM_MAIN_WND_MINI)? FALSE : TRUE));
    khui_enable_action(KHUI_MENU_LAYOUT,
                       ((mode == KHM_MAIN_WND_MINI)? FALSE : TRUE));
    khui_enable_action(KHUI_MENU_COLUMNS,
                       ((mode == KHM_MAIN_WND_MINI)? FALSE : TRUE));

    khui_refresh_actions();

    /*
     * set the window position before the global khm_main_wnd_mode
     * is updated.  otherwise, the windows position for the wrong
     * mode will be set.  Do not set the window position if the
     * main application window has not yet been created.
     */
    if (khm_hwnd_main)
        main_wnd_save_sizepos();

    khm_main_wnd_mode = mode;
    if (khm_hwnd_main) {
        khm_get_main_window_rect(&r);

        SetWindowPos(khm_hwnd_main,
                     NULL,
                     r.left, r.top,
                     r.right - r.left, r.bottom - r.top,
                     SWP_NOACTIVATE | SWP_NOOWNERZORDER |
                     SWP_NOZORDER);
    }

    if (KHM_SUCCEEDED(khc_open_space(NULL, L"CredWindow", KHM_PERM_WRITE,
                                     &csp_cw))) {

        khc_write_int32(csp_cw, L"DefaultWindowMode", mode);
        khc_close_space(csp_cw);

    }

    khm_cred_refresh();
}
Example #17
0
void
khm_cred_begin_startup_actions(void) {
    khm_handle csp_cw;

    if (khm_startup.seen)
        return;

    if (!khm_startup.remote &&
        KHM_SUCCEEDED(khc_open_space(NULL, L"CredWindow", 0, &csp_cw))) {

        khm_int32 t = 0;

        khc_read_int32(csp_cw, L"Autoinit", &t);
        if (t)
            khm_startup.autoinit = TRUE;

        t = 0;
        khc_read_int32(csp_cw, L"AutoImport", &t);
        if (t)
            khm_startup.import = TRUE;

        khc_close_space(csp_cw);

    }

    /* if this is a remote request, and no specific options were
       specified other than --renew, then we perform the default
       action, as if the user clicked on the tray icon. */
    if (khm_startup.remote &&
        !khm_startup.exit &&
        !khm_startup.destroy &&
        !khm_startup.autoinit &&
        !khm_startup.init &&
        !khm_startup.remote_exit &&
        !khm_startup.import &&
        !khm_startup.display) {

        khm_int32 def_action = khm_get_default_notifier_action();

        if (def_action > 0) {
            khui_action_trigger(def_action, NULL);
        }
    }

    khm_startup.seen = TRUE;
    khm_startup.processing = TRUE;

    khm_cred_process_startup_actions();
}
Example #18
0
/* not thread safe. only call from the plugin thread */
khm_boolean
afs_ext_klog(afs_tk_method method,
             khm_handle   identity,
             const char * service,
             const char * cell,
             const char * realm,
             const afs_conf_cell * cell_config,
             khm_int32    lifetime) {

    khm_size idx;
    khm_int32 rv = KHM_ERROR_GENERAL;
    afs_msg_klog msg;
    afs_conf_cell cellconfig;

    ZeroMemory(&msg, sizeof(msg));
    ZeroMemory(&cellconfig, sizeof(cellconfig));

    msg.cbsize = sizeof(msg);

    msg.identity = identity;
    msg.service = service;
    msg.cell = cell;
    msg.realm = realm;
    msg.lifetime = lifetime;

    msg.cell_config = &cellconfig;

    cellconfig = *cell_config;
    cellconfig.cbsize = sizeof(cellconfig);

    for (idx = 0; idx < n_extensions; idx++) {
        if (!extensions[idx].provide_token_acq ||
            (method != AFS_TOKEN_AUTO &&
             extensions[idx].token_acq.method_id != method))
            continue;

        rv = kmq_send_sub_msg(extensions[idx].sub,
                              afs_msg_type_id,
                              AFS_MSG_KLOG,
                              0,
                              (void *) &msg);

        if (KHM_SUCCEEDED(rv))
            return TRUE;
    }

    return FALSE;
}
Example #19
0
/* not thread safe.  only call from the plugin thread */
khm_boolean
afs_ext_resolve_token(const wchar_t * cell,
                      const struct ktc_token * token,
                      const struct ktc_principal * serverp,
                      const struct ktc_principal * clientp,
                      khm_handle * pident,
                      afs_tk_method * pmethod) {

    afs_msg_resolve_token rt;
    khm_size idx;
    khm_int32 rv;

    ZeroMemory(&rt, sizeof(rt));

    rt.cbsize = sizeof(rt);

    rt.cell = cell;
    rt.token = token;
    rt.serverp = serverp;
    rt.clientp = clientp;
    rt.method = AFS_TOKEN_AUTO;
    rt.ident = NULL;

    for (idx = 0; idx < n_extensions; idx++) {
        if (!extensions[idx].provide_token_acq)
            continue;

        rv = kmq_send_sub_msg(extensions[idx].sub,
                              afs_msg_type_id,
                              AFS_MSG_RESOLVE_TOKEN,
                              0,
                              (void *) &rt);

        if (KHM_SUCCEEDED(rv)) {
            assert(rt.ident != NULL);

            *pident = rt.ident;
            *pmethod = rt.method;

            return TRUE;
        }
    }

    return FALSE;
}
Example #20
0
/*! \internal
    \note Obtains ::cs_kmq_msg
    */
KHMEXP LRESULT KHMAPI kmq_wm_end(kmq_message *m, khm_int32 rv) {
    if (m->err_ctx)
        kherr_pop_context();

    EnterCriticalSection(&cs_kmq_msg);
    m->refcount--;
    if(KHM_SUCCEEDED(rv))
        m->nCompleted++;
    else
        m->nFailed++;

    if(m->nCompleted + m->nFailed == m->nSent) {
        kmqint_put_message(m);
    }
    LeaveCriticalSection(&cs_kmq_msg);

    return TRUE;
}
Example #21
0
/*! \internal
    \note Obtains ::cs_kmq_msg, ::cs_kmq_types, ::cs_kmq_msg_ref, kmq_queue::cs
    */
KHMEXP khm_int32 KHMAPI
kmq_send_message(khm_int32 type, khm_int32 subtype,
                 khm_ui_4 uparam, void * blob) {
    kmq_call c;
    khm_int32 rv = KHM_ERROR_SUCCESS;

    rv = kmqint_post_message_ex(type, subtype, uparam, blob, &c, TRUE);
    if(KHM_FAILED(rv))
        return rv;

    rv = kmq_wait(c, INFINITE);
    if(KHM_SUCCEEDED(rv) && c->nFailed > 0)
        rv = KHM_ERROR_PARTIAL;

    kmq_free_call(c);

    return rv;
}
Example #22
0
/*! \internal
  \brief The registrar thread.

  The only thing this function does is to dispatch messages to the
  callback routine ( kmmint_reg_cb() ) */
DWORD WINAPI kmmint_registrar(LPVOID lpParameter)
{

    PDESCTHREAD(L"KMM Registrar", L"KMM");

    tid_registrar = GetCurrentThreadId();

    kmq_subscribe(KMSG_KMM, kmmint_reg_cb);
    kmq_subscribe(KMSG_SYSTEM, kmmint_reg_cb);

    SetEvent(evt_startup);

    while(KHM_SUCCEEDED(kmq_dispatch(INFINITE)));

    kmq_unsubscribe(KMSG_KMM, kmmint_reg_cb);
    kmq_unsubscribe(KMSG_SYSTEM, kmmint_reg_cb);

    ExitThread(0);
}
Example #23
0
/*! \internal
*/
KHMEXP khm_int32 KHMAPI
kmq_send_sub_msg(khm_handle sub, khm_int32 type, khm_int32 subtype,
                 khm_ui_4 uparam, void * vparam)
{
    kmq_call c;
    khm_int32 rv = KHM_ERROR_SUCCESS;

    rv = kmqint_post_sub_msg_ex(sub, type, subtype, uparam, vparam, &c, TRUE);
    if(KHM_FAILED(rv))
        return rv;

    rv = kmq_wait(c, INFINITE);
    if(KHM_SUCCEEDED(rv) && c->nFailed > 0)
        rv = KHM_ERROR_PARTIAL;

    kmq_free_call(c);

    return rv;
}
Example #24
0
KHMEXP khm_int32   KHMAPI
kmm_get_plugins_config(khm_int32 flags, khm_handle * result) {
    khm_handle csp_root;
    khm_handle csp_plugins;
    khm_int32 rv;

    rv = khc_open_space(KHM_INVALID_HANDLE, KMM_CSNAME_ROOT, flags, &csp_root);

    if(KHM_FAILED(rv))
        return rv;

    rv = khc_open_space(csp_root, KMM_CSNAME_PLUGINS, flags, &csp_plugins);
    khc_close_space(csp_root);

    if(KHM_SUCCEEDED(rv))
        *result = csp_plugins;
    else
        *result = NULL;

    return rv;
}
Example #25
0
KHMEXP khm_int32   KHMAPI
kmm_get_modules_config(khm_int32 flags, khm_handle * result) {
    khm_handle croot;
    khm_handle kmm_all_modules;
    khm_int32 rv;

    rv = khc_open_space(NULL, KMM_CSNAME_ROOT, flags, &croot);

    if(KHM_FAILED(rv))
        return rv;

    rv = khc_open_space(croot, KMM_CSNAME_MODULES, flags, &kmm_all_modules);
    khc_close_space(croot);

    if(KHM_SUCCEEDED(rv))
        *result = kmm_all_modules;
    else
        *result = NULL;

    return rv;
}
Example #26
0
KHMEXP khm_int32   KHMAPI 
kmm_load_default_modules(void) {
    khm_handle csm = NULL;
    khm_handle cs_mod = NULL;
    khm_int32 rv;
    wchar_t buf[KMM_MAXCCH_NAME];
    khm_size s;

    rv = kmm_get_modules_config(0, &csm);
    if(KHM_FAILED(rv))
        return rv;

    _begin_task(KHERR_CF_TRANSITIVE);
    _report_mr0(KHERR_NONE, MSG_LOAD_DEFAULT);
    _describe();

    kmmint_add_to_module_queue();

    while(KHM_SUCCEEDED(khc_enum_subspaces(csm, cs_mod, &cs_mod))) {

        s = sizeof(buf);
        if (KHM_FAILED(khc_get_config_space_name(cs_mod, buf, &s)))
            continue;

        /* check for schema subspace.  This is not an actual module. */
        if (!wcscmp(buf, L"_Schema"))
            continue;

        kmm_load_module(buf, 0, NULL);
    }

    kmmint_remove_from_module_queue();

    if(csm)
        khc_close_space(csm);

    _end_task();

    return rv;
}
Example #27
0
static void
check_and_set_refresh_bit_for_identity(khm_handle cred,
                                       khm_handle * plast_identity)
{
    khm_handle this_identity;

    if (KHM_SUCCEEDED(kcdb_cred_get_identity(cred,
                                             &this_identity))) {
        if (!kcdb_identity_is_equal(this_identity, *plast_identity)) {
            kcdb_identity_set_flags(this_identity,
                                    KCDB_IDENT_FLAG_NEEDREFRESH,
                                    KCDB_IDENT_FLAG_NEEDREFRESH);
            kcdb_identity_hold(this_identity);
            if (*plast_identity)
                kcdb_identity_release(*plast_identity);
            *plast_identity = this_identity;
        }

        kcdb_identity_release(this_identity);
        this_identity = NULL;
    }
}
Example #28
0
static void
write_params_idents(void) {
    khm_handle csp_cw = NULL;

    if (KHM_SUCCEEDED(khc_open_space(NULL, L"CredWindow",
                                     KHM_FLAG_CREATE, &csp_cw))) {
        if (cfg_idents.work.monitor != cfg_idents.saved.monitor) {
            khc_write_int32(csp_cw, L"DefaultMonitor",
                            !!cfg_idents.work.monitor);
            cfg_idents.work.monitor = cfg_idents.saved.monitor;
            cfg_idents.applied = TRUE;
        }
        if (cfg_idents.work.auto_renew != cfg_idents.saved.auto_renew) {
            khc_write_int32(csp_cw, L"DefaultAllowAutoRenew",
                            !!cfg_idents.work.auto_renew);
            cfg_idents.work.auto_renew = cfg_idents.saved.auto_renew;
            cfg_idents.applied = TRUE;
        }
        if (cfg_idents.work.sticky != cfg_idents.saved.sticky) {
            khc_write_int32(csp_cw, L"DefaultSticky",
                            !!cfg_idents.work.sticky);
            cfg_idents.work.sticky = cfg_idents.saved.sticky;
            cfg_idents.applied = TRUE;
        }

        khc_close_space(csp_cw);
        csp_cw = NULL;
    }

#if 0
    for (i=0; i < (int)cfg_idents.n_idents; i++) {
        write_params_ident(&cfg_idents.idents[i]);
    }
#endif

    if (cfg_idents.hwnd)
        PostMessage(cfg_idents.hwnd, KHUI_WM_CFG_NOTIFY,
                    MAKEWPARAM(0, WMCFG_UPDATE_STATE), 0);
}
Example #29
0
BOOL 
khm_cred_begin_dialog(void) {
    BOOL rv;

    dialog_sync_init();

    EnterCriticalSection(&cs_dialog);

    if (in_dialog) {
        rv = FALSE;

        /* if a dialog is being displayed and we got a another request
           to show one, we bring the existing one to the
           foreground. */
        if (dialog_nc && dialog_nc->hwnd) {
            khm_int32 t = 0;

            if (KHM_SUCCEEDED(khc_read_int32(NULL,
                                             L"CredWindow\\Windows\\NewCred\\ForceToTop",
                                             &t)) &&
                t != 0) {

                khm_activate_main_window();

                SetWindowPos(dialog_nc->hwnd, HWND_TOP, 0, 0, 0, 0,
                             (SWP_NOMOVE | SWP_NOSIZE));
            }
        }

    } else {
        rv = TRUE;
        in_dialog = TRUE;
        ResetEvent(in_dialog_evt);
    }

    LeaveCriticalSection(&cs_dialog);
    return rv;
}
Example #30
0
void k4_write_identity_data(k4_dlg_data * d) {
    khm_handle csp_ident = NULL;
    khm_handle csp_k4 = NULL;

    if (d->nc->n_identities > 0 &&
        d->nc->identities[0] &&
        KHM_SUCCEEDED(kcdb_identity_get_config(d->nc->identities[0],
                                               KHM_FLAG_CREATE,
                                               &csp_ident))) {
        khc_open_space(csp_ident, CSNAME_KRB4CRED,
                       KHM_FLAG_CREATE | KCONF_FLAG_WRITEIFMOD,
                       &csp_k4);

        if (csp_k4) {
            khc_write_int32(csp_k4, L"Krb4NewCreds", !!d->k4_enabled);
            khc_write_int32(csp_k4, L"Krb4Method", d->method);

            khc_close_space(csp_k4);
        }

        khc_close_space(csp_ident);
    }
}