Re: fmgr, C , and character arguments

From: Marko Kreen <marko(at)l-t(dot)ee>
To: Joel Dudley <Joel(dot)Dudley(at)DevelopOnline(dot)com>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: fmgr, C , and character arguments
Date: 2001-03-28 00:57:18
Message-ID: 20010328025718.A11356@l-t.ee
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Mar 27, 2001 at 03:45:17PM -0700, Joel Dudley wrote:
> Hello all,
> I am having a bit of trouble getting my arguments formatted into a
> command string for system(). Here is what I have so far for code.
>
> #include <string.h>
> #include <stdlib.h>
> #include "postgres.h"
> #include "fmgr.h"
>
>
> PG_FUNCTION_INFO_V1(ssh_exec);
>

Try this:

Datum
ssh_exec(PG_FUNCTION_ARGS)
{
char *uname = PG_GETARG_CHAR(0);
char *uid = PG_GETARG_CHAR(1);
char *gid = PG_GETARG_CHAR(2);

strcpy(sshcmd, "/usr/local/bin/plsshexec ");
strncat(sshcmd, VARDATA(uname), VARSIZE(uname));
strcat(sshcmd, " ");
strncat(sshcmd, VARDATA(uid), VARSIZE(uid));
strcat(sshcmd, " ");
strncat(sshcmd, VARDATA(gid), VARSIZE(gid));
system(sshcmd);
return 0;
}

This may work, but is more to give you idea what PostgreSQL
vars are about. I would not use such code in my projects anyway :)

I suggest you study the code in src/backend/utils/adt/varchar.c
to see examples of char/text manipulation.

--
marko

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tatsuo Ishii 2001-03-28 01:39:51 Re: Re: Call for platforms
Previous Message Adam Haberlach 2001-03-28 00:53:26 Out of date security docs