From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: rabite Newsgroups: gmane.emacs.bugs Subject: bug#41628: [PATCH] Allow emacsclient to connect to other user's socket when using -s Date: Sun, 31 May 2020 15:51:02 +0200 Message-ID: Reply-To: rabite@posteo.de Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=_09021876c5e2fe750c2f33f00d5f9f58" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="40843"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Posteo Webmail To: 41628@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 31 17:30:47 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jfPvC-000AZY-SR for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 31 May 2020 17:30:46 +0200 Original-Received: from localhost ([::1]:55904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jfPvB-00071v-Jr for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 31 May 2020 11:30:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jfPuU-0006Qa-UO for bug-gnu-emacs@gnu.org; Sun, 31 May 2020 11:30:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jfPuU-0008Eb-Ji for bug-gnu-emacs@gnu.org; Sun, 31 May 2020 11:30:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jfPuU-0006D5-F1 for bug-gnu-emacs@gnu.org; Sun, 31 May 2020 11:30:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: rabite Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 31 May 2020 15:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 41628 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.159093896423806 (code B ref -1); Sun, 31 May 2020 15:30:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 31 May 2020 15:29:24 +0000 Original-Received: from localhost ([127.0.0.1]:33620 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jfPts-0006Bt-5n for submit@debbugs.gnu.org; Sun, 31 May 2020 11:29:24 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:50108) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jfOMq-0003Uk-RO for submit@debbugs.gnu.org; Sun, 31 May 2020 09:51:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jfOMq-0006k2-Iz for bug-gnu-emacs@gnu.org; Sun, 31 May 2020 09:51:12 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:56201) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jfOMl-0002z3-Ep for bug-gnu-emacs@gnu.org; Sun, 31 May 2020 09:51:12 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id B7A622400FD for ; Sun, 31 May 2020 15:51:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1590933063; bh=Zaj/n63dsEWXjY7LFKi2MLvRAtZGgMCl1L31c/M+sNk=; h=Date:From:To:Subject:From; b=T5hweyFHOs6RuPo4B/8Ok0rnei3iSkk9JX0HGwDa4vceORlIig5tqLqx83qcI9E7a stLrt87MxF5qsogfx77CeRLtq/+Lad+yvLl60M83bxsCnb9GW2RO5RmBZWM8L2bkJn DI+/OpL17ssXQyEWhablWLAKujH8AKRBJgnnTkMuYfqOhnhrRI95+9FCF8LIgPnHxy uueWXDnbj212IA0+bYb7jtdWBDhJ7a+I5htg1UajxS1yPnysi5QZPJOHoeMwy9k1CB kpp1QvhrJqQrW0j7iLegu5Y+w7i+4j83Ng0t1/97Juo/AgFfhjmNEmwMQPnffS3wDI dMio4lwivrRWQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 49Zfpb1BQ4z9rxS for ; Sun, 31 May 2020 15:51:02 +0200 (CEST) Mail-Reply-To: rabite@posteo.de X-Sender: rabite@posteo.de Received-SPF: pass client-ip=185.67.36.66; envelope-from=rabite@posteo.de; helo=mout02.posteo.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/31 08:26:17 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Mailman-Approved-At: Sun, 31 May 2020 11:29:23 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:181288 Archived-At: --=_09021876c5e2fe750c2f33f00d5f9f58 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Since commit 5c0d8bb95bbd5354e6b2cd2e56a91afe4e780759 emacsclient won't connect to my usual emacs session when run as root. I use this all the time to edit files, combined with "-T /sudo:root@localhost" to handle permissions. Using a separate emacs process would be unpractical as it would require setting up a whole new emacs configuration and keeping it in sync with my main one. I think this is a common use-case for those who have an emacs-server running all the time and supporting it makes a lot of sense. In principle I see no reason emacsclient should refuse a connection that is possible in theory. It looks like this "feature" has been explicitly disabled, maybe because it might triggered unintentionally if running su doesn't set USER or something?. So I propose a new approach to allow root emacsclient to connect to non-root emacs servers: If the user sets a socket file explicitly using the -s switch, the socket_status() function skips the uid check and returns without error as long as the call to stat was successful. Generally, this would allow any user to connect to any emacs server as long as the permissions allow it. If not, it shows the "connect: Permission denied" message, if the socket file is reachable at all, that is. I added a tiny patch that implements this change. If necessary, I'd be willing to expand on it, or even implement a different approach depending on how much work/complicated it would be. --=_09021876c5e2fe750c2f33f00d5f9f58 Content-Transfer-Encoding: base64 Content-Type: text/x-diff; name=0001-allow-sockets-with-different-uid-if-set-explicitly.patch~ Content-Disposition: attachment; filename=0001-allow-sockets-with-different-uid-if-set-explicitly.patch~; size=684 RnJvbSBmNGQxYmZkNDExMmU0OTI3MGM0ODg3NDg1NjIwYjcxMzc2YWUyYzMwIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiByYWJpdGUgPHJhYml0ZUBwb3N0ZW8uZGU+CkRhdGU6IFN1biwg MzEgTWF5IDIwMjAgMTQ6NDg6NDcgKzAyMDAKU3ViamVjdDogW1BBVENIXSBhbGxvdyBzb2NrZXRz IHdpdGggZGlmZmVyZW50IHVpZCBpZiBzZXQgZXhwbGljaXRseQoKLS0tCiBsaWItc3JjL2VtYWNz Y2xpZW50LmMgfCAyICstCiAxIGZpbGUgY2hhbmdlZCwgMSBpbnNlcnRpb24oKyksIDEgZGVsZXRp b24oLSkKCmRpZmYgLS1naXQgYS9saWItc3JjL2VtYWNzY2xpZW50LmMgYi9saWItc3JjL2VtYWNz Y2xpZW50LmMKaW5kZXggMzgwYmU5NTIyMi4uY2NlZjkwODVlNCAxMDA2NDQKLS0tIGEvbGliLXNy Yy9lbWFjc2NsaWVudC5jCisrKyBiL2xpYi1zcmMvZW1hY3NjbGllbnQuYwpAQCAtMTE1Nyw3ICsx MTU3LDcgQEAgc29ja2V0X3N0YXR1cyAoY29uc3QgY2hhciAqbmFtZSwgdWlkX3QgdWlkKQogICBp ZiAoc3RhdCAobmFtZSwgJnN0YXRiZnIpICE9IDApCiAgICAgcmV0dXJuIGVycm5vOwogCi0gIGlm IChzdGF0YmZyLnN0X3VpZCAhPSB1aWQpCisgIGlmIChzdGF0YmZyLnN0X3VpZCAhPSB1aWQgJiYg IXNvY2tldF9uYW1lKQogICAgIHJldHVybiAtMTsKIAogICByZXR1cm4gMDsKLS0gCjIuMjYuMgoK --=_09021876c5e2fe750c2f33f00d5f9f58--