I'd like to call some pgcrypto functions from python. Namely px_crypt. I can't seem to figure out the right object files to link it seems.
Here's my code:
#include <Python.h>
#include "postgres.h"
#include "pgcrypto/px-crypt.h"
static PyObject*
pgcrypt(PyObject* self, PyObject* args)
{
const char* key;
const char* setting;
if (!PyArg_ParseTuple(args, "ss", &key, &setting))
return NULL;
return Py_BuildValue("s", px_crypt(key, setting, "", 0));
}
static PyMethodDef PgCryptMethods[] =
{
{"pgcrypt", pgcrypt, METH_VARARGS, "Call pgcrypto's crypt"},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
initpypgcrypto(void)
{
(void) Py_InitModule("pypgcrypto", PgCryptMethods);
}
and gcc commands and output:
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/home/ionut/github/postgres/contrib/ -I/usr/include/postgresql/9.4/server/ -I/usr/include/python2.7 -c pypgcrypto.c -o build/temp.linux-x86_64-2.7/pypgcrypto.o
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/pypgcrypto.o /usr/lib/postgresql/9.4/lib/pgcrypto.so -lpgport -lpq -o build/lib.linux-x86_64-2.7/pypgcrypto.so
Error is:
python -c "import pypgcrypto; print pypgcrypto.pgcrypt('foo', 'bar')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: /usr/lib/postgresql/9.4/lib/pgcrypto.so: undefined symbol: InterruptPending
InterruptPending
, which library does this symbol belongs to? – Flatfishpx_crypt
is loaded at runtime by postgresql withdlsym()
probably and thatInterruptPending
might be for example a global variable defined in the caller? – VolcanismI want to replicate pgcrypto's behaviour in order to be able to generate password hashes that match the ones already in my database
. My answer does exactly this for the algorithm you need. – Mendelssohn