From owner-svn-src-all@FreeBSD.ORG Fri Jun 14 00:30:12 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 87BDB8B1; Fri, 14 Jun 2013 00:30:12 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 5FF9A13B8; Fri, 14 Jun 2013 00:30:12 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5E0UCGp079544; Fri, 14 Jun 2013 00:30:12 GMT (envelope-from rmacklem@svn.freebsd.org) Received: (from rmacklem@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r5E0UCKN079543; Fri, 14 Jun 2013 00:30:12 GMT (envelope-from rmacklem@svn.freebsd.org) Message-Id: <201306140030.r5E0UCKN079543@svn.freebsd.org> From: Rick Macklem Date: Fri, 14 Jun 2013 00:30:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r251721 - stable/8/usr.sbin/gssd X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Jun 2013 00:30:12 -0000 Author: rmacklem Date: Fri Jun 14 00:30:11 2013 New Revision: 251721 URL: http://svnweb.freebsd.org/changeset/base/251721 Log: MFC: r250176 Fix the getpwuid_r() call in the gssd daemon so that it handles the ERANGE error return case. Without this fix, authentication of users for certain system setups could fail unexpectedly. Modified: stable/8/usr.sbin/gssd/gssd.c Directory Properties: stable/8/usr.sbin/gssd/ (props changed) Modified: stable/8/usr.sbin/gssd/gssd.c ============================================================================== --- stable/8/usr.sbin/gssd/gssd.c Fri Jun 14 00:03:43 2013 (r251720) +++ stable/8/usr.sbin/gssd/gssd.c Fri Jun 14 00:30:11 2013 (r251721) @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -475,8 +476,11 @@ gssd_pname_to_uid_1_svc(pname_to_uid_arg { gss_name_t name = gssd_find_resource(argp->pname); uid_t uid; - char buf[128]; + char buf[1024], *bufp; struct passwd pwd, *pw; + size_t buflen; + int error; + static size_t buflen_hint = 1024; memset(result, 0, sizeof(*result)); if (name) { @@ -485,7 +489,24 @@ gssd_pname_to_uid_1_svc(pname_to_uid_arg name, argp->mech, &uid); if (result->major_status == GSS_S_COMPLETE) { result->uid = uid; - getpwuid_r(uid, &pwd, buf, sizeof(buf), &pw); + buflen = buflen_hint; + for (;;) { + pw = NULL; + bufp = buf; + if (buflen > sizeof(buf)) + bufp = malloc(buflen); + if (bufp == NULL) + break; + error = getpwuid_r(uid, &pwd, bufp, buflen, + &pw); + if (error != ERANGE) + break; + if (buflen > sizeof(buf)) + free(bufp); + buflen += 1024; + if (buflen > buflen_hint) + buflen_hint = buflen; + } if (pw) { int len = NGRPS; int groups[NGRPS]; @@ -502,6 +523,8 @@ gssd_pname_to_uid_1_svc(pname_to_uid_arg result->gidlist.gidlist_len = 0; result->gidlist.gidlist_val = NULL; } + if (bufp != NULL && buflen > sizeof(buf)) + free(bufp); } } else { result->major_status = GSS_S_BAD_NAME;