Import libnss-pgsql version 1.5.0-beta as databases/nss-pgsql

Packaged by Matthew Bauer <matthew.justin.bauer@gmail.com> during Google Code-In.

Name Service Switch module for PostgreSQL.
This commit is contained in:
asau 2013-03-17 14:12:02 +00:00
parent 116f9cdf5d
commit a21b3c1214
12 changed files with 794 additions and 0 deletions

View file

@ -0,0 +1,7 @@
# $NetBSD: DEINSTALL
case ${STAGE} in
POST-DEINSTALL)
rm -f /usr/lib/libnss_pgsql.so.2
;;
esac

View file

@ -0,0 +1 @@
Name Service Switch module for PostgreSQL.

View file

@ -0,0 +1,7 @@
# $NetBSD: INSTALL
case ${STAGE} in
POST-INSTALL)
ln -sf ${PREFIX}/lib/libnss_pgsql.so.2 /usr/lib/libnss_pgsql.so.2
;;
esac

View file

@ -0,0 +1,38 @@
# $NetBSD: Makefile,v 1.1.1.1 2013/03/17 14:12:02 asau Exp $
DISTNAME= libnss-pgsql-1.5.0-beta
PKGNAME= nss-pgsql-1.5.0b
CATEGORIES= databases
MASTER_SITES= http://pgfoundry.org/frs/download.php/1878/
EXTRACT_SUFX= .tgz
MAINTAINER= pkgsrc-users@NetBSD.org
HOMEPAGE= http://pgfoundry.org/projects/sysauth
COMMENT= Name Service Switch module for PostgreSQL
LICENSE= gnu-gpl-v2
GNU_CONFIGURE= yes
USE_LIBTOOL= yes
USE_TOOLS+= gmake
CONFIGURE_ARGS+= --with-docdir=${PREFIX}/share/doc/nss-pgsql/
EGDIR= ${PREFIX}/share/examples/nss-pgsql
CONF_FILES+= ${EGDIR}/nss-pgsql.conf ${PKG_SYSCONFDIR}/nss-pgsql.conf
INSTALLATION_DIRS+= share/doc/nss-pgsql ${EGDIR}
post-extract:
${CP} ${FILESDIR}/netbsd.c ${FILESDIR}/netbsd.h ${WRKSRC}/src/
post-install:
${INSTALL_DATA} ${WRKSRC}/conf/* ${DESTDIR}${EGDIR}/
${INSTALL_DATA} ${WRKSRC}/README ${DESTDIR}${PREFIX}/share/doc/nss-pgsql/
${INSTALL_DATA} ${WRKSRC}/INSTALL ${DESTDIR}${PREFIX}/share/doc/nss-pgsql/
${INSTALL_DATA} ${WRKSRC}/TODO ${DESTDIR}${PREFIX}/share/doc/nss-pgsql/
${INSTALL_DATA} ${WRKSRC}/NEWS ${DESTDIR}${PREFIX}/share/doc/nss-pgsql/
${INSTALL_DATA} ${WRKSRC}/COPYING ${DESTDIR}${PREFIX}/share/doc/nss-pgsql/
${INSTALL_DATA} ${WRKSRC}/AUTHORS ${DESTDIR}${PREFIX}/share/doc/nss-pgsql/
.include "../../mk/pgsql.buildlink3.mk"
.include "../../mk/bsd.pkg.mk"

14
databases/nss-pgsql/PLIST Normal file
View file

@ -0,0 +1,14 @@
@comment $NetBSD: PLIST,v 1.1.1.1 2013/03/17 14:12:02 asau Exp $
lib/libnss_pgsql.la
share/doc/nss-pgsql/AUTHORS
share/doc/nss-pgsql/COPYING
share/doc/nss-pgsql/INSTALL
share/doc/nss-pgsql/NEWS
share/doc/nss-pgsql/README
share/doc/nss-pgsql/TODO
share/doc/nss-pgsql/caution.png
share/doc/nss-pgsql/nss-pgsql.html
share/examples/nss-pgsql/dbschema.sql
share/examples/nss-pgsql/nss-pgsql-root.conf
share/examples/nss-pgsql/nss-pgsql.conf
share/examples/nss-pgsql/nsswitch.conf

View file

@ -0,0 +1,9 @@
$NetBSD: distinfo,v 1.1.1.1 2013/03/17 14:12:02 asau Exp $
SHA1 (libnss-pgsql-1.5.0-beta.tgz) = 69cc58a849a58226a6321c0cd02e150f2d4a81ad
RMD160 (libnss-pgsql-1.5.0-beta.tgz) = 9a81a636d69211a27e07084a3303f55e76e9786f
Size (libnss-pgsql-1.5.0-beta.tgz) = 305543 bytes
SHA1 (patch-config.h.in) = 988a8f524d73b053b15617dfe83eeb80851fd941
SHA1 (patch-src_Makefile.in) = 416c72f8ccdeeee6e832245097ee34890684e5fe
SHA1 (patch-src_backend.c) = 7a718b1419b39adbe657c82ece62d0e538ef0059
SHA1 (patch-src_nss-pgsql.h) = 5e77c19649be46cdefbdfe307aca90eb10453fc7

View file

@ -0,0 +1,544 @@
// $NetBSD: netbsd.c,v 1.1.1.1 2013/03/17 14:12:02 asau Exp $
// Add necessary functions not provided by NetBSD's NSS
#include <sys/param.h>
#include <pwd.h>
#include <grp.h>
#include <nsswitch.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "netbsd.h"
typedef enum nss_status NSS_STATUS;
extern NSS_STATUS _nss_pgsql_setpwent(void);
static int netbsd_setpwent(void *, void *, va_list);
static int netbsd_setpassent(void *, void *, va_list);
extern NSS_STATUS _nss_pgsql_endpwent(void);
static int netbsd_endpwent(void *, void *, va_list);
extern NSS_STATUS _nss_pgsql_getpwent_r(struct passwd *,
char *, size_t, int *);
static int netbsd_getpwent(void *, void *, va_list);
static int netbsd_getpwent_r(void *, void *, va_list);
extern NSS_STATUS _nss_pgsql_getpwnam_r(const char *, struct passwd *,
char *, size_t, int *);
static int netbsd_getpwnam(void *, void *, va_list);
static int netbsd_getpwnam_r(void *, void *, va_list);
extern NSS_STATUS _nss_pgsql_getpwuid_r(uid_t, struct passwd *,
char *, size_t, int *);
static int netbsd_getpwuid(void *, void *, va_list);
static int netbsd_getpwuid_r(void *, void *, va_list);
extern NSS_STATUS _nss_pgsql_setgrent(void);
static int netbsd_setgrent(void *, void *, va_list);
static int netbsd_setgroupent(void *, void *, va_list);
extern NSS_STATUS _nss_pgsql_endgrent(void);
static int netbsd_endgrent(void *, void *, va_list);
extern NSS_STATUS _nss_pgsql_getgrent_r(struct group *,
char *, size_t, int *);
static int netbsd_getgrent(void *, void *, va_list);
static int netbsd_getgrent_r(void *, void *, va_list);
extern NSS_STATUS _nss_pgsql_getgrnam_r(const char *, struct group *,
char *, size_t, int *);
static int netbsd_getgrnam(void *, void *, va_list);
static int netbsd_getgrnam_r(void *, void *, va_list);
extern NSS_STATUS _nss_pgsql_getgrgid_r(gid_t, struct group *,
char *, size_t, int *);
static int netbsd_getgrgid(void *, void *, va_list);
static int netbsd_getgrgid_r(void *, void *, va_list);
extern NSS_STATUS _nss_pgsql_initgroups_dyn(const char *, gid_t, long int *,
long int *, gid_t **, long int, int *);
static int netbsd_getgroupmembership(void *, void *, va_list);
static int nss2netbsderr[] = {
NS_SUCCESS, NS_NOTFOUND, NS_UNAVAIL, NS_TRYAGAIN, NS_RETURN
};
static struct passwd rpw;
static struct group rg;
static char pwbuf[1024];
static char *grpbuf;
static size_t grpbuflen;
static ns_mtab methods[] = {
{ NSDB_PASSWD, "setpwent", netbsd_setpwent, 0 },
{ NSDB_PASSWD, "setpassent", netbsd_setpassent, 0 },
{ NSDB_PASSWD, "endpwent", netbsd_endpwent, 0 },
{ NSDB_PASSWD, "getpwent", netbsd_getpwent, 0 },
{ NSDB_PASSWD, "getpwent_r", netbsd_getpwent_r, 0 },
{ NSDB_PASSWD, "getpwnam", netbsd_getpwnam, 0 },
{ NSDB_PASSWD, "getpwnam_r", netbsd_getpwnam_r, 0 },
{ NSDB_PASSWD, "getpwuid", netbsd_getpwuid, 0 },
{ NSDB_PASSWD, "getpwuid_r", netbsd_getpwuid_r, 0 },
{ NSDB_GROUP, "setgrent", netbsd_setgrent, 0 },
{ NSDB_GROUP, "setgroupent", netbsd_setgroupent, 0 },
{ NSDB_GROUP, "endgrent", netbsd_endgrent, 0 },
{ NSDB_GROUP, "getgrent", netbsd_getgrent, 0 },
{ NSDB_GROUP, "getgrent_r", netbsd_getgrent_r, 0 },
{ NSDB_GROUP, "getgrnam", netbsd_getgrnam, 0 },
{ NSDB_GROUP, "getgrnam_r", netbsd_getgrnam_r, 0 },
{ NSDB_GROUP, "getgrgid", netbsd_getgrgid, 0 },
{ NSDB_GROUP, "getgrgid_r", netbsd_getgrgid_r, 0 },
{ NSDB_GROUP, "getgroupmembership", netbsd_getgroupmembership, 0 },
};
static int
netbsd_setpwent(void *rv, void *cb_data, va_list ap)
{
NSS_STATUS s;
s = _nss_pgsql_setpwent();
return nss2netbsderr[s];
}
static int
netbsd_setpassent(void *rv, void *cb_data, va_list ap)
{
NSS_STATUS s;
int *retval = va_arg(ap, int *);
int stayopen = va_arg(ap, int);
/* XXX stayopen ignored */
s = _nss_pgsql_setpwent();
if (s == NSS_STATUS_SUCCESS)
*retval = 1;
else
*retval = 0;
return nss2netbsderr[s];
}
static int
netbsd_endpwent(void *rv, void *cb_data, va_list ap)
{
NSS_STATUS s;
s = _nss_pgsql_endpwent();
return nss2netbsderr[s];
}
static int
netbsd_getpwent(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
struct passwd **retval = va_arg(ap, struct passwd **);
memset(&rpw, 0, sizeof(rpw));
s = _nss_pgsql_getpwent_r(&rpw, pwbuf, sizeof(pwbuf), &err);
if (s == NSS_STATUS_SUCCESS) {
rpw.pw_class = ""; /* XXX */
*retval = &rpw;
} else
*retval = 0;
return nss2netbsderr[s];
}
static int
netbsd_getpwent_r(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
int *retval = va_arg(ap, int *);
struct passwd *pw = va_arg(ap, struct passwd *);
char *buf = va_arg(ap, char *);
size_t buflen = va_arg(ap, size_t);
struct passwd **result = va_arg(ap, struct passwd **);
memset(pw, 0, sizeof(*pw));
s = _nss_pgsql_getpwent_r(pw, buf, buflen, &err);
if (s == NSS_STATUS_SUCCESS) {
pw->pw_class = ""; /* XXX */
*result = pw;
} else
*result = 0;
if (s == NSS_STATUS_SUCCESS || s == NSS_STATUS_NOTFOUND)
*retval = 0;
else
*retval = 1;
return nss2netbsderr[s];
}
static int
netbsd_getpwnam(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
struct passwd **retval = va_arg(ap, struct passwd **);
const char *name = va_arg(ap, const char *);
memset(&rpw, 0, sizeof(rpw));
s = _nss_pgsql_getpwnam_r(name, &rpw, pwbuf, sizeof(pwbuf), &err);
if (s == NSS_STATUS_SUCCESS) {
rpw.pw_class = ""; /* XXX */
*retval = &rpw;
} else
*retval = 0;
return nss2netbsderr[s];
}
static int
netbsd_getpwnam_r(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
int *retval = va_arg(ap, int *);
const char *name = va_arg(ap, const char *);
struct passwd *pw = va_arg(ap, struct passwd *);
char *buf = va_arg(ap, char *);
size_t buflen = va_arg(ap, size_t);
struct passwd **result = va_arg(ap, struct passwd **);
memset(pw, 0, sizeof(*pw));
s = _nss_pgsql_getpwnam_r(name, pw, buf, buflen, &err);
if (s == NSS_STATUS_SUCCESS) {
pw->pw_class = ""; /* XXX */
*result = pw;
} else
*result = 0;
if (s == NSS_STATUS_SUCCESS || s == NSS_STATUS_NOTFOUND)
*retval = 0;
else
*retval = 1;
return nss2netbsderr[s];
}
static int
netbsd_getpwuid(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
struct passwd **retval = va_arg(ap, struct passwd **);
uid_t uid = va_arg(ap, uid_t);
memset(&rpw, 0, sizeof(rpw));
s = _nss_pgsql_getpwuid_r(uid, &rpw, pwbuf, sizeof(pwbuf), &err);
if (s == NSS_STATUS_SUCCESS) {
rpw.pw_class = ""; /* XXX */
*retval = &rpw;
} else
*retval = 0;
return nss2netbsderr[s];
}
static int
netbsd_getpwuid_r(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
int *retval = va_arg(ap, int *);
uid_t uid = va_arg(ap, uid_t);
struct passwd *pw = va_arg(ap, struct passwd *);
char *buf = va_arg(ap, char *);
size_t buflen = va_arg(ap, size_t);
struct passwd **result = va_arg(ap, struct passwd **);
memset(pw, 0, sizeof(*pw));
s = _nss_pgsql_getpwuid_r(uid, pw, buf, buflen, &err);
if (s == NSS_STATUS_SUCCESS) {
pw->pw_class = ""; /* XXX */
*result = pw;
} else
*result = 0;
if (s == NSS_STATUS_SUCCESS || s == NSS_STATUS_NOTFOUND)
*retval = 0;
else
*retval = 1;
return nss2netbsderr[s];
}
static int
resize_grpbuf()
{
if (grpbuflen > 50000) /* safety guard */
return (-1);
grpbuflen += 1024;
if (grpbuf)
free(grpbuf);
grpbuf = malloc(grpbuflen);
if (!grpbuf)
return (-1);
return (0);
}
static int
netbsd_setgrent(void *rv, void *cb_data, va_list ap)
{
NSS_STATUS s;
s = _nss_pgsql_setgrent();
return nss2netbsderr[s];
}
static int
netbsd_setgroupent(void *rv, void *cb_data, va_list ap)
{
NSS_STATUS s;
int *retval = va_arg(ap, int *);
int stayopen = va_arg(ap, int);
/* XXX stayopen ignored */
s = _nss_pgsql_setgrent();
if (s == NSS_STATUS_SUCCESS)
*retval = 1;
else
*retval = 0;
return nss2netbsderr[s];
}
static int
netbsd_endgrent(void *rv, void *cb_data, va_list ap)
{
NSS_STATUS s;
s = _nss_pgsql_endgrent();
return nss2netbsderr[s];
}
static int
netbsd_getgrent(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
struct group **retval = va_arg(ap, struct group **);
tryagain:
memset(&rg, 0, sizeof(rg));
s = _nss_pgsql_getgrent_r(&rg, grpbuf, grpbuflen, &err);
if (s == NSS_STATUS_SUCCESS)
*retval = &rg;
else if ((s == NSS_STATUS_TRYAGAIN) && (err == ERANGE)
&& (resize_grpbuf() == 0))
goto tryagain;
else
*retval = 0;
return nss2netbsderr[s];
}
static int
netbsd_getgrent_r(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
int *retval = va_arg(ap, int *);
struct group *grp = va_arg(ap, struct group *);
char *buf = va_arg(ap, char *);
size_t buflen = va_arg(ap, size_t);
struct group **result = va_arg(ap, struct group **);
memset(grp, 0, sizeof(*grp));
s = _nss_pgsql_getgrent_r(grp, buf, buflen, &err);
if (s == NSS_STATUS_SUCCESS)
*result = grp;
else
*result = 0;
if (s == NSS_STATUS_SUCCESS || s == NSS_STATUS_NOTFOUND)
*retval = 0;
else
*retval = 1;
return nss2netbsderr[s];
}
static int
netbsd_getgrnam(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
struct group **retval = va_arg(ap, struct group **);
const char *name = va_arg(ap, const char *);
tryagain:
memset(&rg, 0, sizeof(rg));
s = _nss_pgsql_getgrnam_r(name, &rg, grpbuf, grpbuflen, &err);
if (s == NSS_STATUS_SUCCESS)
*retval = &rg;
else if ((s == NSS_STATUS_TRYAGAIN) && (err == ERANGE)
&& (resize_grpbuf() == 0))
goto tryagain;
else
*retval = 0;
return nss2netbsderr[s];
}
static int
netbsd_getgrnam_r(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
int *retval = va_arg(ap, int *);
const char *name = va_arg(ap, const char *);
struct group *grp = va_arg(ap, struct group *);
char *buf = va_arg(ap, char *);
size_t buflen = va_arg(ap, size_t);
struct group **result = va_arg(ap, struct group **);
memset(grp, 0, sizeof(*grp));
s = _nss_pgsql_getgrnam_r(name, grp, buf, buflen, &err);
if (s == NSS_STATUS_SUCCESS)
*result = grp;
else
*result = 0;
if (s == NSS_STATUS_SUCCESS || s == NSS_STATUS_NOTFOUND)
*retval = 0;
else
*retval = 1;
return nss2netbsderr[s];
}
static int
netbsd_getgrgid(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
struct group **retval = va_arg(ap, struct group **);
gid_t gid = va_arg(ap, gid_t);
tryagain:
memset(&rg, 0, sizeof(rg));
s = _nss_pgsql_getgrgid_r(gid, &rg, grpbuf, grpbuflen, &err);
if (s == NSS_STATUS_SUCCESS)
*retval = &rg;
else if ((s == NSS_STATUS_TRYAGAIN) && (err == ERANGE)
&& (resize_grpbuf() == 0))
goto tryagain;
else
*retval = 0;
return nss2netbsderr[s];
}
static int
netbsd_getgrgid_r(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
int *retval = va_arg(ap, int *);
gid_t gid = va_arg(ap, gid_t);
struct group *grp = va_arg(ap, struct group *);
char *buf = va_arg(ap, char *);
size_t buflen = va_arg(ap, size_t);
struct group **result = va_arg(ap, struct group **);
memset(grp, 0, sizeof(*grp));
s = _nss_pgsql_getgrgid_r(gid, grp, buf, buflen, &err);
if (s == NSS_STATUS_SUCCESS)
*result = grp;
else
*result = 0;
if (s == NSS_STATUS_SUCCESS || s == NSS_STATUS_NOTFOUND)
*retval = 0;
else
*retval = 1;
return nss2netbsderr[s];
}
/* addgid helper from NetBSD's getgroupmembership.c */
static int
__gr_addgid(gid_t gid, gid_t *groups, int maxgrp, int *groupc)
{
int ret, dupc;
/* skip duplicates */
for (dupc = 0; dupc < MIN(maxgrp, *groupc); dupc++) {
if (groups[dupc] == gid)
return 1;
}
ret = 1;
if (*groupc < maxgrp) /* add this gid */
groups[*groupc] = gid;
else
ret = 0;
(*groupc)++;
return ret;
}
static int
netbsd_getgroupmembership(void *rv, void *cb_data, va_list ap)
{
int err;
NSS_STATUS s;
int *retval = va_arg(ap, int *);
const char *user = va_arg(ap, const char *);
gid_t group = va_arg(ap, gid_t);
gid_t *groups = va_arg(ap, gid_t *);
int limit = va_arg(ap, int);
int *size = va_arg(ap, int*);
gid_t *tmpgroups;
long int lstart, lsize;
int i;
tmpgroups = malloc(limit * sizeof(gid_t));
if (!tmpgroups)
return NS_TRYAGAIN;
/* insert primary membership */
__gr_addgid(group, groups, limit, size);
lstart = 0;
lsize = limit;
s = _nss_pgsql_initgroups_dyn(user, group, &lstart, &lsize,
&tmpgroups, 0, &err);
if (s == NSS_STATUS_SUCCESS) {
for (i = 0; i < lstart; i++)
if (! __gr_addgid(tmpgroups[i], groups, limit, size))
*retval = -1;
s = NSS_STATUS_NOTFOUND;
}
free(tmpgroups);
return nss2netbsderr[s];
}
ns_mtab *
nss_module_register(const char *source, unsigned int *mtabsize,
nss_module_unregister_fn *unreg)
{
*mtabsize = sizeof(methods)/sizeof(methods[0]);
*unreg = NULL;
if (resize_grpbuf())
return 0;
return (methods);
}

