remminapasswdmodule.c 1.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include <Python.h>
#include <glib/gprintf.h>
#include "remmina_pref.h"
#include "remmina_crypt.h"

char* remmina_password_generate(const char* password) {
    remmina_pref_init();
    return remmina_crypt_encrypt(password);
}

int main(int argc, char **argv) {
    if (argc == 2) {
      remmina_pref_init();
      g_printf("%s", remmina_crypt_encrypt(argv[1]));
      return 0;
   } else {
      /* No (or too many) parameter(s) given, exit with code 1 to signal error */
      return 1;
   }
}

static PyObject* remminapasswd(PyObject* self, PyObject* args) {
    const char* password;
    if (!PyArg_ParseTuple(args, "s", &password)) {
        return NULL;
    }

    return Py_BuildValue("s", remmina_password_generate(password));
}

static PyMethodDef RemminaPasswdMethods[] = {
    {"remminapasswd", remminapasswd, METH_VARARGS, "Genereates a remmina accepted password from a plain text password"},
    {NULL, NULL, 0, NULL}
};
 
PyMODINIT_FUNC initremminapasswd(void) {
    (void) Py_InitModule("remminapasswd", RemminaPasswdMethods);
}