Skip to content

Commit 7514f4f

Browse files
authored
bpo-39184: Add audit events to functions in fcntl, msvcrt, os, resource, shutil, signal, syslog (GH-18407)
1 parent 597ebed commit 7514f4f

File tree

15 files changed

+320
-17
lines changed

15 files changed

+320
-17
lines changed

Doc/library/fcntl.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ The module defines the following functions:
6363

6464
If the :c:func:`fcntl` fails, an :exc:`OSError` is raised.
6565

66+
.. audit-event:: fcntl.fcntl fd,cmd,arg fcntl.fcntl
67+
6668

6769
.. function:: ioctl(fd, request, arg=0, mutate_flag=True)
6870

@@ -112,6 +114,8 @@ The module defines the following functions:
112114
>>> buf
113115
array('h', [13341])
114116

117+
.. audit-event:: fcntl.ioctl fd,request,arg fcntl.ioctl
118+
115119

116120
.. function:: flock(fd, operation)
117121

@@ -122,6 +126,8 @@ The module defines the following functions:
122126

123127
If the :c:func:`flock` fails, an :exc:`OSError` exception is raised.
124128

129+
.. audit-event:: fcntl.flock fd,operation fcntl.flock
130+
125131

126132
.. function:: lockf(fd, cmd, len=0, start=0, whence=0)
127133

@@ -155,6 +161,8 @@ The module defines the following functions:
155161
The default for *len* is 0 which means to lock to the end of the file. The
156162
default for *whence* is also 0.
157163

164+
.. audit-event:: fcntl.lockf fd,cmd,len,start,whence fcntl.lockf
165+
158166
Examples (all on a SVR4 compliant system)::
159167

160168
import struct, fcntl, os

Doc/library/msvcrt.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ File Operations
4242
regions in a file may be locked at the same time, but may not overlap. Adjacent
4343
regions are not merged; they must be unlocked individually.
4444

45+
.. audit-event:: msvcrt.locking fd,mode,nbytes msvcrt.locking
46+
4547

4648
.. data:: LK_LOCK
4749
LK_RLCK
@@ -77,12 +79,16 @@ File Operations
7779
and :const:`os.O_TEXT`. The returned file descriptor may be used as a parameter
7880
to :func:`os.fdopen` to create a file object.
7981

82+
.. audit-event:: msvcrt.open_osfhandle handle,flags msvcrt.open_osfhandle
83+
8084

8185
.. function:: get_osfhandle(fd)
8286

8387
Return the file handle for the file descriptor *fd*. Raises :exc:`OSError` if
8488
*fd* is not recognized.
8589

90+
.. audit-event:: msvcrt.get_osfhandle fd msvcrt.get_osfhandle
91+
8692

8793
.. _msvcrt-console:
8894

Doc/library/os.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ process and user.
445445
On some platforms, including FreeBSD and Mac OS X, setting ``environ`` may
446446
cause memory leaks. Refer to the system documentation for :c:func:`putenv`.
447447

448+
.. audit-event:: os.putenv key,value os.putenv
449+
448450
.. versionchanged:: 3.9
449451
The function is now always available.
450452

@@ -640,6 +642,8 @@ process and user.
640642
don't update ``os.environ``, so it is actually preferable to delete items of
641643
``os.environ``.
642644

645+
.. audit-event:: os.unsetenv key os.unsetenv
646+
643647
.. versionchanged:: 3.9
644648
The function is now always available and is also available on Windows.
645649

@@ -766,6 +770,8 @@ as internal buffering of data.
766770
docs for :func:`chmod` for possible values of *mode*. As of Python 3.3, this
767771
is equivalent to ``os.chmod(fd, mode)``.
768772

773+
.. audit-event:: os.chmod path,mode,dir_fd os.fchmod
774+
769775
.. availability:: Unix.
770776

771777

@@ -776,6 +782,8 @@ as internal buffering of data.
776782
:func:`chown`. As of Python 3.3, this is equivalent to ``os.chown(fd, uid,
777783
gid)``.
778784

785+
.. audit-event:: os.chown path,uid,gid,dir_fd os.fchown
786+
779787
.. availability:: Unix.
780788

781789

