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); }
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); }
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; }
/* Identity Selector control factory Runs in UI thread */ khm_int32 KHMAPI idsel_factory(HWND hwnd_parent, khui_identity_selector * u) { if (hwnd_parent) { HWND hw_dlg; wchar_t display_name[KHUI_MAXCCH_NAME] = L""; khm_handle csp_p = NULL; khm_int32 allow_create = 0; if (KHM_FAILED(kmm_get_plugin_config(IDPROV_NAMEW, 0, &csp_p)) || KHM_FAILED(khc_read_int32(csp_p, L"AllowMultipleKeystores", &allow_create)) || allow_create == 0) { if (csp_p) khc_close_space(csp_p); return KHM_ERROR_INVALID_OPERATION; } if (csp_p) { khc_close_space(csp_p); csp_p = NULL; } hw_dlg = CreateDialog(hResModule, MAKEINTRESOURCE(IDD_IDSPEC), hwnd_parent, idspec_dlg_proc); assert(hw_dlg); u->hwnd_selector = hw_dlg; LoadString(hResModule, IDS_ID_INSTANCE, display_name, ARRAYLENGTH(display_name)); u->display_name = PWCSDUP(display_name); u->icon = LoadImage(hResModule, MAKEINTRESOURCE(IDI_IDENTITY), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_DEFAULTCOLOR); return (hw_dlg ? KHM_ERROR_SUCCESS : KHM_ERROR_UNKNOWN); } else { if (u->display_name) { PFREE(u->display_name); u->display_name = NULL; } if (u->icon) { DestroyIcon(u->icon); u->icon = NULL; } return KHM_ERROR_SUCCESS; } }
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; }
void kmqint_init(void) { khm_handle hconfig = NULL; queues = NULL; InitializeCriticalSection(&cs_kmq_global); InitializeCriticalSection(&cs_kmq_msg); InitializeCriticalSection(&cs_kmq_msg_ref); EnterCriticalSection(&cs_kmq_global); khc_load_schema(NULL, schema_kmqconfig); khc_open_space(NULL, KMQ_CONF_SPACE_NAME, KHM_PERM_READ, &hconfig); if(hconfig) { khm_int32 t = 0; khc_read_int32(hconfig, KMQ_CONF_QUEUE_DEAD_TIMEOUT_NAME, &t); kmq_queue_dead_timeout = t; khc_read_int32(hconfig, KMQ_CONF_CALL_DEAD_TIMEOUT_NAME, &t); kmq_call_dead_timeout = t; khc_close_space(hconfig); } kmqint_init_msg_types(); LeaveCriticalSection(&cs_kmq_global); kmq_tls_queue = TlsAlloc(); }
KHMEXP khm_int32 KHMAPI kmm_enable_plugin(kmm_plugin p, khm_boolean enable) { kmm_plugin_i * pi; khm_int32 rv = KHM_ERROR_NOT_FOUND; /* default to error */ khm_handle csp_plugin = NULL; EnterCriticalSection(&cs_kmm); if (!kmm_is_plugin(p)) { rv = KHM_ERROR_INVALID_PARAM; goto _cleanup; } pi = kmm_plugin_from_handle(p); if (KHM_FAILED(rv = kmm_get_plugin_config(pi->p.name, 0, &csp_plugin))) { goto _cleanup; } if (KHM_FAILED(rv = khc_write_int32(csp_plugin, L"Disabled", !enable))) { goto _cleanup; } rv = KHM_ERROR_SUCCESS; _cleanup: LeaveCriticalSection(&cs_kmm); if (csp_plugin) khc_close_space(csp_plugin); return rv; }
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); }
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); }
khm_boolean k4_id_write_params(HWND hwnd, k4_id_data * d) { khm_handle ident = NULL; khm_int32 flags = 0; khm_handle csp_ident = NULL; khm_handle csp_idk4 = NULL; khm_int32 gettix = 0; khm_boolean applied = FALSE; ident = khui_cfg_get_data(d->cfg.ctx_node); if (ident == NULL) return FALSE; kcdb_identity_get_flags(ident, &flags); if (!(flags & KCDB_IDENT_FLAG_DEFAULT)) goto done_apply; if (IsDlgButtonChecked(hwnd, IDC_CFG_GETTIX) == BST_CHECKED) gettix = TRUE; if (KHM_FAILED(kcdb_identity_get_config(ident, KHM_FLAG_CREATE, &csp_ident))) goto done_apply; if (KHM_FAILED(khc_open_space(csp_ident, CSNAME_KRB4CRED, KHM_FLAG_CREATE | KCONF_FLAG_WRITEIFMOD, &csp_idk4))) goto done_apply; khc_write_int32(csp_idk4, L"Krb4NewCreds", gettix); applied = TRUE; done_apply: if (ident) kcdb_identity_release(ident); if (csp_ident) khc_close_space(csp_ident); if (csp_idk4) khc_close_space(csp_idk4); return applied; }
/* called by the NetIDMgr module manager */ KHMEXP_EXP khm_int32 KHMAPI exit_module(kmm_module h_module) { exit_imports(); exit_error_funcs(); if(attr_regd_key_enctype) kcdb_attrib_unregister(attr_id_key_enctype); if(attr_regd_tkt_enctype) kcdb_attrib_unregister(attr_id_tkt_enctype); if(attr_regd_addr_list) kcdb_attrib_unregister(attr_id_addr_list); if(attr_regd_krb5_flags) kcdb_attrib_unregister(attr_id_krb5_flags); if(attr_regd_krb5_ccname) kcdb_attrib_unregister(attr_id_krb5_ccname); if(attr_regd_kvno) kcdb_attrib_unregister(attr_id_kvno); if(attr_regd_krb5_idflags) kcdb_attrib_unregister(attr_id_krb5_idflags); if(type_regd_enctype) kcdb_type_unregister(type_id_enctype); if(type_regd_addr_list) kcdb_type_unregister(type_id_addr_list); if(type_regd_krb5_flags) kcdb_type_unregister(type_id_krb5_flags); if(type_regd_kvno) kcdb_type_unregister(type_id_kvno); if(csp_params) { khc_close_space(csp_params); csp_params = NULL; } if(csp_krbcred) { khc_close_space(csp_krbcred); csp_krbcred = NULL; } if(csp_plugins) { khc_unload_schema(csp_plugins, schema_krbconfig); khc_close_space(csp_plugins); csp_plugins = NULL; } return KHM_ERROR_SUCCESS; /* the return code is ignored */ }
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); } }
KHMEXP khm_int32 KHMAPI kmm_get_plugin_info_i(kmm_plugin p, kmm_plugin_info * info) { khm_int32 rv = KHM_ERROR_SUCCESS; kmm_plugin_i * pi; khm_handle csp_plugin; if (!info) return KHM_ERROR_INVALID_PARAM; EnterCriticalSection(&cs_kmm); if (!kmm_is_plugin(p)) { rv = KHM_ERROR_INVALID_PARAM; goto _cleanup; } pi = kmm_plugin_from_handle(p); ZeroMemory(info, sizeof(*info)); info->reg = pi->p; info->reg.msg_proc = NULL; if (KHM_FAILED(kmm_get_plugin_config(pi->p.name, KHM_PERM_READ, &csp_plugin))) { info->failure_count = 0; *((khm_int64 *)&info->failure_time) = 0; info->failure_reason = 0; } else { if (KHM_FAILED(khc_read_int32(csp_plugin, L"FailureCount", &info->failure_count))) info->failure_count = 0; if (KHM_FAILED(khc_read_int64(csp_plugin, L"FailureTime", (khm_int64 *) &info->failure_time))) *((khm_int64 *) &info->failure_time) = 0; if (KHM_FAILED(khc_read_int32(csp_plugin, L"FailureReason", &info->failure_reason))) info->failure_reason = 0; khc_close_space(csp_plugin); } info->state = pi->state; kmm_hold_plugin(p); info->h_plugin = p; info->flags = (pi->flags & KMM_PLUGIN_FLAG_DISABLED); _cleanup: LeaveCriticalSection(&cs_kmm); return rv; }
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); }
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); } }
/* 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); }
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(); }
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(); }
/* perform shutdown operations */ static void khm_pre_shutdown(void) { khm_handle csp_cw = NULL; khm_handle credset = NULL; khm_int32 t; khm_size s; /* Check if we should destroy all credentials on exit... */ if (KHM_FAILED(khc_open_space(NULL, L"CredWindow", 0, &csp_cw))) return; if (KHM_FAILED(khc_read_int32(csp_cw, L"DestroyCredsOnExit", &t)) || !t) goto _cleanup; if (KHM_FAILED(kcdb_credset_create(&credset))) goto _cleanup; if (KHM_FAILED(kcdb_credset_extract(credset, NULL, NULL, KCDB_TYPE_INVALID))) goto _cleanup; if (KHM_FAILED(kcdb_credset_get_size(credset, &s)) || s == 0) goto _cleanup; kcdb_credset_apply(credset, mw_select_cred, NULL); khui_context_set(KHUI_SCOPE_GROUP, NULL, KCDB_CREDTYPE_INVALID, NULL, NULL, 0, credset); khm_cred_destroy_creds(TRUE, TRUE); _cleanup: if (credset) kcdb_credset_delete(credset); if (csp_cw) khc_close_space(csp_cw); }
KHMEXP khm_int32 KHMAPI kmm_register_module(kmm_module_reg * module, khm_int32 config_flags) { khm_int32 rv = KHM_ERROR_SUCCESS; khm_handle csp_module = NULL; size_t cch; int i; if((module == NULL) || FAILED(StringCchLength(module->name, KMM_MAXCCH_NAME, &cch)) || (module->description && FAILED(StringCchLength(module->description, KMM_MAXCCH_DESC, &cch))) || FAILED(StringCchLength(module->path, MAX_PATH, &cch)) || (module->n_plugins > 0 && module->plugin_reg_info == NULL)) { return KHM_ERROR_INVALID_PARAM; } #define CKRV if(KHM_FAILED(rv)) goto _exit rv = kmm_get_module_config(module->name, config_flags | KHM_FLAG_CREATE, &csp_module); CKRV; rv = khc_write_string(csp_module, L"ImagePath", module->path); CKRV; rv = khc_write_int32(csp_module, L"Disabled", 0); CKRV; /* FileVersion and ProductVersion will be set when the module is loaded for the first time */ for(i=0; i<module->n_plugins; i++) { rv = kmm_register_plugin(&(module->plugin_reg_info[i]), config_flags); CKRV; } #undef CKRV _exit: if(csp_module) khc_close_space(csp_module); return rv; }
KHMEXP khm_int32 KHMAPI kmm_unregister_module(wchar_t * module, khm_int32 config_flags) { khm_handle csp_module = NULL; khm_int32 rv = KHM_ERROR_SUCCESS; rv = kmm_get_module_config(module, config_flags, &csp_module); if (KHM_FAILED(rv)) goto _cleanup; rv = khc_remove_space(csp_module); _cleanup: if (csp_module) khc_close_space(csp_module); return rv; }
KHMEXP khm_int32 KHMAPI kmm_get_module_config(wchar_t * module, khm_int32 flags, khm_handle * result) { khm_handle csmodules; khm_handle csmodule; khm_int32 rv; if(!module || wcschr(module, L'/') || wcschr(module, L'\\')) return KHM_ERROR_INVALID_PARAM; if(KHM_FAILED(kmm_get_modules_config(flags, &csmodules))) return KHM_ERROR_UNKNOWN; rv = khc_open_space(csmodules, module, flags, &csmodule); *result = csmodule; khc_close_space(csmodules); return rv; }
KHMEXP khm_int32 KHMAPI kmm_unregister_plugin(wchar_t * plugin, khm_int32 config_flags) { khm_handle csp_plugin = NULL; khm_int32 rv = KHM_ERROR_SUCCESS; rv = kmm_get_plugin_config(plugin, config_flags, &csp_plugin); if (KHM_FAILED(rv)) goto _cleanup; rv = khc_remove_space(csp_plugin); _cleanup: if (csp_plugin) khc_close_space(csp_plugin); return rv; }
KHMEXP khm_int32 KHMAPI kmm_get_plugin_config(wchar_t * plugin, khm_int32 flags, khm_handle * result) { khm_handle csplugins; khm_handle csplugin; khm_int32 rv; if(!plugin || wcschr(plugin, L'/') || wcschr(plugin, L'\\')) return KHM_ERROR_INVALID_PARAM; if(KHM_FAILED(kmm_get_plugins_config(flags, &csplugins))) return KHM_ERROR_UNKNOWN; rv = khc_open_space(csplugins, plugin, flags, &csplugin); *result = csplugin; khc_close_space(csplugins); return rv; }
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; }
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; }
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; }
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); }
static void mw_restart_refresh_timer(HWND hwnd) { khm_handle csp_cw; khm_int32 timeout; KillTimer(hwnd, MW_REFRESH_TIMER); if (KHM_SUCCEEDED(khc_open_space(NULL, L"CredWindow", KHM_PERM_READ, &csp_cw))) { if (KHM_FAILED(khc_read_int32(csp_cw, L"RefreshTimeout", &timeout))) timeout = MW_REFRESH_TIMEOUT; khc_close_space(csp_cw); } else { timeout = MW_REFRESH_TIMEOUT; } timeout *= 1000; /* convert to milliseconds */ SetTimer(hwnd, MW_REFRESH_TIMER, timeout, NULL); }
/* process KMSG_SYSTEM messages */ khm_int32 KHMAPI afs_msg_system(khm_int32 msg_subtype, khm_ui_4 uparam, void * vparam) { khm_int32 rv = KHM_ERROR_UNKNOWN; switch(msg_subtype) { case KMSG_SYSTEM_INIT: /* If we are building against an older SDK, we should try to load newer APIs if it's available at run-time. */ #if KH_VERSION_API < 7 do { khm_version libver; khm_ui_4 apiver; khm_get_lib_version(&libver, &apiver); if (apiver < 7) break; hm_netidmgr = LoadLibrary(NIMDLLNAME); if (hm_netidmgr == NULL) break; pkhui_action_lock = (void (KHMAPI *)(void)) GetProcAddress(hm_netidmgr, API_khui_action_lock); pkhui_action_unlock = (void (KHMAPI *)(void)) GetProcAddress(hm_netidmgr, API_khui_action_unlock); pkhui_refresh_actions = (void (KHMAPI *)(void)) GetProcAddress(hm_netidmgr, API_khui_refresh_actions); pkhui_request_UI_callback = (khm_int32 (KHMAPI *)(khm_ui_callback, void *)) GetProcAddress(hm_netidmgr, API_khui_request_UI_callback); } while (FALSE); #endif /* Add the icon now. On NIM v2.x, doing so after tokens were reported may result in a deadlock as we try to switch to the UI thread and the UI thread is blocked on a resource request to this plug-in. */ afs_icon_set_state(AFSICON_SERVICE_STOPPED, NULL); /* Perform critical registrations and data structure initalization */ { kcdb_credtype ct; wchar_t buf[KCDB_MAXCCH_LONG_DESC]; size_t cbsize; kcdb_attrib att; khm_handle csp_afscred = NULL; khm_int32 disable_afscreds = FALSE; ZeroMemory(&ct, sizeof(ct)); /* first of all, register the AFS token credential type */ ct.id = KCDB_CREDTYPE_AUTO; ct.name = AFS_CREDTYPE_NAME; if(LoadString(hResModule, IDS_AFS_SHORT_DESC, buf, ARRAYLENGTH(buf)) != 0) { StringCbLength(buf, sizeof(buf), &cbsize); cbsize += sizeof(wchar_t); ct.short_desc = PMALLOC(cbsize); StringCbCopy(ct.short_desc, cbsize, buf); } else ct.short_desc = NULL; if(LoadString(hResModule, IDS_AFS_LONG_DESC, buf, ARRAYLENGTH(buf)) != 0) { StringCbLength(buf, sizeof(buf), &cbsize); cbsize += sizeof(wchar_t); ct.long_desc = PMALLOC(cbsize); StringCbCopy(ct.long_desc, cbsize, buf); } else ct.long_desc = NULL; ct.icon = LoadImage(hResModule, MAKEINTRESOURCE(IDI_AFSTOKEN), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE); kmq_create_subscription(afs_plugin_cb, &afs_sub); ct.sub = afs_sub; kcdb_credtype_register(&ct, &afs_credtype_id); /* register the attribute types */ { kcdb_type type; ZeroMemory(&type, sizeof(type)); type.comp = afs_type_principal_comp; type.dup = afs_type_principal_dup; type.isValid = afs_type_principal_isValid; type.toString = afs_type_principal_toString; type.name = AFS_TYPENAME_PRINCIPAL; type.id = KCDB_TYPE_INVALID; type.cb_max = sizeof(struct ktc_principal); type.cb_min = sizeof(struct ktc_principal); type.flags = KCDB_TYPE_FLAG_CB_FIXED; if(KHM_FAILED(kcdb_type_register(&type, &afs_type_principal))) goto _exit_init; } { kcdb_type type; kcdb_type *ti32 = NULL; kcdb_type_get_info(KCDB_TYPE_INT32, &ti32); ZeroMemory(&type, sizeof(type)); type.comp = ti32->comp; type.dup = ti32->dup; type.isValid = ti32->isValid; type.toString = afs_type_method_toString; type.name = AFS_TYPENAME_METHOD; type.id = KCDB_TYPE_INVALID; type.cb_max = sizeof(khm_int32); type.cb_min = sizeof(khm_int32); type.flags = KCDB_TYPE_FLAG_CB_FIXED; if(KHM_FAILED(kcdb_type_register(&type, &afs_type_method))) { kcdb_type_release_info(ti32); goto _exit_init; } kcdb_type_release_info(ti32); } /* now register the attributes */ { wchar_t short_desc[KCDB_MAXCCH_SHORT_DESC]; ZeroMemory(&att, sizeof(att)); att.type = KCDB_TYPE_STRING; att.name = AFS_ATTRNAME_CELL; LoadString(hResModule, IDS_ATTR_CELL_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); att.short_desc = short_desc; att.long_desc = NULL; att.id = KCDB_ATTR_INVALID; att.flags = KCDB_ATTR_FLAG_TRANSIENT; if(KHM_FAILED(rv = kcdb_attrib_register(&att, &afs_attr_cell))) goto _exit_init; } { wchar_t short_desc[KCDB_MAXCCH_SHORT_DESC]; ZeroMemory(&att, sizeof(att)); att.type = KCDB_TYPE_STRING; att.name = AFS_ATTRNAME_REALM; LoadString(hResModule, IDS_ATTR_REALM_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); att.short_desc = short_desc; att.long_desc = NULL; att.id = KCDB_ATTR_INVALID; att.flags = KCDB_ATTR_FLAG_TRANSIENT; if(KHM_FAILED(rv = kcdb_attrib_register(&att, &afs_attr_realm))) goto _exit_init; } { wchar_t short_desc[KCDB_MAXCCH_SHORT_DESC]; ZeroMemory(&att, sizeof(att)); att.type = afs_type_method; att.name = AFS_ATTRNAME_METHOD; LoadString(hResModule, IDS_ATTR_METHOD_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); att.short_desc = short_desc; att.long_desc = NULL; att.id = KCDB_ATTR_INVALID; att.flags = KCDB_ATTR_FLAG_TRANSIENT; if(KHM_FAILED(rv = kcdb_attrib_register(&att, &afs_attr_method))) goto _exit_init; } { wchar_t short_desc[KCDB_MAXCCH_SHORT_DESC]; ZeroMemory(&att, sizeof(att)); att.type = afs_type_principal; att.name = AFS_ATTRNAME_CLIENT_PRINC; LoadString(hResModule, IDS_ATTR_CLIENT_PRINC_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); att.short_desc = short_desc; att.long_desc = NULL; att.id = KCDB_ATTR_INVALID; att.flags = KCDB_ATTR_FLAG_TRANSIENT; if(KHM_FAILED(rv = kcdb_attrib_register(&att, &afs_attr_client_princ))) goto _exit_init; } { wchar_t short_desc[KCDB_MAXCCH_SHORT_DESC]; ZeroMemory(&att, sizeof(att)); att.type = afs_type_principal; att.name = AFS_ATTRNAME_SERVER_PRINC; LoadString(hResModule, IDS_ATTR_SERVER_PRINC_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); att.short_desc = short_desc; att.long_desc = NULL; att.id = KCDB_ATTR_INVALID; att.flags = KCDB_ATTR_FLAG_TRANSIENT; if(KHM_FAILED(rv = kcdb_attrib_register(&att, &afs_attr_server_princ))) goto _exit_init; } /* afs_credset is our stock credentials set that we use for all our credset needs (instead of creating a new one every time) */ if(KHM_FAILED(rv = kcdb_credset_create(&afs_credset))) goto _exit_init; if(KHM_FAILED(rv = kcdb_credtype_get_id(KRB5_CREDTYPE_NAME, &krb5_credtype_id))) goto _exit_init; /* register the configuration nodes */ { khui_config_node node_ident; khui_config_node_reg reg; wchar_t wshort_desc[KHUI_MAXCCH_SHORT_DESC]; wchar_t wlong_desc[KHUI_MAXCCH_LONG_DESC]; if (KHM_FAILED(rv = khui_cfg_open(NULL, L"KhmIdentities", &node_ident))) goto _exit_init; ZeroMemory(®, sizeof(reg)); reg.name = AFS_CONFIG_NODE_MAIN; reg.short_desc = wshort_desc; reg.long_desc = wlong_desc; reg.h_module = hResModule; reg.dlg_template = MAKEINTRESOURCE(IDD_CFG_AFS); reg.dlg_proc = afs_cfg_main_proc; reg.flags = 0; LoadString(hResModule, IDS_CFG_MAIN_LONG, wlong_desc, ARRAYLENGTH(wlong_desc)); LoadString(hResModule, IDS_CFG_MAIN_SHORT, wshort_desc, ARRAYLENGTH(wshort_desc)); khui_cfg_register(NULL, ®); ZeroMemory(®, sizeof(reg)); reg.name = AFS_CONFIG_NODE_IDS; reg.short_desc = wshort_desc; reg.long_desc = wshort_desc; reg.h_module = hResModule; reg.dlg_template = MAKEINTRESOURCE(IDD_CFG_IDS_TAB); reg.dlg_proc = afs_cfg_ids_proc; reg.flags = KHUI_CNFLAG_SUBPANEL; LoadString(hResModule, IDS_CFG_IDS_TAB, wshort_desc, ARRAYLENGTH(wshort_desc)); khui_cfg_register(node_ident, ®); ZeroMemory(®, sizeof(reg)); reg.name = AFS_CONFIG_NODE_ID; reg.short_desc = wshort_desc; reg.long_desc = wshort_desc; reg.h_module = hResModule; reg.dlg_template = MAKEINTRESOURCE(IDD_CFG_ID_TAB); reg.dlg_proc = afs_cfg_id_proc; reg.flags = KHUI_CNFLAG_SUBPANEL | KHUI_CNFLAG_PLURAL; LoadString(hResModule, IDS_CFG_ID_TAB, wshort_desc, ARRAYLENGTH(wshort_desc)); khui_cfg_register(node_ident, ®); } /* and register the AFS message type */ rv = kmq_register_type(AFS_MSG_TYPENAME, &afs_msg_type_id); if (KHM_SUCCEEDED(rv)) kmq_subscribe(afs_msg_type_id, afs_plugin_cb); /* if the configuration is set to disable afscreds.exe, then we look for the shortcut and remove it if found. */ if (KHM_SUCCEEDED(kmm_get_plugin_config(AFS_PLUGIN_NAME, 0, &csp_afscred))) { wchar_t wpath[MAX_PATH]; khc_read_int32(csp_afscred, L"Disableafscreds", &disable_afscreds); if (disable_afscreds && afs_cfg_get_afscreds_shortcut(wpath)) { DeleteFile(wpath); } khc_close_space(csp_afscred); } /* try to register the "AFS Help" menu item, if possible */ { khm_handle h_sub = NULL; wchar_t short_desc[KHUI_MAXCCH_SHORT_DESC]; wchar_t long_desc[KHUI_MAXCCH_LONG_DESC]; #if KH_VERSION_API < 7 if (pkhui_action_lock == NULL || pkhui_action_unlock == NULL || pkhui_refresh_actions == NULL || pkhui_request_UI_callback == NULL) goto no_custom_help; #endif kmq_create_subscription(afs_plugin_cb, &h_sub); LoadString(hResModule, IDS_ACTION_AFS_HELP, short_desc, ARRAYLENGTH(short_desc)); LoadString(hResModule, IDS_ACTION_AFS_HELP_TT, long_desc, ARRAYLENGTH(long_desc)); action_id_afs_help = khui_action_create(NULL, short_desc, long_desc, NULL, KHUI_ACTIONTYPE_TRIGGER, h_sub); if (action_id_afs_help != 0) { khm_size s; khm_size i; khui_menu_def * help_menu; khm_boolean refresh = FALSE; khui_action_lock(); help_menu = khui_find_menu(KHUI_MENU_HELP); if (help_menu) { s = khui_menu_get_size(help_menu); for (i=0; i < s; i++) { khui_action_ref * aref; aref = khui_menu_get_action(help_menu, i); if (aref && !(aref->flags & KHUI_ACTIONREF_PACTION) && aref->action == KHUI_ACTION_HELP_INDEX) { khui_menu_insert_action(help_menu, i + 1, action_id_afs_help, 0); refresh = TRUE; break; } } } khui_action_unlock(); if (refresh) khui_refresh_actions(); } #if KH_VERSION_API < 7 no_custom_help: ; #endif } _exit_init: if(ct.short_desc) PFREE(ct.short_desc); if(ct.long_desc) PFREE(ct.long_desc); } /* now that the critical stuff is done, we move on to the non-critical stuff */ if(KHM_SUCCEEDED(rv)) { initialized = TRUE; /* obtain existing tokens */ afs_list_tokens(); } /* define this so that if there are no TGT's, we don't deadlock trying to open a new creds dialog from within the new creds dialog. */ SetEnvironmentVariable(L"KERBEROSLOGIN_NEVER_PROMPT", L"1"); break; /* end of KMSG_SYSTEM_INIT */ case KMSG_SYSTEM_EXIT: afs_remove_icon(); /* Try to remove the AFS plug-in action from Help menu if it was successfully registered. Also, delete the action. */ if (action_id_afs_help != 0) { khui_menu_def * help_menu; khm_boolean menu_changed = FALSE; khui_action_lock(); help_menu = khui_find_menu(KHUI_MENU_HELP); if (help_menu) { khm_size s; khm_size i; s = khui_menu_get_size(help_menu); for (i=0; i < s; i++) { khui_action_ref * aref = khui_menu_get_action(help_menu, i); if (aref && !(aref->flags & KHUI_ACTIONREF_PACTION) && aref->action == action_id_afs_help) { khui_menu_remove_action(help_menu, i); menu_changed = TRUE; break; } } } khui_action_delete(action_id_afs_help); khui_action_unlock(); if (menu_changed) khui_refresh_actions(); action_id_afs_help = 0; } if (afs_msg_type_id != -1) { kmq_unsubscribe(afs_msg_type_id, afs_plugin_cb); kmq_unregister_type(afs_msg_type_id); } if(afs_credtype_id >= 0) { kcdb_credtype_unregister(afs_credtype_id); } #if 0 if(afs_attr_client >= 0) { kcdb_attrib_unregister(afs_attr_client); } #endif if(afs_attr_cell >= 0) { kcdb_attrib_unregister(afs_attr_cell); } if(afs_attr_realm >= 0) { kcdb_attrib_unregister(afs_attr_realm); } if(afs_attr_method >= 0) { kcdb_attrib_unregister(afs_attr_method); } if(afs_attr_client_princ >= 0) { kcdb_attrib_unregister(afs_attr_client_princ); } if(afs_attr_server_princ >= 0) { kcdb_attrib_unregister(afs_attr_server_princ); } if(afs_type_principal >= 0) { kcdb_type_unregister(afs_type_principal); } if(afs_type_method >= 0) { kcdb_type_unregister(afs_type_method); } initialized = FALSE; if(afs_credset) kcdb_credset_delete(afs_credset); /* afs_sub doesn't need to be deleted. That is taken care of when unregistering the afs cred type */ afs_sub = NULL; #if KH_VERSION_API < 7 if (hm_netidmgr) FreeLibrary(hm_netidmgr); pkhui_action_lock = NULL; pkhui_action_unlock = NULL; pkhui_refresh_actions = NULL; pkhui_request_UI_callback = NULL; #endif rv = KHM_ERROR_SUCCESS; break; /* end of KMSG_SYSTEM_EXIT */ } return rv; }