5 #include <libpq/libpq-be.h>
8 char *ident_result = NULL;
10 PG_FUNCTION_INFO_V1(get_ident);
11 Datum get_ident(PG_FUNCTION_ARGS) {
14 if (MyProcPort == NULL)
15 elog(ERROR, "could not get ident for user: no port");
18 id = ident_lookup(MyProcPort->sock, 5);
19 if (id && id->identifier) ident_result = strdup(id->identifier);
26 len = strlen(ident_result);
28 result = palloc(len + VARHDRSZ);
29 VARATT_SIZEP(result) = len + VARHDRSZ;
30 memcpy(VARDATA(result), ident_result, len);
32 PG_RETURN_VARCHAR_P(result);
35 elog(ERROR, "could not get ident for user: ident failed");