From 00a20ce45f11e62470e60a8d5fcacc6b0b1f90a2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 5 Dec 2002 04:00:16 +0000 Subject: The element in fsp->print_job should be a RAP jobid, not a uint32 RPC jobid. This was causing Win9x client "set name" calls to fail. Still need one cleanup fix to finish. Jeremy. (This used to be commit 6c23d2030ab8dddff4c849903c529f0012b94027) --- source3/include/smb.h | 2 +- source3/printing/printfsp.c | 22 +++++++++++++++++++--- source3/printing/printing.c | 28 ++++++++++++++++++++++++---- source3/smbd/fileio.c | 15 +++++++++++++-- source3/smbd/reply.c | 3 +-- source3/smbd/trans2.c | 5 +---- 6 files changed, 59 insertions(+), 16 deletions(-) (limited to 'source3') diff --git a/source3/include/smb.h b/source3/include/smb.h index 07b3150054..de0f10b3c5 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -360,7 +360,7 @@ typedef struct files_struct int fnum; struct connection_struct *conn; int fd; - uint32 print_jobid; + uint16 rap_print_jobid; SMB_DEV_T dev; SMB_INO_T inode; BOOL delete_on_close; diff --git a/source3/printing/printfsp.c b/source3/printing/printfsp.c index 8a4e7ea073..4ae74e27ec 100644 --- a/source3/printing/printfsp.c +++ b/source3/printing/printfsp.c @@ -52,8 +52,15 @@ files_struct *print_fsp_open(connection_struct *conn, char *fname) return NULL; } + /* Convert to RAP id. */ + fsp->rap_print_jobid = pjobid_to_rap(SNUM(conn), jobid); + if (fsp->rap_print_jobid == 0) { + /* We need to delete the entry in the tdb here ! FIXME ! JRA */ + file_free(fsp); + return NULL; + } + /* setup a full fsp */ - fsp->print_jobid = jobid; fsp->fd = print_job_fd(SNUM(conn),jobid); GetTimeOfDay(&fsp->open_time); fsp->vuid = current_user.vuid; @@ -88,6 +95,9 @@ print a file - called on closing the file ****************************************************************************/ void print_fsp_end(files_struct *fsp, BOOL normal_close) { + uint32 jobid; + int snum; + if (fsp->share_mode == FILE_DELETE_ON_CLOSE) { /* * Truncate the job. print_job_end will take @@ -96,9 +106,15 @@ void print_fsp_end(files_struct *fsp, BOOL normal_close) sys_ftruncate(fsp->fd, 0); } - print_job_end(SNUM(fsp->conn),fsp->print_jobid, normal_close); - if (fsp->fsp_name) { string_free(&fsp->fsp_name); } + + if (!rap_to_pjobid(fsp->rap_print_jobid, &snum, &jobid)) { + DEBUG(3,("print_fsp_end: Unable to convert RAP jobid %u to print jobid.\n", + (unsigned int)fsp->rap_print_jobid )); + return; + } + + print_job_end(SNUM(fsp->conn),jobid, normal_close); } diff --git a/source3/printing/printing.c b/source3/printing/printing.c index a6b5e5cb83..6c70b3deae 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -53,6 +53,8 @@ uint16 pjobid_to_rap(int snum, uint32 jobid) TDB_DATA data, key; char jinfo[8]; + DEBUG(10,("pjobid_to_rap: called.\n")); + if (!rap_tdb) { /* Create the in-memory tdb. */ rap_tdb = tdb_open_log(NULL, 0, TDB_INTERNAL, (O_RDWR|O_CREAT), 0644); @@ -80,13 +82,18 @@ uint16 pjobid_to_rap(int snum, uint32 jobid) data.dsize = sizeof(rap_jobid); tdb_store(rap_tdb, key, data, TDB_REPLACE); tdb_store(rap_tdb, data, key, TDB_REPLACE); + + DEBUG(10,("pjobid_to_rap: jobid %u maps to RAP jobid %u\n", + (unsigned int)jobid, + (unsigned int)rap_jobid)); return rap_jobid; } BOOL rap_to_pjobid(uint16 rap_jobid, int *psnum, uint32 *pjobid) { TDB_DATA data, key; - char jinfo[8]; + + DEBUG(10,("rap_to_pjobid called.\n")); if (!rap_tdb) return False; @@ -94,12 +101,18 @@ BOOL rap_to_pjobid(uint16 rap_jobid, int *psnum, uint32 *pjobid) key.dptr = (char *)&rap_jobid; key.dsize = sizeof(rap_jobid); data = tdb_fetch(rap_tdb, key); - if (data.dptr && data.dsize == sizeof(jinfo)) { - *psnum = IVAL(&jinfo,0); - *pjobid = IVAL(&jinfo,4); + if (data.dptr && data.dsize == 8) { + *psnum = IVAL(data.dptr,0); + *pjobid = IVAL(data.dptr,4); + DEBUG(10,("rap_to_pjobid: jobid %u maps to RAP jobid %u\n", + (unsigned int)*pjobid, + (unsigned int)rap_jobid)); SAFE_FREE(data.dptr); return True; } + + DEBUG(10,("rap_to_pjobid: Failed to lookup RAP jobid %u\n", + (unsigned int)rap_jobid)); SAFE_FREE(data.dptr); return False; } @@ -110,6 +123,8 @@ static void rap_jobid_delete(int snum, uint32 jobid) uint16 rap_jobid; char jinfo[8]; + DEBUG(10,("rap_jobid_delete: called.\n")); + if (!rap_tdb) return; @@ -120,10 +135,15 @@ static void rap_jobid_delete(int snum, uint32 jobid) key.dsize = sizeof(jinfo); data = tdb_fetch(rap_tdb, key); if (!data.dptr || (data.dsize != sizeof(uint16))) { + DEBUG(10,("rap_jobid_delete: cannot find jobid %u\n", + (unsigned int)jobid )); SAFE_FREE(data.dptr); return; } + DEBUG(10,("rap_jobid_delete: deleting jobid %u\n", + (unsigned int)jobid )); + memcpy(&rap_jobid, data.dptr, sizeof(uint16)); SAFE_FREE(data.dptr); data.dptr = (char *)&rap_jobid; diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c index 9e37b951e5..b612b1a451 100644 --- a/source3/smbd/fileio.c +++ b/source3/smbd/fileio.c @@ -158,8 +158,19 @@ ssize_t write_file(files_struct *fsp, char *data, SMB_OFF_T pos, size_t n) ssize_t total_written = 0; int write_path = -1; - if (fsp->print_file) - return print_job_write(SNUM(fsp->conn), fsp->print_jobid, data, n); + if (fsp->print_file) { + int snum; + uint32 jobid; + + if (!rap_to_pjobid(fsp->rap_print_jobid, &snum, &jobid)) { + DEBUG(3,("write_file: Unable to map RAP jobid %u to jobid.\n", + (unsigned int)fsp->rap_print_jobid )); + errno = EBADF; + return -1; + } + + return print_job_write(SNUM(fsp->conn), jobid, data, n); + } if (!fsp->can_write) { errno = EPERM; diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 6c2698c297..96b7692b1a 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -353,8 +353,7 @@ int reply_ioctl(connection_struct *conn, switch (ioctl_code) { case IOCTL_QUERY_JOB_INFO: { - uint16 rap_jobid = pjobid_to_rap(SNUM(fsp->conn), fsp->print_jobid); - SSVAL(p,0,rap_jobid); /* Job number */ + SSVAL(p,0,fsp->rap_print_jobid); /* Job number */ srvstr_push(outbuf, p+2, global_myname(), 15, STR_TERMINATE|STR_ASCII); srvstr_push(outbuf, p+18, lp_servicename(SNUM(conn)), 13, STR_TERMINATE|STR_ASCII); break; diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index d83596d68f..872e33c832 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -3006,8 +3006,6 @@ static int call_trans2ioctl(connection_struct *conn, char* inbuf, if ((SVAL(inbuf,(smb_setup+4)) == LMCAT_SPL) && (SVAL(inbuf,(smb_setup+6)) == LMFUNC_GETJOBID)) { - uint16 rap_jobid; - pdata = Realloc(*ppdata, 32); if(pdata == NULL) return ERROR_DOS(ERRDOS,ERRnomem); @@ -3016,8 +3014,7 @@ static int call_trans2ioctl(connection_struct *conn, char* inbuf, /* NOTE - THIS IS ASCII ONLY AT THE MOMENT - NOT SURE IF OS/2 CAN ACCEPT THIS IN UNICODE. JRA. */ - rap_jobid = pjobid_to_rap(SNUM(fsp->conn), fsp->print_jobid); /* Job number */ - SSVAL(pdata,0,rap_jobid); /* Job number */ + SSVAL(pdata,0,fsp->rap_print_jobid); /* Job number */ srvstr_push( outbuf, pdata + 2, global_myname(), 15, STR_ASCII|STR_TERMINATE); /* Our NetBIOS name */ srvstr_push( outbuf, pdata+18, lp_servicename(SNUM(conn)), 13, STR_ASCII|STR_TERMINATE); /* Service name */ send_trans2_replies(outbuf,bufsize,*pparams,0,*ppdata,32); -- cgit