From d2cd0a783b059fc2a938f7e2a5f5d002e83be967 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 24 Feb 2010 14:44:22 +0100 Subject: s4:pyglue: add generate_random_password() metze --- source4/scripting/python/pyglue.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'source4/scripting/python/pyglue.c') diff --git a/source4/scripting/python/pyglue.c b/source4/scripting/python/pyglue.c index 136b121bc0..6fe789ae73 100644 --- a/source4/scripting/python/pyglue.c +++ b/source4/scripting/python/pyglue.c @@ -79,6 +79,23 @@ static PyObject *py_generate_random_str(PyObject *self, PyObject *args) return ret; } +static PyObject *py_generate_random_password(PyObject *self, PyObject *args) +{ + int min, max; + PyObject *ret; + char *retstr; + if (!PyArg_ParseTuple(args, "ii", &min, &max)) + return NULL; + + retstr = generate_random_password(NULL, min, max); + if (retstr == NULL) { + return NULL; + } + ret = PyString_FromString(retstr); + talloc_free(retstr); + return ret; +} + static PyObject *py_unix2nttime(PyObject *self, PyObject *args) { time_t t; @@ -636,8 +653,11 @@ static PyObject *py_interface_ips(PyObject *self, PyObject *args) static PyMethodDef py_misc_methods[] = { { "generate_random_str", (PyCFunction)py_generate_random_str, METH_VARARGS, - "random_password(len) -> string\n" - "Generate random password with specified length." }, + "generate_random_str(len) -> string\n" + "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." }, { "unix2nttime", (PyCFunction)py_unix2nttime, METH_VARARGS, "unix2nttime(timestamp) -> nttime" }, { "ldb_set_session_info", (PyCFunction)py_ldb_set_session_info, METH_VARARGS, -- cgit