@@ -883,6 +891,8 @@ as internal buffering of data.
883891
:data:`F_ULOCK` or :data:`F_TEST`.
884892
*len* specifies the section of the file to lock.
885893

894+
.. audit-event:: os.lockf fd,cmd,len os.lockf
895+
886896
.. availability:: Unix.
887897

888898
.. versionadded:: 3.3
@@ -1603,6 +1613,8 @@ features:
16031613
This function can raise :exc:`OSError` and subclasses such as
16041614
:exc:`FileNotFoundError`, :exc:`PermissionError`, and :exc:`NotADirectoryError`.
16051615

1616+
.. audit-event:: os.chdir path os.chdir
1617+
16061618
.. versionadded:: 3.3
16071619
Added support for specifying *path* as a file descriptor
16081620
on some platforms.
@@ -1631,6 +1643,8 @@ features:
16311643

16321644
This function can support :ref:`not following symlinks <follow_symlinks>`.
16331645

1646+
.. audit-event:: os.chflags path,flags os.chflags
1647+
16341648
.. availability:: Unix.
16351649

16361650
.. versionadded:: 3.3
@@ -1676,6 +1690,8 @@ features:
16761690
read-only flag with it (via the ``stat.S_IWRITE`` and ``stat.S_IREAD``
16771691
constants or a corresponding integer value). All other bits are ignored.
16781692

1693+
.. audit-event:: os.chmod path,mode,dir_fd os.chmod
1694+
16791695
.. versionadded:: 3.3
16801696
Added support for specifying *path* as an open file descriptor,
16811697
and the *dir_fd* and *follow_symlinks* arguments.
@@ -1696,6 +1712,8 @@ features:
16961712
See :func:`shutil.chown` for a higher-level function that accepts names in
16971713
addition to numeric ids.
16981714

1715+
.. audit-event:: os.chown path,uid,gid,dir_fd os.chown
1716+
16991717
.. availability:: Unix.
17001718

17011719
.. versionadded:: 3.3
@@ -1722,6 +1740,8 @@ features:
17221740
descriptor *fd*. The descriptor must refer to an opened directory, not an
17231741
open file. As of Python 3.3, this is equivalent to ``os.chdir(fd)``.
17241742

1743+
.. audit-event:: os.chdir path os.fchdir
1744+
17251745
.. availability:: Unix.
17261746

17271747

@@ -1746,6 +1766,8 @@ features:
17461766
not follow symbolic links. As of Python 3.3, this is equivalent to
17471767
``os.chflags(path, flags, follow_symlinks=False)``.
17481768

1769+
.. audit-event:: os.chflags path,flags os.lchflags
1770+
17491771
.. availability:: Unix.
17501772

17511773
.. versionchanged:: 3.6
@@ -1759,6 +1781,8 @@ features:
17591781
for possible values of *mode*. As of Python 3.3, this is equivalent to
17601782
``os.chmod(path, mode, follow_symlinks=False)``.
17611783

1784+
.. audit-event:: os.chmod path,mode,dir_fd os.lchmod
1785+
17621786
.. availability:: Unix.
17631787

17641788
.. versionchanged:: 3.6
@@ -1770,6 +1794,8 @@ features:
17701794
function will not follow symbolic links. As of Python 3.3, this is equivalent
17711795
to ``os.chown(path, uid, gid, follow_symlinks=False)``.
17721796

1797+
.. audit-event:: os.chown path,uid,gid,dir_fd os.lchown
1798+
17731799
.. availability:: Unix.
17741800

17751801
.. versionchanged:: 3.6
@@ -1784,6 +1810,8 @@ features:
17841810
supply :ref:`paths relative to directory descriptors <dir_fd>`, and :ref:`not
17851811
following symlinks <follow_symlinks>`.
17861812

1813+
.. audit-event:: os.link src,dst,src_dir_fd,dst_dir_fd os.link
1814+
17871815
.. availability:: Unix, Windows.
17881816

17891817
.. versionchanged:: 3.2
@@ -1886,6 +1914,8 @@ features:
18861914
It is also possible to create temporary directories; see the
18871915
:mod:`tempfile` module's :func:`tempfile.mkdtemp` function.
18881916

1917+
.. audit-event:: os.mkdir path,mode,dir_fd os.mkdir
1918+
18891919
.. versionadded:: 3.3
18901920
The *dir_fd* argument.
18911921

