zuluCrypt  5.7.1
About: zuluCrypt is a simple but feature rich solution for hard drives encryption. It can manage PLAIN dm-crypt, LUKS, TrueCrypt and VeraCrypt encrypted volumes.
  Fossies Dox: zuluCrypt-5.7.1.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

remove_key.c
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2011-2015
4  * name : Francis Banyikwa
5  * email: mhogomchungu@gmail.com
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "includes.h"
21 #include <libcryptsetup.h>
22 #include <fcntl.h>
23 #include <unistd.h>
24 
25 typedef struct{
26 
27  const char * key ;
28  size_t key_len ;
29 
30 }arguments ;
31 
32 static int zuluExit( int st,struct crypt_device * cd )
33 {
34  crypt_free( cd ) ;
35  return st ;
36 }
37 
38 static int _remove_key( const char * device,const resolve_path_t * opts )
39 {
40  int slot ;
41 
42  struct crypt_device * cd ;
43 
44  const arguments * args = opts->args ;
45 
46  if( zuluCryptVolumeIsNotLuks( device ) ){
47 
48  return 1 ;
49  }
50  if( crypt_init( &cd,device ) != 0 ){
51 
52  return 3 ;
53  }
54  if( crypt_load( cd,NULL,NULL ) != 0 ){
55 
56  return zuluExit( 3,cd ) ;
57  }
58 
59  slot = crypt_activate_by_passphrase( cd,NULL,CRYPT_ANY_SLOT,args->key,args->key_len,0 ) ;
60 
61  if( slot < 0 ){
62 
63  return zuluExit( 2,cd ) ;
64  }
65  if( crypt_keyslot_destroy( cd,slot ) < 0 ){
66 
67  return zuluExit( 2,cd ) ;
68  }else{
69  return zuluExit( 0,cd ) ;
70  }
71 }
72 
73 int zuluCryptRemoveKey( const char * device ,const char * pass,size_t pass_size )
74 {
75  /*
76  * resolve_path_t is defined in includes.h
77  */
78  resolve_path_t opts ;
79  arguments args ;
80 
81  memset( &opts,'\0',sizeof( opts ) ) ;
82  memset( &args,'\0',sizeof( args ) ) ;
83 
84  args.key = pass ;
85  args.key_len = pass_size ;
86 
87  opts.device = device ;
88  opts.args = &args ;
89  opts.open_mode = O_RDWR ;
90  opts.error_value = 2 ;
91 
92  /*
93  * zuluCryptResolveDevicePath() is defined in resolve_path.c
94  */
95  return zuluCryptResolveDevicePath( _remove_key,&opts ) ;
96 }
zuluCryptResolveDevicePath
int zuluCryptResolveDevicePath(int(*)(const char *, const resolve_path_t *), const resolve_path_t *)
Definition: resolve_paths.c:389
arguments
Definition: add_key.c:25
zuluCryptRemoveKey
int zuluCryptRemoveKey(const char *device, const char *pass, size_t pass_size)
Definition: remove_key.c:73
resolve_path_t::args
const void * args
Definition: includes.h:119
_remove_key
static int _remove_key(const char *device, const resolve_path_t *opts)
Definition: remove_key.c:38
arguments
struct arguments arguments
zuluExit
static int zuluExit(int st, struct crypt_device *cd)
Definition: remove_key.c:32
args
Definition: open_plain.c:25
resolve_path_t::error_value
int error_value
Definition: includes.h:116
zuluCryptVolumeIsNotLuks
int zuluCryptVolumeIsNotLuks(const char *dev)
Definition: is_luks.c:63
resolve_path_t::device
const char * device
Definition: includes.h:115
includes.h
resolve_path_t::open_mode
int open_mode
Definition: includes.h:118
resolve_path_t
Definition: includes.h:114