int get_real_filename(connection_struct *conn, const char *path,
const char *name, TALLOC_CTX *mem_ctx,
char **found_name);
+NTSTATUS filename_convert(TALLOC_CTX *mem_ctx,
+ connection_struct *conn,
+ bool dfs_path,
+ const char *name_in,
+ struct smb_filename **pp_smb_fname,
+ char **pp_name);
/* The following definitions come from smbd/files.c */
unsigned char *create_volume_objectid(connection_struct *conn, unsigned char objid[16]);
NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
connection_struct *conn,
- const char *oldname_in,
- const char *newname_in);
+ const struct smb_filename *smb_fname_old,
+ const struct smb_filename *smb_fname_new);
NTSTATUS smb_set_file_time(connection_struct *conn,
files_struct *fsp,
const char *fname,
TALLOC_FREE(streams);
return status;
}
+
+/****************************************************************************
+ Go through all the steps to validate a filename.
+****************************************************************************/
+
+NTSTATUS filename_convert(TALLOC_CTX *ctx,
+ connection_struct *conn,
+ bool dfs_path,
+ const char *name_in,
+ struct smb_filename **pp_smb_fname,
+ char **pp_name)
+{
+ NTSTATUS status;
+
+ *pp_smb_fname = NULL;
+ *pp_name = NULL;
+
+ status = resolve_dfspath(ctx, conn,
+ dfs_path,
+ name_in,
+ pp_name);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10,("filename_convert: resolve_dfspath failed "
+ "for name %s with %s\n",
+ name_in,
+ nt_errstr(status) ));
+ return status;
+ }
+ status = unix_convert(ctx, conn, *pp_name, pp_smb_fname, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10,("filename_convert: unix_convert failed "
+ "for name %s with %s\n",
+ *pp_name,
+ nt_errstr(status) ));
+ return status;
+ }
+
+ status = get_full_smb_filename(ctx, *pp_smb_fname, pp_name);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ status = check_name(conn, *pp_name);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(3,("filename_convert: check_name failed "
+ "for name %s with %s\n",
+ *pp_name,
+ nt_errstr(status) ));
+ return status;
+ }
+ return status;
+}
? BATCH_OPLOCK : 0;
}
- status = resolve_dfspath(ctx,
+ status = filename_convert(ctx,
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
+ &smb_fname,
&fname);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
req, /* req */
goto out;
}
- status = resolve_dfspath(ctx,
+ status = filename_convert(ctx,
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
+ &smb_fname,
&fname);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
if (oplock_request) {
oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
void reply_ntrename(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ struct smb_filename *smb_fname_old = NULL;
+ struct smb_filename *smb_fname_new = NULL;
char *oldname = NULL;
char *newname = NULL;
const char *p;
return;
}
- status = resolve_dfspath(ctx, conn,
+ status = filename_convert(ctx, conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
oldname,
+ &smb_fname_old,
&oldname);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
return;
}
- status = resolve_dfspath(ctx, conn,
+ status = filename_convert(ctx, conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
newname,
+ &smb_fname_new,
&newname);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
} else {
status = hardlink_internals(ctx,
conn,
- oldname,
- newname);
+ smb_fname_old,
+ smb_fname_new);
}
break;
case RENAME_FLAG_COPY:
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,
+ &name);
+
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)));
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;
}
goto out;
}
- status = resolve_dfspath(ctx, conn,
+ 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)) {
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') {
/*
* Not sure here is the right place to catch this
goto out;
}
- status = resolve_dfspath(ctx,
+ 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)) {
goto out;
}
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
if (!map_open_params_to_ntcreate(
fname, deny_mode, OPENX_FILE_EXISTS_OPEN, &access_mask,
&share_mode, &create_disposition, &create_options)) {
goto out;
}
- status = resolve_dfspath(ctx,
+ 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)) {
goto out;
}
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
if (!map_open_params_to_ntcreate(
fname, deny_mode, smb_ofun, &access_mask,
&share_mode, &create_disposition, &create_options)) {
goto out;
}
- status = resolve_dfspath(ctx,
+ 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)) {
goto out;
}
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
if (fattr & aVOLID) {
DEBUG(0,("Attempt to create file (%s) with volid set - "
"please report this\n", fname));
goto out;
}
- status = resolve_dfspath(ctx, conn,
+ 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)) {
goto out;
}
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
- status = check_name(conn, smb_fname->base_name);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
tmpfd = mkstemp(smb_fname->base_name);
if (tmpfd == -1) {
reply_unixerror(req, ERRDOS, ERRnoaccess);
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 = 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)));
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);
if (!NT_STATUS_IS_OK(status)) {
in_create_options &= ~(0x10);/* NTCREATEX_OPTIONS_SYNC_ALERT */
in_create_options &= ~(0x20);/* NTCREATEX_OPTIONS_ASYNC_ALERT */
- status = resolve_dfspath(talloc_tos(),
+ status = filename_convert(talloc_tos(),
smbreq->conn,
smbreq->flags2 & FLAGS2_DFS_PATHNAMES,
in_name,
+ &smb_fname,
&fname);
if (!NT_STATUS_IS_OK(status)) {
tevent_req_nterror(req, status);
goto out;
}
- status = unix_convert(talloc_tos(), smbreq->conn, fname,
- &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- tevent_req_nterror(req, status);
- goto out;
- }
-
status = SMB_VFS_CREATE_FILE(smbreq->conn,
smbreq,
0, /* root_dir_fid */
fname, (unsigned int)deny_mode, (unsigned int)open_attr,
(unsigned int)open_ofun, open_size));
- status = resolve_dfspath(ctx,
+ 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)) {
goto out;
}
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
if (open_ofun == 0) {
reply_nterror(req, NT_STATUS_OBJECT_NAME_COLLISION);
goto out;
return;
}
- status = resolve_dfspath(ctx,
+ 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)) {
return;
}
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- return;
- }
sbuf = smb_fname->st;
- status = get_full_smb_filename(ctx, smb_fname, &fname);
- TALLOC_FREE(smb_fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- return;
- }
-
- status = check_name(conn, fname);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(3,("call_trans2qfilepathinfo: fileinfo of %s failed (%s)\n",fname,nt_errstr(status)));
- reply_nterror(req, status);
- return;
- }
-
if ((conn->fs_capabilities & FILE_NAMED_STREAMS)
&& is_ntfs_stream_name(fname)) {
char *base;
NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
connection_struct *conn,
- const char *oldname_in,
- const char *newname_in)
+ const struct smb_filename *smb_fname_old,
+ const struct smb_filename *smb_fname_new)
{
- struct smb_filename *smb_fname = NULL;
- struct smb_filename *smb_fname_new = NULL;
char *oldname = NULL;
char *newname = NULL;
NTSTATUS status = NT_STATUS_OK;
- status = unix_convert(ctx, conn, oldname_in, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
- status = get_full_smb_filename(ctx, smb_fname, &oldname);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
- status = check_name(conn, oldname);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
/* source must already exist. */
- if (!VALID_STAT(smb_fname->st)) {
- status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
- goto out;
- }
-
- status = unix_convert(ctx, conn, newname_in, &smb_fname_new, 0);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
- status = get_full_smb_filename(ctx, smb_fname_new, &newname);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
- status = check_name(conn, newname);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
+ if (!VALID_STAT(smb_fname_old->st)) {
+ return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
/* Disallow if newname already exists. */
if (VALID_STAT(smb_fname_new->st)) {
- status = NT_STATUS_OBJECT_NAME_COLLISION;
- goto out;
+ return NT_STATUS_OBJECT_NAME_COLLISION;
}
/* No links from a directory. */
- if (S_ISDIR(smb_fname->st.st_ex_mode)) {
- status = NT_STATUS_FILE_IS_A_DIRECTORY;
- goto out;
+ if (S_ISDIR(smb_fname_old->st.st_ex_mode)) {
+ return NT_STATUS_FILE_IS_A_DIRECTORY;
}
- /* Ensure this is within the share. */
- status = check_reduced_name(conn, oldname);
+ status = get_full_smb_filename(ctx, smb_fname_new, &newname);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+ status = get_full_smb_filename(ctx, smb_fname_old, &oldname);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
nt_errstr(status), newname, oldname));
}
out:
- TALLOC_FREE(smb_fname);
- TALLOC_FREE(smb_fname_new);
+ TALLOC_FREE(newname);
+ TALLOC_FREE(oldname);
return status;
}
static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
struct smb_request *req,
const char *pdata, int total_data,
- const char *fname)
+ const struct smb_filename *smb_fname_new)
{
char *oldname = NULL;
+ struct smb_filename *smb_fname_old = NULL;
TALLOC_CTX *ctx = talloc_tos();
NTSTATUS status = NT_STATUS_OK;
return status;
}
- status = resolve_dfspath(ctx, conn,
+ DEBUG(10,("smb_set_file_unix_hlink: SMB_SET_FILE_UNIX_LINK doing hard link %s -> %s\n",
+ smb_fname_str_dbg(smb_fname_new), oldname));
+
+ status = filename_convert(ctx,
+ conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
oldname,
+ &smb_fname_old,
&oldname);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
- DEBUG(10,("smb_set_file_unix_hlink: SMB_SET_FILE_UNIX_LINK doing hard link %s -> %s\n",
- fname, oldname));
-
- return hardlink_internals(ctx, conn, oldname, fname);
+ return hardlink_internals(ctx, conn, smb_fname_old, smb_fname_new);
}
/****************************************************************************
return;
}
- status = resolve_dfspath(ctx, conn,
+ 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)) {
return;
}
- status = unix_convert(ctx, conn, fname, &smb_fname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- return;
- }
sbuf = smb_fname->st;
- status = get_full_smb_filename(ctx, smb_fname, &fname);
- TALLOC_FREE(smb_fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- return;
- }
-
- status = check_name(conn, fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- return;
- }
-
if (INFO_LEVEL_IS_UNIX(info_level)) {
/*
* For CIFS UNIX extensions the target name may not exist.
case SMB_SET_FILE_UNIX_HLINK:
{
- if (tran_call != TRANSACT2_SETPATHINFO) {
+ if (tran_call != TRANSACT2_SETPATHINFO || smb_fname == NULL) {
/* We must have a pathname for this. */
reply_nterror(req, NT_STATUS_INVALID_LEVEL);
return;
}
status = smb_set_file_unix_hlink(conn, req,
pdata, total_data,
- fname);
+ smb_fname);
break;
}
DEBUG(3,("call_trans2mkdir : name = %s\n", directory));
- status = unix_convert(ctx, conn, directory, &smb_dname, 0);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- return;
- }
+ status = filename_convert(ctx,
+ conn,
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ directory,
+ &smb_dname,
+ &directory);
- status = check_name(conn, smb_dname->base_name);
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(5,("call_trans2mkdir error (%s)\n", nt_errstr(status)));
+ if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+ reply_botherror(req,
+ NT_STATUS_PATH_NOT_COVERED,
+ ERRSRV, ERRbadpath);
+ return;
+ }
reply_nterror(req, status);
- goto out;
- }
+ return;
+ }
/* Any data in this call is an EA list. */
if (total_data && (total_data != 4) && !lp_ea_support(SNUM(conn))) {