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)  

close_volume.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 "../lib/includes.h"
22 #include <locale.h>
23 #include <stdio.h>
24 #include <libintl.h>
25 #include <sys/stat.h>
26 #include <unistd.h>
27 
28 static int zuluExit( int st,string_t p )
29 {
30  StringDelete( &p ) ;
31 
32  switch( st ) {
33  case 0 : printf( gettext( "SUCCESS: volume closed successfully \n" ) ) ; break ;
34  case 1 : printf( gettext( "ERROR: Close failed, volume is not open or was opened by a different user\n" ) ) ; break ;
35  case 2 : printf( gettext( "ERROR: Close failed, the mount point and/or one or more files are in use\n" ) ) ; break ;
36  case 3 : printf( gettext( "ERROR: Close failed, volume does not have an entry in /etc/mtab\n" ) ) ; break ;
37  case 4 : printf( gettext( "ERROR: Close failed, could not get a lock on /etc/mtab~\n" ) ) ; break ;
38  case 5 : printf( gettext( "ERROR: Close failed, volume is unmounted but could not close mapper,advice to close it manually\n") ); break ;
39  case 6 : printf( gettext( "ERROR: Close failed, could not resolve full path of device\n") ) ; break ;
40  case 7 : printf( gettext( "ERROR: Close failed, shared mount point appear to be busy\n" ) ) ; break ;
41  case 8 : printf( gettext( "ERROR: Close failed, shared mount point appear to belong to a different user or multiple mount points detected\n" ) ) ; break ;
42  case 9 : printf( gettext( "ERROR: Close failed, shared mount point appear to be in an ambiguous state,advice to unmount manually\n" ) ) ; break ;
43  case 10: printf( gettext( "ERROR: Close failed, multiple mount points for the volume detected\n" ) ) ; break ;
44 
45  default: printf( gettext( "ERROR: Unrecognized error with status number %d encountered\n" ),st );
46  }
47  return st ;
48 }
49 
50 int zuluCryptEXECloseVolume( const char * dev,const char * mapping_name,uid_t uid )
51 {
52  int st ;
53  int i ;
54  string_t p = StringVoid ;
55  char * m_point = NULL ;
56  struct stat xt ;
57  const char * mapper ;
58 
60 
63 
64  p = zuluCryptBitLockerFullMapperPath( uid,dev ) ;
65 
66  mapper = StringContent( p ) ;
67 
68  i = stat( mapper,&xt ) ;
69 
71 
72  if( i != 0 ){
73 
74  return zuluExit( 1,p ) ;
75  }
76  }else{
78 
79  /*
80  * ZULUCRYPTlongMapperPath is set in ../constants.h
81  * zuluCryptCreateMapperName() defined in ../lib/create_mapper_name.c
82  */
83  p = zuluCryptCreateMapperName( dev,mapping_name,uid,ZULUCRYPTlongMapperPath ) ;
84 
85  mapper = StringContent( p ) ;
86 
87  if( stat( mapper,&xt ) != 0 ){
88 
89  return zuluExit( 1,p ) ;
90  }
91  }
92 
93  /*
94  * zuluCryptBindUnmountVolume() is defined in ./bind.c
95  */
96  switch( zuluCryptBindUnmountVolume( StringListVoid,mapper,uid ) ){
97 
98  case 3 : return zuluExit( 7,p ) ;
99  case 4 : return zuluExit( 8,p ) ;
100  case 5 : return zuluExit( 9,p ) ;
101  default: ;
102  }
103 
105 
107 
108  if( zuluCryptReuseMountPoint() ){
109 
110  st = zuluCryptBitLockerlock( p,NULL ) ;
111  }else{
112  st = zuluCryptBitLockerlock( p,&m_point ) ;
113  }
114  }else{
115  if( zuluCryptReuseMountPoint() ){
116 
117  st = zuluCryptCloseVolume( mapper,NULL ) ;
118  }else{
119  st = zuluCryptCloseVolume( mapper,&m_point ) ;
120  }
121  }
122 
123  if( st == 0 && m_point != NULL ){
124 
125  for( i = 0 ; i < 2 ; i++ ){
126 
127  if( rmdir( m_point ) == 0 ){
128 
129  break ;
130  }else{
131  sleep( 1 ) ;
132  }
133  }
134  }
135 
136  StringFree( m_point ) ;
137 
139  return zuluExit( st,p ) ;
140 }
StringListVoid
#define StringListVoid
Definition: StringList.h:41
zuluCryptCreateMapperName
string_t zuluCryptCreateMapperName(const char *device, const char *mapping_name, uid_t uid, int i)
Definition: create_mapper_name.c:42
zuluCryptIsDislockerMapperPath
int zuluCryptIsDislockerMapperPath(const char *e)
Definition: bitlocker.c:69
zuluCryptBitLockerlock
int zuluCryptBitLockerlock(string_t mapperPath, char **mount_point)
Definition: bitlocker.c:226
zuluCryptCloseVolume
int zuluCryptCloseVolume(const char *map, char **mount_point)
Definition: close_volume.c:22
StringContent
static const __inline__ char * StringContent(string_t st)
Definition: String.h:1011
zuluCryptEXECloseVolume
int zuluCryptEXECloseVolume(const char *dev, const char *mapping_name, uid_t uid)
Definition: close_volume.c:50
StringType
Definition: String.c:49
zuluCryptSecurityDropElevatedPrivileges
int zuluCryptSecurityDropElevatedPrivileges(void)
Definition: security.c:109
zuluCryptSecurityGainElevatedPrivileges
int zuluCryptSecurityGainElevatedPrivileges(void)
Definition: security.c:64
zuluCryptBitLockerType
const char * zuluCryptBitLockerType()
Definition: bitlocker.c:36
zuluCryptBindUnmountVolume
int zuluCryptBindUnmountVolume(stringList_t stx, const char *device, uid_t uid)
Definition: bind.c:200
zuluExit
static int zuluExit(int st, string_t p)
Definition: close_volume.c:28
zuluCryptReuseMountPoint
int zuluCryptReuseMountPoint(void)
Definition: create_mount_point.c:58
StringDelete
void StringDelete(string_t *st)
Definition: String.c:162
zuluCryptDeviceHasAgivenFileSystem
int zuluCryptDeviceHasAgivenFileSystem(const char *device, const char *fs)
Definition: blkid_evaluate_tag.c:176
zuluCryptDeviceManagedByDislocker
int zuluCryptDeviceManagedByDislocker(const char *dev, uid_t uid)
Definition: bitlocker.c:141
includes.h
ZULUCRYPTlongMapperPath
#define ZULUCRYPTlongMapperPath
Definition: constants.h:36
zuluCryptBitLockerFullMapperPath
string_t zuluCryptBitLockerFullMapperPath(uid_t uid, const char *e)
Definition: bitlocker.c:127
StringFree
static __inline__ void StringFree(const void *str)
Definition: String.h:823
StringVoid
#define StringVoid
Definition: String.h:47