diff options
| author | Paul Eggert | 2020-02-23 16:19:42 -0800 |
|---|---|---|
| committer | Paul Eggert | 2020-02-23 16:45:50 -0800 |
| commit | 9d626dffc6ba62c0d7a1a5c712f576ed8684fd66 (patch) | |
| tree | 6cc8fbe8e5bc02c3bb74139710814a0400e91a8a /doc | |
| parent | c4ca8219dd6b8f06e67a0b767475b1259653b8e0 (diff) | |
| download | emacs-9d626dffc6ba62c0d7a1a5c712f576ed8684fd66.tar.gz emacs-9d626dffc6ba62c0d7a1a5c712f576ed8684fd66.zip | |
Add 'nofollow' flag to set-file-modes etc.
This avoids some race conditions (Bug#39683). E.g., if some other
program changes a file to a symlink between the time Emacs creates
the file and the time it changes the file’s permissions, using the
new flag prevents Emacs from inadvertently changing the
permissions of a victim in some completely unrelated directory.
* admin/merge-gnulib (GNULIB_MODULES): Add fchmodat.
* doc/lispref/files.texi (Testing Accessibility, Changing Files):
* doc/lispref/os.texi (File Notifications):
* etc/NEWS:
Adjust documentation accordingly.
* lib/chmodat.c, lib/fchmodat.c, lib/lchmod.c, m4/fchmodat.m4:
* m4/lchmod.m4: New files, copied from Gnulib.
* lib/gnulib.mk.in: Regenerate.
* lisp/dired-aux.el (dired-do-chmod):
* lisp/doc-view.el (doc-view-make-safe-dir):
* lisp/emacs-lisp/autoload.el (autoload--save-buffer):
* lisp/emacs-lisp/bytecomp.el (byte-compile-file):
* lisp/eshell/em-pred.el (eshell-pred-file-mode):
* lisp/files.el (backup-buffer-copy, copy-directory):
* lisp/gnus/mail-source.el (mail-source-movemail):
* lisp/gnus/mm-decode.el (mm-display-external):
* lisp/gnus/nnmail.el (nnmail-write-region):
* lisp/net/tramp-adb.el (tramp-adb-handle-file-local-copy)
(tramp-adb-handle-write-region):
* lisp/net/tramp-sh.el (tramp-do-copy-or-rename-file-directly):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-write-region):
* lisp/net/tramp.el (tramp-handle-write-region)
(tramp-make-tramp-temp-file):
* lisp/server.el (server-ensure-safe-dir):
* lisp/url/url-util.el (url-make-private-file):
When getting or setting file modes, avoid following symbolic links
when the file is not supposed to be a symbolic link.
* lisp/doc-view.el (doc-view-make-safe-dir):
Omit no-longer-needed separate symlink test.
* lisp/gnus/gnus-util.el (gnus-set-file-modes):
* lisp/net/tramp.el (tramp-handle-file-modes):
* lisp/net/tramp-gvfs.el (tramp-gvfs-handle-set-file-modes):
* src/fileio.c (symlink_nofollow_flag): New function.
(Ffile_modes, Fset_file_modes):
Support an optional FLAG arg. All C callers changed.
* lisp/net/ange-ftp.el (ange-ftp-set-file-modes):
* lisp/net/tramp-adb.el (tramp-adb-handle-set-file-modes):
* lisp/net/tramp-sh.el (tramp-sh-handle-set-file-modes):
* lisp/net/tramp-smb.el (tramp-smb-handle-set-file-modes):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-set-file-modes):
Accept an optional FLAG arg that is currently ignored,
and add a FIXME comment for it.
* m4/gnulib-comp.m4: Regenerate.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/files.texi | 27 | ||||
| -rw-r--r-- | doc/lispref/os.texi | 2 |
2 files changed, 22 insertions, 7 deletions
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index a93da39f174..a69a4e5dd38 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi | |||
| @@ -928,7 +928,7 @@ also checks that the file's group would be unchanged. | |||
| 928 | This function does not follow symbolic links. | 928 | This function does not follow symbolic links. |
| 929 | @end defun | 929 | @end defun |
| 930 | 930 | ||
| 931 | @defun file-modes filename | 931 | @defun file-modes filename &optional flag |
| 932 | @cindex mode bits | 932 | @cindex mode bits |
| 933 | @cindex file permissions | 933 | @cindex file permissions |
| 934 | @cindex permissions, file | 934 | @cindex permissions, file |
| @@ -946,12 +946,19 @@ The highest possible value is 4095 (7777 octal), meaning that everyone | |||
| 946 | has read, write, and execute permission, the @acronym{SUID} bit is set | 946 | has read, write, and execute permission, the @acronym{SUID} bit is set |
| 947 | for both others and group, and the sticky bit is set. | 947 | for both others and group, and the sticky bit is set. |
| 948 | 948 | ||
| 949 | By default this function follows symbolic links. However, if the | ||
| 950 | optional argument @var{flag} is the symbol @code{nofollow}, this | ||
| 951 | function does not follow @var{filename} if it is a symbolic link; | ||
| 952 | this can help prevent inadvertently obtaining the mode bits of a file | ||
| 953 | somewhere else, and is more consistent with @code{file-attributes} | ||
| 954 | (@pxref{File Attributes}). | ||
| 955 | |||
| 949 | @xref{Changing Files}, for the @code{set-file-modes} function, which | 956 | @xref{Changing Files}, for the @code{set-file-modes} function, which |
| 950 | can be used to set these permissions. | 957 | can be used to set these permissions. |
| 951 | 958 | ||
| 952 | @example | 959 | @example |
| 953 | @group | 960 | @group |
| 954 | (file-modes "~/junk/diffs") | 961 | (file-modes "~/junk/diffs" 'nofollow) |
| 955 | @result{} 492 ; @r{Decimal integer.} | 962 | @result{} 492 ; @r{Decimal integer.} |
| 956 | @end group | 963 | @end group |
| 957 | @group | 964 | @group |
| @@ -960,7 +967,7 @@ can be used to set these permissions. | |||
| 960 | @end group | 967 | @end group |
| 961 | 968 | ||
| 962 | @group | 969 | @group |
| 963 | (set-file-modes "~/junk/diffs" #o666) | 970 | (set-file-modes "~/junk/diffs" #o666 'nofollow) |
| 964 | @result{} nil | 971 | @result{} nil |
| 965 | @end group | 972 | @end group |
| 966 | 973 | ||
| @@ -1801,9 +1808,17 @@ See also @code{delete-directory} in @ref{Create/Delete Dirs}. | |||
| 1801 | @cindex file permissions, setting | 1808 | @cindex file permissions, setting |
| 1802 | @cindex permissions, file | 1809 | @cindex permissions, file |
| 1803 | @cindex file modes, setting | 1810 | @cindex file modes, setting |
| 1804 | @deffn Command set-file-modes filename mode | 1811 | @deffn Command set-file-modes filename mode &optional flag |
| 1805 | This function sets the @dfn{file mode} (or @dfn{permissions}) of | 1812 | This function sets the @dfn{file mode} (or @dfn{permissions}) of |
| 1806 | @var{filename} to @var{mode}. This function follows symbolic links. | 1813 | @var{filename} to @var{mode}. |
| 1814 | |||
| 1815 | By default this function follows symbolic links. However, if the | ||
| 1816 | optional argument @var{flag} is the symbol @code{nofollow}, this | ||
| 1817 | function does not follow @var{filename} if it is a symbolic link; | ||
| 1818 | this can help prevent inadvertently changing the mode bits of a file | ||
| 1819 | somewhere else. On platforms that do not support changing mode bits | ||
| 1820 | on a symbolic link, this function signals an error when @var{filename} | ||
| 1821 | is a symbolic link and @var{flag} is @code{nofollow}. | ||
| 1807 | 1822 | ||
| 1808 | If called non-interactively, @var{mode} must be an integer. Only the | 1823 | If called non-interactively, @var{mode} must be an integer. Only the |
| 1809 | lowest 12 bits of the integer are used; on most systems, only the | 1824 | lowest 12 bits of the integer are used; on most systems, only the |
| @@ -1811,7 +1826,7 @@ lowest 9 bits are meaningful. You can use the Lisp construct for | |||
| 1811 | octal numbers to enter @var{mode}. For example, | 1826 | octal numbers to enter @var{mode}. For example, |
| 1812 | 1827 | ||
| 1813 | @example | 1828 | @example |
| 1814 | (set-file-modes #o644) | 1829 | (set-file-modes "myfile" #o644 'nofollow) |
| 1815 | @end example | 1830 | @end example |
| 1816 | 1831 | ||
| 1817 | @noindent | 1832 | @noindent |
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index a034ccdcd5c..cf4ef52abfb 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi | |||
| @@ -3127,7 +3127,7 @@ being reported. For example: | |||
| 3127 | @end group | 3127 | @end group |
| 3128 | 3128 | ||
| 3129 | @group | 3129 | @group |
| 3130 | (set-file-modes "/tmp/foo" (default-file-modes)) | 3130 | (set-file-modes "/tmp/foo" (default-file-modes) 'nofollow) |
| 3131 | @result{} Event (35025468 attribute-changed "/tmp/foo") | 3131 | @result{} Event (35025468 attribute-changed "/tmp/foo") |
| 3132 | @end group | 3132 | @end group |
| 3133 | @end example | 3133 | @end example |