From 8978aae69699ccab76fdf95037948b1cc7e7c286 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 17 Aug 1998 03:52:05 +0000 Subject: much cleaner chain pointer handling for both files and pipes. the chain pointer is now stored as a static and is set whenever a handle is created or extracted. This also makes the code less error prone. (This used to be commit 068a862982bea726e8d7b1b4065d510b9840a272) --- source3/smbd/files.c | 55 ++++++++++++++++++++++++++++++++++++-------------- source3/smbd/nttrans.c | 7 ++----- source3/smbd/pipes.c | 2 -- source3/smbd/reply.c | 53 ++++++++++++++++++++---------------------------- source3/smbd/server.c | 5 +---- source3/smbd/trans2.c | 5 ++--- 6 files changed, 67 insertions(+), 60 deletions(-) (limited to 'source3/smbd') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index bc3ea880bf..e66e53e6ed 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -35,6 +35,10 @@ static struct bitmap *fd_bmap; static files_struct *Files; +/* a fsp to use when chaining */ +static files_struct *chain_fsp = NULL; + + /* * Indirection for file fd's. Needed as POSIX locking * is based on file/process, not fd/process. @@ -106,6 +110,8 @@ files_struct *file_new(void ) DEBUG(5,("allocated file structure %d (%d used)\n", i, files_used)); + + chain_fsp = fsp; return fsp; } @@ -237,21 +243,6 @@ void file_init(void) } -/**************************************************************************** -find a fsp given a fnum -****************************************************************************/ -files_struct *file_fsp(int fnum) -{ - files_struct *fsp; - - for (fsp=Files;fsp;fsp=fsp->next) { - if (fsp->fnum == fnum) return fsp; - } - - return NULL; -} - - /**************************************************************************** close files open by a specified vuid ****************************************************************************/ @@ -375,5 +366,39 @@ void file_free(files_struct *fsp) information */ memset(fsp, 0, sizeof(*fsp)); + if (fsp == chain_fsp) chain_fsp = NULL; + free(fsp); } + + +/**************************************************************************** +get a fsp from a packet given the offset of a 16 bit fnum +****************************************************************************/ +files_struct *file_fsp(char *buf, int where) +{ + int fnum; + files_struct *fsp; + + if (chain_fsp) return chain_fsp; + + fnum = SVAL(buf, where); + + for (fsp=Files;fsp;fsp=fsp->next) { + if (fsp->fnum == fnum) { + chain_fsp = fsp; + return fsp; + } + } + + return NULL; +} + + +/**************************************************************************** +reset the chained fsp - done at the start of a packet reply +****************************************************************************/ +void file_chain_reset(void) +{ + chain_fsp = NULL; +} diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c index 31bfac25c8..89efd7ccd7 100644 --- a/source3/smbd/nttrans.c +++ b/source3/smbd/nttrans.c @@ -24,7 +24,6 @@ extern int DEBUGLEVEL; extern int Protocol; -extern files_struct *chain_fsp; extern int Client; extern int oplock_sock; extern int smb_read_error; @@ -665,8 +664,6 @@ int reply_ntcreate_and_X(connection_struct *conn, SCVAL(p,0,fsp->is_directory ? 1 : 0); } - chain_fsp = fsp; - DEBUG(5,("reply_ntcreate_and_X: open name = %s\n", fsp?fsp->fsp_name:"NULL")); @@ -941,7 +938,7 @@ static int call_nt_transact_rename(connection_struct *conn, { char *params = *ppparams; pstring new_name; - files_struct *fsp = GETFSP(params, 0); + files_struct *fsp = file_fsp(params, 0); BOOL replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False; uint32 fname_len = MIN((((uint32)IVAL(inbuf,smb_nt_TotalParameterCount)-4)), ((uint32)sizeof(new_name)-1)); @@ -1166,7 +1163,7 @@ static int call_nt_transact_notify_change(connection_struct *conn, change_notify_buf *cnbp; struct stat st; - fsp = GETFSP(setup,4); + fsp = file_fsp(setup,4); DEBUG(3,("call_nt_transact_notify_change\n")); diff --git a/source3/smbd/pipes.c b/source3/smbd/pipes.c index 84e31894a3..fed5c2bd17 100644 --- a/source3/smbd/pipes.c +++ b/source3/smbd/pipes.c @@ -138,8 +138,6 @@ int reply_pipe_read_and_X(char *inbuf,char *outbuf,int length,int bufsize) DEBUG(3,("readX pnum=%04x min=%d max=%d nread=%d\n", p->pnum, smb_mincnt, smb_maxcnt, nread)); - set_chain_p(p); - return chain_reply(inbuf,outbuf,length,bufsize); } /**************************************************************************** diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index e62c0bd576..6b91d9d152 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -33,7 +33,6 @@ extern int Protocol; extern int DEBUGLEVEL; extern int max_send; extern int max_recv; -extern files_struct *chain_fsp; extern char magic_char; extern BOOL case_sensitive; extern BOOL case_preserve; @@ -1425,8 +1424,6 @@ int reply_open_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt SSVAL(outbuf,smb_vwv8,rmode); SSVAL(outbuf,smb_vwv11,smb_action); - chain_fsp = fsp; - return chain_reply(inbuf,outbuf,length,bufsize); } @@ -1773,7 +1770,7 @@ int reply_readbraw(connection_struct *conn, char *inbuf, char *outbuf, int dum_s return -1; } - fsp = GETFSP(inbuf,smb_vwv0); + fsp = file_fsp(inbuf,smb_vwv0); startpos = IVAL(inbuf,smb_vwv1); maxcount = SVAL(inbuf,smb_vwv3); @@ -1862,7 +1859,7 @@ int reply_lockread(connection_struct *conn, char *inbuf,char *outbuf, int dum_si uint32 startpos, numtoread; int eclass; uint32 ecode; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); CHECK_FSP(fsp,conn); CHECK_READ(fsp); @@ -1905,7 +1902,7 @@ int reply_read(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, char *data; uint32 startpos; int outsize = 0; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); CHECK_FSP(fsp,conn); CHECK_READ(fsp); @@ -1945,7 +1942,7 @@ int reply_read(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, ****************************************************************************/ int reply_read_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) { - files_struct *fsp = GETFSP(inbuf,smb_vwv2); + files_struct *fsp = file_fsp(inbuf,smb_vwv2); uint32 smb_offs = IVAL(inbuf,smb_vwv3); int smb_maxcnt = SVAL(inbuf,smb_vwv5); int smb_mincnt = SVAL(inbuf,smb_vwv6); @@ -1979,8 +1976,6 @@ int reply_read_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt DEBUG( 3, ( "readX fnum=%d min=%d max=%d nread=%d\n", fsp->fnum, smb_mincnt, smb_maxcnt, nread ) ); - chain_fsp = fsp; - return chain_reply(inbuf,outbuf,length,bufsize); } @@ -1998,7 +1993,7 @@ int reply_writebraw(connection_struct *conn, char *inbuf,char *outbuf, int dum_s char *data=NULL; BOOL write_through; int tcount; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); CHECK_FSP(fsp,conn); CHECK_WRITE(fsp); @@ -2100,7 +2095,7 @@ int reply_writeunlock(connection_struct *conn, char *inbuf,char *outbuf, int dum uint32 numtowrite,startpos; int eclass; uint32 ecode; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); CHECK_FSP(fsp,conn); CHECK_WRITE(fsp); @@ -2153,7 +2148,7 @@ int reply_write(connection_struct *conn, char *inbuf,char *outbuf,int dum_size,i int outsize = 0; int startpos; char *data; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); CHECK_FSP(fsp,conn); CHECK_WRITE(fsp); @@ -2203,7 +2198,7 @@ int reply_write(connection_struct *conn, char *inbuf,char *outbuf,int dum_size,i ****************************************************************************/ int reply_write_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) { - files_struct *fsp = GETFSP(inbuf,smb_vwv2); + files_struct *fsp = file_fsp(inbuf,smb_vwv2); uint32 smb_offs = IVAL(inbuf,smb_vwv3); int smb_dsize = SVAL(inbuf,smb_vwv10); int smb_doff = SVAL(inbuf,smb_vwv11); @@ -2246,8 +2241,6 @@ int reply_write_and_X(connection_struct *conn, char *inbuf,char *outbuf,int leng DEBUG(3,("writeX fnum=%d num=%d wrote=%d\n", fsp->fnum, smb_dsize, nwritten)); - chain_fsp = fsp; - if (lp_syncalways(SNUM(conn)) || write_through) sync_file(conn,fsp); @@ -2264,7 +2257,7 @@ int reply_lseek(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int32 res= -1; int mode,umode; int outsize = 0; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); CHECK_FSP(fsp,conn); CHECK_ERROR(fsp); @@ -2300,7 +2293,7 @@ int reply_lseek(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int reply_flush(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { int outsize = set_message(outbuf,0,0,True); - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); if (fsp) { CHECK_FSP(fsp,conn); @@ -2349,7 +2342,7 @@ int reply_close(connection_struct *conn, return reply_pipe_close(conn, inbuf,outbuf); } - fsp = GETFSP(inbuf,smb_vwv0); + fsp = file_fsp(inbuf,smb_vwv0); /* * We can only use CHECK_FSP if we know it's not a directory. @@ -2406,7 +2399,7 @@ int reply_writeclose(connection_struct *conn, int startpos; char *data; time_t mtime; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); CHECK_FSP(fsp,conn); CHECK_WRITE(fsp); @@ -2452,7 +2445,7 @@ int reply_lock(connection_struct *conn, uint32 count,offset; int eclass; uint32 ecode; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); CHECK_FSP(fsp,conn); CHECK_ERROR(fsp); @@ -2479,7 +2472,7 @@ int reply_unlock(connection_struct *conn, char *inbuf,char *outbuf, int dum_size uint32 count,offset; int eclass; uint32 ecode; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); CHECK_FSP(fsp,conn); CHECK_ERROR(fsp); @@ -2629,7 +2622,7 @@ int reply_printclose(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { int outsize = set_message(outbuf,0,0,True); - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); CHECK_FSP(fsp,conn); CHECK_ERROR(fsp); @@ -2724,7 +2717,7 @@ int reply_printwrite(connection_struct *conn, char *inbuf,char *outbuf, int dum_ int numtowrite; int outsize = set_message(outbuf,0,0,True); char *data; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); if (!CAN_PRINT(conn)) return(ERROR(ERRDOS,ERRnoaccess)); @@ -3490,7 +3483,7 @@ int reply_setdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size ****************************************************************************/ int reply_lockingX(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) { - files_struct *fsp = GETFSP(inbuf,smb_vwv2); + files_struct *fsp = file_fsp(inbuf,smb_vwv2); unsigned char locktype = CVAL(inbuf,smb_vwv3); #if 0 unsigned char oplocklevel = CVAL(inbuf,smb_vwv3+1); @@ -3606,8 +3599,6 @@ dev = %x, inode = %x\n", DEBUG( 3, ( "lockingX fnum=%d type=%d num_locks=%d num_ulocks=%d\n", fsp->fnum, (unsigned int)locktype, num_locks, num_ulocks ) ); - chain_fsp = fsp; - return chain_reply(inbuf,outbuf,length,bufsize); } @@ -3625,7 +3616,7 @@ int reply_readbmpx(connection_struct *conn, char *inbuf,char *outbuf,int length, int max_per_packet; int tcount; int pad; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); /* this function doesn't seem to work - disable by default */ if (!lp_readbmpx()) @@ -3692,7 +3683,7 @@ int reply_writebmpx(connection_struct *conn, char *inbuf,char *outbuf, int dum_s uint32 startpos; int tcount, write_through, smb_doff; char *data; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); CHECK_FSP(fsp,conn); CHECK_WRITE(fsp); @@ -3785,7 +3776,7 @@ int reply_writebs(connection_struct *conn, char *inbuf,char *outbuf, int dum_siz char *data; write_bmpx_struct *wbms; BOOL send_response = False; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); CHECK_FSP(fsp,conn); CHECK_WRITE(fsp); @@ -3859,7 +3850,7 @@ int reply_setattrE(connection_struct *conn, char *inbuf,char *outbuf, int dum_si { struct utimbuf unix_times; int outsize = 0; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); outsize = set_message(outbuf,0,0,True); @@ -3912,7 +3903,7 @@ int reply_getattrE(connection_struct *conn, char *inbuf,char *outbuf, int dum_si struct stat sbuf; int outsize = 0; int mode; - files_struct *fsp = GETFSP(inbuf,smb_vwv0); + files_struct *fsp = file_fsp(inbuf,smb_vwv0); outsize = set_message(outbuf,11,0,True); diff --git a/source3/smbd/server.c b/source3/smbd/server.c index e6117000a4..f160b590dc 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -81,9 +81,6 @@ int max_send = BUFFER_SIZE; */ int max_recv = BUFFER_SIZE; -/* a fsp to use when chaining */ -files_struct *chain_fsp = NULL; - /* number of open connections */ static int num_connections_open = 0; @@ -4699,7 +4696,7 @@ int construct_reply(char *inbuf,char *outbuf,int size,int bufsize) smb_last_time = time(NULL); chain_size = 0; - chain_fsp = NULL; + file_chain_reset(); reset_chain_p(); if (msg_type != 0) diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 72ad7ec12b..2789282771 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -32,7 +32,6 @@ extern int oplock_sock; extern int smb_read_error; extern fstring local_machine; extern int global_oplock_break; -extern files_struct *chain_fsp; /**************************************************************************** Send the required number of replies back. @@ -1209,7 +1208,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, BOOL bad_path = False; if (tran_call == TRANSACT2_QFILEINFO) { - files_struct *fsp = GETFSP(params,0); + files_struct *fsp = file_fsp(params,0); info_level = SVAL(params,2); CHECK_FSP(fsp,conn); @@ -1434,7 +1433,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, return(ERROR(ERRSRV,ERRaccess)); if (tran_call == TRANSACT2_SETFILEINFO) { - files_struct *fsp = GETFSP(params,0); + files_struct *fsp = file_fsp(params,0); info_level = SVAL(params,2); CHECK_FSP(fsp,conn); -- cgit