Re: printing problems
Bradley Bell wrote:
>
> I need to print to an HP Laserjet 5Si printer which is hooked up to a
> netware network,
>
> Can anybody point me to any resources on printing to netware printers?
>
> I've studied and tried every trick in the IPX- and Printing-HOWTO, and
> the instructions there are pretty insufficient when it comes to this
> problem.
>
> At the moment, I can almost print text files using nprint, but they come
> out staircased and sideways, and with no banner page.
>
> If anybody else has gotten this working, can I see your printcap and
> filter files?
Yeah, it works fine here. I use a combination of magicfilter (debian
package) and nprint. We have a number of printers all hooked up to a
host called "ics1". I wrote a wrapper for nprint to make the
authentification and to be able to send data to nprint by stdin.
Attached are the makefiles, source, printcap, and a magicfilter file for
one of the printers.
My set up is like this:
/etc/printer/ics1/.nwclient --> authentification (holds "ICS1/username
password")
/Makefile --> rules to make a printer
/tess-ps-1 --> one of the printers.
/nw-printer.c --> source to generate a wrapper for each
printer
/tess-ps --> a wrapper binary generated by the
makefile
You will probably need to make small changes to Makefile and printcap.
Also change a magicfilter generate filter to get it to use the wrapper.
Hope the attachments help you on your way,
Dirk
SHELL=/bin/sh
NW_WHERE=-DHOME=\"/etc/printer/ics1\" -DSERVER=\"ics1\"
CC=gcc -Wall -W -Werror
all: tess-ps tess-tinte tess-ps-kyo37
tess-ps : tess-ps.o
gcc -o $@ $^
chown root.root $@
chmod ug+s $@
tess-ps.o: nw-printer.c
gcc -o $@ -c $^ -Wall -W -Werror $(NW_WHERE) -DQUEUE=\"tess-ps\"
tess-tinte : tess-tinte.o
gcc -o $@ $^
chown root.root $@
chmod ug+s $@
tess-tinte.o: nw-printer.c
gcc -o $@ -c $^ -Wall -W -Werror $(NW_WHERE) -DQUEUE=\"tess-tinte\"
tess-ps-kyo37 : tess-ps-kyo37.o
gcc -o $@ $^
chown root.root $@
chmod ug+s $@
tess-ps-kyo37.o: nw-printer.c
gcc -o $@ -c $^ -Wall -W -Werror $(NW_WHERE) -DQUEUE=\"tess-ps-kyo37\"
/* -*- c -*-
Dirk Bonne
wrapper for nprint, to get authentification working and
make it accept data from the stdin ---magicfilter prefers
this.
*/
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/stat.h>
#define WHO_CAN_RUN_ME "daemon"
int
main(int argc, char** argv)
{
int ret;
char tmpfile[512] = "/tmp/tmpXXXXXX";
char cmd[1024];
struct passwd* pass;
int fd;
char tmpbuf[8192];
ssize_t nread;
if(argc != 1) {
fprintf(stderr, "usage: %s\n", argv[0]);
return 1;
}
if(!(pass = getpwnam(WHO_CAN_RUN_ME))) {
fprintf(stderr, "getpwname failed for " WHO_CAN_RUN_ME ": %s", strerror(errno));
return 1;
}
if(getuid() != 0 && getuid() != pass->pw_uid) {
fprintf(stderr, "only root or " WHO_CAN_RUN_ME " can run me, not you(%d)!\n",
getuid());
return 1;
}
if(-1 == setreuid(geteuid(), geteuid())) {
fprintf(stderr, "setreuid: %s\n", strerror(errno));
return 1;
}
setenv("HOME", HOME, 1); /* so nprint can find .nwclient */
/* nprint wants a file: */
if(-1 == (fd=mkstemp(tmpfile))) {
fprintf(stderr, "mkstemp failed: %s\n", strerror(errno));
return 1;
}
while(0 != (nread = read(STDIN_FILENO, tmpbuf, sizeof(tmpbuf)))) {
if(nread == -1) {
if(errno != EINTR) {
fprintf(stderr, "read on stdin failed: %s\n", strerror(errno));
return 1;
}
} else {
ssize_t nwrite;
const char* p = tmpbuf;
while(nread > 0 && 0 != (nwrite = write(fd, p, nread))) {
nread -= nwrite; /* potentially hangs, if nwrite is zero */
p += nwrite;
}
if(nwrite == -1) {
fprintf(stderr, "write failed: %s\n", strerror(errno));
return 1;
}
}
}
close(fd);
sprintf(cmd, "strace /usr/bin/nprint -S " SERVER " -q " QUEUE " %s 1>&2", tmpfile);
fprintf(stderr, "%s\n", cmd);
fprintf(stderr, "%s\n", getenv("HOME"));
system("env 1>&2");
system("id 1>&2");
ret = system(cmd);
if(ret == -1) {
fprintf(stderr, "system(%s): %s", cmd, strerror(errno));
return 1;
} else if(ret == 127) {
fprintf(stderr, "call of /bin/sh failed for ´%s´\n", cmd);
return 1;
} else {
unlink(tmpfile);
return ret;
}
}
#!/usr/sbin/magicfilter
# Dirk Bonne
# PostScript
#0 %! postscript
#0 \004%! postscript
0 %! filter /etc/printer/ics1/tess-ps
0 \004%! filter /etc/printer/ics1/tess-ps
# TeX DVI
0 \367\002 fpipe /usr/bin/dvips -D 600 -R -q -F -f
# compress'd data
0 \037\235 pipe /bin/gzip -cdq
# packed, gzipped, frozen and SCO LZH data
0 \037\036 pipe /bin/gzip -cdq
0 \037\213 pipe /bin/gzip -cdq
0 \037\236 pipe /bin/gzip -cdq
0 \037\240 pipe /bin/gzip -cdq
# troff documents
0 .\?\?\040 fpipe `/usr/bin/grog -Tps $FILE`
0 .\\\" fpipe `/usr/bin/grog -Tps $FILE`
0 '\\\" fpipe `/usr/bin/grog -Tps $FILE`
0 '.\\\" fpipe `/usr/bin/grog -Tps $FILE`
0 \\\" fpipe `/usr/bin/grog -Tps $FILE`
# ditroff
0 "x T ps" pipe /usr/bin/grops
0 "x T dvi" pipe /usr/bin/grodvi
0 "x T ascii" pipe /usr/bin/grotty
0 "x T latin1" pipe /usr/bin/grotty
0 "x T lj4" reject Cannot print LaserJet 4 ditroff files.
# Portable bit-, grey- and pixmaps
0 P1\n pipe /usr/bin/pnmtops -scale 1000 -dpi 600 2>/dev/null
0 P2\n pipe /usr/bin/pnmtops -scale 1000 -dpi 600 2>/dev/null
0 P3\n pipe /usr/bin/pnmtops -scale 1000 -dpi 600 2>/dev/null
0 P4\n pipe /usr/bin/pnmtops -scale 1000 -dpi 600 2>/dev/null
0 P5\n pipe /usr/bin/pnmtops -scale 1000 -dpi 600 2>/dev/null
0 P6\n pipe /usr/bin/pnmtops -scale 1000 -dpi 600 2>/dev/null
# HP Printer Control Language (PCL) -- assume start with reset code
0 \033E\033 reject Cannot print PCL files on this printer.
# HP Printer Job Language (PJL)
0 \033%-12345X reject Cannot print PJL files on this printer.
0 "@PJL " reject Cannot print PJL files on this printer.
0 @PJL\t reject Cannot print PJL files on this printer.
0 @PJL\r reject Cannot print PJL files on this printer.
0 @PJL\n reject Cannot print PJL files on this printer.
# GIF files
0 GIF87a pipe /usr/bin/giftopnm 2>/dev/null
0 GIF89a pipe /usr/bin/giftopnm 2>/dev/null
# JFIF (JPEG) files
0 \377\330\377\340\?\?JFIF\0 pipe /usr/bin/djpeg -pnm
# TIFF files (the last two bytes of the "magic" is really a version number;
# but the magic is really lame and as far as I have understood the version
# number has never changed and never will, so we include it.)
0 MM\0\x2a pipe /usr/bin/tifftopnm 2>/dev/null
0 II\x2a\0 pipe /usr/bin/tifftopnm 2>/dev/null
# BMP files (even lousier magic -- Microsoft strikes again!)
0 BM\?\?\?\?\?\?\?\?\?\?\?\?\x0c pipe \
/usr/bin/bmptoppm 2>/dev/null
0 BM\?\?\?\?\?\?\?\?\?\?\?\?\x40 pipe \
/usr/bin/bmptoppm 2>/dev/null
0 BM\?\?\?\?\?\?\?\?\?\?\?\?\x28 pipe \
/usr/bin/bmptoppm 2>/dev/null
# Sun rasterfiles
0 \x59\xa6\x6a\x95 pipe /usr/bin/rasttopnm 2>/dev/null
# SGI Imagelib (IRIS RGB) files
0 \x1\xda pipe /usr/bin/sgitopnm 2>/dev/null
0 \xda\x1 pipe /usr/bin/sgitopnm 2>/dev/null
# FIG files; reported by Steven P. Hill <sph@uscbu.ih.att.com>
0 #FIG pipe /usr/bin/X11/fig2dev -Lps -P -l dummy
#
# Standard rejects... things we don't want to print
#
# Various archive formats
257 ustar\0 reject Attempted to print a tar file.
257 "ustar \0" reject Attempted to print a tar file.
0 07070 reject Attempted to print a cpio file.
0 PK\3\4 reject Attempted to print a zip file.
20 \xdc\xa7\xc7\xfd reject Attempted to print a zoo file.
# Binaries (Linux): reject with email message
0 \013\1d\0 reject Attempted to print a compiled binary.
0 \100\1d\0 reject Attempted to print a compiled binary.
0 \007\1d\0 reject Attempted to print a compiled binary.
0 \314\0d\0 reject Attempted to print a compiled binary.
0 \177ELF reject Attempted to print an ELF object.
0 \007\001\0 reject Attempted to print an object file.
216 \021\001\0\0 reject Attempted to print a core dump file.
0 !<arch> reject Attempted to print an archive.
0 =<ar> reject Attempted to print an archive.
# Don't confuse this one with troff!
0 .snd reject Attempted to print Sun/NeXT audio data.
# optimistic troff magic
0 . fpipe `/usr/bin/grog -Tps $FILE`
# wacko troff magic
0 ''' fpipe `/usr/bin/grog -Tps $FILE`
# Default entry -- for normal (text) files. MUST BE LAST.
default pipe a2ps -nH -nP -8 -1 -nd -ns -nu -nL -p
Reply to: