From: Eli Zaretskii Date: Fri, 11 Mar 2011 12:19:08 +0000 (+0200) Subject: Fix comparisons of file ownership on MS-Windows for the Administrator user. X-Git-Tag: emacs-pretest-24.0.90~104^3~109 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2920e68d73e0009f368e817207964efaff751f85;p=emacs.git 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. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1b8a7641b35..6685e355360 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 88063aed2b9..91fed0d1274 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 f62a7c73abc..816a072bf75 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))