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)  

blkid_evaluate_tag.c
Go to the documentation of this file.
1 /*
2  *
3  * Copyright ( c ) 2012-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 
22 #include <fcntl.h>
23 #include <unistd.h>
24 
25 static char * _resolve_path( char * path )
26 {
27  char * e ;
28 
29  if( path == NULL ){
30 
31  return NULL ;
32  }else{
33  /*
34  * zuluCryptResolvePath_3() is defined in resolve_path.c
35  */
36  e = zuluCryptResolvePath_3( path ) ;
37  StringFree( path ) ;
38  return e ;
39  }
40 }
41 
42 char * zuluCryptDeviceFromUUID( const char * uuid )
43 {
44  return _resolve_path( blkid_evaluate_tag( "UUID",uuid,NULL) ) ;
45 }
46 
47 char * zuluCryptDeviceFromLabel( const char * label )
48 {
49  return _resolve_path( blkid_evaluate_tag( "LABEL",label,NULL ) ) ;
50 }
51 
52 char * zuluCryptDeviceFromPARTUUID( const char * PARTUUID )
53 {
54  return _resolve_path( blkid_evaluate_tag( "PARTUUID",PARTUUID,NULL ) ) ;
55 }
56 
57 char * zuluCryptDeviceFromPARTLABEL( const char * PARTLABEL )
58 {
59  return _resolve_path( blkid_evaluate_tag( "PARTLABEL",PARTLABEL,NULL ) ) ;
60 }
61 
62 char * zuluCryptUUIDFromPath_1( const char * device )
63 {
64  const char * c = NULL ;
65  char * r = NULL ;
66 
67  blkid_probe blkid = blkid_new_probe_from_filename( device ) ;
68 
69  if( blkid != NULL ){
70 
71  blkid_do_probe( blkid ) ;
72  blkid_probe_lookup_value( blkid,"UUID",&c,NULL ) ;
73  r = StringCopy_2( c ) ;
74  blkid_free_probe( blkid ) ;
75  }
76 
77  return r ;
78 }
79 
80 int zuluCryptFileSystemIsFUSEbased( const char * device )
81 {
82  const char * cf = NULL ;
83 
84  int st ;
85 
86  blkid_probe blkid = blkid_new_probe_from_filename( device ) ;
87 
88  if( blkid != NULL ){
89 
90  blkid_do_probe( blkid ) ;
91  blkid_probe_lookup_value( blkid,"TYPE",&cf,NULL ) ;
92 #if 1
93  st = StringAtLeastOneMatch_1( cf,"ntfs","exfat",NULL ) ;
94 #else
95  st = StringAtLeastOneMatch_1( cf,"ntfs",NULL ) ;
96 #endif
97  blkid_free_probe( blkid ) ;
98  return st ;
99  }else{
100  return 0 ;
101  }
102 }
103 
104 string_t zulucryptGetBlkidFileSystem( const char * device )
105 {
106  string_t st = StringVoid ;
107 
108  blkid_probe blkid = blkid_new_probe_from_filename( device ) ;
109 
110  if( blkid != NULL ){
111 
112  blkid_do_probe( blkid ) ;
113 
114  st = String( zuluCryptVolumeType( blkid,device ) ) ;
115 
116  blkid_free_probe( blkid ) ;
117  }
118 
119  return st ;
120 }
121 
122 static string_t _zulucrypt_getloopfs( const char * device )
123 {
124  string_t st ;
126 
127  if( e ){
129  StringFree( e ) ;
130 
131  return st ;
132  }else{
133  return StringVoid ;
134  }
135 }
136 
138 {
139  if( StringPrefixEqual( device,"/dev/" ) ){
140 
141  return zulucryptGetBlkidFileSystem( device ) ;
142  }else{
143  return _zulucrypt_getloopfs( device ) ;
144  }
145 }
146 
148 {
149  if( StringPrefixEqual( e,"/dev/loop" ) ){
150 
151  if( StringCharCount( e,'p' ) > 1 ){
152 
153  /*
154  * This loop device will be in "/dev/loopXpY" format, it is partitioned.
155  */
156  return 0 ;
157  }else{
158  /*
159  * This loop device will be in "/dev/loopX, it is not partitioned.
160  */
161  return 1 ;
162  }
163  }else{
164  /*
165  * Not a loop device
166  */
167  return 0 ;
168  }
169 }
170 
172 {
173  return StringCharCount( e,'p' ) > 1 ;
174 }
175 
176 int zuluCryptDeviceHasAgivenFileSystem( const char * device,const char * fs )
177 {
179  int r = StringContains( s,fs ) ;
180  StringDelete( &s ) ;
181  return r ;
182 }
183 
184 int zuluCryptDeviceHasEncryptedFileSystem( const char * device )
185 {
187  int r ;
188 
189  if( st == StringVoid ){
190 
191  return 1 ;
192  }else{
193  if( StringsAreEqual_2( st,"Nil" ) ){
194 
195  r = 1 ;
196 
197  }else if( StringStartsWith( st,"crypto_" ) ){
198 
199  r = 1 ;
200  }else{
201  r = 0 ;
202  }
203 
204  StringDelete( &st ) ;
205 
206  return r ;
207  }
208 }
209 
210 const char * zuluCryptVolumeType( blkid_probe blkid,const char * device )
211 {
212  char buffer[ 16 ] ;
213  const char * e ;
214  const char * s ;
215  string_t xt ;
216 
217  int fd ;
218  int r ;
219 
220  if( blkid_probe_lookup_value( blkid,"TYPE",&e,NULL ) == 0 ){
221 
222  xt = String( e ) ;
223 
224  s = StringToLowerCase( xt ) ;
225  r = StringHasComponent( s,"bitlocker" ) ;
226 
227  StringDelete( &xt ) ;
228 
229  if( r ){
230  return zuluCryptBitLockerType() ;
231  }else{
232  return e ;
233  }
234  }else{
235  /*
236  * We are manually checking for signature because blkid has failed us.
237  * Added to support checking for bitlocker signatures since this functionality
238  * in blkid was added in version 2.33(released Nov 6th,2018) and i dont have it yet.
239  */
240 
241  fd = open( device,O_RDONLY ) ;
242 
243  if( fd != -1 ){
244 
245  if( read( fd,buffer,11 ) ){}
246 
247  close( fd ) ;
248 
249  if( StringAtLeastOnePrefixMatch( buffer,
250  "\xeb\x52\x90-FVE-FS-",
251  "\xeb\x58\x90-FVE-FS-",
252  "\xeb\x58\x90MSWIN4.1",NULL ) ){
253 
254  return zuluCryptBitLockerType() ;
255  }
256  }
257 
258  return "Nil" ;
259  }
260 }
zuluCryptMultiPartitionLoopDevice
int zuluCryptMultiPartitionLoopDevice(const char *e)
Definition: blkid_evaluate_tag.c:171
StringsAreEqual_2
int StringsAreEqual_2(string_t x, const char *y)
Definition: String.c:1469
zuluCryptResolvePath_3
char * zuluCryptResolvePath_3(const char *path)
Definition: resolve_paths.c:288
zuluCryptDeviceFromLabel
char * zuluCryptDeviceFromLabel(const char *label)
Definition: blkid_evaluate_tag.c:47
StringStartsWith
int StringStartsWith(string_t st, const char *s)
Definition: String.c:821
_resolve_path
static char * _resolve_path(char *path)
Definition: blkid_evaluate_tag.c:25
StringToLowerCase
const char * StringToLowerCase(string_t st)
Definition: String.c:95
zulucryptGetBlkidFileSystem
string_t zulucryptGetBlkidFileSystem(const char *device)
Definition: blkid_evaluate_tag.c:104
zuluCryptNoPartitionLoopDevice
int zuluCryptNoPartitionLoopDevice(const char *e)
Definition: blkid_evaluate_tag.c:147
zuluCryptGetALoopDeviceAssociatedWithAnImageFile
char * zuluCryptGetALoopDeviceAssociatedWithAnImageFile(const char *path)
Definition: create_loop_device.c:174
zuluCryptDeviceFromUUID
char * zuluCryptDeviceFromUUID(const char *uuid)
Definition: blkid_evaluate_tag.c:42
StringCopy_2
char * StringCopy_2(const char *str)
Definition: String.c:725
zuluCryptUUIDFromPath_1
char * zuluCryptUUIDFromPath_1(const char *device)
Definition: blkid_evaluate_tag.c:62
StringContains
int StringContains(string_t st, const char *str)
Definition: String.c:420
StringAtLeastOneMatch_1
int StringAtLeastOneMatch_1(const char *x,...)
Definition: String.c:1504
StringType
Definition: String.c:49
String
string_t String(const char *cstring)
Definition: String.c:318
zuluCryptFileSystemIsFUSEbased
int zuluCryptFileSystemIsFUSEbased(const char *device)
Definition: blkid_evaluate_tag.c:80
zuluCryptBitLockerType
const char * zuluCryptBitLockerType()
Definition: bitlocker.c:36
StringHasComponent
static __inline__ int StringHasComponent(const char *x, const char *y)
Definition: String.h:964
e
static QString e
Definition: about.cpp:31
StringAtLeastOnePrefixMatch
int StringAtLeastOnePrefixMatch(const char *x,...)
Definition: String.c:1578
_zulucrypt_getloopfs
static string_t _zulucrypt_getloopfs(const char *device)
Definition: blkid_evaluate_tag.c:122
includes.h
zuluCryptGetFileSystemFromDevice
string_t zuluCryptGetFileSystemFromDevice(const char *device)
Definition: blkid_evaluate_tag.c:137
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
StringCharCount
static __inline__ size_t StringCharCount(const char *x, char y)
Definition: String.h:938
zuluCryptDeviceHasEncryptedFileSystem
int zuluCryptDeviceHasEncryptedFileSystem(const char *device)
Definition: blkid_evaluate_tag.c:184
zuluCryptDeviceFromPARTUUID
char * zuluCryptDeviceFromPARTUUID(const char *PARTUUID)
Definition: blkid_evaluate_tag.c:52
zuluCryptDeviceFromPARTLABEL
char * zuluCryptDeviceFromPARTLABEL(const char *PARTLABEL)
Definition: blkid_evaluate_tag.c:57
zuluCryptVolumeType
const char * zuluCryptVolumeType(blkid_probe blkid, const char *device)
Definition: blkid_evaluate_tag.c:210
StringPrefixEqual
static __inline__ int StringPrefixEqual(const char *x, const char *y)
Definition: String.h:905
StringFree
static __inline__ void StringFree(const void *str)
Definition: String.h:823
StringVoid
#define StringVoid
Definition: String.h:47