Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 1 | /* cryptmodule.c - by Steve Majewski |
| 2 | */ |
| 3 | |
Roger E. Masse | 56c345b | 1996-12-09 23:14:26 +0000 | [diff] [blame] | 4 | #include "Python.h" |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 5 | |
| 6 | #include <sys/types.h> |
| 7 | |
Neal Norwitz | 2a30cd0 | 2006-07-10 01:18:57 +0000 | [diff] [blame] | 8 | #ifdef __VMS |
| 9 | #include <openssl/des.h> |
| 10 | #endif |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 11 | |
| 12 | /* Module crypt */ |
| 13 | |
| 14 | |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 15 | static PyObject *crypt_crypt(PyObject *self, PyObject *args) |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 16 | { |
| 17 | char *word, *salt; |
Neal Norwitz | 2a30cd0 | 2006-07-10 01:18:57 +0000 | [diff] [blame] | 18 | #ifndef __VMS |
Thomas Wouters | bd4bc4e | 2000-07-22 23:57:55 +0000 | [diff] [blame] | 19 | extern char * crypt(const char *, const char *); |
Neal Norwitz | 2a30cd0 | 2006-07-10 01:18:57 +0000 | [diff] [blame] | 20 | #endif |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 21 | |
Neal Norwitz | ba3a16c | 2002-03-31 15:27:00 +0000 | [diff] [blame] | 22 | if (!PyArg_ParseTuple(args, "ss:crypt", &word, &salt)) { |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 23 | return NULL; |
| 24 | } |
Martin v. Löwis | f90ae20 | 2002-06-11 06:22:31 +0000 | [diff] [blame] | 25 | /* On some platforms (AtheOS) crypt returns NULL for an invalid |
| 26 | salt. Return None in that case. XXX Maybe raise an exception? */ |
| 27 | return Py_BuildValue("s", crypt(word, salt)); |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 28 | |
| 29 | } |
| 30 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 31 | PyDoc_STRVAR(crypt_crypt__doc__, |
| 32 | "crypt(word, salt) -> string\n\ |
Fred Drake | a664dbb | 2000-02-01 20:12:39 +0000 | [diff] [blame] | 33 | word will usually be a user's password. salt is a 2-character string\n\ |
| 34 | which will be used to select one of 4096 variations of DES. The characters\n\ |
| 35 | in salt must be either \".\", \"/\", or an alphanumeric character. Returns\n\ |
| 36 | the hashed password as a string, which will be composed of characters from\n\ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 37 | the same alphabet as the salt."); |
Fred Drake | a664dbb | 2000-02-01 20:12:39 +0000 | [diff] [blame] | 38 | |
| 39 | |
Roger E. Masse | 56c345b | 1996-12-09 23:14:26 +0000 | [diff] [blame] | 40 | static PyMethodDef crypt_methods[] = { |
Neal Norwitz | ba3a16c | 2002-03-31 15:27:00 +0000 | [diff] [blame] | 41 | {"crypt", crypt_crypt, METH_VARARGS, crypt_crypt__doc__}, |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 42 | {NULL, NULL} /* sentinel */ |
| 43 | }; |
| 44 | |
Mark Hammond | fe51c6d | 2002-08-02 02:27:13 +0000 | [diff] [blame] | 45 | PyMODINIT_FUNC |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 46 | initcrypt(void) |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 47 | { |
Roger E. Masse | 56c345b | 1996-12-09 23:14:26 +0000 | [diff] [blame] | 48 | Py_InitModule("crypt", crypt_methods); |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 49 | } |