mirror of
https://git.code.sf.net/p/ntfs-3g/ntfs-3g.git
synced 2024-12-03 23:13:39 +08:00
Improved opening/closing $Secure when un/mounting NTFS volume
Call ntfs_close_secure() earlier, check for error, and other cleanups Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
This commit is contained in:
parent
d4dfa18f7d
commit
32587b485c
@ -256,7 +256,7 @@ int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx,
|
|||||||
le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx,
|
le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx,
|
||||||
ntfs_inode *dir_ni, BOOL fordir);
|
ntfs_inode *dir_ni, BOOL fordir);
|
||||||
int ntfs_open_secure(ntfs_volume *vol);
|
int ntfs_open_secure(ntfs_volume *vol);
|
||||||
void ntfs_close_secure(ntfs_volume *vol);
|
int ntfs_close_secure(ntfs_volume *vol);
|
||||||
|
|
||||||
void ntfs_destroy_security_context(struct SECURITY_CONTEXT *scx);
|
void ntfs_destroy_security_context(struct SECURITY_CONTEXT *scx);
|
||||||
|
|
||||||
|
@ -4468,8 +4468,8 @@ int ntfs_set_ntfs_attrib(ntfs_inode *ni,
|
|||||||
/*
|
/*
|
||||||
* Open the volume's security descriptor index ($Secure)
|
* Open the volume's security descriptor index ($Secure)
|
||||||
*
|
*
|
||||||
* returns zero if it succeeds
|
* returns 0 if it succeeds
|
||||||
* non-zero if it fails and the NTFS version is at least v3.x
|
* -1 with errno set if it fails and the volume is NTFS v3.0+
|
||||||
*/
|
*/
|
||||||
int ntfs_open_secure(ntfs_volume *vol)
|
int ntfs_open_secure(ntfs_volume *vol)
|
||||||
{
|
{
|
||||||
@ -4484,8 +4484,8 @@ int ntfs_open_secure(ntfs_volume *vol)
|
|||||||
if (!ni)
|
if (!ni)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* Verify that $Secure has the expected inode number. */
|
|
||||||
if (ni->mft_no != FILE_Secure) {
|
if (ni->mft_no != FILE_Secure) {
|
||||||
|
ntfs_log_error("$Secure does not have expected inode number!");
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
goto err_close_ni;
|
goto err_close_ni;
|
||||||
}
|
}
|
||||||
@ -4499,9 +4499,9 @@ int ntfs_open_secure(ntfs_volume *vol)
|
|||||||
if (!sdh)
|
if (!sdh)
|
||||||
goto err_close_sii;
|
goto err_close_sii;
|
||||||
|
|
||||||
vol->secure_ni = ni;
|
|
||||||
vol->secure_xsii = sii;
|
|
||||||
vol->secure_xsdh = sdh;
|
vol->secure_xsdh = sdh;
|
||||||
|
vol->secure_xsii = sii;
|
||||||
|
vol->secure_ni = ni;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_close_sii:
|
err_close_sii:
|
||||||
@ -4509,24 +4509,30 @@ err_close_sii:
|
|||||||
err_close_ni:
|
err_close_ni:
|
||||||
ntfs_inode_close(ni);
|
ntfs_inode_close(ni);
|
||||||
err:
|
err:
|
||||||
/* Failing on NTFS versions before 3.x is expected */
|
/* Failing on NTFS pre-v3.0 is expected. */
|
||||||
if (vol->major_ver < 3)
|
if (vol->major_ver < 3)
|
||||||
return 0;
|
return 0;
|
||||||
ntfs_log_perror("error opening $Secure");
|
ntfs_log_perror("Failed to open $Secure");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Close the volume's security descriptor index ($Secure)
|
* Close the volume's security descriptor index ($Secure)
|
||||||
|
*
|
||||||
|
* returns 0 if it succeeds
|
||||||
|
* -1 with errno set if it fails
|
||||||
*/
|
*/
|
||||||
void ntfs_close_secure(ntfs_volume *vol)
|
int ntfs_close_secure(ntfs_volume *vol)
|
||||||
{
|
{
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
if (vol->secure_ni) {
|
if (vol->secure_ni) {
|
||||||
ntfs_index_ctx_put(vol->secure_xsii);
|
|
||||||
ntfs_index_ctx_put(vol->secure_xsdh);
|
ntfs_index_ctx_put(vol->secure_xsdh);
|
||||||
ntfs_inode_close(vol->secure_ni);
|
ntfs_index_ctx_put(vol->secure_xsii);
|
||||||
|
res = ntfs_inode_close(vol->secure_ni);
|
||||||
vol->secure_ni = NULL;
|
vol->secure_ni = NULL;
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -173,6 +173,9 @@ static int __ntfs_volume_release(ntfs_volume *v)
|
|||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
if (ntfs_close_secure(v))
|
||||||
|
ntfs_error_set(&err);
|
||||||
|
|
||||||
if (ntfs_inode_free(&v->vol_ni))
|
if (ntfs_inode_free(&v->vol_ni))
|
||||||
ntfs_error_set(&err);
|
ntfs_error_set(&err);
|
||||||
/*
|
/*
|
||||||
@ -207,7 +210,6 @@ static int __ntfs_volume_release(ntfs_volume *v)
|
|||||||
ntfs_error_set(&err);
|
ntfs_error_set(&err);
|
||||||
}
|
}
|
||||||
|
|
||||||
ntfs_close_secure(v);
|
|
||||||
ntfs_free_lru_caches(v);
|
ntfs_free_lru_caches(v);
|
||||||
free(v->vol_name);
|
free(v->vol_name);
|
||||||
free(v->upcase);
|
free(v->upcase);
|
||||||
|
Loading…
Reference in New Issue
Block a user