Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aj6ru-0002V2-CO for pgsql-bugs@arkaria.postgresql.org; Thu, 24 Mar 2016 15:08:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1aj6rt-000386-VI for pgsql-bugs@arkaria.postgresql.org; Thu, 24 Mar 2016 15:08:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1aj6rF-0001ju-Vd; Thu, 24 Mar 2016 15:07:34 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1aj6r7-0007ws-K6; Thu, 24 Mar 2016 15:07:32 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 1D90C4621C; Thu, 24 Mar 2016 15:07:22 +0000 (UTC) Received: from localhost (vpn-232-136.phx2.redhat.com [10.3.232.136]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2OF7LXm005833; Thu, 24 Mar 2016 11:07:21 -0400 From: Robbie Harwood To: Christian Ullrich Cc: PostgreSQL-development , pgsql-bugs Subject: Re: [HACKERS] BUG #13854: SSPI authentication failure: wrong realm name used In-Reply-To: <56EEC584.1080702@chrullrich.net> References: <20160108002526.16053.79037@wrigleys.postgresql.org> <56EEC584.1080702@chrullrich.net> User-Agent: Notmuch/0.21 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-pc-linux-gnu) Date: Thu, 24 Mar 2016 11:07:16 -0400 Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Pg-Spam-Score: -6.9 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Christian Ullrich writes: > Updated patch attached. I unfortunately don't have windows machines to test this on, but I thought it might be helpful to review this anyway since I'm touching code in the same general area (GSSAPI). And as far as I can tell, you don't break anything there; master continues to behave as expected. Some comments inline: > pg_SSPI_recvauth(Port *port) > { > int mtype; > + int status; The section of this function for include_realm checking already uses an int status return code (retval). I would expect to see them share a variable rather than have both "retval" and "status". > + status =3D pg_SSPI_make_upn(accountname, sizeof(accountname), > + domainname, sizeof(domainname), > + port->hba->upn_username); This is the only place I see that this function is called. That being the case, why bother with the sizes of parameters? Why doesn't pg_SSPI_make_upn() just call sizeof() by itself rather than taking those as arguments? > + /* Build SAM name (DOMAIN\\user), then translate to UPN > + (user@kerberos.realm). The realm name is returned in > + lower case, but that is fine because in SSPI auth, > + string comparisons are always case-insensitive. */ Since we're already considering changing things: this is not the comment style for this file (though it is otherwise a good comment). > + upname =3D (char*)palloc(upnamesize); I don't believe this cast is typically included. > + /* Replace domainname with realm name. */ > + if (upnamerealmsize > domainnamesize) > + { > + pfree(upname); > + ereport(LOG, > + (errcode(ERRCODE_INVALID_ROLE_SPECIFICATION), > + errmsg("realm name too long"))); > + return STATUS_ERROR; > + } > +=20 > + /* Length is now safe. */ > + strcpy(domainname, p+1); Is this an actual fail state or something born out of convenience? A naive reading of this code doesn't explain why it's forbidden for the upn realm to be longer than the domain name. > + /* Replace account name as well (in case UPN !=3D SAM)? */ > + if (update_accountname) > + { > + if ((p - upname + 1) > accountnamesize) > + { > + pfree(upname); > + ereport(LOG, > + (errcode(ERRCODE_INVALID_ROLE_SPECIFICATION), > + errmsg("translated account name too long"))); > + return STATUS_ERROR; > + } > +=20 > + *p =3D 0; > + strcpy(accountname, upname); Same as above. Minus the few small things above, this looks good to me, assuming it resolves the issue. =2D-Robbie --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJW9AKkAAoJECUy+RdqlaRCioQQAIwg3FdHIluKA4pJyEuvlhB7 gF2U7Nb4wHM41AAvsEe4d+zvpYzajAFtyWh/y30eFCDE+8ZTnVT8boyxm/3boQBs Pvdg1XZp+8LzG0yeCqr4txBhrN1J6n587GYG08HZQheSeW7HL4GUBS3/zAEZ16vj vfqhSOw7+BiaZhDhMFMDFcd3aBLpj25Xwsh4g8+szLAOT31q4edo3XOQfi0GJjwn 9G5gG1iYpKgXrK98QHUXwcU/bn1oMmyHrbUQoADJP35hL73fSuUABZjF7KEhWno5 nF19ojVZIpu/9q35dMrnxFwW6N69Q8HXiKTcPKYaio7vqExO+wCuAl/w162fYEF+ FHXnBojK97I3IbQNB9yuc/911n5A2uz4YPP8vmrgKRkaBDbRlkXhw99UaXAiZl2v +wEUolqNBKj6txQKQVnLYh/GHzhUMSXJl/8ifPWIMQj0pFhy9Q/QX0fJYRqXIfmw vmXn72whkakfc00uTcYPHjXydNZEvMq2GkOowgpSRIRyb9BCiC9YtFL81zM1FGmK XFqRapEyphYi2zguRZnsWAVfpkAh+Ak3skZgvcBGA+C6nrNBU7tramFNMcDekz0+ Q6KWGCZGq/Ss43DY/8udtHs9biCn3O+An6ZVJRygwt5elaFOyJyVTR6s8hWf7FIU BnMWwrxQAbXIORbZu/Pe =CTSz -----END PGP SIGNATURE----- --=-=-=--