@@ -1918,6 +1948,8 @@ features:
19181948

19191949
This function handles UNC paths correctly.
19201950

1951+
.. audit-event:: os.mkdir path,mode,dir_fd os.makedirs
1952+
19211953
.. versionadded:: 3.2
19221954
The *exist_ok* parameter.
19231955

@@ -2083,6 +2115,8 @@ features:
20832115

20842116
This function is semantically identical to :func:`unlink`.
20852117

2118+
.. audit-event:: os.remove path,dir_fd os.remove
2119+
20862120
.. versionadded:: 3.3
20872121
The *dir_fd* argument.
20882122

@@ -2103,6 +2137,8 @@ features:
21032137
they are empty. Raises :exc:`OSError` if the leaf directory could not be
21042138
successfully removed.
21052139

2140+
.. audit-event:: os.remove path,dir_fd os.removedirs
2141+
21062142
.. versionchanged:: 3.6
21072143
Accepts a :term:`path-like object`.
21082144

@@ -2128,6 +2164,8 @@ features:
21282164

21292165
If you want cross-platform overwriting of the destination, use :func:`replace`.
21302166

2167+
.. audit-event:: os.rename src,dst,src_dir_fd,dst_dir_fd os.rename
2168+
21312169
.. versionadded:: 3.3
21322170
The *src_dir_fd* and *dst_dir_fd* arguments.
21332171

@@ -2147,6 +2185,8 @@ features:
21472185
This function can fail with the new directory structure made if you lack
21482186
permissions needed to remove the leaf directory or file.
21492187

2188+
.. audit-event:: os.rename src,dst,src_dir_fd,dst_dir_fd os.renames
2189+
21502190
.. versionchanged:: 3.6
21512191
Accepts a :term:`path-like object` for *old* and *new*.
21522192

@@ -2162,6 +2202,8 @@ features:
21622202
This function can support specifying *src_dir_fd* and/or *dst_dir_fd* to
21632203
supply :ref:`paths relative to directory descriptors <dir_fd>`.
21642204

2205+
.. audit-event:: os.rename src,dst,src_dir_fd,dst_dir_fd os.replace
2206+
21652207
.. versionadded:: 3.3
21662208

21672209
.. versionchanged:: 3.6
@@ -2178,6 +2220,8 @@ features:
21782220
This function can support :ref:`paths relative to directory descriptors
21792221
<dir_fd>`.
21802222

2223+
.. audit-event:: os.rmdir path,dir_fd os.rmdir
2224+
21812225
.. versionadded:: 3.3
21822226
The *dir_fd* parameter.
21832227

@@ -2821,6 +2865,8 @@ features:
28212865
:exc:`OSError` is raised when the function is called by an unprivileged
28222866
user.
28232867

2868+
.. audit-event:: os.symlink src,dst,dir_fd os.symlink
2869+
28242870
.. availability:: Unix, Windows.
28252871

28262872
.. versionchanged:: 3.2
@@ -2873,6 +2919,8 @@ features:
28732919
traditional Unix name. Please see the documentation for
28742920
:func:`remove` for further information.
28752921

2922+
.. audit-event:: os.remove path,dir_fd os.unlink
2923+
28762924
.. versionadded:: 3.3
28772925
The *dir_fd* parameter.
28782926

@@ -2910,6 +2958,8 @@ features:
29102958
:ref:`paths relative to directory descriptors <dir_fd>` and :ref:`not
29112959
following symlinks <follow_symlinks>`.
29122960

2961+
.. audit-event:: os.utime path,times,ns,dir_fd os.utime
2962+
29132963
.. versionadded:: 3.3
29142964
Added support for specifying *path* as an open file descriptor,
29152965
and the *dir_fd*, *follow_symlinks*, and *ns* parameters.
@@ -3135,6 +3185,8 @@ These functions are all available on Linux only.
31353185
This function can support :ref:`specifying a file descriptor <path_fd>` and
31363186
:ref:`not following symlinks <follow_symlinks>`.
31373187

3188+
.. audit-event:: os.getxattr path,attribute os.getxattr
3189+
31383190
.. versionchanged:: 3.6
31393191
Accepts a :term:`path-like object` for *path* and *attribute*.
31403192

