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)  

volumes.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 <dirent.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <sys/stat.h>
29 #include <unistd.h>
30 #include <libintl.h>
31 #include <locale.h>
32 #include <linux/limits.h>
33 
34 #include <blkid/blkid.h>
35 
36 #include "udev_support.h"
37 
38 /*
39  * NOTE: This source file was previously named "partition.c"
40  */
41 
43 {
44  struct dirent * entry ;
45 
46  string_t st ;
47  string_t xt ;
48 
49  DIR * dir = opendir( "/dev/mapper/" ) ;
50 
51  if( dir != NULL ){
52 
53  st = String( "/dev/mapper/" ) ;
54 
55  while( ( entry = readdir( dir ) ) != NULL ){
56 
57  if( !StringAtLeastOneMatch_1( entry->d_name,".","..","control",NULL ) ){
58 
59  /*
60  * zuluCryptConvertIfPathIsLVM() is defined in ../lib/resolve_paths.c
61  */
62 
63  xt = zuluCryptConvertIfPathIsLVM( StringAppendAt( st,12,entry->d_name ) ) ;
64 
65  if( StringStartsWith( xt,"/dev/mapper/" ) ){
66 
67  StringDelete( &xt ) ;
68  }else{
69  StringListAppendString_1( &stl,&xt ) ;
70  }
71  }
72  }
73  StringDelete( &st ) ;
74  closedir( dir ) ;
75  }
76 
77  return stl ;
78 }
79 
81 {
82  DIR * dir = opendir( "/dev/md/" ) ;
83  struct dirent * entry ;
84  char * e ;
85  const char * f ;
86  string_t st ;
87 
88  if( dir != NULL ){
89 
90  while( ( entry = readdir( dir ) ) != NULL ){
91 
92  f = entry->d_name ;
93 
94  if( !StringAtLeastOneMatch_1( f,".","..","md-device-map",NULL ) ){
95 
96  st = String( "/dev/md/" ) ;
97  e = zuluCryptRealPath( StringAppend( st,f ) ) ;
98 
99  if( e != NULL ){
100 
101  StringListRemoveString( stl,e ) ;
102  StringFree( e ) ;
103  }
104 
105  StringListAppendString_1( &stl,&st ) ;
106  }
107  }
108  closedir( dir ) ;
109  }
110 
111  return stl ;
112 }
113 
114 /*
115  * It is possible for a btrfs volume to cover multiple volumes and this routine
116  * keeps only the first one seen and removes the rest.
117  */
119 {
122 
123  StringListIterator it ;
124  StringListIterator end ;
125 
126  string_t st ;
127 
128  const char * e ;
129 
130  blkid_probe blkid ;
131 
132  StringListGetIterators( stl,&it,&end ) ;
133 
135 
136  while( it != end ){
137 
138  st = *it ;
139  it++ ;
140 
141  blkid = blkid_new_probe_from_filename( StringContent( st ) ) ;
142 
143  if( blkid != NULL ){
144 
145  e = NULL ;
146  blkid_do_probe( blkid ) ;
147  blkid_probe_lookup_value( blkid,"TYPE",&e,NULL ) ;
148 
149  if( StringsAreEqual( e,"btrfs" ) ){
150 
151  e = NULL ;
152  blkid_probe_lookup_value( blkid,"UUID",&e,NULL ) ;
153 
154  if( StringListHasNoEntry( stx,e ) ){
155 
156  /*
157  * we got a btrfs volume with UUID we do not know about,
158  * This will be the only device with this btrfs UUID we support and
159  * all device operations must happen through this device and this device only.
160  */
161 
162  stz = StringListAppendString( stz,st ) ;
163  stx = StringListAppend( stx,e ) ;
164  }else{
165  /*
166  * we already know this UUID and this device is not supported.Any operation on this
167  * device should fail.
168  */
169  }
170  }else{
171  /*
172  * not a btrfs volume
173  */
174  stz = StringListAppendString( stz,st ) ;
175  }
176  blkid_free_probe( blkid ) ;
177  }else{
178  stz = StringListAppendString( stz,st ) ;
179  }
180  }
181 
183 
184  StringListMultipleDelete( &stl,&stx,NULL ) ;
185  return stz ;
186 }
187 
189 {
190  string_t st = *it ;
191 
192  StringListIterator e = it + 1 ;
193 
194  if( StringStartsWithAtLeastOne( st,"/dev/sd","/dev/hd","/dev/mmcblk","/dev/nvme",NULL ) ){
195 
196  /*
197  * we have a partition,lets continue
198  */
199 
200  if( e != *end ){
201 
202  /*
203  * we are not at the end of the list,ie,there is atleast one more entry
204  */
205 
206  if( StringStartsWith_1( *e,st ) ){
207 
208  /*
209  * *e will contain something like "/dev/sdc3"
210  * st will contain something like "/dev/sdc"
211  *
212  * This device is partitioned and hence we remove the "/dev/sdc" entry
213  * from the list since we dont care about it.
214  */
215 
216  StringListRemoveAt_1( stl,it,end ) ;
217 
218  return 0 ;
219  }
220  }
221  }
222 
223  return 1 ;
224 }
225 
226 /*
227  * This routine will remove root addresses of a device if the device is found to contain partitions
228  * and will leave the root path if the device is found to not contains partitions.
229  *
230  * Example:
231  * A device with only "/dev/sdc" path will be left alone.
232  * A device with "/dev/sdc" path together with "/dev/sdc1","/dev/sdc2","/dev/sdcN" will cause the
233  * "/dev/sdc" path to be dropped.
234  *
235  * The rationale is that there is nothing useful in the root path if it has partitions beacuse all
236  * useful contents are in partitions.A device with no partitions probably means the useful content is
237  * on the root path
238  */
240 {
241  StringListIterator it ;
242  StringListIterator end ;
243 
244  StringListGetIterators( stl,&it,&end ) ;
245 
246  while( it != end ){
247 
248  if( _not_removed( stl,it,&end ) ){
249 
250  it++ ;
251  }
252  }
253 
254  return stl ;
255 }
256 
257 static int _supported_device( const char * device )
258 {
259  return StringAtLeastOnePrefixMatch( device,
260  "/dev/sd",
261  "/dev/hd",
262  "/dev/loop",
263  "/dev/sr",
264  "/dev/md",
265  "/dev/mmcblk",
266  "/dev/nvme",
267  NULL ) ;
268 }
269 
270 static stringList_t _zuluCryptVolumeList_0( int resolve_loop_devices )
271 {
272  const char * device ;
273 
274  const char * e ;
275 
276  ssize_t index ;
277 
278  StringListIterator it ;
279  StringListIterator end ;
280 
283  stringList_t stl_1 = StringListVoid ;
284 
285  string_t xt ;
286  string_t st = StringGetFromVirtualFile( "/proc/partitions" ) ;
287  string_t st_1 = String( "/dev/" ) ;
288 
289  stl = StringListStringSplit( st,'\n' ) ;
290 
291  StringDelete( &st ) ;
292 
293  if( stl == StringListVoid ){
294 
295  return StringListVoid ;
296  }
297 
298  StringListGetIterators( stl,&it,&end ) ;
299 
300  /*
301  * skip the first entry
302  */
303  it++ ;
304 
306 
307  while( it != end ){
308 
309  st = *it ;
310  it++ ;
311 
312  index = StringLastIndexOfChar( st,' ' ) ;
313 
314  if( index == -1 ){
315 
316  continue ;
317  }
318 
319  e = StringContent( st ) + index + 1 ;
320  device = StringAppendAt( st_1,5,e ) ;
321 
322  if( _supported_device( device ) ){
323 
324  if( StringPrefixEqual( device,"/dev/loop" ) ){
325 
326  if( it != end ){
327 
328  xt = *it ;
329 
330  index = StringLastIndexOfChar( xt,' ' ) ;
331 
332  if( index != -1 ){
333 
334  e = StringContent( xt ) + index + 1 ;
335 
336  if( StringPrefixEqual( e,device + 5 ) ){
337 
338  /*
339  * We will get here if the current entry has something
340  * like "/dev/loop0" and the next entry has something
341  * like "/dev/loop0p1. This means the current loop device
342  * is a root loop path of a partitioned loop device and
343  * we are skipping it because it doesnt have any useful
344  * content. All the useful contents is in the loop partitions.
345  */
346 
347  continue ;
348  }
349  }
350  }else{
351 
352  }
353 
354  /*
355  * zuluCryptLoopDeviceAddress_1() id defined in ../lib/create_loop_device.c
356  */
357 
358  e = zuluCryptLoopDeviceAddress_1( device ) ;
359 
360  if( !zuluCryptBitLockerVolume( e ) ){
361 
362  if( zuluCryptMultiPartitionLoopDevice( device ) ){
363 
364  stl_1 = StringListAppend( stl_1,device ) ;
365  }else{
366  if( StringListHasNoEntry( stz,e ) ){
367 
368  /*
369  * Here we only keep one loop device if the volume file has
370  * more than one loop device
371  */
372 
373  if( resolve_loop_devices ){
374 
375  stl_1 = StringListAppend( stl_1,e ) ;
376  }else{
377  stl_1 = StringListAppend( stl_1,device ) ;
378  }
379  }
380  }
381 
382  stz = StringListAppend( stz,e ) ;
383  }
384 
385  StringFree( e ) ;
386  }else{
387  stl_1 = StringListAppendIfAbsent( stl_1,device ) ;
388  }
389  }
390  }
391 
393 
394  StringListMultipleDelete( &stl,&stz,NULL ) ;
395 
396  StringDelete( &st_1 ) ;
397 
399 }
400 
402 {
403  return _zuluCryptVolumeList_0( 0 ) ;
404 }
405 
407 {
409 }
410 
411 int zuluCryptDeviceIsSupported( const char * device,uid_t uid )
412 {
413  stringList_t stl ;
414  int r ;
415 
416  if( StringPrefixEqual( device,"/dev/loop" ) ){
417 
418  return 1 ;
419  }else{
421 
422  r = StringListHasEntry( stl,device ) ;
423 
424  StringListDelete( &stl ) ;
425 
426  if( r == 1 ){
427 
428  return 1 ;
429  }else{
430  /*
431  * zuluCryptUserIsAMemberOfAGroup() is defined in security.c
432  */
433  return zuluCryptUserIsAMemberOfAGroup( uid,"zulucrypt" ) ;
434  }
435  }
436 }
437 
438 static int _zuluCryptCheckSYSifDeviceIsSystem( const char * device )
439 {
440  /*
441  * UDEV_SUPPORT is set at configure time by "-DUDEVSUPPORT=true" option,the option being absent equals "-DUDEVSUPPORT=false"
442  * To set the option, configure with "-DUDEVSUPPORT=true"
443  */
444 #if UDEV_SUPPORT
445  /*
446  * udev support is enabled
447  */
448  int r ;
449  size_t e ;
450  ssize_t k ;
451  string_t xt ;
452  string_t st ;
453  char dev[ PATH_MAX + 1 ] ;
454 
455  const char * path ;
456 
457  if( StringPrefixNotEqual( device,"/dev/" ) ){
458  /*
459  * udev doesnt work with path to image files so return early
460  */
461  return 0 ;
462  }
463 
464  if( StringPrefixEqual( device,"/dev/loop" ) ){
465  /*
466  * udev thinks all loop devices are system devices and we disagree and hence we return early
467  */
468  return 0 ;
469  }
470 
471  path = realpath( device,dev ) ;
472 
473  if( path != NULL ){
474 
475  st = String( path ) ;
476  }else{
477  st = String( device ) ;
478  }
479 
480  if( StringStartsWithAtLeastOne( st,"/dev/sd","/dev/hd",NULL ) ){
481  /*
482  * this path will convert something like: "/dev/sdc12" to "/dev/sdc"
483  */
484  StringRemoveDigits( st ) ;
485 
486  }else if( StringStartsWithAtLeastOne( st,"/dev/mmc","/dev/nvme",NULL ) ){
487 
488  /*
489  * device path will be something like "/dev/mmcblk0p2" and what we want to do
490  * is cut off the string from p to end iwth "/dev/mmcblk0"
491  */
492 
493  k = StringIndexOfChar( st,0,'p' ) ;
494 
495  if( k != -1 ){
496 
497  e = StringLength( st ) - ( size_t )k ;
498  StringRemoveRight( st,e ) ;
499  }
500  }
501 
502  StringReplaceString( st,"/dev/","/sys/block/" ) ;
503  path = StringAppend( st,"/removable" ) ;
504 
505  /*
506  * path will be something like "/sys/block/sda/removable"
507  */
508  xt = StringGetFromVirtualFile( path ) ;
509 
510  StringDelete( &st ) ;
511 
512  if( xt == StringVoid ){
513 
514  return 0 ;
515  }else{
516  r = StringsAreEqual_2( xt,"0\n" ) ;
517  StringDelete( &xt ) ;
518 
519  return r ;
520  }
521 #else
522  if( device ){;}
523  /*
524  * udev support is disabled
525  */
526  return 0 ;
527 #endif
528 }
529 
530 stringList_t zuluCryptPartitions( int option,uid_t uid )
531 {
532  const char * device ;
533  const char * e ;
534 
535  stringList_t non_system = StringListVoid ;
536  stringList_t system = StringListVoid ;
537 
538  string_t st ;
539 
540  stringList_t p ;
542 
543  StringListIterator it ;
544  StringListIterator end ;
545 
546  if( stl == StringListVoid ){
547 
548  return StringListVoid ;
549  }
550 
551  if( option == ZULUCRYPTallPartitions ){
552 
553  return _remove_btfs_multiple_devices( stl ) ;
554  }
555 
556  non_system = stl ;
557 
559  /*
560  * zuluCryptGetFstabList() is defined in ../lib/parse_fstab.c
561  */
562  stl = zuluCryptGetFstabList( uid ) ;
564 
565  StringListGetIterators( stl,&it,&end ) ;
566  /*
567  * gather an initial list of system and non system partitions by comparing entries in "/etc/fstab" and "/proc/partitions"
568  * fstab entries makes an initial list of system partitions.
569  * the difference btw list in "/proc/partitions" and "/etc/fstab" makes an initial list of non system partitions.
570  */
571  while( it != end ){
572 
573  st = *it ;
574 
575  it++ ;
576 
577  if( StringStartsWith( st,"/" ) ){
578 
579  device = StringReplaceChar_1( st,0,' ','\0' ) ;
580 
581  system = StringListAppend( system,device ) ;
582 
583  StringListRemoveString( non_system,device ) ;
584  }
585  }
586 
587  StringListDelete( &stl ) ;
588 
589  /*
590  * read entried from "crypttab" and then add them to "system" if absent in that
591  * list and remove them from "non system" if present in that list
592  */
594 
595  if( p != StringListVoid ){
596 
597  StringListGetIterators( p,&it,&end ) ;
598 
599  while( it != end ){
600 
601  device = StringContent( *it ) ;
602 
603  it++ ;
604 
605  StringListAppendIfAbsent( system,device ) ;
606 
607  StringListRemoveIfPresent( non_system,device ) ;
608  }
609 
610  StringListDelete( &p ) ;
611  }
612 
613  /*
614  * read entried from "zuluCrypt-system" and then add them to "system" if absent in that list and remove them from "non system" if present
615  * in that list
616  */
617  p = zuluCryptGetPartitionFromConfigFile( "/etc/zuluCrypt-system" ) ;
618 
619  if( p == StringListVoid ){
620 
621  /*
622  * This is the new path since zuluCrypt 4.6.9
623  */
624 
625  p = zuluCryptGetPartitionFromConfigFile( "/etc/zuluCrypt/system_volumes.list" ) ;
626  }
627 
628  if( p != StringListVoid ){
629 
630  StringListGetIterators( p,&it,&end ) ;
631 
632  while( it != end ){
633 
634  device = StringContent( *it ) ;
635 
636  it++ ;
637 
638  StringListAppendIfAbsent( system,device ) ;
639 
640  StringListRemoveIfPresent( non_system,device ) ;
641  }
642 
643  StringListDelete( &p ) ;
644  }
645 
646  /*
647  * At this point:
648  * "system" contains system devices gathered from fstab,zuluCrypt-system and crypttab
649  * "non_system" contains non system devices gathered from /proc/partitions minus system partitions.
650  */
651 
652  StringListGetIterators( non_system,&it,&end ) ;
653 
654  /*
655  * now we consult udev if enabled and we move partition in the "non system" list to "system" list if udev think they are system
656  */
657  while( it != end ){
658 
659  e = StringContent( *it ) ;
660 
662 
663  StringListAppendIfAbsent( system,e ) ;
664 
665  StringListRemoveAt_1( non_system,it,&end ) ;
666  }else{
667  it++ ;
668  }
669  }
670 
671  /*
672  * Now we read from a config file that contains devices that are not to be considered system and remove them from
673  * the system list if present in that list and add them to non system list if absent in that list
674  */
675  p = zuluCryptGetPartitionFromConfigFile( "/etc/zuluCrypt-nonsystem" ) ;
676 
677  if( p == StringListVoid ){
678 
679  /*
680  * This is the new path since zuluCrypt 4.6.9
681  */
682  p = zuluCryptGetPartitionFromConfigFile( "/etc/zuluCrypt/nonsystem_volumes.list" ) ;
683  }
684 
685  if( p != StringListVoid ){
686 
687  StringListGetIterators( p,&it,&end ) ;
688 
689  while( it != end ){
690 
691  device = StringContent( *it ) ;
692 
693  it++ ;
694 
695  StringListRemoveString( system,device ) ;
696 
697  StringListAppendIfAbsent( non_system,device ) ;
698  }
699 
700  StringListDelete( &p ) ;
701  }
702 
703  if( option == ZULUCRYPTsystemPartitions ){
704 
705  StringListDelete( &non_system ) ;
706 
707  return _remove_btfs_multiple_devices( system ) ;
708  }else{
709  StringListDelete( &system ) ;
710 
711  return _remove_btfs_multiple_devices( non_system ) ;
712  }
713 }
714 
715 int zuluCryptVolumeIsInSystemVolumeList( const char * device )
716 {
717  stringList_t p = zuluCryptGetPartitionFromConfigFile( "/etc/zuluCrypt/system_volumes.list" ) ;
718 
719  int r = StringListHasEntry( p,device ) ;
720 
721  StringListDelete( &p ) ;
722 
723  return r ;
724 }
725 
726 u_int64_t zuluCryptGetVolumeSize( const char * device )
727 {
729 
730  StringListIterator it ;
731  StringListIterator end ;
732 
733  string_t xt ;
734 
735  const char * e ;
736 
737  u_int64_t r = 0 ;
738 
739  blkid_probe blkid = blkid_new_probe_from_filename( device ) ;
740 
741  if( blkid == NULL ){
742 
743  return 0 ;
744  }
745 
746  e = NULL ;
747  blkid_do_probe( blkid ) ;
748  blkid_probe_lookup_value( blkid,"TYPE",&e,NULL ) ;
749 
750  if( StringsAreNotEqual( e,"btrfs" ) ){
751 
752  r = (u_int64_t)blkid_probe_get_size( blkid ) ;
753 
754  blkid_free_probe( blkid ) ;
755 
756  return r ;
757  }else{
758  /*
759  * we got a btrfs volume,this device could be one among a bunch of devices that makes the btfs volume.
760  * iterate through all known devices and add their sizes to this device if they are a part of the same
761  * btrfs volume.
762  */
763  e = NULL ;
764 
765  if( blkid_probe_lookup_value( blkid,"UUID",&e,NULL ) == 0 ){
766 
767  xt = String( e ) ;
768  }else{
769  xt = StringVoid ;
770  }
771 
772  blkid_free_probe( blkid ) ;
773 
774  if( xt == StringVoid ){
775 
776  return 0 ;
777  }else{
778  /*
779  * zuluCryptVolumeList() is defined in this source file
780  */
781  stl = zuluCryptVolumeList() ;
782 
784 
785  StringListGetIterators( stl,&it,&end ) ;
786 
787  while( it != end ){
788 
789  blkid = blkid_new_probe_from_filename( StringContent( *it ) ) ;
790 
791  it++ ;
792 
793  if( blkid != NULL ){
794 
795  blkid_do_probe( blkid ) ;
796 
797  e = NULL ;
798 
799  if( blkid_probe_lookup_value( blkid,"UUID",&e,NULL ) == 0 ){
800 
801  if( StringsAreEqual_2( xt,e ) ){
802 
803  r += (u_int64_t)blkid_probe_get_size( blkid ) ;
804  }
805  }
806 
807  blkid_free_probe( blkid ) ;
808  }
809  }
810 
811  StringDelete( &xt ) ;
812  StringListDelete( &stl ) ;
813 
814  return r ;
815  }
816  }
817 }
818 
819 void zuluCryptPrintPartitionProperties( const char * device )
820 {
821  #define SIZE 64
822  char buffer[ SIZE ] ;
823 
824  const char * e ;
825  u_int64_t size ;
826  blkid_probe blkid ;
827 
828  char * m ;
829 
831 
832  if( zuluCryptNoPartitionLoopDevice( device ) ){
833 
834  /*
835  * zuluCryptLoopDeviceAddress_1() is defined in ../lib/create_loop_device.c
836  */
837 
838  e = zuluCryptLoopDeviceAddress_1( device ) ;
839 
840  if( e != NULL ){
841 
842  printf( "%s\t",e ) ;
843 
844  StringFree( e ) ;
845  }else{
846  printf( "%s\t",device ) ;
847  }
848  }else{
849  printf( "%s\t",device ) ;
850  }
851 
852  size = zuluCryptGetVolumeSize( device ) ;
853 
854  blkid = blkid_new_probe_from_filename( device ) ;
855 
856  if( blkid == NULL ){
857 
858  printf( "Nil\tNil\tNil\tNil\n" ) ;
859  }else{
860  /*
861  * zuluCryptFormatSize() is defined in ../lib/status.c
862  */
863  zuluCryptFormatSize( size,buffer,SIZE ) ;
864 
865  printf( "%s\t",buffer ) ;
866 
867  blkid_do_probe( blkid ) ;
868 
869  if( blkid_probe_lookup_value( blkid,"LABEL",&e,NULL ) == 0 ){
870 
871  printf( "%s\t",e ) ;
872  }else{
873  printf( "Nil\t" ) ;
874  }
875 
876  e = zuluCryptVolumeType( blkid,device ) ;
877 
878  if( StringPrefixEqual( e,"crypto_LUKS" ) ){
879 
880  m = zuluCryptGetVolumeType_1( device ) ;
881 
882  if( m ){
883 
884  printf( "%s\t",m ) ;
885 
886  StringFree( m ) ;
887  }else{
888  printf( "%s\t",e ) ;
889  }
890  }else{
891  printf( "%s\t",e ) ;
892  }
893 
894  if( blkid_probe_lookup_value( blkid,"UUID",&e,NULL ) == 0 ){
895 
896  printf( "%s\n",e ) ;
897  }else{
898  printf( "Nil\n" ) ;
899  }
900  blkid_free_probe( blkid ) ;
901  }
902 
904 }
905 
907 {
908  /*
909  * zuluCryptGetMoutedList() is defined in ../lib/process_mountinfo.c
910  */
912 
913  StringListIterator it ;
914  StringListIterator end ;
915 
916  string_t st ;
917 
918  StringListGetIterators( stl,&it,&end ) ;
919 
920  while( it != end ){
921 
922  st = *it ;
923 
924  it++ ;
925 
926  if( StringListHasStartSequence( stx,StringAppend( st," " ) ) == -1 ){
927 
929  }
930  }
931 
932  StringListDelete( &stx ) ;
933 }
934 
935 static void _print_list( stringList_t stl )
936 {
937  const char * e ;
938  char * z ;
939 
940  StringListIterator it ;
941  StringListIterator end ;
942 
943  StringListGetIterators( stl,&it,&end ) ;
944 
945  while( it != end ){
946 
947  e = StringContent( *it ) ;
948 
949  it++ ;
950 
952 
953  /*
954  * zuluCryptLoopDeviceAddress_1() is defined in ../lib/create_loop_device.c
955  */
956 
958 
959  if( z != NULL ){
960 
961  puts( z ) ;
962  StringFree( z ) ;
963  }else{
964  puts( e ) ;
965  }
966  }else{
967  puts( e ) ;
968  }
969  }
970 }
971 
972 int zuluCryptPrintPartitions( int option,int info,uid_t uid )
973 {
975 
976  switch( option ){
977 
978  case 1 : stl = zuluCryptPartitions( ZULUCRYPTallPartitions,uid ) ;break ;
979  case 2 : stl = zuluCryptPartitions( ZULUCRYPTsystemPartitions,uid ) ;break ;
980  case 3 : stl = zuluCryptPartitions( ZULUCRYPTnonSystemPartitions,uid ) ;break ;
981  }
982 
983  if( stl != StringListVoid ){
984 
985  switch( info ){
986 
988  case 2 : _zuluCryptPrintUnMountedPartitionProperties( stl ) ; break ;
989  default: _print_list( stl ) ;
990  }
991  StringListDelete( &stl ) ;
992  }
993 
994  return 0 ;
995 }
996 
998 {
999  string_t st ;
1000  const char * e ;
1001  char * ac ;
1002 
1003  if( StringStartsWith( path,"/" ) ){
1004 
1005  /*
1006  * zuluCryptResolvePath_1() is defined in resolve_paths.c
1007  */
1008 
1009  st = zuluCryptResolvePath_1( StringContent( path ) ) ;
1010 
1011  if( st != StringVoid ){
1012 
1013  StringListAppendString_1( &stl_1,&st ) ;
1014  }
1015 
1016  }else if( StringStartsWith( path,"UUID=" ) ){
1017 
1018  /*
1019  * check above did not find '/' character and we are in this block assuming the line uses UUID
1020  */
1021 
1022  e = StringRemoveString( path,"\"" ) ;
1023 
1024  /*
1025  * zuluCryptEvaluateDeviceTags() is defined in path_access.c
1026  */
1027 
1028  ac = zuluCryptEvaluateDeviceTags( "UUID",e + 5 ) ;
1029 
1030  if( ac != NULL ){
1031 
1032  stl_1 = StringListAppend( stl_1,ac ) ;
1033 
1034  StringFree( ac ) ;
1035  }
1036  }
1037  return stl_1 ;
1038 }
1039 
1040 /*
1041  * this function will parse /etc/crypttab to see if it has any entries to be used as system partition.
1042  *
1043  * sample example of the file content this function was build on.
1044  *
1045 
1046  * secret /dev/sda15 none
1047  * secret_1 UUID=d2d210b8-0b1f-419f-9172-9d509ea9af0c none
1048  *
1049  */
1051 {
1053  stringList_t stl_1 = StringListVoid ;
1054  stringList_t stz ;
1055 
1056  string_t st ;
1057 
1058  StringListIterator it ;
1059  StringListIterator end ;
1060 
1061  st = StringGetFromFile( "/etc/crypttab" ) ;
1062 
1063  stl = StringListStringSplit( st,'\n' ) ;
1064 
1065  StringDelete( &st ) ;
1066 
1067  StringListGetIterators( stl,&it,&end ) ;
1068 
1069  while( it != end ){
1070 
1071  st = *it ;
1072 
1073  it++ ;
1074 
1075  if( !StringStartsWith( st,"#" ) ){
1076 
1077  stz = StringListStringSplit( st,' ' ) ;
1078 
1079  st = StringListStringAtSecondPlace( stz ) ;
1080 
1081  stl_1 = _eval_path( st,stl_1 ) ;
1082 
1083  StringListDelete( &stz ) ;
1084  }
1085  }
1086 
1087  StringListDelete( &stl ) ;
1088 
1089  return stl_1 ;
1090 }
1091 
1093 {
1094  StringListIterator it ;
1095  StringListIterator end ;
1096 
1097  stringList_t stl ;
1098  stringList_t stl_1 = StringListVoid ;
1099 
1100  string_t st = StringVoid ;
1101 
1103 
1104  st = StringGetFromFile( path ) ;
1105 
1107 
1108  stl = StringListStringSplit( st,'\n' ) ;
1109 
1110  StringDelete( &st ) ;
1111 
1112  StringListGetIterators( stl,&it,&end ) ;
1113 
1114  while( it != end ){
1115 
1116  stl_1 = _eval_path( *it,stl_1 ) ;
1117 
1118  it++ ;
1119  }
1120 
1121  StringListDelete( &stl ) ;
1122 
1123  return stl_1 ;
1124 }
1125 
1126 int _zuluCryptPartitionIsSystemPartition( const char * dev,uid_t uid )
1127 {
1128  stringList_t stl ;
1129  int r = 0 ;
1130 
1132 
1133  if( stl != StringListVoid ){
1134 
1135  r = StringListHasEntry( stl,dev ) ;
1136 
1137  StringListDelete( &stl ) ;
1138  }
1139 
1140  return r ;
1141 }
1142 
1143 int zuluCryptPartitionIsSystemPartition( const char * device,uid_t uid )
1144 {
1145  char * dev ;
1146  int r ;
1147 
1148  if( StringPrefixEqual( device,"/dev/loop" ) ){
1149 
1150  /*
1151  * zuluCryptLoopDeviceAddress_1() is defined in ../lib/create_loop_device.c
1152  */
1153 
1154  dev = zuluCryptLoopDeviceAddress_1( device ) ;
1155 
1156  if( dev == NULL ){
1157 
1158  return 0 ;
1159  }else{
1160  r = _zuluCryptPartitionIsSystemPartition( dev,uid ) ;
1161 
1162  StringFree( dev ) ;
1163 
1164  return r ;
1165  }
1166  }else{
1167  return _zuluCryptPartitionIsSystemPartition( device,uid ) ;
1168  }
1169 }
zuluCryptMultiPartitionLoopDevice
int zuluCryptMultiPartitionLoopDevice(const char *e)
Definition: blkid_evaluate_tag.c:171
StringListVoid
#define StringListVoid
Definition: StringList.h:41
zuluCryptDeviceIsSupported
int zuluCryptDeviceIsSupported(const char *device, uid_t uid)
Definition: volumes.c:411
StringListHasEntry
static int StringListHasEntry(stringList_t stl, const char *cstring)
Definition: StringList.h:480
StringGetFromVirtualFile
string_t StringGetFromVirtualFile(const char *path)
Definition: String.c:2050
StringsAreEqual_2
int StringsAreEqual_2(string_t x, const char *y)
Definition: String.c:1469
zuluCryptPrintPartitionProperties
void zuluCryptPrintPartitionProperties(const char *device)
Definition: volumes.c:819
zuluCryptEvaluateDeviceTags
char * zuluCryptEvaluateDeviceTags(const char *tag, const char *path)
Definition: path_access.c:175
StringGetFromFile
string_t StringGetFromFile(const char *path)
Definition: String.c:2006
zuluCryptFormatSize
void zuluCryptFormatSize(u_int64_t number, char *buffer, size_t buffer_size)
Definition: status.c:113
StringLength
size_t StringLength(string_t st)
Definition: String.c:678
StringsAreNotEqual
#define StringsAreNotEqual(x, y)
Definition: zuluSafe.c:47
StringListRemoveString
ssize_t StringListRemoveString(stringList_t stl, const char *cstring)
Definition: StringList.c:1160
StringStartsWith
int StringStartsWith(string_t st, const char *s)
Definition: String.c:821
zuluCryptConvertIfPathIsLVM
string_t zuluCryptConvertIfPathIsLVM(const char *path)
Definition: resolve_paths.c:136
StringReplaceChar_1
const char * StringReplaceChar_1(string_t st, size_t index, char x, char y)
Definition: String.c:1365
StringListAppendString_1
void StringListAppendString_1(stringList_t *stl, string_t *st)
Definition: StringList.c:659
StringListGetIterators
void StringListGetIterators(stringList_t stl, StringListIterator *begin, StringListIterator *end)
Definition: StringList.c:210
ZULUCRYPTnonSystemPartitions
#define ZULUCRYPTnonSystemPartitions
Definition: constants.h:33
ZULUCRYPTsystemPartitions
#define ZULUCRYPTsystemPartitions
Definition: constants.h:32
StringListHasNoEntry
static int StringListHasNoEntry(stringList_t stl, const char *cstring)
Definition: StringList.h:485
zuluCryptLoopDeviceAddress_1
char * zuluCryptLoopDeviceAddress_1(const char *device)
Definition: create_loop_device.c:140
zuluCryptGetFstabList
stringList_t zuluCryptGetFstabList(uid_t)
Definition: parse_fstab.c:39
zuluCryptGetVolumeSize
u_int64_t zuluCryptGetVolumeSize(const char *device)
Definition: volumes.c:726
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
zuluCryptNoPartitionLoopDevice
int zuluCryptNoPartitionLoopDevice(const char *e)
Definition: blkid_evaluate_tag.c:147
zuluCryptUserIsAMemberOfAGroup
int zuluCryptUserIsAMemberOfAGroup(uid_t uid, const char *groupname)
Definition: mount_fs_options.c:172
SIZE
#define SIZE
StringListDelete
void StringListDelete(stringList_t *stl)
Definition: StringList.c:1184
_print_list
static void _print_list(stringList_t stl)
Definition: volumes.c:935
_remove_root_devices
static stringList_t _remove_root_devices(stringList_t stl)
Definition: volumes.c:239
StringListRemoveIfPresent
size_t StringListRemoveIfPresent(stringList_t stl, const char *str)
Definition: StringList.c:1030
StringStartsWith_1
int StringStartsWith_1(string_t st, string_t xt)
Definition: String.c:830
zuluCryptVolumeIsInSystemVolumeList
int zuluCryptVolumeIsInSystemVolumeList(const char *device)
Definition: volumes.c:715
zuluCryptPartitions
stringList_t zuluCryptPartitions(int option, uid_t uid)
Definition: volumes.c:530
StringListStringSplit
stringList_t StringListStringSplit(string_t st, char splitter)
Definition: StringList.c:483
StringsAreEqual
#define StringsAreEqual(x, y)
Definition: zuluSafe.c:46
StringRemoveString
const char * StringRemoveString(string_t st, const char *s)
Definition: String.c:1328
StringListAppendIfAbsent
stringList_t StringListAppendIfAbsent(stringList_t stl, const char *cstring)
Definition: StringList.c:794
zuluCryptPartitionIsSystemPartition
int zuluCryptPartitionIsSystemPartition(const char *device, uid_t uid)
Definition: volumes.c:1143
StringLastIndexOfChar
ssize_t StringLastIndexOfChar(string_t st, char s)
Definition: String.c:488
StringListMultipleDelete
void StringListMultipleDelete(stringList_t *stl,...)
Definition: StringList.c:1249
zuluCryptVolumeType
const char * zuluCryptVolumeType(blkid_probe blkid, const char *device)
Definition: blkid_evaluate_tag.c:210
_zuluCryptAddMDRAIDVolumes
static stringList_t _zuluCryptAddMDRAIDVolumes(stringList_t stl)
Definition: volumes.c:80
zuluCryptGetAListOfAllVolumes
stringList_t zuluCryptGetAListOfAllVolumes(void)
Definition: volumes.c:406
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
StringType
Definition: String.c:49
StringAppendAt
const char * StringAppendAt(string_t st, size_t x, const char *s)
Definition: String.c:960
StringListForEachString
void StringListForEachString(stringList_t stl, void(*fct)(const char *))
Definition: StringList.c:103
zuluCryptSecurityDropElevatedPrivileges
int zuluCryptSecurityDropElevatedPrivileges(void)
Definition: security.c:109
zuluCryptGetMoutedList
stringList_t zuluCryptGetMoutedList(void)
Definition: mountinfo.c:159
_zuluCryptPrintUnMountedPartitionProperties
static void _zuluCryptPrintUnMountedPartitionProperties(stringList_t stl)
Definition: volumes.c:906
zuluCryptGetPartitionFromCrypttab
stringList_t zuluCryptGetPartitionFromCrypttab(void)
Definition: volumes.c:1050
String
string_t String(const char *cstring)
Definition: String.c:318
StringIndexOfChar
ssize_t StringIndexOfChar(string_t st, size_t p, char s)
Definition: String.c:548
StringStartsWithAtLeastOne
int StringStartsWithAtLeastOne(string_t st,...)
Definition: String.c:1076
_zuluCryptVolumeList_0
static stringList_t _zuluCryptVolumeList_0(int resolve_loop_devices)
Definition: volumes.c:270
zuluCryptSecurityGainElevatedPrivileges
int zuluCryptSecurityGainElevatedPrivileges(void)
Definition: security.c:64
StringListStringAtSecondPlace
static __inline__ string_t StringListStringAtSecondPlace(stringList_t stl)
Definition: StringList.h:171
StringReplaceString
const char * StringReplaceString(string_t st, const char *x, const char *s)
Definition: String.c:1318
StringListType
Definition: StringList.c:33
StringListAppendString
stringList_t StringListAppendString(stringList_t stl, string_t st)
Definition: StringList.c:419
zuluCryptResolvePath_1
string_t zuluCryptResolvePath_1(const char *path)
Definition: resolve_paths.c:272
StringListRemoveAt_1
void StringListRemoveAt_1(stringList_t stl, StringListIterator at, StringListIterator *end)
Definition: StringList.c:1129
zuluCryptGetVolumeType_1
char * zuluCryptGetVolumeType_1(const char *m)
Definition: status.c:470
_zuluCryptPartitionIsSystemPartition
int _zuluCryptPartitionIsSystemPartition(const char *dev, uid_t uid)
Definition: volumes.c:1126
e
static QString e
Definition: about.cpp:31
StringAtLeastOnePrefixMatch
int StringAtLeastOnePrefixMatch(const char *x,...)
Definition: String.c:1578
StringDelete
void StringDelete(string_t *st)
Definition: String.c:162
_supported_device
static int _supported_device(const char *device)
Definition: volumes.c:257
StringListAppend
stringList_t StringListAppend(stringList_t stl, const char *cstring)
Definition: StringList.c:763
ZULUCRYPTallPartitions
#define ZULUCRYPTallPartitions
Definition: constants.h:31
_eval_path
static stringList_t _eval_path(string_t path, stringList_t stl_1)
Definition: volumes.c:997
_not_removed
static int _not_removed(stringList_t stl, StringListIterator it, StringListIterator *end)
Definition: volumes.c:188
zuluCryptRealPath
char * zuluCryptRealPath(const char *path)
Definition: real_path.c:28
_zuluCryptCheckSYSifDeviceIsSystem
static int _zuluCryptCheckSYSifDeviceIsSystem(const char *device)
Definition: volumes.c:438
zuluCryptGetPartitionFromConfigFile
stringList_t zuluCryptGetPartitionFromConfigFile(const char *path)
Definition: volumes.c:1092
_zuluCryptAddLVMVolumes
static stringList_t _zuluCryptAddLVMVolumes(stringList_t stl)
Definition: volumes.c:42
StringRemoveRight
const char * StringRemoveRight(string_t st, size_t x)
Definition: String.c:634
StringRemoveDigits
const char * StringRemoveDigits(string_t st)
Definition: String.c:587
StringAppend
const char * StringAppend(string_t st, const char *s)
Definition: String.c:1052
zuluCryptPrintPartitions
int zuluCryptPrintPartitions(int option, int info, uid_t uid)
Definition: volumes.c:972
includes.h
zuluCryptBitLockerVolume
int zuluCryptBitLockerVolume(const char *e)
Definition: bitlocker.c:150
_remove_btfs_multiple_devices
static stringList_t _remove_btfs_multiple_devices(stringList_t stl)
Definition: volumes.c:118
zuluCryptVolumeList
stringList_t zuluCryptVolumeList(void)
Definition: volumes.c:401
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