Пример #1
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();
}
Пример #2
0
LRESULT CALLBACK
khm_main_wnd_proc(HWND hwnd,
                  UINT uMsg,
                  WPARAM wParam,
                  LPARAM lParam)
{
    LPNMHDR lpnm;

    switch(uMsg) {
    case WM_CREATE:
        khm_create_main_window_controls(hwnd);
        kmq_subscribe_hwnd(KMSG_CRED, hwnd);
        kmq_subscribe_hwnd(KMSG_ACT, hwnd);
        kmq_subscribe_hwnd(KMSG_KMM, hwnd);
        mw_restart_refresh_timer(hwnd);

        /* if the plug-ins finished loading before the window was
           created, we would have missed the KMSG_KMM_I_DONE message.
           So we check if the module load is complete and if so, fire
           off KMSG_ACT_BEGIN_CMDLINE. */
        if (!kmm_load_pending())
            kmq_post_message(KMSG_ACT, KMSG_ACT_BEGIN_CMDLINE, 0, 0);
        break;

    case WM_DESTROY:
        khm_pre_shutdown();
        kmq_unsubscribe_hwnd(KMSG_ACT, hwnd);
        kmq_unsubscribe_hwnd(KMSG_CRED, hwnd);
        kmq_unsubscribe_hwnd(KMSG_KMM, hwnd);
        HtmlHelp(NULL, NULL, HH_CLOSE_ALL, 0);
        PostQuitMessage(0);
        break;

    case WM_NOTIFY:
        lpnm = (LPNMHDR) lParam;
        if(lpnm->hwndFrom == khui_main_menu_toolbar) {
            return khm_menu_notify_main(lpnm);
        } else if(lpnm->hwndFrom == khui_hwnd_standard_toolbar) {
            return khm_toolbar_notify(lpnm);
        } else if(lpnm->hwndFrom == khm_hwnd_rebar) {
            return khm_rebar_notify(lpnm);
        } else if(lpnm->hwndFrom == khm_hwnd_statusbar) {
            return khm_statusbar_notify(lpnm);
        }
        break;

    case WM_HELP:
        khm_html_help(khm_hwnd_main, NULL, HH_HELP_CONTEXT, IDH_WELCOME);
        break;

    case WM_COMMAND:
        switch(LOWORD(wParam)) {
            /* general actions */
        case KHUI_ACTION_VIEW_REFRESH:
            khm_cred_refresh();
            InvalidateRect(khm_hwnd_main_cred, NULL, FALSE);
            return 0;

        case KHUI_ACTION_PASSWD_ID:
            if (khm_startup.processing)
                return 0;

            khm_cred_change_password(NULL);
            return 0;

        case KHUI_ACTION_NEW_CRED:
            if (khm_startup.processing)
                return 0;

            khm_cred_obtain_new_creds(NULL);
            return 0;

        case KHUI_ACTION_RENEW_CRED:
            if (khm_startup.processing)
                return 0;

            khm_cred_renew_creds();
            return 0;

        case KHUI_ACTION_DESTROY_CRED:
            if (khm_startup.processing)
                return 0;

            khm_cred_destroy_creds(FALSE, FALSE);
            return 0;

        case KHUI_ACTION_SET_DEF_ID:
            if (khm_startup.processing)
                return 0;

            khm_cred_set_default();
            return 0;

        case KHUI_ACTION_EXIT:
            DestroyWindow(hwnd);
            return 0;

        case KHUI_ACTION_OPEN_APP:
            khm_show_main_window();
            return 0;

        case KHUI_ACTION_CLOSE_APP:
            khm_hide_main_window();
            return 0;

        case KHUI_ACTION_OPT_KHIM: {
            khui_config_node node = NULL;

            khui_cfg_open(NULL, L"KhmGeneral", &node);
            khm_show_config_pane(node);
        }
            return 0;

        case KHUI_ACTION_OPT_IDENTS: {
            khui_config_node node = NULL;

            khui_cfg_open(NULL, L"KhmIdentities", &node);
            khm_show_config_pane(node);
        }
            return 0;

        case KHUI_ACTION_OPT_APPEAR: {
            khui_config_node node = NULL;

            khui_cfg_open(NULL, L"KhmAppear", &node);
            khm_show_config_pane(node);
        }
            return 0;

        case KHUI_ACTION_OPT_NOTIF: {
            khui_config_node node = NULL;

            khui_cfg_open(NULL, L"KhmNotifications", &node);
            khm_show_config_pane(node);
        }
            return 0;

        case KHUI_ACTION_OPT_PLUGINS: {
            khui_config_node node = NULL;

            khui_cfg_open(NULL, L"KhmPlugins", &node);
            khm_show_config_pane(node);
        }
            return 0;

        case KHUI_ACTION_HELP_CTX:
            khm_html_help(khm_hwnd_main, NULL, HH_HELP_CONTEXT, IDH_WELCOME);
            return 0;

        case KHUI_ACTION_HELP_CONTENTS:
            khm_html_help(khm_hwnd_main, NULL, HH_DISPLAY_TOC, 0);
            return 0;

        case KHUI_ACTION_HELP_INDEX:
            khm_html_help(khm_hwnd_main, NULL, HH_DISPLAY_INDEX, (DWORD_PTR) L"");
            return 0;

        case KHUI_ACTION_HELP_ABOUT:
            khm_create_about_window();
            return 0;

        case KHUI_ACTION_IMPORT:
            khm_cred_import();
            return 0;

        case KHUI_ACTION_PROPERTIES:
            /* properties are not handled by the main window.
               Just bounce it to credwnd.  However, use SendMessage
               instead of PostMessage so we don't lose context */
            return SendMessage(khm_hwnd_main_cred, uMsg,
                               wParam, lParam);

        case KHUI_ACTION_UICB:
            khm_ui_cb(lParam);
            return 0;

            /* layout control */

        case KHUI_ACTION_VIEW_ALL_IDS:
            return SendMessage(khm_hwnd_main_cred, uMsg,
                               wParam, lParam);

        case KHUI_ACTION_LAYOUT_MINI:

            if (khm_main_wnd_mode == KHM_MAIN_WND_MINI) {
                khm_set_main_window_mode(KHM_MAIN_WND_NORMAL);
            } else {
                khm_set_main_window_mode(KHM_MAIN_WND_MINI);
            }
            return SendMessage(khm_hwnd_main_cred, uMsg,
                               wParam, lParam);

        case KHUI_ACTION_LAYOUT_RELOAD:
            return SendMessage(khm_hwnd_main_cred, uMsg,
                               wParam, lParam);

        case KHUI_ACTION_LAYOUT_ID:
        case KHUI_ACTION_LAYOUT_TYPE:
        case KHUI_ACTION_LAYOUT_LOC:
        case KHUI_ACTION_LAYOUT_CUST:
            khm_set_main_window_mode(KHM_MAIN_WND_NORMAL);
            return SendMessage(khm_hwnd_main_cred, uMsg,
                               wParam, lParam);

            /* menu commands */
        case KHUI_PACTION_MENU:
            if(HIWORD(lParam) == 1)
                mm_last_hot_item = LOWORD(lParam);
            return khm_menu_activate(MENU_ACTIVATE_DEFAULT);

        case KHUI_PACTION_ESC:
            /* if esc is pressed while no menu is active, we close the
               main window */
            if (mm_last_hot_item == -1) {
                khm_close_main_window();
                return 0;
            }

            /* generic, retargetting */
        case KHUI_PACTION_UP:
        case KHUI_PACTION_UP_TOGGLE:
        case KHUI_PACTION_UP_EXTEND:
        case KHUI_PACTION_PGUP:
        case KHUI_PACTION_PGUP_EXTEND:
        case KHUI_PACTION_DOWN:
        case KHUI_PACTION_DOWN_TOGGLE:
        case KHUI_PACTION_DOWN_EXTEND:
        case KHUI_PACTION_PGDN:
        case KHUI_PACTION_PGDN_EXTEND:
        case KHUI_PACTION_LEFT:
        case KHUI_PACTION_RIGHT:
        case KHUI_PACTION_ENTER:
            /* menu tracking */
            if(mm_last_hot_item != -1) {
                switch(LOWORD(wParam)) {
                case KHUI_PACTION_LEFT:
                    khm_menu_activate(MENU_ACTIVATE_LEFT);
                    break;

                case KHUI_PACTION_RIGHT:
                    khm_menu_activate(MENU_ACTIVATE_RIGHT);
                    break;

                case KHUI_PACTION_ESC:
                case KHUI_PACTION_ENTER:
                    khm_menu_activate(MENU_ACTIVATE_NONE);
                    break;

                case KHUI_PACTION_DOWN:
                    khm_menu_track_current();
                    break;
                }
                return 0;
            }

            /*FALLTHROUGH*/
        case KHUI_PACTION_DELETE:

        case KHUI_PACTION_SELALL:
            /* otherwise fallthrough and bounce to the creds window */
            return SendMessage(khm_hwnd_main_cred, uMsg,
                               wParam, lParam);

        default:
            /* handle custom actions here */
            {
                khui_action * act;

                /* check if this is an identity menu action.  (custom
                   actions that were created for renewing or
                   destroying specific identities). */
                if (khm_check_identity_menu_action(LOWORD(wParam)))
                    break;

                act = khui_find_action(LOWORD(wParam));
                if (act && act->listener) {
                    kmq_post_sub_msg(act->listener, KMSG_ACT, KMSG_ACT_ACTIVATE, act->cmd, NULL);
                    return 0;
                }
            }
        }
        break;              /* WM_COMMAND */

    case WM_SYSCOMMAND:
        switch(wParam & 0xfff0) {
        case SC_MINIMIZE:
            khm_hide_main_window();
            return 0;

        case SC_CLOSE:
            khm_close_main_window();
            return 0;
        }
        break;

    case WM_MEASUREITEM:
        /* sent to measure the bitmaps associated with a menu item */
        if(!wParam) /* sent by menu */
            return khm_menu_measure_item(wParam, lParam);
        break;

    case WM_DRAWITEM:
        /* sent to draw a menu item */
        if(!wParam)
            return khm_menu_draw_item(wParam, lParam);
        break;

    case WM_ERASEBKGND:
        /* Don't erase the background.  The whole client area is
           covered with children.  It doesn't need to be erased */
        return TRUE;
        break;

    case WM_SIZE:
        if(hwnd == khm_hwnd_main &&
           (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED)) {
            int cwidth, cheight;
            RECT r_rebar, r_status;

            cwidth = LOWORD(lParam);
            cheight = HIWORD(lParam);

            /* resize the rebar control */
            SendMessage(khm_hwnd_rebar, WM_SIZE, 0, 0);

            khm_update_statusbar(hwnd);

            GetWindowRect(khm_hwnd_rebar, &r_rebar);
            GetWindowRect(khm_hwnd_statusbar, &r_status);

            /* the cred window fills the area between the rebar
               and the status bar */
            MoveWindow(khm_hwnd_main_cred, 0,
                       r_rebar.bottom - r_rebar.top,
                       r_status.right - r_status.left,
                       r_status.top - r_rebar.bottom, TRUE);

            SetTimer(hwnd,
                     MW_RESIZE_TIMER,
                     MW_RESIZE_TIMEOUT,
                     NULL);
            return 0;
        }
        break;

    case WM_MOVE:
        {
            SetTimer(hwnd,
                     MW_RESIZE_TIMER,
                     MW_RESIZE_TIMEOUT,
                     NULL);

            return 0;
        }
        break;

    case WM_MOVING:
        {
            RECT * r;

            r = (RECT *) lParam;
            khm_adjust_window_dimensions_for_display(r,
                                                     KHM_DOCK_AUTO | KHM_DOCKF_XBORDER);
        }
        return TRUE;

    case WM_TIMER:
        if (wParam == MW_RESIZE_TIMER) {
            main_wnd_save_sizepos();

            return 0;

        } else if (wParam == MW_REFRESH_TIMER) {
            kmq_post_message(KMSG_CRED, KMSG_CRED_REFRESH, 0, 0);

            return 0;

        }
        break;

    case WM_MENUSELECT:
        return khm_menu_handle_select(wParam, lParam);

    case KMQ_WM_DISPATCH:
        {
            kmq_message * m;
            khm_int32 rv = KHM_ERROR_SUCCESS;

            kmq_wm_begin(lParam, &m);
            if (m->type == KMSG_ACT &&
                m->subtype == KMSG_ACT_REFRESH) {
                khm_menu_refresh_items();
                khm_update_standard_toolbar();
            } else if (m->type == KMSG_ACT &&
                       m->subtype == KMSG_ACT_BEGIN_CMDLINE) {
                khm_cred_begin_startup_actions();
            } else if (m->type == KMSG_ACT &&
                       m->subtype == KMSG_ACT_CONTINUE_CMDLINE) {
                khm_cred_process_startup_actions();
            } else if (m->type == KMSG_ACT &&
                       m->subtype == KMSG_ACT_END_CMDLINE) {
                /* nothing yet */
            } else if (m->type == KMSG_ACT &&
                       m->subtype == KMSG_ACT_SYNC_CFG) {
                khm_refresh_config();
            } else if (m->type == KMSG_ACT &&
                       m->subtype == KMSG_ACT_ACTIVATE) {
                /* some custom action fired */

                khm_int32 action;
                khui_action * paction;

                action = m->uparam;
                paction = khui_find_action(action);
                if (paction && paction->data == (void *) CFGACTION_MAGIC) {
                    /* a custom configuration needs to be invoked */
                    khui_config_node node;

                    if (KHM_SUCCEEDED(khui_cfg_open(NULL, paction->name, &node))) {
                        khm_show_config_pane(node);
                        khui_cfg_release(node);
                    }
                }
            } else if (m->type == KMSG_CRED &&
                  m->subtype == KMSG_CRED_REFRESH) {
                mw_restart_refresh_timer(hwnd);
            } else if (m->type == KMSG_CRED &&
                       m->subtype == KMSG_CRED_ADDR_CHANGE) {
                khm_cred_addr_change();
            } else if (m->type == KMSG_CRED &&
                       m->subtype == KMSG_CRED_ROOTDELTA) {
                khm_refresh_identity_menus();
            } else if (m->type == KMSG_KMM &&
                       m->subtype == KMSG_KMM_I_DONE) {
                kmq_post_message(KMSG_ACT, KMSG_ACT_BEGIN_CMDLINE, 0, 0);
            }

            return kmq_wm_end(m, rv);
        }

    case WM_KHUI_ASSIGN_COMMANDLINE_V1:
        {
            HANDLE hmap;
            void * xfer;
            wchar_t mapname[256];
            khm_startup_options_v1 * pv1opt;
            int code = KHM_ERROR_SUCCESS;

            StringCbPrintf(mapname, sizeof(mapname),
                           COMMANDLINE_MAP_FMT, (DWORD) lParam);

            hmap = OpenFileMapping(FILE_MAP_READ, FALSE, mapname);

            if (hmap == NULL)
                return 1;

            xfer = MapViewOfFile(hmap, FILE_MAP_READ, 0, 0,
                                 sizeof(*pv1opt));

            if (xfer) {
                pv1opt = (khm_startup_options_v1 *) xfer;

                khm_startup.init = pv1opt->init;
                khm_startup.import = pv1opt->import;
                khm_startup.renew = pv1opt->renew;
                khm_startup.destroy = pv1opt->destroy;

                khm_startup.autoinit = pv1opt->autoinit;
                khm_startup.error_exit = FALSE;

                khm_startup.no_main_window = FALSE;
                khm_startup.remote_exit = FALSE;
                khm_startup.display = 0;

                UnmapViewOfFile(xfer);
            } else {
                code = KHM_ERROR_NOT_FOUND;
            }

            CloseHandle(hmap);

            if(InSendMessage())
                ReplyMessage(code);

            if (code == KHM_ERROR_SUCCESS) {
                khm_startup.exit = FALSE;

                khm_startup.seen = FALSE;
                khm_startup.remote = TRUE;
#ifdef DEBUG
                assert(!khm_startup.processing);
#endif
                khm_startup.processing = FALSE;

                khm_cred_begin_startup_actions();
            }

            return code;
        }

    case WM_KHUI_ASSIGN_COMMANDLINE_V2:
        {
            HANDLE hmap;
            void * xfer;
            wchar_t mapname[256];
            khm_startup_options_v2 *pv2opt = NULL;
            khm_startup_options_v3 *pv3opt = NULL;
            int code = KHM_ERROR_SUCCESS;

            StringCbPrintf(mapname, sizeof(mapname),
                           COMMANDLINE_MAP_FMT, (DWORD) lParam);

            hmap = OpenFileMapping(FILE_MAP_WRITE, FALSE, mapname);

            if (hmap == NULL)
                return 1;

            xfer = MapViewOfFile(hmap, FILE_MAP_WRITE, 0, 0,
                                 sizeof(*pv2opt));

            if (xfer) {
                pv2opt = (khm_startup_options_v2 *) xfer;

                if (pv2opt->magic != STARTUP_OPTIONS_MAGIC ||
                    (pv2opt->cb_size != sizeof(*pv2opt) &&
                     pv2opt->cb_size != sizeof(*pv3opt))) {
                    code = KHM_ERROR_INVALID_PARAM;
                    goto done_with_v2_opt;
                }

                khm_startup.init = pv2opt->init;
                khm_startup.import = pv2opt->import;
                khm_startup.renew = pv2opt->renew;
                khm_startup.destroy = pv2opt->destroy;

                khm_startup.autoinit = pv2opt->autoinit;
                khm_startup.exit = pv2opt->remote_exit;

                pv2opt->code = KHM_ERROR_SUCCESS;

                if (pv2opt->cb_size == sizeof(*pv3opt)) {
                    pv3opt = (khm_startup_options_v3 *) xfer;

                    khm_startup.display = pv3opt->remote_display;
                } else {
                    khm_startup.display = 0;
                }

            done_with_v2_opt:
                UnmapViewOfFile(xfer);
            } else {
                code = KHM_ERROR_NOT_FOUND;
            }

            CloseHandle(hmap);

            if(InSendMessage())
                ReplyMessage(code);

            if (code == KHM_ERROR_SUCCESS) {
                khm_startup.seen = FALSE;
                khm_startup.remote = TRUE;
#ifdef DEBUG
                assert(!khm_startup.processing);
#endif
                khm_startup.processing = FALSE;

                khm_cred_begin_startup_actions();
            }

            return code;
        }

    case WM_KHUI_QUERY_APP_VERSION:
        {
            HANDLE hmap;
            void * xfer;
            wchar_t mapname[256];

            StringCbPrintf(mapname, sizeof(mapname),
                           QUERY_APP_VER_MAP_FMT, (DWORD) lParam);

            hmap = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE,
                                   FALSE, mapname);

            if (hmap == NULL)
                return 1;

            xfer = MapViewOfFile(hmap, FILE_MAP_WRITE, 0, 0,
                                 sizeof(khm_query_app_version));

            if (xfer) {
                khm_process_query_app_ver((khm_query_app_version *) xfer);

                UnmapViewOfFile(xfer);
            }

            CloseHandle(hmap);
        }
        return 0;

    }
    return DefWindowProc(hwnd,uMsg,wParam,lParam);
}