C functions, arguments, and ssh oh my! - Mailing list pgsql-general

From Joel Dudley
Subject C functions, arguments, and ssh oh my!
Date
Msg-id A04BDD2C264AD41181C000508BDCB72A4F2B8A@USAZDOLEXCH0
Whole thread Raw
Responses Re: C functions, arguments, and ssh oh my!  (Alfred Perlstein <bright@wintelcom.net>)
Re: C functions, arguments, and ssh oh my!  (Peter Eisentraut <peter_e@gmx.net>)
Re: C functions, arguments, and ssh oh my!  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hello All,
  I am writing my first C function for postgres and failing miserably. my C
function needs to get passed a username (char) , uid(int), and gid(int) and
what it does with those is builds a command string for an external app that
is called with system() and exits 0. I know this is strange and ugly but I
need to trigger this external app when an insert is made into a user table.
I am looking into the version 1 calling convention to get these arguments
into my C function but I can't seem to match the types correctly. I am
looking at SPI with triggers now but I don't know if that will work either.
Am I barking up the wrong tree here? any comments are appreciated and I
appreciate the time you have taken to read my post.  Below is to cludgy poor
code I have so far (it doesnt work of course) and I am halfway between
converting to version 1 calling but I wanted to give you an idea of what I
am trying to do. Thanks again.

- Joel

#include <stdlib.h>
#include "postgres.h"
#include "fmgr.h"

/*int *ssh_exec(char *uname[FILENAME_MAX], char *uid[FILENAME_MAX], char
*gid[FILENAME_MAX])*/

PG_FUNCTION_INFO_V1(ssh_exec);

Datum
ssh_exec(PG_FUNCTION_ARGS)
{
        char sshcmd[255];

        strncpy(sshcmd, "/usr/local/bin/plsshexec ", 255);
        strncat(sshcmd, *uname, 255);
        strncat(sshcmd, " ", 255);
        strncat(sshcmd, *uid, 255);
        strncat(sshcmd, " ", 255);
        strncat(sshcmd, *gid, 255);
        system(sshcmd);
        return 0;
}

pgsql-general by date:

Previous
From: Patrick Aland
Date:
Subject: Two tables for the price of one?
Next
From: Peter Eisentraut
Date:
Subject: Re: Two tables for the price of one?