1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-20 22:50:26 +03:00

smbd: reduce indentation in rmdir_internals()

No change in behaviour. Best viewed with

$ git show -w

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Ralph Boehme 2021-01-22 13:23:00 +01:00 committed by Jeremy Allison
parent 60ddee64f6
commit 065f39a3d0

View File

@ -967,6 +967,11 @@ static NTSTATUS rmdir_internals(TALLOC_CTX *ctx, struct files_struct *fsp)
struct smb_filename *smb_dname = fsp->fsp_name;
const struct loadparm_substitution *lp_sub =
loadparm_s3_global_substitution();
SMB_STRUCT_STAT st;
const char *dname = NULL;
char *talloced = NULL;
long dirpos = 0;
struct smb_Dir *dir_hnd = NULL;
int unlink_flags = 0;
int ret;
@ -1001,151 +1006,147 @@ static NTSTATUS rmdir_internals(TALLOC_CTX *ctx, struct files_struct *fsp)
return NT_STATUS_OK;
}
if (((errno == ENOTEMPTY)||(errno == EEXIST)) &&
*lp_veto_files(talloc_tos(), lp_sub, SNUM(conn)))
if (!((errno == ENOTEMPTY) || (errno == EEXIST)) ||
!*lp_veto_files(talloc_tos(), lp_sub, SNUM(conn)))
{
/*
* Check to see if the only thing in this directory are
* vetoed files/directories. If so then delete them and
* retry. If we fail to delete any of them (and we *don't*
* do a recursive delete) then fail the rmdir.
*/
SMB_STRUCT_STAT st;
const char *dname = NULL;
char *talloced = NULL;
long dirpos = 0;
struct smb_Dir *dir_hnd = NULL;
dir_hnd = OpenDir(talloc_tos(), conn, smb_dname, NULL, 0);
if (dir_hnd == NULL) {
errno = ENOTEMPTY;
goto err;
}
while ((dname = ReadDirName(dir_hnd, &dirpos, &st, &talloced))
!= NULL)
{
if ((strcmp(dname, ".") == 0) ||
(strcmp(dname, "..") == 0))
{
TALLOC_FREE(talloced);
continue;
}
if (!is_visible_file(conn,
dir_hnd,
dname,
&st,
false))
{
TALLOC_FREE(talloced);
continue;
}
if (!IS_VETO_PATH(conn, dname)) {
TALLOC_FREE(dir_hnd);
TALLOC_FREE(talloced);
errno = ENOTEMPTY;
goto err;
}
TALLOC_FREE(talloced);
}
/* We only have veto files/directories.
* Are we allowed to delete them ? */
if (!lp_delete_veto_files(SNUM(conn))) {
TALLOC_FREE(dir_hnd);
errno = ENOTEMPTY;
goto err;
}
/* Do a recursive delete. */
RewindDir(dir_hnd,&dirpos);
while ((dname = ReadDirName(dir_hnd, &dirpos, &st, &talloced))
!= NULL)
{
struct smb_filename *smb_dname_full = NULL;
char *fullname = NULL;
bool do_break = true;
int retval;
if (ISDOT(dname) || ISDOTDOT(dname)) {
TALLOC_FREE(talloced);
continue;
}
if (!is_visible_file(conn,
dir_hnd,
dname,
&st,
false))
{
TALLOC_FREE(talloced);
continue;
}
fullname = talloc_asprintf(ctx,
"%s/%s",
smb_dname->base_name,
dname);
if (fullname == NULL) {
errno = ENOMEM;
goto err_break;
}
smb_dname_full = synthetic_smb_fname(talloc_tos(),
fullname,
NULL,
NULL,
smb_dname->twrp,
smb_dname->flags);
if (smb_dname_full == NULL) {
errno = ENOMEM;
goto err_break;
}
ret = SMB_VFS_LSTAT(conn, smb_dname_full);
if (ret != 0) {
goto err_break;
}
unlink_flags = 0;
if (smb_dname_full->st.st_ex_mode & S_IFDIR) {
if (!recursive_rmdir(ctx, conn,
smb_dname_full))
{
goto err_break;
}
unlink_flags = AT_REMOVEDIR;
}
retval = SMB_VFS_UNLINKAT(conn,
conn->cwd_fsp,
smb_dname_full,
AT_REMOVEDIR);
if (retval != 0) {
goto err_break;
}
/* Successful iteration. */
do_break = false;
err_break:
TALLOC_FREE(fullname);
TALLOC_FREE(smb_dname_full);
TALLOC_FREE(talloced);
if (do_break) {
break;
}
}
TALLOC_FREE(dir_hnd);
/* Retry the rmdir */
ret = SMB_VFS_UNLINKAT(conn,
conn->cwd_fsp,
smb_dname,
AT_REMOVEDIR);
DEBUG(3,("rmdir_internals: couldn't remove directory %s : "
"%s\n", smb_fname_str_dbg(smb_dname),
strerror(errno)));
return map_nt_error_from_unix(errno);
}
/*
* Check to see if the only thing in this directory are
* vetoed files/directories. If so then delete them and
* retry. If we fail to delete any of them (and we *don't*
* do a recursive delete) then fail the rmdir.
*/
dir_hnd = OpenDir(talloc_tos(), conn, smb_dname, NULL, 0);
if (dir_hnd == NULL) {
errno = ENOTEMPTY;
goto err;
}
while ((dname = ReadDirName(dir_hnd, &dirpos, &st, &talloced)) != NULL) {
if ((strcmp(dname, ".") == 0) ||
(strcmp(dname, "..") == 0))
{
TALLOC_FREE(talloced);
continue;
}
if (!is_visible_file(conn,
dir_hnd,
dname,
&st,
false))
{
TALLOC_FREE(talloced);
continue;
}
if (!IS_VETO_PATH(conn, dname)) {
TALLOC_FREE(dir_hnd);
TALLOC_FREE(talloced);
errno = ENOTEMPTY;
goto err;
}
TALLOC_FREE(talloced);
}
/* We only have veto files/directories.
* Are we allowed to delete them ? */
if (!lp_delete_veto_files(SNUM(conn))) {
TALLOC_FREE(dir_hnd);
errno = ENOTEMPTY;
goto err;
}
/* Do a recursive delete. */
RewindDir(dir_hnd,&dirpos);
while ((dname = ReadDirName(dir_hnd, &dirpos, &st, &talloced)) != NULL) {
struct smb_filename *smb_dname_full = NULL;
char *fullname = NULL;
bool do_break = true;
int retval;
if (ISDOT(dname) || ISDOTDOT(dname)) {
TALLOC_FREE(talloced);
continue;
}
if (!is_visible_file(conn,
dir_hnd,
dname,
&st,
false))
{
TALLOC_FREE(talloced);
continue;
}
fullname = talloc_asprintf(ctx,
"%s/%s",
smb_dname->base_name,
dname);
if (fullname == NULL) {
errno = ENOMEM;
goto err_break;
}
smb_dname_full = synthetic_smb_fname(talloc_tos(),
fullname,
NULL,
NULL,
smb_dname->twrp,
smb_dname->flags);
if (smb_dname_full == NULL) {
errno = ENOMEM;
goto err_break;
}
ret = SMB_VFS_LSTAT(conn, smb_dname_full);
if (ret != 0) {
goto err_break;
}
unlink_flags = 0;
if (smb_dname_full->st.st_ex_mode & S_IFDIR) {
if (!recursive_rmdir(ctx, conn,
smb_dname_full))
{
goto err_break;
}
unlink_flags = AT_REMOVEDIR;
}
retval = SMB_VFS_UNLINKAT(conn,
conn->cwd_fsp,
smb_dname_full,
AT_REMOVEDIR);
if (retval != 0) {
goto err_break;
}
/* Successful iteration. */
do_break = false;
err_break:
TALLOC_FREE(fullname);
TALLOC_FREE(smb_dname_full);
TALLOC_FREE(talloced);
if (do_break) {
break;
}
}
TALLOC_FREE(dir_hnd);
/* Retry the rmdir */
ret = SMB_VFS_UNLINKAT(conn,
conn->cwd_fsp,
smb_dname,
AT_REMOVEDIR);
err:
if (ret != 0) {