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)  

parse_fstab.c
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2013-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 
23 #include <blkid/blkid.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 
27 static void _add_entry( string_t xt,ssize_t r,char * e )
28 {
29  StringSubChar( xt,r,' ' ) ;
30 
31  if( e != NULL ){
32 
33  StringRemoveLeft( xt,r ) ;
34  StringPrepend( xt,e ) ;
35  StringFree( e ) ;
36  }
37 }
38 
40 {
41  string_t xt = StringGetFromFile( "/etc/fstab" ) ;
42 
44 
46  StringListIterator end ;
47 
48  ssize_t index ;
49 
50  const char * entry ;
51 
52  if( uid ){;}
53 
54  stl = StringListStringSplit( xt,'\n' ) ;
55 
56  StringDelete( &xt ) ;
57 
60 
61  if( StringListSize( stl ) < 1 ){
62  StringListDelete( &stl ) ;
63  return StringListVoid ;
64  }
65 
66  StringListGetIterators( stl,&it,&end ) ;
67 
68  while( it != end ){
69 
70  xt = *it ;
71  it++ ;
72 
73  index = StringIndexOfChar( xt,0,' ' ) ;
74 
75  if( index != -1 ){
76 
77  entry = StringSubChar( xt,index,'\0' ) ;
78 
79  if( StringPrefixEqual( entry,"/dev/" ) ){
80 
81  /*
82  * zuluCryptResolvePath() is defined in resolve_paths.c
83  */
84  _add_entry( xt,index,zuluCryptResolvePath( entry ) ) ;
85 
86  }else if( StringAtLeastOnePrefixMatch( entry,"UUID=","uuid=",NULL ) ){
87 
88  entry = StringRemoveString( xt,"\"" ) ;
89  /*
90  * zuluCryptDeviceFromUUID() is defined in blkid_evaluate_tag.c
91  */
92  _add_entry( xt,index,zuluCryptDeviceFromUUID( entry + 5 ) ) ;
93 
94  }else if( StringAtLeastOnePrefixMatch( entry,"LABEL=","label=",NULL ) ){
95 
96  entry = StringRemoveString( xt,"\"" ) ;
97  /*
98  * zuluCryptDeviceFromLabel() is defined in blkid_evaluate_tag.c
99  */
100  _add_entry( xt,index,zuluCryptDeviceFromLabel( entry + 6 ) ) ;
101 
102  }else if( StringAtLeastOnePrefixMatch( entry,"PARTUUID=","partuuid=",NULL ) ){
103 
104  entry = StringRemoveString( xt,"\"" ) ;
105  /*
106  * zuluCryptDeviceFromPARTUUID() is defined in blkid_evaluate_tag.c
107  */
108  _add_entry( xt,index,zuluCryptDeviceFromPARTUUID( entry + 9 ) ) ;
109 
110  }else if( StringAtLeastOnePrefixMatch( entry,"PARTLABEL=","partlabel=",NULL ) ){
111 
112  entry = StringRemoveString( xt,"\"" ) ;
113  /*
114  * zuluCryptDeviceFromPARTLABEL() is defined in blkid_evaluate_tag.c
115  */
116  _add_entry( xt,index,zuluCryptDeviceFromPARTLABEL( entry + 10 ) ) ;
117 
118  }else{
119  entry = StringSubChar( xt,index,' ' ) ;
120  }
121  }
122  }
123 
124  return stl ;
125 }
126 
127 string_t zuluCryptGetFstabEntry( const char * device,uid_t uid )
128 {
129  string_t st = StringVoid ;
130  string_t xt = String( device ) ;
131  stringList_t stl = zuluCryptGetFstabList( uid ) ;
132  ssize_t index = StringListHasStartSequence( stl,StringAppend( xt," " ) ) ;
133  if( index >= 0 ){
134  st = StringListCopyStringAt( stl,index ) ;
135  }
136  StringDelete( &xt ) ;
137  StringListDelete( &stl ) ;
138  return st ;
139 }
140 
141 string_t zuluCryptGetMountOptionsFromFstab( const char * device,int pos,uid_t uid )
142 {
143  stringList_t stl ;
144  string_t st = zuluCryptGetFstabEntry( device,uid ) ;
145  if( st != StringVoid ){
146  stl = StringListStringSplit( st,' ' ) ;
147  StringDelete( &st ) ;
148  st = StringListCopyStringAt( stl,pos ) ;
149  StringListDelete( &stl ) ;
150  }
151  return st ;
152 }
153 
154 stringList_t zuluCryptGetFstabEntryList( const char * device,uid_t uid )
155 {
157  string_t st = zuluCryptGetFstabEntry( device,uid ) ;
158  if( st != StringVoid ){
159  stl = StringListStringSplit( st,' ' ) ;
160  StringDelete( &st ) ;
161  }
162  return stl ;
163 }
StringRemoveLeft
const char * StringRemoveLeft(string_t st, size_t x)
Definition: String.c:647
StringListVoid
#define StringListVoid
Definition: StringList.h:41
zuluCryptDeviceFromUUID
char * zuluCryptDeviceFromUUID(const char *uuid)
Definition: blkid_evaluate_tag.c:42
StringListRemoveIfStringStartsWith
size_t StringListRemoveIfStringStartsWith(stringList_t stl, const char *str)
Definition: StringList.c:984
StringGetFromFile
string_t StringGetFromFile(const char *path)
Definition: String.c:2006
StringListCopyStringAt
string_t StringListCopyStringAt(stringList_t stl, size_t pos)
Definition: StringList.c:1308
StringSubChar
const char * StringSubChar(string_t st, size_t x, char s)
Definition: String.c:881
zuluCryptGetFstabEntry
string_t zuluCryptGetFstabEntry(const char *device, uid_t uid)
Definition: parse_fstab.c:127
zuluCryptGetMountOptionsFromFstab
string_t zuluCryptGetMountOptionsFromFstab(const char *device, int pos, uid_t uid)
Definition: parse_fstab.c:141
zuluCryptDeviceFromLabel
char * zuluCryptDeviceFromLabel(const char *label)
Definition: blkid_evaluate_tag.c:47
StringListSize
size_t StringListSize(stringList_t stl)
Definition: StringList.c:492
zuluCryptResolvePath
char * zuluCryptResolvePath(const char *path)
Definition: resolve_paths.c:215
StringListGetIterators
void StringListGetIterators(stringList_t stl, StringListIterator *begin, StringListIterator *end)
Definition: StringList.c:210
zuluCryptGetFstabList
stringList_t zuluCryptGetFstabList(uid_t uid)
Definition: parse_fstab.c:39
StringListHasStartSequence
ssize_t StringListHasStartSequence(stringList_t stl, const char *str)
Definition: StringList.c:869
StringPrepend
const char * StringPrepend(string_t st, const char *s)
Definition: String.c:1015
StringListDelete
void StringListDelete(stringList_t *stl)
Definition: StringList.c:1184
StringListStringSplit
stringList_t StringListStringSplit(string_t st, char splitter)
Definition: StringList.c:483
StringRemoveString
const char * StringRemoveString(string_t st, const char *s)
Definition: String.c:1328
_add_entry
static void _add_entry(string_t xt, ssize_t r, char *e)
Definition: parse_fstab.c:27
StringType
Definition: String.c:49
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
StringListType
Definition: StringList.c:33
e
static QString e
Definition: about.cpp:31
StringAtLeastOnePrefixMatch
int StringAtLeastOnePrefixMatch(const char *x,...)
Definition: String.c:1578
includes.h
StringDelete
void StringDelete(string_t *st)
Definition: String.c:162
zuluCryptGetFstabEntryList
stringList_t zuluCryptGetFstabEntryList(const char *device, uid_t uid)
Definition: parse_fstab.c:154
StringAppend
const char * StringAppend(string_t st, const char *s)
Definition: String.c:1052
zuluCryptDeviceFromPARTUUID
char * zuluCryptDeviceFromPARTUUID(const char *PARTUUID)
Definition: blkid_evaluate_tag.c:52
zuluCryptDeviceFromPARTLABEL
char * zuluCryptDeviceFromPARTLABEL(const char *PARTLABEL)
Definition: blkid_evaluate_tag.c:57
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