]> git.8kb.co.uk Git - slony-i/user_replication/blob - hkey/hkey.c
Remove irrelevant grant
[slony-i/user_replication] / hkey / hkey.c
1 //Glyn 08/05/2008 -- Function to obfuscate enctryption key generation based on username
2
3 #include "postgres.h"
4 #include "fmgr.h"
5 #include <string.h>
6
7 #ifdef PG_MODULE_MAGIC
8 PG_MODULE_MAGIC;
9 #endif
10
11 Datum hkey( PG_FUNCTION_ARGS );
12
13 PG_FUNCTION_INFO_V1( hkey );
14 Datum
15 hkey( PG_FUNCTION_ARGS )
16 {
17    // variable declarations
18    char key[] = "91836zi8euwq45270";
19    text *uname;
20    int keylen;
21    int unamelen;
22    text *keying;
23
24    // Get arguments.  If we declare our function as STRICT, then this check is superfluous.
25    if( PG_ARGISNULL(0) ) {
26       PG_RETURN_NULL();
27    }
28    uname = PG_GETARG_TEXT_P(0);
29
30    // Calculate string sizes.
31    keylen = strlen(key);
32    unamelen = VARSIZE(uname) - VARHDRSZ;
33
34    // Allocate memory and set data structure size.
35    // Don't forget to add the type overhead (size of the length of the word at the start of the value) of int4 / VARHDRSZ
36    keying = (text *)palloc( keylen + unamelen + VARHDRSZ);
37
38    // VARATT_SIZEP depreciated as of 8.3
39    //VARATT_SIZEP( keying ) = keylen + unamelen  + VARHDRSZ;
40    SET_VARSIZE(keying, keylen + unamelen  + VARHDRSZ);
41
42    // Construct keying string.
43    strncpy( VARDATA(keying), key, keylen );
44    strncpy( VARDATA(keying) + keylen,
45             VARDATA(uname),
46             unamelen );
47
48    PG_RETURN_TEXT_P( keying );
49 }