1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

python: Add glue.burn_commandline() method

This uses samba_cmdline_burn() to as to have common
command line redaction code.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15289

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
Andrew Bartlett 2023-07-21 13:29:22 +12:00
parent 5afd206d1d
commit 3f9e455898
2 changed files with 60 additions and 0 deletions

View File

@ -26,6 +26,7 @@
#include "lib/socket/netif.h" #include "lib/socket/netif.h"
#include "lib/util/debug.h" #include "lib/util/debug.h"
#include "librpc/ndr/ndr_private.h" #include "librpc/ndr/ndr_private.h"
#include "lib/cmdline/cmdline.h"
void init_glue(void); void init_glue(void);
static PyObject *PyExc_NTSTATUSError; static PyObject *PyExc_NTSTATUSError;
@ -466,6 +467,62 @@ static PyObject *py_strstr_m(PyObject *self, PyObject *args)
return result; return result;
} }
static PyObject *py_get_burnt_commandline(PyObject *self, PyObject *args)
{
PyObject *cmdline_as_list, *ret;
char *burnt_cmdline = NULL;
Py_ssize_t i, argc;
char **argv = NULL;
TALLOC_CTX *frame = talloc_stackframe();
bool burnt;
if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &cmdline_as_list))
{
TALLOC_FREE(frame);
return NULL;
}
argc = PyList_GET_SIZE(cmdline_as_list);
if (argc == 0) {
TALLOC_FREE(frame);
Py_RETURN_NONE;
}
argv = PyList_AsStringList(frame, cmdline_as_list, "sys.argv");
if (argv == NULL) {
return NULL;
}
burnt = samba_cmdline_burn(argc, argv);
if (!burnt) {
TALLOC_FREE(frame);
Py_RETURN_NONE;
}
for (i = 0; i < argc; i++) {
if (i == 0) {
burnt_cmdline = talloc_strdup(frame,
argv[i]);
} else {
burnt_cmdline
= talloc_asprintf_append(burnt_cmdline,
" %s",
argv[i]);
}
if (burnt_cmdline == NULL) {
PyErr_NoMemory();
TALLOC_FREE(frame);
return NULL;
}
}
ret = PyUnicode_FromString(burnt_cmdline);
TALLOC_FREE(frame);
return ret;
}
static PyMethodDef py_misc_methods[] = { static PyMethodDef py_misc_methods[] = {
{ "generate_random_str", (PyCFunction)py_generate_random_str, METH_VARARGS, { "generate_random_str", (PyCFunction)py_generate_random_str, METH_VARARGS,
"generate_random_str(len) -> string\n" "generate_random_str(len) -> string\n"
@ -525,6 +582,8 @@ static PyMethodDef py_misc_methods[] = {
METH_NOARGS, "is Samba built with selftest enabled?" }, METH_NOARGS, "is Samba built with selftest enabled?" },
{ "ndr_token_max_list_size", (PyCFunction)py_ndr_token_max_list_size, { "ndr_token_max_list_size", (PyCFunction)py_ndr_token_max_list_size,
METH_NOARGS, "How many NDR internal tokens is too many for this build?" }, METH_NOARGS, "How many NDR internal tokens is too many for this build?" },
{ "get_burnt_commandline", (PyCFunction)py_get_burnt_commandline,
METH_VARARGS, "Return a redacted commandline to feed to setproctitle (None if no redaction required)" },
{0} {0}
}; };

View File

@ -117,6 +117,7 @@ def build(bld):
samba-util samba-util
netif netif
ndr ndr
cmdline
%s %s
''' % (pyparam_util, pytalloc_util), ''' % (pyparam_util, pytalloc_util),
realname='samba/_glue.so') realname='samba/_glue.so')