Next | Trivial Utilities | 97 |
printlp is the program that actually copies the data to /dev/lp
Such a program needs special permissions
It must run setuid or setgid
So we want to make it as simple as possible
#!/usr/bin/suidperl
use Fcntl 'O_WRONLY';
my $printer = shift; exit 1 unless defined $printer; exit 2 unless $printer =~ m{^/dev/lp[a-zA-Z.0-9-]*\z}; exit 3 unless -c $printer; my $group = getgrgid((stat _)[5]); exit 4 unless $group eq 'lp'; untaint($printer); sysopen PRINTER, $printer, O_WRONLY or exit 5;
my($br, $buf); while ($br = read STDIN, $buf, 8192) { print PRINTER $buf; } exit 6 unless defined $br; close PRINTER or exit 7; exit 0;
sub untaint { $_[0] =~ /(.*)/; $_[0] = $1; }
This is probably the only time in my life I have used the -c operator
Next | Menu | Copyright © 2012 M. J. Dominus |