📄 bsect.c
字号:
if (pass == walk->unique || (!walk->unique && !strcmp(walk->label,label) && (walk->unique=pass)) ) { memcpy(crcval, walk->crc, MAX_PW_CRC*sizeof(int)); return; } } walk = alloc_t(PASSWORD); if (!walk) die("Out of memory"); walk->next = pwsave; pwsave = walk; walk->unique = pass; walk->label = stralloc(label); printf("\nEntry for %s used null password\n", label); pass = pass2 = NULL; do { if (pass) { printf(" *** Phrases don't match ***\n"); pw_wipe(pass); pw_wipe(pass2); } printf("Type passphrase: "); pass2 = pw_input(); printf("Please re-enter: "); pass = pw_input(); } while (strcmp(pass,pass2)); printf("\n"); pw_wipe(pass2); hash_password(pass, walk->crc); pw_wipe(pass); memcpy(crcval, walk->crc, MAX_PW_CRC*sizeof(int));}static void retrieve_crc(int crcval[]){ int i; char *pass; if (!pwsave) { if (cfg_pw_open()) pw_fill_cache(); } pass = cfg_get_strg(cf_all,"password"); if (pass) pw_get(pass,crcval,0); else pw_get(cfg_get_strg(cf_options,"password"),crcval,1); if (verbose >= 2) { printf("Password found is"); for (i=0; i<MAX_PW_CRC; i++) printf(" %08X", crcval[i]); printf("\n"); }}static void open_bsect(char *boot_dev){ struct stat st; if (verbose > 0) printf("Reading boot sector from %s\n",boot_dev ? boot_dev : "current root."); boot_devnam = boot_dev; if (!boot_dev || !strcmp(boot_dev, "/") ) { if (stat("/",&st) < 0) pdie("stat /");#if 0 if ((st.st_dev & PART_MASK) > PART_MAX)#else if (MAJOR(st.st_dev) != MAJOR_MD && (st.st_dev & P_MASK(st.st_dev)) > PART_MAX)#endif die("Can't put the boot sector on logical partition 0x%04X", (int)st.st_dev); fd = dev_open(&dev,boot_dev_nr = st.st_dev,O_RDWR); boot_devnam = dev.name; use_dev_close = 1; } else { if ((fd = open(boot_dev,O_RDWR)) < 0) die("open %s: %s",boot_dev,strerror(errno)); if (fstat(fd,&st) < 0) die("stat %s: %s",boot_dev,strerror(errno)); if (!S_ISBLK(st.st_mode)) boot_dev_nr = 0; else boot_dev_nr = st.st_rdev; }/* new code to get boot device code *//* plus geo_open will trigger VolumeMgmt (pf_hard_disk_scan) before the boot sector is actually read; timing is very important */{ GEOMETRY geo; geo_open(&geo, boot_devnam, O_RDONLY); bios_boot = geo.device; geo_close(&geo);} if (boot_dev_nr && !is_first(boot_dev_nr) && !nowarn) fprintf(errstd,"Warning: %s is not on the first disk\n",boot_dev ? boot_dev : "current root"); if (read(fd,(char *) &bsect,SECTOR_SIZE) != SECTOR_SIZE) die("read %s: %s",boot_dev ? boot_dev : dev.name,strerror(errno)); bsect_orig = bsect; ireloc = part_nowrite(boot_devnam); if (ireloc == PTW_DOS + PTW_NTFS) ireloc = PTW_DOS;/* check for override (-F) command line flag */ if (ireloc>PTW_DOS && force_fs) {#if 0 fprintf(errstd, "WARNING: '-F' override used. Filesystem on %s may be destroyed.\n", boot_devnam);#else fprintf(stderr, "WARNING: '-F' override used. Filesystem on %s may be destroyed.\n", boot_devnam); if (!yesno("\nProceed? ",0)) exit(0);#endif ireloc=PTW_OKAY; }}void bsect_read(char *boot_dev,BOOT_SECTOR *buffer){ open_bsect(boot_dev); *buffer = bsect; (void) close(fd);}static void menu_do_scheme(char *scheme, MENUTABLE *menu){ static char khar[] = "kbgcrmywKBGCRMYW"; unsigned int fg, bg; int i; unsigned char *at; /* order of color attributes is: text, hilighted text, border, title */#define color(c) ((int)(strchr(khar,(int)(c))-khar)) bg = 0; at = &(menu->at_text); for (i=0; i<4 && *scheme; i++) { fg = color(*scheme); if (fg>=16) die("Invalid menu-scheme color: '%c'", *scheme); if (*++scheme) bg = color(*scheme); else { die("Invalid menu-scheme syntax"); } if (bg>=16) die("Invalid menu-scheme color: '%c'", *scheme); if (*++scheme) { if (ispunct(*scheme)) scheme++; else die("Invalid menu-scheme punctuation"); } if (bg>=8 && !nowarn) fprintf(errstd, "Warning: menu-scheme BG color may not be intensified\n"); *at++ = ((bg<<4) | fg) & 0x7F; } /* check on the TEXT color */ if (menu->at_text == 0) { if (!nowarn) fprintf(errstd, "Warning: menu-scheme \"black on black\" changed to " "\"white on black\"\n"); menu->at_text = 0x07; } /* check on the HIGHLIGHT color */ if (menu->at_highlight == 0) menu->at_highlight = ((menu->at_text<<4)&0x70) | ((menu->at_text>>4)&0x0f); /* check on the BORDER color */ if (menu->at_border == 0) menu->at_border = menu->at_text; /* check on the TITLE color */ if (menu->at_title == 0) menu->at_title = menu->at_border; strncpy(menu->menu_sig, "MENU", 4); if (verbose>=5) printf("Menu attributes: text %02X highlight %02X border %02X title %02X\n", (int)menu->at_text, (int)menu->at_highlight, (int)menu->at_border, (int)menu->at_title);#undef color}void bsect_open(char *boot_dev,char *map_file,char *install,int delay, int timeout, int raid_offset){ static char coms[] = "0123"; static char parity[] = "NnOoEe"; static char bps[] = "110\000150\000300\000600\0001200\0002400\0004800\0009600\000" "19200\00038400\00057600\000115200\000?\000?\000?\000?\000" "56000\000"; GEOMETRY geo; struct stat st; int i, speed, bitmap, j, dataend; int m_fd=0,kt_fd,sectors; char *message,*colon,*serial,*walk,*this,*keytable,*scheme; MENUTABLE *menu; BITMAPFILEHEADER fhv; BITMAPHEADER bmhv; BITMAPLILOHEADER lhv; unsigned int timestamp;#ifdef LCF_BUILTIN BUILTIN_FILE *loader;#else int i_fd;#endif#if 0printf("sizeof(IMAGE_DESCR) = %d\n", sizeof(IMAGE_DESCR));printf("sizeof(DESCR_SECTORS) = %d\n", sizeof(DESCR_SECTORS));printf("MAX_IMAGES = %d\n", MAX_IMAGES);#endif image = image_base = i = 0; memset(&menuparams, 0, sizeof(menuparams)); if (stat(map_file,&st) >= 0 && !S_ISREG(st.st_mode)) die("Map %s is not a regular file.",map_file); open_bsect(boot_dev); part_verify(boot_dev_nr,1); if (ireloc>PTW_DOS) { die("Filesystem would be destroyed by LILO boot sector: %s", boot_dev); } else if (ireloc==PTW_DOS) { if (!nowarn) fprintf(errstd,"Warning: boot record relocation beyond BPB is necessary: %s\n", boot_dev); }#ifdef EARLY_MAP if ((colon = strrchr(map_name = map_file,':')) == NULL) strcat(strcpy(temp_map,map_name),MAP_TMP_APP); else { *colon = 0; strcat(strcat(strcpy(temp_map,map_name),MAP_TMP_APP),colon+1); *colon = ':'; } map_create(temp_map); temp_register(temp_map);#endif if (!install) {#if !defined(LCF_NOINSTDEF) || defined(LCF_BUILTIN) install = DFL_BOOT;#else die("No boot loader specified ('-i' or 'install =')");#endif } /* if (install) */ { timestamp = bsect.par_1.timestamp; /* preserve timestamp *//* determine which secondary loader to use */ loader = select_loader(); if (verbose > 0) { printf("Using %s secondary loader\n", loader==&Bitmap ? "BITMAP" : loader==&Third ? "MENU" : "TEXT" ); } memcpy(&bsect, First.data, MAX_BOOT_SIZE); bsect.par_1.timestamp = timestamp; map_begin_section(); /* no access to the (not yet open) map file required, because this map is built in memory */ here2 = map_insert_data (loader->data, loader->size); memcpy(¶m2,loader->data,sizeof(param2));#ifdef LCF_FIRST6 /* write just the 4 bytes (sa6==2) */ sectors = map_write((SECTOR_ADDR*)secondary_map, (SECTOR_SIZE-4)/sizeof(SECTOR_ADDR)-2, 1, 2);#else sectors = map_write((SECTOR_ADDR*)secondary_map, (SECTOR_SIZE-4)/sizeof(SECTOR_ADDR)-2, 1);#endif memcpy(secondary_map+SECTOR_SIZE-4, EX_MAG_STRING, 4); /* fill in full size of secondary boot loader in paragraphs */ /*bsect.par_1.*/dataend = (sectors + 5 + MAX_DESCR_SECS) * (SECTOR_SIZE/16); if (verbose > 1) printf("Secondary loader: %d sector%s (0x%0X dataend).\n",sectors,sectors == 1 ? "" : "s", /*bsect.par_1.*/dataend*16); stage_flags = ((BOOT_SECTOR*)(loader->data)) -> par_2.stage; if ((stage_flags & 0xFF) != STAGE_SECOND) die("Ill-formed boot loader; no second stage section"); if (verbose>=4) printf("install(2) flags: 0x%04X\n", (int)stage_flags); }#ifndef EARLY_MAP if ((colon = strrchr(map_name = map_file,':')) == NULL) strcat(strcpy(temp_map,map_name),MAP_TMP_APP); else { *colon = 0; strcat(strcat(strcpy(temp_map,map_name),MAP_TMP_APP),colon+1); *colon = ':'; } map_create(temp_map); temp_register(temp_map);#endif map_begin_section(); map_add_sector(secondary_map);#ifdef LCF_FIRST6 /* write out six byte address */ (void) map_write(&bsect.par_1.secondary,1,0,1);#else (void) map_write(&bsect.par_1.secondary,1,0);#endif/* if the state of the BIOS is DL_GOOD, always mark when boot==map if the state of the BIOS is < DL_GOOD, never mark */ if ( bios_boot == bios_map && (bios_passes_dl == DL_GOOD || (do_md_install && !(extra==X_MBR_ONLY )) ) ) bsect.par_1.prompt |= FLAG_MAP_ON_BOOT; if (bios_boot!=bios_map && !nowarn) fprintf(errstd, "Warning: The boot sector and map file are on different disks.\n"); if ( (bios_map & 0x80) && !do_md_install && !cfg_get_flag(cf_options, "static-bios-codes") ) /* hard disk & not raid master */ bsect.par_1.map_serial_no = serial_no[bios_map - 0x80]; if (verbose>=2) printf("bios_boot = 0x%02X bios_map = 0x%02X map==boot = %d map S/N: %08X\n", bios_boot, bios_map, !!(bsect.par_1.prompt&FLAG_MAP_ON_BOOT), bsect.par_1.map_serial_no); /* code to get creation time of map file */ if (stat(temp_map, &st) < 0) die("Cannot get map file status"); param2.map_stamp = bsect.par_1.map_stamp = st.st_mtime; if (verbose>=4) printf("Map time stamp: %08X\n", (int)bsect.par_1.map_stamp); *(unsigned short *) &bsect.sector[BOOT_SIG_OFFSET] = BOOT_SIGNATURE; message = cfg_get_strg(cf_options,"message"); scheme = cfg_get_strg(cf_options,"bitmap"); if (message && scheme) die("'bitmap' and 'message' are mutually exclusive"); param2.msg_len = 0; bitmap = (loader==&Bitmap); if (bitmap) { message = scheme; if (!(stage_flags & STAGE_FLAG_BMP4)) { if (!nowarn) fprintf(errstd,"Warning: Non-bitmap capable boot loader; 'bitmap=' ignored.\n"); message = NULL; } } j = -1; if (message) { if (verbose >= 1) { printf("Mapping %s file %s", bitmap ? "bitmap" : "message", message); show_link(message); printf("\n"); } m_fd = geo_open(&geo,message,O_RDONLY); if (fstat(m_fd,&st) < 0) die("stat %s: %s",message,strerror(errno)); /* the -2 below is because of GCC's alignment requirements */ i = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPHEADER)+sizeof(RGB)*16+ sizeof(BITMAPLILOHEADER); if (bitmap || st.st_size>i) { int bits=0; j = get_std_headers(m_fd, &fhv, &bmhv, &lhv); if (j<0) die("read %s: %s", message, strerror(errno)); if (j==0 || j>2) { /* definitely a bitmap file */ BITMAPHEADER *bmh = &bmhv; if (verbose >= 3) { printf("width=%d height=%d planes=%d bits/plane=%d\n", (int)bmh->width, (int)bmh->height, (int)bmh->numBitPlanes, (int)bmh->numBitsPerPlane); } if (bmh->size == sizeof(BITMAPHEADER) && bmh->width==640 && bmh->height==480 && ((bits = bmh->numBitPlanes * bmh->numBitsPerPlane) == 4 || bits == 8) ) { if (!bitmap) die("Message specifies a bitmap file"); if (bits>4 && adapter<VIDEO_VESA && !nowarn) fprintf(errstd,"Warning: Video adapter does not support VESA BIOS extensions needed for\n" " display of 256 colors. Boot loader will fall back to TEXT only operation.\n"); } else if (bitmap) die("Unsupported bitmap"); } else if (bitmap) die("Not a bitmap file"); } i = bitmap ? MAX_KERNEL_SECS*SECTOR_SIZE : MAX_MESSAGE; if (st.st_size > i) die("%s is too big (> %d bytes)",message,i); param2.msg_len = bitmap ? (st.st_size+15)/16 : st.st_size; map_begin_section();#ifndef LCF_UNIFY map_add(&geo,0,((st.st_size)+SECTOR_SIZE-1)/SECTOR_SIZE);#else map_insert_file (&geo,0,(st.st_size+SECTOR_SIZE-1)/SECTOR_SIZE);#endif sectors = map_end_section(&menuparams.msg,0); if (verbose >= 2) printf("%s: %d sector%s.\n",bitmap?"Bitmap":"Message", sectors,sectors == 1 ? "" : "s"); geo_close(&geo); } if (cfg_get_flag(cf_options,"el-torito-bootable-cd")) param2.flag2 |= FLAG2_EL_TORITO; if (cfg_get_flag(cf_options,"unattended")) { param2.flag2 |= FLAG2_UNATTENDED; if (timeout < 0) { fprintf(errstd,"Warning: UNATTENDED used; setting TIMEOUT to 200 (20 seconds)\n"); timeout = 200; } } serial = cfg_get_strg(cf_options,"serial"); if (serial) { if (!(stage_flags & STAGE_FLAG_SERIAL))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -