diff options
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/lp/lib/papi/mapfile | 3 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/in.lpd.c | 58 | ||||
-rw-r--r-- | usr/src/lib/print/libipp-listener/common/ipp-listener.c | 6 | ||||
-rw-r--r-- | usr/src/lib/print/libpapi-common/Makefile.com | 4 | ||||
-rw-r--r-- | usr/src/lib/print/libpapi-common/common/mapfile | 4 | ||||
-rw-r--r-- | usr/src/lib/print/libpapi-common/common/misc.c | 141 | ||||
-rw-r--r-- | usr/src/lib/print/libpapi-common/common/papi.h | 4 | ||||
-rw-r--r-- | usr/src/lib/print/libpapi-dynamic/Makefile.com | 4 | ||||
-rw-r--r-- | usr/src/lib/print/libpapi-dynamic/common/mapfile | 3 | ||||
-rw-r--r-- | usr/src/lib/print/libpapi-dynamic/common/nss.c | 128 | ||||
-rw-r--r-- | usr/src/lib/print/libpapi-dynamic/common/psm.c | 13 | ||||
-rw-r--r-- | usr/src/lib/print/libpapi-dynamic/common/service.c | 9 | ||||
-rw-r--r-- | usr/src/lib/print/libpapi-ipp/common/mapfile | 3 | ||||
-rw-r--r-- | usr/src/lib/print/libpapi-lpd/common/mapfile | 3 |
14 files changed, 191 insertions, 192 deletions
diff --git a/usr/src/cmd/lp/lib/papi/mapfile b/usr/src/cmd/lp/lib/papi/mapfile index 0377e300ec..45d08b2893 100644 --- a/usr/src/cmd/lp/lib/papi/mapfile +++ b/usr/src/cmd/lp/lib/papi/mapfile @@ -18,7 +18,7 @@ # # CDDL HEADER END # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -143,6 +143,7 @@ SUNWprivate_1.0 { # NS getprinterbyname = FUNCTION FILTER libpapi-common.so ; + is_localhost = FUNCTION FILTER libpapi-common.so ; # extra Attribute Calls copy_attributes = FUNCTION FILTER libpapi-common.so ; diff --git a/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c b/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c index e4bf689d47..25d23c2516 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c +++ b/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c @@ -69,7 +69,7 @@ remote_host_name(FILE *fp) socklen_t peer_len = sizeof (peer); int fd = fileno(fp); int error_num; - char myname[MAXHOSTNAMELEN], tmp_buf[INET6_ADDRSTRLEN]; + char tmp_buf[INET6_ADDRSTRLEN]; char *hostname; /* who is our peer ? */ @@ -88,28 +88,9 @@ remote_host_name(FILE *fp) &peer.sin6_addr, tmp_buf, sizeof (tmp_buf)))); } - /* is it "localhost" ? */ - if (strcasecmp(hp->h_name, "localhost") == 0) - return (strdup("localhost")); - - /* duplicate the name because gethostbyXXXX() is not reentrant */ hostname = strdup(hp->h_name); - (void) sysinfo(SI_HOSTNAME, myname, sizeof (myname)); - - /* is it from one of my addresses ? */ - if ((hp = getipnodebyname(myname, AF_INET6, AI_ALL|AI_V4MAPPED, - &error_num)) != NULL) { - struct in6_addr **tmp = (struct in6_addr **)hp->h_addr_list; - int i = 0; - - while (tmp[i] != NULL) { - if (memcmp(tmp[i++], &peer.sin6_addr, hp->h_length) - == 0) { - free(hostname); - return (strdup("localhost")); - } - } - } + if (is_localhost(hp->h_name) != 0) + return (strdup("localhost")); /* It must be someone else */ return (hostname); @@ -152,11 +133,8 @@ parse_cf(papi_service_t svc, char *cf, char **files) { papi_attribute_t **list = NULL; char previous = NULL, - *entry, - *s, - text[BUFSIZ]; - int count = 0, - copies_set = 0, + *entry; + int copies_set = 0, copies = 0; for (entry = strtok(cf, "\n"); entry != NULL; @@ -288,12 +266,21 @@ parse_cf(papi_service_t svc, char *cf, char **files) /* Sun Solaris Extensions */ case 'O': ++entry; - do { - if (*entry != '"') - text[count++] = *entry; - } while (*entry++); - papiAttributeListFromString(&list, PAPI_ATTR_APPEND, - text); + { + int rd, wr; + + for (rd = wr = 0; entry[rd] != '\0'; rd++) { + if (entry[rd] == '"') + continue; + if (rd != wr) + entry[wr] = entry[rd]; + wr++; + } + entry[wr] = '\0'; + + papiAttributeListFromString(&list, + PAPI_ATTR_APPEND, entry); + } break; case '5': ++entry; @@ -596,7 +583,6 @@ static int cyclical_service_check(char *svc_name) { papi_attribute_t **list; - char buf[BUFSIZ]; uri_t *uri = NULL; char *s = NULL; @@ -627,9 +613,7 @@ cyclical_service_check(char *svc_name) } /* is it the local host? */ - sysinfo(SI_HOSTNAME, buf, sizeof (buf)); - if ((strcasecmp(uri->host, "localhost") != 0) && - (strcasecmp(uri->host, buf) != 0)) { + if (is_localhost(uri->host) != 0) { uri_free(uri); return (0); } diff --git a/usr/src/lib/print/libipp-listener/common/ipp-listener.c b/usr/src/lib/print/libipp-listener/common/ipp-listener.c index 33a1c4d1a0..42f23f85e7 100644 --- a/usr/src/lib/print/libipp-listener/common/ipp-listener.c +++ b/usr/src/lib/print/libipp-listener/common/ipp-listener.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ @@ -399,9 +399,7 @@ cyclical_service_check(char *svc_name, int port) } /* does the host match up */ - sysinfo(SI_HOSTNAME, buf, sizeof (buf)); - if ((strcasecmp(uri->host, "localhost") != 0) && - (strcasecmp(uri->host, buf) != 0)) { + if (is_localhost(uri->host) != 0) { uri_free(uri); return (0); } diff --git a/usr/src/lib/print/libpapi-common/Makefile.com b/usr/src/lib/print/libpapi-common/Makefile.com index f7669307d2..1f1bd87f89 100644 --- a/usr/src/lib/print/libpapi-common/Makefile.com +++ b/usr/src/lib/print/libpapi-common/Makefile.com @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -45,7 +45,7 @@ CPPFLAGS += -I$(SRCDIR) MAPFILES = $(SRCDIR)/mapfile -LDLIBS += -lc +LDLIBS += -lc -lsocket -lnsl .KEEP_STATE: diff --git a/usr/src/lib/print/libpapi-common/common/mapfile b/usr/src/lib/print/libpapi-common/common/mapfile index 1d92801e1f..79cd7803b0 100644 --- a/usr/src/lib/print/libpapi-common/common/mapfile +++ b/usr/src/lib/print/libpapi-common/common/mapfile @@ -20,7 +20,7 @@ # # -# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # @@ -148,6 +148,8 @@ SUNWprivate_1.0 { # Misc. semi-private supporting calls split_and_copy_attributes; papiAttributeListPrint; + is_localhost; + local: *; }; diff --git a/usr/src/lib/print/libpapi-common/common/misc.c b/usr/src/lib/print/libpapi-common/common/misc.c index 646a26e18a..2688fd0ec0 100644 --- a/usr/src/lib/print/libpapi-common/common/misc.c +++ b/usr/src/lib/print/libpapi-common/common/misc.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ @@ -31,9 +31,14 @@ /*LINTLIBRARY*/ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> #include <string.h> +#include <ctype.h> +#include <sys/types.h> #include <papi.h> - +#include <uri.h> #include <config-site.h> /* @@ -85,3 +90,135 @@ strlcat(char *dst, const char *src, size_t dstsize) return (l1 + l2); } #endif + +#if defined(__sun) && defined(__SVR4) +#include <sys/systeminfo.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <sys/sockio.h> +#include <net/if.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> + +static struct in6_addr ** +local_interfaces() +{ + struct in6_addr **result = NULL; + int s; + struct lifnum n; + struct lifconf c; + struct lifreq *r; + int count; + + /* we need a socket to get the interfaces */ + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + return (0); + + /* get the number of interfaces */ + memset(&n, 0, sizeof (n)); + n.lifn_family = AF_UNSPEC; + if (ioctl(s, SIOCGLIFNUM, (char *)&n) < 0) { + close(s); + return (0); /* no interfaces */ + } + + /* get the interface(s) configuration */ + memset(&c, 0, sizeof (c)); + c.lifc_family = AF_UNSPEC; + c.lifc_buf = calloc(n.lifn_count, sizeof (struct lifreq)); + c.lifc_len = (n.lifn_count * sizeof (struct lifreq)); + if (ioctl(s, SIOCGLIFCONF, (char *)&c) < 0) { + free(c.lifc_buf); + close(s); + return (0); /* can't get interface(s) configuration */ + } + close(s); + + r = c.lifc_req; + for (count = c.lifc_len / sizeof (struct lifreq); + count > 0; count--, r++) { + struct in6_addr v6[1], *addr = NULL; + + switch (r->lifr_addr.ss_family) { + case AF_INET: { + struct sockaddr_in *s = + (struct sockaddr_in *)&r->lifr_addr; + IN6_INADDR_TO_V4MAPPED(&s->sin_addr, v6); + addr = v6; + } + break; + case AF_INET6: { + struct sockaddr_in6 *s = + (struct sockaddr_in6 *)&r->lifr_addr; + addr = &s->sin6_addr; + } + break; + } + + if (addr != NULL) { + struct in6_addr *a = malloc(sizeof (*a)); + + memcpy(a, addr, sizeof (*a)); + list_append(&result, a); + } + } + free(c.lifc_buf); + + return (result); +} + +static int +match_interfaces(char *host) +{ + struct in6_addr **lif = local_interfaces(); + struct hostent *hp; + int rc = 0; + int errnum; + + /* are there any local interfaces */ + if (lif == NULL) + return (0); + + /* cycle through the host db addresses */ + hp = getipnodebyname(host, AF_INET6, AI_ALL|AI_V4MAPPED, &errnum); + if (hp != NULL) { + struct in6_addr **tmp = (struct in6_addr **)hp->h_addr_list; + int i; + + for (i = 0; ((rc == 0) && (tmp[i] != NULL)); i++) { + int j; + + for (j = 0; ((rc == 0) && (lif[j] != NULL)); j++) + if (memcmp(tmp[i], lif[j], + sizeof (struct in6_addr)) == 0) + rc = 1; + } + } + free(lif); + + return (rc); +} +#endif + +int +is_localhost(char *host) +{ + char hostname[BUFSIZ]; + + /* is it "localhost" */ + if (strncasecmp(host, "localhost", 10) == 0) + return (1); + + /* is it the {nodename} */ + sysinfo(SI_HOSTNAME, hostname, sizeof (hostname)); + if (strncasecmp(host, hostname, strlen(hostname)) == 0) + return (1); + +#if defined(__sun) && defined(__SVR4) + /* does it match one of the host's configured interfaces */ + if (match_interfaces(host) != 0) + return (1); +#endif + return (0); +} diff --git a/usr/src/lib/print/libpapi-common/common/papi.h b/usr/src/lib/print/libpapi-common/common/papi.h index b84e7904ac..5fcaccc584 100644 --- a/usr/src/lib/print/libpapi-common/common/papi.h +++ b/usr/src/lib/print/libpapi-common/common/papi.h @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ @@ -443,6 +443,8 @@ extern void split_and_copy_attributes(char **list, extern papi_attribute_t **getprinterbyname(char *name, char *ns); +extern int is_localhost(char *hostname); + #ifdef __cplusplus } #endif diff --git a/usr/src/lib/print/libpapi-dynamic/Makefile.com b/usr/src/lib/print/libpapi-dynamic/Makefile.com index ae0c5d93e8..22b7cacf9f 100644 --- a/usr/src/lib/print/libpapi-dynamic/Makefile.com +++ b/usr/src/lib/print/libpapi-dynamic/Makefile.com @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -46,7 +46,7 @@ CFLAGS += $(CCVERBOSE) CPPFLAGS += -I$(SRCDIR) CPPFLAGS += -I../../libpapi-common/common CPPFLAGS += -DNSS_SOLARIS -LDLIBS += -lsocket -lnsl -lc +LDLIBS += -lc .KEEP_STATE: diff --git a/usr/src/lib/print/libpapi-dynamic/common/mapfile b/usr/src/lib/print/libpapi-dynamic/common/mapfile index 41734836cb..0107348167 100644 --- a/usr/src/lib/print/libpapi-dynamic/common/mapfile +++ b/usr/src/lib/print/libpapi-dynamic/common/mapfile @@ -20,7 +20,7 @@ # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # @@ -141,6 +141,7 @@ SUNWprivate_1.0 { list_concatenate = FUNCTION FILTER libpapi-common.so ; # NS getprinterbyname ; + is_localhost = FUNCTION FILTER libpapi-common.so ; # extra Attribute Calls copy_attributes = FUNCTION FILTER libpapi-common.so ; diff --git a/usr/src/lib/print/libpapi-dynamic/common/nss.c b/usr/src/lib/print/libpapi-dynamic/common/nss.c index 22cb2992d5..c20b33daf8 100644 --- a/usr/src/lib/print/libpapi-dynamic/common/nss.c +++ b/usr/src/lib/print/libpapi-dynamic/common/nss.c @@ -81,134 +81,6 @@ bsdaddr_to_uri(papi_attribute_t **list, char *bsdaddr) } #if defined(__sun) && defined(__SVR4) -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <sys/sockio.h> -#include <net/if.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> - -static struct in6_addr ** -local_interfaces() -{ - struct in6_addr **result = NULL; - int s; - struct lifnum n; - struct lifconf c; - struct lifreq *r; - int count; - - /* we need a socket to get the interfaces */ - if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - return (0); - - /* get the number of interfaces */ - memset(&n, 0, sizeof (n)); - n.lifn_family = AF_UNSPEC; - if (ioctl(s, SIOCGLIFNUM, (char *)&n) < 0) { - close(s); - return (0); /* no interfaces */ - } - - /* get the interface(s) configuration */ - memset(&c, 0, sizeof (c)); - c.lifc_family = AF_UNSPEC; - c.lifc_buf = calloc(n.lifn_count, sizeof (struct lifreq)); - c.lifc_len = (n.lifn_count * sizeof (struct lifreq)); - if (ioctl(s, SIOCGLIFCONF, (char *)&c) < 0) { - free(c.lifc_buf); - close(s); - return (0); /* can't get interface(s) configuration */ - } - close(s); - - r = c.lifc_req; - for (count = c.lifc_len / sizeof (struct lifreq); - count > 0; count--, r++) { - struct in6_addr v6[1], *addr = NULL; - - switch (r->lifr_addr.ss_family) { - case AF_INET: { - struct sockaddr_in *s = - (struct sockaddr_in *)&r->lifr_addr; - IN6_INADDR_TO_V4MAPPED(&s->sin_addr, v6); - addr = v6; - } - break; - case AF_INET6: { - struct sockaddr_in6 *s = - (struct sockaddr_in6 *)&r->lifr_addr; - addr = &s->sin6_addr; - } - break; - } - - if (addr != NULL) { - struct in6_addr *a = malloc(sizeof (*a)); - - memcpy(a, addr, sizeof (*a)); - list_append(&result, a); - } - } - free(c.lifc_buf); - - return (result); -} - -static int -match_interfaces(char *host) -{ - struct in6_addr **lif = local_interfaces(); - struct hostent *hp; - int rc = 0; - int errnum; - - /* are there any local interfaces */ - if (lif == NULL) - return (0); - - /* cycle through the host db addresses */ - hp = getipnodebyname(host, AF_INET6, AI_ALL|AI_V4MAPPED, &errnum); - if (hp != NULL) { - struct in6_addr **tmp = (struct in6_addr **)hp->h_addr_list; - int i; - - for (i = 0; ((rc == 0) && (tmp[i] != NULL)); i++) { - int j; - - for (j = 0; ((rc == 0) && (lif[j] != NULL)); j++) - if (memcmp(tmp[i], lif[j], - sizeof (struct in6_addr)) == 0) - rc = 1; - } - } - free(lif); - - return (rc); -} - -static int -is_localhost(char *host) -{ - char hostname[BUFSIZ]; - - /* is it "localhost" */ - if (strncasecmp(host, "localhost", 10) == 0) - return (1); - - /* is it the {nodename} */ - sysinfo(SI_HOSTNAME, hostname, sizeof (hostname)); - if (strncasecmp(host, hostname, strlen(hostname)) == 0) - return (1); - - /* does it match one of the host's configured interfaces */ - if (match_interfaces(host) != 0) - return (1); - - return (0); -} - /* * This is an awful HACK to force the dynamic PAPI library to use the * lpsched support when the destination apears to be a local lpsched diff --git a/usr/src/lib/print/libpapi-dynamic/common/psm.c b/usr/src/lib/print/libpapi-dynamic/common/psm.c index 6bc679b79e..af31f24b4e 100644 --- a/usr/src/lib/print/libpapi-dynamic/common/psm.c +++ b/usr/src/lib/print/libpapi-dynamic/common/psm.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ @@ -48,17 +48,12 @@ papi_status_t psm_open(service_t *svc, char *scheme) { papi_status_t result = PAPI_OK; - char *path; - char buf[BUFSIZ]; + char path[BUFSIZ]; - if (scheme == NULL) + if ((scheme == NULL) || (strchr(scheme, '/') != NULL)) return (PAPI_BAD_ARGUMENT); - if (strchr(scheme, '/') == NULL) { - snprintf(buf, sizeof (buf), PSM_DIR "/psm-%s.so", scheme); - path = buf; - } else - path = scheme; + snprintf(path, sizeof (path), PSM_DIR "/psm-%s.so", scheme); svc->so_handle = dlopen(path, RTLD_LAZY|RTLD_LOCAL|RTLD_GROUP); if (svc->so_handle == NULL) { /* failed, set the result/message */ diff --git a/usr/src/lib/print/libpapi-dynamic/common/service.c b/usr/src/lib/print/libpapi-dynamic/common/service.c index b6a9ecf786..55f1732a65 100644 --- a/usr/src/lib/print/libpapi-dynamic/common/service.c +++ b/usr/src/lib/print/libpapi-dynamic/common/service.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ @@ -34,6 +34,8 @@ #include <stdlib.h> #include <stdio.h> #include <stdarg.h> +#include <sys/types.h> +#include <unistd.h> #include <string.h> #include <alloca.h> #include <libintl.h> @@ -57,7 +59,10 @@ default_service_uri(char *fallback) { char *result = NULL; - if ((result = getenv("PAPI_SERVICE_URI")) == NULL) { + if (getuid() == geteuid()) + result = getenv("PAPI_SERVICE_URI"); + + if (result == NULL) { char *cups; if ((cups = getenv("CUPS_SERVER")) != NULL) { diff --git a/usr/src/lib/print/libpapi-ipp/common/mapfile b/usr/src/lib/print/libpapi-ipp/common/mapfile index 918398aa74..bc2a18d9e4 100644 --- a/usr/src/lib/print/libpapi-ipp/common/mapfile +++ b/usr/src/lib/print/libpapi-ipp/common/mapfile @@ -20,7 +20,7 @@ # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # @@ -141,6 +141,7 @@ SUNWprivate_1.0 { list_concatenate = FUNCTION FILTER libpapi-common.so ; # NS getprinterbyname = FUNCTION FILTER libpapi-common.so ; + is_localhost = FUNCTION FILTER libpapi-common.so ; # extra Attribute Calls copy_attributes = FUNCTION FILTER libpapi-common.so ; diff --git a/usr/src/lib/print/libpapi-lpd/common/mapfile b/usr/src/lib/print/libpapi-lpd/common/mapfile index 257a97becf..982398f891 100644 --- a/usr/src/lib/print/libpapi-lpd/common/mapfile +++ b/usr/src/lib/print/libpapi-lpd/common/mapfile @@ -20,7 +20,7 @@ # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # @@ -141,6 +141,7 @@ SUNWprivate_1.0 { list_concatenate = FUNCTION FILTER libpapi-common.so ; # NS getprinterbyname = FUNCTION FILTER libpapi-common.so ; + is_localhost = FUNCTION FILTER libpapi-common.so ; # extra Attribute Calls copy_attributes = FUNCTION FILTER libpapi-common.so ; |