From: Robbie Harwood <rharwood@redhat.com>
To: Christian Ullrich <chris@chrullrich.net>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: [HACKERS] BUG #13854: SSPI authentication failure: wrong realm name used
Date: Thu, 24 Mar 2016 11:07:16 -0400
Message-ID: <jlgmvpnvrrv.fsf@thriss.redhat.com> (raw)
In-Reply-To: <56EEC584.1080702@chrullrich.net>
References: <20160108002526.16053.79037@wrigleys.postgresql.org>
<n6u4g6$5o6$1@ger.gmane.org>
<n6u6n5$6fh$1@ger.gmane.org>
<n7blsf$g5n$1@ger.gmane.org>
<CABUevEyrSAGhr4HQYdFjNwEETwQ0mnS_8PUptaYCijdv-ZsDiw@mail.gmail.com>
<AM2PR06MB06903FBF291A84BB85263437D4B50@AM2PR06MB0690.eurprd06.prod.outlook.com>
<56EEC584.1080702@chrullrich.net>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Christian Ullrich <chris@chrullrich.net> 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 = 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 = (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;
> + }
> +
> + /* 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 != 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;
> + }
> +
> + *p = 0;
> + strcpy(accountname, upname);
Same as above.
Minus the few small things above, this looks good to me, assuming it
resolves the issue.
--Robbie
Attachments:
signature.asc (application/pgp-signature, 818B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: rharwood@redhat.com, chris@chrullrich.net, pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] BUG #13854: SSPI authentication failure: wrong realm name used
In-Reply-To: <jlgmvpnvrrv.fsf@thriss.redhat.com>
References: <20160108002526.16053.79037@wrigleys.postgresql.org> <n6u4g6$5o6$1@ger.gmane.org> <n6u6n5$6fh$1@ger.gmane.org> <n7blsf$g5n$1@ger.gmane.org> <CABUevEyrSAGhr4HQYdFjNwEETwQ0mnS_8PUptaYCijdv-ZsDiw@mail.gmail.com> <AM2PR06MB06903FBF291A84BB85263437D4B50@AM2PR06MB0690.eurprd06.prod.outlook.com> <56EEC584.1080702@chrullrich.net> <jlgmvpnvrrv.fsf@thriss.redhat.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox