Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id CB23E650E8F; Thu, 3 Jul 2008 14:41:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 21756-03; Thu, 3 Jul 2008 14:41:41 -0300 (ADT) X-Greylist: delayed 00:05:11.114849 by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp2.exchange.upenn.edu (sesat.exchange.upenn.edu [128.91.3.3]) by postgresql.org (Postfix) with ESMTP id 18E68650E93; Thu, 3 Jul 2008 14:41:43 -0300 (ADT) Received: from isc.upenn.edu (128.91.197.64) by smtp2.exchange.upenn.edu (128.91.2.25) with Microsoft SMTP Server (TLS) id 8.1.278.0; Thu, 3 Jul 2008 13:36:30 -0400 Date: Thu, 3 Jul 2008 13:36:28 -0400 From: Garick Hamlin To: , Subject: Solaris ident authentication using unix domain sockets Message-ID: <20080703173628.GA1697@isc.upenn.edu> References: <20080703165936.E80B312A5FFF@mx2.hub.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20080703165936.E80B312A5FFF@mx2.hub.org> User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200807/172 X-Sequence-Number: 120432 Hi, I have a patch that I have been using to support postgresql's notion of ident authentication when using unix domain sockets on Solaris. This patch basically just adds support for using getupeercred() on Solaris so unix sockets and ident auth works just like it does on Linux and elsewhere. This was my first attempt wrestling with automake. I've tested it builds properly after it is applied and autoreconf is run on RHEL4/Linux/x86. I am using the patch currently on Solaris 10 / x86. Garick diff -cr postgresql_CVS/configure.in postgresql/configure.in *** postgresql_CVS/configure.in Tue Jun 24 15:52:30 2008 --- postgresql/configure.in Tue Jun 24 15:57:22 2008 *************** *** 1095,1101 **** AC_FUNC_ACCEPT_ARGTYPES PGAC_FUNC_GETTIMEOFDAY_1ARG ! AC_CHECK_FUNCS([cbrt dlopen fcvt fdatasync getpeereid getrlimit memmove poll pstat readlink setproctitle setsid sigprocmask symlink sysconf towlower utime utimes waitpid wcstombs]) AC_CHECK_DECLS(fdatasync, [], [], [#include ]) AC_CHECK_DECLS(posix_fadvise, [], [], [#include ]) --- 1095,1101 ---- AC_FUNC_ACCEPT_ARGTYPES PGAC_FUNC_GETTIMEOFDAY_1ARG ! AC_CHECK_FUNCS([getpeerucred cbrt dlopen fcvt fdatasync getpeereid getrlimit memmove poll pstat readlink setproctitle setsid sigprocmask symlink sysconf towlower utime utimes waitpid wcstombs]) AC_CHECK_DECLS(fdatasync, [], [], [#include ]) AC_CHECK_DECLS(posix_fadvise, [], [], [#include ]) diff -cr postgresql_CVS/src/backend/libpq/hba.c postgresql/src/backend/libpq/hba.c *** postgresql_CVS/src/backend/libpq/hba.c Tue Jun 24 15:52:32 2008 --- postgresql/src/backend/libpq/hba.c Tue Jun 24 15:53:00 2008 *************** *** 25,30 **** --- 25,33 ---- #include #include #endif + #if defined(HAVE_GETPEERUCRED) + #include + #endif #include #include #include *************** *** 1500,1505 **** --- 1503,1539 ---- strlcpy(ident_user, pass->pw_name, IDENT_USERNAME_MAX + 1); return true; + #elif defined(HAVE_GETPEERUCRED) /* Solaris > 10 */ + uid_t uid; + gid_t gid; + struct passwd *pass; + int ucred_ok=1; + ucred_t *ucred = NULL; + if (getpeerucred(sock, &ucred) == -1) + ucred_ok = 0; + if (ucred_ok && (uid = ucred_geteuid(ucred)) == -1 ) + ucred_ok = 0; + if (ucred_ok && (gid = ucred_getrgid(ucred)) == -1 ) + ucred_ok = 0; + if (ucred) + ucred_free(ucred); + if (!ucred_ok) { + /* We didn't get a valid credentials struct. */ + ereport(LOG, ( + "could not get peer credentials: %s", + strerror(errno))); + return false; + } + pass = getpwuid(uid); + if (pass == NULL) + { + ereport(LOG, + (errmsg("local user with ID %d does not exist", + (int) uid))); + return false; + } + strlcpy(ident_user, pass->pw_name, IDENT_USERNAME_MAX + 1); + return true; #elif defined(HAVE_STRUCT_CMSGCRED) || defined(HAVE_STRUCT_FCRED) || (defined(HAVE_STRUCT_SOCKCRED) && defined(LOCAL_CREDS)) struct msghdr msg;