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)  

mountinfo.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 
22 #include "share_mount_prefix_path.h"
23 
24 typedef struct{
25  const char * device ;
26  const char * mountPoint ;
27  const char * fileSystem ;
28  const char * mountOptions ;
29  const char * rootPath ;
30 }vInfo ;
31 
32 static int _valid_entry( const vInfo * e )
33 {
34  if( StringsAreEqual( e->device,"/dev/fuse" ) ){
35  /*
36  * We dont support these fuse devices.
37  */
38  return 0 ;
39  }
40 
41  if( StringAtLeastOnePrefixMatch( e->mountPoint,"/var/run/media/public",
42  "/var/run/media/private",NULL ) ){
43  /*
44  * some distributions auto generate these extra mount points and we
45  * ignore them as they confuse us.
46  */
47  return 0 ;
48  }
49 
50  if( StringsAreEqual( e->rootPath,"/" ) || StringsAreEqual( e->fileSystem,"btrfs" ) ){
51  /*
52  * we only support bind mount on btrfs.
53  */
54  return 1 ;
55  }
56 
57  return 0 ;
58 }
59 
60 static void _add_entry( string_t ( *function )( const vInfo * ),stringList_t tmp,
61  stringList_t * stx,char * const ** entry,size_t * entry_len )
62 {
63  string_t st ;
64 
65  u_int64_t e ;
66 
67  vInfo volumeInfo ;
68 
69  StringListStringArray_1( entry,entry_len,tmp ) ;
70 
71  volumeInfo.device = *( *entry + *entry_len - 2 ) ;
72  volumeInfo.mountPoint = *( *entry + 4 ) ;
73  volumeInfo.fileSystem = *( *entry + *entry_len - 3 ) ;
74  volumeInfo.mountOptions = *( *entry + 5 ) ;
75  volumeInfo.rootPath = *( *entry + 3 ) ;
76 
77  if( StringAtLeastOneMatch_1( volumeInfo.fileSystem,"fuse.encfs","fuse.cryfs",
78  "fuse.securefs","fuse.gocryptfs",NULL ) ){
79 
80  if( StringAtLeastOnePrefixMatch( volumeInfo.device,"encfs@",
81  "cryfs@","securefs@","gocryptfs@",NULL ) ){
82 
83  volumeInfo.device += StringFirstIndexOfChar_1( volumeInfo.device,'@' ) + 1 ;
84  }else{
85  st = StringListStringAt( tmp,*entry_len - 2 ) ;
86 
87  StringReset( st ) ;
88 
89  e = StringJenkinsOneAtATimeHash( volumeInfo.mountPoint ) ;
90 
91  volumeInfo.device = StringAppendInt( st,e ) ;
92  }
93  }
94 
95  if( _valid_entry( &volumeInfo ) ){
96 
97  st = function( &volumeInfo ) ;
98 
99  StringListAppendString_1( stx,&st ) ;
100  }
101 }
102 
103 static stringList_t _volumeList( string_t ( *function )( const vInfo * ) )
104 {
105  char * const * entry = NULL ;
106 
107  size_t entry_len = 0 ;
108 
109  stringList_t tmp ;
111  stringList_t stl ;
112 
113  StringListIterator it ;
114  StringListIterator end ;
115 
116  string_t st = StringGetFromVirtualFile( "/proc/self/mountinfo" ) ;
117 
118  stl = StringListStringSplit( st,'\n' ) ;
119 
120  StringDelete( &st ) ;
121 
122  StringListGetIterators( stl,&it,&end ) ;
123 
124  while( it != end ){
125 
126  tmp = StringListStringSplit( *it,' ' ) ;
127 
128  it++ ;
129 
130  _add_entry( function,tmp,&stx,&entry,&entry_len ) ;
131 
132  StringListDelete( &tmp ) ;
133  }
134 
135  StringFree( entry ) ;
136 
137  StringListDelete( &stl ) ;
138 
139  return stx ;
140 }
141 
142 static string_t _mount_properties( string_t ( *function )( const char * ),const vInfo * e )
143 {
144  string_t st = function( e->device ) ;
145 
146  StringMultipleAppend( st," ",e->mountPoint," ",e->fileSystem," ",e->mountOptions,NULL ) ;
147 
148  return st ;
149 }
150 
151 static string_t _resolve_path_1( const vInfo * e )
152 {
153  /*
154  * zuluCryptResolvePath_1() is defined in resolve_paths.c
155  */
157 }
158 
160 {
161  return _volumeList( _resolve_path_1 ) ;
162 }
163 
164 static string_t _resolve_path_2( const vInfo * e )
165 {
166  /*
167  * zuluCryptResolvePath_2() is defined in resolve_paths.c
168  */
170 }
171 
173 {
174  return _volumeList( _resolve_path_2 ) ;
175 }
176 
178 {
179  return zuluCryptResolvePath_1( e->device ) ;
180 }
181 
183 {
185 }
186 
187 static int _mounted( ssize_t( *function )( stringList_t,const char * ),string_t st )
188 {
190 
191  ssize_t r = function( stl,StringContent( st ) ) ;
192 
193  StringListDelete( &stl ) ;
194 
195  StringDelete( &st ) ;
196 
197  return r != -1 ;
198 }
199 
200 int zuluCryptMountPointIsActive( const char * m_point )
201 {
202  return _mounted( StringListHasSequence,String_1( " ",m_point," ",NULL ) ) ;
203 }
204 
205 int zuluCryptPartitionIsMounted( const char * path )
206 {
207  return _mounted( StringListHasStartSequence,String_1( path," ",NULL ) ) ;
208 }
209 
211 {
212  const char * e ;
213  const char * c ;
214  const char * d ;
215  const char * t ;
216 
217  char * f ;
218  char * g ;
219 
220  StringListIterator it ;
221  StringListIterator end ;
222 
223  ssize_t k ;
224 
225  string_t q ;
226  string_t z ;
227 
228  string_t j ;
229 
230  stringList_t stx ;
233 
234  if( uid ){;}
235 
236  /*
237  * zuluCryptMapperPrefix() is defined in create_mapper_name.c
238  */
239  j = String_1( zuluCryptMapperPrefix(),"/zuluCrypt-",NULL ) ;
240  /*
241  * t will probably contain "/dev/mapper/zuluCrypt-"
242  */
243  t = StringContent( j ) ;
244 
245  StringListGetIterators( stl,&it,&end ) ;
246 
247  while( it != end ){
248 
249  c = StringContent( *it ) ;
250 
251  it++ ;
252 
253  if( StringPrefixNotEqual( c,t ) && !zuluCryptBitLockerVolume_1( c ) ){
254 
255  /*
256  * we only care about zuluCrypt volumes and these volumes that we care about starts with
257  * "/dev/mapper/zuluCrypt-"
258  *
259  * We also care about dislocker volumes so we let them through. These volumes ends with
260  * "dislocker-file"
261  */
262 
263  continue ;
264  }
265 
266  if( StringHasComponent( c,SHARE_MOUNT_PREFIX "/" ) ){
267 
268  /*
269  * dont show mirror images due to bind mounts
270  */
271 
272  continue ;
273  }
274 
275  stx = StringListSplit( c,' ' ) ;
276 
278 
279  k = StringHasComponent_1( e,"-UUID-" ) ;
280 
281  if( k != -1 ) {
282 
283  q = StringListStringAtFirstPlace( stx ) ;
284  /*
285  * zuluCryptDecodeMountEntry() is defined in mount_volume.c
286  */
288 
289  /*
290  * zuluCryptGetVolumeTypeFromMapperPath() is defined in status.c
291  */
293 
294  e = StringSubChar( q,StringLastIndexOfChar( q,'-' ),'\0' ) + k + 6 ;
295 
296  z = String_1( "UUID=\"",e,"\"\t",d,"\t",f,NULL ) ;
297 
298  StringListAppendString_1( &list,&z ) ;
299 
300  StringFree( f ) ;
301 
302  }else if( zuluCryptIsDislockerMapperPath( e ) ){
303 
305 
307 
308  StringMultipleAppend( q,"\t",d,"\t",zuluCryptBitLockerType(),NULL ) ;
309 
310  StringListAppendString_1( &list,&q ) ;
311  }else{
312  /*
313  * zuluCryptVolumeDeviceName() is defined in status.c
314  */
316 
317  if( g != NULL ){
318 
320 
321  /*
322  * zuluCryptGetVolumeTypeFromMapperPath() is defined in status.c
323  */
324 
326 
327  z = String_1( g,"\t",d,"\t",f,NULL ) ;
328 
329  StringListAppendString_1( &list,&z ) ;
330 
331  StringFree( f ) ;
332 
333  StringFree( g ) ;
334  }
335  }
336 
337  StringListDelete( &stx ) ;
338  }
339 
340  StringListDelete( &stl ) ;
341 
342  StringDelete( &j ) ;
343 
344  return list ;
345 }
346 
347 string_t zuluCryptGetMountEntry( const char * path )
348 {
350 
351  string_t st = zuluCryptGetMountEntry_1( stl,path ) ;
352 
353  StringListDelete( &stl ) ;
354 
355  return st ;
356 }
357 
359 {
360  string_t st ;
361  string_t xt ;
362 
363  if( stl == StringListVoid ){
364 
365  return StringVoid ;
366  }else{
367  /*
368  * zuluCryptResolvePath_1() is defined in resolve_paths.c
369  */
370  st = zuluCryptResolvePath_1( path ) ;
371 
372  xt = StringListHasStartSequence_1( stl,StringAppend( st," " ) ) ;
373 
374  StringDelete( &st ) ;
375 
376  return StringCopy( xt ) ;
377  }
378 }
379 
380 char * zuluCryptGetMountPointFromPath( const char * path )
381 {
382  string_t st = zuluCryptGetMountEntry( path ) ;
383  stringList_t stl ;
384 
385  if( st == StringVoid ){
386 
387  return NULL ;
388  }else{
389  stl = StringListStringSplit( st,' ' ) ;
390 
391  StringDelete( &st ) ;
392 
393  if( stl == StringListVoid ){
394 
395  return NULL ;
396  }else{
398 
399  StringListDelete( &stl ) ;
400 
402 
403  return StringDeleteHandle( &st ) ;
404  }
405  }
406 }
StringListVoid
#define StringListVoid
Definition: StringList.h:41
StringAppendInt
const char * StringAppendInt(string_t st, u_int64_t z)
Definition: String.c:1410
zuluCryptBitLockerResolveMapperPath
string_t zuluCryptBitLockerResolveMapperPath(const char *e, uid_t uid)
Definition: bitlocker.c:203
StringGetFromVirtualFile
string_t StringGetFromVirtualFile(const char *path)
Definition: String.c:2050
StringReset
void StringReset(string_t st)
Definition: String.c:626
StringSubChar
const char * StringSubChar(string_t st, size_t x, char s)
Definition: String.c:881
StringCopy
string_t StringCopy(string_t st)
Definition: String.c:260
StringListContentAtFirstPlace
static const __inline__ char * StringListContentAtFirstPlace(stringList_t stl)
Definition: StringList.h:182
vInfo::mountOptions
const char * mountOptions
Definition: mountinfo.c:28
zuluCryptGetVolumeTypeFromMapperPath
char * zuluCryptGetVolumeTypeFromMapperPath(const char *mapper)
Definition: status.c:449
zuluCryptOpenedVolumesList
stringList_t zuluCryptOpenedVolumesList(uid_t uid)
Definition: mountinfo.c:210
vInfo::device
const char * device
Definition: mountinfo.c:25
zuluCryptGetMoutedList
stringList_t zuluCryptGetMoutedList(void)
Definition: mountinfo.c:159
zuluCryptGetMountEntry_1
string_t zuluCryptGetMountEntry_1(stringList_t stl, const char *path)
Definition: mountinfo.c:358
zuluCryptBitLockerVolume_1
int zuluCryptBitLockerVolume_1(const char *e)
Definition: bitlocker.c:195
StringListHasStartSequence_1
string_t StringListHasStartSequence_1(stringList_t stl, const char *str)
Definition: StringList.c:897
zuluCryptGetAListOfMountedVolumes
stringList_t zuluCryptGetAListOfMountedVolumes(void)
Definition: mountinfo.c:182
_resolve_path_1
static string_t _resolve_path_1(const vInfo *e)
Definition: mountinfo.c:151
StringListAppendString_1
void StringListAppendString_1(stringList_t *stl, string_t *st)
Definition: StringList.c:659
zuluCryptGetMountEntry
string_t zuluCryptGetMountEntry(const char *path)
Definition: mountinfo.c:347
zuluCryptPartitionIsMounted
int zuluCryptPartitionIsMounted(const char *path)
Definition: mountinfo.c:205
zuluCryptResolvePath_2
string_t zuluCryptResolvePath_2(const char *path)
Definition: resolve_paths.c:278
StringListGetIterators
void StringListGetIterators(stringList_t stl, StringListIterator *begin, StringListIterator *end)
Definition: StringList.c:210
vInfo::mountPoint
const char * mountPoint
Definition: mountinfo.c:26
vInfo
Definition: mountinfo.c:24
StringPrefixNotEqual
static __inline__ int StringPrefixNotEqual(const char *x, const char *y)
Definition: String.h:914
StringListHasStartSequence
ssize_t StringListHasStartSequence(stringList_t stl, const char *str)
Definition: StringList.c:869
StringListDelete
void StringListDelete(stringList_t *stl)
Definition: StringList.c:1184
StringMultipleAppend
const char * StringMultipleAppend(string_t st,...)
Definition: String.c:1123
StringListStringSplit
stringList_t StringListStringSplit(string_t st, char splitter)
Definition: StringList.c:483
StringsAreEqual
#define StringsAreEqual(x, y)
Definition: zuluSafe.c:46
StringListStringAtFirstPlace
static __inline__ string_t StringListStringAtFirstPlace(stringList_t stl)
Definition: StringList.h:166
zuluCryptMapperPrefix
const char * zuluCryptMapperPrefix(void)
Definition: create_mapper_name.c:95
StringListStringAt
string_t StringListStringAt(stringList_t stl, size_t index)
Definition: StringList.c:1171
zuluCryptIsDislockerMapperPath
int zuluCryptIsDislockerMapperPath(const char *e)
Definition: bitlocker.c:69
_resolve_path_2
static string_t _resolve_path_2(const vInfo *e)
Definition: mountinfo.c:164
zuluCryptMountPointIsActive
int zuluCryptMountPointIsActive(const char *m_point)
Definition: mountinfo.c:200
StringLastIndexOfChar
ssize_t StringLastIndexOfChar(string_t st, char s)
Definition: String.c:488
StringDeleteHandle
char * StringDeleteHandle(string_t *xt)
Definition: String.c:233
_volumeList
static stringList_t _volumeList(string_t(*function)(const vInfo *))
Definition: mountinfo.c:103
zuluCryptVolumeDeviceName
char * zuluCryptVolumeDeviceName(const char *)
Definition: status.c:895
_valid_entry
static int _valid_entry(const vInfo *e)
Definition: mountinfo.c:32
StringJenkinsOneAtATimeHash
u_int32_t StringJenkinsOneAtATimeHash(const char *key)
Definition: String.c:1816
_add_entry
static void _add_entry(string_t(*function)(const vInfo *), stringList_t tmp, stringList_t *stx, char *const **entry, size_t *entry_len)
Definition: mountinfo.c:60
StringAtLeastOneMatch_1
int StringAtLeastOneMatch_1(const char *x,...)
Definition: String.c:1504
StringContent
static const __inline__ char * StringContent(string_t st)
Definition: String.h:1011
StringHasComponent_1
static __inline__ ssize_t StringHasComponent_1(const char *x, const char *y)
Definition: String.h:923
StringType
Definition: String.c:49
vInfo::fileSystem
const char * fileSystem
Definition: mountinfo.c:27
String_1
string_t String_1(const char *cstring,...)
Definition: String.c:363
StringListHasSequence
ssize_t StringListHasSequence(stringList_t stl, const char *str)
Definition: StringList.c:832
zuluCryptBitLockerType
const char * zuluCryptBitLockerType()
Definition: bitlocker.c:36
StringListStringAtSecondPlace
static __inline__ string_t StringListStringAtSecondPlace(stringList_t stl)
Definition: StringList.h:171
zuluCryptDecodeMountEntry
const char * zuluCryptDecodeMountEntry(string_t)
Definition: mount_volume.c:417
StringFirstIndexOfChar_1
static __inline__ ssize_t StringFirstIndexOfChar_1(const char *str, char s)
Definition: String.h:997
StringListType
Definition: StringList.c:33
zuluCryptResolvePath_1
string_t zuluCryptResolvePath_1(const char *path)
Definition: resolve_paths.c:272
vInfo::rootPath
const char * rootPath
Definition: mountinfo.c:29
StringHasComponent
static __inline__ int StringHasComponent(const char *x, const char *y)
Definition: String.h:964
zuluCryptGetMoutedList_1
stringList_t zuluCryptGetMoutedList_1(void)
Definition: mountinfo.c:172
e
static QString e
Definition: about.cpp:31
StringListSplit
stringList_t StringListSplit(const char *cstring, char splitter)
Definition: StringList.c:428
StringAtLeastOnePrefixMatch
int StringAtLeastOnePrefixMatch(const char *x,...)
Definition: String.c:1578
includes.h
StringDelete
void StringDelete(string_t *st)
Definition: String.c:162
StringListCopyStringAtSecondPlace
static __inline__ string_t StringListCopyStringAtSecondPlace(stringList_t stl)
Definition: StringList.h:475
_mounted
static int _mounted(ssize_t(*function)(stringList_t, const char *), string_t st)
Definition: mountinfo.c:187
StringAppend
const char * StringAppend(string_t st, const char *s)
Definition: String.c:1052
StringListStringArray_1
void StringListStringArray_1(char *const **buffer, size_t *size, stringList_t stl)
Definition: StringList.c:943
_get_mounted_device_list
static string_t _get_mounted_device_list(const vInfo *e)
Definition: mountinfo.c:177
zuluCryptGetMountPointFromPath
char * zuluCryptGetMountPointFromPath(const char *path)
Definition: mountinfo.c:380
_mount_properties
static string_t _mount_properties(string_t(*function)(const char *), const vInfo *e)
Definition: mountinfo.c:142
StringFree
static __inline__ void StringFree(const void *str)
Definition: String.h:823
StringVoid
#define StringVoid
Definition: String.h:47