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

r24102: Pass the fid instead of inbuf and an offset to file_fsp.

This removes the buf==NULL condition in file_fsp(), but wherever it is called
we do have a buffer anyway.

Volker
(This used to be commit d70a1f82fe)
This commit is contained in:
Volker Lendecke 2007-07-31 12:05:40 +00:00 committed by Gerald (Jerry) Carter
parent 3d769de244
commit a2d6aa829f
4 changed files with 38 additions and 42 deletions

View File

@ -487,7 +487,7 @@ files_struct *file_fnum(uint16 fnum)
Get an fsp from a packet given the offset of a 16 bit fnum. Get an fsp from a packet given the offset of a 16 bit fnum.
****************************************************************************/ ****************************************************************************/
files_struct *file_fsp(const char *buf, int where) files_struct *file_fsp(uint16 fid)
{ {
files_struct *fsp; files_struct *fsp;
@ -495,11 +495,7 @@ files_struct *file_fsp(const char *buf, int where)
return chain_fsp; return chain_fsp;
} }
if (!buf) { fsp = file_fnum(fid);
return NULL;
}
fsp = file_fnum(SVAL(buf, where));
if (fsp) { if (fsp) {
chain_fsp = fsp; chain_fsp = fsp;
} }

View File

@ -619,7 +619,7 @@ void reply_ntcreate_and_X(connection_struct *conn,
*/ */
pstring rel_fname; pstring rel_fname;
files_struct *dir_fsp = file_fsp( files_struct *dir_fsp = file_fsp(
(char *)req->inbuf, smb_ntcreate_RootDirectoryFid); SVAL(req->inbuf, smb_ntcreate_RootDirectoryFid));
size_t dir_name_len; size_t dir_name_len;
if(!dir_fsp) { if(!dir_fsp) {
@ -1377,7 +1377,7 @@ static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *o
/* /*
* This filename is relative to a directory fid. * This filename is relative to a directory fid.
*/ */
files_struct *dir_fsp = file_fsp(params,4); files_struct *dir_fsp = file_fsp(SVAL(params,4));
size_t dir_name_len; size_t dir_name_len;
if(!dir_fsp) { if(!dir_fsp) {
@ -2078,7 +2078,7 @@ static int call_nt_transact_notify_change(connection_struct *conn, char *inbuf,
return ERROR_DOS(ERRDOS,ERRbadfunc); return ERROR_DOS(ERRDOS,ERRbadfunc);
} }
fsp = file_fsp((char *)setup,4); fsp = file_fsp(SVAL(setup,4));
filter = IVAL(setup, 0); filter = IVAL(setup, 0);
recursive = (SVAL(setup, 6) != 0) ? True : False; recursive = (SVAL(setup, 6) != 0) ? True : False;
@ -2173,7 +2173,7 @@ static int call_nt_transact_rename(connection_struct *conn, char *inbuf, char *o
return ERROR_DOS(ERRDOS,ERRbadfunc); return ERROR_DOS(ERRDOS,ERRbadfunc);
} }
fsp = file_fsp(params, 0); fsp = file_fsp(SVAL(params, 0));
replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False; replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
CHECK_FSP(fsp, conn); CHECK_FSP(fsp, conn);
srvstr_get_path_wcard(inbuf, SVAL(inbuf,smb_flg2), new_name, params+4, srvstr_get_path_wcard(inbuf, SVAL(inbuf,smb_flg2), new_name, params+4,
@ -2244,7 +2244,7 @@ static int call_nt_transact_query_security_desc(connection_struct *conn, char *i
return ERROR_DOS(ERRDOS,ERRbadfunc); return ERROR_DOS(ERRDOS,ERRbadfunc);
} }
fsp = file_fsp(params,0); fsp = file_fsp(SVAL(params,0));
if(!fsp) { if(!fsp) {
return ERROR_DOS(ERRDOS,ERRbadfid); return ERROR_DOS(ERRDOS,ERRbadfid);
} }
@ -2358,7 +2358,7 @@ static int call_nt_transact_set_security_desc(connection_struct *conn, char *inb
return ERROR_DOS(ERRDOS,ERRbadfunc); return ERROR_DOS(ERRDOS,ERRbadfunc);
} }
if((fsp = file_fsp(params,0)) == NULL) { if((fsp = file_fsp(SVAL(params,0))) == NULL) {
return ERROR_DOS(ERRDOS,ERRbadfid); return ERROR_DOS(ERRDOS,ERRbadfid);
} }
@ -2415,7 +2415,7 @@ static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *ou
DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n", DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
function, fidnum, isFSctl, compfilter)); function, fidnum, isFSctl, compfilter));
fsp=file_fsp((char *)*ppsetup, 4); fsp=file_fsp(SVAL(ppsetup, 4));
/* this check is done in each implemented function case for now /* this check is done in each implemented function case for now
because I don't want to break anything... --metze because I don't want to break anything... --metze
FSP_BELONGS_CONN(fsp,conn);*/ FSP_BELONGS_CONN(fsp,conn);*/
@ -2693,7 +2693,7 @@ static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf,
} }
/* maybe we can check the quota_fnum */ /* maybe we can check the quota_fnum */
fsp = file_fsp(params,0); fsp = file_fsp(SVAL(params,0));
if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) { if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n")); DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
return ERROR_NT(NT_STATUS_INVALID_HANDLE); return ERROR_NT(NT_STATUS_INVALID_HANDLE);
@ -2941,7 +2941,7 @@ static int call_nt_transact_set_user_quota(connection_struct *conn, char *inbuf,
} }
/* maybe we can check the quota_fnum */ /* maybe we can check the quota_fnum */
fsp = file_fsp(params,0); fsp = file_fsp(SVAL(params,0));
if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) { if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n")); DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
return ERROR_NT(NT_STATUS_INVALID_HANDLE); return ERROR_NT(NT_STATUS_INVALID_HANDLE);

View File

@ -709,7 +709,7 @@ int reply_ioctl(connection_struct *conn,
switch (ioctl_code) { switch (ioctl_code) {
case IOCTL_QUERY_JOB_INFO: case IOCTL_QUERY_JOB_INFO:
{ {
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
if (!fsp) { if (!fsp) {
END_PROFILE(SMBioctl); END_PROFILE(SMBioctl);
return(UNIXERROR(ERRDOS,ERRbadfid)); return(UNIXERROR(ERRDOS,ERRbadfid));
@ -2433,7 +2433,7 @@ int reply_readbraw(connection_struct *conn, char *inbuf, char *outbuf, int dum_s
* return a zero length response here. * return a zero length response here.
*/ */
fsp = file_fsp(inbuf,smb_vwv0); fsp = file_fsp(SVAL(inbuf,smb_vwv0));
if (!FNUM_OK(fsp,conn) || !fsp->can_read) { if (!FNUM_OK(fsp,conn) || !fsp->can_read) {
/* /*
@ -2538,7 +2538,7 @@ int reply_lockread(connection_struct *conn, char *inbuf,char *outbuf, int length
SMB_OFF_T startpos; SMB_OFF_T startpos;
size_t numtoread; size_t numtoread;
NTSTATUS status; NTSTATUS status;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
struct byte_range_lock *br_lck = NULL; struct byte_range_lock *br_lck = NULL;
START_PROFILE(SMBlockread); START_PROFILE(SMBlockread);
@ -2624,7 +2624,7 @@ int reply_read(connection_struct *conn, char *inbuf,char *outbuf, int size, int
char *data; char *data;
SMB_OFF_T startpos; SMB_OFF_T startpos;
int outsize = 0; int outsize = 0;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
START_PROFILE(SMBread); START_PROFILE(SMBread);
CHECK_FSP(fsp,conn); CHECK_FSP(fsp,conn);
@ -2827,7 +2827,7 @@ normal_read:
int reply_read_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) int reply_read_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize)
{ {
files_struct *fsp = file_fsp(inbuf,smb_vwv2); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv2));
SMB_OFF_T startpos = IVAL_TO_SMB_OFF_T(inbuf,smb_vwv3); SMB_OFF_T startpos = IVAL_TO_SMB_OFF_T(inbuf,smb_vwv3);
ssize_t nread = -1; ssize_t nread = -1;
size_t smb_maxcnt = SVAL(inbuf,smb_vwv5); size_t smb_maxcnt = SVAL(inbuf,smb_vwv5);
@ -2928,7 +2928,7 @@ int reply_writebraw(connection_struct *conn, char *inbuf,char *outbuf, int size,
SMB_OFF_T startpos; SMB_OFF_T startpos;
char *data=NULL; char *data=NULL;
BOOL write_through; BOOL write_through;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
int outsize = 0; int outsize = 0;
NTSTATUS status; NTSTATUS status;
START_PROFILE(SMBwritebraw); START_PROFILE(SMBwritebraw);
@ -3079,7 +3079,7 @@ int reply_writeunlock(connection_struct *conn, char *inbuf,char *outbuf,
SMB_OFF_T startpos; SMB_OFF_T startpos;
char *data; char *data;
NTSTATUS status = NT_STATUS_OK; NTSTATUS status = NT_STATUS_OK;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
int outsize = 0; int outsize = 0;
START_PROFILE(SMBwriteunlock); START_PROFILE(SMBwriteunlock);
@ -3157,7 +3157,7 @@ int reply_write(connection_struct *conn, char *inbuf,char *outbuf,int size,int d
ssize_t nwritten = -1; ssize_t nwritten = -1;
SMB_OFF_T startpos; SMB_OFF_T startpos;
char *data; char *data;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
int outsize = 0; int outsize = 0;
NTSTATUS status; NTSTATUS status;
START_PROFILE(SMBwrite); START_PROFILE(SMBwrite);
@ -3240,7 +3240,7 @@ int reply_write(connection_struct *conn, char *inbuf,char *outbuf,int size,int d
int reply_write_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) int reply_write_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize)
{ {
files_struct *fsp = file_fsp(inbuf,smb_vwv2); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv2));
SMB_OFF_T startpos = IVAL_TO_SMB_OFF_T(inbuf,smb_vwv3); SMB_OFF_T startpos = IVAL_TO_SMB_OFF_T(inbuf,smb_vwv3);
size_t numtowrite = SVAL(inbuf,smb_vwv10); size_t numtowrite = SVAL(inbuf,smb_vwv10);
BOOL write_through = BITSETW(inbuf+smb_vwv7,0); BOOL write_through = BITSETW(inbuf+smb_vwv7,0);
@ -3362,7 +3362,7 @@ int reply_lseek(connection_struct *conn, char *inbuf,char *outbuf, int size, int
SMB_OFF_T res= -1; SMB_OFF_T res= -1;
int mode,umode; int mode,umode;
int outsize = 0; int outsize = 0;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
START_PROFILE(SMBlseek); START_PROFILE(SMBlseek);
CHECK_FSP(fsp,conn); CHECK_FSP(fsp,conn);
@ -3434,7 +3434,7 @@ int reply_flush(connection_struct *conn, char *inbuf,char *outbuf, int size, int
{ {
int outsize = set_message(inbuf,outbuf,0,0,False); int outsize = set_message(inbuf,outbuf,0,0,False);
uint16 fnum = SVAL(inbuf,smb_vwv0); uint16 fnum = SVAL(inbuf,smb_vwv0);
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
START_PROFILE(SMBflush); START_PROFILE(SMBflush);
if (fnum != 0xFFFF) if (fnum != 0xFFFF)
@ -3501,7 +3501,7 @@ void reply_close(connection_struct *conn, struct smb_request *req)
return; return;
} }
fsp = file_fsp((char *)req->inbuf,smb_vwv0); fsp = file_fsp(SVAL(req->inbuf,smb_vwv0));
/* /*
* We can only use CHECK_FSP if we know it's not a directory. * We can only use CHECK_FSP if we know it's not a directory.
@ -3570,7 +3570,7 @@ int reply_writeclose(connection_struct *conn,
SMB_OFF_T startpos; SMB_OFF_T startpos;
char *data; char *data;
struct timespec mtime; struct timespec mtime;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
START_PROFILE(SMBwriteclose); START_PROFILE(SMBwriteclose);
CHECK_FSP(fsp,conn); CHECK_FSP(fsp,conn);
@ -3637,7 +3637,7 @@ int reply_lock(connection_struct *conn,
int outsize = set_message(inbuf,outbuf,0,0,False); int outsize = set_message(inbuf,outbuf,0,0,False);
SMB_BIG_UINT count,offset; SMB_BIG_UINT count,offset;
NTSTATUS status; NTSTATUS status;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
struct byte_range_lock *br_lck = NULL; struct byte_range_lock *br_lck = NULL;
START_PROFILE(SMBlock); START_PROFILE(SMBlock);
@ -3684,7 +3684,7 @@ int reply_unlock(connection_struct *conn, char *inbuf,char *outbuf, int size,
int outsize = set_message(inbuf,outbuf,0,0,False); int outsize = set_message(inbuf,outbuf,0,0,False);
SMB_BIG_UINT count,offset; SMB_BIG_UINT count,offset;
NTSTATUS status; NTSTATUS status;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
START_PROFILE(SMBunlock); START_PROFILE(SMBunlock);
CHECK_FSP(fsp,conn); CHECK_FSP(fsp,conn);
@ -3830,7 +3830,7 @@ int reply_printclose(connection_struct *conn,
char *inbuf,char *outbuf, int dum_size, int dum_buffsize) char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
{ {
int outsize = set_message(inbuf,outbuf,0,0,False); int outsize = set_message(inbuf,outbuf,0,0,False);
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
NTSTATUS status; NTSTATUS status;
START_PROFILE(SMBsplclose); START_PROFILE(SMBsplclose);
@ -3935,7 +3935,7 @@ int reply_printwrite(connection_struct *conn, char *inbuf,char *outbuf, int dum_
int numtowrite; int numtowrite;
int outsize = set_message(inbuf,outbuf,0,0,False); int outsize = set_message(inbuf,outbuf,0,0,False);
char *data; char *data;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
START_PROFILE(SMBsplwr); START_PROFILE(SMBsplwr);
@ -5533,7 +5533,7 @@ SMB_BIG_UINT get_lock_offset( char *data, int data_offset, BOOL large_file_forma
int reply_lockingX(connection_struct *conn, char *inbuf, char *outbuf, int reply_lockingX(connection_struct *conn, char *inbuf, char *outbuf,
int length, int bufsize) int length, int bufsize)
{ {
files_struct *fsp = file_fsp(inbuf,smb_vwv2); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv2));
unsigned char locktype = CVAL(inbuf,smb_vwv3); unsigned char locktype = CVAL(inbuf,smb_vwv3);
unsigned char oplocklevel = CVAL(inbuf,smb_vwv3+1); unsigned char oplocklevel = CVAL(inbuf,smb_vwv3+1);
uint16 num_ulocks = SVAL(inbuf,smb_vwv6); uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
@ -5860,7 +5860,7 @@ int reply_readbmpx(connection_struct *conn, char *inbuf,char *outbuf,int length,
int max_per_packet; int max_per_packet;
size_t tcount; size_t tcount;
int pad; int pad;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
START_PROFILE(SMBreadBmpx); START_PROFILE(SMBreadBmpx);
/* this function doesn't seem to work - disable by default */ /* this function doesn't seem to work - disable by default */
@ -5931,7 +5931,7 @@ int reply_setattrE(connection_struct *conn, char *inbuf,char *outbuf, int size,
{ {
struct timespec ts[2]; struct timespec ts[2];
int outsize = 0; int outsize = 0;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
START_PROFILE(SMBsetattrE); START_PROFILE(SMBsetattrE);
outsize = set_message(inbuf,outbuf,0,0,False); outsize = set_message(inbuf,outbuf,0,0,False);
@ -6000,7 +6000,7 @@ int reply_writebmpx(connection_struct *conn, char *inbuf,char *outbuf, int size,
BOOL write_through; BOOL write_through;
int smb_doff; int smb_doff;
char *data; char *data;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
NTSTATUS status; NTSTATUS status;
START_PROFILE(SMBwriteBmpx); START_PROFILE(SMBwriteBmpx);
@ -6112,7 +6112,7 @@ int reply_writebs(connection_struct *conn, char *inbuf,char *outbuf, int dum_siz
char *data; char *data;
write_bmpx_struct *wbms; write_bmpx_struct *wbms;
BOOL send_response = False; BOOL send_response = False;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
NTSTATUS status; NTSTATUS status;
START_PROFILE(SMBwriteBs); START_PROFILE(SMBwriteBs);
@ -6201,7 +6201,7 @@ int reply_getattrE(connection_struct *conn, char *inbuf,char *outbuf, int size,
SMB_STRUCT_STAT sbuf; SMB_STRUCT_STAT sbuf;
int outsize = 0; int outsize = 0;
int mode; int mode;
files_struct *fsp = file_fsp(inbuf,smb_vwv0); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv0));
START_PROFILE(SMBgetattrE); START_PROFILE(SMBgetattrE);
outsize = set_message(inbuf,outbuf,11,0,True); outsize = set_message(inbuf,outbuf,11,0,True);

View File

@ -2859,7 +2859,7 @@ cap_low = 0x%x, cap_high = 0x%x\n",
* but we didn't use the last 6 bytes for now * but we didn't use the last 6 bytes for now
* --metze * --metze
*/ */
fsp = file_fsp(params,0); fsp = file_fsp(SVAL(params,0));
if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) { if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n")); DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
return ERROR_NT(NT_STATUS_INVALID_HANDLE); return ERROR_NT(NT_STATUS_INVALID_HANDLE);
@ -3341,7 +3341,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
max_data_bytes); max_data_bytes);
} }
fsp = file_fsp(params,0); fsp = file_fsp(SVAL(params,0));
info_level = SVAL(params,2); info_level = SVAL(params,2);
DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QFILEINFO: level = %d\n", info_level)); DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QFILEINFO: level = %d\n", info_level));
@ -5860,7 +5860,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn,
return ERROR_NT(NT_STATUS_INVALID_PARAMETER); return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
} }
fsp = file_fsp(params,0); fsp = file_fsp(SVAL(params,0));
info_level = SVAL(params,2); info_level = SVAL(params,2);
if(fsp && (fsp->is_directory || fsp->fh->fd == -1)) { if(fsp && (fsp->is_directory || fsp->fh->fd == -1)) {
@ -6460,7 +6460,7 @@ static int call_trans2ioctl(connection_struct *conn, char* inbuf, char* outbuf,
unsigned int max_data_bytes) unsigned int max_data_bytes)
{ {
char *pdata = *ppdata; char *pdata = *ppdata;
files_struct *fsp = file_fsp(inbuf,smb_vwv15); files_struct *fsp = file_fsp(SVAL(inbuf,smb_vwv15));
/* check for an invalid fid before proceeding */ /* check for an invalid fid before proceeding */