Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oODsY-0004l6-FN for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Aug 2022 07:54:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oODsX-0000lF-Cr for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Aug 2022 07:54:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oODsX-0000l6-2j for pgsql-hackers@lists.postgresql.org; Wed, 17 Aug 2022 07:54:17 +0000 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oODsU-0002aH-A1 for pgsql-hackers@postgresql.org; Wed, 17 Aug 2022 07:54:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1660722854; x=1692258854; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=wdK01eEWvicFVT3PUpnkOIC4+sQ14/JqoiUUec7JAc4=; b=WduCa2avBDs1aqUijNBf/MOeTtNJftQOC1qUiNExeJVpqRgGWBHZQKV7 z+hxT++rGqt1l0dKupxam77dO5qMOrNCfpQy35zTBZeOPKaVpu7TdoytJ /jbFDwbr2nSPL8eayVAh+Dkz3pUct+GQrzLyO2zVeO3psvzNmgYvOLv/V 0=; X-IronPort-AV: E=Sophos;i="5.93,242,1654560000"; d="scan'208";a="249748005" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1a-b27d4a00.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9102.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2022 07:53:56 +0000 Received: from EX13D03EUC003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1a-b27d4a00.us-east-1.amazon.com (Postfix) with ESMTPS id 0D0C2811A6; Wed, 17 Aug 2022 07:53:53 +0000 (UTC) Received: from [192.168.2.49] (10.43.161.227) by EX13D03EUC003.ant.amazon.com (10.43.164.192) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Wed, 17 Aug 2022 07:53:49 +0000 Message-ID: <2541c086-e370-d114-69a7-b48b05b25471@amazon.com> Date: Wed, 17 Aug 2022 09:53:45 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 Subject: Re: [PATCH] Expose port->authn_id to extensions and triggers To: Jacob Champion CC: Michael Paquier , Joe Conway , Robert Haas , Tom Lane , "sfrost@snowman.net" , "rjuju123@gmail.com" , "pgsql-hackers@postgresql.org" , "andres@anarazel.de" References: <34308245-ea21-82ee-b1fd-00b4766f3527@amazon.com> <2a1e2717-8c68-3f9e-1e02-32da71deb327@amazon.com> <127bd019-04f0-313c-551c-d949cdc4ad50@amazon.com> <520bd3ce-334b-b9c2-2130-858fb04ce56f@amazon.com> Content-Language: en-US From: "Drouvot, Bertrand" In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.43.161.227] X-ClientProxiedBy: EX13D15UWB002.ant.amazon.com (10.43.161.9) To EX13D03EUC003.ant.amazon.com (10.43.164.192) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 8/16/22 6:58 PM, Jacob Champion wrote: > Sounds good. v3, attached, should make the requested changes: > - declare `struct ClientConnectionInfo` > - use an intermediate serialization struct > - switch to length-"prefixing" for the string > > I do like the way this reads compared to before. Thanks for the new version! +       /* Copy authn_id into the space after the struct. */ +       if (serialized.authn_id_len >= 0) Maybe remove the "." at the end of the comment? (to be consistent with the other comment just above) +/* + * Restore MyClientConnectionInfo from its serialized representation. + */ +void +RestoreClientConnectionInfo(char *conninfo) +{ +       SerializedClientConnectionInfo serialized; +       char       *authn_id; Move "char       *authn_id;" in the "if (serialized.authn_id_len >= 0)" below? + +       memcpy(&serialized, conninfo, sizeof(serialized)); +       authn_id = conninfo + sizeof(serialized); Move "authn_id = conninfo + sizeof(serialized)" in the "if (serialized.authn_id_len >= 0)" below? + +       /* Copy the fields back into place. */ Remove the "." at the end of the comment? +       MyClientConnectionInfo.authn_id = NULL; +       MyClientConnectionInfo.auth_method = serialized.auth_method; + +       if (serialized.authn_id_len >= 0) +               MyClientConnectionInfo.authn_id = MemoryContextStrdup(TopMemoryContext, + authn_id); This instead?     if (serialized.authn_id_len >= 0)     {         char       *authn_id;         authn_id = conninfo + sizeof(serialized);         MyClientConnectionInfo.authn_id = MemoryContextStrdup(TopMemoryContext, authn_id);     } + src/backend/utils/init/miscinit.c:RestoreClientConnectionInfo(char *conninfo) + src/include/miscadmin.h:extern void RestoreClientConnectionInfo(char *procinfo); conninfo in both to be consistent? Apart from the comments above, that looks good to me. Regards, -- Bertrand Drouvot Amazon Web Services: https://aws.amazon.com