summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
authorTim Prouty <tprouty@samba.org>2009-07-02 13:39:20 -0700
committerTim Prouty <tprouty@samba.org>2009-07-06 15:38:42 -0700
commit3cb0e521e1bdddde972b6fd08fb86f7fe73da8d5 (patch)
tree22777dd2e4d6db9f30b19275a91a9dd3c21a2fbf /source3/smbd
parentf39232a8fb93cfccfe1533ab613867572ff7f848 (diff)
downloadsamba-3cb0e521e1bdddde972b6fd08fb86f7fe73da8d5.tar.gz
samba-3cb0e521e1bdddde972b6fd08fb86f7fe73da8d5.tar.bz2
samba-3cb0e521e1bdddde972b6fd08fb86f7fe73da8d5.zip
s3: Plumb smb_filename through SMB_VFS_NTIMES
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/close.c35
-rw-r--r--source3/smbd/dosmode.c18
-rw-r--r--source3/smbd/reply.c56
-rw-r--r--source3/smbd/trans2.c136
4 files changed, 119 insertions, 126 deletions
diff --git a/source3/smbd/close.c b/source3/smbd/close.c
index 537394c481..a0672f3949 100644
--- a/source3/smbd/close.c
+++ b/source3/smbd/close.c
@@ -499,12 +499,11 @@ void set_close_write_time(struct files_struct *fsp, struct timespec ts)
static NTSTATUS update_write_time_on_close(struct files_struct *fsp)
{
- SMB_STRUCT_STAT sbuf;
+ struct smb_filename *smb_fname = NULL;
struct smb_file_time ft;
NTSTATUS status;
int ret = -1;
- ZERO_STRUCT(sbuf);
ZERO_STRUCT(ft);
if (!fsp->update_write_time_on_close) {
@@ -515,36 +514,44 @@ static NTSTATUS update_write_time_on_close(struct files_struct *fsp)
fsp->close_write_time = timespec_current();
}
+ /* 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)) {
+ goto out;
+ }
+
/* Ensure we have a valid stat struct for the source. */
if (fsp->fh->fd != -1) {
- ret = SMB_VFS_FSTAT(fsp, &sbuf);
+ ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
} else {
if (fsp->posix_open) {
- ret = vfs_lstat_smb_fname(fsp->conn, fsp->fsp_name,
- &sbuf);
+ ret = SMB_VFS_LSTAT(fsp->conn, smb_fname);
} else {
- ret = vfs_stat_smb_fname(fsp->conn, fsp->fsp_name,
- &sbuf);
+ ret = SMB_VFS_STAT(fsp->conn, smb_fname);
}
}
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ status = map_nt_error_from_unix(errno);
+ goto out;
}
- if (!VALID_STAT(sbuf)) {
+ if (!VALID_STAT(smb_fname->st)) {
/* if it doesn't seem to be a real file */
- return NT_STATUS_OK;
+ status = NT_STATUS_OK;
+ goto out;
}
ft.mtime = fsp->close_write_time;
- status = smb_set_file_time(fsp->conn, fsp, fsp->fsp_name,
- &sbuf, &ft, true);
+ status = smb_set_file_time(fsp->conn, fsp, smb_fname, &ft, true);
if (!NT_STATUS_IS_OK(status)) {
- return status;
+ goto out;
}
- return NT_STATUS_OK;
+ out:
+ TALLOC_FREE(smb_fname);
+ return status;
}
static NTSTATUS ntstatus_keeperror(NTSTATUS s1, NTSTATUS s2)
diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c
index 97d788218d..76034db164 100644
--- a/source3/smbd/dosmode.c
+++ b/source3/smbd/dosmode.c
@@ -722,11 +722,9 @@ int file_set_dosmode(connection_struct *conn, struct smb_filename *smb_fname,
than POSIX.
*******************************************************************/
-int file_ntimes(connection_struct *conn, const char *fname,
- struct smb_file_time *ft, const SMB_STRUCT_STAT *psbuf)
+int file_ntimes(connection_struct *conn, const struct smb_filename *smb_fname,
+ struct smb_file_time *ft)
{
- struct smb_filename *smb_fname = NULL;
- NTSTATUS status;
int ret = -1;
errno = 0;
@@ -749,7 +747,7 @@ int file_ntimes(connection_struct *conn, const char *fname,
return 0;
}
- if(SMB_VFS_NTIMES(conn, fname, ft) == 0) {
+ if(SMB_VFS_NTIMES(conn, smb_fname, ft) == 0) {
return 0;
}
@@ -767,21 +765,13 @@ int file_ntimes(connection_struct *conn, const char *fname,
(as DOS does).
*/
- status = create_synthetic_smb_fname_split(talloc_tos(), fname, psbuf,
- &smb_fname);
-
- if (!NT_STATUS_IS_OK(status)) {
- return -1;
- }
-
/* Check if we have write access. */
if (can_write_to_file(conn, smb_fname)) {
/* We are allowed to become root and change the filetime. */
become_root();
- ret = SMB_VFS_NTIMES(conn, fname, ft);
+ ret = SMB_VFS_NTIMES(conn, smb_fname, ft);
unbecome_root();
}
- TALLOC_FREE(smb_fname);
return ret;
}
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 4a5610e5e1..8700146859 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -1179,7 +1179,7 @@ void reply_setatr(struct smb_request *req)
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
&smb_fname,
- &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,
@@ -1190,7 +1190,8 @@ void reply_setatr(struct smb_request *req)
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
@@ -1203,8 +1204,7 @@ void reply_setatr(struct smb_request *req)
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;
@@ -1225,7 +1225,8 @@ void reply_setatr(struct smb_request *req)
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);
@@ -2148,8 +2149,7 @@ void reply_mknew(struct smb_request *req)
}
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;
@@ -2168,9 +2168,10 @@ void reply_mknew(struct smb_request *req)
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);
@@ -7582,9 +7583,9 @@ void reply_readbs(struct smb_request *req)
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);
@@ -7592,18 +7593,23 @@ void reply_setattrE(struct smb_request *req)
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.
@@ -7625,34 +7631,30 @@ void reply_setattrE(struct smb_request *req)
/* 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 = vfs_lstat_smb_fname(conn, fsp->fsp_name, &sbuf);
+ ret = SMB_VFS_LSTAT(conn, smb_fname);
} else {
- ret = vfs_stat_smb_fname(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 "
@@ -7662,7 +7664,7 @@ void reply_setattrE(struct smb_request *req)
(unsigned int)ft.mtime.tv_sec,
(unsigned int)ft.create_time.tv_sec
));
-
+ out:
END_PROFILE(SMBsetattrE);
return;
}
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index e93d313821..e5f8039e6e 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -4935,27 +4935,28 @@ NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
NTSTATUS smb_set_file_time(connection_struct *conn,
files_struct *fsp,
- const char *fname,
- const SMB_STRUCT_STAT *psbuf,
+ const struct smb_filename *smb_fname,
struct smb_file_time *ft,
bool setting_write_time)
{
+ struct smb_filename *smb_fname_base = NULL;
uint32 action =
FILE_NOTIFY_CHANGE_LAST_ACCESS
|FILE_NOTIFY_CHANGE_LAST_WRITE;
+ NTSTATUS status;
- if (!VALID_STAT(*psbuf)) {
+ if (!VALID_STAT(smb_fname->st)) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
/* get some defaults (no modifications) if any info is zero or -1. */
if (null_timespec(ft->atime)) {
- ft->atime= psbuf->st_ex_atime;
+ ft->atime= smb_fname->st.st_ex_atime;
action &= ~FILE_NOTIFY_CHANGE_LAST_ACCESS;
}
if (null_timespec(ft->mtime)) {
- ft->mtime = psbuf->st_ex_mtime;
+ ft->mtime = smb_fname->st.st_ex_mtime;
action &= ~FILE_NOTIFY_CHANGE_LAST_WRITE;
}
@@ -4979,8 +4980,8 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
*/
{
- struct timespec mts = psbuf->st_ex_mtime;
- struct timespec ats = psbuf->st_ex_atime;
+ struct timespec mts = smb_fname->st.st_ex_mtime;
+ struct timespec ats = smb_fname->st.st_ex_atime;
if ((timespec_compare(&ft->atime, &ats) == 0) &&
(timespec_compare(&ft->mtime, &mts) == 0)) {
return NT_STATUS_OK;
@@ -5010,21 +5011,29 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
}
} else {
set_sticky_write_time_path(
- vfs_file_id_from_sbuf(conn, psbuf), ft->mtime);
+ vfs_file_id_from_sbuf(conn, &smb_fname->st),
+ ft->mtime);
}
}
DEBUG(10,("smb_set_file_time: setting utimes to modified values.\n"));
- if (fsp && fsp->base_fsp) {
- fname = fsp->base_fsp->fsp_name;
+ /* Always call ntimes on the base, even if a stream was passed in. */
+ status = create_synthetic_smb_fname(talloc_tos(), smb_fname->base_name,
+ NULL, &smb_fname->st,
+ &smb_fname_base);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
}
- if(file_ntimes(conn, fname, ft, psbuf)!=0) {
+ if(file_ntimes(conn, smb_fname_base, ft)!=0) {
+ TALLOC_FREE(smb_fname_base);
return map_nt_error_from_unix(errno);
}
- notify_fname(conn, NOTIFY_ACTION_MODIFIED, action, fname);
+ TALLOC_FREE(smb_fname_base);
+ notify_fname(conn, NOTIFY_ACTION_MODIFIED, action,
+ smb_fname->base_name);
return NT_STATUS_OK;
}
@@ -5033,25 +5042,26 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
****************************************************************************/
static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
- files_struct *fsp,
- const char *fname,
- SMB_STRUCT_STAT *psbuf,
- uint32 dosmode)
+ const struct smb_filename *smb_fname,
+ uint32 dosmode)
{
- if (!VALID_STAT(*psbuf)) {
+ struct smb_filename *smb_fname_base = NULL;
+ NTSTATUS status;
+
+ if (!VALID_STAT(smb_fname->st)) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
- if (fsp) {
- if (fsp->base_fsp) {
- fname = fsp->base_fsp->fsp_name;
- } else {
- fname = fsp->fsp_name;
- }
+ /* Always operate on the base_name, even if a stream was passed in. */
+ status = create_synthetic_smb_fname(talloc_tos(), smb_fname->base_name,
+ NULL, &smb_fname->st,
+ &smb_fname_base);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
}
if (dosmode) {
- if (S_ISDIR(psbuf->st_ex_mode)) {
+ if (S_ISDIR(smb_fname_base->st.st_ex_mode)) {
dosmode |= aDIR;
} else {
dosmode &= ~aDIR;
@@ -5061,29 +5071,27 @@ static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
DEBUG(6,("smb_set_file_dosmode: dosmode: 0x%x\n", (unsigned int)dosmode));
/* check the mode isn't different, before changing it */
- if ((dosmode != 0) && (dosmode != dos_mode(conn, fname, psbuf))) {
- struct smb_filename *smb_fname = NULL;
- NTSTATUS status;
-
- status = create_synthetic_smb_fname_split(talloc_tos(), fname,
- psbuf, &smb_fname);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
- DEBUG(10,("smb_set_file_dosmode: file %s : setting dos mode 0x%x\n",
- fname, (unsigned int)dosmode ));
-
- if(file_set_dosmode(conn, smb_fname, dosmode, NULL, false)) {
- DEBUG(2,("smb_set_file_dosmode: file_set_dosmode of %s failed (%s)\n",
- fname, strerror(errno)));
- TALLOC_FREE(smb_fname);
- return map_nt_error_from_unix(errno);
+ if ((dosmode != 0) && (dosmode != dos_mode(conn,
+ smb_fname_base->base_name,
+ &smb_fname_base->st))) {
+ DEBUG(10,("smb_set_file_dosmode: file %s : setting dos mode "
+ "0x%x\n", smb_fname_str_dbg(smb_fname_base),
+ (unsigned int)dosmode));
+
+ if(file_set_dosmode(conn, smb_fname_base, dosmode, NULL,
+ false)) {
+ DEBUG(2,("smb_set_file_dosmode: file_set_dosmode of "
+ "%s failed (%s)\n",
+ smb_fname_str_dbg(smb_fname_base),
+ strerror(errno)));
+ status = map_nt_error_from_unix(errno);
+ goto out;
}
- *psbuf = smb_fname->st;
- TALLOC_FREE(smb_fname);
}
- return NT_STATUS_OK;
+ status = NT_STATUS_OK;
+ out:
+ TALLOC_FREE(smb_fname_base);
+ return status;
}
/****************************************************************************
@@ -5783,8 +5791,7 @@ static NTSTATUS smb_set_info_standard(connection_struct *conn,
const char *pdata,
int total_data,
files_struct *fsp,
- const char *fname,
- const SMB_STRUCT_STAT *psbuf)
+ const struct smb_filename *smb_fname)
{
struct smb_file_time ft;
ZERO_STRUCT(ft);
@@ -5803,14 +5810,9 @@ static NTSTATUS smb_set_info_standard(connection_struct *conn,
ft.mtime = interpret_long_date(pdata + 16);
DEBUG(10,("smb_set_info_standard: file %s\n",
- fname ? fname : fsp->fsp_name ));
+ smb_fname_str_dbg(smb_fname)));
- return smb_set_file_time(conn,
- fsp,
- fname,
- psbuf,
- &ft,
- true);
+ return smb_set_file_time(conn, fsp, smb_fname, &ft, true);
}
/****************************************************************************
@@ -5821,8 +5823,7 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
const char *pdata,
int total_data,
files_struct *fsp,
- const char *fname,
- SMB_STRUCT_STAT *psbuf)
+ const struct smb_filename *smb_fname)
{
/* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */
struct timespec write_time;
@@ -5840,7 +5841,7 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
/* Set the attributes */
dosmode = IVAL(pdata,32);
- status = smb_set_file_dosmode(conn, fsp, fname, psbuf, dosmode);
+ status = smb_set_file_dosmode(conn, smb_fname, dosmode);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
@@ -5872,15 +5873,11 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
}
}
- DEBUG(10,("smb_set_file_basic_info: file %s\n",
- fname ? fname : fsp->fsp_name ));
+ DEBUG(10, ("smb_set_file_basic_info: file %s\n",
+ smb_fname_str_dbg(smb_fname)));
- return smb_set_file_time(conn,
- fsp,
- fname,
- psbuf,
- &ft,
- setting_write_time);
+ return smb_set_file_time(conn, fsp, smb_fname, &ft,
+ setting_write_time);
}
/****************************************************************************
@@ -6353,8 +6350,7 @@ static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
status = smb_set_file_time(conn,
fsp,
- smb_fname->base_name,
- &sbuf,
+ smb_fname,
&ft,
false);
if (modify_mtime) {
@@ -7072,8 +7068,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
pdata,
total_data,
fsp,
- fname,
- &sbuf);
+ smb_fname);
break;
}
@@ -7094,8 +7089,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
pdata,
total_data,
fsp,
- fname,
- &sbuf);
+ smb_fname);
break;
}