1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-28 01:58:17 +03:00

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 <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Stefan Metzmacher 2016-08-23 09:35:50 +02:00 committed by Ralph Boehme
parent b86c29b1e6
commit d7840e7796
2 changed files with 26 additions and 1 deletions

View File

@ -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,

View File

@ -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