From c3effa8b599a6a0a2fe05487edc3a0d13e83d427 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 17 Aug 1998 13:11:34 +0000 Subject: this completes the splitup of server.c. the splitup was done with an axe, not a scalpel, so there are some rough edges. I mostly wanted to get the general form right with fine tuning of what goes where to come later. Still, this is better than what we had before where server.c was a general repository for anything that didn't fit elsewhere. (This used to be commit a6d194886a4a5f7507fa37289ff96c1be56f14a6) --- source3/smbd/process.c | 810 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 810 insertions(+) create mode 100644 source3/smbd/process.c (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c new file mode 100644 index 0000000000..30abfdb894 --- /dev/null +++ b/source3/smbd/process.c @@ -0,0 +1,810 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + process incoming packets - main loop + Copyright (C) Andrew Tridgell 1992-1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +extern int last_message; +extern int global_oplock_break; +extern pstring sesssetup_user; +extern char *last_inbuf; +extern time_t smb_last_time; +extern char *InBuffer; +extern char *OutBuffer; +extern int oplock_sock; +extern int smb_read_error; +extern BOOL reload_after_sighup; +extern BOOL global_machine_pasword_needs_changing; +extern fstring global_myworkgroup; +extern pstring global_myname; +extern int max_send; + + +/**************************************************************************** +Get the next SMB packet, doing the local message processing automatically. +****************************************************************************/ +BOOL receive_next_smb(int smbfd, int oplockfd, char *inbuf, int bufsize, int timeout) +{ + BOOL got_smb = False; + BOOL ret; + + do + { + ret = receive_message_or_smb(smbfd,oplockfd,inbuf,bufsize, + timeout,&got_smb); + + if(ret && !got_smb) + { + /* Deal with oplock break requests from other smbd's. */ + process_local_message(oplock_sock, inbuf, bufsize); + continue; + } + + if(ret && (CVAL(inbuf,0) == 0x85)) + { + /* Keepalive packet. */ + got_smb = False; + } + + } + while(ret && !got_smb); + + return ret; +} + + + +/**************************************************************************** + process an smb from the client - split out from the process() code so + it can be used by the oplock break code. +****************************************************************************/ +void process_smb(char *inbuf, char *outbuf) +{ + extern int Client; +#ifdef WITH_SSL + extern BOOL sslEnabled; /* don't use function for performance reasons */ + static int sslConnected = 0; +#endif /* WITH_SSL */ + static int trans_num; + int msg_type = CVAL(inbuf,0); + int32 len = smb_len(inbuf); + int nread = len + 4; + + if (trans_num == 0) { + /* on the first packet, check the global hosts allow/ hosts + deny parameters before doing any parsing of the packet + passed to us by the client. This prevents attacks on our + parsing code from hosts not in the hosts allow list */ + if (!check_access(Client, lp_hostsallow(-1), lp_hostsdeny(-1))) { + /* send a negative session response "not listining on calling + name" */ + static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; + DEBUG( 1, ( "Connection denied from %s\n", + client_addr(Client) ) ); + send_smb(Client,(char *)buf); + exit_server("connection denied"); + } + } + + DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type, len ) ); + DEBUG( 3, ( "Transaction %d of length %d\n", trans_num, nread ) ); + +#ifdef WITH_SSL + if(sslEnabled && !sslConnected){ + sslConnected = sslutil_negotiate_ssl(Client, msg_type); + if(sslConnected < 0){ /* an error occured */ + exit_server("SSL negotiation failed"); + }else if(sslConnected){ + trans_num++; + return; + } + } +#endif /* WITH_SSL */ + +#ifdef WITH_VTP + if(trans_num == 1 && VT_Check(inbuf)) + { + VT_Process(); + return; + } +#endif + + if (msg_type == 0) + show_msg(inbuf); + else if(msg_type == 0x85) + return; /* Keepalive packet. */ + + nread = construct_reply(inbuf,outbuf,nread,max_send); + + if(nread > 0) + { + if (CVAL(outbuf,0) == 0) + show_msg(outbuf); + + if (nread != smb_len(outbuf) + 4) + { + DEBUG(0,("ERROR: Invalid message response size! %d %d\n", + nread, smb_len(outbuf))); + } + else + send_smb(Client,outbuf); + } + trans_num++; +} + + +/* +These flags determine some of the permissions required to do an operation + +Note that I don't set NEED_WRITE on some write operations because they +are used by some brain-dead clients when printing, and I don't want to +force write permissions on print services. +*/ +#define AS_USER (1<<0) +#define NEED_WRITE (1<<1) +#define TIME_INIT (1<<2) +#define CAN_IPC (1<<3) +#define AS_GUEST (1<<5) +#define QUEUE_IN_OPLOCK (1<<6) + +/* + define a list of possible SMB messages and their corresponding + functions. Any message that has a NULL function is unimplemented - + please feel free to contribute implementations! +*/ +struct smb_message_struct +{ + int code; + char *name; + int (*fn)(connection_struct *conn, char *, char *, int, int); + int flags; +#if PROFILING + unsigned long time; +#endif +} + smb_messages[] = { + + /* CORE PROTOCOL */ + + {SMBnegprot,"SMBnegprot",reply_negprot,0}, + {SMBtcon,"SMBtcon",reply_tcon,0}, + {SMBtdis,"SMBtdis",reply_tdis,0}, + {SMBexit,"SMBexit",reply_exit,0}, + {SMBioctl,"SMBioctl",reply_ioctl,0}, + {SMBecho,"SMBecho",reply_echo,0}, + {SMBsesssetupX,"SMBsesssetupX",reply_sesssetup_and_X,0}, + {SMBtconX,"SMBtconX",reply_tcon_and_X,0}, + {SMBulogoffX, "SMBulogoffX", reply_ulogoffX, 0}, /* ulogoff doesn't give a valid TID */ + {SMBgetatr,"SMBgetatr",reply_getatr,AS_USER}, + {SMBsetatr,"SMBsetatr",reply_setatr,AS_USER | NEED_WRITE}, + {SMBchkpth,"SMBchkpth",reply_chkpth,AS_USER}, + {SMBsearch,"SMBsearch",reply_search,AS_USER}, + {SMBopen,"SMBopen",reply_open,AS_USER | QUEUE_IN_OPLOCK }, + + /* note that SMBmknew and SMBcreate are deliberately overloaded */ + {SMBcreate,"SMBcreate",reply_mknew,AS_USER}, + {SMBmknew,"SMBmknew",reply_mknew,AS_USER}, + + {SMBunlink,"SMBunlink",reply_unlink,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK}, + {SMBread,"SMBread",reply_read,AS_USER}, + {SMBwrite,"SMBwrite",reply_write,AS_USER}, + {SMBclose,"SMBclose",reply_close,AS_USER | CAN_IPC}, + {SMBmkdir,"SMBmkdir",reply_mkdir,AS_USER | NEED_WRITE}, + {SMBrmdir,"SMBrmdir",reply_rmdir,AS_USER | NEED_WRITE}, + {SMBdskattr,"SMBdskattr",reply_dskattr,AS_USER}, + {SMBmv,"SMBmv",reply_mv,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK}, + + /* this is a Pathworks specific call, allowing the + changing of the root path */ + {pSETDIR,"pSETDIR",reply_setdir,AS_USER}, + + {SMBlseek,"SMBlseek",reply_lseek,AS_USER}, + {SMBflush,"SMBflush",reply_flush,AS_USER}, + {SMBctemp,"SMBctemp",reply_ctemp,AS_USER | QUEUE_IN_OPLOCK }, + {SMBsplopen,"SMBsplopen",reply_printopen,AS_USER | QUEUE_IN_OPLOCK }, + {SMBsplclose,"SMBsplclose",reply_printclose,AS_USER}, + {SMBsplretq,"SMBsplretq",reply_printqueue,AS_USER}, + {SMBsplwr,"SMBsplwr",reply_printwrite,AS_USER}, + {SMBlock,"SMBlock",reply_lock,AS_USER}, + {SMBunlock,"SMBunlock",reply_unlock,AS_USER}, + + /* CORE+ PROTOCOL FOLLOWS */ + + {SMBreadbraw,"SMBreadbraw",reply_readbraw,AS_USER}, + {SMBwritebraw,"SMBwritebraw",reply_writebraw,AS_USER}, + {SMBwriteclose,"SMBwriteclose",reply_writeclose,AS_USER}, + {SMBlockread,"SMBlockread",reply_lockread,AS_USER}, + {SMBwriteunlock,"SMBwriteunlock",reply_writeunlock,AS_USER}, + + /* LANMAN1.0 PROTOCOL FOLLOWS */ + + {SMBreadBmpx,"SMBreadBmpx",reply_readbmpx,AS_USER}, + {SMBreadBs,"SMBreadBs",NULL,AS_USER}, + {SMBwriteBmpx,"SMBwriteBmpx",reply_writebmpx,AS_USER}, + {SMBwriteBs,"SMBwriteBs",reply_writebs,AS_USER}, + {SMBwritec,"SMBwritec",NULL,AS_USER}, + {SMBsetattrE,"SMBsetattrE",reply_setattrE,AS_USER | NEED_WRITE}, + {SMBgetattrE,"SMBgetattrE",reply_getattrE,AS_USER}, + {SMBtrans,"SMBtrans",reply_trans,AS_USER | CAN_IPC}, + {SMBtranss,"SMBtranss",NULL,AS_USER | CAN_IPC}, + {SMBioctls,"SMBioctls",NULL,AS_USER}, + {SMBcopy,"SMBcopy",reply_copy,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK }, + {SMBmove,"SMBmove",NULL,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK }, + + {SMBopenX,"SMBopenX",reply_open_and_X,AS_USER | CAN_IPC | QUEUE_IN_OPLOCK }, + {SMBreadX,"SMBreadX",reply_read_and_X,AS_USER | CAN_IPC }, + {SMBwriteX,"SMBwriteX",reply_write_and_X,AS_USER}, + {SMBlockingX,"SMBlockingX",reply_lockingX,AS_USER}, + + {SMBffirst,"SMBffirst",reply_search,AS_USER}, + {SMBfunique,"SMBfunique",reply_search,AS_USER}, + {SMBfclose,"SMBfclose",reply_fclose,AS_USER}, + + /* LANMAN2.0 PROTOCOL FOLLOWS */ + {SMBfindnclose, "SMBfindnclose", reply_findnclose, AS_USER}, + {SMBfindclose, "SMBfindclose", reply_findclose,AS_USER}, + {SMBtrans2, "SMBtrans2", reply_trans2, AS_USER }, + {SMBtranss2, "SMBtranss2", reply_transs2, AS_USER}, + + /* NT PROTOCOL FOLLOWS */ + {SMBntcreateX, "SMBntcreateX", reply_ntcreate_and_X, AS_USER | CAN_IPC | QUEUE_IN_OPLOCK }, + {SMBnttrans, "SMBnttrans", reply_nttrans, AS_USER | CAN_IPC }, + {SMBnttranss, "SMBnttranss", reply_nttranss, AS_USER | CAN_IPC }, + {SMBntcancel, "SMBntcancel", reply_ntcancel, AS_USER }, + + /* messaging routines */ + {SMBsends,"SMBsends",reply_sends,AS_GUEST}, + {SMBsendstrt,"SMBsendstrt",reply_sendstrt,AS_GUEST}, + {SMBsendend,"SMBsendend",reply_sendend,AS_GUEST}, + {SMBsendtxt,"SMBsendtxt",reply_sendtxt,AS_GUEST}, + + /* NON-IMPLEMENTED PARTS OF THE CORE PROTOCOL */ + + {SMBsendb,"SMBsendb",NULL,AS_GUEST}, + {SMBfwdname,"SMBfwdname",NULL,AS_GUEST}, + {SMBcancelf,"SMBcancelf",NULL,AS_GUEST}, + {SMBgetmac,"SMBgetmac",NULL,AS_GUEST} + }; + +/**************************************************************************** +return a string containing the function name of a SMB command +****************************************************************************/ +char *smb_fn_name(int type) +{ + static char *unknown_name = "SMBunknown"; + static int num_smb_messages = + sizeof(smb_messages) / sizeof(struct smb_message_struct); + int match; + + for (match=0;matchrequested_name); + } + + /* does this protocol need to be run as root? */ + if (!(flags & AS_USER)) + unbecome_user(); + + /* does this protocol need to be run as the connected user? */ + if ((flags & AS_USER) && !become_user(conn,session_tag)) { + if (flags & AS_GUEST) + flags &= ~AS_USER; + else + return(ERROR(ERRSRV,ERRinvnid)); + } + /* this code is to work around a bug is MS client 3 without + introducing a security hole - it needs to be able to do + print queue checks as guest if it isn't logged in properly */ + if (flags & AS_USER) + flags &= ~AS_GUEST; + + /* does it need write permission? */ + if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) + return(ERROR(ERRSRV,ERRaccess)); + + /* ipc services are limited */ + if (IS_IPC(conn) && (flags & AS_USER) && !(flags & CAN_IPC)) { + return(ERROR(ERRSRV,ERRaccess)); + } + + /* load service specific parameters */ + if (conn && + !become_service(conn,(flags & AS_USER)?True:False)) { + return(ERROR(ERRSRV,ERRaccess)); + } + + /* does this protocol need to be run as guest? */ + if ((flags & AS_GUEST) && + (!become_guest() || + !check_access(Client, lp_hostsallow(-1), lp_hostsdeny(-1)))) { + return(ERROR(ERRSRV,ERRaccess)); + } + + last_inbuf = inbuf; + + outsize = smb_messages[match].fn(conn, inbuf,outbuf,size,bufsize); + } + else + { + outsize = reply_unknown(inbuf,outbuf); + } + } + +#if PROFILING + GetTimeOfDay(&msg_end_time); + if (!(smb_messages[match].flags & TIME_INIT)) + { + smb_messages[match].time = 0; + smb_messages[match].flags |= TIME_INIT; + } + { + unsigned long this_time = + (msg_end_time.tv_sec - msg_start_time.tv_sec)*1e6 + + (msg_end_time.tv_usec - msg_start_time.tv_usec); + smb_messages[match].time += this_time; + total_time += this_time; + } + DEBUG(2,("TIME %s %d usecs %g pct\n", + smb_fn_name(type),smb_messages[match].time, + (100.0*smb_messages[match].time) / total_time)); +#endif + + return(outsize); +} + + +/**************************************************************************** + construct a chained reply and add it to the already made reply + **************************************************************************/ +int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) +{ + static char *orig_inbuf; + static char *orig_outbuf; + int smb_com1, smb_com2 = CVAL(inbuf,smb_vwv0); + unsigned smb_off2 = SVAL(inbuf,smb_vwv1); + char *inbuf2, *outbuf2; + int outsize2; + char inbuf_saved[smb_wct]; + char outbuf_saved[smb_wct]; + extern int chain_size; + int wct = CVAL(outbuf,smb_wct); + int outsize = smb_size + 2*wct + SVAL(outbuf,smb_vwv0+2*wct); + + /* maybe its not chained */ + if (smb_com2 == 0xFF) { + CVAL(outbuf,smb_vwv0) = 0xFF; + return outsize; + } + + if (chain_size == 0) { + /* this is the first part of the chain */ + orig_inbuf = inbuf; + orig_outbuf = outbuf; + } + + /* we need to tell the client where the next part of the reply will be */ + SSVAL(outbuf,smb_vwv1,smb_offset(outbuf+outsize,outbuf)); + CVAL(outbuf,smb_vwv0) = smb_com2; + + /* remember how much the caller added to the chain, only counting stuff + after the parameter words */ + chain_size += outsize - smb_wct; + + /* work out pointers into the original packets. The + headers on these need to be filled in */ + inbuf2 = orig_inbuf + smb_off2 + 4 - smb_wct; + outbuf2 = orig_outbuf + SVAL(outbuf,smb_vwv1) + 4 - smb_wct; + + /* remember the original command type */ + smb_com1 = CVAL(orig_inbuf,smb_com); + + /* save the data which will be overwritten by the new headers */ + memcpy(inbuf_saved,inbuf2,smb_wct); + memcpy(outbuf_saved,outbuf2,smb_wct); + + /* give the new packet the same header as the last part of the SMB */ + memmove(inbuf2,inbuf,smb_wct); + + /* create the in buffer */ + CVAL(inbuf2,smb_com) = smb_com2; + + /* create the out buffer */ + bzero(outbuf2,smb_size); + set_message(outbuf2,0,0,True); + CVAL(outbuf2,smb_com) = CVAL(inbuf2,smb_com); + + memcpy(outbuf2+4,inbuf2+4,4); + CVAL(outbuf2,smb_rcls) = SMB_SUCCESS; + CVAL(outbuf2,smb_reh) = 0; + CVAL(outbuf2,smb_flg) = 0x80 | (CVAL(inbuf2,smb_flg) & 0x8); /* bit 7 set + means a reply */ + SSVAL(outbuf2,smb_flg2,1); /* say we support long filenames */ + SSVAL(outbuf2,smb_err,SMB_SUCCESS); + SSVAL(outbuf2,smb_tid,SVAL(inbuf2,smb_tid)); + SSVAL(outbuf2,smb_pid,SVAL(inbuf2,smb_pid)); + SSVAL(outbuf2,smb_uid,SVAL(inbuf2,smb_uid)); + SSVAL(outbuf2,smb_mid,SVAL(inbuf2,smb_mid)); + + DEBUG(3,("Chained message\n")); + show_msg(inbuf2); + + /* process the request */ + outsize2 = switch_message(smb_com2,inbuf2,outbuf2,size-chain_size, + bufsize-chain_size); + + /* copy the new reply and request headers over the old ones, but + preserve the smb_com field */ + memmove(orig_outbuf,outbuf2,smb_wct); + CVAL(orig_outbuf,smb_com) = smb_com1; + + /* restore the saved data, being careful not to overwrite any + data from the reply header */ + memcpy(inbuf2,inbuf_saved,smb_wct); + { + int ofs = smb_wct - PTR_DIFF(outbuf2,orig_outbuf); + if (ofs < 0) ofs = 0; + memmove(outbuf2+ofs,outbuf_saved+ofs,smb_wct-ofs); + } + + return outsize2; +} + + +/**************************************************************************** + Helper function for contruct_reply. +****************************************************************************/ + +void construct_reply_common(char *inbuf,char *outbuf) +{ + bzero(outbuf,smb_size); + + CVAL(outbuf,smb_com) = CVAL(inbuf,smb_com); + set_message(outbuf,0,0,True); + + memcpy(outbuf+4,inbuf+4,4); + CVAL(outbuf,smb_rcls) = SMB_SUCCESS; + CVAL(outbuf,smb_reh) = 0; + CVAL(outbuf,smb_flg) = 0x80 | (CVAL(inbuf,smb_flg) & 0x8); /* bit 7 set + means a reply */ + SSVAL(outbuf,smb_flg2,1); /* say we support long filenames */ + SSVAL(outbuf,smb_err,SMB_SUCCESS); + SSVAL(outbuf,smb_tid,SVAL(inbuf,smb_tid)); + SSVAL(outbuf,smb_pid,SVAL(inbuf,smb_pid)); + SSVAL(outbuf,smb_uid,SVAL(inbuf,smb_uid)); + SSVAL(outbuf,smb_mid,SVAL(inbuf,smb_mid)); +} + +/**************************************************************************** + construct a reply to the incoming packet +****************************************************************************/ +int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) +{ + int type = CVAL(inbuf,smb_com); + int outsize = 0; + int msg_type = CVAL(inbuf,0); + extern int chain_size; + + smb_last_time = time(NULL); + + chain_size = 0; + file_chain_reset(); + reset_chain_p(); + + if (msg_type != 0) + return(reply_special(inbuf,outbuf)); + + construct_reply_common(inbuf, outbuf); + + outsize = switch_message(type,inbuf,outbuf,size,bufsize); + + outsize += chain_size; + + if(outsize > 4) + smb_setlen(outbuf,outsize - 4); + return(outsize); +} + +/**************************************************************************** + process commands from the client +****************************************************************************/ +void smbd_process(void) +{ + extern int Client; + + InBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + OutBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + if ((InBuffer == NULL) || (OutBuffer == NULL)) + return; + + InBuffer += SMB_ALIGNMENT; + OutBuffer += SMB_ALIGNMENT; + +#if PRIME_NMBD + DEBUG(3,("priming nmbd\n")); + { + struct in_addr ip; + ip = *interpret_addr2("localhost"); + if (zero_ip(ip)) ip = *interpret_addr2("127.0.0.1"); + *OutBuffer = 0; + send_one_packet(OutBuffer,1,ip,NMB_PORT,SOCK_DGRAM); + } +#endif + + /* re-initialise the timezone */ + TimeInit(); + + while (True) + { + int deadtime = lp_deadtime()*60; + int counter; + int last_keepalive=0; + int service_load_counter = 0; + BOOL got_smb = False; + + if (deadtime <= 0) + deadtime = DEFAULT_SMBD_TIMEOUT; + +#if USE_READ_PREDICTION + if (lp_readprediction()) + do_read_prediction(); +#endif + + errno = 0; + + for (counter=SMBD_SELECT_LOOP; + !receive_message_or_smb(Client,oplock_sock, + InBuffer,BUFFER_SIZE,SMBD_SELECT_LOOP*1000,&got_smb); + counter += SMBD_SELECT_LOOP) + { + time_t t; + BOOL allidle = True; + extern int keepalive; + + if (counter > 365 * 3600) /* big number of seconds. */ + { + counter = 0; + service_load_counter = 0; + } + + if (smb_read_error == READ_EOF) + { + DEBUG(3,("end of file from client\n")); + return; + } + + if (smb_read_error == READ_ERROR) + { + DEBUG(3,("receive_smb error (%s) exiting\n", + strerror(errno))); + return; + } + + t = time(NULL); + + /* become root again if waiting */ + unbecome_user(); + + /* check for smb.conf reload */ + if (counter >= service_load_counter + SMBD_RELOAD_CHECK) + { + service_load_counter = counter; + + /* reload services, if files have changed. */ + reload_services(True); + } + + /* + * If reload_after_sighup == True then we got a SIGHUP + * and are being asked to reload. Fix from + */ + + if (reload_after_sighup) + { + DEBUG(0,("Reloading services after SIGHUP\n")); + reload_services(False); + reload_after_sighup = False; + } + + /* automatic timeout if all connections are closed */ + if (conn_num_open()==0 && counter >= IDLE_CLOSED_TIMEOUT) + { + DEBUG( 2, ( "Closing idle connection\n" ) ); + return; + } + + if (keepalive && (counter-last_keepalive)>keepalive) + { + struct cli_state *cli = server_client(); + if (!send_keepalive(Client)) { + DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); + return; + } + /* also send a keepalive to the password server if its still + connected */ + if (cli && cli->initialised) + send_keepalive(cli->fd); + last_keepalive = counter; + } + + /* check for connection timeouts */ + allidle = conn_idle_all(t, deadtime); + + if (allidle && conn_num_open()>0) { + DEBUG(2,("Closing idle connection 2.\n")); + return; + } + + if(global_machine_pasword_needs_changing) + { + unsigned char trust_passwd_hash[16]; + time_t lct; + pstring remote_machine_list; + + /* + * We're in domain level security, and the code that + * read the machine password flagged that the machine + * password needs changing. + */ + + /* + * First, open the machine password file with an exclusive lock. + */ + + if(!trust_password_lock( global_myworkgroup, global_myname, True)) { + DEBUG(0,("process: unable to open the machine account password file for \ +machine %s in domain %s.\n", global_myname, global_myworkgroup )); + continue; + } + + if(!get_trust_account_password( trust_passwd_hash, &lct)) { + DEBUG(0,("process: unable to read the machine account password for \ +machine %s in domain %s.\n", global_myname, global_myworkgroup )); + trust_password_unlock(); + continue; + } + + /* + * Make sure someone else hasn't already done this. + */ + + if(t < lct + lp_machine_password_timeout()) { + trust_password_unlock(); + global_machine_pasword_needs_changing = False; + continue; + } + + pstrcpy(remote_machine_list, lp_passwordserver()); + + change_trust_account_password( global_myworkgroup, remote_machine_list); + trust_password_unlock(); + global_machine_pasword_needs_changing = False; + } + + /* + * Check to see if we have any change notifies + * outstanding on the queue. + */ + process_pending_change_notify_queue(t); + } + + if(got_smb) + process_smb(InBuffer, OutBuffer); + else + process_local_message(oplock_sock, InBuffer, BUFFER_SIZE); + } +} -- cgit From dd2e202e5c8d6220e29becb48fde333fa5258794 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 17 Aug 1998 13:44:05 +0000 Subject: move soem variables from server.c that don't belong there. (This used to be commit f92475aa3cb3ade576c39c02c7996c949c42082a) --- source3/smbd/process.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 30abfdb894..acc89ae146 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -23,11 +23,24 @@ extern int DEBUGLEVEL; +time_t smb_last_time=(time_t)0; + +/* + * Size of data we can send to client. Set + * by the client for all protocols above CORE. + * Set by us for CORE protocol. + */ +int max_send = BUFFER_SIZE; +/* + * Size of the data we can receive. Set by us. + * Can be modified by the max xmit parameter. + */ +int max_recv = BUFFER_SIZE; + extern int last_message; extern int global_oplock_break; extern pstring sesssetup_user; extern char *last_inbuf; -extern time_t smb_last_time; extern char *InBuffer; extern char *OutBuffer; extern int oplock_sock; @@ -645,6 +658,9 @@ void smbd_process(void) } #endif + + max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); + /* re-initialise the timezone */ TimeInit(); -- cgit From 28788ca46c06d00a472949fd3de7b64988925283 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 17 Aug 1998 14:11:44 +0000 Subject: removed some of the rough edges from the splitup (This used to be commit 722312c326d54849e2552327fcd88ac77257ad2c) --- source3/smbd/process.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index acc89ae146..756e010d9e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -25,6 +25,11 @@ extern int DEBUGLEVEL; time_t smb_last_time=(time_t)0; +char *InBuffer = NULL; +char *OutBuffer = NULL; +char *last_inbuf = NULL; + + /* * Size of data we can send to client. Set * by the client for all protocols above CORE. -- cgit From dc76502cd8a950f6aff84ce4eedfd9d2b30d3dcc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 20 Aug 1998 19:28:37 +0000 Subject: Turning on blocking locking code. NB. Blocking lock requests that are not the head of an SMB request (ie. are part of a chain) will not be queued - this will be fixed when we move to the new chain code. In practice, this doesn't seem to cause much of a problem (in my admittedly limited testing) bug a debug level zero message will be placed in the log when this happens to help determine how real the problem is. smbd/locking.c: New debug messages. smbd/blocking.c: New blocking code - handles SMBlock, SMBlockread and SMBlockingX smbd/chgpasswd.c: Fix for master fd leak. smbd/files.c: Tidyup comment. smbd/nttrans.c: Added fnum to debug message. smbd/process.c: Made chain_reply() use construct_reply_common(). Added blocking lock queue processing into idle loop. smbd/reply.c: Added queue pushes for SMBlock, SMBlockread and SMBlockingX. Jeremy. (This used to be commit e1dd03ecda0bc6d7eaa31070c83774bb5679fd1b) --- source3/smbd/process.c | 72 ++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 41 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 756e010d9e..5bf8cdb2b1 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -29,7 +29,6 @@ char *InBuffer = NULL; char *OutBuffer = NULL; char *last_inbuf = NULL; - /* * Size of data we can send to client. Set * by the client for all protocols above CORE. @@ -485,6 +484,29 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize return(outsize); } +/**************************************************************************** + Helper function for contruct_reply. +****************************************************************************/ + +void construct_reply_common(char *inbuf,char *outbuf) +{ + bzero(outbuf,smb_size); + + set_message(outbuf,0,0,True); + CVAL(outbuf,smb_com) = CVAL(inbuf,smb_com); + + memcpy(outbuf+4,inbuf+4,4); + CVAL(outbuf,smb_rcls) = SMB_SUCCESS; + CVAL(outbuf,smb_reh) = 0; + CVAL(outbuf,smb_flg) = 0x80 | (CVAL(inbuf,smb_flg) & 0x8); /* bit 7 set + means a reply */ + SSVAL(outbuf,smb_flg2,1); /* say we support long filenames */ + SSVAL(outbuf,smb_err,SMB_SUCCESS); + SSVAL(outbuf,smb_tid,SVAL(inbuf,smb_tid)); + SSVAL(outbuf,smb_pid,SVAL(inbuf,smb_pid)); + SSVAL(outbuf,smb_uid,SVAL(inbuf,smb_uid)); + SSVAL(outbuf,smb_mid,SVAL(inbuf,smb_mid)); +} /**************************************************************************** construct a chained reply and add it to the already made reply @@ -542,21 +564,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) CVAL(inbuf2,smb_com) = smb_com2; /* create the out buffer */ - bzero(outbuf2,smb_size); - set_message(outbuf2,0,0,True); - CVAL(outbuf2,smb_com) = CVAL(inbuf2,smb_com); - - memcpy(outbuf2+4,inbuf2+4,4); - CVAL(outbuf2,smb_rcls) = SMB_SUCCESS; - CVAL(outbuf2,smb_reh) = 0; - CVAL(outbuf2,smb_flg) = 0x80 | (CVAL(inbuf2,smb_flg) & 0x8); /* bit 7 set - means a reply */ - SSVAL(outbuf2,smb_flg2,1); /* say we support long filenames */ - SSVAL(outbuf2,smb_err,SMB_SUCCESS); - SSVAL(outbuf2,smb_tid,SVAL(inbuf2,smb_tid)); - SSVAL(outbuf2,smb_pid,SVAL(inbuf2,smb_pid)); - SSVAL(outbuf2,smb_uid,SVAL(inbuf2,smb_uid)); - SSVAL(outbuf2,smb_mid,SVAL(inbuf2,smb_mid)); + construct_reply_common(inbuf2, outbuf2); DEBUG(3,("Chained message\n")); show_msg(inbuf2); @@ -582,34 +590,10 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) return outsize2; } - -/**************************************************************************** - Helper function for contruct_reply. -****************************************************************************/ - -void construct_reply_common(char *inbuf,char *outbuf) -{ - bzero(outbuf,smb_size); - - CVAL(outbuf,smb_com) = CVAL(inbuf,smb_com); - set_message(outbuf,0,0,True); - - memcpy(outbuf+4,inbuf+4,4); - CVAL(outbuf,smb_rcls) = SMB_SUCCESS; - CVAL(outbuf,smb_reh) = 0; - CVAL(outbuf,smb_flg) = 0x80 | (CVAL(inbuf,smb_flg) & 0x8); /* bit 7 set - means a reply */ - SSVAL(outbuf,smb_flg2,1); /* say we support long filenames */ - SSVAL(outbuf,smb_err,SMB_SUCCESS); - SSVAL(outbuf,smb_tid,SVAL(inbuf,smb_tid)); - SSVAL(outbuf,smb_pid,SVAL(inbuf,smb_pid)); - SSVAL(outbuf,smb_uid,SVAL(inbuf,smb_uid)); - SSVAL(outbuf,smb_mid,SVAL(inbuf,smb_mid)); -} - /**************************************************************************** construct a reply to the incoming packet ****************************************************************************/ + int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) { int type = CVAL(inbuf,smb_com); @@ -816,6 +800,12 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); global_machine_pasword_needs_changing = False; } + /* + * Check to see if we have any blocking locks + * outstanding on the queue. + */ + process_blocking_lock_queue(t); + /* * Check to see if we have any change notifies * outstanding on the queue. -- cgit From 5e5e320d361afcb4d9503354b3912b4c7a672197 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 Aug 1998 20:38:53 +0000 Subject: This is the stat cache code - seems to work fine (needs heavy NetBench testing though.... :-). Attempts to efficiently reduce the number of stat() calls Samba does. Jeremy. (This used to be commit d0e48a2d8072c3e77a57ac6a2fb5044c05f03b41) --- source3/smbd/process.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 5bf8cdb2b1..63e51dc242 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -723,6 +723,10 @@ void smbd_process(void) DEBUG(0,("Reloading services after SIGHUP\n")); reload_services(False); reload_after_sighup = False; + /* + * Use this as an excuse to print some stats. + */ + print_stat_cache_statistics(); } /* automatic timeout if all connections are closed */ -- cgit From e9ea36e4d2270bd7d32da12ef6d6e2299641582d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 5 Sep 1998 05:07:05 +0000 Subject: tridge the destroyer returns! prompted by the interpret_security() dead code that Jean-Francois pointed out I added a make target "finddead" that finds potentially dead (ie. unused) code. It spat out 304 function names ... I went through these are deleted many of them, making others static (finddead also reports functions that are used only in the local file). in doing this I have almost certainly deleted some useful code. I may have even prevented compilation with some compile options. I apologise. I decided it was better to get rid of this code now and add back the one or two functions that are needed than to keep all this baggage. So, if I have done a bit too much "destroying" then let me know. Keep the swearing to a minimum :) One bit I didn't do is the ubibt code. Chris, can you look at that? Heaps of unused functions there. Can they be made static? (This used to be commit 2204475c87f3024ea8fd1fbd7385b2def617a46f) --- source3/smbd/process.c | 286 ++++++++++++++++++++++--------------------------- 1 file changed, 129 insertions(+), 157 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 63e51dc242..b72178013d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -89,86 +89,6 @@ BOOL receive_next_smb(int smbfd, int oplockfd, char *inbuf, int bufsize, int tim } - -/**************************************************************************** - process an smb from the client - split out from the process() code so - it can be used by the oplock break code. -****************************************************************************/ -void process_smb(char *inbuf, char *outbuf) -{ - extern int Client; -#ifdef WITH_SSL - extern BOOL sslEnabled; /* don't use function for performance reasons */ - static int sslConnected = 0; -#endif /* WITH_SSL */ - static int trans_num; - int msg_type = CVAL(inbuf,0); - int32 len = smb_len(inbuf); - int nread = len + 4; - - if (trans_num == 0) { - /* on the first packet, check the global hosts allow/ hosts - deny parameters before doing any parsing of the packet - passed to us by the client. This prevents attacks on our - parsing code from hosts not in the hosts allow list */ - if (!check_access(Client, lp_hostsallow(-1), lp_hostsdeny(-1))) { - /* send a negative session response "not listining on calling - name" */ - static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; - DEBUG( 1, ( "Connection denied from %s\n", - client_addr(Client) ) ); - send_smb(Client,(char *)buf); - exit_server("connection denied"); - } - } - - DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type, len ) ); - DEBUG( 3, ( "Transaction %d of length %d\n", trans_num, nread ) ); - -#ifdef WITH_SSL - if(sslEnabled && !sslConnected){ - sslConnected = sslutil_negotiate_ssl(Client, msg_type); - if(sslConnected < 0){ /* an error occured */ - exit_server("SSL negotiation failed"); - }else if(sslConnected){ - trans_num++; - return; - } - } -#endif /* WITH_SSL */ - -#ifdef WITH_VTP - if(trans_num == 1 && VT_Check(inbuf)) - { - VT_Process(); - return; - } -#endif - - if (msg_type == 0) - show_msg(inbuf); - else if(msg_type == 0x85) - return; /* Keepalive packet. */ - - nread = construct_reply(inbuf,outbuf,nread,max_send); - - if(nread > 0) - { - if (CVAL(outbuf,0) == 0) - show_msg(outbuf); - - if (nread != smb_len(outbuf) + 4) - { - DEBUG(0,("ERROR: Invalid message response size! %d %d\n", - nread, smb_len(outbuf))); - } - else - send_smb(Client,outbuf); - } - trans_num++; -} - - /* These flags determine some of the permissions required to do an operation @@ -194,9 +114,6 @@ struct smb_message_struct char *name; int (*fn)(connection_struct *conn, char *, char *, int, int); int flags; -#if PROFILING - unsigned long time; -#endif } smb_messages[] = { @@ -302,26 +219,6 @@ struct smb_message_struct {SMBgetmac,"SMBgetmac",NULL,AS_GUEST} }; -/**************************************************************************** -return a string containing the function name of a SMB command -****************************************************************************/ -char *smb_fn_name(int type) -{ - static char *unknown_name = "SMBunknown"; - static int num_smb_messages = - sizeof(smb_messages) / sizeof(struct smb_message_struct); - int match; - - for (match=0;match 4) + smb_setlen(outbuf,outsize - 4); + return(outsize); +} + + +/**************************************************************************** + process an smb from the client - split out from the process() code so + it can be used by the oplock break code. +****************************************************************************/ +void process_smb(char *inbuf, char *outbuf) +{ + extern int Client; +#ifdef WITH_SSL + extern BOOL sslEnabled; /* don't use function for performance reasons */ + static int sslConnected = 0; +#endif /* WITH_SSL */ + static int trans_num; + int msg_type = CVAL(inbuf,0); + int32 len = smb_len(inbuf); + int nread = len + 4; + + if (trans_num == 0) { + /* on the first packet, check the global hosts allow/ hosts + deny parameters before doing any parsing of the packet + passed to us by the client. This prevents attacks on our + parsing code from hosts not in the hosts allow list */ + if (!check_access(Client, lp_hostsallow(-1), lp_hostsdeny(-1))) { + /* send a negative session response "not listining on calling + name" */ + static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; + DEBUG( 1, ( "Connection denied from %s\n", + client_addr(Client) ) ); + send_smb(Client,(char *)buf); + exit_server("connection denied"); + } } + + DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type, len ) ); + DEBUG( 3, ( "Transaction %d of length %d\n", trans_num, nread ) ); + +#ifdef WITH_SSL + if(sslEnabled && !sslConnected){ + sslConnected = sslutil_negotiate_ssl(Client, msg_type); + if(sslConnected < 0){ /* an error occured */ + exit_server("SSL negotiation failed"); + }else if(sslConnected){ + trans_num++; + return; + } + } +#endif /* WITH_SSL */ + +#ifdef WITH_VTP + if(trans_num == 1 && VT_Check(inbuf)) { - unsigned long this_time = - (msg_end_time.tv_sec - msg_start_time.tv_sec)*1e6 + - (msg_end_time.tv_usec - msg_start_time.tv_usec); - smb_messages[match].time += this_time; - total_time += this_time; + VT_Process(); + return; } - DEBUG(2,("TIME %s %d usecs %g pct\n", - smb_fn_name(type),smb_messages[match].time, - (100.0*smb_messages[match].time) / total_time)); #endif - return(outsize); + if (msg_type == 0) + show_msg(inbuf); + else if(msg_type == 0x85) + return; /* Keepalive packet. */ + + nread = construct_reply(inbuf,outbuf,nread,max_send); + + if(nread > 0) + { + if (CVAL(outbuf,0) == 0) + show_msg(outbuf); + + if (nread != smb_len(outbuf) + 4) + { + DEBUG(0,("ERROR: Invalid message response size! %d %d\n", + nread, smb_len(outbuf))); + } + else + send_smb(Client,outbuf); + } + trans_num++; +} + + + +/**************************************************************************** +return a string containing the function name of a SMB command +****************************************************************************/ +char *smb_fn_name(int type) +{ + static char *unknown_name = "SMBunknown"; + static int num_smb_messages = + sizeof(smb_messages) / sizeof(struct smb_message_struct); + int match; + + for (match=0;match 4) - smb_setlen(outbuf,outsize - 4); - return(outsize); -} - /**************************************************************************** process commands from the client ****************************************************************************/ -- cgit From b8b67f4fab4a6fd686c5796c2701882197a7bd9d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 17 Sep 1998 23:06:57 +0000 Subject: configure configure.in: Added checks for statvfs64. Last bit of 64 bit widening (I hope :-). include/config.h.in: Added #undef STAT_STATVFS64. include/includes.h: Added SMB_STRUCT_STATVFS type, Changed SMB_BIG_INTEGER to SMB_BIG_UINT and SMB_BIG_INT types. include/smb.h: Added flag defines from CIFS spec. lib/debug.c: Fixed one more mode_t issue. lib/system.c: Added sys_statvfs wrapper. lib/util.c: Changed trim_string to use size_t. param/loadparm.c: Moved "blocking locks" into locking section. Alphabetised locking options. Question - shuld we do this for all options ? passdb/ldap.c: Changed SMB_BIG_INTEGER to SMB_BIG_UINT. passdb/nispass.c: Changed SMB_BIG_INTEGER to SMB_BIG_UINT. passdb/smbpass.c: Changed SMB_BIG_INTEGER to SMB_BIG_UINT. smbd/dfree.c: Changed to use 64 bit types if available. Moved to use unsigned types. smbd/dosmode.c: Fixed one more mode_t issue. smbd/negprot.c: Changed literals to be FLAG_ #defines. smbd/nttrans.c: Removed dead code. smbd/open.c: Changed disk_free call. smbd/process.c: Changed literals to be FLAG_ #defines. smbd/reply.c: Changed disk_free call. smbd/trans2.c: Fixed but in SMB_QUERY_FS_VOLUME_INFO call. Was using UNICODE - should use ascii. tests/summary.c: Added STAT_STATVFS64 check. Jeremy. (This used to be commit c512b1b91fb7f2a7a93b9033a33e06d966daadb4) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index b72178013d..1d6de37df0 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -501,9 +501,9 @@ void construct_reply_common(char *inbuf,char *outbuf) memcpy(outbuf+4,inbuf+4,4); CVAL(outbuf,smb_rcls) = SMB_SUCCESS; CVAL(outbuf,smb_reh) = 0; - CVAL(outbuf,smb_flg) = 0x80 | (CVAL(inbuf,smb_flg) & 0x8); /* bit 7 set + SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); /* bit 7 set means a reply */ - SSVAL(outbuf,smb_flg2,1); /* say we support long filenames */ + SSVAL(outbuf,smb_flg2,FLAGS2_LONG_PATH_COMPONENTS); /* say we support long filenames */ SSVAL(outbuf,smb_err,SMB_SUCCESS); SSVAL(outbuf,smb_tid,SVAL(inbuf,smb_tid)); SSVAL(outbuf,smb_pid,SVAL(inbuf,smb_pid)); -- cgit From aab2fe021643417854451c65e564932f4ac25f10 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 23 Sep 1998 01:48:45 +0000 Subject: First cut at kernel oplocks. This should have no effect unless runnin on a machine that supports them in autoconf. Move various functions out of lib/util.c into smbd/process.c and smbd/oplock.c where they belong. Jeremy. (This used to be commit c3c5e13f85c97939746070132dad941e79c546fb) --- source3/smbd/process.c | 159 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 151 insertions(+), 8 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1d6de37df0..656e2e99e1 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -47,7 +47,6 @@ extern pstring sesssetup_user; extern char *last_inbuf; extern char *InBuffer; extern char *OutBuffer; -extern int oplock_sock; extern int smb_read_error; extern BOOL reload_after_sighup; extern BOOL global_machine_pasword_needs_changing; @@ -55,24 +54,168 @@ extern fstring global_myworkgroup; extern pstring global_myname; extern int max_send; +/**************************************************************************** + structure to hold a linked list of queued messages. + for processing. +****************************************************************************/ + +typedef struct { + ubi_slNode msg_next; + char *msg_buf; + int msg_len; +} pending_message_list; + +static ubi_slList smb_oplock_queue = { NULL, (ubi_slNodePtr)&smb_oplock_queue, 0}; + +/**************************************************************************** + Function to push a message onto the tail of a linked list of smb messages ready + for processing. +****************************************************************************/ + +static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len) +{ + pending_message_list *msg = (pending_message_list *) + malloc(sizeof(pending_message_list)); + + if(msg == NULL) + { + DEBUG(0,("push_message: malloc fail (1)\n")); + return False; + } + + msg->msg_buf = (char *)malloc(msg_len); + if(msg->msg_buf == NULL) + { + DEBUG(0,("push_message: malloc fail (2)\n")); + free((char *)msg); + return False; + } + + memcpy(msg->msg_buf, buf, msg_len); + msg->msg_len = msg_len; + + ubi_slAddTail( list_head, msg); + + return True; +} + +/**************************************************************************** + Function to push a smb message onto a linked list of local smb messages ready + for processing. +****************************************************************************/ + +BOOL push_oplock_pending_smb_message(char *buf, int msg_len) +{ + return push_message(&smb_oplock_queue, buf, msg_len); +} + +/**************************************************************************** + Do a select on an two fd's - with timeout. + + If a local udp message has been pushed onto the + queue (this can only happen during oplock break + processing) return this first. + + If a pending smb message has been pushed onto the + queue (this can only happen during oplock break + processing) return this next. + + If the first smbfd is ready then read an smb from it. + if the second (loopback UDP) fd is ready then read a message + from it and setup the buffer header to identify the length + and from address. + Returns False on timeout or error. + Else returns True. + +The timeout is in milli seconds +****************************************************************************/ + +static BOOL receive_message_or_smb(char *buffer, int buffer_len, + int timeout, BOOL *got_smb) +{ + extern int Client; + fd_set fds; + int selrtn; + struct timeval to; + int maxfd; + + smb_read_error = 0; + + *got_smb = False; + + /* + * Check to see if we already have a message on the smb queue. + * If so - copy and return it. + */ + + if(ubi_slCount(&smb_oplock_queue) != 0) + { + pending_message_list *msg = (pending_message_list *)ubi_slRemHead(&smb_oplock_queue); + memcpy(buffer, msg->msg_buf, MIN(buffer_len, msg->msg_len)); + + /* Free the message we just copied. */ + free((char *)msg->msg_buf); + free((char *)msg); + *got_smb = True; + + DEBUG(5,("receive_message_or_smb: returning queued smb message.\n")); + return True; + } + + /* + * Setup the select read fd set. + */ + + FD_ZERO(&fds); + FD_SET(Client,&fds); + maxfd = setup_oplock_select_set(&fds); + + to.tv_sec = timeout / 1000; + to.tv_usec = (timeout % 1000) * 1000; + + selrtn = sys_select(MAX(maxfd,Client)+1,&fds,timeout>0?&to:NULL); + + /* Check if error */ + if(selrtn == -1) { + /* something is wrong. Maybe the socket is dead? */ + smb_read_error = READ_ERROR; + return False; + } + + /* Did we timeout ? */ + if (selrtn == 0) { + smb_read_error = READ_TIMEOUT; + return False; + } + + if (FD_ISSET(Client,&fds)) + { + *got_smb = True; + return receive_smb(Client, buffer, 0); + } + else + { + return receive_local_message(&fds, buffer, buffer_len, 0); + } +} /**************************************************************************** Get the next SMB packet, doing the local message processing automatically. ****************************************************************************/ -BOOL receive_next_smb(int smbfd, int oplockfd, char *inbuf, int bufsize, int timeout) + +BOOL receive_next_smb(char *inbuf, int bufsize, int timeout) { BOOL got_smb = False; BOOL ret; do { - ret = receive_message_or_smb(smbfd,oplockfd,inbuf,bufsize, - timeout,&got_smb); + ret = receive_message_or_smb(inbuf,bufsize,timeout,&got_smb); if(ret && !got_smb) { /* Deal with oplock break requests from other smbd's. */ - process_local_message(oplock_sock, inbuf, bufsize); + process_local_message(inbuf, bufsize); continue; } @@ -644,8 +787,8 @@ void smbd_process(void) errno = 0; for (counter=SMBD_SELECT_LOOP; - !receive_message_or_smb(Client,oplock_sock, - InBuffer,BUFFER_SIZE,SMBD_SELECT_LOOP*1000,&got_smb); + !receive_message_or_smb(InBuffer,BUFFER_SIZE, + SMBD_SELECT_LOOP*1000,&got_smb); counter += SMBD_SELECT_LOOP) { time_t t; @@ -792,6 +935,6 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); if(got_smb) process_smb(InBuffer, OutBuffer); else - process_local_message(oplock_sock, InBuffer, BUFFER_SIZE); + process_local_message(InBuffer, BUFFER_SIZE); } } -- cgit From 2fef8f2e87f61043e3f1a2cf7d1f2a4ff9f119ff Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 7 Oct 1998 15:22:49 +0000 Subject: dce/rpc (This used to be commit 34afa638f6f7bb145ec094510ac58f7a22dfc3aa) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 656e2e99e1..6e1bdc941a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -329,7 +329,7 @@ struct smb_message_struct {SMBopenX,"SMBopenX",reply_open_and_X,AS_USER | CAN_IPC | QUEUE_IN_OPLOCK }, {SMBreadX,"SMBreadX",reply_read_and_X,AS_USER | CAN_IPC }, - {SMBwriteX,"SMBwriteX",reply_write_and_X,AS_USER}, + {SMBwriteX,"SMBwriteX",reply_write_and_X,AS_USER | CAN_IPC }, {SMBlockingX,"SMBlockingX",reply_lockingX,AS_USER}, {SMBffirst,"SMBffirst",reply_search,AS_USER}, -- cgit From c404bb775414139a4b07a73f79cf069a083acb26 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Thu, 15 Oct 1998 23:51:07 +0000 Subject: rpcclient interactive login (with trust account changing if you are root) cli_session_setup handles null sessions correctly (This used to be commit 60c0f22a4e84703467006dfe1971384a6294a9aa) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 6e1bdc941a..9c00d6fc00 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -49,7 +49,7 @@ extern char *InBuffer; extern char *OutBuffer; extern int smb_read_error; extern BOOL reload_after_sighup; -extern BOOL global_machine_pasword_needs_changing; +extern BOOL global_machine_password_needs_changing; extern fstring global_myworkgroup; extern pstring global_myname; extern int max_send; -- cgit From 1bcbc67767e68ae12533c1ea44e2c0a567e4c93c Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 16 Oct 1998 00:07:25 +0000 Subject: trust password (This used to be commit fa86770d56fd4a3e280ee4f5685e29dee2a713fb) --- source3/smbd/process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 9c00d6fc00..a38e6da683 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -873,7 +873,7 @@ void smbd_process(void) return; } - if(global_machine_pasword_needs_changing) + if(global_machine_password_needs_changing) { unsigned char trust_passwd_hash[16]; time_t lct; @@ -908,7 +908,7 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); if(t < lct + lp_machine_password_timeout()) { trust_password_unlock(); - global_machine_pasword_needs_changing = False; + global_machine_password_needs_changing = False; continue; } @@ -916,7 +916,7 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); change_trust_account_password( global_myworkgroup, remote_machine_list); trust_password_unlock(); - global_machine_pasword_needs_changing = False; + global_machine_password_needs_changing = False; } /* -- cgit From d330c907bdc5d8e3c242cea76dfafaae84041270 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 1 Apr 1999 05:22:58 +0000 Subject: Ken McDonell from SGI was interested in adding some profiling capabilities to Samba so that Samba could talk to the SGI PCP (Performance Co-Pilot) apps. This change adds a profiling shared memory area and uses it to count two fairly trivial things, the number of uid switches and the number of SMB packets processes. To add more just edit include/profile.h and then increment it at the right place. I've also added a -P switch to smbstatus to dump the profile area. (This used to be commit ef3d61a80ad0b87c196a63ef2bd4fe8fc3863bd0) --- source3/smbd/process.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index a38e6da683..420598157f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -545,6 +545,10 @@ void process_smb(char *inbuf, char *outbuf) int32 len = smb_len(inbuf); int nread = len + 4; +#ifdef WITH_PROFILE + profile_p->smb_count++; +#endif + if (trans_num == 0) { /* on the first packet, check the global hosts allow/ hosts deny parameters before doing any parsing of the packet -- cgit From 68e1888fd3f3b26896ef99d689537c73ceecf639 Mon Sep 17 00:00:00 2001 From: Matthew Chapman Date: Thu, 8 Apr 1999 05:36:39 +0000 Subject: Mainly BDC-related changes. * Added SEC_CHAN_BDC * Propagate sec_chan into the various functions which change trust account passwords, so they can be used for domain control and inter-domain trusts. (This used to be commit ca540c21f78b4bc8ca36ac3d5af2b8f67cf716c3) --- source3/smbd/process.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 420598157f..a4c1acba8f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -882,6 +882,7 @@ void smbd_process(void) unsigned char trust_passwd_hash[16]; time_t lct; pstring remote_machine_list; + int sec_chan = SEC_CHAN_WKSTA; /* * We're in domain level security, and the code that @@ -917,8 +918,11 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); } pstrcpy(remote_machine_list, lp_passwordserver()); + if (lp_server_role() == ROLE_DOMAIN_BDC) + sec_chan = SEC_CHAN_BDC; - change_trust_account_password( global_myworkgroup, remote_machine_list); + change_trust_account_password(global_myworkgroup, remote_machine_list, + sec_chan); trust_password_unlock(); global_machine_password_needs_changing = False; } -- cgit From 8f1404739fe75464fe1500c3f6e6d39d4878ec1e Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Mon, 12 Jul 1999 18:46:15 +0000 Subject: Jean-Francois Micouleau's rewritten DFS patch, originally written by Nigel Williams. despite the data format being *exactly* the same as NT's, this still doesn't work yet. more work needed. (This used to be commit 270981960bb5aab52d2f8e494827101ece6729c4) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index a4c1acba8f..bc60cb474d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -339,7 +339,7 @@ struct smb_message_struct /* LANMAN2.0 PROTOCOL FOLLOWS */ {SMBfindnclose, "SMBfindnclose", reply_findnclose, AS_USER}, {SMBfindclose, "SMBfindclose", reply_findclose,AS_USER}, - {SMBtrans2, "SMBtrans2", reply_trans2, AS_USER }, + {SMBtrans2, "SMBtrans2", reply_trans2, AS_USER | CAN_IPC}, {SMBtranss2, "SMBtranss2", reply_transs2, AS_USER}, /* NT PROTOCOL FOLLOWS */ -- cgit From 7f8f5e15bdffec00454168c0591fa39a88d191c2 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 8 Sep 1999 19:37:45 +0000 Subject: bertl patch for making samba listen on port 445, just like nt 5 does. cool! (This used to be commit 727e1421b2c0f8c72c428776593498103304082b) --- source3/smbd/process.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index bc60cb474d..13dd932a57 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -746,6 +746,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) void smbd_process(void) { extern int Client; + extern int ClientPort; InBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); OutBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -772,6 +773,33 @@ void smbd_process(void) /* re-initialise the timezone */ TimeInit(); + /* if connection on port 445, fake session setup... */ + if(ClientPort == 445) + { + extern fstring remote_machine; + extern fstring local_machine; + char *s; + + fstrcpy(remote_machine, dns_to_netbios_name(client_name(Client))); + fstrcpy(local_machine, global_myname); + remote_machine[15] = 0; + local_machine[15] = 0; + strlower(remote_machine); + strlower(local_machine); + + DEBUG(2, ("smbd_process(): faking session setup\n" + "client_name: %s my_name: %s\n", remote_machine, local_machine)); + + add_session_user(remote_machine); + + reload_services(True); + reopen_logs(); + + if(lp_status(-1)) { + claim_connection(NULL,"STATUS.",MAXSTATUS,True); + } + } + while (True) { int deadtime = lp_deadtime()*60; -- cgit From ddf33698b517967deaa5e620dd65a2670a7779e6 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sun, 12 Sep 1999 22:40:27 +0000 Subject: - initialising mach_passwd_file locks to zero (prev. uninit.) - cleanup - #defined report to sprintf as it's #defined to another function in other uses of cmd_lsarpc.c (This used to be commit 8fb2ff247a2fe0ec5ce0c232d8a3da9774f7e6ae) --- source3/smbd/process.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 13dd932a57..e9fb230624 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -778,7 +778,6 @@ void smbd_process(void) { extern fstring remote_machine; extern fstring local_machine; - char *s; fstrcpy(remote_machine, dns_to_netbios_name(client_name(Client))); fstrcpy(local_machine, global_myname); -- cgit From b231d2fafaff8dc67ef2dbaec778f716524d4f6a Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Mon, 15 Nov 1999 22:11:10 +0000 Subject: - added DCE/RPC "fault" PDU support. - disabled (AGAIN) the GETDC "if (MAILSLOT\NTLOGON)" code that will get NT5rc2 to work but WILL break win95 (AGAIN). this needs _not_ to be re-enabled but to be replaced with a better mechanism. - added SMBwrite support (note: SMBwriteX already existed) as NT5rc2 is sending DCE/RPC over SMBwrite not SMBwriteX. (This used to be commit 25c70e3c984c4fed19763ed405741e83fe14f87e) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index e9fb230624..1a6ec320e1 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -283,7 +283,7 @@ struct smb_message_struct {SMBunlink,"SMBunlink",reply_unlink,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK}, {SMBread,"SMBread",reply_read,AS_USER}, - {SMBwrite,"SMBwrite",reply_write,AS_USER}, + {SMBwrite,"SMBwrite",reply_write,AS_USER | CAN_IPC}, {SMBclose,"SMBclose",reply_close,AS_USER | CAN_IPC}, {SMBmkdir,"SMBmkdir",reply_mkdir,AS_USER | NEED_WRITE}, {SMBrmdir,"SMBrmdir",reply_rmdir,AS_USER | NEED_WRITE}, -- cgit From 6ddfc68e0496dc41f8c9a022a0b04a2066b43c9d Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 1 Dec 1999 02:15:14 +0000 Subject: sys_select added one more argument (read, write selectors). (This used to be commit e4d92ff9dfc51735e6932748f66a7c20b2c1cb6a) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1a6ec320e1..95222d3f51 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -173,7 +173,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, to.tv_sec = timeout / 1000; to.tv_usec = (timeout % 1000) * 1000; - selrtn = sys_select(MAX(maxfd,Client)+1,&fds,timeout>0?&to:NULL); + selrtn = sys_select(MAX(maxfd,Client)+1,&fds,NULL, timeout>0?&to:NULL); /* Check if error */ if(selrtn == -1) { -- cgit From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/smbd/process.c | 501 +++++++++++++++++++++++++++++-------------------- 1 file changed, 298 insertions(+), 203 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 95222d3f51..7e94ffa173 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -23,7 +23,7 @@ extern int DEBUGLEVEL; -time_t smb_last_time=(time_t)0; +struct timeval smb_last_time; char *InBuffer = NULL; char *OutBuffer = NULL; @@ -48,7 +48,7 @@ extern char *last_inbuf; extern char *InBuffer; extern char *OutBuffer; extern int smb_read_error; -extern BOOL reload_after_sighup; +extern VOLATILE SIG_ATOMIC_T reload_after_sighup; extern BOOL global_machine_password_needs_changing; extern fstring global_myworkgroup; extern pstring global_myname; @@ -173,7 +173,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, to.tv_sec = timeout / 1000; to.tv_usec = (timeout % 1000) * 1000; - selrtn = sys_select(MAX(maxfd,Client)+1,&fds,NULL, timeout>0?&to:NULL); + selrtn = sys_select(MAX(maxfd,Client)+1,&fds,timeout>0?&to:NULL); /* Check if error */ if(selrtn == -1) { @@ -231,6 +231,52 @@ BOOL receive_next_smb(char *inbuf, int bufsize, int timeout) return ret; } +/**************************************************************************** + We're terminating and have closed all our files/connections etc. + If there are any pending local messages we need to respond to them + before termination so that other smbds don't think we just died whilst + holding oplocks. +****************************************************************************/ + +void respond_to_all_remaining_local_messages(void) +{ + char buffer[1024]; + fd_set fds; + + /* + * Assert we have no exclusive open oplocks. + */ + + if(get_number_of_exclusive_open_oplocks()) { + DEBUG(0,("respond_to_all_remaining_local_messages: PANIC : we have %d exclusive oplocks.\n", + get_number_of_exclusive_open_oplocks() )); + return; + } + + /* + * Setup the select read fd set. + */ + + FD_ZERO(&fds); + if(!setup_oplock_select_set(&fds)) + return; + + /* + * Keep doing receive_local_message with a 1 ms timeout until + * we have no more messages. + */ + + while(receive_local_message(&fds, buffer, sizeof(buffer), 1)) { + /* Deal with oplock break requests from other smbd's. */ + process_local_message(buffer, sizeof(buffer)); + + FD_ZERO(&fds); + (void)setup_oplock_select_set(&fds); + } + + return; +} + /* These flags determine some of the permissions required to do an operation @@ -283,8 +329,8 @@ struct smb_message_struct {SMBunlink,"SMBunlink",reply_unlink,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK}, {SMBread,"SMBread",reply_read,AS_USER}, - {SMBwrite,"SMBwrite",reply_write,AS_USER | CAN_IPC}, - {SMBclose,"SMBclose",reply_close,AS_USER | CAN_IPC}, + {SMBwrite,"SMBwrite",reply_write,AS_USER | CAN_IPC }, + {SMBclose,"SMBclose",reply_close,AS_USER | CAN_IPC }, {SMBmkdir,"SMBmkdir",reply_mkdir,AS_USER | NEED_WRITE}, {SMBrmdir,"SMBrmdir",reply_rmdir,AS_USER | NEED_WRITE}, {SMBdskattr,"SMBdskattr",reply_dskattr,AS_USER}, @@ -319,9 +365,9 @@ struct smb_message_struct {SMBwriteBmpx,"SMBwriteBmpx",reply_writebmpx,AS_USER}, {SMBwriteBs,"SMBwriteBs",reply_writebs,AS_USER}, {SMBwritec,"SMBwritec",NULL,AS_USER}, - {SMBsetattrE,"SMBsetattrE",reply_setattrE,AS_USER | NEED_WRITE}, - {SMBgetattrE,"SMBgetattrE",reply_getattrE,AS_USER}, - {SMBtrans,"SMBtrans",reply_trans,AS_USER | CAN_IPC}, + {SMBsetattrE,"SMBsetattrE",reply_setattrE,AS_USER | NEED_WRITE }, + {SMBgetattrE,"SMBgetattrE",reply_getattrE,AS_USER }, + {SMBtrans,"SMBtrans",reply_trans,AS_USER | CAN_IPC | QUEUE_IN_OPLOCK}, {SMBtranss,"SMBtranss",NULL,AS_USER | CAN_IPC}, {SMBioctls,"SMBioctls",NULL,AS_USER}, {SMBcopy,"SMBcopy",reply_copy,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK }, @@ -330,7 +376,7 @@ struct smb_message_struct {SMBopenX,"SMBopenX",reply_open_and_X,AS_USER | CAN_IPC | QUEUE_IN_OPLOCK }, {SMBreadX,"SMBreadX",reply_read_and_X,AS_USER | CAN_IPC }, {SMBwriteX,"SMBwriteX",reply_write_and_X,AS_USER | CAN_IPC }, - {SMBlockingX,"SMBlockingX",reply_lockingX,AS_USER}, + {SMBlockingX,"SMBlockingX",reply_lockingX,AS_USER }, {SMBffirst,"SMBffirst",reply_search,AS_USER}, {SMBfunique,"SMBfunique",reply_search,AS_USER}, @@ -339,14 +385,14 @@ struct smb_message_struct /* LANMAN2.0 PROTOCOL FOLLOWS */ {SMBfindnclose, "SMBfindnclose", reply_findnclose, AS_USER}, {SMBfindclose, "SMBfindclose", reply_findclose,AS_USER}, - {SMBtrans2, "SMBtrans2", reply_trans2, AS_USER | CAN_IPC}, + {SMBtrans2, "SMBtrans2", reply_trans2, AS_USER | QUEUE_IN_OPLOCK }, {SMBtranss2, "SMBtranss2", reply_transs2, AS_USER}, /* NT PROTOCOL FOLLOWS */ {SMBntcreateX, "SMBntcreateX", reply_ntcreate_and_X, AS_USER | CAN_IPC | QUEUE_IN_OPLOCK }, - {SMBnttrans, "SMBnttrans", reply_nttrans, AS_USER | CAN_IPC }, + {SMBnttrans, "SMBnttrans", reply_nttrans, AS_USER | CAN_IPC | QUEUE_IN_OPLOCK}, {SMBnttranss, "SMBnttranss", reply_nttranss, AS_USER | CAN_IPC }, - {SMBntcancel, "SMBntcancel", reply_ntcancel, AS_USER }, + {SMBntcancel, "SMBntcancel", reply_ntcancel, 0 }, /* messaging routines */ {SMBsends,"SMBsends",reply_sends,AS_GUEST}, @@ -368,14 +414,14 @@ do a switch on the message type, and return the response size ****************************************************************************/ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize) { - static int pid= -1; + static pid_t pid= (pid_t)-1; int outsize = 0; static int num_smb_messages = sizeof(smb_messages) / sizeof(struct smb_message_struct); int match; extern int Client; - if (pid == -1) + if (pid == (pid_t)-1) pid = getpid(); errno = 0; @@ -399,21 +445,25 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize } else { - DEBUG(3,("switch message %s (pid %d)\n",smb_messages[match].name,pid)); + DEBUG(3,("switch message %s (pid %d)\n",smb_messages[match].name,(int)pid)); - if(global_oplock_break && (smb_messages[match].flags & QUEUE_IN_OPLOCK)) + if(global_oplock_break) { - /* - * Queue this message as we are the process of an oplock break. - */ + int flags = smb_messages[match].flags; - DEBUG( 2, ( "switch_message: queueing message due to being in " ) ); - DEBUGADD( 2, ( "oplock break state.\n" ) ); + if(flags & QUEUE_IN_OPLOCK) + { + /* + * Queue this message as we are the process of an oplock break. + */ - push_oplock_pending_smb_message( inbuf, size ); - return -1; - } + DEBUG( 2, ( "switch_message: queueing message due to being in " ) ); + DEBUGADD( 2, ( "oplock break state.\n" ) ); + push_oplock_pending_smb_message( inbuf, size ); + return -1; + } + } if (smb_messages[match].fn) { int flags = smb_messages[match].flags; @@ -508,7 +558,7 @@ static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) int msg_type = CVAL(inbuf,0); extern int chain_size; - smb_last_time = time(NULL); + GetTimeOfDay(&smb_last_time); chain_size = 0; file_chain_reset(); @@ -640,7 +690,7 @@ char *smb_fn_name(int type) void construct_reply_common(char *inbuf,char *outbuf) { - bzero(outbuf,smb_size); + memset(outbuf,'\0',smb_size); set_message(outbuf,0,0,True); CVAL(outbuf,smb_com) = CVAL(inbuf,smb_com); @@ -687,6 +737,14 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) orig_outbuf = outbuf; } + /* + * The original Win95 redirector dies on a reply to + * a lockingX and read chain unless the chain reply is + * 4 byte aligned. JRA. + */ + + outsize = (outsize + 3) & ~3; + /* we need to tell the client where the next part of the reply will be */ SSVAL(outbuf,smb_vwv1,smb_offset(outbuf+outsize,outbuf)); CVAL(outbuf,smb_vwv0) = smb_com2; @@ -741,234 +799,271 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) } /**************************************************************************** - process commands from the client + Setup the needed select timeout. ****************************************************************************/ -void smbd_process(void) + +static int setup_select_timeout(void) { - extern int Client; - extern int ClientPort; + int change_notify_timeout = lp_change_notify_timeout() * 1000; + int select_timeout; - InBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - OutBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - if ((InBuffer == NULL) || (OutBuffer == NULL)) - return; + /* + * Increase the select timeout back to SMBD_SELECT_TIMEOUT if we + * have removed any blocking locks. JRA. + */ - InBuffer += SMB_ALIGNMENT; - OutBuffer += SMB_ALIGNMENT; + select_timeout = blocking_locks_pending() ? SMBD_SELECT_TIMEOUT_WITH_PENDING_LOCKS*1000 : + SMBD_SELECT_TIMEOUT*1000; + + if (change_notifies_pending()) + select_timeout = MIN(select_timeout, change_notify_timeout); + + return select_timeout; +} + +/**************************************************************************** + Check if services need reloading. +****************************************************************************/ + +void check_reload(int t) +{ + static time_t last_smb_conf_reload_time = 0; + + if(last_smb_conf_reload_time == 0) + last_smb_conf_reload_time = t; -#if PRIME_NMBD - DEBUG(3,("priming nmbd\n")); + if (reload_after_sighup || (t >= last_smb_conf_reload_time+SMBD_RELOAD_CHECK)) { - struct in_addr ip; - ip = *interpret_addr2("localhost"); - if (zero_ip(ip)) ip = *interpret_addr2("127.0.0.1"); - *OutBuffer = 0; - send_one_packet(OutBuffer,1,ip,NMB_PORT,SOCK_DGRAM); + reload_services(True); + reload_after_sighup = False; + last_smb_conf_reload_time = t; } -#endif +} +/**************************************************************************** + Process any timeout housekeeping. Return False if the caler should exit. +****************************************************************************/ - max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); +static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_timeout_processing_time) +{ + extern int Client; + static time_t last_keepalive_sent_time = 0; + static time_t last_idle_closed_check = 0; + time_t t; + BOOL allidle = True; + extern int keepalive; - /* re-initialise the timezone */ - TimeInit(); + if (smb_read_error == READ_EOF) + { + DEBUG(3,("end of file from client\n")); + return False; + } - /* if connection on port 445, fake session setup... */ - if(ClientPort == 445) + if (smb_read_error == READ_ERROR) { - extern fstring remote_machine; - extern fstring local_machine; + DEBUG(3,("receive_smb error (%s) exiting\n", + strerror(errno))); + return False; + } - fstrcpy(remote_machine, dns_to_netbios_name(client_name(Client))); - fstrcpy(local_machine, global_myname); - remote_machine[15] = 0; - local_machine[15] = 0; - strlower(remote_machine); - strlower(local_machine); + *last_timeout_processing_time = t = time(NULL); - DEBUG(2, ("smbd_process(): faking session setup\n" - "client_name: %s my_name: %s\n", remote_machine, local_machine)); + if(last_keepalive_sent_time == 0) + last_keepalive_sent_time = t; - add_session_user(remote_machine); + if(last_idle_closed_check == 0) + last_idle_closed_check = t; - reload_services(True); - reopen_logs(); + /* become root again if waiting */ + unbecome_user(); - if(lp_status(-1)) { - claim_connection(NULL,"STATUS.",MAXSTATUS,True); - } + /* check if we need to reload services */ + check_reload(t); + + /* automatic timeout if all connections are closed */ + if (conn_num_open()==0 && (t - last_idle_closed_check) >= IDLE_CLOSED_TIMEOUT) + { + DEBUG( 2, ( "Closing idle connection\n" ) ); + return False; } + else + last_idle_closed_check = t; - while (True) + if (keepalive && (t - last_keepalive_sent_time)>keepalive) { - int deadtime = lp_deadtime()*60; - int counter; - int last_keepalive=0; - int service_load_counter = 0; - BOOL got_smb = False; + struct cli_state *cli = server_client(); + if (!send_keepalive(Client)) { + DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); + return False; + } + /* also send a keepalive to the password server if its still + connected */ + if (cli && cli->initialised) + send_keepalive(cli->fd); + last_keepalive_sent_time = t; + } - if (deadtime <= 0) - deadtime = DEFAULT_SMBD_TIMEOUT; + /* check for connection timeouts */ + allidle = conn_idle_all(t, deadtime); -#if USE_READ_PREDICTION - if (lp_readprediction()) - do_read_prediction(); -#endif + if (allidle && conn_num_open()>0) { + DEBUG(2,("Closing idle connection 2.\n")); + return False; + } - errno = 0; + if(global_machine_password_needs_changing) + { + unsigned char trust_passwd_hash[16]; + time_t lct; + pstring remote_machine_list; + + /* + * We're in domain level security, and the code that + * read the machine password flagged that the machine + * password needs changing. + */ + + /* + * First, open the machine password file with an exclusive lock. + */ + + if(!trust_password_lock( global_myworkgroup, global_myname, True)) { + DEBUG(0,("process: unable to open the machine account password file for \ +machine %s in domain %s.\n", global_myname, global_myworkgroup )); + return True; + } - for (counter=SMBD_SELECT_LOOP; - !receive_message_or_smb(InBuffer,BUFFER_SIZE, - SMBD_SELECT_LOOP*1000,&got_smb); - counter += SMBD_SELECT_LOOP) - { - time_t t; - BOOL allidle = True; - extern int keepalive; + if(!get_trust_account_password( trust_passwd_hash, &lct)) { + DEBUG(0,("process: unable to read the machine account password for \ +machine %s in domain %s.\n", global_myname, global_myworkgroup )); + trust_password_unlock(); + return True; + } - if (counter > 365 * 3600) /* big number of seconds. */ - { - counter = 0; - service_load_counter = 0; - } + /* + * Make sure someone else hasn't already done this. + */ - if (smb_read_error == READ_EOF) - { - DEBUG(3,("end of file from client\n")); - return; - } + if(t < lct + lp_machine_password_timeout()) { + trust_password_unlock(); + global_machine_password_needs_changing = False; + return True; + } - if (smb_read_error == READ_ERROR) - { - DEBUG(3,("receive_smb error (%s) exiting\n", - strerror(errno))); - return; - } + pstrcpy(remote_machine_list, lp_passwordserver()); - t = time(NULL); + change_trust_account_password( global_myworkgroup, remote_machine_list); + trust_password_unlock(); + global_machine_password_needs_changing = False; + } - /* become root again if waiting */ - unbecome_user(); + /* + * Check to see if we have any blocking locks + * outstanding on the queue. + */ + process_blocking_lock_queue(t); - /* check for smb.conf reload */ - if (counter >= service_load_counter + SMBD_RELOAD_CHECK) - { - service_load_counter = counter; + /* + * Check to see if we have any change notifies + * outstanding on the queue. + */ + process_pending_change_notify_queue(t); - /* reload services, if files have changed. */ - reload_services(True); - } + /* + * Modify the select timeout depending upon + * what we have remaining in our queues. + */ - /* - * If reload_after_sighup == True then we got a SIGHUP - * and are being asked to reload. Fix from - */ + *select_timeout = setup_select_timeout(); - if (reload_after_sighup) - { - DEBUG(0,("Reloading services after SIGHUP\n")); - reload_services(False); - reload_after_sighup = False; - /* - * Use this as an excuse to print some stats. - */ - print_stat_cache_statistics(); - } + return True; +} - /* automatic timeout if all connections are closed */ - if (conn_num_open()==0 && counter >= IDLE_CLOSED_TIMEOUT) - { - DEBUG( 2, ( "Closing idle connection\n" ) ); - return; - } +/**************************************************************************** + process commands from the client +****************************************************************************/ - if (keepalive && (counter-last_keepalive)>keepalive) - { - struct cli_state *cli = server_client(); - if (!send_keepalive(Client)) { - DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); - return; - } - /* also send a keepalive to the password server if its still - connected */ - if (cli && cli->initialised) - send_keepalive(cli->fd); - last_keepalive = counter; - } +void smbd_process(void) +{ + extern int smb_echo_count; + time_t last_timeout_processing_time = time(NULL); + unsigned int num_smbs = 0; + + InBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + OutBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + if ((InBuffer == NULL) || (OutBuffer == NULL)) + return; - /* check for connection timeouts */ - allidle = conn_idle_all(t, deadtime); + InBuffer += SMB_ALIGNMENT; + OutBuffer += SMB_ALIGNMENT; - if (allidle && conn_num_open()>0) { - DEBUG(2,("Closing idle connection 2.\n")); - return; - } + max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); - if(global_machine_password_needs_changing) - { - unsigned char trust_passwd_hash[16]; - time_t lct; - pstring remote_machine_list; - int sec_chan = SEC_CHAN_WKSTA; - - /* - * We're in domain level security, and the code that - * read the machine password flagged that the machine - * password needs changing. - */ + /* re-initialise the timezone */ + TimeInit(); - /* - * First, open the machine password file with an exclusive lock. - */ + while (True) + { + int deadtime = lp_deadtime()*60; + BOOL got_smb = False; + int select_timeout = setup_select_timeout(); - if(!trust_password_lock( global_myworkgroup, global_myname, True)) { - DEBUG(0,("process: unable to open the machine account password file for \ -machine %s in domain %s.\n", global_myname, global_myworkgroup )); - continue; - } + if (deadtime <= 0) + deadtime = DEFAULT_SMBD_TIMEOUT; - if(!get_trust_account_password( trust_passwd_hash, &lct)) { - DEBUG(0,("process: unable to read the machine account password for \ -machine %s in domain %s.\n", global_myname, global_myworkgroup )); - trust_password_unlock(); - continue; - } +#if USE_READ_PREDICTION + if (lp_readprediction()) + do_read_prediction(); +#endif - /* - * Make sure someone else hasn't already done this. - */ + errno = 0; - if(t < lct + lp_machine_password_timeout()) { - trust_password_unlock(); - global_machine_password_needs_changing = False; - continue; - } + while(!receive_message_or_smb(InBuffer,BUFFER_SIZE,select_timeout,&got_smb)) + { + if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) + return; + num_smbs = 0; /* Reset smb counter. */ + } - pstrcpy(remote_machine_list, lp_passwordserver()); - if (lp_server_role() == ROLE_DOMAIN_BDC) - sec_chan = SEC_CHAN_BDC; + if(got_smb) { + /* + * Ensure we do timeout processing if the SMB we just got was + * only an echo request. This allows us to set the select + * timeout in 'receive_message_or_smb()' to any value we like + * without worrying that the client will send echo requests + * faster than the select timeout, thus starving out the + * essential processing (change notify, blocking locks) that + * the timeout code does. JRA. + */ + int num_echos = smb_echo_count; + + process_smb(InBuffer, OutBuffer); - change_trust_account_password(global_myworkgroup, remote_machine_list, - sec_chan); - trust_password_unlock(); - global_machine_password_needs_changing = False; + if(smb_echo_count != num_echos) { + if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) + return; + num_smbs = 0; /* Reset smb counter. */ } - /* - * Check to see if we have any blocking locks - * outstanding on the queue. - */ - process_blocking_lock_queue(t); + num_smbs++; /* - * Check to see if we have any change notifies - * outstanding on the queue. + * If we are getting smb requests in a constant stream + * with no echos, make sure we attempt timeout processing + * every select_timeout milliseconds - but only check for this + * every 200 smb requests. */ - process_pending_change_notify_queue(t); - } - if(got_smb) - process_smb(InBuffer, OutBuffer); + if((num_smbs % 200) == 0) { + time_t new_check_time = time(NULL); + if(last_timeout_processing_time - new_check_time >= (select_timeout/1000)) { + if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) + return; + num_smbs = 0; /* Reset smb counter. */ + last_timeout_processing_time = new_check_time; /* Reset time. */ + } + } + } else process_local_message(InBuffer, BUFFER_SIZE); } -- cgit From 7b39ef295073847b29af3220e0566131e503b0a0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 21 Dec 1999 00:06:00 +0000 Subject: Fix from tulipant-gergely@dbrt.hu for returning incorrect error code on user auth fail. Jeremy. (This used to be commit 886ad59d798175f037ea9249dcefa78660e4992a) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 7e94ffa173..36eb882340 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -504,7 +504,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize if (flags & AS_GUEST) flags &= ~AS_USER; else - return(ERROR(ERRSRV,ERRinvnid)); + return(ERROR(ERRSRV,ERRaccess)); } /* this code is to work around a bug is MS client 3 without introducing a security hole - it needs to be able to do -- cgit From 5e9f5591873fc5c5b5c8dbb0e29a080b8afe9966 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 5 Jan 2000 06:36:36 +0000 Subject: implemented talloc() as described on samba-technical. This fixes the lp_string() bug properly. we still need to add lp_talloc_free() calls in all the main event loops, I've only put it in smbd and nmbd thus far. (This used to be commit aa7f81552540f5dca2c146f5edd805611d5b390f) --- source3/smbd/process.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 36eb882340..04432adb96 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1018,6 +1018,9 @@ void smbd_process(void) errno = 0; + /* free up temporary memory */ + lp_talloc_free(); + while(!receive_message_or_smb(InBuffer,BUFFER_SIZE,select_timeout,&got_smb)) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) -- cgit From 2afd5d5eb5c176f09a9f4f00ea3b517e89ef0ddf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 14 Jan 2000 00:50:48 +0000 Subject: some more work on the byte range locking note the ugly global_smbpid - I hope that won't bethere for long, I just didn't want to do two lots of major surgery at the one time. Using global_smbpid avoids the big change of getting rid of our inbuf/outbuf interface to reply routines. I'll do that once the locking stuff passes all tests. (This used to be commit f8bebf91abcaa5bda3ec8701f9242f220da8943a) --- source3/smbd/process.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 04432adb96..d3551b96b1 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -25,7 +25,7 @@ extern int DEBUGLEVEL; struct timeval smb_last_time; -char *InBuffer = NULL; +static char *InBuffer = NULL; char *OutBuffer = NULL; char *last_inbuf = NULL; @@ -420,6 +420,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize sizeof(smb_messages) / sizeof(struct smb_message_struct); int match; extern int Client; + extern int global_smbpid; if (pid == (pid_t)-1) pid = getpid(); @@ -438,6 +439,10 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize if (smb_messages[match].code == type) break; + /* yuck! this is an interim measure before we get rid of our + current inbuf/outbuf system */ + global_smbpid = SVAL(inbuf,smb_pid); + if (match == num_smb_messages) { DEBUG(0,("Unknown message type %d!\n",type)); @@ -841,7 +846,7 @@ void check_reload(int t) } /**************************************************************************** - Process any timeout housekeeping. Return False if the caler should exit. + Process any timeout housekeeping. Return False if the caller should exit. ****************************************************************************/ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_timeout_processing_time) -- cgit From b5e7e4277d87c9eaa663f92c081a869b34170380 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 25 Jan 2000 22:57:51 +0000 Subject: First set of speed improvements from Ying Chen . Inline several commonly used functions as macros. Jeremy. (This used to be commit fc0219c7cc4b83e6db17d5b3be70d74fd7971089) --- source3/smbd/process.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d3551b96b1..7d6e171d05 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -561,7 +561,6 @@ static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) int type = CVAL(inbuf,smb_com); int outsize = 0; int msg_type = CVAL(inbuf,0); - extern int chain_size; GetTimeOfDay(&smb_last_time); @@ -726,7 +725,6 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) int outsize2; char inbuf_saved[smb_wct]; char outbuf_saved[smb_wct]; - extern int chain_size; int wct = CVAL(outbuf,smb_wct); int outsize = smb_size + 2*wct + SVAL(outbuf,smb_vwv0+2*wct); -- cgit From 952799d9afe028d822181831715b85521c89a7ef Mon Sep 17 00:00:00 2001 From: Shirish Kalele Date: Wed, 8 Mar 2000 22:14:30 +0000 Subject: dded Microsoft Dfs services. * added a new msdfs/ directory under source/ * added msdfs sources under this directory. * modified configure setup to add a --with-msdfs configure time option Modified Files: Makefile.in acconfig.h configure configure.in include/config.h.in include/includes.h include/proto.h include/smb.h include/smb_macros.h param/loadparm.c smbd/negprot.c smbd/nttrans.c smbd/process.c smbd/reply.c smbd/server.c smbd/trans2.c Added Files: include/msdfs.h msdfs/README msdfs/msdfs.c msdfs/msdfs_tdb.c msdfs/parse_dfs_map.c ---------------------------------------------------------------------- (This used to be commit 4684b4a188b54493dbe7f0de2909a8d3c5c3ebf9) --- source3/smbd/process.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 7d6e171d05..403990a79d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -385,7 +385,7 @@ struct smb_message_struct /* LANMAN2.0 PROTOCOL FOLLOWS */ {SMBfindnclose, "SMBfindnclose", reply_findnclose, AS_USER}, {SMBfindclose, "SMBfindclose", reply_findclose,AS_USER}, - {SMBtrans2, "SMBtrans2", reply_trans2, AS_USER | QUEUE_IN_OPLOCK }, + {SMBtrans2, "SMBtrans2", reply_trans2, AS_USER | QUEUE_IN_OPLOCK | CAN_IPC }, {SMBtranss2, "SMBtranss2", reply_transs2, AS_USER}, /* NT PROTOCOL FOLLOWS */ @@ -704,7 +704,9 @@ void construct_reply_common(char *inbuf,char *outbuf) CVAL(outbuf,smb_reh) = 0; SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); /* bit 7 set means a reply */ - SSVAL(outbuf,smb_flg2,FLAGS2_LONG_PATH_COMPONENTS); /* say we support long filenames */ + SSVAL(outbuf,smb_flg2,FLAGS2_LONG_PATH_COMPONENTS); + /* say we support long filenames */ + SSVAL(outbuf,smb_err,SMB_SUCCESS); SSVAL(outbuf,smb_tid,SVAL(inbuf,smb_tid)); SSVAL(outbuf,smb_pid,SVAL(inbuf,smb_pid)); -- cgit From 2fa922611bf7160e2c1ce80c11b50006448bf98d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Apr 2000 13:55:53 +0000 Subject: finally got sick of the "extern int Client" code and the stupid assumption that we have one socket everywhere while doing so I discovered a few bugs! 1) the clientgen session retarget code if used from smbd or nmbd would cause a crash as it called close_sockets() which closed our main socket! fixed by removing close_sockets() completely - it is unnecessary 2) the caching in client_addr() and client_name() was bogus - it could easily get fooled and give the wrong result. fixed. 3) the retarget could could recurse, allowing an easy denial of service attack on nmbd. fixed. (This used to be commit 5937ab14d222696e40a3fc6f0e6a536f2d7305d3) --- source3/smbd/process.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 403990a79d..2383b7a3a5 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -133,7 +133,6 @@ The timeout is in milli seconds static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout, BOOL *got_smb) { - extern int Client; fd_set fds; int selrtn; struct timeval to; @@ -167,13 +166,13 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, */ FD_ZERO(&fds); - FD_SET(Client,&fds); + FD_SET(smbd_server_fd(),&fds); maxfd = setup_oplock_select_set(&fds); to.tv_sec = timeout / 1000; to.tv_usec = (timeout % 1000) * 1000; - selrtn = sys_select(MAX(maxfd,Client)+1,&fds,timeout>0?&to:NULL); + selrtn = sys_select(MAX(maxfd,smbd_server_fd())+1,&fds,timeout>0?&to:NULL); /* Check if error */ if(selrtn == -1) { @@ -188,10 +187,10 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, return False; } - if (FD_ISSET(Client,&fds)) + if (FD_ISSET(smbd_server_fd(),&fds)) { *got_smb = True; - return receive_smb(Client, buffer, 0); + return receive_smb(smbd_server_fd(), buffer, 0); } else { @@ -419,7 +418,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize static int num_smb_messages = sizeof(smb_messages) / sizeof(struct smb_message_struct); int match; - extern int Client; extern int global_smbpid; if (pid == (pid_t)-1) @@ -535,7 +533,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* does this protocol need to be run as guest? */ if ((flags & AS_GUEST) && (!become_guest() || - !check_access(Client, lp_hostsallow(-1), lp_hostsdeny(-1)))) { + !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) { return(ERROR(ERRSRV,ERRaccess)); } @@ -589,7 +587,6 @@ static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) ****************************************************************************/ void process_smb(char *inbuf, char *outbuf) { - extern int Client; #ifdef WITH_SSL extern BOOL sslEnabled; /* don't use function for performance reasons */ static int sslConnected = 0; @@ -608,13 +605,13 @@ void process_smb(char *inbuf, char *outbuf) deny parameters before doing any parsing of the packet passed to us by the client. This prevents attacks on our parsing code from hosts not in the hosts allow list */ - if (!check_access(Client, lp_hostsallow(-1), lp_hostsdeny(-1))) { + if (!check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1))) { /* send a negative session response "not listining on calling name" */ static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; DEBUG( 1, ( "Connection denied from %s\n", - client_addr(Client) ) ); - send_smb(Client,(char *)buf); + client_addr() ) ); + send_smb(smbd_server_fd(),(char *)buf); exit_server("connection denied"); } } @@ -624,7 +621,7 @@ void process_smb(char *inbuf, char *outbuf) #ifdef WITH_SSL if(sslEnabled && !sslConnected){ - sslConnected = sslutil_negotiate_ssl(Client, msg_type); + sslConnected = sslutil_negotiate_ssl(smbd_server_fd(), msg_type); if(sslConnected < 0){ /* an error occured */ exit_server("SSL negotiation failed"); }else if(sslConnected){ @@ -660,7 +657,7 @@ void process_smb(char *inbuf, char *outbuf) nread, smb_len(outbuf))); } else - send_smb(Client,outbuf); + send_smb(smbd_server_fd(),outbuf); } trans_num++; } @@ -851,7 +848,6 @@ void check_reload(int t) static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_timeout_processing_time) { - extern int Client; static time_t last_keepalive_sent_time = 0; static time_t last_idle_closed_check = 0; time_t t; @@ -897,7 +893,7 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t if (keepalive && (t - last_keepalive_sent_time)>keepalive) { struct cli_state *cli = server_client(); - if (!send_keepalive(Client)) { + if (!send_keepalive(smbd_server_fd())) { DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); return False; } -- cgit From ce5e230952c18b2308d0e41fff39f0bfdf2cc32b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 15 Apr 2000 00:31:56 +0000 Subject: Log file check patch from Mattias Gronlund . Modified to do checks in timeout processing not in main loop. This (IMHO) is the correct place as (a) we are already root, and (b) it is guarenteed to be called every 200 smb requests. Jeremy. (This used to be commit c3794fd29fdc4e5a0dbd725cdc24fe210934caf2) --- source3/smbd/process.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2383b7a3a5..f378550282 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -970,6 +970,12 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); */ process_pending_change_notify_queue(t); + /* + * Now we are root, check if the log files need pruning. + */ + if(need_to_check_log_size()) + check_log_size(); + /* * Modify the select timeout depending upon * what we have remaining in our queues. -- cgit From 36db78fedad935aaa689d52d7f58e075f1f71812 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 Apr 2000 22:23:04 +0000 Subject: Fixed subtle unlocking bug when a file is closed. We need to store the smbpid used when a file was opened in the files_struct. Else we use the wrong global_smbpid when we are closing the file and trying to remove the brl locks - this causes the brl locks to be left when the file is closed as the samba_context check fails. Jeremy. (This used to be commit 2746e5602e493e5b022764b4b839eb4d2f14363b) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f378550282..77e6fc2aa7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -28,6 +28,7 @@ struct timeval smb_last_time; static char *InBuffer = NULL; char *OutBuffer = NULL; char *last_inbuf = NULL; +int global_smbpid; /* * Size of data we can send to client. Set @@ -418,7 +419,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize static int num_smb_messages = sizeof(smb_messages) / sizeof(struct smb_message_struct); int match; - extern int global_smbpid; if (pid == (pid_t)-1) pid = getpid(); -- cgit From 4b60a33c6fa733060068e192b87c2e858103d6eb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 Apr 2000 23:28:56 +0000 Subject: Ok - this is more subtle than it looks :-). When a file is being closed, once it passes the fnum and tid tests then the locking context should be ignored when removing all locks. This is what is done in the brl close case, but when you have outstanding POSIX locks, then you cannot remove all the brl locks in one go, you have to get the lock list and call do_unlock individually. As this uses global_smbpid as the locking context, you need to make sure that this is set correctly for the specific lock being removed. I now do this by storing the smbpid in each entry in the unlock list returned from the query call. I removed the smbpid from fsp (not needed) and things seem ok (even with the stupid smbpid tricks that smbtorture plays :-). Jeremy. (This used to be commit 6baa96bb466915cc17e8cbad50254d6bd47b967b) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 77e6fc2aa7..f378550282 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -28,7 +28,6 @@ struct timeval smb_last_time; static char *InBuffer = NULL; char *OutBuffer = NULL; char *last_inbuf = NULL; -int global_smbpid; /* * Size of data we can send to client. Set @@ -419,6 +418,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize static int num_smb_messages = sizeof(smb_messages) / sizeof(struct smb_message_struct); int match; + extern int global_smbpid; if (pid == (pid_t)-1) pid = getpid(); -- cgit From 05cb3464f972d336dcb82ca332bf9b2617646070 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Apr 2000 15:13:15 +0000 Subject: - added some error checking - removed the VTP hook in smbd (This used to be commit 09355fcd50e6c9c0c81e5f70ab9b7ff88aa897bf) --- source3/smbd/process.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f378550282..b81e831133 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -631,14 +631,6 @@ void process_smb(char *inbuf, char *outbuf) } #endif /* WITH_SSL */ -#ifdef WITH_VTP - if(trans_num == 1 && VT_Check(inbuf)) - { - VT_Process(); - return; - } -#endif - if (msg_type == 0) show_msg(inbuf); else if(msg_type == 0x85) -- cgit From 693ffb8466ada58ecc59fde754ba79fc6f51528d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 2 May 2000 02:23:41 +0000 Subject: Added sys_fork() and sys_getpid() functions to stop the overhead of doing a system call every time we want to just get our pid. Jeremy. (This used to be commit 148628b616b5c29ba6340d65fc3ddbcabba6e67a) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index b81e831133..1eb5899667 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -421,7 +421,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize extern int global_smbpid; if (pid == (pid_t)-1) - pid = getpid(); + pid = sys_getpid(); errno = 0; last_message = type; -- cgit From 32d5416b6a777a7874fec8518ec44e750560d882 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 May 2000 13:55:42 +0000 Subject: split the username in the vuser structure into a separate userdom_struct. As the name implies this also contains a domain (unused at the moment). This will be important shortly, as operation in appliance mode needs the domain to be always carried with the username. (This used to be commit ee8546342d5be90e730372b985710d764564b124) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1eb5899667..6482ccd538 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -495,7 +495,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize if(session_tag != UID_FIELD_INVALID) vuser = get_valid_user_struct(session_tag); if(vuser != NULL) - pstrcpy( sesssetup_user, vuser->requested_name); + pstrcpy( sesssetup_user, vuser->user.smb_name); } /* does this protocol need to be run as root? */ -- cgit From 2958dfcdf87d5169fe1152806be6ad03acb04d88 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 8 May 2000 10:42:21 +0000 Subject: added secrets.tdb and changed storage of trust account password to use it (This used to be commit 88ad00b82acc4636ab57dfe710af08ea85b82ff1) --- source3/smbd/process.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 6482ccd538..805bbe4415 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -920,16 +920,9 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t * First, open the machine password file with an exclusive lock. */ - if(!trust_password_lock( global_myworkgroup, global_myname, True)) { - DEBUG(0,("process: unable to open the machine account password file for \ -machine %s in domain %s.\n", global_myname, global_myworkgroup )); - return True; - } - - if(!get_trust_account_password( trust_passwd_hash, &lct)) { + if(!get_trust_account_password(global_myworkgroup, trust_passwd_hash, &lct)) { DEBUG(0,("process: unable to read the machine account password for \ machine %s in domain %s.\n", global_myname, global_myworkgroup )); - trust_password_unlock(); return True; } @@ -938,7 +931,6 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); */ if(t < lct + lp_machine_password_timeout()) { - trust_password_unlock(); global_machine_password_needs_changing = False; return True; } @@ -946,7 +938,6 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); pstrcpy(remote_machine_list, lp_passwordserver()); change_trust_account_password( global_myworkgroup, remote_machine_list); - trust_password_unlock(); global_machine_password_needs_changing = False; } -- cgit From 49a0e6d5989656c1b3c9c063a20308ca4ee5d73b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 10 May 2000 10:41:59 +0000 Subject: more merging voodoo this adds "#define OLD_NTDOMAIN 1" in lots of places. Don't panic - this isn't permanent, it should go after another few merge steps have been done (This used to be commit 92109d7b3c06f240452d39f669ecb8c9c86ab610) --- source3/smbd/process.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 805bbe4415..ac81116999 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1,3 +1,4 @@ +#define OLD_NTDOMAIN 1 /* Unix SMB/Netbios implementation. Version 1.9. @@ -1061,3 +1062,5 @@ void smbd_process(void) process_local_message(InBuffer, BUFFER_SIZE); } } + +#undef OLD_NTDOMAIN -- cgit From e86cba2194a04a581b872076d408c66c28b16760 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 10 May 2000 11:49:55 +0000 Subject: check for sighup on each packet - otherwise it can take a _long_ time to reload services (This used to be commit 0fb4ba4e037f25b8b75bcae0ecb1d9b43f0f9e5f) --- source3/smbd/process.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ac81116999..3d2a507cca 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1012,6 +1012,18 @@ void smbd_process(void) /* free up temporary memory */ lp_talloc_free(); + /* + * If reload_after_sighup == True then we got a SIGHUP + * and are being asked to reload. Fix from + */ + if (reload_after_sighup) { + /* become root */ + unbecome_user(); + DEBUG(1,("Reloading services after SIGHUP\n")); + reload_services(False); + reload_after_sighup = False; + } + while(!receive_message_or_smb(InBuffer,BUFFER_SIZE,select_timeout,&got_smb)) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) -- cgit From b27886addbdb1ff7c8e678023c7c1ef6d3bba9a9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 15 May 2000 17:13:50 +0000 Subject: passdb/secrets.c: Fix typo in comment. rpc_server/srv_pipe.c: Use accessor functions rather than diddling with structure internals directly. smbd/process.c: smbd/reply.c: Remove READ_PREDICTION #ifdefs. Jeremy. (This used to be commit eba825ff030a175bd271caa6f543379dfdbbd646) --- source3/smbd/process.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 3d2a507cca..9e5b7b1477 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1002,11 +1002,6 @@ void smbd_process(void) if (deadtime <= 0) deadtime = DEFAULT_SMBD_TIMEOUT; -#if USE_READ_PREDICTION - if (lp_readprediction()) - do_read_prediction(); -#endif - errno = 0; /* free up temporary memory */ -- cgit From 712a30ed51ca2b58e00d38a5d6d70d564b1da11b Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 27 May 2000 09:19:57 +0000 Subject: prs_give_memory in wrong place, also poss. was losing mem. (This used to be commit 9805e17cd0ce427c329a8b5a8318d5f75227e283) --- source3/smbd/process.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 9e5b7b1477..74ec3b64db 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -408,6 +408,29 @@ struct smb_message_struct {SMBgetmac,"SMBgetmac",NULL,AS_GUEST} }; +/******************************************************************* +dump a prs to a file + ********************************************************************/ +static void smb_dump(char *name, int type, char *data, ssize_t len) +{ + int fd, i; + pstring fname; + if (DEBUGLEVEL < 50) return; + + if (len < 4) len = smb_buflen(data); + for (i=1;i<100;i++) { + slprintf(fname,sizeof(fname), "/tmp/%s.%d.%s", name, i, + type ? "req" : "resp"); + fd = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0644); + if (fd != -1 || errno != EEXIST) break; + } + if (fd != -1) { + write(fd, data, len); + close(fd); + DEBUG(0,("created %s len %d\n", fname, len)); + } +} + /**************************************************************************** do a switch on the message type, and return the response size @@ -445,12 +468,14 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize if (match == num_smb_messages) { DEBUG(0,("Unknown message type %d!\n",type)); + smb_dump("Unknown", 1, inbuf, size); outsize = reply_unknown(inbuf,outbuf); } else { DEBUG(3,("switch message %s (pid %d)\n",smb_messages[match].name,(int)pid)); + smb_dump(smb_messages[match].name, 1, inbuf, size); if(global_oplock_break) { int flags = smb_messages[match].flags; @@ -548,6 +573,8 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize } } + smb_dump(smb_messages[match].name, 0, outbuf, outsize); + return(outsize); } -- cgit From 62707533f72f7a2438c8e5c918b4cb75470cd871 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sun, 28 May 2000 20:11:04 +0000 Subject: debug output to /tmp. (This used to be commit f9077e50cba5c7c3e6cf7739888120d8cc757c7c) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 74ec3b64db..077a97ed64 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -417,7 +417,7 @@ static void smb_dump(char *name, int type, char *data, ssize_t len) pstring fname; if (DEBUGLEVEL < 50) return; - if (len < 4) len = smb_buflen(data); + if (len < 4) len = smb_len(data)+4; for (i=1;i<100;i++) { slprintf(fname,sizeof(fname), "/tmp/%s.%d.%s", name, i, type ? "req" : "resp"); -- cgit From da44845a0907bc6c9da9aabc0374b8280a85017f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 3 Jun 2000 06:22:19 +0000 Subject: moved secrets fns into secrets.c (This used to be commit f890bcf06786e7c63bf76fad2fd46d287a99a270) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 077a97ed64..82e61a138e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -948,7 +948,7 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t * First, open the machine password file with an exclusive lock. */ - if(!get_trust_account_password(global_myworkgroup, trust_passwd_hash, &lct)) { + if(!secrets_fetch_trust_account_password(global_myworkgroup, trust_passwd_hash, &lct)) { DEBUG(0,("process: unable to read the machine account password for \ machine %s in domain %s.\n", global_myname, global_myworkgroup )); return True; -- cgit From 8843a6379d7c1cf59f0f3673cbc567b09994b7d2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 11 Jun 2000 05:57:58 +0000 Subject: Linux kernel oplocks now seem to work, but need a _lot_ of testing I had to modify sys_select() to not loop on EINTR. I added a wrapper called sys_select_intr() which gives the old behaviour. (This used to be commit b28cc4163bc2faaa80c5782fc02c8f03c410cdeb) --- source3/smbd/process.c | 107 ++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 51 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 82e61a138e..30d03747d8 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -134,69 +134,74 @@ The timeout is in milli seconds static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout, BOOL *got_smb) { - fd_set fds; - int selrtn; - struct timeval to; - int maxfd; + fd_set fds; + int selrtn; + struct timeval to; + int maxfd; - smb_read_error = 0; + smb_read_error = 0; - *got_smb = False; + *got_smb = False; - /* - * Check to see if we already have a message on the smb queue. - * If so - copy and return it. - */ + /* + * Check to see if we already have a message on the smb queue. + * If so - copy and return it. + */ - if(ubi_slCount(&smb_oplock_queue) != 0) - { - pending_message_list *msg = (pending_message_list *)ubi_slRemHead(&smb_oplock_queue); - memcpy(buffer, msg->msg_buf, MIN(buffer_len, msg->msg_len)); + if(ubi_slCount(&smb_oplock_queue) != 0) { + pending_message_list *msg = (pending_message_list *)ubi_slRemHead(&smb_oplock_queue); + memcpy(buffer, msg->msg_buf, MIN(buffer_len, msg->msg_len)); - /* Free the message we just copied. */ - free((char *)msg->msg_buf); - free((char *)msg); - *got_smb = True; + /* Free the message we just copied. */ + free((char *)msg->msg_buf); + free((char *)msg); + *got_smb = True; + + DEBUG(5,("receive_message_or_smb: returning queued smb message.\n")); + return True; + } - DEBUG(5,("receive_message_or_smb: returning queued smb message.\n")); - return True; - } + /* + * Setup the select read fd set. + */ - /* - * Setup the select read fd set. - */ + FD_ZERO(&fds); + FD_SET(smbd_server_fd(),&fds); + maxfd = setup_oplock_select_set(&fds); - FD_ZERO(&fds); - FD_SET(smbd_server_fd(),&fds); - maxfd = setup_oplock_select_set(&fds); + to.tv_sec = timeout / 1000; + to.tv_usec = (timeout % 1000) * 1000; - to.tv_sec = timeout / 1000; - to.tv_usec = (timeout % 1000) * 1000; + selrtn = sys_select(MAX(maxfd,smbd_server_fd())+1,&fds,timeout>0?&to:NULL); - selrtn = sys_select(MAX(maxfd,smbd_server_fd())+1,&fds,timeout>0?&to:NULL); + /* if we get EINTR then maybe we have received an oplock + signal - treat this as select returning 1. This is ugly, but + is the best we can do until the oplock code knows more about + signals */ + if (selrtn == -1 && errno == EINTR) { + FD_ZERO(&fds); + selrtn = 1; + } - /* Check if error */ - if(selrtn == -1) { - /* something is wrong. Maybe the socket is dead? */ - smb_read_error = READ_ERROR; - return False; - } + /* Check if error */ + if(selrtn == -1 && errno != EINTR) { + /* something is wrong. Maybe the socket is dead? */ + smb_read_error = READ_ERROR; + return False; + } - /* Did we timeout ? */ - if (selrtn == 0) { - smb_read_error = READ_TIMEOUT; - return False; - } - - if (FD_ISSET(smbd_server_fd(),&fds)) - { - *got_smb = True; - return receive_smb(smbd_server_fd(), buffer, 0); - } - else - { - return receive_local_message(&fds, buffer, buffer_len, 0); - } + /* Did we timeout ? */ + if (selrtn == 0) { + smb_read_error = READ_TIMEOUT; + return False; + } + + if (FD_ISSET(smbd_server_fd(),&fds)) { + *got_smb = True; + return receive_smb(smbd_server_fd(), buffer, 0); + } else { + return receive_local_message(&fds, buffer, buffer_len, 0); + } } /**************************************************************************** -- cgit From b2d01bd2dbfed8b35cc324fad42eac562fcad3b4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 12 Jun 2000 15:53:31 +0000 Subject: totally rewrote the async signal, notification and oplock notification handling in Samba. This was needed due to several limitations and races in the previous code - as a side effect the new code is much cleaner :) in summary: - changed sys_select() to avoid a signal/select race condition. It is a rare race but once we have signals doing notification and oplocks it is important. - changed our main processing loop to take advantage of the new sys_select semantics - split the notify code into implementaion dependent and general parts. Added the following structure that defines an implementation: struct cnotify_fns { void * (*register_notify)(connection_struct *conn, char *path, uint32 flags); BOOL (*check_notify)(connection_struct *conn, uint16 vuid, char *path, uint32 flags, void *data, time_t t); void (*remove_notify)(void *data); }; then I wrote two implementations, one using hash/poll (like our old code) and the other using the new Linux kernel change notify. It should be easy to add other change notify implementations by creating a sructure of the above type. - fixed a bug in change notify where we were returning the wrong error code. - rewrote the core change notify code to be much simpler - moved to real-time signals for leases and change notify Amazingly, it all seems to work. I was very surprised! (This used to be commit 44766c39e0027c762bee8b33b12c621c109a3267) --- source3/smbd/process.c | 253 +++++++++++++++++++++++-------------------------- 1 file changed, 120 insertions(+), 133 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 30d03747d8..b84e55343e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -107,7 +107,30 @@ static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len) BOOL push_oplock_pending_smb_message(char *buf, int msg_len) { - return push_message(&smb_oplock_queue, buf, msg_len); + return push_message(&smb_oplock_queue, buf, msg_len); +} + +/**************************************************************************** +do all async processing in here. This includes UDB oplock messages, kernel +oplock messages, change notify events etc. +****************************************************************************/ +static void async_processing(fd_set *fds, char *buffer, int buffer_len) +{ + /* check for oplock messages (both UDP and kernel) */ + if (receive_local_message(fds, buffer, buffer_len, 0)) { + process_local_message(buffer, buffer_len); + } + + /* check for async change notify events */ + process_pending_change_notify_queue(0); + + /* check for sighup processing */ + if (reload_after_sighup) { + unbecome_user(); + DEBUG(1,("Reloading services after SIGHUP\n")); + reload_services(False); + reload_after_sighup = False; + } } /**************************************************************************** @@ -115,7 +138,7 @@ BOOL push_oplock_pending_smb_message(char *buf, int msg_len) If a local udp message has been pushed onto the queue (this can only happen during oplock break - processing) return this first. + processing) call async_processing() If a pending smb message has been pushed onto the queue (this can only happen during oplock break @@ -131,8 +154,7 @@ BOOL push_oplock_pending_smb_message(char *buf, int msg_len) The timeout is in milli seconds ****************************************************************************/ -static BOOL receive_message_or_smb(char *buffer, int buffer_len, - int timeout, BOOL *got_smb) +static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) { fd_set fds; int selrtn; @@ -141,30 +163,28 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, smb_read_error = 0; - *got_smb = False; - /* * Check to see if we already have a message on the smb queue. * If so - copy and return it. */ - - if(ubi_slCount(&smb_oplock_queue) != 0) { + if(ubi_slCount(&smb_oplock_queue) != 0) { pending_message_list *msg = (pending_message_list *)ubi_slRemHead(&smb_oplock_queue); memcpy(buffer, msg->msg_buf, MIN(buffer_len, msg->msg_len)); /* Free the message we just copied. */ free((char *)msg->msg_buf); free((char *)msg); - *got_smb = True; DEBUG(5,("receive_message_or_smb: returning queued smb message.\n")); return True; } + /* * Setup the select read fd set. */ + again: FD_ZERO(&fds); FD_SET(smbd_server_fd(),&fds); maxfd = setup_oplock_select_set(&fds); @@ -175,16 +195,16 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, selrtn = sys_select(MAX(maxfd,smbd_server_fd())+1,&fds,timeout>0?&to:NULL); /* if we get EINTR then maybe we have received an oplock - signal - treat this as select returning 1. This is ugly, but - is the best we can do until the oplock code knows more about - signals */ + signal - treat this as select returning 1. This is ugly, but + is the best we can do until the oplock code knows more about + signals */ if (selrtn == -1 && errno == EINTR) { - FD_ZERO(&fds); - selrtn = 1; + async_processing(&fds, buffer, buffer_len); + goto again; } /* Check if error */ - if(selrtn == -1 && errno != EINTR) { + if (selrtn == -1) { /* something is wrong. Maybe the socket is dead? */ smb_read_error = READ_ERROR; return False; @@ -195,13 +215,13 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, smb_read_error = READ_TIMEOUT; return False; } - - if (FD_ISSET(smbd_server_fd(),&fds)) { - *got_smb = True; - return receive_smb(smbd_server_fd(), buffer, 0); - } else { - return receive_local_message(&fds, buffer, buffer_len, 0); + + if (!FD_ISSET(smbd_server_fd(),&fds) || selrtn > 1) { + async_processing(&fds, buffer, buffer_len); + if (!FD_ISSET(smbd_server_fd(),&fds)) goto again; } + + return receive_smb(smbd_server_fd(), buffer, 0); } /**************************************************************************** @@ -210,30 +230,16 @@ Get the next SMB packet, doing the local message processing automatically. BOOL receive_next_smb(char *inbuf, int bufsize, int timeout) { - BOOL got_smb = False; - BOOL ret; - - do - { - ret = receive_message_or_smb(inbuf,bufsize,timeout,&got_smb); + BOOL got_keepalive; + BOOL ret; - if(ret && !got_smb) - { - /* Deal with oplock break requests from other smbd's. */ - process_local_message(inbuf, bufsize); - continue; - } - - if(ret && (CVAL(inbuf,0) == 0x85)) - { - /* Keepalive packet. */ - got_smb = False; - } - - } - while(ret && !got_smb); + do { + ret = receive_message_or_smb(inbuf,bufsize,timeout); + + got_keepalive = (ret && (CVAL(inbuf,0) == 0x85)); + } while (ret && got_keepalive); - return ret; + return ret; } /**************************************************************************** @@ -270,13 +276,12 @@ void respond_to_all_remaining_local_messages(void) * Keep doing receive_local_message with a 1 ms timeout until * we have no more messages. */ - while(receive_local_message(&fds, buffer, sizeof(buffer), 1)) { - /* Deal with oplock break requests from other smbd's. */ - process_local_message(buffer, sizeof(buffer)); + /* Deal with oplock break requests from other smbd's. */ + process_local_message(buffer, sizeof(buffer)); - FD_ZERO(&fds); - (void)setup_oplock_select_set(&fds); + FD_ZERO(&fds); + (void)setup_oplock_select_set(&fds); } return; @@ -1008,98 +1013,80 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); void smbd_process(void) { - extern int smb_echo_count; - time_t last_timeout_processing_time = time(NULL); - unsigned int num_smbs = 0; + extern int smb_echo_count; + time_t last_timeout_processing_time = time(NULL); + unsigned int num_smbs = 0; - InBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - OutBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - if ((InBuffer == NULL) || (OutBuffer == NULL)) - return; + InBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + OutBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + if ((InBuffer == NULL) || (OutBuffer == NULL)) + return; - InBuffer += SMB_ALIGNMENT; - OutBuffer += SMB_ALIGNMENT; + InBuffer += SMB_ALIGNMENT; + OutBuffer += SMB_ALIGNMENT; - max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); + max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); - /* re-initialise the timezone */ - TimeInit(); + /* re-initialise the timezone */ + TimeInit(); - while (True) - { - int deadtime = lp_deadtime()*60; - BOOL got_smb = False; - int select_timeout = setup_select_timeout(); - - if (deadtime <= 0) - deadtime = DEFAULT_SMBD_TIMEOUT; - - errno = 0; - - /* free up temporary memory */ - lp_talloc_free(); - - /* - * If reload_after_sighup == True then we got a SIGHUP - * and are being asked to reload. Fix from - */ - if (reload_after_sighup) { - /* become root */ - unbecome_user(); - DEBUG(1,("Reloading services after SIGHUP\n")); - reload_services(False); - reload_after_sighup = False; - } - - while(!receive_message_or_smb(InBuffer,BUFFER_SIZE,select_timeout,&got_smb)) - { - if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) - return; - num_smbs = 0; /* Reset smb counter. */ - } - - if(got_smb) { - /* - * Ensure we do timeout processing if the SMB we just got was - * only an echo request. This allows us to set the select - * timeout in 'receive_message_or_smb()' to any value we like - * without worrying that the client will send echo requests - * faster than the select timeout, thus starving out the - * essential processing (change notify, blocking locks) that - * the timeout code does. JRA. - */ - int num_echos = smb_echo_count; - - process_smb(InBuffer, OutBuffer); - - if(smb_echo_count != num_echos) { - if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) - return; - num_smbs = 0; /* Reset smb counter. */ - } - - num_smbs++; + while (True) { + int deadtime = lp_deadtime()*60; + int select_timeout = setup_select_timeout(); + int num_echos; - /* - * If we are getting smb requests in a constant stream - * with no echos, make sure we attempt timeout processing - * every select_timeout milliseconds - but only check for this - * every 200 smb requests. - */ + if (deadtime <= 0) + deadtime = DEFAULT_SMBD_TIMEOUT; - if((num_smbs % 200) == 0) { - time_t new_check_time = time(NULL); - if(last_timeout_processing_time - new_check_time >= (select_timeout/1000)) { - if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) - return; - num_smbs = 0; /* Reset smb counter. */ - last_timeout_processing_time = new_check_time; /* Reset time. */ - } - } - } - else - process_local_message(InBuffer, BUFFER_SIZE); - } + errno = 0; + + /* free up temporary memory */ + lp_talloc_free(); + + while (!receive_message_or_smb(InBuffer,BUFFER_SIZE,select_timeout)) { + if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) + return; + num_smbs = 0; /* Reset smb counter. */ + } + + /* + * Ensure we do timeout processing if the SMB we just got was + * only an echo request. This allows us to set the select + * timeout in 'receive_message_or_smb()' to any value we like + * without worrying that the client will send echo requests + * faster than the select timeout, thus starving out the + * essential processing (change notify, blocking locks) that + * the timeout code does. JRA. + */ + num_echos = smb_echo_count; + + process_smb(InBuffer, OutBuffer); + + if (smb_echo_count != num_echos) { + if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) + return; + num_smbs = 0; /* Reset smb counter. */ + } + + num_smbs++; + + /* + * If we are getting smb requests in a constant stream + * with no echos, make sure we attempt timeout processing + * every select_timeout milliseconds - but only check for this + * every 200 smb requests. + */ + + if ((num_smbs % 200) == 0) { + time_t new_check_time = time(NULL); + if(last_timeout_processing_time - new_check_time >= (select_timeout/1000)) { + if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) + return; + num_smbs = 0; /* Reset smb counter. */ + last_timeout_processing_time = new_check_time; /* Reset time. */ + } + } + } } #undef OLD_NTDOMAIN -- cgit From cc5502a4d01bfc4946fbd198aad75ea03e9734d3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 14 Jun 2000 07:11:27 +0000 Subject: allow the notify implementation to choose the select timeout change (This used to be commit b1441d9622609af5ef598c5e1e1f5af438dc0731) --- source3/smbd/process.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index b84e55343e..3c85c05312 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -836,21 +836,21 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) static int setup_select_timeout(void) { - int change_notify_timeout = lp_change_notify_timeout() * 1000; - int select_timeout; + int select_timeout; + int t; - /* - * Increase the select timeout back to SMBD_SELECT_TIMEOUT if we - * have removed any blocking locks. JRA. - */ + /* + * Increase the select timeout back to SMBD_SELECT_TIMEOUT if we + * have removed any blocking locks. JRA. + */ - select_timeout = blocking_locks_pending() ? SMBD_SELECT_TIMEOUT_WITH_PENDING_LOCKS*1000 : - SMBD_SELECT_TIMEOUT*1000; + select_timeout = blocking_locks_pending() ? SMBD_SELECT_TIMEOUT_WITH_PENDING_LOCKS*1000 : + SMBD_SELECT_TIMEOUT*1000; - if (change_notifies_pending()) - select_timeout = MIN(select_timeout, change_notify_timeout); + t = change_notify_timeout(); + if (t != -1) select_timeout = MIN(select_timeout, t*1000); - return select_timeout; + return select_timeout; } /**************************************************************************** -- cgit From 5ec1642809d9de83da8c88c65d6595c6eb0270f5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 Jul 2000 00:47:19 +0000 Subject: Ok - this is a *BIG* change - but it fixes the problems with static strings in the RPC code. This change was prompted by trying to save a long (>256) character comment in the printer properties page. The new system associates a TALLOC_CTX with the pipe struct, and frees the pool on return of a complete PDU. A global TALLOC_CTX is used for the odd buffer allocated in the BUFFERxx code, and is freed in the main loop. This code works with insure, and seems to be free of memory leaks and crashes (so far) but there are probably the occasional problem with code that uses UNISTRxx structs on the stack and expects them to contain storage without doing a init_unistrXX(). This means that rpcclient will probably be horribly broken. A TALLOC_CTX also needed associating with the struct cli_state also, to make the prs_xx code there work. The main interface change is the addition of a TALLOC_CTX to the prs_init calls - used for dynamic allocation in the prs_XXX calls. Now this is in place it should make dynamic allocation of all RPC memory on unmarshall *much* easier to fix. Jeremy. (This used to be commit 0ff2ce543ee54f7364e6d839db6d06e7ef1edcf4) --- source3/smbd/process.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 3c85c05312..2662db5896 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1042,6 +1042,7 @@ void smbd_process(void) /* free up temporary memory */ lp_talloc_free(); + parse_talloc_free(); while (!receive_message_or_smb(InBuffer,BUFFER_SIZE,select_timeout)) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) -- cgit From 17dcd9a834fc915fb1ff2d8042a23000eeb7acfa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 2 Aug 2000 02:11:55 +0000 Subject: Started to canonicalize our handling of uid -> sid code in order to get ready and fix se_access_check(). Added cannonical lookup_name(), lookup_sid(), uid_to_sid(), gid_to_sid() functions that look via winbind first the fall back on local lookup. All Samba should use these rather than trying to call winbindd code directly. Added NT_USER_TOKEN struct in user_struct, contains list of NT sids associated with this user. se_access_check() should use this (cached) value rather than attempting to do the same thing itself when given a uid/gid pair. More work needs to be done to preserve these things accross security context changes (especially with the tricky pipe problem) but I'm beginning to see how this will be done..... probably by registering a new vuid for an authenticated RPC pipe and not treating the pipe calls specially. More thoughts needed - but we're almost there... Jeremy. (This used to be commit 5e5cc6efe2e4687be59085f562caea1e2e05d0a8) --- source3/smbd/process.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2662db5896..37d8f8dd73 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -561,8 +561,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize } /* load service specific parameters */ - if (conn && - !become_service(conn,(flags & AS_USER)?True:False)) { + if (conn && !become_service(conn,(flags & AS_USER)?True:False)) { return(ERROR(ERRSRV,ERRaccess)); } -- cgit From 3689e4ffc10fceb4c39814ef58fe31697e7dd976 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 Sep 2000 07:02:43 +0000 Subject: the first cut of the internal messaging system. The motivation for this system is to replace the UDP message for oplocks, but this commit only does the "set debug level" message. (This used to be commit 2a34ee95f3929cff131db6c5a2b4820194c05b2d) --- source3/smbd/process.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 37d8f8dd73..1599ade12d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -131,6 +131,9 @@ static void async_processing(fd_set *fds, char *buffer, int buffer_len) reload_services(False); reload_after_sighup = False; } + + /* check for any pending internal messages */ + message_dispatch(); } /**************************************************************************** -- cgit From cdb71ca5181aa1e06bebe2fffb02dc39de83645e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 10 Oct 2000 21:52:31 +0000 Subject: Fixes to periodically scan printing.tdb in idle time and occasionally on exit. Needed to fix printing.tdb from groving to 300Mb+ if being driven by smbclient clients that never ask for status... (effective DOS attack :-). Jeremy. (This used to be commit 6581066b93a674fadf6f9b92441428d2cc8b4a02) --- source3/smbd/process.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1599ade12d..9ed83ec88c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -993,6 +993,12 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); */ process_pending_change_notify_queue(t); + /* + * Ensure the print queue tdb doesn't grow too + * big by periodically scanning it. + */ + process_print_queue(t); + /* * Now we are root, check if the log files need pruning. */ -- cgit From e9270d61fc8ddaecd8eb1d2c0a9ce8eba13b1194 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Oct 2000 02:04:46 +0000 Subject: Remove lpq as root fix - do this in print_job_start instead as part of print queue length processing. Jeremy. (This used to be commit e85a0fadd8dcf608822819f00f15569713518806) --- source3/smbd/process.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 9ed83ec88c..1599ade12d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -993,12 +993,6 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); */ process_pending_change_notify_queue(t); - /* - * Ensure the print queue tdb doesn't grow too - * big by periodically scanning it. - */ - process_print_queue(t); - /* * Now we are root, check if the log files need pruning. */ -- cgit From 7a42a9da7d26ce4635aa479f93de6794317b2f29 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Thu, 12 Oct 2000 15:41:16 +0000 Subject: use macros for incrementing profile counters (This used to be commit cae5eeb16e81b6aa95c68223268513c32aed7056) --- source3/smbd/process.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1599ade12d..dc56534edb 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -636,9 +636,7 @@ void process_smb(char *inbuf, char *outbuf) int32 len = smb_len(inbuf); int nread = len + 4; -#ifdef WITH_PROFILE - profile_p->smb_count++; -#endif + DO_PROFILE_INC(smb_count); if (trans_num == 0) { /* on the first packet, check the global hosts allow/ hosts -- cgit From 2bd3a436fd6ed218bced476b502d24f317511fb2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 21 Nov 2000 00:30:15 +0000 Subject: Fix for updating of print queues changed from a local box. Essentially, this makes sure that the change messages sent to ourselves are handled synchronously w.r.t. other smb packets incoming. Jeremy. (This used to be commit 78a13074455618308d048d1c69f62e660988eb90) --- source3/smbd/process.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index dc56534edb..ea0309599f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -131,9 +131,6 @@ static void async_processing(fd_set *fds, char *buffer, int buffer_len) reload_services(False); reload_after_sighup = False; } - - /* check for any pending internal messages */ - message_dispatch(); } /**************************************************************************** @@ -166,6 +163,15 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) smb_read_error = 0; + again: + + /* + * Note that this call must be before processing any SMB + * messages as we need to synchronously process any messages + * we may have sent to ourselves from the previous SMB. + */ + message_dispatch(); + /* * Check to see if we already have a message on the smb queue. * If so - copy and return it. @@ -187,7 +193,6 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) * Setup the select read fd set. */ - again: FD_ZERO(&fds); FD_SET(smbd_server_fd(),&fds); maxfd = setup_oplock_select_set(&fds); -- cgit From 2f7c1db093504a9798cdfd9c5d08a259cb4abc46 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 23 Jan 2001 01:52:30 +0000 Subject: include/vfs.h: smbd/vfs-wrap.c: smbd/vfs.c: Added fchmod_acl and chmod_acl. lib/substitute.c: smbd/lanman.c: smbd/open.c: smbd/process.c: smbd/reply.c: smbd/service.c: Removed sessetup_user variable. Added current_user_info struct which conatins domain info etc. Added '%D' for client domain parameter. Jeremy. (This used to be commit 2844ec3d511680609d6794b8718001a1bda9e89f) --- source3/smbd/process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ea0309599f..0916dc5b7e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -44,7 +44,7 @@ int max_recv = BUFFER_SIZE; extern int last_message; extern int global_oplock_break; -extern pstring sesssetup_user; +extern userdom_struct current_user_info; extern char *last_inbuf; extern char *InBuffer; extern char *OutBuffer; @@ -524,7 +524,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize SSVAL(inbuf,smb_uid,session_tag); /* - * Ensure the correct username is in sesssetup_user. + * Ensure the correct username is in current_user_info. * This is a really ugly bugfix for problems with * multiple session_setup_and_X's being done and * allowing %U and %G substitutions to work correctly. @@ -539,7 +539,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize if(session_tag != UID_FIELD_INVALID) vuser = get_valid_user_struct(session_tag); if(vuser != NULL) - pstrcpy( sesssetup_user, vuser->user.smb_name); + current_user_info = vuser->user; } /* does this protocol need to be run as root? */ -- cgit From 918c3ebe32aacee82fe354d5b9b7ea4d477dcfda Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Jan 2001 19:04:56 +0000 Subject: smbd/lanman.c: Fix for calling qsort with 0 number. smbd/nttrans.c: Realloc mem fixes based on those that went into trans2.c smbd/process.c: Move to a table based dispatch, based on a comment from Andrew about Antons work. Jeremy. (This used to be commit a958f7822e095367efb8749b6f1f2e110ffb8866) --- source3/smbd/process.c | 525 +++++++++++++++++++++++++++++++------------------ 1 file changed, 330 insertions(+), 195 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 0916dc5b7e..9d857440b8 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -317,114 +317,270 @@ force write permissions on print services. */ struct smb_message_struct { - int code; char *name; int (*fn)(connection_struct *conn, char *, char *, int, int); int flags; } - smb_messages[] = { - - /* CORE PROTOCOL */ - - {SMBnegprot,"SMBnegprot",reply_negprot,0}, - {SMBtcon,"SMBtcon",reply_tcon,0}, - {SMBtdis,"SMBtdis",reply_tdis,0}, - {SMBexit,"SMBexit",reply_exit,0}, - {SMBioctl,"SMBioctl",reply_ioctl,0}, - {SMBecho,"SMBecho",reply_echo,0}, - {SMBsesssetupX,"SMBsesssetupX",reply_sesssetup_and_X,0}, - {SMBtconX,"SMBtconX",reply_tcon_and_X,0}, - {SMBulogoffX, "SMBulogoffX", reply_ulogoffX, 0}, /* ulogoff doesn't give a valid TID */ - {SMBgetatr,"SMBgetatr",reply_getatr,AS_USER}, - {SMBsetatr,"SMBsetatr",reply_setatr,AS_USER | NEED_WRITE}, - {SMBchkpth,"SMBchkpth",reply_chkpth,AS_USER}, - {SMBsearch,"SMBsearch",reply_search,AS_USER}, - {SMBopen,"SMBopen",reply_open,AS_USER | QUEUE_IN_OPLOCK }, - - /* note that SMBmknew and SMBcreate are deliberately overloaded */ - {SMBcreate,"SMBcreate",reply_mknew,AS_USER}, - {SMBmknew,"SMBmknew",reply_mknew,AS_USER}, - - {SMBunlink,"SMBunlink",reply_unlink,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK}, - {SMBread,"SMBread",reply_read,AS_USER}, - {SMBwrite,"SMBwrite",reply_write,AS_USER | CAN_IPC }, - {SMBclose,"SMBclose",reply_close,AS_USER | CAN_IPC }, - {SMBmkdir,"SMBmkdir",reply_mkdir,AS_USER | NEED_WRITE}, - {SMBrmdir,"SMBrmdir",reply_rmdir,AS_USER | NEED_WRITE}, - {SMBdskattr,"SMBdskattr",reply_dskattr,AS_USER}, - {SMBmv,"SMBmv",reply_mv,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK}, - - /* this is a Pathworks specific call, allowing the - changing of the root path */ - {pSETDIR,"pSETDIR",reply_setdir,AS_USER}, - - {SMBlseek,"SMBlseek",reply_lseek,AS_USER}, - {SMBflush,"SMBflush",reply_flush,AS_USER}, - {SMBctemp,"SMBctemp",reply_ctemp,AS_USER | QUEUE_IN_OPLOCK }, - {SMBsplopen,"SMBsplopen",reply_printopen,AS_USER | QUEUE_IN_OPLOCK }, - {SMBsplclose,"SMBsplclose",reply_printclose,AS_USER}, - {SMBsplretq,"SMBsplretq",reply_printqueue,AS_USER}, - {SMBsplwr,"SMBsplwr",reply_printwrite,AS_USER}, - {SMBlock,"SMBlock",reply_lock,AS_USER}, - {SMBunlock,"SMBunlock",reply_unlock,AS_USER}, - - /* CORE+ PROTOCOL FOLLOWS */ - - {SMBreadbraw,"SMBreadbraw",reply_readbraw,AS_USER}, - {SMBwritebraw,"SMBwritebraw",reply_writebraw,AS_USER}, - {SMBwriteclose,"SMBwriteclose",reply_writeclose,AS_USER}, - {SMBlockread,"SMBlockread",reply_lockread,AS_USER}, - {SMBwriteunlock,"SMBwriteunlock",reply_writeunlock,AS_USER}, - - /* LANMAN1.0 PROTOCOL FOLLOWS */ - - {SMBreadBmpx,"SMBreadBmpx",reply_readbmpx,AS_USER}, - {SMBreadBs,"SMBreadBs",NULL,AS_USER}, - {SMBwriteBmpx,"SMBwriteBmpx",reply_writebmpx,AS_USER}, - {SMBwriteBs,"SMBwriteBs",reply_writebs,AS_USER}, - {SMBwritec,"SMBwritec",NULL,AS_USER}, - {SMBsetattrE,"SMBsetattrE",reply_setattrE,AS_USER | NEED_WRITE }, - {SMBgetattrE,"SMBgetattrE",reply_getattrE,AS_USER }, - {SMBtrans,"SMBtrans",reply_trans,AS_USER | CAN_IPC | QUEUE_IN_OPLOCK}, - {SMBtranss,"SMBtranss",NULL,AS_USER | CAN_IPC}, - {SMBioctls,"SMBioctls",NULL,AS_USER}, - {SMBcopy,"SMBcopy",reply_copy,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK }, - {SMBmove,"SMBmove",NULL,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK }, - - {SMBopenX,"SMBopenX",reply_open_and_X,AS_USER | CAN_IPC | QUEUE_IN_OPLOCK }, - {SMBreadX,"SMBreadX",reply_read_and_X,AS_USER | CAN_IPC }, - {SMBwriteX,"SMBwriteX",reply_write_and_X,AS_USER | CAN_IPC }, - {SMBlockingX,"SMBlockingX",reply_lockingX,AS_USER }, - - {SMBffirst,"SMBffirst",reply_search,AS_USER}, - {SMBfunique,"SMBfunique",reply_search,AS_USER}, - {SMBfclose,"SMBfclose",reply_fclose,AS_USER}, - - /* LANMAN2.0 PROTOCOL FOLLOWS */ - {SMBfindnclose, "SMBfindnclose", reply_findnclose, AS_USER}, - {SMBfindclose, "SMBfindclose", reply_findclose,AS_USER}, - {SMBtrans2, "SMBtrans2", reply_trans2, AS_USER | QUEUE_IN_OPLOCK | CAN_IPC }, - {SMBtranss2, "SMBtranss2", reply_transs2, AS_USER}, - - /* NT PROTOCOL FOLLOWS */ - {SMBntcreateX, "SMBntcreateX", reply_ntcreate_and_X, AS_USER | CAN_IPC | QUEUE_IN_OPLOCK }, - {SMBnttrans, "SMBnttrans", reply_nttrans, AS_USER | CAN_IPC | QUEUE_IN_OPLOCK}, - {SMBnttranss, "SMBnttranss", reply_nttranss, AS_USER | CAN_IPC }, - {SMBntcancel, "SMBntcancel", reply_ntcancel, 0 }, - - /* messaging routines */ - {SMBsends,"SMBsends",reply_sends,AS_GUEST}, - {SMBsendstrt,"SMBsendstrt",reply_sendstrt,AS_GUEST}, - {SMBsendend,"SMBsendend",reply_sendend,AS_GUEST}, - {SMBsendtxt,"SMBsendtxt",reply_sendtxt,AS_GUEST}, - - /* NON-IMPLEMENTED PARTS OF THE CORE PROTOCOL */ - - {SMBsendb,"SMBsendb",NULL,AS_GUEST}, - {SMBfwdname,"SMBfwdname",NULL,AS_GUEST}, - {SMBcancelf,"SMBcancelf",NULL,AS_GUEST}, - {SMBgetmac,"SMBgetmac",NULL,AS_GUEST} - }; + smb_messages[256] = { + +/* 0x00 */ { "SMBmkdir",reply_mkdir,AS_USER | NEED_WRITE}, +/* 0x01 */ { "SMBrmdir",reply_rmdir,AS_USER | NEED_WRITE}, +/* 0x02 */ { "SMBopen",reply_open,AS_USER | QUEUE_IN_OPLOCK }, +/* 0x03 */ { "SMBcreate",reply_mknew,AS_USER}, +/* 0x04 */ { "SMBclose",reply_close,AS_USER | CAN_IPC }, +/* 0x05 */ { "SMBflush",reply_flush,AS_USER}, +/* 0x06 */ { "SMBunlink",reply_unlink,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK}, +/* 0x07 */ { "SMBmv",reply_mv,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK}, +/* 0x08 */ { "SMBgetatr",reply_getatr,AS_USER}, +/* 0x09 */ { "SMBsetatr",reply_setatr,AS_USER | NEED_WRITE}, +/* 0x0a */ { "SMBread",reply_read,AS_USER}, +/* 0x0b */ { "SMBwrite",reply_write,AS_USER | CAN_IPC }, +/* 0x0c */ { "SMBlock",reply_lock,AS_USER}, +/* 0x0d */ { "SMBunlock",reply_unlock,AS_USER}, +/* 0x0e */ { "SMBctemp",reply_ctemp,AS_USER | QUEUE_IN_OPLOCK }, +/* 0x0f */ { "SMBmknew",reply_mknew,AS_USER}, +/* 0x10 */ { "SMBchkpth",reply_chkpth,AS_USER}, +/* 0x11 */ { "SMBexit",reply_exit,0}, +/* 0x12 */ { "SMBlseek",reply_lseek,AS_USER}, +/* 0x13 */ { "SMBlockread",reply_lockread,AS_USER}, +/* 0x14 */ { "SMBwriteunlock",reply_writeunlock,AS_USER}, +/* 0x15 */ { NULL, NULL, 0 }, +/* 0x16 */ { NULL, NULL, 0 }, +/* 0x17 */ { NULL, NULL, 0 }, +/* 0x18 */ { NULL, NULL, 0 }, +/* 0x19 */ { NULL, NULL, 0 }, +/* 0x1a */ { "SMBreadbraw",reply_readbraw,AS_USER}, +/* 0x1b */ { "SMBreadBmpx",reply_readbmpx,AS_USER}, +/* 0x1c */ { "SMBreadBs",NULL,AS_USER}, +/* 0x1d */ { "SMBwritebraw",reply_writebraw,AS_USER}, +/* 0x1e */ { "SMBwriteBmpx",reply_writebmpx,AS_USER}, +/* 0x1f */ { "SMBwriteBs",reply_writebs,AS_USER}, +/* 0x20 */ { "SMBwritec",NULL,AS_USER}, +/* 0x21 */ { NULL, NULL, 0 }, +/* 0x22 */ { "SMBsetattrE",reply_setattrE,AS_USER | NEED_WRITE }, +/* 0x23 */ { "SMBgetattrE",reply_getattrE,AS_USER }, +/* 0x24 */ { "SMBlockingX",reply_lockingX,AS_USER }, +/* 0x25 */ { "SMBtrans",reply_trans,AS_USER | CAN_IPC | QUEUE_IN_OPLOCK}, +/* 0x26 */ { "SMBtranss",NULL,AS_USER | CAN_IPC}, +/* 0x27 */ { "SMBioctl",reply_ioctl,0}, +/* 0x28 */ { "SMBioctls",NULL,AS_USER}, +/* 0x29 */ { "SMBcopy",reply_copy,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK }, +/* 0x2a */ { "SMBmove",NULL,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK }, +/* 0x2b */ { "SMBecho",reply_echo,0}, +/* 0x2c */ { "SMBwriteclose",reply_writeclose,AS_USER}, +/* 0x2d */ { "SMBopenX",reply_open_and_X,AS_USER | CAN_IPC | QUEUE_IN_OPLOCK }, +/* 0x2e */ { "SMBreadX",reply_read_and_X,AS_USER | CAN_IPC }, +/* 0x2f */ { "SMBwriteX",reply_write_and_X,AS_USER | CAN_IPC }, +/* 0x30 */ { NULL, NULL, 0 }, +/* 0x31 */ { NULL, NULL, 0 }, +/* 0x32 */ { "SMBtrans2", reply_trans2, AS_USER | QUEUE_IN_OPLOCK | CAN_IPC }, +/* 0x33 */ { "SMBtranss2", reply_transs2, AS_USER}, +/* 0x34 */ { "SMBfindclose", reply_findclose,AS_USER}, +/* 0x35 */ { "SMBfindnclose", reply_findnclose, AS_USER}, +/* 0x36 */ { NULL, NULL, 0 }, +/* 0x37 */ { NULL, NULL, 0 }, +/* 0x38 */ { NULL, NULL, 0 }, +/* 0x39 */ { NULL, NULL, 0 }, +/* 0x3a */ { NULL, NULL, 0 }, +/* 0x3b */ { NULL, NULL, 0 }, +/* 0x3c */ { NULL, NULL, 0 }, +/* 0x3d */ { NULL, NULL, 0 }, +/* 0x3e */ { NULL, NULL, 0 }, +/* 0x3f */ { NULL, NULL, 0 }, +/* 0x40 */ { NULL, NULL, 0 }, +/* 0x41 */ { NULL, NULL, 0 }, +/* 0x42 */ { NULL, NULL, 0 }, +/* 0x43 */ { NULL, NULL, 0 }, +/* 0x44 */ { NULL, NULL, 0 }, +/* 0x45 */ { NULL, NULL, 0 }, +/* 0x46 */ { NULL, NULL, 0 }, +/* 0x47 */ { NULL, NULL, 0 }, +/* 0x48 */ { NULL, NULL, 0 }, +/* 0x49 */ { NULL, NULL, 0 }, +/* 0x4a */ { NULL, NULL, 0 }, +/* 0x4b */ { NULL, NULL, 0 }, +/* 0x4c */ { NULL, NULL, 0 }, +/* 0x4d */ { NULL, NULL, 0 }, +/* 0x4e */ { NULL, NULL, 0 }, +/* 0x4f */ { NULL, NULL, 0 }, +/* 0x50 */ { NULL, NULL, 0 }, +/* 0x51 */ { NULL, NULL, 0 }, +/* 0x52 */ { NULL, NULL, 0 }, +/* 0x53 */ { NULL, NULL, 0 }, +/* 0x54 */ { NULL, NULL, 0 }, +/* 0x55 */ { NULL, NULL, 0 }, +/* 0x56 */ { NULL, NULL, 0 }, +/* 0x57 */ { NULL, NULL, 0 }, +/* 0x58 */ { NULL, NULL, 0 }, +/* 0x59 */ { NULL, NULL, 0 }, +/* 0x5a */ { NULL, NULL, 0 }, +/* 0x5b */ { NULL, NULL, 0 }, +/* 0x5c */ { NULL, NULL, 0 }, +/* 0x5d */ { NULL, NULL, 0 }, +/* 0x5e */ { NULL, NULL, 0 }, +/* 0x5f */ { NULL, NULL, 0 }, +/* 0x60 */ { NULL, NULL, 0 }, +/* 0x61 */ { NULL, NULL, 0 }, +/* 0x62 */ { NULL, NULL, 0 }, +/* 0x63 */ { NULL, NULL, 0 }, +/* 0x64 */ { NULL, NULL, 0 }, +/* 0x65 */ { NULL, NULL, 0 }, +/* 0x66 */ { NULL, NULL, 0 }, +/* 0x67 */ { NULL, NULL, 0 }, +/* 0x68 */ { NULL, NULL, 0 }, +/* 0x69 */ { NULL, NULL, 0 }, +/* 0x6a */ { NULL, NULL, 0 }, +/* 0x6b */ { NULL, NULL, 0 }, +/* 0x6c */ { NULL, NULL, 0 }, +/* 0x6d */ { NULL, NULL, 0 }, +/* 0x6e */ { NULL, NULL, 0 }, +/* 0x6f */ { NULL, NULL, 0 }, +/* 0x70 */ { "SMBtcon",reply_tcon,0}, +/* 0x71 */ { "SMBtdis",reply_tdis,0}, +/* 0x72 */ { "SMBnegprot",reply_negprot,0}, +/* 0x73 */ { "SMBsesssetupX",reply_sesssetup_and_X,0}, +/* 0x74 */ { "SMBulogoffX", reply_ulogoffX, 0}, /* ulogoff doesn't give a valid TID */ +/* 0x75 */ { "SMBtconX",reply_tcon_and_X,0}, +/* 0x76 */ { NULL, NULL, 0 }, +/* 0x77 */ { NULL, NULL, 0 }, +/* 0x78 */ { NULL, NULL, 0 }, +/* 0x79 */ { NULL, NULL, 0 }, +/* 0x7a */ { NULL, NULL, 0 }, +/* 0x7b */ { NULL, NULL, 0 }, +/* 0x7c */ { NULL, NULL, 0 }, +/* 0x7d */ { NULL, NULL, 0 }, +/* 0x7e */ { NULL, NULL, 0 }, +/* 0x7f */ { NULL, NULL, 0 }, +/* 0x80 */ { "SMBdskattr",reply_dskattr,AS_USER}, +/* 0x81 */ { "SMBsearch",reply_search,AS_USER}, +/* 0x82 */ { "SMBffirst",reply_search,AS_USER}, +/* 0x83 */ { "SMBfunique",reply_search,AS_USER}, +/* 0x84 */ { "SMBfclose",reply_fclose,AS_USER}, +/* 0x85 */ { NULL, NULL, 0 }, +/* 0x86 */ { NULL, NULL, 0 }, +/* 0x87 */ { NULL, NULL, 0 }, +/* 0x88 */ { NULL, NULL, 0 }, +/* 0x89 */ { NULL, NULL, 0 }, +/* 0x8a */ { NULL, NULL, 0 }, +/* 0x8b */ { NULL, NULL, 0 }, +/* 0x8c */ { NULL, NULL, 0 }, +/* 0x8d */ { NULL, NULL, 0 }, +/* 0x8e */ { NULL, NULL, 0 }, +/* 0x8f */ { NULL, NULL, 0 }, +/* 0x90 */ { NULL, NULL, 0 }, +/* 0x91 */ { NULL, NULL, 0 }, +/* 0x92 */ { NULL, NULL, 0 }, +/* 0x93 */ { NULL, NULL, 0 }, +/* 0x94 */ { NULL, NULL, 0 }, +/* 0x95 */ { NULL, NULL, 0 }, +/* 0x96 */ { NULL, NULL, 0 }, +/* 0x97 */ { NULL, NULL, 0 }, +/* 0x98 */ { NULL, NULL, 0 }, +/* 0x99 */ { NULL, NULL, 0 }, +/* 0x9a */ { NULL, NULL, 0 }, +/* 0x9b */ { NULL, NULL, 0 }, +/* 0x9c */ { NULL, NULL, 0 }, +/* 0x9d */ { NULL, NULL, 0 }, +/* 0x9e */ { NULL, NULL, 0 }, +/* 0x9f */ { NULL, NULL, 0 }, +/* 0xa0 */ { "SMBnttrans", reply_nttrans, AS_USER | CAN_IPC | QUEUE_IN_OPLOCK}, +/* 0xa1 */ { "SMBnttranss", reply_nttranss, AS_USER | CAN_IPC }, +/* 0xa2 */ { "SMBntcreateX", reply_ntcreate_and_X, AS_USER | CAN_IPC | QUEUE_IN_OPLOCK }, +/* 0xa3 */ { NULL, NULL, 0 }, +/* 0xa4 */ { "SMBntcancel", reply_ntcancel, 0 }, +/* 0xa5 */ { NULL, NULL, 0 }, +/* 0xa6 */ { NULL, NULL, 0 }, +/* 0xa7 */ { NULL, NULL, 0 }, +/* 0xa8 */ { NULL, NULL, 0 }, +/* 0xa9 */ { NULL, NULL, 0 }, +/* 0xaa */ { NULL, NULL, 0 }, +/* 0xab */ { NULL, NULL, 0 }, +/* 0xac */ { NULL, NULL, 0 }, +/* 0xad */ { NULL, NULL, 0 }, +/* 0xae */ { NULL, NULL, 0 }, +/* 0xaf */ { NULL, NULL, 0 }, +/* 0xb0 */ { NULL, NULL, 0 }, +/* 0xb1 */ { NULL, NULL, 0 }, +/* 0xb2 */ { NULL, NULL, 0 }, +/* 0xb3 */ { NULL, NULL, 0 }, +/* 0xb4 */ { NULL, NULL, 0 }, +/* 0xb5 */ { NULL, NULL, 0 }, +/* 0xb6 */ { NULL, NULL, 0 }, +/* 0xb7 */ { NULL, NULL, 0 }, +/* 0xb8 */ { NULL, NULL, 0 }, +/* 0xb9 */ { NULL, NULL, 0 }, +/* 0xba */ { NULL, NULL, 0 }, +/* 0xbb */ { NULL, NULL, 0 }, +/* 0xbc */ { NULL, NULL, 0 }, +/* 0xbd */ { NULL, NULL, 0 }, +/* 0xbe */ { NULL, NULL, 0 }, +/* 0xbf */ { NULL, NULL, 0 }, +/* 0xc0 */ { "SMBsplopen",reply_printopen,AS_USER | QUEUE_IN_OPLOCK }, +/* 0xc1 */ { "SMBsplwr",reply_printwrite,AS_USER}, +/* 0xc2 */ { "SMBsplclose",reply_printclose,AS_USER}, +/* 0xc3 */ { "SMBsplretq",reply_printqueue,AS_USER}, +/* 0xc4 */ { NULL, NULL, 0 }, +/* 0xc5 */ { NULL, NULL, 0 }, +/* 0xc6 */ { NULL, NULL, 0 }, +/* 0xc7 */ { NULL, NULL, 0 }, +/* 0xc8 */ { NULL, NULL, 0 }, +/* 0xc9 */ { NULL, NULL, 0 }, +/* 0xca */ { NULL, NULL, 0 }, +/* 0xcb */ { NULL, NULL, 0 }, +/* 0xcc */ { NULL, NULL, 0 }, +/* 0xcd */ { NULL, NULL, 0 }, +/* 0xce */ { NULL, NULL, 0 }, +/* 0xcf */ { NULL, NULL, 0 }, +/* 0xd0 */ { "SMBsends",reply_sends,AS_GUEST}, +/* 0xd1 */ { "SMBsendb",NULL,AS_GUEST}, +/* 0xd2 */ { "SMBfwdname",NULL,AS_GUEST}, +/* 0xd3 */ { "SMBcancelf",NULL,AS_GUEST}, +/* 0xd4 */ { "SMBgetmac",NULL,AS_GUEST}, +/* 0xd5 */ { "SMBsendstrt",reply_sendstrt,AS_GUEST}, +/* 0xd6 */ { "SMBsendend",reply_sendend,AS_GUEST}, +/* 0xd7 */ { "SMBsendtxt",reply_sendtxt,AS_GUEST}, +/* 0xd8 */ { NULL, NULL, 0 }, +/* 0xd9 */ { NULL, NULL, 0 }, +/* 0xda */ { NULL, NULL, 0 }, +/* 0xdb */ { NULL, NULL, 0 }, +/* 0xdc */ { NULL, NULL, 0 }, +/* 0xdd */ { NULL, NULL, 0 }, +/* 0xde */ { NULL, NULL, 0 }, +/* 0xdf */ { NULL, NULL, 0 }, +/* 0xe0 */ { NULL, NULL, 0 }, +/* 0xe1 */ { NULL, NULL, 0 }, +/* 0xe2 */ { NULL, NULL, 0 }, +/* 0xe3 */ { NULL, NULL, 0 }, +/* 0xe4 */ { NULL, NULL, 0 }, +/* 0xe5 */ { NULL, NULL, 0 }, +/* 0xe6 */ { NULL, NULL, 0 }, +/* 0xe7 */ { NULL, NULL, 0 }, +/* 0xe8 */ { NULL, NULL, 0 }, +/* 0xe9 */ { NULL, NULL, 0 }, +/* 0xea */ { NULL, NULL, 0 }, +/* 0xeb */ { NULL, NULL, 0 }, +/* 0xec */ { NULL, NULL, 0 }, +/* 0xed */ { NULL, NULL, 0 }, +/* 0xee */ { NULL, NULL, 0 }, +/* 0xef */ { NULL, NULL, 0 }, +/* 0xf0 */ { NULL, NULL, 0 }, +/* 0xf1 */ { NULL, NULL, 0 }, +/* 0xf2 */ { NULL, NULL, 0 }, +/* 0xf3 */ { NULL, NULL, 0 }, +/* 0xf4 */ { NULL, NULL, 0 }, +/* 0xf5 */ { NULL, NULL, 0 }, +/* 0xf6 */ { NULL, NULL, 0 }, +/* 0xf7 */ { NULL, NULL, 0 }, +/* 0xf8 */ { NULL, NULL, 0 }, +/* 0xf9 */ { NULL, NULL, 0 }, +/* 0xfa */ { NULL, NULL, 0 }, +/* 0xfb */ { NULL, NULL, 0 }, +/* 0xfc */ { NULL, NULL, 0 }, +/* 0xfd */ { NULL, NULL, 0 }, +/* 0xfe */ { NULL, NULL, 0 }, +/* 0xff */ { NULL, NULL, 0 } + +}; /******************************************************************* dump a prs to a file @@ -457,9 +613,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize { static pid_t pid= (pid_t)-1; int outsize = 0; - static int num_smb_messages = - sizeof(smb_messages) / sizeof(struct smb_message_struct); - int match; extern int global_smbpid; if (pid == (pid_t)-1) @@ -475,15 +628,11 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize return(-1); } - for (match=0;matchuser; - } - - /* does this protocol need to be run as root? */ - if (!(flags & AS_USER)) - unbecome_user(); - - /* does this protocol need to be run as the connected user? */ - if ((flags & AS_USER) && !become_user(conn,session_tag)) { - if (flags & AS_GUEST) - flags &= ~AS_USER; - else - return(ERROR(ERRSRV,ERRaccess)); - } - /* this code is to work around a bug is MS client 3 without - introducing a security hole - it needs to be able to do - print queue checks as guest if it isn't logged in properly */ - if (flags & AS_USER) - flags &= ~AS_GUEST; - - /* does it need write permission? */ - if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) - return(ERROR(ERRSRV,ERRaccess)); - /* ipc services are limited */ - if (IS_IPC(conn) && (flags & AS_USER) && !(flags & CAN_IPC)) { - return(ERROR(ERRSRV,ERRaccess)); - } + /* Ensure this value is replaced in the incoming packet. */ + SSVAL(inbuf,smb_uid,session_tag); - /* load service specific parameters */ - if (conn && !become_service(conn,(flags & AS_USER)?True:False)) { - return(ERROR(ERRSRV,ERRaccess)); - } + /* + * Ensure the correct username is in current_user_info. + * This is a really ugly bugfix for problems with + * multiple session_setup_and_X's being done and + * allowing %U and %G substitutions to work correctly. + * There is a reason this code is done here, don't + * move it unless you know what you're doing... :-). + * JRA. + */ - /* does this protocol need to be run as guest? */ - if ((flags & AS_GUEST) && - (!become_guest() || - !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) { + if (session_tag != last_session_tag) { + user_struct *vuser = NULL; + + last_session_tag = session_tag; + if(session_tag != UID_FIELD_INVALID) + vuser = get_valid_user_struct(session_tag); + if(vuser != NULL) + current_user_info = vuser->user; + } + + /* does this protocol need to be run as root? */ + if (!(flags & AS_USER)) + unbecome_user(); + + /* does this protocol need to be run as the connected user? */ + if ((flags & AS_USER) && !become_user(conn,session_tag)) { + if (flags & AS_GUEST) + flags &= ~AS_USER; + else return(ERROR(ERRSRV,ERRaccess)); - } + } + + /* this code is to work around a bug is MS client 3 without + introducing a security hole - it needs to be able to do + print queue checks as guest if it isn't logged in properly */ + if (flags & AS_USER) + flags &= ~AS_GUEST; - last_inbuf = inbuf; + /* does it need write permission? */ + if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) + return(ERROR(ERRSRV,ERRaccess)); - outsize = smb_messages[match].fn(conn, inbuf,outbuf,size,bufsize); + /* ipc services are limited */ + if (IS_IPC(conn) && (flags & AS_USER) && !(flags & CAN_IPC)) { + return(ERROR(ERRSRV,ERRaccess)); } - else - { - outsize = reply_unknown(inbuf,outbuf); + + /* load service specific parameters */ + if (conn && !become_service(conn,(flags & AS_USER)?True:False)) { + return(ERROR(ERRSRV,ERRaccess)); + } + + /* does this protocol need to be run as guest? */ + if ((flags & AS_GUEST) && + (!become_guest() || + !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) { + return(ERROR(ERRSRV,ERRaccess)); } + + last_inbuf = inbuf; + + outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); } - smb_dump(smb_messages[match].name, 0, outbuf, outsize); + smb_dump(smb_fn_name(type), 0, outbuf, outsize); return(outsize); } @@ -705,18 +847,11 @@ return a string containing the function name of a SMB command char *smb_fn_name(int type) { static char *unknown_name = "SMBunknown"; - static int num_smb_messages = - sizeof(smb_messages) / sizeof(struct smb_message_struct); - int match; - - for (match=0;match Date: Wed, 24 Jan 2001 19:34:53 +0000 Subject: smbd/process.c: & type with 0xff for paranioa sake... smbd/reply.c smbd/service.c: cause all "add home service" calls to go through a winbindd aware function. Jeremy. (This used to be commit a72d12e992e2755e925032aef1aa99be74bf6652) --- source3/smbd/process.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 9d857440b8..eb18219992 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -615,6 +615,8 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize int outsize = 0; extern int global_smbpid; + type &= 0xff; + if (pid == (pid_t)-1) pid = sys_getpid(); -- cgit From 94fc44a93c46cece9b9fa947bff62087dbcd89fa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 12 Feb 2001 16:18:02 +0000 Subject: Merge of JohnR's changes to appliance-head, JF's changes to 2.2, updated the POSIX_ACL code to be in sync. Jeremy. (This used to be commit c0517d6f4e3079feca1309fd1ea7b21e83f0de02) --- source3/smbd/process.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index eb18219992..461fa99f39 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -769,6 +769,30 @@ static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) return(outsize); } +/**************************************************************************** + Keep track of the number of running smbd's. This functionality is used to + 'hard' limit Samba overhead on resource constrained systems. +****************************************************************************/ +static BOOL smbd_process_limit(void) +{ + int total_smbds; + + if (lp_max_smbd_processes()) { + + /* Always add one to the smbd process count, as exit_server() always + * subtracts one. + */ + tdb_lock_bystring(conn_tdb_ctx(), "INFO/total_smbds"); + total_smbds = tdb_fetch_int(conn_tdb_ctx(), "INFO/total_smbds"); + total_smbds = total_smbds < 0 ? 1 : total_smbds + 1; + tdb_store_int(conn_tdb_ctx(), "INFO/total_smbds", total_smbds); + tdb_unlock_bystring(conn_tdb_ctx(), "INFO/total_smbds"); + + return total_smbds > lp_max_smbd_processes(); + } + else + return False; +} /**************************************************************************** process an smb from the client - split out from the process() code so @@ -792,8 +816,9 @@ void process_smb(char *inbuf, char *outbuf) deny parameters before doing any parsing of the packet passed to us by the client. This prevents attacks on our parsing code from hosts not in the hosts allow list */ - if (!check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1))) { - /* send a negative session response "not listining on calling + if (smbd_process_limit() || + !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1))) { + /* send a negative session response "not listening on calling name" */ static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; DEBUG( 1, ( "Connection denied from %s\n", -- cgit From 5265ce7837a185977f71bcb39a41b57492e24964 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Feb 2001 19:22:02 +0000 Subject: Added total memory allocated counter to talloc, so we can tell if a talloc pool is getting bloated. Also added a talloc_zero function to return zeroed memory. Added debug in rpc_server/srv_pipe_hnd.c so we know when a talloc pool is being freed. Syncup with srv_pipe_hnd.c from 2.2 so we are freeing memory at the same time. Jeremy. (This used to be commit d3a56c6042acf037bbd53de88d7636a5803ead20) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 461fa99f39..f8fde41b77 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1209,7 +1209,7 @@ void smbd_process(void) /* free up temporary memory */ lp_talloc_free(); - parse_talloc_free(); + main_loop_talloc_free(); while (!receive_message_or_smb(InBuffer,BUFFER_SIZE,select_timeout)) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) -- cgit From da3053048c3d224a20d6383ac6682d31059cd46c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 11 Mar 2001 00:32:10 +0000 Subject: Merge of new 2.2 code into HEAD (Gerald I hate you :-) :-). Allows new SAMR RPC code to merge with new passdb code. Currently rpcclient doesn't compile. I'm working on it... Jeremy. (This used to be commit 0be41d5158ea4e645e93e8cd30617c038416e549) --- source3/smbd/process.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f8fde41b77..a34555adc1 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1,4 +1,3 @@ -#define OLD_NTDOMAIN 1 /* Unix SMB/Netbios implementation. Version 1.9. @@ -1256,5 +1255,3 @@ void smbd_process(void) } } } - -#undef OLD_NTDOMAIN -- cgit From 23e5cf060d282c9ba9bdf49884ce23a13b285aac Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 13 Mar 2001 00:55:19 +0000 Subject: this patch does a number of things: - removes SMB_ALIGNMENT. That macro caused all sorts of problems with getting unicode aligned right in sub-protocols (such as SMBtrans and SMBtrans2). I believe the performance reasons for having SMB_ALIGNMENT has gone away with the new variants of the SMB protocol anyway, as newer commands tend to have their own internal alignment. - fix the locations where we set smb_flg2 to absolute values. We must never do this if we want a hope of coping with unicode. - add initial support for unicode on the wire in smbd. Currently enabled using SMBD_USE_UNICODE environment variable. (This used to be commit b98b1435e9d8f8622444c9ff33082977e661f16b) --- source3/smbd/process.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index a34555adc1..dea7130cfe 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -897,7 +897,8 @@ void construct_reply_common(char *inbuf,char *outbuf) CVAL(outbuf,smb_reh) = 0; SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); /* bit 7 set means a reply */ - SSVAL(outbuf,smb_flg2,FLAGS2_LONG_PATH_COMPONENTS); + SSVAL(outbuf,smb_flg2, + (SVAL(inbuf,smb_flg2)&FLAGS2_UNICODE_STRINGS) | FLAGS2_LONG_PATH_COMPONENTS); /* say we support long filenames */ SSVAL(outbuf,smb_err,SMB_SUCCESS); @@ -1188,9 +1189,6 @@ void smbd_process(void) if ((InBuffer == NULL) || (OutBuffer == NULL)) return; - InBuffer += SMB_ALIGNMENT; - OutBuffer += SMB_ALIGNMENT; - max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); /* re-initialise the timezone */ -- cgit From f9a15ce1a69f905e94db7650f0a4805720cd9c88 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 8 Apr 2001 20:22:39 +0000 Subject: Got "medieval on our ass" about adding the -1 to slprintf. Jeremy. (This used to be commit 94747b4639ed9b19f7d0fb896e43aa392a84989a) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index dea7130cfe..ac5454c48c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -592,7 +592,7 @@ static void smb_dump(char *name, int type, char *data, ssize_t len) if (len < 4) len = smb_len(data)+4; for (i=1;i<100;i++) { - slprintf(fname,sizeof(fname), "/tmp/%s.%d.%s", name, i, + slprintf(fname,sizeof(fname)-1, "/tmp/%s.%d.%s", name, i, type ? "req" : "resp"); fd = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0644); if (fd != -1 || errno != EEXIST) break; -- cgit From 9ff6634db923da17b0946141abf3ce7df61a0dab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 May 2001 19:28:22 +0000 Subject: Fixup the large_writex problem (a large_writex can send a full 64k of data, we already have space for this we just need to understand the length correctly). Jeremy. (This used to be commit 19145bae720bbcc32dcab380c62a33d1f0e3eef0) --- source3/smbd/process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ac5454c48c..74c0cbc96f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1184,8 +1184,8 @@ void smbd_process(void) time_t last_timeout_processing_time = time(NULL); unsigned int num_smbs = 0; - InBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - OutBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + InBuffer = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); + OutBuffer = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); if ((InBuffer == NULL) || (OutBuffer == NULL)) return; @@ -1208,7 +1208,7 @@ void smbd_process(void) lp_talloc_free(); main_loop_talloc_free(); - while (!receive_message_or_smb(InBuffer,BUFFER_SIZE,select_timeout)) { + while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) return; num_smbs = 0; /* Reset smb counter. */ -- cgit From 15e66ba37ae56787897e49039e217b5426924829 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 25 May 2001 00:48:28 +0000 Subject: Added tdb_change_int_atomic() to allow atomic updates of a tdb int value. Jeremy. (This used to be commit cf5015f15935605cf69078bc15251db61ddc48c7) --- source3/smbd/process.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 74c0cbc96f..1f575e2a46 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -781,12 +781,12 @@ static BOOL smbd_process_limit(void) /* Always add one to the smbd process count, as exit_server() always * subtracts one. */ - tdb_lock_bystring(conn_tdb_ctx(), "INFO/total_smbds"); - total_smbds = tdb_fetch_int(conn_tdb_ctx(), "INFO/total_smbds"); - total_smbds = total_smbds < 0 ? 1 : total_smbds + 1; - tdb_store_int(conn_tdb_ctx(), "INFO/total_smbds", total_smbds); - tdb_unlock_bystring(conn_tdb_ctx(), "INFO/total_smbds"); - + + total_smbds = 1; /* In case we need to create the entry. */ + + if (tdb_change_int_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, 1) == -1) + return True; + return total_smbds > lp_max_smbd_processes(); } else -- cgit From f63ee18c684af33342de2c5757f9fdf0b7d84997 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 9 Jun 2001 01:38:54 +0000 Subject: *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) --- source3/smbd/process.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1f575e2a46..f757467680 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -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++; } -- cgit From fcda2645f099e5d356361ec3de4f45d97285f0b5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Jun 2001 03:05:09 +0000 Subject: added a close-share smbcontrol message that forcibly closes a share in smbd (to allow unmount) (This used to be commit 15b17a80db605a55f667c95fb7e316877a441887) --- source3/smbd/process.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f757467680..72e0fc311a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -693,6 +693,12 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize if (!(flags & AS_USER)) unbecome_user(); + /* does this protocol need a valid tree connection? */ + if ((flags & AS_USER) && !conn) { + return ERROR(ERRSRV, ERRinvnid); + } + + /* does this protocol need to be run as the connected user? */ if ((flags & AS_USER) && !become_user(conn,session_tag)) { if (flags & AS_GUEST) @@ -1195,6 +1201,9 @@ void smbd_process(void) /* re-initialise the timezone */ TimeInit(); + /* register our message handlers */ + message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis); + while (True) { int deadtime = lp_deadtime()*60; int select_timeout = setup_select_timeout(); -- cgit From 5ba566efb70c1047301f551e8da0fcd0d3030283 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 22 Jun 2001 20:56:52 +0000 Subject: Fixed logic bug in timeout processing spotted by Ying Chen . Jeremy. (This used to be commit 08c168242364bf4d415f49d134e507a7e234611b) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 72e0fc311a..dae99ec80e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1254,7 +1254,7 @@ void smbd_process(void) if ((num_smbs % 200) == 0) { time_t new_check_time = time(NULL); - if(last_timeout_processing_time - new_check_time >= (select_timeout/1000)) { + if(new_check_time - last_timeout_processing_time >= (select_timeout/1000)) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) return; num_smbs = 0; /* Reset smb counter. */ -- cgit From b95a294a0879e800e816281a80d0074224cd8cd4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 25 Jun 2001 02:53:13 +0000 Subject: fixed usage of socklen_t and also tidied up SIG_ATOMIC_T, using a typedef instead of a define (This used to be commit e2ecff419fdc0a0dc7551b33b377dc11061ef2a3) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index dae99ec80e..f43c675289 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -48,7 +48,7 @@ extern char *last_inbuf; extern char *InBuffer; extern char *OutBuffer; extern int smb_read_error; -extern VOLATILE SIG_ATOMIC_T reload_after_sighup; +extern VOLATILE sig_atomic_t reload_after_sighup; extern BOOL global_machine_password_needs_changing; extern fstring global_myworkgroup; extern pstring global_myname; -- cgit From 5b69009b25886bfa8b07e3ac885064ffa730f9bf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 2 Jul 2001 02:42:41 +0000 Subject: Fixed the nastiest locking bug to track down.... smb_pids are sent in the lockingX calls - use that instead of smb_pid in the packet. Jeremy. (This used to be commit a3925cb9c6303ce24e5fecad6c8f3a0ba78b9ee0) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f43c675289..dd2318b58a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -612,7 +612,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize { static pid_t pid= (pid_t)-1; int outsize = 0; - extern int global_smbpid; + extern uint16 global_smbpid; type &= 0xff; -- cgit From 541f2b73bcb1621f6660266a0165a3d4f3aee521 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 9 Aug 2001 19:22:51 +0000 Subject: Fix inspired by Don @ HP. Close down password server connection if keepalive fails. Jeremy. (This used to be commit 1f6e3d18cdf460eb2569b737813f94d22680553e) --- source3/smbd/process.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index dd2318b58a..65fa600be4 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1104,7 +1104,10 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t /* also send a keepalive to the password server if its still connected */ if (cli && cli->initialised) - send_keepalive(cli->fd); + if (!send_keepalive(cli->fd)) { + DEBUG( 2, ( "password server keepalive failed.\n")); + cli_shutdown(cli); + } last_keepalive_sent_time = t; } -- cgit From c50ef232152551ac79502caaf259cdfc3a32ca96 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 22 Aug 2001 04:58:00 +0000 Subject: force checking of log size after 200 smbd in a row or after 30 sec with no smbds. This should fix one case of logs not getting rotated properly. We may need to test this to make sure there is no big performance hit from the extra stat call. (This used to be commit 2501fe7c0436fc00f35271e2dce17fe541e97424) --- source3/smbd/process.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 65fa600be4..2b75197c38 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1170,9 +1170,10 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); /* * Now we are root, check if the log files need pruning. + * Force a log file check. */ - if(need_to_check_log_size()) - check_log_size(); + force_check_log_size(); + check_log_size(); /* * Modify the select timeout depending upon -- cgit From e8e98c9ea0690e3acf1126b50882e59e1056c7b3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 Aug 2001 08:19:43 +0000 Subject: converted smbd to use NTSTATUS by default major changes include: - added NSTATUS type - added automatic mapping between dos and nt error codes - changed all ERROR() calls to ERROR_DOS() and many to ERROR_NT() these calls auto-translate to the client error code system - got rid of the cached error code and the writebmpx code We eventually will need to also: - get rid of BOOL, so we don't lose error info - replace all ERROR_DOS() calls with ERROR_NT() calls but that is too much for one night (This used to be commit 83d9896c1ea8be796192b51a4678c2a3b87f7518) --- source3/smbd/process.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2b75197c38..ce1e855e29 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -352,9 +352,9 @@ struct smb_message_struct /* 0x1b */ { "SMBreadBmpx",reply_readbmpx,AS_USER}, /* 0x1c */ { "SMBreadBs",NULL,AS_USER}, /* 0x1d */ { "SMBwritebraw",reply_writebraw,AS_USER}, -/* 0x1e */ { "SMBwriteBmpx",reply_writebmpx,AS_USER}, -/* 0x1f */ { "SMBwriteBs",reply_writebs,AS_USER}, -/* 0x20 */ { "SMBwritec",NULL,AS_USER}, +/* 0x1e */ { NULL,NULL,0}, +/* 0x1f */ { NULL,NULL,0}, +/* 0x20 */ { NULL,NULL,0}, /* 0x21 */ { NULL, NULL, 0 }, /* 0x22 */ { "SMBsetattrE",reply_setattrE,AS_USER | NEED_WRITE }, /* 0x23 */ { "SMBgetattrE",reply_getattrE,AS_USER }, @@ -695,7 +695,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* does this protocol need a valid tree connection? */ if ((flags & AS_USER) && !conn) { - return ERROR(ERRSRV, ERRinvnid); + return ERROR_DOS(ERRSRV, ERRinvnid); } @@ -704,7 +704,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize if (flags & AS_GUEST) flags &= ~AS_USER; else - return(ERROR(ERRSRV,ERRaccess)); + return(ERROR_DOS(ERRSRV,ERRaccess)); } /* this code is to work around a bug is MS client 3 without @@ -715,23 +715,23 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* does it need write permission? */ if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) - return(ERROR(ERRSRV,ERRaccess)); + return(ERROR_DOS(ERRSRV,ERRaccess)); /* ipc services are limited */ if (IS_IPC(conn) && (flags & AS_USER) && !(flags & CAN_IPC)) { - return(ERROR(ERRSRV,ERRaccess)); + return(ERROR_DOS(ERRSRV,ERRaccess)); } /* load service specific parameters */ if (conn && !become_service(conn,(flags & AS_USER)?True:False)) { - return(ERROR(ERRSRV,ERRaccess)); + return(ERROR_DOS(ERRSRV,ERRaccess)); } /* does this protocol need to be run as guest? */ if ((flags & AS_GUEST) && (!become_guest() || !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) { - return(ERROR(ERRSRV,ERRaccess)); + return(ERROR_DOS(ERRSRV,ERRaccess)); } last_inbuf = inbuf; -- cgit From 11f0402a74640c6f32ae18c58b60d9d57932deab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 5 Sep 2001 22:45:48 +0000 Subject: Fix I think for the fcntl spinning problem. Re-prioritize so that oplock break messages get priority over incoming client messages. Jeremy. (This used to be commit 1779f6a223dad87c3b8451d09b9808b46495a8b6) --- source3/smbd/process.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ce1e855e29..9f23c7d3be 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -223,7 +223,13 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) return False; } - if (!FD_ISSET(smbd_server_fd(),&fds) || selrtn > 1) { + /* + * Ensure we process oplock break messages by preference. + * This is IMPORTANT ! Otherwise we can starve other processes + * sending us an oplock break message. JRA. + */ + + if (oplock_message_waiting(&fds)) { async_processing(&fds, buffer, buffer_len); if (!FD_ISSET(smbd_server_fd(),&fds)) goto again; } -- cgit From 45706091f39573c01312179c48842284dc3e9012 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Sep 2001 23:03:14 +0000 Subject: Fix for second logic bug when handing oplock breaks and client messages simultaneously. Jeremy. (This used to be commit 227325b2d63dad55cbcda9608fba676fb6ce5584) --- source3/smbd/process.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 9f23c7d3be..bf9e6457af 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -207,6 +207,11 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) signals */ if (selrtn == -1 && errno == EINTR) { async_processing(&fds, buffer, buffer_len); + /* + * After async processing we must go and do the select again, as + * the state of the flag in fds for the server file descriptor is + * indeterminate - we may have done I/O on it in the oplock processing. JRA. + */ goto again; } @@ -231,7 +236,12 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) if (oplock_message_waiting(&fds)) { async_processing(&fds, buffer, buffer_len); - if (!FD_ISSET(smbd_server_fd(),&fds)) goto again; + /* + * After async processing we must go and do the select again, as + * the state of the flag in fds for the server file descriptor is + * indeterminate - we may have done I/O on it in the oplock processing. JRA. + */ + goto again; } return receive_smb(smbd_server_fd(), buffer, 0); -- cgit From 61b2794968faa35dc91edce17e9b91e5366c3514 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 11:25:41 +0000 Subject: move to SAFE_FREE() (This used to be commit a95943fde0ad89ae3f2deca2f7ba9cb5ab612b74) --- source3/smbd/process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index bf9e6457af..acda7128ae 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -87,7 +87,7 @@ static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len) if(msg->msg_buf == NULL) { DEBUG(0,("push_message: malloc fail (2)\n")); - free((char *)msg); + SAFE_FREE(msg); return False; } @@ -180,8 +180,8 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) memcpy(buffer, msg->msg_buf, MIN(buffer_len, msg->msg_len)); /* Free the message we just copied. */ - free((char *)msg->msg_buf); - free((char *)msg); + SAFE_FREE(msg->msg_buf); + SAFE_FREE(msg); DEBUG(5,("receive_message_or_smb: returning queued smb message.\n")); return True; -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/smbd/process.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index acda7128ae..4b0da0b466 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -21,8 +21,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - struct timeval smb_last_time; static char *InBuffer = NULL; -- cgit From 76745313b16c07092b0198da4d4fc05b38e600f7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 11 Oct 2001 05:53:15 +0000 Subject: Fixed bug when status=no and max smbd processes > 0. Jeremy. (This used to be commit d1adaee373f08020d350af2aa65b7651da94bdae) --- source3/smbd/process.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 4b0da0b466..4b7e80811c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -804,6 +804,12 @@ static BOOL smbd_process_limit(void) total_smbds = 1; /* In case we need to create the entry. */ + if (!conn_tdb_ctx()) { + DEBUG(0,("smbd_process_limit: max smbd processes parameter set with status parameter not \ +set. Ignoring max smbd restriction.\n")); + return False; + } + if (tdb_change_int_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, 1) == -1) return True; -- cgit From d731149a41d7563ab99acd3d3d20fff899e7de8f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 17 Oct 2001 01:38:23 +0000 Subject: Fixed inconsistent definitions of InBuf/OutBuf/last_char. Noticed by albert chin (china@thewrittenword.com) . Jeremy. (This used to be commit f5781f11eb924bdf32d20819c58a782493f4b239) --- source3/smbd/process.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 4b7e80811c..ea97eea8a4 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -42,9 +42,6 @@ int max_recv = BUFFER_SIZE; extern int last_message; extern int global_oplock_break; extern userdom_struct current_user_info; -extern char *last_inbuf; -extern char *InBuffer; -extern char *OutBuffer; extern int smb_read_error; extern VOLATILE sig_atomic_t reload_after_sighup; extern BOOL global_machine_password_needs_changing; -- cgit From b728042334f67738fd1a6fdd03e619bdb78fe06a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 17 Oct 2001 08:54:19 +0000 Subject: added basic NTLMSSP support in smbd. This is still quite rough, and loses things like username mapping. I wanted to get this in then discuss it a bit to see how we want to split up the existing session setup code (This used to be commit b74fda69bf23207c26d8b2af23910d8f2eb89875) --- source3/smbd/process.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ea97eea8a4..cf691ce9f3 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -911,25 +911,24 @@ char *smb_fn_name(int type) void construct_reply_common(char *inbuf,char *outbuf) { - memset(outbuf,'\0',smb_size); - - set_message(outbuf,0,0,True); - CVAL(outbuf,smb_com) = CVAL(inbuf,smb_com); - - memcpy(outbuf+4,inbuf+4,4); - CVAL(outbuf,smb_rcls) = SMB_SUCCESS; - CVAL(outbuf,smb_reh) = 0; - SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); /* bit 7 set - means a reply */ - SSVAL(outbuf,smb_flg2, - (SVAL(inbuf,smb_flg2)&FLAGS2_UNICODE_STRINGS) | FLAGS2_LONG_PATH_COMPONENTS); - /* say we support long filenames */ - - SSVAL(outbuf,smb_err,SMB_SUCCESS); - SSVAL(outbuf,smb_tid,SVAL(inbuf,smb_tid)); - SSVAL(outbuf,smb_pid,SVAL(inbuf,smb_pid)); - SSVAL(outbuf,smb_uid,SVAL(inbuf,smb_uid)); - SSVAL(outbuf,smb_mid,SVAL(inbuf,smb_mid)); + memset(outbuf,'\0',smb_size); + + set_message(outbuf,0,0,True); + CVAL(outbuf,smb_com) = CVAL(inbuf,smb_com); + + memcpy(outbuf+4,inbuf+4,4); + CVAL(outbuf,smb_rcls) = SMB_SUCCESS; + CVAL(outbuf,smb_reh) = 0; + SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); + SSVAL(outbuf,smb_flg2, + FLAGS2_UNICODE_STRINGS | FLAGS2_LONG_PATH_COMPONENTS | + FLAGS2_32_BIT_ERROR_CODES | FLAGS2_EXTENDED_SECURITY); + + SSVAL(outbuf,smb_err,SMB_SUCCESS); + SSVAL(outbuf,smb_tid,SVAL(inbuf,smb_tid)); + SSVAL(outbuf,smb_pid,SVAL(inbuf,smb_pid)); + SSVAL(outbuf,smb_uid,SVAL(inbuf,smb_uid)); + SSVAL(outbuf,smb_mid,SVAL(inbuf,smb_mid)); } /**************************************************************************** -- cgit From c416ff851b4ecc7a44aee9d00d07dd481d8ae2a7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2001 20:15:12 +0000 Subject: Merge the become_XXX -> change_to_XXX fixes from 2.2.2 to HEAD. Ensure make_conection() can only be called as root. Jeremy. (This used to be commit 8d23a7441b4687458ee021bfe8880558506eddba) --- source3/smbd/process.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index cf691ce9f3..edcb6b345f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -120,7 +120,7 @@ static void async_processing(fd_set *fds, char *buffer, int buffer_len) /* check for sighup processing */ if (reload_after_sighup) { - unbecome_user(); + change_to_root_user(); DEBUG(1,("Reloading services after SIGHUP\n")); reload_services(False); reload_after_sighup = False; @@ -702,7 +702,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* does this protocol need to be run as root? */ if (!(flags & AS_USER)) - unbecome_user(); + change_to_root_user(); /* does this protocol need a valid tree connection? */ if ((flags & AS_USER) && !conn) { @@ -711,7 +711,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* does this protocol need to be run as the connected user? */ - if ((flags & AS_USER) && !become_user(conn,session_tag)) { + if ((flags & AS_USER) && !change_to_user(conn,session_tag)) { if (flags & AS_GUEST) flags &= ~AS_USER; else @@ -734,13 +734,13 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize } /* load service specific parameters */ - if (conn && !become_service(conn,(flags & AS_USER)?True:False)) { + if (conn && !set_current_service(conn,(flags & AS_USER)?True:False)) { return(ERROR_DOS(ERRSRV,ERRaccess)); } /* does this protocol need to be run as guest? */ if ((flags & AS_GUEST) && - (!become_guest() || + (!change_to_guest() || !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) { return(ERROR_DOS(ERRSRV,ERRaccess)); } @@ -1096,7 +1096,7 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t last_idle_closed_check = t; /* become root again if waiting */ - unbecome_user(); + change_to_root_user(); /* check if we need to reload services */ check_reload(t); -- cgit From 6cc3953196e3feb340f7b9b7bb823575414c5683 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Oct 2001 00:56:03 +0000 Subject: Restored old Bmpx code - actually used by OS/2. Jeremy. (This used to be commit 7c1688fd67c1bda1477aaf870371c825280db870) --- source3/smbd/process.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index edcb6b345f..a0bfdbb2a2 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -361,11 +361,11 @@ struct smb_message_struct /* 0x19 */ { NULL, NULL, 0 }, /* 0x1a */ { "SMBreadbraw",reply_readbraw,AS_USER}, /* 0x1b */ { "SMBreadBmpx",reply_readbmpx,AS_USER}, -/* 0x1c */ { "SMBreadBs",NULL,AS_USER}, +/* 0x1c */ { "SMBreadBs",NULL,0 }, /* 0x1d */ { "SMBwritebraw",reply_writebraw,AS_USER}, -/* 0x1e */ { NULL,NULL,0}, -/* 0x1f */ { NULL,NULL,0}, -/* 0x20 */ { NULL,NULL,0}, +/* 0x1e */ { "SMBwriteBmpx",reply_writebmpx,AS_USER}, +/* 0x1f */ { "SMBwriteBs",reply_writebs,AS_USER}, +/* 0x20 */ { "SMBwritec",NULL,0}, /* 0x21 */ { NULL, NULL, 0 }, /* 0x22 */ { "SMBsetattrE",reply_setattrE,AS_USER | NEED_WRITE }, /* 0x23 */ { "SMBgetattrE",reply_getattrE,AS_USER }, -- cgit From 7cd889f566ebe352721943e53a055db5b817f12f Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sat, 20 Oct 2001 23:34:40 +0000 Subject: Converted a bunch of 0x85 constants to SMBkeepalive. (This used to be commit b16a15a13ed7d267c6366abaeeb3ccafa5776f5e) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index a0bfdbb2a2..cf01cd2cf5 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -254,7 +254,7 @@ BOOL receive_next_smb(char *inbuf, int bufsize, int timeout) do { ret = receive_message_or_smb(inbuf,bufsize,timeout); - got_keepalive = (ret && (CVAL(inbuf,0) == 0x85)); + got_keepalive = (ret && (CVAL(inbuf,0) == SMBkeepalive)); } while (ret && got_keepalive); return ret; @@ -867,7 +867,7 @@ void process_smb(char *inbuf, char *outbuf) if (msg_type == 0) show_msg(inbuf); - else if(msg_type == 0x85) + else if(msg_type == SMBkeepalive) return; /* Keepalive packet. */ nread = construct_reply(inbuf,outbuf,nread,max_send); -- cgit From d876260d885ad991526544756609ea38e4867028 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 5 Nov 2001 00:02:38 +0000 Subject: Don't put a \n on the end of the arg to exit_server() (This used to be commit dfb8566220c3e90ca2b757ea124f53aed103269e) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index cf01cd2cf5..b020cdd5d7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -884,7 +884,7 @@ void process_smb(char *inbuf, char *outbuf) } else if (!send_smb(smbd_server_fd(),outbuf)) - exit_server("process_smb: send_smb failed.\n"); + exit_server("process_smb: send_smb failed."); } trans_num++; } -- cgit From d0a2faf78d316fec200497f5f7997df4c477a1e1 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 24 Nov 2001 12:12:38 +0000 Subject: This is another rather major change to the samba authenticaion subystem. The particular aim is to modularized the interface - so that we can have arbitrary password back-ends. This code adds one such back-end, a 'winbind' module to authenticate against the winbind_auth_crap functionality. While fully-functional this code is mainly useful as a demonstration, because we don't get back the info3 as we would for direct ntdomain authentication. This commit introduced the new 'auth methods' parameter, in the spirit of the 'auth order' discussed on the lists. It is renamed because not all the methods may be consulted, even if previous methods fail - they may not have a suitable challenge for example. Also, we have a 'local' authentication method, for old-style 'unix if plaintext, sam if encrypted' authentication and a 'guest' module to handle guest logins in a single place. While this current design is not ideal, I feel that it does provide a better infrastructure than the current design, and can be built upon. The following parameters have changed: - use rhosts = This has been replaced by the 'rhosts' authentication method, and can be specified like 'auth methods = guest rhosts' - hosts equiv = This needs both this parameter and an 'auth methods' entry to be effective. (auth methods = guest hostsequiv ....) - plaintext to smbpasswd = This is replaced by specifying 'sam' rather than 'local' in the auth methods. The security = parameter is unchanged, and now provides defaults for the 'auth methods' parameter. The available auth methods are: guest rhosts hostsequiv sam (passdb direct hash access) unix (PAM, crypt() etc) local (the combination of the above, based on encryption) smbserver (old security=server) ntdomain (old security=domain) winbind (use winbind to cache DC connections) Assistance in testing, or the production of new and interesting authentication modules is always appreciated. Andrew Bartlett (This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99) --- source3/smbd/process.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index b020cdd5d7..d9322ae26c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1112,19 +1112,23 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t if (keepalive && (t - last_keepalive_sent_time)>keepalive) { - struct cli_state *cli = server_client(); - if (!send_keepalive(smbd_server_fd())) { - DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); - return False; - } - /* also send a keepalive to the password server if its still - connected */ - if (cli && cli->initialised) - if (!send_keepalive(cli->fd)) { - DEBUG( 2, ( "password server keepalive failed.\n")); - cli_shutdown(cli); - } - last_keepalive_sent_time = t; + extern auth_authsupplied_info *negprot_global_auth_info; + if (!send_keepalive(smbd_server_fd())) { + DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); + return False; + } + + /* send a keepalive for a password server or the like. + This is attached to the auth_info created in the + negprot */ + if (negprot_global_auth_info + && negprot_global_auth_info->challange_set_method + && negprot_global_auth_info->challange_set_method->send_keepalive) { + negprot_global_auth_info->challange_set_method->send_keepalive + (&negprot_global_auth_info->challange_set_method->private_data); + } + + last_keepalive_sent_time = t; } /* check for connection timeouts */ -- cgit From 178f6a64b26d828db6b516392d7072e9c29f6233 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 26 Nov 2001 04:05:28 +0000 Subject: challange -> challenge (This used to be commit d6318add27f6bca5be00cbedf2226b642341297a) --- source3/smbd/process.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d9322ae26c..d4881b0ba5 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1122,10 +1122,10 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t This is attached to the auth_info created in the negprot */ if (negprot_global_auth_info - && negprot_global_auth_info->challange_set_method - && negprot_global_auth_info->challange_set_method->send_keepalive) { - negprot_global_auth_info->challange_set_method->send_keepalive - (&negprot_global_auth_info->challange_set_method->private_data); + && negprot_global_auth_info->challenge_set_method + && negprot_global_auth_info->challenge_set_method->send_keepalive) { + negprot_global_auth_info->challenge_set_method->send_keepalive + (&negprot_global_auth_info->challenge_set_method->private_data); } last_keepalive_sent_time = t; -- cgit From 1fb4d2f1b0d65e9f48081ae7a225950d4341d923 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 Nov 2001 01:51:10 +0000 Subject: don't try to auto-change the trust password unless we are in domain security (This used to be commit 00e4f0c803c6376387c31efd01cf3437c589da9d) --- source3/smbd/process.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d4881b0ba5..bbccc67f97 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1139,7 +1139,10 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t return False; } - if(global_machine_password_needs_changing) + if(global_machine_password_needs_changing && + /* for ADS we need to do a regular ADS password change, not a domain + password change */ + lp_security() == SEC_DOMAIN) { unsigned char trust_passwd_hash[16]; time_t lct; -- cgit From 216f3ae90881fb1d7301920b9c30f551f24244f3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Dec 2001 03:21:38 +0000 Subject: cleanup a little namespace pollution (This used to be commit e5b484451a37a9ac940b342d70791b09362070ee) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index bbccc67f97..111da3bcef 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -325,7 +325,7 @@ force write permissions on print services. functions. Any message that has a NULL function is unimplemented - please feel free to contribute implementations! */ -struct smb_message_struct +static struct smb_message_struct { char *name; int (*fn)(connection_struct *conn, char *, char *, int, int); -- cgit From af643d5f1f9eb7e5aa10a9cfef3bd6dce38ace1d Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Thu, 3 Jan 2002 05:41:13 +0000 Subject: smbd children should also register for POOL_USAGE (This used to be commit b46d874f4736493bdc4244ec6cdf95e77347e7d5) --- source3/smbd/process.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 111da3bcef..d8d644338d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1230,6 +1230,7 @@ void smbd_process(void) /* register our message handlers */ message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis); + register_msg_pool_usage(); while (True) { int deadtime = lp_deadtime()*60; -- cgit From f55c47b1ff9b9b53a53de320a6f7ddc181292b27 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Thu, 3 Jan 2002 05:57:41 +0000 Subject: Fix talloc msg registration (This used to be commit 9a473ecf96fca35d146756c0c313b156aba8d9d9) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d8d644338d..af081d5059 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1230,7 +1230,7 @@ void smbd_process(void) /* register our message handlers */ message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis); - register_msg_pool_usage(); + talloc_init_named("dummy!"); while (True) { int deadtime = lp_deadtime()*60; -- cgit From 2e28f8ff0e3bb50ac5b2742c7678c39cb65bcd95 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 5 Jan 2002 04:55:41 +0000 Subject: I've decided to move the auth code around a bit more... The auth_authsupplied_info typedef is now just a plain struct - auth_context, but it has been modified to contain the function pointers to the rest of the auth subsystem's components. (Who needs non-static functions anyway?) In working all this mess out, I fixed a number of memory leaks and moved the entire auth subsystem over to talloc(). Note that the TALLOC_CTX attached to the auth_context can be rather long-lived, it is provided for things that are intended to live as long. (The global_negprot_auth_context lasts the whole life of the smbd). I've also adjusted a few things in auth_domain.c, mainly passing the domain as a paramater to a few functions instead of looking up lp_workgroup(). I'm hopign to make this entire thing a bit more trusted domains (as PDC) freindly in the near future. Other than that, I moved a bit of the code around, hence the rather messy diff. Andrew Bartlett (This used to be commit 12f5515f556cf39fea98134fe3e2ac4540501048) --- source3/smbd/process.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index af081d5059..2b31a24ced 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1112,7 +1112,7 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t if (keepalive && (t - last_keepalive_sent_time)>keepalive) { - extern auth_authsupplied_info *negprot_global_auth_info; + extern struct auth_context *negprot_global_auth_context; if (!send_keepalive(smbd_server_fd())) { DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); return False; @@ -1121,11 +1121,11 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t /* send a keepalive for a password server or the like. This is attached to the auth_info created in the negprot */ - if (negprot_global_auth_info - && negprot_global_auth_info->challenge_set_method - && negprot_global_auth_info->challenge_set_method->send_keepalive) { - negprot_global_auth_info->challenge_set_method->send_keepalive - (&negprot_global_auth_info->challenge_set_method->private_data); + if (negprot_global_auth_context + && negprot_global_auth_context->challenge_set_method + && negprot_global_auth_context->challenge_set_method->send_keepalive) { + negprot_global_auth_context->challenge_set_method->send_keepalive + (&negprot_global_auth_context->challenge_set_method->private_data); } last_keepalive_sent_time = t; -- cgit From d2687a00e1fe374128a7ad5707f1f7e62d8512d9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 9 Jan 2002 02:35:08 +0000 Subject: Fixed up atomic update code. Jeremy. (This used to be commit 274b04d4a6123fbfe363afc214e908ab36c7e8a7) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2b31a24ced..ff53acbd9e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -791,7 +791,7 @@ static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) ****************************************************************************/ static BOOL smbd_process_limit(void) { - int total_smbds; + int32 total_smbds; if (lp_max_smbd_processes()) { @@ -807,7 +807,7 @@ set. Ignoring max smbd restriction.\n")); return False; } - if (tdb_change_int_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, 1) == -1) + if (tdb_change_int32_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, 1) == -1) return True; return total_smbds > lp_max_smbd_processes(); -- cgit From d6823366b881612234ab0655adb11c594f864c4a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 11 Jan 2002 19:10:25 +0000 Subject: Same fix as went into 2.2 (I'm waiting for jerry to finish some code). Jeremy. (This used to be commit 01ff6ce4963e1daff019f2b936cef218e1c93f67) --- source3/smbd/process.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ff53acbd9e..b1fcf864e1 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -914,11 +914,11 @@ void construct_reply_common(char *inbuf,char *outbuf) memset(outbuf,'\0',smb_size); set_message(outbuf,0,0,True); - CVAL(outbuf,smb_com) = CVAL(inbuf,smb_com); + SCVAL(outbuf,smb_com,CVAL(inbuf,smb_com)); memcpy(outbuf+4,inbuf+4,4); - CVAL(outbuf,smb_rcls) = SMB_SUCCESS; - CVAL(outbuf,smb_reh) = 0; + SCVAL(outbuf,smb_rcls,SMB_SUCCESS); + SCVAL(outbuf,smb_reh,0); SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); SSVAL(outbuf,smb_flg2, FLAGS2_UNICODE_STRINGS | FLAGS2_LONG_PATH_COMPONENTS | @@ -949,7 +949,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) /* maybe its not chained */ if (smb_com2 == 0xFF) { - CVAL(outbuf,smb_vwv0) = 0xFF; + SCVAL(outbuf,smb_vwv0,0xFF); return outsize; } @@ -969,7 +969,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) /* we need to tell the client where the next part of the reply will be */ SSVAL(outbuf,smb_vwv1,smb_offset(outbuf+outsize,outbuf)); - CVAL(outbuf,smb_vwv0) = smb_com2; + SCVAL(outbuf,smb_vwv0,smb_com2); /* remember how much the caller added to the chain, only counting stuff after the parameter words */ @@ -991,7 +991,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) memmove(inbuf2,inbuf,smb_wct); /* create the in buffer */ - CVAL(inbuf2,smb_com) = smb_com2; + SCVAL(inbuf2,smb_com,smb_com2); /* create the out buffer */ construct_reply_common(inbuf2, outbuf2); @@ -1006,7 +1006,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) /* copy the new reply and request headers over the old ones, but preserve the smb_com field */ memmove(orig_outbuf,outbuf2,smb_wct); - CVAL(orig_outbuf,smb_com) = smb_com1; + SCVAL(orig_outbuf,smb_com,smb_com1); /* restore the saved data, being careful not to overwrite any data from the reply header */ -- cgit From e400bfce39dac2f4ff75184d52965aba6b9848de Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 19 Jan 2002 21:29:20 +0000 Subject: Report write fail in smb_dump. Jeremy. (This used to be commit 832b9e7838afc0a48932dd0622c7e2f7b7e44a8f) --- source3/smbd/process.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index b1fcf864e1..48c0053360 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -609,7 +609,9 @@ static void smb_dump(char *name, int type, char *data, ssize_t len) if (fd != -1 || errno != EEXIST) break; } if (fd != -1) { - write(fd, data, len); + ssize_t ret = write(fd, data, len); + if (ret != len) + DEBUG(0,("smb_dump: problem: write returned %d\n", (int)ret )); close(fd); DEBUG(0,("created %s len %d\n", fname, len)); } -- cgit From 723b368dc20b6075055cc0e7177990c1b6391041 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 23 Jan 2002 18:09:56 +0000 Subject: Check request flag for unicode capability and respond accordingly, rather than only doing unicode. smbfs didn't work. (This used to be commit 95857a3515d67effb1242ca07daa5643458bb2f0) --- source3/smbd/process.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 48c0053360..5eb626db2b 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -923,7 +923,8 @@ void construct_reply_common(char *inbuf,char *outbuf) SCVAL(outbuf,smb_reh,0); SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); SSVAL(outbuf,smb_flg2, - FLAGS2_UNICODE_STRINGS | FLAGS2_LONG_PATH_COMPONENTS | + (SVAL(inbuf,smb_flg2) & FLAGS2_UNICODE_STRINGS) | + FLAGS2_LONG_PATH_COMPONENTS | FLAGS2_32_BIT_ERROR_CODES | FLAGS2_EXTENDED_SECURITY); SSVAL(outbuf,smb_err,SMB_SUCCESS); -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/smbd/process.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 5eb626db2b..e7a9d0b644 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. process incoming packets - main loop Copyright (C) Andrew Tridgell 1992-1998 -- cgit From 69adbb0ce3bb9d5bd569c13aaa3ac8f390c1586a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 31 Jan 2002 23:26:12 +0000 Subject: Fix from Michael Steffens to make signal processing work correctly in winbindd. This is a really good patch that gives full select semantics to the Samba modified select. Jeremy. (This used to be commit 3af16ade173cac24c1ac5eff4a36b439f16ac036) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index e7a9d0b644..bf1a1ca9a7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -193,7 +193,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) to.tv_sec = timeout / 1000; to.tv_usec = (timeout % 1000) * 1000; - selrtn = sys_select(MAX(maxfd,smbd_server_fd())+1,&fds,timeout>0?&to:NULL); + selrtn = sys_select(MAX(maxfd,smbd_server_fd())+1,&fds,NULL,NULL,timeout>0?&to:NULL); /* if we get EINTR then maybe we have received an oplock signal - treat this as select returning 1. This is ugly, but -- cgit From d79e11ad6d4be78a4140d0f33acea702cbd1d944 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 1 Mar 2002 01:24:30 +0000 Subject: Various comment fixes from Rafal Szczesniak (This used to be commit 3bf4b42771d115500941be374bfdd9b8c2fdba4a) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index bf1a1ca9a7..8c037b4706 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -818,7 +818,7 @@ set. Ignoring max smbd restriction.\n")); } /**************************************************************************** - process an smb from the client - split out from the process() code so + process an smb from the client - split out from the smbd_process() code so it can be used by the oplock break code. ****************************************************************************/ void process_smb(char *inbuf, char *outbuf) -- cgit From 840279f3424eb92d1c4b55e1f9a1aca938b087ca Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 14 Mar 2002 02:15:08 +0000 Subject: Now we have reliable signals take SIGTERM inband. Jeremy. (This used to be commit cad82926a8baf7605cef81f0e0d4daa8e527e6ee) --- source3/smbd/process.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 8c037b4706..007621f6bb 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -43,6 +43,7 @@ extern int global_oplock_break; extern userdom_struct current_user_info; extern int smb_read_error; extern VOLATILE sig_atomic_t reload_after_sighup; +extern VOLATILE sig_atomic_t got_sig_term; extern BOOL global_machine_password_needs_changing; extern fstring global_myworkgroup; extern pstring global_myname; @@ -104,9 +105,10 @@ BOOL push_oplock_pending_smb_message(char *buf, int msg_len) } /**************************************************************************** -do all async processing in here. This includes UDB oplock messages, kernel -oplock messages, change notify events etc. + Do all async processing in here. This includes UDB oplock messages, kernel + oplock messages, change notify events etc. ****************************************************************************/ + static void async_processing(fd_set *fds, char *buffer, int buffer_len) { /* check for oplock messages (both UDP and kernel) */ @@ -114,6 +116,10 @@ static void async_processing(fd_set *fds, char *buffer, int buffer_len) process_local_message(buffer, buffer_len); } + if (got_sig_term) { + exit_server("Caught TERM signal"); + } + /* check for async change notify events */ process_pending_change_notify_queue(0); @@ -122,7 +128,7 @@ static void async_processing(fd_set *fds, char *buffer, int buffer_len) change_to_root_user(); DEBUG(1,("Reloading services after SIGHUP\n")); reload_services(False); - reload_after_sighup = False; + reload_after_sighup = 0; } } -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/smbd/process.c | 65 +++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 35 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 007621f6bb..43d3c6c531 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -42,8 +42,8 @@ extern int last_message; extern int global_oplock_break; extern userdom_struct current_user_info; extern int smb_read_error; -extern VOLATILE sig_atomic_t reload_after_sighup; -extern VOLATILE sig_atomic_t got_sig_term; +SIG_ATOMIC_T reload_after_sighup; +SIG_ATOMIC_T got_sig_term; extern BOOL global_machine_password_needs_changing; extern fstring global_myworkgroup; extern pstring global_myname; @@ -109,10 +109,12 @@ BOOL push_oplock_pending_smb_message(char *buf, int msg_len) oplock messages, change notify events etc. ****************************************************************************/ -static void async_processing(fd_set *fds, char *buffer, int buffer_len) +static void async_processing(char *buffer, int buffer_len) { + DEBUG(10,("async_processing: Doing async processing.\n")); + /* check for oplock messages (both UDP and kernel) */ - if (receive_local_message(fds, buffer, buffer_len, 0)) { + if (receive_local_message(buffer, buffer_len, 1)) { process_local_message(buffer, buffer_len); } @@ -193,6 +195,27 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) */ FD_ZERO(&fds); + + /* + * Ensure we process oplock break messages by preference. + * We have to do this before the select, after the select + * and if the select returns EINTR. This is due to the fact + * that the selects called from async_processing can eat an EINTR + * caused by a signal (we can't take the break message there). + * This is hideously complex - *MUST* be simplified for 3.0 ! JRA. + */ + + if (oplock_message_waiting(&fds)) { + DEBUG(10,("receive_message_or_smb: oplock_message is waiting.\n")); + async_processing(buffer, buffer_len); + /* + * After async processing we must go and do the select again, as + * the state of the flag in fds for the server file descriptor is + * indeterminate - we may have done I/O on it in the oplock processing. JRA. + */ + goto again; + } + FD_SET(smbd_server_fd(),&fds); maxfd = setup_oplock_select_set(&fds); @@ -206,7 +229,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) is the best we can do until the oplock code knows more about signals */ if (selrtn == -1 && errno == EINTR) { - async_processing(&fds, buffer, buffer_len); + async_processing(buffer, buffer_len); /* * After async processing we must go and do the select again, as * the state of the flag in fds for the server file descriptor is @@ -235,7 +258,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) */ if (oplock_message_waiting(&fds)) { - async_processing(&fds, buffer, buffer_len); + async_processing(buffer, buffer_len); /* * After async processing we must go and do the select again, as * the state of the flag in fds for the server file descriptor is @@ -275,7 +298,6 @@ BOOL receive_next_smb(char *inbuf, int bufsize, int timeout) void respond_to_all_remaining_local_messages(void) { char buffer[1024]; - fd_set fds; /* * Assert we have no exclusive open oplocks. @@ -287,24 +309,13 @@ void respond_to_all_remaining_local_messages(void) return; } - /* - * Setup the select read fd set. - */ - - FD_ZERO(&fds); - if(!setup_oplock_select_set(&fds)) - return; - /* * Keep doing receive_local_message with a 1 ms timeout until * we have no more messages. */ - while(receive_local_message(&fds, buffer, sizeof(buffer), 1)) { + while(receive_local_message(buffer, sizeof(buffer), 1)) { /* Deal with oplock break requests from other smbd's. */ process_local_message(buffer, sizeof(buffer)); - - FD_ZERO(&fds); - (void)setup_oplock_select_set(&fds); } return; @@ -829,10 +840,6 @@ set. Ignoring max smbd restriction.\n")); ****************************************************************************/ void process_smb(char *inbuf, char *outbuf) { -#ifdef WITH_SSL - extern BOOL sslEnabled; /* don't use function for performance reasons */ - static int sslConnected = 0; -#endif /* WITH_SSL */ static int trans_num; int msg_type = CVAL(inbuf,0); int32 len = smb_len(inbuf); @@ -860,18 +867,6 @@ void process_smb(char *inbuf, char *outbuf) DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type, len ) ); DEBUG( 3, ( "Transaction %d of length %d\n", trans_num, nread ) ); -#ifdef WITH_SSL - if(sslEnabled && !sslConnected){ - sslConnected = sslutil_negotiate_ssl(smbd_server_fd(), msg_type); - if(sslConnected < 0){ /* an error occured */ - exit_server("SSL negotiation failed"); - }else if(sslConnected){ - trans_num++; - return; - } - } -#endif /* WITH_SSL */ - if (msg_type == 0) show_msg(inbuf); else if(msg_type == SMBkeepalive) -- cgit From 127e77e6e334fdc33086bffcbe00d340c0ba0097 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 17 Aug 2002 15:27:10 +0000 Subject: Sync 3.0 branch with head (This used to be commit 42615b945e2e48e53a21ea47f2e45407913a6a1e) --- source3/smbd/process.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 43d3c6c531..55234ec896 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -152,7 +152,7 @@ static void async_processing(char *buffer, int buffer_len) Returns False on timeout or error. Else returns True. -The timeout is in milli seconds +The timeout is in milliseconds ****************************************************************************/ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) @@ -341,9 +341,9 @@ force write permissions on print services. functions. Any message that has a NULL function is unimplemented - please feel free to contribute implementations! */ -static struct smb_message_struct +const static struct smb_message_struct { - char *name; + const char *name; int (*fn)(connection_struct *conn, char *, char *, int, int); int flags; } @@ -386,7 +386,7 @@ static struct smb_message_struct /* 0x22 */ { "SMBsetattrE",reply_setattrE,AS_USER | NEED_WRITE }, /* 0x23 */ { "SMBgetattrE",reply_getattrE,AS_USER }, /* 0x24 */ { "SMBlockingX",reply_lockingX,AS_USER }, -/* 0x25 */ { "SMBtrans",reply_trans,AS_USER | CAN_IPC | QUEUE_IN_OPLOCK}, +/* 0x25 */ { "SMBtrans",reply_trans,AS_USER | CAN_IPC }, /* 0x26 */ { "SMBtranss",NULL,AS_USER | CAN_IPC}, /* 0x27 */ { "SMBioctl",reply_ioctl,0}, /* 0x28 */ { "SMBioctls",NULL,AS_USER}, @@ -399,7 +399,7 @@ static struct smb_message_struct /* 0x2f */ { "SMBwriteX",reply_write_and_X,AS_USER | CAN_IPC }, /* 0x30 */ { NULL, NULL, 0 }, /* 0x31 */ { NULL, NULL, 0 }, -/* 0x32 */ { "SMBtrans2", reply_trans2, AS_USER | QUEUE_IN_OPLOCK | CAN_IPC }, +/* 0x32 */ { "SMBtrans2", reply_trans2, AS_USER | CAN_IPC }, /* 0x33 */ { "SMBtranss2", reply_transs2, AS_USER}, /* 0x34 */ { "SMBfindclose", reply_findclose,AS_USER}, /* 0x35 */ { "SMBfindnclose", reply_findnclose, AS_USER}, @@ -611,7 +611,7 @@ static struct smb_message_struct /******************************************************************* dump a prs to a file ********************************************************************/ -static void smb_dump(char *name, int type, char *data, ssize_t len) +static void smb_dump(const char *name, int type, char *data, ssize_t len) { int fd, i; pstring fname; @@ -896,7 +896,7 @@ void process_smb(char *inbuf, char *outbuf) /**************************************************************************** return a string containing the function name of a SMB command ****************************************************************************/ -char *smb_fn_name(int type) +const char *smb_fn_name(int type) { static char *unknown_name = "SMBunknown"; @@ -1228,13 +1228,6 @@ void smbd_process(void) max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); - /* re-initialise the timezone */ - TimeInit(); - - /* register our message handlers */ - message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis); - talloc_init_named("dummy!"); - while (True) { int deadtime = lp_deadtime()*60; int select_timeout = setup_select_timeout(); -- cgit From a834a73e341059be154426390304a42e4a011f72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:19:00 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 65e7b5273bb58802bf0c389b77f7fcae0a1f6139) --- source3/smbd/process.c | 288 +++++++++++++++++++++++++------------------------ 1 file changed, 147 insertions(+), 141 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 55234ec896..0f7cfd0e9c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -42,8 +42,8 @@ extern int last_message; extern int global_oplock_break; extern userdom_struct current_user_info; extern int smb_read_error; -SIG_ATOMIC_T reload_after_sighup; -SIG_ATOMIC_T got_sig_term; +SIG_ATOMIC_T reload_after_sighup = 0; +SIG_ATOMIC_T got_sig_term = 0; extern BOOL global_machine_password_needs_changing; extern fstring global_myworkgroup; extern pstring global_myname; @@ -609,8 +609,9 @@ const static struct smb_message_struct }; /******************************************************************* -dump a prs to a file - ********************************************************************/ + Dump a packet to a file. +********************************************************************/ + static void smb_dump(const char *name, int type, char *data, ssize_t len) { int fd, i; @@ -635,178 +636,171 @@ static void smb_dump(const char *name, int type, char *data, ssize_t len) /**************************************************************************** -do a switch on the message type, and return the response size + Do a switch on the message type, and return the response size ****************************************************************************/ + static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize) { - static pid_t pid= (pid_t)-1; - int outsize = 0; - extern uint16 global_smbpid; - - type &= 0xff; + static pid_t pid= (pid_t)-1; + int outsize = 0; + extern uint16 global_smbpid; - if (pid == (pid_t)-1) - pid = sys_getpid(); + type &= 0xff; - errno = 0; - last_message = type; - - /* make sure this is an SMB packet */ - if (strncmp(smb_base(inbuf),"\377SMB",4) != 0) - { - DEBUG(2,("Non-SMB packet of length %d\n",smb_len(inbuf))); - return(-1); - } + if (pid == (pid_t)-1) + pid = sys_getpid(); - /* yuck! this is an interim measure before we get rid of our - current inbuf/outbuf system */ - global_smbpid = SVAL(inbuf,smb_pid); + errno = 0; + last_message = type; - if (smb_messages[type].fn == NULL) - { - DEBUG(0,("Unknown message type %d!\n",type)); - smb_dump("Unknown", 1, inbuf, size); - outsize = reply_unknown(inbuf,outbuf); - } - else - { - int flags = smb_messages[type].flags; - static uint16 last_session_tag = UID_FIELD_INVALID; - /* In share mode security we must ignore the vuid. */ - uint16 session_tag = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid); - connection_struct *conn = conn_find(SVAL(inbuf,smb_tid)); + /* Make sure this is an SMB packet. smb_size contains NetBIOS header so subtract 4 from it. */ + if ((strncmp(smb_base(inbuf),"\377SMB",4) != 0) || (size < (smb_size - 4))) { + DEBUG(2,("Non-SMB packet of length %d. Terminating server\n",smb_len(inbuf))); + exit_server("Non-SMB packet"); + return(-1); + } - DEBUG(3,("switch message %s (pid %d)\n",smb_fn_name(type),(int)pid)); + /* yuck! this is an interim measure before we get rid of our + current inbuf/outbuf system */ + global_smbpid = SVAL(inbuf,smb_pid); + + if (smb_messages[type].fn == NULL) { + DEBUG(0,("Unknown message type %d!\n",type)); + smb_dump("Unknown", 1, inbuf, size); + outsize = reply_unknown(inbuf,outbuf); + } else { + int flags = smb_messages[type].flags; + static uint16 last_session_tag = UID_FIELD_INVALID; + /* In share mode security we must ignore the vuid. */ + uint16 session_tag = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid); + connection_struct *conn = conn_find(SVAL(inbuf,smb_tid)); + + DEBUG(3,("switch message %s (pid %d)\n",smb_fn_name(type),(int)pid)); + + smb_dump(smb_fn_name(type), 1, inbuf, size); + if(global_oplock_break) { + if(flags & QUEUE_IN_OPLOCK) { + /* + * Queue this message as we are the process of an oplock break. + */ + + DEBUG( 2, ( "switch_message: queueing message due to being in " ) ); + DEBUGADD( 2, ( "oplock break state.\n" ) ); + + push_oplock_pending_smb_message( inbuf, size ); + return -1; + } + } - smb_dump(smb_fn_name(type), 1, inbuf, size); - if(global_oplock_break) - { - if(flags & QUEUE_IN_OPLOCK) - { - /* - * Queue this message as we are the process of an oplock break. - */ - - DEBUG( 2, ( "switch_message: queueing message due to being in " ) ); - DEBUGADD( 2, ( "oplock break state.\n" ) ); - - push_oplock_pending_smb_message( inbuf, size ); - return -1; - } - } + /* Ensure this value is replaced in the incoming packet. */ + SSVAL(inbuf,smb_uid,session_tag); - /* Ensure this value is replaced in the incoming packet. */ - SSVAL(inbuf,smb_uid,session_tag); + /* + * Ensure the correct username is in current_user_info. + * This is a really ugly bugfix for problems with + * multiple session_setup_and_X's being done and + * allowing %U and %G substitutions to work correctly. + * There is a reason this code is done here, don't + * move it unless you know what you're doing... :-). + * JRA. + */ - /* - * Ensure the correct username is in current_user_info. - * This is a really ugly bugfix for problems with - * multiple session_setup_and_X's being done and - * allowing %U and %G substitutions to work correctly. - * There is a reason this code is done here, don't - * move it unless you know what you're doing... :-). - * JRA. - */ + if (session_tag != last_session_tag) { + user_struct *vuser = NULL; - if (session_tag != last_session_tag) { - user_struct *vuser = NULL; + last_session_tag = session_tag; + if(session_tag != UID_FIELD_INVALID) + vuser = get_valid_user_struct(session_tag); + if(vuser != NULL) + current_user_info = vuser->user; + } - last_session_tag = session_tag; - if(session_tag != UID_FIELD_INVALID) - vuser = get_valid_user_struct(session_tag); - if(vuser != NULL) - current_user_info = vuser->user; - } + /* does this protocol need to be run as root? */ + if (!(flags & AS_USER)) + change_to_root_user(); - /* does this protocol need to be run as root? */ - if (!(flags & AS_USER)) - change_to_root_user(); + /* does this protocol need a valid tree connection? */ + if ((flags & AS_USER) && !conn) + return ERROR_DOS(ERRSRV, ERRinvnid); - /* does this protocol need a valid tree connection? */ - if ((flags & AS_USER) && !conn) { - return ERROR_DOS(ERRSRV, ERRinvnid); - } + /* does this protocol need to be run as the connected user? */ + if ((flags & AS_USER) && !change_to_user(conn,session_tag)) { + if (flags & AS_GUEST) + flags &= ~AS_USER; + else + return(ERROR_DOS(ERRSRV,ERRaccess)); + } - /* does this protocol need to be run as the connected user? */ - if ((flags & AS_USER) && !change_to_user(conn,session_tag)) { - if (flags & AS_GUEST) - flags &= ~AS_USER; - else - return(ERROR_DOS(ERRSRV,ERRaccess)); - } - - /* this code is to work around a bug is MS client 3 without - introducing a security hole - it needs to be able to do - print queue checks as guest if it isn't logged in properly */ - if (flags & AS_USER) - flags &= ~AS_GUEST; + /* this code is to work around a bug is MS client 3 without + introducing a security hole - it needs to be able to do + print queue checks as guest if it isn't logged in properly */ + if (flags & AS_USER) + flags &= ~AS_GUEST; - /* does it need write permission? */ - if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) - return(ERROR_DOS(ERRSRV,ERRaccess)); + /* does it need write permission? */ + if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) + return(ERROR_DOS(ERRSRV,ERRaccess)); - /* ipc services are limited */ - if (IS_IPC(conn) && (flags & AS_USER) && !(flags & CAN_IPC)) { - return(ERROR_DOS(ERRSRV,ERRaccess)); - } + /* ipc services are limited */ + if (IS_IPC(conn) && (flags & AS_USER) && !(flags & CAN_IPC)) + return(ERROR_DOS(ERRSRV,ERRaccess)); - /* load service specific parameters */ - if (conn && !set_current_service(conn,(flags & AS_USER)?True:False)) { - return(ERROR_DOS(ERRSRV,ERRaccess)); - } + /* load service specific parameters */ + if (conn && !set_current_service(conn,(flags & AS_USER)?True:False)) + return(ERROR_DOS(ERRSRV,ERRaccess)); - /* does this protocol need to be run as guest? */ - if ((flags & AS_GUEST) && - (!change_to_guest() || - !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) { - return(ERROR_DOS(ERRSRV,ERRaccess)); - } + /* does this protocol need to be run as guest? */ + if ((flags & AS_GUEST) && (!change_to_guest() || + !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) + return(ERROR_DOS(ERRSRV,ERRaccess)); - last_inbuf = inbuf; + last_inbuf = inbuf; - outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); - } + outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); + } - smb_dump(smb_fn_name(type), 0, outbuf, outsize); + smb_dump(smb_fn_name(type), 0, outbuf, outsize); - return(outsize); + return(outsize); } /**************************************************************************** - construct a reply to the incoming packet + Construct a reply to the incoming packet. ****************************************************************************/ + static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) { - int type = CVAL(inbuf,smb_com); - int outsize = 0; - int msg_type = CVAL(inbuf,0); + int type = CVAL(inbuf,smb_com); + int outsize = 0; + int msg_type = CVAL(inbuf,0); - GetTimeOfDay(&smb_last_time); + GetTimeOfDay(&smb_last_time); - chain_size = 0; - file_chain_reset(); - reset_chain_p(); + chain_size = 0; + file_chain_reset(); + reset_chain_p(); - if (msg_type != 0) - return(reply_special(inbuf,outbuf)); + if (msg_type != 0) + return(reply_special(inbuf,outbuf)); - construct_reply_common(inbuf, outbuf); + construct_reply_common(inbuf, outbuf); - outsize = switch_message(type,inbuf,outbuf,size,bufsize); + outsize = switch_message(type,inbuf,outbuf,size,bufsize); - outsize += chain_size; + outsize += chain_size; - if(outsize > 4) - smb_setlen(outbuf,outsize - 4); - return(outsize); + if(outsize > 4) + smb_setlen(outbuf,outsize - 4); + return(outsize); } /**************************************************************************** - Keep track of the number of running smbd's. This functionality is used to - 'hard' limit Samba overhead on resource constrained systems. + Keep track of the number of running smbd's. This functionality is used to + 'hard' limit Samba overhead on resource constrained systems. ****************************************************************************/ + static BOOL smbd_process_limit(void) { int32 total_smbds; @@ -1032,16 +1026,15 @@ static int setup_select_timeout(void) int select_timeout; int t; - /* - * Increase the select timeout back to SMBD_SELECT_TIMEOUT if we - * have removed any blocking locks. JRA. - */ - - select_timeout = blocking_locks_pending() ? SMBD_SELECT_TIMEOUT_WITH_PENDING_LOCKS*1000 : - SMBD_SELECT_TIMEOUT*1000; + select_timeout = blocking_locks_timeout(SMBD_SELECT_TIMEOUT); + select_timeout *= 1000; t = change_notify_timeout(); - if (t != -1) select_timeout = MIN(select_timeout, t*1000); + if (t != -1) + select_timeout = MIN(select_timeout, t*1000); + + if (print_notify_messages_pending()) + select_timeout = MIN(select_timeout, 1000); return select_timeout; } @@ -1161,9 +1154,16 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t * First, open the machine password file with an exclusive lock. */ + if (secrets_lock_trust_account_password(global_myworkgroup, True) == False) { + DEBUG(0,("process: unable to lock the machine account password for \ +machine %s in domain %s.\n", global_myname, global_myworkgroup )); + return True; + } + if(!secrets_fetch_trust_account_password(global_myworkgroup, trust_passwd_hash, &lct)) { DEBUG(0,("process: unable to read the machine account password for \ machine %s in domain %s.\n", global_myname, global_myworkgroup )); + secrets_lock_trust_account_password(global_myworkgroup, False); return True; } @@ -1173,6 +1173,7 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); if(t < lct + lp_machine_password_timeout()) { global_machine_password_needs_changing = False; + secrets_lock_trust_account_password(global_myworkgroup, False); return True; } @@ -1180,6 +1181,7 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); change_trust_account_password( global_myworkgroup, remote_machine_list); global_machine_password_needs_changing = False; + secrets_lock_trust_account_password(global_myworkgroup, False); } /* @@ -1201,6 +1203,10 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); force_check_log_size(); check_log_size(); + /* Send any queued printer notify message to interested smbd's. */ + + print_notify_send_messages(); + /* * Modify the select timeout depending upon * what we have remaining in our queues. -- cgit From 2f194322d419350f35a48dff750066894d68eccf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Nov 2002 23:20:50 +0000 Subject: Removed global_myworkgroup, global_myname, global_myscope. Added liberal dashes of const. This is a rather large check-in, some things may break. It does compile though :-). Jeremy. (This used to be commit f755711df8f74f9b8e8c1a2b0d07d02a931eeb89) --- source3/smbd/process.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 0f7cfd0e9c..c46c4c5509 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -45,8 +45,6 @@ extern int smb_read_error; SIG_ATOMIC_T reload_after_sighup = 0; SIG_ATOMIC_T got_sig_term = 0; extern BOOL global_machine_password_needs_changing; -extern fstring global_myworkgroup; -extern pstring global_myname; extern int max_send; /**************************************************************************** @@ -1154,16 +1152,16 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t * First, open the machine password file with an exclusive lock. */ - if (secrets_lock_trust_account_password(global_myworkgroup, True) == False) { + if (secrets_lock_trust_account_password(lp_workgroup(), True) == False) { DEBUG(0,("process: unable to lock the machine account password for \ -machine %s in domain %s.\n", global_myname, global_myworkgroup )); +machine %s in domain %s.\n", global_myname(), lp_workgroup() )); return True; } - if(!secrets_fetch_trust_account_password(global_myworkgroup, trust_passwd_hash, &lct)) { + if(!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd_hash, &lct)) { DEBUG(0,("process: unable to read the machine account password for \ -machine %s in domain %s.\n", global_myname, global_myworkgroup )); - secrets_lock_trust_account_password(global_myworkgroup, False); +machine %s in domain %s.\n", global_myname(), lp_workgroup() )); + secrets_lock_trust_account_password(lp_workgroup(), False); return True; } @@ -1173,15 +1171,15 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup )); if(t < lct + lp_machine_password_timeout()) { global_machine_password_needs_changing = False; - secrets_lock_trust_account_password(global_myworkgroup, False); + secrets_lock_trust_account_password(lp_workgroup(), False); return True; } pstrcpy(remote_machine_list, lp_passwordserver()); - change_trust_account_password( global_myworkgroup, remote_machine_list); + change_trust_account_password( lp_workgroup(), remote_machine_list); global_machine_password_needs_changing = False; - secrets_lock_trust_account_password(global_myworkgroup, False); + secrets_lock_trust_account_password(lp_workgroup(), False); } /* -- cgit From 612e1ffdba747c969525be760f8783c946960812 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 4 Dec 2002 20:57:48 +0000 Subject: merges from HEAD - change_trust_account_password() must always talk to PDC (This used to be commit af2fa4385015dce8dedafe80e02a0115892e508e) --- source3/smbd/process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c46c4c5509..3b0619b7d0 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1175,9 +1175,9 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup() )); return True; } - pstrcpy(remote_machine_list, lp_passwordserver()); - - change_trust_account_password( lp_workgroup(), remote_machine_list); + /* always just contact the PDC here */ + + change_trust_account_password( lp_workgroup(), NULL); global_machine_password_needs_changing = False; secrets_lock_trust_account_password(lp_workgroup(), False); } -- cgit From 39c78bf516f4db59fd3c218f67d13dd658daf558 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Dec 2002 23:54:40 +0000 Subject: Fixed auth module code. Added VALGRIND defines to reduce spurious warnings. Jeremy. (This used to be commit ec4ed45563f9d8e25fcfd88840944a90b3139c3e) --- source3/smbd/process.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 3b0619b7d0..923b20ad66 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1140,7 +1140,6 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t { unsigned char trust_passwd_hash[16]; time_t lct; - pstring remote_machine_list; /* * We're in domain level security, and the code that -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 923b20ad66..7421c16b40 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -339,7 +339,7 @@ force write permissions on print services. functions. Any message that has a NULL function is unimplemented - please feel free to contribute implementations! */ -const static struct smb_message_struct +static const struct smb_message_struct { const char *name; int (*fn)(connection_struct *conn, char *, char *, int, int); @@ -890,7 +890,7 @@ return a string containing the function name of a SMB command ****************************************************************************/ const char *smb_fn_name(int type) { - static char *unknown_name = "SMBunknown"; + const char *unknown_name = "SMBunknown"; if (smb_messages[type].name == NULL) return(unknown_name); -- cgit From 38aee23f807dad93fb832d97deac57d528a2a175 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 8 Jan 2003 21:42:53 +0000 Subject: Ensure we don't get an invalid number for total smbd's if the tdb update fails. Jeremy. (This used to be commit e0482594724ebba801bbc39a90a73fafa54f8b9e) --- source3/smbd/process.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 7421c16b40..03b1e007ba 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -809,17 +809,13 @@ static BOOL smbd_process_limit(void) * subtracts one. */ - total_smbds = 1; /* In case we need to create the entry. */ - if (!conn_tdb_ctx()) { DEBUG(0,("smbd_process_limit: max smbd processes parameter set with status parameter not \ set. Ignoring max smbd restriction.\n")); return False; } - if (tdb_change_int32_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, 1) == -1) - return True; - + total_smbds = increment_smbd_process_count(); return total_smbds > lp_max_smbd_processes(); } else -- cgit From 195ec103d6c0f8470141014dbfe365996fa0f4a7 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Thu, 9 Jan 2003 06:26:04 +0000 Subject: Moved smbd process counting functions from smbd/server.c to smbd/process.c so that bin/vfstest can link. merge from head (This used to be commit 9151cd7d64a1ee1277cbcfb3e7ed61c32c1037cf) --- source3/smbd/process.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 03b1e007ba..06cedea573 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -799,6 +799,32 @@ static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) 'hard' limit Samba overhead on resource constrained systems. ****************************************************************************/ +static BOOL process_count_update_successful = False; + +static int32 increment_smbd_process_count(void) +{ + int32 total_smbds; + + if (lp_max_smbd_processes()) { + total_smbds = 0; + if (tdb_change_int32_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, -1) == -1) + return 1; + process_count_update_successful = True; + return total_smbds + 1; + } + return 1; +} + +void decrement_smbd_process_count(void) +{ + int32 total_smbds; + + if (lp_max_smbd_processes() && process_count_update_successful) { + total_smbds = 1; + tdb_change_int32_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, -1); + } +} + static BOOL smbd_process_limit(void) { int32 total_smbds; -- cgit From 071af8f007efc20c23959d140a87cc09363aae83 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 11 Jan 2003 02:38:36 +0000 Subject: [merge] make sure to update print queue cache during timeout_processing() to send notify events; CR 1491 (This used to be commit f8a915b14d63e4fdb99235053eeb896ef9492068) --- source3/smbd/process.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 06cedea573..ff84dc8e1a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1209,6 +1209,10 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup() )); */ process_blocking_lock_queue(t); + /* update printer queue caches if necessary */ + + update_monitored_printq_cache(); + /* * Check to see if we have any change notifies * outstanding on the queue. -- cgit From dd072d240b9bca25e6e7394353cacf778847f86e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 24 Jan 2003 19:05:32 +0000 Subject: Fixed typo found by tpot. Jeremy. (This used to be commit 7e2bc1fe58f5da437e55867d1205ca6ceade4c74) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ff84dc8e1a..8018d5f6f6 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -807,7 +807,7 @@ static int32 increment_smbd_process_count(void) if (lp_max_smbd_processes()) { total_smbds = 0; - if (tdb_change_int32_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, -1) == -1) + if (tdb_change_int32_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, 1) == -1) return 1; process_count_update_successful = True; return total_smbds + 1; -- cgit From 142837e5d3bd9d3d853fc1c2eb181fea87a38d3a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 30 Jan 2003 04:38:39 +0000 Subject: Merge of controversial 'max log size' fix. (This used to be commit 71e2b60d8f784174cd2a75c5e03bf2a6ab353900) --- source3/smbd/process.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 8018d5f6f6..98ec6ce184 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1314,5 +1314,17 @@ void smbd_process(void) last_timeout_processing_time = new_check_time; /* Reset time. */ } } + + /* The timeout_processing function isn't run nearly + often enough to implement 'max log size' without + overrunning the size of the file by many megabytes. + This is especially true if we are running at debug + level 10. Checking every 50 SMBs is a nice + tradeoff of performance vs log file size overrun. */ + + if ((num_smbs % 50) == 0 && need_to_check_log_size()) { + change_to_root_user(); + check_log_size(); + } } } -- cgit From bbf9f09ee5c58e348eef33448d2c38e588adb66a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 30 Jan 2003 23:55:58 +0000 Subject: Add 3 second timeout when terminating server and sending print notify messages. Stops build-up of large numbers of smbd's waiting to terminate on large print throughput. Jeremy. (This used to be commit 07efebb98473cb3d4adc6b2e0afef3f06dcc99b8) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 98ec6ce184..c002abad16 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1228,7 +1228,7 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup() )); /* Send any queued printer notify message to interested smbd's. */ - print_notify_send_messages(); + print_notify_send_messages(0); /* * Modify the select timeout depending upon -- cgit From fb3e4b87973e9ad0c818e8d9dd60329c47f22afe Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 Feb 2003 01:04:34 +0000 Subject: Fix to allow blocking lock notification to be done rapidly (no wait for smb -> smb lock release). Adds new PENDING_LOCK type to lockdb (does not interfere with existing locks). Jeremy. (This used to be commit 766928bbba1e597c9c2b12458dd8d37e6080593e) --- source3/smbd/process.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c002abad16..57bc236eef 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1271,6 +1271,13 @@ void smbd_process(void) lp_talloc_free(); main_loop_talloc_free(); + /* Did someone ask for immediate checks on things like blocking locks ? */ + if (select_timeout == 0) { + if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) + return; + num_smbs = 0; /* Reset smb counter. */ + } + while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) return; -- cgit From 1f499a79f5468e87d26b60ffe3aa375b91cadbef Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Mar 2003 13:47:42 +0000 Subject: (merge from HEAD) Small clenaup patches: - safe_string.h - don't assume that __FUNCTION__ is available - process.c - use new workaround from safe_string.h for the same - util.c - Show how many bytes we smb_panic()ed trying to smb_xmalloc() - gencache.c - Keep valgrind quiet by always null terminating. - clistr.c - Add copyright - srvstr.h - move srvstr_push into a .c file again, as a real function. - srvstr.c - revive, with 'safe' checked srvstr_push - loadparm.c - set a default for the display charset. - connection.c - use safe_strcpy() Andrew Bartlett (This used to be commit c91e76bddbe1244ddc8d12b092eba875834029ac) --- source3/smbd/process.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 57bc236eef..16ef30c46c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1249,12 +1249,16 @@ void smbd_process(void) extern int smb_echo_count; time_t last_timeout_processing_time = time(NULL); unsigned int num_smbs = 0; + const size_t total_buffer_size = BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN; - InBuffer = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); - OutBuffer = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); + InBuffer = (char *)malloc(total_buffer_size); + OutBuffer = (char *)malloc(total_buffer_size); if ((InBuffer == NULL) || (OutBuffer == NULL)) return; + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size); + max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); while (True) { @@ -1278,6 +1282,8 @@ void smbd_process(void) num_smbs = 0; /* Reset smb counter. */ } + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); + while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) return; @@ -1295,6 +1301,8 @@ void smbd_process(void) */ num_echos = smb_echo_count; + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size); + process_smb(InBuffer, OutBuffer); if (smb_echo_count != num_echos) { -- cgit From a8c95d79f83b4097ee20d5f3f1005c38ccf00186 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Apr 2003 12:13:07 +0000 Subject: Add support for the new modules system to auth/ (merge from HEAD) (This used to be commit c7a1de090db35835be1a1623bfc80c04065c5dd9) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 16ef30c46c..de1bea493f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -44,7 +44,7 @@ extern userdom_struct current_user_info; extern int smb_read_error; SIG_ATOMIC_T reload_after_sighup = 0; SIG_ATOMIC_T got_sig_term = 0; -extern BOOL global_machine_password_needs_changing; +BOOL global_machine_password_needs_changing = False; extern int max_send; /**************************************************************************** -- cgit From f071020f5e49837154581c97c5af5f84d0e2de89 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 21 Apr 2003 14:09:03 +0000 Subject: Merge from HEAD - save the type of channel used to contact the DC. This allows us to join as a BDC, without appearing on the network as one until we have the database replicated, and the admin changes the configuration. This also change the SID retreval order from secrets.tdb, so we no longer require a 'net rpc getsid' - the sid fetch during the domain join is sufficient. Also minor fixes to 'net'. Andrew Bartlett (This used to be commit 876e00fd112e4aaf7519eec27f382eb99ec7562a) --- source3/smbd/process.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index de1bea493f..54fd4a90d9 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1179,9 +1179,11 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup() )); return True; } - if(!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd_hash, &lct)) { + if(!secrets_fetch_trust_account_password(lp_workgroup(), + trust_passwd_hash, + &lct, NULL)) { DEBUG(0,("process: unable to read the machine account password for \ -machine %s in domain %s.\n", global_myname(), lp_workgroup() )); +machine %s in domain %s.\n", global_myname(), lp_workgroup())); secrets_lock_trust_account_password(lp_workgroup(), False); return True; } -- cgit From 06551c644c75ab2aa14a3cc3c4afbcbb08369133 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 6 May 2003 02:34:59 +0000 Subject: Patch from metze to add exit and interval events. Useful for modules (This used to be commit 3033a63cefb5f28d4460885f7f4e4ecaed95443c) --- source3/smbd/process.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 54fd4a90d9..18acb35f7a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1114,6 +1114,9 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t /* become root again if waiting */ change_to_root_user(); + /* run all registered idle events */ + smb_run_idle_events(t); + /* check if we need to reload services */ check_reload(t); @@ -1277,6 +1280,10 @@ void smbd_process(void) lp_talloc_free(); main_loop_talloc_free(); + /* run all registered idle events */ + smb_run_idle_events(time(NULL)); + + /* Did someone ask for immediate checks on things like blocking locks ? */ if (select_timeout == 0) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) -- cgit From 1eff0523002319b2606466d3624e3a4612dbab6d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 16 Jul 2003 18:06:27 +0000 Subject: Reformatting fixes to bring in line with the rest of the source. Jeremy. (This used to be commit 3c11d9362379f16bb0d14449f64e731efad97ffe) --- source3/smbd/process.c | 663 ++++++++++++++++++++++++------------------------- 1 file changed, 325 insertions(+), 338 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 18acb35f7a..b025503da4 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -53,9 +53,9 @@ extern int max_send; ****************************************************************************/ typedef struct { - ubi_slNode msg_next; - char *msg_buf; - int msg_len; + ubi_slNode msg_next; + char *msg_buf; + int msg_len; } pending_message_list; static ubi_slList smb_oplock_queue = { NULL, (ubi_slNodePtr)&smb_oplock_queue, 0}; @@ -67,29 +67,27 @@ static ubi_slList smb_oplock_queue = { NULL, (ubi_slNodePtr)&smb_oplock_queue, 0 static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len) { - pending_message_list *msg = (pending_message_list *) + pending_message_list *msg = (pending_message_list *) malloc(sizeof(pending_message_list)); - if(msg == NULL) - { - DEBUG(0,("push_message: malloc fail (1)\n")); - return False; - } + if(msg == NULL) { + DEBUG(0,("push_message: malloc fail (1)\n")); + return False; + } - msg->msg_buf = (char *)malloc(msg_len); - if(msg->msg_buf == NULL) - { - DEBUG(0,("push_message: malloc fail (2)\n")); - SAFE_FREE(msg); - return False; - } + msg->msg_buf = (char *)malloc(msg_len); + if(msg->msg_buf == NULL) { + DEBUG(0,("push_message: malloc fail (2)\n")); + SAFE_FREE(msg); + return False; + } - memcpy(msg->msg_buf, buf, msg_len); - msg->msg_len = msg_len; + memcpy(msg->msg_buf, buf, msg_len); + msg->msg_len = msg_len; - ubi_slAddTail( list_head, msg); + ubi_slAddTail( list_head, msg); - return True; + return True; } /**************************************************************************** @@ -295,28 +293,29 @@ BOOL receive_next_smb(char *inbuf, int bufsize, int timeout) void respond_to_all_remaining_local_messages(void) { - char buffer[1024]; - - /* - * Assert we have no exclusive open oplocks. - */ - - if(get_number_of_exclusive_open_oplocks()) { - DEBUG(0,("respond_to_all_remaining_local_messages: PANIC : we have %d exclusive oplocks.\n", - get_number_of_exclusive_open_oplocks() )); - return; - } - - /* - * Keep doing receive_local_message with a 1 ms timeout until - * we have no more messages. - */ - while(receive_local_message(buffer, sizeof(buffer), 1)) { - /* Deal with oplock break requests from other smbd's. */ - process_local_message(buffer, sizeof(buffer)); - } - - return; + char buffer[1024]; + + /* + * Assert we have no exclusive open oplocks. + */ + + if(get_number_of_exclusive_open_oplocks()) { + DEBUG(0,("respond_to_all_remaining_local_messages: PANIC : we have %d exclusive oplocks.\n", + get_number_of_exclusive_open_oplocks() )); + return; + } + + /* + * Keep doing receive_local_message with a 1 ms timeout until + * we have no more messages. + */ + + while(receive_local_message(buffer, sizeof(buffer), 1)) { + /* Deal with oplock break requests from other smbd's. */ + process_local_message(buffer, sizeof(buffer)); + } + + return; } @@ -339,13 +338,11 @@ force write permissions on print services. functions. Any message that has a NULL function is unimplemented - please feel free to contribute implementations! */ -static const struct smb_message_struct -{ - const char *name; - int (*fn)(connection_struct *conn, char *, char *, int, int); - int flags; -} - smb_messages[256] = { +static const struct smb_message_struct { + const char *name; + int (*fn)(connection_struct *conn, char *, char *, int, int); + int flags; +} smb_messages[256] = { /* 0x00 */ { "SMBmkdir",reply_mkdir,AS_USER | NEED_WRITE}, /* 0x01 */ { "SMBrmdir",reply_rmdir,AS_USER | NEED_WRITE}, @@ -849,67 +846,62 @@ set. Ignoring max smbd restriction.\n")); } /**************************************************************************** - process an smb from the client - split out from the smbd_process() code so - it can be used by the oplock break code. + Process an smb from the client - split out from the smbd_process() code so + it can be used by the oplock break code. ****************************************************************************/ + void process_smb(char *inbuf, char *outbuf) { - static int trans_num; - int msg_type = CVAL(inbuf,0); - int32 len = smb_len(inbuf); - int nread = len + 4; - - DO_PROFILE_INC(smb_count); - - if (trans_num == 0) { - /* on the first packet, check the global hosts allow/ hosts - deny parameters before doing any parsing of the packet - passed to us by the client. This prevents attacks on our - parsing code from hosts not in the hosts allow list */ - if (smbd_process_limit() || - !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1))) { - /* send a negative session response "not listening on calling - name" */ - static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; - DEBUG( 1, ( "Connection denied from %s\n", - client_addr() ) ); - (void)send_smb(smbd_server_fd(),(char *)buf); - exit_server("connection denied"); - } - } - - DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type, len ) ); - DEBUG( 3, ( "Transaction %d of length %d\n", trans_num, nread ) ); - - if (msg_type == 0) - show_msg(inbuf); - else if(msg_type == SMBkeepalive) - return; /* Keepalive packet. */ - - nread = construct_reply(inbuf,outbuf,nread,max_send); + static int trans_num; + int msg_type = CVAL(inbuf,0); + int32 len = smb_len(inbuf); + int nread = len + 4; + + DO_PROFILE_INC(smb_count); + + if (trans_num == 0) { + /* on the first packet, check the global hosts allow/ hosts + deny parameters before doing any parsing of the packet + passed to us by the client. This prevents attacks on our + parsing code from hosts not in the hosts allow list */ + if (smbd_process_limit() || + !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1))) { + /* send a negative session response "not listening on calling name" */ + static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; + DEBUG( 1, ( "Connection denied from %s\n", client_addr() ) ); + (void)send_smb(smbd_server_fd(),(char *)buf); + exit_server("connection denied"); + } + } + + DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type, len ) ); + DEBUG( 3, ( "Transaction %d of length %d\n", trans_num, nread ) ); + + if (msg_type == 0) + show_msg(inbuf); + else if(msg_type == SMBkeepalive) + return; /* Keepalive packet. */ + + nread = construct_reply(inbuf,outbuf,nread,max_send); - if(nread > 0) - { - if (CVAL(outbuf,0) == 0) - show_msg(outbuf); + if(nread > 0) { + if (CVAL(outbuf,0) == 0) + show_msg(outbuf); - if (nread != smb_len(outbuf) + 4) - { - DEBUG(0,("ERROR: Invalid message response size! %d %d\n", - nread, smb_len(outbuf))); - } - else - if (!send_smb(smbd_server_fd(),outbuf)) - exit_server("process_smb: send_smb failed."); - } - trans_num++; + if (nread != smb_len(outbuf) + 4) { + DEBUG(0,("ERROR: Invalid message response size! %d %d\n", + nread, smb_len(outbuf))); + } else if (!send_smb(smbd_server_fd(),outbuf)) { + exit_server("process_smb: send_smb failed."); + } + } + trans_num++; } - - /**************************************************************************** -return a string containing the function name of a SMB command + Return a string containing the function name of a SMB command. ****************************************************************************/ + const char *smb_fn_name(int type) { const char *unknown_name = "SMBunknown"; @@ -949,92 +941,94 @@ void construct_reply_common(char *inbuf,char *outbuf) } /**************************************************************************** - construct a chained reply and add it to the already made reply - **************************************************************************/ + Construct a chained reply and add it to the already made reply +****************************************************************************/ + int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) { - static char *orig_inbuf; - static char *orig_outbuf; - int smb_com1, smb_com2 = CVAL(inbuf,smb_vwv0); - unsigned smb_off2 = SVAL(inbuf,smb_vwv1); - char *inbuf2, *outbuf2; - int outsize2; - char inbuf_saved[smb_wct]; - char outbuf_saved[smb_wct]; - int wct = CVAL(outbuf,smb_wct); - int outsize = smb_size + 2*wct + SVAL(outbuf,smb_vwv0+2*wct); - - /* maybe its not chained */ - if (smb_com2 == 0xFF) { - SCVAL(outbuf,smb_vwv0,0xFF); - return outsize; - } - - if (chain_size == 0) { - /* this is the first part of the chain */ - orig_inbuf = inbuf; - orig_outbuf = outbuf; - } - - /* - * The original Win95 redirector dies on a reply to - * a lockingX and read chain unless the chain reply is - * 4 byte aligned. JRA. - */ - - outsize = (outsize + 3) & ~3; - - /* we need to tell the client where the next part of the reply will be */ - SSVAL(outbuf,smb_vwv1,smb_offset(outbuf+outsize,outbuf)); - SCVAL(outbuf,smb_vwv0,smb_com2); - - /* remember how much the caller added to the chain, only counting stuff - after the parameter words */ - chain_size += outsize - smb_wct; - - /* work out pointers into the original packets. The - headers on these need to be filled in */ - inbuf2 = orig_inbuf + smb_off2 + 4 - smb_wct; - outbuf2 = orig_outbuf + SVAL(outbuf,smb_vwv1) + 4 - smb_wct; - - /* remember the original command type */ - smb_com1 = CVAL(orig_inbuf,smb_com); - - /* save the data which will be overwritten by the new headers */ - memcpy(inbuf_saved,inbuf2,smb_wct); - memcpy(outbuf_saved,outbuf2,smb_wct); - - /* give the new packet the same header as the last part of the SMB */ - memmove(inbuf2,inbuf,smb_wct); - - /* create the in buffer */ - SCVAL(inbuf2,smb_com,smb_com2); - - /* create the out buffer */ - construct_reply_common(inbuf2, outbuf2); - - DEBUG(3,("Chained message\n")); - show_msg(inbuf2); - - /* process the request */ - outsize2 = switch_message(smb_com2,inbuf2,outbuf2,size-chain_size, - bufsize-chain_size); - - /* copy the new reply and request headers over the old ones, but - preserve the smb_com field */ - memmove(orig_outbuf,outbuf2,smb_wct); - SCVAL(orig_outbuf,smb_com,smb_com1); - - /* restore the saved data, being careful not to overwrite any - data from the reply header */ - memcpy(inbuf2,inbuf_saved,smb_wct); - { - int ofs = smb_wct - PTR_DIFF(outbuf2,orig_outbuf); - if (ofs < 0) ofs = 0; - memmove(outbuf2+ofs,outbuf_saved+ofs,smb_wct-ofs); - } - - return outsize2; + static char *orig_inbuf; + static char *orig_outbuf; + int smb_com1, smb_com2 = CVAL(inbuf,smb_vwv0); + unsigned smb_off2 = SVAL(inbuf,smb_vwv1); + char *inbuf2, *outbuf2; + int outsize2; + char inbuf_saved[smb_wct]; + char outbuf_saved[smb_wct]; + int wct = CVAL(outbuf,smb_wct); + int outsize = smb_size + 2*wct + SVAL(outbuf,smb_vwv0+2*wct); + + /* maybe its not chained */ + if (smb_com2 == 0xFF) { + SCVAL(outbuf,smb_vwv0,0xFF); + return outsize; + } + + if (chain_size == 0) { + /* this is the first part of the chain */ + orig_inbuf = inbuf; + orig_outbuf = outbuf; + } + + /* + * The original Win95 redirector dies on a reply to + * a lockingX and read chain unless the chain reply is + * 4 byte aligned. JRA. + */ + + outsize = (outsize + 3) & ~3; + + /* we need to tell the client where the next part of the reply will be */ + SSVAL(outbuf,smb_vwv1,smb_offset(outbuf+outsize,outbuf)); + SCVAL(outbuf,smb_vwv0,smb_com2); + + /* remember how much the caller added to the chain, only counting stuff + after the parameter words */ + chain_size += outsize - smb_wct; + + /* work out pointers into the original packets. The + headers on these need to be filled in */ + inbuf2 = orig_inbuf + smb_off2 + 4 - smb_wct; + outbuf2 = orig_outbuf + SVAL(outbuf,smb_vwv1) + 4 - smb_wct; + + /* remember the original command type */ + smb_com1 = CVAL(orig_inbuf,smb_com); + + /* save the data which will be overwritten by the new headers */ + memcpy(inbuf_saved,inbuf2,smb_wct); + memcpy(outbuf_saved,outbuf2,smb_wct); + + /* give the new packet the same header as the last part of the SMB */ + memmove(inbuf2,inbuf,smb_wct); + + /* create the in buffer */ + SCVAL(inbuf2,smb_com,smb_com2); + + /* create the out buffer */ + construct_reply_common(inbuf2, outbuf2); + + DEBUG(3,("Chained message\n")); + show_msg(inbuf2); + + /* process the request */ + outsize2 = switch_message(smb_com2,inbuf2,outbuf2,size-chain_size, + bufsize-chain_size); + + /* copy the new reply and request headers over the old ones, but + preserve the smb_com field */ + memmove(orig_outbuf,outbuf2,smb_wct); + SCVAL(orig_outbuf,smb_com,smb_com1); + + /* restore the saved data, being careful not to overwrite any + data from the reply header */ + memcpy(inbuf2,inbuf_saved,smb_wct); + + { + int ofs = smb_wct - PTR_DIFF(outbuf2,orig_outbuf); + if (ofs < 0) ofs = 0; + memmove(outbuf2+ofs,outbuf_saved+ofs,smb_wct-ofs); + } + + return outsize2; } /**************************************************************************** @@ -1065,17 +1059,16 @@ static int setup_select_timeout(void) void check_reload(int t) { - static time_t last_smb_conf_reload_time = 0; + static time_t last_smb_conf_reload_time = 0; - if(last_smb_conf_reload_time == 0) - last_smb_conf_reload_time = t; + if(last_smb_conf_reload_time == 0) + last_smb_conf_reload_time = t; - if (reload_after_sighup || (t >= last_smb_conf_reload_time+SMBD_RELOAD_CHECK)) - { - reload_services(True); - reload_after_sighup = False; - last_smb_conf_reload_time = t; - } + if (reload_after_sighup || (t >= last_smb_conf_reload_time+SMBD_RELOAD_CHECK)) { + reload_services(True); + reload_after_sighup = False; + last_smb_conf_reload_time = t; + } } /**************************************************************************** @@ -1084,165 +1077,159 @@ void check_reload(int t) static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_timeout_processing_time) { - static time_t last_keepalive_sent_time = 0; - static time_t last_idle_closed_check = 0; - time_t t; - BOOL allidle = True; - extern int keepalive; - - if (smb_read_error == READ_EOF) - { - DEBUG(3,("end of file from client\n")); - return False; - } - - if (smb_read_error == READ_ERROR) - { - DEBUG(3,("receive_smb error (%s) exiting\n", - strerror(errno))); - return False; - } - - *last_timeout_processing_time = t = time(NULL); - - if(last_keepalive_sent_time == 0) - last_keepalive_sent_time = t; - - if(last_idle_closed_check == 0) - last_idle_closed_check = t; - - /* become root again if waiting */ - change_to_root_user(); - - /* run all registered idle events */ - smb_run_idle_events(t); - - /* check if we need to reload services */ - check_reload(t); - - /* automatic timeout if all connections are closed */ - if (conn_num_open()==0 && (t - last_idle_closed_check) >= IDLE_CLOSED_TIMEOUT) - { - DEBUG( 2, ( "Closing idle connection\n" ) ); - return False; - } - else - last_idle_closed_check = t; - - if (keepalive && (t - last_keepalive_sent_time)>keepalive) - { - extern struct auth_context *negprot_global_auth_context; - if (!send_keepalive(smbd_server_fd())) { - DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); - return False; - } - - /* send a keepalive for a password server or the like. - This is attached to the auth_info created in the - negprot */ - if (negprot_global_auth_context - && negprot_global_auth_context->challenge_set_method - && negprot_global_auth_context->challenge_set_method->send_keepalive) { - negprot_global_auth_context->challenge_set_method->send_keepalive - (&negprot_global_auth_context->challenge_set_method->private_data); - } - - last_keepalive_sent_time = t; - } - - /* check for connection timeouts */ - allidle = conn_idle_all(t, deadtime); - - if (allidle && conn_num_open()>0) { - DEBUG(2,("Closing idle connection 2.\n")); - return False; - } - - if(global_machine_password_needs_changing && - /* for ADS we need to do a regular ADS password change, not a domain - password change */ - lp_security() == SEC_DOMAIN) - { - unsigned char trust_passwd_hash[16]; - time_t lct; - - /* - * We're in domain level security, and the code that - * read the machine password flagged that the machine - * password needs changing. - */ - - /* - * First, open the machine password file with an exclusive lock. - */ - - if (secrets_lock_trust_account_password(lp_workgroup(), True) == False) { - DEBUG(0,("process: unable to lock the machine account password for \ + static time_t last_keepalive_sent_time = 0; + static time_t last_idle_closed_check = 0; + time_t t; + BOOL allidle = True; + extern int keepalive; + + if (smb_read_error == READ_EOF) { + DEBUG(3,("end of file from client\n")); + return False; + } + + if (smb_read_error == READ_ERROR) { + DEBUG(3,("receive_smb error (%s) exiting\n", + strerror(errno))); + return False; + } + + *last_timeout_processing_time = t = time(NULL); + + if(last_keepalive_sent_time == 0) + last_keepalive_sent_time = t; + + if(last_idle_closed_check == 0) + last_idle_closed_check = t; + + /* become root again if waiting */ + change_to_root_user(); + + /* run all registered idle events */ + smb_run_idle_events(t); + + /* check if we need to reload services */ + check_reload(t); + + /* automatic timeout if all connections are closed */ + if (conn_num_open()==0 && (t - last_idle_closed_check) >= IDLE_CLOSED_TIMEOUT) { + DEBUG( 2, ( "Closing idle connection\n" ) ); + return False; + } else { + last_idle_closed_check = t; + } + + if (keepalive && (t - last_keepalive_sent_time)>keepalive) { + extern struct auth_context *negprot_global_auth_context; + if (!send_keepalive(smbd_server_fd())) { + DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); + return False; + } + + /* send a keepalive for a password server or the like. + This is attached to the auth_info created in the + negprot */ + if (negprot_global_auth_context && negprot_global_auth_context->challenge_set_method + && negprot_global_auth_context->challenge_set_method->send_keepalive) { + + negprot_global_auth_context->challenge_set_method->send_keepalive + (&negprot_global_auth_context->challenge_set_method->private_data); + } + + last_keepalive_sent_time = t; + } + + /* check for connection timeouts */ + allidle = conn_idle_all(t, deadtime); + + if (allidle && conn_num_open()>0) { + DEBUG(2,("Closing idle connection 2.\n")); + return False; + } + + if(global_machine_password_needs_changing && + /* for ADS we need to do a regular ADS password change, not a domain + password change */ + lp_security() == SEC_DOMAIN) { + + unsigned char trust_passwd_hash[16]; + time_t lct; + + /* + * We're in domain level security, and the code that + * read the machine password flagged that the machine + * password needs changing. + */ + + /* + * First, open the machine password file with an exclusive lock. + */ + + if (secrets_lock_trust_account_password(lp_workgroup(), True) == False) { + DEBUG(0,("process: unable to lock the machine account password for \ machine %s in domain %s.\n", global_myname(), lp_workgroup() )); - return True; - } + return True; + } - if(!secrets_fetch_trust_account_password(lp_workgroup(), - trust_passwd_hash, - &lct, NULL)) { - DEBUG(0,("process: unable to read the machine account password for \ + if(!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd_hash, &lct, NULL)) { + DEBUG(0,("process: unable to read the machine account password for \ machine %s in domain %s.\n", global_myname(), lp_workgroup())); - secrets_lock_trust_account_password(lp_workgroup(), False); - return True; - } + secrets_lock_trust_account_password(lp_workgroup(), False); + return True; + } - /* - * Make sure someone else hasn't already done this. - */ + /* + * Make sure someone else hasn't already done this. + */ - if(t < lct + lp_machine_password_timeout()) { - global_machine_password_needs_changing = False; - secrets_lock_trust_account_password(lp_workgroup(), False); - return True; - } + if(t < lct + lp_machine_password_timeout()) { + global_machine_password_needs_changing = False; + secrets_lock_trust_account_password(lp_workgroup(), False); + return True; + } - /* always just contact the PDC here */ + /* always just contact the PDC here */ - change_trust_account_password( lp_workgroup(), NULL); - global_machine_password_needs_changing = False; - secrets_lock_trust_account_password(lp_workgroup(), False); - } - - /* - * Check to see if we have any blocking locks - * outstanding on the queue. - */ - process_blocking_lock_queue(t); - - /* update printer queue caches if necessary */ + change_trust_account_password( lp_workgroup(), NULL); + global_machine_password_needs_changing = False; + secrets_lock_trust_account_password(lp_workgroup(), False); + } + + /* + * Check to see if we have any blocking locks + * outstanding on the queue. + */ + process_blocking_lock_queue(t); + + /* update printer queue caches if necessary */ - update_monitored_printq_cache(); + update_monitored_printq_cache(); - /* - * Check to see if we have any change notifies - * outstanding on the queue. - */ - process_pending_change_notify_queue(t); + /* + * Check to see if we have any change notifies + * outstanding on the queue. + */ + process_pending_change_notify_queue(t); - /* - * Now we are root, check if the log files need pruning. - * Force a log file check. - */ - force_check_log_size(); - check_log_size(); + /* + * Now we are root, check if the log files need pruning. + * Force a log file check. + */ + force_check_log_size(); + check_log_size(); - /* Send any queued printer notify message to interested smbd's. */ + /* Send any queued printer notify message to interested smbd's. */ - print_notify_send_messages(0); + print_notify_send_messages(0); - /* - * Modify the select timeout depending upon - * what we have remaining in our queues. - */ + /* + * Modify the select timeout depending upon + * what we have remaining in our queues. + */ - *select_timeout = setup_select_timeout(); + *select_timeout = setup_select_timeout(); - return True; + return True; } /**************************************************************************** -- cgit From 0c9433c03188a2d1b49318dd8535d10b7805ce42 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Jul 2003 06:56:56 +0000 Subject: Ensure everywhere we defer an incoming SMB request (blocking lock queue, in oplock break state, change notify queue) we also push the MID onto the deferred signing queue. Tomorrow I will test this with valgrind and oplock tests. Jeremy. (This used to be commit 33a377f3726c85379ba5b962dd7c8ead337b892f) --- source3/smbd/process.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index b025503da4..fb85f38119 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -87,6 +87,9 @@ static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len) ubi_slAddTail( list_head, msg); + /* Push the MID of this packet on the signing queue. */ + srv_defer_sign_response(SVAL(buf,smb_mid)); + return True; } -- cgit From ceb68ee051e97afb1cb08e6f458e23e8f475504e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Jul 2003 19:05:32 +0000 Subject: Fix packet signing with asynchronous oplock breaks. Removed bad error message due to w2k bug. I think this code is now working.... Need more testing of course but works on all the obvious cases I can think of. Jeremy. (This used to be commit a6e537f6611cc1357fffea0b69901fba7c9ad6ea) --- source3/smbd/process.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index fb85f38119..dce1c4bc03 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1087,16 +1087,21 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t extern int keepalive; if (smb_read_error == READ_EOF) { - DEBUG(3,("end of file from client\n")); + DEBUG(3,("timeout_processing: End of file from client (client has disconnected).\n")); return False; } if (smb_read_error == READ_ERROR) { - DEBUG(3,("receive_smb error (%s) exiting\n", + DEBUG(3,("timeout_processing: receive_smb error (%s) Exiting\n", strerror(errno))); return False; } + if (smb_read_error == READ_BAD_SIG) { + DEBUG(3,("timeout_processing: receive_smb error bad smb signature. Exiting\n")); + return False; + } + *last_timeout_processing_time = t = time(NULL); if(last_keepalive_sent_time == 0) -- cgit From 110abf10d208769bf6bcfc0604874cb1bed0406a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 7 Aug 2003 02:59:52 +0000 Subject: Turns out I had my packet sequences wrong for oplock break code. I was storing the mid of the oplock break - I should have been storing the mid from the open. There are thus 2 types of deferred packet sequence returns - ones that increment the sequence number (returns from oplock causing opens) and ones that don't (change notify returns etc). Running with signing forced on does lead to some interesting tests :-). Jeremy. (This used to be commit 85907f02cec566502d9e4adabbd414020a26064d) --- source3/smbd/process.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index dce1c4bc03..373c2f16ae 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -47,6 +47,15 @@ SIG_ATOMIC_T got_sig_term = 0; BOOL global_machine_password_needs_changing = False; extern int max_send; +/**************************************************************************** + Function to return the current request mid from Inbuffer. +****************************************************************************/ + +uint16 get_current_mid(void) +{ + return SVAL(InBuffer,smb_mid); +} + /**************************************************************************** structure to hold a linked list of queued messages. for processing. @@ -88,7 +97,7 @@ static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len) ubi_slAddTail( list_head, msg); /* Push the MID of this packet on the signing queue. */ - srv_defer_sign_response(SVAL(buf,smb_mid)); + srv_defer_sign_response(SVAL(buf,smb_mid), True); return True; } -- cgit From fcdebdae6fb69575bbe6e622b112d2e61f972898 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 28 Aug 2003 23:57:34 +0000 Subject: Fix bug found by tridge in 2.2.x. Ensure that %U substitution is restored on next valid packet if a logon fails. This has relevence if people are using su.exe within logon scripts ! Jeremy. (This used to be commit d405a93a9d3f9a1d93bb3289b00683fba3160bbe) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 373c2f16ae..457ba8cc63 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -719,7 +719,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize if(session_tag != UID_FIELD_INVALID) vuser = get_valid_user_struct(session_tag); if(vuser != NULL) - current_user_info = vuser->user; + set_current_user_info(&vuser->user); } /* does this protocol need to be run as root? */ -- cgit From 245fbf7efbc42530c81d5aac66681bb892c97557 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 4 Sep 2003 01:12:39 +0000 Subject: Used cachegrind to track down some bottlenecks. Removed calls to clobber_region when not compiling with developer as they were hiding speed problems. Added fast path to convert_string() when dealing with ascii -> ascii, ucs2-le to ascii and ascii to ucs2-le with values <= 0x7F. This gives a speedup of 22% on my nbench tests. Next I will do this on convert_string_allocate. Jeremy. (This used to be commit ef140d15ea0d76a3e7cdcadbfd3e917c210a9411) --- source3/smbd/process.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 457ba8cc63..3c15cd1833 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1265,8 +1265,10 @@ void smbd_process(void) if ((InBuffer == NULL) || (OutBuffer == NULL)) return; +#if defined(DEVELOPER) clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size); +#endif max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); @@ -1295,7 +1297,9 @@ void smbd_process(void) num_smbs = 0; /* Reset smb counter. */ } +#if defined(DEVELOPER) clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); +#endif while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) -- cgit From 3fe18a46a33cc1c0a0ecfefc61618356d7746a15 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 21 Oct 2003 17:40:58 +0000 Subject: Fix signing miss-sequence noticed by Stefan Metzmacher Jeremy. (This used to be commit 63f331564396e7a4f16dce95bb98d3b6c4b75351) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 3c15cd1833..43ffb82bd7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -97,7 +97,7 @@ static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len) ubi_slAddTail( list_head, msg); /* Push the MID of this packet on the signing queue. */ - srv_defer_sign_response(SVAL(buf,smb_mid), True); + srv_defer_sign_response(SVAL(buf,smb_mid)); return True; } -- cgit From fbb8f131c2336e921677f41e9fb8bce7406f3336 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 3 Nov 2003 14:34:25 +0000 Subject: Fix more 64-bit printf warnings. (This used to be commit 23443e3aa079710221557e18158d0ddb8ff48a36) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 43ffb82bd7..ee81404a6f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -637,7 +637,7 @@ static void smb_dump(const char *name, int type, char *data, ssize_t len) if (ret != len) DEBUG(0,("smb_dump: problem: write returned %d\n", (int)ret )); close(fd); - DEBUG(0,("created %s len %d\n", fname, len)); + DEBUG(0,("created %s len %ul\n", fname, (unsigned long)len)); } } -- cgit From 9c8d23e5d5da06e661fa1548eea7a1e44f5f6d3a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 5 Nov 2003 00:16:01 +0000 Subject: Fix debug message warning. Jeremy. (This used to be commit 154793981a1b2aea2703ef4da4764a322bf90ca0) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ee81404a6f..8a90a15d29 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -637,7 +637,7 @@ static void smb_dump(const char *name, int type, char *data, ssize_t len) if (ret != len) DEBUG(0,("smb_dump: problem: write returned %d\n", (int)ret )); close(fd); - DEBUG(0,("created %s len %ul\n", fname, (unsigned long)len)); + DEBUG(0,("created %s len %lu\n", fname, (unsigned long)len)); } } -- cgit From 6bb8f54e018db066d93f960ec0f257a77671b593 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 1 Dec 2003 02:25:56 +0000 Subject: Don't automatically set nt status code flag unless client tells us it can cope. Jeremy. (This used to be commit 0d82ac57a59276adb403f8e023578c2d6d5136e4) --- source3/smbd/process.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 8a90a15d29..d93826bc7e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -924,11 +924,17 @@ const char *smb_fn_name(int type) return(smb_messages[type].name); } - /**************************************************************************** - Helper function for contruct_reply. + Helper functions for contruct_reply. ****************************************************************************/ +static uint32 common_flags2 = FLAGS2_LONG_PATH_COMPONENTS|FLAGS2_EXTENDED_SECURITY; + +void add_to_common_flags2(uint32 v) +{ + common_flags2 |= v; +} + void construct_reply_common(char *inbuf,char *outbuf) { memset(outbuf,'\0',smb_size); @@ -941,9 +947,8 @@ void construct_reply_common(char *inbuf,char *outbuf) SCVAL(outbuf,smb_reh,0); SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); SSVAL(outbuf,smb_flg2, - (SVAL(inbuf,smb_flg2) & FLAGS2_UNICODE_STRINGS) | - FLAGS2_LONG_PATH_COMPONENTS | - FLAGS2_32_BIT_ERROR_CODES | FLAGS2_EXTENDED_SECURITY); + (SVAL(inbuf,smb_flg2) & FLAGS2_UNICODE_STRINGS) | + common_flags2); SSVAL(outbuf,smb_err,SMB_SUCCESS); SSVAL(outbuf,smb_tid,SVAL(inbuf,smb_tid)); -- cgit From 27891bdef10069e70e240bbea53f75359cec78eb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 1 Dec 2003 06:19:17 +0000 Subject: Subtract NT_STATUS from common flag, don't add it... Jeremy. (This used to be commit 4e73faa7b4af7f73bdce9fcc2ee1825249dc7da7) --- source3/smbd/process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d93826bc7e..5206dc70f8 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -928,11 +928,11 @@ const char *smb_fn_name(int type) Helper functions for contruct_reply. ****************************************************************************/ -static uint32 common_flags2 = FLAGS2_LONG_PATH_COMPONENTS|FLAGS2_EXTENDED_SECURITY; +static uint32 common_flags2 = FLAGS2_LONG_PATH_COMPONENTS|FLAGS2_EXTENDED_SECURITY|FLAGS2_32_BIT_ERROR_CODES; -void add_to_common_flags2(uint32 v) +void remove_from_common_flags2(uint32 v) { - common_flags2 |= v; + common_flags2 &= ~v; } void construct_reply_common(char *inbuf,char *outbuf) -- cgit From b88f446352b27d71a71d61a7151694c468cfe609 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 24 Feb 2004 00:06:08 +0000 Subject: Added NTrename SMB (0xA5) - how did we miss this.... ? Jeremy. (This used to be commit dfd7d1c2b7b577a084a94926abfce82c91f20b7e) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 5206dc70f8..718d1bb67b 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -521,7 +521,7 @@ static const struct smb_message_struct { /* 0xa2 */ { "SMBntcreateX", reply_ntcreate_and_X, AS_USER | CAN_IPC | QUEUE_IN_OPLOCK }, /* 0xa3 */ { NULL, NULL, 0 }, /* 0xa4 */ { "SMBntcancel", reply_ntcancel, 0 }, -/* 0xa5 */ { NULL, NULL, 0 }, +/* 0xa5 */ { "SMBntrename", reply_ntrename, AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK }, /* 0xa6 */ { NULL, NULL, 0 }, /* 0xa7 */ { NULL, NULL, 0 }, /* 0xa8 */ { NULL, NULL, 0 }, -- cgit From 1843f6905caf30de6493de07316a416696394d3e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 4 May 2004 23:01:00 +0000 Subject: r478: Added Volkers fix to be able to force DOS errors when needed. Jeremy. (This used to be commit a9d1738ebab42ab9bab73f18341d79e086e290b3) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 718d1bb67b..966bb63c1e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -736,7 +736,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize if (flags & AS_GUEST) flags &= ~AS_USER; else - return(ERROR_DOS(ERRSRV,ERRaccess)); + return(ERROR_FORCE_DOS(ERRSRV,ERRbaduid)); } /* this code is to work around a bug is MS client 3 without -- cgit From 89db7e100193c3b895180730f49061424a806c8e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 13 May 2004 00:20:50 +0000 Subject: r656: Make widelinks use realpath(). Tidy up cases where we need to become a service. Jeremy. (This used to be commit a03b6a05e02ec8415efc0e8ceade102e06f8fffe) --- source3/smbd/process.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 966bb63c1e..d0dfc6dd7d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -344,6 +344,7 @@ force write permissions on print services. #define CAN_IPC (1<<3) #define AS_GUEST (1<<5) #define QUEUE_IN_OPLOCK (1<<6) +#define DO_CHDIR (1<<7) /* define a list of possible SMB messages and their corresponding @@ -373,7 +374,7 @@ static const struct smb_message_struct { /* 0x0e */ { "SMBctemp",reply_ctemp,AS_USER | QUEUE_IN_OPLOCK }, /* 0x0f */ { "SMBmknew",reply_mknew,AS_USER}, /* 0x10 */ { "SMBchkpth",reply_chkpth,AS_USER}, -/* 0x11 */ { "SMBexit",reply_exit,0}, +/* 0x11 */ { "SMBexit",reply_exit,DO_CHDIR}, /* 0x12 */ { "SMBlseek",reply_lseek,AS_USER}, /* 0x13 */ { "SMBlockread",reply_lockread,AS_USER}, /* 0x14 */ { "SMBwriteunlock",reply_writeunlock,AS_USER}, @@ -469,7 +470,7 @@ static const struct smb_message_struct { /* 0x6e */ { NULL, NULL, 0 }, /* 0x6f */ { NULL, NULL, 0 }, /* 0x70 */ { "SMBtcon",reply_tcon,0}, -/* 0x71 */ { "SMBtdis",reply_tdis,0}, +/* 0x71 */ { "SMBtdis",reply_tdis,DO_CHDIR}, /* 0x72 */ { "SMBnegprot",reply_negprot,0}, /* 0x73 */ { "SMBsesssetupX",reply_sesssetup_and_X,0}, /* 0x74 */ { "SMBulogoffX", reply_ulogoffX, 0}, /* ulogoff doesn't give a valid TID */ @@ -754,7 +755,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize return(ERROR_DOS(ERRSRV,ERRaccess)); /* load service specific parameters */ - if (conn && !set_current_service(conn,(flags & AS_USER)?True:False)) + if (conn && !set_current_service(conn,(flags & (AS_USER|DO_CHDIR)?True:False))) return(ERROR_DOS(ERRSRV,ERRaccess)); /* does this protocol need to be run as guest? */ -- cgit From 67d474861d34490f6a8064d3eadc716d5a3a6020 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 20 May 2004 16:23:17 +0000 Subject: r799: BUG 1259 -- add 'printcap cache time' patch from Lars (This used to be commit fac90741139b953d0e88d050dd457657f0b9c9f3) --- source3/smbd/process.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d0dfc6dd7d..283b791afd 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1078,15 +1078,41 @@ static int setup_select_timeout(void) void check_reload(int t) { static time_t last_smb_conf_reload_time = 0; + static time_t last_load_printers_reload_time = 0; + time_t printcap_cache_time = (time_t)lp_printcap_cache_time(); - if(last_smb_conf_reload_time == 0) + if(last_smb_conf_reload_time == 0) { last_smb_conf_reload_time = t; + /* Our printing subsystem might not be ready at smbd start up. + Then no printer is available till the first printers check + is performed. A lower initial interval circumvents this. */ + if ( printcap_cache_time > 60 ) + last_load_printers_reload_time = t - printcap_cache_time + 60; + else + last_load_printers_reload_time = t; + } if (reload_after_sighup || (t >= last_smb_conf_reload_time+SMBD_RELOAD_CHECK)) { reload_services(True); reload_after_sighup = False; last_smb_conf_reload_time = t; } + + /* 'printcap cache time = 0' disable the feature */ + + if ( printcap_cache_time != 0 ) + { + /* see if it's time to reload or if the clock has been set back */ + + if ( (t >= last_load_printers_reload_time+printcap_cache_time) + || (t-last_load_printers_reload_time < 0) ) + { + DEBUG( 3,( "Printcap cache time expired.\n")); + remove_stale_printers(); + load_printers(); + last_load_printers_reload_time = t; + } + } } /**************************************************************************** -- cgit From 99d8aa8b17d6b6babdffbaf4f343375d58a88b5b Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Sat, 22 May 2004 05:01:25 +0000 Subject: r814: conn is 0 during ioctl (at least during smbtorture IOCTL test) fix smbd panic (This used to be commit 61da0bb1f6ea22df78ea7bd22a740c5868f62591) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 283b791afd..12fd809b78 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -683,7 +683,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize uint16 session_tag = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid); connection_struct *conn = conn_find(SVAL(inbuf,smb_tid)); - DEBUG(3,("switch message %s (pid %d)\n",smb_fn_name(type),(int)pid)); + DEBUG(3,("switch message %s (pid %d) conn 0x%x\n",smb_fn_name(type),(int)pid,(unsigned int)conn)); smb_dump(smb_fn_name(type), 1, inbuf, size); if(global_oplock_break) { -- cgit From 03d4344432c6aa75d400afc501aec1a14070f35d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 1 Jun 2004 20:43:32 +0000 Subject: r971: Auto remove store dos attributes if underlying filesystem doesn't support EA's. Jeremy. (This used to be commit 9de6b25c9e9abe982e21b0229df520802cafbfd8) --- source3/smbd/process.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 12fd809b78..efbc66a0ac 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -61,23 +61,24 @@ uint16 get_current_mid(void) for processing. ****************************************************************************/ -typedef struct { - ubi_slNode msg_next; +struct pending_message_list { + struct pending_message_list *next, *prev; char *msg_buf; int msg_len; -} pending_message_list; +}; -static ubi_slList smb_oplock_queue = { NULL, (ubi_slNodePtr)&smb_oplock_queue, 0}; +static struct pending_message_list *smb_oplock_queue; /**************************************************************************** Function to push a message onto the tail of a linked list of smb messages ready for processing. ****************************************************************************/ -static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len) +static BOOL push_message(struct pending_message_list *list_head, char *buf, int msg_len) { - pending_message_list *msg = (pending_message_list *) - malloc(sizeof(pending_message_list)); + struct pending_message_list *tmp_msg; + struct pending_message_list *msg = (struct pending_message_list *) + malloc(sizeof(struct pending_message_list)); if(msg == NULL) { DEBUG(0,("push_message: malloc fail (1)\n")); @@ -94,7 +95,7 @@ static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len) memcpy(msg->msg_buf, buf, msg_len); msg->msg_len = msg_len; - ubi_slAddTail( list_head, msg); + DLIST_ADD_END(list_head, msg, tmp_msg); /* Push the MID of this packet on the signing queue. */ srv_defer_sign_response(SVAL(buf,smb_mid)); @@ -109,7 +110,7 @@ static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len) BOOL push_oplock_pending_smb_message(char *buf, int msg_len) { - return push_message(&smb_oplock_queue, buf, msg_len); + return push_message(smb_oplock_queue, buf, msg_len); } /**************************************************************************** @@ -185,11 +186,12 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) * Check to see if we already have a message on the smb queue. * If so - copy and return it. */ - if(ubi_slCount(&smb_oplock_queue) != 0) { - pending_message_list *msg = (pending_message_list *)ubi_slRemHead(&smb_oplock_queue); + if(smb_oplock_queue != NULL) { + struct pending_message_list *msg = smb_oplock_queue; memcpy(buffer, msg->msg_buf, MIN(buffer_len, msg->msg_len)); /* Free the message we just copied. */ + DLIST_REMOVE(smb_oplock_queue, msg); SAFE_FREE(msg->msg_buf); SAFE_FREE(msg); -- cgit From b7ac82294f83b4b60d23b5ddf2ffe2caf5aef1a6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 4 Jun 2004 00:09:57 +0000 Subject: r996: Fix error in change to queuing code (dlink). Jeremy. (This used to be commit 6bd6359090b59d48370e16bb0ddc267a51b361c7) --- source3/smbd/process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index efbc66a0ac..72df91a21d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -74,7 +74,7 @@ static struct pending_message_list *smb_oplock_queue; for processing. ****************************************************************************/ -static BOOL push_message(struct pending_message_list *list_head, char *buf, int msg_len) +static BOOL push_message(struct pending_message_list **pplist_head, char *buf, int msg_len) { struct pending_message_list *tmp_msg; struct pending_message_list *msg = (struct pending_message_list *) @@ -95,7 +95,7 @@ static BOOL push_message(struct pending_message_list *list_head, char *buf, int memcpy(msg->msg_buf, buf, msg_len); msg->msg_len = msg_len; - DLIST_ADD_END(list_head, msg, tmp_msg); + DLIST_ADD_END(*pplist_head, msg, tmp_msg); /* Push the MID of this packet on the signing queue. */ srv_defer_sign_response(SVAL(buf,smb_mid)); @@ -110,7 +110,7 @@ static BOOL push_message(struct pending_message_list *list_head, char *buf, int BOOL push_oplock_pending_smb_message(char *buf, int msg_len) { - return push_message(smb_oplock_queue, buf, msg_len); + return push_message(&smb_oplock_queue, buf, msg_len); } /**************************************************************************** -- cgit From a6f5c88563c2169ce125be4e84f6980714f7e1ff Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 4 Jun 2004 00:20:58 +0000 Subject: r998: Arrrgggh. Do it right this time :-(. Jeremy. (This used to be commit 7ac7cd41629779c877b62ebd54b965980f4dc7bf) --- source3/smbd/process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 72df91a21d..ccebd2b86c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -74,7 +74,7 @@ static struct pending_message_list *smb_oplock_queue; for processing. ****************************************************************************/ -static BOOL push_message(struct pending_message_list **pplist_head, char *buf, int msg_len) +static BOOL push_message(char *buf, int msg_len) { struct pending_message_list *tmp_msg; struct pending_message_list *msg = (struct pending_message_list *) @@ -95,7 +95,7 @@ static BOOL push_message(struct pending_message_list **pplist_head, char *buf, i memcpy(msg->msg_buf, buf, msg_len); msg->msg_len = msg_len; - DLIST_ADD_END(*pplist_head, msg, tmp_msg); + DLIST_ADD_END(smb_oplock_queue, msg, tmp_msg); /* Push the MID of this packet on the signing queue. */ srv_defer_sign_response(SVAL(buf,smb_mid)); @@ -110,7 +110,7 @@ static BOOL push_message(struct pending_message_list **pplist_head, char *buf, i BOOL push_oplock_pending_smb_message(char *buf, int msg_len) { - return push_message(&smb_oplock_queue, buf, msg_len); + return push_message(buf, msg_len); } /**************************************************************************** -- cgit From 2fc57c9a2ce3a266534dd20e6fed4883e052c557 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 8 Jun 2004 16:14:31 +0000 Subject: r1085: Now it's had some proper user testing, merge in the deferred open fix. I'm still doing more testing, but it fixes a behaviour that we've been wrong on ever since the start of Samba. Jeremy. (This used to be commit 894cc6d16296b934c112786eec896846156aee5d) --- source3/smbd/process.c | 217 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 196 insertions(+), 21 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ccebd2b86c..698c8475f7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -61,20 +61,28 @@ uint16 get_current_mid(void) for processing. ****************************************************************************/ -struct pending_message_list { - struct pending_message_list *next, *prev; - char *msg_buf; - int msg_len; -}; - static struct pending_message_list *smb_oplock_queue; +static struct pending_message_list *smb_sharing_violation_queue; + +enum q_type { OPLOCK_QUEUE, SHARE_VIOLATION_QUEUE }; + +/**************************************************************************** + Free up a message. +****************************************************************************/ + +static void free_queued_message(struct pending_message_list *msg) +{ + data_blob_free(&msg->buf); + data_blob_free(&msg->private_data); + SAFE_FREE(msg); +} /**************************************************************************** Function to push a message onto the tail of a linked list of smb messages ready for processing. ****************************************************************************/ -static BOOL push_message(char *buf, int msg_len) +static BOOL push_queued_message(enum q_type qt, char *buf, int msg_len, struct timeval *ptv, char *private, size_t private_len) { struct pending_message_list *tmp_msg; struct pending_message_list *msg = (struct pending_message_list *) @@ -85,32 +93,159 @@ static BOOL push_message(char *buf, int msg_len) return False; } - msg->msg_buf = (char *)malloc(msg_len); - if(msg->msg_buf == NULL) { + memset(msg,'\0',sizeof(*msg)); + + msg->buf = data_blob(buf, msg_len); + if(msg->buf.data == NULL) { DEBUG(0,("push_message: malloc fail (2)\n")); SAFE_FREE(msg); return False; } - memcpy(msg->msg_buf, buf, msg_len); - msg->msg_len = msg_len; + if (ptv) { + msg->msg_time = *ptv; + } - DLIST_ADD_END(smb_oplock_queue, msg, tmp_msg); + if (private) { + msg->private_data = data_blob(private, private_len); + if (msg->private_data.data == NULL) { + DEBUG(0,("push_message: malloc fail (3)\n")); + data_blob_free(&msg->buf); + SAFE_FREE(msg); + } + } + + if (qt == OPLOCK_QUEUE) { + DLIST_ADD_END(smb_oplock_queue, msg, tmp_msg); + } else { + DLIST_ADD_END(smb_sharing_violation_queue, msg, tmp_msg); + } /* Push the MID of this packet on the signing queue. */ srv_defer_sign_response(SVAL(buf,smb_mid)); + DEBUG(10,("push_message: pushed message length %u on queue %s\n", + (unsigned int)msg_len, + qt == OPLOCK_QUEUE ? "smb_oplock_queue" : "smb_sharing_violation_queue" )); + return True; } /**************************************************************************** - Function to push a smb message onto a linked list of local smb messages ready + Function to push an oplock smb message onto a linked list of local smb messages ready for processing. ****************************************************************************/ BOOL push_oplock_pending_smb_message(char *buf, int msg_len) { - return push_message(buf, msg_len); + return push_queued_message(OPLOCK_QUEUE, buf, msg_len, NULL, NULL, 0); +} + +/**************************************************************************** + Function to delete a sharing violation open message by mid. +****************************************************************************/ + +void remove_sharing_violation_open_smb_message(uint16 mid) +{ + struct pending_message_list *pml; + + for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { + if (mid == SVAL(pml->buf.data,smb_mid)) { + DEBUG(10,("remove_sharing_violation_open_smb_message: deleting mid %u len %u\n", + (unsigned int)mid, (unsigned int)pml->buf.length )); + DLIST_REMOVE(smb_sharing_violation_queue, pml); + free_queued_message(pml); + return; + } + } +} + +/**************************************************************************** + Move a sharing violation open retry message to the front of the list and + schedule it for immediate processing. +****************************************************************************/ + +void schedule_sharing_violation_open_smb_message(uint16 mid) +{ + struct pending_message_list *pml; + int i = 0; + + for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { + uint16 msg_mid = SVAL(pml->buf.data,smb_mid); + DEBUG(10,("schedule_sharing_violation_open_smb_message: [%d] msg_mid = %u\n", i++, + (unsigned int)msg_mid )); + if (mid == msg_mid) { + DEBUG(10,("schedule_sharing_violation_open_smb_message: scheduling mid %u\n", + mid )); + pml->msg_time.tv_sec = 0; + pml->msg_time.tv_usec = 0; + DLIST_PROMOTE(smb_sharing_violation_queue, pml); + return; + } + } + + DEBUG(10,("schedule_sharing_violation_open_smb_message: failed to find message mid %u\n", + mid )); +} + +/**************************************************************************** + Return true if this mid is on the deferred queue. +****************************************************************************/ + +BOOL open_was_deferred(uint16 mid) +{ + struct pending_message_list *pml; + for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { + if (SVAL(pml->buf.data,smb_mid) == mid) { + return True; + } + } + return False; +} + +/**************************************************************************** + Return the message queued by this mid. +****************************************************************************/ + +struct pending_message_list *get_open_deferred_message(uint16 mid) +{ + struct pending_message_list *pml; + for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { + if (SVAL(pml->buf.data,smb_mid) == mid) { + return pml; + } + } + return NULL; +} + +/**************************************************************************** + Function to push a sharing violation open smb message onto a linked list of local smb messages ready + for processing. +****************************************************************************/ + +BOOL push_sharing_violation_open_smb_message(struct timeval *ptv, char *private, size_t priv_len) +{ + uint16 mid = SVAL(InBuffer,smb_mid); + struct timeval tv; + SMB_BIG_INT tdif; + + tv = *ptv; + tdif = tv.tv_sec; + tdif *= 1000000; + tdif += tv.tv_usec; + + /* Add on the timeout. */ + tdif += SHARING_VIOLATION_USEC_WAIT; + + tv.tv_sec = tdif / 1000000; + tv.tv_usec = tdif % 1000000; + + DEBUG(10,("push_sharing_violation_open_smb_message: pushing message len %u mid %u\ + timeout time [%u.%06u]\n", (unsigned int) smb_len(InBuffer)+4, (unsigned int)mid, + (unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec)); + + return push_queued_message(SHARE_VIOLATION_QUEUE, InBuffer, + smb_len(InBuffer)+4, &tv, private, priv_len); } /**************************************************************************** @@ -169,12 +304,17 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) fd_set fds; int selrtn; struct timeval to; + struct timeval *pto; int maxfd; smb_read_error = 0; again: + to.tv_sec = timeout / 1000; + to.tv_usec = (timeout % 1000) * 1000; + pto = timeout > 0 ? &to : NULL; + /* * Note that this call must be before processing any SMB * messages as we need to synchronously process any messages @@ -188,17 +328,55 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) */ if(smb_oplock_queue != NULL) { struct pending_message_list *msg = smb_oplock_queue; - memcpy(buffer, msg->msg_buf, MIN(buffer_len, msg->msg_len)); + memcpy(buffer, msg->buf.data, MIN(buffer_len, msg->buf.length)); /* Free the message we just copied. */ DLIST_REMOVE(smb_oplock_queue, msg); - SAFE_FREE(msg->msg_buf); - SAFE_FREE(msg); + free_queued_message(msg); DEBUG(5,("receive_message_or_smb: returning queued smb message.\n")); return True; } + /* + * Check to see if we already have a message on the deferred open queue + * and it's time to schedule. + */ + if(smb_sharing_violation_queue != NULL) { + BOOL pop_message = False; + struct pending_message_list *msg = smb_sharing_violation_queue; + + if (msg->msg_time.tv_sec == 0 && msg->msg_time.tv_usec == 0) { + pop_message = True; + } else { + struct timeval tv; + SMB_BIG_INT tdif; + + GetTimeOfDay(&tv); + tdif = usec_time_diff(&msg->msg_time, &tv); + if (tdif <= 0) { + /* Timed out. Schedule...*/ + pop_message = True; + DEBUG(10,("receive_message_or_smb: queued message timed out.\n")); + } else { + /* Make a more accurate select timeout. */ + to.tv_sec = tdif / 1000000; + to.tv_usec = tdif % 1000000; + pto = &to; + DEBUG(10,("receive_message_or_smb: select with timeout of [%u.%06u]\n", + (unsigned int)pto->tv_sec, (unsigned int)pto->tv_usec )); + } + } + + if (pop_message) { + memcpy(buffer, msg->buf.data, MIN(buffer_len, msg->buf.length)); + + /* We leave this message on the queue so the open code can + know this is a retry. */ + DEBUG(5,("receive_message_or_smb: returning deferred open smb message.\n")); + return True; + } + } /* * Setup the select read fd set. @@ -229,10 +407,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) FD_SET(smbd_server_fd(),&fds); maxfd = setup_oplock_select_set(&fds); - to.tv_sec = timeout / 1000; - to.tv_usec = (timeout % 1000) * 1000; - - selrtn = sys_select(MAX(maxfd,smbd_server_fd())+1,&fds,NULL,NULL,timeout>0?&to:NULL); + selrtn = sys_select(MAX(maxfd,smbd_server_fd())+1,&fds,NULL,NULL,pto); /* if we get EINTR then maybe we have received an oplock signal - treat this as select returning 1. This is ugly, but -- cgit From effd4a33856bf315122df9e4fbbb241a161caa62 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 8 Jun 2004 22:13:59 +0000 Subject: r1089: Removed spurious oplock message in deferred open processing. Fix smb signing sequence counts. Jeremy. (This used to be commit 7e2a5c36614282b6bd50b60360f443549426dd4b) --- source3/smbd/process.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 698c8475f7..05e4d0b1d9 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -121,9 +121,6 @@ static BOOL push_queued_message(enum q_type qt, char *buf, int msg_len, struct t DLIST_ADD_END(smb_sharing_violation_queue, msg, tmp_msg); } - /* Push the MID of this packet on the signing queue. */ - srv_defer_sign_response(SVAL(buf,smb_mid)); - DEBUG(10,("push_message: pushed message length %u on queue %s\n", (unsigned int)msg_len, qt == OPLOCK_QUEUE ? "smb_oplock_queue" : "smb_sharing_violation_queue" )); @@ -138,7 +135,12 @@ static BOOL push_queued_message(enum q_type qt, char *buf, int msg_len, struct t BOOL push_oplock_pending_smb_message(char *buf, int msg_len) { - return push_queued_message(OPLOCK_QUEUE, buf, msg_len, NULL, NULL, 0); + BOOL ret = push_queued_message(OPLOCK_QUEUE, buf, msg_len, NULL, NULL, 0); + if (ret) { + /* Push the MID of this packet on the signing queue. */ + srv_defer_sign_response(SVAL(buf,smb_mid)); + } + return ret; } /**************************************************************************** -- cgit From 2acd0848663f28afedff9b11b738e048f5ead2cc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 15 Jun 2004 18:36:45 +0000 Subject: r1154: Change default setting for case sensitivity to "auto". If set to auto then is the client supports it (current clients supported are Samba and CIFSVFS - detected by the negprot strings "Samba", "POSIX 2" and a bare "NT LM 0.12" string) then the setting of the per packet flag smb_flag FLAG_CASELESS_PATHNAMES is taken into account per packet. This allows the linux CIFS client to use Samba in a case sensitive manner. Additional command in smbclient "case_sensitive", toggles the flag in subsequent packets. Docs to follow. Jeremy. (This used to be commit cf84c0fe1a061acc0313f7db124b8f947cdf623d) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 05e4d0b1d9..72a604811b 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -934,7 +934,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize return(ERROR_DOS(ERRSRV,ERRaccess)); /* load service specific parameters */ - if (conn && !set_current_service(conn,(flags & (AS_USER|DO_CHDIR)?True:False))) + if (conn && !set_current_service(conn,SVAL(inbuf,smb_flg),(flags & (AS_USER|DO_CHDIR)?True:False))) return(ERROR_DOS(ERRSRV,ERRaccess)); /* does this protocol need to be run as guest? */ -- cgit From 3e0f586298125bbda80b8edcced49d5bbb424b0d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 26 Jun 2004 01:04:02 +0000 Subject: r1263: Make "defer sharing violations" a global parameter. Jeremy. (This used to be commit 42cdeccc36dc5f4bd133b84d4eaeb76f42f8043b) --- source3/smbd/process.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 72a604811b..60ce1499e8 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -151,6 +151,10 @@ void remove_sharing_violation_open_smb_message(uint16 mid) { struct pending_message_list *pml; + if (!lp_defer_sharing_violations()) { + return; + } + for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { if (mid == SVAL(pml->buf.data,smb_mid)) { DEBUG(10,("remove_sharing_violation_open_smb_message: deleting mid %u len %u\n", @@ -172,6 +176,10 @@ void schedule_sharing_violation_open_smb_message(uint16 mid) struct pending_message_list *pml; int i = 0; + if (!lp_defer_sharing_violations()) { + return; + } + for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { uint16 msg_mid = SVAL(pml->buf.data,smb_mid); DEBUG(10,("schedule_sharing_violation_open_smb_message: [%d] msg_mid = %u\n", i++, @@ -197,6 +205,11 @@ void schedule_sharing_violation_open_smb_message(uint16 mid) BOOL open_was_deferred(uint16 mid) { struct pending_message_list *pml; + + if (!lp_defer_sharing_violations()) { + return False; + } + for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { if (SVAL(pml->buf.data,smb_mid) == mid) { return True; @@ -212,6 +225,11 @@ BOOL open_was_deferred(uint16 mid) struct pending_message_list *get_open_deferred_message(uint16 mid) { struct pending_message_list *pml; + + if (!lp_defer_sharing_violations()) { + return NULL; + } + for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { if (SVAL(pml->buf.data,smb_mid) == mid) { return pml; @@ -231,6 +249,10 @@ BOOL push_sharing_violation_open_smb_message(struct timeval *ptv, char *private, struct timeval tv; SMB_BIG_INT tdif; + if (!lp_defer_sharing_violations()) { + return True; + } + tv = *ptv; tdif = tv.tv_sec; tdif *= 1000000; -- cgit From 6219c997cbe49952213460f1e100004d32469132 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 19 Aug 2004 20:03:41 +0000 Subject: r1936: Fix bug noticed by Steve - ensure extended security bit is on only if we negotiated extended security. Do not merge for 3.0.6. Works with W2K but needs further testing. Jeremy. (This used to be commit 284689aa18d2711a9041598cdf490359466f7f77) --- source3/smbd/process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 60ce1499e8..5be68d9f0a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1130,7 +1130,12 @@ const char *smb_fn_name(int type) Helper functions for contruct_reply. ****************************************************************************/ -static uint32 common_flags2 = FLAGS2_LONG_PATH_COMPONENTS|FLAGS2_EXTENDED_SECURITY|FLAGS2_32_BIT_ERROR_CODES; +static uint32 common_flags2 = FLAGS2_LONG_PATH_COMPONENTS|FLAGS2_32_BIT_ERROR_CODES; + +void add_to_common_flags2(uint32 v) +{ + common_flags2 |= v; +} void remove_from_common_flags2(uint32 v) { -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/smbd/process.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 5be68d9f0a..8adc5c2e66 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -85,8 +85,7 @@ static void free_queued_message(struct pending_message_list *msg) static BOOL push_queued_message(enum q_type qt, char *buf, int msg_len, struct timeval *ptv, char *private, size_t private_len) { struct pending_message_list *tmp_msg; - struct pending_message_list *msg = (struct pending_message_list *) - malloc(sizeof(struct pending_message_list)); + struct pending_message_list *msg = SMB_MALLOC_P(struct pending_message_list); if(msg == NULL) { DEBUG(0,("push_message: malloc fail (1)\n")); @@ -1498,8 +1497,8 @@ void smbd_process(void) unsigned int num_smbs = 0; const size_t total_buffer_size = BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN; - InBuffer = (char *)malloc(total_buffer_size); - OutBuffer = (char *)malloc(total_buffer_size); + InBuffer = (char *)SMB_MALLOC(total_buffer_size); + OutBuffer = (char *)SMB_MALLOC(total_buffer_size); if ((InBuffer == NULL) || (OutBuffer == NULL)) return; -- cgit From 5b713a206bf9c05faad750512886f4bbeebb21f8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Dec 2004 00:25:11 +0000 Subject: r4186: Fix client & server to allow 127k READX calls. Jeremy. (This used to be commit 831cb21a874601e4536c2cf76c5351e1d0defcb5) --- source3/smbd/process.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 8adc5c2e66..aa1f574767 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1177,8 +1177,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) int outsize2; char inbuf_saved[smb_wct]; char outbuf_saved[smb_wct]; - int wct = CVAL(outbuf,smb_wct); - int outsize = smb_size + 2*wct + SVAL(outbuf,smb_vwv0+2*wct); + int outsize = smb_len(outbuf); /* maybe its not chained */ if (smb_com2 == 0xFF) { -- cgit From 32f9ee7c206138b2f26254d9b4b7b45f4490ef38 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Dec 2004 01:11:22 +0000 Subject: r4190: When changing length calculations, get them right...... Jeremy. (This used to be commit 63cfa904ad186bb9d793584d319bd4a7107cc8b9) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index aa1f574767..1372ebbf45 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1177,7 +1177,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) int outsize2; char inbuf_saved[smb_wct]; char outbuf_saved[smb_wct]; - int outsize = smb_len(outbuf); + int outsize = smb_len(outbuf) + 4; /* maybe its not chained */ if (smb_com2 == 0xFF) { -- cgit From d097ea490525e7a35739dae6a295fd03ba52cfc0 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 5 Jan 2005 16:20:35 +0000 Subject: r4539: patch from Rob -- adding real printcap name cache function to speed up printcap reloads (This used to be commit 1cad5250932b963c2eb9b775221b13db386d601b) --- source3/smbd/process.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1372ebbf45..54837c3b9a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1282,7 +1282,7 @@ static int setup_select_timeout(void) void check_reload(int t) { static time_t last_smb_conf_reload_time = 0; - static time_t last_load_printers_reload_time = 0; + static time_t last_printer_reload_time = 0; time_t printcap_cache_time = (time_t)lp_printcap_cache_time(); if(last_smb_conf_reload_time == 0) { @@ -1291,9 +1291,9 @@ void check_reload(int t) Then no printer is available till the first printers check is performed. A lower initial interval circumvents this. */ if ( printcap_cache_time > 60 ) - last_load_printers_reload_time = t - printcap_cache_time + 60; + last_printer_reload_time = t - printcap_cache_time + 60; else - last_load_printers_reload_time = t; + last_printer_reload_time = t; } if (reload_after_sighup || (t >= last_smb_conf_reload_time+SMBD_RELOAD_CHECK)) { @@ -1308,13 +1308,12 @@ void check_reload(int t) { /* see if it's time to reload or if the clock has been set back */ - if ( (t >= last_load_printers_reload_time+printcap_cache_time) - || (t-last_load_printers_reload_time < 0) ) + if ( (t >= last_printer_reload_time+printcap_cache_time) + || (t-last_printer_reload_time < 0) ) { DEBUG( 3,( "Printcap cache time expired.\n")); - remove_stale_printers(); - load_printers(); - last_load_printers_reload_time = t; + reload_printers(); + last_printer_reload_time = t; } } } -- cgit From 0557c6cba2a21c9df547fbc8ff4db2899bc1c171 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 1 Apr 2005 23:11:28 +0000 Subject: r6172: Tidy up error processing significantly. Remove unix_ERR_XXX global nastyness. Jeremy. (This used to be commit d3379fe61bb934082b51a37adac232a96bafcf46) --- source3/smbd/process.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 54837c3b9a..3043cadfd8 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -211,6 +211,7 @@ BOOL open_was_deferred(uint16 mid) for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { if (SVAL(pml->buf.data,smb_mid) == mid) { + set_saved_error_triple(SMB_SUCCESS, 0, NT_STATUS_OK); return True; } } @@ -859,6 +860,8 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize pid = sys_getpid(); errno = 0; + set_saved_error_triple(0, 0, NT_STATUS_OK); + last_message = type; /* Make sure this is an SMB packet. smb_size contains NetBIOS header so subtract 4 from it. */ -- cgit From 978ca8486031e43754a3c23757f361bf3a85f335 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 6 Apr 2005 16:28:04 +0000 Subject: r6225: get rid of warnings from my compiler about nested externs (This used to be commit efea76ac71412f8622cd233912309e91b9ea52da) --- source3/smbd/process.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 3043cadfd8..1bf6f4f9d1 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -20,6 +20,11 @@ #include "includes.h" +extern uint16 global_smbpid; +extern int keepalive; +extern struct auth_context *negprot_global_auth_context; +extern int smb_echo_count; + struct timeval smb_last_time; static char *InBuffer = NULL; @@ -852,7 +857,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize { static pid_t pid= (pid_t)-1; int outsize = 0; - extern uint16 global_smbpid; type &= 0xff; @@ -1331,7 +1335,6 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t static time_t last_idle_closed_check = 0; time_t t; BOOL allidle = True; - extern int keepalive; if (smb_read_error == READ_EOF) { DEBUG(3,("timeout_processing: End of file from client (client has disconnected).\n")); @@ -1375,7 +1378,6 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t } if (keepalive && (t - last_keepalive_sent_time)>keepalive) { - extern struct auth_context *negprot_global_auth_context; if (!send_keepalive(smbd_server_fd())) { DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); return False; @@ -1493,7 +1495,6 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); void smbd_process(void) { - extern int smb_echo_count; time_t last_timeout_processing_time = time(NULL); unsigned int num_smbs = 0; const size_t total_buffer_size = BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN; -- cgit From f60ad8ded6e614f3c0abb2679d3a75096fc595d3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 14 Apr 2005 23:32:56 +0000 Subject: r6346: Add a counter for the number of SMB operations per connection/file. You will need to do a make clean after SVN updating this. Next will come a smbcontrol message to dump this info. This should be interesting to profile client activity. Jeremy. (This used to be commit 743174da86ac724fc9ee3d4b7bd9a2a97a234bd8) --- source3/smbd/process.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1bf6f4f9d1..e79686b43e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -962,8 +962,12 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize return(ERROR_DOS(ERRSRV,ERRaccess)); /* load service specific parameters */ - if (conn && !set_current_service(conn,SVAL(inbuf,smb_flg),(flags & (AS_USER|DO_CHDIR)?True:False))) - return(ERROR_DOS(ERRSRV,ERRaccess)); + if (conn) { + if (!set_current_service(conn,SVAL(inbuf,smb_flg),(flags & (AS_USER|DO_CHDIR)?True:False))) { + return(ERROR_DOS(ERRSRV,ERRaccess)); + } + conn->num_smb_operations++; + } /* does this protocol need to be run as guest? */ if ((flags & AS_GUEST) && (!change_to_guest() || -- cgit From b6fb04624910964111a1ad90dbe1ebae7981ba6f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 6 Jun 2005 15:21:09 +0000 Subject: r7344: Correctly return if malloc fails. Jeremy, you might want to check this. Thanks, Volker (This used to be commit 560f9d37353f6b886996144215f99e06f2513007) --- source3/smbd/process.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index e79686b43e..afde2e94a9 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -116,6 +116,7 @@ static BOOL push_queued_message(enum q_type qt, char *buf, int msg_len, struct t DEBUG(0,("push_message: malloc fail (3)\n")); data_blob_free(&msg->buf); SAFE_FREE(msg); + return False; } } -- cgit From a59149b86a36cd8b51ad5ae11b4d2b0714bb5e9c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Jun 2005 20:42:21 +0000 Subject: r7550: Steal the correct error return for invalid TID on NTcreateX from Samba4 (thanks tridge !). Jeremy. (This used to be commit 0288823aacdbec6ba99e944c9f06f051e55c64b8) --- source3/smbd/process.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index afde2e94a9..0373cd471c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -936,8 +936,14 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize change_to_root_user(); /* does this protocol need a valid tree connection? */ - if ((flags & AS_USER) && !conn) - return ERROR_DOS(ERRSRV, ERRinvnid); + if ((flags & AS_USER) && !conn) { + /* Amazingly, the error code depends on the command (from Samba4). */ + if (type == SMBntcreateX) { + return ERROR_NT(NT_STATUS_INVALID_HANDLE); + } else { + return ERROR_DOS(ERRSRV, ERRinvnid); + } + } /* does this protocol need to be run as the connected user? */ -- cgit From 19ca97a70f6b7b41d251eaa76e4d3c980c6eedff Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 24 Jun 2005 20:25:18 +0000 Subject: r7882: Looks like a large patch - but what it actually does is make Samba safe for using our headers and linking with C++ modules. Stops us from using C++ reserved keywords in our code. Jeremy (This used to be commit 9506b8e145982b1160a2f0aee5c9b7a54980940a) --- source3/smbd/process.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 0373cd471c..1ec176bd08 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -87,7 +87,7 @@ static void free_queued_message(struct pending_message_list *msg) for processing. ****************************************************************************/ -static BOOL push_queued_message(enum q_type qt, char *buf, int msg_len, struct timeval *ptv, char *private, size_t private_len) +static BOOL push_queued_message(enum q_type qt, char *buf, int msg_len, struct timeval *ptv, char *private_data, size_t private_len) { struct pending_message_list *tmp_msg; struct pending_message_list *msg = SMB_MALLOC_P(struct pending_message_list); @@ -110,8 +110,8 @@ static BOOL push_queued_message(enum q_type qt, char *buf, int msg_len, struct t msg->msg_time = *ptv; } - if (private) { - msg->private_data = data_blob(private, private_len); + if (private_data) { + msg->private_data = data_blob(private_data, private_len); if (msg->private_data.data == NULL) { DEBUG(0,("push_message: malloc fail (3)\n")); data_blob_free(&msg->buf); @@ -249,7 +249,7 @@ struct pending_message_list *get_open_deferred_message(uint16 mid) for processing. ****************************************************************************/ -BOOL push_sharing_violation_open_smb_message(struct timeval *ptv, char *private, size_t priv_len) +BOOL push_sharing_violation_open_smb_message(struct timeval *ptv, char *private_data, size_t priv_len) { uint16 mid = SVAL(InBuffer,smb_mid); struct timeval tv; @@ -275,7 +275,7 @@ BOOL push_sharing_violation_open_smb_message(struct timeval *ptv, char *private, (unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec)); return push_queued_message(SHARE_VIOLATION_QUEUE, InBuffer, - smb_len(InBuffer)+4, &tv, private, priv_len); + smb_len(InBuffer)+4, &tv, private_data, priv_len); } /**************************************************************************** -- cgit From 7ebd74e6c502483b7f7c73943b698d6433c8c0b2 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 27 Jun 2005 22:44:57 +0000 Subject: r7961: randomize reloading so that smbds do not pverload cupsd by reloading printers all at the same time. sss (This used to be commit da227d5f4311c84a12a4e2a9fd510328268af4b3) --- source3/smbd/process.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1ec176bd08..c4c1debbf3 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1299,6 +1299,7 @@ static int setup_select_timeout(void) void check_reload(int t) { + static pid_t mypid = 0; static time_t last_smb_conf_reload_time = 0; static time_t last_printer_reload_time = 0; time_t printcap_cache_time = (time_t)lp_printcap_cache_time(); @@ -1314,6 +1315,15 @@ void check_reload(int t) last_printer_reload_time = t; } + if (mypid != getpid()) { /* First time or fork happened meanwhile */ + /* randomize over 60 second the printcap reload to avoid all + * process hitting cupsd at the same time */ + int time_range = 60; + + last_printer_reload_time += random() % time_range; + mypid = getpid(); + } + if (reload_after_sighup || (t >= last_smb_conf_reload_time+SMBD_RELOAD_CHECK)) { reload_services(True); reload_after_sighup = False; -- cgit From f2f55d703d0dd549a83809d3e5cc5151569b48d6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 27 Jun 2005 22:53:56 +0000 Subject: r7963: Add aio support to 3.0. Jeremy. (This used to be commit 1de27da47051af08790317f5b48b02719d6b9934) --- source3/smbd/process.c | 111 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 98 insertions(+), 13 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c4c1debbf3..94d4b8d903 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -28,8 +28,7 @@ extern int smb_echo_count; struct timeval smb_last_time; static char *InBuffer = NULL; -char *OutBuffer = NULL; -char *last_inbuf = NULL; +static char *OutBuffer = NULL; /* * Size of data we can send to client. Set @@ -287,11 +286,17 @@ static void async_processing(char *buffer, int buffer_len) { DEBUG(10,("async_processing: Doing async processing.\n")); + process_aio_queue(); + /* check for oplock messages (both UDP and kernel) */ if (receive_local_message(buffer, buffer_len, 1)) { process_local_message(buffer, buffer_len); } + /* Do the aio check again after receive_local_message as it does a select + and may have eaten our signal. */ + process_aio_queue(); + if (got_sig_term) { exit_server("Caught TERM signal"); } @@ -981,8 +986,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) return(ERROR_DOS(ERRSRV,ERRaccess)); - last_inbuf = inbuf; - outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); } @@ -1511,24 +1514,106 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); } /**************************************************************************** - process commands from the client + Accessor functions for InBuffer, OutBuffer. ****************************************************************************/ -void smbd_process(void) +char *get_InBuffer(void) { - time_t last_timeout_processing_time = time(NULL); - unsigned int num_smbs = 0; - const size_t total_buffer_size = BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN; + return InBuffer; +} - InBuffer = (char *)SMB_MALLOC(total_buffer_size); - OutBuffer = (char *)SMB_MALLOC(total_buffer_size); - if ((InBuffer == NULL) || (OutBuffer == NULL)) - return; +void set_InBuffer(char *new_inbuf) +{ + InBuffer = new_inbuf; +} + +char *get_OutBuffer(void) +{ + return OutBuffer; +} + +void set_OutBuffer(char *new_outbuf) +{ + OutBuffer = new_outbuf; +} + +/**************************************************************************** + Free an InBuffer. Checks if not in use by aio system. + Must have been allocated by NewInBuffer. +****************************************************************************/ + +void free_InBuffer(char *inbuf) +{ + if (!aio_inbuffer_in_use(inbuf)) { + SAFE_FREE(inbuf); + } +} + +/**************************************************************************** + Free an OutBuffer. No outbuffers currently stolen by aio system. + Must have been allocated by NewInBuffer. +****************************************************************************/ + +void free_OutBuffer(char *outbuf) +{ + SAFE_FREE(outbuf); +} + +const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); +/**************************************************************************** + Allocate a new InBuffer. Returns the new and old ones. +****************************************************************************/ + +char *NewInBuffer(char **old_inbuf) +{ + char *new_inbuf = (char *)SMB_MALLOC(total_buffer_size); + if (!new_inbuf) { + return NULL; + } + if (old_inbuf) { + *old_inbuf = InBuffer; + } + InBuffer = new_inbuf; #if defined(DEVELOPER) clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); +#endif + return InBuffer; +} + +/**************************************************************************** + Allocate a new OutBuffer. Returns the new and old ones. +****************************************************************************/ + +char *NewOutBuffer(char **old_outbuf) +{ + char *new_outbuf = (char *)SMB_MALLOC(total_buffer_size); + if (!new_outbuf) { + return NULL; + } + if (old_outbuf) { + *old_outbuf = OutBuffer; + } + OutBuffer = new_outbuf; +#if defined(DEVELOPER) clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size); #endif + return OutBuffer; +} + +/**************************************************************************** + Process commands from the client +****************************************************************************/ + +void smbd_process(void) +{ + time_t last_timeout_processing_time = time(NULL); + unsigned int num_smbs = 0; + + /* Allocate the primary Inbut/Output buffers. */ + + if ((NewInBuffer(NULL) == NULL) || (NewOutBuffer(NULL) == NULL)) + return; max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); -- cgit From a344155b8d89869fa82594868b9a6952f53d9631 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 26 Jul 2005 17:58:53 +0000 Subject: r8782: Fix bug #2918. The problem was using Inbuffer to push a deferred open message onto the queue when we're in a chained message set - we're actually processing a different buffer then. Added current_inbuf as a static inside smbd/process.c to ensure the correct message gets pushed and processed. Jeremy. (This used to be commit ccef7581717bff6145ffc386d5be24d6f42634cb) --- source3/smbd/process.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 94d4b8d903..897bd56ba7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -29,6 +29,7 @@ struct timeval smb_last_time; static char *InBuffer = NULL; static char *OutBuffer = NULL; +static char *current_inbuf = NULL; /* * Size of data we can send to client. Set @@ -245,12 +246,12 @@ struct pending_message_list *get_open_deferred_message(uint16 mid) /**************************************************************************** Function to push a sharing violation open smb message onto a linked list of local smb messages ready - for processing. + for processing. We must use current_inbuf here not Inbuf in case we're in a chained message set. ****************************************************************************/ BOOL push_sharing_violation_open_smb_message(struct timeval *ptv, char *private_data, size_t priv_len) { - uint16 mid = SVAL(InBuffer,smb_mid); + uint16 mid = SVAL(current_inbuf,smb_mid); struct timeval tv; SMB_BIG_INT tdif; @@ -270,11 +271,11 @@ BOOL push_sharing_violation_open_smb_message(struct timeval *ptv, char *private_ tv.tv_usec = tdif % 1000000; DEBUG(10,("push_sharing_violation_open_smb_message: pushing message len %u mid %u\ - timeout time [%u.%06u]\n", (unsigned int) smb_len(InBuffer)+4, (unsigned int)mid, + timeout time [%u.%06u]\n", (unsigned int) smb_len(current_inbuf)+4, (unsigned int)mid, (unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec)); - return push_queued_message(SHARE_VIOLATION_QUEUE, InBuffer, - smb_len(InBuffer)+4, &tv, private_data, priv_len); + return push_queued_message(SHARE_VIOLATION_QUEUE, current_inbuf, + smb_len(current_inbuf)+4, &tv, private_data, priv_len); } /**************************************************************************** @@ -986,6 +987,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) return(ERROR_DOS(ERRSRV,ERRaccess)); + current_inbuf = inbuf; /* In case we need to defer this message in open... */ outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); } -- cgit From 880d62843afd52c2e4bdf66e9e8218823445e109 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 27 Jul 2005 16:10:50 +0000 Subject: r8798: Save one system call per SMB. smb_run_idle_events right now is only used to close idle pdb_ldap connections, and from my point of view this can wait until normal timeout handling, this does not need to be done per client request. Volker (This used to be commit 404b817d7294fbea64f0fca019406c5c7458e386) --- source3/smbd/process.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 897bd56ba7..19add7e095 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1633,10 +1633,6 @@ void smbd_process(void) lp_talloc_free(); main_loop_talloc_free(); - /* run all registered idle events */ - smb_run_idle_events(time(NULL)); - - /* Did someone ask for immediate checks on things like blocking locks ? */ if (select_timeout == 0) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) -- cgit From 3dae794632f48ae163d1195fef19c14e67f341cc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 5 Aug 2005 17:10:10 +0000 Subject: r9126: Fix valgrind bug Volker found in interaction with new aio buffer flipping and oplocks. Jeremy. (This used to be commit a18c5ff3eada93e46da3f7cbd326b8dceb72e147) --- source3/smbd/process.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 19add7e095..1deb4da269 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1527,6 +1527,7 @@ char *get_InBuffer(void) void set_InBuffer(char *new_inbuf) { InBuffer = new_inbuf; + current_inbuf = InBuffer; } char *get_OutBuffer(void) @@ -1547,6 +1548,9 @@ void set_OutBuffer(char *new_outbuf) void free_InBuffer(char *inbuf) { if (!aio_inbuffer_in_use(inbuf)) { + if (current_inbuf == inbuf) { + current_inbuf = NULL; + } SAFE_FREE(inbuf); } } -- cgit From c46b4cabf4ee02fc90b3b42c800926f55c7099be Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 12 Sep 2005 21:50:32 +0000 Subject: r10188: 64-bit warning fix. Jeremy. (This used to be commit 3b8a8e2947e4d956766e97bea8fa9c25210d1c19) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1deb4da269..8f9cc52882 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -897,7 +897,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize uint16 session_tag = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid); connection_struct *conn = conn_find(SVAL(inbuf,smb_tid)); - DEBUG(3,("switch message %s (pid %d) conn 0x%x\n",smb_fn_name(type),(int)pid,(unsigned int)conn)); + DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n",smb_fn_name(type),(int)pid,(unsigned long)conn)); smb_dump(smb_fn_name(type), 1, inbuf, size); if(global_oplock_break) { -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/smbd/process.c | 457 +++++++++++++++++++++++++++++-------------------- 1 file changed, 270 insertions(+), 187 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 8f9cc52882..0b7b94cce2 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -2,6 +2,7 @@ Unix SMB/CIFS implementation. process incoming packets - main loop Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Volker Lendecke 2005 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -44,12 +45,11 @@ int max_send = BUFFER_SIZE; int max_recv = BUFFER_SIZE; extern int last_message; -extern int global_oplock_break; extern userdom_struct current_user_info; extern int smb_read_error; SIG_ATOMIC_T reload_after_sighup = 0; SIG_ATOMIC_T got_sig_term = 0; -BOOL global_machine_password_needs_changing = False; +extern BOOL global_machine_password_needs_changing; extern int max_send; /**************************************************************************** @@ -66,106 +66,72 @@ uint16 get_current_mid(void) for processing. ****************************************************************************/ -static struct pending_message_list *smb_oplock_queue; -static struct pending_message_list *smb_sharing_violation_queue; - -enum q_type { OPLOCK_QUEUE, SHARE_VIOLATION_QUEUE }; - -/**************************************************************************** - Free up a message. -****************************************************************************/ - -static void free_queued_message(struct pending_message_list *msg) -{ - data_blob_free(&msg->buf); - data_blob_free(&msg->private_data); - SAFE_FREE(msg); -} +static struct pending_message_list *deferred_open_queue; /**************************************************************************** Function to push a message onto the tail of a linked list of smb messages ready for processing. ****************************************************************************/ -static BOOL push_queued_message(enum q_type qt, char *buf, int msg_len, struct timeval *ptv, char *private_data, size_t private_len) +static BOOL push_queued_message(char *buf, int msg_len, + struct timeval request_time, + struct timeval end_time, + char *private_data, size_t private_len) { struct pending_message_list *tmp_msg; - struct pending_message_list *msg = SMB_MALLOC_P(struct pending_message_list); + struct pending_message_list *msg; + + msg = TALLOC_ZERO_P(NULL, struct pending_message_list); if(msg == NULL) { DEBUG(0,("push_message: malloc fail (1)\n")); return False; } - memset(msg,'\0',sizeof(*msg)); - - msg->buf = data_blob(buf, msg_len); + msg->buf = data_blob_talloc(msg, buf, msg_len); if(msg->buf.data == NULL) { DEBUG(0,("push_message: malloc fail (2)\n")); - SAFE_FREE(msg); + talloc_free(msg); return False; } - if (ptv) { - msg->msg_time = *ptv; - } + msg->request_time = request_time; + msg->end_time = end_time; if (private_data) { - msg->private_data = data_blob(private_data, private_len); + msg->private_data = data_blob_talloc(msg, private_data, + private_len); if (msg->private_data.data == NULL) { DEBUG(0,("push_message: malloc fail (3)\n")); - data_blob_free(&msg->buf); - SAFE_FREE(msg); + talloc_free(msg); return False; } } - if (qt == OPLOCK_QUEUE) { - DLIST_ADD_END(smb_oplock_queue, msg, tmp_msg); - } else { - DLIST_ADD_END(smb_sharing_violation_queue, msg, tmp_msg); - } + DLIST_ADD_END(deferred_open_queue, msg, tmp_msg); - DEBUG(10,("push_message: pushed message length %u on queue %s\n", - (unsigned int)msg_len, - qt == OPLOCK_QUEUE ? "smb_oplock_queue" : "smb_sharing_violation_queue" )); + DEBUG(10,("push_message: pushed message length %u on " + "deferred_open_queue\n", (unsigned int)msg_len)); return True; } -/**************************************************************************** - Function to push an oplock smb message onto a linked list of local smb messages ready - for processing. -****************************************************************************/ - -BOOL push_oplock_pending_smb_message(char *buf, int msg_len) -{ - BOOL ret = push_queued_message(OPLOCK_QUEUE, buf, msg_len, NULL, NULL, 0); - if (ret) { - /* Push the MID of this packet on the signing queue. */ - srv_defer_sign_response(SVAL(buf,smb_mid)); - } - return ret; -} - /**************************************************************************** Function to delete a sharing violation open message by mid. ****************************************************************************/ -void remove_sharing_violation_open_smb_message(uint16 mid) +void remove_deferred_open_smb_message(uint16 mid) { struct pending_message_list *pml; - if (!lp_defer_sharing_violations()) { - return; - } - - for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { + for (pml = deferred_open_queue; pml; pml = pml->next) { if (mid == SVAL(pml->buf.data,smb_mid)) { - DEBUG(10,("remove_sharing_violation_open_smb_message: deleting mid %u len %u\n", - (unsigned int)mid, (unsigned int)pml->buf.length )); - DLIST_REMOVE(smb_sharing_violation_queue, pml); - free_queued_message(pml); + DEBUG(10,("remove_sharing_violation_open_smb_message: " + "deleting mid %u len %u\n", + (unsigned int)mid, + (unsigned int)pml->buf.length )); + DLIST_REMOVE(deferred_open_queue, pml); + talloc_free(pml); return; } } @@ -176,30 +142,26 @@ void remove_sharing_violation_open_smb_message(uint16 mid) schedule it for immediate processing. ****************************************************************************/ -void schedule_sharing_violation_open_smb_message(uint16 mid) +void schedule_deferred_open_smb_message(uint16 mid) { struct pending_message_list *pml; int i = 0; - if (!lp_defer_sharing_violations()) { - return; - } - - for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { + for (pml = deferred_open_queue; pml; pml = pml->next) { uint16 msg_mid = SVAL(pml->buf.data,smb_mid); - DEBUG(10,("schedule_sharing_violation_open_smb_message: [%d] msg_mid = %u\n", i++, + DEBUG(10,("schedule_deferred_open_smb_message: [%d] msg_mid = %u\n", i++, (unsigned int)msg_mid )); if (mid == msg_mid) { - DEBUG(10,("schedule_sharing_violation_open_smb_message: scheduling mid %u\n", + DEBUG(10,("schedule_deferred_open_smb_message: scheduling mid %u\n", mid )); - pml->msg_time.tv_sec = 0; - pml->msg_time.tv_usec = 0; - DLIST_PROMOTE(smb_sharing_violation_queue, pml); + pml->end_time.tv_sec = 0; + pml->end_time.tv_usec = 0; + DLIST_PROMOTE(deferred_open_queue, pml); return; } } - DEBUG(10,("schedule_sharing_violation_open_smb_message: failed to find message mid %u\n", + DEBUG(10,("schedule_deferred_open_smb_message: failed to find message mid %u\n", mid )); } @@ -211,13 +173,9 @@ BOOL open_was_deferred(uint16 mid) { struct pending_message_list *pml; - if (!lp_defer_sharing_violations()) { - return False; - } - - for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { + for (pml = deferred_open_queue; pml; pml = pml->next) { if (SVAL(pml->buf.data,smb_mid) == mid) { - set_saved_error_triple(SMB_SUCCESS, 0, NT_STATUS_OK); + set_saved_ntstatus(NT_STATUS_OK); return True; } } @@ -232,11 +190,7 @@ struct pending_message_list *get_open_deferred_message(uint16 mid) { struct pending_message_list *pml; - if (!lp_defer_sharing_violations()) { - return NULL; - } - - for (pml = smb_sharing_violation_queue; pml; pml = pml->next) { + for (pml = deferred_open_queue; pml; pml = pml->next) { if (SVAL(pml->buf.data,smb_mid) == mid) { return pml; } @@ -245,57 +199,216 @@ struct pending_message_list *get_open_deferred_message(uint16 mid) } /**************************************************************************** - Function to push a sharing violation open smb message onto a linked list of local smb messages ready - for processing. We must use current_inbuf here not Inbuf in case we're in a chained message set. + Function to push a deferred open smb message onto a linked list of local smb + messages ready for processing. +****************************************************************************/ + +BOOL push_deferred_smb_message(uint16 mid, + struct timeval request_time, + struct timeval timeout, + char *private_data, size_t priv_len) +{ + struct timeval end_time; + + end_time = timeval_sum(&request_time, &timeout); + + DEBUG(10,("push_deferred_open_smb_message: pushing message len %u mid %u " + "timeout time [%u.%06u]\n", + (unsigned int) smb_len(current_inbuf)+4, (unsigned int)mid, + (unsigned int)end_time.tv_sec, + (unsigned int)end_time.tv_usec)); + + return push_queued_message(current_inbuf, smb_len(current_inbuf)+4, + request_time, end_time, + private_data, priv_len); +} + +static struct timed_event *timed_events; + +struct timed_event { + struct timed_event *next, *prev; + struct timeval when; + const char *event_name; + void (*handler)(struct timed_event *te, + const struct timeval *now, + void *private_data); + void *private_data; +}; + +static int timed_event_destructor(void *p) +{ + struct timed_event *te = talloc_get_type_abort(p, struct timed_event); + DEBUG(10, ("Destroying timed event %lx \"%s\"\n", (unsigned long)te, + te->event_name)); + DLIST_REMOVE(timed_events, te); + return 0; +} + +/**************************************************************************** + Schedule a function for future calling, cancel with talloc_free(). + It's the responsibility of the handler to call talloc_free() on the event + handed to it. ****************************************************************************/ -BOOL push_sharing_violation_open_smb_message(struct timeval *ptv, char *private_data, size_t priv_len) +struct timed_event *add_timed_event(TALLOC_CTX *mem_ctx, + struct timeval when, + const char *event_name, + void (*handler)(struct timed_event *te, + const struct timeval *now, + void *private_data), + void *private_data) { - uint16 mid = SVAL(current_inbuf,smb_mid); - struct timeval tv; - SMB_BIG_INT tdif; + struct timed_event *te, *last_te, *cur_te; - if (!lp_defer_sharing_violations()) { - return True; + te = TALLOC_P(mem_ctx, struct timed_event); + if (te == NULL) { + DEBUG(0, ("talloc failed\n")); + return NULL; } - tv = *ptv; - tdif = tv.tv_sec; - tdif *= 1000000; - tdif += tv.tv_usec; + te->when = when; + te->event_name = event_name; + te->handler = handler; + te->private_data = private_data; + + /* keep the list ordered */ + last_te = NULL; + for (cur_te = timed_events; cur_te; cur_te = cur_te->next) { + /* if the new event comes before the current one break */ + if (!timeval_is_zero(&cur_te->when) && + timeval_compare(&te->when, &cur_te->when) < 0) { + break; + } + last_te = cur_te; + } - /* Add on the timeout. */ - tdif += SHARING_VIOLATION_USEC_WAIT; - - tv.tv_sec = tdif / 1000000; - tv.tv_usec = tdif % 1000000; - - DEBUG(10,("push_sharing_violation_open_smb_message: pushing message len %u mid %u\ - timeout time [%u.%06u]\n", (unsigned int) smb_len(current_inbuf)+4, (unsigned int)mid, - (unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec)); + DLIST_ADD_AFTER(timed_events, te, last_te); + talloc_set_destructor(te, timed_event_destructor); - return push_queued_message(SHARE_VIOLATION_QUEUE, current_inbuf, - smb_len(current_inbuf)+4, &tv, private_data, priv_len); + DEBUG(10, ("Added timed event \"%s\": %lx\n", event_name, + (unsigned long)te)); + return te; } +static void run_events(void) +{ + struct timeval now; + + if (timed_events == NULL) { + /* No syscall if there are no events */ + DEBUG(10, ("run_events: No events\n")); + return; + } + + GetTimeOfDay(&now); + + if (timeval_compare(&now, &timed_events->when) < 0) { + /* Nothing to do yet */ + DEBUG(10, ("run_events: Nothing to do\n")); + return; + } + + DEBUG(10, ("Running event \"%s\" %lx\n", timed_events->event_name, + (unsigned long)timed_events)); + + timed_events->handler(timed_events, &now, timed_events->private_data); + return; +} + +struct timeval timed_events_timeout(void) +{ + struct timeval now, timeout; + + if (timed_events == NULL) { + return timeval_set(SMBD_SELECT_TIMEOUT, 0); + } + + now = timeval_current(); + timeout = timeval_until(&now, &timed_events->when); + + DEBUG(10, ("timed_events_timeout: %d/%d\n", (int)timeout.tv_sec, + (int)timeout.tv_usec)); + + return timeout; +} + +struct idle_event { + struct timed_event *te; + struct timeval interval; + BOOL (*handler)(const struct timeval *now, void *private_data); + void *private_data; +}; + +static void idle_event_handler(struct timed_event *te, + const struct timeval *now, + void *private_data) +{ + struct idle_event *event = + talloc_get_type_abort(private_data, struct idle_event); + + talloc_free(event->te); + + if (!event->handler(now, event->private_data)) { + /* Don't repeat, delete ourselves */ + talloc_free(event); + return; + } + + event->te = add_timed_event(event, timeval_sum(now, &event->interval), + "idle_event_handler", + idle_event_handler, event); + + /* We can't do much but fail here. */ + SMB_ASSERT(event->te != NULL); +} + +struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx, + struct timeval interval, + BOOL (*handler)(const struct timeval *now, + void *private_data), + void *private_data) +{ + struct idle_event *result; + struct timeval now = timeval_current(); + + result = TALLOC_P(mem_ctx, struct idle_event); + if (result == NULL) { + DEBUG(0, ("talloc failed\n")); + return NULL; + } + + result->interval = interval; + result->handler = handler; + result->private_data = private_data; + + result->te = add_timed_event(result, timeval_sum(&now, &interval), + "idle_event_handler", + idle_event_handler, result); + if (result->te == NULL) { + DEBUG(0, ("add_timed_event failed\n")); + talloc_free(result); + return NULL; + } + + return result; +} + /**************************************************************************** - Do all async processing in here. This includes UDB oplock messages, kernel - oplock messages, change notify events etc. + Do all async processing in here. This includes kernel oplock messages, change + notify events etc. ****************************************************************************/ -static void async_processing(char *buffer, int buffer_len) +static void async_processing(void) { DEBUG(10,("async_processing: Doing async processing.\n")); process_aio_queue(); - /* check for oplock messages (both UDP and kernel) */ - if (receive_local_message(buffer, buffer_len, 1)) { - process_local_message(buffer, buffer_len); - } + process_kernel_oplocks(); - /* Do the aio check again after receive_local_message as it does a select - and may have eaten our signal. */ + /* Do the aio check again after receive_local_message as it does a + select and may have eaten our signal. */ + /* Is this till true? -- vl */ process_aio_queue(); if (got_sig_term) { @@ -339,17 +452,17 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) { fd_set fds; int selrtn; - struct timeval to; - struct timeval *pto; + struct timeval to = timeval_set(SMBD_SELECT_TIMEOUT, 0); int maxfd; smb_read_error = 0; again: - to.tv_sec = timeout / 1000; - to.tv_usec = (timeout % 1000) * 1000; - pto = timeout > 0 ? &to : NULL; + if (timeout >= 0) { + to.tv_sec = timeout / 1000; + to.tv_usec = (timeout % 1000) * 1000; + } /* * Note that this call must be before processing any SMB @@ -358,38 +471,22 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) */ message_dispatch(); - /* - * Check to see if we already have a message on the smb queue. - * If so - copy and return it. - */ - if(smb_oplock_queue != NULL) { - struct pending_message_list *msg = smb_oplock_queue; - memcpy(buffer, msg->buf.data, MIN(buffer_len, msg->buf.length)); - - /* Free the message we just copied. */ - DLIST_REMOVE(smb_oplock_queue, msg); - free_queued_message(msg); - - DEBUG(5,("receive_message_or_smb: returning queued smb message.\n")); - return True; - } - /* * Check to see if we already have a message on the deferred open queue * and it's time to schedule. */ - if(smb_sharing_violation_queue != NULL) { + if(deferred_open_queue != NULL) { BOOL pop_message = False; - struct pending_message_list *msg = smb_sharing_violation_queue; + struct pending_message_list *msg = deferred_open_queue; - if (msg->msg_time.tv_sec == 0 && msg->msg_time.tv_usec == 0) { + if (timeval_is_zero(&msg->end_time)) { pop_message = True; } else { struct timeval tv; SMB_BIG_INT tdif; GetTimeOfDay(&tv); - tdif = usec_time_diff(&msg->msg_time, &tv); + tdif = usec_time_diff(&msg->end_time, &tv); if (tdif <= 0) { /* Timed out. Schedule...*/ pop_message = True; @@ -398,9 +495,8 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) /* Make a more accurate select timeout. */ to.tv_sec = tdif / 1000000; to.tv_usec = tdif % 1000000; - pto = &to; DEBUG(10,("receive_message_or_smb: select with timeout of [%u.%06u]\n", - (unsigned int)pto->tv_sec, (unsigned int)pto->tv_usec )); + (unsigned int)to.tv_sec, (unsigned int)to.tv_usec )); } } @@ -431,7 +527,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) if (oplock_message_waiting(&fds)) { DEBUG(10,("receive_message_or_smb: oplock_message is waiting.\n")); - async_processing(buffer, buffer_len); + async_processing(); /* * After async processing we must go and do the select again, as * the state of the flag in fds for the server file descriptor is @@ -439,18 +535,26 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) */ goto again; } + + { + struct timeval tmp = timed_events_timeout(); + to = timeval_min(&to, &tmp); + if (timeval_is_zero(&to)) { + return True; + } + } FD_SET(smbd_server_fd(),&fds); maxfd = setup_oplock_select_set(&fds); - selrtn = sys_select(MAX(maxfd,smbd_server_fd())+1,&fds,NULL,NULL,pto); + selrtn = sys_select(MAX(maxfd,smbd_server_fd())+1,&fds,NULL,NULL,&to); /* if we get EINTR then maybe we have received an oplock signal - treat this as select returning 1. This is ugly, but is the best we can do until the oplock code knows more about signals */ if (selrtn == -1 && errno == EINTR) { - async_processing(buffer, buffer_len); + async_processing(); /* * After async processing we must go and do the select again, as * the state of the flag in fds for the server file descriptor is @@ -479,7 +583,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) */ if (oplock_message_waiting(&fds)) { - async_processing(buffer, buffer_len); + async_processing(); /* * After async processing we must go and do the select again, as * the state of the flag in fds for the server file descriptor is @@ -518,8 +622,6 @@ BOOL receive_next_smb(char *inbuf, int bufsize, int timeout) void respond_to_all_remaining_local_messages(void) { - char buffer[1024]; - /* * Assert we have no exclusive open oplocks. */ @@ -530,15 +632,7 @@ void respond_to_all_remaining_local_messages(void) return; } - /* - * Keep doing receive_local_message with a 1 ms timeout until - * we have no more messages. - */ - - while(receive_local_message(buffer, sizeof(buffer), 1)) { - /* Deal with oplock break requests from other smbd's. */ - process_local_message(buffer, sizeof(buffer)); - } + process_kernel_oplocks(); return; } @@ -556,8 +650,7 @@ force write permissions on print services. #define TIME_INIT (1<<2) #define CAN_IPC (1<<3) #define AS_GUEST (1<<5) -#define QUEUE_IN_OPLOCK (1<<6) -#define DO_CHDIR (1<<7) +#define DO_CHDIR (1<<6) /* define a list of possible SMB messages and their corresponding @@ -572,19 +665,19 @@ static const struct smb_message_struct { /* 0x00 */ { "SMBmkdir",reply_mkdir,AS_USER | NEED_WRITE}, /* 0x01 */ { "SMBrmdir",reply_rmdir,AS_USER | NEED_WRITE}, -/* 0x02 */ { "SMBopen",reply_open,AS_USER | QUEUE_IN_OPLOCK }, +/* 0x02 */ { "SMBopen",reply_open,AS_USER }, /* 0x03 */ { "SMBcreate",reply_mknew,AS_USER}, /* 0x04 */ { "SMBclose",reply_close,AS_USER | CAN_IPC }, /* 0x05 */ { "SMBflush",reply_flush,AS_USER}, -/* 0x06 */ { "SMBunlink",reply_unlink,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK}, -/* 0x07 */ { "SMBmv",reply_mv,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK}, +/* 0x06 */ { "SMBunlink",reply_unlink,AS_USER | NEED_WRITE }, +/* 0x07 */ { "SMBmv",reply_mv,AS_USER | NEED_WRITE }, /* 0x08 */ { "SMBgetatr",reply_getatr,AS_USER}, /* 0x09 */ { "SMBsetatr",reply_setatr,AS_USER | NEED_WRITE}, /* 0x0a */ { "SMBread",reply_read,AS_USER}, /* 0x0b */ { "SMBwrite",reply_write,AS_USER | CAN_IPC }, /* 0x0c */ { "SMBlock",reply_lock,AS_USER}, /* 0x0d */ { "SMBunlock",reply_unlock,AS_USER}, -/* 0x0e */ { "SMBctemp",reply_ctemp,AS_USER | QUEUE_IN_OPLOCK }, +/* 0x0e */ { "SMBctemp",reply_ctemp,AS_USER }, /* 0x0f */ { "SMBmknew",reply_mknew,AS_USER}, /* 0x10 */ { "SMBchkpth",reply_chkpth,AS_USER}, /* 0x11 */ { "SMBexit",reply_exit,DO_CHDIR}, @@ -611,11 +704,11 @@ static const struct smb_message_struct { /* 0x26 */ { "SMBtranss",NULL,AS_USER | CAN_IPC}, /* 0x27 */ { "SMBioctl",reply_ioctl,0}, /* 0x28 */ { "SMBioctls",NULL,AS_USER}, -/* 0x29 */ { "SMBcopy",reply_copy,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK }, -/* 0x2a */ { "SMBmove",NULL,AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK }, +/* 0x29 */ { "SMBcopy",reply_copy,AS_USER | NEED_WRITE }, +/* 0x2a */ { "SMBmove",NULL,AS_USER | NEED_WRITE }, /* 0x2b */ { "SMBecho",reply_echo,0}, /* 0x2c */ { "SMBwriteclose",reply_writeclose,AS_USER}, -/* 0x2d */ { "SMBopenX",reply_open_and_X,AS_USER | CAN_IPC | QUEUE_IN_OPLOCK }, +/* 0x2d */ { "SMBopenX",reply_open_and_X,AS_USER | CAN_IPC }, /* 0x2e */ { "SMBreadX",reply_read_and_X,AS_USER | CAN_IPC }, /* 0x2f */ { "SMBwriteX",reply_write_and_X,AS_USER | CAN_IPC }, /* 0x30 */ { NULL, NULL, 0 }, @@ -730,12 +823,12 @@ static const struct smb_message_struct { /* 0x9d */ { NULL, NULL, 0 }, /* 0x9e */ { NULL, NULL, 0 }, /* 0x9f */ { NULL, NULL, 0 }, -/* 0xa0 */ { "SMBnttrans", reply_nttrans, AS_USER | CAN_IPC | QUEUE_IN_OPLOCK}, +/* 0xa0 */ { "SMBnttrans", reply_nttrans, AS_USER | CAN_IPC }, /* 0xa1 */ { "SMBnttranss", reply_nttranss, AS_USER | CAN_IPC }, -/* 0xa2 */ { "SMBntcreateX", reply_ntcreate_and_X, AS_USER | CAN_IPC | QUEUE_IN_OPLOCK }, +/* 0xa2 */ { "SMBntcreateX", reply_ntcreate_and_X, AS_USER | CAN_IPC }, /* 0xa3 */ { NULL, NULL, 0 }, /* 0xa4 */ { "SMBntcancel", reply_ntcancel, 0 }, -/* 0xa5 */ { "SMBntrename", reply_ntrename, AS_USER | NEED_WRITE | QUEUE_IN_OPLOCK }, +/* 0xa5 */ { "SMBntrename", reply_ntrename, AS_USER | NEED_WRITE }, /* 0xa6 */ { NULL, NULL, 0 }, /* 0xa7 */ { NULL, NULL, 0 }, /* 0xa8 */ { NULL, NULL, 0 }, @@ -762,7 +855,7 @@ static const struct smb_message_struct { /* 0xbd */ { NULL, NULL, 0 }, /* 0xbe */ { NULL, NULL, 0 }, /* 0xbf */ { NULL, NULL, 0 }, -/* 0xc0 */ { "SMBsplopen",reply_printopen,AS_USER | QUEUE_IN_OPLOCK }, +/* 0xc0 */ { "SMBsplopen",reply_printopen,AS_USER}, /* 0xc1 */ { "SMBsplwr",reply_printwrite,AS_USER}, /* 0xc2 */ { "SMBsplclose",reply_printclose,AS_USER}, /* 0xc3 */ { "SMBsplretq",reply_printqueue,AS_USER}, @@ -871,7 +964,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize pid = sys_getpid(); errno = 0; - set_saved_error_triple(0, 0, NT_STATUS_OK); + set_saved_ntstatus(NT_STATUS_OK); last_message = type; @@ -900,19 +993,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n",smb_fn_name(type),(int)pid,(unsigned long)conn)); smb_dump(smb_fn_name(type), 1, inbuf, size); - if(global_oplock_break) { - if(flags & QUEUE_IN_OPLOCK) { - /* - * Queue this message as we are the process of an oplock break. - */ - - DEBUG( 2, ( "switch_message: queueing message due to being in " ) ); - DEBUGADD( 2, ( "oplock break state.\n" ) ); - - push_oplock_pending_smb_message( inbuf, size ); - return -1; - } - } /* Ensure this value is replaced in the incoming packet. */ SSVAL(inbuf,smb_uid,session_tag); @@ -1289,6 +1369,7 @@ static int setup_select_timeout(void) select_timeout *= 1000; t = change_notify_timeout(); + DEBUG(10, ("change_notify_timeout: %d\n", t)); if (t != -1) select_timeout = MIN(select_timeout, t*1000); @@ -1302,7 +1383,7 @@ static int setup_select_timeout(void) Check if services need reloading. ****************************************************************************/ -void check_reload(int t) +void check_reload(time_t t) { static pid_t mypid = 0; static time_t last_smb_conf_reload_time = 0; @@ -1644,6 +1725,8 @@ void smbd_process(void) num_smbs = 0; /* Reset smb counter. */ } + run_events(); + #if defined(DEVELOPER) clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); #endif -- cgit From 0af1500fc0bafe61019f1b2ab1d9e1d369221240 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Feb 2006 22:19:41 +0000 Subject: r13316: Let the carnage begin.... Sync with trunk as off r13315 (This used to be commit 17e63ac4ed8325c0d44fe62b2442449f3298559f) --- source3/smbd/process.c | 115 ++----------------------------------------------- 1 file changed, 4 insertions(+), 111 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 0b7b94cce2..d646ebe02d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -223,115 +223,6 @@ BOOL push_deferred_smb_message(uint16 mid, private_data, priv_len); } -static struct timed_event *timed_events; - -struct timed_event { - struct timed_event *next, *prev; - struct timeval when; - const char *event_name; - void (*handler)(struct timed_event *te, - const struct timeval *now, - void *private_data); - void *private_data; -}; - -static int timed_event_destructor(void *p) -{ - struct timed_event *te = talloc_get_type_abort(p, struct timed_event); - DEBUG(10, ("Destroying timed event %lx \"%s\"\n", (unsigned long)te, - te->event_name)); - DLIST_REMOVE(timed_events, te); - return 0; -} - -/**************************************************************************** - Schedule a function for future calling, cancel with talloc_free(). - It's the responsibility of the handler to call talloc_free() on the event - handed to it. -****************************************************************************/ - -struct timed_event *add_timed_event(TALLOC_CTX *mem_ctx, - struct timeval when, - const char *event_name, - void (*handler)(struct timed_event *te, - const struct timeval *now, - void *private_data), - void *private_data) -{ - struct timed_event *te, *last_te, *cur_te; - - te = TALLOC_P(mem_ctx, struct timed_event); - if (te == NULL) { - DEBUG(0, ("talloc failed\n")); - return NULL; - } - - te->when = when; - te->event_name = event_name; - te->handler = handler; - te->private_data = private_data; - - /* keep the list ordered */ - last_te = NULL; - for (cur_te = timed_events; cur_te; cur_te = cur_te->next) { - /* if the new event comes before the current one break */ - if (!timeval_is_zero(&cur_te->when) && - timeval_compare(&te->when, &cur_te->when) < 0) { - break; - } - last_te = cur_te; - } - - DLIST_ADD_AFTER(timed_events, te, last_te); - talloc_set_destructor(te, timed_event_destructor); - - DEBUG(10, ("Added timed event \"%s\": %lx\n", event_name, - (unsigned long)te)); - return te; -} - -static void run_events(void) -{ - struct timeval now; - - if (timed_events == NULL) { - /* No syscall if there are no events */ - DEBUG(10, ("run_events: No events\n")); - return; - } - - GetTimeOfDay(&now); - - if (timeval_compare(&now, &timed_events->when) < 0) { - /* Nothing to do yet */ - DEBUG(10, ("run_events: Nothing to do\n")); - return; - } - - DEBUG(10, ("Running event \"%s\" %lx\n", timed_events->event_name, - (unsigned long)timed_events)); - - timed_events->handler(timed_events, &now, timed_events->private_data); - return; -} - -struct timeval timed_events_timeout(void) -{ - struct timeval now, timeout; - - if (timed_events == NULL) { - return timeval_set(SMBD_SELECT_TIMEOUT, 0); - } - - now = timeval_current(); - timeout = timeval_until(&now, &timed_events->when); - - DEBUG(10, ("timed_events_timeout: %d/%d\n", (int)timeout.tv_sec, - (int)timeout.tv_usec)); - - return timeout; -} - struct idle_event { struct timed_event *te; struct timeval interval; @@ -537,8 +428,10 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) } { - struct timeval tmp = timed_events_timeout(); - to = timeval_min(&to, &tmp); + struct timeval tmp; + struct timeval *tp = get_timed_events_timeout(&tmp,SMBD_SELECT_TIMEOUT); + + to = timeval_min(&to, tp); if (timeval_is_zero(&to)) { return True; } -- cgit From 8fbdd112b2c69a54d05807163bfc52b34f4d0424 Mon Sep 17 00:00:00 2001 From: James Peach Date: Mon, 13 Feb 2006 04:07:15 +0000 Subject: r13482: Push the FAM notification file descriptor into the select set to avoid unnecessary polling. (This used to be commit 1dce945ccbba25092cf54890301c8f78f8aede33) --- source3/smbd/process.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d646ebe02d..2f19f909f2 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -283,7 +283,7 @@ struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx, return result; } - + /**************************************************************************** Do all async processing in here. This includes kernel oplock messages, change notify events etc. @@ -318,6 +318,20 @@ static void async_processing(void) } } +/**************************************************************************** + Add a fd to the set we will be select(2)ing on. +****************************************************************************/ + +static int select_on_fd(int fd, int maxfd, fd_set *fds) +{ + if (fd != -1) { + FD_SET(fd, fds); + maxfd = MAX(maxfd, fd); + } + + return maxfd; +} + /**************************************************************************** Do a select on an two fd's - with timeout. @@ -344,7 +358,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) fd_set fds; int selrtn; struct timeval to = timeval_set(SMBD_SELECT_TIMEOUT, 0); - int maxfd; + int maxfd = 0; smb_read_error = 0; @@ -437,10 +451,11 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) } } - FD_SET(smbd_server_fd(),&fds); - maxfd = setup_oplock_select_set(&fds); + maxfd = select_on_fd(smbd_server_fd(), maxfd, &fds); + maxfd = select_on_fd(change_notify_fd(), maxfd, &fds); + maxfd = select_on_fd(oplock_notify_fd(), maxfd, &fds); - selrtn = sys_select(MAX(maxfd,smbd_server_fd())+1,&fds,NULL,NULL,&to); + selrtn = sys_select(maxfd+1,&fds,NULL,NULL,&to); /* if we get EINTR then maybe we have received an oplock signal - treat this as select returning 1. This is ugly, but -- cgit From 5c149702b0885db8d63f189f4bba0e17fdaad7a4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Feb 2006 23:00:39 +0000 Subject: r13498: Fix the kernel oplocks code for IRIX. Should fix #3515. Jeremy. (This used to be commit 006cf9c3654e7f18e01b75a5fe87798df862d26a) --- source3/smbd/process.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2f19f909f2..9d35252e28 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -289,13 +289,13 @@ struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx, notify events etc. ****************************************************************************/ -static void async_processing(void) +static void async_processing(fd_set *pfds) { DEBUG(10,("async_processing: Doing async processing.\n")); process_aio_queue(); - process_kernel_oplocks(); + process_kernel_oplocks(pfds); /* Do the aio check again after receive_local_message as it does a select and may have eaten our signal. */ @@ -432,7 +432,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) if (oplock_message_waiting(&fds)) { DEBUG(10,("receive_message_or_smb: oplock_message is waiting.\n")); - async_processing(); + async_processing(&fds); /* * After async processing we must go and do the select again, as * the state of the flag in fds for the server file descriptor is @@ -462,7 +462,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) is the best we can do until the oplock code knows more about signals */ if (selrtn == -1 && errno == EINTR) { - async_processing(); + async_processing(&fds); /* * After async processing we must go and do the select again, as * the state of the flag in fds for the server file descriptor is @@ -491,7 +491,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) */ if (oplock_message_waiting(&fds)) { - async_processing(); + async_processing(&fds); /* * After async processing we must go and do the select again, as * the state of the flag in fds for the server file descriptor is @@ -540,7 +540,7 @@ void respond_to_all_remaining_local_messages(void) return; } - process_kernel_oplocks(); + process_kernel_oplocks(NULL); return; } -- cgit From fb5362c069b5b6548478b2217a0519c56d856705 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 20 Feb 2006 17:59:58 +0000 Subject: r13571: Replace all calls to talloc_free() with thye TALLOC_FREE() macro which sets the freed pointer to NULL. (This used to be commit b65be8874a2efe5a4b167448960a4fcf6bd995e2) --- source3/smbd/process.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 9d35252e28..a50323887a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -91,7 +91,7 @@ static BOOL push_queued_message(char *buf, int msg_len, msg->buf = data_blob_talloc(msg, buf, msg_len); if(msg->buf.data == NULL) { DEBUG(0,("push_message: malloc fail (2)\n")); - talloc_free(msg); + TALLOC_FREE(msg); return False; } @@ -103,7 +103,7 @@ static BOOL push_queued_message(char *buf, int msg_len, private_len); if (msg->private_data.data == NULL) { DEBUG(0,("push_message: malloc fail (3)\n")); - talloc_free(msg); + TALLOC_FREE(msg); return False; } } @@ -131,7 +131,7 @@ void remove_deferred_open_smb_message(uint16 mid) (unsigned int)mid, (unsigned int)pml->buf.length )); DLIST_REMOVE(deferred_open_queue, pml); - talloc_free(pml); + TALLOC_FREE(pml); return; } } @@ -237,11 +237,11 @@ static void idle_event_handler(struct timed_event *te, struct idle_event *event = talloc_get_type_abort(private_data, struct idle_event); - talloc_free(event->te); + TALLOC_FREE(event->te); if (!event->handler(now, event->private_data)) { /* Don't repeat, delete ourselves */ - talloc_free(event); + TALLOC_FREE(event); return; } @@ -277,7 +277,7 @@ struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx, idle_event_handler, result); if (result->te == NULL) { DEBUG(0, ("add_timed_event failed\n")); - talloc_free(result); + TALLOC_FREE(result); return NULL; } @@ -1623,8 +1623,8 @@ void smbd_process(void) errno = 0; /* free up temporary memory */ - lp_talloc_free(); - main_loop_talloc_free(); + lp_TALLOC_FREE(); + main_loop_TALLOC_FREE(); /* Did someone ask for immediate checks on things like blocking locks ? */ if (select_timeout == 0) { -- cgit From ff122b308bf4ad9115ebfe1d292051c3c5ecbb78 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 12 Mar 2006 04:18:43 +0000 Subject: r14229: Something Coverity hasn't caught (yet) but I've gotten sensitive to null derefs. get_timed_events_timeout() can potentially return NULL. Cope with this. Jeremy. (This used to be commit 04838078723613628b298b7a87622df30432cf64) --- source3/smbd/process.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index a50323887a..40d6818f3f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -445,9 +445,11 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) struct timeval tmp; struct timeval *tp = get_timed_events_timeout(&tmp,SMBD_SELECT_TIMEOUT); - to = timeval_min(&to, tp); - if (timeval_is_zero(&to)) { - return True; + if (tp) { + to = timeval_min(&to, tp); + if (timeval_is_zero(&to)) { + return True; + } } } -- cgit From 49ecd176ee4bb2c4acffa0db548c33d6c90dcad7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 19 Mar 2006 11:11:37 +0000 Subject: r14559: Oplocks have changed, process_smb can be static again (This used to be commit 19e9bc03f81d8d000b683cf5c5f478ba25ddeb0d) --- source3/smbd/process.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 40d6818f3f..7ec08cb4a7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1072,11 +1072,10 @@ set. Ignoring max smbd restriction.\n")); } /**************************************************************************** - Process an smb from the client - split out from the smbd_process() code so - it can be used by the oplock break code. + Process an smb from the client ****************************************************************************/ -void process_smb(char *inbuf, char *outbuf) +static void process_smb(char *inbuf, char *outbuf) { static int trans_num; int msg_type = CVAL(inbuf,0); -- cgit From 4fa555980070d78b39711ef21d77628d26055bc2 Mon Sep 17 00:00:00 2001 From: James Peach Date: Tue, 4 Apr 2006 00:27:50 +0000 Subject: r14898: This change is an attempt to improve the quality of the information that is produced when a process exits abnormally. First, we coalesce the core dumping code so that we greatly improve our odds of being able to produce a core file, even in the case of a memory fault. I've removed duplicates of dump_core() and split it in two to reduce the amount of work needed to actually do the dump. Second, we refactor the exit_server code path to always log an explanation and a stack trace. My goal is to always produce enough log information for us to be able to explain any server exit, though there is a risk that this could produce too much log information on a flaky network. Finally, smbcontrol has gained a smbd fault injection operation to test the changes above. This is only enabled for developer builds. (This used to be commit 56bc02d64498eb3faf89f0c5452b9299daea8e95) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 7ec08cb4a7..40d26f7672 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -303,7 +303,7 @@ static void async_processing(fd_set *pfds) process_aio_queue(); if (got_sig_term) { - exit_server("Caught TERM signal"); + exit_server_cleanly(); } /* check for async change notify events */ -- cgit From 22dbd67708f1651a2341d70ce576fac360affccf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Apr 2006 15:33:04 +0000 Subject: r15018: Merge Volker's ipc/trans2/nttrans changes over into 3.0. Also merge the new POSIX lock code - this is not enabled unless -DDEVELOPER is defined. This doesn't yet map onto underlying system POSIX locks. Updates vfs to allow lock queries. Jeremy. (This used to be commit 08e52ead03304ff04229e1bfe544ff40e2564fc7) --- source3/smbd/process.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 40d26f7672..cdeccab5e8 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -505,22 +505,27 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) return receive_smb(smbd_server_fd(), buffer, 0); } -/**************************************************************************** -Get the next SMB packet, doing the local message processing automatically. -****************************************************************************/ +/* + * Only allow 5 outstanding trans requests. We're allocating memory, so + * prevent a DoS. + */ -BOOL receive_next_smb(char *inbuf, int bufsize, int timeout) +NTSTATUS allow_new_trans(struct trans_state *list, int mid) { - BOOL got_keepalive; - BOOL ret; + int count = 0; + for (; list != NULL; list = list->next) { - do { - ret = receive_message_or_smb(inbuf,bufsize,timeout); - - got_keepalive = (ret && (CVAL(inbuf,0) == SMBkeepalive)); - } while (ret && got_keepalive); + if (list->mid == mid) { + return NT_STATUS_INVALID_PARAMETER; + } + + count += 1; + } + if (count > 5) { + return NT_STATUS_INSUFFICIENT_RESOURCES; + } - return ret; + return NT_STATUS_OK; } /**************************************************************************** @@ -611,7 +616,7 @@ static const struct smb_message_struct { /* 0x23 */ { "SMBgetattrE",reply_getattrE,AS_USER }, /* 0x24 */ { "SMBlockingX",reply_lockingX,AS_USER }, /* 0x25 */ { "SMBtrans",reply_trans,AS_USER | CAN_IPC }, -/* 0x26 */ { "SMBtranss",NULL,AS_USER | CAN_IPC}, +/* 0x26 */ { "SMBtranss",reply_transs,AS_USER | CAN_IPC}, /* 0x27 */ { "SMBioctl",reply_ioctl,0}, /* 0x28 */ { "SMBioctls",NULL,AS_USER}, /* 0x29 */ { "SMBcopy",reply_copy,AS_USER | NEED_WRITE }, -- cgit From eecdc6c956d983be2c139843e2730136d3273fe9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Apr 2006 22:47:09 +0000 Subject: r15022: Fix core dumps on normal server exit. Jeremy. (This used to be commit 13c3abf03187f84874b5754b54de5d3fe2dea188) --- source3/smbd/process.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index cdeccab5e8..b2634e2653 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -303,7 +303,7 @@ static void async_processing(fd_set *pfds) process_aio_queue(); if (got_sig_term) { - exit_server_cleanly(); + exit_server_cleanly("termination signal"); } /* check for async change notify events */ @@ -886,7 +886,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* Make sure this is an SMB packet. smb_size contains NetBIOS header so subtract 4 from it. */ if ((strncmp(smb_base(inbuf),"\377SMB",4) != 0) || (size < (smb_size - 4))) { DEBUG(2,("Non-SMB packet of length %d. Terminating server\n",smb_len(inbuf))); - exit_server("Non-SMB packet"); + exit_server_cleanly("Non-SMB packet"); return(-1); } @@ -1100,7 +1100,7 @@ static 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() ) ); (void)send_smb(smbd_server_fd(),(char *)buf); - exit_server("connection denied"); + exit_server_cleanly("connection denied"); } } @@ -1122,7 +1122,7 @@ static void process_smb(char *inbuf, char *outbuf) DEBUG(0,("ERROR: Invalid message response size! %d %d\n", nread, smb_len(outbuf))); } else if (!send_smb(smbd_server_fd(),outbuf)) { - exit_server("process_smb: send_smb failed."); + exit_server_cleanly("process_smb: send_smb failed."); } } trans_num++; -- cgit From fc13f284179df5f3f3a1d475bf84da21dc89c970 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Apr 2006 01:43:13 +0000 Subject: r15030: On a performace hunt... Remove as many extraneous memset's as possible. Jeremy. (This used to be commit 1217ed392b75aa8bfefa9c3f1ec5fa3bba841ee0) --- source3/smbd/process.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index b2634e2653..c0a43e99dd 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1160,20 +1160,16 @@ void remove_from_common_flags2(uint32 v) void construct_reply_common(char *inbuf,char *outbuf) { - memset(outbuf,'\0',smb_size); - - set_message(outbuf,0,0,True); - SCVAL(outbuf,smb_com,CVAL(inbuf,smb_com)); + set_message(outbuf,0,0,False); - memcpy(outbuf+4,inbuf+4,4); - SCVAL(outbuf,smb_rcls,SMB_SUCCESS); - SCVAL(outbuf,smb_reh,0); + SCVAL(outbuf,smb_com,CVAL(inbuf,smb_com)); + SIVAL(outbuf,smb_rcls,0); SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); SSVAL(outbuf,smb_flg2, (SVAL(inbuf,smb_flg2) & FLAGS2_UNICODE_STRINGS) | common_flags2); + memset(outbuf+smb_pidhigh,'\0',(smb_tid-smb_pidhigh)); - SSVAL(outbuf,smb_err,SMB_SUCCESS); SSVAL(outbuf,smb_tid,SVAL(inbuf,smb_tid)); SSVAL(outbuf,smb_pid,SVAL(inbuf,smb_pid)); SSVAL(outbuf,smb_uid,SVAL(inbuf,smb_uid)); -- cgit From cc203f3e59840b75fbb42a53d36b717a57268c2f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 14 Apr 2006 03:55:42 +0000 Subject: r15084: Try and squeeze more out of the non-read/write code path. Jeremy. (This used to be commit 23dcff4d50d1d35b7ddee0d0cb79c16a312f179c) --- source3/smbd/process.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c0a43e99dd..ba14e57c54 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -357,7 +357,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) { fd_set fds; int selrtn; - struct timeval to = timeval_set(SMBD_SELECT_TIMEOUT, 0); + struct timeval to; int maxfd = 0; smb_read_error = 0; @@ -367,6 +367,9 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) if (timeout >= 0) { to.tv_sec = timeout / 1000; to.tv_usec = (timeout % 1000) * 1000; + } else { + to.tv_sec = SMBD_SELECT_TIMEOUT; + to.tv_usec = 0; } /* @@ -441,14 +444,20 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) goto again; } + /* + * Are there any timed events waiting ? If so, ensure we don't + * select for longer than it would take to wait for them. + */ + { struct timeval tmp; - struct timeval *tp = get_timed_events_timeout(&tmp,SMBD_SELECT_TIMEOUT); + struct timeval *tp = get_timed_events_timeout(&tmp); if (tp) { to = timeval_min(&to, tp); if (timeval_is_zero(&to)) { - return True; + /* Process a timed event now... */ + run_events(); } } } -- cgit From 010c725b36feb1a234dce9f40b95ae5869058698 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 15 Apr 2006 04:07:10 +0000 Subject: r15088: Remove all time() and gettimeofday() calls out of the mainline packet processing code. Only do these when needed (ie. in the idle timeout code). We drop an unneccessary global here too. Jeremy. (This used to be commit 8272a5ab0605fcf95527143c4f909aa1008e5b94) --- source3/smbd/process.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ba14e57c54..aaf98203a2 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -26,8 +26,6 @@ extern int keepalive; extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; -struct timeval smb_last_time; - static char *InBuffer = NULL; static char *OutBuffer = NULL; static char *current_inbuf = NULL; @@ -1011,8 +1009,6 @@ static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) int outsize = 0; int msg_type = CVAL(inbuf,0); - GetTimeOfDay(&smb_last_time); - chain_size = 0; file_chain_reset(); reset_chain_p(); -- cgit From b3a5633de0dafacd3532fa132814739b0d6c84d4 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 7 May 2006 17:33:10 +0000 Subject: r15495: current_user_info is not referenced in process.c (This used to be commit 8cedbbfbcf137b6a0c0323572982e9cb25648b0b) --- source3/smbd/process.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index aaf98203a2..440d0ac0a5 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -43,7 +43,6 @@ int max_send = BUFFER_SIZE; int max_recv = BUFFER_SIZE; extern int last_message; -extern userdom_struct current_user_info; extern int smb_read_error; SIG_ATOMIC_T reload_after_sighup = 0; SIG_ATOMIC_T got_sig_term = 0; -- cgit From ce61fb21d948bd8e3c7733d542f8ecae1390cbfc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 20 Jun 2006 02:38:28 +0000 Subject: r16397: Fix Klocwork #11767 and drasticly simplify the logic in smbd/process.c. All interested (Volker, Jerry, James etc). PLEASE REVIEW THIS CHANGE. The logic should be identical but *much* easier to follow and change (and shouldn't confuse Klockwork :-). Jeremy. (This used to be commit d357f8b33594472ffa78d0a112accccc2a8b1fe7) --- source3/smbd/process.c | 74 ++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 38 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 440d0ac0a5..b3ce49360d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -567,10 +567,10 @@ are used by some brain-dead clients when printing, and I don't want to force write permissions on print services. */ #define AS_USER (1<<0) -#define NEED_WRITE (1<<1) +#define NEED_WRITE (1<<1) /* Must be paired with AS_USER */ #define TIME_INIT (1<<2) -#define CAN_IPC (1<<3) -#define AS_GUEST (1<<5) +#define CAN_IPC (1<<3) /* Must be paired with AS_USER */ +#define AS_GUEST (1<<5) /* Must *NOT* be paired with AS_USER */ #define DO_CHDIR (1<<6) /* @@ -932,48 +932,46 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize user_struct *vuser = NULL; last_session_tag = session_tag; - if(session_tag != UID_FIELD_INVALID) + if(session_tag != UID_FIELD_INVALID) { vuser = get_valid_user_struct(session_tag); - if(vuser != NULL) - set_current_user_info(&vuser->user); - } - - /* does this protocol need to be run as root? */ - if (!(flags & AS_USER)) - change_to_root_user(); - - /* does this protocol need a valid tree connection? */ - if ((flags & AS_USER) && !conn) { - /* Amazingly, the error code depends on the command (from Samba4). */ - if (type == SMBntcreateX) { - return ERROR_NT(NT_STATUS_INVALID_HANDLE); - } else { - return ERROR_DOS(ERRSRV, ERRinvnid); + if (vuser) { + set_current_user_info(&vuser->user); + } } } + /* Does this call need to be run as the connected user? */ + if (flags & AS_USER) { + + /* Does this call need a valid tree connection? */ + if (!conn) { + /* Amazingly, the error code depends on the command (from Samba4). */ + if (type == SMBntcreateX) { + return ERROR_NT(NT_STATUS_INVALID_HANDLE); + } else { + return ERROR_DOS(ERRSRV, ERRinvnid); + } + } - /* does this protocol need to be run as the connected user? */ - if ((flags & AS_USER) && !change_to_user(conn,session_tag)) { - if (flags & AS_GUEST) - flags &= ~AS_USER; - else + if (!change_to_user(conn,session_tag)) { return(ERROR_FORCE_DOS(ERRSRV,ERRbaduid)); - } + } - /* this code is to work around a bug is MS client 3 without - introducing a security hole - it needs to be able to do - print queue checks as guest if it isn't logged in properly */ - if (flags & AS_USER) - flags &= ~AS_GUEST; + /* All NEED_WRITE and CAN_IPC flags must also have AS_USER. */ - /* does it need write permission? */ - if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) - return(ERROR_DOS(ERRSRV,ERRaccess)); + /* Does it need write permission? */ + if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) { + return(ERROR_DOS(ERRSRV,ERRaccess)); + } - /* ipc services are limited */ - if (IS_IPC(conn) && (flags & AS_USER) && !(flags & CAN_IPC)) - return(ERROR_DOS(ERRSRV,ERRaccess)); + /* IPC services are limited */ + if (IS_IPC(conn) && !(flags & CAN_IPC)) { + return(ERROR_DOS(ERRSRV,ERRaccess)); + } + } else { + /* This call needs to be run as root */ + change_to_root_user(); + } /* load service specific parameters */ if (conn) { @@ -985,8 +983,9 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* does this protocol need to be run as guest? */ if ((flags & AS_GUEST) && (!change_to_guest() || - !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) + !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) { return(ERROR_DOS(ERRSRV,ERRaccess)); + } current_inbuf = inbuf; /* In case we need to defer this message in open... */ outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); @@ -997,7 +996,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize return(outsize); } - /**************************************************************************** Construct a reply to the incoming packet. ****************************************************************************/ -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/smbd/process.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index b3ce49360d..ce352adfd7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -21,7 +21,7 @@ #include "includes.h" -extern uint16 global_smbpid; +uint16 global_smbpid; extern int keepalive; extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; @@ -172,7 +172,6 @@ BOOL open_was_deferred(uint16 mid) for (pml = deferred_open_queue; pml; pml = pml->next) { if (SVAL(pml->buf.data,smb_mid) == mid) { - set_saved_ntstatus(NT_STATUS_OK); return True; } } @@ -459,11 +458,20 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) } } - maxfd = select_on_fd(smbd_server_fd(), maxfd, &fds); - maxfd = select_on_fd(change_notify_fd(), maxfd, &fds); - maxfd = select_on_fd(oplock_notify_fd(), maxfd, &fds); + { + int sav; + START_PROFILE(smbd_idle); + + maxfd = select_on_fd(smbd_server_fd(), maxfd, &fds); + maxfd = select_on_fd(change_notify_fd(), maxfd, &fds); + maxfd = select_on_fd(oplock_notify_fd(), maxfd, &fds); - selrtn = sys_select(maxfd+1,&fds,NULL,NULL,&to); + selrtn = sys_select(maxfd+1,&fds,NULL,NULL,&to); + sav = errno; + + END_PROFILE(smbd_idle); + errno = sav; + } /* if we get EINTR then maybe we have received an oplock signal - treat this as select returning 1. This is ugly, but @@ -885,7 +893,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize pid = sys_getpid(); errno = 0; - set_saved_ntstatus(NT_STATUS_OK); last_message = type; @@ -954,7 +961,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize } if (!change_to_user(conn,session_tag)) { - return(ERROR_FORCE_DOS(ERRSRV,ERRbaduid)); + return(ERROR_NT(NT_STATUS_DOS(ERRSRV,ERRbaduid))); } /* All NEED_WRITE and CAN_IPC flags must also have AS_USER. */ -- cgit From b737f26764cce935d9482335ece11c71a96720f4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 18 Jul 2006 01:05:51 +0000 Subject: r17105: Fix the race Volker found - we had a non-locked region between detecting a pending lock was needed and when we added the blocking lock record. Make sure that we hold the lock over all this period. Removed the old code for doing blocking locks on SMB requests that never block (the old SMBlock and friends). Discovered something interesting about the strange NT_STATUS_FILE_LOCK_CONFLICT return. If we asked for a lock with zero timeout, and we got an error of NT_STATUS_FILE_LOCK_CONFLICT, treat it as though it was a blocking lock with a timeout of 150 - 300ms. This only happens when timeout is sent as zero and can be seen quite clearly in ethereal. This is the real replacement for old do_lock_spin() code. Re-worked the blocking lock select timeout to correctly use milliseconds instead of the old second level resolution (far too coarse for this work). Jeremy. (This used to be commit b81d6d1ae95a3d3e449dde629884b565eac289d9) --- source3/smbd/process.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ce352adfd7..f8c66d93ea 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1276,7 +1276,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) } /**************************************************************************** - Setup the needed select timeout. + Setup the needed select timeout in milliseconds. ****************************************************************************/ static int setup_select_timeout(void) @@ -1284,16 +1284,17 @@ static int setup_select_timeout(void) int select_timeout; int t; - select_timeout = blocking_locks_timeout(SMBD_SELECT_TIMEOUT); - select_timeout *= 1000; + select_timeout = blocking_locks_timeout_ms(SMBD_SELECT_TIMEOUT*1000); t = change_notify_timeout(); DEBUG(10, ("change_notify_timeout: %d\n", t)); - if (t != -1) + if (t != -1) { select_timeout = MIN(select_timeout, t*1000); + } - if (print_notify_messages_pending()) + if (print_notify_messages_pending()) { select_timeout = MIN(select_timeout, 1000); + } return select_timeout; } @@ -1482,7 +1483,7 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); * Check to see if we have any blocking locks * outstanding on the queue. */ - process_blocking_lock_queue(t); + process_blocking_lock_queue(); /* update printer queue caches if necessary */ -- cgit From 0be131725ff90e48d4f9696b80b35b740575fb2c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 16 Aug 2006 10:36:19 +0000 Subject: r17569: Make 'max smbd processes' more robust. Counting on the child to decrement a tdb entry is not the most reliable way to count children correctly. This increments the number of children after a fork and decrements it upon SIGCLD. I'm keeping a list of children just for consistency checks, so that we at least get a debug level 0 message if something goes wrong. Volker (This used to be commit eb45de167d24d07a218307ec5a48c0029ec097c6) --- source3/smbd/process.c | 58 ++------------------------------------------------ 1 file changed, 2 insertions(+), 56 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f8c66d93ea..a202c1fa87 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1031,60 +1031,6 @@ static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) return(outsize); } -/**************************************************************************** - Keep track of the number of running smbd's. This functionality is used to - 'hard' limit Samba overhead on resource constrained systems. -****************************************************************************/ - -static BOOL process_count_update_successful = False; - -static int32 increment_smbd_process_count(void) -{ - int32 total_smbds; - - if (lp_max_smbd_processes()) { - total_smbds = 0; - if (tdb_change_int32_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, 1) == -1) - return 1; - process_count_update_successful = True; - return total_smbds + 1; - } - return 1; -} - -void decrement_smbd_process_count(void) -{ - int32 total_smbds; - - if (lp_max_smbd_processes() && process_count_update_successful) { - total_smbds = 1; - tdb_change_int32_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, -1); - } -} - -static BOOL smbd_process_limit(void) -{ - int32 total_smbds; - - if (lp_max_smbd_processes()) { - - /* Always add one to the smbd process count, as exit_server() always - * subtracts one. - */ - - if (!conn_tdb_ctx()) { - DEBUG(0,("smbd_process_limit: max smbd processes parameter set with status parameter not \ -set. Ignoring max smbd restriction.\n")); - return False; - } - - total_smbds = increment_smbd_process_count(); - return total_smbds > lp_max_smbd_processes(); - } - else - return False; -} - /**************************************************************************** Process an smb from the client ****************************************************************************/ @@ -1103,8 +1049,8 @@ static void process_smb(char *inbuf, char *outbuf) deny parameters before doing any parsing of the packet passed to us by the client. This prevents attacks on our parsing code from hosts not in the hosts allow list */ - if (smbd_process_limit() || - !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1))) { + if (!check_access(smbd_server_fd(), lp_hostsallow(-1), + lp_hostsdeny(-1))) { /* send a negative session response "not listening on calling name" */ static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; DEBUG( 1, ( "Connection denied from %s\n", client_addr() ) ); -- cgit From 258a465e20e007a30043220367d17ecfc87b4f90 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 18 Sep 2006 07:52:16 +0000 Subject: r18605: sync dlinklist.h with samba4, that means DLIST_ADD_END() and DLIST_DEMOTE() now take the type of the tmp pointer not the tmp pointer itself anymore. metze (This used to be commit 2f58645b7094e81dff3734f11aa183ea2ab53d2d) --- source3/smbd/process.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index a202c1fa87..cf61e16a15 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -75,7 +75,6 @@ static BOOL push_queued_message(char *buf, int msg_len, struct timeval end_time, char *private_data, size_t private_len) { - struct pending_message_list *tmp_msg; struct pending_message_list *msg; msg = TALLOC_ZERO_P(NULL, struct pending_message_list); @@ -105,7 +104,7 @@ static BOOL push_queued_message(char *buf, int msg_len, } } - DLIST_ADD_END(deferred_open_queue, msg, tmp_msg); + DLIST_ADD_END(deferred_open_queue, msg, struct pending_message_list *); DEBUG(10,("push_message: pushed message length %u on " "deferred_open_queue\n", (unsigned int)msg_len)); -- cgit From ab7fc62edfb32422bf95dbf358f6ee5d94e27a34 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 31 Dec 2006 10:08:52 +0000 Subject: r20432: Apply some const (This used to be commit 22163fee595251d4ea92279d88a1e8525188c620) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index cf61e16a15..28c2cd65dd 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1112,7 +1112,7 @@ void remove_from_common_flags2(uint32 v) common_flags2 &= ~v; } -void construct_reply_common(char *inbuf,char *outbuf) +void construct_reply_common(const char *inbuf, char *outbuf) { set_message(outbuf,0,0,False); -- cgit From 7a915ec3a61b74b07564d93112a3fbc87970c48d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 12 Jan 2007 09:29:44 +0000 Subject: r20700: In the main processing loop we select() on the fam socket. If it fires, it might be possible that we hang in the receive_smb() although that socket is not the reason for the select() to return. This immediately reacts to the fam socket to become readable, and goes into the select loop again. This fixes delays in files showing up in Windows. Jeremy, James please review this and merge to 3_0_24 if appropriate. Thanks, Volker (This used to be commit c846153b2ed2f9aca82491888e391ccbe239e88a) --- source3/smbd/process.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 28c2cd65dd..ecb33453c5 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -514,6 +514,19 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) */ goto again; } + + if ((change_notify_fd() >= 0) && FD_ISSET(change_notify_fd(), &fds)) { + + process_pending_change_notify_queue((time_t)0); + + /* + * Same comment as for oplock processing applies here. We + * might have done I/O on the client socket. + */ + + goto again; + } + return receive_smb(smbd_server_fd(), buffer, 0); } -- cgit From ab46f9cdd232cc08b4c2f57c3fe7add652f6ce38 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 13 Jan 2007 22:10:18 +0000 Subject: r20742: Rename chkpth -> checkpath for sanity's sake :-). Start removing unneeded "BOOL ok" from this reply.c (this logic is old, old, old..... :-). Jeremy. (This used to be commit 3d52268095c605a80dfcd371769198a332baa0a5) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ecb33453c5..929471a48c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -620,7 +620,7 @@ static const struct smb_message_struct { /* 0x0d */ { "SMBunlock",reply_unlock,AS_USER}, /* 0x0e */ { "SMBctemp",reply_ctemp,AS_USER }, /* 0x0f */ { "SMBmknew",reply_mknew,AS_USER}, -/* 0x10 */ { "SMBchkpth",reply_chkpth,AS_USER}, +/* 0x10 */ { "SMBcheckpath",reply_checkpath,AS_USER}, /* 0x11 */ { "SMBexit",reply_exit,DO_CHDIR}, /* 0x12 */ { "SMBlseek",reply_lseek,AS_USER}, /* 0x13 */ { "SMBlockread",reply_lockread,AS_USER}, -- cgit From bf219447a35d86913c1a643b66d993986a651360 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 17 Jan 2007 12:59:14 +0000 Subject: r20846: Before this gets out of control... This add a struct event_context and infrastructure for fd events to smbd. This is step zero to import lib/events. Jeremy, I rely on you to watch the change in receive_message_or_smb() closely. For the normal code path this should be the only relevant change. The rest is either not yet used or is cosmetic. Volker (This used to be commit cd07f93a8aecb24c056e33b1ad3447a41959810f) --- source3/smbd/process.c | 65 +++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 27 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 929471a48c..2a52da12b3 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -225,7 +225,8 @@ struct idle_event { void *private_data; }; -static void idle_event_handler(struct timed_event *te, +static void idle_event_handler(struct event_context *ctx, + struct timed_event *te, const struct timeval *now, void *private_data) { @@ -240,7 +241,8 @@ static void idle_event_handler(struct timed_event *te, return; } - event->te = add_timed_event(event, timeval_sum(now, &event->interval), + event->te = event_add_timed(smbd_event_context(), event, + timeval_sum(now, &event->interval), "idle_event_handler", idle_event_handler, event); @@ -267,11 +269,12 @@ struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx, result->handler = handler; result->private_data = private_data; - result->te = add_timed_event(result, timeval_sum(&now, &interval), + result->te = event_add_timed(smbd_event_context(), result, + timeval_sum(&now, &interval), "idle_event_handler", idle_event_handler, result); if (result->te == NULL) { - DEBUG(0, ("add_timed_event failed\n")); + DEBUG(0, ("event_add_timed failed\n")); TALLOC_FREE(result); return NULL; } @@ -350,7 +353,7 @@ The timeout is in milliseconds static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) { - fd_set fds; + fd_set r_fds, w_fds; int selrtn; struct timeval to; int maxfd = 0; @@ -414,10 +417,11 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) } /* - * Setup the select read fd set. + * Setup the select fd sets. */ - FD_ZERO(&fds); + FD_ZERO(&r_fds); + FD_ZERO(&w_fds); /* * Ensure we process oplock break messages by preference. @@ -428,9 +432,9 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) * This is hideously complex - *MUST* be simplified for 3.0 ! JRA. */ - if (oplock_message_waiting(&fds)) { + if (oplock_message_waiting(&r_fds)) { DEBUG(10,("receive_message_or_smb: oplock_message is waiting.\n")); - async_processing(&fds); + async_processing(&r_fds); /* * After async processing we must go and do the select again, as * the state of the flag in fds for the server file descriptor is @@ -445,15 +449,17 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) */ { - struct timeval tmp; - struct timeval *tp = get_timed_events_timeout(&tmp); - - if (tp) { - to = timeval_min(&to, tp); - if (timeval_is_zero(&to)) { - /* Process a timed event now... */ - run_events(); - } + struct timeval now; + GetTimeOfDay(&now); + + event_add_to_select_args(smbd_event_context(), &now, + &r_fds, &w_fds, &to, &maxfd); + } + + if (timeval_is_zero(&to)) { + /* Process a timed event now... */ + if (run_events(smbd_event_context(), 0, NULL, NULL)) { + goto again; } } @@ -461,23 +467,27 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) int sav; START_PROFILE(smbd_idle); - maxfd = select_on_fd(smbd_server_fd(), maxfd, &fds); - maxfd = select_on_fd(change_notify_fd(), maxfd, &fds); - maxfd = select_on_fd(oplock_notify_fd(), maxfd, &fds); + maxfd = select_on_fd(smbd_server_fd(), maxfd, &r_fds); + maxfd = select_on_fd(change_notify_fd(), maxfd, &r_fds); + maxfd = select_on_fd(oplock_notify_fd(), maxfd, &r_fds); - selrtn = sys_select(maxfd+1,&fds,NULL,NULL,&to); + selrtn = sys_select(maxfd+1,&r_fds,&w_fds,NULL,&to); sav = errno; END_PROFILE(smbd_idle); errno = sav; } + if (run_events(smbd_event_context(), selrtn, &r_fds, &w_fds)) { + goto again; + } + /* if we get EINTR then maybe we have received an oplock signal - treat this as select returning 1. This is ugly, but is the best we can do until the oplock code knows more about signals */ if (selrtn == -1 && errno == EINTR) { - async_processing(&fds); + async_processing(&r_fds); /* * After async processing we must go and do the select again, as * the state of the flag in fds for the server file descriptor is @@ -505,8 +515,8 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) * sending us an oplock break message. JRA. */ - if (oplock_message_waiting(&fds)) { - async_processing(&fds); + if (oplock_message_waiting(&r_fds)) { + async_processing(&r_fds); /* * After async processing we must go and do the select again, as * the state of the flag in fds for the server file descriptor is @@ -515,7 +525,8 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) goto again; } - if ((change_notify_fd() >= 0) && FD_ISSET(change_notify_fd(), &fds)) { + if ((change_notify_fd() >= 0) && FD_ISSET(change_notify_fd(), + &r_fds)) { process_pending_change_notify_queue((time_t)0); @@ -1603,7 +1614,7 @@ void smbd_process(void) num_smbs = 0; /* Reset smb counter. */ } - run_events(); + run_events(smbd_event_context(), 0, NULL, NULL); #if defined(DEVELOPER) clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); -- cgit From d5206610cd67f88e2cc7d5b2b434e320e81c29d5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 21 Jan 2007 11:49:00 +0000 Subject: r20931: This changes the notify infrastructure from a polling-based to an event-driven based approach. The only remaining hook into the backend is now void *(*notify_add)(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, files_struct *fsp, uint32 *filter); (Should we put this through the VFS, so that others can more easily plug in?) The trick here is that the backend can pick filter bits that the main smbd should not handle anymore. Thanks to tridge for this idea. The backend can notify the main smbd process via void notify_fsp(files_struct *fsp, uint32 action, char *name); The core patch is not big, what makes this more than 1800 lines are the individual backends that are considerably changed but can be reviewed one by one. Based on this I'll continue with inotify now. Volker (This used to be commit 9cd6a8a82792b7b6967141565d043b6337836a5d) --- source3/smbd/process.c | 31 ------------------------------- 1 file changed, 31 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2a52da12b3..cfecd7fecb 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -304,9 +304,6 @@ static void async_processing(fd_set *pfds) exit_server_cleanly("termination signal"); } - /* check for async change notify events */ - process_pending_change_notify_queue(0); - /* check for sighup processing */ if (reload_after_sighup) { change_to_root_user(); @@ -468,7 +465,6 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) START_PROFILE(smbd_idle); maxfd = select_on_fd(smbd_server_fd(), maxfd, &r_fds); - maxfd = select_on_fd(change_notify_fd(), maxfd, &r_fds); maxfd = select_on_fd(oplock_notify_fd(), maxfd, &r_fds); selrtn = sys_select(maxfd+1,&r_fds,&w_fds,NULL,&to); @@ -525,20 +521,6 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) goto again; } - if ((change_notify_fd() >= 0) && FD_ISSET(change_notify_fd(), - &r_fds)) { - - process_pending_change_notify_queue((time_t)0); - - /* - * Same comment as for oplock processing applies here. We - * might have done I/O on the client socket. - */ - - goto again; - } - - return receive_smb(smbd_server_fd(), buffer, 0); } @@ -1251,16 +1233,9 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) static int setup_select_timeout(void) { int select_timeout; - int t; select_timeout = blocking_locks_timeout_ms(SMBD_SELECT_TIMEOUT*1000); - t = change_notify_timeout(); - DEBUG(10, ("change_notify_timeout: %d\n", t)); - if (t != -1) { - select_timeout = MIN(select_timeout, t*1000); - } - if (print_notify_messages_pending()) { select_timeout = MIN(select_timeout, 1000); } @@ -1458,12 +1433,6 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); update_monitored_printq_cache(); - /* - * Check to see if we have any change notifies - * outstanding on the queue. - */ - process_pending_change_notify_queue(t); - /* * Now we are root, check if the log files need pruning. * Force a log file check. -- cgit From 14785319cccde0e36c07927a6a3b23f52cbfb944 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 5 Feb 2007 23:33:53 +0000 Subject: r21166: Ensure we return the correct "EROFS" error on a non-writable filesystem. Jeremy. (This used to be commit 1e25501e8e6c568ab8892e05e0a60197e267d2b5) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index cfecd7fecb..5830af8f43 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -973,7 +973,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* Does it need write permission? */ if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) { - return(ERROR_DOS(ERRSRV,ERRaccess)); + return ERROR_NT(NT_STATUS_MEDIA_WRITE_PROTECTED); } /* IPC services are limited */ -- cgit From c59a49d83b7e2e46f9d8111f1beb359095cc448e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 6 Feb 2007 20:07:29 +0000 Subject: r21184: Dummy checkin to let the build farm pick up r21183 of Samba4 (This used to be commit 22c9511314d563e1f4480099d2990cb5fbb8546a) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 5830af8f43..6a6da8715f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -66,8 +66,8 @@ uint16 get_current_mid(void) static struct pending_message_list *deferred_open_queue; /**************************************************************************** - Function to push a message onto the tail of a linked list of smb messages ready - for processing. + Function to push a message onto the tail of a linked list of smb messages + ready for processing. ****************************************************************************/ static BOOL push_queued_message(char *buf, int msg_len, -- cgit From fe881c3e38bb25a6716d94df362a5580afbdfd8b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 11 Feb 2007 14:07:50 +0000 Subject: r21278: The main goal of this was to get rid of the NetInBuffer / set_InBuffer. But it turns out that this patch actually speeds up the async writes considerably. I tested writing 100.000 times 65535 bytes with the allowed 10 ops in parallel. Without this patch it took about 32 seconds on my dual-core 1.6GHz laptop. With this patch it dropped to about 26 seconds. I can only explain it by better cache locality, NewInBuffer allocates more than 128k, so we jump around in memory more. Jeremy, please check! Volker (This used to be commit 452d51bc6fd41771b9c41ba6391664513d7cf2cd) --- source3/smbd/process.c | 40 ++-------------------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 6a6da8715f..a0e14d8445 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1463,54 +1463,18 @@ char *get_InBuffer(void) return InBuffer; } -void set_InBuffer(char *new_inbuf) -{ - InBuffer = new_inbuf; - current_inbuf = InBuffer; -} - char *get_OutBuffer(void) { return OutBuffer; } -void set_OutBuffer(char *new_outbuf) -{ - OutBuffer = new_outbuf; -} - -/**************************************************************************** - Free an InBuffer. Checks if not in use by aio system. - Must have been allocated by NewInBuffer. -****************************************************************************/ - -void free_InBuffer(char *inbuf) -{ - if (!aio_inbuffer_in_use(inbuf)) { - if (current_inbuf == inbuf) { - current_inbuf = NULL; - } - SAFE_FREE(inbuf); - } -} - -/**************************************************************************** - Free an OutBuffer. No outbuffers currently stolen by aio system. - Must have been allocated by NewInBuffer. -****************************************************************************/ - -void free_OutBuffer(char *outbuf) -{ - SAFE_FREE(outbuf); -} - const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); /**************************************************************************** Allocate a new InBuffer. Returns the new and old ones. ****************************************************************************/ -char *NewInBuffer(char **old_inbuf) +static char *NewInBuffer(char **old_inbuf) { char *new_inbuf = (char *)SMB_MALLOC(total_buffer_size); if (!new_inbuf) { @@ -1530,7 +1494,7 @@ char *NewInBuffer(char **old_inbuf) Allocate a new OutBuffer. Returns the new and old ones. ****************************************************************************/ -char *NewOutBuffer(char **old_outbuf) +static char *NewOutBuffer(char **old_outbuf) { char *new_outbuf = (char *)SMB_MALLOC(total_buffer_size); if (!new_outbuf) { -- cgit From 235b0f97f280cd0b3d7941969cf154a89fd53775 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 7 Mar 2007 01:28:19 +0000 Subject: r21731: Fix long-standing bug in our chain processing code. Should fix a bug with WinPE. Probably a candidate for the Vista patchset. Jeremy. (This used to be commit ef32de6b59fef3e9f59e6f864ce5eb072390ea48) --- source3/smbd/process.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index a0e14d8445..dbac553aea 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1148,6 +1148,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) unsigned smb_off2 = SVAL(inbuf,smb_vwv1); char *inbuf2, *outbuf2; int outsize2; + int new_size; char inbuf_saved[smb_wct]; char outbuf_saved[smb_wct]; int outsize = smb_len(outbuf) + 4; @@ -1198,6 +1199,20 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) /* create the in buffer */ SCVAL(inbuf2,smb_com,smb_com2); + /* work out the new size for the in buffer. */ + new_size = size - (inbuf2 - inbuf); + if (new_size < 0) { + DEBUG(0,("chain_reply: chain packet size incorrect (orig size = %d, " + "offset = %d)\n", + size, + (inbuf2 - inbuf) )); + exit_server_cleanly("Bad chained packet"); + return(-1); + } + + /* And set it in the header. */ + smb_setlen(inbuf2, new_size); + /* create the out buffer */ construct_reply_common(inbuf2, outbuf2); @@ -1205,7 +1220,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) show_msg(inbuf2); /* process the request */ - outsize2 = switch_message(smb_com2,inbuf2,outbuf2,size-chain_size, + outsize2 = switch_message(smb_com2,inbuf2,outbuf2,new_size, bufsize-chain_size); /* copy the new reply and request headers over the old ones, but @@ -1219,8 +1234,10 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) { int ofs = smb_wct - PTR_DIFF(outbuf2,orig_outbuf); - if (ofs < 0) ofs = 0; - memmove(outbuf2+ofs,outbuf_saved+ofs,smb_wct-ofs); + if (ofs < 0) { + ofs = 0; + } + memmove(outbuf2+ofs,outbuf_saved+ofs,smb_wct-ofs); } return outsize2; -- cgit From 0d91334fe799f6b50a8265f9dc097411c3a29e18 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 11 Mar 2007 16:49:16 +0000 Subject: r21784: Replace smb_register_idle_event() with event_add_timed(). This fixes winbind who did not run the idle events to drop ldap connections. Volker (This used to be commit af3308ce5a21220ff4c510de356dbaa6cf9ff997) --- source3/smbd/process.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index dbac553aea..11ef33679f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1351,9 +1351,6 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t /* become root again if waiting */ change_to_root_user(); - /* run all registered idle events */ - smb_run_idle_events(t); - /* check if we need to reload services */ check_reload(t); -- cgit From 2864d86b37fe29ba2e985b61e646061feb0b841f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 18 Mar 2007 10:09:16 +0000 Subject: r21867: Simplify calling convention of timeout_processing. lp_deadtime is only referenced in conn_idle_all(). (This used to be commit c0aaee6d36cf1fb873cfb9ab6ee52ff097a202a0) --- source3/smbd/process.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 11ef33679f..846f338ccf 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1317,7 +1317,8 @@ void check_reload(time_t t) Process any timeout housekeeping. Return False if the caller should exit. ****************************************************************************/ -static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_timeout_processing_time) +static BOOL timeout_processing(int *select_timeout, + time_t *last_timeout_processing_time) { static time_t last_keepalive_sent_time = 0; static time_t last_idle_closed_check = 0; @@ -1382,7 +1383,7 @@ static BOOL timeout_processing(int deadtime, int *select_timeout, time_t *last_t } /* check for connection timeouts */ - allidle = conn_idle_all(t, deadtime); + allidle = conn_idle_all(t); if (allidle && conn_num_open()>0) { DEBUG(2,("Closing idle connection 2.\n")); @@ -1541,13 +1542,9 @@ void smbd_process(void) max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); while (True) { - int deadtime = lp_deadtime()*60; int select_timeout = setup_select_timeout(); int num_echos; - if (deadtime <= 0) - deadtime = DEFAULT_SMBD_TIMEOUT; - errno = 0; /* free up temporary memory */ @@ -1556,7 +1553,8 @@ void smbd_process(void) /* Did someone ask for immediate checks on things like blocking locks ? */ if (select_timeout == 0) { - if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) + if(!timeout_processing(&select_timeout, + &last_timeout_processing_time)) return; num_smbs = 0; /* Reset smb counter. */ } @@ -1568,7 +1566,8 @@ void smbd_process(void) #endif while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) { - if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) + if(!timeout_processing(&select_timeout, + &last_timeout_processing_time)) return; num_smbs = 0; /* Reset smb counter. */ } @@ -1589,7 +1588,7 @@ void smbd_process(void) process_smb(InBuffer, OutBuffer); if (smb_echo_count != num_echos) { - if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) + if(!timeout_processing( &select_timeout, &last_timeout_processing_time)) return; num_smbs = 0; /* Reset smb counter. */ } @@ -1606,7 +1605,9 @@ void smbd_process(void) if ((num_smbs % 200) == 0) { time_t new_check_time = time(NULL); if(new_check_time - last_timeout_processing_time >= (select_timeout/1000)) { - if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) + if(!timeout_processing( + &select_timeout, + &last_timeout_processing_time)) return; num_smbs = 0; /* Reset smb counter. */ last_timeout_processing_time = new_check_time; /* Reset time. */ -- cgit From 8d0cfddb26a354606844a10254055fb8cd54e792 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 18 Mar 2007 10:13:35 +0000 Subject: r21868: Remove check_log_size from the central smbd processing loop. This can be done with a become_root/unbecome_root in debug.c. (This used to be commit 4632a0caaf251d9cc7b9d84cbd20362d37f0e4e0) --- source3/smbd/process.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 846f338ccf..83072817a3 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1448,13 +1448,6 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); update_monitored_printq_cache(); - /* - * Now we are root, check if the log files need pruning. - * Force a log file check. - */ - force_check_log_size(); - check_log_size(); - /* Send any queued printer notify message to interested smbd's. */ print_notify_send_messages(0); -- cgit From 7c2bc9c07083e7035028cf22e97e0c31b3e9d6a5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 18 Mar 2007 10:57:46 +0000 Subject: r21869: Move sending keepalives out of the main processing loop into idle event. On the way, make lp_keepalive() a proper parameter. Volker (This used to be commit 9499fd9c803d030ce9827f8379c2e56d91bb786e) --- source3/smbd/process.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 83072817a3..5edb2c1009 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -22,7 +22,6 @@ #include "includes.h" uint16 global_smbpid; -extern int keepalive; extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; @@ -221,6 +220,7 @@ BOOL push_deferred_smb_message(uint16 mid, struct idle_event { struct timed_event *te; struct timeval interval; + char *name; BOOL (*handler)(const struct timeval *now, void *private_data); void *private_data; }; @@ -241,17 +241,19 @@ static void idle_event_handler(struct event_context *ctx, return; } - event->te = event_add_timed(smbd_event_context(), event, + event->te = event_add_timed(ctx, event, timeval_sum(now, &event->interval), - "idle_event_handler", + event->name, idle_event_handler, event); /* We can't do much but fail here. */ SMB_ASSERT(event->te != NULL); } -struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx, +struct idle_event *event_add_idle(struct event_context *event_ctx, + TALLOC_CTX *mem_ctx, struct timeval interval, + const char *name, BOOL (*handler)(const struct timeval *now, void *private_data), void *private_data) @@ -269,9 +271,15 @@ struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx, result->handler = handler; result->private_data = private_data; - result->te = event_add_timed(smbd_event_context(), result, + if (!(result->name = talloc_asprintf(result, "idle_evt(%s)", name))) { + DEBUG(0, ("talloc failed\n")); + TALLOC_FREE(result); + return NULL; + } + + result->te = event_add_timed(event_ctx, result, timeval_sum(&now, &interval), - "idle_event_handler", + result->name, idle_event_handler, result); if (result->te == NULL) { DEBUG(0, ("event_add_timed failed\n")); @@ -1363,12 +1371,7 @@ static BOOL timeout_processing(int *select_timeout, last_idle_closed_check = t; } - if (keepalive && (t - last_keepalive_sent_time)>keepalive) { - if (!send_keepalive(smbd_server_fd())) { - DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); - return False; - } - + if (lp_keepalive() && (t - last_keepalive_sent_time)> lp_keepalive()) { /* send a keepalive for a password server or the like. This is attached to the auth_info created in the negprot */ -- cgit From c0e37a74963ae942ed48431bd2ea353ebad256ff Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 18 Mar 2007 11:24:10 +0000 Subject: r21870: Move sending auth_server keepalives out of the main loop into an idle event. Volker (This used to be commit 6226b30f38cd82531422815ba66a687aab50028d) --- source3/smbd/process.c | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 5edb2c1009..76af8f2054 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1328,7 +1328,6 @@ void check_reload(time_t t) static BOOL timeout_processing(int *select_timeout, time_t *last_timeout_processing_time) { - static time_t last_keepalive_sent_time = 0; static time_t last_idle_closed_check = 0; time_t t; BOOL allidle = True; @@ -1351,9 +1350,6 @@ static BOOL timeout_processing(int *select_timeout, *last_timeout_processing_time = t = time(NULL); - if(last_keepalive_sent_time == 0) - last_keepalive_sent_time = t; - if(last_idle_closed_check == 0) last_idle_closed_check = t; @@ -1371,20 +1367,6 @@ static BOOL timeout_processing(int *select_timeout, last_idle_closed_check = t; } - if (lp_keepalive() && (t - last_keepalive_sent_time)> lp_keepalive()) { - /* send a keepalive for a password server or the like. - This is attached to the auth_info created in the - negprot */ - if (negprot_global_auth_context && negprot_global_auth_context->challenge_set_method - && negprot_global_auth_context->challenge_set_method->send_keepalive) { - - negprot_global_auth_context->challenge_set_method->send_keepalive - (&negprot_global_auth_context->challenge_set_method->private_data); - } - - last_keepalive_sent_time = t; - } - /* check for connection timeouts */ allidle = conn_idle_all(t); -- cgit From fe0b56ead166377d415b0eaf04ee1af3bdb435de Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 18 Mar 2007 13:19:40 +0000 Subject: r21871: Move deadtime processing into an idle event. While there, simplify conn_idle_all() a bit. Volker (This used to be commit 3fc00977a99932b226bdcbc43bbc0ede1bcec26f) --- source3/smbd/process.c | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 76af8f2054..6497dfa97b 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1328,9 +1328,7 @@ void check_reload(time_t t) static BOOL timeout_processing(int *select_timeout, time_t *last_timeout_processing_time) { - static time_t last_idle_closed_check = 0; time_t t; - BOOL allidle = True; if (smb_read_error == READ_EOF) { DEBUG(3,("timeout_processing: End of file from client (client has disconnected).\n")); @@ -1350,31 +1348,12 @@ static BOOL timeout_processing(int *select_timeout, *last_timeout_processing_time = t = time(NULL); - if(last_idle_closed_check == 0) - last_idle_closed_check = t; - /* become root again if waiting */ change_to_root_user(); /* check if we need to reload services */ check_reload(t); - /* automatic timeout if all connections are closed */ - if (conn_num_open()==0 && (t - last_idle_closed_check) >= IDLE_CLOSED_TIMEOUT) { - DEBUG( 2, ( "Closing idle connection\n" ) ); - return False; - } else { - last_idle_closed_check = t; - } - - /* check for connection timeouts */ - allidle = conn_idle_all(t); - - if (allidle && conn_num_open()>0) { - DEBUG(2,("Closing idle connection 2.\n")); - return False; - } - if(global_machine_password_needs_changing && /* for ADS we need to do a regular ADS password change, not a domain password change */ -- cgit From 496dbdf4350ffc5f53c9f8f734d2c29b312ff11b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 19 Mar 2007 21:52:27 +0000 Subject: r21879: Move process_blocking_lock_queue to a timed event. The idea is that we have blocking.c:brl_timeout as a timed event that is present whenever we do have a blocking lock pending. It fires brl_timeout_fn() which calls process_blocking_lock_queue(). Whenever we make changes to blocking_lock_queue, we trigger a recalc_brl_timeout() which sets a new brl_timout event if necessary. This makes the call to blocking_locks_timeout_ms() in setup_select_timeout() unnecessary, this is implicitly done in event_add_to_select_args() from the timed events. Volker (This used to be commit 7e31b8ce21de803ac1f8967967393341a3f44ac3) --- source3/smbd/process.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 6497dfa97b..59ad96d880 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1259,7 +1259,7 @@ static int setup_select_timeout(void) { int select_timeout; - select_timeout = blocking_locks_timeout_ms(SMBD_SELECT_TIMEOUT*1000); + select_timeout = SMBD_SELECT_TIMEOUT*1000; if (print_notify_messages_pending()) { select_timeout = MIN(select_timeout, 1000); @@ -1402,12 +1402,6 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); secrets_lock_trust_account_password(lp_workgroup(), False); } - /* - * Check to see if we have any blocking locks - * outstanding on the queue. - */ - process_blocking_lock_queue(); - /* update printer queue caches if necessary */ update_monitored_printq_cache(); -- cgit From a0987247347e473e4802f9267773b0bff68f0187 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Apr 2007 21:01:46 +0000 Subject: r22145: Fix bug #4494 - reported by Kevin Jamieson . If returning a mapped UNIX error from sendfile, don't call chain_reply. Jeremy. (This used to be commit 38404c990db1436241c3a774c51196bc058d7576) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 59ad96d880..c5db007525 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1161,8 +1161,8 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) char outbuf_saved[smb_wct]; int outsize = smb_len(outbuf) + 4; - /* maybe its not chained */ - if (smb_com2 == 0xFF) { + /* Maybe its not chained, or it's an error packet. */ + if (smb_com2 == 0xFF || SVAL(outbuf,smb_rcls) != 0) { SCVAL(outbuf,smb_vwv0,0xFF); return outsize; } -- cgit From a633b42592080982b38f5e3cde8d32bf2fd80e7e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 14 Apr 2007 06:40:47 +0000 Subject: r22213: We can't use become_root() here, as it does DEBUG() itself. become_root_uid_only did not :-) Revert 21868, we need to find a better way. Volker (This used to be commit 629f966714c7a8d96b06027d514b86cde81b69b9) --- source3/smbd/process.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c5db007525..6f3ad9884c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1406,6 +1406,13 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); update_monitored_printq_cache(); + /* + * Now we are root, check if the log files need pruning. + * Force a log file check. + */ + force_check_log_size(); + check_log_size(); + /* Send any queued printer notify message to interested smbd's. */ print_notify_send_messages(0); -- cgit From dc90cd89a7fef3b0a744ef1873193cf2c9d75cad Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 19 Apr 2007 20:50:49 +0000 Subject: r22389: Start preparing for multiple encryption contexts in the server. Allow server to reflect back to calling client the encryption context that was sent. Jeremy. (This used to be commit b49e90335d1e589916b5ab4992e3c4a2d221ca7e) --- source3/smbd/process.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 6f3ad9884c..c6bcfb7394 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1039,8 +1039,9 @@ static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) outsize += chain_size; - if(outsize > 4) - smb_setlen(outbuf,outsize - 4); + if(outsize > 4) { + smb_setlen(outbuf,outsize - 4, inbuf); + } return(outsize); } @@ -1219,7 +1220,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) } /* And set it in the header. */ - smb_setlen(inbuf2, new_size); + smb_setlen(inbuf2, new_size, inbuf); /* create the out buffer */ construct_reply_common(inbuf2, outbuf2); -- cgit From 0829e1ad1c3646efecf50729f493b9ee72ef0517 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 19 Apr 2007 22:40:32 +0000 Subject: r22391: Looks bigger than it is. Make "inbuf" available to all callers of smb_setlen (via set_message() calls). This will allow the server to reflect back the correct encryption context. Jeremy. (This used to be commit 2d80a96120a5fe2fe726f00746d36d85044c4bdb) --- source3/smbd/process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c6bcfb7394..ff1170f552 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1040,7 +1040,7 @@ static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) outsize += chain_size; if(outsize > 4) { - smb_setlen(outbuf,outsize - 4, inbuf); + smb_setlen(inbuf,outbuf,outsize - 4); } return(outsize); } @@ -1129,7 +1129,7 @@ void remove_from_common_flags2(uint32 v) void construct_reply_common(const char *inbuf, char *outbuf) { - set_message(outbuf,0,0,False); + set_message(inbuf,outbuf,0,0,False); SCVAL(outbuf,smb_com,CVAL(inbuf,smb_com)); SIVAL(outbuf,smb_rcls,0); @@ -1220,7 +1220,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) } /* And set it in the header. */ - smb_setlen(inbuf2, new_size, inbuf); + smb_setlen(inbuf, inbuf2, new_size); /* create the out buffer */ construct_reply_common(inbuf2, outbuf2); -- cgit From 2541e0d59048f9d0f522aaebca4c4c6f5019fec5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 22 Apr 2007 14:51:07 +0000 Subject: r22458: Fix a comment (This used to be commit f5ccec42287cfdf128bbfcf562a47a852bd0e3fe) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ff1170f552..16c1d80c0f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -121,7 +121,7 @@ void remove_deferred_open_smb_message(uint16 mid) for (pml = deferred_open_queue; pml; pml = pml->next) { if (mid == SVAL(pml->buf.data,smb_mid)) { - DEBUG(10,("remove_sharing_violation_open_smb_message: " + DEBUG(10,("remove_deferred_open_smb_message: " "deleting mid %u len %u\n", (unsigned int)mid, (unsigned int)pml->buf.length )); -- cgit From fb5644342760cb54b4285c65ab36d693f558a289 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 5 May 2007 21:13:40 +0000 Subject: r22691: Fix a 64-bit warning and a const const discard warning (This used to be commit 3a2ca1b1b85e268928587287f61d26f992b303a5) --- source3/smbd/process.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 16c1d80c0f..44baa96059 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1211,10 +1211,9 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) /* work out the new size for the in buffer. */ new_size = size - (inbuf2 - inbuf); if (new_size < 0) { - DEBUG(0,("chain_reply: chain packet size incorrect (orig size = %d, " - "offset = %d)\n", - size, - (inbuf2 - inbuf) )); + DEBUG(0,("chain_reply: chain packet size incorrect " + "(orig size = %d, offset = %d)\n", + size, (int)(inbuf2 - inbuf) )); exit_server_cleanly("Bad chained packet"); return(-1); } -- cgit From bf7008abb8c79c0d4c86d60408b03e419a1dc0dc Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 6 May 2007 13:46:30 +0000 Subject: r22695: Dummy checkin (reformatting) to make the AIX hosts retry. (This used to be commit cd55ccef6a1d0c95836feeb5efb5abcaedb35df2) --- source3/smbd/process.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 44baa96059..4ae6dcd5ba 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -144,11 +144,11 @@ void schedule_deferred_open_smb_message(uint16 mid) for (pml = deferred_open_queue; pml; pml = pml->next) { uint16 msg_mid = SVAL(pml->buf.data,smb_mid); - DEBUG(10,("schedule_deferred_open_smb_message: [%d] msg_mid = %u\n", i++, - (unsigned int)msg_mid )); + DEBUG(10, ("schedule_deferred_open_smb_message: [%d] " + "msg_mid = %u\n", i++, (unsigned int)msg_mid )); if (mid == msg_mid) { - DEBUG(10,("schedule_deferred_open_smb_message: scheduling mid %u\n", - mid )); + DEBUG(10, ("schedule_deferred_open_smb_message: " + "scheduling mid %u\n", mid)); pml->end_time.tv_sec = 0; pml->end_time.tv_usec = 0; DLIST_PROMOTE(deferred_open_queue, pml); @@ -156,8 +156,8 @@ void schedule_deferred_open_smb_message(uint16 mid) } } - DEBUG(10,("schedule_deferred_open_smb_message: failed to find message mid %u\n", - mid )); + DEBUG(10, ("schedule_deferred_open_smb_message: failed to find " + "message mid %u\n", mid )); } /**************************************************************************** -- cgit From fad7dd8a60e6637598b17fa89ec92d98db51fffe Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 14 May 2007 20:31:28 +0000 Subject: r22868: Replace some message_send_pid calls with messaging_send_pid calls. More tomorrow. (This used to be commit 74fa57ca5d7fa8eace72bbe948a08a0bca3cc4ca) --- source3/smbd/process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 4ae6dcd5ba..02dc507e11 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -301,7 +301,7 @@ static void async_processing(fd_set *pfds) process_aio_queue(); - process_kernel_oplocks(pfds); + process_kernel_oplocks(smbd_messaging_context(), pfds); /* Do the aio check again after receive_local_message as it does a select and may have eaten our signal. */ @@ -574,7 +574,7 @@ void respond_to_all_remaining_local_messages(void) return; } - process_kernel_oplocks(NULL); + process_kernel_oplocks(smbd_messaging_context(), NULL); return; } @@ -1415,7 +1415,7 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); /* Send any queued printer notify message to interested smbd's. */ - print_notify_send_messages(0); + print_notify_send_messages(smbd_messaging_context(), 0); /* * Modify the select timeout depending upon -- cgit From ac3f08ddbe0b484375624db0e35999a8584b57f4 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 21 May 2007 22:17:13 +0000 Subject: r23055: Rewrite messages.c to use auto-generated marshalling in the tdb. I'm doing this because for the clustering the marshalling is needed in more than one place, so I wanted a decent routine to marshall a message_rec struct which was not there before. Tridge, this seems about the same speed as it used to be before, the librpc/ndr overhead in my tests was under the noise. Volker (This used to be commit eaefd00563173dfabb7716c5695ac0a2f7139bb6) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 02dc507e11..3b922af51f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -380,7 +380,7 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) * messages as we need to synchronously process any messages * we may have sent to ourselves from the previous SMB. */ - message_dispatch(); + message_dispatch(smbd_messaging_context()); /* * Check to see if we already have a message on the deferred open queue -- cgit From 5e8a4c12f9617d7e7b2c392eddc1ced613a561fe Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 17 Jun 2007 05:19:30 +0000 Subject: r23528: Two changes to make the valgrind massif (heap profiler) output readable: Remove the allocated inbuf/output. In async I/O we copy the buffers explicitly now, so NewInBuffer is called exactly once. This does not reduce memory footprint, but removes one of the larger chunks that clobber the rest of the massif output In getgroups_unix_user on Linux 2.6 we allocated 64k groups x 4 bytes per group x 2 (once in the routine itself and once in libc) = 512k just to throw it away directly again. This reduces it do a more typical limit of 32 groups per user. We certainly cope with overflow fine if 32 is not enough. Not 100% sure about this one, a DEVELOPER only thing? (This used to be commit 009af0909944e0f303c5d496b56fb65ca40a41d5) --- source3/smbd/process.c | 64 ++++++++------------------------------------------ 1 file changed, 10 insertions(+), 54 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 3b922af51f..0e1ad06ed5 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -25,9 +25,10 @@ uint16 global_smbpid; extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; -static char *InBuffer = NULL; -static char *OutBuffer = NULL; -static char *current_inbuf = NULL; +#define TOTAL_BUFFER_SIZE (BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE+SAFETY_MARGIN) + +static char InBuffer[TOTAL_BUFFER_SIZE]; +static char OutBuffer[TOTAL_BUFFER_SIZE]; /* * Size of data we can send to client. Set @@ -208,11 +209,11 @@ BOOL push_deferred_smb_message(uint16 mid, DEBUG(10,("push_deferred_open_smb_message: pushing message len %u mid %u " "timeout time [%u.%06u]\n", - (unsigned int) smb_len(current_inbuf)+4, (unsigned int)mid, + (unsigned int) smb_len(InBuffer)+4, (unsigned int)mid, (unsigned int)end_time.tv_sec, (unsigned int)end_time.tv_usec)); - return push_queued_message(current_inbuf, smb_len(current_inbuf)+4, + return push_queued_message(InBuffer, smb_len(InBuffer)+4, request_time, end_time, private_data, priv_len); } @@ -1007,7 +1008,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize return(ERROR_DOS(ERRSRV,ERRaccess)); } - current_inbuf = inbuf; /* In case we need to defer this message in open... */ outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); } @@ -1441,47 +1441,6 @@ char *get_OutBuffer(void) return OutBuffer; } -const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); - -/**************************************************************************** - Allocate a new InBuffer. Returns the new and old ones. -****************************************************************************/ - -static char *NewInBuffer(char **old_inbuf) -{ - char *new_inbuf = (char *)SMB_MALLOC(total_buffer_size); - if (!new_inbuf) { - return NULL; - } - if (old_inbuf) { - *old_inbuf = InBuffer; - } - InBuffer = new_inbuf; -#if defined(DEVELOPER) - clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); -#endif - return InBuffer; -} - -/**************************************************************************** - Allocate a new OutBuffer. Returns the new and old ones. -****************************************************************************/ - -static char *NewOutBuffer(char **old_outbuf) -{ - char *new_outbuf = (char *)SMB_MALLOC(total_buffer_size); - if (!new_outbuf) { - return NULL; - } - if (old_outbuf) { - *old_outbuf = OutBuffer; - } - OutBuffer = new_outbuf; -#if defined(DEVELOPER) - clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size); -#endif - return OutBuffer; -} /**************************************************************************** Process commands from the client @@ -1492,11 +1451,6 @@ void smbd_process(void) time_t last_timeout_processing_time = time(NULL); unsigned int num_smbs = 0; - /* Allocate the primary Inbut/Output buffers. */ - - if ((NewInBuffer(NULL) == NULL) || (NewOutBuffer(NULL) == NULL)) - return; - max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); while (True) { @@ -1520,7 +1474,8 @@ void smbd_process(void) run_events(smbd_event_context(), 0, NULL, NULL); #if defined(DEVELOPER) - clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, + InBuffer, TOTAL_BUFFER_SIZE); #endif while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) { @@ -1541,7 +1496,8 @@ void smbd_process(void) */ num_echos = smb_echo_count; - clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size); + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, + OutBuffer, TOTAL_BUFFER_SIZE); process_smb(InBuffer, OutBuffer); -- cgit From 864cad1353867a4092e4ba4b46721f91ada64ca9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 18 Jun 2007 09:25:31 +0000 Subject: r23537: Revert the inbuf/outbuf part of r23528: This caused the Solaris CC make test to break. The Solaris CC put the static char InBuffer[TOTAL_BUFFER_SIZE] on an odd address, the malloc'ed one is always aligned. The problem showed up in pull_ucs2, ucs2_align uses the address of InBuffer as an indication whether to bump up the src of the string by one. Unfortunately in the trans calls the data portion is malloced and thus has different alignment guarantees than a static variable. This one is bigger.... Volker (This used to be commit 6affd7818f6981be2a9f44fcf302e7fddb468347) --- source3/smbd/process.c | 64 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 10 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 0e1ad06ed5..3b922af51f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -25,10 +25,9 @@ uint16 global_smbpid; extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; -#define TOTAL_BUFFER_SIZE (BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE+SAFETY_MARGIN) - -static char InBuffer[TOTAL_BUFFER_SIZE]; -static char OutBuffer[TOTAL_BUFFER_SIZE]; +static char *InBuffer = NULL; +static char *OutBuffer = NULL; +static char *current_inbuf = NULL; /* * Size of data we can send to client. Set @@ -209,11 +208,11 @@ BOOL push_deferred_smb_message(uint16 mid, DEBUG(10,("push_deferred_open_smb_message: pushing message len %u mid %u " "timeout time [%u.%06u]\n", - (unsigned int) smb_len(InBuffer)+4, (unsigned int)mid, + (unsigned int) smb_len(current_inbuf)+4, (unsigned int)mid, (unsigned int)end_time.tv_sec, (unsigned int)end_time.tv_usec)); - return push_queued_message(InBuffer, smb_len(InBuffer)+4, + return push_queued_message(current_inbuf, smb_len(current_inbuf)+4, request_time, end_time, private_data, priv_len); } @@ -1008,6 +1007,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize return(ERROR_DOS(ERRSRV,ERRaccess)); } + current_inbuf = inbuf; /* In case we need to defer this message in open... */ outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); } @@ -1441,6 +1441,47 @@ char *get_OutBuffer(void) return OutBuffer; } +const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); + +/**************************************************************************** + Allocate a new InBuffer. Returns the new and old ones. +****************************************************************************/ + +static char *NewInBuffer(char **old_inbuf) +{ + char *new_inbuf = (char *)SMB_MALLOC(total_buffer_size); + if (!new_inbuf) { + return NULL; + } + if (old_inbuf) { + *old_inbuf = InBuffer; + } + InBuffer = new_inbuf; +#if defined(DEVELOPER) + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); +#endif + return InBuffer; +} + +/**************************************************************************** + Allocate a new OutBuffer. Returns the new and old ones. +****************************************************************************/ + +static char *NewOutBuffer(char **old_outbuf) +{ + char *new_outbuf = (char *)SMB_MALLOC(total_buffer_size); + if (!new_outbuf) { + return NULL; + } + if (old_outbuf) { + *old_outbuf = OutBuffer; + } + OutBuffer = new_outbuf; +#if defined(DEVELOPER) + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size); +#endif + return OutBuffer; +} /**************************************************************************** Process commands from the client @@ -1451,6 +1492,11 @@ void smbd_process(void) time_t last_timeout_processing_time = time(NULL); unsigned int num_smbs = 0; + /* Allocate the primary Inbut/Output buffers. */ + + if ((NewInBuffer(NULL) == NULL) || (NewOutBuffer(NULL) == NULL)) + return; + max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); while (True) { @@ -1474,8 +1520,7 @@ void smbd_process(void) run_events(smbd_event_context(), 0, NULL, NULL); #if defined(DEVELOPER) - clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, - InBuffer, TOTAL_BUFFER_SIZE); + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); #endif while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) { @@ -1496,8 +1541,7 @@ void smbd_process(void) */ num_echos = smb_echo_count; - clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, - OutBuffer, TOTAL_BUFFER_SIZE); + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size); process_smb(InBuffer, OutBuffer); -- cgit From 0bc56a2e5ffd0e65e4770e10c80d9fec02950b36 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 5 Jul 2007 16:26:27 +0000 Subject: r23724: Reduce access to the global inbuf a tiny bit. Add a struct smb_request that contains some of the fields from the SMB header, removing the need to access inbuf directly. This right now is used only in the open file code & friends, and creating that header is only done when needed. This needs more work, but it is a start. Jeremy, I'm only checking this into 3_0, please review before I merge it to _26. Volker (This used to be commit ca988f4e79e977160d82e86486972afd15d4acf5) --- source3/smbd/process.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 3b922af51f..dd623e69a5 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -57,6 +57,18 @@ uint16 get_current_mid(void) return SVAL(InBuffer,smb_mid); } +/* + * Initialize a struct smb_request from an inbuf + */ + +void init_smb_request(struct smb_request *req, const uint8 *inbuf) +{ + req->flags2 = SVAL(inbuf, smb_flg2); + req->smbpid = SVAL(inbuf, smb_pid); + req->mid = SVAL(inbuf, smb_mid); + req->vuid = SVAL(inbuf, smb_uid); +} + /**************************************************************************** structure to hold a linked list of queued messages. for processing. -- cgit From 5391750ce6db47678a03db4d67a016acff4fc8e2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 5 Jul 2007 16:27:47 +0000 Subject: r23725: Remove get_current_mid() Jeremy, next one to review :-) (This used to be commit a50555dda7db5e848e337185ed91c41c2557f7be) --- source3/smbd/process.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index dd623e69a5..1cb2c27fd3 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -48,15 +48,6 @@ SIG_ATOMIC_T got_sig_term = 0; extern BOOL global_machine_password_needs_changing; extern int max_send; -/**************************************************************************** - Function to return the current request mid from Inbuffer. -****************************************************************************/ - -uint16 get_current_mid(void) -{ - return SVAL(InBuffer,smb_mid); -} - /* * Initialize a struct smb_request from an inbuf */ -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1cb2c27fd3..595c524137 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -6,7 +6,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/smbd/process.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 595c524137..0e39614f58 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From fa919f24f082dbcc7e5f88d69273eba4f72e8806 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 10 Jul 2007 12:22:44 +0000 Subject: r23813: Remove unused global variable (This used to be commit 3b811134c02ff9b24d3e36c1ff94b32946c6183c) --- source3/smbd/process.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 0e39614f58..e6bafa8dc3 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -20,7 +20,6 @@ #include "includes.h" -uint16 global_smbpid; extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; @@ -918,10 +917,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize return(-1); } - /* yuck! this is an interim measure before we get rid of our - current inbuf/outbuf system */ - global_smbpid = SVAL(inbuf,smb_pid); - if (smb_messages[type].fn == NULL) { DEBUG(0,("Unknown message type %d!\n",type)); smb_dump("Unknown", 1, inbuf, size); -- cgit From 799c3ec8d466853a87b94df04e0e7b404a311bea Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 21 Jul 2007 22:00:09 +0000 Subject: r23987: Remove static pid in switch_message() There's no point in duplicating functionality that exists in sys_getpid() that also only used in a debug statement (This used to be commit ebf1b1e97c709f5ffe48c85b4227a0af1f88b0ab) --- source3/smbd/process.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index e6bafa8dc3..d193cfb95b 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -898,14 +898,10 @@ static void smb_dump(const char *name, int type, char *data, ssize_t len) static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize) { - static pid_t pid= (pid_t)-1; int outsize = 0; type &= 0xff; - if (pid == (pid_t)-1) - pid = sys_getpid(); - errno = 0; last_message = type; @@ -928,7 +924,9 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize uint16 session_tag = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid); connection_struct *conn = conn_find(SVAL(inbuf,smb_tid)); - DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n",smb_fn_name(type),(int)pid,(unsigned long)conn)); + DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n", + smb_fn_name(type), (int)sys_getpid(), + (unsigned long)conn)); smb_dump(smb_fn_name(type), 1, inbuf, size); -- cgit From 941db29ab41a893ca2f4f2fb39f31cfbb6a634c9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 21 Jul 2007 22:29:55 +0000 Subject: r23988: Looks a lot more scary than it is: This just unwraps the else-branch of if (smb_messages[type].fn == NULL) { into the function top-level. Makes this function a bit easier to understand IMO. Volker (This used to be commit ada23b7f06acb00c36763a3e7a6f6e0caac86951) --- source3/smbd/process.c | 141 ++++++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 67 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d193cfb95b..7958fc761d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -899,6 +899,10 @@ static void smb_dump(const char *name, int type, char *data, ssize_t len) static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize) { int outsize = 0; + int flags; + static uint16 last_session_tag = UID_FIELD_INVALID; + uint16 session_tag; + connection_struct *conn; type &= 0xff; @@ -917,97 +921,100 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize DEBUG(0,("Unknown message type %d!\n",type)); smb_dump("Unknown", 1, inbuf, size); outsize = reply_unknown(inbuf,outbuf); - } else { - int flags = smb_messages[type].flags; - static uint16 last_session_tag = UID_FIELD_INVALID; - /* In share mode security we must ignore the vuid. */ - uint16 session_tag = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid); - connection_struct *conn = conn_find(SVAL(inbuf,smb_tid)); + goto done; + } - DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n", - smb_fn_name(type), (int)sys_getpid(), - (unsigned long)conn)); + flags = smb_messages[type].flags; - smb_dump(smb_fn_name(type), 1, inbuf, size); + /* In share mode security we must ignore the vuid. */ + session_tag = (lp_security() == SEC_SHARE) + ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid); - /* Ensure this value is replaced in the incoming packet. */ - SSVAL(inbuf,smb_uid,session_tag); + conn = conn_find(SVAL(inbuf,smb_tid)); - /* - * Ensure the correct username is in current_user_info. - * This is a really ugly bugfix for problems with - * multiple session_setup_and_X's being done and - * allowing %U and %G substitutions to work correctly. - * There is a reason this code is done here, don't - * move it unless you know what you're doing... :-). - * JRA. - */ + DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n", + smb_fn_name(type), (int)sys_getpid(), + (unsigned long)conn)); + + smb_dump(smb_fn_name(type), 1, inbuf, size); + + /* Ensure this value is replaced in the incoming packet. */ + SSVAL(inbuf,smb_uid,session_tag); - if (session_tag != last_session_tag) { - user_struct *vuser = NULL; + /* + * Ensure the correct username is in current_user_info. This is a + * really ugly bugfix for problems with multiple session_setup_and_X's + * being done and allowing %U and %G substitutions to work correctly. + * There is a reason this code is done here, don't move it unless you + * know what you're doing... :-). JRA. + */ - last_session_tag = session_tag; - if(session_tag != UID_FIELD_INVALID) { - vuser = get_valid_user_struct(session_tag); - if (vuser) { - set_current_user_info(&vuser->user); - } + if (session_tag != last_session_tag) { + user_struct *vuser = NULL; + + last_session_tag = session_tag; + if(session_tag != UID_FIELD_INVALID) { + vuser = get_valid_user_struct(session_tag); + if (vuser) { + set_current_user_info(&vuser->user); } } + } - /* Does this call need to be run as the connected user? */ - if (flags & AS_USER) { - - /* Does this call need a valid tree connection? */ - if (!conn) { - /* Amazingly, the error code depends on the command (from Samba4). */ - if (type == SMBntcreateX) { - return ERROR_NT(NT_STATUS_INVALID_HANDLE); - } else { - return ERROR_DOS(ERRSRV, ERRinvnid); - } - } + /* Does this call need to be run as the connected user? */ + if (flags & AS_USER) { - if (!change_to_user(conn,session_tag)) { - return(ERROR_NT(NT_STATUS_DOS(ERRSRV,ERRbaduid))); + /* Does this call need a valid tree connection? */ + if (!conn) { + /* Amazingly, the error code depends on the command (from Samba4). */ + if (type == SMBntcreateX) { + return ERROR_NT(NT_STATUS_INVALID_HANDLE); + } else { + return ERROR_DOS(ERRSRV, ERRinvnid); } + } - /* All NEED_WRITE and CAN_IPC flags must also have AS_USER. */ + if (!change_to_user(conn,session_tag)) { + return(ERROR_NT(NT_STATUS_DOS(ERRSRV,ERRbaduid))); + } - /* Does it need write permission? */ - if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) { - return ERROR_NT(NT_STATUS_MEDIA_WRITE_PROTECTED); - } + /* All NEED_WRITE and CAN_IPC flags must also have AS_USER. */ - /* IPC services are limited */ - if (IS_IPC(conn) && !(flags & CAN_IPC)) { - return(ERROR_DOS(ERRSRV,ERRaccess)); - } - } else { - /* This call needs to be run as root */ - change_to_root_user(); + /* Does it need write permission? */ + if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) { + return ERROR_NT(NT_STATUS_MEDIA_WRITE_PROTECTED); } - /* load service specific parameters */ - if (conn) { - if (!set_current_service(conn,SVAL(inbuf,smb_flg),(flags & (AS_USER|DO_CHDIR)?True:False))) { - return(ERROR_DOS(ERRSRV,ERRaccess)); - } - conn->num_smb_operations++; + /* IPC services are limited */ + if (IS_IPC(conn) && !(flags & CAN_IPC)) { + return(ERROR_DOS(ERRSRV,ERRaccess)); } + } else { + /* This call needs to be run as root */ + change_to_root_user(); + } - /* does this protocol need to be run as guest? */ - if ((flags & AS_GUEST) && (!change_to_guest() || - !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) { + /* load service specific parameters */ + if (conn) { + if (!set_current_service(conn,SVAL(inbuf,smb_flg),(flags & (AS_USER|DO_CHDIR)?True:False))) { return(ERROR_DOS(ERRSRV,ERRaccess)); } + conn->num_smb_operations++; + } - current_inbuf = inbuf; /* In case we need to defer this message in open... */ - outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); + /* does this protocol need to be run as guest? */ + if ((flags & AS_GUEST) + && (!change_to_guest() || + !check_access(smbd_server_fd(), lp_hostsallow(-1), + lp_hostsdeny(-1)))) { + return(ERROR_DOS(ERRSRV,ERRaccess)); } - smb_dump(smb_fn_name(type), 0, outbuf, outsize); + current_inbuf = inbuf; /* In case we need to defer this message in open... */ + outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); + done: + smb_dump(smb_fn_name(type), 0, outbuf, outsize); return(outsize); } -- cgit From 8579dd4deddb97d851dc03b6961d1a0c01cc7bfa Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 22 Jul 2007 11:38:11 +0000 Subject: r23990: Reformatting for 80 cols and trailing whitespace (This used to be commit 0484de27d97306707ae0243443d18e9dec6d80f3) --- source3/smbd/process.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 7958fc761d..558d403948 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -900,10 +900,11 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize { int outsize = 0; int flags; - static uint16 last_session_tag = UID_FIELD_INVALID; uint16 session_tag; connection_struct *conn; + static uint16 last_session_tag = UID_FIELD_INVALID; + type &= 0xff; errno = 0; @@ -929,12 +930,10 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* In share mode security we must ignore the vuid. */ session_tag = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid); - conn = conn_find(SVAL(inbuf,smb_tid)); - DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n", - smb_fn_name(type), (int)sys_getpid(), - (unsigned long)conn)); + DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n", smb_fn_name(type), + (int)sys_getpid(), (unsigned long)conn)); smb_dump(smb_fn_name(type), 1, inbuf, size); @@ -946,7 +945,8 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize * really ugly bugfix for problems with multiple session_setup_and_X's * being done and allowing %U and %G substitutions to work correctly. * There is a reason this code is done here, don't move it unless you - * know what you're doing... :-). JRA. + * know what you're doing... :-). + * JRA. */ if (session_tag != last_session_tag) { @@ -954,7 +954,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize last_session_tag = session_tag; if(session_tag != UID_FIELD_INVALID) { - vuser = get_valid_user_struct(session_tag); + vuser = get_valid_user_struct(session_tag); if (vuser) { set_current_user_info(&vuser->user); } @@ -966,7 +966,10 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* Does this call need a valid tree connection? */ if (!conn) { - /* Amazingly, the error code depends on the command (from Samba4). */ + /* + * Amazingly, the error code depends on the command + * (from Samba4). + */ if (type == SMBntcreateX) { return ERROR_NT(NT_STATUS_INVALID_HANDLE); } else { @@ -996,7 +999,9 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* load service specific parameters */ if (conn) { - if (!set_current_service(conn,SVAL(inbuf,smb_flg),(flags & (AS_USER|DO_CHDIR)?True:False))) { + if (!set_current_service(conn,SVAL(inbuf,smb_flg), + (flags & (AS_USER|DO_CHDIR) + ?True:False))) { return(ERROR_DOS(ERRSRV,ERRaccess)); } conn->num_smb_operations++; @@ -1004,17 +1009,19 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* does this protocol need to be run as guest? */ if ((flags & AS_GUEST) - && (!change_to_guest() || + && (!change_to_guest() || !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) { return(ERROR_DOS(ERRSRV,ERRaccess)); } - current_inbuf = inbuf; /* In case we need to defer this message in open... */ + current_inbuf = inbuf; /* In case we need to defer this message in + * open... */ outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); done: smb_dump(smb_fn_name(type), 0, outbuf, outsize); + return(outsize); } -- cgit From cc6a41017c577742af73b4bc60993d8d415ea580 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 23 Jul 2007 09:36:09 +0000 Subject: r23997: Check in the infrastructure for getting rid of the global InBuffer/OutBuffer The complete history of this patch can be found under http://www.samba.org/~vlendec/inbuf-checkin/. Jeremy, Jerry: If possible I would like to see this in 3.2.0. I'm only checking into 3_2 at the moment, as it currently will slow down operations for all non-converted (i.e. all at this moment) operations, as it will copy the talloc'ed inbuf over the global InBuffer. It will need quite a bit of effort to convert everything necessary for the normal operations an XP box does. I have patches for negprot, session setup, tcon_and_X, open_and_X, close. More to come, but I would appreciate some help here. Volker (This used to be commit 5594af2b208c860d3f4b453af6a649d9e4295d1c) --- source3/smbd/process.c | 968 ++++++++++++++++++++++++++++++------------------- 1 file changed, 595 insertions(+), 373 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 558d403948..4a846e9708 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -23,9 +23,14 @@ extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; +const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); + static char *InBuffer = NULL; static char *OutBuffer = NULL; -static char *current_inbuf = NULL; +static const char *current_inbuf = NULL; + +static char *NewInBuffer(char **old_inbuf); +static char *NewOutBuffer(char **old_outbuf); /* * Size of data we can send to client. Set @@ -56,6 +61,10 @@ void init_smb_request(struct smb_request *req, const uint8 *inbuf) req->smbpid = SVAL(inbuf, smb_pid); req->mid = SVAL(inbuf, smb_mid); req->vuid = SVAL(inbuf, smb_uid); + req->tid = SVAL(inbuf, smb_tid); + req->wct = CVAL(inbuf, smb_wct); + req->inbuf = inbuf; + req->outbuf = NULL; } /**************************************************************************** @@ -70,7 +79,7 @@ static struct pending_message_list *deferred_open_queue; ready for processing. ****************************************************************************/ -static BOOL push_queued_message(char *buf, int msg_len, +static BOOL push_queued_message(const char *buf, int msg_len, struct timeval request_time, struct timeval end_time, char *private_data, size_t private_len) @@ -357,12 +366,14 @@ static int select_on_fd(int fd, int maxfd, fd_set *fds) The timeout is in milliseconds ****************************************************************************/ -static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) +static BOOL receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, + size_t *buffer_len, int timeout) { fd_set r_fds, w_fds; int selrtn; struct timeval to; int maxfd = 0; + ssize_t len; smb_read_error = 0; @@ -413,8 +424,16 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) } if (pop_message) { - memcpy(buffer, msg->buf.data, MIN(buffer_len, msg->buf.length)); - + + *buffer = (char *)talloc_memdup(mem_ctx, msg->buf.data, + msg->buf.length); + if (*buffer == NULL) { + DEBUG(0, ("talloc failed\n")); + smb_read_error = READ_ERROR; + return False; + } + *buffer_len = msg->buf.length; + /* We leave this message on the queue so the open code can know this is a retry. */ DEBUG(5,("receive_message_or_smb: returning deferred open smb message.\n")); @@ -530,7 +549,15 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout) goto again; } - return receive_smb(smbd_server_fd(), buffer, 0); + len = receive_smb_talloc(mem_ctx, smbd_server_fd(), buffer, 0); + + if (len == -1) { + return False; + } + + *buffer_len = (size_t)len; + + return True; } /* @@ -603,273 +630,301 @@ force write permissions on print services. static const struct smb_message_struct { const char *name; int (*fn)(connection_struct *conn, char *, char *, int, int); + void (*fn_new)(connection_struct *conn, struct smb_request *req); int flags; } smb_messages[256] = { -/* 0x00 */ { "SMBmkdir",reply_mkdir,AS_USER | NEED_WRITE}, -/* 0x01 */ { "SMBrmdir",reply_rmdir,AS_USER | NEED_WRITE}, -/* 0x02 */ { "SMBopen",reply_open,AS_USER }, -/* 0x03 */ { "SMBcreate",reply_mknew,AS_USER}, -/* 0x04 */ { "SMBclose",reply_close,AS_USER | CAN_IPC }, -/* 0x05 */ { "SMBflush",reply_flush,AS_USER}, -/* 0x06 */ { "SMBunlink",reply_unlink,AS_USER | NEED_WRITE }, -/* 0x07 */ { "SMBmv",reply_mv,AS_USER | NEED_WRITE }, -/* 0x08 */ { "SMBgetatr",reply_getatr,AS_USER}, -/* 0x09 */ { "SMBsetatr",reply_setatr,AS_USER | NEED_WRITE}, -/* 0x0a */ { "SMBread",reply_read,AS_USER}, -/* 0x0b */ { "SMBwrite",reply_write,AS_USER | CAN_IPC }, -/* 0x0c */ { "SMBlock",reply_lock,AS_USER}, -/* 0x0d */ { "SMBunlock",reply_unlock,AS_USER}, -/* 0x0e */ { "SMBctemp",reply_ctemp,AS_USER }, -/* 0x0f */ { "SMBmknew",reply_mknew,AS_USER}, -/* 0x10 */ { "SMBcheckpath",reply_checkpath,AS_USER}, -/* 0x11 */ { "SMBexit",reply_exit,DO_CHDIR}, -/* 0x12 */ { "SMBlseek",reply_lseek,AS_USER}, -/* 0x13 */ { "SMBlockread",reply_lockread,AS_USER}, -/* 0x14 */ { "SMBwriteunlock",reply_writeunlock,AS_USER}, -/* 0x15 */ { NULL, NULL, 0 }, -/* 0x16 */ { NULL, NULL, 0 }, -/* 0x17 */ { NULL, NULL, 0 }, -/* 0x18 */ { NULL, NULL, 0 }, -/* 0x19 */ { NULL, NULL, 0 }, -/* 0x1a */ { "SMBreadbraw",reply_readbraw,AS_USER}, -/* 0x1b */ { "SMBreadBmpx",reply_readbmpx,AS_USER}, -/* 0x1c */ { "SMBreadBs",NULL,0 }, -/* 0x1d */ { "SMBwritebraw",reply_writebraw,AS_USER}, -/* 0x1e */ { "SMBwriteBmpx",reply_writebmpx,AS_USER}, -/* 0x1f */ { "SMBwriteBs",reply_writebs,AS_USER}, -/* 0x20 */ { "SMBwritec",NULL,0}, -/* 0x21 */ { NULL, NULL, 0 }, -/* 0x22 */ { "SMBsetattrE",reply_setattrE,AS_USER | NEED_WRITE }, -/* 0x23 */ { "SMBgetattrE",reply_getattrE,AS_USER }, -/* 0x24 */ { "SMBlockingX",reply_lockingX,AS_USER }, -/* 0x25 */ { "SMBtrans",reply_trans,AS_USER | CAN_IPC }, -/* 0x26 */ { "SMBtranss",reply_transs,AS_USER | CAN_IPC}, -/* 0x27 */ { "SMBioctl",reply_ioctl,0}, -/* 0x28 */ { "SMBioctls",NULL,AS_USER}, -/* 0x29 */ { "SMBcopy",reply_copy,AS_USER | NEED_WRITE }, -/* 0x2a */ { "SMBmove",NULL,AS_USER | NEED_WRITE }, -/* 0x2b */ { "SMBecho",reply_echo,0}, -/* 0x2c */ { "SMBwriteclose",reply_writeclose,AS_USER}, -/* 0x2d */ { "SMBopenX",reply_open_and_X,AS_USER | CAN_IPC }, -/* 0x2e */ { "SMBreadX",reply_read_and_X,AS_USER | CAN_IPC }, -/* 0x2f */ { "SMBwriteX",reply_write_and_X,AS_USER | CAN_IPC }, -/* 0x30 */ { NULL, NULL, 0 }, -/* 0x31 */ { NULL, NULL, 0 }, -/* 0x32 */ { "SMBtrans2", reply_trans2, AS_USER | CAN_IPC }, -/* 0x33 */ { "SMBtranss2", reply_transs2, AS_USER}, -/* 0x34 */ { "SMBfindclose", reply_findclose,AS_USER}, -/* 0x35 */ { "SMBfindnclose", reply_findnclose, AS_USER}, -/* 0x36 */ { NULL, NULL, 0 }, -/* 0x37 */ { NULL, NULL, 0 }, -/* 0x38 */ { NULL, NULL, 0 }, -/* 0x39 */ { NULL, NULL, 0 }, -/* 0x3a */ { NULL, NULL, 0 }, -/* 0x3b */ { NULL, NULL, 0 }, -/* 0x3c */ { NULL, NULL, 0 }, -/* 0x3d */ { NULL, NULL, 0 }, -/* 0x3e */ { NULL, NULL, 0 }, -/* 0x3f */ { NULL, NULL, 0 }, -/* 0x40 */ { NULL, NULL, 0 }, -/* 0x41 */ { NULL, NULL, 0 }, -/* 0x42 */ { NULL, NULL, 0 }, -/* 0x43 */ { NULL, NULL, 0 }, -/* 0x44 */ { NULL, NULL, 0 }, -/* 0x45 */ { NULL, NULL, 0 }, -/* 0x46 */ { NULL, NULL, 0 }, -/* 0x47 */ { NULL, NULL, 0 }, -/* 0x48 */ { NULL, NULL, 0 }, -/* 0x49 */ { NULL, NULL, 0 }, -/* 0x4a */ { NULL, NULL, 0 }, -/* 0x4b */ { NULL, NULL, 0 }, -/* 0x4c */ { NULL, NULL, 0 }, -/* 0x4d */ { NULL, NULL, 0 }, -/* 0x4e */ { NULL, NULL, 0 }, -/* 0x4f */ { NULL, NULL, 0 }, -/* 0x50 */ { NULL, NULL, 0 }, -/* 0x51 */ { NULL, NULL, 0 }, -/* 0x52 */ { NULL, NULL, 0 }, -/* 0x53 */ { NULL, NULL, 0 }, -/* 0x54 */ { NULL, NULL, 0 }, -/* 0x55 */ { NULL, NULL, 0 }, -/* 0x56 */ { NULL, NULL, 0 }, -/* 0x57 */ { NULL, NULL, 0 }, -/* 0x58 */ { NULL, NULL, 0 }, -/* 0x59 */ { NULL, NULL, 0 }, -/* 0x5a */ { NULL, NULL, 0 }, -/* 0x5b */ { NULL, NULL, 0 }, -/* 0x5c */ { NULL, NULL, 0 }, -/* 0x5d */ { NULL, NULL, 0 }, -/* 0x5e */ { NULL, NULL, 0 }, -/* 0x5f */ { NULL, NULL, 0 }, -/* 0x60 */ { NULL, NULL, 0 }, -/* 0x61 */ { NULL, NULL, 0 }, -/* 0x62 */ { NULL, NULL, 0 }, -/* 0x63 */ { NULL, NULL, 0 }, -/* 0x64 */ { NULL, NULL, 0 }, -/* 0x65 */ { NULL, NULL, 0 }, -/* 0x66 */ { NULL, NULL, 0 }, -/* 0x67 */ { NULL, NULL, 0 }, -/* 0x68 */ { NULL, NULL, 0 }, -/* 0x69 */ { NULL, NULL, 0 }, -/* 0x6a */ { NULL, NULL, 0 }, -/* 0x6b */ { NULL, NULL, 0 }, -/* 0x6c */ { NULL, NULL, 0 }, -/* 0x6d */ { NULL, NULL, 0 }, -/* 0x6e */ { NULL, NULL, 0 }, -/* 0x6f */ { NULL, NULL, 0 }, -/* 0x70 */ { "SMBtcon",reply_tcon,0}, -/* 0x71 */ { "SMBtdis",reply_tdis,DO_CHDIR}, -/* 0x72 */ { "SMBnegprot",reply_negprot,0}, -/* 0x73 */ { "SMBsesssetupX",reply_sesssetup_and_X,0}, -/* 0x74 */ { "SMBulogoffX", reply_ulogoffX, 0}, /* ulogoff doesn't give a valid TID */ -/* 0x75 */ { "SMBtconX",reply_tcon_and_X,0}, -/* 0x76 */ { NULL, NULL, 0 }, -/* 0x77 */ { NULL, NULL, 0 }, -/* 0x78 */ { NULL, NULL, 0 }, -/* 0x79 */ { NULL, NULL, 0 }, -/* 0x7a */ { NULL, NULL, 0 }, -/* 0x7b */ { NULL, NULL, 0 }, -/* 0x7c */ { NULL, NULL, 0 }, -/* 0x7d */ { NULL, NULL, 0 }, -/* 0x7e */ { NULL, NULL, 0 }, -/* 0x7f */ { NULL, NULL, 0 }, -/* 0x80 */ { "SMBdskattr",reply_dskattr,AS_USER}, -/* 0x81 */ { "SMBsearch",reply_search,AS_USER}, -/* 0x82 */ { "SMBffirst",reply_search,AS_USER}, -/* 0x83 */ { "SMBfunique",reply_search,AS_USER}, -/* 0x84 */ { "SMBfclose",reply_fclose,AS_USER}, -/* 0x85 */ { NULL, NULL, 0 }, -/* 0x86 */ { NULL, NULL, 0 }, -/* 0x87 */ { NULL, NULL, 0 }, -/* 0x88 */ { NULL, NULL, 0 }, -/* 0x89 */ { NULL, NULL, 0 }, -/* 0x8a */ { NULL, NULL, 0 }, -/* 0x8b */ { NULL, NULL, 0 }, -/* 0x8c */ { NULL, NULL, 0 }, -/* 0x8d */ { NULL, NULL, 0 }, -/* 0x8e */ { NULL, NULL, 0 }, -/* 0x8f */ { NULL, NULL, 0 }, -/* 0x90 */ { NULL, NULL, 0 }, -/* 0x91 */ { NULL, NULL, 0 }, -/* 0x92 */ { NULL, NULL, 0 }, -/* 0x93 */ { NULL, NULL, 0 }, -/* 0x94 */ { NULL, NULL, 0 }, -/* 0x95 */ { NULL, NULL, 0 }, -/* 0x96 */ { NULL, NULL, 0 }, -/* 0x97 */ { NULL, NULL, 0 }, -/* 0x98 */ { NULL, NULL, 0 }, -/* 0x99 */ { NULL, NULL, 0 }, -/* 0x9a */ { NULL, NULL, 0 }, -/* 0x9b */ { NULL, NULL, 0 }, -/* 0x9c */ { NULL, NULL, 0 }, -/* 0x9d */ { NULL, NULL, 0 }, -/* 0x9e */ { NULL, NULL, 0 }, -/* 0x9f */ { NULL, NULL, 0 }, -/* 0xa0 */ { "SMBnttrans", reply_nttrans, AS_USER | CAN_IPC }, -/* 0xa1 */ { "SMBnttranss", reply_nttranss, AS_USER | CAN_IPC }, -/* 0xa2 */ { "SMBntcreateX", reply_ntcreate_and_X, AS_USER | CAN_IPC }, -/* 0xa3 */ { NULL, NULL, 0 }, -/* 0xa4 */ { "SMBntcancel", reply_ntcancel, 0 }, -/* 0xa5 */ { "SMBntrename", reply_ntrename, AS_USER | NEED_WRITE }, -/* 0xa6 */ { NULL, NULL, 0 }, -/* 0xa7 */ { NULL, NULL, 0 }, -/* 0xa8 */ { NULL, NULL, 0 }, -/* 0xa9 */ { NULL, NULL, 0 }, -/* 0xaa */ { NULL, NULL, 0 }, -/* 0xab */ { NULL, NULL, 0 }, -/* 0xac */ { NULL, NULL, 0 }, -/* 0xad */ { NULL, NULL, 0 }, -/* 0xae */ { NULL, NULL, 0 }, -/* 0xaf */ { NULL, NULL, 0 }, -/* 0xb0 */ { NULL, NULL, 0 }, -/* 0xb1 */ { NULL, NULL, 0 }, -/* 0xb2 */ { NULL, NULL, 0 }, -/* 0xb3 */ { NULL, NULL, 0 }, -/* 0xb4 */ { NULL, NULL, 0 }, -/* 0xb5 */ { NULL, NULL, 0 }, -/* 0xb6 */ { NULL, NULL, 0 }, -/* 0xb7 */ { NULL, NULL, 0 }, -/* 0xb8 */ { NULL, NULL, 0 }, -/* 0xb9 */ { NULL, NULL, 0 }, -/* 0xba */ { NULL, NULL, 0 }, -/* 0xbb */ { NULL, NULL, 0 }, -/* 0xbc */ { NULL, NULL, 0 }, -/* 0xbd */ { NULL, NULL, 0 }, -/* 0xbe */ { NULL, NULL, 0 }, -/* 0xbf */ { NULL, NULL, 0 }, -/* 0xc0 */ { "SMBsplopen",reply_printopen,AS_USER}, -/* 0xc1 */ { "SMBsplwr",reply_printwrite,AS_USER}, -/* 0xc2 */ { "SMBsplclose",reply_printclose,AS_USER}, -/* 0xc3 */ { "SMBsplretq",reply_printqueue,AS_USER}, -/* 0xc4 */ { NULL, NULL, 0 }, -/* 0xc5 */ { NULL, NULL, 0 }, -/* 0xc6 */ { NULL, NULL, 0 }, -/* 0xc7 */ { NULL, NULL, 0 }, -/* 0xc8 */ { NULL, NULL, 0 }, -/* 0xc9 */ { NULL, NULL, 0 }, -/* 0xca */ { NULL, NULL, 0 }, -/* 0xcb */ { NULL, NULL, 0 }, -/* 0xcc */ { NULL, NULL, 0 }, -/* 0xcd */ { NULL, NULL, 0 }, -/* 0xce */ { NULL, NULL, 0 }, -/* 0xcf */ { NULL, NULL, 0 }, -/* 0xd0 */ { "SMBsends",reply_sends,AS_GUEST}, -/* 0xd1 */ { "SMBsendb",NULL,AS_GUEST}, -/* 0xd2 */ { "SMBfwdname",NULL,AS_GUEST}, -/* 0xd3 */ { "SMBcancelf",NULL,AS_GUEST}, -/* 0xd4 */ { "SMBgetmac",NULL,AS_GUEST}, -/* 0xd5 */ { "SMBsendstrt",reply_sendstrt,AS_GUEST}, -/* 0xd6 */ { "SMBsendend",reply_sendend,AS_GUEST}, -/* 0xd7 */ { "SMBsendtxt",reply_sendtxt,AS_GUEST}, -/* 0xd8 */ { NULL, NULL, 0 }, -/* 0xd9 */ { NULL, NULL, 0 }, -/* 0xda */ { NULL, NULL, 0 }, -/* 0xdb */ { NULL, NULL, 0 }, -/* 0xdc */ { NULL, NULL, 0 }, -/* 0xdd */ { NULL, NULL, 0 }, -/* 0xde */ { NULL, NULL, 0 }, -/* 0xdf */ { NULL, NULL, 0 }, -/* 0xe0 */ { NULL, NULL, 0 }, -/* 0xe1 */ { NULL, NULL, 0 }, -/* 0xe2 */ { NULL, NULL, 0 }, -/* 0xe3 */ { NULL, NULL, 0 }, -/* 0xe4 */ { NULL, NULL, 0 }, -/* 0xe5 */ { NULL, NULL, 0 }, -/* 0xe6 */ { NULL, NULL, 0 }, -/* 0xe7 */ { NULL, NULL, 0 }, -/* 0xe8 */ { NULL, NULL, 0 }, -/* 0xe9 */ { NULL, NULL, 0 }, -/* 0xea */ { NULL, NULL, 0 }, -/* 0xeb */ { NULL, NULL, 0 }, -/* 0xec */ { NULL, NULL, 0 }, -/* 0xed */ { NULL, NULL, 0 }, -/* 0xee */ { NULL, NULL, 0 }, -/* 0xef */ { NULL, NULL, 0 }, -/* 0xf0 */ { NULL, NULL, 0 }, -/* 0xf1 */ { NULL, NULL, 0 }, -/* 0xf2 */ { NULL, NULL, 0 }, -/* 0xf3 */ { NULL, NULL, 0 }, -/* 0xf4 */ { NULL, NULL, 0 }, -/* 0xf5 */ { NULL, NULL, 0 }, -/* 0xf6 */ { NULL, NULL, 0 }, -/* 0xf7 */ { NULL, NULL, 0 }, -/* 0xf8 */ { NULL, NULL, 0 }, -/* 0xf9 */ { NULL, NULL, 0 }, -/* 0xfa */ { NULL, NULL, 0 }, -/* 0xfb */ { NULL, NULL, 0 }, -/* 0xfc */ { NULL, NULL, 0 }, -/* 0xfd */ { NULL, NULL, 0 }, -/* 0xfe */ { NULL, NULL, 0 }, -/* 0xff */ { NULL, NULL, 0 } +/* 0x00 */ { "SMBmkdir",reply_mkdir,NULL,AS_USER | NEED_WRITE}, +/* 0x01 */ { "SMBrmdir",reply_rmdir,NULL,AS_USER | NEED_WRITE}, +/* 0x02 */ { "SMBopen",reply_open,NULL,AS_USER }, +/* 0x03 */ { "SMBcreate",reply_mknew,NULL,AS_USER}, +/* 0x04 */ { "SMBclose",reply_close,NULL,AS_USER | CAN_IPC }, +/* 0x05 */ { "SMBflush",reply_flush,NULL,AS_USER}, +/* 0x06 */ { "SMBunlink",reply_unlink,NULL,AS_USER | NEED_WRITE }, +/* 0x07 */ { "SMBmv",reply_mv,NULL,AS_USER | NEED_WRITE }, +/* 0x08 */ { "SMBgetatr",reply_getatr,NULL,AS_USER}, +/* 0x09 */ { "SMBsetatr",reply_setatr,NULL,AS_USER | NEED_WRITE}, +/* 0x0a */ { "SMBread",reply_read,NULL,AS_USER}, +/* 0x0b */ { "SMBwrite",reply_write,NULL,AS_USER | CAN_IPC }, +/* 0x0c */ { "SMBlock",reply_lock,NULL,AS_USER}, +/* 0x0d */ { "SMBunlock",reply_unlock,NULL,AS_USER}, +/* 0x0e */ { "SMBctemp",reply_ctemp,NULL,AS_USER }, +/* 0x0f */ { "SMBmknew",reply_mknew,NULL,AS_USER}, +/* 0x10 */ { "SMBcheckpath",reply_checkpath,NULL,AS_USER}, +/* 0x11 */ { "SMBexit",reply_exit,NULL,DO_CHDIR}, +/* 0x12 */ { "SMBlseek",reply_lseek,NULL,AS_USER}, +/* 0x13 */ { "SMBlockread",reply_lockread,NULL,AS_USER}, +/* 0x14 */ { "SMBwriteunlock",reply_writeunlock,NULL,AS_USER}, +/* 0x15 */ { NULL, NULL, NULL, 0 }, +/* 0x16 */ { NULL, NULL, NULL, 0 }, +/* 0x17 */ { NULL, NULL, NULL, 0 }, +/* 0x18 */ { NULL, NULL, NULL, 0 }, +/* 0x19 */ { NULL, NULL, NULL, 0 }, +/* 0x1a */ { "SMBreadbraw",reply_readbraw,NULL,AS_USER}, +/* 0x1b */ { "SMBreadBmpx",reply_readbmpx,NULL,AS_USER}, +/* 0x1c */ { "SMBreadBs",NULL, NULL,0 }, +/* 0x1d */ { "SMBwritebraw",reply_writebraw,NULL,AS_USER}, +/* 0x1e */ { "SMBwriteBmpx",reply_writebmpx,NULL,AS_USER}, +/* 0x1f */ { "SMBwriteBs",reply_writebs,NULL,AS_USER}, +/* 0x20 */ { "SMBwritec",NULL, NULL,0}, +/* 0x21 */ { NULL, NULL, NULL, 0 }, +/* 0x22 */ { "SMBsetattrE",reply_setattrE,NULL,AS_USER | NEED_WRITE }, +/* 0x23 */ { "SMBgetattrE",reply_getattrE,NULL,AS_USER }, +/* 0x24 */ { "SMBlockingX",reply_lockingX,NULL,AS_USER }, +/* 0x25 */ { "SMBtrans",reply_trans,NULL,AS_USER | CAN_IPC }, +/* 0x26 */ { "SMBtranss",reply_transs,NULL,AS_USER | CAN_IPC}, +/* 0x27 */ { "SMBioctl",reply_ioctl,NULL,0}, +/* 0x28 */ { "SMBioctls",NULL, NULL,AS_USER}, +/* 0x29 */ { "SMBcopy",reply_copy,NULL,AS_USER | NEED_WRITE }, +/* 0x2a */ { "SMBmove",NULL, NULL,AS_USER | NEED_WRITE }, +/* 0x2b */ { "SMBecho",reply_echo,NULL,0}, +/* 0x2c */ { "SMBwriteclose",reply_writeclose,NULL,AS_USER}, +/* 0x2d */ { "SMBopenX",reply_open_and_X,NULL,AS_USER | CAN_IPC }, +/* 0x2e */ { "SMBreadX",reply_read_and_X,NULL,AS_USER | CAN_IPC }, +/* 0x2f */ { "SMBwriteX",reply_write_and_X,NULL,AS_USER | CAN_IPC }, +/* 0x30 */ { NULL, NULL, NULL, 0 }, +/* 0x31 */ { NULL, NULL, NULL, 0 }, +/* 0x32 */ { "SMBtrans2", reply_trans2,NULL, AS_USER | CAN_IPC }, +/* 0x33 */ { "SMBtranss2", reply_transs2,NULL, AS_USER}, +/* 0x34 */ { "SMBfindclose", reply_findclose,NULL,AS_USER}, +/* 0x35 */ { "SMBfindnclose", reply_findnclose,NULL, AS_USER}, +/* 0x36 */ { NULL, NULL, NULL, 0 }, +/* 0x37 */ { NULL, NULL, NULL, 0 }, +/* 0x38 */ { NULL, NULL, NULL, 0 }, +/* 0x39 */ { NULL, NULL, NULL, 0 }, +/* 0x3a */ { NULL, NULL, NULL, 0 }, +/* 0x3b */ { NULL, NULL, NULL, 0 }, +/* 0x3c */ { NULL, NULL, NULL, 0 }, +/* 0x3d */ { NULL, NULL, NULL, 0 }, +/* 0x3e */ { NULL, NULL, NULL, 0 }, +/* 0x3f */ { NULL, NULL, NULL, 0 }, +/* 0x40 */ { NULL, NULL, NULL, 0 }, +/* 0x41 */ { NULL, NULL, NULL, 0 }, +/* 0x42 */ { NULL, NULL, NULL, 0 }, +/* 0x43 */ { NULL, NULL, NULL, 0 }, +/* 0x44 */ { NULL, NULL, NULL, 0 }, +/* 0x45 */ { NULL, NULL, NULL, 0 }, +/* 0x46 */ { NULL, NULL, NULL, 0 }, +/* 0x47 */ { NULL, NULL, NULL, 0 }, +/* 0x48 */ { NULL, NULL, NULL, 0 }, +/* 0x49 */ { NULL, NULL, NULL, 0 }, +/* 0x4a */ { NULL, NULL, NULL, 0 }, +/* 0x4b */ { NULL, NULL, NULL, 0 }, +/* 0x4c */ { NULL, NULL, NULL, 0 }, +/* 0x4d */ { NULL, NULL, NULL, 0 }, +/* 0x4e */ { NULL, NULL, NULL, 0 }, +/* 0x4f */ { NULL, NULL, NULL, 0 }, +/* 0x50 */ { NULL, NULL, NULL, 0 }, +/* 0x51 */ { NULL, NULL, NULL, 0 }, +/* 0x52 */ { NULL, NULL, NULL, 0 }, +/* 0x53 */ { NULL, NULL, NULL, 0 }, +/* 0x54 */ { NULL, NULL, NULL, 0 }, +/* 0x55 */ { NULL, NULL, NULL, 0 }, +/* 0x56 */ { NULL, NULL, NULL, 0 }, +/* 0x57 */ { NULL, NULL, NULL, 0 }, +/* 0x58 */ { NULL, NULL, NULL, 0 }, +/* 0x59 */ { NULL, NULL, NULL, 0 }, +/* 0x5a */ { NULL, NULL, NULL, 0 }, +/* 0x5b */ { NULL, NULL, NULL, 0 }, +/* 0x5c */ { NULL, NULL, NULL, 0 }, +/* 0x5d */ { NULL, NULL, NULL, 0 }, +/* 0x5e */ { NULL, NULL, NULL, 0 }, +/* 0x5f */ { NULL, NULL, NULL, 0 }, +/* 0x60 */ { NULL, NULL, NULL, 0 }, +/* 0x61 */ { NULL, NULL, NULL, 0 }, +/* 0x62 */ { NULL, NULL, NULL, 0 }, +/* 0x63 */ { NULL, NULL, NULL, 0 }, +/* 0x64 */ { NULL, NULL, NULL, 0 }, +/* 0x65 */ { NULL, NULL, NULL, 0 }, +/* 0x66 */ { NULL, NULL, NULL, 0 }, +/* 0x67 */ { NULL, NULL, NULL, 0 }, +/* 0x68 */ { NULL, NULL, NULL, 0 }, +/* 0x69 */ { NULL, NULL, NULL, 0 }, +/* 0x6a */ { NULL, NULL, NULL, 0 }, +/* 0x6b */ { NULL, NULL, NULL, 0 }, +/* 0x6c */ { NULL, NULL, NULL, 0 }, +/* 0x6d */ { NULL, NULL, NULL, 0 }, +/* 0x6e */ { NULL, NULL, NULL, 0 }, +/* 0x6f */ { NULL, NULL, NULL, 0 }, +/* 0x70 */ { "SMBtcon",reply_tcon,NULL,0}, +/* 0x71 */ { "SMBtdis",reply_tdis,NULL,DO_CHDIR}, +/* 0x72 */ { "SMBnegprot",reply_negprot,NULL,0}, +/* 0x73 */ { "SMBsesssetupX",reply_sesssetup_and_X,NULL,0}, +/* 0x74 */ { "SMBulogoffX", reply_ulogoffX,NULL, 0}, /* ulogoff doesn't give a valid TID */ +/* 0x75 */ { "SMBtconX",reply_tcon_and_X,NULL,0}, +/* 0x76 */ { NULL, NULL, NULL, 0 }, +/* 0x77 */ { NULL, NULL, NULL, 0 }, +/* 0x78 */ { NULL, NULL, NULL, 0 }, +/* 0x79 */ { NULL, NULL, NULL, 0 }, +/* 0x7a */ { NULL, NULL, NULL, 0 }, +/* 0x7b */ { NULL, NULL, NULL, 0 }, +/* 0x7c */ { NULL, NULL, NULL, 0 }, +/* 0x7d */ { NULL, NULL, NULL, 0 }, +/* 0x7e */ { NULL, NULL, NULL, 0 }, +/* 0x7f */ { NULL, NULL, NULL, 0 }, +/* 0x80 */ { "SMBdskattr",reply_dskattr,NULL,AS_USER}, +/* 0x81 */ { "SMBsearch",reply_search,NULL,AS_USER}, +/* 0x82 */ { "SMBffirst",reply_search,NULL,AS_USER}, +/* 0x83 */ { "SMBfunique",reply_search,NULL,AS_USER}, +/* 0x84 */ { "SMBfclose",reply_fclose,NULL,AS_USER}, +/* 0x85 */ { NULL, NULL, NULL, 0 }, +/* 0x86 */ { NULL, NULL, NULL, 0 }, +/* 0x87 */ { NULL, NULL, NULL, 0 }, +/* 0x88 */ { NULL, NULL, NULL, 0 }, +/* 0x89 */ { NULL, NULL, NULL, 0 }, +/* 0x8a */ { NULL, NULL, NULL, 0 }, +/* 0x8b */ { NULL, NULL, NULL, 0 }, +/* 0x8c */ { NULL, NULL, NULL, 0 }, +/* 0x8d */ { NULL, NULL, NULL, 0 }, +/* 0x8e */ { NULL, NULL, NULL, 0 }, +/* 0x8f */ { NULL, NULL, NULL, 0 }, +/* 0x90 */ { NULL, NULL, NULL, 0 }, +/* 0x91 */ { NULL, NULL, NULL, 0 }, +/* 0x92 */ { NULL, NULL, NULL, 0 }, +/* 0x93 */ { NULL, NULL, NULL, 0 }, +/* 0x94 */ { NULL, NULL, NULL, 0 }, +/* 0x95 */ { NULL, NULL, NULL, 0 }, +/* 0x96 */ { NULL, NULL, NULL, 0 }, +/* 0x97 */ { NULL, NULL, NULL, 0 }, +/* 0x98 */ { NULL, NULL, NULL, 0 }, +/* 0x99 */ { NULL, NULL, NULL, 0 }, +/* 0x9a */ { NULL, NULL, NULL, 0 }, +/* 0x9b */ { NULL, NULL, NULL, 0 }, +/* 0x9c */ { NULL, NULL, NULL, 0 }, +/* 0x9d */ { NULL, NULL, NULL, 0 }, +/* 0x9e */ { NULL, NULL, NULL, 0 }, +/* 0x9f */ { NULL, NULL, NULL, 0 }, +/* 0xa0 */ { "SMBnttrans", reply_nttrans,NULL, AS_USER | CAN_IPC }, +/* 0xa1 */ { "SMBnttranss", reply_nttranss,NULL, AS_USER | CAN_IPC }, +/* 0xa2 */ { "SMBntcreateX", reply_ntcreate_and_X,NULL, AS_USER | CAN_IPC }, +/* 0xa3 */ { NULL, NULL, NULL, 0 }, +/* 0xa4 */ { "SMBntcancel", reply_ntcancel,NULL, 0 }, +/* 0xa5 */ { "SMBntrename", reply_ntrename,NULL, AS_USER | NEED_WRITE }, +/* 0xa6 */ { NULL, NULL, NULL, 0 }, +/* 0xa7 */ { NULL, NULL, NULL, 0 }, +/* 0xa8 */ { NULL, NULL, NULL, 0 }, +/* 0xa9 */ { NULL, NULL, NULL, 0 }, +/* 0xaa */ { NULL, NULL, NULL, 0 }, +/* 0xab */ { NULL, NULL, NULL, 0 }, +/* 0xac */ { NULL, NULL, NULL, 0 }, +/* 0xad */ { NULL, NULL, NULL, 0 }, +/* 0xae */ { NULL, NULL, NULL, 0 }, +/* 0xaf */ { NULL, NULL, NULL, 0 }, +/* 0xb0 */ { NULL, NULL, NULL, 0 }, +/* 0xb1 */ { NULL, NULL, NULL, 0 }, +/* 0xb2 */ { NULL, NULL, NULL, 0 }, +/* 0xb3 */ { NULL, NULL, NULL, 0 }, +/* 0xb4 */ { NULL, NULL, NULL, 0 }, +/* 0xb5 */ { NULL, NULL, NULL, 0 }, +/* 0xb6 */ { NULL, NULL, NULL, 0 }, +/* 0xb7 */ { NULL, NULL, NULL, 0 }, +/* 0xb8 */ { NULL, NULL, NULL, 0 }, +/* 0xb9 */ { NULL, NULL, NULL, 0 }, +/* 0xba */ { NULL, NULL, NULL, 0 }, +/* 0xbb */ { NULL, NULL, NULL, 0 }, +/* 0xbc */ { NULL, NULL, NULL, 0 }, +/* 0xbd */ { NULL, NULL, NULL, 0 }, +/* 0xbe */ { NULL, NULL, NULL, 0 }, +/* 0xbf */ { NULL, NULL, NULL, 0 }, +/* 0xc0 */ { "SMBsplopen",reply_printopen,NULL,AS_USER}, +/* 0xc1 */ { "SMBsplwr",reply_printwrite,NULL,AS_USER}, +/* 0xc2 */ { "SMBsplclose",reply_printclose,NULL,AS_USER}, +/* 0xc3 */ { "SMBsplretq",reply_printqueue,NULL,AS_USER}, +/* 0xc4 */ { NULL, NULL, NULL, 0 }, +/* 0xc5 */ { NULL, NULL, NULL, 0 }, +/* 0xc6 */ { NULL, NULL, NULL, 0 }, +/* 0xc7 */ { NULL, NULL, NULL, 0 }, +/* 0xc8 */ { NULL, NULL, NULL, 0 }, +/* 0xc9 */ { NULL, NULL, NULL, 0 }, +/* 0xca */ { NULL, NULL, NULL, 0 }, +/* 0xcb */ { NULL, NULL, NULL, 0 }, +/* 0xcc */ { NULL, NULL, NULL, 0 }, +/* 0xcd */ { NULL, NULL, NULL, 0 }, +/* 0xce */ { NULL, NULL, NULL, 0 }, +/* 0xcf */ { NULL, NULL, NULL, 0 }, +/* 0xd0 */ { "SMBsends",reply_sends,NULL,AS_GUEST}, +/* 0xd1 */ { "SMBsendb",NULL, NULL,AS_GUEST}, +/* 0xd2 */ { "SMBfwdname",NULL, NULL,AS_GUEST}, +/* 0xd3 */ { "SMBcancelf",NULL, NULL,AS_GUEST}, +/* 0xd4 */ { "SMBgetmac",NULL, NULL,AS_GUEST}, +/* 0xd5 */ { "SMBsendstrt",reply_sendstrt,NULL,AS_GUEST}, +/* 0xd6 */ { "SMBsendend",reply_sendend,NULL,AS_GUEST}, +/* 0xd7 */ { "SMBsendtxt",reply_sendtxt,NULL,AS_GUEST}, +/* 0xd8 */ { NULL, NULL, NULL, 0 }, +/* 0xd9 */ { NULL, NULL, NULL, 0 }, +/* 0xda */ { NULL, NULL, NULL, 0 }, +/* 0xdb */ { NULL, NULL, NULL, 0 }, +/* 0xdc */ { NULL, NULL, NULL, 0 }, +/* 0xdd */ { NULL, NULL, NULL, 0 }, +/* 0xde */ { NULL, NULL, NULL, 0 }, +/* 0xdf */ { NULL, NULL, NULL, 0 }, +/* 0xe0 */ { NULL, NULL, NULL, 0 }, +/* 0xe1 */ { NULL, NULL, NULL, 0 }, +/* 0xe2 */ { NULL, NULL, NULL, 0 }, +/* 0xe3 */ { NULL, NULL, NULL, 0 }, +/* 0xe4 */ { NULL, NULL, NULL, 0 }, +/* 0xe5 */ { NULL, NULL, NULL, 0 }, +/* 0xe6 */ { NULL, NULL, NULL, 0 }, +/* 0xe7 */ { NULL, NULL, NULL, 0 }, +/* 0xe8 */ { NULL, NULL, NULL, 0 }, +/* 0xe9 */ { NULL, NULL, NULL, 0 }, +/* 0xea */ { NULL, NULL, NULL, 0 }, +/* 0xeb */ { NULL, NULL, NULL, 0 }, +/* 0xec */ { NULL, NULL, NULL, 0 }, +/* 0xed */ { NULL, NULL, NULL, 0 }, +/* 0xee */ { NULL, NULL, NULL, 0 }, +/* 0xef */ { NULL, NULL, NULL, 0 }, +/* 0xf0 */ { NULL, NULL, NULL, 0 }, +/* 0xf1 */ { NULL, NULL, NULL, 0 }, +/* 0xf2 */ { NULL, NULL, NULL, 0 }, +/* 0xf3 */ { NULL, NULL, NULL, 0 }, +/* 0xf4 */ { NULL, NULL, NULL, 0 }, +/* 0xf5 */ { NULL, NULL, NULL, 0 }, +/* 0xf6 */ { NULL, NULL, NULL, 0 }, +/* 0xf7 */ { NULL, NULL, NULL, 0 }, +/* 0xf8 */ { NULL, NULL, NULL, 0 }, +/* 0xf9 */ { NULL, NULL, NULL, 0 }, +/* 0xfa */ { NULL, NULL, NULL, 0 }, +/* 0xfb */ { NULL, NULL, NULL, 0 }, +/* 0xfc */ { NULL, NULL, NULL, 0 }, +/* 0xfd */ { NULL, NULL, NULL, 0 }, +/* 0xfe */ { NULL, NULL, NULL, 0 }, +/* 0xff */ { NULL, NULL, NULL, 0 } }; +/******************************************************************* + allocate and initialize a reply packet +********************************************************************/ + +void reply_outbuf(struct smb_request *req, uint8 num_words, uint16 num_bytes) +{ + if (!(req->outbuf = TALLOC_ARRAY( + req, uint8, + smb_size + num_words*2 + num_bytes))) { + smb_panic("could not allocate output buffer\n"); + } + + construct_reply_common((char *)req->inbuf, (char *)req->outbuf); + set_message((char *)req->inbuf, (char *)req->outbuf, + num_words, num_bytes, False); + /* + * Zero out the word area, the caller has to take care of the bcc area + * himself + */ + if (num_words != 0) { + memset(req->outbuf + smb_vwv0, 0, num_words*2); + } + + return; +} + + /******************************************************************* Dump a packet to a file. ********************************************************************/ -static void smb_dump(const char *name, int type, char *data, ssize_t len) +static void smb_dump(const char *name, int type, const char *data, ssize_t len) { int fd, i; pstring fname; @@ -891,37 +946,47 @@ static void smb_dump(const char *name, int type, char *data, ssize_t len) } } - /**************************************************************************** - Do a switch on the message type, and return the response size + Prepare everything for calling the actual request function, and potentially + call the request function via the "new" interface. + + Return False if the "legacy" function needs to be called, everything is + prepared. + + Return True if we're done. + + I know this API sucks, but it is the one with the least code change I could + find. ****************************************************************************/ -static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize) +static BOOL switch_message_new(uint8 type, struct smb_request *req, int size, + connection_struct **pconn) { - int outsize = 0; int flags; uint16 session_tag; connection_struct *conn; static uint16 last_session_tag = UID_FIELD_INVALID; - type &= 0xff; - errno = 0; last_message = type; - /* Make sure this is an SMB packet. smb_size contains NetBIOS header so subtract 4 from it. */ - if ((strncmp(smb_base(inbuf),"\377SMB",4) != 0) || (size < (smb_size - 4))) { - DEBUG(2,("Non-SMB packet of length %d. Terminating server\n",smb_len(inbuf))); + /* Make sure this is an SMB packet. smb_size contains NetBIOS header + * so subtract 4 from it. */ + if ((strncmp(smb_base(req->inbuf),"\377SMB",4) != 0) + || (size < (smb_size - 4))) { + DEBUG(2,("Non-SMB packet of length %d. Terminating server\n", + smb_len(req->inbuf))); exit_server_cleanly("Non-SMB packet"); - return(-1); + return True; } - if (smb_messages[type].fn == NULL) { + if ((smb_messages[type].fn == NULL) + && (smb_messages[type].fn_new == NULL)) { DEBUG(0,("Unknown message type %d!\n",type)); - smb_dump("Unknown", 1, inbuf, size); - outsize = reply_unknown(inbuf,outbuf); + smb_dump("Unknown", 1, (char *)req->inbuf, size); + reply_unknown_new(req, type); goto done; } @@ -929,16 +994,16 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* In share mode security we must ignore the vuid. */ session_tag = (lp_security() == SEC_SHARE) - ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid); - conn = conn_find(SVAL(inbuf,smb_tid)); + ? UID_FIELD_INVALID : req->vuid; + conn = conn_find(req->tid); DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n", smb_fn_name(type), (int)sys_getpid(), (unsigned long)conn)); - smb_dump(smb_fn_name(type), 1, inbuf, size); + smb_dump(smb_fn_name(type), 1, (char *)req->inbuf, size); /* Ensure this value is replaced in the incoming packet. */ - SSVAL(inbuf,smb_uid,session_tag); + SSVAL(req->inbuf,smb_uid,session_tag); /* * Ensure the correct username is in current_user_info. This is a @@ -971,26 +1036,30 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize * (from Samba4). */ if (type == SMBntcreateX) { - return ERROR_NT(NT_STATUS_INVALID_HANDLE); + reply_nterror(req, NT_STATUS_INVALID_HANDLE); } else { - return ERROR_DOS(ERRSRV, ERRinvnid); + reply_doserror(req, ERRSRV, ERRinvnid); } + goto done; } if (!change_to_user(conn,session_tag)) { - return(ERROR_NT(NT_STATUS_DOS(ERRSRV,ERRbaduid))); + reply_nterror(req, NT_STATUS_DOS(ERRSRV, ERRbaduid)); + goto done; } /* All NEED_WRITE and CAN_IPC flags must also have AS_USER. */ /* Does it need write permission? */ if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) { - return ERROR_NT(NT_STATUS_MEDIA_WRITE_PROTECTED); + reply_nterror(req, NT_STATUS_MEDIA_WRITE_PROTECTED); + goto done; } /* IPC services are limited */ if (IS_IPC(conn) && !(flags & CAN_IPC)) { - return(ERROR_DOS(ERRSRV,ERRaccess)); + reply_doserror(req, ERRSRV,ERRaccess); + goto done; } } else { /* This call needs to be run as root */ @@ -999,10 +1068,11 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize /* load service specific parameters */ if (conn) { - if (!set_current_service(conn,SVAL(inbuf,smb_flg), + if (!set_current_service(conn,SVAL(req->inbuf,smb_flg), (flags & (AS_USER|DO_CHDIR) ?True:False))) { - return(ERROR_DOS(ERRSRV,ERRaccess)); + reply_doserror(req, ERRSRV, ERRaccess); + goto done; } conn->num_smb_operations++; } @@ -1012,15 +1082,72 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize && (!change_to_guest() || !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) { - return(ERROR_DOS(ERRSRV,ERRaccess)); + reply_doserror(req, ERRSRV, ERRaccess); + goto done; } - current_inbuf = inbuf; /* In case we need to defer this message in - * open... */ - outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); + current_inbuf = (char *)req->inbuf; /* In case we need to defer this + * message in open... */ + + if (smb_messages[type].fn_new != NULL) { + smb_messages[type].fn_new(conn, req); + goto done; + } + + /* + * Indicate the upper layer that there's still work. + */ + *pconn = conn; + return False; done: - smb_dump(smb_fn_name(type), 0, outbuf, outsize); + return True; +} + + +/**************************************************************************** + Do a switch on the message type, and return the response size +****************************************************************************/ + +static int switch_message(uint8 type, struct smb_request *req, char **outbuf, + int size, int bufsize) +{ + int outsize = 0; + connection_struct *conn = NULL; + + if (switch_message_new(type, req, size, &conn)) { + if (req->outbuf != NULL) { + *outbuf = (char *)req->outbuf; + return smb_len(req->outbuf)+4; + } + return -1; + } + + if (InBuffer == NULL) { + DEBUG(1, ("have to alloc InBuffer for %s\n", + smb_fn_name(type))); + if (NewInBuffer(NULL) == NULL) { + smb_panic("Could not allocate InBuffer"); + } + } + + if ((OutBuffer == NULL) && (NewOutBuffer(NULL) == NULL)) { + smb_panic("Could not allocate OutBuffer"); + } + + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, + total_buffer_size); + + memcpy(InBuffer, req->inbuf, MIN(size, total_buffer_size)); + + construct_reply_common(InBuffer, OutBuffer); + + outsize = smb_messages[type].fn(conn, InBuffer, OutBuffer, size, + bufsize); + + smb_dump(smb_fn_name(type), 0, OutBuffer, outsize); + + *outbuf = OutBuffer; return(outsize); } @@ -1029,41 +1156,54 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize Construct a reply to the incoming packet. ****************************************************************************/ -static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) +static void construct_reply(char *inbuf, int size) { - int type = CVAL(inbuf,smb_com); + uint8 type = CVAL(inbuf,smb_com); int outsize = 0; - int msg_type = CVAL(inbuf,0); + struct smb_request *req; + char *outbuf; chain_size = 0; file_chain_reset(); reset_chain_p(); - if (msg_type != 0) - return(reply_special(inbuf,outbuf)); + if (!(req = talloc(tmp_talloc_ctx(), struct smb_request))) { + smb_panic("could not allocate smb_request"); + } + init_smb_request(req, (uint8 *)inbuf); - construct_reply_common(inbuf, outbuf); + outsize = switch_message(type, req, &outbuf, size, max_send); - outsize = switch_message(type,inbuf,outbuf,size,bufsize); + if (outsize > 4) { + smb_setlen(inbuf,outbuf,outsize - 4); + } - outsize += chain_size; + if (outsize > 0) { + if (CVAL(outbuf,0) == 0) + show_msg(outbuf); - if(outsize > 4) { - smb_setlen(inbuf,outbuf,outsize - 4); + if (outsize != smb_len(outbuf) + 4) { + DEBUG(0,("ERROR: Invalid message response size! " + "%d %d\n", outsize, smb_len(outbuf))); + } else if (!send_smb(smbd_server_fd(),outbuf)) { + exit_server_cleanly("construct_reply: send_smb " + "failed."); + } } - return(outsize); + + TALLOC_FREE(req); + + return; } /**************************************************************************** Process an smb from the client ****************************************************************************/ -static void process_smb(char *inbuf, char *outbuf) +static void process_smb(char *inbuf, size_t nread) { static int trans_num; int msg_type = CVAL(inbuf,0); - int32 len = smb_len(inbuf); - int nread = len + 4; DO_PROFILE_INC(smb_count); @@ -1082,27 +1222,22 @@ static void process_smb(char *inbuf, char *outbuf) } } - DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type, len ) ); + DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type, + smb_len(inbuf) ) ); DEBUG( 3, ( "Transaction %d of length %d\n", trans_num, nread ) ); - if (msg_type == 0) - show_msg(inbuf); - else if(msg_type == SMBkeepalive) - return; /* Keepalive packet. */ + if (msg_type != 0) { + /* + * NetBIOS session request, keepalive, etc. + */ + reply_special(inbuf); + return; + } - nread = construct_reply(inbuf,outbuf,nread,max_send); + show_msg(inbuf); + + construct_reply(inbuf,nread); - if(nread > 0) { - if (CVAL(outbuf,0) == 0) - show_msg(outbuf); - - if (nread != smb_len(outbuf) + 4) { - DEBUG(0,("ERROR: Invalid message response size! %d %d\n", - nread, smb_len(outbuf))); - } else if (!send_smb(smbd_server_fd(),outbuf)) { - exit_server_cleanly("process_smb: send_smb failed."); - } - } trans_num++; } @@ -1158,18 +1293,23 @@ void construct_reply_common(const char *inbuf, char *outbuf) Construct a chained reply and add it to the already made reply ****************************************************************************/ -int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) +int chain_reply(char *inbuf,char **poutbuf,int size,int bufsize) { static char *orig_inbuf; - static char *orig_outbuf; int smb_com1, smb_com2 = CVAL(inbuf,smb_vwv0); unsigned smb_off2 = SVAL(inbuf,smb_vwv1); - char *inbuf2, *outbuf2; + char *inbuf2; int outsize2; int new_size; char inbuf_saved[smb_wct]; - char outbuf_saved[smb_wct]; - int outsize = smb_len(outbuf) + 4; + char *outbuf = *poutbuf; + size_t outsize = smb_len(outbuf) + 4; + size_t outsize_padded; + size_t ofs, to_move; + + struct smb_request *req; + size_t caller_outputlen; + char *caller_output; /* Maybe its not chained, or it's an error packet. */ if (smb_com2 == 0xFF || SVAL(outbuf,smb_rcls) != 0) { @@ -1180,7 +1320,20 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) if (chain_size == 0) { /* this is the first part of the chain */ orig_inbuf = inbuf; - orig_outbuf = outbuf; + } + + /* + * We need to save the output the caller added to the chain so that we + * can splice it into the final output buffer later. + */ + + caller_outputlen = outsize - smb_wct; + + caller_output = (char *)memdup(outbuf + smb_wct, caller_outputlen); + + if (caller_output == NULL) { + /* TODO: NT_STATUS_NO_MEMORY */ + smb_panic("could not dup outbuf"); } /* @@ -1189,27 +1342,25 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) * 4 byte aligned. JRA. */ - outsize = (outsize + 3) & ~3; + outsize_padded = (outsize + 3) & ~3; - /* we need to tell the client where the next part of the reply will be */ - SSVAL(outbuf,smb_vwv1,smb_offset(outbuf+outsize,outbuf)); - SCVAL(outbuf,smb_vwv0,smb_com2); - - /* remember how much the caller added to the chain, only counting stuff - after the parameter words */ - chain_size += outsize - smb_wct; + /* + * remember how much the caller added to the chain, only counting + * stuff after the parameter words + */ + chain_size += outsize_padded - smb_wct; - /* work out pointers into the original packets. The - headers on these need to be filled in */ + /* + * work out pointers into the original packets. The + * headers on these need to be filled in + */ inbuf2 = orig_inbuf + smb_off2 + 4 - smb_wct; - outbuf2 = orig_outbuf + SVAL(outbuf,smb_vwv1) + 4 - smb_wct; /* remember the original command type */ smb_com1 = CVAL(orig_inbuf,smb_com); /* save the data which will be overwritten by the new headers */ memcpy(inbuf_saved,inbuf2,smb_wct); - memcpy(outbuf_saved,outbuf2,smb_wct); /* give the new packet the same header as the last part of the SMB */ memmove(inbuf2,inbuf,smb_wct); @@ -1230,34 +1381,112 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize) /* And set it in the header. */ smb_setlen(inbuf, inbuf2, new_size); - /* create the out buffer */ - construct_reply_common(inbuf2, outbuf2); - DEBUG(3,("Chained message\n")); show_msg(inbuf2); + if (!(req = talloc(tmp_talloc_ctx(), struct smb_request))) { + smb_panic("could not allocate smb_request"); + } + init_smb_request(req, (uint8 *)inbuf2); + /* process the request */ - outsize2 = switch_message(smb_com2,inbuf2,outbuf2,new_size, - bufsize-chain_size); + outsize2 = switch_message(smb_com2, req, &outbuf, new_size, + bufsize-chain_size); - /* copy the new reply and request headers over the old ones, but - preserve the smb_com field */ - memmove(orig_outbuf,outbuf2,smb_wct); - SCVAL(orig_outbuf,smb_com,smb_com1); + /* + * We don't accept deferred operations in chained requests. + */ + SMB_ASSERT(outsize2 >= smb_wct); - /* restore the saved data, being careful not to overwrite any - data from the reply header */ - memcpy(inbuf2,inbuf_saved,smb_wct); + /* + * Move away the new command output so that caller_output fits in, + * copy in the caller_output saved above. + */ - { - int ofs = smb_wct - PTR_DIFF(outbuf2,orig_outbuf); - if (ofs < 0) { - ofs = 0; + SMB_ASSERT(outsize_padded >= smb_wct); + + /* + * "ofs" is the space we need for caller_output. Equal to + * caller_outputlen plus the padding. + */ + + ofs = outsize_padded - smb_wct; + + /* + * "to_move" is the amount of bytes the secondary routine gave us + */ + + to_move = outsize2 - smb_wct; + + if (to_move + ofs + smb_wct + chain_size > max_send) { + smb_panic("replies too large -- would have to cut"); + } + + /* + * In the "new" API "outbuf" is allocated via reply_outbuf, just for + * the first request in the chain. So we have to re-allocate it. In + * the "old" API the only outbuf ever used is the global OutBuffer + * which is always large enough. + */ + + if (outbuf != OutBuffer) { + outbuf = TALLOC_REALLOC_ARRAY(NULL, outbuf, char, + to_move + ofs + smb_wct); + if (outbuf == NULL) { + smb_panic("could not realloc outbuf"); } - memmove(outbuf2+ofs,outbuf_saved+ofs,smb_wct-ofs); } - return outsize2; + *poutbuf = outbuf; + + memmove(outbuf + smb_wct + ofs, outbuf + smb_wct, to_move); + memcpy(outbuf + smb_wct, caller_output, caller_outputlen); + + /* + * The secondary function has overwritten smb_com + */ + + SCVAL(outbuf, smb_com, smb_com1); + + /* + * We've just copied in the whole "wct" area from the secondary + * function. Fix up the chaining: com2 and the offset need to be + * readjusted. + */ + + SCVAL(outbuf, smb_vwv0, smb_com2); + SSVAL(outbuf, smb_vwv1, chain_size + smb_wct - 4); + + if (outsize_padded > outsize) { + + /* + * Due to padding we have some uninitialized bytes after the + * caller's output + */ + + memset(outbuf + outsize, 0, outsize_padded - outsize); + } + + smb_setlen(NULL, outbuf, outsize2 + chain_size - 4); + + /* + * restore the saved data, being careful not to overwrite any data + * from the reply header + */ + memcpy(inbuf2,inbuf_saved,smb_wct); + + SAFE_FREE(caller_output); + TALLOC_FREE(req); + + return outsize2 + chain_size; +} + +void chain_reply_new(struct smb_request *req) +{ + chain_reply(CONST_DISCARD(char *, req->inbuf), + (char **)(void *)&req->outbuf, + smb_len(req->inbuf)+4, + smb_len(req->outbuf)+4); } /**************************************************************************** @@ -1450,8 +1679,6 @@ char *get_OutBuffer(void) return OutBuffer; } -const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); - /**************************************************************************** Allocate a new InBuffer. Returns the new and old ones. ****************************************************************************/ @@ -1501,16 +1728,13 @@ void smbd_process(void) time_t last_timeout_processing_time = time(NULL); unsigned int num_smbs = 0; - /* Allocate the primary Inbut/Output buffers. */ - - if ((NewInBuffer(NULL) == NULL) || (NewOutBuffer(NULL) == NULL)) - return; - max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); while (True) { int select_timeout = setup_select_timeout(); int num_echos; + char *inbuf; + size_t inbuf_len; errno = 0; @@ -1528,17 +1752,15 @@ void smbd_process(void) run_events(smbd_event_context(), 0, NULL, NULL); -#if defined(DEVELOPER) - clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); -#endif - - while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) { + while (!receive_message_or_smb(NULL, &inbuf, &inbuf_len, + select_timeout)) { if(!timeout_processing(&select_timeout, &last_timeout_processing_time)) return; num_smbs = 0; /* Reset smb counter. */ } + /* * Ensure we do timeout processing if the SMB we just got was * only an echo request. This allows us to set the select @@ -1550,9 +1772,9 @@ void smbd_process(void) */ num_echos = smb_echo_count; - clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size); + process_smb(inbuf, inbuf_len); - process_smb(InBuffer, OutBuffer); + TALLOC_FREE(inbuf); if (smb_echo_count != num_echos) { if(!timeout_processing( &select_timeout, &last_timeout_processing_time)) -- cgit From 47cdfc0413886780f51fb98b7fca18d7c83b7c23 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 23 Jul 2007 09:53:06 +0000 Subject: r23998: Convert reply_close to the new API (This used to be commit dbf74cb747d34dac571d85d6bae9398558086456) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 4a846e9708..f40caa49ad 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -638,7 +638,7 @@ static const struct smb_message_struct { /* 0x01 */ { "SMBrmdir",reply_rmdir,NULL,AS_USER | NEED_WRITE}, /* 0x02 */ { "SMBopen",reply_open,NULL,AS_USER }, /* 0x03 */ { "SMBcreate",reply_mknew,NULL,AS_USER}, -/* 0x04 */ { "SMBclose",reply_close,NULL,AS_USER | CAN_IPC }, +/* 0x04 */ { "SMBclose",NULL,reply_close,AS_USER | CAN_IPC }, /* 0x05 */ { "SMBflush",reply_flush,NULL,AS_USER}, /* 0x06 */ { "SMBunlink",reply_unlink,NULL,AS_USER | NEED_WRITE }, /* 0x07 */ { "SMBmv",reply_mv,NULL,AS_USER | NEED_WRITE }, -- cgit From 9e40557047b32dae012b0b5a3450c2c23b7895e5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 23 Jul 2007 09:54:36 +0000 Subject: r23999: Convert reply_open_and_X This is an example of chained code that is executed in make test (This used to be commit e3a10e9ffb06f429208f8b8e8482bbfd56dace91) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f40caa49ad..ea8f37563b 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -679,7 +679,7 @@ static const struct smb_message_struct { /* 0x2a */ { "SMBmove",NULL, NULL,AS_USER | NEED_WRITE }, /* 0x2b */ { "SMBecho",reply_echo,NULL,0}, /* 0x2c */ { "SMBwriteclose",reply_writeclose,NULL,AS_USER}, -/* 0x2d */ { "SMBopenX",reply_open_and_X,NULL,AS_USER | CAN_IPC }, +/* 0x2d */ { "SMBopenX",NULL,reply_open_and_X,AS_USER | CAN_IPC }, /* 0x2e */ { "SMBreadX",reply_read_and_X,NULL,AS_USER | CAN_IPC }, /* 0x2f */ { "SMBwriteX",reply_write_and_X,NULL,AS_USER | CAN_IPC }, /* 0x30 */ { NULL, NULL, NULL, 0 }, -- cgit From 3d12c53eb3bf5506b0661fbcaa0d36f90f847c65 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 23 Jul 2007 11:18:20 +0000 Subject: r24002: Convert reply_negprot to the new API (This used to be commit bd981f53282573058bf4c2939e0e836499cf38be) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ea8f37563b..5d37b43321 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -748,7 +748,7 @@ static const struct smb_message_struct { /* 0x6f */ { NULL, NULL, NULL, 0 }, /* 0x70 */ { "SMBtcon",reply_tcon,NULL,0}, /* 0x71 */ { "SMBtdis",reply_tdis,NULL,DO_CHDIR}, -/* 0x72 */ { "SMBnegprot",reply_negprot,NULL,0}, +/* 0x72 */ { "SMBnegprot",NULL,reply_negprot,0}, /* 0x73 */ { "SMBsesssetupX",reply_sesssetup_and_X,NULL,0}, /* 0x74 */ { "SMBulogoffX", reply_ulogoffX,NULL, 0}, /* ulogoff doesn't give a valid TID */ /* 0x75 */ { "SMBtconX",reply_tcon_and_X,NULL,0}, -- cgit From db9f25c1c58cbf17b5b94d598126b019d9e7507e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 23 Jul 2007 11:38:29 +0000 Subject: r24003: Convert reply_tcon_and_X to the new API (This used to be commit 9422385d9c018a0b1f2a0b2edd82dc574a9fb403) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 5d37b43321..2cc8b3976b 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -751,7 +751,7 @@ static const struct smb_message_struct { /* 0x72 */ { "SMBnegprot",NULL,reply_negprot,0}, /* 0x73 */ { "SMBsesssetupX",reply_sesssetup_and_X,NULL,0}, /* 0x74 */ { "SMBulogoffX", reply_ulogoffX,NULL, 0}, /* ulogoff doesn't give a valid TID */ -/* 0x75 */ { "SMBtconX",reply_tcon_and_X,NULL,0}, +/* 0x75 */ { "SMBtconX",NULL,reply_tcon_and_X,0}, /* 0x76 */ { NULL, NULL, NULL, 0 }, /* 0x77 */ { NULL, NULL, NULL, 0 }, /* 0x78 */ { NULL, NULL, NULL, 0 }, -- cgit From 01d5091c26b9edd54023b5d3b0ab00ad93608654 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 23 Jul 2007 12:03:58 +0000 Subject: r24004: Convert reply_checkpath to the new API (This used to be commit e5c7c6406af5552b3060f03a09b5e6c9a42e531c) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2cc8b3976b..41ca060d56 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -650,7 +650,7 @@ static const struct smb_message_struct { /* 0x0d */ { "SMBunlock",reply_unlock,NULL,AS_USER}, /* 0x0e */ { "SMBctemp",reply_ctemp,NULL,AS_USER }, /* 0x0f */ { "SMBmknew",reply_mknew,NULL,AS_USER}, -/* 0x10 */ { "SMBcheckpath",reply_checkpath,NULL,AS_USER}, +/* 0x10 */ { "SMBcheckpath",NULL,reply_checkpath,AS_USER}, /* 0x11 */ { "SMBexit",reply_exit,NULL,DO_CHDIR}, /* 0x12 */ { "SMBlseek",reply_lseek,NULL,AS_USER}, /* 0x13 */ { "SMBlockread",reply_lockread,NULL,AS_USER}, -- cgit From e5cdc454aadf2d3d93d80524d2c84990f239aaa0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 25 Jul 2007 18:39:10 +0000 Subject: r24046: Fix a 64-bit warning (This used to be commit a2ecc34aa43f810e68815c25016da1d184a21a04) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 41ca060d56..1159589e8d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1224,7 +1224,7 @@ static void process_smb(char *inbuf, size_t nread) DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type, smb_len(inbuf) ) ); - DEBUG( 3, ( "Transaction %d of length %d\n", trans_num, nread ) ); + DEBUG( 3, ( "Transaction %d of length %d\n", trans_num, (int)nread ) ); if (msg_type != 0) { /* -- cgit From 7d2d4ddfa2fbd859f35f8f4e2b8243f52a4ace0e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 26 Jul 2007 16:01:12 +0000 Subject: r24056: Another big one: This converts reply_sesssetup_and_X to the new API. As usual, its history can be found on http://samba.org/~vlendec/sesssetup/. This very obviously needs close review. Volker (This used to be commit 35675a6a33d584e5c3c97d1cb5ca9b0315a5fa92) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1159589e8d..85e061710d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -749,7 +749,7 @@ static const struct smb_message_struct { /* 0x70 */ { "SMBtcon",reply_tcon,NULL,0}, /* 0x71 */ { "SMBtdis",reply_tdis,NULL,DO_CHDIR}, /* 0x72 */ { "SMBnegprot",NULL,reply_negprot,0}, -/* 0x73 */ { "SMBsesssetupX",reply_sesssetup_and_X,NULL,0}, +/* 0x73 */ { "SMBsesssetupX",NULL,reply_sesssetup_and_X,0}, /* 0x74 */ { "SMBulogoffX", reply_ulogoffX,NULL, 0}, /* ulogoff doesn't give a valid TID */ /* 0x75 */ { "SMBtconX",NULL,reply_tcon_and_X,0}, /* 0x76 */ { NULL, NULL, NULL, 0 }, -- cgit From 09b3d2525249fd832b7d46a19921a87a13b71407 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 30 Jul 2007 10:20:52 +0000 Subject: r24077: Convert reply_tdis to the new API (This used to be commit bd0cb48dde401f48dec98fa7ca794a912e0244f1) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 85e061710d..fdec2d106d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -747,7 +747,7 @@ static const struct smb_message_struct { /* 0x6e */ { NULL, NULL, NULL, 0 }, /* 0x6f */ { NULL, NULL, NULL, 0 }, /* 0x70 */ { "SMBtcon",reply_tcon,NULL,0}, -/* 0x71 */ { "SMBtdis",reply_tdis,NULL,DO_CHDIR}, +/* 0x71 */ { "SMBtdis",NULL,reply_tdis,DO_CHDIR}, /* 0x72 */ { "SMBnegprot",NULL,reply_negprot,0}, /* 0x73 */ { "SMBsesssetupX",NULL,reply_sesssetup_and_X,0}, /* 0x74 */ { "SMBulogoffX", reply_ulogoffX,NULL, 0}, /* ulogoff doesn't give a valid TID */ -- cgit From ef97e2dece55d84e64bdcbb922939ea28199a2e6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 30 Jul 2007 10:30:19 +0000 Subject: r24079: Convert reply_dskattr to the new API (This used to be commit c8e0aa5752fde34f7271a4fad758dfae0991722d) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index fdec2d106d..971a9d299b 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -762,7 +762,7 @@ static const struct smb_message_struct { /* 0x7d */ { NULL, NULL, NULL, 0 }, /* 0x7e */ { NULL, NULL, NULL, 0 }, /* 0x7f */ { NULL, NULL, NULL, 0 }, -/* 0x80 */ { "SMBdskattr",reply_dskattr,NULL,AS_USER}, +/* 0x80 */ { "SMBdskattr",NULL,reply_dskattr,AS_USER}, /* 0x81 */ { "SMBsearch",reply_search,NULL,AS_USER}, /* 0x82 */ { "SMBffirst",reply_search,NULL,AS_USER}, /* 0x83 */ { "SMBfunique",reply_search,NULL,AS_USER}, -- cgit From 68513d521d930188bb381b1737d3a7130ef2088f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 30 Jul 2007 11:35:39 +0000 Subject: r24084: Convert reply_mkdir to the new API (This used to be commit e93f3996fcdde6f0fbba3fb9e1e97407e9ccdd62) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 971a9d299b..4b0f2902ef 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -634,7 +634,7 @@ static const struct smb_message_struct { int flags; } smb_messages[256] = { -/* 0x00 */ { "SMBmkdir",reply_mkdir,NULL,AS_USER | NEED_WRITE}, +/* 0x00 */ { "SMBmkdir",NULL,reply_mkdir,AS_USER | NEED_WRITE}, /* 0x01 */ { "SMBrmdir",reply_rmdir,NULL,AS_USER | NEED_WRITE}, /* 0x02 */ { "SMBopen",reply_open,NULL,AS_USER }, /* 0x03 */ { "SMBcreate",reply_mknew,NULL,AS_USER}, -- cgit From 4694e757ba084e68e6f5bc3bf2d3714474c215cd Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 30 Jul 2007 14:07:29 +0000 Subject: r24085: Convert reply_rmdir to the new API (This used to be commit 7689048d71cc4adbdaee5521cc57890518e7090a) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 4b0f2902ef..dafea5ed2f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -635,7 +635,7 @@ static const struct smb_message_struct { } smb_messages[256] = { /* 0x00 */ { "SMBmkdir",NULL,reply_mkdir,AS_USER | NEED_WRITE}, -/* 0x01 */ { "SMBrmdir",reply_rmdir,NULL,AS_USER | NEED_WRITE}, +/* 0x01 */ { "SMBrmdir",NULL,reply_rmdir,AS_USER | NEED_WRITE}, /* 0x02 */ { "SMBopen",reply_open,NULL,AS_USER }, /* 0x03 */ { "SMBcreate",reply_mknew,NULL,AS_USER}, /* 0x04 */ { "SMBclose",NULL,reply_close,AS_USER | CAN_IPC }, -- cgit From 8084a39ce0a2b2535c537115a08dd57dec82a102 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 30 Jul 2007 19:53:57 +0000 Subject: r24086: Convert reply_ulogoffX to the new API (This used to be commit bbc99e1c3b764bc2adf620553b7fa85efdf8ac53) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index dafea5ed2f..70276293f8 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -750,7 +750,7 @@ static const struct smb_message_struct { /* 0x71 */ { "SMBtdis",NULL,reply_tdis,DO_CHDIR}, /* 0x72 */ { "SMBnegprot",NULL,reply_negprot,0}, /* 0x73 */ { "SMBsesssetupX",NULL,reply_sesssetup_and_X,0}, -/* 0x74 */ { "SMBulogoffX", reply_ulogoffX,NULL, 0}, /* ulogoff doesn't give a valid TID */ +/* 0x74 */ { "SMBulogoffX", NULL,reply_ulogoffX, 0}, /* ulogoff doesn't give a valid TID */ /* 0x75 */ { "SMBtconX",NULL,reply_tcon_and_X,0}, /* 0x76 */ { NULL, NULL, NULL, 0 }, /* 0x77 */ { NULL, NULL, NULL, 0 }, -- cgit From 4254af71803b122449887258ac0e721f67ed39a3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 31 Jul 2007 07:57:33 +0000 Subject: r24088: Convert reply_unlink to the new API (This used to be commit fb0a1b7bd0a195dbedb3b0c02d8a4ec25c21b9bf) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 70276293f8..e99d70f236 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -640,7 +640,7 @@ static const struct smb_message_struct { /* 0x03 */ { "SMBcreate",reply_mknew,NULL,AS_USER}, /* 0x04 */ { "SMBclose",NULL,reply_close,AS_USER | CAN_IPC }, /* 0x05 */ { "SMBflush",reply_flush,NULL,AS_USER}, -/* 0x06 */ { "SMBunlink",reply_unlink,NULL,AS_USER | NEED_WRITE }, +/* 0x06 */ { "SMBunlink",NULL,reply_unlink,AS_USER | NEED_WRITE }, /* 0x07 */ { "SMBmv",reply_mv,NULL,AS_USER | NEED_WRITE }, /* 0x08 */ { "SMBgetatr",reply_getatr,NULL,AS_USER}, /* 0x09 */ { "SMBsetatr",reply_setatr,NULL,AS_USER | NEED_WRITE}, -- cgit From 15dc8917dbe5a1fed5ca909bb1bee24cff59db0f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 31 Jul 2007 08:06:56 +0000 Subject: r24089: Add reply_prep/post_legacy Routines to ease the transition to the new API (This used to be commit 1bb2b341e2cb6c0175376dc8bd2d1ce6d9c6c00e) --- source3/smbd/process.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index e99d70f236..1fba7e487c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -67,6 +67,60 @@ void init_smb_request(struct smb_request *req, const uint8 *inbuf) req->outbuf = NULL; } +/* + * From within a converted call you might have to call non-converted + * subroutines that still take the old inbuf/outbuf/lenght/bufsize + * parameters. This takes a struct smb_request and prepares the legacy + * parameters. + */ + +BOOL reply_prep_legacy(struct smb_request *req, + char **pinbuf, char **poutbuf, + int *psize, int *pbufsize) +{ + const int bufsize = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + + SAFETY_MARGIN); + char *inbuf, *outbuf; + + if (!(inbuf = TALLOC_ARRAY(req, char, bufsize))) { + DEBUG(0, ("Could not allocate legacy inbuf\n")); + return False; + } + memcpy(inbuf, req->inbuf, MIN(smb_len(req->inbuf)+4, bufsize)); + req->inbuf = (uint8 *)inbuf; + + if (!(outbuf = TALLOC_ARRAY(req, char, bufsize))) { + DEBUG(0, ("Could not allocate legacy outbuf\n")); + return False; + } + req->outbuf = (uint8 *)outbuf; + + construct_reply_common(inbuf, outbuf); + + *pinbuf = inbuf; + *poutbuf = outbuf; + *psize = smb_len(inbuf)+4; + *pbufsize = bufsize; + + return True; +} + +/* + * Post-process the output of the legacy routine so that the result fits into + * the new reply_xxx API + */ + +void reply_post_legacy(struct smb_request *req, int outsize) +{ + if (outsize > 0) { + smb_setlen((char *)req->inbuf, (char *)req->outbuf, + outsize); + } + else { + TALLOC_FREE(req->outbuf); + } +} + /**************************************************************************** structure to hold a linked list of queued messages. for processing. -- cgit From d95725370ffb8613828a440a513201520ffb5de3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 31 Jul 2007 08:56:08 +0000 Subject: r24091: Convert reply_ntcreate_and_X to the new API The routines called will follow (This used to be commit 28025fc17efa033515cef94789e518a6615e141f) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1fba7e487c..2773779898 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -850,7 +850,7 @@ static const struct smb_message_struct { /* 0x9f */ { NULL, NULL, NULL, 0 }, /* 0xa0 */ { "SMBnttrans", reply_nttrans,NULL, AS_USER | CAN_IPC }, /* 0xa1 */ { "SMBnttranss", reply_nttranss,NULL, AS_USER | CAN_IPC }, -/* 0xa2 */ { "SMBntcreateX", reply_ntcreate_and_X,NULL, AS_USER | CAN_IPC }, +/* 0xa2 */ { "SMBntcreateX", NULL,reply_ntcreate_and_X, AS_USER | CAN_IPC }, /* 0xa3 */ { NULL, NULL, NULL, 0 }, /* 0xa4 */ { "SMBntcancel", reply_ntcancel,NULL, 0 }, /* 0xa5 */ { "SMBntrename", reply_ntrename,NULL, AS_USER | NEED_WRITE }, -- cgit From 4473a5ec545ad4b087f6ac6738a961c6cddabb82 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 31 Jul 2007 10:04:54 +0000 Subject: r24100: Convert reply_ntcancel to the new API (This used to be commit 6e5f39379f60e30cd0445a049df619ec8f65fc01) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2773779898..ab2f205ebe 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -852,7 +852,7 @@ static const struct smb_message_struct { /* 0xa1 */ { "SMBnttranss", reply_nttranss,NULL, AS_USER | CAN_IPC }, /* 0xa2 */ { "SMBntcreateX", NULL,reply_ntcreate_and_X, AS_USER | CAN_IPC }, /* 0xa3 */ { NULL, NULL, NULL, 0 }, -/* 0xa4 */ { "SMBntcancel", reply_ntcancel,NULL, 0 }, +/* 0xa4 */ { "SMBntcancel", NULL,reply_ntcancel, 0 }, /* 0xa5 */ { "SMBntrename", reply_ntrename,NULL, AS_USER | NEED_WRITE }, /* 0xa6 */ { NULL, NULL, NULL, 0 }, /* 0xa7 */ { NULL, NULL, NULL, 0 }, -- cgit From a0a9a301d258ffdd6e1f35a9d4d32c555237556c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 2 Aug 2007 05:50:40 +0000 Subject: r24119: Convert reply_exit to the new API (This used to be commit d4d550aa2ba20d704d2ab1265732b03405e8819c) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ab2f205ebe..4acdb177a6 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -705,7 +705,7 @@ static const struct smb_message_struct { /* 0x0e */ { "SMBctemp",reply_ctemp,NULL,AS_USER }, /* 0x0f */ { "SMBmknew",reply_mknew,NULL,AS_USER}, /* 0x10 */ { "SMBcheckpath",NULL,reply_checkpath,AS_USER}, -/* 0x11 */ { "SMBexit",reply_exit,NULL,DO_CHDIR}, +/* 0x11 */ { "SMBexit",NULL,reply_exit,DO_CHDIR}, /* 0x12 */ { "SMBlseek",reply_lseek,NULL,AS_USER}, /* 0x13 */ { "SMBlockread",reply_lockread,NULL,AS_USER}, /* 0x14 */ { "SMBwriteunlock",reply_writeunlock,NULL,AS_USER}, -- cgit From b91704d47b7946d561a0021a08c14f8923d59e3a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 2 Aug 2007 18:28:41 +0000 Subject: r24135: Convert call_trans2open to the new API This itself won't help much, because send_trans2_replies_new still allocates the big buffers, but stay tuned :-) Also add/update my copyright on stuff I recently touched. Volker (This used to be commit 248f15ff143474db2493cef89ba446892342a361) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 4acdb177a6..54a1ef17b1 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. process incoming packets - main loop Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) Volker Lendecke 2005 + Copyright (C) Volker Lendecke 2005-2007 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit From e2f0b5dd2afa60a9ba2239f9ad7da8a2363baea6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 3 Aug 2007 13:34:02 +0000 Subject: r24156: Convert reply_trans2 to the new API (This used to be commit a9c2d75b42be8b0d89ed1e1a2ce2c6ab4284f5ea) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 54a1ef17b1..0076cfcad7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -738,7 +738,7 @@ static const struct smb_message_struct { /* 0x2f */ { "SMBwriteX",reply_write_and_X,NULL,AS_USER | CAN_IPC }, /* 0x30 */ { NULL, NULL, NULL, 0 }, /* 0x31 */ { NULL, NULL, NULL, 0 }, -/* 0x32 */ { "SMBtrans2", reply_trans2,NULL, AS_USER | CAN_IPC }, +/* 0x32 */ { "SMBtrans2", NULL,reply_trans2, AS_USER | CAN_IPC }, /* 0x33 */ { "SMBtranss2", reply_transs2,NULL, AS_USER}, /* 0x34 */ { "SMBfindclose", reply_findclose,NULL,AS_USER}, /* 0x35 */ { "SMBfindnclose", reply_findnclose,NULL, AS_USER}, -- cgit From 1d8851f4c734b65312baae042d12c014a8fe88c5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 3 Aug 2007 14:02:07 +0000 Subject: r24159: Convert reply_transs2 to the new API (This used to be commit a55a4d71ffe9ff1395e02f8bb3ad88fe5132fe99) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 0076cfcad7..df86970ca8 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -739,7 +739,7 @@ static const struct smb_message_struct { /* 0x30 */ { NULL, NULL, NULL, 0 }, /* 0x31 */ { NULL, NULL, NULL, 0 }, /* 0x32 */ { "SMBtrans2", NULL,reply_trans2, AS_USER | CAN_IPC }, -/* 0x33 */ { "SMBtranss2", reply_transs2,NULL, AS_USER}, +/* 0x33 */ { "SMBtranss2", NULL,reply_transs2, AS_USER}, /* 0x34 */ { "SMBfindclose", reply_findclose,NULL,AS_USER}, /* 0x35 */ { "SMBfindnclose", reply_findnclose,NULL, AS_USER}, /* 0x36 */ { NULL, NULL, NULL, 0 }, -- cgit From c847b2afe7f4c979499c20869563439e25f0cb7e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 4 Aug 2007 20:08:35 +0000 Subject: r24223: Convert reply_echo to the new API (This used to be commit 4863ff2899419e791ed0e340821072d004fb1d17) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index df86970ca8..02ad205bd5 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -731,7 +731,7 @@ static const struct smb_message_struct { /* 0x28 */ { "SMBioctls",NULL, NULL,AS_USER}, /* 0x29 */ { "SMBcopy",reply_copy,NULL,AS_USER | NEED_WRITE }, /* 0x2a */ { "SMBmove",NULL, NULL,AS_USER | NEED_WRITE }, -/* 0x2b */ { "SMBecho",reply_echo,NULL,0}, +/* 0x2b */ { "SMBecho",NULL,reply_echo,0}, /* 0x2c */ { "SMBwriteclose",reply_writeclose,NULL,AS_USER}, /* 0x2d */ { "SMBopenX",NULL,reply_open_and_X,AS_USER | CAN_IPC }, /* 0x2e */ { "SMBreadX",reply_read_and_X,NULL,AS_USER | CAN_IPC }, -- cgit From 5d2031915e9fa56cb1ccdc55a489bd62225ce739 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 4 Aug 2007 20:44:33 +0000 Subject: r24225: Convert reply_flush to the new API (This used to be commit f843c02f0794964eba02ab983f9c0701801f415c) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 02ad205bd5..f455b39a52 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -693,7 +693,7 @@ static const struct smb_message_struct { /* 0x02 */ { "SMBopen",reply_open,NULL,AS_USER }, /* 0x03 */ { "SMBcreate",reply_mknew,NULL,AS_USER}, /* 0x04 */ { "SMBclose",NULL,reply_close,AS_USER | CAN_IPC }, -/* 0x05 */ { "SMBflush",reply_flush,NULL,AS_USER}, +/* 0x05 */ { "SMBflush",NULL,reply_flush,AS_USER}, /* 0x06 */ { "SMBunlink",NULL,reply_unlink,AS_USER | NEED_WRITE }, /* 0x07 */ { "SMBmv",reply_mv,NULL,AS_USER | NEED_WRITE }, /* 0x08 */ { "SMBgetatr",reply_getatr,NULL,AS_USER}, -- cgit From 133ef281c08b3c0f35b57d935e343674d69b39b3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 5 Aug 2007 08:04:11 +0000 Subject: r24229: Push allocating InBuffer/OutBuffer into reply_transs (This used to be commit 39a7809aa4c34bb26178589245c419df44796e22) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f455b39a52..f593c5e177 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -725,7 +725,7 @@ static const struct smb_message_struct { /* 0x22 */ { "SMBsetattrE",reply_setattrE,NULL,AS_USER | NEED_WRITE }, /* 0x23 */ { "SMBgetattrE",reply_getattrE,NULL,AS_USER }, /* 0x24 */ { "SMBlockingX",reply_lockingX,NULL,AS_USER }, -/* 0x25 */ { "SMBtrans",reply_trans,NULL,AS_USER | CAN_IPC }, +/* 0x25 */ { "SMBtrans",NULL,reply_trans,AS_USER | CAN_IPC }, /* 0x26 */ { "SMBtranss",reply_transs,NULL,AS_USER | CAN_IPC}, /* 0x27 */ { "SMBioctl",reply_ioctl,NULL,0}, /* 0x28 */ { "SMBioctls",NULL, NULL,AS_USER}, -- cgit From 1d3c1de502bdb925fbe83714e65c37984d63ee52 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 5 Aug 2007 08:47:09 +0000 Subject: r24231: Push allocating InBuffer/OutBuffer into reply_transs (This used to be commit 74ae19cca6dd15b65deffbf464cfd0e485da8611) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f593c5e177..d7bde0043a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -726,7 +726,7 @@ static const struct smb_message_struct { /* 0x23 */ { "SMBgetattrE",reply_getattrE,NULL,AS_USER }, /* 0x24 */ { "SMBlockingX",reply_lockingX,NULL,AS_USER }, /* 0x25 */ { "SMBtrans",NULL,reply_trans,AS_USER | CAN_IPC }, -/* 0x26 */ { "SMBtranss",reply_transs,NULL,AS_USER | CAN_IPC}, +/* 0x26 */ { "SMBtranss",NULL,reply_transs,AS_USER | CAN_IPC}, /* 0x27 */ { "SMBioctl",reply_ioctl,NULL,0}, /* 0x28 */ { "SMBioctls",NULL, NULL,AS_USER}, /* 0x29 */ { "SMBcopy",reply_copy,NULL,AS_USER | NEED_WRITE }, -- cgit From b0dc209c190b90cef64d5fdea0623567e42c5a85 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 7 Aug 2007 13:43:02 +0000 Subject: r24271: Push reply_prep_legacy into reply_write_and_X (This used to be commit 607e7d2447bf19eea872a3a4d1ad499a53f0a935) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d7bde0043a..1b8e6521f7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -735,7 +735,7 @@ static const struct smb_message_struct { /* 0x2c */ { "SMBwriteclose",reply_writeclose,NULL,AS_USER}, /* 0x2d */ { "SMBopenX",NULL,reply_open_and_X,AS_USER | CAN_IPC }, /* 0x2e */ { "SMBreadX",reply_read_and_X,NULL,AS_USER | CAN_IPC }, -/* 0x2f */ { "SMBwriteX",reply_write_and_X,NULL,AS_USER | CAN_IPC }, +/* 0x2f */ { "SMBwriteX",NULL,reply_write_and_X,AS_USER | CAN_IPC }, /* 0x30 */ { NULL, NULL, NULL, 0 }, /* 0x31 */ { NULL, NULL, NULL, 0 }, /* 0x32 */ { "SMBtrans2", NULL,reply_trans2, AS_USER | CAN_IPC }, -- cgit From c898c519843e9bca4104e1414d9f5e0dbad77950 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 10 Aug 2007 20:53:27 +0000 Subject: r24318: Print a prominent warning when reply_prep_legacy is called This is a temporary function anyway (This used to be commit 9269e3d5882e97d1c884df6511fa6d63a7b1cfcd) --- source3/smbd/process.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1b8e6521f7..d0531bdfd9 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -82,6 +82,8 @@ BOOL reply_prep_legacy(struct smb_request *req, + SAFETY_MARGIN); char *inbuf, *outbuf; + DEBUG(1, ("reply_prep_legacy called\n")); + if (!(inbuf = TALLOC_ARRAY(req, char, bufsize))) { DEBUG(0, ("Could not allocate legacy inbuf\n")); return False; -- cgit From 61ee2d37200f8cc00d4b0291683f4b3fb8992457 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 11 Aug 2007 10:26:40 +0000 Subject: r24322: Wrap reply_read_and_X in reply_prep_legacy (This used to be commit 7926b5dfb8d05ad2fe40c3f7658a492f0450e505) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d0531bdfd9..2946eb878f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -736,7 +736,7 @@ static const struct smb_message_struct { /* 0x2b */ { "SMBecho",NULL,reply_echo,0}, /* 0x2c */ { "SMBwriteclose",reply_writeclose,NULL,AS_USER}, /* 0x2d */ { "SMBopenX",NULL,reply_open_and_X,AS_USER | CAN_IPC }, -/* 0x2e */ { "SMBreadX",reply_read_and_X,NULL,AS_USER | CAN_IPC }, +/* 0x2e */ { "SMBreadX",NULL,reply_read_and_X,AS_USER | CAN_IPC }, /* 0x2f */ { "SMBwriteX",NULL,reply_write_and_X,AS_USER | CAN_IPC }, /* 0x30 */ { NULL, NULL, NULL, 0 }, /* 0x31 */ { NULL, NULL, NULL, 0 }, -- cgit From 26f6826dfc996fe4d170dc7bc5ef2a728c9ddcaf Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 11 Aug 2007 14:37:39 +0000 Subject: r24327: First round of fixes to chain_reply The argument to smb_setlen does not contain the nbt header of 4 bytes The chained function might allocate outbuf itself (as now happens with reply_read_and_X). This would erroneously overwrite the caller's outbuf. Give it an outbuf pointer of it's own (This used to be commit f923bba90866af14b32c0d0ab58acc00a5939fbb) --- source3/smbd/process.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2946eb878f..9624ca0e49 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1355,6 +1355,7 @@ int chain_reply(char *inbuf,char **poutbuf,int size,int bufsize) int smb_com1, smb_com2 = CVAL(inbuf,smb_vwv0); unsigned smb_off2 = SVAL(inbuf,smb_vwv1); char *inbuf2; + char *outbuf2 = NULL; int outsize2; int new_size; char inbuf_saved[smb_wct]; @@ -1435,7 +1436,7 @@ int chain_reply(char *inbuf,char **poutbuf,int size,int bufsize) } /* And set it in the header. */ - smb_setlen(inbuf, inbuf2, new_size); + smb_setlen(inbuf, inbuf2, new_size - 4); DEBUG(3,("Chained message\n")); show_msg(inbuf2); @@ -1446,7 +1447,7 @@ int chain_reply(char *inbuf,char **poutbuf,int size,int bufsize) init_smb_request(req, (uint8 *)inbuf2); /* process the request */ - outsize2 = switch_message(smb_com2, req, &outbuf, new_size, + outsize2 = switch_message(smb_com2, req, &outbuf2, new_size, bufsize-chain_size); /* @@ -1495,7 +1496,7 @@ int chain_reply(char *inbuf,char **poutbuf,int size,int bufsize) *poutbuf = outbuf; - memmove(outbuf + smb_wct + ofs, outbuf + smb_wct, to_move); + memmove(outbuf + smb_wct + ofs, outbuf2 + smb_wct, to_move); memcpy(outbuf + smb_wct, caller_output, caller_outputlen); /* -- cgit From d90f6fa1bd9f4aa1e09de1169597e0c703859b75 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 11 Aug 2007 15:02:58 +0000 Subject: r24328: Restore chain_reply error handling Get the whole smb header from the second chained function, in particular the error fields (This used to be commit 0eb831ca0eadb725242cb4ad75eb7008a5c18bf2) --- source3/smbd/process.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 9624ca0e49..adc3f638e0 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1500,9 +1500,10 @@ int chain_reply(char *inbuf,char **poutbuf,int size,int bufsize) memcpy(outbuf + smb_wct, caller_output, caller_outputlen); /* - * The secondary function has overwritten smb_com + * copy the new reply header over the old one but preserve the smb_com + * field */ - + memmove(outbuf,outbuf2,smb_wct); SCVAL(outbuf, smb_com, smb_com1); /* -- cgit From 2fb27fcb692dfaccf36c6530012d6e24f944e1a4 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 12 Aug 2007 12:15:32 +0000 Subject: r24349: For large read&x we need more than 64k of outbuf. (This used to be commit f7e2eec35f7457ec70d75ef099b34f83c9dfd654) --- source3/smbd/process.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index adc3f638e0..c59ee2c200 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -953,8 +953,19 @@ static const struct smb_message_struct { allocate and initialize a reply packet ********************************************************************/ -void reply_outbuf(struct smb_request *req, uint8 num_words, uint16 num_bytes) +void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes) { + /* + * Protect against integer wrap + */ + if ((num_bytes > 0xffffff) + || ((num_bytes + smb_size + num_words*2) > 0xffffff)) { + char *msg; + asprintf(&msg, "num_bytes too large: %u", + (unsigned)num_bytes); + smb_panic(msg); + } + if (!(req->outbuf = TALLOC_ARRAY( req, uint8, smb_size + num_words*2 + num_bytes))) { -- cgit From 6bee410431067dc4525fd5a4ff57b5ae22a8fb0c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 13 Aug 2007 09:12:21 +0000 Subject: r24358: Push reply_prep_legacy into reply_nttrans[s] (This used to be commit 197c2310792965f94d66ad7c8016a1594945bdf8) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c59ee2c200..93c6be8c2f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -850,8 +850,8 @@ static const struct smb_message_struct { /* 0x9d */ { NULL, NULL, NULL, 0 }, /* 0x9e */ { NULL, NULL, NULL, 0 }, /* 0x9f */ { NULL, NULL, NULL, 0 }, -/* 0xa0 */ { "SMBnttrans", reply_nttrans,NULL, AS_USER | CAN_IPC }, -/* 0xa1 */ { "SMBnttranss", reply_nttranss,NULL, AS_USER | CAN_IPC }, +/* 0xa0 */ { "SMBnttrans", NULL,reply_nttrans, AS_USER | CAN_IPC }, +/* 0xa1 */ { "SMBnttranss", NULL,reply_nttranss, AS_USER | CAN_IPC }, /* 0xa2 */ { "SMBntcreateX", NULL,reply_ntcreate_and_X, AS_USER | CAN_IPC }, /* 0xa3 */ { NULL, NULL, NULL, 0 }, /* 0xa4 */ { "SMBntcancel", NULL,reply_ntcancel, 0 }, -- cgit From 5cc0a6b43c32f2a118c0b7995a74c99ccca6ca64 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Aug 2007 20:29:24 +0000 Subject: r24386: Piss off Volker (not deliberately) by checking in a reply_mknew -> conversion. Sorry vl, remove one of your 15 patches :-). Jeremy. (This used to be commit a7648ed9d40d6f61362e1488dc30216363870694) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 93c6be8c2f..96945e0748 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -693,7 +693,7 @@ static const struct smb_message_struct { /* 0x00 */ { "SMBmkdir",NULL,reply_mkdir,AS_USER | NEED_WRITE}, /* 0x01 */ { "SMBrmdir",NULL,reply_rmdir,AS_USER | NEED_WRITE}, /* 0x02 */ { "SMBopen",reply_open,NULL,AS_USER }, -/* 0x03 */ { "SMBcreate",reply_mknew,NULL,AS_USER}, +/* 0x03 */ { "SMBcreate",NULL,reply_mknew,AS_USER}, /* 0x04 */ { "SMBclose",NULL,reply_close,AS_USER | CAN_IPC }, /* 0x05 */ { "SMBflush",NULL,reply_flush,AS_USER}, /* 0x06 */ { "SMBunlink",NULL,reply_unlink,AS_USER | NEED_WRITE }, @@ -705,7 +705,7 @@ static const struct smb_message_struct { /* 0x0c */ { "SMBlock",reply_lock,NULL,AS_USER}, /* 0x0d */ { "SMBunlock",reply_unlock,NULL,AS_USER}, /* 0x0e */ { "SMBctemp",reply_ctemp,NULL,AS_USER }, -/* 0x0f */ { "SMBmknew",reply_mknew,NULL,AS_USER}, +/* 0x0f */ { "SMBmknew",NULL,reply_mknew,AS_USER}, /* 0x10 */ { "SMBcheckpath",NULL,reply_checkpath,AS_USER}, /* 0x11 */ { "SMBexit",NULL,reply_exit,DO_CHDIR}, /* 0x12 */ { "SMBlseek",reply_lseek,NULL,AS_USER}, -- cgit From d701a47c736b058af9308cfb031b9862948c86a9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Aug 2007 01:45:26 +0000 Subject: r24387: Convert readbraw to the new api. Volker, keep checking in your patches please :-). I'll work on SMBreadBmpx tomorrow. Jeremy. (This used to be commit 27e183afa8d23dca6aada1f3810dc53aa8c55ccd) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 96945e0748..7e499b7797 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -716,7 +716,7 @@ static const struct smb_message_struct { /* 0x17 */ { NULL, NULL, NULL, 0 }, /* 0x18 */ { NULL, NULL, NULL, 0 }, /* 0x19 */ { NULL, NULL, NULL, 0 }, -/* 0x1a */ { "SMBreadbraw",reply_readbraw,NULL,AS_USER}, +/* 0x1a */ { "SMBreadbraw",NULL,reply_readbraw,AS_USER}, /* 0x1b */ { "SMBreadBmpx",reply_readbmpx,NULL,AS_USER}, /* 0x1c */ { "SMBreadBs",NULL, NULL,0 }, /* 0x1d */ { "SMBwritebraw",reply_writebraw,NULL,AS_USER}, -- cgit From ae89ba48ec548f28d38a0a35bc3884181946f1b8 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 10:06:33 +0000 Subject: r24404: Remove get_OutBuffer usage from blocking.c (This used to be commit cb8fab5663db2cb408e1b85a7287d3670b09d503) --- source3/smbd/process.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 7e499b7797..ca55c8f63f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1743,11 +1743,6 @@ char *get_InBuffer(void) return InBuffer; } -char *get_OutBuffer(void) -{ - return OutBuffer; -} - /**************************************************************************** Allocate a new InBuffer. Returns the new and old ones. ****************************************************************************/ -- cgit From 29df25351df5ce5987334318e7f3507aa01c7ebe Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 10:47:47 +0000 Subject: r24406: Push reply_prep_legacy into reply_lockingX (This used to be commit bce87ebdc00b9086dcdcc55442b57b92345971ac) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ca55c8f63f..0f4d53b77a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -726,7 +726,7 @@ static const struct smb_message_struct { /* 0x21 */ { NULL, NULL, NULL, 0 }, /* 0x22 */ { "SMBsetattrE",reply_setattrE,NULL,AS_USER | NEED_WRITE }, /* 0x23 */ { "SMBgetattrE",reply_getattrE,NULL,AS_USER }, -/* 0x24 */ { "SMBlockingX",reply_lockingX,NULL,AS_USER }, +/* 0x24 */ { "SMBlockingX",NULL,reply_lockingX,AS_USER }, /* 0x25 */ { "SMBtrans",NULL,reply_trans,AS_USER | CAN_IPC }, /* 0x26 */ { "SMBtranss",NULL,reply_transs,AS_USER | CAN_IPC}, /* 0x27 */ { "SMBioctl",reply_ioctl,NULL,0}, -- cgit From 2da44a2dee1ad425a25f9a188896ce031356630c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 14:31:55 +0000 Subject: r24412: Convert reply_open to the new API (This used to be commit 394987f5224086cb379ea8d0364924679b8a0214) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 0f4d53b77a..f0d1c56e90 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -692,7 +692,7 @@ static const struct smb_message_struct { /* 0x00 */ { "SMBmkdir",NULL,reply_mkdir,AS_USER | NEED_WRITE}, /* 0x01 */ { "SMBrmdir",NULL,reply_rmdir,AS_USER | NEED_WRITE}, -/* 0x02 */ { "SMBopen",reply_open,NULL,AS_USER }, +/* 0x02 */ { "SMBopen",NULL,reply_open,AS_USER }, /* 0x03 */ { "SMBcreate",NULL,reply_mknew,AS_USER}, /* 0x04 */ { "SMBclose",NULL,reply_close,AS_USER | CAN_IPC }, /* 0x05 */ { "SMBflush",NULL,reply_flush,AS_USER}, -- cgit From 5fe4384cd98237c7e426de8508dfb2b7b29f757f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 14:50:49 +0000 Subject: r24414: Convert reply_mv to the new API (This used to be commit fa341e4840d422cee389c06112e0b2df43a31f45) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f0d1c56e90..a03529ed0d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -697,7 +697,7 @@ static const struct smb_message_struct { /* 0x04 */ { "SMBclose",NULL,reply_close,AS_USER | CAN_IPC }, /* 0x05 */ { "SMBflush",NULL,reply_flush,AS_USER}, /* 0x06 */ { "SMBunlink",NULL,reply_unlink,AS_USER | NEED_WRITE }, -/* 0x07 */ { "SMBmv",reply_mv,NULL,AS_USER | NEED_WRITE }, +/* 0x07 */ { "SMBmv",NULL,reply_mv,AS_USER | NEED_WRITE }, /* 0x08 */ { "SMBgetatr",reply_getatr,NULL,AS_USER}, /* 0x09 */ { "SMBsetatr",reply_setatr,NULL,AS_USER | NEED_WRITE}, /* 0x0a */ { "SMBread",reply_read,NULL,AS_USER}, -- cgit From 73b3ae9c55c5c1b3d20c69ce3571d066556881ed Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 15:09:49 +0000 Subject: r24415: Convert reply_getatr to the new API (This used to be commit 1a08b97a933e25362707cb0d8ba09d733af4cbbf) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index a03529ed0d..b49945eafc 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -698,7 +698,7 @@ static const struct smb_message_struct { /* 0x05 */ { "SMBflush",NULL,reply_flush,AS_USER}, /* 0x06 */ { "SMBunlink",NULL,reply_unlink,AS_USER | NEED_WRITE }, /* 0x07 */ { "SMBmv",NULL,reply_mv,AS_USER | NEED_WRITE }, -/* 0x08 */ { "SMBgetatr",reply_getatr,NULL,AS_USER}, +/* 0x08 */ { "SMBgetatr",NULL,reply_getatr,AS_USER}, /* 0x09 */ { "SMBsetatr",reply_setatr,NULL,AS_USER | NEED_WRITE}, /* 0x0a */ { "SMBread",reply_read,NULL,AS_USER}, /* 0x0b */ { "SMBwrite",reply_write,NULL,AS_USER | CAN_IPC }, -- cgit From 06ed827edf3fa210aebeea2e1e059fde090159fa Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 15:26:54 +0000 Subject: r24417: Convert reply_setatr to the new API (This used to be commit 56bab5ea4cbcf8e46101053bd68f66691fd737c5) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index b49945eafc..883c39c532 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -699,7 +699,7 @@ static const struct smb_message_struct { /* 0x06 */ { "SMBunlink",NULL,reply_unlink,AS_USER | NEED_WRITE }, /* 0x07 */ { "SMBmv",NULL,reply_mv,AS_USER | NEED_WRITE }, /* 0x08 */ { "SMBgetatr",NULL,reply_getatr,AS_USER}, -/* 0x09 */ { "SMBsetatr",reply_setatr,NULL,AS_USER | NEED_WRITE}, +/* 0x09 */ { "SMBsetatr",NULL,reply_setatr,AS_USER | NEED_WRITE}, /* 0x0a */ { "SMBread",reply_read,NULL,AS_USER}, /* 0x0b */ { "SMBwrite",reply_write,NULL,AS_USER | CAN_IPC }, /* 0x0c */ { "SMBlock",reply_lock,NULL,AS_USER}, -- cgit From dee4ab15338841469729c794275eea158079e076 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 15:42:39 +0000 Subject: r24422: Convert reply_ctemp to the new API (This used to be commit 3cc22fd74f0ffc72f4340a963b4eca7178be2192) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 883c39c532..1241741449 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -704,7 +704,7 @@ static const struct smb_message_struct { /* 0x0b */ { "SMBwrite",reply_write,NULL,AS_USER | CAN_IPC }, /* 0x0c */ { "SMBlock",reply_lock,NULL,AS_USER}, /* 0x0d */ { "SMBunlock",reply_unlock,NULL,AS_USER}, -/* 0x0e */ { "SMBctemp",reply_ctemp,NULL,AS_USER }, +/* 0x0e */ { "SMBctemp",NULL,reply_ctemp,AS_USER }, /* 0x0f */ { "SMBmknew",NULL,reply_mknew,AS_USER}, /* 0x10 */ { "SMBcheckpath",NULL,reply_checkpath,AS_USER}, /* 0x11 */ { "SMBexit",NULL,reply_exit,DO_CHDIR}, -- cgit From fe502551c32263ef6faed26ee691aa1586f75104 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 16:04:31 +0000 Subject: r24423: Convert reply_lseek to the new API (This used to be commit bd228853863ce5b4b9b974347c50c956d7f2e055) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1241741449..fe6da4b265 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -708,7 +708,7 @@ static const struct smb_message_struct { /* 0x0f */ { "SMBmknew",NULL,reply_mknew,AS_USER}, /* 0x10 */ { "SMBcheckpath",NULL,reply_checkpath,AS_USER}, /* 0x11 */ { "SMBexit",NULL,reply_exit,DO_CHDIR}, -/* 0x12 */ { "SMBlseek",reply_lseek,NULL,AS_USER}, +/* 0x12 */ { "SMBlseek",NULL,reply_lseek,AS_USER}, /* 0x13 */ { "SMBlockread",reply_lockread,NULL,AS_USER}, /* 0x14 */ { "SMBwriteunlock",reply_writeunlock,NULL,AS_USER}, /* 0x15 */ { NULL, NULL, NULL, 0 }, -- cgit From 7c25bf4511161cb7d3da8c27ca74b73c02b8841f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 18:16:04 +0000 Subject: r24425: Convert reply_write to the new API (This used to be commit 244965f7b67becb85774311e6ce84318d554384d) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index fe6da4b265..c84f4b2dee 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -701,7 +701,7 @@ static const struct smb_message_struct { /* 0x08 */ { "SMBgetatr",NULL,reply_getatr,AS_USER}, /* 0x09 */ { "SMBsetatr",NULL,reply_setatr,AS_USER | NEED_WRITE}, /* 0x0a */ { "SMBread",reply_read,NULL,AS_USER}, -/* 0x0b */ { "SMBwrite",reply_write,NULL,AS_USER | CAN_IPC }, +/* 0x0b */ { "SMBwrite",NULL,reply_write,AS_USER | CAN_IPC }, /* 0x0c */ { "SMBlock",reply_lock,NULL,AS_USER}, /* 0x0d */ { "SMBunlock",reply_unlock,NULL,AS_USER}, /* 0x0e */ { "SMBctemp",NULL,reply_ctemp,AS_USER }, -- cgit From 4c7212b4e4099c03049853cd211085030128ffd9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 18:33:29 +0000 Subject: r24426: Convert reply_read to the new API (This used to be commit 30aada0ef8e16ce94035039b63ab140d158009d9) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c84f4b2dee..e05a941542 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -700,7 +700,7 @@ static const struct smb_message_struct { /* 0x07 */ { "SMBmv",NULL,reply_mv,AS_USER | NEED_WRITE }, /* 0x08 */ { "SMBgetatr",NULL,reply_getatr,AS_USER}, /* 0x09 */ { "SMBsetatr",NULL,reply_setatr,AS_USER | NEED_WRITE}, -/* 0x0a */ { "SMBread",reply_read,NULL,AS_USER}, +/* 0x0a */ { "SMBread",NULL,reply_read,AS_USER}, /* 0x0b */ { "SMBwrite",NULL,reply_write,AS_USER | CAN_IPC }, /* 0x0c */ { "SMBlock",reply_lock,NULL,AS_USER}, /* 0x0d */ { "SMBunlock",reply_unlock,NULL,AS_USER}, -- cgit From ca70ea9310fdf904011ce55cf1122043e2b42b4a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 18:52:58 +0000 Subject: r24427: Convert reply_lock to the new API (This used to be commit 212f43ddeaa6369e5437ed3915eb066a37bc9014) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index e05a941542..e0da594450 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -702,7 +702,7 @@ static const struct smb_message_struct { /* 0x09 */ { "SMBsetatr",NULL,reply_setatr,AS_USER | NEED_WRITE}, /* 0x0a */ { "SMBread",NULL,reply_read,AS_USER}, /* 0x0b */ { "SMBwrite",NULL,reply_write,AS_USER | CAN_IPC }, -/* 0x0c */ { "SMBlock",reply_lock,NULL,AS_USER}, +/* 0x0c */ { "SMBlock",NULL,reply_lock,AS_USER}, /* 0x0d */ { "SMBunlock",reply_unlock,NULL,AS_USER}, /* 0x0e */ { "SMBctemp",NULL,reply_ctemp,AS_USER }, /* 0x0f */ { "SMBmknew",NULL,reply_mknew,AS_USER}, -- cgit From 0f73d64f7dcabffa7b2e512d4c2b5750f6799090 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 19:09:37 +0000 Subject: r24428: Convert reply_unlock to the new API (This used to be commit 01c7426fc0e2af6a955dcb37111ca439fc913d5f) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index e0da594450..64e41ff155 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -703,7 +703,7 @@ static const struct smb_message_struct { /* 0x0a */ { "SMBread",NULL,reply_read,AS_USER}, /* 0x0b */ { "SMBwrite",NULL,reply_write,AS_USER | CAN_IPC }, /* 0x0c */ { "SMBlock",NULL,reply_lock,AS_USER}, -/* 0x0d */ { "SMBunlock",reply_unlock,NULL,AS_USER}, +/* 0x0d */ { "SMBunlock",NULL,reply_unlock,AS_USER}, /* 0x0e */ { "SMBctemp",NULL,reply_ctemp,AS_USER }, /* 0x0f */ { "SMBmknew",NULL,reply_mknew,AS_USER}, /* 0x10 */ { "SMBcheckpath",NULL,reply_checkpath,AS_USER}, -- cgit From 4a989dac81372a8829d3769633c46fcba6e798f3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 19:29:02 +0000 Subject: r24430: Convert reply_writeclose to the new API (This used to be commit 6def2ee03bb3510f000b1977c4d5293cad4ae364) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 64e41ff155..6751272567 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -734,7 +734,7 @@ static const struct smb_message_struct { /* 0x29 */ { "SMBcopy",reply_copy,NULL,AS_USER | NEED_WRITE }, /* 0x2a */ { "SMBmove",NULL, NULL,AS_USER | NEED_WRITE }, /* 0x2b */ { "SMBecho",NULL,reply_echo,0}, -/* 0x2c */ { "SMBwriteclose",reply_writeclose,NULL,AS_USER}, +/* 0x2c */ { "SMBwriteclose",NULL,reply_writeclose,AS_USER}, /* 0x2d */ { "SMBopenX",NULL,reply_open_and_X,AS_USER | CAN_IPC }, /* 0x2e */ { "SMBreadX",NULL,reply_read_and_X,AS_USER | CAN_IPC }, /* 0x2f */ { "SMBwriteX",NULL,reply_write_and_X,AS_USER | CAN_IPC }, -- cgit From 591669ba066cde377c0c14e3473f23b35530b4ba Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 19:45:24 +0000 Subject: r24431: Convert the reply_printXX calls to the new API (This used to be commit e528479f56bc936cc60eb95c9738a48de48dbd05) --- source3/smbd/process.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 6751272567..be311b4135 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -882,10 +882,10 @@ static const struct smb_message_struct { /* 0xbd */ { NULL, NULL, NULL, 0 }, /* 0xbe */ { NULL, NULL, NULL, 0 }, /* 0xbf */ { NULL, NULL, NULL, 0 }, -/* 0xc0 */ { "SMBsplopen",reply_printopen,NULL,AS_USER}, -/* 0xc1 */ { "SMBsplwr",reply_printwrite,NULL,AS_USER}, -/* 0xc2 */ { "SMBsplclose",reply_printclose,NULL,AS_USER}, -/* 0xc3 */ { "SMBsplretq",reply_printqueue,NULL,AS_USER}, +/* 0xc0 */ { "SMBsplopen",NULL,reply_printopen,AS_USER}, +/* 0xc1 */ { "SMBsplwr",NULL,reply_printwrite,AS_USER}, +/* 0xc2 */ { "SMBsplclose",NULL,reply_printclose,AS_USER}, +/* 0xc3 */ { "SMBsplretq",NULL,reply_printqueue,AS_USER}, /* 0xc4 */ { NULL, NULL, NULL, 0 }, /* 0xc5 */ { NULL, NULL, NULL, 0 }, /* 0xc6 */ { NULL, NULL, NULL, 0 }, -- cgit From 2ea14d4e987e9cad627e4a66eb20ab545305b965 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 20:02:11 +0000 Subject: r24433: Convert reply_ntrename to the new API (This used to be commit 42b07a52b9f4fe147426e9156958cb4d33691678) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index be311b4135..837991f2ee 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -855,7 +855,7 @@ static const struct smb_message_struct { /* 0xa2 */ { "SMBntcreateX", NULL,reply_ntcreate_and_X, AS_USER | CAN_IPC }, /* 0xa3 */ { NULL, NULL, NULL, 0 }, /* 0xa4 */ { "SMBntcancel", NULL,reply_ntcancel, 0 }, -/* 0xa5 */ { "SMBntrename", reply_ntrename,NULL, AS_USER | NEED_WRITE }, +/* 0xa5 */ { "SMBntrename", NULL,reply_ntrename, AS_USER | NEED_WRITE }, /* 0xa6 */ { NULL, NULL, NULL, 0 }, /* 0xa7 */ { NULL, NULL, NULL, 0 }, /* 0xa8 */ { NULL, NULL, NULL, 0 }, -- cgit From 05fafc1df28e7848a1e6869d0103ea96dc21f0e4 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 20:20:51 +0000 Subject: r24436: Convert reply_lockread/writeunlock to the new API (This used to be commit 1b6add251ca1db565a03407db30884132dd93e7d) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 837991f2ee..aaaf475d2e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -709,8 +709,8 @@ static const struct smb_message_struct { /* 0x10 */ { "SMBcheckpath",NULL,reply_checkpath,AS_USER}, /* 0x11 */ { "SMBexit",NULL,reply_exit,DO_CHDIR}, /* 0x12 */ { "SMBlseek",NULL,reply_lseek,AS_USER}, -/* 0x13 */ { "SMBlockread",reply_lockread,NULL,AS_USER}, -/* 0x14 */ { "SMBwriteunlock",reply_writeunlock,NULL,AS_USER}, +/* 0x13 */ { "SMBlockread",NULL,reply_lockread,AS_USER}, +/* 0x14 */ { "SMBwriteunlock",NULL,reply_writeunlock,AS_USER}, /* 0x15 */ { NULL, NULL, NULL, 0 }, /* 0x16 */ { NULL, NULL, NULL, 0 }, /* 0x17 */ { NULL, NULL, NULL, 0 }, -- cgit From 90741da80bf99fea22d9ee3a03a0f0994d0da6a3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 20:55:24 +0000 Subject: r24439: Convert reply_get/setattrE to the new API (This used to be commit 6b0ad071d85ddd8fbf24386db11688bde49baf81) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index aaaf475d2e..c198aa7c0c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -724,8 +724,8 @@ static const struct smb_message_struct { /* 0x1f */ { "SMBwriteBs",reply_writebs,NULL,AS_USER}, /* 0x20 */ { "SMBwritec",NULL, NULL,0}, /* 0x21 */ { NULL, NULL, NULL, 0 }, -/* 0x22 */ { "SMBsetattrE",reply_setattrE,NULL,AS_USER | NEED_WRITE }, -/* 0x23 */ { "SMBgetattrE",reply_getattrE,NULL,AS_USER }, +/* 0x22 */ { "SMBsetattrE",NULL,reply_setattrE,AS_USER | NEED_WRITE }, +/* 0x23 */ { "SMBgetattrE",NULL,reply_getattrE,AS_USER }, /* 0x24 */ { "SMBlockingX",NULL,reply_lockingX,AS_USER }, /* 0x25 */ { "SMBtrans",NULL,reply_trans,AS_USER | CAN_IPC }, /* 0x26 */ { "SMBtranss",NULL,reply_transs,AS_USER | CAN_IPC}, -- cgit From c5572072e5c50883a643ebd55295c7fb4d10fe3e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 21:07:44 +0000 Subject: r24440: Convert the reply_sendXX functions to the new API (This used to be commit a64bc31098de8694b79eeafd3a226cf519700707) --- source3/smbd/process.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c198aa7c0c..671b7116fa 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -898,14 +898,14 @@ static const struct smb_message_struct { /* 0xcd */ { NULL, NULL, NULL, 0 }, /* 0xce */ { NULL, NULL, NULL, 0 }, /* 0xcf */ { NULL, NULL, NULL, 0 }, -/* 0xd0 */ { "SMBsends",reply_sends,NULL,AS_GUEST}, +/* 0xd0 */ { "SMBsends",NULL,reply_sends,AS_GUEST}, /* 0xd1 */ { "SMBsendb",NULL, NULL,AS_GUEST}, /* 0xd2 */ { "SMBfwdname",NULL, NULL,AS_GUEST}, /* 0xd3 */ { "SMBcancelf",NULL, NULL,AS_GUEST}, /* 0xd4 */ { "SMBgetmac",NULL, NULL,AS_GUEST}, -/* 0xd5 */ { "SMBsendstrt",reply_sendstrt,NULL,AS_GUEST}, -/* 0xd6 */ { "SMBsendend",reply_sendend,NULL,AS_GUEST}, -/* 0xd7 */ { "SMBsendtxt",reply_sendtxt,NULL,AS_GUEST}, +/* 0xd5 */ { "SMBsendstrt",NULL,reply_sendstrt,AS_GUEST}, +/* 0xd6 */ { "SMBsendend",NULL,reply_sendend,AS_GUEST}, +/* 0xd7 */ { "SMBsendtxt",NULL,reply_sendtxt,AS_GUEST}, /* 0xd8 */ { NULL, NULL, NULL, 0 }, /* 0xd9 */ { NULL, NULL, NULL, 0 }, /* 0xda */ { NULL, NULL, NULL, 0 }, -- cgit From 9c2bfffecec108c5ffaf0308390dfd8093881adb Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 21:13:05 +0000 Subject: r24441: Convert reply_ioctl to the new API (This used to be commit a5af7ebb7f1d869659fbab187652e68ec4fafbb8) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 671b7116fa..9604439230 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -729,7 +729,7 @@ static const struct smb_message_struct { /* 0x24 */ { "SMBlockingX",NULL,reply_lockingX,AS_USER }, /* 0x25 */ { "SMBtrans",NULL,reply_trans,AS_USER | CAN_IPC }, /* 0x26 */ { "SMBtranss",NULL,reply_transs,AS_USER | CAN_IPC}, -/* 0x27 */ { "SMBioctl",reply_ioctl,NULL,0}, +/* 0x27 */ { "SMBioctl",NULL,reply_ioctl,0}, /* 0x28 */ { "SMBioctls",NULL, NULL,AS_USER}, /* 0x29 */ { "SMBcopy",reply_copy,NULL,AS_USER | NEED_WRITE }, /* 0x2a */ { "SMBmove",NULL, NULL,AS_USER | NEED_WRITE }, -- cgit From f93b093d5f3a2cc7b72e1ddff8d84fe70267c23c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 21:21:52 +0000 Subject: r24442: Convert reply_copy to the new API (This used to be commit 0cb00c54750837ab2d2dc12e4947fedb7d38e878) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 9604439230..ad6ddba737 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -731,7 +731,7 @@ static const struct smb_message_struct { /* 0x26 */ { "SMBtranss",NULL,reply_transs,AS_USER | CAN_IPC}, /* 0x27 */ { "SMBioctl",NULL,reply_ioctl,0}, /* 0x28 */ { "SMBioctls",NULL, NULL,AS_USER}, -/* 0x29 */ { "SMBcopy",reply_copy,NULL,AS_USER | NEED_WRITE }, +/* 0x29 */ { "SMBcopy",NULL,reply_copy,AS_USER | NEED_WRITE }, /* 0x2a */ { "SMBmove",NULL, NULL,AS_USER | NEED_WRITE }, /* 0x2b */ { "SMBecho",NULL,reply_echo,0}, /* 0x2c */ { "SMBwriteclose",NULL,reply_writeclose,AS_USER}, -- cgit From 5edcc342c6b24e41fed826c13a257929f4071668 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 21:32:52 +0000 Subject: r24443: Convert reply_search/fclose to the new API (This used to be commit a8a33c377e38046b4103cf1d59032b97ab6bac9a) --- source3/smbd/process.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ad6ddba737..7f307ade63 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -819,10 +819,10 @@ static const struct smb_message_struct { /* 0x7e */ { NULL, NULL, NULL, 0 }, /* 0x7f */ { NULL, NULL, NULL, 0 }, /* 0x80 */ { "SMBdskattr",NULL,reply_dskattr,AS_USER}, -/* 0x81 */ { "SMBsearch",reply_search,NULL,AS_USER}, -/* 0x82 */ { "SMBffirst",reply_search,NULL,AS_USER}, -/* 0x83 */ { "SMBfunique",reply_search,NULL,AS_USER}, -/* 0x84 */ { "SMBfclose",reply_fclose,NULL,AS_USER}, +/* 0x81 */ { "SMBsearch",NULL,reply_search,AS_USER}, +/* 0x82 */ { "SMBffirst",NULL,reply_search,AS_USER}, +/* 0x83 */ { "SMBfunique",NULL,reply_search,AS_USER}, +/* 0x84 */ { "SMBfclose",NULL,reply_fclose,AS_USER}, /* 0x85 */ { NULL, NULL, NULL, 0 }, /* 0x86 */ { NULL, NULL, NULL, 0 }, /* 0x87 */ { NULL, NULL, NULL, 0 }, -- cgit From 527905a09a0b5b39830440189a145182b7d571f2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 14 Aug 2007 21:53:48 +0000 Subject: r24444: Convert reply_find[n]close to the new API (This used to be commit 6af85953465789594342f2d199ef5d29462cf34f) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 7f307ade63..6405ddf1f5 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -742,8 +742,8 @@ static const struct smb_message_struct { /* 0x31 */ { NULL, NULL, NULL, 0 }, /* 0x32 */ { "SMBtrans2", NULL,reply_trans2, AS_USER | CAN_IPC }, /* 0x33 */ { "SMBtranss2", NULL,reply_transs2, AS_USER}, -/* 0x34 */ { "SMBfindclose", reply_findclose,NULL,AS_USER}, -/* 0x35 */ { "SMBfindnclose", reply_findnclose,NULL, AS_USER}, +/* 0x34 */ { "SMBfindclose", NULL,reply_findclose,AS_USER}, +/* 0x35 */ { "SMBfindnclose", NULL,reply_findnclose,AS_USER}, /* 0x36 */ { NULL, NULL, NULL, 0 }, /* 0x37 */ { NULL, NULL, NULL, 0 }, /* 0x38 */ { NULL, NULL, NULL, 0 }, -- cgit From 2823bf10b520996a20688190d784f45851e1ba24 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 15 Aug 2007 01:54:37 +0000 Subject: r24445: Convert SMBwritebraw. No test suite unfortunately.... I need to write one for this. Jeremy (This used to be commit edc17dfcbd21cccaffb76f4ae67fe4b06520f1a9) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 6405ddf1f5..b4de0edc28 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -719,7 +719,7 @@ static const struct smb_message_struct { /* 0x1a */ { "SMBreadbraw",NULL,reply_readbraw,AS_USER}, /* 0x1b */ { "SMBreadBmpx",reply_readbmpx,NULL,AS_USER}, /* 0x1c */ { "SMBreadBs",NULL, NULL,0 }, -/* 0x1d */ { "SMBwritebraw",reply_writebraw,NULL,AS_USER}, +/* 0x1d */ { "SMBwritebraw",NULL,reply_writebraw,AS_USER}, /* 0x1e */ { "SMBwriteBmpx",reply_writebmpx,NULL,AS_USER}, /* 0x1f */ { "SMBwriteBs",reply_writebs,NULL,AS_USER}, /* 0x20 */ { "SMBwritec",NULL, NULL,0}, -- cgit From 24f42c5cefff01cc69118cb714a053cddb68e4d9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 15 Aug 2007 09:52:09 +0000 Subject: r24453: Remove the read and write bmpx calls Talked to both Tridge and Jeremy about this, Tridge said that there is a special error message persuading OS/2 to fall back to other methods. The calls now checked in always return the error message we used to return when "read bmpx = False" was set (the default): ERRSRV, ERRuseSTD. If someone has a reproducable test case where this is really needed, we can always dig it up from version control and convert it to the new API. But that time without that silly parameter, and with a torture test case for "make test" please :-) Volker (This used to be commit d941aae2dfd11609e807bf4ce712571a2e354627) --- source3/smbd/process.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index b4de0edc28..e64a18a196 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -717,11 +717,11 @@ static const struct smb_message_struct { /* 0x18 */ { NULL, NULL, NULL, 0 }, /* 0x19 */ { NULL, NULL, NULL, 0 }, /* 0x1a */ { "SMBreadbraw",NULL,reply_readbraw,AS_USER}, -/* 0x1b */ { "SMBreadBmpx",reply_readbmpx,NULL,AS_USER}, -/* 0x1c */ { "SMBreadBs",NULL, NULL,0 }, +/* 0x1b */ { "SMBreadBmpx",NULL,reply_readbmpx,AS_USER}, +/* 0x1c */ { "SMBreadBs",NULL,reply_readbs,AS_USER }, /* 0x1d */ { "SMBwritebraw",NULL,reply_writebraw,AS_USER}, -/* 0x1e */ { "SMBwriteBmpx",reply_writebmpx,NULL,AS_USER}, -/* 0x1f */ { "SMBwriteBs",reply_writebs,NULL,AS_USER}, +/* 0x1e */ { "SMBwriteBmpx",NULL,reply_writebmpx,AS_USER}, +/* 0x1f */ { "SMBwriteBs",NULL,reply_writebs,AS_USER}, /* 0x20 */ { "SMBwritec",NULL, NULL,0}, /* 0x21 */ { NULL, NULL, NULL, 0 }, /* 0x22 */ { "SMBsetattrE",NULL,reply_setattrE,AS_USER | NEED_WRITE }, -- cgit From 716e01d97e91227a0d03cbd5e74e4a36efc223eb Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 15 Aug 2007 10:29:47 +0000 Subject: r24457: Convert reply_tcon to the new API Jeremy, I really apologize for doing this, but I just wanted to enjoy converting the last SMB call :-) I've left one little task for you there, I'm not certain that checking the inbuf length is correct here. Volker (This used to be commit 1e08fddafda11961f8855423b29c1f8a9a6b4457) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index e64a18a196..bf86603924 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -802,7 +802,7 @@ static const struct smb_message_struct { /* 0x6d */ { NULL, NULL, NULL, 0 }, /* 0x6e */ { NULL, NULL, NULL, 0 }, /* 0x6f */ { NULL, NULL, NULL, 0 }, -/* 0x70 */ { "SMBtcon",reply_tcon,NULL,0}, +/* 0x70 */ { "SMBtcon",NULL,reply_tcon,0}, /* 0x71 */ { "SMBtdis",NULL,reply_tdis,DO_CHDIR}, /* 0x72 */ { "SMBnegprot",NULL,reply_negprot,0}, /* 0x73 */ { "SMBsesssetupX",NULL,reply_sesssetup_and_X,0}, -- cgit From a1f593cd737ccfaf48a98b954f38a541646cc5c7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 15 Aug 2007 19:25:38 +0000 Subject: r24467: Do range checking on incoming smb request. Jeremy. (This used to be commit dbd58dd647279def1681d88701e41d8a738c680a) --- source3/smbd/process.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index bf86603924..ce04c4331f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -57,12 +57,26 @@ extern int max_send; void init_smb_request(struct smb_request *req, const uint8 *inbuf) { + size_t req_size = smb_len(inbuf); + /* Ensure we have at smb_size request. */ + if (req_size < smb_size) { + DEBUG(0,("init_smb_request: invalid request size %u\n", + (unsigned int)req_size )); + exit_server_cleanly("Invalid SMB request"); + } req->flags2 = SVAL(inbuf, smb_flg2); req->smbpid = SVAL(inbuf, smb_pid); req->mid = SVAL(inbuf, smb_mid); req->vuid = SVAL(inbuf, smb_uid); req->tid = SVAL(inbuf, smb_tid); req->wct = CVAL(inbuf, smb_wct); + /* Ensure we have at least wct words. */ + if (smb_size + req->wct*2 > req_size) { + DEBUG(0,("init_smb_request: invalid wct number %u (size %u)\n", + (unsigned int)req->wct, + (unsigned int)req_size)); + exit_server_cleanly("Invalid SMB request"); + } req->inbuf = inbuf; req->outbuf = NULL; } -- cgit From ed70bc0d8eef17af75ffcafd0c4b90ea403002fc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 15 Aug 2007 19:43:26 +0000 Subject: r24468: Don't forget the +4 for length :-). Jeremy. (This used to be commit 4d01e0b7443aa4e4d450d705df5762d801172809) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ce04c4331f..bf3abf9758 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -57,8 +57,8 @@ extern int max_send; void init_smb_request(struct smb_request *req, const uint8 *inbuf) { - size_t req_size = smb_len(inbuf); - /* Ensure we have at smb_size request. */ + size_t req_size = smb_len(inbuf) + 4; + /* Ensure we have at least smb_size bytes. */ if (req_size < smb_size) { DEBUG(0,("init_smb_request: invalid request size %u\n", (unsigned int)req_size )); -- cgit From a662a62e5a718065640e9b9f3c8f166638f4ec9a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 16 Aug 2007 23:53:51 +0000 Subject: r24500: Add check that bcc is correct in an incoming packet. Jeremy. (This used to be commit 267a0ac48d358e1bd10d92238352ca3d867a58d4) --- source3/smbd/process.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index bf3abf9758..35f1d6fb3c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -70,13 +70,22 @@ void init_smb_request(struct smb_request *req, const uint8 *inbuf) req->vuid = SVAL(inbuf, smb_uid); req->tid = SVAL(inbuf, smb_tid); req->wct = CVAL(inbuf, smb_wct); - /* Ensure we have at least wct words. */ + /* Ensure we have at least wct words and 2 bytes of bcc. */ if (smb_size + req->wct*2 > req_size) { DEBUG(0,("init_smb_request: invalid wct number %u (size %u)\n", (unsigned int)req->wct, (unsigned int)req_size)); exit_server_cleanly("Invalid SMB request"); } + /* Ensure bcc is correct. */ + if (((uint8 *)smb_buf(inbuf)) + smb_buflen(inbuf) > inbuf + req_size) { + DEBUG(0,("init_smb_request: invalid bcc number %u " + "(wct = %u, size %u)\n", + (unsigned int)smb_buflen(inbuf), + (unsigned int)req->wct, + (unsigned int)req_size)); + exit_server_cleanly("Invalid SMB request"); + } req->inbuf = inbuf; req->outbuf = NULL; } -- cgit From b578db69e91a088f158c1cd78a71d00045fc1da6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 27 Aug 2007 12:04:09 +0000 Subject: r24702: Remove the old API pointers (This used to be commit 17df313db42199e26d7d2044f6a1d845aacd1a90) --- source3/smbd/process.c | 804 +++++++++++++++++++------------------------------ 1 file changed, 308 insertions(+), 496 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 35f1d6fb3c..99898141db 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -25,13 +25,6 @@ extern int smb_echo_count; const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); -static char *InBuffer = NULL; -static char *OutBuffer = NULL; -static const char *current_inbuf = NULL; - -static char *NewInBuffer(char **old_inbuf); -static char *NewOutBuffer(char **old_outbuf); - /* * Size of data we can send to client. Set * by the client for all protocols above CORE. @@ -90,62 +83,6 @@ void init_smb_request(struct smb_request *req, const uint8 *inbuf) req->outbuf = NULL; } -/* - * From within a converted call you might have to call non-converted - * subroutines that still take the old inbuf/outbuf/lenght/bufsize - * parameters. This takes a struct smb_request and prepares the legacy - * parameters. - */ - -BOOL reply_prep_legacy(struct smb_request *req, - char **pinbuf, char **poutbuf, - int *psize, int *pbufsize) -{ - const int bufsize = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE - + SAFETY_MARGIN); - char *inbuf, *outbuf; - - DEBUG(1, ("reply_prep_legacy called\n")); - - if (!(inbuf = TALLOC_ARRAY(req, char, bufsize))) { - DEBUG(0, ("Could not allocate legacy inbuf\n")); - return False; - } - memcpy(inbuf, req->inbuf, MIN(smb_len(req->inbuf)+4, bufsize)); - req->inbuf = (uint8 *)inbuf; - - if (!(outbuf = TALLOC_ARRAY(req, char, bufsize))) { - DEBUG(0, ("Could not allocate legacy outbuf\n")); - return False; - } - req->outbuf = (uint8 *)outbuf; - - construct_reply_common(inbuf, outbuf); - - *pinbuf = inbuf; - *poutbuf = outbuf; - *psize = smb_len(inbuf)+4; - *pbufsize = bufsize; - - return True; -} - -/* - * Post-process the output of the legacy routine so that the result fits into - * the new reply_xxx API - */ - -void reply_post_legacy(struct smb_request *req, int outsize) -{ - if (outsize > 0) { - smb_setlen((char *)req->inbuf, (char *)req->outbuf, - outsize); - } - else { - TALLOC_FREE(req->outbuf); - } -} - /**************************************************************************** structure to hold a linked list of queued messages. for processing. @@ -158,11 +95,12 @@ static struct pending_message_list *deferred_open_queue; ready for processing. ****************************************************************************/ -static BOOL push_queued_message(const char *buf, int msg_len, +static BOOL push_queued_message(struct smb_request *req, struct timeval request_time, struct timeval end_time, char *private_data, size_t private_len) { + int msg_len = smb_len(req->inbuf) + 4; struct pending_message_list *msg; msg = TALLOC_ZERO_P(NULL, struct pending_message_list); @@ -172,7 +110,7 @@ static BOOL push_queued_message(const char *buf, int msg_len, return False; } - msg->buf = data_blob_talloc(msg, buf, msg_len); + msg->buf = data_blob_talloc(msg, req->inbuf, msg_len); if(msg->buf.data == NULL) { DEBUG(0,("push_message: malloc fail (2)\n")); TALLOC_FREE(msg); @@ -286,7 +224,7 @@ struct pending_message_list *get_open_deferred_message(uint16 mid) messages ready for processing. ****************************************************************************/ -BOOL push_deferred_smb_message(uint16 mid, +BOOL push_deferred_smb_message(struct smb_request *req, struct timeval request_time, struct timeval timeout, char *private_data, size_t priv_len) @@ -297,12 +235,11 @@ BOOL push_deferred_smb_message(uint16 mid, DEBUG(10,("push_deferred_open_smb_message: pushing message len %u mid %u " "timeout time [%u.%06u]\n", - (unsigned int) smb_len(current_inbuf)+4, (unsigned int)mid, + (unsigned int) smb_len(req->inbuf)+4, (unsigned int)req->mid, (unsigned int)end_time.tv_sec, (unsigned int)end_time.tv_usec)); - return push_queued_message(current_inbuf, smb_len(current_inbuf)+4, - request_time, end_time, + return push_queued_message(req, request_time, end_time, private_data, priv_len); } @@ -708,267 +645,266 @@ force write permissions on print services. */ static const struct smb_message_struct { const char *name; - int (*fn)(connection_struct *conn, char *, char *, int, int); void (*fn_new)(connection_struct *conn, struct smb_request *req); int flags; } smb_messages[256] = { -/* 0x00 */ { "SMBmkdir",NULL,reply_mkdir,AS_USER | NEED_WRITE}, -/* 0x01 */ { "SMBrmdir",NULL,reply_rmdir,AS_USER | NEED_WRITE}, -/* 0x02 */ { "SMBopen",NULL,reply_open,AS_USER }, -/* 0x03 */ { "SMBcreate",NULL,reply_mknew,AS_USER}, -/* 0x04 */ { "SMBclose",NULL,reply_close,AS_USER | CAN_IPC }, -/* 0x05 */ { "SMBflush",NULL,reply_flush,AS_USER}, -/* 0x06 */ { "SMBunlink",NULL,reply_unlink,AS_USER | NEED_WRITE }, -/* 0x07 */ { "SMBmv",NULL,reply_mv,AS_USER | NEED_WRITE }, -/* 0x08 */ { "SMBgetatr",NULL,reply_getatr,AS_USER}, -/* 0x09 */ { "SMBsetatr",NULL,reply_setatr,AS_USER | NEED_WRITE}, -/* 0x0a */ { "SMBread",NULL,reply_read,AS_USER}, -/* 0x0b */ { "SMBwrite",NULL,reply_write,AS_USER | CAN_IPC }, -/* 0x0c */ { "SMBlock",NULL,reply_lock,AS_USER}, -/* 0x0d */ { "SMBunlock",NULL,reply_unlock,AS_USER}, -/* 0x0e */ { "SMBctemp",NULL,reply_ctemp,AS_USER }, -/* 0x0f */ { "SMBmknew",NULL,reply_mknew,AS_USER}, -/* 0x10 */ { "SMBcheckpath",NULL,reply_checkpath,AS_USER}, -/* 0x11 */ { "SMBexit",NULL,reply_exit,DO_CHDIR}, -/* 0x12 */ { "SMBlseek",NULL,reply_lseek,AS_USER}, -/* 0x13 */ { "SMBlockread",NULL,reply_lockread,AS_USER}, -/* 0x14 */ { "SMBwriteunlock",NULL,reply_writeunlock,AS_USER}, -/* 0x15 */ { NULL, NULL, NULL, 0 }, -/* 0x16 */ { NULL, NULL, NULL, 0 }, -/* 0x17 */ { NULL, NULL, NULL, 0 }, -/* 0x18 */ { NULL, NULL, NULL, 0 }, -/* 0x19 */ { NULL, NULL, NULL, 0 }, -/* 0x1a */ { "SMBreadbraw",NULL,reply_readbraw,AS_USER}, -/* 0x1b */ { "SMBreadBmpx",NULL,reply_readbmpx,AS_USER}, -/* 0x1c */ { "SMBreadBs",NULL,reply_readbs,AS_USER }, -/* 0x1d */ { "SMBwritebraw",NULL,reply_writebraw,AS_USER}, -/* 0x1e */ { "SMBwriteBmpx",NULL,reply_writebmpx,AS_USER}, -/* 0x1f */ { "SMBwriteBs",NULL,reply_writebs,AS_USER}, -/* 0x20 */ { "SMBwritec",NULL, NULL,0}, -/* 0x21 */ { NULL, NULL, NULL, 0 }, -/* 0x22 */ { "SMBsetattrE",NULL,reply_setattrE,AS_USER | NEED_WRITE }, -/* 0x23 */ { "SMBgetattrE",NULL,reply_getattrE,AS_USER }, -/* 0x24 */ { "SMBlockingX",NULL,reply_lockingX,AS_USER }, -/* 0x25 */ { "SMBtrans",NULL,reply_trans,AS_USER | CAN_IPC }, -/* 0x26 */ { "SMBtranss",NULL,reply_transs,AS_USER | CAN_IPC}, -/* 0x27 */ { "SMBioctl",NULL,reply_ioctl,0}, -/* 0x28 */ { "SMBioctls",NULL, NULL,AS_USER}, -/* 0x29 */ { "SMBcopy",NULL,reply_copy,AS_USER | NEED_WRITE }, -/* 0x2a */ { "SMBmove",NULL, NULL,AS_USER | NEED_WRITE }, -/* 0x2b */ { "SMBecho",NULL,reply_echo,0}, -/* 0x2c */ { "SMBwriteclose",NULL,reply_writeclose,AS_USER}, -/* 0x2d */ { "SMBopenX",NULL,reply_open_and_X,AS_USER | CAN_IPC }, -/* 0x2e */ { "SMBreadX",NULL,reply_read_and_X,AS_USER | CAN_IPC }, -/* 0x2f */ { "SMBwriteX",NULL,reply_write_and_X,AS_USER | CAN_IPC }, -/* 0x30 */ { NULL, NULL, NULL, 0 }, -/* 0x31 */ { NULL, NULL, NULL, 0 }, -/* 0x32 */ { "SMBtrans2", NULL,reply_trans2, AS_USER | CAN_IPC }, -/* 0x33 */ { "SMBtranss2", NULL,reply_transs2, AS_USER}, -/* 0x34 */ { "SMBfindclose", NULL,reply_findclose,AS_USER}, -/* 0x35 */ { "SMBfindnclose", NULL,reply_findnclose,AS_USER}, -/* 0x36 */ { NULL, NULL, NULL, 0 }, -/* 0x37 */ { NULL, NULL, NULL, 0 }, -/* 0x38 */ { NULL, NULL, NULL, 0 }, -/* 0x39 */ { NULL, NULL, NULL, 0 }, -/* 0x3a */ { NULL, NULL, NULL, 0 }, -/* 0x3b */ { NULL, NULL, NULL, 0 }, -/* 0x3c */ { NULL, NULL, NULL, 0 }, -/* 0x3d */ { NULL, NULL, NULL, 0 }, -/* 0x3e */ { NULL, NULL, NULL, 0 }, -/* 0x3f */ { NULL, NULL, NULL, 0 }, -/* 0x40 */ { NULL, NULL, NULL, 0 }, -/* 0x41 */ { NULL, NULL, NULL, 0 }, -/* 0x42 */ { NULL, NULL, NULL, 0 }, -/* 0x43 */ { NULL, NULL, NULL, 0 }, -/* 0x44 */ { NULL, NULL, NULL, 0 }, -/* 0x45 */ { NULL, NULL, NULL, 0 }, -/* 0x46 */ { NULL, NULL, NULL, 0 }, -/* 0x47 */ { NULL, NULL, NULL, 0 }, -/* 0x48 */ { NULL, NULL, NULL, 0 }, -/* 0x49 */ { NULL, NULL, NULL, 0 }, -/* 0x4a */ { NULL, NULL, NULL, 0 }, -/* 0x4b */ { NULL, NULL, NULL, 0 }, -/* 0x4c */ { NULL, NULL, NULL, 0 }, -/* 0x4d */ { NULL, NULL, NULL, 0 }, -/* 0x4e */ { NULL, NULL, NULL, 0 }, -/* 0x4f */ { NULL, NULL, NULL, 0 }, -/* 0x50 */ { NULL, NULL, NULL, 0 }, -/* 0x51 */ { NULL, NULL, NULL, 0 }, -/* 0x52 */ { NULL, NULL, NULL, 0 }, -/* 0x53 */ { NULL, NULL, NULL, 0 }, -/* 0x54 */ { NULL, NULL, NULL, 0 }, -/* 0x55 */ { NULL, NULL, NULL, 0 }, -/* 0x56 */ { NULL, NULL, NULL, 0 }, -/* 0x57 */ { NULL, NULL, NULL, 0 }, -/* 0x58 */ { NULL, NULL, NULL, 0 }, -/* 0x59 */ { NULL, NULL, NULL, 0 }, -/* 0x5a */ { NULL, NULL, NULL, 0 }, -/* 0x5b */ { NULL, NULL, NULL, 0 }, -/* 0x5c */ { NULL, NULL, NULL, 0 }, -/* 0x5d */ { NULL, NULL, NULL, 0 }, -/* 0x5e */ { NULL, NULL, NULL, 0 }, -/* 0x5f */ { NULL, NULL, NULL, 0 }, -/* 0x60 */ { NULL, NULL, NULL, 0 }, -/* 0x61 */ { NULL, NULL, NULL, 0 }, -/* 0x62 */ { NULL, NULL, NULL, 0 }, -/* 0x63 */ { NULL, NULL, NULL, 0 }, -/* 0x64 */ { NULL, NULL, NULL, 0 }, -/* 0x65 */ { NULL, NULL, NULL, 0 }, -/* 0x66 */ { NULL, NULL, NULL, 0 }, -/* 0x67 */ { NULL, NULL, NULL, 0 }, -/* 0x68 */ { NULL, NULL, NULL, 0 }, -/* 0x69 */ { NULL, NULL, NULL, 0 }, -/* 0x6a */ { NULL, NULL, NULL, 0 }, -/* 0x6b */ { NULL, NULL, NULL, 0 }, -/* 0x6c */ { NULL, NULL, NULL, 0 }, -/* 0x6d */ { NULL, NULL, NULL, 0 }, -/* 0x6e */ { NULL, NULL, NULL, 0 }, -/* 0x6f */ { NULL, NULL, NULL, 0 }, -/* 0x70 */ { "SMBtcon",NULL,reply_tcon,0}, -/* 0x71 */ { "SMBtdis",NULL,reply_tdis,DO_CHDIR}, -/* 0x72 */ { "SMBnegprot",NULL,reply_negprot,0}, -/* 0x73 */ { "SMBsesssetupX",NULL,reply_sesssetup_and_X,0}, -/* 0x74 */ { "SMBulogoffX", NULL,reply_ulogoffX, 0}, /* ulogoff doesn't give a valid TID */ -/* 0x75 */ { "SMBtconX",NULL,reply_tcon_and_X,0}, -/* 0x76 */ { NULL, NULL, NULL, 0 }, -/* 0x77 */ { NULL, NULL, NULL, 0 }, -/* 0x78 */ { NULL, NULL, NULL, 0 }, -/* 0x79 */ { NULL, NULL, NULL, 0 }, -/* 0x7a */ { NULL, NULL, NULL, 0 }, -/* 0x7b */ { NULL, NULL, NULL, 0 }, -/* 0x7c */ { NULL, NULL, NULL, 0 }, -/* 0x7d */ { NULL, NULL, NULL, 0 }, -/* 0x7e */ { NULL, NULL, NULL, 0 }, -/* 0x7f */ { NULL, NULL, NULL, 0 }, -/* 0x80 */ { "SMBdskattr",NULL,reply_dskattr,AS_USER}, -/* 0x81 */ { "SMBsearch",NULL,reply_search,AS_USER}, -/* 0x82 */ { "SMBffirst",NULL,reply_search,AS_USER}, -/* 0x83 */ { "SMBfunique",NULL,reply_search,AS_USER}, -/* 0x84 */ { "SMBfclose",NULL,reply_fclose,AS_USER}, -/* 0x85 */ { NULL, NULL, NULL, 0 }, -/* 0x86 */ { NULL, NULL, NULL, 0 }, -/* 0x87 */ { NULL, NULL, NULL, 0 }, -/* 0x88 */ { NULL, NULL, NULL, 0 }, -/* 0x89 */ { NULL, NULL, NULL, 0 }, -/* 0x8a */ { NULL, NULL, NULL, 0 }, -/* 0x8b */ { NULL, NULL, NULL, 0 }, -/* 0x8c */ { NULL, NULL, NULL, 0 }, -/* 0x8d */ { NULL, NULL, NULL, 0 }, -/* 0x8e */ { NULL, NULL, NULL, 0 }, -/* 0x8f */ { NULL, NULL, NULL, 0 }, -/* 0x90 */ { NULL, NULL, NULL, 0 }, -/* 0x91 */ { NULL, NULL, NULL, 0 }, -/* 0x92 */ { NULL, NULL, NULL, 0 }, -/* 0x93 */ { NULL, NULL, NULL, 0 }, -/* 0x94 */ { NULL, NULL, NULL, 0 }, -/* 0x95 */ { NULL, NULL, NULL, 0 }, -/* 0x96 */ { NULL, NULL, NULL, 0 }, -/* 0x97 */ { NULL, NULL, NULL, 0 }, -/* 0x98 */ { NULL, NULL, NULL, 0 }, -/* 0x99 */ { NULL, NULL, NULL, 0 }, -/* 0x9a */ { NULL, NULL, NULL, 0 }, -/* 0x9b */ { NULL, NULL, NULL, 0 }, -/* 0x9c */ { NULL, NULL, NULL, 0 }, -/* 0x9d */ { NULL, NULL, NULL, 0 }, -/* 0x9e */ { NULL, NULL, NULL, 0 }, -/* 0x9f */ { NULL, NULL, NULL, 0 }, -/* 0xa0 */ { "SMBnttrans", NULL,reply_nttrans, AS_USER | CAN_IPC }, -/* 0xa1 */ { "SMBnttranss", NULL,reply_nttranss, AS_USER | CAN_IPC }, -/* 0xa2 */ { "SMBntcreateX", NULL,reply_ntcreate_and_X, AS_USER | CAN_IPC }, -/* 0xa3 */ { NULL, NULL, NULL, 0 }, -/* 0xa4 */ { "SMBntcancel", NULL,reply_ntcancel, 0 }, -/* 0xa5 */ { "SMBntrename", NULL,reply_ntrename, AS_USER | NEED_WRITE }, -/* 0xa6 */ { NULL, NULL, NULL, 0 }, -/* 0xa7 */ { NULL, NULL, NULL, 0 }, -/* 0xa8 */ { NULL, NULL, NULL, 0 }, -/* 0xa9 */ { NULL, NULL, NULL, 0 }, -/* 0xaa */ { NULL, NULL, NULL, 0 }, -/* 0xab */ { NULL, NULL, NULL, 0 }, -/* 0xac */ { NULL, NULL, NULL, 0 }, -/* 0xad */ { NULL, NULL, NULL, 0 }, -/* 0xae */ { NULL, NULL, NULL, 0 }, -/* 0xaf */ { NULL, NULL, NULL, 0 }, -/* 0xb0 */ { NULL, NULL, NULL, 0 }, -/* 0xb1 */ { NULL, NULL, NULL, 0 }, -/* 0xb2 */ { NULL, NULL, NULL, 0 }, -/* 0xb3 */ { NULL, NULL, NULL, 0 }, -/* 0xb4 */ { NULL, NULL, NULL, 0 }, -/* 0xb5 */ { NULL, NULL, NULL, 0 }, -/* 0xb6 */ { NULL, NULL, NULL, 0 }, -/* 0xb7 */ { NULL, NULL, NULL, 0 }, -/* 0xb8 */ { NULL, NULL, NULL, 0 }, -/* 0xb9 */ { NULL, NULL, NULL, 0 }, -/* 0xba */ { NULL, NULL, NULL, 0 }, -/* 0xbb */ { NULL, NULL, NULL, 0 }, -/* 0xbc */ { NULL, NULL, NULL, 0 }, -/* 0xbd */ { NULL, NULL, NULL, 0 }, -/* 0xbe */ { NULL, NULL, NULL, 0 }, -/* 0xbf */ { NULL, NULL, NULL, 0 }, -/* 0xc0 */ { "SMBsplopen",NULL,reply_printopen,AS_USER}, -/* 0xc1 */ { "SMBsplwr",NULL,reply_printwrite,AS_USER}, -/* 0xc2 */ { "SMBsplclose",NULL,reply_printclose,AS_USER}, -/* 0xc3 */ { "SMBsplretq",NULL,reply_printqueue,AS_USER}, -/* 0xc4 */ { NULL, NULL, NULL, 0 }, -/* 0xc5 */ { NULL, NULL, NULL, 0 }, -/* 0xc6 */ { NULL, NULL, NULL, 0 }, -/* 0xc7 */ { NULL, NULL, NULL, 0 }, -/* 0xc8 */ { NULL, NULL, NULL, 0 }, -/* 0xc9 */ { NULL, NULL, NULL, 0 }, -/* 0xca */ { NULL, NULL, NULL, 0 }, -/* 0xcb */ { NULL, NULL, NULL, 0 }, -/* 0xcc */ { NULL, NULL, NULL, 0 }, -/* 0xcd */ { NULL, NULL, NULL, 0 }, -/* 0xce */ { NULL, NULL, NULL, 0 }, -/* 0xcf */ { NULL, NULL, NULL, 0 }, -/* 0xd0 */ { "SMBsends",NULL,reply_sends,AS_GUEST}, -/* 0xd1 */ { "SMBsendb",NULL, NULL,AS_GUEST}, -/* 0xd2 */ { "SMBfwdname",NULL, NULL,AS_GUEST}, -/* 0xd3 */ { "SMBcancelf",NULL, NULL,AS_GUEST}, -/* 0xd4 */ { "SMBgetmac",NULL, NULL,AS_GUEST}, -/* 0xd5 */ { "SMBsendstrt",NULL,reply_sendstrt,AS_GUEST}, -/* 0xd6 */ { "SMBsendend",NULL,reply_sendend,AS_GUEST}, -/* 0xd7 */ { "SMBsendtxt",NULL,reply_sendtxt,AS_GUEST}, -/* 0xd8 */ { NULL, NULL, NULL, 0 }, -/* 0xd9 */ { NULL, NULL, NULL, 0 }, -/* 0xda */ { NULL, NULL, NULL, 0 }, -/* 0xdb */ { NULL, NULL, NULL, 0 }, -/* 0xdc */ { NULL, NULL, NULL, 0 }, -/* 0xdd */ { NULL, NULL, NULL, 0 }, -/* 0xde */ { NULL, NULL, NULL, 0 }, -/* 0xdf */ { NULL, NULL, NULL, 0 }, -/* 0xe0 */ { NULL, NULL, NULL, 0 }, -/* 0xe1 */ { NULL, NULL, NULL, 0 }, -/* 0xe2 */ { NULL, NULL, NULL, 0 }, -/* 0xe3 */ { NULL, NULL, NULL, 0 }, -/* 0xe4 */ { NULL, NULL, NULL, 0 }, -/* 0xe5 */ { NULL, NULL, NULL, 0 }, -/* 0xe6 */ { NULL, NULL, NULL, 0 }, -/* 0xe7 */ { NULL, NULL, NULL, 0 }, -/* 0xe8 */ { NULL, NULL, NULL, 0 }, -/* 0xe9 */ { NULL, NULL, NULL, 0 }, -/* 0xea */ { NULL, NULL, NULL, 0 }, -/* 0xeb */ { NULL, NULL, NULL, 0 }, -/* 0xec */ { NULL, NULL, NULL, 0 }, -/* 0xed */ { NULL, NULL, NULL, 0 }, -/* 0xee */ { NULL, NULL, NULL, 0 }, -/* 0xef */ { NULL, NULL, NULL, 0 }, -/* 0xf0 */ { NULL, NULL, NULL, 0 }, -/* 0xf1 */ { NULL, NULL, NULL, 0 }, -/* 0xf2 */ { NULL, NULL, NULL, 0 }, -/* 0xf3 */ { NULL, NULL, NULL, 0 }, -/* 0xf4 */ { NULL, NULL, NULL, 0 }, -/* 0xf5 */ { NULL, NULL, NULL, 0 }, -/* 0xf6 */ { NULL, NULL, NULL, 0 }, -/* 0xf7 */ { NULL, NULL, NULL, 0 }, -/* 0xf8 */ { NULL, NULL, NULL, 0 }, -/* 0xf9 */ { NULL, NULL, NULL, 0 }, -/* 0xfa */ { NULL, NULL, NULL, 0 }, -/* 0xfb */ { NULL, NULL, NULL, 0 }, -/* 0xfc */ { NULL, NULL, NULL, 0 }, -/* 0xfd */ { NULL, NULL, NULL, 0 }, -/* 0xfe */ { NULL, NULL, NULL, 0 }, -/* 0xff */ { NULL, NULL, NULL, 0 } +/* 0x00 */ { "SMBmkdir",reply_mkdir,AS_USER | NEED_WRITE}, +/* 0x01 */ { "SMBrmdir",reply_rmdir,AS_USER | NEED_WRITE}, +/* 0x02 */ { "SMBopen",reply_open,AS_USER }, +/* 0x03 */ { "SMBcreate",reply_mknew,AS_USER}, +/* 0x04 */ { "SMBclose",reply_close,AS_USER | CAN_IPC }, +/* 0x05 */ { "SMBflush",reply_flush,AS_USER}, +/* 0x06 */ { "SMBunlink",reply_unlink,AS_USER | NEED_WRITE }, +/* 0x07 */ { "SMBmv",reply_mv,AS_USER | NEED_WRITE }, +/* 0x08 */ { "SMBgetatr",reply_getatr,AS_USER}, +/* 0x09 */ { "SMBsetatr",reply_setatr,AS_USER | NEED_WRITE}, +/* 0x0a */ { "SMBread",reply_read,AS_USER}, +/* 0x0b */ { "SMBwrite",reply_write,AS_USER | CAN_IPC }, +/* 0x0c */ { "SMBlock",reply_lock,AS_USER}, +/* 0x0d */ { "SMBunlock",reply_unlock,AS_USER}, +/* 0x0e */ { "SMBctemp",reply_ctemp,AS_USER }, +/* 0x0f */ { "SMBmknew",reply_mknew,AS_USER}, +/* 0x10 */ { "SMBcheckpath",reply_checkpath,AS_USER}, +/* 0x11 */ { "SMBexit",reply_exit,DO_CHDIR}, +/* 0x12 */ { "SMBlseek",reply_lseek,AS_USER}, +/* 0x13 */ { "SMBlockread",reply_lockread,AS_USER}, +/* 0x14 */ { "SMBwriteunlock",reply_writeunlock,AS_USER}, +/* 0x15 */ { NULL, NULL, 0 }, +/* 0x16 */ { NULL, NULL, 0 }, +/* 0x17 */ { NULL, NULL, 0 }, +/* 0x18 */ { NULL, NULL, 0 }, +/* 0x19 */ { NULL, NULL, 0 }, +/* 0x1a */ { "SMBreadbraw",reply_readbraw,AS_USER}, +/* 0x1b */ { "SMBreadBmpx",reply_readbmpx,AS_USER}, +/* 0x1c */ { "SMBreadBs",reply_readbs,AS_USER }, +/* 0x1d */ { "SMBwritebraw",reply_writebraw,AS_USER}, +/* 0x1e */ { "SMBwriteBmpx",reply_writebmpx,AS_USER}, +/* 0x1f */ { "SMBwriteBs",reply_writebs,AS_USER}, +/* 0x20 */ { "SMBwritec", NULL,0}, +/* 0x21 */ { NULL, NULL, 0 }, +/* 0x22 */ { "SMBsetattrE",reply_setattrE,AS_USER | NEED_WRITE }, +/* 0x23 */ { "SMBgetattrE",reply_getattrE,AS_USER }, +/* 0x24 */ { "SMBlockingX",reply_lockingX,AS_USER }, +/* 0x25 */ { "SMBtrans",reply_trans,AS_USER | CAN_IPC }, +/* 0x26 */ { "SMBtranss",reply_transs,AS_USER | CAN_IPC}, +/* 0x27 */ { "SMBioctl",reply_ioctl,0}, +/* 0x28 */ { "SMBioctls", NULL,AS_USER}, +/* 0x29 */ { "SMBcopy",reply_copy,AS_USER | NEED_WRITE }, +/* 0x2a */ { "SMBmove", NULL,AS_USER | NEED_WRITE }, +/* 0x2b */ { "SMBecho",reply_echo,0}, +/* 0x2c */ { "SMBwriteclose",reply_writeclose,AS_USER}, +/* 0x2d */ { "SMBopenX",reply_open_and_X,AS_USER | CAN_IPC }, +/* 0x2e */ { "SMBreadX",reply_read_and_X,AS_USER | CAN_IPC }, +/* 0x2f */ { "SMBwriteX",reply_write_and_X,AS_USER | CAN_IPC }, +/* 0x30 */ { NULL, NULL, 0 }, +/* 0x31 */ { NULL, NULL, 0 }, +/* 0x32 */ { "SMBtrans2",reply_trans2, AS_USER | CAN_IPC }, +/* 0x33 */ { "SMBtranss2",reply_transs2, AS_USER}, +/* 0x34 */ { "SMBfindclose",reply_findclose,AS_USER}, +/* 0x35 */ { "SMBfindnclose",reply_findnclose,AS_USER}, +/* 0x36 */ { NULL, NULL, 0 }, +/* 0x37 */ { NULL, NULL, 0 }, +/* 0x38 */ { NULL, NULL, 0 }, +/* 0x39 */ { NULL, NULL, 0 }, +/* 0x3a */ { NULL, NULL, 0 }, +/* 0x3b */ { NULL, NULL, 0 }, +/* 0x3c */ { NULL, NULL, 0 }, +/* 0x3d */ { NULL, NULL, 0 }, +/* 0x3e */ { NULL, NULL, 0 }, +/* 0x3f */ { NULL, NULL, 0 }, +/* 0x40 */ { NULL, NULL, 0 }, +/* 0x41 */ { NULL, NULL, 0 }, +/* 0x42 */ { NULL, NULL, 0 }, +/* 0x43 */ { NULL, NULL, 0 }, +/* 0x44 */ { NULL, NULL, 0 }, +/* 0x45 */ { NULL, NULL, 0 }, +/* 0x46 */ { NULL, NULL, 0 }, +/* 0x47 */ { NULL, NULL, 0 }, +/* 0x48 */ { NULL, NULL, 0 }, +/* 0x49 */ { NULL, NULL, 0 }, +/* 0x4a */ { NULL, NULL, 0 }, +/* 0x4b */ { NULL, NULL, 0 }, +/* 0x4c */ { NULL, NULL, 0 }, +/* 0x4d */ { NULL, NULL, 0 }, +/* 0x4e */ { NULL, NULL, 0 }, +/* 0x4f */ { NULL, NULL, 0 }, +/* 0x50 */ { NULL, NULL, 0 }, +/* 0x51 */ { NULL, NULL, 0 }, +/* 0x52 */ { NULL, NULL, 0 }, +/* 0x53 */ { NULL, NULL, 0 }, +/* 0x54 */ { NULL, NULL, 0 }, +/* 0x55 */ { NULL, NULL, 0 }, +/* 0x56 */ { NULL, NULL, 0 }, +/* 0x57 */ { NULL, NULL, 0 }, +/* 0x58 */ { NULL, NULL, 0 }, +/* 0x59 */ { NULL, NULL, 0 }, +/* 0x5a */ { NULL, NULL, 0 }, +/* 0x5b */ { NULL, NULL, 0 }, +/* 0x5c */ { NULL, NULL, 0 }, +/* 0x5d */ { NULL, NULL, 0 }, +/* 0x5e */ { NULL, NULL, 0 }, +/* 0x5f */ { NULL, NULL, 0 }, +/* 0x60 */ { NULL, NULL, 0 }, +/* 0x61 */ { NULL, NULL, 0 }, +/* 0x62 */ { NULL, NULL, 0 }, +/* 0x63 */ { NULL, NULL, 0 }, +/* 0x64 */ { NULL, NULL, 0 }, +/* 0x65 */ { NULL, NULL, 0 }, +/* 0x66 */ { NULL, NULL, 0 }, +/* 0x67 */ { NULL, NULL, 0 }, +/* 0x68 */ { NULL, NULL, 0 }, +/* 0x69 */ { NULL, NULL, 0 }, +/* 0x6a */ { NULL, NULL, 0 }, +/* 0x6b */ { NULL, NULL, 0 }, +/* 0x6c */ { NULL, NULL, 0 }, +/* 0x6d */ { NULL, NULL, 0 }, +/* 0x6e */ { NULL, NULL, 0 }, +/* 0x6f */ { NULL, NULL, 0 }, +/* 0x70 */ { "SMBtcon",reply_tcon,0}, +/* 0x71 */ { "SMBtdis",reply_tdis,DO_CHDIR}, +/* 0x72 */ { "SMBnegprot",reply_negprot,0}, +/* 0x73 */ { "SMBsesssetupX",reply_sesssetup_and_X,0}, +/* 0x74 */ { "SMBulogoffX",reply_ulogoffX, 0}, /* ulogoff doesn't give a valid TID */ +/* 0x75 */ { "SMBtconX",reply_tcon_and_X,0}, +/* 0x76 */ { NULL, NULL, 0 }, +/* 0x77 */ { NULL, NULL, 0 }, +/* 0x78 */ { NULL, NULL, 0 }, +/* 0x79 */ { NULL, NULL, 0 }, +/* 0x7a */ { NULL, NULL, 0 }, +/* 0x7b */ { NULL, NULL, 0 }, +/* 0x7c */ { NULL, NULL, 0 }, +/* 0x7d */ { NULL, NULL, 0 }, +/* 0x7e */ { NULL, NULL, 0 }, +/* 0x7f */ { NULL, NULL, 0 }, +/* 0x80 */ { "SMBdskattr",reply_dskattr,AS_USER}, +/* 0x81 */ { "SMBsearch",reply_search,AS_USER}, +/* 0x82 */ { "SMBffirst",reply_search,AS_USER}, +/* 0x83 */ { "SMBfunique",reply_search,AS_USER}, +/* 0x84 */ { "SMBfclose",reply_fclose,AS_USER}, +/* 0x85 */ { NULL, NULL, 0 }, +/* 0x86 */ { NULL, NULL, 0 }, +/* 0x87 */ { NULL, NULL, 0 }, +/* 0x88 */ { NULL, NULL, 0 }, +/* 0x89 */ { NULL, NULL, 0 }, +/* 0x8a */ { NULL, NULL, 0 }, +/* 0x8b */ { NULL, NULL, 0 }, +/* 0x8c */ { NULL, NULL, 0 }, +/* 0x8d */ { NULL, NULL, 0 }, +/* 0x8e */ { NULL, NULL, 0 }, +/* 0x8f */ { NULL, NULL, 0 }, +/* 0x90 */ { NULL, NULL, 0 }, +/* 0x91 */ { NULL, NULL, 0 }, +/* 0x92 */ { NULL, NULL, 0 }, +/* 0x93 */ { NULL, NULL, 0 }, +/* 0x94 */ { NULL, NULL, 0 }, +/* 0x95 */ { NULL, NULL, 0 }, +/* 0x96 */ { NULL, NULL, 0 }, +/* 0x97 */ { NULL, NULL, 0 }, +/* 0x98 */ { NULL, NULL, 0 }, +/* 0x99 */ { NULL, NULL, 0 }, +/* 0x9a */ { NULL, NULL, 0 }, +/* 0x9b */ { NULL, NULL, 0 }, +/* 0x9c */ { NULL, NULL, 0 }, +/* 0x9d */ { NULL, NULL, 0 }, +/* 0x9e */ { NULL, NULL, 0 }, +/* 0x9f */ { NULL, NULL, 0 }, +/* 0xa0 */ { "SMBnttrans",reply_nttrans, AS_USER | CAN_IPC }, +/* 0xa1 */ { "SMBnttranss",reply_nttranss, AS_USER | CAN_IPC }, +/* 0xa2 */ { "SMBntcreateX",reply_ntcreate_and_X, AS_USER | CAN_IPC }, +/* 0xa3 */ { NULL, NULL, 0 }, +/* 0xa4 */ { "SMBntcancel",reply_ntcancel, 0 }, +/* 0xa5 */ { "SMBntrename",reply_ntrename, AS_USER | NEED_WRITE }, +/* 0xa6 */ { NULL, NULL, 0 }, +/* 0xa7 */ { NULL, NULL, 0 }, +/* 0xa8 */ { NULL, NULL, 0 }, +/* 0xa9 */ { NULL, NULL, 0 }, +/* 0xaa */ { NULL, NULL, 0 }, +/* 0xab */ { NULL, NULL, 0 }, +/* 0xac */ { NULL, NULL, 0 }, +/* 0xad */ { NULL, NULL, 0 }, +/* 0xae */ { NULL, NULL, 0 }, +/* 0xaf */ { NULL, NULL, 0 }, +/* 0xb0 */ { NULL, NULL, 0 }, +/* 0xb1 */ { NULL, NULL, 0 }, +/* 0xb2 */ { NULL, NULL, 0 }, +/* 0xb3 */ { NULL, NULL, 0 }, +/* 0xb4 */ { NULL, NULL, 0 }, +/* 0xb5 */ { NULL, NULL, 0 }, +/* 0xb6 */ { NULL, NULL, 0 }, +/* 0xb7 */ { NULL, NULL, 0 }, +/* 0xb8 */ { NULL, NULL, 0 }, +/* 0xb9 */ { NULL, NULL, 0 }, +/* 0xba */ { NULL, NULL, 0 }, +/* 0xbb */ { NULL, NULL, 0 }, +/* 0xbc */ { NULL, NULL, 0 }, +/* 0xbd */ { NULL, NULL, 0 }, +/* 0xbe */ { NULL, NULL, 0 }, +/* 0xbf */ { NULL, NULL, 0 }, +/* 0xc0 */ { "SMBsplopen",reply_printopen,AS_USER}, +/* 0xc1 */ { "SMBsplwr",reply_printwrite,AS_USER}, +/* 0xc2 */ { "SMBsplclose",reply_printclose,AS_USER}, +/* 0xc3 */ { "SMBsplretq",reply_printqueue,AS_USER}, +/* 0xc4 */ { NULL, NULL, 0 }, +/* 0xc5 */ { NULL, NULL, 0 }, +/* 0xc6 */ { NULL, NULL, 0 }, +/* 0xc7 */ { NULL, NULL, 0 }, +/* 0xc8 */ { NULL, NULL, 0 }, +/* 0xc9 */ { NULL, NULL, 0 }, +/* 0xca */ { NULL, NULL, 0 }, +/* 0xcb */ { NULL, NULL, 0 }, +/* 0xcc */ { NULL, NULL, 0 }, +/* 0xcd */ { NULL, NULL, 0 }, +/* 0xce */ { NULL, NULL, 0 }, +/* 0xcf */ { NULL, NULL, 0 }, +/* 0xd0 */ { "SMBsends",reply_sends,AS_GUEST}, +/* 0xd1 */ { "SMBsendb", NULL,AS_GUEST}, +/* 0xd2 */ { "SMBfwdname", NULL,AS_GUEST}, +/* 0xd3 */ { "SMBcancelf", NULL,AS_GUEST}, +/* 0xd4 */ { "SMBgetmac", NULL,AS_GUEST}, +/* 0xd5 */ { "SMBsendstrt",reply_sendstrt,AS_GUEST}, +/* 0xd6 */ { "SMBsendend",reply_sendend,AS_GUEST}, +/* 0xd7 */ { "SMBsendtxt",reply_sendtxt,AS_GUEST}, +/* 0xd8 */ { NULL, NULL, 0 }, +/* 0xd9 */ { NULL, NULL, 0 }, +/* 0xda */ { NULL, NULL, 0 }, +/* 0xdb */ { NULL, NULL, 0 }, +/* 0xdc */ { NULL, NULL, 0 }, +/* 0xdd */ { NULL, NULL, 0 }, +/* 0xde */ { NULL, NULL, 0 }, +/* 0xdf */ { NULL, NULL, 0 }, +/* 0xe0 */ { NULL, NULL, 0 }, +/* 0xe1 */ { NULL, NULL, 0 }, +/* 0xe2 */ { NULL, NULL, 0 }, +/* 0xe3 */ { NULL, NULL, 0 }, +/* 0xe4 */ { NULL, NULL, 0 }, +/* 0xe5 */ { NULL, NULL, 0 }, +/* 0xe6 */ { NULL, NULL, 0 }, +/* 0xe7 */ { NULL, NULL, 0 }, +/* 0xe8 */ { NULL, NULL, 0 }, +/* 0xe9 */ { NULL, NULL, 0 }, +/* 0xea */ { NULL, NULL, 0 }, +/* 0xeb */ { NULL, NULL, 0 }, +/* 0xec */ { NULL, NULL, 0 }, +/* 0xed */ { NULL, NULL, 0 }, +/* 0xee */ { NULL, NULL, 0 }, +/* 0xef */ { NULL, NULL, 0 }, +/* 0xf0 */ { NULL, NULL, 0 }, +/* 0xf1 */ { NULL, NULL, 0 }, +/* 0xf2 */ { NULL, NULL, 0 }, +/* 0xf3 */ { NULL, NULL, 0 }, +/* 0xf4 */ { NULL, NULL, 0 }, +/* 0xf5 */ { NULL, NULL, 0 }, +/* 0xf6 */ { NULL, NULL, 0 }, +/* 0xf7 */ { NULL, NULL, 0 }, +/* 0xf8 */ { NULL, NULL, 0 }, +/* 0xf9 */ { NULL, NULL, 0 }, +/* 0xfa */ { NULL, NULL, 0 }, +/* 0xfb */ { NULL, NULL, 0 }, +/* 0xfc */ { NULL, NULL, 0 }, +/* 0xfd */ { NULL, NULL, 0 }, +/* 0xfe */ { NULL, NULL, 0 }, +/* 0xff */ { NULL, NULL, 0 } }; @@ -1049,8 +985,7 @@ static void smb_dump(const char *name, int type, const char *data, ssize_t len) find. ****************************************************************************/ -static BOOL switch_message_new(uint8 type, struct smb_request *req, int size, - connection_struct **pconn) +static void switch_message(uint8 type, struct smb_request *req, int size) { int flags; uint16 session_tag; @@ -1069,15 +1004,13 @@ static BOOL switch_message_new(uint8 type, struct smb_request *req, int size, DEBUG(2,("Non-SMB packet of length %d. Terminating server\n", smb_len(req->inbuf))); exit_server_cleanly("Non-SMB packet"); - return True; } - if ((smb_messages[type].fn == NULL) - && (smb_messages[type].fn_new == NULL)) { + if (smb_messages[type].fn_new == NULL) { DEBUG(0,("Unknown message type %d!\n",type)); smb_dump("Unknown", 1, (char *)req->inbuf, size); reply_unknown_new(req, type); - goto done; + return; } flags = smb_messages[type].flags; @@ -1130,12 +1063,12 @@ static BOOL switch_message_new(uint8 type, struct smb_request *req, int size, } else { reply_doserror(req, ERRSRV, ERRinvnid); } - goto done; + return; } if (!change_to_user(conn,session_tag)) { reply_nterror(req, NT_STATUS_DOS(ERRSRV, ERRbaduid)); - goto done; + return; } /* All NEED_WRITE and CAN_IPC flags must also have AS_USER. */ @@ -1143,13 +1076,13 @@ static BOOL switch_message_new(uint8 type, struct smb_request *req, int size, /* Does it need write permission? */ if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) { reply_nterror(req, NT_STATUS_MEDIA_WRITE_PROTECTED); - goto done; + return; } /* IPC services are limited */ if (IS_IPC(conn) && !(flags & CAN_IPC)) { reply_doserror(req, ERRSRV,ERRaccess); - goto done; + return; } } else { /* This call needs to be run as root */ @@ -1162,7 +1095,7 @@ static BOOL switch_message_new(uint8 type, struct smb_request *req, int size, (flags & (AS_USER|DO_CHDIR) ?True:False))) { reply_doserror(req, ERRSRV, ERRaccess); - goto done; + return; } conn->num_smb_operations++; } @@ -1173,73 +1106,10 @@ static BOOL switch_message_new(uint8 type, struct smb_request *req, int size, !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) { reply_doserror(req, ERRSRV, ERRaccess); - goto done; - } - - current_inbuf = (char *)req->inbuf; /* In case we need to defer this - * message in open... */ - - if (smb_messages[type].fn_new != NULL) { - smb_messages[type].fn_new(conn, req); - goto done; - } - - /* - * Indicate the upper layer that there's still work. - */ - *pconn = conn; - return False; - - done: - return True; -} - - -/**************************************************************************** - Do a switch on the message type, and return the response size -****************************************************************************/ - -static int switch_message(uint8 type, struct smb_request *req, char **outbuf, - int size, int bufsize) -{ - int outsize = 0; - connection_struct *conn = NULL; - - if (switch_message_new(type, req, size, &conn)) { - if (req->outbuf != NULL) { - *outbuf = (char *)req->outbuf; - return smb_len(req->outbuf)+4; - } - return -1; - } - - if (InBuffer == NULL) { - DEBUG(1, ("have to alloc InBuffer for %s\n", - smb_fn_name(type))); - if (NewInBuffer(NULL) == NULL) { - smb_panic("Could not allocate InBuffer"); - } - } - - if ((OutBuffer == NULL) && (NewOutBuffer(NULL) == NULL)) { - smb_panic("Could not allocate OutBuffer"); + return; } - clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, - total_buffer_size); - - memcpy(InBuffer, req->inbuf, MIN(size, total_buffer_size)); - - construct_reply_common(InBuffer, OutBuffer); - - outsize = smb_messages[type].fn(conn, InBuffer, OutBuffer, size, - bufsize); - - smb_dump(smb_fn_name(type), 0, OutBuffer, outsize); - - *outbuf = OutBuffer; - - return(outsize); + smb_messages[type].fn_new(conn, req); } /**************************************************************************** @@ -1249,9 +1119,7 @@ static int switch_message(uint8 type, struct smb_request *req, char **outbuf, static void construct_reply(char *inbuf, int size) { uint8 type = CVAL(inbuf,smb_com); - int outsize = 0; struct smb_request *req; - char *outbuf; chain_size = 0; file_chain_reset(); @@ -1262,23 +1130,18 @@ static void construct_reply(char *inbuf, int size) } init_smb_request(req, (uint8 *)inbuf); - outsize = switch_message(type, req, &outbuf, size, max_send); + switch_message(type, req, size); - if (outsize > 4) { - smb_setlen(inbuf,outbuf,outsize - 4); + if (req->outbuf == NULL) { + return; } - if (outsize > 0) { - if (CVAL(outbuf,0) == 0) - show_msg(outbuf); + if (CVAL(req->outbuf,0) == 0) { + show_msg((char *)req->outbuf); + } - if (outsize != smb_len(outbuf) + 4) { - DEBUG(0,("ERROR: Invalid message response size! " - "%d %d\n", outsize, smb_len(outbuf))); - } else if (!send_smb(smbd_server_fd(),outbuf)) { - exit_server_cleanly("construct_reply: send_smb " - "failed."); - } + if (!send_smb(smbd_server_fd(), (char *)req->outbuf)) { + exit_server_cleanly("construct_reply: send_smb failed."); } TALLOC_FREE(req); @@ -1383,29 +1246,37 @@ void construct_reply_common(const char *inbuf, char *outbuf) Construct a chained reply and add it to the already made reply ****************************************************************************/ -int chain_reply(char *inbuf,char **poutbuf,int size,int bufsize) +void chain_reply(struct smb_request *req) { static char *orig_inbuf; + + /* + * Dirty little const_discard: We mess with req->inbuf, which is + * declared as const. If maybe at some point this routine gets + * rewritten, this const_discard could go away. + */ + char *inbuf = CONST_DISCARD(char *, req->inbuf); + int size = smb_len(req->inbuf)+4; + int smb_com1, smb_com2 = CVAL(inbuf,smb_vwv0); unsigned smb_off2 = SVAL(inbuf,smb_vwv1); char *inbuf2; - char *outbuf2 = NULL; int outsize2; int new_size; char inbuf_saved[smb_wct]; - char *outbuf = *poutbuf; + char *outbuf = (char *)req->outbuf; size_t outsize = smb_len(outbuf) + 4; size_t outsize_padded; size_t ofs, to_move; - struct smb_request *req; + struct smb_request *req2; size_t caller_outputlen; char *caller_output; /* Maybe its not chained, or it's an error packet. */ if (smb_com2 == 0xFF || SVAL(outbuf,smb_rcls) != 0) { SCVAL(outbuf,smb_vwv0,0xFF); - return outsize; + return; } if (chain_size == 0) { @@ -1466,7 +1337,7 @@ int chain_reply(char *inbuf,char **poutbuf,int size,int bufsize) "(orig size = %d, offset = %d)\n", size, (int)(inbuf2 - inbuf) )); exit_server_cleanly("Bad chained packet"); - return(-1); + return; } /* And set it in the header. */ @@ -1475,19 +1346,19 @@ int chain_reply(char *inbuf,char **poutbuf,int size,int bufsize) DEBUG(3,("Chained message\n")); show_msg(inbuf2); - if (!(req = talloc(tmp_talloc_ctx(), struct smb_request))) { + if (!(req2 = talloc(tmp_talloc_ctx(), struct smb_request))) { smb_panic("could not allocate smb_request"); } - init_smb_request(req, (uint8 *)inbuf2); + init_smb_request(req2, (uint8 *)inbuf2); /* process the request */ - outsize2 = switch_message(smb_com2, req, &outbuf2, new_size, - bufsize-chain_size); + switch_message(smb_com2, req2, new_size); /* * We don't accept deferred operations in chained requests. */ - SMB_ASSERT(outsize2 >= smb_wct); + SMB_ASSERT(req2->outbuf != NULL); + outsize2 = smb_len(req2->outbuf)+4; /* * Move away the new command output so that caller_output fits in, @@ -1520,24 +1391,22 @@ int chain_reply(char *inbuf,char **poutbuf,int size,int bufsize) * which is always large enough. */ - if (outbuf != OutBuffer) { - outbuf = TALLOC_REALLOC_ARRAY(NULL, outbuf, char, - to_move + ofs + smb_wct); - if (outbuf == NULL) { - smb_panic("could not realloc outbuf"); - } + outbuf = TALLOC_REALLOC_ARRAY(NULL, outbuf, char, + to_move + ofs + smb_wct); + if (outbuf == NULL) { + smb_panic("could not realloc outbuf"); } - *poutbuf = outbuf; + req->outbuf = (uint8 *)outbuf; - memmove(outbuf + smb_wct + ofs, outbuf2 + smb_wct, to_move); + memmove(outbuf + smb_wct + ofs, req2->outbuf + smb_wct, to_move); memcpy(outbuf + smb_wct, caller_output, caller_outputlen); /* * copy the new reply header over the old one but preserve the smb_com * field */ - memmove(outbuf,outbuf2,smb_wct); + memmove(outbuf, req2->outbuf, smb_wct); SCVAL(outbuf, smb_com, smb_com1); /* @@ -1568,17 +1437,9 @@ int chain_reply(char *inbuf,char **poutbuf,int size,int bufsize) memcpy(inbuf2,inbuf_saved,smb_wct); SAFE_FREE(caller_output); - TALLOC_FREE(req); - - return outsize2 + chain_size; -} + TALLOC_FREE(req2); -void chain_reply_new(struct smb_request *req) -{ - chain_reply(CONST_DISCARD(char *, req->inbuf), - (char **)(void *)&req->outbuf, - smb_len(req->inbuf)+4, - smb_len(req->outbuf)+4); + return; } /**************************************************************************** @@ -1757,55 +1618,6 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); return True; } -/**************************************************************************** - Accessor functions for InBuffer, OutBuffer. -****************************************************************************/ - -char *get_InBuffer(void) -{ - return InBuffer; -} - -/**************************************************************************** - Allocate a new InBuffer. Returns the new and old ones. -****************************************************************************/ - -static char *NewInBuffer(char **old_inbuf) -{ - char *new_inbuf = (char *)SMB_MALLOC(total_buffer_size); - if (!new_inbuf) { - return NULL; - } - if (old_inbuf) { - *old_inbuf = InBuffer; - } - InBuffer = new_inbuf; -#if defined(DEVELOPER) - clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); -#endif - return InBuffer; -} - -/**************************************************************************** - Allocate a new OutBuffer. Returns the new and old ones. -****************************************************************************/ - -static char *NewOutBuffer(char **old_outbuf) -{ - char *new_outbuf = (char *)SMB_MALLOC(total_buffer_size); - if (!new_outbuf) { - return NULL; - } - if (old_outbuf) { - *old_outbuf = OutBuffer; - } - OutBuffer = new_outbuf; -#if defined(DEVELOPER) - clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size); -#endif - return OutBuffer; -} - /**************************************************************************** Process commands from the client ****************************************************************************/ -- cgit From 929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 30 Aug 2007 19:48:31 +0000 Subject: r24809: Consolidate the use of temporary talloc contexts. This adds the two functions talloc_stackframe() and talloc_tos(). * When a new talloc stackframe is allocated with talloc_stackframe(), then * the TALLOC_CTX returned with talloc_tos() is reset to that new * frame. Whenever that stack frame is TALLOC_FREE()'ed, then the reverse * happens: The previous talloc_tos() is restored. * * This API is designed to be robust in the sense that if someone forgets to * TALLOC_FREE() a stackframe, then the next outer one correctly cleans up and * resets the talloc_tos(). The original motivation for this patch was to get rid of the sid_string_static & friends buffers. Explicitly passing talloc context everywhere clutters code too much for my taste, so an implicit talloc_tos() is introduced here. Many of these static buffers are replaced by a single static pointer. The intended use would thus be that low-level functions can rather freely push stuff to talloc_tos, the upper layers clean up by freeing the stackframe. The more of these stackframes are used and correctly freed the more exact the memory cleanup happens. This patch removes the main_loop_talloc_ctx, tmp_talloc_ctx and lp_talloc_ctx (did I forget any?) So, never do a tmp_ctx = talloc_init("foo"); anymore, instead, use tmp_ctx = talloc_stackframe() :-) Volker (This used to be commit 6585ea2cb7f417e14540495b9c7380fe9c8c717b) --- source3/smbd/process.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 99898141db..8b3e85f4b4 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1125,7 +1125,7 @@ static void construct_reply(char *inbuf, int size) file_chain_reset(); reset_chain_p(); - if (!(req = talloc(tmp_talloc_ctx(), struct smb_request))) { + if (!(req = talloc(talloc_tos(), struct smb_request))) { smb_panic("could not allocate smb_request"); } init_smb_request(req, (uint8 *)inbuf); @@ -1346,7 +1346,7 @@ void chain_reply(struct smb_request *req) DEBUG(3,("Chained message\n")); show_msg(inbuf2); - if (!(req2 = talloc(tmp_talloc_ctx(), struct smb_request))) { + if (!(req2 = talloc(talloc_tos(), struct smb_request))) { smb_panic("could not allocate smb_request"); } init_smb_request(req2, (uint8 *)inbuf2); @@ -1634,13 +1634,10 @@ void smbd_process(void) int num_echos; char *inbuf; size_t inbuf_len; + TALLOC_CTX *frame = talloc_stackframe(); errno = 0; - /* free up temporary memory */ - lp_TALLOC_FREE(); - main_loop_TALLOC_FREE(); - /* Did someone ask for immediate checks on things like blocking locks ? */ if (select_timeout == 0) { if(!timeout_processing(&select_timeout, @@ -1713,5 +1710,6 @@ void smbd_process(void) change_to_root_user(); check_log_size(); } + TALLOC_FREE(frame); } } -- cgit From 12f61e09d943ea7fc4149166077507b5b0b3b4e7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 12 Sep 2007 21:48:20 +0000 Subject: r25117: The mega-patch Jerry was waiting for. Remove all pstrings from the main server code paths. We should now be able to cope with paths up to PATH_MAX length now. Final job will be to add the TALLOC_CTX * parameter to unix_convert to make it explicit (for Volker). Jeremy. (This used to be commit 7f0db75fb0f24873577dcb758a2ecee74fdc4297) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 8b3e85f4b4..29b942de81 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1227,7 +1227,7 @@ void remove_from_common_flags2(uint32 v) void construct_reply_common(const char *inbuf, char *outbuf) { set_message(inbuf,outbuf,0,0,False); - + SCVAL(outbuf,smb_com,CVAL(inbuf,smb_com)); SIVAL(outbuf,smb_rcls,0); SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); -- cgit From e5a951325a6cac8567af3a66de6d2df577508ae4 Mon Sep 17 00:00:00 2001 From: "Gerald (Jerry) Carter" Date: Wed, 10 Oct 2007 15:34:30 -0500 Subject: [GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch. (This used to be commit 5c6c8e1fe93f340005110a7833946191659d88ab) --- source3/smbd/process.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 29b942de81..7faf26af25 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -91,8 +91,8 @@ void init_smb_request(struct smb_request *req, const uint8 *inbuf) static struct pending_message_list *deferred_open_queue; /**************************************************************************** - Function to push a message onto the tail of a linked list of smb messages - ready for processing. + Function to push a message onto the tail of a linked list of smb messages ready + for processing. ****************************************************************************/ static BOOL push_queued_message(struct smb_request *req, @@ -148,7 +148,7 @@ void remove_deferred_open_smb_message(uint16 mid) for (pml = deferred_open_queue; pml; pml = pml->next) { if (mid == SVAL(pml->buf.data,smb_mid)) { - DEBUG(10,("remove_deferred_open_smb_message: " + DEBUG(10,("remove_sharing_violation_open_smb_message: " "deleting mid %u len %u\n", (unsigned int)mid, (unsigned int)pml->buf.length )); @@ -171,11 +171,11 @@ void schedule_deferred_open_smb_message(uint16 mid) for (pml = deferred_open_queue; pml; pml = pml->next) { uint16 msg_mid = SVAL(pml->buf.data,smb_mid); - DEBUG(10, ("schedule_deferred_open_smb_message: [%d] " - "msg_mid = %u\n", i++, (unsigned int)msg_mid )); + DEBUG(10,("schedule_deferred_open_smb_message: [%d] msg_mid = %u\n", i++, + (unsigned int)msg_mid )); if (mid == msg_mid) { - DEBUG(10, ("schedule_deferred_open_smb_message: " - "scheduling mid %u\n", mid)); + DEBUG(10,("schedule_deferred_open_smb_message: scheduling mid %u\n", + mid )); pml->end_time.tv_sec = 0; pml->end_time.tv_usec = 0; DLIST_PROMOTE(deferred_open_queue, pml); @@ -183,8 +183,8 @@ void schedule_deferred_open_smb_message(uint16 mid) } } - DEBUG(10, ("schedule_deferred_open_smb_message: failed to find " - "message mid %u\n", mid )); + DEBUG(10,("schedule_deferred_open_smb_message: failed to find message mid %u\n", + mid )); } /**************************************************************************** @@ -932,8 +932,7 @@ void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes) } construct_reply_common((char *)req->inbuf, (char *)req->outbuf); - set_message((char *)req->inbuf, (char *)req->outbuf, - num_words, num_bytes, False); + set_message((char *)req->outbuf, num_words, num_bytes, False); /* * Zero out the word area, the caller has to take care of the bcc area * himself @@ -1226,8 +1225,8 @@ void remove_from_common_flags2(uint32 v) void construct_reply_common(const char *inbuf, char *outbuf) { - set_message(inbuf,outbuf,0,0,False); - + set_message(outbuf,0,0,False); + SCVAL(outbuf,smb_com,CVAL(inbuf,smb_com)); SIVAL(outbuf,smb_rcls,0); SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); @@ -1341,7 +1340,7 @@ void chain_reply(struct smb_request *req) } /* And set it in the header. */ - smb_setlen(inbuf, inbuf2, new_size - 4); + smb_setlen(inbuf2, new_size - 4); DEBUG(3,("Chained message\n")); show_msg(inbuf2); @@ -1428,7 +1427,7 @@ void chain_reply(struct smb_request *req) memset(outbuf + outsize, 0, outsize_padded - outsize); } - smb_setlen(NULL, outbuf, outsize2 + chain_size - 4); + smb_setlen(outbuf, outsize2 + chain_size - 4); /* * restore the saved data, being careful not to overwrite any data -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/smbd/process.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 7faf26af25..ed1bf762e9 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -41,7 +41,7 @@ extern int last_message; extern int smb_read_error; SIG_ATOMIC_T reload_after_sighup = 0; SIG_ATOMIC_T got_sig_term = 0; -extern BOOL global_machine_password_needs_changing; +extern bool global_machine_password_needs_changing; extern int max_send; /* @@ -95,7 +95,7 @@ static struct pending_message_list *deferred_open_queue; for processing. ****************************************************************************/ -static BOOL push_queued_message(struct smb_request *req, +static bool push_queued_message(struct smb_request *req, struct timeval request_time, struct timeval end_time, char *private_data, size_t private_len) @@ -191,7 +191,7 @@ void schedule_deferred_open_smb_message(uint16 mid) Return true if this mid is on the deferred queue. ****************************************************************************/ -BOOL open_was_deferred(uint16 mid) +bool open_was_deferred(uint16 mid) { struct pending_message_list *pml; @@ -224,7 +224,7 @@ struct pending_message_list *get_open_deferred_message(uint16 mid) messages ready for processing. ****************************************************************************/ -BOOL push_deferred_smb_message(struct smb_request *req, +bool push_deferred_smb_message(struct smb_request *req, struct timeval request_time, struct timeval timeout, char *private_data, size_t priv_len) @@ -247,7 +247,7 @@ struct idle_event { struct timed_event *te; struct timeval interval; char *name; - BOOL (*handler)(const struct timeval *now, void *private_data); + bool (*handler)(const struct timeval *now, void *private_data); void *private_data; }; @@ -280,7 +280,7 @@ struct idle_event *event_add_idle(struct event_context *event_ctx, TALLOC_CTX *mem_ctx, struct timeval interval, const char *name, - BOOL (*handler)(const struct timeval *now, + bool (*handler)(const struct timeval *now, void *private_data), void *private_data) { @@ -382,7 +382,7 @@ static int select_on_fd(int fd, int maxfd, fd_set *fds) The timeout is in milliseconds ****************************************************************************/ -static BOOL receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, +static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, size_t *buffer_len, int timeout) { fd_set r_fds, w_fds; @@ -415,7 +415,7 @@ static BOOL receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, * and it's time to schedule. */ if(deferred_open_queue != NULL) { - BOOL pop_message = False; + bool pop_message = False; struct pending_message_list *msg = deferred_open_queue; if (timeval_is_zero(&msg->end_time)) { @@ -1515,7 +1515,7 @@ void check_reload(time_t t) Process any timeout housekeeping. Return False if the caller should exit. ****************************************************************************/ -static BOOL timeout_processing(int *select_timeout, +static bool timeout_processing(int *select_timeout, time_t *last_timeout_processing_time) { time_t t; -- cgit From c3250149e12338fac5093991b385ad2807c92d1f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 30 Oct 2007 16:22:24 -0700 Subject: Add new parameter, "min receivefile size" (by default set to zero). If non-zero, writeX calls greater than this value will be left in the socket buffer for later handling with recvfile (or userspace equivalent). Definition of recvfile for your system is left as an exercise for the reader (I'm working on getting splice working :-). Jeremy. (This used to be commit 11c03b75ddbcb6e36b231bb40a1773d1c550621c) --- source3/smbd/process.c | 62 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 17 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ed1bf762e9..1c8d8a6e76 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -25,7 +25,7 @@ extern int smb_echo_count; const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); -/* +/* * Size of data we can send to client. Set * by the client for all protocols above CORE. * Set by us for CORE protocol. @@ -48,7 +48,9 @@ extern int max_send; * Initialize a struct smb_request from an inbuf */ -void init_smb_request(struct smb_request *req, const uint8 *inbuf) +void init_smb_request(struct smb_request *req, + const uint8 *inbuf, + size_t unread_bytes) { size_t req_size = smb_len(inbuf) + 4; /* Ensure we have at least smb_size bytes. */ @@ -63,6 +65,8 @@ void init_smb_request(struct smb_request *req, const uint8 *inbuf) req->vuid = SVAL(inbuf, smb_uid); req->tid = SVAL(inbuf, smb_tid); req->wct = CVAL(inbuf, smb_wct); + req->unread_bytes = unread_bytes; + /* Ensure we have at least wct words and 2 bytes of bcc. */ if (smb_size + req->wct*2 > req_size) { DEBUG(0,("init_smb_request: invalid wct number %u (size %u)\n", @@ -231,6 +235,14 @@ bool push_deferred_smb_message(struct smb_request *req, { struct timeval end_time; + if (req->unread_bytes) { + DEBUG(0,("push_deferred_smb_message: logic error ! " + "unread_bytes = %u\n", + (unsigned int)req->unread_bytes )); + smb_panic("push_deferred_smb_message: " + "logic error unread_bytes != 0" ); + } + end_time = timeval_sum(&request_time, &timeout); DEBUG(10,("push_deferred_open_smb_message: pushing message len %u mid %u " @@ -382,8 +394,11 @@ static int select_on_fd(int fd, int maxfd, fd_set *fds) The timeout is in milliseconds ****************************************************************************/ -static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, - size_t *buffer_len, int timeout) +static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, + char **buffer, + size_t *buffer_len, + int timeout, + size_t *p_unread) { fd_set r_fds, w_fds; int selrtn; @@ -391,6 +406,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, int maxfd = 0; ssize_t len; + *p_unread = 0; smb_read_error = 0; again: @@ -565,7 +581,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, goto again; } - len = receive_smb_talloc(mem_ctx, smbd_server_fd(), buffer, 0); + len = receive_smb_talloc(mem_ctx, smbd_server_fd(), buffer, 0, p_unread); if (len == -1) { return False; @@ -1115,7 +1131,7 @@ static void switch_message(uint8 type, struct smb_request *req, int size) Construct a reply to the incoming packet. ****************************************************************************/ -static void construct_reply(char *inbuf, int size) +static void construct_reply(char *inbuf, int size, size_t unread_bytes) { uint8 type = CVAL(inbuf,smb_com); struct smb_request *req; @@ -1127,10 +1143,19 @@ static void construct_reply(char *inbuf, int size) if (!(req = talloc(talloc_tos(), struct smb_request))) { smb_panic("could not allocate smb_request"); } - init_smb_request(req, (uint8 *)inbuf); + init_smb_request(req, (uint8 *)inbuf, unread_bytes); switch_message(type, req, size); + if (req->unread_bytes) { + /* writeX failed. drain socket. */ + if (drain_socket(smbd_server_fd(), req->unread_bytes) != + req->unread_bytes) { + smb_panic("failed to drain pending bytes"); + } + req->unread_bytes = 0; + } + if (req->outbuf == NULL) { return; } @@ -1152,7 +1177,7 @@ static void construct_reply(char *inbuf, int size) Process an smb from the client ****************************************************************************/ -static void process_smb(char *inbuf, size_t nread) +static void process_smb(char *inbuf, size_t nread, size_t unread_bytes) { static int trans_num; int msg_type = CVAL(inbuf,0); @@ -1176,7 +1201,9 @@ static void process_smb(char *inbuf, size_t nread) DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type, smb_len(inbuf) ) ); - DEBUG( 3, ( "Transaction %d of length %d\n", trans_num, (int)nread ) ); + DEBUG( 3, ( "Transaction %d of length %d (%u toread)\n", trans_num, + (int)nread, + (unsigned int)unread_bytes )); if (msg_type != 0) { /* @@ -1188,8 +1215,8 @@ static void process_smb(char *inbuf, size_t nread) show_msg(inbuf); - construct_reply(inbuf,nread); - + construct_reply(inbuf,nread,unread_bytes); + trans_num++; } @@ -1348,7 +1375,7 @@ void chain_reply(struct smb_request *req) if (!(req2 = talloc(talloc_tos(), struct smb_request))) { smb_panic("could not allocate smb_request"); } - init_smb_request(req2, (uint8 *)inbuf2); + init_smb_request(req2, (uint8 *)inbuf2,0); /* process the request */ switch_message(smb_com2, req2, new_size); @@ -1625,6 +1652,7 @@ void smbd_process(void) { time_t last_timeout_processing_time = time(NULL); unsigned int num_smbs = 0; + size_t unread_bytes = 0; max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); @@ -1635,8 +1663,8 @@ void smbd_process(void) size_t inbuf_len; TALLOC_CTX *frame = talloc_stackframe(); - errno = 0; - + errno = 0; + /* Did someone ask for immediate checks on things like blocking locks ? */ if (select_timeout == 0) { if(!timeout_processing(&select_timeout, @@ -1648,7 +1676,7 @@ void smbd_process(void) run_events(smbd_event_context(), 0, NULL, NULL); while (!receive_message_or_smb(NULL, &inbuf, &inbuf_len, - select_timeout)) { + select_timeout, &unread_bytes)) { if(!timeout_processing(&select_timeout, &last_timeout_processing_time)) return; @@ -1664,10 +1692,10 @@ void smbd_process(void) * faster than the select timeout, thus starving out the * essential processing (change notify, blocking locks) that * the timeout code does. JRA. - */ + */ num_echos = smb_echo_count; - process_smb(inbuf, inbuf_len); + process_smb(inbuf, inbuf_len, unread_bytes); TALLOC_FREE(inbuf); -- cgit From 695c4a7a741f1a8a00a4dc867cc3ef731bfc093f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 31 Oct 2007 14:24:52 -0700 Subject: Fix vfstest link - move socket calls into smbd/process.c not smbd/server.c Jeremy (This used to be commit 8fbefe18a2dc23adb0ebe488cfb37ab4a382207d) --- source3/smbd/process.c | 288 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 288 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1c8d8a6e76..eca51a74a3 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -22,6 +22,7 @@ extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; +extern int smb_read_error; const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); @@ -44,6 +45,293 @@ SIG_ATOMIC_T got_sig_term = 0; extern bool global_machine_password_needs_changing; extern int max_send; +/* Socket functions for smbd packet processing. */ + +static bool valid_packet_size(len) +{ + /* + * A WRITEX with CAP_LARGE_WRITEX can be 64k worth of data plus 65 bytes + * of header. Don't print the error if this fits.... JRA. + */ + + if (len > (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE)) { + DEBUG(0,("Invalid packet length! (%lu bytes).\n", + (unsigned long)len)); + if (len > BUFFER_SIZE + (SAFETY_MARGIN/2)) { + + /* + * Correct fix. smb_read_error may have already been + * set. Only set it here if not already set. Global + * variables still suck :-). JRA. + */ + + if (smb_read_error == 0) + smb_read_error = READ_ERROR; + return false; + } + } + return true; +} + +static ssize_t read_packet_remainder(int fd, + char *buffer, + unsigned int timeout, + ssize_t len) +{ + ssize_t ret; + + if(len <= 0) { + return len; + } + + if (timeout > 0) { + ret = read_socket_with_timeout(fd, + buffer, + len, + len, + timeout); + } else { + ret = read_data(fd, buffer, len); + } + + if (ret != len) { + if (smb_read_error == 0) { + smb_read_error = READ_ERROR; + } + return -1; + } + + return len; +} + +/**************************************************************************** + Attempt a zerocopy writeX read. We know here that len > smb_size-4 +****************************************************************************/ + +/* + * Unfortunately, earlier versions of smbclient/libsmbclient + * don't send this "standard" writeX header. I've fixed this + * for 3.2 but we'll use the old method with earlier versions. + * Windows and CIFSFS at least use this standard size. Not + * sure about MacOSX. + */ + +#define STANDARD_WRITE_AND_X_HEADER_SIZE (smb_size - 4 + /* basic header */ \ + (2*14) + /* word count (including bcc) */ \ + 1 /* pad byte */) + +ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, + const char lenbuf[4], + int fd, + char **buffer, + unsigned int timeout, + size_t *p_unread) +{ + /* Size of a WRITEX call (+4 byte len). */ + char writeX_header[4 + STANDARD_WRITE_AND_X_HEADER_SIZE]; + ssize_t len = smb_len_large(lenbuf); /* Could be a UNIX large writeX. */ + ssize_t toread; + ssize_t ret; + + memcpy(writeX_header, lenbuf, sizeof(lenbuf)); + + if (timeout > 0) { + ret = read_socket_with_timeout(fd, + writeX_header + 4, + STANDARD_WRITE_AND_X_HEADER_SIZE, + STANDARD_WRITE_AND_X_HEADER_SIZE, + timeout); + } else { + ret = read_data(fd, + writeX_header+4, + STANDARD_WRITE_AND_X_HEADER_SIZE); + } + + if (ret != STANDARD_WRITE_AND_X_HEADER_SIZE) { + if (smb_read_error == 0) { + smb_read_error = READ_ERROR; + } + return -1; + } + + /* + * Ok - now try and see if this is a possible + * valid writeX call. + */ + + if (is_valid_writeX_buffer(writeX_header)) { + /* + * If the data offset is beyond what + * we've read, drain the extra bytes. + */ + uint16_t doff = SVAL(writeX_header,smb_vwv11); + ssize_t newlen; + + if (doff > STANDARD_WRITE_AND_X_HEADER_SIZE) { + size_t drain = doff - STANDARD_WRITE_AND_X_HEADER_SIZE; + if (drain_socket(smbd_server_fd(), drain) != drain) { + smb_panic("receive_smb_raw_talloc_partial_read:" + " failed to drain pending bytes"); + } + } else { + doff = STANDARD_WRITE_AND_X_HEADER_SIZE; + } + + /* Spoof down the length and null out the bcc. */ + set_message_bcc(writeX_header, 0); + newlen = smb_len(writeX_header); + + /* Copy the header we've written. */ + + *buffer = TALLOC_MEMDUP(mem_ctx, + writeX_header, + sizeof(writeX_header)); + + if (*buffer == NULL) { + DEBUG(0, ("Could not allocate inbuf of length %d\n", + (int)sizeof(writeX_header))); + if (smb_read_error == 0) + smb_read_error = READ_ERROR; + return -1; + } + + /* Work out the remaining bytes. */ + *p_unread = len - STANDARD_WRITE_AND_X_HEADER_SIZE; + + return newlen + 4; + } + + if (!valid_packet_size(len)) { + return -1; + } + + /* + * Not a valid writeX call. Just do the standard + * talloc and return. + */ + + *buffer = TALLOC_ARRAY(mem_ctx, char, len+4); + + if (*buffer == NULL) { + DEBUG(0, ("Could not allocate inbuf of length %d\n", + (int)len+4)); + if (smb_read_error == 0) + smb_read_error = READ_ERROR; + return -1; + } + + /* Copy in what we already read. */ + memcpy(*buffer, + writeX_header, + 4 + STANDARD_WRITE_AND_X_HEADER_SIZE); + toread = len - STANDARD_WRITE_AND_X_HEADER_SIZE; + + if(toread > 0) { + ret = read_packet_remainder(fd, + (*buffer) + 4 + STANDARD_WRITE_AND_X_HEADER_SIZE, + timeout, + toread); + if (ret != toread) { + return -1; + } + } + + return len + 4; +} + +static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, + int fd, + char **buffer, + unsigned int timeout, + size_t *p_unread) +{ + char lenbuf[4]; + ssize_t len,ret; + int min_recv_size = lp_min_receive_file_size(); + + smb_read_error = 0; + *p_unread = 0; + + len = read_smb_length_return_keepalive(fd, lenbuf, timeout); + if (len < 0) { + DEBUG(10,("receive_smb_raw: length < 0!\n")); + + /* + * Correct fix. smb_read_error may have already been + * set. Only set it here if not already set. Global + * variables still suck :-). JRA. + */ + + if (smb_read_error == 0) + smb_read_error = READ_ERROR; + return -1; + } + + if (CVAL(lenbuf,0) != SMBkeepalive && + min_recv_size && + len > min_recv_size && + !srv_is_signing_active()) { + + return receive_smb_raw_talloc_partial_read(mem_ctx, + lenbuf, + fd, + buffer, + timeout, + p_unread); + } + + if (!valid_packet_size(len)) { + return -1; + } + + /* + * The +4 here can't wrap, we've checked the length above already. + */ + + *buffer = TALLOC_ARRAY(mem_ctx, char, len+4); + + if (*buffer == NULL) { + DEBUG(0, ("Could not allocate inbuf of length %d\n", + (int)len+4)); + if (smb_read_error == 0) + smb_read_error = READ_ERROR; + return -1; + } + + memcpy(*buffer, lenbuf, sizeof(lenbuf)); + + ret = read_packet_remainder(fd, (*buffer)+4, timeout, len); + if (ret != len) { + return -1; + } + + return len + 4; +} + +ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, char **buffer, + unsigned int timeout, size_t *p_unread) +{ + ssize_t len; + + len = receive_smb_raw_talloc(mem_ctx, fd, buffer, timeout, p_unread); + + if (len < 0) { + return -1; + } + + /* Check the incoming SMB signature. */ + if (!srv_check_sign_mac(*buffer, true)) { + DEBUG(0, ("receive_smb: SMB Signature verification failed on " + "incoming packet!\n")); + if (smb_read_error == 0) { + smb_read_error = READ_BAD_SIG; + } + return -1; + } + + return len; +} + /* * Initialize a struct smb_request from an inbuf */ -- cgit From 73d407968002587eadd0ff13eb413ddf07c78771 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Nov 2007 15:12:42 -0700 Subject: Remove the smb_read_error global variable and replace it with accessor functions. "One global or pstring a day...." :-). Jeremy. (This used to be commit d50d14c300abc83b7015718ec48acc8b3227a273) --- source3/smbd/process.c | 51 +++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index eca51a74a3..11fdb03d72 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -22,7 +22,6 @@ extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; -extern int smb_read_error; const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); @@ -39,7 +38,6 @@ int max_send = BUFFER_SIZE; int max_recv = BUFFER_SIZE; extern int last_message; -extern int smb_read_error; SIG_ATOMIC_T reload_after_sighup = 0; SIG_ATOMIC_T got_sig_term = 0; extern bool global_machine_password_needs_changing; @@ -65,8 +63,7 @@ static bool valid_packet_size(len) * variables still suck :-). JRA. */ - if (smb_read_error == 0) - smb_read_error = READ_ERROR; + cond_set_smb_read_error(SMB_READ_ERROR); return false; } } @@ -95,9 +92,7 @@ static ssize_t read_packet_remainder(int fd, } if (ret != len) { - if (smb_read_error == 0) { - smb_read_error = READ_ERROR; - } + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -148,9 +143,7 @@ ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, } if (ret != STANDARD_WRITE_AND_X_HEADER_SIZE) { - if (smb_read_error == 0) { - smb_read_error = READ_ERROR; - } + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -190,8 +183,7 @@ ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)sizeof(writeX_header))); - if (smb_read_error == 0) - smb_read_error = READ_ERROR; + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -215,8 +207,7 @@ ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)len+4)); - if (smb_read_error == 0) - smb_read_error = READ_ERROR; + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -249,7 +240,7 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, ssize_t len,ret; int min_recv_size = lp_min_receive_file_size(); - smb_read_error = 0; + set_smb_read_error(SMB_READ_OK); *p_unread = 0; len = read_smb_length_return_keepalive(fd, lenbuf, timeout); @@ -262,8 +253,7 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, * variables still suck :-). JRA. */ - if (smb_read_error == 0) - smb_read_error = READ_ERROR; + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -293,8 +283,7 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)len+4)); - if (smb_read_error == 0) - smb_read_error = READ_ERROR; + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -323,9 +312,7 @@ ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, char **buffer, if (!srv_check_sign_mac(*buffer, true)) { DEBUG(0, ("receive_smb: SMB Signature verification failed on " "incoming packet!\n")); - if (smb_read_error == 0) { - smb_read_error = READ_BAD_SIG; - } + cond_set_smb_read_error(SMB_READ_BAD_SIG); return -1; } @@ -695,7 +682,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, ssize_t len; *p_unread = 0; - smb_read_error = 0; + set_smb_read_error(SMB_READ_OK); again: @@ -749,7 +736,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, msg->buf.length); if (*buffer == NULL) { DEBUG(0, ("talloc failed\n")); - smb_read_error = READ_ERROR; + set_smb_read_error(SMB_READ_ERROR); return False; } *buffer_len = msg->buf.length; @@ -843,13 +830,13 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, /* Check if error */ if (selrtn == -1) { /* something is wrong. Maybe the socket is dead? */ - smb_read_error = READ_ERROR; + set_smb_read_error(SMB_READ_ERROR); return False; } /* Did we timeout ? */ if (selrtn == 0) { - smb_read_error = READ_TIMEOUT; + set_smb_read_error(SMB_READ_TIMEOUT); return False; } @@ -1835,20 +1822,20 @@ static bool timeout_processing(int *select_timeout, { time_t t; - if (smb_read_error == READ_EOF) { + if (get_smb_read_error() == SMB_READ_EOF) { DEBUG(3,("timeout_processing: End of file from client (client has disconnected).\n")); - return False; + return false; } - if (smb_read_error == READ_ERROR) { + if (get_smb_read_error() == SMB_READ_ERROR) { DEBUG(3,("timeout_processing: receive_smb error (%s) Exiting\n", strerror(errno))); - return False; + return false; } - if (smb_read_error == READ_BAD_SIG) { + if (get_smb_read_error() == SMB_READ_BAD_SIG) { DEBUG(3,("timeout_processing: receive_smb error bad smb signature. Exiting\n")); - return False; + return false; } *last_timeout_processing_time = t = time(NULL); -- cgit From 6658165d5e9cd186fea74e1581091233e8990e9b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Nov 2007 18:15:45 -0700 Subject: Stop get_peer_addr() and client_addr() from using global statics. Part of my library cleanups. Jeremy. (This used to be commit e848506c858bd16706c1d7f6b4b032005512b8ac) --- source3/smbd/process.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 11fdb03d72..f35e7054d7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1460,15 +1460,18 @@ static void process_smb(char *inbuf, size_t nread, size_t unread_bytes) DO_PROFILE_INC(smb_count); if (trans_num == 0) { + char addr[INET6_ADDRSTRLEN]; + /* on the first packet, check the global hosts allow/ hosts deny parameters before doing any parsing of the packet passed to us by the client. This prevents attacks on our parsing code from hosts not in the hosts allow list */ + if (!check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1))) { /* send a negative session response "not listening on calling name" */ static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; - DEBUG( 1, ( "Connection denied from %s\n", client_addr() ) ); + DEBUG( 1, ( "Connection denied from %s\n", client_addr(addr) ) ); (void)send_smb(smbd_server_fd(),(char *)buf); exit_server_cleanly("connection denied"); } -- cgit From 25074433f412c4dd2531fd268d51be8753ddc11b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Nov 2007 18:41:26 -0700 Subject: I can't get away without a 'length' arg. :-). Jeremy. (This used to be commit 95d01279a5def709d0a5d5ae7224d6286006d120) --- source3/smbd/process.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f35e7054d7..24feac4630 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1471,7 +1471,8 @@ static void process_smb(char *inbuf, size_t nread, size_t unread_bytes) lp_hostsdeny(-1))) { /* send a negative session response "not listening on calling name" */ static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; - DEBUG( 1, ( "Connection denied from %s\n", client_addr(addr) ) ); + DEBUG( 1, ( "Connection denied from %s\n", + client_addr(addr,sizeof(addr)) ) ); (void)send_smb(smbd_server_fd(),(char *)buf); exit_server_cleanly("connection denied"); } -- cgit From 5b0b4f23ef5fec3d1ad518237f973d4e014b5766 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Nov 2007 23:20:10 -0700 Subject: Remove most of the remaining globals out of lib/util_sock.c. I have a plan for dealing with the remaining..... Watch this space. Jeremy. (This used to be commit 963fc7685212689f02b3adcc05b4273ee5c382d4) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 24feac4630..aa39b01258 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1472,7 +1472,7 @@ static void process_smb(char *inbuf, size_t nread, size_t unread_bytes) /* send a negative session response "not listening on calling name" */ static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; DEBUG( 1, ( "Connection denied from %s\n", - client_addr(addr,sizeof(addr)) ) ); + client_addr(get_client_fd(),addr,sizeof(addr)) ) ); (void)send_smb(smbd_server_fd(),(char *)buf); exit_server_cleanly("connection denied"); } -- cgit From 4721050df5dd268fbb99199c17071c2b05c61e1f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 4 Nov 2007 15:38:43 -0800 Subject: Don't believe len returned from read_smb_length_return_keepalive(), it may be a UNIX large writeX (which wraps len in that case). Stevef this should fix your 128k write bug. Jeremy. (This used to be commit de2ebffa3c99ed28a3868fd956ef45629ca855b6) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index aa39b01258..659b7b55e9 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -259,7 +259,7 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, if (CVAL(lenbuf,0) != SMBkeepalive && min_recv_size && - len > min_recv_size && + smb_len_large(lenbuf) > min_recv_size && /* Could be a UNIX large writeX. */ !srv_is_signing_active()) { return receive_smb_raw_talloc_partial_read(mem_ctx, -- cgit From 58fbb512cc7a26471a2aae88425de4d337258e3a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 4 Nov 2007 17:15:35 -0800 Subject: Forgot arg type. Jeremy. (This used to be commit 46f3b04ddea4c63c6b37c7038d4bbd2ee1c9ca0c) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 659b7b55e9..7d6455621f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -45,7 +45,7 @@ extern int max_send; /* Socket functions for smbd packet processing. */ -static bool valid_packet_size(len) +static bool valid_packet_size(size_t len) { /* * A WRITEX with CAP_LARGE_WRITEX can be 64k worth of data plus 65 bytes -- cgit From 36441da4240f3e3a296eed65f0796b25b7b05a3a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 5 Nov 2007 11:12:56 -0800 Subject: Remove the horror that was the global smb_rw_error. Each cli struct has it's own local copy of this variable, so use that in client code. In the smbd server, add one static to smbd/proccess.c and use that inside smbd. Fix a bunch of places where smb_rw_error could be set by calling read_data() in places where we weren't reading from the SMB client socket (ie. winbindd). Jeremy. (This used to be commit 255c2adf7b6ef30932b5bb9f142ccef4a5d3d0db) --- source3/smbd/process.c | 59 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 21 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 7d6455621f..24497de69a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -24,6 +24,7 @@ extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); +static enum smb_read_errors smb_read_error = SMB_READ_OK; /* * Size of data we can send to client. Set @@ -43,6 +44,13 @@ SIG_ATOMIC_T got_sig_term = 0; extern bool global_machine_password_needs_changing; extern int max_send; +/* Accessor function for smb_read_error for smbd functions. */ + +enum smb_read_errors *get_srv_read_error(void) +{ + return &smb_read_error; +} + /* Socket functions for smbd packet processing. */ static bool valid_packet_size(size_t len) @@ -63,7 +71,8 @@ static bool valid_packet_size(size_t len) * variables still suck :-). JRA. */ - cond_set_smb_read_error(SMB_READ_ERROR); + cond_set_smb_read_error(get_srv_read_error(), + SMB_READ_ERROR); return false; } } @@ -86,13 +95,15 @@ static ssize_t read_packet_remainder(int fd, buffer, len, len, - timeout); + timeout, + get_srv_read_error()); } else { - ret = read_data(fd, buffer, len); + ret = read_data(fd, buffer, len, get_srv_read_error()); } if (ret != len) { - cond_set_smb_read_error(SMB_READ_ERROR); + cond_set_smb_read_error(get_srv_read_error(), + SMB_READ_ERROR); return -1; } @@ -135,15 +146,18 @@ ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, writeX_header + 4, STANDARD_WRITE_AND_X_HEADER_SIZE, STANDARD_WRITE_AND_X_HEADER_SIZE, - timeout); + timeout, + get_srv_read_error()); } else { ret = read_data(fd, writeX_header+4, - STANDARD_WRITE_AND_X_HEADER_SIZE); + STANDARD_WRITE_AND_X_HEADER_SIZE, + get_srv_read_error()); } if (ret != STANDARD_WRITE_AND_X_HEADER_SIZE) { - cond_set_smb_read_error(SMB_READ_ERROR); + cond_set_smb_read_error(get_srv_read_error(), + SMB_READ_ERROR); return -1; } @@ -183,7 +197,8 @@ ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)sizeof(writeX_header))); - cond_set_smb_read_error(SMB_READ_ERROR); + cond_set_smb_read_error(get_srv_read_error(), + SMB_READ_ERROR); return -1; } @@ -207,7 +222,8 @@ ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)len+4)); - cond_set_smb_read_error(SMB_READ_ERROR); + cond_set_smb_read_error(get_srv_read_error(), + SMB_READ_ERROR); return -1; } @@ -240,10 +256,11 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, ssize_t len,ret; int min_recv_size = lp_min_receive_file_size(); - set_smb_read_error(SMB_READ_OK); + set_smb_read_error(get_srv_read_error(),SMB_READ_OK); *p_unread = 0; - len = read_smb_length_return_keepalive(fd, lenbuf, timeout); + len = read_smb_length_return_keepalive(fd, lenbuf, + timeout, get_srv_read_error()); if (len < 0) { DEBUG(10,("receive_smb_raw: length < 0!\n")); @@ -253,7 +270,7 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, * variables still suck :-). JRA. */ - cond_set_smb_read_error(SMB_READ_ERROR); + cond_set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); return -1; } @@ -283,7 +300,7 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)len+4)); - cond_set_smb_read_error(SMB_READ_ERROR); + cond_set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); return -1; } @@ -312,7 +329,7 @@ ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, char **buffer, if (!srv_check_sign_mac(*buffer, true)) { DEBUG(0, ("receive_smb: SMB Signature verification failed on " "incoming packet!\n")); - cond_set_smb_read_error(SMB_READ_BAD_SIG); + cond_set_smb_read_error(get_srv_read_error(),SMB_READ_BAD_SIG); return -1; } @@ -682,7 +699,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, ssize_t len; *p_unread = 0; - set_smb_read_error(SMB_READ_OK); + set_smb_read_error(get_srv_read_error(),SMB_READ_OK); again: @@ -736,7 +753,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, msg->buf.length); if (*buffer == NULL) { DEBUG(0, ("talloc failed\n")); - set_smb_read_error(SMB_READ_ERROR); + set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); return False; } *buffer_len = msg->buf.length; @@ -830,13 +847,13 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, /* Check if error */ if (selrtn == -1) { /* something is wrong. Maybe the socket is dead? */ - set_smb_read_error(SMB_READ_ERROR); + set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); return False; } /* Did we timeout ? */ if (selrtn == 0) { - set_smb_read_error(SMB_READ_TIMEOUT); + set_smb_read_error(get_srv_read_error(),SMB_READ_TIMEOUT); return False; } @@ -1826,18 +1843,18 @@ static bool timeout_processing(int *select_timeout, { time_t t; - if (get_smb_read_error() == SMB_READ_EOF) { + if (*get_srv_read_error() == SMB_READ_EOF) { DEBUG(3,("timeout_processing: End of file from client (client has disconnected).\n")); return false; } - if (get_smb_read_error() == SMB_READ_ERROR) { + if (*get_srv_read_error() == SMB_READ_ERROR) { DEBUG(3,("timeout_processing: receive_smb error (%s) Exiting\n", strerror(errno))); return false; } - if (get_smb_read_error() == SMB_READ_BAD_SIG) { + if (*get_srv_read_error() == SMB_READ_BAD_SIG) { DEBUG(3,("timeout_processing: receive_smb error bad smb signature. Exiting\n")); return false; } -- cgit From 637f9d9bf0947600e612057ddcd9caf137b9698e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 9 Nov 2007 14:23:16 +0100 Subject: Fix some warnings (This used to be commit 0a1f524e8cce9bbe4fd10467c1f64f7a8862d298) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 24497de69a..5601a7fb6e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -190,7 +190,7 @@ ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, /* Copy the header we've written. */ - *buffer = TALLOC_MEMDUP(mem_ctx, + *buffer = (char *)TALLOC_MEMDUP(mem_ctx, writeX_header, sizeof(writeX_header)); -- cgit From d068bc64b6f16bc0b4a8170b56f6aadd487d7203 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 11 Nov 2007 21:46:52 -0800 Subject: Three more pstring removals. Jeremy. (This used to be commit c15819b75751a1e15cfed2ef94dae10ee72d769c) --- source3/smbd/process.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 5601a7fb6e..ffc9e106f6 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1260,13 +1260,18 @@ void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes) static void smb_dump(const char *name, int type, const char *data, ssize_t len) { int fd, i; - pstring fname; - if (DEBUGLEVEL < 50) return; + char *fname = NULL; + if (DEBUGLEVEL < 50) { + return; + } if (len < 4) len = smb_len(data)+4; for (i=1;i<100;i++) { - slprintf(fname,sizeof(fname)-1, "/tmp/%s.%d.%s", name, i, + asprintf(&fname, "/tmp/%s.%d.%s", name, i, type ? "req" : "resp"); + if (!fname) { + return; + } fd = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0644); if (fd != -1 || errno != EEXIST) break; } @@ -1277,6 +1282,7 @@ static void smb_dump(const char *name, int type, const char *data, ssize_t len) close(fd); DEBUG(0,("created %s len %lu\n", fname, (unsigned long)len)); } + SAFE_FREE(fname); } /**************************************************************************** -- cgit From a34c6cd0e7046c1127b05bf3b5d5819f1d500cbc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 18 Dec 2007 18:10:09 -0800 Subject: Remove last_message completely as it's no longer used. Jeremy. (This used to be commit c378c3edc1197d46c5d6eb2bcabbf9e774c03ffc) --- source3/smbd/process.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ffc9e106f6..ee76f90bf5 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -38,7 +38,6 @@ int max_send = BUFFER_SIZE; */ int max_recv = BUFFER_SIZE; -extern int last_message; SIG_ATOMIC_T reload_after_sighup = 0; SIG_ATOMIC_T got_sig_term = 0; extern bool global_machine_password_needs_changing; @@ -1308,8 +1307,6 @@ static void switch_message(uint8 type, struct smb_request *req, int size) errno = 0; - last_message = type; - /* Make sure this is an SMB packet. smb_size contains NetBIOS header * so subtract 4 from it. */ if ((strncmp(smb_base(req->inbuf),"\377SMB",4) != 0) -- cgit From afc93255d183eefb68e45b8ec6275f6a62cf9795 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 26 Dec 2007 17:12:36 -0800 Subject: Add SMB encryption. Still fixing client decrypt but negotiation works. Jeremy. (This used to be commit d78045601af787731f0737b8627450018902b104) --- source3/smbd/process.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ee76f90bf5..1260d52c77 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -50,6 +50,43 @@ enum smb_read_errors *get_srv_read_error(void) return &smb_read_error; } +/******************************************************************* + Setup the word count and byte count for a smb message. + copying the '0xFF X X X' bytes from incoming + buffer (so we copy any encryption context). +********************************************************************/ + +int srv_set_message(const char *frombuf, + char *buf, + int num_words, + int num_bytes, + bool zero) +{ + if (zero && (num_words || num_bytes)) { + memset(buf + smb_size,'\0',num_words*2 + num_bytes); + } + SCVAL(buf,smb_wct,num_words); + SSVAL(buf,smb_vwv + num_words*SIZEOFWORD,num_bytes); + _smb_setlen(buf,(smb_size + num_words*2 + num_bytes - 4)); + if (buf != frombuf) { + memcpy(buf+4, frombuf+4, 4); + } + return (smb_size + num_words*2 + num_bytes); +} + +static bool valid_smb_header(const char *inbuf) +{ + if (srv_encryption_on()) { + uint16_t enc_num; + NTSTATUS status = get_enc_ctx_num(inbuf, &enc_num); + if (!NT_STATUS_IS_OK(status)) { + return false; + } + return (enc_num == 0); + } + return (strncmp(smb_base(inbuf),"\377SMB",4) == 0); +} + /* Socket functions for smbd packet processing. */ static bool valid_packet_size(size_t len) @@ -324,6 +361,18 @@ ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, char **buffer, return -1; } + if (srv_encryption_on()) { + NTSTATUS status = srv_decrypt_buffer(*buffer); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("receive_smb_talloc: SMB decryption failed on " + "incoming packet! Error %s\n", + nt_errstr(status) )); + cond_set_smb_read_error(get_srv_read_error(), + SMB_READ_BAD_DECRYPT); + return -1; + } + } + /* Check the incoming SMB signature. */ if (!srv_check_sign_mac(*buffer, true)) { DEBUG(0, ("receive_smb: SMB Signature verification failed on " @@ -1239,7 +1288,8 @@ void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes) } construct_reply_common((char *)req->inbuf, (char *)req->outbuf); - set_message((char *)req->outbuf, num_words, num_bytes, False); + srv_set_message((const char *)req->inbuf, + (char *)req->outbuf, num_words, num_bytes, false); /* * Zero out the word area, the caller has to take care of the bcc area * himself @@ -1309,7 +1359,7 @@ static void switch_message(uint8 type, struct smb_request *req, int size) /* Make sure this is an SMB packet. smb_size contains NetBIOS header * so subtract 4 from it. */ - if ((strncmp(smb_base(req->inbuf),"\377SMB",4) != 0) + if (!valid_smb_header((const char *)req->inbuf) || (size < (smb_size - 4))) { DEBUG(2,("Non-SMB packet of length %d. Terminating server\n", smb_len(req->inbuf))); @@ -1551,7 +1601,7 @@ void remove_from_common_flags2(uint32 v) void construct_reply_common(const char *inbuf, char *outbuf) { - set_message(outbuf,0,0,False); + srv_set_message(inbuf,outbuf,0,0,false); SCVAL(outbuf,smb_com,CVAL(inbuf,smb_com)); SIVAL(outbuf,smb_rcls,0); -- cgit From afce2b245a8ff137a4ecea547c3cfb65ab58dc15 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 Dec 2007 23:51:03 -0800 Subject: Add the capability to set "smb encrypt = required" on a share (or global) and have the server reply with ACCESS_DENIED for all non-encrypted traffic (except that used to query encryption requirements and set encryption state). Jeremy. (This used to be commit d241bfa57729bb934ada6beabf842a2ca7b4f8a2) --- source3/smbd/process.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 1260d52c77..48a6d18bc9 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1457,6 +1457,16 @@ static void switch_message(uint8 type, struct smb_request *req, int size) reply_doserror(req, ERRSRV, ERRaccess); return; } + + if (conn->encrypt_level == Required && SVAL(req->inbuf,4) != 0x45FF ) { + /* An encrypted packet has 0xFF 'E' at offset 4 + * which is little endian 0x45FF */ + uint8 com = CVAL(req->inbuf,smb_com); + if (com != SMBtrans2 && com != SMBtranss2) { + reply_nterror(req, NT_STATUS_ACCESS_DENIED); + return; + } + } conn->num_smb_operations++; } -- cgit From 9254bb4ef1c3c3a52ea8e935edb0e7a86ec3ea7a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 4 Jan 2008 12:56:23 -0800 Subject: Refactor the crypto code after a very helpful conversation with Volker. Mostly making sure we have data on the incoming packet type, not stored in the smb header. Jeremy. (This used to be commit c4e5a505043965eec77b5bb9bc60957e8f3b97c8) --- source3/smbd/process.c | 173 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 113 insertions(+), 60 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 48a6d18bc9..32d1d058e3 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -50,14 +50,52 @@ enum smb_read_errors *get_srv_read_error(void) return &smb_read_error; } +/**************************************************************************** + Send an smb to a fd. +****************************************************************************/ + +bool srv_send_smb(int fd, char *buffer, bool do_encrypt) +{ + size_t len; + size_t nwritten=0; + ssize_t ret; + char *buf_out = buffer; + + /* Sign the outgoing packet if required. */ + srv_calculate_sign_mac(buf_out); + + if (do_encrypt) { + NTSTATUS status = srv_encrypt_buffer(buffer, &buf_out); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("send_smb: SMB encryption failed " + "on outgoing packet! Error %s\n", + nt_errstr(status) )); + return false; + } + } + + len = smb_len(buf_out) + 4; + + while (nwritten < len) { + ret = write_data(fd,buf_out+nwritten,len - nwritten); + if (ret <= 0) { + DEBUG(0,("Error writing %d bytes to client. %d. (%s)\n", + (int)len,(int)ret, strerror(errno) )); + srv_free_enc_buffer(buf_out); + return false; + } + nwritten += ret; + } + + srv_free_enc_buffer(buf_out); + return true; +} + /******************************************************************* Setup the word count and byte count for a smb message. - copying the '0xFF X X X' bytes from incoming - buffer (so we copy any encryption context). ********************************************************************/ -int srv_set_message(const char *frombuf, - char *buf, +int srv_set_message(char *buf, int num_words, int num_bytes, bool zero) @@ -67,22 +105,14 @@ int srv_set_message(const char *frombuf, } SCVAL(buf,smb_wct,num_words); SSVAL(buf,smb_vwv + num_words*SIZEOFWORD,num_bytes); - _smb_setlen(buf,(smb_size + num_words*2 + num_bytes - 4)); - if (buf != frombuf) { - memcpy(buf+4, frombuf+4, 4); - } + smb_setlen(buf,(smb_size + num_words*2 + num_bytes - 4)); return (smb_size + num_words*2 + num_bytes); } -static bool valid_smb_header(const char *inbuf) +static bool valid_smb_header(const uint8_t *inbuf) { - if (srv_encryption_on()) { - uint16_t enc_num; - NTSTATUS status = get_enc_ctx_num(inbuf, &enc_num); - if (!NT_STATUS_IS_OK(status)) { - return false; - } - return (enc_num == 0); + if (is_encrypted_packet(inbuf)) { + return true; } return (strncmp(smb_base(inbuf),"\377SMB",4) == 0); } @@ -162,7 +192,7 @@ static ssize_t read_packet_remainder(int fd, (2*14) + /* word count (including bcc) */ \ 1 /* pad byte */) -ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, +static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, const char lenbuf[4], int fd, char **buffer, @@ -202,7 +232,7 @@ ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, * valid writeX call. */ - if (is_valid_writeX_buffer(writeX_header)) { + if (is_valid_writeX_buffer((uint8_t *)writeX_header)) { /* * If the data offset is beyond what * we've read, drain the extra bytes. @@ -310,7 +340,7 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, return -1; } - if (CVAL(lenbuf,0) != SMBkeepalive && + if (CVAL(lenbuf,0) == 0 && min_recv_size && smb_len_large(lenbuf) > min_recv_size && /* Could be a UNIX large writeX. */ !srv_is_signing_active()) { @@ -350,18 +380,24 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, return len + 4; } -ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, char **buffer, - unsigned int timeout, size_t *p_unread) +static ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, + int fd, + char **buffer, + unsigned int timeout, + size_t *p_unread, + bool *p_encrypted) { ssize_t len; + *p_encrypted = false; + len = receive_smb_raw_talloc(mem_ctx, fd, buffer, timeout, p_unread); if (len < 0) { return -1; } - if (srv_encryption_on()) { + if (is_encrypted_packet((uint8_t *)*buffer)) { NTSTATUS status = srv_decrypt_buffer(*buffer); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("receive_smb_talloc: SMB decryption failed on " @@ -371,6 +407,7 @@ ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, char **buffer, SMB_READ_BAD_DECRYPT); return -1; } + *p_encrypted = true; } /* Check the incoming SMB signature. */ @@ -390,7 +427,8 @@ ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, char **buffer, void init_smb_request(struct smb_request *req, const uint8 *inbuf, - size_t unread_bytes) + size_t unread_bytes, + bool encrypted) { size_t req_size = smb_len(inbuf) + 4; /* Ensure we have at least smb_size bytes. */ @@ -406,6 +444,8 @@ void init_smb_request(struct smb_request *req, req->tid = SVAL(inbuf, smb_tid); req->wct = CVAL(inbuf, smb_wct); req->unread_bytes = unread_bytes; + req->encrypted = encrypted; + req->conn = conn_find(req->tid); /* Ensure we have at least wct words and 2 bytes of bcc. */ if (smb_size + req->wct*2 > req_size) { @@ -463,6 +503,7 @@ static bool push_queued_message(struct smb_request *req, msg->request_time = request_time; msg->end_time = end_time; + msg->encrypted = req->encrypted; if (private_data) { msg->private_data = data_blob_talloc(msg, private_data, @@ -738,7 +779,8 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, size_t *buffer_len, int timeout, - size_t *p_unread) + size_t *p_unread, + bool *p_encrypted) { fd_set r_fds, w_fds; int selrtn; @@ -805,6 +847,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, return False; } *buffer_len = msg->buf.length; + *p_encrypted = msg->encrypted; /* We leave this message on the queue so the open code can know this is a retry. */ @@ -921,7 +964,8 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, goto again; } - len = receive_smb_talloc(mem_ctx, smbd_server_fd(), buffer, 0, p_unread); + len = receive_smb_talloc(mem_ctx, smbd_server_fd(), + buffer, 0, p_unread, p_encrypted); if (len == -1) { return False; @@ -1288,8 +1332,7 @@ void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes) } construct_reply_common((char *)req->inbuf, (char *)req->outbuf); - srv_set_message((const char *)req->inbuf, - (char *)req->outbuf, num_words, num_bytes, false); + srv_set_message((char *)req->outbuf, num_words, num_bytes, false); /* * Zero out the word area, the caller has to take care of the bcc area * himself @@ -1347,11 +1390,11 @@ static void smb_dump(const char *name, int type, const char *data, ssize_t len) find. ****************************************************************************/ -static void switch_message(uint8 type, struct smb_request *req, int size) +static connection_struct *switch_message(uint8 type, struct smb_request *req, int size) { int flags; uint16 session_tag; - connection_struct *conn; + connection_struct *conn = NULL; static uint16 last_session_tag = UID_FIELD_INVALID; @@ -1359,7 +1402,7 @@ static void switch_message(uint8 type, struct smb_request *req, int size) /* Make sure this is an SMB packet. smb_size contains NetBIOS header * so subtract 4 from it. */ - if (!valid_smb_header((const char *)req->inbuf) + if (!valid_smb_header(req->inbuf) || (size < (smb_size - 4))) { DEBUG(2,("Non-SMB packet of length %d. Terminating server\n", smb_len(req->inbuf))); @@ -1370,7 +1413,7 @@ static void switch_message(uint8 type, struct smb_request *req, int size) DEBUG(0,("Unknown message type %d!\n",type)); smb_dump("Unknown", 1, (char *)req->inbuf, size); reply_unknown_new(req, type); - return; + return NULL; } flags = smb_messages[type].flags; @@ -1378,7 +1421,7 @@ static void switch_message(uint8 type, struct smb_request *req, int size) /* In share mode security we must ignore the vuid. */ session_tag = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : req->vuid; - conn = conn_find(req->tid); + conn = req->conn; DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n", smb_fn_name(type), (int)sys_getpid(), (unsigned long)conn)); @@ -1423,12 +1466,12 @@ static void switch_message(uint8 type, struct smb_request *req, int size) } else { reply_doserror(req, ERRSRV, ERRinvnid); } - return; + return NULL; } if (!change_to_user(conn,session_tag)) { reply_nterror(req, NT_STATUS_DOS(ERRSRV, ERRbaduid)); - return; + return conn; } /* All NEED_WRITE and CAN_IPC flags must also have AS_USER. */ @@ -1436,13 +1479,13 @@ static void switch_message(uint8 type, struct smb_request *req, int size) /* Does it need write permission? */ if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) { reply_nterror(req, NT_STATUS_MEDIA_WRITE_PROTECTED); - return; + return conn; } /* IPC services are limited */ if (IS_IPC(conn) && !(flags & CAN_IPC)) { reply_doserror(req, ERRSRV,ERRaccess); - return; + return conn; } } else { /* This call needs to be run as root */ @@ -1451,21 +1494,24 @@ static void switch_message(uint8 type, struct smb_request *req, int size) /* load service specific parameters */ if (conn) { + if (req->encrypted) { + conn->encrypted_tid = true; + /* encrypted required from now on. */ + conn->encrypt_level = Required; + } else if (ENCRYPTION_REQUIRED(conn)) { + uint8 com = CVAL(req->inbuf,smb_com); + if (com != SMBtrans2 && com != SMBtranss2) { + exit_server_cleanly("encryption required " + "on connection"); + return conn; + } + } + if (!set_current_service(conn,SVAL(req->inbuf,smb_flg), (flags & (AS_USER|DO_CHDIR) ?True:False))) { reply_doserror(req, ERRSRV, ERRaccess); - return; - } - - if (conn->encrypt_level == Required && SVAL(req->inbuf,4) != 0x45FF ) { - /* An encrypted packet has 0xFF 'E' at offset 4 - * which is little endian 0x45FF */ - uint8 com = CVAL(req->inbuf,smb_com); - if (com != SMBtrans2 && com != SMBtranss2) { - reply_nterror(req, NT_STATUS_ACCESS_DENIED); - return; - } + return conn; } conn->num_smb_operations++; } @@ -1476,19 +1522,21 @@ static void switch_message(uint8 type, struct smb_request *req, int size) !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) { reply_doserror(req, ERRSRV, ERRaccess); - return; + return conn; } smb_messages[type].fn_new(conn, req); + return req->conn; } /**************************************************************************** Construct a reply to the incoming packet. ****************************************************************************/ -static void construct_reply(char *inbuf, int size, size_t unread_bytes) +static void construct_reply(char *inbuf, int size, size_t unread_bytes, bool encrypted) { uint8 type = CVAL(inbuf,smb_com); + connection_struct *conn; struct smb_request *req; chain_size = 0; @@ -1498,9 +1546,9 @@ static void construct_reply(char *inbuf, int size, size_t unread_bytes) if (!(req = talloc(talloc_tos(), struct smb_request))) { smb_panic("could not allocate smb_request"); } - init_smb_request(req, (uint8 *)inbuf, unread_bytes); + init_smb_request(req, (uint8 *)inbuf, unread_bytes, encrypted); - switch_message(type, req, size); + conn = switch_message(type, req, size); if (req->unread_bytes) { /* writeX failed. drain socket. */ @@ -1519,8 +1567,10 @@ static void construct_reply(char *inbuf, int size, size_t unread_bytes) show_msg((char *)req->outbuf); } - if (!send_smb(smbd_server_fd(), (char *)req->outbuf)) { - exit_server_cleanly("construct_reply: send_smb failed."); + if (!srv_send_smb(smbd_server_fd(), + (char *)req->outbuf, + IS_CONN_ENCRYPTED(conn)||req->encrypted)) { + exit_server_cleanly("construct_reply: srv_send_smb failed."); } TALLOC_FREE(req); @@ -1532,7 +1582,7 @@ static void construct_reply(char *inbuf, int size, size_t unread_bytes) Process an smb from the client ****************************************************************************/ -static void process_smb(char *inbuf, size_t nread, size_t unread_bytes) +static void process_smb(char *inbuf, size_t nread, size_t unread_bytes, bool encrypted) { static int trans_num; int msg_type = CVAL(inbuf,0); @@ -1553,7 +1603,7 @@ static void process_smb(char *inbuf, size_t nread, size_t unread_bytes) static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; DEBUG( 1, ( "Connection denied from %s\n", client_addr(get_client_fd(),addr,sizeof(addr)) ) ); - (void)send_smb(smbd_server_fd(),(char *)buf); + (void)srv_send_smb(smbd_server_fd(),(char *)buf,false); exit_server_cleanly("connection denied"); } } @@ -1574,7 +1624,7 @@ static void process_smb(char *inbuf, size_t nread, size_t unread_bytes) show_msg(inbuf); - construct_reply(inbuf,nread,unread_bytes); + construct_reply(inbuf,nread,unread_bytes,encrypted); trans_num++; } @@ -1611,7 +1661,7 @@ void remove_from_common_flags2(uint32 v) void construct_reply_common(const char *inbuf, char *outbuf) { - srv_set_message(inbuf,outbuf,0,0,false); + srv_set_message(outbuf,0,0,false); SCVAL(outbuf,smb_com,CVAL(inbuf,smb_com)); SIVAL(outbuf,smb_rcls,0); @@ -1734,7 +1784,7 @@ void chain_reply(struct smb_request *req) if (!(req2 = talloc(talloc_tos(), struct smb_request))) { smb_panic("could not allocate smb_request"); } - init_smb_request(req2, (uint8 *)inbuf2,0); + init_smb_request(req2, (uint8 *)inbuf2,0, req->encrypted); /* process the request */ switch_message(smb_com2, req2, new_size); @@ -2020,6 +2070,7 @@ void smbd_process(void) int num_echos; char *inbuf; size_t inbuf_len; + bool encrypted = false; TALLOC_CTX *frame = talloc_stackframe(); errno = 0; @@ -2035,7 +2086,9 @@ void smbd_process(void) run_events(smbd_event_context(), 0, NULL, NULL); while (!receive_message_or_smb(NULL, &inbuf, &inbuf_len, - select_timeout, &unread_bytes)) { + select_timeout, + &unread_bytes, + &encrypted)) { if(!timeout_processing(&select_timeout, &last_timeout_processing_time)) return; @@ -2054,7 +2107,7 @@ void smbd_process(void) */ num_echos = smb_echo_count; - process_smb(inbuf, inbuf_len, unread_bytes); + process_smb(inbuf, inbuf_len, unread_bytes, encrypted); TALLOC_FREE(inbuf); -- cgit From 29562987c393ef7e908aa02ee7ba00a83f3db520 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 4 Jan 2008 15:37:24 -0800 Subject: Now conn is part of smb_request, we don't need it as an extra parameter. This cleans up quite a few places we were passing it around without needing it. Jeremy. (This used to be commit 8f36def18e9f980e8db522e1de41e80cfd5f466e) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 32d1d058e3..fe32d57ff7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1045,7 +1045,7 @@ force write permissions on print services. */ static const struct smb_message_struct { const char *name; - void (*fn_new)(connection_struct *conn, struct smb_request *req); + void (*fn_new)(struct smb_request *req); int flags; } smb_messages[256] = { @@ -1525,7 +1525,7 @@ static connection_struct *switch_message(uint8 type, struct smb_request *req, in return conn; } - smb_messages[type].fn_new(conn, req); + smb_messages[type].fn_new(req); return req->conn; } -- cgit From 253fbf1a6ece5c8dc9759e3535b7f9fa46883c1b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 9 Jan 2008 17:11:04 -0800 Subject: Make use of talloc_pool in the main codepaths. Remove the sub-contexts. Jeremy. (This used to be commit bc932b8ad4396f76b71c43efe9a6346f89c3632c) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index fe32d57ff7..2d3cf7fbd8 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -2071,7 +2071,7 @@ void smbd_process(void) char *inbuf; size_t inbuf_len; bool encrypted = false; - TALLOC_CTX *frame = talloc_stackframe(); + TALLOC_CTX *frame = talloc_stackframe_pool(8192); errno = 0; -- cgit From 18083f1d88f3cfade68587f9289fa709c229e1d0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 12 Jan 2008 21:09:43 +0100 Subject: Get the inbuf on talloc_tos() (This used to be commit 883f7415769ad1e714f636e9d6fbd1f075e69d1e) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2d3cf7fbd8..a5bdb96650 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -2085,7 +2085,7 @@ void smbd_process(void) run_events(smbd_event_context(), 0, NULL, NULL); - while (!receive_message_or_smb(NULL, &inbuf, &inbuf_len, + while (!receive_message_or_smb(talloc_tos(), &inbuf, &inbuf_len, select_timeout, &unread_bytes, &encrypted)) { -- cgit From 5b35ecd930dc6267821c7a3d8b3a90c680ab71b1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 23 Jan 2008 10:33:36 +0100 Subject: Remove two unused variables (This used to be commit f12ac1ecedd6634d8ccc54d8fce8382514e3322f) --- source3/smbd/process.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index a5bdb96650..6fd4d17d88 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -23,7 +23,6 @@ extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; -const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); static enum smb_read_errors smb_read_error = SMB_READ_OK; /* -- cgit From a925a53f61ebdc6b4386b7c0853f2f87cbe2e166 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 23 Jan 2008 16:42:31 +0100 Subject: read_socket_with_timeout has timeout=0 handling (This used to be commit 7101026061c470ed962267b43ac0aa67cc761a64) --- source3/smbd/process.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 6fd4d17d88..d961f98cc0 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -155,16 +155,8 @@ static ssize_t read_packet_remainder(int fd, return len; } - if (timeout > 0) { - ret = read_socket_with_timeout(fd, - buffer, - len, - len, - timeout, - get_srv_read_error()); - } else { - ret = read_data(fd, buffer, len, get_srv_read_error()); - } + ret = read_socket_with_timeout(fd, buffer, len, len, timeout, + get_srv_read_error()); if (ret != len) { cond_set_smb_read_error(get_srv_read_error(), @@ -206,19 +198,10 @@ static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, memcpy(writeX_header, lenbuf, sizeof(lenbuf)); - if (timeout > 0) { - ret = read_socket_with_timeout(fd, - writeX_header + 4, - STANDARD_WRITE_AND_X_HEADER_SIZE, - STANDARD_WRITE_AND_X_HEADER_SIZE, - timeout, - get_srv_read_error()); - } else { - ret = read_data(fd, - writeX_header+4, - STANDARD_WRITE_AND_X_HEADER_SIZE, - get_srv_read_error()); - } + ret = read_socket_with_timeout(fd, writeX_header + 4, + STANDARD_WRITE_AND_X_HEADER_SIZE, + STANDARD_WRITE_AND_X_HEADER_SIZE, + timeout, get_srv_read_error()); if (ret != STANDARD_WRITE_AND_X_HEADER_SIZE) { cond_set_smb_read_error(get_srv_read_error(), -- cgit From 47e1251f721cfbc45ab26b15d5bdbc523c55d6e9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 27 Jan 2008 00:35:14 +0100 Subject: Remove an unused external reference (This used to be commit 147033b9dff7160ff324fa52aba1f054f962961b) --- source3/smbd/process.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d961f98cc0..4672510d8d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -20,7 +20,6 @@ #include "includes.h" -extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; static enum smb_read_errors smb_read_error = SMB_READ_OK; -- cgit From 0afbfa4284db8204a3696f4fea6cff96965e6074 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 21:24:48 +0100 Subject: Convert read_smb_length_return_keepalive to return NTSTATUS (This used to be commit 73a79a957a33a8761acf54598ce71e3604ecf3c5) --- source3/smbd/process.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 4672510d8d..d6301d0d00 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -300,24 +300,30 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, size_t *p_unread) { char lenbuf[4]; - ssize_t len,ret; + size_t len; + ssize_t ret; int min_recv_size = lp_min_receive_file_size(); + NTSTATUS status; set_smb_read_error(get_srv_read_error(),SMB_READ_OK); *p_unread = 0; - len = read_smb_length_return_keepalive(fd, lenbuf, - timeout, get_srv_read_error()); - if (len < 0) { - DEBUG(10,("receive_smb_raw: length < 0!\n")); + status = read_smb_length_return_keepalive(fd, lenbuf, timeout, &len); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(10, ("receive_smb_raw: %s\n", nt_errstr(status))); - /* - * Correct fix. smb_read_error may have already been - * set. Only set it here if not already set. Global - * variables still suck :-). JRA. - */ + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); + return -1; + } - cond_set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + return -1; + } + + set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR); return -1; } -- cgit From 48b1ee61db5f513321b7f3360eb17f94ef339872 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 22:21:38 +0100 Subject: Convert read_packet_remainder to use read_socket_with_timeout_ntstatus (This used to be commit fff31f8f35ad26d67e78b9a71cfd35670aa9ac5f) --- source3/smbd/process.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d6301d0d00..02b190f003 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -148,22 +148,34 @@ static ssize_t read_packet_remainder(int fd, unsigned int timeout, ssize_t len) { - ssize_t ret; + NTSTATUS status; - if(len <= 0) { + if (len <= 0) { return len; } - ret = read_socket_with_timeout(fd, buffer, len, len, timeout, - get_srv_read_error()); + set_smb_read_error(get_srv_read_error(), SMB_READ_OK); - if (ret != len) { - cond_set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); + status = read_socket_with_timeout_ntstatus(fd, buffer, len, len, + timeout, NULL); + + if (NT_STATUS_IS_OK(status)) { + return len; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); return -1; } - return len; + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + return -1; + } + + set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR); + return -1; } /**************************************************************************** -- cgit From e604e137e21af52efdbabc28863a5ea76d8d620d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 22:27:59 +0100 Subject: Convert read_packet_remainder to return NTSTATUS (This used to be commit 667864d442ea7e1faed7b032315db8856fa91481) --- source3/smbd/process.c | 81 +++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 37 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 02b190f003..4d9a90a840 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -143,39 +143,15 @@ static bool valid_packet_size(size_t len) return true; } -static ssize_t read_packet_remainder(int fd, - char *buffer, - unsigned int timeout, - ssize_t len) +static NTSTATUS read_packet_remainder(int fd, char *buffer, + unsigned int timeout, ssize_t len) { - NTSTATUS status; - if (len <= 0) { - return len; - } - - set_smb_read_error(get_srv_read_error(), SMB_READ_OK); - - status = read_socket_with_timeout_ntstatus(fd, buffer, len, len, - timeout, NULL); - - if (NT_STATUS_IS_OK(status)) { - return len; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); - return -1; + return NT_STATUS_OK; } - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_TIMEOUT); - return -1; - } - - set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR); - return -1; + return read_socket_with_timeout_ntstatus(fd, buffer, len, len, + timeout, NULL); } /**************************************************************************** @@ -293,11 +269,29 @@ static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, toread = len - STANDARD_WRITE_AND_X_HEADER_SIZE; if(toread > 0) { - ret = read_packet_remainder(fd, - (*buffer) + 4 + STANDARD_WRITE_AND_X_HEADER_SIZE, - timeout, - toread); - if (ret != toread) { + NTSTATUS status; + + set_smb_read_error(get_srv_read_error(), SMB_READ_OK); + + status = read_packet_remainder( + fd, (*buffer) + 4 + STANDARD_WRITE_AND_X_HEADER_SIZE, + timeout, toread); + + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_EOF); + return -1; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + return -1; + } + + set_smb_read_error(get_srv_read_error(), + SMB_READ_ERROR); return -1; } } @@ -313,7 +307,6 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, { char lenbuf[4]; size_t len; - ssize_t ret; int min_recv_size = lp_min_receive_file_size(); NTSTATUS status; @@ -371,8 +364,22 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, memcpy(*buffer, lenbuf, sizeof(lenbuf)); - ret = read_packet_remainder(fd, (*buffer)+4, timeout, len); - if (ret != len) { + status = read_packet_remainder(fd, (*buffer)+4, timeout, len); + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_EOF); + return -1; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + return -1; + } + + set_smb_read_error(get_srv_read_error(), + SMB_READ_ERROR); return -1; } -- cgit From 250b2b6464521fa4e2b5c737164e1ce68755677f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:12:04 +0100 Subject: Convert receive_smb_raw_talloc_partial_read to NTSTATUS (This used to be commit 9a82350ba92bf5fc4f2968d5130bcb2118e7a981) --- source3/smbd/process.c | 106 ++++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 59 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 4d9a90a840..10ef67c2b2 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -128,15 +128,6 @@ static bool valid_packet_size(size_t len) DEBUG(0,("Invalid packet length! (%lu bytes).\n", (unsigned long)len)); if (len > BUFFER_SIZE + (SAFETY_MARGIN/2)) { - - /* - * Correct fix. smb_read_error may have already been - * set. Only set it here if not already set. Global - * variables still suck :-). JRA. - */ - - cond_set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); return false; } } @@ -170,30 +161,29 @@ static NTSTATUS read_packet_remainder(int fd, char *buffer, (2*14) + /* word count (including bcc) */ \ 1 /* pad byte */) -static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, - const char lenbuf[4], - int fd, - char **buffer, - unsigned int timeout, - size_t *p_unread) +static NTSTATUS receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, + const char lenbuf[4], + int fd, char **buffer, + unsigned int timeout, + size_t *p_unread, + size_t *len_ret) { /* Size of a WRITEX call (+4 byte len). */ char writeX_header[4 + STANDARD_WRITE_AND_X_HEADER_SIZE]; ssize_t len = smb_len_large(lenbuf); /* Could be a UNIX large writeX. */ ssize_t toread; - ssize_t ret; + NTSTATUS status; memcpy(writeX_header, lenbuf, sizeof(lenbuf)); - ret = read_socket_with_timeout(fd, writeX_header + 4, - STANDARD_WRITE_AND_X_HEADER_SIZE, - STANDARD_WRITE_AND_X_HEADER_SIZE, - timeout, get_srv_read_error()); + status = read_socket_with_timeout_ntstatus( + fd, writeX_header + 4, + STANDARD_WRITE_AND_X_HEADER_SIZE, + STANDARD_WRITE_AND_X_HEADER_SIZE, + timeout, NULL); - if (ret != STANDARD_WRITE_AND_X_HEADER_SIZE) { - cond_set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); - return -1; + if (!NT_STATUS_IS_OK(status)) { + return status; } /* @@ -232,19 +222,17 @@ static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)sizeof(writeX_header))); - cond_set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); - return -1; + return NT_STATUS_NO_MEMORY; } /* Work out the remaining bytes. */ *p_unread = len - STANDARD_WRITE_AND_X_HEADER_SIZE; - - return newlen + 4; + *len_ret = newlen + 4; + return NT_STATUS_OK; } if (!valid_packet_size(len)) { - return -1; + return NT_STATUS_INVALID_PARAMETER; } /* @@ -257,9 +245,7 @@ static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)len+4)); - cond_set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); - return -1; + return NT_STATUS_NO_MEMORY; } /* Copy in what we already read. */ @@ -269,34 +255,17 @@ static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, toread = len - STANDARD_WRITE_AND_X_HEADER_SIZE; if(toread > 0) { - NTSTATUS status; - - set_smb_read_error(get_srv_read_error(), SMB_READ_OK); - status = read_packet_remainder( fd, (*buffer) + 4 + STANDARD_WRITE_AND_X_HEADER_SIZE, timeout, toread); if (!NT_STATUS_IS_OK(status)) { - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_EOF); - return -1; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_TIMEOUT); - return -1; - } - - set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); - return -1; + return status; } } - return len + 4; + *len_ret = len + 4; + return NT_STATUS_OK; } static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, @@ -337,15 +306,34 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, smb_len_large(lenbuf) > min_recv_size && /* Could be a UNIX large writeX. */ !srv_is_signing_active()) { - return receive_smb_raw_talloc_partial_read(mem_ctx, - lenbuf, - fd, - buffer, - timeout, - p_unread); + status = receive_smb_raw_talloc_partial_read( + mem_ctx, lenbuf, fd, buffer, timeout, p_unread, &len); + + if (!NT_STATUS_IS_OK(status)) { + + DEBUG(10, ("receive_smb_raw: %s\n", + nt_errstr(status))); + + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_EOF); + return -1; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + return -1; + } + + set_smb_read_error(get_srv_read_error(), + SMB_READ_ERROR); + return -1; + } } if (!valid_packet_size(len)) { + cond_set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); return -1; } -- cgit From 9fe66ddd15b3c5b5d9a30fc79d6ed6cdb31cae12 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:18:56 +0100 Subject: Convert receive_smb_raw_talloc to NTSTATUS (This used to be commit 187707591ffa2668aecd4857cb2ef2cd20bd6b08) --- source3/smbd/process.c | 90 ++++++++++++++++---------------------------------- 1 file changed, 29 insertions(+), 61 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 10ef67c2b2..cb7d12a0c3 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -268,37 +268,21 @@ static NTSTATUS receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } -static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, - int fd, - char **buffer, - unsigned int timeout, - size_t *p_unread) +static NTSTATUS receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, int fd, + char **buffer, unsigned int timeout, + size_t *p_unread, size_t *plen) { char lenbuf[4]; size_t len; int min_recv_size = lp_min_receive_file_size(); NTSTATUS status; - set_smb_read_error(get_srv_read_error(),SMB_READ_OK); *p_unread = 0; status = read_smb_length_return_keepalive(fd, lenbuf, timeout, &len); if (!NT_STATUS_IS_OK(status)) { DEBUG(10, ("receive_smb_raw: %s\n", nt_errstr(status))); - - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); - return -1; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_TIMEOUT); - return -1; - } - - set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR); - return -1; + return status; } if (CVAL(lenbuf,0) == 0 && @@ -310,31 +294,14 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, mem_ctx, lenbuf, fd, buffer, timeout, p_unread, &len); if (!NT_STATUS_IS_OK(status)) { - DEBUG(10, ("receive_smb_raw: %s\n", nt_errstr(status))); - - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_EOF); - return -1; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_TIMEOUT); - return -1; - } - - set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); - return -1; + return status; } } if (!valid_packet_size(len)) { - cond_set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); - return -1; + return NT_STATUS_INVALID_PARAMETER; } /* @@ -346,32 +313,18 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)len+4)); - cond_set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); - return -1; + return NT_STATUS_NO_MEMORY; } memcpy(*buffer, lenbuf, sizeof(lenbuf)); status = read_packet_remainder(fd, (*buffer)+4, timeout, len); if (!NT_STATUS_IS_OK(status)) { - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_EOF); - return -1; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_TIMEOUT); - return -1; - } - - set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); - return -1; + return status; } - return len + 4; + *plen = len + 4; + return NT_STATUS_OK; } static ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, @@ -381,18 +334,33 @@ static ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, size_t *p_unread, bool *p_encrypted) { - ssize_t len; + size_t len; + NTSTATUS status; *p_encrypted = false; - len = receive_smb_raw_talloc(mem_ctx, fd, buffer, timeout, p_unread); + set_smb_read_error(get_srv_read_error(), SMB_READ_OK); + + status = receive_smb_raw_talloc(mem_ctx, fd, buffer, timeout, + p_unread, &len); + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); + return -1; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + return -1; + } - if (len < 0) { + set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR); return -1; } if (is_encrypted_packet((uint8_t *)*buffer)) { - NTSTATUS status = srv_decrypt_buffer(*buffer); + status = srv_decrypt_buffer(*buffer); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("receive_smb_talloc: SMB decryption failed on " "incoming packet! Error %s\n", -- cgit From e514cd0af56031cd0396e716e9e77edf897420e9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:28:22 +0100 Subject: Convert receive_smb_talloc to NTSTATUS (This used to be commit ddbdd11a49fba9ec4834807dec385cdf3120ce00) --- source3/smbd/process.c | 61 +++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 33 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index cb7d12a0c3..e21229109d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -327,36 +327,20 @@ static NTSTATUS receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, int fd, return NT_STATUS_OK; } -static ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, - int fd, - char **buffer, - unsigned int timeout, - size_t *p_unread, - bool *p_encrypted) +static NTSTATUS receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, + char **buffer, unsigned int timeout, + size_t *p_unread, bool *p_encrypted, + size_t *p_len) { size_t len; NTSTATUS status; *p_encrypted = false; - set_smb_read_error(get_srv_read_error(), SMB_READ_OK); - status = receive_smb_raw_talloc(mem_ctx, fd, buffer, timeout, p_unread, &len); if (!NT_STATUS_IS_OK(status)) { - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); - return -1; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_TIMEOUT); - return -1; - } - - set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR); - return -1; + return status; } if (is_encrypted_packet((uint8_t *)*buffer)) { @@ -365,9 +349,7 @@ static ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, DEBUG(0, ("receive_smb_talloc: SMB decryption failed on " "incoming packet! Error %s\n", nt_errstr(status) )); - cond_set_smb_read_error(get_srv_read_error(), - SMB_READ_BAD_DECRYPT); - return -1; + return status; } *p_encrypted = true; } @@ -376,11 +358,11 @@ static ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, if (!srv_check_sign_mac(*buffer, true)) { DEBUG(0, ("receive_smb: SMB Signature verification failed on " "incoming packet!\n")); - cond_set_smb_read_error(get_srv_read_error(),SMB_READ_BAD_SIG); - return -1; + return NT_STATUS_INVALID_NETWORK_RESPONSE; } - return len; + *p_len = len; + return NT_STATUS_OK; } /* @@ -748,7 +730,8 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, int selrtn; struct timeval to; int maxfd = 0; - ssize_t len; + size_t len; + NTSTATUS status; *p_unread = 0; set_smb_read_error(get_srv_read_error(),SMB_READ_OK); @@ -926,14 +909,26 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, goto again; } - len = receive_smb_talloc(mem_ctx, smbd_server_fd(), - buffer, 0, p_unread, p_encrypted); + status = receive_smb_talloc(mem_ctx, smbd_server_fd(), buffer, 0, + p_unread, p_encrypted, &len); - if (len == -1) { - return False; + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); + return false; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + return false; + } + + set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR); + return false; } - *buffer_len = (size_t)len; + *buffer_len = len; return True; } -- cgit From 6ddfa6ae7734ffdd26ac38478c27cc9d646ddadd Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:43:50 +0100 Subject: read_socket_with_timeout_ntstatus->read_socket_with_timeout (This used to be commit 90554799afa42855c3e7b87dc632e67f0952f988) --- source3/smbd/process.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index e21229109d..83e51e3892 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -141,8 +141,7 @@ static NTSTATUS read_packet_remainder(int fd, char *buffer, return NT_STATUS_OK; } - return read_socket_with_timeout_ntstatus(fd, buffer, len, len, - timeout, NULL); + return read_socket_with_timeout(fd, buffer, len, len, timeout, NULL); } /**************************************************************************** @@ -176,7 +175,7 @@ static NTSTATUS receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, memcpy(writeX_header, lenbuf, sizeof(lenbuf)); - status = read_socket_with_timeout_ntstatus( + status = read_socket_with_timeout( fd, writeX_header + 4, STANDARD_WRITE_AND_X_HEADER_SIZE, STANDARD_WRITE_AND_X_HEADER_SIZE, -- cgit From 21e7344d2f45416ea996f88be72de1a923c0ee9c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:57:20 +0100 Subject: Make get_srv_read_error static to process.c (This used to be commit 9e2947039ef70cab8bbd6027182d9c721eac3194) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 83e51e3892..f5a3186e5e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -43,7 +43,7 @@ extern int max_send; /* Accessor function for smb_read_error for smbd functions. */ -enum smb_read_errors *get_srv_read_error(void) +static enum smb_read_errors *get_srv_read_error(void) { return &smb_read_error; } -- cgit From eaf7621c51629f058b85ce4593a2338b9b2d06ed Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Jan 2008 15:18:33 +0100 Subject: Convert receive_message_or_smb to NTSTATUS (This used to be commit 0f7d360a01baf02e251846118cb36e6a1cdcbeb9) --- source3/smbd/process.c | 79 +++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 36 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f5a3186e5e..4fa1248e3b 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -718,12 +718,9 @@ static int select_on_fd(int fd, int maxfd, fd_set *fds) The timeout is in milliseconds ****************************************************************************/ -static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, - char **buffer, - size_t *buffer_len, - int timeout, - size_t *p_unread, - bool *p_encrypted) +static NTSTATUS receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, + size_t *buffer_len, int timeout, + size_t *p_unread, bool *p_encrypted) { fd_set r_fds, w_fds; int selrtn; @@ -733,7 +730,6 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, NTSTATUS status; *p_unread = 0; - set_smb_read_error(get_srv_read_error(),SMB_READ_OK); again: @@ -787,8 +783,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, msg->buf.length); if (*buffer == NULL) { DEBUG(0, ("talloc failed\n")); - set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); - return False; + return NT_STATUS_NO_MEMORY; } *buffer_len = msg->buf.length; *p_encrypted = msg->encrypted; @@ -796,7 +791,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, /* We leave this message on the queue so the open code can know this is a retry. */ DEBUG(5,("receive_message_or_smb: returning deferred open smb message.\n")); - return True; + return NT_STATUS_OK; } } @@ -882,14 +877,12 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, /* Check if error */ if (selrtn == -1) { /* something is wrong. Maybe the socket is dead? */ - set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); - return False; + return map_nt_error_from_unix(errno); } /* Did we timeout ? */ if (selrtn == 0) { - set_smb_read_error(get_srv_read_error(),SMB_READ_TIMEOUT); - return False; + return NT_STATUS_IO_TIMEOUT; } /* @@ -912,24 +905,12 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, p_unread, p_encrypted, &len); if (!NT_STATUS_IS_OK(status)) { - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); - return false; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_TIMEOUT); - return false; - } - - set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR); - return false; + return status; } *buffer_len = len; - return True; + return NT_STATUS_OK; } /* @@ -2024,8 +2005,8 @@ void smbd_process(void) while (True) { int select_timeout = setup_select_timeout(); int num_echos; - char *inbuf; - size_t inbuf_len; + char *inbuf = NULL; + size_t inbuf_len = 0; bool encrypted = false; TALLOC_CTX *frame = talloc_stackframe_pool(8192); @@ -2041,13 +2022,39 @@ void smbd_process(void) run_events(smbd_event_context(), 0, NULL, NULL); - while (!receive_message_or_smb(talloc_tos(), &inbuf, &inbuf_len, - select_timeout, - &unread_bytes, - &encrypted)) { - if(!timeout_processing(&select_timeout, - &last_timeout_processing_time)) + while (True) { + NTSTATUS status; + + set_smb_read_error(get_srv_read_error(), SMB_READ_OK); + + status = receive_message_or_smb( + talloc_tos(), &inbuf, &inbuf_len, + select_timeout, &unread_bytes, &encrypted); + + if (NT_STATUS_IS_OK(status)) { + break; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_EOF); + } + else if (NT_STATUS_EQUAL(status, + NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + } + else { + set_smb_read_error(get_srv_read_error(), + SMB_READ_ERROR); + } + + if (!timeout_processing( + &select_timeout, + &last_timeout_processing_time)) { return; + } + num_smbs = 0; /* Reset smb counter. */ } -- cgit From 9e5a5d49dee83335f6990c4ec5d3b11f1f69e2e7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Jan 2008 15:33:40 +0100 Subject: Remove dependency on get_srv_read_error() from main loop (This used to be commit fad87968921eca0b5144760c412c5f599f9066f3) --- source3/smbd/process.c | 69 +++++++++++++++----------------------------------- 1 file changed, 20 insertions(+), 49 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 4fa1248e3b..3cb1331054 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1888,27 +1888,11 @@ void check_reload(time_t t) Process any timeout housekeeping. Return False if the caller should exit. ****************************************************************************/ -static bool timeout_processing(int *select_timeout, +static void timeout_processing(int *select_timeout, time_t *last_timeout_processing_time) { time_t t; - if (*get_srv_read_error() == SMB_READ_EOF) { - DEBUG(3,("timeout_processing: End of file from client (client has disconnected).\n")); - return false; - } - - if (*get_srv_read_error() == SMB_READ_ERROR) { - DEBUG(3,("timeout_processing: receive_smb error (%s) Exiting\n", - strerror(errno))); - return false; - } - - if (*get_srv_read_error() == SMB_READ_BAD_SIG) { - DEBUG(3,("timeout_processing: receive_smb error bad smb signature. Exiting\n")); - return false; - } - *last_timeout_processing_time = t = time(NULL); /* become root again if waiting */ @@ -1938,14 +1922,14 @@ static bool timeout_processing(int *select_timeout, if (secrets_lock_trust_account_password(lp_workgroup(), True) == False) { DEBUG(0,("process: unable to lock the machine account password for \ machine %s in domain %s.\n", global_myname(), lp_workgroup() )); - return True; + return; } if(!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd_hash, &lct, NULL)) { DEBUG(0,("process: unable to read the machine account password for \ machine %s in domain %s.\n", global_myname(), lp_workgroup())); secrets_lock_trust_account_password(lp_workgroup(), False); - return True; + return; } /* @@ -1955,7 +1939,7 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); if(t < lct + lp_machine_password_timeout()) { global_machine_password_needs_changing = False; secrets_lock_trust_account_password(lp_workgroup(), False); - return True; + return; } /* always just contact the PDC here */ @@ -1987,7 +1971,7 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); *select_timeout = setup_select_timeout(); - return True; + return; } /**************************************************************************** @@ -2014,9 +1998,8 @@ void smbd_process(void) /* Did someone ask for immediate checks on things like blocking locks ? */ if (select_timeout == 0) { - if(!timeout_processing(&select_timeout, - &last_timeout_processing_time)) - return; + timeout_processing(&select_timeout, + &last_timeout_processing_time); num_smbs = 0; /* Reset smb counter. */ } @@ -2025,8 +2008,6 @@ void smbd_process(void) while (True) { NTSTATUS status; - set_smb_read_error(get_srv_read_error(), SMB_READ_OK); - status = receive_message_or_smb( talloc_tos(), &inbuf, &inbuf_len, select_timeout, &unread_bytes, &encrypted); @@ -2035,25 +2016,16 @@ void smbd_process(void) break; } - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_EOF); - } - else if (NT_STATUS_EQUAL(status, - NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_TIMEOUT); - } - else { - set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + timeout_processing( + &select_timeout, + &last_timeout_processing_time); + continue; } - if (!timeout_processing( - &select_timeout, - &last_timeout_processing_time)) { - return; - } + DEBUG(3, ("receive_message_or_smb failed: %s, " + "exiting\n", nt_errstr(status))); + return; num_smbs = 0; /* Reset smb counter. */ } @@ -2075,8 +2047,8 @@ void smbd_process(void) TALLOC_FREE(inbuf); if (smb_echo_count != num_echos) { - if(!timeout_processing( &select_timeout, &last_timeout_processing_time)) - return; + timeout_processing(&select_timeout, + &last_timeout_processing_time); num_smbs = 0; /* Reset smb counter. */ } @@ -2092,10 +2064,9 @@ void smbd_process(void) if ((num_smbs % 200) == 0) { time_t new_check_time = time(NULL); if(new_check_time - last_timeout_processing_time >= (select_timeout/1000)) { - if(!timeout_processing( - &select_timeout, - &last_timeout_processing_time)) - return; + timeout_processing( + &select_timeout, + &last_timeout_processing_time); num_smbs = 0; /* Reset smb counter. */ last_timeout_processing_time = new_check_time; /* Reset time. */ } -- cgit From e8f1edb9cd0d2014c05cdb2aba4f4deef48efedf Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Jan 2008 15:36:00 +0100 Subject: Remove smb_read_error global YESS :-) (This used to be commit 26771bdca0e6837db267f4db7907e489acd92fc6) --- source3/smbd/process.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 3cb1331054..2a643864fa 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -22,8 +22,6 @@ extern int smb_echo_count; -static enum smb_read_errors smb_read_error = SMB_READ_OK; - /* * Size of data we can send to client. Set * by the client for all protocols above CORE. @@ -43,11 +41,6 @@ extern int max_send; /* Accessor function for smb_read_error for smbd functions. */ -static enum smb_read_errors *get_srv_read_error(void) -{ - return &smb_read_error; -} - /**************************************************************************** Send an smb to a fd. ****************************************************************************/ -- cgit From 47666c93a78dc7a9c18212bfe7be3e6487313226 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 5 Feb 2008 13:36:17 -0800 Subject: Fix a couple of "might be used uninitialized" warnings. Jeremy. (This used to be commit b3ac8073a23afbba19d045302aa0700197c58bd5) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2a643864fa..68bec7830a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -324,7 +324,7 @@ static NTSTATUS receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, size_t *p_unread, bool *p_encrypted, size_t *p_len) { - size_t len; + size_t len = 0; NTSTATUS status; *p_encrypted = false; @@ -719,7 +719,7 @@ static NTSTATUS receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, int selrtn; struct timeval to; int maxfd = 0; - size_t len; + size_t len = 0; NTSTATUS status; *p_unread = 0; -- cgit From d634ab06b34990b6eecee751435f2436ff76ec44 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 10 Mar 2008 15:48:04 +0100 Subject: Convert secrets_lock_trust_account_password to talloc This is preparing the conversion of secrets.c to ctdb (This used to be commit 1307f0130c47b8d740d2b7afe7a5d8d1a655e2a2) --- source3/smbd/process.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 68bec7830a..9c01bbaa4a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1901,6 +1901,7 @@ static void timeout_processing(int *select_timeout, unsigned char trust_passwd_hash[16]; time_t lct; + void *lock; /* * We're in domain level security, and the code that @@ -1912,7 +1913,9 @@ static void timeout_processing(int *select_timeout, * First, open the machine password file with an exclusive lock. */ - if (secrets_lock_trust_account_password(lp_workgroup(), True) == False) { + lock = secrets_get_trust_account_lock(NULL, lp_workgroup()); + + if (lock == NULL) { DEBUG(0,("process: unable to lock the machine account password for \ machine %s in domain %s.\n", global_myname(), lp_workgroup() )); return; @@ -1921,7 +1924,7 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup() )); if(!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd_hash, &lct, NULL)) { DEBUG(0,("process: unable to read the machine account password for \ machine %s in domain %s.\n", global_myname(), lp_workgroup())); - secrets_lock_trust_account_password(lp_workgroup(), False); + TALLOC_FREE(lock); return; } @@ -1931,7 +1934,7 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); if(t < lct + lp_machine_password_timeout()) { global_machine_password_needs_changing = False; - secrets_lock_trust_account_password(lp_workgroup(), False); + TALLOC_FREE(lock); return; } @@ -1939,7 +1942,7 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); change_trust_account_password( lp_workgroup(), NULL); global_machine_password_needs_changing = False; - secrets_lock_trust_account_password(lp_workgroup(), False); + TALLOC_FREE(lock); } /* update printer queue caches if necessary */ -- cgit From e11cd466e1b6beae82fa0117c300669b8eff7f0a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 31 Mar 2008 16:46:20 -0700 Subject: Reduce the race condition in Samba4 in RAW-RENAME test. We rename a file using trans2 setfileinfo on one connection, and then check the file name has changed on the other. In Samba we achieve this by sending a local message to the other process. This change causes us to re-scan for incoming messages after we've woken up from the select (which is cheap if there are no pending messages). This reduces the race significantly. Volker please review. Jeremy. (This used to be commit a7499e994aef743ea9c443f9a1618b262f6eda93) --- source3/smbd/process.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 9c01bbaa4a..03216a0700 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -853,6 +853,15 @@ static NTSTATUS receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, goto again; } + /* + * We've just woken up from a protentially long select sleep. + * Ensure we process local messages as we need to synchronously + * process any messages from other smbd's to avoid file rename race + * conditions. This call is cheap if there are no messages waiting. + * JRA. + */ + message_dispatch(smbd_messaging_context()); + /* if we get EINTR then maybe we have received an oplock signal - treat this as select returning 1. This is ugly, but is the best we can do until the oplock code knows more about -- cgit From 6913f1013456be8938bb71b3d8968170e50933e7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 31 Mar 2008 16:56:21 -0700 Subject: Move the message_dispatch() call after the check for errno on the select return. We don't want the call to message_dispatch to mess up the errno value. Jeremy. (This used to be commit 26a74d01bb2b53ffa5d296ff1c7d8b2b0d17831a) --- source3/smbd/process.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 03216a0700..9aa775d0f6 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -853,15 +853,6 @@ static NTSTATUS receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, goto again; } - /* - * We've just woken up from a protentially long select sleep. - * Ensure we process local messages as we need to synchronously - * process any messages from other smbd's to avoid file rename race - * conditions. This call is cheap if there are no messages waiting. - * JRA. - */ - message_dispatch(smbd_messaging_context()); - /* if we get EINTR then maybe we have received an oplock signal - treat this as select returning 1. This is ugly, but is the best we can do until the oplock code knows more about @@ -880,8 +871,17 @@ static NTSTATUS receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, if (selrtn == -1) { /* something is wrong. Maybe the socket is dead? */ return map_nt_error_from_unix(errno); - } - + } + + /* + * We've just woken up from a protentially long select sleep. + * Ensure we process local messages as we need to synchronously + * process any messages from other smbd's to avoid file rename race + * conditions. This call is cheap if there are no messages waiting. + * JRA. + */ + message_dispatch(smbd_messaging_context()); + /* Did we timeout ? */ if (selrtn == 0) { return NT_STATUS_IO_TIMEOUT; -- cgit From 8b04a3350092bf482e4b1c3339ccf95449848bf7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 31 Mar 2008 17:01:27 -0700 Subject: Ok, final move of this code :-). I think I've found the correct place for it now where it will cause minimal disruption (only call the extra message_dispatch just before reading the next smb off the wire). Jeremy. (This used to be commit da2c19c481d0041872b4ce2f5105052077f3d3b8) --- source3/smbd/process.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 9aa775d0f6..88684315cc 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -873,15 +873,6 @@ static NTSTATUS receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, return map_nt_error_from_unix(errno); } - /* - * We've just woken up from a protentially long select sleep. - * Ensure we process local messages as we need to synchronously - * process any messages from other smbd's to avoid file rename race - * conditions. This call is cheap if there are no messages waiting. - * JRA. - */ - message_dispatch(smbd_messaging_context()); - /* Did we timeout ? */ if (selrtn == 0) { return NT_STATUS_IO_TIMEOUT; @@ -903,6 +894,15 @@ static NTSTATUS receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, goto again; } + /* + * We've just woken up from a protentially long select sleep. + * Ensure we process local messages as we need to synchronously + * process any messages from other smbd's to avoid file rename race + * conditions. This call is cheap if there are no messages waiting. + * JRA. + */ + message_dispatch(smbd_messaging_context()); + status = receive_smb_talloc(mem_ctx, smbd_server_fd(), buffer, 0, p_unread, p_encrypted, &len); -- cgit From a4c0812af0132476dfd542ca212304de898fa7c7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 2 Apr 2008 15:54:49 +0200 Subject: Fix some "ignoring asprintf result" warnings (This used to be commit 155d62ddfd3584d44a493c2aa1ea7f096bcff432) --- source3/smbd/process.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 88684315cc..5946989ae7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1259,8 +1259,10 @@ void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes) if ((num_bytes > 0xffffff) || ((num_bytes + smb_size + num_words*2) > 0xffffff)) { char *msg; - asprintf(&msg, "num_bytes too large: %u", - (unsigned)num_bytes); + if (asprintf(&msg, "num_bytes too large: %u", + (unsigned)num_bytes) == -1) { + msg = CONST_DISCARD(char *, "num_bytes too large"); + } smb_panic(msg); } @@ -1298,9 +1300,8 @@ static void smb_dump(const char *name, int type, const char *data, ssize_t len) if (len < 4) len = smb_len(data)+4; for (i=1;i<100;i++) { - asprintf(&fname, "/tmp/%s.%d.%s", name, i, - type ? "req" : "resp"); - if (!fname) { + if (asprintf(&fname, "/tmp/%s.%d.%s", name, i, + type ? "req" : "resp") == -1) { return; } fd = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0644); -- cgit From bec1dfab27be3db888eeb451b4547f16e08e93c3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 30 Apr 2008 17:42:39 +0200 Subject: Remove "userdom_struct user" from "struct user_struct" (This used to be commit 420de035237bb08bc470c9eb820f3da2edaa6805) --- source3/smbd/process.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 5946989ae7..ab737a89a7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1387,7 +1387,13 @@ static connection_struct *switch_message(uint8 type, struct smb_request *req, in if(session_tag != UID_FIELD_INVALID) { vuser = get_valid_user_struct(session_tag); if (vuser) { - set_current_user_info(&vuser->user); + set_current_user_info( + vuser->server_info->sanitized_username, + vuser->server_info->unix_name, + pdb_get_fullname(vuser->server_info + ->sam_account), + pdb_get_domain(vuser->server_info + ->sam_account)); } } } -- cgit From 8ca459e067c3d4f3495e0a6dafea7296e3dfb2ab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 20 May 2008 12:09:48 -0700 Subject: Fix bug #5477 - recvfile code was broken. Jeremy. (This used to be commit 830337f054a6c0646d85df33d9958e99283e727a) --- source3/smbd/process.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ab737a89a7..c8ad19dd15 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -252,6 +252,8 @@ static NTSTATUS receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, timeout, toread); if (!NT_STATUS_IS_OK(status)) { + DEBUG(10, ("receive_smb_raw_talloc_partial_read: %s\n", + nt_errstr(status))); return status; } } @@ -282,14 +284,8 @@ static NTSTATUS receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, int fd, smb_len_large(lenbuf) > min_recv_size && /* Could be a UNIX large writeX. */ !srv_is_signing_active()) { - status = receive_smb_raw_talloc_partial_read( - mem_ctx, lenbuf, fd, buffer, timeout, p_unread, &len); - - if (!NT_STATUS_IS_OK(status)) { - DEBUG(10, ("receive_smb_raw: %s\n", - nt_errstr(status))); - return status; - } + return receive_smb_raw_talloc_partial_read( + mem_ctx, lenbuf, fd, buffer, timeout, p_unread, plen); } if (!valid_packet_size(len)) { -- cgit From d36434f31268b75040311352f23c92c9a61e8cda Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 May 2008 09:31:42 -0700 Subject: Security fix for CVE-2008-1105: Boundary failure when parsing SMB responses can result in a buffer overrun. Jeremy. (This used to be commit 23b825e9d2c74c5b940cf4d3aa56c18692259972) --- source3/smbd/process.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c8ad19dd15..71e38634b7 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -120,9 +120,7 @@ static bool valid_packet_size(size_t len) if (len > (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE)) { DEBUG(0,("Invalid packet length! (%lu bytes).\n", (unsigned long)len)); - if (len > BUFFER_SIZE + (SAFETY_MARGIN/2)) { - return false; - } + return false; } return true; } -- cgit From 5cd8a42720b09c50109052b4fea253b2653525d5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 2 Apr 2008 15:34:29 +0200 Subject: Factor out create_outbuf, creating an outbuf just given an inbuf (This used to be commit 50427cbf6345d3f671e9ea321089c4b4244df972) --- source3/smbd/process.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 71e38634b7..da1165219b 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1245,7 +1245,8 @@ static const struct smb_message_struct { allocate and initialize a reply packet ********************************************************************/ -void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes) +bool create_outbuf(TALLOC_CTX *mem_ctx, const char *inbuf, char **outbuf, + uint8_t num_words, uint32_t num_bytes) { /* * Protect against integer wrap @@ -1260,23 +1261,33 @@ void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes) smb_panic(msg); } - if (!(req->outbuf = TALLOC_ARRAY( - req, uint8, - smb_size + num_words*2 + num_bytes))) { - smb_panic("could not allocate output buffer\n"); + *outbuf = TALLOC_ARRAY(mem_ctx, char, + smb_size + num_words*2 + num_bytes); + if (*outbuf == NULL) { + return false; } - construct_reply_common((char *)req->inbuf, (char *)req->outbuf); - srv_set_message((char *)req->outbuf, num_words, num_bytes, false); + construct_reply_common(inbuf, *outbuf); + srv_set_message(*outbuf, num_words, num_bytes, false); /* * Zero out the word area, the caller has to take care of the bcc area * himself */ if (num_words != 0) { - memset(req->outbuf + smb_vwv0, 0, num_words*2); + memset(*outbuf + smb_vwv0, 0, num_words*2); } - return; + return true; +} + +void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes) +{ + char *outbuf; + if (!create_outbuf(req, (char *)req->inbuf, &outbuf, num_words, + num_bytes)) { + smb_panic("could not allocate output buffer\n"); + } + req->outbuf = (uint8_t *)outbuf; } -- cgit From 12b6c1f57db772679cfb4b640a3f3dba259c9c72 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 10 Aug 2008 17:37:08 +0200 Subject: Fix andx offset calculation for more than 2 chained requests Untested code is broken code.... Test follows later, it's quite an intrusive change to libsmb/ (This used to be commit 0ff16e8573f3c312f10fc723648319fa1f514ac0) --- source3/smbd/process.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index da1165219b..a1d2d88b3d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1696,7 +1696,7 @@ void chain_reply(struct smb_request *req) * remember how much the caller added to the chain, only counting * stuff after the parameter words */ - chain_size += outsize_padded - smb_wct; + chain_size += (outsize_padded - smb_wct); /* * work out pointers into the original packets. The @@ -1825,6 +1825,12 @@ void chain_reply(struct smb_request *req) SAFE_FREE(caller_output); TALLOC_FREE(req2); + /* + * Reset the chain_size for our caller's offset calculations + */ + + chain_size -= (outsize_padded - smb_wct); + return; } -- cgit From 1a7b6fe34d6d7d29256fe3b5432593fa07d74838 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 10 Aug 2008 17:53:35 +0200 Subject: fix smb_len calculation for chained requests I think chain_reply() is one of the most tricky parts of Samba. This recursion needs to go away, we need to sequentially walk the chain list. (This used to be commit af2b01d85188d2301580643f7e862e3e3988aadc) --- source3/smbd/process.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index a1d2d88b3d..332a2e4da3 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1653,6 +1653,7 @@ void chain_reply(struct smb_request *req) char *outbuf = (char *)req->outbuf; size_t outsize = smb_len(outbuf) + 4; size_t outsize_padded; + size_t padding; size_t ofs, to_move; struct smb_request *req2; @@ -1691,6 +1692,7 @@ void chain_reply(struct smb_request *req) */ outsize_padded = (outsize + 3) & ~3; + padding = outsize_padded - outsize; /* * remember how much the caller added to the chain, only counting @@ -1804,17 +1806,17 @@ void chain_reply(struct smb_request *req) SCVAL(outbuf, smb_vwv0, smb_com2); SSVAL(outbuf, smb_vwv1, chain_size + smb_wct - 4); - if (outsize_padded > outsize) { + if (padding != 0) { /* * Due to padding we have some uninitialized bytes after the * caller's output */ - memset(outbuf + outsize, 0, outsize_padded - outsize); + memset(outbuf + outsize, 0, padding); } - smb_setlen(outbuf, outsize2 + chain_size - 4); + smb_setlen(outbuf, outsize2 + caller_outputlen + padding - 4); /* * restore the saved data, being careful not to overwrite any data -- cgit From 227718cd1a2143cd3c9585fc76f335ec7b5a24a5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 1 Sep 2008 13:46:27 +0200 Subject: Fix Coverity ID 587 The following test program prints "8" on 64-bit :-) static void print_size(const char lenbuf[4]) { printf("sizeof(lenbuf) = %d\n", (int)sizeof(lenbuf)); } int main(void) { const char lenbuf[4]; print_size(lenbuf); return 0; } Jeremy, please check :-) Volker (This used to be commit 9daea0ccfdda58450be3c9a9a94c016f5900c319) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 332a2e4da3..b2d19e11e3 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -164,7 +164,7 @@ static NTSTATUS receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, ssize_t toread; NTSTATUS status; - memcpy(writeX_header, lenbuf, sizeof(lenbuf)); + memcpy(writeX_header, lenbuf, 4); status = read_socket_with_timeout( fd, writeX_header + 4, -- cgit