summaryrefslogtreecommitdiff
path: root/Modules/main.c
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2019-07-01 16:03:53 -0700
committerGitHub <noreply@github.com>2019-07-01 16:03:53 -0700
commite226e83d36dfc7220d836fb7a249ce18e70cb4a6 (patch)
treeec4de1abf366960dadf2aa1e8e1b4b89458243f9 /Modules/main.c
parent0f4e8132820947d93eccf31b9e526b81c6ffa53d (diff)
downloadcpython-git-e226e83d36dfc7220d836fb7a249ce18e70cb4a6.tar.gz
bpo-37363: Add audit events on startup for the run commands (GH-14524)
Diffstat (limited to 'Modules/main.c')
-rw-r--r--Modules/main.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/Modules/main.c b/Modules/main.c
index b126f4554d..b8a1c9b79c 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -247,6 +247,10 @@ pymain_run_command(wchar_t *command, PyCompilerFlags *cf)
goto error;
}
+ if (PySys_Audit("cpython.run_command", "O", unicode) < 0) {
+ return pymain_exit_err_print();
+ }
+
bytes = PyUnicode_AsUTF8String(unicode);
Py_DECREF(unicode);
if (bytes == NULL) {
@@ -267,6 +271,9 @@ static int
pymain_run_module(const wchar_t *modname, int set_argv0)
{
PyObject *module, *runpy, *runmodule, *runargs, *result;
+ if (PySys_Audit("cpython.run_module", "u", modname) < 0) {
+ return pymain_exit_err_print();
+ }
runpy = PyImport_ImportModule("runpy");
if (runpy == NULL) {
fprintf(stderr, "Could not import runpy module\n");
@@ -311,6 +318,9 @@ static int
pymain_run_file(PyConfig *config, PyCompilerFlags *cf)
{
const wchar_t *filename = config->run_filename;
+ if (PySys_Audit("cpython.run_file", "u", filename) < 0) {
+ return pymain_exit_err_print();
+ }
FILE *fp = _Py_wfopen(filename, L"rb");
if (fp == NULL) {
char *cfilename_buffer;
@@ -383,6 +393,9 @@ pymain_run_startup(PyConfig *config, PyCompilerFlags *cf, int *exitcode)
if (startup == NULL) {
return 0;
}
+ if (PySys_Audit("cpython.run_startup", "s", startup) < 0) {
+ return pymain_err_print(exitcode);
+ }
FILE *fp = _Py_fopen(startup, "r");
if (fp == NULL) {
@@ -420,6 +433,10 @@ pymain_run_interactive_hook(int *exitcode)
return 0;
}
+ if (PySys_Audit("cpython.run_interactivehook", "O", hook) < 0) {
+ goto error;
+ }
+
result = _PyObject_CallNoArg(hook);
Py_DECREF(hook);
if (result == NULL) {
@@ -457,6 +474,10 @@ pymain_run_stdin(PyConfig *config, PyCompilerFlags *cf)
return pymain_exit_err_print();
}
+ if (PySys_Audit("cpython.run_stdin", NULL) < 0) {
+ return pymain_exit_err_print();
+ }
+
int run = PyRun_AnyFileExFlags(stdin, "<stdin>", 0, cf);
return (run != 0);
}