View file

@ -0,0 +1,14 @@
// $NetBSD: netbsd.h,v 1.1.1.1 2013/03/17 14:12:02 asau Exp $
// add necessary functions that is not provided by NetBSD's NSS
#ifndef _NSS_PGSQL_NETBSD_H
#define _NSS_PGSQL_NETBSD_H
enum nss_status {
NSS_STATUS_SUCCESS,
NSS_STATUS_NOTFOUND,
NSS_STATUS_UNAVAIL,
NSS_STATUS_TRYAGAIN,
NSS_STATUS_RETURN
};
#endif /* _NSS_PGSQL_NETBSD_H */

View file

@ -0,0 +1,30 @@
# $NetBSD: patch-config.h.in,v 1.1.1.1 2013/03/17 14:12:02 asau Exp $
Defines NSSWITCH_H and SHADOW_H variables
--- config.h.in.orig 2008-08-19 10:10:55.000000000 +0000
+++ config.h.in
@@ -25,10 +25,14 @@
/* Define to 1 if you have the <nss.h> header file. */
#undef HAVE_NSS_H
+#undef HAVE_NSSWITCH_H
+
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
and to 0 otherwise. */
#undef HAVE_REALLOC
+#undef HAVE_SHADOW_H
+
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
@@ -106,3 +110,8 @@
/* Define to `int' if <sys/types.h> doesn't define. */
#undef uid_t
+
+#ifdef __NetBSD__
+#include "netbsd.h"
+#endif
+

