From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.devel Subject: [PATCH] lisp/server.el: Introduction of server-auth-key variable Date: Tue, 22 Feb 2011 14:55:00 +0100 Message-ID: <835b9d42b15c18e5adf7381138f347061fbc17e8.1298381336.git.mina86@mina86.com> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1298394687 1098 80.91.229.12 (22 Feb 2011 17:11:27 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 22 Feb 2011 17:11:27 +0000 (UTC) Cc: Michal Nazarewicz To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Feb 22 18:11:22 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Prvli-0003x8-3G for ged-emacs-devel@m.gmane.org; Tue, 22 Feb 2011 18:11:22 +0100 Original-Received: from localhost ([127.0.0.1]:43311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Prvlh-0008Tt-FV for ged-emacs-devel@m.gmane.org; Tue, 22 Feb 2011 12:11:21 -0500 Original-Received: from [140.186.70.92] (port=49506 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Prsn6-0004JI-1y for emacs-devel@gnu.org; Tue, 22 Feb 2011 09:00:44 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PrsiT-0005Vg-LE for emacs-devel@gnu.org; Tue, 22 Feb 2011 08:55:50 -0500 Original-Received: from smtp-out.google.com ([74.125.121.67]:22087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PrsiT-0005V9-9X for emacs-devel@gnu.org; Tue, 22 Feb 2011 08:55:49 -0500 Original-Received: from kpbe19.cbf.corp.google.com (kpbe19.cbf.corp.google.com [172.25.105.83]) by smtp-out.google.com with ESMTP id p1MDtkiD001572 for ; Tue, 22 Feb 2011 05:55:47 -0800 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1298382947; bh=sys5wdzU3D+VM2ERyb3pXYntl6o=; h=From:To:Cc:Subject:Date:Message-Id; b=t8TSo0p4cLjaPqOHTHt5HUXeGkxChDNNvj+sv4WLENv4RnecYsJGvzO91mzt+AUu7 sMR3UJOm7GuD5QxmwiQ5g== Original-Received: from fxm20 (fxm20.prod.google.com [10.184.13.20]) by kpbe19.cbf.corp.google.com with ESMTP id p1MDtiB1001928 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Tue, 22 Feb 2011 05:55:45 -0800 Original-Received: by fxm20 with SMTP id 20so2447178fxm.12 for ; Tue, 22 Feb 2011 05:55:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=beta; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=i6f8sxfDp1ammc+kFez+Xz0xBaJN4wdvannxDRSNPiQ=; b=XE28ZY9FCiiwQAYkRID/kqmM52OzCt5dt34+fE/jjZCM6eT1LCZvLpp8779LlnjpaT 6eRbyMY90muIv0fSMzSA== DomainKey-Signature: a=rsa-sha1; c=nofws; d=google.com; s=beta; h=from:to:cc:subject:date:message-id:x-mailer; b=BLLeVJrLMIQZleUTH1n9f875ZOTXlYeHM52WOdIBeR3axgh1ZhhOe1+TG7ju5VESKt p0mxmD1E8irpM8IyY9Zg== Original-Received: by 10.223.87.193 with SMTP id x1mr3440816fal.118.1298382943861; Tue, 22 Feb 2011 05:55:43 -0800 (PST) Original-Received: from mnazarewicz-glaptop.zrh.corp.google.com (dhcp-172-16-75-204.zrh.corp.google.com [172.16.75.204]) by mx.google.com with ESMTPS id z1sm2538763fau.21.2011.02.22.05.55.42 (version=SSLv3 cipher=OTHER); Tue, 22 Feb 2011 05:55:43 -0800 (PST) X-Mailer: git-send-email 1.7.3.1 X-System-Of-Record: true X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 74.125.121.67 X-Mailman-Approved-At: Tue, 22 Feb 2011 12:09:51 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:136372 Archived-At: From: Michal Nazarewicz This commit adds a server-auth-key variable which allows user to specify a default authentication key used by the server process. --- lisp/server.el | 42 +++++++++++++++++++++++++++++++++++------- 1 files changed, 35 insertions(+), 7 deletions(-) Hello, attached is a patch that adds a `server-auth-key' variable, which I use to easily allow a host to connect to Emacs daemon listening on TCP port without the need of synchronising the server file each time server starts. The etc/CONTRIBUTE mentions ChangeLog entry. I'm unsure whether you need anything more then the commit message above but in case you do, here's ChangeLog entry: 2011-02-21 Michal Nazarewicz (tiny change) * lisp/server.el: Introduce server-auth-key variable which allows user to specify a default authentication key used by the server process. Hope you guys don't mind git style patch mail. diff --git a/lisp/server.el b/lisp/server.el index df8cae0..3963e86 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -134,6 +134,27 @@ directory residing in a NTFS partition instead." ;;;###autoload (put 'server-auth-dir 'risky-local-variable t) +(defcustom server-auth-key nil + "Server authentication key. + +Normally, authentication key is generated on random when server +starts, which guarantees a certain level of security. It is +recommended to leave it that way. + +In some situations however, it can be difficult to share randomly +generated password with remote hosts (eg. no shared directory), +so you can set the key with this variable and then copy server +file to remote host (with possible changes to IP address and/or +port if that applies). + +You can use \\[server-generate-key] to get a random authentication +key." + :group 'server + :type '(choice + (const :tag "Random" nil) + (string :tag "Password")) + :version "24.0") + (defcustom server-raise-frame t "If non-nil, raise frame when switching to a buffer." :group 'server @@ -495,6 +516,19 @@ See variable `server-auth-dir' for details." (unless safe (error "The directory `%s' is unsafe" dir))))) +(defun server-generate-key () + "Generates and returns a random 64-byte strings of random chars +in the range `!'..`~'. If called interactively, also inserts it +into current buffer." + (interactive) + (let ((auth-key + (loop repeat 64 + collect (+ 33 (random 94)) into auth + finally return (concat auth)))) + (if (called-interactively-p) + (insert auth-key)) + auth-key)) + ;;;###autoload (defun server-start (&optional leave-dead inhibit-prompt) "Allow this Emacs process to be a server for client processes. @@ -588,13 +622,7 @@ server or call `M-x server-force-delete' to forcibly disconnect it.") (unless server-process (error "Could not start server process")) (process-put server-process :server-file server-file) (when server-use-tcp - (let ((auth-key - (loop - ;; The auth key is a 64-byte string of random chars in the - ;; range `!'..`~'. - repeat 64 - collect (+ 33 (random 94)) into auth - finally return (concat auth)))) + (let ((auth-key (or server-auth-key (server-generate-key)))) (process-put server-process :auth-key auth-key) (with-temp-file server-file (set-buffer-multibyte nil) -- 1.7.3.1