- if (strcasecmp(line, "BrowseLocalProtocols"))
- BrowseRemoteProtocols = protocols;
- if (strcasecmp(line, "BrowseRemoteProtocols"))
- BrowseLocalProtocols = protocols;
- }
- else if ((!strcasecmp(line, "BrowseAllow") ||
- !strcasecmp(line, "BrowseDeny")) && value)
- {
- /*
- * BrowseAllow [From] host/ip...
- * BrowseDeny [From] host/ip...
- */
-
- if ((location = cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL)
- location = cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
-
- if (location == NULL)
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to initialize browse access control list!");
- else
- {
- while (*value)
- {
- if (!strncasecmp(value, "from", 4))
- {
- /*
- * Strip leading "from"...
- */
-
- value += 4;
-
- while (isspace(*value & 255))
- value ++;
-
- if (!*value)
- break;
- }
-
- /*
- * Find the end of the value...
- */
-
- for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
-
- while (isspace(*valueptr & 255))
- *valueptr++ = '\0';
-
- /*
- * Figure out what form the allow/deny address takes:
- *
- * All
- * None
- * *.domain.com
- * .domain.com
- * host.domain.com
- * nnn.*
- * nnn.nnn.*
- * nnn.nnn.nnn.*
- * nnn.nnn.nnn.nnn
- * nnn.nnn.nnn.nnn/mm
- * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
- */
-
- if (!strcasecmp(value, "all"))
- {
- /*
- * All hosts...
- */
-
- if (!strcasecmp(line, "BrowseAllow"))
- cupsdAllowIP(location, zeros, zeros);
- else
- cupsdDenyIP(location, zeros, zeros);
- }
- else if (!strcasecmp(value, "none"))
- {
- /*
- * No hosts...
- */
-
- if (!strcasecmp(line, "BrowseAllow"))
- cupsdAllowIP(location, ones, zeros);
- else
- cupsdDenyIP(location, ones, zeros);
- }
-#ifdef AF_INET6
- else if (value[0] == '*' || value[0] == '.' ||
- (!isdigit(value[0] & 255) && value[0] != '['))
-#else
- else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255))
-#endif /* AF_INET6 */
- {
- /*
- * Host or domain name...
- */
-
- if (value[0] == '*')
- value ++;
-
- if (!strcasecmp(line, "BrowseAllow"))
- cupsdAllowHost(location, value);
- else
- cupsdDenyHost(location, value);
- }
- else
- {
- /*
- * One of many IP address forms...
- */
-
- if (!get_addr_and_mask(value, ip, mask))
- {
- cupsdLogMessage(CUPSD_LOG_ERROR, "Bad netmask value %s on line %d.",
- value, linenum);
- break;
- }
-
- if (!strcasecmp(line, "BrowseAllow"))
- cupsdAllowIP(location, ip, mask);
- else
- cupsdDenyIP(location, ip, mask);
- }
-
- /*
- * Advance to next value...
- */
-
- value = valueptr;
- }
- }
- }
- else if (!strcasecmp(line, "BrowseRelay") && value)
- {
- /*
- * BrowseRelay [from] source [to] destination
- */
-
- if (NumRelays == 0)
- relay = malloc(sizeof(cupsd_dirsvc_relay_t));
- else
- relay = realloc(Relays, (NumRelays + 1) * sizeof(cupsd_dirsvc_relay_t));
-
- if (!relay)
- {
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to allocate BrowseRelay at line %d - %s.",
- linenum, strerror(errno));
- continue;
- }
-
- Relays = relay;
- relay += NumRelays;
-
- memset(relay, 0, sizeof(cupsd_dirsvc_relay_t));
-
- if (!strncasecmp(value, "from ", 5))
- {
- /*
- * Strip leading "from"...
- */
-
- value += 5;
-
- while (isspace(*value))
- value ++;
- }
-
- /*
- * Figure out what form the from address takes:
- *
- * *.domain.com
- * .domain.com
- * host.domain.com
- * nnn.*
- * nnn.nnn.*
- * nnn.nnn.nnn.*
- * nnn.nnn.nnn.nnn
- * nnn.nnn.nnn.nnn/mm
- * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
- */
-
-#ifdef AF_INET6
- if (value[0] == '*' || value[0] == '.' ||
- (!isdigit(value[0] & 255) && value[0] != '['))
-#else
- if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255))
-#endif /* AF_INET6 */
- {
- /*
- * Host or domain name...
- */
-
- if (value[0] == '*')
- value ++;
-
- strlcpy(temp, value, sizeof(temp));
- if ((ptr = strchr(temp, ' ')) != NULL)
- *ptr = '\0';
-
- relay->from.type = CUPSD_AUTH_NAME;
-
- if ((relay->from.mask.name.name = strdup(temp)) == NULL)
- {
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to allocate BrowseRelay name at line %d - %s.",
- linenum, strerror(errno));
- continue;
- }
-
- relay->from.mask.name.length = strlen(temp);
- }
- else
- {
- /*
- * One of many IP address forms...
- */
-
- if (!get_addr_and_mask(value, ip, mask))
- {
- cupsdLogMessage(CUPSD_LOG_ERROR, "Bad netmask value %s on line %d.",
- value, linenum);
- break;
- }
-
- relay->from.type = CUPSD_AUTH_IP;
- memcpy(relay->from.mask.ip.address, ip,
- sizeof(relay->from.mask.ip.address));
- memcpy(relay->from.mask.ip.netmask, mask,
- sizeof(relay->from.mask.ip.netmask));
- }
-
- /*
- * Skip value and trailing whitespace...
- */
-
- for (; *value; value ++)
- if (isspace(*value))
- break;
-
- while (isspace(*value))
- value ++;
-
- if (!strncasecmp(value, "to ", 3))
- {
- /*
- * Strip leading "to"...
- */
-
- value += 3;
-
- while (isspace(*value))
- value ++;
- }
-
- /*
- * Get "to" address and port...
- */
-
- if ((addrlist = get_address(value, BrowsePort)) != NULL)
- {
- /*
- * Only IPv4 addresses are supported...
- */
-
- for (addr = addrlist; addr; addr = addr->next)
- if (addr->addr.addr.sa_family == AF_INET)
- break;
-
- if (addr)
- {
- memcpy(&(relay->to), &(addrlist->addr), sizeof(relay->to));
-
- httpAddrString(&(relay->to), temp, sizeof(temp));
-
- if (relay->from.type == CUPSD_AUTH_IP)
- snprintf(temp2, sizeof(temp2), "%u.%u.%u.%u/%u.%u.%u.%u",
- relay->from.mask.ip.address[0] >> 24,
- (relay->from.mask.ip.address[0] >> 16) & 255,
- (relay->from.mask.ip.address[0] >> 8) & 255,
- relay->from.mask.ip.address[0] & 255,
- relay->from.mask.ip.netmask[0] >> 24,
- (relay->from.mask.ip.netmask[0] >> 16) & 255,
- (relay->from.mask.ip.netmask[0] >> 8) & 255,
- relay->from.mask.ip.netmask[0] & 255);
- else
- strlcpy(temp2, relay->from.mask.name.name, sizeof(temp2));
-
- cupsdLogMessage(CUPSD_LOG_INFO, "Relaying from %s to %s:%d (IPv4)",
- temp2, temp, ntohs(relay->to.ipv4.sin_port));
-
- NumRelays ++;
- }
- else
- cupsdLogMessage(CUPSD_LOG_ERROR, "Bad relay address %s at line %d.",
- value, linenum);
-
- httpAddrFreeList(addrlist);
- }
- else
- {
- if (relay->from.type == CUPSD_AUTH_NAME)
- free(relay->from.mask.name.name);
-
- cupsdLogMessage(CUPSD_LOG_ERROR, "Bad relay address %s at line %d.",
- value, linenum);
- }
- }
- else if (!strcasecmp(line, "BrowsePoll") && value)
- {
- /*
- * BrowsePoll address[:port]
- */
-
- char *portname; /* Port name */
- int portnum; /* Port number */
- struct servent *service; /* Service */
-
-
- /*
- * Extract the port name from the address...
- */
-
- if ((portname = strrchr(value, ':')) != NULL && !strchr(portname, ']'))
- {
- *portname++ = '\0';
-
- if (isdigit(*portname & 255))
- portnum = atoi(portname);
- else if ((service = getservbyname(portname, NULL)) != NULL)
- portnum = ntohs(service->s_port);
- else
- {
- cupsdLogMessage(CUPSD_LOG_ERROR, "Lookup of service \"%s\" failed!",
- portname);
- continue;
- }
- }
- else
- portnum = ippPort();
-
- /*
- * Add the poll entry...
- */
-
- if (NumPolled == 0)
- pollp = malloc(sizeof(cupsd_dirsvc_poll_t));
- else
- pollp = realloc(Polled, (NumPolled + 1) * sizeof(cupsd_dirsvc_poll_t));
-
- if (!pollp)
- {
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to allocate BrowsePoll at line %d - %s.",
- linenum, strerror(errno));
- continue;
- }
-
- Polled = pollp;
- pollp += NumPolled;
-
- NumPolled ++;
- memset(pollp, 0, sizeof(cupsd_dirsvc_poll_t));
-
- strlcpy(pollp->hostname, value, sizeof(pollp->hostname));
- pollp->port = portnum;
-
- cupsdLogMessage(CUPSD_LOG_INFO, "Polling %s:%d", pollp->hostname,
- pollp->port);