1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

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 commit is contained in:
Andrew Tridgell 0001-01-01 00:00:00 +00:00
parent 8bc2627ff2
commit 068a862982
11 changed files with 81 additions and 87 deletions

View File

@ -1857,10 +1857,9 @@ BOOL api_netlog_rpc(pipes_struct *p, prs_struct *data);
/*The following definitions come from rpc_server/srv_pipe_hnd.c */
void reset_chain_p(void);
void set_chain_p(pipes_struct *new_p);
void init_rpc_pipe_hnd(void);
pipes_struct *open_rpc_pipe_p(char *pipe_name,
connection_struct *conn, uint16 vuid);
connection_struct *conn, uint16 vuid);
int read_pipe(pipes_struct *p, char *data, uint32 pos, int n);
char *get_rpc_pipe_hnd_name(pipes_struct *p);
BOOL set_rpc_pipe_hnd_state(pipes_struct *p, uint16 device_state);
@ -1957,12 +1956,13 @@ file_fd_struct *fd_get_already_open(struct stat *sbuf);
file_fd_struct *fd_get_new(void);
void file_close_conn(connection_struct *conn);
void file_init(void);
files_struct *file_fsp(int fnum);
void file_close_user(int vuid);
files_struct *file_find_dit(int dev, int inode, struct timeval *tval);
files_struct *file_find_print(void);
void file_sync_all(connection_struct *conn);
void file_free(files_struct *fsp);
files_struct *file_fsp(char *buf, int where);
void file_chain_reset(void);
/*The following definitions come from smbd/groupname.c */

View File

@ -602,11 +602,6 @@ typedef struct files_struct
char *fsp_name;
} files_struct;
/* this macro should always be used to extract an fnum (smb_fid) from
a packet to ensure chaining works correctly */
#define GETFSP(buf,where) (chain_fsp?chain_fsp:file_fsp(SVAL(buf,where)))
/* Domain controller authentication protocol info */
struct dcinfo
{

View File

@ -26,8 +26,6 @@ extern int DEBUGLEVEL;
int num_good_sends = 0;
int num_good_receives = 0;
extern pstring scope;
extern struct in_addr ipzero;
static struct opcode_names {
char *nmb_opcode_name;

View File

@ -61,7 +61,7 @@ static ubi_slList blocking_lock_queue = { NULL, (ubi_slNodePtr)&blocking_lock_qu
BOOL push_blocking_lock_request( char *inbuf, int length, int lock_timeout, int lock_num)
{
blocking_lock_record *blr;
files_struct *fsp = GETFSP(inbuf,smb_vwv2);
files_struct *fsp = file_fsp(inbuf,smb_vwv2);
/*
* Now queue an entry on the blocking lock queue. We setup
@ -98,12 +98,11 @@ for fnum = %d, name = %s\n", blr->expire_time, fsp->fnum, fsp->name ));
static void blocking_lock_reply_success(blocking_lock_record *blr)
{
extern int chain_size;
extern files_struct *chain_fsp;
extern char *OutBuffer;
char *outbuf = OutBuffer;
int bufsize = BUFFER_SIZE;
char *inbuf = blr->inbuf;
files_struct *fsp = GETFSP(inbuf,smb_vwv2);
files_struct *fsp = file_fsp(inbuf,smb_vwv2);
int outsize = 0;
construct_reply_common(inbuf, outbuf);
@ -117,7 +116,7 @@ static void blocking_lock_reply_success(blocking_lock_record *blr)
* that here and must set up the chain info manually.
*/
chain_fsp = fsp;
file_set_chain(fsp);
chain_size = 0;
outsize = chain_reply(inbuf,outbuf,blr->length,bufsize);
@ -140,7 +139,7 @@ static void blocking_lock_reply_error(blocking_lock_record *blr, int eclass, int
char *outbuf = OutBuffer;
int bufsize = BUFFER_SIZE;
char *inbuf = blr->inbuf;
files_struct *fsp = GETFSP(inbuf,smb_vwv2);
files_struct *fsp = file_fsp(inbuf,smb_vwv2);
uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
uint16 num_locks = SVAL(inbuf,smb_vwv7);
uint32 count, offset;
@ -175,7 +174,7 @@ static BOOL blocking_lock_record_process(blocking_lock_record *blr)
{
char *inbuf = blr->inbuf;
unsigned char locktype = CVAL(inbuf,smb_vwv3);
files_struct *fsp = GETFSP(inbuf,smb_vwv2);
files_struct *fsp = file_fsp(inbuf,smb_vwv2);
uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
uint16 num_locks = SVAL(inbuf,smb_vwv7);
uint32 count, offset;
@ -250,7 +249,7 @@ void process_blocking_lock_queue(time_t t)
*/
while(blr != NULL) {
files_struct *fsp = GETFSP(blr->inbuf,smb_vwv2);
files_struct *fsp = file_fsp(blr->inbuf,smb_vwv2);
uint16 vuid = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID :
SVAL(blr->inbuf,smb_uid);

View File

@ -50,14 +50,6 @@ void reset_chain_p(void)
chain_p = NULL;
}
/****************************************************************************
sets chain pipe-file handle
****************************************************************************/
void set_chain_p(pipes_struct *new_p)
{
chain_p = new_p;
}
/****************************************************************************
initialise pipe handle states...
****************************************************************************/
@ -136,7 +128,7 @@ pipes_struct *open_rpc_pipe_p(char *pipe_name,
DEBUG(4,("Opened pipe %s with handle %x (pipes_open=%d)\n",
pipe_name, i, pipes_open));
set_chain_p(p);
chain_p = p;
return p;
}
@ -335,7 +327,10 @@ pipes_struct *get_rpc_pipe(int pnum)
pipes_struct *p;
for (p=Pipes;p;p=p->next) {
if (p->pnum == pnum) return p;
if (p->pnum == pnum) {
chain_p = p;
return p;
}
}
return NULL;

View File

@ -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;
}

View File

@ -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"));

View File

@ -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);
}
/****************************************************************************

View File

@ -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);

View File

@ -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)

View File

@ -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);