Skip to content

Commit

Permalink
Disable SNMP supply levels when the community name is cleared (Issue #…
Browse files Browse the repository at this point in the history
…5354)

backend/snmp-supplies.c:
- Look for empty community name.

cups/snmp.c:
- Allow empty community name.

man/cups-snmp.conf.man:
- Document behavior of empty community name.
  • Loading branch information
michaelrsweet committed Nov 8, 2018
1 parent 9eacf61 commit 8d32a3f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CHANGES - 2.3b6 - 2018-11-07
CHANGES - 2.3b6 - 2018-11-08
============================

Changes in CUPS v2.3b6
Expand All @@ -21,6 +21,9 @@ Changes in CUPS v2.3b6
- The IPP Everywhere "driver" now properly supports face-up printers
(Issue #5345)
- Fixed some typos in the label printer drivers (Issue #5350)
- Setting the `Community` name to the empty string in `snmp.conf` now disables
SNMP supply level monitoring by all the standard network backends
(Issue #5354)
- Multi-file jobs could get stuck if the backend failed (Issue #5359,
Issue #5413)
- The IPP Everywhere "driver" no longer does local filtering when printing to
Expand Down
15 changes: 10 additions & 5 deletions backend/snmp-supplies.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ backend_init_supplies(
{
int i, /* Looping var */
type; /* Current marker type */
const char *community; /* SNMP community name */
cups_file_t *cachefile; /* Cache file */
const char *cachedir; /* CUPS_CACHEDIR value */
char addrstr[1024], /* Address string */
Expand Down Expand Up @@ -507,6 +508,10 @@ backend_init_supplies(
* See if we should be getting supply levels via SNMP...
*/

community = _cupsSNMPDefaultCommunity();
if (!*community)
return;

if ((ppd = ppdOpenFile(getenv("PPD"))) == NULL ||
((ppdattr = ppdFindAttr(ppd, "cupsSNMPSupplies", NULL)) != NULL &&
ppdattr->value && _cups_strcasecmp(ppdattr->value, "true")))
Expand All @@ -528,7 +533,7 @@ backend_init_supplies(
*/

if (!_cupsSNMPWrite(snmp_fd, addr, CUPS_SNMP_VERSION_1,
_cupsSNMPDefaultCommunity(), CUPS_ASN1_GET_REQUEST, 1,
community, CUPS_ASN1_GET_REQUEST, 1,
hrDeviceDescr))
return;

Expand Down Expand Up @@ -605,7 +610,7 @@ backend_init_supplies(


if (!_cupsSNMPWrite(snmp_fd, &current_addr, CUPS_SNMP_VERSION_1,
_cupsSNMPDefaultCommunity(), CUPS_ASN1_GET_REQUEST, 1,
community, CUPS_ASN1_GET_REQUEST, 1,
prtGeneralCurrentLocalization))
return;

Expand All @@ -626,7 +631,7 @@ backend_init_supplies(


if (!_cupsSNMPWrite(snmp_fd, &current_addr, CUPS_SNMP_VERSION_1,
_cupsSNMPDefaultCommunity(), CUPS_ASN1_GET_REQUEST, 1,
community, CUPS_ASN1_GET_REQUEST, 1,
oid))
return;

Expand All @@ -651,7 +656,7 @@ backend_init_supplies(
*/

_cupsSNMPWalk(snmp_fd, &current_addr, CUPS_SNMP_VERSION_1,
_cupsSNMPDefaultCommunity(), prtMarkerSuppliesEntry,
community, prtMarkerSuppliesEntry,
CUPS_SUPPLY_TIMEOUT, backend_walk_cb, NULL);
}

Expand Down Expand Up @@ -685,7 +690,7 @@ backend_init_supplies(
strlcpy(supplies[i].color, "none", sizeof(supplies[i].color));

_cupsSNMPWalk(snmp_fd, &current_addr, CUPS_SNMP_VERSION_1,
_cupsSNMPDefaultCommunity(), prtMarkerColorantValue,
community, prtMarkerColorantValue,
CUPS_SUPPLY_TIMEOUT, backend_walk_cb, NULL);

/*
Expand Down
8 changes: 6 additions & 2 deletions cups/snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,13 @@ _cupsSNMPDefaultCommunity(void)
{
linenum = 0;
while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
if (!_cups_strcasecmp(line, "Community") && value)
if (!_cups_strcasecmp(line, "Community"))
{
strlcpy(cg->snmp_community, value, sizeof(cg->snmp_community));
if (value)
strlcpy(cg->snmp_community, value, sizeof(cg->snmp_community));
else
cg->snmp_community[0] = '\0';

break;
}

Expand Down
3 changes: 2 additions & 1 deletion man/cups-snmp.conf.man
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.\"
.\" Licensed under Apache License v2.0. See the file "LICENSE" for more information.
.\"
.TH snmp.conf 5 "CUPS" "10 June 2014" "Apple Inc."
.TH snmp.conf 5 "CUPS" "8 November 2018" "Apple Inc."
.SH NAME
snmp.conf \- snmp configuration file for cups
.SH DESCRIPTION
Expand All @@ -32,6 +32,7 @@ There is no default for the broadcast address.
Specifies the community name to use.
Only a single community name may be specified.
The default community name is "public".
If no name is specified, all SNMP functions are disabled.
.TP 5
\fBDebugLevel \fInumber\fR
Specifies the logging level from 0 (none) to 3 (everything).
Expand Down

0 comments on commit 8d32a3f

Please sign in to comment.