Fix a couple more unix_convert uses to filename_convert.
Fix bug in acl_group_override() where an uninitialized
struct could be used. Move unix_convert with wildcard
use in SMBsearch reply to boilerplate code.
Jeremy.
mode_t unix_mode(connection_struct *conn, int dosmode, const char *fname,
const char *inherit_from_dir);
-uint32 dos_mode_msdfs(connection_struct *conn, const char *path,SMB_STRUCT_STAT *sbuf);
+uint32 dos_mode_msdfs(connection_struct *conn, const char *path, const SMB_STRUCT_STAT *sbuf);
int dos_attributes_to_stat_dos_flags(uint32_t dosmode);
-uint32 dos_mode(connection_struct *conn, const char *path,SMB_STRUCT_STAT *sbuf);
+uint32 dos_mode(connection_struct *conn, const char *path, const SMB_STRUCT_STAT *sbuf);
int file_set_dosmode(connection_struct *conn, const char *fname,
uint32 dosmode, SMB_STRUCT_STAT *st,
const char *parent_dir,
uint32_t access_mask);
bool can_delete_file_in_directory(connection_struct *conn,
const struct smb_filename *smb_fname);
-bool can_access_file_data(connection_struct *conn, const char *fname, SMB_STRUCT_STAT *psbuf, uint32 access_mask);
-bool can_write_to_file(connection_struct *conn, const char *fname, SMB_STRUCT_STAT *psbuf);
+bool can_access_file_data(connection_struct *conn, const char *fname, const SMB_STRUCT_STAT *psbuf, uint32 access_mask);
+bool can_write_to_file(connection_struct *conn, const char *fname, const SMB_STRUCT_STAT *psbuf);
bool directory_has_default_acl(connection_struct *conn, const char *fname);
/* The following definitions come from smbd/fileio.c */
goto error_exit;
}
- nt_status = resolve_dfspath(talloc_tos(),
+ nt_status = filename_convert(talloc_tos(),
conn,
false,
r->in.file,
+ &smb_fname,
&fname);
if (!NT_STATUS_IS_OK(nt_status)) {
werr = ntstatus_to_werror(nt_status);
goto error_exit;
}
- nt_status = unix_convert(talloc_tos(), conn, fname, &smb_fname,
- 0);
- if (!NT_STATUS_IS_OK(nt_status)) {
- werr = ntstatus_to_werror(nt_status);
- goto error_exit;
- }
-
nt_status = SMB_VFS_CREATE_FILE(
conn, /* conn */
NULL, /* req */
goto error_exit;
}
- nt_status = resolve_dfspath(talloc_tos(),
+ nt_status = filename_convert(talloc_tos(),
conn,
false,
r->in.file,
+ &smb_fname,
&fname);
if (!NT_STATUS_IS_OK(nt_status)) {
werr = ntstatus_to_werror(nt_status);
goto error_exit;
}
- nt_status = unix_convert(talloc_tos(), conn, fname, &smb_fname,
- 0);
- if (!NT_STATUS_IS_OK(nt_status)) {
- werr = ntstatus_to_werror(nt_status);
- goto error_exit;
- }
nt_status = SMB_VFS_CREATE_FILE(
conn, /* conn */
Change a unix mode to a dos mode.
****************************************************************************/
-static uint32 dos_mode_from_sbuf(connection_struct *conn, const char *path, SMB_STRUCT_STAT *sbuf)
+static uint32 dos_mode_from_sbuf(connection_struct *conn, const char *path, const SMB_STRUCT_STAT *sbuf)
{
int result = 0;
enum mapreadonly_options ro_opts = (enum mapreadonly_options)lp_map_readonly(SNUM(conn));
Get DOS attributes from an EA.
****************************************************************************/
-static bool get_ea_dos_attribute(connection_struct *conn, const char *path,SMB_STRUCT_STAT *sbuf, uint32 *pattr)
+static bool get_ea_dos_attribute(connection_struct *conn, const char *path, const SMB_STRUCT_STAT *sbuf, uint32 *pattr)
{
ssize_t sizeret;
fstring attrstr;
Change a unix mode to a dos mode for an ms dfs link.
****************************************************************************/
-uint32 dos_mode_msdfs(connection_struct *conn, const char *path,SMB_STRUCT_STAT *sbuf)
+uint32 dos_mode_msdfs(connection_struct *conn, const char *path, const SMB_STRUCT_STAT *psbuf)
{
+ SMB_STRUCT_STAT sbuf = *psbuf;
uint32 result = 0;
DEBUG(8,("dos_mode_msdfs: %s\n", path));
- if (!VALID_STAT(*sbuf)) {
+ if (!VALID_STAT(sbuf)) {
return 0;
}
}
}
- result |= dos_mode_from_sbuf(conn, path, sbuf);
+ result |= dos_mode_from_sbuf(conn, path, &sbuf);
/* Optimization : Only call is_hidden_path if it's not already
hidden. */
Change a unix mode to a dos mode.
****************************************************************************/
-uint32 dos_mode(connection_struct *conn, const char *path,SMB_STRUCT_STAT *sbuf)
+uint32 dos_mode(connection_struct *conn, const char *path, const SMB_STRUCT_STAT *psbuf)
{
+ SMB_STRUCT_STAT sbuf = *psbuf;
uint32 result = 0;
bool offline, used_stat_dos_flags = false;
DEBUG(8,("dos_mode: %s\n", path));
- if (!VALID_STAT(*sbuf)) {
+ if (!VALID_STAT(sbuf)) {
return 0;
}
}
#ifdef HAVE_STAT_DOS_FLAGS
- used_stat_dos_flags = get_stat_dos_flags(conn, path, sbuf, &result);
+ used_stat_dos_flags = get_stat_dos_flags(conn, path, &sbuf, &result);
#endif
if (!used_stat_dos_flags) {
/* Get the DOS attributes from an EA by preference. */
- if (get_ea_dos_attribute(conn, path, sbuf, &result)) {
- result |= set_sparse_flag(sbuf);
+ if (get_ea_dos_attribute(conn, path, &sbuf, &result)) {
+ result |= set_sparse_flag(&sbuf);
} else {
- result |= dos_mode_from_sbuf(conn, path, sbuf);
+ result |= dos_mode_from_sbuf(conn, path, &sbuf);
}
}
- offline = SMB_VFS_IS_OFFLINE(conn, path, sbuf);
- if (S_ISREG(sbuf->st_ex_mode) && offline) {
+ offline = SMB_VFS_IS_OFFLINE(conn, path, &sbuf);
+ if (S_ISREG(sbuf.st_ex_mode) && offline) {
result |= FILE_ATTRIBUTE_OFFLINE;
}
Note this doesn't take into account share write permissions.
****************************************************************************/
-bool can_access_file_data(connection_struct *conn, const char *fname, SMB_STRUCT_STAT *psbuf, uint32 access_mask)
+bool can_access_file_data(connection_struct *conn, const char *fname, const SMB_STRUCT_STAT *psbuf, uint32 access_mask)
{
if (!(access_mask & (FILE_READ_DATA|FILE_WRITE_DATA))) {
return False;
return True;
}
- if (!VALID_STAT(*psbuf)) {
- /* Get the file permission mask and owners. */
- if(SMB_VFS_STAT(conn, fname, psbuf) != 0) {
- return False;
- }
- }
+ SMB_ASSERT(psbuf && VALID_STAT(*psbuf));
/* Check primary owner access. */
if (conn->server_info->utok.uid == psbuf->st_ex_uid) {
Note this doesn't take into account share write permissions.
****************************************************************************/
-bool can_write_to_file(connection_struct *conn, const char *fname, SMB_STRUCT_STAT *psbuf)
+bool can_write_to_file(connection_struct *conn, const char *fname, const SMB_STRUCT_STAT *psbuf)
{
return can_access_file_data(conn, fname, psbuf, FILE_WRITE_DATA);
}
static NTSTATUS copy_internals(TALLOC_CTX *ctx,
connection_struct *conn,
struct smb_request *req,
- const char *oldname_in,
- const char *newname_in,
+ struct smb_filename *smb_fname_src,
+ struct smb_filename *smb_fname_dst,
uint32 attrs)
{
- struct smb_filename *smb_fname_src = NULL;
- struct smb_filename *smb_fname_dst = NULL;
char *oldname = NULL;
char *newname = NULL;
files_struct *fsp1,*fsp2;
goto out;
}
- status = unix_convert(ctx, conn, oldname_in, &smb_fname_src, 0);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
- status = check_name(conn, smb_fname_src->base_name);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
/* Source must already exist. */
if (!VALID_STAT(smb_fname_src->st)) {
status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
goto out;
}
- status = unix_convert(ctx, conn, newname_in, &smb_fname_dst, 0);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
- status = check_name(conn, smb_fname_dst->base_name);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
/* Disallow if dst file already exists. */
if (VALID_STAT(smb_fname_dst->st)) {
status = NT_STATUS_OBJECT_NAME_COLLISION;
goto out;
}
- /* Ensure this is within the share. */
- status = check_reduced_name(conn, smb_fname_src->base_name);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
DEBUG(10,("copy_internals: doing file copy %s to %s\n",
smb_fname_str_dbg(smb_fname_src),
smb_fname_str_dbg(smb_fname_dst)));
smb_fname_str_dbg(smb_fname_dst)));
}
- TALLOC_FREE(smb_fname_src);
- TALLOC_FREE(smb_fname_dst);
TALLOC_FREE(oldname);
TALLOC_FREE(newname);
/* No wildcards. */
status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
} else {
- status = copy_internals(ctx, conn, req, oldname,
- newname, attrs);
+ status = copy_internals(ctx, conn, req,
+ smb_fname_old,
+ smb_fname_new,
+ attrs);
}
break;
case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
uint64_t allocation_size,
struct security_descriptor *sd,
struct ea_list *ea_list,
-
files_struct **result,
int *pinfo)
{
static bool acl_group_override(connection_struct *conn,
gid_t prim_gid,
- const char *fname)
+ files_struct *fsp)
{
- SMB_STRUCT_STAT sbuf;
if ((errno != EPERM) && (errno != EACCES)) {
return false;
}
/* user has writeable permission */
- if (lp_dos_filemode(SNUM(conn)) &&
- can_write_to_file(conn, fname, &sbuf)) {
- return true;
+ if (lp_dos_filemode(SNUM(conn))) {
+ SMB_STRUCT_STAT sbuf;
+ int ret;
+
+ if (fsp->posix_open) {
+ ret = SMB_VFS_LSTAT(conn,fsp->fsp_name,&sbuf);
+ } else {
+ ret = SMB_VFS_STAT(conn,fsp->fsp_name,&sbuf);
+ }
+
+ if (ret == -1) {
+ return false;
+ }
+
+ if (can_write_to_file(conn, fsp->fsp_name, &sbuf)) {
+ return true;
+ }
}
return false;
*pacl_set_support = False;
}
- if (acl_group_override(conn, prim_gid, fsp->fsp_name)) {
+ if (acl_group_override(conn, prim_gid, fsp)) {
int sret;
DEBUG(5,("set_canon_ace_list: acl group control on and current user in file %s primary group.\n",
*pacl_set_support = False;
}
- if (acl_group_override(conn, prim_gid, fsp->fsp_name)) {
+ if (acl_group_override(conn, prim_gid, fsp)) {
int sret;
DEBUG(5,("set_canon_ace_list: acl group control on and current user in file %s primary group.\n",
unbecome_root();
}
if (sret == -1) {
- if (acl_group_override(conn, sbuf.st_ex_gid, fsp->fsp_name)) {
+ if (acl_group_override(conn, sbuf.st_ex_gid, fsp)) {
DEBUG(5,("set_nt_acl: acl group control on and "
"current user in file %s primary group. Override delete_def_acl\n",
fsp->fsp_name ));
unbecome_root();
}
if(sret == -1) {
- if (acl_group_override(conn, sbuf.st_ex_gid, fsp->fsp_name)) {
+ if (acl_group_override(conn, sbuf.st_ex_gid, fsp)) {
DEBUG(5,("set_nt_acl: acl group control on and "
"current user in file %s primary group. Override chmod\n",
fsp->fsp_name ));
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)) {