summaryrefslogtreecommitdiff
path: root/usr/src/lib
diff options
context:
space:
mode:
authorps29005 <none@none>2008-07-18 16:08:33 -0700
committerps29005 <none@none>2008-07-18 16:08:33 -0700
commita18dc42fc967d11feba9b8be61c6727dc6c56b48 (patch)
tree336dd000adc2ff7a4938db982383c2b78764752e /usr/src/lib
parentcbded9ae11944b2d8ab0ae13e5dbd0881ddba98c (diff)
downloadillumos-joyent-a18dc42fc967d11feba9b8be61c6727dc6c56b48.tar.gz
6599099 fix for 4383387 should reuse existing memory
6599100 libpapi should be more picky about the uri schemes it allows. 6599950 print localhost checking should be shared
Diffstat (limited to 'usr/src/lib')
-rw-r--r--usr/src/lib/print/libipp-listener/common/ipp-listener.c6
-rw-r--r--usr/src/lib/print/libpapi-common/Makefile.com4
-rw-r--r--usr/src/lib/print/libpapi-common/common/mapfile4
-rw-r--r--usr/src/lib/print/libpapi-common/common/misc.c141
-rw-r--r--usr/src/lib/print/libpapi-common/common/papi.h4
-rw-r--r--usr/src/lib/print/libpapi-dynamic/Makefile.com4
-rw-r--r--usr/src/lib/print/libpapi-dynamic/common/mapfile3
-rw-r--r--usr/src/lib/print/libpapi-dynamic/common/nss.c128
-rw-r--r--usr/src/lib/print/libpapi-dynamic/common/psm.c13
-rw-r--r--usr/src/lib/print/libpapi-dynamic/common/service.c9
-rw-r--r--usr/src/lib/print/libpapi-ipp/common/mapfile3
-rw-r--r--usr/src/lib/print/libpapi-lpd/common/mapfile3
12 files changed, 168 insertions, 154 deletions
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 ;