📄 bcfsck.c
字号:
/********************************************************************* Copyright (c) 1994-1999 Jetico, Inc., Finland* All rights reserved.** File: bcformat.c* Revision: $Id: bcfsck.c,v 1.15 2005/05/14 07:58:33 crypt Rel-1.6-3 $* Created:* Description: implementation of format container routine********************************************************************/#include <sys/mount.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <errno.h>#include <bc_types.h>#include <bc_ioctl.h>#include <kg_defs.h>#include <fcntl.h>#include <kblock.h>#include <string.h>#include "keygen.h"#include "alg.h"#include "config.h"#include "bctool.h"#include "misc.h"#include "error.h"#include "header.h"char bcfsck_c[]="$Id: bcfsck.c,v 1.15 2005/05/14 07:58:33 crypt Rel-1.6-3 $";int bcfsck (int argc, char ** argv){ struct HiddenSector hs; char *device; int fd, fdd, flag; long long Offset; ALG_SERV Alg; DWORD KeyHandle,DataSize,_offset; DATA_BLOCK db, *pdb; alg_info *alg_inf; char *command[16]; if ( argc < 2 ) { msg(stderr,"Please specify container name\n"); return -1; } else if ( argc > 2 ) { msg(stderr,"Too many parameters\n"); return -1; } if ( (device=FindFreeDevice())==NULL ) { msg(stderr,"Can not find free device\n"); return -1; } if ( (Alg.bc_fd = open(device, O_RDONLY)) < 0 ) { msg(stderr,"open(\"%s\",O_RDONLY): %s\n",device,strerror(errno));// perror(device); return -1; } if ( (fd = open(argv[1], O_RDWR|O_LARGEFILE)) < 0 ) { msg(stderr,"open(\"%s\",O_RDWR|O_LARGEFILE): %s\n",argv[1],strerror(errno)); close(Alg.bc_fd); return -1; } if ( read(fd, &hs, sizeof(hs))!=sizeof(hs) ) { msg(stderr,"Can not read container header\n"); close(fd); close(Alg.bc_fd); return -1; } if ( strncmp(hs.br.OEMid, "LOCOS94 ", sizeof(hs.br.OEMid))!=0 ) { msg(stderr,"%s is not valid BestCrypt container\n",argv[1]); close(fd); close(Alg.bc_fd); return -1; } if ('B' == hs.br.jmpCode[0]) { msg(stderr, "WARNING! Container \"%s\" is probably in use!\n\n" "Two reasons for the report are possible:\n" " 1. The container is already mounted. In this case do not use the container\n" " until someone dismounts it.\n" " 2. The container was not unmounted properly last time, so a lock mask \n" " for the container was not reset. If so, unlock the container by running the command:\n" " \"bctool unlock %s\" \n\n", argv[1],argv[1]); close(fd); close(Alg.bc_fd); return -1; } if ( read(fd, &db, sizeof (db))!=sizeof(db) ) { msg(stderr,"Can not read data block\n"); close(fd); close(Alg.bc_fd); return -1; } if ( (alg_inf=GetInfoById(hs.algorithmId))==NULL ) { msg(stderr,"Unknown algorithm Id: %d\n",hs.algorithmId); close(fd); close(Alg.bc_fd); return -1; } if ( o_fstype==NULL && (o_fstype=getFStypeById(hs.fileSystemId))==NULL ) { msg(stderr,"Unknown filesystem. Try: -t fstype \n"); close(fd); close(Alg.bc_fd); return -1; } Alg.alg_id=hs.algorithmId; Alg.alg_module =alg_inf->mod_name; pdb = &db; DataSize = sizeof(db);// Offset=hs.dwDataOffset; if (KGSHA256_ID == hs.keyGenId) { UseSha256(); } CreateKeyHandleEx(Alg,alg_inf->key_size,NULL,"Enter password:",CFLAG_VERIFY_AND_LOAD_KEY,(BYTE **)&pdb,&DataSize,&KeyHandle,&Error,&_offset); if ( Error!=0 ) { print_error(Error); close(fd); close(Alg.bc_fd); return -1; } if (_offset) Offset = (long long)512 * _offset; else Offset = hs.dwDataOffset; Error=bc_set_fdkh64(Alg, KeyHandle, fd, Offset, 0, 0, hs.version == 0 ? 0 : BC_FLAGS_IV_64BIT); if ( Error!=0 ) { print_error(Error); FreeKeyHandle(Alg,KeyHandle); close(fd); close(Alg.bc_fd); return -1; }//----------------------------------------------------------------------// BestCrypt for Windows 7.11+ compatibility code//---------------------------------------------------------------------- fdd = open(device, O_RDONLY); // workaround for 2.4.x flag = 0; _offset = check_msdos_partition(0 > fdd ? Alg.bc_fd : fdd, &flag); if (0 <= fdd) close(fdd); if (0 != (flag & 0xFF000000)) { // partition table detected msg(stderr, "Warning! %d (%d extended) partition(s) detected inside container.\n", flag >> 24, (flag >> 16) & 0xFF); if (0x0100 != (flag >> 16)) { // non-trivial case if (!ask_y_n("Do you want to continue? (y/[n]):")) { FreeKeyHandle(Alg, KeyHandle); close(Alg.bc_fd); close(fd); return 0; } }// Offset += (long long) 512 * _offset; bc_clear_fd(Alg); Error=bc_set_fdkh64(Alg, KeyHandle, fd, Offset, (long long)_offset, 0, (o_ro ? BC_FLAGS_READONLY : 0) | (hs.version == 0 ? 0 : BC_FLAGS_IV_64BIT)); if ( Error!=0 ) { msg(stderr,"bc_set_fd_kh: %s\n",strerror(-Error)); FreeKeyHandle(Alg,KeyHandle); close(Alg.bc_fd); close(fd); return -1; } }//---------------------------------------------------------------------- //---------------------------------------------------------------------- // snprintf(command,sizeof(command),"/sbin/fsck -V -t \"%s\" %s\n",o_fstype,device); command[0]="/sbin/fsck"; command[1]="-V"; command[2]="-t"; command[3]=o_fstype; command[4]=device; command[5]=0; if (-1 == run_process(command)) { msg(stderr,"Can not launch %s\n",command[0]); Error=bc_clear_fd(Alg); FreeKeyHandle(Alg,KeyHandle); return -1; } FreeKeyHandle(Alg,KeyHandle); Error=bc_clear_fd(Alg); if ( Error!=0 ) { print_error(Error); close(fd); close(Alg.bc_fd); return -1; } close(fd); close(Alg.bc_fd); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -