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)  

create_mapper_name.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 #include <libcryptsetup.h>
22 
23 /*
24  * This function is responsible for creating a mapper name,the mapper name will show up at "/dev/mapper" if the volume
25  * is successfully opened.
26  *
27  * mapping_name is taken from a path to a volume presented by the user and then "zuluCrypt-XXX-YYYY-ZZZZ-AAAA is added to it to give
28  * a mapper name unique to zuluCrypt.
29  *
30  * XXX is the UID of the user that run the program,YYYY tells if the volume uses UUID or not."NAAN" pads the volume length
31  * to make sure the length of "zuluCrypt-XXX-YYYY" is always the same regardless of what the user provided.
32  *
33  * XXX is there for security reason.It makes sure one user can not manage another user's mappers
34  *
35  * ZZZZ is taken from the last component of the device path.
36  *
37  * AAAA is hash of the string to prevent collissions if two different volumes that ends with the same ZZZZ are used.
38  *
39  * A successfully constructed "ZULUCRYPTshortMapperPath mapper path" will look like "zuluCrypt-500-NAAN-mdraid-2355849641"
40  */
41 
42 string_t zuluCryptCreateMapperName( const char * device,const char * mapping_name,uid_t uid,int i )
43 {
44  string_t p ;
45  unsigned long z ;
46  char * e ;
47  /*
48  * ZULUCRYPTshortMapperPath is set in ../constants.h
49  */
50  if( i == ZULUCRYPTshortMapperPath ){
51  p = String( "zuluCrypt-" ) ;
52  }else{
53  /*
54  * zuluCryptMapperPrefix() is defined in include.h
55  */
56  p = String_1( zuluCryptMapperPrefix(),"/zuluCrypt-",NULL ) ;
57  }
58 
59  StringAppendInt( p,uid ) ;
60 
61  if( StringPrefixEqual( mapping_name,"UUID-" ) ){
62 
63  StringMultipleAppend( p,"-",mapping_name,"-",NULL ) ;
64  z = StringJenkinsOneAtATimeHash( mapping_name ) ;
65  }else{
66  StringMultipleAppend( p,"-NAAN-",mapping_name,"-",NULL ) ;
67 
68  if( StringPrefixEqual( device,"/dev/loop" ) ){
69 
70  /*
71  * zuluCryptLoopDeviceAddress_1() is defined in ./create_loop_device.c
72  */
73  e = zuluCryptLoopDeviceAddress_1( device ) ;
74 
75  if( e != NULL ){
77  StringFree( e ) ;
78  }else{
79  z = StringJenkinsOneAtATimeHash( device ) ;
80  }
81  }else{
82  z = StringJenkinsOneAtATimeHash( device ) ;
83  }
84  }
85 
86  StringAppendInt( p,z ) ;
87 
89 
90  return p ;
91 }
92 
93 static const char * _zuluCryptMapperPrefix = NULL ;
94 
95 const char * zuluCryptMapperPrefix( void )
96 {
97  if( _zuluCryptMapperPrefix == NULL ){
98  _zuluCryptMapperPrefix = crypt_get_dir() ;
99  return _zuluCryptMapperPrefix ;
100  }else{
101  return _zuluCryptMapperPrefix ;
102  }
103 }
StringAppendInt
const char * StringAppendInt(string_t st, u_int64_t z)
Definition: String.c:1410
zuluCryptLoopDeviceAddress_1
char * zuluCryptLoopDeviceAddress_1(const char *device)
Definition: create_loop_device.c:140
zuluCryptCreateMapperName
string_t zuluCryptCreateMapperName(const char *device, const char *mapping_name, uid_t uid, int i)
Definition: create_mapper_name.c:42
StringMultipleAppend
const char * StringMultipleAppend(string_t st,...)
Definition: String.c:1123
zuluCryptMapperPrefix
const char * zuluCryptMapperPrefix(void)
Definition: create_mapper_name.c:95
_zuluCryptMapperPrefix
static const char * _zuluCryptMapperPrefix
Definition: create_mapper_name.c:93
StringReplaceCharString
const char * StringReplaceCharString(string_t st, char x, const char *y)
Definition: String.c:931
StringJenkinsOneAtATimeHash
u_int32_t StringJenkinsOneAtATimeHash(const char *key)
Definition: String.c:1816
StringType
Definition: String.c:49
String
string_t String(const char *cstring)
Definition: String.c:318
String_1
string_t String_1(const char *cstring,...)
Definition: String.c:363
e
static QString e
Definition: about.cpp:31
includes.h
BASH_SPECIAL_CHARS
#define BASH_SPECIAL_CHARS
Definition: bash_special_chars.h:26
ZULUCRYPTshortMapperPath
#define ZULUCRYPTshortMapperPath
Definition: constants.h:35
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