📄 bcpasswd.c
字号:
/********************************************************************* Copyright (c) 1994-1999 Jetico, Inc., Finland* All rights reserved.** File: bccreate.c* Revision: $Id: bcpasswd.c,v 1.12 2005/05/14 07:58:33 crypt Rel-1.6-3 $* Created:* Description: implementation of change password routine********************************************************************/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <strings.h>#include <string.h>#include <errno.h>#include <bc_types.h>#include <bc_ioctl.h>#include "keygen.h"#include <kg_defs.h>#include "header.h"#include <kblock.h>#include "alg.h"#include "config.h"#include "bctool.h"#include "misc.h"#include "error.h"char bcpasswd_c[]="$Id: bcpasswd.c,v 1.12 2005/05/14 07:58:33 crypt Rel-1.6-3 $";int bcpasswd (int argc, char ** argv){ struct HiddenSector hs; int fd; ALG_SERV Alg; DWORD KeyHandle,DataSize; DATA_BLOCK db, *pdb; alg_info *alg_inf; char device[MAX_DEV_PATH]; 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 ( (Alg.bc_fd = open_bc_dev(device, 0)) < 0 ) { msg(stderr,"%s: %s\n",device,strerror(errno)); 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,"read(\"%s\",&hs, sizeof(hs)): %s\n",argv[1],strerror(errno)); 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,"read(\"%s\",&db, sizeof(db)): %s\n",argv[1],strerror(errno)); 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; } Alg.alg_id=hs.algorithmId; Alg.alg_module =alg_inf->mod_name; pdb = &db; DataSize = sizeof(db); if (KGSHA256_ID == hs.keyGenId) { UseSha256(); } CreateKeyHandle(Alg,alg_inf->key_size,NULL,"Enter password:",CFLAG_CHANGE_PASSWORD,(BYTE **)&pdb,&DataSize,&KeyHandle,&Error); if ( Error!=0 ) { print_error(Error); close(fd); close(Alg.bc_fd); return -1; } if ( lseek(fd,sizeof(hs),SEEK_SET) < 0 ) { msg(stderr,"lseek(%d,%d,SEEK_SET): %s\n", fd, sizeof(hs), strerror(errno)); FreeKeyHandle(Alg,KeyHandle); close(fd); close(Alg.bc_fd); return -1; } if ( write(fd,&db,sizeof(db)) < 0 ) { msg(stderr,"write(%d,&db,%d): %s\n", fd, sizeof(db), strerror(errno)); FreeKeyHandle(Alg,KeyHandle); close(fd); close(Alg.bc_fd); return -1; } FreeKeyHandle(Alg,KeyHandle); close(fd); close(Alg.bc_fd); return 0;}int bcpasswd_add (int argc, char ** argv){ struct HiddenSector hs; int fd; ALG_SERV Alg; DWORD KeyHandle,DataSize; DATA_BLOCK db, *pdb; alg_info *alg_inf; char device[MAX_DEV_PATH]; 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 (!is_valid_container(argv[1])) { msg(stderr,"Invalid container\n"); return -1; } if ( (Alg.bc_fd = open_bc_dev(device, 0)) < 0 ) { msg(stderr,"open(\"%s\",O_RDONLY): %s\n",device, strerror(errno)); 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 ( '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; } Alg.alg_id=hs.algorithmId; Alg.alg_module =alg_inf->mod_name; pdb = &db; DataSize = sizeof(db); if (KGSHA256_ID == hs.keyGenId) { UseSha256(); } CreateKeyHandle(Alg,alg_inf->key_size,NULL,"Enter password:",CFLAG_ADD_NEW_PASSWORD,(BYTE **)&pdb,&DataSize,&KeyHandle,&Error); if ( Error!=0 ) { print_error(Error); close(fd); close(Alg.bc_fd); return -1; } if ( lseek(fd,sizeof(hs),SEEK_SET) < 0 ) { msg(stderr,"lseek(%d,%d,SEEK_SET): %s\n", fd, sizeof(hs), strerror(errno)); FreeKeyHandle(Alg,KeyHandle); close(fd); close(Alg.bc_fd); return -1; } if ( write(fd,&db,sizeof(db)) < 0 ) { msg(stderr,"write(%d,&db,%d): %s\n", fd, sizeof(db), strerror(errno)); FreeKeyHandle(Alg,KeyHandle); close(fd); close(Alg.bc_fd); return -1; } FreeKeyHandle(Alg,KeyHandle); close(fd); close(Alg.bc_fd); return 0;}int bcpasswd_del (int argc, char ** argv){ struct HiddenSector hs; int fd; ALG_SERV Alg; DWORD KeyHandle,DataSize; DATA_BLOCK db, *pdb; alg_info *alg_inf; char device[MAX_DEV_PATH]; 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 (!is_valid_container(argv[1])) { msg(stderr,"Invalid container\n"); return -1; } if ( (Alg.bc_fd = open_bc_dev(device, 0)) < 0 ) { msg(stderr,"open(\"%s\",O_RDONLY): %s\n", device, strerror(errno)); 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 ('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; } Alg.alg_id=hs.algorithmId; Alg.alg_module =alg_inf->mod_name; pdb = &db; DataSize = sizeof(db); if (KGSHA256_ID == hs.keyGenId) { UseSha256(); } CreateKeyHandle(Alg,alg_inf->key_size,NULL,"Enter password:",CFLAG_REMOVE_ADDITIONAL_PASSWORD,(BYTE **)&pdb,&DataSize,&KeyHandle,&Error); if ( Error!=0 ) { print_error(Error); close(fd); close(Alg.bc_fd); return -1; } if ( lseek(fd,sizeof(hs),SEEK_SET) < 0 ) { msg(stderr,"lseek(%d,%d,SEEK_SET): %s\n", fd, sizeof(hs), strerror(errno)); FreeKeyHandle(Alg,KeyHandle); close(fd); close(Alg.bc_fd); return -1; } if ( write(fd,&db,sizeof(db)) < 0 ) { msg(stderr,"write(%d,&db,%d): %s\n", fd, sizeof(db), strerror(errno)); FreeKeyHandle(Alg,KeyHandle); close(fd); close(Alg.bc_fd); return -1; } FreeKeyHandle(Alg,KeyHandle); close(fd); close(Alg.bc_fd); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -