1994-05-06 11:25:39 -03:00
|
|
|
/* cryptmodule.c - by Steve Majewski
|
|
|
|
*/
|
|
|
|
|
1996-12-09 19:14:26 -04:00
|
|
|
#include "Python.h"
|
1994-05-06 11:25:39 -03:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
/* Module crypt */
|
|
|
|
|
2014-01-14 16:00:27 -04:00
|
|
|
/*[clinic input]
|
|
|
|
module crypt
|
|
|
|
[clinic start generated code]*/
|
2014-01-28 09:00:08 -04:00
|
|
|
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=c6252cf4f2f2ae81]*/
|
1994-05-06 11:25:39 -03:00
|
|
|
|
2014-01-14 16:00:27 -04:00
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
crypt.crypt
|
|
|
|
|
|
|
|
word: 's'
|
|
|
|
salt: 's'
|
|
|
|
/
|
|
|
|
|
|
|
|
Hash a *word* with the given *salt* and return the hashed password.
|
|
|
|
|
|
|
|
*word* will usually be a user's password. *salt* (either a random 2 or 16
|
|
|
|
character string, possibly prefixed with $digit$ to indicate the method)
|
|
|
|
will be used to perturb the encryption algorithm and produce distinct
|
|
|
|
results for a given *word*.
|
|
|
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
PyDoc_STRVAR(crypt_crypt__doc__,
|
2014-02-09 02:15:29 -04:00
|
|
|
"crypt($module, word, salt, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
2014-01-14 16:00:27 -04:00
|
|
|
"Hash a *word* with the given *salt* and return the hashed password.\n"
|
|
|
|
"\n"
|
|
|
|
"*word* will usually be a user\'s password. *salt* (either a random 2 or 16\n"
|
|
|
|
"character string, possibly prefixed with $digit$ to indicate the method)\n"
|
|
|
|
"will be used to perturb the encryption algorithm and produce distinct\n"
|
|
|
|
"results for a given *word*.");
|
|
|
|
|
|
|
|
#define CRYPT_CRYPT_METHODDEF \
|
|
|
|
{"crypt", (PyCFunction)crypt_crypt, METH_VARARGS, crypt_crypt__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
crypt_crypt_impl(PyModuleDef *module, const char *word, const char *salt);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
crypt_crypt(PyModuleDef *module, PyObject *args)
|
1994-05-06 11:25:39 -03:00
|
|
|
{
|
2014-01-14 16:00:27 -04:00
|
|
|
PyObject *return_value = NULL;
|
|
|
|
const char *word;
|
|
|
|
const char *salt;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args,
|
|
|
|
"ss:crypt",
|
|
|
|
&word, &salt))
|
|
|
|
goto exit;
|
|
|
|
return_value = crypt_crypt_impl(module, word, salt);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
1994-05-06 11:25:39 -03:00
|
|
|
|
2014-01-14 16:00:27 -04:00
|
|
|
static PyObject *
|
|
|
|
crypt_crypt_impl(PyModuleDef *module, const char *word, const char *salt)
|
2014-02-09 02:15:29 -04:00
|
|
|
/*[clinic end generated code: output=3eaacdf994a6ff23 input=4d93b6d0f41fbf58]*/
|
2014-01-14 16:00:27 -04:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
/* On some platforms (AtheOS) crypt returns NULL for an invalid
|
|
|
|
salt. Return None in that case. XXX Maybe raise an exception? */
|
|
|
|
return Py_BuildValue("s", crypt(word, salt));
|
1994-05-06 11:25:39 -03:00
|
|
|
}
|
|
|
|
|
2000-02-01 16:12:39 -04:00
|
|
|
|
1996-12-09 19:14:26 -04:00
|
|
|
static PyMethodDef crypt_methods[] = {
|
2014-01-14 16:00:27 -04:00
|
|
|
CRYPT_CRYPT_METHODDEF
|
2010-05-09 12:52:27 -03:00
|
|
|
{NULL, NULL} /* sentinel */
|
1994-05-06 11:25:39 -03:00
|
|
|
};
|
|
|
|
|
2008-06-11 02:26:20 -03:00
|
|
|
|
|
|
|
static struct PyModuleDef cryptmodule = {
|
2010-05-09 12:52:27 -03:00
|
|
|
PyModuleDef_HEAD_INIT,
|
2011-02-22 06:55:44 -04:00
|
|
|
"_crypt",
|
2010-05-09 12:52:27 -03:00
|
|
|
NULL,
|
|
|
|
-1,
|
|
|
|
crypt_methods,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
2008-06-11 02:26:20 -03:00
|
|
|
};
|
|
|
|
|
2002-08-01 23:27:13 -03:00
|
|
|
PyMODINIT_FUNC
|
2011-02-22 06:55:44 -04:00
|
|
|
PyInit__crypt(void)
|
1994-05-06 11:25:39 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
return PyModule_Create(&cryptmodule);
|
1994-05-06 11:25:39 -03:00
|
|
|
}
|