*/
#include "includes.h"
+#include "smbd/globals.h"
-/* look in server.c for some explanation of these variables */
extern enum protocol_types Protocol;
-extern int max_recv;
-extern uint32 global_client_caps;
-
-extern bool global_encrypted_passwords_negotiated;
/****************************************************************************
Ensure we check the path in *exactly* the same way as W2K for a findfirst/findnext
}
}
- if (!stream_started && *s == ':') {
+ if (!posix_path && !stream_started && *s == ':') {
if (*p_last_component_contains_wcard) {
return NT_STATUS_OBJECT_NAME_INVALID;
}
- /* stream names allow more characters than file names */
+ /* Stream names allow more characters than file names.
+ We're overloading posix_path here to allow a wider
+ range of characters. If stream_started is true this
+ is still a Windows path even if posix_path is true.
+ JRA.
+ */
stream_started = true;
start_of_name_component = false;
posix_path = true;
return False;
}
+static bool netbios_session_retarget(const char *name, int name_type)
+{
+ char *trim_name;
+ char *trim_name_type;
+ const char *retarget_parm;
+ char *retarget;
+ char *p;
+ int retarget_type = 0x20;
+ int retarget_port = 139;
+ struct sockaddr_storage retarget_addr;
+ struct sockaddr_in *in_addr;
+ bool ret = false;
+ uint8_t outbuf[10];
+
+ if (get_socket_port(smbd_server_fd()) != 139) {
+ return false;
+ }
+
+ trim_name = talloc_strdup(talloc_tos(), name);
+ if (trim_name == NULL) {
+ goto fail;
+ }
+ trim_char(trim_name, ' ', ' ');
+
+ trim_name_type = talloc_asprintf(trim_name, "%s#%2.2x", trim_name,
+ name_type);
+ if (trim_name_type == NULL) {
+ goto fail;
+ }
+
+ retarget_parm = lp_parm_const_string(-1, "netbios retarget",
+ trim_name_type, NULL);
+ if (retarget_parm == NULL) {
+ retarget_parm = lp_parm_const_string(-1, "netbios retarget",
+ trim_name, NULL);
+ }
+ if (retarget_parm == NULL) {
+ goto fail;
+ }
+
+ retarget = talloc_strdup(trim_name, retarget_parm);
+ if (retarget == NULL) {
+ goto fail;
+ }
+
+ DEBUG(10, ("retargeting %s to %s\n", trim_name_type, retarget));
+
+ p = strchr(retarget, ':');
+ if (p != NULL) {
+ *p++ = '\0';
+ retarget_port = atoi(p);
+ }
+
+ p = strchr_m(retarget, '#');
+ if (p != NULL) {
+ *p++ = '\0';
+ sscanf(p, "%x", &retarget_type);
+ }
+
+ ret = resolve_name(retarget, &retarget_addr, retarget_type);
+ if (!ret) {
+ DEBUG(10, ("could not resolve %s\n", retarget));
+ goto fail;
+ }
+
+ if (retarget_addr.ss_family != AF_INET) {
+ DEBUG(10, ("Retarget target not an IPv4 addr\n"));
+ goto fail;
+ }
+
+ in_addr = (struct sockaddr_in *)(void *)&retarget_addr;
+
+ _smb_setlen(outbuf, 6);
+ SCVAL(outbuf, 0, 0x84);
+ *(uint32_t *)(outbuf+4) = in_addr->sin_addr.s_addr;
+ *(uint16_t *)(outbuf+8) = htons(retarget_port);
+
+ if (!srv_send_smb(smbd_server_fd(), (char *)outbuf, false, 0, false,
+ NULL)) {
+ exit_server_cleanly("netbios_session_regarget: srv_send_smb "
+ "failed.");
+ }
+
+ ret = true;
+ fail:
+ TALLOC_FREE(trim_name);
+ return ret;
+}
+
/****************************************************************************
Reply to a (netbios-level) special message.
****************************************************************************/
int msg_type = CVAL(inbuf,0);
int msg_flags = CVAL(inbuf,1);
fstring name1,name2;
- char name_type = 0;
+ char name_type1, name_type2;
/*
* We only really use 4 bytes of the outbuf, but for the smb_setlen
*/
char outbuf[smb_size];
- static bool already_got_session = False;
-
*name1 = *name2 = 0;
memset(outbuf, '\0', sizeof(outbuf));
DEBUG(0,("Invalid name length in session request\n"));
return;
}
- name_extract(inbuf,4,name1);
- name_type = name_extract(inbuf,4 + name_len(inbuf + 4),name2);
- DEBUG(2,("netbios connect: name1=%s name2=%s\n",
- name1,name2));
+ name_type1 = name_extract(inbuf,4,name1);
+ name_type2 = name_extract(inbuf,4 + name_len(inbuf + 4),name2);
+ DEBUG(2,("netbios connect: name1=%s0x%x name2=%s0x%x\n",
+ name1, name_type1, name2, name_type2));
+
+ if (netbios_session_retarget(name1, name_type1)) {
+ exit_server_cleanly("retargeted client");
+ }
set_local_machine_name(name1, True);
set_remote_machine_name(name2, True);
DEBUG(2,("netbios connect: local=%s remote=%s, name type = %x\n",
get_local_machine_name(), get_remote_machine_name(),
- name_type));
+ name_type2));
- if (name_type == 'R') {
+ if (name_type2 == 'R') {
/* We are being asked for a pathworks session ---
no thanks! */
SCVAL(outbuf, 0,0x83);
DEBUG(5,("init msg_type=0x%x msg_flags=0x%x\n",
msg_type, msg_flags));
- srv_send_smb(smbd_server_fd(), outbuf, false);
+ srv_send_smb(smbd_server_fd(), outbuf, false, 0, false, NULL);
return;
}
void reply_checkpath(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ struct smb_filename *smb_fname = NULL;
char *name = NULL;
- SMB_STRUCT_STAT sbuf;
NTSTATUS status;
TALLOC_CTX *ctx = talloc_tos();
DEBUG(3,("reply_checkpath %s mode=%d\n", name, (int)SVAL(req->vwv+0, 0)));
- status = unix_convert(ctx, conn, name, False, &name, NULL, &sbuf);
+ 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;
}
goto path_err;
}
- if (!VALID_STAT(sbuf) && (SMB_VFS_STAT(conn,name,&sbuf) != 0)) {
+ 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)));
status = map_nt_error_from_unix(errno);
goto path_err;
}
- if (!S_ISDIR(sbuf.st_mode)) {
+ if (!S_ISDIR(smb_fname->st.st_mode)) {
reply_botherror(req, NT_STATUS_NOT_A_DIRECTORY,
ERRDOS, ERRbadpath);
- END_PROFILE(SMBcheckpath);
- return;
+ goto out;
}
reply_outbuf(req, 0, 0);
-
+ out:
+ TALLOC_FREE(smb_fname);
END_PROFILE(SMBcheckpath);
return;
- path_err:
+ path_err:
+
+ TALLOC_FREE(smb_fname);
END_PROFILE(SMBcheckpath);
void reply_getatr(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ struct smb_filename *smb_fname = NULL;
char *fname = NULL;
- SMB_STRUCT_STAT sbuf;
int mode=0;
SMB_OFF_T size=0;
time_t mtime=0;
p += srvstr_get_path_req(ctx, req, &fname, p, STR_TERMINATE, &status);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBgetatr);
- return;
+ goto out;
}
status = resolve_dfspath(ctx, conn,
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
ERRSRV, ERRbadpath);
- END_PROFILE(SMBgetatr);
- return;
+ goto out;
}
reply_nterror(req, status);
- END_PROFILE(SMBgetatr);
- return;
+ goto out;
}
/* dos smetimes asks for a stat of "" - it returns a "hidden directory"
size = 0;
mtime = 0;
} else {
- status = unix_convert(ctx, conn, fname, False, &fname, NULL,&sbuf);
+ status = unix_convert(ctx, conn, fname, &smb_fname, 0);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBgetatr);
- return;
+ 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)) {
DEBUG(3,("reply_getatr: check_name of %s failed (%s)\n",fname,nt_errstr(status)));
reply_nterror(req, status);
- END_PROFILE(SMBgetatr);
- return;
+ goto out;
}
- if (!VALID_STAT(sbuf) && (SMB_VFS_STAT(conn,fname,&sbuf) != 0)) {
+ 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)));
reply_unixerror(req, ERRDOS,ERRbadfile);
- END_PROFILE(SMBgetatr);
- return;
+ goto out;
}
- mode = dos_mode(conn,fname,&sbuf);
- size = sbuf.st_size;
- mtime = sbuf.st_mtime;
+ mode = dos_mode(conn, fname, &smb_fname->st);
+ size = smb_fname->st.st_size;
+ mtime = smb_fname->st.st_mtime;
if (mode & aDIR) {
size = 0;
}
DEBUG(3,("reply_getatr: name=%s mode=%d size=%u\n", fname, mode, (unsigned int)size ) );
+ out:
+ TALLOC_FREE(smb_fname);
END_PROFILE(SMBgetatr);
return;
}
void reply_setatr(struct smb_request *req)
{
- struct timespec ts[2];
+ struct smb_file_time ft;
connection_struct *conn = req->conn;
+ struct smb_filename *smb_fname = NULL;
char *fname = NULL;
int mode;
time_t mtime;
- SMB_STRUCT_STAT sbuf;
const char *p;
NTSTATUS status;
TALLOC_CTX *ctx = talloc_tos();
START_PROFILE(SMBsetatr);
- ZERO_STRUCT(ts);
+ ZERO_STRUCT(ft);
if (req->wct < 2) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ goto out;
}
p = (const char *)req->buf + 1;
p += srvstr_get_path_req(ctx, req, &fname, p, STR_TERMINATE, &status);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBsetatr);
- return;
+ goto out;
}
status = resolve_dfspath(ctx, conn,
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
ERRSRV, ERRbadpath);
- END_PROFILE(SMBsetatr);
- return;
+ goto out;
}
reply_nterror(req, status);
- END_PROFILE(SMBsetatr);
- return;
+ goto out;
}
- status = unix_convert(ctx, conn, fname, False, &fname, NULL, &sbuf);
+ status = unix_convert(ctx, conn, fname, &smb_fname, 0);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBsetatr);
- return;
+ 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);
- END_PROFILE(SMBsetatr);
- return;
+ goto out;
}
if (fname[0] == '.' && fname[1] == '\0') {
* condition. Might be moved to somewhere else later -- vl
*/
reply_nterror(req, NT_STATUS_ACCESS_DENIED);
- END_PROFILE(SMBsetatr);
- return;
+ goto out;
}
mode = SVAL(req->vwv+0, 0);
mtime = srv_make_unix_date3(req->vwv+1);
- ts[1] = convert_time_t_to_timespec(mtime);
+ ft.mtime = convert_time_t_to_timespec(mtime);
status = smb_set_file_time(conn, NULL, fname,
- &sbuf, ts, true);
+ &smb_fname->st, &ft, true);
if (!NT_STATUS_IS_OK(status)) {
reply_unixerror(req, ERRDOS, ERRnoaccess);
- END_PROFILE(SMBsetatr);
- return;
+ goto out;
}
if (mode != FILE_ATTRIBUTE_NORMAL) {
- if (VALID_STAT_OF_DIR(sbuf))
+ if (VALID_STAT_OF_DIR(smb_fname->st))
mode |= aDIR;
else
mode &= ~aDIR;
- if (file_set_dosmode(conn,fname,mode,&sbuf,NULL,false) != 0) {
+ if (file_set_dosmode(conn, fname, mode, &smb_fname->st, NULL,
+ false) != 0) {
reply_unixerror(req, ERRDOS, ERRnoaccess);
- END_PROFILE(SMBsetatr);
- return;
+ goto out;
}
}
reply_outbuf(req, 0, 0);
DEBUG( 3, ( "setatr name=%s mode=%d\n", fname, mode ) );
-
+ out:
+ TALLOC_FREE(smb_fname);
END_PROFILE(SMBsetatr);
return;
}
/* dirtype &= ~aDIR; */
if (status_len == 0) {
- SMB_STRUCT_STAT sbuf;
+ struct smb_filename *smb_fname = NULL;
- nt_status = unix_convert(ctx, conn, path, True,
- &directory, NULL, &sbuf);
+ nt_status = unix_convert(ctx, conn, path, &smb_fname,
+ UCF_ALLOW_WCARD_LCOMP);
+ if (!NT_STATUS_IS_OK(nt_status)) {
+ reply_nterror(req, nt_status);
+ END_PROFILE(SMBsearch);
+ return;
+ }
+
+ nt_status = get_full_smb_filename(ctx, smb_fname, &directory);
+ TALLOC_FREE(smb_fname);
if (!NT_STATUS_IS_OK(nt_status)) {
reply_nterror(req, nt_status);
END_PROFILE(SMBsearch);
DEBUG(4,("dptr_num is %d\n",dptr_num));
+ /* Initialize per SMBsearch/SMBffirst/SMBfunique operation data */
+ dptr_init_search_op(conn->dirptr);
+
if ((dirtype&0x1F) == aVOLID) {
char buf[DIR_STRUCT_SIZE];
memcpy(buf,status,21);
START_PROFILE(SMBopen);
+ SET_STAT_INVALID(sbuf);
+
if (req->wct < 2) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
END_PROFILE(SMBopen);
return;
}
+ SET_STAT_INVALID(sbuf);
+
open_flags = SVAL(req->vwv+2, 0);
deny_mode = SVAL(req->vwv+3, 0);
smb_attr = SVAL(req->vwv+5, 0);
END_PROFILE(SMBopenX);
return;
}
- sbuf.st_size = get_allocation_size(conn,fsp,&sbuf);
+ sbuf.st_size = SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&sbuf);
}
fattr = dos_mode(conn,fsp->fsp_name,&sbuf);
connection_struct *conn = req->conn;
char *fname = NULL;
uint32 fattr = 0;
- struct timespec ts[2];
+ struct smb_file_time ft;
files_struct *fsp;
int oplock_request = 0;
SMB_STRUCT_STAT sbuf;
TALLOC_CTX *ctx = talloc_tos();
START_PROFILE(SMBcreate);
+ ZERO_STRUCT(ft);
+ SET_STAT_INVALID(sbuf);
if (req->wct < 3) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
fattr = SVAL(req->vwv+0, 0);
oplock_request = CORE_OPLOCK_REQUEST(req->inbuf);
- ts[1] = convert_time_t_to_timespec(srv_make_unix_date3(req->vwv+1));
- /* mtime. */
+ /* mtime. */
+ ft.mtime = convert_time_t_to_timespec(srv_make_unix_date3(req->vwv+1));
srvstr_get_path_req(ctx, req, &fname, (const char *)req->buf + 1,
STR_TERMINATE, &status);
return;
}
- ts[0] = get_atimespec(&sbuf); /* atime. */
- status = smb_set_file_time(conn, fsp, fsp->fsp_name, &sbuf, ts, true);
+ ft.atime = get_atimespec(&sbuf); /* atime. */
+ status = smb_set_file_time(conn, fsp, fsp->fsp_name, &sbuf, &ft, true);
if (!NT_STATUS_IS_OK(status)) {
END_PROFILE(SMBcreate);
reply_openerror(req, status);
void reply_ctemp(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ struct smb_filename *smb_fname = NULL;
char *fname = NULL;
uint32 fattr;
files_struct *fsp;
int oplock_request;
int tmpfd;
- SMB_STRUCT_STAT sbuf;
char *s;
NTSTATUS status;
TALLOC_CTX *ctx = talloc_tos();
if (req->wct < 3) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- END_PROFILE(SMBctemp);
- return;
+ goto out;
}
fattr = SVAL(req->vwv+0, 0);
STR_TERMINATE, &status);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBctemp);
- return;
+ goto out;
}
if (*fname) {
fname = talloc_asprintf(ctx,
if (!fname) {
reply_nterror(req, NT_STATUS_NO_MEMORY);
- END_PROFILE(SMBctemp);
- return;
+ goto out;
}
status = resolve_dfspath(ctx, conn,
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
ERRSRV, ERRbadpath);
- END_PROFILE(SMBctemp);
- return;
+ goto out;
}
reply_nterror(req, status);
- END_PROFILE(SMBctemp);
- return;
+ goto out;
}
- status = unix_convert(ctx, conn, fname, False, &fname, NULL, &sbuf);
+ status = unix_convert(ctx, conn, fname, &smb_fname, 0);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBctemp);
- return;
+ 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);
- END_PROFILE(SMBctemp);
- return;
+ goto out;
}
- tmpfd = smb_mkstemp(fname);
+ tmpfd = mkstemp(fname);
if (tmpfd == -1) {
reply_unixerror(req, ERRDOS, ERRnoaccess);
- END_PROFILE(SMBctemp);
- return;
+ goto out;
}
- SMB_VFS_STAT(conn,fname,&sbuf);
+ SET_STAT_INVALID(smb_fname->st);
+ SMB_VFS_STAT(conn, fname, &smb_fname->st);
/* We should fail if file does not exist. */
status = SMB_VFS_CREATE_FILE(
NULL, /* ea_list */
&fsp, /* result */
NULL, /* pinfo */
- &sbuf); /* psbuf */
+ &smb_fname->st); /* psbuf */
- /* close fd from smb_mkstemp() */
+ /* close fd from mkstemp() */
close(tmpfd);
if (!NT_STATUS_IS_OK(status)) {
if (open_was_deferred(req->mid)) {
/* We have re-scheduled this call. */
- END_PROFILE(SMBctemp);
- return;
+ goto out;
}
reply_openerror(req, status);
- END_PROFILE(SMBctemp);
- return;
+ goto out;
}
reply_outbuf(req, 1, 0);
if (message_push_string(&req->outbuf, s, STR_ASCII|STR_TERMINATE)
== -1) {
reply_nterror(req, NT_STATUS_NO_MEMORY);
- END_PROFILE(SMBctemp);
- return;
+ goto out;
}
if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
DEBUG( 2, ( "reply_ctemp: created temp file %s\n", fsp->fsp_name ) );
DEBUG( 3, ( "reply_ctemp %s fd=%d umode=0%o\n", fsp->fsp_name,
- fsp->fh->fd, (unsigned int)sbuf.st_mode ) );
-
+ fsp->fh->fd, (unsigned int)smb_fname->st.st_mode));
+ out:
+ TALLOC_FREE(smb_fname);
END_PROFILE(SMBctemp);
return;
}
}
if (S_ISDIR(pst->st_mode)) {
+ if (fsp->posix_open) {
+ return NT_STATUS_OK;
+ }
+
+ /* If no pathnames are open below this
+ directory, allow the rename. */
+
+ if (file_find_subpath(fsp)) {
+ return NT_STATUS_ACCESS_DENIED;
+ }
return NT_STATUS_OK;
}
NTSTATUS unlink_internals(connection_struct *conn, struct smb_request *req,
uint32 dirtype, const char *name_in, bool has_wild)
{
+ struct smb_filename *smb_fname = NULL;
const char *directory = NULL;
char *mask = NULL;
char *name = NULL;
char *p = NULL;
int count=0;
NTSTATUS status = NT_STATUS_OK;
- SMB_STRUCT_STAT sbuf;
+ SMB_STRUCT_STAT st;
TALLOC_CTX *ctx = talloc_tos();
- status = unix_convert(ctx, conn, name_in, has_wild, &name, NULL, &sbuf);
+ status = unix_convert(ctx, conn, name_in, &smb_fname,
+ has_wild ? UCF_ALLOW_WCARD_LCOMP : 0);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
+ status = get_full_smb_filename(ctx, smb_fname, &name);
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(smb_fname);
+ return status;
+ }
+
p = strrchr_m(name,'/');
if (!p) {
directory = talloc_strdup(ctx, ".");
if (!directory) {
+ TALLOC_FREE(smb_fname);
return NT_STATUS_NO_MEMORY;
}
mask = name;
* Tine Smukavec <valentin.smukavec@hermes.si>.
*/
- if (!VALID_STAT(sbuf) && mangle_is_mangled(mask,conn->params)) {
+ if (!VALID_STAT(smb_fname->st) && mangle_is_mangled(mask,conn->params)) {
char *new_mask = NULL;
mangle_lookup_name_from_8_3(ctx,
mask,
mask = new_mask;
}
}
+ TALLOC_FREE(smb_fname);
if (!has_wild) {
directory = talloc_asprintf(ctx,
status = NT_STATUS_NO_SUCH_FILE;
- while ((dname = ReadDirName(dir_hnd, &offset))) {
- SMB_STRUCT_STAT st;
+ while ((dname = ReadDirName(dir_hnd, &offset, &st))) {
char *fname = NULL;
- if (!is_visible_file(conn, directory, dname, &st, True)) {
+ if (!is_visible_file(conn, directory, dname, &st,
+ true))
+ {
continue;
}
/* If we had a short read, fill with zeros. */
if (ret < cur_read) {
- memset(buf, '\0', cur_read - ret);
+ memset(buf + ret, '\0', cur_read - ret);
}
if (write_data(smbd_server_fd(),buf,cur_read) != cur_read) {
return (ssize_t)nread;
}
+#if defined(WITH_SENDFILE)
+/****************************************************************************
+ Deal with the case of sendfile reading less bytes from the file than
+ requested. Fill with zeros (all we can do).
+****************************************************************************/
+
+static void sendfile_short_send(files_struct *fsp,
+ ssize_t nread,
+ size_t headersize,
+ size_t smb_maxcnt)
+{
+#define SHORT_SEND_BUFSIZE 1024
+ if (nread < headersize) {
+ DEBUG(0,("sendfile_short_send: sendfile failed to send "
+ "header for file %s (%s). Terminating\n",
+ fsp->fsp_name, strerror(errno) ));
+ exit_server_cleanly("sendfile_short_send failed");
+ }
+
+ nread -= headersize;
+
+ if (nread < smb_maxcnt) {
+ char *buf = SMB_CALLOC_ARRAY(char, SHORT_SEND_BUFSIZE);
+ if (!buf) {
+ exit_server_cleanly("sendfile_short_send: "
+ "malloc failed");
+ }
+
+ DEBUG(0,("sendfile_short_send: filling truncated file %s "
+ "with zeros !\n", fsp->fsp_name));
+
+ while (nread < smb_maxcnt) {
+ /*
+ * We asked for the real file size and told sendfile
+ * to not go beyond the end of the file. But it can
+ * happen that in between our fstat call and the
+ * sendfile call the file was truncated. This is very
+ * bad because we have already announced the larger
+ * number of bytes to the client.
+ *
+ * The best we can do now is to send 0-bytes, just as
+ * a read from a hole in a sparse file would do.
+ *
+ * This should happen rarely enough that I don't care
+ * about efficiency here :-)
+ */
+ size_t to_write;
+
+ to_write = MIN(SHORT_SEND_BUFSIZE, smb_maxcnt - nread);
+ if (write_data(smbd_server_fd(), buf, to_write) != to_write) {
+ exit_server_cleanly("sendfile_short_send: "
+ "write_data failed");
+ }
+ nread += to_write;
+ }
+ SAFE_FREE(buf);
+ }
+}
+#endif /* defined WITH_SENDFILE */
+
/****************************************************************************
Return a readbraw error (4 bytes of zero).
****************************************************************************/
Use sendfile in readbraw.
****************************************************************************/
-void send_file_readbraw(connection_struct *conn,
- files_struct *fsp,
- SMB_OFF_T startpos,
- size_t nread,
- ssize_t mincount)
+static void send_file_readbraw(connection_struct *conn,
+ struct smb_request *req,
+ files_struct *fsp,
+ SMB_OFF_T startpos,
+ size_t nread,
+ ssize_t mincount)
{
char *outbuf = NULL;
ssize_t ret=0;
* reply_readbraw has already checked the length.
*/
- if ( (chain_size == 0) && (nread > 0) && (fsp->base_fsp == NULL) &&
- (fsp->wcp == NULL) && lp_use_sendfile(SNUM(conn)) ) {
+ if ( !req_is_in_chain(req) && (nread > 0) && (fsp->base_fsp == NULL) &&
+ (fsp->wcp == NULL) &&
+ lp_use_sendfile(SNUM(conn), smbd_server_conn->signing_state) ) {
+ ssize_t sendfile_read = -1;
char header[4];
DATA_BLOB header_blob;
_smb_setlen(header,nread);
header_blob = data_blob_const(header, 4);
- if (SMB_VFS_SENDFILE(smbd_server_fd(), fsp,
- &header_blob, startpos, nread) == -1) {
+ if ((sendfile_read = SMB_VFS_SENDFILE(smbd_server_fd(), fsp,
+ &header_blob, startpos, nread)) == -1) {
/* Returning ENOSYS means no data at all was sent.
* Do this as a normal read. */
if (errno == ENOSYS) {
DEBUG(0,("send_file_readbraw: sendfile failed for file %s (%s). Terminating\n",
fsp->fsp_name, strerror(errno) ));
exit_server_cleanly("send_file_readbraw sendfile failed");
+ } else if (sendfile_read == 0) {
+ /*
+ * Some sendfile implementations return 0 to indicate
+ * that there was a short read, but nothing was
+ * actually written to the socket. In this case,
+ * fallback to the normal read path so the header gets
+ * the correct byte count.
+ */
+ DEBUG(3, ("send_file_readbraw: sendfile sent zero "
+ "bytes falling back to the normal read: "
+ "%s\n", fsp->fsp_name));
+ goto normal_readbraw;
}
+ /* Deal with possible short send. */
+ if (sendfile_read != 4+nread) {
+ sendfile_short_send(fsp, sendfile_read, 4, nread);
+ }
return;
}
-#endif
normal_readbraw:
+#endif
outbuf = TALLOC_ARRAY(NULL, char, nread+4);
if (!outbuf) {
size_t nread = 0;
SMB_OFF_T startpos;
files_struct *fsp;
+ struct lock_struct lock;
SMB_STRUCT_STAT st;
SMB_OFF_T size = 0;
START_PROFILE(SMBreadbraw);
- if (srv_is_signing_active() || is_encrypted_packet(req->inbuf)) {
+ if (srv_is_signing_active(smbd_server_conn) ||
+ is_encrypted_packet(req->inbuf)) {
exit_server_cleanly("reply_readbraw: SMB signing/sealing is active - "
"raw reads/writes are disallowed.");
}
/* ensure we don't overrun the packet size */
maxcount = MIN(65535,maxcount);
- if (is_locked(fsp,(uint32)req->smbpid,
- (uint64_t)maxcount,
- (uint64_t)startpos,
- READ_LOCK)) {
+ init_strict_lock_struct(fsp, (uint32)req->smbpid,
+ (uint64_t)startpos, (uint64_t)maxcount, READ_LOCK,
+ &lock);
+
+ if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
reply_readbraw_error();
END_PROFILE(SMBreadbraw);
return;
(unsigned long)mincount,
(unsigned long)nread ) );
- send_file_readbraw(conn, fsp, startpos, nread, mincount);
+ send_file_readbraw(conn, req, fsp, startpos, nread, mincount);
DEBUG(5,("reply_readbraw finished\n"));
+
+ SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+
END_PROFILE(SMBreadbraw);
+ return;
}
#undef DBGC_CLASS
return;
}
- release_level_2_oplocks_on_change(fsp);
-
numtoread = SVAL(req->vwv+1, 0);
startpos = IVAL_TO_SMB_OFF_T(req->vwv+2, 0);
WINDOWS_LOCK,
False, /* Non-blocking lock. */
&status,
+ NULL,
NULL);
TALLOC_FREE(br_lck);
SMB_OFF_T startpos;
int outsize = 0;
files_struct *fsp;
+ struct lock_struct lock;
START_PROFILE(SMBread);
data = smb_buf(req->outbuf) + 3;
- if (is_locked(fsp, (uint32)req->smbpid, (uint64_t)numtoread,
- (uint64_t)startpos, READ_LOCK)) {
+ init_strict_lock_struct(fsp, (uint32)req->smbpid,
+ (uint64_t)startpos, (uint64_t)numtoread, READ_LOCK,
+ &lock);
+
+ if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
reply_doserror(req, ERRDOS,ERRlock);
END_PROFILE(SMBread);
return;
if (nread < 0) {
reply_unixerror(req, ERRDOS,ERRnoaccess);
- END_PROFILE(SMBread);
- return;
+ goto strict_unlock;
}
srv_set_message((char *)req->outbuf, 5, nread+3, False);
DEBUG( 3, ( "read fnum=%d num=%d nread=%d\n",
fsp->fnum, (int)numtoread, (int)nread ) );
+strict_unlock:
+ SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+
END_PROFILE(SMBread);
return;
}
Setup readX header.
****************************************************************************/
-static int setup_readX_header(char *outbuf, size_t smb_maxcnt)
+static int setup_readX_header(struct smb_request *req, char *outbuf,
+ size_t smb_maxcnt)
{
int outsize;
char *data;
SCVAL(outbuf,smb_vwv0,0xFF);
SSVAL(outbuf,smb_vwv2,0xFFFF); /* Remaining - must be -1. */
SSVAL(outbuf,smb_vwv5,smb_maxcnt);
- SSVAL(outbuf,smb_vwv6,smb_offset(data,outbuf));
+ SSVAL(outbuf,smb_vwv6,
+ req_wct_ofs(req)
+ + 1 /* the wct field */
+ + 12 * sizeof(uint16_t) /* vwv */
+ + 2); /* the buflen field */
SSVAL(outbuf,smb_vwv7,(smb_maxcnt >> 16));
- SSVAL(smb_buf(outbuf),-2,smb_maxcnt);
+ SSVAL(outbuf,smb_vwv11,smb_maxcnt);
/* Reset the outgoing length, set_message truncates at 0x1FFFF. */
_smb_setlen_large(outbuf,(smb_size + 12*2 + smb_maxcnt - 4));
return outsize;
{
SMB_STRUCT_STAT sbuf;
ssize_t nread = -1;
+ struct lock_struct lock;
if(SMB_VFS_FSTAT(fsp, &sbuf) == -1) {
reply_unixerror(req, ERRDOS, ERRnoaccess);
return;
}
- if (startpos > sbuf.st_size) {
- smb_maxcnt = 0;
- } else if (smb_maxcnt > (sbuf.st_size - startpos)) {
- smb_maxcnt = (sbuf.st_size - startpos);
+ init_strict_lock_struct(fsp, (uint32)req->smbpid,
+ (uint64_t)startpos, (uint64_t)smb_maxcnt, READ_LOCK,
+ &lock);
+
+ if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
+ reply_doserror(req, ERRDOS, ERRlock);
+ return;
}
- if (smb_maxcnt == 0) {
- goto normal_read;
+ if (!S_ISREG(sbuf.st_mode) || (startpos > sbuf.st_size)
+ || (smb_maxcnt > (sbuf.st_size - startpos))) {
+ /*
+ * We already know that we would do a short read, so don't
+ * try the sendfile() path.
+ */
+ goto nosendfile_read;
}
#if defined(WITH_SENDFILE)
* on a train in Germany :-). JRA.
*/
- if ((chain_size == 0) && (CVAL(req->vwv+0, 0) == 0xFF) &&
+ if (!req_is_in_chain(req) &&
!is_encrypted_packet(req->inbuf) && (fsp->base_fsp == NULL) &&
- lp_use_sendfile(SNUM(conn)) && (fsp->wcp == NULL) ) {
+ (fsp->wcp == NULL) &&
+ lp_use_sendfile(SNUM(conn), smbd_server_conn->signing_state) ) {
uint8 headerbuf[smb_size + 12 * 2];
DATA_BLOB header;
header = data_blob_const(headerbuf, sizeof(headerbuf));
construct_reply_common_req(req, (char *)headerbuf);
- setup_readX_header((char *)headerbuf, smb_maxcnt);
+ setup_readX_header(req, (char *)headerbuf, smb_maxcnt);
if ((nread = SMB_VFS_SENDFILE(smbd_server_fd(), fsp, &header, startpos, smb_maxcnt)) == -1) {
- /* Returning ENOSYS or EINVAL means no data at all was sent.
+ /* Returning ENOSYS means no data at all was sent.
Do this as a normal read. */
- if (errno == ENOSYS || errno == EINVAL) {
+ if (errno == ENOSYS) {
goto normal_read;
}
DEBUG( 3, ( "send_file_readX: fake_sendfile fnum=%d max=%d nread=%d\n",
fsp->fnum, (int)smb_maxcnt, (int)nread ) );
/* No outbuf here means successful sendfile. */
- TALLOC_FREE(req->outbuf);
- return;
+ goto strict_unlock;
}
DEBUG(0,("send_file_readX: sendfile failed for file %s (%s). Terminating\n",
fsp->fsp_name, strerror(errno) ));
exit_server_cleanly("send_file_readX sendfile failed");
+ } else if (nread == 0) {
+ /*
+ * Some sendfile implementations return 0 to indicate
+ * that there was a short read, but nothing was
+ * actually written to the socket. In this case,
+ * fallback to the normal read path so the header gets
+ * the correct byte count.
+ */
+ DEBUG(3, ("send_file_readX: sendfile sent zero bytes "
+ "falling back to the normal read: %s\n",
+ fsp->fsp_name));
+ goto normal_read;
}
DEBUG( 3, ( "send_file_readX: sendfile fnum=%d max=%d nread=%d\n",
fsp->fnum, (int)smb_maxcnt, (int)nread ) );
+
+ /* Deal with possible short send. */
+ if (nread != smb_maxcnt + sizeof(headerbuf)) {
+ sendfile_short_send(fsp, nread, sizeof(headerbuf), smb_maxcnt);
+ }
/* No outbuf here means successful sendfile. */
- TALLOC_FREE(req->outbuf);
- return;
+ SMB_PERFCOUNT_SET_MSGLEN_OUT(&req->pcd, nread);
+ SMB_PERFCOUNT_END(&req->pcd);
+ goto strict_unlock;
}
-#endif
normal_read:
+#endif
+
if ((smb_maxcnt & 0xFF0000) > 0x10000) {
uint8 headerbuf[smb_size + 2*12];
construct_reply_common_req(req, (char *)headerbuf);
- setup_readX_header((char *)headerbuf, smb_maxcnt);
+ setup_readX_header(req, (char *)headerbuf, smb_maxcnt);
/* Send out the header. */
if (write_data(smbd_server_fd(), (char *)headerbuf,
fsp->fsp_name, strerror(errno) ));
exit_server_cleanly("send_file_readX: fake_sendfile failed");
}
- TALLOC_FREE(req->outbuf);
- return;
+ goto strict_unlock;
}
+nosendfile_read:
+
reply_outbuf(req, 12, smb_maxcnt);
nread = read_file(fsp, smb_buf(req->outbuf), startpos, smb_maxcnt);
+
+ SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+
if (nread < 0) {
reply_unixerror(req, ERRDOS, ERRnoaccess);
return;
}
- setup_readX_header((char *)req->outbuf, nread);
+ setup_readX_header(req, (char *)req->outbuf, nread);
DEBUG( 3, ( "send_file_readX fnum=%d max=%d nread=%d\n",
fsp->fnum, (int)smb_maxcnt, (int)nread ) );
chain_reply(req);
+ return;
+
+ strict_unlock:
+ SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+ TALLOC_FREE(req->outbuf);
+ return;
}
/****************************************************************************
return;
}
/* We currently don't do this on signed or sealed data. */
- if (srv_is_signing_active() || is_encrypted_packet(req->inbuf)) {
+ if (srv_is_signing_active(smbd_server_conn) ||
+ is_encrypted_packet(req->inbuf)) {
reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
END_PROFILE(SMBreadX);
return;
}
- if (is_locked(fsp, (uint32)req->smbpid, (uint64_t)smb_maxcnt,
- (uint64_t)startpos, READ_LOCK)) {
- END_PROFILE(SMBreadX);
- reply_doserror(req, ERRDOS, ERRlock);
- return;
- }
-
if (!big_readX &&
schedule_aio_read_and_X(conn, req, fsp, startpos, smb_maxcnt)) {
- END_PROFILE(SMBreadX);
- return;
+ goto out;
}
send_file_readX(conn, req, fsp, startpos, smb_maxcnt);
+ out:
END_PROFILE(SMBreadX);
return;
}
char *data=NULL;
bool write_through;
files_struct *fsp;
+ struct lock_struct lock;
NTSTATUS status;
START_PROFILE(SMBwritebraw);
*/
SCVAL(req->inbuf,smb_com,SMBwritec);
- if (srv_is_signing_active()) {
+ if (srv_is_signing_active(smbd_server_conn)) {
END_PROFILE(SMBwritebraw);
exit_server_cleanly("reply_writebraw: SMB signing is active - "
"raw reads/writes are disallowed.");
return;
}
- if (is_locked(fsp,(uint32)req->smbpid,(uint64_t)tcount,
- (uint64_t)startpos, WRITE_LOCK)) {
+ init_strict_lock_struct(fsp, (uint32)req->smbpid,
+ (uint64_t)startpos, (uint64_t)tcount, WRITE_LOCK,
+ &lock);
+
+ if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
reply_doserror(req, ERRDOS, ERRlock);
error_to_writebrawerr(req);
END_PROFILE(SMBwritebraw);
if (nwritten < (ssize_t)numtowrite) {
reply_unixerror(req, ERRHRD, ERRdiskfull);
error_to_writebrawerr(req);
- END_PROFILE(SMBwritebraw);
- return;
+ goto strict_unlock;
}
total_written = nwritten;
if (!buf) {
reply_doserror(req, ERRDOS, ERRnomem);
error_to_writebrawerr(req);
- END_PROFILE(SMBwritebraw);
- return;
+ goto strict_unlock;
}
/* Return a SMBwritebraw message to the redirector to tell
SSVALS(buf,smb_vwv0,0xFFFF);
show_msg(buf);
if (!srv_send_smb(smbd_server_fd(),
- buf,
- IS_CONN_ENCRYPTED(conn))) {
+ buf,
+ false, 0, /* no signing */
+ IS_CONN_ENCRYPTED(conn),
+ &req->pcd)) {
exit_server_cleanly("reply_writebraw: srv_send_smb "
"failed.");
}
TALLOC_FREE(buf);
reply_unixerror(req, ERRHRD, ERRdiskfull);
error_to_writebrawerr(req);
- END_PROFILE(SMBwritebraw);
- return;
+ goto strict_unlock;
}
if (nwritten < (ssize_t)numtowrite) {
fsp->fsp_name, nt_errstr(status) ));
reply_nterror(req, status);
error_to_writebrawerr(req);
- END_PROFILE(SMBwritebraw);
- return;
+ goto strict_unlock;
}
DEBUG(3,("reply_writebraw: secondart write fnum=%d start=%.0f num=%d "
fsp->fnum, (double)startpos, (int)numtowrite,
(int)total_written));
+ SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+
/* We won't return a status if write through is not selected - this
* follows what WfWg does */
END_PROFILE(SMBwritebraw);
TALLOC_FREE(req->outbuf);
}
return;
+
+strict_unlock:
+ SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+
+ END_PROFILE(SMBwritebraw);
+ return;
}
#undef DBGC_CLASS
const char *data;
NTSTATUS status = NT_STATUS_OK;
files_struct *fsp;
+ struct lock_struct lock;
START_PROFILE(SMBwriteunlock);
startpos = IVAL_TO_SMB_OFF_T(req->vwv+2, 0);
data = (const char *)req->buf + 3;
- if (numtowrite
- && is_locked(fsp, (uint32)req->smbpid, (uint64_t)numtowrite,
- (uint64_t)startpos, WRITE_LOCK)) {
- reply_doserror(req, ERRDOS, ERRlock);
- END_PROFILE(SMBwriteunlock);
- return;
+ if (numtowrite) {
+ init_strict_lock_struct(fsp, (uint32)req->smbpid,
+ (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
+ &lock);
+
+ if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
+ reply_doserror(req, ERRDOS, ERRlock);
+ END_PROFILE(SMBwriteunlock);
+ return;
+ }
}
/* The special X/Open SMB protocol handling of
DEBUG(5,("reply_writeunlock: sync_file for %s returned %s\n",
fsp->fsp_name, nt_errstr(status) ));
reply_nterror(req, status);
- END_PROFILE(SMBwriteunlock);
- return;
+ goto strict_unlock;
}
if(((nwritten < numtowrite) && (numtowrite != 0))||(nwritten < 0)) {
reply_unixerror(req, ERRHRD, ERRdiskfull);
- END_PROFILE(SMBwriteunlock);
- return;
+ goto strict_unlock;
}
if (numtowrite) {
if (NT_STATUS_V(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBwriteunlock);
- return;
+ goto strict_unlock;
}
}
DEBUG(3,("writeunlock fnum=%d num=%d wrote=%d\n",
fsp->fnum, (int)numtowrite, (int)nwritten));
+strict_unlock:
+ if (numtowrite) {
+ SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+ }
+
END_PROFILE(SMBwriteunlock);
return;
}
SMB_OFF_T startpos;
const char *data;
files_struct *fsp;
+ struct lock_struct lock;
NTSTATUS status;
START_PROFILE(SMBwrite);
startpos = IVAL_TO_SMB_OFF_T(req->vwv+2, 0);
data = (const char *)req->buf + 3;
- if (is_locked(fsp, (uint32)req->smbpid, (uint64_t)numtowrite,
- (uint64_t)startpos, WRITE_LOCK)) {
+ init_strict_lock_struct(fsp, (uint32)req->smbpid,
+ (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
+ &lock);
+
+ if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
reply_doserror(req, ERRDOS, ERRlock);
END_PROFILE(SMBwrite);
return;
nwritten = vfs_allocate_file_space(fsp, (SMB_OFF_T)startpos);
if (nwritten < 0) {
reply_nterror(req, NT_STATUS_DISK_FULL);
- END_PROFILE(SMBwrite);
- return;
+ goto strict_unlock;
}
nwritten = vfs_set_filelen(fsp, (SMB_OFF_T)startpos);
if (nwritten < 0) {
reply_nterror(req, NT_STATUS_DISK_FULL);
- END_PROFILE(SMBwrite);
- return;
+ goto strict_unlock;
}
trigger_write_time_update_immediate(fsp);
} else {
DEBUG(5,("reply_write: sync_file for %s returned %s\n",
fsp->fsp_name, nt_errstr(status) ));
reply_nterror(req, status);
- END_PROFILE(SMBwrite);
- return;
+ goto strict_unlock;
}
if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0)) {
reply_unixerror(req, ERRHRD, ERRdiskfull);
- END_PROFILE(SMBwrite);
- return;
+ goto strict_unlock;
}
reply_outbuf(req, 1, 0);
DEBUG(3,("write fnum=%d num=%d wrote=%d\n", fsp->fnum, (int)numtowrite, (int)nwritten));
+strict_unlock:
+ SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+
END_PROFILE(SMBwrite);
return;
}
{
connection_struct *conn = req->conn;
files_struct *fsp;
+ struct lock_struct lock;
SMB_OFF_T startpos;
size_t numtowrite;
bool write_through;
#endif /* LARGE_SMB_OFF_T */
}
- if (is_locked(fsp,(uint32)req->smbpid,
- (uint64_t)numtowrite,
- (uint64_t)startpos, WRITE_LOCK)) {
+ init_strict_lock_struct(fsp, (uint32)req->smbpid,
+ (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
+ &lock);
+
+ if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
reply_doserror(req, ERRDOS, ERRlock);
END_PROFILE(SMBwriteX);
return;
if ((req->unread_bytes == 0) &&
schedule_aio_write_and_X(conn, req, fsp, data, startpos,
numtowrite)) {
- END_PROFILE(SMBwriteX);
- return;
+ goto strict_unlock;
}
nwritten = write_file(req,fsp,data,startpos,numtowrite);
if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0)) {
reply_unixerror(req, ERRHRD, ERRdiskfull);
- END_PROFILE(SMBwriteX);
- return;
+ goto strict_unlock;
}
reply_outbuf(req, 6, 0);
DEBUG(5,("reply_write_and_X: sync_file for %s returned %s\n",
fsp->fsp_name, nt_errstr(status) ));
reply_nterror(req, status);
- END_PROFILE(SMBwriteX);
- return;
+ goto strict_unlock;
}
+ SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+
END_PROFILE(SMBwriteX);
chain_reply(req);
return;
+
+strict_unlock:
+ SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+
+ END_PROFILE(SMBwriteX);
+ return;
}
/****************************************************************************
const char *data;
struct timespec mtime;
files_struct *fsp;
+ struct lock_struct lock;
START_PROFILE(SMBwriteclose);
mtime = convert_time_t_to_timespec(srv_make_unix_date3(req->vwv+4));
data = (const char *)req->buf + 1;
- if (numtowrite
- && is_locked(fsp, (uint32)req->smbpid, (uint64_t)numtowrite,
- (uint64_t)startpos, WRITE_LOCK)) {
- reply_doserror(req, ERRDOS,ERRlock);
- END_PROFILE(SMBwriteclose);
- return;
+ if (numtowrite) {
+ init_strict_lock_struct(fsp, (uint32)req->smbpid,
+ (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
+ &lock);
+
+ if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
+ reply_doserror(req, ERRDOS,ERRlock);
+ END_PROFILE(SMBwriteclose);
+ return;
+ }
}
nwritten = write_file(req,fsp,data,startpos,numtowrite);
if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0)) {
reply_doserror(req, ERRHRD, ERRdiskfull);
- END_PROFILE(SMBwriteclose);
- return;
+ goto strict_unlock;
}
if(!NT_STATUS_IS_OK(close_status)) {
reply_nterror(req, close_status);
- END_PROFILE(SMBwriteclose);
- return;
+ goto strict_unlock;
}
reply_outbuf(req, 1, 0);
SSVAL(req->outbuf,smb_vwv0,nwritten);
+
+strict_unlock:
+ if (numtowrite) {
+ SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+ }
+
END_PROFILE(SMBwriteclose);
return;
}
return;
}
- release_level_2_oplocks_on_change(fsp);
-
count = (uint64_t)IVAL(req->vwv+1, 0);
offset = (uint64_t)IVAL(req->vwv+3, 0);
WINDOWS_LOCK,
False, /* Non-blocking lock. */
&status,
+ NULL,
NULL);
TALLOC_FREE(br_lck);
void reply_echo(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ struct smb_perfcount_data local_pcd;
+ struct smb_perfcount_data *cur_pcd;
int smb_reverb;
int seq_num;
START_PROFILE(SMBecho);
+ smb_init_perfcount_data(&local_pcd);
+
if (req->wct < 1) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
END_PROFILE(SMBecho);
smb_reverb = 100;
}
- for (seq_num =1 ; seq_num <= smb_reverb ; seq_num++) {
+ for (seq_num = 1 ; seq_num <= smb_reverb ; seq_num++) {
+
+ /* this makes sure we catch the request pcd */
+ if (seq_num == smb_reverb) {
+ cur_pcd = &req->pcd;
+ } else {
+ SMB_PERFCOUNT_COPY_CONTEXT(&req->pcd, &local_pcd);
+ cur_pcd = &local_pcd;
+ }
+
SSVAL(req->outbuf,smb_vwv0,seq_num);
show_msg((char *)req->outbuf);
if (!srv_send_smb(smbd_server_fd(),
(char *)req->outbuf,
- IS_CONN_ENCRYPTED(conn)||req->encrypted))
+ true, req->seqnum+1,
+ IS_CONN_ENCRYPTED(conn)||req->encrypted,
+ cur_pcd))
exit_server_cleanly("reply_echo: srv_send_smb failed.");
}
void reply_mkdir(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ struct smb_filename *smb_dname = NULL;
char *directory = NULL;
NTSTATUS status;
- SMB_STRUCT_STAT sbuf;
TALLOC_CTX *ctx = talloc_tos();
START_PROFILE(SMBmkdir);
STR_TERMINATE, &status);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBmkdir);
- return;
+ goto out;
}
status = resolve_dfspath(ctx, conn,
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
ERRSRV, ERRbadpath);
- END_PROFILE(SMBmkdir);
- return;
+ goto out;
}
reply_nterror(req, status);
- END_PROFILE(SMBmkdir);
- return;
+ goto out;
}
- status = unix_convert(ctx, conn, directory, False, &directory, NULL, &sbuf);
+ status = unix_convert(ctx, conn, directory, &smb_dname, 0);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBmkdir);
- return;
+ 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);
- END_PROFILE(SMBmkdir);
- return;
+ goto out;
}
status = create_directory(conn, req, directory);
}
reply_nterror(req, status);
- END_PROFILE(SMBmkdir);
- return;
+ goto out;
}
reply_outbuf(req, 0, 0);
DEBUG( 3, ( "mkdir %s\n", directory ) );
-
+ out:
+ TALLOC_FREE(smb_dname);
END_PROFILE(SMBmkdir);
return;
}
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);
if(dir_hnd == NULL)
return False;
- while((dname = ReadDirName(dir_hnd, &offset))) {
+ while((dname = ReadDirName(dir_hnd, &offset, &st))) {
char *fullname = NULL;
- SMB_STRUCT_STAT st;
if (ISDOT(dname) || ISDOTDOT(dname)) {
continue;
goto err;
}
- while ((dname = ReadDirName(dir_hnd,&dirpos))) {
+ while ((dname = ReadDirName(dir_hnd, &dirpos, &st))) {
if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
continue;
if (!is_visible_file(conn, directory, dname, &st, False))
/* Do a recursive delete. */
RewindDir(dir_hnd,&dirpos);
- while ((dname = ReadDirName(dir_hnd,&dirpos))) {
+ while ((dname = ReadDirName(dir_hnd, &dirpos, &st))) {
char *fullname = NULL;
if (ISDOT(dname) || ISDOTDOT(dname)) {
void reply_rmdir(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ struct smb_filename *smb_dname = NULL;
char *directory = NULL;
- SMB_STRUCT_STAT sbuf;
NTSTATUS status;
TALLOC_CTX *ctx = talloc_tos();
STR_TERMINATE, &status);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBrmdir);
- return;
+ goto out;
}
status = resolve_dfspath(ctx, conn,
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
ERRSRV, ERRbadpath);
- END_PROFILE(SMBrmdir);
- return;
+ goto out;
}
reply_nterror(req, status);
- END_PROFILE(SMBrmdir);
- return;
+ goto out;
}
- status = unix_convert(ctx, conn, directory, False, &directory,
- NULL, &sbuf);
+ status = unix_convert(ctx, conn, directory, &smb_dname, 0);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBrmdir);
- return;
+ 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);
- END_PROFILE(SMBrmdir);
- return;
+ goto out;
}
dptr_closepath(directory, req->smbpid);
status = rmdir_internals(ctx, conn, directory);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBrmdir);
- return;
+ goto out;
}
reply_outbuf(req, 0, 0);
DEBUG( 3, ( "rmdir %s\n", directory ) );
-
+ out:
+ TALLOC_FREE(smb_dname);
END_PROFILE(SMBrmdir);
return;
}
return map_nt_error_from_unix(errno);
}
} else {
- if (SMB_VFS_STAT(conn,fsp->fsp_name,&sbuf) == -1) {
+ int ret = -1;
+ 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 map_nt_error_from_unix(errno);
}
}
bool dest_has_wild,
uint32_t access_mask)
{
+ struct smb_filename *smb_fname = NULL;
+ struct smb_filename *smb_fname_new = NULL;
char *directory = NULL;
char *mask = NULL;
- char *last_component_src = NULL;
- char *last_component_dest = NULL;
char *name = NULL;
char *newname = NULL;
char *p;
int count=0;
NTSTATUS status = NT_STATUS_OK;
- SMB_STRUCT_STAT sbuf1, sbuf2;
struct smb_Dir *dir_hnd = NULL;
const char *dname;
long offset = 0;
int create_options = 0;
+ bool posix_pathnames = lp_posix_pathnames();
- ZERO_STRUCT(sbuf1);
- ZERO_STRUCT(sbuf2);
+ status = unix_convert(ctx, conn, name_in, &smb_fname,
+ src_has_wild ? UCF_ALLOW_WCARD_LCOMP : 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
- status = unix_convert(ctx, conn, name_in, src_has_wild, &name,
- &last_component_src, &sbuf1);
+ status = get_full_smb_filename(ctx, smb_fname, &name);
if (!NT_STATUS_IS_OK(status)) {
- return status;
+ goto out;
}
- status = unix_convert(ctx, conn, newname_in, dest_has_wild, &newname,
- &last_component_dest, &sbuf2);
+ status = unix_convert(ctx, conn, newname_in, &smb_fname_new,
+ (UCF_SAVE_LCOMP |
+ (dest_has_wild ? UCF_ALLOW_WCARD_LCOMP : 0)));
if (!NT_STATUS_IS_OK(status)) {
- return status;
+ goto out;
+ }
+
+ status = get_full_smb_filename(ctx, smb_fname_new, &newname);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
}
/*
if (!p) {
directory = talloc_strdup(ctx, ".");
if (!directory) {
- return NT_STATUS_NO_MEMORY;
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
mask = name;
} else {
*p = 0;
directory = talloc_strdup(ctx, name);
if (!directory) {
- return NT_STATUS_NO_MEMORY;
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
mask = p+1;
*p = '/'; /* Replace needed for exceptional test below. */
* Tine Smukavec <valentin.smukavec@hermes.si>.
*/
- if (!VALID_STAT(sbuf1) && mangle_is_mangled(mask, conn->params)) {
+ if (!VALID_STAT(smb_fname->st) && mangle_is_mangled(mask, conn->params)) {
char *new_mask = NULL;
mangle_lookup_name_from_8_3(ctx,
mask,
/*
* No wildcards - just process the one file.
*/
- bool is_short_name = mangle_is_8_3(name, True, conn->params);
-
/* Add a terminating '/' to the directory name. */
directory = talloc_asprintf_append(directory,
"/%s",
mask);
if (!directory) {
- return NT_STATUS_NO_MEMORY;
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
/* Ensure newname contains a '/' also */
"./%s",
newname);
if (!newname) {
- return NT_STATUS_NO_MEMORY;
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
}
DEBUG(3, ("rename_internals: case_sensitive = %d, "
"case_preserve = %d, short case preserve = %d, "
"directory = %s, newname = %s, "
- "last_component_dest = %s, is_8_3 = %d\n",
+ "last_component_dest = %s\n",
conn->case_sensitive, conn->case_preserve,
conn->short_case_preserve, directory,
- newname, last_component_dest, is_short_name));
+ newname, smb_fname_new->original_lcomp));
/* The dest name still may have wildcards. */
if (dest_has_wild) {
"%s %s failed\n",
directory,
newname));
- return NT_STATUS_NO_MEMORY;
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
newname = mod_newname;
}
- ZERO_STRUCT(sbuf1);
- SMB_VFS_STAT(conn, directory, &sbuf1);
+ ZERO_STRUCT(smb_fname->st);
+ if (posix_pathnames) {
+ SMB_VFS_LSTAT(conn, directory, &smb_fname->st);
+ } else {
+ SMB_VFS_STAT(conn, directory, &smb_fname->st);
+ }
- if (S_ISDIR(sbuf1.st_mode)) {
+ if (S_ISDIR(smb_fname->st.st_mode)) {
create_options |= FILE_DIRECTORY_FILE;
}
FILE_SHARE_WRITE),
FILE_OPEN, /* create_disposition*/
create_options, /* create_options */
- 0, /* file_attributes */
+ posix_pathnames ? FILE_FLAG_POSIX_SEMANTICS|0777 : 0, /* file_attributes */
0, /* oplock_request */
0, /* allocation_size */
NULL, /* sd */
NULL, /* ea_list */
&fsp, /* result */
NULL, /* pinfo */
- &sbuf1); /* psbuf */
+ &smb_fname->st); /* psbuf */
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("Could not open rename source %s: %s\n",
directory, nt_errstr(status)));
- return status;
+ goto out;
}
status = rename_internals_fsp(conn, fsp, newname,
- last_component_dest,
+ smb_fname_new->original_lcomp,
attrs, replace_if_exists);
close_file(req, fsp, NORMAL_CLOSE);
DEBUG(3, ("rename_internals: Error %s rename %s -> %s\n",
nt_errstr(status), directory,newname));
- return status;
+ goto out;
}
/*
status = check_name(conn, directory);
if (!NT_STATUS_IS_OK(status)) {
- return status;
+ goto out;
}
dir_hnd = OpenDir(talloc_tos(), conn, directory, mask, attrs);
if (dir_hnd == NULL) {
- return map_nt_error_from_unix(errno);
+ status = map_nt_error_from_unix(errno);
+ goto out;
}
status = NT_STATUS_NO_SUCH_FILE;
* - gentest fix. JRA
*/
- while ((dname = ReadDirName(dir_hnd, &offset))) {
+ while ((dname = ReadDirName(dir_hnd, &offset, &smb_fname->st))) {
files_struct *fsp = NULL;
char *fname = NULL;
char *destname = NULL;
}
}
- if (!is_visible_file(conn, directory, dname, &sbuf1, False)) {
+ if (!is_visible_file(conn, directory, dname, &smb_fname->st,
+ False)) {
continue;
}
directory,
dname);
if (!fname) {
- return NT_STATUS_NO_MEMORY;
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
if (!resolve_wildcards(ctx,
continue;
}
if (!destname) {
- return NT_STATUS_NO_MEMORY;
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
- ZERO_STRUCT(sbuf1);
- SMB_VFS_STAT(conn, fname, &sbuf1);
+ ZERO_STRUCT(smb_fname->st);
+ if (posix_pathnames) {
+ SMB_VFS_LSTAT(conn, fname, &smb_fname->st);
+ } else {
+ SMB_VFS_STAT(conn, fname, &smb_fname->st);
+ }
create_options = 0;
- if (S_ISDIR(sbuf1.st_mode)) {
+ if (S_ISDIR(smb_fname->st.st_mode)) {
create_options |= FILE_DIRECTORY_FILE;
}
FILE_SHARE_WRITE),
FILE_OPEN, /* create_disposition*/
create_options, /* create_options */
- 0, /* file_attributes */
+ posix_pathnames ? FILE_FLAG_POSIX_SEMANTICS|0777 : 0, /* file_attributes */
0, /* oplock_request */
0, /* allocation_size */
NULL, /* sd */
NULL, /* ea_list */
&fsp, /* result */
NULL, /* pinfo */
- &sbuf1); /* psbuf */
+ &smb_fname->st); /* psbuf */
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3,("rename_internals: SMB_VFS_CREATE_FILE "
status = map_nt_error_from_unix(errno);
}
+ out:
+ TALLOC_FREE(smb_fname);
+ TALLOC_FREE(smb_fname_new);
return status;
}
void reply_copy(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ struct smb_filename *smb_fname = NULL;
+ struct smb_filename *smb_fname_new = NULL;
char *name = NULL;
char *newname = NULL;
char *directory = NULL;
bool target_is_directory=False;
bool source_has_wild = False;
bool dest_has_wild = False;
- SMB_STRUCT_STAT sbuf1, sbuf2;
NTSTATUS status;
TALLOC_CTX *ctx = talloc_tos();
if (req->wct < 3) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
tid2 = SVAL(req->vwv+0, 0);
&status, &source_has_wild);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
p += srvstr_get_path_req_wcard(ctx, req, &newname, p, STR_TERMINATE,
&status, &dest_has_wild);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
DEBUG(3,("reply_copy : %s -> %s\n",name,newname));
/* can't currently handle inter share copies XXXX */
DEBUG(3,("Rejecting inter-share copy\n"));
reply_doserror(req, ERRSRV, ERRinvdevice);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
status = resolve_dfspath_wcard(ctx, conn,
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
ERRSRV, ERRbadpath);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
status = resolve_dfspath_wcard(ctx, conn,
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
ERRSRV, ERRbadpath);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
- status = unix_convert(ctx, conn, name, source_has_wild,
- &name, NULL, &sbuf1);
+ status = unix_convert(ctx, conn, name, &smb_fname,
+ source_has_wild ? UCF_ALLOW_WCARD_LCOMP : 0);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
- status = unix_convert(ctx, conn, newname, dest_has_wild,
- &newname, NULL, &sbuf2);
+ status = get_full_smb_filename(ctx, smb_fname, &name);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
+ }
+
+ status = unix_convert(ctx, conn, newname, &smb_fname_new,
+ dest_has_wild ? UCF_ALLOW_WCARD_LCOMP : 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ reply_nterror(req, status);
+ goto out;
}
- target_is_directory = VALID_STAT_OF_DIR(sbuf2);
+ status = get_full_smb_filename(ctx, smb_fname_new, &newname);
+ if (!NT_STATUS_IS_OK(status)) {
+ reply_nterror(req, status);
+ goto out;
+ }
+
+ target_is_directory = VALID_STAT_OF_DIR(smb_fname_new->st);
if ((flags&1) && target_is_directory) {
reply_doserror(req, ERRDOS, ERRbadfile);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
if ((flags&2) && !target_is_directory) {
reply_doserror(req, ERRDOS, ERRbadpath);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
- if ((flags&(1<<5)) && VALID_STAT_OF_DIR(sbuf1)) {
+ if ((flags&(1<<5)) && VALID_STAT_OF_DIR(smb_fname->st)) {
/* wants a tree copy! XXXX */
DEBUG(3,("Rejecting tree copy\n"));
reply_doserror(req, ERRSRV, ERRerror);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
p = strrchr_m(name,'/');
if (!directory) {
reply_nterror(req, NT_STATUS_NO_MEMORY);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
/*
* Tine Smukavec <valentin.smukavec@hermes.si>.
*/
- if (!VALID_STAT(sbuf1) && mangle_is_mangled(mask, conn->params)) {
+ if (!VALID_STAT(smb_fname->st) &&
+ mangle_is_mangled(mask, conn->params)) {
char *new_mask = NULL;
mangle_lookup_name_from_8_3(ctx,
mask,
if (!resolve_wildcards(ctx,
directory,newname,&mod_newname)) {
reply_nterror(req, NT_STATUS_NO_MEMORY);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
newname = mod_newname;
}
status = check_name(conn, directory);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
status = check_name(conn, newname);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
status = copy_file(ctx,conn,directory,newname,ofun,
if(!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
} else {
count++;
}
status = check_name(conn, directory);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
dir_hnd = OpenDir(talloc_tos(), conn, directory, mask, 0);
if (dir_hnd == NULL) {
status = map_nt_error_from_unix(errno);
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
error = ERRbadfile;
- while ((dname = ReadDirName(dir_hnd, &offset))) {
+ while ((dname = ReadDirName(dir_hnd, &offset,
+ &smb_fname->st))) {
char *destname = NULL;
char *fname = NULL;
continue;
}
- if (!is_visible_file(conn, directory, dname, &sbuf1, False)) {
+ if (!is_visible_file(conn, directory, dname,
+ &smb_fname->st, False)) {
continue;
}
if (!fname) {
TALLOC_FREE(dir_hnd);
reply_nterror(req, NT_STATUS_NO_MEMORY);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
if (!resolve_wildcards(ctx,
if (!destname) {
TALLOC_FREE(dir_hnd);
reply_nterror(req, NT_STATUS_NO_MEMORY);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
status = check_name(conn, fname);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(dir_hnd);
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
status = check_name(conn, destname);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(dir_hnd);
reply_nterror(req, status);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
DEBUG(3,("reply_copy : doing copy on %s -> %s\n",fname, destname));
/* Error on close... */
errno = err;
reply_unixerror(req, ERRHRD, ERRgeneral);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
reply_doserror(req, ERRDOS, error);
- END_PROFILE(SMBcopy);
- return;
+ goto out;
}
reply_outbuf(req, 1, 0);
SSVAL(req->outbuf,smb_vwv0,count);
-
+ out:
+ TALLOC_FREE(smb_fname);
+ TALLOC_FREE(smb_fname_new);
END_PROFILE(SMBcopy);
return;
}
}
}
- /*
- * We do this check *after* we have checked this is not a oplock break
- * response message. JRA.
- */
-
- release_level_2_oplocks_on_change(fsp);
-
if (req->buflen <
(num_ulocks + num_locks) * (large_file_format ? 20 : 10)) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
offset,
WINDOWS_LOCK);
+ DEBUG(10, ("reply_lockingX: unlock returned %s\n",
+ nt_errstr(status)));
+
if (NT_STATUS_V(status)) {
END_PROFILE(SMBlockingX);
reply_nterror(req, status);
fsp->fsp_name, (int)lock_timeout ));
if (locktype & LOCKING_ANDX_CANCEL_LOCK) {
+ struct blocking_lock_record *blr = NULL;
+
if (lp_blocking_locks(SNUM(conn))) {
/* Schedule a message to ourselves to
remove the blocking lock record and
return the right error. */
- if (!blocking_lock_cancel(fsp,
+ blr = blocking_lock_cancel(fsp,
lock_pid,
offset,
count,
WINDOWS_LOCK,
locktype,
- NT_STATUS_FILE_LOCK_CONFLICT)) {
+ NT_STATUS_FILE_LOCK_CONFLICT);
+ if (blr == NULL) {
END_PROFILE(SMBlockingX);
reply_nterror(
req,
lock_pid,
count,
offset,
- WINDOWS_LOCK);
+ WINDOWS_LOCK,
+ blr);
} else {
bool blocking_lock = lock_timeout ? True : False;
bool defer_lock = False;
WINDOWS_LOCK,
blocking_lock,
&status,
- &block_smbpid);
+ &block_smbpid,
+ NULL);
if (br_lck && blocking_lock && ERROR_WAS_LOCK_DENIED(status)) {
/* Windows internal resolution for blocking locks seems
void reply_setattrE(struct smb_request *req)
{
connection_struct *conn = req->conn;
- struct timespec ts[2];
+ struct smb_file_time ft;
files_struct *fsp;
SMB_STRUCT_STAT sbuf;
NTSTATUS status;
START_PROFILE(SMBsetattrE);
+ ZERO_STRUCT(ft);
if (req->wct < 7) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
/*
- * Convert the DOS times into unix times. Ignore create
- * time as UNIX can't set this.
+ * Convert the DOS times into unix times.
*/
- ts[0] = convert_time_t_to_timespec(
- srv_make_unix_date2(req->vwv+3)); /* atime. */
- ts[1] = convert_time_t_to_timespec(
- srv_make_unix_date2(req->vwv+5)); /* mtime. */
+ ft.atime = convert_time_t_to_timespec(
+ srv_make_unix_date2(req->vwv+3));
+ ft.mtime = convert_time_t_to_timespec(
+ srv_make_unix_date2(req->vwv+5));
+ ft.create_time = convert_time_t_to_timespec(
+ srv_make_unix_date2(req->vwv+1));
reply_outbuf(req, 0, 0);
return;
}
} else {
- if (SMB_VFS_STAT(conn, fsp->fsp_name, &sbuf) == -1) {
+ int ret = -1;
+
+ 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) {
status = map_nt_error_from_unix(errno);
reply_nterror(req, status);
END_PROFILE(SMBsetattrE);
}
status = smb_set_file_time(conn, fsp, fsp->fsp_name,
- &sbuf, ts, true);
+ &sbuf, &ft, true);
if (!NT_STATUS_IS_OK(status)) {
reply_doserror(req, ERRDOS, ERRnoaccess);
END_PROFILE(SMBsetattrE);
return;
}
- DEBUG( 3, ( "reply_setattrE fnum=%d actime=%u modtime=%u\n",
+ DEBUG( 3, ( "reply_setattrE fnum=%d actime=%u modtime=%u "
+ " createtime=%u\n",
fsp->fnum,
- (unsigned int)ts[0].tv_sec,
- (unsigned int)ts[1].tv_sec));
+ (unsigned int)ft.atime.tv_sec,
+ (unsigned int)ft.mtime.tv_sec,
+ (unsigned int)ft.create_time.tv_sec
+ ));
END_PROFILE(SMBsetattrE);
return;
SIVAL(req->outbuf, smb_vwv6, 0);
SIVAL(req->outbuf, smb_vwv8, 0);
} else {
- uint32 allocation_size = get_allocation_size(conn,fsp, &sbuf);
+ uint32 allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn,fsp, &sbuf);
SIVAL(req->outbuf, smb_vwv6, (uint32)sbuf.st_size);
SIVAL(req->outbuf, smb_vwv8, allocation_size);
}