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>
|
|
|
|
|
2006-07-09 22:18:57 -03:00
|
|
|
#ifdef __VMS
|
|
|
|
#include <openssl/des.h>
|
|
|
|
#endif
|
1994-05-06 11:25:39 -03:00
|
|
|
|
|
|
|
/* Module crypt */
|
|
|
|
|
|
|
|
|
2000-07-10 06:57:19 -03:00
|
|
|
static PyObject *crypt_crypt(PyObject *self, PyObject *args)
|
1994-05-06 11:25:39 -03:00
|
|
|
{
|
2010-05-09 12:15:40 -03:00
|
|
|
char *word, *salt;
|
2006-07-09 22:18:57 -03:00
|
|
|
#ifndef __VMS
|
2010-05-09 12:15:40 -03:00
|
|
|
extern char * crypt(const char *, const char *);
|
2006-07-09 22:18:57 -03:00
|
|
|
#endif
|
1994-05-06 11:25:39 -03:00
|
|
|
|
2010-05-09 12:15:40 -03:00
|
|
|
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));
|
1994-05-06 11:25:39 -03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-06-13 17:33:02 -03:00
|
|
|
PyDoc_STRVAR(crypt_crypt__doc__,
|
|
|
|
"crypt(word, salt) -> string\n\
|
2000-02-01 16:12:39 -04:00
|
|
|
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\
|
2002-06-13 17:33:02 -03:00
|
|
|
the same alphabet as the salt.");
|
2000-02-01 16:12:39 -04:00
|
|
|
|
|
|
|
|
1996-12-09 19:14:26 -04:00
|
|
|
static PyMethodDef crypt_methods[] = {
|
2010-05-09 12:15:40 -03:00
|
|
|
{"crypt", crypt_crypt, METH_VARARGS, crypt_crypt__doc__},
|
|
|
|
{NULL, NULL} /* sentinel */
|
1994-05-06 11:25:39 -03:00
|
|
|
};
|
|
|
|
|
2002-08-01 23:27:13 -03:00
|
|
|
PyMODINIT_FUNC
|
2000-07-21 03:00:07 -03:00
|
|
|
initcrypt(void)
|
1994-05-06 11:25:39 -03:00
|
|
|
{
|
2010-05-09 12:15:40 -03:00
|
|
|
Py_InitModule("crypt", crypt_methods);
|
1994-05-06 11:25:39 -03:00
|
|
|
}
|