return;
}
- status = resolve_dfspath(ctx, conn,
- req->flags2 & FLAGS2_DFS_PATHNAMES,
- name,
- &name);
+ DEBUG(3,("reply_checkpath %s mode=%d\n", name, (int)SVAL(req->vwv+0, 0)));
+
+ status = filename_convert(ctx,
+ conn,
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ name,
+ &smb_fname,
+ NULL);
+
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
goto path_err;
}
- DEBUG(3,("reply_checkpath %s mode=%d\n", name, (int)SVAL(req->vwv+0, 0)));
-
- status = unix_convert(ctx, conn, name, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- goto path_err;
- }
-
- status = get_full_smb_filename(ctx, smb_fname, &name);
- if (!NT_STATUS_IS_OK(status)) {
- goto path_err;
- }
-
- status = check_name(conn, name);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(3,("reply_checkpath: check_name of %s failed (%s)\n",name,nt_errstr(status)));
- goto path_err;
- }
-
if (!VALID_STAT(smb_fname->st) &&
- (SMB_VFS_STAT(conn, name, &smb_fname->st) != 0)) {
- DEBUG(3,("reply_checkpath: stat of %s failed (%s)\n",name,strerror(errno)));
+ (SMB_VFS_STAT(conn, smb_fname) != 0)) {
+ DEBUG(3,("reply_checkpath: stat of %s failed (%s)\n",
+ smb_fname_str_dbg(smb_fname), strerror(errno)));
status = map_nt_error_from_unix(errno);
goto path_err;
}
}
reply_outbuf(req, 0, 0);
- out:
- TALLOC_FREE(smb_fname);
- END_PROFILE(SMBcheckpath);
- return;
path_err:
-
- TALLOC_FREE(smb_fname);
-
- END_PROFILE(SMBcheckpath);
-
/* We special case this - as when a Windows machine
is parsing a path is steps through the components
one at a time - if a component fails it expects
*/
reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
ERRDOS, ERRbadpath);
- return;
+ goto out;
}
reply_nterror(req, status);
+
+ out:
+ TALLOC_FREE(smb_fname);
+ END_PROFILE(SMBcheckpath);
+ return;
}
/****************************************************************************
goto out;
}
- status = resolve_dfspath(ctx, conn,
- req->flags2 & FLAGS2_DFS_PATHNAMES,
- fname,
- &fname);
- if (!NT_STATUS_IS_OK(status)) {
- if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
- reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
- ERRSRV, ERRbadpath);
- goto out;
- }
- reply_nterror(req, status);
- goto out;
- }
-
/* dos smetimes asks for a stat of "" - it returns a "hidden directory"
under WfWg - weird! */
if (*fname == '\0') {
size = 0;
mtime = 0;
} else {
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
- status = get_full_smb_filename(ctx, smb_fname, &fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
- status = check_name(conn, fname);
+ status = filename_convert(ctx,
+ conn,
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ fname,
+ &smb_fname,
+ &fname);
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(3,("reply_getatr: check_name of %s failed (%s)\n",fname,nt_errstr(status)));
+ if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+ reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
+ ERRSRV, ERRbadpath);
+ goto out;
+ }
reply_nterror(req, status);
goto out;
}
if (!VALID_STAT(smb_fname->st) &&
- (SMB_VFS_STAT(conn, fname, &smb_fname->st) != 0)) {
- DEBUG(3,("reply_getatr: stat of %s failed (%s)\n",fname,strerror(errno)));
+ (SMB_VFS_STAT(conn, smb_fname) != 0)) {
+ DEBUG(3,("reply_getatr: stat of %s failed (%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
reply_unixerror(req, ERRDOS,ERRbadfile);
goto out;
}
SVAL(req->outbuf, smb_flg2) | FLAGS2_IS_LONG_NAME);
}
- DEBUG(3,("reply_getatr: name=%s mode=%d size=%u\n", fname, mode, (unsigned int)size ) );
+ DEBUG(3,("reply_getatr: name=%s mode=%d size=%u\n",
+ smb_fname_str_dbg(smb_fname), mode, (unsigned int)size));
out:
TALLOC_FREE(smb_fname);
+ TALLOC_FREE(fname);
END_PROFILE(SMBgetatr);
return;
}
goto out;
}
- status = resolve_dfspath(ctx, conn,
+ status = filename_convert(ctx,
+ conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- &fname);
+ &smb_fname,
+ NULL);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
goto out;
}
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
- status = get_full_smb_filename(ctx, smb_fname, &fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
- status = check_name(conn, fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
- if (fname[0] == '.' && fname[1] == '\0') {
+ if (smb_fname->base_name[0] == '.' &&
+ smb_fname->base_name[1] == '\0') {
/*
* Not sure here is the right place to catch this
* condition. Might be moved to somewhere else later -- vl
mtime = srv_make_unix_date3(req->vwv+1);
ft.mtime = convert_time_t_to_timespec(mtime);
- status = smb_set_file_time(conn, NULL, fname,
- &smb_fname->st, &ft, true);
+ status = smb_set_file_time(conn, NULL, smb_fname, &ft, true);
if (!NT_STATUS_IS_OK(status)) {
reply_unixerror(req, ERRDOS, ERRnoaccess);
goto out;
else
mode &= ~aDIR;
- if (file_set_dosmode(conn, fname, mode, &smb_fname->st, NULL,
+ if (file_set_dosmode(conn, smb_fname, mode, NULL,
false) != 0) {
reply_unixerror(req, ERRDOS, ERRnoaccess);
goto out;
reply_outbuf(req, 0, 0);
- DEBUG( 3, ( "setatr name=%s mode=%d\n", fname, mode ) );
+ DEBUG(3, ("setatr name=%s mode=%d\n", smb_fname_str_dbg(smb_fname),
+ mode));
out:
TALLOC_FREE(smb_fname);
END_PROFILE(SMBsetatr);
void reply_search(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ char *path = NULL;
const char *mask = NULL;
char *directory = NULL;
char *fname = NULL;
bool finished = False;
const char *p;
int status_len;
- char *path = NULL;
char status[21];
int dptr_num= -1;
bool check_descend = False;
return;
}
- nt_status = resolve_dfspath_wcard(ctx, conn,
- req->flags2 & FLAGS2_DFS_PATHNAMES,
- path,
- &path,
- &mask_contains_wcard);
- if (!NT_STATUS_IS_OK(nt_status)) {
- if (NT_STATUS_EQUAL(nt_status,NT_STATUS_PATH_NOT_COVERED)) {
- reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
- ERRSRV, ERRbadpath);
- END_PROFILE(SMBsearch);
- return;
- }
- reply_nterror(req, nt_status);
- END_PROFILE(SMBsearch);
- return;
- }
-
p++;
status_len = SVAL(p, 0);
p += 2;
if (status_len == 0) {
struct smb_filename *smb_fname = NULL;
+ nt_status = resolve_dfspath_wcard(ctx, conn,
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ path,
+ &path,
+ &mask_contains_wcard);
+ if (!NT_STATUS_IS_OK(nt_status)) {
+ if (NT_STATUS_EQUAL(nt_status,NT_STATUS_PATH_NOT_COVERED)) {
+ reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
+ ERRSRV, ERRbadpath);
+ END_PROFILE(SMBsearch);
+ return;
+ }
+ reply_nterror(req, nt_status);
+ END_PROFILE(SMBsearch);
+ return;
+ }
+
nt_status = unix_convert(ctx, conn, path, &smb_fname,
UCF_ALLOW_WCARD_LCOMP);
if (!NT_STATUS_IS_OK(nt_status)) {
goto out;
}
- if (!map_open_params_to_ntcreate(
- fname, deny_mode, OPENX_FILE_EXISTS_OPEN, &access_mask,
- &share_mode, &create_disposition, &create_options)) {
- reply_nterror(req, NT_STATUS_DOS(ERRDOS, ERRbadaccess));
- END_PROFILE(SMBopen);
- return;
- }
-
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
+ status = filename_convert(ctx,
+ conn,
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ fname,
+ &smb_fname,
+ &fname);
if (!NT_STATUS_IS_OK(status)) {
+ if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+ reply_botherror(req,
+ NT_STATUS_PATH_NOT_COVERED,
+ ERRSRV, ERRbadpath);
+ goto out;
+ }
reply_nterror(req, status);
goto out;
}
- status = get_full_smb_filename(ctx, smb_fname, &fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
+ if (!map_open_params_to_ntcreate(
+ fname, deny_mode, OPENX_FILE_EXISTS_OPEN, &access_mask,
+ &share_mode, &create_disposition, &create_options)) {
+ reply_nterror(req, NT_STATUS_DOS(ERRDOS, ERRbadaccess));
goto out;
}
conn, /* conn */
req, /* req */
0, /* root_dir_fid */
- fname, /* fname */
- 0, /* create_file_flags */
+ smb_fname, /* fname */
access_mask, /* access_mask */
share_mode, /* share_access */
create_disposition, /* create_disposition*/
NULL, /* sd */
NULL, /* ea_list */
&fsp, /* result */
- &info, /* pinfo */
- &smb_fname->st); /* psbuf */
+ &info); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
if (open_was_deferred(req->mid)) {
goto out;
}
- if (!map_open_params_to_ntcreate(
- fname, deny_mode, smb_ofun, &access_mask,
- &share_mode, &create_disposition, &create_options)) {
- reply_nterror(req, NT_STATUS_DOS(ERRDOS, ERRbadaccess));
- goto out;
- }
-
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
+ status = filename_convert(ctx,
+ conn,
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ fname,
+ &smb_fname,
+ &fname);
if (!NT_STATUS_IS_OK(status)) {
+ if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+ reply_botherror(req,
+ NT_STATUS_PATH_NOT_COVERED,
+ ERRSRV, ERRbadpath);
+ goto out;
+ }
reply_nterror(req, status);
goto out;
}
- status = get_full_smb_filename(ctx, smb_fname, &fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
+ if (!map_open_params_to_ntcreate(
+ fname, deny_mode, smb_ofun, &access_mask,
+ &share_mode, &create_disposition, &create_options)) {
+ reply_nterror(req, NT_STATUS_DOS(ERRDOS, ERRbadaccess));
goto out;
}
conn, /* conn */
req, /* req */
0, /* root_dir_fid */
- fname, /* fname */
- 0, /* create_file_flags */
+ smb_fname, /* fname */
access_mask, /* access_mask */
share_mode, /* share_access */
create_disposition, /* create_disposition*/
NULL, /* sd */
NULL, /* ea_list */
&fsp, /* result */
- &smb_action, /* pinfo */
- &smb_fname->st); /* psbuf */
+ &smb_action); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
if (open_was_deferred(req->mid)) {
goto out;
}
+ status = filename_convert(ctx,
+ conn,
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ fname,
+ &smb_fname,
+ NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+ reply_botherror(req,
+ NT_STATUS_PATH_NOT_COVERED,
+ ERRSRV, ERRbadpath);
+ goto out;
+ }
+ reply_nterror(req, status);
+ goto out;
+ }
+
if (fattr & aVOLID) {
DEBUG(0,("Attempt to create file (%s) with volid set - "
- "please report this\n", fname));
+ "please report this\n",
+ smb_fname_str_dbg(smb_fname)));
}
if(req->cmd == SMBmknew) {
create_disposition = FILE_OVERWRITE_IF;
}
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
- status = get_full_smb_filename(ctx, smb_fname, &fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
req, /* req */
0, /* root_dir_fid */
- fname, /* fname */
- 0, /* create_file_flags */
+ smb_fname, /* fname */
access_mask, /* access_mask */
share_mode, /* share_access */
create_disposition, /* create_disposition*/
NULL, /* sd */
NULL, /* ea_list */
&fsp, /* result */
- NULL, /* pinfo */
- &smb_fname->st); /* psbuf */
+ NULL); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
if (open_was_deferred(req->mid)) {
}
ft.atime = smb_fname->st.st_ex_atime; /* atime. */
- status = smb_set_file_time(conn, fsp, fsp->fsp_name, &smb_fname->st,
- &ft, true);
+ status = smb_set_file_time(conn, fsp, smb_fname, &ft, true);
if (!NT_STATUS_IS_OK(status)) {
END_PROFILE(SMBcreate);
goto out;
CVAL(req->outbuf,smb_flg)|CORE_OPLOCK_GRANTED);
}
- DEBUG( 2, ( "reply_mknew: file %s\n", fsp->fsp_name ) );
- DEBUG( 3, ( "reply_mknew %s fd=%d dmode=0x%x\n",
- fsp->fsp_name, fsp->fh->fd, (unsigned int)fattr ) );
+ DEBUG(2, ("reply_mknew: file %s\n", smb_fname_str_dbg(smb_fname)));
+ DEBUG(3, ("reply_mknew %s fd=%d dmode=0x%x\n",
+ smb_fname_str_dbg(smb_fname), fsp->fh->fd,
+ (unsigned int)fattr));
out:
TALLOC_FREE(smb_fname);
goto out;
}
- status = resolve_dfspath(ctx, conn,
+ status = filename_convert(ctx, conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- &fname);
+ &smb_fname,
+ NULL);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
goto out;
}
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
- status = get_full_smb_filename(ctx, smb_fname, &fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
- status = check_name(conn, fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
- tmpfd = mkstemp(fname);
+ tmpfd = mkstemp(smb_fname->base_name);
if (tmpfd == -1) {
reply_unixerror(req, ERRDOS, ERRnoaccess);
goto out;
}
- SET_STAT_INVALID(smb_fname->st);
- SMB_VFS_STAT(conn, fname, &smb_fname->st);
+ SMB_VFS_STAT(conn, smb_fname);
/* We should fail if file does not exist. */
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
req, /* req */
0, /* root_dir_fid */
- fname, /* fname */
- 0, /* create_file_flags */
+ smb_fname, /* fname */
FILE_GENERIC_READ | FILE_GENERIC_WRITE, /* access_mask */
FILE_SHARE_READ | FILE_SHARE_WRITE, /* share_access */
FILE_OPEN, /* create_disposition*/
NULL, /* sd */
NULL, /* ea_list */
&fsp, /* result */
- NULL, /* pinfo */
- &smb_fname->st); /* psbuf */
+ NULL); /* pinfo */
/* close fd from mkstemp() */
close(tmpfd);
return NT_STATUS_MEDIA_WRITE_PROTECTED;
}
+ if (SMB_VFS_LSTAT(conn, smb_fname) != 0) {
+ return map_nt_error_from_unix(errno);
+ }
+
status = get_full_smb_filename(smb_fname, smb_fname, &fname);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
-
- if (SMB_VFS_LSTAT(conn, fname, &smb_fname->st) != 0) {
- return map_nt_error_from_unix(errno);
- }
-
fattr = dos_mode(conn, fname, &smb_fname->st);
+ TALLOC_FREE(fname);
if (dirtype & FILE_ATTRIBUTE_NORMAL) {
dirtype = aDIR|aARCH|aRONLY;
(conn, /* conn */
req, /* req */
0, /* root_dir_fid */
- fname, /* fname */
- 0, /* create_file_flags */
+ smb_fname, /* fname */
DELETE_ACCESS, /* access_mask */
FILE_SHARE_NONE, /* share_access */
FILE_OPEN, /* create_disposition*/
NULL, /* sd */
NULL, /* ea_list */
&fsp, /* result */
- NULL, /* pinfo */
- &smb_fname->st); /* psbuf */
+ NULL); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10, ("SMB_VFS_CREATEFILE failed: %s\n",
goto out;
}
- status = resolve_dfspath(ctx, conn,
+ status = filename_convert(ctx, conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
directory,
- &directory);
+ &smb_dname,
+ NULL);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
goto out;
}
- status = unix_convert(ctx, conn, directory, &smb_dname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
- status = check_name(conn, smb_dname->base_name);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
status = create_directory(conn, req, smb_dname);
DEBUG(5, ("create_directory returned %s\n", nt_errstr(status)));
static bool recursive_rmdir(TALLOC_CTX *ctx,
connection_struct *conn,
- char *directory)
+ struct smb_filename *smb_dname)
{
const char *dname = NULL;
bool ret = True;
long offset = 0;
SMB_STRUCT_STAT st;
- struct smb_Dir *dir_hnd = OpenDir(talloc_tos(), conn, directory,
- NULL, 0);
+ struct smb_Dir *dir_hnd;
+
+ SMB_ASSERT(!is_ntfs_stream_smb_fname(smb_dname));
+ dir_hnd = OpenDir(talloc_tos(), conn, smb_dname->base_name, NULL, 0);
if(dir_hnd == NULL)
return False;
while((dname = ReadDirName(dir_hnd, &offset, &st))) {
+ struct smb_filename *smb_dname_full = NULL;
char *fullname = NULL;
+ bool do_break = true;
+ NTSTATUS status;
if (ISDOT(dname) || ISDOTDOT(dname)) {
continue;
}
- if (!is_visible_file(conn, directory, dname, &st, False)) {
+ if (!is_visible_file(conn, smb_dname->base_name, dname, &st,
+ false)) {
continue;
}
/* Construct the full name. */
fullname = talloc_asprintf(ctx,
"%s/%s",
- directory,
+ smb_dname->base_name,
dname);
if (!fullname) {
errno = ENOMEM;
- ret = False;
- break;
+ goto err_break;
}
- if(SMB_VFS_LSTAT(conn,fullname, &st) != 0) {
- ret = False;
- break;
+ status = create_synthetic_smb_fname(talloc_tos(), fullname,
+ NULL, NULL,
+ &smb_dname_full);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto err_break;
}
- if(st.st_ex_mode & S_IFDIR) {
- if(!recursive_rmdir(ctx, conn, fullname)) {
- ret = False;
- break;
+ if(SMB_VFS_LSTAT(conn, smb_dname_full) != 0) {
+ goto err_break;
+ }
+
+ if(smb_dname_full->st.st_ex_mode & S_IFDIR) {
+ if(!recursive_rmdir(ctx, conn, smb_dname_full)) {
+ goto err_break;
}
- if(SMB_VFS_RMDIR(conn,fullname) != 0) {
- ret = False;
- break;
+ if(SMB_VFS_RMDIR(conn,
+ smb_dname_full->base_name) != 0) {
+ goto err_break;
}
- } else if(SMB_VFS_UNLINK(conn,fullname) != 0) {
- ret = False;
- break;
+ } else if(SMB_VFS_UNLINK(conn, smb_dname_full) != 0) {
+ goto err_break;
}
+
+ /* Successful iteration. */
+ do_break = false;
+
+ err_break:
+ TALLOC_FREE(smb_dname_full);
TALLOC_FREE(fullname);
+ if (do_break) {
+ ret = false;
+ break;
+ }
}
TALLOC_FREE(dir_hnd);
return ret;
****************************************************************************/
NTSTATUS rmdir_internals(TALLOC_CTX *ctx,
- connection_struct *conn,
- const char *directory)
+ connection_struct *conn,
+ struct smb_filename *smb_dname)
{
int ret;
SMB_STRUCT_STAT st;
+ SMB_ASSERT(!is_ntfs_stream_smb_fname(smb_dname));
+
/* Might be a symlink. */
- if(SMB_VFS_LSTAT(conn, directory, &st) != 0) {
+ if(SMB_VFS_LSTAT(conn, smb_dname) != 0) {
return map_nt_error_from_unix(errno);
}
- if (S_ISLNK(st.st_ex_mode)) {
+ if (S_ISLNK(smb_dname->st.st_ex_mode)) {
/* Is what it points to a directory ? */
- if(SMB_VFS_STAT(conn, directory, &st) != 0) {
+ if(SMB_VFS_STAT(conn, smb_dname) != 0) {
return map_nt_error_from_unix(errno);
}
- if (!(S_ISDIR(st.st_ex_mode))) {
+ if (!(S_ISDIR(smb_dname->st.st_ex_mode))) {
return NT_STATUS_NOT_A_DIRECTORY;
}
- ret = SMB_VFS_UNLINK(conn,directory);
+ ret = SMB_VFS_UNLINK(conn, smb_dname);
} else {
- ret = SMB_VFS_RMDIR(conn,directory);
+ ret = SMB_VFS_RMDIR(conn, smb_dname->base_name);
}
if (ret == 0) {
notify_fname(conn, NOTIFY_ACTION_REMOVED,
FILE_NOTIFY_CHANGE_DIR_NAME,
- directory);
+ smb_dname->base_name);
return NT_STATUS_OK;
}
const char *dname;
long dirpos = 0;
struct smb_Dir *dir_hnd = OpenDir(talloc_tos(), conn,
- directory, NULL, 0);
+ smb_dname->base_name, NULL,
+ 0);
if(dir_hnd == NULL) {
errno = ENOTEMPTY;
while ((dname = ReadDirName(dir_hnd, &dirpos, &st))) {
if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
continue;
- if (!is_visible_file(conn, directory, dname, &st, False))
+ if (!is_visible_file(conn, smb_dname->base_name, dname,
+ &st, false))
continue;
if(!IS_VETO_PATH(conn, dname)) {
TALLOC_FREE(dir_hnd);
/* Do a recursive delete. */
RewindDir(dir_hnd,&dirpos);
while ((dname = ReadDirName(dir_hnd, &dirpos, &st))) {
+ struct smb_filename *smb_dname_full = NULL;
char *fullname = NULL;
+ bool do_break = true;
+ NTSTATUS status;
if (ISDOT(dname) || ISDOTDOT(dname)) {
continue;
}
- if (!is_visible_file(conn, directory, dname, &st, False)) {
+ if (!is_visible_file(conn, smb_dname->base_name, dname,
+ &st, false)) {
continue;
}
fullname = talloc_asprintf(ctx,
"%s/%s",
- directory,
+ smb_dname->base_name,
dname);
if(!fullname) {
errno = ENOMEM;
- break;
+ goto err_break;
}
- if(SMB_VFS_LSTAT(conn,fullname, &st) != 0) {
- break;
+ status = create_synthetic_smb_fname(talloc_tos(),
+ fullname, NULL,
+ NULL,
+ &smb_dname_full);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto err_break;
}
- if(st.st_ex_mode & S_IFDIR) {
- if(!recursive_rmdir(ctx, conn, fullname)) {
- break;
+
+ if(SMB_VFS_LSTAT(conn, smb_dname_full) != 0) {
+ goto err_break;
+ }
+ if(smb_dname_full->st.st_ex_mode & S_IFDIR) {
+ if(!recursive_rmdir(ctx, conn,
+ smb_dname_full)) {
+ goto err_break;
}
- if(SMB_VFS_RMDIR(conn,fullname) != 0) {
- break;
+ if(SMB_VFS_RMDIR(conn,
+ smb_dname_full->base_name) != 0) {
+ goto err_break;
}
- } else if(SMB_VFS_UNLINK(conn,fullname) != 0) {
- break;
+ } else if(SMB_VFS_UNLINK(conn, smb_dname_full) != 0) {
+ goto err_break;
}
+
+ /* Successful iteration. */
+ do_break = false;
+
+ err_break:
TALLOC_FREE(fullname);
+ TALLOC_FREE(smb_dname_full);
+ if (do_break)
+ break;
}
TALLOC_FREE(dir_hnd);
/* Retry the rmdir */
- ret = SMB_VFS_RMDIR(conn,directory);
+ ret = SMB_VFS_RMDIR(conn, smb_dname->base_name);
}
err:
if (ret != 0) {
DEBUG(3,("rmdir_internals: couldn't remove directory %s : "
- "%s\n", directory,strerror(errno)));
+ "%s\n", smb_fname_str_dbg(smb_dname),
+ strerror(errno)));
return map_nt_error_from_unix(errno);
}
notify_fname(conn, NOTIFY_ACTION_REMOVED,
FILE_NOTIFY_CHANGE_DIR_NAME,
- directory);
+ smb_dname->base_name);
return NT_STATUS_OK;
}
goto out;
}
- status = resolve_dfspath(ctx, conn,
+ status = filename_convert(ctx, conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
directory,
+ &smb_dname,
&directory);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
goto out;
}
- status = unix_convert(ctx, conn, directory, &smb_dname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
- status = get_full_smb_filename(ctx, smb_dname, &directory);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
- status = check_name(conn, directory);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
dptr_closepath(directory, req->smbpid);
- status = rmdir_internals(ctx, conn, directory);
+ status = rmdir_internals(ctx, conn, smb_dname);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
goto out;
static void rename_open_files(connection_struct *conn,
struct share_mode_lock *lck,
- const char *newname)
+ const struct smb_filename *smb_fname_dst)
{
files_struct *fsp;
bool did_rename = False;
+ char *fname_dst = NULL;
+ NTSTATUS status;
+
+ status = get_full_smb_filename(talloc_tos(), smb_fname_dst,
+ &fname_dst);
+ if (!NT_STATUS_IS_OK(status)) {
+ return;
+ }
for(fsp = file_find_di_first(lck->id); fsp;
fsp = file_find_di_next(fsp)) {
if (!strequal(fsp->conn->connectpath, conn->connectpath)) {
continue;
}
- DEBUG(10,("rename_open_files: renaming file fnum %d (file_id %s) from %s -> %s\n",
- fsp->fnum, file_id_string_tos(&fsp->file_id),
- fsp->fsp_name, newname ));
- string_set(&fsp->fsp_name, newname);
+ DEBUG(10, ("rename_open_files: renaming file fnum %d "
+ "(file_id %s) from %s -> %s\n", fsp->fnum,
+ file_id_string_tos(&fsp->file_id), fsp->fsp_name,
+ smb_fname_str_dbg(smb_fname_dst)));
+ string_set(&fsp->fsp_name, fname_dst);
did_rename = True;
}
if (!did_rename) {
- DEBUG(10,("rename_open_files: no open files on file_id %s for %s\n",
- file_id_string_tos(&lck->id), newname ));
+ DEBUG(10, ("rename_open_files: no open files on file_id %s "
+ "for %s\n", file_id_string_tos(&lck->id),
+ smb_fname_str_dbg(smb_fname_dst)));
}
/* Send messages to all smbd's (not ourself) that the name has changed. */
rename_share_filename(smbd_messaging_context(), lck, conn->connectpath,
- newname);
+ fname_dst);
+ TALLOC_FREE(fname_dst);
}
/****************************************************************************
report from <AndyLiebman@aol.com>.
****************************************************************************/
-static bool rename_path_prefix_equal(const char *src, const char *dest)
+static bool rename_path_prefix_equal(const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
- const char *psrc = src;
- const char *pdst = dest;
+ const char *psrc = smb_fname_src->base_name;
+ const char *pdst = smb_fname_dst->base_name;
size_t slen;
if (psrc[0] == '.' && psrc[1] == '/') {
*/
static void notify_rename(connection_struct *conn, bool is_dir,
- const char *oldpath, const char *newpath)
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
- char *olddir, *newdir;
- const char *oldname, *newname;
+ char *parent_dir_src = NULL;
+ char *parent_dir_dst = NULL;
+ char *fname_src = NULL;
+ char *fname_dst = NULL;
+ NTSTATUS status;
uint32 mask;
mask = is_dir ? FILE_NOTIFY_CHANGE_DIR_NAME
: FILE_NOTIFY_CHANGE_FILE_NAME;
- if (!parent_dirname(talloc_tos(), oldpath, &olddir, &oldname)
- || !parent_dirname(talloc_tos(), newpath, &newdir, &newname)) {
- TALLOC_FREE(olddir);
- return;
+ if (!parent_dirname(talloc_tos(), smb_fname_src->base_name,
+ &parent_dir_src, NULL) ||
+ !parent_dirname(talloc_tos(), smb_fname_dst->base_name,
+ &parent_dir_dst, NULL)) {
+ goto out;
+ }
+
+ status = get_full_smb_filename(talloc_tos(), smb_fname_src,
+ &fname_src);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+ status = get_full_smb_filename(talloc_tos(), smb_fname_dst,
+ &fname_dst);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
}
- if (strcmp(olddir, newdir) == 0) {
- notify_fname(conn, NOTIFY_ACTION_OLD_NAME, mask, oldpath);
- notify_fname(conn, NOTIFY_ACTION_NEW_NAME, mask, newpath);
+ if (strcmp(parent_dir_src, parent_dir_dst) == 0) {
+ notify_fname(conn, NOTIFY_ACTION_OLD_NAME, mask, fname_src);
+ notify_fname(conn, NOTIFY_ACTION_NEW_NAME, mask, fname_dst);
}
else {
- notify_fname(conn, NOTIFY_ACTION_REMOVED, mask, oldpath);
- notify_fname(conn, NOTIFY_ACTION_ADDED, mask, newpath);
+ notify_fname(conn, NOTIFY_ACTION_REMOVED, mask, fname_src);
+ notify_fname(conn, NOTIFY_ACTION_ADDED, mask, fname_dst);
}
- TALLOC_FREE(olddir);
- TALLOC_FREE(newdir);
/* this is a strange one. w2k3 gives an additional event for
CHANGE_ATTRIBUTES and CHANGE_CREATION on the new file when renaming
notify_fname(conn, NOTIFY_ACTION_MODIFIED,
FILE_NOTIFY_CHANGE_ATTRIBUTES
|FILE_NOTIFY_CHANGE_CREATION,
- newpath);
+ fname_dst);
}
+ out:
+ TALLOC_FREE(parent_dir_src);
+ TALLOC_FREE(parent_dir_dst);
+ TALLOC_FREE(fname_src);
+ TALLOC_FREE(fname_dst);
}
/****************************************************************************
NTSTATUS rename_internals_fsp(connection_struct *conn,
files_struct *fsp,
- char *newname,
- const char *newname_last_component,
+ const struct smb_filename *smb_fname_dst_in,
uint32 attrs,
bool replace_if_exists)
{
TALLOC_CTX *ctx = talloc_tos();
- SMB_STRUCT_STAT sbuf, sbuf1;
+ struct smb_filename *smb_fname_src = NULL;
+ struct smb_filename *smb_fname_dst = NULL;
+ SMB_STRUCT_STAT sbuf;
NTSTATUS status = NT_STATUS_OK;
struct share_mode_lock *lck = NULL;
bool dst_exists, old_is_stream, new_is_stream;
ZERO_STRUCT(sbuf);
- status = check_name(conn, newname);
+ status = check_name(conn, smb_fname_dst_in->base_name);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
- /* Ensure newname contains a '/' */
- if(strrchr_m(newname,'/') == 0) {
- newname = talloc_asprintf(ctx,
- "./%s",
- newname);
- if (!newname) {
- return NT_STATUS_NO_MEMORY;
+ /* Make a copy of the src and dst smb_fname structs */
+ status = copy_smb_filename(ctx, smb_fname_dst_in, &smb_fname_dst);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ /*
+ * This will be replaced with copy_smb_filename() when fsp->fsp_name
+ * is converted to store an smb_filename struct.
+ */
+ status = create_synthetic_smb_fname_split(ctx, fsp->fsp_name, NULL,
+ &smb_fname_src);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ /* Ensure the dst smb_fname contains a '/' */
+ if(strrchr_m(smb_fname_dst->base_name,'/') == 0) {
+ char * tmp;
+ tmp = talloc_asprintf(smb_fname_dst, "./%s",
+ smb_fname_dst->base_name);
+ if (!tmp) {
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
+ TALLOC_FREE(smb_fname_dst->base_name);
+ smb_fname_dst->base_name = tmp;
}
/*
* the rename (user is trying to change the case of the
* filename).
*/
-
if((conn->case_sensitive == False) && (conn->case_preserve == True) &&
- strequal(newname, fsp->fsp_name)) {
- char *p;
- char *newname_modified_last_component = NULL;
+ strequal(smb_fname_src->base_name, smb_fname_dst->base_name) &&
+ strequal(smb_fname_src->stream_name, smb_fname_dst->stream_name)) {
+ char *last_slash;
+ char *fname_dst_lcomp_base_mod = NULL;
+ struct smb_filename *smb_fname_orig_lcomp = NULL;
+
+ /*
+ * Get the last component of the destination name. Note that
+ * we guarantee that destination name contains a '/' character
+ * above.
+ */
+ last_slash = strrchr_m(smb_fname_dst->base_name, '/');
+ fname_dst_lcomp_base_mod = talloc_strdup(ctx, last_slash + 1);
+ if (!fname_dst_lcomp_base_mod) {
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
+ }
/*
- * Get the last component of the modified name.
- * Note that we guarantee that newname contains a '/'
- * character above.
+ * Create an smb_filename struct using the original last
+ * component of the destination.
*/
- p = strrchr_m(newname,'/');
- newname_modified_last_component = talloc_strdup(ctx,
- p+1);
- if (!newname_modified_last_component) {
- return NT_STATUS_NO_MEMORY;
+ status = create_synthetic_smb_fname_split(ctx,
+ smb_fname_dst->original_lcomp, NULL,
+ &smb_fname_orig_lcomp);
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(fname_dst_lcomp_base_mod);
+ goto out;
}
- if(strcsequal(newname_modified_last_component,
- newname_last_component) == False) {
+ /* If the base names only differ by case, use original. */
+ if(!strcsequal(fname_dst_lcomp_base_mod,
+ smb_fname_orig_lcomp->base_name)) {
+ char *tmp;
/*
- * Replace the modified last component with
- * the original.
+ * Replace the modified last component with the
+ * original.
*/
- *p = '\0'; /* Truncate at the '/' */
- newname = talloc_asprintf(ctx,
+ *last_slash = '\0'; /* Truncate at the '/' */
+ tmp = talloc_asprintf(smb_fname_dst,
"%s/%s",
- newname,
- newname_last_component);
+ smb_fname_dst->base_name,
+ smb_fname_orig_lcomp->base_name);
+ if (tmp == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ TALLOC_FREE(fname_dst_lcomp_base_mod);
+ TALLOC_FREE(smb_fname_orig_lcomp);
+ goto out;
+ }
+ TALLOC_FREE(smb_fname_dst->base_name);
+ smb_fname_dst->base_name = tmp;
}
+
+ /* If the stream_names only differ by case, use original. */
+ if(!strcsequal(smb_fname_dst->stream_name,
+ smb_fname_orig_lcomp->stream_name)) {
+ char *tmp = NULL;
+ /* Use the original stream. */
+ tmp = talloc_strdup(smb_fname_dst,
+ smb_fname_orig_lcomp->stream_name);
+ if (tmp == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ TALLOC_FREE(fname_dst_lcomp_base_mod);
+ TALLOC_FREE(smb_fname_orig_lcomp);
+ goto out;
+ }
+ TALLOC_FREE(smb_fname_dst->stream_name);
+ smb_fname_dst->stream_name = tmp;
+ }
+ TALLOC_FREE(fname_dst_lcomp_base_mod);
+ TALLOC_FREE(smb_fname_orig_lcomp);
}
/*
* don't do the rename, just return success.
*/
- if (strcsequal(fsp->fsp_name, newname)) {
- DEBUG(3,("rename_internals_fsp: identical names in rename %s - returning success\n",
- newname));
- return NT_STATUS_OK;
+ if (strcsequal(smb_fname_src->base_name, smb_fname_dst->base_name) &&
+ strcsequal(smb_fname_src->stream_name,
+ smb_fname_dst->stream_name)) {
+ DEBUG(3, ("rename_internals_fsp: identical names in rename %s "
+ "- returning success\n",
+ smb_fname_str_dbg(smb_fname_dst)));
+ status = NT_STATUS_OK;
+ goto out;
}
- old_is_stream = is_ntfs_stream_name(fsp->fsp_name);
- new_is_stream = is_ntfs_stream_name(newname);
+ old_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
+ new_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
/* Return the correct error code if both names aren't streams. */
if (!old_is_stream && new_is_stream) {
- return NT_STATUS_OBJECT_NAME_INVALID;
+ status = NT_STATUS_OBJECT_NAME_INVALID;
+ goto out;
}
if (old_is_stream && !new_is_stream) {
- return NT_STATUS_INVALID_PARAMETER;
+ status = NT_STATUS_INVALID_PARAMETER;
+ goto out;
}
- /*
- * Have vfs_object_exist also fill sbuf1
- */
- dst_exists = vfs_object_exist(conn, newname, &sbuf1);
+ dst_exists = SMB_VFS_STAT(conn, smb_fname_dst) == 0;
if(!replace_if_exists && dst_exists) {
- DEBUG(3,("rename_internals_fsp: dest exists doing rename %s -> %s\n",
- fsp->fsp_name,newname));
- return NT_STATUS_OBJECT_NAME_COLLISION;
+ DEBUG(3, ("rename_internals_fsp: dest exists doing rename "
+ "%s -> %s\n", smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
+ status = NT_STATUS_OBJECT_NAME_COLLISION;
+ goto out;
}
if (dst_exists) {
- struct file_id fileid = vfs_file_id_from_sbuf(conn, &sbuf1);
+ struct file_id fileid = vfs_file_id_from_sbuf(conn,
+ &smb_fname_dst->st);
files_struct *dst_fsp = file_find_di_first(fileid);
/* The file can be open when renaming a stream */
if (dst_fsp && !new_is_stream) {
DEBUG(3, ("rename_internals_fsp: Target file open\n"));
- return NT_STATUS_ACCESS_DENIED;
+ status = NT_STATUS_ACCESS_DENIED;
+ goto out;
}
}
/* Ensure we have a valid stat struct for the source. */
if (fsp->fh->fd != -1) {
if (SMB_VFS_FSTAT(fsp, &sbuf) == -1) {
- return map_nt_error_from_unix(errno);
+ status = map_nt_error_from_unix(errno);
+ goto out;
}
} else {
int ret = -1;
if (fsp->posix_open) {
- ret = SMB_VFS_LSTAT(conn,fsp->fsp_name,&sbuf);
+ ret = SMB_VFS_LSTAT(conn, smb_fname_src);
} else {
- ret = SMB_VFS_STAT(conn,fsp->fsp_name,&sbuf);
+
+ ret = SMB_VFS_STAT(conn, smb_fname_src);
}
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ status = map_nt_error_from_unix(errno);
+ goto out;
}
+ sbuf = smb_fname_src->st;
}
status = can_rename(conn, fsp, attrs, &sbuf);
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(3,("rename_internals_fsp: Error %s rename %s -> %s\n",
- nt_errstr(status), fsp->fsp_name,newname));
+ DEBUG(3, ("rename_internals_fsp: Error %s rename %s -> %s\n",
+ nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
if (NT_STATUS_EQUAL(status,NT_STATUS_SHARING_VIOLATION))
status = NT_STATUS_ACCESS_DENIED;
- return status;
+ goto out;
}
- if (rename_path_prefix_equal(fsp->fsp_name, newname)) {
- return NT_STATUS_ACCESS_DENIED;
+ if (rename_path_prefix_equal(smb_fname_src, smb_fname_dst)) {
+ status = NT_STATUS_ACCESS_DENIED;
}
lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
SMB_ASSERT(lck != NULL);
- if(SMB_VFS_RENAME(conn,fsp->fsp_name, newname) == 0) {
+ if(SMB_VFS_RENAME(conn, smb_fname_src, smb_fname_dst) == 0) {
uint32 create_options = fsp->fh->private_options;
- DEBUG(3,("rename_internals_fsp: succeeded doing rename on %s -> %s\n",
- fsp->fsp_name,newname));
+ DEBUG(3, ("rename_internals_fsp: succeeded doing rename on "
+ "%s -> %s\n", smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
- notify_rename(conn, fsp->is_directory, fsp->fsp_name, newname);
+ notify_rename(conn, fsp->is_directory, smb_fname_src,
+ smb_fname_dst);
- rename_open_files(conn, lck, newname);
+ rename_open_files(conn, lck, smb_fname_dst);
/*
* A rename acts as a new file create w.r.t. allowing an initial delete
}
}
TALLOC_FREE(lck);
- return NT_STATUS_OK;
+ status = NT_STATUS_OK;
+ goto out;
}
TALLOC_FREE(lck);
status = map_nt_error_from_unix(errno);
}
- DEBUG(3,("rename_internals_fsp: Error %s rename %s -> %s\n",
- nt_errstr(status), fsp->fsp_name,newname));
+ DEBUG(3, ("rename_internals_fsp: Error %s rename %s -> %s\n",
+ nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
+
+ out:
+ TALLOC_FREE(smb_fname_src);
+ TALLOC_FREE(smb_fname_dst);
return status;
}
if (!src_has_wild) {
files_struct *fsp;
- char *fname_src = NULL;
- char *fname_dst = NULL;
/*
- * Only one file needs to be renamied. Append the mask back
+ * Only one file needs to be renamed. Append the mask back
* onto the directory.
*/
TALLOC_FREE(smb_fname_src->base_name);
"directory = %s, newname = %s, "
"last_component_dest = %s\n",
conn->case_sensitive, conn->case_preserve,
- conn->short_case_preserve, smb_fname_src->base_name,
- smb_fname_dst->base_name,
+ conn->short_case_preserve,
+ smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst),
smb_fname_dst->original_lcomp));
/* The dest name still may have wildcards. */
smb_fname_dst->base_name = fname_dst_mod;
}
- status = get_full_smb_filename(ctx, smb_fname_src, &fname_src);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
ZERO_STRUCT(smb_fname_src->st);
if (posix_pathnames) {
- SMB_VFS_LSTAT(conn, fname_src, &smb_fname_src->st);
+ SMB_VFS_LSTAT(conn, smb_fname_src);
} else {
- SMB_VFS_STAT(conn, fname_src, &smb_fname_src->st);
+ SMB_VFS_STAT(conn, smb_fname_src);
}
if (S_ISDIR(smb_fname_src->st.st_ex_mode)) {
conn, /* conn */
req, /* req */
0, /* root_dir_fid */
- fname_src, /* fname */
- 0, /* create_file_flags */
+ smb_fname_src, /* fname */
access_mask, /* access_mask */
(FILE_SHARE_READ | /* share_access */
FILE_SHARE_WRITE),
NULL, /* sd */
NULL, /* ea_list */
&fsp, /* result */
- NULL, /* pinfo */
- &smb_fname_src->st); /* psbuf */
+ NULL); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("Could not open rename source %s: %s\n",
- fname_src, nt_errstr(status)));
- TALLOC_FREE(fname_src);
- goto out;
- }
-
- status = get_full_smb_filename(ctx, smb_fname_dst, &fname_dst);
- if (!NT_STATUS_IS_OK(status)) {
- TALLOC_FREE(fname_src);
+ smb_fname_str_dbg(smb_fname_src),
+ nt_errstr(status)));
goto out;
}
- status = rename_internals_fsp(conn, fsp, fname_dst,
- smb_fname_dst->original_lcomp,
+ status = rename_internals_fsp(conn, fsp, smb_fname_dst,
attrs, replace_if_exists);
close_file(req, fsp, NORMAL_CLOSE);
DEBUG(3, ("rename_internals: Error %s rename %s -> %s\n",
- nt_errstr(status), fname_src, fname_dst));
+ nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
- TALLOC_FREE(fname_src);
- TALLOC_FREE(fname_dst);
goto out;
}
while ((dname = ReadDirName(dir_hnd, &offset, &smb_fname_src->st))) {
files_struct *fsp = NULL;
- char *fname_src = NULL;
- char *fname_dst = NULL;
char *destname = NULL;
bool sysdir_entry = False;
TALLOC_FREE(smb_fname_dst->base_name);
smb_fname_dst->base_name = destname;
- status = get_full_smb_filename(ctx, smb_fname_src, &fname_src);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
- status = get_full_smb_filename(ctx, smb_fname_dst, &fname_dst);
- if (!NT_STATUS_IS_OK(status)) {
- TALLOC_FREE(fname_src);
- goto out;
- }
-
ZERO_STRUCT(smb_fname_src->st);
if (posix_pathnames) {
- SMB_VFS_LSTAT(conn, fname_src, &smb_fname_src->st);
+ SMB_VFS_LSTAT(conn, smb_fname_src);
} else {
- SMB_VFS_STAT(conn, fname_src, &smb_fname_src->st);
+ SMB_VFS_STAT(conn, smb_fname_src);
}
create_options = 0;
conn, /* conn */
req, /* req */
0, /* root_dir_fid */
- fname_src, /* fname */
- 0, /* create_file_flags */
+ smb_fname_src, /* fname */
access_mask, /* access_mask */
(FILE_SHARE_READ | /* share_access */
FILE_SHARE_WRITE),
NULL, /* sd */
NULL, /* ea_list */
&fsp, /* result */
- NULL, /* pinfo */
- &smb_fname_src->st); /* psbuf */
+ NULL); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3,("rename_internals: SMB_VFS_CREATE_FILE "
"returned %s rename %s -> %s\n",
- nt_errstr(status), fname_src, fname_dst));
- TALLOC_FREE(fname_src);
- TALLOC_FREE(fname_dst);
+ nt_errstr(status),
+ smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
break;
}
- status = rename_internals_fsp(conn, fsp, fname_dst, dname,
+ smb_fname_dst->original_lcomp = talloc_strdup(smb_fname_dst,
+ dname);
+ if (!smb_fname_dst->original_lcomp) {
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
+ }
+
+ status = rename_internals_fsp(conn, fsp, smb_fname_dst,
attrs, replace_if_exists);
close_file(req, fsp, NORMAL_CLOSE);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("rename_internals_fsp returned %s for "
"rename %s -> %s\n", nt_errstr(status),
- fname_src, fname_dst));
+ smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
break;
- TALLOC_FREE(fname_src);
- TALLOC_FREE(fname_dst);
}
count++;
DEBUG(3,("rename_internals: doing rename on %s -> "
- "%s\n", fname_src, fname_dst));
+ "%s\n", smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_src)));
- TALLOC_FREE(fname_src);
- TALLOC_FREE(fname_dst);
}
TALLOC_FREE(dir_hnd);
{
struct smb_filename *smb_fname_dst_tmp = NULL;
char *fname_src = NULL;
- char *fname_dst = NULL;
SMB_OFF_T ret=-1;
files_struct *fsp1,*fsp2;
uint32 dosattrs;
}
}
- status = get_full_smb_filename(talloc_tos(), smb_fname_src, &fname_src);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
/* Open the src file for reading. */
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
NULL, /* req */
0, /* root_dir_fid */
- fname_src, /* fname */
- 0, /* create_file_flags */
+ smb_fname_src, /* fname */
FILE_GENERIC_READ, /* access_mask */
FILE_SHARE_READ | FILE_SHARE_WRITE, /* share_access */
FILE_OPEN, /* create_disposition*/
NULL, /* sd */
NULL, /* ea_list */
&fsp1, /* result */
- NULL, /* pinfo */
- &smb_fname_src->st); /* psbuf */
+ NULL); /* psbuf */
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
- dosattrs = dos_mode(conn, fname_src, &smb_fname_src->st);
-
- status = get_full_smb_filename(talloc_tos(), smb_fname_dst_tmp, &fname_dst);
+ status = get_full_smb_filename(talloc_tos(), smb_fname_src, &fname_src);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
- if (SMB_VFS_STAT(conn, fname_dst, &smb_fname_dst_tmp->st) == -1) {
+ dosattrs = dos_mode(conn, fname_src, &smb_fname_src->st);
+
+ TALLOC_FREE(fname_src);
+
+ if (SMB_VFS_STAT(conn, smb_fname_dst_tmp) == -1) {
ZERO_STRUCTP(&smb_fname_dst_tmp->st);
}
conn, /* conn */
NULL, /* req */
0, /* root_dir_fid */
- fname_dst, /* fname */
- 0, /* create_file_flags */
+ smb_fname_dst, /* fname */
FILE_GENERIC_WRITE, /* access_mask */
FILE_SHARE_READ | FILE_SHARE_WRITE, /* share_access */
new_create_disposition, /* create_disposition*/
NULL, /* sd */
NULL, /* ea_list */
&fsp2, /* result */
- NULL, /* pinfo */
- &smb_fname_dst_tmp->st); /* psbuf */
+ NULL); /* psbuf */
if (!NT_STATUS_IS_OK(status)) {
close_file(NULL, fsp1, ERROR_CLOSE);
out:
TALLOC_FREE(smb_fname_dst_tmp);
- TALLOC_FREE(fname_src);
- TALLOC_FREE(fname_dst);
return status;
}
}
if (NT_STATUS_V(status)) {
- END_PROFILE(SMBlockingX);
- reply_nterror(req, status);
- return;
+ break;
}
}
/* If any of the above locks failed, then we must unlock
all of the previous locks (X/Open spec). */
+ if (num_locks != 0 && !NT_STATUS_IS_OK(status)) {
+
+ if (locktype & LOCKING_ANDX_CANCEL_LOCK) {
+ i = -1; /* we want to skip the for loop */
+ }
- if (!(locktype & LOCKING_ANDX_CANCEL_LOCK) &&
- (i != num_locks) &&
- (num_locks != 0)) {
/*
* Ensure we don't do a remove on the lock that just failed,
* as under POSIX rules, if we have a lock already there, we
void reply_setattrE(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ struct smb_filename *smb_fname = NULL;
struct smb_file_time ft;
files_struct *fsp;
- SMB_STRUCT_STAT sbuf;
NTSTATUS status;
START_PROFILE(SMBsetattrE);
if (req->wct < 7) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- END_PROFILE(SMBsetattrE);
- return;
+ goto out;
}
fsp = file_fsp(req, SVAL(req->vwv+0, 0));
if(!fsp || (fsp->conn != conn)) {
reply_doserror(req, ERRDOS, ERRbadfid);
- END_PROFILE(SMBsetattrE);
- return;
+ goto out;
}
+ /* XXX: Remove when fsp->fsp_name is converted to smb_filename. */
+ status = create_synthetic_smb_fname_split(talloc_tos(), fsp->fsp_name,
+ NULL, &smb_fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ reply_nterror(req, status);
+ goto out;
+ }
/*
* Convert the DOS times into unix times.
/* Ensure we have a valid stat struct for the source. */
if (fsp->fh->fd != -1) {
- if (SMB_VFS_FSTAT(fsp, &sbuf) == -1) {
+ if (SMB_VFS_FSTAT(fsp, &smb_fname->st) == -1) {
status = map_nt_error_from_unix(errno);
reply_nterror(req, status);
- END_PROFILE(SMBsetattrE);
- return;
+ goto out;
}
} else {
int ret = -1;
if (fsp->posix_open) {
- ret = SMB_VFS_LSTAT(conn, fsp->fsp_name, &sbuf);
+ ret = SMB_VFS_LSTAT(conn, smb_fname);
} else {
- ret = SMB_VFS_STAT(conn, fsp->fsp_name, &sbuf);
+ ret = SMB_VFS_STAT(conn, smb_fname);
}
if (ret == -1) {
status = map_nt_error_from_unix(errno);
reply_nterror(req, status);
- END_PROFILE(SMBsetattrE);
- return;
+ goto out;
}
}
- status = smb_set_file_time(conn, fsp, fsp->fsp_name,
- &sbuf, &ft, true);
+ status = smb_set_file_time(conn, fsp, smb_fname, &ft, true);
if (!NT_STATUS_IS_OK(status)) {
reply_doserror(req, ERRDOS, ERRnoaccess);
- END_PROFILE(SMBsetattrE);
- return;
+ goto out;
}
DEBUG( 3, ( "reply_setattrE fnum=%d actime=%u modtime=%u "
(unsigned int)ft.mtime.tv_sec,
(unsigned int)ft.create_time.tv_sec
));
-
+ out:
END_PROFILE(SMBsetattrE);
return;
}