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