#include "libsmb/nmblib.h"
#include "auth.h"
#include "smbprofile.h"
+#include "../lib/tsocket/tsocket.h"
/****************************************************************************
Ensure we check the path in *exactly* the same way as W2K for a findfirst/findnext
if (!srv_send_smb(sconn, (char *)outbuf, false, 0, false,
NULL)) {
- exit_server_cleanly("netbios_session_regarget: srv_send_smb "
+ exit_server_cleanly("netbios_session_retarget: srv_send_smb "
"failed.");
}
smb_setlen(outbuf,0);
switch (msg_type) {
- case 0x81: /* session request */
+ case NBSSrequest: /* session request */
{
/* inbuf_size is guarenteed to be at least 4. */
fstring name1,name2;
exit_server_cleanly("multiple session request not permitted");
}
- SCVAL(outbuf,0,0x82);
+ SCVAL(outbuf,0,NBSSpositive);
SCVAL(outbuf,3,0);
/* inbuf_size is guaranteed to be at least 4. */
*/
if (strequal(name1, "*SMBSERVER ")
|| strequal(name1, "*SMBSERV ")) {
- fstrcpy(name1, sconn->client_id.addr);
+ char *raddr;
+
+ raddr = tsocket_address_inet_addr_string(sconn->remote_address,
+ talloc_tos());
+ if (raddr == NULL) {
+ exit_server_cleanly("could not allocate raddr");
+ }
+
+ fstrcpy(name1, raddr);
}
set_local_machine_name(name1, True);
case 0x89: /* session keepalive request
(some old clients produce this?) */
- SCVAL(outbuf,0,SMBkeepalive);
+ SCVAL(outbuf,0,NBSSkeepalive);
SCVAL(outbuf,3,0);
break;
- case 0x82: /* positive session response */
- case 0x83: /* negative session response */
- case 0x84: /* retarget session response */
+ case NBSSpositive: /* positive session response */
+ case NBSSnegative: /* negative session response */
+ case NBSSretarget: /* retarget session response */
DEBUG(0,("Unexpected session response\n"));
break;
- case SMBkeepalive: /* session keepalive */
+ case NBSSkeepalive: /* session keepalive */
default:
return;
}
perm1 = FILE_ALL_ACCESS;
perm2 = FILE_ALL_ACCESS;
} else {
- perm1 = CAN_WRITE(conn) ?
- SHARE_ALL_ACCESS :
- SHARE_READ_ONLY;
+ perm1 = conn->share_access;
}
SIVAL(req->outbuf, smb_vwv3, perm1);
mode = SVAL(req->vwv+0, 0);
mtime = srv_make_unix_date3(req->vwv+1);
- ft.mtime = convert_time_t_to_timespec(mtime);
- status = smb_set_file_time(conn, NULL, smb_fname, &ft, true);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- goto out;
- }
-
if (mode != FILE_ATTRIBUTE_NORMAL) {
if (VALID_STAT_OF_DIR(smb_fname->st))
mode |= FILE_ATTRIBUTE_DIRECTORY;
else
mode &= ~FILE_ATTRIBUTE_DIRECTORY;
+ status = check_access(conn, NULL, smb_fname,
+ FILE_WRITE_ATTRIBUTES);
+ if (!NT_STATUS_IS_OK(status)) {
+ reply_nterror(req, status);
+ goto out;
+ }
+
if (file_set_dosmode(conn, smb_fname, mode, NULL,
false) != 0) {
reply_nterror(req, map_nt_error_from_unix(errno));
}
}
+ ft.mtime = convert_time_t_to_timespec(mtime);
+ status = smb_set_file_time(conn, NULL, smb_fname, &ft, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ reply_nterror(req, status);
+ goto out;
+ }
+
reply_outbuf(req, 0, 0);
DEBUG(3, ("setatr name=%s mode=%d\n", smb_fname_str_dbg(smb_fname),
goto out;
}
- if (!map_open_params_to_ntcreate(smb_fname, deny_mode,
+ if (!map_open_params_to_ntcreate(smb_fname->base_name, deny_mode,
OPENX_FILE_EXISTS_OPEN, &access_mask,
&share_mode, &create_disposition,
&create_options, &private_flags)) {
&info); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
- if (open_was_deferred(req->mid)) {
+ if (open_was_deferred(req->sconn, req->mid)) {
/* We have re-scheduled this call. */
goto out;
}
goto out;
}
- if (!map_open_params_to_ntcreate(smb_fname, deny_mode, smb_ofun,
+ if (!map_open_params_to_ntcreate(smb_fname->base_name, deny_mode,
+ smb_ofun,
&access_mask, &share_mode,
&create_disposition,
&create_options,
&smb_action); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
- if (open_was_deferred(req->mid)) {
+ if (open_was_deferred(req->sconn, req->mid)) {
/* We have re-scheduled this call. */
goto out;
}
NULL); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
- if (open_was_deferred(req->mid)) {
+ if (open_was_deferred(req->sconn, req->mid)) {
/* We have re-scheduled this call. */
goto out;
}
close(tmpfd);
if (!NT_STATUS_IS_OK(status)) {
- if (open_was_deferred(req->mid)) {
+ if (open_was_deferred(req->sconn, req->mid)) {
/* We have re-scheduled this call. */
goto out;
}
}
/* The set is across all open files on this dev/inode pair. */
- if (!set_delete_on_close(fsp, True, &conn->session_info->utok)) {
+ if (!set_delete_on_close(fsp, True, conn->session_info->unix_token)) {
close_file(req, fsp, NORMAL_CLOSE);
return NT_STATUS_ACCESS_DENIED;
}
status = unlink_internals(conn, req, dirtype, smb_fname,
path_contains_wcard);
if (!NT_STATUS_IS_OK(status)) {
- if (open_was_deferred(req->mid)) {
+ if (open_was_deferred(req->sconn, req->mid)) {
/* We have re-scheduled this call. */
goto out;
}
START_PROFILE(SMBreadbraw);
if (srv_is_signing_active(sconn) ||
- is_encrypted_packet(req->inbuf)) {
+ is_encrypted_packet(sconn, req->inbuf)) {
exit_server_cleanly("reply_readbraw: SMB signing/sealing is active - "
"raw reads/writes are disallowed.");
}
*/
if (!req_is_in_chain(req) &&
- !is_encrypted_packet(req->inbuf) && (fsp->base_fsp == NULL) &&
+ !is_encrypted_packet(req->sconn, req->inbuf) &&
+ (fsp->base_fsp == NULL) &&
(fsp->wcp == NULL) &&
lp_use_sendfile(SNUM(conn), req->sconn->smb1.signing_state) ) {
uint8 headerbuf[smb_size + 12 * 2];
void reply_read_and_X(struct smb_request *req)
{
+ struct smbd_server_connection *sconn = req->sconn;
connection_struct *conn = req->conn;
files_struct *fsp;
SMB_OFF_T startpos;
return;
}
- if (global_client_caps & CAP_LARGE_READX) {
+ if ((sconn->smb1.unix_info.client_cap_low & CIFS_UNIX_LARGE_READ_CAP) ||
+ (get_remote_arch() == RA_SAMBA)) {
+ /*
+ * This is Samba only behavior (up to Samba 3.6)!
+ *
+ * Windows 2008 R2 ignores the upper_size,
+ * so we do unless unix extentions are active
+ * or "smbclient" is talking to us.
+ */
size_t upper_size = SVAL(req->vwv+7, 0);
smb_maxcnt |= (upper_size<<16);
if (upper_size > 1) {
}
/* We currently don't do this on signed or sealed data. */
if (srv_is_signing_active(req->sconn) ||
- is_encrypted_packet(req->inbuf)) {
+ is_encrypted_packet(req->sconn, req->inbuf)) {
reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
END_PROFILE(SMBreadX);
return;
static NTSTATUS read_smb_length(int fd, char *inbuf, unsigned int timeout,
size_t *len)
{
- uint8_t msgtype = SMBkeepalive;
+ uint8_t msgtype = NBSSkeepalive;
- while (msgtype == SMBkeepalive) {
+ while (msgtype == NBSSkeepalive) {
NTSTATUS status;
status = read_smb_length_return_keepalive(fd, inbuf, timeout,
#if RABBIT_PELLET_FIX
/*
* Fix for "rabbit pellet" mode, trigger an early TCP ack by
- * sending a SMBkeepalive. Thanks to DaveCB at Sun for this.
+ * sending a NBSSkeepalive. Thanks to DaveCB at Sun for this.
* JRA.
*/
if (!send_keepalive(req->sconn->sock)) {
unsigned int doff = 0;
size_t len = smb_len_large(inbuf);
- if (is_encrypted_packet(inbuf)) {
+ if (is_encrypted_packet(sconn, inbuf)) {
/* Can't do this on encrypted
* connections. */
return false;
status = rpc_pipe_open_interface(conn,
&ndr_table_spoolss.syntax_id,
conn->session_info,
- &conn->sconn->client_id,
+ conn->sconn->remote_address,
conn->sconn->msg_ctx,
&cli);
if (!NT_STATUS_IS_OK(status)) {
&info); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
- if (open_was_deferred(req->mid)) {
+ if (open_was_deferred(req->sconn, req->mid)) {
/* We have re-scheduled this call. */
goto out;
}
goto out;
}
- if (!set_delete_on_close(fsp, true, &conn->session_info->utok)) {
+ if (!set_delete_on_close(fsp, true, conn->session_info->unix_token)) {
close_file(req, fsp, ERROR_CLOSE);
reply_nterror(req, NT_STATUS_ACCESS_DENIED);
goto out;
TALLOC_FREE(parent_dir_dst);
}
+/****************************************************************************
+ Returns an error if the parent directory for a filename is open in an
+ incompatible way.
+****************************************************************************/
+
+static NTSTATUS parent_dirname_compatible_open(connection_struct *conn,
+ const struct smb_filename *smb_fname_dst_in)
+{
+ char *parent_dir = NULL;
+ struct smb_filename smb_fname_parent;
+ struct file_id id;
+ files_struct *fsp = NULL;
+ int ret;
+
+ if (!parent_dirname(talloc_tos(), smb_fname_dst_in->base_name,
+ &parent_dir, NULL)) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ ZERO_STRUCT(smb_fname_parent);
+ smb_fname_parent.base_name = parent_dir;
+
+ ret = SMB_VFS_LSTAT(conn, &smb_fname_parent);
+ if (ret == -1) {
+ return map_nt_error_from_unix(errno);
+ }
+
+ /*
+ * We're only checking on this smbd here, mostly good
+ * enough.. and will pass tests.
+ */
+
+ id = vfs_file_id_from_sbuf(conn, &smb_fname_parent.st);
+ for (fsp = file_find_di_first(conn->sconn, id); fsp;
+ fsp = file_find_di_next(fsp)) {
+ if (fsp->access_mask & DELETE_ACCESS) {
+ return NT_STATUS_SHARING_VIOLATION;
+ }
+ }
+ return NT_STATUS_OK;
+}
+
/****************************************************************************
Rename an open file - given an fsp.
****************************************************************************/
return status;
}
+ status = parent_dirname_compatible_open(conn, smb_fname_dst_in);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
/* Make a copy of the dst smb_fname structs */
status = copy_smb_filename(ctx, smb_fname_dst_in, &smb_fname_dst);
attrs, False, src_has_wcard, dest_has_wcard,
DELETE_ACCESS);
if (!NT_STATUS_IS_OK(status)) {
- if (open_was_deferred(req->mid)) {
+ if (open_was_deferred(req->sconn, req->mid)) {
/* We have re-scheduled this call. */
goto out;
}
if (!target_is_directory && count) {
new_create_disposition = FILE_OPEN;
} else {
- if (!map_open_params_to_ntcreate(smb_fname_dst_tmp, 0, ofun,
+ if (!map_open_params_to_ntcreate(smb_fname_dst_tmp->base_name,
+ 0, ofun,
NULL, NULL,
&new_create_disposition,
NULL,
goto out;
}
+ if (!(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {
+ reply_nterror(req, NT_STATUS_ACCESS_DENIED);
+ goto out;
+ }
+
status = smb_set_file_time(conn, fsp, fsp->fsp_name, &ft, true);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);