diff options
author | Andrew Tridgell <tridge@samba.org> | 1997-08-31 02:18:59 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1997-08-31 02:18:59 +0000 |
commit | f434139087ea45ed1eb578267843943b0f04c94c (patch) | |
tree | 573b9db9136913863364f057c7fe66c84fc7bd6d | |
parent | 06dc98f220dba6d602010df235679c6584cba279 (diff) | |
download | samba-f434139087ea45ed1eb578267843943b0f04c94c.tar.gz samba-f434139087ea45ed1eb578267843943b0f04c94c.tar.bz2 samba-f434139087ea45ed1eb578267843943b0f04c94c.zip |
fixed a bug in the printjob encoding/decoding. We weren't doing it for
the print_ functions in reply.c, with the effect that you couldn't
cancel print jobs from smbclient or from older dos clients.
we now use a couple of utility functions printjob_encode() and
printjob_decode() rather than sticking the bitops inline in each
place.
also fixed a bunch of places that used foo%0xFF rather than foo&0xFF
Note that this isn't really me doing the commit, it can't be as I'm
working on my thesis ...
(This used to be commit 3556763be3acbf01c967ee9717943dd44163fb9f)
-rw-r--r-- | source3/printing/printing.c | 24 | ||||
-rw-r--r-- | source3/smbd/ipc.c | 25 | ||||
-rw-r--r-- | source3/smbd/reply.c | 2 |
3 files changed, 34 insertions, 17 deletions
diff --git a/source3/printing/printing.c b/source3/printing/printing.c index c4dd9803eb..c83d216989 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -929,8 +929,8 @@ int get_printqueue(int snum,int cnum,print_queue_struct **queue, if (!printername || !*printername) { - DEBUG(6,("replacing printer name with service (snum=(%s,%d))\n", - lp_servicename(snum),snum)); + DEBUG(6,("xx replacing printer name with service (snum=(%s,%d))\n", + lp_servicename(snum),snum)); printername = lp_servicename(snum); } @@ -1080,3 +1080,23 @@ void status_printjob(int cnum,int snum,int jobid,int status) } + +/**************************************************************************** +we encode print job numbers over the wire so that when we get them back we can +tell not only what print job they are but also what service it belongs to, +this is to overcome the problem that windows clients tend to send the wrong +service number when doing print queue manipulation! +****************************************************************************/ +int printjob_encode(int snum, int job) +{ + return ((snum&0xFF)<<8) | (job & 0xFF); +} + +/**************************************************************************** +and now decode them again ... +****************************************************************************/ +void printjob_decode(int jobid, int *snum, int *job) +{ + (*snum) = (jobid >> 8) & 0xFF; + (*job) = jobid & 0xFF; +} diff --git a/source3/smbd/ipc.c b/source3/smbd/ipc.c index e21021c0ac..55e293d7ff 100644 --- a/source3/smbd/ipc.c +++ b/source3/smbd/ipc.c @@ -480,7 +480,7 @@ static void fill_printjob_info(int cnum, int snum, int uLevel, /* the client expects localtime */ t -= TimeDiff(t); - PACKI(desc,"W",((snum%0xFF)<<8) | (queue->job%0xFF)); /* uJobId */ + PACKI(desc,"W",printjob_encode(snum, queue->job)); /* uJobId */ if (uLevel == 1) { PACKS(desc,"B21",queue->user); /* szUserName */ PACKS(desc,"B",""); /* pad */ @@ -1405,11 +1405,10 @@ static BOOL api_RDosPrintJobDel(int cnum,uint16 vuid, char *param,char *data, char *str1 = param+2; char *str2 = skip_string(str1,1); char *p = skip_string(str2,1); - int jobid = (SVAL(p,0)&0xFF); /* the snum and jobid are encoded - by the print queue api */ - int snum = (SVAL(p,0)>>8); + int jobid, snum; int i, count; + printjob_decode(SVAL(p,0), &snum, &jobid); /* check it's a supported varient */ if (!(strcsequal(str1,"W") && strcsequal(str2,""))) @@ -1429,7 +1428,7 @@ static BOOL api_RDosPrintJobDel(int cnum,uint16 vuid, char *param,char *data, count = get_printqueue(snum,cnum,&queue,NULL); for (i=0;i<count;i++) - if ((queue[i].job%0xFF) == jobid) + if ((queue[i].job&0xFF) == jobid) { switch (function) { case 81: /* delete */ @@ -1538,13 +1537,13 @@ static BOOL api_PrintJobInfo(int cnum,uint16 vuid,char *param,char *data, char *str1 = param+2; char *str2 = skip_string(str1,1); char *p = skip_string(str2,1); - int jobid = (SVAL(p,0)&0xFF); /* the snum and jobid are encoded - by the print queue api */ - int snum = (SVAL(p,0)>>8); + int jobid, snum; int uLevel = SVAL(p,2); int function = SVAL(p,4); /* what is this ?? */ int i; char *s = data; + + printjob_decode(SVAL(p,0), &snum, &jobid); *rparam_len = 4; *rparam = REALLOC(*rparam,*rparam_len); @@ -1565,7 +1564,7 @@ static BOOL api_PrintJobInfo(int cnum,uint16 vuid,char *param,char *data, lpq_reset(snum); count = get_printqueue(snum,cnum,&queue,NULL); for (i=0;i<count;i++) /* find job */ - if ((queue[i].job%0xFF) == jobid) break; + if ((queue[i].job&0xFF) == jobid) break; if (i==count) { desc.errcode=NERR_JobNotFound; @@ -2317,7 +2316,6 @@ static BOOL api_WPrintJobGetInfo(int cnum,uint16 vuid, char *param,char *data, char *str1 = param+2; char *str2 = skip_string(str1,1); char *p = skip_string(str2,1); - int uJobId = SVAL(p,0); int uLevel,cbBuf; int count; int i; @@ -2333,20 +2331,19 @@ static BOOL api_WPrintJobGetInfo(int cnum,uint16 vuid, char *param,char *data, bzero(&desc,sizeof(desc)); bzero(&status,sizeof(status)); - DEBUG(3,("WPrintJobGetInfo uLevel=%d uJobId=0x%X\n",uLevel,uJobId)); + DEBUG(3,("WPrintJobGetInfo uLevel=%d uJobId=0x%X\n",uLevel,SVAL(p,0))); /* check it's a supported varient */ if (strcmp(str1,"WWrLh") != 0) return False; if (!check_printjob_info(&desc,uLevel,str2)) return False; - snum = (unsigned int)uJobId >> 8; /*## valid serice number??*/ - job = uJobId & 0xFF; + printjob_decode(SVAL(p,0), &snum, &job); if (snum < 0 || !VALID_SNUM(snum)) return(False); count = get_printqueue(snum,cnum,&queue,&status); for (i = 0; i < count; i++) { - if ((queue[i].job % 0xFF) == job) break; + if ((queue[i].job & 0xFF) == job) break; } if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt); desc.base = *rdata; diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index cadd63e045..4616ea14ed 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -2463,7 +2463,7 @@ int reply_printqueue(char *inbuf,char *outbuf) { put_dos_date2(p,0,queue[i].time); CVAL(p,4) = (queue[i].status==LPQ_PRINTING?2:3); - SSVAL(p,5,queue[i].job); + SSVAL(p,5,printjob_encode(SNUM(cnum), queue[i].job)); SIVAL(p,7,queue[i].size); CVAL(p,11) = 0; StrnCpy(p+12,queue[i].user,16); |