From 40366fd386b3793451857670109f7c0be7011230 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 23 Aug 2016 09:35:50 +0200 Subject: [PATCH] pyglue: add generate_random_machine_password() wrapper We use PyUnicode_FromString() (which is available from 2.6) because we really have non-ascii strings. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12262 Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme (cherry picked from commit d7840e77961cdc4ccc4f5549494d458b6b2c2cf4) --- python/pyglue.c | 26 +++++++++++++++++++++++++- python/samba/__init__.py | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/python/pyglue.c b/python/pyglue.c index dbe7eb4ec69..0e80ba62609 100644 --- a/python/pyglue.c +++ b/python/pyglue.c @@ -60,6 +60,23 @@ static PyObject *py_generate_random_password(PyObject *self, PyObject *args) return ret; } +static PyObject *py_generate_random_machine_password(PyObject *self, PyObject *args) +{ + int min, max; + PyObject *ret; + char *retstr; + if (!PyArg_ParseTuple(args, "ii", &min, &max)) + return NULL; + + retstr = generate_random_machine_password(NULL, min, max); + if (retstr == NULL) { + return NULL; + } + ret = PyUnicode_FromString(retstr); + talloc_free(retstr); + return ret; +} + static PyObject *py_unix2nttime(PyObject *self, PyObject *args) { time_t t; @@ -261,7 +278,14 @@ static PyMethodDef py_misc_methods[] = { "Generate random string with specified length." }, { "generate_random_password", (PyCFunction)py_generate_random_password, METH_VARARGS, "generate_random_password(min, max) -> string\n" - "Generate random password with a length >= min and <= max." }, + "Generate random password (based on printable ascii characters) " + "with a length >= min and <= max." }, + { "generate_random_machine_password", (PyCFunction)py_generate_random_machine_password, + METH_VARARGS, "generate_random_machine_password(min, max) -> string\n" + "Generate random password " + "(based on random utf16 characters converted to utf8 or " + "random ascii characters if 'unix charset' is not 'utf8')" + "with a length >= min (at least 14) and <= max (at most 255)." }, { "unix2nttime", (PyCFunction)py_unix2nttime, METH_VARARGS, "unix2nttime(timestamp) -> nttime" }, { "nttime2unix", (PyCFunction)py_nttime2unix, METH_VARARGS, diff --git a/python/samba/__init__.py b/python/samba/__init__.py index 5f915318093..19d5e38e896 100644 --- a/python/samba/__init__.py +++ b/python/samba/__init__.py @@ -396,6 +396,7 @@ nttime2string = _glue.nttime2string nttime2unix = _glue.nttime2unix unix2nttime = _glue.unix2nttime generate_random_password = _glue.generate_random_password +generate_random_machine_password = _glue.generate_random_machine_password strcasecmp_m = _glue.strcasecmp_m strstr_m = _glue.strstr_m is_ntvfs_fileserver_built = _glue.is_ntvfs_fileserver_built -- 2.11.4.GIT