mirror of
https://github.com/samba-team/samba.git
synced 2025-02-23 09:57:40 +03:00
*Wonderful* patch from Andrew Bartlett that will help ensure tdb's are
cleaned on clients abending connections. Thanks Andrew ! Jeremy. (This used to be commit 1b3977c5367a0b713b194f369abd9872ae01ac2a)
This commit is contained in:
parent
c7b67c26e2
commit
f63ee18c68
@ -661,8 +661,10 @@ BOOL receive_smb(int fd,char *buffer, unsigned int timeout)
|
||||
|
||||
if (len > (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE)) {
|
||||
DEBUG(0,("Invalid packet length! (%d bytes).\n",len));
|
||||
if (len > BUFFER_SIZE + (SAFETY_MARGIN/2))
|
||||
exit(1);
|
||||
if (len > BUFFER_SIZE + (SAFETY_MARGIN/2)) {
|
||||
smb_read_error = READ_ERROR;
|
||||
return False;
|
||||
}
|
||||
}
|
||||
|
||||
if(len > 0) {
|
||||
@ -710,56 +712,28 @@ BOOL client_receive_smb(int fd,char *buffer, unsigned int timeout)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
send an null session message to a fd
|
||||
****************************************************************************/
|
||||
|
||||
BOOL send_null_session_msg(int fd)
|
||||
{
|
||||
ssize_t ret;
|
||||
uint32 blank = 0;
|
||||
size_t len = 4;
|
||||
size_t nwritten=0;
|
||||
char *buffer = (char *)␣
|
||||
|
||||
while (nwritten < len)
|
||||
{
|
||||
ret = write_socket(fd,buffer+nwritten,len - nwritten);
|
||||
if (ret <= 0)
|
||||
{
|
||||
DEBUG(0,("send_null_session_msg: Error writing %d bytes to client. %d. Exiting\n",(int)len,(int)ret));
|
||||
exit(1);
|
||||
}
|
||||
nwritten += ret;
|
||||
}
|
||||
|
||||
DEBUG(10,("send_null_session_msg: sent 4 null bytes to client.\n"));
|
||||
return True;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
send an smb to a fd
|
||||
****************************************************************************/
|
||||
|
||||
BOOL send_smb(int fd,char *buffer)
|
||||
{
|
||||
size_t len;
|
||||
size_t nwritten=0;
|
||||
ssize_t ret;
|
||||
len = smb_len(buffer) + 4;
|
||||
size_t len;
|
||||
size_t nwritten=0;
|
||||
ssize_t ret;
|
||||
len = smb_len(buffer) + 4;
|
||||
|
||||
while (nwritten < len)
|
||||
{
|
||||
ret = write_socket(fd,buffer+nwritten,len - nwritten);
|
||||
if (ret <= 0)
|
||||
{
|
||||
DEBUG(0,("Error writing %d bytes to client. %d. Exiting\n",(int)len,(int)ret));
|
||||
exit(1);
|
||||
}
|
||||
nwritten += ret;
|
||||
}
|
||||
while (nwritten < len) {
|
||||
ret = write_socket(fd,buffer+nwritten,len - nwritten);
|
||||
if (ret <= 0) {
|
||||
DEBUG(0,("Error writing %d bytes to client. %d. (%s)\n",
|
||||
(int)len,(int)ret, strerror(errno) ));
|
||||
return False;
|
||||
}
|
||||
nwritten += ret;
|
||||
}
|
||||
|
||||
return True;
|
||||
return True;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -130,10 +130,11 @@ for fnum = %d, name = %s\n", length, (int)blr->expire_time, lock_timeout,
|
||||
|
||||
static void send_blocking_reply(char *outbuf, int outsize)
|
||||
{
|
||||
if(outsize > 4)
|
||||
smb_setlen(outbuf,outsize - 4);
|
||||
if(outsize > 4)
|
||||
smb_setlen(outbuf,outsize - 4);
|
||||
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("send_blocking_reply: send_smb failed.\n");
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -171,15 +172,16 @@ static void reply_lockingX_success(blocking_lock_record *blr)
|
||||
|
||||
static void generic_blocking_lock_error(blocking_lock_record *blr, int eclass, int32 ecode)
|
||||
{
|
||||
char *outbuf = OutBuffer;
|
||||
char *inbuf = blr->inbuf;
|
||||
construct_reply_common(inbuf, outbuf);
|
||||
char *outbuf = OutBuffer;
|
||||
char *inbuf = blr->inbuf;
|
||||
construct_reply_common(inbuf, outbuf);
|
||||
|
||||
if(eclass == 0) /* NT Error. */
|
||||
SSVAL(outbuf,smb_flg2, SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
|
||||
if(eclass == 0) /* NT Error. */
|
||||
SSVAL(outbuf,smb_flg2, SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
|
||||
|
||||
ERROR(eclass,ecode);
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
ERROR(eclass,ecode);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("generic_blocking_lock_error: send_smb failed.\n");
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -128,7 +128,8 @@ void send_trans_reply(char *outbuf,
|
||||
SSVAL(outbuf,smb_vwv9,0);
|
||||
|
||||
show_msg(outbuf);
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("send_trans_reply: send_smb failed.\n");
|
||||
|
||||
tot_data_sent = this_ldata;
|
||||
tot_param_sent = this_lparam;
|
||||
@ -161,7 +162,8 @@ void send_trans_reply(char *outbuf,
|
||||
SSVAL(outbuf,smb_vwv9,0);
|
||||
|
||||
show_msg(outbuf);
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("send_trans_reply: send_smb failed.\n");
|
||||
|
||||
tot_data_sent += this_ldata;
|
||||
tot_param_sent += this_lparam;
|
||||
@ -424,7 +426,8 @@ int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int
|
||||
of the parameter/data bytes */
|
||||
outsize = set_message(outbuf,0,0,True);
|
||||
show_msg(outbuf);
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("reply_trans: send_smb failed.\n");
|
||||
}
|
||||
|
||||
/* receive the rest of the trans packet */
|
||||
|
@ -71,7 +71,8 @@ static void change_notify_reply_packet(char *inbuf, uint32 error_code)
|
||||
*/
|
||||
set_message(outbuf,18,0,False);
|
||||
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("change_notify_reply_packet: send_smb failed.\n");
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -96,7 +96,8 @@ static int send_nt_replies(char *inbuf, char *outbuf, int bufsize, uint32 nt_err
|
||||
*/
|
||||
|
||||
if(params_to_send == 0 && data_to_send == 0) {
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("send_nt_replies: send_smb failed.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -225,7 +226,8 @@ static int send_nt_replies(char *inbuf, char *outbuf, int bufsize, uint32 nt_err
|
||||
params_to_send, data_to_send, paramsize, datasize));
|
||||
|
||||
/* Send the packet */
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("send_nt_replies: send_smb failed.\n");
|
||||
|
||||
pp += params_sent_thistime;
|
||||
pd += data_sent_thistime;
|
||||
@ -1780,7 +1782,8 @@ due to being in oplock break state.\n" ));
|
||||
/* We need to send an interim response then receive the rest
|
||||
of the parameter/data bytes */
|
||||
outsize = set_message(outbuf,0,0,True);
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("reply_nttrans: send_smb failed.\n");
|
||||
|
||||
while( num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
|
||||
BOOL ret;
|
||||
|
@ -572,7 +572,8 @@ BOOL oplock_break_level2(files_struct *fsp, BOOL local_request, int token)
|
||||
/* Prepare the SMBlockingX message. */
|
||||
|
||||
prepare_break_message( outbuf, fsp, False);
|
||||
send_smb(smbd_server_fd(), outbuf);
|
||||
if (!send_smb(smbd_server_fd(), outbuf))
|
||||
exit_server("oplock_break_level2: send_smb failed.\n");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -716,7 +717,8 @@ static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval, B
|
||||
fsp->sent_oplock_break = using_levelII?
|
||||
LEVEL_II_BREAK_SENT:EXCLUSIVE_BREAK_SENT;
|
||||
|
||||
send_smb(smbd_server_fd(), outbuf);
|
||||
if (!send_smb(smbd_server_fd(), outbuf))
|
||||
exit_server("oplock_break: send_smb failed.\n");
|
||||
|
||||
/* We need this in case a readraw crosses on the wire. */
|
||||
global_oplock_break = True;
|
||||
|
@ -2056,12 +2056,25 @@ BOOL set_nt_acl(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd)
|
||||
}
|
||||
}
|
||||
|
||||
if (acl_perms && acl_set_support && fsp->is_directory && dir_ace_list) {
|
||||
if (!set_canon_ace_list(fsp, dir_ace_list, True, &acl_set_support)) {
|
||||
DEBUG(3,("set_nt_acl: failed to set default acl on directory %s (%s).\n", fsp->fsp_name, strerror(errno) ));
|
||||
free_canon_ace_list(file_ace_list);
|
||||
free_canon_ace_list(dir_ace_list);
|
||||
return False;
|
||||
if (acl_perms && acl_set_support && fsp->is_directory) {
|
||||
if (dir_ace_list) {
|
||||
if (!set_canon_ace_list(fsp, dir_ace_list, True, &acl_set_support)) {
|
||||
DEBUG(3,("set_nt_acl: failed to set default acl on directory %s (%s).\n", fsp->fsp_name, strerror(errno) ));
|
||||
free_canon_ace_list(file_ace_list);
|
||||
free_canon_ace_list(dir_ace_list);
|
||||
return False;
|
||||
}
|
||||
} else {
|
||||
|
||||
/*
|
||||
* No default ACL - delete one if it exists.
|
||||
*/
|
||||
|
||||
if (sys_acl_delete_def_file(dos_to_unix(fsp->fsp_name,False)) == -1) {
|
||||
DEBUG(3,("set_nt_acl: sys_acl_delete_def_file failed (%s)\n", strerror(errno)));
|
||||
free_canon_ace_list(file_ace_list);
|
||||
return False;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -822,7 +822,7 @@ void process_smb(char *inbuf, char *outbuf)
|
||||
static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81};
|
||||
DEBUG( 1, ( "Connection denied from %s\n",
|
||||
client_addr() ) );
|
||||
send_smb(smbd_server_fd(),(char *)buf);
|
||||
(void)send_smb(smbd_server_fd(),(char *)buf);
|
||||
exit_server("connection denied");
|
||||
}
|
||||
}
|
||||
@ -860,7 +860,8 @@ void process_smb(char *inbuf, char *outbuf)
|
||||
nread, smb_len(outbuf)));
|
||||
}
|
||||
else
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("process_smb: send_smb failed.\n");
|
||||
}
|
||||
trans_num++;
|
||||
}
|
||||
|
@ -2487,7 +2487,8 @@ int reply_writebraw(connection_struct *conn, char *inbuf,char *outbuf, int size,
|
||||
CVAL(outbuf,smb_com) = SMBwritebraw;
|
||||
SSVALS(outbuf,smb_vwv0,-1);
|
||||
outsize = set_message(outbuf,Protocol>PROTOCOL_COREPLUS?1:0,0,True);
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("reply_writebraw: send_smb failed.\n");
|
||||
|
||||
/* Now read the raw data into the buffer and write it */
|
||||
if (read_smb_length(smbd_server_fd(),inbuf,SMB_SECONDARY_WAIT) == -1) {
|
||||
@ -3172,7 +3173,8 @@ int reply_echo(connection_struct *conn,
|
||||
|
||||
smb_setlen(outbuf,outsize - 4);
|
||||
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("reply_echo: send_smb failed.\n");
|
||||
}
|
||||
|
||||
DEBUG(3,("echo %d times\n", smb_reverb));
|
||||
@ -4552,7 +4554,8 @@ int reply_readbmpx(connection_struct *conn, char *inbuf,char *outbuf,int length,
|
||||
SSVAL(outbuf,smb_vwv6,nread);
|
||||
SSVAL(outbuf,smb_vwv7,smb_offset(data,outbuf));
|
||||
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("reply_readbmpx: send_smb failed.\n");
|
||||
|
||||
total_read += nread;
|
||||
startpos += nread;
|
||||
@ -4650,7 +4653,8 @@ int reply_writebmpx(connection_struct *conn, char *inbuf,char *outbuf, int size,
|
||||
if (write_through && tcount==nwritten) {
|
||||
/* we need to send both a primary and a secondary response */
|
||||
smb_setlen(outbuf,outsize - 4);
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("reply_writebmpx: send_smb failed.\n");
|
||||
|
||||
/* now the secondary */
|
||||
outsize = set_message(outbuf,1,0,True);
|
||||
|
@ -255,11 +255,13 @@ char *reqHosts, *resignHosts;
|
||||
if(msg_type != 0x81){ /* first packet must be a session request */
|
||||
DEBUG( 0, ( "Client %s did not use session setup; access denied\n",
|
||||
client_addr() ) );
|
||||
send_smb(fd, (char *)buf);
|
||||
if (!send_smb(fd, (char *)buf))
|
||||
exit_server("sslutil_negotiate_ssl: send_smb failed.\n");
|
||||
return -1;
|
||||
}
|
||||
buf[4] = 0x8e; /* negative session response: use SSL */
|
||||
send_smb(fd, (char *)buf);
|
||||
if (!send_smb(fd, (char *)buf))
|
||||
exit_server("sslutil_negotiate_ssl: send_smb failed.\n");
|
||||
if(sslutil_accept(fd) != 0){
|
||||
DEBUG( 0, ( "Client %s failed SSL negotiation!\n", client_addr() ) );
|
||||
return -1;
|
||||
|
@ -65,7 +65,8 @@ static int send_trans2_replies(char *outbuf, int bufsize, char *params,
|
||||
the empty packet */
|
||||
if(params_to_send == 0 && data_to_send == 0)
|
||||
{
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("send_trans2_replies: send_smb failed.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -160,7 +161,8 @@ static int send_trans2_replies(char *outbuf, int bufsize, char *params,
|
||||
params_to_send, data_to_send, paramsize, datasize));
|
||||
|
||||
/* Send the packet */
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("send_trans2_replies: send_smb failed.\n");
|
||||
|
||||
pp += params_sent_thistime;
|
||||
pd += data_sent_thistime;
|
||||
@ -2340,7 +2342,8 @@ int reply_trans2(connection_struct *conn,
|
||||
/* We need to send an interim response then receive the rest
|
||||
of the parameter/data bytes */
|
||||
outsize = set_message(outbuf,0,0,True);
|
||||
send_smb(smbd_server_fd(),outbuf);
|
||||
if (!send_smb(smbd_server_fd(),outbuf))
|
||||
exit_server("reply_trans2: send_smb failed.\n");
|
||||
|
||||
while (num_data_sofar < total_data ||
|
||||
num_params_sofar < total_params) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user