📄 bctool.c
字号:
/********************************************************************* Copyright (c) 1994-1999 Jetico, Inc., Finland* All rights reserved.** File: bccreate.c* Revision: $Id: bctool.c,v 1.19 2005/05/14 10:58:51 crypt Rel-1.6-3 $* Created:* Description: implementation of command line interface********************************************************************/#include <stdio.h>#include <unistd.h>#include <string.h>#include <getopt.h>#include <errno.h>#include <stdlib.h>#include <libgen.h>#include <bc_types.h>#include "alg.h"#include "config.h"#include "error.h"#include "version.h"#include "bctool.h"#include "misc.h"char bctool_c[]="$Id: bctool.c,v 1.19 2005/05/14 10:58:51 crypt Rel-1.6-3 $";extern int bccreate(int argc,char **argv);extern int bcumount(int argc,char **argv);extern int bcumount_all(int argc,char **argv);extern int bcmount(int argc,char **argv);extern int bcpasswd(int argc,char **argv);extern int bcpasswd_add(int argc,char **argv);extern int bcpasswd_del(int argc,char **argv);extern int bcinfo(int argc,char **argv);extern int bcformat(int argc,char **argv);extern int bcreencrypt(int argc,char **argv);extern int bcfsck(int argc,char **argv);extern int bclink(int argc,char **argv);extern int bclink_raw(int argc,char **argv);extern int bcunlink(int argc,char **argv);extern int bcunlock(int argc,char **argv);extern int bccreate_hidden(int argc, char ** argv);int main (int argc, char ** argv){ int c; char *progname=NULL; char *commandname; Error=0; o_fstype=NULL; o_alg=NULL; o_options=NULL; o_cont_size=0; o_description=NULL; o_verbose=0; o_ro=0; o_mode=0700; setvbuf(stderr,(char*)NULL,_IONBF,0); setvbuf(stdout,(char*)NULL,_IONBF,0); ruid=getuid(); euid=geteuid(); if (0 != ruid && 0 != euid ) { msg(stderr,"This program must be run as root or have the SUID attribute set\n"); exit(-1); } if ( !modules_loaded() ) { exit(-1); } if ( setreuid(ruid,ruid)!=0 ) { msg(stderr,"setreuid(%d,%d): %s\n",ruid,ruid,strerror(errno)); exit(-1); } o_uid=ruid; o_gid=getgid(); progname = strdup(argv[0]); while ( (c=getopt(argc,argv,"AVvfhprt:a:o:s:d:m:u:g:"))!=-1 ) { switch ( (char)c ) { case 'V': msg(stdout,"BestCrypt version %d.%d\nCopyright Jetico, Inc. See LICENSE for details.\n",VERSION_MAJOR,VERSION_MINOR); exit(-1); case 'v': o_verbose++; break; case 'A': o_umount_all++; break; case 'p': o_random_password=0xff; break; case 'r': o_ro=0xff; break; case 'f': o_force=0xff; break; case 'h': usage(stdout); exit(-1); case 't': o_fstype=optarg; break; case 'a': o_alg=strtolower(optarg); break; case 'o': o_options=optarg; break; case 'd': o_description=optarg; break; case 's': o_cont_size=string_to_long(optarg); if ( o_cont_size==0 ) { msg(stderr,"Invalid container size\n"); exit(-1); } break; case 'm': o_mode=strtol(optarg,NULL,8); o_mode=o_mode & 07777; if (0 == o_mode) { msg(stderr,"Invalid mode. Using 0700\n"); o_mode=0700; } break; case 'u': if (0 != ruid) { msg(stderr,"Only root can specify mountpoint's owner\n"); exit(-1); } o_uid=get_uid_by_name(optarg); if (-1 == o_uid) { msg(stderr,"Invalid username '%s'\n",optarg); exit(-1); } break; case 'g': o_gid=get_gid_by_name(optarg); if (-1 == o_gid) { msg(stderr,"Invalid groupname '%s'\n",optarg); exit(-1); } break; case '?': default: usage(stderr); exit(-1); } /* end of switch */ } /* end of while */ argc -= optind; argv += optind; if ( (Error=read_conf())!=0 ) { print_error(Error); exit(-1); } commandname = basename(progname); if ( 0 != strcmp(commandname,"bctool") ) { if ( 0 == strncmp(commandname,"bc",2)) { commandname +=2; argv--; argc++; }else { msg(stderr,"Unknown command %s\n",commandname); exit(-1); } }else { commandname = argv[0]; } if ( NULL == commandname ) { msg(stderr,"Missed command\n"); usage(stderr); exit(-1); } if (LoadKeygens()) { msg(stderr,"Can not Load Key Generators\n"); exit(-1); } if ( !strcmp(commandname,"info") ) Error = bcinfo(argc,argv); else if ( !strcmp(commandname,"new") ) Error = bccreate(argc,argv); else if ( !strcmp(commandname,"format") ) Error = bcformat(argc,argv); else if ( !strcmp(commandname,"mount") ) Error = bcmount(argc,argv); else if ( !strcmp(commandname,"umount") ) Error = bcumount(argc,argv); else if ( !strcmp(commandname,"umount_all") ) Error = bcumount_all(argc,argv); else if ( !strcmp(commandname,"passwd") ) Error = bcpasswd(argc,argv); else if ( !strcmp(commandname,"reencrypt") ) Error = bcreencrypt(argc,argv); else if ( !strcmp(commandname,"fsck") ) Error = bcfsck(argc,argv); else if ( !strcmp(commandname,"link") ) Error = bclink(argc,argv); else if ( !strcmp(commandname,"unlink") ) Error = bcunlink(argc,argv); else if ( !strcmp(commandname,"unlock") ) Error = bcunlock(argc,argv); else if ( !strcmp(commandname,"add_passwd") ) Error = bcpasswd_add(argc,argv); else if ( !strcmp(commandname,"del_passwd") ) Error = bcpasswd_del(argc,argv); else if ( !strcmp(commandname,"make_hidden") ) Error = bccreate_hidden(argc,argv); else if ( !strcmp(commandname,"raw_link") ) Error = bclink_raw(argc,argv); else { msg(stderr,"Unknown command %s\n",commandname); usage(stderr); Error = -1; } if (progname) { free(progname); } UnLoadKeygens(); if (0 != Error) exit(-1); exit(0);} /* end of main */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -