[comp.os.os2.programmer] How to change userid of spooled file

gould@pilot.njin.net (Brian Jay Gould) (01/03/91)

I am fairly new at programming OS2 and Lan Manager 2.0. (actually
I am reluctant to be programming at all..:-) )  I am attempting
to force a print job to have a different owner id on the console
and banner page.  I tried doing a DosPrintSetInfo with level 1.  
Although I get back a zero status, nothing changes.

I'm willing to have another program on the print server change the
SHD file, but I need to put the new information into it somewhere.  I 
tried stuffing the information in by changing szCommend in the 
PRJINFO structure, but I don't see any new information in the SHD
file.

There appears to be a problem with DosPrintGetInfo.  I use the structure
for PRJINFO level one provided by pmspl.h, but the structure is three
bytes too small.  The DLL responds that it has three more bytes to return.
Otherwise, everything looks OK.

What am I doing wrong?

On another note, DosPrintGetInfo will return an 87 on a bad argument.  It
isn't documented.

One last question:  When do you use spool versus pmspl?

Thanks for any advice in advance...
-- 
--
Any disclaimers made for me, by me, or about me - may or may not accurately
reflect my failure to be reflecting the opinions of myself or anyone else.
*************************************************
*  Brian Jay Gould - Professional Brain-stormer *
*************************************************

beng@microsoft.UUCP (Ben Goetter (beng, 1/2154, x68609)) (01/08/91)

In article <Jan.2.22.19.12.1991.18407@pilot.njin.net>
           gould@pilot.njin.net (Brian Jay Gould) writes:
|
| I am attempting
| to force a print job to have a different owner id on the console
| and banner page.  I tried doing a DosPrintSetInfo with level 1.  
| Although I get back a zero status, nothing changes.

You're trying to change the username?  No API support for that, I'm
afraid; that would constitute a minor security breach.  Now, you can
change the return-notification name, if that would suffice.  (Maybe I
don't understand what you're trying to do.)

Here's how to change the return-notification name (the messaging-alias
which will be pestered as the job changes status).  Note that you don't
have to SetInfo every field in the structure - only that one which you
want to change.  Hence the final argument to the API call, which specifies
which parameter you're targeting:

	pbData = "NEWNAME"; // point to buffer containing data.
			    // here static r-o data is just fine.
			    // please excuse gross example...
	cbData = strlen(pbData)+1;
	usErr = DosPrintJobSetInfo(pszServer, usJob, 0,
	                           pbData, cbData, PRJ_NOTIFYNAME_PARMNUM);

|
| I'm willing to have another program on the print server change the
| SHD file, but I need to put the new information into it somewhere.  I 
| tried stuffing the information in by changing szCommend in the 
| PRJINFO structure, but I don't see any new information in the SHD
| file.

Again, to change the comment on a job in the queue:

	pbData = "I am a glorious new comment"; // same caveat as above
	cbData = strlen(pbData)+1;
	usErr = DosPrintJobSetInfo(pszServer, usJob, 0,
	                           pbData, cbData, PRJ_COMMENT_PARMNUM);

Through the API, you can change the notification name, the job
comment, the data type string, the parameters string, the position of
the job within the queue, the print job's priority, the job's document
name, the parameters to the queue processor, and something called the
"default driver name" which I don't feel like looking up in Richard
Scarry's Big Book of Presentation Manager Fun - but not the username.

|
| There appears to be a problem with DosPrintGetInfo.  I use the structure
| for PRJINFO level one provided by pmspl.h, but the structure is three
| bytes too small.  The DLL responds that it has three more bytes to return.
| Otherwise, everything looks OK.

If you examine the definition of PRJINFO, you'll see that it contains
several char-pointer fields - three of them, in fact.  These fields I would
guess want to point to empty strings; however, your application hasn't
given the API sufficient room to add them.

When you GetInfo, you need to give the API more room than just that
of the info-struct; you also need to allow sufficient room for any
variable-length data which the API might pass back to you (such as the
three strings in a level-0 printjobgetinfo).  One easy way to do this,
at the expense of an extra net call, is to call the API twice: the
first time with a cbData of 0, the second time with the value you
got back as *pcbTotal the first time:

	cbTotal = 0;
	usErr = DosPrintJobGetInfo(pszServer, usJob, 0, NULL, 0, &cbTotal);
	if (usErr != 0 && usErr != NERR_BufTooSmall)
	    go do something about it;
	cbData = cbTotal;
	pbData = malloc(cbData);
	if (pbData == NULL)
	    whine and moan;
	usErr = DosPrintJobGetInfo(pszServer, usJob, 0,
				   pbData, cbData, &cbTotal);
	...

This gives you major portability wins should some infostructure ever
change size, removes path-length dependencies from your code, etc.

Once you have your pbData full of information, you can reference the info
structure out of it:

	PRJINFO * pprji = (PRJINFO *)pbData;

Now when you ask for pprji->pszComment, you also have the data area
into which that pointer must point.

| 
| On another note, DosPrintGetInfo will return an 87 on a bad argument.  It
| isn't documented.

All the Lanman APIs will return ERROR_BAD_PARAMETER (87) if you give them
a bogus argument.  Unfortunately, they don't indicate which argument they
have found displeasing....

(What doc are you using?)

| 
| One last question:  When do you use spool versus pmspl?

Use <spool.h> for backward compatibility with apps written to the LM 1.0 API.
New code should use <pmspl.h> (or its Dos Lanman equivalent <dospmspl.h>).

Hope this helps somewhat.

--
Ben Goetter
microsoft!beng