- char *rparam = NULL;
- char *rdata = NULL;
- char *p;
- int rdrcnt, rprcnt;
- pstring param;
- int result_code=0;
-
- if (!connect_as_printer)
- {
- DEBUG(0,("WARNING: You didn't use the -P option to smbclient.\n"));
- DEBUG(0,("Trying to print without -P may fail\n"));
- }
-
- bzero(param,sizeof(param));
-
- p = param;
- SSVAL(p,0,76); /* API function number 76 (DosPrintJobEnum) */
- p += 2;
- pstrcpy(p,"zWrLeh"); /* parameter description? */
- p = skip_string(p,1);
- pstrcpy(p,"WWzWWDDzz"); /* returned data format */
- p = skip_string(p,1);
- pstrcpy(p,strrchr(service,'\\')+1); /* name of queue */
- p = skip_string(p,1);
- SSVAL(p,0,2); /* API function level 2, PRJINFO_2 data structure */
- SSVAL(p,2,1000); /* size of bytes of returned data buffer */
- p += 4;
- pstrcpy(p,""); /* subformat */
- p = skip_string(p,1);
-
- DEBUG(1,("Calling DosPrintJobEnum()...\n"));
- if( cli_call_api(PIPE_LANMAN, 0,PTR_DIFF(p,param), 0, 0,
- 10, 4096,
- &rprcnt, &rdrcnt,
- param, NULL, NULL,
- &rparam, &rdata) )
- {
- int converter;
- result_code = SVAL(rparam,0);
- converter = SVAL(rparam,2); /* conversion factor */
-
- DEBUG(2,("returned %d bytes of parameters, %d bytes of data, %d records\n", rprcnt, rdrcnt, SVAL(rparam,4) ));
-
- if (result_code == 0) /* if no error, */
- {
- int i;
- uint16 JobId;
- uint16 Priority;
- uint32 Size;
- char *UserName;
- char *JobName;
- char *JobTimeStr;
- time_t JobTime;
- fstring PrinterName;
-
- fstrcpy(PrinterName,strrchr(service,'\\')+1); /* name of queue */
- strlower(PrinterName); /* in lower case */
-
- p = rdata; /* received data */
- for( i = 0; i < SVAL(rparam,4); ++i)
- {
- JobId = SVAL(p,0);
- Priority = SVAL(p,2);
- UserName = fix_char_ptr(SVAL(p,4), converter, rdata, rdrcnt);
- strlower(UserName);
- Priority = SVAL(p,2);
- JobTime = make_unix_date3( p + 12);
- JobTimeStr = asctime(LocalTime( &JobTime));
- Size = IVAL(p,16);
- JobName = fix_char_ptr(SVAL(p,24), converter, rdata, rdrcnt);
-
-
- printf("%s-%u %s priority %u %s %s %u bytes\n",
- PrinterName, JobId, UserName,
- Priority, JobTimeStr, JobName, Size);
-
-#if 0 /* DEBUG code */
- printf("Job Id: \"%u\"\n", SVAL(p,0));
- printf("Priority: \"%u\"\n", SVAL(p,2));
-
- printf("User Name: \"%s\"\n", fix_char_ptr(SVAL(p,4), converter, rdata, rdrcnt) );
- printf("Position: \"%u\"\n", SVAL(p,8));
- printf("Status: \"%u\"\n", SVAL(p,10));
-
- JobTime = make_unix_date3( p + 12);
- printf("Submitted: \"%s\"\n", asctime(LocalTime(&JobTime)));
- printf("date: \"%u\"\n", SVAL(p,12));
-
- printf("Size: \"%u\"\n", SVAL(p,16));
- printf("Comment: \"%s\"\n", fix_char_ptr(SVAL(p,20), converter, rdata, rdrcnt) );
- printf("Document: \"%s\"\n", fix_char_ptr(SVAL(p,24), converter, rdata, rdrcnt) );
-#endif /* DEBUG CODE */
- p += 28;
- }
- }
- }
- else /* cli_call_api() failed */
- {
- printf("Failed, error = %d\n", result_code);
- }
-
- /* If any parameters or data were returned, free the storage. */
- if(rparam) free(rparam);
- if(rdata) free(rdata);
-
- return;