2021-08-13 10:20:45 +00:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
|
|
|
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
│ Python 3 │
|
|
|
|
│ https://docs.python.org/3/license.html │
|
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2021-08-12 07:42:14 +00:00
|
|
|
#include "third_party/python/Include/modsupport.h"
|
|
|
|
#include "third_party/python/Include/object.h"
|
|
|
|
#include "third_party/python/Include/pymacro.h"
|
2021-09-05 08:20:03 +00:00
|
|
|
#include "third_party/python/Include/yoink.h"
|
2021-08-10 17:26:13 +00:00
|
|
|
/* clang-format off */
|
2021-08-12 07:42:14 +00:00
|
|
|
|
2021-09-05 08:20:03 +00:00
|
|
|
PYTHON_PROVIDE("_crypt");
|
2021-09-07 02:24:10 +00:00
|
|
|
PYTHON_PROVIDE("_crypt.crypt");
|
2021-09-05 08:20:03 +00:00
|
|
|
|
2021-08-08 04:08:33 +00:00
|
|
|
/* cryptmodule.c - by Steve Majewski
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
module crypt
|
|
|
|
[clinic start generated code]*/
|
|
|
|
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=c6252cf4f2f2ae81]*/
|
|
|
|
|
2021-08-10 17:26:13 +00:00
|
|
|
#include "third_party/python/Modules/clinic/_cryptmodule.inc"
|
2021-08-08 04:08:33 +00:00
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
crypt.crypt
|
|
|
|
|
|
|
|
word: str
|
|
|
|
salt: str
|
|
|
|
/
|
|
|
|
|
|
|
|
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]*/
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
crypt_crypt_impl(PyObject *module, const char *word, const char *salt)
|
|
|
|
/*[clinic end generated code: output=0512284a03d2803c input=0e8edec9c364352b]*/
|
|
|
|
{
|
|
|
|
/* 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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static PyMethodDef crypt_methods[] = {
|
|
|
|
CRYPT_CRYPT_METHODDEF
|
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static struct PyModuleDef cryptmodule = {
|
|
|
|
PyModuleDef_HEAD_INIT,
|
|
|
|
"_crypt",
|
|
|
|
NULL,
|
|
|
|
-1,
|
|
|
|
crypt_methods,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
PyMODINIT_FUNC
|
|
|
|
PyInit__crypt(void)
|
|
|
|
{
|
|
|
|
return PyModule_Create(&cryptmodule);
|
|
|
|
}
|