diff options
| author | Stefan Monnier | 2003-04-12 19:04:11 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2003-04-12 19:04:11 +0000 |
| commit | 724629d2c2c796c1f831f33db6201f5f9f515a26 (patch) | |
| tree | c73b22fef6cd74cf630d3f8649d2905ae0365ef0 | |
| parent | caa4df2b5de3cc9933c9284b68e5723fbbaca7b1 (diff) | |
| download | emacs-724629d2c2c796c1f831f33db6201f5f9f515a26.tar.gz emacs-724629d2c2c796c1f831f33db6201f5f9f515a26.zip | |
(server-socket-name): Use new safe location for socket.
(server-ensure-safe-dir): New fun.
(server-start): Use it.
(server-process-filter): Re-enable the -eval feature.
| -rw-r--r-- | lisp/server.el | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/lisp/server.el b/lisp/server.el index 39c183a3fc5..5256df44dd4 100644 --- a/lisp/server.el +++ b/lisp/server.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; server.el --- Lisp code for GNU Emacs running as server process | 1 | ;;; server.el --- Lisp code for GNU Emacs running as server process |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1986, 87, 92, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002 | 3 | ;; Copyright (C) 1986,87,92,94,95,96,97,98,99,2000,01,02,2003 |
| 4 | ;; Free Software Foundation, Inc. | 4 | ;; Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | ;; Author: William Sommerfeld <wesommer@athena.mit.edu> | 6 | ;; Author: William Sommerfeld <wesommer@athena.mit.edu> |
| @@ -159,11 +159,8 @@ This means that the server should not kill the buffer when you say you | |||
| 159 | are done with it in the server.") | 159 | are done with it in the server.") |
| 160 | (make-variable-buffer-local 'server-existing-buffer) | 160 | (make-variable-buffer-local 'server-existing-buffer) |
| 161 | 161 | ||
| 162 | ;; Fixme: This doesn't look secure. If it really is, it deserves a | ||
| 163 | ;; comment, but I'd expect it to be created in a protected subdir as | ||
| 164 | ;; normal. -- fx | ||
| 165 | (defvar server-socket-name | 162 | (defvar server-socket-name |
| 166 | (format "/tmp/esrv%d-%s" (user-uid) | 163 | (format "/tmp/emacs%d-%s/server" (user-uid) |
| 167 | (substring (system-name) 0 (string-match "\\." (system-name))))) | 164 | (substring (system-name) 0 (string-match "\\." (system-name))))) |
| 168 | 165 | ||
| 169 | (defun server-log (string &optional client) | 166 | (defun server-log (string &optional client) |
| @@ -223,6 +220,22 @@ are done with it in the server.") | |||
| 223 | (t " "))) | 220 | (t " "))) |
| 224 | arg t t)) | 221 | arg t t)) |
| 225 | 222 | ||
| 223 | (defun server-ensure-safe-dir (dir) | ||
| 224 | "Make sure DIR is a directory with no race-condition issues. | ||
| 225 | Creates the directory if necessary and makes sure: | ||
| 226 | - there's no symlink involved | ||
| 227 | - it's owned by us | ||
| 228 | - it's not readable/writable by anybody else." | ||
| 229 | (setq dir (directory-file-name dir)) | ||
| 230 | (let ((attrs (file-attributes dir))) | ||
| 231 | (unless attrs | ||
| 232 | (letf (((default-file-modes) ?\700)) (make-directory dir)) | ||
| 233 | (setq attrs (file-attributes dir))) | ||
| 234 | ;; Check that it's safe for use. | ||
| 235 | (unless (and (eq t (car attrs)) (eq (nth 2 attrs) (user-uid)) | ||
| 236 | (zerop (logand ?\077 (file-modes dir)))) | ||
| 237 | (error "The directory %s is unsafe" dir)))) | ||
| 238 | |||
| 226 | ;;;###autoload | 239 | ;;;###autoload |
| 227 | (defun server-start (&optional leave-dead) | 240 | (defun server-start (&optional leave-dead) |
| 228 | "Allow this Emacs process to be a server for client processes. | 241 | "Allow this Emacs process to be a server for client processes. |
| @@ -233,6 +246,8 @@ Emacs distribution as your standard \"editor\". | |||
| 233 | 246 | ||
| 234 | Prefix arg means just kill any existing server communications subprocess." | 247 | Prefix arg means just kill any existing server communications subprocess." |
| 235 | (interactive "P") | 248 | (interactive "P") |
| 249 | ;; Make sure there is a safe directory in which to place the socket. | ||
| 250 | (server-ensure-safe-dir (file-name-directory server-socket-name)) | ||
| 236 | ;; kill it dead! | 251 | ;; kill it dead! |
| 237 | (condition-case () (delete-process server-process) (error nil)) | 252 | (condition-case () (delete-process server-process) (error nil)) |
| 238 | ;; Delete the socket files made by previous server invocations. | 253 | ;; Delete the socket files made by previous server invocations. |
| @@ -271,7 +286,6 @@ Server mode runs a process that accepts commands from the | |||
| 271 | ;; Fixme: Should this check for an existing server socket and do | 286 | ;; Fixme: Should this check for an existing server socket and do |
| 272 | ;; nothing if there is one (for multiple Emacs sessions)? | 287 | ;; nothing if there is one (for multiple Emacs sessions)? |
| 273 | (server-start (not server-mode))) | 288 | (server-start (not server-mode))) |
| 274 | (custom-add-version 'server-mode "21.4") | ||
| 275 | 289 | ||
| 276 | (defun server-process-filter (proc string) | 290 | (defun server-process-filter (proc string) |
| 277 | "Process a request from the server to edit some files. | 291 | "Process a request from the server to edit some files. |
| @@ -296,13 +310,11 @@ PROC is the server process. Format of STRING is \"PATH PATH PATH... \\n\"." | |||
| 296 | (setq string (substring string (match-end 0))) | 310 | (setq string (substring string (match-end 0))) |
| 297 | (setq client (cons proc nil)) | 311 | (setq client (cons proc nil)) |
| 298 | (while (string-match "[^ ]* " request) | 312 | (while (string-match "[^ ]* " request) |
| 299 | (let ((arg (substring request (match-beginning 0) (1- (match-end 0)))) | 313 | (let ((arg (substring request (match-beginning 0) (1- (match-end 0))))) |
| 300 | (pos 0)) | ||
| 301 | (setq request (substring request (match-end 0))) | 314 | (setq request (substring request (match-end 0))) |
| 302 | (cond | 315 | (cond |
| 303 | ((equal "-nowait" arg) (setq nowait t)) | 316 | ((equal "-nowait" arg) (setq nowait t)) |
| 304 | ;;; This is not safe unless we make sure other users can't send commands. | 317 | ((equal "-eval" arg) (setq eval t)) |
| 305 | ;;; ((equal "-eval" arg) (setq eval t)) | ||
| 306 | ((and (equal "-display" arg) (string-match "\\([^ ]*\\) " request)) | 318 | ((and (equal "-display" arg) (string-match "\\([^ ]*\\) " request)) |
| 307 | (let ((display (server-unquote-arg (match-string 1 request)))) | 319 | (let ((display (server-unquote-arg (match-string 1 request)))) |
| 308 | (setq request (substring request (match-end 0))) | 320 | (setq request (substring request (match-end 0))) |