- Updated to improved dnssd backend from Till Kamppeter.
This commit is contained in:
parent
991c06573d
commit
b0dd15a49e
@ -449,6 +449,9 @@ rm -rf $RPM_BUILD_ROOT
|
|||||||
%{cups_serverbin}/daemon/cups-lpd
|
%{cups_serverbin}/daemon/cups-lpd
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Nov 27 2007 Tim Waugh <twaugh@redhat.com>
|
||||||
|
- Updated to improved dnssd backend from Till Kamppeter.
|
||||||
|
|
||||||
* Tue Nov 13 2007 Tim Waugh <twaugh@redhat.com>
|
* Tue Nov 13 2007 Tim Waugh <twaugh@redhat.com>
|
||||||
- Fixed CVE-2007-4045 patch; has no effect with shipped packages since they
|
- Fixed CVE-2007-4045 patch; has no effect with shipped packages since they
|
||||||
are linked with gnutls.
|
are linked with gnutls.
|
||||||
|
96
dnssd
96
dnssd
@ -45,11 +45,12 @@ my $avahicmd = "avahi-browse -k -t -v -r -a 2> /dev/null";
|
|||||||
|
|
||||||
# IPs which are for computers, consider their printer entries as queues
|
# IPs which are for computers, consider their printer entries as queues
|
||||||
# set up with the local printing system (CUPS, LPD, Windows/Samba SMB, ...)
|
# set up with the local printing system (CUPS, LPD, Windows/Samba SMB, ...)
|
||||||
my @ipblacklist = ();
|
my @computerips = ();
|
||||||
my $output;
|
my $output;
|
||||||
|
my $hosts;
|
||||||
my ($interface, $nettype, $ip, $host, $make, $model, $description, $cmd, $makemodel, $deviceid, $protocol, $port, $uriext, $uri);
|
my ($interface, $nettype, $ip, $host, $make, $model, $description, $cmd, $makemodel, $deviceid, $protocol, $port, $uriext, $uri);
|
||||||
|
|
||||||
open (AVAHI, "$avahicmd |") or die "Could not call \"$avahicmd\"\n";
|
open (AVAHI, "$avahicmd |") or exit 0;
|
||||||
while (my $line = <AVAHI>) {
|
while (my $line = <AVAHI>) {
|
||||||
chomp ($line);
|
chomp ($line);
|
||||||
if ($line =~ /^\s*=\s+(\S+)\s+(\S+)\s+(.*?)\s+(\S+)\s+(\S+)\s*$/) {
|
if ($line =~ /^\s*=\s+(\S+)\s+(\S+)\s+(.*?)\s+(\S+)\s+(\S+)\s*$/) {
|
||||||
@ -73,7 +74,7 @@ while (my $line = <AVAHI>) {
|
|||||||
} elsif ($line =~ /^\s*address\s*=\s*\[([^\]]+)\]\s*$/) {
|
} elsif ($line =~ /^\s*address\s*=\s*\[([^\]]+)\]\s*$/) {
|
||||||
$ip = $1;
|
$ip = $1;
|
||||||
if ($protocol eq "computer") {
|
if ($protocol eq "computer") {
|
||||||
push (@ipblacklist, $ip);
|
push (@computerips, $ip);
|
||||||
$protocol = "";
|
$protocol = "";
|
||||||
}
|
}
|
||||||
} elsif ($line =~ /^\s*port\s*=\s*\[([^\]]+)\]\s*$/) {
|
} elsif ($line =~ /^\s*port\s*=\s*\[([^\]]+)\]\s*$/) {
|
||||||
@ -124,7 +125,7 @@ while (my $line = <AVAHI>) {
|
|||||||
$usb_DES ||= $product;
|
$usb_DES ||= $product;
|
||||||
if ($usb_MFG) {
|
if ($usb_MFG) {
|
||||||
$make = $usb_MFG;
|
$make = $usb_MFG;
|
||||||
} elsif ($usb_DES =~ /^KONICA\s+MINOLTA\b/i) {
|
} elsif ($usb_DES =~ /^KONICA\s*MINOLTA\b/i) {
|
||||||
$make = "KONICA MINOLTA";
|
$make = "KONICA MINOLTA";
|
||||||
} elsif ($usb_DES) {
|
} elsif ($usb_DES) {
|
||||||
$usb_DES =~ /^\s*(\S*)\b/;
|
$usb_DES =~ /^\s*(\S*)\b/;
|
||||||
@ -138,7 +139,11 @@ while (my $line = <AVAHI>) {
|
|||||||
$usb_CMD ||= $pdls;
|
$usb_CMD ||= $pdls;
|
||||||
my $extra;
|
my $extra;
|
||||||
if ($protocol eq "socket") {
|
if ($protocol eq "socket") {
|
||||||
|
if ($port eq "9100") {
|
||||||
|
$uri = "socket://$ip";
|
||||||
|
} else {
|
||||||
$uri = "socket://$ip:$port";
|
$uri = "socket://$ip:$port";
|
||||||
|
}
|
||||||
$extra = "Port $port";
|
$extra = "Port $port";
|
||||||
} elsif ($protocol eq "lpd") {
|
} elsif ($protocol eq "lpd") {
|
||||||
$uri = "lpd://$ip" . ($uriext ? "/$uriext" : "");
|
$uri = "lpd://$ip" . ($uriext ? "/$uriext" : "");
|
||||||
@ -164,7 +169,8 @@ while (my $line = <AVAHI>) {
|
|||||||
($usb_DES ? "DES:$usb_DES;" : "") .
|
($usb_DES ? "DES:$usb_DES;" : "") .
|
||||||
($usb_CMD ? "CMD:$usb_CMD;" : "");
|
($usb_CMD ? "CMD:$usb_CMD;" : "");
|
||||||
$deviceid .= "CLS:PRINTER;" if $deviceid;
|
$deviceid .= "CLS:PRINTER;" if $deviceid;
|
||||||
$output->{$ip}{$protocol}{$extra} =
|
$hosts->{$ip} = $hostname if ($hostname);
|
||||||
|
$output->{$ip}{$protocol}{$uriext} =
|
||||||
"network $uri \"$makemodel\" \"$makemodel $ip ($extra)\" \"$deviceid\"\n";
|
"network $uri \"$makemodel\" \"$makemodel $ip ($extra)\" \"$deviceid\"\n";
|
||||||
($interface, $nettype, $ip, $host, $make, $model, $description, $cmd, $makemodel, $deviceid, $protocol, $port, $uriext, $uri) =
|
($interface, $nettype, $ip, $host, $make, $model, $description, $cmd, $makemodel, $deviceid, $protocol, $port, $uriext, $uri) =
|
||||||
("", "", "", "", "", "", "", "", "", "", "", "", "", "");
|
("", "", "", "", "", "", "", "", "", "", "", "", "", "");
|
||||||
@ -172,31 +178,87 @@ while (my $line = <AVAHI>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $localqueues = {};
|
||||||
|
my $queue = undef;
|
||||||
|
if (open LPSTAT, "LC_ALL=C lpstat -l -p -v |") {
|
||||||
|
while (my $line = <LPSTAT>) {
|
||||||
|
chomp $line;
|
||||||
|
if ($line =~ /^printer\s+(\S+)/i) {
|
||||||
|
$queue = $1;
|
||||||
|
$localqueues->{$queue} = {};
|
||||||
|
} elsif ($queue) {
|
||||||
|
if ($line =~ /^\s+Connection:\s+remote/i) {
|
||||||
|
$localqueues->{$queue}{remote} = 1;
|
||||||
|
} elsif ($line =~ /^\s+Interface:\s+(\S+)/i) {
|
||||||
|
$localqueues->{$queue}{interface} = $1;
|
||||||
|
} elsif ($line =~ /^device\s+for\s+(\S+)\s*:\s*(\S+)/i) {
|
||||||
|
$localqueues->{$1}{uri} = $2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close LPSTAT
|
||||||
|
}
|
||||||
|
|
||||||
|
my @localips = ();
|
||||||
|
if (open IFCONFIG, "LC_ALL=C /sbin/ifconfig |") {
|
||||||
|
while (my $line = <IFCONFIG>) {
|
||||||
|
chomp $line;
|
||||||
|
if ($line =~ /^\s*inet\s+addr:\s*(\S+)/i) {
|
||||||
|
push (@localips, $1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close IFCONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
foreach my $ip (keys(%{$output})) {
|
foreach my $ip (keys(%{$output})) {
|
||||||
next if member($ip, @ipblacklist);
|
# Do not list print queues of the local machine
|
||||||
|
next if member($ip, @localips);
|
||||||
if ($output->{$ip}{"socket"}) {
|
if ($output->{$ip}{"socket"}) {
|
||||||
foreach my $extra (keys(%{$output->{$ip}{"socket"}})) {
|
foreach my $uriext (keys(%{$output->{$ip}{"socket"}})) {
|
||||||
if (keys(%{$output->{$ip}{"socket"}}) = 1) {
|
if (keys(%{$output->{$ip}{"socket"}}) == 1) {
|
||||||
$output->{$ip}{"socket"}{$extra} =~
|
$output->{$ip}{"socket"}{$uriext} =~
|
||||||
s/^(\s*\S*\s*\S*\s*\"[^\"]*\"\s*\"[^\"\(]*?)\s*\([^\)]*\)\s*(\"\s*.*)$/$1$2/;
|
s/^(\s*\S*\s*\S*\s*\"[^\"]*\"\s*\"[^\"\(]*?)\s*\([^\)]*\)\s*(\"\s*.*)$/$1$2/;
|
||||||
}
|
}
|
||||||
print $output->{$ip}{"socket"}{$extra};
|
print $output->{$ip}{"socket"}{$uriext};
|
||||||
}
|
}
|
||||||
} elsif ($output->{$ip}{"lpd"}) {
|
} elsif ($output->{$ip}{"lpd"}) {
|
||||||
foreach my $extra (keys(%{$output->{$ip}{"lpd"}})) {
|
foreach my $uriext (keys(%{$output->{$ip}{"lpd"}})) {
|
||||||
if (keys(%{$output->{$ip}{"lpd"}}) = 1) {
|
if (keys(%{$output->{$ip}{"lpd"}}) == 1) {
|
||||||
$output->{$ip}{"lpd"}{$extra} =~
|
$output->{$ip}{"lpd"}{$uriext} =~
|
||||||
s/^(\s*\S*\s*\S*\s*\"[^\"]*\"\s*\"[^\"\(]*?)\s*\([^\)]*\)\s*(\"\s*.*)$/$1$2/;
|
s/^(\s*\S*\s*\S*\s*\"[^\"]*\"\s*\"[^\"\(]*?)\s*\([^\)]*\)\s*(\"\s*.*)$/$1$2/;
|
||||||
}
|
}
|
||||||
print $output->{$ip}{"lpd"}{$extra};
|
print $output->{$ip}{"lpd"}{$uriext};
|
||||||
}
|
}
|
||||||
} elsif ($output->{$ip}{"ipp"}) {
|
} elsif ($output->{$ip}{"ipp"}) {
|
||||||
foreach my $extra (keys(%{$output->{$ip}{"ipp"}})) {
|
foreach my $uriext (keys(%{$output->{$ip}{"ipp"}})) {
|
||||||
|
if ($uriext =~ /^(printers|classes)\/(\S+)$/) {
|
||||||
|
# Queue from a CUPS server. We should suppress it if it
|
||||||
|
# is a queue received via CUPS broadcast
|
||||||
|
$queue=$2;
|
||||||
|
if (defined($localqueues->{"$queue\@$ip"})) {
|
||||||
|
$queue = "$queue\@$ip";
|
||||||
|
} elsif (defined($localqueues->{"$queue\@$hosts->{$ip}"})) {
|
||||||
|
$queue = "$queue\@$hosts->{$ip}";
|
||||||
|
}
|
||||||
|
if (defined($localqueues->{$queue})) {
|
||||||
|
if ($localqueues->{$queue}{remote} &&
|
||||||
|
($localqueues->{$queue}{uri} =~
|
||||||
|
/^ipp:\/\/([^\/:]+)(:\d+|)\/(\S+)/)) {
|
||||||
|
my $host = $1;
|
||||||
|
my $ue = $3;
|
||||||
|
if ($host !~ /\d+\.\d+\.\d+\.\d+/) {
|
||||||
|
$host =
|
||||||
|
join(".", unpack("C4", gethostbyname($host)));
|
||||||
|
}
|
||||||
|
next if ($host eq $ip) && ($ue eq $uriext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (keys(%{$output->{$ip}{"ipp"}}) == 1) {
|
if (keys(%{$output->{$ip}{"ipp"}}) == 1) {
|
||||||
$output->{$ip}{"ipp"}{$extra} =~
|
$output->{$ip}{"ipp"}{$uriext} =~
|
||||||
s/^(\s*\S*\s*\S*\s*\"[^\"]*\"\s*\"[^\"]*?)\s*\([^\)]*\)\s*(\"\s*.*)$/$1$2/;
|
s/^(\s*\S*\s*\S*\s*\"[^\"]*\"\s*\"[^\"]*?)\s*\([^\)]*\)\s*(\"\s*.*)$/$1$2/;
|
||||||
}
|
}
|
||||||
print $output->{$ip}{"ipp"}{$extra};
|
print $output->{$ip}{"ipp"}{$uriext};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user