BOOL CKrb4ConfigFileLocation::OnInitDialog() { CPropertyPage::OnInitDialog(); INT krbCreate = 0; INT krbrealmCreate = 0; CHAR krb_path[MAX_PATH]; CHAR krbrealm_path[MAX_PATH]; CHAR ticketName[MAX_PATH]; unsigned int krb_path_sz = sizeof(krb_path); unsigned int krbrealm_path_sz = sizeof(krbrealm_path); CString strMessage; // Set KRB.CON memset(krb_path, '\0', sizeof(krb_path)); if (!pkrb_get_krbconf2(krb_path, &krb_path_sz)) { // Error has happened m_noKrbFileStartupWarning = TRUE; } else { // normal find m_initKrbFile = krb_path; m_newKrbFile = m_initKrbFile; SetDlgItemText(IDC_EDIT_KRB_LOC, m_initKrbFile); } // Set KRBREALM.CON memset(krbrealm_path, '\0', sizeof(krbrealm_path)); if (!pkrb_get_krbrealm2(krbrealm_path, &krbrealm_path_sz)) { // Error has happened m_noKrbrealmFileStartupWarning = TRUE; } else { // normal find m_initKrbrealmFile = krbrealm_path; m_newKrbrealmFile = m_initKrbrealmFile; SetDlgItemText(IDC_EDIT_KRBREALM_LOC, m_initKrbrealmFile); } if (pLeash_get_lock_file_locations() || getenv("KRB4_KRB.REALMS") || getenv("KRB4_KRB.CONF") || getenv("KRB4_CONFIG")) { GetDlgItem(IDC_EDIT_KRB_LOC)->EnableWindow(FALSE); GetDlgItem(IDC_EDIT_KRBREALM_LOC)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON_KRB_BROWSE)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON_KRBREALM_BROWSE)->EnableWindow(FALSE); } else if ( !(getenv("KRB4_KRB.REALMS") || getenv("KRB4_KRB.CONF") || getenv("KRB4_CONFIG")) ) { GetDlgItem(IDC_STATIC_CONFILES)->ShowWindow(FALSE); } // Set TICKET.KRB file Editbox *ticketName = NULL; pkrb_set_tkt_string(0); char *pticketName = ptkt_string(); if (pticketName) strcpy(ticketName, pticketName); if (!*ticketName) { LeashErrorBox("OnInitDialog::Can't locate ticket file", TICKET_FILE); } else { m_initTicketFile = m_newTicketFile = ticketName; m_ticketEditBox.ReplaceSel(m_initTicketFile); } if (getenv("KRBTKFILE")) GetDlgItem(IDC_EDIT_TICKET_FILE)->EnableWindow(FALSE); else GetDlgItem(IDC_STATIC_TXT)->ShowWindow(FALSE); return FALSE; }
INT_PTR CALLBACK krb4_confg_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static BOOL in_init = FALSE; k4_config_dlg_data * d; switch(uMsg) { case WM_INITDIALOG: { wchar_t wbuf[MAX_PATH]; CHAR krb_path[MAX_PATH]; CHAR krbrealm_path[MAX_PATH]; CHAR ticketName[MAX_PATH]; char * pticketName; size_t krb_path_sz = sizeof(krb_path); size_t krbrealm_path_sz = sizeof(krbrealm_path); khm_size cbsize; d = PMALLOC(sizeof(*d)); ZeroMemory(d, sizeof(*d)); #pragma warning(push) #pragma warning(disable: 4244) SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) d); #pragma warning(pop) d->node = (khui_config_node) lParam; in_init = TRUE; // Set KRB.CON memset(krb_path, '\0', sizeof(krb_path)); if (!pkrb_get_krbconf2(krb_path, &krb_path_sz)) { // Error has happened } else { // normal find AnsiStrToUnicode(wbuf, sizeof(wbuf), krb_path); SetDlgItemText(hwnd, IDC_CFG_CFGPATH, wbuf); StringCbCopyA(d->krb_path, sizeof(d->krb_path), krb_path); } // Set KRBREALM.CON memset(krbrealm_path, '\0', sizeof(krbrealm_path)); if (!pkrb_get_krbrealm2(krbrealm_path, &krbrealm_path_sz)) { // Error has happened } else { AnsiStrToUnicode(wbuf, sizeof(wbuf), krbrealm_path); SetDlgItemText(hwnd, IDC_CFG_RLMPATH, wbuf); StringCbCopyA(d->krbrealm_path, sizeof(d->krbrealm_path), krbrealm_path); } cbsize = sizeof(wbuf); if (KHM_SUCCEEDED(khc_read_string(csp_params, L"TktString", wbuf, &cbsize)) && wbuf[0] != L'\0') { UnicodeStrToAnsi(ticketName, sizeof(ticketName), wbuf); } else { // Set TICKET.KRB file Editbox *ticketName = 0; pkrb_set_tkt_string(0); pticketName = ptkt_string(); if (pticketName) StringCbCopyA(ticketName, sizeof(ticketName), pticketName); } if (!*ticketName) { // error } else { AnsiStrToUnicode(wbuf, sizeof(wbuf), ticketName); SetDlgItemText(hwnd, IDC_CFG_CACHE, wbuf); StringCbCopyA(d->tkt_string, sizeof(d->tkt_string), ticketName); } in_init = FALSE; } break; case WM_COMMAND: if (MAKEWPARAM(IDC_CFG_CACHE, EN_CHANGE)) { char tkt_string[MAX_PATH]; wchar_t wtkt_string[MAX_PATH]; if (in_init) { return TRUE; } d = (k4_config_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); if (d == NULL) return TRUE; tkt_string[0] = 0; wtkt_string[0] = 0; GetDlgItemText(hwnd, IDC_CFG_CACHE, wtkt_string, ARRAYLENGTH(wtkt_string)); UnicodeStrToAnsi(tkt_string, sizeof(tkt_string), wtkt_string); if (_stricmp(tkt_string, d->tkt_string)) { khui_cfg_set_flags(d->node, KHUI_CNFLAG_MODIFIED, KHUI_CNFLAG_MODIFIED); } else { khui_cfg_set_flags(d->node, 0, KHUI_CNFLAG_MODIFIED); } return TRUE; } break; case KHUI_WM_CFG_NOTIFY: if (HIWORD(wParam) == WMCFG_APPLY) { wchar_t wtkt_string[MAX_PATH]; char tkt_string[MAX_PATH]; int t; d = (k4_config_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); if (d == NULL) return TRUE; t = GetDlgItemText(hwnd, IDC_CFG_CACHE, wtkt_string, ARRAYLENGTH(wtkt_string)); if (t == 0) return TRUE; UnicodeStrToAnsi(tkt_string, sizeof(tkt_string), wtkt_string); if (_stricmp(tkt_string, d->tkt_string)) { pkrb_set_tkt_string(tkt_string); khc_write_string(csp_params, L"TktString", wtkt_string); khui_cfg_set_flags(d->node, KHUI_CNFLAG_APPLIED, KHUI_CNFLAG_APPLIED | KHUI_CNFLAG_MODIFIED); khm_krb4_list_tickets(); } else { khui_cfg_set_flags(d->node, 0, KHUI_CNFLAG_MODIFIED); } return TRUE; } break; case WM_DESTROY: d = (k4_config_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); if (d) { PFREE(d); SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) 0); } break; } return FALSE; }