static DWORD _dc_upd_bootloader( ) { ldr_config conf; DWORD status; if ( dc_get_mbr_config( -1, NULL, &conf ) != ST_OK ) return NO_ERROR; if ( (status = dc_update_boot(-1)) != ST_OK ) return 100000 + status; return NO_ERROR; }
int _update_layout( _dnode *node, int new_layout, /* -1 - init */ int *old_layout ) { BOOL boot_dev = _is_boot_device( &node->mnt.info ); ldr_config conf; int kbd_layout = KB_QWERTY; int rlt = ST_OK; if ( new_layout != -1 ) { if ( boot_dev ) { if ( (rlt = dc_get_mbr_config( -1, NULL, &conf )) != ST_OK ) { return rlt; } conf.kbd_layout = new_layout; if ( (rlt = dc_set_mbr_config( -1, NULL, &conf )) != ST_OK ) { return rlt; } } return rlt; } else { BOOL result = dc_get_mbr_config( -1, NULL, &conf ) == ST_OK; if ( old_layout ) { *old_layout = result ? conf.kbd_layout : KB_QWERTY; } return result; } }
int _get_info_install_boot_page( vol_inf *vol, _wz_sheets *sheets, int *dsk_num ) { ldr_config conf; drive_inf drv; int boot_disk_1; int boot_disk_2; int rlt = ST_ERROR; sheets[WPAGE_ENC_BOOT].show = FALSE; if ( _is_boot_device(vol) ) { sheets[WPAGE_ENC_BOOT].show = TRUE; } rlt = dc_get_drive_info( vol->w32_device, &drv ); if ( ( rlt && dsk_num ) == ST_OK ) { *dsk_num = drv.disks[0].number; } rlt = dc_get_boot_disk( &boot_disk_1, &boot_disk_2 ); if ( rlt == ST_OK ) { if ( dc_get_mbr_config( boot_disk_1, NULL, &conf ) == ST_OK ) { sheets[WPAGE_ENC_BOOT].show = FALSE; } } return rlt; }
int boot_menu(int argc, wchar_t *argv[]) { ldr_config conf; int resl; int is_small; is_small = is_param(L"-small"); do { if ( (argc == 3) && (wcscmp(argv[2], L"-enum") == 0) ) { wchar_t s_size[MAX_PATH]; wchar_t h_name[MAX_PATH]; wchar_t *str; u64 size; int i, bd_1, bd_2; wprintf( L"--------------------------------------------------------------\n" L"HDD | name | size | bootable | bootloader\n" L"----+--------------------------+---------+----------+-----------\n"); if (dc_get_boot_disk(&bd_1, &bd_2) != ST_OK) { bd_1 = bd_2 = -1; } for (i = 0; i < 100; i++) { if (size = dc_dsk_get_size(i, 0)) { dc_format_byte_size(s_size, sizeof_w(s_size), size); if (dc_get_hw_name(i, 0, h_name, sizeof_w(h_name)) != ST_OK) { h_name[0] = 0; } if (dc_get_mbr_config(i, NULL, &conf) == ST_OK) { str = L"installed"; } else { str = L"none"; } wprintf( L"hd%d | %-24s | %-8s| %-8s | %s\n", i, h_name, s_size, (i == bd_1) || (i == bd_2) ? L"yes":L"no", str ); } } resl = ST_OK; break; } if ( (argc >= 4) && (wcscmp(argv[2], L"-setmbr") == 0) ) { int d_num; if (dsk_num(argv[3], &d_num) == 0) { resl = ST_OK; break; } if ( (resl = dc_set_boot_interactive(d_num, is_small)) == ST_OK) { wprintf(L"Bootloader successfully installed to %s\n", argv[3]); } break; } if ( (argc == 4) && (wcscmp(argv[2], L"-delmbr") == 0) ) { int d_num; if (dsk_num(argv[3], &d_num) == 0) { resl = ST_OK; break; } if ( (resl = dc_unset_mbr(d_num)) == ST_OK ) { wprintf(L"Bootloader successfully removed from %s\n", argv[3]); } break; } if ( (argc == 4) && (wcscmp(argv[2], L"-updmbr") == 0) ) { int d_num; if (dsk_num(argv[3], &d_num) == 0) { resl = ST_OK; break; } if ( (resl = dc_update_boot(d_num)) == ST_OK ) { wprintf(L"Bootloader on %s successfully updated\n", argv[3]); } break; } if ( (argc >= 4) && (wcscmp(argv[2], L"-setpar") == 0) ) { if ( (resl = dc_set_boot(argv[3], 0, is_small)) == ST_FORMAT_NEEDED ) { wprintf( L"Removable media not correctly formatted\n" L"Format media? (Y/N)\n" ); if (tolower(_getch()) == 'y') { resl = dc_set_boot(argv[3], 1, is_small); } else { resl = ST_OK; break; } } if (resl != ST_OK) { break; } if ( (resl = dc_mbr_config_by_partition(argv[3], 0, &conf)) != ST_OK ) { break; } conf.options |= OP_EXTERNAL; conf.boot_type = BT_AP_PASSWORD; boot_conf_menu( &conf, L"Please set bootloader options:"); if ( (resl = dc_mbr_config_by_partition(argv[3], 1, &conf)) == ST_OK ) { wprintf(L"Bootloader successfully installed\n"); } break; } if ( (argc >= 4) && (wcscmp(argv[2], L"-makeiso") == 0) ) { if ( (resl = dc_make_iso(argv[3], is_small)) != ST_OK ) { break; } if ( (resl = dc_get_mbr_config(0, argv[3], &conf)) != ST_OK ) { break; } conf.options |= OP_EXTERNAL; conf.boot_type = BT_MBR_FIRST; boot_conf_menu( &conf, L"Please set bootloader options:"); if ( (resl = dc_set_mbr_config(0, argv[3], &conf)) == ST_OK ) { wprintf(L"Bootloader .iso image successfully created\n", argv[3]); } break; } if ( (argc >= 4) && (wcscmp(argv[2], L"-makepxe") == 0) ) { if ( (resl = dc_make_pxe(argv[3], is_small)) != ST_OK ) { break; } if ( (resl = dc_get_mbr_config(0, argv[3], &conf)) != ST_OK ) { break; } conf.options |= OP_EXTERNAL; conf.boot_type = BT_MBR_FIRST; boot_conf_menu( &conf, L"Please set bootloader options:"); if ( (resl = dc_set_mbr_config(0, argv[3], &conf)) == ST_OK ) { wprintf(L"Bootloader PXE image successfully created\n", argv[3]); } break; } if ( (argc == 4) && (wcscmp(argv[2], L"-config") == 0) ) { int d_num; wchar_t *file; int ispar; if ( ((argv[3][1] == L':') && (argv[3][2] == 0)) || ((argv[3][0] == L'\\') && (argv[3][5] == L':')) ) { ispar = 1; } else { if (dsk_num(argv[3], &d_num) == 0) { file = argv[3]; d_num = 0; } else { file = NULL; } ispar = 0; } if (ispar != 0) { resl = dc_mbr_config_by_partition(argv[3], 0, &conf); } else { resl = dc_get_mbr_config(d_num, file, &conf); } if (resl != ST_OK) { break; } boot_conf_menu( &conf, L"Please change bootloader options:"); if (ispar != 0) { resl = dc_mbr_config_by_partition(argv[3], 1, &conf); } else { resl = dc_set_mbr_config(d_num, file, &conf); } if (resl == ST_OK) { wprintf(L"Bootloader configuration successfully changed\n"); } break; } } while (0); return resl; }
int WINAPI wWinMain( HINSTANCE hinst, HINSTANCE hprev, LPWSTR cmd_line, int cmd_show ) { int d_st; int resl; if (dc_is_old_runned() != 0) { return ST_INCOMPATIBLE; } /* open DC driver device */ dc_open_device(); /* get DC sriver status */ d_st = dc_driver_status(); resl = ST_ERROR; do { if (wcscmp(cmd_line, L"-setup") == 0) { if (d_st == ST_ERROR) { resl = dc_install_driver(NULL); } else { resl = dc_update_boot(-1); if ( (resl != ST_OK) && (resl != ST_BLDR_NOTINST) ) { break; } resl = dc_update_driver(); } break; } if (wcscmp(cmd_line, L"-unins") == 0) { if (d_st == ST_ERROR) { resl = ST_ERROR; break; } resl = dc_remove_driver(); break; } if (wcscmp(cmd_line, L"-unldr") == 0) { resl = dc_unset_mbr(-1); break; } if (wcscmp(cmd_line, L"-isboot") == 0) { ldr_config conf; resl = dc_get_mbr_config(-1, NULL, &conf); break; } if (wcscmp(cmd_line, L"-isenc") == 0) { vol_inf info; u32 flags; wchar_t boot_dev[MAX_PATH]; int is_enc = 0; if (dc_open_device() != ST_OK) { resl = ST_ERROR; break; } if (dc_get_boot_device(boot_dev) != ST_OK) { boot_dev[0] = 0; } if (dc_first_volume(&info) == ST_OK) { do { flags = info.status.flags; if ( ((flags & F_SYSTEM) || (wcscmp(info.device, boot_dev) == 0)) && (flags & F_ENABLED) ) { is_enc = 1; } } while (dc_next_volume(&info) == ST_OK); } dc_close_device(); resl = is_enc != 0 ? ST_ENCRYPTED : ST_OK; break; } } while (0); return resl; }
INT_PTR CALLBACK _password_change_dlg_proc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam ) { WORD code = HIWORD(wparam); WORD id = LOWORD(wparam); wchar_t display[MAX_PATH] = { 0 }; static dlgpass *info; int k; int check_init[ ] = { IDC_CHECK_SHOW_CURRENT, IDC_USE_KEYFILES_CURRENT, IDC_CHECK_SHOW_NEW, IDC_USE_KEYFILES_NEW, -1 }; _ctl_init static_head[ ] = { { L"# Current Password", IDC_HEAD_PASS_CURRENT, 0 }, { L"# New Password", IDC_HEAD_PASS_NEW, 0 }, { L"# Password Rating", IDC_HEAD_RATING, 0 }, { STR_NULL, -1, -1 } }; switch (message) { case WM_CTLCOLOREDIT : return _ctl_color(wparam, _cl(COLOR_BTNFACE, LGHT_CLR)); break; case WM_CTLCOLORSTATIC : { HDC dc = (HDC)wparam; COLORREF bgcolor, fn = 0; SetBkMode(dc, TRANSPARENT); k = 0; while (pass_gr_ctls[k].id != -1) { if (pass_gr_ctls[k].hwnd == (HWND)lparam) fn = pass_gr_ctls[k].color; if (pass_pe_ctls[k].hwnd == (HWND)lparam) fn = pass_pe_ctls[k].color; k++; } SetTextColor(dc, fn); bgcolor = GetSysColor(COLOR_BTNFACE); SetDCBrushColor(dc, bgcolor); return (INT_PTR)GetStockObject(DC_BRUSH); } break; case WM_INITDIALOG : { info = (dlgpass *)lparam; SendMessage(GetDlgItem(hwnd, IDE_PASS_NEW_CONFIRM), EM_LIMITTEXT, MAX_PASSWORD, 0); SendMessage(GetDlgItem(hwnd, IDE_PASS_CURRENT), EM_LIMITTEXT, MAX_PASSWORD, 0); SendMessage(GetDlgItem(hwnd, IDE_PASS_NEW), EM_LIMITTEXT, MAX_PASSWORD, 0); SendMessage(hwnd, WM_COMMAND, MAKELONG(IDE_PASS_NEW, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_NEW)); if (info->node) { _snwprintf(display, sizeof_w(display), L"[%s] - %s", info->node->mnt.info.status.mnt_point, info->node->mnt.info.device); } else { wcscpy(display, L"Change password"); } SetWindowText(hwnd, display); SendMessage( GetDlgItem(hwnd, IDP_BREAKABLE), PBM_SETBARCOLOR, 0, _cl(COLOR_BTNSHADOW, DARK_CLR-20) ); SendMessage( GetDlgItem(hwnd, IDP_BREAKABLE), PBM_SETRANGE, 0, MAKELPARAM(0, 193) ); k = 0; while (static_head[k].id != -1) { SetWindowText(GetDlgItem(hwnd, static_head[k].id), static_head[k].display); SendMessage(GetDlgItem(hwnd, static_head[k].id), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0); k++; } k = 0; while (check_init[k] != -1) { _sub_class(GetDlgItem(hwnd, check_init[k]), SUB_STATIC_PROC, HWND_NULL); _set_check(hwnd, check_init[k], FALSE); k++; } SetForegroundWindow(hwnd); return 1L; } break; case WM_USER_CLICK : { if ( (HWND)wparam == GetDlgItem(hwnd, IDC_CHECK_SHOW_CURRENT) ) { SendMessage(GetDlgItem(hwnd, IDE_PASS_CURRENT), EM_SETPASSWORDCHAR, _get_check(hwnd, IDC_CHECK_SHOW_CURRENT) ? 0 : '*', 0 ); InvalidateRect(GetDlgItem(hwnd, IDE_PASS_CURRENT), NULL, TRUE); return 1L; } if ( (HWND)wparam == GetDlgItem(hwnd, IDC_CHECK_SHOW_NEW) ) { int mask = _get_check(hwnd, IDC_CHECK_SHOW_NEW) ? 0 : '*'; SendMessage(GetDlgItem(hwnd, IDE_PASS_NEW), EM_SETPASSWORDCHAR, mask, 0); SendMessage(GetDlgItem(hwnd, IDE_PASS_NEW_CONFIRM), EM_SETPASSWORDCHAR, mask, 0); InvalidateRect(GetDlgItem(hwnd, IDE_PASS_NEW), NULL, TRUE); InvalidateRect(GetDlgItem(hwnd, IDE_PASS_NEW_CONFIRM), NULL, TRUE); return 1L; } if ( (HWND)wparam == GetDlgItem(hwnd, IDC_USE_KEYFILES_CURRENT) ) { SendMessage( hwnd, WM_COMMAND, MAKELONG(IDE_PASS_CURRENT, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_CURRENT) ); EnableWindow( GetDlgItem(hwnd, IDB_USE_KEYFILES_CURRENT), _get_check(hwnd, IDC_USE_KEYFILES_CURRENT) ); return 1L; } if ( (HWND)wparam == GetDlgItem(hwnd, IDC_USE_KEYFILES_NEW) ) { SendMessage( hwnd, WM_COMMAND, MAKELONG(IDE_PASS_NEW, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_NEW) ); EnableWindow( GetDlgItem(hwnd, IDB_USE_KEYFILES_NEW), _get_check(hwnd, IDC_USE_KEYFILES_NEW )); return 1L; } } break; case WM_COMMAND : if ( id == IDB_USE_KEYFILES_CURRENT ) { _dlg_keyfiles( hwnd, KEYLIST_CURRENT ); SendMessage( hwnd, WM_COMMAND, MAKELONG(IDE_PASS_CURRENT, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_CURRENT) ); } if ( id == IDB_USE_KEYFILES_NEW ) { _dlg_keyfiles( hwnd, KEYLIST_CHANGE_PASS ); SendMessage( hwnd, WM_COMMAND, MAKELONG(IDE_PASS_NEW, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_NEW) ); } if ( code == EN_CHANGE ) { BOOL correct_current, correct_new; int id_stat_current, id_stat_new; dc_pass *pass; dc_pass *verify; ldr_config conf; int kb_layout = -1; int keylist; if ( info->node && _is_boot_device(&info->node->mnt.info) ) { if (dc_get_mbr_config( -1, NULL, &conf ) == ST_OK) { kb_layout = conf.kbd_layout; } } if ( id == IDE_PASS_NEW ) { int entropy; dc_pass *pass; pass = _get_pass(hwnd, IDE_PASS_NEW); _draw_pass_rating(hwnd, pass, kb_layout, &entropy); secure_free(pass); SendMessage( GetDlgItem(hwnd, IDP_BREAKABLE), PBM_SETPOS, (WPARAM)entropy, 0 ); } pass = _get_pass(hwnd, IDE_PASS_CURRENT); keylist = _get_check(hwnd, IDC_USE_KEYFILES_CURRENT) ? KEYLIST_CURRENT : KEYLIST_NONE; correct_current = _input_verify(pass, NULL, keylist, -1, &id_stat_current ); secure_free(pass); pass = _get_pass(hwnd, IDE_PASS_NEW); verify = _get_pass(hwnd, IDE_PASS_NEW_CONFIRM); keylist = _get_check(hwnd, IDC_USE_KEYFILES_NEW) ? KEYLIST_CHANGE_PASS : KEYLIST_NONE; correct_new = _input_verify(pass, verify, keylist, kb_layout, &id_stat_new ); secure_free(pass); secure_free(verify); SetWindowText(GetDlgItem(hwnd, IDC_PASS_STATUS_CURRENT), _get_text_name(id_stat_current, pass_status)); SetWindowText(GetDlgItem(hwnd, IDC_PASS_STATUS_NEW), _get_text_name(id_stat_new, pass_status)); EnableWindow(GetDlgItem(hwnd, IDOK), correct_current && correct_new); return 1L; } if ( (id == IDCANCEL) || (id == IDOK) ) { if ( id == IDOK ) { info->pass = _get_pass_keyfiles(hwnd, IDE_PASS_CURRENT, IDC_USE_KEYFILES_CURRENT, KEYLIST_CURRENT); info->new_pass = _get_pass_keyfiles(hwnd, IDE_PASS_NEW, IDC_USE_KEYFILES_NEW, KEYLIST_CHANGE_PASS); if ( IsWindowEnabled(GetDlgItem(hwnd, IDC_COMBO_MNPOINT)) && info->mnt_point ) { GetWindowText( GetDlgItem(hwnd, IDC_COMBO_MNPOINT), (wchar_t *)info->mnt_point, MAX_PATH ); } } EndDialog (hwnd, id); return 1L; } break; case WM_DESTROY: { _wipe_pass_control(hwnd, IDE_PASS_NEW_CONFIRM); _wipe_pass_control(hwnd, IDE_PASS_CURRENT); _wipe_pass_control(hwnd, IDE_PASS_NEW); _keyfiles_wipe(KEYLIST_CURRENT); _keyfiles_wipe(KEYLIST_CHANGE_PASS); return 0L; } break; default: { int rlt = _draw_proc(message, lparam); if (rlt != -1) return rlt; } } return 0L; }