aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python/src/Modules/cryptmodule.c
diff options
context:
space:
mode:
authornkozlovskiy <nmk@ydb.tech>2023-09-29 12:24:06 +0300
committernkozlovskiy <nmk@ydb.tech>2023-09-29 12:41:34 +0300
commite0e3e1717e3d33762ce61950504f9637a6e669ed (patch)
treebca3ff6939b10ed60c3d5c12439963a1146b9711 /contrib/tools/python/src/Modules/cryptmodule.c
parent38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff)
downloadydb-e0e3e1717e3d33762ce61950504f9637a6e669ed.tar.gz
add ydb deps
Diffstat (limited to 'contrib/tools/python/src/Modules/cryptmodule.c')
-rw-r--r--contrib/tools/python/src/Modules/cryptmodule.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/contrib/tools/python/src/Modules/cryptmodule.c b/contrib/tools/python/src/Modules/cryptmodule.c
new file mode 100644
index 0000000000..858adf5ee8
--- /dev/null
+++ b/contrib/tools/python/src/Modules/cryptmodule.c
@@ -0,0 +1,53 @@
+/* cryptmodule.c - by Steve Majewski
+ */
+
+#include "Python.h"
+
+#include <sys/types.h>
+
+#if defined(__VMS) || defined(__CYGWIN__)
+#include <openssl/des.h>
+#endif
+
+#if defined(__CYGWIN__)
+#define crypt DES_crypt
+#endif
+
+/* Module crypt */
+
+
+static PyObject *crypt_crypt(PyObject *self, PyObject *args)
+{
+ char *word, *salt;
+#ifndef __VMS
+ extern char * crypt(const char *, const char *);
+#endif
+
+ if (!PyArg_ParseTuple(args, "ss:crypt", &word, &salt)) {
+ return NULL;
+ }
+ /* 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));
+
+}
+
+PyDoc_STRVAR(crypt_crypt__doc__,
+"crypt(word, salt) -> string\n\
+word will usually be a user's password. salt is a 2-character string\n\
+which will be used to select one of 4096 variations of DES. The characters\n\
+in salt must be either \".\", \"/\", or an alphanumeric character. Returns\n\
+the hashed password as a string, which will be composed of characters from\n\
+the same alphabet as the salt.");
+
+
+static PyMethodDef crypt_methods[] = {
+ {"crypt", crypt_crypt, METH_VARARGS, crypt_crypt__doc__},
+ {NULL, NULL} /* sentinel */
+};
+
+PyMODINIT_FUNC
+initcrypt(void)
+{
+ Py_InitModule("crypt", crypt_methods);
+}