Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coQyu-00088N-9J for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Mar 2017 08:42:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1coQys-0001Os-Gm for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Mar 2017 08:41:58 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1coQxM-0005WQ-So for pgsql-hackers@postgresql.org; Thu, 16 Mar 2017 08:40:25 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1coQxJ-000532-88 for pgsql-hackers@postgresql.org; Thu, 16 Mar 2017 08:40:23 +0000 Received: by mail-lf0-x241.google.com with SMTP id v2so2849335lfi.2 for ; Thu, 16 Mar 2017 01:40:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=eLk0g01TyEkVkcSMg0LRlAUyqpodv1izcELjjl2ijt4=; b=ZqVokL/lW5MdJLAydwlKV4/mUuCM2SjUKgrtNkxr8WgmETtdlQZLRteVjdljrE/+4S K0gmi7Ywa0o6SGVm2X596NPOFPyN3oZ+7BXITI6KYrocECRC1pav6hUPpdCySOi8t1/q uxje72wncPbYK1sg04jxYbWcaRsy5wClzc4z5Wv8QDSWBuZByI3+J9qV5bST9Qw2opcG qFAYjgeLeOFt6ze7IdCxgcrmOTZ0/8L062/eLXfYR9/2wCW6DunWpN8EAtjP0/LMtfEO tIA4xLSvXzvXNEwGlpfq9iNtSaxKe1BIzqKfg1fm9ozBv9URbRQg0E9nV0Cdg5IRUXMv eCUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=eLk0g01TyEkVkcSMg0LRlAUyqpodv1izcELjjl2ijt4=; b=iBWMEr217BYx4kPQUtRc9beXc+PmHsbstrpeGBK+tr3YqOOEqZ72oeOl3f1idTlvSE dFOgcWkY8nzZniKYH/O8Ou+vHTBPFfrvuqJGPBXq95hWmhGUQmZvBjOQ7CrabiijpdWk eNJxSbh956YRKOTmnvLStHoN6lE/WZHQMqeJWndfQEOK9lEWAJE9OBhQ4wRl2LKJUyYu 2dda+p7GDi+TY3uNnule9HgGbJmCx1pD+js2rDWNUtKxOImw8jXy8dxiYacUVnQ8vjmH MHjkNQxT6YKqPmZytD+lGsgU7074VyuPcCWI2oARIRcQWRav0D1P9dYYd3zLedRM2URa pF9w== X-Gm-Message-State: AFeK/H223+y17lQY89TZ1SHjHXEHJDXLOkLPf9yBg/a12YgUaPIzYFw683doCiamVLpVOw== X-Received: by 10.46.20.28 with SMTP id u28mr2546083ljd.11.1489653618452; Thu, 16 Mar 2017 01:40:18 -0700 (PDT) Received: from [192.168.1.99] (dsl-hkibrasgw1-50df7f-241.dhcp.inet.fi. [80.223.127.241]) by smtp.gmail.com with ESMTPSA id f137sm774402lff.21.2017.03.16.01.40.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Mar 2017 01:40:17 -0700 (PDT) Subject: Re: BUG #13755: pgwin32_is_service not checking if SECURITY_SERVICE_SID is disabled To: Michael Paquier , "Tsunakawa, Takayuki" References: <952A88FFCBDA419EB6D6556B6A8F29C1@tunaPC> <0A3221C70F24FB45833433255569204D1F63BD65@G01JPEXMBYT05> <8230C8E316B544FC92813D96FA139F2E@tunaPC> <0A3221C70F24FB45833433255569204D1F63C649@G01JPEXMBYT05> <0A3221C70F24FB45833433255569204D1F63C6C9@G01JPEXMBYT05> <0A3221C70F24FB45833433255569204D1F63C7A6@G01JPEXMBYT05> <0A3221C70F24FB45833433255569204D1F63C85A@G01JPEXMBYT05> Cc: MauMau , Breen Hagan , Heikki Linnakangas , Alvaro Herrera , PostgreSQL Hackers From: Heikki Linnakangas Message-ID: Date: Thu, 16 Mar 2017 10:40:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.4 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 11/08/2016 07:56 AM, Michael Paquier wrote: > On Tue, Nov 8, 2016 at 2:25 PM, Tsunakawa, Takayuki > wrote: >> From: pgsql-hackers-owner@postgresql.org >>> [mailto:pgsql-hackers-owner@postgresql.org] On Behalf Of Michael Paquier >>> Things are this way since b15f9b08 that introduced pgwin32_is_service(). >>> Still, by considering what you say, you definitely have a point that if >>> postgres is started by another service running as Local System logs are >>> going where they should not. Let's remove the check for LocalSystem but >>> still check for SE_GROUP_ENABLED. I did some testing on patch v5, on my Windows 8 VM. I launched cmd as Administrator, and registered the service with: pg_ctl register -D data I.e. without specifying a user. When I start the service with "net start", it refuses to start, and there are no messages in the event log. It refuses to start because "data" is not a valid directory, so that's correct. But the error message about that is lost. Added some debugging messages to win32_is_service(), and it confirms that with this patch (v5), win32_is_service() incorrectly returns false, while unmodified git master returns true, and writes the error message to the event log. So, I think we still need the check for Local System. >>> So, without any refactoring work, isn't the attached patch just but fine? >>> That seems to work properly for me. >> >> Just taking a look at the patch, I'm sure it will work. >> >> Committer (Heikki?), >> v5 is refactored for HEAD, and v6 is for previous releases without refactoring. I'd like v5 to be applied to at least HEAD, as it removes a lot of unnecessary code. > > + if (!CheckTokenMembership(NULL, AdministratorsSid, &IsAdministrators) || > + !CheckTokenMembership(NULL, PowerUsersSid, &IsPowerUsers)) > { > - if ((EqualSid(AdministratorsSid, Groups->Groups[x].Sid) && > - (Groups->Groups[x].Attributes & SE_GROUP_ENABLED)) || > - (EqualSid(PowerUsersSid, Groups->Groups[x].Sid) && > - (Groups->Groups[x].Attributes & SE_GROUP_ENABLED))) > - { > - success = TRUE; > - break; > - } > + log_error("could not check access token membership: error code %lu\n", > + GetLastError()); > + exit(1); > } > I just looked more deeply at your refactoring patch, and I didn't know > about CheckTokenMembership()... The whole logic of your patch depends > on it. That's quite a cleanup that you have here. It looks that the > former implementation just had no knowledge of this routine or it > would just have been used. Yeah, CheckTokenMembership() seems really handy. Let's switch to that, but without removing the checks for Local System. - Heikki -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers