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)  

umount.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 #include "includes.h"
20 #include <libintl.h>
21 #include <stdio.h>
22 #include <unistd.h>
23 
25 {
26  const char * device = args->device ;
27  uid_t uid = args->uid ;
28  char * loop_device ;
29  char * m_point = NULL ;
30  int status ;
31  string_t st = StringVoid ;
32  const char * dev = NULL ;
33  const char * errorMsg = gettext( "\
34 ERROR: You can not umount volumes out of \"%s\" since you are not root and do not belong to group \"zulumount\"\n" ) ;
35  string_t xt ;
36 
37  if( zuluCryptNoPartitionLoopDevice( device ) ){
38  /*
39  * zuluCryptLoopDeviceAddress() is defined in ../zuluCrypt-cli/lib/create_loop_devices.c
40  */
41  loop_device = zuluCryptLoopDeviceAddress( device ) ;
42 
43  if( loop_device == NULL ){
44  /*
45  * the error msg is a lie,but its harmless since the user will most likely never see it as
46  * this code path will not be passed.
47  */
48  return _zuluExit( 100,StringVoid,m_point,gettext( "ERROR: Device does not appear to be mounted" ) ) ;
49  }else{
50  st = StringInherit( &loop_device ) ;
51  dev = StringContent( st ) ;
52  /*
53  * zuluCryptGetMountPointFromPath() is defined in defined in ../zuluCrypt-cli/lib/process_mountinfo.c
54  */
55  m_point = zuluCryptGetMountPointFromPath( dev ) ;
56 
57  if( m_point == NULL ){
58 
59  return _zuluExit( 100,st,m_point,gettext( "ERROR: Device does not appear to be mounted" ) ) ;
60  }
61  }
62  }else{
63  /*
64  * zuluCryptGetMountPointFromPath() is defined in defined in ../zuluCrypt-cli/lib/process_mountinfo.c
65  */
66  m_point = zuluCryptGetMountPointFromPath( device ) ;
67 
68  if( m_point == NULL ){
69 
70  return _zuluExit( 100,st,m_point,gettext( "ERROR: Device does not appear to be mounted" ) ) ;
71  }
72  }
73 
74  /*
75  * zuluCryptMountPointPrefixMatch() is defined in ../zuluCrypt-cli/bin/create_mount_point.c
76  */
77  if( zuluCryptMountPointPrefixMatch( m_point,uid,&xt ) ){
78 
79  StringDelete( &xt ) ;
80  }else{
81  /*
82  * zuluCryptUserIsAMemberOfAGroup() is defined in ../zuluCrypt-cli/bin/security.c
83  */
84  if( zuluCryptUserIsAMemberOfAGroup( uid,"zulumount" ) ){
85 
86  StringDelete( &xt ) ;
87  }else{
88  printf( errorMsg,StringContent( xt ) ) ;
89  StringDelete( &xt ) ;
90  return _zuluExit( 101,st,m_point,NULL ) ;
91  }
92  }
93 
94  StringFree( m_point ) ;
95  m_point = NULL ;
96 
97  /*
98  * zuluCryptBindUnmountVolume() is defined in ../zuluCrypt-cli/bin/bind.c
99  */
100  switch( zuluCryptBindUnmountVolume( StringListVoid,device,uid ) ){
101 
102  case 3 : return _zuluExit( 107,st,m_point,gettext( "ERROR: Shared mount point appear to be busy" ) ) ;
103  case 4 : return _zuluExit( 108,st,m_point,gettext( "ERROR: Shared mount point appear to belong to a different user" ) ) ;
104  case 5 : return _zuluExit( 109,st,m_point,gettext( "ERROR: Shared mount point appear to be in an ambiguous state,advice to unmount manually" ) ) ;
105  default: ;
106  }
107 
108  /*
109  * zuluCryptSecurityGainElevatedPrivileges() is defined in ../zuluCrypt-cli/bin/security.c
110  */
112  /*
113  * zuluCryptUnmountVolume() is defined in ../zuluCrypt-cli/lib/unmount_volume.c
114  */
115  status = zuluCryptUnmountVolume( device,&m_point ) ;
116  /*
117  * zuluCryptSecurityDropElevatedPrivileges() is defined in ../zuluCrypt-cli/bin/security.c
118  */
120 
121  if( status == 0 ){
122 
123  if( m_point != NULL ){
124 
125  /*
126  * zuluCryptReuseMountPoint() is defined in ../zuluCrypt-cli/bin/create_mount_point.c
127  */
128  if( !zuluCryptReuseMountPoint() ){
129 
131 
132  rmdir( m_point ) ;
133 
135  }
136  }
137 
138  return _zuluExit( 0,st,m_point,gettext( "SUCCESS: umount complete successfully" ) ) ;
139  }else{
140  switch( status ) {
141 
142  case 1 : return _zuluExit( 103,st,m_point,gettext( "ERROR: Device does not exist" ) ) ;
143  case 2 : return _zuluExit( 104,st,m_point,gettext( "ERROR: Failed to unmount,the mount point and/or one or more files are in use" ) ) ;
144  case 4 : return _zuluExit( 105,st,m_point,gettext( "ERROR: Failed to unmount,could not get a lock on /etc/mtab~" ) ) ;
145  case 10: return _zuluExit( 111,st,m_point,gettext( "ERROR: Failed to unmount,multiple mount points for the volume detected" ) ) ; break ;
146 
147  default: return _zuluExit( 106,st,m_point,gettext( "ERROR: Failed to unmount the partition" ) ) ;
148  }
149  }
150 }
StringListVoid
#define StringListVoid
Definition: StringList.h:41
ARGS
Definition: includes.h:27
zuluCryptMountPointPrefixMatch
int zuluCryptMountPointPrefixMatch(const char *m_path, uid_t uid, string_t *m_point)
Definition: create_mount_point.c:390
zuluCryptGetMountPointFromPath
char * zuluCryptGetMountPointFromPath(const char *path)
Definition: mountinfo.c:380
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
args
Definition: open_plain.c:25
StringInherit
string_t StringInherit(char **data)
Definition: String.c:391
StringContent
static const __inline__ char * StringContent(string_t st)
Definition: String.h:1011
StringType
Definition: String.c:49
zuluCryptSecurityDropElevatedPrivileges
int zuluCryptSecurityDropElevatedPrivileges(void)
Definition: security.c:109
siritask::status
status
Definition: siritask.h:114
zuluCryptSecurityGainElevatedPrivileges
int zuluCryptSecurityGainElevatedPrivileges(void)
Definition: security.c:64
zuluCryptBindUnmountVolume
int zuluCryptBindUnmountVolume(stringList_t stx, const char *device, uid_t uid)
Definition: bind.c:200
zuluMountUMount
int zuluMountUMount(ARGS *args)
Definition: umount.c:24
zuluCryptReuseMountPoint
int zuluCryptReuseMountPoint(void)
Definition: create_mount_point.c:58
StringDelete
void StringDelete(string_t *st)
Definition: String.c:162
includes.h
zuluCryptLoopDeviceAddress
char * zuluCryptLoopDeviceAddress(const char *device)
Definition: create_loop_device.c:134
_zuluExit
static int _zuluExit(int r, char *const *options, stringList_t stl)
Definition: create_tcrypt.c:277
zuluCryptUnmountVolume
int zuluCryptUnmountVolume(const char *mapper, char **m_point)
Definition: unmount_volume.c:134
StringFree
static __inline__ void StringFree(const void *str)
Definition: String.h:823
StringVoid
#define StringVoid
Definition: String.h:47