unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] lisp/server.el: Introduction of server-auth-key variable
@ 2011-02-22 13:55 Michal Nazarewicz
  2011-04-29 11:30 ` Juanma Barranquero
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Michal Nazarewicz @ 2011-02-22 13:55 UTC (permalink / raw)
  To: emacs-devel; +Cc: Michal Nazarewicz

From: Michal Nazarewicz <mina86@mina86.com>

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  <mina86@mina86.com>  (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




^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2011-05-02 15:28 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-22 13:55 [PATCH] lisp/server.el: Introduction of server-auth-key variable Michal Nazarewicz
2011-04-29 11:30 ` Juanma Barranquero
2011-04-29 11:42   ` Michal Nazarewicz
2011-04-29 12:02     ` Juanma Barranquero
2011-04-29 12:43       ` Michal Nazarewicz
2011-04-29 14:34       ` Michal Nazarewicz
2011-04-30  6:39         ` Eli Zaretskii
2011-04-30 21:03           ` Richard Stallman
2011-04-30 22:24           ` Michal Nazarewicz
2011-04-29 16:22 ` Stefan Monnier
2011-04-29 16:35   ` Michal Nazarewicz
2011-04-29 17:09     ` Stefan Monnier
2011-04-30 14:31   ` Juanma Barranquero
2011-04-30 22:55     ` Michal Nazarewicz
2011-04-30 23:59       ` Juanma Barranquero
2011-05-01  0:44         ` Michal Nazarewicz
2011-05-01  0:58           ` Juanma Barranquero
2011-05-01  1:22             ` Michal Nazarewicz
2011-05-02 15:28 ` [PATCHv2] " Michal Nazarewicz

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).