View file

@ -0,0 +1,15 @@
# $NetBSD: patch-src_Makefile.in,v 1.1.1.1 2013/03/17 14:12:02 asau Exp $
Adds netbsd.c to source list - should we make it only used by NetBSD?
--- src/Makefile.in.orig 2008-08-19 10:10:56.000000000 +0000
+++ src/Makefile.in
@@ -86,7 +86,7 @@ VERSION = @VERSION@
docdir = @docdir@
lib_LTLIBRARIES = libnss_pgsql.la
-libnss_pgsql_la_SOURCES = interface.c config.c backend.c util.c
+libnss_pgsql_la_SOURCES = interface.c config.c backend.c util.c netbsd.c
libnss_pgsql_la_LDFLAGS = -module -version-info 2
EXTRA_DIST = nss-pgsql.h
mkinstalldirs = $(SHELL) $(top_srcdir)/autoconf/mkinstalldirs

View file

@ -0,0 +1,76 @@
# $NetBSD: patch-src_backend.c,v 1.1.1.1 2013/03/17 14:12:02 asau Exp $
Changes name of libpq-fe.h so it works on our PostgreSQL installation
Reorders list of copy_attr_colname as it references copy_attr_string
--- src/backend.c.orig 2008-08-19 09:44:37.000000000 +0000
+++ src/backend.c
@@ -11,7 +11,7 @@
*/
#include "nss-pgsql.h"
-#include <postgresql/libpq-fe.h>
+#include <libpq-fe.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -205,22 +205,6 @@ inline void getent_close(char type)
Assign a single value to *valptr from the specified row in the result
*/
enum nss_status
-copy_attr_colnum(PGresult *res, int attrib_number, char **valptr,
- char **buffer, size_t *buflen, int *errnop, int row)
-{
-
- const char *sptr;
- size_t slen;
-
- sptr = PQgetvalue(res, row, attrib_number);
- return copy_attr_string(sptr, valptr, buffer, buflen, errnop);
-}
-
-/*
- With apologies to nss_ldap...
- Assign a single value to *valptr from the specified row in the result
-*/
-enum nss_status
copy_attr_string(char *sptr, char **valptr,
char **buffer, size_t *buflen, int *errnop)
{
@@ -244,6 +228,22 @@ copy_attr_string(char *sptr, char **valp
}
/*
+ With apologies to nss_ldap...
+ Assign a single value to *valptr from the specified row in the result
+*/
+enum nss_status
+copy_attr_colnum(PGresult *res, int attrib_number, char **valptr,
+ char **buffer, size_t *buflen, int *errnop, int row)
+{
+
+ const char *sptr;
+ size_t slen;
+
+ sptr = PQgetvalue(res, row, attrib_number);
+ return copy_attr_string(sptr, valptr, buffer, buflen, errnop);
+}
+
+/*
* return array of strings containing usernames that are member of group with gid 'gid'
*/
enum nss_status getgroupmem(gid_t gid,
@@ -778,6 +778,7 @@ size_t backend_initgroups_dyn(const char
return *start;
}
+#ifdef HAVE_SHADOW_H
/*
* 'convert' a PGresult to struct shadow
*/
@@ -863,4 +864,4 @@ enum nss_status backend_getspnam(const c
return status;
}
-
+#endif

View file

@ -0,0 +1,39 @@
# $NetBSD: patch-src_nss-pgsql.h,v 1.1.1.1 2013/03/17 14:12:02 asau Exp $
Adds checks for header files
--- src/nss-pgsql.h.orig 2006-01-09 22:33:07.000000000 +0000
+++ src/nss-pgsql.h
@@ -11,11 +11,15 @@
# ifdef HAVE_NSS_H
# include <nss.h>
+# elsif HAVE_NSSWITCH_H
+# include <nsswitch.h>
# endif
# include <pwd.h>
# include <grp.h>
-# include <shadow.h>
+# ifdef HAVE_SHADOW_H
+# include <shadow.h>
+# endif
# include <sys/types.h>
#define CFGFILE SYSCONFDIR"/nss-pgsql.conf"
@@ -71,6 +75,7 @@ size_t backend_initgroups_dyn(const char
long int limit,
int *errnop);
+#ifdef HAVE_SHADOW_H
enum nss_status backend_getspent(struct spwd *result,
char *buffer,
size_t buflen,
@@ -82,6 +87,7 @@ enum nss_status backend_getspnam(const c
size_t buflen,
int *errnop);
+#endif
void print_err(const char *msg, ...);
void print_msg(const char *msg, ...);