Fix typo in iteration time api call.
[platform/upstream/cryptsetup.git] / python / pycryptsetup.c
1 /*
2  * Python bindings to libcryptsetup
3  *
4  * Copyright (C) 2009-2011, Red Hat, Inc. All rights reserved.
5  * Written by Martin Sivak
6  *
7  * This file is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This file is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this file; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <Python.h>
23 #include <structmember.h>
24 #include <errno.h>
25
26 #include "libcryptsetup.h"
27
28 typedef struct {
29         PyObject_HEAD
30
31         /* Type-specific fields go here. */
32         struct crypt_device *device;
33         char *activated_as;
34
35         /* Callbacks */
36         PyObject *yesDialogCB;
37         PyObject *cmdLineLogCB;
38         PyObject *passwordDialogCB;
39 } CryptSetupObject;
40
41 static int yesDialog(const char *msg, void *this)
42 {
43         CryptSetupObject *self = this;
44         PyObject *result, *arglist;
45         int r;
46
47         if (self->yesDialogCB){
48                 arglist = Py_BuildValue("(s)", msg);
49                 if (!arglist)
50                         return -ENOMEM;
51
52                 result = PyEval_CallObject(self->yesDialogCB, arglist);
53                 Py_DECREF(arglist);
54
55                 if (!result)
56                         return -EINVAL;
57
58                 if (!PyArg_Parse(result, "i", &r))
59                         r = -EINVAL;
60
61                 Py_DECREF(result);
62                 return r;
63         }
64
65         return 1;
66 }
67
68 static int passwordDialog(const char *msg, char *buf, size_t length, void *this)
69 {
70         CryptSetupObject *self = this;
71         PyObject *result, *arglist;
72         char *res = NULL;
73
74         if(self->passwordDialogCB){
75                 arglist = Py_BuildValue("(s)", msg);
76                 if (!arglist)
77                         return -ENOMEM;
78
79                 result = PyEval_CallObject(self->passwordDialogCB, arglist);
80                 Py_DECREF(arglist);
81
82                 if (!result)
83                         return -EINVAL;
84
85                 if (!PyArg_Parse(result, "z", &res)) {
86                         Py_DECREF(result);
87                         return -EINVAL;
88                 }
89
90                 strncpy(buf, res, length - 1);
91
92                 // FIXME: wipe res
93                 Py_DECREF(result);
94                 return strlen(buf);
95         }
96
97         return -EINVAL;
98 }
99
100 static void cmdLineLog(int cls, const char *msg, void *this)
101 {
102         CryptSetupObject *self = this;
103         PyObject *result, *arglist;
104
105         if(self->cmdLineLogCB) {
106                 arglist = Py_BuildValue("(is)", cls, msg);
107                 if(!arglist)
108                         return;
109
110                 result = PyEval_CallObject(self->cmdLineLogCB, arglist);
111                 Py_DECREF(arglist);
112                 Py_XDECREF(result);
113         }
114 }
115
116 static void CryptSetup_dealloc(CryptSetupObject* self)
117 {
118         /* free the callbacks */
119         Py_XDECREF(self->yesDialogCB);
120         Py_XDECREF(self->cmdLineLogCB);
121         Py_XDECREF(self->passwordDialogCB);
122
123         free(self->activated_as);
124
125         crypt_free(self->device);
126
127         /* free self */
128         self->ob_type->tp_free((PyObject*)self);
129 }
130
131 static PyObject *CryptSetup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
132 {
133         CryptSetupObject *self = (CryptSetupObject *)type->tp_alloc(type, 0);
134
135         if (self) {
136                 self->yesDialogCB = NULL;
137                 self->passwordDialogCB = NULL;
138                 self->cmdLineLogCB = NULL;
139                 self->activated_as = NULL;
140         }
141
142         return (PyObject *)self;
143 }
144
145 static PyObject *PyObjectResult(int is)
146 {
147         PyObject *result = Py_BuildValue("i", is);
148
149         if (!result)
150                 PyErr_SetString(PyExc_RuntimeError, "Error during constructing values for return value");
151
152         return result;
153 }
154
155 #define CryptSetup_HELP "CryptSetup object\n\n\
156 constructor takes one to five arguments:\n\
157   __init__(device, name, yesDialog, passwordDialog, logFunc)\n\n\
158   yesDialog - python function with func(text) signature, \n\
159               which asks the user question text and returns 1\n\
160               of the answer was positive or 0 if not\n\
161   logFunc   - python function with func(level, text) signature to log stuff somewhere"
162
163 static int CryptSetup_init(CryptSetupObject* self, PyObject *args, PyObject *kwds)
164 {
165         static char *kwlist[] = {"device", "name", "yesDialog", "passwordDialog", "logFunc", NULL};
166         PyObject *yesDialogCB = NULL,
167                  *passwordDialogCB = NULL,
168                  *cmdLineLogCB = NULL,
169                  *tmp = NULL;
170         char *device = NULL, *deviceName = NULL;
171
172         if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzOOO", kwlist, &device, &deviceName,
173                                          &yesDialogCB, &passwordDialogCB, &cmdLineLogCB))
174                 return -1;
175
176         if (device) {
177                 if (crypt_init(&(self->device), device)) {
178                         PyErr_SetString(PyExc_IOError, "Device cannot be opened");
179                         return -1;
180                 }
181
182         } else if (deviceName) {
183                 if (crypt_init_by_name(&(self->device), deviceName)) {
184                         PyErr_SetString(PyExc_IOError, "Device cannot be opened");
185                         return -1;
186                 }
187         } else {
188                 PyErr_SetString(PyExc_RuntimeError, "Either device file or luks name has to be specified");
189                 return -1;
190         }
191
192         // FIXME: check return code
193         crypt_load(self->device, NULL, NULL);
194         if(deviceName)
195                 self->activated_as = strdup(deviceName);
196
197         if (yesDialogCB) {
198                 tmp = self->yesDialogCB;
199                 Py_INCREF(yesDialogCB);
200                 self->yesDialogCB = yesDialogCB;
201                 Py_XDECREF(tmp);
202                 crypt_set_confirm_callback(self->device, yesDialog, self);
203         }
204
205         if (passwordDialogCB) {
206                 tmp = self->passwordDialogCB;
207                 Py_INCREF(passwordDialogCB);
208                 self->passwordDialogCB = passwordDialogCB;
209                 Py_XDECREF(tmp);
210                 crypt_set_password_callback(self->device, passwordDialog, self);
211         }
212
213         if (cmdLineLogCB) {
214                 tmp = self->cmdLineLogCB;
215                 Py_INCREF(cmdLineLogCB);
216                 self->cmdLineLogCB = cmdLineLogCB;
217                 Py_XDECREF(tmp);
218                 crypt_set_log_callback(self->device, cmdLineLog, self);
219         }
220
221         return 0;
222 }
223
224 #define CryptSetup_activate_HELP "Activate LUKS device\n\n\
225   activate(name)"
226
227 static PyObject *CryptSetup_activate(CryptSetupObject* self, PyObject *args, PyObject *kwds)
228 {
229         static char *kwlist[] = {"name", "passphrase", NULL};
230         char *name = NULL, *passphrase = NULL;
231         int is;
232
233         if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|s", kwlist, &name, &passphrase))
234                 return NULL;
235
236         // FIXME: allow keyfile and \0 in passphrase
237         is = crypt_activate_by_passphrase(self->device, name, CRYPT_ANY_SLOT,
238                                           passphrase, passphrase ? strlen(passphrase) : 0, 0);
239
240         if (is >= 0) {
241                 free(self->activated_as);
242                 self->activated_as = strdup(name);
243         }
244
245         return PyObjectResult(is);
246 }
247
248 #define CryptSetup_deactivate_HELP "Dectivate LUKS device\n\n\
249   deactivate()"
250
251 static PyObject *CryptSetup_deactivate(CryptSetupObject* self, PyObject *args, PyObject *kwds)
252 {
253         int is = crypt_deactivate(self->device, self->activated_as);
254
255         if (!is) {
256                 free(self->activated_as);
257                 self->activated_as = NULL;
258         }
259
260         return PyObjectResult(is);
261 }
262
263 #define CryptSetup_askyes_HELP "Asks a question using the configured dialog CB\n\n\
264   int askyes(message)"
265
266 static PyObject *CryptSetup_askyes(CryptSetupObject* self, PyObject *args, PyObject *kwds)
267 {
268         static char *kwlist[] = {"message", NULL};
269         PyObject *message = NULL, *result, *arglist;
270
271         if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &message))
272                 return NULL;
273
274         Py_INCREF(message);
275
276         arglist = Py_BuildValue("(O)", message);
277         if (!arglist){
278                 PyErr_SetString(PyExc_RuntimeError, "Error during constructing values for internal call");
279                 return NULL;
280         }
281
282         result = PyEval_CallObject(self->yesDialogCB, arglist);
283         Py_DECREF(arglist);
284         Py_DECREF(message);
285
286         return result;
287 }
288
289 #define CryptSetup_log_HELP "Logs a string using the configured log CB\n\n\
290   log(int level, message)"
291
292 static PyObject *CryptSetup_log(CryptSetupObject* self, PyObject *args, PyObject *kwds)
293 {
294         static char *kwlist[] = {"priority", "message", NULL};
295         PyObject *message = NULL, *priority = NULL, *result, *arglist;
296
297         if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &message, &priority))
298                 return NULL;
299
300         Py_INCREF(message);
301         Py_INCREF(priority);
302
303         arglist = Py_BuildValue("(OO)", message, priority);
304         if (!arglist){
305                 PyErr_SetString(PyExc_RuntimeError, "Error during constructing values for internal call");
306                 return NULL;
307         }
308
309         result = PyEval_CallObject(self->cmdLineLogCB, arglist);
310         Py_DECREF(arglist);
311         Py_DECREF(priority);
312         Py_DECREF(message);
313
314         return result;
315 }
316
317 #define CryptSetup_luksUUID_HELP "Get UUID of the LUKS device\n\n\
318   luksUUID()"
319
320 static PyObject *CryptSetup_luksUUID(CryptSetupObject* self, PyObject *args, PyObject *kwds)
321 {
322         PyObject *result;
323
324         result = Py_BuildValue("s", crypt_get_uuid(self->device));
325         if (!result)
326                 PyErr_SetString(PyExc_RuntimeError, "Error during constructing values for return value");
327
328         return result;
329 }
330
331 #define CryptSetup_isLuks_HELP "Is the device LUKS?\n\n\
332   isLuks()"
333
334 static PyObject *CryptSetup_isLuks(CryptSetupObject* self, PyObject *args, PyObject *kwds)
335 {
336         return PyObjectResult(crypt_load(self->device, CRYPT_LUKS1, NULL));
337 }
338
339 #define CryptSetup_Info_HELP "Returns dictionary with info about opened device\nKeys:\n\
340   dir\n  name\n  uuid\n  cipher\n  cipher_mode\n  keysize\n  device\n\
341   offset\n  size\n  skip\n  mode\n"
342
343 static PyObject *CryptSetup_Info(CryptSetupObject* self, PyObject *args, PyObject *kwds)
344 {
345         PyObject *result;
346
347         result = Py_BuildValue("{s:s,s:s,s:z,s:s,s:s,s:s,s:i,s:K}",
348                                 "dir",          crypt_get_dir(),
349                                 "device",       crypt_get_device_name(self->device),
350                                 "name",         self->activated_as,
351                                 "uuid",         crypt_get_uuid(self->device),
352                                 "cipher",       crypt_get_cipher(self->device),
353                                 "cipher_mode",  crypt_get_cipher_mode(self->device),
354                                 "keysize",      crypt_get_volume_key_size(self->device) * 8,
355                                 //"size",       co.size,
356                                 //"mode",       (co.flags & CRYPT_FLAG_READONLY) ? "readonly" : "read/write",
357                                 "offset",       crypt_get_data_offset(self->device)
358                                 );
359
360         if (!result)
361                 PyErr_SetString(PyExc_RuntimeError, "Error during constructing values for return value");
362
363         return result;
364 }
365
366 #define CryptSetup_luksFormat_HELP "Format device to enable LUKS\n\n\
367   luksFormat(cipher = 'aes', cipherMode = 'cbc-essiv:sha256', keysize = 256)\n\n\
368   cipher - cipher specification, e.g. aes, serpent\n\
369   cipherMode - cipher mode specification, e.g. cbc-essiv:sha256, xts-plain64\n\
370   keysize - key size in bits"
371
372 static PyObject *CryptSetup_luksFormat(CryptSetupObject* self, PyObject *args, PyObject *kwds)
373 {
374         static char *kwlist[] = {"cipher", "cipherMode", "keysize", NULL};
375         char *cipher_mode = NULL, *cipher = NULL;
376         int keysize = 256;
377         PyObject *keysize_object = NULL;
378
379         if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzO", kwlist, 
380                                         &cipher, &cipher_mode, &keysize_object))
381                 return NULL;
382
383         if (!keysize_object || keysize_object == Py_None) {
384                 /* use default value */
385         } else if (!PyInt_Check(keysize_object)) {
386                 PyErr_SetString(PyExc_TypeError, "keysize must be an integer");
387                 return NULL;
388         } else if (PyInt_AsLong(keysize_object) % 8) {
389                 PyErr_SetString(PyExc_TypeError, "keysize must have integer value dividable by 8");
390                 return NULL;
391         } else if (PyInt_AsLong(keysize_object) <= 0) {
392                 PyErr_SetString(PyExc_TypeError, "keysize must be positive number bigger than 0");
393                 return NULL;
394         } else
395                 keysize = PyInt_AsLong(keysize_object);
396
397         // FIXME use #defined defaults
398         return PyObjectResult(crypt_format(self->device, CRYPT_LUKS1,
399                                 cipher ?: "aes", cipher_mode ?: "cbc-essiv:sha256",
400                                 NULL, NULL, keysize / 8, NULL));
401 }
402
403 #define CryptSetup_addKeyByPassphrase_HELP "Initialize keyslot using passphrase\n\n\
404   addKeyByPassphrase(passphrase, newPassphrase, slot)\n\n\
405   passphrase - string or none to ask the user\n\
406   newPassphrase - passphrase to add\n\
407   slot - which slot to use (optional)"
408
409 static PyObject *CryptSetup_addKeyByPassphrase(CryptSetupObject* self, PyObject *args, PyObject *kwds)
410 {
411         static char *kwlist[] = {"passphrase", "newPassphrase", "slot", NULL};
412         char *passphrase = NULL, *newpassphrase = NULL;
413         size_t passphrase_len = 0, newpassphrase_len = 0;
414         int slot = CRYPT_ANY_SLOT;
415
416         if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|i", kwlist, &passphrase, &newpassphrase, &slot))
417                 return NULL;
418
419         if(passphrase)
420                 passphrase_len = strlen(passphrase);
421
422         if(newpassphrase)
423                 newpassphrase_len = strlen(newpassphrase);
424
425         return PyObjectResult(crypt_keyslot_add_by_passphrase(self->device, slot,
426                                         passphrase, passphrase_len,
427                                         newpassphrase, newpassphrase_len));
428 }
429
430 #define CryptSetup_addKeyByVolumeKey_HELP "Initialize keyslot using cached volume key\n\n\
431   addKeyByVolumeKey(passphrase, newPassphrase, slot)\n\n\
432   newPassphrase - passphrase to add\n\
433   slot - which slot to use (optional)"
434
435 static PyObject *CryptSetup_addKeyByVolumeKey(CryptSetupObject* self, PyObject *args, PyObject *kwds)
436 {
437         static char *kwlist[] = {"newPassphrase", "slot", NULL};
438         char *newpassphrase = NULL;
439         size_t newpassphrase_len = 0;
440         int slot = CRYPT_ANY_SLOT;
441
442         if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i", kwlist, &newpassphrase, &slot))
443                 return NULL;
444
445         if (newpassphrase)
446                 newpassphrase_len = strlen(newpassphrase);
447
448         return PyObjectResult(crypt_keyslot_add_by_volume_key(self->device, slot,
449                                         NULL, 0, newpassphrase, newpassphrase_len));
450 }
451
452 #define CryptSetup_removePassphrase_HELP "Destroy keyslot using passphrase\n\n\
453   removePassphrase(passphrase)\n\n\
454   passphrase - string or none to ask the user"
455
456 static PyObject *CryptSetup_removePassphrase(CryptSetupObject* self, PyObject *args, PyObject *kwds)
457 {
458         static char *kwlist[] = {"passphrase", NULL};
459         char *passphrase = NULL;
460         size_t passphrase_len = 0;
461         int is;
462
463         if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &passphrase))
464                 return NULL;
465
466         if (passphrase)
467                 passphrase_len = strlen(passphrase);
468
469         is = crypt_activate_by_passphrase(self->device, NULL, CRYPT_ANY_SLOT,
470                                           passphrase, passphrase_len, 0);
471         if (is < 0)
472                 return PyObjectResult(is);
473
474         return PyObjectResult(crypt_keyslot_destroy(self->device, is));
475 }
476
477 #define CryptSetup_killSlot_HELP "Destroy keyslot\n\n\
478   killSlot(slot)\n\n\
479   slot - the slot to remove"
480
481 static PyObject *CryptSetup_killSlot(CryptSetupObject* self, PyObject *args, PyObject *kwds)
482 {
483         static char *kwlist[] = {"slot", NULL};
484         int slot = CRYPT_ANY_SLOT;
485
486         if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &slot))
487                 return NULL;
488
489         switch (crypt_keyslot_status(self->device, slot)) {
490         case CRYPT_SLOT_ACTIVE:
491                 return PyObjectResult(crypt_keyslot_destroy(self->device, slot));
492         case CRYPT_SLOT_ACTIVE_LAST:
493                 PyErr_SetString(PyExc_ValueError, "Last slot, removing it would render the device unusable");
494                 break;
495         case CRYPT_SLOT_INACTIVE:
496                 PyErr_SetString(PyExc_ValueError, "Inactive slot");
497                 break;
498         case CRYPT_SLOT_INVALID:
499                 PyErr_SetString(PyExc_ValueError, "Invalid slot");
500                 break;
501         }
502
503         return NULL;
504 }
505
506 #define CryptSetup_Status_HELP "Status of LUKS device\n\n\
507   luksStatus()"
508
509 static PyObject *CryptSetup_Status(CryptSetupObject* self, PyObject *args, PyObject *kwds)
510 {
511         if (!self->activated_as){
512                 PyErr_SetString(PyExc_IOError, "Device has not been activated yet.");
513                 return NULL;
514         }
515
516         return PyObjectResult(crypt_status(self->device, self->activated_as));
517 }
518
519 #define CryptSetup_Resume_HELP "Resume LUKS device\n\n\
520   luksOpen(passphrase)\n\n\
521   passphrase - string or none to ask the user"
522
523 static PyObject *CryptSetup_Resume(CryptSetupObject* self, PyObject *args, PyObject *kwds)
524 {
525         static char *kwlist[] = {"passphrase", NULL};
526         char* passphrase = NULL;
527         size_t passphrase_len = 0;
528
529         if (!self->activated_as){
530                 PyErr_SetString(PyExc_IOError, "Device has not been activated yet.");
531                 return NULL;
532         }
533
534         if (! PyArg_ParseTupleAndKeywords(args, kwds, "|s", kwlist, &passphrase))
535                 return NULL;
536
537         if (passphrase)
538                 passphrase_len = strlen(passphrase);
539
540         return PyObjectResult(crypt_resume_by_passphrase(self->device, self->activated_as,
541                                         CRYPT_ANY_SLOT, passphrase, passphrase_len));
542 }
543
544 #define CryptSetup_Suspend_HELP "Suspend LUKS device\n\n\
545   luksSupsend()"
546
547 static PyObject *CryptSetup_Suspend(CryptSetupObject* self, PyObject *args, PyObject *kwds)
548 {
549         if (!self->activated_as){
550                 PyErr_SetString(PyExc_IOError, "Device has not been activated yet.");
551                 return NULL;
552         }
553
554         return PyObjectResult(crypt_suspend(self->device, self->activated_as));
555 }
556
557 #define CryptSetup_debugLevel_HELP "Set debug level\n\n\
558   debugLevel(level)\n\n\
559   level - debug level"
560
561 static PyObject *CryptSetup_debugLevel(CryptSetupObject* self, PyObject *args, PyObject *kwds)
562 {
563         static char *kwlist[] = {"level", NULL};
564         int level = 0;
565
566         if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &level))
567                 return NULL;
568
569         crypt_set_debug_level(level);
570         return PyObjectResult(0);
571 }
572
573 #define CryptSetup_iterationTime_HELP "Set iteration time\n\n\
574   iterationTime(time_ms)\n\n\
575   time_ms - time in miliseconds"
576
577 static PyObject *CryptSetup_iterationTime(CryptSetupObject* self, PyObject *args, PyObject *kwds)
578 {
579         static char *kwlist[] = {"time_ms", NULL};
580         uint64_t time_ms = 0;
581
582         if (!PyArg_ParseTupleAndKeywords(args, kwds, "l", kwlist, &time_ms))
583                 return NULL;
584
585         crypt_set_iteration_time(self->device, time_ms);
586         return PyObjectResult(0);
587 }
588
589 static PyMemberDef CryptSetup_members[] = {
590         {"yesDialogCB", T_OBJECT_EX, offsetof(CryptSetupObject, yesDialogCB), 0, "confirmation dialog callback"},
591         {"cmdLineLogCB", T_OBJECT_EX, offsetof(CryptSetupObject, cmdLineLogCB), 0, "logging callback"},
592         {"passwordDialogCB", T_OBJECT_EX, offsetof(CryptSetupObject, passwordDialogCB), 0, "password dialog callback"},
593         {NULL}
594 };
595
596 static PyMethodDef CryptSetup_methods[] = {
597         /* self-test methods */
598         {"log", (PyCFunction)CryptSetup_log, METH_VARARGS|METH_KEYWORDS, CryptSetup_askyes_HELP},
599         {"askyes", (PyCFunction)CryptSetup_askyes, METH_VARARGS|METH_KEYWORDS, CryptSetup_log_HELP},
600
601         /* activation and deactivation */
602         {"deactivate", (PyCFunction)CryptSetup_deactivate, METH_NOARGS, CryptSetup_deactivate_HELP},
603         {"activate", (PyCFunction)CryptSetup_activate, METH_VARARGS|METH_KEYWORDS, CryptSetup_activate_HELP},
604
605         /* cryptsetup info entrypoints */
606         {"luksUUID", (PyCFunction)CryptSetup_luksUUID, METH_NOARGS, CryptSetup_luksUUID_HELP},
607         {"isLuks", (PyCFunction)CryptSetup_isLuks, METH_NOARGS, CryptSetup_isLuks_HELP},
608         {"info", (PyCFunction)CryptSetup_Info, METH_NOARGS, CryptSetup_Info_HELP},  
609         {"status", (PyCFunction)CryptSetup_Status, METH_NOARGS, CryptSetup_Status_HELP},
610
611         /* cryptsetup mgmt entrypoints */
612         {"luksFormat", (PyCFunction)CryptSetup_luksFormat, METH_VARARGS|METH_KEYWORDS, CryptSetup_luksFormat_HELP},
613         {"addKeyByPassphrase", (PyCFunction)CryptSetup_addKeyByPassphrase, METH_VARARGS|METH_KEYWORDS, CryptSetup_addKeyByPassphrase_HELP},
614         {"addKeyByVolumeKey", (PyCFunction)CryptSetup_addKeyByVolumeKey, METH_VARARGS|METH_KEYWORDS, CryptSetup_addKeyByVolumeKey_HELP},
615         {"removePassphrase", (PyCFunction)CryptSetup_removePassphrase, METH_VARARGS|METH_KEYWORDS, CryptSetup_removePassphrase_HELP},
616         {"killSlot", (PyCFunction)CryptSetup_killSlot, METH_VARARGS|METH_KEYWORDS, CryptSetup_killSlot_HELP},
617
618         /* suspend resume */
619         {"resume", (PyCFunction)CryptSetup_Resume, METH_VARARGS|METH_KEYWORDS, CryptSetup_Resume_HELP},
620         {"suspend", (PyCFunction)CryptSetup_Suspend, METH_NOARGS, CryptSetup_Suspend_HELP},
621
622         /* misc */
623         {"debugLevel", (PyCFunction)CryptSetup_debugLevel, METH_VARARGS|METH_KEYWORDS, CryptSetup_debugLevel_HELP},
624         {"iterationTime", (PyCFunction)CryptSetup_iterationTime, METH_VARARGS|METH_KEYWORDS, CryptSetup_iterationTime_HELP},
625
626         {NULL} /* Sentinel */
627 };
628
629 static PyTypeObject CryptSetupType = {
630         PyObject_HEAD_INIT(NULL)
631         0, /*ob_size*/
632         "pycryptsetup.CryptSetup", /*tp_name*/
633         sizeof(CryptSetupObject), /*tp_basicsize*/
634         0, /*tp_itemsize*/
635         (destructor)CryptSetup_dealloc, /*tp_dealloc*/
636         0, /*tp_print*/
637         0, /*tp_getattr*/
638         0, /*tp_setattr*/
639         0, /*tp_compare*/
640         0, /*tp_repr*/
641         0, /*tp_as_number*/
642         0, /*tp_as_sequence*/
643         0, /*tp_as_mapping*/
644         0, /*tp_hash */
645         0, /*tp_call*/
646         0, /*tp_str*/
647         0, /*tp_getattro*/
648         0, /*tp_setattro*/
649         0, /*tp_as_buffer*/
650         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
651         CryptSetup_HELP, /* tp_doc */
652         0, /* tp_traverse */
653         0, /* tp_clear */
654         0, /* tp_richcompare */
655         0, /* tp_weaklistoffset */
656         0, /* tp_iter */
657         0, /* tp_iternext */
658         CryptSetup_methods, /* tp_methods */
659         CryptSetup_members, /* tp_members */
660         0, /* tp_getset */
661         0, /* tp_base */
662         0, /* tp_dict */
663         0, /* tp_descr_get */
664         0, /* tp_descr_set */
665         0, /* tp_dictoffset */
666         (initproc)CryptSetup_init, /* tp_init */
667         0, /* tp_alloc */
668         CryptSetup_new, /* tp_new */
669 };
670
671 static PyMethodDef pycryptsetup_methods[] = {
672         {NULL} /* Sentinel */
673 };
674
675 PyMODINIT_FUNC initpycryptsetup(void);
676 PyMODINIT_FUNC initpycryptsetup(void)
677 {
678         PyObject *m;
679
680         if (PyType_Ready(&CryptSetupType) < 0)
681                 return;
682
683         m = Py_InitModule3("pycryptsetup", pycryptsetup_methods, "CryptSetup pythonized API.");
684         Py_INCREF((PyObject *)&CryptSetupType);
685
686         PyModule_AddObject(m, "CryptSetup", (PyObject *)&CryptSetupType);
687 }