From 2920e68d73e0009f368e817207964efaff751f85 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 11 Mar 2011 14:19:08 +0200 Subject: [PATCH] Fix comparisons of file ownership on MS-Windows for the Administrator user. lisp/files.el (file-ownership-preserved-p): Pass `integer' as an explicit 2nd argument to `file-attributes'. If the file's owner is the Administrators group on Windows, and the current user is Administrator, consider that a match. lisp/server.el (server-ensure-safe-dir): Consider server directory safe on MS-Windows if its owner is the Administrators group while the current Emacs user is Administrator. Use `=' to compare numerical UIDs, since they could be integers or floats. --- lisp/ChangeLog | 12 ++++++++++++ lisp/files.el | 10 ++++++++-- lisp/server.el | 8 +++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1b8a7641b3..6685e35536 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2011-03-11 Eli Zaretskii + + * files.el (file-ownership-preserved-p): Pass `integer' as an + explicit 2nd argument to `file-attributes'. If the file's owner + is the Administrators group on Windows, and the current user is + Administrator, consider that a match. + + * server.el (server-ensure-safe-dir): Consider server directory + safe on MS-Windows if its owner is the Administrators group while + the current Emacs user is Administrator. Use `=' to compare + numerical UIDs, since they could be integers or floats. + 2011-03-07 Chong Yidong * Version 23.3 released. diff --git a/lisp/files.el b/lisp/files.el index 88063aed2b..91fed0d127 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3752,11 +3752,17 @@ we do not remove backup version numbers, only true file version numbers." (let ((handler (find-file-name-handler file 'file-ownership-preserved-p))) (if handler (funcall handler 'file-ownership-preserved-p file) - (let ((attributes (file-attributes file))) + (let ((attributes (file-attributes file 'integer))) ;; Return t if the file doesn't exist, since it's true that no ;; information would be lost by an (attempted) delete and create. (or (null attributes) - (= (nth 2 attributes) (user-uid))))))) + (= (nth 2 attributes) (user-uid)) + ;; Files created on Windows by Administrator (RID=500) + ;; have the Administrators group (RID=544) recorded as + ;; their owner. Rewriting them will still preserve the + ;; owner. + (and (eq system-type 'windows-nt) + (= (user-uid) 500) (= (nth 2 attributes) 544))))))) (defun file-name-sans-extension (filename) "Return FILENAME sans final \"extension\". diff --git a/lisp/server.el b/lisp/server.el index f62a7c73ab..816a072bf7 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -474,7 +474,13 @@ See variable `server-auth-dir' for details." (file-name-as-directory dir)) :warning) (throw :safe t)) - (unless (eql uid (user-uid)) ; is the dir ours? + (unless (or (= uid (user-uid)) ; is the dir ours? + (and w32 + ;; Files created on Windows by + ;; Administrator (RID=500) have + ;; the Administrators (RID=544) + ;; group recorded as the owner. + (= uid 544) (= (user-uid) 500))) (throw :safe nil)) (when w32 ; on NTFS? (throw :safe t)) -- 2.20.1