Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit a00b5be

Browse files
zoobagousaiyang
andauthored
bpo-39184: Add audit events to functions in fcntl, msvcrt, os, resource, shutil, signal, syslog (pythonGH-18407)
Co-authored-by: Saiyang Gou <[email protected]>
1 parent 669981b commit a00b5be

File tree

15 files changed

+314
-17
lines changed

15 files changed

+314
-17
lines changed

Doc/library/fcntl.rst

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

5858
If the :c:func:`fcntl` fails, an :exc:`OSError` is raised.
5959

60+
.. audit-event:: fcntl.fcntl fd,cmd,arg fcntl.fcntl
61+
6062

6163
.. function:: ioctl(fd, request, arg=0, mutate_flag=True)
6264

@@ -106,6 +108,8 @@ The module defines the following functions:
106108
>>> buf
107109
array('h', [13341])
108110

111+
.. audit-event:: fcntl.ioctl fd,request,arg fcntl.ioctl
112+
109113

110114
.. function:: flock(fd, operation)
111115

@@ -116,6 +120,8 @@ The module defines the following functions:
116120

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

123+
.. audit-event:: fcntl.flock fd,operation fcntl.flock
124+
119125

120126
.. function:: lockf(fd, cmd, len=0, start=0, whence=0)
121127

@@ -149,6 +155,8 @@ The module defines the following functions:
149155
The default for *len* is 0 which means to lock to the end of the file. The
150156
default for *whence* is also 0.
151157

158+
.. audit-event:: fcntl.lockf fd,cmd,len,start,whence fcntl.lockf
159+
152160
Examples (all on a SVR4 compliant system)::
153161

154162
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
@@ -451,6 +451,8 @@ process and user.
451451
calls to :func:`putenv` don't update ``os.environ``, so it is actually
452452
preferable to assign to items of ``os.environ``.
453453

454+
.. audit-event:: os.putenv key,value os.putenv
455+
454456

455457
.. function:: setegid(egid)
456458

@@ -643,6 +645,8 @@ process and user.
643645
calls to :func:`unsetenv` don't update ``os.environ``, so it is actually
644646
preferable to delete items of ``os.environ``.
645647

648+
.. audit-event:: os.unsetenv key os.unsetenv
649+
646650
.. availability:: most flavors of Unix.
647651

648652

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

775+
.. audit-event:: os.chmod path,mode,dir_fd os.fchmod
776+
771777
.. availability:: Unix.
772778

773779

@@ -778,6 +784,8 @@ as internal buffering of data.
778784
:func:`chown`. As of Python 3.3, this is equivalent to ``os.chown(fd, uid,
779785
gid)``.
780786

787+
.. audit-event:: os.chown path,uid,gid,dir_fd os.fchown
788+
781789
.. availability:: Unix.
782790

783791

@@ -885,6 +893,8 @@ as internal buffering of data.
885893
:data:`F_ULOCK` or :data:`F_TEST`.
886894
*len* specifies the section of the file to lock.
887895

896+
.. audit-event:: os.lockf fd,cmd,len os.lockf
897+
888898
.. availability:: Unix.
889899

890900
.. versionadded:: 3.3
@@ -1602,6 +1612,8 @@ features:
16021612
This function can raise :exc:`OSError` and subclasses such as
16031613
:exc:`FileNotFoundError`, :exc:`PermissionError`, and :exc:`NotADirectoryError`.
16041614

1615+
.. audit-event:: os.chdir path os.chdir
1616+
16051617
.. versionadded:: 3.3
16061618
Added support for specifying *path* as a file descriptor
16071619
on some platforms.
@@ -1630,6 +1642,8 @@ features:
16301642

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

1645+
.. audit-event:: os.chflags path,flags os.chflags
1646+
16331647
.. availability:: Unix.
16341648

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

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

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

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

1742+
.. audit-event:: os.chdir path os.fchdir
1743+
17241744
.. availability:: Unix.
17251745

17261746

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

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

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

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

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

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

17741800
.. versionchanged:: 3.6
@@ -1783,6 +1809,8 @@ features:
17831809
supply :ref:`paths relative to directory descriptors <dir_fd>`, and :ref:`not
17841810
following symlinks <follow_symlinks>`.
17851811

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

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

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

@@ -1917,6 +1947,8 @@ features:
19171947

19181948
This function handles UNC paths correctly.
19191949

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

@@ -2082,6 +2114,8 @@ features:
20822114

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

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

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

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

@@ -2127,6 +2163,8 @@ features:
21272163

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

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

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

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

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

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

21662208
.. versionchanged:: 3.6
@@ -2177,6 +2219,8 @@ features:
21772219
This function can support :ref:`paths relative to directory descriptors
21782220
<dir_fd>`.
21792221

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

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

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

28252871
.. versionchanged:: 3.2
@@ -2872,6 +2918,8 @@ features:
28722918
traditional Unix name. Please see the documentation for
28732919
:func:`remove` for further information.
28742920

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

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

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

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

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

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

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

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

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

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

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

3308+
.. audit-event:: os.add_dll_directory path os.add_dll_directory
3309+
32503310
.. availability:: Windows.
32513311

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

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

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

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

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

@@ -3536,6 +3602,8 @@ written in Python, such as a mail server's external command delivery program.
35363602

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

3605+
.. audit-event:: os.killpg pgid,sig os.killpg
3606+
35393607
.. availability:: Unix.
35403608

35413609

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)