Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Zu3MM-0003s7-Ok for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Nov 2015 19:04:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Zu3MM-0005ha-3U for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Nov 2015 19:04:38 +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) (envelope-from ) id 1ZtrUR-0000o4-5Z for pgsql-bugs@postgresql.org; Wed, 04 Nov 2015 06:24:11 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZtrUJ-0001YF-IU for pgsql-bugs@postgresql.org; Wed, 04 Nov 2015 06:24:10 +0000 MIME-Version: 1.0 Subject: BUG #13755: pgwin32_is_service not checking if SECURITY_SERVICE_SID is disabled To: pgsql-bugs@postgresql.org From: breen@rtda.com Date: Wed, 04 Nov 2015 06:23:15 +0000 Message-ID: <20151104062315.2745.67143@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.2 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following bug has been logged on the website: Bug reference: 13755 Logged by: Breen Hagan Email address: breen@rtda.com PostgreSQL version: 9.4.4 Operating system: Windows 8.1 Description: Short version: pgwin32_is_service checks the process token for SECURITY_SERVICE_RID by doing an EqualSid check. This will match against a SECURITY_SERVICE_RID that has been disabled ("use_for_deny_only"), causing PG to think it's a service when it is not. This causes it to attempt to log to the event log, but this doesn't work, and so there is no logging at all. Long version: We ship PG with our own product, which may or may not be installed as a service. When running PG, we run postgres.exe directly via a Tcl-based wrapper script so that we can monitor the output in real time. This works as expected when our product is not being run as a service. When our product is installed as a service, we use CreateRestrictedToken to disable all admin rights as well as the SECURITY_SERVICE_RID, and use the returned token with CreateProcessAsUser, for which we also specify CREATE_NEW_CONSOLE. This process then calls our wrapper script. Inside this wrapper, I can call GetStdHandle (via Twapi) and get valid handles for all 3: in, out, and err. Yet when the script calls postgres.exe, nothing is received on the output. As mentioned above, nothing is logged in the event log, either. If you look at https://msdn.microsoft.com/en-us/library/windows/desktop/aa379554(v=vs.85).aspx, this code is very similar to pgwin32_is_service (except that it looks for Admins), but also checks the attributes on the SID to see if it is enabled, or used for deny only. I believe this check needs to be added to pgwin32_is_service. Thanks! -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs