X-Git-Url: https://git.ucc.asn.au/?p=uccvend-vendserver.git;a=blobdiff_plain;f=sql-edition%2Fident%2Fpg_ident.c;fp=sql-edition%2Fident%2Fpg_ident.c;h=2de212178c9e34a8e0acb05b85a3be44c5543f37;hp=0000000000000000000000000000000000000000;hb=b2dec34c53f25194708de8ec3caf771a29d51833;hpb=6e99ab47bc4c632a1f43ad5e22e0fd27ce27677d diff --git a/sql-edition/ident/pg_ident.c b/sql-edition/ident/pg_ident.c new file mode 100644 index 0000000..2de2121 --- /dev/null +++ b/sql-edition/ident/pg_ident.c @@ -0,0 +1,39 @@ +#include + +#include +#include +#include +#include + +char *ident_result = NULL; + +PG_FUNCTION_INFO_V1(get_ident); +Datum get_ident(PG_FUNCTION_ARGS) { + IDENT *id; + + if (MyProcPort == NULL) + elog(ERROR, "could not get ident for user: no port"); + + if (!ident_result) { + id = ident_lookup(MyProcPort->sock, 5); + if (id && id->identifier) ident_result = strdup(id->identifier); + } + + if (ident_result) { + int len; + VarChar* result; + + len = strlen(ident_result); + if (len > 8) len = 8; + result = palloc(len + VARHDRSZ); + VARATT_SIZEP(result) = len + VARHDRSZ; + memcpy(VARDATA(result), ident_result, len); + + PG_RETURN_VARCHAR_P(result); + } + + elog(ERROR, "could not get ident for user: ident failed"); + + /* not reached */ + PG_RETURN_NULL(); +}