@ -27,6 +27,9 @@ import string
from calculate . lib . cl_lang import setLocalTranslate
setLocalTranslate ( ' cl_lib3 ' , sys . modules [ __name__ ] )
class CommonError ( Exception ) :
pass
class _error :
# Здесь ошибки, если они есть
error = [ ]
@ -408,3 +411,63 @@ def getGroups(prefix="/"):
map ( lambda x : x . split ( ' : ' ) [ 0 ] ,
readLinesFile ( path . join ( prefix , ' etc/group ' ) ) ) )
def mountEcryptfs ( userName , userPwd , userDir ) :
"""
Подключить ecryptfs
Args :
userName : логин пользователя
userPwd : пароль пользователя
userDir : домашний каталог пользователя
"""
from calculate . lib . utils . files import ( process , readLinesFile , STDOUT ,
isMount )
if " .Private " in isMount ( userDir ) :
return True
# расшифровать passphrase
ecryptUserName = path . join ( ' /home/.ecryptfs ' , userName )
wrappedPassphraseFile = path . join ( ecryptUserName ,
" .ecryptfs/wrapped-passphrase " )
p = process ( ' /usr/bin/ecryptfs-unwrap-passphrase ' , wrappedPassphraseFile )
p . write ( userPwd )
try :
if p . failed ( ) :
raise Exception
result = p . readlines ( )
if len ( result ) > 1 and " Passphrase: " in result [ 0 ] and result [ 1 ] :
passphrase = result [ 1 ]
else :
raise Exception
except :
raise CommonError ( " Failed to unwrap passphrase " )
# добавить passphrase в ключи ядра
p = process ( ' /usr/bin/ecryptfs-add-passphrase ' , ' --fnek ' , ' - ' , stderr = STDOUT )
p . write ( passphrase )
if not p . success ( ) :
raise CommonError ( p . read ( ) + " Failed to add passphrase " )
# получить сигнатуры шифрования содержимого файлов и имен файлов
try :
ecryptfs_sig , ecryptfs_fnek_sig = \
readLinesFile ( path . join ( ecryptUserName , " .ecryptfs/Private.sig " ) )
except ValueError :
raise CommonError ( " Failed to parse Private.sig " )
# подключить шифрованный раздел
mountProcess = process ( ' /sbin/mount.ecryptfs ' ,
path . join ( ecryptUserName , ' .Private ' ) ,
userDir ,
' -o ' , ' ecryptfs_passthrough=n, '
' ecryptfs_cipher=aes, '
' ecryptfs_key_bytes=16, '
' no_sig_cache, '
' ecryptfs_enable_filename_crypto=y, '
' ecryptfs_sig= {ecryptfs_sig} , '
' ecryptfs_fnek_sig= {ecryptfs_fnek_sig} , '
' passphrase_passwd_fd=0 ' . format (
ecryptfs_sig = ecryptfs_sig ,
ecryptfs_fnek_sig = ecryptfs_fnek_sig ) , stderr = STDOUT )
# отправить пароль через stdin
mountProcess . write ( " passphrase_passwd= " + userPwd )
return mountProcess . success ( )