@@ -3149,6 +3201,8 @@ These functions are all available on Linux only.
31493201
This function can support :ref:`specifying a file descriptor <path_fd>` and
31503202
:ref:`not following symlinks <follow_symlinks>`.
31513203

3204+
.. audit-event:: os.listxattr path os.listxattr
3205+
31523206
.. versionchanged:: 3.6
31533207
Accepts a :term:`path-like object`.
31543208

@@ -3163,6 +3217,8 @@ These functions are all available on Linux only.
31633217
This function can support :ref:`specifying a file descriptor <path_fd>` and
31643218
:ref:`not following symlinks <follow_symlinks>`.
31653219

3220+
.. audit-event:: os.removexattr path,attribute os.removexattr
3221+
31663222
.. versionchanged:: 3.6
31673223
Accepts a :term:`path-like object` for *path* and *attribute*.
31683224

@@ -3186,6 +3242,8 @@ These functions are all available on Linux only.
31863242
A bug in Linux kernel versions less than 2.6.39 caused the flags argument
31873243
to be ignored on some filesystems.
31883244

3245+
.. audit-event:: os.setxattr path,attribute,value,flags os.setxattr
3246+
31893247
.. versionchanged:: 3.6
31903248
Accepts a :term:`path-like object` for *path* and *attribute*.
31913249

@@ -3248,6 +3306,8 @@ to be ignored.
32483306
<https://msdn.microsoft.com/44228cf2-6306-466c-8f16-f513cd3ba8b5>`_
32493307
for more information about how DLLs are loaded.
32503308

3309+
.. audit-event:: os.add_dll_directory path os.add_dll_directory
3310+
32513311
.. availability:: Windows.
32523312

32533313
.. versionadded:: 3.8
@@ -3480,6 +3540,8 @@ written in Python, such as a mail server's external command delivery program.
34803540
Note that some platforms including FreeBSD <= 6.3 and Cygwin have
34813541
known issues when using ``fork()`` from a thread.
34823542

3543+
.. audit-event:: os.fork "" os.fork
3544+
34833545
.. versionchanged:: 3.8
34843546
Calling ``fork()`` in a subinterpreter is no longer supported
34853547
(:exc:`RuntimeError` is raised).
@@ -3499,6 +3561,8 @@ written in Python, such as a mail server's external command delivery program.
34993561
master end of the pseudo-terminal. For a more portable approach, use the
35003562
:mod:`pty` module. If an error occurs :exc:`OSError` is raised.
35013563

3564+
.. audit-event:: os.forkpty "" os.forkpty
3565+
35023566
.. versionchanged:: 3.8
35033567
Calling ``forkpty()`` in a subinterpreter is no longer supported
35043568
(:exc:`RuntimeError` is raised).
@@ -3525,6 +3589,8 @@ written in Python, such as a mail server's external command delivery program.
35253589

35263590
See also :func:`signal.pthread_kill`.
35273591

3592+
.. audit-event:: os.kill pid,sig os.kill
3593+
35283594
.. versionadded:: 3.2
35293595
Windows support.
35303596

@@ -3537,6 +3603,8 @@ written in Python, such as a mail server's external command delivery program.
35373603

35383604
Send the signal *sig* to the process group *pgid*.
35393605

3606+
.. audit-event:: os.killpg pgid,sig os.killpg
3607+
35403608
.. availability:: Unix.
35413609

35423610

Doc/library/resource.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ this module for those platforms.
7878

7979
VxWorks only supports setting :data:`RLIMIT_NOFILE`.
8080

81+
.. audit-event:: resource.setrlimit resource,limits resource.setrlimit
82+
83+
8184
.. function:: prlimit(pid, resource[, limits])
8285

8386
Combines :func:`setrlimit` and :func:`getrlimit` in one function and
@@ -94,6 +97,8 @@ this module for those platforms.
9497
:exc:`PermissionError` when the user doesn't have ``CAP_SYS_RESOURCE`` for
9598
the process.
9699

100+
.. audit-event:: resource.prlimit pid,resource,limits resource.prlimit
101+
97102
.. availability:: Linux 2.6.36 or later with glibc 2.13 or later.
98103

99104
.. versionadded:: 3.4

0 commit comments

Comments
 (0)